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