blob: 1e53d7a82675f3e7fee8db985922331ecf2cadc3 [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
Himangi Saraogi09b38aa2014-05-28 19:53:09 +053031#include <linux/device.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020032#include <linux/in.h>
33#include <linux/ip.h>
34#include <linux/tcp.h>
35#include <linux/udp.h>
36#include <linux/if.h>
37#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020039#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020040#include <linux/notifier.h>
41#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020042#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010043#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070044#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070045#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020046
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020047#include <net/ip.h>
48
49#include "ehea.h"
50#include "ehea_qmr.h"
51#include "ehea_phyp.h"
52
53
54MODULE_LICENSE("GPL");
55MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
56MODULE_DESCRIPTION("IBM eServer HEA Driver");
57MODULE_VERSION(DRV_VERSION);
58
59
60static int msg_level = -1;
61static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
62static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
63static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
64static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000065static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060066static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020067
68module_param(msg_level, int, 0);
69module_param(rq1_entries, int, 0);
70module_param(rq2_entries, int, 0);
71module_param(rq3_entries, int, 0);
72module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020073module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010074module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020075
76MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020077MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
78 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
Dave Young31d17532013-02-15 20:19:19 +000080 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
82MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
Dave Young31d17532013-02-15 20:19:19 +000083 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020084 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
85MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
Dave Young31d17532013-02-15 20:19:19 +000086 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020087 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
88MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
Dave Young31d17532013-02-15 20:19:19 +000089 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020090 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000091MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
92 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020093
Doug Maxey508d2b52008-01-31 20:20:49 -060094static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020095static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080096static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070097static DEFINE_MUTEX(dlpar_mem_lock);
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +000098static struct ehea_fw_handle_array ehea_fw_handles;
99static struct ehea_bcmc_reg_array ehea_bcmc_regs;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100100
Thomas Kleind1dea382007-04-26 11:56:13 +0200101
Rob Herringc45640e2013-04-20 21:51:08 -0500102static int ehea_probe_adapter(struct platform_device *dev);
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
Fabian Frederickabae1e02015-03-17 19:40:26 +0100106static const struct of_device_id ehea_module_device_table[] = {
Olaf Hering7a3a6212013-09-13 14:52:01 -0700107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {
112 .type = "network",
113 .compatible = "IBM,lhea-ethernet",
114 },
115 {},
116};
117MODULE_DEVICE_TABLE(of, ehea_module_device_table);
118
Fabian Frederickabae1e02015-03-17 19:40:26 +0100119static const struct of_device_id ehea_device_table[] = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200120 {
121 .name = "lhea",
122 .compatible = "IBM,lhea",
123 },
124 {},
125};
126
Rob Herringc45640e2013-04-20 21:51:08 -0500127static struct platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700128 .driver = {
129 .name = "ehea",
130 .owner = THIS_MODULE,
131 .of_match_table = ehea_device_table,
132 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200133 .probe = ehea_probe_adapter,
134 .remove = ehea_remove,
135};
136
Doug Maxey508d2b52008-01-31 20:20:49 -0600137void ehea_dump(void *adr, int len, char *msg)
138{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200139 int x;
140 unsigned char *deb = adr;
141 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800142 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
143 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200144 deb += 16;
145 }
146}
147
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +0000148static void ehea_schedule_port_reset(struct ehea_port *port)
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100149{
150 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
151 schedule_work(&port->reset_task);
152}
153
Thomas Klein21eee2d2008-02-13 16:18:33 +0100154static void ehea_update_firmware_handles(void)
155{
156 struct ehea_fw_handle_entry *arr = NULL;
157 struct ehea_adapter *adapter;
158 int num_adapters = 0;
159 int num_ports = 0;
160 int num_portres = 0;
161 int i = 0;
162 int num_fw_handles, k, l;
163
164 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700165 mutex_lock(&ehea_fw_handles.lock);
166
Thomas Klein21eee2d2008-02-13 16:18:33 +0100167 list_for_each_entry(adapter, &adapter_list, list) {
168 num_adapters++;
169
170 for (k = 0; k < EHEA_MAX_PORTS; k++) {
171 struct ehea_port *port = adapter->port[k];
172
173 if (!port || (port->state != EHEA_PORT_UP))
174 continue;
175
176 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000177 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100178 }
179 }
180
181 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
182 num_ports * EHEA_NUM_PORT_FW_HANDLES +
183 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
184
185 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000186 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100187 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700188 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 } else
190 goto out_update;
191
192 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700193 if (num_adapters == 0)
194 break;
195
Thomas Klein21eee2d2008-02-13 16:18:33 +0100196 for (k = 0; k < EHEA_MAX_PORTS; k++) {
197 struct ehea_port *port = adapter->port[k];
198
Joe Perches8e95a202009-12-03 07:58:21 +0000199 if (!port || (port->state != EHEA_PORT_UP) ||
200 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100201 continue;
202
Anton Blanchard723f28e2011-10-14 05:31:01 +0000203 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100204 struct ehea_port_res *pr = &port->port_res[l];
205
206 arr[i].adh = adapter->handle;
207 arr[i++].fwh = pr->qp->fw_handle;
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = pr->send_cq->fw_handle;
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = pr->recv_cq->fw_handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = pr->eq->fw_handle;
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = pr->send_mr.handle;
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = pr->recv_mr.handle;
218 }
219 arr[i].adh = adapter->handle;
220 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700221 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100222 }
223
224 arr[i].adh = adapter->handle;
225 arr[i++].fwh = adapter->neq->fw_handle;
226
227 if (adapter->mr.handle) {
228 arr[i].adh = adapter->handle;
229 arr[i++].fwh = adapter->mr.handle;
230 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700231 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100232 }
233
234out_update:
235 kfree(ehea_fw_handles.arr);
236 ehea_fw_handles.arr = arr;
237 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700238out:
239 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100240}
241
242static void ehea_update_bcmc_registrations(void)
243{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700244 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100245 struct ehea_bcmc_reg_entry *arr = NULL;
246 struct ehea_adapter *adapter;
247 struct ehea_mc_list *mc_entry;
248 int num_registrations = 0;
249 int i = 0;
250 int k;
251
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700252 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
253
Thomas Klein21eee2d2008-02-13 16:18:33 +0100254 /* Determine number of registrations */
255 list_for_each_entry(adapter, &adapter_list, list)
256 for (k = 0; k < EHEA_MAX_PORTS; k++) {
257 struct ehea_port *port = adapter->port[k];
258
259 if (!port || (port->state != EHEA_PORT_UP))
260 continue;
261
262 num_registrations += 2; /* Broadcast registrations */
263
264 list_for_each_entry(mc_entry, &port->mc_list->list,list)
265 num_registrations += 2;
266 }
267
268 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000269 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100270 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700271 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100272 } else
273 goto out_update;
274
275 list_for_each_entry(adapter, &adapter_list, list) {
276 for (k = 0; k < EHEA_MAX_PORTS; k++) {
277 struct ehea_port *port = adapter->port[k];
278
279 if (!port || (port->state != EHEA_PORT_UP))
280 continue;
281
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700282 if (num_registrations == 0)
283 goto out_update;
284
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285 arr[i].adh = adapter->handle;
286 arr[i].port_id = port->logical_port_id;
287 arr[i].reg_type = EHEA_BCMC_BROADCAST |
288 EHEA_BCMC_UNTAGGED;
289 arr[i++].macaddr = port->mac_addr;
290
291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
293 arr[i].reg_type = EHEA_BCMC_BROADCAST |
294 EHEA_BCMC_VLANID_ALL;
295 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700296 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297
298 list_for_each_entry(mc_entry,
299 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700300 if (num_registrations == 0)
301 goto out_update;
302
Thomas Klein21eee2d2008-02-13 16:18:33 +0100303 arr[i].adh = adapter->handle;
304 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000305 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100306 EHEA_BCMC_UNTAGGED;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000307 if (mc_entry->macaddr == 0)
308 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100309 arr[i++].macaddr = mc_entry->macaddr;
310
311 arr[i].adh = adapter->handle;
312 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000313 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100314 EHEA_BCMC_VLANID_ALL;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000315 if (mc_entry->macaddr == 0)
316 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700318 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100319 }
320 }
321 }
322
323out_update:
324 kfree(ehea_bcmc_regs.arr);
325 ehea_bcmc_regs.arr = arr;
326 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700327out:
328 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100329}
330
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800331static void ehea_get_stats64(struct net_device *dev,
332 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200333{
334 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000335 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 int i;
337
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000338 for (i = 0; i < port->num_def_qps; i++) {
339 rx_packets += port->port_res[i].rx_packets;
340 rx_bytes += port->port_res[i].rx_bytes;
341 }
342
Anton Blanchard723f28e2011-10-14 05:31:01 +0000343 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000344 tx_packets += port->port_res[i].tx_packets;
345 tx_bytes += port->port_res[i].tx_bytes;
346 }
347
348 stats->tx_packets = tx_packets;
349 stats->rx_bytes = rx_bytes;
350 stats->tx_bytes = tx_bytes;
351 stats->rx_packets = rx_packets;
352
Eric Dumazet09c1d442012-03-06 19:46:41 +0000353 stats->multicast = port->stats.multicast;
354 stats->rx_errors = port->stats.rx_errors;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000355}
356
357static void ehea_update_stats(struct work_struct *work)
358{
359 struct ehea_port *port =
360 container_of(work, struct ehea_port, stats_work.work);
361 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000362 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000363 struct hcp_ehea_port_cb2 *cb2;
364 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200365
Brian King3d8009c2010-06-30 11:59:12 +0000366 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200367 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000368 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
369 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370 }
371
372 hret = ehea_h_query_ehea_port(port->adapter->handle,
373 port->logical_port_id,
374 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
375 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800376 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200377 goto out_herr;
378 }
379
380 if (netif_msg_hw(port))
381 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
382
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200383 stats->multicast = cb2->rxmcp;
384 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200385
386out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800387 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000388resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000389 schedule_delayed_work(&port->stats_work,
390 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200391}
392
393static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
394{
395 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
396 struct net_device *dev = pr->port->netdev;
397 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200398 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
399 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200400 int i;
401
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200402 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200403
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200404 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200405 if (nr_of_wqes > 0)
406 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200407 pr->rq1_skba.os_skbs = fill_wqes;
408 return;
409 }
410
411 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412 if (!skb_arr_rq1[index]) {
413 skb_arr_rq1[index] = netdev_alloc_skb(dev,
414 EHEA_L_PKT_SIZE);
415 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200416 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 break;
418 }
419 }
420 index--;
421 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200422 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200424
425 if (adder == 0)
426 return;
427
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200428 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200429 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200430}
431
Thomas Kleine2878802009-01-21 14:45:57 -0800432static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
435 struct net_device *dev = pr->port->netdev;
436 int i;
437
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800439 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000440 return;
441 }
442
443 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200444 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000445 if (!skb_arr_rq1[i])
Thomas Kleine2878802009-01-21 14:45:57 -0800446 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200447 }
448 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000449 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450}
451
452static int ehea_refill_rq_def(struct ehea_port_res *pr,
453 struct ehea_q_skb_arr *q_skba, int rq_nr,
454 int num_wqes, int wqe_type, int packet_size)
455{
456 struct net_device *dev = pr->port->netdev;
457 struct ehea_qp *qp = pr->qp;
458 struct sk_buff **skb_arr = q_skba->arr;
459 struct ehea_rwqe *rwqe;
460 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200461 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462 int ret = 0;
463
464 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200466
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200467 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
468 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200470 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471
472 index = q_skba->index;
473 max_index_mask = q_skba->len - 1;
474 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200475 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000476 struct sk_buff *skb;
477
478 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200480 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800481 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800482 netdev_info(pr->port->netdev,
483 "rq%i ran dry - no mem for skb\n",
484 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800485 ret = -ENOMEM;
486 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487 break;
488 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489
490 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200491 tmp_addr = ehea_map_vaddr(skb->data);
492 if (tmp_addr == -1) {
Eric W. Biedermancfbe4062014-03-15 17:25:48 -0700493 dev_consume_skb_any(skb);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200494 q_skba->os_skbs = fill_wqes - i;
495 ret = 0;
496 break;
497 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200498
499 rwqe = ehea_get_next_rwqe(qp, rq_nr);
500 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200501 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200503 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 rwqe->sg_list[0].len = packet_size;
505 rwqe->data_segments = 1;
506
507 index++;
508 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200510 }
Thomas Klein44c82152007-07-11 16:32:00 +0200511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200513 if (adder == 0)
514 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515
516 /* Ring doorbell */
517 iosync();
518 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200519 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200520 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200521 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200522out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200523 return ret;
524}
525
526
527static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
528{
529 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
530 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200532}
533
534
535static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
536{
537 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
538 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000539 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200540}
541
542static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
543{
544 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
545 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
546 return 0;
547 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
548 (cqe->header_length == 0))
549 return 0;
550 return -EINVAL;
551}
552
553static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000554 struct sk_buff *skb, struct ehea_cqe *cqe,
555 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200556{
557 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
558
559 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000561
562 /* The packet was not an IPV4 packet so a complemented checksum was
563 calculated. The value is found in the Internet Checksum field. */
564 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
565 skb->ip_summed = CHECKSUM_COMPLETE;
566 skb->csum = csum_unfold(~cqe->inet_checksum_value);
567 } else
568 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000569
570 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200571}
572
573static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
574 int arr_len,
575 struct ehea_cqe *cqe)
576{
577 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
578 struct sk_buff *skb;
579 void *pref;
580 int x;
581
582 x = skb_index + 1;
583 x &= (arr_len - 1);
584
585 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700586 if (pref) {
587 prefetchw(pref);
588 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200589
Hannes Hering0b2febf2009-05-04 11:06:37 -0700590 pref = (skb_array[x]->data);
591 prefetch(pref);
592 prefetch(pref + EHEA_CACHE_LINE);
593 prefetch(pref + EHEA_CACHE_LINE * 2);
594 prefetch(pref + EHEA_CACHE_LINE * 3);
595 }
596
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200597 skb = skb_array[skb_index];
598 skb_array[skb_index] = NULL;
599 return skb;
600}
601
602static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
603 int arr_len, int wqe_index)
604{
605 struct sk_buff *skb;
606 void *pref;
607 int x;
608
609 x = wqe_index + 1;
610 x &= (arr_len - 1);
611
612 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700613 if (pref) {
614 prefetchw(pref);
615 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200616
Hannes Hering0b2febf2009-05-04 11:06:37 -0700617 pref = (skb_array[x]->data);
618 prefetchw(pref);
619 prefetchw(pref + EHEA_CACHE_LINE);
620 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200621
622 skb = skb_array[wqe_index];
623 skb_array[wqe_index] = NULL;
624 return skb;
625}
626
627static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
628 struct ehea_cqe *cqe, int *processed_rq2,
629 int *processed_rq3)
630{
631 struct sk_buff *skb;
632
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100633 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
634 pr->p_stats.err_tcp_cksum++;
635 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
636 pr->p_stats.err_ip_cksum++;
637 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
638 pr->p_stats.err_frame_crc++;
639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200640 if (rq == 2) {
641 *processed_rq2 += 1;
642 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
643 dev_kfree_skb(skb);
644 } else if (rq == 3) {
645 *processed_rq3 += 1;
646 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
647 dev_kfree_skb(skb);
648 }
649
650 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100651 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800652 pr_err("Critical receive error for QP %d. Resetting port.\n",
653 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100654 ehea_dump(cqe, sizeof(*cqe), "CQE");
655 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100656 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200657 return 1;
658 }
659
660 return 0;
661}
662
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700663static int ehea_proc_rwqes(struct net_device *dev,
664 struct ehea_port_res *pr,
665 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200666{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100667 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200668 struct ehea_qp *qp = pr->qp;
669 struct ehea_cqe *cqe;
670 struct sk_buff *skb;
671 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
672 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
673 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
674 int skb_arr_rq1_len = pr->rq1_skba.len;
675 int skb_arr_rq2_len = pr->rq2_skba.len;
676 int skb_arr_rq3_len = pr->rq3_skba.len;
677 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000678 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700679 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200680
681 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
682 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200683
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200684 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700685 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200686 ehea_inc_rq1(qp);
687 processed_rq1++;
688 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200689 if (netif_msg_rx_status(port))
690 ehea_dump(cqe, sizeof(*cqe), "CQE");
691
692 last_wqe_index = wqe_index;
693 rmb();
694 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600695 if (rq == 1) {
696 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200697 skb = get_skb_by_index_ll(skb_arr_rq1,
698 skb_arr_rq1_len,
699 wqe_index);
700 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800701 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800702 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100703
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700704 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200705 EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000706 if (!skb)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707 break;
708 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600709 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200710 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000711 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600712 } else if (rq == 2) {
713 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200714 skb = get_skb_by_index(skb_arr_rq2,
715 skb_arr_rq2_len, cqe);
716 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800717 netif_err(port, rx_err, dev,
718 "rq2: 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_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600723 } else {
724 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 skb = get_skb_by_index(skb_arr_rq3,
726 skb_arr_rq3_len, cqe);
727 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800728 netif_err(port, rx_err, dev,
729 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200730 break;
731 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000732 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200733 processed_rq3++;
734 }
735
Breno Leitaoce45b872010-10-27 08:45:14 +0000736 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000737
738 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
David S. Millere5905c82013-04-22 19:24:19 -0400739 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
740 cqe->vlan_tag);
Anton Blanchard34284142011-10-14 05:31:11 +0000741
742 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100743 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100744 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 port_reset = ehea_treat_poll_error(pr, rq, cqe,
746 &processed_rq2,
747 &processed_rq3);
748 if (port_reset)
749 break;
750 }
751 cqe = ehea_poll_rq1(qp, &wqe_index);
752 }
753
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000755 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756
757 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
758 ehea_refill_rq2(pr, processed_rq2);
759 ehea_refill_rq3(pr, processed_rq3);
760
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700761 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200762}
763
Andre Detsch2928db42010-08-17 05:49:12 +0000764#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
765
766static void reset_sq_restart_flag(struct ehea_port *port)
767{
768 int i;
769
Anton Blanchard723f28e2011-10-14 05:31:01 +0000770 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000771 struct ehea_port_res *pr = &port->port_res[i];
772 pr->sq_restart_flag = 0;
773 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000774 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000775}
776
777static void check_sqs(struct ehea_port *port)
778{
779 struct ehea_swqe *swqe;
780 int swqe_index;
781 int i, k;
782
Anton Blanchard723f28e2011-10-14 05:31:01 +0000783 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000784 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000785 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000786 k = 0;
787 swqe = ehea_get_swqe(pr->qp, &swqe_index);
788 memset(swqe, 0, SWQE_HEADER_SIZE);
789 atomic_dec(&pr->swqe_avail);
790
791 swqe->tx_control |= EHEA_SWQE_PURGE;
792 swqe->wr_id = SWQE_RESTART_CHECK;
793 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
794 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
795 swqe->immediate_data_length = 80;
796
797 ehea_post_swqe(pr->qp, swqe);
798
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000799 ret = wait_event_timeout(port->restart_wq,
800 pr->sq_restart_flag == 0,
801 msecs_to_jiffies(100));
802
803 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800804 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000805 ehea_schedule_port_reset(pr->port);
806 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000807 }
808 }
Andre Detsch2928db42010-08-17 05:49:12 +0000809}
810
811
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100812static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200813{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100814 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200815 struct ehea_cq *send_cq = pr->send_cq;
816 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100817 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200818 int cqe_counter = 0;
819 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100820 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000821 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
822 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200823
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100824 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600825 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100826 ehea_inc_cq(send_cq);
827
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200828 cqe_counter++;
829 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000830
831 if (cqe->wr_id == SWQE_RESTART_CHECK) {
832 pr->sq_restart_flag = 1;
833 swqe_av++;
834 break;
835 }
836
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200837 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800838 pr_err("Bad send completion status=0x%04X\n",
839 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000840
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200841 if (netif_msg_tx_err(pr->port))
842 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000843
844 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800845 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000846 ehea_schedule_port_reset(pr->port);
847 break;
848 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200849 }
850
851 if (netif_msg_tx_done(pr->port))
852 ehea_dump(cqe, sizeof(*cqe), "CQE");
853
854 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100855 == EHEA_SWQE2_TYPE)) {
856
857 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
858 skb = pr->sq_skba.arr[index];
Eric W. Biedermancfbe4062014-03-15 17:25:48 -0700859 dev_consume_skb_any(skb);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100860 pr->sq_skba.arr[index] = NULL;
861 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200862
863 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
864 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100865
866 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700867 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868
869 ehea_update_feca(send_cq, cqe_counter);
870 atomic_add(swqe_av, &pr->swqe_avail);
871
Anton Blanchardb9564462011-10-14 05:30:59 +0000872 if (unlikely(netif_tx_queue_stopped(txq) &&
873 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
874 __netif_tx_lock(txq, smp_processor_id());
875 if (netif_tx_queue_stopped(txq) &&
876 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
877 netif_tx_wake_queue(txq);
878 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000880
Breno Leitao5b27d422010-10-05 13:16:22 +0000881 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100883 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200884}
885
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700886#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100887
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700888static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200889{
Doug Maxey508d2b52008-01-31 20:20:49 -0600890 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
891 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700892 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893 struct ehea_cqe *cqe;
894 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000895 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700896 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100897
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700898 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000899 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100900
Anton Blanchard222ca962011-10-14 05:31:00 +0000901 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800902 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903 ehea_reset_cq_ep(pr->recv_cq);
904 ehea_reset_cq_ep(pr->send_cq);
905 ehea_reset_cq_n1(pr->recv_cq);
906 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000907 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
909 cqe_skb = ehea_poll_cq(pr->send_cq);
910
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100911 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700912 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100913
Ben Hutchings288379f2009-01-19 16:43:59 -0800914 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700915 return rx;
916
917 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
918 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100919 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100920
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700921 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200922}
923
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200924#ifdef CONFIG_NET_POLL_CONTROLLER
925static void ehea_netpoll(struct net_device *dev)
926{
927 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700928 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200929
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800931 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200932}
933#endif
934
David Howells7d12e782006-10-05 14:55:46 +0100935static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200936{
937 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938
Ben Hutchings288379f2009-01-19 16:43:59 -0800939 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100940
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200941 return IRQ_HANDLED;
942}
943
David Howells7d12e782006-10-05 14:55:46 +0100944static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200945{
946 struct ehea_port *port = param;
947 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100948 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200949 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000950 u64 resource_type, aer, aerr;
951 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200952
953 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100954
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200955 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200956 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800957 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
958 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100959
960 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000961
962 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
963 &aer, &aerr);
964
965 if (resource_type == EHEA_AER_RESTYPE_QP) {
966 if ((aer & EHEA_AER_RESET_MASK) ||
967 (aerr & EHEA_AERR_RESET_MASK))
968 reset_port = 1;
969 } else
970 reset_port = 1; /* Reset in case of CQ or EQ error */
971
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100972 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973 }
974
Thomas Kleinea96cea2010-04-20 23:10:55 +0000975 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800976 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000977 ehea_schedule_port_reset(port);
978 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100979
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200980 return IRQ_HANDLED;
981}
982
983static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
984 int logical_port)
985{
986 int i;
987
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100988 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100989 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200990 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100991 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 return NULL;
993}
994
995int ehea_sense_port_attr(struct ehea_port *port)
996{
997 int ret;
998 u64 hret;
999 struct hcp_ehea_port_cb0 *cb0;
1000
Doug Maxey508d2b52008-01-31 20:20:49 -06001001 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001002 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001003 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001004 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001005 ret = -ENOMEM;
1006 goto out;
1007 }
1008
1009 hret = ehea_h_query_ehea_port(port->adapter->handle,
1010 port->logical_port_id, H_PORT_CB0,
1011 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1012 cb0);
1013 if (hret != H_SUCCESS) {
1014 ret = -EIO;
1015 goto out_free;
1016 }
1017
1018 /* MAC address */
1019 port->mac_addr = cb0->port_mac_addr << 16;
1020
Doug Maxey508d2b52008-01-31 20:20:49 -06001021 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001022 ret = -EADDRNOTAVAIL;
1023 goto out_free;
1024 }
1025
1026 /* Port speed */
1027 switch (cb0->port_speed) {
1028 case H_SPEED_10M_H:
1029 port->port_speed = EHEA_SPEED_10M;
1030 port->full_duplex = 0;
1031 break;
1032 case H_SPEED_10M_F:
1033 port->port_speed = EHEA_SPEED_10M;
1034 port->full_duplex = 1;
1035 break;
1036 case H_SPEED_100M_H:
1037 port->port_speed = EHEA_SPEED_100M;
1038 port->full_duplex = 0;
1039 break;
1040 case H_SPEED_100M_F:
1041 port->port_speed = EHEA_SPEED_100M;
1042 port->full_duplex = 1;
1043 break;
1044 case H_SPEED_1G_F:
1045 port->port_speed = EHEA_SPEED_1G;
1046 port->full_duplex = 1;
1047 break;
1048 case H_SPEED_10G_F:
1049 port->port_speed = EHEA_SPEED_10G;
1050 port->full_duplex = 1;
1051 break;
1052 default:
1053 port->port_speed = 0;
1054 port->full_duplex = 0;
1055 break;
1056 }
1057
Thomas Kleine919b592007-01-22 12:53:20 +01001058 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001059 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001060
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001061 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001062 if (use_mcs)
1063 port->num_def_qps = cb0->num_default_qps;
1064 else
1065 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001066
1067 if (!port->num_def_qps) {
1068 ret = -EINVAL;
1069 goto out_free;
1070 }
1071
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001072 ret = 0;
1073out_free:
1074 if (ret || netif_msg_probe(port))
1075 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001076 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001077out:
1078 return ret;
1079}
1080
1081int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1082{
1083 struct hcp_ehea_port_cb4 *cb4;
1084 u64 hret;
1085 int ret = 0;
1086
Thomas Klein3faf2692009-01-21 14:45:33 -08001087 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001088 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001089 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001090 ret = -ENOMEM;
1091 goto out;
1092 }
1093
1094 cb4->port_speed = port_speed;
1095
1096 netif_carrier_off(port->netdev);
1097
1098 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1099 port->logical_port_id,
1100 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1101 if (hret == H_SUCCESS) {
1102 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1103
1104 hret = ehea_h_query_ehea_port(port->adapter->handle,
1105 port->logical_port_id,
1106 H_PORT_CB4, H_PORT_CB4_SPEED,
1107 cb4);
1108 if (hret == H_SUCCESS) {
1109 switch (cb4->port_speed) {
1110 case H_SPEED_10M_H:
1111 port->port_speed = EHEA_SPEED_10M;
1112 port->full_duplex = 0;
1113 break;
1114 case H_SPEED_10M_F:
1115 port->port_speed = EHEA_SPEED_10M;
1116 port->full_duplex = 1;
1117 break;
1118 case H_SPEED_100M_H:
1119 port->port_speed = EHEA_SPEED_100M;
1120 port->full_duplex = 0;
1121 break;
1122 case H_SPEED_100M_F:
1123 port->port_speed = EHEA_SPEED_100M;
1124 port->full_duplex = 1;
1125 break;
1126 case H_SPEED_1G_F:
1127 port->port_speed = EHEA_SPEED_1G;
1128 port->full_duplex = 1;
1129 break;
1130 case H_SPEED_10G_F:
1131 port->port_speed = EHEA_SPEED_10G;
1132 port->full_duplex = 1;
1133 break;
1134 default:
1135 port->port_speed = 0;
1136 port->full_duplex = 0;
1137 break;
1138 }
1139 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001140 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 ret = -EIO;
1142 }
1143 } else {
1144 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001145 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001146 ret = -EPERM;
1147 } else {
1148 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001149 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001150 }
1151 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001152 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1153 netif_carrier_on(port->netdev);
1154
Thomas Klein3faf2692009-01-21 14:45:33 -08001155 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001156out:
1157 return ret;
1158}
1159
1160static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1161{
1162 int ret;
1163 u8 ec;
1164 u8 portnum;
1165 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001166 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001167
1168 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1169 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1170 port = ehea_get_port(adapter, portnum);
xypron.glpk@gmx.de1740c292016-05-17 22:28:54 +02001171 if (!port) {
1172 netdev_err(NULL, "unknown portnum %x\n", portnum);
1173 return;
1174 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001175 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001176
1177 switch (ec) {
1178 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1179
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001180 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001181 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001182 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001183 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001184 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185 break;
1186 }
1187
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 netif_info(port, link, dev,
1189 "Logical port up: %dMbps %s Duplex\n",
1190 port->port_speed,
1191 port->full_duplex == 1 ?
1192 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001193
Joe Perches8c4877a2010-12-13 10:05:14 -08001194 netif_carrier_on(dev);
1195 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001196 }
1197 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001198 if (netif_carrier_ok(dev)) {
1199 netif_info(port, link, dev,
1200 "Logical port down\n");
1201 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001202 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001203 }
1204
1205 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001206 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001207 netif_info(port, link, dev,
1208 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001209 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001210 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001212 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001213 netif_info(port, link, dev,
1214 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001215 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001216 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001217 }
1218
1219 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 netdev_info(dev,
1221 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001223 netdev_info(dev,
1224 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001225
1226 break;
1227 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001228 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229 break;
1230 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001231 netdev_info(dev, "Port malfunction\n");
1232 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001233 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 break;
1235 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001236 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001237 break;
1238 }
1239}
1240
1241static void ehea_neq_tasklet(unsigned long data)
1242{
Doug Maxey508d2b52008-01-31 20:20:49 -06001243 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244 struct ehea_eqe *eqe;
1245 u64 event_mask;
1246
1247 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001248 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249
1250 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001251 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001252 ehea_parse_eqe(adapter, eqe->entry);
1253 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001254 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001255 }
1256
1257 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1258 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1259 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1260
1261 ehea_h_reset_events(adapter->handle,
1262 adapter->neq->fw_handle, event_mask);
1263}
1264
David Howells7d12e782006-10-05 14:55:46 +01001265static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266{
1267 struct ehea_adapter *adapter = param;
1268 tasklet_hi_schedule(&adapter->neq_tasklet);
1269 return IRQ_HANDLED;
1270}
1271
1272
1273static int ehea_fill_port_res(struct ehea_port_res *pr)
1274{
1275 int ret;
1276 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1277
Breno Leitaof76957f2011-01-11 07:45:57 +00001278 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001279
Thomas Kleine2878802009-01-21 14:45:57 -08001280 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281
1282 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1283
1284 return ret;
1285}
1286
1287static int ehea_reg_interrupts(struct net_device *dev)
1288{
1289 struct ehea_port *port = netdev_priv(dev);
1290 struct ehea_port_res *pr;
1291 int i, ret;
1292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293
1294 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1295 dev->name);
1296
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001297 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001298 ehea_qp_aff_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001299 0, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001301 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1302 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303 goto out_free_qpeq;
1304 }
1305
Joe Perches8c4877a2010-12-13 10:05:14 -08001306 netif_info(port, ifup, dev,
1307 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1308 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001309
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001310
Anton Blanchard723f28e2011-10-14 05:31:01 +00001311 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001312 pr = &port->port_res[i];
1313 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001314 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001315 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001316 ehea_recv_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001317 0, pr->int_send_name, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001318 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001319 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1320 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001321 goto out_free_req;
1322 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001323 netif_info(port, ifup, dev,
1324 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1325 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326 }
1327out:
1328 return ret;
1329
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001331out_free_req:
1332 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001333 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001334 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001335 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001336
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001338 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001340
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001341 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001342
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001343}
1344
1345static void ehea_free_interrupts(struct net_device *dev)
1346{
1347 struct ehea_port *port = netdev_priv(dev);
1348 struct ehea_port_res *pr;
1349 int i;
1350
1351 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001352
Anton Blanchard723f28e2011-10-14 05:31:01 +00001353 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001355 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001356 netif_info(port, intr, dev,
1357 "free send irq for res %d with handle 0x%X\n",
1358 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359 }
1360
1361 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001362 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001363 netif_info(port, intr, dev,
1364 "associated event interrupt for handle 0x%X freed\n",
1365 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366}
1367
1368static int ehea_configure_port(struct ehea_port *port)
1369{
1370 int ret, i;
1371 u64 hret, mask;
1372 struct hcp_ehea_port_cb0 *cb0;
1373
1374 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001375 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376 if (!cb0)
1377 goto out;
1378
1379 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1380 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1381 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1382 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1383 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1384 PXLY_RC_VLAN_FILTER)
1385 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1386
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001387 for (i = 0; i < port->num_mcs; i++)
1388 if (use_mcs)
1389 cb0->default_qpn_arr[i] =
1390 port->port_res[i].qp->init_attr.qp_nr;
1391 else
1392 cb0->default_qpn_arr[i] =
1393 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001394
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001395 if (netif_msg_ifup(port))
1396 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1397
1398 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1399 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1400
1401 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1402 port->logical_port_id,
1403 H_PORT_CB0, mask, cb0);
1404 ret = -EIO;
1405 if (hret != H_SUCCESS)
1406 goto out_free;
1407
1408 ret = 0;
1409
1410out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001411 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412out:
1413 return ret;
1414}
1415
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001416static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001417{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001418 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419 struct ehea_adapter *adapter = pr->port->adapter;
1420
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001421 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1422 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423 goto out;
1424
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001425 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1426 if (ret)
1427 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428
1429 return 0;
1430
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001431out_free:
1432 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001433out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001434 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001435 return -EIO;
1436}
1437
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001438static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001439{
Joe Perches8e95a202009-12-03 07:58:21 +00001440 if ((ehea_rem_mr(&pr->send_mr)) ||
1441 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001442 return -EIO;
1443 else
1444 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445}
1446
1447static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1448{
Doug Maxey508d2b52008-01-31 20:20:49 -06001449 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001450
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001451 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001452 if (!q_skba->arr)
1453 return -ENOMEM;
1454
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001455 q_skba->len = max_q_entries;
1456 q_skba->index = 0;
1457 q_skba->os_skbs = 0;
1458
1459 return 0;
1460}
1461
1462static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1463 struct port_res_cfg *pr_cfg, int queue_token)
1464{
1465 struct ehea_adapter *adapter = port->adapter;
1466 enum ehea_eq_type eq_type = EHEA_EQ;
1467 struct ehea_qp_init_attr *init_attr = NULL;
1468 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001469 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1470
1471 tx_bytes = pr->tx_bytes;
1472 tx_packets = pr->tx_packets;
1473 rx_bytes = pr->rx_bytes;
1474 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475
1476 memset(pr, 0, sizeof(struct ehea_port_res));
1477
Breno Leitaoce45b872010-10-27 08:45:14 +00001478 pr->tx_bytes = rx_bytes;
1479 pr->tx_packets = tx_packets;
1480 pr->rx_bytes = rx_bytes;
1481 pr->rx_packets = rx_packets;
1482
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001485 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1486 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001487 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001488 goto out_free;
1489 }
1490
1491 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001492 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001493 port->logical_port_id);
1494 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001495 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496 goto out_free;
1497 }
1498
1499 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001500 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001501 port->logical_port_id);
1502 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001503 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001504 goto out_free;
1505 }
1506
1507 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001508 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1509 pr->send_cq->attr.act_nr_of_cqes,
1510 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511
1512 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1513 if (!init_attr) {
1514 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001515 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001516 goto out_free;
1517 }
1518
1519 init_attr->low_lat_rq1 = 1;
1520 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1521 init_attr->rq_count = 3;
1522 init_attr->qp_token = queue_token;
1523 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1524 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1525 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1526 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1527 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1528 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1529 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1530 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1531 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1532 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1533 init_attr->port_nr = port->logical_port_id;
1534 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1535 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1536 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1537
1538 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1539 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001540 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541 ret = -EIO;
1542 goto out_free;
1543 }
1544
1545 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001546 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",
1547 init_attr->qp_nr,
1548 init_attr->act_nr_send_wqes,
1549 init_attr->act_nr_rwqes_rq1,
1550 init_attr->act_nr_rwqes_rq2,
1551 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001552
Thomas Klein44fb3122008-04-04 15:04:53 +02001553 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1554
1555 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001556 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1557 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1558 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1559 if (ret)
1560 goto out_free;
1561
1562 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1563 if (ehea_gen_smrs(pr) != 0) {
1564 ret = -EIO;
1565 goto out_free;
1566 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001567
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001568 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1569
1570 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001571
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001572 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001574 ret = 0;
1575 goto out;
1576
1577out_free:
1578 kfree(init_attr);
1579 vfree(pr->sq_skba.arr);
1580 vfree(pr->rq1_skba.arr);
1581 vfree(pr->rq2_skba.arr);
1582 vfree(pr->rq3_skba.arr);
1583 ehea_destroy_qp(pr->qp);
1584 ehea_destroy_cq(pr->send_cq);
1585 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001586 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001587out:
1588 return ret;
1589}
1590
1591static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1592{
1593 int ret, i;
1594
Hannes Hering357eb462009-08-04 11:48:39 -07001595 if (pr->qp)
1596 netif_napi_del(&pr->napi);
1597
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001598 ret = ehea_destroy_qp(pr->qp);
1599
1600 if (!ret) {
1601 ehea_destroy_cq(pr->send_cq);
1602 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001603 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001604
1605 for (i = 0; i < pr->rq1_skba.len; i++)
1606 if (pr->rq1_skba.arr[i])
1607 dev_kfree_skb(pr->rq1_skba.arr[i]);
1608
1609 for (i = 0; i < pr->rq2_skba.len; i++)
1610 if (pr->rq2_skba.arr[i])
1611 dev_kfree_skb(pr->rq2_skba.arr[i]);
1612
1613 for (i = 0; i < pr->rq3_skba.len; i++)
1614 if (pr->rq3_skba.arr[i])
1615 dev_kfree_skb(pr->rq3_skba.arr[i]);
1616
1617 for (i = 0; i < pr->sq_skba.len; i++)
1618 if (pr->sq_skba.arr[i])
1619 dev_kfree_skb(pr->sq_skba.arr[i]);
1620
1621 vfree(pr->rq1_skba.arr);
1622 vfree(pr->rq2_skba.arr);
1623 vfree(pr->rq3_skba.arr);
1624 vfree(pr->sq_skba.arr);
1625 ret = ehea_rem_smrs(pr);
1626 }
1627 return ret;
1628}
1629
Anton Blanchard13946f52011-10-14 05:31:06 +00001630static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1631 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632{
Eric Dumazete743d312010-04-14 15:59:40 -07001633 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1635 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001636 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001637
Anton Blanchard13946f52011-10-14 05:31:06 +00001638 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001639
Anton Blanchard13946f52011-10-14 05:31:06 +00001640 if (skb_is_gso(skb)) {
1641 swqe->tx_control |= EHEA_SWQE_TSO;
1642 swqe->mss = skb_shinfo(skb)->gso_size;
1643 /*
1644 * For TSO packets we only copy the headers into the
1645 * immediate area.
1646 */
1647 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1648 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001649
Anton Blanchard13946f52011-10-14 05:31:06 +00001650 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1651 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1652 swqe->immediate_data_length = immediate_len;
1653
1654 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001656 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001657 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001658 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001659 swqe->descriptors++;
1660 }
1661 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001662 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001663 swqe->immediate_data_length = skb_data_size;
1664 }
1665}
1666
1667static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1668 struct ehea_swqe *swqe, u32 lkey)
1669{
1670 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1671 skb_frag_t *frag;
1672 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001673
1674 nfrags = skb_shinfo(skb)->nr_frags;
1675 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001676 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001677 sg1entry_contains_frag_data = 0;
1678
Anton Blanchard13946f52011-10-14 05:31:06 +00001679 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001680
1681 /* write descriptors */
1682 if (nfrags > 0) {
1683 if (swqe->descriptors == 0) {
1684 /* sg1entry not yet used */
1685 frag = &skb_shinfo(skb)->frags[0];
1686
1687 /* copy sg1entry data */
1688 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001689 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001690 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001691 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001692 swqe->descriptors++;
1693 sg1entry_contains_frag_data = 1;
1694 }
1695
1696 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1697
1698 frag = &skb_shinfo(skb)->frags[i];
1699 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1700
1701 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001702 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001703 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001704 swqe->descriptors++;
1705 }
1706 }
1707}
1708
1709static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1710{
1711 int ret = 0;
1712 u64 hret;
1713 u8 reg_type;
1714
1715 /* De/Register untagged packets */
1716 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1717 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1718 port->logical_port_id,
1719 reg_type, port->mac_addr, 0, hcallid);
1720 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001721 pr_err("%sregistering bc address failed (tagged)\n",
1722 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001723 ret = -EIO;
1724 goto out_herr;
1725 }
1726
1727 /* De/Register VLAN packets */
1728 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1729 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1730 port->logical_port_id,
1731 reg_type, port->mac_addr, 0, hcallid);
1732 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001733 pr_err("%sregistering bc address failed (vlan)\n",
1734 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735 ret = -EIO;
1736 }
1737out_herr:
1738 return ret;
1739}
1740
1741static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1742{
1743 struct ehea_port *port = netdev_priv(dev);
1744 struct sockaddr *mac_addr = sa;
1745 struct hcp_ehea_port_cb0 *cb0;
1746 int ret;
1747 u64 hret;
1748
1749 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1750 ret = -EADDRNOTAVAIL;
1751 goto out;
1752 }
1753
Thomas Klein3faf2692009-01-21 14:45:33 -08001754 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001755 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001756 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757 ret = -ENOMEM;
1758 goto out;
1759 }
1760
1761 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1762
1763 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1764
1765 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1766 port->logical_port_id, H_PORT_CB0,
1767 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1768 if (hret != H_SUCCESS) {
1769 ret = -EIO;
1770 goto out_free;
1771 }
1772
1773 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1774
1775 /* Deregister old 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_DEREG_BCMC);
1778 if (ret)
1779 goto out_upregs;
1780 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781
1782 port->mac_addr = cb0->port_mac_addr << 16;
1783
1784 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001785 if (port->state == EHEA_PORT_UP) {
1786 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1787 if (ret)
1788 goto out_upregs;
1789 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790
1791 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001792
1793out_upregs:
1794 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001795out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001796 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797out:
1798 return ret;
1799}
1800
1801static void ehea_promiscuous_error(u64 hret, int enable)
1802{
Thomas Klein7674a582007-01-22 12:54:20 +01001803 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001804 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1805 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001806 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001807 pr_err("failed %sabling promiscuous mode\n",
1808 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001809}
1810
1811static void ehea_promiscuous(struct net_device *dev, int enable)
1812{
1813 struct ehea_port *port = netdev_priv(dev);
1814 struct hcp_ehea_port_cb7 *cb7;
1815 u64 hret;
1816
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001817 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818 return;
1819
Thomas Klein3faf2692009-01-21 14:45:33 -08001820 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001821 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001822 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001823 goto out;
1824 }
1825
1826 /* Modify Pxs_DUCQPN in CB7 */
1827 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1828
1829 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1830 port->logical_port_id,
1831 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1832 if (hret) {
1833 ehea_promiscuous_error(hret, enable);
1834 goto out;
1835 }
1836
1837 port->promisc = enable;
1838out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001839 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001840}
1841
1842static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1843 u32 hcallid)
1844{
1845 u64 hret;
1846 u8 reg_type;
1847
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001848 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1849 if (mc_mac_addr == 0)
1850 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001851
1852 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1853 port->logical_port_id,
1854 reg_type, mc_mac_addr, 0, hcallid);
1855 if (hret)
1856 goto out;
1857
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001858 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1859 if (mc_mac_addr == 0)
1860 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001861
1862 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1863 port->logical_port_id,
1864 reg_type, mc_mac_addr, 0, hcallid);
1865out:
1866 return hret;
1867}
1868
1869static int ehea_drop_multicast_list(struct net_device *dev)
1870{
1871 struct ehea_port *port = netdev_priv(dev);
1872 struct ehea_mc_list *mc_entry = port->mc_list;
1873 struct list_head *pos;
1874 struct list_head *temp;
1875 int ret = 0;
1876 u64 hret;
1877
1878 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1879 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1880
1881 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1882 H_DEREG_BCMC);
1883 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001884 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001885 ret = -EIO;
1886 }
1887
1888 list_del(pos);
1889 kfree(mc_entry);
1890 }
1891 return ret;
1892}
1893
1894static void ehea_allmulti(struct net_device *dev, int enable)
1895{
1896 struct ehea_port *port = netdev_priv(dev);
1897 u64 hret;
1898
1899 if (!port->allmulti) {
1900 if (enable) {
1901 /* Enable ALLMULTI */
1902 ehea_drop_multicast_list(dev);
1903 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1904 if (!hret)
1905 port->allmulti = 1;
1906 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001907 netdev_err(dev,
1908 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001909 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001910 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001911 if (!enable) {
1912 /* Disable ALLMULTI */
1913 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1914 if (!hret)
1915 port->allmulti = 0;
1916 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001917 netdev_err(dev,
1918 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001920 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921}
1922
Doug Maxey508d2b52008-01-31 20:20:49 -06001923static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001924{
1925 struct ehea_mc_list *ehea_mcl_entry;
1926 u64 hret;
1927
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001928 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001929 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001930 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001931
1932 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1933
1934 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1935
1936 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1937 H_REG_BCMC);
1938 if (!hret)
1939 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1940 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001941 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942 kfree(ehea_mcl_entry);
1943 }
1944}
1945
1946static void ehea_set_multicast_list(struct net_device *dev)
1947{
1948 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001949 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001950 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001952 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001953
1954 if (dev->flags & IFF_ALLMULTI) {
1955 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001956 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 }
1958 ehea_allmulti(dev, 0);
1959
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001960 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001961 ret = ehea_drop_multicast_list(dev);
1962 if (ret) {
1963 /* Dropping the current multicast list failed.
1964 * Enabling ALL_MULTI is the best we can do.
1965 */
1966 ehea_allmulti(dev, 1);
1967 }
1968
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001969 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001970 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1971 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001972 goto out;
1973 }
1974
Jiri Pirko22bedad32010-04-01 21:22:57 +00001975 netdev_for_each_mc_addr(ha, dev)
1976 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001977
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001978 }
1979out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001980 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001981}
1982
Anton Blanchardd695c332011-10-14 05:31:05 +00001983static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1984{
1985 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1986
Vlad Yasevichbe1d1482014-08-25 10:34:51 -04001987 if (vlan_get_protocol(skb) != htons(ETH_P_IP))
Anton Blanchardd695c332011-10-14 05:31:05 +00001988 return;
1989
1990 if (skb->ip_summed == CHECKSUM_PARTIAL)
1991 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1992
1993 swqe->ip_start = skb_network_offset(skb);
1994 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1995
1996 switch (ip_hdr(skb)->protocol) {
1997 case IPPROTO_UDP:
1998 if (skb->ip_summed == CHECKSUM_PARTIAL)
1999 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2000
2001 swqe->tcp_offset = swqe->ip_end + 1 +
2002 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002003 break;
2004
2005 case IPPROTO_TCP:
2006 if (skb->ip_summed == CHECKSUM_PARTIAL)
2007 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2008
2009 swqe->tcp_offset = swqe->ip_end + 1 +
2010 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002011 break;
2012 }
2013}
2014
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002015static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2016 struct ehea_swqe *swqe, u32 lkey)
2017{
Anton Blanchardd695c332011-10-14 05:31:05 +00002018 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002019
Anton Blanchardd695c332011-10-14 05:31:05 +00002020 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002021
2022 write_swqe2_data(skb, dev, swqe, lkey);
2023}
2024
2025static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2026 struct ehea_swqe *swqe)
2027{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002028 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002029
Anton Blanchardd695c332011-10-14 05:31:05 +00002030 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002031
Anton Blanchard30e2e902011-10-14 05:31:07 +00002032 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002033 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002034 else
2035 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002036
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002037 swqe->immediate_data_length = skb->len;
Eric W. Biedermancfbe4062014-03-15 17:25:48 -07002038 dev_consume_skb_any(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002039}
2040
2041static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2042{
2043 struct ehea_port *port = netdev_priv(dev);
2044 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002045 u32 lkey;
2046 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002047 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002048 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049
Anton Blanchardb9564462011-10-14 05:30:59 +00002050 pr = &port->port_res[skb_get_queue_mapping(skb)];
2051 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002052
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2054 memset(swqe, 0, SWQE_HEADER_SIZE);
2055 atomic_dec(&pr->swqe_avail);
2056
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002057 if (skb_vlan_tag_present(skb)) {
Eric Dumazete5ccd962010-10-26 19:21:07 +00002058 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002059 swqe->vlan_tag = skb_vlan_tag_get(skb);
Eric Dumazete5ccd962010-10-26 19:21:07 +00002060 }
2061
Breno Leitaoce45b872010-10-27 08:45:14 +00002062 pr->tx_packets++;
2063 pr->tx_bytes += skb->len;
2064
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002065 if (skb->len <= SWQE3_MAX_IMM) {
2066 u32 sig_iv = port->sig_comp_iv;
2067 u32 swqe_num = pr->swqe_id_counter;
2068 ehea_xmit3(skb, dev, swqe);
2069 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2070 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2071 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2072 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2073 sig_iv);
2074 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2075 pr->swqe_ll_count = 0;
2076 } else
2077 pr->swqe_ll_count += 1;
2078 } else {
2079 swqe->wr_id =
2080 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2081 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002082 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002083 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2084 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2085
2086 pr->sq_skba.index++;
2087 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2088
2089 lkey = pr->send_mr.lkey;
2090 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002091 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002092 }
2093 pr->swqe_id_counter += 1;
2094
Joe Perches8c4877a2010-12-13 10:05:14 -08002095 netif_info(port, tx_queued, dev,
2096 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2097 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002098 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002100 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002101 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002102 swqe->tx_control |= EHEA_SWQE_PURGE;
2103 }
Thomas Klein44c82152007-07-11 16:32:00 +02002104
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002105 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002106
2107 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002108 pr->p_stats.queue_stopped++;
2109 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002111
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112 return NETDEV_TX_OK;
2113}
2114
Patrick McHardy80d5c362013-04-19 02:04:28 +00002115static int ehea_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002116{
2117 struct ehea_port *port = netdev_priv(dev);
2118 struct ehea_adapter *adapter = port->adapter;
2119 struct hcp_ehea_port_cb1 *cb1;
2120 int index;
2121 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002122 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002123
Thomas Klein3faf2692009-01-21 14:45:33 -08002124 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002125 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002126 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002127 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128 goto out;
2129 }
2130
2131 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2132 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2133 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002134 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002135 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002136 goto out;
2137 }
2138
2139 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002140 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002141
2142 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2143 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002144 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002145 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002146 err = -EINVAL;
2147 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002148out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002149 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002150 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151}
2152
Patrick McHardy80d5c362013-04-19 02:04:28 +00002153static int ehea_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002154{
2155 struct ehea_port *port = netdev_priv(dev);
2156 struct ehea_adapter *adapter = port->adapter;
2157 struct hcp_ehea_port_cb1 *cb1;
2158 int index;
2159 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002160 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002161
Thomas Klein3faf2692009-01-21 14:45:33 -08002162 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002163 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002164 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002165 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002166 goto out;
2167 }
2168
2169 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2170 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2171 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002172 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002173 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174 goto out;
2175 }
2176
2177 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002178 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002179
2180 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2181 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002182 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002183 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002184 err = -EINVAL;
2185 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002186out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002187 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002188 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189}
2190
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002191static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192{
2193 int ret = -EIO;
2194 u64 hret;
2195 u16 dummy16 = 0;
2196 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002197 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002198
Thomas Klein3faf2692009-01-21 14:45:33 -08002199 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002200 if (!cb0) {
2201 ret = -ENOMEM;
2202 goto out;
2203 }
2204
2205 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2206 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2207 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002208 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002209 goto out;
2210 }
2211
2212 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2213 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2214 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2215 &dummy64, &dummy64, &dummy16, &dummy16);
2216 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002217 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002218 goto out;
2219 }
2220
2221 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2222 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2223 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002224 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002225 goto out;
2226 }
2227
2228 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2229 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2230 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2231 &dummy64, &dummy64, &dummy16, &dummy16);
2232 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002233 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002234 goto out;
2235 }
2236
2237 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2238 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2239 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002240 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002241 goto out;
2242 }
2243
2244 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2245 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2246 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2247 &dummy64, &dummy64, &dummy16, &dummy16);
2248 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002249 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002250 goto out;
2251 }
2252
2253 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2254 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2255 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002256 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002257 goto out;
2258 }
2259
2260 ret = 0;
2261out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002262 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002263 return ret;
2264}
2265
Anton Blanchard723f28e2011-10-14 05:31:01 +00002266static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002267{
2268 int ret, i;
2269 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2270 enum ehea_eq_type eq_type = EHEA_EQ;
2271
2272 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2273 EHEA_MAX_ENTRIES_EQ, 1);
2274 if (!port->qp_eq) {
2275 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002276 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002277 goto out_kill_eq;
2278 }
2279
2280 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002281 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002282 pr_cfg.max_entries_sq = sq_entries;
2283 pr_cfg.max_entries_rq1 = rq1_entries;
2284 pr_cfg.max_entries_rq2 = rq2_entries;
2285 pr_cfg.max_entries_rq3 = rq3_entries;
2286
2287 pr_cfg_small_rx.max_entries_rcq = 1;
2288 pr_cfg_small_rx.max_entries_scq = sq_entries;
2289 pr_cfg_small_rx.max_entries_sq = sq_entries;
2290 pr_cfg_small_rx.max_entries_rq1 = 1;
2291 pr_cfg_small_rx.max_entries_rq2 = 1;
2292 pr_cfg_small_rx.max_entries_rq3 = 1;
2293
2294 for (i = 0; i < def_qps; i++) {
2295 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2296 if (ret)
2297 goto out_clean_pr;
2298 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002299 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002300 ret = ehea_init_port_res(port, &port->port_res[i],
2301 &pr_cfg_small_rx, i);
2302 if (ret)
2303 goto out_clean_pr;
2304 }
2305
2306 return 0;
2307
2308out_clean_pr:
2309 while (--i >= 0)
2310 ehea_clean_portres(port, &port->port_res[i]);
2311
2312out_kill_eq:
2313 ehea_destroy_eq(port->qp_eq);
2314 return ret;
2315}
2316
2317static int ehea_clean_all_portres(struct ehea_port *port)
2318{
2319 int ret = 0;
2320 int i;
2321
Anton Blanchard723f28e2011-10-14 05:31:01 +00002322 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002323 ret |= ehea_clean_portres(port, &port->port_res[i]);
2324
2325 ret |= ehea_destroy_eq(port->qp_eq);
2326
2327 return ret;
2328}
2329
Thomas Klein35cf2e22007-08-06 13:55:14 +02002330static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002331{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002332 if (adapter->active_ports)
2333 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002334
2335 ehea_rem_mr(&adapter->mr);
2336}
2337
Thomas Klein35cf2e22007-08-06 13:55:14 +02002338static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002339{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002340 if (adapter->active_ports)
2341 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002342
2343 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2344}
2345
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002346static int ehea_up(struct net_device *dev)
2347{
2348 int ret, i;
2349 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002350
2351 if (port->state == EHEA_PORT_UP)
2352 return 0;
2353
Anton Blanchard723f28e2011-10-14 05:31:01 +00002354 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002356 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002357 goto out;
2358 }
2359
2360 /* Set default QP for this port */
2361 ret = ehea_configure_port(port);
2362 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002363 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364 goto out_clean_pr;
2365 }
2366
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002367 ret = ehea_reg_interrupts(dev);
2368 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002369 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002370 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371 }
2372
Anton Blanchard723f28e2011-10-14 05:31:01 +00002373 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002374 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2375 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002376 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 goto out_free_irqs;
2378 }
2379 }
2380
Doug Maxey508d2b52008-01-31 20:20:49 -06002381 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382 ret = ehea_fill_port_res(&port->port_res[i]);
2383 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002384 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002385 goto out_free_irqs;
2386 }
2387 }
2388
Thomas Klein21eee2d2008-02-13 16:18:33 +01002389 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2390 if (ret) {
2391 ret = -EIO;
2392 goto out_free_irqs;
2393 }
2394
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002395 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002396
2397 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 goto out;
2399
2400out_free_irqs:
2401 ehea_free_interrupts(dev);
2402
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002403out_clean_pr:
2404 ehea_clean_all_portres(port);
2405out:
Thomas Klein44c82152007-07-11 16:32:00 +02002406 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002407 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002408
Thomas Klein21eee2d2008-02-13 16:18:33 +01002409 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002410 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002411
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002412 return ret;
2413}
2414
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002415static void port_napi_disable(struct ehea_port *port)
2416{
2417 int i;
2418
Anton Blanchard723f28e2011-10-14 05:31:01 +00002419 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002420 napi_disable(&port->port_res[i].napi);
2421}
2422
2423static void port_napi_enable(struct ehea_port *port)
2424{
2425 int i;
2426
Anton Blanchard723f28e2011-10-14 05:31:01 +00002427 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002428 napi_enable(&port->port_res[i].napi);
2429}
2430
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002431static int ehea_open(struct net_device *dev)
2432{
2433 int ret;
2434 struct ehea_port *port = netdev_priv(dev);
2435
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002436 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002437
Joe Perches8c4877a2010-12-13 10:05:14 -08002438 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002439
Guilherme G. Piccoli29ab5a32016-11-03 08:16:20 -02002440 netif_carrier_off(dev);
2441
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002442 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002443 if (!ret) {
2444 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002445 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002446 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002447
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002448 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002449 schedule_delayed_work(&port->stats_work,
2450 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002451
2452 return ret;
2453}
2454
2455static int ehea_down(struct net_device *dev)
2456{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002457 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002458 struct ehea_port *port = netdev_priv(dev);
2459
2460 if (port->state == EHEA_PORT_DOWN)
2461 return 0;
2462
2463 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002464 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002465 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2466
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002467 ehea_free_interrupts(dev);
2468
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002469 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002470
Thomas Klein21eee2d2008-02-13 16:18:33 +01002471 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002472
Thomas Klein44c82152007-07-11 16:32:00 +02002473 ret = ehea_clean_all_portres(port);
2474 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002475 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002476
Thomas Klein21eee2d2008-02-13 16:18:33 +01002477 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479 return ret;
2480}
2481
2482static int ehea_stop(struct net_device *dev)
2483{
2484 int ret;
2485 struct ehea_port *port = netdev_priv(dev);
2486
Joe Perches8c4877a2010-12-13 10:05:14 -08002487 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002488
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002489 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002490 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002491 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002492 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002493 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002494 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002495 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002496 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002497 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002498 return ret;
2499}
2500
Andrew Morton22559c52008-04-18 13:50:39 -07002501static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002502{
2503 struct ehea_qp qp = *orig_qp;
2504 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2505 struct ehea_swqe *swqe;
2506 int wqe_index;
2507 int i;
2508
2509 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2510 swqe = ehea_get_swqe(&qp, &wqe_index);
2511 swqe->tx_control |= EHEA_SWQE_PURGE;
2512 }
2513}
2514
Andrew Morton22559c52008-04-18 13:50:39 -07002515static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002516{
2517 int i;
2518
Anton Blanchard723f28e2011-10-14 05:31:01 +00002519 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002520 struct ehea_port_res *pr = &port->port_res[i];
2521 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002522 int ret;
2523
2524 ret = wait_event_timeout(port->swqe_avail_wq,
2525 atomic_read(&pr->swqe_avail) >= swqe_max,
2526 msecs_to_jiffies(100));
2527
2528 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002529 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002530 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002531 }
2532 }
2533}
2534
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002535static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002536{
2537 struct ehea_port *port = netdev_priv(dev);
2538 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002539 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002540 int ret = -EIO;
2541 int dret;
2542 int i;
2543 u64 hret;
2544 u64 dummy64 = 0;
2545 u16 dummy16 = 0;
2546
Thomas Klein3faf2692009-01-21 14:45:33 -08002547 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002548 if (!cb0) {
2549 ret = -ENOMEM;
2550 goto out;
2551 }
2552
Anton Blanchard723f28e2011-10-14 05:31:01 +00002553 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002554 struct ehea_port_res *pr = &port->port_res[i];
2555 struct ehea_qp *qp = pr->qp;
2556
2557 /* Purge send queue */
2558 ehea_purge_sq(qp);
2559
2560 /* Disable queue pair */
2561 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2562 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2563 cb0);
2564 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002565 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002566 goto out;
2567 }
2568
2569 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2570 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2571
2572 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2573 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2574 1), cb0, &dummy64,
2575 &dummy64, &dummy16, &dummy16);
2576 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002577 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002578 goto out;
2579 }
2580
2581 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2582 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2583 cb0);
2584 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002585 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002586 goto out;
2587 }
2588
2589 /* deregister shared memory regions */
2590 dret = ehea_rem_smrs(pr);
2591 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002592 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002593 goto out;
2594 }
2595 }
2596
2597 ret = 0;
2598out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002599 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002600
2601 return ret;
2602}
2603
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002604static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002605{
2606 struct ehea_qp qp = *orig_qp;
2607 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2608 struct ehea_rwqe *rwqe;
2609 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2610 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2611 struct sk_buff *skb;
2612 u32 lkey = pr->recv_mr.lkey;
2613
2614
2615 int i;
2616 int index;
2617
2618 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2619 rwqe = ehea_get_next_rwqe(&qp, 2);
2620 rwqe->sg_list[0].l_key = lkey;
2621 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2622 skb = skba_rq2[index];
2623 if (skb)
2624 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2625 }
2626
2627 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2628 rwqe = ehea_get_next_rwqe(&qp, 3);
2629 rwqe->sg_list[0].l_key = lkey;
2630 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2631 skb = skba_rq3[index];
2632 if (skb)
2633 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2634 }
2635}
2636
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002637static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002638{
2639 struct ehea_port *port = netdev_priv(dev);
2640 struct ehea_adapter *adapter = port->adapter;
2641 int ret = 0;
2642 int i;
2643
Doug Maxey508d2b52008-01-31 20:20:49 -06002644 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002645 u64 hret;
2646 u64 dummy64 = 0;
2647 u16 dummy16 = 0;
2648
Thomas Klein3faf2692009-01-21 14:45:33 -08002649 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002650 if (!cb0) {
2651 ret = -ENOMEM;
2652 goto out;
2653 }
2654
Anton Blanchard723f28e2011-10-14 05:31:01 +00002655 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002656 struct ehea_port_res *pr = &port->port_res[i];
2657 struct ehea_qp *qp = pr->qp;
2658
2659 ret = ehea_gen_smrs(pr);
2660 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002661 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002662 goto out;
2663 }
2664
2665 ehea_update_rqs(qp, pr);
2666
2667 /* Enable queue pair */
2668 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2669 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2670 cb0);
2671 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002672 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002673 goto out;
2674 }
2675
2676 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2677 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2678
2679 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2680 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2681 1), cb0, &dummy64,
2682 &dummy64, &dummy16, &dummy16);
2683 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002684 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002685 goto out;
2686 }
2687
2688 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2689 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2690 cb0);
2691 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002692 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002693 goto out;
2694 }
2695
2696 /* refill entire queue */
2697 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2698 ehea_refill_rq2(pr, 0);
2699 ehea_refill_rq3(pr, 0);
2700 }
2701out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002702 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002703
2704 return ret;
2705}
2706
David Howellsc4028952006-11-22 14:57:56 +00002707static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002708{
2709 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002710 struct ehea_port *port =
2711 container_of(work, struct ehea_port, reset_task);
2712 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002713
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002714 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002715 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002716 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002717 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002718
2719 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002720
Thomas Klein44c82152007-07-11 16:32:00 +02002721 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002722
2723 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002724 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002725 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002727 ehea_set_multicast_list(dev);
2728
Joe Perches8c4877a2010-12-13 10:05:14 -08002729 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002730
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002731 port_napi_enable(port);
2732
Anton Blanchardb9564462011-10-14 05:30:59 +00002733 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002734out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002735 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002736 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002737}
2738
Tejun Heo3d6b8922010-12-12 16:45:14 +01002739static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002740{
2741 int ret, i;
2742 struct ehea_adapter *adapter;
2743
Joe Perches8c4877a2010-12-13 10:05:14 -08002744 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002745
2746 list_for_each_entry(adapter, &adapter_list, list)
2747 if (adapter->active_ports) {
2748 /* Shutdown all ports */
2749 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2750 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002751 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002752
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002753 if (!port)
2754 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002755
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002756 dev = port->netdev;
2757
2758 if (dev->flags & IFF_UP) {
2759 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002760 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002761 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002762 ret = ehea_stop_qps(dev);
2763 if (ret) {
2764 mutex_unlock(&port->port_lock);
2765 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002766 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002767 port_napi_disable(port);
2768 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002769 }
Andre Detsch2928db42010-08-17 05:49:12 +00002770 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002771 }
2772
2773 /* Unregister old memory region */
2774 ret = ehea_rem_mr(&adapter->mr);
2775 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002776 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002777 goto out;
2778 }
2779 }
2780
Thomas Klein44c82152007-07-11 16:32:00 +02002781 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2782
2783 list_for_each_entry(adapter, &adapter_list, list)
2784 if (adapter->active_ports) {
2785 /* Register new memory region */
2786 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2787 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002788 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002789 goto out;
2790 }
2791
2792 /* Restart all ports */
2793 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2794 struct ehea_port *port = adapter->port[i];
2795
2796 if (port) {
2797 struct net_device *dev = port->netdev;
2798
2799 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002800 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002801 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002802 if (!ret) {
2803 check_sqs(port);
2804 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002805 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002806 } else {
2807 netdev_err(dev, "Unable to restart QPS\n");
2808 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002809 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002810 }
2811 }
2812 }
2813 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002814 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002815out:
2816 return;
2817}
2818
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002819static void ehea_tx_watchdog(struct net_device *dev)
2820{
2821 struct ehea_port *port = netdev_priv(dev);
2822
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002823 if (netif_carrier_ok(dev) &&
2824 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002825 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002826}
2827
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002828static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002829{
2830 struct hcp_query_ehea *cb;
2831 u64 hret;
2832 int ret;
2833
Thomas Klein3faf2692009-01-21 14:45:33 -08002834 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002835 if (!cb) {
2836 ret = -ENOMEM;
2837 goto out;
2838 }
2839
2840 hret = ehea_h_query_ehea(adapter->handle, cb);
2841
2842 if (hret != H_SUCCESS) {
2843 ret = -EIO;
2844 goto out_herr;
2845 }
2846
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002847 adapter->max_mc_mac = cb->max_mc_mac - 1;
2848 ret = 0;
2849
2850out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002851 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002852out:
2853 return ret;
2854}
2855
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002856static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002857{
2858 struct hcp_ehea_port_cb4 *cb4;
2859 u64 hret;
2860 int ret = 0;
2861
2862 *jumbo = 0;
2863
2864 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002865 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002866 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002867 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002868 ret = -ENOMEM;
2869 goto out;
2870 } else {
2871 hret = ehea_h_query_ehea_port(port->adapter->handle,
2872 port->logical_port_id,
2873 H_PORT_CB4,
2874 H_PORT_CB4_JUMBO, cb4);
2875 if (hret == H_SUCCESS) {
2876 if (cb4->jumbo_frame)
2877 *jumbo = 1;
2878 else {
2879 cb4->jumbo_frame = 1;
2880 hret = ehea_h_modify_ehea_port(port->adapter->
2881 handle,
2882 port->
2883 logical_port_id,
2884 H_PORT_CB4,
2885 H_PORT_CB4_JUMBO,
2886 cb4);
2887 if (hret == H_SUCCESS)
2888 *jumbo = 1;
2889 }
2890 } else
2891 ret = -EINVAL;
2892
Thomas Klein3faf2692009-01-21 14:45:33 -08002893 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002894 }
2895out:
2896 return ret;
2897}
2898
2899static ssize_t ehea_show_port_id(struct device *dev,
2900 struct device_attribute *attr, char *buf)
2901{
2902 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002903 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002904}
2905
2906static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2907 NULL);
2908
Bill Pemberton0297be02012-12-03 09:23:10 -05002909static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002910{
2911 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002912 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002913}
2914
2915static struct device *ehea_register_port(struct ehea_port *port,
2916 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002917{
2918 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002919
Grant Likely61c7a082010-04-13 16:12:29 -07002920 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002921 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002922 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002923
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002924 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002925 port->ofdev.dev.release = logical_port_release;
2926
2927 ret = of_device_register(&port->ofdev);
2928 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002929 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002930 goto out;
2931 }
2932
2933 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002934 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002935 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002936 goto out_unreg_of_dev;
2937 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002938
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002939 return &port->ofdev.dev;
2940
2941out_unreg_of_dev:
2942 of_device_unregister(&port->ofdev);
2943out:
2944 return NULL;
2945}
2946
2947static void ehea_unregister_port(struct ehea_port *port)
2948{
2949 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2950 of_device_unregister(&port->ofdev);
2951}
2952
Thomas Klein086c1b22009-01-21 14:43:59 -08002953static const struct net_device_ops ehea_netdev_ops = {
2954 .ndo_open = ehea_open,
2955 .ndo_stop = ehea_stop,
2956 .ndo_start_xmit = ehea_start_xmit,
2957#ifdef CONFIG_NET_POLL_CONTROLLER
2958 .ndo_poll_controller = ehea_netpoll,
2959#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002960 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002961 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002962 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002963 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002964 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002965 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2966 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002967};
2968
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002969static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002970 u32 logical_port_id,
2971 struct device_node *dn)
2972{
2973 int ret;
2974 struct net_device *dev;
2975 struct ehea_port *port;
2976 struct device *port_dev;
2977 int jumbo;
2978
2979 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002980 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002981
2982 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983 ret = -ENOMEM;
2984 goto out_err;
2985 }
2986
2987 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002988
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002989 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002990 port->state = EHEA_PORT_DOWN;
2991 port->sig_comp_iv = sq_entries / 10;
2992
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002993 port->adapter = adapter;
2994 port->netdev = dev;
2995 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002996
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002997 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002998
2999 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3000 if (!port->mc_list) {
3001 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003002 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003003 }
3004
3005 INIT_LIST_HEAD(&port->mc_list->list);
3006
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003007 ret = ehea_sense_port_attr(port);
3008 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003009 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003010
Anton Blanchardb9564462011-10-14 05:30:59 +00003011 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003012 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003013
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003014 port_dev = ehea_register_port(port, dn);
3015 if (!port_dev)
3016 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003017
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003018 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003019
3020 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003021 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3022
Thomas Klein086c1b22009-01-21 14:43:59 -08003023 dev->netdev_ops = &ehea_netdev_ops;
3024 ehea_set_ethtool_ops(dev);
3025
David S. Miller55fbbe42013-04-22 19:34:34 -04003026 dev->hw_features = NETIF_F_SG | NETIF_F_TSO |
3027 NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_CTAG_TX;
Eric Dumazet28e24c62013-12-02 08:51:13 -08003028 dev->features = NETIF_F_SG | NETIF_F_TSO |
David S. Miller55fbbe42013-04-22 19:34:34 -04003029 NETIF_F_HIGHDMA | NETIF_F_IP_CSUM |
3030 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
3031 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003032 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3033 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003034 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3035
Jarod Wilson3d5d96a2016-10-17 15:54:14 -04003036 /* MTU range: 68 - 9022 */
3037 dev->min_mtu = ETH_MIN_MTU;
3038 dev->max_mtu = EHEA_MAX_PACKET_SIZE;
3039
David Howellsc4028952006-11-22 14:57:56 +00003040 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003041 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003042
Anton Blanchard21ccc792011-05-10 16:17:10 +00003043 init_waitqueue_head(&port->swqe_avail_wq);
3044 init_waitqueue_head(&port->restart_wq);
3045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003046 ret = register_netdev(dev);
3047 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003048 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003049 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003050 }
3051
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003052 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003053 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003054 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055
Joe Perches8c4877a2010-12-13 10:05:14 -08003056 netdev_info(dev, "Jumbo frames are %sabled\n",
3057 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003058
Thomas Klein44c82152007-07-11 16:32:00 +02003059 adapter->active_ports++;
3060
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003061 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003062
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003063out_unreg_port:
3064 ehea_unregister_port(port);
3065
3066out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003067 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003068
3069out_free_ethdev:
3070 free_netdev(dev);
3071
3072out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003073 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3074 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003075 return NULL;
3076}
3077
3078static void ehea_shutdown_single_port(struct ehea_port *port)
3079{
Brian King7fb1c2a2008-05-14 09:48:25 -05003080 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003081
3082 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003083 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003084 unregister_netdev(port->netdev);
3085 ehea_unregister_port(port);
3086 kfree(port->mc_list);
3087 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003088 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003089}
3090
3091static int ehea_setup_ports(struct ehea_adapter *adapter)
3092{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003093 struct device_node *lhea_dn;
3094 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003095
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003096 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003097 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003098
Grant Likely61c7a082010-04-13 16:12:29 -07003099 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003100 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003101
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003102 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003103 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003104 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003105 pr_err("bad device node: eth_dn name=%s\n",
3106 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003107 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003108 }
3109
Thomas Klein1211bb62007-04-26 11:56:43 +02003110 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003111 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003112 of_node_put(eth_dn);
3113 return -EIO;
3114 }
3115
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116 adapter->port[i] = ehea_setup_single_port(adapter,
3117 *dn_log_port_id,
3118 eth_dn);
3119 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003120 netdev_info(adapter->port[i]->netdev,
3121 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003122 else
3123 ehea_remove_adapter_mr(adapter);
3124
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003125 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003126 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003127 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003128}
3129
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003130static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3131 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003132{
3133 struct device_node *lhea_dn;
3134 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003135 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003136
Grant Likely61c7a082010-04-13 16:12:29 -07003137 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003138 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003139
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003140 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003141 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003142 if (dn_log_port_id)
3143 if (*dn_log_port_id == logical_port_id)
3144 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003145 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003146
3147 return NULL;
3148}
3149
3150static ssize_t ehea_probe_port(struct device *dev,
3151 struct device_attribute *attr,
3152 const char *buf, size_t count)
3153{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003154 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003155 struct ehea_port *port;
3156 struct device_node *eth_dn = NULL;
3157 int i;
3158
3159 u32 logical_port_id;
3160
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003161 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162
3163 port = ehea_get_port(adapter, logical_port_id);
3164
3165 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003166 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3167 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 return -EINVAL;
3169 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003170
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3172
3173 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003174 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003175 return -EINVAL;
3176 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003177
Thomas Klein1211bb62007-04-26 11:56:43 +02003178 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003179 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003180 return -EIO;
3181 }
3182
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3184
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003185 of_node_put(eth_dn);
3186
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003187 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003188 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003189 if (!adapter->port[i]) {
3190 adapter->port[i] = port;
3191 break;
3192 }
3193
Joe Perches8c4877a2010-12-13 10:05:14 -08003194 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3195 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003196 } else {
3197 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003198 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003199 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003200
3201 return (ssize_t) count;
3202}
3203
3204static ssize_t ehea_remove_port(struct device *dev,
3205 struct device_attribute *attr,
3206 const char *buf, size_t count)
3207{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003208 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003209 struct ehea_port *port;
3210 int i;
3211 u32 logical_port_id;
3212
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003213 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003214
3215 port = ehea_get_port(adapter, logical_port_id);
3216
3217 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003218 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3219 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003220
3221 ehea_shutdown_single_port(port);
3222
Doug Maxey508d2b52008-01-31 20:20:49 -06003223 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003224 if (adapter->port[i] == port) {
3225 adapter->port[i] = NULL;
3226 break;
3227 }
3228 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003229 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3230 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231 return -EINVAL;
3232 }
3233
Thomas Klein1211bb62007-04-26 11:56:43 +02003234 ehea_remove_adapter_mr(adapter);
3235
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003236 return (ssize_t) count;
3237}
3238
3239static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3240static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3241
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003242static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003244 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003245 if (ret)
3246 goto out;
3247
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003248 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250 return ret;
3251}
3252
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003253static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003254{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003255 device_remove_file(&dev->dev, &dev_attr_probe_port);
3256 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003257}
3258
Anton Blanchardaa183322015-02-15 17:44:20 -02003259static int ehea_reboot_notifier(struct notifier_block *nb,
3260 unsigned long action, void *unused)
3261{
3262 if (action == SYS_RESTART) {
3263 pr_info("Reboot: freeing all eHEA resources\n");
3264 ibmebus_unregister_driver(&ehea_driver);
3265 }
3266 return NOTIFY_DONE;
3267}
3268
3269static struct notifier_block ehea_reboot_nb = {
3270 .notifier_call = ehea_reboot_notifier,
3271};
3272
3273static int ehea_mem_notifier(struct notifier_block *nb,
3274 unsigned long action, void *data)
3275{
3276 int ret = NOTIFY_BAD;
3277 struct memory_notify *arg = data;
3278
3279 mutex_lock(&dlpar_mem_lock);
3280
3281 switch (action) {
3282 case MEM_CANCEL_OFFLINE:
3283 pr_info("memory offlining canceled");
3284 /* Fall through: re-add canceled memory block */
3285
3286 case MEM_ONLINE:
3287 pr_info("memory is going online");
3288 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3289 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3290 goto out_unlock;
3291 ehea_rereg_mrs();
3292 break;
3293
3294 case MEM_GOING_OFFLINE:
3295 pr_info("memory is going offline");
3296 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3297 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3298 goto out_unlock;
3299 ehea_rereg_mrs();
3300 break;
3301
3302 default:
3303 break;
3304 }
3305
3306 ehea_update_firmware_handles();
3307 ret = NOTIFY_OK;
3308
3309out_unlock:
3310 mutex_unlock(&dlpar_mem_lock);
3311 return ret;
3312}
3313
3314static struct notifier_block ehea_mem_nb = {
3315 .notifier_call = ehea_mem_notifier,
3316};
3317
3318static void ehea_crash_handler(void)
3319{
3320 int i;
3321
3322 if (ehea_fw_handles.arr)
3323 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3324 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3325 ehea_fw_handles.arr[i].fwh,
3326 FORCE_FREE);
3327
3328 if (ehea_bcmc_regs.arr)
3329 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3330 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3331 ehea_bcmc_regs.arr[i].port_id,
3332 ehea_bcmc_regs.arr[i].reg_type,
3333 ehea_bcmc_regs.arr[i].macaddr,
3334 0, H_DEREG_BCMC);
3335}
3336
3337static atomic_t ehea_memory_hooks_registered;
3338
3339/* Register memory hooks on probe of first adapter */
3340static int ehea_register_memory_hooks(void)
3341{
3342 int ret = 0;
3343
Michael Ellerman3051f392015-04-24 15:52:32 +10003344 if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
Anton Blanchardaa183322015-02-15 17:44:20 -02003345 return 0;
3346
3347 ret = ehea_create_busmap();
3348 if (ret) {
3349 pr_info("ehea_create_busmap failed\n");
3350 goto out;
3351 }
3352
3353 ret = register_reboot_notifier(&ehea_reboot_nb);
3354 if (ret) {
3355 pr_info("register_reboot_notifier failed\n");
3356 goto out;
3357 }
3358
3359 ret = register_memory_notifier(&ehea_mem_nb);
3360 if (ret) {
3361 pr_info("register_memory_notifier failed\n");
3362 goto out2;
3363 }
3364
3365 ret = crash_shutdown_register(ehea_crash_handler);
3366 if (ret) {
3367 pr_info("crash_shutdown_register failed\n");
3368 goto out3;
3369 }
3370
3371 return 0;
3372
3373out3:
3374 unregister_memory_notifier(&ehea_mem_nb);
3375out2:
3376 unregister_reboot_notifier(&ehea_reboot_nb);
3377out:
Michael Ellerman3051f392015-04-24 15:52:32 +10003378 atomic_dec(&ehea_memory_hooks_registered);
Anton Blanchardaa183322015-02-15 17:44:20 -02003379 return ret;
3380}
3381
3382static void ehea_unregister_memory_hooks(void)
3383{
Michael Ellerman3051f392015-04-24 15:52:32 +10003384 /* Only remove the hooks if we've registered them */
3385 if (atomic_read(&ehea_memory_hooks_registered) == 0)
Anton Blanchardaa183322015-02-15 17:44:20 -02003386 return;
3387
3388 unregister_reboot_notifier(&ehea_reboot_nb);
3389 if (crash_shutdown_unregister(ehea_crash_handler))
3390 pr_info("failed unregistering crash handler\n");
3391 unregister_memory_notifier(&ehea_mem_nb);
3392}
3393
Rob Herringc45640e2013-04-20 21:51:08 -05003394static int ehea_probe_adapter(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003395{
3396 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003397 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003398 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003399 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003400
Anton Blanchardaa183322015-02-15 17:44:20 -02003401 ret = ehea_register_memory_hooks();
3402 if (ret)
3403 return ret;
3404
Grant Likely61c7a082010-04-13 16:12:29 -07003405 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003406 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003407 return -EINVAL;
3408 }
3409
Himangi Saraogi09b38aa2014-05-28 19:53:09 +05303410 adapter = devm_kzalloc(&dev->dev, sizeof(*adapter), GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003411 if (!adapter) {
3412 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003413 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003414 goto out;
3415 }
3416
Thomas Klein44c82152007-07-11 16:32:00 +02003417 list_add(&adapter->list, &adapter_list);
3418
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003419 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003420
Grant Likely61c7a082010-04-13 16:12:29 -07003421 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003422 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003423 if (adapter_handle)
3424 adapter->handle = *adapter_handle;
3425
3426 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003427 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003428 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003429 ret = -ENODEV;
3430 goto out_free_ad;
3431 }
3432
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003433 adapter->pd = EHEA_PD_ID;
3434
Jingoo Han8513fbd2013-05-23 00:52:31 +00003435 platform_set_drvdata(dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003436
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003437
3438 /* initialize adapter and ports */
3439 /* get adapter properties */
3440 ret = ehea_sense_adapter_attr(adapter);
3441 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003442 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003443 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003444 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003445
3446 adapter->neq = ehea_create_eq(adapter,
3447 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3448 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003449 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003450 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003451 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003452 }
3453
3454 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3455 (unsigned long)adapter);
3456
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003457 ret = ehea_create_device_sysfs(dev);
3458 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003459 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003460
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003461 ret = ehea_setup_ports(adapter);
3462 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003463 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003464 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003465 }
3466
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003467 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02003468 ehea_interrupt_neq, 0,
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003469 "ehea_neq", adapter);
3470 if (ret) {
3471 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3472 goto out_shutdown_ports;
3473 }
3474
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003475 /* Handle any events that might be pending. */
3476 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003477
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003478 ret = 0;
3479 goto out;
3480
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003481out_shutdown_ports:
3482 for (i = 0; i < EHEA_MAX_PORTS; i++)
3483 if (adapter->port[i]) {
3484 ehea_shutdown_single_port(adapter->port[i]);
3485 adapter->port[i] = NULL;
3486 }
3487
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003488out_rem_dev_sysfs:
3489 ehea_remove_device_sysfs(dev);
3490
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491out_kill_eq:
3492 ehea_destroy_eq(adapter->neq);
3493
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003495 list_del(&adapter->list);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003496
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003497out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003498 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003500 return ret;
3501}
3502
Bill Pemberton0297be02012-12-03 09:23:10 -05003503static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504{
Jingoo Han8513fbd2013-05-23 00:52:31 +00003505 struct ehea_adapter *adapter = platform_get_drvdata(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 int i;
3507
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003508 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003509 if (adapter->port[i]) {
3510 ehea_shutdown_single_port(adapter->port[i]);
3511 adapter->port[i] = NULL;
3512 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003513
3514 ehea_remove_device_sysfs(dev);
3515
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003516 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003517 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003518
3519 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003520 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003521 list_del(&adapter->list);
Thomas Klein44c82152007-07-11 16:32:00 +02003522
Thomas Klein21eee2d2008-02-13 16:18:33 +01003523 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003524
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003525 return 0;
3526}
3527
3528static int check_module_parm(void)
3529{
3530 int ret = 0;
3531
3532 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3533 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003534 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535 ret = -EINVAL;
3536 }
3537 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3538 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003539 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540 ret = -EINVAL;
3541 }
3542 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3543 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003544 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003545 ret = -EINVAL;
3546 }
3547 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3548 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003549 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550 ret = -EINVAL;
3551 }
3552
3553 return ret;
3554}
3555
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003556static ssize_t ehea_show_capabilities(struct device_driver *drv,
3557 char *buf)
3558{
3559 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3560}
3561
3562static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3563 ehea_show_capabilities, NULL);
3564
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003565static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003566{
3567 int ret;
3568
Joe Perches8c4877a2010-12-13 10:05:14 -08003569 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570
Thomas Klein21eee2d2008-02-13 16:18:33 +01003571 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3572 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3573
Daniel Walker9f71a562008-03-28 14:41:26 -07003574 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003575 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003576
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577 ret = check_module_parm();
3578 if (ret)
3579 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003580
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003582 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003583 pr_err("failed registering eHEA device driver on ebus\n");
Anton Blanchardaa183322015-02-15 17:44:20 -02003584 goto out;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003585 }
3586
3587 ret = driver_create_file(&ehea_driver.driver,
3588 &driver_attr_capabilities);
3589 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003590 pr_err("failed to register capabilities attribute, ret=%d\n",
3591 ret);
Anton Blanchardaa183322015-02-15 17:44:20 -02003592 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003593 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003594
Thomas Klein21eee2d2008-02-13 16:18:33 +01003595 return ret;
3596
Thomas Klein21eee2d2008-02-13 16:18:33 +01003597out2:
Anton Blanchardaa183322015-02-15 17:44:20 -02003598 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003599out:
3600 return ret;
3601}
3602
3603static void __exit ehea_module_exit(void)
3604{
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003605 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003606 ibmebus_unregister_driver(&ehea_driver);
Anton Blanchardaa183322015-02-15 17:44:20 -02003607 ehea_unregister_memory_hooks();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003608 kfree(ehea_fw_handles.arr);
3609 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003610 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003611}
3612
3613module_init(ehea_module_init);
3614module_exit(ehea_module_exit);