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