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