blob: 02963343447497f1ab9d728a0a9fe7971872549b [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 * linux/drivers/net/ethernet/ibm/ehea/ehea_main.c
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
75MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
Dave Young31d17532013-02-15 20:19:19 +000079 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
Dave Young31d17532013-02-15 20:19:19 +000082 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020083 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
Dave Young31d17532013-02-15 20:19:19 +000085 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020086 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
Dave Young31d17532013-02-15 20:19:19 +000088 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020089 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000090MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
91 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Doug Maxey508d2b52008-01-31 20:20:49 -060093static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020094static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080095static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070096static DEFINE_MUTEX(dlpar_mem_lock);
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +000097static struct ehea_fw_handle_array ehea_fw_handles;
98static struct ehea_bcmc_reg_array ehea_bcmc_regs;
Thomas Klein21eee2d2008-02-13 16:18:33 +010099
Thomas Kleind1dea382007-04-26 11:56:13 +0200100
Bill Pemberton0297be02012-12-03 09:23:10 -0500101static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Bill Pemberton0297be02012-12-03 09:23:10 -0500104static int ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200105
106static struct of_device_id ehea_device_table[] = {
107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {},
112};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100113MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000115static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700116 .driver = {
117 .name = "ehea",
118 .owner = THIS_MODULE,
119 .of_match_table = ehea_device_table,
120 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .probe = ehea_probe_adapter,
122 .remove = ehea_remove,
123};
124
Doug Maxey508d2b52008-01-31 20:20:49 -0600125void ehea_dump(void *adr, int len, char *msg)
126{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200127 int x;
128 unsigned char *deb = adr;
129 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 deb += 16;
133 }
134}
135
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +0000136static void ehea_schedule_port_reset(struct ehea_port *port)
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100137{
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
139 schedule_work(&port->reset_task);
140}
141
Thomas Klein21eee2d2008-02-13 16:18:33 +0100142static void ehea_update_firmware_handles(void)
143{
144 struct ehea_fw_handle_entry *arr = NULL;
145 struct ehea_adapter *adapter;
146 int num_adapters = 0;
147 int num_ports = 0;
148 int num_portres = 0;
149 int i = 0;
150 int num_fw_handles, k, l;
151
152 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700153 mutex_lock(&ehea_fw_handles.lock);
154
Thomas Klein21eee2d2008-02-13 16:18:33 +0100155 list_for_each_entry(adapter, &adapter_list, list) {
156 num_adapters++;
157
158 for (k = 0; k < EHEA_MAX_PORTS; k++) {
159 struct ehea_port *port = adapter->port[k];
160
161 if (!port || (port->state != EHEA_PORT_UP))
162 continue;
163
164 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000165 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 }
167 }
168
169 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
170 num_ports * EHEA_NUM_PORT_FW_HANDLES +
171 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
172
173 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000174 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700176 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100177 } else
178 goto out_update;
179
180 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 if (num_adapters == 0)
182 break;
183
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
Joe Perches8e95a202009-12-03 07:58:21 +0000187 if (!port || (port->state != EHEA_PORT_UP) ||
188 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 continue;
190
Anton Blanchard723f28e2011-10-14 05:31:01 +0000191 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 struct ehea_port_res *pr = &port->port_res[l];
193
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->qp->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_cq->fw_handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_cq->fw_handle;
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = pr->eq->fw_handle;
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->send_mr.handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->recv_mr.handle;
206 }
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700209 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222out_update:
223 kfree(ehea_fw_handles.arr);
224 ehea_fw_handles.arr = arr;
225 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226out:
227 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228}
229
230static void ehea_update_bcmc_registrations(void)
231{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 struct ehea_bcmc_reg_entry *arr = NULL;
234 struct ehea_adapter *adapter;
235 struct ehea_mc_list *mc_entry;
236 int num_registrations = 0;
237 int i = 0;
238 int k;
239
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
241
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 /* Determine number of registrations */
243 list_for_each_entry(adapter, &adapter_list, list)
244 for (k = 0; k < EHEA_MAX_PORTS; k++) {
245 struct ehea_port *port = adapter->port[k];
246
247 if (!port || (port->state != EHEA_PORT_UP))
248 continue;
249
250 num_registrations += 2; /* Broadcast registrations */
251
252 list_for_each_entry(mc_entry, &port->mc_list->list,list)
253 num_registrations += 2;
254 }
255
256 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000257 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100258 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700259 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100260 } else
261 goto out_update;
262
263 list_for_each_entry(adapter, &adapter_list, list) {
264 for (k = 0; k < EHEA_MAX_PORTS; k++) {
265 struct ehea_port *port = adapter->port[k];
266
267 if (!port || (port->state != EHEA_PORT_UP))
268 continue;
269
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 if (num_registrations == 0)
271 goto out_update;
272
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 arr[i].adh = adapter->handle;
274 arr[i].port_id = port->logical_port_id;
275 arr[i].reg_type = EHEA_BCMC_BROADCAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = port->mac_addr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_BROADCAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285
286 list_for_each_entry(mc_entry,
287 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700288 if (num_registrations == 0)
289 goto out_update;
290
Thomas Klein21eee2d2008-02-13 16:18:33 +0100291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000293 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100294 EHEA_BCMC_UNTAGGED;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000295 if (mc_entry->macaddr == 0)
296 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297 arr[i++].macaddr = mc_entry->macaddr;
298
299 arr[i].adh = adapter->handle;
300 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000301 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 EHEA_BCMC_VLANID_ALL;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000303 if (mc_entry->macaddr == 0)
304 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700306 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100307 }
308 }
309 }
310
311out_update:
312 kfree(ehea_bcmc_regs.arr);
313 ehea_bcmc_regs.arr = arr;
314 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315out:
316 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317}
318
Anton Blanchard239c5622011-10-14 05:31:09 +0000319static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
320 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200321{
322 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000323 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324 int i;
325
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000326 for (i = 0; i < port->num_def_qps; i++) {
327 rx_packets += port->port_res[i].rx_packets;
328 rx_bytes += port->port_res[i].rx_bytes;
329 }
330
Anton Blanchard723f28e2011-10-14 05:31:01 +0000331 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000332 tx_packets += port->port_res[i].tx_packets;
333 tx_bytes += port->port_res[i].tx_bytes;
334 }
335
336 stats->tx_packets = tx_packets;
337 stats->rx_bytes = rx_bytes;
338 stats->tx_bytes = tx_bytes;
339 stats->rx_packets = rx_packets;
340
Eric Dumazet09c1d442012-03-06 19:46:41 +0000341 stats->multicast = port->stats.multicast;
342 stats->rx_errors = port->stats.rx_errors;
343 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000344}
345
346static void ehea_update_stats(struct work_struct *work)
347{
348 struct ehea_port *port =
349 container_of(work, struct ehea_port, stats_work.work);
350 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000351 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000352 struct hcp_ehea_port_cb2 *cb2;
353 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200354
Brian King3d8009c2010-06-30 11:59:12 +0000355 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000357 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
358 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 }
360
361 hret = ehea_h_query_ehea_port(port->adapter->handle,
362 port->logical_port_id,
363 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
364 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800365 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 goto out_herr;
367 }
368
369 if (netif_msg_hw(port))
370 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 stats->multicast = cb2->rxmcp;
373 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374
375out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800376 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000377resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000378 schedule_delayed_work(&port->stats_work,
379 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200406 break;
407 }
408 }
409 index--;
410 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200411 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200413
414 if (adder == 0)
415 return;
416
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200419}
420
Thomas Kleine2878802009-01-21 14:45:57 -0800421static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
424 struct net_device *dev = pr->port->netdev;
425 int i;
426
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000427 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800428 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000429 return;
430 }
431
432 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000434 if (!skb_arr_rq1[i])
Thomas Kleine2878802009-01-21 14:45:57 -0800435 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 }
437 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000438 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439}
440
441static int ehea_refill_rq_def(struct ehea_port_res *pr,
442 struct ehea_q_skb_arr *q_skba, int rq_nr,
443 int num_wqes, int wqe_type, int packet_size)
444{
445 struct net_device *dev = pr->port->netdev;
446 struct ehea_qp *qp = pr->qp;
447 struct sk_buff **skb_arr = q_skba->arr;
448 struct ehea_rwqe *rwqe;
449 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200450 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 int ret = 0;
452
453 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200454 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200455
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200456 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
457 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460
461 index = q_skba->index;
462 max_index_mask = q_skba->len - 1;
463 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200464 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000465 struct sk_buff *skb;
466
467 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800470 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800471 netdev_info(pr->port->netdev,
472 "rq%i ran dry - no mem for skb\n",
473 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800474 ret = -ENOMEM;
475 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 break;
477 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478
479 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200480 tmp_addr = ehea_map_vaddr(skb->data);
481 if (tmp_addr == -1) {
482 dev_kfree_skb(skb);
483 q_skba->os_skbs = fill_wqes - i;
484 ret = 0;
485 break;
486 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487
488 rwqe = ehea_get_next_rwqe(qp, rq_nr);
489 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200490 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200491 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 rwqe->sg_list[0].len = packet_size;
494 rwqe->data_segments = 1;
495
496 index++;
497 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200498 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499 }
Thomas Klein44c82152007-07-11 16:32:00 +0200500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200501 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200502 if (adder == 0)
503 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504
505 /* Ring doorbell */
506 iosync();
507 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200508 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200511out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 return ret;
513}
514
515
516static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
517{
518 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
519 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000520 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521}
522
523
524static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
525{
526 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
527 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000528 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200529}
530
531static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
532{
533 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
534 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
535 return 0;
536 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
537 (cqe->header_length == 0))
538 return 0;
539 return -EINVAL;
540}
541
542static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000543 struct sk_buff *skb, struct ehea_cqe *cqe,
544 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200545{
546 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
547
548 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200549 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000550
551 /* The packet was not an IPV4 packet so a complemented checksum was
552 calculated. The value is found in the Internet Checksum field. */
553 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
554 skb->ip_summed = CHECKSUM_COMPLETE;
555 skb->csum = csum_unfold(~cqe->inet_checksum_value);
556 } else
557 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000558
559 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560}
561
562static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
563 int arr_len,
564 struct ehea_cqe *cqe)
565{
566 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
567 struct sk_buff *skb;
568 void *pref;
569 int x;
570
571 x = skb_index + 1;
572 x &= (arr_len - 1);
573
574 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700575 if (pref) {
576 prefetchw(pref);
577 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578
Hannes Hering0b2febf2009-05-04 11:06:37 -0700579 pref = (skb_array[x]->data);
580 prefetch(pref);
581 prefetch(pref + EHEA_CACHE_LINE);
582 prefetch(pref + EHEA_CACHE_LINE * 2);
583 prefetch(pref + EHEA_CACHE_LINE * 3);
584 }
585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200586 skb = skb_array[skb_index];
587 skb_array[skb_index] = NULL;
588 return skb;
589}
590
591static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
592 int arr_len, int wqe_index)
593{
594 struct sk_buff *skb;
595 void *pref;
596 int x;
597
598 x = wqe_index + 1;
599 x &= (arr_len - 1);
600
601 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700602 if (pref) {
603 prefetchw(pref);
604 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200605
Hannes Hering0b2febf2009-05-04 11:06:37 -0700606 pref = (skb_array[x]->data);
607 prefetchw(pref);
608 prefetchw(pref + EHEA_CACHE_LINE);
609 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200610
611 skb = skb_array[wqe_index];
612 skb_array[wqe_index] = NULL;
613 return skb;
614}
615
616static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
617 struct ehea_cqe *cqe, int *processed_rq2,
618 int *processed_rq3)
619{
620 struct sk_buff *skb;
621
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100622 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
623 pr->p_stats.err_tcp_cksum++;
624 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
625 pr->p_stats.err_ip_cksum++;
626 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
627 pr->p_stats.err_frame_crc++;
628
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200629 if (rq == 2) {
630 *processed_rq2 += 1;
631 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
632 dev_kfree_skb(skb);
633 } else if (rq == 3) {
634 *processed_rq3 += 1;
635 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
636 dev_kfree_skb(skb);
637 }
638
639 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100640 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800641 pr_err("Critical receive error for QP %d. Resetting port.\n",
642 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100643 ehea_dump(cqe, sizeof(*cqe), "CQE");
644 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100645 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200646 return 1;
647 }
648
649 return 0;
650}
651
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700652static int ehea_proc_rwqes(struct net_device *dev,
653 struct ehea_port_res *pr,
654 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200655{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100656 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200657 struct ehea_qp *qp = pr->qp;
658 struct ehea_cqe *cqe;
659 struct sk_buff *skb;
660 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
661 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
662 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
663 int skb_arr_rq1_len = pr->rq1_skba.len;
664 int skb_arr_rq2_len = pr->rq2_skba.len;
665 int skb_arr_rq3_len = pr->rq3_skba.len;
666 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000667 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700668 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200669
670 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
671 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200673 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700674 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200675 ehea_inc_rq1(qp);
676 processed_rq1++;
677 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200678 if (netif_msg_rx_status(port))
679 ehea_dump(cqe, sizeof(*cqe), "CQE");
680
681 last_wqe_index = wqe_index;
682 rmb();
683 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600684 if (rq == 1) {
685 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200686 skb = get_skb_by_index_ll(skb_arr_rq1,
687 skb_arr_rq1_len,
688 wqe_index);
689 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800690 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800691 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100692
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700693 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200694 EHEA_L_PKT_SIZE);
Joe Perches720a43e2013-03-08 15:03:25 +0000695 if (!skb)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696 break;
697 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600698 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200699 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000700 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600701 } else if (rq == 2) {
702 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200703 skb = get_skb_by_index(skb_arr_rq2,
704 skb_arr_rq2_len, cqe);
705 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800706 netif_err(port, rx_err, dev,
707 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 break;
709 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000710 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600712 } else {
713 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200714 skb = get_skb_by_index(skb_arr_rq3,
715 skb_arr_rq3_len, cqe);
716 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800717 netif_err(port, rx_err, dev,
718 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 break;
720 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000721 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722 processed_rq3++;
723 }
724
Breno Leitaoce45b872010-10-27 08:45:14 +0000725 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000726
727 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
728 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
729
730 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100731 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100732 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200733 port_reset = ehea_treat_poll_error(pr, rq, cqe,
734 &processed_rq2,
735 &processed_rq3);
736 if (port_reset)
737 break;
738 }
739 cqe = ehea_poll_rq1(qp, &wqe_index);
740 }
741
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200742 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000743 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200744
745 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
746 ehea_refill_rq2(pr, processed_rq2);
747 ehea_refill_rq3(pr, processed_rq3);
748
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700749 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750}
751
Andre Detsch2928db42010-08-17 05:49:12 +0000752#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
753
754static void reset_sq_restart_flag(struct ehea_port *port)
755{
756 int i;
757
Anton Blanchard723f28e2011-10-14 05:31:01 +0000758 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000759 struct ehea_port_res *pr = &port->port_res[i];
760 pr->sq_restart_flag = 0;
761 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000762 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000763}
764
765static void check_sqs(struct ehea_port *port)
766{
767 struct ehea_swqe *swqe;
768 int swqe_index;
769 int i, k;
770
Anton Blanchard723f28e2011-10-14 05:31:01 +0000771 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000772 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000773 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000774 k = 0;
775 swqe = ehea_get_swqe(pr->qp, &swqe_index);
776 memset(swqe, 0, SWQE_HEADER_SIZE);
777 atomic_dec(&pr->swqe_avail);
778
779 swqe->tx_control |= EHEA_SWQE_PURGE;
780 swqe->wr_id = SWQE_RESTART_CHECK;
781 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
782 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
783 swqe->immediate_data_length = 80;
784
785 ehea_post_swqe(pr->qp, swqe);
786
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000787 ret = wait_event_timeout(port->restart_wq,
788 pr->sq_restart_flag == 0,
789 msecs_to_jiffies(100));
790
791 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800792 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000793 ehea_schedule_port_reset(pr->port);
794 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000795 }
796 }
Andre Detsch2928db42010-08-17 05:49:12 +0000797}
798
799
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100800static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200801{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100802 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200803 struct ehea_cq *send_cq = pr->send_cq;
804 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100805 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200806 int cqe_counter = 0;
807 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100808 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000809 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
810 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200811
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100812 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600813 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100814 ehea_inc_cq(send_cq);
815
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816 cqe_counter++;
817 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000818
819 if (cqe->wr_id == SWQE_RESTART_CHECK) {
820 pr->sq_restart_flag = 1;
821 swqe_av++;
822 break;
823 }
824
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200825 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800826 pr_err("Bad send completion status=0x%04X\n",
827 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000828
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200829 if (netif_msg_tx_err(pr->port))
830 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000831
832 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800833 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000834 ehea_schedule_port_reset(pr->port);
835 break;
836 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200837 }
838
839 if (netif_msg_tx_done(pr->port))
840 ehea_dump(cqe, sizeof(*cqe), "CQE");
841
842 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100843 == EHEA_SWQE2_TYPE)) {
844
845 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
846 skb = pr->sq_skba.arr[index];
847 dev_kfree_skb(skb);
848 pr->sq_skba.arr[index] = NULL;
849 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200850
851 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
852 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100853
854 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700855 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856
857 ehea_update_feca(send_cq, cqe_counter);
858 atomic_add(swqe_av, &pr->swqe_avail);
859
Anton Blanchardb9564462011-10-14 05:30:59 +0000860 if (unlikely(netif_tx_queue_stopped(txq) &&
861 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
862 __netif_tx_lock(txq, smp_processor_id());
863 if (netif_tx_queue_stopped(txq) &&
864 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
865 netif_tx_wake_queue(txq);
866 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200867 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000868
Breno Leitao5b27d422010-10-05 13:16:22 +0000869 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200870
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100871 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200872}
873
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700874#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100875
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700876static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877{
Doug Maxey508d2b52008-01-31 20:20:49 -0600878 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
879 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700880 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100881 struct ehea_cqe *cqe;
882 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000883 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700884 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100885
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700886 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000887 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100888
Anton Blanchard222ca962011-10-14 05:31:00 +0000889 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800890 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100891 ehea_reset_cq_ep(pr->recv_cq);
892 ehea_reset_cq_ep(pr->send_cq);
893 ehea_reset_cq_n1(pr->recv_cq);
894 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000895 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100896 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
897 cqe_skb = ehea_poll_cq(pr->send_cq);
898
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100899 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700900 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901
Ben Hutchings288379f2009-01-19 16:43:59 -0800902 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700903 return rx;
904
905 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
906 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100907 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100908
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700909 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200910}
911
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200912#ifdef CONFIG_NET_POLL_CONTROLLER
913static void ehea_netpoll(struct net_device *dev)
914{
915 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700916 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200917
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700918 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800919 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200920}
921#endif
922
David Howells7d12e782006-10-05 14:55:46 +0100923static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200924{
925 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100926
Ben Hutchings288379f2009-01-19 16:43:59 -0800927 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100928
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929 return IRQ_HANDLED;
930}
931
David Howells7d12e782006-10-05 14:55:46 +0100932static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200933{
934 struct ehea_port *port = param;
935 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100936 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200937 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000938 u64 resource_type, aer, aerr;
939 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200940
941 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100942
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200943 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200944 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800945 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
946 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100947
948 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000949
950 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
951 &aer, &aerr);
952
953 if (resource_type == EHEA_AER_RESTYPE_QP) {
954 if ((aer & EHEA_AER_RESET_MASK) ||
955 (aerr & EHEA_AERR_RESET_MASK))
956 reset_port = 1;
957 } else
958 reset_port = 1; /* Reset in case of CQ or EQ error */
959
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100960 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200961 }
962
Thomas Kleinea96cea2010-04-20 23:10:55 +0000963 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800964 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000965 ehea_schedule_port_reset(port);
966 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100967
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200968 return IRQ_HANDLED;
969}
970
971static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
972 int logical_port)
973{
974 int i;
975
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100976 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100977 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200978 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100979 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200980 return NULL;
981}
982
983int ehea_sense_port_attr(struct ehea_port *port)
984{
985 int ret;
986 u64 hret;
987 struct hcp_ehea_port_cb0 *cb0;
988
Doug Maxey508d2b52008-01-31 20:20:49 -0600989 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800990 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600991 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800992 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 ret = -ENOMEM;
994 goto out;
995 }
996
997 hret = ehea_h_query_ehea_port(port->adapter->handle,
998 port->logical_port_id, H_PORT_CB0,
999 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1000 cb0);
1001 if (hret != H_SUCCESS) {
1002 ret = -EIO;
1003 goto out_free;
1004 }
1005
1006 /* MAC address */
1007 port->mac_addr = cb0->port_mac_addr << 16;
1008
Doug Maxey508d2b52008-01-31 20:20:49 -06001009 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001010 ret = -EADDRNOTAVAIL;
1011 goto out_free;
1012 }
1013
1014 /* Port speed */
1015 switch (cb0->port_speed) {
1016 case H_SPEED_10M_H:
1017 port->port_speed = EHEA_SPEED_10M;
1018 port->full_duplex = 0;
1019 break;
1020 case H_SPEED_10M_F:
1021 port->port_speed = EHEA_SPEED_10M;
1022 port->full_duplex = 1;
1023 break;
1024 case H_SPEED_100M_H:
1025 port->port_speed = EHEA_SPEED_100M;
1026 port->full_duplex = 0;
1027 break;
1028 case H_SPEED_100M_F:
1029 port->port_speed = EHEA_SPEED_100M;
1030 port->full_duplex = 1;
1031 break;
1032 case H_SPEED_1G_F:
1033 port->port_speed = EHEA_SPEED_1G;
1034 port->full_duplex = 1;
1035 break;
1036 case H_SPEED_10G_F:
1037 port->port_speed = EHEA_SPEED_10G;
1038 port->full_duplex = 1;
1039 break;
1040 default:
1041 port->port_speed = 0;
1042 port->full_duplex = 0;
1043 break;
1044 }
1045
Thomas Kleine919b592007-01-22 12:53:20 +01001046 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001047 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001048
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001049 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001050 if (use_mcs)
1051 port->num_def_qps = cb0->num_default_qps;
1052 else
1053 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001054
1055 if (!port->num_def_qps) {
1056 ret = -EINVAL;
1057 goto out_free;
1058 }
1059
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001060 ret = 0;
1061out_free:
1062 if (ret || netif_msg_probe(port))
1063 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001064 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001065out:
1066 return ret;
1067}
1068
1069int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1070{
1071 struct hcp_ehea_port_cb4 *cb4;
1072 u64 hret;
1073 int ret = 0;
1074
Thomas Klein3faf2692009-01-21 14:45:33 -08001075 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001076 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001077 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001078 ret = -ENOMEM;
1079 goto out;
1080 }
1081
1082 cb4->port_speed = port_speed;
1083
1084 netif_carrier_off(port->netdev);
1085
1086 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1087 port->logical_port_id,
1088 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1089 if (hret == H_SUCCESS) {
1090 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1091
1092 hret = ehea_h_query_ehea_port(port->adapter->handle,
1093 port->logical_port_id,
1094 H_PORT_CB4, H_PORT_CB4_SPEED,
1095 cb4);
1096 if (hret == H_SUCCESS) {
1097 switch (cb4->port_speed) {
1098 case H_SPEED_10M_H:
1099 port->port_speed = EHEA_SPEED_10M;
1100 port->full_duplex = 0;
1101 break;
1102 case H_SPEED_10M_F:
1103 port->port_speed = EHEA_SPEED_10M;
1104 port->full_duplex = 1;
1105 break;
1106 case H_SPEED_100M_H:
1107 port->port_speed = EHEA_SPEED_100M;
1108 port->full_duplex = 0;
1109 break;
1110 case H_SPEED_100M_F:
1111 port->port_speed = EHEA_SPEED_100M;
1112 port->full_duplex = 1;
1113 break;
1114 case H_SPEED_1G_F:
1115 port->port_speed = EHEA_SPEED_1G;
1116 port->full_duplex = 1;
1117 break;
1118 case H_SPEED_10G_F:
1119 port->port_speed = EHEA_SPEED_10G;
1120 port->full_duplex = 1;
1121 break;
1122 default:
1123 port->port_speed = 0;
1124 port->full_duplex = 0;
1125 break;
1126 }
1127 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001128 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001129 ret = -EIO;
1130 }
1131 } else {
1132 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001133 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 ret = -EPERM;
1135 } else {
1136 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001137 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001138 }
1139 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001140 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1141 netif_carrier_on(port->netdev);
1142
Thomas Klein3faf2692009-01-21 14:45:33 -08001143 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001144out:
1145 return ret;
1146}
1147
1148static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1149{
1150 int ret;
1151 u8 ec;
1152 u8 portnum;
1153 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001154 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001155
1156 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1157 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1158 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001159 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001160
1161 switch (ec) {
1162 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1163
1164 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001165 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001166 break;
1167 }
1168
1169 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001170 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001171 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001172 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001173 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001174 break;
1175 }
1176
Joe Perches8c4877a2010-12-13 10:05:14 -08001177 netif_info(port, link, dev,
1178 "Logical port up: %dMbps %s Duplex\n",
1179 port->port_speed,
1180 port->full_duplex == 1 ?
1181 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001182
Joe Perches8c4877a2010-12-13 10:05:14 -08001183 netif_carrier_on(dev);
1184 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185 }
1186 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001187 if (netif_carrier_ok(dev)) {
1188 netif_info(port, link, dev,
1189 "Logical port down\n");
1190 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001191 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001192 }
1193
1194 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001195 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001196 netif_info(port, link, dev,
1197 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001198 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001199 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001201 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001202 netif_info(port, link, dev,
1203 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001204 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001205 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001206 }
1207
1208 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001209 netdev_info(dev,
1210 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001212 netdev_info(dev,
1213 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001214
1215 break;
1216 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001217 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001218 break;
1219 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 netdev_info(dev, "Port malfunction\n");
1221 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001222 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 break;
1224 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226 break;
1227 }
1228}
1229
1230static void ehea_neq_tasklet(unsigned long data)
1231{
Doug Maxey508d2b52008-01-31 20:20:49 -06001232 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001233 struct ehea_eqe *eqe;
1234 u64 event_mask;
1235
1236 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001237 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238
1239 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001240 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 ehea_parse_eqe(adapter, eqe->entry);
1242 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001243 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244 }
1245
1246 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1247 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1248 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1249
1250 ehea_h_reset_events(adapter->handle,
1251 adapter->neq->fw_handle, event_mask);
1252}
1253
David Howells7d12e782006-10-05 14:55:46 +01001254static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001255{
1256 struct ehea_adapter *adapter = param;
1257 tasklet_hi_schedule(&adapter->neq_tasklet);
1258 return IRQ_HANDLED;
1259}
1260
1261
1262static int ehea_fill_port_res(struct ehea_port_res *pr)
1263{
1264 int ret;
1265 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1266
Breno Leitaof76957f2011-01-11 07:45:57 +00001267 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268
Thomas Kleine2878802009-01-21 14:45:57 -08001269 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001270
1271 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1272
1273 return ret;
1274}
1275
1276static int ehea_reg_interrupts(struct net_device *dev)
1277{
1278 struct ehea_port *port = netdev_priv(dev);
1279 struct ehea_port_res *pr;
1280 int i, ret;
1281
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001282
1283 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1284 dev->name);
1285
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001286 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001288 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001289 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001290 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1291 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 goto out_free_qpeq;
1293 }
1294
Joe Perches8c4877a2010-12-13 10:05:14 -08001295 netif_info(port, ifup, dev,
1296 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1297 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001298
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001299
Anton Blanchard723f28e2011-10-14 05:31:01 +00001300 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301 pr = &port->port_res[i];
1302 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001303 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001304 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001305 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001306 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307 pr);
1308 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001309 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1310 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001311 goto out_free_req;
1312 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001313 netif_info(port, ifup, dev,
1314 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1315 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001316 }
1317out:
1318 return ret;
1319
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001320
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001321out_free_req:
1322 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001323 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001324 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001325 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001326
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001328 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001329 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001331 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001332
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001333}
1334
1335static void ehea_free_interrupts(struct net_device *dev)
1336{
1337 struct ehea_port *port = netdev_priv(dev);
1338 struct ehea_port_res *pr;
1339 int i;
1340
1341 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001342
Anton Blanchard723f28e2011-10-14 05:31:01 +00001343 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001345 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001346 netif_info(port, intr, dev,
1347 "free send irq for res %d with handle 0x%X\n",
1348 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349 }
1350
1351 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001352 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001353 netif_info(port, intr, dev,
1354 "associated event interrupt for handle 0x%X freed\n",
1355 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356}
1357
1358static int ehea_configure_port(struct ehea_port *port)
1359{
1360 int ret, i;
1361 u64 hret, mask;
1362 struct hcp_ehea_port_cb0 *cb0;
1363
1364 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001365 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 if (!cb0)
1367 goto out;
1368
1369 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1370 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1371 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1372 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1374 PXLY_RC_VLAN_FILTER)
1375 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1376
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001377 for (i = 0; i < port->num_mcs; i++)
1378 if (use_mcs)
1379 cb0->default_qpn_arr[i] =
1380 port->port_res[i].qp->init_attr.qp_nr;
1381 else
1382 cb0->default_qpn_arr[i] =
1383 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001384
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001385 if (netif_msg_ifup(port))
1386 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1387
1388 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1389 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1390
1391 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1392 port->logical_port_id,
1393 H_PORT_CB0, mask, cb0);
1394 ret = -EIO;
1395 if (hret != H_SUCCESS)
1396 goto out_free;
1397
1398 ret = 0;
1399
1400out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001401 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001402out:
1403 return ret;
1404}
1405
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001406static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001408 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001409 struct ehea_adapter *adapter = pr->port->adapter;
1410
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001411 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1412 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001413 goto out;
1414
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001415 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1416 if (ret)
1417 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418
1419 return 0;
1420
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001421out_free:
1422 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001424 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001425 return -EIO;
1426}
1427
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001428static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001429{
Joe Perches8e95a202009-12-03 07:58:21 +00001430 if ((ehea_rem_mr(&pr->send_mr)) ||
1431 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001432 return -EIO;
1433 else
1434 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001435}
1436
1437static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1438{
Doug Maxey508d2b52008-01-31 20:20:49 -06001439 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001440
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001441 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001442 if (!q_skba->arr)
1443 return -ENOMEM;
1444
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445 q_skba->len = max_q_entries;
1446 q_skba->index = 0;
1447 q_skba->os_skbs = 0;
1448
1449 return 0;
1450}
1451
1452static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1453 struct port_res_cfg *pr_cfg, int queue_token)
1454{
1455 struct ehea_adapter *adapter = port->adapter;
1456 enum ehea_eq_type eq_type = EHEA_EQ;
1457 struct ehea_qp_init_attr *init_attr = NULL;
1458 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001459 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1460
1461 tx_bytes = pr->tx_bytes;
1462 tx_packets = pr->tx_packets;
1463 rx_bytes = pr->rx_bytes;
1464 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001465
1466 memset(pr, 0, sizeof(struct ehea_port_res));
1467
Breno Leitaoce45b872010-10-27 08:45:14 +00001468 pr->tx_bytes = rx_bytes;
1469 pr->tx_packets = tx_packets;
1470 pr->rx_bytes = rx_bytes;
1471 pr->rx_packets = rx_packets;
1472
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001473 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001475 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1476 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001477 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478 goto out_free;
1479 }
1480
1481 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001482 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 port->logical_port_id);
1484 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001485 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486 goto out_free;
1487 }
1488
1489 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001490 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491 port->logical_port_id);
1492 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001493 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001494 goto out_free;
1495 }
1496
1497 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001498 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1499 pr->send_cq->attr.act_nr_of_cqes,
1500 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001501
1502 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1503 if (!init_attr) {
1504 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001505 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506 goto out_free;
1507 }
1508
1509 init_attr->low_lat_rq1 = 1;
1510 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1511 init_attr->rq_count = 3;
1512 init_attr->qp_token = queue_token;
1513 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1514 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1515 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1516 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1517 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1518 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1519 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1520 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1521 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1522 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1523 init_attr->port_nr = port->logical_port_id;
1524 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1525 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1526 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1527
1528 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1529 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001530 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001531 ret = -EIO;
1532 goto out_free;
1533 }
1534
1535 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001536 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",
1537 init_attr->qp_nr,
1538 init_attr->act_nr_send_wqes,
1539 init_attr->act_nr_rwqes_rq1,
1540 init_attr->act_nr_rwqes_rq2,
1541 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001542
Thomas Klein44fb3122008-04-04 15:04:53 +02001543 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1544
1545 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001546 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1547 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1548 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1549 if (ret)
1550 goto out_free;
1551
1552 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1553 if (ehea_gen_smrs(pr) != 0) {
1554 ret = -EIO;
1555 goto out_free;
1556 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001557
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1559
1560 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001561
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001562 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001564 ret = 0;
1565 goto out;
1566
1567out_free:
1568 kfree(init_attr);
1569 vfree(pr->sq_skba.arr);
1570 vfree(pr->rq1_skba.arr);
1571 vfree(pr->rq2_skba.arr);
1572 vfree(pr->rq3_skba.arr);
1573 ehea_destroy_qp(pr->qp);
1574 ehea_destroy_cq(pr->send_cq);
1575 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001576 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001577out:
1578 return ret;
1579}
1580
1581static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1582{
1583 int ret, i;
1584
Hannes Hering357eb462009-08-04 11:48:39 -07001585 if (pr->qp)
1586 netif_napi_del(&pr->napi);
1587
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001588 ret = ehea_destroy_qp(pr->qp);
1589
1590 if (!ret) {
1591 ehea_destroy_cq(pr->send_cq);
1592 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001593 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001594
1595 for (i = 0; i < pr->rq1_skba.len; i++)
1596 if (pr->rq1_skba.arr[i])
1597 dev_kfree_skb(pr->rq1_skba.arr[i]);
1598
1599 for (i = 0; i < pr->rq2_skba.len; i++)
1600 if (pr->rq2_skba.arr[i])
1601 dev_kfree_skb(pr->rq2_skba.arr[i]);
1602
1603 for (i = 0; i < pr->rq3_skba.len; i++)
1604 if (pr->rq3_skba.arr[i])
1605 dev_kfree_skb(pr->rq3_skba.arr[i]);
1606
1607 for (i = 0; i < pr->sq_skba.len; i++)
1608 if (pr->sq_skba.arr[i])
1609 dev_kfree_skb(pr->sq_skba.arr[i]);
1610
1611 vfree(pr->rq1_skba.arr);
1612 vfree(pr->rq2_skba.arr);
1613 vfree(pr->rq3_skba.arr);
1614 vfree(pr->sq_skba.arr);
1615 ret = ehea_rem_smrs(pr);
1616 }
1617 return ret;
1618}
1619
Anton Blanchard13946f52011-10-14 05:31:06 +00001620static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1621 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001622{
Eric Dumazete743d312010-04-14 15:59:40 -07001623 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001624 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1625 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001626 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627
Anton Blanchard13946f52011-10-14 05:31:06 +00001628 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001629
Anton Blanchard13946f52011-10-14 05:31:06 +00001630 if (skb_is_gso(skb)) {
1631 swqe->tx_control |= EHEA_SWQE_TSO;
1632 swqe->mss = skb_shinfo(skb)->gso_size;
1633 /*
1634 * For TSO packets we only copy the headers into the
1635 * immediate area.
1636 */
1637 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1638 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001639
Anton Blanchard13946f52011-10-14 05:31:06 +00001640 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1641 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1642 swqe->immediate_data_length = immediate_len;
1643
1644 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001645 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001646 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001647 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001648 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001649 swqe->descriptors++;
1650 }
1651 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001652 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001653 swqe->immediate_data_length = skb_data_size;
1654 }
1655}
1656
1657static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1658 struct ehea_swqe *swqe, u32 lkey)
1659{
1660 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1661 skb_frag_t *frag;
1662 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001663
1664 nfrags = skb_shinfo(skb)->nr_frags;
1665 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001666 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001667 sg1entry_contains_frag_data = 0;
1668
Anton Blanchard13946f52011-10-14 05:31:06 +00001669 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001670
1671 /* write descriptors */
1672 if (nfrags > 0) {
1673 if (swqe->descriptors == 0) {
1674 /* sg1entry not yet used */
1675 frag = &skb_shinfo(skb)->frags[0];
1676
1677 /* copy sg1entry data */
1678 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001679 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001680 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001681 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001682 swqe->descriptors++;
1683 sg1entry_contains_frag_data = 1;
1684 }
1685
1686 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1687
1688 frag = &skb_shinfo(skb)->frags[i];
1689 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1690
1691 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001692 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001693 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001694 swqe->descriptors++;
1695 }
1696 }
1697}
1698
1699static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1700{
1701 int ret = 0;
1702 u64 hret;
1703 u8 reg_type;
1704
1705 /* De/Register untagged packets */
1706 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1707 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1708 port->logical_port_id,
1709 reg_type, port->mac_addr, 0, hcallid);
1710 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001711 pr_err("%sregistering bc address failed (tagged)\n",
1712 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001713 ret = -EIO;
1714 goto out_herr;
1715 }
1716
1717 /* De/Register VLAN packets */
1718 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1719 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1720 port->logical_port_id,
1721 reg_type, port->mac_addr, 0, hcallid);
1722 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001723 pr_err("%sregistering bc address failed (vlan)\n",
1724 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001725 ret = -EIO;
1726 }
1727out_herr:
1728 return ret;
1729}
1730
1731static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1732{
1733 struct ehea_port *port = netdev_priv(dev);
1734 struct sockaddr *mac_addr = sa;
1735 struct hcp_ehea_port_cb0 *cb0;
1736 int ret;
1737 u64 hret;
1738
1739 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1740 ret = -EADDRNOTAVAIL;
1741 goto out;
1742 }
1743
Thomas Klein3faf2692009-01-21 14:45:33 -08001744 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001746 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001747 ret = -ENOMEM;
1748 goto out;
1749 }
1750
1751 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1752
1753 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1754
1755 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1756 port->logical_port_id, H_PORT_CB0,
1757 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1758 if (hret != H_SUCCESS) {
1759 ret = -EIO;
1760 goto out_free;
1761 }
1762
1763 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1764
1765 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001766 if (port->state == EHEA_PORT_UP) {
1767 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1768 if (ret)
1769 goto out_upregs;
1770 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001771
1772 port->mac_addr = cb0->port_mac_addr << 16;
1773
1774 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001775 if (port->state == EHEA_PORT_UP) {
1776 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1777 if (ret)
1778 goto out_upregs;
1779 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001780
1781 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001782
1783out_upregs:
1784 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001786 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001787out:
1788 return ret;
1789}
1790
1791static void ehea_promiscuous_error(u64 hret, int enable)
1792{
Thomas Klein7674a582007-01-22 12:54:20 +01001793 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001794 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1795 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001796 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001797 pr_err("failed %sabling promiscuous mode\n",
1798 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799}
1800
1801static void ehea_promiscuous(struct net_device *dev, int enable)
1802{
1803 struct ehea_port *port = netdev_priv(dev);
1804 struct hcp_ehea_port_cb7 *cb7;
1805 u64 hret;
1806
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001807 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001808 return;
1809
Thomas Klein3faf2692009-01-21 14:45:33 -08001810 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001811 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001812 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001813 goto out;
1814 }
1815
1816 /* Modify Pxs_DUCQPN in CB7 */
1817 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1818
1819 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1820 port->logical_port_id,
1821 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1822 if (hret) {
1823 ehea_promiscuous_error(hret, enable);
1824 goto out;
1825 }
1826
1827 port->promisc = enable;
1828out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001829 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001830}
1831
1832static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1833 u32 hcallid)
1834{
1835 u64 hret;
1836 u8 reg_type;
1837
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001838 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1839 if (mc_mac_addr == 0)
1840 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001841
1842 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1843 port->logical_port_id,
1844 reg_type, mc_mac_addr, 0, hcallid);
1845 if (hret)
1846 goto out;
1847
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001848 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1849 if (mc_mac_addr == 0)
1850 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001851
1852 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1853 port->logical_port_id,
1854 reg_type, mc_mac_addr, 0, hcallid);
1855out:
1856 return hret;
1857}
1858
1859static int ehea_drop_multicast_list(struct net_device *dev)
1860{
1861 struct ehea_port *port = netdev_priv(dev);
1862 struct ehea_mc_list *mc_entry = port->mc_list;
1863 struct list_head *pos;
1864 struct list_head *temp;
1865 int ret = 0;
1866 u64 hret;
1867
1868 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1869 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1870
1871 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1872 H_DEREG_BCMC);
1873 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001874 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001875 ret = -EIO;
1876 }
1877
1878 list_del(pos);
1879 kfree(mc_entry);
1880 }
1881 return ret;
1882}
1883
1884static void ehea_allmulti(struct net_device *dev, int enable)
1885{
1886 struct ehea_port *port = netdev_priv(dev);
1887 u64 hret;
1888
1889 if (!port->allmulti) {
1890 if (enable) {
1891 /* Enable ALLMULTI */
1892 ehea_drop_multicast_list(dev);
1893 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1894 if (!hret)
1895 port->allmulti = 1;
1896 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001897 netdev_err(dev,
1898 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001899 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001900 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001901 if (!enable) {
1902 /* Disable ALLMULTI */
1903 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1904 if (!hret)
1905 port->allmulti = 0;
1906 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001907 netdev_err(dev,
1908 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001909 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001910 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001911}
1912
Doug Maxey508d2b52008-01-31 20:20:49 -06001913static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914{
1915 struct ehea_mc_list *ehea_mcl_entry;
1916 u64 hret;
1917
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001918 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001919 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001920 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921
1922 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1923
1924 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1925
1926 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1927 H_REG_BCMC);
1928 if (!hret)
1929 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1930 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001931 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932 kfree(ehea_mcl_entry);
1933 }
1934}
1935
1936static void ehea_set_multicast_list(struct net_device *dev)
1937{
1938 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001939 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001940 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001941
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001942 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001943
1944 if (dev->flags & IFF_ALLMULTI) {
1945 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001946 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 }
1948 ehea_allmulti(dev, 0);
1949
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001950 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951 ret = ehea_drop_multicast_list(dev);
1952 if (ret) {
1953 /* Dropping the current multicast list failed.
1954 * Enabling ALL_MULTI is the best we can do.
1955 */
1956 ehea_allmulti(dev, 1);
1957 }
1958
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001959 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001960 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1961 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001962 goto out;
1963 }
1964
Jiri Pirko22bedad32010-04-01 21:22:57 +00001965 netdev_for_each_mc_addr(ha, dev)
1966 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001967
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001968 }
1969out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001970 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001971}
1972
1973static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1974{
1975 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1976 return -EINVAL;
1977 dev->mtu = new_mtu;
1978 return 0;
1979}
1980
Anton Blanchardd695c332011-10-14 05:31:05 +00001981static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1982{
1983 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1984
1985 if (skb->protocol != htons(ETH_P_IP))
1986 return;
1987
1988 if (skb->ip_summed == CHECKSUM_PARTIAL)
1989 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1990
1991 swqe->ip_start = skb_network_offset(skb);
1992 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1993
1994 switch (ip_hdr(skb)->protocol) {
1995 case IPPROTO_UDP:
1996 if (skb->ip_summed == CHECKSUM_PARTIAL)
1997 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
1998
1999 swqe->tcp_offset = swqe->ip_end + 1 +
2000 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002001 break;
2002
2003 case IPPROTO_TCP:
2004 if (skb->ip_summed == CHECKSUM_PARTIAL)
2005 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2006
2007 swqe->tcp_offset = swqe->ip_end + 1 +
2008 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002009 break;
2010 }
2011}
2012
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002013static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2014 struct ehea_swqe *swqe, u32 lkey)
2015{
Anton Blanchardd695c332011-10-14 05:31:05 +00002016 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002017
Anton Blanchardd695c332011-10-14 05:31:05 +00002018 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002019
2020 write_swqe2_data(skb, dev, swqe, lkey);
2021}
2022
2023static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2024 struct ehea_swqe *swqe)
2025{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002026 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002027
Anton Blanchardd695c332011-10-14 05:31:05 +00002028 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002029
Anton Blanchard30e2e902011-10-14 05:31:07 +00002030 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002031 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002032 else
2033 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002034
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 swqe->immediate_data_length = skb->len;
2036 dev_kfree_skb(skb);
2037}
2038
2039static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2040{
2041 struct ehea_port *port = netdev_priv(dev);
2042 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 u32 lkey;
2044 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002045 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002046 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002047
Anton Blanchardb9564462011-10-14 05:30:59 +00002048 pr = &port->port_res[skb_get_queue_mapping(skb)];
2049 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002050
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2052 memset(swqe, 0, SWQE_HEADER_SIZE);
2053 atomic_dec(&pr->swqe_avail);
2054
Eric Dumazete5ccd962010-10-26 19:21:07 +00002055 if (vlan_tx_tag_present(skb)) {
2056 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2057 swqe->vlan_tag = vlan_tx_tag_get(skb);
2058 }
2059
Breno Leitaoce45b872010-10-27 08:45:14 +00002060 pr->tx_packets++;
2061 pr->tx_bytes += skb->len;
2062
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 if (skb->len <= SWQE3_MAX_IMM) {
2064 u32 sig_iv = port->sig_comp_iv;
2065 u32 swqe_num = pr->swqe_id_counter;
2066 ehea_xmit3(skb, dev, swqe);
2067 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2068 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2069 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2070 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2071 sig_iv);
2072 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2073 pr->swqe_ll_count = 0;
2074 } else
2075 pr->swqe_ll_count += 1;
2076 } else {
2077 swqe->wr_id =
2078 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2079 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002080 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002081 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2082 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2083
2084 pr->sq_skba.index++;
2085 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2086
2087 lkey = pr->send_mr.lkey;
2088 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002089 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002090 }
2091 pr->swqe_id_counter += 1;
2092
Joe Perches8c4877a2010-12-13 10:05:14 -08002093 netif_info(port, tx_queued, dev,
2094 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2095 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002096 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002097
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002098 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002099 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002100 swqe->tx_control |= EHEA_SWQE_PURGE;
2101 }
Thomas Klein44c82152007-07-11 16:32:00 +02002102
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002103 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002104
2105 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002106 pr->p_stats.queue_stopped++;
2107 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002109
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 return NETDEV_TX_OK;
2111}
2112
Jiri Pirko8e586132011-12-08 19:52:37 -05002113static int ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002114{
2115 struct ehea_port *port = netdev_priv(dev);
2116 struct ehea_adapter *adapter = port->adapter;
2117 struct hcp_ehea_port_cb1 *cb1;
2118 int index;
2119 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002120 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002121
Thomas Klein3faf2692009-01-21 14:45:33 -08002122 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002123 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002124 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002125 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126 goto out;
2127 }
2128
2129 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2130 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2131 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002132 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002133 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002134 goto out;
2135 }
2136
2137 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002138 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002139
2140 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2141 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002142 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002143 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002144 err = -EINVAL;
2145 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002146out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002147 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002148 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002149}
2150
Jiri Pirko8e586132011-12-08 19:52:37 -05002151static int ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152{
2153 struct ehea_port *port = netdev_priv(dev);
2154 struct ehea_adapter *adapter = port->adapter;
2155 struct hcp_ehea_port_cb1 *cb1;
2156 int index;
2157 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002158 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002159
Thomas Klein3faf2692009-01-21 14:45:33 -08002160 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002161 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002162 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002163 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164 goto out;
2165 }
2166
2167 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2168 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2169 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002170 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002171 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002172 goto out;
2173 }
2174
2175 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002176 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002177
2178 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2179 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002180 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002181 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002182 err = -EINVAL;
2183 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002185 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002186 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002187}
2188
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002189static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002190{
2191 int ret = -EIO;
2192 u64 hret;
2193 u16 dummy16 = 0;
2194 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002195 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002196
Thomas Klein3faf2692009-01-21 14:45:33 -08002197 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002198 if (!cb0) {
2199 ret = -ENOMEM;
2200 goto out;
2201 }
2202
2203 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2204 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2205 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002206 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002207 goto out;
2208 }
2209
2210 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2211 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2212 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2213 &dummy64, &dummy64, &dummy16, &dummy16);
2214 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002215 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002216 goto out;
2217 }
2218
2219 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2220 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2221 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002222 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002223 goto out;
2224 }
2225
2226 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2227 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2228 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2229 &dummy64, &dummy64, &dummy16, &dummy16);
2230 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002231 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002232 goto out;
2233 }
2234
2235 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2236 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2237 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002238 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002239 goto out;
2240 }
2241
2242 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2243 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2244 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2245 &dummy64, &dummy64, &dummy16, &dummy16);
2246 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002247 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002248 goto out;
2249 }
2250
2251 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2252 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2253 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002254 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002255 goto out;
2256 }
2257
2258 ret = 0;
2259out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002260 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002261 return ret;
2262}
2263
Anton Blanchard723f28e2011-10-14 05:31:01 +00002264static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002265{
2266 int ret, i;
2267 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2268 enum ehea_eq_type eq_type = EHEA_EQ;
2269
2270 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2271 EHEA_MAX_ENTRIES_EQ, 1);
2272 if (!port->qp_eq) {
2273 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002274 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275 goto out_kill_eq;
2276 }
2277
2278 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002279 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002280 pr_cfg.max_entries_sq = sq_entries;
2281 pr_cfg.max_entries_rq1 = rq1_entries;
2282 pr_cfg.max_entries_rq2 = rq2_entries;
2283 pr_cfg.max_entries_rq3 = rq3_entries;
2284
2285 pr_cfg_small_rx.max_entries_rcq = 1;
2286 pr_cfg_small_rx.max_entries_scq = sq_entries;
2287 pr_cfg_small_rx.max_entries_sq = sq_entries;
2288 pr_cfg_small_rx.max_entries_rq1 = 1;
2289 pr_cfg_small_rx.max_entries_rq2 = 1;
2290 pr_cfg_small_rx.max_entries_rq3 = 1;
2291
2292 for (i = 0; i < def_qps; i++) {
2293 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2294 if (ret)
2295 goto out_clean_pr;
2296 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002297 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 ret = ehea_init_port_res(port, &port->port_res[i],
2299 &pr_cfg_small_rx, i);
2300 if (ret)
2301 goto out_clean_pr;
2302 }
2303
2304 return 0;
2305
2306out_clean_pr:
2307 while (--i >= 0)
2308 ehea_clean_portres(port, &port->port_res[i]);
2309
2310out_kill_eq:
2311 ehea_destroy_eq(port->qp_eq);
2312 return ret;
2313}
2314
2315static int ehea_clean_all_portres(struct ehea_port *port)
2316{
2317 int ret = 0;
2318 int i;
2319
Anton Blanchard723f28e2011-10-14 05:31:01 +00002320 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002321 ret |= ehea_clean_portres(port, &port->port_res[i]);
2322
2323 ret |= ehea_destroy_eq(port->qp_eq);
2324
2325 return ret;
2326}
2327
Thomas Klein35cf2e22007-08-06 13:55:14 +02002328static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002329{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002330 if (adapter->active_ports)
2331 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002332
2333 ehea_rem_mr(&adapter->mr);
2334}
2335
Thomas Klein35cf2e22007-08-06 13:55:14 +02002336static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002337{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002338 if (adapter->active_ports)
2339 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002340
2341 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2342}
2343
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002344static int ehea_up(struct net_device *dev)
2345{
2346 int ret, i;
2347 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002348
2349 if (port->state == EHEA_PORT_UP)
2350 return 0;
2351
Anton Blanchard723f28e2011-10-14 05:31:01 +00002352 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002354 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355 goto out;
2356 }
2357
2358 /* Set default QP for this port */
2359 ret = ehea_configure_port(port);
2360 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002361 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362 goto out_clean_pr;
2363 }
2364
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365 ret = ehea_reg_interrupts(dev);
2366 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002367 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002368 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369 }
2370
Anton Blanchard723f28e2011-10-14 05:31:01 +00002371 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002372 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2373 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002374 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 goto out_free_irqs;
2376 }
2377 }
2378
Doug Maxey508d2b52008-01-31 20:20:49 -06002379 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 ret = ehea_fill_port_res(&port->port_res[i]);
2381 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002382 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002383 goto out_free_irqs;
2384 }
2385 }
2386
Thomas Klein21eee2d2008-02-13 16:18:33 +01002387 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2388 if (ret) {
2389 ret = -EIO;
2390 goto out_free_irqs;
2391 }
2392
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002393 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002394
2395 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002396 goto out;
2397
2398out_free_irqs:
2399 ehea_free_interrupts(dev);
2400
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401out_clean_pr:
2402 ehea_clean_all_portres(port);
2403out:
Thomas Klein44c82152007-07-11 16:32:00 +02002404 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002405 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002406
Thomas Klein21eee2d2008-02-13 16:18:33 +01002407 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002408 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002410 return ret;
2411}
2412
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002413static void port_napi_disable(struct ehea_port *port)
2414{
2415 int i;
2416
Anton Blanchard723f28e2011-10-14 05:31:01 +00002417 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002418 napi_disable(&port->port_res[i].napi);
2419}
2420
2421static void port_napi_enable(struct ehea_port *port)
2422{
2423 int i;
2424
Anton Blanchard723f28e2011-10-14 05:31:01 +00002425 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002426 napi_enable(&port->port_res[i].napi);
2427}
2428
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002429static int ehea_open(struct net_device *dev)
2430{
2431 int ret;
2432 struct ehea_port *port = netdev_priv(dev);
2433
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002434 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002435
Joe Perches8c4877a2010-12-13 10:05:14 -08002436 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002437
2438 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002439 if (!ret) {
2440 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002441 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002442 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002444 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002445 schedule_delayed_work(&port->stats_work,
2446 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002447
2448 return ret;
2449}
2450
2451static int ehea_down(struct net_device *dev)
2452{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002453 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454 struct ehea_port *port = netdev_priv(dev);
2455
2456 if (port->state == EHEA_PORT_DOWN)
2457 return 0;
2458
2459 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002460 ehea_allmulti(dev, 0);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002461 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2462
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002463 ehea_free_interrupts(dev);
2464
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002465 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002466
Thomas Klein21eee2d2008-02-13 16:18:33 +01002467 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002468
Thomas Klein44c82152007-07-11 16:32:00 +02002469 ret = ehea_clean_all_portres(port);
2470 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002471 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002472
Thomas Klein21eee2d2008-02-13 16:18:33 +01002473 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002474
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002475 return ret;
2476}
2477
2478static int ehea_stop(struct net_device *dev)
2479{
2480 int ret;
2481 struct ehea_port *port = netdev_priv(dev);
2482
Joe Perches8c4877a2010-12-13 10:05:14 -08002483 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002484
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002485 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002486 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002487 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002488 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002489 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002490 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002491 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002492 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002493 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002494 return ret;
2495}
2496
Andrew Morton22559c52008-04-18 13:50:39 -07002497static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002498{
2499 struct ehea_qp qp = *orig_qp;
2500 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2501 struct ehea_swqe *swqe;
2502 int wqe_index;
2503 int i;
2504
2505 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2506 swqe = ehea_get_swqe(&qp, &wqe_index);
2507 swqe->tx_control |= EHEA_SWQE_PURGE;
2508 }
2509}
2510
Andrew Morton22559c52008-04-18 13:50:39 -07002511static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002512{
2513 int i;
2514
Anton Blanchard723f28e2011-10-14 05:31:01 +00002515 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002516 struct ehea_port_res *pr = &port->port_res[i];
2517 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002518 int ret;
2519
2520 ret = wait_event_timeout(port->swqe_avail_wq,
2521 atomic_read(&pr->swqe_avail) >= swqe_max,
2522 msecs_to_jiffies(100));
2523
2524 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002525 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002526 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002527 }
2528 }
2529}
2530
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002531static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002532{
2533 struct ehea_port *port = netdev_priv(dev);
2534 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002535 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002536 int ret = -EIO;
2537 int dret;
2538 int i;
2539 u64 hret;
2540 u64 dummy64 = 0;
2541 u16 dummy16 = 0;
2542
Thomas Klein3faf2692009-01-21 14:45:33 -08002543 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002544 if (!cb0) {
2545 ret = -ENOMEM;
2546 goto out;
2547 }
2548
Anton Blanchard723f28e2011-10-14 05:31:01 +00002549 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002550 struct ehea_port_res *pr = &port->port_res[i];
2551 struct ehea_qp *qp = pr->qp;
2552
2553 /* Purge send queue */
2554 ehea_purge_sq(qp);
2555
2556 /* Disable queue pair */
2557 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2558 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2559 cb0);
2560 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002561 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002562 goto out;
2563 }
2564
2565 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2566 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2567
2568 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2569 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2570 1), cb0, &dummy64,
2571 &dummy64, &dummy16, &dummy16);
2572 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002573 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002574 goto out;
2575 }
2576
2577 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2578 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2579 cb0);
2580 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002581 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002582 goto out;
2583 }
2584
2585 /* deregister shared memory regions */
2586 dret = ehea_rem_smrs(pr);
2587 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002588 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002589 goto out;
2590 }
2591 }
2592
2593 ret = 0;
2594out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002595 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002596
2597 return ret;
2598}
2599
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002600static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002601{
2602 struct ehea_qp qp = *orig_qp;
2603 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2604 struct ehea_rwqe *rwqe;
2605 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2606 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2607 struct sk_buff *skb;
2608 u32 lkey = pr->recv_mr.lkey;
2609
2610
2611 int i;
2612 int index;
2613
2614 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2615 rwqe = ehea_get_next_rwqe(&qp, 2);
2616 rwqe->sg_list[0].l_key = lkey;
2617 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2618 skb = skba_rq2[index];
2619 if (skb)
2620 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2621 }
2622
2623 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2624 rwqe = ehea_get_next_rwqe(&qp, 3);
2625 rwqe->sg_list[0].l_key = lkey;
2626 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2627 skb = skba_rq3[index];
2628 if (skb)
2629 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2630 }
2631}
2632
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002633static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002634{
2635 struct ehea_port *port = netdev_priv(dev);
2636 struct ehea_adapter *adapter = port->adapter;
2637 int ret = 0;
2638 int i;
2639
Doug Maxey508d2b52008-01-31 20:20:49 -06002640 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002641 u64 hret;
2642 u64 dummy64 = 0;
2643 u16 dummy16 = 0;
2644
Thomas Klein3faf2692009-01-21 14:45:33 -08002645 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002646 if (!cb0) {
2647 ret = -ENOMEM;
2648 goto out;
2649 }
2650
Anton Blanchard723f28e2011-10-14 05:31:01 +00002651 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002652 struct ehea_port_res *pr = &port->port_res[i];
2653 struct ehea_qp *qp = pr->qp;
2654
2655 ret = ehea_gen_smrs(pr);
2656 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002657 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002658 goto out;
2659 }
2660
2661 ehea_update_rqs(qp, pr);
2662
2663 /* Enable queue pair */
2664 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2665 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2666 cb0);
2667 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002668 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002669 goto out;
2670 }
2671
2672 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2673 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2674
2675 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2676 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2677 1), cb0, &dummy64,
2678 &dummy64, &dummy16, &dummy16);
2679 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002680 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002681 goto out;
2682 }
2683
2684 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2685 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2686 cb0);
2687 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002688 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002689 goto out;
2690 }
2691
2692 /* refill entire queue */
2693 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2694 ehea_refill_rq2(pr, 0);
2695 ehea_refill_rq3(pr, 0);
2696 }
2697out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002698 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002699
2700 return ret;
2701}
2702
David Howellsc4028952006-11-22 14:57:56 +00002703static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002704{
2705 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002706 struct ehea_port *port =
2707 container_of(work, struct ehea_port, reset_task);
2708 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002709
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002710 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002711 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002712 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002713 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002714
2715 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716
Thomas Klein44c82152007-07-11 16:32:00 +02002717 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002718
2719 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002720 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002721 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002722
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002723 ehea_set_multicast_list(dev);
2724
Joe Perches8c4877a2010-12-13 10:05:14 -08002725 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002727 port_napi_enable(port);
2728
Anton Blanchardb9564462011-10-14 05:30:59 +00002729 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002730out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002731 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002732 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733}
2734
Tejun Heo3d6b8922010-12-12 16:45:14 +01002735static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002736{
2737 int ret, i;
2738 struct ehea_adapter *adapter;
2739
Joe Perches8c4877a2010-12-13 10:05:14 -08002740 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002741
2742 list_for_each_entry(adapter, &adapter_list, list)
2743 if (adapter->active_ports) {
2744 /* Shutdown all ports */
2745 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2746 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002747 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002748
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002749 if (!port)
2750 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002751
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002752 dev = port->netdev;
2753
2754 if (dev->flags & IFF_UP) {
2755 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002756 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002757 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002758 ret = ehea_stop_qps(dev);
2759 if (ret) {
2760 mutex_unlock(&port->port_lock);
2761 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002762 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002763 port_napi_disable(port);
2764 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002765 }
Andre Detsch2928db42010-08-17 05:49:12 +00002766 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002767 }
2768
2769 /* Unregister old memory region */
2770 ret = ehea_rem_mr(&adapter->mr);
2771 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002772 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002773 goto out;
2774 }
2775 }
2776
Thomas Klein44c82152007-07-11 16:32:00 +02002777 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2778
2779 list_for_each_entry(adapter, &adapter_list, list)
2780 if (adapter->active_ports) {
2781 /* Register new memory region */
2782 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2783 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002784 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002785 goto out;
2786 }
2787
2788 /* Restart all ports */
2789 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2790 struct ehea_port *port = adapter->port[i];
2791
2792 if (port) {
2793 struct net_device *dev = port->netdev;
2794
2795 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002796 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002797 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002798 if (!ret) {
2799 check_sqs(port);
2800 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002801 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002802 } else {
2803 netdev_err(dev, "Unable to restart QPS\n");
2804 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002805 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002806 }
2807 }
2808 }
2809 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002810 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002811out:
2812 return;
2813}
2814
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002815static void ehea_tx_watchdog(struct net_device *dev)
2816{
2817 struct ehea_port *port = netdev_priv(dev);
2818
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002819 if (netif_carrier_ok(dev) &&
2820 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002821 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002822}
2823
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002824static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002825{
2826 struct hcp_query_ehea *cb;
2827 u64 hret;
2828 int ret;
2829
Thomas Klein3faf2692009-01-21 14:45:33 -08002830 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002831 if (!cb) {
2832 ret = -ENOMEM;
2833 goto out;
2834 }
2835
2836 hret = ehea_h_query_ehea(adapter->handle, cb);
2837
2838 if (hret != H_SUCCESS) {
2839 ret = -EIO;
2840 goto out_herr;
2841 }
2842
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002843 adapter->max_mc_mac = cb->max_mc_mac - 1;
2844 ret = 0;
2845
2846out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002847 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002848out:
2849 return ret;
2850}
2851
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002852static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002853{
2854 struct hcp_ehea_port_cb4 *cb4;
2855 u64 hret;
2856 int ret = 0;
2857
2858 *jumbo = 0;
2859
2860 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002861 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002862 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002863 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002864 ret = -ENOMEM;
2865 goto out;
2866 } else {
2867 hret = ehea_h_query_ehea_port(port->adapter->handle,
2868 port->logical_port_id,
2869 H_PORT_CB4,
2870 H_PORT_CB4_JUMBO, cb4);
2871 if (hret == H_SUCCESS) {
2872 if (cb4->jumbo_frame)
2873 *jumbo = 1;
2874 else {
2875 cb4->jumbo_frame = 1;
2876 hret = ehea_h_modify_ehea_port(port->adapter->
2877 handle,
2878 port->
2879 logical_port_id,
2880 H_PORT_CB4,
2881 H_PORT_CB4_JUMBO,
2882 cb4);
2883 if (hret == H_SUCCESS)
2884 *jumbo = 1;
2885 }
2886 } else
2887 ret = -EINVAL;
2888
Thomas Klein3faf2692009-01-21 14:45:33 -08002889 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002890 }
2891out:
2892 return ret;
2893}
2894
2895static ssize_t ehea_show_port_id(struct device *dev,
2896 struct device_attribute *attr, char *buf)
2897{
2898 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002899 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002900}
2901
2902static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2903 NULL);
2904
Bill Pemberton0297be02012-12-03 09:23:10 -05002905static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002906{
2907 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002908 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002909}
2910
2911static struct device *ehea_register_port(struct ehea_port *port,
2912 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002913{
2914 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002915
Grant Likely61c7a082010-04-13 16:12:29 -07002916 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002917 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002918 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002919
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002920 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002921 port->ofdev.dev.release = logical_port_release;
2922
2923 ret = of_device_register(&port->ofdev);
2924 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002925 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002926 goto out;
2927 }
2928
2929 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002930 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002931 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002932 goto out_unreg_of_dev;
2933 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002934
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002935 return &port->ofdev.dev;
2936
2937out_unreg_of_dev:
2938 of_device_unregister(&port->ofdev);
2939out:
2940 return NULL;
2941}
2942
2943static void ehea_unregister_port(struct ehea_port *port)
2944{
2945 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2946 of_device_unregister(&port->ofdev);
2947}
2948
Thomas Klein086c1b22009-01-21 14:43:59 -08002949static const struct net_device_ops ehea_netdev_ops = {
2950 .ndo_open = ehea_open,
2951 .ndo_stop = ehea_stop,
2952 .ndo_start_xmit = ehea_start_xmit,
2953#ifdef CONFIG_NET_POLL_CONTROLLER
2954 .ndo_poll_controller = ehea_netpoll,
2955#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002956 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002957 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002958 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002959 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002960 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002961 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002962 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2963 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002964};
2965
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002966static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002967 u32 logical_port_id,
2968 struct device_node *dn)
2969{
2970 int ret;
2971 struct net_device *dev;
2972 struct ehea_port *port;
2973 struct device *port_dev;
2974 int jumbo;
2975
2976 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002977 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002978
2979 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002980 ret = -ENOMEM;
2981 goto out_err;
2982 }
2983
2984 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002985
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002986 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002987 port->state = EHEA_PORT_DOWN;
2988 port->sig_comp_iv = sq_entries / 10;
2989
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002990 port->adapter = adapter;
2991 port->netdev = dev;
2992 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002993
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002994 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002995
2996 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2997 if (!port->mc_list) {
2998 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002999 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003000 }
3001
3002 INIT_LIST_HEAD(&port->mc_list->list);
3003
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003004 ret = ehea_sense_port_attr(port);
3005 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003006 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003007
Anton Blanchardb9564462011-10-14 05:30:59 +00003008 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003009 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003010
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003011 port_dev = ehea_register_port(port, dn);
3012 if (!port_dev)
3013 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003014
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003015 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003016
3017 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003018 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3019
Thomas Klein086c1b22009-01-21 14:43:59 -08003020 dev->netdev_ops = &ehea_netdev_ops;
3021 ehea_set_ethtool_ops(dev);
3022
Anton Blanchardd695c332011-10-14 05:31:05 +00003023 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Ben Hutchings3865fe12012-11-16 12:46:43 +00003024 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003025 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003026 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003027 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003028 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003029 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3030 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003031 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3032
David Howellsc4028952006-11-22 14:57:56 +00003033 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003034 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003035
Anton Blanchard21ccc792011-05-10 16:17:10 +00003036 init_waitqueue_head(&port->swqe_avail_wq);
3037 init_waitqueue_head(&port->restart_wq);
3038
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003039 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003040 ret = register_netdev(dev);
3041 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003042 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003043 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003044 }
3045
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003046 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003047 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003048 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003049
Joe Perches8c4877a2010-12-13 10:05:14 -08003050 netdev_info(dev, "Jumbo frames are %sabled\n",
3051 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003052
Thomas Klein44c82152007-07-11 16:32:00 +02003053 adapter->active_ports++;
3054
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003056
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003057out_unreg_port:
3058 ehea_unregister_port(port);
3059
3060out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003061 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003062
3063out_free_ethdev:
3064 free_netdev(dev);
3065
3066out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003067 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3068 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003069 return NULL;
3070}
3071
3072static void ehea_shutdown_single_port(struct ehea_port *port)
3073{
Brian King7fb1c2a2008-05-14 09:48:25 -05003074 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003075
3076 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003077 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003078 unregister_netdev(port->netdev);
3079 ehea_unregister_port(port);
3080 kfree(port->mc_list);
3081 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003082 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003083}
3084
3085static int ehea_setup_ports(struct ehea_adapter *adapter)
3086{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003087 struct device_node *lhea_dn;
3088 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003089
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003090 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003091 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003092
Grant Likely61c7a082010-04-13 16:12:29 -07003093 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003094 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003095
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003096 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003097 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003099 pr_err("bad device node: eth_dn name=%s\n",
3100 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003101 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003102 }
3103
Thomas Klein1211bb62007-04-26 11:56:43 +02003104 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003105 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003106 of_node_put(eth_dn);
3107 return -EIO;
3108 }
3109
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 adapter->port[i] = ehea_setup_single_port(adapter,
3111 *dn_log_port_id,
3112 eth_dn);
3113 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003114 netdev_info(adapter->port[i]->netdev,
3115 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003116 else
3117 ehea_remove_adapter_mr(adapter);
3118
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003119 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003120 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003121 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003122}
3123
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003124static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3125 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126{
3127 struct device_node *lhea_dn;
3128 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003129 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003130
Grant Likely61c7a082010-04-13 16:12:29 -07003131 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003132 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003133
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003134 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003135 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003136 if (dn_log_port_id)
3137 if (*dn_log_port_id == logical_port_id)
3138 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003139 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140
3141 return NULL;
3142}
3143
3144static ssize_t ehea_probe_port(struct device *dev,
3145 struct device_attribute *attr,
3146 const char *buf, size_t count)
3147{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003148 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003149 struct ehea_port *port;
3150 struct device_node *eth_dn = NULL;
3151 int i;
3152
3153 u32 logical_port_id;
3154
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003155 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156
3157 port = ehea_get_port(adapter, logical_port_id);
3158
3159 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003160 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3161 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162 return -EINVAL;
3163 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003164
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3166
3167 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003168 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169 return -EINVAL;
3170 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003171
Thomas Klein1211bb62007-04-26 11:56:43 +02003172 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003173 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003174 return -EIO;
3175 }
3176
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3178
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003179 of_node_put(eth_dn);
3180
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003181 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003182 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183 if (!adapter->port[i]) {
3184 adapter->port[i] = port;
3185 break;
3186 }
3187
Joe Perches8c4877a2010-12-13 10:05:14 -08003188 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3189 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003190 } else {
3191 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003192 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003193 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003194
3195 return (ssize_t) count;
3196}
3197
3198static ssize_t ehea_remove_port(struct device *dev,
3199 struct device_attribute *attr,
3200 const char *buf, size_t count)
3201{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003202 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003203 struct ehea_port *port;
3204 int i;
3205 u32 logical_port_id;
3206
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003207 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003208
3209 port = ehea_get_port(adapter, logical_port_id);
3210
3211 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003212 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3213 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003214
3215 ehea_shutdown_single_port(port);
3216
Doug Maxey508d2b52008-01-31 20:20:49 -06003217 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 if (adapter->port[i] == port) {
3219 adapter->port[i] = NULL;
3220 break;
3221 }
3222 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003223 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3224 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003225 return -EINVAL;
3226 }
3227
Thomas Klein1211bb62007-04-26 11:56:43 +02003228 ehea_remove_adapter_mr(adapter);
3229
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 return (ssize_t) count;
3231}
3232
3233static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3234static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3235
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003236static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003238 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003239 if (ret)
3240 goto out;
3241
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003242 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003244 return ret;
3245}
3246
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003247static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003248{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003249 device_remove_file(&dev->dev, &dev_attr_probe_port);
3250 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251}
3252
Bill Pemberton0297be02012-12-03 09:23:10 -05003253static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003254 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003255{
3256 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003257 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003258 int ret;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003259 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260
Grant Likely61c7a082010-04-13 16:12:29 -07003261 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003262 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003263 return -EINVAL;
3264 }
3265
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003266 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3267 if (!adapter) {
3268 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003269 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 goto out;
3271 }
3272
Thomas Klein44c82152007-07-11 16:32:00 +02003273 list_add(&adapter->list, &adapter_list);
3274
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003275 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003276
Grant Likely61c7a082010-04-13 16:12:29 -07003277 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003278 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003279 if (adapter_handle)
3280 adapter->handle = *adapter_handle;
3281
3282 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003283 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003284 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003285 ret = -ENODEV;
3286 goto out_free_ad;
3287 }
3288
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003289 adapter->pd = EHEA_PD_ID;
3290
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003291 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003293
3294 /* initialize adapter and ports */
3295 /* get adapter properties */
3296 ret = ehea_sense_adapter_attr(adapter);
3297 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003298 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003299 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003300 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003301
3302 adapter->neq = ehea_create_eq(adapter,
3303 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3304 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003305 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003306 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003307 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003308 }
3309
3310 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3311 (unsigned long)adapter);
3312
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003313 ret = ehea_create_device_sysfs(dev);
3314 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003315 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003317 ret = ehea_setup_ports(adapter);
3318 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003319 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003320 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003321 }
3322
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003323 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3324 ehea_interrupt_neq, IRQF_DISABLED,
3325 "ehea_neq", adapter);
3326 if (ret) {
3327 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3328 goto out_shutdown_ports;
3329 }
3330
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003331 /* Handle any events that might be pending. */
3332 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003333
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003334 ret = 0;
3335 goto out;
3336
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003337out_shutdown_ports:
3338 for (i = 0; i < EHEA_MAX_PORTS; i++)
3339 if (adapter->port[i]) {
3340 ehea_shutdown_single_port(adapter->port[i]);
3341 adapter->port[i] = NULL;
3342 }
3343
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344out_rem_dev_sysfs:
3345 ehea_remove_device_sysfs(dev);
3346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003347out_kill_eq:
3348 ehea_destroy_eq(adapter->neq);
3349
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003350out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003351 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003352 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003353
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003354out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003355 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003356
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003357 return ret;
3358}
3359
Bill Pemberton0297be02012-12-03 09:23:10 -05003360static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003361{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003362 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003363 int i;
3364
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003366 if (adapter->port[i]) {
3367 ehea_shutdown_single_port(adapter->port[i]);
3368 adapter->port[i] = NULL;
3369 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370
3371 ehea_remove_device_sysfs(dev);
3372
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003373 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003374 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375
3376 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003377 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003378 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003379 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003380
Thomas Klein21eee2d2008-02-13 16:18:33 +01003381 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003382
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003383 return 0;
3384}
3385
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003386static void ehea_crash_handler(void)
Thomas Klein21eee2d2008-02-13 16:18:33 +01003387{
3388 int i;
3389
3390 if (ehea_fw_handles.arr)
3391 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3392 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3393 ehea_fw_handles.arr[i].fwh,
3394 FORCE_FREE);
3395
3396 if (ehea_bcmc_regs.arr)
3397 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3398 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3399 ehea_bcmc_regs.arr[i].port_id,
3400 ehea_bcmc_regs.arr[i].reg_type,
3401 ehea_bcmc_regs.arr[i].macaddr,
3402 0, H_DEREG_BCMC);
3403}
3404
Hannes Hering48cfb142008-05-07 14:43:36 +02003405static int ehea_mem_notifier(struct notifier_block *nb,
3406 unsigned long action, void *data)
3407{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003408 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003409 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003410
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003411 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003412
Hannes Hering48cfb142008-05-07 14:43:36 +02003413 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003414 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003415 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003416 /* Readd canceled memory block */
3417 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003418 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003419 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003420 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003421 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003422 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003423 break;
3424 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003425 pr_info("memory is going offline");
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_rem_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 Hering48cfb142008-05-07 14:43:36 +02003430 break;
3431 default:
3432 break;
3433 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003434
3435 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003436 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003437
Thomas Kleina7c561f22010-04-20 23:11:31 +00003438out_unlock:
3439 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003440 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003441}
3442
3443static struct notifier_block ehea_mem_nb = {
3444 .notifier_call = ehea_mem_notifier,
3445};
3446
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003447static int ehea_reboot_notifier(struct notifier_block *nb,
3448 unsigned long action, void *unused)
3449{
3450 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003451 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003452 ibmebus_unregister_driver(&ehea_driver);
3453 }
3454 return NOTIFY_DONE;
3455}
3456
3457static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003458 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003459};
3460
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003461static int check_module_parm(void)
3462{
3463 int ret = 0;
3464
3465 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3466 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003467 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468 ret = -EINVAL;
3469 }
3470 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3471 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003472 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 ret = -EINVAL;
3474 }
3475 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3476 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003477 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003478 ret = -EINVAL;
3479 }
3480 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3481 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003482 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003483 ret = -EINVAL;
3484 }
3485
3486 return ret;
3487}
3488
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003489static ssize_t ehea_show_capabilities(struct device_driver *drv,
3490 char *buf)
3491{
3492 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3493}
3494
3495static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3496 ehea_show_capabilities, NULL);
3497
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003498static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499{
3500 int ret;
3501
Joe Perches8c4877a2010-12-13 10:05:14 -08003502 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503
Thomas Klein21eee2d2008-02-13 16:18:33 +01003504 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3505 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3506
Daniel Walker9f71a562008-03-28 14:41:26 -07003507 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003508 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003509
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510 ret = check_module_parm();
3511 if (ret)
3512 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003513
3514 ret = ehea_create_busmap();
3515 if (ret)
3516 goto out;
3517
Thomas Klein21eee2d2008-02-13 16:18:33 +01003518 ret = register_reboot_notifier(&ehea_reboot_nb);
3519 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003520 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003521
Hannes Hering48cfb142008-05-07 14:43:36 +02003522 ret = register_memory_notifier(&ehea_mem_nb);
3523 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003524 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003525
Joe Perchesc061b182010-08-23 18:20:03 +00003526 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003527 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003528 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003529
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003530 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003531 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003532 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003533 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003534 }
3535
3536 ret = driver_create_file(&ehea_driver.driver,
3537 &driver_attr_capabilities);
3538 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003539 pr_err("failed to register capabilities attribute, ret=%d\n",
3540 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003541 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003542 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003543
Thomas Klein21eee2d2008-02-13 16:18:33 +01003544 return ret;
3545
3546out3:
3547 ibmebus_unregister_driver(&ehea_driver);
3548out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003549 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003550 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003551 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003552out:
3553 return ret;
3554}
3555
3556static void __exit ehea_module_exit(void)
3557{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003558 int ret;
3559
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003560 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003562 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003563 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003564 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003565 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003566 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003567 kfree(ehea_fw_handles.arr);
3568 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003569 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570}
3571
3572module_init(ehea_module_init);
3573module_exit(ehea_module_exit);