blob: f700c76d3e603a5af1a27468c357a4abbb399eb4 [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 Perches539995d2010-11-30 08:18:44 +000029#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>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020044
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020045#include <net/ip.h>
46
47#include "ehea.h"
48#include "ehea_qmr.h"
49#include "ehea_phyp.h"
50
51
52MODULE_LICENSE("GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HEA Driver");
55MODULE_VERSION(DRV_VERSION);
56
57
58static int msg_level = -1;
59static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
60static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
61static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
62static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060063static int use_mcs;
64static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070065static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010066static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060067static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020068
69module_param(msg_level, int, 0);
70module_param(rq1_entries, int, 0);
71module_param(rq2_entries, int, 0);
72module_param(rq3_entries, int, 0);
73module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020074module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070076module_param(use_lro, int, 0);
77module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010078module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010080MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020082MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
83 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020084MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
87MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
90MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
93MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
94 "[2^x - 1], x = [6..14]. Default = "
95 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020096MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020097
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070098MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
99 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
100MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
101 "Default = 0");
102
Doug Maxey508d2b52008-01-31 20:20:49 -0600103static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200104static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800105static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200106struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700107static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100108struct ehea_fw_handle_array ehea_fw_handles;
109struct ehea_bcmc_reg_array ehea_bcmc_regs;
110
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Grant Likely2dc11582010-08-06 09:25:50 -0600112static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200113 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Grant Likely2dc11582010-08-06 09:25:50 -0600115static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200116
117static struct of_device_id ehea_device_table[] = {
118 {
119 .name = "lhea",
120 .compatible = "IBM,lhea",
121 },
122 {},
123};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100124MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200125
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000126static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700127 .driver = {
128 .name = "ehea",
129 .owner = THIS_MODULE,
130 .of_match_table = ehea_device_table,
131 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200132 .probe = ehea_probe_adapter,
133 .remove = ehea_remove,
134};
135
Doug Maxey508d2b52008-01-31 20:20:49 -0600136void ehea_dump(void *adr, int len, char *msg)
137{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200138 int x;
139 unsigned char *deb = adr;
140 for (x = 0; x < len; x += 16) {
Joe Perches539995d2010-11-30 08:18:44 +0000141 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
142 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200143 deb += 16;
144 }
145}
146
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100147void ehea_schedule_port_reset(struct ehea_port *port)
148{
149 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
150 schedule_work(&port->reset_task);
151}
152
Thomas Klein21eee2d2008-02-13 16:18:33 +0100153static void ehea_update_firmware_handles(void)
154{
155 struct ehea_fw_handle_entry *arr = NULL;
156 struct ehea_adapter *adapter;
157 int num_adapters = 0;
158 int num_ports = 0;
159 int num_portres = 0;
160 int i = 0;
161 int num_fw_handles, k, l;
162
163 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700164 mutex_lock(&ehea_fw_handles.lock);
165
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 list_for_each_entry(adapter, &adapter_list, list) {
167 num_adapters++;
168
169 for (k = 0; k < EHEA_MAX_PORTS; k++) {
170 struct ehea_port *port = adapter->port[k];
171
172 if (!port || (port->state != EHEA_PORT_UP))
173 continue;
174
175 num_ports++;
176 num_portres += port->num_def_qps + port->num_add_tx_qps;
177 }
178 }
179
180 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
181 num_ports * EHEA_NUM_PORT_FW_HANDLES +
182 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
183
184 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000185 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700187 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100188 } else
189 goto out_update;
190
191 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700192 if (num_adapters == 0)
193 break;
194
Thomas Klein21eee2d2008-02-13 16:18:33 +0100195 for (k = 0; k < EHEA_MAX_PORTS; k++) {
196 struct ehea_port *port = adapter->port[k];
197
Joe Perches8e95a202009-12-03 07:58:21 +0000198 if (!port || (port->state != EHEA_PORT_UP) ||
199 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100200 continue;
201
202 for (l = 0;
203 l < port->num_def_qps + port->num_add_tx_qps;
204 l++) {
205 struct ehea_port_res *pr = &port->port_res[l];
206
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->qp->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->send_cq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->recv_cq->fw_handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->eq->fw_handle;
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = pr->send_mr.handle;
217 arr[i].adh = adapter->handle;
218 arr[i++].fwh = pr->recv_mr.handle;
219 }
220 arr[i].adh = adapter->handle;
221 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700222 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100223 }
224
225 arr[i].adh = adapter->handle;
226 arr[i++].fwh = adapter->neq->fw_handle;
227
228 if (adapter->mr.handle) {
229 arr[i].adh = adapter->handle;
230 arr[i++].fwh = adapter->mr.handle;
231 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 }
234
235out_update:
236 kfree(ehea_fw_handles.arr);
237 ehea_fw_handles.arr = arr;
238 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700239out:
240 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100241}
242
243static void ehea_update_bcmc_registrations(void)
244{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700245 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100246 struct ehea_bcmc_reg_entry *arr = NULL;
247 struct ehea_adapter *adapter;
248 struct ehea_mc_list *mc_entry;
249 int num_registrations = 0;
250 int i = 0;
251 int k;
252
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700253 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
254
Thomas Klein21eee2d2008-02-13 16:18:33 +0100255 /* Determine number of registrations */
256 list_for_each_entry(adapter, &adapter_list, list)
257 for (k = 0; k < EHEA_MAX_PORTS; k++) {
258 struct ehea_port *port = adapter->port[k];
259
260 if (!port || (port->state != EHEA_PORT_UP))
261 continue;
262
263 num_registrations += 2; /* Broadcast registrations */
264
265 list_for_each_entry(mc_entry, &port->mc_list->list,list)
266 num_registrations += 2;
267 }
268
269 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000270 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100271 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700272 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 } else
274 goto out_update;
275
276 list_for_each_entry(adapter, &adapter_list, list) {
277 for (k = 0; k < EHEA_MAX_PORTS; k++) {
278 struct ehea_port *port = adapter->port[k];
279
280 if (!port || (port->state != EHEA_PORT_UP))
281 continue;
282
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700283 if (num_registrations == 0)
284 goto out_update;
285
Thomas Klein21eee2d2008-02-13 16:18:33 +0100286 arr[i].adh = adapter->handle;
287 arr[i].port_id = port->logical_port_id;
288 arr[i].reg_type = EHEA_BCMC_BROADCAST |
289 EHEA_BCMC_UNTAGGED;
290 arr[i++].macaddr = port->mac_addr;
291
292 arr[i].adh = adapter->handle;
293 arr[i].port_id = port->logical_port_id;
294 arr[i].reg_type = EHEA_BCMC_BROADCAST |
295 EHEA_BCMC_VLANID_ALL;
296 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700297 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100298
299 list_for_each_entry(mc_entry,
300 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700301 if (num_registrations == 0)
302 goto out_update;
303
Thomas Klein21eee2d2008-02-13 16:18:33 +0100304 arr[i].adh = adapter->handle;
305 arr[i].port_id = port->logical_port_id;
306 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
307 EHEA_BCMC_MULTICAST |
308 EHEA_BCMC_UNTAGGED;
309 arr[i++].macaddr = mc_entry->macaddr;
310
311 arr[i].adh = adapter->handle;
312 arr[i].port_id = port->logical_port_id;
313 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
314 EHEA_BCMC_MULTICAST |
315 EHEA_BCMC_VLANID_ALL;
316 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700317 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100318 }
319 }
320 }
321
322out_update:
323 kfree(ehea_bcmc_regs.arr);
324 ehea_bcmc_regs.arr = arr;
325 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700326out:
327 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100328}
329
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200330static struct net_device_stats *ehea_get_stats(struct net_device *dev)
331{
332 struct ehea_port *port = netdev_priv(dev);
333 struct net_device_stats *stats = &port->stats;
334 struct hcp_ehea_port_cb2 *cb2;
Breno Leitaoce45b872010-10-27 08:45:14 +0000335 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 int i;
337
338 memset(stats, 0, sizeof(*stats));
339
Brian King3d8009c2010-06-30 11:59:12 +0000340 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200341 if (!cb2) {
Joe Perches539995d2010-11-30 08:18:44 +0000342 netdev_err(dev, "no mem for cb2\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200343 goto out;
344 }
345
346 hret = ehea_h_query_ehea_port(port->adapter->handle,
347 port->logical_port_id,
348 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
349 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +0000350 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200351 goto out_herr;
352 }
353
354 if (netif_msg_hw(port))
355 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
356
357 rx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000358 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 rx_packets += port->port_res[i].rx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000360 rx_bytes += port->port_res[i].rx_bytes;
361 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200362
Thomas Klein7393b872007-11-21 17:37:58 +0100363 tx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000364 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Thomas Klein7393b872007-11-21 17:37:58 +0100365 tx_packets += port->port_res[i].tx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000366 tx_bytes += port->port_res[i].tx_bytes;
367 }
Thomas Klein7393b872007-11-21 17:37:58 +0100368
369 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370 stats->multicast = cb2->rxmcp;
371 stats->rx_errors = cb2->rxuerr;
Breno Leitaoce45b872010-10-27 08:45:14 +0000372 stats->rx_bytes = rx_bytes;
373 stats->tx_bytes = tx_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374 stats->rx_packets = rx_packets;
375
376out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800377 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200378out:
379 return stats;
380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200406 break;
407 }
408 }
409 index--;
410 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200411 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200413
414 if (adder == 0)
415 return;
416
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200419}
420
Thomas Kleine2878802009-01-21 14:45:57 -0800421static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
424 struct net_device *dev = pr->port->netdev;
425 int i;
426
427 for (i = 0; i < pr->rq1_skba.len; i++) {
428 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800429 if (!skb_arr_rq1[i])
430 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431 }
432 /* Ring doorbell */
433 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434}
435
436static int ehea_refill_rq_def(struct ehea_port_res *pr,
437 struct ehea_q_skb_arr *q_skba, int rq_nr,
438 int num_wqes, int wqe_type, int packet_size)
439{
440 struct net_device *dev = pr->port->netdev;
441 struct ehea_qp *qp = pr->qp;
442 struct sk_buff **skb_arr = q_skba->arr;
443 struct ehea_rwqe *rwqe;
444 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200445 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200446 int ret = 0;
447
448 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200449 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200451 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
452 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200454 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200455
456 index = q_skba->index;
457 max_index_mask = q_skba->len - 1;
458 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000460 struct sk_buff *skb;
461
462 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200464 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800465 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches539995d2010-11-30 08:18:44 +0000466 netdev_info(pr->port->netdev,
467 "rq%i ran dry - no mem for skb\n",
468 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800469 ret = -ENOMEM;
470 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471 break;
472 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200473
474 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200475 tmp_addr = ehea_map_vaddr(skb->data);
476 if (tmp_addr == -1) {
477 dev_kfree_skb(skb);
478 q_skba->os_skbs = fill_wqes - i;
479 ret = 0;
480 break;
481 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200482
483 rwqe = ehea_get_next_rwqe(qp, rq_nr);
484 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200485 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200486 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200487 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200488 rwqe->sg_list[0].len = packet_size;
489 rwqe->data_segments = 1;
490
491 index++;
492 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200493 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 }
Thomas Klein44c82152007-07-11 16:32:00 +0200495
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200497 if (adder == 0)
498 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499
500 /* Ring doorbell */
501 iosync();
502 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200503 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200505 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200506out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200507 return ret;
508}
509
510
511static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
512{
513 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
514 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000515 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200516}
517
518
519static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
520{
521 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
522 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000523 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524}
525
526static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
527{
528 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
529 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
530 return 0;
531 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
532 (cqe->header_length == 0))
533 return 0;
534 return -EINVAL;
535}
536
537static inline void ehea_fill_skb(struct net_device *dev,
538 struct sk_buff *skb, struct ehea_cqe *cqe)
539{
540 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
541
542 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200543 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000544
545 /* The packet was not an IPV4 packet so a complemented checksum was
546 calculated. The value is found in the Internet Checksum field. */
547 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
548 skb->ip_summed = CHECKSUM_COMPLETE;
549 skb->csum = csum_unfold(~cqe->inet_checksum_value);
550 } else
551 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200552}
553
554static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
555 int arr_len,
556 struct ehea_cqe *cqe)
557{
558 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
559 struct sk_buff *skb;
560 void *pref;
561 int x;
562
563 x = skb_index + 1;
564 x &= (arr_len - 1);
565
566 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700567 if (pref) {
568 prefetchw(pref);
569 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200570
Hannes Hering0b2febf2009-05-04 11:06:37 -0700571 pref = (skb_array[x]->data);
572 prefetch(pref);
573 prefetch(pref + EHEA_CACHE_LINE);
574 prefetch(pref + EHEA_CACHE_LINE * 2);
575 prefetch(pref + EHEA_CACHE_LINE * 3);
576 }
577
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578 skb = skb_array[skb_index];
579 skb_array[skb_index] = NULL;
580 return skb;
581}
582
583static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
584 int arr_len, int wqe_index)
585{
586 struct sk_buff *skb;
587 void *pref;
588 int x;
589
590 x = wqe_index + 1;
591 x &= (arr_len - 1);
592
593 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700594 if (pref) {
595 prefetchw(pref);
596 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200597
Hannes Hering0b2febf2009-05-04 11:06:37 -0700598 pref = (skb_array[x]->data);
599 prefetchw(pref);
600 prefetchw(pref + EHEA_CACHE_LINE);
601 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200602
603 skb = skb_array[wqe_index];
604 skb_array[wqe_index] = NULL;
605 return skb;
606}
607
608static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
609 struct ehea_cqe *cqe, int *processed_rq2,
610 int *processed_rq3)
611{
612 struct sk_buff *skb;
613
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100614 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
615 pr->p_stats.err_tcp_cksum++;
616 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
617 pr->p_stats.err_ip_cksum++;
618 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
619 pr->p_stats.err_frame_crc++;
620
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200621 if (rq == 2) {
622 *processed_rq2 += 1;
623 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
624 dev_kfree_skb(skb);
625 } else if (rq == 3) {
626 *processed_rq3 += 1;
627 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
628 dev_kfree_skb(skb);
629 }
630
631 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100632 if (netif_msg_rx_err(pr->port)) {
Joe Perches539995d2010-11-30 08:18:44 +0000633 pr_err("Critical receive error for QP %d. Resetting port.\n",
634 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100635 ehea_dump(cqe, sizeof(*cqe), "CQE");
636 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100637 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200638 return 1;
639 }
640
641 return 0;
642}
643
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700644static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
645 void **tcph, u64 *hdr_flags, void *priv)
646{
647 struct ehea_cqe *cqe = priv;
648 unsigned int ip_len;
649 struct iphdr *iph;
650
651 /* non tcp/udp packets */
652 if (!cqe->header_length)
653 return -1;
654
655 /* non tcp packet */
656 skb_reset_network_header(skb);
657 iph = ip_hdr(skb);
658 if (iph->protocol != IPPROTO_TCP)
659 return -1;
660
661 ip_len = ip_hdrlen(skb);
662 skb_set_transport_header(skb, ip_len);
663 *tcph = tcp_hdr(skb);
664
665 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700666 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700667 return -1;
668
669 *hdr_flags = LRO_IPV4 | LRO_TCP;
670 *iphdr = iph;
671
672 return 0;
673}
674
675static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
676 struct sk_buff *skb)
677{
Joe Perches8e95a202009-12-03 07:58:21 +0000678 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
679 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700680
681 if (use_lro) {
682 if (vlan_extracted)
683 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
684 pr->port->vgrp,
685 cqe->vlan_tag,
686 cqe);
687 else
688 lro_receive_skb(&pr->lro_mgr, skb, cqe);
689 } else {
690 if (vlan_extracted)
691 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
692 cqe->vlan_tag);
693 else
694 netif_receive_skb(skb);
695 }
696}
697
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700698static int ehea_proc_rwqes(struct net_device *dev,
699 struct ehea_port_res *pr,
700 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200701{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100702 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200703 struct ehea_qp *qp = pr->qp;
704 struct ehea_cqe *cqe;
705 struct sk_buff *skb;
706 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
707 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
708 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
709 int skb_arr_rq1_len = pr->rq1_skba.len;
710 int skb_arr_rq2_len = pr->rq2_skba.len;
711 int skb_arr_rq3_len = pr->rq3_skba.len;
712 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000713 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700714 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200715
716 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
717 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200718
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700720 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200721 ehea_inc_rq1(qp);
722 processed_rq1++;
723 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 if (netif_msg_rx_status(port))
725 ehea_dump(cqe, sizeof(*cqe), "CQE");
726
727 last_wqe_index = wqe_index;
728 rmb();
729 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600730 if (rq == 1) {
731 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200732 skb = get_skb_by_index_ll(skb_arr_rq1,
733 skb_arr_rq1_len,
734 wqe_index);
735 if (unlikely(!skb)) {
Joe Perches539995d2010-11-30 08:18:44 +0000736 netif_err(port, rx_err, dev,
737 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100738
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700739 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200740 EHEA_L_PKT_SIZE);
741 if (!skb)
742 break;
743 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600744 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200745 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700746 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600747 } else if (rq == 2) {
748 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 skb = get_skb_by_index(skb_arr_rq2,
750 skb_arr_rq2_len, cqe);
751 if (unlikely(!skb)) {
Joe Perches539995d2010-11-30 08:18:44 +0000752 netif_err(port, rx_err, dev,
753 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 break;
755 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700756 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200757 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600758 } else {
759 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 skb = get_skb_by_index(skb_arr_rq3,
761 skb_arr_rq3_len, cqe);
762 if (unlikely(!skb)) {
Joe Perches539995d2010-11-30 08:18:44 +0000763 netif_err(port, rx_err, dev,
764 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200765 break;
766 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700767 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200768 processed_rq3++;
769 }
770
Breno Leitaoce45b872010-10-27 08:45:14 +0000771 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700772 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100773 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100774 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200775 port_reset = ehea_treat_poll_error(pr, rq, cqe,
776 &processed_rq2,
777 &processed_rq3);
778 if (port_reset)
779 break;
780 }
781 cqe = ehea_poll_rq1(qp, &wqe_index);
782 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700783 if (use_lro)
784 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200785
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200786 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000787 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200788
789 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
790 ehea_refill_rq2(pr, processed_rq2);
791 ehea_refill_rq3(pr, processed_rq3);
792
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700793 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200794}
795
Andre Detsch2928db42010-08-17 05:49:12 +0000796#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
797
798static void reset_sq_restart_flag(struct ehea_port *port)
799{
800 int i;
801
802 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
803 struct ehea_port_res *pr = &port->port_res[i];
804 pr->sq_restart_flag = 0;
805 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000806 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000807}
808
809static void check_sqs(struct ehea_port *port)
810{
811 struct ehea_swqe *swqe;
812 int swqe_index;
813 int i, k;
814
815 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
816 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000817 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000818 k = 0;
819 swqe = ehea_get_swqe(pr->qp, &swqe_index);
820 memset(swqe, 0, SWQE_HEADER_SIZE);
821 atomic_dec(&pr->swqe_avail);
822
823 swqe->tx_control |= EHEA_SWQE_PURGE;
824 swqe->wr_id = SWQE_RESTART_CHECK;
825 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
826 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
827 swqe->immediate_data_length = 80;
828
829 ehea_post_swqe(pr->qp, swqe);
830
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000831 ret = wait_event_timeout(port->restart_wq,
832 pr->sq_restart_flag == 0,
833 msecs_to_jiffies(100));
834
835 if (!ret) {
Joe Perches539995d2010-11-30 08:18:44 +0000836 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000837 ehea_schedule_port_reset(pr->port);
838 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000839 }
840 }
Andre Detsch2928db42010-08-17 05:49:12 +0000841}
842
843
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100844static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200845{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100846 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200847 struct ehea_cq *send_cq = pr->send_cq;
848 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100849 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200850 int cqe_counter = 0;
851 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100852 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200853 unsigned long flags;
854
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600856 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100857 ehea_inc_cq(send_cq);
858
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200859 cqe_counter++;
860 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000861
862 if (cqe->wr_id == SWQE_RESTART_CHECK) {
863 pr->sq_restart_flag = 1;
864 swqe_av++;
865 break;
866 }
867
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches539995d2010-11-30 08:18:44 +0000869 pr_err("Bad send completion status=0x%04X\n",
870 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000871
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200872 if (netif_msg_tx_err(pr->port))
873 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000874
875 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches539995d2010-11-30 08:18:44 +0000876 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000877 ehea_schedule_port_reset(pr->port);
878 break;
879 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200880 }
881
882 if (netif_msg_tx_done(pr->port))
883 ehea_dump(cqe, sizeof(*cqe), "CQE");
884
885 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100886 == EHEA_SWQE2_TYPE)) {
887
888 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
889 skb = pr->sq_skba.arr[index];
890 dev_kfree_skb(skb);
891 pr->sq_skba.arr[index] = NULL;
892 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200893
894 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
895 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100896
897 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700898 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200899
900 ehea_update_feca(send_cq, cqe_counter);
901 atomic_add(swqe_av, &pr->swqe_avail);
902
903 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100904
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200905 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
906 >= pr->swqe_refill_th)) {
907 netif_wake_queue(pr->port->netdev);
908 pr->queue_stopped = 0;
909 }
910 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000911 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200912
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100913 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200914}
915
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100916#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700917#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100918
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700919static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200920{
Doug Maxey508d2b52008-01-31 20:20:49 -0600921 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
922 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700923 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100924 struct ehea_cqe *cqe;
925 struct ehea_cqe *cqe_skb = NULL;
926 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700927 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100928
929 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700932 if (!force_irq)
933 rx += ehea_proc_rwqes(dev, pr, budget - rx);
934
935 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100936 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700937 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800938 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100939 ehea_reset_cq_ep(pr->recv_cq);
940 ehea_reset_cq_ep(pr->send_cq);
941 ehea_reset_cq_n1(pr->recv_cq);
942 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000943 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100944 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
945 cqe_skb = ehea_poll_cq(pr->send_cq);
946
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100947 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700948 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100949
Ben Hutchings288379f2009-01-19 16:43:59 -0800950 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700951 return rx;
952
953 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
954 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100955 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100956
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700957 pr->poll_counter++;
958 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200959}
960
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200961#ifdef CONFIG_NET_POLL_CONTROLLER
962static void ehea_netpoll(struct net_device *dev)
963{
964 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700965 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200966
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700967 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800968 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200969}
970#endif
971
David Howells7d12e782006-10-05 14:55:46 +0100972static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973{
974 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100975
Ben Hutchings288379f2009-01-19 16:43:59 -0800976 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100977
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200978 return IRQ_HANDLED;
979}
980
David Howells7d12e782006-10-05 14:55:46 +0100981static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200982{
983 struct ehea_port *port = param;
984 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100985 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200986 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000987 u64 resource_type, aer, aerr;
988 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200989
990 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100991
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches539995d2010-11-30 08:18:44 +0000994 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
995 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100996
997 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000998
999 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1000 &aer, &aerr);
1001
1002 if (resource_type == EHEA_AER_RESTYPE_QP) {
1003 if ((aer & EHEA_AER_RESET_MASK) ||
1004 (aerr & EHEA_AERR_RESET_MASK))
1005 reset_port = 1;
1006 } else
1007 reset_port = 1; /* Reset in case of CQ or EQ error */
1008
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001009 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001010 }
1011
Thomas Kleinea96cea2010-04-20 23:10:55 +00001012 if (reset_port) {
Joe Perches539995d2010-11-30 08:18:44 +00001013 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001014 ehea_schedule_port_reset(port);
1015 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001016
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001017 return IRQ_HANDLED;
1018}
1019
1020static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1021 int logical_port)
1022{
1023 int i;
1024
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001025 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001026 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001027 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001028 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001029 return NULL;
1030}
1031
1032int ehea_sense_port_attr(struct ehea_port *port)
1033{
1034 int ret;
1035 u64 hret;
1036 struct hcp_ehea_port_cb0 *cb0;
1037
Doug Maxey508d2b52008-01-31 20:20:49 -06001038 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001039 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001040 if (!cb0) {
Joe Perches539995d2010-11-30 08:18:44 +00001041 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001042 ret = -ENOMEM;
1043 goto out;
1044 }
1045
1046 hret = ehea_h_query_ehea_port(port->adapter->handle,
1047 port->logical_port_id, H_PORT_CB0,
1048 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1049 cb0);
1050 if (hret != H_SUCCESS) {
1051 ret = -EIO;
1052 goto out_free;
1053 }
1054
1055 /* MAC address */
1056 port->mac_addr = cb0->port_mac_addr << 16;
1057
Doug Maxey508d2b52008-01-31 20:20:49 -06001058 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001059 ret = -EADDRNOTAVAIL;
1060 goto out_free;
1061 }
1062
1063 /* Port speed */
1064 switch (cb0->port_speed) {
1065 case H_SPEED_10M_H:
1066 port->port_speed = EHEA_SPEED_10M;
1067 port->full_duplex = 0;
1068 break;
1069 case H_SPEED_10M_F:
1070 port->port_speed = EHEA_SPEED_10M;
1071 port->full_duplex = 1;
1072 break;
1073 case H_SPEED_100M_H:
1074 port->port_speed = EHEA_SPEED_100M;
1075 port->full_duplex = 0;
1076 break;
1077 case H_SPEED_100M_F:
1078 port->port_speed = EHEA_SPEED_100M;
1079 port->full_duplex = 1;
1080 break;
1081 case H_SPEED_1G_F:
1082 port->port_speed = EHEA_SPEED_1G;
1083 port->full_duplex = 1;
1084 break;
1085 case H_SPEED_10G_F:
1086 port->port_speed = EHEA_SPEED_10G;
1087 port->full_duplex = 1;
1088 break;
1089 default:
1090 port->port_speed = 0;
1091 port->full_duplex = 0;
1092 break;
1093 }
1094
Thomas Kleine919b592007-01-22 12:53:20 +01001095 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001096 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001097
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001098 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001099 if (use_mcs)
1100 port->num_def_qps = cb0->num_default_qps;
1101 else
1102 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001103
1104 if (!port->num_def_qps) {
1105 ret = -EINVAL;
1106 goto out_free;
1107 }
1108
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001109 port->num_tx_qps = num_tx_qps;
1110
1111 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001112 port->num_add_tx_qps = 0;
1113 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001114 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001115
1116 ret = 0;
1117out_free:
1118 if (ret || netif_msg_probe(port))
1119 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001120 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001121out:
1122 return ret;
1123}
1124
1125int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1126{
1127 struct hcp_ehea_port_cb4 *cb4;
1128 u64 hret;
1129 int ret = 0;
1130
Thomas Klein3faf2692009-01-21 14:45:33 -08001131 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001132 if (!cb4) {
Joe Perches539995d2010-11-30 08:18:44 +00001133 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 ret = -ENOMEM;
1135 goto out;
1136 }
1137
1138 cb4->port_speed = port_speed;
1139
1140 netif_carrier_off(port->netdev);
1141
1142 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1143 port->logical_port_id,
1144 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1145 if (hret == H_SUCCESS) {
1146 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1147
1148 hret = ehea_h_query_ehea_port(port->adapter->handle,
1149 port->logical_port_id,
1150 H_PORT_CB4, H_PORT_CB4_SPEED,
1151 cb4);
1152 if (hret == H_SUCCESS) {
1153 switch (cb4->port_speed) {
1154 case H_SPEED_10M_H:
1155 port->port_speed = EHEA_SPEED_10M;
1156 port->full_duplex = 0;
1157 break;
1158 case H_SPEED_10M_F:
1159 port->port_speed = EHEA_SPEED_10M;
1160 port->full_duplex = 1;
1161 break;
1162 case H_SPEED_100M_H:
1163 port->port_speed = EHEA_SPEED_100M;
1164 port->full_duplex = 0;
1165 break;
1166 case H_SPEED_100M_F:
1167 port->port_speed = EHEA_SPEED_100M;
1168 port->full_duplex = 1;
1169 break;
1170 case H_SPEED_1G_F:
1171 port->port_speed = EHEA_SPEED_1G;
1172 port->full_duplex = 1;
1173 break;
1174 case H_SPEED_10G_F:
1175 port->port_speed = EHEA_SPEED_10G;
1176 port->full_duplex = 1;
1177 break;
1178 default:
1179 port->port_speed = 0;
1180 port->full_duplex = 0;
1181 break;
1182 }
1183 } else {
Joe Perches539995d2010-11-30 08:18:44 +00001184 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185 ret = -EIO;
1186 }
1187 } else {
1188 if (hret == H_AUTHORITY) {
Joe Perches539995d2010-11-30 08:18:44 +00001189 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001190 ret = -EPERM;
1191 } else {
1192 ret = -EIO;
Joe Perches539995d2010-11-30 08:18:44 +00001193 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001194 }
1195 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001196 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1197 netif_carrier_on(port->netdev);
1198
Thomas Klein3faf2692009-01-21 14:45:33 -08001199 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200out:
1201 return ret;
1202}
1203
1204static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1205{
1206 int ret;
1207 u8 ec;
1208 u8 portnum;
1209 struct ehea_port *port;
Joe Perches539995d2010-11-30 08:18:44 +00001210 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211
1212 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1213 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1214 port = ehea_get_port(adapter, portnum);
Joe Perches539995d2010-11-30 08:18:44 +00001215 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216
1217 switch (ec) {
1218 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1219
1220 if (!port) {
Joe Perches539995d2010-11-30 08:18:44 +00001221 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222 break;
1223 }
1224
1225 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches539995d2010-11-30 08:18:44 +00001226 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001227 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001228 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00001229 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001230 break;
1231 }
1232
Joe Perches539995d2010-11-30 08:18:44 +00001233 netif_info(port, link, dev,
1234 "Logical port up: %dMbps %s Duplex\n",
1235 port->port_speed,
1236 port->full_duplex == 1 ?
1237 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238
Joe Perches539995d2010-11-30 08:18:44 +00001239 netif_carrier_on(dev);
1240 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 }
1242 } else
Joe Perches539995d2010-11-30 08:18:44 +00001243 if (netif_carrier_ok(dev)) {
1244 netif_info(port, link, dev,
1245 "Logical port down\n");
1246 netif_carrier_off(dev);
1247 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248 }
1249
1250 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001251 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches539995d2010-11-30 08:18:44 +00001252 netif_info(port, link, dev,
1253 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001254 if (prop_carrier_state)
Joe Perches539995d2010-11-30 08:18:44 +00001255 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001257 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches539995d2010-11-30 08:18:44 +00001258 netif_info(port, link, dev,
1259 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001260 if (prop_carrier_state)
Joe Perches539995d2010-11-30 08:18:44 +00001261 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001262 }
1263
1264 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches539995d2010-11-30 08:18:44 +00001265 netdev_info(dev,
1266 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001267 else
Joe Perches539995d2010-11-30 08:18:44 +00001268 netdev_info(dev,
1269 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001270
1271 break;
1272 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches539995d2010-11-30 08:18:44 +00001273 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001274 break;
1275 case EHEA_EC_PORT_MALFUNC:
Joe Perches539995d2010-11-30 08:18:44 +00001276 netdev_info(dev, "Port malfunction\n");
1277 netif_carrier_off(dev);
1278 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001279 break;
1280 default:
Joe Perches539995d2010-11-30 08:18:44 +00001281 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001282 break;
1283 }
1284}
1285
1286static void ehea_neq_tasklet(unsigned long data)
1287{
Doug Maxey508d2b52008-01-31 20:20:49 -06001288 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001289 struct ehea_eqe *eqe;
1290 u64 event_mask;
1291
1292 eqe = ehea_poll_eq(adapter->neq);
Joe Perches539995d2010-11-30 08:18:44 +00001293 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294
1295 while (eqe) {
Joe Perches539995d2010-11-30 08:18:44 +00001296 pr_debug("*eqe=%lx\n", eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001297 ehea_parse_eqe(adapter, eqe->entry);
1298 eqe = ehea_poll_eq(adapter->neq);
Joe Perches539995d2010-11-30 08:18:44 +00001299 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300 }
1301
1302 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1303 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1304 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1305
1306 ehea_h_reset_events(adapter->handle,
1307 adapter->neq->fw_handle, event_mask);
1308}
1309
David Howells7d12e782006-10-05 14:55:46 +01001310static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001311{
1312 struct ehea_adapter *adapter = param;
1313 tasklet_hi_schedule(&adapter->neq_tasklet);
1314 return IRQ_HANDLED;
1315}
1316
1317
1318static int ehea_fill_port_res(struct ehea_port_res *pr)
1319{
1320 int ret;
1321 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1322
Thomas Kleine2878802009-01-21 14:45:57 -08001323 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1324 - init_attr->act_nr_rwqes_rq2
1325 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326
Thomas Kleine2878802009-01-21 14:45:57 -08001327 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328
1329 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1330
1331 return ret;
1332}
1333
1334static int ehea_reg_interrupts(struct net_device *dev)
1335{
1336 struct ehea_port *port = netdev_priv(dev);
1337 struct ehea_port_res *pr;
1338 int i, ret;
1339
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001340
1341 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1342 dev->name);
1343
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001344 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001346 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00001348 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1349 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 goto out_free_qpeq;
1351 }
1352
Joe Perches539995d2010-11-30 08:18:44 +00001353 netif_info(port, ifup, dev,
1354 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1355 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001357
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1359 pr = &port->port_res[i];
1360 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001361 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001362 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001363 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001364 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001365 pr);
1366 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00001367 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1368 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 goto out_free_req;
1370 }
Joe Perches539995d2010-11-30 08:18:44 +00001371 netif_info(port, ifup, dev,
1372 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1373 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 }
1375out:
1376 return ret;
1377
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379out_free_req:
1380 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001381 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001382 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001384
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001385out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001386 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001389 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001390
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391}
1392
1393static void ehea_free_interrupts(struct net_device *dev)
1394{
1395 struct ehea_port *port = netdev_priv(dev);
1396 struct ehea_port_res *pr;
1397 int i;
1398
1399 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001400
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001401 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1402 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001403 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches539995d2010-11-30 08:18:44 +00001404 netif_info(port, intr, dev,
1405 "free send irq for res %d with handle 0x%X\n",
1406 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407 }
1408
1409 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001410 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches539995d2010-11-30 08:18:44 +00001411 netif_info(port, intr, dev,
1412 "associated event interrupt for handle 0x%X freed\n",
1413 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414}
1415
1416static int ehea_configure_port(struct ehea_port *port)
1417{
1418 int ret, i;
1419 u64 hret, mask;
1420 struct hcp_ehea_port_cb0 *cb0;
1421
1422 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001423 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424 if (!cb0)
1425 goto out;
1426
1427 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1428 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1429 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1430 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1431 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1432 PXLY_RC_VLAN_FILTER)
1433 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1434
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001435 for (i = 0; i < port->num_mcs; i++)
1436 if (use_mcs)
1437 cb0->default_qpn_arr[i] =
1438 port->port_res[i].qp->init_attr.qp_nr;
1439 else
1440 cb0->default_qpn_arr[i] =
1441 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001442
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443 if (netif_msg_ifup(port))
1444 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1445
1446 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1447 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1448
1449 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1450 port->logical_port_id,
1451 H_PORT_CB0, mask, cb0);
1452 ret = -EIO;
1453 if (hret != H_SUCCESS)
1454 goto out_free;
1455
1456 ret = 0;
1457
1458out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001459 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001460out:
1461 return ret;
1462}
1463
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001464int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001465{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001466 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001467 struct ehea_adapter *adapter = pr->port->adapter;
1468
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001469 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1470 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001471 goto out;
1472
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1474 if (ret)
1475 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476
1477 return 0;
1478
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001479out_free:
1480 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481out:
Joe Perches539995d2010-11-30 08:18:44 +00001482 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 return -EIO;
1484}
1485
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001486int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487{
Joe Perches8e95a202009-12-03 07:58:21 +00001488 if ((ehea_rem_mr(&pr->send_mr)) ||
1489 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001490 return -EIO;
1491 else
1492 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001493}
1494
1495static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1496{
Doug Maxey508d2b52008-01-31 20:20:49 -06001497 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001499 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500 if (!q_skba->arr)
1501 return -ENOMEM;
1502
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001503 q_skba->len = max_q_entries;
1504 q_skba->index = 0;
1505 q_skba->os_skbs = 0;
1506
1507 return 0;
1508}
1509
1510static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1511 struct port_res_cfg *pr_cfg, int queue_token)
1512{
1513 struct ehea_adapter *adapter = port->adapter;
1514 enum ehea_eq_type eq_type = EHEA_EQ;
1515 struct ehea_qp_init_attr *init_attr = NULL;
1516 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001517 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1518
1519 tx_bytes = pr->tx_bytes;
1520 tx_packets = pr->tx_packets;
1521 rx_bytes = pr->rx_bytes;
1522 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001523
1524 memset(pr, 0, sizeof(struct ehea_port_res));
1525
Breno Leitaoce45b872010-10-27 08:45:14 +00001526 pr->tx_bytes = rx_bytes;
1527 pr->tx_packets = tx_packets;
1528 pr->rx_bytes = rx_bytes;
1529 pr->rx_packets = rx_packets;
1530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001531 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532 spin_lock_init(&pr->xmit_lock);
1533 spin_lock_init(&pr->netif_queue);
1534
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001535 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1536 if (!pr->eq) {
Joe Perches539995d2010-11-30 08:18:44 +00001537 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001538 goto out_free;
1539 }
1540
1541 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001542 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 port->logical_port_id);
1544 if (!pr->recv_cq) {
Joe Perches539995d2010-11-30 08:18:44 +00001545 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001546 goto out_free;
1547 }
1548
1549 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001550 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 port->logical_port_id);
1552 if (!pr->send_cq) {
Joe Perches539995d2010-11-30 08:18:44 +00001553 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001554 goto out_free;
1555 }
1556
1557 if (netif_msg_ifup(port))
Joe Perches539995d2010-11-30 08:18:44 +00001558 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1559 pr->send_cq->attr.act_nr_of_cqes,
1560 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561
1562 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1563 if (!init_attr) {
1564 ret = -ENOMEM;
Joe Perches539995d2010-11-30 08:18:44 +00001565 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001566 goto out_free;
1567 }
1568
1569 init_attr->low_lat_rq1 = 1;
1570 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1571 init_attr->rq_count = 3;
1572 init_attr->qp_token = queue_token;
1573 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1574 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1575 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1576 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1577 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1578 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1579 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1580 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1581 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1582 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1583 init_attr->port_nr = port->logical_port_id;
1584 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1585 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1586 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1587
1588 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1589 if (!pr->qp) {
Joe Perches539995d2010-11-30 08:18:44 +00001590 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001591 ret = -EIO;
1592 goto out_free;
1593 }
1594
1595 if (netif_msg_ifup(port))
Joe Perches539995d2010-11-30 08:18:44 +00001596 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",
1597 init_attr->qp_nr,
1598 init_attr->act_nr_send_wqes,
1599 init_attr->act_nr_rwqes_rq1,
1600 init_attr->act_nr_rwqes_rq2,
1601 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001602
Thomas Klein44fb3122008-04-04 15:04:53 +02001603 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1604
1605 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1607 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1608 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1609 if (ret)
1610 goto out_free;
1611
1612 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1613 if (ehea_gen_smrs(pr) != 0) {
1614 ret = -EIO;
1615 goto out_free;
1616 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001618 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1619
1620 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001621
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001622 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001623
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001624 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1625 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1626 pr->lro_mgr.lro_arr = pr->lro_desc;
1627 pr->lro_mgr.get_skb_header = get_skb_hdr;
1628 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1629 pr->lro_mgr.dev = port->netdev;
1630 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1631 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1632
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001633 ret = 0;
1634 goto out;
1635
1636out_free:
1637 kfree(init_attr);
1638 vfree(pr->sq_skba.arr);
1639 vfree(pr->rq1_skba.arr);
1640 vfree(pr->rq2_skba.arr);
1641 vfree(pr->rq3_skba.arr);
1642 ehea_destroy_qp(pr->qp);
1643 ehea_destroy_cq(pr->send_cq);
1644 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001645 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001646out:
1647 return ret;
1648}
1649
1650static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1651{
1652 int ret, i;
1653
Hannes Hering357eb462009-08-04 11:48:39 -07001654 if (pr->qp)
1655 netif_napi_del(&pr->napi);
1656
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001657 ret = ehea_destroy_qp(pr->qp);
1658
1659 if (!ret) {
1660 ehea_destroy_cq(pr->send_cq);
1661 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001662 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001663
1664 for (i = 0; i < pr->rq1_skba.len; i++)
1665 if (pr->rq1_skba.arr[i])
1666 dev_kfree_skb(pr->rq1_skba.arr[i]);
1667
1668 for (i = 0; i < pr->rq2_skba.len; i++)
1669 if (pr->rq2_skba.arr[i])
1670 dev_kfree_skb(pr->rq2_skba.arr[i]);
1671
1672 for (i = 0; i < pr->rq3_skba.len; i++)
1673 if (pr->rq3_skba.arr[i])
1674 dev_kfree_skb(pr->rq3_skba.arr[i]);
1675
1676 for (i = 0; i < pr->sq_skba.len; i++)
1677 if (pr->sq_skba.arr[i])
1678 dev_kfree_skb(pr->sq_skba.arr[i]);
1679
1680 vfree(pr->rq1_skba.arr);
1681 vfree(pr->rq2_skba.arr);
1682 vfree(pr->rq3_skba.arr);
1683 vfree(pr->sq_skba.arr);
1684 ret = ehea_rem_smrs(pr);
1685 }
1686 return ret;
1687}
1688
1689/*
1690 * The write_* functions store information in swqe which is used by
1691 * the hardware to calculate the ip/tcp/udp checksum
1692 */
1693
1694static inline void write_ip_start_end(struct ehea_swqe *swqe,
1695 const struct sk_buff *skb)
1696{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001697 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001698 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001699}
1700
1701static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1702 const struct sk_buff *skb)
1703{
1704 swqe->tcp_offset =
1705 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1706
1707 swqe->tcp_end = (u16)skb->len - 1;
1708}
1709
1710static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1711 const struct sk_buff *skb)
1712{
1713 swqe->tcp_offset =
1714 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1715
1716 swqe->tcp_end = (u16)skb->len - 1;
1717}
1718
1719
1720static void write_swqe2_TSO(struct sk_buff *skb,
1721 struct ehea_swqe *swqe, u32 lkey)
1722{
1723 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1724 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001725 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001727
1728 /* Packet is TCP with TSO enabled */
1729 swqe->tx_control |= EHEA_SWQE_TSO;
1730 swqe->mss = skb_shinfo(skb)->gso_size;
1731 /* copy only eth/ip/tcp headers to immediate data and
1732 * the rest of skb->data to sg1entry
1733 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001734 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735
Eric Dumazete743d312010-04-14 15:59:40 -07001736 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001737
1738 if (skb_data_size >= headersize) {
1739 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001740 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001741 swqe->immediate_data_length = headersize;
1742
1743 if (skb_data_size > headersize) {
1744 /* set sg1entry data */
1745 sg1entry->l_key = lkey;
1746 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001747 sg1entry->vaddr =
1748 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001749 swqe->descriptors++;
1750 }
1751 } else
Joe Perches539995d2010-11-30 08:18:44 +00001752 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753}
1754
1755static void write_swqe2_nonTSO(struct sk_buff *skb,
1756 struct ehea_swqe *swqe, u32 lkey)
1757{
Eric Dumazete743d312010-04-14 15:59:40 -07001758 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001759 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1760 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761
1762 /* Packet is any nonTSO type
1763 *
1764 * Copy as much as possible skb->data to immediate data and
1765 * the rest to sg1entry
1766 */
1767 if (skb_data_size >= SWQE2_MAX_IMM) {
1768 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001769 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 swqe->immediate_data_length = SWQE2_MAX_IMM;
1772
1773 if (skb_data_size > SWQE2_MAX_IMM) {
1774 /* copy sg1entry data */
1775 sg1entry->l_key = lkey;
1776 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001777 sg1entry->vaddr =
1778 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779 swqe->descriptors++;
1780 }
1781 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001782 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783 swqe->immediate_data_length = skb_data_size;
1784 }
1785}
1786
1787static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1788 struct ehea_swqe *swqe, u32 lkey)
1789{
1790 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1791 skb_frag_t *frag;
1792 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001793
1794 nfrags = skb_shinfo(skb)->nr_frags;
1795 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001796 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797 swqe->descriptors = 0;
1798 sg1entry_contains_frag_data = 0;
1799
1800 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1801 write_swqe2_TSO(skb, swqe, lkey);
1802 else
1803 write_swqe2_nonTSO(skb, swqe, lkey);
1804
1805 /* write descriptors */
1806 if (nfrags > 0) {
1807 if (swqe->descriptors == 0) {
1808 /* sg1entry not yet used */
1809 frag = &skb_shinfo(skb)->frags[0];
1810
1811 /* copy sg1entry data */
1812 sg1entry->l_key = lkey;
1813 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001814 sg1entry->vaddr =
1815 ehea_map_vaddr(page_address(frag->page)
1816 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001817 swqe->descriptors++;
1818 sg1entry_contains_frag_data = 1;
1819 }
1820
1821 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1822
1823 frag = &skb_shinfo(skb)->frags[i];
1824 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1825
1826 sgentry->l_key = lkey;
1827 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001828 sgentry->vaddr =
1829 ehea_map_vaddr(page_address(frag->page)
1830 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001831 swqe->descriptors++;
1832 }
1833 }
1834}
1835
1836static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1837{
1838 int ret = 0;
1839 u64 hret;
1840 u8 reg_type;
1841
1842 /* De/Register untagged packets */
1843 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1844 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1845 port->logical_port_id,
1846 reg_type, port->mac_addr, 0, hcallid);
1847 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00001848 pr_err("%sregistering bc address failed (tagged)\n",
1849 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001850 ret = -EIO;
1851 goto out_herr;
1852 }
1853
1854 /* De/Register VLAN packets */
1855 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1856 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1857 port->logical_port_id,
1858 reg_type, port->mac_addr, 0, hcallid);
1859 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00001860 pr_err("%sregistering bc address failed (vlan)\n",
1861 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001862 ret = -EIO;
1863 }
1864out_herr:
1865 return ret;
1866}
1867
1868static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1869{
1870 struct ehea_port *port = netdev_priv(dev);
1871 struct sockaddr *mac_addr = sa;
1872 struct hcp_ehea_port_cb0 *cb0;
1873 int ret;
1874 u64 hret;
1875
1876 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1877 ret = -EADDRNOTAVAIL;
1878 goto out;
1879 }
1880
Thomas Klein3faf2692009-01-21 14:45:33 -08001881 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001882 if (!cb0) {
Joe Perches539995d2010-11-30 08:18:44 +00001883 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001884 ret = -ENOMEM;
1885 goto out;
1886 }
1887
1888 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1889
1890 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1891
1892 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1893 port->logical_port_id, H_PORT_CB0,
1894 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1895 if (hret != H_SUCCESS) {
1896 ret = -EIO;
1897 goto out_free;
1898 }
1899
1900 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1901
1902 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001903 if (port->state == EHEA_PORT_UP) {
1904 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1905 if (ret)
1906 goto out_upregs;
1907 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001908
1909 port->mac_addr = cb0->port_mac_addr << 16;
1910
1911 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001912 if (port->state == EHEA_PORT_UP) {
1913 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1914 if (ret)
1915 goto out_upregs;
1916 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001917
1918 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001919
1920out_upregs:
1921 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001922out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001923 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001924out:
1925 return ret;
1926}
1927
1928static void ehea_promiscuous_error(u64 hret, int enable)
1929{
Thomas Klein7674a582007-01-22 12:54:20 +01001930 if (hret == H_AUTHORITY)
Joe Perches539995d2010-11-30 08:18:44 +00001931 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1932 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001933 else
Joe Perches539995d2010-11-30 08:18:44 +00001934 pr_err("failed %sabling promiscuous mode\n",
1935 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001936}
1937
1938static void ehea_promiscuous(struct net_device *dev, int enable)
1939{
1940 struct ehea_port *port = netdev_priv(dev);
1941 struct hcp_ehea_port_cb7 *cb7;
1942 u64 hret;
1943
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001944 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945 return;
1946
Thomas Klein3faf2692009-01-21 14:45:33 -08001947 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948 if (!cb7) {
Joe Perches539995d2010-11-30 08:18:44 +00001949 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001950 goto out;
1951 }
1952
1953 /* Modify Pxs_DUCQPN in CB7 */
1954 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1955
1956 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1957 port->logical_port_id,
1958 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1959 if (hret) {
1960 ehea_promiscuous_error(hret, enable);
1961 goto out;
1962 }
1963
1964 port->promisc = enable;
1965out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001966 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001967}
1968
1969static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1970 u32 hcallid)
1971{
1972 u64 hret;
1973 u8 reg_type;
1974
1975 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1976 | EHEA_BCMC_UNTAGGED;
1977
1978 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1979 port->logical_port_id,
1980 reg_type, mc_mac_addr, 0, hcallid);
1981 if (hret)
1982 goto out;
1983
1984 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1985 | EHEA_BCMC_VLANID_ALL;
1986
1987 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1988 port->logical_port_id,
1989 reg_type, mc_mac_addr, 0, hcallid);
1990out:
1991 return hret;
1992}
1993
1994static int ehea_drop_multicast_list(struct net_device *dev)
1995{
1996 struct ehea_port *port = netdev_priv(dev);
1997 struct ehea_mc_list *mc_entry = port->mc_list;
1998 struct list_head *pos;
1999 struct list_head *temp;
2000 int ret = 0;
2001 u64 hret;
2002
2003 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2004 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2005
2006 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2007 H_DEREG_BCMC);
2008 if (hret) {
Joe Perches539995d2010-11-30 08:18:44 +00002009 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002010 ret = -EIO;
2011 }
2012
2013 list_del(pos);
2014 kfree(mc_entry);
2015 }
2016 return ret;
2017}
2018
2019static void ehea_allmulti(struct net_device *dev, int enable)
2020{
2021 struct ehea_port *port = netdev_priv(dev);
2022 u64 hret;
2023
2024 if (!port->allmulti) {
2025 if (enable) {
2026 /* Enable ALLMULTI */
2027 ehea_drop_multicast_list(dev);
2028 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2029 if (!hret)
2030 port->allmulti = 1;
2031 else
Joe Perches539995d2010-11-30 08:18:44 +00002032 netdev_err(dev,
2033 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002034 }
2035 } else
2036 if (!enable) {
2037 /* Disable ALLMULTI */
2038 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2039 if (!hret)
2040 port->allmulti = 0;
2041 else
Joe Perches539995d2010-11-30 08:18:44 +00002042 netdev_err(dev,
2043 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002044 }
2045}
2046
Doug Maxey508d2b52008-01-31 20:20:49 -06002047static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002048{
2049 struct ehea_mc_list *ehea_mcl_entry;
2050 u64 hret;
2051
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002052 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053 if (!ehea_mcl_entry) {
Joe Perches539995d2010-11-30 08:18:44 +00002054 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002055 return;
2056 }
2057
2058 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2059
2060 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2061
2062 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2063 H_REG_BCMC);
2064 if (!hret)
2065 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2066 else {
Joe Perches539995d2010-11-30 08:18:44 +00002067 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002068 kfree(ehea_mcl_entry);
2069 }
2070}
2071
2072static void ehea_set_multicast_list(struct net_device *dev)
2073{
2074 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002075 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002076 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002077
2078 if (dev->flags & IFF_PROMISC) {
2079 ehea_promiscuous(dev, 1);
2080 return;
2081 }
2082 ehea_promiscuous(dev, 0);
2083
2084 if (dev->flags & IFF_ALLMULTI) {
2085 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002086 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002087 }
2088 ehea_allmulti(dev, 0);
2089
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002090 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002091 ret = ehea_drop_multicast_list(dev);
2092 if (ret) {
2093 /* Dropping the current multicast list failed.
2094 * Enabling ALL_MULTI is the best we can do.
2095 */
2096 ehea_allmulti(dev, 1);
2097 }
2098
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002099 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches539995d2010-11-30 08:18:44 +00002100 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2101 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002102 goto out;
2103 }
2104
Jiri Pirko22bedad32010-04-01 21:22:57 +00002105 netdev_for_each_mc_addr(ha, dev)
2106 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 }
2109out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002110 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111}
2112
2113static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2114{
2115 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2116 return -EINVAL;
2117 dev->mtu = new_mtu;
2118 return 0;
2119}
2120
2121static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2122 struct ehea_swqe *swqe, u32 lkey)
2123{
2124 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002125 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002126
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127 /* IPv4 */
2128 swqe->tx_control |= EHEA_SWQE_CRC
2129 | EHEA_SWQE_IP_CHECKSUM
2130 | EHEA_SWQE_TCP_CHECKSUM
2131 | EHEA_SWQE_IMM_DATA_PRESENT
2132 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2133
2134 write_ip_start_end(swqe, skb);
2135
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002136 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002137 if ((iph->frag_off & IP_MF) ||
2138 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002139 /* IP fragment, so don't change cs */
2140 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2141 else
2142 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002143 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002144 write_tcp_offset_end(swqe, skb);
2145 }
2146
2147 /* icmp (big data) and ip segmentation packets (all other ip
2148 packets) do not require any special handling */
2149
2150 } else {
2151 /* Other Ethernet Protocol */
2152 swqe->tx_control |= EHEA_SWQE_CRC
2153 | EHEA_SWQE_IMM_DATA_PRESENT
2154 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2155 }
2156
2157 write_swqe2_data(skb, dev, swqe, lkey);
2158}
2159
2160static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2161 struct ehea_swqe *swqe)
2162{
2163 int nfrags = skb_shinfo(skb)->nr_frags;
2164 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2165 skb_frag_t *frag;
2166 int i;
2167
2168 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002169 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002170
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002171 /* IPv4 */
2172 write_ip_start_end(swqe, skb);
2173
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002174 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002175 swqe->tx_control |= EHEA_SWQE_CRC
2176 | EHEA_SWQE_IP_CHECKSUM
2177 | EHEA_SWQE_TCP_CHECKSUM
2178 | EHEA_SWQE_IMM_DATA_PRESENT;
2179
2180 write_tcp_offset_end(swqe, skb);
2181
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002182 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002183 if ((iph->frag_off & IP_MF) ||
2184 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002185 /* IP fragment, so don't change cs */
2186 swqe->tx_control |= EHEA_SWQE_CRC
2187 | EHEA_SWQE_IMM_DATA_PRESENT;
2188 else {
2189 swqe->tx_control |= EHEA_SWQE_CRC
2190 | EHEA_SWQE_IP_CHECKSUM
2191 | EHEA_SWQE_TCP_CHECKSUM
2192 | EHEA_SWQE_IMM_DATA_PRESENT;
2193
2194 write_udp_offset_end(swqe, skb);
2195 }
2196 } else {
2197 /* icmp (big data) and
2198 ip segmentation packets (all other ip packets) */
2199 swqe->tx_control |= EHEA_SWQE_CRC
2200 | EHEA_SWQE_IP_CHECKSUM
2201 | EHEA_SWQE_IMM_DATA_PRESENT;
2202 }
2203 } else {
2204 /* Other Ethernet Protocol */
2205 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2206 }
2207 /* copy (immediate) data */
2208 if (nfrags == 0) {
2209 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002210 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002211 } else {
2212 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002213 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002214 skb_headlen(skb));
2215 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002216
2217 /* ... then copy data from the fragments */
2218 for (i = 0; i < nfrags; i++) {
2219 frag = &skb_shinfo(skb)->frags[i];
2220 memcpy(imm_data,
2221 page_address(frag->page) + frag->page_offset,
2222 frag->size);
2223 imm_data += frag->size;
2224 }
2225 }
2226 swqe->immediate_data_length = skb->len;
2227 dev_kfree_skb(skb);
2228}
2229
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002230static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2231{
2232 struct tcphdr *tcp;
2233 u32 tmp;
2234
2235 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002236 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002237 tcp = (struct tcphdr *)(skb_network_header(skb) +
2238 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002239 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002240 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002241 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002242 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002243 return 0;
2244}
2245
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002246static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2247{
2248 struct ehea_port *port = netdev_priv(dev);
2249 struct ehea_swqe *swqe;
2250 unsigned long flags;
2251 u32 lkey;
2252 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002253 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002255 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2256
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002257 if (!spin_trylock(&pr->xmit_lock))
2258 return NETDEV_TX_BUSY;
2259
2260 if (pr->queue_stopped) {
2261 spin_unlock(&pr->xmit_lock);
2262 return NETDEV_TX_BUSY;
2263 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002264
2265 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2266 memset(swqe, 0, SWQE_HEADER_SIZE);
2267 atomic_dec(&pr->swqe_avail);
2268
Eric Dumazete5ccd962010-10-26 19:21:07 +00002269 if (vlan_tx_tag_present(skb)) {
2270 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2271 swqe->vlan_tag = vlan_tx_tag_get(skb);
2272 }
2273
Breno Leitaoce45b872010-10-27 08:45:14 +00002274 pr->tx_packets++;
2275 pr->tx_bytes += skb->len;
2276
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002277 if (skb->len <= SWQE3_MAX_IMM) {
2278 u32 sig_iv = port->sig_comp_iv;
2279 u32 swqe_num = pr->swqe_id_counter;
2280 ehea_xmit3(skb, dev, swqe);
2281 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2282 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2283 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2284 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2285 sig_iv);
2286 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2287 pr->swqe_ll_count = 0;
2288 } else
2289 pr->swqe_ll_count += 1;
2290 } else {
2291 swqe->wr_id =
2292 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2293 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002294 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002295 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2296 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2297
2298 pr->sq_skba.index++;
2299 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2300
2301 lkey = pr->send_mr.lkey;
2302 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002303 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002304 }
2305 pr->swqe_id_counter += 1;
2306
Joe Perches539995d2010-11-30 08:18:44 +00002307 netif_info(port, tx_queued, dev,
2308 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2309 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002310 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002311
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002312 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2313 netif_stop_queue(dev);
2314 swqe->tx_control |= EHEA_SWQE_PURGE;
2315 }
Thomas Klein44c82152007-07-11 16:32:00 +02002316
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002317 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002318
2319 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2320 spin_lock_irqsave(&pr->netif_queue, flags);
2321 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002322 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002323 netif_stop_queue(dev);
2324 pr->queue_stopped = 1;
2325 }
2326 spin_unlock_irqrestore(&pr->netif_queue, flags);
2327 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002328 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002329 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 return NETDEV_TX_OK;
2332}
2333
2334static void ehea_vlan_rx_register(struct net_device *dev,
2335 struct vlan_group *grp)
2336{
2337 struct ehea_port *port = netdev_priv(dev);
2338 struct ehea_adapter *adapter = port->adapter;
2339 struct hcp_ehea_port_cb1 *cb1;
2340 u64 hret;
2341
2342 port->vgrp = grp;
2343
Thomas Klein3faf2692009-01-21 14:45:33 -08002344 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002345 if (!cb1) {
Joe Perches539995d2010-11-30 08:18:44 +00002346 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002347 goto out;
2348 }
2349
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002350 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2351 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2352 if (hret != H_SUCCESS)
Joe Perches539995d2010-11-30 08:18:44 +00002353 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354
Thomas Klein3faf2692009-01-21 14:45:33 -08002355 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356out:
2357 return;
2358}
2359
2360static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2361{
2362 struct ehea_port *port = netdev_priv(dev);
2363 struct ehea_adapter *adapter = port->adapter;
2364 struct hcp_ehea_port_cb1 *cb1;
2365 int index;
2366 u64 hret;
2367
Thomas Klein3faf2692009-01-21 14:45:33 -08002368 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369 if (!cb1) {
Joe Perches539995d2010-11-30 08:18:44 +00002370 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371 goto out;
2372 }
2373
2374 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2375 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2376 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002377 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 goto out;
2379 }
2380
2381 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002382 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002383
2384 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2385 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2386 if (hret != H_SUCCESS)
Joe Perches539995d2010-11-30 08:18:44 +00002387 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002388out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002389 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002390 return;
2391}
2392
2393static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2394{
2395 struct ehea_port *port = netdev_priv(dev);
2396 struct ehea_adapter *adapter = port->adapter;
2397 struct hcp_ehea_port_cb1 *cb1;
2398 int index;
2399 u64 hret;
2400
Dan Aloni5c15bde2007-03-02 20:44:51 -08002401 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002402
Thomas Klein3faf2692009-01-21 14:45:33 -08002403 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002404 if (!cb1) {
Joe Perches539995d2010-11-30 08:18:44 +00002405 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002406 goto out;
2407 }
2408
2409 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2410 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2411 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002412 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413 goto out;
2414 }
2415
2416 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002417 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002418
2419 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2420 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2421 if (hret != H_SUCCESS)
Joe Perches539995d2010-11-30 08:18:44 +00002422 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002423out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002424 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425}
2426
2427int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2428{
2429 int ret = -EIO;
2430 u64 hret;
2431 u16 dummy16 = 0;
2432 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002433 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002434
Thomas Klein3faf2692009-01-21 14:45:33 -08002435 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436 if (!cb0) {
2437 ret = -ENOMEM;
2438 goto out;
2439 }
2440
2441 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2442 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2443 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002444 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002445 goto out;
2446 }
2447
2448 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2449 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2450 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2451 &dummy64, &dummy64, &dummy16, &dummy16);
2452 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002453 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454 goto out;
2455 }
2456
2457 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2458 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2459 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002460 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002461 goto out;
2462 }
2463
2464 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2465 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2466 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2467 &dummy64, &dummy64, &dummy16, &dummy16);
2468 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002469 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 goto out;
2471 }
2472
2473 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2474 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2475 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002476 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002477 goto out;
2478 }
2479
2480 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2481 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2482 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2483 &dummy64, &dummy64, &dummy16, &dummy16);
2484 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002485 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002486 goto out;
2487 }
2488
2489 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2490 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2491 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002492 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002493 goto out;
2494 }
2495
2496 ret = 0;
2497out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002498 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002499 return ret;
2500}
2501
2502static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2503 int add_tx_qps)
2504{
2505 int ret, i;
2506 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2507 enum ehea_eq_type eq_type = EHEA_EQ;
2508
2509 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2510 EHEA_MAX_ENTRIES_EQ, 1);
2511 if (!port->qp_eq) {
2512 ret = -EINVAL;
Joe Perches539995d2010-11-30 08:18:44 +00002513 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002514 goto out_kill_eq;
2515 }
2516
2517 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002518 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002519 pr_cfg.max_entries_sq = sq_entries;
2520 pr_cfg.max_entries_rq1 = rq1_entries;
2521 pr_cfg.max_entries_rq2 = rq2_entries;
2522 pr_cfg.max_entries_rq3 = rq3_entries;
2523
2524 pr_cfg_small_rx.max_entries_rcq = 1;
2525 pr_cfg_small_rx.max_entries_scq = sq_entries;
2526 pr_cfg_small_rx.max_entries_sq = sq_entries;
2527 pr_cfg_small_rx.max_entries_rq1 = 1;
2528 pr_cfg_small_rx.max_entries_rq2 = 1;
2529 pr_cfg_small_rx.max_entries_rq3 = 1;
2530
2531 for (i = 0; i < def_qps; i++) {
2532 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2533 if (ret)
2534 goto out_clean_pr;
2535 }
2536 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2537 ret = ehea_init_port_res(port, &port->port_res[i],
2538 &pr_cfg_small_rx, i);
2539 if (ret)
2540 goto out_clean_pr;
2541 }
2542
2543 return 0;
2544
2545out_clean_pr:
2546 while (--i >= 0)
2547 ehea_clean_portres(port, &port->port_res[i]);
2548
2549out_kill_eq:
2550 ehea_destroy_eq(port->qp_eq);
2551 return ret;
2552}
2553
2554static int ehea_clean_all_portres(struct ehea_port *port)
2555{
2556 int ret = 0;
2557 int i;
2558
Doug Maxey508d2b52008-01-31 20:20:49 -06002559 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002560 ret |= ehea_clean_portres(port, &port->port_res[i]);
2561
2562 ret |= ehea_destroy_eq(port->qp_eq);
2563
2564 return ret;
2565}
2566
Thomas Klein35cf2e22007-08-06 13:55:14 +02002567static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002568{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002569 if (adapter->active_ports)
2570 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002571
2572 ehea_rem_mr(&adapter->mr);
2573}
2574
Thomas Klein35cf2e22007-08-06 13:55:14 +02002575static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002576{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002577 if (adapter->active_ports)
2578 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002579
2580 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2581}
2582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002583static int ehea_up(struct net_device *dev)
2584{
2585 int ret, i;
2586 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002587
2588 if (port->state == EHEA_PORT_UP)
2589 return 0;
2590
2591 ret = ehea_port_res_setup(port, port->num_def_qps,
2592 port->num_add_tx_qps);
2593 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002594 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002595 goto out;
2596 }
2597
2598 /* Set default QP for this port */
2599 ret = ehea_configure_port(port);
2600 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002601 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002602 goto out_clean_pr;
2603 }
2604
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002605 ret = ehea_reg_interrupts(dev);
2606 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002607 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002608 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002609 }
2610
Doug Maxey508d2b52008-01-31 20:20:49 -06002611 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2613 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002614 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002615 goto out_free_irqs;
2616 }
2617 }
2618
Doug Maxey508d2b52008-01-31 20:20:49 -06002619 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 ret = ehea_fill_port_res(&port->port_res[i]);
2621 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002622 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 goto out_free_irqs;
2624 }
2625 }
2626
Thomas Klein21eee2d2008-02-13 16:18:33 +01002627 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2628 if (ret) {
2629 ret = -EIO;
2630 goto out_free_irqs;
2631 }
2632
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002633 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002634
2635 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002636 goto out;
2637
2638out_free_irqs:
2639 ehea_free_interrupts(dev);
2640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002641out_clean_pr:
2642 ehea_clean_all_portres(port);
2643out:
Thomas Klein44c82152007-07-11 16:32:00 +02002644 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00002645 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002646
Thomas Klein21eee2d2008-02-13 16:18:33 +01002647 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002648 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002649
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650 return ret;
2651}
2652
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002653static void port_napi_disable(struct ehea_port *port)
2654{
2655 int i;
2656
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002657 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002658 napi_disable(&port->port_res[i].napi);
2659}
2660
2661static void port_napi_enable(struct ehea_port *port)
2662{
2663 int i;
2664
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002665 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002666 napi_enable(&port->port_res[i].napi);
2667}
2668
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002669static int ehea_open(struct net_device *dev)
2670{
2671 int ret;
2672 struct ehea_port *port = netdev_priv(dev);
2673
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002674 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002675
Joe Perches539995d2010-11-30 08:18:44 +00002676 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677
2678 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002679 if (!ret) {
2680 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002681 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002682 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002683
Breno Leitao5b27d422010-10-05 13:16:22 +00002684 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002685 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002686
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002687 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002688
2689 return ret;
2690}
2691
2692static int ehea_down(struct net_device *dev)
2693{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002694 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002695 struct ehea_port *port = netdev_priv(dev);
2696
2697 if (port->state == EHEA_PORT_DOWN)
2698 return 0;
2699
2700 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002701 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2702
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002703 ehea_free_interrupts(dev);
2704
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002705 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002706
Thomas Klein21eee2d2008-02-13 16:18:33 +01002707 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002708
Thomas Klein44c82152007-07-11 16:32:00 +02002709 ret = ehea_clean_all_portres(port);
2710 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00002711 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002712
Thomas Klein21eee2d2008-02-13 16:18:33 +01002713 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002714
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002715 return ret;
2716}
2717
2718static int ehea_stop(struct net_device *dev)
2719{
2720 int ret;
2721 struct ehea_port *port = netdev_priv(dev);
2722
Joe Perches539995d2010-11-30 08:18:44 +00002723 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002724
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002725 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002726 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002727 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002728 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002729 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002730 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002731 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002732 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733 return ret;
2734}
2735
Andrew Morton22559c52008-04-18 13:50:39 -07002736static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002737{
2738 struct ehea_qp qp = *orig_qp;
2739 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2740 struct ehea_swqe *swqe;
2741 int wqe_index;
2742 int i;
2743
2744 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2745 swqe = ehea_get_swqe(&qp, &wqe_index);
2746 swqe->tx_control |= EHEA_SWQE_PURGE;
2747 }
2748}
2749
Andrew Morton22559c52008-04-18 13:50:39 -07002750static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002751{
2752 int i;
2753
2754 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2755 struct ehea_port_res *pr = &port->port_res[i];
2756 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002757 int ret;
2758
2759 ret = wait_event_timeout(port->swqe_avail_wq,
2760 atomic_read(&pr->swqe_avail) >= swqe_max,
2761 msecs_to_jiffies(100));
2762
2763 if (!ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002764 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002765 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002766 }
2767 }
2768}
2769
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002770int ehea_stop_qps(struct net_device *dev)
2771{
2772 struct ehea_port *port = netdev_priv(dev);
2773 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002774 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002775 int ret = -EIO;
2776 int dret;
2777 int i;
2778 u64 hret;
2779 u64 dummy64 = 0;
2780 u16 dummy16 = 0;
2781
Thomas Klein3faf2692009-01-21 14:45:33 -08002782 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002783 if (!cb0) {
2784 ret = -ENOMEM;
2785 goto out;
2786 }
2787
2788 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2789 struct ehea_port_res *pr = &port->port_res[i];
2790 struct ehea_qp *qp = pr->qp;
2791
2792 /* Purge send queue */
2793 ehea_purge_sq(qp);
2794
2795 /* Disable queue pair */
2796 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2797 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2798 cb0);
2799 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002800 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002801 goto out;
2802 }
2803
2804 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2805 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2806
2807 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2808 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2809 1), cb0, &dummy64,
2810 &dummy64, &dummy16, &dummy16);
2811 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002812 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002813 goto out;
2814 }
2815
2816 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2817 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2818 cb0);
2819 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002820 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002821 goto out;
2822 }
2823
2824 /* deregister shared memory regions */
2825 dret = ehea_rem_smrs(pr);
2826 if (dret) {
Joe Perches539995d2010-11-30 08:18:44 +00002827 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002828 goto out;
2829 }
2830 }
2831
2832 ret = 0;
2833out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002834 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002835
2836 return ret;
2837}
2838
Doug Maxey508d2b52008-01-31 20:20:49 -06002839void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002840{
2841 struct ehea_qp qp = *orig_qp;
2842 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2843 struct ehea_rwqe *rwqe;
2844 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2845 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2846 struct sk_buff *skb;
2847 u32 lkey = pr->recv_mr.lkey;
2848
2849
2850 int i;
2851 int index;
2852
2853 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2854 rwqe = ehea_get_next_rwqe(&qp, 2);
2855 rwqe->sg_list[0].l_key = lkey;
2856 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2857 skb = skba_rq2[index];
2858 if (skb)
2859 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2860 }
2861
2862 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2863 rwqe = ehea_get_next_rwqe(&qp, 3);
2864 rwqe->sg_list[0].l_key = lkey;
2865 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2866 skb = skba_rq3[index];
2867 if (skb)
2868 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2869 }
2870}
2871
2872int ehea_restart_qps(struct net_device *dev)
2873{
2874 struct ehea_port *port = netdev_priv(dev);
2875 struct ehea_adapter *adapter = port->adapter;
2876 int ret = 0;
2877 int i;
2878
Doug Maxey508d2b52008-01-31 20:20:49 -06002879 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002880 u64 hret;
2881 u64 dummy64 = 0;
2882 u16 dummy16 = 0;
2883
Thomas Klein3faf2692009-01-21 14:45:33 -08002884 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002885 if (!cb0) {
2886 ret = -ENOMEM;
2887 goto out;
2888 }
2889
2890 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2891 struct ehea_port_res *pr = &port->port_res[i];
2892 struct ehea_qp *qp = pr->qp;
2893
2894 ret = ehea_gen_smrs(pr);
2895 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00002896 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002897 goto out;
2898 }
2899
2900 ehea_update_rqs(qp, pr);
2901
2902 /* Enable queue pair */
2903 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2904 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2905 cb0);
2906 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002907 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002908 goto out;
2909 }
2910
2911 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2912 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2913
2914 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2915 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2916 1), cb0, &dummy64,
2917 &dummy64, &dummy16, &dummy16);
2918 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002919 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002920 goto out;
2921 }
2922
2923 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2924 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2925 cb0);
2926 if (hret != H_SUCCESS) {
Joe Perches539995d2010-11-30 08:18:44 +00002927 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002928 goto out;
2929 }
2930
2931 /* refill entire queue */
2932 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2933 ehea_refill_rq2(pr, 0);
2934 ehea_refill_rq3(pr, 0);
2935 }
2936out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002937 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002938
2939 return ret;
2940}
2941
David Howellsc4028952006-11-22 14:57:56 +00002942static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002943{
2944 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002945 struct ehea_port *port =
2946 container_of(work, struct ehea_port, reset_task);
2947 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002948
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002949 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002950 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002951 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002952 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002953
2954 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002955
Thomas Klein44c82152007-07-11 16:32:00 +02002956 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957
2958 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002959 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002960 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002961
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002962 ehea_set_multicast_list(dev);
2963
Joe Perches539995d2010-11-30 08:18:44 +00002964 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002965
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002966 port_napi_enable(port);
2967
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002968 netif_wake_queue(dev);
2969out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002970 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002971 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002972}
2973
Thomas Klein44c82152007-07-11 16:32:00 +02002974static void ehea_rereg_mrs(struct work_struct *work)
2975{
2976 int ret, i;
2977 struct ehea_adapter *adapter;
2978
Joe Perches539995d2010-11-30 08:18:44 +00002979 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002980
2981 list_for_each_entry(adapter, &adapter_list, list)
2982 if (adapter->active_ports) {
2983 /* Shutdown all ports */
2984 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2985 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002986 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002987
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002988 if (!port)
2989 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002990
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002991 dev = port->netdev;
2992
2993 if (dev->flags & IFF_UP) {
2994 mutex_lock(&port->port_lock);
2995 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002996 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002997 ret = ehea_stop_qps(dev);
2998 if (ret) {
2999 mutex_unlock(&port->port_lock);
3000 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003001 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003002 port_napi_disable(port);
3003 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003004 }
Andre Detsch2928db42010-08-17 05:49:12 +00003005 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003006 }
3007
3008 /* Unregister old memory region */
3009 ret = ehea_rem_mr(&adapter->mr);
3010 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003011 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003012 goto out;
3013 }
3014 }
3015
Thomas Klein44c82152007-07-11 16:32:00 +02003016 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3017
3018 list_for_each_entry(adapter, &adapter_list, list)
3019 if (adapter->active_ports) {
3020 /* Register new memory region */
3021 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3022 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003023 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003024 goto out;
3025 }
3026
3027 /* Restart all ports */
3028 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3029 struct ehea_port *port = adapter->port[i];
3030
3031 if (port) {
3032 struct net_device *dev = port->netdev;
3033
3034 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003035 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003036 port_napi_enable(port);
3037 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003038 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003039 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003040 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003041 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003042 }
3043 }
3044 }
3045 }
Joe Perches539995d2010-11-30 08:18:44 +00003046 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003047out:
3048 return;
3049}
3050
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003051static void ehea_tx_watchdog(struct net_device *dev)
3052{
3053 struct ehea_port *port = netdev_priv(dev);
3054
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003055 if (netif_carrier_ok(dev) &&
3056 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003057 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003058}
3059
3060int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3061{
3062 struct hcp_query_ehea *cb;
3063 u64 hret;
3064 int ret;
3065
Thomas Klein3faf2692009-01-21 14:45:33 -08003066 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003067 if (!cb) {
3068 ret = -ENOMEM;
3069 goto out;
3070 }
3071
3072 hret = ehea_h_query_ehea(adapter->handle, cb);
3073
3074 if (hret != H_SUCCESS) {
3075 ret = -EIO;
3076 goto out_herr;
3077 }
3078
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003079 adapter->max_mc_mac = cb->max_mc_mac - 1;
3080 ret = 0;
3081
3082out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003083 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003084out:
3085 return ret;
3086}
3087
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003088int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3089{
3090 struct hcp_ehea_port_cb4 *cb4;
3091 u64 hret;
3092 int ret = 0;
3093
3094 *jumbo = 0;
3095
3096 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003097 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 if (!cb4) {
Joe Perches539995d2010-11-30 08:18:44 +00003099 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003100 ret = -ENOMEM;
3101 goto out;
3102 } else {
3103 hret = ehea_h_query_ehea_port(port->adapter->handle,
3104 port->logical_port_id,
3105 H_PORT_CB4,
3106 H_PORT_CB4_JUMBO, cb4);
3107 if (hret == H_SUCCESS) {
3108 if (cb4->jumbo_frame)
3109 *jumbo = 1;
3110 else {
3111 cb4->jumbo_frame = 1;
3112 hret = ehea_h_modify_ehea_port(port->adapter->
3113 handle,
3114 port->
3115 logical_port_id,
3116 H_PORT_CB4,
3117 H_PORT_CB4_JUMBO,
3118 cb4);
3119 if (hret == H_SUCCESS)
3120 *jumbo = 1;
3121 }
3122 } else
3123 ret = -EINVAL;
3124
Thomas Klein3faf2692009-01-21 14:45:33 -08003125 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 }
3127out:
3128 return ret;
3129}
3130
3131static ssize_t ehea_show_port_id(struct device *dev,
3132 struct device_attribute *attr, char *buf)
3133{
3134 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003135 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003136}
3137
3138static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3139 NULL);
3140
3141static void __devinit logical_port_release(struct device *dev)
3142{
3143 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003144 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003145}
3146
3147static struct device *ehea_register_port(struct ehea_port *port,
3148 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003149{
3150 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003151
Grant Likely61c7a082010-04-13 16:12:29 -07003152 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003153 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003154 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003155
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003156 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003157 port->ofdev.dev.release = logical_port_release;
3158
3159 ret = of_device_register(&port->ofdev);
3160 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003161 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162 goto out;
3163 }
3164
3165 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003166 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003167 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 goto out_unreg_of_dev;
3169 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003170
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 return &port->ofdev.dev;
3172
3173out_unreg_of_dev:
3174 of_device_unregister(&port->ofdev);
3175out:
3176 return NULL;
3177}
3178
3179static void ehea_unregister_port(struct ehea_port *port)
3180{
3181 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3182 of_device_unregister(&port->ofdev);
3183}
3184
Thomas Klein086c1b22009-01-21 14:43:59 -08003185static const struct net_device_ops ehea_netdev_ops = {
3186 .ndo_open = ehea_open,
3187 .ndo_stop = ehea_stop,
3188 .ndo_start_xmit = ehea_start_xmit,
3189#ifdef CONFIG_NET_POLL_CONTROLLER
3190 .ndo_poll_controller = ehea_netpoll,
3191#endif
3192 .ndo_get_stats = ehea_get_stats,
3193 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003194 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003195 .ndo_set_multicast_list = ehea_set_multicast_list,
3196 .ndo_change_mtu = ehea_change_mtu,
3197 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3198 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003199 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3200 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003201};
3202
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003203struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3204 u32 logical_port_id,
3205 struct device_node *dn)
3206{
3207 int ret;
3208 struct net_device *dev;
3209 struct ehea_port *port;
3210 struct device *port_dev;
3211 int jumbo;
3212
3213 /* allocate memory for the port structures */
3214 dev = alloc_etherdev(sizeof(struct ehea_port));
3215
3216 if (!dev) {
Joe Perches539995d2010-11-30 08:18:44 +00003217 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 ret = -ENOMEM;
3219 goto out_err;
3220 }
3221
3222 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003223
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003224 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003225 port->state = EHEA_PORT_DOWN;
3226 port->sig_comp_iv = sq_entries / 10;
3227
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003228 port->adapter = adapter;
3229 port->netdev = dev;
3230 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003231
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233
3234 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3235 if (!port->mc_list) {
3236 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238 }
3239
3240 INIT_LIST_HEAD(&port->mc_list->list);
3241
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003242 ret = ehea_sense_port_attr(port);
3243 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246 port_dev = ehea_register_port(port, dn);
3247 if (!port_dev)
3248 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003249
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003250 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003251
3252 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003253 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3254
Thomas Klein086c1b22009-01-21 14:43:59 -08003255 dev->netdev_ops = &ehea_netdev_ops;
3256 ehea_set_ethtool_ops(dev);
3257
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003258 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003259 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3261 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3263
David Howellsc4028952006-11-22 14:57:56 +00003264 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265
3266 ret = register_netdev(dev);
3267 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003268 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003269 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 }
3271
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003272 port->lro_max_aggr = lro_max_aggr;
3273
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003274 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003275 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00003276 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003277
Joe Perches539995d2010-11-30 08:18:44 +00003278 netdev_info(dev, "Jumbo frames are %sabled\n",
3279 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003280
Thomas Klein44c82152007-07-11 16:32:00 +02003281 adapter->active_ports++;
3282
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003283 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003284
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003285out_unreg_port:
3286 ehea_unregister_port(port);
3287
3288out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003289 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290
3291out_free_ethdev:
3292 free_netdev(dev);
3293
3294out_err:
Joe Perches539995d2010-11-30 08:18:44 +00003295 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3296 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003297 return NULL;
3298}
3299
3300static void ehea_shutdown_single_port(struct ehea_port *port)
3301{
Brian King7fb1c2a2008-05-14 09:48:25 -05003302 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303 unregister_netdev(port->netdev);
3304 ehea_unregister_port(port);
3305 kfree(port->mc_list);
3306 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003307 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003308}
3309
3310static int ehea_setup_ports(struct ehea_adapter *adapter)
3311{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003312 struct device_node *lhea_dn;
3313 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003314
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003315 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003317
Grant Likely61c7a082010-04-13 16:12:29 -07003318 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003319 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003320
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003321 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003322 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003323 if (!dn_log_port_id) {
Joe Perches539995d2010-11-30 08:18:44 +00003324 pr_err("bad device node: eth_dn name=%s\n",
3325 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003326 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003327 }
3328
Thomas Klein1211bb62007-04-26 11:56:43 +02003329 if (ehea_add_adapter_mr(adapter)) {
Joe Perches539995d2010-11-30 08:18:44 +00003330 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003331 of_node_put(eth_dn);
3332 return -EIO;
3333 }
3334
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003335 adapter->port[i] = ehea_setup_single_port(adapter,
3336 *dn_log_port_id,
3337 eth_dn);
3338 if (adapter->port[i])
Joe Perches539995d2010-11-30 08:18:44 +00003339 netdev_info(adapter->port[i]->netdev,
3340 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003341 else
3342 ehea_remove_adapter_mr(adapter);
3343
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003345 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003346 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347}
3348
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003349static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3350 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351{
3352 struct device_node *lhea_dn;
3353 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003354 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003355
Grant Likely61c7a082010-04-13 16:12:29 -07003356 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003357 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003358
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003359 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003360 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361 if (dn_log_port_id)
3362 if (*dn_log_port_id == logical_port_id)
3363 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003364 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365
3366 return NULL;
3367}
3368
3369static ssize_t ehea_probe_port(struct device *dev,
3370 struct device_attribute *attr,
3371 const char *buf, size_t count)
3372{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003373 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003374 struct ehea_port *port;
3375 struct device_node *eth_dn = NULL;
3376 int i;
3377
3378 u32 logical_port_id;
3379
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003380 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003381
3382 port = ehea_get_port(adapter, logical_port_id);
3383
3384 if (port) {
Joe Perches539995d2010-11-30 08:18:44 +00003385 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3386 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003387 return -EINVAL;
3388 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003389
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003390 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3391
3392 if (!eth_dn) {
Joe Perches539995d2010-11-30 08:18:44 +00003393 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003394 return -EINVAL;
3395 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003396
Thomas Klein1211bb62007-04-26 11:56:43 +02003397 if (ehea_add_adapter_mr(adapter)) {
Joe Perches539995d2010-11-30 08:18:44 +00003398 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003399 return -EIO;
3400 }
3401
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003402 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3403
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003404 of_node_put(eth_dn);
3405
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003406 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003407 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003408 if (!adapter->port[i]) {
3409 adapter->port[i] = port;
3410 break;
3411 }
3412
Joe Perches539995d2010-11-30 08:18:44 +00003413 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3414 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003415 } else {
3416 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003417 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003418 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003419
3420 return (ssize_t) count;
3421}
3422
3423static ssize_t ehea_remove_port(struct device *dev,
3424 struct device_attribute *attr,
3425 const char *buf, size_t count)
3426{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003427 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003428 struct ehea_port *port;
3429 int i;
3430 u32 logical_port_id;
3431
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003432 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433
3434 port = ehea_get_port(adapter, logical_port_id);
3435
3436 if (port) {
Joe Perches539995d2010-11-30 08:18:44 +00003437 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3438 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003439
3440 ehea_shutdown_single_port(port);
3441
Doug Maxey508d2b52008-01-31 20:20:49 -06003442 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003443 if (adapter->port[i] == port) {
3444 adapter->port[i] = NULL;
3445 break;
3446 }
3447 } else {
Joe Perches539995d2010-11-30 08:18:44 +00003448 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3449 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003450 return -EINVAL;
3451 }
3452
Thomas Klein1211bb62007-04-26 11:56:43 +02003453 ehea_remove_adapter_mr(adapter);
3454
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003455 return (ssize_t) count;
3456}
3457
3458static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3459static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3460
Grant Likely2dc11582010-08-06 09:25:50 -06003461int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003462{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003463 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003464 if (ret)
3465 goto out;
3466
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003467 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003468out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003469 return ret;
3470}
3471
Grant Likely2dc11582010-08-06 09:25:50 -06003472void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003473{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003474 device_remove_file(&dev->dev, &dev_attr_probe_port);
3475 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003476}
3477
Grant Likely2dc11582010-08-06 09:25:50 -06003478static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480{
3481 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003482 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003483 int ret;
3484
Grant Likely61c7a082010-04-13 16:12:29 -07003485 if (!dev || !dev->dev.of_node) {
Joe Perches539995d2010-11-30 08:18:44 +00003486 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003487 return -EINVAL;
3488 }
3489
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003490 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3491 if (!adapter) {
3492 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003493 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494 goto out;
3495 }
3496
Thomas Klein44c82152007-07-11 16:32:00 +02003497 list_add(&adapter->list, &adapter_list);
3498
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003499 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003500
Grant Likely61c7a082010-04-13 16:12:29 -07003501 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003502 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003503 if (adapter_handle)
3504 adapter->handle = *adapter_handle;
3505
3506 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003507 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003508 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003509 ret = -ENODEV;
3510 goto out_free_ad;
3511 }
3512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003513 adapter->pd = EHEA_PD_ID;
3514
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003515 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003516
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517
3518 /* initialize adapter and ports */
3519 /* get adapter properties */
3520 ret = ehea_sense_adapter_attr(adapter);
3521 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003522 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003523 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003524 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003525
3526 adapter->neq = ehea_create_eq(adapter,
3527 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3528 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003529 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003530 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003531 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 }
3533
3534 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3535 (unsigned long)adapter);
3536
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003537 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003538 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539 "ehea_neq", adapter);
3540 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003541 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003542 goto out_kill_eq;
3543 }
3544
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003545 ret = ehea_create_device_sysfs(dev);
3546 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003547 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003548
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003549 ret = ehea_setup_ports(adapter);
3550 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003551 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003552 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553 }
3554
3555 ret = 0;
3556 goto out;
3557
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003558out_rem_dev_sysfs:
3559 ehea_remove_device_sysfs(dev);
3560
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003562 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003563
3564out_kill_eq:
3565 ehea_destroy_eq(adapter->neq);
3566
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003567out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003568 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003569 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003572 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574 return ret;
3575}
3576
Grant Likely2dc11582010-08-06 09:25:50 -06003577static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003578{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003579 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003580 int i;
3581
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003582 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003583 if (adapter->port[i]) {
3584 ehea_shutdown_single_port(adapter->port[i]);
3585 adapter->port[i] = NULL;
3586 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003587
3588 ehea_remove_device_sysfs(dev);
3589
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003590 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003591
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003592 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003593 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003594
3595 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003596 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003597 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003598 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003599
Thomas Klein21eee2d2008-02-13 16:18:33 +01003600 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003601
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003602 return 0;
3603}
3604
Thomas Klein21eee2d2008-02-13 16:18:33 +01003605void ehea_crash_handler(void)
3606{
3607 int i;
3608
3609 if (ehea_fw_handles.arr)
3610 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3611 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3612 ehea_fw_handles.arr[i].fwh,
3613 FORCE_FREE);
3614
3615 if (ehea_bcmc_regs.arr)
3616 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3617 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3618 ehea_bcmc_regs.arr[i].port_id,
3619 ehea_bcmc_regs.arr[i].reg_type,
3620 ehea_bcmc_regs.arr[i].macaddr,
3621 0, H_DEREG_BCMC);
3622}
3623
Hannes Hering48cfb142008-05-07 14:43:36 +02003624static int ehea_mem_notifier(struct notifier_block *nb,
3625 unsigned long action, void *data)
3626{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003627 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003628 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003629
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003630 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003631
Hannes Hering48cfb142008-05-07 14:43:36 +02003632 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003633 case MEM_CANCEL_OFFLINE:
Joe Perches539995d2010-11-30 08:18:44 +00003634 pr_info("memory offlining canceled\n");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003635 /* Readd canceled memory block */
3636 case MEM_ONLINE:
Joe Perches539995d2010-11-30 08:18:44 +00003637 pr_info("memory is going online\n");
Thomas Klein38767322009-02-20 00:42:01 -08003638 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003639 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003640 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003641 ehea_rereg_mrs(NULL);
3642 break;
3643 case MEM_GOING_OFFLINE:
Joe Perches539995d2010-11-30 08:18:44 +00003644 pr_info("memory is going offline\n");
Thomas Klein38767322009-02-20 00:42:01 -08003645 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003646 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003647 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003648 ehea_rereg_mrs(NULL);
3649 break;
3650 default:
3651 break;
3652 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003653
3654 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003655 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003656
Thomas Kleina7c561f22010-04-20 23:11:31 +00003657out_unlock:
3658 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003659 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003660}
3661
3662static struct notifier_block ehea_mem_nb = {
3663 .notifier_call = ehea_mem_notifier,
3664};
3665
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003666static int ehea_reboot_notifier(struct notifier_block *nb,
3667 unsigned long action, void *unused)
3668{
3669 if (action == SYS_RESTART) {
Joe Perches539995d2010-11-30 08:18:44 +00003670 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003671 ibmebus_unregister_driver(&ehea_driver);
3672 }
3673 return NOTIFY_DONE;
3674}
3675
3676static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003677 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003678};
3679
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003680static int check_module_parm(void)
3681{
3682 int ret = 0;
3683
3684 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3685 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches539995d2010-11-30 08:18:44 +00003686 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003687 ret = -EINVAL;
3688 }
3689 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3690 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches539995d2010-11-30 08:18:44 +00003691 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003692 ret = -EINVAL;
3693 }
3694 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3695 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches539995d2010-11-30 08:18:44 +00003696 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003697 ret = -EINVAL;
3698 }
3699 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3700 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches539995d2010-11-30 08:18:44 +00003701 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003702 ret = -EINVAL;
3703 }
3704
3705 return ret;
3706}
3707
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003708static ssize_t ehea_show_capabilities(struct device_driver *drv,
3709 char *buf)
3710{
3711 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3712}
3713
3714static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3715 ehea_show_capabilities, NULL);
3716
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003717int __init ehea_module_init(void)
3718{
3719 int ret;
3720
Joe Perches539995d2010-11-30 08:18:44 +00003721 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003722
Thomas Klein44c82152007-07-11 16:32:00 +02003723
3724 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003725 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3726 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3727
Daniel Walker9f71a562008-03-28 14:41:26 -07003728 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003729 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003730
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003731 ret = check_module_parm();
3732 if (ret)
3733 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003734
3735 ret = ehea_create_busmap();
3736 if (ret)
3737 goto out;
3738
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 ret = register_reboot_notifier(&ehea_reboot_nb);
3740 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00003741 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003742
Hannes Hering48cfb142008-05-07 14:43:36 +02003743 ret = register_memory_notifier(&ehea_mem_nb);
3744 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00003745 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003746
Joe Perchesc061b182010-08-23 18:20:03 +00003747 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003748 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00003749 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003750
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003751 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003752 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003753 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003754 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003755 }
3756
3757 ret = driver_create_file(&ehea_driver.driver,
3758 &driver_attr_capabilities);
3759 if (ret) {
Joe Perches539995d2010-11-30 08:18:44 +00003760 pr_err("failed to register capabilities attribute, ret=%d\n",
3761 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003762 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003763 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003764
Thomas Klein21eee2d2008-02-13 16:18:33 +01003765 return ret;
3766
3767out3:
3768 ibmebus_unregister_driver(&ehea_driver);
3769out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003770 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003771 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003772 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003773out:
3774 return ret;
3775}
3776
3777static void __exit ehea_module_exit(void)
3778{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003779 int ret;
3780
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003781 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003782 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003783 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003784 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003785 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003786 if (ret)
Joe Perches539995d2010-11-30 08:18:44 +00003787 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003788 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003789 kfree(ehea_fw_handles.arr);
3790 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003791 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003792}
3793
3794module_init(ehea_module_init);
3795module_exit(ehea_module_exit);