blob: a6c4192e12f4e8300c3eec487ac54de5e41e352d [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070066static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
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) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000097MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
98 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020099
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700100MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
101 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
102MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
103 "Default = 0");
104
Doug Maxey508d2b52008-01-31 20:20:49 -0600105static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200106static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800107static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700108static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100109struct ehea_fw_handle_array ehea_fw_handles;
110struct ehea_bcmc_reg_array ehea_bcmc_regs;
111
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Grant Likely2dc11582010-08-06 09:25:50 -0600113static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200114 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200115
Grant Likely2dc11582010-08-06 09:25:50 -0600116static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200117
118static struct of_device_id ehea_device_table[] = {
119 {
120 .name = "lhea",
121 .compatible = "IBM,lhea",
122 },
123 {},
124};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100125MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200126
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000127static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700128 .driver = {
129 .name = "ehea",
130 .owner = THIS_MODULE,
131 .of_match_table = ehea_device_table,
132 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200133 .probe = ehea_probe_adapter,
134 .remove = ehea_remove,
135};
136
Doug Maxey508d2b52008-01-31 20:20:49 -0600137void ehea_dump(void *adr, int len, char *msg)
138{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200139 int x;
140 unsigned char *deb = adr;
141 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800142 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
143 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200144 deb += 16;
145 }
146}
147
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100148void ehea_schedule_port_reset(struct ehea_port *port)
149{
150 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
151 schedule_work(&port->reset_task);
152}
153
Thomas Klein21eee2d2008-02-13 16:18:33 +0100154static void ehea_update_firmware_handles(void)
155{
156 struct ehea_fw_handle_entry *arr = NULL;
157 struct ehea_adapter *adapter;
158 int num_adapters = 0;
159 int num_ports = 0;
160 int num_portres = 0;
161 int i = 0;
162 int num_fw_handles, k, l;
163
164 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700165 mutex_lock(&ehea_fw_handles.lock);
166
Thomas Klein21eee2d2008-02-13 16:18:33 +0100167 list_for_each_entry(adapter, &adapter_list, list) {
168 num_adapters++;
169
170 for (k = 0; k < EHEA_MAX_PORTS; k++) {
171 struct ehea_port *port = adapter->port[k];
172
173 if (!port || (port->state != EHEA_PORT_UP))
174 continue;
175
176 num_ports++;
177 num_portres += port->num_def_qps + port->num_add_tx_qps;
178 }
179 }
180
181 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
182 num_ports * EHEA_NUM_PORT_FW_HANDLES +
183 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
184
185 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000186 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100187 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700188 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 } else
190 goto out_update;
191
192 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700193 if (num_adapters == 0)
194 break;
195
Thomas Klein21eee2d2008-02-13 16:18:33 +0100196 for (k = 0; k < EHEA_MAX_PORTS; k++) {
197 struct ehea_port *port = adapter->port[k];
198
Joe Perches8e95a202009-12-03 07:58:21 +0000199 if (!port || (port->state != EHEA_PORT_UP) ||
200 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100201 continue;
202
203 for (l = 0;
204 l < port->num_def_qps + port->num_add_tx_qps;
205 l++) {
206 struct ehea_port_res *pr = &port->port_res[l];
207
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = pr->qp->fw_handle;
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = pr->send_cq->fw_handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = pr->recv_cq->fw_handle;
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = pr->eq->fw_handle;
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = pr->send_mr.handle;
218 arr[i].adh = adapter->handle;
219 arr[i++].fwh = pr->recv_mr.handle;
220 }
221 arr[i].adh = adapter->handle;
222 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700223 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100224 }
225
226 arr[i].adh = adapter->handle;
227 arr[i++].fwh = adapter->neq->fw_handle;
228
229 if (adapter->mr.handle) {
230 arr[i].adh = adapter->handle;
231 arr[i++].fwh = adapter->mr.handle;
232 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700233 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100234 }
235
236out_update:
237 kfree(ehea_fw_handles.arr);
238 ehea_fw_handles.arr = arr;
239 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240out:
241 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242}
243
244static void ehea_update_bcmc_registrations(void)
245{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700246 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100247 struct ehea_bcmc_reg_entry *arr = NULL;
248 struct ehea_adapter *adapter;
249 struct ehea_mc_list *mc_entry;
250 int num_registrations = 0;
251 int i = 0;
252 int k;
253
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700254 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
255
Thomas Klein21eee2d2008-02-13 16:18:33 +0100256 /* Determine number of registrations */
257 list_for_each_entry(adapter, &adapter_list, list)
258 for (k = 0; k < EHEA_MAX_PORTS; k++) {
259 struct ehea_port *port = adapter->port[k];
260
261 if (!port || (port->state != EHEA_PORT_UP))
262 continue;
263
264 num_registrations += 2; /* Broadcast registrations */
265
266 list_for_each_entry(mc_entry, &port->mc_list->list,list)
267 num_registrations += 2;
268 }
269
270 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000271 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100272 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700273 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100274 } else
275 goto out_update;
276
277 list_for_each_entry(adapter, &adapter_list, list) {
278 for (k = 0; k < EHEA_MAX_PORTS; k++) {
279 struct ehea_port *port = adapter->port[k];
280
281 if (!port || (port->state != EHEA_PORT_UP))
282 continue;
283
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 if (num_registrations == 0)
285 goto out_update;
286
Thomas Klein21eee2d2008-02-13 16:18:33 +0100287 arr[i].adh = adapter->handle;
288 arr[i].port_id = port->logical_port_id;
289 arr[i].reg_type = EHEA_BCMC_BROADCAST |
290 EHEA_BCMC_UNTAGGED;
291 arr[i++].macaddr = port->mac_addr;
292
293 arr[i].adh = adapter->handle;
294 arr[i].port_id = port->logical_port_id;
295 arr[i].reg_type = EHEA_BCMC_BROADCAST |
296 EHEA_BCMC_VLANID_ALL;
297 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700298 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100299
300 list_for_each_entry(mc_entry,
301 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700302 if (num_registrations == 0)
303 goto out_update;
304
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 arr[i].adh = adapter->handle;
306 arr[i].port_id = port->logical_port_id;
307 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
308 EHEA_BCMC_MULTICAST |
309 EHEA_BCMC_UNTAGGED;
310 arr[i++].macaddr = mc_entry->macaddr;
311
312 arr[i].adh = adapter->handle;
313 arr[i].port_id = port->logical_port_id;
314 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
315 EHEA_BCMC_MULTICAST |
316 EHEA_BCMC_VLANID_ALL;
317 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700318 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100319 }
320 }
321 }
322
323out_update:
324 kfree(ehea_bcmc_regs.arr);
325 ehea_bcmc_regs.arr = arr;
326 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700327out:
328 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100329}
330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200331static struct net_device_stats *ehea_get_stats(struct net_device *dev)
332{
333 struct ehea_port *port = netdev_priv(dev);
334 struct net_device_stats *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000335 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 int i;
337
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000338 for (i = 0; i < port->num_def_qps; i++) {
339 rx_packets += port->port_res[i].rx_packets;
340 rx_bytes += port->port_res[i].rx_bytes;
341 }
342
343 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
344 tx_packets += port->port_res[i].tx_packets;
345 tx_bytes += port->port_res[i].tx_bytes;
346 }
347
348 stats->tx_packets = tx_packets;
349 stats->rx_bytes = rx_bytes;
350 stats->tx_bytes = tx_bytes;
351 stats->rx_packets = rx_packets;
352
353 return &port->stats;
354}
355
356static void ehea_update_stats(struct work_struct *work)
357{
358 struct ehea_port *port =
359 container_of(work, struct ehea_port, stats_work.work);
360 struct net_device *dev = port->netdev;
361 struct net_device_stats *stats = &port->stats;
362 struct hcp_ehea_port_cb2 *cb2;
363 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364
Brian King3d8009c2010-06-30 11:59:12 +0000365 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000367 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
368 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200369 }
370
371 hret = ehea_h_query_ehea_port(port->adapter->handle,
372 port->logical_port_id,
373 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
374 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800375 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200376 goto out_herr;
377 }
378
379 if (netif_msg_hw(port))
380 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
381
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200382 stats->multicast = cb2->rxmcp;
383 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200384
385out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800386 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000387resched:
388 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389}
390
391static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
392{
393 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
394 struct net_device *dev = pr->port->netdev;
395 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
397 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200398 int i;
399
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200400 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200402 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200403 if (nr_of_wqes > 0)
404 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 pr->rq1_skba.os_skbs = fill_wqes;
406 return;
407 }
408
409 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200410 if (!skb_arr_rq1[index]) {
411 skb_arr_rq1[index] = netdev_alloc_skb(dev,
412 EHEA_L_PKT_SIZE);
413 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800414 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200415 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416 break;
417 }
418 }
419 index--;
420 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200421 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200423
424 if (adder == 0)
425 return;
426
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200427 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200428 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429}
430
Thomas Kleine2878802009-01-21 14:45:57 -0800431static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200432{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
434 struct net_device *dev = pr->port->netdev;
435 int i;
436
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000437 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800438 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000439 return;
440 }
441
442 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200443 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000444 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800445 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800446 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000447 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200448 }
449 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000450 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451}
452
453static int ehea_refill_rq_def(struct ehea_port_res *pr,
454 struct ehea_q_skb_arr *q_skba, int rq_nr,
455 int num_wqes, int wqe_type, int packet_size)
456{
457 struct net_device *dev = pr->port->netdev;
458 struct ehea_qp *qp = pr->qp;
459 struct sk_buff **skb_arr = q_skba->arr;
460 struct ehea_rwqe *rwqe;
461 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463 int ret = 0;
464
465 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200466 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200467
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
469 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200471 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472
473 index = q_skba->index;
474 max_index_mask = q_skba->len - 1;
475 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200476 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000477 struct sk_buff *skb;
478
479 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200480 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800482 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800483 netdev_info(pr->port->netdev,
484 "rq%i ran dry - no mem for skb\n",
485 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800486 ret = -ENOMEM;
487 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200488 break;
489 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490
491 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 tmp_addr = ehea_map_vaddr(skb->data);
493 if (tmp_addr == -1) {
494 dev_kfree_skb(skb);
495 q_skba->os_skbs = fill_wqes - i;
496 ret = 0;
497 break;
498 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499
500 rwqe = ehea_get_next_rwqe(qp, rq_nr);
501 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200502 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200504 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200505 rwqe->sg_list[0].len = packet_size;
506 rwqe->data_segments = 1;
507
508 index++;
509 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511 }
Thomas Klein44c82152007-07-11 16:32:00 +0200512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200513 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200514 if (adder == 0)
515 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200516
517 /* Ring doorbell */
518 iosync();
519 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200520 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200522 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200523out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524 return ret;
525}
526
527
528static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
529{
530 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
531 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000532 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200533}
534
535
536static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
537{
538 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
539 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000540 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200541}
542
543static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
544{
545 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
546 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
547 return 0;
548 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
549 (cqe->header_length == 0))
550 return 0;
551 return -EINVAL;
552}
553
554static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000555 struct sk_buff *skb, struct ehea_cqe *cqe,
556 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200557{
558 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
559
560 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200561 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000562
563 /* The packet was not an IPV4 packet so a complemented checksum was
564 calculated. The value is found in the Internet Checksum field. */
565 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
566 skb->ip_summed = CHECKSUM_COMPLETE;
567 skb->csum = csum_unfold(~cqe->inet_checksum_value);
568 } else
569 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000570
571 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200572}
573
574static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
575 int arr_len,
576 struct ehea_cqe *cqe)
577{
578 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
579 struct sk_buff *skb;
580 void *pref;
581 int x;
582
583 x = skb_index + 1;
584 x &= (arr_len - 1);
585
586 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700587 if (pref) {
588 prefetchw(pref);
589 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200590
Hannes Hering0b2febf2009-05-04 11:06:37 -0700591 pref = (skb_array[x]->data);
592 prefetch(pref);
593 prefetch(pref + EHEA_CACHE_LINE);
594 prefetch(pref + EHEA_CACHE_LINE * 2);
595 prefetch(pref + EHEA_CACHE_LINE * 3);
596 }
597
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200598 skb = skb_array[skb_index];
599 skb_array[skb_index] = NULL;
600 return skb;
601}
602
603static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
604 int arr_len, int wqe_index)
605{
606 struct sk_buff *skb;
607 void *pref;
608 int x;
609
610 x = wqe_index + 1;
611 x &= (arr_len - 1);
612
613 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700614 if (pref) {
615 prefetchw(pref);
616 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200617
Hannes Hering0b2febf2009-05-04 11:06:37 -0700618 pref = (skb_array[x]->data);
619 prefetchw(pref);
620 prefetchw(pref + EHEA_CACHE_LINE);
621 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200622
623 skb = skb_array[wqe_index];
624 skb_array[wqe_index] = NULL;
625 return skb;
626}
627
628static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
629 struct ehea_cqe *cqe, int *processed_rq2,
630 int *processed_rq3)
631{
632 struct sk_buff *skb;
633
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100634 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
635 pr->p_stats.err_tcp_cksum++;
636 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
637 pr->p_stats.err_ip_cksum++;
638 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
639 pr->p_stats.err_frame_crc++;
640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200641 if (rq == 2) {
642 *processed_rq2 += 1;
643 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
644 dev_kfree_skb(skb);
645 } else if (rq == 3) {
646 *processed_rq3 += 1;
647 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
648 dev_kfree_skb(skb);
649 }
650
651 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100652 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800653 pr_err("Critical receive error for QP %d. Resetting port.\n",
654 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100655 ehea_dump(cqe, sizeof(*cqe), "CQE");
656 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100657 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200658 return 1;
659 }
660
661 return 0;
662}
663
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700664static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
665 void **tcph, u64 *hdr_flags, void *priv)
666{
667 struct ehea_cqe *cqe = priv;
668 unsigned int ip_len;
669 struct iphdr *iph;
670
671 /* non tcp/udp packets */
672 if (!cqe->header_length)
673 return -1;
674
675 /* non tcp packet */
676 skb_reset_network_header(skb);
677 iph = ip_hdr(skb);
678 if (iph->protocol != IPPROTO_TCP)
679 return -1;
680
681 ip_len = ip_hdrlen(skb);
682 skb_set_transport_header(skb, ip_len);
683 *tcph = tcp_hdr(skb);
684
685 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700686 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700687 return -1;
688
689 *hdr_flags = LRO_IPV4 | LRO_TCP;
690 *iphdr = iph;
691
692 return 0;
693}
694
695static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
696 struct sk_buff *skb)
697{
Jiri Pirkob4950092011-07-20 04:54:07 +0000698 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
699 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700700
Jiri Pirkob4950092011-07-20 04:54:07 +0000701 if (skb->dev->features & NETIF_F_LRO)
702 lro_receive_skb(&pr->lro_mgr, skb, cqe);
703 else
704 netif_receive_skb(skb);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700705}
706
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700707static int ehea_proc_rwqes(struct net_device *dev,
708 struct ehea_port_res *pr,
709 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100711 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712 struct ehea_qp *qp = pr->qp;
713 struct ehea_cqe *cqe;
714 struct sk_buff *skb;
715 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
716 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
717 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
718 int skb_arr_rq1_len = pr->rq1_skba.len;
719 int skb_arr_rq2_len = pr->rq2_skba.len;
720 int skb_arr_rq3_len = pr->rq3_skba.len;
721 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000722 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700723 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724
725 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
726 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200728 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700729 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200730 ehea_inc_rq1(qp);
731 processed_rq1++;
732 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200733 if (netif_msg_rx_status(port))
734 ehea_dump(cqe, sizeof(*cqe), "CQE");
735
736 last_wqe_index = wqe_index;
737 rmb();
738 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600739 if (rq == 1) {
740 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200741 skb = get_skb_by_index_ll(skb_arr_rq1,
742 skb_arr_rq1_len,
743 wqe_index);
744 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800745 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800746 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100747
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700748 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000750 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800751 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200752 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000753 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600755 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200756 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000757 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600758 } else if (rq == 2) {
759 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 skb = get_skb_by_index(skb_arr_rq2,
761 skb_arr_rq2_len, cqe);
762 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800763 netif_err(port, rx_err, dev,
764 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200765 break;
766 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000767 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200768 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600769 } else {
770 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200771 skb = get_skb_by_index(skb_arr_rq3,
772 skb_arr_rq3_len, cqe);
773 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800774 netif_err(port, rx_err, dev,
775 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200776 break;
777 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000778 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200779 processed_rq3++;
780 }
781
Breno Leitaoce45b872010-10-27 08:45:14 +0000782 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700783 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100784 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100785 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200786 port_reset = ehea_treat_poll_error(pr, rq, cqe,
787 &processed_rq2,
788 &processed_rq3);
789 if (port_reset)
790 break;
791 }
792 cqe = ehea_poll_rq1(qp, &wqe_index);
793 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800794 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700795 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200796
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200797 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000798 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200799
800 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
801 ehea_refill_rq2(pr, processed_rq2);
802 ehea_refill_rq3(pr, processed_rq3);
803
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700804 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200805}
806
Andre Detsch2928db42010-08-17 05:49:12 +0000807#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
808
809static void reset_sq_restart_flag(struct ehea_port *port)
810{
811 int i;
812
813 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
814 struct ehea_port_res *pr = &port->port_res[i];
815 pr->sq_restart_flag = 0;
816 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000817 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000818}
819
820static void check_sqs(struct ehea_port *port)
821{
822 struct ehea_swqe *swqe;
823 int swqe_index;
824 int i, k;
825
826 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
827 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000828 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000829 k = 0;
830 swqe = ehea_get_swqe(pr->qp, &swqe_index);
831 memset(swqe, 0, SWQE_HEADER_SIZE);
832 atomic_dec(&pr->swqe_avail);
833
834 swqe->tx_control |= EHEA_SWQE_PURGE;
835 swqe->wr_id = SWQE_RESTART_CHECK;
836 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
837 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
838 swqe->immediate_data_length = 80;
839
840 ehea_post_swqe(pr->qp, swqe);
841
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000842 ret = wait_event_timeout(port->restart_wq,
843 pr->sq_restart_flag == 0,
844 msecs_to_jiffies(100));
845
846 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800847 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000848 ehea_schedule_port_reset(pr->port);
849 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000850 }
851 }
Andre Detsch2928db42010-08-17 05:49:12 +0000852}
853
854
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100857 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200858 struct ehea_cq *send_cq = pr->send_cq;
859 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100860 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861 int cqe_counter = 0;
862 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100863 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000864 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
865 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200866
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100867 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600868 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100869 ehea_inc_cq(send_cq);
870
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200871 cqe_counter++;
872 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000873
874 if (cqe->wr_id == SWQE_RESTART_CHECK) {
875 pr->sq_restart_flag = 1;
876 swqe_av++;
877 break;
878 }
879
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200880 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800881 pr_err("Bad send completion status=0x%04X\n",
882 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000883
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200884 if (netif_msg_tx_err(pr->port))
885 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000886
887 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800888 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000889 ehea_schedule_port_reset(pr->port);
890 break;
891 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200892 }
893
894 if (netif_msg_tx_done(pr->port))
895 ehea_dump(cqe, sizeof(*cqe), "CQE");
896
897 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100898 == EHEA_SWQE2_TYPE)) {
899
900 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
901 skb = pr->sq_skba.arr[index];
902 dev_kfree_skb(skb);
903 pr->sq_skba.arr[index] = NULL;
904 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200905
906 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
907 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908
909 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700910 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911
912 ehea_update_feca(send_cq, cqe_counter);
913 atomic_add(swqe_av, &pr->swqe_avail);
914
Anton Blanchardb9564462011-10-14 05:30:59 +0000915 if (unlikely(netif_tx_queue_stopped(txq) &&
916 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
917 __netif_tx_lock(txq, smp_processor_id());
918 if (netif_tx_queue_stopped(txq) &&
919 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
920 netif_tx_wake_queue(txq);
921 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200922 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000923
Breno Leitao5b27d422010-10-05 13:16:22 +0000924 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200925
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100926 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200927}
928
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700932static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200933{
Doug Maxey508d2b52008-01-31 20:20:49 -0600934 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
935 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100937 struct ehea_cqe *cqe;
938 struct ehea_cqe *cqe_skb = NULL;
939 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700940 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100941
942 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700943 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100944
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700945 if (!force_irq)
946 rx += ehea_proc_rwqes(dev, pr, budget - rx);
947
948 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100949 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700950 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800951 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100952 ehea_reset_cq_ep(pr->recv_cq);
953 ehea_reset_cq_ep(pr->send_cq);
954 ehea_reset_cq_n1(pr->recv_cq);
955 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000956 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100957 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
958 cqe_skb = ehea_poll_cq(pr->send_cq);
959
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100960 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700961 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100962
Ben Hutchings288379f2009-01-19 16:43:59 -0800963 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 return rx;
965
966 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
967 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100968 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100969
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700970 pr->poll_counter++;
971 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200972}
973
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200974#ifdef CONFIG_NET_POLL_CONTROLLER
975static void ehea_netpoll(struct net_device *dev)
976{
977 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700978 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200979
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700980 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800981 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200982}
983#endif
984
David Howells7d12e782006-10-05 14:55:46 +0100985static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200986{
987 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100988
Ben Hutchings288379f2009-01-19 16:43:59 -0800989 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100990
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200991 return IRQ_HANDLED;
992}
993
David Howells7d12e782006-10-05 14:55:46 +0100994static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200995{
996 struct ehea_port *port = param;
997 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100998 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001000 u64 resource_type, aer, aerr;
1001 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001002
1003 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001004
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001005 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001006 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -08001007 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1008 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001009
1010 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001011
1012 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1013 &aer, &aerr);
1014
1015 if (resource_type == EHEA_AER_RESTYPE_QP) {
1016 if ((aer & EHEA_AER_RESET_MASK) ||
1017 (aerr & EHEA_AERR_RESET_MASK))
1018 reset_port = 1;
1019 } else
1020 reset_port = 1; /* Reset in case of CQ or EQ error */
1021
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001022 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001023 }
1024
Thomas Kleinea96cea2010-04-20 23:10:55 +00001025 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001026 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001027 ehea_schedule_port_reset(port);
1028 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001029
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001030 return IRQ_HANDLED;
1031}
1032
1033static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1034 int logical_port)
1035{
1036 int i;
1037
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001038 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001039 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001040 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001041 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001042 return NULL;
1043}
1044
1045int ehea_sense_port_attr(struct ehea_port *port)
1046{
1047 int ret;
1048 u64 hret;
1049 struct hcp_ehea_port_cb0 *cb0;
1050
Doug Maxey508d2b52008-01-31 20:20:49 -06001051 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001052 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001053 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001054 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001055 ret = -ENOMEM;
1056 goto out;
1057 }
1058
1059 hret = ehea_h_query_ehea_port(port->adapter->handle,
1060 port->logical_port_id, H_PORT_CB0,
1061 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1062 cb0);
1063 if (hret != H_SUCCESS) {
1064 ret = -EIO;
1065 goto out_free;
1066 }
1067
1068 /* MAC address */
1069 port->mac_addr = cb0->port_mac_addr << 16;
1070
Doug Maxey508d2b52008-01-31 20:20:49 -06001071 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001072 ret = -EADDRNOTAVAIL;
1073 goto out_free;
1074 }
1075
1076 /* Port speed */
1077 switch (cb0->port_speed) {
1078 case H_SPEED_10M_H:
1079 port->port_speed = EHEA_SPEED_10M;
1080 port->full_duplex = 0;
1081 break;
1082 case H_SPEED_10M_F:
1083 port->port_speed = EHEA_SPEED_10M;
1084 port->full_duplex = 1;
1085 break;
1086 case H_SPEED_100M_H:
1087 port->port_speed = EHEA_SPEED_100M;
1088 port->full_duplex = 0;
1089 break;
1090 case H_SPEED_100M_F:
1091 port->port_speed = EHEA_SPEED_100M;
1092 port->full_duplex = 1;
1093 break;
1094 case H_SPEED_1G_F:
1095 port->port_speed = EHEA_SPEED_1G;
1096 port->full_duplex = 1;
1097 break;
1098 case H_SPEED_10G_F:
1099 port->port_speed = EHEA_SPEED_10G;
1100 port->full_duplex = 1;
1101 break;
1102 default:
1103 port->port_speed = 0;
1104 port->full_duplex = 0;
1105 break;
1106 }
1107
Thomas Kleine919b592007-01-22 12:53:20 +01001108 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001109 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001110
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001111 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001112 if (use_mcs)
1113 port->num_def_qps = cb0->num_default_qps;
1114 else
1115 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001116
1117 if (!port->num_def_qps) {
1118 ret = -EINVAL;
1119 goto out_free;
1120 }
1121
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001122 port->num_tx_qps = num_tx_qps;
1123
1124 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001125 port->num_add_tx_qps = 0;
1126 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001127 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001128
1129 ret = 0;
1130out_free:
1131 if (ret || netif_msg_probe(port))
1132 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001133 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134out:
1135 return ret;
1136}
1137
1138int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1139{
1140 struct hcp_ehea_port_cb4 *cb4;
1141 u64 hret;
1142 int ret = 0;
1143
Thomas Klein3faf2692009-01-21 14:45:33 -08001144 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001145 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001146 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001147 ret = -ENOMEM;
1148 goto out;
1149 }
1150
1151 cb4->port_speed = port_speed;
1152
1153 netif_carrier_off(port->netdev);
1154
1155 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1156 port->logical_port_id,
1157 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1158 if (hret == H_SUCCESS) {
1159 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1160
1161 hret = ehea_h_query_ehea_port(port->adapter->handle,
1162 port->logical_port_id,
1163 H_PORT_CB4, H_PORT_CB4_SPEED,
1164 cb4);
1165 if (hret == H_SUCCESS) {
1166 switch (cb4->port_speed) {
1167 case H_SPEED_10M_H:
1168 port->port_speed = EHEA_SPEED_10M;
1169 port->full_duplex = 0;
1170 break;
1171 case H_SPEED_10M_F:
1172 port->port_speed = EHEA_SPEED_10M;
1173 port->full_duplex = 1;
1174 break;
1175 case H_SPEED_100M_H:
1176 port->port_speed = EHEA_SPEED_100M;
1177 port->full_duplex = 0;
1178 break;
1179 case H_SPEED_100M_F:
1180 port->port_speed = EHEA_SPEED_100M;
1181 port->full_duplex = 1;
1182 break;
1183 case H_SPEED_1G_F:
1184 port->port_speed = EHEA_SPEED_1G;
1185 port->full_duplex = 1;
1186 break;
1187 case H_SPEED_10G_F:
1188 port->port_speed = EHEA_SPEED_10G;
1189 port->full_duplex = 1;
1190 break;
1191 default:
1192 port->port_speed = 0;
1193 port->full_duplex = 0;
1194 break;
1195 }
1196 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001197 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001198 ret = -EIO;
1199 }
1200 } else {
1201 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001202 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001203 ret = -EPERM;
1204 } else {
1205 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001206 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207 }
1208 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001209 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1210 netif_carrier_on(port->netdev);
1211
Thomas Klein3faf2692009-01-21 14:45:33 -08001212 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001213out:
1214 return ret;
1215}
1216
1217static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1218{
1219 int ret;
1220 u8 ec;
1221 u8 portnum;
1222 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001223 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224
1225 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1226 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1227 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001228 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229
1230 switch (ec) {
1231 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1232
1233 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001234 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001235 break;
1236 }
1237
1238 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001239 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001240 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001242 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243 break;
1244 }
1245
Joe Perches8c4877a2010-12-13 10:05:14 -08001246 netif_info(port, link, dev,
1247 "Logical port up: %dMbps %s Duplex\n",
1248 port->port_speed,
1249 port->full_duplex == 1 ?
1250 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251
Joe Perches8c4877a2010-12-13 10:05:14 -08001252 netif_carrier_on(dev);
1253 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001254 }
1255 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001256 if (netif_carrier_ok(dev)) {
1257 netif_info(port, link, dev,
1258 "Logical port down\n");
1259 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001260 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 }
1262
1263 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001264 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001265 netif_info(port, link, dev,
1266 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001267 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001268 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001270 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001271 netif_info(port, link, dev,
1272 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001273 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001274 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001275 }
1276
1277 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001278 netdev_info(dev,
1279 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001280 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001281 netdev_info(dev,
1282 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283
1284 break;
1285 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001286 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 break;
1288 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001289 netdev_info(dev, "Port malfunction\n");
1290 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001291 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 break;
1293 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001294 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295 break;
1296 }
1297}
1298
1299static void ehea_neq_tasklet(unsigned long data)
1300{
Doug Maxey508d2b52008-01-31 20:20:49 -06001301 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001302 struct ehea_eqe *eqe;
1303 u64 event_mask;
1304
1305 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001306 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307
1308 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001309 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310 ehea_parse_eqe(adapter, eqe->entry);
1311 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001312 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001313 }
1314
1315 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1316 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1317 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1318
1319 ehea_h_reset_events(adapter->handle,
1320 adapter->neq->fw_handle, event_mask);
1321}
1322
David Howells7d12e782006-10-05 14:55:46 +01001323static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001324{
1325 struct ehea_adapter *adapter = param;
1326 tasklet_hi_schedule(&adapter->neq_tasklet);
1327 return IRQ_HANDLED;
1328}
1329
1330
1331static int ehea_fill_port_res(struct ehea_port_res *pr)
1332{
1333 int ret;
1334 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1335
Breno Leitaof76957f2011-01-11 07:45:57 +00001336 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337
Thomas Kleine2878802009-01-21 14:45:57 -08001338 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339
1340 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1341
1342 return ret;
1343}
1344
1345static int ehea_reg_interrupts(struct net_device *dev)
1346{
1347 struct ehea_port *port = netdev_priv(dev);
1348 struct ehea_port_res *pr;
1349 int i, ret;
1350
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001351
1352 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1353 dev->name);
1354
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001355 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001357 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001359 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1360 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361 goto out_free_qpeq;
1362 }
1363
Joe Perches8c4877a2010-12-13 10:05:14 -08001364 netif_info(port, ifup, dev,
1365 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1366 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001368
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1370 pr = &port->port_res[i];
1371 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001372 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001373 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001374 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001375 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376 pr);
1377 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001378 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1379 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001380 goto out_free_req;
1381 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001382 netif_info(port, ifup, dev,
1383 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1384 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001385 }
1386out:
1387 return ret;
1388
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390out_free_req:
1391 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001392 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001393 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001397 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001399
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001400 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001401
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001402}
1403
1404static void ehea_free_interrupts(struct net_device *dev)
1405{
1406 struct ehea_port *port = netdev_priv(dev);
1407 struct ehea_port_res *pr;
1408 int i;
1409
1410 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001411
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1413 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001414 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001415 netif_info(port, intr, dev,
1416 "free send irq for res %d with handle 0x%X\n",
1417 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418 }
1419
1420 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001421 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001422 netif_info(port, intr, dev,
1423 "associated event interrupt for handle 0x%X freed\n",
1424 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001425}
1426
1427static int ehea_configure_port(struct ehea_port *port)
1428{
1429 int ret, i;
1430 u64 hret, mask;
1431 struct hcp_ehea_port_cb0 *cb0;
1432
1433 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001434 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001435 if (!cb0)
1436 goto out;
1437
1438 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1440 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1441 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1442 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1443 PXLY_RC_VLAN_FILTER)
1444 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1445
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001446 for (i = 0; i < port->num_mcs; i++)
1447 if (use_mcs)
1448 cb0->default_qpn_arr[i] =
1449 port->port_res[i].qp->init_attr.qp_nr;
1450 else
1451 cb0->default_qpn_arr[i] =
1452 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001453
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001454 if (netif_msg_ifup(port))
1455 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1456
1457 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1458 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1459
1460 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1461 port->logical_port_id,
1462 H_PORT_CB0, mask, cb0);
1463 ret = -EIO;
1464 if (hret != H_SUCCESS)
1465 goto out_free;
1466
1467 ret = 0;
1468
1469out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001470 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001471out:
1472 return ret;
1473}
1474
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001475int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001477 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478 struct ehea_adapter *adapter = pr->port->adapter;
1479
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001480 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1481 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001482 goto out;
1483
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001484 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1485 if (ret)
1486 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487
1488 return 0;
1489
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001490out_free:
1491 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001493 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001494 return -EIO;
1495}
1496
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001497int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498{
Joe Perches8e95a202009-12-03 07:58:21 +00001499 if ((ehea_rem_mr(&pr->send_mr)) ||
1500 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001501 return -EIO;
1502 else
1503 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001504}
1505
1506static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1507{
Doug Maxey508d2b52008-01-31 20:20:49 -06001508 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001510 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511 if (!q_skba->arr)
1512 return -ENOMEM;
1513
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001514 q_skba->len = max_q_entries;
1515 q_skba->index = 0;
1516 q_skba->os_skbs = 0;
1517
1518 return 0;
1519}
1520
1521static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1522 struct port_res_cfg *pr_cfg, int queue_token)
1523{
1524 struct ehea_adapter *adapter = port->adapter;
1525 enum ehea_eq_type eq_type = EHEA_EQ;
1526 struct ehea_qp_init_attr *init_attr = NULL;
1527 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001528 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1529
1530 tx_bytes = pr->tx_bytes;
1531 tx_packets = pr->tx_packets;
1532 rx_bytes = pr->rx_bytes;
1533 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001534
1535 memset(pr, 0, sizeof(struct ehea_port_res));
1536
Breno Leitaoce45b872010-10-27 08:45:14 +00001537 pr->tx_bytes = rx_bytes;
1538 pr->tx_packets = tx_packets;
1539 pr->rx_bytes = rx_bytes;
1540 pr->rx_packets = rx_packets;
1541
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001542 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001544 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1545 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001546 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 goto out_free;
1548 }
1549
1550 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001551 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001552 port->logical_port_id);
1553 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001554 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 goto out_free;
1556 }
1557
1558 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001559 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001560 port->logical_port_id);
1561 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001562 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 goto out_free;
1564 }
1565
1566 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001567 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1568 pr->send_cq->attr.act_nr_of_cqes,
1569 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570
1571 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1572 if (!init_attr) {
1573 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001574 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001575 goto out_free;
1576 }
1577
1578 init_attr->low_lat_rq1 = 1;
1579 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1580 init_attr->rq_count = 3;
1581 init_attr->qp_token = queue_token;
1582 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1583 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1584 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1585 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1586 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1587 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1588 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1589 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1590 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1591 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1592 init_attr->port_nr = port->logical_port_id;
1593 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1594 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1595 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1596
1597 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1598 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001599 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600 ret = -EIO;
1601 goto out_free;
1602 }
1603
1604 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001605 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",
1606 init_attr->qp_nr,
1607 init_attr->act_nr_send_wqes,
1608 init_attr->act_nr_rwqes_rq1,
1609 init_attr->act_nr_rwqes_rq2,
1610 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001611
Thomas Klein44fb3122008-04-04 15:04:53 +02001612 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1613
1614 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001615 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1616 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1617 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1618 if (ret)
1619 goto out_free;
1620
1621 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1622 if (ehea_gen_smrs(pr) != 0) {
1623 ret = -EIO;
1624 goto out_free;
1625 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001626
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1628
1629 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001630
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001631 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001632
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001633 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1634 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1635 pr->lro_mgr.lro_arr = pr->lro_desc;
1636 pr->lro_mgr.get_skb_header = get_skb_hdr;
1637 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1638 pr->lro_mgr.dev = port->netdev;
1639 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1640 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001642 ret = 0;
1643 goto out;
1644
1645out_free:
1646 kfree(init_attr);
1647 vfree(pr->sq_skba.arr);
1648 vfree(pr->rq1_skba.arr);
1649 vfree(pr->rq2_skba.arr);
1650 vfree(pr->rq3_skba.arr);
1651 ehea_destroy_qp(pr->qp);
1652 ehea_destroy_cq(pr->send_cq);
1653 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001654 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655out:
1656 return ret;
1657}
1658
1659static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1660{
1661 int ret, i;
1662
Hannes Hering357eb462009-08-04 11:48:39 -07001663 if (pr->qp)
1664 netif_napi_del(&pr->napi);
1665
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001666 ret = ehea_destroy_qp(pr->qp);
1667
1668 if (!ret) {
1669 ehea_destroy_cq(pr->send_cq);
1670 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001671 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001672
1673 for (i = 0; i < pr->rq1_skba.len; i++)
1674 if (pr->rq1_skba.arr[i])
1675 dev_kfree_skb(pr->rq1_skba.arr[i]);
1676
1677 for (i = 0; i < pr->rq2_skba.len; i++)
1678 if (pr->rq2_skba.arr[i])
1679 dev_kfree_skb(pr->rq2_skba.arr[i]);
1680
1681 for (i = 0; i < pr->rq3_skba.len; i++)
1682 if (pr->rq3_skba.arr[i])
1683 dev_kfree_skb(pr->rq3_skba.arr[i]);
1684
1685 for (i = 0; i < pr->sq_skba.len; i++)
1686 if (pr->sq_skba.arr[i])
1687 dev_kfree_skb(pr->sq_skba.arr[i]);
1688
1689 vfree(pr->rq1_skba.arr);
1690 vfree(pr->rq2_skba.arr);
1691 vfree(pr->rq3_skba.arr);
1692 vfree(pr->sq_skba.arr);
1693 ret = ehea_rem_smrs(pr);
1694 }
1695 return ret;
1696}
1697
1698/*
1699 * The write_* functions store information in swqe which is used by
1700 * the hardware to calculate the ip/tcp/udp checksum
1701 */
1702
1703static inline void write_ip_start_end(struct ehea_swqe *swqe,
1704 const struct sk_buff *skb)
1705{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001706 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001707 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708}
1709
1710static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1711 const struct sk_buff *skb)
1712{
1713 swqe->tcp_offset =
1714 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1715
1716 swqe->tcp_end = (u16)skb->len - 1;
1717}
1718
1719static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1720 const struct sk_buff *skb)
1721{
1722 swqe->tcp_offset =
1723 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1724
1725 swqe->tcp_end = (u16)skb->len - 1;
1726}
1727
1728
1729static void write_swqe2_TSO(struct sk_buff *skb,
1730 struct ehea_swqe *swqe, u32 lkey)
1731{
1732 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1733 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001734 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001736
1737 /* Packet is TCP with TSO enabled */
1738 swqe->tx_control |= EHEA_SWQE_TSO;
1739 swqe->mss = skb_shinfo(skb)->gso_size;
1740 /* copy only eth/ip/tcp headers to immediate data and
1741 * the rest of skb->data to sg1entry
1742 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001743 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744
Eric Dumazete743d312010-04-14 15:59:40 -07001745 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746
1747 if (skb_data_size >= headersize) {
1748 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001749 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 swqe->immediate_data_length = headersize;
1751
1752 if (skb_data_size > headersize) {
1753 /* set sg1entry data */
1754 sg1entry->l_key = lkey;
1755 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001756 sg1entry->vaddr =
1757 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001758 swqe->descriptors++;
1759 }
1760 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001761 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001762}
1763
1764static void write_swqe2_nonTSO(struct sk_buff *skb,
1765 struct ehea_swqe *swqe, u32 lkey)
1766{
Eric Dumazete743d312010-04-14 15:59:40 -07001767 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1769 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 /* Packet is any nonTSO type
1772 *
1773 * Copy as much as possible skb->data to immediate data and
1774 * the rest to sg1entry
1775 */
1776 if (skb_data_size >= SWQE2_MAX_IMM) {
1777 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001778 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779
1780 swqe->immediate_data_length = SWQE2_MAX_IMM;
1781
1782 if (skb_data_size > SWQE2_MAX_IMM) {
1783 /* copy sg1entry data */
1784 sg1entry->l_key = lkey;
1785 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001786 sg1entry->vaddr =
1787 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788 swqe->descriptors++;
1789 }
1790 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001791 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792 swqe->immediate_data_length = skb_data_size;
1793 }
1794}
1795
1796static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1797 struct ehea_swqe *swqe, u32 lkey)
1798{
1799 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1800 skb_frag_t *frag;
1801 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001802
1803 nfrags = skb_shinfo(skb)->nr_frags;
1804 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001805 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001806 swqe->descriptors = 0;
1807 sg1entry_contains_frag_data = 0;
1808
1809 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1810 write_swqe2_TSO(skb, swqe, lkey);
1811 else
1812 write_swqe2_nonTSO(skb, swqe, lkey);
1813
1814 /* write descriptors */
1815 if (nfrags > 0) {
1816 if (swqe->descriptors == 0) {
1817 /* sg1entry not yet used */
1818 frag = &skb_shinfo(skb)->frags[0];
1819
1820 /* copy sg1entry data */
1821 sg1entry->l_key = lkey;
1822 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001823 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001824 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001825 swqe->descriptors++;
1826 sg1entry_contains_frag_data = 1;
1827 }
1828
1829 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1830
1831 frag = &skb_shinfo(skb)->frags[i];
1832 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1833
1834 sgentry->l_key = lkey;
1835 sgentry->len = frag->size;
Ian Campbell618c4a02011-10-10 01:11:38 +00001836 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001837 swqe->descriptors++;
1838 }
1839 }
1840}
1841
1842static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1843{
1844 int ret = 0;
1845 u64 hret;
1846 u8 reg_type;
1847
1848 /* De/Register untagged packets */
1849 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1850 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1851 port->logical_port_id,
1852 reg_type, port->mac_addr, 0, hcallid);
1853 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001854 pr_err("%sregistering bc address failed (tagged)\n",
1855 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001856 ret = -EIO;
1857 goto out_herr;
1858 }
1859
1860 /* De/Register VLAN packets */
1861 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1862 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1863 port->logical_port_id,
1864 reg_type, port->mac_addr, 0, hcallid);
1865 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001866 pr_err("%sregistering bc address failed (vlan)\n",
1867 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001868 ret = -EIO;
1869 }
1870out_herr:
1871 return ret;
1872}
1873
1874static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1875{
1876 struct ehea_port *port = netdev_priv(dev);
1877 struct sockaddr *mac_addr = sa;
1878 struct hcp_ehea_port_cb0 *cb0;
1879 int ret;
1880 u64 hret;
1881
1882 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1883 ret = -EADDRNOTAVAIL;
1884 goto out;
1885 }
1886
Thomas Klein3faf2692009-01-21 14:45:33 -08001887 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001888 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001889 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001890 ret = -ENOMEM;
1891 goto out;
1892 }
1893
1894 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1895
1896 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1897
1898 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1899 port->logical_port_id, H_PORT_CB0,
1900 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1901 if (hret != H_SUCCESS) {
1902 ret = -EIO;
1903 goto out_free;
1904 }
1905
1906 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1907
1908 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001909 if (port->state == EHEA_PORT_UP) {
1910 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1911 if (ret)
1912 goto out_upregs;
1913 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914
1915 port->mac_addr = cb0->port_mac_addr << 16;
1916
1917 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001918 if (port->state == EHEA_PORT_UP) {
1919 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1920 if (ret)
1921 goto out_upregs;
1922 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001923
1924 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001925
1926out_upregs:
1927 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001928out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001929 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001930out:
1931 return ret;
1932}
1933
1934static void ehea_promiscuous_error(u64 hret, int enable)
1935{
Thomas Klein7674a582007-01-22 12:54:20 +01001936 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001937 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1938 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001939 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001940 pr_err("failed %sabling promiscuous mode\n",
1941 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942}
1943
1944static void ehea_promiscuous(struct net_device *dev, int enable)
1945{
1946 struct ehea_port *port = netdev_priv(dev);
1947 struct hcp_ehea_port_cb7 *cb7;
1948 u64 hret;
1949
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001950 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951 return;
1952
Thomas Klein3faf2692009-01-21 14:45:33 -08001953 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001954 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001955 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001956 goto out;
1957 }
1958
1959 /* Modify Pxs_DUCQPN in CB7 */
1960 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1961
1962 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1963 port->logical_port_id,
1964 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1965 if (hret) {
1966 ehea_promiscuous_error(hret, enable);
1967 goto out;
1968 }
1969
1970 port->promisc = enable;
1971out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001972 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001973}
1974
1975static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1976 u32 hcallid)
1977{
1978 u64 hret;
1979 u8 reg_type;
1980
1981 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1982 | EHEA_BCMC_UNTAGGED;
1983
1984 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1985 port->logical_port_id,
1986 reg_type, mc_mac_addr, 0, hcallid);
1987 if (hret)
1988 goto out;
1989
1990 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1991 | EHEA_BCMC_VLANID_ALL;
1992
1993 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1994 port->logical_port_id,
1995 reg_type, mc_mac_addr, 0, hcallid);
1996out:
1997 return hret;
1998}
1999
2000static int ehea_drop_multicast_list(struct net_device *dev)
2001{
2002 struct ehea_port *port = netdev_priv(dev);
2003 struct ehea_mc_list *mc_entry = port->mc_list;
2004 struct list_head *pos;
2005 struct list_head *temp;
2006 int ret = 0;
2007 u64 hret;
2008
2009 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2010 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2011
2012 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2013 H_DEREG_BCMC);
2014 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002015 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002016 ret = -EIO;
2017 }
2018
2019 list_del(pos);
2020 kfree(mc_entry);
2021 }
2022 return ret;
2023}
2024
2025static void ehea_allmulti(struct net_device *dev, int enable)
2026{
2027 struct ehea_port *port = netdev_priv(dev);
2028 u64 hret;
2029
2030 if (!port->allmulti) {
2031 if (enable) {
2032 /* Enable ALLMULTI */
2033 ehea_drop_multicast_list(dev);
2034 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2035 if (!hret)
2036 port->allmulti = 1;
2037 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002038 netdev_err(dev,
2039 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002040 }
2041 } else
2042 if (!enable) {
2043 /* Disable ALLMULTI */
2044 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2045 if (!hret)
2046 port->allmulti = 0;
2047 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002048 netdev_err(dev,
2049 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002050 }
2051}
2052
Doug Maxey508d2b52008-01-31 20:20:49 -06002053static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054{
2055 struct ehea_mc_list *ehea_mcl_entry;
2056 u64 hret;
2057
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002058 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002059 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002060 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002061 return;
2062 }
2063
2064 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2065
2066 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2067
2068 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2069 H_REG_BCMC);
2070 if (!hret)
2071 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2072 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002073 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002074 kfree(ehea_mcl_entry);
2075 }
2076}
2077
2078static void ehea_set_multicast_list(struct net_device *dev)
2079{
2080 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002081 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002082 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002083
Breno Leitaoa4910b72011-05-23 03:36:35 +00002084 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002085 ehea_promiscuous(dev, 1);
2086 return;
2087 }
2088 ehea_promiscuous(dev, 0);
2089
2090 if (dev->flags & IFF_ALLMULTI) {
2091 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002092 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002093 }
2094 ehea_allmulti(dev, 0);
2095
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002096 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002097 ret = ehea_drop_multicast_list(dev);
2098 if (ret) {
2099 /* Dropping the current multicast list failed.
2100 * Enabling ALL_MULTI is the best we can do.
2101 */
2102 ehea_allmulti(dev, 1);
2103 }
2104
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002105 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002106 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2107 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 goto out;
2109 }
2110
Jiri Pirko22bedad32010-04-01 21:22:57 +00002111 netdev_for_each_mc_addr(ha, dev)
2112 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002113
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002114 }
2115out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002116 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117}
2118
2119static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2120{
2121 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2122 return -EINVAL;
2123 dev->mtu = new_mtu;
2124 return 0;
2125}
2126
2127static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2128 struct ehea_swqe *swqe, u32 lkey)
2129{
2130 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002131 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002132
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002133 /* IPv4 */
2134 swqe->tx_control |= EHEA_SWQE_CRC
2135 | EHEA_SWQE_IP_CHECKSUM
2136 | EHEA_SWQE_TCP_CHECKSUM
2137 | EHEA_SWQE_IMM_DATA_PRESENT
2138 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2139
2140 write_ip_start_end(swqe, skb);
2141
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002142 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002143 if ((iph->frag_off & IP_MF) ||
2144 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002145 /* IP fragment, so don't change cs */
2146 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2147 else
2148 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002149 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002150 write_tcp_offset_end(swqe, skb);
2151 }
2152
2153 /* icmp (big data) and ip segmentation packets (all other ip
2154 packets) do not require any special handling */
2155
2156 } else {
2157 /* Other Ethernet Protocol */
2158 swqe->tx_control |= EHEA_SWQE_CRC
2159 | EHEA_SWQE_IMM_DATA_PRESENT
2160 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2161 }
2162
2163 write_swqe2_data(skb, dev, swqe, lkey);
2164}
2165
2166static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2167 struct ehea_swqe *swqe)
2168{
2169 int nfrags = skb_shinfo(skb)->nr_frags;
2170 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2171 skb_frag_t *frag;
2172 int i;
2173
2174 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002175 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002176
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002177 /* IPv4 */
2178 write_ip_start_end(swqe, skb);
2179
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002180 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002181 swqe->tx_control |= EHEA_SWQE_CRC
2182 | EHEA_SWQE_IP_CHECKSUM
2183 | EHEA_SWQE_TCP_CHECKSUM
2184 | EHEA_SWQE_IMM_DATA_PRESENT;
2185
2186 write_tcp_offset_end(swqe, skb);
2187
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002188 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002189 if ((iph->frag_off & IP_MF) ||
2190 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002191 /* IP fragment, so don't change cs */
2192 swqe->tx_control |= EHEA_SWQE_CRC
2193 | EHEA_SWQE_IMM_DATA_PRESENT;
2194 else {
2195 swqe->tx_control |= EHEA_SWQE_CRC
2196 | EHEA_SWQE_IP_CHECKSUM
2197 | EHEA_SWQE_TCP_CHECKSUM
2198 | EHEA_SWQE_IMM_DATA_PRESENT;
2199
2200 write_udp_offset_end(swqe, skb);
2201 }
2202 } else {
2203 /* icmp (big data) and
2204 ip segmentation packets (all other ip packets) */
2205 swqe->tx_control |= EHEA_SWQE_CRC
2206 | EHEA_SWQE_IP_CHECKSUM
2207 | EHEA_SWQE_IMM_DATA_PRESENT;
2208 }
2209 } else {
2210 /* Other Ethernet Protocol */
2211 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2212 }
2213 /* copy (immediate) data */
2214 if (nfrags == 0) {
2215 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002216 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002217 } else {
2218 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002219 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002220 skb_headlen(skb));
2221 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002222
2223 /* ... then copy data from the fragments */
2224 for (i = 0; i < nfrags; i++) {
2225 frag = &skb_shinfo(skb)->frags[i];
Ian Campbell618c4a02011-10-10 01:11:38 +00002226 memcpy(imm_data, skb_frag_address(frag), frag->size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227 imm_data += frag->size;
2228 }
2229 }
2230 swqe->immediate_data_length = skb->len;
2231 dev_kfree_skb(skb);
2232}
2233
2234static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2235{
2236 struct ehea_port *port = netdev_priv(dev);
2237 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002238 u32 lkey;
2239 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002240 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002241 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002242
Anton Blanchardb9564462011-10-14 05:30:59 +00002243 pr = &port->port_res[skb_get_queue_mapping(skb)];
2244 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002245
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002246 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2247 memset(swqe, 0, SWQE_HEADER_SIZE);
2248 atomic_dec(&pr->swqe_avail);
2249
Eric Dumazete5ccd962010-10-26 19:21:07 +00002250 if (vlan_tx_tag_present(skb)) {
2251 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2252 swqe->vlan_tag = vlan_tx_tag_get(skb);
2253 }
2254
Breno Leitaoce45b872010-10-27 08:45:14 +00002255 pr->tx_packets++;
2256 pr->tx_bytes += skb->len;
2257
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002258 if (skb->len <= SWQE3_MAX_IMM) {
2259 u32 sig_iv = port->sig_comp_iv;
2260 u32 swqe_num = pr->swqe_id_counter;
2261 ehea_xmit3(skb, dev, swqe);
2262 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2263 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2264 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2265 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2266 sig_iv);
2267 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2268 pr->swqe_ll_count = 0;
2269 } else
2270 pr->swqe_ll_count += 1;
2271 } else {
2272 swqe->wr_id =
2273 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2274 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002275 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002276 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2277 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2278
2279 pr->sq_skba.index++;
2280 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2281
2282 lkey = pr->send_mr.lkey;
2283 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002284 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 }
2286 pr->swqe_id_counter += 1;
2287
Joe Perches8c4877a2010-12-13 10:05:14 -08002288 netif_info(port, tx_queued, dev,
2289 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2290 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002291 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002292
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002293 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002294 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002295 swqe->tx_control |= EHEA_SWQE_PURGE;
2296 }
Thomas Klein44c82152007-07-11 16:32:00 +02002297
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299
2300 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002301 pr->p_stats.queue_stopped++;
2302 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002304
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002305 return NETDEV_TX_OK;
2306}
2307
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002308static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2309{
2310 struct ehea_port *port = netdev_priv(dev);
2311 struct ehea_adapter *adapter = port->adapter;
2312 struct hcp_ehea_port_cb1 *cb1;
2313 int index;
2314 u64 hret;
2315
Thomas Klein3faf2692009-01-21 14:45:33 -08002316 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002317 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002318 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319 goto out;
2320 }
2321
2322 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2323 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2324 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002325 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 goto out;
2327 }
2328
2329 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002330 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331
2332 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2333 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2334 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002335 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002336out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002337 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002338 return;
2339}
2340
2341static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2342{
2343 struct ehea_port *port = netdev_priv(dev);
2344 struct ehea_adapter *adapter = port->adapter;
2345 struct hcp_ehea_port_cb1 *cb1;
2346 int index;
2347 u64 hret;
2348
Thomas Klein3faf2692009-01-21 14:45:33 -08002349 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002350 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002351 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002352 goto out;
2353 }
2354
2355 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2356 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2357 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002358 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359 goto out;
2360 }
2361
2362 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002363 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364
2365 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2366 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2367 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002368 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002370 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371}
2372
2373int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2374{
2375 int ret = -EIO;
2376 u64 hret;
2377 u16 dummy16 = 0;
2378 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002379 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380
Thomas Klein3faf2692009-01-21 14:45:33 -08002381 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382 if (!cb0) {
2383 ret = -ENOMEM;
2384 goto out;
2385 }
2386
2387 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2388 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2389 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002390 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002391 goto out;
2392 }
2393
2394 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2395 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2396 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2397 &dummy64, &dummy64, &dummy16, &dummy16);
2398 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002399 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002400 goto out;
2401 }
2402
2403 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2404 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2405 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002406 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002407 goto out;
2408 }
2409
2410 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2411 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2412 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2413 &dummy64, &dummy64, &dummy16, &dummy16);
2414 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002415 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002416 goto out;
2417 }
2418
2419 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2420 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2421 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002422 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002423 goto out;
2424 }
2425
2426 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2427 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2428 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2429 &dummy64, &dummy64, &dummy16, &dummy16);
2430 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002431 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432 goto out;
2433 }
2434
2435 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2436 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2437 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002438 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002439 goto out;
2440 }
2441
2442 ret = 0;
2443out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002444 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002445 return ret;
2446}
2447
2448static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2449 int add_tx_qps)
2450{
2451 int ret, i;
2452 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2453 enum ehea_eq_type eq_type = EHEA_EQ;
2454
2455 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2456 EHEA_MAX_ENTRIES_EQ, 1);
2457 if (!port->qp_eq) {
2458 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002459 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002460 goto out_kill_eq;
2461 }
2462
2463 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002464 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002465 pr_cfg.max_entries_sq = sq_entries;
2466 pr_cfg.max_entries_rq1 = rq1_entries;
2467 pr_cfg.max_entries_rq2 = rq2_entries;
2468 pr_cfg.max_entries_rq3 = rq3_entries;
2469
2470 pr_cfg_small_rx.max_entries_rcq = 1;
2471 pr_cfg_small_rx.max_entries_scq = sq_entries;
2472 pr_cfg_small_rx.max_entries_sq = sq_entries;
2473 pr_cfg_small_rx.max_entries_rq1 = 1;
2474 pr_cfg_small_rx.max_entries_rq2 = 1;
2475 pr_cfg_small_rx.max_entries_rq3 = 1;
2476
2477 for (i = 0; i < def_qps; i++) {
2478 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2479 if (ret)
2480 goto out_clean_pr;
2481 }
2482 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2483 ret = ehea_init_port_res(port, &port->port_res[i],
2484 &pr_cfg_small_rx, i);
2485 if (ret)
2486 goto out_clean_pr;
2487 }
2488
2489 return 0;
2490
2491out_clean_pr:
2492 while (--i >= 0)
2493 ehea_clean_portres(port, &port->port_res[i]);
2494
2495out_kill_eq:
2496 ehea_destroy_eq(port->qp_eq);
2497 return ret;
2498}
2499
2500static int ehea_clean_all_portres(struct ehea_port *port)
2501{
2502 int ret = 0;
2503 int i;
2504
Doug Maxey508d2b52008-01-31 20:20:49 -06002505 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002506 ret |= ehea_clean_portres(port, &port->port_res[i]);
2507
2508 ret |= ehea_destroy_eq(port->qp_eq);
2509
2510 return ret;
2511}
2512
Thomas Klein35cf2e22007-08-06 13:55:14 +02002513static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002514{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002515 if (adapter->active_ports)
2516 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002517
2518 ehea_rem_mr(&adapter->mr);
2519}
2520
Thomas Klein35cf2e22007-08-06 13:55:14 +02002521static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002522{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002523 if (adapter->active_ports)
2524 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002525
2526 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2527}
2528
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529static int ehea_up(struct net_device *dev)
2530{
2531 int ret, i;
2532 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002533
2534 if (port->state == EHEA_PORT_UP)
2535 return 0;
2536
2537 ret = ehea_port_res_setup(port, port->num_def_qps,
2538 port->num_add_tx_qps);
2539 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002540 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002541 goto out;
2542 }
2543
2544 /* Set default QP for this port */
2545 ret = ehea_configure_port(port);
2546 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002547 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002548 goto out_clean_pr;
2549 }
2550
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002551 ret = ehea_reg_interrupts(dev);
2552 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002553 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002554 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002555 }
2556
Doug Maxey508d2b52008-01-31 20:20:49 -06002557 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2559 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002560 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002561 goto out_free_irqs;
2562 }
2563 }
2564
Doug Maxey508d2b52008-01-31 20:20:49 -06002565 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002566 ret = ehea_fill_port_res(&port->port_res[i]);
2567 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002568 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569 goto out_free_irqs;
2570 }
2571 }
2572
Thomas Klein21eee2d2008-02-13 16:18:33 +01002573 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2574 if (ret) {
2575 ret = -EIO;
2576 goto out_free_irqs;
2577 }
2578
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002579 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002580
2581 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002582 goto out;
2583
2584out_free_irqs:
2585 ehea_free_interrupts(dev);
2586
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002587out_clean_pr:
2588 ehea_clean_all_portres(port);
2589out:
Thomas Klein44c82152007-07-11 16:32:00 +02002590 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002591 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002592
Thomas Klein21eee2d2008-02-13 16:18:33 +01002593 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002594 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002595
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002596 return ret;
2597}
2598
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002599static void port_napi_disable(struct ehea_port *port)
2600{
2601 int i;
2602
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002603 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002604 napi_disable(&port->port_res[i].napi);
2605}
2606
2607static void port_napi_enable(struct ehea_port *port)
2608{
2609 int i;
2610
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002611 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002612 napi_enable(&port->port_res[i].napi);
2613}
2614
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002615static int ehea_open(struct net_device *dev)
2616{
2617 int ret;
2618 struct ehea_port *port = netdev_priv(dev);
2619
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002620 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002621
Joe Perches8c4877a2010-12-13 10:05:14 -08002622 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623
2624 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002625 if (!ret) {
2626 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002627 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002628 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002629
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002630 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002631 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002632
2633 return ret;
2634}
2635
2636static int ehea_down(struct net_device *dev)
2637{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002638 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002639 struct ehea_port *port = netdev_priv(dev);
2640
2641 if (port->state == EHEA_PORT_DOWN)
2642 return 0;
2643
2644 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002645 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2646
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002647 ehea_free_interrupts(dev);
2648
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002649 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002650
Thomas Klein21eee2d2008-02-13 16:18:33 +01002651 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002652
Thomas Klein44c82152007-07-11 16:32:00 +02002653 ret = ehea_clean_all_portres(port);
2654 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002655 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002656
Thomas Klein21eee2d2008-02-13 16:18:33 +01002657 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002658
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002659 return ret;
2660}
2661
2662static int ehea_stop(struct net_device *dev)
2663{
2664 int ret;
2665 struct ehea_port *port = netdev_priv(dev);
2666
Joe Perches8c4877a2010-12-13 10:05:14 -08002667 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002668
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002669 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002670 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002671 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002672 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002673 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002674 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002675 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002676 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002677 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002678 return ret;
2679}
2680
Andrew Morton22559c52008-04-18 13:50:39 -07002681static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002682{
2683 struct ehea_qp qp = *orig_qp;
2684 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2685 struct ehea_swqe *swqe;
2686 int wqe_index;
2687 int i;
2688
2689 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2690 swqe = ehea_get_swqe(&qp, &wqe_index);
2691 swqe->tx_control |= EHEA_SWQE_PURGE;
2692 }
2693}
2694
Andrew Morton22559c52008-04-18 13:50:39 -07002695static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002696{
2697 int i;
2698
2699 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2700 struct ehea_port_res *pr = &port->port_res[i];
2701 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002702 int ret;
2703
2704 ret = wait_event_timeout(port->swqe_avail_wq,
2705 atomic_read(&pr->swqe_avail) >= swqe_max,
2706 msecs_to_jiffies(100));
2707
2708 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002709 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002710 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002711 }
2712 }
2713}
2714
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002715int ehea_stop_qps(struct net_device *dev)
2716{
2717 struct ehea_port *port = netdev_priv(dev);
2718 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002719 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002720 int ret = -EIO;
2721 int dret;
2722 int i;
2723 u64 hret;
2724 u64 dummy64 = 0;
2725 u16 dummy16 = 0;
2726
Thomas Klein3faf2692009-01-21 14:45:33 -08002727 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002728 if (!cb0) {
2729 ret = -ENOMEM;
2730 goto out;
2731 }
2732
2733 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2734 struct ehea_port_res *pr = &port->port_res[i];
2735 struct ehea_qp *qp = pr->qp;
2736
2737 /* Purge send queue */
2738 ehea_purge_sq(qp);
2739
2740 /* Disable queue pair */
2741 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2742 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2743 cb0);
2744 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002745 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002746 goto out;
2747 }
2748
2749 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2750 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2751
2752 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2753 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2754 1), cb0, &dummy64,
2755 &dummy64, &dummy16, &dummy16);
2756 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002757 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002758 goto out;
2759 }
2760
2761 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2762 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2763 cb0);
2764 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002765 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002766 goto out;
2767 }
2768
2769 /* deregister shared memory regions */
2770 dret = ehea_rem_smrs(pr);
2771 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002772 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002773 goto out;
2774 }
2775 }
2776
2777 ret = 0;
2778out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002779 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002780
2781 return ret;
2782}
2783
Doug Maxey508d2b52008-01-31 20:20:49 -06002784void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002785{
2786 struct ehea_qp qp = *orig_qp;
2787 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2788 struct ehea_rwqe *rwqe;
2789 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2790 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2791 struct sk_buff *skb;
2792 u32 lkey = pr->recv_mr.lkey;
2793
2794
2795 int i;
2796 int index;
2797
2798 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2799 rwqe = ehea_get_next_rwqe(&qp, 2);
2800 rwqe->sg_list[0].l_key = lkey;
2801 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2802 skb = skba_rq2[index];
2803 if (skb)
2804 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2805 }
2806
2807 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2808 rwqe = ehea_get_next_rwqe(&qp, 3);
2809 rwqe->sg_list[0].l_key = lkey;
2810 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2811 skb = skba_rq3[index];
2812 if (skb)
2813 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2814 }
2815}
2816
2817int ehea_restart_qps(struct net_device *dev)
2818{
2819 struct ehea_port *port = netdev_priv(dev);
2820 struct ehea_adapter *adapter = port->adapter;
2821 int ret = 0;
2822 int i;
2823
Doug Maxey508d2b52008-01-31 20:20:49 -06002824 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002825 u64 hret;
2826 u64 dummy64 = 0;
2827 u16 dummy16 = 0;
2828
Thomas Klein3faf2692009-01-21 14:45:33 -08002829 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002830 if (!cb0) {
2831 ret = -ENOMEM;
2832 goto out;
2833 }
2834
2835 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2836 struct ehea_port_res *pr = &port->port_res[i];
2837 struct ehea_qp *qp = pr->qp;
2838
2839 ret = ehea_gen_smrs(pr);
2840 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002841 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002842 goto out;
2843 }
2844
2845 ehea_update_rqs(qp, pr);
2846
2847 /* Enable queue pair */
2848 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2849 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2850 cb0);
2851 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002852 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002853 goto out;
2854 }
2855
2856 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2857 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2858
2859 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2860 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2861 1), cb0, &dummy64,
2862 &dummy64, &dummy16, &dummy16);
2863 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002864 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002865 goto out;
2866 }
2867
2868 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2869 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2870 cb0);
2871 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002872 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002873 goto out;
2874 }
2875
2876 /* refill entire queue */
2877 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2878 ehea_refill_rq2(pr, 0);
2879 ehea_refill_rq3(pr, 0);
2880 }
2881out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002882 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002883
2884 return ret;
2885}
2886
David Howellsc4028952006-11-22 14:57:56 +00002887static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002888{
2889 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002890 struct ehea_port *port =
2891 container_of(work, struct ehea_port, reset_task);
2892 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002893
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002894 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002895 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002896 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002897 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002898
2899 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002900
Thomas Klein44c82152007-07-11 16:32:00 +02002901 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002902
2903 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002904 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002905 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002906
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002907 ehea_set_multicast_list(dev);
2908
Joe Perches8c4877a2010-12-13 10:05:14 -08002909 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002910
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002911 port_napi_enable(port);
2912
Anton Blanchardb9564462011-10-14 05:30:59 +00002913 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002914out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002915 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002916 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002917}
2918
Tejun Heo3d6b8922010-12-12 16:45:14 +01002919static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002920{
2921 int ret, i;
2922 struct ehea_adapter *adapter;
2923
Joe Perches8c4877a2010-12-13 10:05:14 -08002924 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002925
2926 list_for_each_entry(adapter, &adapter_list, list)
2927 if (adapter->active_ports) {
2928 /* Shutdown all ports */
2929 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2930 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002931 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002932
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002933 if (!port)
2934 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002935
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002936 dev = port->netdev;
2937
2938 if (dev->flags & IFF_UP) {
2939 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002940 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002941 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002942 ret = ehea_stop_qps(dev);
2943 if (ret) {
2944 mutex_unlock(&port->port_lock);
2945 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002946 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002947 port_napi_disable(port);
2948 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002949 }
Andre Detsch2928db42010-08-17 05:49:12 +00002950 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002951 }
2952
2953 /* Unregister old memory region */
2954 ret = ehea_rem_mr(&adapter->mr);
2955 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002956 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002957 goto out;
2958 }
2959 }
2960
Thomas Klein44c82152007-07-11 16:32:00 +02002961 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2962
2963 list_for_each_entry(adapter, &adapter_list, list)
2964 if (adapter->active_ports) {
2965 /* Register new memory region */
2966 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2967 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002968 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002969 goto out;
2970 }
2971
2972 /* Restart all ports */
2973 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2974 struct ehea_port *port = adapter->port[i];
2975
2976 if (port) {
2977 struct net_device *dev = port->netdev;
2978
2979 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002980 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002981 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002982 if (!ret) {
2983 check_sqs(port);
2984 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002985 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002986 } else {
2987 netdev_err(dev, "Unable to restart QPS\n");
2988 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002989 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002990 }
2991 }
2992 }
2993 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002994 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002995out:
2996 return;
2997}
2998
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999static void ehea_tx_watchdog(struct net_device *dev)
3000{
3001 struct ehea_port *port = netdev_priv(dev);
3002
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003003 if (netif_carrier_ok(dev) &&
3004 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003005 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003006}
3007
3008int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3009{
3010 struct hcp_query_ehea *cb;
3011 u64 hret;
3012 int ret;
3013
Thomas Klein3faf2692009-01-21 14:45:33 -08003014 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003015 if (!cb) {
3016 ret = -ENOMEM;
3017 goto out;
3018 }
3019
3020 hret = ehea_h_query_ehea(adapter->handle, cb);
3021
3022 if (hret != H_SUCCESS) {
3023 ret = -EIO;
3024 goto out_herr;
3025 }
3026
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003027 adapter->max_mc_mac = cb->max_mc_mac - 1;
3028 ret = 0;
3029
3030out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003031 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003032out:
3033 return ret;
3034}
3035
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003036int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3037{
3038 struct hcp_ehea_port_cb4 *cb4;
3039 u64 hret;
3040 int ret = 0;
3041
3042 *jumbo = 0;
3043
3044 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003045 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003046 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003047 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003048 ret = -ENOMEM;
3049 goto out;
3050 } else {
3051 hret = ehea_h_query_ehea_port(port->adapter->handle,
3052 port->logical_port_id,
3053 H_PORT_CB4,
3054 H_PORT_CB4_JUMBO, cb4);
3055 if (hret == H_SUCCESS) {
3056 if (cb4->jumbo_frame)
3057 *jumbo = 1;
3058 else {
3059 cb4->jumbo_frame = 1;
3060 hret = ehea_h_modify_ehea_port(port->adapter->
3061 handle,
3062 port->
3063 logical_port_id,
3064 H_PORT_CB4,
3065 H_PORT_CB4_JUMBO,
3066 cb4);
3067 if (hret == H_SUCCESS)
3068 *jumbo = 1;
3069 }
3070 } else
3071 ret = -EINVAL;
3072
Thomas Klein3faf2692009-01-21 14:45:33 -08003073 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003074 }
3075out:
3076 return ret;
3077}
3078
3079static ssize_t ehea_show_port_id(struct device *dev,
3080 struct device_attribute *attr, char *buf)
3081{
3082 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003083 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003084}
3085
3086static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3087 NULL);
3088
3089static void __devinit logical_port_release(struct device *dev)
3090{
3091 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003092 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003093}
3094
3095static struct device *ehea_register_port(struct ehea_port *port,
3096 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003097{
3098 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003099
Grant Likely61c7a082010-04-13 16:12:29 -07003100 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003101 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003102 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003104 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 port->ofdev.dev.release = logical_port_release;
3106
3107 ret = of_device_register(&port->ofdev);
3108 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003109 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 goto out;
3111 }
3112
3113 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003114 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003115 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116 goto out_unreg_of_dev;
3117 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003118
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003119 return &port->ofdev.dev;
3120
3121out_unreg_of_dev:
3122 of_device_unregister(&port->ofdev);
3123out:
3124 return NULL;
3125}
3126
3127static void ehea_unregister_port(struct ehea_port *port)
3128{
3129 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3130 of_device_unregister(&port->ofdev);
3131}
3132
Thomas Klein086c1b22009-01-21 14:43:59 -08003133static const struct net_device_ops ehea_netdev_ops = {
3134 .ndo_open = ehea_open,
3135 .ndo_stop = ehea_stop,
3136 .ndo_start_xmit = ehea_start_xmit,
3137#ifdef CONFIG_NET_POLL_CONTROLLER
3138 .ndo_poll_controller = ehea_netpoll,
3139#endif
3140 .ndo_get_stats = ehea_get_stats,
3141 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c102d2009-07-09 17:54:35 +00003142 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003143 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003144 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003145 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003146 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3147 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003148};
3149
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3151 u32 logical_port_id,
3152 struct device_node *dn)
3153{
3154 int ret;
3155 struct net_device *dev;
3156 struct ehea_port *port;
3157 struct device *port_dev;
3158 int jumbo;
3159
3160 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00003161 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162
3163 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003164 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 ret = -ENOMEM;
3166 goto out_err;
3167 }
3168
3169 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003170
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003171 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003172 port->state = EHEA_PORT_DOWN;
3173 port->sig_comp_iv = sq_entries / 10;
3174
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003175 port->adapter = adapter;
3176 port->netdev = dev;
3177 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003178
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003179 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003180
3181 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3182 if (!port->mc_list) {
3183 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003185 }
3186
3187 INIT_LIST_HEAD(&port->mc_list->list);
3188
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003189 ret = ehea_sense_port_attr(port);
3190 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003191 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003192
Anton Blanchardb9564462011-10-14 05:30:59 +00003193 netif_set_real_num_rx_queues(dev, port->num_def_qps);
3194 netif_set_real_num_tx_queues(dev, port->num_def_qps +
3195 port->num_add_tx_qps);
3196
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003197 port_dev = ehea_register_port(port, dn);
3198 if (!port_dev)
3199 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003200
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003202
3203 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003204 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3205
Thomas Klein086c1b22009-01-21 14:43:59 -08003206 dev->netdev_ops = &ehea_netdev_ops;
3207 ehea_set_ethtool_ops(dev);
3208
Michał Mirosławf4786a92011-04-17 00:15:47 +00003209 dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3210 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003211 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003212 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003213 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003214 | NETIF_F_RXCSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003215 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3216
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003217 if (use_lro)
3218 dev->features |= NETIF_F_LRO;
3219
David Howellsc4028952006-11-22 14:57:56 +00003220 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003221 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003222
Anton Blanchard21ccc792011-05-10 16:17:10 +00003223 init_waitqueue_head(&port->swqe_avail_wq);
3224 init_waitqueue_head(&port->restart_wq);
3225
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003226 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003227 ret = register_netdev(dev);
3228 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003229 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003230 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003231 }
3232
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003233 port->lro_max_aggr = lro_max_aggr;
3234
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003235 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003236 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003237 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003238
Joe Perches8c4877a2010-12-13 10:05:14 -08003239 netdev_info(dev, "Jumbo frames are %sabled\n",
3240 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003241
Thomas Klein44c82152007-07-11 16:32:00 +02003242 adapter->active_ports++;
3243
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246out_unreg_port:
3247 ehea_unregister_port(port);
3248
3249out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251
3252out_free_ethdev:
3253 free_netdev(dev);
3254
3255out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003256 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3257 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258 return NULL;
3259}
3260
3261static void ehea_shutdown_single_port(struct ehea_port *port)
3262{
Brian King7fb1c2a2008-05-14 09:48:25 -05003263 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003264
3265 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003266 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003267 unregister_netdev(port->netdev);
3268 ehea_unregister_port(port);
3269 kfree(port->mc_list);
3270 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003271 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003272}
3273
3274static int ehea_setup_ports(struct ehea_adapter *adapter)
3275{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003276 struct device_node *lhea_dn;
3277 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003278
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003279 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003280 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003281
Grant Likely61c7a082010-04-13 16:12:29 -07003282 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003283 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003284
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003285 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003286 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003288 pr_err("bad device node: eth_dn name=%s\n",
3289 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003291 }
3292
Thomas Klein1211bb62007-04-26 11:56:43 +02003293 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003294 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003295 of_node_put(eth_dn);
3296 return -EIO;
3297 }
3298
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003299 adapter->port[i] = ehea_setup_single_port(adapter,
3300 *dn_log_port_id,
3301 eth_dn);
3302 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003303 netdev_info(adapter->port[i]->netdev,
3304 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003305 else
3306 ehea_remove_adapter_mr(adapter);
3307
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003308 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003309 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003310 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003311}
3312
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003313static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3314 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003315{
3316 struct device_node *lhea_dn;
3317 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003318 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003319
Grant Likely61c7a082010-04-13 16:12:29 -07003320 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003321 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003322
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003323 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003324 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325 if (dn_log_port_id)
3326 if (*dn_log_port_id == logical_port_id)
3327 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003328 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329
3330 return NULL;
3331}
3332
3333static ssize_t ehea_probe_port(struct device *dev,
3334 struct device_attribute *attr,
3335 const char *buf, size_t count)
3336{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003337 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003338 struct ehea_port *port;
3339 struct device_node *eth_dn = NULL;
3340 int i;
3341
3342 u32 logical_port_id;
3343
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003344 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003345
3346 port = ehea_get_port(adapter, logical_port_id);
3347
3348 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003349 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3350 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351 return -EINVAL;
3352 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003353
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003354 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3355
3356 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003357 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358 return -EINVAL;
3359 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003360
Thomas Klein1211bb62007-04-26 11:56:43 +02003361 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003362 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003363 return -EIO;
3364 }
3365
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003366 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3367
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003368 of_node_put(eth_dn);
3369
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003371 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372 if (!adapter->port[i]) {
3373 adapter->port[i] = port;
3374 break;
3375 }
3376
Joe Perches8c4877a2010-12-13 10:05:14 -08003377 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3378 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003379 } else {
3380 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003381 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003382 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003383
3384 return (ssize_t) count;
3385}
3386
3387static ssize_t ehea_remove_port(struct device *dev,
3388 struct device_attribute *attr,
3389 const char *buf, size_t count)
3390{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003391 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003392 struct ehea_port *port;
3393 int i;
3394 u32 logical_port_id;
3395
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003396 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397
3398 port = ehea_get_port(adapter, logical_port_id);
3399
3400 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003401 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3402 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003403
3404 ehea_shutdown_single_port(port);
3405
Doug Maxey508d2b52008-01-31 20:20:49 -06003406 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003407 if (adapter->port[i] == port) {
3408 adapter->port[i] = NULL;
3409 break;
3410 }
3411 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003412 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3413 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003414 return -EINVAL;
3415 }
3416
Thomas Klein1211bb62007-04-26 11:56:43 +02003417 ehea_remove_adapter_mr(adapter);
3418
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003419 return (ssize_t) count;
3420}
3421
3422static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3423static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3424
Grant Likely2dc11582010-08-06 09:25:50 -06003425int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003426{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003427 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003428 if (ret)
3429 goto out;
3430
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003431 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003432out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003433 return ret;
3434}
3435
Grant Likely2dc11582010-08-06 09:25:50 -06003436void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003437{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003438 device_remove_file(&dev->dev, &dev_attr_probe_port);
3439 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003440}
3441
Grant Likely2dc11582010-08-06 09:25:50 -06003442static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003443 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003444{
3445 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003446 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447 int ret;
3448
Grant Likely61c7a082010-04-13 16:12:29 -07003449 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003450 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003451 return -EINVAL;
3452 }
3453
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003454 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3455 if (!adapter) {
3456 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003457 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458 goto out;
3459 }
3460
Thomas Klein44c82152007-07-11 16:32:00 +02003461 list_add(&adapter->list, &adapter_list);
3462
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003463 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003464
Grant Likely61c7a082010-04-13 16:12:29 -07003465 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003466 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003467 if (adapter_handle)
3468 adapter->handle = *adapter_handle;
3469
3470 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003471 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003472 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 ret = -ENODEV;
3474 goto out_free_ad;
3475 }
3476
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003477 adapter->pd = EHEA_PD_ID;
3478
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003479 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003481
3482 /* initialize adapter and ports */
3483 /* get adapter properties */
3484 ret = ehea_sense_adapter_attr(adapter);
3485 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003486 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003487 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003489
3490 adapter->neq = ehea_create_eq(adapter,
3491 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3492 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003493 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003494 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003495 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496 }
3497
3498 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3499 (unsigned long)adapter);
3500
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003501 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003502 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503 "ehea_neq", adapter);
3504 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003505 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 goto out_kill_eq;
3507 }
3508
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003509 ret = ehea_create_device_sysfs(dev);
3510 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003511 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003513 ret = ehea_setup_ports(adapter);
3514 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003515 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003516 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 }
3518
3519 ret = 0;
3520 goto out;
3521
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003522out_rem_dev_sysfs:
3523 ehea_remove_device_sysfs(dev);
3524
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003525out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003526 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527
3528out_kill_eq:
3529 ehea_destroy_eq(adapter->neq);
3530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003532 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003533 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003536 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003537
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003538 return ret;
3539}
3540
Grant Likely2dc11582010-08-06 09:25:50 -06003541static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003542{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003543 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003544 int i;
3545
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003546 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 if (adapter->port[i]) {
3548 ehea_shutdown_single_port(adapter->port[i]);
3549 adapter->port[i] = NULL;
3550 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003551
3552 ehea_remove_device_sysfs(dev);
3553
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003554 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003555 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003556
3557 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003558 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003559 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003560 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003561
Thomas Klein21eee2d2008-02-13 16:18:33 +01003562 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003564 return 0;
3565}
3566
Thomas Klein21eee2d2008-02-13 16:18:33 +01003567void ehea_crash_handler(void)
3568{
3569 int i;
3570
3571 if (ehea_fw_handles.arr)
3572 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3573 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3574 ehea_fw_handles.arr[i].fwh,
3575 FORCE_FREE);
3576
3577 if (ehea_bcmc_regs.arr)
3578 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3579 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3580 ehea_bcmc_regs.arr[i].port_id,
3581 ehea_bcmc_regs.arr[i].reg_type,
3582 ehea_bcmc_regs.arr[i].macaddr,
3583 0, H_DEREG_BCMC);
3584}
3585
Hannes Hering48cfb142008-05-07 14:43:36 +02003586static int ehea_mem_notifier(struct notifier_block *nb,
3587 unsigned long action, void *data)
3588{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003589 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003590 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003591
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003592 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003593
Hannes Hering48cfb142008-05-07 14:43:36 +02003594 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003595 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003596 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003597 /* Readd canceled memory block */
3598 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003599 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003600 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003601 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003602 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003603 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003604 break;
3605 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003606 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003607 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003608 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003609 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003610 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003611 break;
3612 default:
3613 break;
3614 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003615
3616 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003617 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003618
Thomas Kleina7c561f22010-04-20 23:11:31 +00003619out_unlock:
3620 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003621 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003622}
3623
3624static struct notifier_block ehea_mem_nb = {
3625 .notifier_call = ehea_mem_notifier,
3626};
3627
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003628static int ehea_reboot_notifier(struct notifier_block *nb,
3629 unsigned long action, void *unused)
3630{
3631 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003632 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003633 ibmebus_unregister_driver(&ehea_driver);
3634 }
3635 return NOTIFY_DONE;
3636}
3637
3638static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003639 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003640};
3641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003642static int check_module_parm(void)
3643{
3644 int ret = 0;
3645
3646 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3647 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003648 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003649 ret = -EINVAL;
3650 }
3651 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3652 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003653 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003654 ret = -EINVAL;
3655 }
3656 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3657 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003658 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003659 ret = -EINVAL;
3660 }
3661 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3662 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003663 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003664 ret = -EINVAL;
3665 }
3666
3667 return ret;
3668}
3669
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003670static ssize_t ehea_show_capabilities(struct device_driver *drv,
3671 char *buf)
3672{
3673 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3674}
3675
3676static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3677 ehea_show_capabilities, NULL);
3678
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003679int __init ehea_module_init(void)
3680{
3681 int ret;
3682
Joe Perches8c4877a2010-12-13 10:05:14 -08003683 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003684
Thomas Klein21eee2d2008-02-13 16:18:33 +01003685 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3686 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3687
Daniel Walker9f71a562008-03-28 14:41:26 -07003688 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003689 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003690
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003691 ret = check_module_parm();
3692 if (ret)
3693 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003694
3695 ret = ehea_create_busmap();
3696 if (ret)
3697 goto out;
3698
Thomas Klein21eee2d2008-02-13 16:18:33 +01003699 ret = register_reboot_notifier(&ehea_reboot_nb);
3700 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003701 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003702
Hannes Hering48cfb142008-05-07 14:43:36 +02003703 ret = register_memory_notifier(&ehea_mem_nb);
3704 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003705 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003706
Joe Perchesc061b182010-08-23 18:20:03 +00003707 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003708 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003709 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003710
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003711 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003712 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003713 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003714 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003715 }
3716
3717 ret = driver_create_file(&ehea_driver.driver,
3718 &driver_attr_capabilities);
3719 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003720 pr_err("failed to register capabilities attribute, ret=%d\n",
3721 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003722 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003723 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003724
Thomas Klein21eee2d2008-02-13 16:18:33 +01003725 return ret;
3726
3727out3:
3728 ibmebus_unregister_driver(&ehea_driver);
3729out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003730 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003731 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003732 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003733out:
3734 return ret;
3735}
3736
3737static void __exit ehea_module_exit(void)
3738{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 int ret;
3740
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003741 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003742 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003743 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003744 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003745 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003746 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003747 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003748 kfree(ehea_fw_handles.arr);
3749 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003750 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003751}
3752
3753module_init(ehea_module_init);
3754module_exit(ehea_module_exit);