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