blob: 0fc0ae8b830fa62f4a1abc7ba10c6adcd0d96c52 [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
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200326static struct net_device_stats *ehea_get_stats(struct net_device *dev)
327{
328 struct ehea_port *port = netdev_priv(dev);
329 struct net_device_stats *stats = &port->stats;
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;
356 struct net_device_stats *stats = &port->stats;
357 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{
2090 int nfrags = skb_shinfo(skb)->nr_frags;
2091 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2092 skb_frag_t *frag;
2093 int i;
2094
Anton Blanchardd695c332011-10-14 05:31:05 +00002095 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002096
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002097 if (nfrags == 0) {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002098 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002100 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002101 skb_headlen(skb));
2102 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002103
2104 /* ... then copy data from the fragments */
2105 for (i = 0; i < nfrags; i++) {
2106 frag = &skb_shinfo(skb)->frags[i];
Ian Campbell618c4a02011-10-10 01:11:38 +00002107 memcpy(imm_data, skb_frag_address(frag), frag->size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 imm_data += frag->size;
2109 }
2110 }
Anton Blanchardd695c332011-10-14 05:31:05 +00002111
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112 swqe->immediate_data_length = skb->len;
2113 dev_kfree_skb(skb);
2114}
2115
2116static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2117{
2118 struct ehea_port *port = netdev_priv(dev);
2119 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120 u32 lkey;
2121 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002122 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002123 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002124
Anton Blanchardb9564462011-10-14 05:30:59 +00002125 pr = &port->port_res[skb_get_queue_mapping(skb)];
2126 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002127
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2129 memset(swqe, 0, SWQE_HEADER_SIZE);
2130 atomic_dec(&pr->swqe_avail);
2131
Eric Dumazete5ccd962010-10-26 19:21:07 +00002132 if (vlan_tx_tag_present(skb)) {
2133 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2134 swqe->vlan_tag = vlan_tx_tag_get(skb);
2135 }
2136
Breno Leitaoce45b872010-10-27 08:45:14 +00002137 pr->tx_packets++;
2138 pr->tx_bytes += skb->len;
2139
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002140 if (skb->len <= SWQE3_MAX_IMM) {
2141 u32 sig_iv = port->sig_comp_iv;
2142 u32 swqe_num = pr->swqe_id_counter;
2143 ehea_xmit3(skb, dev, swqe);
2144 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2145 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2146 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2147 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2148 sig_iv);
2149 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2150 pr->swqe_ll_count = 0;
2151 } else
2152 pr->swqe_ll_count += 1;
2153 } else {
2154 swqe->wr_id =
2155 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2156 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002157 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2159 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2160
2161 pr->sq_skba.index++;
2162 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2163
2164 lkey = pr->send_mr.lkey;
2165 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002166 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002167 }
2168 pr->swqe_id_counter += 1;
2169
Joe Perches8c4877a2010-12-13 10:05:14 -08002170 netif_info(port, tx_queued, dev,
2171 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2172 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002173 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002175 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002176 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002177 swqe->tx_control |= EHEA_SWQE_PURGE;
2178 }
Thomas Klein44c82152007-07-11 16:32:00 +02002179
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002181
2182 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002183 pr->p_stats.queue_stopped++;
2184 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002185 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002186
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002187 return NETDEV_TX_OK;
2188}
2189
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002190static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2191{
2192 struct ehea_port *port = netdev_priv(dev);
2193 struct ehea_adapter *adapter = port->adapter;
2194 struct hcp_ehea_port_cb1 *cb1;
2195 int index;
2196 u64 hret;
2197
Thomas Klein3faf2692009-01-21 14:45:33 -08002198 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002199 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002200 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002201 goto out;
2202 }
2203
2204 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2205 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2206 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002207 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208 goto out;
2209 }
2210
2211 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002212 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002213
2214 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2215 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2216 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002217 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002218out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002219 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002220 return;
2221}
2222
2223static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2224{
2225 struct ehea_port *port = netdev_priv(dev);
2226 struct ehea_adapter *adapter = port->adapter;
2227 struct hcp_ehea_port_cb1 *cb1;
2228 int index;
2229 u64 hret;
2230
Thomas Klein3faf2692009-01-21 14:45:33 -08002231 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002232 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002233 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002234 goto out;
2235 }
2236
2237 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2238 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2239 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002240 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002241 goto out;
2242 }
2243
2244 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002245 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002246
2247 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2248 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2249 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002250 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002252 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002253}
2254
2255int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2256{
2257 int ret = -EIO;
2258 u64 hret;
2259 u16 dummy16 = 0;
2260 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002261 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002262
Thomas Klein3faf2692009-01-21 14:45:33 -08002263 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002264 if (!cb0) {
2265 ret = -ENOMEM;
2266 goto out;
2267 }
2268
2269 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2270 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2271 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002272 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273 goto out;
2274 }
2275
2276 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2277 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2278 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2279 &dummy64, &dummy64, &dummy16, &dummy16);
2280 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002281 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002282 goto out;
2283 }
2284
2285 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2286 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2287 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002288 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002289 goto out;
2290 }
2291
2292 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2293 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2294 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2295 &dummy64, &dummy64, &dummy16, &dummy16);
2296 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002297 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 goto out;
2299 }
2300
2301 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2302 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2303 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002304 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002305 goto out;
2306 }
2307
2308 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2309 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2310 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2311 &dummy64, &dummy64, &dummy16, &dummy16);
2312 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002313 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002314 goto out;
2315 }
2316
2317 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2318 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2319 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002320 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002321 goto out;
2322 }
2323
2324 ret = 0;
2325out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002326 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002327 return ret;
2328}
2329
Anton Blanchard723f28e2011-10-14 05:31:01 +00002330static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331{
2332 int ret, i;
2333 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2334 enum ehea_eq_type eq_type = EHEA_EQ;
2335
2336 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2337 EHEA_MAX_ENTRIES_EQ, 1);
2338 if (!port->qp_eq) {
2339 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002340 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002341 goto out_kill_eq;
2342 }
2343
2344 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002345 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002346 pr_cfg.max_entries_sq = sq_entries;
2347 pr_cfg.max_entries_rq1 = rq1_entries;
2348 pr_cfg.max_entries_rq2 = rq2_entries;
2349 pr_cfg.max_entries_rq3 = rq3_entries;
2350
2351 pr_cfg_small_rx.max_entries_rcq = 1;
2352 pr_cfg_small_rx.max_entries_scq = sq_entries;
2353 pr_cfg_small_rx.max_entries_sq = sq_entries;
2354 pr_cfg_small_rx.max_entries_rq1 = 1;
2355 pr_cfg_small_rx.max_entries_rq2 = 1;
2356 pr_cfg_small_rx.max_entries_rq3 = 1;
2357
2358 for (i = 0; i < def_qps; i++) {
2359 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2360 if (ret)
2361 goto out_clean_pr;
2362 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002363 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364 ret = ehea_init_port_res(port, &port->port_res[i],
2365 &pr_cfg_small_rx, i);
2366 if (ret)
2367 goto out_clean_pr;
2368 }
2369
2370 return 0;
2371
2372out_clean_pr:
2373 while (--i >= 0)
2374 ehea_clean_portres(port, &port->port_res[i]);
2375
2376out_kill_eq:
2377 ehea_destroy_eq(port->qp_eq);
2378 return ret;
2379}
2380
2381static int ehea_clean_all_portres(struct ehea_port *port)
2382{
2383 int ret = 0;
2384 int i;
2385
Anton Blanchard723f28e2011-10-14 05:31:01 +00002386 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 ret |= ehea_clean_portres(port, &port->port_res[i]);
2388
2389 ret |= ehea_destroy_eq(port->qp_eq);
2390
2391 return ret;
2392}
2393
Thomas Klein35cf2e22007-08-06 13:55:14 +02002394static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002395{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002396 if (adapter->active_ports)
2397 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002398
2399 ehea_rem_mr(&adapter->mr);
2400}
2401
Thomas Klein35cf2e22007-08-06 13:55:14 +02002402static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002403{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002404 if (adapter->active_ports)
2405 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002406
2407 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2408}
2409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002410static int ehea_up(struct net_device *dev)
2411{
2412 int ret, i;
2413 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414
2415 if (port->state == EHEA_PORT_UP)
2416 return 0;
2417
Anton Blanchard723f28e2011-10-14 05:31:01 +00002418 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002419 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002420 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002421 goto out;
2422 }
2423
2424 /* Set default QP for this port */
2425 ret = ehea_configure_port(port);
2426 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002427 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002428 goto out_clean_pr;
2429 }
2430
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002431 ret = ehea_reg_interrupts(dev);
2432 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002433 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002434 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002435 }
2436
Anton Blanchard723f28e2011-10-14 05:31:01 +00002437 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002438 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2439 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002440 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441 goto out_free_irqs;
2442 }
2443 }
2444
Doug Maxey508d2b52008-01-31 20:20:49 -06002445 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002446 ret = ehea_fill_port_res(&port->port_res[i]);
2447 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002448 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002449 goto out_free_irqs;
2450 }
2451 }
2452
Thomas Klein21eee2d2008-02-13 16:18:33 +01002453 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2454 if (ret) {
2455 ret = -EIO;
2456 goto out_free_irqs;
2457 }
2458
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002459 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002460
2461 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 goto out;
2463
2464out_free_irqs:
2465 ehea_free_interrupts(dev);
2466
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002467out_clean_pr:
2468 ehea_clean_all_portres(port);
2469out:
Thomas Klein44c82152007-07-11 16:32:00 +02002470 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002471 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002472
Thomas Klein21eee2d2008-02-13 16:18:33 +01002473 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002474 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002475
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002476 return ret;
2477}
2478
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002479static void port_napi_disable(struct ehea_port *port)
2480{
2481 int i;
2482
Anton Blanchard723f28e2011-10-14 05:31:01 +00002483 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002484 napi_disable(&port->port_res[i].napi);
2485}
2486
2487static void port_napi_enable(struct ehea_port *port)
2488{
2489 int i;
2490
Anton Blanchard723f28e2011-10-14 05:31:01 +00002491 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002492 napi_enable(&port->port_res[i].napi);
2493}
2494
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002495static int ehea_open(struct net_device *dev)
2496{
2497 int ret;
2498 struct ehea_port *port = netdev_priv(dev);
2499
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002500 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501
Joe Perches8c4877a2010-12-13 10:05:14 -08002502 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002503
2504 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002505 if (!ret) {
2506 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002507 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002508 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002509
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002510 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002511 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002512
2513 return ret;
2514}
2515
2516static int ehea_down(struct net_device *dev)
2517{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002518 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002519 struct ehea_port *port = netdev_priv(dev);
2520
2521 if (port->state == EHEA_PORT_DOWN)
2522 return 0;
2523
2524 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002525 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002527 ehea_free_interrupts(dev);
2528
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002530
Thomas Klein21eee2d2008-02-13 16:18:33 +01002531 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002532
Thomas Klein44c82152007-07-11 16:32:00 +02002533 ret = ehea_clean_all_portres(port);
2534 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002535 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002536
Thomas Klein21eee2d2008-02-13 16:18:33 +01002537 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002539 return ret;
2540}
2541
2542static int ehea_stop(struct net_device *dev)
2543{
2544 int ret;
2545 struct ehea_port *port = netdev_priv(dev);
2546
Joe Perches8c4877a2010-12-13 10:05:14 -08002547 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002548
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002549 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002550 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002551 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002552 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002553 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002554 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002555 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002556 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002557 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558 return ret;
2559}
2560
Andrew Morton22559c52008-04-18 13:50:39 -07002561static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002562{
2563 struct ehea_qp qp = *orig_qp;
2564 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2565 struct ehea_swqe *swqe;
2566 int wqe_index;
2567 int i;
2568
2569 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2570 swqe = ehea_get_swqe(&qp, &wqe_index);
2571 swqe->tx_control |= EHEA_SWQE_PURGE;
2572 }
2573}
2574
Andrew Morton22559c52008-04-18 13:50:39 -07002575static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002576{
2577 int i;
2578
Anton Blanchard723f28e2011-10-14 05:31:01 +00002579 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002580 struct ehea_port_res *pr = &port->port_res[i];
2581 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002582 int ret;
2583
2584 ret = wait_event_timeout(port->swqe_avail_wq,
2585 atomic_read(&pr->swqe_avail) >= swqe_max,
2586 msecs_to_jiffies(100));
2587
2588 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002589 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002590 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002591 }
2592 }
2593}
2594
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002595int ehea_stop_qps(struct net_device *dev)
2596{
2597 struct ehea_port *port = netdev_priv(dev);
2598 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002599 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002600 int ret = -EIO;
2601 int dret;
2602 int i;
2603 u64 hret;
2604 u64 dummy64 = 0;
2605 u16 dummy16 = 0;
2606
Thomas Klein3faf2692009-01-21 14:45:33 -08002607 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002608 if (!cb0) {
2609 ret = -ENOMEM;
2610 goto out;
2611 }
2612
Anton Blanchard723f28e2011-10-14 05:31:01 +00002613 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002614 struct ehea_port_res *pr = &port->port_res[i];
2615 struct ehea_qp *qp = pr->qp;
2616
2617 /* Purge send queue */
2618 ehea_purge_sq(qp);
2619
2620 /* Disable queue pair */
2621 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2622 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2623 cb0);
2624 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002625 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002626 goto out;
2627 }
2628
2629 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2630 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2631
2632 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2633 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2634 1), cb0, &dummy64,
2635 &dummy64, &dummy16, &dummy16);
2636 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002637 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002638 goto out;
2639 }
2640
2641 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2642 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2643 cb0);
2644 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002645 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002646 goto out;
2647 }
2648
2649 /* deregister shared memory regions */
2650 dret = ehea_rem_smrs(pr);
2651 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002652 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002653 goto out;
2654 }
2655 }
2656
2657 ret = 0;
2658out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002659 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002660
2661 return ret;
2662}
2663
Doug Maxey508d2b52008-01-31 20:20:49 -06002664void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002665{
2666 struct ehea_qp qp = *orig_qp;
2667 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2668 struct ehea_rwqe *rwqe;
2669 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2670 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2671 struct sk_buff *skb;
2672 u32 lkey = pr->recv_mr.lkey;
2673
2674
2675 int i;
2676 int index;
2677
2678 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2679 rwqe = ehea_get_next_rwqe(&qp, 2);
2680 rwqe->sg_list[0].l_key = lkey;
2681 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2682 skb = skba_rq2[index];
2683 if (skb)
2684 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2685 }
2686
2687 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2688 rwqe = ehea_get_next_rwqe(&qp, 3);
2689 rwqe->sg_list[0].l_key = lkey;
2690 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2691 skb = skba_rq3[index];
2692 if (skb)
2693 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2694 }
2695}
2696
2697int ehea_restart_qps(struct net_device *dev)
2698{
2699 struct ehea_port *port = netdev_priv(dev);
2700 struct ehea_adapter *adapter = port->adapter;
2701 int ret = 0;
2702 int i;
2703
Doug Maxey508d2b52008-01-31 20:20:49 -06002704 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002705 u64 hret;
2706 u64 dummy64 = 0;
2707 u16 dummy16 = 0;
2708
Thomas Klein3faf2692009-01-21 14:45:33 -08002709 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002710 if (!cb0) {
2711 ret = -ENOMEM;
2712 goto out;
2713 }
2714
Anton Blanchard723f28e2011-10-14 05:31:01 +00002715 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002716 struct ehea_port_res *pr = &port->port_res[i];
2717 struct ehea_qp *qp = pr->qp;
2718
2719 ret = ehea_gen_smrs(pr);
2720 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002721 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002722 goto out;
2723 }
2724
2725 ehea_update_rqs(qp, pr);
2726
2727 /* Enable queue pair */
2728 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2729 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2730 cb0);
2731 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002732 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002733 goto out;
2734 }
2735
2736 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2737 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2738
2739 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2740 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2741 1), cb0, &dummy64,
2742 &dummy64, &dummy16, &dummy16);
2743 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002744 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002745 goto out;
2746 }
2747
2748 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2749 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2750 cb0);
2751 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002752 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002753 goto out;
2754 }
2755
2756 /* refill entire queue */
2757 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2758 ehea_refill_rq2(pr, 0);
2759 ehea_refill_rq3(pr, 0);
2760 }
2761out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002762 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002763
2764 return ret;
2765}
2766
David Howellsc4028952006-11-22 14:57:56 +00002767static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002768{
2769 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002770 struct ehea_port *port =
2771 container_of(work, struct ehea_port, reset_task);
2772 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002773
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002774 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002775 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002776 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002777 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002778
2779 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002780
Thomas Klein44c82152007-07-11 16:32:00 +02002781 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002782
2783 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002784 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002785 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002786
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002787 ehea_set_multicast_list(dev);
2788
Joe Perches8c4877a2010-12-13 10:05:14 -08002789 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002790
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002791 port_napi_enable(port);
2792
Anton Blanchardb9564462011-10-14 05:30:59 +00002793 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002794out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002795 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002796 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002797}
2798
Tejun Heo3d6b8922010-12-12 16:45:14 +01002799static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002800{
2801 int ret, i;
2802 struct ehea_adapter *adapter;
2803
Joe Perches8c4877a2010-12-13 10:05:14 -08002804 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002805
2806 list_for_each_entry(adapter, &adapter_list, list)
2807 if (adapter->active_ports) {
2808 /* Shutdown all ports */
2809 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2810 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002811 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002812
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002813 if (!port)
2814 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002815
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002816 dev = port->netdev;
2817
2818 if (dev->flags & IFF_UP) {
2819 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002820 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002821 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002822 ret = ehea_stop_qps(dev);
2823 if (ret) {
2824 mutex_unlock(&port->port_lock);
2825 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002826 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002827 port_napi_disable(port);
2828 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002829 }
Andre Detsch2928db42010-08-17 05:49:12 +00002830 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002831 }
2832
2833 /* Unregister old memory region */
2834 ret = ehea_rem_mr(&adapter->mr);
2835 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002836 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002837 goto out;
2838 }
2839 }
2840
Thomas Klein44c82152007-07-11 16:32:00 +02002841 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2842
2843 list_for_each_entry(adapter, &adapter_list, list)
2844 if (adapter->active_ports) {
2845 /* Register new memory region */
2846 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2847 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002848 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002849 goto out;
2850 }
2851
2852 /* Restart all ports */
2853 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2854 struct ehea_port *port = adapter->port[i];
2855
2856 if (port) {
2857 struct net_device *dev = port->netdev;
2858
2859 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002860 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002861 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002862 if (!ret) {
2863 check_sqs(port);
2864 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002865 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002866 } else {
2867 netdev_err(dev, "Unable to restart QPS\n");
2868 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002869 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002870 }
2871 }
2872 }
2873 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002874 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002875out:
2876 return;
2877}
2878
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002879static void ehea_tx_watchdog(struct net_device *dev)
2880{
2881 struct ehea_port *port = netdev_priv(dev);
2882
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002883 if (netif_carrier_ok(dev) &&
2884 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002885 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002886}
2887
2888int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2889{
2890 struct hcp_query_ehea *cb;
2891 u64 hret;
2892 int ret;
2893
Thomas Klein3faf2692009-01-21 14:45:33 -08002894 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002895 if (!cb) {
2896 ret = -ENOMEM;
2897 goto out;
2898 }
2899
2900 hret = ehea_h_query_ehea(adapter->handle, cb);
2901
2902 if (hret != H_SUCCESS) {
2903 ret = -EIO;
2904 goto out_herr;
2905 }
2906
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002907 adapter->max_mc_mac = cb->max_mc_mac - 1;
2908 ret = 0;
2909
2910out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002911 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002912out:
2913 return ret;
2914}
2915
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002916int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2917{
2918 struct hcp_ehea_port_cb4 *cb4;
2919 u64 hret;
2920 int ret = 0;
2921
2922 *jumbo = 0;
2923
2924 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002925 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002926 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002927 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002928 ret = -ENOMEM;
2929 goto out;
2930 } else {
2931 hret = ehea_h_query_ehea_port(port->adapter->handle,
2932 port->logical_port_id,
2933 H_PORT_CB4,
2934 H_PORT_CB4_JUMBO, cb4);
2935 if (hret == H_SUCCESS) {
2936 if (cb4->jumbo_frame)
2937 *jumbo = 1;
2938 else {
2939 cb4->jumbo_frame = 1;
2940 hret = ehea_h_modify_ehea_port(port->adapter->
2941 handle,
2942 port->
2943 logical_port_id,
2944 H_PORT_CB4,
2945 H_PORT_CB4_JUMBO,
2946 cb4);
2947 if (hret == H_SUCCESS)
2948 *jumbo = 1;
2949 }
2950 } else
2951 ret = -EINVAL;
2952
Thomas Klein3faf2692009-01-21 14:45:33 -08002953 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002954 }
2955out:
2956 return ret;
2957}
2958
2959static ssize_t ehea_show_port_id(struct device *dev,
2960 struct device_attribute *attr, char *buf)
2961{
2962 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002963 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002964}
2965
2966static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2967 NULL);
2968
2969static void __devinit logical_port_release(struct device *dev)
2970{
2971 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002972 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002973}
2974
2975static struct device *ehea_register_port(struct ehea_port *port,
2976 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002977{
2978 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002979
Grant Likely61c7a082010-04-13 16:12:29 -07002980 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002981 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002982 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002984 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002985 port->ofdev.dev.release = logical_port_release;
2986
2987 ret = of_device_register(&port->ofdev);
2988 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002989 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002990 goto out;
2991 }
2992
2993 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002994 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002995 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002996 goto out_unreg_of_dev;
2997 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002998
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002999 return &port->ofdev.dev;
3000
3001out_unreg_of_dev:
3002 of_device_unregister(&port->ofdev);
3003out:
3004 return NULL;
3005}
3006
3007static void ehea_unregister_port(struct ehea_port *port)
3008{
3009 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3010 of_device_unregister(&port->ofdev);
3011}
3012
Thomas Klein086c1b22009-01-21 14:43:59 -08003013static const struct net_device_ops ehea_netdev_ops = {
3014 .ndo_open = ehea_open,
3015 .ndo_stop = ehea_stop,
3016 .ndo_start_xmit = ehea_start_xmit,
3017#ifdef CONFIG_NET_POLL_CONTROLLER
3018 .ndo_poll_controller = ehea_netpoll,
3019#endif
3020 .ndo_get_stats = ehea_get_stats,
3021 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003022 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003023 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003024 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003025 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003026 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3027 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003028};
3029
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003030struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3031 u32 logical_port_id,
3032 struct device_node *dn)
3033{
3034 int ret;
3035 struct net_device *dev;
3036 struct ehea_port *port;
3037 struct device *port_dev;
3038 int jumbo;
3039
3040 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00003041 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003042
3043 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003044 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003045 ret = -ENOMEM;
3046 goto out_err;
3047 }
3048
3049 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003050
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003051 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003052 port->state = EHEA_PORT_DOWN;
3053 port->sig_comp_iv = sq_entries / 10;
3054
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055 port->adapter = adapter;
3056 port->netdev = dev;
3057 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003058
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003059 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003060
3061 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3062 if (!port->mc_list) {
3063 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003065 }
3066
3067 INIT_LIST_HEAD(&port->mc_list->list);
3068
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003069 ret = ehea_sense_port_attr(port);
3070 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003071 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003072
Anton Blanchardb9564462011-10-14 05:30:59 +00003073 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003074 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003075
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003076 port_dev = ehea_register_port(port, dn);
3077 if (!port_dev)
3078 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003079
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003080 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003081
3082 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003083 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3084
Thomas Klein086c1b22009-01-21 14:43:59 -08003085 dev->netdev_ops = &ehea_netdev_ops;
3086 ehea_set_ethtool_ops(dev);
3087
Anton Blanchardd695c332011-10-14 05:31:05 +00003088 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Michał Mirosławf4786a92011-04-17 00:15:47 +00003089 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003090 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003091 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003092 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003093 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003094 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3095 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003096 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3097
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003098 if (use_lro)
3099 dev->features |= NETIF_F_LRO;
3100
David Howellsc4028952006-11-22 14:57:56 +00003101 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003102 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003103
Anton Blanchard21ccc792011-05-10 16:17:10 +00003104 init_waitqueue_head(&port->swqe_avail_wq);
3105 init_waitqueue_head(&port->restart_wq);
3106
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003107 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003108 ret = register_netdev(dev);
3109 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003110 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003111 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003112 }
3113
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003114 port->lro_max_aggr = lro_max_aggr;
3115
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003117 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003118 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003119
Joe Perches8c4877a2010-12-13 10:05:14 -08003120 netdev_info(dev, "Jumbo frames are %sabled\n",
3121 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003122
Thomas Klein44c82152007-07-11 16:32:00 +02003123 adapter->active_ports++;
3124
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003125 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003126
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003127out_unreg_port:
3128 ehea_unregister_port(port);
3129
3130out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003131 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003132
3133out_free_ethdev:
3134 free_netdev(dev);
3135
3136out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003137 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3138 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003139 return NULL;
3140}
3141
3142static void ehea_shutdown_single_port(struct ehea_port *port)
3143{
Brian King7fb1c2a2008-05-14 09:48:25 -05003144 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003145
3146 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003147 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003148 unregister_netdev(port->netdev);
3149 ehea_unregister_port(port);
3150 kfree(port->mc_list);
3151 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003152 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003153}
3154
3155static int ehea_setup_ports(struct ehea_adapter *adapter)
3156{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003157 struct device_node *lhea_dn;
3158 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003159
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003160 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003162
Grant Likely61c7a082010-04-13 16:12:29 -07003163 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003164 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003165
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003166 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003167 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003169 pr_err("bad device node: eth_dn name=%s\n",
3170 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003172 }
3173
Thomas Klein1211bb62007-04-26 11:56:43 +02003174 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003175 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003176 of_node_put(eth_dn);
3177 return -EIO;
3178 }
3179
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180 adapter->port[i] = ehea_setup_single_port(adapter,
3181 *dn_log_port_id,
3182 eth_dn);
3183 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003184 netdev_info(adapter->port[i]->netdev,
3185 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003186 else
3187 ehea_remove_adapter_mr(adapter);
3188
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003189 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003190 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003191 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003192}
3193
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003194static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3195 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003196{
3197 struct device_node *lhea_dn;
3198 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003199 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003200
Grant Likely61c7a082010-04-13 16:12:29 -07003201 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003202 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003203
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003204 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003205 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206 if (dn_log_port_id)
3207 if (*dn_log_port_id == logical_port_id)
3208 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003209 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003210
3211 return NULL;
3212}
3213
3214static ssize_t ehea_probe_port(struct device *dev,
3215 struct device_attribute *attr,
3216 const char *buf, size_t count)
3217{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003218 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 struct ehea_port *port;
3220 struct device_node *eth_dn = NULL;
3221 int i;
3222
3223 u32 logical_port_id;
3224
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003225 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226
3227 port = ehea_get_port(adapter, logical_port_id);
3228
3229 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003230 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3231 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 return -EINVAL;
3233 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003234
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003235 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3236
3237 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003238 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003239 return -EINVAL;
3240 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003241
Thomas Klein1211bb62007-04-26 11:56:43 +02003242 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003243 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003244 return -EIO;
3245 }
3246
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3248
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003249 of_node_put(eth_dn);
3250
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003252 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253 if (!adapter->port[i]) {
3254 adapter->port[i] = port;
3255 break;
3256 }
3257
Joe Perches8c4877a2010-12-13 10:05:14 -08003258 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3259 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003260 } else {
3261 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003262 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003263 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003264
3265 return (ssize_t) count;
3266}
3267
3268static ssize_t ehea_remove_port(struct device *dev,
3269 struct device_attribute *attr,
3270 const char *buf, size_t count)
3271{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003272 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003273 struct ehea_port *port;
3274 int i;
3275 u32 logical_port_id;
3276
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003277 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003278
3279 port = ehea_get_port(adapter, logical_port_id);
3280
3281 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003282 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3283 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003284
3285 ehea_shutdown_single_port(port);
3286
Doug Maxey508d2b52008-01-31 20:20:49 -06003287 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003288 if (adapter->port[i] == port) {
3289 adapter->port[i] = NULL;
3290 break;
3291 }
3292 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003293 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3294 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003295 return -EINVAL;
3296 }
3297
Thomas Klein1211bb62007-04-26 11:56:43 +02003298 ehea_remove_adapter_mr(adapter);
3299
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300 return (ssize_t) count;
3301}
3302
3303static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3304static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3305
Grant Likely2dc11582010-08-06 09:25:50 -06003306int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003307{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003308 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003309 if (ret)
3310 goto out;
3311
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003312 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003313out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003314 return ret;
3315}
3316
Grant Likely2dc11582010-08-06 09:25:50 -06003317void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003319 device_remove_file(&dev->dev, &dev_attr_probe_port);
3320 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003321}
3322
Grant Likely2dc11582010-08-06 09:25:50 -06003323static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003324 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003325{
3326 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003327 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003328 int ret;
3329
Grant Likely61c7a082010-04-13 16:12:29 -07003330 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003331 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003332 return -EINVAL;
3333 }
3334
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003335 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3336 if (!adapter) {
3337 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003338 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003339 goto out;
3340 }
3341
Thomas Klein44c82152007-07-11 16:32:00 +02003342 list_add(&adapter->list, &adapter_list);
3343
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003344 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003345
Grant Likely61c7a082010-04-13 16:12:29 -07003346 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003347 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003348 if (adapter_handle)
3349 adapter->handle = *adapter_handle;
3350
3351 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003352 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003353 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003354 ret = -ENODEV;
3355 goto out_free_ad;
3356 }
3357
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003358 adapter->pd = EHEA_PD_ID;
3359
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003360 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003361
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003362
3363 /* initialize adapter and ports */
3364 /* get adapter properties */
3365 ret = ehea_sense_adapter_attr(adapter);
3366 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003367 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003368 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003369 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003370
3371 adapter->neq = ehea_create_eq(adapter,
3372 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3373 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003374 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003375 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003376 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003377 }
3378
3379 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3380 (unsigned long)adapter);
3381
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003382 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003383 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003384 "ehea_neq", adapter);
3385 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003386 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003387 goto out_kill_eq;
3388 }
3389
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003390 ret = ehea_create_device_sysfs(dev);
3391 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003392 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003394 ret = ehea_setup_ports(adapter);
3395 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003396 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003398 }
3399
3400 ret = 0;
3401 goto out;
3402
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003403out_rem_dev_sysfs:
3404 ehea_remove_device_sysfs(dev);
3405
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003407 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003408
3409out_kill_eq:
3410 ehea_destroy_eq(adapter->neq);
3411
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003412out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003413 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003414 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003415
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003416out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003417 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003418
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003419 return ret;
3420}
3421
Grant Likely2dc11582010-08-06 09:25:50 -06003422static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003423{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003424 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003425 int i;
3426
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003427 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003428 if (adapter->port[i]) {
3429 ehea_shutdown_single_port(adapter->port[i]);
3430 adapter->port[i] = NULL;
3431 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003432
3433 ehea_remove_device_sysfs(dev);
3434
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003435 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003436 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003437
3438 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003439 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003440 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003441 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003442
Thomas Klein21eee2d2008-02-13 16:18:33 +01003443 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003444
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003445 return 0;
3446}
3447
Thomas Klein21eee2d2008-02-13 16:18:33 +01003448void ehea_crash_handler(void)
3449{
3450 int i;
3451
3452 if (ehea_fw_handles.arr)
3453 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3454 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3455 ehea_fw_handles.arr[i].fwh,
3456 FORCE_FREE);
3457
3458 if (ehea_bcmc_regs.arr)
3459 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3460 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3461 ehea_bcmc_regs.arr[i].port_id,
3462 ehea_bcmc_regs.arr[i].reg_type,
3463 ehea_bcmc_regs.arr[i].macaddr,
3464 0, H_DEREG_BCMC);
3465}
3466
Hannes Hering48cfb142008-05-07 14:43:36 +02003467static int ehea_mem_notifier(struct notifier_block *nb,
3468 unsigned long action, void *data)
3469{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003470 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003471 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003472
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003473 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003474
Hannes Hering48cfb142008-05-07 14:43:36 +02003475 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003476 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003477 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003478 /* Readd canceled memory block */
3479 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003480 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003481 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003482 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003483 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003484 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003485 break;
3486 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003487 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003488 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003489 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003490 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003491 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003492 break;
3493 default:
3494 break;
3495 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003496
3497 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003498 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003499
Thomas Kleina7c561f22010-04-20 23:11:31 +00003500out_unlock:
3501 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003502 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003503}
3504
3505static struct notifier_block ehea_mem_nb = {
3506 .notifier_call = ehea_mem_notifier,
3507};
3508
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003509static int ehea_reboot_notifier(struct notifier_block *nb,
3510 unsigned long action, void *unused)
3511{
3512 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003513 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003514 ibmebus_unregister_driver(&ehea_driver);
3515 }
3516 return NOTIFY_DONE;
3517}
3518
3519static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003520 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003521};
3522
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003523static int check_module_parm(void)
3524{
3525 int ret = 0;
3526
3527 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3528 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003529 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003530 ret = -EINVAL;
3531 }
3532 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3533 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003534 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535 ret = -EINVAL;
3536 }
3537 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3538 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003539 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540 ret = -EINVAL;
3541 }
3542 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3543 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003544 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003545 ret = -EINVAL;
3546 }
3547
3548 return ret;
3549}
3550
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003551static ssize_t ehea_show_capabilities(struct device_driver *drv,
3552 char *buf)
3553{
3554 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3555}
3556
3557static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3558 ehea_show_capabilities, NULL);
3559
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003560int __init ehea_module_init(void)
3561{
3562 int ret;
3563
Joe Perches8c4877a2010-12-13 10:05:14 -08003564 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003565
Thomas Klein21eee2d2008-02-13 16:18:33 +01003566 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3567 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3568
Daniel Walker9f71a562008-03-28 14:41:26 -07003569 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003570 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003571
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003572 ret = check_module_parm();
3573 if (ret)
3574 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003575
3576 ret = ehea_create_busmap();
3577 if (ret)
3578 goto out;
3579
Thomas Klein21eee2d2008-02-13 16:18:33 +01003580 ret = register_reboot_notifier(&ehea_reboot_nb);
3581 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003582 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003583
Hannes Hering48cfb142008-05-07 14:43:36 +02003584 ret = register_memory_notifier(&ehea_mem_nb);
3585 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003586 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003587
Joe Perchesc061b182010-08-23 18:20:03 +00003588 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003589 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003590 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003593 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003594 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003595 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003596 }
3597
3598 ret = driver_create_file(&ehea_driver.driver,
3599 &driver_attr_capabilities);
3600 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003601 pr_err("failed to register capabilities attribute, ret=%d\n",
3602 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003603 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003604 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003605
Thomas Klein21eee2d2008-02-13 16:18:33 +01003606 return ret;
3607
3608out3:
3609 ibmebus_unregister_driver(&ehea_driver);
3610out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003611 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003612 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003613 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003614out:
3615 return ret;
3616}
3617
3618static void __exit ehea_module_exit(void)
3619{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003620 int ret;
3621
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003622 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003623 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003624 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003625 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003626 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003627 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003628 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003629 kfree(ehea_fw_handles.arr);
3630 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003631 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003632}
3633
3634module_init(ehea_module_init);
3635module_exit(ehea_module_exit);