blob: 3fd5a240034840d223cf43095bc76599811755e6 [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{
Joe Perches8e95a202009-12-03 07:58:21 +0000686 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
687 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700688
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800689 if (skb->dev->features & NETIF_F_LRO) {
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700690 if (vlan_extracted)
691 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
692 pr->port->vgrp,
693 cqe->vlan_tag,
694 cqe);
695 else
696 lro_receive_skb(&pr->lro_mgr, skb, cqe);
697 } else {
698 if (vlan_extracted)
699 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
700 cqe->vlan_tag);
701 else
702 netif_receive_skb(skb);
703 }
704}
705
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700706static int ehea_proc_rwqes(struct net_device *dev,
707 struct ehea_port_res *pr,
708 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200709{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100710 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 struct ehea_qp *qp = pr->qp;
712 struct ehea_cqe *cqe;
713 struct sk_buff *skb;
714 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
715 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
716 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
717 int skb_arr_rq1_len = pr->rq1_skba.len;
718 int skb_arr_rq2_len = pr->rq2_skba.len;
719 int skb_arr_rq3_len = pr->rq3_skba.len;
720 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000721 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700722 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723
724 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
725 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200726
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700728 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 ehea_inc_rq1(qp);
730 processed_rq1++;
731 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200732 if (netif_msg_rx_status(port))
733 ehea_dump(cqe, sizeof(*cqe), "CQE");
734
735 last_wqe_index = wqe_index;
736 rmb();
737 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600738 if (rq == 1) {
739 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200740 skb = get_skb_by_index_ll(skb_arr_rq1,
741 skb_arr_rq1_len,
742 wqe_index);
743 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800744 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800745 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100746
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700747 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000749 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800750 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000752 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200753 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600754 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200755 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700756 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600757 } else if (rq == 2) {
758 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200759 skb = get_skb_by_index(skb_arr_rq2,
760 skb_arr_rq2_len, cqe);
761 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800762 netif_err(port, rx_err, dev,
763 "rq2: 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_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600768 } else {
769 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200770 skb = get_skb_by_index(skb_arr_rq3,
771 skb_arr_rq3_len, cqe);
772 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800773 netif_err(port, rx_err, dev,
774 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200775 break;
776 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700777 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200778 processed_rq3++;
779 }
780
Breno Leitaoce45b872010-10-27 08:45:14 +0000781 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700782 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100783 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100784 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200785 port_reset = ehea_treat_poll_error(pr, rq, cqe,
786 &processed_rq2,
787 &processed_rq3);
788 if (port_reset)
789 break;
790 }
791 cqe = ehea_poll_rq1(qp, &wqe_index);
792 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800793 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700794 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200795
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200796 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000797 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200798
799 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
800 ehea_refill_rq2(pr, processed_rq2);
801 ehea_refill_rq3(pr, processed_rq3);
802
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700803 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200804}
805
Andre Detsch2928db42010-08-17 05:49:12 +0000806#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
807
808static void reset_sq_restart_flag(struct ehea_port *port)
809{
810 int i;
811
812 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
813 struct ehea_port_res *pr = &port->port_res[i];
814 pr->sq_restart_flag = 0;
815 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000816 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000817}
818
819static void check_sqs(struct ehea_port *port)
820{
821 struct ehea_swqe *swqe;
822 int swqe_index;
823 int i, k;
824
825 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
826 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000827 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000828 k = 0;
829 swqe = ehea_get_swqe(pr->qp, &swqe_index);
830 memset(swqe, 0, SWQE_HEADER_SIZE);
831 atomic_dec(&pr->swqe_avail);
832
833 swqe->tx_control |= EHEA_SWQE_PURGE;
834 swqe->wr_id = SWQE_RESTART_CHECK;
835 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
836 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
837 swqe->immediate_data_length = 80;
838
839 ehea_post_swqe(pr->qp, swqe);
840
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000841 ret = wait_event_timeout(port->restart_wq,
842 pr->sq_restart_flag == 0,
843 msecs_to_jiffies(100));
844
845 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800846 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000847 ehea_schedule_port_reset(pr->port);
848 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000849 }
850 }
Andre Detsch2928db42010-08-17 05:49:12 +0000851}
852
853
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100854static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200855{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100856 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857 struct ehea_cq *send_cq = pr->send_cq;
858 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100859 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200860 int cqe_counter = 0;
861 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100862 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200863 unsigned long flags;
864
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100865 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600866 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100867 ehea_inc_cq(send_cq);
868
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200869 cqe_counter++;
870 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000871
872 if (cqe->wr_id == SWQE_RESTART_CHECK) {
873 pr->sq_restart_flag = 1;
874 swqe_av++;
875 break;
876 }
877
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200878 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800879 pr_err("Bad send completion status=0x%04X\n",
880 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000881
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882 if (netif_msg_tx_err(pr->port))
883 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000884
885 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800886 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000887 ehea_schedule_port_reset(pr->port);
888 break;
889 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200890 }
891
892 if (netif_msg_tx_done(pr->port))
893 ehea_dump(cqe, sizeof(*cqe), "CQE");
894
895 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100896 == EHEA_SWQE2_TYPE)) {
897
898 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
899 skb = pr->sq_skba.arr[index];
900 dev_kfree_skb(skb);
901 pr->sq_skba.arr[index] = NULL;
902 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200903
904 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
905 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100906
907 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700908 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200909
910 ehea_update_feca(send_cq, cqe_counter);
911 atomic_add(swqe_av, &pr->swqe_avail);
912
913 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100914
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200915 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
916 >= pr->swqe_refill_th)) {
917 netif_wake_queue(pr->port->netdev);
918 pr->queue_stopped = 0;
919 }
920 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000921 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200922
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100923 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200924}
925
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100926#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700927#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100928
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930{
Doug Maxey508d2b52008-01-31 20:20:49 -0600931 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
932 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700933 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100934 struct ehea_cqe *cqe;
935 struct ehea_cqe *cqe_skb = NULL;
936 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700937 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938
939 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700940 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100941
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700942 if (!force_irq)
943 rx += ehea_proc_rwqes(dev, pr, budget - rx);
944
945 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700947 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800948 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100949 ehea_reset_cq_ep(pr->recv_cq);
950 ehea_reset_cq_ep(pr->send_cq);
951 ehea_reset_cq_n1(pr->recv_cq);
952 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000953 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100954 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
955 cqe_skb = ehea_poll_cq(pr->send_cq);
956
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100957 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700958 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100959
Ben Hutchings288379f2009-01-19 16:43:59 -0800960 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700961 return rx;
962
963 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
964 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100965 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100966
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700967 pr->poll_counter++;
968 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200969}
970
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200971#ifdef CONFIG_NET_POLL_CONTROLLER
972static void ehea_netpoll(struct net_device *dev)
973{
974 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700975 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200976
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700977 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800978 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200979}
980#endif
981
David Howells7d12e782006-10-05 14:55:46 +0100982static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983{
984 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100985
Ben Hutchings288379f2009-01-19 16:43:59 -0800986 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100987
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988 return IRQ_HANDLED;
989}
990
David Howells7d12e782006-10-05 14:55:46 +0100991static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992{
993 struct ehea_port *port = param;
994 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100995 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200996 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000997 u64 resource_type, aer, aerr;
998 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999
1000 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001001
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001002 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001003 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -08001004 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1005 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001006
1007 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001008
1009 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1010 &aer, &aerr);
1011
1012 if (resource_type == EHEA_AER_RESTYPE_QP) {
1013 if ((aer & EHEA_AER_RESET_MASK) ||
1014 (aerr & EHEA_AERR_RESET_MASK))
1015 reset_port = 1;
1016 } else
1017 reset_port = 1; /* Reset in case of CQ or EQ error */
1018
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001019 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001020 }
1021
Thomas Kleinea96cea2010-04-20 23:10:55 +00001022 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001023 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001024 ehea_schedule_port_reset(port);
1025 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001026
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001027 return IRQ_HANDLED;
1028}
1029
1030static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1031 int logical_port)
1032{
1033 int i;
1034
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001035 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001036 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001037 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001038 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001039 return NULL;
1040}
1041
1042int ehea_sense_port_attr(struct ehea_port *port)
1043{
1044 int ret;
1045 u64 hret;
1046 struct hcp_ehea_port_cb0 *cb0;
1047
Doug Maxey508d2b52008-01-31 20:20:49 -06001048 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001049 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001050 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001051 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001052 ret = -ENOMEM;
1053 goto out;
1054 }
1055
1056 hret = ehea_h_query_ehea_port(port->adapter->handle,
1057 port->logical_port_id, H_PORT_CB0,
1058 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1059 cb0);
1060 if (hret != H_SUCCESS) {
1061 ret = -EIO;
1062 goto out_free;
1063 }
1064
1065 /* MAC address */
1066 port->mac_addr = cb0->port_mac_addr << 16;
1067
Doug Maxey508d2b52008-01-31 20:20:49 -06001068 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001069 ret = -EADDRNOTAVAIL;
1070 goto out_free;
1071 }
1072
1073 /* Port speed */
1074 switch (cb0->port_speed) {
1075 case H_SPEED_10M_H:
1076 port->port_speed = EHEA_SPEED_10M;
1077 port->full_duplex = 0;
1078 break;
1079 case H_SPEED_10M_F:
1080 port->port_speed = EHEA_SPEED_10M;
1081 port->full_duplex = 1;
1082 break;
1083 case H_SPEED_100M_H:
1084 port->port_speed = EHEA_SPEED_100M;
1085 port->full_duplex = 0;
1086 break;
1087 case H_SPEED_100M_F:
1088 port->port_speed = EHEA_SPEED_100M;
1089 port->full_duplex = 1;
1090 break;
1091 case H_SPEED_1G_F:
1092 port->port_speed = EHEA_SPEED_1G;
1093 port->full_duplex = 1;
1094 break;
1095 case H_SPEED_10G_F:
1096 port->port_speed = EHEA_SPEED_10G;
1097 port->full_duplex = 1;
1098 break;
1099 default:
1100 port->port_speed = 0;
1101 port->full_duplex = 0;
1102 break;
1103 }
1104
Thomas Kleine919b592007-01-22 12:53:20 +01001105 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001106 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001108 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001109 if (use_mcs)
1110 port->num_def_qps = cb0->num_default_qps;
1111 else
1112 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001113
1114 if (!port->num_def_qps) {
1115 ret = -EINVAL;
1116 goto out_free;
1117 }
1118
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001119 port->num_tx_qps = num_tx_qps;
1120
1121 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001122 port->num_add_tx_qps = 0;
1123 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001124 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001125
1126 ret = 0;
1127out_free:
1128 if (ret || netif_msg_probe(port))
1129 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001130 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001131out:
1132 return ret;
1133}
1134
1135int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1136{
1137 struct hcp_ehea_port_cb4 *cb4;
1138 u64 hret;
1139 int ret = 0;
1140
Thomas Klein3faf2692009-01-21 14:45:33 -08001141 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001142 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001143 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001144 ret = -ENOMEM;
1145 goto out;
1146 }
1147
1148 cb4->port_speed = port_speed;
1149
1150 netif_carrier_off(port->netdev);
1151
1152 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1153 port->logical_port_id,
1154 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1155 if (hret == H_SUCCESS) {
1156 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1157
1158 hret = ehea_h_query_ehea_port(port->adapter->handle,
1159 port->logical_port_id,
1160 H_PORT_CB4, H_PORT_CB4_SPEED,
1161 cb4);
1162 if (hret == H_SUCCESS) {
1163 switch (cb4->port_speed) {
1164 case H_SPEED_10M_H:
1165 port->port_speed = EHEA_SPEED_10M;
1166 port->full_duplex = 0;
1167 break;
1168 case H_SPEED_10M_F:
1169 port->port_speed = EHEA_SPEED_10M;
1170 port->full_duplex = 1;
1171 break;
1172 case H_SPEED_100M_H:
1173 port->port_speed = EHEA_SPEED_100M;
1174 port->full_duplex = 0;
1175 break;
1176 case H_SPEED_100M_F:
1177 port->port_speed = EHEA_SPEED_100M;
1178 port->full_duplex = 1;
1179 break;
1180 case H_SPEED_1G_F:
1181 port->port_speed = EHEA_SPEED_1G;
1182 port->full_duplex = 1;
1183 break;
1184 case H_SPEED_10G_F:
1185 port->port_speed = EHEA_SPEED_10G;
1186 port->full_duplex = 1;
1187 break;
1188 default:
1189 port->port_speed = 0;
1190 port->full_duplex = 0;
1191 break;
1192 }
1193 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001194 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001195 ret = -EIO;
1196 }
1197 } else {
1198 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001199 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200 ret = -EPERM;
1201 } else {
1202 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001203 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001204 }
1205 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001206 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1207 netif_carrier_on(port->netdev);
1208
Thomas Klein3faf2692009-01-21 14:45:33 -08001209 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001210out:
1211 return ret;
1212}
1213
1214static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1215{
1216 int ret;
1217 u8 ec;
1218 u8 portnum;
1219 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001221
1222 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1223 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1224 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226
1227 switch (ec) {
1228 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1229
1230 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001231 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001232 break;
1233 }
1234
1235 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001236 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001237 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001239 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001240 break;
1241 }
1242
Joe Perches8c4877a2010-12-13 10:05:14 -08001243 netif_info(port, link, dev,
1244 "Logical port up: %dMbps %s Duplex\n",
1245 port->port_speed,
1246 port->full_duplex == 1 ?
1247 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248
Joe Perches8c4877a2010-12-13 10:05:14 -08001249 netif_carrier_on(dev);
1250 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251 }
1252 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001253 if (netif_carrier_ok(dev)) {
1254 netif_info(port, link, dev,
1255 "Logical port down\n");
1256 netif_carrier_off(dev);
1257 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001258 }
1259
1260 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001261 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001262 netif_info(port, link, dev,
1263 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001264 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001265 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001267 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001268 netif_info(port, link, dev,
1269 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001270 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001271 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 }
1273
1274 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001275 netdev_info(dev,
1276 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001277 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001278 netdev_info(dev,
1279 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001280
1281 break;
1282 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001283 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001284 break;
1285 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001286 netdev_info(dev, "Port malfunction\n");
1287 netif_carrier_off(dev);
1288 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001289 break;
1290 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001291 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 break;
1293 }
1294}
1295
1296static void ehea_neq_tasklet(unsigned long data)
1297{
Doug Maxey508d2b52008-01-31 20:20:49 -06001298 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299 struct ehea_eqe *eqe;
1300 u64 event_mask;
1301
1302 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001303 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001304
1305 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001306 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307 ehea_parse_eqe(adapter, eqe->entry);
1308 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001309 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310 }
1311
1312 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1313 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1314 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1315
1316 ehea_h_reset_events(adapter->handle,
1317 adapter->neq->fw_handle, event_mask);
1318}
1319
David Howells7d12e782006-10-05 14:55:46 +01001320static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001321{
1322 struct ehea_adapter *adapter = param;
1323 tasklet_hi_schedule(&adapter->neq_tasklet);
1324 return IRQ_HANDLED;
1325}
1326
1327
1328static int ehea_fill_port_res(struct ehea_port_res *pr)
1329{
1330 int ret;
1331 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1332
Breno Leitaof76957f2011-01-11 07:45:57 +00001333 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334
Thomas Kleine2878802009-01-21 14:45:57 -08001335 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336
1337 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1338
1339 return ret;
1340}
1341
1342static int ehea_reg_interrupts(struct net_device *dev)
1343{
1344 struct ehea_port *port = netdev_priv(dev);
1345 struct ehea_port_res *pr;
1346 int i, ret;
1347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348
1349 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1350 dev->name);
1351
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001352 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001353 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001354 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001356 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1357 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358 goto out_free_qpeq;
1359 }
1360
Joe Perches8c4877a2010-12-13 10:05:14 -08001361 netif_info(port, ifup, dev,
1362 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1363 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001365
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1367 pr = &port->port_res[i];
1368 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001369 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001370 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001371 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001372 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001373 pr);
1374 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001375 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1376 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001377 goto out_free_req;
1378 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001379 netif_info(port, ifup, dev,
1380 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1381 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001382 }
1383out:
1384 return ret;
1385
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001386
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387out_free_req:
1388 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001389 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001390 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001392
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001393out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001394 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001395 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001396
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001398
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001399}
1400
1401static void ehea_free_interrupts(struct net_device *dev)
1402{
1403 struct ehea_port *port = netdev_priv(dev);
1404 struct ehea_port_res *pr;
1405 int i;
1406
1407 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001408
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001409 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1410 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001411 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001412 netif_info(port, intr, dev,
1413 "free send irq for res %d with handle 0x%X\n",
1414 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001415 }
1416
1417 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001418 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001419 netif_info(port, intr, dev,
1420 "associated event interrupt for handle 0x%X freed\n",
1421 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001422}
1423
1424static int ehea_configure_port(struct ehea_port *port)
1425{
1426 int ret, i;
1427 u64 hret, mask;
1428 struct hcp_ehea_port_cb0 *cb0;
1429
1430 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001431 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001432 if (!cb0)
1433 goto out;
1434
1435 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1436 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1437 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1440 PXLY_RC_VLAN_FILTER)
1441 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1442
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001443 for (i = 0; i < port->num_mcs; i++)
1444 if (use_mcs)
1445 cb0->default_qpn_arr[i] =
1446 port->port_res[i].qp->init_attr.qp_nr;
1447 else
1448 cb0->default_qpn_arr[i] =
1449 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001450
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001451 if (netif_msg_ifup(port))
1452 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1453
1454 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1455 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1456
1457 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1458 port->logical_port_id,
1459 H_PORT_CB0, mask, cb0);
1460 ret = -EIO;
1461 if (hret != H_SUCCESS)
1462 goto out_free;
1463
1464 ret = 0;
1465
1466out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001467 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001468out:
1469 return ret;
1470}
1471
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001472int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001473{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001474 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475 struct ehea_adapter *adapter = pr->port->adapter;
1476
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001477 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1478 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479 goto out;
1480
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001481 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1482 if (ret)
1483 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484
1485 return 0;
1486
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001487out_free:
1488 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001489out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001490 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491 return -EIO;
1492}
1493
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001494int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495{
Joe Perches8e95a202009-12-03 07:58:21 +00001496 if ((ehea_rem_mr(&pr->send_mr)) ||
1497 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001498 return -EIO;
1499 else
1500 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001501}
1502
1503static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1504{
Doug Maxey508d2b52008-01-31 20:20:49 -06001505 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001507 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001508 if (!q_skba->arr)
1509 return -ENOMEM;
1510
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511 q_skba->len = max_q_entries;
1512 q_skba->index = 0;
1513 q_skba->os_skbs = 0;
1514
1515 return 0;
1516}
1517
1518static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1519 struct port_res_cfg *pr_cfg, int queue_token)
1520{
1521 struct ehea_adapter *adapter = port->adapter;
1522 enum ehea_eq_type eq_type = EHEA_EQ;
1523 struct ehea_qp_init_attr *init_attr = NULL;
1524 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001525 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1526
1527 tx_bytes = pr->tx_bytes;
1528 tx_packets = pr->tx_packets;
1529 rx_bytes = pr->rx_bytes;
1530 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001531
1532 memset(pr, 0, sizeof(struct ehea_port_res));
1533
Breno Leitaoce45b872010-10-27 08:45:14 +00001534 pr->tx_bytes = rx_bytes;
1535 pr->tx_packets = tx_packets;
1536 pr->rx_bytes = rx_bytes;
1537 pr->rx_packets = rx_packets;
1538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001539 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540 spin_lock_init(&pr->xmit_lock);
1541 spin_lock_init(&pr->netif_queue);
1542
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001543 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1544 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001545 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001546 goto out_free;
1547 }
1548
1549 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001550 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 port->logical_port_id);
1552 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001553 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001554 goto out_free;
1555 }
1556
1557 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001558 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001559 port->logical_port_id);
1560 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001561 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001562 goto out_free;
1563 }
1564
1565 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001566 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1567 pr->send_cq->attr.act_nr_of_cqes,
1568 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001569
1570 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1571 if (!init_attr) {
1572 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001573 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001574 goto out_free;
1575 }
1576
1577 init_attr->low_lat_rq1 = 1;
1578 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1579 init_attr->rq_count = 3;
1580 init_attr->qp_token = queue_token;
1581 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1582 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1583 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1584 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1585 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1586 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1587 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1588 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1589 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1590 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1591 init_attr->port_nr = port->logical_port_id;
1592 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1593 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1594 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1595
1596 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1597 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001598 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599 ret = -EIO;
1600 goto out_free;
1601 }
1602
1603 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001604 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",
1605 init_attr->qp_nr,
1606 init_attr->act_nr_send_wqes,
1607 init_attr->act_nr_rwqes_rq1,
1608 init_attr->act_nr_rwqes_rq2,
1609 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001610
Thomas Klein44fb3122008-04-04 15:04:53 +02001611 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1612
1613 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001614 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1615 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1616 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1617 if (ret)
1618 goto out_free;
1619
1620 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1621 if (ehea_gen_smrs(pr) != 0) {
1622 ret = -EIO;
1623 goto out_free;
1624 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001625
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001626 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1627
1628 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001629
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001630 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001631
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001632 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1633 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1634 pr->lro_mgr.lro_arr = pr->lro_desc;
1635 pr->lro_mgr.get_skb_header = get_skb_hdr;
1636 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1637 pr->lro_mgr.dev = port->netdev;
1638 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1639 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001641 ret = 0;
1642 goto out;
1643
1644out_free:
1645 kfree(init_attr);
1646 vfree(pr->sq_skba.arr);
1647 vfree(pr->rq1_skba.arr);
1648 vfree(pr->rq2_skba.arr);
1649 vfree(pr->rq3_skba.arr);
1650 ehea_destroy_qp(pr->qp);
1651 ehea_destroy_cq(pr->send_cq);
1652 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001653 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654out:
1655 return ret;
1656}
1657
1658static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1659{
1660 int ret, i;
1661
Hannes Hering357eb462009-08-04 11:48:39 -07001662 if (pr->qp)
1663 netif_napi_del(&pr->napi);
1664
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001665 ret = ehea_destroy_qp(pr->qp);
1666
1667 if (!ret) {
1668 ehea_destroy_cq(pr->send_cq);
1669 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001670 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001671
1672 for (i = 0; i < pr->rq1_skba.len; i++)
1673 if (pr->rq1_skba.arr[i])
1674 dev_kfree_skb(pr->rq1_skba.arr[i]);
1675
1676 for (i = 0; i < pr->rq2_skba.len; i++)
1677 if (pr->rq2_skba.arr[i])
1678 dev_kfree_skb(pr->rq2_skba.arr[i]);
1679
1680 for (i = 0; i < pr->rq3_skba.len; i++)
1681 if (pr->rq3_skba.arr[i])
1682 dev_kfree_skb(pr->rq3_skba.arr[i]);
1683
1684 for (i = 0; i < pr->sq_skba.len; i++)
1685 if (pr->sq_skba.arr[i])
1686 dev_kfree_skb(pr->sq_skba.arr[i]);
1687
1688 vfree(pr->rq1_skba.arr);
1689 vfree(pr->rq2_skba.arr);
1690 vfree(pr->rq3_skba.arr);
1691 vfree(pr->sq_skba.arr);
1692 ret = ehea_rem_smrs(pr);
1693 }
1694 return ret;
1695}
1696
1697/*
1698 * The write_* functions store information in swqe which is used by
1699 * the hardware to calculate the ip/tcp/udp checksum
1700 */
1701
1702static inline void write_ip_start_end(struct ehea_swqe *swqe,
1703 const struct sk_buff *skb)
1704{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001705 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001706 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001707}
1708
1709static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1710 const struct sk_buff *skb)
1711{
1712 swqe->tcp_offset =
1713 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1714
1715 swqe->tcp_end = (u16)skb->len - 1;
1716}
1717
1718static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1719 const struct sk_buff *skb)
1720{
1721 swqe->tcp_offset =
1722 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1723
1724 swqe->tcp_end = (u16)skb->len - 1;
1725}
1726
1727
1728static void write_swqe2_TSO(struct sk_buff *skb,
1729 struct ehea_swqe *swqe, u32 lkey)
1730{
1731 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1732 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001733 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001734 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735
1736 /* Packet is TCP with TSO enabled */
1737 swqe->tx_control |= EHEA_SWQE_TSO;
1738 swqe->mss = skb_shinfo(skb)->gso_size;
1739 /* copy only eth/ip/tcp headers to immediate data and
1740 * the rest of skb->data to sg1entry
1741 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001742 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001743
Eric Dumazete743d312010-04-14 15:59:40 -07001744 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745
1746 if (skb_data_size >= headersize) {
1747 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001748 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001749 swqe->immediate_data_length = headersize;
1750
1751 if (skb_data_size > headersize) {
1752 /* set sg1entry data */
1753 sg1entry->l_key = lkey;
1754 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001755 sg1entry->vaddr =
1756 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757 swqe->descriptors++;
1758 }
1759 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001760 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761}
1762
1763static void write_swqe2_nonTSO(struct sk_buff *skb,
1764 struct ehea_swqe *swqe, u32 lkey)
1765{
Eric Dumazete743d312010-04-14 15:59:40 -07001766 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001767 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1768 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001769
1770 /* Packet is any nonTSO type
1771 *
1772 * Copy as much as possible skb->data to immediate data and
1773 * the rest to sg1entry
1774 */
1775 if (skb_data_size >= SWQE2_MAX_IMM) {
1776 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001777 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001778
1779 swqe->immediate_data_length = SWQE2_MAX_IMM;
1780
1781 if (skb_data_size > SWQE2_MAX_IMM) {
1782 /* copy sg1entry data */
1783 sg1entry->l_key = lkey;
1784 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001785 sg1entry->vaddr =
1786 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001787 swqe->descriptors++;
1788 }
1789 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001790 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001791 swqe->immediate_data_length = skb_data_size;
1792 }
1793}
1794
1795static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1796 struct ehea_swqe *swqe, u32 lkey)
1797{
1798 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1799 skb_frag_t *frag;
1800 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001801
1802 nfrags = skb_shinfo(skb)->nr_frags;
1803 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001804 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001805 swqe->descriptors = 0;
1806 sg1entry_contains_frag_data = 0;
1807
1808 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1809 write_swqe2_TSO(skb, swqe, lkey);
1810 else
1811 write_swqe2_nonTSO(skb, swqe, lkey);
1812
1813 /* write descriptors */
1814 if (nfrags > 0) {
1815 if (swqe->descriptors == 0) {
1816 /* sg1entry not yet used */
1817 frag = &skb_shinfo(skb)->frags[0];
1818
1819 /* copy sg1entry data */
1820 sg1entry->l_key = lkey;
1821 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001822 sg1entry->vaddr =
1823 ehea_map_vaddr(page_address(frag->page)
1824 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001825 swqe->descriptors++;
1826 sg1entry_contains_frag_data = 1;
1827 }
1828
1829 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1830
1831 frag = &skb_shinfo(skb)->frags[i];
1832 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1833
1834 sgentry->l_key = lkey;
1835 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001836 sgentry->vaddr =
1837 ehea_map_vaddr(page_address(frag->page)
1838 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001839 swqe->descriptors++;
1840 }
1841 }
1842}
1843
1844static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1845{
1846 int ret = 0;
1847 u64 hret;
1848 u8 reg_type;
1849
1850 /* De/Register untagged packets */
1851 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1852 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1853 port->logical_port_id,
1854 reg_type, port->mac_addr, 0, hcallid);
1855 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001856 pr_err("%sregistering bc address failed (tagged)\n",
1857 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001858 ret = -EIO;
1859 goto out_herr;
1860 }
1861
1862 /* De/Register VLAN packets */
1863 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1864 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1865 port->logical_port_id,
1866 reg_type, port->mac_addr, 0, hcallid);
1867 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001868 pr_err("%sregistering bc address failed (vlan)\n",
1869 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001870 ret = -EIO;
1871 }
1872out_herr:
1873 return ret;
1874}
1875
1876static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1877{
1878 struct ehea_port *port = netdev_priv(dev);
1879 struct sockaddr *mac_addr = sa;
1880 struct hcp_ehea_port_cb0 *cb0;
1881 int ret;
1882 u64 hret;
1883
1884 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1885 ret = -EADDRNOTAVAIL;
1886 goto out;
1887 }
1888
Thomas Klein3faf2692009-01-21 14:45:33 -08001889 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001890 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001891 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001892 ret = -ENOMEM;
1893 goto out;
1894 }
1895
1896 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1897
1898 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1899
1900 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1901 port->logical_port_id, H_PORT_CB0,
1902 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1903 if (hret != H_SUCCESS) {
1904 ret = -EIO;
1905 goto out_free;
1906 }
1907
1908 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1909
1910 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001911 if (port->state == EHEA_PORT_UP) {
1912 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1913 if (ret)
1914 goto out_upregs;
1915 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001916
1917 port->mac_addr = cb0->port_mac_addr << 16;
1918
1919 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001920 if (port->state == EHEA_PORT_UP) {
1921 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1922 if (ret)
1923 goto out_upregs;
1924 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001925
1926 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001927
1928out_upregs:
1929 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001930out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001931 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932out:
1933 return ret;
1934}
1935
1936static void ehea_promiscuous_error(u64 hret, int enable)
1937{
Thomas Klein7674a582007-01-22 12:54:20 +01001938 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001939 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1940 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001941 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001942 pr_err("failed %sabling promiscuous mode\n",
1943 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001944}
1945
1946static void ehea_promiscuous(struct net_device *dev, int enable)
1947{
1948 struct ehea_port *port = netdev_priv(dev);
1949 struct hcp_ehea_port_cb7 *cb7;
1950 u64 hret;
1951
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001952 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001953 return;
1954
Thomas Klein3faf2692009-01-21 14:45:33 -08001955 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001956 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001957 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001958 goto out;
1959 }
1960
1961 /* Modify Pxs_DUCQPN in CB7 */
1962 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1963
1964 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1965 port->logical_port_id,
1966 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1967 if (hret) {
1968 ehea_promiscuous_error(hret, enable);
1969 goto out;
1970 }
1971
1972 port->promisc = enable;
1973out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001974 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001975}
1976
1977static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1978 u32 hcallid)
1979{
1980 u64 hret;
1981 u8 reg_type;
1982
1983 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1984 | EHEA_BCMC_UNTAGGED;
1985
1986 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1987 port->logical_port_id,
1988 reg_type, mc_mac_addr, 0, hcallid);
1989 if (hret)
1990 goto out;
1991
1992 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1993 | EHEA_BCMC_VLANID_ALL;
1994
1995 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1996 port->logical_port_id,
1997 reg_type, mc_mac_addr, 0, hcallid);
1998out:
1999 return hret;
2000}
2001
2002static int ehea_drop_multicast_list(struct net_device *dev)
2003{
2004 struct ehea_port *port = netdev_priv(dev);
2005 struct ehea_mc_list *mc_entry = port->mc_list;
2006 struct list_head *pos;
2007 struct list_head *temp;
2008 int ret = 0;
2009 u64 hret;
2010
2011 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2012 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2013
2014 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2015 H_DEREG_BCMC);
2016 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002017 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002018 ret = -EIO;
2019 }
2020
2021 list_del(pos);
2022 kfree(mc_entry);
2023 }
2024 return ret;
2025}
2026
2027static void ehea_allmulti(struct net_device *dev, int enable)
2028{
2029 struct ehea_port *port = netdev_priv(dev);
2030 u64 hret;
2031
2032 if (!port->allmulti) {
2033 if (enable) {
2034 /* Enable ALLMULTI */
2035 ehea_drop_multicast_list(dev);
2036 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2037 if (!hret)
2038 port->allmulti = 1;
2039 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002040 netdev_err(dev,
2041 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002042 }
2043 } else
2044 if (!enable) {
2045 /* Disable ALLMULTI */
2046 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2047 if (!hret)
2048 port->allmulti = 0;
2049 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002050 netdev_err(dev,
2051 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052 }
2053}
2054
Doug Maxey508d2b52008-01-31 20:20:49 -06002055static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002056{
2057 struct ehea_mc_list *ehea_mcl_entry;
2058 u64 hret;
2059
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002060 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002061 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002062 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 return;
2064 }
2065
2066 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2067
2068 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2069
2070 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2071 H_REG_BCMC);
2072 if (!hret)
2073 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2074 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002075 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002076 kfree(ehea_mcl_entry);
2077 }
2078}
2079
2080static void ehea_set_multicast_list(struct net_device *dev)
2081{
2082 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002083 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002084 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002085
Breno Leitaoa4910b72011-05-23 03:36:35 +00002086 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002087 ehea_promiscuous(dev, 1);
2088 return;
2089 }
2090 ehea_promiscuous(dev, 0);
2091
2092 if (dev->flags & IFF_ALLMULTI) {
2093 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002094 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002095 }
2096 ehea_allmulti(dev, 0);
2097
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002098 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099 ret = ehea_drop_multicast_list(dev);
2100 if (ret) {
2101 /* Dropping the current multicast list failed.
2102 * Enabling ALL_MULTI is the best we can do.
2103 */
2104 ehea_allmulti(dev, 1);
2105 }
2106
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002107 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002108 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2109 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 goto out;
2111 }
2112
Jiri Pirko22bedad2010-04-01 21:22:57 +00002113 netdev_for_each_mc_addr(ha, dev)
2114 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002115
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002116 }
2117out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002118 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002119}
2120
2121static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2122{
2123 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2124 return -EINVAL;
2125 dev->mtu = new_mtu;
2126 return 0;
2127}
2128
2129static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2130 struct ehea_swqe *swqe, u32 lkey)
2131{
2132 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002133 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002134
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002135 /* IPv4 */
2136 swqe->tx_control |= EHEA_SWQE_CRC
2137 | EHEA_SWQE_IP_CHECKSUM
2138 | EHEA_SWQE_TCP_CHECKSUM
2139 | EHEA_SWQE_IMM_DATA_PRESENT
2140 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2141
2142 write_ip_start_end(swqe, skb);
2143
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002144 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002145 if ((iph->frag_off & IP_MF) ||
2146 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002147 /* IP fragment, so don't change cs */
2148 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2149 else
2150 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002151 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152 write_tcp_offset_end(swqe, skb);
2153 }
2154
2155 /* icmp (big data) and ip segmentation packets (all other ip
2156 packets) do not require any special handling */
2157
2158 } else {
2159 /* Other Ethernet Protocol */
2160 swqe->tx_control |= EHEA_SWQE_CRC
2161 | EHEA_SWQE_IMM_DATA_PRESENT
2162 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2163 }
2164
2165 write_swqe2_data(skb, dev, swqe, lkey);
2166}
2167
2168static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2169 struct ehea_swqe *swqe)
2170{
2171 int nfrags = skb_shinfo(skb)->nr_frags;
2172 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2173 skb_frag_t *frag;
2174 int i;
2175
2176 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002177 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002178
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002179 /* IPv4 */
2180 write_ip_start_end(swqe, skb);
2181
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002182 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002183 swqe->tx_control |= EHEA_SWQE_CRC
2184 | EHEA_SWQE_IP_CHECKSUM
2185 | EHEA_SWQE_TCP_CHECKSUM
2186 | EHEA_SWQE_IMM_DATA_PRESENT;
2187
2188 write_tcp_offset_end(swqe, skb);
2189
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002190 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002191 if ((iph->frag_off & IP_MF) ||
2192 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193 /* IP fragment, so don't change cs */
2194 swqe->tx_control |= EHEA_SWQE_CRC
2195 | EHEA_SWQE_IMM_DATA_PRESENT;
2196 else {
2197 swqe->tx_control |= EHEA_SWQE_CRC
2198 | EHEA_SWQE_IP_CHECKSUM
2199 | EHEA_SWQE_TCP_CHECKSUM
2200 | EHEA_SWQE_IMM_DATA_PRESENT;
2201
2202 write_udp_offset_end(swqe, skb);
2203 }
2204 } else {
2205 /* icmp (big data) and
2206 ip segmentation packets (all other ip packets) */
2207 swqe->tx_control |= EHEA_SWQE_CRC
2208 | EHEA_SWQE_IP_CHECKSUM
2209 | EHEA_SWQE_IMM_DATA_PRESENT;
2210 }
2211 } else {
2212 /* Other Ethernet Protocol */
2213 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2214 }
2215 /* copy (immediate) data */
2216 if (nfrags == 0) {
2217 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002218 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 } else {
2220 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002221 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002222 skb_headlen(skb));
2223 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002224
2225 /* ... then copy data from the fragments */
2226 for (i = 0; i < nfrags; i++) {
2227 frag = &skb_shinfo(skb)->frags[i];
2228 memcpy(imm_data,
2229 page_address(frag->page) + frag->page_offset,
2230 frag->size);
2231 imm_data += frag->size;
2232 }
2233 }
2234 swqe->immediate_data_length = skb->len;
2235 dev_kfree_skb(skb);
2236}
2237
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2239{
2240 struct tcphdr *tcp;
2241 u32 tmp;
2242
2243 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002244 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002245 tcp = (struct tcphdr *)(skb_network_header(skb) +
2246 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002247 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002248 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002249 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002250 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002251 return 0;
2252}
2253
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2255{
2256 struct ehea_port *port = netdev_priv(dev);
2257 struct ehea_swqe *swqe;
2258 unsigned long flags;
2259 u32 lkey;
2260 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002261 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002262
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002263 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2264
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002265 if (!spin_trylock(&pr->xmit_lock))
2266 return NETDEV_TX_BUSY;
2267
2268 if (pr->queue_stopped) {
2269 spin_unlock(&pr->xmit_lock);
2270 return NETDEV_TX_BUSY;
2271 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002272
2273 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2274 memset(swqe, 0, SWQE_HEADER_SIZE);
2275 atomic_dec(&pr->swqe_avail);
2276
Eric Dumazete5ccd962010-10-26 19:21:07 +00002277 if (vlan_tx_tag_present(skb)) {
2278 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2279 swqe->vlan_tag = vlan_tx_tag_get(skb);
2280 }
2281
Breno Leitaoce45b872010-10-27 08:45:14 +00002282 pr->tx_packets++;
2283 pr->tx_bytes += skb->len;
2284
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 if (skb->len <= SWQE3_MAX_IMM) {
2286 u32 sig_iv = port->sig_comp_iv;
2287 u32 swqe_num = pr->swqe_id_counter;
2288 ehea_xmit3(skb, dev, swqe);
2289 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2290 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2291 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2292 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2293 sig_iv);
2294 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2295 pr->swqe_ll_count = 0;
2296 } else
2297 pr->swqe_ll_count += 1;
2298 } else {
2299 swqe->wr_id =
2300 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2301 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002302 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2304 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2305
2306 pr->sq_skba.index++;
2307 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2308
2309 lkey = pr->send_mr.lkey;
2310 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002311 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312 }
2313 pr->swqe_id_counter += 1;
2314
Joe Perches8c4877a2010-12-13 10:05:14 -08002315 netif_info(port, tx_queued, dev,
2316 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2317 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002318 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002320 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2321 netif_stop_queue(dev);
2322 swqe->tx_control |= EHEA_SWQE_PURGE;
2323 }
Thomas Klein44c82152007-07-11 16:32:00 +02002324
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002325 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326
2327 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2328 spin_lock_irqsave(&pr->netif_queue, flags);
2329 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002330 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 netif_stop_queue(dev);
2332 pr->queue_stopped = 1;
2333 }
2334 spin_unlock_irqrestore(&pr->netif_queue, flags);
2335 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002336 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002337 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002338
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002339 return NETDEV_TX_OK;
2340}
2341
2342static void ehea_vlan_rx_register(struct net_device *dev,
2343 struct vlan_group *grp)
2344{
2345 struct ehea_port *port = netdev_priv(dev);
2346 struct ehea_adapter *adapter = port->adapter;
2347 struct hcp_ehea_port_cb1 *cb1;
2348 u64 hret;
2349
2350 port->vgrp = grp;
2351
Thomas Klein3faf2692009-01-21 14:45:33 -08002352 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002354 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355 goto out;
2356 }
2357
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002358 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2359 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2360 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002361 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362
Thomas Klein3faf2692009-01-21 14:45:33 -08002363 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364out:
2365 return;
2366}
2367
2368static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2369{
2370 struct ehea_port *port = netdev_priv(dev);
2371 struct ehea_adapter *adapter = port->adapter;
2372 struct hcp_ehea_port_cb1 *cb1;
2373 int index;
2374 u64 hret;
2375
Thomas Klein3faf2692009-01-21 14:45:33 -08002376 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002378 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002379 goto out;
2380 }
2381
2382 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2383 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2384 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002385 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 goto out;
2387 }
2388
2389 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002390 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002391
2392 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2393 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2394 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002395 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002396out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002397 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 return;
2399}
2400
2401static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2402{
2403 struct ehea_port *port = netdev_priv(dev);
2404 struct ehea_adapter *adapter = port->adapter;
2405 struct hcp_ehea_port_cb1 *cb1;
2406 int index;
2407 u64 hret;
2408
Dan Aloni5c15bde2007-03-02 20:44:51 -08002409 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002410
Thomas Klein3faf2692009-01-21 14:45:33 -08002411 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002412 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002413 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414 goto out;
2415 }
2416
2417 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2418 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2419 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002420 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002421 goto out;
2422 }
2423
2424 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002425 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002426
2427 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2428 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2429 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002430 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002431out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002432 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002433}
2434
2435int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2436{
2437 int ret = -EIO;
2438 u64 hret;
2439 u16 dummy16 = 0;
2440 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002441 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002442
Thomas Klein3faf2692009-01-21 14:45:33 -08002443 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444 if (!cb0) {
2445 ret = -ENOMEM;
2446 goto out;
2447 }
2448
2449 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2450 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2451 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002452 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453 goto out;
2454 }
2455
2456 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2457 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2459 &dummy64, &dummy64, &dummy16, &dummy16);
2460 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002461 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 goto out;
2463 }
2464
2465 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2466 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2467 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002468 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002469 goto out;
2470 }
2471
2472 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2473 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2474 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2475 &dummy64, &dummy64, &dummy16, &dummy16);
2476 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002477 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 goto out;
2479 }
2480
2481 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2482 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2483 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002484 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002485 goto out;
2486 }
2487
2488 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2489 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2490 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2491 &dummy64, &dummy64, &dummy16, &dummy16);
2492 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002493 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002494 goto out;
2495 }
2496
2497 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2498 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2499 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002500 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501 goto out;
2502 }
2503
2504 ret = 0;
2505out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002506 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002507 return ret;
2508}
2509
2510static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2511 int add_tx_qps)
2512{
2513 int ret, i;
2514 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2515 enum ehea_eq_type eq_type = EHEA_EQ;
2516
2517 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2518 EHEA_MAX_ENTRIES_EQ, 1);
2519 if (!port->qp_eq) {
2520 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002521 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002522 goto out_kill_eq;
2523 }
2524
2525 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002526 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002527 pr_cfg.max_entries_sq = sq_entries;
2528 pr_cfg.max_entries_rq1 = rq1_entries;
2529 pr_cfg.max_entries_rq2 = rq2_entries;
2530 pr_cfg.max_entries_rq3 = rq3_entries;
2531
2532 pr_cfg_small_rx.max_entries_rcq = 1;
2533 pr_cfg_small_rx.max_entries_scq = sq_entries;
2534 pr_cfg_small_rx.max_entries_sq = sq_entries;
2535 pr_cfg_small_rx.max_entries_rq1 = 1;
2536 pr_cfg_small_rx.max_entries_rq2 = 1;
2537 pr_cfg_small_rx.max_entries_rq3 = 1;
2538
2539 for (i = 0; i < def_qps; i++) {
2540 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2541 if (ret)
2542 goto out_clean_pr;
2543 }
2544 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2545 ret = ehea_init_port_res(port, &port->port_res[i],
2546 &pr_cfg_small_rx, i);
2547 if (ret)
2548 goto out_clean_pr;
2549 }
2550
2551 return 0;
2552
2553out_clean_pr:
2554 while (--i >= 0)
2555 ehea_clean_portres(port, &port->port_res[i]);
2556
2557out_kill_eq:
2558 ehea_destroy_eq(port->qp_eq);
2559 return ret;
2560}
2561
2562static int ehea_clean_all_portres(struct ehea_port *port)
2563{
2564 int ret = 0;
2565 int i;
2566
Doug Maxey508d2b52008-01-31 20:20:49 -06002567 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002568 ret |= ehea_clean_portres(port, &port->port_res[i]);
2569
2570 ret |= ehea_destroy_eq(port->qp_eq);
2571
2572 return ret;
2573}
2574
Thomas Klein35cf2e22007-08-06 13:55:14 +02002575static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002576{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002577 if (adapter->active_ports)
2578 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002579
2580 ehea_rem_mr(&adapter->mr);
2581}
2582
Thomas Klein35cf2e22007-08-06 13:55:14 +02002583static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002584{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002585 if (adapter->active_ports)
2586 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002587
2588 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2589}
2590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591static int ehea_up(struct net_device *dev)
2592{
2593 int ret, i;
2594 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002595
2596 if (port->state == EHEA_PORT_UP)
2597 return 0;
2598
2599 ret = ehea_port_res_setup(port, port->num_def_qps,
2600 port->num_add_tx_qps);
2601 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002602 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002603 goto out;
2604 }
2605
2606 /* Set default QP for this port */
2607 ret = ehea_configure_port(port);
2608 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002609 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610 goto out_clean_pr;
2611 }
2612
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002613 ret = ehea_reg_interrupts(dev);
2614 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002615 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002616 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002617 }
2618
Doug Maxey508d2b52008-01-31 20:20:49 -06002619 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2621 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002622 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 goto out_free_irqs;
2624 }
2625 }
2626
Doug Maxey508d2b52008-01-31 20:20:49 -06002627 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002628 ret = ehea_fill_port_res(&port->port_res[i]);
2629 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002630 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002631 goto out_free_irqs;
2632 }
2633 }
2634
Thomas Klein21eee2d2008-02-13 16:18:33 +01002635 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2636 if (ret) {
2637 ret = -EIO;
2638 goto out_free_irqs;
2639 }
2640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002641 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002642
2643 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002644 goto out;
2645
2646out_free_irqs:
2647 ehea_free_interrupts(dev);
2648
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002649out_clean_pr:
2650 ehea_clean_all_portres(port);
2651out:
Thomas Klein44c82152007-07-11 16:32:00 +02002652 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002653 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002654
Thomas Klein21eee2d2008-02-13 16:18:33 +01002655 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002656 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002657
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002658 return ret;
2659}
2660
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002661static void port_napi_disable(struct ehea_port *port)
2662{
2663 int i;
2664
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002665 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002666 napi_disable(&port->port_res[i].napi);
2667}
2668
2669static void port_napi_enable(struct ehea_port *port)
2670{
2671 int i;
2672
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002673 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002674 napi_enable(&port->port_res[i].napi);
2675}
2676
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677static int ehea_open(struct net_device *dev)
2678{
2679 int ret;
2680 struct ehea_port *port = netdev_priv(dev);
2681
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002682 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002683
Joe Perches8c4877a2010-12-13 10:05:14 -08002684 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002685
2686 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002687 if (!ret) {
2688 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002689 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002690 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002691
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002692 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002693
2694 return ret;
2695}
2696
2697static int ehea_down(struct net_device *dev)
2698{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002699 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002700 struct ehea_port *port = netdev_priv(dev);
2701
2702 if (port->state == EHEA_PORT_DOWN)
2703 return 0;
2704
2705 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002706 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2707
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002708 ehea_free_interrupts(dev);
2709
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002710 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002711
Thomas Klein21eee2d2008-02-13 16:18:33 +01002712 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002713
Thomas Klein44c82152007-07-11 16:32:00 +02002714 ret = ehea_clean_all_portres(port);
2715 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002716 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002717
Thomas Klein21eee2d2008-02-13 16:18:33 +01002718 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002719
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002720 return ret;
2721}
2722
2723static int ehea_stop(struct net_device *dev)
2724{
2725 int ret;
2726 struct ehea_port *port = netdev_priv(dev);
2727
Joe Perches8c4877a2010-12-13 10:05:14 -08002728 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002729
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002730 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002731 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002732 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002734 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002736 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002737 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002738 return ret;
2739}
2740
Andrew Morton22559c52008-04-18 13:50:39 -07002741static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002742{
2743 struct ehea_qp qp = *orig_qp;
2744 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2745 struct ehea_swqe *swqe;
2746 int wqe_index;
2747 int i;
2748
2749 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2750 swqe = ehea_get_swqe(&qp, &wqe_index);
2751 swqe->tx_control |= EHEA_SWQE_PURGE;
2752 }
2753}
2754
Andrew Morton22559c52008-04-18 13:50:39 -07002755static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002756{
2757 int i;
2758
2759 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2760 struct ehea_port_res *pr = &port->port_res[i];
2761 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002762 int ret;
2763
2764 ret = wait_event_timeout(port->swqe_avail_wq,
2765 atomic_read(&pr->swqe_avail) >= swqe_max,
2766 msecs_to_jiffies(100));
2767
2768 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002769 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002770 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002771 }
2772 }
2773}
2774
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002775int ehea_stop_qps(struct net_device *dev)
2776{
2777 struct ehea_port *port = netdev_priv(dev);
2778 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002779 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002780 int ret = -EIO;
2781 int dret;
2782 int i;
2783 u64 hret;
2784 u64 dummy64 = 0;
2785 u16 dummy16 = 0;
2786
Thomas Klein3faf2692009-01-21 14:45:33 -08002787 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002788 if (!cb0) {
2789 ret = -ENOMEM;
2790 goto out;
2791 }
2792
2793 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2794 struct ehea_port_res *pr = &port->port_res[i];
2795 struct ehea_qp *qp = pr->qp;
2796
2797 /* Purge send queue */
2798 ehea_purge_sq(qp);
2799
2800 /* Disable queue pair */
2801 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2802 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2803 cb0);
2804 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002805 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002806 goto out;
2807 }
2808
2809 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2810 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2811
2812 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2813 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2814 1), cb0, &dummy64,
2815 &dummy64, &dummy16, &dummy16);
2816 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002817 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002818 goto out;
2819 }
2820
2821 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2822 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2823 cb0);
2824 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002825 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002826 goto out;
2827 }
2828
2829 /* deregister shared memory regions */
2830 dret = ehea_rem_smrs(pr);
2831 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002832 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002833 goto out;
2834 }
2835 }
2836
2837 ret = 0;
2838out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002839 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002840
2841 return ret;
2842}
2843
Doug Maxey508d2b52008-01-31 20:20:49 -06002844void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002845{
2846 struct ehea_qp qp = *orig_qp;
2847 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2848 struct ehea_rwqe *rwqe;
2849 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2850 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2851 struct sk_buff *skb;
2852 u32 lkey = pr->recv_mr.lkey;
2853
2854
2855 int i;
2856 int index;
2857
2858 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2859 rwqe = ehea_get_next_rwqe(&qp, 2);
2860 rwqe->sg_list[0].l_key = lkey;
2861 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2862 skb = skba_rq2[index];
2863 if (skb)
2864 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2865 }
2866
2867 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2868 rwqe = ehea_get_next_rwqe(&qp, 3);
2869 rwqe->sg_list[0].l_key = lkey;
2870 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2871 skb = skba_rq3[index];
2872 if (skb)
2873 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2874 }
2875}
2876
2877int ehea_restart_qps(struct net_device *dev)
2878{
2879 struct ehea_port *port = netdev_priv(dev);
2880 struct ehea_adapter *adapter = port->adapter;
2881 int ret = 0;
2882 int i;
2883
Doug Maxey508d2b52008-01-31 20:20:49 -06002884 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002885 u64 hret;
2886 u64 dummy64 = 0;
2887 u16 dummy16 = 0;
2888
Thomas Klein3faf2692009-01-21 14:45:33 -08002889 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002890 if (!cb0) {
2891 ret = -ENOMEM;
2892 goto out;
2893 }
2894
2895 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2896 struct ehea_port_res *pr = &port->port_res[i];
2897 struct ehea_qp *qp = pr->qp;
2898
2899 ret = ehea_gen_smrs(pr);
2900 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002901 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002902 goto out;
2903 }
2904
2905 ehea_update_rqs(qp, pr);
2906
2907 /* Enable queue pair */
2908 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2909 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2910 cb0);
2911 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002912 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002913 goto out;
2914 }
2915
2916 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2917 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2918
2919 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2920 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2921 1), cb0, &dummy64,
2922 &dummy64, &dummy16, &dummy16);
2923 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002924 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002925 goto out;
2926 }
2927
2928 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2929 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2930 cb0);
2931 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002932 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002933 goto out;
2934 }
2935
2936 /* refill entire queue */
2937 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2938 ehea_refill_rq2(pr, 0);
2939 ehea_refill_rq3(pr, 0);
2940 }
2941out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002942 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002943
2944 return ret;
2945}
2946
David Howellsc4028952006-11-22 14:57:56 +00002947static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002948{
2949 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002950 struct ehea_port *port =
2951 container_of(work, struct ehea_port, reset_task);
2952 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002953
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002954 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002955 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002956 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002958
2959 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002960
Thomas Klein44c82152007-07-11 16:32:00 +02002961 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962
2963 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002964 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002965 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002966
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002967 ehea_set_multicast_list(dev);
2968
Joe Perches8c4877a2010-12-13 10:05:14 -08002969 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002970
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002971 port_napi_enable(port);
2972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002973 netif_wake_queue(dev);
2974out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002975 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002976 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002977}
2978
Tejun Heo3d6b8922010-12-12 16:45:14 +01002979static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002980{
2981 int ret, i;
2982 struct ehea_adapter *adapter;
2983
Joe Perches8c4877a2010-12-13 10:05:14 -08002984 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002985
2986 list_for_each_entry(adapter, &adapter_list, list)
2987 if (adapter->active_ports) {
2988 /* Shutdown all ports */
2989 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2990 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002991 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002992
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002993 if (!port)
2994 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002995
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002996 dev = port->netdev;
2997
2998 if (dev->flags & IFF_UP) {
2999 mutex_lock(&port->port_lock);
3000 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003001 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003002 ret = ehea_stop_qps(dev);
3003 if (ret) {
3004 mutex_unlock(&port->port_lock);
3005 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003006 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003007 port_napi_disable(port);
3008 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003009 }
Andre Detsch2928db42010-08-17 05:49:12 +00003010 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003011 }
3012
3013 /* Unregister old memory region */
3014 ret = ehea_rem_mr(&adapter->mr);
3015 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003016 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003017 goto out;
3018 }
3019 }
3020
Thomas Klein44c82152007-07-11 16:32:00 +02003021 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3022
3023 list_for_each_entry(adapter, &adapter_list, list)
3024 if (adapter->active_ports) {
3025 /* Register new memory region */
3026 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3027 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003028 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003029 goto out;
3030 }
3031
3032 /* Restart all ports */
3033 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3034 struct ehea_port *port = adapter->port[i];
3035
3036 if (port) {
3037 struct net_device *dev = port->netdev;
3038
3039 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003040 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003041 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003042 if (!ret) {
3043 check_sqs(port);
3044 port_napi_enable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003045 netif_wake_queue(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003046 } else {
3047 netdev_err(dev, "Unable to restart QPS\n");
3048 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003049 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003050 }
3051 }
3052 }
3053 }
Joe Perches8c4877a2010-12-13 10:05:14 -08003054 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003055out:
3056 return;
3057}
3058
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003059static void ehea_tx_watchdog(struct net_device *dev)
3060{
3061 struct ehea_port *port = netdev_priv(dev);
3062
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003063 if (netif_carrier_ok(dev) &&
3064 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003065 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003066}
3067
3068int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3069{
3070 struct hcp_query_ehea *cb;
3071 u64 hret;
3072 int ret;
3073
Thomas Klein3faf2692009-01-21 14:45:33 -08003074 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003075 if (!cb) {
3076 ret = -ENOMEM;
3077 goto out;
3078 }
3079
3080 hret = ehea_h_query_ehea(adapter->handle, cb);
3081
3082 if (hret != H_SUCCESS) {
3083 ret = -EIO;
3084 goto out_herr;
3085 }
3086
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003087 adapter->max_mc_mac = cb->max_mc_mac - 1;
3088 ret = 0;
3089
3090out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003091 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003092out:
3093 return ret;
3094}
3095
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003096int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3097{
3098 struct hcp_ehea_port_cb4 *cb4;
3099 u64 hret;
3100 int ret = 0;
3101
3102 *jumbo = 0;
3103
3104 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003105 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003106 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003107 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003108 ret = -ENOMEM;
3109 goto out;
3110 } else {
3111 hret = ehea_h_query_ehea_port(port->adapter->handle,
3112 port->logical_port_id,
3113 H_PORT_CB4,
3114 H_PORT_CB4_JUMBO, cb4);
3115 if (hret == H_SUCCESS) {
3116 if (cb4->jumbo_frame)
3117 *jumbo = 1;
3118 else {
3119 cb4->jumbo_frame = 1;
3120 hret = ehea_h_modify_ehea_port(port->adapter->
3121 handle,
3122 port->
3123 logical_port_id,
3124 H_PORT_CB4,
3125 H_PORT_CB4_JUMBO,
3126 cb4);
3127 if (hret == H_SUCCESS)
3128 *jumbo = 1;
3129 }
3130 } else
3131 ret = -EINVAL;
3132
Thomas Klein3faf2692009-01-21 14:45:33 -08003133 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003134 }
3135out:
3136 return ret;
3137}
3138
3139static ssize_t ehea_show_port_id(struct device *dev,
3140 struct device_attribute *attr, char *buf)
3141{
3142 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003143 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144}
3145
3146static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3147 NULL);
3148
3149static void __devinit logical_port_release(struct device *dev)
3150{
3151 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003152 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003153}
3154
3155static struct device *ehea_register_port(struct ehea_port *port,
3156 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003157{
3158 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003159
Grant Likely61c7a082010-04-13 16:12:29 -07003160 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003161 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003162 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003164 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 port->ofdev.dev.release = logical_port_release;
3166
3167 ret = of_device_register(&port->ofdev);
3168 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003169 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170 goto out;
3171 }
3172
3173 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003174 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003175 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 goto out_unreg_of_dev;
3177 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003178
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003179 return &port->ofdev.dev;
3180
3181out_unreg_of_dev:
3182 of_device_unregister(&port->ofdev);
3183out:
3184 return NULL;
3185}
3186
3187static void ehea_unregister_port(struct ehea_port *port)
3188{
3189 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3190 of_device_unregister(&port->ofdev);
3191}
3192
Thomas Klein086c1b22009-01-21 14:43:59 -08003193static const struct net_device_ops ehea_netdev_ops = {
3194 .ndo_open = ehea_open,
3195 .ndo_stop = ehea_stop,
3196 .ndo_start_xmit = ehea_start_xmit,
3197#ifdef CONFIG_NET_POLL_CONTROLLER
3198 .ndo_poll_controller = ehea_netpoll,
3199#endif
3200 .ndo_get_stats = ehea_get_stats,
3201 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003202 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003203 .ndo_set_multicast_list = ehea_set_multicast_list,
3204 .ndo_change_mtu = ehea_change_mtu,
3205 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3206 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003207 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3208 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003209};
3210
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003211struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3212 u32 logical_port_id,
3213 struct device_node *dn)
3214{
3215 int ret;
3216 struct net_device *dev;
3217 struct ehea_port *port;
3218 struct device *port_dev;
3219 int jumbo;
3220
3221 /* allocate memory for the port structures */
3222 dev = alloc_etherdev(sizeof(struct ehea_port));
3223
3224 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003225 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226 ret = -ENOMEM;
3227 goto out_err;
3228 }
3229
3230 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003231
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003232 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233 port->state = EHEA_PORT_DOWN;
3234 port->sig_comp_iv = sq_entries / 10;
3235
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003236 port->adapter = adapter;
3237 port->netdev = dev;
3238 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003239
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003241
3242 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3243 if (!port->mc_list) {
3244 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003245 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003246 }
3247
3248 INIT_LIST_HEAD(&port->mc_list->list);
3249
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250 ret = ehea_sense_port_attr(port);
3251 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003253
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003254 port_dev = ehea_register_port(port, dn);
3255 if (!port_dev)
3256 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003257
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259
3260 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003261 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3262
Thomas Klein086c1b22009-01-21 14:43:59 -08003263 dev->netdev_ops = &ehea_netdev_ops;
3264 ehea_set_ethtool_ops(dev);
3265
Michał Mirosławf4786a92011-04-17 00:15:47 +00003266 dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3267 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003268 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003269 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Michał Mirosławf4786a92011-04-17 00:15:47 +00003271 | NETIF_F_LLTX | NETIF_F_RXCSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003272 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3273
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003274 if (use_lro)
3275 dev->features |= NETIF_F_LRO;
3276
David Howellsc4028952006-11-22 14:57:56 +00003277 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003278
Anton Blanchard21ccc792011-05-10 16:17:10 +00003279 init_waitqueue_head(&port->swqe_avail_wq);
3280 init_waitqueue_head(&port->restart_wq);
3281
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003282 ret = register_netdev(dev);
3283 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003284 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003285 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003286 }
3287
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003288 port->lro_max_aggr = lro_max_aggr;
3289
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003291 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003292 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003293
Joe Perches8c4877a2010-12-13 10:05:14 -08003294 netdev_info(dev, "Jumbo frames are %sabled\n",
3295 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003296
Thomas Klein44c82152007-07-11 16:32:00 +02003297 adapter->active_ports++;
3298
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003299 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003300
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003301out_unreg_port:
3302 ehea_unregister_port(port);
3303
3304out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003306
3307out_free_ethdev:
3308 free_netdev(dev);
3309
3310out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003311 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3312 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003313 return NULL;
3314}
3315
3316static void ehea_shutdown_single_port(struct ehea_port *port)
3317{
Brian King7fb1c2a2008-05-14 09:48:25 -05003318 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003319
3320 cancel_work_sync(&port->reset_task);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003321 unregister_netdev(port->netdev);
3322 ehea_unregister_port(port);
3323 kfree(port->mc_list);
3324 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003325 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003326}
3327
3328static int ehea_setup_ports(struct ehea_adapter *adapter)
3329{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003330 struct device_node *lhea_dn;
3331 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003332
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003333 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003334 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003335
Grant Likely61c7a082010-04-13 16:12:29 -07003336 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003337 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003338
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003339 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003340 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003341 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003342 pr_err("bad device node: eth_dn name=%s\n",
3343 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003345 }
3346
Thomas Klein1211bb62007-04-26 11:56:43 +02003347 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003348 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003349 of_node_put(eth_dn);
3350 return -EIO;
3351 }
3352
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003353 adapter->port[i] = ehea_setup_single_port(adapter,
3354 *dn_log_port_id,
3355 eth_dn);
3356 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003357 netdev_info(adapter->port[i]->netdev,
3358 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003359 else
3360 ehea_remove_adapter_mr(adapter);
3361
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003362 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003363 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003364 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365}
3366
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003367static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3368 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003369{
3370 struct device_node *lhea_dn;
3371 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003372 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373
Grant Likely61c7a082010-04-13 16:12:29 -07003374 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003375 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003376
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003377 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003378 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003379 if (dn_log_port_id)
3380 if (*dn_log_port_id == logical_port_id)
3381 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003382 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003383
3384 return NULL;
3385}
3386
3387static ssize_t ehea_probe_port(struct device *dev,
3388 struct device_attribute *attr,
3389 const char *buf, size_t count)
3390{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003391 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003392 struct ehea_port *port;
3393 struct device_node *eth_dn = NULL;
3394 int i;
3395
3396 u32 logical_port_id;
3397
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003398 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003399
3400 port = ehea_get_port(adapter, logical_port_id);
3401
3402 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003403 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3404 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003405 return -EINVAL;
3406 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003407
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003408 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3409
3410 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003411 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003412 return -EINVAL;
3413 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003414
Thomas Klein1211bb62007-04-26 11:56:43 +02003415 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003416 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003417 return -EIO;
3418 }
3419
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003420 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3421
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003422 of_node_put(eth_dn);
3423
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003424 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003425 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003426 if (!adapter->port[i]) {
3427 adapter->port[i] = port;
3428 break;
3429 }
3430
Joe Perches8c4877a2010-12-13 10:05:14 -08003431 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3432 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003433 } else {
3434 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003435 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003436 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003437
3438 return (ssize_t) count;
3439}
3440
3441static ssize_t ehea_remove_port(struct device *dev,
3442 struct device_attribute *attr,
3443 const char *buf, size_t count)
3444{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003445 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003446 struct ehea_port *port;
3447 int i;
3448 u32 logical_port_id;
3449
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003450 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451
3452 port = ehea_get_port(adapter, logical_port_id);
3453
3454 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003455 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3456 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003457
3458 ehea_shutdown_single_port(port);
3459
Doug Maxey508d2b52008-01-31 20:20:49 -06003460 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003461 if (adapter->port[i] == port) {
3462 adapter->port[i] = NULL;
3463 break;
3464 }
3465 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003466 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3467 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003468 return -EINVAL;
3469 }
3470
Thomas Klein1211bb62007-04-26 11:56:43 +02003471 ehea_remove_adapter_mr(adapter);
3472
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003473 return (ssize_t) count;
3474}
3475
3476static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3477static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3478
Grant Likely2dc11582010-08-06 09:25:50 -06003479int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003480{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003481 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003482 if (ret)
3483 goto out;
3484
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003485 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003486out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003487 return ret;
3488}
3489
Grant Likely2dc11582010-08-06 09:25:50 -06003490void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003491{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003492 device_remove_file(&dev->dev, &dev_attr_probe_port);
3493 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003494}
3495
Grant Likely2dc11582010-08-06 09:25:50 -06003496static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003497 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498{
3499 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003500 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003501 int ret;
3502
Grant Likely61c7a082010-04-13 16:12:29 -07003503 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003504 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003505 return -EINVAL;
3506 }
3507
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003508 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3509 if (!adapter) {
3510 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003511 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003512 goto out;
3513 }
3514
Thomas Klein44c82152007-07-11 16:32:00 +02003515 list_add(&adapter->list, &adapter_list);
3516
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003517 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003518
Grant Likely61c7a082010-04-13 16:12:29 -07003519 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003520 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003521 if (adapter_handle)
3522 adapter->handle = *adapter_handle;
3523
3524 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003525 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003526 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 ret = -ENODEV;
3528 goto out_free_ad;
3529 }
3530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 adapter->pd = EHEA_PD_ID;
3532
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003533 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535
3536 /* initialize adapter and ports */
3537 /* get adapter properties */
3538 ret = ehea_sense_adapter_attr(adapter);
3539 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003540 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003541 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003542 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003543
3544 adapter->neq = ehea_create_eq(adapter,
3545 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3546 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003547 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003548 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003549 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550 }
3551
3552 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3553 (unsigned long)adapter);
3554
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003555 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003556 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 "ehea_neq", adapter);
3558 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003559 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003560 goto out_kill_eq;
3561 }
3562
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003563 ret = ehea_create_device_sysfs(dev);
3564 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003565 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003566
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003567 ret = ehea_setup_ports(adapter);
3568 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003569 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003570 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571 }
3572
3573 ret = 0;
3574 goto out;
3575
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003576out_rem_dev_sysfs:
3577 ehea_remove_device_sysfs(dev);
3578
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003579out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003580 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581
3582out_kill_eq:
3583 ehea_destroy_eq(adapter->neq);
3584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003585out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003586 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003587 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003589out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003590 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592 return ret;
3593}
3594
Grant Likely2dc11582010-08-06 09:25:50 -06003595static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003596{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003597 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003598 int i;
3599
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003600 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003601 if (adapter->port[i]) {
3602 ehea_shutdown_single_port(adapter->port[i]);
3603 adapter->port[i] = NULL;
3604 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003605
3606 ehea_remove_device_sysfs(dev);
3607
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003608 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003609 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003610
3611 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003612 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003613 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003614 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003615
Thomas Klein21eee2d2008-02-13 16:18:33 +01003616 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003618 return 0;
3619}
3620
Thomas Klein21eee2d2008-02-13 16:18:33 +01003621void ehea_crash_handler(void)
3622{
3623 int i;
3624
3625 if (ehea_fw_handles.arr)
3626 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3627 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3628 ehea_fw_handles.arr[i].fwh,
3629 FORCE_FREE);
3630
3631 if (ehea_bcmc_regs.arr)
3632 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3633 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3634 ehea_bcmc_regs.arr[i].port_id,
3635 ehea_bcmc_regs.arr[i].reg_type,
3636 ehea_bcmc_regs.arr[i].macaddr,
3637 0, H_DEREG_BCMC);
3638}
3639
Hannes Hering48cfb142008-05-07 14:43:36 +02003640static int ehea_mem_notifier(struct notifier_block *nb,
3641 unsigned long action, void *data)
3642{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003643 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003644 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003645
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003646 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003647
Hannes Hering48cfb142008-05-07 14:43:36 +02003648 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003649 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003650 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003651 /* Readd canceled memory block */
3652 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003653 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003654 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003655 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003656 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003657 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003658 break;
3659 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003660 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003661 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003662 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003663 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003664 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003665 break;
3666 default:
3667 break;
3668 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003669
3670 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003671 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003672
Thomas Kleina7c561f22010-04-20 23:11:31 +00003673out_unlock:
3674 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003675 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003676}
3677
3678static struct notifier_block ehea_mem_nb = {
3679 .notifier_call = ehea_mem_notifier,
3680};
3681
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003682static int ehea_reboot_notifier(struct notifier_block *nb,
3683 unsigned long action, void *unused)
3684{
3685 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003686 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003687 ibmebus_unregister_driver(&ehea_driver);
3688 }
3689 return NOTIFY_DONE;
3690}
3691
3692static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003693 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003694};
3695
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003696static int check_module_parm(void)
3697{
3698 int ret = 0;
3699
3700 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3701 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003702 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003703 ret = -EINVAL;
3704 }
3705 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3706 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003707 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003708 ret = -EINVAL;
3709 }
3710 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3711 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003712 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003713 ret = -EINVAL;
3714 }
3715 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3716 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003717 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003718 ret = -EINVAL;
3719 }
3720
3721 return ret;
3722}
3723
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003724static ssize_t ehea_show_capabilities(struct device_driver *drv,
3725 char *buf)
3726{
3727 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3728}
3729
3730static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3731 ehea_show_capabilities, NULL);
3732
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003733int __init ehea_module_init(void)
3734{
3735 int ret;
3736
Joe Perches8c4877a2010-12-13 10:05:14 -08003737 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003738
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3740 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3741
Daniel Walker9f71a562008-03-28 14:41:26 -07003742 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003743 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003744
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003745 ret = check_module_parm();
3746 if (ret)
3747 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003748
3749 ret = ehea_create_busmap();
3750 if (ret)
3751 goto out;
3752
Thomas Klein21eee2d2008-02-13 16:18:33 +01003753 ret = register_reboot_notifier(&ehea_reboot_nb);
3754 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003755 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003756
Hannes Hering48cfb142008-05-07 14:43:36 +02003757 ret = register_memory_notifier(&ehea_mem_nb);
3758 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003759 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003760
Joe Perchesc061b182010-08-23 18:20:03 +00003761 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003762 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003763 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003764
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003765 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003766 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003767 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003768 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003769 }
3770
3771 ret = driver_create_file(&ehea_driver.driver,
3772 &driver_attr_capabilities);
3773 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003774 pr_err("failed to register capabilities attribute, ret=%d\n",
3775 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003776 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003777 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003778
Thomas Klein21eee2d2008-02-13 16:18:33 +01003779 return ret;
3780
3781out3:
3782 ibmebus_unregister_driver(&ehea_driver);
3783out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003784 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003785 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003786 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003787out:
3788 return ret;
3789}
3790
3791static void __exit ehea_module_exit(void)
3792{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003793 int ret;
3794
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003795 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003796 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003797 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003798 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003799 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003800 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003801 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003802 kfree(ehea_fw_handles.arr);
3803 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003804 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003805}
3806
3807module_init(ehea_module_init);
3808module_exit(ehea_module_exit);