blob: 4032a0a6b92978e252508df1e26620c0c859f0da [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
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100930
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700931static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200932{
Doug Maxey508d2b52008-01-31 20:20:49 -0600933 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
934 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700935 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100936 struct ehea_cqe *cqe;
937 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000938 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700939 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100940
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700941 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000942 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100943
Anton Blanchard222ca962011-10-14 05:31:00 +0000944 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800945 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946 ehea_reset_cq_ep(pr->recv_cq);
947 ehea_reset_cq_ep(pr->send_cq);
948 ehea_reset_cq_n1(pr->recv_cq);
949 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000950 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100951 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
952 cqe_skb = ehea_poll_cq(pr->send_cq);
953
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100954 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700955 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100956
Ben Hutchings288379f2009-01-19 16:43:59 -0800957 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700958 return rx;
959
960 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
961 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100962 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100963
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200965}
966
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200967#ifdef CONFIG_NET_POLL_CONTROLLER
968static void ehea_netpoll(struct net_device *dev)
969{
970 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700971 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200972
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700973 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800974 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200975}
976#endif
977
David Howells7d12e782006-10-05 14:55:46 +0100978static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979{
980 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100981
Ben Hutchings288379f2009-01-19 16:43:59 -0800982 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100983
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200984 return IRQ_HANDLED;
985}
986
David Howells7d12e782006-10-05 14:55:46 +0100987static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988{
989 struct ehea_port *port = param;
990 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100991 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000993 u64 resource_type, aer, aerr;
994 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200995
996 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100997
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -08001000 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1001 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001002
1003 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001004
1005 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1006 &aer, &aerr);
1007
1008 if (resource_type == EHEA_AER_RESTYPE_QP) {
1009 if ((aer & EHEA_AER_RESET_MASK) ||
1010 (aerr & EHEA_AERR_RESET_MASK))
1011 reset_port = 1;
1012 } else
1013 reset_port = 1; /* Reset in case of CQ or EQ error */
1014
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001015 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001016 }
1017
Thomas Kleinea96cea2010-04-20 23:10:55 +00001018 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001019 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001020 ehea_schedule_port_reset(port);
1021 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001022
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001023 return IRQ_HANDLED;
1024}
1025
1026static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1027 int logical_port)
1028{
1029 int i;
1030
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001031 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001032 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001033 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001034 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001035 return NULL;
1036}
1037
1038int ehea_sense_port_attr(struct ehea_port *port)
1039{
1040 int ret;
1041 u64 hret;
1042 struct hcp_ehea_port_cb0 *cb0;
1043
Doug Maxey508d2b52008-01-31 20:20:49 -06001044 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001045 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001046 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001047 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001048 ret = -ENOMEM;
1049 goto out;
1050 }
1051
1052 hret = ehea_h_query_ehea_port(port->adapter->handle,
1053 port->logical_port_id, H_PORT_CB0,
1054 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1055 cb0);
1056 if (hret != H_SUCCESS) {
1057 ret = -EIO;
1058 goto out_free;
1059 }
1060
1061 /* MAC address */
1062 port->mac_addr = cb0->port_mac_addr << 16;
1063
Doug Maxey508d2b52008-01-31 20:20:49 -06001064 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001065 ret = -EADDRNOTAVAIL;
1066 goto out_free;
1067 }
1068
1069 /* Port speed */
1070 switch (cb0->port_speed) {
1071 case H_SPEED_10M_H:
1072 port->port_speed = EHEA_SPEED_10M;
1073 port->full_duplex = 0;
1074 break;
1075 case H_SPEED_10M_F:
1076 port->port_speed = EHEA_SPEED_10M;
1077 port->full_duplex = 1;
1078 break;
1079 case H_SPEED_100M_H:
1080 port->port_speed = EHEA_SPEED_100M;
1081 port->full_duplex = 0;
1082 break;
1083 case H_SPEED_100M_F:
1084 port->port_speed = EHEA_SPEED_100M;
1085 port->full_duplex = 1;
1086 break;
1087 case H_SPEED_1G_F:
1088 port->port_speed = EHEA_SPEED_1G;
1089 port->full_duplex = 1;
1090 break;
1091 case H_SPEED_10G_F:
1092 port->port_speed = EHEA_SPEED_10G;
1093 port->full_duplex = 1;
1094 break;
1095 default:
1096 port->port_speed = 0;
1097 port->full_duplex = 0;
1098 break;
1099 }
1100
Thomas Kleine919b592007-01-22 12:53:20 +01001101 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001102 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001103
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001104 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001105 if (use_mcs)
1106 port->num_def_qps = cb0->num_default_qps;
1107 else
1108 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001109
1110 if (!port->num_def_qps) {
1111 ret = -EINVAL;
1112 goto out_free;
1113 }
1114
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001115 port->num_tx_qps = num_tx_qps;
1116
1117 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001118 port->num_add_tx_qps = 0;
1119 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001120 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001121
1122 ret = 0;
1123out_free:
1124 if (ret || netif_msg_probe(port))
1125 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001126 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001127out:
1128 return ret;
1129}
1130
1131int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1132{
1133 struct hcp_ehea_port_cb4 *cb4;
1134 u64 hret;
1135 int ret = 0;
1136
Thomas Klein3faf2692009-01-21 14:45:33 -08001137 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001138 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001139 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001140 ret = -ENOMEM;
1141 goto out;
1142 }
1143
1144 cb4->port_speed = port_speed;
1145
1146 netif_carrier_off(port->netdev);
1147
1148 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1149 port->logical_port_id,
1150 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1151 if (hret == H_SUCCESS) {
1152 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1153
1154 hret = ehea_h_query_ehea_port(port->adapter->handle,
1155 port->logical_port_id,
1156 H_PORT_CB4, H_PORT_CB4_SPEED,
1157 cb4);
1158 if (hret == H_SUCCESS) {
1159 switch (cb4->port_speed) {
1160 case H_SPEED_10M_H:
1161 port->port_speed = EHEA_SPEED_10M;
1162 port->full_duplex = 0;
1163 break;
1164 case H_SPEED_10M_F:
1165 port->port_speed = EHEA_SPEED_10M;
1166 port->full_duplex = 1;
1167 break;
1168 case H_SPEED_100M_H:
1169 port->port_speed = EHEA_SPEED_100M;
1170 port->full_duplex = 0;
1171 break;
1172 case H_SPEED_100M_F:
1173 port->port_speed = EHEA_SPEED_100M;
1174 port->full_duplex = 1;
1175 break;
1176 case H_SPEED_1G_F:
1177 port->port_speed = EHEA_SPEED_1G;
1178 port->full_duplex = 1;
1179 break;
1180 case H_SPEED_10G_F:
1181 port->port_speed = EHEA_SPEED_10G;
1182 port->full_duplex = 1;
1183 break;
1184 default:
1185 port->port_speed = 0;
1186 port->full_duplex = 0;
1187 break;
1188 }
1189 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001190 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001191 ret = -EIO;
1192 }
1193 } else {
1194 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001195 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001196 ret = -EPERM;
1197 } else {
1198 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001199 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200 }
1201 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001202 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1203 netif_carrier_on(port->netdev);
1204
Thomas Klein3faf2692009-01-21 14:45:33 -08001205 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001206out:
1207 return ret;
1208}
1209
1210static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1211{
1212 int ret;
1213 u8 ec;
1214 u8 portnum;
1215 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001216 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001217
1218 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1219 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1220 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001221 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222
1223 switch (ec) {
1224 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1225
1226 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001227 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001228 break;
1229 }
1230
1231 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001232 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001233 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001235 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236 break;
1237 }
1238
Joe Perches8c4877a2010-12-13 10:05:14 -08001239 netif_info(port, link, dev,
1240 "Logical port up: %dMbps %s Duplex\n",
1241 port->port_speed,
1242 port->full_duplex == 1 ?
1243 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244
Joe Perches8c4877a2010-12-13 10:05:14 -08001245 netif_carrier_on(dev);
1246 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 }
1248 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001249 if (netif_carrier_ok(dev)) {
1250 netif_info(port, link, dev,
1251 "Logical port down\n");
1252 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001253 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001254 }
1255
1256 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001257 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001258 netif_info(port, link, dev,
1259 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001260 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001261 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001262 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001263 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001264 netif_info(port, link, dev,
1265 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001266 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001267 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268 }
1269
1270 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001271 netdev_info(dev,
1272 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001274 netdev_info(dev,
1275 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001276
1277 break;
1278 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001279 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001280 break;
1281 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001282 netdev_info(dev, "Port malfunction\n");
1283 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001284 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001285 break;
1286 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001287 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 break;
1289 }
1290}
1291
1292static void ehea_neq_tasklet(unsigned long data)
1293{
Doug Maxey508d2b52008-01-31 20:20:49 -06001294 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295 struct ehea_eqe *eqe;
1296 u64 event_mask;
1297
1298 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001299 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300
1301 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001302 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303 ehea_parse_eqe(adapter, eqe->entry);
1304 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001305 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001306 }
1307
1308 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1309 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1310 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1311
1312 ehea_h_reset_events(adapter->handle,
1313 adapter->neq->fw_handle, event_mask);
1314}
1315
David Howells7d12e782006-10-05 14:55:46 +01001316static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001317{
1318 struct ehea_adapter *adapter = param;
1319 tasklet_hi_schedule(&adapter->neq_tasklet);
1320 return IRQ_HANDLED;
1321}
1322
1323
1324static int ehea_fill_port_res(struct ehea_port_res *pr)
1325{
1326 int ret;
1327 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1328
Breno Leitaof76957f2011-01-11 07:45:57 +00001329 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330
Thomas Kleine2878802009-01-21 14:45:57 -08001331 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332
1333 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1334
1335 return ret;
1336}
1337
1338static int ehea_reg_interrupts(struct net_device *dev)
1339{
1340 struct ehea_port *port = netdev_priv(dev);
1341 struct ehea_port_res *pr;
1342 int i, ret;
1343
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344
1345 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1346 dev->name);
1347
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001348 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001350 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001351 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001352 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1353 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 goto out_free_qpeq;
1355 }
1356
Joe Perches8c4877a2010-12-13 10:05:14 -08001357 netif_info(port, ifup, dev,
1358 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1359 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001360
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001361
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001362 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1363 pr = &port->port_res[i];
1364 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001365 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001366 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001367 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001368 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 pr);
1370 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001371 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1372 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001373 goto out_free_req;
1374 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001375 netif_info(port, ifup, dev,
1376 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1377 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378 }
1379out:
1380 return ret;
1381
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001382
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383out_free_req:
1384 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001385 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001386 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001389out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001390 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001392
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001393 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001394
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001395}
1396
1397static void ehea_free_interrupts(struct net_device *dev)
1398{
1399 struct ehea_port *port = netdev_priv(dev);
1400 struct ehea_port_res *pr;
1401 int i;
1402
1403 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001404
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001405 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1406 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001407 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001408 netif_info(port, intr, dev,
1409 "free send irq for res %d with handle 0x%X\n",
1410 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001411 }
1412
1413 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001414 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001415 netif_info(port, intr, dev,
1416 "associated event interrupt for handle 0x%X freed\n",
1417 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418}
1419
1420static int ehea_configure_port(struct ehea_port *port)
1421{
1422 int ret, i;
1423 u64 hret, mask;
1424 struct hcp_ehea_port_cb0 *cb0;
1425
1426 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001427 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428 if (!cb0)
1429 goto out;
1430
1431 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1432 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1433 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1434 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1435 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1436 PXLY_RC_VLAN_FILTER)
1437 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1438
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001439 for (i = 0; i < port->num_mcs; i++)
1440 if (use_mcs)
1441 cb0->default_qpn_arr[i] =
1442 port->port_res[i].qp->init_attr.qp_nr;
1443 else
1444 cb0->default_qpn_arr[i] =
1445 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001446
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001447 if (netif_msg_ifup(port))
1448 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1449
1450 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1451 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1452
1453 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1454 port->logical_port_id,
1455 H_PORT_CB0, mask, cb0);
1456 ret = -EIO;
1457 if (hret != H_SUCCESS)
1458 goto out_free;
1459
1460 ret = 0;
1461
1462out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001463 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001464out:
1465 return ret;
1466}
1467
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001468int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001469{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001470 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001471 struct ehea_adapter *adapter = pr->port->adapter;
1472
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1474 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475 goto out;
1476
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001477 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1478 if (ret)
1479 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480
1481 return 0;
1482
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001483out_free:
1484 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001486 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487 return -EIO;
1488}
1489
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001490int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491{
Joe Perches8e95a202009-12-03 07:58:21 +00001492 if ((ehea_rem_mr(&pr->send_mr)) ||
1493 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001494 return -EIO;
1495 else
1496 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001497}
1498
1499static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1500{
Doug Maxey508d2b52008-01-31 20:20:49 -06001501 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001503 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001504 if (!q_skba->arr)
1505 return -ENOMEM;
1506
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507 q_skba->len = max_q_entries;
1508 q_skba->index = 0;
1509 q_skba->os_skbs = 0;
1510
1511 return 0;
1512}
1513
1514static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1515 struct port_res_cfg *pr_cfg, int queue_token)
1516{
1517 struct ehea_adapter *adapter = port->adapter;
1518 enum ehea_eq_type eq_type = EHEA_EQ;
1519 struct ehea_qp_init_attr *init_attr = NULL;
1520 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001521 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1522
1523 tx_bytes = pr->tx_bytes;
1524 tx_packets = pr->tx_packets;
1525 rx_bytes = pr->rx_bytes;
1526 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001527
1528 memset(pr, 0, sizeof(struct ehea_port_res));
1529
Breno Leitaoce45b872010-10-27 08:45:14 +00001530 pr->tx_bytes = rx_bytes;
1531 pr->tx_packets = tx_packets;
1532 pr->rx_bytes = rx_bytes;
1533 pr->rx_packets = rx_packets;
1534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001535 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001536
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001537 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1538 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001539 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540 goto out_free;
1541 }
1542
1543 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001544 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001545 port->logical_port_id);
1546 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001547 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001548 goto out_free;
1549 }
1550
1551 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001552 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001553 port->logical_port_id);
1554 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001555 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001556 goto out_free;
1557 }
1558
1559 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001560 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1561 pr->send_cq->attr.act_nr_of_cqes,
1562 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563
1564 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1565 if (!init_attr) {
1566 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001567 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001568 goto out_free;
1569 }
1570
1571 init_attr->low_lat_rq1 = 1;
1572 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1573 init_attr->rq_count = 3;
1574 init_attr->qp_token = queue_token;
1575 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1576 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1577 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1578 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1579 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1580 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1581 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1582 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1583 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1584 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1585 init_attr->port_nr = port->logical_port_id;
1586 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1587 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1588 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1589
1590 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1591 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001592 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001593 ret = -EIO;
1594 goto out_free;
1595 }
1596
1597 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001598 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",
1599 init_attr->qp_nr,
1600 init_attr->act_nr_send_wqes,
1601 init_attr->act_nr_rwqes_rq1,
1602 init_attr->act_nr_rwqes_rq2,
1603 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001604
Thomas Klein44fb3122008-04-04 15:04:53 +02001605 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1606
1607 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001608 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1609 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1610 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1611 if (ret)
1612 goto out_free;
1613
1614 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1615 if (ehea_gen_smrs(pr) != 0) {
1616 ret = -EIO;
1617 goto out_free;
1618 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001619
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001620 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1621
1622 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001623
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001624 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001625
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001626 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1627 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1628 pr->lro_mgr.lro_arr = pr->lro_desc;
1629 pr->lro_mgr.get_skb_header = get_skb_hdr;
1630 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1631 pr->lro_mgr.dev = port->netdev;
1632 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1633 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1634
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001635 ret = 0;
1636 goto out;
1637
1638out_free:
1639 kfree(init_attr);
1640 vfree(pr->sq_skba.arr);
1641 vfree(pr->rq1_skba.arr);
1642 vfree(pr->rq2_skba.arr);
1643 vfree(pr->rq3_skba.arr);
1644 ehea_destroy_qp(pr->qp);
1645 ehea_destroy_cq(pr->send_cq);
1646 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001647 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001648out:
1649 return ret;
1650}
1651
1652static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1653{
1654 int ret, i;
1655
Hannes Hering357eb462009-08-04 11:48:39 -07001656 if (pr->qp)
1657 netif_napi_del(&pr->napi);
1658
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001659 ret = ehea_destroy_qp(pr->qp);
1660
1661 if (!ret) {
1662 ehea_destroy_cq(pr->send_cq);
1663 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001664 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001665
1666 for (i = 0; i < pr->rq1_skba.len; i++)
1667 if (pr->rq1_skba.arr[i])
1668 dev_kfree_skb(pr->rq1_skba.arr[i]);
1669
1670 for (i = 0; i < pr->rq2_skba.len; i++)
1671 if (pr->rq2_skba.arr[i])
1672 dev_kfree_skb(pr->rq2_skba.arr[i]);
1673
1674 for (i = 0; i < pr->rq3_skba.len; i++)
1675 if (pr->rq3_skba.arr[i])
1676 dev_kfree_skb(pr->rq3_skba.arr[i]);
1677
1678 for (i = 0; i < pr->sq_skba.len; i++)
1679 if (pr->sq_skba.arr[i])
1680 dev_kfree_skb(pr->sq_skba.arr[i]);
1681
1682 vfree(pr->rq1_skba.arr);
1683 vfree(pr->rq2_skba.arr);
1684 vfree(pr->rq3_skba.arr);
1685 vfree(pr->sq_skba.arr);
1686 ret = ehea_rem_smrs(pr);
1687 }
1688 return ret;
1689}
1690
1691/*
1692 * The write_* functions store information in swqe which is used by
1693 * the hardware to calculate the ip/tcp/udp checksum
1694 */
1695
1696static inline void write_ip_start_end(struct ehea_swqe *swqe,
1697 const struct sk_buff *skb)
1698{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001699 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001700 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001701}
1702
1703static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1704 const struct sk_buff *skb)
1705{
1706 swqe->tcp_offset =
1707 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1708
1709 swqe->tcp_end = (u16)skb->len - 1;
1710}
1711
1712static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1713 const struct sk_buff *skb)
1714{
1715 swqe->tcp_offset =
1716 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1717
1718 swqe->tcp_end = (u16)skb->len - 1;
1719}
1720
1721
1722static void write_swqe2_TSO(struct sk_buff *skb,
1723 struct ehea_swqe *swqe, u32 lkey)
1724{
1725 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1726 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001727 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001728 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001729
1730 /* Packet is TCP with TSO enabled */
1731 swqe->tx_control |= EHEA_SWQE_TSO;
1732 swqe->mss = skb_shinfo(skb)->gso_size;
1733 /* copy only eth/ip/tcp headers to immediate data and
1734 * the rest of skb->data to sg1entry
1735 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001736 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001737
Eric Dumazete743d312010-04-14 15:59:40 -07001738 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001739
1740 if (skb_data_size >= headersize) {
1741 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001742 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001743 swqe->immediate_data_length = headersize;
1744
1745 if (skb_data_size > headersize) {
1746 /* set sg1entry data */
1747 sg1entry->l_key = lkey;
1748 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001749 sg1entry->vaddr =
1750 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001751 swqe->descriptors++;
1752 }
1753 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001754 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001755}
1756
1757static void write_swqe2_nonTSO(struct sk_buff *skb,
1758 struct ehea_swqe *swqe, u32 lkey)
1759{
Eric Dumazete743d312010-04-14 15:59:40 -07001760 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1762 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001763
1764 /* Packet is any nonTSO type
1765 *
1766 * Copy as much as possible skb->data to immediate data and
1767 * the rest to sg1entry
1768 */
1769 if (skb_data_size >= SWQE2_MAX_IMM) {
1770 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001771 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001772
1773 swqe->immediate_data_length = SWQE2_MAX_IMM;
1774
1775 if (skb_data_size > SWQE2_MAX_IMM) {
1776 /* copy sg1entry data */
1777 sg1entry->l_key = lkey;
1778 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001779 sg1entry->vaddr =
1780 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781 swqe->descriptors++;
1782 }
1783 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001784 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785 swqe->immediate_data_length = skb_data_size;
1786 }
1787}
1788
1789static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1790 struct ehea_swqe *swqe, u32 lkey)
1791{
1792 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1793 skb_frag_t *frag;
1794 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001795
1796 nfrags = skb_shinfo(skb)->nr_frags;
1797 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001798 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799 swqe->descriptors = 0;
1800 sg1entry_contains_frag_data = 0;
1801
1802 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1803 write_swqe2_TSO(skb, swqe, lkey);
1804 else
1805 write_swqe2_nonTSO(skb, swqe, lkey);
1806
1807 /* write descriptors */
1808 if (nfrags > 0) {
1809 if (swqe->descriptors == 0) {
1810 /* sg1entry not yet used */
1811 frag = &skb_shinfo(skb)->frags[0];
1812
1813 /* copy sg1entry data */
1814 sg1entry->l_key = lkey;
1815 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001816 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001817 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818 swqe->descriptors++;
1819 sg1entry_contains_frag_data = 1;
1820 }
1821
1822 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1823
1824 frag = &skb_shinfo(skb)->frags[i];
1825 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1826
1827 sgentry->l_key = lkey;
1828 sgentry->len = frag->size;
Ian Campbell618c4a02011-10-10 01:11:38 +00001829 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001830 swqe->descriptors++;
1831 }
1832 }
1833}
1834
1835static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1836{
1837 int ret = 0;
1838 u64 hret;
1839 u8 reg_type;
1840
1841 /* De/Register untagged packets */
1842 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1843 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1844 port->logical_port_id,
1845 reg_type, port->mac_addr, 0, hcallid);
1846 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001847 pr_err("%sregistering bc address failed (tagged)\n",
1848 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001849 ret = -EIO;
1850 goto out_herr;
1851 }
1852
1853 /* De/Register VLAN packets */
1854 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1855 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1856 port->logical_port_id,
1857 reg_type, port->mac_addr, 0, hcallid);
1858 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001859 pr_err("%sregistering bc address failed (vlan)\n",
1860 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001861 ret = -EIO;
1862 }
1863out_herr:
1864 return ret;
1865}
1866
1867static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1868{
1869 struct ehea_port *port = netdev_priv(dev);
1870 struct sockaddr *mac_addr = sa;
1871 struct hcp_ehea_port_cb0 *cb0;
1872 int ret;
1873 u64 hret;
1874
1875 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1876 ret = -EADDRNOTAVAIL;
1877 goto out;
1878 }
1879
Thomas Klein3faf2692009-01-21 14:45:33 -08001880 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001881 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001882 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001883 ret = -ENOMEM;
1884 goto out;
1885 }
1886
1887 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1888
1889 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1890
1891 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1892 port->logical_port_id, H_PORT_CB0,
1893 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1894 if (hret != H_SUCCESS) {
1895 ret = -EIO;
1896 goto out_free;
1897 }
1898
1899 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1900
1901 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001902 if (port->state == EHEA_PORT_UP) {
1903 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1904 if (ret)
1905 goto out_upregs;
1906 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001907
1908 port->mac_addr = cb0->port_mac_addr << 16;
1909
1910 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001911 if (port->state == EHEA_PORT_UP) {
1912 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1913 if (ret)
1914 goto out_upregs;
1915 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001916
1917 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001918
1919out_upregs:
1920 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001922 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001923out:
1924 return ret;
1925}
1926
1927static void ehea_promiscuous_error(u64 hret, int enable)
1928{
Thomas Klein7674a582007-01-22 12:54:20 +01001929 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001930 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1931 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001932 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001933 pr_err("failed %sabling promiscuous mode\n",
1934 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001935}
1936
1937static void ehea_promiscuous(struct net_device *dev, int enable)
1938{
1939 struct ehea_port *port = netdev_priv(dev);
1940 struct hcp_ehea_port_cb7 *cb7;
1941 u64 hret;
1942
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001943 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001944 return;
1945
Thomas Klein3faf2692009-01-21 14:45:33 -08001946 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001948 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001949 goto out;
1950 }
1951
1952 /* Modify Pxs_DUCQPN in CB7 */
1953 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1954
1955 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1956 port->logical_port_id,
1957 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1958 if (hret) {
1959 ehea_promiscuous_error(hret, enable);
1960 goto out;
1961 }
1962
1963 port->promisc = enable;
1964out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001965 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001966}
1967
1968static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1969 u32 hcallid)
1970{
1971 u64 hret;
1972 u8 reg_type;
1973
1974 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1975 | EHEA_BCMC_UNTAGGED;
1976
1977 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1978 port->logical_port_id,
1979 reg_type, mc_mac_addr, 0, hcallid);
1980 if (hret)
1981 goto out;
1982
1983 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1984 | EHEA_BCMC_VLANID_ALL;
1985
1986 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1987 port->logical_port_id,
1988 reg_type, mc_mac_addr, 0, hcallid);
1989out:
1990 return hret;
1991}
1992
1993static int ehea_drop_multicast_list(struct net_device *dev)
1994{
1995 struct ehea_port *port = netdev_priv(dev);
1996 struct ehea_mc_list *mc_entry = port->mc_list;
1997 struct list_head *pos;
1998 struct list_head *temp;
1999 int ret = 0;
2000 u64 hret;
2001
2002 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2003 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2004
2005 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2006 H_DEREG_BCMC);
2007 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002008 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002009 ret = -EIO;
2010 }
2011
2012 list_del(pos);
2013 kfree(mc_entry);
2014 }
2015 return ret;
2016}
2017
2018static void ehea_allmulti(struct net_device *dev, int enable)
2019{
2020 struct ehea_port *port = netdev_priv(dev);
2021 u64 hret;
2022
2023 if (!port->allmulti) {
2024 if (enable) {
2025 /* Enable ALLMULTI */
2026 ehea_drop_multicast_list(dev);
2027 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2028 if (!hret)
2029 port->allmulti = 1;
2030 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002031 netdev_err(dev,
2032 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033 }
2034 } else
2035 if (!enable) {
2036 /* Disable ALLMULTI */
2037 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2038 if (!hret)
2039 port->allmulti = 0;
2040 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002041 netdev_err(dev,
2042 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 }
2044}
2045
Doug Maxey508d2b52008-01-31 20:20:49 -06002046static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002047{
2048 struct ehea_mc_list *ehea_mcl_entry;
2049 u64 hret;
2050
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002051 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002053 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054 return;
2055 }
2056
2057 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2058
2059 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2060
2061 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2062 H_REG_BCMC);
2063 if (!hret)
2064 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2065 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002066 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002067 kfree(ehea_mcl_entry);
2068 }
2069}
2070
2071static void ehea_set_multicast_list(struct net_device *dev)
2072{
2073 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002074 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002075 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002076
Breno Leitaoa4910b72011-05-23 03:36:35 +00002077 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002078 ehea_promiscuous(dev, 1);
2079 return;
2080 }
2081 ehea_promiscuous(dev, 0);
2082
2083 if (dev->flags & IFF_ALLMULTI) {
2084 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002085 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002086 }
2087 ehea_allmulti(dev, 0);
2088
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002089 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002090 ret = ehea_drop_multicast_list(dev);
2091 if (ret) {
2092 /* Dropping the current multicast list failed.
2093 * Enabling ALL_MULTI is the best we can do.
2094 */
2095 ehea_allmulti(dev, 1);
2096 }
2097
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002098 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002099 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2100 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002101 goto out;
2102 }
2103
Jiri Pirko22bedad32010-04-01 21:22:57 +00002104 netdev_for_each_mc_addr(ha, dev)
2105 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002106
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107 }
2108out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002109 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110}
2111
2112static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2113{
2114 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2115 return -EINVAL;
2116 dev->mtu = new_mtu;
2117 return 0;
2118}
2119
2120static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2121 struct ehea_swqe *swqe, u32 lkey)
2122{
2123 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002124 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002125
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126 /* IPv4 */
2127 swqe->tx_control |= EHEA_SWQE_CRC
2128 | EHEA_SWQE_IP_CHECKSUM
2129 | EHEA_SWQE_TCP_CHECKSUM
2130 | EHEA_SWQE_IMM_DATA_PRESENT
2131 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2132
2133 write_ip_start_end(swqe, skb);
2134
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002135 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002136 if ((iph->frag_off & IP_MF) ||
2137 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002138 /* IP fragment, so don't change cs */
2139 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2140 else
2141 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002142 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002143 write_tcp_offset_end(swqe, skb);
2144 }
2145
2146 /* icmp (big data) and ip segmentation packets (all other ip
2147 packets) do not require any special handling */
2148
2149 } else {
2150 /* Other Ethernet Protocol */
2151 swqe->tx_control |= EHEA_SWQE_CRC
2152 | EHEA_SWQE_IMM_DATA_PRESENT
2153 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2154 }
2155
2156 write_swqe2_data(skb, dev, swqe, lkey);
2157}
2158
2159static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2160 struct ehea_swqe *swqe)
2161{
2162 int nfrags = skb_shinfo(skb)->nr_frags;
2163 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2164 skb_frag_t *frag;
2165 int i;
2166
2167 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002168 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002169
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002170 /* IPv4 */
2171 write_ip_start_end(swqe, skb);
2172
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002173 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174 swqe->tx_control |= EHEA_SWQE_CRC
2175 | EHEA_SWQE_IP_CHECKSUM
2176 | EHEA_SWQE_TCP_CHECKSUM
2177 | EHEA_SWQE_IMM_DATA_PRESENT;
2178
2179 write_tcp_offset_end(swqe, skb);
2180
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002181 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002182 if ((iph->frag_off & IP_MF) ||
2183 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 /* IP fragment, so don't change cs */
2185 swqe->tx_control |= EHEA_SWQE_CRC
2186 | EHEA_SWQE_IMM_DATA_PRESENT;
2187 else {
2188 swqe->tx_control |= EHEA_SWQE_CRC
2189 | EHEA_SWQE_IP_CHECKSUM
2190 | EHEA_SWQE_TCP_CHECKSUM
2191 | EHEA_SWQE_IMM_DATA_PRESENT;
2192
2193 write_udp_offset_end(swqe, skb);
2194 }
2195 } else {
2196 /* icmp (big data) and
2197 ip segmentation packets (all other ip packets) */
2198 swqe->tx_control |= EHEA_SWQE_CRC
2199 | EHEA_SWQE_IP_CHECKSUM
2200 | EHEA_SWQE_IMM_DATA_PRESENT;
2201 }
2202 } else {
2203 /* Other Ethernet Protocol */
2204 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2205 }
2206 /* copy (immediate) data */
2207 if (nfrags == 0) {
2208 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002209 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002210 } else {
2211 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002212 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002213 skb_headlen(skb));
2214 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002215
2216 /* ... then copy data from the fragments */
2217 for (i = 0; i < nfrags; i++) {
2218 frag = &skb_shinfo(skb)->frags[i];
Ian Campbell618c4a02011-10-10 01:11:38 +00002219 memcpy(imm_data, skb_frag_address(frag), frag->size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002220 imm_data += frag->size;
2221 }
2222 }
2223 swqe->immediate_data_length = skb->len;
2224 dev_kfree_skb(skb);
2225}
2226
2227static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2228{
2229 struct ehea_port *port = netdev_priv(dev);
2230 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002231 u32 lkey;
2232 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002233 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002234 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235
Anton Blanchardb9564462011-10-14 05:30:59 +00002236 pr = &port->port_res[skb_get_queue_mapping(skb)];
2237 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002239 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2240 memset(swqe, 0, SWQE_HEADER_SIZE);
2241 atomic_dec(&pr->swqe_avail);
2242
Eric Dumazete5ccd962010-10-26 19:21:07 +00002243 if (vlan_tx_tag_present(skb)) {
2244 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2245 swqe->vlan_tag = vlan_tx_tag_get(skb);
2246 }
2247
Breno Leitaoce45b872010-10-27 08:45:14 +00002248 pr->tx_packets++;
2249 pr->tx_bytes += skb->len;
2250
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251 if (skb->len <= SWQE3_MAX_IMM) {
2252 u32 sig_iv = port->sig_comp_iv;
2253 u32 swqe_num = pr->swqe_id_counter;
2254 ehea_xmit3(skb, dev, swqe);
2255 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2256 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2257 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2258 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2259 sig_iv);
2260 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2261 pr->swqe_ll_count = 0;
2262 } else
2263 pr->swqe_ll_count += 1;
2264 } else {
2265 swqe->wr_id =
2266 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2267 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002268 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002269 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2270 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2271
2272 pr->sq_skba.index++;
2273 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2274
2275 lkey = pr->send_mr.lkey;
2276 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002277 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002278 }
2279 pr->swqe_id_counter += 1;
2280
Joe Perches8c4877a2010-12-13 10:05:14 -08002281 netif_info(port, tx_queued, dev,
2282 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2283 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002284 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002286 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002287 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002288 swqe->tx_control |= EHEA_SWQE_PURGE;
2289 }
Thomas Klein44c82152007-07-11 16:32:00 +02002290
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002291 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002292
2293 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002294 pr->p_stats.queue_stopped++;
2295 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002296 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002297
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 return NETDEV_TX_OK;
2299}
2300
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2302{
2303 struct ehea_port *port = netdev_priv(dev);
2304 struct ehea_adapter *adapter = port->adapter;
2305 struct hcp_ehea_port_cb1 *cb1;
2306 int index;
2307 u64 hret;
2308
Thomas Klein3faf2692009-01-21 14:45:33 -08002309 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002310 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002311 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312 goto out;
2313 }
2314
2315 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2316 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2317 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002318 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319 goto out;
2320 }
2321
2322 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002323 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002324
2325 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2326 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2327 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002328 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002329out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002330 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 return;
2332}
2333
2334static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2335{
2336 struct ehea_port *port = netdev_priv(dev);
2337 struct ehea_adapter *adapter = port->adapter;
2338 struct hcp_ehea_port_cb1 *cb1;
2339 int index;
2340 u64 hret;
2341
Thomas Klein3faf2692009-01-21 14:45:33 -08002342 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002343 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002344 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002345 goto out;
2346 }
2347
2348 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2349 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2350 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002351 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002352 goto out;
2353 }
2354
2355 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002356 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002357
2358 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2359 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2360 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002361 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002363 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364}
2365
2366int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2367{
2368 int ret = -EIO;
2369 u64 hret;
2370 u16 dummy16 = 0;
2371 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002372 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002373
Thomas Klein3faf2692009-01-21 14:45:33 -08002374 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 if (!cb0) {
2376 ret = -ENOMEM;
2377 goto out;
2378 }
2379
2380 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2381 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2382 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002383 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002384 goto out;
2385 }
2386
2387 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2388 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2389 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2390 &dummy64, &dummy64, &dummy16, &dummy16);
2391 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002392 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002393 goto out;
2394 }
2395
2396 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2397 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2398 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002399 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002400 goto out;
2401 }
2402
2403 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2404 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2405 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2406 &dummy64, &dummy64, &dummy16, &dummy16);
2407 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002408 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002409 goto out;
2410 }
2411
2412 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2413 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2414 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002415 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002416 goto out;
2417 }
2418
2419 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2420 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2421 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2422 &dummy64, &dummy64, &dummy16, &dummy16);
2423 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002424 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425 goto out;
2426 }
2427
2428 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2429 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2430 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002431 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432 goto out;
2433 }
2434
2435 ret = 0;
2436out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002437 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002438 return ret;
2439}
2440
2441static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2442 int add_tx_qps)
2443{
2444 int ret, i;
2445 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2446 enum ehea_eq_type eq_type = EHEA_EQ;
2447
2448 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2449 EHEA_MAX_ENTRIES_EQ, 1);
2450 if (!port->qp_eq) {
2451 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002452 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453 goto out_kill_eq;
2454 }
2455
2456 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002457 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002458 pr_cfg.max_entries_sq = sq_entries;
2459 pr_cfg.max_entries_rq1 = rq1_entries;
2460 pr_cfg.max_entries_rq2 = rq2_entries;
2461 pr_cfg.max_entries_rq3 = rq3_entries;
2462
2463 pr_cfg_small_rx.max_entries_rcq = 1;
2464 pr_cfg_small_rx.max_entries_scq = sq_entries;
2465 pr_cfg_small_rx.max_entries_sq = sq_entries;
2466 pr_cfg_small_rx.max_entries_rq1 = 1;
2467 pr_cfg_small_rx.max_entries_rq2 = 1;
2468 pr_cfg_small_rx.max_entries_rq3 = 1;
2469
2470 for (i = 0; i < def_qps; i++) {
2471 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2472 if (ret)
2473 goto out_clean_pr;
2474 }
2475 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2476 ret = ehea_init_port_res(port, &port->port_res[i],
2477 &pr_cfg_small_rx, i);
2478 if (ret)
2479 goto out_clean_pr;
2480 }
2481
2482 return 0;
2483
2484out_clean_pr:
2485 while (--i >= 0)
2486 ehea_clean_portres(port, &port->port_res[i]);
2487
2488out_kill_eq:
2489 ehea_destroy_eq(port->qp_eq);
2490 return ret;
2491}
2492
2493static int ehea_clean_all_portres(struct ehea_port *port)
2494{
2495 int ret = 0;
2496 int i;
2497
Doug Maxey508d2b52008-01-31 20:20:49 -06002498 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002499 ret |= ehea_clean_portres(port, &port->port_res[i]);
2500
2501 ret |= ehea_destroy_eq(port->qp_eq);
2502
2503 return ret;
2504}
2505
Thomas Klein35cf2e22007-08-06 13:55:14 +02002506static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002507{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002508 if (adapter->active_ports)
2509 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002510
2511 ehea_rem_mr(&adapter->mr);
2512}
2513
Thomas Klein35cf2e22007-08-06 13:55:14 +02002514static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002515{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002516 if (adapter->active_ports)
2517 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002518
2519 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2520}
2521
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002522static int ehea_up(struct net_device *dev)
2523{
2524 int ret, i;
2525 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002526
2527 if (port->state == EHEA_PORT_UP)
2528 return 0;
2529
2530 ret = ehea_port_res_setup(port, port->num_def_qps,
2531 port->num_add_tx_qps);
2532 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002533 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002534 goto out;
2535 }
2536
2537 /* Set default QP for this port */
2538 ret = ehea_configure_port(port);
2539 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002540 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002541 goto out_clean_pr;
2542 }
2543
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002544 ret = ehea_reg_interrupts(dev);
2545 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002546 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002547 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002548 }
2549
Doug Maxey508d2b52008-01-31 20:20:49 -06002550 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002551 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2552 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002553 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002554 goto out_free_irqs;
2555 }
2556 }
2557
Doug Maxey508d2b52008-01-31 20:20:49 -06002558 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002559 ret = ehea_fill_port_res(&port->port_res[i]);
2560 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002561 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002562 goto out_free_irqs;
2563 }
2564 }
2565
Thomas Klein21eee2d2008-02-13 16:18:33 +01002566 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2567 if (ret) {
2568 ret = -EIO;
2569 goto out_free_irqs;
2570 }
2571
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002572 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002573
2574 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002575 goto out;
2576
2577out_free_irqs:
2578 ehea_free_interrupts(dev);
2579
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580out_clean_pr:
2581 ehea_clean_all_portres(port);
2582out:
Thomas Klein44c82152007-07-11 16:32:00 +02002583 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002584 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002585
Thomas Klein21eee2d2008-02-13 16:18:33 +01002586 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002587 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589 return ret;
2590}
2591
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002592static void port_napi_disable(struct ehea_port *port)
2593{
2594 int i;
2595
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002596 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002597 napi_disable(&port->port_res[i].napi);
2598}
2599
2600static void port_napi_enable(struct ehea_port *port)
2601{
2602 int i;
2603
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002604 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002605 napi_enable(&port->port_res[i].napi);
2606}
2607
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002608static int ehea_open(struct net_device *dev)
2609{
2610 int ret;
2611 struct ehea_port *port = netdev_priv(dev);
2612
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002613 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614
Joe Perches8c4877a2010-12-13 10:05:14 -08002615 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002616
2617 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002618 if (!ret) {
2619 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002620 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002621 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002622
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002623 mutex_unlock(&port->port_lock);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002624 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002625
2626 return ret;
2627}
2628
2629static int ehea_down(struct net_device *dev)
2630{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002631 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002632 struct ehea_port *port = netdev_priv(dev);
2633
2634 if (port->state == EHEA_PORT_DOWN)
2635 return 0;
2636
2637 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002638 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002640 ehea_free_interrupts(dev);
2641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002642 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002643
Thomas Klein21eee2d2008-02-13 16:18:33 +01002644 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002645
Thomas Klein44c82152007-07-11 16:32:00 +02002646 ret = ehea_clean_all_portres(port);
2647 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002648 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002649
Thomas Klein21eee2d2008-02-13 16:18:33 +01002650 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002651
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002652 return ret;
2653}
2654
2655static int ehea_stop(struct net_device *dev)
2656{
2657 int ret;
2658 struct ehea_port *port = netdev_priv(dev);
2659
Joe Perches8c4877a2010-12-13 10:05:14 -08002660 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002661
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002662 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002663 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002664 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002665 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002666 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002667 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002668 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002669 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002670 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002671 return ret;
2672}
2673
Andrew Morton22559c52008-04-18 13:50:39 -07002674static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002675{
2676 struct ehea_qp qp = *orig_qp;
2677 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2678 struct ehea_swqe *swqe;
2679 int wqe_index;
2680 int i;
2681
2682 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2683 swqe = ehea_get_swqe(&qp, &wqe_index);
2684 swqe->tx_control |= EHEA_SWQE_PURGE;
2685 }
2686}
2687
Andrew Morton22559c52008-04-18 13:50:39 -07002688static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002689{
2690 int i;
2691
2692 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2693 struct ehea_port_res *pr = &port->port_res[i];
2694 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002695 int ret;
2696
2697 ret = wait_event_timeout(port->swqe_avail_wq,
2698 atomic_read(&pr->swqe_avail) >= swqe_max,
2699 msecs_to_jiffies(100));
2700
2701 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002702 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002703 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002704 }
2705 }
2706}
2707
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002708int ehea_stop_qps(struct net_device *dev)
2709{
2710 struct ehea_port *port = netdev_priv(dev);
2711 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002712 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002713 int ret = -EIO;
2714 int dret;
2715 int i;
2716 u64 hret;
2717 u64 dummy64 = 0;
2718 u16 dummy16 = 0;
2719
Thomas Klein3faf2692009-01-21 14:45:33 -08002720 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002721 if (!cb0) {
2722 ret = -ENOMEM;
2723 goto out;
2724 }
2725
2726 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2727 struct ehea_port_res *pr = &port->port_res[i];
2728 struct ehea_qp *qp = pr->qp;
2729
2730 /* Purge send queue */
2731 ehea_purge_sq(qp);
2732
2733 /* Disable queue pair */
2734 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2735 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2736 cb0);
2737 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002738 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002739 goto out;
2740 }
2741
2742 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2743 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2744
2745 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2746 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2747 1), cb0, &dummy64,
2748 &dummy64, &dummy16, &dummy16);
2749 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002750 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002751 goto out;
2752 }
2753
2754 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2755 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2756 cb0);
2757 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002758 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002759 goto out;
2760 }
2761
2762 /* deregister shared memory regions */
2763 dret = ehea_rem_smrs(pr);
2764 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002765 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002766 goto out;
2767 }
2768 }
2769
2770 ret = 0;
2771out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002772 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002773
2774 return ret;
2775}
2776
Doug Maxey508d2b52008-01-31 20:20:49 -06002777void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002778{
2779 struct ehea_qp qp = *orig_qp;
2780 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2781 struct ehea_rwqe *rwqe;
2782 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2783 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2784 struct sk_buff *skb;
2785 u32 lkey = pr->recv_mr.lkey;
2786
2787
2788 int i;
2789 int index;
2790
2791 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2792 rwqe = ehea_get_next_rwqe(&qp, 2);
2793 rwqe->sg_list[0].l_key = lkey;
2794 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2795 skb = skba_rq2[index];
2796 if (skb)
2797 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2798 }
2799
2800 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2801 rwqe = ehea_get_next_rwqe(&qp, 3);
2802 rwqe->sg_list[0].l_key = lkey;
2803 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2804 skb = skba_rq3[index];
2805 if (skb)
2806 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2807 }
2808}
2809
2810int ehea_restart_qps(struct net_device *dev)
2811{
2812 struct ehea_port *port = netdev_priv(dev);
2813 struct ehea_adapter *adapter = port->adapter;
2814 int ret = 0;
2815 int i;
2816
Doug Maxey508d2b52008-01-31 20:20:49 -06002817 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002818 u64 hret;
2819 u64 dummy64 = 0;
2820 u16 dummy16 = 0;
2821
Thomas Klein3faf2692009-01-21 14:45:33 -08002822 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002823 if (!cb0) {
2824 ret = -ENOMEM;
2825 goto out;
2826 }
2827
2828 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2829 struct ehea_port_res *pr = &port->port_res[i];
2830 struct ehea_qp *qp = pr->qp;
2831
2832 ret = ehea_gen_smrs(pr);
2833 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002834 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002835 goto out;
2836 }
2837
2838 ehea_update_rqs(qp, pr);
2839
2840 /* Enable queue pair */
2841 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2842 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2843 cb0);
2844 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002845 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002846 goto out;
2847 }
2848
2849 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2850 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2851
2852 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2853 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2854 1), cb0, &dummy64,
2855 &dummy64, &dummy16, &dummy16);
2856 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002857 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002858 goto out;
2859 }
2860
2861 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2862 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2863 cb0);
2864 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002865 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002866 goto out;
2867 }
2868
2869 /* refill entire queue */
2870 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2871 ehea_refill_rq2(pr, 0);
2872 ehea_refill_rq3(pr, 0);
2873 }
2874out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002875 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002876
2877 return ret;
2878}
2879
David Howellsc4028952006-11-22 14:57:56 +00002880static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002881{
2882 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002883 struct ehea_port *port =
2884 container_of(work, struct ehea_port, reset_task);
2885 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002886
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002887 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002888 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002889 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002890 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002891
2892 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002893
Thomas Klein44c82152007-07-11 16:32:00 +02002894 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002895
2896 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002897 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002898 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002899
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002900 ehea_set_multicast_list(dev);
2901
Joe Perches8c4877a2010-12-13 10:05:14 -08002902 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002903
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002904 port_napi_enable(port);
2905
Anton Blanchardb9564462011-10-14 05:30:59 +00002906 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002907out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002908 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002909 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002910}
2911
Tejun Heo3d6b8922010-12-12 16:45:14 +01002912static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002913{
2914 int ret, i;
2915 struct ehea_adapter *adapter;
2916
Joe Perches8c4877a2010-12-13 10:05:14 -08002917 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002918
2919 list_for_each_entry(adapter, &adapter_list, list)
2920 if (adapter->active_ports) {
2921 /* Shutdown all ports */
2922 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2923 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002924 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002925
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002926 if (!port)
2927 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002928
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002929 dev = port->netdev;
2930
2931 if (dev->flags & IFF_UP) {
2932 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002933 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002934 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002935 ret = ehea_stop_qps(dev);
2936 if (ret) {
2937 mutex_unlock(&port->port_lock);
2938 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002939 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002940 port_napi_disable(port);
2941 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002942 }
Andre Detsch2928db42010-08-17 05:49:12 +00002943 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002944 }
2945
2946 /* Unregister old memory region */
2947 ret = ehea_rem_mr(&adapter->mr);
2948 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002949 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002950 goto out;
2951 }
2952 }
2953
Thomas Klein44c82152007-07-11 16:32:00 +02002954 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2955
2956 list_for_each_entry(adapter, &adapter_list, list)
2957 if (adapter->active_ports) {
2958 /* Register new memory region */
2959 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2960 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002961 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002962 goto out;
2963 }
2964
2965 /* Restart all ports */
2966 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2967 struct ehea_port *port = adapter->port[i];
2968
2969 if (port) {
2970 struct net_device *dev = port->netdev;
2971
2972 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002973 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002974 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002975 if (!ret) {
2976 check_sqs(port);
2977 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002978 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002979 } else {
2980 netdev_err(dev, "Unable to restart QPS\n");
2981 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002982 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002983 }
2984 }
2985 }
2986 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002987 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002988out:
2989 return;
2990}
2991
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002992static void ehea_tx_watchdog(struct net_device *dev)
2993{
2994 struct ehea_port *port = netdev_priv(dev);
2995
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002996 if (netif_carrier_ok(dev) &&
2997 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002998 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999}
3000
3001int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3002{
3003 struct hcp_query_ehea *cb;
3004 u64 hret;
3005 int ret;
3006
Thomas Klein3faf2692009-01-21 14:45:33 -08003007 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003008 if (!cb) {
3009 ret = -ENOMEM;
3010 goto out;
3011 }
3012
3013 hret = ehea_h_query_ehea(adapter->handle, cb);
3014
3015 if (hret != H_SUCCESS) {
3016 ret = -EIO;
3017 goto out_herr;
3018 }
3019
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003020 adapter->max_mc_mac = cb->max_mc_mac - 1;
3021 ret = 0;
3022
3023out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003024 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003025out:
3026 return ret;
3027}
3028
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003029int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3030{
3031 struct hcp_ehea_port_cb4 *cb4;
3032 u64 hret;
3033 int ret = 0;
3034
3035 *jumbo = 0;
3036
3037 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003038 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003039 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003040 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003041 ret = -ENOMEM;
3042 goto out;
3043 } else {
3044 hret = ehea_h_query_ehea_port(port->adapter->handle,
3045 port->logical_port_id,
3046 H_PORT_CB4,
3047 H_PORT_CB4_JUMBO, cb4);
3048 if (hret == H_SUCCESS) {
3049 if (cb4->jumbo_frame)
3050 *jumbo = 1;
3051 else {
3052 cb4->jumbo_frame = 1;
3053 hret = ehea_h_modify_ehea_port(port->adapter->
3054 handle,
3055 port->
3056 logical_port_id,
3057 H_PORT_CB4,
3058 H_PORT_CB4_JUMBO,
3059 cb4);
3060 if (hret == H_SUCCESS)
3061 *jumbo = 1;
3062 }
3063 } else
3064 ret = -EINVAL;
3065
Thomas Klein3faf2692009-01-21 14:45:33 -08003066 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003067 }
3068out:
3069 return ret;
3070}
3071
3072static ssize_t ehea_show_port_id(struct device *dev,
3073 struct device_attribute *attr, char *buf)
3074{
3075 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003076 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003077}
3078
3079static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3080 NULL);
3081
3082static void __devinit logical_port_release(struct device *dev)
3083{
3084 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003085 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003086}
3087
3088static struct device *ehea_register_port(struct ehea_port *port,
3089 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003090{
3091 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003092
Grant Likely61c7a082010-04-13 16:12:29 -07003093 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003094 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003095 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003096
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003097 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 port->ofdev.dev.release = logical_port_release;
3099
3100 ret = of_device_register(&port->ofdev);
3101 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003102 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 goto out;
3104 }
3105
3106 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003107 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003108 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003109 goto out_unreg_of_dev;
3110 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003111
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112 return &port->ofdev.dev;
3113
3114out_unreg_of_dev:
3115 of_device_unregister(&port->ofdev);
3116out:
3117 return NULL;
3118}
3119
3120static void ehea_unregister_port(struct ehea_port *port)
3121{
3122 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3123 of_device_unregister(&port->ofdev);
3124}
3125
Thomas Klein086c1b22009-01-21 14:43:59 -08003126static const struct net_device_ops ehea_netdev_ops = {
3127 .ndo_open = ehea_open,
3128 .ndo_stop = ehea_stop,
3129 .ndo_start_xmit = ehea_start_xmit,
3130#ifdef CONFIG_NET_POLL_CONTROLLER
3131 .ndo_poll_controller = ehea_netpoll,
3132#endif
3133 .ndo_get_stats = ehea_get_stats,
3134 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c102d2009-07-09 17:54:35 +00003135 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003136 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08003137 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003138 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003139 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3140 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003141};
3142
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3144 u32 logical_port_id,
3145 struct device_node *dn)
3146{
3147 int ret;
3148 struct net_device *dev;
3149 struct ehea_port *port;
3150 struct device *port_dev;
3151 int jumbo;
3152
3153 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00003154 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003155
3156 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003157 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003158 ret = -ENOMEM;
3159 goto out_err;
3160 }
3161
3162 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003163
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003164 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003165 port->state = EHEA_PORT_DOWN;
3166 port->sig_comp_iv = sq_entries / 10;
3167
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 port->adapter = adapter;
3169 port->netdev = dev;
3170 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003171
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003173
3174 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3175 if (!port->mc_list) {
3176 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003178 }
3179
3180 INIT_LIST_HEAD(&port->mc_list->list);
3181
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003182 ret = ehea_sense_port_attr(port);
3183 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003185
Anton Blanchardb9564462011-10-14 05:30:59 +00003186 netif_set_real_num_rx_queues(dev, port->num_def_qps);
3187 netif_set_real_num_tx_queues(dev, port->num_def_qps +
3188 port->num_add_tx_qps);
3189
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 port_dev = ehea_register_port(port, dn);
3191 if (!port_dev)
3192 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003193
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003194 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003195
3196 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003197 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3198
Thomas Klein086c1b22009-01-21 14:43:59 -08003199 dev->netdev_ops = &ehea_netdev_ops;
3200 ehea_set_ethtool_ops(dev);
3201
Michał Mirosławf4786a92011-04-17 00:15:47 +00003202 dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3203 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003204 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003205 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003206 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003207 | NETIF_F_RXCSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003208 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3209
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003210 if (use_lro)
3211 dev->features |= NETIF_F_LRO;
3212
David Howellsc4028952006-11-22 14:57:56 +00003213 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003214 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003215
Anton Blanchard21ccc792011-05-10 16:17:10 +00003216 init_waitqueue_head(&port->swqe_avail_wq);
3217 init_waitqueue_head(&port->restart_wq);
3218
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003219 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003220 ret = register_netdev(dev);
3221 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003222 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003223 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003224 }
3225
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003226 port->lro_max_aggr = lro_max_aggr;
3227
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003228 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003229 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003230 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231
Joe Perches8c4877a2010-12-13 10:05:14 -08003232 netdev_info(dev, "Jumbo frames are %sabled\n",
3233 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003234
Thomas Klein44c82152007-07-11 16:32:00 +02003235 adapter->active_ports++;
3236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003239out_unreg_port:
3240 ehea_unregister_port(port);
3241
3242out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003243 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244
3245out_free_ethdev:
3246 free_netdev(dev);
3247
3248out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003249 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3250 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 return NULL;
3252}
3253
3254static void ehea_shutdown_single_port(struct ehea_port *port)
3255{
Brian King7fb1c2a2008-05-14 09:48:25 -05003256 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003257
3258 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003259 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260 unregister_netdev(port->netdev);
3261 ehea_unregister_port(port);
3262 kfree(port->mc_list);
3263 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003264 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265}
3266
3267static int ehea_setup_ports(struct ehea_adapter *adapter)
3268{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003269 struct device_node *lhea_dn;
3270 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003271
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003272 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003273 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003274
Grant Likely61c7a082010-04-13 16:12:29 -07003275 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003276 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003277
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003278 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003279 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003280 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003281 pr_err("bad device node: eth_dn name=%s\n",
3282 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003283 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003284 }
3285
Thomas Klein1211bb62007-04-26 11:56:43 +02003286 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003287 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003288 of_node_put(eth_dn);
3289 return -EIO;
3290 }
3291
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003292 adapter->port[i] = ehea_setup_single_port(adapter,
3293 *dn_log_port_id,
3294 eth_dn);
3295 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003296 netdev_info(adapter->port[i]->netdev,
3297 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003298 else
3299 ehea_remove_adapter_mr(adapter);
3300
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003301 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003302 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003303 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304}
3305
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003306static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3307 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003308{
3309 struct device_node *lhea_dn;
3310 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003311 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003312
Grant Likely61c7a082010-04-13 16:12:29 -07003313 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003314 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003315
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003316 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003317 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318 if (dn_log_port_id)
3319 if (*dn_log_port_id == logical_port_id)
3320 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003321 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322
3323 return NULL;
3324}
3325
3326static ssize_t ehea_probe_port(struct device *dev,
3327 struct device_attribute *attr,
3328 const char *buf, size_t count)
3329{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003330 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003331 struct ehea_port *port;
3332 struct device_node *eth_dn = NULL;
3333 int i;
3334
3335 u32 logical_port_id;
3336
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003337 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003338
3339 port = ehea_get_port(adapter, logical_port_id);
3340
3341 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003342 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3343 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344 return -EINVAL;
3345 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003346
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3348
3349 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003350 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351 return -EINVAL;
3352 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003353
Thomas Klein1211bb62007-04-26 11:56:43 +02003354 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003355 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003356 return -EIO;
3357 }
3358
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3360
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003361 of_node_put(eth_dn);
3362
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003363 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003364 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365 if (!adapter->port[i]) {
3366 adapter->port[i] = port;
3367 break;
3368 }
3369
Joe Perches8c4877a2010-12-13 10:05:14 -08003370 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3371 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003372 } else {
3373 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003374 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003375 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003376
3377 return (ssize_t) count;
3378}
3379
3380static ssize_t ehea_remove_port(struct device *dev,
3381 struct device_attribute *attr,
3382 const char *buf, size_t count)
3383{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003384 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003385 struct ehea_port *port;
3386 int i;
3387 u32 logical_port_id;
3388
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003389 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003390
3391 port = ehea_get_port(adapter, logical_port_id);
3392
3393 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003394 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3395 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003396
3397 ehea_shutdown_single_port(port);
3398
Doug Maxey508d2b52008-01-31 20:20:49 -06003399 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003400 if (adapter->port[i] == port) {
3401 adapter->port[i] = NULL;
3402 break;
3403 }
3404 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003405 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3406 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003407 return -EINVAL;
3408 }
3409
Thomas Klein1211bb62007-04-26 11:56:43 +02003410 ehea_remove_adapter_mr(adapter);
3411
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003412 return (ssize_t) count;
3413}
3414
3415static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3416static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3417
Grant Likely2dc11582010-08-06 09:25:50 -06003418int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003419{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003420 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003421 if (ret)
3422 goto out;
3423
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003424 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003425out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003426 return ret;
3427}
3428
Grant Likely2dc11582010-08-06 09:25:50 -06003429void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003430{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003431 device_remove_file(&dev->dev, &dev_attr_probe_port);
3432 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433}
3434
Grant Likely2dc11582010-08-06 09:25:50 -06003435static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003436 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003437{
3438 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003439 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003440 int ret;
3441
Grant Likely61c7a082010-04-13 16:12:29 -07003442 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003443 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003444 return -EINVAL;
3445 }
3446
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3448 if (!adapter) {
3449 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003450 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003451 goto out;
3452 }
3453
Thomas Klein44c82152007-07-11 16:32:00 +02003454 list_add(&adapter->list, &adapter_list);
3455
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003456 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003457
Grant Likely61c7a082010-04-13 16:12:29 -07003458 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003459 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003460 if (adapter_handle)
3461 adapter->handle = *adapter_handle;
3462
3463 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003464 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003465 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 ret = -ENODEV;
3467 goto out_free_ad;
3468 }
3469
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003470 adapter->pd = EHEA_PD_ID;
3471
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003472 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003474
3475 /* initialize adapter and ports */
3476 /* get adapter properties */
3477 ret = ehea_sense_adapter_attr(adapter);
3478 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003479 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003480 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003481 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003482
3483 adapter->neq = ehea_create_eq(adapter,
3484 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3485 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003486 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003487 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003488 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003489 }
3490
3491 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3492 (unsigned long)adapter);
3493
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003494 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003495 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496 "ehea_neq", adapter);
3497 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003498 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499 goto out_kill_eq;
3500 }
3501
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003502 ret = ehea_create_device_sysfs(dev);
3503 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003504 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003505
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 ret = ehea_setup_ports(adapter);
3507 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003508 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003509 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003510 }
3511
3512 ret = 0;
3513 goto out;
3514
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003515out_rem_dev_sysfs:
3516 ehea_remove_device_sysfs(dev);
3517
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003518out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003519 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003520
3521out_kill_eq:
3522 ehea_destroy_eq(adapter->neq);
3523
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003524out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003525 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003526 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003528out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003529 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 return ret;
3532}
3533
Grant Likely2dc11582010-08-06 09:25:50 -06003534static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003536 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003537 int i;
3538
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003539 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540 if (adapter->port[i]) {
3541 ehea_shutdown_single_port(adapter->port[i]);
3542 adapter->port[i] = NULL;
3543 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003544
3545 ehea_remove_device_sysfs(dev);
3546
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003547 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003548 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003549
3550 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003551 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003552 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003554
Thomas Klein21eee2d2008-02-13 16:18:33 +01003555 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003556
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 return 0;
3558}
3559
Thomas Klein21eee2d2008-02-13 16:18:33 +01003560void ehea_crash_handler(void)
3561{
3562 int i;
3563
3564 if (ehea_fw_handles.arr)
3565 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3566 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3567 ehea_fw_handles.arr[i].fwh,
3568 FORCE_FREE);
3569
3570 if (ehea_bcmc_regs.arr)
3571 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3572 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3573 ehea_bcmc_regs.arr[i].port_id,
3574 ehea_bcmc_regs.arr[i].reg_type,
3575 ehea_bcmc_regs.arr[i].macaddr,
3576 0, H_DEREG_BCMC);
3577}
3578
Hannes Hering48cfb142008-05-07 14:43:36 +02003579static int ehea_mem_notifier(struct notifier_block *nb,
3580 unsigned long action, void *data)
3581{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003582 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003583 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003584
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003585 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003586
Hannes Hering48cfb142008-05-07 14:43:36 +02003587 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003588 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003589 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003590 /* Readd canceled memory block */
3591 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003592 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003593 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003594 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003595 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003596 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003597 break;
3598 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003599 pr_info("memory is going offline");
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_rem_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 Hering48cfb142008-05-07 14:43:36 +02003604 break;
3605 default:
3606 break;
3607 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003608
3609 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003610 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003611
Thomas Kleina7c561f22010-04-20 23:11:31 +00003612out_unlock:
3613 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003614 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003615}
3616
3617static struct notifier_block ehea_mem_nb = {
3618 .notifier_call = ehea_mem_notifier,
3619};
3620
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003621static int ehea_reboot_notifier(struct notifier_block *nb,
3622 unsigned long action, void *unused)
3623{
3624 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003625 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003626 ibmebus_unregister_driver(&ehea_driver);
3627 }
3628 return NOTIFY_DONE;
3629}
3630
3631static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003632 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003633};
3634
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003635static int check_module_parm(void)
3636{
3637 int ret = 0;
3638
3639 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3640 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003641 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003642 ret = -EINVAL;
3643 }
3644 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3645 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003646 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003647 ret = -EINVAL;
3648 }
3649 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3650 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003651 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003652 ret = -EINVAL;
3653 }
3654 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3655 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003656 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003657 ret = -EINVAL;
3658 }
3659
3660 return ret;
3661}
3662
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003663static ssize_t ehea_show_capabilities(struct device_driver *drv,
3664 char *buf)
3665{
3666 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3667}
3668
3669static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3670 ehea_show_capabilities, NULL);
3671
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003672int __init ehea_module_init(void)
3673{
3674 int ret;
3675
Joe Perches8c4877a2010-12-13 10:05:14 -08003676 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003677
Thomas Klein21eee2d2008-02-13 16:18:33 +01003678 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3679 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3680
Daniel Walker9f71a562008-03-28 14:41:26 -07003681 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003682 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003683
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003684 ret = check_module_parm();
3685 if (ret)
3686 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003687
3688 ret = ehea_create_busmap();
3689 if (ret)
3690 goto out;
3691
Thomas Klein21eee2d2008-02-13 16:18:33 +01003692 ret = register_reboot_notifier(&ehea_reboot_nb);
3693 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003694 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003695
Hannes Hering48cfb142008-05-07 14:43:36 +02003696 ret = register_memory_notifier(&ehea_mem_nb);
3697 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003698 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003699
Joe Perchesc061b182010-08-23 18:20:03 +00003700 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003701 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003702 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003703
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003704 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003705 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003706 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003707 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003708 }
3709
3710 ret = driver_create_file(&ehea_driver.driver,
3711 &driver_attr_capabilities);
3712 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003713 pr_err("failed to register capabilities attribute, ret=%d\n",
3714 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003715 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003716 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003717
Thomas Klein21eee2d2008-02-13 16:18:33 +01003718 return ret;
3719
3720out3:
3721 ibmebus_unregister_driver(&ehea_driver);
3722out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003723 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003724 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003725 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003726out:
3727 return ret;
3728}
3729
3730static void __exit ehea_module_exit(void)
3731{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003732 int ret;
3733
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003734 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003735 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003736 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003737 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003738 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003739 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003740 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003741 kfree(ehea_fw_handles.arr);
3742 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003743 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003744}
3745
3746module_init(ehea_module_init);
3747module_exit(ehea_module_exit);