blob: 6372610ed24093b8ed99fdf002e44442be49f696 [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) {
183 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
184 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) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100268 arr = kzalloc(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);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200536 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000537
538 /* The packet was not an IPV4 packet so a complemented checksum was
539 calculated. The value is found in the Internet Checksum field. */
540 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
541 skb->ip_summed = CHECKSUM_COMPLETE;
542 skb->csum = csum_unfold(~cqe->inet_checksum_value);
543 } else
544 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200545}
546
547static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
548 int arr_len,
549 struct ehea_cqe *cqe)
550{
551 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
552 struct sk_buff *skb;
553 void *pref;
554 int x;
555
556 x = skb_index + 1;
557 x &= (arr_len - 1);
558
559 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700560 if (pref) {
561 prefetchw(pref);
562 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200563
Hannes Hering0b2febf2009-05-04 11:06:37 -0700564 pref = (skb_array[x]->data);
565 prefetch(pref);
566 prefetch(pref + EHEA_CACHE_LINE);
567 prefetch(pref + EHEA_CACHE_LINE * 2);
568 prefetch(pref + EHEA_CACHE_LINE * 3);
569 }
570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200571 skb = skb_array[skb_index];
572 skb_array[skb_index] = NULL;
573 return skb;
574}
575
576static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
577 int arr_len, int wqe_index)
578{
579 struct sk_buff *skb;
580 void *pref;
581 int x;
582
583 x = wqe_index + 1;
584 x &= (arr_len - 1);
585
586 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700587 if (pref) {
588 prefetchw(pref);
589 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200590
Hannes Hering0b2febf2009-05-04 11:06:37 -0700591 pref = (skb_array[x]->data);
592 prefetchw(pref);
593 prefetchw(pref + EHEA_CACHE_LINE);
594 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200595
596 skb = skb_array[wqe_index];
597 skb_array[wqe_index] = NULL;
598 return skb;
599}
600
601static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
602 struct ehea_cqe *cqe, int *processed_rq2,
603 int *processed_rq3)
604{
605 struct sk_buff *skb;
606
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100607 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
608 pr->p_stats.err_tcp_cksum++;
609 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
610 pr->p_stats.err_ip_cksum++;
611 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
612 pr->p_stats.err_frame_crc++;
613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200614 if (rq == 2) {
615 *processed_rq2 += 1;
616 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
617 dev_kfree_skb(skb);
618 } else if (rq == 3) {
619 *processed_rq3 += 1;
620 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
621 dev_kfree_skb(skb);
622 }
623
624 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100625 if (netif_msg_rx_err(pr->port)) {
626 ehea_error("Critical receive error for QP %d. "
627 "Resetting port.", pr->qp->init_attr.qp_nr);
628 ehea_dump(cqe, sizeof(*cqe), "CQE");
629 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100630 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200631 return 1;
632 }
633
634 return 0;
635}
636
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700637static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
638 void **tcph, u64 *hdr_flags, void *priv)
639{
640 struct ehea_cqe *cqe = priv;
641 unsigned int ip_len;
642 struct iphdr *iph;
643
644 /* non tcp/udp packets */
645 if (!cqe->header_length)
646 return -1;
647
648 /* non tcp packet */
649 skb_reset_network_header(skb);
650 iph = ip_hdr(skb);
651 if (iph->protocol != IPPROTO_TCP)
652 return -1;
653
654 ip_len = ip_hdrlen(skb);
655 skb_set_transport_header(skb, ip_len);
656 *tcph = tcp_hdr(skb);
657
658 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700659 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700660 return -1;
661
662 *hdr_flags = LRO_IPV4 | LRO_TCP;
663 *iphdr = iph;
664
665 return 0;
666}
667
668static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
669 struct sk_buff *skb)
670{
Joe Perches8e95a202009-12-03 07:58:21 +0000671 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
672 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700673
674 if (use_lro) {
675 if (vlan_extracted)
676 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
677 pr->port->vgrp,
678 cqe->vlan_tag,
679 cqe);
680 else
681 lro_receive_skb(&pr->lro_mgr, skb, cqe);
682 } else {
683 if (vlan_extracted)
684 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
685 cqe->vlan_tag);
686 else
687 netif_receive_skb(skb);
688 }
689}
690
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700691static int ehea_proc_rwqes(struct net_device *dev,
692 struct ehea_port_res *pr,
693 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200694{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100695 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696 struct ehea_qp *qp = pr->qp;
697 struct ehea_cqe *cqe;
698 struct sk_buff *skb;
699 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
700 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
701 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
702 int skb_arr_rq1_len = pr->rq1_skba.len;
703 int skb_arr_rq2_len = pr->rq2_skba.len;
704 int skb_arr_rq3_len = pr->rq3_skba.len;
705 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700706 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707
708 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
709 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700712 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 ehea_inc_rq1(qp);
714 processed_rq1++;
715 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 if (netif_msg_rx_status(port))
717 ehea_dump(cqe, sizeof(*cqe), "CQE");
718
719 last_wqe_index = wqe_index;
720 rmb();
721 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600722 if (rq == 1) {
723 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 skb = get_skb_by_index_ll(skb_arr_rq1,
725 skb_arr_rq1_len,
726 wqe_index);
727 if (unlikely(!skb)) {
728 if (netif_msg_rx_err(port))
729 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100730
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700731 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200732 EHEA_L_PKT_SIZE);
733 if (!skb)
734 break;
735 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600736 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200737 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700738 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600739 } else if (rq == 2) {
740 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200741 skb = get_skb_by_index(skb_arr_rq2,
742 skb_arr_rq2_len, cqe);
743 if (unlikely(!skb)) {
744 if (netif_msg_rx_err(port))
745 ehea_error("rq2: skb=NULL");
746 break;
747 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700748 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600750 } else {
751 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200752 skb = get_skb_by_index(skb_arr_rq3,
753 skb_arr_rq3_len, cqe);
754 if (unlikely(!skb)) {
755 if (netif_msg_rx_err(port))
756 ehea_error("rq3: skb=NULL");
757 break;
758 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700759 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 processed_rq3++;
761 }
762
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700763 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100764 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100765 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 port_reset = ehea_treat_poll_error(pr, rq, cqe,
767 &processed_rq2,
768 &processed_rq3);
769 if (port_reset)
770 break;
771 }
772 cqe = ehea_poll_rq1(qp, &wqe_index);
773 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700774 if (use_lro)
775 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200776
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777 pr->rx_packets += processed;
778
779 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
780 ehea_refill_rq2(pr, processed_rq2);
781 ehea_refill_rq3(pr, processed_rq3);
782
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700783 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784}
785
Andre Detsch2928db42010-08-17 05:49:12 +0000786#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
787
788static void reset_sq_restart_flag(struct ehea_port *port)
789{
790 int i;
791
792 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
793 struct ehea_port_res *pr = &port->port_res[i];
794 pr->sq_restart_flag = 0;
795 }
796}
797
798static void check_sqs(struct ehea_port *port)
799{
800 struct ehea_swqe *swqe;
801 int swqe_index;
802 int i, k;
803
804 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
805 struct ehea_port_res *pr = &port->port_res[i];
806 k = 0;
807 swqe = ehea_get_swqe(pr->qp, &swqe_index);
808 memset(swqe, 0, SWQE_HEADER_SIZE);
809 atomic_dec(&pr->swqe_avail);
810
811 swqe->tx_control |= EHEA_SWQE_PURGE;
812 swqe->wr_id = SWQE_RESTART_CHECK;
813 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
814 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
815 swqe->immediate_data_length = 80;
816
817 ehea_post_swqe(pr->qp, swqe);
818
819 while (pr->sq_restart_flag == 0) {
820 msleep(5);
821 if (++k == 100) {
822 ehea_error("HW/SW queues out of sync");
823 ehea_schedule_port_reset(pr->port);
824 return;
825 }
826 }
827 }
828
829 return;
830}
831
832
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100833static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200834{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100835 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200836 struct ehea_cq *send_cq = pr->send_cq;
837 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100838 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200839 int cqe_counter = 0;
840 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100841 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200842 unsigned long flags;
843
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100844 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600845 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100846 ehea_inc_cq(send_cq);
847
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200848 cqe_counter++;
849 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000850
851 if (cqe->wr_id == SWQE_RESTART_CHECK) {
852 pr->sq_restart_flag = 1;
853 swqe_av++;
854 break;
855 }
856
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Thomas Kleinea96cea2010-04-20 23:10:55 +0000858 ehea_error("Bad send completion status=0x%04X",
859 cqe->status);
860
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861 if (netif_msg_tx_err(pr->port))
862 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000863
864 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
865 ehea_error("Resetting port");
866 ehea_schedule_port_reset(pr->port);
867 break;
868 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200869 }
870
871 if (netif_msg_tx_done(pr->port))
872 ehea_dump(cqe, sizeof(*cqe), "CQE");
873
874 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100875 == EHEA_SWQE2_TYPE)) {
876
877 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
878 skb = pr->sq_skba.arr[index];
879 dev_kfree_skb(skb);
880 pr->sq_skba.arr[index] = NULL;
881 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882
883 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
884 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100885
886 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700887 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200888
889 ehea_update_feca(send_cq, cqe_counter);
890 atomic_add(swqe_av, &pr->swqe_avail);
891
892 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200894 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
895 >= pr->swqe_refill_th)) {
896 netif_wake_queue(pr->port->netdev);
897 pr->queue_stopped = 0;
898 }
899 spin_unlock_irqrestore(&pr->netif_queue, flags);
900
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902}
903
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100904#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700905#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100906
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700907static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200908{
Doug Maxey508d2b52008-01-31 20:20:49 -0600909 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
910 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700911 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100912 struct ehea_cqe *cqe;
913 struct ehea_cqe *cqe_skb = NULL;
914 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700915 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100916
917 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700918 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100919
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700920 if (!force_irq)
921 rx += ehea_proc_rwqes(dev, pr, budget - rx);
922
923 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100924 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700925 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800926 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100927 ehea_reset_cq_ep(pr->recv_cq);
928 ehea_reset_cq_ep(pr->send_cq);
929 ehea_reset_cq_n1(pr->recv_cq);
930 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000931 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100932 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
933 cqe_skb = ehea_poll_cq(pr->send_cq);
934
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100935 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100937
Ben Hutchings288379f2009-01-19 16:43:59 -0800938 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700939 return rx;
940
941 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
942 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100943 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100944
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700945 pr->poll_counter++;
946 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200947}
948
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200949#ifdef CONFIG_NET_POLL_CONTROLLER
950static void ehea_netpoll(struct net_device *dev)
951{
952 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700953 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200954
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700955 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800956 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200957}
958#endif
959
David Howells7d12e782006-10-05 14:55:46 +0100960static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200961{
962 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100963
Ben Hutchings288379f2009-01-19 16:43:59 -0800964 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100965
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966 return IRQ_HANDLED;
967}
968
David Howells7d12e782006-10-05 14:55:46 +0100969static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200970{
971 struct ehea_port *port = param;
972 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100973 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200974 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000975 u64 resource_type, aer, aerr;
976 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200977
978 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100979
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200980 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200981 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000982 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100983 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100984
985 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000986
987 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
988 &aer, &aerr);
989
990 if (resource_type == EHEA_AER_RESTYPE_QP) {
991 if ((aer & EHEA_AER_RESET_MASK) ||
992 (aerr & EHEA_AERR_RESET_MASK))
993 reset_port = 1;
994 } else
995 reset_port = 1; /* Reset in case of CQ or EQ error */
996
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100997 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 }
999
Thomas Kleinea96cea2010-04-20 23:10:55 +00001000 if (reset_port) {
1001 ehea_error("Resetting port");
1002 ehea_schedule_port_reset(port);
1003 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001004
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001005 return IRQ_HANDLED;
1006}
1007
1008static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1009 int logical_port)
1010{
1011 int i;
1012
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001013 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001014 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001015 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001016 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001017 return NULL;
1018}
1019
1020int ehea_sense_port_attr(struct ehea_port *port)
1021{
1022 int ret;
1023 u64 hret;
1024 struct hcp_ehea_port_cb0 *cb0;
1025
Doug Maxey508d2b52008-01-31 20:20:49 -06001026 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001027 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001028 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001029 ehea_error("no mem for cb0");
1030 ret = -ENOMEM;
1031 goto out;
1032 }
1033
1034 hret = ehea_h_query_ehea_port(port->adapter->handle,
1035 port->logical_port_id, H_PORT_CB0,
1036 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1037 cb0);
1038 if (hret != H_SUCCESS) {
1039 ret = -EIO;
1040 goto out_free;
1041 }
1042
1043 /* MAC address */
1044 port->mac_addr = cb0->port_mac_addr << 16;
1045
Doug Maxey508d2b52008-01-31 20:20:49 -06001046 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001047 ret = -EADDRNOTAVAIL;
1048 goto out_free;
1049 }
1050
1051 /* Port speed */
1052 switch (cb0->port_speed) {
1053 case H_SPEED_10M_H:
1054 port->port_speed = EHEA_SPEED_10M;
1055 port->full_duplex = 0;
1056 break;
1057 case H_SPEED_10M_F:
1058 port->port_speed = EHEA_SPEED_10M;
1059 port->full_duplex = 1;
1060 break;
1061 case H_SPEED_100M_H:
1062 port->port_speed = EHEA_SPEED_100M;
1063 port->full_duplex = 0;
1064 break;
1065 case H_SPEED_100M_F:
1066 port->port_speed = EHEA_SPEED_100M;
1067 port->full_duplex = 1;
1068 break;
1069 case H_SPEED_1G_F:
1070 port->port_speed = EHEA_SPEED_1G;
1071 port->full_duplex = 1;
1072 break;
1073 case H_SPEED_10G_F:
1074 port->port_speed = EHEA_SPEED_10G;
1075 port->full_duplex = 1;
1076 break;
1077 default:
1078 port->port_speed = 0;
1079 port->full_duplex = 0;
1080 break;
1081 }
1082
Thomas Kleine919b592007-01-22 12:53:20 +01001083 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001084 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001085
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001086 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001087 if (use_mcs)
1088 port->num_def_qps = cb0->num_default_qps;
1089 else
1090 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001091
1092 if (!port->num_def_qps) {
1093 ret = -EINVAL;
1094 goto out_free;
1095 }
1096
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001097 port->num_tx_qps = num_tx_qps;
1098
1099 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001100 port->num_add_tx_qps = 0;
1101 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001102 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001103
1104 ret = 0;
1105out_free:
1106 if (ret || netif_msg_probe(port))
1107 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001108 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001109out:
1110 return ret;
1111}
1112
1113int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1114{
1115 struct hcp_ehea_port_cb4 *cb4;
1116 u64 hret;
1117 int ret = 0;
1118
Thomas Klein3faf2692009-01-21 14:45:33 -08001119 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001120 if (!cb4) {
1121 ehea_error("no mem for cb4");
1122 ret = -ENOMEM;
1123 goto out;
1124 }
1125
1126 cb4->port_speed = port_speed;
1127
1128 netif_carrier_off(port->netdev);
1129
1130 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1131 port->logical_port_id,
1132 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1133 if (hret == H_SUCCESS) {
1134 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1135
1136 hret = ehea_h_query_ehea_port(port->adapter->handle,
1137 port->logical_port_id,
1138 H_PORT_CB4, H_PORT_CB4_SPEED,
1139 cb4);
1140 if (hret == H_SUCCESS) {
1141 switch (cb4->port_speed) {
1142 case H_SPEED_10M_H:
1143 port->port_speed = EHEA_SPEED_10M;
1144 port->full_duplex = 0;
1145 break;
1146 case H_SPEED_10M_F:
1147 port->port_speed = EHEA_SPEED_10M;
1148 port->full_duplex = 1;
1149 break;
1150 case H_SPEED_100M_H:
1151 port->port_speed = EHEA_SPEED_100M;
1152 port->full_duplex = 0;
1153 break;
1154 case H_SPEED_100M_F:
1155 port->port_speed = EHEA_SPEED_100M;
1156 port->full_duplex = 1;
1157 break;
1158 case H_SPEED_1G_F:
1159 port->port_speed = EHEA_SPEED_1G;
1160 port->full_duplex = 1;
1161 break;
1162 case H_SPEED_10G_F:
1163 port->port_speed = EHEA_SPEED_10G;
1164 port->full_duplex = 1;
1165 break;
1166 default:
1167 port->port_speed = 0;
1168 port->full_duplex = 0;
1169 break;
1170 }
1171 } else {
1172 ehea_error("Failed sensing port speed");
1173 ret = -EIO;
1174 }
1175 } else {
1176 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001177 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001178 ret = -EPERM;
1179 } else {
1180 ret = -EIO;
1181 ehea_error("Failed setting port speed");
1182 }
1183 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001184 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1185 netif_carrier_on(port->netdev);
1186
Thomas Klein3faf2692009-01-21 14:45:33 -08001187 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001188out:
1189 return ret;
1190}
1191
1192static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1193{
1194 int ret;
1195 u8 ec;
1196 u8 portnum;
1197 struct ehea_port *port;
1198
1199 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1200 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1201 port = ehea_get_port(adapter, portnum);
1202
1203 switch (ec) {
1204 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1205
1206 if (!port) {
1207 ehea_error("unknown portnum %x", portnum);
1208 break;
1209 }
1210
1211 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1212 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001213 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001214 if (ret) {
1215 ehea_error("failed resensing port "
1216 "attributes");
1217 break;
1218 }
1219
1220 if (netif_msg_link(port))
1221 ehea_info("%s: Logical port up: %dMbps "
1222 "%s Duplex",
1223 port->netdev->name,
1224 port->port_speed,
1225 port->full_duplex ==
1226 1 ? "Full" : "Half");
1227
1228 netif_carrier_on(port->netdev);
1229 netif_wake_queue(port->netdev);
1230 }
1231 } else
1232 if (netif_carrier_ok(port->netdev)) {
1233 if (netif_msg_link(port))
1234 ehea_info("%s: Logical port down",
1235 port->netdev->name);
1236 netif_carrier_off(port->netdev);
1237 netif_stop_queue(port->netdev);
1238 }
1239
1240 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001241 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001242 if (netif_msg_link(port))
1243 ehea_info("%s: Physical port up",
1244 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001245 if (prop_carrier_state)
1246 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001248 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 if (netif_msg_link(port))
1250 ehea_info("%s: Physical port down",
1251 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001252 if (prop_carrier_state)
1253 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001254 }
1255
1256 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1257 ehea_info("External switch port is primary port");
1258 else
1259 ehea_info("External switch port is backup port");
1260
1261 break;
1262 case EHEA_EC_ADAPTER_MALFUNC:
1263 ehea_error("Adapter malfunction");
1264 break;
1265 case EHEA_EC_PORT_MALFUNC:
1266 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1267 netif_carrier_off(port->netdev);
1268 netif_stop_queue(port->netdev);
1269 break;
1270 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001271 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 break;
1273 }
1274}
1275
1276static void ehea_neq_tasklet(unsigned long data)
1277{
Doug Maxey508d2b52008-01-31 20:20:49 -06001278 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001279 struct ehea_eqe *eqe;
1280 u64 event_mask;
1281
1282 eqe = ehea_poll_eq(adapter->neq);
1283 ehea_debug("eqe=%p", eqe);
1284
1285 while (eqe) {
1286 ehea_debug("*eqe=%lx", eqe->entry);
1287 ehea_parse_eqe(adapter, eqe->entry);
1288 eqe = ehea_poll_eq(adapter->neq);
1289 ehea_debug("next eqe=%p", eqe);
1290 }
1291
1292 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1293 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1294 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1295
1296 ehea_h_reset_events(adapter->handle,
1297 adapter->neq->fw_handle, event_mask);
1298}
1299
David Howells7d12e782006-10-05 14:55:46 +01001300static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301{
1302 struct ehea_adapter *adapter = param;
1303 tasklet_hi_schedule(&adapter->neq_tasklet);
1304 return IRQ_HANDLED;
1305}
1306
1307
1308static int ehea_fill_port_res(struct ehea_port_res *pr)
1309{
1310 int ret;
1311 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1312
Thomas Kleine2878802009-01-21 14:45:57 -08001313 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1314 - init_attr->act_nr_rwqes_rq2
1315 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001316
Thomas Kleine2878802009-01-21 14:45:57 -08001317 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001318
1319 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1320
1321 return ret;
1322}
1323
1324static int ehea_reg_interrupts(struct net_device *dev)
1325{
1326 struct ehea_port *port = netdev_priv(dev);
1327 struct ehea_port_res *pr;
1328 int i, ret;
1329
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330
1331 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1332 dev->name);
1333
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001334 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001335 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001336 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337 if (ret) {
1338 ehea_error("failed registering irq for qp_aff_irq_handler:"
1339 "ist=%X", port->qp_eq->attr.ist1);
1340 goto out_free_qpeq;
1341 }
1342
1343 if (netif_msg_ifup(port))
1344 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1345 "registered", port->qp_eq->attr.ist1);
1346
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1349 pr = &port->port_res[i];
1350 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001351 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001352 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001353 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001354 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 pr);
1356 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001357 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001359 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001360 goto out_free_req;
1361 }
1362 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001363 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1364 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001365 }
1366out:
1367 return ret;
1368
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001369
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370out_free_req:
1371 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001372 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001373 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001375
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001377 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001379
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001380 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001381
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001382}
1383
1384static void ehea_free_interrupts(struct net_device *dev)
1385{
1386 struct ehea_port *port = netdev_priv(dev);
1387 struct ehea_port_res *pr;
1388 int i;
1389
1390 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001391
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1393 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001394 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001395 if (netif_msg_intr(port))
1396 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001397 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398 }
1399
1400 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001401 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001402 if (netif_msg_intr(port))
1403 ehea_info("associated event interrupt for handle 0x%X freed",
1404 port->qp_eq->attr.ist1);
1405}
1406
1407static int ehea_configure_port(struct ehea_port *port)
1408{
1409 int ret, i;
1410 u64 hret, mask;
1411 struct hcp_ehea_port_cb0 *cb0;
1412
1413 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001414 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001415 if (!cb0)
1416 goto out;
1417
1418 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1419 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1420 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1421 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1422 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1423 PXLY_RC_VLAN_FILTER)
1424 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1425
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001426 for (i = 0; i < port->num_mcs; i++)
1427 if (use_mcs)
1428 cb0->default_qpn_arr[i] =
1429 port->port_res[i].qp->init_attr.qp_nr;
1430 else
1431 cb0->default_qpn_arr[i] =
1432 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001433
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434 if (netif_msg_ifup(port))
1435 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1436
1437 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1438 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1439
1440 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1441 port->logical_port_id,
1442 H_PORT_CB0, mask, cb0);
1443 ret = -EIO;
1444 if (hret != H_SUCCESS)
1445 goto out_free;
1446
1447 ret = 0;
1448
1449out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001450 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001451out:
1452 return ret;
1453}
1454
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001455int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001456{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001457 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001458 struct ehea_adapter *adapter = pr->port->adapter;
1459
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001460 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1461 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001462 goto out;
1463
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001464 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1465 if (ret)
1466 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001467
1468 return 0;
1469
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001470out_free:
1471 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001472out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474 return -EIO;
1475}
1476
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001477int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478{
Joe Perches8e95a202009-12-03 07:58:21 +00001479 if ((ehea_rem_mr(&pr->send_mr)) ||
1480 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001481 return -EIO;
1482 else
1483 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484}
1485
1486static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1487{
Doug Maxey508d2b52008-01-31 20:20:49 -06001488 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001489
1490 q_skba->arr = vmalloc(arr_size);
1491 if (!q_skba->arr)
1492 return -ENOMEM;
1493
1494 memset(q_skba->arr, 0, arr_size);
1495
1496 q_skba->len = max_q_entries;
1497 q_skba->index = 0;
1498 q_skba->os_skbs = 0;
1499
1500 return 0;
1501}
1502
1503static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1504 struct port_res_cfg *pr_cfg, int queue_token)
1505{
1506 struct ehea_adapter *adapter = port->adapter;
1507 enum ehea_eq_type eq_type = EHEA_EQ;
1508 struct ehea_qp_init_attr *init_attr = NULL;
1509 int ret = -EIO;
1510
1511 memset(pr, 0, sizeof(struct ehea_port_res));
1512
1513 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001514 spin_lock_init(&pr->xmit_lock);
1515 spin_lock_init(&pr->netif_queue);
1516
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001517 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1518 if (!pr->eq) {
1519 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001520 goto out_free;
1521 }
1522
1523 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
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->recv_cq) {
1527 ehea_error("create_cq failed (cq_recv)");
1528 goto out_free;
1529 }
1530
1531 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001532 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001533 port->logical_port_id);
1534 if (!pr->send_cq) {
1535 ehea_error("create_cq failed (cq_send)");
1536 goto out_free;
1537 }
1538
1539 if (netif_msg_ifup(port))
1540 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1541 pr->send_cq->attr.act_nr_of_cqes,
1542 pr->recv_cq->attr.act_nr_of_cqes);
1543
1544 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1545 if (!init_attr) {
1546 ret = -ENOMEM;
1547 ehea_error("no mem for ehea_qp_init_attr");
1548 goto out_free;
1549 }
1550
1551 init_attr->low_lat_rq1 = 1;
1552 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1553 init_attr->rq_count = 3;
1554 init_attr->qp_token = queue_token;
1555 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1556 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1557 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1558 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1559 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1560 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1561 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1562 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1563 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1564 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1565 init_attr->port_nr = port->logical_port_id;
1566 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1567 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1568 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1569
1570 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1571 if (!pr->qp) {
1572 ehea_error("create_qp failed");
1573 ret = -EIO;
1574 goto out_free;
1575 }
1576
1577 if (netif_msg_ifup(port))
1578 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1579 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1580 init_attr->act_nr_send_wqes,
1581 init_attr->act_nr_rwqes_rq1,
1582 init_attr->act_nr_rwqes_rq2,
1583 init_attr->act_nr_rwqes_rq3);
1584
Thomas Klein44fb3122008-04-04 15:04:53 +02001585 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1586
1587 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001588 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1589 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1590 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1591 if (ret)
1592 goto out_free;
1593
1594 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1595 if (ehea_gen_smrs(pr) != 0) {
1596 ret = -EIO;
1597 goto out_free;
1598 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001599
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1601
1602 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001603
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001604 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001605
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001606 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1607 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1608 pr->lro_mgr.lro_arr = pr->lro_desc;
1609 pr->lro_mgr.get_skb_header = get_skb_hdr;
1610 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1611 pr->lro_mgr.dev = port->netdev;
1612 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1613 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1614
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001615 ret = 0;
1616 goto out;
1617
1618out_free:
1619 kfree(init_attr);
1620 vfree(pr->sq_skba.arr);
1621 vfree(pr->rq1_skba.arr);
1622 vfree(pr->rq2_skba.arr);
1623 vfree(pr->rq3_skba.arr);
1624 ehea_destroy_qp(pr->qp);
1625 ehea_destroy_cq(pr->send_cq);
1626 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001627 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001628out:
1629 return ret;
1630}
1631
1632static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1633{
1634 int ret, i;
1635
Hannes Hering357eb462009-08-04 11:48:39 -07001636 if (pr->qp)
1637 netif_napi_del(&pr->napi);
1638
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001639 ret = ehea_destroy_qp(pr->qp);
1640
1641 if (!ret) {
1642 ehea_destroy_cq(pr->send_cq);
1643 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001644 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001645
1646 for (i = 0; i < pr->rq1_skba.len; i++)
1647 if (pr->rq1_skba.arr[i])
1648 dev_kfree_skb(pr->rq1_skba.arr[i]);
1649
1650 for (i = 0; i < pr->rq2_skba.len; i++)
1651 if (pr->rq2_skba.arr[i])
1652 dev_kfree_skb(pr->rq2_skba.arr[i]);
1653
1654 for (i = 0; i < pr->rq3_skba.len; i++)
1655 if (pr->rq3_skba.arr[i])
1656 dev_kfree_skb(pr->rq3_skba.arr[i]);
1657
1658 for (i = 0; i < pr->sq_skba.len; i++)
1659 if (pr->sq_skba.arr[i])
1660 dev_kfree_skb(pr->sq_skba.arr[i]);
1661
1662 vfree(pr->rq1_skba.arr);
1663 vfree(pr->rq2_skba.arr);
1664 vfree(pr->rq3_skba.arr);
1665 vfree(pr->sq_skba.arr);
1666 ret = ehea_rem_smrs(pr);
1667 }
1668 return ret;
1669}
1670
1671/*
1672 * The write_* functions store information in swqe which is used by
1673 * the hardware to calculate the ip/tcp/udp checksum
1674 */
1675
1676static inline void write_ip_start_end(struct ehea_swqe *swqe,
1677 const struct sk_buff *skb)
1678{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001679 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001680 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001681}
1682
1683static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1684 const struct sk_buff *skb)
1685{
1686 swqe->tcp_offset =
1687 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1688
1689 swqe->tcp_end = (u16)skb->len - 1;
1690}
1691
1692static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1693 const struct sk_buff *skb)
1694{
1695 swqe->tcp_offset =
1696 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1697
1698 swqe->tcp_end = (u16)skb->len - 1;
1699}
1700
1701
1702static void write_swqe2_TSO(struct sk_buff *skb,
1703 struct ehea_swqe *swqe, u32 lkey)
1704{
1705 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1706 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001707 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001709
1710 /* Packet is TCP with TSO enabled */
1711 swqe->tx_control |= EHEA_SWQE_TSO;
1712 swqe->mss = skb_shinfo(skb)->gso_size;
1713 /* copy only eth/ip/tcp headers to immediate data and
1714 * the rest of skb->data to sg1entry
1715 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001716 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001717
Eric Dumazete743d312010-04-14 15:59:40 -07001718 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001719
1720 if (skb_data_size >= headersize) {
1721 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001722 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001723 swqe->immediate_data_length = headersize;
1724
1725 if (skb_data_size > headersize) {
1726 /* set sg1entry data */
1727 sg1entry->l_key = lkey;
1728 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001729 sg1entry->vaddr =
1730 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001731 swqe->descriptors++;
1732 }
1733 } else
1734 ehea_error("cannot handle fragmented headers");
1735}
1736
1737static void write_swqe2_nonTSO(struct sk_buff *skb,
1738 struct ehea_swqe *swqe, u32 lkey)
1739{
Eric Dumazete743d312010-04-14 15:59:40 -07001740 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001741 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1742 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001743
1744 /* Packet is any nonTSO type
1745 *
1746 * Copy as much as possible skb->data to immediate data and
1747 * the rest to sg1entry
1748 */
1749 if (skb_data_size >= SWQE2_MAX_IMM) {
1750 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001751 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001752
1753 swqe->immediate_data_length = SWQE2_MAX_IMM;
1754
1755 if (skb_data_size > SWQE2_MAX_IMM) {
1756 /* copy sg1entry data */
1757 sg1entry->l_key = lkey;
1758 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001759 sg1entry->vaddr =
1760 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761 swqe->descriptors++;
1762 }
1763 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001764 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001765 swqe->immediate_data_length = skb_data_size;
1766 }
1767}
1768
1769static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1770 struct ehea_swqe *swqe, u32 lkey)
1771{
1772 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1773 skb_frag_t *frag;
1774 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001775
1776 nfrags = skb_shinfo(skb)->nr_frags;
1777 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001778 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779 swqe->descriptors = 0;
1780 sg1entry_contains_frag_data = 0;
1781
1782 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1783 write_swqe2_TSO(skb, swqe, lkey);
1784 else
1785 write_swqe2_nonTSO(skb, swqe, lkey);
1786
1787 /* write descriptors */
1788 if (nfrags > 0) {
1789 if (swqe->descriptors == 0) {
1790 /* sg1entry not yet used */
1791 frag = &skb_shinfo(skb)->frags[0];
1792
1793 /* copy sg1entry data */
1794 sg1entry->l_key = lkey;
1795 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001796 sg1entry->vaddr =
1797 ehea_map_vaddr(page_address(frag->page)
1798 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799 swqe->descriptors++;
1800 sg1entry_contains_frag_data = 1;
1801 }
1802
1803 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1804
1805 frag = &skb_shinfo(skb)->frags[i];
1806 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1807
1808 sgentry->l_key = lkey;
1809 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001810 sgentry->vaddr =
1811 ehea_map_vaddr(page_address(frag->page)
1812 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001813 swqe->descriptors++;
1814 }
1815 }
1816}
1817
1818static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1819{
1820 int ret = 0;
1821 u64 hret;
1822 u8 reg_type;
1823
1824 /* De/Register untagged packets */
1825 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1826 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1827 port->logical_port_id,
1828 reg_type, port->mac_addr, 0, hcallid);
1829 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001830 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001831 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001832 ret = -EIO;
1833 goto out_herr;
1834 }
1835
1836 /* De/Register VLAN packets */
1837 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1838 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1839 port->logical_port_id,
1840 reg_type, port->mac_addr, 0, hcallid);
1841 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001842 ehea_error("%sregistering bc address failed (vlan)",
1843 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001844 ret = -EIO;
1845 }
1846out_herr:
1847 return ret;
1848}
1849
1850static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1851{
1852 struct ehea_port *port = netdev_priv(dev);
1853 struct sockaddr *mac_addr = sa;
1854 struct hcp_ehea_port_cb0 *cb0;
1855 int ret;
1856 u64 hret;
1857
1858 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1859 ret = -EADDRNOTAVAIL;
1860 goto out;
1861 }
1862
Thomas Klein3faf2692009-01-21 14:45:33 -08001863 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001864 if (!cb0) {
1865 ehea_error("no mem for cb0");
1866 ret = -ENOMEM;
1867 goto out;
1868 }
1869
1870 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1871
1872 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1873
1874 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1875 port->logical_port_id, H_PORT_CB0,
1876 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1877 if (hret != H_SUCCESS) {
1878 ret = -EIO;
1879 goto out_free;
1880 }
1881
1882 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1883
1884 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001885 if (port->state == EHEA_PORT_UP) {
1886 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1887 if (ret)
1888 goto out_upregs;
1889 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001890
1891 port->mac_addr = cb0->port_mac_addr << 16;
1892
1893 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001894 if (port->state == EHEA_PORT_UP) {
1895 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1896 if (ret)
1897 goto out_upregs;
1898 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001899
1900 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001901
1902out_upregs:
1903 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001904out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001905 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906out:
1907 return ret;
1908}
1909
1910static void ehea_promiscuous_error(u64 hret, int enable)
1911{
Thomas Klein7674a582007-01-22 12:54:20 +01001912 if (hret == H_AUTHORITY)
1913 ehea_info("Hypervisor denied %sabling promiscuous mode",
1914 enable == 1 ? "en" : "dis");
1915 else
1916 ehea_error("failed %sabling promiscuous mode",
1917 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001918}
1919
1920static void ehea_promiscuous(struct net_device *dev, int enable)
1921{
1922 struct ehea_port *port = netdev_priv(dev);
1923 struct hcp_ehea_port_cb7 *cb7;
1924 u64 hret;
1925
1926 if ((enable && port->promisc) || (!enable && !port->promisc))
1927 return;
1928
Thomas Klein3faf2692009-01-21 14:45:33 -08001929 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001930 if (!cb7) {
1931 ehea_error("no mem for cb7");
1932 goto out;
1933 }
1934
1935 /* Modify Pxs_DUCQPN in CB7 */
1936 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1937
1938 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1939 port->logical_port_id,
1940 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1941 if (hret) {
1942 ehea_promiscuous_error(hret, enable);
1943 goto out;
1944 }
1945
1946 port->promisc = enable;
1947out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001948 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001949}
1950
1951static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1952 u32 hcallid)
1953{
1954 u64 hret;
1955 u8 reg_type;
1956
1957 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1958 | EHEA_BCMC_UNTAGGED;
1959
1960 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1961 port->logical_port_id,
1962 reg_type, mc_mac_addr, 0, hcallid);
1963 if (hret)
1964 goto out;
1965
1966 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1967 | EHEA_BCMC_VLANID_ALL;
1968
1969 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1970 port->logical_port_id,
1971 reg_type, mc_mac_addr, 0, hcallid);
1972out:
1973 return hret;
1974}
1975
1976static int ehea_drop_multicast_list(struct net_device *dev)
1977{
1978 struct ehea_port *port = netdev_priv(dev);
1979 struct ehea_mc_list *mc_entry = port->mc_list;
1980 struct list_head *pos;
1981 struct list_head *temp;
1982 int ret = 0;
1983 u64 hret;
1984
1985 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1986 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1987
1988 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1989 H_DEREG_BCMC);
1990 if (hret) {
1991 ehea_error("failed deregistering mcast MAC");
1992 ret = -EIO;
1993 }
1994
1995 list_del(pos);
1996 kfree(mc_entry);
1997 }
1998 return ret;
1999}
2000
2001static void ehea_allmulti(struct net_device *dev, int enable)
2002{
2003 struct ehea_port *port = netdev_priv(dev);
2004 u64 hret;
2005
2006 if (!port->allmulti) {
2007 if (enable) {
2008 /* Enable ALLMULTI */
2009 ehea_drop_multicast_list(dev);
2010 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2011 if (!hret)
2012 port->allmulti = 1;
2013 else
2014 ehea_error("failed enabling IFF_ALLMULTI");
2015 }
2016 } else
2017 if (!enable) {
2018 /* Disable ALLMULTI */
2019 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2020 if (!hret)
2021 port->allmulti = 0;
2022 else
2023 ehea_error("failed disabling IFF_ALLMULTI");
2024 }
2025}
2026
Doug Maxey508d2b52008-01-31 20:20:49 -06002027static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002028{
2029 struct ehea_mc_list *ehea_mcl_entry;
2030 u64 hret;
2031
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002032 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033 if (!ehea_mcl_entry) {
2034 ehea_error("no mem for mcl_entry");
2035 return;
2036 }
2037
2038 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2039
2040 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2041
2042 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2043 H_REG_BCMC);
2044 if (!hret)
2045 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2046 else {
2047 ehea_error("failed registering mcast MAC");
2048 kfree(ehea_mcl_entry);
2049 }
2050}
2051
2052static void ehea_set_multicast_list(struct net_device *dev)
2053{
2054 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002055 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002056 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002057
2058 if (dev->flags & IFF_PROMISC) {
2059 ehea_promiscuous(dev, 1);
2060 return;
2061 }
2062 ehea_promiscuous(dev, 0);
2063
2064 if (dev->flags & IFF_ALLMULTI) {
2065 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002066 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002067 }
2068 ehea_allmulti(dev, 0);
2069
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002070 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002071 ret = ehea_drop_multicast_list(dev);
2072 if (ret) {
2073 /* Dropping the current multicast list failed.
2074 * Enabling ALL_MULTI is the best we can do.
2075 */
2076 ehea_allmulti(dev, 1);
2077 }
2078
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002079 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00002080 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002081 "Use ALLMULTI!",
2082 port->adapter->max_mc_mac);
2083 goto out;
2084 }
2085
Jiri Pirko22bedad32010-04-01 21:22:57 +00002086 netdev_for_each_mc_addr(ha, dev)
2087 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002088
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002089 }
2090out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002091 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002092}
2093
2094static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2095{
2096 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2097 return -EINVAL;
2098 dev->mtu = new_mtu;
2099 return 0;
2100}
2101
2102static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2103 struct ehea_swqe *swqe, u32 lkey)
2104{
2105 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002106 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 /* IPv4 */
2109 swqe->tx_control |= EHEA_SWQE_CRC
2110 | EHEA_SWQE_IP_CHECKSUM
2111 | EHEA_SWQE_TCP_CHECKSUM
2112 | EHEA_SWQE_IMM_DATA_PRESENT
2113 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2114
2115 write_ip_start_end(swqe, skb);
2116
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002117 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002118 if ((iph->frag_off & IP_MF) ||
2119 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120 /* IP fragment, so don't change cs */
2121 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2122 else
2123 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002124 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002125 write_tcp_offset_end(swqe, skb);
2126 }
2127
2128 /* icmp (big data) and ip segmentation packets (all other ip
2129 packets) do not require any special handling */
2130
2131 } else {
2132 /* Other Ethernet Protocol */
2133 swqe->tx_control |= EHEA_SWQE_CRC
2134 | EHEA_SWQE_IMM_DATA_PRESENT
2135 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2136 }
2137
2138 write_swqe2_data(skb, dev, swqe, lkey);
2139}
2140
2141static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2142 struct ehea_swqe *swqe)
2143{
2144 int nfrags = skb_shinfo(skb)->nr_frags;
2145 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2146 skb_frag_t *frag;
2147 int i;
2148
2149 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002150 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002151
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152 /* IPv4 */
2153 write_ip_start_end(swqe, skb);
2154
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002155 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002156 swqe->tx_control |= EHEA_SWQE_CRC
2157 | EHEA_SWQE_IP_CHECKSUM
2158 | EHEA_SWQE_TCP_CHECKSUM
2159 | EHEA_SWQE_IMM_DATA_PRESENT;
2160
2161 write_tcp_offset_end(swqe, skb);
2162
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002163 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002164 if ((iph->frag_off & IP_MF) ||
2165 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002166 /* IP fragment, so don't change cs */
2167 swqe->tx_control |= EHEA_SWQE_CRC
2168 | EHEA_SWQE_IMM_DATA_PRESENT;
2169 else {
2170 swqe->tx_control |= EHEA_SWQE_CRC
2171 | EHEA_SWQE_IP_CHECKSUM
2172 | EHEA_SWQE_TCP_CHECKSUM
2173 | EHEA_SWQE_IMM_DATA_PRESENT;
2174
2175 write_udp_offset_end(swqe, skb);
2176 }
2177 } else {
2178 /* icmp (big data) and
2179 ip segmentation packets (all other ip packets) */
2180 swqe->tx_control |= EHEA_SWQE_CRC
2181 | EHEA_SWQE_IP_CHECKSUM
2182 | EHEA_SWQE_IMM_DATA_PRESENT;
2183 }
2184 } else {
2185 /* Other Ethernet Protocol */
2186 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2187 }
2188 /* copy (immediate) data */
2189 if (nfrags == 0) {
2190 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002191 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192 } else {
2193 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002194 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002195 skb_headlen(skb));
2196 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002197
2198 /* ... then copy data from the fragments */
2199 for (i = 0; i < nfrags; i++) {
2200 frag = &skb_shinfo(skb)->frags[i];
2201 memcpy(imm_data,
2202 page_address(frag->page) + frag->page_offset,
2203 frag->size);
2204 imm_data += frag->size;
2205 }
2206 }
2207 swqe->immediate_data_length = skb->len;
2208 dev_kfree_skb(skb);
2209}
2210
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002211static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2212{
2213 struct tcphdr *tcp;
2214 u32 tmp;
2215
2216 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002217 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002218 tcp = (struct tcphdr *)(skb_network_header(skb) +
2219 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002220 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002221 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002222 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002223 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002224 return 0;
2225}
2226
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2228{
2229 struct ehea_port *port = netdev_priv(dev);
2230 struct ehea_swqe *swqe;
2231 unsigned long flags;
2232 u32 lkey;
2233 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002234 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002236 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2237
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238 if (!spin_trylock(&pr->xmit_lock))
2239 return NETDEV_TX_BUSY;
2240
2241 if (pr->queue_stopped) {
2242 spin_unlock(&pr->xmit_lock);
2243 return NETDEV_TX_BUSY;
2244 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002245
2246 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2247 memset(swqe, 0, SWQE_HEADER_SIZE);
2248 atomic_dec(&pr->swqe_avail);
2249
2250 if (skb->len <= SWQE3_MAX_IMM) {
2251 u32 sig_iv = port->sig_comp_iv;
2252 u32 swqe_num = pr->swqe_id_counter;
2253 ehea_xmit3(skb, dev, swqe);
2254 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2255 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2256 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2257 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2258 sig_iv);
2259 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2260 pr->swqe_ll_count = 0;
2261 } else
2262 pr->swqe_ll_count += 1;
2263 } else {
2264 swqe->wr_id =
2265 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2266 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002267 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2269 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2270
2271 pr->sq_skba.index++;
2272 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2273
2274 lkey = pr->send_mr.lkey;
2275 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002276 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002277 }
2278 pr->swqe_id_counter += 1;
2279
2280 if (port->vgrp && vlan_tx_tag_present(skb)) {
2281 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2282 swqe->vlan_tag = vlan_tx_tag_get(skb);
2283 }
2284
2285 if (netif_msg_tx_queued(port)) {
2286 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002287 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002288 }
2289
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002290 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2291 netif_stop_queue(dev);
2292 swqe->tx_control |= EHEA_SWQE_PURGE;
2293 }
Thomas Klein44c82152007-07-11 16:32:00 +02002294
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002295 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002296 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002297
2298 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2299 spin_lock_irqsave(&pr->netif_queue, flags);
2300 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002301 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002302 netif_stop_queue(dev);
2303 pr->queue_stopped = 1;
2304 }
2305 spin_unlock_irqrestore(&pr->netif_queue, flags);
2306 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002307 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002308 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002309
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002310 return NETDEV_TX_OK;
2311}
2312
2313static void ehea_vlan_rx_register(struct net_device *dev,
2314 struct vlan_group *grp)
2315{
2316 struct ehea_port *port = netdev_priv(dev);
2317 struct ehea_adapter *adapter = port->adapter;
2318 struct hcp_ehea_port_cb1 *cb1;
2319 u64 hret;
2320
2321 port->vgrp = grp;
2322
Thomas Klein3faf2692009-01-21 14:45:33 -08002323 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002324 if (!cb1) {
2325 ehea_error("no mem for cb1");
2326 goto out;
2327 }
2328
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002329 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2330 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2331 if (hret != H_SUCCESS)
2332 ehea_error("modify_ehea_port failed");
2333
Thomas Klein3faf2692009-01-21 14:45:33 -08002334 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002335out:
2336 return;
2337}
2338
2339static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2340{
2341 struct ehea_port *port = netdev_priv(dev);
2342 struct ehea_adapter *adapter = port->adapter;
2343 struct hcp_ehea_port_cb1 *cb1;
2344 int index;
2345 u64 hret;
2346
Thomas Klein3faf2692009-01-21 14:45:33 -08002347 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002348 if (!cb1) {
2349 ehea_error("no mem for cb1");
2350 goto out;
2351 }
2352
2353 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2354 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2355 if (hret != H_SUCCESS) {
2356 ehea_error("query_ehea_port failed");
2357 goto out;
2358 }
2359
2360 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002361 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362
2363 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2364 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2365 if (hret != H_SUCCESS)
2366 ehea_error("modify_ehea_port failed");
2367out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002368 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369 return;
2370}
2371
2372static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2373{
2374 struct ehea_port *port = netdev_priv(dev);
2375 struct ehea_adapter *adapter = port->adapter;
2376 struct hcp_ehea_port_cb1 *cb1;
2377 int index;
2378 u64 hret;
2379
Dan Aloni5c15bde2007-03-02 20:44:51 -08002380 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002381
Thomas Klein3faf2692009-01-21 14:45:33 -08002382 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002383 if (!cb1) {
2384 ehea_error("no mem for cb1");
2385 goto out;
2386 }
2387
2388 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2389 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2390 if (hret != H_SUCCESS) {
2391 ehea_error("query_ehea_port failed");
2392 goto out;
2393 }
2394
2395 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002396 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397
2398 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2399 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2400 if (hret != H_SUCCESS)
2401 ehea_error("modify_ehea_port failed");
2402out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002403 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002404}
2405
2406int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2407{
2408 int ret = -EIO;
2409 u64 hret;
2410 u16 dummy16 = 0;
2411 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002412 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413
Thomas Klein3faf2692009-01-21 14:45:33 -08002414 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 if (!cb0) {
2416 ret = -ENOMEM;
2417 goto out;
2418 }
2419
2420 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2421 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2422 if (hret != H_SUCCESS) {
2423 ehea_error("query_ehea_qp failed (1)");
2424 goto out;
2425 }
2426
2427 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2428 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2429 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2430 &dummy64, &dummy64, &dummy16, &dummy16);
2431 if (hret != H_SUCCESS) {
2432 ehea_error("modify_ehea_qp failed (1)");
2433 goto out;
2434 }
2435
2436 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2437 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2438 if (hret != H_SUCCESS) {
2439 ehea_error("query_ehea_qp failed (2)");
2440 goto out;
2441 }
2442
2443 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2444 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2445 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2446 &dummy64, &dummy64, &dummy16, &dummy16);
2447 if (hret != H_SUCCESS) {
2448 ehea_error("modify_ehea_qp failed (2)");
2449 goto out;
2450 }
2451
2452 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2453 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2454 if (hret != H_SUCCESS) {
2455 ehea_error("query_ehea_qp failed (3)");
2456 goto out;
2457 }
2458
2459 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2460 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2461 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2462 &dummy64, &dummy64, &dummy16, &dummy16);
2463 if (hret != H_SUCCESS) {
2464 ehea_error("modify_ehea_qp failed (3)");
2465 goto out;
2466 }
2467
2468 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2469 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2470 if (hret != H_SUCCESS) {
2471 ehea_error("query_ehea_qp failed (4)");
2472 goto out;
2473 }
2474
2475 ret = 0;
2476out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002477 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 return ret;
2479}
2480
2481static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2482 int add_tx_qps)
2483{
2484 int ret, i;
2485 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2486 enum ehea_eq_type eq_type = EHEA_EQ;
2487
2488 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2489 EHEA_MAX_ENTRIES_EQ, 1);
2490 if (!port->qp_eq) {
2491 ret = -EINVAL;
2492 ehea_error("ehea_create_eq failed (qp_eq)");
2493 goto out_kill_eq;
2494 }
2495
2496 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002497 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002498 pr_cfg.max_entries_sq = sq_entries;
2499 pr_cfg.max_entries_rq1 = rq1_entries;
2500 pr_cfg.max_entries_rq2 = rq2_entries;
2501 pr_cfg.max_entries_rq3 = rq3_entries;
2502
2503 pr_cfg_small_rx.max_entries_rcq = 1;
2504 pr_cfg_small_rx.max_entries_scq = sq_entries;
2505 pr_cfg_small_rx.max_entries_sq = sq_entries;
2506 pr_cfg_small_rx.max_entries_rq1 = 1;
2507 pr_cfg_small_rx.max_entries_rq2 = 1;
2508 pr_cfg_small_rx.max_entries_rq3 = 1;
2509
2510 for (i = 0; i < def_qps; i++) {
2511 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2512 if (ret)
2513 goto out_clean_pr;
2514 }
2515 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2516 ret = ehea_init_port_res(port, &port->port_res[i],
2517 &pr_cfg_small_rx, i);
2518 if (ret)
2519 goto out_clean_pr;
2520 }
2521
2522 return 0;
2523
2524out_clean_pr:
2525 while (--i >= 0)
2526 ehea_clean_portres(port, &port->port_res[i]);
2527
2528out_kill_eq:
2529 ehea_destroy_eq(port->qp_eq);
2530 return ret;
2531}
2532
2533static int ehea_clean_all_portres(struct ehea_port *port)
2534{
2535 int ret = 0;
2536 int i;
2537
Doug Maxey508d2b52008-01-31 20:20:49 -06002538 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002539 ret |= ehea_clean_portres(port, &port->port_res[i]);
2540
2541 ret |= ehea_destroy_eq(port->qp_eq);
2542
2543 return ret;
2544}
2545
Thomas Klein35cf2e22007-08-06 13:55:14 +02002546static void ehea_remove_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;
Thomas Klein1211bb62007-04-26 11:56:43 +02002550
2551 ehea_rem_mr(&adapter->mr);
2552}
2553
Thomas Klein35cf2e22007-08-06 13:55:14 +02002554static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002555{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002556 if (adapter->active_ports)
2557 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002558
2559 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2560}
2561
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002562static int ehea_up(struct net_device *dev)
2563{
2564 int ret, i;
2565 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002566
2567 if (port->state == EHEA_PORT_UP)
2568 return 0;
2569
2570 ret = ehea_port_res_setup(port, port->num_def_qps,
2571 port->num_add_tx_qps);
2572 if (ret) {
2573 ehea_error("port_res_failed");
2574 goto out;
2575 }
2576
2577 /* Set default QP for this port */
2578 ret = ehea_configure_port(port);
2579 if (ret) {
2580 ehea_error("ehea_configure_port failed. ret:%d", ret);
2581 goto out_clean_pr;
2582 }
2583
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002584 ret = ehea_reg_interrupts(dev);
2585 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002586 ehea_error("reg_interrupts failed. ret:%d", ret);
2587 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002588 }
2589
Doug Maxey508d2b52008-01-31 20:20:49 -06002590 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2592 if (ret) {
2593 ehea_error("activate_qp failed");
2594 goto out_free_irqs;
2595 }
2596 }
2597
Doug Maxey508d2b52008-01-31 20:20:49 -06002598 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002599 ret = ehea_fill_port_res(&port->port_res[i]);
2600 if (ret) {
2601 ehea_error("out_free_irqs");
2602 goto out_free_irqs;
2603 }
2604 }
2605
Thomas Klein21eee2d2008-02-13 16:18:33 +01002606 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2607 if (ret) {
2608 ret = -EIO;
2609 goto out_free_irqs;
2610 }
2611
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002613
2614 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002615 goto out;
2616
2617out_free_irqs:
2618 ehea_free_interrupts(dev);
2619
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620out_clean_pr:
2621 ehea_clean_all_portres(port);
2622out:
Thomas Klein44c82152007-07-11 16:32:00 +02002623 if (ret)
2624 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2625
Thomas Klein21eee2d2008-02-13 16:18:33 +01002626 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002627 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002628
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002629 return ret;
2630}
2631
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002632static void port_napi_disable(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_disable(&port->port_res[i].napi);
2638}
2639
2640static void port_napi_enable(struct ehea_port *port)
2641{
2642 int i;
2643
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002644 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002645 napi_enable(&port->port_res[i].napi);
2646}
2647
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002648static int ehea_open(struct net_device *dev)
2649{
2650 int ret;
2651 struct ehea_port *port = netdev_priv(dev);
2652
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002653 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002654
2655 if (netif_msg_ifup(port))
2656 ehea_info("enabling port %s", dev->name);
2657
2658 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002659 if (!ret) {
2660 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002661 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002662 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002663
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002664 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002665
2666 return ret;
2667}
2668
2669static int ehea_down(struct net_device *dev)
2670{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002671 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002672 struct ehea_port *port = netdev_priv(dev);
2673
2674 if (port->state == EHEA_PORT_DOWN)
2675 return 0;
2676
2677 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002678 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2679
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002680 ehea_free_interrupts(dev);
2681
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002682 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002683
Thomas Klein21eee2d2008-02-13 16:18:33 +01002684 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002685
Thomas Klein44c82152007-07-11 16:32:00 +02002686 ret = ehea_clean_all_portres(port);
2687 if (ret)
2688 ehea_info("Failed freeing resources for %s. ret=%i",
2689 dev->name, ret);
2690
Thomas Klein21eee2d2008-02-13 16:18:33 +01002691 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002692
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002693 return ret;
2694}
2695
2696static int ehea_stop(struct net_device *dev)
2697{
2698 int ret;
2699 struct ehea_port *port = netdev_priv(dev);
2700
2701 if (netif_msg_ifdown(port))
2702 ehea_info("disabling port %s", dev->name);
2703
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002704 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002705 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002706 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002707 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002708 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002709 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002710 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002711 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 return ret;
2713}
2714
Andrew Morton22559c52008-04-18 13:50:39 -07002715static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002716{
2717 struct ehea_qp qp = *orig_qp;
2718 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2719 struct ehea_swqe *swqe;
2720 int wqe_index;
2721 int i;
2722
2723 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2724 swqe = ehea_get_swqe(&qp, &wqe_index);
2725 swqe->tx_control |= EHEA_SWQE_PURGE;
2726 }
2727}
2728
Andrew Morton22559c52008-04-18 13:50:39 -07002729static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002730{
2731 int i;
2732
2733 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2734 struct ehea_port_res *pr = &port->port_res[i];
2735 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2736 int k = 0;
2737 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2738 msleep(5);
Andre Detsch2928db42010-08-17 05:49:12 +00002739 if (++k == 20) {
2740 ehea_error("WARNING: sq not flushed completely");
Thomas Klein44fb3122008-04-04 15:04:53 +02002741 break;
Andre Detsch2928db42010-08-17 05:49:12 +00002742 }
Thomas Klein44fb3122008-04-04 15:04:53 +02002743 }
2744 }
2745}
2746
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002747int ehea_stop_qps(struct net_device *dev)
2748{
2749 struct ehea_port *port = netdev_priv(dev);
2750 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002751 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002752 int ret = -EIO;
2753 int dret;
2754 int i;
2755 u64 hret;
2756 u64 dummy64 = 0;
2757 u16 dummy16 = 0;
2758
Thomas Klein3faf2692009-01-21 14:45:33 -08002759 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002760 if (!cb0) {
2761 ret = -ENOMEM;
2762 goto out;
2763 }
2764
2765 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2766 struct ehea_port_res *pr = &port->port_res[i];
2767 struct ehea_qp *qp = pr->qp;
2768
2769 /* Purge send queue */
2770 ehea_purge_sq(qp);
2771
2772 /* Disable queue pair */
2773 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2774 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2775 cb0);
2776 if (hret != H_SUCCESS) {
2777 ehea_error("query_ehea_qp failed (1)");
2778 goto out;
2779 }
2780
2781 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2782 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2783
2784 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2785 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2786 1), cb0, &dummy64,
2787 &dummy64, &dummy16, &dummy16);
2788 if (hret != H_SUCCESS) {
2789 ehea_error("modify_ehea_qp failed (1)");
2790 goto out;
2791 }
2792
2793 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2794 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2795 cb0);
2796 if (hret != H_SUCCESS) {
2797 ehea_error("query_ehea_qp failed (2)");
2798 goto out;
2799 }
2800
2801 /* deregister shared memory regions */
2802 dret = ehea_rem_smrs(pr);
2803 if (dret) {
2804 ehea_error("unreg shared memory region failed");
2805 goto out;
2806 }
2807 }
2808
2809 ret = 0;
2810out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002811 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002812
2813 return ret;
2814}
2815
Doug Maxey508d2b52008-01-31 20:20:49 -06002816void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002817{
2818 struct ehea_qp qp = *orig_qp;
2819 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2820 struct ehea_rwqe *rwqe;
2821 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2822 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2823 struct sk_buff *skb;
2824 u32 lkey = pr->recv_mr.lkey;
2825
2826
2827 int i;
2828 int index;
2829
2830 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2831 rwqe = ehea_get_next_rwqe(&qp, 2);
2832 rwqe->sg_list[0].l_key = lkey;
2833 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2834 skb = skba_rq2[index];
2835 if (skb)
2836 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2837 }
2838
2839 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2840 rwqe = ehea_get_next_rwqe(&qp, 3);
2841 rwqe->sg_list[0].l_key = lkey;
2842 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2843 skb = skba_rq3[index];
2844 if (skb)
2845 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2846 }
2847}
2848
2849int ehea_restart_qps(struct net_device *dev)
2850{
2851 struct ehea_port *port = netdev_priv(dev);
2852 struct ehea_adapter *adapter = port->adapter;
2853 int ret = 0;
2854 int i;
2855
Doug Maxey508d2b52008-01-31 20:20:49 -06002856 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002857 u64 hret;
2858 u64 dummy64 = 0;
2859 u16 dummy16 = 0;
2860
Thomas Klein3faf2692009-01-21 14:45:33 -08002861 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002862 if (!cb0) {
2863 ret = -ENOMEM;
2864 goto out;
2865 }
2866
2867 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2868 struct ehea_port_res *pr = &port->port_res[i];
2869 struct ehea_qp *qp = pr->qp;
2870
2871 ret = ehea_gen_smrs(pr);
2872 if (ret) {
2873 ehea_error("creation of shared memory regions failed");
2874 goto out;
2875 }
2876
2877 ehea_update_rqs(qp, pr);
2878
2879 /* Enable queue pair */
2880 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2881 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2882 cb0);
2883 if (hret != H_SUCCESS) {
2884 ehea_error("query_ehea_qp failed (1)");
2885 goto out;
2886 }
2887
2888 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2889 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2890
2891 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2892 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2893 1), cb0, &dummy64,
2894 &dummy64, &dummy16, &dummy16);
2895 if (hret != H_SUCCESS) {
2896 ehea_error("modify_ehea_qp failed (1)");
2897 goto out;
2898 }
2899
2900 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2901 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2902 cb0);
2903 if (hret != H_SUCCESS) {
2904 ehea_error("query_ehea_qp failed (2)");
2905 goto out;
2906 }
2907
2908 /* refill entire queue */
2909 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2910 ehea_refill_rq2(pr, 0);
2911 ehea_refill_rq3(pr, 0);
2912 }
2913out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002914 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002915
2916 return ret;
2917}
2918
David Howellsc4028952006-11-22 14:57:56 +00002919static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002920{
2921 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002922 struct ehea_port *port =
2923 container_of(work, struct ehea_port, reset_task);
2924 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002925
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002926 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002927 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002928 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002929 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002930
2931 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002932
Thomas Klein44c82152007-07-11 16:32:00 +02002933 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002934
2935 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002936 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002937 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002938
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002939 ehea_set_multicast_list(dev);
2940
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002941 if (netif_msg_timer(port))
2942 ehea_info("Device %s resetted successfully", dev->name);
2943
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002944 port_napi_enable(port);
2945
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002946 netif_wake_queue(dev);
2947out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002948 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002949 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002950}
2951
Thomas Klein44c82152007-07-11 16:32:00 +02002952static void ehea_rereg_mrs(struct work_struct *work)
2953{
2954 int ret, i;
2955 struct ehea_adapter *adapter;
2956
Hannes Heringd4f12da2008-10-16 11:36:42 +02002957 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002958
2959 list_for_each_entry(adapter, &adapter_list, list)
2960 if (adapter->active_ports) {
2961 /* Shutdown all ports */
2962 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2963 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002964 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002965
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002966 if (!port)
2967 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002968
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002969 dev = port->netdev;
2970
2971 if (dev->flags & IFF_UP) {
2972 mutex_lock(&port->port_lock);
2973 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002974 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002975 ret = ehea_stop_qps(dev);
2976 if (ret) {
2977 mutex_unlock(&port->port_lock);
2978 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002979 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002980 port_napi_disable(port);
2981 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002982 }
Andre Detsch2928db42010-08-17 05:49:12 +00002983 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002984 }
2985
2986 /* Unregister old memory region */
2987 ret = ehea_rem_mr(&adapter->mr);
2988 if (ret) {
2989 ehea_error("unregister MR failed - driver"
2990 " inoperable!");
2991 goto out;
2992 }
2993 }
2994
Thomas Klein44c82152007-07-11 16:32:00 +02002995 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2996
2997 list_for_each_entry(adapter, &adapter_list, list)
2998 if (adapter->active_ports) {
2999 /* Register new memory region */
3000 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3001 if (ret) {
3002 ehea_error("register MR failed - driver"
3003 " inoperable!");
3004 goto out;
3005 }
3006
3007 /* Restart all ports */
3008 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3009 struct ehea_port *port = adapter->port[i];
3010
3011 if (port) {
3012 struct net_device *dev = port->netdev;
3013
3014 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003015 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003016 port_napi_enable(port);
3017 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003018 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003019 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003020 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003021 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003022 }
3023 }
3024 }
3025 }
Julia Lawall68905eb2008-07-21 09:57:26 +02003026 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003027out:
3028 return;
3029}
3030
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003031static void ehea_tx_watchdog(struct net_device *dev)
3032{
3033 struct ehea_port *port = netdev_priv(dev);
3034
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003035 if (netif_carrier_ok(dev) &&
3036 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003037 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003038}
3039
3040int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3041{
3042 struct hcp_query_ehea *cb;
3043 u64 hret;
3044 int ret;
3045
Thomas Klein3faf2692009-01-21 14:45:33 -08003046 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003047 if (!cb) {
3048 ret = -ENOMEM;
3049 goto out;
3050 }
3051
3052 hret = ehea_h_query_ehea(adapter->handle, cb);
3053
3054 if (hret != H_SUCCESS) {
3055 ret = -EIO;
3056 goto out_herr;
3057 }
3058
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003059 adapter->max_mc_mac = cb->max_mc_mac - 1;
3060 ret = 0;
3061
3062out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003063 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003064out:
3065 return ret;
3066}
3067
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003068int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3069{
3070 struct hcp_ehea_port_cb4 *cb4;
3071 u64 hret;
3072 int ret = 0;
3073
3074 *jumbo = 0;
3075
3076 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003077 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003078 if (!cb4) {
3079 ehea_error("no mem for cb4");
3080 ret = -ENOMEM;
3081 goto out;
3082 } else {
3083 hret = ehea_h_query_ehea_port(port->adapter->handle,
3084 port->logical_port_id,
3085 H_PORT_CB4,
3086 H_PORT_CB4_JUMBO, cb4);
3087 if (hret == H_SUCCESS) {
3088 if (cb4->jumbo_frame)
3089 *jumbo = 1;
3090 else {
3091 cb4->jumbo_frame = 1;
3092 hret = ehea_h_modify_ehea_port(port->adapter->
3093 handle,
3094 port->
3095 logical_port_id,
3096 H_PORT_CB4,
3097 H_PORT_CB4_JUMBO,
3098 cb4);
3099 if (hret == H_SUCCESS)
3100 *jumbo = 1;
3101 }
3102 } else
3103 ret = -EINVAL;
3104
Thomas Klein3faf2692009-01-21 14:45:33 -08003105 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003106 }
3107out:
3108 return ret;
3109}
3110
3111static ssize_t ehea_show_port_id(struct device *dev,
3112 struct device_attribute *attr, char *buf)
3113{
3114 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003115 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116}
3117
3118static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3119 NULL);
3120
3121static void __devinit logical_port_release(struct device *dev)
3122{
3123 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003124 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003125}
3126
3127static struct device *ehea_register_port(struct ehea_port *port,
3128 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003129{
3130 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131
Grant Likely61c7a082010-04-13 16:12:29 -07003132 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003133 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003134 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003135
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003136 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003137 port->ofdev.dev.release = logical_port_release;
3138
3139 ret = of_device_register(&port->ofdev);
3140 if (ret) {
3141 ehea_error("failed to register device. ret=%d", ret);
3142 goto out;
3143 }
3144
3145 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003146 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003147 ehea_error("failed to register attributes, ret=%d", ret);
3148 goto out_unreg_of_dev;
3149 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003150
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003151 return &port->ofdev.dev;
3152
3153out_unreg_of_dev:
3154 of_device_unregister(&port->ofdev);
3155out:
3156 return NULL;
3157}
3158
3159static void ehea_unregister_port(struct ehea_port *port)
3160{
3161 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3162 of_device_unregister(&port->ofdev);
3163}
3164
Thomas Klein086c1b22009-01-21 14:43:59 -08003165static const struct net_device_ops ehea_netdev_ops = {
3166 .ndo_open = ehea_open,
3167 .ndo_stop = ehea_stop,
3168 .ndo_start_xmit = ehea_start_xmit,
3169#ifdef CONFIG_NET_POLL_CONTROLLER
3170 .ndo_poll_controller = ehea_netpoll,
3171#endif
3172 .ndo_get_stats = ehea_get_stats,
3173 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003174 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003175 .ndo_set_multicast_list = ehea_set_multicast_list,
3176 .ndo_change_mtu = ehea_change_mtu,
3177 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3178 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003179 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3180 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003181};
3182
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3184 u32 logical_port_id,
3185 struct device_node *dn)
3186{
3187 int ret;
3188 struct net_device *dev;
3189 struct ehea_port *port;
3190 struct device *port_dev;
3191 int jumbo;
3192
3193 /* allocate memory for the port structures */
3194 dev = alloc_etherdev(sizeof(struct ehea_port));
3195
3196 if (!dev) {
3197 ehea_error("no mem for net_device");
3198 ret = -ENOMEM;
3199 goto out_err;
3200 }
3201
3202 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003203
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003204 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003205 port->state = EHEA_PORT_DOWN;
3206 port->sig_comp_iv = sq_entries / 10;
3207
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003208 port->adapter = adapter;
3209 port->netdev = dev;
3210 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003211
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003212 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003213
3214 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3215 if (!port->mc_list) {
3216 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003217 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003218 }
3219
3220 INIT_LIST_HEAD(&port->mc_list->list);
3221
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003222 ret = ehea_sense_port_attr(port);
3223 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003224 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003225
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226 port_dev = ehea_register_port(port, dn);
3227 if (!port_dev)
3228 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003229
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003231
3232 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3234
Thomas Klein086c1b22009-01-21 14:43:59 -08003235 dev->netdev_ops = &ehea_netdev_ops;
3236 ehea_set_ethtool_ops(dev);
3237
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003239 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3241 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003242 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3243
David Howellsc4028952006-11-22 14:57:56 +00003244 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245
3246 ret = register_netdev(dev);
3247 if (ret) {
3248 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003249 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250 }
3251
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003252 port->lro_max_aggr = lro_max_aggr;
3253
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003254 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003255 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003256 ehea_error("failed determining jumbo frame status for %s",
3257 port->netdev->name);
3258
Thomas Klein9c750b72007-01-29 18:44:01 +01003259 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3260 jumbo == 1 ? "en" : "dis");
3261
Thomas Klein44c82152007-07-11 16:32:00 +02003262 adapter->active_ports++;
3263
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003264 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003266out_unreg_port:
3267 ehea_unregister_port(port);
3268
3269out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003271
3272out_free_ethdev:
3273 free_netdev(dev);
3274
3275out_err:
3276 ehea_error("setting up logical port with id=%d failed, ret=%d",
3277 logical_port_id, ret);
3278 return NULL;
3279}
3280
3281static void ehea_shutdown_single_port(struct ehea_port *port)
3282{
Brian King7fb1c2a2008-05-14 09:48:25 -05003283 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003284 unregister_netdev(port->netdev);
3285 ehea_unregister_port(port);
3286 kfree(port->mc_list);
3287 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003288 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003289}
3290
3291static int ehea_setup_ports(struct ehea_adapter *adapter)
3292{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003293 struct device_node *lhea_dn;
3294 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003295
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003296 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003297 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003298
Grant Likely61c7a082010-04-13 16:12:29 -07003299 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003300 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003301
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003302 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003303 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304 if (!dn_log_port_id) {
3305 ehea_error("bad device node: eth_dn name=%s",
3306 eth_dn->full_name);
3307 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003308 }
3309
Thomas Klein1211bb62007-04-26 11:56:43 +02003310 if (ehea_add_adapter_mr(adapter)) {
3311 ehea_error("creating MR failed");
3312 of_node_put(eth_dn);
3313 return -EIO;
3314 }
3315
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316 adapter->port[i] = ehea_setup_single_port(adapter,
3317 *dn_log_port_id,
3318 eth_dn);
3319 if (adapter->port[i])
3320 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003321 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003323 else
3324 ehea_remove_adapter_mr(adapter);
3325
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003326 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003327 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003328 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329}
3330
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003331static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3332 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333{
3334 struct device_node *lhea_dn;
3335 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003336 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003337
Grant Likely61c7a082010-04-13 16:12:29 -07003338 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003339 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003340
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003341 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003342 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343 if (dn_log_port_id)
3344 if (*dn_log_port_id == logical_port_id)
3345 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003346 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347
3348 return NULL;
3349}
3350
3351static ssize_t ehea_probe_port(struct device *dev,
3352 struct device_attribute *attr,
3353 const char *buf, size_t count)
3354{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003355 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003356 struct ehea_port *port;
3357 struct device_node *eth_dn = NULL;
3358 int i;
3359
3360 u32 logical_port_id;
3361
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003362 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003363
3364 port = ehea_get_port(adapter, logical_port_id);
3365
3366 if (port) {
3367 ehea_info("adding port with logical port id=%d failed. port "
3368 "already configured as %s.", logical_port_id,
3369 port->netdev->name);
3370 return -EINVAL;
3371 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003372
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3374
3375 if (!eth_dn) {
3376 ehea_info("no logical port with id %d found", logical_port_id);
3377 return -EINVAL;
3378 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003379
Thomas Klein1211bb62007-04-26 11:56:43 +02003380 if (ehea_add_adapter_mr(adapter)) {
3381 ehea_error("creating MR failed");
3382 return -EIO;
3383 }
3384
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003385 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3386
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003387 of_node_put(eth_dn);
3388
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003389 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003390 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003391 if (!adapter->port[i]) {
3392 adapter->port[i] = port;
3393 break;
3394 }
3395
3396 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3397 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003398 } else {
3399 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003400 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003401 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003402
3403 return (ssize_t) count;
3404}
3405
3406static ssize_t ehea_remove_port(struct device *dev,
3407 struct device_attribute *attr,
3408 const char *buf, size_t count)
3409{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003410 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003411 struct ehea_port *port;
3412 int i;
3413 u32 logical_port_id;
3414
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003415 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003416
3417 port = ehea_get_port(adapter, logical_port_id);
3418
3419 if (port) {
3420 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3421 logical_port_id);
3422
3423 ehea_shutdown_single_port(port);
3424
Doug Maxey508d2b52008-01-31 20:20:49 -06003425 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003426 if (adapter->port[i] == port) {
3427 adapter->port[i] = NULL;
3428 break;
3429 }
3430 } else {
3431 ehea_error("removing port with logical port id=%d failed. port "
3432 "not configured.", logical_port_id);
3433 return -EINVAL;
3434 }
3435
Thomas Klein1211bb62007-04-26 11:56:43 +02003436 ehea_remove_adapter_mr(adapter);
3437
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003438 return (ssize_t) count;
3439}
3440
3441static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3442static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3443
Grant Likely2dc11582010-08-06 09:25:50 -06003444int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003445{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003446 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003447 if (ret)
3448 goto out;
3449
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003450 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003452 return ret;
3453}
3454
Grant Likely2dc11582010-08-06 09:25:50 -06003455void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003456{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003457 device_remove_file(&dev->dev, &dev_attr_probe_port);
3458 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003459}
3460
Grant Likely2dc11582010-08-06 09:25:50 -06003461static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003462 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003463{
3464 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003465 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 int ret;
3467
Grant Likely61c7a082010-04-13 16:12:29 -07003468 if (!dev || !dev->dev.of_node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003469 ehea_error("Invalid ibmebus device probed");
3470 return -EINVAL;
3471 }
3472
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3474 if (!adapter) {
3475 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003476 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003477 goto out;
3478 }
3479
Thomas Klein44c82152007-07-11 16:32:00 +02003480 list_add(&adapter->list, &adapter_list);
3481
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003482 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003483
Grant Likely61c7a082010-04-13 16:12:29 -07003484 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003485 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003486 if (adapter_handle)
3487 adapter->handle = *adapter_handle;
3488
3489 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003490 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003491 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492 ret = -ENODEV;
3493 goto out_free_ad;
3494 }
3495
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496 adapter->pd = EHEA_PD_ID;
3497
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003498 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003500
3501 /* initialize adapter and ports */
3502 /* get adapter properties */
3503 ret = ehea_sense_adapter_attr(adapter);
3504 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003505 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003506 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003507 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003508
3509 adapter->neq = ehea_create_eq(adapter,
3510 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3511 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003512 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003513 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003514 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003515 }
3516
3517 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3518 (unsigned long)adapter);
3519
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003520 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003521 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003522 "ehea_neq", adapter);
3523 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003524 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003525 goto out_kill_eq;
3526 }
3527
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003528 ret = ehea_create_device_sysfs(dev);
3529 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003530 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003531
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 ret = ehea_setup_ports(adapter);
3533 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003534 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003535 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003536 }
3537
3538 ret = 0;
3539 goto out;
3540
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003541out_rem_dev_sysfs:
3542 ehea_remove_device_sysfs(dev);
3543
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003544out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003545 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546
3547out_kill_eq:
3548 ehea_destroy_eq(adapter->neq);
3549
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003551 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003552 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003553
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003554out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003555 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003556
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 return ret;
3558}
3559
Grant Likely2dc11582010-08-06 09:25:50 -06003560static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003562 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003563 int i;
3564
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003565 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003566 if (adapter->port[i]) {
3567 ehea_shutdown_single_port(adapter->port[i]);
3568 adapter->port[i] = NULL;
3569 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003570
3571 ehea_remove_device_sysfs(dev);
3572
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003573 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003575 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003576 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577
3578 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003579 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003580 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003582
Thomas Klein21eee2d2008-02-13 16:18:33 +01003583 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003585 return 0;
3586}
3587
Thomas Klein21eee2d2008-02-13 16:18:33 +01003588void ehea_crash_handler(void)
3589{
3590 int i;
3591
3592 if (ehea_fw_handles.arr)
3593 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3594 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3595 ehea_fw_handles.arr[i].fwh,
3596 FORCE_FREE);
3597
3598 if (ehea_bcmc_regs.arr)
3599 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3600 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3601 ehea_bcmc_regs.arr[i].port_id,
3602 ehea_bcmc_regs.arr[i].reg_type,
3603 ehea_bcmc_regs.arr[i].macaddr,
3604 0, H_DEREG_BCMC);
3605}
3606
Hannes Hering48cfb142008-05-07 14:43:36 +02003607static int ehea_mem_notifier(struct notifier_block *nb,
3608 unsigned long action, void *data)
3609{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003610 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003611 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003612
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003613 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003614
Hannes Hering48cfb142008-05-07 14:43:36 +02003615 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003616 case MEM_CANCEL_OFFLINE:
3617 ehea_info("memory offlining canceled");
3618 /* Readd canceled memory block */
3619 case MEM_ONLINE:
3620 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003621 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003622 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003623 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003624 ehea_rereg_mrs(NULL);
3625 break;
3626 case MEM_GOING_OFFLINE:
3627 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003628 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003629 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003630 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003631 ehea_rereg_mrs(NULL);
3632 break;
3633 default:
3634 break;
3635 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003636
3637 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003638 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003639
Thomas Kleina7c561f22010-04-20 23:11:31 +00003640out_unlock:
3641 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003642 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003643}
3644
3645static struct notifier_block ehea_mem_nb = {
3646 .notifier_call = ehea_mem_notifier,
3647};
3648
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003649static int ehea_reboot_notifier(struct notifier_block *nb,
3650 unsigned long action, void *unused)
3651{
3652 if (action == SYS_RESTART) {
3653 ehea_info("Reboot: freeing all eHEA resources");
3654 ibmebus_unregister_driver(&ehea_driver);
3655 }
3656 return NOTIFY_DONE;
3657}
3658
3659static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003660 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003661};
3662
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003663static int check_module_parm(void)
3664{
3665 int ret = 0;
3666
3667 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3668 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3669 ehea_info("Bad parameter: rq1_entries");
3670 ret = -EINVAL;
3671 }
3672 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3673 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3674 ehea_info("Bad parameter: rq2_entries");
3675 ret = -EINVAL;
3676 }
3677 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3678 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3679 ehea_info("Bad parameter: rq3_entries");
3680 ret = -EINVAL;
3681 }
3682 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3683 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3684 ehea_info("Bad parameter: sq_entries");
3685 ret = -EINVAL;
3686 }
3687
3688 return ret;
3689}
3690
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003691static ssize_t ehea_show_capabilities(struct device_driver *drv,
3692 char *buf)
3693{
3694 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3695}
3696
3697static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3698 ehea_show_capabilities, NULL);
3699
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003700int __init ehea_module_init(void)
3701{
3702 int ret;
3703
3704 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3705 DRV_VERSION);
3706
Thomas Klein44c82152007-07-11 16:32:00 +02003707
3708 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003709 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3710 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3711
Daniel Walker9f71a562008-03-28 14:41:26 -07003712 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003713 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003714
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003715 ret = check_module_parm();
3716 if (ret)
3717 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003718
3719 ret = ehea_create_busmap();
3720 if (ret)
3721 goto out;
3722
Thomas Klein21eee2d2008-02-13 16:18:33 +01003723 ret = register_reboot_notifier(&ehea_reboot_nb);
3724 if (ret)
3725 ehea_info("failed registering reboot notifier");
3726
Hannes Hering48cfb142008-05-07 14:43:36 +02003727 ret = register_memory_notifier(&ehea_mem_nb);
3728 if (ret)
3729 ehea_info("failed registering memory remove notifier");
3730
Thomas Klein21eee2d2008-02-13 16:18:33 +01003731 ret = crash_shutdown_register(&ehea_crash_handler);
3732 if (ret)
3733 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003734
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003735 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003736 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003737 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003738 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003739 }
3740
3741 ret = driver_create_file(&ehea_driver.driver,
3742 &driver_attr_capabilities);
3743 if (ret) {
3744 ehea_error("failed to register capabilities attribute, ret=%d",
3745 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003746 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003747 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003748
Thomas Klein21eee2d2008-02-13 16:18:33 +01003749 return ret;
3750
3751out3:
3752 ibmebus_unregister_driver(&ehea_driver);
3753out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003754 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003755 unregister_reboot_notifier(&ehea_reboot_nb);
3756 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003757out:
3758 return ret;
3759}
3760
3761static void __exit ehea_module_exit(void)
3762{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003763 int ret;
3764
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003765 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003766 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003767 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003768 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003769 ret = crash_shutdown_unregister(&ehea_crash_handler);
3770 if (ret)
3771 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003772 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003773 kfree(ehea_fw_handles.arr);
3774 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003775 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003776}
3777
3778module_init(ehea_module_init);
3779module_exit(ehea_module_exit);