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