Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/net/ehea/ehea_main.c |
| 3 | * |
| 4 | * eHEA ethernet device driver for IBM eServer System p |
| 5 | * |
| 6 | * (C) Copyright IBM Corp. 2006 |
| 7 | * |
| 8 | * Authors: |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 9 | * Christoph Raisch <raisch@de.ibm.com> |
| 10 | * Jan-Bernd Themann <themann@de.ibm.com> |
| 11 | * Thomas Klein <tklein@de.ibm.com> |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 12 | * |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
| 17 | * any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/in.h> |
| 30 | #include <linux/ip.h> |
| 31 | #include <linux/tcp.h> |
| 32 | #include <linux/udp.h> |
| 33 | #include <linux/if.h> |
| 34 | #include <linux/list.h> |
| 35 | #include <linux/if_ether.h> |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 36 | #include <linux/notifier.h> |
| 37 | #include <linux/reboot.h> |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 38 | #include <linux/memory.h> |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 39 | #include <asm/kexec.h> |
Daniel Walker | 06f89ed | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 40 | #include <linux/mutex.h> |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 41 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 42 | #include <net/ip.h> |
| 43 | |
| 44 | #include "ehea.h" |
| 45 | #include "ehea_qmr.h" |
| 46 | #include "ehea_phyp.h" |
| 47 | |
| 48 | |
| 49 | MODULE_LICENSE("GPL"); |
| 50 | MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); |
| 51 | MODULE_DESCRIPTION("IBM eServer HEA Driver"); |
| 52 | MODULE_VERSION(DRV_VERSION); |
| 53 | |
| 54 | |
| 55 | static int msg_level = -1; |
| 56 | static int rq1_entries = EHEA_DEF_ENTRIES_RQ1; |
| 57 | static int rq2_entries = EHEA_DEF_ENTRIES_RQ2; |
| 58 | static int rq3_entries = EHEA_DEF_ENTRIES_RQ3; |
| 59 | static int sq_entries = EHEA_DEF_ENTRIES_SQ; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 60 | static int use_mcs; |
| 61 | static int use_lro; |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 62 | static int lro_max_aggr = EHEA_LRO_MAX_AGGR; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 63 | static int num_tx_qps = EHEA_NUM_TX_QP; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 64 | static int prop_carrier_state; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 65 | |
| 66 | module_param(msg_level, int, 0); |
| 67 | module_param(rq1_entries, int, 0); |
| 68 | module_param(rq2_entries, int, 0); |
| 69 | module_param(rq3_entries, int, 0); |
| 70 | module_param(sq_entries, int, 0); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 71 | module_param(prop_carrier_state, int, 0); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 72 | module_param(use_mcs, int, 0); |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 73 | module_param(use_lro, int, 0); |
| 74 | module_param(lro_max_aggr, int, 0); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 75 | module_param(num_tx_qps, int, 0); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 76 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 77 | MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 78 | MODULE_PARM_DESC(msg_level, "msg_level"); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 79 | MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical " |
| 80 | "port to stack. 1:yes, 0:no. Default = 0 "); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 81 | MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 " |
| 82 | "[2^x - 1], x = [6..14]. Default = " |
| 83 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")"); |
| 84 | MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 " |
| 85 | "[2^x - 1], x = [6..14]. Default = " |
| 86 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")"); |
| 87 | MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 " |
| 88 | "[2^x - 1], x = [6..14]. Default = " |
| 89 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")"); |
| 90 | MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue " |
| 91 | "[2^x - 1], x = [6..14]. Default = " |
| 92 | __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")"); |
Jan-Bernd Themann | 18072a5 | 2007-08-22 16:21:24 +0200 | [diff] [blame] | 93 | MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 "); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 94 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 95 | MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = " |
| 96 | __MODULE_STRING(EHEA_LRO_MAX_AGGR)); |
| 97 | MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, " |
| 98 | "Default = 0"); |
| 99 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 100 | static int port_name_cnt; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 101 | static LIST_HEAD(adapter_list); |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 102 | u64 ehea_driver_flags; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 103 | struct work_struct ehea_rereg_mr_task; |
Daniel Walker | 06f89ed | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 104 | static DEFINE_MUTEX(dlpar_mem_lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 105 | struct ehea_fw_handle_array ehea_fw_handles; |
| 106 | struct ehea_bcmc_reg_array ehea_bcmc_regs; |
| 107 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 108 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 109 | static int __devinit ehea_probe_adapter(struct of_device *dev, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 110 | const struct of_device_id *id); |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 111 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 112 | static int __devexit ehea_remove(struct of_device *dev); |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 113 | |
| 114 | static struct of_device_id ehea_device_table[] = { |
| 115 | { |
| 116 | .name = "lhea", |
| 117 | .compatible = "IBM,lhea", |
| 118 | }, |
| 119 | {}, |
| 120 | }; |
| 121 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 122 | static struct of_platform_driver ehea_driver = { |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 123 | .name = "ehea", |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 124 | .match_table = ehea_device_table, |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 125 | .probe = ehea_probe_adapter, |
| 126 | .remove = ehea_remove, |
| 127 | }; |
| 128 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 129 | void ehea_dump(void *adr, int len, char *msg) |
| 130 | { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 131 | int x; |
| 132 | unsigned char *deb = adr; |
| 133 | for (x = 0; x < len; x += 16) { |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 134 | printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg, |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 135 | deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8])); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 136 | deb += 16; |
| 137 | } |
| 138 | } |
| 139 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 140 | static void ehea_update_firmware_handles(void) |
| 141 | { |
| 142 | struct ehea_fw_handle_entry *arr = NULL; |
| 143 | struct ehea_adapter *adapter; |
| 144 | int num_adapters = 0; |
| 145 | int num_ports = 0; |
| 146 | int num_portres = 0; |
| 147 | int i = 0; |
| 148 | int num_fw_handles, k, l; |
| 149 | |
| 150 | /* Determine number of handles */ |
| 151 | list_for_each_entry(adapter, &adapter_list, list) { |
| 152 | num_adapters++; |
| 153 | |
| 154 | for (k = 0; k < EHEA_MAX_PORTS; k++) { |
| 155 | struct ehea_port *port = adapter->port[k]; |
| 156 | |
| 157 | if (!port || (port->state != EHEA_PORT_UP)) |
| 158 | continue; |
| 159 | |
| 160 | num_ports++; |
| 161 | num_portres += port->num_def_qps + port->num_add_tx_qps; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES + |
| 166 | num_ports * EHEA_NUM_PORT_FW_HANDLES + |
| 167 | num_portres * EHEA_NUM_PORTRES_FW_HANDLES; |
| 168 | |
| 169 | if (num_fw_handles) { |
| 170 | arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL); |
| 171 | if (!arr) |
| 172 | return; /* Keep the existing array */ |
| 173 | } else |
| 174 | goto out_update; |
| 175 | |
| 176 | list_for_each_entry(adapter, &adapter_list, list) { |
| 177 | for (k = 0; k < EHEA_MAX_PORTS; k++) { |
| 178 | struct ehea_port *port = adapter->port[k]; |
| 179 | |
| 180 | if (!port || (port->state != EHEA_PORT_UP)) |
| 181 | continue; |
| 182 | |
| 183 | for (l = 0; |
| 184 | l < port->num_def_qps + port->num_add_tx_qps; |
| 185 | l++) { |
| 186 | struct ehea_port_res *pr = &port->port_res[l]; |
| 187 | |
| 188 | arr[i].adh = adapter->handle; |
| 189 | arr[i++].fwh = pr->qp->fw_handle; |
| 190 | arr[i].adh = adapter->handle; |
| 191 | arr[i++].fwh = pr->send_cq->fw_handle; |
| 192 | arr[i].adh = adapter->handle; |
| 193 | arr[i++].fwh = pr->recv_cq->fw_handle; |
| 194 | arr[i].adh = adapter->handle; |
| 195 | arr[i++].fwh = pr->eq->fw_handle; |
| 196 | arr[i].adh = adapter->handle; |
| 197 | arr[i++].fwh = pr->send_mr.handle; |
| 198 | arr[i].adh = adapter->handle; |
| 199 | arr[i++].fwh = pr->recv_mr.handle; |
| 200 | } |
| 201 | arr[i].adh = adapter->handle; |
| 202 | arr[i++].fwh = port->qp_eq->fw_handle; |
| 203 | } |
| 204 | |
| 205 | arr[i].adh = adapter->handle; |
| 206 | arr[i++].fwh = adapter->neq->fw_handle; |
| 207 | |
| 208 | if (adapter->mr.handle) { |
| 209 | arr[i].adh = adapter->handle; |
| 210 | arr[i++].fwh = adapter->mr.handle; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | out_update: |
| 215 | kfree(ehea_fw_handles.arr); |
| 216 | ehea_fw_handles.arr = arr; |
| 217 | ehea_fw_handles.num_entries = i; |
| 218 | } |
| 219 | |
| 220 | static void ehea_update_bcmc_registrations(void) |
| 221 | { |
| 222 | struct ehea_bcmc_reg_entry *arr = NULL; |
| 223 | struct ehea_adapter *adapter; |
| 224 | struct ehea_mc_list *mc_entry; |
| 225 | int num_registrations = 0; |
| 226 | int i = 0; |
| 227 | int k; |
| 228 | |
| 229 | /* Determine number of registrations */ |
| 230 | list_for_each_entry(adapter, &adapter_list, list) |
| 231 | for (k = 0; k < EHEA_MAX_PORTS; k++) { |
| 232 | struct ehea_port *port = adapter->port[k]; |
| 233 | |
| 234 | if (!port || (port->state != EHEA_PORT_UP)) |
| 235 | continue; |
| 236 | |
| 237 | num_registrations += 2; /* Broadcast registrations */ |
| 238 | |
| 239 | list_for_each_entry(mc_entry, &port->mc_list->list,list) |
| 240 | num_registrations += 2; |
| 241 | } |
| 242 | |
| 243 | if (num_registrations) { |
| 244 | arr = kzalloc(num_registrations * sizeof(*arr), GFP_KERNEL); |
| 245 | if (!arr) |
| 246 | return; /* Keep the existing array */ |
| 247 | } else |
| 248 | goto out_update; |
| 249 | |
| 250 | list_for_each_entry(adapter, &adapter_list, list) { |
| 251 | for (k = 0; k < EHEA_MAX_PORTS; k++) { |
| 252 | struct ehea_port *port = adapter->port[k]; |
| 253 | |
| 254 | if (!port || (port->state != EHEA_PORT_UP)) |
| 255 | continue; |
| 256 | |
| 257 | arr[i].adh = adapter->handle; |
| 258 | arr[i].port_id = port->logical_port_id; |
| 259 | arr[i].reg_type = EHEA_BCMC_BROADCAST | |
| 260 | EHEA_BCMC_UNTAGGED; |
| 261 | arr[i++].macaddr = port->mac_addr; |
| 262 | |
| 263 | arr[i].adh = adapter->handle; |
| 264 | arr[i].port_id = port->logical_port_id; |
| 265 | arr[i].reg_type = EHEA_BCMC_BROADCAST | |
| 266 | EHEA_BCMC_VLANID_ALL; |
| 267 | arr[i++].macaddr = port->mac_addr; |
| 268 | |
| 269 | list_for_each_entry(mc_entry, |
| 270 | &port->mc_list->list, list) { |
| 271 | arr[i].adh = adapter->handle; |
| 272 | arr[i].port_id = port->logical_port_id; |
| 273 | arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | |
| 274 | EHEA_BCMC_MULTICAST | |
| 275 | EHEA_BCMC_UNTAGGED; |
| 276 | arr[i++].macaddr = mc_entry->macaddr; |
| 277 | |
| 278 | arr[i].adh = adapter->handle; |
| 279 | arr[i].port_id = port->logical_port_id; |
| 280 | arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | |
| 281 | EHEA_BCMC_MULTICAST | |
| 282 | EHEA_BCMC_VLANID_ALL; |
| 283 | arr[i++].macaddr = mc_entry->macaddr; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | out_update: |
| 289 | kfree(ehea_bcmc_regs.arr); |
| 290 | ehea_bcmc_regs.arr = arr; |
| 291 | ehea_bcmc_regs.num_entries = i; |
| 292 | } |
| 293 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 294 | static struct net_device_stats *ehea_get_stats(struct net_device *dev) |
| 295 | { |
| 296 | struct ehea_port *port = netdev_priv(dev); |
| 297 | struct net_device_stats *stats = &port->stats; |
| 298 | struct hcp_ehea_port_cb2 *cb2; |
Thomas Klein | 7393b87 | 2007-11-21 17:37:58 +0100 | [diff] [blame] | 299 | u64 hret, rx_packets, tx_packets; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 300 | int i; |
| 301 | |
| 302 | memset(stats, 0, sizeof(*stats)); |
| 303 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 304 | cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 305 | if (!cb2) { |
| 306 | ehea_error("no mem for cb2"); |
| 307 | goto out; |
| 308 | } |
| 309 | |
| 310 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 311 | port->logical_port_id, |
| 312 | H_PORT_CB2, H_PORT_CB2_ALL, cb2); |
| 313 | if (hret != H_SUCCESS) { |
| 314 | ehea_error("query_ehea_port failed"); |
| 315 | goto out_herr; |
| 316 | } |
| 317 | |
| 318 | if (netif_msg_hw(port)) |
| 319 | ehea_dump(cb2, sizeof(*cb2), "net_device_stats"); |
| 320 | |
| 321 | rx_packets = 0; |
| 322 | for (i = 0; i < port->num_def_qps; i++) |
| 323 | rx_packets += port->port_res[i].rx_packets; |
| 324 | |
Thomas Klein | 7393b87 | 2007-11-21 17:37:58 +0100 | [diff] [blame] | 325 | tx_packets = 0; |
| 326 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) |
| 327 | tx_packets += port->port_res[i].tx_packets; |
| 328 | |
| 329 | stats->tx_packets = tx_packets; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 330 | stats->multicast = cb2->rxmcp; |
| 331 | stats->rx_errors = cb2->rxuerr; |
| 332 | stats->rx_bytes = cb2->rxo; |
| 333 | stats->tx_bytes = cb2->txo; |
| 334 | stats->rx_packets = rx_packets; |
| 335 | |
| 336 | out_herr: |
| 337 | kfree(cb2); |
| 338 | out: |
| 339 | return stats; |
| 340 | } |
| 341 | |
| 342 | static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes) |
| 343 | { |
| 344 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 345 | struct net_device *dev = pr->port->netdev; |
| 346 | int max_index_mask = pr->rq1_skba.len - 1; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 347 | int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes; |
| 348 | int adder = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 349 | int i; |
| 350 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 351 | pr->rq1_skba.os_skbs = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 352 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 353 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
Thomas Klein | 44fb312 | 2008-04-04 15:04:53 +0200 | [diff] [blame] | 354 | if (nr_of_wqes > 0) |
| 355 | pr->rq1_skba.index = index; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 356 | pr->rq1_skba.os_skbs = fill_wqes; |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | for (i = 0; i < fill_wqes; i++) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 361 | if (!skb_arr_rq1[index]) { |
| 362 | skb_arr_rq1[index] = netdev_alloc_skb(dev, |
| 363 | EHEA_L_PKT_SIZE); |
| 364 | if (!skb_arr_rq1[index]) { |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 365 | pr->rq1_skba.os_skbs = fill_wqes - i; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 366 | ehea_error("%s: no mem for skb/%d wqes filled", |
| 367 | dev->name, i); |
| 368 | break; |
| 369 | } |
| 370 | } |
| 371 | index--; |
| 372 | index &= max_index_mask; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 373 | adder++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 374 | } |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 375 | |
| 376 | if (adder == 0) |
| 377 | return; |
| 378 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 379 | /* Ring doorbell */ |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 380 | ehea_update_rq1a(pr->qp, adder); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a) |
| 384 | { |
| 385 | int ret = 0; |
| 386 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 387 | struct net_device *dev = pr->port->netdev; |
| 388 | int i; |
| 389 | |
| 390 | for (i = 0; i < pr->rq1_skba.len; i++) { |
| 391 | skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE); |
| 392 | if (!skb_arr_rq1[i]) { |
| 393 | ehea_error("%s: no mem for skb/%d wqes filled", |
| 394 | dev->name, i); |
| 395 | ret = -ENOMEM; |
| 396 | goto out; |
| 397 | } |
| 398 | } |
| 399 | /* Ring doorbell */ |
| 400 | ehea_update_rq1a(pr->qp, nr_rq1a); |
| 401 | out: |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | static int ehea_refill_rq_def(struct ehea_port_res *pr, |
| 406 | struct ehea_q_skb_arr *q_skba, int rq_nr, |
| 407 | int num_wqes, int wqe_type, int packet_size) |
| 408 | { |
| 409 | struct net_device *dev = pr->port->netdev; |
| 410 | struct ehea_qp *qp = pr->qp; |
| 411 | struct sk_buff **skb_arr = q_skba->arr; |
| 412 | struct ehea_rwqe *rwqe; |
| 413 | int i, index, max_index_mask, fill_wqes; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 414 | int adder = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 415 | int ret = 0; |
| 416 | |
| 417 | fill_wqes = q_skba->os_skbs + num_wqes; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 418 | q_skba->os_skbs = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 419 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 420 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
| 421 | q_skba->os_skbs = fill_wqes; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 422 | return ret; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 423 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 424 | |
| 425 | index = q_skba->index; |
| 426 | max_index_mask = q_skba->len - 1; |
| 427 | for (i = 0; i < fill_wqes; i++) { |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 428 | u64 tmp_addr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 429 | struct sk_buff *skb = netdev_alloc_skb(dev, packet_size); |
| 430 | if (!skb) { |
| 431 | ehea_error("%s: no mem for skb/%d wqes filled", |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 432 | pr->port->netdev->name, i); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 433 | q_skba->os_skbs = fill_wqes - i; |
| 434 | ret = -ENOMEM; |
| 435 | break; |
| 436 | } |
| 437 | skb_reserve(skb, NET_IP_ALIGN); |
| 438 | |
| 439 | skb_arr[index] = skb; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 440 | tmp_addr = ehea_map_vaddr(skb->data); |
| 441 | if (tmp_addr == -1) { |
| 442 | dev_kfree_skb(skb); |
| 443 | q_skba->os_skbs = fill_wqes - i; |
| 444 | ret = 0; |
| 445 | break; |
| 446 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 447 | |
| 448 | rwqe = ehea_get_next_rwqe(qp, rq_nr); |
| 449 | rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type) |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 450 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 451 | rwqe->sg_list[0].l_key = pr->recv_mr.lkey; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 452 | rwqe->sg_list[0].vaddr = tmp_addr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 453 | rwqe->sg_list[0].len = packet_size; |
| 454 | rwqe->data_segments = 1; |
| 455 | |
| 456 | index++; |
| 457 | index &= max_index_mask; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 458 | adder++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 459 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 460 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 461 | q_skba->index = index; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 462 | if (adder == 0) |
| 463 | goto out; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 464 | |
| 465 | /* Ring doorbell */ |
| 466 | iosync(); |
| 467 | if (rq_nr == 2) |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 468 | ehea_update_rq2a(pr->qp, adder); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 469 | else |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 470 | ehea_update_rq3a(pr->qp, adder); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 471 | out: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 472 | return ret; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes) |
| 477 | { |
| 478 | return ehea_refill_rq_def(pr, &pr->rq2_skba, 2, |
| 479 | nr_of_wqes, EHEA_RWQE2_TYPE, |
| 480 | EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes) |
| 485 | { |
| 486 | return ehea_refill_rq_def(pr, &pr->rq3_skba, 3, |
| 487 | nr_of_wqes, EHEA_RWQE3_TYPE, |
| 488 | EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN); |
| 489 | } |
| 490 | |
| 491 | static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num) |
| 492 | { |
| 493 | *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5; |
| 494 | if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0) |
| 495 | return 0; |
| 496 | if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) && |
| 497 | (cqe->header_length == 0)) |
| 498 | return 0; |
| 499 | return -EINVAL; |
| 500 | } |
| 501 | |
| 502 | static inline void ehea_fill_skb(struct net_device *dev, |
| 503 | struct sk_buff *skb, struct ehea_cqe *cqe) |
| 504 | { |
| 505 | int length = cqe->num_bytes_transfered - 4; /*remove CRC */ |
| 506 | |
| 507 | skb_put(skb, length); |
| 508 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 509 | skb->protocol = eth_type_trans(skb, dev); |
| 510 | } |
| 511 | |
| 512 | static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array, |
| 513 | int arr_len, |
| 514 | struct ehea_cqe *cqe) |
| 515 | { |
| 516 | int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); |
| 517 | struct sk_buff *skb; |
| 518 | void *pref; |
| 519 | int x; |
| 520 | |
| 521 | x = skb_index + 1; |
| 522 | x &= (arr_len - 1); |
| 523 | |
| 524 | pref = skb_array[x]; |
| 525 | prefetchw(pref); |
| 526 | prefetchw(pref + EHEA_CACHE_LINE); |
| 527 | |
| 528 | pref = (skb_array[x]->data); |
| 529 | prefetch(pref); |
| 530 | prefetch(pref + EHEA_CACHE_LINE); |
| 531 | prefetch(pref + EHEA_CACHE_LINE * 2); |
| 532 | prefetch(pref + EHEA_CACHE_LINE * 3); |
| 533 | skb = skb_array[skb_index]; |
| 534 | skb_array[skb_index] = NULL; |
| 535 | return skb; |
| 536 | } |
| 537 | |
| 538 | static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array, |
| 539 | int arr_len, int wqe_index) |
| 540 | { |
| 541 | struct sk_buff *skb; |
| 542 | void *pref; |
| 543 | int x; |
| 544 | |
| 545 | x = wqe_index + 1; |
| 546 | x &= (arr_len - 1); |
| 547 | |
| 548 | pref = skb_array[x]; |
| 549 | prefetchw(pref); |
| 550 | prefetchw(pref + EHEA_CACHE_LINE); |
| 551 | |
| 552 | pref = (skb_array[x]->data); |
| 553 | prefetchw(pref); |
| 554 | prefetchw(pref + EHEA_CACHE_LINE); |
| 555 | |
| 556 | skb = skb_array[wqe_index]; |
| 557 | skb_array[wqe_index] = NULL; |
| 558 | return skb; |
| 559 | } |
| 560 | |
| 561 | static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq, |
| 562 | struct ehea_cqe *cqe, int *processed_rq2, |
| 563 | int *processed_rq3) |
| 564 | { |
| 565 | struct sk_buff *skb; |
| 566 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 567 | if (cqe->status & EHEA_CQE_STAT_ERR_TCP) |
| 568 | pr->p_stats.err_tcp_cksum++; |
| 569 | if (cqe->status & EHEA_CQE_STAT_ERR_IP) |
| 570 | pr->p_stats.err_ip_cksum++; |
| 571 | if (cqe->status & EHEA_CQE_STAT_ERR_CRC) |
| 572 | pr->p_stats.err_frame_crc++; |
| 573 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 574 | if (rq == 2) { |
| 575 | *processed_rq2 += 1; |
| 576 | skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe); |
| 577 | dev_kfree_skb(skb); |
| 578 | } else if (rq == 3) { |
| 579 | *processed_rq3 += 1; |
| 580 | skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe); |
| 581 | dev_kfree_skb(skb); |
| 582 | } |
| 583 | |
| 584 | if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) { |
Thomas Klein | 58dd825 | 2007-11-21 17:42:27 +0100 | [diff] [blame] | 585 | if (netif_msg_rx_err(pr->port)) { |
| 586 | ehea_error("Critical receive error for QP %d. " |
| 587 | "Resetting port.", pr->qp->init_attr.qp_nr); |
| 588 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 589 | } |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 590 | schedule_work(&pr->port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 591 | return 1; |
| 592 | } |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 597 | static int get_skb_hdr(struct sk_buff *skb, void **iphdr, |
| 598 | void **tcph, u64 *hdr_flags, void *priv) |
| 599 | { |
| 600 | struct ehea_cqe *cqe = priv; |
| 601 | unsigned int ip_len; |
| 602 | struct iphdr *iph; |
| 603 | |
| 604 | /* non tcp/udp packets */ |
| 605 | if (!cqe->header_length) |
| 606 | return -1; |
| 607 | |
| 608 | /* non tcp packet */ |
| 609 | skb_reset_network_header(skb); |
| 610 | iph = ip_hdr(skb); |
| 611 | if (iph->protocol != IPPROTO_TCP) |
| 612 | return -1; |
| 613 | |
| 614 | ip_len = ip_hdrlen(skb); |
| 615 | skb_set_transport_header(skb, ip_len); |
| 616 | *tcph = tcp_hdr(skb); |
| 617 | |
| 618 | /* check if ip header and tcp header are complete */ |
| 619 | if (iph->tot_len < ip_len + tcp_hdrlen(skb)) |
| 620 | return -1; |
| 621 | |
| 622 | *hdr_flags = LRO_IPV4 | LRO_TCP; |
| 623 | *iphdr = iph; |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe, |
| 629 | struct sk_buff *skb) |
| 630 | { |
| 631 | int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) |
| 632 | && pr->port->vgrp; |
| 633 | |
| 634 | if (use_lro) { |
| 635 | if (vlan_extracted) |
| 636 | lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb, |
| 637 | pr->port->vgrp, |
| 638 | cqe->vlan_tag, |
| 639 | cqe); |
| 640 | else |
| 641 | lro_receive_skb(&pr->lro_mgr, skb, cqe); |
| 642 | } else { |
| 643 | if (vlan_extracted) |
| 644 | vlan_hwaccel_receive_skb(skb, pr->port->vgrp, |
| 645 | cqe->vlan_tag); |
| 646 | else |
| 647 | netif_receive_skb(skb); |
| 648 | } |
| 649 | } |
| 650 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 651 | static int ehea_proc_rwqes(struct net_device *dev, |
| 652 | struct ehea_port_res *pr, |
| 653 | int budget) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 654 | { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 655 | struct ehea_port *port = pr->port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 656 | struct ehea_qp *qp = pr->qp; |
| 657 | struct ehea_cqe *cqe; |
| 658 | struct sk_buff *skb; |
| 659 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 660 | struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr; |
| 661 | struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr; |
| 662 | int skb_arr_rq1_len = pr->rq1_skba.len; |
| 663 | int skb_arr_rq2_len = pr->rq2_skba.len; |
| 664 | int skb_arr_rq3_len = pr->rq3_skba.len; |
| 665 | int processed, processed_rq1, processed_rq2, processed_rq3; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 666 | int wqe_index, last_wqe_index, rq, port_reset; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 667 | |
| 668 | processed = processed_rq1 = processed_rq2 = processed_rq3 = 0; |
| 669 | last_wqe_index = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 670 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 671 | cqe = ehea_poll_rq1(qp, &wqe_index); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 672 | while ((processed < budget) && cqe) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 673 | ehea_inc_rq1(qp); |
| 674 | processed_rq1++; |
| 675 | processed++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 676 | if (netif_msg_rx_status(port)) |
| 677 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 678 | |
| 679 | last_wqe_index = wqe_index; |
| 680 | rmb(); |
| 681 | if (!ehea_check_cqe(cqe, &rq)) { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 682 | if (rq == 1) { |
| 683 | /* LL RQ1 */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 684 | skb = get_skb_by_index_ll(skb_arr_rq1, |
| 685 | skb_arr_rq1_len, |
| 686 | wqe_index); |
| 687 | if (unlikely(!skb)) { |
| 688 | if (netif_msg_rx_err(port)) |
| 689 | ehea_error("LL rq1: skb=NULL"); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 690 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 691 | skb = netdev_alloc_skb(dev, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 692 | EHEA_L_PKT_SIZE); |
| 693 | if (!skb) |
| 694 | break; |
| 695 | } |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 696 | skb_copy_to_linear_data(skb, ((char *)cqe) + 64, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 697 | cqe->num_bytes_transfered - 4); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 698 | ehea_fill_skb(dev, skb, cqe); |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 699 | } else if (rq == 2) { |
| 700 | /* RQ2 */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 701 | skb = get_skb_by_index(skb_arr_rq2, |
| 702 | skb_arr_rq2_len, cqe); |
| 703 | if (unlikely(!skb)) { |
| 704 | if (netif_msg_rx_err(port)) |
| 705 | ehea_error("rq2: skb=NULL"); |
| 706 | break; |
| 707 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 708 | ehea_fill_skb(dev, skb, cqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 709 | processed_rq2++; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 710 | } else { |
| 711 | /* RQ3 */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 712 | skb = get_skb_by_index(skb_arr_rq3, |
| 713 | skb_arr_rq3_len, cqe); |
| 714 | if (unlikely(!skb)) { |
| 715 | if (netif_msg_rx_err(port)) |
| 716 | ehea_error("rq3: skb=NULL"); |
| 717 | break; |
| 718 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 719 | ehea_fill_skb(dev, skb, cqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 720 | processed_rq3++; |
| 721 | } |
| 722 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 723 | ehea_proc_skb(pr, cqe, skb); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 724 | dev->last_rx = jiffies; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 725 | } else { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 726 | pr->p_stats.poll_receive_errors++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 727 | port_reset = ehea_treat_poll_error(pr, rq, cqe, |
| 728 | &processed_rq2, |
| 729 | &processed_rq3); |
| 730 | if (port_reset) |
| 731 | break; |
| 732 | } |
| 733 | cqe = ehea_poll_rq1(qp, &wqe_index); |
| 734 | } |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 735 | if (use_lro) |
| 736 | lro_flush_all(&pr->lro_mgr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 737 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 738 | pr->rx_packets += processed; |
| 739 | |
| 740 | ehea_refill_rq1(pr, last_wqe_index, processed_rq1); |
| 741 | ehea_refill_rq2(pr, processed_rq2); |
| 742 | ehea_refill_rq3(pr, processed_rq3); |
| 743 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 744 | return processed; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 747 | static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 748 | { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 749 | struct sk_buff *skb; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 750 | struct ehea_cq *send_cq = pr->send_cq; |
| 751 | struct ehea_cqe *cqe; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 752 | int quota = my_quota; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 753 | int cqe_counter = 0; |
| 754 | int swqe_av = 0; |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 755 | int index; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 756 | unsigned long flags; |
| 757 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 758 | cqe = ehea_poll_cq(send_cq); |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 759 | while (cqe && (quota > 0)) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 760 | ehea_inc_cq(send_cq); |
| 761 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 762 | cqe_counter++; |
| 763 | rmb(); |
| 764 | if (cqe->status & EHEA_CQE_STAT_ERR_MASK) { |
| 765 | ehea_error("Send Completion Error: Resetting port"); |
| 766 | if (netif_msg_tx_err(pr->port)) |
| 767 | ehea_dump(cqe, sizeof(*cqe), "Send CQE"); |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 768 | schedule_work(&pr->port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | |
| 772 | if (netif_msg_tx_done(pr->port)) |
| 773 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 774 | |
| 775 | if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id) |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 776 | == EHEA_SWQE2_TYPE)) { |
| 777 | |
| 778 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); |
| 779 | skb = pr->sq_skba.arr[index]; |
| 780 | dev_kfree_skb(skb); |
| 781 | pr->sq_skba.arr[index] = NULL; |
| 782 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 783 | |
| 784 | swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); |
| 785 | quota--; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 786 | |
| 787 | cqe = ehea_poll_cq(send_cq); |
| 788 | }; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 789 | |
| 790 | ehea_update_feca(send_cq, cqe_counter); |
| 791 | atomic_add(swqe_av, &pr->swqe_avail); |
| 792 | |
| 793 | spin_lock_irqsave(&pr->netif_queue, flags); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 794 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 795 | if (pr->queue_stopped && (atomic_read(&pr->swqe_avail) |
| 796 | >= pr->swqe_refill_th)) { |
| 797 | netif_wake_queue(pr->port->netdev); |
| 798 | pr->queue_stopped = 0; |
| 799 | } |
| 800 | spin_unlock_irqrestore(&pr->netif_queue, flags); |
| 801 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 802 | return cqe; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 805 | #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16 |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 806 | #define EHEA_POLL_MAX_CQES 65535 |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 807 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 808 | static int ehea_poll(struct napi_struct *napi, int budget) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 809 | { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 810 | struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, |
| 811 | napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 812 | struct net_device *dev = pr->port->netdev; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 813 | struct ehea_cqe *cqe; |
| 814 | struct ehea_cqe *cqe_skb = NULL; |
| 815 | int force_irq, wqe_index; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 816 | int rx = 0; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 817 | |
| 818 | force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 819 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 820 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 821 | if (!force_irq) |
| 822 | rx += ehea_proc_rwqes(dev, pr, budget - rx); |
| 823 | |
| 824 | while ((rx != budget) || force_irq) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 825 | pr->poll_counter = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 826 | force_irq = 0; |
| 827 | netif_rx_complete(dev, napi); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 828 | ehea_reset_cq_ep(pr->recv_cq); |
| 829 | ehea_reset_cq_ep(pr->send_cq); |
| 830 | ehea_reset_cq_n1(pr->recv_cq); |
| 831 | ehea_reset_cq_n1(pr->send_cq); |
| 832 | cqe = ehea_poll_rq1(pr->qp, &wqe_index); |
| 833 | cqe_skb = ehea_poll_cq(pr->send_cq); |
| 834 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 835 | if (!cqe && !cqe_skb) |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 836 | return rx; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 837 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 838 | if (!netif_rx_reschedule(dev, napi)) |
| 839 | return rx; |
| 840 | |
| 841 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
| 842 | rx += ehea_proc_rwqes(dev, pr, budget - rx); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 843 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 844 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 845 | pr->poll_counter++; |
| 846 | return rx; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 847 | } |
| 848 | |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 849 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 850 | static void ehea_netpoll(struct net_device *dev) |
| 851 | { |
| 852 | struct ehea_port *port = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 853 | int i; |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 854 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 855 | for (i = 0; i < port->num_def_qps; i++) |
| 856 | netif_rx_schedule(dev, &port->port_res[i].napi); |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 857 | } |
| 858 | #endif |
| 859 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 860 | static irqreturn_t ehea_recv_irq_handler(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 861 | { |
| 862 | struct ehea_port_res *pr = param; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 863 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 864 | netif_rx_schedule(pr->port->netdev, &pr->napi); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 865 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 866 | return IRQ_HANDLED; |
| 867 | } |
| 868 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 869 | static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 870 | { |
| 871 | struct ehea_port *port = param; |
| 872 | struct ehea_eqe *eqe; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 873 | struct ehea_qp *qp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 874 | u32 qp_token; |
| 875 | |
| 876 | eqe = ehea_poll_eq(port->qp_eq); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 877 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 878 | while (eqe) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 879 | qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 880 | ehea_error("QP aff_err: entry=0x%lx, token=0x%x", |
| 881 | eqe->entry, qp_token); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 882 | |
| 883 | qp = port->port_res[qp_token].qp; |
| 884 | ehea_error_data(port->adapter, qp->fw_handle); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 885 | eqe = ehea_poll_eq(port->qp_eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 886 | } |
| 887 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 888 | schedule_work(&port->reset_task); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 889 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 890 | return IRQ_HANDLED; |
| 891 | } |
| 892 | |
| 893 | static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter, |
| 894 | int logical_port) |
| 895 | { |
| 896 | int i; |
| 897 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 898 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Thomas Klein | 41b69c7 | 2007-01-22 12:55:20 +0100 | [diff] [blame] | 899 | if (adapter->port[i]) |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 900 | if (adapter->port[i]->logical_port_id == logical_port) |
Thomas Klein | 41b69c7 | 2007-01-22 12:55:20 +0100 | [diff] [blame] | 901 | return adapter->port[i]; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 902 | return NULL; |
| 903 | } |
| 904 | |
| 905 | int ehea_sense_port_attr(struct ehea_port *port) |
| 906 | { |
| 907 | int ret; |
| 908 | u64 hret; |
| 909 | struct hcp_ehea_port_cb0 *cb0; |
| 910 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 911 | /* may be called via ehea_neq_tasklet() */ |
| 912 | cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
| 913 | if (!cb0) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 914 | ehea_error("no mem for cb0"); |
| 915 | ret = -ENOMEM; |
| 916 | goto out; |
| 917 | } |
| 918 | |
| 919 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 920 | port->logical_port_id, H_PORT_CB0, |
| 921 | EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF), |
| 922 | cb0); |
| 923 | if (hret != H_SUCCESS) { |
| 924 | ret = -EIO; |
| 925 | goto out_free; |
| 926 | } |
| 927 | |
| 928 | /* MAC address */ |
| 929 | port->mac_addr = cb0->port_mac_addr << 16; |
| 930 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 931 | if (!is_valid_ether_addr((u8 *)&port->mac_addr)) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 932 | ret = -EADDRNOTAVAIL; |
| 933 | goto out_free; |
| 934 | } |
| 935 | |
| 936 | /* Port speed */ |
| 937 | switch (cb0->port_speed) { |
| 938 | case H_SPEED_10M_H: |
| 939 | port->port_speed = EHEA_SPEED_10M; |
| 940 | port->full_duplex = 0; |
| 941 | break; |
| 942 | case H_SPEED_10M_F: |
| 943 | port->port_speed = EHEA_SPEED_10M; |
| 944 | port->full_duplex = 1; |
| 945 | break; |
| 946 | case H_SPEED_100M_H: |
| 947 | port->port_speed = EHEA_SPEED_100M; |
| 948 | port->full_duplex = 0; |
| 949 | break; |
| 950 | case H_SPEED_100M_F: |
| 951 | port->port_speed = EHEA_SPEED_100M; |
| 952 | port->full_duplex = 1; |
| 953 | break; |
| 954 | case H_SPEED_1G_F: |
| 955 | port->port_speed = EHEA_SPEED_1G; |
| 956 | port->full_duplex = 1; |
| 957 | break; |
| 958 | case H_SPEED_10G_F: |
| 959 | port->port_speed = EHEA_SPEED_10G; |
| 960 | port->full_duplex = 1; |
| 961 | break; |
| 962 | default: |
| 963 | port->port_speed = 0; |
| 964 | port->full_duplex = 0; |
| 965 | break; |
| 966 | } |
| 967 | |
Thomas Klein | e919b59 | 2007-01-22 12:53:20 +0100 | [diff] [blame] | 968 | port->autoneg = 1; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 969 | port->num_mcs = cb0->num_default_qps; |
Thomas Klein | e919b59 | 2007-01-22 12:53:20 +0100 | [diff] [blame] | 970 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 971 | /* Number of default QPs */ |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 972 | if (use_mcs) |
| 973 | port->num_def_qps = cb0->num_default_qps; |
| 974 | else |
| 975 | port->num_def_qps = 1; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 976 | |
| 977 | if (!port->num_def_qps) { |
| 978 | ret = -EINVAL; |
| 979 | goto out_free; |
| 980 | } |
| 981 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 982 | port->num_tx_qps = num_tx_qps; |
| 983 | |
| 984 | if (port->num_def_qps >= port->num_tx_qps) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 985 | port->num_add_tx_qps = 0; |
| 986 | else |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 987 | port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 988 | |
| 989 | ret = 0; |
| 990 | out_free: |
| 991 | if (ret || netif_msg_probe(port)) |
| 992 | ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr"); |
| 993 | kfree(cb0); |
| 994 | out: |
| 995 | return ret; |
| 996 | } |
| 997 | |
| 998 | int ehea_set_portspeed(struct ehea_port *port, u32 port_speed) |
| 999 | { |
| 1000 | struct hcp_ehea_port_cb4 *cb4; |
| 1001 | u64 hret; |
| 1002 | int ret = 0; |
| 1003 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1004 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1005 | if (!cb4) { |
| 1006 | ehea_error("no mem for cb4"); |
| 1007 | ret = -ENOMEM; |
| 1008 | goto out; |
| 1009 | } |
| 1010 | |
| 1011 | cb4->port_speed = port_speed; |
| 1012 | |
| 1013 | netif_carrier_off(port->netdev); |
| 1014 | |
| 1015 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1016 | port->logical_port_id, |
| 1017 | H_PORT_CB4, H_PORT_CB4_SPEED, cb4); |
| 1018 | if (hret == H_SUCCESS) { |
| 1019 | port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0; |
| 1020 | |
| 1021 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 1022 | port->logical_port_id, |
| 1023 | H_PORT_CB4, H_PORT_CB4_SPEED, |
| 1024 | cb4); |
| 1025 | if (hret == H_SUCCESS) { |
| 1026 | switch (cb4->port_speed) { |
| 1027 | case H_SPEED_10M_H: |
| 1028 | port->port_speed = EHEA_SPEED_10M; |
| 1029 | port->full_duplex = 0; |
| 1030 | break; |
| 1031 | case H_SPEED_10M_F: |
| 1032 | port->port_speed = EHEA_SPEED_10M; |
| 1033 | port->full_duplex = 1; |
| 1034 | break; |
| 1035 | case H_SPEED_100M_H: |
| 1036 | port->port_speed = EHEA_SPEED_100M; |
| 1037 | port->full_duplex = 0; |
| 1038 | break; |
| 1039 | case H_SPEED_100M_F: |
| 1040 | port->port_speed = EHEA_SPEED_100M; |
| 1041 | port->full_duplex = 1; |
| 1042 | break; |
| 1043 | case H_SPEED_1G_F: |
| 1044 | port->port_speed = EHEA_SPEED_1G; |
| 1045 | port->full_duplex = 1; |
| 1046 | break; |
| 1047 | case H_SPEED_10G_F: |
| 1048 | port->port_speed = EHEA_SPEED_10G; |
| 1049 | port->full_duplex = 1; |
| 1050 | break; |
| 1051 | default: |
| 1052 | port->port_speed = 0; |
| 1053 | port->full_duplex = 0; |
| 1054 | break; |
| 1055 | } |
| 1056 | } else { |
| 1057 | ehea_error("Failed sensing port speed"); |
| 1058 | ret = -EIO; |
| 1059 | } |
| 1060 | } else { |
| 1061 | if (hret == H_AUTHORITY) { |
Thomas Klein | 7674a58 | 2007-01-22 12:54:20 +0100 | [diff] [blame] | 1062 | ehea_info("Hypervisor denied setting port speed"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1063 | ret = -EPERM; |
| 1064 | } else { |
| 1065 | ret = -EIO; |
| 1066 | ehea_error("Failed setting port speed"); |
| 1067 | } |
| 1068 | } |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 1069 | if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP)) |
| 1070 | netif_carrier_on(port->netdev); |
| 1071 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1072 | kfree(cb4); |
| 1073 | out: |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe) |
| 1078 | { |
| 1079 | int ret; |
| 1080 | u8 ec; |
| 1081 | u8 portnum; |
| 1082 | struct ehea_port *port; |
| 1083 | |
| 1084 | ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe); |
| 1085 | portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe); |
| 1086 | port = ehea_get_port(adapter, portnum); |
| 1087 | |
| 1088 | switch (ec) { |
| 1089 | case EHEA_EC_PORTSTATE_CHG: /* port state change */ |
| 1090 | |
| 1091 | if (!port) { |
| 1092 | ehea_error("unknown portnum %x", portnum); |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) { |
| 1097 | if (!netif_carrier_ok(port->netdev)) { |
Jan-Bernd Themann | 1e1675c | 2006-10-25 13:11:42 +0200 | [diff] [blame] | 1098 | ret = ehea_sense_port_attr(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1099 | if (ret) { |
| 1100 | ehea_error("failed resensing port " |
| 1101 | "attributes"); |
| 1102 | break; |
| 1103 | } |
| 1104 | |
| 1105 | if (netif_msg_link(port)) |
| 1106 | ehea_info("%s: Logical port up: %dMbps " |
| 1107 | "%s Duplex", |
| 1108 | port->netdev->name, |
| 1109 | port->port_speed, |
| 1110 | port->full_duplex == |
| 1111 | 1 ? "Full" : "Half"); |
| 1112 | |
| 1113 | netif_carrier_on(port->netdev); |
| 1114 | netif_wake_queue(port->netdev); |
| 1115 | } |
| 1116 | } else |
| 1117 | if (netif_carrier_ok(port->netdev)) { |
| 1118 | if (netif_msg_link(port)) |
| 1119 | ehea_info("%s: Logical port down", |
| 1120 | port->netdev->name); |
| 1121 | netif_carrier_off(port->netdev); |
| 1122 | netif_stop_queue(port->netdev); |
| 1123 | } |
| 1124 | |
| 1125 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) { |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 1126 | port->phy_link = EHEA_PHY_LINK_UP; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1127 | if (netif_msg_link(port)) |
| 1128 | ehea_info("%s: Physical port up", |
| 1129 | port->netdev->name); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 1130 | if (prop_carrier_state) |
| 1131 | netif_carrier_on(port->netdev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1132 | } else { |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 1133 | port->phy_link = EHEA_PHY_LINK_DOWN; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1134 | if (netif_msg_link(port)) |
| 1135 | ehea_info("%s: Physical port down", |
| 1136 | port->netdev->name); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 1137 | if (prop_carrier_state) |
| 1138 | netif_carrier_off(port->netdev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe)) |
| 1142 | ehea_info("External switch port is primary port"); |
| 1143 | else |
| 1144 | ehea_info("External switch port is backup port"); |
| 1145 | |
| 1146 | break; |
| 1147 | case EHEA_EC_ADAPTER_MALFUNC: |
| 1148 | ehea_error("Adapter malfunction"); |
| 1149 | break; |
| 1150 | case EHEA_EC_PORT_MALFUNC: |
| 1151 | ehea_info("Port malfunction: Device: %s", port->netdev->name); |
| 1152 | netif_carrier_off(port->netdev); |
| 1153 | netif_stop_queue(port->netdev); |
| 1154 | break; |
| 1155 | default: |
Jan-Bernd Themann | bff0a55 | 2006-10-05 16:53:14 +0200 | [diff] [blame] | 1156 | ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | static void ehea_neq_tasklet(unsigned long data) |
| 1162 | { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1163 | struct ehea_adapter *adapter = (struct ehea_adapter *)data; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1164 | struct ehea_eqe *eqe; |
| 1165 | u64 event_mask; |
| 1166 | |
| 1167 | eqe = ehea_poll_eq(adapter->neq); |
| 1168 | ehea_debug("eqe=%p", eqe); |
| 1169 | |
| 1170 | while (eqe) { |
| 1171 | ehea_debug("*eqe=%lx", eqe->entry); |
| 1172 | ehea_parse_eqe(adapter, eqe->entry); |
| 1173 | eqe = ehea_poll_eq(adapter->neq); |
| 1174 | ehea_debug("next eqe=%p", eqe); |
| 1175 | } |
| 1176 | |
| 1177 | event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1) |
| 1178 | | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1) |
| 1179 | | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1); |
| 1180 | |
| 1181 | ehea_h_reset_events(adapter->handle, |
| 1182 | adapter->neq->fw_handle, event_mask); |
| 1183 | } |
| 1184 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1185 | static irqreturn_t ehea_interrupt_neq(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1186 | { |
| 1187 | struct ehea_adapter *adapter = param; |
| 1188 | tasklet_hi_schedule(&adapter->neq_tasklet); |
| 1189 | return IRQ_HANDLED; |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | static int ehea_fill_port_res(struct ehea_port_res *pr) |
| 1194 | { |
| 1195 | int ret; |
| 1196 | struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr; |
| 1197 | |
| 1198 | ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1 |
| 1199 | - init_attr->act_nr_rwqes_rq2 |
| 1200 | - init_attr->act_nr_rwqes_rq3 - 1); |
| 1201 | |
| 1202 | ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1); |
| 1203 | |
| 1204 | ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1); |
| 1205 | |
| 1206 | return ret; |
| 1207 | } |
| 1208 | |
| 1209 | static int ehea_reg_interrupts(struct net_device *dev) |
| 1210 | { |
| 1211 | struct ehea_port *port = netdev_priv(dev); |
| 1212 | struct ehea_port_res *pr; |
| 1213 | int i, ret; |
| 1214 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1215 | |
| 1216 | snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff", |
| 1217 | dev->name); |
| 1218 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1219 | ret = ibmebus_request_irq(port->qp_eq->attr.ist1, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1220 | ehea_qp_aff_irq_handler, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 1221 | IRQF_DISABLED, port->int_aff_name, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1222 | if (ret) { |
| 1223 | ehea_error("failed registering irq for qp_aff_irq_handler:" |
| 1224 | "ist=%X", port->qp_eq->attr.ist1); |
| 1225 | goto out_free_qpeq; |
| 1226 | } |
| 1227 | |
| 1228 | if (netif_msg_ifup(port)) |
| 1229 | ehea_info("irq_handle 0x%X for function qp_aff_irq_handler " |
| 1230 | "registered", port->qp_eq->attr.ist1); |
| 1231 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1232 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1233 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 1234 | pr = &port->port_res[i]; |
| 1235 | snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1236 | "%s-queue%d", dev->name, i); |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1237 | ret = ibmebus_request_irq(pr->eq->attr.ist1, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1238 | ehea_recv_irq_handler, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 1239 | IRQF_DISABLED, pr->int_send_name, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1240 | pr); |
| 1241 | if (ret) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1242 | ehea_error("failed registering irq for ehea_queue " |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1243 | "port_res_nr:%d, ist=%X", i, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1244 | pr->eq->attr.ist1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1245 | goto out_free_req; |
| 1246 | } |
| 1247 | if (netif_msg_ifup(port)) |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1248 | ehea_info("irq_handle 0x%X for function ehea_queue_int " |
| 1249 | "%d registered", pr->eq->attr.ist1, i); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1250 | } |
| 1251 | out: |
| 1252 | return ret; |
| 1253 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1254 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1255 | out_free_req: |
| 1256 | while (--i >= 0) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1257 | u32 ist = port->port_res[i].eq->attr.ist1; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1258 | ibmebus_free_irq(ist, &port->port_res[i]); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1259 | } |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1260 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1261 | out_free_qpeq: |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1262 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1263 | i = port->num_def_qps; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1264 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1265 | goto out; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1266 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static void ehea_free_interrupts(struct net_device *dev) |
| 1270 | { |
| 1271 | struct ehea_port *port = netdev_priv(dev); |
| 1272 | struct ehea_port_res *pr; |
| 1273 | int i; |
| 1274 | |
| 1275 | /* send */ |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1276 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1277 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 1278 | pr = &port->port_res[i]; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1279 | ibmebus_free_irq(pr->eq->attr.ist1, pr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1280 | if (netif_msg_intr(port)) |
| 1281 | ehea_info("free send irq for res %d with handle 0x%X", |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1282 | i, pr->eq->attr.ist1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /* associated events */ |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1286 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1287 | if (netif_msg_intr(port)) |
| 1288 | ehea_info("associated event interrupt for handle 0x%X freed", |
| 1289 | port->qp_eq->attr.ist1); |
| 1290 | } |
| 1291 | |
| 1292 | static int ehea_configure_port(struct ehea_port *port) |
| 1293 | { |
| 1294 | int ret, i; |
| 1295 | u64 hret, mask; |
| 1296 | struct hcp_ehea_port_cb0 *cb0; |
| 1297 | |
| 1298 | ret = -ENOMEM; |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1299 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1300 | if (!cb0) |
| 1301 | goto out; |
| 1302 | |
| 1303 | cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1) |
| 1304 | | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1) |
| 1305 | | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1) |
| 1306 | | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1) |
| 1307 | | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER, |
| 1308 | PXLY_RC_VLAN_FILTER) |
| 1309 | | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); |
| 1310 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1311 | for (i = 0; i < port->num_mcs; i++) |
| 1312 | if (use_mcs) |
| 1313 | cb0->default_qpn_arr[i] = |
| 1314 | port->port_res[i].qp->init_attr.qp_nr; |
| 1315 | else |
| 1316 | cb0->default_qpn_arr[i] = |
| 1317 | port->port_res[0].qp->init_attr.qp_nr; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1318 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1319 | if (netif_msg_ifup(port)) |
| 1320 | ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); |
| 1321 | |
| 1322 | mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1) |
| 1323 | | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1); |
| 1324 | |
| 1325 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1326 | port->logical_port_id, |
| 1327 | H_PORT_CB0, mask, cb0); |
| 1328 | ret = -EIO; |
| 1329 | if (hret != H_SUCCESS) |
| 1330 | goto out_free; |
| 1331 | |
| 1332 | ret = 0; |
| 1333 | |
| 1334 | out_free: |
| 1335 | kfree(cb0); |
| 1336 | out: |
| 1337 | return ret; |
| 1338 | } |
| 1339 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1340 | int ehea_gen_smrs(struct ehea_port_res *pr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1341 | { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1342 | int ret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1343 | struct ehea_adapter *adapter = pr->port->adapter; |
| 1344 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1345 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr); |
| 1346 | if (ret) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1347 | goto out; |
| 1348 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1349 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr); |
| 1350 | if (ret) |
| 1351 | goto out_free; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1352 | |
| 1353 | return 0; |
| 1354 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1355 | out_free: |
| 1356 | ehea_rem_mr(&pr->send_mr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1357 | out: |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1358 | ehea_error("Generating SMRS failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1359 | return -EIO; |
| 1360 | } |
| 1361 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1362 | int ehea_rem_smrs(struct ehea_port_res *pr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1363 | { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1364 | if ((ehea_rem_mr(&pr->send_mr)) |
| 1365 | || (ehea_rem_mr(&pr->recv_mr))) |
| 1366 | return -EIO; |
| 1367 | else |
| 1368 | return 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries) |
| 1372 | { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1373 | int arr_size = sizeof(void *) * max_q_entries; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1374 | |
| 1375 | q_skba->arr = vmalloc(arr_size); |
| 1376 | if (!q_skba->arr) |
| 1377 | return -ENOMEM; |
| 1378 | |
| 1379 | memset(q_skba->arr, 0, arr_size); |
| 1380 | |
| 1381 | q_skba->len = max_q_entries; |
| 1382 | q_skba->index = 0; |
| 1383 | q_skba->os_skbs = 0; |
| 1384 | |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
| 1388 | static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr, |
| 1389 | struct port_res_cfg *pr_cfg, int queue_token) |
| 1390 | { |
| 1391 | struct ehea_adapter *adapter = port->adapter; |
| 1392 | enum ehea_eq_type eq_type = EHEA_EQ; |
| 1393 | struct ehea_qp_init_attr *init_attr = NULL; |
| 1394 | int ret = -EIO; |
| 1395 | |
| 1396 | memset(pr, 0, sizeof(struct ehea_port_res)); |
| 1397 | |
| 1398 | pr->port = port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1399 | spin_lock_init(&pr->xmit_lock); |
| 1400 | spin_lock_init(&pr->netif_queue); |
| 1401 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1402 | pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0); |
| 1403 | if (!pr->eq) { |
| 1404 | ehea_error("create_eq failed (eq)"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1405 | goto out_free; |
| 1406 | } |
| 1407 | |
| 1408 | pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1409 | pr->eq->fw_handle, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1410 | port->logical_port_id); |
| 1411 | if (!pr->recv_cq) { |
| 1412 | ehea_error("create_cq failed (cq_recv)"); |
| 1413 | goto out_free; |
| 1414 | } |
| 1415 | |
| 1416 | pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1417 | pr->eq->fw_handle, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1418 | port->logical_port_id); |
| 1419 | if (!pr->send_cq) { |
| 1420 | ehea_error("create_cq failed (cq_send)"); |
| 1421 | goto out_free; |
| 1422 | } |
| 1423 | |
| 1424 | if (netif_msg_ifup(port)) |
| 1425 | ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d", |
| 1426 | pr->send_cq->attr.act_nr_of_cqes, |
| 1427 | pr->recv_cq->attr.act_nr_of_cqes); |
| 1428 | |
| 1429 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 1430 | if (!init_attr) { |
| 1431 | ret = -ENOMEM; |
| 1432 | ehea_error("no mem for ehea_qp_init_attr"); |
| 1433 | goto out_free; |
| 1434 | } |
| 1435 | |
| 1436 | init_attr->low_lat_rq1 = 1; |
| 1437 | init_attr->signalingtype = 1; /* generate CQE if specified in WQE */ |
| 1438 | init_attr->rq_count = 3; |
| 1439 | init_attr->qp_token = queue_token; |
| 1440 | init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq; |
| 1441 | init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1; |
| 1442 | init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2; |
| 1443 | init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3; |
| 1444 | init_attr->wqe_size_enc_sq = EHEA_SG_SQ; |
| 1445 | init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1; |
| 1446 | init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2; |
| 1447 | init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3; |
| 1448 | init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD; |
| 1449 | init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD; |
| 1450 | init_attr->port_nr = port->logical_port_id; |
| 1451 | init_attr->send_cq_handle = pr->send_cq->fw_handle; |
| 1452 | init_attr->recv_cq_handle = pr->recv_cq->fw_handle; |
| 1453 | init_attr->aff_eq_handle = port->qp_eq->fw_handle; |
| 1454 | |
| 1455 | pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr); |
| 1456 | if (!pr->qp) { |
| 1457 | ehea_error("create_qp failed"); |
| 1458 | ret = -EIO; |
| 1459 | goto out_free; |
| 1460 | } |
| 1461 | |
| 1462 | if (netif_msg_ifup(port)) |
| 1463 | ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n " |
| 1464 | "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr, |
| 1465 | init_attr->act_nr_send_wqes, |
| 1466 | init_attr->act_nr_rwqes_rq1, |
| 1467 | init_attr->act_nr_rwqes_rq2, |
| 1468 | init_attr->act_nr_rwqes_rq3); |
| 1469 | |
Thomas Klein | 44fb312 | 2008-04-04 15:04:53 +0200 | [diff] [blame] | 1470 | pr->sq_skba_size = init_attr->act_nr_send_wqes + 1; |
| 1471 | |
| 1472 | ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1473 | ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1); |
| 1474 | ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1); |
| 1475 | ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1); |
| 1476 | if (ret) |
| 1477 | goto out_free; |
| 1478 | |
| 1479 | pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10; |
| 1480 | if (ehea_gen_smrs(pr) != 0) { |
| 1481 | ret = -EIO; |
| 1482 | goto out_free; |
| 1483 | } |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1484 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1485 | atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1); |
| 1486 | |
| 1487 | kfree(init_attr); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1488 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1489 | netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1490 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 1491 | pr->lro_mgr.max_aggr = pr->port->lro_max_aggr; |
| 1492 | pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS; |
| 1493 | pr->lro_mgr.lro_arr = pr->lro_desc; |
| 1494 | pr->lro_mgr.get_skb_header = get_skb_hdr; |
| 1495 | pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID; |
| 1496 | pr->lro_mgr.dev = port->netdev; |
| 1497 | pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY; |
| 1498 | pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; |
| 1499 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1500 | ret = 0; |
| 1501 | goto out; |
| 1502 | |
| 1503 | out_free: |
| 1504 | kfree(init_attr); |
| 1505 | vfree(pr->sq_skba.arr); |
| 1506 | vfree(pr->rq1_skba.arr); |
| 1507 | vfree(pr->rq2_skba.arr); |
| 1508 | vfree(pr->rq3_skba.arr); |
| 1509 | ehea_destroy_qp(pr->qp); |
| 1510 | ehea_destroy_cq(pr->send_cq); |
| 1511 | ehea_destroy_cq(pr->recv_cq); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1512 | ehea_destroy_eq(pr->eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1513 | out: |
| 1514 | return ret; |
| 1515 | } |
| 1516 | |
| 1517 | static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr) |
| 1518 | { |
| 1519 | int ret, i; |
| 1520 | |
| 1521 | ret = ehea_destroy_qp(pr->qp); |
| 1522 | |
| 1523 | if (!ret) { |
| 1524 | ehea_destroy_cq(pr->send_cq); |
| 1525 | ehea_destroy_cq(pr->recv_cq); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1526 | ehea_destroy_eq(pr->eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1527 | |
| 1528 | for (i = 0; i < pr->rq1_skba.len; i++) |
| 1529 | if (pr->rq1_skba.arr[i]) |
| 1530 | dev_kfree_skb(pr->rq1_skba.arr[i]); |
| 1531 | |
| 1532 | for (i = 0; i < pr->rq2_skba.len; i++) |
| 1533 | if (pr->rq2_skba.arr[i]) |
| 1534 | dev_kfree_skb(pr->rq2_skba.arr[i]); |
| 1535 | |
| 1536 | for (i = 0; i < pr->rq3_skba.len; i++) |
| 1537 | if (pr->rq3_skba.arr[i]) |
| 1538 | dev_kfree_skb(pr->rq3_skba.arr[i]); |
| 1539 | |
| 1540 | for (i = 0; i < pr->sq_skba.len; i++) |
| 1541 | if (pr->sq_skba.arr[i]) |
| 1542 | dev_kfree_skb(pr->sq_skba.arr[i]); |
| 1543 | |
| 1544 | vfree(pr->rq1_skba.arr); |
| 1545 | vfree(pr->rq2_skba.arr); |
| 1546 | vfree(pr->rq3_skba.arr); |
| 1547 | vfree(pr->sq_skba.arr); |
| 1548 | ret = ehea_rem_smrs(pr); |
| 1549 | } |
| 1550 | return ret; |
| 1551 | } |
| 1552 | |
| 1553 | /* |
| 1554 | * The write_* functions store information in swqe which is used by |
| 1555 | * the hardware to calculate the ip/tcp/udp checksum |
| 1556 | */ |
| 1557 | |
| 1558 | static inline void write_ip_start_end(struct ehea_swqe *swqe, |
| 1559 | const struct sk_buff *skb) |
| 1560 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1561 | swqe->ip_start = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1562 | swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | static inline void write_tcp_offset_end(struct ehea_swqe *swqe, |
| 1566 | const struct sk_buff *skb) |
| 1567 | { |
| 1568 | swqe->tcp_offset = |
| 1569 | (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check)); |
| 1570 | |
| 1571 | swqe->tcp_end = (u16)skb->len - 1; |
| 1572 | } |
| 1573 | |
| 1574 | static inline void write_udp_offset_end(struct ehea_swqe *swqe, |
| 1575 | const struct sk_buff *skb) |
| 1576 | { |
| 1577 | swqe->tcp_offset = |
| 1578 | (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check)); |
| 1579 | |
| 1580 | swqe->tcp_end = (u16)skb->len - 1; |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | static void write_swqe2_TSO(struct sk_buff *skb, |
| 1585 | struct ehea_swqe *swqe, u32 lkey) |
| 1586 | { |
| 1587 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; |
| 1588 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; |
| 1589 | int skb_data_size = skb->len - skb->data_len; |
| 1590 | int headersize; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1591 | |
| 1592 | /* Packet is TCP with TSO enabled */ |
| 1593 | swqe->tx_control |= EHEA_SWQE_TSO; |
| 1594 | swqe->mss = skb_shinfo(skb)->gso_size; |
| 1595 | /* copy only eth/ip/tcp headers to immediate data and |
| 1596 | * the rest of skb->data to sg1entry |
| 1597 | */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1598 | headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1599 | |
| 1600 | skb_data_size = skb->len - skb->data_len; |
| 1601 | |
| 1602 | if (skb_data_size >= headersize) { |
| 1603 | /* copy immediate data */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1604 | skb_copy_from_linear_data(skb, imm_data, headersize); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1605 | swqe->immediate_data_length = headersize; |
| 1606 | |
| 1607 | if (skb_data_size > headersize) { |
| 1608 | /* set sg1entry data */ |
| 1609 | sg1entry->l_key = lkey; |
| 1610 | sg1entry->len = skb_data_size - headersize; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1611 | sg1entry->vaddr = |
| 1612 | ehea_map_vaddr(skb->data + headersize); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1613 | swqe->descriptors++; |
| 1614 | } |
| 1615 | } else |
| 1616 | ehea_error("cannot handle fragmented headers"); |
| 1617 | } |
| 1618 | |
| 1619 | static void write_swqe2_nonTSO(struct sk_buff *skb, |
| 1620 | struct ehea_swqe *swqe, u32 lkey) |
| 1621 | { |
| 1622 | int skb_data_size = skb->len - skb->data_len; |
| 1623 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; |
| 1624 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1625 | |
| 1626 | /* Packet is any nonTSO type |
| 1627 | * |
| 1628 | * Copy as much as possible skb->data to immediate data and |
| 1629 | * the rest to sg1entry |
| 1630 | */ |
| 1631 | if (skb_data_size >= SWQE2_MAX_IMM) { |
| 1632 | /* copy immediate data */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1633 | skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1634 | |
| 1635 | swqe->immediate_data_length = SWQE2_MAX_IMM; |
| 1636 | |
| 1637 | if (skb_data_size > SWQE2_MAX_IMM) { |
| 1638 | /* copy sg1entry data */ |
| 1639 | sg1entry->l_key = lkey; |
| 1640 | sg1entry->len = skb_data_size - SWQE2_MAX_IMM; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1641 | sg1entry->vaddr = |
| 1642 | ehea_map_vaddr(skb->data + SWQE2_MAX_IMM); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1643 | swqe->descriptors++; |
| 1644 | } |
| 1645 | } else { |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1646 | skb_copy_from_linear_data(skb, imm_data, skb_data_size); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1647 | swqe->immediate_data_length = skb_data_size; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev, |
| 1652 | struct ehea_swqe *swqe, u32 lkey) |
| 1653 | { |
| 1654 | struct ehea_vsgentry *sg_list, *sg1entry, *sgentry; |
| 1655 | skb_frag_t *frag; |
| 1656 | int nfrags, sg1entry_contains_frag_data, i; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1657 | |
| 1658 | nfrags = skb_shinfo(skb)->nr_frags; |
| 1659 | sg1entry = &swqe->u.immdata_desc.sg_entry; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1660 | sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1661 | swqe->descriptors = 0; |
| 1662 | sg1entry_contains_frag_data = 0; |
| 1663 | |
| 1664 | if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size) |
| 1665 | write_swqe2_TSO(skb, swqe, lkey); |
| 1666 | else |
| 1667 | write_swqe2_nonTSO(skb, swqe, lkey); |
| 1668 | |
| 1669 | /* write descriptors */ |
| 1670 | if (nfrags > 0) { |
| 1671 | if (swqe->descriptors == 0) { |
| 1672 | /* sg1entry not yet used */ |
| 1673 | frag = &skb_shinfo(skb)->frags[0]; |
| 1674 | |
| 1675 | /* copy sg1entry data */ |
| 1676 | sg1entry->l_key = lkey; |
| 1677 | sg1entry->len = frag->size; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1678 | sg1entry->vaddr = |
| 1679 | ehea_map_vaddr(page_address(frag->page) |
| 1680 | + frag->page_offset); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1681 | swqe->descriptors++; |
| 1682 | sg1entry_contains_frag_data = 1; |
| 1683 | } |
| 1684 | |
| 1685 | for (i = sg1entry_contains_frag_data; i < nfrags; i++) { |
| 1686 | |
| 1687 | frag = &skb_shinfo(skb)->frags[i]; |
| 1688 | sgentry = &sg_list[i - sg1entry_contains_frag_data]; |
| 1689 | |
| 1690 | sgentry->l_key = lkey; |
| 1691 | sgentry->len = frag->size; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1692 | sgentry->vaddr = |
| 1693 | ehea_map_vaddr(page_address(frag->page) |
| 1694 | + frag->page_offset); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1695 | swqe->descriptors++; |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid) |
| 1701 | { |
| 1702 | int ret = 0; |
| 1703 | u64 hret; |
| 1704 | u8 reg_type; |
| 1705 | |
| 1706 | /* De/Register untagged packets */ |
| 1707 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED; |
| 1708 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1709 | port->logical_port_id, |
| 1710 | reg_type, port->mac_addr, 0, hcallid); |
| 1711 | if (hret != H_SUCCESS) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 1712 | ehea_error("%sregistering bc address failed (tagged)", |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1713 | hcallid == H_REG_BCMC ? "" : "de"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1714 | ret = -EIO; |
| 1715 | goto out_herr; |
| 1716 | } |
| 1717 | |
| 1718 | /* De/Register VLAN packets */ |
| 1719 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL; |
| 1720 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1721 | port->logical_port_id, |
| 1722 | reg_type, port->mac_addr, 0, hcallid); |
| 1723 | if (hret != H_SUCCESS) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 1724 | ehea_error("%sregistering bc address failed (vlan)", |
| 1725 | hcallid == H_REG_BCMC ? "" : "de"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1726 | ret = -EIO; |
| 1727 | } |
| 1728 | out_herr: |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
| 1732 | static int ehea_set_mac_addr(struct net_device *dev, void *sa) |
| 1733 | { |
| 1734 | struct ehea_port *port = netdev_priv(dev); |
| 1735 | struct sockaddr *mac_addr = sa; |
| 1736 | struct hcp_ehea_port_cb0 *cb0; |
| 1737 | int ret; |
| 1738 | u64 hret; |
| 1739 | |
| 1740 | if (!is_valid_ether_addr(mac_addr->sa_data)) { |
| 1741 | ret = -EADDRNOTAVAIL; |
| 1742 | goto out; |
| 1743 | } |
| 1744 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1745 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1746 | if (!cb0) { |
| 1747 | ehea_error("no mem for cb0"); |
| 1748 | ret = -ENOMEM; |
| 1749 | goto out; |
| 1750 | } |
| 1751 | |
| 1752 | memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN); |
| 1753 | |
| 1754 | cb0->port_mac_addr = cb0->port_mac_addr >> 16; |
| 1755 | |
| 1756 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1757 | port->logical_port_id, H_PORT_CB0, |
| 1758 | EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0); |
| 1759 | if (hret != H_SUCCESS) { |
| 1760 | ret = -EIO; |
| 1761 | goto out_free; |
| 1762 | } |
| 1763 | |
| 1764 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); |
| 1765 | |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 1766 | mutex_lock(&ehea_bcmc_regs.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 1767 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1768 | /* Deregister old MAC in pHYP */ |
Jan-Bernd Themann | 00aaea2 | 2008-06-09 15:17:37 +0100 | [diff] [blame^] | 1769 | if (port->state == EHEA_PORT_UP) { |
| 1770 | ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
| 1771 | if (ret) |
| 1772 | goto out_upregs; |
| 1773 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1774 | |
| 1775 | port->mac_addr = cb0->port_mac_addr << 16; |
| 1776 | |
| 1777 | /* Register new MAC in pHYP */ |
Jan-Bernd Themann | 00aaea2 | 2008-06-09 15:17:37 +0100 | [diff] [blame^] | 1778 | if (port->state == EHEA_PORT_UP) { |
| 1779 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); |
| 1780 | if (ret) |
| 1781 | goto out_upregs; |
| 1782 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1783 | |
| 1784 | ret = 0; |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 1785 | |
| 1786 | out_upregs: |
| 1787 | ehea_update_bcmc_registrations(); |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 1788 | mutex_unlock(&ehea_bcmc_regs.lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1789 | out_free: |
| 1790 | kfree(cb0); |
| 1791 | out: |
| 1792 | return ret; |
| 1793 | } |
| 1794 | |
| 1795 | static void ehea_promiscuous_error(u64 hret, int enable) |
| 1796 | { |
Thomas Klein | 7674a58 | 2007-01-22 12:54:20 +0100 | [diff] [blame] | 1797 | if (hret == H_AUTHORITY) |
| 1798 | ehea_info("Hypervisor denied %sabling promiscuous mode", |
| 1799 | enable == 1 ? "en" : "dis"); |
| 1800 | else |
| 1801 | ehea_error("failed %sabling promiscuous mode", |
| 1802 | enable == 1 ? "en" : "dis"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | static void ehea_promiscuous(struct net_device *dev, int enable) |
| 1806 | { |
| 1807 | struct ehea_port *port = netdev_priv(dev); |
| 1808 | struct hcp_ehea_port_cb7 *cb7; |
| 1809 | u64 hret; |
| 1810 | |
| 1811 | if ((enable && port->promisc) || (!enable && !port->promisc)) |
| 1812 | return; |
| 1813 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1814 | cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1815 | if (!cb7) { |
| 1816 | ehea_error("no mem for cb7"); |
| 1817 | goto out; |
| 1818 | } |
| 1819 | |
| 1820 | /* Modify Pxs_DUCQPN in CB7 */ |
| 1821 | cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0; |
| 1822 | |
| 1823 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1824 | port->logical_port_id, |
| 1825 | H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7); |
| 1826 | if (hret) { |
| 1827 | ehea_promiscuous_error(hret, enable); |
| 1828 | goto out; |
| 1829 | } |
| 1830 | |
| 1831 | port->promisc = enable; |
| 1832 | out: |
| 1833 | kfree(cb7); |
| 1834 | return; |
| 1835 | } |
| 1836 | |
| 1837 | static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr, |
| 1838 | u32 hcallid) |
| 1839 | { |
| 1840 | u64 hret; |
| 1841 | u8 reg_type; |
| 1842 | |
| 1843 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST |
| 1844 | | EHEA_BCMC_UNTAGGED; |
| 1845 | |
| 1846 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1847 | port->logical_port_id, |
| 1848 | reg_type, mc_mac_addr, 0, hcallid); |
| 1849 | if (hret) |
| 1850 | goto out; |
| 1851 | |
| 1852 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST |
| 1853 | | EHEA_BCMC_VLANID_ALL; |
| 1854 | |
| 1855 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1856 | port->logical_port_id, |
| 1857 | reg_type, mc_mac_addr, 0, hcallid); |
| 1858 | out: |
| 1859 | return hret; |
| 1860 | } |
| 1861 | |
| 1862 | static int ehea_drop_multicast_list(struct net_device *dev) |
| 1863 | { |
| 1864 | struct ehea_port *port = netdev_priv(dev); |
| 1865 | struct ehea_mc_list *mc_entry = port->mc_list; |
| 1866 | struct list_head *pos; |
| 1867 | struct list_head *temp; |
| 1868 | int ret = 0; |
| 1869 | u64 hret; |
| 1870 | |
| 1871 | list_for_each_safe(pos, temp, &(port->mc_list->list)) { |
| 1872 | mc_entry = list_entry(pos, struct ehea_mc_list, list); |
| 1873 | |
| 1874 | hret = ehea_multicast_reg_helper(port, mc_entry->macaddr, |
| 1875 | H_DEREG_BCMC); |
| 1876 | if (hret) { |
| 1877 | ehea_error("failed deregistering mcast MAC"); |
| 1878 | ret = -EIO; |
| 1879 | } |
| 1880 | |
| 1881 | list_del(pos); |
| 1882 | kfree(mc_entry); |
| 1883 | } |
| 1884 | return ret; |
| 1885 | } |
| 1886 | |
| 1887 | static void ehea_allmulti(struct net_device *dev, int enable) |
| 1888 | { |
| 1889 | struct ehea_port *port = netdev_priv(dev); |
| 1890 | u64 hret; |
| 1891 | |
| 1892 | if (!port->allmulti) { |
| 1893 | if (enable) { |
| 1894 | /* Enable ALLMULTI */ |
| 1895 | ehea_drop_multicast_list(dev); |
| 1896 | hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC); |
| 1897 | if (!hret) |
| 1898 | port->allmulti = 1; |
| 1899 | else |
| 1900 | ehea_error("failed enabling IFF_ALLMULTI"); |
| 1901 | } |
| 1902 | } else |
| 1903 | if (!enable) { |
| 1904 | /* Disable ALLMULTI */ |
| 1905 | hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC); |
| 1906 | if (!hret) |
| 1907 | port->allmulti = 0; |
| 1908 | else |
| 1909 | ehea_error("failed disabling IFF_ALLMULTI"); |
| 1910 | } |
| 1911 | } |
| 1912 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1913 | static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1914 | { |
| 1915 | struct ehea_mc_list *ehea_mcl_entry; |
| 1916 | u64 hret; |
| 1917 | |
Jan-Bernd Themann | 1e1675c | 2006-10-25 13:11:42 +0200 | [diff] [blame] | 1918 | ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1919 | if (!ehea_mcl_entry) { |
| 1920 | ehea_error("no mem for mcl_entry"); |
| 1921 | return; |
| 1922 | } |
| 1923 | |
| 1924 | INIT_LIST_HEAD(&ehea_mcl_entry->list); |
| 1925 | |
| 1926 | memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN); |
| 1927 | |
| 1928 | hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr, |
| 1929 | H_REG_BCMC); |
| 1930 | if (!hret) |
| 1931 | list_add(&ehea_mcl_entry->list, &port->mc_list->list); |
| 1932 | else { |
| 1933 | ehea_error("failed registering mcast MAC"); |
| 1934 | kfree(ehea_mcl_entry); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | static void ehea_set_multicast_list(struct net_device *dev) |
| 1939 | { |
| 1940 | struct ehea_port *port = netdev_priv(dev); |
| 1941 | struct dev_mc_list *k_mcl_entry; |
| 1942 | int ret, i; |
| 1943 | |
| 1944 | if (dev->flags & IFF_PROMISC) { |
| 1945 | ehea_promiscuous(dev, 1); |
| 1946 | return; |
| 1947 | } |
| 1948 | ehea_promiscuous(dev, 0); |
| 1949 | |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 1950 | mutex_lock(&ehea_bcmc_regs.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 1951 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1952 | if (dev->flags & IFF_ALLMULTI) { |
| 1953 | ehea_allmulti(dev, 1); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 1954 | goto out; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1955 | } |
| 1956 | ehea_allmulti(dev, 0); |
| 1957 | |
| 1958 | if (dev->mc_count) { |
| 1959 | ret = ehea_drop_multicast_list(dev); |
| 1960 | if (ret) { |
| 1961 | /* Dropping the current multicast list failed. |
| 1962 | * Enabling ALL_MULTI is the best we can do. |
| 1963 | */ |
| 1964 | ehea_allmulti(dev, 1); |
| 1965 | } |
| 1966 | |
| 1967 | if (dev->mc_count > port->adapter->max_mc_mac) { |
| 1968 | ehea_info("Mcast registration limit reached (0x%lx). " |
| 1969 | "Use ALLMULTI!", |
| 1970 | port->adapter->max_mc_mac); |
| 1971 | goto out; |
| 1972 | } |
| 1973 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1974 | for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++, |
| 1975 | k_mcl_entry = k_mcl_entry->next) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1976 | ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr); |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 1977 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1978 | } |
| 1979 | out: |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 1980 | ehea_update_bcmc_registrations(); |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 1981 | mutex_unlock(&ehea_bcmc_regs.lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1982 | return; |
| 1983 | } |
| 1984 | |
| 1985 | static int ehea_change_mtu(struct net_device *dev, int new_mtu) |
| 1986 | { |
| 1987 | if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE)) |
| 1988 | return -EINVAL; |
| 1989 | dev->mtu = new_mtu; |
| 1990 | return 0; |
| 1991 | } |
| 1992 | |
| 1993 | static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev, |
| 1994 | struct ehea_swqe *swqe, u32 lkey) |
| 1995 | { |
| 1996 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1997 | const struct iphdr *iph = ip_hdr(skb); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 1998 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1999 | /* IPv4 */ |
| 2000 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2001 | | EHEA_SWQE_IP_CHECKSUM |
| 2002 | | EHEA_SWQE_TCP_CHECKSUM |
| 2003 | | EHEA_SWQE_IMM_DATA_PRESENT |
| 2004 | | EHEA_SWQE_DESCRIPTORS_PRESENT; |
| 2005 | |
| 2006 | write_ip_start_end(swqe, skb); |
| 2007 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2008 | if (iph->protocol == IPPROTO_UDP) { |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2009 | if ((iph->frag_off & IP_MF) |
| 2010 | || (iph->frag_off & IP_OFFSET)) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2011 | /* IP fragment, so don't change cs */ |
| 2012 | swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM; |
| 2013 | else |
| 2014 | write_udp_offset_end(swqe, skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2015 | } else if (iph->protocol == IPPROTO_TCP) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2016 | write_tcp_offset_end(swqe, skb); |
| 2017 | } |
| 2018 | |
| 2019 | /* icmp (big data) and ip segmentation packets (all other ip |
| 2020 | packets) do not require any special handling */ |
| 2021 | |
| 2022 | } else { |
| 2023 | /* Other Ethernet Protocol */ |
| 2024 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2025 | | EHEA_SWQE_IMM_DATA_PRESENT |
| 2026 | | EHEA_SWQE_DESCRIPTORS_PRESENT; |
| 2027 | } |
| 2028 | |
| 2029 | write_swqe2_data(skb, dev, swqe, lkey); |
| 2030 | } |
| 2031 | |
| 2032 | static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev, |
| 2033 | struct ehea_swqe *swqe) |
| 2034 | { |
| 2035 | int nfrags = skb_shinfo(skb)->nr_frags; |
| 2036 | u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0]; |
| 2037 | skb_frag_t *frag; |
| 2038 | int i; |
| 2039 | |
| 2040 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2041 | const struct iphdr *iph = ip_hdr(skb); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2042 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2043 | /* IPv4 */ |
| 2044 | write_ip_start_end(swqe, skb); |
| 2045 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2046 | if (iph->protocol == IPPROTO_TCP) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2047 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2048 | | EHEA_SWQE_IP_CHECKSUM |
| 2049 | | EHEA_SWQE_TCP_CHECKSUM |
| 2050 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 2051 | |
| 2052 | write_tcp_offset_end(swqe, skb); |
| 2053 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2054 | } else if (iph->protocol == IPPROTO_UDP) { |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2055 | if ((iph->frag_off & IP_MF) |
| 2056 | || (iph->frag_off & IP_OFFSET)) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2057 | /* IP fragment, so don't change cs */ |
| 2058 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2059 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 2060 | else { |
| 2061 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2062 | | EHEA_SWQE_IP_CHECKSUM |
| 2063 | | EHEA_SWQE_TCP_CHECKSUM |
| 2064 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 2065 | |
| 2066 | write_udp_offset_end(swqe, skb); |
| 2067 | } |
| 2068 | } else { |
| 2069 | /* icmp (big data) and |
| 2070 | ip segmentation packets (all other ip packets) */ |
| 2071 | swqe->tx_control |= EHEA_SWQE_CRC |
| 2072 | | EHEA_SWQE_IP_CHECKSUM |
| 2073 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 2074 | } |
| 2075 | } else { |
| 2076 | /* Other Ethernet Protocol */ |
| 2077 | swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT; |
| 2078 | } |
| 2079 | /* copy (immediate) data */ |
| 2080 | if (nfrags == 0) { |
| 2081 | /* data is in a single piece */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 2082 | skb_copy_from_linear_data(skb, imm_data, skb->len); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2083 | } else { |
| 2084 | /* first copy data from the skb->data buffer ... */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 2085 | skb_copy_from_linear_data(skb, imm_data, |
| 2086 | skb->len - skb->data_len); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2087 | imm_data += skb->len - skb->data_len; |
| 2088 | |
| 2089 | /* ... then copy data from the fragments */ |
| 2090 | for (i = 0; i < nfrags; i++) { |
| 2091 | frag = &skb_shinfo(skb)->frags[i]; |
| 2092 | memcpy(imm_data, |
| 2093 | page_address(frag->page) + frag->page_offset, |
| 2094 | frag->size); |
| 2095 | imm_data += frag->size; |
| 2096 | } |
| 2097 | } |
| 2098 | swqe->immediate_data_length = skb->len; |
| 2099 | dev_kfree_skb(skb); |
| 2100 | } |
| 2101 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2102 | static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps) |
| 2103 | { |
| 2104 | struct tcphdr *tcp; |
| 2105 | u32 tmp; |
| 2106 | |
| 2107 | if ((skb->protocol == htons(ETH_P_IP)) && |
Thomas Klein | 88ca2d0 | 2007-05-02 16:07:05 +0200 | [diff] [blame] | 2108 | (ip_hdr(skb)->protocol == IPPROTO_TCP)) { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2109 | tcp = (struct tcphdr *)(skb_network_header(skb) + |
| 2110 | (ip_hdr(skb)->ihl * 4)); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2111 | tmp = (tcp->source + (tcp->dest << 16)) % 31; |
Thomas Klein | 88ca2d0 | 2007-05-02 16:07:05 +0200 | [diff] [blame] | 2112 | tmp += ip_hdr(skb)->daddr % 31; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2113 | return tmp % num_qps; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2114 | } else |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2115 | return 0; |
| 2116 | } |
| 2117 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2118 | static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 2119 | { |
| 2120 | struct ehea_port *port = netdev_priv(dev); |
| 2121 | struct ehea_swqe *swqe; |
| 2122 | unsigned long flags; |
| 2123 | u32 lkey; |
| 2124 | int swqe_index; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2125 | struct ehea_port_res *pr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2126 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2127 | pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)]; |
| 2128 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2129 | if (!spin_trylock(&pr->xmit_lock)) |
| 2130 | return NETDEV_TX_BUSY; |
| 2131 | |
| 2132 | if (pr->queue_stopped) { |
| 2133 | spin_unlock(&pr->xmit_lock); |
| 2134 | return NETDEV_TX_BUSY; |
| 2135 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2136 | |
| 2137 | swqe = ehea_get_swqe(pr->qp, &swqe_index); |
| 2138 | memset(swqe, 0, SWQE_HEADER_SIZE); |
| 2139 | atomic_dec(&pr->swqe_avail); |
| 2140 | |
| 2141 | if (skb->len <= SWQE3_MAX_IMM) { |
| 2142 | u32 sig_iv = port->sig_comp_iv; |
| 2143 | u32 swqe_num = pr->swqe_id_counter; |
| 2144 | ehea_xmit3(skb, dev, swqe); |
| 2145 | swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE) |
| 2146 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num); |
| 2147 | if (pr->swqe_ll_count >= (sig_iv - 1)) { |
| 2148 | swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL, |
| 2149 | sig_iv); |
| 2150 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; |
| 2151 | pr->swqe_ll_count = 0; |
| 2152 | } else |
| 2153 | pr->swqe_ll_count += 1; |
| 2154 | } else { |
| 2155 | swqe->wr_id = |
| 2156 | EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE) |
| 2157 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter) |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 2158 | | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2159 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index); |
| 2160 | pr->sq_skba.arr[pr->sq_skba.index] = skb; |
| 2161 | |
| 2162 | pr->sq_skba.index++; |
| 2163 | pr->sq_skba.index &= (pr->sq_skba.len - 1); |
| 2164 | |
| 2165 | lkey = pr->send_mr.lkey; |
| 2166 | ehea_xmit2(skb, dev, swqe, lkey); |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 2167 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2168 | } |
| 2169 | pr->swqe_id_counter += 1; |
| 2170 | |
| 2171 | if (port->vgrp && vlan_tx_tag_present(skb)) { |
| 2172 | swqe->tx_control |= EHEA_SWQE_VLAN_INSERT; |
| 2173 | swqe->vlan_tag = vlan_tx_tag_get(skb); |
| 2174 | } |
| 2175 | |
| 2176 | if (netif_msg_tx_queued(port)) { |
| 2177 | ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr); |
Jan-Bernd Themann | bff0a55 | 2006-10-05 16:53:14 +0200 | [diff] [blame] | 2178 | ehea_dump(swqe, 512, "swqe"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2179 | } |
| 2180 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2181 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
| 2182 | netif_stop_queue(dev); |
| 2183 | swqe->tx_control |= EHEA_SWQE_PURGE; |
| 2184 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2185 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2186 | ehea_post_swqe(pr->qp, swqe); |
Thomas Klein | 7393b87 | 2007-11-21 17:37:58 +0100 | [diff] [blame] | 2187 | pr->tx_packets++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2188 | |
| 2189 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { |
| 2190 | spin_lock_irqsave(&pr->netif_queue, flags); |
| 2191 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 2192 | pr->p_stats.queue_stopped++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2193 | netif_stop_queue(dev); |
| 2194 | pr->queue_stopped = 1; |
| 2195 | } |
| 2196 | spin_unlock_irqrestore(&pr->netif_queue, flags); |
| 2197 | } |
| 2198 | dev->trans_start = jiffies; |
| 2199 | spin_unlock(&pr->xmit_lock); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2200 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2201 | return NETDEV_TX_OK; |
| 2202 | } |
| 2203 | |
| 2204 | static void ehea_vlan_rx_register(struct net_device *dev, |
| 2205 | struct vlan_group *grp) |
| 2206 | { |
| 2207 | struct ehea_port *port = netdev_priv(dev); |
| 2208 | struct ehea_adapter *adapter = port->adapter; |
| 2209 | struct hcp_ehea_port_cb1 *cb1; |
| 2210 | u64 hret; |
| 2211 | |
| 2212 | port->vgrp = grp; |
| 2213 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2214 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2215 | if (!cb1) { |
| 2216 | ehea_error("no mem for cb1"); |
| 2217 | goto out; |
| 2218 | } |
| 2219 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2220 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2221 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2222 | if (hret != H_SUCCESS) |
| 2223 | ehea_error("modify_ehea_port failed"); |
| 2224 | |
| 2225 | kfree(cb1); |
| 2226 | out: |
| 2227 | return; |
| 2228 | } |
| 2229 | |
| 2230 | static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 2231 | { |
| 2232 | struct ehea_port *port = netdev_priv(dev); |
| 2233 | struct ehea_adapter *adapter = port->adapter; |
| 2234 | struct hcp_ehea_port_cb1 *cb1; |
| 2235 | int index; |
| 2236 | u64 hret; |
| 2237 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2238 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2239 | if (!cb1) { |
| 2240 | ehea_error("no mem for cb1"); |
| 2241 | goto out; |
| 2242 | } |
| 2243 | |
| 2244 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, |
| 2245 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2246 | if (hret != H_SUCCESS) { |
| 2247 | ehea_error("query_ehea_port failed"); |
| 2248 | goto out; |
| 2249 | } |
| 2250 | |
| 2251 | index = (vid / 64); |
Thomas Klein | dec590c | 2007-06-06 20:53:16 +0200 | [diff] [blame] | 2252 | cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F))); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2253 | |
| 2254 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2255 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2256 | if (hret != H_SUCCESS) |
| 2257 | ehea_error("modify_ehea_port failed"); |
| 2258 | out: |
| 2259 | kfree(cb1); |
| 2260 | return; |
| 2261 | } |
| 2262 | |
| 2263 | static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 2264 | { |
| 2265 | struct ehea_port *port = netdev_priv(dev); |
| 2266 | struct ehea_adapter *adapter = port->adapter; |
| 2267 | struct hcp_ehea_port_cb1 *cb1; |
| 2268 | int index; |
| 2269 | u64 hret; |
| 2270 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 2271 | vlan_group_set_device(port->vgrp, vid, NULL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2272 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2273 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2274 | if (!cb1) { |
| 2275 | ehea_error("no mem for cb1"); |
| 2276 | goto out; |
| 2277 | } |
| 2278 | |
| 2279 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, |
| 2280 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2281 | if (hret != H_SUCCESS) { |
| 2282 | ehea_error("query_ehea_port failed"); |
| 2283 | goto out; |
| 2284 | } |
| 2285 | |
| 2286 | index = (vid / 64); |
Thomas Klein | dec590c | 2007-06-06 20:53:16 +0200 | [diff] [blame] | 2287 | cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F))); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2288 | |
| 2289 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2290 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2291 | if (hret != H_SUCCESS) |
| 2292 | ehea_error("modify_ehea_port failed"); |
| 2293 | out: |
| 2294 | kfree(cb1); |
| 2295 | return; |
| 2296 | } |
| 2297 | |
| 2298 | int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp) |
| 2299 | { |
| 2300 | int ret = -EIO; |
| 2301 | u64 hret; |
| 2302 | u16 dummy16 = 0; |
| 2303 | u64 dummy64 = 0; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2304 | struct hcp_modify_qp_cb0 *cb0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2305 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2306 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2307 | if (!cb0) { |
| 2308 | ret = -ENOMEM; |
| 2309 | goto out; |
| 2310 | } |
| 2311 | |
| 2312 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2313 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2314 | if (hret != H_SUCCESS) { |
| 2315 | ehea_error("query_ehea_qp failed (1)"); |
| 2316 | goto out; |
| 2317 | } |
| 2318 | |
| 2319 | cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED; |
| 2320 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2321 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2322 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2323 | if (hret != H_SUCCESS) { |
| 2324 | ehea_error("modify_ehea_qp failed (1)"); |
| 2325 | goto out; |
| 2326 | } |
| 2327 | |
| 2328 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2329 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2330 | if (hret != H_SUCCESS) { |
| 2331 | ehea_error("query_ehea_qp failed (2)"); |
| 2332 | goto out; |
| 2333 | } |
| 2334 | |
| 2335 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED; |
| 2336 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2337 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2338 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2339 | if (hret != H_SUCCESS) { |
| 2340 | ehea_error("modify_ehea_qp failed (2)"); |
| 2341 | goto out; |
| 2342 | } |
| 2343 | |
| 2344 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2345 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2346 | if (hret != H_SUCCESS) { |
| 2347 | ehea_error("query_ehea_qp failed (3)"); |
| 2348 | goto out; |
| 2349 | } |
| 2350 | |
| 2351 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND; |
| 2352 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2353 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2354 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2355 | if (hret != H_SUCCESS) { |
| 2356 | ehea_error("modify_ehea_qp failed (3)"); |
| 2357 | goto out; |
| 2358 | } |
| 2359 | |
| 2360 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2361 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2362 | if (hret != H_SUCCESS) { |
| 2363 | ehea_error("query_ehea_qp failed (4)"); |
| 2364 | goto out; |
| 2365 | } |
| 2366 | |
| 2367 | ret = 0; |
| 2368 | out: |
| 2369 | kfree(cb0); |
| 2370 | return ret; |
| 2371 | } |
| 2372 | |
| 2373 | static int ehea_port_res_setup(struct ehea_port *port, int def_qps, |
| 2374 | int add_tx_qps) |
| 2375 | { |
| 2376 | int ret, i; |
| 2377 | struct port_res_cfg pr_cfg, pr_cfg_small_rx; |
| 2378 | enum ehea_eq_type eq_type = EHEA_EQ; |
| 2379 | |
| 2380 | port->qp_eq = ehea_create_eq(port->adapter, eq_type, |
| 2381 | EHEA_MAX_ENTRIES_EQ, 1); |
| 2382 | if (!port->qp_eq) { |
| 2383 | ret = -EINVAL; |
| 2384 | ehea_error("ehea_create_eq failed (qp_eq)"); |
| 2385 | goto out_kill_eq; |
| 2386 | } |
| 2387 | |
| 2388 | pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2389 | pr_cfg.max_entries_scq = sq_entries * 2; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2390 | pr_cfg.max_entries_sq = sq_entries; |
| 2391 | pr_cfg.max_entries_rq1 = rq1_entries; |
| 2392 | pr_cfg.max_entries_rq2 = rq2_entries; |
| 2393 | pr_cfg.max_entries_rq3 = rq3_entries; |
| 2394 | |
| 2395 | pr_cfg_small_rx.max_entries_rcq = 1; |
| 2396 | pr_cfg_small_rx.max_entries_scq = sq_entries; |
| 2397 | pr_cfg_small_rx.max_entries_sq = sq_entries; |
| 2398 | pr_cfg_small_rx.max_entries_rq1 = 1; |
| 2399 | pr_cfg_small_rx.max_entries_rq2 = 1; |
| 2400 | pr_cfg_small_rx.max_entries_rq3 = 1; |
| 2401 | |
| 2402 | for (i = 0; i < def_qps; i++) { |
| 2403 | ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i); |
| 2404 | if (ret) |
| 2405 | goto out_clean_pr; |
| 2406 | } |
| 2407 | for (i = def_qps; i < def_qps + add_tx_qps; i++) { |
| 2408 | ret = ehea_init_port_res(port, &port->port_res[i], |
| 2409 | &pr_cfg_small_rx, i); |
| 2410 | if (ret) |
| 2411 | goto out_clean_pr; |
| 2412 | } |
| 2413 | |
| 2414 | return 0; |
| 2415 | |
| 2416 | out_clean_pr: |
| 2417 | while (--i >= 0) |
| 2418 | ehea_clean_portres(port, &port->port_res[i]); |
| 2419 | |
| 2420 | out_kill_eq: |
| 2421 | ehea_destroy_eq(port->qp_eq); |
| 2422 | return ret; |
| 2423 | } |
| 2424 | |
| 2425 | static int ehea_clean_all_portres(struct ehea_port *port) |
| 2426 | { |
| 2427 | int ret = 0; |
| 2428 | int i; |
| 2429 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2430 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2431 | ret |= ehea_clean_portres(port, &port->port_res[i]); |
| 2432 | |
| 2433 | ret |= ehea_destroy_eq(port->qp_eq); |
| 2434 | |
| 2435 | return ret; |
| 2436 | } |
| 2437 | |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2438 | static void ehea_remove_adapter_mr(struct ehea_adapter *adapter) |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2439 | { |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2440 | if (adapter->active_ports) |
| 2441 | return; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2442 | |
| 2443 | ehea_rem_mr(&adapter->mr); |
| 2444 | } |
| 2445 | |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2446 | static int ehea_add_adapter_mr(struct ehea_adapter *adapter) |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2447 | { |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2448 | if (adapter->active_ports) |
| 2449 | return 0; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2450 | |
| 2451 | return ehea_reg_kernel_mr(adapter, &adapter->mr); |
| 2452 | } |
| 2453 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2454 | static int ehea_up(struct net_device *dev) |
| 2455 | { |
| 2456 | int ret, i; |
| 2457 | struct ehea_port *port = netdev_priv(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2458 | |
| 2459 | if (port->state == EHEA_PORT_UP) |
| 2460 | return 0; |
| 2461 | |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 2462 | mutex_lock(&ehea_fw_handles.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2463 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2464 | ret = ehea_port_res_setup(port, port->num_def_qps, |
| 2465 | port->num_add_tx_qps); |
| 2466 | if (ret) { |
| 2467 | ehea_error("port_res_failed"); |
| 2468 | goto out; |
| 2469 | } |
| 2470 | |
| 2471 | /* Set default QP for this port */ |
| 2472 | ret = ehea_configure_port(port); |
| 2473 | if (ret) { |
| 2474 | ehea_error("ehea_configure_port failed. ret:%d", ret); |
| 2475 | goto out_clean_pr; |
| 2476 | } |
| 2477 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2478 | ret = ehea_reg_interrupts(dev); |
| 2479 | if (ret) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 2480 | ehea_error("reg_interrupts failed. ret:%d", ret); |
| 2481 | goto out_clean_pr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2482 | } |
| 2483 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2484 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2485 | ret = ehea_activate_qp(port->adapter, port->port_res[i].qp); |
| 2486 | if (ret) { |
| 2487 | ehea_error("activate_qp failed"); |
| 2488 | goto out_free_irqs; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2492 | for (i = 0; i < port->num_def_qps; i++) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2493 | ret = ehea_fill_port_res(&port->port_res[i]); |
| 2494 | if (ret) { |
| 2495 | ehea_error("out_free_irqs"); |
| 2496 | goto out_free_irqs; |
| 2497 | } |
| 2498 | } |
| 2499 | |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2500 | mutex_lock(&ehea_bcmc_regs.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2501 | |
| 2502 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); |
| 2503 | if (ret) { |
| 2504 | ret = -EIO; |
| 2505 | goto out_free_irqs; |
| 2506 | } |
| 2507 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2508 | port->state = EHEA_PORT_UP; |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2509 | |
| 2510 | ret = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2511 | goto out; |
| 2512 | |
| 2513 | out_free_irqs: |
| 2514 | ehea_free_interrupts(dev); |
| 2515 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2516 | out_clean_pr: |
| 2517 | ehea_clean_all_portres(port); |
| 2518 | out: |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2519 | if (ret) |
| 2520 | ehea_info("Failed starting %s. ret=%i", dev->name, ret); |
| 2521 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2522 | ehea_update_bcmc_registrations(); |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2523 | mutex_unlock(&ehea_bcmc_regs.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2524 | |
| 2525 | ehea_update_firmware_handles(); |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 2526 | mutex_unlock(&ehea_fw_handles.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2527 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2528 | return ret; |
| 2529 | } |
| 2530 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2531 | static void port_napi_disable(struct ehea_port *port) |
| 2532 | { |
| 2533 | int i; |
| 2534 | |
Jan-Bernd Themann | 0173b79 | 2007-10-24 11:53:34 +0200 | [diff] [blame] | 2535 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2536 | napi_disable(&port->port_res[i].napi); |
| 2537 | } |
| 2538 | |
| 2539 | static void port_napi_enable(struct ehea_port *port) |
| 2540 | { |
| 2541 | int i; |
| 2542 | |
Jan-Bernd Themann | 0173b79 | 2007-10-24 11:53:34 +0200 | [diff] [blame] | 2543 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2544 | napi_enable(&port->port_res[i].napi); |
| 2545 | } |
| 2546 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2547 | static int ehea_open(struct net_device *dev) |
| 2548 | { |
| 2549 | int ret; |
| 2550 | struct ehea_port *port = netdev_priv(dev); |
| 2551 | |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2552 | mutex_lock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2553 | |
| 2554 | if (netif_msg_ifup(port)) |
| 2555 | ehea_info("enabling port %s", dev->name); |
| 2556 | |
| 2557 | ret = ehea_up(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2558 | if (!ret) { |
| 2559 | port_napi_enable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2560 | netif_start_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2561 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2562 | |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2563 | mutex_unlock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2564 | |
| 2565 | return ret; |
| 2566 | } |
| 2567 | |
| 2568 | static int ehea_down(struct net_device *dev) |
| 2569 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2570 | int ret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2571 | struct ehea_port *port = netdev_priv(dev); |
| 2572 | |
| 2573 | if (port->state == EHEA_PORT_DOWN) |
| 2574 | return 0; |
| 2575 | |
Daniel Walker | dbbcbb2 | 2008-03-28 14:41:27 -0700 | [diff] [blame] | 2576 | mutex_lock(&ehea_fw_handles.lock); |
| 2577 | |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2578 | mutex_lock(&ehea_bcmc_regs.lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2579 | ehea_drop_multicast_list(dev); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2580 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
| 2581 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2582 | ehea_free_interrupts(dev); |
| 2583 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2584 | port->state = EHEA_PORT_DOWN; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2585 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2586 | ehea_update_bcmc_registrations(); |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2587 | mutex_unlock(&ehea_bcmc_regs.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2588 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2589 | ret = ehea_clean_all_portres(port); |
| 2590 | if (ret) |
| 2591 | ehea_info("Failed freeing resources for %s. ret=%i", |
| 2592 | dev->name, ret); |
| 2593 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2594 | ehea_update_firmware_handles(); |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 2595 | mutex_unlock(&ehea_fw_handles.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 2596 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2597 | return ret; |
| 2598 | } |
| 2599 | |
| 2600 | static int ehea_stop(struct net_device *dev) |
| 2601 | { |
| 2602 | int ret; |
| 2603 | struct ehea_port *port = netdev_priv(dev); |
| 2604 | |
| 2605 | if (netif_msg_ifdown(port)) |
| 2606 | ehea_info("disabling port %s", dev->name); |
| 2607 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 2608 | flush_scheduled_work(); |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2609 | mutex_lock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2610 | netif_stop_queue(dev); |
Jan-Bernd Themann | 0173b79 | 2007-10-24 11:53:34 +0200 | [diff] [blame] | 2611 | port_napi_disable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2612 | ret = ehea_down(dev); |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2613 | mutex_unlock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2614 | return ret; |
| 2615 | } |
| 2616 | |
Andrew Morton | 22559c5 | 2008-04-18 13:50:39 -0700 | [diff] [blame] | 2617 | static void ehea_purge_sq(struct ehea_qp *orig_qp) |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2618 | { |
| 2619 | struct ehea_qp qp = *orig_qp; |
| 2620 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; |
| 2621 | struct ehea_swqe *swqe; |
| 2622 | int wqe_index; |
| 2623 | int i; |
| 2624 | |
| 2625 | for (i = 0; i < init_attr->act_nr_send_wqes; i++) { |
| 2626 | swqe = ehea_get_swqe(&qp, &wqe_index); |
| 2627 | swqe->tx_control |= EHEA_SWQE_PURGE; |
| 2628 | } |
| 2629 | } |
| 2630 | |
Andrew Morton | 22559c5 | 2008-04-18 13:50:39 -0700 | [diff] [blame] | 2631 | static void ehea_flush_sq(struct ehea_port *port) |
Thomas Klein | 44fb312 | 2008-04-04 15:04:53 +0200 | [diff] [blame] | 2632 | { |
| 2633 | int i; |
| 2634 | |
| 2635 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 2636 | struct ehea_port_res *pr = &port->port_res[i]; |
| 2637 | int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count; |
| 2638 | int k = 0; |
| 2639 | while (atomic_read(&pr->swqe_avail) < swqe_max) { |
| 2640 | msleep(5); |
| 2641 | if (++k == 20) |
| 2642 | break; |
| 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2647 | int ehea_stop_qps(struct net_device *dev) |
| 2648 | { |
| 2649 | struct ehea_port *port = netdev_priv(dev); |
| 2650 | struct ehea_adapter *adapter = port->adapter; |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2651 | struct hcp_modify_qp_cb0 *cb0; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2652 | int ret = -EIO; |
| 2653 | int dret; |
| 2654 | int i; |
| 2655 | u64 hret; |
| 2656 | u64 dummy64 = 0; |
| 2657 | u16 dummy16 = 0; |
| 2658 | |
| 2659 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2660 | if (!cb0) { |
| 2661 | ret = -ENOMEM; |
| 2662 | goto out; |
| 2663 | } |
| 2664 | |
| 2665 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { |
| 2666 | struct ehea_port_res *pr = &port->port_res[i]; |
| 2667 | struct ehea_qp *qp = pr->qp; |
| 2668 | |
| 2669 | /* Purge send queue */ |
| 2670 | ehea_purge_sq(qp); |
| 2671 | |
| 2672 | /* Disable queue pair */ |
| 2673 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2674 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2675 | cb0); |
| 2676 | if (hret != H_SUCCESS) { |
| 2677 | ehea_error("query_ehea_qp failed (1)"); |
| 2678 | goto out; |
| 2679 | } |
| 2680 | |
| 2681 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; |
| 2682 | cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED; |
| 2683 | |
| 2684 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2685 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, |
| 2686 | 1), cb0, &dummy64, |
| 2687 | &dummy64, &dummy16, &dummy16); |
| 2688 | if (hret != H_SUCCESS) { |
| 2689 | ehea_error("modify_ehea_qp failed (1)"); |
| 2690 | goto out; |
| 2691 | } |
| 2692 | |
| 2693 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2694 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2695 | cb0); |
| 2696 | if (hret != H_SUCCESS) { |
| 2697 | ehea_error("query_ehea_qp failed (2)"); |
| 2698 | goto out; |
| 2699 | } |
| 2700 | |
| 2701 | /* deregister shared memory regions */ |
| 2702 | dret = ehea_rem_smrs(pr); |
| 2703 | if (dret) { |
| 2704 | ehea_error("unreg shared memory region failed"); |
| 2705 | goto out; |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | ret = 0; |
| 2710 | out: |
| 2711 | kfree(cb0); |
| 2712 | |
| 2713 | return ret; |
| 2714 | } |
| 2715 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2716 | void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr) |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2717 | { |
| 2718 | struct ehea_qp qp = *orig_qp; |
| 2719 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; |
| 2720 | struct ehea_rwqe *rwqe; |
| 2721 | struct sk_buff **skba_rq2 = pr->rq2_skba.arr; |
| 2722 | struct sk_buff **skba_rq3 = pr->rq3_skba.arr; |
| 2723 | struct sk_buff *skb; |
| 2724 | u32 lkey = pr->recv_mr.lkey; |
| 2725 | |
| 2726 | |
| 2727 | int i; |
| 2728 | int index; |
| 2729 | |
| 2730 | for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) { |
| 2731 | rwqe = ehea_get_next_rwqe(&qp, 2); |
| 2732 | rwqe->sg_list[0].l_key = lkey; |
| 2733 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); |
| 2734 | skb = skba_rq2[index]; |
| 2735 | if (skb) |
| 2736 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); |
| 2737 | } |
| 2738 | |
| 2739 | for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) { |
| 2740 | rwqe = ehea_get_next_rwqe(&qp, 3); |
| 2741 | rwqe->sg_list[0].l_key = lkey; |
| 2742 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); |
| 2743 | skb = skba_rq3[index]; |
| 2744 | if (skb) |
| 2745 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | int ehea_restart_qps(struct net_device *dev) |
| 2750 | { |
| 2751 | struct ehea_port *port = netdev_priv(dev); |
| 2752 | struct ehea_adapter *adapter = port->adapter; |
| 2753 | int ret = 0; |
| 2754 | int i; |
| 2755 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 2756 | struct hcp_modify_qp_cb0 *cb0; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2757 | u64 hret; |
| 2758 | u64 dummy64 = 0; |
| 2759 | u16 dummy16 = 0; |
| 2760 | |
| 2761 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2762 | if (!cb0) { |
| 2763 | ret = -ENOMEM; |
| 2764 | goto out; |
| 2765 | } |
| 2766 | |
| 2767 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { |
| 2768 | struct ehea_port_res *pr = &port->port_res[i]; |
| 2769 | struct ehea_qp *qp = pr->qp; |
| 2770 | |
| 2771 | ret = ehea_gen_smrs(pr); |
| 2772 | if (ret) { |
| 2773 | ehea_error("creation of shared memory regions failed"); |
| 2774 | goto out; |
| 2775 | } |
| 2776 | |
| 2777 | ehea_update_rqs(qp, pr); |
| 2778 | |
| 2779 | /* Enable queue pair */ |
| 2780 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2781 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2782 | cb0); |
| 2783 | if (hret != H_SUCCESS) { |
| 2784 | ehea_error("query_ehea_qp failed (1)"); |
| 2785 | goto out; |
| 2786 | } |
| 2787 | |
| 2788 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; |
| 2789 | cb0->qp_ctl_reg |= H_QP_CR_ENABLED; |
| 2790 | |
| 2791 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2792 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, |
| 2793 | 1), cb0, &dummy64, |
| 2794 | &dummy64, &dummy16, &dummy16); |
| 2795 | if (hret != H_SUCCESS) { |
| 2796 | ehea_error("modify_ehea_qp failed (1)"); |
| 2797 | goto out; |
| 2798 | } |
| 2799 | |
| 2800 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2801 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2802 | cb0); |
| 2803 | if (hret != H_SUCCESS) { |
| 2804 | ehea_error("query_ehea_qp failed (2)"); |
| 2805 | goto out; |
| 2806 | } |
| 2807 | |
| 2808 | /* refill entire queue */ |
| 2809 | ehea_refill_rq1(pr, pr->rq1_skba.index, 0); |
| 2810 | ehea_refill_rq2(pr, 0); |
| 2811 | ehea_refill_rq3(pr, 0); |
| 2812 | } |
| 2813 | out: |
| 2814 | kfree(cb0); |
| 2815 | |
| 2816 | return ret; |
| 2817 | } |
| 2818 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2819 | static void ehea_reset_port(struct work_struct *work) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2820 | { |
| 2821 | int ret; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2822 | struct ehea_port *port = |
| 2823 | container_of(work, struct ehea_port, reset_task); |
| 2824 | struct net_device *dev = port->netdev; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2825 | |
| 2826 | port->resets++; |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2827 | mutex_lock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2828 | netif_stop_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2829 | |
| 2830 | port_napi_disable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2831 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2832 | ehea_down(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2833 | |
| 2834 | ret = ehea_up(dev); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2835 | if (ret) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2836 | goto out; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2837 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2838 | ehea_set_multicast_list(dev); |
| 2839 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2840 | if (netif_msg_timer(port)) |
| 2841 | ehea_info("Device %s resetted successfully", dev->name); |
| 2842 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2843 | port_napi_enable(port); |
| 2844 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2845 | netif_wake_queue(dev); |
| 2846 | out: |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2847 | mutex_unlock(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2848 | return; |
| 2849 | } |
| 2850 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2851 | static void ehea_rereg_mrs(struct work_struct *work) |
| 2852 | { |
| 2853 | int ret, i; |
| 2854 | struct ehea_adapter *adapter; |
| 2855 | |
Daniel Walker | 06f89ed | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 2856 | mutex_lock(&dlpar_mem_lock); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2857 | ehea_info("LPAR memory enlarged - re-initializing driver"); |
| 2858 | |
| 2859 | list_for_each_entry(adapter, &adapter_list, list) |
| 2860 | if (adapter->active_ports) { |
| 2861 | /* Shutdown all ports */ |
| 2862 | for (i = 0; i < EHEA_MAX_PORTS; i++) { |
| 2863 | struct ehea_port *port = adapter->port[i]; |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2864 | struct net_device *dev; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2865 | |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2866 | if (!port) |
| 2867 | continue; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2868 | |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2869 | dev = port->netdev; |
| 2870 | |
| 2871 | if (dev->flags & IFF_UP) { |
| 2872 | mutex_lock(&port->port_lock); |
| 2873 | netif_stop_queue(dev); |
David S. Miller | df39e8b | 2008-04-14 02:30:23 -0700 | [diff] [blame] | 2874 | ehea_flush_sq(port); |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2875 | ret = ehea_stop_qps(dev); |
| 2876 | if (ret) { |
| 2877 | mutex_unlock(&port->port_lock); |
| 2878 | goto out; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2879 | } |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2880 | port_napi_disable(port); |
| 2881 | mutex_unlock(&port->port_lock); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | /* Unregister old memory region */ |
| 2886 | ret = ehea_rem_mr(&adapter->mr); |
| 2887 | if (ret) { |
| 2888 | ehea_error("unregister MR failed - driver" |
| 2889 | " inoperable!"); |
| 2890 | goto out; |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | ehea_destroy_busmap(); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2895 | ret = ehea_create_busmap(); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2896 | if (ret) { |
| 2897 | ehea_error("creating ehea busmap failed"); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2898 | goto out; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2899 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2900 | |
| 2901 | clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags); |
| 2902 | |
| 2903 | list_for_each_entry(adapter, &adapter_list, list) |
| 2904 | if (adapter->active_ports) { |
| 2905 | /* Register new memory region */ |
| 2906 | ret = ehea_reg_kernel_mr(adapter, &adapter->mr); |
| 2907 | if (ret) { |
| 2908 | ehea_error("register MR failed - driver" |
| 2909 | " inoperable!"); |
| 2910 | goto out; |
| 2911 | } |
| 2912 | |
| 2913 | /* Restart all ports */ |
| 2914 | for (i = 0; i < EHEA_MAX_PORTS; i++) { |
| 2915 | struct ehea_port *port = adapter->port[i]; |
| 2916 | |
| 2917 | if (port) { |
| 2918 | struct net_device *dev = port->netdev; |
| 2919 | |
| 2920 | if (dev->flags & IFF_UP) { |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2921 | mutex_lock(&port->port_lock); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2922 | port_napi_enable(port); |
| 2923 | ret = ehea_restart_qps(dev); |
| 2924 | if (!ret) |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2925 | netif_wake_queue(dev); |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 2926 | mutex_unlock(&port->port_lock); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | } |
| 2930 | } |
Daniel Walker | 06f89ed | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 2931 | mutex_unlock(&dlpar_mem_lock); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2932 | ehea_info("re-initializing driver complete"); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2933 | out: |
| 2934 | return; |
| 2935 | } |
| 2936 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2937 | static void ehea_tx_watchdog(struct net_device *dev) |
| 2938 | { |
| 2939 | struct ehea_port *port = netdev_priv(dev); |
| 2940 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2941 | if (netif_carrier_ok(dev) && |
| 2942 | !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags)) |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 2943 | schedule_work(&port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | int ehea_sense_adapter_attr(struct ehea_adapter *adapter) |
| 2947 | { |
| 2948 | struct hcp_query_ehea *cb; |
| 2949 | u64 hret; |
| 2950 | int ret; |
| 2951 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2952 | cb = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2953 | if (!cb) { |
| 2954 | ret = -ENOMEM; |
| 2955 | goto out; |
| 2956 | } |
| 2957 | |
| 2958 | hret = ehea_h_query_ehea(adapter->handle, cb); |
| 2959 | |
| 2960 | if (hret != H_SUCCESS) { |
| 2961 | ret = -EIO; |
| 2962 | goto out_herr; |
| 2963 | } |
| 2964 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2965 | adapter->max_mc_mac = cb->max_mc_mac - 1; |
| 2966 | ret = 0; |
| 2967 | |
| 2968 | out_herr: |
| 2969 | kfree(cb); |
| 2970 | out: |
| 2971 | return ret; |
| 2972 | } |
| 2973 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2974 | int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo) |
| 2975 | { |
| 2976 | struct hcp_ehea_port_cb4 *cb4; |
| 2977 | u64 hret; |
| 2978 | int ret = 0; |
| 2979 | |
| 2980 | *jumbo = 0; |
| 2981 | |
| 2982 | /* (Try to) enable *jumbo frames */ |
| 2983 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2984 | if (!cb4) { |
| 2985 | ehea_error("no mem for cb4"); |
| 2986 | ret = -ENOMEM; |
| 2987 | goto out; |
| 2988 | } else { |
| 2989 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 2990 | port->logical_port_id, |
| 2991 | H_PORT_CB4, |
| 2992 | H_PORT_CB4_JUMBO, cb4); |
| 2993 | if (hret == H_SUCCESS) { |
| 2994 | if (cb4->jumbo_frame) |
| 2995 | *jumbo = 1; |
| 2996 | else { |
| 2997 | cb4->jumbo_frame = 1; |
| 2998 | hret = ehea_h_modify_ehea_port(port->adapter-> |
| 2999 | handle, |
| 3000 | port-> |
| 3001 | logical_port_id, |
| 3002 | H_PORT_CB4, |
| 3003 | H_PORT_CB4_JUMBO, |
| 3004 | cb4); |
| 3005 | if (hret == H_SUCCESS) |
| 3006 | *jumbo = 1; |
| 3007 | } |
| 3008 | } else |
| 3009 | ret = -EINVAL; |
| 3010 | |
| 3011 | kfree(cb4); |
| 3012 | } |
| 3013 | out: |
| 3014 | return ret; |
| 3015 | } |
| 3016 | |
| 3017 | static ssize_t ehea_show_port_id(struct device *dev, |
| 3018 | struct device_attribute *attr, char *buf) |
| 3019 | { |
| 3020 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 3021 | return sprintf(buf, "%d", port->logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id, |
| 3025 | NULL); |
| 3026 | |
| 3027 | static void __devinit logical_port_release(struct device *dev) |
| 3028 | { |
| 3029 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); |
| 3030 | of_node_put(port->ofdev.node); |
| 3031 | } |
| 3032 | |
| 3033 | static struct device *ehea_register_port(struct ehea_port *port, |
| 3034 | struct device_node *dn) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3035 | { |
| 3036 | int ret; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3037 | |
| 3038 | port->ofdev.node = of_node_get(dn); |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3039 | port->ofdev.dev.parent = &port->adapter->ofdev->dev; |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 3040 | port->ofdev.dev.bus = &ibmebus_bus_type; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3041 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 3042 | sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3043 | port->ofdev.dev.release = logical_port_release; |
| 3044 | |
| 3045 | ret = of_device_register(&port->ofdev); |
| 3046 | if (ret) { |
| 3047 | ehea_error("failed to register device. ret=%d", ret); |
| 3048 | goto out; |
| 3049 | } |
| 3050 | |
| 3051 | ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3052 | if (ret) { |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3053 | ehea_error("failed to register attributes, ret=%d", ret); |
| 3054 | goto out_unreg_of_dev; |
| 3055 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3056 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3057 | return &port->ofdev.dev; |
| 3058 | |
| 3059 | out_unreg_of_dev: |
| 3060 | of_device_unregister(&port->ofdev); |
| 3061 | out: |
| 3062 | return NULL; |
| 3063 | } |
| 3064 | |
| 3065 | static void ehea_unregister_port(struct ehea_port *port) |
| 3066 | { |
| 3067 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); |
| 3068 | of_device_unregister(&port->ofdev); |
| 3069 | } |
| 3070 | |
| 3071 | struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter, |
| 3072 | u32 logical_port_id, |
| 3073 | struct device_node *dn) |
| 3074 | { |
| 3075 | int ret; |
| 3076 | struct net_device *dev; |
| 3077 | struct ehea_port *port; |
| 3078 | struct device *port_dev; |
| 3079 | int jumbo; |
| 3080 | |
| 3081 | /* allocate memory for the port structures */ |
| 3082 | dev = alloc_etherdev(sizeof(struct ehea_port)); |
| 3083 | |
| 3084 | if (!dev) { |
| 3085 | ehea_error("no mem for net_device"); |
| 3086 | ret = -ENOMEM; |
| 3087 | goto out_err; |
| 3088 | } |
| 3089 | |
| 3090 | port = netdev_priv(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3091 | |
Daniel Walker | a5af6ad | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 3092 | mutex_init(&port->port_lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3093 | port->state = EHEA_PORT_DOWN; |
| 3094 | port->sig_comp_iv = sq_entries / 10; |
| 3095 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3096 | port->adapter = adapter; |
| 3097 | port->netdev = dev; |
| 3098 | port->logical_port_id = logical_port_id; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3099 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3100 | port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3101 | |
| 3102 | port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL); |
| 3103 | if (!port->mc_list) { |
| 3104 | ret = -ENOMEM; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3105 | goto out_free_ethdev; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | INIT_LIST_HEAD(&port->mc_list->list); |
| 3109 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3110 | ret = ehea_sense_port_attr(port); |
| 3111 | if (ret) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3112 | goto out_free_mc_list; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3113 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3114 | port_dev = ehea_register_port(port, dn); |
| 3115 | if (!port_dev) |
| 3116 | goto out_free_mc_list; |
Thomas Klein | 9c750b7 | 2007-01-29 18:44:01 +0100 | [diff] [blame] | 3117 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3118 | SET_NETDEV_DEV(dev, port_dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3119 | |
| 3120 | /* initialize net_device structure */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3121 | memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN); |
| 3122 | |
| 3123 | dev->open = ehea_open; |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 3124 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3125 | dev->poll_controller = ehea_netpoll; |
| 3126 | #endif |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3127 | dev->stop = ehea_stop; |
| 3128 | dev->hard_start_xmit = ehea_start_xmit; |
| 3129 | dev->get_stats = ehea_get_stats; |
| 3130 | dev->set_multicast_list = ehea_set_multicast_list; |
| 3131 | dev->set_mac_address = ehea_set_mac_addr; |
| 3132 | dev->change_mtu = ehea_change_mtu; |
| 3133 | dev->vlan_rx_register = ehea_vlan_rx_register; |
| 3134 | dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid; |
| 3135 | dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid; |
| 3136 | dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |
Thomas Klein | dc01c44 | 2008-03-19 13:55:43 +0100 | [diff] [blame] | 3137 | | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3138 | | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER |
| 3139 | | NETIF_F_LLTX; |
| 3140 | dev->tx_timeout = &ehea_tx_watchdog; |
| 3141 | dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT; |
| 3142 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3143 | INIT_WORK(&port->reset_task, ehea_reset_port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3144 | ehea_set_ethtool_ops(dev); |
| 3145 | |
| 3146 | ret = register_netdev(dev); |
| 3147 | if (ret) { |
| 3148 | ehea_error("register_netdev failed. ret=%d", ret); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3149 | goto out_unreg_port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3150 | } |
| 3151 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 3152 | port->lro_max_aggr = lro_max_aggr; |
| 3153 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3154 | ret = ehea_get_jumboframe_status(port, &jumbo); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3155 | if (ret) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3156 | ehea_error("failed determining jumbo frame status for %s", |
| 3157 | port->netdev->name); |
| 3158 | |
Thomas Klein | 9c750b7 | 2007-01-29 18:44:01 +0100 | [diff] [blame] | 3159 | ehea_info("%s: Jumbo frames are %sabled", dev->name, |
| 3160 | jumbo == 1 ? "en" : "dis"); |
| 3161 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3162 | adapter->active_ports++; |
| 3163 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3164 | return port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3165 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3166 | out_unreg_port: |
| 3167 | ehea_unregister_port(port); |
| 3168 | |
| 3169 | out_free_mc_list: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3170 | kfree(port->mc_list); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3171 | |
| 3172 | out_free_ethdev: |
| 3173 | free_netdev(dev); |
| 3174 | |
| 3175 | out_err: |
| 3176 | ehea_error("setting up logical port with id=%d failed, ret=%d", |
| 3177 | logical_port_id, ret); |
| 3178 | return NULL; |
| 3179 | } |
| 3180 | |
| 3181 | static void ehea_shutdown_single_port(struct ehea_port *port) |
| 3182 | { |
Brian King | 7fb1c2a | 2008-05-14 09:48:25 -0500 | [diff] [blame] | 3183 | struct ehea_adapter *adapter = port->adapter; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3184 | unregister_netdev(port->netdev); |
| 3185 | ehea_unregister_port(port); |
| 3186 | kfree(port->mc_list); |
| 3187 | free_netdev(port->netdev); |
Brian King | 7fb1c2a | 2008-05-14 09:48:25 -0500 | [diff] [blame] | 3188 | adapter->active_ports--; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | static int ehea_setup_ports(struct ehea_adapter *adapter) |
| 3192 | { |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3193 | struct device_node *lhea_dn; |
| 3194 | struct device_node *eth_dn = NULL; |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3195 | |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3196 | const u32 *dn_log_port_id; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3197 | int i = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3198 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3199 | lhea_dn = adapter->ofdev->node; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3200 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3201 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 3202 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3203 | NULL); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3204 | if (!dn_log_port_id) { |
| 3205 | ehea_error("bad device node: eth_dn name=%s", |
| 3206 | eth_dn->full_name); |
| 3207 | continue; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3208 | } |
| 3209 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3210 | if (ehea_add_adapter_mr(adapter)) { |
| 3211 | ehea_error("creating MR failed"); |
| 3212 | of_node_put(eth_dn); |
| 3213 | return -EIO; |
| 3214 | } |
| 3215 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3216 | adapter->port[i] = ehea_setup_single_port(adapter, |
| 3217 | *dn_log_port_id, |
| 3218 | eth_dn); |
| 3219 | if (adapter->port[i]) |
| 3220 | ehea_info("%s -> logical port id #%d", |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3221 | adapter->port[i]->netdev->name, |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3222 | *dn_log_port_id); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3223 | else |
| 3224 | ehea_remove_adapter_mr(adapter); |
| 3225 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3226 | i++; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3227 | }; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3228 | return 0; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3229 | } |
| 3230 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3231 | static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter, |
| 3232 | u32 logical_port_id) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3233 | { |
| 3234 | struct device_node *lhea_dn; |
| 3235 | struct device_node *eth_dn = NULL; |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3236 | const u32 *dn_log_port_id; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3237 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3238 | lhea_dn = adapter->ofdev->node; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3239 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3240 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 3241 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3242 | NULL); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3243 | if (dn_log_port_id) |
| 3244 | if (*dn_log_port_id == logical_port_id) |
| 3245 | return eth_dn; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3246 | }; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3247 | |
| 3248 | return NULL; |
| 3249 | } |
| 3250 | |
| 3251 | static ssize_t ehea_probe_port(struct device *dev, |
| 3252 | struct device_attribute *attr, |
| 3253 | const char *buf, size_t count) |
| 3254 | { |
| 3255 | struct ehea_adapter *adapter = dev->driver_data; |
| 3256 | struct ehea_port *port; |
| 3257 | struct device_node *eth_dn = NULL; |
| 3258 | int i; |
| 3259 | |
| 3260 | u32 logical_port_id; |
| 3261 | |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 3262 | sscanf(buf, "%d", &logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3263 | |
| 3264 | port = ehea_get_port(adapter, logical_port_id); |
| 3265 | |
| 3266 | if (port) { |
| 3267 | ehea_info("adding port with logical port id=%d failed. port " |
| 3268 | "already configured as %s.", logical_port_id, |
| 3269 | port->netdev->name); |
| 3270 | return -EINVAL; |
| 3271 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3272 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3273 | eth_dn = ehea_get_eth_dn(adapter, logical_port_id); |
| 3274 | |
| 3275 | if (!eth_dn) { |
| 3276 | ehea_info("no logical port with id %d found", logical_port_id); |
| 3277 | return -EINVAL; |
| 3278 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3279 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3280 | if (ehea_add_adapter_mr(adapter)) { |
| 3281 | ehea_error("creating MR failed"); |
| 3282 | return -EIO; |
| 3283 | } |
| 3284 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3285 | port = ehea_setup_single_port(adapter, logical_port_id, eth_dn); |
| 3286 | |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3287 | of_node_put(eth_dn); |
| 3288 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3289 | if (port) { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 3290 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3291 | if (!adapter->port[i]) { |
| 3292 | adapter->port[i] = port; |
| 3293 | break; |
| 3294 | } |
| 3295 | |
| 3296 | ehea_info("added %s (logical port id=%d)", port->netdev->name, |
| 3297 | logical_port_id); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3298 | } else { |
| 3299 | ehea_remove_adapter_mr(adapter); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3300 | return -EIO; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3301 | } |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3302 | |
| 3303 | return (ssize_t) count; |
| 3304 | } |
| 3305 | |
| 3306 | static ssize_t ehea_remove_port(struct device *dev, |
| 3307 | struct device_attribute *attr, |
| 3308 | const char *buf, size_t count) |
| 3309 | { |
| 3310 | struct ehea_adapter *adapter = dev->driver_data; |
| 3311 | struct ehea_port *port; |
| 3312 | int i; |
| 3313 | u32 logical_port_id; |
| 3314 | |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 3315 | sscanf(buf, "%d", &logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3316 | |
| 3317 | port = ehea_get_port(adapter, logical_port_id); |
| 3318 | |
| 3319 | if (port) { |
| 3320 | ehea_info("removed %s (logical port id=%d)", port->netdev->name, |
| 3321 | logical_port_id); |
| 3322 | |
| 3323 | ehea_shutdown_single_port(port); |
| 3324 | |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 3325 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3326 | if (adapter->port[i] == port) { |
| 3327 | adapter->port[i] = NULL; |
| 3328 | break; |
| 3329 | } |
| 3330 | } else { |
| 3331 | ehea_error("removing port with logical port id=%d failed. port " |
| 3332 | "not configured.", logical_port_id); |
| 3333 | return -EINVAL; |
| 3334 | } |
| 3335 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3336 | ehea_remove_adapter_mr(adapter); |
| 3337 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3338 | return (ssize_t) count; |
| 3339 | } |
| 3340 | |
| 3341 | static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); |
| 3342 | static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); |
| 3343 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3344 | int ehea_create_device_sysfs(struct of_device *dev) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3345 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3346 | int ret = device_create_file(&dev->dev, &dev_attr_probe_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3347 | if (ret) |
| 3348 | goto out; |
| 3349 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3350 | ret = device_create_file(&dev->dev, &dev_attr_remove_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3351 | out: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3352 | return ret; |
| 3353 | } |
| 3354 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3355 | void ehea_remove_device_sysfs(struct of_device *dev) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3356 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3357 | device_remove_file(&dev->dev, &dev_attr_probe_port); |
| 3358 | device_remove_file(&dev->dev, &dev_attr_remove_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3359 | } |
| 3360 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3361 | static int __devinit ehea_probe_adapter(struct of_device *dev, |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3362 | const struct of_device_id *id) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3363 | { |
| 3364 | struct ehea_adapter *adapter; |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3365 | const u64 *adapter_handle; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3366 | int ret; |
| 3367 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3368 | if (!dev || !dev->node) { |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3369 | ehea_error("Invalid ibmebus device probed"); |
| 3370 | return -EINVAL; |
| 3371 | } |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 3372 | mutex_lock(&ehea_fw_handles.lock); |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3373 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3374 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 3375 | if (!adapter) { |
| 3376 | ret = -ENOMEM; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3377 | dev_err(&dev->dev, "no mem for ehea_adapter\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3378 | goto out; |
| 3379 | } |
| 3380 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3381 | list_add(&adapter->list, &adapter_list); |
| 3382 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3383 | adapter->ofdev = dev; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3384 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3385 | adapter_handle = of_get_property(dev->node, "ibm,hea-handle", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3386 | NULL); |
Thomas Klein | 061bf3c | 2007-01-22 12:52:20 +0100 | [diff] [blame] | 3387 | if (adapter_handle) |
| 3388 | adapter->handle = *adapter_handle; |
| 3389 | |
| 3390 | if (!adapter->handle) { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3391 | dev_err(&dev->dev, "failed getting handle for adapter" |
| 3392 | " '%s'\n", dev->node->full_name); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3393 | ret = -ENODEV; |
| 3394 | goto out_free_ad; |
| 3395 | } |
| 3396 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3397 | adapter->pd = EHEA_PD_ID; |
| 3398 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3399 | dev->dev.driver_data = adapter; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3400 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3401 | |
| 3402 | /* initialize adapter and ports */ |
| 3403 | /* get adapter properties */ |
| 3404 | ret = ehea_sense_adapter_attr(adapter); |
| 3405 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3406 | dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3407 | goto out_free_ad; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3408 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3409 | |
| 3410 | adapter->neq = ehea_create_eq(adapter, |
| 3411 | EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1); |
| 3412 | if (!adapter->neq) { |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3413 | ret = -EIO; |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3414 | dev_err(&dev->dev, "NEQ creation failed\n"); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3415 | goto out_free_ad; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet, |
| 3419 | (unsigned long)adapter); |
| 3420 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3421 | ret = ibmebus_request_irq(adapter->neq->attr.ist1, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 3422 | ehea_interrupt_neq, IRQF_DISABLED, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3423 | "ehea_neq", adapter); |
| 3424 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3425 | dev_err(&dev->dev, "requesting NEQ IRQ failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3426 | goto out_kill_eq; |
| 3427 | } |
| 3428 | |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3429 | ret = ehea_create_device_sysfs(dev); |
| 3430 | if (ret) |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3431 | goto out_free_irq; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3432 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3433 | ret = ehea_setup_ports(adapter); |
| 3434 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3435 | dev_err(&dev->dev, "setup_ports failed\n"); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3436 | goto out_rem_dev_sysfs; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | ret = 0; |
| 3440 | goto out; |
| 3441 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3442 | out_rem_dev_sysfs: |
| 3443 | ehea_remove_device_sysfs(dev); |
| 3444 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3445 | out_free_irq: |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3446 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3447 | |
| 3448 | out_kill_eq: |
| 3449 | ehea_destroy_eq(adapter->neq); |
| 3450 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3451 | out_free_ad: |
| 3452 | kfree(adapter); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3453 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3454 | out: |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3455 | ehea_update_firmware_handles(); |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 3456 | mutex_unlock(&ehea_fw_handles.lock); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3457 | return ret; |
| 3458 | } |
| 3459 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3460 | static int __devexit ehea_remove(struct of_device *dev) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3461 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3462 | struct ehea_adapter *adapter = dev->dev.driver_data; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3463 | int i; |
| 3464 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3465 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3466 | if (adapter->port[i]) { |
| 3467 | ehea_shutdown_single_port(adapter->port[i]); |
| 3468 | adapter->port[i] = NULL; |
| 3469 | } |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3470 | |
| 3471 | ehea_remove_device_sysfs(dev); |
| 3472 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3473 | flush_scheduled_work(); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3474 | |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 3475 | mutex_lock(&ehea_fw_handles.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3476 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3477 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); |
Thomas Klein | d4150a2 | 2007-01-29 18:44:41 +0100 | [diff] [blame] | 3478 | tasklet_kill(&adapter->neq_tasklet); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3479 | |
| 3480 | ehea_destroy_eq(adapter->neq); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3481 | ehea_remove_adapter_mr(adapter); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3482 | list_del(&adapter->list); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3483 | kfree(adapter); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3484 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3485 | ehea_update_firmware_handles(); |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 3486 | mutex_unlock(&ehea_fw_handles.lock); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3487 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3488 | return 0; |
| 3489 | } |
| 3490 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3491 | void ehea_crash_handler(void) |
| 3492 | { |
| 3493 | int i; |
| 3494 | |
| 3495 | if (ehea_fw_handles.arr) |
| 3496 | for (i = 0; i < ehea_fw_handles.num_entries; i++) |
| 3497 | ehea_h_free_resource(ehea_fw_handles.arr[i].adh, |
| 3498 | ehea_fw_handles.arr[i].fwh, |
| 3499 | FORCE_FREE); |
| 3500 | |
| 3501 | if (ehea_bcmc_regs.arr) |
| 3502 | for (i = 0; i < ehea_bcmc_regs.num_entries; i++) |
| 3503 | ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh, |
| 3504 | ehea_bcmc_regs.arr[i].port_id, |
| 3505 | ehea_bcmc_regs.arr[i].reg_type, |
| 3506 | ehea_bcmc_regs.arr[i].macaddr, |
| 3507 | 0, H_DEREG_BCMC); |
| 3508 | } |
| 3509 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 3510 | static int ehea_mem_notifier(struct notifier_block *nb, |
| 3511 | unsigned long action, void *data) |
| 3512 | { |
| 3513 | switch (action) { |
| 3514 | case MEM_OFFLINE: |
| 3515 | ehea_info("memory has been removed"); |
| 3516 | ehea_rereg_mrs(NULL); |
| 3517 | break; |
| 3518 | default: |
| 3519 | break; |
| 3520 | } |
| 3521 | return NOTIFY_OK; |
| 3522 | } |
| 3523 | |
| 3524 | static struct notifier_block ehea_mem_nb = { |
| 3525 | .notifier_call = ehea_mem_notifier, |
| 3526 | }; |
| 3527 | |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 3528 | static int ehea_reboot_notifier(struct notifier_block *nb, |
| 3529 | unsigned long action, void *unused) |
| 3530 | { |
| 3531 | if (action == SYS_RESTART) { |
| 3532 | ehea_info("Reboot: freeing all eHEA resources"); |
| 3533 | ibmebus_unregister_driver(&ehea_driver); |
| 3534 | } |
| 3535 | return NOTIFY_DONE; |
| 3536 | } |
| 3537 | |
| 3538 | static struct notifier_block ehea_reboot_nb = { |
Doug Maxey | 508d2b5 | 2008-01-31 20:20:49 -0600 | [diff] [blame] | 3539 | .notifier_call = ehea_reboot_notifier, |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 3540 | }; |
| 3541 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3542 | static int check_module_parm(void) |
| 3543 | { |
| 3544 | int ret = 0; |
| 3545 | |
| 3546 | if ((rq1_entries < EHEA_MIN_ENTRIES_QP) || |
| 3547 | (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) { |
| 3548 | ehea_info("Bad parameter: rq1_entries"); |
| 3549 | ret = -EINVAL; |
| 3550 | } |
| 3551 | if ((rq2_entries < EHEA_MIN_ENTRIES_QP) || |
| 3552 | (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) { |
| 3553 | ehea_info("Bad parameter: rq2_entries"); |
| 3554 | ret = -EINVAL; |
| 3555 | } |
| 3556 | if ((rq3_entries < EHEA_MIN_ENTRIES_QP) || |
| 3557 | (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) { |
| 3558 | ehea_info("Bad parameter: rq3_entries"); |
| 3559 | ret = -EINVAL; |
| 3560 | } |
| 3561 | if ((sq_entries < EHEA_MIN_ENTRIES_QP) || |
| 3562 | (sq_entries > EHEA_MAX_ENTRIES_SQ)) { |
| 3563 | ehea_info("Bad parameter: sq_entries"); |
| 3564 | ret = -EINVAL; |
| 3565 | } |
| 3566 | |
| 3567 | return ret; |
| 3568 | } |
| 3569 | |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3570 | static ssize_t ehea_show_capabilities(struct device_driver *drv, |
| 3571 | char *buf) |
| 3572 | { |
| 3573 | return sprintf(buf, "%d", EHEA_CAPABILITIES); |
| 3574 | } |
| 3575 | |
| 3576 | static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH, |
| 3577 | ehea_show_capabilities, NULL); |
| 3578 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3579 | int __init ehea_module_init(void) |
| 3580 | { |
| 3581 | int ret; |
| 3582 | |
| 3583 | printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n", |
| 3584 | DRV_VERSION); |
| 3585 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3586 | |
| 3587 | INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3588 | memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles)); |
| 3589 | memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs)); |
| 3590 | |
Daniel Walker | 9f71a56 | 2008-03-28 14:41:26 -0700 | [diff] [blame] | 3591 | mutex_init(&ehea_fw_handles.lock); |
Daniel Walker | da59cde | 2008-03-28 14:41:28 -0700 | [diff] [blame] | 3592 | mutex_init(&ehea_bcmc_regs.lock); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3593 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3594 | ret = check_module_parm(); |
| 3595 | if (ret) |
| 3596 | goto out; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3597 | |
| 3598 | ret = ehea_create_busmap(); |
| 3599 | if (ret) |
| 3600 | goto out; |
| 3601 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3602 | ret = register_reboot_notifier(&ehea_reboot_nb); |
| 3603 | if (ret) |
| 3604 | ehea_info("failed registering reboot notifier"); |
| 3605 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 3606 | ret = register_memory_notifier(&ehea_mem_nb); |
| 3607 | if (ret) |
| 3608 | ehea_info("failed registering memory remove notifier"); |
| 3609 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3610 | ret = crash_shutdown_register(&ehea_crash_handler); |
| 3611 | if (ret) |
| 3612 | ehea_info("failed registering crash handler"); |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 3613 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3614 | ret = ibmebus_register_driver(&ehea_driver); |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3615 | if (ret) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3616 | ehea_error("failed registering eHEA device driver on ebus"); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3617 | goto out2; |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | ret = driver_create_file(&ehea_driver.driver, |
| 3621 | &driver_attr_capabilities); |
| 3622 | if (ret) { |
| 3623 | ehea_error("failed to register capabilities attribute, ret=%d", |
| 3624 | ret); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3625 | goto out3; |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3626 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3627 | |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3628 | return ret; |
| 3629 | |
| 3630 | out3: |
| 3631 | ibmebus_unregister_driver(&ehea_driver); |
| 3632 | out2: |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 3633 | unregister_memory_notifier(&ehea_mem_nb); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3634 | unregister_reboot_notifier(&ehea_reboot_nb); |
| 3635 | crash_shutdown_unregister(&ehea_crash_handler); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3636 | out: |
| 3637 | return ret; |
| 3638 | } |
| 3639 | |
| 3640 | static void __exit ehea_module_exit(void) |
| 3641 | { |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3642 | int ret; |
| 3643 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3644 | flush_scheduled_work(); |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3645 | driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3646 | ibmebus_unregister_driver(&ehea_driver); |
Jan-Bernd Themann | 2a6f4e4 | 2007-10-26 14:37:28 +0200 | [diff] [blame] | 3647 | unregister_reboot_notifier(&ehea_reboot_nb); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3648 | ret = crash_shutdown_unregister(&ehea_crash_handler); |
| 3649 | if (ret) |
| 3650 | ehea_info("failed unregistering crash handler"); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 3651 | unregister_memory_notifier(&ehea_mem_nb); |
Thomas Klein | 21eee2d | 2008-02-13 16:18:33 +0100 | [diff] [blame] | 3652 | kfree(ehea_fw_handles.arr); |
| 3653 | kfree(ehea_bcmc_regs.arr); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3654 | ehea_destroy_busmap(); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | module_init(ehea_module_init); |
| 3658 | module_exit(ehea_module_exit); |