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