blob: 19b64de7124b9ae51e0649b887bc1b208c7627b3 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 * linux/drivers/net/ethernet/ibm/ehea/ehea_main.c
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
75MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000090MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
91 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Doug Maxey508d2b52008-01-31 20:20:49 -060093static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020094static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080095static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070096static DEFINE_MUTEX(dlpar_mem_lock);
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +000097static struct ehea_fw_handle_array ehea_fw_handles;
98static struct ehea_bcmc_reg_array ehea_bcmc_regs;
Thomas Klein21eee2d2008-02-13 16:18:33 +010099
Thomas Kleind1dea382007-04-26 11:56:13 +0200100
Bill Pemberton0297be02012-12-03 09:23:10 -0500101static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Bill Pemberton0297be02012-12-03 09:23:10 -0500104static int ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200105
106static struct of_device_id ehea_device_table[] = {
107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {},
112};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100113MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000115static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700116 .driver = {
117 .name = "ehea",
118 .owner = THIS_MODULE,
119 .of_match_table = ehea_device_table,
120 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .probe = ehea_probe_adapter,
122 .remove = ehea_remove,
123};
124
Doug Maxey508d2b52008-01-31 20:20:49 -0600125void ehea_dump(void *adr, int len, char *msg)
126{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200127 int x;
128 unsigned char *deb = adr;
129 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 deb += 16;
133 }
134}
135
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +0000136static void ehea_schedule_port_reset(struct ehea_port *port)
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100137{
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
139 schedule_work(&port->reset_task);
140}
141
Thomas Klein21eee2d2008-02-13 16:18:33 +0100142static void ehea_update_firmware_handles(void)
143{
144 struct ehea_fw_handle_entry *arr = NULL;
145 struct ehea_adapter *adapter;
146 int num_adapters = 0;
147 int num_ports = 0;
148 int num_portres = 0;
149 int i = 0;
150 int num_fw_handles, k, l;
151
152 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700153 mutex_lock(&ehea_fw_handles.lock);
154
Thomas Klein21eee2d2008-02-13 16:18:33 +0100155 list_for_each_entry(adapter, &adapter_list, list) {
156 num_adapters++;
157
158 for (k = 0; k < EHEA_MAX_PORTS; k++) {
159 struct ehea_port *port = adapter->port[k];
160
161 if (!port || (port->state != EHEA_PORT_UP))
162 continue;
163
164 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000165 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 }
167 }
168
169 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
170 num_ports * EHEA_NUM_PORT_FW_HANDLES +
171 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
172
173 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000174 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700176 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100177 } else
178 goto out_update;
179
180 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 if (num_adapters == 0)
182 break;
183
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
Joe Perches8e95a202009-12-03 07:58:21 +0000187 if (!port || (port->state != EHEA_PORT_UP) ||
188 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 continue;
190
Anton Blanchard723f28e2011-10-14 05:31:01 +0000191 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 struct ehea_port_res *pr = &port->port_res[l];
193
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->qp->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_cq->fw_handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_cq->fw_handle;
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = pr->eq->fw_handle;
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->send_mr.handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->recv_mr.handle;
206 }
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700209 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222out_update:
223 kfree(ehea_fw_handles.arr);
224 ehea_fw_handles.arr = arr;
225 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226out:
227 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228}
229
230static void ehea_update_bcmc_registrations(void)
231{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 struct ehea_bcmc_reg_entry *arr = NULL;
234 struct ehea_adapter *adapter;
235 struct ehea_mc_list *mc_entry;
236 int num_registrations = 0;
237 int i = 0;
238 int k;
239
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
241
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 /* Determine number of registrations */
243 list_for_each_entry(adapter, &adapter_list, list)
244 for (k = 0; k < EHEA_MAX_PORTS; k++) {
245 struct ehea_port *port = adapter->port[k];
246
247 if (!port || (port->state != EHEA_PORT_UP))
248 continue;
249
250 num_registrations += 2; /* Broadcast registrations */
251
252 list_for_each_entry(mc_entry, &port->mc_list->list,list)
253 num_registrations += 2;
254 }
255
256 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000257 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100258 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700259 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100260 } else
261 goto out_update;
262
263 list_for_each_entry(adapter, &adapter_list, list) {
264 for (k = 0; k < EHEA_MAX_PORTS; k++) {
265 struct ehea_port *port = adapter->port[k];
266
267 if (!port || (port->state != EHEA_PORT_UP))
268 continue;
269
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 if (num_registrations == 0)
271 goto out_update;
272
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 arr[i].adh = adapter->handle;
274 arr[i].port_id = port->logical_port_id;
275 arr[i].reg_type = EHEA_BCMC_BROADCAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = port->mac_addr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_BROADCAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285
286 list_for_each_entry(mc_entry,
287 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700288 if (num_registrations == 0)
289 goto out_update;
290
Thomas Klein21eee2d2008-02-13 16:18:33 +0100291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000293 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100294 EHEA_BCMC_UNTAGGED;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000295 if (mc_entry->macaddr == 0)
296 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297 arr[i++].macaddr = mc_entry->macaddr;
298
299 arr[i].adh = adapter->handle;
300 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000301 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 EHEA_BCMC_VLANID_ALL;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000303 if (mc_entry->macaddr == 0)
304 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700306 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100307 }
308 }
309 }
310
311out_update:
312 kfree(ehea_bcmc_regs.arr);
313 ehea_bcmc_regs.arr = arr;
314 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315out:
316 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317}
318
Anton Blanchard239c5622011-10-14 05:31:09 +0000319static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
320 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200321{
322 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000323 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324 int i;
325
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000326 for (i = 0; i < port->num_def_qps; i++) {
327 rx_packets += port->port_res[i].rx_packets;
328 rx_bytes += port->port_res[i].rx_bytes;
329 }
330
Anton Blanchard723f28e2011-10-14 05:31:01 +0000331 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000332 tx_packets += port->port_res[i].tx_packets;
333 tx_bytes += port->port_res[i].tx_bytes;
334 }
335
336 stats->tx_packets = tx_packets;
337 stats->rx_bytes = rx_bytes;
338 stats->tx_bytes = tx_bytes;
339 stats->rx_packets = rx_packets;
340
Eric Dumazet09c1d442012-03-06 19:46:41 +0000341 stats->multicast = port->stats.multicast;
342 stats->rx_errors = port->stats.rx_errors;
343 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000344}
345
346static void ehea_update_stats(struct work_struct *work)
347{
348 struct ehea_port *port =
349 container_of(work, struct ehea_port, stats_work.work);
350 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000351 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000352 struct hcp_ehea_port_cb2 *cb2;
353 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200354
Brian King3d8009c2010-06-30 11:59:12 +0000355 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000357 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
358 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 }
360
361 hret = ehea_h_query_ehea_port(port->adapter->handle,
362 port->logical_port_id,
363 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
364 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800365 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 goto out_herr;
367 }
368
369 if (netif_msg_hw(port))
370 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 stats->multicast = cb2->rxmcp;
373 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374
375out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800376 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000377resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000378 schedule_delayed_work(&port->stats_work,
379 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800405 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200406 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200407 break;
408 }
409 }
410 index--;
411 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200414
415 if (adder == 0)
416 return;
417
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200419 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420}
421
Thomas Kleine2878802009-01-21 14:45:57 -0800422static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
425 struct net_device *dev = pr->port->netdev;
426 int i;
427
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000428 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800429 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000430 return;
431 }
432
433 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000435 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800436 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800437 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439 }
440 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000441 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200442}
443
444static int ehea_refill_rq_def(struct ehea_port_res *pr,
445 struct ehea_q_skb_arr *q_skba, int rq_nr,
446 int num_wqes, int wqe_type, int packet_size)
447{
448 struct net_device *dev = pr->port->netdev;
449 struct ehea_qp *qp = pr->qp;
450 struct sk_buff **skb_arr = q_skba->arr;
451 struct ehea_rwqe *rwqe;
452 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 int ret = 0;
455
456 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
460 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463
464 index = q_skba->index;
465 max_index_mask = q_skba->len - 1;
466 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200467 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000468 struct sk_buff *skb;
469
470 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800473 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800474 netdev_info(pr->port->netdev,
475 "rq%i ran dry - no mem for skb\n",
476 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800477 ret = -ENOMEM;
478 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 break;
480 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481
482 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200483 tmp_addr = ehea_map_vaddr(skb->data);
484 if (tmp_addr == -1) {
485 dev_kfree_skb(skb);
486 q_skba->os_skbs = fill_wqes - i;
487 ret = 0;
488 break;
489 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490
491 rwqe = ehea_get_next_rwqe(qp, rq_nr);
492 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200493 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200495 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496 rwqe->sg_list[0].len = packet_size;
497 rwqe->data_segments = 1;
498
499 index++;
500 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200501 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 }
Thomas Klein44c82152007-07-11 16:32:00 +0200503
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200505 if (adder == 0)
506 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200507
508 /* Ring doorbell */
509 iosync();
510 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200511 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200513 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200514out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515 return ret;
516}
517
518
519static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
520{
521 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
522 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000523 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524}
525
526
527static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
528{
529 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
530 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200532}
533
534static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
535{
536 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
537 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
538 return 0;
539 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
540 (cqe->header_length == 0))
541 return 0;
542 return -EINVAL;
543}
544
545static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000546 struct sk_buff *skb, struct ehea_cqe *cqe,
547 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200548{
549 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
550
551 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200552 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000553
554 /* The packet was not an IPV4 packet so a complemented checksum was
555 calculated. The value is found in the Internet Checksum field. */
556 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
557 skb->ip_summed = CHECKSUM_COMPLETE;
558 skb->csum = csum_unfold(~cqe->inet_checksum_value);
559 } else
560 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000561
562 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200563}
564
565static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
566 int arr_len,
567 struct ehea_cqe *cqe)
568{
569 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
570 struct sk_buff *skb;
571 void *pref;
572 int x;
573
574 x = skb_index + 1;
575 x &= (arr_len - 1);
576
577 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700578 if (pref) {
579 prefetchw(pref);
580 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200581
Hannes Hering0b2febf2009-05-04 11:06:37 -0700582 pref = (skb_array[x]->data);
583 prefetch(pref);
584 prefetch(pref + EHEA_CACHE_LINE);
585 prefetch(pref + EHEA_CACHE_LINE * 2);
586 prefetch(pref + EHEA_CACHE_LINE * 3);
587 }
588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200589 skb = skb_array[skb_index];
590 skb_array[skb_index] = NULL;
591 return skb;
592}
593
594static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
595 int arr_len, int wqe_index)
596{
597 struct sk_buff *skb;
598 void *pref;
599 int x;
600
601 x = wqe_index + 1;
602 x &= (arr_len - 1);
603
604 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700605 if (pref) {
606 prefetchw(pref);
607 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200608
Hannes Hering0b2febf2009-05-04 11:06:37 -0700609 pref = (skb_array[x]->data);
610 prefetchw(pref);
611 prefetchw(pref + EHEA_CACHE_LINE);
612 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200613
614 skb = skb_array[wqe_index];
615 skb_array[wqe_index] = NULL;
616 return skb;
617}
618
619static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
620 struct ehea_cqe *cqe, int *processed_rq2,
621 int *processed_rq3)
622{
623 struct sk_buff *skb;
624
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100625 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
626 pr->p_stats.err_tcp_cksum++;
627 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
628 pr->p_stats.err_ip_cksum++;
629 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
630 pr->p_stats.err_frame_crc++;
631
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200632 if (rq == 2) {
633 *processed_rq2 += 1;
634 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
635 dev_kfree_skb(skb);
636 } else if (rq == 3) {
637 *processed_rq3 += 1;
638 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
639 dev_kfree_skb(skb);
640 }
641
642 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100643 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800644 pr_err("Critical receive error for QP %d. Resetting port.\n",
645 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100646 ehea_dump(cqe, sizeof(*cqe), "CQE");
647 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100648 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200649 return 1;
650 }
651
652 return 0;
653}
654
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700655static int ehea_proc_rwqes(struct net_device *dev,
656 struct ehea_port_res *pr,
657 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200658{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100659 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200660 struct ehea_qp *qp = pr->qp;
661 struct ehea_cqe *cqe;
662 struct sk_buff *skb;
663 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
664 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
665 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
666 int skb_arr_rq1_len = pr->rq1_skba.len;
667 int skb_arr_rq2_len = pr->rq2_skba.len;
668 int skb_arr_rq3_len = pr->rq3_skba.len;
669 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000670 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700671 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672
673 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
674 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200675
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200676 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700677 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200678 ehea_inc_rq1(qp);
679 processed_rq1++;
680 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200681 if (netif_msg_rx_status(port))
682 ehea_dump(cqe, sizeof(*cqe), "CQE");
683
684 last_wqe_index = wqe_index;
685 rmb();
686 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600687 if (rq == 1) {
688 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200689 skb = get_skb_by_index_ll(skb_arr_rq1,
690 skb_arr_rq1_len,
691 wqe_index);
692 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800693 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800694 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100695
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700696 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200697 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000698 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800699 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000701 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200702 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600703 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200704 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000705 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600706 } else if (rq == 2) {
707 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 skb = get_skb_by_index(skb_arr_rq2,
709 skb_arr_rq2_len, cqe);
710 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800711 netif_err(port, rx_err, dev,
712 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 break;
714 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000715 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600717 } else {
718 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 skb = get_skb_by_index(skb_arr_rq3,
720 skb_arr_rq3_len, cqe);
721 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800722 netif_err(port, rx_err, dev,
723 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 break;
725 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000726 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727 processed_rq3++;
728 }
729
Breno Leitaoce45b872010-10-27 08:45:14 +0000730 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000731
732 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
733 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
734
735 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100736 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100737 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200738 port_reset = ehea_treat_poll_error(pr, rq, cqe,
739 &processed_rq2,
740 &processed_rq3);
741 if (port_reset)
742 break;
743 }
744 cqe = ehea_poll_rq1(qp, &wqe_index);
745 }
746
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000748 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749
750 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
751 ehea_refill_rq2(pr, processed_rq2);
752 ehea_refill_rq3(pr, processed_rq3);
753
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700754 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755}
756
Andre Detsch2928db42010-08-17 05:49:12 +0000757#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
758
759static void reset_sq_restart_flag(struct ehea_port *port)
760{
761 int i;
762
Anton Blanchard723f28e2011-10-14 05:31:01 +0000763 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000764 struct ehea_port_res *pr = &port->port_res[i];
765 pr->sq_restart_flag = 0;
766 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000767 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000768}
769
770static void check_sqs(struct ehea_port *port)
771{
772 struct ehea_swqe *swqe;
773 int swqe_index;
774 int i, k;
775
Anton Blanchard723f28e2011-10-14 05:31:01 +0000776 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000777 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000778 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000779 k = 0;
780 swqe = ehea_get_swqe(pr->qp, &swqe_index);
781 memset(swqe, 0, SWQE_HEADER_SIZE);
782 atomic_dec(&pr->swqe_avail);
783
784 swqe->tx_control |= EHEA_SWQE_PURGE;
785 swqe->wr_id = SWQE_RESTART_CHECK;
786 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
787 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
788 swqe->immediate_data_length = 80;
789
790 ehea_post_swqe(pr->qp, swqe);
791
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000792 ret = wait_event_timeout(port->restart_wq,
793 pr->sq_restart_flag == 0,
794 msecs_to_jiffies(100));
795
796 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800797 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000798 ehea_schedule_port_reset(pr->port);
799 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000800 }
801 }
Andre Detsch2928db42010-08-17 05:49:12 +0000802}
803
804
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100805static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200806{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100807 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200808 struct ehea_cq *send_cq = pr->send_cq;
809 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100810 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200811 int cqe_counter = 0;
812 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100813 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000814 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
815 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100817 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600818 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100819 ehea_inc_cq(send_cq);
820
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200821 cqe_counter++;
822 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000823
824 if (cqe->wr_id == SWQE_RESTART_CHECK) {
825 pr->sq_restart_flag = 1;
826 swqe_av++;
827 break;
828 }
829
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800831 pr_err("Bad send completion status=0x%04X\n",
832 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000833
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200834 if (netif_msg_tx_err(pr->port))
835 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000836
837 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800838 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000839 ehea_schedule_port_reset(pr->port);
840 break;
841 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200842 }
843
844 if (netif_msg_tx_done(pr->port))
845 ehea_dump(cqe, sizeof(*cqe), "CQE");
846
847 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100848 == EHEA_SWQE2_TYPE)) {
849
850 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
851 skb = pr->sq_skba.arr[index];
852 dev_kfree_skb(skb);
853 pr->sq_skba.arr[index] = NULL;
854 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200855
856 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
857 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100858
859 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700860 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861
862 ehea_update_feca(send_cq, cqe_counter);
863 atomic_add(swqe_av, &pr->swqe_avail);
864
Anton Blanchardb9564462011-10-14 05:30:59 +0000865 if (unlikely(netif_tx_queue_stopped(txq) &&
866 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
867 __netif_tx_lock(txq, smp_processor_id());
868 if (netif_tx_queue_stopped(txq) &&
869 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
870 netif_tx_wake_queue(txq);
871 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200872 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000873
Breno Leitao5b27d422010-10-05 13:16:22 +0000874 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100876 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877}
878
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700879#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100880
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700881static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882{
Doug Maxey508d2b52008-01-31 20:20:49 -0600883 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
884 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700885 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100886 struct ehea_cqe *cqe;
887 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000888 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700889 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100890
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700891 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000892 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893
Anton Blanchard222ca962011-10-14 05:31:00 +0000894 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800895 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100896 ehea_reset_cq_ep(pr->recv_cq);
897 ehea_reset_cq_ep(pr->send_cq);
898 ehea_reset_cq_n1(pr->recv_cq);
899 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000900 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
902 cqe_skb = ehea_poll_cq(pr->send_cq);
903
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100904 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700905 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100906
Ben Hutchings288379f2009-01-19 16:43:59 -0800907 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700908 return rx;
909
910 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
911 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100912 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100913
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700914 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200915}
916
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200917#ifdef CONFIG_NET_POLL_CONTROLLER
918static void ehea_netpoll(struct net_device *dev)
919{
920 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700921 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200922
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700923 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800924 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200925}
926#endif
927
David Howells7d12e782006-10-05 14:55:46 +0100928static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929{
930 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931
Ben Hutchings288379f2009-01-19 16:43:59 -0800932 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100933
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200934 return IRQ_HANDLED;
935}
936
David Howells7d12e782006-10-05 14:55:46 +0100937static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200938{
939 struct ehea_port *port = param;
940 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100941 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200942 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000943 u64 resource_type, aer, aerr;
944 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200945
946 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100947
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200948 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200949 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800950 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
951 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100952
953 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000954
955 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
956 &aer, &aerr);
957
958 if (resource_type == EHEA_AER_RESTYPE_QP) {
959 if ((aer & EHEA_AER_RESET_MASK) ||
960 (aerr & EHEA_AERR_RESET_MASK))
961 reset_port = 1;
962 } else
963 reset_port = 1; /* Reset in case of CQ or EQ error */
964
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100965 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966 }
967
Thomas Kleinea96cea2010-04-20 23:10:55 +0000968 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800969 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000970 ehea_schedule_port_reset(port);
971 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973 return IRQ_HANDLED;
974}
975
976static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
977 int logical_port)
978{
979 int i;
980
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100981 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100982 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200983 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100984 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 return NULL;
986}
987
988int ehea_sense_port_attr(struct ehea_port *port)
989{
990 int ret;
991 u64 hret;
992 struct hcp_ehea_port_cb0 *cb0;
993
Doug Maxey508d2b52008-01-31 20:20:49 -0600994 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800995 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600996 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800997 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 ret = -ENOMEM;
999 goto out;
1000 }
1001
1002 hret = ehea_h_query_ehea_port(port->adapter->handle,
1003 port->logical_port_id, H_PORT_CB0,
1004 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1005 cb0);
1006 if (hret != H_SUCCESS) {
1007 ret = -EIO;
1008 goto out_free;
1009 }
1010
1011 /* MAC address */
1012 port->mac_addr = cb0->port_mac_addr << 16;
1013
Doug Maxey508d2b52008-01-31 20:20:49 -06001014 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001015 ret = -EADDRNOTAVAIL;
1016 goto out_free;
1017 }
1018
1019 /* Port speed */
1020 switch (cb0->port_speed) {
1021 case H_SPEED_10M_H:
1022 port->port_speed = EHEA_SPEED_10M;
1023 port->full_duplex = 0;
1024 break;
1025 case H_SPEED_10M_F:
1026 port->port_speed = EHEA_SPEED_10M;
1027 port->full_duplex = 1;
1028 break;
1029 case H_SPEED_100M_H:
1030 port->port_speed = EHEA_SPEED_100M;
1031 port->full_duplex = 0;
1032 break;
1033 case H_SPEED_100M_F:
1034 port->port_speed = EHEA_SPEED_100M;
1035 port->full_duplex = 1;
1036 break;
1037 case H_SPEED_1G_F:
1038 port->port_speed = EHEA_SPEED_1G;
1039 port->full_duplex = 1;
1040 break;
1041 case H_SPEED_10G_F:
1042 port->port_speed = EHEA_SPEED_10G;
1043 port->full_duplex = 1;
1044 break;
1045 default:
1046 port->port_speed = 0;
1047 port->full_duplex = 0;
1048 break;
1049 }
1050
Thomas Kleine919b592007-01-22 12:53:20 +01001051 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001052 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001053
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001054 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001055 if (use_mcs)
1056 port->num_def_qps = cb0->num_default_qps;
1057 else
1058 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001059
1060 if (!port->num_def_qps) {
1061 ret = -EINVAL;
1062 goto out_free;
1063 }
1064
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001065 ret = 0;
1066out_free:
1067 if (ret || netif_msg_probe(port))
1068 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001069 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001070out:
1071 return ret;
1072}
1073
1074int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1075{
1076 struct hcp_ehea_port_cb4 *cb4;
1077 u64 hret;
1078 int ret = 0;
1079
Thomas Klein3faf2692009-01-21 14:45:33 -08001080 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001081 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001082 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001083 ret = -ENOMEM;
1084 goto out;
1085 }
1086
1087 cb4->port_speed = port_speed;
1088
1089 netif_carrier_off(port->netdev);
1090
1091 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1092 port->logical_port_id,
1093 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1094 if (hret == H_SUCCESS) {
1095 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1096
1097 hret = ehea_h_query_ehea_port(port->adapter->handle,
1098 port->logical_port_id,
1099 H_PORT_CB4, H_PORT_CB4_SPEED,
1100 cb4);
1101 if (hret == H_SUCCESS) {
1102 switch (cb4->port_speed) {
1103 case H_SPEED_10M_H:
1104 port->port_speed = EHEA_SPEED_10M;
1105 port->full_duplex = 0;
1106 break;
1107 case H_SPEED_10M_F:
1108 port->port_speed = EHEA_SPEED_10M;
1109 port->full_duplex = 1;
1110 break;
1111 case H_SPEED_100M_H:
1112 port->port_speed = EHEA_SPEED_100M;
1113 port->full_duplex = 0;
1114 break;
1115 case H_SPEED_100M_F:
1116 port->port_speed = EHEA_SPEED_100M;
1117 port->full_duplex = 1;
1118 break;
1119 case H_SPEED_1G_F:
1120 port->port_speed = EHEA_SPEED_1G;
1121 port->full_duplex = 1;
1122 break;
1123 case H_SPEED_10G_F:
1124 port->port_speed = EHEA_SPEED_10G;
1125 port->full_duplex = 1;
1126 break;
1127 default:
1128 port->port_speed = 0;
1129 port->full_duplex = 0;
1130 break;
1131 }
1132 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001133 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 ret = -EIO;
1135 }
1136 } else {
1137 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001138 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 ret = -EPERM;
1140 } else {
1141 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001142 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001143 }
1144 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001145 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1146 netif_carrier_on(port->netdev);
1147
Thomas Klein3faf2692009-01-21 14:45:33 -08001148 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001149out:
1150 return ret;
1151}
1152
1153static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1154{
1155 int ret;
1156 u8 ec;
1157 u8 portnum;
1158 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001159 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001160
1161 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1162 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1163 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001164 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001165
1166 switch (ec) {
1167 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1168
1169 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001170 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001171 break;
1172 }
1173
1174 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001175 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001176 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001177 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001179 break;
1180 }
1181
Joe Perches8c4877a2010-12-13 10:05:14 -08001182 netif_info(port, link, dev,
1183 "Logical port up: %dMbps %s Duplex\n",
1184 port->port_speed,
1185 port->full_duplex == 1 ?
1186 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001187
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 netif_carrier_on(dev);
1189 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001190 }
1191 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001192 if (netif_carrier_ok(dev)) {
1193 netif_info(port, link, dev,
1194 "Logical port down\n");
1195 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001196 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 }
1198
1199 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001200 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001201 netif_info(port, link, dev,
1202 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001203 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001204 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001205 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001206 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001207 netif_info(port, link, dev,
1208 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001209 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001210 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211 }
1212
1213 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001214 netdev_info(dev,
1215 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001217 netdev_info(dev,
1218 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001219
1220 break;
1221 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001222 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 break;
1224 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 netdev_info(dev, "Port malfunction\n");
1226 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001227 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001228 break;
1229 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001230 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231 break;
1232 }
1233}
1234
1235static void ehea_neq_tasklet(unsigned long data)
1236{
Doug Maxey508d2b52008-01-31 20:20:49 -06001237 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238 struct ehea_eqe *eqe;
1239 u64 event_mask;
1240
1241 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001242 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243
1244 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001245 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246 ehea_parse_eqe(adapter, eqe->entry);
1247 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001248 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 }
1250
1251 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1252 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1253 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1254
1255 ehea_h_reset_events(adapter->handle,
1256 adapter->neq->fw_handle, event_mask);
1257}
1258
David Howells7d12e782006-10-05 14:55:46 +01001259static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001260{
1261 struct ehea_adapter *adapter = param;
1262 tasklet_hi_schedule(&adapter->neq_tasklet);
1263 return IRQ_HANDLED;
1264}
1265
1266
1267static int ehea_fill_port_res(struct ehea_port_res *pr)
1268{
1269 int ret;
1270 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1271
Breno Leitaof76957f2011-01-11 07:45:57 +00001272 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273
Thomas Kleine2878802009-01-21 14:45:57 -08001274 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001275
1276 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1277
1278 return ret;
1279}
1280
1281static int ehea_reg_interrupts(struct net_device *dev)
1282{
1283 struct ehea_port *port = netdev_priv(dev);
1284 struct ehea_port_res *pr;
1285 int i, ret;
1286
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287
1288 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1289 dev->name);
1290
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001291 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001293 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001295 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1296 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001297 goto out_free_qpeq;
1298 }
1299
Joe Perches8c4877a2010-12-13 10:05:14 -08001300 netif_info(port, ifup, dev,
1301 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1302 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304
Anton Blanchard723f28e2011-10-14 05:31:01 +00001305 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001306 pr = &port->port_res[i];
1307 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001308 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001309 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001310 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001311 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001312 pr);
1313 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001314 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1315 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001316 goto out_free_req;
1317 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001318 netif_info(port, ifup, dev,
1319 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1320 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001321 }
1322out:
1323 return ret;
1324
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326out_free_req:
1327 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001328 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001329 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001333 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001335
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001337
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001338}
1339
1340static void ehea_free_interrupts(struct net_device *dev)
1341{
1342 struct ehea_port *port = netdev_priv(dev);
1343 struct ehea_port_res *pr;
1344 int i;
1345
1346 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001347
Anton Blanchard723f28e2011-10-14 05:31:01 +00001348 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001350 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001351 netif_info(port, intr, dev,
1352 "free send irq for res %d with handle 0x%X\n",
1353 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 }
1355
1356 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001357 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001358 netif_info(port, intr, dev,
1359 "associated event interrupt for handle 0x%X freed\n",
1360 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361}
1362
1363static int ehea_configure_port(struct ehea_port *port)
1364{
1365 int ret, i;
1366 u64 hret, mask;
1367 struct hcp_ehea_port_cb0 *cb0;
1368
1369 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001370 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001371 if (!cb0)
1372 goto out;
1373
1374 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1375 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1376 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1377 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1378 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1379 PXLY_RC_VLAN_FILTER)
1380 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1381
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001382 for (i = 0; i < port->num_mcs; i++)
1383 if (use_mcs)
1384 cb0->default_qpn_arr[i] =
1385 port->port_res[i].qp->init_attr.qp_nr;
1386 else
1387 cb0->default_qpn_arr[i] =
1388 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390 if (netif_msg_ifup(port))
1391 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1392
1393 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1394 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1395
1396 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1397 port->logical_port_id,
1398 H_PORT_CB0, mask, cb0);
1399 ret = -EIO;
1400 if (hret != H_SUCCESS)
1401 goto out_free;
1402
1403 ret = 0;
1404
1405out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001406 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407out:
1408 return ret;
1409}
1410
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001411static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001413 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 struct ehea_adapter *adapter = pr->port->adapter;
1415
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001416 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1417 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418 goto out;
1419
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001420 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1421 if (ret)
1422 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423
1424 return 0;
1425
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001426out_free:
1427 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001429 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001430 return -EIO;
1431}
1432
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001433static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434{
Joe Perches8e95a202009-12-03 07:58:21 +00001435 if ((ehea_rem_mr(&pr->send_mr)) ||
1436 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001437 return -EIO;
1438 else
1439 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001440}
1441
1442static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1443{
Doug Maxey508d2b52008-01-31 20:20:49 -06001444 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001446 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001447 if (!q_skba->arr)
1448 return -ENOMEM;
1449
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001450 q_skba->len = max_q_entries;
1451 q_skba->index = 0;
1452 q_skba->os_skbs = 0;
1453
1454 return 0;
1455}
1456
1457static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1458 struct port_res_cfg *pr_cfg, int queue_token)
1459{
1460 struct ehea_adapter *adapter = port->adapter;
1461 enum ehea_eq_type eq_type = EHEA_EQ;
1462 struct ehea_qp_init_attr *init_attr = NULL;
1463 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001464 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1465
1466 tx_bytes = pr->tx_bytes;
1467 tx_packets = pr->tx_packets;
1468 rx_bytes = pr->rx_bytes;
1469 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001470
1471 memset(pr, 0, sizeof(struct ehea_port_res));
1472
Breno Leitaoce45b872010-10-27 08:45:14 +00001473 pr->tx_bytes = rx_bytes;
1474 pr->tx_packets = tx_packets;
1475 pr->rx_bytes = rx_bytes;
1476 pr->rx_packets = rx_packets;
1477
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001480 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1481 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001482 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 goto out_free;
1484 }
1485
1486 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001487 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001488 port->logical_port_id);
1489 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001490 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491 goto out_free;
1492 }
1493
1494 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001495 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496 port->logical_port_id);
1497 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001498 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001499 goto out_free;
1500 }
1501
1502 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001503 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1504 pr->send_cq->attr.act_nr_of_cqes,
1505 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506
1507 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1508 if (!init_attr) {
1509 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001510 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511 goto out_free;
1512 }
1513
1514 init_attr->low_lat_rq1 = 1;
1515 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1516 init_attr->rq_count = 3;
1517 init_attr->qp_token = queue_token;
1518 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1519 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1520 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1521 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1522 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1523 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1524 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1525 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1526 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1527 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1528 init_attr->port_nr = port->logical_port_id;
1529 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1530 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1531 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1532
1533 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1534 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001535 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001536 ret = -EIO;
1537 goto out_free;
1538 }
1539
1540 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001541 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",
1542 init_attr->qp_nr,
1543 init_attr->act_nr_send_wqes,
1544 init_attr->act_nr_rwqes_rq1,
1545 init_attr->act_nr_rwqes_rq2,
1546 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547
Thomas Klein44fb3122008-04-04 15:04:53 +02001548 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1549
1550 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1552 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1553 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1554 if (ret)
1555 goto out_free;
1556
1557 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1558 if (ehea_gen_smrs(pr) != 0) {
1559 ret = -EIO;
1560 goto out_free;
1561 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1564
1565 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001566
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001567 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001568
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001569 ret = 0;
1570 goto out;
1571
1572out_free:
1573 kfree(init_attr);
1574 vfree(pr->sq_skba.arr);
1575 vfree(pr->rq1_skba.arr);
1576 vfree(pr->rq2_skba.arr);
1577 vfree(pr->rq3_skba.arr);
1578 ehea_destroy_qp(pr->qp);
1579 ehea_destroy_cq(pr->send_cq);
1580 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001581 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001582out:
1583 return ret;
1584}
1585
1586static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1587{
1588 int ret, i;
1589
Hannes Hering357eb462009-08-04 11:48:39 -07001590 if (pr->qp)
1591 netif_napi_del(&pr->napi);
1592
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001593 ret = ehea_destroy_qp(pr->qp);
1594
1595 if (!ret) {
1596 ehea_destroy_cq(pr->send_cq);
1597 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001598 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599
1600 for (i = 0; i < pr->rq1_skba.len; i++)
1601 if (pr->rq1_skba.arr[i])
1602 dev_kfree_skb(pr->rq1_skba.arr[i]);
1603
1604 for (i = 0; i < pr->rq2_skba.len; i++)
1605 if (pr->rq2_skba.arr[i])
1606 dev_kfree_skb(pr->rq2_skba.arr[i]);
1607
1608 for (i = 0; i < pr->rq3_skba.len; i++)
1609 if (pr->rq3_skba.arr[i])
1610 dev_kfree_skb(pr->rq3_skba.arr[i]);
1611
1612 for (i = 0; i < pr->sq_skba.len; i++)
1613 if (pr->sq_skba.arr[i])
1614 dev_kfree_skb(pr->sq_skba.arr[i]);
1615
1616 vfree(pr->rq1_skba.arr);
1617 vfree(pr->rq2_skba.arr);
1618 vfree(pr->rq3_skba.arr);
1619 vfree(pr->sq_skba.arr);
1620 ret = ehea_rem_smrs(pr);
1621 }
1622 return ret;
1623}
1624
Anton Blanchard13946f52011-10-14 05:31:06 +00001625static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1626 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627{
Eric Dumazete743d312010-04-14 15:59:40 -07001628 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001629 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1630 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001631 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632
Anton Blanchard13946f52011-10-14 05:31:06 +00001633 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634
Anton Blanchard13946f52011-10-14 05:31:06 +00001635 if (skb_is_gso(skb)) {
1636 swqe->tx_control |= EHEA_SWQE_TSO;
1637 swqe->mss = skb_shinfo(skb)->gso_size;
1638 /*
1639 * For TSO packets we only copy the headers into the
1640 * immediate area.
1641 */
1642 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1643 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001644
Anton Blanchard13946f52011-10-14 05:31:06 +00001645 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1646 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1647 swqe->immediate_data_length = immediate_len;
1648
1649 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001651 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001652 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001653 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 swqe->descriptors++;
1655 }
1656 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001657 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001658 swqe->immediate_data_length = skb_data_size;
1659 }
1660}
1661
1662static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1663 struct ehea_swqe *swqe, u32 lkey)
1664{
1665 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1666 skb_frag_t *frag;
1667 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001668
1669 nfrags = skb_shinfo(skb)->nr_frags;
1670 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001671 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001672 sg1entry_contains_frag_data = 0;
1673
Anton Blanchard13946f52011-10-14 05:31:06 +00001674 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001675
1676 /* write descriptors */
1677 if (nfrags > 0) {
1678 if (swqe->descriptors == 0) {
1679 /* sg1entry not yet used */
1680 frag = &skb_shinfo(skb)->frags[0];
1681
1682 /* copy sg1entry data */
1683 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001684 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001685 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001686 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001687 swqe->descriptors++;
1688 sg1entry_contains_frag_data = 1;
1689 }
1690
1691 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1692
1693 frag = &skb_shinfo(skb)->frags[i];
1694 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1695
1696 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001697 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001698 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001699 swqe->descriptors++;
1700 }
1701 }
1702}
1703
1704static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1705{
1706 int ret = 0;
1707 u64 hret;
1708 u8 reg_type;
1709
1710 /* De/Register untagged packets */
1711 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1712 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1713 port->logical_port_id,
1714 reg_type, port->mac_addr, 0, hcallid);
1715 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001716 pr_err("%sregistering bc address failed (tagged)\n",
1717 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001718 ret = -EIO;
1719 goto out_herr;
1720 }
1721
1722 /* De/Register VLAN packets */
1723 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1724 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1725 port->logical_port_id,
1726 reg_type, port->mac_addr, 0, hcallid);
1727 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001728 pr_err("%sregistering bc address failed (vlan)\n",
1729 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001730 ret = -EIO;
1731 }
1732out_herr:
1733 return ret;
1734}
1735
1736static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1737{
1738 struct ehea_port *port = netdev_priv(dev);
1739 struct sockaddr *mac_addr = sa;
1740 struct hcp_ehea_port_cb0 *cb0;
1741 int ret;
1742 u64 hret;
1743
1744 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1745 ret = -EADDRNOTAVAIL;
1746 goto out;
1747 }
1748
Thomas Klein3faf2692009-01-21 14:45:33 -08001749 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001751 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001752 ret = -ENOMEM;
1753 goto out;
1754 }
1755
1756 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1757
1758 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1759
1760 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1761 port->logical_port_id, H_PORT_CB0,
1762 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1763 if (hret != H_SUCCESS) {
1764 ret = -EIO;
1765 goto out_free;
1766 }
1767
1768 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1769
1770 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001771 if (port->state == EHEA_PORT_UP) {
1772 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1773 if (ret)
1774 goto out_upregs;
1775 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001776
1777 port->mac_addr = cb0->port_mac_addr << 16;
1778
1779 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001780 if (port->state == EHEA_PORT_UP) {
1781 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1782 if (ret)
1783 goto out_upregs;
1784 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785
1786 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001787
1788out_upregs:
1789 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001791 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792out:
1793 return ret;
1794}
1795
1796static void ehea_promiscuous_error(u64 hret, int enable)
1797{
Thomas Klein7674a582007-01-22 12:54:20 +01001798 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001799 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1800 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001801 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001802 pr_err("failed %sabling promiscuous mode\n",
1803 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001804}
1805
1806static void ehea_promiscuous(struct net_device *dev, int enable)
1807{
1808 struct ehea_port *port = netdev_priv(dev);
1809 struct hcp_ehea_port_cb7 *cb7;
1810 u64 hret;
1811
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001812 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001813 return;
1814
Thomas Klein3faf2692009-01-21 14:45:33 -08001815 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001816 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001817 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818 goto out;
1819 }
1820
1821 /* Modify Pxs_DUCQPN in CB7 */
1822 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1823
1824 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1825 port->logical_port_id,
1826 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1827 if (hret) {
1828 ehea_promiscuous_error(hret, enable);
1829 goto out;
1830 }
1831
1832 port->promisc = enable;
1833out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001834 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001835}
1836
1837static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1838 u32 hcallid)
1839{
1840 u64 hret;
1841 u8 reg_type;
1842
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001843 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1844 if (mc_mac_addr == 0)
1845 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001846
1847 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1848 port->logical_port_id,
1849 reg_type, mc_mac_addr, 0, hcallid);
1850 if (hret)
1851 goto out;
1852
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001853 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1854 if (mc_mac_addr == 0)
1855 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001856
1857 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1858 port->logical_port_id,
1859 reg_type, mc_mac_addr, 0, hcallid);
1860out:
1861 return hret;
1862}
1863
1864static int ehea_drop_multicast_list(struct net_device *dev)
1865{
1866 struct ehea_port *port = netdev_priv(dev);
1867 struct ehea_mc_list *mc_entry = port->mc_list;
1868 struct list_head *pos;
1869 struct list_head *temp;
1870 int ret = 0;
1871 u64 hret;
1872
1873 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1874 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1875
1876 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1877 H_DEREG_BCMC);
1878 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001879 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001880 ret = -EIO;
1881 }
1882
1883 list_del(pos);
1884 kfree(mc_entry);
1885 }
1886 return ret;
1887}
1888
1889static void ehea_allmulti(struct net_device *dev, int enable)
1890{
1891 struct ehea_port *port = netdev_priv(dev);
1892 u64 hret;
1893
1894 if (!port->allmulti) {
1895 if (enable) {
1896 /* Enable ALLMULTI */
1897 ehea_drop_multicast_list(dev);
1898 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1899 if (!hret)
1900 port->allmulti = 1;
1901 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001902 netdev_err(dev,
1903 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001904 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001905 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906 if (!enable) {
1907 /* Disable ALLMULTI */
1908 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1909 if (!hret)
1910 port->allmulti = 0;
1911 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001912 netdev_err(dev,
1913 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001915 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001916}
1917
Doug Maxey508d2b52008-01-31 20:20:49 -06001918static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919{
1920 struct ehea_mc_list *ehea_mcl_entry;
1921 u64 hret;
1922
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001923 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001924 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001925 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926 return;
1927 }
1928
1929 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1930
1931 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1932
1933 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1934 H_REG_BCMC);
1935 if (!hret)
1936 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1937 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001938 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001939 kfree(ehea_mcl_entry);
1940 }
1941}
1942
1943static void ehea_set_multicast_list(struct net_device *dev)
1944{
1945 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001946 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001947 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001949 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001950
1951 if (dev->flags & IFF_ALLMULTI) {
1952 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001953 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001954 }
1955 ehea_allmulti(dev, 0);
1956
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001957 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001958 ret = ehea_drop_multicast_list(dev);
1959 if (ret) {
1960 /* Dropping the current multicast list failed.
1961 * Enabling ALL_MULTI is the best we can do.
1962 */
1963 ehea_allmulti(dev, 1);
1964 }
1965
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001966 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001967 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1968 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001969 goto out;
1970 }
1971
Jiri Pirko22bedad32010-04-01 21:22:57 +00001972 netdev_for_each_mc_addr(ha, dev)
1973 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001974
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001975 }
1976out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001977 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001978}
1979
1980static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1981{
1982 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1983 return -EINVAL;
1984 dev->mtu = new_mtu;
1985 return 0;
1986}
1987
Anton Blanchardd695c332011-10-14 05:31:05 +00001988static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1989{
1990 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1991
1992 if (skb->protocol != htons(ETH_P_IP))
1993 return;
1994
1995 if (skb->ip_summed == CHECKSUM_PARTIAL)
1996 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1997
1998 swqe->ip_start = skb_network_offset(skb);
1999 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
2000
2001 switch (ip_hdr(skb)->protocol) {
2002 case IPPROTO_UDP:
2003 if (skb->ip_summed == CHECKSUM_PARTIAL)
2004 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2005
2006 swqe->tcp_offset = swqe->ip_end + 1 +
2007 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002008 break;
2009
2010 case IPPROTO_TCP:
2011 if (skb->ip_summed == CHECKSUM_PARTIAL)
2012 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2013
2014 swqe->tcp_offset = swqe->ip_end + 1 +
2015 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002016 break;
2017 }
2018}
2019
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002020static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2021 struct ehea_swqe *swqe, u32 lkey)
2022{
Anton Blanchardd695c332011-10-14 05:31:05 +00002023 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002024
Anton Blanchardd695c332011-10-14 05:31:05 +00002025 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002026
2027 write_swqe2_data(skb, dev, swqe, lkey);
2028}
2029
2030static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2031 struct ehea_swqe *swqe)
2032{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002034
Anton Blanchardd695c332011-10-14 05:31:05 +00002035 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002036
Anton Blanchard30e2e902011-10-14 05:31:07 +00002037 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002038 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002039 else
2040 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002041
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002042 swqe->immediate_data_length = skb->len;
2043 dev_kfree_skb(skb);
2044}
2045
2046static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2047{
2048 struct ehea_port *port = netdev_priv(dev);
2049 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002050 u32 lkey;
2051 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002052 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002053 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054
Anton Blanchardb9564462011-10-14 05:30:59 +00002055 pr = &port->port_res[skb_get_queue_mapping(skb)];
2056 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002057
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002058 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2059 memset(swqe, 0, SWQE_HEADER_SIZE);
2060 atomic_dec(&pr->swqe_avail);
2061
Eric Dumazete5ccd962010-10-26 19:21:07 +00002062 if (vlan_tx_tag_present(skb)) {
2063 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2064 swqe->vlan_tag = vlan_tx_tag_get(skb);
2065 }
2066
Breno Leitaoce45b872010-10-27 08:45:14 +00002067 pr->tx_packets++;
2068 pr->tx_bytes += skb->len;
2069
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002070 if (skb->len <= SWQE3_MAX_IMM) {
2071 u32 sig_iv = port->sig_comp_iv;
2072 u32 swqe_num = pr->swqe_id_counter;
2073 ehea_xmit3(skb, dev, swqe);
2074 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2075 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2076 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2077 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2078 sig_iv);
2079 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2080 pr->swqe_ll_count = 0;
2081 } else
2082 pr->swqe_ll_count += 1;
2083 } else {
2084 swqe->wr_id =
2085 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2086 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002087 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002088 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2089 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2090
2091 pr->sq_skba.index++;
2092 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2093
2094 lkey = pr->send_mr.lkey;
2095 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002096 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002097 }
2098 pr->swqe_id_counter += 1;
2099
Joe Perches8c4877a2010-12-13 10:05:14 -08002100 netif_info(port, tx_queued, dev,
2101 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2102 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002103 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002104
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002105 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002106 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002107 swqe->tx_control |= EHEA_SWQE_PURGE;
2108 }
Thomas Klein44c82152007-07-11 16:32:00 +02002109
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111
2112 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002113 pr->p_stats.queue_stopped++;
2114 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002116
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117 return NETDEV_TX_OK;
2118}
2119
Jiri Pirko8e586132011-12-08 19:52:37 -05002120static int ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002121{
2122 struct ehea_port *port = netdev_priv(dev);
2123 struct ehea_adapter *adapter = port->adapter;
2124 struct hcp_ehea_port_cb1 *cb1;
2125 int index;
2126 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002127 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128
Thomas Klein3faf2692009-01-21 14:45:33 -08002129 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002130 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002131 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002132 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002133 goto out;
2134 }
2135
2136 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2137 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2138 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002139 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002140 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002141 goto out;
2142 }
2143
2144 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002145 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002146
2147 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2148 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002149 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002150 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002151 err = -EINVAL;
2152 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002154 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002155 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002156}
2157
Jiri Pirko8e586132011-12-08 19:52:37 -05002158static int ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002159{
2160 struct ehea_port *port = netdev_priv(dev);
2161 struct ehea_adapter *adapter = port->adapter;
2162 struct hcp_ehea_port_cb1 *cb1;
2163 int index;
2164 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002165 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002166
Thomas Klein3faf2692009-01-21 14:45:33 -08002167 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002168 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002169 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002170 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002171 goto out;
2172 }
2173
2174 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2175 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2176 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002177 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002178 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002179 goto out;
2180 }
2181
2182 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002183 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184
2185 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2186 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002187 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002188 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002189 err = -EINVAL;
2190 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002191out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002192 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002193 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002194}
2195
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002196static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002197{
2198 int ret = -EIO;
2199 u64 hret;
2200 u16 dummy16 = 0;
2201 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002202 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002203
Thomas Klein3faf2692009-01-21 14:45:33 -08002204 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002205 if (!cb0) {
2206 ret = -ENOMEM;
2207 goto out;
2208 }
2209
2210 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2211 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2212 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002213 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002214 goto out;
2215 }
2216
2217 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2218 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2219 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2220 &dummy64, &dummy64, &dummy16, &dummy16);
2221 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002222 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002223 goto out;
2224 }
2225
2226 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2227 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2228 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002229 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002230 goto out;
2231 }
2232
2233 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2234 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2235 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2236 &dummy64, &dummy64, &dummy16, &dummy16);
2237 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002238 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002239 goto out;
2240 }
2241
2242 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2243 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2244 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002245 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002246 goto out;
2247 }
2248
2249 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2250 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2251 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2252 &dummy64, &dummy64, &dummy16, &dummy16);
2253 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002254 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002255 goto out;
2256 }
2257
2258 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2259 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2260 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002261 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002262 goto out;
2263 }
2264
2265 ret = 0;
2266out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002267 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268 return ret;
2269}
2270
Anton Blanchard723f28e2011-10-14 05:31:01 +00002271static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002272{
2273 int ret, i;
2274 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2275 enum ehea_eq_type eq_type = EHEA_EQ;
2276
2277 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2278 EHEA_MAX_ENTRIES_EQ, 1);
2279 if (!port->qp_eq) {
2280 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002281 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002282 goto out_kill_eq;
2283 }
2284
2285 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002286 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002287 pr_cfg.max_entries_sq = sq_entries;
2288 pr_cfg.max_entries_rq1 = rq1_entries;
2289 pr_cfg.max_entries_rq2 = rq2_entries;
2290 pr_cfg.max_entries_rq3 = rq3_entries;
2291
2292 pr_cfg_small_rx.max_entries_rcq = 1;
2293 pr_cfg_small_rx.max_entries_scq = sq_entries;
2294 pr_cfg_small_rx.max_entries_sq = sq_entries;
2295 pr_cfg_small_rx.max_entries_rq1 = 1;
2296 pr_cfg_small_rx.max_entries_rq2 = 1;
2297 pr_cfg_small_rx.max_entries_rq3 = 1;
2298
2299 for (i = 0; i < def_qps; i++) {
2300 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2301 if (ret)
2302 goto out_clean_pr;
2303 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002304 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002305 ret = ehea_init_port_res(port, &port->port_res[i],
2306 &pr_cfg_small_rx, i);
2307 if (ret)
2308 goto out_clean_pr;
2309 }
2310
2311 return 0;
2312
2313out_clean_pr:
2314 while (--i >= 0)
2315 ehea_clean_portres(port, &port->port_res[i]);
2316
2317out_kill_eq:
2318 ehea_destroy_eq(port->qp_eq);
2319 return ret;
2320}
2321
2322static int ehea_clean_all_portres(struct ehea_port *port)
2323{
2324 int ret = 0;
2325 int i;
2326
Anton Blanchard723f28e2011-10-14 05:31:01 +00002327 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 ret |= ehea_clean_portres(port, &port->port_res[i]);
2329
2330 ret |= ehea_destroy_eq(port->qp_eq);
2331
2332 return ret;
2333}
2334
Thomas Klein35cf2e22007-08-06 13:55:14 +02002335static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002336{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002337 if (adapter->active_ports)
2338 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002339
2340 ehea_rem_mr(&adapter->mr);
2341}
2342
Thomas Klein35cf2e22007-08-06 13:55:14 +02002343static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002344{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002345 if (adapter->active_ports)
2346 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002347
2348 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2349}
2350
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002351static int ehea_up(struct net_device *dev)
2352{
2353 int ret, i;
2354 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355
2356 if (port->state == EHEA_PORT_UP)
2357 return 0;
2358
Anton Blanchard723f28e2011-10-14 05:31:01 +00002359 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002360 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002361 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362 goto out;
2363 }
2364
2365 /* Set default QP for this port */
2366 ret = ehea_configure_port(port);
2367 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002368 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369 goto out_clean_pr;
2370 }
2371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002372 ret = ehea_reg_interrupts(dev);
2373 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002374 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002375 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002376 }
2377
Anton Blanchard723f28e2011-10-14 05:31:01 +00002378 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002379 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2380 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002381 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382 goto out_free_irqs;
2383 }
2384 }
2385
Doug Maxey508d2b52008-01-31 20:20:49 -06002386 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 ret = ehea_fill_port_res(&port->port_res[i]);
2388 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002389 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002390 goto out_free_irqs;
2391 }
2392 }
2393
Thomas Klein21eee2d2008-02-13 16:18:33 +01002394 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2395 if (ret) {
2396 ret = -EIO;
2397 goto out_free_irqs;
2398 }
2399
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002400 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002401
2402 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002403 goto out;
2404
2405out_free_irqs:
2406 ehea_free_interrupts(dev);
2407
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002408out_clean_pr:
2409 ehea_clean_all_portres(port);
2410out:
Thomas Klein44c82152007-07-11 16:32:00 +02002411 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002412 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002413
Thomas Klein21eee2d2008-02-13 16:18:33 +01002414 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002415 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002416
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002417 return ret;
2418}
2419
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002420static void port_napi_disable(struct ehea_port *port)
2421{
2422 int i;
2423
Anton Blanchard723f28e2011-10-14 05:31:01 +00002424 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002425 napi_disable(&port->port_res[i].napi);
2426}
2427
2428static void port_napi_enable(struct ehea_port *port)
2429{
2430 int i;
2431
Anton Blanchard723f28e2011-10-14 05:31:01 +00002432 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002433 napi_enable(&port->port_res[i].napi);
2434}
2435
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436static int ehea_open(struct net_device *dev)
2437{
2438 int ret;
2439 struct ehea_port *port = netdev_priv(dev);
2440
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002441 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002442
Joe Perches8c4877a2010-12-13 10:05:14 -08002443 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444
2445 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002446 if (!ret) {
2447 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002448 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002449 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002450
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002451 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002452 schedule_delayed_work(&port->stats_work,
2453 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454
2455 return ret;
2456}
2457
2458static int ehea_down(struct net_device *dev)
2459{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002460 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002461 struct ehea_port *port = netdev_priv(dev);
2462
2463 if (port->state == EHEA_PORT_DOWN)
2464 return 0;
2465
2466 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002467 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002468 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2469
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 ehea_free_interrupts(dev);
2471
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002472 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002473
Thomas Klein21eee2d2008-02-13 16:18:33 +01002474 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002475
Thomas Klein44c82152007-07-11 16:32:00 +02002476 ret = ehea_clean_all_portres(port);
2477 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002478 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002479
Thomas Klein21eee2d2008-02-13 16:18:33 +01002480 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002481
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002482 return ret;
2483}
2484
2485static int ehea_stop(struct net_device *dev)
2486{
2487 int ret;
2488 struct ehea_port *port = netdev_priv(dev);
2489
Joe Perches8c4877a2010-12-13 10:05:14 -08002490 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002491
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002492 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002493 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002494 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002495 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002496 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002497 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002498 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002499 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002500 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501 return ret;
2502}
2503
Andrew Morton22559c52008-04-18 13:50:39 -07002504static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002505{
2506 struct ehea_qp qp = *orig_qp;
2507 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2508 struct ehea_swqe *swqe;
2509 int wqe_index;
2510 int i;
2511
2512 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2513 swqe = ehea_get_swqe(&qp, &wqe_index);
2514 swqe->tx_control |= EHEA_SWQE_PURGE;
2515 }
2516}
2517
Andrew Morton22559c52008-04-18 13:50:39 -07002518static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002519{
2520 int i;
2521
Anton Blanchard723f28e2011-10-14 05:31:01 +00002522 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002523 struct ehea_port_res *pr = &port->port_res[i];
2524 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002525 int ret;
2526
2527 ret = wait_event_timeout(port->swqe_avail_wq,
2528 atomic_read(&pr->swqe_avail) >= swqe_max,
2529 msecs_to_jiffies(100));
2530
2531 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002532 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002533 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002534 }
2535 }
2536}
2537
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002538static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002539{
2540 struct ehea_port *port = netdev_priv(dev);
2541 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002542 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002543 int ret = -EIO;
2544 int dret;
2545 int i;
2546 u64 hret;
2547 u64 dummy64 = 0;
2548 u16 dummy16 = 0;
2549
Thomas Klein3faf2692009-01-21 14:45:33 -08002550 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002551 if (!cb0) {
2552 ret = -ENOMEM;
2553 goto out;
2554 }
2555
Anton Blanchard723f28e2011-10-14 05:31:01 +00002556 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002557 struct ehea_port_res *pr = &port->port_res[i];
2558 struct ehea_qp *qp = pr->qp;
2559
2560 /* Purge send queue */
2561 ehea_purge_sq(qp);
2562
2563 /* Disable queue pair */
2564 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2565 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2566 cb0);
2567 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002568 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002569 goto out;
2570 }
2571
2572 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2573 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2574
2575 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2576 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2577 1), cb0, &dummy64,
2578 &dummy64, &dummy16, &dummy16);
2579 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002580 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002581 goto out;
2582 }
2583
2584 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2585 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2586 cb0);
2587 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002588 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002589 goto out;
2590 }
2591
2592 /* deregister shared memory regions */
2593 dret = ehea_rem_smrs(pr);
2594 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002595 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002596 goto out;
2597 }
2598 }
2599
2600 ret = 0;
2601out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002602 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002603
2604 return ret;
2605}
2606
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002607static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002608{
2609 struct ehea_qp qp = *orig_qp;
2610 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2611 struct ehea_rwqe *rwqe;
2612 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2613 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2614 struct sk_buff *skb;
2615 u32 lkey = pr->recv_mr.lkey;
2616
2617
2618 int i;
2619 int index;
2620
2621 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2622 rwqe = ehea_get_next_rwqe(&qp, 2);
2623 rwqe->sg_list[0].l_key = lkey;
2624 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2625 skb = skba_rq2[index];
2626 if (skb)
2627 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2628 }
2629
2630 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2631 rwqe = ehea_get_next_rwqe(&qp, 3);
2632 rwqe->sg_list[0].l_key = lkey;
2633 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2634 skb = skba_rq3[index];
2635 if (skb)
2636 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2637 }
2638}
2639
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002640static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002641{
2642 struct ehea_port *port = netdev_priv(dev);
2643 struct ehea_adapter *adapter = port->adapter;
2644 int ret = 0;
2645 int i;
2646
Doug Maxey508d2b52008-01-31 20:20:49 -06002647 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002648 u64 hret;
2649 u64 dummy64 = 0;
2650 u16 dummy16 = 0;
2651
Thomas Klein3faf2692009-01-21 14:45:33 -08002652 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002653 if (!cb0) {
2654 ret = -ENOMEM;
2655 goto out;
2656 }
2657
Anton Blanchard723f28e2011-10-14 05:31:01 +00002658 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002659 struct ehea_port_res *pr = &port->port_res[i];
2660 struct ehea_qp *qp = pr->qp;
2661
2662 ret = ehea_gen_smrs(pr);
2663 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002664 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002665 goto out;
2666 }
2667
2668 ehea_update_rqs(qp, pr);
2669
2670 /* Enable queue pair */
2671 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2672 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2673 cb0);
2674 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002675 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002676 goto out;
2677 }
2678
2679 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2680 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2681
2682 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2683 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2684 1), cb0, &dummy64,
2685 &dummy64, &dummy16, &dummy16);
2686 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002687 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002688 goto out;
2689 }
2690
2691 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2692 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2693 cb0);
2694 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002695 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002696 goto out;
2697 }
2698
2699 /* refill entire queue */
2700 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2701 ehea_refill_rq2(pr, 0);
2702 ehea_refill_rq3(pr, 0);
2703 }
2704out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002705 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002706
2707 return ret;
2708}
2709
David Howellsc4028952006-11-22 14:57:56 +00002710static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002711{
2712 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002713 struct ehea_port *port =
2714 container_of(work, struct ehea_port, reset_task);
2715 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002717 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002718 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002719 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002720 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002721
2722 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723
Thomas Klein44c82152007-07-11 16:32:00 +02002724 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002725
2726 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002727 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002728 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002729
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002730 ehea_set_multicast_list(dev);
2731
Joe Perches8c4877a2010-12-13 10:05:14 -08002732 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002734 port_napi_enable(port);
2735
Anton Blanchardb9564462011-10-14 05:30:59 +00002736 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002737out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002738 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002739 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002740}
2741
Tejun Heo3d6b8922010-12-12 16:45:14 +01002742static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002743{
2744 int ret, i;
2745 struct ehea_adapter *adapter;
2746
Joe Perches8c4877a2010-12-13 10:05:14 -08002747 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002748
2749 list_for_each_entry(adapter, &adapter_list, list)
2750 if (adapter->active_ports) {
2751 /* Shutdown all ports */
2752 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2753 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002754 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002755
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002756 if (!port)
2757 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002758
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002759 dev = port->netdev;
2760
2761 if (dev->flags & IFF_UP) {
2762 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002763 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002764 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002765 ret = ehea_stop_qps(dev);
2766 if (ret) {
2767 mutex_unlock(&port->port_lock);
2768 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002769 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002770 port_napi_disable(port);
2771 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002772 }
Andre Detsch2928db42010-08-17 05:49:12 +00002773 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002774 }
2775
2776 /* Unregister old memory region */
2777 ret = ehea_rem_mr(&adapter->mr);
2778 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002779 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002780 goto out;
2781 }
2782 }
2783
Thomas Klein44c82152007-07-11 16:32:00 +02002784 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2785
2786 list_for_each_entry(adapter, &adapter_list, list)
2787 if (adapter->active_ports) {
2788 /* Register new memory region */
2789 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2790 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002791 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002792 goto out;
2793 }
2794
2795 /* Restart all ports */
2796 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2797 struct ehea_port *port = adapter->port[i];
2798
2799 if (port) {
2800 struct net_device *dev = port->netdev;
2801
2802 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002803 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002804 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002805 if (!ret) {
2806 check_sqs(port);
2807 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002808 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002809 } else {
2810 netdev_err(dev, "Unable to restart QPS\n");
2811 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002812 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002813 }
2814 }
2815 }
2816 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002817 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002818out:
2819 return;
2820}
2821
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002822static void ehea_tx_watchdog(struct net_device *dev)
2823{
2824 struct ehea_port *port = netdev_priv(dev);
2825
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002826 if (netif_carrier_ok(dev) &&
2827 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002828 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002829}
2830
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002831static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002832{
2833 struct hcp_query_ehea *cb;
2834 u64 hret;
2835 int ret;
2836
Thomas Klein3faf2692009-01-21 14:45:33 -08002837 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002838 if (!cb) {
2839 ret = -ENOMEM;
2840 goto out;
2841 }
2842
2843 hret = ehea_h_query_ehea(adapter->handle, cb);
2844
2845 if (hret != H_SUCCESS) {
2846 ret = -EIO;
2847 goto out_herr;
2848 }
2849
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002850 adapter->max_mc_mac = cb->max_mc_mac - 1;
2851 ret = 0;
2852
2853out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002854 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002855out:
2856 return ret;
2857}
2858
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002859static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002860{
2861 struct hcp_ehea_port_cb4 *cb4;
2862 u64 hret;
2863 int ret = 0;
2864
2865 *jumbo = 0;
2866
2867 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002868 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002869 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002870 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002871 ret = -ENOMEM;
2872 goto out;
2873 } else {
2874 hret = ehea_h_query_ehea_port(port->adapter->handle,
2875 port->logical_port_id,
2876 H_PORT_CB4,
2877 H_PORT_CB4_JUMBO, cb4);
2878 if (hret == H_SUCCESS) {
2879 if (cb4->jumbo_frame)
2880 *jumbo = 1;
2881 else {
2882 cb4->jumbo_frame = 1;
2883 hret = ehea_h_modify_ehea_port(port->adapter->
2884 handle,
2885 port->
2886 logical_port_id,
2887 H_PORT_CB4,
2888 H_PORT_CB4_JUMBO,
2889 cb4);
2890 if (hret == H_SUCCESS)
2891 *jumbo = 1;
2892 }
2893 } else
2894 ret = -EINVAL;
2895
Thomas Klein3faf2692009-01-21 14:45:33 -08002896 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002897 }
2898out:
2899 return ret;
2900}
2901
2902static ssize_t ehea_show_port_id(struct device *dev,
2903 struct device_attribute *attr, char *buf)
2904{
2905 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002906 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002907}
2908
2909static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2910 NULL);
2911
Bill Pemberton0297be02012-12-03 09:23:10 -05002912static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002913{
2914 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002915 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002916}
2917
2918static struct device *ehea_register_port(struct ehea_port *port,
2919 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002920{
2921 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002922
Grant Likely61c7a082010-04-13 16:12:29 -07002923 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002924 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002925 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002926
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002927 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002928 port->ofdev.dev.release = logical_port_release;
2929
2930 ret = of_device_register(&port->ofdev);
2931 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002932 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002933 goto out;
2934 }
2935
2936 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002937 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002938 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002939 goto out_unreg_of_dev;
2940 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002941
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002942 return &port->ofdev.dev;
2943
2944out_unreg_of_dev:
2945 of_device_unregister(&port->ofdev);
2946out:
2947 return NULL;
2948}
2949
2950static void ehea_unregister_port(struct ehea_port *port)
2951{
2952 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2953 of_device_unregister(&port->ofdev);
2954}
2955
Thomas Klein086c1b22009-01-21 14:43:59 -08002956static const struct net_device_ops ehea_netdev_ops = {
2957 .ndo_open = ehea_open,
2958 .ndo_stop = ehea_stop,
2959 .ndo_start_xmit = ehea_start_xmit,
2960#ifdef CONFIG_NET_POLL_CONTROLLER
2961 .ndo_poll_controller = ehea_netpoll,
2962#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002963 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002964 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002965 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002966 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002967 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002968 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002969 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2970 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002971};
2972
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002973static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002974 u32 logical_port_id,
2975 struct device_node *dn)
2976{
2977 int ret;
2978 struct net_device *dev;
2979 struct ehea_port *port;
2980 struct device *port_dev;
2981 int jumbo;
2982
2983 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002984 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002985
2986 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002987 ret = -ENOMEM;
2988 goto out_err;
2989 }
2990
2991 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002992
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002993 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002994 port->state = EHEA_PORT_DOWN;
2995 port->sig_comp_iv = sq_entries / 10;
2996
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002997 port->adapter = adapter;
2998 port->netdev = dev;
2999 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003000
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003001 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003002
3003 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3004 if (!port->mc_list) {
3005 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003006 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003007 }
3008
3009 INIT_LIST_HEAD(&port->mc_list->list);
3010
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003011 ret = ehea_sense_port_attr(port);
3012 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003013 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003014
Anton Blanchardb9564462011-10-14 05:30:59 +00003015 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003016 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003017
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003018 port_dev = ehea_register_port(port, dn);
3019 if (!port_dev)
3020 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003021
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003022 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003023
3024 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003025 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3026
Thomas Klein086c1b22009-01-21 14:43:59 -08003027 dev->netdev_ops = &ehea_netdev_ops;
3028 ehea_set_ethtool_ops(dev);
3029
Anton Blanchardd695c332011-10-14 05:31:05 +00003030 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Ben Hutchings3865fe12012-11-16 12:46:43 +00003031 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003032 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003033 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003034 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003035 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003036 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3037 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003038 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3039
David Howellsc4028952006-11-22 14:57:56 +00003040 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003041 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003042
Anton Blanchard21ccc792011-05-10 16:17:10 +00003043 init_waitqueue_head(&port->swqe_avail_wq);
3044 init_waitqueue_head(&port->restart_wq);
3045
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003046 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003047 ret = register_netdev(dev);
3048 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003049 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003050 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003051 }
3052
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003053 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003054 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003055 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003056
Joe Perches8c4877a2010-12-13 10:05:14 -08003057 netdev_info(dev, "Jumbo frames are %sabled\n",
3058 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003059
Thomas Klein44c82152007-07-11 16:32:00 +02003060 adapter->active_ports++;
3061
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003062 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003063
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064out_unreg_port:
3065 ehea_unregister_port(port);
3066
3067out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003069
3070out_free_ethdev:
3071 free_netdev(dev);
3072
3073out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003074 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3075 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003076 return NULL;
3077}
3078
3079static void ehea_shutdown_single_port(struct ehea_port *port)
3080{
Brian King7fb1c2a2008-05-14 09:48:25 -05003081 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003082
3083 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003084 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003085 unregister_netdev(port->netdev);
3086 ehea_unregister_port(port);
3087 kfree(port->mc_list);
3088 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003089 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003090}
3091
3092static int ehea_setup_ports(struct ehea_adapter *adapter)
3093{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003094 struct device_node *lhea_dn;
3095 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003096
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003097 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099
Grant Likely61c7a082010-04-13 16:12:29 -07003100 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003101 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003102
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003103 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003104 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003106 pr_err("bad device node: eth_dn name=%s\n",
3107 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003108 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003109 }
3110
Thomas Klein1211bb62007-04-26 11:56:43 +02003111 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003112 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003113 of_node_put(eth_dn);
3114 return -EIO;
3115 }
3116
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003117 adapter->port[i] = ehea_setup_single_port(adapter,
3118 *dn_log_port_id,
3119 eth_dn);
3120 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003121 netdev_info(adapter->port[i]->netdev,
3122 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003123 else
3124 ehea_remove_adapter_mr(adapter);
3125
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003127 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003128 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003129}
3130
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003131static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3132 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003133{
3134 struct device_node *lhea_dn;
3135 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003136 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137
Grant Likely61c7a082010-04-13 16:12:29 -07003138 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003139 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003140
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003141 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003142 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143 if (dn_log_port_id)
3144 if (*dn_log_port_id == logical_port_id)
3145 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003146 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003147
3148 return NULL;
3149}
3150
3151static ssize_t ehea_probe_port(struct device *dev,
3152 struct device_attribute *attr,
3153 const char *buf, size_t count)
3154{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003155 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156 struct ehea_port *port;
3157 struct device_node *eth_dn = NULL;
3158 int i;
3159
3160 u32 logical_port_id;
3161
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003162 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163
3164 port = ehea_get_port(adapter, logical_port_id);
3165
3166 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003167 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3168 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169 return -EINVAL;
3170 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003171
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3173
3174 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003175 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 return -EINVAL;
3177 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003178
Thomas Klein1211bb62007-04-26 11:56:43 +02003179 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003180 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003181 return -EIO;
3182 }
3183
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3185
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003186 of_node_put(eth_dn);
3187
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003188 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003189 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 if (!adapter->port[i]) {
3191 adapter->port[i] = port;
3192 break;
3193 }
3194
Joe Perches8c4877a2010-12-13 10:05:14 -08003195 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3196 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003197 } else {
3198 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003199 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003200 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201
3202 return (ssize_t) count;
3203}
3204
3205static ssize_t ehea_remove_port(struct device *dev,
3206 struct device_attribute *attr,
3207 const char *buf, size_t count)
3208{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003209 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003210 struct ehea_port *port;
3211 int i;
3212 u32 logical_port_id;
3213
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003214 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215
3216 port = ehea_get_port(adapter, logical_port_id);
3217
3218 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003219 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3220 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003221
3222 ehea_shutdown_single_port(port);
3223
Doug Maxey508d2b52008-01-31 20:20:49 -06003224 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003225 if (adapter->port[i] == port) {
3226 adapter->port[i] = NULL;
3227 break;
3228 }
3229 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003230 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3231 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 return -EINVAL;
3233 }
3234
Thomas Klein1211bb62007-04-26 11:56:43 +02003235 ehea_remove_adapter_mr(adapter);
3236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 return (ssize_t) count;
3238}
3239
3240static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3241static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3242
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003243static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003245 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246 if (ret)
3247 goto out;
3248
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003249 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003250out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003251 return ret;
3252}
3253
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003254static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003256 device_remove_file(&dev->dev, &dev_attr_probe_port);
3257 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258}
3259
Bill Pemberton0297be02012-12-03 09:23:10 -05003260static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003261 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262{
3263 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003264 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003266 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003267
Grant Likely61c7a082010-04-13 16:12:29 -07003268 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003269 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003270 return -EINVAL;
3271 }
3272
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003273 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3274 if (!adapter) {
3275 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003276 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277 goto out;
3278 }
3279
Thomas Klein44c82152007-07-11 16:32:00 +02003280 list_add(&adapter->list, &adapter_list);
3281
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003282 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003283
Grant Likely61c7a082010-04-13 16:12:29 -07003284 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003285 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003286 if (adapter_handle)
3287 adapter->handle = *adapter_handle;
3288
3289 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003290 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003291 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003292 ret = -ENODEV;
3293 goto out_free_ad;
3294 }
3295
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296 adapter->pd = EHEA_PD_ID;
3297
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003298 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003299
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003300
3301 /* initialize adapter and ports */
3302 /* get adapter properties */
3303 ret = ehea_sense_adapter_attr(adapter);
3304 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003305 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003306 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003307 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003308
3309 adapter->neq = ehea_create_eq(adapter,
3310 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3311 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003312 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003313 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003314 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003315 }
3316
3317 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3318 (unsigned long)adapter);
3319
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003320 ret = ehea_create_device_sysfs(dev);
3321 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003322 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003323
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003324 ret = ehea_setup_ports(adapter);
3325 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003326 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003327 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003328 }
3329
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003330 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3331 ehea_interrupt_neq, IRQF_DISABLED,
3332 "ehea_neq", adapter);
3333 if (ret) {
3334 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3335 goto out_shutdown_ports;
3336 }
3337
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003338 /* Handle any events that might be pending. */
3339 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003340
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003341 ret = 0;
3342 goto out;
3343
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003344out_shutdown_ports:
3345 for (i = 0; i < EHEA_MAX_PORTS; i++)
3346 if (adapter->port[i]) {
3347 ehea_shutdown_single_port(adapter->port[i]);
3348 adapter->port[i] = NULL;
3349 }
3350
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351out_rem_dev_sysfs:
3352 ehea_remove_device_sysfs(dev);
3353
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003354out_kill_eq:
3355 ehea_destroy_eq(adapter->neq);
3356
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003357out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003358 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003359 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003360
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003361out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003362 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003363
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003364 return ret;
3365}
3366
Bill Pemberton0297be02012-12-03 09:23:10 -05003367static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003368{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003369 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003370 int i;
3371
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003373 if (adapter->port[i]) {
3374 ehea_shutdown_single_port(adapter->port[i]);
3375 adapter->port[i] = NULL;
3376 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003377
3378 ehea_remove_device_sysfs(dev);
3379
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003380 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003381 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003382
3383 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003384 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003385 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003386 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003387
Thomas Klein21eee2d2008-02-13 16:18:33 +01003388 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003390 return 0;
3391}
3392
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003393static void ehea_crash_handler(void)
Thomas Klein21eee2d2008-02-13 16:18:33 +01003394{
3395 int i;
3396
3397 if (ehea_fw_handles.arr)
3398 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3399 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3400 ehea_fw_handles.arr[i].fwh,
3401 FORCE_FREE);
3402
3403 if (ehea_bcmc_regs.arr)
3404 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3405 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3406 ehea_bcmc_regs.arr[i].port_id,
3407 ehea_bcmc_regs.arr[i].reg_type,
3408 ehea_bcmc_regs.arr[i].macaddr,
3409 0, H_DEREG_BCMC);
3410}
3411
Hannes Hering48cfb142008-05-07 14:43:36 +02003412static int ehea_mem_notifier(struct notifier_block *nb,
3413 unsigned long action, void *data)
3414{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003415 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003416 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003417
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003418 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003419
Hannes Hering48cfb142008-05-07 14:43:36 +02003420 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003421 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003422 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003423 /* Readd canceled memory block */
3424 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003425 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003426 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003427 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003428 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003429 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003430 break;
3431 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003432 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003433 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003434 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003435 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003436 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003437 break;
3438 default:
3439 break;
3440 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003441
3442 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003443 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003444
Thomas Kleina7c561f22010-04-20 23:11:31 +00003445out_unlock:
3446 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003447 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003448}
3449
3450static struct notifier_block ehea_mem_nb = {
3451 .notifier_call = ehea_mem_notifier,
3452};
3453
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003454static int ehea_reboot_notifier(struct notifier_block *nb,
3455 unsigned long action, void *unused)
3456{
3457 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003458 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003459 ibmebus_unregister_driver(&ehea_driver);
3460 }
3461 return NOTIFY_DONE;
3462}
3463
3464static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003465 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003466};
3467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468static int check_module_parm(void)
3469{
3470 int ret = 0;
3471
3472 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3473 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003474 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475 ret = -EINVAL;
3476 }
3477 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3478 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003479 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 ret = -EINVAL;
3481 }
3482 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3483 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003484 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003485 ret = -EINVAL;
3486 }
3487 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3488 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003489 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003490 ret = -EINVAL;
3491 }
3492
3493 return ret;
3494}
3495
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003496static ssize_t ehea_show_capabilities(struct device_driver *drv,
3497 char *buf)
3498{
3499 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3500}
3501
3502static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3503 ehea_show_capabilities, NULL);
3504
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003505static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506{
3507 int ret;
3508
Joe Perches8c4877a2010-12-13 10:05:14 -08003509 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510
Thomas Klein21eee2d2008-02-13 16:18:33 +01003511 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3512 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3513
Daniel Walker9f71a562008-03-28 14:41:26 -07003514 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003515 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003516
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 ret = check_module_parm();
3518 if (ret)
3519 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003520
3521 ret = ehea_create_busmap();
3522 if (ret)
3523 goto out;
3524
Thomas Klein21eee2d2008-02-13 16:18:33 +01003525 ret = register_reboot_notifier(&ehea_reboot_nb);
3526 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003527 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003528
Hannes Hering48cfb142008-05-07 14:43:36 +02003529 ret = register_memory_notifier(&ehea_mem_nb);
3530 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003531 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003532
Joe Perchesc061b182010-08-23 18:20:03 +00003533 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003534 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003535 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003536
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003537 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003538 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003539 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003540 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003541 }
3542
3543 ret = driver_create_file(&ehea_driver.driver,
3544 &driver_attr_capabilities);
3545 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003546 pr_err("failed to register capabilities attribute, ret=%d\n",
3547 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003548 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003549 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550
Thomas Klein21eee2d2008-02-13 16:18:33 +01003551 return ret;
3552
3553out3:
3554 ibmebus_unregister_driver(&ehea_driver);
3555out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003556 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003557 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003558 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003559out:
3560 return ret;
3561}
3562
3563static void __exit ehea_module_exit(void)
3564{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003565 int ret;
3566
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003567 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003568 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003569 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003570 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003571 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003572 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003573 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003574 kfree(ehea_fw_handles.arr);
3575 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003576 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577}
3578
3579module_init(ehea_module_init);
3580module_exit(ehea_module_exit);