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