blob: be2cb4ab8b4f4b09cbd36b8c4f5fc3444466e05f [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;
Doug Maxey508d2b52008-01-31 20:20:49 -060064static int use_mcs;
65static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070066static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010067static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060068static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020069
70module_param(msg_level, int, 0);
71module_param(rq1_entries, int, 0);
72module_param(rq2_entries, int, 0);
73module_param(rq3_entries, int, 0);
74module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020075module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070077module_param(use_lro, int, 0);
78module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010079module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010081MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020083MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
84 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020085MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
88MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
91MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
94MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
95 "[2^x - 1], x = [6..14]. Default = "
96 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020097MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020098
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070099MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
100 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
101MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
102 "Default = 0");
103
Doug Maxey508d2b52008-01-31 20:20:49 -0600104static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200105static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800106static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700107static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100108struct ehea_fw_handle_array ehea_fw_handles;
109struct ehea_bcmc_reg_array ehea_bcmc_regs;
110
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Grant Likely2dc11582010-08-06 09:25:50 -0600112static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200113 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Grant Likely2dc11582010-08-06 09:25:50 -0600115static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200116
117static struct of_device_id ehea_device_table[] = {
118 {
119 .name = "lhea",
120 .compatible = "IBM,lhea",
121 },
122 {},
123};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100124MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200125
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000126static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700127 .driver = {
128 .name = "ehea",
129 .owner = THIS_MODULE,
130 .of_match_table = ehea_device_table,
131 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200132 .probe = ehea_probe_adapter,
133 .remove = ehea_remove,
134};
135
Doug Maxey508d2b52008-01-31 20:20:49 -0600136void ehea_dump(void *adr, int len, char *msg)
137{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200138 int x;
139 unsigned char *deb = adr;
140 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800141 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
142 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200143 deb += 16;
144 }
145}
146
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100147void ehea_schedule_port_reset(struct ehea_port *port)
148{
149 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
150 schedule_work(&port->reset_task);
151}
152
Thomas Klein21eee2d2008-02-13 16:18:33 +0100153static void ehea_update_firmware_handles(void)
154{
155 struct ehea_fw_handle_entry *arr = NULL;
156 struct ehea_adapter *adapter;
157 int num_adapters = 0;
158 int num_ports = 0;
159 int num_portres = 0;
160 int i = 0;
161 int num_fw_handles, k, l;
162
163 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700164 mutex_lock(&ehea_fw_handles.lock);
165
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 list_for_each_entry(adapter, &adapter_list, list) {
167 num_adapters++;
168
169 for (k = 0; k < EHEA_MAX_PORTS; k++) {
170 struct ehea_port *port = adapter->port[k];
171
172 if (!port || (port->state != EHEA_PORT_UP))
173 continue;
174
175 num_ports++;
176 num_portres += port->num_def_qps + port->num_add_tx_qps;
177 }
178 }
179
180 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
181 num_ports * EHEA_NUM_PORT_FW_HANDLES +
182 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
183
184 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000185 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700187 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100188 } else
189 goto out_update;
190
191 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700192 if (num_adapters == 0)
193 break;
194
Thomas Klein21eee2d2008-02-13 16:18:33 +0100195 for (k = 0; k < EHEA_MAX_PORTS; k++) {
196 struct ehea_port *port = adapter->port[k];
197
Joe Perches8e95a202009-12-03 07:58:21 +0000198 if (!port || (port->state != EHEA_PORT_UP) ||
199 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100200 continue;
201
202 for (l = 0;
203 l < port->num_def_qps + port->num_add_tx_qps;
204 l++) {
205 struct ehea_port_res *pr = &port->port_res[l];
206
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->qp->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->send_cq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->recv_cq->fw_handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->eq->fw_handle;
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = pr->send_mr.handle;
217 arr[i].adh = adapter->handle;
218 arr[i++].fwh = pr->recv_mr.handle;
219 }
220 arr[i].adh = adapter->handle;
221 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700222 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100223 }
224
225 arr[i].adh = adapter->handle;
226 arr[i++].fwh = adapter->neq->fw_handle;
227
228 if (adapter->mr.handle) {
229 arr[i].adh = adapter->handle;
230 arr[i++].fwh = adapter->mr.handle;
231 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 }
234
235out_update:
236 kfree(ehea_fw_handles.arr);
237 ehea_fw_handles.arr = arr;
238 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700239out:
240 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100241}
242
243static void ehea_update_bcmc_registrations(void)
244{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700245 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100246 struct ehea_bcmc_reg_entry *arr = NULL;
247 struct ehea_adapter *adapter;
248 struct ehea_mc_list *mc_entry;
249 int num_registrations = 0;
250 int i = 0;
251 int k;
252
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700253 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
254
Thomas Klein21eee2d2008-02-13 16:18:33 +0100255 /* Determine number of registrations */
256 list_for_each_entry(adapter, &adapter_list, list)
257 for (k = 0; k < EHEA_MAX_PORTS; k++) {
258 struct ehea_port *port = adapter->port[k];
259
260 if (!port || (port->state != EHEA_PORT_UP))
261 continue;
262
263 num_registrations += 2; /* Broadcast registrations */
264
265 list_for_each_entry(mc_entry, &port->mc_list->list,list)
266 num_registrations += 2;
267 }
268
269 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000270 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100271 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700272 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 } else
274 goto out_update;
275
276 list_for_each_entry(adapter, &adapter_list, list) {
277 for (k = 0; k < EHEA_MAX_PORTS; k++) {
278 struct ehea_port *port = adapter->port[k];
279
280 if (!port || (port->state != EHEA_PORT_UP))
281 continue;
282
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700283 if (num_registrations == 0)
284 goto out_update;
285
Thomas Klein21eee2d2008-02-13 16:18:33 +0100286 arr[i].adh = adapter->handle;
287 arr[i].port_id = port->logical_port_id;
288 arr[i].reg_type = EHEA_BCMC_BROADCAST |
289 EHEA_BCMC_UNTAGGED;
290 arr[i++].macaddr = port->mac_addr;
291
292 arr[i].adh = adapter->handle;
293 arr[i].port_id = port->logical_port_id;
294 arr[i].reg_type = EHEA_BCMC_BROADCAST |
295 EHEA_BCMC_VLANID_ALL;
296 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700297 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100298
299 list_for_each_entry(mc_entry,
300 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700301 if (num_registrations == 0)
302 goto out_update;
303
Thomas Klein21eee2d2008-02-13 16:18:33 +0100304 arr[i].adh = adapter->handle;
305 arr[i].port_id = port->logical_port_id;
306 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
307 EHEA_BCMC_MULTICAST |
308 EHEA_BCMC_UNTAGGED;
309 arr[i++].macaddr = mc_entry->macaddr;
310
311 arr[i].adh = adapter->handle;
312 arr[i].port_id = port->logical_port_id;
313 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
314 EHEA_BCMC_MULTICAST |
315 EHEA_BCMC_VLANID_ALL;
316 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700317 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100318 }
319 }
320 }
321
322out_update:
323 kfree(ehea_bcmc_regs.arr);
324 ehea_bcmc_regs.arr = arr;
325 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700326out:
327 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100328}
329
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200330static struct net_device_stats *ehea_get_stats(struct net_device *dev)
331{
332 struct ehea_port *port = netdev_priv(dev);
333 struct net_device_stats *stats = &port->stats;
334 struct hcp_ehea_port_cb2 *cb2;
Breno Leitaoce45b872010-10-27 08:45:14 +0000335 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 int i;
337
338 memset(stats, 0, sizeof(*stats));
339
Brian King3d8009c2010-06-30 11:59:12 +0000340 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200341 if (!cb2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800342 netdev_err(dev, "no mem for cb2\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200343 goto out;
344 }
345
346 hret = ehea_h_query_ehea_port(port->adapter->handle,
347 port->logical_port_id,
348 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
349 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800350 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200351 goto out_herr;
352 }
353
354 if (netif_msg_hw(port))
355 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
356
357 rx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000358 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 rx_packets += port->port_res[i].rx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000360 rx_bytes += port->port_res[i].rx_bytes;
361 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200362
Thomas Klein7393b872007-11-21 17:37:58 +0100363 tx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000364 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Thomas Klein7393b872007-11-21 17:37:58 +0100365 tx_packets += port->port_res[i].tx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000366 tx_bytes += port->port_res[i].tx_bytes;
367 }
Thomas Klein7393b872007-11-21 17:37:58 +0100368
369 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370 stats->multicast = cb2->rxmcp;
371 stats->rx_errors = cb2->rxuerr;
Breno Leitaoce45b872010-10-27 08:45:14 +0000372 stats->rx_bytes = rx_bytes;
373 stats->tx_bytes = tx_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374 stats->rx_packets = rx_packets;
375
376out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800377 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200378out:
379 return stats;
380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800405 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200406 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200407 break;
408 }
409 }
410 index--;
411 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200414
415 if (adder == 0)
416 return;
417
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200419 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420}
421
Thomas Kleine2878802009-01-21 14:45:57 -0800422static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
425 struct net_device *dev = pr->port->netdev;
426 int i;
427
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000428 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800429 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000430 return;
431 }
432
433 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000435 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800436 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800437 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439 }
440 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000441 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200442}
443
444static int ehea_refill_rq_def(struct ehea_port_res *pr,
445 struct ehea_q_skb_arr *q_skba, int rq_nr,
446 int num_wqes, int wqe_type, int packet_size)
447{
448 struct net_device *dev = pr->port->netdev;
449 struct ehea_qp *qp = pr->qp;
450 struct sk_buff **skb_arr = q_skba->arr;
451 struct ehea_rwqe *rwqe;
452 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 int ret = 0;
455
456 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
460 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463
464 index = q_skba->index;
465 max_index_mask = q_skba->len - 1;
466 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200467 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000468 struct sk_buff *skb;
469
470 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800473 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800474 netdev_info(pr->port->netdev,
475 "rq%i ran dry - no mem for skb\n",
476 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800477 ret = -ENOMEM;
478 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 break;
480 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481
482 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200483 tmp_addr = ehea_map_vaddr(skb->data);
484 if (tmp_addr == -1) {
485 dev_kfree_skb(skb);
486 q_skba->os_skbs = fill_wqes - i;
487 ret = 0;
488 break;
489 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490
491 rwqe = ehea_get_next_rwqe(qp, rq_nr);
492 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200493 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200495 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496 rwqe->sg_list[0].len = packet_size;
497 rwqe->data_segments = 1;
498
499 index++;
500 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200501 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 }
Thomas Klein44c82152007-07-11 16:32:00 +0200503
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200505 if (adder == 0)
506 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200507
508 /* Ring doorbell */
509 iosync();
510 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200511 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200513 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200514out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515 return ret;
516}
517
518
519static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
520{
521 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
522 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000523 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524}
525
526
527static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
528{
529 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
530 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200532}
533
534static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
535{
536 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
537 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
538 return 0;
539 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
540 (cqe->header_length == 0))
541 return 0;
542 return -EINVAL;
543}
544
545static inline void ehea_fill_skb(struct net_device *dev,
546 struct sk_buff *skb, struct ehea_cqe *cqe)
547{
548 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
549
550 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200551 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000552
553 /* The packet was not an IPV4 packet so a complemented checksum was
554 calculated. The value is found in the Internet Checksum field. */
555 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
556 skb->ip_summed = CHECKSUM_COMPLETE;
557 skb->csum = csum_unfold(~cqe->inet_checksum_value);
558 } else
559 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560}
561
562static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
563 int arr_len,
564 struct ehea_cqe *cqe)
565{
566 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
567 struct sk_buff *skb;
568 void *pref;
569 int x;
570
571 x = skb_index + 1;
572 x &= (arr_len - 1);
573
574 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700575 if (pref) {
576 prefetchw(pref);
577 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578
Hannes Hering0b2febf2009-05-04 11:06:37 -0700579 pref = (skb_array[x]->data);
580 prefetch(pref);
581 prefetch(pref + EHEA_CACHE_LINE);
582 prefetch(pref + EHEA_CACHE_LINE * 2);
583 prefetch(pref + EHEA_CACHE_LINE * 3);
584 }
585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200586 skb = skb_array[skb_index];
587 skb_array[skb_index] = NULL;
588 return skb;
589}
590
591static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
592 int arr_len, int wqe_index)
593{
594 struct sk_buff *skb;
595 void *pref;
596 int x;
597
598 x = wqe_index + 1;
599 x &= (arr_len - 1);
600
601 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700602 if (pref) {
603 prefetchw(pref);
604 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200605
Hannes Hering0b2febf2009-05-04 11:06:37 -0700606 pref = (skb_array[x]->data);
607 prefetchw(pref);
608 prefetchw(pref + EHEA_CACHE_LINE);
609 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200610
611 skb = skb_array[wqe_index];
612 skb_array[wqe_index] = NULL;
613 return skb;
614}
615
616static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
617 struct ehea_cqe *cqe, int *processed_rq2,
618 int *processed_rq3)
619{
620 struct sk_buff *skb;
621
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100622 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
623 pr->p_stats.err_tcp_cksum++;
624 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
625 pr->p_stats.err_ip_cksum++;
626 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
627 pr->p_stats.err_frame_crc++;
628
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200629 if (rq == 2) {
630 *processed_rq2 += 1;
631 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
632 dev_kfree_skb(skb);
633 } else if (rq == 3) {
634 *processed_rq3 += 1;
635 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
636 dev_kfree_skb(skb);
637 }
638
639 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100640 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800641 pr_err("Critical receive error for QP %d. Resetting port.\n",
642 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100643 ehea_dump(cqe, sizeof(*cqe), "CQE");
644 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100645 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200646 return 1;
647 }
648
649 return 0;
650}
651
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700652static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
653 void **tcph, u64 *hdr_flags, void *priv)
654{
655 struct ehea_cqe *cqe = priv;
656 unsigned int ip_len;
657 struct iphdr *iph;
658
659 /* non tcp/udp packets */
660 if (!cqe->header_length)
661 return -1;
662
663 /* non tcp packet */
664 skb_reset_network_header(skb);
665 iph = ip_hdr(skb);
666 if (iph->protocol != IPPROTO_TCP)
667 return -1;
668
669 ip_len = ip_hdrlen(skb);
670 skb_set_transport_header(skb, ip_len);
671 *tcph = tcp_hdr(skb);
672
673 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700674 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700675 return -1;
676
677 *hdr_flags = LRO_IPV4 | LRO_TCP;
678 *iphdr = iph;
679
680 return 0;
681}
682
683static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
684 struct sk_buff *skb)
685{
Jiri Pirkob4950092011-07-20 04:54:07 +0000686 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
687 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700688
Jiri Pirkob4950092011-07-20 04:54:07 +0000689 if (skb->dev->features & NETIF_F_LRO)
690 lro_receive_skb(&pr->lro_mgr, skb, cqe);
691 else
692 netif_receive_skb(skb);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700693}
694
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700695static int ehea_proc_rwqes(struct net_device *dev,
696 struct ehea_port_res *pr,
697 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100699 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 struct ehea_qp *qp = pr->qp;
701 struct ehea_cqe *cqe;
702 struct sk_buff *skb;
703 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
704 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
705 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
706 int skb_arr_rq1_len = pr->rq1_skba.len;
707 int skb_arr_rq2_len = pr->rq2_skba.len;
708 int skb_arr_rq3_len = pr->rq3_skba.len;
709 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000710 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700711 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712
713 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
714 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200715
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700717 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200718 ehea_inc_rq1(qp);
719 processed_rq1++;
720 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200721 if (netif_msg_rx_status(port))
722 ehea_dump(cqe, sizeof(*cqe), "CQE");
723
724 last_wqe_index = wqe_index;
725 rmb();
726 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600727 if (rq == 1) {
728 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 skb = get_skb_by_index_ll(skb_arr_rq1,
730 skb_arr_rq1_len,
731 wqe_index);
732 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800733 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800734 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100735
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700736 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000738 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800739 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200740 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000741 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200742 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600743 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200744 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700745 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600746 } else if (rq == 2) {
747 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 skb = get_skb_by_index(skb_arr_rq2,
749 skb_arr_rq2_len, cqe);
750 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800751 netif_err(port, rx_err, dev,
752 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200753 break;
754 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700755 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600757 } else {
758 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200759 skb = get_skb_by_index(skb_arr_rq3,
760 skb_arr_rq3_len, cqe);
761 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800762 netif_err(port, rx_err, dev,
763 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200764 break;
765 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700766 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 processed_rq3++;
768 }
769
Breno Leitaoce45b872010-10-27 08:45:14 +0000770 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700771 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100772 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100773 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200774 port_reset = ehea_treat_poll_error(pr, rq, cqe,
775 &processed_rq2,
776 &processed_rq3);
777 if (port_reset)
778 break;
779 }
780 cqe = ehea_poll_rq1(qp, &wqe_index);
781 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800782 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700783 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200785 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000786 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200787
788 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
789 ehea_refill_rq2(pr, processed_rq2);
790 ehea_refill_rq3(pr, processed_rq3);
791
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700792 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200793}
794
Andre Detsch2928db42010-08-17 05:49:12 +0000795#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
796
797static void reset_sq_restart_flag(struct ehea_port *port)
798{
799 int i;
800
801 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
802 struct ehea_port_res *pr = &port->port_res[i];
803 pr->sq_restart_flag = 0;
804 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000805 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000806}
807
808static void check_sqs(struct ehea_port *port)
809{
810 struct ehea_swqe *swqe;
811 int swqe_index;
812 int i, k;
813
814 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
815 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000816 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000817 k = 0;
818 swqe = ehea_get_swqe(pr->qp, &swqe_index);
819 memset(swqe, 0, SWQE_HEADER_SIZE);
820 atomic_dec(&pr->swqe_avail);
821
822 swqe->tx_control |= EHEA_SWQE_PURGE;
823 swqe->wr_id = SWQE_RESTART_CHECK;
824 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
825 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
826 swqe->immediate_data_length = 80;
827
828 ehea_post_swqe(pr->qp, swqe);
829
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000830 ret = wait_event_timeout(port->restart_wq,
831 pr->sq_restart_flag == 0,
832 msecs_to_jiffies(100));
833
834 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800835 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000836 ehea_schedule_port_reset(pr->port);
837 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000838 }
839 }
Andre Detsch2928db42010-08-17 05:49:12 +0000840}
841
842
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100843static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200844{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100845 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200846 struct ehea_cq *send_cq = pr->send_cq;
847 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100848 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200849 int cqe_counter = 0;
850 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100851 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200852 unsigned long flags;
853
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100854 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600855 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100856 ehea_inc_cq(send_cq);
857
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200858 cqe_counter++;
859 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000860
861 if (cqe->wr_id == SWQE_RESTART_CHECK) {
862 pr->sq_restart_flag = 1;
863 swqe_av++;
864 break;
865 }
866
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200867 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800868 pr_err("Bad send completion status=0x%04X\n",
869 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000870
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200871 if (netif_msg_tx_err(pr->port))
872 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000873
874 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800875 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000876 ehea_schedule_port_reset(pr->port);
877 break;
878 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 }
880
881 if (netif_msg_tx_done(pr->port))
882 ehea_dump(cqe, sizeof(*cqe), "CQE");
883
884 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100885 == EHEA_SWQE2_TYPE)) {
886
887 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
888 skb = pr->sq_skba.arr[index];
889 dev_kfree_skb(skb);
890 pr->sq_skba.arr[index] = NULL;
891 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200892
893 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
894 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100895
896 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700897 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200898
899 ehea_update_feca(send_cq, cqe_counter);
900 atomic_add(swqe_av, &pr->swqe_avail);
901
902 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200904 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
905 >= pr->swqe_refill_th)) {
906 netif_wake_queue(pr->port->netdev);
907 pr->queue_stopped = 0;
908 }
909 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000910 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100912 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200913}
914
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100915#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700916#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100917
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700918static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200919{
Doug Maxey508d2b52008-01-31 20:20:49 -0600920 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
921 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700922 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100923 struct ehea_cqe *cqe;
924 struct ehea_cqe *cqe_skb = NULL;
925 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700926 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100927
928 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100930
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700931 if (!force_irq)
932 rx += ehea_proc_rwqes(dev, pr, budget - rx);
933
934 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100935 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800937 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938 ehea_reset_cq_ep(pr->recv_cq);
939 ehea_reset_cq_ep(pr->send_cq);
940 ehea_reset_cq_n1(pr->recv_cq);
941 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000942 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100943 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
944 cqe_skb = ehea_poll_cq(pr->send_cq);
945
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100946 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700947 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100948
Ben Hutchings288379f2009-01-19 16:43:59 -0800949 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700950 return rx;
951
952 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
953 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100954 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100955
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700956 pr->poll_counter++;
957 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200958}
959
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200960#ifdef CONFIG_NET_POLL_CONTROLLER
961static void ehea_netpoll(struct net_device *dev)
962{
963 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200965
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700966 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800967 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200968}
969#endif
970
David Howells7d12e782006-10-05 14:55:46 +0100971static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200972{
973 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100974
Ben Hutchings288379f2009-01-19 16:43:59 -0800975 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100976
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200977 return IRQ_HANDLED;
978}
979
David Howells7d12e782006-10-05 14:55:46 +0100980static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200981{
982 struct ehea_port *port = param;
983 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100984 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000986 u64 resource_type, aer, aerr;
987 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988
989 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100990
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200991 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800993 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
994 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100995
996 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000997
998 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
999 &aer, &aerr);
1000
1001 if (resource_type == EHEA_AER_RESTYPE_QP) {
1002 if ((aer & EHEA_AER_RESET_MASK) ||
1003 (aerr & EHEA_AERR_RESET_MASK))
1004 reset_port = 1;
1005 } else
1006 reset_port = 1; /* Reset in case of CQ or EQ error */
1007
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001008 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001009 }
1010
Thomas Kleinea96cea2010-04-20 23:10:55 +00001011 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001012 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001013 ehea_schedule_port_reset(port);
1014 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001015
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001016 return IRQ_HANDLED;
1017}
1018
1019static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1020 int logical_port)
1021{
1022 int i;
1023
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001024 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001025 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001026 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001027 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001028 return NULL;
1029}
1030
1031int ehea_sense_port_attr(struct ehea_port *port)
1032{
1033 int ret;
1034 u64 hret;
1035 struct hcp_ehea_port_cb0 *cb0;
1036
Doug Maxey508d2b52008-01-31 20:20:49 -06001037 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001038 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001039 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001040 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001041 ret = -ENOMEM;
1042 goto out;
1043 }
1044
1045 hret = ehea_h_query_ehea_port(port->adapter->handle,
1046 port->logical_port_id, H_PORT_CB0,
1047 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1048 cb0);
1049 if (hret != H_SUCCESS) {
1050 ret = -EIO;
1051 goto out_free;
1052 }
1053
1054 /* MAC address */
1055 port->mac_addr = cb0->port_mac_addr << 16;
1056
Doug Maxey508d2b52008-01-31 20:20:49 -06001057 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001058 ret = -EADDRNOTAVAIL;
1059 goto out_free;
1060 }
1061
1062 /* Port speed */
1063 switch (cb0->port_speed) {
1064 case H_SPEED_10M_H:
1065 port->port_speed = EHEA_SPEED_10M;
1066 port->full_duplex = 0;
1067 break;
1068 case H_SPEED_10M_F:
1069 port->port_speed = EHEA_SPEED_10M;
1070 port->full_duplex = 1;
1071 break;
1072 case H_SPEED_100M_H:
1073 port->port_speed = EHEA_SPEED_100M;
1074 port->full_duplex = 0;
1075 break;
1076 case H_SPEED_100M_F:
1077 port->port_speed = EHEA_SPEED_100M;
1078 port->full_duplex = 1;
1079 break;
1080 case H_SPEED_1G_F:
1081 port->port_speed = EHEA_SPEED_1G;
1082 port->full_duplex = 1;
1083 break;
1084 case H_SPEED_10G_F:
1085 port->port_speed = EHEA_SPEED_10G;
1086 port->full_duplex = 1;
1087 break;
1088 default:
1089 port->port_speed = 0;
1090 port->full_duplex = 0;
1091 break;
1092 }
1093
Thomas Kleine919b592007-01-22 12:53:20 +01001094 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001095 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001096
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001097 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001098 if (use_mcs)
1099 port->num_def_qps = cb0->num_default_qps;
1100 else
1101 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001102
1103 if (!port->num_def_qps) {
1104 ret = -EINVAL;
1105 goto out_free;
1106 }
1107
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001108 port->num_tx_qps = num_tx_qps;
1109
1110 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001111 port->num_add_tx_qps = 0;
1112 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001113 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001114
1115 ret = 0;
1116out_free:
1117 if (ret || netif_msg_probe(port))
1118 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001119 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001120out:
1121 return ret;
1122}
1123
1124int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1125{
1126 struct hcp_ehea_port_cb4 *cb4;
1127 u64 hret;
1128 int ret = 0;
1129
Thomas Klein3faf2692009-01-21 14:45:33 -08001130 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001131 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001132 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001133 ret = -ENOMEM;
1134 goto out;
1135 }
1136
1137 cb4->port_speed = port_speed;
1138
1139 netif_carrier_off(port->netdev);
1140
1141 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1142 port->logical_port_id,
1143 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1144 if (hret == H_SUCCESS) {
1145 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1146
1147 hret = ehea_h_query_ehea_port(port->adapter->handle,
1148 port->logical_port_id,
1149 H_PORT_CB4, H_PORT_CB4_SPEED,
1150 cb4);
1151 if (hret == H_SUCCESS) {
1152 switch (cb4->port_speed) {
1153 case H_SPEED_10M_H:
1154 port->port_speed = EHEA_SPEED_10M;
1155 port->full_duplex = 0;
1156 break;
1157 case H_SPEED_10M_F:
1158 port->port_speed = EHEA_SPEED_10M;
1159 port->full_duplex = 1;
1160 break;
1161 case H_SPEED_100M_H:
1162 port->port_speed = EHEA_SPEED_100M;
1163 port->full_duplex = 0;
1164 break;
1165 case H_SPEED_100M_F:
1166 port->port_speed = EHEA_SPEED_100M;
1167 port->full_duplex = 1;
1168 break;
1169 case H_SPEED_1G_F:
1170 port->port_speed = EHEA_SPEED_1G;
1171 port->full_duplex = 1;
1172 break;
1173 case H_SPEED_10G_F:
1174 port->port_speed = EHEA_SPEED_10G;
1175 port->full_duplex = 1;
1176 break;
1177 default:
1178 port->port_speed = 0;
1179 port->full_duplex = 0;
1180 break;
1181 }
1182 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001183 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184 ret = -EIO;
1185 }
1186 } else {
1187 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001189 ret = -EPERM;
1190 } else {
1191 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001192 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001193 }
1194 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001195 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1196 netif_carrier_on(port->netdev);
1197
Thomas Klein3faf2692009-01-21 14:45:33 -08001198 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001199out:
1200 return ret;
1201}
1202
1203static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1204{
1205 int ret;
1206 u8 ec;
1207 u8 portnum;
1208 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001209 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001210
1211 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1212 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1213 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001214 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001215
1216 switch (ec) {
1217 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1218
1219 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001221 break;
1222 }
1223
1224 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001226 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001228 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229 break;
1230 }
1231
Joe Perches8c4877a2010-12-13 10:05:14 -08001232 netif_info(port, link, dev,
1233 "Logical port up: %dMbps %s Duplex\n",
1234 port->port_speed,
1235 port->full_duplex == 1 ?
1236 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001237
Joe Perches8c4877a2010-12-13 10:05:14 -08001238 netif_carrier_on(dev);
1239 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001240 }
1241 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001242 if (netif_carrier_ok(dev)) {
1243 netif_info(port, link, dev,
1244 "Logical port down\n");
1245 netif_carrier_off(dev);
1246 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 }
1248
1249 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001250 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001251 netif_info(port, link, dev,
1252 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001253 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001254 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001255 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001256 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001257 netif_info(port, link, dev,
1258 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001259 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001260 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 }
1262
1263 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001264 netdev_info(dev,
1265 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001267 netdev_info(dev,
1268 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269
1270 break;
1271 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001272 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 break;
1274 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001275 netdev_info(dev, "Port malfunction\n");
1276 netif_carrier_off(dev);
1277 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278 break;
1279 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001280 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 break;
1282 }
1283}
1284
1285static void ehea_neq_tasklet(unsigned long data)
1286{
Doug Maxey508d2b52008-01-31 20:20:49 -06001287 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 struct ehea_eqe *eqe;
1289 u64 event_mask;
1290
1291 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001292 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293
1294 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001295 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001296 ehea_parse_eqe(adapter, eqe->entry);
1297 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001298 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299 }
1300
1301 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1302 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1303 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1304
1305 ehea_h_reset_events(adapter->handle,
1306 adapter->neq->fw_handle, event_mask);
1307}
1308
David Howells7d12e782006-10-05 14:55:46 +01001309static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310{
1311 struct ehea_adapter *adapter = param;
1312 tasklet_hi_schedule(&adapter->neq_tasklet);
1313 return IRQ_HANDLED;
1314}
1315
1316
1317static int ehea_fill_port_res(struct ehea_port_res *pr)
1318{
1319 int ret;
1320 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1321
Breno Leitaof76957f2011-01-11 07:45:57 +00001322 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001323
Thomas Kleine2878802009-01-21 14:45:57 -08001324 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001325
1326 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1327
1328 return ret;
1329}
1330
1331static int ehea_reg_interrupts(struct net_device *dev)
1332{
1333 struct ehea_port *port = netdev_priv(dev);
1334 struct ehea_port_res *pr;
1335 int i, ret;
1336
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337
1338 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1339 dev->name);
1340
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001341 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001342 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001343 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001345 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1346 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 goto out_free_qpeq;
1348 }
1349
Joe Perches8c4877a2010-12-13 10:05:14 -08001350 netif_info(port, ifup, dev,
1351 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1352 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001353
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001354
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1356 pr = &port->port_res[i];
1357 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001358 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001359 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001360 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001361 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001362 pr);
1363 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001364 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1365 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 goto out_free_req;
1367 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001368 netif_info(port, ifup, dev,
1369 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1370 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001371 }
1372out:
1373 return ret;
1374
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001375
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376out_free_req:
1377 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001379 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001380 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001381
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001382out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001383 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001387
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001388}
1389
1390static void ehea_free_interrupts(struct net_device *dev)
1391{
1392 struct ehea_port *port = netdev_priv(dev);
1393 struct ehea_port_res *pr;
1394 int i;
1395
1396 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1399 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001400 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001401 netif_info(port, intr, dev,
1402 "free send irq for res %d with handle 0x%X\n",
1403 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001404 }
1405
1406 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001407 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001408 netif_info(port, intr, dev,
1409 "associated event interrupt for handle 0x%X freed\n",
1410 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001411}
1412
1413static int ehea_configure_port(struct ehea_port *port)
1414{
1415 int ret, i;
1416 u64 hret, mask;
1417 struct hcp_ehea_port_cb0 *cb0;
1418
1419 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001420 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001421 if (!cb0)
1422 goto out;
1423
1424 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1425 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1426 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1427 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1428 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1429 PXLY_RC_VLAN_FILTER)
1430 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1431
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001432 for (i = 0; i < port->num_mcs; i++)
1433 if (use_mcs)
1434 cb0->default_qpn_arr[i] =
1435 port->port_res[i].qp->init_attr.qp_nr;
1436 else
1437 cb0->default_qpn_arr[i] =
1438 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001439
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001440 if (netif_msg_ifup(port))
1441 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1442
1443 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1444 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1445
1446 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1447 port->logical_port_id,
1448 H_PORT_CB0, mask, cb0);
1449 ret = -EIO;
1450 if (hret != H_SUCCESS)
1451 goto out_free;
1452
1453 ret = 0;
1454
1455out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001456 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001457out:
1458 return ret;
1459}
1460
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001461int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001462{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001463 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001464 struct ehea_adapter *adapter = pr->port->adapter;
1465
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001466 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1467 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001468 goto out;
1469
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001470 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1471 if (ret)
1472 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001473
1474 return 0;
1475
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001476out_free:
1477 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001479 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480 return -EIO;
1481}
1482
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001483int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484{
Joe Perches8e95a202009-12-03 07:58:21 +00001485 if ((ehea_rem_mr(&pr->send_mr)) ||
1486 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001487 return -EIO;
1488 else
1489 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490}
1491
1492static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1493{
Doug Maxey508d2b52008-01-31 20:20:49 -06001494 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001496 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001497 if (!q_skba->arr)
1498 return -ENOMEM;
1499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500 q_skba->len = max_q_entries;
1501 q_skba->index = 0;
1502 q_skba->os_skbs = 0;
1503
1504 return 0;
1505}
1506
1507static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1508 struct port_res_cfg *pr_cfg, int queue_token)
1509{
1510 struct ehea_adapter *adapter = port->adapter;
1511 enum ehea_eq_type eq_type = EHEA_EQ;
1512 struct ehea_qp_init_attr *init_attr = NULL;
1513 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001514 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1515
1516 tx_bytes = pr->tx_bytes;
1517 tx_packets = pr->tx_packets;
1518 rx_bytes = pr->rx_bytes;
1519 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001520
1521 memset(pr, 0, sizeof(struct ehea_port_res));
1522
Breno Leitaoce45b872010-10-27 08:45:14 +00001523 pr->tx_bytes = rx_bytes;
1524 pr->tx_packets = tx_packets;
1525 pr->rx_bytes = rx_bytes;
1526 pr->rx_packets = rx_packets;
1527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001528 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001529 spin_lock_init(&pr->xmit_lock);
1530 spin_lock_init(&pr->netif_queue);
1531
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001532 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1533 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001534 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001535 goto out_free;
1536 }
1537
1538 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001539 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540 port->logical_port_id);
1541 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001542 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 goto out_free;
1544 }
1545
1546 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001547 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001548 port->logical_port_id);
1549 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001550 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 goto out_free;
1552 }
1553
1554 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001555 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1556 pr->send_cq->attr.act_nr_of_cqes,
1557 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558
1559 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1560 if (!init_attr) {
1561 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001562 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 goto out_free;
1564 }
1565
1566 init_attr->low_lat_rq1 = 1;
1567 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1568 init_attr->rq_count = 3;
1569 init_attr->qp_token = queue_token;
1570 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1571 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1572 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1573 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1574 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1575 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1576 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1577 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1578 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1579 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1580 init_attr->port_nr = port->logical_port_id;
1581 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1582 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1583 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1584
1585 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1586 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001587 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001588 ret = -EIO;
1589 goto out_free;
1590 }
1591
1592 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001593 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",
1594 init_attr->qp_nr,
1595 init_attr->act_nr_send_wqes,
1596 init_attr->act_nr_rwqes_rq1,
1597 init_attr->act_nr_rwqes_rq2,
1598 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599
Thomas Klein44fb3122008-04-04 15:04:53 +02001600 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1601
1602 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001603 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1604 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1605 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1606 if (ret)
1607 goto out_free;
1608
1609 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1610 if (ehea_gen_smrs(pr) != 0) {
1611 ret = -EIO;
1612 goto out_free;
1613 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001614
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001615 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1616
1617 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001618
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001619 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001620
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001621 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1622 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1623 pr->lro_mgr.lro_arr = pr->lro_desc;
1624 pr->lro_mgr.get_skb_header = get_skb_hdr;
1625 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1626 pr->lro_mgr.dev = port->netdev;
1627 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1628 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1629
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630 ret = 0;
1631 goto out;
1632
1633out_free:
1634 kfree(init_attr);
1635 vfree(pr->sq_skba.arr);
1636 vfree(pr->rq1_skba.arr);
1637 vfree(pr->rq2_skba.arr);
1638 vfree(pr->rq3_skba.arr);
1639 ehea_destroy_qp(pr->qp);
1640 ehea_destroy_cq(pr->send_cq);
1641 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001642 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643out:
1644 return ret;
1645}
1646
1647static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1648{
1649 int ret, i;
1650
Hannes Hering357eb462009-08-04 11:48:39 -07001651 if (pr->qp)
1652 netif_napi_del(&pr->napi);
1653
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 ret = ehea_destroy_qp(pr->qp);
1655
1656 if (!ret) {
1657 ehea_destroy_cq(pr->send_cq);
1658 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001659 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001660
1661 for (i = 0; i < pr->rq1_skba.len; i++)
1662 if (pr->rq1_skba.arr[i])
1663 dev_kfree_skb(pr->rq1_skba.arr[i]);
1664
1665 for (i = 0; i < pr->rq2_skba.len; i++)
1666 if (pr->rq2_skba.arr[i])
1667 dev_kfree_skb(pr->rq2_skba.arr[i]);
1668
1669 for (i = 0; i < pr->rq3_skba.len; i++)
1670 if (pr->rq3_skba.arr[i])
1671 dev_kfree_skb(pr->rq3_skba.arr[i]);
1672
1673 for (i = 0; i < pr->sq_skba.len; i++)
1674 if (pr->sq_skba.arr[i])
1675 dev_kfree_skb(pr->sq_skba.arr[i]);
1676
1677 vfree(pr->rq1_skba.arr);
1678 vfree(pr->rq2_skba.arr);
1679 vfree(pr->rq3_skba.arr);
1680 vfree(pr->sq_skba.arr);
1681 ret = ehea_rem_smrs(pr);
1682 }
1683 return ret;
1684}
1685
1686/*
1687 * The write_* functions store information in swqe which is used by
1688 * the hardware to calculate the ip/tcp/udp checksum
1689 */
1690
1691static inline void write_ip_start_end(struct ehea_swqe *swqe,
1692 const struct sk_buff *skb)
1693{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001694 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001695 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001696}
1697
1698static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1699 const struct sk_buff *skb)
1700{
1701 swqe->tcp_offset =
1702 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1703
1704 swqe->tcp_end = (u16)skb->len - 1;
1705}
1706
1707static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1708 const struct sk_buff *skb)
1709{
1710 swqe->tcp_offset =
1711 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1712
1713 swqe->tcp_end = (u16)skb->len - 1;
1714}
1715
1716
1717static void write_swqe2_TSO(struct sk_buff *skb,
1718 struct ehea_swqe *swqe, u32 lkey)
1719{
1720 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1721 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001722 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001723 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001724
1725 /* Packet is TCP with TSO enabled */
1726 swqe->tx_control |= EHEA_SWQE_TSO;
1727 swqe->mss = skb_shinfo(skb)->gso_size;
1728 /* copy only eth/ip/tcp headers to immediate data and
1729 * the rest of skb->data to sg1entry
1730 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001731 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001732
Eric Dumazete743d312010-04-14 15:59:40 -07001733 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001734
1735 if (skb_data_size >= headersize) {
1736 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001737 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001738 swqe->immediate_data_length = headersize;
1739
1740 if (skb_data_size > headersize) {
1741 /* set sg1entry data */
1742 sg1entry->l_key = lkey;
1743 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001744 sg1entry->vaddr =
1745 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746 swqe->descriptors++;
1747 }
1748 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001749 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750}
1751
1752static void write_swqe2_nonTSO(struct sk_buff *skb,
1753 struct ehea_swqe *swqe, u32 lkey)
1754{
Eric Dumazete743d312010-04-14 15:59:40 -07001755 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001756 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1757 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001758
1759 /* Packet is any nonTSO type
1760 *
1761 * Copy as much as possible skb->data to immediate data and
1762 * the rest to sg1entry
1763 */
1764 if (skb_data_size >= SWQE2_MAX_IMM) {
1765 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001766 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001767
1768 swqe->immediate_data_length = SWQE2_MAX_IMM;
1769
1770 if (skb_data_size > SWQE2_MAX_IMM) {
1771 /* copy sg1entry data */
1772 sg1entry->l_key = lkey;
1773 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001774 sg1entry->vaddr =
1775 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001776 swqe->descriptors++;
1777 }
1778 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001779 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001780 swqe->immediate_data_length = skb_data_size;
1781 }
1782}
1783
1784static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1785 struct ehea_swqe *swqe, u32 lkey)
1786{
1787 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1788 skb_frag_t *frag;
1789 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790
1791 nfrags = skb_shinfo(skb)->nr_frags;
1792 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001793 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001794 swqe->descriptors = 0;
1795 sg1entry_contains_frag_data = 0;
1796
1797 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1798 write_swqe2_TSO(skb, swqe, lkey);
1799 else
1800 write_swqe2_nonTSO(skb, swqe, lkey);
1801
1802 /* write descriptors */
1803 if (nfrags > 0) {
1804 if (swqe->descriptors == 0) {
1805 /* sg1entry not yet used */
1806 frag = &skb_shinfo(skb)->frags[0];
1807
1808 /* copy sg1entry data */
1809 sg1entry->l_key = lkey;
1810 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001811 sg1entry->vaddr =
1812 ehea_map_vaddr(page_address(frag->page)
1813 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001814 swqe->descriptors++;
1815 sg1entry_contains_frag_data = 1;
1816 }
1817
1818 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1819
1820 frag = &skb_shinfo(skb)->frags[i];
1821 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1822
1823 sgentry->l_key = lkey;
1824 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001825 sgentry->vaddr =
1826 ehea_map_vaddr(page_address(frag->page)
1827 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001828 swqe->descriptors++;
1829 }
1830 }
1831}
1832
1833static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1834{
1835 int ret = 0;
1836 u64 hret;
1837 u8 reg_type;
1838
1839 /* De/Register untagged packets */
1840 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1841 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1842 port->logical_port_id,
1843 reg_type, port->mac_addr, 0, hcallid);
1844 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001845 pr_err("%sregistering bc address failed (tagged)\n",
1846 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001847 ret = -EIO;
1848 goto out_herr;
1849 }
1850
1851 /* De/Register VLAN packets */
1852 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, port->mac_addr, 0, hcallid);
1856 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001857 pr_err("%sregistering bc address failed (vlan)\n",
1858 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001859 ret = -EIO;
1860 }
1861out_herr:
1862 return ret;
1863}
1864
1865static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1866{
1867 struct ehea_port *port = netdev_priv(dev);
1868 struct sockaddr *mac_addr = sa;
1869 struct hcp_ehea_port_cb0 *cb0;
1870 int ret;
1871 u64 hret;
1872
1873 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1874 ret = -EADDRNOTAVAIL;
1875 goto out;
1876 }
1877
Thomas Klein3faf2692009-01-21 14:45:33 -08001878 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001879 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001880 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001881 ret = -ENOMEM;
1882 goto out;
1883 }
1884
1885 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1886
1887 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1888
1889 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1890 port->logical_port_id, H_PORT_CB0,
1891 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1892 if (hret != H_SUCCESS) {
1893 ret = -EIO;
1894 goto out_free;
1895 }
1896
1897 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1898
1899 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001900 if (port->state == EHEA_PORT_UP) {
1901 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1902 if (ret)
1903 goto out_upregs;
1904 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001905
1906 port->mac_addr = cb0->port_mac_addr << 16;
1907
1908 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001909 if (port->state == EHEA_PORT_UP) {
1910 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1911 if (ret)
1912 goto out_upregs;
1913 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914
1915 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001916
1917out_upregs:
1918 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001920 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921out:
1922 return ret;
1923}
1924
1925static void ehea_promiscuous_error(u64 hret, int enable)
1926{
Thomas Klein7674a582007-01-22 12:54:20 +01001927 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001928 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1929 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001930 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001931 pr_err("failed %sabling promiscuous mode\n",
1932 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001933}
1934
1935static void ehea_promiscuous(struct net_device *dev, int enable)
1936{
1937 struct ehea_port *port = netdev_priv(dev);
1938 struct hcp_ehea_port_cb7 *cb7;
1939 u64 hret;
1940
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001941 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942 return;
1943
Thomas Klein3faf2692009-01-21 14:45:33 -08001944 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001946 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 goto out;
1948 }
1949
1950 /* Modify Pxs_DUCQPN in CB7 */
1951 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1952
1953 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1954 port->logical_port_id,
1955 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1956 if (hret) {
1957 ehea_promiscuous_error(hret, enable);
1958 goto out;
1959 }
1960
1961 port->promisc = enable;
1962out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001963 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001964}
1965
1966static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1967 u32 hcallid)
1968{
1969 u64 hret;
1970 u8 reg_type;
1971
1972 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1973 | EHEA_BCMC_UNTAGGED;
1974
1975 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1976 port->logical_port_id,
1977 reg_type, mc_mac_addr, 0, hcallid);
1978 if (hret)
1979 goto out;
1980
1981 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1982 | EHEA_BCMC_VLANID_ALL;
1983
1984 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1985 port->logical_port_id,
1986 reg_type, mc_mac_addr, 0, hcallid);
1987out:
1988 return hret;
1989}
1990
1991static int ehea_drop_multicast_list(struct net_device *dev)
1992{
1993 struct ehea_port *port = netdev_priv(dev);
1994 struct ehea_mc_list *mc_entry = port->mc_list;
1995 struct list_head *pos;
1996 struct list_head *temp;
1997 int ret = 0;
1998 u64 hret;
1999
2000 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2001 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2002
2003 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2004 H_DEREG_BCMC);
2005 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002006 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002007 ret = -EIO;
2008 }
2009
2010 list_del(pos);
2011 kfree(mc_entry);
2012 }
2013 return ret;
2014}
2015
2016static void ehea_allmulti(struct net_device *dev, int enable)
2017{
2018 struct ehea_port *port = netdev_priv(dev);
2019 u64 hret;
2020
2021 if (!port->allmulti) {
2022 if (enable) {
2023 /* Enable ALLMULTI */
2024 ehea_drop_multicast_list(dev);
2025 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2026 if (!hret)
2027 port->allmulti = 1;
2028 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002029 netdev_err(dev,
2030 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002031 }
2032 } else
2033 if (!enable) {
2034 /* Disable ALLMULTI */
2035 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2036 if (!hret)
2037 port->allmulti = 0;
2038 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002039 netdev_err(dev,
2040 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002041 }
2042}
2043
Doug Maxey508d2b52008-01-31 20:20:49 -06002044static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002045{
2046 struct ehea_mc_list *ehea_mcl_entry;
2047 u64 hret;
2048
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002049 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002050 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002051 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052 return;
2053 }
2054
2055 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2056
2057 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2058
2059 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2060 H_REG_BCMC);
2061 if (!hret)
2062 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2063 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002064 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002065 kfree(ehea_mcl_entry);
2066 }
2067}
2068
2069static void ehea_set_multicast_list(struct net_device *dev)
2070{
2071 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002072 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002073 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002074
Breno Leitaoa4910b72011-05-23 03:36:35 +00002075 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002076 ehea_promiscuous(dev, 1);
2077 return;
2078 }
2079 ehea_promiscuous(dev, 0);
2080
2081 if (dev->flags & IFF_ALLMULTI) {
2082 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002083 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084 }
2085 ehea_allmulti(dev, 0);
2086
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002087 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002088 ret = ehea_drop_multicast_list(dev);
2089 if (ret) {
2090 /* Dropping the current multicast list failed.
2091 * Enabling ALL_MULTI is the best we can do.
2092 */
2093 ehea_allmulti(dev, 1);
2094 }
2095
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002096 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002097 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2098 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099 goto out;
2100 }
2101
Jiri Pirko22bedad32010-04-01 21:22:57 +00002102 netdev_for_each_mc_addr(ha, dev)
2103 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002104
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002105 }
2106out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002107 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108}
2109
2110static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2111{
2112 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2113 return -EINVAL;
2114 dev->mtu = new_mtu;
2115 return 0;
2116}
2117
2118static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2119 struct ehea_swqe *swqe, u32 lkey)
2120{
2121 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002122 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002123
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002124 /* IPv4 */
2125 swqe->tx_control |= EHEA_SWQE_CRC
2126 | EHEA_SWQE_IP_CHECKSUM
2127 | EHEA_SWQE_TCP_CHECKSUM
2128 | EHEA_SWQE_IMM_DATA_PRESENT
2129 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2130
2131 write_ip_start_end(swqe, skb);
2132
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002133 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002134 if ((iph->frag_off & IP_MF) ||
2135 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002136 /* IP fragment, so don't change cs */
2137 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2138 else
2139 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002140 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002141 write_tcp_offset_end(swqe, skb);
2142 }
2143
2144 /* icmp (big data) and ip segmentation packets (all other ip
2145 packets) do not require any special handling */
2146
2147 } else {
2148 /* Other Ethernet Protocol */
2149 swqe->tx_control |= EHEA_SWQE_CRC
2150 | EHEA_SWQE_IMM_DATA_PRESENT
2151 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2152 }
2153
2154 write_swqe2_data(skb, dev, swqe, lkey);
2155}
2156
2157static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2158 struct ehea_swqe *swqe)
2159{
2160 int nfrags = skb_shinfo(skb)->nr_frags;
2161 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2162 skb_frag_t *frag;
2163 int i;
2164
2165 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002166 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002167
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002168 /* IPv4 */
2169 write_ip_start_end(swqe, skb);
2170
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002171 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002172 swqe->tx_control |= EHEA_SWQE_CRC
2173 | EHEA_SWQE_IP_CHECKSUM
2174 | EHEA_SWQE_TCP_CHECKSUM
2175 | EHEA_SWQE_IMM_DATA_PRESENT;
2176
2177 write_tcp_offset_end(swqe, skb);
2178
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002179 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002180 if ((iph->frag_off & IP_MF) ||
2181 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182 /* IP fragment, so don't change cs */
2183 swqe->tx_control |= EHEA_SWQE_CRC
2184 | EHEA_SWQE_IMM_DATA_PRESENT;
2185 else {
2186 swqe->tx_control |= EHEA_SWQE_CRC
2187 | EHEA_SWQE_IP_CHECKSUM
2188 | EHEA_SWQE_TCP_CHECKSUM
2189 | EHEA_SWQE_IMM_DATA_PRESENT;
2190
2191 write_udp_offset_end(swqe, skb);
2192 }
2193 } else {
2194 /* icmp (big data) and
2195 ip segmentation packets (all other ip packets) */
2196 swqe->tx_control |= EHEA_SWQE_CRC
2197 | EHEA_SWQE_IP_CHECKSUM
2198 | EHEA_SWQE_IMM_DATA_PRESENT;
2199 }
2200 } else {
2201 /* Other Ethernet Protocol */
2202 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2203 }
2204 /* copy (immediate) data */
2205 if (nfrags == 0) {
2206 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002207 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208 } else {
2209 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002210 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002211 skb_headlen(skb));
2212 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002213
2214 /* ... then copy data from the fragments */
2215 for (i = 0; i < nfrags; i++) {
2216 frag = &skb_shinfo(skb)->frags[i];
2217 memcpy(imm_data,
2218 page_address(frag->page) + frag->page_offset,
2219 frag->size);
2220 imm_data += frag->size;
2221 }
2222 }
2223 swqe->immediate_data_length = skb->len;
2224 dev_kfree_skb(skb);
2225}
2226
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002227static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2228{
2229 struct tcphdr *tcp;
2230 u32 tmp;
2231
2232 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002233 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002234 tcp = (struct tcphdr *)(skb_network_header(skb) +
2235 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002236 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002237 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002239 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002240 return 0;
2241}
2242
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002243static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2244{
2245 struct ehea_port *port = netdev_priv(dev);
2246 struct ehea_swqe *swqe;
2247 unsigned long flags;
2248 u32 lkey;
2249 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002250 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2253
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002254 if (!spin_trylock(&pr->xmit_lock))
2255 return NETDEV_TX_BUSY;
2256
2257 if (pr->queue_stopped) {
2258 spin_unlock(&pr->xmit_lock);
2259 return NETDEV_TX_BUSY;
2260 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002261
2262 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2263 memset(swqe, 0, SWQE_HEADER_SIZE);
2264 atomic_dec(&pr->swqe_avail);
2265
Eric Dumazete5ccd962010-10-26 19:21:07 +00002266 if (vlan_tx_tag_present(skb)) {
2267 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2268 swqe->vlan_tag = vlan_tx_tag_get(skb);
2269 }
2270
Breno Leitaoce45b872010-10-27 08:45:14 +00002271 pr->tx_packets++;
2272 pr->tx_bytes += skb->len;
2273
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002274 if (skb->len <= SWQE3_MAX_IMM) {
2275 u32 sig_iv = port->sig_comp_iv;
2276 u32 swqe_num = pr->swqe_id_counter;
2277 ehea_xmit3(skb, dev, swqe);
2278 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2279 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2280 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2281 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2282 sig_iv);
2283 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2284 pr->swqe_ll_count = 0;
2285 } else
2286 pr->swqe_ll_count += 1;
2287 } else {
2288 swqe->wr_id =
2289 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2290 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002291 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002292 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2293 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2294
2295 pr->sq_skba.index++;
2296 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2297
2298 lkey = pr->send_mr.lkey;
2299 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002300 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301 }
2302 pr->swqe_id_counter += 1;
2303
Joe Perches8c4877a2010-12-13 10:05:14 -08002304 netif_info(port, tx_queued, dev,
2305 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2306 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002307 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002308
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002309 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2310 netif_stop_queue(dev);
2311 swqe->tx_control |= EHEA_SWQE_PURGE;
2312 }
Thomas Klein44c82152007-07-11 16:32:00 +02002313
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002314 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002315
2316 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2317 spin_lock_irqsave(&pr->netif_queue, flags);
2318 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002319 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002320 netif_stop_queue(dev);
2321 pr->queue_stopped = 1;
2322 }
2323 spin_unlock_irqrestore(&pr->netif_queue, flags);
2324 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002325 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 return NETDEV_TX_OK;
2329}
2330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2332{
2333 struct ehea_port *port = netdev_priv(dev);
2334 struct ehea_adapter *adapter = port->adapter;
2335 struct hcp_ehea_port_cb1 *cb1;
2336 int index;
2337 u64 hret;
2338
Thomas Klein3faf2692009-01-21 14:45:33 -08002339 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002340 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002341 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002342 goto out;
2343 }
2344
2345 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2346 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2347 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002348 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002349 goto out;
2350 }
2351
2352 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002353 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354
2355 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2356 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2357 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002358 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002360 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361 return;
2362}
2363
2364static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2365{
2366 struct ehea_port *port = netdev_priv(dev);
2367 struct ehea_adapter *adapter = port->adapter;
2368 struct hcp_ehea_port_cb1 *cb1;
2369 int index;
2370 u64 hret;
2371
Thomas Klein3faf2692009-01-21 14:45:33 -08002372 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002373 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002374 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 goto out;
2376 }
2377
2378 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2379 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2380 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002381 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382 goto out;
2383 }
2384
2385 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002386 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387
2388 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2389 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2390 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002391 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002392out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002393 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002394}
2395
2396int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2397{
2398 int ret = -EIO;
2399 u64 hret;
2400 u16 dummy16 = 0;
2401 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002402 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002403
Thomas Klein3faf2692009-01-21 14:45:33 -08002404 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002405 if (!cb0) {
2406 ret = -ENOMEM;
2407 goto out;
2408 }
2409
2410 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2411 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2412 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002413 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414 goto out;
2415 }
2416
2417 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2418 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2419 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2420 &dummy64, &dummy64, &dummy16, &dummy16);
2421 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002422 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002423 goto out;
2424 }
2425
2426 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2427 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2428 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002429 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002430 goto out;
2431 }
2432
2433 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2434 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2435 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2436 &dummy64, &dummy64, &dummy16, &dummy16);
2437 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002438 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002439 goto out;
2440 }
2441
2442 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2443 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2444 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002445 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002446 goto out;
2447 }
2448
2449 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2450 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2451 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2452 &dummy64, &dummy64, &dummy16, &dummy16);
2453 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002454 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455 goto out;
2456 }
2457
2458 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2459 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2460 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002461 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 goto out;
2463 }
2464
2465 ret = 0;
2466out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002467 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002468 return ret;
2469}
2470
2471static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2472 int add_tx_qps)
2473{
2474 int ret, i;
2475 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2476 enum ehea_eq_type eq_type = EHEA_EQ;
2477
2478 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2479 EHEA_MAX_ENTRIES_EQ, 1);
2480 if (!port->qp_eq) {
2481 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002482 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483 goto out_kill_eq;
2484 }
2485
2486 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002487 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002488 pr_cfg.max_entries_sq = sq_entries;
2489 pr_cfg.max_entries_rq1 = rq1_entries;
2490 pr_cfg.max_entries_rq2 = rq2_entries;
2491 pr_cfg.max_entries_rq3 = rq3_entries;
2492
2493 pr_cfg_small_rx.max_entries_rcq = 1;
2494 pr_cfg_small_rx.max_entries_scq = sq_entries;
2495 pr_cfg_small_rx.max_entries_sq = sq_entries;
2496 pr_cfg_small_rx.max_entries_rq1 = 1;
2497 pr_cfg_small_rx.max_entries_rq2 = 1;
2498 pr_cfg_small_rx.max_entries_rq3 = 1;
2499
2500 for (i = 0; i < def_qps; i++) {
2501 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2502 if (ret)
2503 goto out_clean_pr;
2504 }
2505 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2506 ret = ehea_init_port_res(port, &port->port_res[i],
2507 &pr_cfg_small_rx, i);
2508 if (ret)
2509 goto out_clean_pr;
2510 }
2511
2512 return 0;
2513
2514out_clean_pr:
2515 while (--i >= 0)
2516 ehea_clean_portres(port, &port->port_res[i]);
2517
2518out_kill_eq:
2519 ehea_destroy_eq(port->qp_eq);
2520 return ret;
2521}
2522
2523static int ehea_clean_all_portres(struct ehea_port *port)
2524{
2525 int ret = 0;
2526 int i;
2527
Doug Maxey508d2b52008-01-31 20:20:49 -06002528 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529 ret |= ehea_clean_portres(port, &port->port_res[i]);
2530
2531 ret |= ehea_destroy_eq(port->qp_eq);
2532
2533 return ret;
2534}
2535
Thomas Klein35cf2e22007-08-06 13:55:14 +02002536static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002537{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002538 if (adapter->active_ports)
2539 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002540
2541 ehea_rem_mr(&adapter->mr);
2542}
2543
Thomas Klein35cf2e22007-08-06 13:55:14 +02002544static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002545{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002546 if (adapter->active_ports)
2547 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002548
2549 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2550}
2551
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002552static int ehea_up(struct net_device *dev)
2553{
2554 int ret, i;
2555 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002556
2557 if (port->state == EHEA_PORT_UP)
2558 return 0;
2559
2560 ret = ehea_port_res_setup(port, port->num_def_qps,
2561 port->num_add_tx_qps);
2562 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002563 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002564 goto out;
2565 }
2566
2567 /* Set default QP for this port */
2568 ret = ehea_configure_port(port);
2569 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002570 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002571 goto out_clean_pr;
2572 }
2573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002574 ret = ehea_reg_interrupts(dev);
2575 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002576 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002577 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002578 }
2579
Doug Maxey508d2b52008-01-31 20:20:49 -06002580 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002581 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2582 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002583 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002584 goto out_free_irqs;
2585 }
2586 }
2587
Doug Maxey508d2b52008-01-31 20:20:49 -06002588 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589 ret = ehea_fill_port_res(&port->port_res[i]);
2590 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002591 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002592 goto out_free_irqs;
2593 }
2594 }
2595
Thomas Klein21eee2d2008-02-13 16:18:33 +01002596 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2597 if (ret) {
2598 ret = -EIO;
2599 goto out_free_irqs;
2600 }
2601
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002602 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002603
2604 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002605 goto out;
2606
2607out_free_irqs:
2608 ehea_free_interrupts(dev);
2609
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610out_clean_pr:
2611 ehea_clean_all_portres(port);
2612out:
Thomas Klein44c82152007-07-11 16:32:00 +02002613 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002614 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002615
Thomas Klein21eee2d2008-02-13 16:18:33 +01002616 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002617 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002618
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002619 return ret;
2620}
2621
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002622static void port_napi_disable(struct ehea_port *port)
2623{
2624 int i;
2625
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002626 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002627 napi_disable(&port->port_res[i].napi);
2628}
2629
2630static void port_napi_enable(struct ehea_port *port)
2631{
2632 int i;
2633
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002634 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002635 napi_enable(&port->port_res[i].napi);
2636}
2637
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002638static int ehea_open(struct net_device *dev)
2639{
2640 int ret;
2641 struct ehea_port *port = netdev_priv(dev);
2642
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002643 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002644
Joe Perches8c4877a2010-12-13 10:05:14 -08002645 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002646
2647 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002648 if (!ret) {
2649 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002651 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002652
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002653 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002654
2655 return ret;
2656}
2657
2658static int ehea_down(struct net_device *dev)
2659{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002660 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002661 struct ehea_port *port = netdev_priv(dev);
2662
2663 if (port->state == EHEA_PORT_DOWN)
2664 return 0;
2665
2666 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002667 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2668
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002669 ehea_free_interrupts(dev);
2670
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002671 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002672
Thomas Klein21eee2d2008-02-13 16:18:33 +01002673 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002674
Thomas Klein44c82152007-07-11 16:32:00 +02002675 ret = ehea_clean_all_portres(port);
2676 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002677 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002678
Thomas Klein21eee2d2008-02-13 16:18:33 +01002679 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002680
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002681 return ret;
2682}
2683
2684static int ehea_stop(struct net_device *dev)
2685{
2686 int ret;
2687 struct ehea_port *port = netdev_priv(dev);
2688
Joe Perches8c4877a2010-12-13 10:05:14 -08002689 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002690
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002691 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002692 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002693 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002694 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002695 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002696 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002697 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002698 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002699 return ret;
2700}
2701
Andrew Morton22559c52008-04-18 13:50:39 -07002702static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002703{
2704 struct ehea_qp qp = *orig_qp;
2705 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2706 struct ehea_swqe *swqe;
2707 int wqe_index;
2708 int i;
2709
2710 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2711 swqe = ehea_get_swqe(&qp, &wqe_index);
2712 swqe->tx_control |= EHEA_SWQE_PURGE;
2713 }
2714}
2715
Andrew Morton22559c52008-04-18 13:50:39 -07002716static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002717{
2718 int i;
2719
2720 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2721 struct ehea_port_res *pr = &port->port_res[i];
2722 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002723 int ret;
2724
2725 ret = wait_event_timeout(port->swqe_avail_wq,
2726 atomic_read(&pr->swqe_avail) >= swqe_max,
2727 msecs_to_jiffies(100));
2728
2729 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002730 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002731 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002732 }
2733 }
2734}
2735
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002736int ehea_stop_qps(struct net_device *dev)
2737{
2738 struct ehea_port *port = netdev_priv(dev);
2739 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002740 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002741 int ret = -EIO;
2742 int dret;
2743 int i;
2744 u64 hret;
2745 u64 dummy64 = 0;
2746 u16 dummy16 = 0;
2747
Thomas Klein3faf2692009-01-21 14:45:33 -08002748 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002749 if (!cb0) {
2750 ret = -ENOMEM;
2751 goto out;
2752 }
2753
2754 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2755 struct ehea_port_res *pr = &port->port_res[i];
2756 struct ehea_qp *qp = pr->qp;
2757
2758 /* Purge send queue */
2759 ehea_purge_sq(qp);
2760
2761 /* Disable 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 pr_err("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 pr_err("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 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002787 goto out;
2788 }
2789
2790 /* deregister shared memory regions */
2791 dret = ehea_rem_smrs(pr);
2792 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002793 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002794 goto out;
2795 }
2796 }
2797
2798 ret = 0;
2799out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002800 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002801
2802 return ret;
2803}
2804
Doug Maxey508d2b52008-01-31 20:20:49 -06002805void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002806{
2807 struct ehea_qp qp = *orig_qp;
2808 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2809 struct ehea_rwqe *rwqe;
2810 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2811 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2812 struct sk_buff *skb;
2813 u32 lkey = pr->recv_mr.lkey;
2814
2815
2816 int i;
2817 int index;
2818
2819 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2820 rwqe = ehea_get_next_rwqe(&qp, 2);
2821 rwqe->sg_list[0].l_key = lkey;
2822 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2823 skb = skba_rq2[index];
2824 if (skb)
2825 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2826 }
2827
2828 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2829 rwqe = ehea_get_next_rwqe(&qp, 3);
2830 rwqe->sg_list[0].l_key = lkey;
2831 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2832 skb = skba_rq3[index];
2833 if (skb)
2834 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2835 }
2836}
2837
2838int ehea_restart_qps(struct net_device *dev)
2839{
2840 struct ehea_port *port = netdev_priv(dev);
2841 struct ehea_adapter *adapter = port->adapter;
2842 int ret = 0;
2843 int i;
2844
Doug Maxey508d2b52008-01-31 20:20:49 -06002845 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002846 u64 hret;
2847 u64 dummy64 = 0;
2848 u16 dummy16 = 0;
2849
Thomas Klein3faf2692009-01-21 14:45:33 -08002850 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002851 if (!cb0) {
2852 ret = -ENOMEM;
2853 goto out;
2854 }
2855
2856 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2857 struct ehea_port_res *pr = &port->port_res[i];
2858 struct ehea_qp *qp = pr->qp;
2859
2860 ret = ehea_gen_smrs(pr);
2861 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002862 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002863 goto out;
2864 }
2865
2866 ehea_update_rqs(qp, pr);
2867
2868 /* Enable queue pair */
2869 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2870 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2871 cb0);
2872 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002873 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002874 goto out;
2875 }
2876
2877 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2878 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2879
2880 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2881 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2882 1), cb0, &dummy64,
2883 &dummy64, &dummy16, &dummy16);
2884 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002885 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002886 goto out;
2887 }
2888
2889 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2890 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2891 cb0);
2892 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002893 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002894 goto out;
2895 }
2896
2897 /* refill entire queue */
2898 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2899 ehea_refill_rq2(pr, 0);
2900 ehea_refill_rq3(pr, 0);
2901 }
2902out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002903 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002904
2905 return ret;
2906}
2907
David Howellsc4028952006-11-22 14:57:56 +00002908static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002909{
2910 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002911 struct ehea_port *port =
2912 container_of(work, struct ehea_port, reset_task);
2913 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002914
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002915 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002916 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002917 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002918 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002919
2920 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002921
Thomas Klein44c82152007-07-11 16:32:00 +02002922 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002923
2924 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002925 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002926 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002927
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002928 ehea_set_multicast_list(dev);
2929
Joe Perches8c4877a2010-12-13 10:05:14 -08002930 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002931
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002932 port_napi_enable(port);
2933
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002934 netif_wake_queue(dev);
2935out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002936 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002937 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002938}
2939
Tejun Heo3d6b8922010-12-12 16:45:14 +01002940static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002941{
2942 int ret, i;
2943 struct ehea_adapter *adapter;
2944
Joe Perches8c4877a2010-12-13 10:05:14 -08002945 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002946
2947 list_for_each_entry(adapter, &adapter_list, list)
2948 if (adapter->active_ports) {
2949 /* Shutdown all ports */
2950 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2951 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002952 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002953
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002954 if (!port)
2955 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002956
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002957 dev = port->netdev;
2958
2959 if (dev->flags & IFF_UP) {
2960 mutex_lock(&port->port_lock);
2961 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002962 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002963 ret = ehea_stop_qps(dev);
2964 if (ret) {
2965 mutex_unlock(&port->port_lock);
2966 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002967 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002968 port_napi_disable(port);
2969 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002970 }
Andre Detsch2928db42010-08-17 05:49:12 +00002971 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002972 }
2973
2974 /* Unregister old memory region */
2975 ret = ehea_rem_mr(&adapter->mr);
2976 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002977 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002978 goto out;
2979 }
2980 }
2981
Thomas Klein44c82152007-07-11 16:32:00 +02002982 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2983
2984 list_for_each_entry(adapter, &adapter_list, list)
2985 if (adapter->active_ports) {
2986 /* Register new memory region */
2987 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2988 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002989 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002990 goto out;
2991 }
2992
2993 /* Restart all ports */
2994 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2995 struct ehea_port *port = adapter->port[i];
2996
2997 if (port) {
2998 struct net_device *dev = port->netdev;
2999
3000 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003001 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003002 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003003 if (!ret) {
3004 check_sqs(port);
3005 port_napi_enable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003006 netif_wake_queue(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003007 } else {
3008 netdev_err(dev, "Unable to restart QPS\n");
3009 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003010 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003011 }
3012 }
3013 }
3014 }
Joe Perches8c4877a2010-12-13 10:05:14 -08003015 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003016out:
3017 return;
3018}
3019
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003020static void ehea_tx_watchdog(struct net_device *dev)
3021{
3022 struct ehea_port *port = netdev_priv(dev);
3023
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003024 if (netif_carrier_ok(dev) &&
3025 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003026 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003027}
3028
3029int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3030{
3031 struct hcp_query_ehea *cb;
3032 u64 hret;
3033 int ret;
3034
Thomas Klein3faf2692009-01-21 14:45:33 -08003035 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003036 if (!cb) {
3037 ret = -ENOMEM;
3038 goto out;
3039 }
3040
3041 hret = ehea_h_query_ehea(adapter->handle, cb);
3042
3043 if (hret != H_SUCCESS) {
3044 ret = -EIO;
3045 goto out_herr;
3046 }
3047
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003048 adapter->max_mc_mac = cb->max_mc_mac - 1;
3049 ret = 0;
3050
3051out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003052 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003053out:
3054 return ret;
3055}
3056
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003057int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3058{
3059 struct hcp_ehea_port_cb4 *cb4;
3060 u64 hret;
3061 int ret = 0;
3062
3063 *jumbo = 0;
3064
3065 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003066 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003067 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003068 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003069 ret = -ENOMEM;
3070 goto out;
3071 } else {
3072 hret = ehea_h_query_ehea_port(port->adapter->handle,
3073 port->logical_port_id,
3074 H_PORT_CB4,
3075 H_PORT_CB4_JUMBO, cb4);
3076 if (hret == H_SUCCESS) {
3077 if (cb4->jumbo_frame)
3078 *jumbo = 1;
3079 else {
3080 cb4->jumbo_frame = 1;
3081 hret = ehea_h_modify_ehea_port(port->adapter->
3082 handle,
3083 port->
3084 logical_port_id,
3085 H_PORT_CB4,
3086 H_PORT_CB4_JUMBO,
3087 cb4);
3088 if (hret == H_SUCCESS)
3089 *jumbo = 1;
3090 }
3091 } else
3092 ret = -EINVAL;
3093
Thomas Klein3faf2692009-01-21 14:45:33 -08003094 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003095 }
3096out:
3097 return ret;
3098}
3099
3100static ssize_t ehea_show_port_id(struct device *dev,
3101 struct device_attribute *attr, char *buf)
3102{
3103 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003104 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105}
3106
3107static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3108 NULL);
3109
3110static void __devinit logical_port_release(struct device *dev)
3111{
3112 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003113 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114}
3115
3116static struct device *ehea_register_port(struct ehea_port *port,
3117 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003118{
3119 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003120
Grant Likely61c7a082010-04-13 16:12:29 -07003121 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003122 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003123 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003124
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003125 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 port->ofdev.dev.release = logical_port_release;
3127
3128 ret = of_device_register(&port->ofdev);
3129 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003130 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 goto out;
3132 }
3133
3134 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003135 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003136 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137 goto out_unreg_of_dev;
3138 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003139
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140 return &port->ofdev.dev;
3141
3142out_unreg_of_dev:
3143 of_device_unregister(&port->ofdev);
3144out:
3145 return NULL;
3146}
3147
3148static void ehea_unregister_port(struct ehea_port *port)
3149{
3150 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3151 of_device_unregister(&port->ofdev);
3152}
3153
Thomas Klein086c1b22009-01-21 14:43:59 -08003154static const struct net_device_ops ehea_netdev_ops = {
3155 .ndo_open = ehea_open,
3156 .ndo_stop = ehea_stop,
3157 .ndo_start_xmit = ehea_start_xmit,
3158#ifdef CONFIG_NET_POLL_CONTROLLER
3159 .ndo_poll_controller = ehea_netpoll,
3160#endif
3161 .ndo_get_stats = ehea_get_stats,
3162 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003163 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003164 .ndo_set_multicast_list = ehea_set_multicast_list,
3165 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003166 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003167 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3168 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003169};
3170
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3172 u32 logical_port_id,
3173 struct device_node *dn)
3174{
3175 int ret;
3176 struct net_device *dev;
3177 struct ehea_port *port;
3178 struct device *port_dev;
3179 int jumbo;
3180
3181 /* allocate memory for the port structures */
3182 dev = alloc_etherdev(sizeof(struct ehea_port));
3183
3184 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003185 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003186 ret = -ENOMEM;
3187 goto out_err;
3188 }
3189
3190 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003191
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003192 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003193 port->state = EHEA_PORT_DOWN;
3194 port->sig_comp_iv = sq_entries / 10;
3195
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003196 port->adapter = adapter;
3197 port->netdev = dev;
3198 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003199
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003200 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003201
3202 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3203 if (!port->mc_list) {
3204 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003205 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003206 }
3207
3208 INIT_LIST_HEAD(&port->mc_list->list);
3209
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003210 ret = ehea_sense_port_attr(port);
3211 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003212 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003213
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003214 port_dev = ehea_register_port(port, dn);
3215 if (!port_dev)
3216 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003217
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003219
3220 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003221 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3222
Thomas Klein086c1b22009-01-21 14:43:59 -08003223 dev->netdev_ops = &ehea_netdev_ops;
3224 ehea_set_ethtool_ops(dev);
3225
Michał Mirosławf4786a92011-04-17 00:15:47 +00003226 dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3227 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003228 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003229 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003230 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Michał Mirosławf4786a92011-04-17 00:15:47 +00003231 | NETIF_F_LLTX | NETIF_F_RXCSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003232 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3233
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003234 if (use_lro)
3235 dev->features |= NETIF_F_LRO;
3236
David Howellsc4028952006-11-22 14:57:56 +00003237 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238
Anton Blanchard21ccc792011-05-10 16:17:10 +00003239 init_waitqueue_head(&port->swqe_avail_wq);
3240 init_waitqueue_head(&port->restart_wq);
3241
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003242 ret = register_netdev(dev);
3243 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003244 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003245 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003246 }
3247
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003248 port->lro_max_aggr = lro_max_aggr;
3249
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003250 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003251 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003252 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253
Joe Perches8c4877a2010-12-13 10:05:14 -08003254 netdev_info(dev, "Jumbo frames are %sabled\n",
3255 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003256
Thomas Klein44c82152007-07-11 16:32:00 +02003257 adapter->active_ports++;
3258
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261out_unreg_port:
3262 ehea_unregister_port(port);
3263
3264out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003266
3267out_free_ethdev:
3268 free_netdev(dev);
3269
3270out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003271 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3272 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003273 return NULL;
3274}
3275
3276static void ehea_shutdown_single_port(struct ehea_port *port)
3277{
Brian King7fb1c2a2008-05-14 09:48:25 -05003278 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003279
3280 cancel_work_sync(&port->reset_task);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003281 unregister_netdev(port->netdev);
3282 ehea_unregister_port(port);
3283 kfree(port->mc_list);
3284 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003285 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003286}
3287
3288static int ehea_setup_ports(struct ehea_adapter *adapter)
3289{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290 struct device_node *lhea_dn;
3291 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003292
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003293 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003294 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003295
Grant Likely61c7a082010-04-13 16:12:29 -07003296 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003297 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003298
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003299 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003300 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003301 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003302 pr_err("bad device node: eth_dn name=%s\n",
3303 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305 }
3306
Thomas Klein1211bb62007-04-26 11:56:43 +02003307 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003308 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003309 of_node_put(eth_dn);
3310 return -EIO;
3311 }
3312
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003313 adapter->port[i] = ehea_setup_single_port(adapter,
3314 *dn_log_port_id,
3315 eth_dn);
3316 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003317 netdev_info(adapter->port[i]->netdev,
3318 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003319 else
3320 ehea_remove_adapter_mr(adapter);
3321
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003323 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003324 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325}
3326
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003327static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3328 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329{
3330 struct device_node *lhea_dn;
3331 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003332 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333
Grant Likely61c7a082010-04-13 16:12:29 -07003334 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003335 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003336
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003337 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003338 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003339 if (dn_log_port_id)
3340 if (*dn_log_port_id == logical_port_id)
3341 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003342 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343
3344 return NULL;
3345}
3346
3347static ssize_t ehea_probe_port(struct device *dev,
3348 struct device_attribute *attr,
3349 const char *buf, size_t count)
3350{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003351 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352 struct ehea_port *port;
3353 struct device_node *eth_dn = NULL;
3354 int i;
3355
3356 u32 logical_port_id;
3357
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003358 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359
3360 port = ehea_get_port(adapter, logical_port_id);
3361
3362 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003363 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3364 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365 return -EINVAL;
3366 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003367
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003368 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3369
3370 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003371 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372 return -EINVAL;
3373 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003374
Thomas Klein1211bb62007-04-26 11:56:43 +02003375 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003376 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003377 return -EIO;
3378 }
3379
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3381
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003382 of_node_put(eth_dn);
3383
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003384 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003385 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003386 if (!adapter->port[i]) {
3387 adapter->port[i] = port;
3388 break;
3389 }
3390
Joe Perches8c4877a2010-12-13 10:05:14 -08003391 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3392 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003393 } else {
3394 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003395 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003396 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397
3398 return (ssize_t) count;
3399}
3400
3401static ssize_t ehea_remove_port(struct device *dev,
3402 struct device_attribute *attr,
3403 const char *buf, size_t count)
3404{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003405 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003406 struct ehea_port *port;
3407 int i;
3408 u32 logical_port_id;
3409
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003410 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003411
3412 port = ehea_get_port(adapter, logical_port_id);
3413
3414 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003415 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3416 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003417
3418 ehea_shutdown_single_port(port);
3419
Doug Maxey508d2b52008-01-31 20:20:49 -06003420 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003421 if (adapter->port[i] == port) {
3422 adapter->port[i] = NULL;
3423 break;
3424 }
3425 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003426 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3427 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003428 return -EINVAL;
3429 }
3430
Thomas Klein1211bb62007-04-26 11:56:43 +02003431 ehea_remove_adapter_mr(adapter);
3432
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433 return (ssize_t) count;
3434}
3435
3436static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3437static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3438
Grant Likely2dc11582010-08-06 09:25:50 -06003439int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003440{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003441 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003442 if (ret)
3443 goto out;
3444
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003445 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003446out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447 return ret;
3448}
3449
Grant Likely2dc11582010-08-06 09:25:50 -06003450void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003452 device_remove_file(&dev->dev, &dev_attr_probe_port);
3453 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003454}
3455
Grant Likely2dc11582010-08-06 09:25:50 -06003456static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003457 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458{
3459 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003460 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003461 int ret;
3462
Grant Likely61c7a082010-04-13 16:12:29 -07003463 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003464 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003465 return -EINVAL;
3466 }
3467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3469 if (!adapter) {
3470 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003471 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003472 goto out;
3473 }
3474
Thomas Klein44c82152007-07-11 16:32:00 +02003475 list_add(&adapter->list, &adapter_list);
3476
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003477 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003478
Grant Likely61c7a082010-04-13 16:12:29 -07003479 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003480 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003481 if (adapter_handle)
3482 adapter->handle = *adapter_handle;
3483
3484 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003485 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003486 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003487 ret = -ENODEV;
3488 goto out_free_ad;
3489 }
3490
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491 adapter->pd = EHEA_PD_ID;
3492
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003493 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495
3496 /* initialize adapter and ports */
3497 /* get adapter properties */
3498 ret = ehea_sense_adapter_attr(adapter);
3499 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003500 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003501 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003502 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503
3504 adapter->neq = ehea_create_eq(adapter,
3505 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3506 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003507 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003508 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003509 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510 }
3511
3512 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3513 (unsigned long)adapter);
3514
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003515 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003516 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 "ehea_neq", adapter);
3518 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003519 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003520 goto out_kill_eq;
3521 }
3522
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003523 ret = ehea_create_device_sysfs(dev);
3524 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003525 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 ret = ehea_setup_ports(adapter);
3528 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003529 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003530 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 }
3532
3533 ret = 0;
3534 goto out;
3535
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003536out_rem_dev_sysfs:
3537 ehea_remove_device_sysfs(dev);
3538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003540 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003541
3542out_kill_eq:
3543 ehea_destroy_eq(adapter->neq);
3544
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003545out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003546 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003548
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003549out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003550 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003551
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003552 return ret;
3553}
3554
Grant Likely2dc11582010-08-06 09:25:50 -06003555static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003556{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003557 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003558 int i;
3559
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003560 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561 if (adapter->port[i]) {
3562 ehea_shutdown_single_port(adapter->port[i]);
3563 adapter->port[i] = NULL;
3564 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003565
3566 ehea_remove_device_sysfs(dev);
3567
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003568 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003569 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570
3571 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003572 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003573 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003575
Thomas Klein21eee2d2008-02-13 16:18:33 +01003576 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003577
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003578 return 0;
3579}
3580
Thomas Klein21eee2d2008-02-13 16:18:33 +01003581void ehea_crash_handler(void)
3582{
3583 int i;
3584
3585 if (ehea_fw_handles.arr)
3586 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3587 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3588 ehea_fw_handles.arr[i].fwh,
3589 FORCE_FREE);
3590
3591 if (ehea_bcmc_regs.arr)
3592 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3593 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3594 ehea_bcmc_regs.arr[i].port_id,
3595 ehea_bcmc_regs.arr[i].reg_type,
3596 ehea_bcmc_regs.arr[i].macaddr,
3597 0, H_DEREG_BCMC);
3598}
3599
Hannes Hering48cfb142008-05-07 14:43:36 +02003600static int ehea_mem_notifier(struct notifier_block *nb,
3601 unsigned long action, void *data)
3602{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003603 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003604 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003605
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003606 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003607
Hannes Hering48cfb142008-05-07 14:43:36 +02003608 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003609 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003610 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003611 /* Readd canceled memory block */
3612 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003613 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003614 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003615 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003616 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003617 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003618 break;
3619 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003620 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003621 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003622 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003623 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003624 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003625 break;
3626 default:
3627 break;
3628 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003629
3630 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003631 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003632
Thomas Kleina7c561f22010-04-20 23:11:31 +00003633out_unlock:
3634 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003635 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003636}
3637
3638static struct notifier_block ehea_mem_nb = {
3639 .notifier_call = ehea_mem_notifier,
3640};
3641
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003642static int ehea_reboot_notifier(struct notifier_block *nb,
3643 unsigned long action, void *unused)
3644{
3645 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003646 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003647 ibmebus_unregister_driver(&ehea_driver);
3648 }
3649 return NOTIFY_DONE;
3650}
3651
3652static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003653 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003654};
3655
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003656static int check_module_parm(void)
3657{
3658 int ret = 0;
3659
3660 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3661 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003662 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003663 ret = -EINVAL;
3664 }
3665 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3666 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003667 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003668 ret = -EINVAL;
3669 }
3670 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3671 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003672 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003673 ret = -EINVAL;
3674 }
3675 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3676 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003677 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003678 ret = -EINVAL;
3679 }
3680
3681 return ret;
3682}
3683
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003684static ssize_t ehea_show_capabilities(struct device_driver *drv,
3685 char *buf)
3686{
3687 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3688}
3689
3690static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3691 ehea_show_capabilities, NULL);
3692
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003693int __init ehea_module_init(void)
3694{
3695 int ret;
3696
Joe Perches8c4877a2010-12-13 10:05:14 -08003697 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003698
Thomas Klein21eee2d2008-02-13 16:18:33 +01003699 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3700 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3701
Daniel Walker9f71a562008-03-28 14:41:26 -07003702 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003703 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003704
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003705 ret = check_module_parm();
3706 if (ret)
3707 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003708
3709 ret = ehea_create_busmap();
3710 if (ret)
3711 goto out;
3712
Thomas Klein21eee2d2008-02-13 16:18:33 +01003713 ret = register_reboot_notifier(&ehea_reboot_nb);
3714 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003715 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003716
Hannes Hering48cfb142008-05-07 14:43:36 +02003717 ret = register_memory_notifier(&ehea_mem_nb);
3718 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003719 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003720
Joe Perchesc061b182010-08-23 18:20:03 +00003721 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003722 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003723 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003724
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003725 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003726 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003727 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003728 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003729 }
3730
3731 ret = driver_create_file(&ehea_driver.driver,
3732 &driver_attr_capabilities);
3733 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003734 pr_err("failed to register capabilities attribute, ret=%d\n",
3735 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003736 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003737 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003738
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 return ret;
3740
3741out3:
3742 ibmebus_unregister_driver(&ehea_driver);
3743out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003744 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003745 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003746 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003747out:
3748 return ret;
3749}
3750
3751static void __exit ehea_module_exit(void)
3752{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003753 int ret;
3754
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003755 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003756 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003757 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003758 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003759 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003760 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003761 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003762 kfree(ehea_fw_handles.arr);
3763 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003764 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003765}
3766
3767module_init(ehea_module_init);
3768module_exit(ehea_module_exit);