blob: 2a0dc127df3f4e099e273a77715ad87358385aff [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);
Joe Perches8c4877a2010-12-13 10:05:14 -08001172 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001173
1174 switch (ec) {
1175 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1176
1177 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001179 break;
1180 }
1181
1182 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001183 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001184 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001186 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001187 break;
1188 }
1189
Joe Perches8c4877a2010-12-13 10:05:14 -08001190 netif_info(port, link, dev,
1191 "Logical port up: %dMbps %s Duplex\n",
1192 port->port_speed,
1193 port->full_duplex == 1 ?
1194 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001195
Joe Perches8c4877a2010-12-13 10:05:14 -08001196 netif_carrier_on(dev);
1197 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001198 }
1199 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001200 if (netif_carrier_ok(dev)) {
1201 netif_info(port, link, dev,
1202 "Logical port down\n");
1203 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001204 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001205 }
1206
1207 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001208 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001209 netif_info(port, link, dev,
1210 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001211 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001212 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001213 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001214 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001215 netif_info(port, link, dev,
1216 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001217 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001218 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001219 }
1220
1221 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001222 netdev_info(dev,
1223 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 netdev_info(dev,
1226 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227
1228 break;
1229 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001230 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231 break;
1232 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001233 netdev_info(dev, "Port malfunction\n");
1234 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001235 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236 break;
1237 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001238 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239 break;
1240 }
1241}
1242
1243static void ehea_neq_tasklet(unsigned long data)
1244{
Doug Maxey508d2b52008-01-31 20:20:49 -06001245 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246 struct ehea_eqe *eqe;
1247 u64 event_mask;
1248
1249 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001250 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251
1252 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001253 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001254 ehea_parse_eqe(adapter, eqe->entry);
1255 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001256 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001257 }
1258
1259 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1260 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1261 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1262
1263 ehea_h_reset_events(adapter->handle,
1264 adapter->neq->fw_handle, event_mask);
1265}
1266
David Howells7d12e782006-10-05 14:55:46 +01001267static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268{
1269 struct ehea_adapter *adapter = param;
1270 tasklet_hi_schedule(&adapter->neq_tasklet);
1271 return IRQ_HANDLED;
1272}
1273
1274
1275static int ehea_fill_port_res(struct ehea_port_res *pr)
1276{
1277 int ret;
1278 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1279
Breno Leitaof76957f2011-01-11 07:45:57 +00001280 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281
Thomas Kleine2878802009-01-21 14:45:57 -08001282 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283
1284 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1285
1286 return ret;
1287}
1288
1289static int ehea_reg_interrupts(struct net_device *dev)
1290{
1291 struct ehea_port *port = netdev_priv(dev);
1292 struct ehea_port_res *pr;
1293 int i, ret;
1294
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295
1296 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1297 dev->name);
1298
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001299 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300 ehea_qp_aff_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001301 0, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001302 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001303 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1304 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001305 goto out_free_qpeq;
1306 }
1307
Joe Perches8c4877a2010-12-13 10:05:14 -08001308 netif_info(port, ifup, dev,
1309 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1310 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001311
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001312
Anton Blanchard723f28e2011-10-14 05:31:01 +00001313 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001314 pr = &port->port_res[i];
1315 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001316 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001317 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001318 ehea_recv_irq_handler,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02001319 0, pr->int_send_name, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001321 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1322 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001323 goto out_free_req;
1324 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001325 netif_info(port, ifup, dev,
1326 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1327 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328 }
1329out:
1330 return ret;
1331
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001332
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001333out_free_req:
1334 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001335 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001336 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001338
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001340 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001341 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001342
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001343 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001344
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345}
1346
1347static void ehea_free_interrupts(struct net_device *dev)
1348{
1349 struct ehea_port *port = netdev_priv(dev);
1350 struct ehea_port_res *pr;
1351 int i;
1352
1353 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001354
Anton Blanchard723f28e2011-10-14 05:31:01 +00001355 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001357 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001358 netif_info(port, intr, dev,
1359 "free send irq for res %d with handle 0x%X\n",
1360 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361 }
1362
1363 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001364 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001365 netif_info(port, intr, dev,
1366 "associated event interrupt for handle 0x%X freed\n",
1367 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001368}
1369
1370static int ehea_configure_port(struct ehea_port *port)
1371{
1372 int ret, i;
1373 u64 hret, mask;
1374 struct hcp_ehea_port_cb0 *cb0;
1375
1376 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001377 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378 if (!cb0)
1379 goto out;
1380
1381 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1382 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1383 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1384 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1385 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1386 PXLY_RC_VLAN_FILTER)
1387 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1388
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001389 for (i = 0; i < port->num_mcs; i++)
1390 if (use_mcs)
1391 cb0->default_qpn_arr[i] =
1392 port->port_res[i].qp->init_attr.qp_nr;
1393 else
1394 cb0->default_qpn_arr[i] =
1395 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001396
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 if (netif_msg_ifup(port))
1398 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1399
1400 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1401 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1402
1403 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1404 port->logical_port_id,
1405 H_PORT_CB0, mask, cb0);
1406 ret = -EIO;
1407 if (hret != H_SUCCESS)
1408 goto out_free;
1409
1410 ret = 0;
1411
1412out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001413 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414out:
1415 return ret;
1416}
1417
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001418static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001420 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001421 struct ehea_adapter *adapter = pr->port->adapter;
1422
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001423 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1424 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001425 goto out;
1426
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001427 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1428 if (ret)
1429 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001430
1431 return 0;
1432
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001433out_free:
1434 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001435out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001436 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001437 return -EIO;
1438}
1439
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001440static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001441{
Joe Perches8e95a202009-12-03 07:58:21 +00001442 if ((ehea_rem_mr(&pr->send_mr)) ||
1443 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001444 return -EIO;
1445 else
1446 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001447}
1448
1449static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1450{
Doug Maxey508d2b52008-01-31 20:20:49 -06001451 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001452
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001453 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001454 if (!q_skba->arr)
1455 return -ENOMEM;
1456
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001457 q_skba->len = max_q_entries;
1458 q_skba->index = 0;
1459 q_skba->os_skbs = 0;
1460
1461 return 0;
1462}
1463
1464static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1465 struct port_res_cfg *pr_cfg, int queue_token)
1466{
1467 struct ehea_adapter *adapter = port->adapter;
1468 enum ehea_eq_type eq_type = EHEA_EQ;
1469 struct ehea_qp_init_attr *init_attr = NULL;
1470 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001471 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1472
1473 tx_bytes = pr->tx_bytes;
1474 tx_packets = pr->tx_packets;
1475 rx_bytes = pr->rx_bytes;
1476 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001477
1478 memset(pr, 0, sizeof(struct ehea_port_res));
1479
Breno Leitaoce45b872010-10-27 08:45:14 +00001480 pr->tx_bytes = rx_bytes;
1481 pr->tx_packets = tx_packets;
1482 pr->rx_bytes = rx_bytes;
1483 pr->rx_packets = rx_packets;
1484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001487 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1488 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001489 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490 goto out_free;
1491 }
1492
1493 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001494 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495 port->logical_port_id);
1496 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001497 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498 goto out_free;
1499 }
1500
1501 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001502 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001503 port->logical_port_id);
1504 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001505 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506 goto out_free;
1507 }
1508
1509 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001510 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1511 pr->send_cq->attr.act_nr_of_cqes,
1512 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001513
1514 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1515 if (!init_attr) {
1516 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001517 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001518 goto out_free;
1519 }
1520
1521 init_attr->low_lat_rq1 = 1;
1522 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1523 init_attr->rq_count = 3;
1524 init_attr->qp_token = queue_token;
1525 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1526 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1527 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1528 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1529 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1530 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1531 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1532 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1533 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1534 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1535 init_attr->port_nr = port->logical_port_id;
1536 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1537 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1538 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1539
1540 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1541 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001542 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 ret = -EIO;
1544 goto out_free;
1545 }
1546
1547 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001548 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",
1549 init_attr->qp_nr,
1550 init_attr->act_nr_send_wqes,
1551 init_attr->act_nr_rwqes_rq1,
1552 init_attr->act_nr_rwqes_rq2,
1553 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001554
Thomas Klein44fb3122008-04-04 15:04:53 +02001555 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1556
1557 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1559 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1560 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1561 if (ret)
1562 goto out_free;
1563
1564 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1565 if (ehea_gen_smrs(pr) != 0) {
1566 ret = -EIO;
1567 goto out_free;
1568 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001569
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1571
1572 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001573
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001574 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001575
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001576 ret = 0;
1577 goto out;
1578
1579out_free:
1580 kfree(init_attr);
1581 vfree(pr->sq_skba.arr);
1582 vfree(pr->rq1_skba.arr);
1583 vfree(pr->rq2_skba.arr);
1584 vfree(pr->rq3_skba.arr);
1585 ehea_destroy_qp(pr->qp);
1586 ehea_destroy_cq(pr->send_cq);
1587 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001588 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001589out:
1590 return ret;
1591}
1592
1593static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1594{
1595 int ret, i;
1596
Hannes Hering357eb462009-08-04 11:48:39 -07001597 if (pr->qp)
1598 netif_napi_del(&pr->napi);
1599
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600 ret = ehea_destroy_qp(pr->qp);
1601
1602 if (!ret) {
1603 ehea_destroy_cq(pr->send_cq);
1604 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001605 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606
1607 for (i = 0; i < pr->rq1_skba.len; i++)
1608 if (pr->rq1_skba.arr[i])
1609 dev_kfree_skb(pr->rq1_skba.arr[i]);
1610
1611 for (i = 0; i < pr->rq2_skba.len; i++)
1612 if (pr->rq2_skba.arr[i])
1613 dev_kfree_skb(pr->rq2_skba.arr[i]);
1614
1615 for (i = 0; i < pr->rq3_skba.len; i++)
1616 if (pr->rq3_skba.arr[i])
1617 dev_kfree_skb(pr->rq3_skba.arr[i]);
1618
1619 for (i = 0; i < pr->sq_skba.len; i++)
1620 if (pr->sq_skba.arr[i])
1621 dev_kfree_skb(pr->sq_skba.arr[i]);
1622
1623 vfree(pr->rq1_skba.arr);
1624 vfree(pr->rq2_skba.arr);
1625 vfree(pr->rq3_skba.arr);
1626 vfree(pr->sq_skba.arr);
1627 ret = ehea_rem_smrs(pr);
1628 }
1629 return ret;
1630}
1631
Anton Blanchard13946f52011-10-14 05:31:06 +00001632static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1633 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634{
Eric Dumazete743d312010-04-14 15:59:40 -07001635 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001636 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1637 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001638 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001639
Anton Blanchard13946f52011-10-14 05:31:06 +00001640 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001641
Anton Blanchard13946f52011-10-14 05:31:06 +00001642 if (skb_is_gso(skb)) {
1643 swqe->tx_control |= EHEA_SWQE_TSO;
1644 swqe->mss = skb_shinfo(skb)->gso_size;
1645 /*
1646 * For TSO packets we only copy the headers into the
1647 * immediate area.
1648 */
1649 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1650 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001651
Anton Blanchard13946f52011-10-14 05:31:06 +00001652 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1653 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1654 swqe->immediate_data_length = immediate_len;
1655
1656 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001657 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001658 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001659 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001660 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001661 swqe->descriptors++;
1662 }
1663 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001664 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001665 swqe->immediate_data_length = skb_data_size;
1666 }
1667}
1668
1669static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1670 struct ehea_swqe *swqe, u32 lkey)
1671{
1672 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1673 skb_frag_t *frag;
1674 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001675
1676 nfrags = skb_shinfo(skb)->nr_frags;
1677 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001678 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001679 sg1entry_contains_frag_data = 0;
1680
Anton Blanchard13946f52011-10-14 05:31:06 +00001681 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001682
1683 /* write descriptors */
1684 if (nfrags > 0) {
1685 if (swqe->descriptors == 0) {
1686 /* sg1entry not yet used */
1687 frag = &skb_shinfo(skb)->frags[0];
1688
1689 /* copy sg1entry data */
1690 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001691 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001692 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001693 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001694 swqe->descriptors++;
1695 sg1entry_contains_frag_data = 1;
1696 }
1697
1698 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1699
1700 frag = &skb_shinfo(skb)->frags[i];
1701 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1702
1703 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001704 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001705 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001706 swqe->descriptors++;
1707 }
1708 }
1709}
1710
1711static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1712{
1713 int ret = 0;
1714 u64 hret;
1715 u8 reg_type;
1716
1717 /* De/Register untagged packets */
1718 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1719 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1720 port->logical_port_id,
1721 reg_type, port->mac_addr, 0, hcallid);
1722 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001723 pr_err("%sregistering bc address failed (tagged)\n",
1724 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001725 ret = -EIO;
1726 goto out_herr;
1727 }
1728
1729 /* De/Register VLAN packets */
1730 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1731 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1732 port->logical_port_id,
1733 reg_type, port->mac_addr, 0, hcallid);
1734 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001735 pr_err("%sregistering bc address failed (vlan)\n",
1736 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001737 ret = -EIO;
1738 }
1739out_herr:
1740 return ret;
1741}
1742
1743static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1744{
1745 struct ehea_port *port = netdev_priv(dev);
1746 struct sockaddr *mac_addr = sa;
1747 struct hcp_ehea_port_cb0 *cb0;
1748 int ret;
1749 u64 hret;
1750
1751 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1752 ret = -EADDRNOTAVAIL;
1753 goto out;
1754 }
1755
Thomas Klein3faf2692009-01-21 14:45:33 -08001756 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001758 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001759 ret = -ENOMEM;
1760 goto out;
1761 }
1762
1763 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1764
1765 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1766
1767 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1768 port->logical_port_id, H_PORT_CB0,
1769 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1770 if (hret != H_SUCCESS) {
1771 ret = -EIO;
1772 goto out_free;
1773 }
1774
1775 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1776
1777 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001778 if (port->state == EHEA_PORT_UP) {
1779 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1780 if (ret)
1781 goto out_upregs;
1782 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783
1784 port->mac_addr = cb0->port_mac_addr << 16;
1785
1786 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001787 if (port->state == EHEA_PORT_UP) {
1788 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1789 if (ret)
1790 goto out_upregs;
1791 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792
1793 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001794
1795out_upregs:
1796 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001798 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799out:
1800 return ret;
1801}
1802
1803static void ehea_promiscuous_error(u64 hret, int enable)
1804{
Thomas Klein7674a582007-01-22 12:54:20 +01001805 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001806 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1807 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001808 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001809 pr_err("failed %sabling promiscuous mode\n",
1810 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001811}
1812
1813static void ehea_promiscuous(struct net_device *dev, int enable)
1814{
1815 struct ehea_port *port = netdev_priv(dev);
1816 struct hcp_ehea_port_cb7 *cb7;
1817 u64 hret;
1818
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001819 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001820 return;
1821
Thomas Klein3faf2692009-01-21 14:45:33 -08001822 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001823 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001824 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001825 goto out;
1826 }
1827
1828 /* Modify Pxs_DUCQPN in CB7 */
1829 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1830
1831 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1832 port->logical_port_id,
1833 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1834 if (hret) {
1835 ehea_promiscuous_error(hret, enable);
1836 goto out;
1837 }
1838
1839 port->promisc = enable;
1840out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001841 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001842}
1843
1844static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1845 u32 hcallid)
1846{
1847 u64 hret;
1848 u8 reg_type;
1849
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001850 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1851 if (mc_mac_addr == 0)
1852 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001853
1854 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1855 port->logical_port_id,
1856 reg_type, mc_mac_addr, 0, hcallid);
1857 if (hret)
1858 goto out;
1859
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001860 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1861 if (mc_mac_addr == 0)
1862 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001863
1864 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1865 port->logical_port_id,
1866 reg_type, mc_mac_addr, 0, hcallid);
1867out:
1868 return hret;
1869}
1870
1871static int ehea_drop_multicast_list(struct net_device *dev)
1872{
1873 struct ehea_port *port = netdev_priv(dev);
1874 struct ehea_mc_list *mc_entry = port->mc_list;
1875 struct list_head *pos;
1876 struct list_head *temp;
1877 int ret = 0;
1878 u64 hret;
1879
1880 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1881 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1882
1883 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1884 H_DEREG_BCMC);
1885 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001886 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001887 ret = -EIO;
1888 }
1889
1890 list_del(pos);
1891 kfree(mc_entry);
1892 }
1893 return ret;
1894}
1895
1896static void ehea_allmulti(struct net_device *dev, int enable)
1897{
1898 struct ehea_port *port = netdev_priv(dev);
1899 u64 hret;
1900
1901 if (!port->allmulti) {
1902 if (enable) {
1903 /* Enable ALLMULTI */
1904 ehea_drop_multicast_list(dev);
1905 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1906 if (!hret)
1907 port->allmulti = 1;
1908 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001909 netdev_err(dev,
1910 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001911 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001912 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001913 if (!enable) {
1914 /* Disable ALLMULTI */
1915 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1916 if (!hret)
1917 port->allmulti = 0;
1918 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001919 netdev_err(dev,
1920 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001922 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001923}
1924
Doug Maxey508d2b52008-01-31 20:20:49 -06001925static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926{
1927 struct ehea_mc_list *ehea_mcl_entry;
1928 u64 hret;
1929
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001930 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001931 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001933
1934 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1935
1936 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1937
1938 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1939 H_REG_BCMC);
1940 if (!hret)
1941 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1942 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001943 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001944 kfree(ehea_mcl_entry);
1945 }
1946}
1947
1948static void ehea_set_multicast_list(struct net_device *dev)
1949{
1950 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001951 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001952 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001953
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001954 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001955
1956 if (dev->flags & IFF_ALLMULTI) {
1957 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001958 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001959 }
1960 ehea_allmulti(dev, 0);
1961
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001962 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001963 ret = ehea_drop_multicast_list(dev);
1964 if (ret) {
1965 /* Dropping the current multicast list failed.
1966 * Enabling ALL_MULTI is the best we can do.
1967 */
1968 ehea_allmulti(dev, 1);
1969 }
1970
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001971 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001972 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1973 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001974 goto out;
1975 }
1976
Jiri Pirko22bedad32010-04-01 21:22:57 +00001977 netdev_for_each_mc_addr(ha, dev)
1978 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001979
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001980 }
1981out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001982 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001983}
1984
1985static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1986{
1987 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1988 return -EINVAL;
1989 dev->mtu = new_mtu;
1990 return 0;
1991}
1992
Anton Blanchardd695c332011-10-14 05:31:05 +00001993static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1994{
1995 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1996
Vlad Yasevichbe1d1482014-08-25 10:34:51 -04001997 if (vlan_get_protocol(skb) != htons(ETH_P_IP))
Anton Blanchardd695c332011-10-14 05:31:05 +00001998 return;
1999
2000 if (skb->ip_summed == CHECKSUM_PARTIAL)
2001 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
2002
2003 swqe->ip_start = skb_network_offset(skb);
2004 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
2005
2006 switch (ip_hdr(skb)->protocol) {
2007 case IPPROTO_UDP:
2008 if (skb->ip_summed == CHECKSUM_PARTIAL)
2009 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2010
2011 swqe->tcp_offset = swqe->ip_end + 1 +
2012 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002013 break;
2014
2015 case IPPROTO_TCP:
2016 if (skb->ip_summed == CHECKSUM_PARTIAL)
2017 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2018
2019 swqe->tcp_offset = swqe->ip_end + 1 +
2020 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002021 break;
2022 }
2023}
2024
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002025static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2026 struct ehea_swqe *swqe, u32 lkey)
2027{
Anton Blanchardd695c332011-10-14 05:31:05 +00002028 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002029
Anton Blanchardd695c332011-10-14 05:31:05 +00002030 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002031
2032 write_swqe2_data(skb, dev, swqe, lkey);
2033}
2034
2035static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2036 struct ehea_swqe *swqe)
2037{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002038 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002039
Anton Blanchardd695c332011-10-14 05:31:05 +00002040 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002041
Anton Blanchard30e2e902011-10-14 05:31:07 +00002042 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002043 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002044 else
2045 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002046
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002047 swqe->immediate_data_length = skb->len;
Eric W. Biedermancfbe4062014-03-15 17:25:48 -07002048 dev_consume_skb_any(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049}
2050
2051static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2052{
2053 struct ehea_port *port = netdev_priv(dev);
2054 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002055 u32 lkey;
2056 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002057 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002058 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002059
Anton Blanchardb9564462011-10-14 05:30:59 +00002060 pr = &port->port_res[skb_get_queue_mapping(skb)];
2061 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002062
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2064 memset(swqe, 0, SWQE_HEADER_SIZE);
2065 atomic_dec(&pr->swqe_avail);
2066
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002067 if (skb_vlan_tag_present(skb)) {
Eric Dumazete5ccd962010-10-26 19:21:07 +00002068 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002069 swqe->vlan_tag = skb_vlan_tag_get(skb);
Eric Dumazete5ccd962010-10-26 19:21:07 +00002070 }
2071
Breno Leitaoce45b872010-10-27 08:45:14 +00002072 pr->tx_packets++;
2073 pr->tx_bytes += skb->len;
2074
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002075 if (skb->len <= SWQE3_MAX_IMM) {
2076 u32 sig_iv = port->sig_comp_iv;
2077 u32 swqe_num = pr->swqe_id_counter;
2078 ehea_xmit3(skb, dev, swqe);
2079 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2080 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2081 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2082 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2083 sig_iv);
2084 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2085 pr->swqe_ll_count = 0;
2086 } else
2087 pr->swqe_ll_count += 1;
2088 } else {
2089 swqe->wr_id =
2090 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2091 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002092 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002093 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2094 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2095
2096 pr->sq_skba.index++;
2097 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2098
2099 lkey = pr->send_mr.lkey;
2100 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002101 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002102 }
2103 pr->swqe_id_counter += 1;
2104
Joe Perches8c4877a2010-12-13 10:05:14 -08002105 netif_info(port, tx_queued, dev,
2106 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2107 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002108 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002110 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002111 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002112 swqe->tx_control |= EHEA_SWQE_PURGE;
2113 }
Thomas Klein44c82152007-07-11 16:32:00 +02002114
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002116
2117 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002118 pr->p_stats.queue_stopped++;
2119 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002121
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002122 return NETDEV_TX_OK;
2123}
2124
Patrick McHardy80d5c362013-04-19 02:04:28 +00002125static int ehea_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126{
2127 struct ehea_port *port = netdev_priv(dev);
2128 struct ehea_adapter *adapter = port->adapter;
2129 struct hcp_ehea_port_cb1 *cb1;
2130 int index;
2131 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002132 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002133
Thomas Klein3faf2692009-01-21 14:45:33 -08002134 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002135 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002136 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002137 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002138 goto out;
2139 }
2140
2141 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2142 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2143 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002144 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002145 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002146 goto out;
2147 }
2148
2149 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002150 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151
2152 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2153 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002154 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002155 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002156 err = -EINVAL;
2157 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002159 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002160 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002161}
2162
Patrick McHardy80d5c362013-04-19 02:04:28 +00002163static int ehea_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164{
2165 struct ehea_port *port = netdev_priv(dev);
2166 struct ehea_adapter *adapter = port->adapter;
2167 struct hcp_ehea_port_cb1 *cb1;
2168 int index;
2169 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002170 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002171
Thomas Klein3faf2692009-01-21 14:45:33 -08002172 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002173 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002174 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002175 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002176 goto out;
2177 }
2178
2179 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2180 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2181 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002182 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002183 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 goto out;
2185 }
2186
2187 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002188 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189
2190 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2191 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002192 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002193 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002194 err = -EINVAL;
2195 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002196out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002197 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002198 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002199}
2200
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002201static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002202{
2203 int ret = -EIO;
2204 u64 hret;
2205 u16 dummy16 = 0;
2206 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002207 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208
Thomas Klein3faf2692009-01-21 14:45:33 -08002209 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002210 if (!cb0) {
2211 ret = -ENOMEM;
2212 goto out;
2213 }
2214
2215 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2216 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2217 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002218 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 goto out;
2220 }
2221
2222 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2223 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2224 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2225 &dummy64, &dummy64, &dummy16, &dummy16);
2226 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002227 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002228 goto out;
2229 }
2230
2231 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2232 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2233 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002234 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235 goto out;
2236 }
2237
2238 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2239 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2240 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2241 &dummy64, &dummy64, &dummy16, &dummy16);
2242 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002243 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002244 goto out;
2245 }
2246
2247 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2248 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2249 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002250 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251 goto out;
2252 }
2253
2254 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2255 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2256 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2257 &dummy64, &dummy64, &dummy16, &dummy16);
2258 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002259 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002260 goto out;
2261 }
2262
2263 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2264 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2265 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002266 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002267 goto out;
2268 }
2269
2270 ret = 0;
2271out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002272 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273 return ret;
2274}
2275
Anton Blanchard723f28e2011-10-14 05:31:01 +00002276static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002277{
2278 int ret, i;
2279 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2280 enum ehea_eq_type eq_type = EHEA_EQ;
2281
2282 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2283 EHEA_MAX_ENTRIES_EQ, 1);
2284 if (!port->qp_eq) {
2285 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002286 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002287 goto out_kill_eq;
2288 }
2289
2290 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002291 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002292 pr_cfg.max_entries_sq = sq_entries;
2293 pr_cfg.max_entries_rq1 = rq1_entries;
2294 pr_cfg.max_entries_rq2 = rq2_entries;
2295 pr_cfg.max_entries_rq3 = rq3_entries;
2296
2297 pr_cfg_small_rx.max_entries_rcq = 1;
2298 pr_cfg_small_rx.max_entries_scq = sq_entries;
2299 pr_cfg_small_rx.max_entries_sq = sq_entries;
2300 pr_cfg_small_rx.max_entries_rq1 = 1;
2301 pr_cfg_small_rx.max_entries_rq2 = 1;
2302 pr_cfg_small_rx.max_entries_rq3 = 1;
2303
2304 for (i = 0; i < def_qps; i++) {
2305 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2306 if (ret)
2307 goto out_clean_pr;
2308 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002309 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002310 ret = ehea_init_port_res(port, &port->port_res[i],
2311 &pr_cfg_small_rx, i);
2312 if (ret)
2313 goto out_clean_pr;
2314 }
2315
2316 return 0;
2317
2318out_clean_pr:
2319 while (--i >= 0)
2320 ehea_clean_portres(port, &port->port_res[i]);
2321
2322out_kill_eq:
2323 ehea_destroy_eq(port->qp_eq);
2324 return ret;
2325}
2326
2327static int ehea_clean_all_portres(struct ehea_port *port)
2328{
2329 int ret = 0;
2330 int i;
2331
Anton Blanchard723f28e2011-10-14 05:31:01 +00002332 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002333 ret |= ehea_clean_portres(port, &port->port_res[i]);
2334
2335 ret |= ehea_destroy_eq(port->qp_eq);
2336
2337 return ret;
2338}
2339
Thomas Klein35cf2e22007-08-06 13:55:14 +02002340static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002341{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002342 if (adapter->active_ports)
2343 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002344
2345 ehea_rem_mr(&adapter->mr);
2346}
2347
Thomas Klein35cf2e22007-08-06 13:55:14 +02002348static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002349{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002350 if (adapter->active_ports)
2351 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002352
2353 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2354}
2355
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356static int ehea_up(struct net_device *dev)
2357{
2358 int ret, i;
2359 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002360
2361 if (port->state == EHEA_PORT_UP)
2362 return 0;
2363
Anton Blanchard723f28e2011-10-14 05:31:01 +00002364 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002366 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002367 goto out;
2368 }
2369
2370 /* Set default QP for this port */
2371 ret = ehea_configure_port(port);
2372 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002373 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002374 goto out_clean_pr;
2375 }
2376
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 ret = ehea_reg_interrupts(dev);
2378 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002379 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002380 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002381 }
2382
Anton Blanchard723f28e2011-10-14 05:31:01 +00002383 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002384 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2385 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002386 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 goto out_free_irqs;
2388 }
2389 }
2390
Doug Maxey508d2b52008-01-31 20:20:49 -06002391 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002392 ret = ehea_fill_port_res(&port->port_res[i]);
2393 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002394 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002395 goto out_free_irqs;
2396 }
2397 }
2398
Thomas Klein21eee2d2008-02-13 16:18:33 +01002399 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2400 if (ret) {
2401 ret = -EIO;
2402 goto out_free_irqs;
2403 }
2404
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002405 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002406
2407 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002408 goto out;
2409
2410out_free_irqs:
2411 ehea_free_interrupts(dev);
2412
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413out_clean_pr:
2414 ehea_clean_all_portres(port);
2415out:
Thomas Klein44c82152007-07-11 16:32:00 +02002416 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002417 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002418
Thomas Klein21eee2d2008-02-13 16:18:33 +01002419 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002420 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002421
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002422 return ret;
2423}
2424
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002425static void port_napi_disable(struct ehea_port *port)
2426{
2427 int i;
2428
Anton Blanchard723f28e2011-10-14 05:31:01 +00002429 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002430 napi_disable(&port->port_res[i].napi);
2431}
2432
2433static void port_napi_enable(struct ehea_port *port)
2434{
2435 int i;
2436
Anton Blanchard723f28e2011-10-14 05:31:01 +00002437 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002438 napi_enable(&port->port_res[i].napi);
2439}
2440
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441static int ehea_open(struct net_device *dev)
2442{
2443 int ret;
2444 struct ehea_port *port = netdev_priv(dev);
2445
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002446 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002447
Joe Perches8c4877a2010-12-13 10:05:14 -08002448 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002449
2450 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002451 if (!ret) {
2452 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002453 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002454 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002456 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002457 schedule_delayed_work(&port->stats_work,
2458 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002459
2460 return ret;
2461}
2462
2463static int ehea_down(struct net_device *dev)
2464{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002465 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002466 struct ehea_port *port = netdev_priv(dev);
2467
2468 if (port->state == EHEA_PORT_DOWN)
2469 return 0;
2470
2471 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002472 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002473 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2474
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002475 ehea_free_interrupts(dev);
2476
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002477 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002478
Thomas Klein21eee2d2008-02-13 16:18:33 +01002479 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002480
Thomas Klein44c82152007-07-11 16:32:00 +02002481 ret = ehea_clean_all_portres(port);
2482 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002483 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002484
Thomas Klein21eee2d2008-02-13 16:18:33 +01002485 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002486
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002487 return ret;
2488}
2489
2490static int ehea_stop(struct net_device *dev)
2491{
2492 int ret;
2493 struct ehea_port *port = netdev_priv(dev);
2494
Joe Perches8c4877a2010-12-13 10:05:14 -08002495 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002496
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002497 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002498 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002499 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002500 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002501 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002502 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002503 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002504 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002505 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002506 return ret;
2507}
2508
Andrew Morton22559c52008-04-18 13:50:39 -07002509static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002510{
2511 struct ehea_qp qp = *orig_qp;
2512 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2513 struct ehea_swqe *swqe;
2514 int wqe_index;
2515 int i;
2516
2517 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2518 swqe = ehea_get_swqe(&qp, &wqe_index);
2519 swqe->tx_control |= EHEA_SWQE_PURGE;
2520 }
2521}
2522
Andrew Morton22559c52008-04-18 13:50:39 -07002523static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002524{
2525 int i;
2526
Anton Blanchard723f28e2011-10-14 05:31:01 +00002527 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002528 struct ehea_port_res *pr = &port->port_res[i];
2529 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002530 int ret;
2531
2532 ret = wait_event_timeout(port->swqe_avail_wq,
2533 atomic_read(&pr->swqe_avail) >= swqe_max,
2534 msecs_to_jiffies(100));
2535
2536 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002537 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002538 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002539 }
2540 }
2541}
2542
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002543static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002544{
2545 struct ehea_port *port = netdev_priv(dev);
2546 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002547 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002548 int ret = -EIO;
2549 int dret;
2550 int i;
2551 u64 hret;
2552 u64 dummy64 = 0;
2553 u16 dummy16 = 0;
2554
Thomas Klein3faf2692009-01-21 14:45:33 -08002555 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002556 if (!cb0) {
2557 ret = -ENOMEM;
2558 goto out;
2559 }
2560
Anton Blanchard723f28e2011-10-14 05:31:01 +00002561 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002562 struct ehea_port_res *pr = &port->port_res[i];
2563 struct ehea_qp *qp = pr->qp;
2564
2565 /* Purge send queue */
2566 ehea_purge_sq(qp);
2567
2568 /* Disable queue pair */
2569 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2570 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2571 cb0);
2572 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002573 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002574 goto out;
2575 }
2576
2577 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2578 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2579
2580 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2581 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2582 1), cb0, &dummy64,
2583 &dummy64, &dummy16, &dummy16);
2584 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002585 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002586 goto out;
2587 }
2588
2589 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2590 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2591 cb0);
2592 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002593 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002594 goto out;
2595 }
2596
2597 /* deregister shared memory regions */
2598 dret = ehea_rem_smrs(pr);
2599 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002600 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002601 goto out;
2602 }
2603 }
2604
2605 ret = 0;
2606out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002607 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002608
2609 return ret;
2610}
2611
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002612static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002613{
2614 struct ehea_qp qp = *orig_qp;
2615 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2616 struct ehea_rwqe *rwqe;
2617 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2618 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2619 struct sk_buff *skb;
2620 u32 lkey = pr->recv_mr.lkey;
2621
2622
2623 int i;
2624 int index;
2625
2626 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2627 rwqe = ehea_get_next_rwqe(&qp, 2);
2628 rwqe->sg_list[0].l_key = lkey;
2629 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2630 skb = skba_rq2[index];
2631 if (skb)
2632 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2633 }
2634
2635 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2636 rwqe = ehea_get_next_rwqe(&qp, 3);
2637 rwqe->sg_list[0].l_key = lkey;
2638 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2639 skb = skba_rq3[index];
2640 if (skb)
2641 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2642 }
2643}
2644
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002645static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002646{
2647 struct ehea_port *port = netdev_priv(dev);
2648 struct ehea_adapter *adapter = port->adapter;
2649 int ret = 0;
2650 int i;
2651
Doug Maxey508d2b52008-01-31 20:20:49 -06002652 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002653 u64 hret;
2654 u64 dummy64 = 0;
2655 u16 dummy16 = 0;
2656
Thomas Klein3faf2692009-01-21 14:45:33 -08002657 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002658 if (!cb0) {
2659 ret = -ENOMEM;
2660 goto out;
2661 }
2662
Anton Blanchard723f28e2011-10-14 05:31:01 +00002663 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002664 struct ehea_port_res *pr = &port->port_res[i];
2665 struct ehea_qp *qp = pr->qp;
2666
2667 ret = ehea_gen_smrs(pr);
2668 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002669 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002670 goto out;
2671 }
2672
2673 ehea_update_rqs(qp, pr);
2674
2675 /* Enable queue pair */
2676 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2677 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2678 cb0);
2679 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002680 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002681 goto out;
2682 }
2683
2684 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2685 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2686
2687 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2688 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2689 1), cb0, &dummy64,
2690 &dummy64, &dummy16, &dummy16);
2691 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002692 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002693 goto out;
2694 }
2695
2696 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2697 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2698 cb0);
2699 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002700 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002701 goto out;
2702 }
2703
2704 /* refill entire queue */
2705 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2706 ehea_refill_rq2(pr, 0);
2707 ehea_refill_rq3(pr, 0);
2708 }
2709out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002710 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002711
2712 return ret;
2713}
2714
David Howellsc4028952006-11-22 14:57:56 +00002715static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716{
2717 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002718 struct ehea_port *port =
2719 container_of(work, struct ehea_port, reset_task);
2720 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002721
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002722 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002724 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002725 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002726
2727 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002728
Thomas Klein44c82152007-07-11 16:32:00 +02002729 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002730
2731 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002732 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002734
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002735 ehea_set_multicast_list(dev);
2736
Joe Perches8c4877a2010-12-13 10:05:14 -08002737 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002738
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002739 port_napi_enable(port);
2740
Anton Blanchardb9564462011-10-14 05:30:59 +00002741 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002742out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002743 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002744 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002745}
2746
Tejun Heo3d6b8922010-12-12 16:45:14 +01002747static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002748{
2749 int ret, i;
2750 struct ehea_adapter *adapter;
2751
Joe Perches8c4877a2010-12-13 10:05:14 -08002752 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002753
2754 list_for_each_entry(adapter, &adapter_list, list)
2755 if (adapter->active_ports) {
2756 /* Shutdown all ports */
2757 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2758 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002759 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002760
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002761 if (!port)
2762 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002763
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002764 dev = port->netdev;
2765
2766 if (dev->flags & IFF_UP) {
2767 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002768 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002769 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002770 ret = ehea_stop_qps(dev);
2771 if (ret) {
2772 mutex_unlock(&port->port_lock);
2773 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002774 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002775 port_napi_disable(port);
2776 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002777 }
Andre Detsch2928db42010-08-17 05:49:12 +00002778 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002779 }
2780
2781 /* Unregister old memory region */
2782 ret = ehea_rem_mr(&adapter->mr);
2783 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002784 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002785 goto out;
2786 }
2787 }
2788
Thomas Klein44c82152007-07-11 16:32:00 +02002789 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2790
2791 list_for_each_entry(adapter, &adapter_list, list)
2792 if (adapter->active_ports) {
2793 /* Register new memory region */
2794 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2795 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002796 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002797 goto out;
2798 }
2799
2800 /* Restart all ports */
2801 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2802 struct ehea_port *port = adapter->port[i];
2803
2804 if (port) {
2805 struct net_device *dev = port->netdev;
2806
2807 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002808 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002809 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002810 if (!ret) {
2811 check_sqs(port);
2812 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002813 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002814 } else {
2815 netdev_err(dev, "Unable to restart QPS\n");
2816 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002817 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002818 }
2819 }
2820 }
2821 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002822 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002823out:
2824 return;
2825}
2826
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002827static void ehea_tx_watchdog(struct net_device *dev)
2828{
2829 struct ehea_port *port = netdev_priv(dev);
2830
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002831 if (netif_carrier_ok(dev) &&
2832 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002833 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002834}
2835
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002836static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002837{
2838 struct hcp_query_ehea *cb;
2839 u64 hret;
2840 int ret;
2841
Thomas Klein3faf2692009-01-21 14:45:33 -08002842 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002843 if (!cb) {
2844 ret = -ENOMEM;
2845 goto out;
2846 }
2847
2848 hret = ehea_h_query_ehea(adapter->handle, cb);
2849
2850 if (hret != H_SUCCESS) {
2851 ret = -EIO;
2852 goto out_herr;
2853 }
2854
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002855 adapter->max_mc_mac = cb->max_mc_mac - 1;
2856 ret = 0;
2857
2858out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002859 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002860out:
2861 return ret;
2862}
2863
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002864static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002865{
2866 struct hcp_ehea_port_cb4 *cb4;
2867 u64 hret;
2868 int ret = 0;
2869
2870 *jumbo = 0;
2871
2872 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002873 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002874 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002875 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002876 ret = -ENOMEM;
2877 goto out;
2878 } else {
2879 hret = ehea_h_query_ehea_port(port->adapter->handle,
2880 port->logical_port_id,
2881 H_PORT_CB4,
2882 H_PORT_CB4_JUMBO, cb4);
2883 if (hret == H_SUCCESS) {
2884 if (cb4->jumbo_frame)
2885 *jumbo = 1;
2886 else {
2887 cb4->jumbo_frame = 1;
2888 hret = ehea_h_modify_ehea_port(port->adapter->
2889 handle,
2890 port->
2891 logical_port_id,
2892 H_PORT_CB4,
2893 H_PORT_CB4_JUMBO,
2894 cb4);
2895 if (hret == H_SUCCESS)
2896 *jumbo = 1;
2897 }
2898 } else
2899 ret = -EINVAL;
2900
Thomas Klein3faf2692009-01-21 14:45:33 -08002901 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002902 }
2903out:
2904 return ret;
2905}
2906
2907static ssize_t ehea_show_port_id(struct device *dev,
2908 struct device_attribute *attr, char *buf)
2909{
2910 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002911 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002912}
2913
2914static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2915 NULL);
2916
Bill Pemberton0297be02012-12-03 09:23:10 -05002917static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002918{
2919 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002920 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002921}
2922
2923static struct device *ehea_register_port(struct ehea_port *port,
2924 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002925{
2926 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002927
Grant Likely61c7a082010-04-13 16:12:29 -07002928 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002929 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002930 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002931
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002932 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002933 port->ofdev.dev.release = logical_port_release;
2934
2935 ret = of_device_register(&port->ofdev);
2936 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002937 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002938 goto out;
2939 }
2940
2941 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002942 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002943 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002944 goto out_unreg_of_dev;
2945 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002946
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002947 return &port->ofdev.dev;
2948
2949out_unreg_of_dev:
2950 of_device_unregister(&port->ofdev);
2951out:
2952 return NULL;
2953}
2954
2955static void ehea_unregister_port(struct ehea_port *port)
2956{
2957 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2958 of_device_unregister(&port->ofdev);
2959}
2960
Thomas Klein086c1b22009-01-21 14:43:59 -08002961static const struct net_device_ops ehea_netdev_ops = {
2962 .ndo_open = ehea_open,
2963 .ndo_stop = ehea_stop,
2964 .ndo_start_xmit = ehea_start_xmit,
2965#ifdef CONFIG_NET_POLL_CONTROLLER
2966 .ndo_poll_controller = ehea_netpoll,
2967#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002968 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002969 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002970 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002971 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002972 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002973 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002974 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2975 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002976};
2977
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002978static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002979 u32 logical_port_id,
2980 struct device_node *dn)
2981{
2982 int ret;
2983 struct net_device *dev;
2984 struct ehea_port *port;
2985 struct device *port_dev;
2986 int jumbo;
2987
2988 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002989 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002990
2991 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002992 ret = -ENOMEM;
2993 goto out_err;
2994 }
2995
2996 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002997
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002998 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999 port->state = EHEA_PORT_DOWN;
3000 port->sig_comp_iv = sq_entries / 10;
3001
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003002 port->adapter = adapter;
3003 port->netdev = dev;
3004 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003005
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003006 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003007
3008 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3009 if (!port->mc_list) {
3010 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003011 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003012 }
3013
3014 INIT_LIST_HEAD(&port->mc_list->list);
3015
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003016 ret = ehea_sense_port_attr(port);
3017 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003018 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003019
Anton Blanchardb9564462011-10-14 05:30:59 +00003020 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003021 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003022
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003023 port_dev = ehea_register_port(port, dn);
3024 if (!port_dev)
3025 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003026
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003027 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003028
3029 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003030 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3031
Thomas Klein086c1b22009-01-21 14:43:59 -08003032 dev->netdev_ops = &ehea_netdev_ops;
3033 ehea_set_ethtool_ops(dev);
3034
David S. Miller55fbbe42013-04-22 19:34:34 -04003035 dev->hw_features = NETIF_F_SG | NETIF_F_TSO |
3036 NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_CTAG_TX;
Eric Dumazet28e24c62013-12-02 08:51:13 -08003037 dev->features = NETIF_F_SG | NETIF_F_TSO |
David S. Miller55fbbe42013-04-22 19:34:34 -04003038 NETIF_F_HIGHDMA | NETIF_F_IP_CSUM |
3039 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
3040 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003041 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3042 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003043 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3044
David Howellsc4028952006-11-22 14:57:56 +00003045 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003046 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003047
Anton Blanchard21ccc792011-05-10 16:17:10 +00003048 init_waitqueue_head(&port->swqe_avail_wq);
3049 init_waitqueue_head(&port->restart_wq);
3050
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003051 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003052 ret = register_netdev(dev);
3053 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003054 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003055 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003056 }
3057
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003058 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003059 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003060 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003061
Joe Perches8c4877a2010-12-13 10:05:14 -08003062 netdev_info(dev, "Jumbo frames are %sabled\n",
3063 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003064
Thomas Klein44c82152007-07-11 16:32:00 +02003065 adapter->active_ports++;
3066
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003067 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003069out_unreg_port:
3070 ehea_unregister_port(port);
3071
3072out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003073 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003074
3075out_free_ethdev:
3076 free_netdev(dev);
3077
3078out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003079 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3080 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003081 return NULL;
3082}
3083
3084static void ehea_shutdown_single_port(struct ehea_port *port)
3085{
Brian King7fb1c2a2008-05-14 09:48:25 -05003086 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003087
3088 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003089 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003090 unregister_netdev(port->netdev);
3091 ehea_unregister_port(port);
3092 kfree(port->mc_list);
3093 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003094 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003095}
3096
3097static int ehea_setup_ports(struct ehea_adapter *adapter)
3098{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003099 struct device_node *lhea_dn;
3100 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003101
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003102 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003104
Grant Likely61c7a082010-04-13 16:12:29 -07003105 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003106 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003107
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003108 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003109 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003111 pr_err("bad device node: eth_dn name=%s\n",
3112 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003113 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003114 }
3115
Thomas Klein1211bb62007-04-26 11:56:43 +02003116 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003117 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003118 of_node_put(eth_dn);
3119 return -EIO;
3120 }
3121
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003122 adapter->port[i] = ehea_setup_single_port(adapter,
3123 *dn_log_port_id,
3124 eth_dn);
3125 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003126 netdev_info(adapter->port[i]->netdev,
3127 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003128 else
3129 ehea_remove_adapter_mr(adapter);
3130
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003132 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003133 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003134}
3135
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003136static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3137 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003138{
3139 struct device_node *lhea_dn;
3140 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003141 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003142
Grant Likely61c7a082010-04-13 16:12:29 -07003143 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003144 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003145
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003146 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003147 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003148 if (dn_log_port_id)
3149 if (*dn_log_port_id == logical_port_id)
3150 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003151 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003152
3153 return NULL;
3154}
3155
3156static ssize_t ehea_probe_port(struct device *dev,
3157 struct device_attribute *attr,
3158 const char *buf, size_t count)
3159{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003160 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161 struct ehea_port *port;
3162 struct device_node *eth_dn = NULL;
3163 int i;
3164
3165 u32 logical_port_id;
3166
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003167 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168
3169 port = ehea_get_port(adapter, logical_port_id);
3170
3171 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003172 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3173 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003174 return -EINVAL;
3175 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003176
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3178
3179 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003180 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003181 return -EINVAL;
3182 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003183
Thomas Klein1211bb62007-04-26 11:56:43 +02003184 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003185 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003186 return -EIO;
3187 }
3188
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003189 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3190
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003191 of_node_put(eth_dn);
3192
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003193 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003194 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003195 if (!adapter->port[i]) {
3196 adapter->port[i] = port;
3197 break;
3198 }
3199
Joe Perches8c4877a2010-12-13 10:05:14 -08003200 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3201 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003202 } else {
3203 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003204 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003205 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206
3207 return (ssize_t) count;
3208}
3209
3210static ssize_t ehea_remove_port(struct device *dev,
3211 struct device_attribute *attr,
3212 const char *buf, size_t count)
3213{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003214 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215 struct ehea_port *port;
3216 int i;
3217 u32 logical_port_id;
3218
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003219 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003220
3221 port = ehea_get_port(adapter, logical_port_id);
3222
3223 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003224 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3225 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226
3227 ehea_shutdown_single_port(port);
3228
Doug Maxey508d2b52008-01-31 20:20:49 -06003229 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 if (adapter->port[i] == port) {
3231 adapter->port[i] = NULL;
3232 break;
3233 }
3234 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003235 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3236 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 return -EINVAL;
3238 }
3239
Thomas Klein1211bb62007-04-26 11:56:43 +02003240 ehea_remove_adapter_mr(adapter);
3241
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242 return (ssize_t) count;
3243}
3244
3245static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3246static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3247
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003248static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003250 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 if (ret)
3252 goto out;
3253
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003254 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003256 return ret;
3257}
3258
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003259static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003261 device_remove_file(&dev->dev, &dev_attr_probe_port);
3262 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003263}
3264
Anton Blanchardaa183322015-02-15 17:44:20 -02003265static int ehea_reboot_notifier(struct notifier_block *nb,
3266 unsigned long action, void *unused)
3267{
3268 if (action == SYS_RESTART) {
3269 pr_info("Reboot: freeing all eHEA resources\n");
3270 ibmebus_unregister_driver(&ehea_driver);
3271 }
3272 return NOTIFY_DONE;
3273}
3274
3275static struct notifier_block ehea_reboot_nb = {
3276 .notifier_call = ehea_reboot_notifier,
3277};
3278
3279static int ehea_mem_notifier(struct notifier_block *nb,
3280 unsigned long action, void *data)
3281{
3282 int ret = NOTIFY_BAD;
3283 struct memory_notify *arg = data;
3284
3285 mutex_lock(&dlpar_mem_lock);
3286
3287 switch (action) {
3288 case MEM_CANCEL_OFFLINE:
3289 pr_info("memory offlining canceled");
3290 /* Fall through: re-add canceled memory block */
3291
3292 case MEM_ONLINE:
3293 pr_info("memory is going online");
3294 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3295 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3296 goto out_unlock;
3297 ehea_rereg_mrs();
3298 break;
3299
3300 case MEM_GOING_OFFLINE:
3301 pr_info("memory is going offline");
3302 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3303 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3304 goto out_unlock;
3305 ehea_rereg_mrs();
3306 break;
3307
3308 default:
3309 break;
3310 }
3311
3312 ehea_update_firmware_handles();
3313 ret = NOTIFY_OK;
3314
3315out_unlock:
3316 mutex_unlock(&dlpar_mem_lock);
3317 return ret;
3318}
3319
3320static struct notifier_block ehea_mem_nb = {
3321 .notifier_call = ehea_mem_notifier,
3322};
3323
3324static void ehea_crash_handler(void)
3325{
3326 int i;
3327
3328 if (ehea_fw_handles.arr)
3329 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3330 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3331 ehea_fw_handles.arr[i].fwh,
3332 FORCE_FREE);
3333
3334 if (ehea_bcmc_regs.arr)
3335 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3336 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3337 ehea_bcmc_regs.arr[i].port_id,
3338 ehea_bcmc_regs.arr[i].reg_type,
3339 ehea_bcmc_regs.arr[i].macaddr,
3340 0, H_DEREG_BCMC);
3341}
3342
3343static atomic_t ehea_memory_hooks_registered;
3344
3345/* Register memory hooks on probe of first adapter */
3346static int ehea_register_memory_hooks(void)
3347{
3348 int ret = 0;
3349
Michael Ellerman3051f392015-04-24 15:52:32 +10003350 if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
Anton Blanchardaa183322015-02-15 17:44:20 -02003351 return 0;
3352
3353 ret = ehea_create_busmap();
3354 if (ret) {
3355 pr_info("ehea_create_busmap failed\n");
3356 goto out;
3357 }
3358
3359 ret = register_reboot_notifier(&ehea_reboot_nb);
3360 if (ret) {
3361 pr_info("register_reboot_notifier failed\n");
3362 goto out;
3363 }
3364
3365 ret = register_memory_notifier(&ehea_mem_nb);
3366 if (ret) {
3367 pr_info("register_memory_notifier failed\n");
3368 goto out2;
3369 }
3370
3371 ret = crash_shutdown_register(ehea_crash_handler);
3372 if (ret) {
3373 pr_info("crash_shutdown_register failed\n");
3374 goto out3;
3375 }
3376
3377 return 0;
3378
3379out3:
3380 unregister_memory_notifier(&ehea_mem_nb);
3381out2:
3382 unregister_reboot_notifier(&ehea_reboot_nb);
3383out:
Michael Ellerman3051f392015-04-24 15:52:32 +10003384 atomic_dec(&ehea_memory_hooks_registered);
Anton Blanchardaa183322015-02-15 17:44:20 -02003385 return ret;
3386}
3387
3388static void ehea_unregister_memory_hooks(void)
3389{
Michael Ellerman3051f392015-04-24 15:52:32 +10003390 /* Only remove the hooks if we've registered them */
3391 if (atomic_read(&ehea_memory_hooks_registered) == 0)
Anton Blanchardaa183322015-02-15 17:44:20 -02003392 return;
3393
3394 unregister_reboot_notifier(&ehea_reboot_nb);
3395 if (crash_shutdown_unregister(ehea_crash_handler))
3396 pr_info("failed unregistering crash handler\n");
3397 unregister_memory_notifier(&ehea_mem_nb);
3398}
3399
Rob Herringc45640e2013-04-20 21:51:08 -05003400static int ehea_probe_adapter(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003401{
3402 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003403 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003404 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003405 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406
Anton Blanchardaa183322015-02-15 17:44:20 -02003407 ret = ehea_register_memory_hooks();
3408 if (ret)
3409 return ret;
3410
Grant Likely61c7a082010-04-13 16:12:29 -07003411 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003412 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003413 return -EINVAL;
3414 }
3415
Himangi Saraogi09b38aa2014-05-28 19:53:09 +05303416 adapter = devm_kzalloc(&dev->dev, sizeof(*adapter), GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003417 if (!adapter) {
3418 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003419 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003420 goto out;
3421 }
3422
Thomas Klein44c82152007-07-11 16:32:00 +02003423 list_add(&adapter->list, &adapter_list);
3424
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003425 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003426
Grant Likely61c7a082010-04-13 16:12:29 -07003427 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003428 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003429 if (adapter_handle)
3430 adapter->handle = *adapter_handle;
3431
3432 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003433 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003434 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003435 ret = -ENODEV;
3436 goto out_free_ad;
3437 }
3438
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003439 adapter->pd = EHEA_PD_ID;
3440
Jingoo Han8513fbd2013-05-23 00:52:31 +00003441 platform_set_drvdata(dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003442
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003443
3444 /* initialize adapter and ports */
3445 /* get adapter properties */
3446 ret = ehea_sense_adapter_attr(adapter);
3447 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003448 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003449 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003451
3452 adapter->neq = ehea_create_eq(adapter,
3453 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3454 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003455 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003456 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003457 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458 }
3459
3460 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3461 (unsigned long)adapter);
3462
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003463 ret = ehea_create_device_sysfs(dev);
3464 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003465 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003466
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003467 ret = ehea_setup_ports(adapter);
3468 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003469 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003470 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471 }
3472
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003473 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Michael Opdenacker46c915f2013-09-12 05:46:11 +02003474 ehea_interrupt_neq, 0,
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003475 "ehea_neq", adapter);
3476 if (ret) {
3477 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3478 goto out_shutdown_ports;
3479 }
3480
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003481 /* Handle any events that might be pending. */
3482 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003483
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003484 ret = 0;
3485 goto out;
3486
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003487out_shutdown_ports:
3488 for (i = 0; i < EHEA_MAX_PORTS; i++)
3489 if (adapter->port[i]) {
3490 ehea_shutdown_single_port(adapter->port[i]);
3491 adapter->port[i] = NULL;
3492 }
3493
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003494out_rem_dev_sysfs:
3495 ehea_remove_device_sysfs(dev);
3496
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003497out_kill_eq:
3498 ehea_destroy_eq(adapter->neq);
3499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003500out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003501 list_del(&adapter->list);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003502
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003504 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003505
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 return ret;
3507}
3508
Bill Pemberton0297be02012-12-03 09:23:10 -05003509static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510{
Jingoo Han8513fbd2013-05-23 00:52:31 +00003511 struct ehea_adapter *adapter = platform_get_drvdata(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003512 int i;
3513
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003514 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003515 if (adapter->port[i]) {
3516 ehea_shutdown_single_port(adapter->port[i]);
3517 adapter->port[i] = NULL;
3518 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003519
3520 ehea_remove_device_sysfs(dev);
3521
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003522 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003523 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003524
3525 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003526 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003527 list_del(&adapter->list);
Thomas Klein44c82152007-07-11 16:32:00 +02003528
Thomas Klein21eee2d2008-02-13 16:18:33 +01003529 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 return 0;
3532}
3533
3534static int check_module_parm(void)
3535{
3536 int ret = 0;
3537
3538 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3539 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003540 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003541 ret = -EINVAL;
3542 }
3543 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3544 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003545 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546 ret = -EINVAL;
3547 }
3548 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3549 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003550 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003551 ret = -EINVAL;
3552 }
3553 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3554 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003555 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003556 ret = -EINVAL;
3557 }
3558
3559 return ret;
3560}
3561
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003562static ssize_t ehea_show_capabilities(struct device_driver *drv,
3563 char *buf)
3564{
3565 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3566}
3567
3568static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3569 ehea_show_capabilities, NULL);
3570
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003571static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003572{
3573 int ret;
3574
Joe Perches8c4877a2010-12-13 10:05:14 -08003575 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003576
Thomas Klein21eee2d2008-02-13 16:18:33 +01003577 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3578 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3579
Daniel Walker9f71a562008-03-28 14:41:26 -07003580 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003581 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003583 ret = check_module_parm();
3584 if (ret)
3585 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003586
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003587 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003588 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003589 pr_err("failed registering eHEA device driver on ebus\n");
Anton Blanchardaa183322015-02-15 17:44:20 -02003590 goto out;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003591 }
3592
3593 ret = driver_create_file(&ehea_driver.driver,
3594 &driver_attr_capabilities);
3595 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003596 pr_err("failed to register capabilities attribute, ret=%d\n",
3597 ret);
Anton Blanchardaa183322015-02-15 17:44:20 -02003598 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003599 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003600
Thomas Klein21eee2d2008-02-13 16:18:33 +01003601 return ret;
3602
Thomas Klein21eee2d2008-02-13 16:18:33 +01003603out2:
Anton Blanchardaa183322015-02-15 17:44:20 -02003604 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003605out:
3606 return ret;
3607}
3608
3609static void __exit ehea_module_exit(void)
3610{
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003611 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003612 ibmebus_unregister_driver(&ehea_driver);
Anton Blanchardaa183322015-02-15 17:44:20 -02003613 ehea_unregister_memory_hooks();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003614 kfree(ehea_fw_handles.arr);
3615 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003616 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003617}
3618
3619module_init(ehea_module_init);
3620module_exit(ehea_module_exit);