blob: 702446a93697a42a94cae938ac303d58350461cf [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
Anton Blanchard239c5622011-10-14 05:31:09 +0000331static struct rtnl_link_stats64 *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;
355 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000356}
357
358static void ehea_update_stats(struct work_struct *work)
359{
360 struct ehea_port *port =
361 container_of(work, struct ehea_port, stats_work.work);
362 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000363 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000364 struct hcp_ehea_port_cb2 *cb2;
365 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366
Brian King3d8009c2010-06-30 11:59:12 +0000367 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000369 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
370 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200371 }
372
373 hret = ehea_h_query_ehea_port(port->adapter->handle,
374 port->logical_port_id,
375 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
376 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800377 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200378 goto out_herr;
379 }
380
381 if (netif_msg_hw(port))
382 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
383
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200384 stats->multicast = cb2->rxmcp;
385 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200386
387out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800388 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000389resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000390 schedule_delayed_work(&port->stats_work,
391 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392}
393
394static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
395{
396 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
397 struct net_device *dev = pr->port->netdev;
398 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200399 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
400 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 int i;
402
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200403 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200404
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200406 if (nr_of_wqes > 0)
407 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200408 pr->rq1_skba.os_skbs = fill_wqes;
409 return;
410 }
411
412 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 if (!skb_arr_rq1[index]) {
414 skb_arr_rq1[index] = netdev_alloc_skb(dev,
415 EHEA_L_PKT_SIZE);
416 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200417 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418 break;
419 }
420 }
421 index--;
422 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200423 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200425
426 if (adder == 0)
427 return;
428
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200430 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431}
432
Thomas Kleine2878802009-01-21 14:45:57 -0800433static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200435 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
436 struct net_device *dev = pr->port->netdev;
437 int i;
438
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000439 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800440 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000441 return;
442 }
443
444 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200445 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000446 if (!skb_arr_rq1[i])
Thomas Kleine2878802009-01-21 14:45:57 -0800447 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200448 }
449 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000450 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451}
452
453static int ehea_refill_rq_def(struct ehea_port_res *pr,
454 struct ehea_q_skb_arr *q_skba, int rq_nr,
455 int num_wqes, int wqe_type, int packet_size)
456{
457 struct net_device *dev = pr->port->netdev;
458 struct ehea_qp *qp = pr->qp;
459 struct sk_buff **skb_arr = q_skba->arr;
460 struct ehea_rwqe *rwqe;
461 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463 int ret = 0;
464
465 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200466 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200467
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
469 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200471 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472
473 index = q_skba->index;
474 max_index_mask = q_skba->len - 1;
475 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200476 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000477 struct sk_buff *skb;
478
479 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200480 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800482 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800483 netdev_info(pr->port->netdev,
484 "rq%i ran dry - no mem for skb\n",
485 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800486 ret = -ENOMEM;
487 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200488 break;
489 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490
491 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 tmp_addr = ehea_map_vaddr(skb->data);
493 if (tmp_addr == -1) {
Eric W. Biedermancfbe4062014-03-15 17:25:48 -0700494 dev_consume_skb_any(skb);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200495 q_skba->os_skbs = fill_wqes - i;
496 ret = 0;
497 break;
498 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499
500 rwqe = ehea_get_next_rwqe(qp, rq_nr);
501 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200502 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200504 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200505 rwqe->sg_list[0].len = packet_size;
506 rwqe->data_segments = 1;
507
508 index++;
509 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511 }
Thomas Klein44c82152007-07-11 16:32:00 +0200512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200513 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200514 if (adder == 0)
515 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200516
517 /* Ring doorbell */
518 iosync();
519 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200520 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200522 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200523out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524 return ret;
525}
526
527
528static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
529{
530 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
531 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000532 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200533}
534
535
536static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
537{
538 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
539 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000540 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200541}
542
543static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
544{
545 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
546 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
547 return 0;
548 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
549 (cqe->header_length == 0))
550 return 0;
551 return -EINVAL;
552}
553
554static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000555 struct sk_buff *skb, struct ehea_cqe *cqe,
556 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200557{
558 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
559
560 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200561 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000562
563 /* The packet was not an IPV4 packet so a complemented checksum was
564 calculated. The value is found in the Internet Checksum field. */
565 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
566 skb->ip_summed = CHECKSUM_COMPLETE;
567 skb->csum = csum_unfold(~cqe->inet_checksum_value);
568 } else
569 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000570
571 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200572}
573
574static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
575 int arr_len,
576 struct ehea_cqe *cqe)
577{
578 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
579 struct sk_buff *skb;
580 void *pref;
581 int x;
582
583 x = skb_index + 1;
584 x &= (arr_len - 1);
585
586 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700587 if (pref) {
588 prefetchw(pref);
589 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200590
Hannes Hering0b2febf2009-05-04 11:06:37 -0700591 pref = (skb_array[x]->data);
592 prefetch(pref);
593 prefetch(pref + EHEA_CACHE_LINE);
594 prefetch(pref + EHEA_CACHE_LINE * 2);
595 prefetch(pref + EHEA_CACHE_LINE * 3);
596 }
597
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200598 skb = skb_array[skb_index];
599 skb_array[skb_index] = NULL;
600 return skb;
601}
602
603static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
604 int arr_len, int wqe_index)
605{
606 struct sk_buff *skb;
607 void *pref;
608 int x;
609
610 x = wqe_index + 1;
611 x &= (arr_len - 1);
612
613 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700614 if (pref) {
615 prefetchw(pref);
616 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200617
Hannes Hering0b2febf2009-05-04 11:06:37 -0700618 pref = (skb_array[x]->data);
619 prefetchw(pref);
620 prefetchw(pref + EHEA_CACHE_LINE);
621 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200622
623 skb = skb_array[wqe_index];
624 skb_array[wqe_index] = NULL;
625 return skb;
626}
627
628static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
629 struct ehea_cqe *cqe, int *processed_rq2,
630 int *processed_rq3)
631{
632 struct sk_buff *skb;
633
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100634 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
635 pr->p_stats.err_tcp_cksum++;
636 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
637 pr->p_stats.err_ip_cksum++;
638 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
639 pr->p_stats.err_frame_crc++;
640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200641 if (rq == 2) {
642 *processed_rq2 += 1;
643 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
644 dev_kfree_skb(skb);
645 } else if (rq == 3) {
646 *processed_rq3 += 1;
647 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
648 dev_kfree_skb(skb);
649 }
650
651 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100652 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800653 pr_err("Critical receive error for QP %d. Resetting port.\n",
654 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100655 ehea_dump(cqe, sizeof(*cqe), "CQE");
656 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100657 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200658 return 1;
659 }
660
661 return 0;
662}
663
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700664static int ehea_proc_rwqes(struct net_device *dev,
665 struct ehea_port_res *pr,
666 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200667{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100668 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200669 struct ehea_qp *qp = pr->qp;
670 struct ehea_cqe *cqe;
671 struct sk_buff *skb;
672 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
673 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
674 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
675 int skb_arr_rq1_len = pr->rq1_skba.len;
676 int skb_arr_rq2_len = pr->rq2_skba.len;
677 int skb_arr_rq3_len = pr->rq3_skba.len;
678 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000679 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700680 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200681
682 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
683 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200684
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200685 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700686 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200687 ehea_inc_rq1(qp);
688 processed_rq1++;
689 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200690 if (netif_msg_rx_status(port))
691 ehea_dump(cqe, sizeof(*cqe), "CQE");
692
693 last_wqe_index = wqe_index;
694 rmb();
695 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600696 if (rq == 1) {
697 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698 skb = get_skb_by_index_ll(skb_arr_rq1,
699 skb_arr_rq1_len,
700 wqe_index);
701 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800702 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800703 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100704
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700705 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706 EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000707 if (!skb)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 break;
709 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600710 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200711 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000712 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600713 } else if (rq == 2) {
714 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200715 skb = get_skb_by_index(skb_arr_rq2,
716 skb_arr_rq2_len, cqe);
717 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800718 netif_err(port, rx_err, dev,
719 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720 break;
721 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000722 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600724 } else {
725 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200726 skb = get_skb_by_index(skb_arr_rq3,
727 skb_arr_rq3_len, cqe);
728 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800729 netif_err(port, rx_err, dev,
730 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200731 break;
732 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000733 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 processed_rq3++;
735 }
736
Breno Leitaoce45b872010-10-27 08:45:14 +0000737 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000738
739 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
David S. Millere5905c82013-04-22 19:24:19 -0400740 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
741 cqe->vlan_tag);
Anton Blanchard34284142011-10-14 05:31:11 +0000742
743 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100744 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100745 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200746 port_reset = ehea_treat_poll_error(pr, rq, cqe,
747 &processed_rq2,
748 &processed_rq3);
749 if (port_reset)
750 break;
751 }
752 cqe = ehea_poll_rq1(qp, &wqe_index);
753 }
754
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000756 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200757
758 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
759 ehea_refill_rq2(pr, processed_rq2);
760 ehea_refill_rq3(pr, processed_rq3);
761
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700762 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763}
764
Andre Detsch2928db42010-08-17 05:49:12 +0000765#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
766
767static void reset_sq_restart_flag(struct ehea_port *port)
768{
769 int i;
770
Anton Blanchard723f28e2011-10-14 05:31:01 +0000771 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000772 struct ehea_port_res *pr = &port->port_res[i];
773 pr->sq_restart_flag = 0;
774 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000775 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000776}
777
778static void check_sqs(struct ehea_port *port)
779{
780 struct ehea_swqe *swqe;
781 int swqe_index;
782 int i, k;
783
Anton Blanchard723f28e2011-10-14 05:31:01 +0000784 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000785 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000786 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000787 k = 0;
788 swqe = ehea_get_swqe(pr->qp, &swqe_index);
789 memset(swqe, 0, SWQE_HEADER_SIZE);
790 atomic_dec(&pr->swqe_avail);
791
792 swqe->tx_control |= EHEA_SWQE_PURGE;
793 swqe->wr_id = SWQE_RESTART_CHECK;
794 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
795 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
796 swqe->immediate_data_length = 80;
797
798 ehea_post_swqe(pr->qp, swqe);
799
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000800 ret = wait_event_timeout(port->restart_wq,
801 pr->sq_restart_flag == 0,
802 msecs_to_jiffies(100));
803
804 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800805 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000806 ehea_schedule_port_reset(pr->port);
807 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000808 }
809 }
Andre Detsch2928db42010-08-17 05:49:12 +0000810}
811
812
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200814{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100815 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816 struct ehea_cq *send_cq = pr->send_cq;
817 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100818 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200819 int cqe_counter = 0;
820 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100821 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000822 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
823 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200824
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100825 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600826 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100827 ehea_inc_cq(send_cq);
828
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200829 cqe_counter++;
830 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000831
832 if (cqe->wr_id == SWQE_RESTART_CHECK) {
833 pr->sq_restart_flag = 1;
834 swqe_av++;
835 break;
836 }
837
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200838 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800839 pr_err("Bad send completion status=0x%04X\n",
840 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000841
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200842 if (netif_msg_tx_err(pr->port))
843 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000844
845 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800846 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000847 ehea_schedule_port_reset(pr->port);
848 break;
849 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200850 }
851
852 if (netif_msg_tx_done(pr->port))
853 ehea_dump(cqe, sizeof(*cqe), "CQE");
854
855 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100856 == EHEA_SWQE2_TYPE)) {
857
858 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
859 skb = pr->sq_skba.arr[index];
Eric W. Biedermancfbe4062014-03-15 17:25:48 -0700860 dev_consume_skb_any(skb);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100861 pr->sq_skba.arr[index] = NULL;
862 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200863
864 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
865 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100866
867 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700868 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200869
870 ehea_update_feca(send_cq, cqe_counter);
871 atomic_add(swqe_av, &pr->swqe_avail);
872
Anton Blanchardb9564462011-10-14 05:30:59 +0000873 if (unlikely(netif_tx_queue_stopped(txq) &&
874 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
875 __netif_tx_lock(txq, smp_processor_id());
876 if (netif_tx_queue_stopped(txq) &&
877 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
878 netif_tx_wake_queue(txq);
879 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200880 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000881
Breno Leitao5b27d422010-10-05 13:16:22 +0000882 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200883
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100884 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200885}
886
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700887#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100888
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700889static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200890{
Doug Maxey508d2b52008-01-31 20:20:49 -0600891 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
892 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700893 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100894 struct ehea_cqe *cqe;
895 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000896 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700897 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100898
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700899 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000900 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901
Anton Blanchard222ca962011-10-14 05:31:00 +0000902 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800903 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100904 ehea_reset_cq_ep(pr->recv_cq);
905 ehea_reset_cq_ep(pr->send_cq);
906 ehea_reset_cq_n1(pr->recv_cq);
907 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000908 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100909 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
910 cqe_skb = ehea_poll_cq(pr->send_cq);
911
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100912 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700913 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100914
Ben Hutchings288379f2009-01-19 16:43:59 -0800915 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700916 return rx;
917
918 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
919 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100920 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100921
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700922 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200923}
924
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200925#ifdef CONFIG_NET_POLL_CONTROLLER
926static void ehea_netpoll(struct net_device *dev)
927{
928 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200930
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700931 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800932 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200933}
934#endif
935
David Howells7d12e782006-10-05 14:55:46 +0100936static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200937{
938 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100939
Ben Hutchings288379f2009-01-19 16:43:59 -0800940 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100941
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200942 return IRQ_HANDLED;
943}
944
David Howells7d12e782006-10-05 14:55:46 +0100945static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200946{
947 struct ehea_port *port = param;
948 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100949 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200950 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000951 u64 resource_type, aer, aerr;
952 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200953
954 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100955
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200956 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200957 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800958 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
959 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100960
961 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000962
963 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
964 &aer, &aerr);
965
966 if (resource_type == EHEA_AER_RESTYPE_QP) {
967 if ((aer & EHEA_AER_RESET_MASK) ||
968 (aerr & EHEA_AERR_RESET_MASK))
969 reset_port = 1;
970 } else
971 reset_port = 1; /* Reset in case of CQ or EQ error */
972
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100973 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200974 }
975
Thomas Kleinea96cea2010-04-20 23:10:55 +0000976 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800977 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000978 ehea_schedule_port_reset(port);
979 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100980
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200981 return IRQ_HANDLED;
982}
983
984static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
985 int logical_port)
986{
987 int i;
988
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100989 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100990 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200991 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100992 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 return NULL;
994}
995
996int ehea_sense_port_attr(struct ehea_port *port)
997{
998 int ret;
999 u64 hret;
1000 struct hcp_ehea_port_cb0 *cb0;
1001
Doug Maxey508d2b52008-01-31 20:20:49 -06001002 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001003 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001004 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001005 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001006 ret = -ENOMEM;
1007 goto out;
1008 }
1009
1010 hret = ehea_h_query_ehea_port(port->adapter->handle,
1011 port->logical_port_id, H_PORT_CB0,
1012 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1013 cb0);
1014 if (hret != H_SUCCESS) {
1015 ret = -EIO;
1016 goto out_free;
1017 }
1018
1019 /* MAC address */
1020 port->mac_addr = cb0->port_mac_addr << 16;
1021
Doug Maxey508d2b52008-01-31 20:20:49 -06001022 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001023 ret = -EADDRNOTAVAIL;
1024 goto out_free;
1025 }
1026
1027 /* Port speed */
1028 switch (cb0->port_speed) {
1029 case H_SPEED_10M_H:
1030 port->port_speed = EHEA_SPEED_10M;
1031 port->full_duplex = 0;
1032 break;
1033 case H_SPEED_10M_F:
1034 port->port_speed = EHEA_SPEED_10M;
1035 port->full_duplex = 1;
1036 break;
1037 case H_SPEED_100M_H:
1038 port->port_speed = EHEA_SPEED_100M;
1039 port->full_duplex = 0;
1040 break;
1041 case H_SPEED_100M_F:
1042 port->port_speed = EHEA_SPEED_100M;
1043 port->full_duplex = 1;
1044 break;
1045 case H_SPEED_1G_F:
1046 port->port_speed = EHEA_SPEED_1G;
1047 port->full_duplex = 1;
1048 break;
1049 case H_SPEED_10G_F:
1050 port->port_speed = EHEA_SPEED_10G;
1051 port->full_duplex = 1;
1052 break;
1053 default:
1054 port->port_speed = 0;
1055 port->full_duplex = 0;
1056 break;
1057 }
1058
Thomas Kleine919b592007-01-22 12:53:20 +01001059 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001060 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001061
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001062 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001063 if (use_mcs)
1064 port->num_def_qps = cb0->num_default_qps;
1065 else
1066 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001067
1068 if (!port->num_def_qps) {
1069 ret = -EINVAL;
1070 goto out_free;
1071 }
1072
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001073 ret = 0;
1074out_free:
1075 if (ret || netif_msg_probe(port))
1076 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001077 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001078out:
1079 return ret;
1080}
1081
1082int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1083{
1084 struct hcp_ehea_port_cb4 *cb4;
1085 u64 hret;
1086 int ret = 0;
1087
Thomas Klein3faf2692009-01-21 14:45:33 -08001088 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001089 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001090 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001091 ret = -ENOMEM;
1092 goto out;
1093 }
1094
1095 cb4->port_speed = port_speed;
1096
1097 netif_carrier_off(port->netdev);
1098
1099 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1100 port->logical_port_id,
1101 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1102 if (hret == H_SUCCESS) {
1103 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1104
1105 hret = ehea_h_query_ehea_port(port->adapter->handle,
1106 port->logical_port_id,
1107 H_PORT_CB4, H_PORT_CB4_SPEED,
1108 cb4);
1109 if (hret == H_SUCCESS) {
1110 switch (cb4->port_speed) {
1111 case H_SPEED_10M_H:
1112 port->port_speed = EHEA_SPEED_10M;
1113 port->full_duplex = 0;
1114 break;
1115 case H_SPEED_10M_F:
1116 port->port_speed = EHEA_SPEED_10M;
1117 port->full_duplex = 1;
1118 break;
1119 case H_SPEED_100M_H:
1120 port->port_speed = EHEA_SPEED_100M;
1121 port->full_duplex = 0;
1122 break;
1123 case H_SPEED_100M_F:
1124 port->port_speed = EHEA_SPEED_100M;
1125 port->full_duplex = 1;
1126 break;
1127 case H_SPEED_1G_F:
1128 port->port_speed = EHEA_SPEED_1G;
1129 port->full_duplex = 1;
1130 break;
1131 case H_SPEED_10G_F:
1132 port->port_speed = EHEA_SPEED_10G;
1133 port->full_duplex = 1;
1134 break;
1135 default:
1136 port->port_speed = 0;
1137 port->full_duplex = 0;
1138 break;
1139 }
1140 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001141 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001142 ret = -EIO;
1143 }
1144 } else {
1145 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001146 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001147 ret = -EPERM;
1148 } else {
1149 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001150 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001151 }
1152 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001153 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1154 netif_carrier_on(port->netdev);
1155
Thomas Klein3faf2692009-01-21 14:45:33 -08001156 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001157out:
1158 return ret;
1159}
1160
1161static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1162{
1163 int ret;
1164 u8 ec;
1165 u8 portnum;
1166 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001167 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001168
1169 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1170 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1171 port = ehea_get_port(adapter, portnum);
xypron.glpk@gmx.de1740c292016-05-17 22:28:54 +02001172 if (!port) {
1173 netdev_err(NULL, "unknown portnum %x\n", portnum);
1174 return;
1175 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001176 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001177
1178 switch (ec) {
1179 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1180
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001181 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001182 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001183 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001185 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001186 break;
1187 }
1188
Joe Perches8c4877a2010-12-13 10:05:14 -08001189 netif_info(port, link, dev,
1190 "Logical port up: %dMbps %s Duplex\n",
1191 port->port_speed,
1192 port->full_duplex == 1 ?
1193 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001194
Joe Perches8c4877a2010-12-13 10:05:14 -08001195 netif_carrier_on(dev);
1196 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 }
1198 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001199 if (netif_carrier_ok(dev)) {
1200 netif_info(port, link, dev,
1201 "Logical port down\n");
1202 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001203 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001204 }
1205
1206 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001207 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001208 netif_info(port, link, dev,
1209 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001210 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001211 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001212 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001213 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001214 netif_info(port, link, dev,
1215 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001216 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001217 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001218 }
1219
1220 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001221 netdev_info(dev,
1222 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001224 netdev_info(dev,
1225 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226
1227 break;
1228 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001229 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001230 break;
1231 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001232 netdev_info(dev, "Port malfunction\n");
1233 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001234 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001235 break;
1236 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001237 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238 break;
1239 }
1240}
1241
1242static void ehea_neq_tasklet(unsigned long data)
1243{
Doug Maxey508d2b52008-01-31 20:20:49 -06001244 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245 struct ehea_eqe *eqe;
1246 u64 event_mask;
1247
1248 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001249 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250
1251 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001252 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001253 ehea_parse_eqe(adapter, eqe->entry);
1254 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001255 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 }
1257
1258 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1259 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1260 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1261
1262 ehea_h_reset_events(adapter->handle,
1263 adapter->neq->fw_handle, event_mask);
1264}
1265
David Howells7d12e782006-10-05 14:55:46 +01001266static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001267{
1268 struct ehea_adapter *adapter = param;
1269 tasklet_hi_schedule(&adapter->neq_tasklet);
1270 return IRQ_HANDLED;
1271}
1272
1273
1274static int ehea_fill_port_res(struct ehea_port_res *pr)
1275{
1276 int ret;
1277 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1278
Breno Leitaof76957f2011-01-11 07:45:57 +00001279 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001280
Thomas Kleine2878802009-01-21 14:45:57 -08001281 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001282
1283 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1284
1285 return ret;
1286}
1287
1288static int ehea_reg_interrupts(struct net_device *dev)
1289{
1290 struct ehea_port *port = netdev_priv(dev);
1291 struct ehea_port_res *pr;
1292 int i, ret;
1293
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294
1295 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1296 dev->name);
1297
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001298 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299 ehea_qp_aff_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001300 0, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001302 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1303 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001304 goto out_free_qpeq;
1305 }
1306
Joe Perches8c4877a2010-12-13 10:05:14 -08001307 netif_info(port, ifup, dev,
1308 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1309 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001311
Anton Blanchard723f28e2011-10-14 05:31:01 +00001312 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001313 pr = &port->port_res[i];
1314 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001315 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001316 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001317 ehea_recv_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001318 0, pr->int_send_name, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001319 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001320 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1321 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001322 goto out_free_req;
1323 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001324 netif_info(port, ifup, dev,
1325 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1326 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327 }
1328out:
1329 return ret;
1330
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332out_free_req:
1333 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001334 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001335 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001337
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001338out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001339 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001340 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001341
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001342 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001343
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344}
1345
1346static void ehea_free_interrupts(struct net_device *dev)
1347{
1348 struct ehea_port *port = netdev_priv(dev);
1349 struct ehea_port_res *pr;
1350 int i;
1351
1352 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001353
Anton Blanchard723f28e2011-10-14 05:31:01 +00001354 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001356 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001357 netif_info(port, intr, dev,
1358 "free send irq for res %d with handle 0x%X\n",
1359 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001360 }
1361
1362 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001363 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001364 netif_info(port, intr, dev,
1365 "associated event interrupt for handle 0x%X freed\n",
1366 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367}
1368
1369static int ehea_configure_port(struct ehea_port *port)
1370{
1371 int ret, i;
1372 u64 hret, mask;
1373 struct hcp_ehea_port_cb0 *cb0;
1374
1375 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001376 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001377 if (!cb0)
1378 goto out;
1379
1380 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1381 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1382 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1383 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1384 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1385 PXLY_RC_VLAN_FILTER)
1386 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1387
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388 for (i = 0; i < port->num_mcs; i++)
1389 if (use_mcs)
1390 cb0->default_qpn_arr[i] =
1391 port->port_res[i].qp->init_attr.qp_nr;
1392 else
1393 cb0->default_qpn_arr[i] =
1394 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396 if (netif_msg_ifup(port))
1397 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1398
1399 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1400 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1401
1402 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1403 port->logical_port_id,
1404 H_PORT_CB0, mask, cb0);
1405 ret = -EIO;
1406 if (hret != H_SUCCESS)
1407 goto out_free;
1408
1409 ret = 0;
1410
1411out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001412 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001413out:
1414 return ret;
1415}
1416
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001417static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001419 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001420 struct ehea_adapter *adapter = pr->port->adapter;
1421
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001422 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1423 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424 goto out;
1425
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001426 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1427 if (ret)
1428 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001429
1430 return 0;
1431
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001432out_free:
1433 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001435 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001436 return -EIO;
1437}
1438
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001439static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001440{
Joe Perches8e95a202009-12-03 07:58:21 +00001441 if ((ehea_rem_mr(&pr->send_mr)) ||
1442 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001443 return -EIO;
1444 else
1445 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001446}
1447
1448static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1449{
Doug Maxey508d2b52008-01-31 20:20:49 -06001450 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001451
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001452 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001453 if (!q_skba->arr)
1454 return -ENOMEM;
1455
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001456 q_skba->len = max_q_entries;
1457 q_skba->index = 0;
1458 q_skba->os_skbs = 0;
1459
1460 return 0;
1461}
1462
1463static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1464 struct port_res_cfg *pr_cfg, int queue_token)
1465{
1466 struct ehea_adapter *adapter = port->adapter;
1467 enum ehea_eq_type eq_type = EHEA_EQ;
1468 struct ehea_qp_init_attr *init_attr = NULL;
1469 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001470 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1471
1472 tx_bytes = pr->tx_bytes;
1473 tx_packets = pr->tx_packets;
1474 rx_bytes = pr->rx_bytes;
1475 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476
1477 memset(pr, 0, sizeof(struct ehea_port_res));
1478
Breno Leitaoce45b872010-10-27 08:45:14 +00001479 pr->tx_bytes = rx_bytes;
1480 pr->tx_packets = tx_packets;
1481 pr->rx_bytes = rx_bytes;
1482 pr->rx_packets = rx_packets;
1483
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001486 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1487 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001488 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001489 goto out_free;
1490 }
1491
1492 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001493 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001494 port->logical_port_id);
1495 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001496 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001497 goto out_free;
1498 }
1499
1500 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001501 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502 port->logical_port_id);
1503 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001504 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001505 goto out_free;
1506 }
1507
1508 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001509 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1510 pr->send_cq->attr.act_nr_of_cqes,
1511 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001512
1513 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1514 if (!init_attr) {
1515 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001516 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001517 goto out_free;
1518 }
1519
1520 init_attr->low_lat_rq1 = 1;
1521 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1522 init_attr->rq_count = 3;
1523 init_attr->qp_token = queue_token;
1524 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1525 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1526 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1527 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1528 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1529 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1530 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1531 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1532 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1533 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1534 init_attr->port_nr = port->logical_port_id;
1535 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1536 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1537 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1538
1539 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1540 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001541 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001542 ret = -EIO;
1543 goto out_free;
1544 }
1545
1546 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001547 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",
1548 init_attr->qp_nr,
1549 init_attr->act_nr_send_wqes,
1550 init_attr->act_nr_rwqes_rq1,
1551 init_attr->act_nr_rwqes_rq2,
1552 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001553
Thomas Klein44fb3122008-04-04 15:04:53 +02001554 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1555
1556 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001557 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1558 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1559 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1560 if (ret)
1561 goto out_free;
1562
1563 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1564 if (ehea_gen_smrs(pr) != 0) {
1565 ret = -EIO;
1566 goto out_free;
1567 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001568
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001569 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1570
1571 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001572
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001573 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001574
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001575 ret = 0;
1576 goto out;
1577
1578out_free:
1579 kfree(init_attr);
1580 vfree(pr->sq_skba.arr);
1581 vfree(pr->rq1_skba.arr);
1582 vfree(pr->rq2_skba.arr);
1583 vfree(pr->rq3_skba.arr);
1584 ehea_destroy_qp(pr->qp);
1585 ehea_destroy_cq(pr->send_cq);
1586 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001587 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001588out:
1589 return ret;
1590}
1591
1592static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1593{
1594 int ret, i;
1595
Hannes Hering357eb462009-08-04 11:48:39 -07001596 if (pr->qp)
1597 netif_napi_del(&pr->napi);
1598
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599 ret = ehea_destroy_qp(pr->qp);
1600
1601 if (!ret) {
1602 ehea_destroy_cq(pr->send_cq);
1603 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001604 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001605
1606 for (i = 0; i < pr->rq1_skba.len; i++)
1607 if (pr->rq1_skba.arr[i])
1608 dev_kfree_skb(pr->rq1_skba.arr[i]);
1609
1610 for (i = 0; i < pr->rq2_skba.len; i++)
1611 if (pr->rq2_skba.arr[i])
1612 dev_kfree_skb(pr->rq2_skba.arr[i]);
1613
1614 for (i = 0; i < pr->rq3_skba.len; i++)
1615 if (pr->rq3_skba.arr[i])
1616 dev_kfree_skb(pr->rq3_skba.arr[i]);
1617
1618 for (i = 0; i < pr->sq_skba.len; i++)
1619 if (pr->sq_skba.arr[i])
1620 dev_kfree_skb(pr->sq_skba.arr[i]);
1621
1622 vfree(pr->rq1_skba.arr);
1623 vfree(pr->rq2_skba.arr);
1624 vfree(pr->rq3_skba.arr);
1625 vfree(pr->sq_skba.arr);
1626 ret = ehea_rem_smrs(pr);
1627 }
1628 return ret;
1629}
1630
Anton Blanchard13946f52011-10-14 05:31:06 +00001631static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1632 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001633{
Eric Dumazete743d312010-04-14 15:59:40 -07001634 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001635 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1636 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001637 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001638
Anton Blanchard13946f52011-10-14 05:31:06 +00001639 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001640
Anton Blanchard13946f52011-10-14 05:31:06 +00001641 if (skb_is_gso(skb)) {
1642 swqe->tx_control |= EHEA_SWQE_TSO;
1643 swqe->mss = skb_shinfo(skb)->gso_size;
1644 /*
1645 * For TSO packets we only copy the headers into the
1646 * immediate area.
1647 */
1648 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1649 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650
Anton Blanchard13946f52011-10-14 05:31:06 +00001651 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1652 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1653 swqe->immediate_data_length = immediate_len;
1654
1655 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001656 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001657 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001658 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001659 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001660 swqe->descriptors++;
1661 }
1662 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001663 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664 swqe->immediate_data_length = skb_data_size;
1665 }
1666}
1667
1668static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1669 struct ehea_swqe *swqe, u32 lkey)
1670{
1671 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1672 skb_frag_t *frag;
1673 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001674
1675 nfrags = skb_shinfo(skb)->nr_frags;
1676 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001677 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001678 sg1entry_contains_frag_data = 0;
1679
Anton Blanchard13946f52011-10-14 05:31:06 +00001680 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001681
1682 /* write descriptors */
1683 if (nfrags > 0) {
1684 if (swqe->descriptors == 0) {
1685 /* sg1entry not yet used */
1686 frag = &skb_shinfo(skb)->frags[0];
1687
1688 /* copy sg1entry data */
1689 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001690 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001691 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001692 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001693 swqe->descriptors++;
1694 sg1entry_contains_frag_data = 1;
1695 }
1696
1697 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1698
1699 frag = &skb_shinfo(skb)->frags[i];
1700 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1701
1702 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001703 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001704 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001705 swqe->descriptors++;
1706 }
1707 }
1708}
1709
1710static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1711{
1712 int ret = 0;
1713 u64 hret;
1714 u8 reg_type;
1715
1716 /* De/Register untagged packets */
1717 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1718 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1719 port->logical_port_id,
1720 reg_type, port->mac_addr, 0, hcallid);
1721 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001722 pr_err("%sregistering bc address failed (tagged)\n",
1723 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001724 ret = -EIO;
1725 goto out_herr;
1726 }
1727
1728 /* De/Register VLAN packets */
1729 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1730 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1731 port->logical_port_id,
1732 reg_type, port->mac_addr, 0, hcallid);
1733 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001734 pr_err("%sregistering bc address failed (vlan)\n",
1735 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001736 ret = -EIO;
1737 }
1738out_herr:
1739 return ret;
1740}
1741
1742static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1743{
1744 struct ehea_port *port = netdev_priv(dev);
1745 struct sockaddr *mac_addr = sa;
1746 struct hcp_ehea_port_cb0 *cb0;
1747 int ret;
1748 u64 hret;
1749
1750 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1751 ret = -EADDRNOTAVAIL;
1752 goto out;
1753 }
1754
Thomas Klein3faf2692009-01-21 14:45:33 -08001755 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001756 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001757 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001758 ret = -ENOMEM;
1759 goto out;
1760 }
1761
1762 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1763
1764 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1765
1766 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1767 port->logical_port_id, H_PORT_CB0,
1768 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1769 if (hret != H_SUCCESS) {
1770 ret = -EIO;
1771 goto out_free;
1772 }
1773
1774 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1775
1776 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001777 if (port->state == EHEA_PORT_UP) {
1778 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1779 if (ret)
1780 goto out_upregs;
1781 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001782
1783 port->mac_addr = cb0->port_mac_addr << 16;
1784
1785 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001786 if (port->state == EHEA_PORT_UP) {
1787 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1788 if (ret)
1789 goto out_upregs;
1790 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001791
1792 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001793
1794out_upregs:
1795 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001796out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001797 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001798out:
1799 return ret;
1800}
1801
1802static void ehea_promiscuous_error(u64 hret, int enable)
1803{
Thomas Klein7674a582007-01-22 12:54:20 +01001804 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001805 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1806 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001807 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001808 pr_err("failed %sabling promiscuous mode\n",
1809 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001810}
1811
1812static void ehea_promiscuous(struct net_device *dev, int enable)
1813{
1814 struct ehea_port *port = netdev_priv(dev);
1815 struct hcp_ehea_port_cb7 *cb7;
1816 u64 hret;
1817
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001818 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001819 return;
1820
Thomas Klein3faf2692009-01-21 14:45:33 -08001821 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001822 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001823 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001824 goto out;
1825 }
1826
1827 /* Modify Pxs_DUCQPN in CB7 */
1828 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1829
1830 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1831 port->logical_port_id,
1832 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1833 if (hret) {
1834 ehea_promiscuous_error(hret, enable);
1835 goto out;
1836 }
1837
1838 port->promisc = enable;
1839out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001840 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001841}
1842
1843static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1844 u32 hcallid)
1845{
1846 u64 hret;
1847 u8 reg_type;
1848
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001849 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1850 if (mc_mac_addr == 0)
1851 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001852
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, mc_mac_addr, 0, hcallid);
1856 if (hret)
1857 goto out;
1858
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001859 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1860 if (mc_mac_addr == 0)
1861 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001862
1863 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1864 port->logical_port_id,
1865 reg_type, mc_mac_addr, 0, hcallid);
1866out:
1867 return hret;
1868}
1869
1870static int ehea_drop_multicast_list(struct net_device *dev)
1871{
1872 struct ehea_port *port = netdev_priv(dev);
1873 struct ehea_mc_list *mc_entry = port->mc_list;
1874 struct list_head *pos;
1875 struct list_head *temp;
1876 int ret = 0;
1877 u64 hret;
1878
1879 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1880 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1881
1882 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1883 H_DEREG_BCMC);
1884 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001885 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001886 ret = -EIO;
1887 }
1888
1889 list_del(pos);
1890 kfree(mc_entry);
1891 }
1892 return ret;
1893}
1894
1895static void ehea_allmulti(struct net_device *dev, int enable)
1896{
1897 struct ehea_port *port = netdev_priv(dev);
1898 u64 hret;
1899
1900 if (!port->allmulti) {
1901 if (enable) {
1902 /* Enable ALLMULTI */
1903 ehea_drop_multicast_list(dev);
1904 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1905 if (!hret)
1906 port->allmulti = 1;
1907 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001908 netdev_err(dev,
1909 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001910 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001911 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001912 if (!enable) {
1913 /* Disable ALLMULTI */
1914 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1915 if (!hret)
1916 port->allmulti = 0;
1917 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001918 netdev_err(dev,
1919 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001920 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001921 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001922}
1923
Doug Maxey508d2b52008-01-31 20:20:49 -06001924static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001925{
1926 struct ehea_mc_list *ehea_mcl_entry;
1927 u64 hret;
1928
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001929 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001930 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001931 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932
1933 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1934
1935 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1936
1937 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1938 H_REG_BCMC);
1939 if (!hret)
1940 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1941 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001942 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001943 kfree(ehea_mcl_entry);
1944 }
1945}
1946
1947static void ehea_set_multicast_list(struct net_device *dev)
1948{
1949 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001950 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001951 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001952
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001953 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001954
1955 if (dev->flags & IFF_ALLMULTI) {
1956 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001957 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001958 }
1959 ehea_allmulti(dev, 0);
1960
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001961 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001962 ret = ehea_drop_multicast_list(dev);
1963 if (ret) {
1964 /* Dropping the current multicast list failed.
1965 * Enabling ALL_MULTI is the best we can do.
1966 */
1967 ehea_allmulti(dev, 1);
1968 }
1969
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001970 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001971 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1972 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001973 goto out;
1974 }
1975
Jiri Pirko22bedad32010-04-01 21:22:57 +00001976 netdev_for_each_mc_addr(ha, dev)
1977 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001978
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001979 }
1980out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001981 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001982}
1983
Anton Blanchardd695c332011-10-14 05:31:05 +00001984static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1985{
1986 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1987
Vlad Yasevichbe1d1482014-08-25 10:34:51 -04001988 if (vlan_get_protocol(skb) != htons(ETH_P_IP))
Anton Blanchardd695c332011-10-14 05:31:05 +00001989 return;
1990
1991 if (skb->ip_summed == CHECKSUM_PARTIAL)
1992 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1993
1994 swqe->ip_start = skb_network_offset(skb);
1995 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1996
1997 switch (ip_hdr(skb)->protocol) {
1998 case IPPROTO_UDP:
1999 if (skb->ip_summed == CHECKSUM_PARTIAL)
2000 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2001
2002 swqe->tcp_offset = swqe->ip_end + 1 +
2003 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002004 break;
2005
2006 case IPPROTO_TCP:
2007 if (skb->ip_summed == CHECKSUM_PARTIAL)
2008 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2009
2010 swqe->tcp_offset = swqe->ip_end + 1 +
2011 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002012 break;
2013 }
2014}
2015
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002016static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2017 struct ehea_swqe *swqe, u32 lkey)
2018{
Anton Blanchardd695c332011-10-14 05:31:05 +00002019 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002020
Anton Blanchardd695c332011-10-14 05:31:05 +00002021 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002022
2023 write_swqe2_data(skb, dev, swqe, lkey);
2024}
2025
2026static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2027 struct ehea_swqe *swqe)
2028{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002029 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002030
Anton Blanchardd695c332011-10-14 05:31:05 +00002031 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002032
Anton Blanchard30e2e902011-10-14 05:31:07 +00002033 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002034 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002035 else
2036 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002037
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002038 swqe->immediate_data_length = skb->len;
Eric W. Biedermancfbe4062014-03-15 17:25:48 -07002039 dev_consume_skb_any(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002040}
2041
2042static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2043{
2044 struct ehea_port *port = netdev_priv(dev);
2045 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002046 u32 lkey;
2047 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002048 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002049 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002050
Anton Blanchardb9564462011-10-14 05:30:59 +00002051 pr = &port->port_res[skb_get_queue_mapping(skb)];
2052 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002053
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2055 memset(swqe, 0, SWQE_HEADER_SIZE);
2056 atomic_dec(&pr->swqe_avail);
2057
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002058 if (skb_vlan_tag_present(skb)) {
Eric Dumazete5ccd962010-10-26 19:21:07 +00002059 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002060 swqe->vlan_tag = skb_vlan_tag_get(skb);
Eric Dumazete5ccd962010-10-26 19:21:07 +00002061 }
2062
Breno Leitaoce45b872010-10-27 08:45:14 +00002063 pr->tx_packets++;
2064 pr->tx_bytes += skb->len;
2065
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002066 if (skb->len <= SWQE3_MAX_IMM) {
2067 u32 sig_iv = port->sig_comp_iv;
2068 u32 swqe_num = pr->swqe_id_counter;
2069 ehea_xmit3(skb, dev, swqe);
2070 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2071 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2072 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2073 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2074 sig_iv);
2075 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2076 pr->swqe_ll_count = 0;
2077 } else
2078 pr->swqe_ll_count += 1;
2079 } else {
2080 swqe->wr_id =
2081 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2082 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002083 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2085 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2086
2087 pr->sq_skba.index++;
2088 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2089
2090 lkey = pr->send_mr.lkey;
2091 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002092 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002093 }
2094 pr->swqe_id_counter += 1;
2095
Joe Perches8c4877a2010-12-13 10:05:14 -08002096 netif_info(port, tx_queued, dev,
2097 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2098 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002099 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002100
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002101 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002102 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002103 swqe->tx_control |= EHEA_SWQE_PURGE;
2104 }
Thomas Klein44c82152007-07-11 16:32:00 +02002105
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002106 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107
2108 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002109 pr->p_stats.queue_stopped++;
2110 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002112
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002113 return NETDEV_TX_OK;
2114}
2115
Patrick McHardy80d5c362013-04-19 02:04:28 +00002116static int ehea_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117{
2118 struct ehea_port *port = netdev_priv(dev);
2119 struct ehea_adapter *adapter = port->adapter;
2120 struct hcp_ehea_port_cb1 *cb1;
2121 int index;
2122 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002123 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002124
Thomas Klein3faf2692009-01-21 14:45:33 -08002125 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002127 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002128 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002129 goto out;
2130 }
2131
2132 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2133 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2134 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002135 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002136 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002137 goto out;
2138 }
2139
2140 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002141 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002142
2143 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2144 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002145 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002146 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002147 err = -EINVAL;
2148 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002149out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002150 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002151 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152}
2153
Patrick McHardy80d5c362013-04-19 02:04:28 +00002154static int ehea_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002155{
2156 struct ehea_port *port = netdev_priv(dev);
2157 struct ehea_adapter *adapter = port->adapter;
2158 struct hcp_ehea_port_cb1 *cb1;
2159 int index;
2160 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002161 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002162
Thomas Klein3faf2692009-01-21 14:45:33 -08002163 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002165 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002166 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002167 goto out;
2168 }
2169
2170 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2171 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2172 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002173 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002174 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002175 goto out;
2176 }
2177
2178 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002179 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180
2181 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2182 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002183 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002184 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002185 err = -EINVAL;
2186 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002187out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002188 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002189 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002190}
2191
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002192static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193{
2194 int ret = -EIO;
2195 u64 hret;
2196 u16 dummy16 = 0;
2197 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002198 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002199
Thomas Klein3faf2692009-01-21 14:45:33 -08002200 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002201 if (!cb0) {
2202 ret = -ENOMEM;
2203 goto out;
2204 }
2205
2206 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2207 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2208 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002209 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002210 goto out;
2211 }
2212
2213 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2214 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2215 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2216 &dummy64, &dummy64, &dummy16, &dummy16);
2217 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002218 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 goto out;
2220 }
2221
2222 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2223 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2224 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002225 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002226 goto out;
2227 }
2228
2229 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2230 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2231 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2232 &dummy64, &dummy64, &dummy16, &dummy16);
2233 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002234 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235 goto out;
2236 }
2237
2238 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2239 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2240 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002241 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002242 goto out;
2243 }
2244
2245 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2246 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2247 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2248 &dummy64, &dummy64, &dummy16, &dummy16);
2249 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002250 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251 goto out;
2252 }
2253
2254 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2255 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2256 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002257 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002258 goto out;
2259 }
2260
2261 ret = 0;
2262out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002263 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002264 return ret;
2265}
2266
Anton Blanchard723f28e2011-10-14 05:31:01 +00002267static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268{
2269 int ret, i;
2270 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2271 enum ehea_eq_type eq_type = EHEA_EQ;
2272
2273 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2274 EHEA_MAX_ENTRIES_EQ, 1);
2275 if (!port->qp_eq) {
2276 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002277 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002278 goto out_kill_eq;
2279 }
2280
2281 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002282 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002283 pr_cfg.max_entries_sq = sq_entries;
2284 pr_cfg.max_entries_rq1 = rq1_entries;
2285 pr_cfg.max_entries_rq2 = rq2_entries;
2286 pr_cfg.max_entries_rq3 = rq3_entries;
2287
2288 pr_cfg_small_rx.max_entries_rcq = 1;
2289 pr_cfg_small_rx.max_entries_scq = sq_entries;
2290 pr_cfg_small_rx.max_entries_sq = sq_entries;
2291 pr_cfg_small_rx.max_entries_rq1 = 1;
2292 pr_cfg_small_rx.max_entries_rq2 = 1;
2293 pr_cfg_small_rx.max_entries_rq3 = 1;
2294
2295 for (i = 0; i < def_qps; i++) {
2296 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2297 if (ret)
2298 goto out_clean_pr;
2299 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002300 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301 ret = ehea_init_port_res(port, &port->port_res[i],
2302 &pr_cfg_small_rx, i);
2303 if (ret)
2304 goto out_clean_pr;
2305 }
2306
2307 return 0;
2308
2309out_clean_pr:
2310 while (--i >= 0)
2311 ehea_clean_portres(port, &port->port_res[i]);
2312
2313out_kill_eq:
2314 ehea_destroy_eq(port->qp_eq);
2315 return ret;
2316}
2317
2318static int ehea_clean_all_portres(struct ehea_port *port)
2319{
2320 int ret = 0;
2321 int i;
2322
Anton Blanchard723f28e2011-10-14 05:31:01 +00002323 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002324 ret |= ehea_clean_portres(port, &port->port_res[i]);
2325
2326 ret |= ehea_destroy_eq(port->qp_eq);
2327
2328 return ret;
2329}
2330
Thomas Klein35cf2e22007-08-06 13:55:14 +02002331static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002332{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002333 if (adapter->active_ports)
2334 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002335
2336 ehea_rem_mr(&adapter->mr);
2337}
2338
Thomas Klein35cf2e22007-08-06 13:55:14 +02002339static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002340{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002341 if (adapter->active_ports)
2342 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002343
2344 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2345}
2346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002347static int ehea_up(struct net_device *dev)
2348{
2349 int ret, i;
2350 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002351
2352 if (port->state == EHEA_PORT_UP)
2353 return 0;
2354
Anton Blanchard723f28e2011-10-14 05:31:01 +00002355 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002357 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002358 goto out;
2359 }
2360
2361 /* Set default QP for this port */
2362 ret = ehea_configure_port(port);
2363 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002364 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365 goto out_clean_pr;
2366 }
2367
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002368 ret = ehea_reg_interrupts(dev);
2369 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002370 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002371 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002372 }
2373
Anton Blanchard723f28e2011-10-14 05:31:01 +00002374 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2376 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002377 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 goto out_free_irqs;
2379 }
2380 }
2381
Doug Maxey508d2b52008-01-31 20:20:49 -06002382 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002383 ret = ehea_fill_port_res(&port->port_res[i]);
2384 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002385 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 goto out_free_irqs;
2387 }
2388 }
2389
Thomas Klein21eee2d2008-02-13 16:18:33 +01002390 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2391 if (ret) {
2392 ret = -EIO;
2393 goto out_free_irqs;
2394 }
2395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002396 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002397
2398 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002399 goto out;
2400
2401out_free_irqs:
2402 ehea_free_interrupts(dev);
2403
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002404out_clean_pr:
2405 ehea_clean_all_portres(port);
2406out:
Thomas Klein44c82152007-07-11 16:32:00 +02002407 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002408 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002409
Thomas Klein21eee2d2008-02-13 16:18:33 +01002410 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002411 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002412
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413 return ret;
2414}
2415
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002416static void port_napi_disable(struct ehea_port *port)
2417{
2418 int i;
2419
Anton Blanchard723f28e2011-10-14 05:31:01 +00002420 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002421 napi_disable(&port->port_res[i].napi);
2422}
2423
2424static void port_napi_enable(struct ehea_port *port)
2425{
2426 int i;
2427
Anton Blanchard723f28e2011-10-14 05:31:01 +00002428 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002429 napi_enable(&port->port_res[i].napi);
2430}
2431
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432static int ehea_open(struct net_device *dev)
2433{
2434 int ret;
2435 struct ehea_port *port = netdev_priv(dev);
2436
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002437 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002438
Joe Perches8c4877a2010-12-13 10:05:14 -08002439 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002440
Guilherme G. Piccoli29ab5a32016-11-03 08:16:20 -02002441 netif_carrier_off(dev);
2442
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002444 if (!ret) {
2445 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002446 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002447 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002448
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002449 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002450 schedule_delayed_work(&port->stats_work,
2451 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002452
2453 return ret;
2454}
2455
2456static int ehea_down(struct net_device *dev)
2457{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002458 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002459 struct ehea_port *port = netdev_priv(dev);
2460
2461 if (port->state == EHEA_PORT_DOWN)
2462 return 0;
2463
2464 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002465 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002466 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002468 ehea_free_interrupts(dev);
2469
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002471
Thomas Klein21eee2d2008-02-13 16:18:33 +01002472 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002473
Thomas Klein44c82152007-07-11 16:32:00 +02002474 ret = ehea_clean_all_portres(port);
2475 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002476 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002477
Thomas Klein21eee2d2008-02-13 16:18:33 +01002478 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002479
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002480 return ret;
2481}
2482
2483static int ehea_stop(struct net_device *dev)
2484{
2485 int ret;
2486 struct ehea_port *port = netdev_priv(dev);
2487
Joe Perches8c4877a2010-12-13 10:05:14 -08002488 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002489
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002490 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002491 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002492 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002493 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002494 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002495 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002496 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002497 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002498 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002499 return ret;
2500}
2501
Andrew Morton22559c52008-04-18 13:50:39 -07002502static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002503{
2504 struct ehea_qp qp = *orig_qp;
2505 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2506 struct ehea_swqe *swqe;
2507 int wqe_index;
2508 int i;
2509
2510 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2511 swqe = ehea_get_swqe(&qp, &wqe_index);
2512 swqe->tx_control |= EHEA_SWQE_PURGE;
2513 }
2514}
2515
Andrew Morton22559c52008-04-18 13:50:39 -07002516static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002517{
2518 int i;
2519
Anton Blanchard723f28e2011-10-14 05:31:01 +00002520 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002521 struct ehea_port_res *pr = &port->port_res[i];
2522 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002523 int ret;
2524
2525 ret = wait_event_timeout(port->swqe_avail_wq,
2526 atomic_read(&pr->swqe_avail) >= swqe_max,
2527 msecs_to_jiffies(100));
2528
2529 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002530 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002531 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002532 }
2533 }
2534}
2535
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002536static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002537{
2538 struct ehea_port *port = netdev_priv(dev);
2539 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002540 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002541 int ret = -EIO;
2542 int dret;
2543 int i;
2544 u64 hret;
2545 u64 dummy64 = 0;
2546 u16 dummy16 = 0;
2547
Thomas Klein3faf2692009-01-21 14:45:33 -08002548 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002549 if (!cb0) {
2550 ret = -ENOMEM;
2551 goto out;
2552 }
2553
Anton Blanchard723f28e2011-10-14 05:31:01 +00002554 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002555 struct ehea_port_res *pr = &port->port_res[i];
2556 struct ehea_qp *qp = pr->qp;
2557
2558 /* Purge send queue */
2559 ehea_purge_sq(qp);
2560
2561 /* Disable queue pair */
2562 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2563 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2564 cb0);
2565 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002566 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002567 goto out;
2568 }
2569
2570 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2571 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2572
2573 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2574 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2575 1), cb0, &dummy64,
2576 &dummy64, &dummy16, &dummy16);
2577 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002578 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002579 goto out;
2580 }
2581
2582 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2583 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2584 cb0);
2585 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002586 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002587 goto out;
2588 }
2589
2590 /* deregister shared memory regions */
2591 dret = ehea_rem_smrs(pr);
2592 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002593 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002594 goto out;
2595 }
2596 }
2597
2598 ret = 0;
2599out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002600 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002601
2602 return ret;
2603}
2604
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002605static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002606{
2607 struct ehea_qp qp = *orig_qp;
2608 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2609 struct ehea_rwqe *rwqe;
2610 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2611 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2612 struct sk_buff *skb;
2613 u32 lkey = pr->recv_mr.lkey;
2614
2615
2616 int i;
2617 int index;
2618
2619 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2620 rwqe = ehea_get_next_rwqe(&qp, 2);
2621 rwqe->sg_list[0].l_key = lkey;
2622 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2623 skb = skba_rq2[index];
2624 if (skb)
2625 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2626 }
2627
2628 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2629 rwqe = ehea_get_next_rwqe(&qp, 3);
2630 rwqe->sg_list[0].l_key = lkey;
2631 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2632 skb = skba_rq3[index];
2633 if (skb)
2634 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2635 }
2636}
2637
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002638static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002639{
2640 struct ehea_port *port = netdev_priv(dev);
2641 struct ehea_adapter *adapter = port->adapter;
2642 int ret = 0;
2643 int i;
2644
Doug Maxey508d2b52008-01-31 20:20:49 -06002645 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002646 u64 hret;
2647 u64 dummy64 = 0;
2648 u16 dummy16 = 0;
2649
Thomas Klein3faf2692009-01-21 14:45:33 -08002650 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002651 if (!cb0) {
2652 ret = -ENOMEM;
2653 goto out;
2654 }
2655
Anton Blanchard723f28e2011-10-14 05:31:01 +00002656 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002657 struct ehea_port_res *pr = &port->port_res[i];
2658 struct ehea_qp *qp = pr->qp;
2659
2660 ret = ehea_gen_smrs(pr);
2661 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002662 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002663 goto out;
2664 }
2665
2666 ehea_update_rqs(qp, pr);
2667
2668 /* Enable queue pair */
2669 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2670 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2671 cb0);
2672 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002673 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002674 goto out;
2675 }
2676
2677 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2678 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2679
2680 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2681 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2682 1), cb0, &dummy64,
2683 &dummy64, &dummy16, &dummy16);
2684 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002685 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002686 goto out;
2687 }
2688
2689 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2690 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2691 cb0);
2692 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002693 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002694 goto out;
2695 }
2696
2697 /* refill entire queue */
2698 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2699 ehea_refill_rq2(pr, 0);
2700 ehea_refill_rq3(pr, 0);
2701 }
2702out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002703 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002704
2705 return ret;
2706}
2707
David Howellsc4028952006-11-22 14:57:56 +00002708static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002709{
2710 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002711 struct ehea_port *port =
2712 container_of(work, struct ehea_port, reset_task);
2713 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002715 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002717 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002718 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002719
2720 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002721
Thomas Klein44c82152007-07-11 16:32:00 +02002722 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723
2724 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002725 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002727
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002728 ehea_set_multicast_list(dev);
2729
Joe Perches8c4877a2010-12-13 10:05:14 -08002730 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002731
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002732 port_napi_enable(port);
2733
Anton Blanchardb9564462011-10-14 05:30:59 +00002734 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002736 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002737 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002738}
2739
Tejun Heo3d6b8922010-12-12 16:45:14 +01002740static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002741{
2742 int ret, i;
2743 struct ehea_adapter *adapter;
2744
Joe Perches8c4877a2010-12-13 10:05:14 -08002745 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002746
2747 list_for_each_entry(adapter, &adapter_list, list)
2748 if (adapter->active_ports) {
2749 /* Shutdown all ports */
2750 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2751 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002752 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002753
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002754 if (!port)
2755 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002756
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002757 dev = port->netdev;
2758
2759 if (dev->flags & IFF_UP) {
2760 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002761 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002762 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002763 ret = ehea_stop_qps(dev);
2764 if (ret) {
2765 mutex_unlock(&port->port_lock);
2766 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002767 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002768 port_napi_disable(port);
2769 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002770 }
Andre Detsch2928db42010-08-17 05:49:12 +00002771 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002772 }
2773
2774 /* Unregister old memory region */
2775 ret = ehea_rem_mr(&adapter->mr);
2776 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002777 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002778 goto out;
2779 }
2780 }
2781
Thomas Klein44c82152007-07-11 16:32:00 +02002782 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2783
2784 list_for_each_entry(adapter, &adapter_list, list)
2785 if (adapter->active_ports) {
2786 /* Register new memory region */
2787 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2788 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002789 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002790 goto out;
2791 }
2792
2793 /* Restart all ports */
2794 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2795 struct ehea_port *port = adapter->port[i];
2796
2797 if (port) {
2798 struct net_device *dev = port->netdev;
2799
2800 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002801 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002802 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002803 if (!ret) {
2804 check_sqs(port);
2805 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002806 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002807 } else {
2808 netdev_err(dev, "Unable to restart QPS\n");
2809 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002810 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002811 }
2812 }
2813 }
2814 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002815 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002816out:
2817 return;
2818}
2819
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002820static void ehea_tx_watchdog(struct net_device *dev)
2821{
2822 struct ehea_port *port = netdev_priv(dev);
2823
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002824 if (netif_carrier_ok(dev) &&
2825 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002826 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002827}
2828
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002829static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002830{
2831 struct hcp_query_ehea *cb;
2832 u64 hret;
2833 int ret;
2834
Thomas Klein3faf2692009-01-21 14:45:33 -08002835 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002836 if (!cb) {
2837 ret = -ENOMEM;
2838 goto out;
2839 }
2840
2841 hret = ehea_h_query_ehea(adapter->handle, cb);
2842
2843 if (hret != H_SUCCESS) {
2844 ret = -EIO;
2845 goto out_herr;
2846 }
2847
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002848 adapter->max_mc_mac = cb->max_mc_mac - 1;
2849 ret = 0;
2850
2851out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002852 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002853out:
2854 return ret;
2855}
2856
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002857static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002858{
2859 struct hcp_ehea_port_cb4 *cb4;
2860 u64 hret;
2861 int ret = 0;
2862
2863 *jumbo = 0;
2864
2865 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002866 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002867 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002868 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002869 ret = -ENOMEM;
2870 goto out;
2871 } else {
2872 hret = ehea_h_query_ehea_port(port->adapter->handle,
2873 port->logical_port_id,
2874 H_PORT_CB4,
2875 H_PORT_CB4_JUMBO, cb4);
2876 if (hret == H_SUCCESS) {
2877 if (cb4->jumbo_frame)
2878 *jumbo = 1;
2879 else {
2880 cb4->jumbo_frame = 1;
2881 hret = ehea_h_modify_ehea_port(port->adapter->
2882 handle,
2883 port->
2884 logical_port_id,
2885 H_PORT_CB4,
2886 H_PORT_CB4_JUMBO,
2887 cb4);
2888 if (hret == H_SUCCESS)
2889 *jumbo = 1;
2890 }
2891 } else
2892 ret = -EINVAL;
2893
Thomas Klein3faf2692009-01-21 14:45:33 -08002894 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002895 }
2896out:
2897 return ret;
2898}
2899
2900static ssize_t ehea_show_port_id(struct device *dev,
2901 struct device_attribute *attr, char *buf)
2902{
2903 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002904 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002905}
2906
2907static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2908 NULL);
2909
Bill Pemberton0297be02012-12-03 09:23:10 -05002910static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002911{
2912 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002913 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002914}
2915
2916static struct device *ehea_register_port(struct ehea_port *port,
2917 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002918{
2919 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002920
Grant Likely61c7a082010-04-13 16:12:29 -07002921 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002922 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002923 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002924
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002925 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002926 port->ofdev.dev.release = logical_port_release;
2927
2928 ret = of_device_register(&port->ofdev);
2929 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002930 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002931 goto out;
2932 }
2933
2934 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002935 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002936 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002937 goto out_unreg_of_dev;
2938 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002939
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002940 return &port->ofdev.dev;
2941
2942out_unreg_of_dev:
2943 of_device_unregister(&port->ofdev);
2944out:
2945 return NULL;
2946}
2947
2948static void ehea_unregister_port(struct ehea_port *port)
2949{
2950 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2951 of_device_unregister(&port->ofdev);
2952}
2953
Thomas Klein086c1b22009-01-21 14:43:59 -08002954static const struct net_device_ops ehea_netdev_ops = {
2955 .ndo_open = ehea_open,
2956 .ndo_stop = ehea_stop,
2957 .ndo_start_xmit = ehea_start_xmit,
2958#ifdef CONFIG_NET_POLL_CONTROLLER
2959 .ndo_poll_controller = ehea_netpoll,
2960#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002961 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002962 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002963 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002964 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002965 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002966 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2967 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002968};
2969
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002970static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002971 u32 logical_port_id,
2972 struct device_node *dn)
2973{
2974 int ret;
2975 struct net_device *dev;
2976 struct ehea_port *port;
2977 struct device *port_dev;
2978 int jumbo;
2979
2980 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002981 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002982
2983 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002984 ret = -ENOMEM;
2985 goto out_err;
2986 }
2987
2988 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002989
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002990 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002991 port->state = EHEA_PORT_DOWN;
2992 port->sig_comp_iv = sq_entries / 10;
2993
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002994 port->adapter = adapter;
2995 port->netdev = dev;
2996 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002997
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002998 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999
3000 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3001 if (!port->mc_list) {
3002 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003003 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003004 }
3005
3006 INIT_LIST_HEAD(&port->mc_list->list);
3007
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003008 ret = ehea_sense_port_attr(port);
3009 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003010 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003011
Anton Blanchardb9564462011-10-14 05:30:59 +00003012 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003013 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003014
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003015 port_dev = ehea_register_port(port, dn);
3016 if (!port_dev)
3017 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003018
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003019 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003020
3021 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003022 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3023
Thomas Klein086c1b22009-01-21 14:43:59 -08003024 dev->netdev_ops = &ehea_netdev_ops;
3025 ehea_set_ethtool_ops(dev);
3026
David S. Miller55fbbe42013-04-22 19:34:34 -04003027 dev->hw_features = NETIF_F_SG | NETIF_F_TSO |
3028 NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_CTAG_TX;
Eric Dumazet28e24c62013-12-02 08:51:13 -08003029 dev->features = NETIF_F_SG | NETIF_F_TSO |
David S. Miller55fbbe42013-04-22 19:34:34 -04003030 NETIF_F_HIGHDMA | NETIF_F_IP_CSUM |
3031 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
3032 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003033 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3034 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003035 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3036
Jarod Wilson3d5d96a2016-10-17 15:54:14 -04003037 /* MTU range: 68 - 9022 */
3038 dev->min_mtu = ETH_MIN_MTU;
3039 dev->max_mtu = EHEA_MAX_PACKET_SIZE;
3040
David Howellsc4028952006-11-22 14:57:56 +00003041 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003042 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003043
Anton Blanchard21ccc792011-05-10 16:17:10 +00003044 init_waitqueue_head(&port->swqe_avail_wq);
3045 init_waitqueue_head(&port->restart_wq);
3046
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003047 ret = register_netdev(dev);
3048 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003049 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003050 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003051 }
3052
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003053 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003054 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003055 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003056
Joe Perches8c4877a2010-12-13 10:05:14 -08003057 netdev_info(dev, "Jumbo frames are %sabled\n",
3058 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003059
Thomas Klein44c82152007-07-11 16:32:00 +02003060 adapter->active_ports++;
3061
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003062 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003063
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064out_unreg_port:
3065 ehea_unregister_port(port);
3066
3067out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003069
3070out_free_ethdev:
3071 free_netdev(dev);
3072
3073out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003074 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3075 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003076 return NULL;
3077}
3078
3079static void ehea_shutdown_single_port(struct ehea_port *port)
3080{
Brian King7fb1c2a2008-05-14 09:48:25 -05003081 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003082
3083 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003084 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003085 unregister_netdev(port->netdev);
3086 ehea_unregister_port(port);
3087 kfree(port->mc_list);
3088 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003089 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003090}
3091
3092static int ehea_setup_ports(struct ehea_adapter *adapter)
3093{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003094 struct device_node *lhea_dn;
3095 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003096
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003097 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099
Grant Likely61c7a082010-04-13 16:12:29 -07003100 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003101 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003102
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003103 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003104 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003106 pr_err("bad device node: eth_dn name=%s\n",
3107 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003108 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003109 }
3110
Thomas Klein1211bb62007-04-26 11:56:43 +02003111 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003112 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003113 of_node_put(eth_dn);
3114 return -EIO;
3115 }
3116
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003117 adapter->port[i] = ehea_setup_single_port(adapter,
3118 *dn_log_port_id,
3119 eth_dn);
3120 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003121 netdev_info(adapter->port[i]->netdev,
3122 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003123 else
3124 ehea_remove_adapter_mr(adapter);
3125
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003127 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003128 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003129}
3130
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003131static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3132 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003133{
3134 struct device_node *lhea_dn;
3135 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003136 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137
Grant Likely61c7a082010-04-13 16:12:29 -07003138 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003139 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003140
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003141 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003142 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143 if (dn_log_port_id)
3144 if (*dn_log_port_id == logical_port_id)
3145 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003146 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003147
3148 return NULL;
3149}
3150
3151static ssize_t ehea_probe_port(struct device *dev,
3152 struct device_attribute *attr,
3153 const char *buf, size_t count)
3154{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003155 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156 struct ehea_port *port;
3157 struct device_node *eth_dn = NULL;
3158 int i;
3159
3160 u32 logical_port_id;
3161
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003162 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163
3164 port = ehea_get_port(adapter, logical_port_id);
3165
3166 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003167 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3168 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169 return -EINVAL;
3170 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003171
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3173
3174 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003175 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 return -EINVAL;
3177 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003178
Thomas Klein1211bb62007-04-26 11:56:43 +02003179 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003180 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003181 return -EIO;
3182 }
3183
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3185
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003186 of_node_put(eth_dn);
3187
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003188 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003189 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 if (!adapter->port[i]) {
3191 adapter->port[i] = port;
3192 break;
3193 }
3194
Joe Perches8c4877a2010-12-13 10:05:14 -08003195 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3196 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003197 } else {
3198 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003199 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003200 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201
3202 return (ssize_t) count;
3203}
3204
3205static ssize_t ehea_remove_port(struct device *dev,
3206 struct device_attribute *attr,
3207 const char *buf, size_t count)
3208{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003209 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003210 struct ehea_port *port;
3211 int i;
3212 u32 logical_port_id;
3213
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003214 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215
3216 port = ehea_get_port(adapter, logical_port_id);
3217
3218 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003219 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3220 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003221
3222 ehea_shutdown_single_port(port);
3223
Doug Maxey508d2b52008-01-31 20:20:49 -06003224 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003225 if (adapter->port[i] == port) {
3226 adapter->port[i] = NULL;
3227 break;
3228 }
3229 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003230 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3231 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 return -EINVAL;
3233 }
3234
Thomas Klein1211bb62007-04-26 11:56:43 +02003235 ehea_remove_adapter_mr(adapter);
3236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 return (ssize_t) count;
3238}
3239
3240static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3241static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3242
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003243static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003245 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246 if (ret)
3247 goto out;
3248
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003249 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003250out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003251 return ret;
3252}
3253
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003254static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003256 device_remove_file(&dev->dev, &dev_attr_probe_port);
3257 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258}
3259
Anton Blanchardaa183322015-02-15 17:44:20 -02003260static int ehea_reboot_notifier(struct notifier_block *nb,
3261 unsigned long action, void *unused)
3262{
3263 if (action == SYS_RESTART) {
3264 pr_info("Reboot: freeing all eHEA resources\n");
3265 ibmebus_unregister_driver(&ehea_driver);
3266 }
3267 return NOTIFY_DONE;
3268}
3269
3270static struct notifier_block ehea_reboot_nb = {
3271 .notifier_call = ehea_reboot_notifier,
3272};
3273
3274static int ehea_mem_notifier(struct notifier_block *nb,
3275 unsigned long action, void *data)
3276{
3277 int ret = NOTIFY_BAD;
3278 struct memory_notify *arg = data;
3279
3280 mutex_lock(&dlpar_mem_lock);
3281
3282 switch (action) {
3283 case MEM_CANCEL_OFFLINE:
3284 pr_info("memory offlining canceled");
3285 /* Fall through: re-add canceled memory block */
3286
3287 case MEM_ONLINE:
3288 pr_info("memory is going online");
3289 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3290 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3291 goto out_unlock;
3292 ehea_rereg_mrs();
3293 break;
3294
3295 case MEM_GOING_OFFLINE:
3296 pr_info("memory is going offline");
3297 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3298 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3299 goto out_unlock;
3300 ehea_rereg_mrs();
3301 break;
3302
3303 default:
3304 break;
3305 }
3306
3307 ehea_update_firmware_handles();
3308 ret = NOTIFY_OK;
3309
3310out_unlock:
3311 mutex_unlock(&dlpar_mem_lock);
3312 return ret;
3313}
3314
3315static struct notifier_block ehea_mem_nb = {
3316 .notifier_call = ehea_mem_notifier,
3317};
3318
3319static void ehea_crash_handler(void)
3320{
3321 int i;
3322
3323 if (ehea_fw_handles.arr)
3324 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3325 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3326 ehea_fw_handles.arr[i].fwh,
3327 FORCE_FREE);
3328
3329 if (ehea_bcmc_regs.arr)
3330 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3331 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3332 ehea_bcmc_regs.arr[i].port_id,
3333 ehea_bcmc_regs.arr[i].reg_type,
3334 ehea_bcmc_regs.arr[i].macaddr,
3335 0, H_DEREG_BCMC);
3336}
3337
3338static atomic_t ehea_memory_hooks_registered;
3339
3340/* Register memory hooks on probe of first adapter */
3341static int ehea_register_memory_hooks(void)
3342{
3343 int ret = 0;
3344
Michael Ellerman3051f392015-04-24 15:52:32 +10003345 if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
Anton Blanchardaa183322015-02-15 17:44:20 -02003346 return 0;
3347
3348 ret = ehea_create_busmap();
3349 if (ret) {
3350 pr_info("ehea_create_busmap failed\n");
3351 goto out;
3352 }
3353
3354 ret = register_reboot_notifier(&ehea_reboot_nb);
3355 if (ret) {
3356 pr_info("register_reboot_notifier failed\n");
3357 goto out;
3358 }
3359
3360 ret = register_memory_notifier(&ehea_mem_nb);
3361 if (ret) {
3362 pr_info("register_memory_notifier failed\n");
3363 goto out2;
3364 }
3365
3366 ret = crash_shutdown_register(ehea_crash_handler);
3367 if (ret) {
3368 pr_info("crash_shutdown_register failed\n");
3369 goto out3;
3370 }
3371
3372 return 0;
3373
3374out3:
3375 unregister_memory_notifier(&ehea_mem_nb);
3376out2:
3377 unregister_reboot_notifier(&ehea_reboot_nb);
3378out:
Michael Ellerman3051f392015-04-24 15:52:32 +10003379 atomic_dec(&ehea_memory_hooks_registered);
Anton Blanchardaa183322015-02-15 17:44:20 -02003380 return ret;
3381}
3382
3383static void ehea_unregister_memory_hooks(void)
3384{
Michael Ellerman3051f392015-04-24 15:52:32 +10003385 /* Only remove the hooks if we've registered them */
3386 if (atomic_read(&ehea_memory_hooks_registered) == 0)
Anton Blanchardaa183322015-02-15 17:44:20 -02003387 return;
3388
3389 unregister_reboot_notifier(&ehea_reboot_nb);
3390 if (crash_shutdown_unregister(ehea_crash_handler))
3391 pr_info("failed unregistering crash handler\n");
3392 unregister_memory_notifier(&ehea_mem_nb);
3393}
3394
Rob Herringc45640e2013-04-20 21:51:08 -05003395static int ehea_probe_adapter(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003396{
3397 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003398 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003399 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003400 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003401
Anton Blanchardaa183322015-02-15 17:44:20 -02003402 ret = ehea_register_memory_hooks();
3403 if (ret)
3404 return ret;
3405
Grant Likely61c7a082010-04-13 16:12:29 -07003406 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003407 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003408 return -EINVAL;
3409 }
3410
Himangi Saraogi09b38aa2014-05-28 19:53:09 +05303411 adapter = devm_kzalloc(&dev->dev, sizeof(*adapter), GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003412 if (!adapter) {
3413 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003414 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003415 goto out;
3416 }
3417
Thomas Klein44c82152007-07-11 16:32:00 +02003418 list_add(&adapter->list, &adapter_list);
3419
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003420 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003421
Grant Likely61c7a082010-04-13 16:12:29 -07003422 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003423 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003424 if (adapter_handle)
3425 adapter->handle = *adapter_handle;
3426
3427 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003428 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003429 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003430 ret = -ENODEV;
3431 goto out_free_ad;
3432 }
3433
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003434 adapter->pd = EHEA_PD_ID;
3435
Jingoo Han8513fbd2013-05-23 00:52:31 +00003436 platform_set_drvdata(dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003437
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003438
3439 /* initialize adapter and ports */
3440 /* get adapter properties */
3441 ret = ehea_sense_adapter_attr(adapter);
3442 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003443 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003444 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003445 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003446
3447 adapter->neq = ehea_create_eq(adapter,
3448 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3449 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003450 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003451 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003452 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003453 }
3454
3455 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3456 (unsigned long)adapter);
3457
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003458 ret = ehea_create_device_sysfs(dev);
3459 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003460 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003461
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003462 ret = ehea_setup_ports(adapter);
3463 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003464 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003465 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 }
3467
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003468 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02003469 ehea_interrupt_neq, 0,
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003470 "ehea_neq", adapter);
3471 if (ret) {
3472 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3473 goto out_shutdown_ports;
3474 }
3475
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003476 /* Handle any events that might be pending. */
3477 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003479 ret = 0;
3480 goto out;
3481
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003482out_shutdown_ports:
3483 for (i = 0; i < EHEA_MAX_PORTS; i++)
3484 if (adapter->port[i]) {
3485 ehea_shutdown_single_port(adapter->port[i]);
3486 adapter->port[i] = NULL;
3487 }
3488
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003489out_rem_dev_sysfs:
3490 ehea_remove_device_sysfs(dev);
3491
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492out_kill_eq:
3493 ehea_destroy_eq(adapter->neq);
3494
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003496 list_del(&adapter->list);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003497
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003499 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003501 return ret;
3502}
3503
Bill Pemberton0297be02012-12-03 09:23:10 -05003504static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003505{
Jingoo Han8513fbd2013-05-23 00:52:31 +00003506 struct ehea_adapter *adapter = platform_get_drvdata(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003507 int i;
3508
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003509 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510 if (adapter->port[i]) {
3511 ehea_shutdown_single_port(adapter->port[i]);
3512 adapter->port[i] = NULL;
3513 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003514
3515 ehea_remove_device_sysfs(dev);
3516
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003517 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003518 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003519
3520 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003521 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003522 list_del(&adapter->list);
Thomas Klein44c82152007-07-11 16:32:00 +02003523
Thomas Klein21eee2d2008-02-13 16:18:33 +01003524 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003525
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003526 return 0;
3527}
3528
3529static int check_module_parm(void)
3530{
3531 int ret = 0;
3532
3533 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3534 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003535 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003536 ret = -EINVAL;
3537 }
3538 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3539 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003540 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003541 ret = -EINVAL;
3542 }
3543 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3544 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003545 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546 ret = -EINVAL;
3547 }
3548 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3549 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003550 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003551 ret = -EINVAL;
3552 }
3553
3554 return ret;
3555}
3556
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003557static ssize_t ehea_show_capabilities(struct device_driver *drv,
3558 char *buf)
3559{
3560 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3561}
3562
3563static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3564 ehea_show_capabilities, NULL);
3565
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003566static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003567{
3568 int ret;
3569
Joe Perches8c4877a2010-12-13 10:05:14 -08003570 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571
Thomas Klein21eee2d2008-02-13 16:18:33 +01003572 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3573 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3574
Daniel Walker9f71a562008-03-28 14:41:26 -07003575 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003576 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003577
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003578 ret = check_module_parm();
3579 if (ret)
3580 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003582 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003583 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003584 pr_err("failed registering eHEA device driver on ebus\n");
Anton Blanchardaa183322015-02-15 17:44:20 -02003585 goto out;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003586 }
3587
3588 ret = driver_create_file(&ehea_driver.driver,
3589 &driver_attr_capabilities);
3590 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003591 pr_err("failed to register capabilities attribute, ret=%d\n",
3592 ret);
Anton Blanchardaa183322015-02-15 17:44:20 -02003593 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003594 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003595
Thomas Klein21eee2d2008-02-13 16:18:33 +01003596 return ret;
3597
Thomas Klein21eee2d2008-02-13 16:18:33 +01003598out2:
Anton Blanchardaa183322015-02-15 17:44:20 -02003599 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003600out:
3601 return ret;
3602}
3603
3604static void __exit ehea_module_exit(void)
3605{
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003606 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003607 ibmebus_unregister_driver(&ehea_driver);
Anton Blanchardaa183322015-02-15 17:44:20 -02003608 ehea_unregister_memory_hooks();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003609 kfree(ehea_fw_handles.arr);
3610 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003611 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003612}
3613
3614module_init(ehea_module_init);
3615module_exit(ehea_module_exit);