blob: 90ea0b1673ca45300f902f0f038f0a4a7061b745 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 * linux/drivers/net/ethernet/ibm/ehea/ehea_main.c
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
75MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
Dave Young31d17532013-02-15 20:19:19 +000079 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
Dave Young31d17532013-02-15 20:19:19 +000082 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020083 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
Dave Young31d17532013-02-15 20:19:19 +000085 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020086 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
Dave Young31d17532013-02-15 20:19:19 +000088 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020089 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000090MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
91 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Doug Maxey508d2b52008-01-31 20:20:49 -060093static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020094static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080095static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070096static DEFINE_MUTEX(dlpar_mem_lock);
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +000097static struct ehea_fw_handle_array ehea_fw_handles;
98static struct ehea_bcmc_reg_array ehea_bcmc_regs;
Thomas Klein21eee2d2008-02-13 16:18:33 +010099
Thomas Kleind1dea382007-04-26 11:56:13 +0200100
Bill Pemberton0297be02012-12-03 09:23:10 -0500101static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Bill Pemberton0297be02012-12-03 09:23:10 -0500104static int ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200105
106static struct of_device_id ehea_device_table[] = {
107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {},
112};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100113MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000115static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700116 .driver = {
117 .name = "ehea",
118 .owner = THIS_MODULE,
119 .of_match_table = ehea_device_table,
120 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .probe = ehea_probe_adapter,
122 .remove = ehea_remove,
123};
124
Doug Maxey508d2b52008-01-31 20:20:49 -0600125void ehea_dump(void *adr, int len, char *msg)
126{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200127 int x;
128 unsigned char *deb = adr;
129 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 deb += 16;
133 }
134}
135
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +0000136static void ehea_schedule_port_reset(struct ehea_port *port)
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100137{
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
139 schedule_work(&port->reset_task);
140}
141
Thomas Klein21eee2d2008-02-13 16:18:33 +0100142static void ehea_update_firmware_handles(void)
143{
144 struct ehea_fw_handle_entry *arr = NULL;
145 struct ehea_adapter *adapter;
146 int num_adapters = 0;
147 int num_ports = 0;
148 int num_portres = 0;
149 int i = 0;
150 int num_fw_handles, k, l;
151
152 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700153 mutex_lock(&ehea_fw_handles.lock);
154
Thomas Klein21eee2d2008-02-13 16:18:33 +0100155 list_for_each_entry(adapter, &adapter_list, list) {
156 num_adapters++;
157
158 for (k = 0; k < EHEA_MAX_PORTS; k++) {
159 struct ehea_port *port = adapter->port[k];
160
161 if (!port || (port->state != EHEA_PORT_UP))
162 continue;
163
164 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000165 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 }
167 }
168
169 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
170 num_ports * EHEA_NUM_PORT_FW_HANDLES +
171 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
172
173 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000174 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700176 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100177 } else
178 goto out_update;
179
180 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 if (num_adapters == 0)
182 break;
183
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
Joe Perches8e95a202009-12-03 07:58:21 +0000187 if (!port || (port->state != EHEA_PORT_UP) ||
188 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 continue;
190
Anton Blanchard723f28e2011-10-14 05:31:01 +0000191 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 struct ehea_port_res *pr = &port->port_res[l];
193
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->qp->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_cq->fw_handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_cq->fw_handle;
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = pr->eq->fw_handle;
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->send_mr.handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->recv_mr.handle;
206 }
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700209 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222out_update:
223 kfree(ehea_fw_handles.arr);
224 ehea_fw_handles.arr = arr;
225 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226out:
227 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228}
229
230static void ehea_update_bcmc_registrations(void)
231{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 struct ehea_bcmc_reg_entry *arr = NULL;
234 struct ehea_adapter *adapter;
235 struct ehea_mc_list *mc_entry;
236 int num_registrations = 0;
237 int i = 0;
238 int k;
239
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
241
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 /* Determine number of registrations */
243 list_for_each_entry(adapter, &adapter_list, list)
244 for (k = 0; k < EHEA_MAX_PORTS; k++) {
245 struct ehea_port *port = adapter->port[k];
246
247 if (!port || (port->state != EHEA_PORT_UP))
248 continue;
249
250 num_registrations += 2; /* Broadcast registrations */
251
252 list_for_each_entry(mc_entry, &port->mc_list->list,list)
253 num_registrations += 2;
254 }
255
256 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000257 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100258 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700259 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100260 } else
261 goto out_update;
262
263 list_for_each_entry(adapter, &adapter_list, list) {
264 for (k = 0; k < EHEA_MAX_PORTS; k++) {
265 struct ehea_port *port = adapter->port[k];
266
267 if (!port || (port->state != EHEA_PORT_UP))
268 continue;
269
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 if (num_registrations == 0)
271 goto out_update;
272
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 arr[i].adh = adapter->handle;
274 arr[i].port_id = port->logical_port_id;
275 arr[i].reg_type = EHEA_BCMC_BROADCAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = port->mac_addr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_BROADCAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285
286 list_for_each_entry(mc_entry,
287 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700288 if (num_registrations == 0)
289 goto out_update;
290
Thomas Klein21eee2d2008-02-13 16:18:33 +0100291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000293 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100294 EHEA_BCMC_UNTAGGED;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000295 if (mc_entry->macaddr == 0)
296 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297 arr[i++].macaddr = mc_entry->macaddr;
298
299 arr[i].adh = adapter->handle;
300 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000301 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 EHEA_BCMC_VLANID_ALL;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000303 if (mc_entry->macaddr == 0)
304 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700306 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100307 }
308 }
309 }
310
311out_update:
312 kfree(ehea_bcmc_regs.arr);
313 ehea_bcmc_regs.arr = arr;
314 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315out:
316 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317}
318
Anton Blanchard239c5622011-10-14 05:31:09 +0000319static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
320 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200321{
322 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000323 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324 int i;
325
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000326 for (i = 0; i < port->num_def_qps; i++) {
327 rx_packets += port->port_res[i].rx_packets;
328 rx_bytes += port->port_res[i].rx_bytes;
329 }
330
Anton Blanchard723f28e2011-10-14 05:31:01 +0000331 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000332 tx_packets += port->port_res[i].tx_packets;
333 tx_bytes += port->port_res[i].tx_bytes;
334 }
335
336 stats->tx_packets = tx_packets;
337 stats->rx_bytes = rx_bytes;
338 stats->tx_bytes = tx_bytes;
339 stats->rx_packets = rx_packets;
340
Eric Dumazet09c1d442012-03-06 19:46:41 +0000341 stats->multicast = port->stats.multicast;
342 stats->rx_errors = port->stats.rx_errors;
343 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000344}
345
346static void ehea_update_stats(struct work_struct *work)
347{
348 struct ehea_port *port =
349 container_of(work, struct ehea_port, stats_work.work);
350 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000351 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000352 struct hcp_ehea_port_cb2 *cb2;
353 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200354
Brian King3d8009c2010-06-30 11:59:12 +0000355 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000357 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
358 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 }
360
361 hret = ehea_h_query_ehea_port(port->adapter->handle,
362 port->logical_port_id,
363 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
364 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800365 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 goto out_herr;
367 }
368
369 if (netif_msg_hw(port))
370 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 stats->multicast = cb2->rxmcp;
373 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374
375out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800376 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000377resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000378 schedule_delayed_work(&port->stats_work,
379 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200406 break;
407 }
408 }
409 index--;
410 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200411 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200413
414 if (adder == 0)
415 return;
416
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200419}
420
Thomas Kleine2878802009-01-21 14:45:57 -0800421static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
424 struct net_device *dev = pr->port->netdev;
425 int i;
426
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000427 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800428 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000429 return;
430 }
431
432 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000434 if (!skb_arr_rq1[i])
Thomas Kleine2878802009-01-21 14:45:57 -0800435 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 }
437 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000438 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439}
440
441static int ehea_refill_rq_def(struct ehea_port_res *pr,
442 struct ehea_q_skb_arr *q_skba, int rq_nr,
443 int num_wqes, int wqe_type, int packet_size)
444{
445 struct net_device *dev = pr->port->netdev;
446 struct ehea_qp *qp = pr->qp;
447 struct sk_buff **skb_arr = q_skba->arr;
448 struct ehea_rwqe *rwqe;
449 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200450 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 int ret = 0;
452
453 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200454 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200455
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200456 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
457 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460
461 index = q_skba->index;
462 max_index_mask = q_skba->len - 1;
463 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200464 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000465 struct sk_buff *skb;
466
467 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800470 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800471 netdev_info(pr->port->netdev,
472 "rq%i ran dry - no mem for skb\n",
473 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800474 ret = -ENOMEM;
475 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 break;
477 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478
479 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200480 tmp_addr = ehea_map_vaddr(skb->data);
481 if (tmp_addr == -1) {
482 dev_kfree_skb(skb);
483 q_skba->os_skbs = fill_wqes - i;
484 ret = 0;
485 break;
486 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487
488 rwqe = ehea_get_next_rwqe(qp, rq_nr);
489 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200490 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200491 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 rwqe->sg_list[0].len = packet_size;
494 rwqe->data_segments = 1;
495
496 index++;
497 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200498 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499 }
Thomas Klein44c82152007-07-11 16:32:00 +0200500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200501 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200502 if (adder == 0)
503 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504
505 /* Ring doorbell */
506 iosync();
507 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200508 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200511out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 return ret;
513}
514
515
516static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
517{
518 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
519 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000520 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521}
522
523
524static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
525{
526 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
527 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000528 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200529}
530
531static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
532{
533 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
534 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
535 return 0;
536 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
537 (cqe->header_length == 0))
538 return 0;
539 return -EINVAL;
540}
541
542static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000543 struct sk_buff *skb, struct ehea_cqe *cqe,
544 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200545{
546 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
547
548 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200549 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000550
551 /* The packet was not an IPV4 packet so a complemented checksum was
552 calculated. The value is found in the Internet Checksum field. */
553 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
554 skb->ip_summed = CHECKSUM_COMPLETE;
555 skb->csum = csum_unfold(~cqe->inet_checksum_value);
556 } else
557 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000558
559 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560}
561
562static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
563 int arr_len,
564 struct ehea_cqe *cqe)
565{
566 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
567 struct sk_buff *skb;
568 void *pref;
569 int x;
570
571 x = skb_index + 1;
572 x &= (arr_len - 1);
573
574 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700575 if (pref) {
576 prefetchw(pref);
577 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578
Hannes Hering0b2febf2009-05-04 11:06:37 -0700579 pref = (skb_array[x]->data);
580 prefetch(pref);
581 prefetch(pref + EHEA_CACHE_LINE);
582 prefetch(pref + EHEA_CACHE_LINE * 2);
583 prefetch(pref + EHEA_CACHE_LINE * 3);
584 }
585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200586 skb = skb_array[skb_index];
587 skb_array[skb_index] = NULL;
588 return skb;
589}
590
591static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
592 int arr_len, int wqe_index)
593{
594 struct sk_buff *skb;
595 void *pref;
596 int x;
597
598 x = wqe_index + 1;
599 x &= (arr_len - 1);
600
601 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700602 if (pref) {
603 prefetchw(pref);
604 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200605
Hannes Hering0b2febf2009-05-04 11:06:37 -0700606 pref = (skb_array[x]->data);
607 prefetchw(pref);
608 prefetchw(pref + EHEA_CACHE_LINE);
609 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200610
611 skb = skb_array[wqe_index];
612 skb_array[wqe_index] = NULL;
613 return skb;
614}
615
616static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
617 struct ehea_cqe *cqe, int *processed_rq2,
618 int *processed_rq3)
619{
620 struct sk_buff *skb;
621
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100622 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
623 pr->p_stats.err_tcp_cksum++;
624 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
625 pr->p_stats.err_ip_cksum++;
626 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
627 pr->p_stats.err_frame_crc++;
628
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200629 if (rq == 2) {
630 *processed_rq2 += 1;
631 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
632 dev_kfree_skb(skb);
633 } else if (rq == 3) {
634 *processed_rq3 += 1;
635 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
636 dev_kfree_skb(skb);
637 }
638
639 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100640 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800641 pr_err("Critical receive error for QP %d. Resetting port.\n",
642 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100643 ehea_dump(cqe, sizeof(*cqe), "CQE");
644 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100645 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200646 return 1;
647 }
648
649 return 0;
650}
651
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700652static int ehea_proc_rwqes(struct net_device *dev,
653 struct ehea_port_res *pr,
654 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200655{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100656 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200657 struct ehea_qp *qp = pr->qp;
658 struct ehea_cqe *cqe;
659 struct sk_buff *skb;
660 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
661 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
662 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
663 int skb_arr_rq1_len = pr->rq1_skba.len;
664 int skb_arr_rq2_len = pr->rq2_skba.len;
665 int skb_arr_rq3_len = pr->rq3_skba.len;
666 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000667 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700668 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200669
670 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
671 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200673 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700674 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200675 ehea_inc_rq1(qp);
676 processed_rq1++;
677 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200678 if (netif_msg_rx_status(port))
679 ehea_dump(cqe, sizeof(*cqe), "CQE");
680
681 last_wqe_index = wqe_index;
682 rmb();
683 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600684 if (rq == 1) {
685 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200686 skb = get_skb_by_index_ll(skb_arr_rq1,
687 skb_arr_rq1_len,
688 wqe_index);
689 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800690 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800691 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100692
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700693 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200694 EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000695 if (!skb)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696 break;
697 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600698 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200699 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000700 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600701 } else if (rq == 2) {
702 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200703 skb = get_skb_by_index(skb_arr_rq2,
704 skb_arr_rq2_len, cqe);
705 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800706 netif_err(port, rx_err, dev,
707 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 break;
709 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000710 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600712 } else {
713 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200714 skb = get_skb_by_index(skb_arr_rq3,
715 skb_arr_rq3_len, cqe);
716 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800717 netif_err(port, rx_err, dev,
718 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 break;
720 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000721 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722 processed_rq3++;
723 }
724
Breno Leitaoce45b872010-10-27 08:45:14 +0000725 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000726
727 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
David S. Millere5905c82013-04-22 19:24:19 -0400728 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
729 cqe->vlan_tag);
Anton Blanchard34284142011-10-14 05:31:11 +0000730
731 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100732 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100733 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 port_reset = ehea_treat_poll_error(pr, rq, cqe,
735 &processed_rq2,
736 &processed_rq3);
737 if (port_reset)
738 break;
739 }
740 cqe = ehea_poll_rq1(qp, &wqe_index);
741 }
742
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200743 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000744 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745
746 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
747 ehea_refill_rq2(pr, processed_rq2);
748 ehea_refill_rq3(pr, processed_rq3);
749
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700750 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751}
752
Andre Detsch2928db42010-08-17 05:49:12 +0000753#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
754
755static void reset_sq_restart_flag(struct ehea_port *port)
756{
757 int i;
758
Anton Blanchard723f28e2011-10-14 05:31:01 +0000759 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000760 struct ehea_port_res *pr = &port->port_res[i];
761 pr->sq_restart_flag = 0;
762 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000763 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000764}
765
766static void check_sqs(struct ehea_port *port)
767{
768 struct ehea_swqe *swqe;
769 int swqe_index;
770 int i, k;
771
Anton Blanchard723f28e2011-10-14 05:31:01 +0000772 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000773 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000774 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000775 k = 0;
776 swqe = ehea_get_swqe(pr->qp, &swqe_index);
777 memset(swqe, 0, SWQE_HEADER_SIZE);
778 atomic_dec(&pr->swqe_avail);
779
780 swqe->tx_control |= EHEA_SWQE_PURGE;
781 swqe->wr_id = SWQE_RESTART_CHECK;
782 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
783 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
784 swqe->immediate_data_length = 80;
785
786 ehea_post_swqe(pr->qp, swqe);
787
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000788 ret = wait_event_timeout(port->restart_wq,
789 pr->sq_restart_flag == 0,
790 msecs_to_jiffies(100));
791
792 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800793 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000794 ehea_schedule_port_reset(pr->port);
795 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000796 }
797 }
Andre Detsch2928db42010-08-17 05:49:12 +0000798}
799
800
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100801static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200802{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100803 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200804 struct ehea_cq *send_cq = pr->send_cq;
805 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100806 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200807 int cqe_counter = 0;
808 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100809 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000810 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
811 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200812
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600814 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100815 ehea_inc_cq(send_cq);
816
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200817 cqe_counter++;
818 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000819
820 if (cqe->wr_id == SWQE_RESTART_CHECK) {
821 pr->sq_restart_flag = 1;
822 swqe_av++;
823 break;
824 }
825
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200826 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800827 pr_err("Bad send completion status=0x%04X\n",
828 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000829
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 if (netif_msg_tx_err(pr->port))
831 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000832
833 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800834 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000835 ehea_schedule_port_reset(pr->port);
836 break;
837 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200838 }
839
840 if (netif_msg_tx_done(pr->port))
841 ehea_dump(cqe, sizeof(*cqe), "CQE");
842
843 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100844 == EHEA_SWQE2_TYPE)) {
845
846 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
847 skb = pr->sq_skba.arr[index];
848 dev_kfree_skb(skb);
849 pr->sq_skba.arr[index] = NULL;
850 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200851
852 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
853 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100854
855 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700856 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857
858 ehea_update_feca(send_cq, cqe_counter);
859 atomic_add(swqe_av, &pr->swqe_avail);
860
Anton Blanchardb9564462011-10-14 05:30:59 +0000861 if (unlikely(netif_tx_queue_stopped(txq) &&
862 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
863 __netif_tx_lock(txq, smp_processor_id());
864 if (netif_tx_queue_stopped(txq) &&
865 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
866 netif_tx_wake_queue(txq);
867 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000869
Breno Leitao5b27d422010-10-05 13:16:22 +0000870 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200871
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100872 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200873}
874
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700875#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100876
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700877static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200878{
Doug Maxey508d2b52008-01-31 20:20:49 -0600879 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
880 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700881 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100882 struct ehea_cqe *cqe;
883 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000884 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700885 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100886
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700887 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000888 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100889
Anton Blanchard222ca962011-10-14 05:31:00 +0000890 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800891 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100892 ehea_reset_cq_ep(pr->recv_cq);
893 ehea_reset_cq_ep(pr->send_cq);
894 ehea_reset_cq_n1(pr->recv_cq);
895 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000896 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100897 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
898 cqe_skb = ehea_poll_cq(pr->send_cq);
899
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100900 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700901 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100902
Ben Hutchings288379f2009-01-19 16:43:59 -0800903 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700904 return rx;
905
906 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
907 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100909
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700910 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911}
912
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200913#ifdef CONFIG_NET_POLL_CONTROLLER
914static void ehea_netpoll(struct net_device *dev)
915{
916 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700917 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200918
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700919 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800920 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200921}
922#endif
923
David Howells7d12e782006-10-05 14:55:46 +0100924static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200925{
926 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100927
Ben Hutchings288379f2009-01-19 16:43:59 -0800928 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930 return IRQ_HANDLED;
931}
932
David Howells7d12e782006-10-05 14:55:46 +0100933static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200934{
935 struct ehea_port *port = param;
936 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100937 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200938 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000939 u64 resource_type, aer, aerr;
940 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200941
942 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100943
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200944 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200945 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800946 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
947 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100948
949 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000950
951 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
952 &aer, &aerr);
953
954 if (resource_type == EHEA_AER_RESTYPE_QP) {
955 if ((aer & EHEA_AER_RESET_MASK) ||
956 (aerr & EHEA_AERR_RESET_MASK))
957 reset_port = 1;
958 } else
959 reset_port = 1; /* Reset in case of CQ or EQ error */
960
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100961 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200962 }
963
Thomas Kleinea96cea2010-04-20 23:10:55 +0000964 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800965 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000966 ehea_schedule_port_reset(port);
967 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100968
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200969 return IRQ_HANDLED;
970}
971
972static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
973 int logical_port)
974{
975 int i;
976
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100977 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100978 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200979 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100980 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200981 return NULL;
982}
983
984int ehea_sense_port_attr(struct ehea_port *port)
985{
986 int ret;
987 u64 hret;
988 struct hcp_ehea_port_cb0 *cb0;
989
Doug Maxey508d2b52008-01-31 20:20:49 -0600990 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800991 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600992 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800993 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200994 ret = -ENOMEM;
995 goto out;
996 }
997
998 hret = ehea_h_query_ehea_port(port->adapter->handle,
999 port->logical_port_id, H_PORT_CB0,
1000 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1001 cb0);
1002 if (hret != H_SUCCESS) {
1003 ret = -EIO;
1004 goto out_free;
1005 }
1006
1007 /* MAC address */
1008 port->mac_addr = cb0->port_mac_addr << 16;
1009
Doug Maxey508d2b52008-01-31 20:20:49 -06001010 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001011 ret = -EADDRNOTAVAIL;
1012 goto out_free;
1013 }
1014
1015 /* Port speed */
1016 switch (cb0->port_speed) {
1017 case H_SPEED_10M_H:
1018 port->port_speed = EHEA_SPEED_10M;
1019 port->full_duplex = 0;
1020 break;
1021 case H_SPEED_10M_F:
1022 port->port_speed = EHEA_SPEED_10M;
1023 port->full_duplex = 1;
1024 break;
1025 case H_SPEED_100M_H:
1026 port->port_speed = EHEA_SPEED_100M;
1027 port->full_duplex = 0;
1028 break;
1029 case H_SPEED_100M_F:
1030 port->port_speed = EHEA_SPEED_100M;
1031 port->full_duplex = 1;
1032 break;
1033 case H_SPEED_1G_F:
1034 port->port_speed = EHEA_SPEED_1G;
1035 port->full_duplex = 1;
1036 break;
1037 case H_SPEED_10G_F:
1038 port->port_speed = EHEA_SPEED_10G;
1039 port->full_duplex = 1;
1040 break;
1041 default:
1042 port->port_speed = 0;
1043 port->full_duplex = 0;
1044 break;
1045 }
1046
Thomas Kleine919b592007-01-22 12:53:20 +01001047 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001048 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001049
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001050 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001051 if (use_mcs)
1052 port->num_def_qps = cb0->num_default_qps;
1053 else
1054 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001055
1056 if (!port->num_def_qps) {
1057 ret = -EINVAL;
1058 goto out_free;
1059 }
1060
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001061 ret = 0;
1062out_free:
1063 if (ret || netif_msg_probe(port))
1064 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001065 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001066out:
1067 return ret;
1068}
1069
1070int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1071{
1072 struct hcp_ehea_port_cb4 *cb4;
1073 u64 hret;
1074 int ret = 0;
1075
Thomas Klein3faf2692009-01-21 14:45:33 -08001076 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001077 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001078 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001079 ret = -ENOMEM;
1080 goto out;
1081 }
1082
1083 cb4->port_speed = port_speed;
1084
1085 netif_carrier_off(port->netdev);
1086
1087 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1088 port->logical_port_id,
1089 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1090 if (hret == H_SUCCESS) {
1091 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1092
1093 hret = ehea_h_query_ehea_port(port->adapter->handle,
1094 port->logical_port_id,
1095 H_PORT_CB4, H_PORT_CB4_SPEED,
1096 cb4);
1097 if (hret == H_SUCCESS) {
1098 switch (cb4->port_speed) {
1099 case H_SPEED_10M_H:
1100 port->port_speed = EHEA_SPEED_10M;
1101 port->full_duplex = 0;
1102 break;
1103 case H_SPEED_10M_F:
1104 port->port_speed = EHEA_SPEED_10M;
1105 port->full_duplex = 1;
1106 break;
1107 case H_SPEED_100M_H:
1108 port->port_speed = EHEA_SPEED_100M;
1109 port->full_duplex = 0;
1110 break;
1111 case H_SPEED_100M_F:
1112 port->port_speed = EHEA_SPEED_100M;
1113 port->full_duplex = 1;
1114 break;
1115 case H_SPEED_1G_F:
1116 port->port_speed = EHEA_SPEED_1G;
1117 port->full_duplex = 1;
1118 break;
1119 case H_SPEED_10G_F:
1120 port->port_speed = EHEA_SPEED_10G;
1121 port->full_duplex = 1;
1122 break;
1123 default:
1124 port->port_speed = 0;
1125 port->full_duplex = 0;
1126 break;
1127 }
1128 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001129 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001130 ret = -EIO;
1131 }
1132 } else {
1133 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001134 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001135 ret = -EPERM;
1136 } else {
1137 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001138 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 }
1140 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001141 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1142 netif_carrier_on(port->netdev);
1143
Thomas Klein3faf2692009-01-21 14:45:33 -08001144 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001145out:
1146 return ret;
1147}
1148
1149static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1150{
1151 int ret;
1152 u8 ec;
1153 u8 portnum;
1154 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001155 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001156
1157 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1158 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1159 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001160 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001161
1162 switch (ec) {
1163 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1164
1165 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001166 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001167 break;
1168 }
1169
1170 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001171 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001172 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001173 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001174 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001175 break;
1176 }
1177
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 netif_info(port, link, dev,
1179 "Logical port up: %dMbps %s Duplex\n",
1180 port->port_speed,
1181 port->full_duplex == 1 ?
1182 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001183
Joe Perches8c4877a2010-12-13 10:05:14 -08001184 netif_carrier_on(dev);
1185 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001186 }
1187 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 if (netif_carrier_ok(dev)) {
1189 netif_info(port, link, dev,
1190 "Logical port down\n");
1191 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001192 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001193 }
1194
1195 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001196 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001197 netif_info(port, link, dev,
1198 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001199 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001200 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001201 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001202 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001203 netif_info(port, link, dev,
1204 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001205 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001206 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207 }
1208
1209 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001210 netdev_info(dev,
1211 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001212 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001213 netdev_info(dev,
1214 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001215
1216 break;
1217 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001218 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001219 break;
1220 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001221 netdev_info(dev, "Port malfunction\n");
1222 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001223 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224 break;
1225 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001226 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227 break;
1228 }
1229}
1230
1231static void ehea_neq_tasklet(unsigned long data)
1232{
Doug Maxey508d2b52008-01-31 20:20:49 -06001233 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 struct ehea_eqe *eqe;
1235 u64 event_mask;
1236
1237 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001238 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239
1240 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001241 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001242 ehea_parse_eqe(adapter, eqe->entry);
1243 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001244 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245 }
1246
1247 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1248 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1249 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1250
1251 ehea_h_reset_events(adapter->handle,
1252 adapter->neq->fw_handle, event_mask);
1253}
1254
David Howells7d12e782006-10-05 14:55:46 +01001255static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256{
1257 struct ehea_adapter *adapter = param;
1258 tasklet_hi_schedule(&adapter->neq_tasklet);
1259 return IRQ_HANDLED;
1260}
1261
1262
1263static int ehea_fill_port_res(struct ehea_port_res *pr)
1264{
1265 int ret;
1266 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1267
Breno Leitaof76957f2011-01-11 07:45:57 +00001268 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269
Thomas Kleine2878802009-01-21 14:45:57 -08001270 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271
1272 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1273
1274 return ret;
1275}
1276
1277static int ehea_reg_interrupts(struct net_device *dev)
1278{
1279 struct ehea_port *port = netdev_priv(dev);
1280 struct ehea_port_res *pr;
1281 int i, ret;
1282
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283
1284 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1285 dev->name);
1286
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001287 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001289 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001291 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1292 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293 goto out_free_qpeq;
1294 }
1295
Joe Perches8c4877a2010-12-13 10:05:14 -08001296 netif_info(port, ifup, dev,
1297 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1298 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001300
Anton Blanchard723f28e2011-10-14 05:31:01 +00001301 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001302 pr = &port->port_res[i];
1303 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001305 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001306 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001307 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001308 pr);
1309 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001310 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1311 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001312 goto out_free_req;
1313 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001314 netif_info(port, ifup, dev,
1315 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1316 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001317 }
1318out:
1319 return ret;
1320
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001322out_free_req:
1323 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001324 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001325 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001329 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001333
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334}
1335
1336static void ehea_free_interrupts(struct net_device *dev)
1337{
1338 struct ehea_port *port = netdev_priv(dev);
1339 struct ehea_port_res *pr;
1340 int i;
1341
1342 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001343
Anton Blanchard723f28e2011-10-14 05:31:01 +00001344 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001346 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001347 netif_info(port, intr, dev,
1348 "free send irq for res %d with handle 0x%X\n",
1349 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 }
1351
1352 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001353 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001354 netif_info(port, intr, dev,
1355 "associated event interrupt for handle 0x%X freed\n",
1356 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357}
1358
1359static int ehea_configure_port(struct ehea_port *port)
1360{
1361 int ret, i;
1362 u64 hret, mask;
1363 struct hcp_ehea_port_cb0 *cb0;
1364
1365 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001366 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367 if (!cb0)
1368 goto out;
1369
1370 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1371 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1372 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1374 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1375 PXLY_RC_VLAN_FILTER)
1376 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1377
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378 for (i = 0; i < port->num_mcs; i++)
1379 if (use_mcs)
1380 cb0->default_qpn_arr[i] =
1381 port->port_res[i].qp->init_attr.qp_nr;
1382 else
1383 cb0->default_qpn_arr[i] =
1384 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386 if (netif_msg_ifup(port))
1387 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1388
1389 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1390 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1391
1392 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1393 port->logical_port_id,
1394 H_PORT_CB0, mask, cb0);
1395 ret = -EIO;
1396 if (hret != H_SUCCESS)
1397 goto out_free;
1398
1399 ret = 0;
1400
1401out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001402 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001403out:
1404 return ret;
1405}
1406
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001407static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001408{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001409 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410 struct ehea_adapter *adapter = pr->port->adapter;
1411
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001412 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1413 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 goto out;
1415
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001416 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1417 if (ret)
1418 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419
1420 return 0;
1421
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001422out_free:
1423 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001425 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001426 return -EIO;
1427}
1428
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001429static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001430{
Joe Perches8e95a202009-12-03 07:58:21 +00001431 if ((ehea_rem_mr(&pr->send_mr)) ||
1432 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001433 return -EIO;
1434 else
1435 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001436}
1437
1438static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1439{
Doug Maxey508d2b52008-01-31 20:20:49 -06001440 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001441
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001442 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443 if (!q_skba->arr)
1444 return -ENOMEM;
1445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001446 q_skba->len = max_q_entries;
1447 q_skba->index = 0;
1448 q_skba->os_skbs = 0;
1449
1450 return 0;
1451}
1452
1453static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1454 struct port_res_cfg *pr_cfg, int queue_token)
1455{
1456 struct ehea_adapter *adapter = port->adapter;
1457 enum ehea_eq_type eq_type = EHEA_EQ;
1458 struct ehea_qp_init_attr *init_attr = NULL;
1459 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001460 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1461
1462 tx_bytes = pr->tx_bytes;
1463 tx_packets = pr->tx_packets;
1464 rx_bytes = pr->rx_bytes;
1465 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001466
1467 memset(pr, 0, sizeof(struct ehea_port_res));
1468
Breno Leitaoce45b872010-10-27 08:45:14 +00001469 pr->tx_bytes = rx_bytes;
1470 pr->tx_packets = tx_packets;
1471 pr->rx_bytes = rx_bytes;
1472 pr->rx_packets = rx_packets;
1473
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001476 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1477 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001478 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479 goto out_free;
1480 }
1481
1482 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001483 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484 port->logical_port_id);
1485 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001486 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487 goto out_free;
1488 }
1489
1490 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001491 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 port->logical_port_id);
1493 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001494 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495 goto out_free;
1496 }
1497
1498 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001499 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1500 pr->send_cq->attr.act_nr_of_cqes,
1501 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502
1503 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1504 if (!init_attr) {
1505 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001506 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507 goto out_free;
1508 }
1509
1510 init_attr->low_lat_rq1 = 1;
1511 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1512 init_attr->rq_count = 3;
1513 init_attr->qp_token = queue_token;
1514 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1515 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1516 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1517 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1518 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1519 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1520 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1521 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1522 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1523 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1524 init_attr->port_nr = port->logical_port_id;
1525 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1526 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1527 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1528
1529 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1530 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001531 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532 ret = -EIO;
1533 goto out_free;
1534 }
1535
1536 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001537 pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n",
1538 init_attr->qp_nr,
1539 init_attr->act_nr_send_wqes,
1540 init_attr->act_nr_rwqes_rq1,
1541 init_attr->act_nr_rwqes_rq2,
1542 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543
Thomas Klein44fb3122008-04-04 15:04:53 +02001544 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1545
1546 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1548 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1549 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1550 if (ret)
1551 goto out_free;
1552
1553 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1554 if (ehea_gen_smrs(pr) != 0) {
1555 ret = -EIO;
1556 goto out_free;
1557 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001558
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001559 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1560
1561 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001563 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001564
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001565 ret = 0;
1566 goto out;
1567
1568out_free:
1569 kfree(init_attr);
1570 vfree(pr->sq_skba.arr);
1571 vfree(pr->rq1_skba.arr);
1572 vfree(pr->rq2_skba.arr);
1573 vfree(pr->rq3_skba.arr);
1574 ehea_destroy_qp(pr->qp);
1575 ehea_destroy_cq(pr->send_cq);
1576 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001577 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001578out:
1579 return ret;
1580}
1581
1582static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1583{
1584 int ret, i;
1585
Hannes Hering357eb462009-08-04 11:48:39 -07001586 if (pr->qp)
1587 netif_napi_del(&pr->napi);
1588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001589 ret = ehea_destroy_qp(pr->qp);
1590
1591 if (!ret) {
1592 ehea_destroy_cq(pr->send_cq);
1593 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001594 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001595
1596 for (i = 0; i < pr->rq1_skba.len; i++)
1597 if (pr->rq1_skba.arr[i])
1598 dev_kfree_skb(pr->rq1_skba.arr[i]);
1599
1600 for (i = 0; i < pr->rq2_skba.len; i++)
1601 if (pr->rq2_skba.arr[i])
1602 dev_kfree_skb(pr->rq2_skba.arr[i]);
1603
1604 for (i = 0; i < pr->rq3_skba.len; i++)
1605 if (pr->rq3_skba.arr[i])
1606 dev_kfree_skb(pr->rq3_skba.arr[i]);
1607
1608 for (i = 0; i < pr->sq_skba.len; i++)
1609 if (pr->sq_skba.arr[i])
1610 dev_kfree_skb(pr->sq_skba.arr[i]);
1611
1612 vfree(pr->rq1_skba.arr);
1613 vfree(pr->rq2_skba.arr);
1614 vfree(pr->rq3_skba.arr);
1615 vfree(pr->sq_skba.arr);
1616 ret = ehea_rem_smrs(pr);
1617 }
1618 return ret;
1619}
1620
Anton Blanchard13946f52011-10-14 05:31:06 +00001621static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1622 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001623{
Eric Dumazete743d312010-04-14 15:59:40 -07001624 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1626 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001627 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001628
Anton Blanchard13946f52011-10-14 05:31:06 +00001629 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630
Anton Blanchard13946f52011-10-14 05:31:06 +00001631 if (skb_is_gso(skb)) {
1632 swqe->tx_control |= EHEA_SWQE_TSO;
1633 swqe->mss = skb_shinfo(skb)->gso_size;
1634 /*
1635 * For TSO packets we only copy the headers into the
1636 * immediate area.
1637 */
1638 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1639 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001640
Anton Blanchard13946f52011-10-14 05:31:06 +00001641 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1642 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1643 swqe->immediate_data_length = immediate_len;
1644
1645 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001646 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001647 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001648 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001649 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650 swqe->descriptors++;
1651 }
1652 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001653 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 swqe->immediate_data_length = skb_data_size;
1655 }
1656}
1657
1658static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1659 struct ehea_swqe *swqe, u32 lkey)
1660{
1661 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1662 skb_frag_t *frag;
1663 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664
1665 nfrags = skb_shinfo(skb)->nr_frags;
1666 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001667 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001668 sg1entry_contains_frag_data = 0;
1669
Anton Blanchard13946f52011-10-14 05:31:06 +00001670 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001671
1672 /* write descriptors */
1673 if (nfrags > 0) {
1674 if (swqe->descriptors == 0) {
1675 /* sg1entry not yet used */
1676 frag = &skb_shinfo(skb)->frags[0];
1677
1678 /* copy sg1entry data */
1679 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001680 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001681 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001682 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001683 swqe->descriptors++;
1684 sg1entry_contains_frag_data = 1;
1685 }
1686
1687 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1688
1689 frag = &skb_shinfo(skb)->frags[i];
1690 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1691
1692 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001693 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001694 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001695 swqe->descriptors++;
1696 }
1697 }
1698}
1699
1700static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1701{
1702 int ret = 0;
1703 u64 hret;
1704 u8 reg_type;
1705
1706 /* De/Register untagged packets */
1707 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1708 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1709 port->logical_port_id,
1710 reg_type, port->mac_addr, 0, hcallid);
1711 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001712 pr_err("%sregistering bc address failed (tagged)\n",
1713 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001714 ret = -EIO;
1715 goto out_herr;
1716 }
1717
1718 /* De/Register VLAN packets */
1719 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1720 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1721 port->logical_port_id,
1722 reg_type, port->mac_addr, 0, hcallid);
1723 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001724 pr_err("%sregistering bc address failed (vlan)\n",
1725 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 ret = -EIO;
1727 }
1728out_herr:
1729 return ret;
1730}
1731
1732static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1733{
1734 struct ehea_port *port = netdev_priv(dev);
1735 struct sockaddr *mac_addr = sa;
1736 struct hcp_ehea_port_cb0 *cb0;
1737 int ret;
1738 u64 hret;
1739
1740 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1741 ret = -EADDRNOTAVAIL;
1742 goto out;
1743 }
1744
Thomas Klein3faf2692009-01-21 14:45:33 -08001745 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001747 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001748 ret = -ENOMEM;
1749 goto out;
1750 }
1751
1752 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1753
1754 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1755
1756 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1757 port->logical_port_id, H_PORT_CB0,
1758 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1759 if (hret != H_SUCCESS) {
1760 ret = -EIO;
1761 goto out_free;
1762 }
1763
1764 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1765
1766 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001767 if (port->state == EHEA_PORT_UP) {
1768 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1769 if (ret)
1770 goto out_upregs;
1771 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001772
1773 port->mac_addr = cb0->port_mac_addr << 16;
1774
1775 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001776 if (port->state == EHEA_PORT_UP) {
1777 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1778 if (ret)
1779 goto out_upregs;
1780 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781
1782 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001783
1784out_upregs:
1785 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001786out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001787 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788out:
1789 return ret;
1790}
1791
1792static void ehea_promiscuous_error(u64 hret, int enable)
1793{
Thomas Klein7674a582007-01-22 12:54:20 +01001794 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001795 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1796 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001797 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001798 pr_err("failed %sabling promiscuous mode\n",
1799 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001800}
1801
1802static void ehea_promiscuous(struct net_device *dev, int enable)
1803{
1804 struct ehea_port *port = netdev_priv(dev);
1805 struct hcp_ehea_port_cb7 *cb7;
1806 u64 hret;
1807
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001808 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001809 return;
1810
Thomas Klein3faf2692009-01-21 14:45:33 -08001811 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001812 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001813 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001814 goto out;
1815 }
1816
1817 /* Modify Pxs_DUCQPN in CB7 */
1818 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1819
1820 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1821 port->logical_port_id,
1822 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1823 if (hret) {
1824 ehea_promiscuous_error(hret, enable);
1825 goto out;
1826 }
1827
1828 port->promisc = enable;
1829out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001830 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001831}
1832
1833static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1834 u32 hcallid)
1835{
1836 u64 hret;
1837 u8 reg_type;
1838
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001839 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1840 if (mc_mac_addr == 0)
1841 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001842
1843 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1844 port->logical_port_id,
1845 reg_type, mc_mac_addr, 0, hcallid);
1846 if (hret)
1847 goto out;
1848
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001849 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1850 if (mc_mac_addr == 0)
1851 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001852
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, mc_mac_addr, 0, hcallid);
1856out:
1857 return hret;
1858}
1859
1860static int ehea_drop_multicast_list(struct net_device *dev)
1861{
1862 struct ehea_port *port = netdev_priv(dev);
1863 struct ehea_mc_list *mc_entry = port->mc_list;
1864 struct list_head *pos;
1865 struct list_head *temp;
1866 int ret = 0;
1867 u64 hret;
1868
1869 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1870 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1871
1872 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1873 H_DEREG_BCMC);
1874 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001875 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001876 ret = -EIO;
1877 }
1878
1879 list_del(pos);
1880 kfree(mc_entry);
1881 }
1882 return ret;
1883}
1884
1885static void ehea_allmulti(struct net_device *dev, int enable)
1886{
1887 struct ehea_port *port = netdev_priv(dev);
1888 u64 hret;
1889
1890 if (!port->allmulti) {
1891 if (enable) {
1892 /* Enable ALLMULTI */
1893 ehea_drop_multicast_list(dev);
1894 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1895 if (!hret)
1896 port->allmulti = 1;
1897 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001898 netdev_err(dev,
1899 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001900 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001901 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001902 if (!enable) {
1903 /* Disable ALLMULTI */
1904 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1905 if (!hret)
1906 port->allmulti = 0;
1907 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001908 netdev_err(dev,
1909 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001910 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001911 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001912}
1913
Doug Maxey508d2b52008-01-31 20:20:49 -06001914static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001915{
1916 struct ehea_mc_list *ehea_mcl_entry;
1917 u64 hret;
1918
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001919 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001920 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001922
1923 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1924
1925 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1926
1927 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1928 H_REG_BCMC);
1929 if (!hret)
1930 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1931 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001932 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001933 kfree(ehea_mcl_entry);
1934 }
1935}
1936
1937static void ehea_set_multicast_list(struct net_device *dev)
1938{
1939 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001940 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001941 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001943 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001944
1945 if (dev->flags & IFF_ALLMULTI) {
1946 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001947 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948 }
1949 ehea_allmulti(dev, 0);
1950
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001951 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001952 ret = ehea_drop_multicast_list(dev);
1953 if (ret) {
1954 /* Dropping the current multicast list failed.
1955 * Enabling ALL_MULTI is the best we can do.
1956 */
1957 ehea_allmulti(dev, 1);
1958 }
1959
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001960 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001961 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1962 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001963 goto out;
1964 }
1965
Jiri Pirko22bedad32010-04-01 21:22:57 +00001966 netdev_for_each_mc_addr(ha, dev)
1967 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001968
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001969 }
1970out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001971 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001972}
1973
1974static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1975{
1976 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1977 return -EINVAL;
1978 dev->mtu = new_mtu;
1979 return 0;
1980}
1981
Anton Blanchardd695c332011-10-14 05:31:05 +00001982static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1983{
1984 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1985
1986 if (skb->protocol != htons(ETH_P_IP))
1987 return;
1988
1989 if (skb->ip_summed == CHECKSUM_PARTIAL)
1990 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1991
1992 swqe->ip_start = skb_network_offset(skb);
1993 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1994
1995 switch (ip_hdr(skb)->protocol) {
1996 case IPPROTO_UDP:
1997 if (skb->ip_summed == CHECKSUM_PARTIAL)
1998 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
1999
2000 swqe->tcp_offset = swqe->ip_end + 1 +
2001 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002002 break;
2003
2004 case IPPROTO_TCP:
2005 if (skb->ip_summed == CHECKSUM_PARTIAL)
2006 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2007
2008 swqe->tcp_offset = swqe->ip_end + 1 +
2009 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002010 break;
2011 }
2012}
2013
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002014static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2015 struct ehea_swqe *swqe, u32 lkey)
2016{
Anton Blanchardd695c332011-10-14 05:31:05 +00002017 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002018
Anton Blanchardd695c332011-10-14 05:31:05 +00002019 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002020
2021 write_swqe2_data(skb, dev, swqe, lkey);
2022}
2023
2024static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2025 struct ehea_swqe *swqe)
2026{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002027 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002028
Anton Blanchardd695c332011-10-14 05:31:05 +00002029 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002030
Anton Blanchard30e2e902011-10-14 05:31:07 +00002031 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002032 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002033 else
2034 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002035
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002036 swqe->immediate_data_length = skb->len;
2037 dev_kfree_skb(skb);
2038}
2039
2040static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2041{
2042 struct ehea_port *port = netdev_priv(dev);
2043 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002044 u32 lkey;
2045 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002046 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002047 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002048
Anton Blanchardb9564462011-10-14 05:30:59 +00002049 pr = &port->port_res[skb_get_queue_mapping(skb)];
2050 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002051
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2053 memset(swqe, 0, SWQE_HEADER_SIZE);
2054 atomic_dec(&pr->swqe_avail);
2055
Eric Dumazete5ccd962010-10-26 19:21:07 +00002056 if (vlan_tx_tag_present(skb)) {
2057 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2058 swqe->vlan_tag = vlan_tx_tag_get(skb);
2059 }
2060
Breno Leitaoce45b872010-10-27 08:45:14 +00002061 pr->tx_packets++;
2062 pr->tx_bytes += skb->len;
2063
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002064 if (skb->len <= SWQE3_MAX_IMM) {
2065 u32 sig_iv = port->sig_comp_iv;
2066 u32 swqe_num = pr->swqe_id_counter;
2067 ehea_xmit3(skb, dev, swqe);
2068 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2069 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2070 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2071 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2072 sig_iv);
2073 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2074 pr->swqe_ll_count = 0;
2075 } else
2076 pr->swqe_ll_count += 1;
2077 } else {
2078 swqe->wr_id =
2079 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2080 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002081 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002082 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2083 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2084
2085 pr->sq_skba.index++;
2086 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2087
2088 lkey = pr->send_mr.lkey;
2089 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002090 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002091 }
2092 pr->swqe_id_counter += 1;
2093
Joe Perches8c4877a2010-12-13 10:05:14 -08002094 netif_info(port, tx_queued, dev,
2095 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2096 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002097 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002098
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002099 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002100 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002101 swqe->tx_control |= EHEA_SWQE_PURGE;
2102 }
Thomas Klein44c82152007-07-11 16:32:00 +02002103
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002104 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002105
2106 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002107 pr->p_stats.queue_stopped++;
2108 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002110
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 return NETDEV_TX_OK;
2112}
2113
Patrick McHardy80d5c362013-04-19 02:04:28 +00002114static int ehea_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115{
2116 struct ehea_port *port = netdev_priv(dev);
2117 struct ehea_adapter *adapter = port->adapter;
2118 struct hcp_ehea_port_cb1 *cb1;
2119 int index;
2120 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002121 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002122
Thomas Klein3faf2692009-01-21 14:45:33 -08002123 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002124 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002125 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002126 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127 goto out;
2128 }
2129
2130 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2131 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2132 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002133 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002134 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002135 goto out;
2136 }
2137
2138 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002139 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002140
2141 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2142 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002143 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002144 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002145 err = -EINVAL;
2146 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002147out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002148 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002149 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002150}
2151
Patrick McHardy80d5c362013-04-19 02:04:28 +00002152static int ehea_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153{
2154 struct ehea_port *port = netdev_priv(dev);
2155 struct ehea_adapter *adapter = port->adapter;
2156 struct hcp_ehea_port_cb1 *cb1;
2157 int index;
2158 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002159 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002160
Thomas Klein3faf2692009-01-21 14:45:33 -08002161 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002162 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002163 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002164 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002165 goto out;
2166 }
2167
2168 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2169 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2170 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002171 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002172 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002173 goto out;
2174 }
2175
2176 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002177 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002178
2179 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2180 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002181 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002182 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002183 err = -EINVAL;
2184 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002185out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002186 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002187 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002188}
2189
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002190static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002191{
2192 int ret = -EIO;
2193 u64 hret;
2194 u16 dummy16 = 0;
2195 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002196 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002197
Thomas Klein3faf2692009-01-21 14:45:33 -08002198 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002199 if (!cb0) {
2200 ret = -ENOMEM;
2201 goto out;
2202 }
2203
2204 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2205 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2206 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002207 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208 goto out;
2209 }
2210
2211 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2212 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2213 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2214 &dummy64, &dummy64, &dummy16, &dummy16);
2215 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002216 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002217 goto out;
2218 }
2219
2220 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2221 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2222 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002223 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002224 goto out;
2225 }
2226
2227 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2228 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2229 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2230 &dummy64, &dummy64, &dummy16, &dummy16);
2231 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002232 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002233 goto out;
2234 }
2235
2236 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2237 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2238 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002239 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002240 goto out;
2241 }
2242
2243 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2244 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2245 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2246 &dummy64, &dummy64, &dummy16, &dummy16);
2247 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002248 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002249 goto out;
2250 }
2251
2252 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2253 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2254 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002255 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002256 goto out;
2257 }
2258
2259 ret = 0;
2260out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002261 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002262 return ret;
2263}
2264
Anton Blanchard723f28e2011-10-14 05:31:01 +00002265static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002266{
2267 int ret, i;
2268 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2269 enum ehea_eq_type eq_type = EHEA_EQ;
2270
2271 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2272 EHEA_MAX_ENTRIES_EQ, 1);
2273 if (!port->qp_eq) {
2274 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002275 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002276 goto out_kill_eq;
2277 }
2278
2279 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002280 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002281 pr_cfg.max_entries_sq = sq_entries;
2282 pr_cfg.max_entries_rq1 = rq1_entries;
2283 pr_cfg.max_entries_rq2 = rq2_entries;
2284 pr_cfg.max_entries_rq3 = rq3_entries;
2285
2286 pr_cfg_small_rx.max_entries_rcq = 1;
2287 pr_cfg_small_rx.max_entries_scq = sq_entries;
2288 pr_cfg_small_rx.max_entries_sq = sq_entries;
2289 pr_cfg_small_rx.max_entries_rq1 = 1;
2290 pr_cfg_small_rx.max_entries_rq2 = 1;
2291 pr_cfg_small_rx.max_entries_rq3 = 1;
2292
2293 for (i = 0; i < def_qps; i++) {
2294 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2295 if (ret)
2296 goto out_clean_pr;
2297 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002298 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299 ret = ehea_init_port_res(port, &port->port_res[i],
2300 &pr_cfg_small_rx, i);
2301 if (ret)
2302 goto out_clean_pr;
2303 }
2304
2305 return 0;
2306
2307out_clean_pr:
2308 while (--i >= 0)
2309 ehea_clean_portres(port, &port->port_res[i]);
2310
2311out_kill_eq:
2312 ehea_destroy_eq(port->qp_eq);
2313 return ret;
2314}
2315
2316static int ehea_clean_all_portres(struct ehea_port *port)
2317{
2318 int ret = 0;
2319 int i;
2320
Anton Blanchard723f28e2011-10-14 05:31:01 +00002321 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002322 ret |= ehea_clean_portres(port, &port->port_res[i]);
2323
2324 ret |= ehea_destroy_eq(port->qp_eq);
2325
2326 return ret;
2327}
2328
Thomas Klein35cf2e22007-08-06 13:55:14 +02002329static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002330{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002331 if (adapter->active_ports)
2332 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002333
2334 ehea_rem_mr(&adapter->mr);
2335}
2336
Thomas Klein35cf2e22007-08-06 13:55:14 +02002337static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002338{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002339 if (adapter->active_ports)
2340 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002341
2342 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2343}
2344
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002345static int ehea_up(struct net_device *dev)
2346{
2347 int ret, i;
2348 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002349
2350 if (port->state == EHEA_PORT_UP)
2351 return 0;
2352
Anton Blanchard723f28e2011-10-14 05:31:01 +00002353 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002355 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 goto out;
2357 }
2358
2359 /* Set default QP for this port */
2360 ret = ehea_configure_port(port);
2361 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002362 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002363 goto out_clean_pr;
2364 }
2365
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002366 ret = ehea_reg_interrupts(dev);
2367 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002368 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002369 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002370 }
2371
Anton Blanchard723f28e2011-10-14 05:31:01 +00002372 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002373 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2374 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002375 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002376 goto out_free_irqs;
2377 }
2378 }
2379
Doug Maxey508d2b52008-01-31 20:20:49 -06002380 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002381 ret = ehea_fill_port_res(&port->port_res[i]);
2382 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002383 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002384 goto out_free_irqs;
2385 }
2386 }
2387
Thomas Klein21eee2d2008-02-13 16:18:33 +01002388 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2389 if (ret) {
2390 ret = -EIO;
2391 goto out_free_irqs;
2392 }
2393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002394 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002395
2396 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397 goto out;
2398
2399out_free_irqs:
2400 ehea_free_interrupts(dev);
2401
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002402out_clean_pr:
2403 ehea_clean_all_portres(port);
2404out:
Thomas Klein44c82152007-07-11 16:32:00 +02002405 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002406 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002407
Thomas Klein21eee2d2008-02-13 16:18:33 +01002408 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002409 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002410
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002411 return ret;
2412}
2413
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002414static void port_napi_disable(struct ehea_port *port)
2415{
2416 int i;
2417
Anton Blanchard723f28e2011-10-14 05:31:01 +00002418 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002419 napi_disable(&port->port_res[i].napi);
2420}
2421
2422static void port_napi_enable(struct ehea_port *port)
2423{
2424 int i;
2425
Anton Blanchard723f28e2011-10-14 05:31:01 +00002426 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002427 napi_enable(&port->port_res[i].napi);
2428}
2429
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002430static int ehea_open(struct net_device *dev)
2431{
2432 int ret;
2433 struct ehea_port *port = netdev_priv(dev);
2434
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002435 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436
Joe Perches8c4877a2010-12-13 10:05:14 -08002437 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002438
2439 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002440 if (!ret) {
2441 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002442 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002443 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002445 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002446 schedule_delayed_work(&port->stats_work,
2447 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002448
2449 return ret;
2450}
2451
2452static int ehea_down(struct net_device *dev)
2453{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002454 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455 struct ehea_port *port = netdev_priv(dev);
2456
2457 if (port->state == EHEA_PORT_DOWN)
2458 return 0;
2459
2460 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002461 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002462 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2463
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002464 ehea_free_interrupts(dev);
2465
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002466 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002467
Thomas Klein21eee2d2008-02-13 16:18:33 +01002468 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002469
Thomas Klein44c82152007-07-11 16:32:00 +02002470 ret = ehea_clean_all_portres(port);
2471 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002472 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002473
Thomas Klein21eee2d2008-02-13 16:18:33 +01002474 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002475
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002476 return ret;
2477}
2478
2479static int ehea_stop(struct net_device *dev)
2480{
2481 int ret;
2482 struct ehea_port *port = netdev_priv(dev);
2483
Joe Perches8c4877a2010-12-13 10:05:14 -08002484 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002485
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002486 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002487 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002488 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002489 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002490 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002491 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002492 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002493 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002494 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002495 return ret;
2496}
2497
Andrew Morton22559c52008-04-18 13:50:39 -07002498static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002499{
2500 struct ehea_qp qp = *orig_qp;
2501 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2502 struct ehea_swqe *swqe;
2503 int wqe_index;
2504 int i;
2505
2506 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2507 swqe = ehea_get_swqe(&qp, &wqe_index);
2508 swqe->tx_control |= EHEA_SWQE_PURGE;
2509 }
2510}
2511
Andrew Morton22559c52008-04-18 13:50:39 -07002512static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002513{
2514 int i;
2515
Anton Blanchard723f28e2011-10-14 05:31:01 +00002516 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002517 struct ehea_port_res *pr = &port->port_res[i];
2518 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002519 int ret;
2520
2521 ret = wait_event_timeout(port->swqe_avail_wq,
2522 atomic_read(&pr->swqe_avail) >= swqe_max,
2523 msecs_to_jiffies(100));
2524
2525 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002526 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002527 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002528 }
2529 }
2530}
2531
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002532static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002533{
2534 struct ehea_port *port = netdev_priv(dev);
2535 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002536 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002537 int ret = -EIO;
2538 int dret;
2539 int i;
2540 u64 hret;
2541 u64 dummy64 = 0;
2542 u16 dummy16 = 0;
2543
Thomas Klein3faf2692009-01-21 14:45:33 -08002544 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002545 if (!cb0) {
2546 ret = -ENOMEM;
2547 goto out;
2548 }
2549
Anton Blanchard723f28e2011-10-14 05:31:01 +00002550 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002551 struct ehea_port_res *pr = &port->port_res[i];
2552 struct ehea_qp *qp = pr->qp;
2553
2554 /* Purge send queue */
2555 ehea_purge_sq(qp);
2556
2557 /* Disable queue pair */
2558 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2559 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2560 cb0);
2561 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002562 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002563 goto out;
2564 }
2565
2566 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2567 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2568
2569 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2570 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2571 1), cb0, &dummy64,
2572 &dummy64, &dummy16, &dummy16);
2573 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002574 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002575 goto out;
2576 }
2577
2578 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2579 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2580 cb0);
2581 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002582 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002583 goto out;
2584 }
2585
2586 /* deregister shared memory regions */
2587 dret = ehea_rem_smrs(pr);
2588 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002589 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002590 goto out;
2591 }
2592 }
2593
2594 ret = 0;
2595out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002596 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002597
2598 return ret;
2599}
2600
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002601static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002602{
2603 struct ehea_qp qp = *orig_qp;
2604 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2605 struct ehea_rwqe *rwqe;
2606 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2607 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2608 struct sk_buff *skb;
2609 u32 lkey = pr->recv_mr.lkey;
2610
2611
2612 int i;
2613 int index;
2614
2615 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2616 rwqe = ehea_get_next_rwqe(&qp, 2);
2617 rwqe->sg_list[0].l_key = lkey;
2618 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2619 skb = skba_rq2[index];
2620 if (skb)
2621 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2622 }
2623
2624 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2625 rwqe = ehea_get_next_rwqe(&qp, 3);
2626 rwqe->sg_list[0].l_key = lkey;
2627 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2628 skb = skba_rq3[index];
2629 if (skb)
2630 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2631 }
2632}
2633
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002634static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002635{
2636 struct ehea_port *port = netdev_priv(dev);
2637 struct ehea_adapter *adapter = port->adapter;
2638 int ret = 0;
2639 int i;
2640
Doug Maxey508d2b52008-01-31 20:20:49 -06002641 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002642 u64 hret;
2643 u64 dummy64 = 0;
2644 u16 dummy16 = 0;
2645
Thomas Klein3faf2692009-01-21 14:45:33 -08002646 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002647 if (!cb0) {
2648 ret = -ENOMEM;
2649 goto out;
2650 }
2651
Anton Blanchard723f28e2011-10-14 05:31:01 +00002652 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002653 struct ehea_port_res *pr = &port->port_res[i];
2654 struct ehea_qp *qp = pr->qp;
2655
2656 ret = ehea_gen_smrs(pr);
2657 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002658 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002659 goto out;
2660 }
2661
2662 ehea_update_rqs(qp, pr);
2663
2664 /* Enable queue pair */
2665 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2666 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2667 cb0);
2668 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002669 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002670 goto out;
2671 }
2672
2673 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2674 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2675
2676 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2677 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2678 1), cb0, &dummy64,
2679 &dummy64, &dummy16, &dummy16);
2680 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002681 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002682 goto out;
2683 }
2684
2685 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2686 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2687 cb0);
2688 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002689 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002690 goto out;
2691 }
2692
2693 /* refill entire queue */
2694 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2695 ehea_refill_rq2(pr, 0);
2696 ehea_refill_rq3(pr, 0);
2697 }
2698out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002699 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002700
2701 return ret;
2702}
2703
David Howellsc4028952006-11-22 14:57:56 +00002704static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002705{
2706 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002707 struct ehea_port *port =
2708 container_of(work, struct ehea_port, reset_task);
2709 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002710
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002711 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002713 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002714 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002715
2716 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002717
Thomas Klein44c82152007-07-11 16:32:00 +02002718 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002719
2720 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002721 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002722 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002724 ehea_set_multicast_list(dev);
2725
Joe Perches8c4877a2010-12-13 10:05:14 -08002726 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002727
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002728 port_napi_enable(port);
2729
Anton Blanchardb9564462011-10-14 05:30:59 +00002730 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002731out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002732 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002733 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002734}
2735
Tejun Heo3d6b8922010-12-12 16:45:14 +01002736static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002737{
2738 int ret, i;
2739 struct ehea_adapter *adapter;
2740
Joe Perches8c4877a2010-12-13 10:05:14 -08002741 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002742
2743 list_for_each_entry(adapter, &adapter_list, list)
2744 if (adapter->active_ports) {
2745 /* Shutdown all ports */
2746 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2747 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002748 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002749
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002750 if (!port)
2751 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002752
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002753 dev = port->netdev;
2754
2755 if (dev->flags & IFF_UP) {
2756 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002757 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002758 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002759 ret = ehea_stop_qps(dev);
2760 if (ret) {
2761 mutex_unlock(&port->port_lock);
2762 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002763 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002764 port_napi_disable(port);
2765 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002766 }
Andre Detsch2928db42010-08-17 05:49:12 +00002767 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002768 }
2769
2770 /* Unregister old memory region */
2771 ret = ehea_rem_mr(&adapter->mr);
2772 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002773 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002774 goto out;
2775 }
2776 }
2777
Thomas Klein44c82152007-07-11 16:32:00 +02002778 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2779
2780 list_for_each_entry(adapter, &adapter_list, list)
2781 if (adapter->active_ports) {
2782 /* Register new memory region */
2783 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2784 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002785 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002786 goto out;
2787 }
2788
2789 /* Restart all ports */
2790 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2791 struct ehea_port *port = adapter->port[i];
2792
2793 if (port) {
2794 struct net_device *dev = port->netdev;
2795
2796 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002797 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002798 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002799 if (!ret) {
2800 check_sqs(port);
2801 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002802 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002803 } else {
2804 netdev_err(dev, "Unable to restart QPS\n");
2805 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002806 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002807 }
2808 }
2809 }
2810 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002811 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002812out:
2813 return;
2814}
2815
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002816static void ehea_tx_watchdog(struct net_device *dev)
2817{
2818 struct ehea_port *port = netdev_priv(dev);
2819
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002820 if (netif_carrier_ok(dev) &&
2821 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002822 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002823}
2824
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002825static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002826{
2827 struct hcp_query_ehea *cb;
2828 u64 hret;
2829 int ret;
2830
Thomas Klein3faf2692009-01-21 14:45:33 -08002831 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002832 if (!cb) {
2833 ret = -ENOMEM;
2834 goto out;
2835 }
2836
2837 hret = ehea_h_query_ehea(adapter->handle, cb);
2838
2839 if (hret != H_SUCCESS) {
2840 ret = -EIO;
2841 goto out_herr;
2842 }
2843
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002844 adapter->max_mc_mac = cb->max_mc_mac - 1;
2845 ret = 0;
2846
2847out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002848 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002849out:
2850 return ret;
2851}
2852
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002853static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002854{
2855 struct hcp_ehea_port_cb4 *cb4;
2856 u64 hret;
2857 int ret = 0;
2858
2859 *jumbo = 0;
2860
2861 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002862 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002863 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002864 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002865 ret = -ENOMEM;
2866 goto out;
2867 } else {
2868 hret = ehea_h_query_ehea_port(port->adapter->handle,
2869 port->logical_port_id,
2870 H_PORT_CB4,
2871 H_PORT_CB4_JUMBO, cb4);
2872 if (hret == H_SUCCESS) {
2873 if (cb4->jumbo_frame)
2874 *jumbo = 1;
2875 else {
2876 cb4->jumbo_frame = 1;
2877 hret = ehea_h_modify_ehea_port(port->adapter->
2878 handle,
2879 port->
2880 logical_port_id,
2881 H_PORT_CB4,
2882 H_PORT_CB4_JUMBO,
2883 cb4);
2884 if (hret == H_SUCCESS)
2885 *jumbo = 1;
2886 }
2887 } else
2888 ret = -EINVAL;
2889
Thomas Klein3faf2692009-01-21 14:45:33 -08002890 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002891 }
2892out:
2893 return ret;
2894}
2895
2896static ssize_t ehea_show_port_id(struct device *dev,
2897 struct device_attribute *attr, char *buf)
2898{
2899 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002900 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002901}
2902
2903static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2904 NULL);
2905
Bill Pemberton0297be02012-12-03 09:23:10 -05002906static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002907{
2908 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002909 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002910}
2911
2912static struct device *ehea_register_port(struct ehea_port *port,
2913 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002914{
2915 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002916
Grant Likely61c7a082010-04-13 16:12:29 -07002917 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002918 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002919 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002920
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002921 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002922 port->ofdev.dev.release = logical_port_release;
2923
2924 ret = of_device_register(&port->ofdev);
2925 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002926 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002927 goto out;
2928 }
2929
2930 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002931 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002932 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002933 goto out_unreg_of_dev;
2934 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002935
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002936 return &port->ofdev.dev;
2937
2938out_unreg_of_dev:
2939 of_device_unregister(&port->ofdev);
2940out:
2941 return NULL;
2942}
2943
2944static void ehea_unregister_port(struct ehea_port *port)
2945{
2946 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2947 of_device_unregister(&port->ofdev);
2948}
2949
Thomas Klein086c1b22009-01-21 14:43:59 -08002950static const struct net_device_ops ehea_netdev_ops = {
2951 .ndo_open = ehea_open,
2952 .ndo_stop = ehea_stop,
2953 .ndo_start_xmit = ehea_start_xmit,
2954#ifdef CONFIG_NET_POLL_CONTROLLER
2955 .ndo_poll_controller = ehea_netpoll,
2956#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002957 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002958 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002959 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002960 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002961 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002962 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002963 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2964 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002965};
2966
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002967static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002968 u32 logical_port_id,
2969 struct device_node *dn)
2970{
2971 int ret;
2972 struct net_device *dev;
2973 struct ehea_port *port;
2974 struct device *port_dev;
2975 int jumbo;
2976
2977 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002978 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002979
2980 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002981 ret = -ENOMEM;
2982 goto out_err;
2983 }
2984
2985 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002986
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002987 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002988 port->state = EHEA_PORT_DOWN;
2989 port->sig_comp_iv = sq_entries / 10;
2990
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002991 port->adapter = adapter;
2992 port->netdev = dev;
2993 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002994
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002995 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002996
2997 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2998 if (!port->mc_list) {
2999 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003000 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003001 }
3002
3003 INIT_LIST_HEAD(&port->mc_list->list);
3004
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003005 ret = ehea_sense_port_attr(port);
3006 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003007 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003008
Anton Blanchardb9564462011-10-14 05:30:59 +00003009 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003010 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003011
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003012 port_dev = ehea_register_port(port, dn);
3013 if (!port_dev)
3014 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003015
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003016 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003017
3018 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003019 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3020
Thomas Klein086c1b22009-01-21 14:43:59 -08003021 dev->netdev_ops = &ehea_netdev_ops;
3022 ehea_set_ethtool_ops(dev);
3023
David S. Miller55fbbe42013-04-22 19:34:34 -04003024 dev->hw_features = NETIF_F_SG | NETIF_F_TSO |
3025 NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_CTAG_TX;
3026 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |
3027 NETIF_F_HIGHDMA | NETIF_F_IP_CSUM |
3028 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
3029 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003030 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3031 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003032 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3033
David Howellsc4028952006-11-22 14:57:56 +00003034 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003035 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003036
Anton Blanchard21ccc792011-05-10 16:17:10 +00003037 init_waitqueue_head(&port->swqe_avail_wq);
3038 init_waitqueue_head(&port->restart_wq);
3039
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003040 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003041 ret = register_netdev(dev);
3042 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003043 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003044 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045 }
3046
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003047 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003048 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003049 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003050
Joe Perches8c4877a2010-12-13 10:05:14 -08003051 netdev_info(dev, "Jumbo frames are %sabled\n",
3052 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003053
Thomas Klein44c82152007-07-11 16:32:00 +02003054 adapter->active_ports++;
3055
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003056 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003057
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003058out_unreg_port:
3059 ehea_unregister_port(port);
3060
3061out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003062 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003063
3064out_free_ethdev:
3065 free_netdev(dev);
3066
3067out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003068 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3069 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003070 return NULL;
3071}
3072
3073static void ehea_shutdown_single_port(struct ehea_port *port)
3074{
Brian King7fb1c2a2008-05-14 09:48:25 -05003075 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003076
3077 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003078 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003079 unregister_netdev(port->netdev);
3080 ehea_unregister_port(port);
3081 kfree(port->mc_list);
3082 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003083 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003084}
3085
3086static int ehea_setup_ports(struct ehea_adapter *adapter)
3087{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003088 struct device_node *lhea_dn;
3089 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003090
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003091 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003092 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003093
Grant Likely61c7a082010-04-13 16:12:29 -07003094 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003095 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003096
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003097 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003098 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003099 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003100 pr_err("bad device node: eth_dn name=%s\n",
3101 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003103 }
3104
Thomas Klein1211bb62007-04-26 11:56:43 +02003105 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003106 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003107 of_node_put(eth_dn);
3108 return -EIO;
3109 }
3110
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003111 adapter->port[i] = ehea_setup_single_port(adapter,
3112 *dn_log_port_id,
3113 eth_dn);
3114 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003115 netdev_info(adapter->port[i]->netdev,
3116 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003117 else
3118 ehea_remove_adapter_mr(adapter);
3119
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003120 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003121 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003122 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003123}
3124
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003125static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3126 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003127{
3128 struct device_node *lhea_dn;
3129 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003130 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131
Grant Likely61c7a082010-04-13 16:12:29 -07003132 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003133 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003134
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003135 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003136 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137 if (dn_log_port_id)
3138 if (*dn_log_port_id == logical_port_id)
3139 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003140 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003141
3142 return NULL;
3143}
3144
3145static ssize_t ehea_probe_port(struct device *dev,
3146 struct device_attribute *attr,
3147 const char *buf, size_t count)
3148{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003149 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150 struct ehea_port *port;
3151 struct device_node *eth_dn = NULL;
3152 int i;
3153
3154 u32 logical_port_id;
3155
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003156 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003157
3158 port = ehea_get_port(adapter, logical_port_id);
3159
3160 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003161 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3162 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163 return -EINVAL;
3164 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003165
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3167
3168 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003169 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170 return -EINVAL;
3171 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003172
Thomas Klein1211bb62007-04-26 11:56:43 +02003173 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003174 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003175 return -EIO;
3176 }
3177
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003178 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3179
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003180 of_node_put(eth_dn);
3181
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003182 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003183 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 if (!adapter->port[i]) {
3185 adapter->port[i] = port;
3186 break;
3187 }
3188
Joe Perches8c4877a2010-12-13 10:05:14 -08003189 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3190 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003191 } else {
3192 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003193 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003194 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003195
3196 return (ssize_t) count;
3197}
3198
3199static ssize_t ehea_remove_port(struct device *dev,
3200 struct device_attribute *attr,
3201 const char *buf, size_t count)
3202{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003203 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003204 struct ehea_port *port;
3205 int i;
3206 u32 logical_port_id;
3207
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003208 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003209
3210 port = ehea_get_port(adapter, logical_port_id);
3211
3212 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003213 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3214 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215
3216 ehea_shutdown_single_port(port);
3217
Doug Maxey508d2b52008-01-31 20:20:49 -06003218 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 if (adapter->port[i] == port) {
3220 adapter->port[i] = NULL;
3221 break;
3222 }
3223 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003224 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3225 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226 return -EINVAL;
3227 }
3228
Thomas Klein1211bb62007-04-26 11:56:43 +02003229 ehea_remove_adapter_mr(adapter);
3230
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231 return (ssize_t) count;
3232}
3233
3234static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3235static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3236
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003237static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003238{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003239 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 if (ret)
3241 goto out;
3242
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003243 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245 return ret;
3246}
3247
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003248static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003250 device_remove_file(&dev->dev, &dev_attr_probe_port);
3251 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252}
3253
Bill Pemberton0297be02012-12-03 09:23:10 -05003254static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003255 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003256{
3257 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003258 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003260 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003261
Grant Likely61c7a082010-04-13 16:12:29 -07003262 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003263 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003264 return -EINVAL;
3265 }
3266
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003267 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3268 if (!adapter) {
3269 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003270 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003271 goto out;
3272 }
3273
Thomas Klein44c82152007-07-11 16:32:00 +02003274 list_add(&adapter->list, &adapter_list);
3275
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003276 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003277
Grant Likely61c7a082010-04-13 16:12:29 -07003278 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003279 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003280 if (adapter_handle)
3281 adapter->handle = *adapter_handle;
3282
3283 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003284 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003285 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003286 ret = -ENODEV;
3287 goto out_free_ad;
3288 }
3289
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003290 adapter->pd = EHEA_PD_ID;
3291
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003292 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003293
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003294
3295 /* initialize adapter and ports */
3296 /* get adapter properties */
3297 ret = ehea_sense_adapter_attr(adapter);
3298 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003299 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003300 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003301 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003302
3303 adapter->neq = ehea_create_eq(adapter,
3304 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3305 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003306 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003307 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003308 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003309 }
3310
3311 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3312 (unsigned long)adapter);
3313
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003314 ret = ehea_create_device_sysfs(dev);
3315 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003316 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003317
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003318 ret = ehea_setup_ports(adapter);
3319 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003320 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003321 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003322 }
3323
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003324 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3325 ehea_interrupt_neq, IRQF_DISABLED,
3326 "ehea_neq", adapter);
3327 if (ret) {
3328 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3329 goto out_shutdown_ports;
3330 }
3331
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003332 /* Handle any events that might be pending. */
3333 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003334
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003335 ret = 0;
3336 goto out;
3337
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003338out_shutdown_ports:
3339 for (i = 0; i < EHEA_MAX_PORTS; i++)
3340 if (adapter->port[i]) {
3341 ehea_shutdown_single_port(adapter->port[i]);
3342 adapter->port[i] = NULL;
3343 }
3344
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003345out_rem_dev_sysfs:
3346 ehea_remove_device_sysfs(dev);
3347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348out_kill_eq:
3349 ehea_destroy_eq(adapter->neq);
3350
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003351out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003352 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003353 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003354
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003355out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003356 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003357
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003358 return ret;
3359}
3360
Bill Pemberton0297be02012-12-03 09:23:10 -05003361static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003362{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003363 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003364 int i;
3365
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003366 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003367 if (adapter->port[i]) {
3368 ehea_shutdown_single_port(adapter->port[i]);
3369 adapter->port[i] = NULL;
3370 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003371
3372 ehea_remove_device_sysfs(dev);
3373
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003374 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003375 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003376
3377 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003378 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003379 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003381
Thomas Klein21eee2d2008-02-13 16:18:33 +01003382 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003383
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003384 return 0;
3385}
3386
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003387static void ehea_crash_handler(void)
Thomas Klein21eee2d2008-02-13 16:18:33 +01003388{
3389 int i;
3390
3391 if (ehea_fw_handles.arr)
3392 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3393 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3394 ehea_fw_handles.arr[i].fwh,
3395 FORCE_FREE);
3396
3397 if (ehea_bcmc_regs.arr)
3398 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3399 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3400 ehea_bcmc_regs.arr[i].port_id,
3401 ehea_bcmc_regs.arr[i].reg_type,
3402 ehea_bcmc_regs.arr[i].macaddr,
3403 0, H_DEREG_BCMC);
3404}
3405
Hannes Hering48cfb142008-05-07 14:43:36 +02003406static int ehea_mem_notifier(struct notifier_block *nb,
3407 unsigned long action, void *data)
3408{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003409 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003410 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003411
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003412 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003413
Hannes Hering48cfb142008-05-07 14:43:36 +02003414 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003415 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003416 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003417 /* Readd canceled memory block */
3418 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003419 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003420 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003421 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003422 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003423 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003424 break;
3425 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003426 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003427 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003428 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003429 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003430 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003431 break;
3432 default:
3433 break;
3434 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003435
3436 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003437 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003438
Thomas Kleina7c561f22010-04-20 23:11:31 +00003439out_unlock:
3440 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003441 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003442}
3443
3444static struct notifier_block ehea_mem_nb = {
3445 .notifier_call = ehea_mem_notifier,
3446};
3447
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003448static int ehea_reboot_notifier(struct notifier_block *nb,
3449 unsigned long action, void *unused)
3450{
3451 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003452 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003453 ibmebus_unregister_driver(&ehea_driver);
3454 }
3455 return NOTIFY_DONE;
3456}
3457
3458static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003459 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003460};
3461
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003462static int check_module_parm(void)
3463{
3464 int ret = 0;
3465
3466 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3467 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003468 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003469 ret = -EINVAL;
3470 }
3471 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3472 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003473 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003474 ret = -EINVAL;
3475 }
3476 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3477 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003478 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003479 ret = -EINVAL;
3480 }
3481 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3482 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003483 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003484 ret = -EINVAL;
3485 }
3486
3487 return ret;
3488}
3489
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003490static ssize_t ehea_show_capabilities(struct device_driver *drv,
3491 char *buf)
3492{
3493 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3494}
3495
3496static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3497 ehea_show_capabilities, NULL);
3498
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003499static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003500{
3501 int ret;
3502
Joe Perches8c4877a2010-12-13 10:05:14 -08003503 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504
Thomas Klein21eee2d2008-02-13 16:18:33 +01003505 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3506 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3507
Daniel Walker9f71a562008-03-28 14:41:26 -07003508 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003509 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003510
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003511 ret = check_module_parm();
3512 if (ret)
3513 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003514
3515 ret = ehea_create_busmap();
3516 if (ret)
3517 goto out;
3518
Thomas Klein21eee2d2008-02-13 16:18:33 +01003519 ret = register_reboot_notifier(&ehea_reboot_nb);
3520 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003521 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003522
Hannes Hering48cfb142008-05-07 14:43:36 +02003523 ret = register_memory_notifier(&ehea_mem_nb);
3524 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003525 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003526
Joe Perchesc061b182010-08-23 18:20:03 +00003527 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003528 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003529 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003532 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003533 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003534 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003535 }
3536
3537 ret = driver_create_file(&ehea_driver.driver,
3538 &driver_attr_capabilities);
3539 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003540 pr_err("failed to register capabilities attribute, ret=%d\n",
3541 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003542 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003543 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003544
Thomas Klein21eee2d2008-02-13 16:18:33 +01003545 return ret;
3546
3547out3:
3548 ibmebus_unregister_driver(&ehea_driver);
3549out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003550 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003551 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003552 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553out:
3554 return ret;
3555}
3556
3557static void __exit ehea_module_exit(void)
3558{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003559 int ret;
3560
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003561 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003562 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003563 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003564 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003565 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003566 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003567 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003568 kfree(ehea_fw_handles.arr);
3569 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003570 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571}
3572
3573module_init(ehea_module_init);
3574module_exit(ehea_module_exit);