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