blob: a0a3c5f747c9ea1840bb6b7b99a816c6f7746c55 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
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 use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070066static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Doug Maxey508d2b52008-01-31 20:20:49 -060067static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020068
69module_param(msg_level, int, 0);
70module_param(rq1_entries, int, 0);
71module_param(rq2_entries, int, 0);
72module_param(rq3_entries, int, 0);
73module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020074module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070076module_param(use_lro, int, 0);
77module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078
79MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020080MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
81 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
85MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
88MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
91MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000094MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
95 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020096
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070097MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
98 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
99MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
100 "Default = 0");
101
Doug Maxey508d2b52008-01-31 20:20:49 -0600102static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200103static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800104static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700105static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100106struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Grant Likely2dc11582010-08-06 09:25:50 -0600110static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200111 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Grant Likely2dc11582010-08-06 09:25:50 -0600113static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
115static struct of_device_id ehea_device_table[] = {
116 {
117 .name = "lhea",
118 .compatible = "IBM,lhea",
119 },
120 {},
121};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100122MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200123
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700125 .driver = {
126 .name = "ehea",
127 .owner = THIS_MODULE,
128 .of_match_table = ehea_device_table,
129 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200130 .probe = ehea_probe_adapter,
131 .remove = ehea_remove,
132};
133
Doug Maxey508d2b52008-01-31 20:20:49 -0600134void ehea_dump(void *adr, int len, char *msg)
135{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200136 int x;
137 unsigned char *deb = adr;
138 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800139 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
140 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200141 deb += 16;
142 }
143}
144
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100145void ehea_schedule_port_reset(struct ehea_port *port)
146{
147 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
148 schedule_work(&port->reset_task);
149}
150
Thomas Klein21eee2d2008-02-13 16:18:33 +0100151static void ehea_update_firmware_handles(void)
152{
153 struct ehea_fw_handle_entry *arr = NULL;
154 struct ehea_adapter *adapter;
155 int num_adapters = 0;
156 int num_ports = 0;
157 int num_portres = 0;
158 int i = 0;
159 int num_fw_handles, k, l;
160
161 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700162 mutex_lock(&ehea_fw_handles.lock);
163
Thomas Klein21eee2d2008-02-13 16:18:33 +0100164 list_for_each_entry(adapter, &adapter_list, list) {
165 num_adapters++;
166
167 for (k = 0; k < EHEA_MAX_PORTS; k++) {
168 struct ehea_port *port = adapter->port[k];
169
170 if (!port || (port->state != EHEA_PORT_UP))
171 continue;
172
173 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000174 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 }
176 }
177
178 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
179 num_ports * EHEA_NUM_PORT_FW_HANDLES +
180 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
181
182 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000183 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700185 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 } else
187 goto out_update;
188
189 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700190 if (num_adapters == 0)
191 break;
192
Thomas Klein21eee2d2008-02-13 16:18:33 +0100193 for (k = 0; k < EHEA_MAX_PORTS; k++) {
194 struct ehea_port *port = adapter->port[k];
195
Joe Perches8e95a202009-12-03 07:58:21 +0000196 if (!port || (port->state != EHEA_PORT_UP) ||
197 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100198 continue;
199
Anton Blanchard723f28e2011-10-14 05:31:01 +0000200 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100201 struct ehea_port_res *pr = &port->port_res[l];
202
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = pr->qp->fw_handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->send_cq->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->recv_cq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->eq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->send_mr.handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->recv_mr.handle;
215 }
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700218 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100219 }
220
221 arr[i].adh = adapter->handle;
222 arr[i++].fwh = adapter->neq->fw_handle;
223
224 if (adapter->mr.handle) {
225 arr[i].adh = adapter->handle;
226 arr[i++].fwh = adapter->mr.handle;
227 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700228 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100229 }
230
231out_update:
232 kfree(ehea_fw_handles.arr);
233 ehea_fw_handles.arr = arr;
234 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700235out:
236 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100237}
238
239static void ehea_update_bcmc_registrations(void)
240{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700241 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 struct ehea_bcmc_reg_entry *arr = NULL;
243 struct ehea_adapter *adapter;
244 struct ehea_mc_list *mc_entry;
245 int num_registrations = 0;
246 int i = 0;
247 int k;
248
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700249 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
250
Thomas Klein21eee2d2008-02-13 16:18:33 +0100251 /* Determine number of registrations */
252 list_for_each_entry(adapter, &adapter_list, list)
253 for (k = 0; k < EHEA_MAX_PORTS; k++) {
254 struct ehea_port *port = adapter->port[k];
255
256 if (!port || (port->state != EHEA_PORT_UP))
257 continue;
258
259 num_registrations += 2; /* Broadcast registrations */
260
261 list_for_each_entry(mc_entry, &port->mc_list->list,list)
262 num_registrations += 2;
263 }
264
265 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000266 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100267 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700268 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100269 } else
270 goto out_update;
271
272 list_for_each_entry(adapter, &adapter_list, list) {
273 for (k = 0; k < EHEA_MAX_PORTS; k++) {
274 struct ehea_port *port = adapter->port[k];
275
276 if (!port || (port->state != EHEA_PORT_UP))
277 continue;
278
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700279 if (num_registrations == 0)
280 goto out_update;
281
Thomas Klein21eee2d2008-02-13 16:18:33 +0100282 arr[i].adh = adapter->handle;
283 arr[i].port_id = port->logical_port_id;
284 arr[i].reg_type = EHEA_BCMC_BROADCAST |
285 EHEA_BCMC_UNTAGGED;
286 arr[i++].macaddr = port->mac_addr;
287
288 arr[i].adh = adapter->handle;
289 arr[i].port_id = port->logical_port_id;
290 arr[i].reg_type = EHEA_BCMC_BROADCAST |
291 EHEA_BCMC_VLANID_ALL;
292 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700293 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100294
295 list_for_each_entry(mc_entry,
296 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700297 if (num_registrations == 0)
298 goto out_update;
299
Thomas Klein21eee2d2008-02-13 16:18:33 +0100300 arr[i].adh = adapter->handle;
301 arr[i].port_id = port->logical_port_id;
302 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
303 EHEA_BCMC_MULTICAST |
304 EHEA_BCMC_UNTAGGED;
305 arr[i++].macaddr = mc_entry->macaddr;
306
307 arr[i].adh = adapter->handle;
308 arr[i].port_id = port->logical_port_id;
309 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
310 EHEA_BCMC_MULTICAST |
311 EHEA_BCMC_VLANID_ALL;
312 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700313 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100314 }
315 }
316 }
317
318out_update:
319 kfree(ehea_bcmc_regs.arr);
320 ehea_bcmc_regs.arr = arr;
321 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700322out:
323 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100324}
325
Anton Blanchard239c5622011-10-14 05:31:09 +0000326static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
327 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200328{
329 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000330 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200331 int i;
332
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000333 for (i = 0; i < port->num_def_qps; i++) {
334 rx_packets += port->port_res[i].rx_packets;
335 rx_bytes += port->port_res[i].rx_bytes;
336 }
337
Anton Blanchard723f28e2011-10-14 05:31:01 +0000338 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000339 tx_packets += port->port_res[i].tx_packets;
340 tx_bytes += port->port_res[i].tx_bytes;
341 }
342
343 stats->tx_packets = tx_packets;
344 stats->rx_bytes = rx_bytes;
345 stats->tx_bytes = tx_bytes;
346 stats->rx_packets = rx_packets;
347
348 return &port->stats;
349}
350
351static void ehea_update_stats(struct work_struct *work)
352{
353 struct ehea_port *port =
354 container_of(work, struct ehea_port, stats_work.work);
355 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000356 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000357 struct hcp_ehea_port_cb2 *cb2;
358 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359
Brian King3d8009c2010-06-30 11:59:12 +0000360 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200361 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000362 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
363 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364 }
365
366 hret = ehea_h_query_ehea_port(port->adapter->handle,
367 port->logical_port_id,
368 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
369 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800370 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200371 goto out_herr;
372 }
373
374 if (netif_msg_hw(port))
375 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
376
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200377 stats->multicast = cb2->rxmcp;
378 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379
380out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800381 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000382resched:
383 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200384}
385
386static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
387{
388 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
389 struct net_device *dev = pr->port->netdev;
390 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
392 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200393 int i;
394
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200395 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200396
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200397 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200398 if (nr_of_wqes > 0)
399 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200400 pr->rq1_skba.os_skbs = fill_wqes;
401 return;
402 }
403
404 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200405 if (!skb_arr_rq1[index]) {
406 skb_arr_rq1[index] = netdev_alloc_skb(dev,
407 EHEA_L_PKT_SIZE);
408 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800409 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200410 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200411 break;
412 }
413 }
414 index--;
415 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200416 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418
419 if (adder == 0)
420 return;
421
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200423 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424}
425
Thomas Kleine2878802009-01-21 14:45:57 -0800426static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200427{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200428 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
429 struct net_device *dev = pr->port->netdev;
430 int i;
431
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000432 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800433 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000434 return;
435 }
436
437 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200438 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000439 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800440 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800441 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000442 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200443 }
444 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000445 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200446}
447
448static int ehea_refill_rq_def(struct ehea_port_res *pr,
449 struct ehea_q_skb_arr *q_skba, int rq_nr,
450 int num_wqes, int wqe_type, int packet_size)
451{
452 struct net_device *dev = pr->port->netdev;
453 struct ehea_qp *qp = pr->qp;
454 struct sk_buff **skb_arr = q_skba->arr;
455 struct ehea_rwqe *rwqe;
456 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 int ret = 0;
459
460 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200461 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200463 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
464 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200465 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200466 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200467
468 index = q_skba->index;
469 max_index_mask = q_skba->len - 1;
470 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200471 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000472 struct sk_buff *skb;
473
474 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800477 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800478 netdev_info(pr->port->netdev,
479 "rq%i ran dry - no mem for skb\n",
480 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800481 ret = -ENOMEM;
482 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200483 break;
484 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200485
486 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200487 tmp_addr = ehea_map_vaddr(skb->data);
488 if (tmp_addr == -1) {
489 dev_kfree_skb(skb);
490 q_skba->os_skbs = fill_wqes - i;
491 ret = 0;
492 break;
493 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494
495 rwqe = ehea_get_next_rwqe(qp, rq_nr);
496 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200497 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200498 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200499 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 rwqe->sg_list[0].len = packet_size;
501 rwqe->data_segments = 1;
502
503 index++;
504 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200505 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200506 }
Thomas Klein44c82152007-07-11 16:32:00 +0200507
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200508 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 if (adder == 0)
510 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511
512 /* Ring doorbell */
513 iosync();
514 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200515 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200516 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200517 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200518out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200519 return ret;
520}
521
522
523static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
524{
525 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
526 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000527 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200528}
529
530
531static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
532{
533 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
534 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000535 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200536}
537
538static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
539{
540 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
541 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
542 return 0;
543 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
544 (cqe->header_length == 0))
545 return 0;
546 return -EINVAL;
547}
548
549static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000550 struct sk_buff *skb, struct ehea_cqe *cqe,
551 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200552{
553 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
554
555 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200556 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000557
558 /* The packet was not an IPV4 packet so a complemented checksum was
559 calculated. The value is found in the Internet Checksum field. */
560 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
561 skb->ip_summed = CHECKSUM_COMPLETE;
562 skb->csum = csum_unfold(~cqe->inet_checksum_value);
563 } else
564 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000565
566 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200567}
568
569static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
570 int arr_len,
571 struct ehea_cqe *cqe)
572{
573 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
574 struct sk_buff *skb;
575 void *pref;
576 int x;
577
578 x = skb_index + 1;
579 x &= (arr_len - 1);
580
581 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700582 if (pref) {
583 prefetchw(pref);
584 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200585
Hannes Hering0b2febf2009-05-04 11:06:37 -0700586 pref = (skb_array[x]->data);
587 prefetch(pref);
588 prefetch(pref + EHEA_CACHE_LINE);
589 prefetch(pref + EHEA_CACHE_LINE * 2);
590 prefetch(pref + EHEA_CACHE_LINE * 3);
591 }
592
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200593 skb = skb_array[skb_index];
594 skb_array[skb_index] = NULL;
595 return skb;
596}
597
598static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
599 int arr_len, int wqe_index)
600{
601 struct sk_buff *skb;
602 void *pref;
603 int x;
604
605 x = wqe_index + 1;
606 x &= (arr_len - 1);
607
608 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700609 if (pref) {
610 prefetchw(pref);
611 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200612
Hannes Hering0b2febf2009-05-04 11:06:37 -0700613 pref = (skb_array[x]->data);
614 prefetchw(pref);
615 prefetchw(pref + EHEA_CACHE_LINE);
616 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200617
618 skb = skb_array[wqe_index];
619 skb_array[wqe_index] = NULL;
620 return skb;
621}
622
623static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
624 struct ehea_cqe *cqe, int *processed_rq2,
625 int *processed_rq3)
626{
627 struct sk_buff *skb;
628
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100629 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
630 pr->p_stats.err_tcp_cksum++;
631 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
632 pr->p_stats.err_ip_cksum++;
633 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
634 pr->p_stats.err_frame_crc++;
635
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200636 if (rq == 2) {
637 *processed_rq2 += 1;
638 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
639 dev_kfree_skb(skb);
640 } else if (rq == 3) {
641 *processed_rq3 += 1;
642 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
643 dev_kfree_skb(skb);
644 }
645
646 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100647 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800648 pr_err("Critical receive error for QP %d. Resetting port.\n",
649 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100650 ehea_dump(cqe, sizeof(*cqe), "CQE");
651 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100652 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200653 return 1;
654 }
655
656 return 0;
657}
658
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700659static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
660 void **tcph, u64 *hdr_flags, void *priv)
661{
662 struct ehea_cqe *cqe = priv;
663 unsigned int ip_len;
664 struct iphdr *iph;
665
666 /* non tcp/udp packets */
667 if (!cqe->header_length)
668 return -1;
669
670 /* non tcp packet */
671 skb_reset_network_header(skb);
672 iph = ip_hdr(skb);
673 if (iph->protocol != IPPROTO_TCP)
674 return -1;
675
676 ip_len = ip_hdrlen(skb);
677 skb_set_transport_header(skb, ip_len);
678 *tcph = tcp_hdr(skb);
679
680 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700681 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700682 return -1;
683
684 *hdr_flags = LRO_IPV4 | LRO_TCP;
685 *iphdr = iph;
686
687 return 0;
688}
689
690static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
691 struct sk_buff *skb)
692{
Jiri Pirkob4950092011-07-20 04:54:07 +0000693 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
694 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700695
Jiri Pirkob4950092011-07-20 04:54:07 +0000696 if (skb->dev->features & NETIF_F_LRO)
697 lro_receive_skb(&pr->lro_mgr, skb, cqe);
698 else
699 netif_receive_skb(skb);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700700}
701
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700702static int ehea_proc_rwqes(struct net_device *dev,
703 struct ehea_port_res *pr,
704 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200705{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100706 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707 struct ehea_qp *qp = pr->qp;
708 struct ehea_cqe *cqe;
709 struct sk_buff *skb;
710 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
711 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
712 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
713 int skb_arr_rq1_len = pr->rq1_skba.len;
714 int skb_arr_rq2_len = pr->rq2_skba.len;
715 int skb_arr_rq3_len = pr->rq3_skba.len;
716 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000717 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700718 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719
720 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
721 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700724 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 ehea_inc_rq1(qp);
726 processed_rq1++;
727 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200728 if (netif_msg_rx_status(port))
729 ehea_dump(cqe, sizeof(*cqe), "CQE");
730
731 last_wqe_index = wqe_index;
732 rmb();
733 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600734 if (rq == 1) {
735 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200736 skb = get_skb_by_index_ll(skb_arr_rq1,
737 skb_arr_rq1_len,
738 wqe_index);
739 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800740 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800741 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100742
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700743 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200744 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000745 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800746 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000748 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600750 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200751 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000752 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600753 } else if (rq == 2) {
754 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755 skb = get_skb_by_index(skb_arr_rq2,
756 skb_arr_rq2_len, cqe);
757 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800758 netif_err(port, rx_err, dev,
759 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 break;
761 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000762 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600764 } else {
765 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 skb = get_skb_by_index(skb_arr_rq3,
767 skb_arr_rq3_len, cqe);
768 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800769 netif_err(port, rx_err, dev,
770 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200771 break;
772 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000773 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200774 processed_rq3++;
775 }
776
Breno Leitaoce45b872010-10-27 08:45:14 +0000777 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700778 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100779 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100780 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200781 port_reset = ehea_treat_poll_error(pr, rq, cqe,
782 &processed_rq2,
783 &processed_rq3);
784 if (port_reset)
785 break;
786 }
787 cqe = ehea_poll_rq1(qp, &wqe_index);
788 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800789 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700790 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200791
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200792 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000793 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200794
795 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
796 ehea_refill_rq2(pr, processed_rq2);
797 ehea_refill_rq3(pr, processed_rq3);
798
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700799 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200800}
801
Andre Detsch2928db42010-08-17 05:49:12 +0000802#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
803
804static void reset_sq_restart_flag(struct ehea_port *port)
805{
806 int i;
807
Anton Blanchard723f28e2011-10-14 05:31:01 +0000808 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000809 struct ehea_port_res *pr = &port->port_res[i];
810 pr->sq_restart_flag = 0;
811 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000812 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000813}
814
815static void check_sqs(struct ehea_port *port)
816{
817 struct ehea_swqe *swqe;
818 int swqe_index;
819 int i, k;
820
Anton Blanchard723f28e2011-10-14 05:31:01 +0000821 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000822 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000823 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000824 k = 0;
825 swqe = ehea_get_swqe(pr->qp, &swqe_index);
826 memset(swqe, 0, SWQE_HEADER_SIZE);
827 atomic_dec(&pr->swqe_avail);
828
829 swqe->tx_control |= EHEA_SWQE_PURGE;
830 swqe->wr_id = SWQE_RESTART_CHECK;
831 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
832 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
833 swqe->immediate_data_length = 80;
834
835 ehea_post_swqe(pr->qp, swqe);
836
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000837 ret = wait_event_timeout(port->restart_wq,
838 pr->sq_restart_flag == 0,
839 msecs_to_jiffies(100));
840
841 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800842 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000843 ehea_schedule_port_reset(pr->port);
844 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000845 }
846 }
Andre Detsch2928db42010-08-17 05:49:12 +0000847}
848
849
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100850static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200851{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100852 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200853 struct ehea_cq *send_cq = pr->send_cq;
854 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856 int cqe_counter = 0;
857 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100858 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000859 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
860 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100862 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600863 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864 ehea_inc_cq(send_cq);
865
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200866 cqe_counter++;
867 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000868
869 if (cqe->wr_id == SWQE_RESTART_CHECK) {
870 pr->sq_restart_flag = 1;
871 swqe_av++;
872 break;
873 }
874
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800876 pr_err("Bad send completion status=0x%04X\n",
877 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000878
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 if (netif_msg_tx_err(pr->port))
880 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000881
882 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800883 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000884 ehea_schedule_port_reset(pr->port);
885 break;
886 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200887 }
888
889 if (netif_msg_tx_done(pr->port))
890 ehea_dump(cqe, sizeof(*cqe), "CQE");
891
892 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100893 == EHEA_SWQE2_TYPE)) {
894
895 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
896 skb = pr->sq_skba.arr[index];
897 dev_kfree_skb(skb);
898 pr->sq_skba.arr[index] = NULL;
899 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200900
901 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
902 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903
904 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700905 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200906
907 ehea_update_feca(send_cq, cqe_counter);
908 atomic_add(swqe_av, &pr->swqe_avail);
909
Anton Blanchardb9564462011-10-14 05:30:59 +0000910 if (unlikely(netif_tx_queue_stopped(txq) &&
911 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
912 __netif_tx_lock(txq, smp_processor_id());
913 if (netif_tx_queue_stopped(txq) &&
914 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
915 netif_tx_wake_queue(txq);
916 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200917 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000918
Breno Leitao5b27d422010-10-05 13:16:22 +0000919 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200920
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100921 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200922}
923
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700924#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100925
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700926static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200927{
Doug Maxey508d2b52008-01-31 20:20:49 -0600928 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
929 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931 struct ehea_cqe *cqe;
932 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000933 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700934 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100935
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000937 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938
Anton Blanchard222ca962011-10-14 05:31:00 +0000939 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800940 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100941 ehea_reset_cq_ep(pr->recv_cq);
942 ehea_reset_cq_ep(pr->send_cq);
943 ehea_reset_cq_n1(pr->recv_cq);
944 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000945 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
947 cqe_skb = ehea_poll_cq(pr->send_cq);
948
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100949 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700950 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100951
Ben Hutchings288379f2009-01-19 16:43:59 -0800952 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700953 return rx;
954
955 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
956 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100957 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100958
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700959 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200960}
961
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200962#ifdef CONFIG_NET_POLL_CONTROLLER
963static void ehea_netpoll(struct net_device *dev)
964{
965 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700966 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200967
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700968 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800969 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200970}
971#endif
972
David Howells7d12e782006-10-05 14:55:46 +0100973static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200974{
975 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100976
Ben Hutchings288379f2009-01-19 16:43:59 -0800977 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100978
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979 return IRQ_HANDLED;
980}
981
David Howells7d12e782006-10-05 14:55:46 +0100982static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983{
984 struct ehea_port *port = param;
985 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100986 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200987 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000988 u64 resource_type, aer, aerr;
989 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200990
991 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100992
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200994 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800995 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
996 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100997
998 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000999
1000 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1001 &aer, &aerr);
1002
1003 if (resource_type == EHEA_AER_RESTYPE_QP) {
1004 if ((aer & EHEA_AER_RESET_MASK) ||
1005 (aerr & EHEA_AERR_RESET_MASK))
1006 reset_port = 1;
1007 } else
1008 reset_port = 1; /* Reset in case of CQ or EQ error */
1009
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001010 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001011 }
1012
Thomas Kleinea96cea2010-04-20 23:10:55 +00001013 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001014 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001015 ehea_schedule_port_reset(port);
1016 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001017
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001018 return IRQ_HANDLED;
1019}
1020
1021static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1022 int logical_port)
1023{
1024 int i;
1025
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001026 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001027 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001028 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001029 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001030 return NULL;
1031}
1032
1033int ehea_sense_port_attr(struct ehea_port *port)
1034{
1035 int ret;
1036 u64 hret;
1037 struct hcp_ehea_port_cb0 *cb0;
1038
Doug Maxey508d2b52008-01-31 20:20:49 -06001039 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001040 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001041 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001042 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001043 ret = -ENOMEM;
1044 goto out;
1045 }
1046
1047 hret = ehea_h_query_ehea_port(port->adapter->handle,
1048 port->logical_port_id, H_PORT_CB0,
1049 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1050 cb0);
1051 if (hret != H_SUCCESS) {
1052 ret = -EIO;
1053 goto out_free;
1054 }
1055
1056 /* MAC address */
1057 port->mac_addr = cb0->port_mac_addr << 16;
1058
Doug Maxey508d2b52008-01-31 20:20:49 -06001059 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001060 ret = -EADDRNOTAVAIL;
1061 goto out_free;
1062 }
1063
1064 /* Port speed */
1065 switch (cb0->port_speed) {
1066 case H_SPEED_10M_H:
1067 port->port_speed = EHEA_SPEED_10M;
1068 port->full_duplex = 0;
1069 break;
1070 case H_SPEED_10M_F:
1071 port->port_speed = EHEA_SPEED_10M;
1072 port->full_duplex = 1;
1073 break;
1074 case H_SPEED_100M_H:
1075 port->port_speed = EHEA_SPEED_100M;
1076 port->full_duplex = 0;
1077 break;
1078 case H_SPEED_100M_F:
1079 port->port_speed = EHEA_SPEED_100M;
1080 port->full_duplex = 1;
1081 break;
1082 case H_SPEED_1G_F:
1083 port->port_speed = EHEA_SPEED_1G;
1084 port->full_duplex = 1;
1085 break;
1086 case H_SPEED_10G_F:
1087 port->port_speed = EHEA_SPEED_10G;
1088 port->full_duplex = 1;
1089 break;
1090 default:
1091 port->port_speed = 0;
1092 port->full_duplex = 0;
1093 break;
1094 }
1095
Thomas Kleine919b592007-01-22 12:53:20 +01001096 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001097 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001098
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001099 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001100 if (use_mcs)
1101 port->num_def_qps = cb0->num_default_qps;
1102 else
1103 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001104
1105 if (!port->num_def_qps) {
1106 ret = -EINVAL;
1107 goto out_free;
1108 }
1109
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001110 ret = 0;
1111out_free:
1112 if (ret || netif_msg_probe(port))
1113 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001114 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001115out:
1116 return ret;
1117}
1118
1119int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1120{
1121 struct hcp_ehea_port_cb4 *cb4;
1122 u64 hret;
1123 int ret = 0;
1124
Thomas Klein3faf2692009-01-21 14:45:33 -08001125 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001126 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001127 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001128 ret = -ENOMEM;
1129 goto out;
1130 }
1131
1132 cb4->port_speed = port_speed;
1133
1134 netif_carrier_off(port->netdev);
1135
1136 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1137 port->logical_port_id,
1138 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1139 if (hret == H_SUCCESS) {
1140 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1141
1142 hret = ehea_h_query_ehea_port(port->adapter->handle,
1143 port->logical_port_id,
1144 H_PORT_CB4, H_PORT_CB4_SPEED,
1145 cb4);
1146 if (hret == H_SUCCESS) {
1147 switch (cb4->port_speed) {
1148 case H_SPEED_10M_H:
1149 port->port_speed = EHEA_SPEED_10M;
1150 port->full_duplex = 0;
1151 break;
1152 case H_SPEED_10M_F:
1153 port->port_speed = EHEA_SPEED_10M;
1154 port->full_duplex = 1;
1155 break;
1156 case H_SPEED_100M_H:
1157 port->port_speed = EHEA_SPEED_100M;
1158 port->full_duplex = 0;
1159 break;
1160 case H_SPEED_100M_F:
1161 port->port_speed = EHEA_SPEED_100M;
1162 port->full_duplex = 1;
1163 break;
1164 case H_SPEED_1G_F:
1165 port->port_speed = EHEA_SPEED_1G;
1166 port->full_duplex = 1;
1167 break;
1168 case H_SPEED_10G_F:
1169 port->port_speed = EHEA_SPEED_10G;
1170 port->full_duplex = 1;
1171 break;
1172 default:
1173 port->port_speed = 0;
1174 port->full_duplex = 0;
1175 break;
1176 }
1177 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001179 ret = -EIO;
1180 }
1181 } else {
1182 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001183 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184 ret = -EPERM;
1185 } else {
1186 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001187 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001188 }
1189 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001190 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1191 netif_carrier_on(port->netdev);
1192
Thomas Klein3faf2692009-01-21 14:45:33 -08001193 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001194out:
1195 return ret;
1196}
1197
1198static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1199{
1200 int ret;
1201 u8 ec;
1202 u8 portnum;
1203 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001204 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001205
1206 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1207 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1208 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001209 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001210
1211 switch (ec) {
1212 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1213
1214 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001215 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216 break;
1217 }
1218
1219 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001221 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001223 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224 break;
1225 }
1226
Joe Perches8c4877a2010-12-13 10:05:14 -08001227 netif_info(port, link, dev,
1228 "Logical port up: %dMbps %s Duplex\n",
1229 port->port_speed,
1230 port->full_duplex == 1 ?
1231 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001232
Joe Perches8c4877a2010-12-13 10:05:14 -08001233 netif_carrier_on(dev);
1234 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001235 }
1236 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001237 if (netif_carrier_ok(dev)) {
1238 netif_info(port, link, dev,
1239 "Logical port down\n");
1240 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001241 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001242 }
1243
1244 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001245 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001246 netif_info(port, link, dev,
1247 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001248 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001249 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001251 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001252 netif_info(port, link, dev,
1253 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001254 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001255 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 }
1257
1258 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001259 netdev_info(dev,
1260 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001262 netdev_info(dev,
1263 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001264
1265 break;
1266 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001267 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268 break;
1269 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001270 netdev_info(dev, "Port malfunction\n");
1271 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001272 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 break;
1274 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001275 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001276 break;
1277 }
1278}
1279
1280static void ehea_neq_tasklet(unsigned long data)
1281{
Doug Maxey508d2b52008-01-31 20:20:49 -06001282 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283 struct ehea_eqe *eqe;
1284 u64 event_mask;
1285
1286 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001287 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288
1289 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001290 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001291 ehea_parse_eqe(adapter, eqe->entry);
1292 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001293 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294 }
1295
1296 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1297 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1298 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1299
1300 ehea_h_reset_events(adapter->handle,
1301 adapter->neq->fw_handle, event_mask);
1302}
1303
David Howells7d12e782006-10-05 14:55:46 +01001304static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001305{
1306 struct ehea_adapter *adapter = param;
1307 tasklet_hi_schedule(&adapter->neq_tasklet);
1308 return IRQ_HANDLED;
1309}
1310
1311
1312static int ehea_fill_port_res(struct ehea_port_res *pr)
1313{
1314 int ret;
1315 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1316
Breno Leitaof76957f2011-01-11 07:45:57 +00001317 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001318
Thomas Kleine2878802009-01-21 14:45:57 -08001319 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320
1321 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1322
1323 return ret;
1324}
1325
1326static int ehea_reg_interrupts(struct net_device *dev)
1327{
1328 struct ehea_port *port = netdev_priv(dev);
1329 struct ehea_port_res *pr;
1330 int i, ret;
1331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332
1333 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1334 dev->name);
1335
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001336 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001338 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001340 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1341 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001342 goto out_free_qpeq;
1343 }
1344
Joe Perches8c4877a2010-12-13 10:05:14 -08001345 netif_info(port, ifup, dev,
1346 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1347 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001349
Anton Blanchard723f28e2011-10-14 05:31:01 +00001350 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001351 pr = &port->port_res[i];
1352 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001353 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001354 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001355 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001356 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 pr);
1358 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001359 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1360 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361 goto out_free_req;
1362 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001363 netif_info(port, ifup, dev,
1364 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1365 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 }
1367out:
1368 return ret;
1369
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001370
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001371out_free_req:
1372 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001373 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001374 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001375 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001376
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001377out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001378 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001380
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001381 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001382
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383}
1384
1385static void ehea_free_interrupts(struct net_device *dev)
1386{
1387 struct ehea_port *port = netdev_priv(dev);
1388 struct ehea_port_res *pr;
1389 int i;
1390
1391 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001392
Anton Blanchard723f28e2011-10-14 05:31:01 +00001393 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001395 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001396 netif_info(port, intr, dev,
1397 "free send irq for res %d with handle 0x%X\n",
1398 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001399 }
1400
1401 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001402 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001403 netif_info(port, intr, dev,
1404 "associated event interrupt for handle 0x%X freed\n",
1405 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001406}
1407
1408static int ehea_configure_port(struct ehea_port *port)
1409{
1410 int ret, i;
1411 u64 hret, mask;
1412 struct hcp_ehea_port_cb0 *cb0;
1413
1414 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001415 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001416 if (!cb0)
1417 goto out;
1418
1419 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1420 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1421 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1422 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1423 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1424 PXLY_RC_VLAN_FILTER)
1425 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1426
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001427 for (i = 0; i < port->num_mcs; i++)
1428 if (use_mcs)
1429 cb0->default_qpn_arr[i] =
1430 port->port_res[i].qp->init_attr.qp_nr;
1431 else
1432 cb0->default_qpn_arr[i] =
1433 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001434
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001435 if (netif_msg_ifup(port))
1436 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1437
1438 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1439 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1440
1441 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1442 port->logical_port_id,
1443 H_PORT_CB0, mask, cb0);
1444 ret = -EIO;
1445 if (hret != H_SUCCESS)
1446 goto out_free;
1447
1448 ret = 0;
1449
1450out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001451 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001452out:
1453 return ret;
1454}
1455
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001456int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001457{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001458 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001459 struct ehea_adapter *adapter = pr->port->adapter;
1460
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001461 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1462 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001463 goto out;
1464
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001465 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1466 if (ret)
1467 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001468
1469 return 0;
1470
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001471out_free:
1472 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001473out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001474 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475 return -EIO;
1476}
1477
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001478int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479{
Joe Perches8e95a202009-12-03 07:58:21 +00001480 if ((ehea_rem_mr(&pr->send_mr)) ||
1481 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001482 return -EIO;
1483 else
1484 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485}
1486
1487static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1488{
Doug Maxey508d2b52008-01-31 20:20:49 -06001489 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001491 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 if (!q_skba->arr)
1493 return -ENOMEM;
1494
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495 q_skba->len = max_q_entries;
1496 q_skba->index = 0;
1497 q_skba->os_skbs = 0;
1498
1499 return 0;
1500}
1501
1502static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1503 struct port_res_cfg *pr_cfg, int queue_token)
1504{
1505 struct ehea_adapter *adapter = port->adapter;
1506 enum ehea_eq_type eq_type = EHEA_EQ;
1507 struct ehea_qp_init_attr *init_attr = NULL;
1508 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001509 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1510
1511 tx_bytes = pr->tx_bytes;
1512 tx_packets = pr->tx_packets;
1513 rx_bytes = pr->rx_bytes;
1514 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001515
1516 memset(pr, 0, sizeof(struct ehea_port_res));
1517
Breno Leitaoce45b872010-10-27 08:45:14 +00001518 pr->tx_bytes = rx_bytes;
1519 pr->tx_packets = tx_packets;
1520 pr->rx_bytes = rx_bytes;
1521 pr->rx_packets = rx_packets;
1522
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001523 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001524
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001525 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1526 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001527 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001528 goto out_free;
1529 }
1530
1531 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001532 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001533 port->logical_port_id);
1534 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001535 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001536 goto out_free;
1537 }
1538
1539 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001540 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541 port->logical_port_id);
1542 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001543 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001544 goto out_free;
1545 }
1546
1547 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001548 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1549 pr->send_cq->attr.act_nr_of_cqes,
1550 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551
1552 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1553 if (!init_attr) {
1554 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001555 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001556 goto out_free;
1557 }
1558
1559 init_attr->low_lat_rq1 = 1;
1560 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1561 init_attr->rq_count = 3;
1562 init_attr->qp_token = queue_token;
1563 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1564 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1565 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1566 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1567 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1568 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1569 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1570 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1571 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1572 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1573 init_attr->port_nr = port->logical_port_id;
1574 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1575 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1576 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1577
1578 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1579 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001580 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001581 ret = -EIO;
1582 goto out_free;
1583 }
1584
1585 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001586 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",
1587 init_attr->qp_nr,
1588 init_attr->act_nr_send_wqes,
1589 init_attr->act_nr_rwqes_rq1,
1590 init_attr->act_nr_rwqes_rq2,
1591 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001592
Thomas Klein44fb3122008-04-04 15:04:53 +02001593 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1594
1595 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001596 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1597 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1598 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1599 if (ret)
1600 goto out_free;
1601
1602 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1603 if (ehea_gen_smrs(pr) != 0) {
1604 ret = -EIO;
1605 goto out_free;
1606 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001607
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001608 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1609
1610 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001611
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001612 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001613
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001614 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1615 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1616 pr->lro_mgr.lro_arr = pr->lro_desc;
1617 pr->lro_mgr.get_skb_header = get_skb_hdr;
1618 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1619 pr->lro_mgr.dev = port->netdev;
1620 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1621 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1622
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001623 ret = 0;
1624 goto out;
1625
1626out_free:
1627 kfree(init_attr);
1628 vfree(pr->sq_skba.arr);
1629 vfree(pr->rq1_skba.arr);
1630 vfree(pr->rq2_skba.arr);
1631 vfree(pr->rq3_skba.arr);
1632 ehea_destroy_qp(pr->qp);
1633 ehea_destroy_cq(pr->send_cq);
1634 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001635 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001636out:
1637 return ret;
1638}
1639
1640static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1641{
1642 int ret, i;
1643
Hannes Hering357eb462009-08-04 11:48:39 -07001644 if (pr->qp)
1645 netif_napi_del(&pr->napi);
1646
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001647 ret = ehea_destroy_qp(pr->qp);
1648
1649 if (!ret) {
1650 ehea_destroy_cq(pr->send_cq);
1651 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001652 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001653
1654 for (i = 0; i < pr->rq1_skba.len; i++)
1655 if (pr->rq1_skba.arr[i])
1656 dev_kfree_skb(pr->rq1_skba.arr[i]);
1657
1658 for (i = 0; i < pr->rq2_skba.len; i++)
1659 if (pr->rq2_skba.arr[i])
1660 dev_kfree_skb(pr->rq2_skba.arr[i]);
1661
1662 for (i = 0; i < pr->rq3_skba.len; i++)
1663 if (pr->rq3_skba.arr[i])
1664 dev_kfree_skb(pr->rq3_skba.arr[i]);
1665
1666 for (i = 0; i < pr->sq_skba.len; i++)
1667 if (pr->sq_skba.arr[i])
1668 dev_kfree_skb(pr->sq_skba.arr[i]);
1669
1670 vfree(pr->rq1_skba.arr);
1671 vfree(pr->rq2_skba.arr);
1672 vfree(pr->rq3_skba.arr);
1673 vfree(pr->sq_skba.arr);
1674 ret = ehea_rem_smrs(pr);
1675 }
1676 return ret;
1677}
1678
Anton Blanchard13946f52011-10-14 05:31:06 +00001679static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1680 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001681{
Eric Dumazete743d312010-04-14 15:59:40 -07001682 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001683 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1684 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001685 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001686
Anton Blanchard13946f52011-10-14 05:31:06 +00001687 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001688
Anton Blanchard13946f52011-10-14 05:31:06 +00001689 if (skb_is_gso(skb)) {
1690 swqe->tx_control |= EHEA_SWQE_TSO;
1691 swqe->mss = skb_shinfo(skb)->gso_size;
1692 /*
1693 * For TSO packets we only copy the headers into the
1694 * immediate area.
1695 */
1696 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1697 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001698
Anton Blanchard13946f52011-10-14 05:31:06 +00001699 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1700 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1701 swqe->immediate_data_length = immediate_len;
1702
1703 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001704 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001705 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001706 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001707 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708 swqe->descriptors++;
1709 }
1710 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001711 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001712 swqe->immediate_data_length = skb_data_size;
1713 }
1714}
1715
1716static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1717 struct ehea_swqe *swqe, u32 lkey)
1718{
1719 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1720 skb_frag_t *frag;
1721 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001722
1723 nfrags = skb_shinfo(skb)->nr_frags;
1724 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001725 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 sg1entry_contains_frag_data = 0;
1727
Anton Blanchard13946f52011-10-14 05:31:06 +00001728 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001729
1730 /* write descriptors */
1731 if (nfrags > 0) {
1732 if (swqe->descriptors == 0) {
1733 /* sg1entry not yet used */
1734 frag = &skb_shinfo(skb)->frags[0];
1735
1736 /* copy sg1entry data */
1737 sg1entry->l_key = lkey;
1738 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001739 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001740 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001741 swqe->descriptors++;
1742 sg1entry_contains_frag_data = 1;
1743 }
1744
1745 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1746
1747 frag = &skb_shinfo(skb)->frags[i];
1748 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1749
1750 sgentry->l_key = lkey;
1751 sgentry->len = frag->size;
Ian Campbell618c4a02011-10-10 01:11:38 +00001752 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753 swqe->descriptors++;
1754 }
1755 }
1756}
1757
1758static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1759{
1760 int ret = 0;
1761 u64 hret;
1762 u8 reg_type;
1763
1764 /* De/Register untagged packets */
1765 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1766 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1767 port->logical_port_id,
1768 reg_type, port->mac_addr, 0, hcallid);
1769 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001770 pr_err("%sregistering bc address failed (tagged)\n",
1771 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001772 ret = -EIO;
1773 goto out_herr;
1774 }
1775
1776 /* De/Register VLAN packets */
1777 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1778 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1779 port->logical_port_id,
1780 reg_type, port->mac_addr, 0, hcallid);
1781 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001782 pr_err("%sregistering bc address failed (vlan)\n",
1783 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001784 ret = -EIO;
1785 }
1786out_herr:
1787 return ret;
1788}
1789
1790static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1791{
1792 struct ehea_port *port = netdev_priv(dev);
1793 struct sockaddr *mac_addr = sa;
1794 struct hcp_ehea_port_cb0 *cb0;
1795 int ret;
1796 u64 hret;
1797
1798 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1799 ret = -EADDRNOTAVAIL;
1800 goto out;
1801 }
1802
Thomas Klein3faf2692009-01-21 14:45:33 -08001803 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001804 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001805 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001806 ret = -ENOMEM;
1807 goto out;
1808 }
1809
1810 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1811
1812 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1813
1814 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1815 port->logical_port_id, H_PORT_CB0,
1816 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1817 if (hret != H_SUCCESS) {
1818 ret = -EIO;
1819 goto out_free;
1820 }
1821
1822 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1823
1824 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001825 if (port->state == EHEA_PORT_UP) {
1826 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1827 if (ret)
1828 goto out_upregs;
1829 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001830
1831 port->mac_addr = cb0->port_mac_addr << 16;
1832
1833 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001834 if (port->state == EHEA_PORT_UP) {
1835 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1836 if (ret)
1837 goto out_upregs;
1838 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001839
1840 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001841
1842out_upregs:
1843 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001844out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001845 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001846out:
1847 return ret;
1848}
1849
1850static void ehea_promiscuous_error(u64 hret, int enable)
1851{
Thomas Klein7674a582007-01-22 12:54:20 +01001852 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001853 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1854 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001855 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001856 pr_err("failed %sabling promiscuous mode\n",
1857 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001858}
1859
1860static void ehea_promiscuous(struct net_device *dev, int enable)
1861{
1862 struct ehea_port *port = netdev_priv(dev);
1863 struct hcp_ehea_port_cb7 *cb7;
1864 u64 hret;
1865
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001866 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001867 return;
1868
Thomas Klein3faf2692009-01-21 14:45:33 -08001869 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001870 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001871 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001872 goto out;
1873 }
1874
1875 /* Modify Pxs_DUCQPN in CB7 */
1876 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1877
1878 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1879 port->logical_port_id,
1880 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1881 if (hret) {
1882 ehea_promiscuous_error(hret, enable);
1883 goto out;
1884 }
1885
1886 port->promisc = enable;
1887out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001888 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001889}
1890
1891static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1892 u32 hcallid)
1893{
1894 u64 hret;
1895 u8 reg_type;
1896
1897 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1898 | EHEA_BCMC_UNTAGGED;
1899
1900 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1901 port->logical_port_id,
1902 reg_type, mc_mac_addr, 0, hcallid);
1903 if (hret)
1904 goto out;
1905
1906 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1907 | EHEA_BCMC_VLANID_ALL;
1908
1909 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1910 port->logical_port_id,
1911 reg_type, mc_mac_addr, 0, hcallid);
1912out:
1913 return hret;
1914}
1915
1916static int ehea_drop_multicast_list(struct net_device *dev)
1917{
1918 struct ehea_port *port = netdev_priv(dev);
1919 struct ehea_mc_list *mc_entry = port->mc_list;
1920 struct list_head *pos;
1921 struct list_head *temp;
1922 int ret = 0;
1923 u64 hret;
1924
1925 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1926 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1927
1928 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1929 H_DEREG_BCMC);
1930 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001931 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932 ret = -EIO;
1933 }
1934
1935 list_del(pos);
1936 kfree(mc_entry);
1937 }
1938 return ret;
1939}
1940
1941static void ehea_allmulti(struct net_device *dev, int enable)
1942{
1943 struct ehea_port *port = netdev_priv(dev);
1944 u64 hret;
1945
1946 if (!port->allmulti) {
1947 if (enable) {
1948 /* Enable ALLMULTI */
1949 ehea_drop_multicast_list(dev);
1950 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1951 if (!hret)
1952 port->allmulti = 1;
1953 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001954 netdev_err(dev,
1955 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001956 }
1957 } else
1958 if (!enable) {
1959 /* Disable ALLMULTI */
1960 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1961 if (!hret)
1962 port->allmulti = 0;
1963 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001964 netdev_err(dev,
1965 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001966 }
1967}
1968
Doug Maxey508d2b52008-01-31 20:20:49 -06001969static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001970{
1971 struct ehea_mc_list *ehea_mcl_entry;
1972 u64 hret;
1973
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001974 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001975 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001976 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001977 return;
1978 }
1979
1980 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1981
1982 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1983
1984 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1985 H_REG_BCMC);
1986 if (!hret)
1987 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1988 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001989 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001990 kfree(ehea_mcl_entry);
1991 }
1992}
1993
1994static void ehea_set_multicast_list(struct net_device *dev)
1995{
1996 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001997 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001998 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001999
Breno Leitaoa4910b72011-05-23 03:36:35 +00002000 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002001 ehea_promiscuous(dev, 1);
2002 return;
2003 }
2004 ehea_promiscuous(dev, 0);
2005
2006 if (dev->flags & IFF_ALLMULTI) {
2007 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002008 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002009 }
2010 ehea_allmulti(dev, 0);
2011
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002012 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002013 ret = ehea_drop_multicast_list(dev);
2014 if (ret) {
2015 /* Dropping the current multicast list failed.
2016 * Enabling ALL_MULTI is the best we can do.
2017 */
2018 ehea_allmulti(dev, 1);
2019 }
2020
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002021 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002022 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2023 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002024 goto out;
2025 }
2026
Jiri Pirko22bedad32010-04-01 21:22:57 +00002027 netdev_for_each_mc_addr(ha, dev)
2028 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002029
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002030 }
2031out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002032 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033}
2034
2035static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2036{
2037 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2038 return -EINVAL;
2039 dev->mtu = new_mtu;
2040 return 0;
2041}
2042
Anton Blanchardd695c332011-10-14 05:31:05 +00002043static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
2044{
2045 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
2046
2047 if (skb->protocol != htons(ETH_P_IP))
2048 return;
2049
2050 if (skb->ip_summed == CHECKSUM_PARTIAL)
2051 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
2052
2053 swqe->ip_start = skb_network_offset(skb);
2054 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
2055
2056 switch (ip_hdr(skb)->protocol) {
2057 case IPPROTO_UDP:
2058 if (skb->ip_summed == CHECKSUM_PARTIAL)
2059 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2060
2061 swqe->tcp_offset = swqe->ip_end + 1 +
2062 offsetof(struct udphdr, check);
2063 swqe->tcp_end = skb->len - 1;
2064 break;
2065
2066 case IPPROTO_TCP:
2067 if (skb->ip_summed == CHECKSUM_PARTIAL)
2068 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2069
2070 swqe->tcp_offset = swqe->ip_end + 1 +
2071 offsetof(struct tcphdr, check);
2072 swqe->tcp_end = skb->len - 1;
2073 break;
2074 }
2075}
2076
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002077static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2078 struct ehea_swqe *swqe, u32 lkey)
2079{
Anton Blanchardd695c332011-10-14 05:31:05 +00002080 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002081
Anton Blanchardd695c332011-10-14 05:31:05 +00002082 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002083
2084 write_swqe2_data(skb, dev, swqe, lkey);
2085}
2086
2087static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2088 struct ehea_swqe *swqe)
2089{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002090 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002091
Anton Blanchardd695c332011-10-14 05:31:05 +00002092 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002093
Anton Blanchard30e2e902011-10-14 05:31:07 +00002094 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002095 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002096 else
2097 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002098
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099 swqe->immediate_data_length = skb->len;
2100 dev_kfree_skb(skb);
2101}
2102
2103static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2104{
2105 struct ehea_port *port = netdev_priv(dev);
2106 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107 u32 lkey;
2108 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002109 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002110 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111
Anton Blanchardb9564462011-10-14 05:30:59 +00002112 pr = &port->port_res[skb_get_queue_mapping(skb)];
2113 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002114
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2116 memset(swqe, 0, SWQE_HEADER_SIZE);
2117 atomic_dec(&pr->swqe_avail);
2118
Eric Dumazete5ccd962010-10-26 19:21:07 +00002119 if (vlan_tx_tag_present(skb)) {
2120 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2121 swqe->vlan_tag = vlan_tx_tag_get(skb);
2122 }
2123
Breno Leitaoce45b872010-10-27 08:45:14 +00002124 pr->tx_packets++;
2125 pr->tx_bytes += skb->len;
2126
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127 if (skb->len <= SWQE3_MAX_IMM) {
2128 u32 sig_iv = port->sig_comp_iv;
2129 u32 swqe_num = pr->swqe_id_counter;
2130 ehea_xmit3(skb, dev, swqe);
2131 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2132 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2133 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2134 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2135 sig_iv);
2136 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2137 pr->swqe_ll_count = 0;
2138 } else
2139 pr->swqe_ll_count += 1;
2140 } else {
2141 swqe->wr_id =
2142 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2143 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002144 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002145 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2146 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2147
2148 pr->sq_skba.index++;
2149 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2150
2151 lkey = pr->send_mr.lkey;
2152 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002153 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002154 }
2155 pr->swqe_id_counter += 1;
2156
Joe Perches8c4877a2010-12-13 10:05:14 -08002157 netif_info(port, tx_queued, dev,
2158 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2159 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002160 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002161
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002162 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002163 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002164 swqe->tx_control |= EHEA_SWQE_PURGE;
2165 }
Thomas Klein44c82152007-07-11 16:32:00 +02002166
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002167 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002168
2169 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002170 pr->p_stats.queue_stopped++;
2171 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002172 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002173
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174 return NETDEV_TX_OK;
2175}
2176
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002177static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2178{
2179 struct ehea_port *port = netdev_priv(dev);
2180 struct ehea_adapter *adapter = port->adapter;
2181 struct hcp_ehea_port_cb1 *cb1;
2182 int index;
2183 u64 hret;
2184
Thomas Klein3faf2692009-01-21 14:45:33 -08002185 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002186 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002187 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002188 goto out;
2189 }
2190
2191 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2192 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2193 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002194 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002195 goto out;
2196 }
2197
2198 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002199 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002200
2201 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2202 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2203 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002204 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002205out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002206 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002207 return;
2208}
2209
2210static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2211{
2212 struct ehea_port *port = netdev_priv(dev);
2213 struct ehea_adapter *adapter = port->adapter;
2214 struct hcp_ehea_port_cb1 *cb1;
2215 int index;
2216 u64 hret;
2217
Thomas Klein3faf2692009-01-21 14:45:33 -08002218 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002220 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002221 goto out;
2222 }
2223
2224 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2225 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2226 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002227 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002228 goto out;
2229 }
2230
2231 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002232 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002233
2234 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2235 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2236 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002237 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002238out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002239 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002240}
2241
2242int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2243{
2244 int ret = -EIO;
2245 u64 hret;
2246 u16 dummy16 = 0;
2247 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002248 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002249
Thomas Klein3faf2692009-01-21 14:45:33 -08002250 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251 if (!cb0) {
2252 ret = -ENOMEM;
2253 goto out;
2254 }
2255
2256 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2257 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2258 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002259 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002260 goto out;
2261 }
2262
2263 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2264 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2265 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2266 &dummy64, &dummy64, &dummy16, &dummy16);
2267 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002268 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002269 goto out;
2270 }
2271
2272 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2273 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2274 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002275 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002276 goto out;
2277 }
2278
2279 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2280 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2281 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2282 &dummy64, &dummy64, &dummy16, &dummy16);
2283 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002284 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 goto out;
2286 }
2287
2288 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2289 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2290 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002291 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002292 goto out;
2293 }
2294
2295 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2296 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2297 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2298 &dummy64, &dummy64, &dummy16, &dummy16);
2299 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002300 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301 goto out;
2302 }
2303
2304 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2305 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2306 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002307 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002308 goto out;
2309 }
2310
2311 ret = 0;
2312out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002313 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002314 return ret;
2315}
2316
Anton Blanchard723f28e2011-10-14 05:31:01 +00002317static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002318{
2319 int ret, i;
2320 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2321 enum ehea_eq_type eq_type = EHEA_EQ;
2322
2323 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2324 EHEA_MAX_ENTRIES_EQ, 1);
2325 if (!port->qp_eq) {
2326 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002327 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 goto out_kill_eq;
2329 }
2330
2331 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002332 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002333 pr_cfg.max_entries_sq = sq_entries;
2334 pr_cfg.max_entries_rq1 = rq1_entries;
2335 pr_cfg.max_entries_rq2 = rq2_entries;
2336 pr_cfg.max_entries_rq3 = rq3_entries;
2337
2338 pr_cfg_small_rx.max_entries_rcq = 1;
2339 pr_cfg_small_rx.max_entries_scq = sq_entries;
2340 pr_cfg_small_rx.max_entries_sq = sq_entries;
2341 pr_cfg_small_rx.max_entries_rq1 = 1;
2342 pr_cfg_small_rx.max_entries_rq2 = 1;
2343 pr_cfg_small_rx.max_entries_rq3 = 1;
2344
2345 for (i = 0; i < def_qps; i++) {
2346 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2347 if (ret)
2348 goto out_clean_pr;
2349 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002350 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002351 ret = ehea_init_port_res(port, &port->port_res[i],
2352 &pr_cfg_small_rx, i);
2353 if (ret)
2354 goto out_clean_pr;
2355 }
2356
2357 return 0;
2358
2359out_clean_pr:
2360 while (--i >= 0)
2361 ehea_clean_portres(port, &port->port_res[i]);
2362
2363out_kill_eq:
2364 ehea_destroy_eq(port->qp_eq);
2365 return ret;
2366}
2367
2368static int ehea_clean_all_portres(struct ehea_port *port)
2369{
2370 int ret = 0;
2371 int i;
2372
Anton Blanchard723f28e2011-10-14 05:31:01 +00002373 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002374 ret |= ehea_clean_portres(port, &port->port_res[i]);
2375
2376 ret |= ehea_destroy_eq(port->qp_eq);
2377
2378 return ret;
2379}
2380
Thomas Klein35cf2e22007-08-06 13:55:14 +02002381static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002382{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002383 if (adapter->active_ports)
2384 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002385
2386 ehea_rem_mr(&adapter->mr);
2387}
2388
Thomas Klein35cf2e22007-08-06 13:55:14 +02002389static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002390{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002391 if (adapter->active_ports)
2392 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002393
2394 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2395}
2396
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397static int ehea_up(struct net_device *dev)
2398{
2399 int ret, i;
2400 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401
2402 if (port->state == EHEA_PORT_UP)
2403 return 0;
2404
Anton Blanchard723f28e2011-10-14 05:31:01 +00002405 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002406 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002407 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002408 goto out;
2409 }
2410
2411 /* Set default QP for this port */
2412 ret = ehea_configure_port(port);
2413 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002414 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 goto out_clean_pr;
2416 }
2417
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002418 ret = ehea_reg_interrupts(dev);
2419 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002420 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002421 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002422 }
2423
Anton Blanchard723f28e2011-10-14 05:31:01 +00002424 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2426 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002427 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002428 goto out_free_irqs;
2429 }
2430 }
2431
Doug Maxey508d2b52008-01-31 20:20:49 -06002432 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002433 ret = ehea_fill_port_res(&port->port_res[i]);
2434 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002435 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436 goto out_free_irqs;
2437 }
2438 }
2439
Thomas Klein21eee2d2008-02-13 16:18:33 +01002440 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2441 if (ret) {
2442 ret = -EIO;
2443 goto out_free_irqs;
2444 }
2445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002446 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002447
2448 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002449 goto out;
2450
2451out_free_irqs:
2452 ehea_free_interrupts(dev);
2453
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454out_clean_pr:
2455 ehea_clean_all_portres(port);
2456out:
Thomas Klein44c82152007-07-11 16:32:00 +02002457 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002458 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002459
Thomas Klein21eee2d2008-02-13 16:18:33 +01002460 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002461 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002462
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002463 return ret;
2464}
2465
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002466static void port_napi_disable(struct ehea_port *port)
2467{
2468 int i;
2469
Anton Blanchard723f28e2011-10-14 05:31:01 +00002470 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002471 napi_disable(&port->port_res[i].napi);
2472}
2473
2474static void port_napi_enable(struct ehea_port *port)
2475{
2476 int i;
2477
Anton Blanchard723f28e2011-10-14 05:31:01 +00002478 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002479 napi_enable(&port->port_res[i].napi);
2480}
2481
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002482static int ehea_open(struct net_device *dev)
2483{
2484 int ret;
2485 struct ehea_port *port = netdev_priv(dev);
2486
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002487 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002488
Joe Perches8c4877a2010-12-13 10:05:14 -08002489 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002490
2491 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002492 if (!ret) {
2493 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002494 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002495 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002496
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002497 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002498 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002499
2500 return ret;
2501}
2502
2503static int ehea_down(struct net_device *dev)
2504{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002505 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002506 struct ehea_port *port = netdev_priv(dev);
2507
2508 if (port->state == EHEA_PORT_DOWN)
2509 return 0;
2510
2511 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002512 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2513
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002514 ehea_free_interrupts(dev);
2515
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002516 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002517
Thomas Klein21eee2d2008-02-13 16:18:33 +01002518 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002519
Thomas Klein44c82152007-07-11 16:32:00 +02002520 ret = ehea_clean_all_portres(port);
2521 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002522 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002523
Thomas Klein21eee2d2008-02-13 16:18:33 +01002524 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002525
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002526 return ret;
2527}
2528
2529static int ehea_stop(struct net_device *dev)
2530{
2531 int ret;
2532 struct ehea_port *port = netdev_priv(dev);
2533
Joe Perches8c4877a2010-12-13 10:05:14 -08002534 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002535
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002536 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002537 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002538 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002539 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002540 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002541 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002542 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002543 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002544 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002545 return ret;
2546}
2547
Andrew Morton22559c52008-04-18 13:50:39 -07002548static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002549{
2550 struct ehea_qp qp = *orig_qp;
2551 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2552 struct ehea_swqe *swqe;
2553 int wqe_index;
2554 int i;
2555
2556 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2557 swqe = ehea_get_swqe(&qp, &wqe_index);
2558 swqe->tx_control |= EHEA_SWQE_PURGE;
2559 }
2560}
2561
Andrew Morton22559c52008-04-18 13:50:39 -07002562static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002563{
2564 int i;
2565
Anton Blanchard723f28e2011-10-14 05:31:01 +00002566 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002567 struct ehea_port_res *pr = &port->port_res[i];
2568 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002569 int ret;
2570
2571 ret = wait_event_timeout(port->swqe_avail_wq,
2572 atomic_read(&pr->swqe_avail) >= swqe_max,
2573 msecs_to_jiffies(100));
2574
2575 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002576 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002577 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002578 }
2579 }
2580}
2581
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002582int ehea_stop_qps(struct net_device *dev)
2583{
2584 struct ehea_port *port = netdev_priv(dev);
2585 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002586 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002587 int ret = -EIO;
2588 int dret;
2589 int i;
2590 u64 hret;
2591 u64 dummy64 = 0;
2592 u16 dummy16 = 0;
2593
Thomas Klein3faf2692009-01-21 14:45:33 -08002594 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002595 if (!cb0) {
2596 ret = -ENOMEM;
2597 goto out;
2598 }
2599
Anton Blanchard723f28e2011-10-14 05:31:01 +00002600 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002601 struct ehea_port_res *pr = &port->port_res[i];
2602 struct ehea_qp *qp = pr->qp;
2603
2604 /* Purge send queue */
2605 ehea_purge_sq(qp);
2606
2607 /* Disable queue pair */
2608 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2609 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2610 cb0);
2611 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002612 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002613 goto out;
2614 }
2615
2616 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2617 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2618
2619 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2620 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2621 1), cb0, &dummy64,
2622 &dummy64, &dummy16, &dummy16);
2623 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002624 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002625 goto out;
2626 }
2627
2628 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2629 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2630 cb0);
2631 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002632 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002633 goto out;
2634 }
2635
2636 /* deregister shared memory regions */
2637 dret = ehea_rem_smrs(pr);
2638 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002639 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002640 goto out;
2641 }
2642 }
2643
2644 ret = 0;
2645out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002646 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002647
2648 return ret;
2649}
2650
Doug Maxey508d2b52008-01-31 20:20:49 -06002651void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002652{
2653 struct ehea_qp qp = *orig_qp;
2654 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2655 struct ehea_rwqe *rwqe;
2656 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2657 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2658 struct sk_buff *skb;
2659 u32 lkey = pr->recv_mr.lkey;
2660
2661
2662 int i;
2663 int index;
2664
2665 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2666 rwqe = ehea_get_next_rwqe(&qp, 2);
2667 rwqe->sg_list[0].l_key = lkey;
2668 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2669 skb = skba_rq2[index];
2670 if (skb)
2671 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2672 }
2673
2674 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2675 rwqe = ehea_get_next_rwqe(&qp, 3);
2676 rwqe->sg_list[0].l_key = lkey;
2677 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2678 skb = skba_rq3[index];
2679 if (skb)
2680 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2681 }
2682}
2683
2684int ehea_restart_qps(struct net_device *dev)
2685{
2686 struct ehea_port *port = netdev_priv(dev);
2687 struct ehea_adapter *adapter = port->adapter;
2688 int ret = 0;
2689 int i;
2690
Doug Maxey508d2b52008-01-31 20:20:49 -06002691 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002692 u64 hret;
2693 u64 dummy64 = 0;
2694 u16 dummy16 = 0;
2695
Thomas Klein3faf2692009-01-21 14:45:33 -08002696 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002697 if (!cb0) {
2698 ret = -ENOMEM;
2699 goto out;
2700 }
2701
Anton Blanchard723f28e2011-10-14 05:31:01 +00002702 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002703 struct ehea_port_res *pr = &port->port_res[i];
2704 struct ehea_qp *qp = pr->qp;
2705
2706 ret = ehea_gen_smrs(pr);
2707 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002708 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002709 goto out;
2710 }
2711
2712 ehea_update_rqs(qp, pr);
2713
2714 /* Enable queue pair */
2715 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2716 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2717 cb0);
2718 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002719 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002720 goto out;
2721 }
2722
2723 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2724 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2725
2726 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2727 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2728 1), cb0, &dummy64,
2729 &dummy64, &dummy16, &dummy16);
2730 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002731 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002732 goto out;
2733 }
2734
2735 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2736 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2737 cb0);
2738 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002739 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002740 goto out;
2741 }
2742
2743 /* refill entire queue */
2744 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2745 ehea_refill_rq2(pr, 0);
2746 ehea_refill_rq3(pr, 0);
2747 }
2748out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002749 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002750
2751 return ret;
2752}
2753
David Howellsc4028952006-11-22 14:57:56 +00002754static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002755{
2756 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002757 struct ehea_port *port =
2758 container_of(work, struct ehea_port, reset_task);
2759 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002760
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002761 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002762 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002763 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002764 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002765
2766 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002767
Thomas Klein44c82152007-07-11 16:32:00 +02002768 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002769
2770 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002771 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002772 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002773
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002774 ehea_set_multicast_list(dev);
2775
Joe Perches8c4877a2010-12-13 10:05:14 -08002776 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002777
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002778 port_napi_enable(port);
2779
Anton Blanchardb9564462011-10-14 05:30:59 +00002780 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002781out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002782 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002783 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002784}
2785
Tejun Heo3d6b8922010-12-12 16:45:14 +01002786static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002787{
2788 int ret, i;
2789 struct ehea_adapter *adapter;
2790
Joe Perches8c4877a2010-12-13 10:05:14 -08002791 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002792
2793 list_for_each_entry(adapter, &adapter_list, list)
2794 if (adapter->active_ports) {
2795 /* Shutdown all ports */
2796 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2797 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002798 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002799
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002800 if (!port)
2801 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002802
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002803 dev = port->netdev;
2804
2805 if (dev->flags & IFF_UP) {
2806 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002807 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002808 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002809 ret = ehea_stop_qps(dev);
2810 if (ret) {
2811 mutex_unlock(&port->port_lock);
2812 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002813 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002814 port_napi_disable(port);
2815 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002816 }
Andre Detsch2928db42010-08-17 05:49:12 +00002817 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002818 }
2819
2820 /* Unregister old memory region */
2821 ret = ehea_rem_mr(&adapter->mr);
2822 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002823 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002824 goto out;
2825 }
2826 }
2827
Thomas Klein44c82152007-07-11 16:32:00 +02002828 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2829
2830 list_for_each_entry(adapter, &adapter_list, list)
2831 if (adapter->active_ports) {
2832 /* Register new memory region */
2833 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2834 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002835 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002836 goto out;
2837 }
2838
2839 /* Restart all ports */
2840 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2841 struct ehea_port *port = adapter->port[i];
2842
2843 if (port) {
2844 struct net_device *dev = port->netdev;
2845
2846 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002847 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002848 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002849 if (!ret) {
2850 check_sqs(port);
2851 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002852 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002853 } else {
2854 netdev_err(dev, "Unable to restart QPS\n");
2855 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002856 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002857 }
2858 }
2859 }
2860 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002861 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002862out:
2863 return;
2864}
2865
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002866static void ehea_tx_watchdog(struct net_device *dev)
2867{
2868 struct ehea_port *port = netdev_priv(dev);
2869
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002870 if (netif_carrier_ok(dev) &&
2871 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002872 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002873}
2874
2875int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2876{
2877 struct hcp_query_ehea *cb;
2878 u64 hret;
2879 int ret;
2880
Thomas Klein3faf2692009-01-21 14:45:33 -08002881 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002882 if (!cb) {
2883 ret = -ENOMEM;
2884 goto out;
2885 }
2886
2887 hret = ehea_h_query_ehea(adapter->handle, cb);
2888
2889 if (hret != H_SUCCESS) {
2890 ret = -EIO;
2891 goto out_herr;
2892 }
2893
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002894 adapter->max_mc_mac = cb->max_mc_mac - 1;
2895 ret = 0;
2896
2897out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002898 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002899out:
2900 return ret;
2901}
2902
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002903int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2904{
2905 struct hcp_ehea_port_cb4 *cb4;
2906 u64 hret;
2907 int ret = 0;
2908
2909 *jumbo = 0;
2910
2911 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002912 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002913 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002914 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002915 ret = -ENOMEM;
2916 goto out;
2917 } else {
2918 hret = ehea_h_query_ehea_port(port->adapter->handle,
2919 port->logical_port_id,
2920 H_PORT_CB4,
2921 H_PORT_CB4_JUMBO, cb4);
2922 if (hret == H_SUCCESS) {
2923 if (cb4->jumbo_frame)
2924 *jumbo = 1;
2925 else {
2926 cb4->jumbo_frame = 1;
2927 hret = ehea_h_modify_ehea_port(port->adapter->
2928 handle,
2929 port->
2930 logical_port_id,
2931 H_PORT_CB4,
2932 H_PORT_CB4_JUMBO,
2933 cb4);
2934 if (hret == H_SUCCESS)
2935 *jumbo = 1;
2936 }
2937 } else
2938 ret = -EINVAL;
2939
Thomas Klein3faf2692009-01-21 14:45:33 -08002940 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002941 }
2942out:
2943 return ret;
2944}
2945
2946static ssize_t ehea_show_port_id(struct device *dev,
2947 struct device_attribute *attr, char *buf)
2948{
2949 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002950 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002951}
2952
2953static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2954 NULL);
2955
2956static void __devinit logical_port_release(struct device *dev)
2957{
2958 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002959 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002960}
2961
2962static struct device *ehea_register_port(struct ehea_port *port,
2963 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964{
2965 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002966
Grant Likely61c7a082010-04-13 16:12:29 -07002967 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002968 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002969 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002970
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002971 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002972 port->ofdev.dev.release = logical_port_release;
2973
2974 ret = of_device_register(&port->ofdev);
2975 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002976 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002977 goto out;
2978 }
2979
2980 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002981 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002982 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983 goto out_unreg_of_dev;
2984 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002985
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002986 return &port->ofdev.dev;
2987
2988out_unreg_of_dev:
2989 of_device_unregister(&port->ofdev);
2990out:
2991 return NULL;
2992}
2993
2994static void ehea_unregister_port(struct ehea_port *port)
2995{
2996 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2997 of_device_unregister(&port->ofdev);
2998}
2999
Thomas Klein086c1b22009-01-21 14:43:59 -08003000static const struct net_device_ops ehea_netdev_ops = {
3001 .ndo_open = ehea_open,
3002 .ndo_stop = ehea_stop,
3003 .ndo_start_xmit = ehea_start_xmit,
3004#ifdef CONFIG_NET_POLL_CONTROLLER
3005 .ndo_poll_controller = ehea_netpoll,
3006#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00003007 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08003008 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003009 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003010 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003011 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003012 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003013 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3014 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003015};
3016
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003017struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3018 u32 logical_port_id,
3019 struct device_node *dn)
3020{
3021 int ret;
3022 struct net_device *dev;
3023 struct ehea_port *port;
3024 struct device *port_dev;
3025 int jumbo;
3026
3027 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00003028 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003029
3030 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003031 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003032 ret = -ENOMEM;
3033 goto out_err;
3034 }
3035
3036 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003037
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003038 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003039 port->state = EHEA_PORT_DOWN;
3040 port->sig_comp_iv = sq_entries / 10;
3041
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003042 port->adapter = adapter;
3043 port->netdev = dev;
3044 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003046 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003047
3048 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3049 if (!port->mc_list) {
3050 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003052 }
3053
3054 INIT_LIST_HEAD(&port->mc_list->list);
3055
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003056 ret = ehea_sense_port_attr(port);
3057 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003058 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003059
Anton Blanchardb9564462011-10-14 05:30:59 +00003060 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003061 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003062
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003063 port_dev = ehea_register_port(port, dn);
3064 if (!port_dev)
3065 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003066
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003067 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068
3069 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003070 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3071
Thomas Klein086c1b22009-01-21 14:43:59 -08003072 dev->netdev_ops = &ehea_netdev_ops;
3073 ehea_set_ethtool_ops(dev);
3074
Anton Blanchardd695c332011-10-14 05:31:05 +00003075 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Michał Mirosławf4786a92011-04-17 00:15:47 +00003076 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003077 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003078 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003079 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003080 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003081 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3082 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003083 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3084
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003085 if (use_lro)
3086 dev->features |= NETIF_F_LRO;
3087
David Howellsc4028952006-11-22 14:57:56 +00003088 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003089 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003090
Anton Blanchard21ccc792011-05-10 16:17:10 +00003091 init_waitqueue_head(&port->swqe_avail_wq);
3092 init_waitqueue_head(&port->restart_wq);
3093
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003094 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003095 ret = register_netdev(dev);
3096 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003097 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003098 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099 }
3100
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003101 port->lro_max_aggr = lro_max_aggr;
3102
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003104 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003105 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003106
Joe Perches8c4877a2010-12-13 10:05:14 -08003107 netdev_info(dev, "Jumbo frames are %sabled\n",
3108 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003109
Thomas Klein44c82152007-07-11 16:32:00 +02003110 adapter->active_ports++;
3111
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003113
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114out_unreg_port:
3115 ehea_unregister_port(port);
3116
3117out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003118 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003119
3120out_free_ethdev:
3121 free_netdev(dev);
3122
3123out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003124 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3125 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 return NULL;
3127}
3128
3129static void ehea_shutdown_single_port(struct ehea_port *port)
3130{
Brian King7fb1c2a2008-05-14 09:48:25 -05003131 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003132
3133 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003134 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003135 unregister_netdev(port->netdev);
3136 ehea_unregister_port(port);
3137 kfree(port->mc_list);
3138 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003139 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003140}
3141
3142static int ehea_setup_ports(struct ehea_adapter *adapter)
3143{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144 struct device_node *lhea_dn;
3145 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003146
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003147 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003148 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003149
Grant Likely61c7a082010-04-13 16:12:29 -07003150 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003151 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003152
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003153 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003154 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003155 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003156 pr_err("bad device node: eth_dn name=%s\n",
3157 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003158 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159 }
3160
Thomas Klein1211bb62007-04-26 11:56:43 +02003161 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003162 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003163 of_node_put(eth_dn);
3164 return -EIO;
3165 }
3166
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003167 adapter->port[i] = ehea_setup_single_port(adapter,
3168 *dn_log_port_id,
3169 eth_dn);
3170 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003171 netdev_info(adapter->port[i]->netdev,
3172 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003173 else
3174 ehea_remove_adapter_mr(adapter);
3175
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003177 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003178 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003179}
3180
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003181static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3182 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183{
3184 struct device_node *lhea_dn;
3185 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003186 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003187
Grant Likely61c7a082010-04-13 16:12:29 -07003188 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003189 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003190
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003191 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003192 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003193 if (dn_log_port_id)
3194 if (*dn_log_port_id == logical_port_id)
3195 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003196 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003197
3198 return NULL;
3199}
3200
3201static ssize_t ehea_probe_port(struct device *dev,
3202 struct device_attribute *attr,
3203 const char *buf, size_t count)
3204{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003205 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206 struct ehea_port *port;
3207 struct device_node *eth_dn = NULL;
3208 int i;
3209
3210 u32 logical_port_id;
3211
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003212 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213
3214 port = ehea_get_port(adapter, logical_port_id);
3215
3216 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003217 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3218 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 return -EINVAL;
3220 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003221
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003222 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3223
3224 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003225 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226 return -EINVAL;
3227 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003228
Thomas Klein1211bb62007-04-26 11:56:43 +02003229 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003230 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003231 return -EIO;
3232 }
3233
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003234 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3235
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003236 of_node_put(eth_dn);
3237
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003238 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003239 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 if (!adapter->port[i]) {
3241 adapter->port[i] = port;
3242 break;
3243 }
3244
Joe Perches8c4877a2010-12-13 10:05:14 -08003245 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3246 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003247 } else {
3248 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003249 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003250 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251
3252 return (ssize_t) count;
3253}
3254
3255static ssize_t ehea_remove_port(struct device *dev,
3256 struct device_attribute *attr,
3257 const char *buf, size_t count)
3258{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003259 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260 struct ehea_port *port;
3261 int i;
3262 u32 logical_port_id;
3263
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003264 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003265
3266 port = ehea_get_port(adapter, logical_port_id);
3267
3268 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003269 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3270 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003271
3272 ehea_shutdown_single_port(port);
3273
Doug Maxey508d2b52008-01-31 20:20:49 -06003274 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003275 if (adapter->port[i] == port) {
3276 adapter->port[i] = NULL;
3277 break;
3278 }
3279 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003280 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3281 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003282 return -EINVAL;
3283 }
3284
Thomas Klein1211bb62007-04-26 11:56:43 +02003285 ehea_remove_adapter_mr(adapter);
3286
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 return (ssize_t) count;
3288}
3289
3290static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3291static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3292
Grant Likely2dc11582010-08-06 09:25:50 -06003293int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003294{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003295 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003296 if (ret)
3297 goto out;
3298
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003299 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003301 return ret;
3302}
3303
Grant Likely2dc11582010-08-06 09:25:50 -06003304void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003305{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003306 device_remove_file(&dev->dev, &dev_attr_probe_port);
3307 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003308}
3309
Grant Likely2dc11582010-08-06 09:25:50 -06003310static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003311 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003312{
3313 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003314 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003315 int ret;
3316
Grant Likely61c7a082010-04-13 16:12:29 -07003317 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003318 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003319 return -EINVAL;
3320 }
3321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003322 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3323 if (!adapter) {
3324 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003325 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003326 goto out;
3327 }
3328
Thomas Klein44c82152007-07-11 16:32:00 +02003329 list_add(&adapter->list, &adapter_list);
3330
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003331 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003332
Grant Likely61c7a082010-04-13 16:12:29 -07003333 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003334 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003335 if (adapter_handle)
3336 adapter->handle = *adapter_handle;
3337
3338 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003339 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003340 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003341 ret = -ENODEV;
3342 goto out_free_ad;
3343 }
3344
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003345 adapter->pd = EHEA_PD_ID;
3346
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003347 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003349
3350 /* initialize adapter and ports */
3351 /* get adapter properties */
3352 ret = ehea_sense_adapter_attr(adapter);
3353 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003354 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003355 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003356 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003357
3358 adapter->neq = ehea_create_eq(adapter,
3359 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3360 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003361 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003362 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003363 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003364 }
3365
3366 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3367 (unsigned long)adapter);
3368
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003369 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003370 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371 "ehea_neq", adapter);
3372 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003373 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003374 goto out_kill_eq;
3375 }
3376
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003377 ret = ehea_create_device_sysfs(dev);
3378 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003379 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003381 ret = ehea_setup_ports(adapter);
3382 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003383 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003384 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003385 }
3386
3387 ret = 0;
3388 goto out;
3389
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003390out_rem_dev_sysfs:
3391 ehea_remove_device_sysfs(dev);
3392
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003393out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003394 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003395
3396out_kill_eq:
3397 ehea_destroy_eq(adapter->neq);
3398
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003399out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003400 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003401 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003402
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003403out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003404 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003405
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406 return ret;
3407}
3408
Grant Likely2dc11582010-08-06 09:25:50 -06003409static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003410{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003411 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003412 int i;
3413
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003414 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003415 if (adapter->port[i]) {
3416 ehea_shutdown_single_port(adapter->port[i]);
3417 adapter->port[i] = NULL;
3418 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003419
3420 ehea_remove_device_sysfs(dev);
3421
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003422 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003423 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003424
3425 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003426 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003427 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003428 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003429
Thomas Klein21eee2d2008-02-13 16:18:33 +01003430 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003431
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003432 return 0;
3433}
3434
Thomas Klein21eee2d2008-02-13 16:18:33 +01003435void ehea_crash_handler(void)
3436{
3437 int i;
3438
3439 if (ehea_fw_handles.arr)
3440 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3441 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3442 ehea_fw_handles.arr[i].fwh,
3443 FORCE_FREE);
3444
3445 if (ehea_bcmc_regs.arr)
3446 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3447 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3448 ehea_bcmc_regs.arr[i].port_id,
3449 ehea_bcmc_regs.arr[i].reg_type,
3450 ehea_bcmc_regs.arr[i].macaddr,
3451 0, H_DEREG_BCMC);
3452}
3453
Hannes Hering48cfb142008-05-07 14:43:36 +02003454static int ehea_mem_notifier(struct notifier_block *nb,
3455 unsigned long action, void *data)
3456{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003457 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003458 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003459
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003460 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003461
Hannes Hering48cfb142008-05-07 14:43:36 +02003462 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003463 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003464 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003465 /* Readd canceled memory block */
3466 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003467 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003468 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003469 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003470 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003471 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003472 break;
3473 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003474 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003475 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003476 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003477 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003478 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003479 break;
3480 default:
3481 break;
3482 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003483
3484 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003485 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003486
Thomas Kleina7c561f22010-04-20 23:11:31 +00003487out_unlock:
3488 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003489 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003490}
3491
3492static struct notifier_block ehea_mem_nb = {
3493 .notifier_call = ehea_mem_notifier,
3494};
3495
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003496static int ehea_reboot_notifier(struct notifier_block *nb,
3497 unsigned long action, void *unused)
3498{
3499 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003500 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003501 ibmebus_unregister_driver(&ehea_driver);
3502 }
3503 return NOTIFY_DONE;
3504}
3505
3506static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003507 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003508};
3509
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510static int check_module_parm(void)
3511{
3512 int ret = 0;
3513
3514 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3515 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003516 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 ret = -EINVAL;
3518 }
3519 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3520 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003521 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003522 ret = -EINVAL;
3523 }
3524 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3525 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003526 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 ret = -EINVAL;
3528 }
3529 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3530 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003531 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 ret = -EINVAL;
3533 }
3534
3535 return ret;
3536}
3537
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003538static ssize_t ehea_show_capabilities(struct device_driver *drv,
3539 char *buf)
3540{
3541 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3542}
3543
3544static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3545 ehea_show_capabilities, NULL);
3546
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547int __init ehea_module_init(void)
3548{
3549 int ret;
3550
Joe Perches8c4877a2010-12-13 10:05:14 -08003551 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003552
Thomas Klein21eee2d2008-02-13 16:18:33 +01003553 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3554 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3555
Daniel Walker9f71a562008-03-28 14:41:26 -07003556 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003557 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003558
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003559 ret = check_module_parm();
3560 if (ret)
3561 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003562
3563 ret = ehea_create_busmap();
3564 if (ret)
3565 goto out;
3566
Thomas Klein21eee2d2008-02-13 16:18:33 +01003567 ret = register_reboot_notifier(&ehea_reboot_nb);
3568 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003569 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003570
Hannes Hering48cfb142008-05-07 14:43:36 +02003571 ret = register_memory_notifier(&ehea_mem_nb);
3572 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003573 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003574
Joe Perchesc061b182010-08-23 18:20:03 +00003575 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003576 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003577 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003578
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003579 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003580 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003581 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003582 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003583 }
3584
3585 ret = driver_create_file(&ehea_driver.driver,
3586 &driver_attr_capabilities);
3587 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003588 pr_err("failed to register capabilities attribute, ret=%d\n",
3589 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003590 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003591 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592
Thomas Klein21eee2d2008-02-13 16:18:33 +01003593 return ret;
3594
3595out3:
3596 ibmebus_unregister_driver(&ehea_driver);
3597out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003598 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003599 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003600 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003601out:
3602 return ret;
3603}
3604
3605static void __exit ehea_module_exit(void)
3606{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003607 int ret;
3608
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003609 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003610 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003611 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003612 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003613 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003614 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003615 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003616 kfree(ehea_fw_handles.arr);
3617 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003618 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003619}
3620
3621module_init(ehea_module_init);
3622module_exit(ehea_module_exit);