blob: 77aafba8272c02bb8059bf8efd990ef691f6da23 [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
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001679static void write_swqe2_TSO(struct sk_buff *skb,
1680 struct ehea_swqe *swqe, u32 lkey)
1681{
1682 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1683 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001684 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001685 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001686
1687 /* Packet is TCP with TSO enabled */
1688 swqe->tx_control |= EHEA_SWQE_TSO;
1689 swqe->mss = skb_shinfo(skb)->gso_size;
1690 /* copy only eth/ip/tcp headers to immediate data and
1691 * the rest of skb->data to sg1entry
1692 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001693 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001694
Eric Dumazete743d312010-04-14 15:59:40 -07001695 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001696
1697 if (skb_data_size >= headersize) {
1698 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001699 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001700 swqe->immediate_data_length = headersize;
1701
1702 if (skb_data_size > headersize) {
1703 /* set sg1entry data */
1704 sg1entry->l_key = lkey;
1705 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001706 sg1entry->vaddr =
1707 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708 swqe->descriptors++;
1709 }
1710 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001711 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001712}
1713
1714static void write_swqe2_nonTSO(struct sk_buff *skb,
1715 struct ehea_swqe *swqe, u32 lkey)
1716{
Eric Dumazete743d312010-04-14 15:59:40 -07001717 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001718 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1719 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001720
1721 /* Packet is any nonTSO type
1722 *
1723 * Copy as much as possible skb->data to immediate data and
1724 * the rest to sg1entry
1725 */
1726 if (skb_data_size >= SWQE2_MAX_IMM) {
1727 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001728 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001729
1730 swqe->immediate_data_length = SWQE2_MAX_IMM;
1731
1732 if (skb_data_size > SWQE2_MAX_IMM) {
1733 /* copy sg1entry data */
1734 sg1entry->l_key = lkey;
1735 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001736 sg1entry->vaddr =
1737 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001738 swqe->descriptors++;
1739 }
1740 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001741 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001742 swqe->immediate_data_length = skb_data_size;
1743 }
1744}
1745
1746static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1747 struct ehea_swqe *swqe, u32 lkey)
1748{
1749 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1750 skb_frag_t *frag;
1751 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001752
1753 nfrags = skb_shinfo(skb)->nr_frags;
1754 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001755 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001756 swqe->descriptors = 0;
1757 sg1entry_contains_frag_data = 0;
1758
Anton Blanchard921ddc12011-10-14 05:31:02 +00001759 if (skb_is_gso(skb))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001760 write_swqe2_TSO(skb, swqe, lkey);
1761 else
1762 write_swqe2_nonTSO(skb, swqe, lkey);
1763
1764 /* write descriptors */
1765 if (nfrags > 0) {
1766 if (swqe->descriptors == 0) {
1767 /* sg1entry not yet used */
1768 frag = &skb_shinfo(skb)->frags[0];
1769
1770 /* copy sg1entry data */
1771 sg1entry->l_key = lkey;
1772 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001773 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001774 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001775 swqe->descriptors++;
1776 sg1entry_contains_frag_data = 1;
1777 }
1778
1779 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1780
1781 frag = &skb_shinfo(skb)->frags[i];
1782 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1783
1784 sgentry->l_key = lkey;
1785 sgentry->len = frag->size;
Ian Campbell618c4a02011-10-10 01:11:38 +00001786 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001787 swqe->descriptors++;
1788 }
1789 }
1790}
1791
1792static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1793{
1794 int ret = 0;
1795 u64 hret;
1796 u8 reg_type;
1797
1798 /* De/Register untagged packets */
1799 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1800 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1801 port->logical_port_id,
1802 reg_type, port->mac_addr, 0, hcallid);
1803 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001804 pr_err("%sregistering bc address failed (tagged)\n",
1805 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001806 ret = -EIO;
1807 goto out_herr;
1808 }
1809
1810 /* De/Register VLAN packets */
1811 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1812 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1813 port->logical_port_id,
1814 reg_type, port->mac_addr, 0, hcallid);
1815 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001816 pr_err("%sregistering bc address failed (vlan)\n",
1817 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818 ret = -EIO;
1819 }
1820out_herr:
1821 return ret;
1822}
1823
1824static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1825{
1826 struct ehea_port *port = netdev_priv(dev);
1827 struct sockaddr *mac_addr = sa;
1828 struct hcp_ehea_port_cb0 *cb0;
1829 int ret;
1830 u64 hret;
1831
1832 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1833 ret = -EADDRNOTAVAIL;
1834 goto out;
1835 }
1836
Thomas Klein3faf2692009-01-21 14:45:33 -08001837 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001838 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001839 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001840 ret = -ENOMEM;
1841 goto out;
1842 }
1843
1844 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1845
1846 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1847
1848 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1849 port->logical_port_id, H_PORT_CB0,
1850 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1851 if (hret != H_SUCCESS) {
1852 ret = -EIO;
1853 goto out_free;
1854 }
1855
1856 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1857
1858 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001859 if (port->state == EHEA_PORT_UP) {
1860 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1861 if (ret)
1862 goto out_upregs;
1863 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001864
1865 port->mac_addr = cb0->port_mac_addr << 16;
1866
1867 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001868 if (port->state == EHEA_PORT_UP) {
1869 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1870 if (ret)
1871 goto out_upregs;
1872 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001873
1874 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001875
1876out_upregs:
1877 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001878out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001879 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001880out:
1881 return ret;
1882}
1883
1884static void ehea_promiscuous_error(u64 hret, int enable)
1885{
Thomas Klein7674a582007-01-22 12:54:20 +01001886 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001887 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1888 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001889 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001890 pr_err("failed %sabling promiscuous mode\n",
1891 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001892}
1893
1894static void ehea_promiscuous(struct net_device *dev, int enable)
1895{
1896 struct ehea_port *port = netdev_priv(dev);
1897 struct hcp_ehea_port_cb7 *cb7;
1898 u64 hret;
1899
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001900 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001901 return;
1902
Thomas Klein3faf2692009-01-21 14:45:33 -08001903 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001904 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001905 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906 goto out;
1907 }
1908
1909 /* Modify Pxs_DUCQPN in CB7 */
1910 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1911
1912 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1913 port->logical_port_id,
1914 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1915 if (hret) {
1916 ehea_promiscuous_error(hret, enable);
1917 goto out;
1918 }
1919
1920 port->promisc = enable;
1921out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001922 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001923}
1924
1925static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1926 u32 hcallid)
1927{
1928 u64 hret;
1929 u8 reg_type;
1930
1931 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1932 | EHEA_BCMC_UNTAGGED;
1933
1934 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1935 port->logical_port_id,
1936 reg_type, mc_mac_addr, 0, hcallid);
1937 if (hret)
1938 goto out;
1939
1940 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1941 | EHEA_BCMC_VLANID_ALL;
1942
1943 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1944 port->logical_port_id,
1945 reg_type, mc_mac_addr, 0, hcallid);
1946out:
1947 return hret;
1948}
1949
1950static int ehea_drop_multicast_list(struct net_device *dev)
1951{
1952 struct ehea_port *port = netdev_priv(dev);
1953 struct ehea_mc_list *mc_entry = port->mc_list;
1954 struct list_head *pos;
1955 struct list_head *temp;
1956 int ret = 0;
1957 u64 hret;
1958
1959 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1960 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1961
1962 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1963 H_DEREG_BCMC);
1964 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001965 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001966 ret = -EIO;
1967 }
1968
1969 list_del(pos);
1970 kfree(mc_entry);
1971 }
1972 return ret;
1973}
1974
1975static void ehea_allmulti(struct net_device *dev, int enable)
1976{
1977 struct ehea_port *port = netdev_priv(dev);
1978 u64 hret;
1979
1980 if (!port->allmulti) {
1981 if (enable) {
1982 /* Enable ALLMULTI */
1983 ehea_drop_multicast_list(dev);
1984 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1985 if (!hret)
1986 port->allmulti = 1;
1987 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001988 netdev_err(dev,
1989 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001990 }
1991 } else
1992 if (!enable) {
1993 /* Disable ALLMULTI */
1994 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1995 if (!hret)
1996 port->allmulti = 0;
1997 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001998 netdev_err(dev,
1999 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002000 }
2001}
2002
Doug Maxey508d2b52008-01-31 20:20:49 -06002003static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002004{
2005 struct ehea_mc_list *ehea_mcl_entry;
2006 u64 hret;
2007
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002008 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002009 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002010 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002011 return;
2012 }
2013
2014 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2015
2016 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2017
2018 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2019 H_REG_BCMC);
2020 if (!hret)
2021 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2022 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002023 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002024 kfree(ehea_mcl_entry);
2025 }
2026}
2027
2028static void ehea_set_multicast_list(struct net_device *dev)
2029{
2030 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002031 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002032 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033
Breno Leitaoa4910b72011-05-23 03:36:35 +00002034 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 ehea_promiscuous(dev, 1);
2036 return;
2037 }
2038 ehea_promiscuous(dev, 0);
2039
2040 if (dev->flags & IFF_ALLMULTI) {
2041 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002042 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 }
2044 ehea_allmulti(dev, 0);
2045
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002046 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002047 ret = ehea_drop_multicast_list(dev);
2048 if (ret) {
2049 /* Dropping the current multicast list failed.
2050 * Enabling ALL_MULTI is the best we can do.
2051 */
2052 ehea_allmulti(dev, 1);
2053 }
2054
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002055 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002056 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2057 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002058 goto out;
2059 }
2060
Jiri Pirko22bedad32010-04-01 21:22:57 +00002061 netdev_for_each_mc_addr(ha, dev)
2062 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002063
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002064 }
2065out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002066 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002067}
2068
2069static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2070{
2071 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2072 return -EINVAL;
2073 dev->mtu = new_mtu;
2074 return 0;
2075}
2076
Anton Blanchardd695c332011-10-14 05:31:05 +00002077static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
2078{
2079 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
2080
2081 if (skb->protocol != htons(ETH_P_IP))
2082 return;
2083
2084 if (skb->ip_summed == CHECKSUM_PARTIAL)
2085 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
2086
2087 swqe->ip_start = skb_network_offset(skb);
2088 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
2089
2090 switch (ip_hdr(skb)->protocol) {
2091 case IPPROTO_UDP:
2092 if (skb->ip_summed == CHECKSUM_PARTIAL)
2093 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2094
2095 swqe->tcp_offset = swqe->ip_end + 1 +
2096 offsetof(struct udphdr, check);
2097 swqe->tcp_end = skb->len - 1;
2098 break;
2099
2100 case IPPROTO_TCP:
2101 if (skb->ip_summed == CHECKSUM_PARTIAL)
2102 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2103
2104 swqe->tcp_offset = swqe->ip_end + 1 +
2105 offsetof(struct tcphdr, check);
2106 swqe->tcp_end = skb->len - 1;
2107 break;
2108 }
2109}
2110
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2112 struct ehea_swqe *swqe, u32 lkey)
2113{
Anton Blanchardd695c332011-10-14 05:31:05 +00002114 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002115
Anton Blanchardd695c332011-10-14 05:31:05 +00002116 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117
2118 write_swqe2_data(skb, dev, swqe, lkey);
2119}
2120
2121static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2122 struct ehea_swqe *swqe)
2123{
2124 int nfrags = skb_shinfo(skb)->nr_frags;
2125 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2126 skb_frag_t *frag;
2127 int i;
2128
Anton Blanchardd695c332011-10-14 05:31:05 +00002129 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002130
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002131 if (nfrags == 0) {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002132 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002133 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002134 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002135 skb_headlen(skb));
2136 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002137
2138 /* ... then copy data from the fragments */
2139 for (i = 0; i < nfrags; i++) {
2140 frag = &skb_shinfo(skb)->frags[i];
Ian Campbell618c4a02011-10-10 01:11:38 +00002141 memcpy(imm_data, skb_frag_address(frag), frag->size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002142 imm_data += frag->size;
2143 }
2144 }
Anton Blanchardd695c332011-10-14 05:31:05 +00002145
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002146 swqe->immediate_data_length = skb->len;
2147 dev_kfree_skb(skb);
2148}
2149
2150static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2151{
2152 struct ehea_port *port = netdev_priv(dev);
2153 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002154 u32 lkey;
2155 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002156 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002157 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158
Anton Blanchardb9564462011-10-14 05:30:59 +00002159 pr = &port->port_res[skb_get_queue_mapping(skb)];
2160 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002161
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002162 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2163 memset(swqe, 0, SWQE_HEADER_SIZE);
2164 atomic_dec(&pr->swqe_avail);
2165
Eric Dumazete5ccd962010-10-26 19:21:07 +00002166 if (vlan_tx_tag_present(skb)) {
2167 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2168 swqe->vlan_tag = vlan_tx_tag_get(skb);
2169 }
2170
Breno Leitaoce45b872010-10-27 08:45:14 +00002171 pr->tx_packets++;
2172 pr->tx_bytes += skb->len;
2173
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174 if (skb->len <= SWQE3_MAX_IMM) {
2175 u32 sig_iv = port->sig_comp_iv;
2176 u32 swqe_num = pr->swqe_id_counter;
2177 ehea_xmit3(skb, dev, swqe);
2178 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2179 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2180 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2181 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2182 sig_iv);
2183 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2184 pr->swqe_ll_count = 0;
2185 } else
2186 pr->swqe_ll_count += 1;
2187 } else {
2188 swqe->wr_id =
2189 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2190 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002191 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2193 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2194
2195 pr->sq_skba.index++;
2196 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2197
2198 lkey = pr->send_mr.lkey;
2199 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002200 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002201 }
2202 pr->swqe_id_counter += 1;
2203
Joe Perches8c4877a2010-12-13 10:05:14 -08002204 netif_info(port, tx_queued, dev,
2205 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2206 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002207 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002209 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002210 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002211 swqe->tx_control |= EHEA_SWQE_PURGE;
2212 }
Thomas Klein44c82152007-07-11 16:32:00 +02002213
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002214 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002215
2216 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002217 pr->p_stats.queue_stopped++;
2218 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002220
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002221 return NETDEV_TX_OK;
2222}
2223
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002224static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2225{
2226 struct ehea_port *port = netdev_priv(dev);
2227 struct ehea_adapter *adapter = port->adapter;
2228 struct hcp_ehea_port_cb1 *cb1;
2229 int index;
2230 u64 hret;
2231
Thomas Klein3faf2692009-01-21 14:45:33 -08002232 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002233 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002234 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235 goto out;
2236 }
2237
2238 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2239 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2240 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002241 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002242 goto out;
2243 }
2244
2245 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002246 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002247
2248 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2249 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2250 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002251 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002252out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002253 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254 return;
2255}
2256
2257static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2258{
2259 struct ehea_port *port = netdev_priv(dev);
2260 struct ehea_adapter *adapter = port->adapter;
2261 struct hcp_ehea_port_cb1 *cb1;
2262 int index;
2263 u64 hret;
2264
Thomas Klein3faf2692009-01-21 14:45:33 -08002265 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002266 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002267 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268 goto out;
2269 }
2270
2271 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2272 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2273 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002274 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275 goto out;
2276 }
2277
2278 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002279 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002280
2281 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2282 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2283 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002284 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002286 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002287}
2288
2289int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2290{
2291 int ret = -EIO;
2292 u64 hret;
2293 u16 dummy16 = 0;
2294 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002295 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002296
Thomas Klein3faf2692009-01-21 14:45:33 -08002297 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 if (!cb0) {
2299 ret = -ENOMEM;
2300 goto out;
2301 }
2302
2303 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2304 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2305 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002306 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002307 goto out;
2308 }
2309
2310 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2311 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2312 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2313 &dummy64, &dummy64, &dummy16, &dummy16);
2314 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002315 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002316 goto out;
2317 }
2318
2319 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2320 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2321 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002322 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002323 goto out;
2324 }
2325
2326 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2327 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2328 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2329 &dummy64, &dummy64, &dummy16, &dummy16);
2330 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002331 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002332 goto out;
2333 }
2334
2335 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2336 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2337 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002338 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002339 goto out;
2340 }
2341
2342 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2343 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2344 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2345 &dummy64, &dummy64, &dummy16, &dummy16);
2346 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002347 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002348 goto out;
2349 }
2350
2351 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2352 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2353 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002354 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355 goto out;
2356 }
2357
2358 ret = 0;
2359out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002360 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361 return ret;
2362}
2363
Anton Blanchard723f28e2011-10-14 05:31:01 +00002364static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365{
2366 int ret, i;
2367 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2368 enum ehea_eq_type eq_type = EHEA_EQ;
2369
2370 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2371 EHEA_MAX_ENTRIES_EQ, 1);
2372 if (!port->qp_eq) {
2373 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002374 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 goto out_kill_eq;
2376 }
2377
2378 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002379 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 pr_cfg.max_entries_sq = sq_entries;
2381 pr_cfg.max_entries_rq1 = rq1_entries;
2382 pr_cfg.max_entries_rq2 = rq2_entries;
2383 pr_cfg.max_entries_rq3 = rq3_entries;
2384
2385 pr_cfg_small_rx.max_entries_rcq = 1;
2386 pr_cfg_small_rx.max_entries_scq = sq_entries;
2387 pr_cfg_small_rx.max_entries_sq = sq_entries;
2388 pr_cfg_small_rx.max_entries_rq1 = 1;
2389 pr_cfg_small_rx.max_entries_rq2 = 1;
2390 pr_cfg_small_rx.max_entries_rq3 = 1;
2391
2392 for (i = 0; i < def_qps; i++) {
2393 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2394 if (ret)
2395 goto out_clean_pr;
2396 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002397 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 ret = ehea_init_port_res(port, &port->port_res[i],
2399 &pr_cfg_small_rx, i);
2400 if (ret)
2401 goto out_clean_pr;
2402 }
2403
2404 return 0;
2405
2406out_clean_pr:
2407 while (--i >= 0)
2408 ehea_clean_portres(port, &port->port_res[i]);
2409
2410out_kill_eq:
2411 ehea_destroy_eq(port->qp_eq);
2412 return ret;
2413}
2414
2415static int ehea_clean_all_portres(struct ehea_port *port)
2416{
2417 int ret = 0;
2418 int i;
2419
Anton Blanchard723f28e2011-10-14 05:31:01 +00002420 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002421 ret |= ehea_clean_portres(port, &port->port_res[i]);
2422
2423 ret |= ehea_destroy_eq(port->qp_eq);
2424
2425 return ret;
2426}
2427
Thomas Klein35cf2e22007-08-06 13:55:14 +02002428static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002429{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002430 if (adapter->active_ports)
2431 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002432
2433 ehea_rem_mr(&adapter->mr);
2434}
2435
Thomas Klein35cf2e22007-08-06 13:55:14 +02002436static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002437{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002438 if (adapter->active_ports)
2439 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002440
2441 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2442}
2443
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444static int ehea_up(struct net_device *dev)
2445{
2446 int ret, i;
2447 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002448
2449 if (port->state == EHEA_PORT_UP)
2450 return 0;
2451
Anton Blanchard723f28e2011-10-14 05:31:01 +00002452 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002454 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455 goto out;
2456 }
2457
2458 /* Set default QP for this port */
2459 ret = ehea_configure_port(port);
2460 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002461 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 goto out_clean_pr;
2463 }
2464
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002465 ret = ehea_reg_interrupts(dev);
2466 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002467 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002468 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002469 }
2470
Anton Blanchard723f28e2011-10-14 05:31:01 +00002471 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002472 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2473 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002474 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002475 goto out_free_irqs;
2476 }
2477 }
2478
Doug Maxey508d2b52008-01-31 20:20:49 -06002479 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002480 ret = ehea_fill_port_res(&port->port_res[i]);
2481 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002482 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483 goto out_free_irqs;
2484 }
2485 }
2486
Thomas Klein21eee2d2008-02-13 16:18:33 +01002487 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2488 if (ret) {
2489 ret = -EIO;
2490 goto out_free_irqs;
2491 }
2492
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002493 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002494
2495 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002496 goto out;
2497
2498out_free_irqs:
2499 ehea_free_interrupts(dev);
2500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501out_clean_pr:
2502 ehea_clean_all_portres(port);
2503out:
Thomas Klein44c82152007-07-11 16:32:00 +02002504 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002505 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002506
Thomas Klein21eee2d2008-02-13 16:18:33 +01002507 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002508 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002509
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002510 return ret;
2511}
2512
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002513static void port_napi_disable(struct ehea_port *port)
2514{
2515 int i;
2516
Anton Blanchard723f28e2011-10-14 05:31:01 +00002517 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002518 napi_disable(&port->port_res[i].napi);
2519}
2520
2521static void port_napi_enable(struct ehea_port *port)
2522{
2523 int i;
2524
Anton Blanchard723f28e2011-10-14 05:31:01 +00002525 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002526 napi_enable(&port->port_res[i].napi);
2527}
2528
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529static int ehea_open(struct net_device *dev)
2530{
2531 int ret;
2532 struct ehea_port *port = netdev_priv(dev);
2533
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002534 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002535
Joe Perches8c4877a2010-12-13 10:05:14 -08002536 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002537
2538 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002539 if (!ret) {
2540 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002541 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002542 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002543
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002544 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002545 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002546
2547 return ret;
2548}
2549
2550static int ehea_down(struct net_device *dev)
2551{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002552 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002553 struct ehea_port *port = netdev_priv(dev);
2554
2555 if (port->state == EHEA_PORT_DOWN)
2556 return 0;
2557
2558 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002559 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2560
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002561 ehea_free_interrupts(dev);
2562
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002563 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002564
Thomas Klein21eee2d2008-02-13 16:18:33 +01002565 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002566
Thomas Klein44c82152007-07-11 16:32:00 +02002567 ret = ehea_clean_all_portres(port);
2568 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002569 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002570
Thomas Klein21eee2d2008-02-13 16:18:33 +01002571 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002572
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002573 return ret;
2574}
2575
2576static int ehea_stop(struct net_device *dev)
2577{
2578 int ret;
2579 struct ehea_port *port = netdev_priv(dev);
2580
Joe Perches8c4877a2010-12-13 10:05:14 -08002581 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002582
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002583 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002584 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002585 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002586 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002587 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002588 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002590 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002591 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002592 return ret;
2593}
2594
Andrew Morton22559c52008-04-18 13:50:39 -07002595static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002596{
2597 struct ehea_qp qp = *orig_qp;
2598 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2599 struct ehea_swqe *swqe;
2600 int wqe_index;
2601 int i;
2602
2603 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2604 swqe = ehea_get_swqe(&qp, &wqe_index);
2605 swqe->tx_control |= EHEA_SWQE_PURGE;
2606 }
2607}
2608
Andrew Morton22559c52008-04-18 13:50:39 -07002609static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002610{
2611 int i;
2612
Anton Blanchard723f28e2011-10-14 05:31:01 +00002613 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002614 struct ehea_port_res *pr = &port->port_res[i];
2615 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002616 int ret;
2617
2618 ret = wait_event_timeout(port->swqe_avail_wq,
2619 atomic_read(&pr->swqe_avail) >= swqe_max,
2620 msecs_to_jiffies(100));
2621
2622 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002623 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002624 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002625 }
2626 }
2627}
2628
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002629int ehea_stop_qps(struct net_device *dev)
2630{
2631 struct ehea_port *port = netdev_priv(dev);
2632 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002633 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002634 int ret = -EIO;
2635 int dret;
2636 int i;
2637 u64 hret;
2638 u64 dummy64 = 0;
2639 u16 dummy16 = 0;
2640
Thomas Klein3faf2692009-01-21 14:45:33 -08002641 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002642 if (!cb0) {
2643 ret = -ENOMEM;
2644 goto out;
2645 }
2646
Anton Blanchard723f28e2011-10-14 05:31:01 +00002647 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002648 struct ehea_port_res *pr = &port->port_res[i];
2649 struct ehea_qp *qp = pr->qp;
2650
2651 /* Purge send queue */
2652 ehea_purge_sq(qp);
2653
2654 /* Disable queue pair */
2655 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2656 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2657 cb0);
2658 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002659 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002660 goto out;
2661 }
2662
2663 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2664 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2665
2666 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2667 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2668 1), cb0, &dummy64,
2669 &dummy64, &dummy16, &dummy16);
2670 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002671 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002672 goto out;
2673 }
2674
2675 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2676 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2677 cb0);
2678 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002679 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002680 goto out;
2681 }
2682
2683 /* deregister shared memory regions */
2684 dret = ehea_rem_smrs(pr);
2685 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002686 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002687 goto out;
2688 }
2689 }
2690
2691 ret = 0;
2692out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002693 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002694
2695 return ret;
2696}
2697
Doug Maxey508d2b52008-01-31 20:20:49 -06002698void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002699{
2700 struct ehea_qp qp = *orig_qp;
2701 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2702 struct ehea_rwqe *rwqe;
2703 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2704 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2705 struct sk_buff *skb;
2706 u32 lkey = pr->recv_mr.lkey;
2707
2708
2709 int i;
2710 int index;
2711
2712 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2713 rwqe = ehea_get_next_rwqe(&qp, 2);
2714 rwqe->sg_list[0].l_key = lkey;
2715 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2716 skb = skba_rq2[index];
2717 if (skb)
2718 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2719 }
2720
2721 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2722 rwqe = ehea_get_next_rwqe(&qp, 3);
2723 rwqe->sg_list[0].l_key = lkey;
2724 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2725 skb = skba_rq3[index];
2726 if (skb)
2727 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2728 }
2729}
2730
2731int ehea_restart_qps(struct net_device *dev)
2732{
2733 struct ehea_port *port = netdev_priv(dev);
2734 struct ehea_adapter *adapter = port->adapter;
2735 int ret = 0;
2736 int i;
2737
Doug Maxey508d2b52008-01-31 20:20:49 -06002738 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002739 u64 hret;
2740 u64 dummy64 = 0;
2741 u16 dummy16 = 0;
2742
Thomas Klein3faf2692009-01-21 14:45:33 -08002743 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002744 if (!cb0) {
2745 ret = -ENOMEM;
2746 goto out;
2747 }
2748
Anton Blanchard723f28e2011-10-14 05:31:01 +00002749 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002750 struct ehea_port_res *pr = &port->port_res[i];
2751 struct ehea_qp *qp = pr->qp;
2752
2753 ret = ehea_gen_smrs(pr);
2754 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002755 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002756 goto out;
2757 }
2758
2759 ehea_update_rqs(qp, pr);
2760
2761 /* Enable queue pair */
2762 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2763 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2764 cb0);
2765 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002766 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002767 goto out;
2768 }
2769
2770 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2771 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2772
2773 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2774 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2775 1), cb0, &dummy64,
2776 &dummy64, &dummy16, &dummy16);
2777 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002778 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002779 goto out;
2780 }
2781
2782 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2783 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2784 cb0);
2785 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002786 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002787 goto out;
2788 }
2789
2790 /* refill entire queue */
2791 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2792 ehea_refill_rq2(pr, 0);
2793 ehea_refill_rq3(pr, 0);
2794 }
2795out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002796 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002797
2798 return ret;
2799}
2800
David Howellsc4028952006-11-22 14:57:56 +00002801static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002802{
2803 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002804 struct ehea_port *port =
2805 container_of(work, struct ehea_port, reset_task);
2806 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002807
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002808 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002809 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002810 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002811 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002812
2813 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002814
Thomas Klein44c82152007-07-11 16:32:00 +02002815 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002816
2817 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002818 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002819 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002820
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002821 ehea_set_multicast_list(dev);
2822
Joe Perches8c4877a2010-12-13 10:05:14 -08002823 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002824
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002825 port_napi_enable(port);
2826
Anton Blanchardb9564462011-10-14 05:30:59 +00002827 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002828out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002829 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002830 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002831}
2832
Tejun Heo3d6b8922010-12-12 16:45:14 +01002833static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002834{
2835 int ret, i;
2836 struct ehea_adapter *adapter;
2837
Joe Perches8c4877a2010-12-13 10:05:14 -08002838 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002839
2840 list_for_each_entry(adapter, &adapter_list, list)
2841 if (adapter->active_ports) {
2842 /* Shutdown all ports */
2843 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2844 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002845 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002846
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002847 if (!port)
2848 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002849
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002850 dev = port->netdev;
2851
2852 if (dev->flags & IFF_UP) {
2853 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002854 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002855 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002856 ret = ehea_stop_qps(dev);
2857 if (ret) {
2858 mutex_unlock(&port->port_lock);
2859 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002860 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002861 port_napi_disable(port);
2862 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002863 }
Andre Detsch2928db42010-08-17 05:49:12 +00002864 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002865 }
2866
2867 /* Unregister old memory region */
2868 ret = ehea_rem_mr(&adapter->mr);
2869 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002870 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002871 goto out;
2872 }
2873 }
2874
Thomas Klein44c82152007-07-11 16:32:00 +02002875 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2876
2877 list_for_each_entry(adapter, &adapter_list, list)
2878 if (adapter->active_ports) {
2879 /* Register new memory region */
2880 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2881 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002882 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002883 goto out;
2884 }
2885
2886 /* Restart all ports */
2887 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2888 struct ehea_port *port = adapter->port[i];
2889
2890 if (port) {
2891 struct net_device *dev = port->netdev;
2892
2893 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002894 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002895 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002896 if (!ret) {
2897 check_sqs(port);
2898 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002899 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002900 } else {
2901 netdev_err(dev, "Unable to restart QPS\n");
2902 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002903 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002904 }
2905 }
2906 }
2907 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002908 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002909out:
2910 return;
2911}
2912
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002913static void ehea_tx_watchdog(struct net_device *dev)
2914{
2915 struct ehea_port *port = netdev_priv(dev);
2916
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002917 if (netif_carrier_ok(dev) &&
2918 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002919 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002920}
2921
2922int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2923{
2924 struct hcp_query_ehea *cb;
2925 u64 hret;
2926 int ret;
2927
Thomas Klein3faf2692009-01-21 14:45:33 -08002928 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002929 if (!cb) {
2930 ret = -ENOMEM;
2931 goto out;
2932 }
2933
2934 hret = ehea_h_query_ehea(adapter->handle, cb);
2935
2936 if (hret != H_SUCCESS) {
2937 ret = -EIO;
2938 goto out_herr;
2939 }
2940
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002941 adapter->max_mc_mac = cb->max_mc_mac - 1;
2942 ret = 0;
2943
2944out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002945 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002946out:
2947 return ret;
2948}
2949
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002950int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2951{
2952 struct hcp_ehea_port_cb4 *cb4;
2953 u64 hret;
2954 int ret = 0;
2955
2956 *jumbo = 0;
2957
2958 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002959 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002960 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002961 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002962 ret = -ENOMEM;
2963 goto out;
2964 } else {
2965 hret = ehea_h_query_ehea_port(port->adapter->handle,
2966 port->logical_port_id,
2967 H_PORT_CB4,
2968 H_PORT_CB4_JUMBO, cb4);
2969 if (hret == H_SUCCESS) {
2970 if (cb4->jumbo_frame)
2971 *jumbo = 1;
2972 else {
2973 cb4->jumbo_frame = 1;
2974 hret = ehea_h_modify_ehea_port(port->adapter->
2975 handle,
2976 port->
2977 logical_port_id,
2978 H_PORT_CB4,
2979 H_PORT_CB4_JUMBO,
2980 cb4);
2981 if (hret == H_SUCCESS)
2982 *jumbo = 1;
2983 }
2984 } else
2985 ret = -EINVAL;
2986
Thomas Klein3faf2692009-01-21 14:45:33 -08002987 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002988 }
2989out:
2990 return ret;
2991}
2992
2993static ssize_t ehea_show_port_id(struct device *dev,
2994 struct device_attribute *attr, char *buf)
2995{
2996 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002997 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002998}
2999
3000static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3001 NULL);
3002
3003static void __devinit logical_port_release(struct device *dev)
3004{
3005 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003006 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003007}
3008
3009static struct device *ehea_register_port(struct ehea_port *port,
3010 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003011{
3012 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003013
Grant Likely61c7a082010-04-13 16:12:29 -07003014 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003015 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003016 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003017
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003018 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003019 port->ofdev.dev.release = logical_port_release;
3020
3021 ret = of_device_register(&port->ofdev);
3022 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003023 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003024 goto out;
3025 }
3026
3027 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003028 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003029 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003030 goto out_unreg_of_dev;
3031 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003032
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003033 return &port->ofdev.dev;
3034
3035out_unreg_of_dev:
3036 of_device_unregister(&port->ofdev);
3037out:
3038 return NULL;
3039}
3040
3041static void ehea_unregister_port(struct ehea_port *port)
3042{
3043 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3044 of_device_unregister(&port->ofdev);
3045}
3046
Thomas Klein086c1b22009-01-21 14:43:59 -08003047static const struct net_device_ops ehea_netdev_ops = {
3048 .ndo_open = ehea_open,
3049 .ndo_stop = ehea_stop,
3050 .ndo_start_xmit = ehea_start_xmit,
3051#ifdef CONFIG_NET_POLL_CONTROLLER
3052 .ndo_poll_controller = ehea_netpoll,
3053#endif
3054 .ndo_get_stats = ehea_get_stats,
3055 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003056 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003057 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003058 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003059 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003060 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3061 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003062};
3063
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3065 u32 logical_port_id,
3066 struct device_node *dn)
3067{
3068 int ret;
3069 struct net_device *dev;
3070 struct ehea_port *port;
3071 struct device *port_dev;
3072 int jumbo;
3073
3074 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00003075 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003076
3077 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003078 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003079 ret = -ENOMEM;
3080 goto out_err;
3081 }
3082
3083 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003084
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003085 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003086 port->state = EHEA_PORT_DOWN;
3087 port->sig_comp_iv = sq_entries / 10;
3088
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003089 port->adapter = adapter;
3090 port->netdev = dev;
3091 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003092
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003093 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003094
3095 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3096 if (!port->mc_list) {
3097 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099 }
3100
3101 INIT_LIST_HEAD(&port->mc_list->list);
3102
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003103 ret = ehea_sense_port_attr(port);
3104 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003106
Anton Blanchardb9564462011-10-14 05:30:59 +00003107 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003108 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003109
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 port_dev = ehea_register_port(port, dn);
3111 if (!port_dev)
3112 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003113
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003115
3116 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003117 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3118
Thomas Klein086c1b22009-01-21 14:43:59 -08003119 dev->netdev_ops = &ehea_netdev_ops;
3120 ehea_set_ethtool_ops(dev);
3121
Anton Blanchardd695c332011-10-14 05:31:05 +00003122 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Michał Mirosławf4786a92011-04-17 00:15:47 +00003123 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003124 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003125 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003126 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003127 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003128 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3129 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003130 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3131
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003132 if (use_lro)
3133 dev->features |= NETIF_F_LRO;
3134
David Howellsc4028952006-11-22 14:57:56 +00003135 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003136 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003137
Anton Blanchard21ccc792011-05-10 16:17:10 +00003138 init_waitqueue_head(&port->swqe_avail_wq);
3139 init_waitqueue_head(&port->restart_wq);
3140
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003141 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003142 ret = register_netdev(dev);
3143 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003144 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003145 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003146 }
3147
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003148 port->lro_max_aggr = lro_max_aggr;
3149
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003151 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003152 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003153
Joe Perches8c4877a2010-12-13 10:05:14 -08003154 netdev_info(dev, "Jumbo frames are %sabled\n",
3155 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003156
Thomas Klein44c82152007-07-11 16:32:00 +02003157 adapter->active_ports++;
3158
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003159 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003160
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161out_unreg_port:
3162 ehea_unregister_port(port);
3163
3164out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003165 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166
3167out_free_ethdev:
3168 free_netdev(dev);
3169
3170out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003171 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3172 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003173 return NULL;
3174}
3175
3176static void ehea_shutdown_single_port(struct ehea_port *port)
3177{
Brian King7fb1c2a2008-05-14 09:48:25 -05003178 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003179
3180 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003181 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003182 unregister_netdev(port->netdev);
3183 ehea_unregister_port(port);
3184 kfree(port->mc_list);
3185 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003186 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003187}
3188
3189static int ehea_setup_ports(struct ehea_adapter *adapter)
3190{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003191 struct device_node *lhea_dn;
3192 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003193
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003194 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003195 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003196
Grant Likely61c7a082010-04-13 16:12:29 -07003197 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003198 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003199
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003200 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003201 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003202 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003203 pr_err("bad device node: eth_dn name=%s\n",
3204 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003205 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003206 }
3207
Thomas Klein1211bb62007-04-26 11:56:43 +02003208 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003209 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003210 of_node_put(eth_dn);
3211 return -EIO;
3212 }
3213
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003214 adapter->port[i] = ehea_setup_single_port(adapter,
3215 *dn_log_port_id,
3216 eth_dn);
3217 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003218 netdev_info(adapter->port[i]->netdev,
3219 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003220 else
3221 ehea_remove_adapter_mr(adapter);
3222
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003223 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003224 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003225 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226}
3227
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003228static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3229 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230{
3231 struct device_node *lhea_dn;
3232 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003233 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003234
Grant Likely61c7a082010-04-13 16:12:29 -07003235 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003236 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003237
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003238 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003239 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 if (dn_log_port_id)
3241 if (*dn_log_port_id == logical_port_id)
3242 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003243 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244
3245 return NULL;
3246}
3247
3248static ssize_t ehea_probe_port(struct device *dev,
3249 struct device_attribute *attr,
3250 const char *buf, size_t count)
3251{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003252 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253 struct ehea_port *port;
3254 struct device_node *eth_dn = NULL;
3255 int i;
3256
3257 u32 logical_port_id;
3258
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003259 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260
3261 port = ehea_get_port(adapter, logical_port_id);
3262
3263 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003264 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3265 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003266 return -EINVAL;
3267 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003268
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003269 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3270
3271 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003272 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003273 return -EINVAL;
3274 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003275
Thomas Klein1211bb62007-04-26 11:56:43 +02003276 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003277 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003278 return -EIO;
3279 }
3280
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003281 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3282
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003283 of_node_put(eth_dn);
3284
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003285 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003286 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 if (!adapter->port[i]) {
3288 adapter->port[i] = port;
3289 break;
3290 }
3291
Joe Perches8c4877a2010-12-13 10:05:14 -08003292 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3293 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003294 } else {
3295 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003296 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003297 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003298
3299 return (ssize_t) count;
3300}
3301
3302static ssize_t ehea_remove_port(struct device *dev,
3303 struct device_attribute *attr,
3304 const char *buf, size_t count)
3305{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003306 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003307 struct ehea_port *port;
3308 int i;
3309 u32 logical_port_id;
3310
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003311 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003312
3313 port = ehea_get_port(adapter, logical_port_id);
3314
3315 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003316 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3317 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318
3319 ehea_shutdown_single_port(port);
3320
Doug Maxey508d2b52008-01-31 20:20:49 -06003321 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 if (adapter->port[i] == port) {
3323 adapter->port[i] = NULL;
3324 break;
3325 }
3326 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003327 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3328 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329 return -EINVAL;
3330 }
3331
Thomas Klein1211bb62007-04-26 11:56:43 +02003332 ehea_remove_adapter_mr(adapter);
3333
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003334 return (ssize_t) count;
3335}
3336
3337static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3338static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3339
Grant Likely2dc11582010-08-06 09:25:50 -06003340int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003341{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003342 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343 if (ret)
3344 goto out;
3345
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003346 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348 return ret;
3349}
3350
Grant Likely2dc11582010-08-06 09:25:50 -06003351void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003353 device_remove_file(&dev->dev, &dev_attr_probe_port);
3354 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003355}
3356
Grant Likely2dc11582010-08-06 09:25:50 -06003357static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003359{
3360 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003361 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003362 int ret;
3363
Grant Likely61c7a082010-04-13 16:12:29 -07003364 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003365 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003366 return -EINVAL;
3367 }
3368
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003369 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3370 if (!adapter) {
3371 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003372 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003373 goto out;
3374 }
3375
Thomas Klein44c82152007-07-11 16:32:00 +02003376 list_add(&adapter->list, &adapter_list);
3377
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003378 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003379
Grant Likely61c7a082010-04-13 16:12:29 -07003380 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003381 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003382 if (adapter_handle)
3383 adapter->handle = *adapter_handle;
3384
3385 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003386 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003387 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003388 ret = -ENODEV;
3389 goto out_free_ad;
3390 }
3391
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003392 adapter->pd = EHEA_PD_ID;
3393
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003394 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003396
3397 /* initialize adapter and ports */
3398 /* get adapter properties */
3399 ret = ehea_sense_adapter_attr(adapter);
3400 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003401 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003402 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003403 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003404
3405 adapter->neq = ehea_create_eq(adapter,
3406 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3407 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003408 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003409 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003410 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003411 }
3412
3413 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3414 (unsigned long)adapter);
3415
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003416 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003417 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003418 "ehea_neq", adapter);
3419 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003420 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003421 goto out_kill_eq;
3422 }
3423
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003424 ret = ehea_create_device_sysfs(dev);
3425 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003426 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003427
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003428 ret = ehea_setup_ports(adapter);
3429 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003430 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003431 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003432 }
3433
3434 ret = 0;
3435 goto out;
3436
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003437out_rem_dev_sysfs:
3438 ehea_remove_device_sysfs(dev);
3439
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003440out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003441 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003442
3443out_kill_eq:
3444 ehea_destroy_eq(adapter->neq);
3445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003446out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003447 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003448 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003449
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003451 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003452
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003453 return ret;
3454}
3455
Grant Likely2dc11582010-08-06 09:25:50 -06003456static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003457{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003458 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003459 int i;
3460
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003461 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003462 if (adapter->port[i]) {
3463 ehea_shutdown_single_port(adapter->port[i]);
3464 adapter->port[i] = NULL;
3465 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003466
3467 ehea_remove_device_sysfs(dev);
3468
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003469 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003470 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471
3472 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003473 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003474 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003476
Thomas Klein21eee2d2008-02-13 16:18:33 +01003477 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003479 return 0;
3480}
3481
Thomas Klein21eee2d2008-02-13 16:18:33 +01003482void ehea_crash_handler(void)
3483{
3484 int i;
3485
3486 if (ehea_fw_handles.arr)
3487 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3488 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3489 ehea_fw_handles.arr[i].fwh,
3490 FORCE_FREE);
3491
3492 if (ehea_bcmc_regs.arr)
3493 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3494 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3495 ehea_bcmc_regs.arr[i].port_id,
3496 ehea_bcmc_regs.arr[i].reg_type,
3497 ehea_bcmc_regs.arr[i].macaddr,
3498 0, H_DEREG_BCMC);
3499}
3500
Hannes Hering48cfb142008-05-07 14:43:36 +02003501static int ehea_mem_notifier(struct notifier_block *nb,
3502 unsigned long action, void *data)
3503{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003504 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003505 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003506
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003507 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003508
Hannes Hering48cfb142008-05-07 14:43:36 +02003509 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003510 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003511 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003512 /* Readd canceled memory block */
3513 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003514 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003515 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003516 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003517 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003518 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003519 break;
3520 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003521 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003522 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003523 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003524 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003525 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003526 break;
3527 default:
3528 break;
3529 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003530
3531 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003532 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003533
Thomas Kleina7c561f22010-04-20 23:11:31 +00003534out_unlock:
3535 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003536 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003537}
3538
3539static struct notifier_block ehea_mem_nb = {
3540 .notifier_call = ehea_mem_notifier,
3541};
3542
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003543static int ehea_reboot_notifier(struct notifier_block *nb,
3544 unsigned long action, void *unused)
3545{
3546 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003547 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003548 ibmebus_unregister_driver(&ehea_driver);
3549 }
3550 return NOTIFY_DONE;
3551}
3552
3553static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003554 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003555};
3556
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557static int check_module_parm(void)
3558{
3559 int ret = 0;
3560
3561 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3562 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003563 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003564 ret = -EINVAL;
3565 }
3566 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3567 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003568 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003569 ret = -EINVAL;
3570 }
3571 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3572 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003573 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574 ret = -EINVAL;
3575 }
3576 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3577 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003578 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003579 ret = -EINVAL;
3580 }
3581
3582 return ret;
3583}
3584
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003585static ssize_t ehea_show_capabilities(struct device_driver *drv,
3586 char *buf)
3587{
3588 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3589}
3590
3591static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3592 ehea_show_capabilities, NULL);
3593
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003594int __init ehea_module_init(void)
3595{
3596 int ret;
3597
Joe Perches8c4877a2010-12-13 10:05:14 -08003598 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003599
Thomas Klein21eee2d2008-02-13 16:18:33 +01003600 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3601 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3602
Daniel Walker9f71a562008-03-28 14:41:26 -07003603 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003604 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003605
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003606 ret = check_module_parm();
3607 if (ret)
3608 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003609
3610 ret = ehea_create_busmap();
3611 if (ret)
3612 goto out;
3613
Thomas Klein21eee2d2008-02-13 16:18:33 +01003614 ret = register_reboot_notifier(&ehea_reboot_nb);
3615 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003616 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003617
Hannes Hering48cfb142008-05-07 14:43:36 +02003618 ret = register_memory_notifier(&ehea_mem_nb);
3619 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003620 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003621
Joe Perchesc061b182010-08-23 18:20:03 +00003622 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003623 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003624 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003625
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003626 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003627 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003628 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003629 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003630 }
3631
3632 ret = driver_create_file(&ehea_driver.driver,
3633 &driver_attr_capabilities);
3634 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003635 pr_err("failed to register capabilities attribute, ret=%d\n",
3636 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003637 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003638 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003639
Thomas Klein21eee2d2008-02-13 16:18:33 +01003640 return ret;
3641
3642out3:
3643 ibmebus_unregister_driver(&ehea_driver);
3644out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003645 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003646 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003647 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003648out:
3649 return ret;
3650}
3651
3652static void __exit ehea_module_exit(void)
3653{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003654 int ret;
3655
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003656 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003657 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003658 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003659 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003660 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003661 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003662 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003663 kfree(ehea_fw_handles.arr);
3664 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003665 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003666}
3667
3668module_init(ehea_module_init);
3669module_exit(ehea_module_exit);