blob: 53c0f04b1b2322ccee9c53e19e71f5321e81cb8a [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
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;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700106static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100107struct ehea_fw_handle_array ehea_fw_handles;
108struct ehea_bcmc_reg_array ehea_bcmc_regs;
109
Thomas Kleind1dea382007-04-26 11:56:13 +0200110
Grant Likely2dc11582010-08-06 09:25:50 -0600111static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200112 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
Grant Likely2dc11582010-08-06 09:25:50 -0600114static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200115
116static struct of_device_id ehea_device_table[] = {
117 {
118 .name = "lhea",
119 .compatible = "IBM,lhea",
120 },
121 {},
122};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100123MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200124
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000125static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700126 .driver = {
127 .name = "ehea",
128 .owner = THIS_MODULE,
129 .of_match_table = ehea_device_table,
130 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200131 .probe = ehea_probe_adapter,
132 .remove = ehea_remove,
133};
134
Doug Maxey508d2b52008-01-31 20:20:49 -0600135void ehea_dump(void *adr, int len, char *msg)
136{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200137 int x;
138 unsigned char *deb = adr;
139 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800140 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
141 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200142 deb += 16;
143 }
144}
145
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100146void ehea_schedule_port_reset(struct ehea_port *port)
147{
148 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
149 schedule_work(&port->reset_task);
150}
151
Thomas Klein21eee2d2008-02-13 16:18:33 +0100152static void ehea_update_firmware_handles(void)
153{
154 struct ehea_fw_handle_entry *arr = NULL;
155 struct ehea_adapter *adapter;
156 int num_adapters = 0;
157 int num_ports = 0;
158 int num_portres = 0;
159 int i = 0;
160 int num_fw_handles, k, l;
161
162 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700163 mutex_lock(&ehea_fw_handles.lock);
164
Thomas Klein21eee2d2008-02-13 16:18:33 +0100165 list_for_each_entry(adapter, &adapter_list, list) {
166 num_adapters++;
167
168 for (k = 0; k < EHEA_MAX_PORTS; k++) {
169 struct ehea_port *port = adapter->port[k];
170
171 if (!port || (port->state != EHEA_PORT_UP))
172 continue;
173
174 num_ports++;
175 num_portres += port->num_def_qps + port->num_add_tx_qps;
176 }
177 }
178
179 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
180 num_ports * EHEA_NUM_PORT_FW_HANDLES +
181 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
182
183 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000184 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100185 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700186 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100187 } else
188 goto out_update;
189
190 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700191 if (num_adapters == 0)
192 break;
193
Thomas Klein21eee2d2008-02-13 16:18:33 +0100194 for (k = 0; k < EHEA_MAX_PORTS; k++) {
195 struct ehea_port *port = adapter->port[k];
196
Joe Perches8e95a202009-12-03 07:58:21 +0000197 if (!port || (port->state != EHEA_PORT_UP) ||
198 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100199 continue;
200
201 for (l = 0;
202 l < port->num_def_qps + port->num_add_tx_qps;
203 l++) {
204 struct ehea_port_res *pr = &port->port_res[l];
205
206 arr[i].adh = adapter->handle;
207 arr[i++].fwh = pr->qp->fw_handle;
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = pr->send_cq->fw_handle;
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = pr->recv_cq->fw_handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = pr->eq->fw_handle;
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = pr->send_mr.handle;
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = pr->recv_mr.handle;
218 }
219 arr[i].adh = adapter->handle;
220 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700221 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100222 }
223
224 arr[i].adh = adapter->handle;
225 arr[i++].fwh = adapter->neq->fw_handle;
226
227 if (adapter->mr.handle) {
228 arr[i].adh = adapter->handle;
229 arr[i++].fwh = adapter->mr.handle;
230 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700231 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100232 }
233
234out_update:
235 kfree(ehea_fw_handles.arr);
236 ehea_fw_handles.arr = arr;
237 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700238out:
239 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100240}
241
242static void ehea_update_bcmc_registrations(void)
243{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700244 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100245 struct ehea_bcmc_reg_entry *arr = NULL;
246 struct ehea_adapter *adapter;
247 struct ehea_mc_list *mc_entry;
248 int num_registrations = 0;
249 int i = 0;
250 int k;
251
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700252 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
253
Thomas Klein21eee2d2008-02-13 16:18:33 +0100254 /* Determine number of registrations */
255 list_for_each_entry(adapter, &adapter_list, list)
256 for (k = 0; k < EHEA_MAX_PORTS; k++) {
257 struct ehea_port *port = adapter->port[k];
258
259 if (!port || (port->state != EHEA_PORT_UP))
260 continue;
261
262 num_registrations += 2; /* Broadcast registrations */
263
264 list_for_each_entry(mc_entry, &port->mc_list->list,list)
265 num_registrations += 2;
266 }
267
268 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000269 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100270 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700271 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100272 } else
273 goto out_update;
274
275 list_for_each_entry(adapter, &adapter_list, list) {
276 for (k = 0; k < EHEA_MAX_PORTS; k++) {
277 struct ehea_port *port = adapter->port[k];
278
279 if (!port || (port->state != EHEA_PORT_UP))
280 continue;
281
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700282 if (num_registrations == 0)
283 goto out_update;
284
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285 arr[i].adh = adapter->handle;
286 arr[i].port_id = port->logical_port_id;
287 arr[i].reg_type = EHEA_BCMC_BROADCAST |
288 EHEA_BCMC_UNTAGGED;
289 arr[i++].macaddr = port->mac_addr;
290
291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
293 arr[i].reg_type = EHEA_BCMC_BROADCAST |
294 EHEA_BCMC_VLANID_ALL;
295 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700296 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297
298 list_for_each_entry(mc_entry,
299 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700300 if (num_registrations == 0)
301 goto out_update;
302
Thomas Klein21eee2d2008-02-13 16:18:33 +0100303 arr[i].adh = adapter->handle;
304 arr[i].port_id = port->logical_port_id;
305 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
306 EHEA_BCMC_MULTICAST |
307 EHEA_BCMC_UNTAGGED;
308 arr[i++].macaddr = mc_entry->macaddr;
309
310 arr[i].adh = adapter->handle;
311 arr[i].port_id = port->logical_port_id;
312 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
313 EHEA_BCMC_MULTICAST |
314 EHEA_BCMC_VLANID_ALL;
315 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700316 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317 }
318 }
319 }
320
321out_update:
322 kfree(ehea_bcmc_regs.arr);
323 ehea_bcmc_regs.arr = arr;
324 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700325out:
326 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100327}
328
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200329static struct net_device_stats *ehea_get_stats(struct net_device *dev)
330{
331 struct ehea_port *port = netdev_priv(dev);
332 struct net_device_stats *stats = &port->stats;
333 struct hcp_ehea_port_cb2 *cb2;
Breno Leitaoce45b872010-10-27 08:45:14 +0000334 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200335 int i;
336
337 memset(stats, 0, sizeof(*stats));
338
Brian King3d8009c2010-06-30 11:59:12 +0000339 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200340 if (!cb2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800341 netdev_err(dev, "no mem for cb2\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200342 goto out;
343 }
344
345 hret = ehea_h_query_ehea_port(port->adapter->handle,
346 port->logical_port_id,
347 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
348 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800349 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200350 goto out_herr;
351 }
352
353 if (netif_msg_hw(port))
354 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
355
356 rx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000357 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200358 rx_packets += port->port_res[i].rx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000359 rx_bytes += port->port_res[i].rx_bytes;
360 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200361
Thomas Klein7393b872007-11-21 17:37:58 +0100362 tx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000363 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Thomas Klein7393b872007-11-21 17:37:58 +0100364 tx_packets += port->port_res[i].tx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000365 tx_bytes += port->port_res[i].tx_bytes;
366 }
Thomas Klein7393b872007-11-21 17:37:58 +0100367
368 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200369 stats->multicast = cb2->rxmcp;
370 stats->rx_errors = cb2->rxuerr;
Breno Leitaoce45b872010-10-27 08:45:14 +0000371 stats->rx_bytes = rx_bytes;
372 stats->tx_bytes = tx_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200373 stats->rx_packets = rx_packets;
374
375out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800376 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200377out:
378 return stats;
379}
380
381static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
382{
383 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
384 struct net_device *dev = pr->port->netdev;
385 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200386 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
387 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200388 int i;
389
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200390 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200391
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200392 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200393 if (nr_of_wqes > 0)
394 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200395 pr->rq1_skba.os_skbs = fill_wqes;
396 return;
397 }
398
399 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200400 if (!skb_arr_rq1[index]) {
401 skb_arr_rq1[index] = netdev_alloc_skb(dev,
402 EHEA_L_PKT_SIZE);
403 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800404 netdev_info(dev, "Unable to allocate enough skb in the array\n");
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
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000427 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800428 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000429 return;
430 }
431
432 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000434 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800435 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800436 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000437 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200438 }
439 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000440 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200441}
442
443static int ehea_refill_rq_def(struct ehea_port_res *pr,
444 struct ehea_q_skb_arr *q_skba, int rq_nr,
445 int num_wqes, int wqe_type, int packet_size)
446{
447 struct net_device *dev = pr->port->netdev;
448 struct ehea_qp *qp = pr->qp;
449 struct sk_buff **skb_arr = q_skba->arr;
450 struct ehea_rwqe *rwqe;
451 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200452 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453 int ret = 0;
454
455 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200456 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200458 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
459 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200461 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462
463 index = q_skba->index;
464 max_index_mask = q_skba->len - 1;
465 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200466 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000467 struct sk_buff *skb;
468
469 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800472 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800473 netdev_info(pr->port->netdev,
474 "rq%i ran dry - no mem for skb\n",
475 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800476 ret = -ENOMEM;
477 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478 break;
479 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200480
481 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200482 tmp_addr = ehea_map_vaddr(skb->data);
483 if (tmp_addr == -1) {
484 dev_kfree_skb(skb);
485 q_skba->os_skbs = fill_wqes - i;
486 ret = 0;
487 break;
488 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489
490 rwqe = ehea_get_next_rwqe(qp, rq_nr);
491 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200492 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200494 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200495 rwqe->sg_list[0].len = packet_size;
496 rwqe->data_segments = 1;
497
498 index++;
499 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200500 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200501 }
Thomas Klein44c82152007-07-11 16:32:00 +0200502
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200504 if (adder == 0)
505 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200506
507 /* Ring doorbell */
508 iosync();
509 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200512 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200513out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200514 return ret;
515}
516
517
518static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
519{
520 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
521 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000522 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200523}
524
525
526static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
527{
528 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
529 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000530 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200531}
532
533static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
534{
535 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
536 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
537 return 0;
538 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
539 (cqe->header_length == 0))
540 return 0;
541 return -EINVAL;
542}
543
544static inline void ehea_fill_skb(struct net_device *dev,
545 struct sk_buff *skb, struct ehea_cqe *cqe)
546{
547 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
548
549 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200550 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000551
552 /* The packet was not an IPV4 packet so a complemented checksum was
553 calculated. The value is found in the Internet Checksum field. */
554 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
555 skb->ip_summed = CHECKSUM_COMPLETE;
556 skb->csum = csum_unfold(~cqe->inet_checksum_value);
557 } else
558 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200559}
560
561static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
562 int arr_len,
563 struct ehea_cqe *cqe)
564{
565 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
566 struct sk_buff *skb;
567 void *pref;
568 int x;
569
570 x = skb_index + 1;
571 x &= (arr_len - 1);
572
573 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700574 if (pref) {
575 prefetchw(pref);
576 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200577
Hannes Hering0b2febf2009-05-04 11:06:37 -0700578 pref = (skb_array[x]->data);
579 prefetch(pref);
580 prefetch(pref + EHEA_CACHE_LINE);
581 prefetch(pref + EHEA_CACHE_LINE * 2);
582 prefetch(pref + EHEA_CACHE_LINE * 3);
583 }
584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200585 skb = skb_array[skb_index];
586 skb_array[skb_index] = NULL;
587 return skb;
588}
589
590static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
591 int arr_len, int wqe_index)
592{
593 struct sk_buff *skb;
594 void *pref;
595 int x;
596
597 x = wqe_index + 1;
598 x &= (arr_len - 1);
599
600 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700601 if (pref) {
602 prefetchw(pref);
603 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200604
Hannes Hering0b2febf2009-05-04 11:06:37 -0700605 pref = (skb_array[x]->data);
606 prefetchw(pref);
607 prefetchw(pref + EHEA_CACHE_LINE);
608 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200609
610 skb = skb_array[wqe_index];
611 skb_array[wqe_index] = NULL;
612 return skb;
613}
614
615static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
616 struct ehea_cqe *cqe, int *processed_rq2,
617 int *processed_rq3)
618{
619 struct sk_buff *skb;
620
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100621 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
622 pr->p_stats.err_tcp_cksum++;
623 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
624 pr->p_stats.err_ip_cksum++;
625 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
626 pr->p_stats.err_frame_crc++;
627
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200628 if (rq == 2) {
629 *processed_rq2 += 1;
630 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
631 dev_kfree_skb(skb);
632 } else if (rq == 3) {
633 *processed_rq3 += 1;
634 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
635 dev_kfree_skb(skb);
636 }
637
638 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100639 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800640 pr_err("Critical receive error for QP %d. Resetting port.\n",
641 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100642 ehea_dump(cqe, sizeof(*cqe), "CQE");
643 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100644 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200645 return 1;
646 }
647
648 return 0;
649}
650
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700651static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
652 void **tcph, u64 *hdr_flags, void *priv)
653{
654 struct ehea_cqe *cqe = priv;
655 unsigned int ip_len;
656 struct iphdr *iph;
657
658 /* non tcp/udp packets */
659 if (!cqe->header_length)
660 return -1;
661
662 /* non tcp packet */
663 skb_reset_network_header(skb);
664 iph = ip_hdr(skb);
665 if (iph->protocol != IPPROTO_TCP)
666 return -1;
667
668 ip_len = ip_hdrlen(skb);
669 skb_set_transport_header(skb, ip_len);
670 *tcph = tcp_hdr(skb);
671
672 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700673 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700674 return -1;
675
676 *hdr_flags = LRO_IPV4 | LRO_TCP;
677 *iphdr = iph;
678
679 return 0;
680}
681
682static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
683 struct sk_buff *skb)
684{
Joe Perches8e95a202009-12-03 07:58:21 +0000685 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
686 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700687
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800688 if (skb->dev->features & NETIF_F_LRO) {
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700689 if (vlan_extracted)
690 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
691 pr->port->vgrp,
692 cqe->vlan_tag,
693 cqe);
694 else
695 lro_receive_skb(&pr->lro_mgr, skb, cqe);
696 } else {
697 if (vlan_extracted)
698 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
699 cqe->vlan_tag);
700 else
701 netif_receive_skb(skb);
702 }
703}
704
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700705static int ehea_proc_rwqes(struct net_device *dev,
706 struct ehea_port_res *pr,
707 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100709 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710 struct ehea_qp *qp = pr->qp;
711 struct ehea_cqe *cqe;
712 struct sk_buff *skb;
713 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
714 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
715 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
716 int skb_arr_rq1_len = pr->rq1_skba.len;
717 int skb_arr_rq2_len = pr->rq2_skba.len;
718 int skb_arr_rq3_len = pr->rq3_skba.len;
719 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000720 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700721 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722
723 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
724 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200726 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700727 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200728 ehea_inc_rq1(qp);
729 processed_rq1++;
730 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200731 if (netif_msg_rx_status(port))
732 ehea_dump(cqe, sizeof(*cqe), "CQE");
733
734 last_wqe_index = wqe_index;
735 rmb();
736 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600737 if (rq == 1) {
738 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200739 skb = get_skb_by_index_ll(skb_arr_rq1,
740 skb_arr_rq1_len,
741 wqe_index);
742 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800743 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800744 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100745
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700746 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000748 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800749 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000751 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200752 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600753 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200754 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700755 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600756 } else if (rq == 2) {
757 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200758 skb = get_skb_by_index(skb_arr_rq2,
759 skb_arr_rq2_len, cqe);
760 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800761 netif_err(port, rx_err, dev,
762 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763 break;
764 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700765 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600767 } else {
768 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200769 skb = get_skb_by_index(skb_arr_rq3,
770 skb_arr_rq3_len, cqe);
771 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800772 netif_err(port, rx_err, dev,
773 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200774 break;
775 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700776 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777 processed_rq3++;
778 }
779
Breno Leitaoce45b872010-10-27 08:45:14 +0000780 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700781 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100782 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100783 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784 port_reset = ehea_treat_poll_error(pr, rq, cqe,
785 &processed_rq2,
786 &processed_rq3);
787 if (port_reset)
788 break;
789 }
790 cqe = ehea_poll_rq1(qp, &wqe_index);
791 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800792 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700793 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200794
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200795 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000796 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200797
798 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
799 ehea_refill_rq2(pr, processed_rq2);
800 ehea_refill_rq3(pr, processed_rq3);
801
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700802 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200803}
804
Andre Detsch2928db42010-08-17 05:49:12 +0000805#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
806
807static void reset_sq_restart_flag(struct ehea_port *port)
808{
809 int i;
810
811 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
812 struct ehea_port_res *pr = &port->port_res[i];
813 pr->sq_restart_flag = 0;
814 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000815 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000816}
817
818static void check_sqs(struct ehea_port *port)
819{
820 struct ehea_swqe *swqe;
821 int swqe_index;
822 int i, k;
823
824 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
825 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000826 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000827 k = 0;
828 swqe = ehea_get_swqe(pr->qp, &swqe_index);
829 memset(swqe, 0, SWQE_HEADER_SIZE);
830 atomic_dec(&pr->swqe_avail);
831
832 swqe->tx_control |= EHEA_SWQE_PURGE;
833 swqe->wr_id = SWQE_RESTART_CHECK;
834 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
835 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
836 swqe->immediate_data_length = 80;
837
838 ehea_post_swqe(pr->qp, swqe);
839
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000840 ret = wait_event_timeout(port->restart_wq,
841 pr->sq_restart_flag == 0,
842 msecs_to_jiffies(100));
843
844 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800845 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000846 ehea_schedule_port_reset(pr->port);
847 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000848 }
849 }
Andre Detsch2928db42010-08-17 05:49:12 +0000850}
851
852
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100853static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200854{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100855 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856 struct ehea_cq *send_cq = pr->send_cq;
857 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100858 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200859 int cqe_counter = 0;
860 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100861 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200862 unsigned long flags;
863
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600865 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100866 ehea_inc_cq(send_cq);
867
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868 cqe_counter++;
869 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000870
871 if (cqe->wr_id == SWQE_RESTART_CHECK) {
872 pr->sq_restart_flag = 1;
873 swqe_av++;
874 break;
875 }
876
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800878 pr_err("Bad send completion status=0x%04X\n",
879 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000880
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200881 if (netif_msg_tx_err(pr->port))
882 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000883
884 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800885 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000886 ehea_schedule_port_reset(pr->port);
887 break;
888 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200889 }
890
891 if (netif_msg_tx_done(pr->port))
892 ehea_dump(cqe, sizeof(*cqe), "CQE");
893
894 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100895 == EHEA_SWQE2_TYPE)) {
896
897 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
898 skb = pr->sq_skba.arr[index];
899 dev_kfree_skb(skb);
900 pr->sq_skba.arr[index] = NULL;
901 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902
903 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
904 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100905
906 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700907 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200908
909 ehea_update_feca(send_cq, cqe_counter);
910 atomic_add(swqe_av, &pr->swqe_avail);
911
912 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100913
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200914 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
915 >= pr->swqe_refill_th)) {
916 netif_wake_queue(pr->port->netdev);
917 pr->queue_stopped = 0;
918 }
919 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000920 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200921
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100922 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200923}
924
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100925#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700926#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100927
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700928static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929{
Doug Maxey508d2b52008-01-31 20:20:49 -0600930 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
931 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700932 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100933 struct ehea_cqe *cqe;
934 struct ehea_cqe *cqe_skb = NULL;
935 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100937
938 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700939 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100940
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700941 if (!force_irq)
942 rx += ehea_proc_rwqes(dev, pr, budget - rx);
943
944 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100945 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700946 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800947 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100948 ehea_reset_cq_ep(pr->recv_cq);
949 ehea_reset_cq_ep(pr->send_cq);
950 ehea_reset_cq_n1(pr->recv_cq);
951 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000952 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100953 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
954 cqe_skb = ehea_poll_cq(pr->send_cq);
955
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100956 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700957 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100958
Ben Hutchings288379f2009-01-19 16:43:59 -0800959 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700960 return rx;
961
962 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
963 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100964 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100965
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700966 pr->poll_counter++;
967 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200968}
969
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200970#ifdef CONFIG_NET_POLL_CONTROLLER
971static void ehea_netpoll(struct net_device *dev)
972{
973 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700974 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200975
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700976 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800977 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200978}
979#endif
980
David Howells7d12e782006-10-05 14:55:46 +0100981static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200982{
983 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100984
Ben Hutchings288379f2009-01-19 16:43:59 -0800985 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100986
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200987 return IRQ_HANDLED;
988}
989
David Howells7d12e782006-10-05 14:55:46 +0100990static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200991{
992 struct ehea_port *port = param;
993 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100994 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200995 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000996 u64 resource_type, aer, aerr;
997 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998
999 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001000
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001001 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001002 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -08001003 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1004 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001005
1006 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001007
1008 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1009 &aer, &aerr);
1010
1011 if (resource_type == EHEA_AER_RESTYPE_QP) {
1012 if ((aer & EHEA_AER_RESET_MASK) ||
1013 (aerr & EHEA_AERR_RESET_MASK))
1014 reset_port = 1;
1015 } else
1016 reset_port = 1; /* Reset in case of CQ or EQ error */
1017
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001018 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001019 }
1020
Thomas Kleinea96cea2010-04-20 23:10:55 +00001021 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001022 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001023 ehea_schedule_port_reset(port);
1024 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001025
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001026 return IRQ_HANDLED;
1027}
1028
1029static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1030 int logical_port)
1031{
1032 int i;
1033
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001034 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001035 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001036 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001037 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001038 return NULL;
1039}
1040
1041int ehea_sense_port_attr(struct ehea_port *port)
1042{
1043 int ret;
1044 u64 hret;
1045 struct hcp_ehea_port_cb0 *cb0;
1046
Doug Maxey508d2b52008-01-31 20:20:49 -06001047 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001048 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001049 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001050 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001051 ret = -ENOMEM;
1052 goto out;
1053 }
1054
1055 hret = ehea_h_query_ehea_port(port->adapter->handle,
1056 port->logical_port_id, H_PORT_CB0,
1057 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1058 cb0);
1059 if (hret != H_SUCCESS) {
1060 ret = -EIO;
1061 goto out_free;
1062 }
1063
1064 /* MAC address */
1065 port->mac_addr = cb0->port_mac_addr << 16;
1066
Doug Maxey508d2b52008-01-31 20:20:49 -06001067 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001068 ret = -EADDRNOTAVAIL;
1069 goto out_free;
1070 }
1071
1072 /* Port speed */
1073 switch (cb0->port_speed) {
1074 case H_SPEED_10M_H:
1075 port->port_speed = EHEA_SPEED_10M;
1076 port->full_duplex = 0;
1077 break;
1078 case H_SPEED_10M_F:
1079 port->port_speed = EHEA_SPEED_10M;
1080 port->full_duplex = 1;
1081 break;
1082 case H_SPEED_100M_H:
1083 port->port_speed = EHEA_SPEED_100M;
1084 port->full_duplex = 0;
1085 break;
1086 case H_SPEED_100M_F:
1087 port->port_speed = EHEA_SPEED_100M;
1088 port->full_duplex = 1;
1089 break;
1090 case H_SPEED_1G_F:
1091 port->port_speed = EHEA_SPEED_1G;
1092 port->full_duplex = 1;
1093 break;
1094 case H_SPEED_10G_F:
1095 port->port_speed = EHEA_SPEED_10G;
1096 port->full_duplex = 1;
1097 break;
1098 default:
1099 port->port_speed = 0;
1100 port->full_duplex = 0;
1101 break;
1102 }
1103
Thomas Kleine919b592007-01-22 12:53:20 +01001104 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001105 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001106
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001107 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001108 if (use_mcs)
1109 port->num_def_qps = cb0->num_default_qps;
1110 else
1111 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001112
1113 if (!port->num_def_qps) {
1114 ret = -EINVAL;
1115 goto out_free;
1116 }
1117
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001118 port->num_tx_qps = num_tx_qps;
1119
1120 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001121 port->num_add_tx_qps = 0;
1122 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001123 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001124
1125 ret = 0;
1126out_free:
1127 if (ret || netif_msg_probe(port))
1128 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001129 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001130out:
1131 return ret;
1132}
1133
1134int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1135{
1136 struct hcp_ehea_port_cb4 *cb4;
1137 u64 hret;
1138 int ret = 0;
1139
Thomas Klein3faf2692009-01-21 14:45:33 -08001140 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001142 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001143 ret = -ENOMEM;
1144 goto out;
1145 }
1146
1147 cb4->port_speed = port_speed;
1148
1149 netif_carrier_off(port->netdev);
1150
1151 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1152 port->logical_port_id,
1153 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1154 if (hret == H_SUCCESS) {
1155 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1156
1157 hret = ehea_h_query_ehea_port(port->adapter->handle,
1158 port->logical_port_id,
1159 H_PORT_CB4, H_PORT_CB4_SPEED,
1160 cb4);
1161 if (hret == H_SUCCESS) {
1162 switch (cb4->port_speed) {
1163 case H_SPEED_10M_H:
1164 port->port_speed = EHEA_SPEED_10M;
1165 port->full_duplex = 0;
1166 break;
1167 case H_SPEED_10M_F:
1168 port->port_speed = EHEA_SPEED_10M;
1169 port->full_duplex = 1;
1170 break;
1171 case H_SPEED_100M_H:
1172 port->port_speed = EHEA_SPEED_100M;
1173 port->full_duplex = 0;
1174 break;
1175 case H_SPEED_100M_F:
1176 port->port_speed = EHEA_SPEED_100M;
1177 port->full_duplex = 1;
1178 break;
1179 case H_SPEED_1G_F:
1180 port->port_speed = EHEA_SPEED_1G;
1181 port->full_duplex = 1;
1182 break;
1183 case H_SPEED_10G_F:
1184 port->port_speed = EHEA_SPEED_10G;
1185 port->full_duplex = 1;
1186 break;
1187 default:
1188 port->port_speed = 0;
1189 port->full_duplex = 0;
1190 break;
1191 }
1192 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001193 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001194 ret = -EIO;
1195 }
1196 } else {
1197 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001198 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001199 ret = -EPERM;
1200 } else {
1201 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001202 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001203 }
1204 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001205 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1206 netif_carrier_on(port->netdev);
1207
Thomas Klein3faf2692009-01-21 14:45:33 -08001208 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001209out:
1210 return ret;
1211}
1212
1213static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1214{
1215 int ret;
1216 u8 ec;
1217 u8 portnum;
1218 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001219 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001220
1221 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1222 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1223 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001224 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001225
1226 switch (ec) {
1227 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1228
1229 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001230 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231 break;
1232 }
1233
1234 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001235 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001236 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001237 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001238 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239 break;
1240 }
1241
Joe Perches8c4877a2010-12-13 10:05:14 -08001242 netif_info(port, link, dev,
1243 "Logical port up: %dMbps %s Duplex\n",
1244 port->port_speed,
1245 port->full_duplex == 1 ?
1246 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247
Joe Perches8c4877a2010-12-13 10:05:14 -08001248 netif_carrier_on(dev);
1249 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250 }
1251 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001252 if (netif_carrier_ok(dev)) {
1253 netif_info(port, link, dev,
1254 "Logical port down\n");
1255 netif_carrier_off(dev);
1256 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001257 }
1258
1259 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001260 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001261 netif_info(port, link, dev,
1262 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001263 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001264 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001265 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001266 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001267 netif_info(port, link, dev,
1268 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001269 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001270 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271 }
1272
1273 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001274 netdev_info(dev,
1275 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001276 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001277 netdev_info(dev,
1278 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001279
1280 break;
1281 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001282 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283 break;
1284 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001285 netdev_info(dev, "Port malfunction\n");
1286 netif_carrier_off(dev);
1287 netif_stop_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 break;
1289 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001290 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001291 break;
1292 }
1293}
1294
1295static void ehea_neq_tasklet(unsigned long data)
1296{
Doug Maxey508d2b52008-01-31 20:20:49 -06001297 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001298 struct ehea_eqe *eqe;
1299 u64 event_mask;
1300
1301 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001302 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303
1304 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001305 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001306 ehea_parse_eqe(adapter, eqe->entry);
1307 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001308 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001309 }
1310
1311 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1312 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1313 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1314
1315 ehea_h_reset_events(adapter->handle,
1316 adapter->neq->fw_handle, event_mask);
1317}
1318
David Howells7d12e782006-10-05 14:55:46 +01001319static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320{
1321 struct ehea_adapter *adapter = param;
1322 tasklet_hi_schedule(&adapter->neq_tasklet);
1323 return IRQ_HANDLED;
1324}
1325
1326
1327static int ehea_fill_port_res(struct ehea_port_res *pr)
1328{
1329 int ret;
1330 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1331
Breno Leitaof76957f2011-01-11 07:45:57 +00001332 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001333
Thomas Kleine2878802009-01-21 14:45:57 -08001334 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001335
1336 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1337
1338 return ret;
1339}
1340
1341static int ehea_reg_interrupts(struct net_device *dev)
1342{
1343 struct ehea_port *port = netdev_priv(dev);
1344 struct ehea_port_res *pr;
1345 int i, ret;
1346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347
1348 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1349 dev->name);
1350
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001351 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001352 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001353 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001355 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1356 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 goto out_free_qpeq;
1358 }
1359
Joe Perches8c4877a2010-12-13 10:05:14 -08001360 netif_info(port, ifup, dev,
1361 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1362 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001363
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001364
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001365 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1366 pr = &port->port_res[i];
1367 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001368 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001369 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001370 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001371 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001372 pr);
1373 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001374 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1375 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376 goto out_free_req;
1377 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001378 netif_info(port, ifup, dev,
1379 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1380 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001381 }
1382out:
1383 return ret;
1384
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386out_free_req:
1387 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001389 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001391
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001393 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001395
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398}
1399
1400static void ehea_free_interrupts(struct net_device *dev)
1401{
1402 struct ehea_port *port = netdev_priv(dev);
1403 struct ehea_port_res *pr;
1404 int i;
1405
1406 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001407
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001408 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1409 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001410 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001411 netif_info(port, intr, dev,
1412 "free send irq for res %d with handle 0x%X\n",
1413 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 }
1415
1416 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001417 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001418 netif_info(port, intr, dev,
1419 "associated event interrupt for handle 0x%X freed\n",
1420 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001421}
1422
1423static int ehea_configure_port(struct ehea_port *port)
1424{
1425 int ret, i;
1426 u64 hret, mask;
1427 struct hcp_ehea_port_cb0 *cb0;
1428
1429 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001430 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001431 if (!cb0)
1432 goto out;
1433
1434 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1435 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1436 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1437 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1439 PXLY_RC_VLAN_FILTER)
1440 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1441
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001442 for (i = 0; i < port->num_mcs; i++)
1443 if (use_mcs)
1444 cb0->default_qpn_arr[i] =
1445 port->port_res[i].qp->init_attr.qp_nr;
1446 else
1447 cb0->default_qpn_arr[i] =
1448 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001449
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001450 if (netif_msg_ifup(port))
1451 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1452
1453 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1454 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1455
1456 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1457 port->logical_port_id,
1458 H_PORT_CB0, mask, cb0);
1459 ret = -EIO;
1460 if (hret != H_SUCCESS)
1461 goto out_free;
1462
1463 ret = 0;
1464
1465out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001466 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001467out:
1468 return ret;
1469}
1470
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001471int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001472{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474 struct ehea_adapter *adapter = pr->port->adapter;
1475
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001476 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1477 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478 goto out;
1479
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001480 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1481 if (ret)
1482 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483
1484 return 0;
1485
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001486out_free:
1487 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001488out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001489 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490 return -EIO;
1491}
1492
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001493int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001494{
Joe Perches8e95a202009-12-03 07:58:21 +00001495 if ((ehea_rem_mr(&pr->send_mr)) ||
1496 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001497 return -EIO;
1498 else
1499 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500}
1501
1502static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1503{
Doug Maxey508d2b52008-01-31 20:20:49 -06001504 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001505
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001506 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507 if (!q_skba->arr)
1508 return -ENOMEM;
1509
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001510 q_skba->len = max_q_entries;
1511 q_skba->index = 0;
1512 q_skba->os_skbs = 0;
1513
1514 return 0;
1515}
1516
1517static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1518 struct port_res_cfg *pr_cfg, int queue_token)
1519{
1520 struct ehea_adapter *adapter = port->adapter;
1521 enum ehea_eq_type eq_type = EHEA_EQ;
1522 struct ehea_qp_init_attr *init_attr = NULL;
1523 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001524 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1525
1526 tx_bytes = pr->tx_bytes;
1527 tx_packets = pr->tx_packets;
1528 rx_bytes = pr->rx_bytes;
1529 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001530
1531 memset(pr, 0, sizeof(struct ehea_port_res));
1532
Breno Leitaoce45b872010-10-27 08:45:14 +00001533 pr->tx_bytes = rx_bytes;
1534 pr->tx_packets = tx_packets;
1535 pr->rx_bytes = rx_bytes;
1536 pr->rx_packets = rx_packets;
1537
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001538 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001539 spin_lock_init(&pr->xmit_lock);
1540 spin_lock_init(&pr->netif_queue);
1541
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001542 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1543 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001544 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001545 goto out_free;
1546 }
1547
1548 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001549 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001550 port->logical_port_id);
1551 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001552 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001553 goto out_free;
1554 }
1555
1556 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001557 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558 port->logical_port_id);
1559 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001560 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561 goto out_free;
1562 }
1563
1564 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001565 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1566 pr->send_cq->attr.act_nr_of_cqes,
1567 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001568
1569 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1570 if (!init_attr) {
1571 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001572 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001573 goto out_free;
1574 }
1575
1576 init_attr->low_lat_rq1 = 1;
1577 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1578 init_attr->rq_count = 3;
1579 init_attr->qp_token = queue_token;
1580 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1581 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1582 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1583 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1584 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1585 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1586 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1587 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1588 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1589 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1590 init_attr->port_nr = port->logical_port_id;
1591 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1592 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1593 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1594
1595 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1596 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001597 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001598 ret = -EIO;
1599 goto out_free;
1600 }
1601
1602 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001603 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",
1604 init_attr->qp_nr,
1605 init_attr->act_nr_send_wqes,
1606 init_attr->act_nr_rwqes_rq1,
1607 init_attr->act_nr_rwqes_rq2,
1608 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001609
Thomas Klein44fb3122008-04-04 15:04:53 +02001610 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1611
1612 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001613 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1614 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1615 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1616 if (ret)
1617 goto out_free;
1618
1619 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1620 if (ehea_gen_smrs(pr) != 0) {
1621 ret = -EIO;
1622 goto out_free;
1623 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001624
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1626
1627 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001628
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001629 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001630
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001631 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1632 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1633 pr->lro_mgr.lro_arr = pr->lro_desc;
1634 pr->lro_mgr.get_skb_header = get_skb_hdr;
1635 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1636 pr->lro_mgr.dev = port->netdev;
1637 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1638 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001640 ret = 0;
1641 goto out;
1642
1643out_free:
1644 kfree(init_attr);
1645 vfree(pr->sq_skba.arr);
1646 vfree(pr->rq1_skba.arr);
1647 vfree(pr->rq2_skba.arr);
1648 vfree(pr->rq3_skba.arr);
1649 ehea_destroy_qp(pr->qp);
1650 ehea_destroy_cq(pr->send_cq);
1651 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001652 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001653out:
1654 return ret;
1655}
1656
1657static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1658{
1659 int ret, i;
1660
Hannes Hering357eb462009-08-04 11:48:39 -07001661 if (pr->qp)
1662 netif_napi_del(&pr->napi);
1663
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664 ret = ehea_destroy_qp(pr->qp);
1665
1666 if (!ret) {
1667 ehea_destroy_cq(pr->send_cq);
1668 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001669 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001670
1671 for (i = 0; i < pr->rq1_skba.len; i++)
1672 if (pr->rq1_skba.arr[i])
1673 dev_kfree_skb(pr->rq1_skba.arr[i]);
1674
1675 for (i = 0; i < pr->rq2_skba.len; i++)
1676 if (pr->rq2_skba.arr[i])
1677 dev_kfree_skb(pr->rq2_skba.arr[i]);
1678
1679 for (i = 0; i < pr->rq3_skba.len; i++)
1680 if (pr->rq3_skba.arr[i])
1681 dev_kfree_skb(pr->rq3_skba.arr[i]);
1682
1683 for (i = 0; i < pr->sq_skba.len; i++)
1684 if (pr->sq_skba.arr[i])
1685 dev_kfree_skb(pr->sq_skba.arr[i]);
1686
1687 vfree(pr->rq1_skba.arr);
1688 vfree(pr->rq2_skba.arr);
1689 vfree(pr->rq3_skba.arr);
1690 vfree(pr->sq_skba.arr);
1691 ret = ehea_rem_smrs(pr);
1692 }
1693 return ret;
1694}
1695
1696/*
1697 * The write_* functions store information in swqe which is used by
1698 * the hardware to calculate the ip/tcp/udp checksum
1699 */
1700
1701static inline void write_ip_start_end(struct ehea_swqe *swqe,
1702 const struct sk_buff *skb)
1703{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001704 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001705 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001706}
1707
1708static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1709 const struct sk_buff *skb)
1710{
1711 swqe->tcp_offset =
1712 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1713
1714 swqe->tcp_end = (u16)skb->len - 1;
1715}
1716
1717static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1718 const struct sk_buff *skb)
1719{
1720 swqe->tcp_offset =
1721 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1722
1723 swqe->tcp_end = (u16)skb->len - 1;
1724}
1725
1726
1727static void write_swqe2_TSO(struct sk_buff *skb,
1728 struct ehea_swqe *swqe, u32 lkey)
1729{
1730 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1731 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001732 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001733 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001734
1735 /* Packet is TCP with TSO enabled */
1736 swqe->tx_control |= EHEA_SWQE_TSO;
1737 swqe->mss = skb_shinfo(skb)->gso_size;
1738 /* copy only eth/ip/tcp headers to immediate data and
1739 * the rest of skb->data to sg1entry
1740 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001741 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001742
Eric Dumazete743d312010-04-14 15:59:40 -07001743 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744
1745 if (skb_data_size >= headersize) {
1746 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001747 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001748 swqe->immediate_data_length = headersize;
1749
1750 if (skb_data_size > headersize) {
1751 /* set sg1entry data */
1752 sg1entry->l_key = lkey;
1753 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001754 sg1entry->vaddr =
1755 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001756 swqe->descriptors++;
1757 }
1758 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001759 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001760}
1761
1762static void write_swqe2_nonTSO(struct sk_buff *skb,
1763 struct ehea_swqe *swqe, u32 lkey)
1764{
Eric Dumazete743d312010-04-14 15:59:40 -07001765 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001766 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1767 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768
1769 /* Packet is any nonTSO type
1770 *
1771 * Copy as much as possible skb->data to immediate data and
1772 * the rest to sg1entry
1773 */
1774 if (skb_data_size >= SWQE2_MAX_IMM) {
1775 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001776 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001777
1778 swqe->immediate_data_length = SWQE2_MAX_IMM;
1779
1780 if (skb_data_size > SWQE2_MAX_IMM) {
1781 /* copy sg1entry data */
1782 sg1entry->l_key = lkey;
1783 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001784 sg1entry->vaddr =
1785 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001786 swqe->descriptors++;
1787 }
1788 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001789 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790 swqe->immediate_data_length = skb_data_size;
1791 }
1792}
1793
1794static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1795 struct ehea_swqe *swqe, u32 lkey)
1796{
1797 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1798 skb_frag_t *frag;
1799 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001800
1801 nfrags = skb_shinfo(skb)->nr_frags;
1802 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001803 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001804 swqe->descriptors = 0;
1805 sg1entry_contains_frag_data = 0;
1806
1807 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1808 write_swqe2_TSO(skb, swqe, lkey);
1809 else
1810 write_swqe2_nonTSO(skb, swqe, lkey);
1811
1812 /* write descriptors */
1813 if (nfrags > 0) {
1814 if (swqe->descriptors == 0) {
1815 /* sg1entry not yet used */
1816 frag = &skb_shinfo(skb)->frags[0];
1817
1818 /* copy sg1entry data */
1819 sg1entry->l_key = lkey;
1820 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001821 sg1entry->vaddr =
1822 ehea_map_vaddr(page_address(frag->page)
1823 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001824 swqe->descriptors++;
1825 sg1entry_contains_frag_data = 1;
1826 }
1827
1828 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1829
1830 frag = &skb_shinfo(skb)->frags[i];
1831 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1832
1833 sgentry->l_key = lkey;
1834 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001835 sgentry->vaddr =
1836 ehea_map_vaddr(page_address(frag->page)
1837 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001838 swqe->descriptors++;
1839 }
1840 }
1841}
1842
1843static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1844{
1845 int ret = 0;
1846 u64 hret;
1847 u8 reg_type;
1848
1849 /* De/Register untagged packets */
1850 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1851 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1852 port->logical_port_id,
1853 reg_type, port->mac_addr, 0, hcallid);
1854 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001855 pr_err("%sregistering bc address failed (tagged)\n",
1856 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001857 ret = -EIO;
1858 goto out_herr;
1859 }
1860
1861 /* De/Register VLAN packets */
1862 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1863 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1864 port->logical_port_id,
1865 reg_type, port->mac_addr, 0, hcallid);
1866 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001867 pr_err("%sregistering bc address failed (vlan)\n",
1868 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001869 ret = -EIO;
1870 }
1871out_herr:
1872 return ret;
1873}
1874
1875static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1876{
1877 struct ehea_port *port = netdev_priv(dev);
1878 struct sockaddr *mac_addr = sa;
1879 struct hcp_ehea_port_cb0 *cb0;
1880 int ret;
1881 u64 hret;
1882
1883 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1884 ret = -EADDRNOTAVAIL;
1885 goto out;
1886 }
1887
Thomas Klein3faf2692009-01-21 14:45:33 -08001888 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001889 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001890 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001891 ret = -ENOMEM;
1892 goto out;
1893 }
1894
1895 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1896
1897 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1898
1899 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1900 port->logical_port_id, H_PORT_CB0,
1901 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1902 if (hret != H_SUCCESS) {
1903 ret = -EIO;
1904 goto out_free;
1905 }
1906
1907 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1908
1909 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001910 if (port->state == EHEA_PORT_UP) {
1911 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1912 if (ret)
1913 goto out_upregs;
1914 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001915
1916 port->mac_addr = cb0->port_mac_addr << 16;
1917
1918 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001919 if (port->state == EHEA_PORT_UP) {
1920 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1921 if (ret)
1922 goto out_upregs;
1923 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001924
1925 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001926
1927out_upregs:
1928 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001929out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001930 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001931out:
1932 return ret;
1933}
1934
1935static void ehea_promiscuous_error(u64 hret, int enable)
1936{
Thomas Klein7674a582007-01-22 12:54:20 +01001937 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001938 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1939 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001940 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001941 pr_err("failed %sabling promiscuous mode\n",
1942 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001943}
1944
1945static void ehea_promiscuous(struct net_device *dev, int enable)
1946{
1947 struct ehea_port *port = netdev_priv(dev);
1948 struct hcp_ehea_port_cb7 *cb7;
1949 u64 hret;
1950
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001951 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001952 return;
1953
Thomas Klein3faf2692009-01-21 14:45:33 -08001954 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001955 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001956 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 goto out;
1958 }
1959
1960 /* Modify Pxs_DUCQPN in CB7 */
1961 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1962
1963 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1964 port->logical_port_id,
1965 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1966 if (hret) {
1967 ehea_promiscuous_error(hret, enable);
1968 goto out;
1969 }
1970
1971 port->promisc = enable;
1972out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001973 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001974}
1975
1976static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1977 u32 hcallid)
1978{
1979 u64 hret;
1980 u8 reg_type;
1981
1982 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1983 | EHEA_BCMC_UNTAGGED;
1984
1985 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1986 port->logical_port_id,
1987 reg_type, mc_mac_addr, 0, hcallid);
1988 if (hret)
1989 goto out;
1990
1991 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1992 | EHEA_BCMC_VLANID_ALL;
1993
1994 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1995 port->logical_port_id,
1996 reg_type, mc_mac_addr, 0, hcallid);
1997out:
1998 return hret;
1999}
2000
2001static int ehea_drop_multicast_list(struct net_device *dev)
2002{
2003 struct ehea_port *port = netdev_priv(dev);
2004 struct ehea_mc_list *mc_entry = port->mc_list;
2005 struct list_head *pos;
2006 struct list_head *temp;
2007 int ret = 0;
2008 u64 hret;
2009
2010 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2011 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2012
2013 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2014 H_DEREG_BCMC);
2015 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002016 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002017 ret = -EIO;
2018 }
2019
2020 list_del(pos);
2021 kfree(mc_entry);
2022 }
2023 return ret;
2024}
2025
2026static void ehea_allmulti(struct net_device *dev, int enable)
2027{
2028 struct ehea_port *port = netdev_priv(dev);
2029 u64 hret;
2030
2031 if (!port->allmulti) {
2032 if (enable) {
2033 /* Enable ALLMULTI */
2034 ehea_drop_multicast_list(dev);
2035 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2036 if (!hret)
2037 port->allmulti = 1;
2038 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002039 netdev_err(dev,
2040 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002041 }
2042 } else
2043 if (!enable) {
2044 /* Disable ALLMULTI */
2045 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2046 if (!hret)
2047 port->allmulti = 0;
2048 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002049 netdev_err(dev,
2050 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051 }
2052}
2053
Doug Maxey508d2b52008-01-31 20:20:49 -06002054static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002055{
2056 struct ehea_mc_list *ehea_mcl_entry;
2057 u64 hret;
2058
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002059 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002060 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002061 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002062 return;
2063 }
2064
2065 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2066
2067 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2068
2069 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2070 H_REG_BCMC);
2071 if (!hret)
2072 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2073 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002074 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002075 kfree(ehea_mcl_entry);
2076 }
2077}
2078
2079static void ehea_set_multicast_list(struct net_device *dev)
2080{
2081 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002082 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002083 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084
2085 if (dev->flags & IFF_PROMISC) {
2086 ehea_promiscuous(dev, 1);
2087 return;
2088 }
2089 ehea_promiscuous(dev, 0);
2090
2091 if (dev->flags & IFF_ALLMULTI) {
2092 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002093 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002094 }
2095 ehea_allmulti(dev, 0);
2096
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002097 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002098 ret = ehea_drop_multicast_list(dev);
2099 if (ret) {
2100 /* Dropping the current multicast list failed.
2101 * Enabling ALL_MULTI is the best we can do.
2102 */
2103 ehea_allmulti(dev, 1);
2104 }
2105
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002106 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002107 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2108 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109 goto out;
2110 }
2111
Jiri Pirko22bedad32010-04-01 21:22:57 +00002112 netdev_for_each_mc_addr(ha, dev)
2113 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002114
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115 }
2116out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002117 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002118}
2119
2120static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2121{
2122 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2123 return -EINVAL;
2124 dev->mtu = new_mtu;
2125 return 0;
2126}
2127
2128static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2129 struct ehea_swqe *swqe, u32 lkey)
2130{
2131 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002132 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002133
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002134 /* IPv4 */
2135 swqe->tx_control |= EHEA_SWQE_CRC
2136 | EHEA_SWQE_IP_CHECKSUM
2137 | EHEA_SWQE_TCP_CHECKSUM
2138 | EHEA_SWQE_IMM_DATA_PRESENT
2139 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2140
2141 write_ip_start_end(swqe, skb);
2142
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002143 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002144 if ((iph->frag_off & IP_MF) ||
2145 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002146 /* IP fragment, so don't change cs */
2147 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2148 else
2149 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002150 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151 write_tcp_offset_end(swqe, skb);
2152 }
2153
2154 /* icmp (big data) and ip segmentation packets (all other ip
2155 packets) do not require any special handling */
2156
2157 } else {
2158 /* Other Ethernet Protocol */
2159 swqe->tx_control |= EHEA_SWQE_CRC
2160 | EHEA_SWQE_IMM_DATA_PRESENT
2161 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2162 }
2163
2164 write_swqe2_data(skb, dev, swqe, lkey);
2165}
2166
2167static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2168 struct ehea_swqe *swqe)
2169{
2170 int nfrags = skb_shinfo(skb)->nr_frags;
2171 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2172 skb_frag_t *frag;
2173 int i;
2174
2175 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002176 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002177
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002178 /* IPv4 */
2179 write_ip_start_end(swqe, skb);
2180
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002181 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182 swqe->tx_control |= EHEA_SWQE_CRC
2183 | EHEA_SWQE_IP_CHECKSUM
2184 | EHEA_SWQE_TCP_CHECKSUM
2185 | EHEA_SWQE_IMM_DATA_PRESENT;
2186
2187 write_tcp_offset_end(swqe, skb);
2188
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002189 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002190 if ((iph->frag_off & IP_MF) ||
2191 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192 /* IP fragment, so don't change cs */
2193 swqe->tx_control |= EHEA_SWQE_CRC
2194 | EHEA_SWQE_IMM_DATA_PRESENT;
2195 else {
2196 swqe->tx_control |= EHEA_SWQE_CRC
2197 | EHEA_SWQE_IP_CHECKSUM
2198 | EHEA_SWQE_TCP_CHECKSUM
2199 | EHEA_SWQE_IMM_DATA_PRESENT;
2200
2201 write_udp_offset_end(swqe, skb);
2202 }
2203 } else {
2204 /* icmp (big data) and
2205 ip segmentation packets (all other ip packets) */
2206 swqe->tx_control |= EHEA_SWQE_CRC
2207 | EHEA_SWQE_IP_CHECKSUM
2208 | EHEA_SWQE_IMM_DATA_PRESENT;
2209 }
2210 } else {
2211 /* Other Ethernet Protocol */
2212 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2213 }
2214 /* copy (immediate) data */
2215 if (nfrags == 0) {
2216 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002217 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002218 } else {
2219 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002220 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002221 skb_headlen(skb));
2222 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002223
2224 /* ... then copy data from the fragments */
2225 for (i = 0; i < nfrags; i++) {
2226 frag = &skb_shinfo(skb)->frags[i];
2227 memcpy(imm_data,
2228 page_address(frag->page) + frag->page_offset,
2229 frag->size);
2230 imm_data += frag->size;
2231 }
2232 }
2233 swqe->immediate_data_length = skb->len;
2234 dev_kfree_skb(skb);
2235}
2236
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002237static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2238{
2239 struct tcphdr *tcp;
2240 u32 tmp;
2241
2242 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002243 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002244 tcp = (struct tcphdr *)(skb_network_header(skb) +
2245 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002246 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002247 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002248 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002249 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002250 return 0;
2251}
2252
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002253static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2254{
2255 struct ehea_port *port = netdev_priv(dev);
2256 struct ehea_swqe *swqe;
2257 unsigned long flags;
2258 u32 lkey;
2259 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002260 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002261
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002262 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2263
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002264 if (!spin_trylock(&pr->xmit_lock))
2265 return NETDEV_TX_BUSY;
2266
2267 if (pr->queue_stopped) {
2268 spin_unlock(&pr->xmit_lock);
2269 return NETDEV_TX_BUSY;
2270 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002271
2272 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2273 memset(swqe, 0, SWQE_HEADER_SIZE);
2274 atomic_dec(&pr->swqe_avail);
2275
Eric Dumazete5ccd962010-10-26 19:21:07 +00002276 if (vlan_tx_tag_present(skb)) {
2277 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2278 swqe->vlan_tag = vlan_tx_tag_get(skb);
2279 }
2280
Breno Leitaoce45b872010-10-27 08:45:14 +00002281 pr->tx_packets++;
2282 pr->tx_bytes += skb->len;
2283
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002284 if (skb->len <= SWQE3_MAX_IMM) {
2285 u32 sig_iv = port->sig_comp_iv;
2286 u32 swqe_num = pr->swqe_id_counter;
2287 ehea_xmit3(skb, dev, swqe);
2288 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2289 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2290 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2291 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2292 sig_iv);
2293 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2294 pr->swqe_ll_count = 0;
2295 } else
2296 pr->swqe_ll_count += 1;
2297 } else {
2298 swqe->wr_id =
2299 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2300 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002301 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002302 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2303 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2304
2305 pr->sq_skba.index++;
2306 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2307
2308 lkey = pr->send_mr.lkey;
2309 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002310 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002311 }
2312 pr->swqe_id_counter += 1;
2313
Joe Perches8c4877a2010-12-13 10:05:14 -08002314 netif_info(port, tx_queued, dev,
2315 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2316 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002317 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002318
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002319 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2320 netif_stop_queue(dev);
2321 swqe->tx_control |= EHEA_SWQE_PURGE;
2322 }
Thomas Klein44c82152007-07-11 16:32:00 +02002323
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002324 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002325
2326 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2327 spin_lock_irqsave(&pr->netif_queue, flags);
2328 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002329 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002330 netif_stop_queue(dev);
2331 pr->queue_stopped = 1;
2332 }
2333 spin_unlock_irqrestore(&pr->netif_queue, flags);
2334 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002335 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002336 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002337
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002338 return NETDEV_TX_OK;
2339}
2340
2341static void ehea_vlan_rx_register(struct net_device *dev,
2342 struct vlan_group *grp)
2343{
2344 struct ehea_port *port = netdev_priv(dev);
2345 struct ehea_adapter *adapter = port->adapter;
2346 struct hcp_ehea_port_cb1 *cb1;
2347 u64 hret;
2348
2349 port->vgrp = grp;
2350
Thomas Klein3faf2692009-01-21 14:45:33 -08002351 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002352 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002353 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354 goto out;
2355 }
2356
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002357 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2358 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2359 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002360 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361
Thomas Klein3faf2692009-01-21 14:45:33 -08002362 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002363out:
2364 return;
2365}
2366
2367static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2368{
2369 struct ehea_port *port = netdev_priv(dev);
2370 struct ehea_adapter *adapter = port->adapter;
2371 struct hcp_ehea_port_cb1 *cb1;
2372 int index;
2373 u64 hret;
2374
Thomas Klein3faf2692009-01-21 14:45:33 -08002375 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002376 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002377 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 goto out;
2379 }
2380
2381 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2382 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2383 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002384 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002385 goto out;
2386 }
2387
2388 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002389 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002390
2391 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2392 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2393 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002394 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002395out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002396 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397 return;
2398}
2399
2400static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2401{
2402 struct ehea_port *port = netdev_priv(dev);
2403 struct ehea_adapter *adapter = port->adapter;
2404 struct hcp_ehea_port_cb1 *cb1;
2405 int index;
2406 u64 hret;
2407
Dan Aloni5c15bde2007-03-02 20:44:51 -08002408 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002409
Thomas Klein3faf2692009-01-21 14:45:33 -08002410 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002411 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002412 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413 goto out;
2414 }
2415
2416 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2417 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2418 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002419 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002420 goto out;
2421 }
2422
2423 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002424 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425
2426 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2427 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2428 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002429 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002430out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002431 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432}
2433
2434int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2435{
2436 int ret = -EIO;
2437 u64 hret;
2438 u16 dummy16 = 0;
2439 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002440 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441
Thomas Klein3faf2692009-01-21 14:45:33 -08002442 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443 if (!cb0) {
2444 ret = -ENOMEM;
2445 goto out;
2446 }
2447
2448 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2449 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2450 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002451 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002452 goto out;
2453 }
2454
2455 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2456 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2457 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2458 &dummy64, &dummy64, &dummy16, &dummy16);
2459 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002460 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002461 goto out;
2462 }
2463
2464 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2465 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2466 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002467 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002468 goto out;
2469 }
2470
2471 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2472 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2473 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2474 &dummy64, &dummy64, &dummy16, &dummy16);
2475 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002476 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002477 goto out;
2478 }
2479
2480 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2481 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2482 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002483 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002484 goto out;
2485 }
2486
2487 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2488 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2489 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2490 &dummy64, &dummy64, &dummy16, &dummy16);
2491 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002492 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002493 goto out;
2494 }
2495
2496 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2497 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2498 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002499 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002500 goto out;
2501 }
2502
2503 ret = 0;
2504out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002505 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002506 return ret;
2507}
2508
2509static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2510 int add_tx_qps)
2511{
2512 int ret, i;
2513 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2514 enum ehea_eq_type eq_type = EHEA_EQ;
2515
2516 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2517 EHEA_MAX_ENTRIES_EQ, 1);
2518 if (!port->qp_eq) {
2519 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002520 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002521 goto out_kill_eq;
2522 }
2523
2524 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002525 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002526 pr_cfg.max_entries_sq = sq_entries;
2527 pr_cfg.max_entries_rq1 = rq1_entries;
2528 pr_cfg.max_entries_rq2 = rq2_entries;
2529 pr_cfg.max_entries_rq3 = rq3_entries;
2530
2531 pr_cfg_small_rx.max_entries_rcq = 1;
2532 pr_cfg_small_rx.max_entries_scq = sq_entries;
2533 pr_cfg_small_rx.max_entries_sq = sq_entries;
2534 pr_cfg_small_rx.max_entries_rq1 = 1;
2535 pr_cfg_small_rx.max_entries_rq2 = 1;
2536 pr_cfg_small_rx.max_entries_rq3 = 1;
2537
2538 for (i = 0; i < def_qps; i++) {
2539 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2540 if (ret)
2541 goto out_clean_pr;
2542 }
2543 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2544 ret = ehea_init_port_res(port, &port->port_res[i],
2545 &pr_cfg_small_rx, i);
2546 if (ret)
2547 goto out_clean_pr;
2548 }
2549
2550 return 0;
2551
2552out_clean_pr:
2553 while (--i >= 0)
2554 ehea_clean_portres(port, &port->port_res[i]);
2555
2556out_kill_eq:
2557 ehea_destroy_eq(port->qp_eq);
2558 return ret;
2559}
2560
2561static int ehea_clean_all_portres(struct ehea_port *port)
2562{
2563 int ret = 0;
2564 int i;
2565
Doug Maxey508d2b52008-01-31 20:20:49 -06002566 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002567 ret |= ehea_clean_portres(port, &port->port_res[i]);
2568
2569 ret |= ehea_destroy_eq(port->qp_eq);
2570
2571 return ret;
2572}
2573
Thomas Klein35cf2e22007-08-06 13:55:14 +02002574static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002575{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002576 if (adapter->active_ports)
2577 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002578
2579 ehea_rem_mr(&adapter->mr);
2580}
2581
Thomas Klein35cf2e22007-08-06 13:55:14 +02002582static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002583{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002584 if (adapter->active_ports)
2585 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002586
2587 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2588}
2589
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002590static int ehea_up(struct net_device *dev)
2591{
2592 int ret, i;
2593 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002594
2595 if (port->state == EHEA_PORT_UP)
2596 return 0;
2597
2598 ret = ehea_port_res_setup(port, port->num_def_qps,
2599 port->num_add_tx_qps);
2600 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002601 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002602 goto out;
2603 }
2604
2605 /* Set default QP for this port */
2606 ret = ehea_configure_port(port);
2607 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002608 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002609 goto out_clean_pr;
2610 }
2611
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612 ret = ehea_reg_interrupts(dev);
2613 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002614 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002615 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002616 }
2617
Doug Maxey508d2b52008-01-31 20:20:49 -06002618 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002619 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2620 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002621 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002622 goto out_free_irqs;
2623 }
2624 }
2625
Doug Maxey508d2b52008-01-31 20:20:49 -06002626 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002627 ret = ehea_fill_port_res(&port->port_res[i]);
2628 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002629 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002630 goto out_free_irqs;
2631 }
2632 }
2633
Thomas Klein21eee2d2008-02-13 16:18:33 +01002634 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2635 if (ret) {
2636 ret = -EIO;
2637 goto out_free_irqs;
2638 }
2639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002640 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002641
2642 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002643 goto out;
2644
2645out_free_irqs:
2646 ehea_free_interrupts(dev);
2647
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002648out_clean_pr:
2649 ehea_clean_all_portres(port);
2650out:
Thomas Klein44c82152007-07-11 16:32:00 +02002651 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002652 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002653
Thomas Klein21eee2d2008-02-13 16:18:33 +01002654 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002655 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002656
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002657 return ret;
2658}
2659
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002660static void port_napi_disable(struct ehea_port *port)
2661{
2662 int i;
2663
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002664 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002665 napi_disable(&port->port_res[i].napi);
2666}
2667
2668static void port_napi_enable(struct ehea_port *port)
2669{
2670 int i;
2671
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002672 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002673 napi_enable(&port->port_res[i].napi);
2674}
2675
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002676static int ehea_open(struct net_device *dev)
2677{
2678 int ret;
2679 struct ehea_port *port = netdev_priv(dev);
2680
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002681 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002682
Joe Perches8c4877a2010-12-13 10:05:14 -08002683 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002684
2685 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002686 if (!ret) {
2687 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002688 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002689 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002690
Breno Leitao5b27d422010-10-05 13:16:22 +00002691 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002692 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002693
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002694 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002695
2696 return ret;
2697}
2698
2699static int ehea_down(struct net_device *dev)
2700{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002701 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002702 struct ehea_port *port = netdev_priv(dev);
2703
2704 if (port->state == EHEA_PORT_DOWN)
2705 return 0;
2706
2707 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002708 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2709
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002710 ehea_free_interrupts(dev);
2711
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002713
Thomas Klein21eee2d2008-02-13 16:18:33 +01002714 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002715
Thomas Klein44c82152007-07-11 16:32:00 +02002716 ret = ehea_clean_all_portres(port);
2717 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002718 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002719
Thomas Klein21eee2d2008-02-13 16:18:33 +01002720 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002721
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002722 return ret;
2723}
2724
2725static int ehea_stop(struct net_device *dev)
2726{
2727 int ret;
2728 struct ehea_port *port = netdev_priv(dev);
2729
Joe Perches8c4877a2010-12-13 10:05:14 -08002730 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002731
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002732 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002733 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002734 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002736 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002737 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002738 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002739 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002740 return ret;
2741}
2742
Andrew Morton22559c52008-04-18 13:50:39 -07002743static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002744{
2745 struct ehea_qp qp = *orig_qp;
2746 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2747 struct ehea_swqe *swqe;
2748 int wqe_index;
2749 int i;
2750
2751 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2752 swqe = ehea_get_swqe(&qp, &wqe_index);
2753 swqe->tx_control |= EHEA_SWQE_PURGE;
2754 }
2755}
2756
Andrew Morton22559c52008-04-18 13:50:39 -07002757static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002758{
2759 int i;
2760
2761 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2762 struct ehea_port_res *pr = &port->port_res[i];
2763 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002764 int ret;
2765
2766 ret = wait_event_timeout(port->swqe_avail_wq,
2767 atomic_read(&pr->swqe_avail) >= swqe_max,
2768 msecs_to_jiffies(100));
2769
2770 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002771 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002772 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002773 }
2774 }
2775}
2776
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002777int ehea_stop_qps(struct net_device *dev)
2778{
2779 struct ehea_port *port = netdev_priv(dev);
2780 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002781 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002782 int ret = -EIO;
2783 int dret;
2784 int i;
2785 u64 hret;
2786 u64 dummy64 = 0;
2787 u16 dummy16 = 0;
2788
Thomas Klein3faf2692009-01-21 14:45:33 -08002789 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002790 if (!cb0) {
2791 ret = -ENOMEM;
2792 goto out;
2793 }
2794
2795 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2796 struct ehea_port_res *pr = &port->port_res[i];
2797 struct ehea_qp *qp = pr->qp;
2798
2799 /* Purge send queue */
2800 ehea_purge_sq(qp);
2801
2802 /* Disable queue pair */
2803 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2804 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2805 cb0);
2806 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002807 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002808 goto out;
2809 }
2810
2811 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2812 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2813
2814 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2815 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2816 1), cb0, &dummy64,
2817 &dummy64, &dummy16, &dummy16);
2818 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002819 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002820 goto out;
2821 }
2822
2823 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2824 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2825 cb0);
2826 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002827 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002828 goto out;
2829 }
2830
2831 /* deregister shared memory regions */
2832 dret = ehea_rem_smrs(pr);
2833 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002834 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002835 goto out;
2836 }
2837 }
2838
2839 ret = 0;
2840out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002841 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002842
2843 return ret;
2844}
2845
Doug Maxey508d2b52008-01-31 20:20:49 -06002846void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002847{
2848 struct ehea_qp qp = *orig_qp;
2849 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2850 struct ehea_rwqe *rwqe;
2851 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2852 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2853 struct sk_buff *skb;
2854 u32 lkey = pr->recv_mr.lkey;
2855
2856
2857 int i;
2858 int index;
2859
2860 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2861 rwqe = ehea_get_next_rwqe(&qp, 2);
2862 rwqe->sg_list[0].l_key = lkey;
2863 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2864 skb = skba_rq2[index];
2865 if (skb)
2866 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2867 }
2868
2869 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2870 rwqe = ehea_get_next_rwqe(&qp, 3);
2871 rwqe->sg_list[0].l_key = lkey;
2872 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2873 skb = skba_rq3[index];
2874 if (skb)
2875 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2876 }
2877}
2878
2879int ehea_restart_qps(struct net_device *dev)
2880{
2881 struct ehea_port *port = netdev_priv(dev);
2882 struct ehea_adapter *adapter = port->adapter;
2883 int ret = 0;
2884 int i;
2885
Doug Maxey508d2b52008-01-31 20:20:49 -06002886 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002887 u64 hret;
2888 u64 dummy64 = 0;
2889 u16 dummy16 = 0;
2890
Thomas Klein3faf2692009-01-21 14:45:33 -08002891 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002892 if (!cb0) {
2893 ret = -ENOMEM;
2894 goto out;
2895 }
2896
2897 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2898 struct ehea_port_res *pr = &port->port_res[i];
2899 struct ehea_qp *qp = pr->qp;
2900
2901 ret = ehea_gen_smrs(pr);
2902 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002903 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002904 goto out;
2905 }
2906
2907 ehea_update_rqs(qp, pr);
2908
2909 /* Enable queue pair */
2910 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2911 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2912 cb0);
2913 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002914 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002915 goto out;
2916 }
2917
2918 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2919 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2920
2921 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2922 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2923 1), cb0, &dummy64,
2924 &dummy64, &dummy16, &dummy16);
2925 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002926 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002927 goto out;
2928 }
2929
2930 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2931 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2932 cb0);
2933 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002934 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002935 goto out;
2936 }
2937
2938 /* refill entire queue */
2939 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2940 ehea_refill_rq2(pr, 0);
2941 ehea_refill_rq3(pr, 0);
2942 }
2943out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002944 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002945
2946 return ret;
2947}
2948
David Howellsc4028952006-11-22 14:57:56 +00002949static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002950{
2951 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002952 struct ehea_port *port =
2953 container_of(work, struct ehea_port, reset_task);
2954 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002955
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002956 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002958 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002959 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002960
2961 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962
Thomas Klein44c82152007-07-11 16:32:00 +02002963 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964
2965 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002966 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002967 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002968
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002969 ehea_set_multicast_list(dev);
2970
Joe Perches8c4877a2010-12-13 10:05:14 -08002971 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002972
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002973 port_napi_enable(port);
2974
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002975 netif_wake_queue(dev);
2976out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002977 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002978 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002979}
2980
Tejun Heo3d6b8922010-12-12 16:45:14 +01002981static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002982{
2983 int ret, i;
2984 struct ehea_adapter *adapter;
2985
Joe Perches8c4877a2010-12-13 10:05:14 -08002986 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002987
2988 list_for_each_entry(adapter, &adapter_list, list)
2989 if (adapter->active_ports) {
2990 /* Shutdown all ports */
2991 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2992 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002993 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002994
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002995 if (!port)
2996 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002997
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002998 dev = port->netdev;
2999
3000 if (dev->flags & IFF_UP) {
3001 mutex_lock(&port->port_lock);
3002 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003003 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003004 ret = ehea_stop_qps(dev);
3005 if (ret) {
3006 mutex_unlock(&port->port_lock);
3007 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003008 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003009 port_napi_disable(port);
3010 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003011 }
Andre Detsch2928db42010-08-17 05:49:12 +00003012 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003013 }
3014
3015 /* Unregister old memory region */
3016 ret = ehea_rem_mr(&adapter->mr);
3017 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003018 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003019 goto out;
3020 }
3021 }
3022
Thomas Klein44c82152007-07-11 16:32:00 +02003023 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3024
3025 list_for_each_entry(adapter, &adapter_list, list)
3026 if (adapter->active_ports) {
3027 /* Register new memory region */
3028 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3029 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003030 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003031 goto out;
3032 }
3033
3034 /* Restart all ports */
3035 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3036 struct ehea_port *port = adapter->port[i];
3037
3038 if (port) {
3039 struct net_device *dev = port->netdev;
3040
3041 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003042 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003043 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003044 if (!ret) {
3045 check_sqs(port);
3046 port_napi_enable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003047 netif_wake_queue(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00003048 } else {
3049 netdev_err(dev, "Unable to restart QPS\n");
3050 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003051 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003052 }
3053 }
3054 }
3055 }
Joe Perches8c4877a2010-12-13 10:05:14 -08003056 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003057out:
3058 return;
3059}
3060
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003061static void ehea_tx_watchdog(struct net_device *dev)
3062{
3063 struct ehea_port *port = netdev_priv(dev);
3064
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003065 if (netif_carrier_ok(dev) &&
3066 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003067 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068}
3069
3070int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3071{
3072 struct hcp_query_ehea *cb;
3073 u64 hret;
3074 int ret;
3075
Thomas Klein3faf2692009-01-21 14:45:33 -08003076 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003077 if (!cb) {
3078 ret = -ENOMEM;
3079 goto out;
3080 }
3081
3082 hret = ehea_h_query_ehea(adapter->handle, cb);
3083
3084 if (hret != H_SUCCESS) {
3085 ret = -EIO;
3086 goto out_herr;
3087 }
3088
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003089 adapter->max_mc_mac = cb->max_mc_mac - 1;
3090 ret = 0;
3091
3092out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003093 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003094out:
3095 return ret;
3096}
3097
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3099{
3100 struct hcp_ehea_port_cb4 *cb4;
3101 u64 hret;
3102 int ret = 0;
3103
3104 *jumbo = 0;
3105
3106 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003107 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003108 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003109 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 ret = -ENOMEM;
3111 goto out;
3112 } else {
3113 hret = ehea_h_query_ehea_port(port->adapter->handle,
3114 port->logical_port_id,
3115 H_PORT_CB4,
3116 H_PORT_CB4_JUMBO, cb4);
3117 if (hret == H_SUCCESS) {
3118 if (cb4->jumbo_frame)
3119 *jumbo = 1;
3120 else {
3121 cb4->jumbo_frame = 1;
3122 hret = ehea_h_modify_ehea_port(port->adapter->
3123 handle,
3124 port->
3125 logical_port_id,
3126 H_PORT_CB4,
3127 H_PORT_CB4_JUMBO,
3128 cb4);
3129 if (hret == H_SUCCESS)
3130 *jumbo = 1;
3131 }
3132 } else
3133 ret = -EINVAL;
3134
Thomas Klein3faf2692009-01-21 14:45:33 -08003135 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003136 }
3137out:
3138 return ret;
3139}
3140
3141static ssize_t ehea_show_port_id(struct device *dev,
3142 struct device_attribute *attr, char *buf)
3143{
3144 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003145 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003146}
3147
3148static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3149 NULL);
3150
3151static void __devinit logical_port_release(struct device *dev)
3152{
3153 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003154 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003155}
3156
3157static struct device *ehea_register_port(struct ehea_port *port,
3158 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159{
3160 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161
Grant Likely61c7a082010-04-13 16:12:29 -07003162 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003163 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003164 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003166 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003167 port->ofdev.dev.release = logical_port_release;
3168
3169 ret = of_device_register(&port->ofdev);
3170 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003171 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172 goto out;
3173 }
3174
3175 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003176 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003177 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003178 goto out_unreg_of_dev;
3179 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003180
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003181 return &port->ofdev.dev;
3182
3183out_unreg_of_dev:
3184 of_device_unregister(&port->ofdev);
3185out:
3186 return NULL;
3187}
3188
3189static void ehea_unregister_port(struct ehea_port *port)
3190{
3191 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3192 of_device_unregister(&port->ofdev);
3193}
3194
Thomas Klein086c1b22009-01-21 14:43:59 -08003195static const struct net_device_ops ehea_netdev_ops = {
3196 .ndo_open = ehea_open,
3197 .ndo_stop = ehea_stop,
3198 .ndo_start_xmit = ehea_start_xmit,
3199#ifdef CONFIG_NET_POLL_CONTROLLER
3200 .ndo_poll_controller = ehea_netpoll,
3201#endif
3202 .ndo_get_stats = ehea_get_stats,
3203 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003204 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003205 .ndo_set_multicast_list = ehea_set_multicast_list,
3206 .ndo_change_mtu = ehea_change_mtu,
3207 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3208 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003209 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3210 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003211};
3212
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3214 u32 logical_port_id,
3215 struct device_node *dn)
3216{
3217 int ret;
3218 struct net_device *dev;
3219 struct ehea_port *port;
3220 struct device *port_dev;
3221 int jumbo;
3222
3223 /* allocate memory for the port structures */
3224 dev = alloc_etherdev(sizeof(struct ehea_port));
3225
3226 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003227 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003228 ret = -ENOMEM;
3229 goto out_err;
3230 }
3231
3232 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003234 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003235 port->state = EHEA_PORT_DOWN;
3236 port->sig_comp_iv = sq_entries / 10;
3237
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003238 port->adapter = adapter;
3239 port->netdev = dev;
3240 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003241
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003243
3244 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3245 if (!port->mc_list) {
3246 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003248 }
3249
3250 INIT_LIST_HEAD(&port->mc_list->list);
3251
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003252 ret = ehea_sense_port_attr(port);
3253 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003254 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003255
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003256 port_dev = ehea_register_port(port, dn);
3257 if (!port_dev)
3258 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003259
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003261
3262 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003263 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3264
Thomas Klein086c1b22009-01-21 14:43:59 -08003265 dev->netdev_ops = &ehea_netdev_ops;
3266 ehea_set_ethtool_ops(dev);
3267
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003268 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003269 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3271 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003272 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3273
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003274 if (use_lro)
3275 dev->features |= NETIF_F_LRO;
3276
David Howellsc4028952006-11-22 14:57:56 +00003277 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003278
3279 ret = register_netdev(dev);
3280 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003281 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003282 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003283 }
3284
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003285 port->lro_max_aggr = lro_max_aggr;
3286
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003288 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003289 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290
Joe Perches8c4877a2010-12-13 10:05:14 -08003291 netdev_info(dev, "Jumbo frames are %sabled\n",
3292 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003293
Thomas Klein44c82152007-07-11 16:32:00 +02003294 adapter->active_ports++;
3295
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003296 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003297
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003298out_unreg_port:
3299 ehea_unregister_port(port);
3300
3301out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003302 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303
3304out_free_ethdev:
3305 free_netdev(dev);
3306
3307out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003308 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3309 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003310 return NULL;
3311}
3312
3313static void ehea_shutdown_single_port(struct ehea_port *port)
3314{
Brian King7fb1c2a2008-05-14 09:48:25 -05003315 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003316
3317 cancel_work_sync(&port->reset_task);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318 unregister_netdev(port->netdev);
3319 ehea_unregister_port(port);
3320 kfree(port->mc_list);
3321 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003322 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003323}
3324
3325static int ehea_setup_ports(struct ehea_adapter *adapter)
3326{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003327 struct device_node *lhea_dn;
3328 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003329
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003330 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003331 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003332
Grant Likely61c7a082010-04-13 16:12:29 -07003333 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003334 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003335
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003336 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003337 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003338 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003339 pr_err("bad device node: eth_dn name=%s\n",
3340 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003341 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003342 }
3343
Thomas Klein1211bb62007-04-26 11:56:43 +02003344 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003345 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003346 of_node_put(eth_dn);
3347 return -EIO;
3348 }
3349
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003350 adapter->port[i] = ehea_setup_single_port(adapter,
3351 *dn_log_port_id,
3352 eth_dn);
3353 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003354 netdev_info(adapter->port[i]->netdev,
3355 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003356 else
3357 ehea_remove_adapter_mr(adapter);
3358
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003360 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003361 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003362}
3363
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003364static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3365 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003366{
3367 struct device_node *lhea_dn;
3368 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003369 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370
Grant Likely61c7a082010-04-13 16:12:29 -07003371 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003372 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003373
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003374 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003375 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003376 if (dn_log_port_id)
3377 if (*dn_log_port_id == logical_port_id)
3378 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003379 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380
3381 return NULL;
3382}
3383
3384static ssize_t ehea_probe_port(struct device *dev,
3385 struct device_attribute *attr,
3386 const char *buf, size_t count)
3387{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003388 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003389 struct ehea_port *port;
3390 struct device_node *eth_dn = NULL;
3391 int i;
3392
3393 u32 logical_port_id;
3394
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003395 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003396
3397 port = ehea_get_port(adapter, logical_port_id);
3398
3399 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003400 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3401 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003402 return -EINVAL;
3403 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003404
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003405 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3406
3407 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003408 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003409 return -EINVAL;
3410 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003411
Thomas Klein1211bb62007-04-26 11:56:43 +02003412 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003413 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003414 return -EIO;
3415 }
3416
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003417 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3418
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003419 of_node_put(eth_dn);
3420
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003421 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003422 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003423 if (!adapter->port[i]) {
3424 adapter->port[i] = port;
3425 break;
3426 }
3427
Joe Perches8c4877a2010-12-13 10:05:14 -08003428 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3429 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003430 } else {
3431 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003432 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003433 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003434
3435 return (ssize_t) count;
3436}
3437
3438static ssize_t ehea_remove_port(struct device *dev,
3439 struct device_attribute *attr,
3440 const char *buf, size_t count)
3441{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003442 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003443 struct ehea_port *port;
3444 int i;
3445 u32 logical_port_id;
3446
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003447 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003448
3449 port = ehea_get_port(adapter, logical_port_id);
3450
3451 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003452 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3453 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003454
3455 ehea_shutdown_single_port(port);
3456
Doug Maxey508d2b52008-01-31 20:20:49 -06003457 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003458 if (adapter->port[i] == port) {
3459 adapter->port[i] = NULL;
3460 break;
3461 }
3462 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003463 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3464 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003465 return -EINVAL;
3466 }
3467
Thomas Klein1211bb62007-04-26 11:56:43 +02003468 ehea_remove_adapter_mr(adapter);
3469
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003470 return (ssize_t) count;
3471}
3472
3473static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3474static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3475
Grant Likely2dc11582010-08-06 09:25:50 -06003476int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003477{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003478 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479 if (ret)
3480 goto out;
3481
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003482 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003483out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003484 return ret;
3485}
3486
Grant Likely2dc11582010-08-06 09:25:50 -06003487void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003488{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003489 device_remove_file(&dev->dev, &dev_attr_probe_port);
3490 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003491}
3492
Grant Likely2dc11582010-08-06 09:25:50 -06003493static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003494 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495{
3496 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003497 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498 int ret;
3499
Grant Likely61c7a082010-04-13 16:12:29 -07003500 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003501 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003502 return -EINVAL;
3503 }
3504
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003505 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3506 if (!adapter) {
3507 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003508 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003509 goto out;
3510 }
3511
Thomas Klein44c82152007-07-11 16:32:00 +02003512 list_add(&adapter->list, &adapter_list);
3513
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003514 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003515
Grant Likely61c7a082010-04-13 16:12:29 -07003516 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003517 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003518 if (adapter_handle)
3519 adapter->handle = *adapter_handle;
3520
3521 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003522 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003523 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003524 ret = -ENODEV;
3525 goto out_free_ad;
3526 }
3527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003528 adapter->pd = EHEA_PD_ID;
3529
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003530 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532
3533 /* initialize adapter and ports */
3534 /* get adapter properties */
3535 ret = ehea_sense_adapter_attr(adapter);
3536 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003537 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003538 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540
3541 adapter->neq = ehea_create_eq(adapter,
3542 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3543 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003544 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003545 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003546 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 }
3548
3549 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3550 (unsigned long)adapter);
3551
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003552 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003553 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003554 "ehea_neq", adapter);
3555 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003556 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 goto out_kill_eq;
3558 }
3559
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003560 ret = ehea_create_device_sysfs(dev);
3561 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003562 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003564 ret = ehea_setup_ports(adapter);
3565 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003566 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003567 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003568 }
3569
3570 ret = 0;
3571 goto out;
3572
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003573out_rem_dev_sysfs:
3574 ehea_remove_device_sysfs(dev);
3575
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003576out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003577 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003578
3579out_kill_eq:
3580 ehea_destroy_eq(adapter->neq);
3581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003582out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003583 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003584 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003586out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003587 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003589 return ret;
3590}
3591
Grant Likely2dc11582010-08-06 09:25:50 -06003592static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003593{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003594 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003595 int i;
3596
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003597 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003598 if (adapter->port[i]) {
3599 ehea_shutdown_single_port(adapter->port[i]);
3600 adapter->port[i] = NULL;
3601 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003602
3603 ehea_remove_device_sysfs(dev);
3604
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003605 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003606 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003607
3608 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003609 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003610 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003611 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003612
Thomas Klein21eee2d2008-02-13 16:18:33 +01003613 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003614
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003615 return 0;
3616}
3617
Thomas Klein21eee2d2008-02-13 16:18:33 +01003618void ehea_crash_handler(void)
3619{
3620 int i;
3621
3622 if (ehea_fw_handles.arr)
3623 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3624 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3625 ehea_fw_handles.arr[i].fwh,
3626 FORCE_FREE);
3627
3628 if (ehea_bcmc_regs.arr)
3629 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3630 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3631 ehea_bcmc_regs.arr[i].port_id,
3632 ehea_bcmc_regs.arr[i].reg_type,
3633 ehea_bcmc_regs.arr[i].macaddr,
3634 0, H_DEREG_BCMC);
3635}
3636
Hannes Hering48cfb142008-05-07 14:43:36 +02003637static int ehea_mem_notifier(struct notifier_block *nb,
3638 unsigned long action, void *data)
3639{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003640 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003641 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003642
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003643 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003644
Hannes Hering48cfb142008-05-07 14:43:36 +02003645 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003646 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003647 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003648 /* Readd canceled memory block */
3649 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003650 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003651 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003652 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003653 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003654 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003655 break;
3656 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003657 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003658 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003659 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003660 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003661 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003662 break;
3663 default:
3664 break;
3665 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003666
3667 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003668 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003669
Thomas Kleina7c561f22010-04-20 23:11:31 +00003670out_unlock:
3671 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003672 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003673}
3674
3675static struct notifier_block ehea_mem_nb = {
3676 .notifier_call = ehea_mem_notifier,
3677};
3678
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003679static int ehea_reboot_notifier(struct notifier_block *nb,
3680 unsigned long action, void *unused)
3681{
3682 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003683 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003684 ibmebus_unregister_driver(&ehea_driver);
3685 }
3686 return NOTIFY_DONE;
3687}
3688
3689static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003690 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003691};
3692
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003693static int check_module_parm(void)
3694{
3695 int ret = 0;
3696
3697 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3698 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003699 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003700 ret = -EINVAL;
3701 }
3702 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3703 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003704 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003705 ret = -EINVAL;
3706 }
3707 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3708 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003709 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003710 ret = -EINVAL;
3711 }
3712 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3713 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003714 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003715 ret = -EINVAL;
3716 }
3717
3718 return ret;
3719}
3720
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003721static ssize_t ehea_show_capabilities(struct device_driver *drv,
3722 char *buf)
3723{
3724 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3725}
3726
3727static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3728 ehea_show_capabilities, NULL);
3729
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003730int __init ehea_module_init(void)
3731{
3732 int ret;
3733
Joe Perches8c4877a2010-12-13 10:05:14 -08003734 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003735
Thomas Klein21eee2d2008-02-13 16:18:33 +01003736 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3737 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3738
Daniel Walker9f71a562008-03-28 14:41:26 -07003739 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003740 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003741
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003742 ret = check_module_parm();
3743 if (ret)
3744 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003745
3746 ret = ehea_create_busmap();
3747 if (ret)
3748 goto out;
3749
Thomas Klein21eee2d2008-02-13 16:18:33 +01003750 ret = register_reboot_notifier(&ehea_reboot_nb);
3751 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003752 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003753
Hannes Hering48cfb142008-05-07 14:43:36 +02003754 ret = register_memory_notifier(&ehea_mem_nb);
3755 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003756 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003757
Joe Perchesc061b182010-08-23 18:20:03 +00003758 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003759 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003760 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003761
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003762 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003763 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003764 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003765 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003766 }
3767
3768 ret = driver_create_file(&ehea_driver.driver,
3769 &driver_attr_capabilities);
3770 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003771 pr_err("failed to register capabilities attribute, ret=%d\n",
3772 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003773 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003774 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003775
Thomas Klein21eee2d2008-02-13 16:18:33 +01003776 return ret;
3777
3778out3:
3779 ibmebus_unregister_driver(&ehea_driver);
3780out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003781 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003782 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003783 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003784out:
3785 return ret;
3786}
3787
3788static void __exit ehea_module_exit(void)
3789{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003790 int ret;
3791
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003792 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003793 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003794 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003795 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003796 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003797 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003798 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003799 kfree(ehea_fw_handles.arr);
3800 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003801 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003802}
3803
3804module_init(ehea_module_init);
3805module_exit(ehea_module_exit);