blob: 7897bdf76e66bb4acb3749a4b53d13dc36f43239 [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
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/tcp.h>
32#include <linux/udp.h>
33#include <linux/if.h>
34#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020036#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020037#include <linux/notifier.h>
38#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020039#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010040#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070041#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020042
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020043#include <net/ip.h>
44
45#include "ehea.h"
46#include "ehea_qmr.h"
47#include "ehea_phyp.h"
48
49
50MODULE_LICENSE("GPL");
51MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
52MODULE_DESCRIPTION("IBM eServer HEA Driver");
53MODULE_VERSION(DRV_VERSION);
54
55
56static int msg_level = -1;
57static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
58static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
59static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
60static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060061static int use_mcs;
62static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070063static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010064static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070074module_param(use_lro, int, 0);
75module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020077
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010078MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020080MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
81 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
85MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
88MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
91MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020094MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020095
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070096MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
97 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
98MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
99 "Default = 0");
100
Doug Maxey508d2b52008-01-31 20:20:49 -0600101static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200102static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800103static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200104struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700105static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100106struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Grant Likely2dc11582010-08-06 09:25:50 -0600110static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200111 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Grant Likely2dc11582010-08-06 09:25:50 -0600113static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
115static struct of_device_id ehea_device_table[] = {
116 {
117 .name = "lhea",
118 .compatible = "IBM,lhea",
119 },
120 {},
121};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100122MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200123
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700125 .driver = {
126 .name = "ehea",
127 .owner = THIS_MODULE,
128 .of_match_table = ehea_device_table,
129 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200130 .probe = ehea_probe_adapter,
131 .remove = ehea_remove,
132};
133
Doug Maxey508d2b52008-01-31 20:20:49 -0600134void ehea_dump(void *adr, int len, char *msg)
135{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200136 int x;
137 unsigned char *deb = adr;
138 for (x = 0; x < len; x += 16) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000139 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600140 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200141 deb += 16;
142 }
143}
144
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100145void ehea_schedule_port_reset(struct ehea_port *port)
146{
147 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
148 schedule_work(&port->reset_task);
149}
150
Thomas Klein21eee2d2008-02-13 16:18:33 +0100151static void ehea_update_firmware_handles(void)
152{
153 struct ehea_fw_handle_entry *arr = NULL;
154 struct ehea_adapter *adapter;
155 int num_adapters = 0;
156 int num_ports = 0;
157 int num_portres = 0;
158 int i = 0;
159 int num_fw_handles, k, l;
160
161 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700162 mutex_lock(&ehea_fw_handles.lock);
163
Thomas Klein21eee2d2008-02-13 16:18:33 +0100164 list_for_each_entry(adapter, &adapter_list, list) {
165 num_adapters++;
166
167 for (k = 0; k < EHEA_MAX_PORTS; k++) {
168 struct ehea_port *port = adapter->port[k];
169
170 if (!port || (port->state != EHEA_PORT_UP))
171 continue;
172
173 num_ports++;
174 num_portres += port->num_def_qps + port->num_add_tx_qps;
175 }
176 }
177
178 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
179 num_ports * EHEA_NUM_PORT_FW_HANDLES +
180 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
181
182 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000183 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700185 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 } else
187 goto out_update;
188
189 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700190 if (num_adapters == 0)
191 break;
192
Thomas Klein21eee2d2008-02-13 16:18:33 +0100193 for (k = 0; k < EHEA_MAX_PORTS; k++) {
194 struct ehea_port *port = adapter->port[k];
195
Joe Perches8e95a202009-12-03 07:58:21 +0000196 if (!port || (port->state != EHEA_PORT_UP) ||
197 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100198 continue;
199
200 for (l = 0;
201 l < port->num_def_qps + port->num_add_tx_qps;
202 l++) {
203 struct ehea_port_res *pr = &port->port_res[l];
204
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->qp->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->send_cq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->recv_cq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->eq->fw_handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->send_mr.handle;
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = pr->recv_mr.handle;
217 }
218 arr[i].adh = adapter->handle;
219 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700220 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100221 }
222
223 arr[i].adh = adapter->handle;
224 arr[i++].fwh = adapter->neq->fw_handle;
225
226 if (adapter->mr.handle) {
227 arr[i].adh = adapter->handle;
228 arr[i++].fwh = adapter->mr.handle;
229 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700230 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100231 }
232
233out_update:
234 kfree(ehea_fw_handles.arr);
235 ehea_fw_handles.arr = arr;
236 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700237out:
238 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100239}
240
241static void ehea_update_bcmc_registrations(void)
242{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700243 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100244 struct ehea_bcmc_reg_entry *arr = NULL;
245 struct ehea_adapter *adapter;
246 struct ehea_mc_list *mc_entry;
247 int num_registrations = 0;
248 int i = 0;
249 int k;
250
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700251 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
252
Thomas Klein21eee2d2008-02-13 16:18:33 +0100253 /* Determine number of registrations */
254 list_for_each_entry(adapter, &adapter_list, list)
255 for (k = 0; k < EHEA_MAX_PORTS; k++) {
256 struct ehea_port *port = adapter->port[k];
257
258 if (!port || (port->state != EHEA_PORT_UP))
259 continue;
260
261 num_registrations += 2; /* Broadcast registrations */
262
263 list_for_each_entry(mc_entry, &port->mc_list->list,list)
264 num_registrations += 2;
265 }
266
267 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000268 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100269 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100271 } else
272 goto out_update;
273
274 list_for_each_entry(adapter, &adapter_list, list) {
275 for (k = 0; k < EHEA_MAX_PORTS; k++) {
276 struct ehea_port *port = adapter->port[k];
277
278 if (!port || (port->state != EHEA_PORT_UP))
279 continue;
280
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700281 if (num_registrations == 0)
282 goto out_update;
283
Thomas Klein21eee2d2008-02-13 16:18:33 +0100284 arr[i].adh = adapter->handle;
285 arr[i].port_id = port->logical_port_id;
286 arr[i].reg_type = EHEA_BCMC_BROADCAST |
287 EHEA_BCMC_UNTAGGED;
288 arr[i++].macaddr = port->mac_addr;
289
290 arr[i].adh = adapter->handle;
291 arr[i].port_id = port->logical_port_id;
292 arr[i].reg_type = EHEA_BCMC_BROADCAST |
293 EHEA_BCMC_VLANID_ALL;
294 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700295 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100296
297 list_for_each_entry(mc_entry,
298 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700299 if (num_registrations == 0)
300 goto out_update;
301
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 arr[i].adh = adapter->handle;
303 arr[i].port_id = port->logical_port_id;
304 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
305 EHEA_BCMC_MULTICAST |
306 EHEA_BCMC_UNTAGGED;
307 arr[i++].macaddr = mc_entry->macaddr;
308
309 arr[i].adh = adapter->handle;
310 arr[i].port_id = port->logical_port_id;
311 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
312 EHEA_BCMC_MULTICAST |
313 EHEA_BCMC_VLANID_ALL;
314 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100316 }
317 }
318 }
319
320out_update:
321 kfree(ehea_bcmc_regs.arr);
322 ehea_bcmc_regs.arr = arr;
323 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700324out:
325 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100326}
327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200328static struct net_device_stats *ehea_get_stats(struct net_device *dev)
329{
330 struct ehea_port *port = netdev_priv(dev);
331 struct net_device_stats *stats = &port->stats;
332 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100333 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200334 int i;
335
336 memset(stats, 0, sizeof(*stats));
337
Brian King3d8009c2010-06-30 11:59:12 +0000338 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200339 if (!cb2) {
340 ehea_error("no mem for cb2");
341 goto out;
342 }
343
344 hret = ehea_h_query_ehea_port(port->adapter->handle,
345 port->logical_port_id,
346 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
347 if (hret != H_SUCCESS) {
348 ehea_error("query_ehea_port failed");
349 goto out_herr;
350 }
351
352 if (netif_msg_hw(port))
353 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
354
355 rx_packets = 0;
356 for (i = 0; i < port->num_def_qps; i++)
357 rx_packets += port->port_res[i].rx_packets;
358
Thomas Klein7393b872007-11-21 17:37:58 +0100359 tx_packets = 0;
360 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
361 tx_packets += port->port_res[i].tx_packets;
362
363 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364 stats->multicast = cb2->rxmcp;
365 stats->rx_errors = cb2->rxuerr;
366 stats->rx_bytes = cb2->rxo;
367 stats->tx_bytes = cb2->txo;
368 stats->rx_packets = rx_packets;
369
370out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800371 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372out:
373 return stats;
374}
375
376static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
377{
378 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
379 struct net_device *dev = pr->port->netdev;
380 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200381 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
382 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200383 int i;
384
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200385 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200386
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200388 if (nr_of_wqes > 0)
389 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200390 pr->rq1_skba.os_skbs = fill_wqes;
391 return;
392 }
393
394 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200395 if (!skb_arr_rq1[index]) {
396 skb_arr_rq1[index] = netdev_alloc_skb(dev,
397 EHEA_L_PKT_SIZE);
398 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200399 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200400 break;
401 }
402 }
403 index--;
404 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200406 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200407
408 if (adder == 0)
409 return;
410
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200411 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413}
414
Thomas Kleine2878802009-01-21 14:45:57 -0800415static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
418 struct net_device *dev = pr->port->netdev;
419 int i;
420
421 for (i = 0; i < pr->rq1_skba.len; i++) {
422 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800423 if (!skb_arr_rq1[i])
424 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200425 }
426 /* Ring doorbell */
427 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200428}
429
430static int ehea_refill_rq_def(struct ehea_port_res *pr,
431 struct ehea_q_skb_arr *q_skba, int rq_nr,
432 int num_wqes, int wqe_type, int packet_size)
433{
434 struct net_device *dev = pr->port->netdev;
435 struct ehea_qp *qp = pr->qp;
436 struct sk_buff **skb_arr = q_skba->arr;
437 struct ehea_rwqe *rwqe;
438 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200439 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440 int ret = 0;
441
442 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200443 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200444
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200445 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
446 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200447 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200448 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200449
450 index = q_skba->index;
451 max_index_mask = q_skba->len - 1;
452 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000454 struct sk_buff *skb;
455
456 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800459 if (q_skba->os_skbs == q_skba->len - 2) {
460 ehea_info("%s: rq%i ran dry - no mem for skb",
461 pr->port->netdev->name, rq_nr);
462 ret = -ENOMEM;
463 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200464 break;
465 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200466
467 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 tmp_addr = ehea_map_vaddr(skb->data);
469 if (tmp_addr == -1) {
470 dev_kfree_skb(skb);
471 q_skba->os_skbs = fill_wqes - i;
472 ret = 0;
473 break;
474 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475
476 rwqe = ehea_get_next_rwqe(qp, rq_nr);
477 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200478 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200480 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481 rwqe->sg_list[0].len = packet_size;
482 rwqe->data_segments = 1;
483
484 index++;
485 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200486 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487 }
Thomas Klein44c82152007-07-11 16:32:00 +0200488
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200490 if (adder == 0)
491 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492
493 /* Ring doorbell */
494 iosync();
495 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200496 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200497 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200498 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200499out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 return ret;
501}
502
503
504static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
505{
506 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
507 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000508 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509}
510
511
512static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
513{
514 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
515 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000516 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200517}
518
519static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
520{
521 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
522 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
523 return 0;
524 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
525 (cqe->header_length == 0))
526 return 0;
527 return -EINVAL;
528}
529
530static inline void ehea_fill_skb(struct net_device *dev,
531 struct sk_buff *skb, struct ehea_cqe *cqe)
532{
533 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
534
535 skb_put(skb, length);
536 skb->ip_summed = CHECKSUM_UNNECESSARY;
537 skb->protocol = eth_type_trans(skb, dev);
538}
539
540static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
541 int arr_len,
542 struct ehea_cqe *cqe)
543{
544 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
545 struct sk_buff *skb;
546 void *pref;
547 int x;
548
549 x = skb_index + 1;
550 x &= (arr_len - 1);
551
552 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700553 if (pref) {
554 prefetchw(pref);
555 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200556
Hannes Hering0b2febf2009-05-04 11:06:37 -0700557 pref = (skb_array[x]->data);
558 prefetch(pref);
559 prefetch(pref + EHEA_CACHE_LINE);
560 prefetch(pref + EHEA_CACHE_LINE * 2);
561 prefetch(pref + EHEA_CACHE_LINE * 3);
562 }
563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200564 skb = skb_array[skb_index];
565 skb_array[skb_index] = NULL;
566 return skb;
567}
568
569static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
570 int arr_len, int wqe_index)
571{
572 struct sk_buff *skb;
573 void *pref;
574 int x;
575
576 x = wqe_index + 1;
577 x &= (arr_len - 1);
578
579 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700580 if (pref) {
581 prefetchw(pref);
582 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200583
Hannes Hering0b2febf2009-05-04 11:06:37 -0700584 pref = (skb_array[x]->data);
585 prefetchw(pref);
586 prefetchw(pref + EHEA_CACHE_LINE);
587 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200588
589 skb = skb_array[wqe_index];
590 skb_array[wqe_index] = NULL;
591 return skb;
592}
593
594static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
595 struct ehea_cqe *cqe, int *processed_rq2,
596 int *processed_rq3)
597{
598 struct sk_buff *skb;
599
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100600 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
601 pr->p_stats.err_tcp_cksum++;
602 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
603 pr->p_stats.err_ip_cksum++;
604 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
605 pr->p_stats.err_frame_crc++;
606
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200607 if (rq == 2) {
608 *processed_rq2 += 1;
609 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
610 dev_kfree_skb(skb);
611 } else if (rq == 3) {
612 *processed_rq3 += 1;
613 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
614 dev_kfree_skb(skb);
615 }
616
617 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100618 if (netif_msg_rx_err(pr->port)) {
619 ehea_error("Critical receive error for QP %d. "
620 "Resetting port.", pr->qp->init_attr.qp_nr);
621 ehea_dump(cqe, sizeof(*cqe), "CQE");
622 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100623 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200624 return 1;
625 }
626
627 return 0;
628}
629
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700630static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
631 void **tcph, u64 *hdr_flags, void *priv)
632{
633 struct ehea_cqe *cqe = priv;
634 unsigned int ip_len;
635 struct iphdr *iph;
636
637 /* non tcp/udp packets */
638 if (!cqe->header_length)
639 return -1;
640
641 /* non tcp packet */
642 skb_reset_network_header(skb);
643 iph = ip_hdr(skb);
644 if (iph->protocol != IPPROTO_TCP)
645 return -1;
646
647 ip_len = ip_hdrlen(skb);
648 skb_set_transport_header(skb, ip_len);
649 *tcph = tcp_hdr(skb);
650
651 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700652 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700653 return -1;
654
655 *hdr_flags = LRO_IPV4 | LRO_TCP;
656 *iphdr = iph;
657
658 return 0;
659}
660
661static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
662 struct sk_buff *skb)
663{
Joe Perches8e95a202009-12-03 07:58:21 +0000664 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
665 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700666
667 if (use_lro) {
668 if (vlan_extracted)
669 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
670 pr->port->vgrp,
671 cqe->vlan_tag,
672 cqe);
673 else
674 lro_receive_skb(&pr->lro_mgr, skb, cqe);
675 } else {
676 if (vlan_extracted)
677 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
678 cqe->vlan_tag);
679 else
680 netif_receive_skb(skb);
681 }
682}
683
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700684static int ehea_proc_rwqes(struct net_device *dev,
685 struct ehea_port_res *pr,
686 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200687{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100688 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200689 struct ehea_qp *qp = pr->qp;
690 struct ehea_cqe *cqe;
691 struct sk_buff *skb;
692 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
693 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
694 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
695 int skb_arr_rq1_len = pr->rq1_skba.len;
696 int skb_arr_rq2_len = pr->rq2_skba.len;
697 int skb_arr_rq3_len = pr->rq3_skba.len;
698 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700699 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700
701 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
702 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200703
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200704 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700705 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706 ehea_inc_rq1(qp);
707 processed_rq1++;
708 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200709 if (netif_msg_rx_status(port))
710 ehea_dump(cqe, sizeof(*cqe), "CQE");
711
712 last_wqe_index = wqe_index;
713 rmb();
714 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600715 if (rq == 1) {
716 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200717 skb = get_skb_by_index_ll(skb_arr_rq1,
718 skb_arr_rq1_len,
719 wqe_index);
720 if (unlikely(!skb)) {
721 if (netif_msg_rx_err(port))
722 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100723
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700724 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 EHEA_L_PKT_SIZE);
726 if (!skb)
727 break;
728 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600729 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200730 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700731 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600732 } else if (rq == 2) {
733 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 skb = get_skb_by_index(skb_arr_rq2,
735 skb_arr_rq2_len, cqe);
736 if (unlikely(!skb)) {
737 if (netif_msg_rx_err(port))
738 ehea_error("rq2: skb=NULL");
739 break;
740 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700741 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200742 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600743 } else {
744 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 skb = get_skb_by_index(skb_arr_rq3,
746 skb_arr_rq3_len, cqe);
747 if (unlikely(!skb)) {
748 if (netif_msg_rx_err(port))
749 ehea_error("rq3: skb=NULL");
750 break;
751 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700752 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200753 processed_rq3++;
754 }
755
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700756 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100757 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100758 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200759 port_reset = ehea_treat_poll_error(pr, rq, cqe,
760 &processed_rq2,
761 &processed_rq3);
762 if (port_reset)
763 break;
764 }
765 cqe = ehea_poll_rq1(qp, &wqe_index);
766 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700767 if (use_lro)
768 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200769
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200770 pr->rx_packets += processed;
771
772 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
773 ehea_refill_rq2(pr, processed_rq2);
774 ehea_refill_rq3(pr, processed_rq3);
775
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700776 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777}
778
Andre Detsch2928db42010-08-17 05:49:12 +0000779#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
780
781static void reset_sq_restart_flag(struct ehea_port *port)
782{
783 int i;
784
785 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
786 struct ehea_port_res *pr = &port->port_res[i];
787 pr->sq_restart_flag = 0;
788 }
789}
790
791static void check_sqs(struct ehea_port *port)
792{
793 struct ehea_swqe *swqe;
794 int swqe_index;
795 int i, k;
796
797 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
798 struct ehea_port_res *pr = &port->port_res[i];
799 k = 0;
800 swqe = ehea_get_swqe(pr->qp, &swqe_index);
801 memset(swqe, 0, SWQE_HEADER_SIZE);
802 atomic_dec(&pr->swqe_avail);
803
804 swqe->tx_control |= EHEA_SWQE_PURGE;
805 swqe->wr_id = SWQE_RESTART_CHECK;
806 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
807 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
808 swqe->immediate_data_length = 80;
809
810 ehea_post_swqe(pr->qp, swqe);
811
812 while (pr->sq_restart_flag == 0) {
813 msleep(5);
814 if (++k == 100) {
815 ehea_error("HW/SW queues out of sync");
816 ehea_schedule_port_reset(pr->port);
817 return;
818 }
819 }
820 }
Andre Detsch2928db42010-08-17 05:49:12 +0000821}
822
823
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100824static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200825{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100826 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200827 struct ehea_cq *send_cq = pr->send_cq;
828 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100829 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 int cqe_counter = 0;
831 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100832 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200833 unsigned long flags;
834
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100835 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600836 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100837 ehea_inc_cq(send_cq);
838
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200839 cqe_counter++;
840 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000841
842 if (cqe->wr_id == SWQE_RESTART_CHECK) {
843 pr->sq_restart_flag = 1;
844 swqe_av++;
845 break;
846 }
847
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200848 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Thomas Kleinea96cea2010-04-20 23:10:55 +0000849 ehea_error("Bad send completion status=0x%04X",
850 cqe->status);
851
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200852 if (netif_msg_tx_err(pr->port))
853 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000854
855 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
856 ehea_error("Resetting port");
857 ehea_schedule_port_reset(pr->port);
858 break;
859 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200860 }
861
862 if (netif_msg_tx_done(pr->port))
863 ehea_dump(cqe, sizeof(*cqe), "CQE");
864
865 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100866 == EHEA_SWQE2_TYPE)) {
867
868 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
869 skb = pr->sq_skba.arr[index];
870 dev_kfree_skb(skb);
871 pr->sq_skba.arr[index] = NULL;
872 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200873
874 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
875 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100876
877 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700878 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879
880 ehea_update_feca(send_cq, cqe_counter);
881 atomic_add(swqe_av, &pr->swqe_avail);
882
883 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100884
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200885 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
886 >= pr->swqe_refill_th)) {
887 netif_wake_queue(pr->port->netdev);
888 pr->queue_stopped = 0;
889 }
890 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000891 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200892
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200894}
895
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100896#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700897#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100898
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700899static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200900{
Doug Maxey508d2b52008-01-31 20:20:49 -0600901 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
902 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700903 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100904 struct ehea_cqe *cqe;
905 struct ehea_cqe *cqe_skb = NULL;
906 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700907 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908
909 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700910 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100911
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700912 if (!force_irq)
913 rx += ehea_proc_rwqes(dev, pr, budget - rx);
914
915 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100916 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700917 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800918 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100919 ehea_reset_cq_ep(pr->recv_cq);
920 ehea_reset_cq_ep(pr->send_cq);
921 ehea_reset_cq_n1(pr->recv_cq);
922 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000923 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100924 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
925 cqe_skb = ehea_poll_cq(pr->send_cq);
926
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100927 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700928 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929
Ben Hutchings288379f2009-01-19 16:43:59 -0800930 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700931 return rx;
932
933 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
934 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100935 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100936
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700937 pr->poll_counter++;
938 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200939}
940
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200941#ifdef CONFIG_NET_POLL_CONTROLLER
942static void ehea_netpoll(struct net_device *dev)
943{
944 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700945 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200946
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700947 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800948 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200949}
950#endif
951
David Howells7d12e782006-10-05 14:55:46 +0100952static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200953{
954 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100955
Ben Hutchings288379f2009-01-19 16:43:59 -0800956 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100957
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200958 return IRQ_HANDLED;
959}
960
David Howells7d12e782006-10-05 14:55:46 +0100961static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200962{
963 struct ehea_port *port = param;
964 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100965 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000967 u64 resource_type, aer, aerr;
968 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200969
970 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100971
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200972 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000974 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100975 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100976
977 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000978
979 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
980 &aer, &aerr);
981
982 if (resource_type == EHEA_AER_RESTYPE_QP) {
983 if ((aer & EHEA_AER_RESET_MASK) ||
984 (aerr & EHEA_AERR_RESET_MASK))
985 reset_port = 1;
986 } else
987 reset_port = 1; /* Reset in case of CQ or EQ error */
988
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100989 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200990 }
991
Thomas Kleinea96cea2010-04-20 23:10:55 +0000992 if (reset_port) {
993 ehea_error("Resetting port");
994 ehea_schedule_port_reset(port);
995 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100996
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200997 return IRQ_HANDLED;
998}
999
1000static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1001 int logical_port)
1002{
1003 int i;
1004
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001005 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001006 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001007 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001008 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001009 return NULL;
1010}
1011
1012int ehea_sense_port_attr(struct ehea_port *port)
1013{
1014 int ret;
1015 u64 hret;
1016 struct hcp_ehea_port_cb0 *cb0;
1017
Doug Maxey508d2b52008-01-31 20:20:49 -06001018 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001019 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001020 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001021 ehea_error("no mem for cb0");
1022 ret = -ENOMEM;
1023 goto out;
1024 }
1025
1026 hret = ehea_h_query_ehea_port(port->adapter->handle,
1027 port->logical_port_id, H_PORT_CB0,
1028 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1029 cb0);
1030 if (hret != H_SUCCESS) {
1031 ret = -EIO;
1032 goto out_free;
1033 }
1034
1035 /* MAC address */
1036 port->mac_addr = cb0->port_mac_addr << 16;
1037
Doug Maxey508d2b52008-01-31 20:20:49 -06001038 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001039 ret = -EADDRNOTAVAIL;
1040 goto out_free;
1041 }
1042
1043 /* Port speed */
1044 switch (cb0->port_speed) {
1045 case H_SPEED_10M_H:
1046 port->port_speed = EHEA_SPEED_10M;
1047 port->full_duplex = 0;
1048 break;
1049 case H_SPEED_10M_F:
1050 port->port_speed = EHEA_SPEED_10M;
1051 port->full_duplex = 1;
1052 break;
1053 case H_SPEED_100M_H:
1054 port->port_speed = EHEA_SPEED_100M;
1055 port->full_duplex = 0;
1056 break;
1057 case H_SPEED_100M_F:
1058 port->port_speed = EHEA_SPEED_100M;
1059 port->full_duplex = 1;
1060 break;
1061 case H_SPEED_1G_F:
1062 port->port_speed = EHEA_SPEED_1G;
1063 port->full_duplex = 1;
1064 break;
1065 case H_SPEED_10G_F:
1066 port->port_speed = EHEA_SPEED_10G;
1067 port->full_duplex = 1;
1068 break;
1069 default:
1070 port->port_speed = 0;
1071 port->full_duplex = 0;
1072 break;
1073 }
1074
Thomas Kleine919b592007-01-22 12:53:20 +01001075 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001076 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001077
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001078 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001079 if (use_mcs)
1080 port->num_def_qps = cb0->num_default_qps;
1081 else
1082 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001083
1084 if (!port->num_def_qps) {
1085 ret = -EINVAL;
1086 goto out_free;
1087 }
1088
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001089 port->num_tx_qps = num_tx_qps;
1090
1091 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001092 port->num_add_tx_qps = 0;
1093 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001094 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001095
1096 ret = 0;
1097out_free:
1098 if (ret || netif_msg_probe(port))
1099 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001100 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001101out:
1102 return ret;
1103}
1104
1105int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1106{
1107 struct hcp_ehea_port_cb4 *cb4;
1108 u64 hret;
1109 int ret = 0;
1110
Thomas Klein3faf2692009-01-21 14:45:33 -08001111 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001112 if (!cb4) {
1113 ehea_error("no mem for cb4");
1114 ret = -ENOMEM;
1115 goto out;
1116 }
1117
1118 cb4->port_speed = port_speed;
1119
1120 netif_carrier_off(port->netdev);
1121
1122 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1123 port->logical_port_id,
1124 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1125 if (hret == H_SUCCESS) {
1126 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1127
1128 hret = ehea_h_query_ehea_port(port->adapter->handle,
1129 port->logical_port_id,
1130 H_PORT_CB4, H_PORT_CB4_SPEED,
1131 cb4);
1132 if (hret == H_SUCCESS) {
1133 switch (cb4->port_speed) {
1134 case H_SPEED_10M_H:
1135 port->port_speed = EHEA_SPEED_10M;
1136 port->full_duplex = 0;
1137 break;
1138 case H_SPEED_10M_F:
1139 port->port_speed = EHEA_SPEED_10M;
1140 port->full_duplex = 1;
1141 break;
1142 case H_SPEED_100M_H:
1143 port->port_speed = EHEA_SPEED_100M;
1144 port->full_duplex = 0;
1145 break;
1146 case H_SPEED_100M_F:
1147 port->port_speed = EHEA_SPEED_100M;
1148 port->full_duplex = 1;
1149 break;
1150 case H_SPEED_1G_F:
1151 port->port_speed = EHEA_SPEED_1G;
1152 port->full_duplex = 1;
1153 break;
1154 case H_SPEED_10G_F:
1155 port->port_speed = EHEA_SPEED_10G;
1156 port->full_duplex = 1;
1157 break;
1158 default:
1159 port->port_speed = 0;
1160 port->full_duplex = 0;
1161 break;
1162 }
1163 } else {
1164 ehea_error("Failed sensing port speed");
1165 ret = -EIO;
1166 }
1167 } else {
1168 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001169 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001170 ret = -EPERM;
1171 } else {
1172 ret = -EIO;
1173 ehea_error("Failed setting port speed");
1174 }
1175 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001176 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1177 netif_carrier_on(port->netdev);
1178
Thomas Klein3faf2692009-01-21 14:45:33 -08001179 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001180out:
1181 return ret;
1182}
1183
1184static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1185{
1186 int ret;
1187 u8 ec;
1188 u8 portnum;
1189 struct ehea_port *port;
1190
1191 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1192 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1193 port = ehea_get_port(adapter, portnum);
1194
1195 switch (ec) {
1196 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1197
1198 if (!port) {
1199 ehea_error("unknown portnum %x", portnum);
1200 break;
1201 }
1202
1203 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1204 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001205 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001206 if (ret) {
1207 ehea_error("failed resensing port "
1208 "attributes");
1209 break;
1210 }
1211
1212 if (netif_msg_link(port))
1213 ehea_info("%s: Logical port up: %dMbps "
1214 "%s Duplex",
1215 port->netdev->name,
1216 port->port_speed,
1217 port->full_duplex ==
1218 1 ? "Full" : "Half");
1219
1220 netif_carrier_on(port->netdev);
1221 netif_wake_queue(port->netdev);
1222 }
1223 } else
1224 if (netif_carrier_ok(port->netdev)) {
1225 if (netif_msg_link(port))
1226 ehea_info("%s: Logical port down",
1227 port->netdev->name);
1228 netif_carrier_off(port->netdev);
1229 netif_stop_queue(port->netdev);
1230 }
1231
1232 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001233 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 if (netif_msg_link(port))
1235 ehea_info("%s: Physical port up",
1236 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001237 if (prop_carrier_state)
1238 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001240 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 if (netif_msg_link(port))
1242 ehea_info("%s: Physical port down",
1243 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001244 if (prop_carrier_state)
1245 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246 }
1247
1248 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1249 ehea_info("External switch port is primary port");
1250 else
1251 ehea_info("External switch port is backup port");
1252
1253 break;
1254 case EHEA_EC_ADAPTER_MALFUNC:
1255 ehea_error("Adapter malfunction");
1256 break;
1257 case EHEA_EC_PORT_MALFUNC:
1258 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1259 netif_carrier_off(port->netdev);
1260 netif_stop_queue(port->netdev);
1261 break;
1262 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001263 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001264 break;
1265 }
1266}
1267
1268static void ehea_neq_tasklet(unsigned long data)
1269{
Doug Maxey508d2b52008-01-31 20:20:49 -06001270 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271 struct ehea_eqe *eqe;
1272 u64 event_mask;
1273
1274 eqe = ehea_poll_eq(adapter->neq);
1275 ehea_debug("eqe=%p", eqe);
1276
1277 while (eqe) {
1278 ehea_debug("*eqe=%lx", eqe->entry);
1279 ehea_parse_eqe(adapter, eqe->entry);
1280 eqe = ehea_poll_eq(adapter->neq);
1281 ehea_debug("next eqe=%p", eqe);
1282 }
1283
1284 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1285 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1286 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1287
1288 ehea_h_reset_events(adapter->handle,
1289 adapter->neq->fw_handle, event_mask);
1290}
1291
David Howells7d12e782006-10-05 14:55:46 +01001292static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293{
1294 struct ehea_adapter *adapter = param;
1295 tasklet_hi_schedule(&adapter->neq_tasklet);
1296 return IRQ_HANDLED;
1297}
1298
1299
1300static int ehea_fill_port_res(struct ehea_port_res *pr)
1301{
1302 int ret;
1303 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1304
Thomas Kleine2878802009-01-21 14:45:57 -08001305 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1306 - init_attr->act_nr_rwqes_rq2
1307 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001308
Thomas Kleine2878802009-01-21 14:45:57 -08001309 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310
1311 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1312
1313 return ret;
1314}
1315
1316static int ehea_reg_interrupts(struct net_device *dev)
1317{
1318 struct ehea_port *port = netdev_priv(dev);
1319 struct ehea_port_res *pr;
1320 int i, ret;
1321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001322
1323 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1324 dev->name);
1325
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001326 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001328 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001329 if (ret) {
1330 ehea_error("failed registering irq for qp_aff_irq_handler:"
1331 "ist=%X", port->qp_eq->attr.ist1);
1332 goto out_free_qpeq;
1333 }
1334
1335 if (netif_msg_ifup(port))
1336 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1337 "registered", port->qp_eq->attr.ist1);
1338
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001339
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001340 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1341 pr = &port->port_res[i];
1342 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001343 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001344 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001345 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001346 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 pr);
1348 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001349 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001351 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001352 goto out_free_req;
1353 }
1354 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001355 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1356 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 }
1358out:
1359 return ret;
1360
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001361
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001362out_free_req:
1363 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001364 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001365 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001367
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001368out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001369 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001372 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001373
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374}
1375
1376static void ehea_free_interrupts(struct net_device *dev)
1377{
1378 struct ehea_port *port = netdev_priv(dev);
1379 struct ehea_port_res *pr;
1380 int i;
1381
1382 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001383
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1385 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001386 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387 if (netif_msg_intr(port))
1388 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001389 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390 }
1391
1392 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001393 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 if (netif_msg_intr(port))
1395 ehea_info("associated event interrupt for handle 0x%X freed",
1396 port->qp_eq->attr.ist1);
1397}
1398
1399static int ehea_configure_port(struct ehea_port *port)
1400{
1401 int ret, i;
1402 u64 hret, mask;
1403 struct hcp_ehea_port_cb0 *cb0;
1404
1405 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001406 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407 if (!cb0)
1408 goto out;
1409
1410 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1411 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1412 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1413 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1414 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1415 PXLY_RC_VLAN_FILTER)
1416 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1417
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001418 for (i = 0; i < port->num_mcs; i++)
1419 if (use_mcs)
1420 cb0->default_qpn_arr[i] =
1421 port->port_res[i].qp->init_attr.qp_nr;
1422 else
1423 cb0->default_qpn_arr[i] =
1424 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001425
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001426 if (netif_msg_ifup(port))
1427 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1428
1429 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1430 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1431
1432 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1433 port->logical_port_id,
1434 H_PORT_CB0, mask, cb0);
1435 ret = -EIO;
1436 if (hret != H_SUCCESS)
1437 goto out_free;
1438
1439 ret = 0;
1440
1441out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001442 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443out:
1444 return ret;
1445}
1446
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001447int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001448{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001449 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001450 struct ehea_adapter *adapter = pr->port->adapter;
1451
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001452 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1453 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001454 goto out;
1455
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001456 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1457 if (ret)
1458 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001459
1460 return 0;
1461
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001462out_free:
1463 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001464out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001465 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001466 return -EIO;
1467}
1468
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001469int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001470{
Joe Perches8e95a202009-12-03 07:58:21 +00001471 if ((ehea_rem_mr(&pr->send_mr)) ||
1472 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 return -EIO;
1474 else
1475 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476}
1477
1478static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1479{
Doug Maxey508d2b52008-01-31 20:20:49 -06001480 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481
1482 q_skba->arr = vmalloc(arr_size);
1483 if (!q_skba->arr)
1484 return -ENOMEM;
1485
1486 memset(q_skba->arr, 0, arr_size);
1487
1488 q_skba->len = max_q_entries;
1489 q_skba->index = 0;
1490 q_skba->os_skbs = 0;
1491
1492 return 0;
1493}
1494
1495static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1496 struct port_res_cfg *pr_cfg, int queue_token)
1497{
1498 struct ehea_adapter *adapter = port->adapter;
1499 enum ehea_eq_type eq_type = EHEA_EQ;
1500 struct ehea_qp_init_attr *init_attr = NULL;
1501 int ret = -EIO;
1502
1503 memset(pr, 0, sizeof(struct ehea_port_res));
1504
1505 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506 spin_lock_init(&pr->xmit_lock);
1507 spin_lock_init(&pr->netif_queue);
1508
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001509 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1510 if (!pr->eq) {
1511 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001512 goto out_free;
1513 }
1514
1515 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001516 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001517 port->logical_port_id);
1518 if (!pr->recv_cq) {
1519 ehea_error("create_cq failed (cq_recv)");
1520 goto out_free;
1521 }
1522
1523 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001524 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001525 port->logical_port_id);
1526 if (!pr->send_cq) {
1527 ehea_error("create_cq failed (cq_send)");
1528 goto out_free;
1529 }
1530
1531 if (netif_msg_ifup(port))
1532 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1533 pr->send_cq->attr.act_nr_of_cqes,
1534 pr->recv_cq->attr.act_nr_of_cqes);
1535
1536 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1537 if (!init_attr) {
1538 ret = -ENOMEM;
1539 ehea_error("no mem for ehea_qp_init_attr");
1540 goto out_free;
1541 }
1542
1543 init_attr->low_lat_rq1 = 1;
1544 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1545 init_attr->rq_count = 3;
1546 init_attr->qp_token = queue_token;
1547 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1548 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1549 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1550 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1551 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1552 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1553 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1554 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1555 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1556 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1557 init_attr->port_nr = port->logical_port_id;
1558 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1559 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1560 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1561
1562 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1563 if (!pr->qp) {
1564 ehea_error("create_qp failed");
1565 ret = -EIO;
1566 goto out_free;
1567 }
1568
1569 if (netif_msg_ifup(port))
1570 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1571 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1572 init_attr->act_nr_send_wqes,
1573 init_attr->act_nr_rwqes_rq1,
1574 init_attr->act_nr_rwqes_rq2,
1575 init_attr->act_nr_rwqes_rq3);
1576
Thomas Klein44fb3122008-04-04 15:04:53 +02001577 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1578
1579 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001580 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1581 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1582 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1583 if (ret)
1584 goto out_free;
1585
1586 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1587 if (ehea_gen_smrs(pr) != 0) {
1588 ret = -EIO;
1589 goto out_free;
1590 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001592 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1593
1594 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001595
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001596 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001597
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001598 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1599 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1600 pr->lro_mgr.lro_arr = pr->lro_desc;
1601 pr->lro_mgr.get_skb_header = get_skb_hdr;
1602 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1603 pr->lro_mgr.dev = port->netdev;
1604 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1605 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1606
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001607 ret = 0;
1608 goto out;
1609
1610out_free:
1611 kfree(init_attr);
1612 vfree(pr->sq_skba.arr);
1613 vfree(pr->rq1_skba.arr);
1614 vfree(pr->rq2_skba.arr);
1615 vfree(pr->rq3_skba.arr);
1616 ehea_destroy_qp(pr->qp);
1617 ehea_destroy_cq(pr->send_cq);
1618 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001619 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001620out:
1621 return ret;
1622}
1623
1624static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1625{
1626 int ret, i;
1627
Hannes Hering357eb462009-08-04 11:48:39 -07001628 if (pr->qp)
1629 netif_napi_del(&pr->napi);
1630
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001631 ret = ehea_destroy_qp(pr->qp);
1632
1633 if (!ret) {
1634 ehea_destroy_cq(pr->send_cq);
1635 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001636 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001637
1638 for (i = 0; i < pr->rq1_skba.len; i++)
1639 if (pr->rq1_skba.arr[i])
1640 dev_kfree_skb(pr->rq1_skba.arr[i]);
1641
1642 for (i = 0; i < pr->rq2_skba.len; i++)
1643 if (pr->rq2_skba.arr[i])
1644 dev_kfree_skb(pr->rq2_skba.arr[i]);
1645
1646 for (i = 0; i < pr->rq3_skba.len; i++)
1647 if (pr->rq3_skba.arr[i])
1648 dev_kfree_skb(pr->rq3_skba.arr[i]);
1649
1650 for (i = 0; i < pr->sq_skba.len; i++)
1651 if (pr->sq_skba.arr[i])
1652 dev_kfree_skb(pr->sq_skba.arr[i]);
1653
1654 vfree(pr->rq1_skba.arr);
1655 vfree(pr->rq2_skba.arr);
1656 vfree(pr->rq3_skba.arr);
1657 vfree(pr->sq_skba.arr);
1658 ret = ehea_rem_smrs(pr);
1659 }
1660 return ret;
1661}
1662
1663/*
1664 * The write_* functions store information in swqe which is used by
1665 * the hardware to calculate the ip/tcp/udp checksum
1666 */
1667
1668static inline void write_ip_start_end(struct ehea_swqe *swqe,
1669 const struct sk_buff *skb)
1670{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001671 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001672 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001673}
1674
1675static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1676 const struct sk_buff *skb)
1677{
1678 swqe->tcp_offset =
1679 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1680
1681 swqe->tcp_end = (u16)skb->len - 1;
1682}
1683
1684static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1685 const struct sk_buff *skb)
1686{
1687 swqe->tcp_offset =
1688 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1689
1690 swqe->tcp_end = (u16)skb->len - 1;
1691}
1692
1693
1694static void write_swqe2_TSO(struct sk_buff *skb,
1695 struct ehea_swqe *swqe, u32 lkey)
1696{
1697 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1698 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001699 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001700 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001701
1702 /* Packet is TCP with TSO enabled */
1703 swqe->tx_control |= EHEA_SWQE_TSO;
1704 swqe->mss = skb_shinfo(skb)->gso_size;
1705 /* copy only eth/ip/tcp headers to immediate data and
1706 * the rest of skb->data to sg1entry
1707 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001708 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001709
Eric Dumazete743d312010-04-14 15:59:40 -07001710 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001711
1712 if (skb_data_size >= headersize) {
1713 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001714 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001715 swqe->immediate_data_length = headersize;
1716
1717 if (skb_data_size > headersize) {
1718 /* set sg1entry data */
1719 sg1entry->l_key = lkey;
1720 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001721 sg1entry->vaddr =
1722 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001723 swqe->descriptors++;
1724 }
1725 } else
1726 ehea_error("cannot handle fragmented headers");
1727}
1728
1729static void write_swqe2_nonTSO(struct sk_buff *skb,
1730 struct ehea_swqe *swqe, u32 lkey)
1731{
Eric Dumazete743d312010-04-14 15:59:40 -07001732 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001733 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1734 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735
1736 /* Packet is any nonTSO type
1737 *
1738 * Copy as much as possible skb->data to immediate data and
1739 * the rest to sg1entry
1740 */
1741 if (skb_data_size >= SWQE2_MAX_IMM) {
1742 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001743 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744
1745 swqe->immediate_data_length = SWQE2_MAX_IMM;
1746
1747 if (skb_data_size > SWQE2_MAX_IMM) {
1748 /* copy sg1entry data */
1749 sg1entry->l_key = lkey;
1750 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001751 sg1entry->vaddr =
1752 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753 swqe->descriptors++;
1754 }
1755 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001756 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757 swqe->immediate_data_length = skb_data_size;
1758 }
1759}
1760
1761static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1762 struct ehea_swqe *swqe, u32 lkey)
1763{
1764 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1765 skb_frag_t *frag;
1766 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001767
1768 nfrags = skb_shinfo(skb)->nr_frags;
1769 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001770 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001771 swqe->descriptors = 0;
1772 sg1entry_contains_frag_data = 0;
1773
1774 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1775 write_swqe2_TSO(skb, swqe, lkey);
1776 else
1777 write_swqe2_nonTSO(skb, swqe, lkey);
1778
1779 /* write descriptors */
1780 if (nfrags > 0) {
1781 if (swqe->descriptors == 0) {
1782 /* sg1entry not yet used */
1783 frag = &skb_shinfo(skb)->frags[0];
1784
1785 /* copy sg1entry data */
1786 sg1entry->l_key = lkey;
1787 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001788 sg1entry->vaddr =
1789 ehea_map_vaddr(page_address(frag->page)
1790 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001791 swqe->descriptors++;
1792 sg1entry_contains_frag_data = 1;
1793 }
1794
1795 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1796
1797 frag = &skb_shinfo(skb)->frags[i];
1798 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1799
1800 sgentry->l_key = lkey;
1801 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001802 sgentry->vaddr =
1803 ehea_map_vaddr(page_address(frag->page)
1804 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001805 swqe->descriptors++;
1806 }
1807 }
1808}
1809
1810static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1811{
1812 int ret = 0;
1813 u64 hret;
1814 u8 reg_type;
1815
1816 /* De/Register untagged packets */
1817 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1818 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1819 port->logical_port_id,
1820 reg_type, port->mac_addr, 0, hcallid);
1821 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001822 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001823 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001824 ret = -EIO;
1825 goto out_herr;
1826 }
1827
1828 /* De/Register VLAN packets */
1829 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1830 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1831 port->logical_port_id,
1832 reg_type, port->mac_addr, 0, hcallid);
1833 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001834 ehea_error("%sregistering bc address failed (vlan)",
1835 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001836 ret = -EIO;
1837 }
1838out_herr:
1839 return ret;
1840}
1841
1842static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1843{
1844 struct ehea_port *port = netdev_priv(dev);
1845 struct sockaddr *mac_addr = sa;
1846 struct hcp_ehea_port_cb0 *cb0;
1847 int ret;
1848 u64 hret;
1849
1850 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1851 ret = -EADDRNOTAVAIL;
1852 goto out;
1853 }
1854
Thomas Klein3faf2692009-01-21 14:45:33 -08001855 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001856 if (!cb0) {
1857 ehea_error("no mem for cb0");
1858 ret = -ENOMEM;
1859 goto out;
1860 }
1861
1862 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1863
1864 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1865
1866 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1867 port->logical_port_id, H_PORT_CB0,
1868 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1869 if (hret != H_SUCCESS) {
1870 ret = -EIO;
1871 goto out_free;
1872 }
1873
1874 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1875
1876 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001877 if (port->state == EHEA_PORT_UP) {
1878 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1879 if (ret)
1880 goto out_upregs;
1881 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001882
1883 port->mac_addr = cb0->port_mac_addr << 16;
1884
1885 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001886 if (port->state == EHEA_PORT_UP) {
1887 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1888 if (ret)
1889 goto out_upregs;
1890 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001891
1892 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001893
1894out_upregs:
1895 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001896out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001897 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001898out:
1899 return ret;
1900}
1901
1902static void ehea_promiscuous_error(u64 hret, int enable)
1903{
Thomas Klein7674a582007-01-22 12:54:20 +01001904 if (hret == H_AUTHORITY)
1905 ehea_info("Hypervisor denied %sabling promiscuous mode",
1906 enable == 1 ? "en" : "dis");
1907 else
1908 ehea_error("failed %sabling promiscuous mode",
1909 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001910}
1911
1912static void ehea_promiscuous(struct net_device *dev, int enable)
1913{
1914 struct ehea_port *port = netdev_priv(dev);
1915 struct hcp_ehea_port_cb7 *cb7;
1916 u64 hret;
1917
1918 if ((enable && port->promisc) || (!enable && !port->promisc))
1919 return;
1920
Thomas Klein3faf2692009-01-21 14:45:33 -08001921 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001922 if (!cb7) {
1923 ehea_error("no mem for cb7");
1924 goto out;
1925 }
1926
1927 /* Modify Pxs_DUCQPN in CB7 */
1928 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1929
1930 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1931 port->logical_port_id,
1932 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1933 if (hret) {
1934 ehea_promiscuous_error(hret, enable);
1935 goto out;
1936 }
1937
1938 port->promisc = enable;
1939out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001940 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001941}
1942
1943static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1944 u32 hcallid)
1945{
1946 u64 hret;
1947 u8 reg_type;
1948
1949 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1950 | EHEA_BCMC_UNTAGGED;
1951
1952 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1953 port->logical_port_id,
1954 reg_type, mc_mac_addr, 0, hcallid);
1955 if (hret)
1956 goto out;
1957
1958 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1959 | EHEA_BCMC_VLANID_ALL;
1960
1961 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1962 port->logical_port_id,
1963 reg_type, mc_mac_addr, 0, hcallid);
1964out:
1965 return hret;
1966}
1967
1968static int ehea_drop_multicast_list(struct net_device *dev)
1969{
1970 struct ehea_port *port = netdev_priv(dev);
1971 struct ehea_mc_list *mc_entry = port->mc_list;
1972 struct list_head *pos;
1973 struct list_head *temp;
1974 int ret = 0;
1975 u64 hret;
1976
1977 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1978 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1979
1980 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1981 H_DEREG_BCMC);
1982 if (hret) {
1983 ehea_error("failed deregistering mcast MAC");
1984 ret = -EIO;
1985 }
1986
1987 list_del(pos);
1988 kfree(mc_entry);
1989 }
1990 return ret;
1991}
1992
1993static void ehea_allmulti(struct net_device *dev, int enable)
1994{
1995 struct ehea_port *port = netdev_priv(dev);
1996 u64 hret;
1997
1998 if (!port->allmulti) {
1999 if (enable) {
2000 /* Enable ALLMULTI */
2001 ehea_drop_multicast_list(dev);
2002 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2003 if (!hret)
2004 port->allmulti = 1;
2005 else
2006 ehea_error("failed enabling IFF_ALLMULTI");
2007 }
2008 } else
2009 if (!enable) {
2010 /* Disable ALLMULTI */
2011 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2012 if (!hret)
2013 port->allmulti = 0;
2014 else
2015 ehea_error("failed disabling IFF_ALLMULTI");
2016 }
2017}
2018
Doug Maxey508d2b52008-01-31 20:20:49 -06002019static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002020{
2021 struct ehea_mc_list *ehea_mcl_entry;
2022 u64 hret;
2023
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002024 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002025 if (!ehea_mcl_entry) {
2026 ehea_error("no mem for mcl_entry");
2027 return;
2028 }
2029
2030 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2031
2032 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2033
2034 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2035 H_REG_BCMC);
2036 if (!hret)
2037 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2038 else {
2039 ehea_error("failed registering mcast MAC");
2040 kfree(ehea_mcl_entry);
2041 }
2042}
2043
2044static void ehea_set_multicast_list(struct net_device *dev)
2045{
2046 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002047 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002048 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049
2050 if (dev->flags & IFF_PROMISC) {
2051 ehea_promiscuous(dev, 1);
2052 return;
2053 }
2054 ehea_promiscuous(dev, 0);
2055
2056 if (dev->flags & IFF_ALLMULTI) {
2057 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002058 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002059 }
2060 ehea_allmulti(dev, 0);
2061
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002062 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 ret = ehea_drop_multicast_list(dev);
2064 if (ret) {
2065 /* Dropping the current multicast list failed.
2066 * Enabling ALL_MULTI is the best we can do.
2067 */
2068 ehea_allmulti(dev, 1);
2069 }
2070
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002071 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00002072 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002073 "Use ALLMULTI!",
2074 port->adapter->max_mc_mac);
2075 goto out;
2076 }
2077
Jiri Pirko22bedad32010-04-01 21:22:57 +00002078 netdev_for_each_mc_addr(ha, dev)
2079 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002080
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002081 }
2082out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002083 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084}
2085
2086static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2087{
2088 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2089 return -EINVAL;
2090 dev->mtu = new_mtu;
2091 return 0;
2092}
2093
2094static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2095 struct ehea_swqe *swqe, u32 lkey)
2096{
2097 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002098 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002099
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002100 /* IPv4 */
2101 swqe->tx_control |= EHEA_SWQE_CRC
2102 | EHEA_SWQE_IP_CHECKSUM
2103 | EHEA_SWQE_TCP_CHECKSUM
2104 | EHEA_SWQE_IMM_DATA_PRESENT
2105 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2106
2107 write_ip_start_end(swqe, skb);
2108
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002109 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002110 if ((iph->frag_off & IP_MF) ||
2111 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112 /* IP fragment, so don't change cs */
2113 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2114 else
2115 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002116 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117 write_tcp_offset_end(swqe, skb);
2118 }
2119
2120 /* icmp (big data) and ip segmentation packets (all other ip
2121 packets) do not require any special handling */
2122
2123 } else {
2124 /* Other Ethernet Protocol */
2125 swqe->tx_control |= EHEA_SWQE_CRC
2126 | EHEA_SWQE_IMM_DATA_PRESENT
2127 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2128 }
2129
2130 write_swqe2_data(skb, dev, swqe, lkey);
2131}
2132
2133static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2134 struct ehea_swqe *swqe)
2135{
2136 int nfrags = skb_shinfo(skb)->nr_frags;
2137 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2138 skb_frag_t *frag;
2139 int i;
2140
2141 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002142 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002143
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002144 /* IPv4 */
2145 write_ip_start_end(swqe, skb);
2146
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002147 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002148 swqe->tx_control |= EHEA_SWQE_CRC
2149 | EHEA_SWQE_IP_CHECKSUM
2150 | EHEA_SWQE_TCP_CHECKSUM
2151 | EHEA_SWQE_IMM_DATA_PRESENT;
2152
2153 write_tcp_offset_end(swqe, skb);
2154
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002155 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002156 if ((iph->frag_off & IP_MF) ||
2157 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158 /* IP fragment, so don't change cs */
2159 swqe->tx_control |= EHEA_SWQE_CRC
2160 | EHEA_SWQE_IMM_DATA_PRESENT;
2161 else {
2162 swqe->tx_control |= EHEA_SWQE_CRC
2163 | EHEA_SWQE_IP_CHECKSUM
2164 | EHEA_SWQE_TCP_CHECKSUM
2165 | EHEA_SWQE_IMM_DATA_PRESENT;
2166
2167 write_udp_offset_end(swqe, skb);
2168 }
2169 } else {
2170 /* icmp (big data) and
2171 ip segmentation packets (all other ip packets) */
2172 swqe->tx_control |= EHEA_SWQE_CRC
2173 | EHEA_SWQE_IP_CHECKSUM
2174 | EHEA_SWQE_IMM_DATA_PRESENT;
2175 }
2176 } else {
2177 /* Other Ethernet Protocol */
2178 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2179 }
2180 /* copy (immediate) data */
2181 if (nfrags == 0) {
2182 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002183 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 } else {
2185 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002186 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002187 skb_headlen(skb));
2188 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189
2190 /* ... then copy data from the fragments */
2191 for (i = 0; i < nfrags; i++) {
2192 frag = &skb_shinfo(skb)->frags[i];
2193 memcpy(imm_data,
2194 page_address(frag->page) + frag->page_offset,
2195 frag->size);
2196 imm_data += frag->size;
2197 }
2198 }
2199 swqe->immediate_data_length = skb->len;
2200 dev_kfree_skb(skb);
2201}
2202
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002203static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2204{
2205 struct tcphdr *tcp;
2206 u32 tmp;
2207
2208 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002209 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002210 tcp = (struct tcphdr *)(skb_network_header(skb) +
2211 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002212 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002213 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002214 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002215 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002216 return 0;
2217}
2218
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2220{
2221 struct ehea_port *port = netdev_priv(dev);
2222 struct ehea_swqe *swqe;
2223 unsigned long flags;
2224 u32 lkey;
2225 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002226 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002228 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2229
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002230 if (!spin_trylock(&pr->xmit_lock))
2231 return NETDEV_TX_BUSY;
2232
2233 if (pr->queue_stopped) {
2234 spin_unlock(&pr->xmit_lock);
2235 return NETDEV_TX_BUSY;
2236 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002237
2238 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2239 memset(swqe, 0, SWQE_HEADER_SIZE);
2240 atomic_dec(&pr->swqe_avail);
2241
2242 if (skb->len <= SWQE3_MAX_IMM) {
2243 u32 sig_iv = port->sig_comp_iv;
2244 u32 swqe_num = pr->swqe_id_counter;
2245 ehea_xmit3(skb, dev, swqe);
2246 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2247 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2248 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2249 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2250 sig_iv);
2251 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2252 pr->swqe_ll_count = 0;
2253 } else
2254 pr->swqe_ll_count += 1;
2255 } else {
2256 swqe->wr_id =
2257 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2258 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002259 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002260 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2261 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2262
2263 pr->sq_skba.index++;
2264 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2265
2266 lkey = pr->send_mr.lkey;
2267 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002268 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002269 }
2270 pr->swqe_id_counter += 1;
2271
2272 if (port->vgrp && vlan_tx_tag_present(skb)) {
2273 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2274 swqe->vlan_tag = vlan_tx_tag_get(skb);
2275 }
2276
2277 if (netif_msg_tx_queued(port)) {
2278 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002279 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002280 }
2281
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002282 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2283 netif_stop_queue(dev);
2284 swqe->tx_control |= EHEA_SWQE_PURGE;
2285 }
Thomas Klein44c82152007-07-11 16:32:00 +02002286
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002287 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002288 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002289
2290 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2291 spin_lock_irqsave(&pr->netif_queue, flags);
2292 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002293 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002294 netif_stop_queue(dev);
2295 pr->queue_stopped = 1;
2296 }
2297 spin_unlock_irqrestore(&pr->netif_queue, flags);
2298 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002299 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002300 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002301
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002302 return NETDEV_TX_OK;
2303}
2304
2305static void ehea_vlan_rx_register(struct net_device *dev,
2306 struct vlan_group *grp)
2307{
2308 struct ehea_port *port = netdev_priv(dev);
2309 struct ehea_adapter *adapter = port->adapter;
2310 struct hcp_ehea_port_cb1 *cb1;
2311 u64 hret;
2312
2313 port->vgrp = grp;
2314
Thomas Klein3faf2692009-01-21 14:45:33 -08002315 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002316 if (!cb1) {
2317 ehea_error("no mem for cb1");
2318 goto out;
2319 }
2320
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002321 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2322 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2323 if (hret != H_SUCCESS)
2324 ehea_error("modify_ehea_port failed");
2325
Thomas Klein3faf2692009-01-21 14:45:33 -08002326 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002327out:
2328 return;
2329}
2330
2331static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2332{
2333 struct ehea_port *port = netdev_priv(dev);
2334 struct ehea_adapter *adapter = port->adapter;
2335 struct hcp_ehea_port_cb1 *cb1;
2336 int index;
2337 u64 hret;
2338
Thomas Klein3faf2692009-01-21 14:45:33 -08002339 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002340 if (!cb1) {
2341 ehea_error("no mem for cb1");
2342 goto out;
2343 }
2344
2345 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2346 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2347 if (hret != H_SUCCESS) {
2348 ehea_error("query_ehea_port failed");
2349 goto out;
2350 }
2351
2352 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002353 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354
2355 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2356 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2357 if (hret != H_SUCCESS)
2358 ehea_error("modify_ehea_port failed");
2359out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002360 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361 return;
2362}
2363
2364static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2365{
2366 struct ehea_port *port = netdev_priv(dev);
2367 struct ehea_adapter *adapter = port->adapter;
2368 struct hcp_ehea_port_cb1 *cb1;
2369 int index;
2370 u64 hret;
2371
Dan Aloni5c15bde2007-03-02 20:44:51 -08002372 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002373
Thomas Klein3faf2692009-01-21 14:45:33 -08002374 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 if (!cb1) {
2376 ehea_error("no mem for cb1");
2377 goto out;
2378 }
2379
2380 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2381 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2382 if (hret != H_SUCCESS) {
2383 ehea_error("query_ehea_port failed");
2384 goto out;
2385 }
2386
2387 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002388 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002389
2390 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2391 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2392 if (hret != H_SUCCESS)
2393 ehea_error("modify_ehea_port failed");
2394out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002395 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002396}
2397
2398int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2399{
2400 int ret = -EIO;
2401 u64 hret;
2402 u16 dummy16 = 0;
2403 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002404 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002405
Thomas Klein3faf2692009-01-21 14:45:33 -08002406 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002407 if (!cb0) {
2408 ret = -ENOMEM;
2409 goto out;
2410 }
2411
2412 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2413 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2414 if (hret != H_SUCCESS) {
2415 ehea_error("query_ehea_qp failed (1)");
2416 goto out;
2417 }
2418
2419 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2420 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2421 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2422 &dummy64, &dummy64, &dummy16, &dummy16);
2423 if (hret != H_SUCCESS) {
2424 ehea_error("modify_ehea_qp failed (1)");
2425 goto out;
2426 }
2427
2428 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2429 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2430 if (hret != H_SUCCESS) {
2431 ehea_error("query_ehea_qp failed (2)");
2432 goto out;
2433 }
2434
2435 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2436 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2437 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2438 &dummy64, &dummy64, &dummy16, &dummy16);
2439 if (hret != H_SUCCESS) {
2440 ehea_error("modify_ehea_qp failed (2)");
2441 goto out;
2442 }
2443
2444 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2445 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2446 if (hret != H_SUCCESS) {
2447 ehea_error("query_ehea_qp failed (3)");
2448 goto out;
2449 }
2450
2451 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2452 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2453 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2454 &dummy64, &dummy64, &dummy16, &dummy16);
2455 if (hret != H_SUCCESS) {
2456 ehea_error("modify_ehea_qp failed (3)");
2457 goto out;
2458 }
2459
2460 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2461 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2462 if (hret != H_SUCCESS) {
2463 ehea_error("query_ehea_qp failed (4)");
2464 goto out;
2465 }
2466
2467 ret = 0;
2468out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002469 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 return ret;
2471}
2472
2473static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2474 int add_tx_qps)
2475{
2476 int ret, i;
2477 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2478 enum ehea_eq_type eq_type = EHEA_EQ;
2479
2480 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2481 EHEA_MAX_ENTRIES_EQ, 1);
2482 if (!port->qp_eq) {
2483 ret = -EINVAL;
2484 ehea_error("ehea_create_eq failed (qp_eq)");
2485 goto out_kill_eq;
2486 }
2487
2488 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002489 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002490 pr_cfg.max_entries_sq = sq_entries;
2491 pr_cfg.max_entries_rq1 = rq1_entries;
2492 pr_cfg.max_entries_rq2 = rq2_entries;
2493 pr_cfg.max_entries_rq3 = rq3_entries;
2494
2495 pr_cfg_small_rx.max_entries_rcq = 1;
2496 pr_cfg_small_rx.max_entries_scq = sq_entries;
2497 pr_cfg_small_rx.max_entries_sq = sq_entries;
2498 pr_cfg_small_rx.max_entries_rq1 = 1;
2499 pr_cfg_small_rx.max_entries_rq2 = 1;
2500 pr_cfg_small_rx.max_entries_rq3 = 1;
2501
2502 for (i = 0; i < def_qps; i++) {
2503 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2504 if (ret)
2505 goto out_clean_pr;
2506 }
2507 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2508 ret = ehea_init_port_res(port, &port->port_res[i],
2509 &pr_cfg_small_rx, i);
2510 if (ret)
2511 goto out_clean_pr;
2512 }
2513
2514 return 0;
2515
2516out_clean_pr:
2517 while (--i >= 0)
2518 ehea_clean_portres(port, &port->port_res[i]);
2519
2520out_kill_eq:
2521 ehea_destroy_eq(port->qp_eq);
2522 return ret;
2523}
2524
2525static int ehea_clean_all_portres(struct ehea_port *port)
2526{
2527 int ret = 0;
2528 int i;
2529
Doug Maxey508d2b52008-01-31 20:20:49 -06002530 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002531 ret |= ehea_clean_portres(port, &port->port_res[i]);
2532
2533 ret |= ehea_destroy_eq(port->qp_eq);
2534
2535 return ret;
2536}
2537
Thomas Klein35cf2e22007-08-06 13:55:14 +02002538static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002539{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002540 if (adapter->active_ports)
2541 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002542
2543 ehea_rem_mr(&adapter->mr);
2544}
2545
Thomas Klein35cf2e22007-08-06 13:55:14 +02002546static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002547{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002548 if (adapter->active_ports)
2549 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002550
2551 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2552}
2553
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002554static int ehea_up(struct net_device *dev)
2555{
2556 int ret, i;
2557 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558
2559 if (port->state == EHEA_PORT_UP)
2560 return 0;
2561
2562 ret = ehea_port_res_setup(port, port->num_def_qps,
2563 port->num_add_tx_qps);
2564 if (ret) {
2565 ehea_error("port_res_failed");
2566 goto out;
2567 }
2568
2569 /* Set default QP for this port */
2570 ret = ehea_configure_port(port);
2571 if (ret) {
2572 ehea_error("ehea_configure_port failed. ret:%d", ret);
2573 goto out_clean_pr;
2574 }
2575
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002576 ret = ehea_reg_interrupts(dev);
2577 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002578 ehea_error("reg_interrupts failed. ret:%d", ret);
2579 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580 }
2581
Doug Maxey508d2b52008-01-31 20:20:49 -06002582 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002583 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2584 if (ret) {
2585 ehea_error("activate_qp failed");
2586 goto out_free_irqs;
2587 }
2588 }
2589
Doug Maxey508d2b52008-01-31 20:20:49 -06002590 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591 ret = ehea_fill_port_res(&port->port_res[i]);
2592 if (ret) {
2593 ehea_error("out_free_irqs");
2594 goto out_free_irqs;
2595 }
2596 }
2597
Thomas Klein21eee2d2008-02-13 16:18:33 +01002598 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2599 if (ret) {
2600 ret = -EIO;
2601 goto out_free_irqs;
2602 }
2603
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002605
2606 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002607 goto out;
2608
2609out_free_irqs:
2610 ehea_free_interrupts(dev);
2611
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612out_clean_pr:
2613 ehea_clean_all_portres(port);
2614out:
Thomas Klein44c82152007-07-11 16:32:00 +02002615 if (ret)
2616 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2617
Thomas Klein21eee2d2008-02-13 16:18:33 +01002618 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002619 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002620
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002621 return ret;
2622}
2623
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002624static void port_napi_disable(struct ehea_port *port)
2625{
2626 int i;
2627
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002628 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002629 napi_disable(&port->port_res[i].napi);
2630}
2631
2632static void port_napi_enable(struct ehea_port *port)
2633{
2634 int i;
2635
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002636 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002637 napi_enable(&port->port_res[i].napi);
2638}
2639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002640static int ehea_open(struct net_device *dev)
2641{
2642 int ret;
2643 struct ehea_port *port = netdev_priv(dev);
2644
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002645 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002646
2647 if (netif_msg_ifup(port))
2648 ehea_info("enabling port %s", dev->name);
2649
2650 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002651 if (!ret) {
2652 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002653 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002654 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002655
Breno Leitao5b27d422010-10-05 13:16:22 +00002656 init_waitqueue_head(&port->swqe_avail_wq);
2657
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002658 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002659
2660 return ret;
2661}
2662
2663static int ehea_down(struct net_device *dev)
2664{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002665 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002666 struct ehea_port *port = netdev_priv(dev);
2667
2668 if (port->state == EHEA_PORT_DOWN)
2669 return 0;
2670
2671 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002672 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2673
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002674 ehea_free_interrupts(dev);
2675
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002676 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002677
Thomas Klein21eee2d2008-02-13 16:18:33 +01002678 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002679
Thomas Klein44c82152007-07-11 16:32:00 +02002680 ret = ehea_clean_all_portres(port);
2681 if (ret)
2682 ehea_info("Failed freeing resources for %s. ret=%i",
2683 dev->name, ret);
2684
Thomas Klein21eee2d2008-02-13 16:18:33 +01002685 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002686
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002687 return ret;
2688}
2689
2690static int ehea_stop(struct net_device *dev)
2691{
2692 int ret;
2693 struct ehea_port *port = netdev_priv(dev);
2694
2695 if (netif_msg_ifdown(port))
2696 ehea_info("disabling port %s", dev->name);
2697
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002698 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002699 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002700 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002701 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002702 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002703 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002704 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002705 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002706 return ret;
2707}
2708
Andrew Morton22559c52008-04-18 13:50:39 -07002709static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002710{
2711 struct ehea_qp qp = *orig_qp;
2712 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2713 struct ehea_swqe *swqe;
2714 int wqe_index;
2715 int i;
2716
2717 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2718 swqe = ehea_get_swqe(&qp, &wqe_index);
2719 swqe->tx_control |= EHEA_SWQE_PURGE;
2720 }
2721}
2722
Andrew Morton22559c52008-04-18 13:50:39 -07002723static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002724{
2725 int i;
2726
2727 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2728 struct ehea_port_res *pr = &port->port_res[i];
2729 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002730 int ret;
2731
2732 ret = wait_event_timeout(port->swqe_avail_wq,
2733 atomic_read(&pr->swqe_avail) >= swqe_max,
2734 msecs_to_jiffies(100));
2735
2736 if (!ret) {
2737 ehea_error("WARNING: sq not flushed completely");
2738 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002739 }
2740 }
2741}
2742
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002743int ehea_stop_qps(struct net_device *dev)
2744{
2745 struct ehea_port *port = netdev_priv(dev);
2746 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002747 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002748 int ret = -EIO;
2749 int dret;
2750 int i;
2751 u64 hret;
2752 u64 dummy64 = 0;
2753 u16 dummy16 = 0;
2754
Thomas Klein3faf2692009-01-21 14:45:33 -08002755 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002756 if (!cb0) {
2757 ret = -ENOMEM;
2758 goto out;
2759 }
2760
2761 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2762 struct ehea_port_res *pr = &port->port_res[i];
2763 struct ehea_qp *qp = pr->qp;
2764
2765 /* Purge send queue */
2766 ehea_purge_sq(qp);
2767
2768 /* Disable queue pair */
2769 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2770 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2771 cb0);
2772 if (hret != H_SUCCESS) {
2773 ehea_error("query_ehea_qp failed (1)");
2774 goto out;
2775 }
2776
2777 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2778 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2779
2780 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2781 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2782 1), cb0, &dummy64,
2783 &dummy64, &dummy16, &dummy16);
2784 if (hret != H_SUCCESS) {
2785 ehea_error("modify_ehea_qp failed (1)");
2786 goto out;
2787 }
2788
2789 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2790 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2791 cb0);
2792 if (hret != H_SUCCESS) {
2793 ehea_error("query_ehea_qp failed (2)");
2794 goto out;
2795 }
2796
2797 /* deregister shared memory regions */
2798 dret = ehea_rem_smrs(pr);
2799 if (dret) {
2800 ehea_error("unreg shared memory region failed");
2801 goto out;
2802 }
2803 }
2804
2805 ret = 0;
2806out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002807 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002808
2809 return ret;
2810}
2811
Doug Maxey508d2b52008-01-31 20:20:49 -06002812void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002813{
2814 struct ehea_qp qp = *orig_qp;
2815 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2816 struct ehea_rwqe *rwqe;
2817 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2818 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2819 struct sk_buff *skb;
2820 u32 lkey = pr->recv_mr.lkey;
2821
2822
2823 int i;
2824 int index;
2825
2826 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2827 rwqe = ehea_get_next_rwqe(&qp, 2);
2828 rwqe->sg_list[0].l_key = lkey;
2829 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2830 skb = skba_rq2[index];
2831 if (skb)
2832 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2833 }
2834
2835 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2836 rwqe = ehea_get_next_rwqe(&qp, 3);
2837 rwqe->sg_list[0].l_key = lkey;
2838 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2839 skb = skba_rq3[index];
2840 if (skb)
2841 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2842 }
2843}
2844
2845int ehea_restart_qps(struct net_device *dev)
2846{
2847 struct ehea_port *port = netdev_priv(dev);
2848 struct ehea_adapter *adapter = port->adapter;
2849 int ret = 0;
2850 int i;
2851
Doug Maxey508d2b52008-01-31 20:20:49 -06002852 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002853 u64 hret;
2854 u64 dummy64 = 0;
2855 u16 dummy16 = 0;
2856
Thomas Klein3faf2692009-01-21 14:45:33 -08002857 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002858 if (!cb0) {
2859 ret = -ENOMEM;
2860 goto out;
2861 }
2862
2863 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2864 struct ehea_port_res *pr = &port->port_res[i];
2865 struct ehea_qp *qp = pr->qp;
2866
2867 ret = ehea_gen_smrs(pr);
2868 if (ret) {
2869 ehea_error("creation of shared memory regions failed");
2870 goto out;
2871 }
2872
2873 ehea_update_rqs(qp, pr);
2874
2875 /* Enable queue pair */
2876 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2877 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2878 cb0);
2879 if (hret != H_SUCCESS) {
2880 ehea_error("query_ehea_qp failed (1)");
2881 goto out;
2882 }
2883
2884 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2885 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2886
2887 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2888 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2889 1), cb0, &dummy64,
2890 &dummy64, &dummy16, &dummy16);
2891 if (hret != H_SUCCESS) {
2892 ehea_error("modify_ehea_qp failed (1)");
2893 goto out;
2894 }
2895
2896 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2897 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2898 cb0);
2899 if (hret != H_SUCCESS) {
2900 ehea_error("query_ehea_qp failed (2)");
2901 goto out;
2902 }
2903
2904 /* refill entire queue */
2905 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2906 ehea_refill_rq2(pr, 0);
2907 ehea_refill_rq3(pr, 0);
2908 }
2909out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002910 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002911
2912 return ret;
2913}
2914
David Howellsc4028952006-11-22 14:57:56 +00002915static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002916{
2917 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002918 struct ehea_port *port =
2919 container_of(work, struct ehea_port, reset_task);
2920 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002921
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002922 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002923 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002924 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002925 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002926
2927 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002928
Thomas Klein44c82152007-07-11 16:32:00 +02002929 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002930
2931 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002932 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002933 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002934
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002935 ehea_set_multicast_list(dev);
2936
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002937 if (netif_msg_timer(port))
2938 ehea_info("Device %s resetted successfully", dev->name);
2939
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002940 port_napi_enable(port);
2941
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002942 netif_wake_queue(dev);
2943out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002944 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002945 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002946}
2947
Thomas Klein44c82152007-07-11 16:32:00 +02002948static void ehea_rereg_mrs(struct work_struct *work)
2949{
2950 int ret, i;
2951 struct ehea_adapter *adapter;
2952
Hannes Heringd4f12da2008-10-16 11:36:42 +02002953 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002954
2955 list_for_each_entry(adapter, &adapter_list, list)
2956 if (adapter->active_ports) {
2957 /* Shutdown all ports */
2958 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2959 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002960 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002961
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002962 if (!port)
2963 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002964
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002965 dev = port->netdev;
2966
2967 if (dev->flags & IFF_UP) {
2968 mutex_lock(&port->port_lock);
2969 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002970 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002971 ret = ehea_stop_qps(dev);
2972 if (ret) {
2973 mutex_unlock(&port->port_lock);
2974 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002975 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002976 port_napi_disable(port);
2977 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002978 }
Andre Detsch2928db42010-08-17 05:49:12 +00002979 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002980 }
2981
2982 /* Unregister old memory region */
2983 ret = ehea_rem_mr(&adapter->mr);
2984 if (ret) {
2985 ehea_error("unregister MR failed - driver"
2986 " inoperable!");
2987 goto out;
2988 }
2989 }
2990
Thomas Klein44c82152007-07-11 16:32:00 +02002991 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2992
2993 list_for_each_entry(adapter, &adapter_list, list)
2994 if (adapter->active_ports) {
2995 /* Register new memory region */
2996 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2997 if (ret) {
2998 ehea_error("register MR failed - driver"
2999 " inoperable!");
3000 goto out;
3001 }
3002
3003 /* Restart all ports */
3004 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3005 struct ehea_port *port = adapter->port[i];
3006
3007 if (port) {
3008 struct net_device *dev = port->netdev;
3009
3010 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003011 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003012 port_napi_enable(port);
3013 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003014 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003015 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003016 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003017 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003018 }
3019 }
3020 }
3021 }
Julia Lawall68905eb2008-07-21 09:57:26 +02003022 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003023out:
3024 return;
3025}
3026
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003027static void ehea_tx_watchdog(struct net_device *dev)
3028{
3029 struct ehea_port *port = netdev_priv(dev);
3030
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003031 if (netif_carrier_ok(dev) &&
3032 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003033 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003034}
3035
3036int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3037{
3038 struct hcp_query_ehea *cb;
3039 u64 hret;
3040 int ret;
3041
Thomas Klein3faf2692009-01-21 14:45:33 -08003042 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003043 if (!cb) {
3044 ret = -ENOMEM;
3045 goto out;
3046 }
3047
3048 hret = ehea_h_query_ehea(adapter->handle, cb);
3049
3050 if (hret != H_SUCCESS) {
3051 ret = -EIO;
3052 goto out_herr;
3053 }
3054
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003055 adapter->max_mc_mac = cb->max_mc_mac - 1;
3056 ret = 0;
3057
3058out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003059 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003060out:
3061 return ret;
3062}
3063
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3065{
3066 struct hcp_ehea_port_cb4 *cb4;
3067 u64 hret;
3068 int ret = 0;
3069
3070 *jumbo = 0;
3071
3072 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003073 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003074 if (!cb4) {
3075 ehea_error("no mem for cb4");
3076 ret = -ENOMEM;
3077 goto out;
3078 } else {
3079 hret = ehea_h_query_ehea_port(port->adapter->handle,
3080 port->logical_port_id,
3081 H_PORT_CB4,
3082 H_PORT_CB4_JUMBO, cb4);
3083 if (hret == H_SUCCESS) {
3084 if (cb4->jumbo_frame)
3085 *jumbo = 1;
3086 else {
3087 cb4->jumbo_frame = 1;
3088 hret = ehea_h_modify_ehea_port(port->adapter->
3089 handle,
3090 port->
3091 logical_port_id,
3092 H_PORT_CB4,
3093 H_PORT_CB4_JUMBO,
3094 cb4);
3095 if (hret == H_SUCCESS)
3096 *jumbo = 1;
3097 }
3098 } else
3099 ret = -EINVAL;
3100
Thomas Klein3faf2692009-01-21 14:45:33 -08003101 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102 }
3103out:
3104 return ret;
3105}
3106
3107static ssize_t ehea_show_port_id(struct device *dev,
3108 struct device_attribute *attr, char *buf)
3109{
3110 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003111 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112}
3113
3114static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3115 NULL);
3116
3117static void __devinit logical_port_release(struct device *dev)
3118{
3119 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003120 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003121}
3122
3123static struct device *ehea_register_port(struct ehea_port *port,
3124 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003125{
3126 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003127
Grant Likely61c7a082010-04-13 16:12:29 -07003128 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003129 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003130 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003132 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003133 port->ofdev.dev.release = logical_port_release;
3134
3135 ret = of_device_register(&port->ofdev);
3136 if (ret) {
3137 ehea_error("failed to register device. ret=%d", ret);
3138 goto out;
3139 }
3140
3141 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003142 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143 ehea_error("failed to register attributes, ret=%d", ret);
3144 goto out_unreg_of_dev;
3145 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003146
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003147 return &port->ofdev.dev;
3148
3149out_unreg_of_dev:
3150 of_device_unregister(&port->ofdev);
3151out:
3152 return NULL;
3153}
3154
3155static void ehea_unregister_port(struct ehea_port *port)
3156{
3157 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3158 of_device_unregister(&port->ofdev);
3159}
3160
Thomas Klein086c1b22009-01-21 14:43:59 -08003161static const struct net_device_ops ehea_netdev_ops = {
3162 .ndo_open = ehea_open,
3163 .ndo_stop = ehea_stop,
3164 .ndo_start_xmit = ehea_start_xmit,
3165#ifdef CONFIG_NET_POLL_CONTROLLER
3166 .ndo_poll_controller = ehea_netpoll,
3167#endif
3168 .ndo_get_stats = ehea_get_stats,
3169 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003170 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003171 .ndo_set_multicast_list = ehea_set_multicast_list,
3172 .ndo_change_mtu = ehea_change_mtu,
3173 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3174 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003175 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3176 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003177};
3178
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003179struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3180 u32 logical_port_id,
3181 struct device_node *dn)
3182{
3183 int ret;
3184 struct net_device *dev;
3185 struct ehea_port *port;
3186 struct device *port_dev;
3187 int jumbo;
3188
3189 /* allocate memory for the port structures */
3190 dev = alloc_etherdev(sizeof(struct ehea_port));
3191
3192 if (!dev) {
3193 ehea_error("no mem for net_device");
3194 ret = -ENOMEM;
3195 goto out_err;
3196 }
3197
3198 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003199
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003200 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003201 port->state = EHEA_PORT_DOWN;
3202 port->sig_comp_iv = sq_entries / 10;
3203
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003204 port->adapter = adapter;
3205 port->netdev = dev;
3206 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003207
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003208 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003209
3210 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3211 if (!port->mc_list) {
3212 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003214 }
3215
3216 INIT_LIST_HEAD(&port->mc_list->list);
3217
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003218 ret = ehea_sense_port_attr(port);
3219 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003220 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003221
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003222 port_dev = ehea_register_port(port, dn);
3223 if (!port_dev)
3224 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003225
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003227
3228 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003229 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3230
Thomas Klein086c1b22009-01-21 14:43:59 -08003231 dev->netdev_ops = &ehea_netdev_ops;
3232 ehea_set_ethtool_ops(dev);
3233
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003234 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003235 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003236 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3237 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3239
David Howellsc4028952006-11-22 14:57:56 +00003240 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003241
3242 ret = register_netdev(dev);
3243 if (ret) {
3244 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003245 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003246 }
3247
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003248 port->lro_max_aggr = lro_max_aggr;
3249
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003250 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003251 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252 ehea_error("failed determining jumbo frame status for %s",
3253 port->netdev->name);
3254
Thomas Klein9c750b72007-01-29 18:44:01 +01003255 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3256 jumbo == 1 ? "en" : "dis");
3257
Thomas Klein44c82152007-07-11 16:32:00 +02003258 adapter->active_ports++;
3259
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003261
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003262out_unreg_port:
3263 ehea_unregister_port(port);
3264
3265out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003266 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003267
3268out_free_ethdev:
3269 free_netdev(dev);
3270
3271out_err:
3272 ehea_error("setting up logical port with id=%d failed, ret=%d",
3273 logical_port_id, ret);
3274 return NULL;
3275}
3276
3277static void ehea_shutdown_single_port(struct ehea_port *port)
3278{
Brian King7fb1c2a2008-05-14 09:48:25 -05003279 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003280 unregister_netdev(port->netdev);
3281 ehea_unregister_port(port);
3282 kfree(port->mc_list);
3283 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003284 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003285}
3286
3287static int ehea_setup_ports(struct ehea_adapter *adapter)
3288{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003289 struct device_node *lhea_dn;
3290 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003291
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003292 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003293 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003294
Grant Likely61c7a082010-04-13 16:12:29 -07003295 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003296 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003297
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003298 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003299 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300 if (!dn_log_port_id) {
3301 ehea_error("bad device node: eth_dn name=%s",
3302 eth_dn->full_name);
3303 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003304 }
3305
Thomas Klein1211bb62007-04-26 11:56:43 +02003306 if (ehea_add_adapter_mr(adapter)) {
3307 ehea_error("creating MR failed");
3308 of_node_put(eth_dn);
3309 return -EIO;
3310 }
3311
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003312 adapter->port[i] = ehea_setup_single_port(adapter,
3313 *dn_log_port_id,
3314 eth_dn);
3315 if (adapter->port[i])
3316 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003317 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003319 else
3320 ehea_remove_adapter_mr(adapter);
3321
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003323 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003324 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325}
3326
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003327static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3328 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329{
3330 struct device_node *lhea_dn;
3331 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003332 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333
Grant Likely61c7a082010-04-13 16:12:29 -07003334 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003335 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003336
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003337 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003338 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003339 if (dn_log_port_id)
3340 if (*dn_log_port_id == logical_port_id)
3341 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003342 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343
3344 return NULL;
3345}
3346
3347static ssize_t ehea_probe_port(struct device *dev,
3348 struct device_attribute *attr,
3349 const char *buf, size_t count)
3350{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003351 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352 struct ehea_port *port;
3353 struct device_node *eth_dn = NULL;
3354 int i;
3355
3356 u32 logical_port_id;
3357
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003358 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359
3360 port = ehea_get_port(adapter, logical_port_id);
3361
3362 if (port) {
3363 ehea_info("adding port with logical port id=%d failed. port "
3364 "already configured as %s.", logical_port_id,
3365 port->netdev->name);
3366 return -EINVAL;
3367 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003368
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003369 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3370
3371 if (!eth_dn) {
3372 ehea_info("no logical port with id %d found", logical_port_id);
3373 return -EINVAL;
3374 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003375
Thomas Klein1211bb62007-04-26 11:56:43 +02003376 if (ehea_add_adapter_mr(adapter)) {
3377 ehea_error("creating MR failed");
3378 return -EIO;
3379 }
3380
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003381 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3382
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003383 of_node_put(eth_dn);
3384
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003385 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003386 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003387 if (!adapter->port[i]) {
3388 adapter->port[i] = port;
3389 break;
3390 }
3391
3392 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3393 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003394 } else {
3395 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003396 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003397 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003398
3399 return (ssize_t) count;
3400}
3401
3402static ssize_t ehea_remove_port(struct device *dev,
3403 struct device_attribute *attr,
3404 const char *buf, size_t count)
3405{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003406 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003407 struct ehea_port *port;
3408 int i;
3409 u32 logical_port_id;
3410
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003411 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003412
3413 port = ehea_get_port(adapter, logical_port_id);
3414
3415 if (port) {
3416 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3417 logical_port_id);
3418
3419 ehea_shutdown_single_port(port);
3420
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] == port) {
3423 adapter->port[i] = NULL;
3424 break;
3425 }
3426 } else {
3427 ehea_error("removing port with logical port id=%d failed. port "
3428 "not configured.", logical_port_id);
3429 return -EINVAL;
3430 }
3431
Thomas Klein1211bb62007-04-26 11:56:43 +02003432 ehea_remove_adapter_mr(adapter);
3433
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003434 return (ssize_t) count;
3435}
3436
3437static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3438static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3439
Grant Likely2dc11582010-08-06 09:25:50 -06003440int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003441{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003442 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003443 if (ret)
3444 goto out;
3445
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003446 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003447out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003448 return ret;
3449}
3450
Grant Likely2dc11582010-08-06 09:25:50 -06003451void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003452{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003453 device_remove_file(&dev->dev, &dev_attr_probe_port);
3454 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003455}
3456
Grant Likely2dc11582010-08-06 09:25:50 -06003457static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003458 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003459{
3460 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003461 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003462 int ret;
3463
Grant Likely61c7a082010-04-13 16:12:29 -07003464 if (!dev || !dev->dev.of_node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003465 ehea_error("Invalid ibmebus device probed");
3466 return -EINVAL;
3467 }
3468
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003469 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3470 if (!adapter) {
3471 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003472 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 goto out;
3474 }
3475
Thomas Klein44c82152007-07-11 16:32:00 +02003476 list_add(&adapter->list, &adapter_list);
3477
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003478 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479
Grant Likely61c7a082010-04-13 16:12:29 -07003480 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003481 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003482 if (adapter_handle)
3483 adapter->handle = *adapter_handle;
3484
3485 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003486 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003487 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488 ret = -ENODEV;
3489 goto out_free_ad;
3490 }
3491
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492 adapter->pd = EHEA_PD_ID;
3493
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003494 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496
3497 /* initialize adapter and ports */
3498 /* get adapter properties */
3499 ret = ehea_sense_adapter_attr(adapter);
3500 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003501 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003502 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504
3505 adapter->neq = ehea_create_eq(adapter,
3506 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3507 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003508 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003509 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003510 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003511 }
3512
3513 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3514 (unsigned long)adapter);
3515
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003516 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003517 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003518 "ehea_neq", adapter);
3519 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003520 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003521 goto out_kill_eq;
3522 }
3523
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003524 ret = ehea_create_device_sysfs(dev);
3525 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003526 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003528 ret = ehea_setup_ports(adapter);
3529 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003530 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003531 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 }
3533
3534 ret = 0;
3535 goto out;
3536
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003537out_rem_dev_sysfs:
3538 ehea_remove_device_sysfs(dev);
3539
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003541 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003542
3543out_kill_eq:
3544 ehea_destroy_eq(adapter->neq);
3545
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003547 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003548 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003549
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003551 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003552
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553 return ret;
3554}
3555
Grant Likely2dc11582010-08-06 09:25:50 -06003556static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003558 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003559 int i;
3560
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003561 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003562 if (adapter->port[i]) {
3563 ehea_shutdown_single_port(adapter->port[i]);
3564 adapter->port[i] = NULL;
3565 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003566
3567 ehea_remove_device_sysfs(dev);
3568
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003569 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003571 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003572 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003573
3574 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003575 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003576 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003578
Thomas Klein21eee2d2008-02-13 16:18:33 +01003579 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003580
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581 return 0;
3582}
3583
Thomas Klein21eee2d2008-02-13 16:18:33 +01003584void ehea_crash_handler(void)
3585{
3586 int i;
3587
3588 if (ehea_fw_handles.arr)
3589 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3590 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3591 ehea_fw_handles.arr[i].fwh,
3592 FORCE_FREE);
3593
3594 if (ehea_bcmc_regs.arr)
3595 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3596 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3597 ehea_bcmc_regs.arr[i].port_id,
3598 ehea_bcmc_regs.arr[i].reg_type,
3599 ehea_bcmc_regs.arr[i].macaddr,
3600 0, H_DEREG_BCMC);
3601}
3602
Hannes Hering48cfb142008-05-07 14:43:36 +02003603static int ehea_mem_notifier(struct notifier_block *nb,
3604 unsigned long action, void *data)
3605{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003606 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003607 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003608
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003609 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003610
Hannes Hering48cfb142008-05-07 14:43:36 +02003611 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003612 case MEM_CANCEL_OFFLINE:
3613 ehea_info("memory offlining canceled");
3614 /* Readd canceled memory block */
3615 case MEM_ONLINE:
3616 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003617 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003618 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003619 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003620 ehea_rereg_mrs(NULL);
3621 break;
3622 case MEM_GOING_OFFLINE:
3623 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003624 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003625 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003626 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003627 ehea_rereg_mrs(NULL);
3628 break;
3629 default:
3630 break;
3631 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003632
3633 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003634 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003635
Thomas Kleina7c561f22010-04-20 23:11:31 +00003636out_unlock:
3637 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003638 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003639}
3640
3641static struct notifier_block ehea_mem_nb = {
3642 .notifier_call = ehea_mem_notifier,
3643};
3644
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003645static int ehea_reboot_notifier(struct notifier_block *nb,
3646 unsigned long action, void *unused)
3647{
3648 if (action == SYS_RESTART) {
3649 ehea_info("Reboot: freeing all eHEA resources");
3650 ibmebus_unregister_driver(&ehea_driver);
3651 }
3652 return NOTIFY_DONE;
3653}
3654
3655static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003656 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003657};
3658
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003659static int check_module_parm(void)
3660{
3661 int ret = 0;
3662
3663 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3664 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3665 ehea_info("Bad parameter: rq1_entries");
3666 ret = -EINVAL;
3667 }
3668 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3669 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3670 ehea_info("Bad parameter: rq2_entries");
3671 ret = -EINVAL;
3672 }
3673 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3674 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3675 ehea_info("Bad parameter: rq3_entries");
3676 ret = -EINVAL;
3677 }
3678 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3679 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3680 ehea_info("Bad parameter: sq_entries");
3681 ret = -EINVAL;
3682 }
3683
3684 return ret;
3685}
3686
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003687static ssize_t ehea_show_capabilities(struct device_driver *drv,
3688 char *buf)
3689{
3690 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3691}
3692
3693static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3694 ehea_show_capabilities, NULL);
3695
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003696int __init ehea_module_init(void)
3697{
3698 int ret;
3699
3700 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3701 DRV_VERSION);
3702
Thomas Klein44c82152007-07-11 16:32:00 +02003703
3704 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003705 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3706 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3707
Daniel Walker9f71a562008-03-28 14:41:26 -07003708 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003709 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003710
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003711 ret = check_module_parm();
3712 if (ret)
3713 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003714
3715 ret = ehea_create_busmap();
3716 if (ret)
3717 goto out;
3718
Thomas Klein21eee2d2008-02-13 16:18:33 +01003719 ret = register_reboot_notifier(&ehea_reboot_nb);
3720 if (ret)
3721 ehea_info("failed registering reboot notifier");
3722
Hannes Hering48cfb142008-05-07 14:43:36 +02003723 ret = register_memory_notifier(&ehea_mem_nb);
3724 if (ret)
3725 ehea_info("failed registering memory remove notifier");
3726
Joe Perchesc061b182010-08-23 18:20:03 +00003727 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003728 if (ret)
3729 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003730
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003731 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003732 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003733 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003734 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003735 }
3736
3737 ret = driver_create_file(&ehea_driver.driver,
3738 &driver_attr_capabilities);
3739 if (ret) {
3740 ehea_error("failed to register capabilities attribute, ret=%d",
3741 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003742 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003743 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003744
Thomas Klein21eee2d2008-02-13 16:18:33 +01003745 return ret;
3746
3747out3:
3748 ibmebus_unregister_driver(&ehea_driver);
3749out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003750 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003751 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003752 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003753out:
3754 return ret;
3755}
3756
3757static void __exit ehea_module_exit(void)
3758{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003759 int ret;
3760
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003761 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003762 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003763 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003764 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003765 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003766 if (ret)
3767 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003768 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003769 kfree(ehea_fw_handles.arr);
3770 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003771 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003772}
3773
3774module_init(ehea_module_init);
3775module_exit(ehea_module_exit);