blob: 0dfef6d764454b2c88503ed0b86b9be8dea3d38a [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 Leitao5c7e57f2010-11-26 07:26:27 +0000440 ehea_update_rq1a(pr->qp, i);
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)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800743 netif_err(port, rx_err, dev,
744 "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) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800749 netdev_info(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
Thomas Kleine2878802009-01-21 14:45:57 -08001332 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1333 - init_attr->act_nr_rwqes_rq2
1334 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001335
Thomas Kleine2878802009-01-21 14:45:57 -08001336 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337
1338 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1339
1340 return ret;
1341}
1342
1343static int ehea_reg_interrupts(struct net_device *dev)
1344{
1345 struct ehea_port *port = netdev_priv(dev);
1346 struct ehea_port_res *pr;
1347 int i, ret;
1348
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349
1350 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1351 dev->name);
1352
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001353 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001355 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001357 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1358 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359 goto out_free_qpeq;
1360 }
1361
Joe Perches8c4877a2010-12-13 10:05:14 -08001362 netif_info(port, ifup, dev,
1363 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1364 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001365
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001366
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1368 pr = &port->port_res[i];
1369 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001370 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001371 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001372 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001373 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 pr);
1375 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001376 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1377 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378 goto out_free_req;
1379 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001380 netif_info(port, ifup, dev,
1381 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1382 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383 }
1384out:
1385 return ret;
1386
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001387
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001388out_free_req:
1389 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001390 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001391 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001395 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001399
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001400}
1401
1402static void ehea_free_interrupts(struct net_device *dev)
1403{
1404 struct ehea_port *port = netdev_priv(dev);
1405 struct ehea_port_res *pr;
1406 int i;
1407
1408 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1411 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001412 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001413 netif_info(port, intr, dev,
1414 "free send irq for res %d with handle 0x%X\n",
1415 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001416 }
1417
1418 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001419 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001420 netif_info(port, intr, dev,
1421 "associated event interrupt for handle 0x%X freed\n",
1422 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423}
1424
1425static int ehea_configure_port(struct ehea_port *port)
1426{
1427 int ret, i;
1428 u64 hret, mask;
1429 struct hcp_ehea_port_cb0 *cb0;
1430
1431 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001432 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001433 if (!cb0)
1434 goto out;
1435
1436 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1437 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1440 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1441 PXLY_RC_VLAN_FILTER)
1442 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1443
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001444 for (i = 0; i < port->num_mcs; i++)
1445 if (use_mcs)
1446 cb0->default_qpn_arr[i] =
1447 port->port_res[i].qp->init_attr.qp_nr;
1448 else
1449 cb0->default_qpn_arr[i] =
1450 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001451
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001452 if (netif_msg_ifup(port))
1453 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1454
1455 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1456 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1457
1458 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1459 port->logical_port_id,
1460 H_PORT_CB0, mask, cb0);
1461 ret = -EIO;
1462 if (hret != H_SUCCESS)
1463 goto out_free;
1464
1465 ret = 0;
1466
1467out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001468 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001469out:
1470 return ret;
1471}
1472
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001475 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 struct ehea_adapter *adapter = pr->port->adapter;
1477
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001478 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1479 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480 goto out;
1481
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001482 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1483 if (ret)
1484 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485
1486 return 0;
1487
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001488out_free:
1489 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001491 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 return -EIO;
1493}
1494
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001495int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496{
Joe Perches8e95a202009-12-03 07:58:21 +00001497 if ((ehea_rem_mr(&pr->send_mr)) ||
1498 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001499 return -EIO;
1500 else
1501 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502}
1503
1504static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1505{
Doug Maxey508d2b52008-01-31 20:20:49 -06001506 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001508 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509 if (!q_skba->arr)
1510 return -ENOMEM;
1511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001512 q_skba->len = max_q_entries;
1513 q_skba->index = 0;
1514 q_skba->os_skbs = 0;
1515
1516 return 0;
1517}
1518
1519static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1520 struct port_res_cfg *pr_cfg, int queue_token)
1521{
1522 struct ehea_adapter *adapter = port->adapter;
1523 enum ehea_eq_type eq_type = EHEA_EQ;
1524 struct ehea_qp_init_attr *init_attr = NULL;
1525 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001526 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1527
1528 tx_bytes = pr->tx_bytes;
1529 tx_packets = pr->tx_packets;
1530 rx_bytes = pr->rx_bytes;
1531 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532
1533 memset(pr, 0, sizeof(struct ehea_port_res));
1534
Breno Leitaoce45b872010-10-27 08:45:14 +00001535 pr->tx_bytes = rx_bytes;
1536 pr->tx_packets = tx_packets;
1537 pr->rx_bytes = rx_bytes;
1538 pr->rx_packets = rx_packets;
1539
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541 spin_lock_init(&pr->xmit_lock);
1542 spin_lock_init(&pr->netif_queue);
1543
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001544 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1545 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001546 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 goto out_free;
1548 }
1549
1550 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001551 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001552 port->logical_port_id);
1553 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001554 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 goto out_free;
1556 }
1557
1558 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001559 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001560 port->logical_port_id);
1561 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001562 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 goto out_free;
1564 }
1565
1566 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001567 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1568 pr->send_cq->attr.act_nr_of_cqes,
1569 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570
1571 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1572 if (!init_attr) {
1573 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001574 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001575 goto out_free;
1576 }
1577
1578 init_attr->low_lat_rq1 = 1;
1579 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1580 init_attr->rq_count = 3;
1581 init_attr->qp_token = queue_token;
1582 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1583 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1584 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1585 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1586 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1587 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1588 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1589 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1590 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1591 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1592 init_attr->port_nr = port->logical_port_id;
1593 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1594 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1595 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1596
1597 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1598 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001599 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600 ret = -EIO;
1601 goto out_free;
1602 }
1603
1604 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001605 pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n",
1606 init_attr->qp_nr,
1607 init_attr->act_nr_send_wqes,
1608 init_attr->act_nr_rwqes_rq1,
1609 init_attr->act_nr_rwqes_rq2,
1610 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001611
Thomas Klein44fb3122008-04-04 15:04:53 +02001612 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1613
1614 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001615 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1616 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1617 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1618 if (ret)
1619 goto out_free;
1620
1621 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1622 if (ehea_gen_smrs(pr) != 0) {
1623 ret = -EIO;
1624 goto out_free;
1625 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001626
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1628
1629 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001630
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001631 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001632
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001633 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1634 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1635 pr->lro_mgr.lro_arr = pr->lro_desc;
1636 pr->lro_mgr.get_skb_header = get_skb_hdr;
1637 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1638 pr->lro_mgr.dev = port->netdev;
1639 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1640 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001642 ret = 0;
1643 goto out;
1644
1645out_free:
1646 kfree(init_attr);
1647 vfree(pr->sq_skba.arr);
1648 vfree(pr->rq1_skba.arr);
1649 vfree(pr->rq2_skba.arr);
1650 vfree(pr->rq3_skba.arr);
1651 ehea_destroy_qp(pr->qp);
1652 ehea_destroy_cq(pr->send_cq);
1653 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001654 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655out:
1656 return ret;
1657}
1658
1659static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1660{
1661 int ret, i;
1662
Hannes Hering357eb462009-08-04 11:48:39 -07001663 if (pr->qp)
1664 netif_napi_del(&pr->napi);
1665
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001666 ret = ehea_destroy_qp(pr->qp);
1667
1668 if (!ret) {
1669 ehea_destroy_cq(pr->send_cq);
1670 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001671 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001672
1673 for (i = 0; i < pr->rq1_skba.len; i++)
1674 if (pr->rq1_skba.arr[i])
1675 dev_kfree_skb(pr->rq1_skba.arr[i]);
1676
1677 for (i = 0; i < pr->rq2_skba.len; i++)
1678 if (pr->rq2_skba.arr[i])
1679 dev_kfree_skb(pr->rq2_skba.arr[i]);
1680
1681 for (i = 0; i < pr->rq3_skba.len; i++)
1682 if (pr->rq3_skba.arr[i])
1683 dev_kfree_skb(pr->rq3_skba.arr[i]);
1684
1685 for (i = 0; i < pr->sq_skba.len; i++)
1686 if (pr->sq_skba.arr[i])
1687 dev_kfree_skb(pr->sq_skba.arr[i]);
1688
1689 vfree(pr->rq1_skba.arr);
1690 vfree(pr->rq2_skba.arr);
1691 vfree(pr->rq3_skba.arr);
1692 vfree(pr->sq_skba.arr);
1693 ret = ehea_rem_smrs(pr);
1694 }
1695 return ret;
1696}
1697
1698/*
1699 * The write_* functions store information in swqe which is used by
1700 * the hardware to calculate the ip/tcp/udp checksum
1701 */
1702
1703static inline void write_ip_start_end(struct ehea_swqe *swqe,
1704 const struct sk_buff *skb)
1705{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001706 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001707 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708}
1709
1710static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1711 const struct sk_buff *skb)
1712{
1713 swqe->tcp_offset =
1714 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1715
1716 swqe->tcp_end = (u16)skb->len - 1;
1717}
1718
1719static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1720 const struct sk_buff *skb)
1721{
1722 swqe->tcp_offset =
1723 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1724
1725 swqe->tcp_end = (u16)skb->len - 1;
1726}
1727
1728
1729static void write_swqe2_TSO(struct sk_buff *skb,
1730 struct ehea_swqe *swqe, u32 lkey)
1731{
1732 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1733 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001734 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001736
1737 /* Packet is TCP with TSO enabled */
1738 swqe->tx_control |= EHEA_SWQE_TSO;
1739 swqe->mss = skb_shinfo(skb)->gso_size;
1740 /* copy only eth/ip/tcp headers to immediate data and
1741 * the rest of skb->data to sg1entry
1742 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001743 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744
Eric Dumazete743d312010-04-14 15:59:40 -07001745 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746
1747 if (skb_data_size >= headersize) {
1748 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001749 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 swqe->immediate_data_length = headersize;
1751
1752 if (skb_data_size > headersize) {
1753 /* set sg1entry data */
1754 sg1entry->l_key = lkey;
1755 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001756 sg1entry->vaddr =
1757 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001758 swqe->descriptors++;
1759 }
1760 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001761 pr_err("cannot handle fragmented headers\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001762}
1763
1764static void write_swqe2_nonTSO(struct sk_buff *skb,
1765 struct ehea_swqe *swqe, u32 lkey)
1766{
Eric Dumazete743d312010-04-14 15:59:40 -07001767 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1769 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 /* Packet is any nonTSO type
1772 *
1773 * Copy as much as possible skb->data to immediate data and
1774 * the rest to sg1entry
1775 */
1776 if (skb_data_size >= SWQE2_MAX_IMM) {
1777 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001778 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779
1780 swqe->immediate_data_length = SWQE2_MAX_IMM;
1781
1782 if (skb_data_size > SWQE2_MAX_IMM) {
1783 /* copy sg1entry data */
1784 sg1entry->l_key = lkey;
1785 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001786 sg1entry->vaddr =
1787 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788 swqe->descriptors++;
1789 }
1790 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001791 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792 swqe->immediate_data_length = skb_data_size;
1793 }
1794}
1795
1796static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1797 struct ehea_swqe *swqe, u32 lkey)
1798{
1799 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1800 skb_frag_t *frag;
1801 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001802
1803 nfrags = skb_shinfo(skb)->nr_frags;
1804 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001805 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001806 swqe->descriptors = 0;
1807 sg1entry_contains_frag_data = 0;
1808
1809 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1810 write_swqe2_TSO(skb, swqe, lkey);
1811 else
1812 write_swqe2_nonTSO(skb, swqe, lkey);
1813
1814 /* write descriptors */
1815 if (nfrags > 0) {
1816 if (swqe->descriptors == 0) {
1817 /* sg1entry not yet used */
1818 frag = &skb_shinfo(skb)->frags[0];
1819
1820 /* copy sg1entry data */
1821 sg1entry->l_key = lkey;
1822 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001823 sg1entry->vaddr =
1824 ehea_map_vaddr(page_address(frag->page)
1825 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001826 swqe->descriptors++;
1827 sg1entry_contains_frag_data = 1;
1828 }
1829
1830 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1831
1832 frag = &skb_shinfo(skb)->frags[i];
1833 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1834
1835 sgentry->l_key = lkey;
1836 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001837 sgentry->vaddr =
1838 ehea_map_vaddr(page_address(frag->page)
1839 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001840 swqe->descriptors++;
1841 }
1842 }
1843}
1844
1845static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1846{
1847 int ret = 0;
1848 u64 hret;
1849 u8 reg_type;
1850
1851 /* De/Register untagged packets */
1852 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, port->mac_addr, 0, hcallid);
1856 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001857 pr_err("%sregistering bc address failed (tagged)\n",
1858 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001859 ret = -EIO;
1860 goto out_herr;
1861 }
1862
1863 /* De/Register VLAN packets */
1864 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1865 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1866 port->logical_port_id,
1867 reg_type, port->mac_addr, 0, hcallid);
1868 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001869 pr_err("%sregistering bc address failed (vlan)\n",
1870 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001871 ret = -EIO;
1872 }
1873out_herr:
1874 return ret;
1875}
1876
1877static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1878{
1879 struct ehea_port *port = netdev_priv(dev);
1880 struct sockaddr *mac_addr = sa;
1881 struct hcp_ehea_port_cb0 *cb0;
1882 int ret;
1883 u64 hret;
1884
1885 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1886 ret = -EADDRNOTAVAIL;
1887 goto out;
1888 }
1889
Thomas Klein3faf2692009-01-21 14:45:33 -08001890 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001891 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001892 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001893 ret = -ENOMEM;
1894 goto out;
1895 }
1896
1897 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1898
1899 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1900
1901 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1902 port->logical_port_id, H_PORT_CB0,
1903 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1904 if (hret != H_SUCCESS) {
1905 ret = -EIO;
1906 goto out_free;
1907 }
1908
1909 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1910
1911 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001912 if (port->state == EHEA_PORT_UP) {
1913 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1914 if (ret)
1915 goto out_upregs;
1916 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001917
1918 port->mac_addr = cb0->port_mac_addr << 16;
1919
1920 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001921 if (port->state == EHEA_PORT_UP) {
1922 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1923 if (ret)
1924 goto out_upregs;
1925 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926
1927 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001928
1929out_upregs:
1930 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001931out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001932 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001933out:
1934 return ret;
1935}
1936
1937static void ehea_promiscuous_error(u64 hret, int enable)
1938{
Thomas Klein7674a582007-01-22 12:54:20 +01001939 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001940 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1941 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001942 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001943 pr_err("failed %sabling promiscuous mode\n",
1944 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945}
1946
1947static void ehea_promiscuous(struct net_device *dev, int enable)
1948{
1949 struct ehea_port *port = netdev_priv(dev);
1950 struct hcp_ehea_port_cb7 *cb7;
1951 u64 hret;
1952
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001953 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001954 return;
1955
Thomas Klein3faf2692009-01-21 14:45:33 -08001956 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001958 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001959 goto out;
1960 }
1961
1962 /* Modify Pxs_DUCQPN in CB7 */
1963 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1964
1965 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1966 port->logical_port_id,
1967 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1968 if (hret) {
1969 ehea_promiscuous_error(hret, enable);
1970 goto out;
1971 }
1972
1973 port->promisc = enable;
1974out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001975 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001976}
1977
1978static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1979 u32 hcallid)
1980{
1981 u64 hret;
1982 u8 reg_type;
1983
1984 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1985 | EHEA_BCMC_UNTAGGED;
1986
1987 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1988 port->logical_port_id,
1989 reg_type, mc_mac_addr, 0, hcallid);
1990 if (hret)
1991 goto out;
1992
1993 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1994 | EHEA_BCMC_VLANID_ALL;
1995
1996 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1997 port->logical_port_id,
1998 reg_type, mc_mac_addr, 0, hcallid);
1999out:
2000 return hret;
2001}
2002
2003static int ehea_drop_multicast_list(struct net_device *dev)
2004{
2005 struct ehea_port *port = netdev_priv(dev);
2006 struct ehea_mc_list *mc_entry = port->mc_list;
2007 struct list_head *pos;
2008 struct list_head *temp;
2009 int ret = 0;
2010 u64 hret;
2011
2012 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2013 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2014
2015 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2016 H_DEREG_BCMC);
2017 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002018 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002019 ret = -EIO;
2020 }
2021
2022 list_del(pos);
2023 kfree(mc_entry);
2024 }
2025 return ret;
2026}
2027
2028static void ehea_allmulti(struct net_device *dev, int enable)
2029{
2030 struct ehea_port *port = netdev_priv(dev);
2031 u64 hret;
2032
2033 if (!port->allmulti) {
2034 if (enable) {
2035 /* Enable ALLMULTI */
2036 ehea_drop_multicast_list(dev);
2037 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2038 if (!hret)
2039 port->allmulti = 1;
2040 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002041 netdev_err(dev,
2042 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 }
2044 } else
2045 if (!enable) {
2046 /* Disable ALLMULTI */
2047 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2048 if (!hret)
2049 port->allmulti = 0;
2050 else
Joe Perches8c4877a2010-12-13 10:05:14 -08002051 netdev_err(dev,
2052 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053 }
2054}
2055
Doug Maxey508d2b52008-01-31 20:20:49 -06002056static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002057{
2058 struct ehea_mc_list *ehea_mcl_entry;
2059 u64 hret;
2060
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002061 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002062 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002063 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002064 return;
2065 }
2066
2067 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2068
2069 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2070
2071 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2072 H_REG_BCMC);
2073 if (!hret)
2074 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2075 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08002076 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002077 kfree(ehea_mcl_entry);
2078 }
2079}
2080
2081static void ehea_set_multicast_list(struct net_device *dev)
2082{
2083 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002084 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002085 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002086
2087 if (dev->flags & IFF_PROMISC) {
2088 ehea_promiscuous(dev, 1);
2089 return;
2090 }
2091 ehea_promiscuous(dev, 0);
2092
2093 if (dev->flags & IFF_ALLMULTI) {
2094 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002095 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002096 }
2097 ehea_allmulti(dev, 0);
2098
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002099 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002100 ret = ehea_drop_multicast_list(dev);
2101 if (ret) {
2102 /* Dropping the current multicast list failed.
2103 * Enabling ALL_MULTI is the best we can do.
2104 */
2105 ehea_allmulti(dev, 1);
2106 }
2107
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002108 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002109 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2110 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 goto out;
2112 }
2113
Jiri Pirko22bedad32010-04-01 21:22:57 +00002114 netdev_for_each_mc_addr(ha, dev)
2115 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002116
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117 }
2118out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002119 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120}
2121
2122static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2123{
2124 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2125 return -EINVAL;
2126 dev->mtu = new_mtu;
2127 return 0;
2128}
2129
2130static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2131 struct ehea_swqe *swqe, u32 lkey)
2132{
2133 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002134 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002135
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002136 /* IPv4 */
2137 swqe->tx_control |= EHEA_SWQE_CRC
2138 | EHEA_SWQE_IP_CHECKSUM
2139 | EHEA_SWQE_TCP_CHECKSUM
2140 | EHEA_SWQE_IMM_DATA_PRESENT
2141 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2142
2143 write_ip_start_end(swqe, skb);
2144
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002145 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002146 if ((iph->frag_off & IP_MF) ||
2147 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002148 /* IP fragment, so don't change cs */
2149 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2150 else
2151 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002152 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153 write_tcp_offset_end(swqe, skb);
2154 }
2155
2156 /* icmp (big data) and ip segmentation packets (all other ip
2157 packets) do not require any special handling */
2158
2159 } else {
2160 /* Other Ethernet Protocol */
2161 swqe->tx_control |= EHEA_SWQE_CRC
2162 | EHEA_SWQE_IMM_DATA_PRESENT
2163 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2164 }
2165
2166 write_swqe2_data(skb, dev, swqe, lkey);
2167}
2168
2169static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2170 struct ehea_swqe *swqe)
2171{
2172 int nfrags = skb_shinfo(skb)->nr_frags;
2173 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2174 skb_frag_t *frag;
2175 int i;
2176
2177 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002178 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002179
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180 /* IPv4 */
2181 write_ip_start_end(swqe, skb);
2182
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002183 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 swqe->tx_control |= EHEA_SWQE_CRC
2185 | EHEA_SWQE_IP_CHECKSUM
2186 | EHEA_SWQE_TCP_CHECKSUM
2187 | EHEA_SWQE_IMM_DATA_PRESENT;
2188
2189 write_tcp_offset_end(swqe, skb);
2190
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002191 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002192 if ((iph->frag_off & IP_MF) ||
2193 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002194 /* IP fragment, so don't change cs */
2195 swqe->tx_control |= EHEA_SWQE_CRC
2196 | EHEA_SWQE_IMM_DATA_PRESENT;
2197 else {
2198 swqe->tx_control |= EHEA_SWQE_CRC
2199 | EHEA_SWQE_IP_CHECKSUM
2200 | EHEA_SWQE_TCP_CHECKSUM
2201 | EHEA_SWQE_IMM_DATA_PRESENT;
2202
2203 write_udp_offset_end(swqe, skb);
2204 }
2205 } else {
2206 /* icmp (big data) and
2207 ip segmentation packets (all other ip packets) */
2208 swqe->tx_control |= EHEA_SWQE_CRC
2209 | EHEA_SWQE_IP_CHECKSUM
2210 | EHEA_SWQE_IMM_DATA_PRESENT;
2211 }
2212 } else {
2213 /* Other Ethernet Protocol */
2214 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2215 }
2216 /* copy (immediate) data */
2217 if (nfrags == 0) {
2218 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002219 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002220 } else {
2221 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002222 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002223 skb_headlen(skb));
2224 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002225
2226 /* ... then copy data from the fragments */
2227 for (i = 0; i < nfrags; i++) {
2228 frag = &skb_shinfo(skb)->frags[i];
2229 memcpy(imm_data,
2230 page_address(frag->page) + frag->page_offset,
2231 frag->size);
2232 imm_data += frag->size;
2233 }
2234 }
2235 swqe->immediate_data_length = skb->len;
2236 dev_kfree_skb(skb);
2237}
2238
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002239static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2240{
2241 struct tcphdr *tcp;
2242 u32 tmp;
2243
2244 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002245 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002246 tcp = (struct tcphdr *)(skb_network_header(skb) +
2247 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002248 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002249 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002250 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002251 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 return 0;
2253}
2254
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002255static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2256{
2257 struct ehea_port *port = netdev_priv(dev);
2258 struct ehea_swqe *swqe;
2259 unsigned long flags;
2260 u32 lkey;
2261 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002262 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002263
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002264 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2265
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002266 if (!spin_trylock(&pr->xmit_lock))
2267 return NETDEV_TX_BUSY;
2268
2269 if (pr->queue_stopped) {
2270 spin_unlock(&pr->xmit_lock);
2271 return NETDEV_TX_BUSY;
2272 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273
2274 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2275 memset(swqe, 0, SWQE_HEADER_SIZE);
2276 atomic_dec(&pr->swqe_avail);
2277
Eric Dumazete5ccd962010-10-26 19:21:07 +00002278 if (vlan_tx_tag_present(skb)) {
2279 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2280 swqe->vlan_tag = vlan_tx_tag_get(skb);
2281 }
2282
Breno Leitaoce45b872010-10-27 08:45:14 +00002283 pr->tx_packets++;
2284 pr->tx_bytes += skb->len;
2285
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002286 if (skb->len <= SWQE3_MAX_IMM) {
2287 u32 sig_iv = port->sig_comp_iv;
2288 u32 swqe_num = pr->swqe_id_counter;
2289 ehea_xmit3(skb, dev, swqe);
2290 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2291 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2292 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2293 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2294 sig_iv);
2295 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2296 pr->swqe_ll_count = 0;
2297 } else
2298 pr->swqe_ll_count += 1;
2299 } else {
2300 swqe->wr_id =
2301 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2302 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002303 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002304 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2305 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2306
2307 pr->sq_skba.index++;
2308 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2309
2310 lkey = pr->send_mr.lkey;
2311 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002312 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002313 }
2314 pr->swqe_id_counter += 1;
2315
Joe Perches8c4877a2010-12-13 10:05:14 -08002316 netif_info(port, tx_queued, dev,
2317 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2318 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002319 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002320
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002321 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2322 netif_stop_queue(dev);
2323 swqe->tx_control |= EHEA_SWQE_PURGE;
2324 }
Thomas Klein44c82152007-07-11 16:32:00 +02002325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002327
2328 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2329 spin_lock_irqsave(&pr->netif_queue, flags);
2330 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002331 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002332 netif_stop_queue(dev);
2333 pr->queue_stopped = 1;
2334 }
2335 spin_unlock_irqrestore(&pr->netif_queue, flags);
2336 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002337 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002338 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002339
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002340 return NETDEV_TX_OK;
2341}
2342
2343static void ehea_vlan_rx_register(struct net_device *dev,
2344 struct vlan_group *grp)
2345{
2346 struct ehea_port *port = netdev_priv(dev);
2347 struct ehea_adapter *adapter = port->adapter;
2348 struct hcp_ehea_port_cb1 *cb1;
2349 u64 hret;
2350
2351 port->vgrp = grp;
2352
Thomas Klein3faf2692009-01-21 14:45:33 -08002353 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002355 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 goto out;
2357 }
2358
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2360 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2361 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002362 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002363
Thomas Klein3faf2692009-01-21 14:45:33 -08002364 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365out:
2366 return;
2367}
2368
2369static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2370{
2371 struct ehea_port *port = netdev_priv(dev);
2372 struct ehea_adapter *adapter = port->adapter;
2373 struct hcp_ehea_port_cb1 *cb1;
2374 int index;
2375 u64 hret;
2376
Thomas Klein3faf2692009-01-21 14:45:33 -08002377 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002379 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 goto out;
2381 }
2382
2383 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2384 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2385 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002386 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 goto out;
2388 }
2389
2390 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002391 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002392
2393 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2394 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2395 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002396 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002398 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002399 return;
2400}
2401
2402static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2403{
2404 struct ehea_port *port = netdev_priv(dev);
2405 struct ehea_adapter *adapter = port->adapter;
2406 struct hcp_ehea_port_cb1 *cb1;
2407 int index;
2408 u64 hret;
2409
Dan Aloni5c15bde2007-03-02 20:44:51 -08002410 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002411
Thomas Klein3faf2692009-01-21 14:45:33 -08002412 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002414 pr_err("no mem for cb1\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 goto out;
2416 }
2417
2418 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2419 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2420 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002421 pr_err("query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002422 goto out;
2423 }
2424
2425 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002426 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002427
2428 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2429 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2430 if (hret != H_SUCCESS)
Joe Perches8c4877a2010-12-13 10:05:14 -08002431 pr_err("modify_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002433 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002434}
2435
2436int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2437{
2438 int ret = -EIO;
2439 u64 hret;
2440 u16 dummy16 = 0;
2441 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002442 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443
Thomas Klein3faf2692009-01-21 14:45:33 -08002444 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002445 if (!cb0) {
2446 ret = -ENOMEM;
2447 goto out;
2448 }
2449
2450 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2451 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2452 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002453 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454 goto out;
2455 }
2456
2457 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2458 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2459 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2460 &dummy64, &dummy64, &dummy16, &dummy16);
2461 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002462 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002463 goto out;
2464 }
2465
2466 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2467 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2468 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002469 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 goto out;
2471 }
2472
2473 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2474 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2475 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2476 &dummy64, &dummy64, &dummy16, &dummy16);
2477 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002478 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479 goto out;
2480 }
2481
2482 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2483 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2484 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002485 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002486 goto out;
2487 }
2488
2489 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2490 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2491 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2492 &dummy64, &dummy64, &dummy16, &dummy16);
2493 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002494 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002495 goto out;
2496 }
2497
2498 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2499 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2500 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002501 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002502 goto out;
2503 }
2504
2505 ret = 0;
2506out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002507 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002508 return ret;
2509}
2510
2511static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2512 int add_tx_qps)
2513{
2514 int ret, i;
2515 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2516 enum ehea_eq_type eq_type = EHEA_EQ;
2517
2518 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2519 EHEA_MAX_ENTRIES_EQ, 1);
2520 if (!port->qp_eq) {
2521 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002522 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002523 goto out_kill_eq;
2524 }
2525
2526 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002527 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002528 pr_cfg.max_entries_sq = sq_entries;
2529 pr_cfg.max_entries_rq1 = rq1_entries;
2530 pr_cfg.max_entries_rq2 = rq2_entries;
2531 pr_cfg.max_entries_rq3 = rq3_entries;
2532
2533 pr_cfg_small_rx.max_entries_rcq = 1;
2534 pr_cfg_small_rx.max_entries_scq = sq_entries;
2535 pr_cfg_small_rx.max_entries_sq = sq_entries;
2536 pr_cfg_small_rx.max_entries_rq1 = 1;
2537 pr_cfg_small_rx.max_entries_rq2 = 1;
2538 pr_cfg_small_rx.max_entries_rq3 = 1;
2539
2540 for (i = 0; i < def_qps; i++) {
2541 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2542 if (ret)
2543 goto out_clean_pr;
2544 }
2545 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2546 ret = ehea_init_port_res(port, &port->port_res[i],
2547 &pr_cfg_small_rx, i);
2548 if (ret)
2549 goto out_clean_pr;
2550 }
2551
2552 return 0;
2553
2554out_clean_pr:
2555 while (--i >= 0)
2556 ehea_clean_portres(port, &port->port_res[i]);
2557
2558out_kill_eq:
2559 ehea_destroy_eq(port->qp_eq);
2560 return ret;
2561}
2562
2563static int ehea_clean_all_portres(struct ehea_port *port)
2564{
2565 int ret = 0;
2566 int i;
2567
Doug Maxey508d2b52008-01-31 20:20:49 -06002568 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569 ret |= ehea_clean_portres(port, &port->port_res[i]);
2570
2571 ret |= ehea_destroy_eq(port->qp_eq);
2572
2573 return ret;
2574}
2575
Thomas Klein35cf2e22007-08-06 13:55:14 +02002576static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002577{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002578 if (adapter->active_ports)
2579 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002580
2581 ehea_rem_mr(&adapter->mr);
2582}
2583
Thomas Klein35cf2e22007-08-06 13:55:14 +02002584static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002585{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002586 if (adapter->active_ports)
2587 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002588
2589 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2590}
2591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002592static int ehea_up(struct net_device *dev)
2593{
2594 int ret, i;
2595 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002596
2597 if (port->state == EHEA_PORT_UP)
2598 return 0;
2599
2600 ret = ehea_port_res_setup(port, port->num_def_qps,
2601 port->num_add_tx_qps);
2602 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002603 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604 goto out;
2605 }
2606
2607 /* Set default QP for this port */
2608 ret = ehea_configure_port(port);
2609 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002610 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002611 goto out_clean_pr;
2612 }
2613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 ret = ehea_reg_interrupts(dev);
2615 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002616 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002617 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002618 }
2619
Doug Maxey508d2b52008-01-31 20:20:49 -06002620 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002621 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2622 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002623 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002624 goto out_free_irqs;
2625 }
2626 }
2627
Doug Maxey508d2b52008-01-31 20:20:49 -06002628 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002629 ret = ehea_fill_port_res(&port->port_res[i]);
2630 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002631 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002632 goto out_free_irqs;
2633 }
2634 }
2635
Thomas Klein21eee2d2008-02-13 16:18:33 +01002636 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2637 if (ret) {
2638 ret = -EIO;
2639 goto out_free_irqs;
2640 }
2641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002642 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002643
2644 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002645 goto out;
2646
2647out_free_irqs:
2648 ehea_free_interrupts(dev);
2649
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650out_clean_pr:
2651 ehea_clean_all_portres(port);
2652out:
Thomas Klein44c82152007-07-11 16:32:00 +02002653 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002654 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002655
Thomas Klein21eee2d2008-02-13 16:18:33 +01002656 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002657 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002658
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002659 return ret;
2660}
2661
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002662static void port_napi_disable(struct ehea_port *port)
2663{
2664 int i;
2665
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002666 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002667 napi_disable(&port->port_res[i].napi);
2668}
2669
2670static void port_napi_enable(struct ehea_port *port)
2671{
2672 int i;
2673
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002674 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002675 napi_enable(&port->port_res[i].napi);
2676}
2677
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002678static int ehea_open(struct net_device *dev)
2679{
2680 int ret;
2681 struct ehea_port *port = netdev_priv(dev);
2682
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002683 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002684
Joe Perches8c4877a2010-12-13 10:05:14 -08002685 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002686
2687 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002688 if (!ret) {
2689 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002690 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002691 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002692
Breno Leitao5b27d422010-10-05 13:16:22 +00002693 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002694 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002695
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002696 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002697
2698 return ret;
2699}
2700
2701static int ehea_down(struct net_device *dev)
2702{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002703 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002704 struct ehea_port *port = netdev_priv(dev);
2705
2706 if (port->state == EHEA_PORT_DOWN)
2707 return 0;
2708
2709 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002710 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2711
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 ehea_free_interrupts(dev);
2713
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002715
Thomas Klein21eee2d2008-02-13 16:18:33 +01002716 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002717
Thomas Klein44c82152007-07-11 16:32:00 +02002718 ret = ehea_clean_all_portres(port);
2719 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002720 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002721
Thomas Klein21eee2d2008-02-13 16:18:33 +01002722 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002723
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002724 return ret;
2725}
2726
2727static int ehea_stop(struct net_device *dev)
2728{
2729 int ret;
2730 struct ehea_port *port = netdev_priv(dev);
2731
Joe Perches8c4877a2010-12-13 10:05:14 -08002732 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002734 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002735 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002736 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002737 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002738 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002739 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002740 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002741 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002742 return ret;
2743}
2744
Andrew Morton22559c52008-04-18 13:50:39 -07002745static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002746{
2747 struct ehea_qp qp = *orig_qp;
2748 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2749 struct ehea_swqe *swqe;
2750 int wqe_index;
2751 int i;
2752
2753 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2754 swqe = ehea_get_swqe(&qp, &wqe_index);
2755 swqe->tx_control |= EHEA_SWQE_PURGE;
2756 }
2757}
2758
Andrew Morton22559c52008-04-18 13:50:39 -07002759static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002760{
2761 int i;
2762
2763 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2764 struct ehea_port_res *pr = &port->port_res[i];
2765 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002766 int ret;
2767
2768 ret = wait_event_timeout(port->swqe_avail_wq,
2769 atomic_read(&pr->swqe_avail) >= swqe_max,
2770 msecs_to_jiffies(100));
2771
2772 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002773 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002774 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002775 }
2776 }
2777}
2778
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002779int ehea_stop_qps(struct net_device *dev)
2780{
2781 struct ehea_port *port = netdev_priv(dev);
2782 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002783 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002784 int ret = -EIO;
2785 int dret;
2786 int i;
2787 u64 hret;
2788 u64 dummy64 = 0;
2789 u16 dummy16 = 0;
2790
Thomas Klein3faf2692009-01-21 14:45:33 -08002791 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002792 if (!cb0) {
2793 ret = -ENOMEM;
2794 goto out;
2795 }
2796
2797 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2798 struct ehea_port_res *pr = &port->port_res[i];
2799 struct ehea_qp *qp = pr->qp;
2800
2801 /* Purge send queue */
2802 ehea_purge_sq(qp);
2803
2804 /* Disable queue pair */
2805 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2806 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2807 cb0);
2808 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002809 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002810 goto out;
2811 }
2812
2813 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2814 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2815
2816 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2817 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2818 1), cb0, &dummy64,
2819 &dummy64, &dummy16, &dummy16);
2820 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002821 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002822 goto out;
2823 }
2824
2825 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2826 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2827 cb0);
2828 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002829 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002830 goto out;
2831 }
2832
2833 /* deregister shared memory regions */
2834 dret = ehea_rem_smrs(pr);
2835 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002836 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002837 goto out;
2838 }
2839 }
2840
2841 ret = 0;
2842out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002843 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002844
2845 return ret;
2846}
2847
Doug Maxey508d2b52008-01-31 20:20:49 -06002848void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002849{
2850 struct ehea_qp qp = *orig_qp;
2851 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2852 struct ehea_rwqe *rwqe;
2853 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2854 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2855 struct sk_buff *skb;
2856 u32 lkey = pr->recv_mr.lkey;
2857
2858
2859 int i;
2860 int index;
2861
2862 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2863 rwqe = ehea_get_next_rwqe(&qp, 2);
2864 rwqe->sg_list[0].l_key = lkey;
2865 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2866 skb = skba_rq2[index];
2867 if (skb)
2868 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2869 }
2870
2871 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2872 rwqe = ehea_get_next_rwqe(&qp, 3);
2873 rwqe->sg_list[0].l_key = lkey;
2874 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2875 skb = skba_rq3[index];
2876 if (skb)
2877 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2878 }
2879}
2880
2881int ehea_restart_qps(struct net_device *dev)
2882{
2883 struct ehea_port *port = netdev_priv(dev);
2884 struct ehea_adapter *adapter = port->adapter;
2885 int ret = 0;
2886 int i;
2887
Doug Maxey508d2b52008-01-31 20:20:49 -06002888 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002889 u64 hret;
2890 u64 dummy64 = 0;
2891 u16 dummy16 = 0;
2892
Thomas Klein3faf2692009-01-21 14:45:33 -08002893 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002894 if (!cb0) {
2895 ret = -ENOMEM;
2896 goto out;
2897 }
2898
2899 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2900 struct ehea_port_res *pr = &port->port_res[i];
2901 struct ehea_qp *qp = pr->qp;
2902
2903 ret = ehea_gen_smrs(pr);
2904 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002905 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002906 goto out;
2907 }
2908
2909 ehea_update_rqs(qp, pr);
2910
2911 /* Enable queue pair */
2912 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2913 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2914 cb0);
2915 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002916 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002917 goto out;
2918 }
2919
2920 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2921 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2922
2923 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2924 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2925 1), cb0, &dummy64,
2926 &dummy64, &dummy16, &dummy16);
2927 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002928 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002929 goto out;
2930 }
2931
2932 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2933 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2934 cb0);
2935 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002936 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002937 goto out;
2938 }
2939
2940 /* refill entire queue */
2941 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2942 ehea_refill_rq2(pr, 0);
2943 ehea_refill_rq3(pr, 0);
2944 }
2945out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002946 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002947
2948 return ret;
2949}
2950
David Howellsc4028952006-11-22 14:57:56 +00002951static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002952{
2953 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002954 struct ehea_port *port =
2955 container_of(work, struct ehea_port, reset_task);
2956 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002958 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002959 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002960 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002961 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002962
2963 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964
Thomas Klein44c82152007-07-11 16:32:00 +02002965 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002966
2967 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002968 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002969 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002970
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002971 ehea_set_multicast_list(dev);
2972
Joe Perches8c4877a2010-12-13 10:05:14 -08002973 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002974
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002975 port_napi_enable(port);
2976
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002977 netif_wake_queue(dev);
2978out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002979 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002980 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002981}
2982
Tejun Heo3d6b8922010-12-12 16:45:14 +01002983static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002984{
2985 int ret, i;
2986 struct ehea_adapter *adapter;
2987
Joe Perches8c4877a2010-12-13 10:05:14 -08002988 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002989
2990 list_for_each_entry(adapter, &adapter_list, list)
2991 if (adapter->active_ports) {
2992 /* Shutdown all ports */
2993 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2994 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002995 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002996
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002997 if (!port)
2998 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002999
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003000 dev = port->netdev;
3001
3002 if (dev->flags & IFF_UP) {
3003 mutex_lock(&port->port_lock);
3004 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003005 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003006 ret = ehea_stop_qps(dev);
3007 if (ret) {
3008 mutex_unlock(&port->port_lock);
3009 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003010 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003011 port_napi_disable(port);
3012 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003013 }
Andre Detsch2928db42010-08-17 05:49:12 +00003014 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003015 }
3016
3017 /* Unregister old memory region */
3018 ret = ehea_rem_mr(&adapter->mr);
3019 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003020 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003021 goto out;
3022 }
3023 }
3024
Thomas Klein44c82152007-07-11 16:32:00 +02003025 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3026
3027 list_for_each_entry(adapter, &adapter_list, list)
3028 if (adapter->active_ports) {
3029 /* Register new memory region */
3030 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3031 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003032 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003033 goto out;
3034 }
3035
3036 /* Restart all ports */
3037 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3038 struct ehea_port *port = adapter->port[i];
3039
3040 if (port) {
3041 struct net_device *dev = port->netdev;
3042
3043 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003044 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003045 port_napi_enable(port);
3046 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003047 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003048 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003049 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003050 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003051 }
3052 }
3053 }
3054 }
Joe Perches8c4877a2010-12-13 10:05:14 -08003055 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02003056out:
3057 return;
3058}
3059
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003060static void ehea_tx_watchdog(struct net_device *dev)
3061{
3062 struct ehea_port *port = netdev_priv(dev);
3063
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003064 if (netif_carrier_ok(dev) &&
3065 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003066 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003067}
3068
3069int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3070{
3071 struct hcp_query_ehea *cb;
3072 u64 hret;
3073 int ret;
3074
Thomas Klein3faf2692009-01-21 14:45:33 -08003075 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003076 if (!cb) {
3077 ret = -ENOMEM;
3078 goto out;
3079 }
3080
3081 hret = ehea_h_query_ehea(adapter->handle, cb);
3082
3083 if (hret != H_SUCCESS) {
3084 ret = -EIO;
3085 goto out_herr;
3086 }
3087
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003088 adapter->max_mc_mac = cb->max_mc_mac - 1;
3089 ret = 0;
3090
3091out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003092 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003093out:
3094 return ret;
3095}
3096
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003097int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3098{
3099 struct hcp_ehea_port_cb4 *cb4;
3100 u64 hret;
3101 int ret = 0;
3102
3103 *jumbo = 0;
3104
3105 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003106 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003107 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003108 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003109 ret = -ENOMEM;
3110 goto out;
3111 } else {
3112 hret = ehea_h_query_ehea_port(port->adapter->handle,
3113 port->logical_port_id,
3114 H_PORT_CB4,
3115 H_PORT_CB4_JUMBO, cb4);
3116 if (hret == H_SUCCESS) {
3117 if (cb4->jumbo_frame)
3118 *jumbo = 1;
3119 else {
3120 cb4->jumbo_frame = 1;
3121 hret = ehea_h_modify_ehea_port(port->adapter->
3122 handle,
3123 port->
3124 logical_port_id,
3125 H_PORT_CB4,
3126 H_PORT_CB4_JUMBO,
3127 cb4);
3128 if (hret == H_SUCCESS)
3129 *jumbo = 1;
3130 }
3131 } else
3132 ret = -EINVAL;
3133
Thomas Klein3faf2692009-01-21 14:45:33 -08003134 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003135 }
3136out:
3137 return ret;
3138}
3139
3140static ssize_t ehea_show_port_id(struct device *dev,
3141 struct device_attribute *attr, char *buf)
3142{
3143 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003144 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003145}
3146
3147static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3148 NULL);
3149
3150static void __devinit logical_port_release(struct device *dev)
3151{
3152 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003153 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003154}
3155
3156static struct device *ehea_register_port(struct ehea_port *port,
3157 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003158{
3159 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003160
Grant Likely61c7a082010-04-13 16:12:29 -07003161 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003162 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003163 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003164
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003165 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166 port->ofdev.dev.release = logical_port_release;
3167
3168 ret = of_device_register(&port->ofdev);
3169 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003170 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 goto out;
3172 }
3173
3174 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003175 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003176 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177 goto out_unreg_of_dev;
3178 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003179
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180 return &port->ofdev.dev;
3181
3182out_unreg_of_dev:
3183 of_device_unregister(&port->ofdev);
3184out:
3185 return NULL;
3186}
3187
3188static void ehea_unregister_port(struct ehea_port *port)
3189{
3190 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3191 of_device_unregister(&port->ofdev);
3192}
3193
Thomas Klein086c1b22009-01-21 14:43:59 -08003194static const struct net_device_ops ehea_netdev_ops = {
3195 .ndo_open = ehea_open,
3196 .ndo_stop = ehea_stop,
3197 .ndo_start_xmit = ehea_start_xmit,
3198#ifdef CONFIG_NET_POLL_CONTROLLER
3199 .ndo_poll_controller = ehea_netpoll,
3200#endif
3201 .ndo_get_stats = ehea_get_stats,
3202 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003203 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003204 .ndo_set_multicast_list = ehea_set_multicast_list,
3205 .ndo_change_mtu = ehea_change_mtu,
3206 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3207 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003208 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3209 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003210};
3211
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003212struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3213 u32 logical_port_id,
3214 struct device_node *dn)
3215{
3216 int ret;
3217 struct net_device *dev;
3218 struct ehea_port *port;
3219 struct device *port_dev;
3220 int jumbo;
3221
3222 /* allocate memory for the port structures */
3223 dev = alloc_etherdev(sizeof(struct ehea_port));
3224
3225 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003226 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003227 ret = -ENOMEM;
3228 goto out_err;
3229 }
3230
3231 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003232
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003233 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003234 port->state = EHEA_PORT_DOWN;
3235 port->sig_comp_iv = sq_entries / 10;
3236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 port->adapter = adapter;
3238 port->netdev = dev;
3239 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003241 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003242
3243 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3244 if (!port->mc_list) {
3245 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003247 }
3248
3249 INIT_LIST_HEAD(&port->mc_list->list);
3250
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003251 ret = ehea_sense_port_attr(port);
3252 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003254
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255 port_dev = ehea_register_port(port, dn);
3256 if (!port_dev)
3257 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003258
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260
3261 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3263
Thomas Klein086c1b22009-01-21 14:43:59 -08003264 dev->netdev_ops = &ehea_netdev_ops;
3265 ehea_set_ethtool_ops(dev);
3266
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003267 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003268 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003269 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3270 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003271 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3272
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003273 if (use_lro)
3274 dev->features |= NETIF_F_LRO;
3275
David Howellsc4028952006-11-22 14:57:56 +00003276 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277
3278 ret = register_netdev(dev);
3279 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003280 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003281 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003282 }
3283
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003284 port->lro_max_aggr = lro_max_aggr;
3285
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003286 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003287 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003288 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003289
Joe Perches8c4877a2010-12-13 10:05:14 -08003290 netdev_info(dev, "Jumbo frames are %sabled\n",
3291 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003292
Thomas Klein44c82152007-07-11 16:32:00 +02003293 adapter->active_ports++;
3294
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003295 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003297out_unreg_port:
3298 ehea_unregister_port(port);
3299
3300out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003301 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003302
3303out_free_ethdev:
3304 free_netdev(dev);
3305
3306out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003307 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3308 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003309 return NULL;
3310}
3311
3312static void ehea_shutdown_single_port(struct ehea_port *port)
3313{
Brian King7fb1c2a2008-05-14 09:48:25 -05003314 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003315
3316 cancel_work_sync(&port->reset_task);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003317 unregister_netdev(port->netdev);
3318 ehea_unregister_port(port);
3319 kfree(port->mc_list);
3320 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003321 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003322}
3323
3324static int ehea_setup_ports(struct ehea_adapter *adapter)
3325{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003326 struct device_node *lhea_dn;
3327 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003328
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003329 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003330 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003331
Grant Likely61c7a082010-04-13 16:12:29 -07003332 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003333 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003334
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003335 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003336 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003337 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003338 pr_err("bad device node: eth_dn name=%s\n",
3339 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003341 }
3342
Thomas Klein1211bb62007-04-26 11:56:43 +02003343 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003344 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003345 of_node_put(eth_dn);
3346 return -EIO;
3347 }
3348
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003349 adapter->port[i] = ehea_setup_single_port(adapter,
3350 *dn_log_port_id,
3351 eth_dn);
3352 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003353 netdev_info(adapter->port[i]->netdev,
3354 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003355 else
3356 ehea_remove_adapter_mr(adapter);
3357
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003359 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003360 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361}
3362
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003363static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3364 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365{
3366 struct device_node *lhea_dn;
3367 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003368 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003369
Grant Likely61c7a082010-04-13 16:12:29 -07003370 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003371 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003372
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003373 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003374 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003375 if (dn_log_port_id)
3376 if (*dn_log_port_id == logical_port_id)
3377 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003378 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003379
3380 return NULL;
3381}
3382
3383static ssize_t ehea_probe_port(struct device *dev,
3384 struct device_attribute *attr,
3385 const char *buf, size_t count)
3386{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003387 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003388 struct ehea_port *port;
3389 struct device_node *eth_dn = NULL;
3390 int i;
3391
3392 u32 logical_port_id;
3393
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003394 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003395
3396 port = ehea_get_port(adapter, logical_port_id);
3397
3398 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003399 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3400 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003401 return -EINVAL;
3402 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003403
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003404 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3405
3406 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003407 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003408 return -EINVAL;
3409 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003410
Thomas Klein1211bb62007-04-26 11:56:43 +02003411 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003412 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003413 return -EIO;
3414 }
3415
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003416 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3417
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003418 of_node_put(eth_dn);
3419
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003420 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003421 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003422 if (!adapter->port[i]) {
3423 adapter->port[i] = port;
3424 break;
3425 }
3426
Joe Perches8c4877a2010-12-13 10:05:14 -08003427 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3428 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003429 } else {
3430 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003431 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003432 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433
3434 return (ssize_t) count;
3435}
3436
3437static ssize_t ehea_remove_port(struct device *dev,
3438 struct device_attribute *attr,
3439 const char *buf, size_t count)
3440{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003441 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003442 struct ehea_port *port;
3443 int i;
3444 u32 logical_port_id;
3445
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003446 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003447
3448 port = ehea_get_port(adapter, logical_port_id);
3449
3450 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003451 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3452 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003453
3454 ehea_shutdown_single_port(port);
3455
Doug Maxey508d2b52008-01-31 20:20:49 -06003456 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003457 if (adapter->port[i] == port) {
3458 adapter->port[i] = NULL;
3459 break;
3460 }
3461 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003462 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3463 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003464 return -EINVAL;
3465 }
3466
Thomas Klein1211bb62007-04-26 11:56:43 +02003467 ehea_remove_adapter_mr(adapter);
3468
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003469 return (ssize_t) count;
3470}
3471
3472static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3473static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3474
Grant Likely2dc11582010-08-06 09:25:50 -06003475int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003476{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003477 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003478 if (ret)
3479 goto out;
3480
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003481 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003482out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003483 return ret;
3484}
3485
Grant Likely2dc11582010-08-06 09:25:50 -06003486void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003487{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003488 device_remove_file(&dev->dev, &dev_attr_probe_port);
3489 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003490}
3491
Grant Likely2dc11582010-08-06 09:25:50 -06003492static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003493 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494{
3495 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003496 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003497 int ret;
3498
Grant Likely61c7a082010-04-13 16:12:29 -07003499 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003500 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003501 return -EINVAL;
3502 }
3503
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3505 if (!adapter) {
3506 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003507 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003508 goto out;
3509 }
3510
Thomas Klein44c82152007-07-11 16:32:00 +02003511 list_add(&adapter->list, &adapter_list);
3512
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003513 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003514
Grant Likely61c7a082010-04-13 16:12:29 -07003515 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003516 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003517 if (adapter_handle)
3518 adapter->handle = *adapter_handle;
3519
3520 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003521 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003522 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003523 ret = -ENODEV;
3524 goto out_free_ad;
3525 }
3526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 adapter->pd = EHEA_PD_ID;
3528
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003529 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531
3532 /* initialize adapter and ports */
3533 /* get adapter properties */
3534 ret = ehea_sense_adapter_attr(adapter);
3535 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003536 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003537 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003538 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539
3540 adapter->neq = ehea_create_eq(adapter,
3541 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3542 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003543 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003544 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003545 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546 }
3547
3548 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3549 (unsigned long)adapter);
3550
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003551 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003552 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553 "ehea_neq", adapter);
3554 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003555 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003556 goto out_kill_eq;
3557 }
3558
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003559 ret = ehea_create_device_sysfs(dev);
3560 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003561 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003562
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003563 ret = ehea_setup_ports(adapter);
3564 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003565 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003566 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003567 }
3568
3569 ret = 0;
3570 goto out;
3571
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003572out_rem_dev_sysfs:
3573 ehea_remove_device_sysfs(dev);
3574
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003575out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003576 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577
3578out_kill_eq:
3579 ehea_destroy_eq(adapter->neq);
3580
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003582 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003583 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003585out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003586 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003587
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588 return ret;
3589}
3590
Grant Likely2dc11582010-08-06 09:25:50 -06003591static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003593 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003594 int i;
3595
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003596 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003597 if (adapter->port[i]) {
3598 ehea_shutdown_single_port(adapter->port[i]);
3599 adapter->port[i] = NULL;
3600 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003601
3602 ehea_remove_device_sysfs(dev);
3603
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003604 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003605 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003606
3607 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003608 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003609 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003610 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003611
Thomas Klein21eee2d2008-02-13 16:18:33 +01003612 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003614 return 0;
3615}
3616
Thomas Klein21eee2d2008-02-13 16:18:33 +01003617void ehea_crash_handler(void)
3618{
3619 int i;
3620
3621 if (ehea_fw_handles.arr)
3622 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3623 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3624 ehea_fw_handles.arr[i].fwh,
3625 FORCE_FREE);
3626
3627 if (ehea_bcmc_regs.arr)
3628 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3629 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3630 ehea_bcmc_regs.arr[i].port_id,
3631 ehea_bcmc_regs.arr[i].reg_type,
3632 ehea_bcmc_regs.arr[i].macaddr,
3633 0, H_DEREG_BCMC);
3634}
3635
Hannes Hering48cfb142008-05-07 14:43:36 +02003636static int ehea_mem_notifier(struct notifier_block *nb,
3637 unsigned long action, void *data)
3638{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003639 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003640 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003641
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003642 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003643
Hannes Hering48cfb142008-05-07 14:43:36 +02003644 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003645 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003646 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003647 /* Readd canceled memory block */
3648 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003649 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003650 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003651 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003652 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003653 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003654 break;
3655 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003656 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003657 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003658 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003659 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003660 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003661 break;
3662 default:
3663 break;
3664 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003665
3666 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003667 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003668
Thomas Kleina7c561f22010-04-20 23:11:31 +00003669out_unlock:
3670 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003671 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003672}
3673
3674static struct notifier_block ehea_mem_nb = {
3675 .notifier_call = ehea_mem_notifier,
3676};
3677
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003678static int ehea_reboot_notifier(struct notifier_block *nb,
3679 unsigned long action, void *unused)
3680{
3681 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003682 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003683 ibmebus_unregister_driver(&ehea_driver);
3684 }
3685 return NOTIFY_DONE;
3686}
3687
3688static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003689 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003690};
3691
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003692static int check_module_parm(void)
3693{
3694 int ret = 0;
3695
3696 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3697 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003698 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003699 ret = -EINVAL;
3700 }
3701 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3702 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003703 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003704 ret = -EINVAL;
3705 }
3706 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3707 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003708 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003709 ret = -EINVAL;
3710 }
3711 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3712 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003713 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003714 ret = -EINVAL;
3715 }
3716
3717 return ret;
3718}
3719
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003720static ssize_t ehea_show_capabilities(struct device_driver *drv,
3721 char *buf)
3722{
3723 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3724}
3725
3726static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3727 ehea_show_capabilities, NULL);
3728
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003729int __init ehea_module_init(void)
3730{
3731 int ret;
3732
Joe Perches8c4877a2010-12-13 10:05:14 -08003733 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003734
Thomas Klein21eee2d2008-02-13 16:18:33 +01003735 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3736 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3737
Daniel Walker9f71a562008-03-28 14:41:26 -07003738 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003739 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003740
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003741 ret = check_module_parm();
3742 if (ret)
3743 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003744
3745 ret = ehea_create_busmap();
3746 if (ret)
3747 goto out;
3748
Thomas Klein21eee2d2008-02-13 16:18:33 +01003749 ret = register_reboot_notifier(&ehea_reboot_nb);
3750 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003751 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003752
Hannes Hering48cfb142008-05-07 14:43:36 +02003753 ret = register_memory_notifier(&ehea_mem_nb);
3754 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003755 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003756
Joe Perchesc061b182010-08-23 18:20:03 +00003757 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003758 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003759 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003760
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003761 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003762 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003763 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003764 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003765 }
3766
3767 ret = driver_create_file(&ehea_driver.driver,
3768 &driver_attr_capabilities);
3769 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003770 pr_err("failed to register capabilities attribute, ret=%d\n",
3771 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003772 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003773 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003774
Thomas Klein21eee2d2008-02-13 16:18:33 +01003775 return ret;
3776
3777out3:
3778 ibmebus_unregister_driver(&ehea_driver);
3779out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003780 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003781 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003782 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003783out:
3784 return ret;
3785}
3786
3787static void __exit ehea_module_exit(void)
3788{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003789 int ret;
3790
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003791 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003792 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003793 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003794 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003795 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003796 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003797 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003798 kfree(ehea_fw_handles.arr);
3799 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003800 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003801}
3802
3803module_init(ehea_module_init);
3804module_exit(ehea_module_exit);