blob: ce9a6703272451deda0192ad2179c734a8e3de89 [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;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000334 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200335 int i;
336
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000337 for (i = 0; i < port->num_def_qps; i++) {
338 rx_packets += port->port_res[i].rx_packets;
339 rx_bytes += port->port_res[i].rx_bytes;
340 }
341
342 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
343 tx_packets += port->port_res[i].tx_packets;
344 tx_bytes += port->port_res[i].tx_bytes;
345 }
346
347 stats->tx_packets = tx_packets;
348 stats->rx_bytes = rx_bytes;
349 stats->tx_bytes = tx_bytes;
350 stats->rx_packets = rx_packets;
351
352 return &port->stats;
353}
354
355static void ehea_update_stats(struct work_struct *work)
356{
357 struct ehea_port *port =
358 container_of(work, struct ehea_port, stats_work.work);
359 struct net_device *dev = port->netdev;
360 struct net_device_stats *stats = &port->stats;
361 struct hcp_ehea_port_cb2 *cb2;
362 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200363
Brian King3d8009c2010-06-30 11:59:12 +0000364 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200365 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000366 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
367 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368 }
369
370 hret = ehea_h_query_ehea_port(port->adapter->handle,
371 port->logical_port_id,
372 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
373 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800374 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200375 goto out_herr;
376 }
377
378 if (netif_msg_hw(port))
379 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
380
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200381 stats->multicast = cb2->rxmcp;
382 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200383
384out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800385 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000386resched:
387 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200388}
389
390static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
391{
392 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
393 struct net_device *dev = pr->port->netdev;
394 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200395 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
396 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200397 int i;
398
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200399 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200400
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200401 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200402 if (nr_of_wqes > 0)
403 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200404 pr->rq1_skba.os_skbs = fill_wqes;
405 return;
406 }
407
408 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200409 if (!skb_arr_rq1[index]) {
410 skb_arr_rq1[index] = netdev_alloc_skb(dev,
411 EHEA_L_PKT_SIZE);
412 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800413 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200414 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200415 break;
416 }
417 }
418 index--;
419 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200420 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200422
423 if (adder == 0)
424 return;
425
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200426 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200427 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200428}
429
Thomas Kleine2878802009-01-21 14:45:57 -0800430static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200432 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
433 struct net_device *dev = pr->port->netdev;
434 int i;
435
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000436 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800437 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 return;
439 }
440
441 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200442 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000443 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800444 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800445 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000446 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200447 }
448 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000449 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450}
451
452static int ehea_refill_rq_def(struct ehea_port_res *pr,
453 struct ehea_q_skb_arr *q_skba, int rq_nr,
454 int num_wqes, int wqe_type, int packet_size)
455{
456 struct net_device *dev = pr->port->netdev;
457 struct ehea_qp *qp = pr->qp;
458 struct sk_buff **skb_arr = q_skba->arr;
459 struct ehea_rwqe *rwqe;
460 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200461 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462 int ret = 0;
463
464 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200466
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200467 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
468 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200470 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471
472 index = q_skba->index;
473 max_index_mask = q_skba->len - 1;
474 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200475 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000476 struct sk_buff *skb;
477
478 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200480 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800481 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800482 netdev_info(pr->port->netdev,
483 "rq%i ran dry - no mem for skb\n",
484 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800485 ret = -ENOMEM;
486 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487 break;
488 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489
490 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200491 tmp_addr = ehea_map_vaddr(skb->data);
492 if (tmp_addr == -1) {
493 dev_kfree_skb(skb);
494 q_skba->os_skbs = fill_wqes - i;
495 ret = 0;
496 break;
497 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200498
499 rwqe = ehea_get_next_rwqe(qp, rq_nr);
500 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200501 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200503 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 rwqe->sg_list[0].len = packet_size;
505 rwqe->data_segments = 1;
506
507 index++;
508 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200510 }
Thomas Klein44c82152007-07-11 16:32:00 +0200511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200513 if (adder == 0)
514 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515
516 /* Ring doorbell */
517 iosync();
518 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200519 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200520 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200521 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200522out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200523 return ret;
524}
525
526
527static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
528{
529 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
530 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200532}
533
534
535static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
536{
537 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
538 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000539 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200540}
541
542static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
543{
544 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
545 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
546 return 0;
547 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
548 (cqe->header_length == 0))
549 return 0;
550 return -EINVAL;
551}
552
553static inline void ehea_fill_skb(struct net_device *dev,
554 struct sk_buff *skb, struct ehea_cqe *cqe)
555{
556 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
557
558 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200559 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000560
561 /* The packet was not an IPV4 packet so a complemented checksum was
562 calculated. The value is found in the Internet Checksum field. */
563 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
564 skb->ip_summed = CHECKSUM_COMPLETE;
565 skb->csum = csum_unfold(~cqe->inet_checksum_value);
566 } else
567 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200568}
569
570static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
571 int arr_len,
572 struct ehea_cqe *cqe)
573{
574 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
575 struct sk_buff *skb;
576 void *pref;
577 int x;
578
579 x = skb_index + 1;
580 x &= (arr_len - 1);
581
582 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700583 if (pref) {
584 prefetchw(pref);
585 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200586
Hannes Hering0b2febf2009-05-04 11:06:37 -0700587 pref = (skb_array[x]->data);
588 prefetch(pref);
589 prefetch(pref + EHEA_CACHE_LINE);
590 prefetch(pref + EHEA_CACHE_LINE * 2);
591 prefetch(pref + EHEA_CACHE_LINE * 3);
592 }
593
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200594 skb = skb_array[skb_index];
595 skb_array[skb_index] = NULL;
596 return skb;
597}
598
599static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
600 int arr_len, int wqe_index)
601{
602 struct sk_buff *skb;
603 void *pref;
604 int x;
605
606 x = wqe_index + 1;
607 x &= (arr_len - 1);
608
609 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700610 if (pref) {
611 prefetchw(pref);
612 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200613
Hannes Hering0b2febf2009-05-04 11:06:37 -0700614 pref = (skb_array[x]->data);
615 prefetchw(pref);
616 prefetchw(pref + EHEA_CACHE_LINE);
617 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200618
619 skb = skb_array[wqe_index];
620 skb_array[wqe_index] = NULL;
621 return skb;
622}
623
624static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
625 struct ehea_cqe *cqe, int *processed_rq2,
626 int *processed_rq3)
627{
628 struct sk_buff *skb;
629
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100630 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
631 pr->p_stats.err_tcp_cksum++;
632 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
633 pr->p_stats.err_ip_cksum++;
634 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
635 pr->p_stats.err_frame_crc++;
636
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200637 if (rq == 2) {
638 *processed_rq2 += 1;
639 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
640 dev_kfree_skb(skb);
641 } else if (rq == 3) {
642 *processed_rq3 += 1;
643 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
644 dev_kfree_skb(skb);
645 }
646
647 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100648 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800649 pr_err("Critical receive error for QP %d. Resetting port.\n",
650 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100651 ehea_dump(cqe, sizeof(*cqe), "CQE");
652 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100653 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200654 return 1;
655 }
656
657 return 0;
658}
659
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700660static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
661 void **tcph, u64 *hdr_flags, void *priv)
662{
663 struct ehea_cqe *cqe = priv;
664 unsigned int ip_len;
665 struct iphdr *iph;
666
667 /* non tcp/udp packets */
668 if (!cqe->header_length)
669 return -1;
670
671 /* non tcp packet */
672 skb_reset_network_header(skb);
673 iph = ip_hdr(skb);
674 if (iph->protocol != IPPROTO_TCP)
675 return -1;
676
677 ip_len = ip_hdrlen(skb);
678 skb_set_transport_header(skb, ip_len);
679 *tcph = tcp_hdr(skb);
680
681 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700682 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700683 return -1;
684
685 *hdr_flags = LRO_IPV4 | LRO_TCP;
686 *iphdr = iph;
687
688 return 0;
689}
690
691static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
692 struct sk_buff *skb)
693{
Jiri Pirkob4950092011-07-20 04:54:07 +0000694 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
695 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700696
Jiri Pirkob4950092011-07-20 04:54:07 +0000697 if (skb->dev->features & NETIF_F_LRO)
698 lro_receive_skb(&pr->lro_mgr, skb, cqe);
699 else
700 netif_receive_skb(skb);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700701}
702
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700703static int ehea_proc_rwqes(struct net_device *dev,
704 struct ehea_port_res *pr,
705 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100707 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 struct ehea_qp *qp = pr->qp;
709 struct ehea_cqe *cqe;
710 struct sk_buff *skb;
711 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
712 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
713 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
714 int skb_arr_rq1_len = pr->rq1_skba.len;
715 int skb_arr_rq2_len = pr->rq2_skba.len;
716 int skb_arr_rq3_len = pr->rq3_skba.len;
717 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000718 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700719 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720
721 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
722 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700725 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200726 ehea_inc_rq1(qp);
727 processed_rq1++;
728 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 if (netif_msg_rx_status(port))
730 ehea_dump(cqe, sizeof(*cqe), "CQE");
731
732 last_wqe_index = wqe_index;
733 rmb();
734 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600735 if (rq == 1) {
736 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737 skb = get_skb_by_index_ll(skb_arr_rq1,
738 skb_arr_rq1_len,
739 wqe_index);
740 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800741 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800742 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100743
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700744 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000746 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800747 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000749 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600751 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200752 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700753 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600754 } else if (rq == 2) {
755 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756 skb = get_skb_by_index(skb_arr_rq2,
757 skb_arr_rq2_len, cqe);
758 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800759 netif_err(port, rx_err, dev,
760 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200761 break;
762 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700763 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200764 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600765 } else {
766 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 skb = get_skb_by_index(skb_arr_rq3,
768 skb_arr_rq3_len, cqe);
769 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800770 netif_err(port, rx_err, dev,
771 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200772 break;
773 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700774 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200775 processed_rq3++;
776 }
777
Breno Leitaoce45b872010-10-27 08:45:14 +0000778 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700779 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100780 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100781 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200782 port_reset = ehea_treat_poll_error(pr, rq, cqe,
783 &processed_rq2,
784 &processed_rq3);
785 if (port_reset)
786 break;
787 }
788 cqe = ehea_poll_rq1(qp, &wqe_index);
789 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800790 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700791 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200792
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200793 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000794 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200795
796 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
797 ehea_refill_rq2(pr, processed_rq2);
798 ehea_refill_rq3(pr, processed_rq3);
799
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700800 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200801}
802
Andre Detsch2928db42010-08-17 05:49:12 +0000803#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
804
805static void reset_sq_restart_flag(struct ehea_port *port)
806{
807 int i;
808
809 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
810 struct ehea_port_res *pr = &port->port_res[i];
811 pr->sq_restart_flag = 0;
812 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000813 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000814}
815
816static void check_sqs(struct ehea_port *port)
817{
818 struct ehea_swqe *swqe;
819 int swqe_index;
820 int i, k;
821
822 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
823 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000824 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000825 k = 0;
826 swqe = ehea_get_swqe(pr->qp, &swqe_index);
827 memset(swqe, 0, SWQE_HEADER_SIZE);
828 atomic_dec(&pr->swqe_avail);
829
830 swqe->tx_control |= EHEA_SWQE_PURGE;
831 swqe->wr_id = SWQE_RESTART_CHECK;
832 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
833 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
834 swqe->immediate_data_length = 80;
835
836 ehea_post_swqe(pr->qp, swqe);
837
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000838 ret = wait_event_timeout(port->restart_wq,
839 pr->sq_restart_flag == 0,
840 msecs_to_jiffies(100));
841
842 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800843 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000844 ehea_schedule_port_reset(pr->port);
845 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000846 }
847 }
Andre Detsch2928db42010-08-17 05:49:12 +0000848}
849
850
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100851static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200852{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100853 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200854 struct ehea_cq *send_cq = pr->send_cq;
855 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100856 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857 int cqe_counter = 0;
858 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100859 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200860 unsigned long flags;
861
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100862 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600863 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864 ehea_inc_cq(send_cq);
865
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200866 cqe_counter++;
867 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000868
869 if (cqe->wr_id == SWQE_RESTART_CHECK) {
870 pr->sq_restart_flag = 1;
871 swqe_av++;
872 break;
873 }
874
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800876 pr_err("Bad send completion status=0x%04X\n",
877 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000878
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 if (netif_msg_tx_err(pr->port))
880 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000881
882 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800883 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000884 ehea_schedule_port_reset(pr->port);
885 break;
886 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200887 }
888
889 if (netif_msg_tx_done(pr->port))
890 ehea_dump(cqe, sizeof(*cqe), "CQE");
891
892 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100893 == EHEA_SWQE2_TYPE)) {
894
895 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
896 skb = pr->sq_skba.arr[index];
897 dev_kfree_skb(skb);
898 pr->sq_skba.arr[index] = NULL;
899 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200900
901 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
902 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903
904 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700905 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200906
907 ehea_update_feca(send_cq, cqe_counter);
908 atomic_add(swqe_av, &pr->swqe_avail);
909
910 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100911
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200912 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
913 >= pr->swqe_refill_th)) {
914 netif_wake_queue(pr->port->netdev);
915 pr->queue_stopped = 0;
916 }
917 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000918 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200919
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100920 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200921}
922
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100923#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700924#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100925
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700926static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200927{
Doug Maxey508d2b52008-01-31 20:20:49 -0600928 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
929 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931 struct ehea_cqe *cqe;
932 struct ehea_cqe *cqe_skb = NULL;
933 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700934 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100935
936 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700937 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700939 if (!force_irq)
940 rx += ehea_proc_rwqes(dev, pr, budget - rx);
941
942 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100943 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700944 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800945 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946 ehea_reset_cq_ep(pr->recv_cq);
947 ehea_reset_cq_ep(pr->send_cq);
948 ehea_reset_cq_n1(pr->recv_cq);
949 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000950 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100951 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
952 cqe_skb = ehea_poll_cq(pr->send_cq);
953
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100954 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700955 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100956
Ben Hutchings288379f2009-01-19 16:43:59 -0800957 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700958 return rx;
959
960 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
961 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100962 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100963
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 pr->poll_counter++;
965 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966}
967
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200968#ifdef CONFIG_NET_POLL_CONTROLLER
969static void ehea_netpoll(struct net_device *dev)
970{
971 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700972 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200973
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700974 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800975 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200976}
977#endif
978
David Howells7d12e782006-10-05 14:55:46 +0100979static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200980{
981 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100982
Ben Hutchings288379f2009-01-19 16:43:59 -0800983 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100984
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 return IRQ_HANDLED;
986}
987
David Howells7d12e782006-10-05 14:55:46 +0100988static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200989{
990 struct ehea_port *port = param;
991 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100992 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000994 u64 resource_type, aer, aerr;
995 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200996
997 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100998
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001000 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -08001001 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1002 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001003
1004 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001005
1006 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1007 &aer, &aerr);
1008
1009 if (resource_type == EHEA_AER_RESTYPE_QP) {
1010 if ((aer & EHEA_AER_RESET_MASK) ||
1011 (aerr & EHEA_AERR_RESET_MASK))
1012 reset_port = 1;
1013 } else
1014 reset_port = 1; /* Reset in case of CQ or EQ error */
1015
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001016 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001017 }
1018
Thomas Kleinea96cea2010-04-20 23:10:55 +00001019 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001020 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001021 ehea_schedule_port_reset(port);
1022 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001023
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001024 return IRQ_HANDLED;
1025}
1026
1027static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1028 int logical_port)
1029{
1030 int i;
1031
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001032 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001033 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001034 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001035 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001036 return NULL;
1037}
1038
1039int ehea_sense_port_attr(struct ehea_port *port)
1040{
1041 int ret;
1042 u64 hret;
1043 struct hcp_ehea_port_cb0 *cb0;
1044
Doug Maxey508d2b52008-01-31 20:20:49 -06001045 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001046 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001047 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001048 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001049 ret = -ENOMEM;
1050 goto out;
1051 }
1052
1053 hret = ehea_h_query_ehea_port(port->adapter->handle,
1054 port->logical_port_id, H_PORT_CB0,
1055 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1056 cb0);
1057 if (hret != H_SUCCESS) {
1058 ret = -EIO;
1059 goto out_free;
1060 }
1061
1062 /* MAC address */
1063 port->mac_addr = cb0->port_mac_addr << 16;
1064
Doug Maxey508d2b52008-01-31 20:20:49 -06001065 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001066 ret = -EADDRNOTAVAIL;
1067 goto out_free;
1068 }
1069
1070 /* Port speed */
1071 switch (cb0->port_speed) {
1072 case H_SPEED_10M_H:
1073 port->port_speed = EHEA_SPEED_10M;
1074 port->full_duplex = 0;
1075 break;
1076 case H_SPEED_10M_F:
1077 port->port_speed = EHEA_SPEED_10M;
1078 port->full_duplex = 1;
1079 break;
1080 case H_SPEED_100M_H:
1081 port->port_speed = EHEA_SPEED_100M;
1082 port->full_duplex = 0;
1083 break;
1084 case H_SPEED_100M_F:
1085 port->port_speed = EHEA_SPEED_100M;
1086 port->full_duplex = 1;
1087 break;
1088 case H_SPEED_1G_F:
1089 port->port_speed = EHEA_SPEED_1G;
1090 port->full_duplex = 1;
1091 break;
1092 case H_SPEED_10G_F:
1093 port->port_speed = EHEA_SPEED_10G;
1094 port->full_duplex = 1;
1095 break;
1096 default:
1097 port->port_speed = 0;
1098 port->full_duplex = 0;
1099 break;
1100 }
1101
Thomas Kleine919b592007-01-22 12:53:20 +01001102 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001103 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001104
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001105 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001106 if (use_mcs)
1107 port->num_def_qps = cb0->num_default_qps;
1108 else
1109 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001110
1111 if (!port->num_def_qps) {
1112 ret = -EINVAL;
1113 goto out_free;
1114 }
1115
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001116 port->num_tx_qps = num_tx_qps;
1117
1118 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001119 port->num_add_tx_qps = 0;
1120 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001121 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001122
1123 ret = 0;
1124out_free:
1125 if (ret || netif_msg_probe(port))
1126 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001127 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001128out:
1129 return ret;
1130}
1131
1132int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1133{
1134 struct hcp_ehea_port_cb4 *cb4;
1135 u64 hret;
1136 int ret = 0;
1137
Thomas Klein3faf2692009-01-21 14:45:33 -08001138 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001140 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 ret = -ENOMEM;
1142 goto out;
1143 }
1144
1145 cb4->port_speed = port_speed;
1146
1147 netif_carrier_off(port->netdev);
1148
1149 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1150 port->logical_port_id,
1151 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1152 if (hret == H_SUCCESS) {
1153 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1154
1155 hret = ehea_h_query_ehea_port(port->adapter->handle,
1156 port->logical_port_id,
1157 H_PORT_CB4, H_PORT_CB4_SPEED,
1158 cb4);
1159 if (hret == H_SUCCESS) {
1160 switch (cb4->port_speed) {
1161 case H_SPEED_10M_H:
1162 port->port_speed = EHEA_SPEED_10M;
1163 port->full_duplex = 0;
1164 break;
1165 case H_SPEED_10M_F:
1166 port->port_speed = EHEA_SPEED_10M;
1167 port->full_duplex = 1;
1168 break;
1169 case H_SPEED_100M_H:
1170 port->port_speed = EHEA_SPEED_100M;
1171 port->full_duplex = 0;
1172 break;
1173 case H_SPEED_100M_F:
1174 port->port_speed = EHEA_SPEED_100M;
1175 port->full_duplex = 1;
1176 break;
1177 case H_SPEED_1G_F:
1178 port->port_speed = EHEA_SPEED_1G;
1179 port->full_duplex = 1;
1180 break;
1181 case H_SPEED_10G_F:
1182 port->port_speed = EHEA_SPEED_10G;
1183 port->full_duplex = 1;
1184 break;
1185 default:
1186 port->port_speed = 0;
1187 port->full_duplex = 0;
1188 break;
1189 }
1190 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001191 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001192 ret = -EIO;
1193 }
1194 } else {
1195 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001196 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 ret = -EPERM;
1198 } else {
1199 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001200 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001201 }
1202 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001203 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1204 netif_carrier_on(port->netdev);
1205
Thomas Klein3faf2692009-01-21 14:45:33 -08001206 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207out:
1208 return ret;
1209}
1210
1211static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1212{
1213 int ret;
1214 u8 ec;
1215 u8 portnum;
1216 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001217 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001218
1219 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1220 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1221 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001222 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223
1224 switch (ec) {
1225 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1226
1227 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001228 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229 break;
1230 }
1231
1232 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001233 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001234 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001235 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001236 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001237 break;
1238 }
1239
Joe Perches8c4877a2010-12-13 10:05:14 -08001240 netif_info(port, link, dev,
1241 "Logical port up: %dMbps %s Duplex\n",
1242 port->port_speed,
1243 port->full_duplex == 1 ?
1244 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245
Joe Perches8c4877a2010-12-13 10:05:14 -08001246 netif_carrier_on(dev);
1247 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248 }
1249 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001250 if (netif_carrier_ok(dev)) {
1251 netif_info(port, link, dev,
1252 "Logical port down\n");
1253 netif_carrier_off(dev);
1254 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001255 }
1256
1257 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001258 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001259 netif_info(port, link, dev,
1260 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001261 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001262 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001263 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001264 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001265 netif_info(port, link, dev,
1266 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001267 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001268 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269 }
1270
1271 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001272 netdev_info(dev,
1273 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001274 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001275 netdev_info(dev,
1276 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001277
1278 break;
1279 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001280 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 break;
1282 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001283 netdev_info(dev, "Port malfunction\n");
1284 netif_carrier_off(dev);
1285 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001286 break;
1287 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001288 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001289 break;
1290 }
1291}
1292
1293static void ehea_neq_tasklet(unsigned long data)
1294{
Doug Maxey508d2b52008-01-31 20:20:49 -06001295 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001296 struct ehea_eqe *eqe;
1297 u64 event_mask;
1298
1299 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001300 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301
1302 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001303 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001304 ehea_parse_eqe(adapter, eqe->entry);
1305 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001306 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307 }
1308
1309 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1310 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1311 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1312
1313 ehea_h_reset_events(adapter->handle,
1314 adapter->neq->fw_handle, event_mask);
1315}
1316
David Howells7d12e782006-10-05 14:55:46 +01001317static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001318{
1319 struct ehea_adapter *adapter = param;
1320 tasklet_hi_schedule(&adapter->neq_tasklet);
1321 return IRQ_HANDLED;
1322}
1323
1324
1325static int ehea_fill_port_res(struct ehea_port_res *pr)
1326{
1327 int ret;
1328 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1329
Breno Leitaof76957f2011-01-11 07:45:57 +00001330 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001331
Thomas Kleine2878802009-01-21 14:45:57 -08001332 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001333
1334 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1335
1336 return ret;
1337}
1338
1339static int ehea_reg_interrupts(struct net_device *dev)
1340{
1341 struct ehea_port *port = netdev_priv(dev);
1342 struct ehea_port_res *pr;
1343 int i, ret;
1344
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345
1346 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1347 dev->name);
1348
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001349 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001351 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001352 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001353 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1354 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 goto out_free_qpeq;
1356 }
1357
Joe Perches8c4877a2010-12-13 10:05:14 -08001358 netif_info(port, ifup, dev,
1359 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1360 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001362
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001363 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1364 pr = &port->port_res[i];
1365 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001366 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001367 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001368 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001369 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370 pr);
1371 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001372 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1373 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 goto out_free_req;
1375 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001376 netif_info(port, ifup, dev,
1377 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1378 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379 }
1380out:
1381 return ret;
1382
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001383
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384out_free_req:
1385 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001386 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001387 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001388 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001391 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396}
1397
1398static void ehea_free_interrupts(struct net_device *dev)
1399{
1400 struct ehea_port *port = netdev_priv(dev);
1401 struct ehea_port_res *pr;
1402 int i;
1403
1404 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001405
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001406 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1407 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001408 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001409 netif_info(port, intr, dev,
1410 "free send irq for res %d with handle 0x%X\n",
1411 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412 }
1413
1414 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001415 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001416 netif_info(port, intr, dev,
1417 "associated event interrupt for handle 0x%X freed\n",
1418 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419}
1420
1421static int ehea_configure_port(struct ehea_port *port)
1422{
1423 int ret, i;
1424 u64 hret, mask;
1425 struct hcp_ehea_port_cb0 *cb0;
1426
1427 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001428 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001429 if (!cb0)
1430 goto out;
1431
1432 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1433 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1434 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1435 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1436 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1437 PXLY_RC_VLAN_FILTER)
1438 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1439
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001440 for (i = 0; i < port->num_mcs; i++)
1441 if (use_mcs)
1442 cb0->default_qpn_arr[i] =
1443 port->port_res[i].qp->init_attr.qp_nr;
1444 else
1445 cb0->default_qpn_arr[i] =
1446 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001447
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001448 if (netif_msg_ifup(port))
1449 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1450
1451 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1452 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1453
1454 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1455 port->logical_port_id,
1456 H_PORT_CB0, mask, cb0);
1457 ret = -EIO;
1458 if (hret != H_SUCCESS)
1459 goto out_free;
1460
1461 ret = 0;
1462
1463out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001464 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001465out:
1466 return ret;
1467}
1468
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001469int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001470{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001471 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001472 struct ehea_adapter *adapter = pr->port->adapter;
1473
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001474 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1475 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 goto out;
1477
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001478 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1479 if (ret)
1480 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481
1482 return 0;
1483
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001484out_free:
1485 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001487 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001488 return -EIO;
1489}
1490
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001491int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492{
Joe Perches8e95a202009-12-03 07:58:21 +00001493 if ((ehea_rem_mr(&pr->send_mr)) ||
1494 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001495 return -EIO;
1496 else
1497 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498}
1499
1500static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1501{
Doug Maxey508d2b52008-01-31 20:20:49 -06001502 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001503
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001504 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001505 if (!q_skba->arr)
1506 return -ENOMEM;
1507
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001508 q_skba->len = max_q_entries;
1509 q_skba->index = 0;
1510 q_skba->os_skbs = 0;
1511
1512 return 0;
1513}
1514
1515static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1516 struct port_res_cfg *pr_cfg, int queue_token)
1517{
1518 struct ehea_adapter *adapter = port->adapter;
1519 enum ehea_eq_type eq_type = EHEA_EQ;
1520 struct ehea_qp_init_attr *init_attr = NULL;
1521 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001522 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1523
1524 tx_bytes = pr->tx_bytes;
1525 tx_packets = pr->tx_packets;
1526 rx_bytes = pr->rx_bytes;
1527 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001528
1529 memset(pr, 0, sizeof(struct ehea_port_res));
1530
Breno Leitaoce45b872010-10-27 08:45:14 +00001531 pr->tx_bytes = rx_bytes;
1532 pr->tx_packets = tx_packets;
1533 pr->rx_bytes = rx_bytes;
1534 pr->rx_packets = rx_packets;
1535
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001536 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001537 spin_lock_init(&pr->netif_queue);
1538
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001539 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1540 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001541 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001542 goto out_free;
1543 }
1544
1545 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001546 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 port->logical_port_id);
1548 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001549 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001550 goto out_free;
1551 }
1552
1553 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001554 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 port->logical_port_id);
1556 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001557 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558 goto out_free;
1559 }
1560
1561 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001562 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1563 pr->send_cq->attr.act_nr_of_cqes,
1564 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001565
1566 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1567 if (!init_attr) {
1568 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001569 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570 goto out_free;
1571 }
1572
1573 init_attr->low_lat_rq1 = 1;
1574 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1575 init_attr->rq_count = 3;
1576 init_attr->qp_token = queue_token;
1577 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1578 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1579 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1580 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1581 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1582 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1583 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1584 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1585 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1586 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1587 init_attr->port_nr = port->logical_port_id;
1588 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1589 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1590 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1591
1592 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1593 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001594 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001595 ret = -EIO;
1596 goto out_free;
1597 }
1598
1599 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001600 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",
1601 init_attr->qp_nr,
1602 init_attr->act_nr_send_wqes,
1603 init_attr->act_nr_rwqes_rq1,
1604 init_attr->act_nr_rwqes_rq2,
1605 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606
Thomas Klein44fb3122008-04-04 15:04:53 +02001607 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1608
1609 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001610 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1611 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1612 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1613 if (ret)
1614 goto out_free;
1615
1616 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1617 if (ehea_gen_smrs(pr) != 0) {
1618 ret = -EIO;
1619 goto out_free;
1620 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001621
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001622 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1623
1624 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001625
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001626 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001627
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001628 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1629 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1630 pr->lro_mgr.lro_arr = pr->lro_desc;
1631 pr->lro_mgr.get_skb_header = get_skb_hdr;
1632 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1633 pr->lro_mgr.dev = port->netdev;
1634 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1635 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1636
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001637 ret = 0;
1638 goto out;
1639
1640out_free:
1641 kfree(init_attr);
1642 vfree(pr->sq_skba.arr);
1643 vfree(pr->rq1_skba.arr);
1644 vfree(pr->rq2_skba.arr);
1645 vfree(pr->rq3_skba.arr);
1646 ehea_destroy_qp(pr->qp);
1647 ehea_destroy_cq(pr->send_cq);
1648 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001649 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650out:
1651 return ret;
1652}
1653
1654static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1655{
1656 int ret, i;
1657
Hannes Hering357eb462009-08-04 11:48:39 -07001658 if (pr->qp)
1659 netif_napi_del(&pr->napi);
1660
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001661 ret = ehea_destroy_qp(pr->qp);
1662
1663 if (!ret) {
1664 ehea_destroy_cq(pr->send_cq);
1665 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001666 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001667
1668 for (i = 0; i < pr->rq1_skba.len; i++)
1669 if (pr->rq1_skba.arr[i])
1670 dev_kfree_skb(pr->rq1_skba.arr[i]);
1671
1672 for (i = 0; i < pr->rq2_skba.len; i++)
1673 if (pr->rq2_skba.arr[i])
1674 dev_kfree_skb(pr->rq2_skba.arr[i]);
1675
1676 for (i = 0; i < pr->rq3_skba.len; i++)
1677 if (pr->rq3_skba.arr[i])
1678 dev_kfree_skb(pr->rq3_skba.arr[i]);
1679
1680 for (i = 0; i < pr->sq_skba.len; i++)
1681 if (pr->sq_skba.arr[i])
1682 dev_kfree_skb(pr->sq_skba.arr[i]);
1683
1684 vfree(pr->rq1_skba.arr);
1685 vfree(pr->rq2_skba.arr);
1686 vfree(pr->rq3_skba.arr);
1687 vfree(pr->sq_skba.arr);
1688 ret = ehea_rem_smrs(pr);
1689 }
1690 return ret;
1691}
1692
1693/*
1694 * The write_* functions store information in swqe which is used by
1695 * the hardware to calculate the ip/tcp/udp checksum
1696 */
1697
1698static inline void write_ip_start_end(struct ehea_swqe *swqe,
1699 const struct sk_buff *skb)
1700{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001701 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001702 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001703}
1704
1705static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1706 const struct sk_buff *skb)
1707{
1708 swqe->tcp_offset =
1709 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1710
1711 swqe->tcp_end = (u16)skb->len - 1;
1712}
1713
1714static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1715 const struct sk_buff *skb)
1716{
1717 swqe->tcp_offset =
1718 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1719
1720 swqe->tcp_end = (u16)skb->len - 1;
1721}
1722
1723
1724static void write_swqe2_TSO(struct sk_buff *skb,
1725 struct ehea_swqe *swqe, u32 lkey)
1726{
1727 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1728 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001729 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001730 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001731
1732 /* Packet is TCP with TSO enabled */
1733 swqe->tx_control |= EHEA_SWQE_TSO;
1734 swqe->mss = skb_shinfo(skb)->gso_size;
1735 /* copy only eth/ip/tcp headers to immediate data and
1736 * the rest of skb->data to sg1entry
1737 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001738 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001739
Eric Dumazete743d312010-04-14 15:59:40 -07001740 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001741
1742 if (skb_data_size >= headersize) {
1743 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001744 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745 swqe->immediate_data_length = headersize;
1746
1747 if (skb_data_size > headersize) {
1748 /* set sg1entry data */
1749 sg1entry->l_key = lkey;
1750 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001751 sg1entry->vaddr =
1752 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753 swqe->descriptors++;
1754 }
1755 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001756 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757}
1758
1759static void write_swqe2_nonTSO(struct sk_buff *skb,
1760 struct ehea_swqe *swqe, u32 lkey)
1761{
Eric Dumazete743d312010-04-14 15:59:40 -07001762 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001763 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1764 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001765
1766 /* Packet is any nonTSO type
1767 *
1768 * Copy as much as possible skb->data to immediate data and
1769 * the rest to sg1entry
1770 */
1771 if (skb_data_size >= SWQE2_MAX_IMM) {
1772 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001773 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001774
1775 swqe->immediate_data_length = SWQE2_MAX_IMM;
1776
1777 if (skb_data_size > SWQE2_MAX_IMM) {
1778 /* copy sg1entry data */
1779 sg1entry->l_key = lkey;
1780 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001781 sg1entry->vaddr =
1782 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783 swqe->descriptors++;
1784 }
1785 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001786 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001787 swqe->immediate_data_length = skb_data_size;
1788 }
1789}
1790
1791static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1792 struct ehea_swqe *swqe, u32 lkey)
1793{
1794 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1795 skb_frag_t *frag;
1796 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797
1798 nfrags = skb_shinfo(skb)->nr_frags;
1799 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001800 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001801 swqe->descriptors = 0;
1802 sg1entry_contains_frag_data = 0;
1803
1804 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1805 write_swqe2_TSO(skb, swqe, lkey);
1806 else
1807 write_swqe2_nonTSO(skb, swqe, lkey);
1808
1809 /* write descriptors */
1810 if (nfrags > 0) {
1811 if (swqe->descriptors == 0) {
1812 /* sg1entry not yet used */
1813 frag = &skb_shinfo(skb)->frags[0];
1814
1815 /* copy sg1entry data */
1816 sg1entry->l_key = lkey;
1817 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001818 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001819 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001820 swqe->descriptors++;
1821 sg1entry_contains_frag_data = 1;
1822 }
1823
1824 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1825
1826 frag = &skb_shinfo(skb)->frags[i];
1827 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1828
1829 sgentry->l_key = lkey;
1830 sgentry->len = frag->size;
Ian Campbell618c4a02011-10-10 01:11:38 +00001831 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001832 swqe->descriptors++;
1833 }
1834 }
1835}
1836
1837static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1838{
1839 int ret = 0;
1840 u64 hret;
1841 u8 reg_type;
1842
1843 /* De/Register untagged packets */
1844 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1845 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1846 port->logical_port_id,
1847 reg_type, port->mac_addr, 0, hcallid);
1848 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001849 pr_err("%sregistering bc address failed (tagged)\n",
1850 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001851 ret = -EIO;
1852 goto out_herr;
1853 }
1854
1855 /* De/Register VLAN packets */
1856 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1857 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1858 port->logical_port_id,
1859 reg_type, port->mac_addr, 0, hcallid);
1860 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001861 pr_err("%sregistering bc address failed (vlan)\n",
1862 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001863 ret = -EIO;
1864 }
1865out_herr:
1866 return ret;
1867}
1868
1869static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1870{
1871 struct ehea_port *port = netdev_priv(dev);
1872 struct sockaddr *mac_addr = sa;
1873 struct hcp_ehea_port_cb0 *cb0;
1874 int ret;
1875 u64 hret;
1876
1877 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1878 ret = -EADDRNOTAVAIL;
1879 goto out;
1880 }
1881
Thomas Klein3faf2692009-01-21 14:45:33 -08001882 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001883 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001884 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001885 ret = -ENOMEM;
1886 goto out;
1887 }
1888
1889 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1890
1891 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1892
1893 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1894 port->logical_port_id, H_PORT_CB0,
1895 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1896 if (hret != H_SUCCESS) {
1897 ret = -EIO;
1898 goto out_free;
1899 }
1900
1901 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1902
1903 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001904 if (port->state == EHEA_PORT_UP) {
1905 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1906 if (ret)
1907 goto out_upregs;
1908 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001909
1910 port->mac_addr = cb0->port_mac_addr << 16;
1911
1912 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001913 if (port->state == EHEA_PORT_UP) {
1914 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1915 if (ret)
1916 goto out_upregs;
1917 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001918
1919 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001920
1921out_upregs:
1922 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001923out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001924 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001925out:
1926 return ret;
1927}
1928
1929static void ehea_promiscuous_error(u64 hret, int enable)
1930{
Thomas Klein7674a582007-01-22 12:54:20 +01001931 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001932 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1933 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001934 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001935 pr_err("failed %sabling promiscuous mode\n",
1936 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001937}
1938
1939static void ehea_promiscuous(struct net_device *dev, int enable)
1940{
1941 struct ehea_port *port = netdev_priv(dev);
1942 struct hcp_ehea_port_cb7 *cb7;
1943 u64 hret;
1944
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001945 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001946 return;
1947
Thomas Klein3faf2692009-01-21 14:45:33 -08001948 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001949 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001950 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951 goto out;
1952 }
1953
1954 /* Modify Pxs_DUCQPN in CB7 */
1955 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1956
1957 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1958 port->logical_port_id,
1959 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1960 if (hret) {
1961 ehea_promiscuous_error(hret, enable);
1962 goto out;
1963 }
1964
1965 port->promisc = enable;
1966out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001967 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001968}
1969
1970static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1971 u32 hcallid)
1972{
1973 u64 hret;
1974 u8 reg_type;
1975
1976 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1977 | EHEA_BCMC_UNTAGGED;
1978
1979 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1980 port->logical_port_id,
1981 reg_type, mc_mac_addr, 0, hcallid);
1982 if (hret)
1983 goto out;
1984
1985 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1986 | EHEA_BCMC_VLANID_ALL;
1987
1988 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1989 port->logical_port_id,
1990 reg_type, mc_mac_addr, 0, hcallid);
1991out:
1992 return hret;
1993}
1994
1995static int ehea_drop_multicast_list(struct net_device *dev)
1996{
1997 struct ehea_port *port = netdev_priv(dev);
1998 struct ehea_mc_list *mc_entry = port->mc_list;
1999 struct list_head *pos;
2000 struct list_head *temp;
2001 int ret = 0;
2002 u64 hret;
2003
2004 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2005 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2006
2007 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2008 H_DEREG_BCMC);
2009 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002010 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002011 ret = -EIO;
2012 }
2013
2014 list_del(pos);
2015 kfree(mc_entry);
2016 }
2017 return ret;
2018}
2019
2020static void ehea_allmulti(struct net_device *dev, int enable)
2021{
2022 struct ehea_port *port = netdev_priv(dev);
2023 u64 hret;
2024
2025 if (!port->allmulti) {
2026 if (enable) {
2027 /* Enable ALLMULTI */
2028 ehea_drop_multicast_list(dev);
2029 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2030 if (!hret)
2031 port->allmulti = 1;
2032 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002033 netdev_err(dev,
2034 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 }
2036 } else
2037 if (!enable) {
2038 /* Disable ALLMULTI */
2039 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2040 if (!hret)
2041 port->allmulti = 0;
2042 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002043 netdev_err(dev,
2044 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002045 }
2046}
2047
Doug Maxey508d2b52008-01-31 20:20:49 -06002048static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049{
2050 struct ehea_mc_list *ehea_mcl_entry;
2051 u64 hret;
2052
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002053 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002055 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002056 return;
2057 }
2058
2059 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2060
2061 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2062
2063 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2064 H_REG_BCMC);
2065 if (!hret)
2066 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2067 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002068 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002069 kfree(ehea_mcl_entry);
2070 }
2071}
2072
2073static void ehea_set_multicast_list(struct net_device *dev)
2074{
2075 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002076 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002077 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002078
Breno Leitaoa4910b72011-05-23 03:36:35 +00002079 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002080 ehea_promiscuous(dev, 1);
2081 return;
2082 }
2083 ehea_promiscuous(dev, 0);
2084
2085 if (dev->flags & IFF_ALLMULTI) {
2086 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002087 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002088 }
2089 ehea_allmulti(dev, 0);
2090
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002091 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002092 ret = ehea_drop_multicast_list(dev);
2093 if (ret) {
2094 /* Dropping the current multicast list failed.
2095 * Enabling ALL_MULTI is the best we can do.
2096 */
2097 ehea_allmulti(dev, 1);
2098 }
2099
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002100 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002101 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2102 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002103 goto out;
2104 }
2105
Jiri Pirko22bedad32010-04-01 21:22:57 +00002106 netdev_for_each_mc_addr(ha, dev)
2107 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002108
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109 }
2110out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002111 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112}
2113
2114static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2115{
2116 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2117 return -EINVAL;
2118 dev->mtu = new_mtu;
2119 return 0;
2120}
2121
2122static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2123 struct ehea_swqe *swqe, u32 lkey)
2124{
2125 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002126 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002127
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128 /* IPv4 */
2129 swqe->tx_control |= EHEA_SWQE_CRC
2130 | EHEA_SWQE_IP_CHECKSUM
2131 | EHEA_SWQE_TCP_CHECKSUM
2132 | EHEA_SWQE_IMM_DATA_PRESENT
2133 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2134
2135 write_ip_start_end(swqe, skb);
2136
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002137 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002138 if ((iph->frag_off & IP_MF) ||
2139 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002140 /* IP fragment, so don't change cs */
2141 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2142 else
2143 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002144 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002145 write_tcp_offset_end(swqe, skb);
2146 }
2147
2148 /* icmp (big data) and ip segmentation packets (all other ip
2149 packets) do not require any special handling */
2150
2151 } else {
2152 /* Other Ethernet Protocol */
2153 swqe->tx_control |= EHEA_SWQE_CRC
2154 | EHEA_SWQE_IMM_DATA_PRESENT
2155 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2156 }
2157
2158 write_swqe2_data(skb, dev, swqe, lkey);
2159}
2160
2161static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2162 struct ehea_swqe *swqe)
2163{
2164 int nfrags = skb_shinfo(skb)->nr_frags;
2165 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2166 skb_frag_t *frag;
2167 int i;
2168
2169 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002170 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002171
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002172 /* IPv4 */
2173 write_ip_start_end(swqe, skb);
2174
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002175 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002176 swqe->tx_control |= EHEA_SWQE_CRC
2177 | EHEA_SWQE_IP_CHECKSUM
2178 | EHEA_SWQE_TCP_CHECKSUM
2179 | EHEA_SWQE_IMM_DATA_PRESENT;
2180
2181 write_tcp_offset_end(swqe, skb);
2182
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002183 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002184 if ((iph->frag_off & IP_MF) ||
2185 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002186 /* IP fragment, so don't change cs */
2187 swqe->tx_control |= EHEA_SWQE_CRC
2188 | EHEA_SWQE_IMM_DATA_PRESENT;
2189 else {
2190 swqe->tx_control |= EHEA_SWQE_CRC
2191 | EHEA_SWQE_IP_CHECKSUM
2192 | EHEA_SWQE_TCP_CHECKSUM
2193 | EHEA_SWQE_IMM_DATA_PRESENT;
2194
2195 write_udp_offset_end(swqe, skb);
2196 }
2197 } else {
2198 /* icmp (big data) and
2199 ip segmentation packets (all other ip packets) */
2200 swqe->tx_control |= EHEA_SWQE_CRC
2201 | EHEA_SWQE_IP_CHECKSUM
2202 | EHEA_SWQE_IMM_DATA_PRESENT;
2203 }
2204 } else {
2205 /* Other Ethernet Protocol */
2206 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2207 }
2208 /* copy (immediate) data */
2209 if (nfrags == 0) {
2210 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002211 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002212 } else {
2213 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002214 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002215 skb_headlen(skb));
2216 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002217
2218 /* ... then copy data from the fragments */
2219 for (i = 0; i < nfrags; i++) {
2220 frag = &skb_shinfo(skb)->frags[i];
Ian Campbell618c4a02011-10-10 01:11:38 +00002221 memcpy(imm_data, skb_frag_address(frag), frag->size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002222 imm_data += frag->size;
2223 }
2224 }
2225 swqe->immediate_data_length = skb->len;
2226 dev_kfree_skb(skb);
2227}
2228
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002229static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2230{
2231 struct tcphdr *tcp;
2232 u32 tmp;
2233
2234 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002235 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002236 tcp = (struct tcphdr *)(skb_network_header(skb) +
2237 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002239 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002240 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002241 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002242 return 0;
2243}
2244
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002245static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2246{
2247 struct ehea_port *port = netdev_priv(dev);
2248 struct ehea_swqe *swqe;
2249 unsigned long flags;
2250 u32 lkey;
2251 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002253
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002254 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2255
Anton Blanchard3f7947b2011-10-14 05:30:58 +00002256 if (pr->queue_stopped)
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002257 return NETDEV_TX_BUSY;
2258
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002259 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2260 memset(swqe, 0, SWQE_HEADER_SIZE);
2261 atomic_dec(&pr->swqe_avail);
2262
Eric Dumazete5ccd962010-10-26 19:21:07 +00002263 if (vlan_tx_tag_present(skb)) {
2264 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2265 swqe->vlan_tag = vlan_tx_tag_get(skb);
2266 }
2267
Breno Leitaoce45b872010-10-27 08:45:14 +00002268 pr->tx_packets++;
2269 pr->tx_bytes += skb->len;
2270
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002271 if (skb->len <= SWQE3_MAX_IMM) {
2272 u32 sig_iv = port->sig_comp_iv;
2273 u32 swqe_num = pr->swqe_id_counter;
2274 ehea_xmit3(skb, dev, swqe);
2275 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2276 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2277 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2278 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2279 sig_iv);
2280 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2281 pr->swqe_ll_count = 0;
2282 } else
2283 pr->swqe_ll_count += 1;
2284 } else {
2285 swqe->wr_id =
2286 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2287 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002288 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002289 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2290 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2291
2292 pr->sq_skba.index++;
2293 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2294
2295 lkey = pr->send_mr.lkey;
2296 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002297 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 }
2299 pr->swqe_id_counter += 1;
2300
Joe Perches8c4877a2010-12-13 10:05:14 -08002301 netif_info(port, tx_queued, dev,
2302 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2303 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002304 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002305
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002306 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2307 netif_stop_queue(dev);
2308 swqe->tx_control |= EHEA_SWQE_PURGE;
2309 }
Thomas Klein44c82152007-07-11 16:32:00 +02002310
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002311 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312
2313 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2314 spin_lock_irqsave(&pr->netif_queue, flags);
2315 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002316 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002317 netif_stop_queue(dev);
2318 pr->queue_stopped = 1;
2319 }
2320 spin_unlock_irqrestore(&pr->netif_queue, flags);
2321 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002322
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002323 return NETDEV_TX_OK;
2324}
2325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2327{
2328 struct ehea_port *port = netdev_priv(dev);
2329 struct ehea_adapter *adapter = port->adapter;
2330 struct hcp_ehea_port_cb1 *cb1;
2331 int index;
2332 u64 hret;
2333
Thomas Klein3faf2692009-01-21 14:45:33 -08002334 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002335 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002336 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002337 goto out;
2338 }
2339
2340 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2341 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2342 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002343 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002344 goto out;
2345 }
2346
2347 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002348 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002349
2350 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2351 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2352 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002353 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002355 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 return;
2357}
2358
2359static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2360{
2361 struct ehea_port *port = netdev_priv(dev);
2362 struct ehea_adapter *adapter = port->adapter;
2363 struct hcp_ehea_port_cb1 *cb1;
2364 int index;
2365 u64 hret;
2366
Thomas Klein3faf2692009-01-21 14:45:33 -08002367 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002368 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002369 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002370 goto out;
2371 }
2372
2373 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2374 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2375 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002376 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 goto out;
2378 }
2379
2380 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002381 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382
2383 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2384 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2385 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002386 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002388 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002389}
2390
2391int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2392{
2393 int ret = -EIO;
2394 u64 hret;
2395 u16 dummy16 = 0;
2396 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002397 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398
Thomas Klein3faf2692009-01-21 14:45:33 -08002399 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002400 if (!cb0) {
2401 ret = -ENOMEM;
2402 goto out;
2403 }
2404
2405 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2406 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2407 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002408 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002409 goto out;
2410 }
2411
2412 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2413 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2414 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2415 &dummy64, &dummy64, &dummy16, &dummy16);
2416 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002417 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002418 goto out;
2419 }
2420
2421 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2422 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2423 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002424 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425 goto out;
2426 }
2427
2428 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2429 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2430 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2431 &dummy64, &dummy64, &dummy16, &dummy16);
2432 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002433 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002434 goto out;
2435 }
2436
2437 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2438 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2439 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002440 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441 goto out;
2442 }
2443
2444 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2445 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2446 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2447 &dummy64, &dummy64, &dummy16, &dummy16);
2448 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002449 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002450 goto out;
2451 }
2452
2453 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2454 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2455 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002456 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002457 goto out;
2458 }
2459
2460 ret = 0;
2461out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002462 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002463 return ret;
2464}
2465
2466static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2467 int add_tx_qps)
2468{
2469 int ret, i;
2470 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2471 enum ehea_eq_type eq_type = EHEA_EQ;
2472
2473 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2474 EHEA_MAX_ENTRIES_EQ, 1);
2475 if (!port->qp_eq) {
2476 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002477 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 goto out_kill_eq;
2479 }
2480
2481 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002482 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483 pr_cfg.max_entries_sq = sq_entries;
2484 pr_cfg.max_entries_rq1 = rq1_entries;
2485 pr_cfg.max_entries_rq2 = rq2_entries;
2486 pr_cfg.max_entries_rq3 = rq3_entries;
2487
2488 pr_cfg_small_rx.max_entries_rcq = 1;
2489 pr_cfg_small_rx.max_entries_scq = sq_entries;
2490 pr_cfg_small_rx.max_entries_sq = sq_entries;
2491 pr_cfg_small_rx.max_entries_rq1 = 1;
2492 pr_cfg_small_rx.max_entries_rq2 = 1;
2493 pr_cfg_small_rx.max_entries_rq3 = 1;
2494
2495 for (i = 0; i < def_qps; i++) {
2496 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2497 if (ret)
2498 goto out_clean_pr;
2499 }
2500 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2501 ret = ehea_init_port_res(port, &port->port_res[i],
2502 &pr_cfg_small_rx, i);
2503 if (ret)
2504 goto out_clean_pr;
2505 }
2506
2507 return 0;
2508
2509out_clean_pr:
2510 while (--i >= 0)
2511 ehea_clean_portres(port, &port->port_res[i]);
2512
2513out_kill_eq:
2514 ehea_destroy_eq(port->qp_eq);
2515 return ret;
2516}
2517
2518static int ehea_clean_all_portres(struct ehea_port *port)
2519{
2520 int ret = 0;
2521 int i;
2522
Doug Maxey508d2b52008-01-31 20:20:49 -06002523 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002524 ret |= ehea_clean_portres(port, &port->port_res[i]);
2525
2526 ret |= ehea_destroy_eq(port->qp_eq);
2527
2528 return ret;
2529}
2530
Thomas Klein35cf2e22007-08-06 13:55:14 +02002531static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002532{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002533 if (adapter->active_ports)
2534 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002535
2536 ehea_rem_mr(&adapter->mr);
2537}
2538
Thomas Klein35cf2e22007-08-06 13:55:14 +02002539static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002540{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002541 if (adapter->active_ports)
2542 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002543
2544 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2545}
2546
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002547static int ehea_up(struct net_device *dev)
2548{
2549 int ret, i;
2550 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002551
2552 if (port->state == EHEA_PORT_UP)
2553 return 0;
2554
2555 ret = ehea_port_res_setup(port, port->num_def_qps,
2556 port->num_add_tx_qps);
2557 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002558 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002559 goto out;
2560 }
2561
2562 /* Set default QP for this port */
2563 ret = ehea_configure_port(port);
2564 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002565 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002566 goto out_clean_pr;
2567 }
2568
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569 ret = ehea_reg_interrupts(dev);
2570 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002571 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002572 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002573 }
2574
Doug Maxey508d2b52008-01-31 20:20:49 -06002575 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002576 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2577 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002578 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002579 goto out_free_irqs;
2580 }
2581 }
2582
Doug Maxey508d2b52008-01-31 20:20:49 -06002583 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002584 ret = ehea_fill_port_res(&port->port_res[i]);
2585 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002586 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002587 goto out_free_irqs;
2588 }
2589 }
2590
Thomas Klein21eee2d2008-02-13 16:18:33 +01002591 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2592 if (ret) {
2593 ret = -EIO;
2594 goto out_free_irqs;
2595 }
2596
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002597 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002598
2599 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002600 goto out;
2601
2602out_free_irqs:
2603 ehea_free_interrupts(dev);
2604
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002605out_clean_pr:
2606 ehea_clean_all_portres(port);
2607out:
Thomas Klein44c82152007-07-11 16:32:00 +02002608 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002609 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002610
Thomas Klein21eee2d2008-02-13 16:18:33 +01002611 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002612 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 return ret;
2615}
2616
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002617static void port_napi_disable(struct ehea_port *port)
2618{
2619 int i;
2620
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002621 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002622 napi_disable(&port->port_res[i].napi);
2623}
2624
2625static void port_napi_enable(struct ehea_port *port)
2626{
2627 int i;
2628
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002629 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002630 napi_enable(&port->port_res[i].napi);
2631}
2632
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002633static int ehea_open(struct net_device *dev)
2634{
2635 int ret;
2636 struct ehea_port *port = netdev_priv(dev);
2637
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002638 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002639
Joe Perches8c4877a2010-12-13 10:05:14 -08002640 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002641
2642 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002643 if (!ret) {
2644 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002645 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002646 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002647
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002648 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002649 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650
2651 return ret;
2652}
2653
2654static int ehea_down(struct net_device *dev)
2655{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002656 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002657 struct ehea_port *port = netdev_priv(dev);
2658
2659 if (port->state == EHEA_PORT_DOWN)
2660 return 0;
2661
2662 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002663 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2664
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002665 ehea_free_interrupts(dev);
2666
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002667 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002668
Thomas Klein21eee2d2008-02-13 16:18:33 +01002669 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002670
Thomas Klein44c82152007-07-11 16:32:00 +02002671 ret = ehea_clean_all_portres(port);
2672 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002673 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002674
Thomas Klein21eee2d2008-02-13 16:18:33 +01002675 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002676
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677 return ret;
2678}
2679
2680static int ehea_stop(struct net_device *dev)
2681{
2682 int ret;
2683 struct ehea_port *port = netdev_priv(dev);
2684
Joe Perches8c4877a2010-12-13 10:05:14 -08002685 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002686
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002687 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002688 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002689 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002690 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002691 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002692 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002693 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002694 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002695 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002696 return ret;
2697}
2698
Andrew Morton22559c52008-04-18 13:50:39 -07002699static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002700{
2701 struct ehea_qp qp = *orig_qp;
2702 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2703 struct ehea_swqe *swqe;
2704 int wqe_index;
2705 int i;
2706
2707 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2708 swqe = ehea_get_swqe(&qp, &wqe_index);
2709 swqe->tx_control |= EHEA_SWQE_PURGE;
2710 }
2711}
2712
Andrew Morton22559c52008-04-18 13:50:39 -07002713static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002714{
2715 int i;
2716
2717 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2718 struct ehea_port_res *pr = &port->port_res[i];
2719 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002720 int ret;
2721
2722 ret = wait_event_timeout(port->swqe_avail_wq,
2723 atomic_read(&pr->swqe_avail) >= swqe_max,
2724 msecs_to_jiffies(100));
2725
2726 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002727 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002728 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002729 }
2730 }
2731}
2732
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002733int ehea_stop_qps(struct net_device *dev)
2734{
2735 struct ehea_port *port = netdev_priv(dev);
2736 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002737 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002738 int ret = -EIO;
2739 int dret;
2740 int i;
2741 u64 hret;
2742 u64 dummy64 = 0;
2743 u16 dummy16 = 0;
2744
Thomas Klein3faf2692009-01-21 14:45:33 -08002745 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002746 if (!cb0) {
2747 ret = -ENOMEM;
2748 goto out;
2749 }
2750
2751 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2752 struct ehea_port_res *pr = &port->port_res[i];
2753 struct ehea_qp *qp = pr->qp;
2754
2755 /* Purge send queue */
2756 ehea_purge_sq(qp);
2757
2758 /* Disable queue pair */
2759 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2760 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2761 cb0);
2762 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002763 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002764 goto out;
2765 }
2766
2767 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2768 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2769
2770 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2771 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2772 1), cb0, &dummy64,
2773 &dummy64, &dummy16, &dummy16);
2774 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002775 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002776 goto out;
2777 }
2778
2779 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2780 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2781 cb0);
2782 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002783 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002784 goto out;
2785 }
2786
2787 /* deregister shared memory regions */
2788 dret = ehea_rem_smrs(pr);
2789 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002790 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002791 goto out;
2792 }
2793 }
2794
2795 ret = 0;
2796out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002797 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002798
2799 return ret;
2800}
2801
Doug Maxey508d2b52008-01-31 20:20:49 -06002802void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002803{
2804 struct ehea_qp qp = *orig_qp;
2805 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2806 struct ehea_rwqe *rwqe;
2807 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2808 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2809 struct sk_buff *skb;
2810 u32 lkey = pr->recv_mr.lkey;
2811
2812
2813 int i;
2814 int index;
2815
2816 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2817 rwqe = ehea_get_next_rwqe(&qp, 2);
2818 rwqe->sg_list[0].l_key = lkey;
2819 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2820 skb = skba_rq2[index];
2821 if (skb)
2822 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2823 }
2824
2825 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2826 rwqe = ehea_get_next_rwqe(&qp, 3);
2827 rwqe->sg_list[0].l_key = lkey;
2828 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2829 skb = skba_rq3[index];
2830 if (skb)
2831 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2832 }
2833}
2834
2835int ehea_restart_qps(struct net_device *dev)
2836{
2837 struct ehea_port *port = netdev_priv(dev);
2838 struct ehea_adapter *adapter = port->adapter;
2839 int ret = 0;
2840 int i;
2841
Doug Maxey508d2b52008-01-31 20:20:49 -06002842 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002843 u64 hret;
2844 u64 dummy64 = 0;
2845 u16 dummy16 = 0;
2846
Thomas Klein3faf2692009-01-21 14:45:33 -08002847 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002848 if (!cb0) {
2849 ret = -ENOMEM;
2850 goto out;
2851 }
2852
2853 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2854 struct ehea_port_res *pr = &port->port_res[i];
2855 struct ehea_qp *qp = pr->qp;
2856
2857 ret = ehea_gen_smrs(pr);
2858 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002859 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002860 goto out;
2861 }
2862
2863 ehea_update_rqs(qp, pr);
2864
2865 /* Enable queue pair */
2866 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2867 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2868 cb0);
2869 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002870 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002871 goto out;
2872 }
2873
2874 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2875 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2876
2877 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2878 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2879 1), cb0, &dummy64,
2880 &dummy64, &dummy16, &dummy16);
2881 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002882 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002883 goto out;
2884 }
2885
2886 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2887 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2888 cb0);
2889 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002890 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002891 goto out;
2892 }
2893
2894 /* refill entire queue */
2895 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2896 ehea_refill_rq2(pr, 0);
2897 ehea_refill_rq3(pr, 0);
2898 }
2899out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002900 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002901
2902 return ret;
2903}
2904
David Howellsc4028952006-11-22 14:57:56 +00002905static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002906{
2907 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002908 struct ehea_port *port =
2909 container_of(work, struct ehea_port, reset_task);
2910 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002911
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002912 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002913 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002914 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002915 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002916
2917 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002918
Thomas Klein44c82152007-07-11 16:32:00 +02002919 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002920
2921 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002922 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002923 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002924
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002925 ehea_set_multicast_list(dev);
2926
Joe Perches8c4877a2010-12-13 10:05:14 -08002927 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002928
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002929 port_napi_enable(port);
2930
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002931 netif_wake_queue(dev);
2932out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002933 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002934 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002935}
2936
Tejun Heo3d6b8922010-12-12 16:45:14 +01002937static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002938{
2939 int ret, i;
2940 struct ehea_adapter *adapter;
2941
Joe Perches8c4877a2010-12-13 10:05:14 -08002942 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002943
2944 list_for_each_entry(adapter, &adapter_list, list)
2945 if (adapter->active_ports) {
2946 /* Shutdown all ports */
2947 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2948 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002949 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002950
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002951 if (!port)
2952 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002953
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002954 dev = port->netdev;
2955
2956 if (dev->flags & IFF_UP) {
2957 mutex_lock(&port->port_lock);
2958 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002959 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002960 ret = ehea_stop_qps(dev);
2961 if (ret) {
2962 mutex_unlock(&port->port_lock);
2963 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002964 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002965 port_napi_disable(port);
2966 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002967 }
Andre Detsch2928db42010-08-17 05:49:12 +00002968 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002969 }
2970
2971 /* Unregister old memory region */
2972 ret = ehea_rem_mr(&adapter->mr);
2973 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002974 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002975 goto out;
2976 }
2977 }
2978
Thomas Klein44c82152007-07-11 16:32:00 +02002979 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2980
2981 list_for_each_entry(adapter, &adapter_list, list)
2982 if (adapter->active_ports) {
2983 /* Register new memory region */
2984 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2985 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002986 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002987 goto out;
2988 }
2989
2990 /* Restart all ports */
2991 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2992 struct ehea_port *port = adapter->port[i];
2993
2994 if (port) {
2995 struct net_device *dev = port->netdev;
2996
2997 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002998 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002999 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003000 if (!ret) {
3001 check_sqs(port);
3002 port_napi_enable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003003 netif_wake_queue(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003004 } else {
3005 netdev_err(dev, "Unable to restart QPS\n");
3006 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003007 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003008 }
3009 }
3010 }
3011 }
Joe Perches8c4877a2010-12-13 10:05:14 -08003012 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003013out:
3014 return;
3015}
3016
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003017static void ehea_tx_watchdog(struct net_device *dev)
3018{
3019 struct ehea_port *port = netdev_priv(dev);
3020
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003021 if (netif_carrier_ok(dev) &&
3022 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003023 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003024}
3025
3026int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3027{
3028 struct hcp_query_ehea *cb;
3029 u64 hret;
3030 int ret;
3031
Thomas Klein3faf2692009-01-21 14:45:33 -08003032 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003033 if (!cb) {
3034 ret = -ENOMEM;
3035 goto out;
3036 }
3037
3038 hret = ehea_h_query_ehea(adapter->handle, cb);
3039
3040 if (hret != H_SUCCESS) {
3041 ret = -EIO;
3042 goto out_herr;
3043 }
3044
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045 adapter->max_mc_mac = cb->max_mc_mac - 1;
3046 ret = 0;
3047
3048out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003049 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003050out:
3051 return ret;
3052}
3053
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003054int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3055{
3056 struct hcp_ehea_port_cb4 *cb4;
3057 u64 hret;
3058 int ret = 0;
3059
3060 *jumbo = 0;
3061
3062 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003063 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003065 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003066 ret = -ENOMEM;
3067 goto out;
3068 } else {
3069 hret = ehea_h_query_ehea_port(port->adapter->handle,
3070 port->logical_port_id,
3071 H_PORT_CB4,
3072 H_PORT_CB4_JUMBO, cb4);
3073 if (hret == H_SUCCESS) {
3074 if (cb4->jumbo_frame)
3075 *jumbo = 1;
3076 else {
3077 cb4->jumbo_frame = 1;
3078 hret = ehea_h_modify_ehea_port(port->adapter->
3079 handle,
3080 port->
3081 logical_port_id,
3082 H_PORT_CB4,
3083 H_PORT_CB4_JUMBO,
3084 cb4);
3085 if (hret == H_SUCCESS)
3086 *jumbo = 1;
3087 }
3088 } else
3089 ret = -EINVAL;
3090
Thomas Klein3faf2692009-01-21 14:45:33 -08003091 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003092 }
3093out:
3094 return ret;
3095}
3096
3097static ssize_t ehea_show_port_id(struct device *dev,
3098 struct device_attribute *attr, char *buf)
3099{
3100 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003101 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102}
3103
3104static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3105 NULL);
3106
3107static void __devinit logical_port_release(struct device *dev)
3108{
3109 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003110 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003111}
3112
3113static struct device *ehea_register_port(struct ehea_port *port,
3114 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003115{
3116 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003117
Grant Likely61c7a082010-04-13 16:12:29 -07003118 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003119 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003120 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003121
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003122 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003123 port->ofdev.dev.release = logical_port_release;
3124
3125 ret = of_device_register(&port->ofdev);
3126 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003127 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003128 goto out;
3129 }
3130
3131 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003132 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003133 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003134 goto out_unreg_of_dev;
3135 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003136
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137 return &port->ofdev.dev;
3138
3139out_unreg_of_dev:
3140 of_device_unregister(&port->ofdev);
3141out:
3142 return NULL;
3143}
3144
3145static void ehea_unregister_port(struct ehea_port *port)
3146{
3147 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3148 of_device_unregister(&port->ofdev);
3149}
3150
Thomas Klein086c1b22009-01-21 14:43:59 -08003151static const struct net_device_ops ehea_netdev_ops = {
3152 .ndo_open = ehea_open,
3153 .ndo_stop = ehea_stop,
3154 .ndo_start_xmit = ehea_start_xmit,
3155#ifdef CONFIG_NET_POLL_CONTROLLER
3156 .ndo_poll_controller = ehea_netpoll,
3157#endif
3158 .ndo_get_stats = ehea_get_stats,
3159 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003160 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003161 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003162 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003163 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003164 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3165 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003166};
3167
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3169 u32 logical_port_id,
3170 struct device_node *dn)
3171{
3172 int ret;
3173 struct net_device *dev;
3174 struct ehea_port *port;
3175 struct device *port_dev;
3176 int jumbo;
3177
3178 /* allocate memory for the port structures */
3179 dev = alloc_etherdev(sizeof(struct ehea_port));
3180
3181 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003182 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183 ret = -ENOMEM;
3184 goto out_err;
3185 }
3186
3187 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003188
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003189 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003190 port->state = EHEA_PORT_DOWN;
3191 port->sig_comp_iv = sq_entries / 10;
3192
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003193 port->adapter = adapter;
3194 port->netdev = dev;
3195 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003196
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003197 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003198
3199 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3200 if (!port->mc_list) {
3201 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003202 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003203 }
3204
3205 INIT_LIST_HEAD(&port->mc_list->list);
3206
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003207 ret = ehea_sense_port_attr(port);
3208 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003209 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003210
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003211 port_dev = ehea_register_port(port, dn);
3212 if (!port_dev)
3213 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003214
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003216
3217 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003218 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3219
Thomas Klein086c1b22009-01-21 14:43:59 -08003220 dev->netdev_ops = &ehea_netdev_ops;
3221 ehea_set_ethtool_ops(dev);
3222
Michał Mirosławf4786a92011-04-17 00:15:47 +00003223 dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3224 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003225 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003226 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003227 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003228 | NETIF_F_RXCSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003229 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3230
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003231 if (use_lro)
3232 dev->features |= NETIF_F_LRO;
3233
David Howellsc4028952006-11-22 14:57:56 +00003234 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003235 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003236
Anton Blanchard21ccc792011-05-10 16:17:10 +00003237 init_waitqueue_head(&port->swqe_avail_wq);
3238 init_waitqueue_head(&port->restart_wq);
3239
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003240 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003241 ret = register_netdev(dev);
3242 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003243 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003244 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245 }
3246
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003247 port->lro_max_aggr = lro_max_aggr;
3248
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003250 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003251 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252
Joe Perches8c4877a2010-12-13 10:05:14 -08003253 netdev_info(dev, "Jumbo frames are %sabled\n",
3254 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003255
Thomas Klein44c82152007-07-11 16:32:00 +02003256 adapter->active_ports++;
3257
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260out_unreg_port:
3261 ehea_unregister_port(port);
3262
3263out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003264 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003265
3266out_free_ethdev:
3267 free_netdev(dev);
3268
3269out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003270 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3271 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003272 return NULL;
3273}
3274
3275static void ehea_shutdown_single_port(struct ehea_port *port)
3276{
Brian King7fb1c2a2008-05-14 09:48:25 -05003277 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003278
3279 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003280 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003281 unregister_netdev(port->netdev);
3282 ehea_unregister_port(port);
3283 kfree(port->mc_list);
3284 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003285 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003286}
3287
3288static int ehea_setup_ports(struct ehea_adapter *adapter)
3289{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290 struct device_node *lhea_dn;
3291 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003292
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003293 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003294 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003295
Grant Likely61c7a082010-04-13 16:12:29 -07003296 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003297 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003298
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003299 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003300 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003301 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003302 pr_err("bad device node: eth_dn name=%s\n",
3303 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305 }
3306
Thomas Klein1211bb62007-04-26 11:56:43 +02003307 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003308 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003309 of_node_put(eth_dn);
3310 return -EIO;
3311 }
3312
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003313 adapter->port[i] = ehea_setup_single_port(adapter,
3314 *dn_log_port_id,
3315 eth_dn);
3316 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003317 netdev_info(adapter->port[i]->netdev,
3318 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003319 else
3320 ehea_remove_adapter_mr(adapter);
3321
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003323 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003324 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325}
3326
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003327static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3328 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329{
3330 struct device_node *lhea_dn;
3331 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003332 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333
Grant Likely61c7a082010-04-13 16:12:29 -07003334 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003335 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003336
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003337 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003338 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003339 if (dn_log_port_id)
3340 if (*dn_log_port_id == logical_port_id)
3341 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003342 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343
3344 return NULL;
3345}
3346
3347static ssize_t ehea_probe_port(struct device *dev,
3348 struct device_attribute *attr,
3349 const char *buf, size_t count)
3350{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003351 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352 struct ehea_port *port;
3353 struct device_node *eth_dn = NULL;
3354 int i;
3355
3356 u32 logical_port_id;
3357
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003358 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359
3360 port = ehea_get_port(adapter, logical_port_id);
3361
3362 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003363 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3364 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365 return -EINVAL;
3366 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003367
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003368 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3369
3370 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003371 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372 return -EINVAL;
3373 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003374
Thomas Klein1211bb62007-04-26 11:56:43 +02003375 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003376 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003377 return -EIO;
3378 }
3379
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3381
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003382 of_node_put(eth_dn);
3383
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003384 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003385 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003386 if (!adapter->port[i]) {
3387 adapter->port[i] = port;
3388 break;
3389 }
3390
Joe Perches8c4877a2010-12-13 10:05:14 -08003391 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3392 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003393 } else {
3394 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003395 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003396 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397
3398 return (ssize_t) count;
3399}
3400
3401static ssize_t ehea_remove_port(struct device *dev,
3402 struct device_attribute *attr,
3403 const char *buf, size_t count)
3404{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003405 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003406 struct ehea_port *port;
3407 int i;
3408 u32 logical_port_id;
3409
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003410 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003411
3412 port = ehea_get_port(adapter, logical_port_id);
3413
3414 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003415 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3416 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003417
3418 ehea_shutdown_single_port(port);
3419
Doug Maxey508d2b52008-01-31 20:20:49 -06003420 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003421 if (adapter->port[i] == port) {
3422 adapter->port[i] = NULL;
3423 break;
3424 }
3425 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003426 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3427 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003428 return -EINVAL;
3429 }
3430
Thomas Klein1211bb62007-04-26 11:56:43 +02003431 ehea_remove_adapter_mr(adapter);
3432
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433 return (ssize_t) count;
3434}
3435
3436static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3437static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3438
Grant Likely2dc11582010-08-06 09:25:50 -06003439int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003440{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003441 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003442 if (ret)
3443 goto out;
3444
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003445 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003446out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447 return ret;
3448}
3449
Grant Likely2dc11582010-08-06 09:25:50 -06003450void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003452 device_remove_file(&dev->dev, &dev_attr_probe_port);
3453 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003454}
3455
Grant Likely2dc11582010-08-06 09:25:50 -06003456static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003457 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458{
3459 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003460 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003461 int ret;
3462
Grant Likely61c7a082010-04-13 16:12:29 -07003463 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003464 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003465 return -EINVAL;
3466 }
3467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3469 if (!adapter) {
3470 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003471 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003472 goto out;
3473 }
3474
Thomas Klein44c82152007-07-11 16:32:00 +02003475 list_add(&adapter->list, &adapter_list);
3476
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003477 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003478
Grant Likely61c7a082010-04-13 16:12:29 -07003479 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003480 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003481 if (adapter_handle)
3482 adapter->handle = *adapter_handle;
3483
3484 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003485 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003486 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003487 ret = -ENODEV;
3488 goto out_free_ad;
3489 }
3490
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491 adapter->pd = EHEA_PD_ID;
3492
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003493 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495
3496 /* initialize adapter and ports */
3497 /* get adapter properties */
3498 ret = ehea_sense_adapter_attr(adapter);
3499 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003500 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003501 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003502 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503
3504 adapter->neq = ehea_create_eq(adapter,
3505 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3506 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003507 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003508 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003509 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510 }
3511
3512 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3513 (unsigned long)adapter);
3514
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003515 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003516 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 "ehea_neq", adapter);
3518 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003519 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003520 goto out_kill_eq;
3521 }
3522
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003523 ret = ehea_create_device_sysfs(dev);
3524 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003525 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 ret = ehea_setup_ports(adapter);
3528 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003529 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003530 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 }
3532
3533 ret = 0;
3534 goto out;
3535
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003536out_rem_dev_sysfs:
3537 ehea_remove_device_sysfs(dev);
3538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003540 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003541
3542out_kill_eq:
3543 ehea_destroy_eq(adapter->neq);
3544
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003545out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003546 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003548
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003549out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003550 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003551
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003552 return ret;
3553}
3554
Grant Likely2dc11582010-08-06 09:25:50 -06003555static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003556{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003557 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003558 int i;
3559
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003560 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561 if (adapter->port[i]) {
3562 ehea_shutdown_single_port(adapter->port[i]);
3563 adapter->port[i] = NULL;
3564 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003565
3566 ehea_remove_device_sysfs(dev);
3567
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003568 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003569 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570
3571 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003572 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003573 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003575
Thomas Klein21eee2d2008-02-13 16:18:33 +01003576 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003577
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003578 return 0;
3579}
3580
Thomas Klein21eee2d2008-02-13 16:18:33 +01003581void ehea_crash_handler(void)
3582{
3583 int i;
3584
3585 if (ehea_fw_handles.arr)
3586 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3587 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3588 ehea_fw_handles.arr[i].fwh,
3589 FORCE_FREE);
3590
3591 if (ehea_bcmc_regs.arr)
3592 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3593 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3594 ehea_bcmc_regs.arr[i].port_id,
3595 ehea_bcmc_regs.arr[i].reg_type,
3596 ehea_bcmc_regs.arr[i].macaddr,
3597 0, H_DEREG_BCMC);
3598}
3599
Hannes Hering48cfb142008-05-07 14:43:36 +02003600static int ehea_mem_notifier(struct notifier_block *nb,
3601 unsigned long action, void *data)
3602{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003603 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003604 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003605
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003606 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003607
Hannes Hering48cfb142008-05-07 14:43:36 +02003608 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003609 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003610 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003611 /* Readd canceled memory block */
3612 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003613 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003614 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003615 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003616 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003617 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003618 break;
3619 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003620 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003621 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003622 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003623 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003624 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003625 break;
3626 default:
3627 break;
3628 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003629
3630 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003631 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003632
Thomas Kleina7c561f22010-04-20 23:11:31 +00003633out_unlock:
3634 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003635 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003636}
3637
3638static struct notifier_block ehea_mem_nb = {
3639 .notifier_call = ehea_mem_notifier,
3640};
3641
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003642static int ehea_reboot_notifier(struct notifier_block *nb,
3643 unsigned long action, void *unused)
3644{
3645 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003646 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003647 ibmebus_unregister_driver(&ehea_driver);
3648 }
3649 return NOTIFY_DONE;
3650}
3651
3652static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003653 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003654};
3655
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003656static int check_module_parm(void)
3657{
3658 int ret = 0;
3659
3660 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3661 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003662 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003663 ret = -EINVAL;
3664 }
3665 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3666 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003667 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003668 ret = -EINVAL;
3669 }
3670 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3671 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003672 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003673 ret = -EINVAL;
3674 }
3675 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3676 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003677 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003678 ret = -EINVAL;
3679 }
3680
3681 return ret;
3682}
3683
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003684static ssize_t ehea_show_capabilities(struct device_driver *drv,
3685 char *buf)
3686{
3687 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3688}
3689
3690static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3691 ehea_show_capabilities, NULL);
3692
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003693int __init ehea_module_init(void)
3694{
3695 int ret;
3696
Joe Perches8c4877a2010-12-13 10:05:14 -08003697 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003698
Thomas Klein21eee2d2008-02-13 16:18:33 +01003699 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3700 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3701
Daniel Walker9f71a562008-03-28 14:41:26 -07003702 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003703 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003704
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003705 ret = check_module_parm();
3706 if (ret)
3707 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003708
3709 ret = ehea_create_busmap();
3710 if (ret)
3711 goto out;
3712
Thomas Klein21eee2d2008-02-13 16:18:33 +01003713 ret = register_reboot_notifier(&ehea_reboot_nb);
3714 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003715 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003716
Hannes Hering48cfb142008-05-07 14:43:36 +02003717 ret = register_memory_notifier(&ehea_mem_nb);
3718 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003719 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003720
Joe Perchesc061b182010-08-23 18:20:03 +00003721 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003722 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003723 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003724
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003725 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003726 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003727 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003728 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003729 }
3730
3731 ret = driver_create_file(&ehea_driver.driver,
3732 &driver_attr_capabilities);
3733 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003734 pr_err("failed to register capabilities attribute, ret=%d\n",
3735 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003736 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003737 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003738
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 return ret;
3740
3741out3:
3742 ibmebus_unregister_driver(&ehea_driver);
3743out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003744 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003745 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003746 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003747out:
3748 return ret;
3749}
3750
3751static void __exit ehea_module_exit(void)
3752{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003753 int ret;
3754
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003755 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003756 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003757 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003758 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003759 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003760 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003761 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003762 kfree(ehea_fw_handles.arr);
3763 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003764 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003765}
3766
3767module_init(ehea_module_init);
3768module_exit(ehea_module_exit);