blob: 49ba6a9a7b06116e4fea8adf02108cd7a07986c4 [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>
35#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020036#include <linux/notifier.h>
37#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020038#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010039#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070040#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020041
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020042#include <net/ip.h>
43
44#include "ehea.h"
45#include "ehea_qmr.h"
46#include "ehea_phyp.h"
47
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51MODULE_DESCRIPTION("IBM eServer HEA Driver");
52MODULE_VERSION(DRV_VERSION);
53
54
55static int msg_level = -1;
56static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
57static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
58static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
59static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060060static int use_mcs;
61static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070062static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010063static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060064static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020065
66module_param(msg_level, int, 0);
67module_param(rq1_entries, int, 0);
68module_param(rq2_entries, int, 0);
69module_param(rq3_entries, int, 0);
70module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020071module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010072module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070073module_param(use_lro, int, 0);
74module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010077MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020079MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
84MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
87MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
90MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020093MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020094
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070095MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
97MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
98 "Default = 0");
99
Doug Maxey508d2b52008-01-31 20:20:49 -0600100static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200101static LIST_HEAD(adapter_list);
Doug Maxey508d2b52008-01-31 20:20:49 -0600102u64 ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200103struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700104static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100105struct ehea_fw_handle_array ehea_fw_handles;
106struct ehea_bcmc_reg_array ehea_bcmc_regs;
107
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000109static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200110 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000112static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
114static struct of_device_id ehea_device_table[] = {
115 {
116 .name = "lhea",
117 .compatible = "IBM,lhea",
118 },
119 {},
120};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100121MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200122
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200124 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000125 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200126 .probe = ehea_probe_adapter,
127 .remove = ehea_remove,
128};
129
Doug Maxey508d2b52008-01-31 20:20:49 -0600130void ehea_dump(void *adr, int len, char *msg)
131{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 int x;
133 unsigned char *deb = adr;
134 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100135 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600136 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200137 deb += 16;
138 }
139}
140
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100141void ehea_schedule_port_reset(struct ehea_port *port)
142{
143 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
144 schedule_work(&port->reset_task);
145}
146
Thomas Klein21eee2d2008-02-13 16:18:33 +0100147static void ehea_update_firmware_handles(void)
148{
149 struct ehea_fw_handle_entry *arr = NULL;
150 struct ehea_adapter *adapter;
151 int num_adapters = 0;
152 int num_ports = 0;
153 int num_portres = 0;
154 int i = 0;
155 int num_fw_handles, k, l;
156
157 /* Determine number of handles */
158 list_for_each_entry(adapter, &adapter_list, list) {
159 num_adapters++;
160
161 for (k = 0; k < EHEA_MAX_PORTS; k++) {
162 struct ehea_port *port = adapter->port[k];
163
164 if (!port || (port->state != EHEA_PORT_UP))
165 continue;
166
167 num_ports++;
168 num_portres += port->num_def_qps + port->num_add_tx_qps;
169 }
170 }
171
172 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
173 num_ports * EHEA_NUM_PORT_FW_HANDLES +
174 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
175
176 if (num_fw_handles) {
177 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
178 if (!arr)
179 return; /* Keep the existing array */
180 } else
181 goto out_update;
182
183 list_for_each_entry(adapter, &adapter_list, list) {
184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
187 if (!port || (port->state != EHEA_PORT_UP))
188 continue;
189
190 for (l = 0;
191 l < port->num_def_qps + port->num_add_tx_qps;
192 l++) {
193 struct ehea_port_res *pr = &port->port_res[l];
194
195 arr[i].adh = adapter->handle;
196 arr[i++].fwh = pr->qp->fw_handle;
197 arr[i].adh = adapter->handle;
198 arr[i++].fwh = pr->send_cq->fw_handle;
199 arr[i].adh = adapter->handle;
200 arr[i++].fwh = pr->recv_cq->fw_handle;
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = pr->eq->fw_handle;
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = pr->send_mr.handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->recv_mr.handle;
207 }
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = port->qp_eq->fw_handle;
210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
219 }
220
221out_update:
222 kfree(ehea_fw_handles.arr);
223 ehea_fw_handles.arr = arr;
224 ehea_fw_handles.num_entries = i;
225}
226
227static void ehea_update_bcmc_registrations(void)
228{
229 struct ehea_bcmc_reg_entry *arr = NULL;
230 struct ehea_adapter *adapter;
231 struct ehea_mc_list *mc_entry;
232 int num_registrations = 0;
233 int i = 0;
234 int k;
235
236 /* Determine number of registrations */
237 list_for_each_entry(adapter, &adapter_list, list)
238 for (k = 0; k < EHEA_MAX_PORTS; k++) {
239 struct ehea_port *port = adapter->port[k];
240
241 if (!port || (port->state != EHEA_PORT_UP))
242 continue;
243
244 num_registrations += 2; /* Broadcast registrations */
245
246 list_for_each_entry(mc_entry, &port->mc_list->list,list)
247 num_registrations += 2;
248 }
249
250 if (num_registrations) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100251 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100252 if (!arr)
253 return; /* Keep the existing array */
254 } else
255 goto out_update;
256
257 list_for_each_entry(adapter, &adapter_list, list) {
258 for (k = 0; k < EHEA_MAX_PORTS; k++) {
259 struct ehea_port *port = adapter->port[k];
260
261 if (!port || (port->state != EHEA_PORT_UP))
262 continue;
263
264 arr[i].adh = adapter->handle;
265 arr[i].port_id = port->logical_port_id;
266 arr[i].reg_type = EHEA_BCMC_BROADCAST |
267 EHEA_BCMC_UNTAGGED;
268 arr[i++].macaddr = port->mac_addr;
269
270 arr[i].adh = adapter->handle;
271 arr[i].port_id = port->logical_port_id;
272 arr[i].reg_type = EHEA_BCMC_BROADCAST |
273 EHEA_BCMC_VLANID_ALL;
274 arr[i++].macaddr = port->mac_addr;
275
276 list_for_each_entry(mc_entry,
277 &port->mc_list->list, list) {
278 arr[i].adh = adapter->handle;
279 arr[i].port_id = port->logical_port_id;
280 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
281 EHEA_BCMC_MULTICAST |
282 EHEA_BCMC_UNTAGGED;
283 arr[i++].macaddr = mc_entry->macaddr;
284
285 arr[i].adh = adapter->handle;
286 arr[i].port_id = port->logical_port_id;
287 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
288 EHEA_BCMC_MULTICAST |
289 EHEA_BCMC_VLANID_ALL;
290 arr[i++].macaddr = mc_entry->macaddr;
291 }
292 }
293 }
294
295out_update:
296 kfree(ehea_bcmc_regs.arr);
297 ehea_bcmc_regs.arr = arr;
298 ehea_bcmc_regs.num_entries = i;
299}
300
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200301static struct net_device_stats *ehea_get_stats(struct net_device *dev)
302{
303 struct ehea_port *port = netdev_priv(dev);
304 struct net_device_stats *stats = &port->stats;
305 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100306 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200307 int i;
308
309 memset(stats, 0, sizeof(*stats));
310
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100311 cb2 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200312 if (!cb2) {
313 ehea_error("no mem for cb2");
314 goto out;
315 }
316
317 hret = ehea_h_query_ehea_port(port->adapter->handle,
318 port->logical_port_id,
319 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
320 if (hret != H_SUCCESS) {
321 ehea_error("query_ehea_port failed");
322 goto out_herr;
323 }
324
325 if (netif_msg_hw(port))
326 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
327
328 rx_packets = 0;
329 for (i = 0; i < port->num_def_qps; i++)
330 rx_packets += port->port_res[i].rx_packets;
331
Thomas Klein7393b872007-11-21 17:37:58 +0100332 tx_packets = 0;
333 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
334 tx_packets += port->port_res[i].tx_packets;
335
336 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200337 stats->multicast = cb2->rxmcp;
338 stats->rx_errors = cb2->rxuerr;
339 stats->rx_bytes = cb2->rxo;
340 stats->tx_bytes = cb2->txo;
341 stats->rx_packets = rx_packets;
342
343out_herr:
344 kfree(cb2);
345out:
346 return stats;
347}
348
349static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
350{
351 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
352 struct net_device *dev = pr->port->netdev;
353 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200354 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
355 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 int i;
357
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200358 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200360 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200361 if (nr_of_wqes > 0)
362 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200363 pr->rq1_skba.os_skbs = fill_wqes;
364 return;
365 }
366
367 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368 if (!skb_arr_rq1[index]) {
369 skb_arr_rq1[index] = netdev_alloc_skb(dev,
370 EHEA_L_PKT_SIZE);
371 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200372 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200373 ehea_error("%s: no mem for skb/%d wqes filled",
374 dev->name, i);
375 break;
376 }
377 }
378 index--;
379 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200380 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200381 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200382
383 if (adder == 0)
384 return;
385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200386 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200388}
389
390static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
391{
392 int ret = 0;
393 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
394 struct net_device *dev = pr->port->netdev;
395 int i;
396
397 for (i = 0; i < pr->rq1_skba.len; i++) {
398 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
399 if (!skb_arr_rq1[i]) {
400 ehea_error("%s: no mem for skb/%d wqes filled",
401 dev->name, i);
402 ret = -ENOMEM;
403 goto out;
404 }
405 }
406 /* Ring doorbell */
407 ehea_update_rq1a(pr->qp, nr_rq1a);
408out:
409 return ret;
410}
411
412static int ehea_refill_rq_def(struct ehea_port_res *pr,
413 struct ehea_q_skb_arr *q_skba, int rq_nr,
414 int num_wqes, int wqe_type, int packet_size)
415{
416 struct net_device *dev = pr->port->netdev;
417 struct ehea_qp *qp = pr->qp;
418 struct sk_buff **skb_arr = q_skba->arr;
419 struct ehea_rwqe *rwqe;
420 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200421 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 int ret = 0;
423
424 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200425 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200426
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200427 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
428 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200430 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431
432 index = q_skba->index;
433 max_index_mask = q_skba->len - 1;
434 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200435 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
437 if (!skb) {
438 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100439 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440 q_skba->os_skbs = fill_wqes - i;
441 ret = -ENOMEM;
442 break;
443 }
444 skb_reserve(skb, NET_IP_ALIGN);
445
446 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200447 tmp_addr = ehea_map_vaddr(skb->data);
448 if (tmp_addr == -1) {
449 dev_kfree_skb(skb);
450 q_skba->os_skbs = fill_wqes - i;
451 ret = 0;
452 break;
453 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454
455 rwqe = ehea_get_next_rwqe(qp, rq_nr);
456 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200457 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460 rwqe->sg_list[0].len = packet_size;
461 rwqe->data_segments = 1;
462
463 index++;
464 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200466 }
Thomas Klein44c82152007-07-11 16:32:00 +0200467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200469 if (adder == 0)
470 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471
472 /* Ring doorbell */
473 iosync();
474 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200475 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200477 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200478out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 return ret;
480}
481
482
483static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
484{
485 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
486 nr_of_wqes, EHEA_RWQE2_TYPE,
487 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
488}
489
490
491static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
492{
493 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
494 nr_of_wqes, EHEA_RWQE3_TYPE,
495 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
496}
497
498static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
499{
500 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
501 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
502 return 0;
503 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
504 (cqe->header_length == 0))
505 return 0;
506 return -EINVAL;
507}
508
509static inline void ehea_fill_skb(struct net_device *dev,
510 struct sk_buff *skb, struct ehea_cqe *cqe)
511{
512 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
513
514 skb_put(skb, length);
515 skb->ip_summed = CHECKSUM_UNNECESSARY;
516 skb->protocol = eth_type_trans(skb, dev);
517}
518
519static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
520 int arr_len,
521 struct ehea_cqe *cqe)
522{
523 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
524 struct sk_buff *skb;
525 void *pref;
526 int x;
527
528 x = skb_index + 1;
529 x &= (arr_len - 1);
530
531 pref = skb_array[x];
532 prefetchw(pref);
533 prefetchw(pref + EHEA_CACHE_LINE);
534
535 pref = (skb_array[x]->data);
536 prefetch(pref);
537 prefetch(pref + EHEA_CACHE_LINE);
538 prefetch(pref + EHEA_CACHE_LINE * 2);
539 prefetch(pref + EHEA_CACHE_LINE * 3);
540 skb = skb_array[skb_index];
541 skb_array[skb_index] = NULL;
542 return skb;
543}
544
545static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
546 int arr_len, int wqe_index)
547{
548 struct sk_buff *skb;
549 void *pref;
550 int x;
551
552 x = wqe_index + 1;
553 x &= (arr_len - 1);
554
555 pref = skb_array[x];
556 prefetchw(pref);
557 prefetchw(pref + EHEA_CACHE_LINE);
558
559 pref = (skb_array[x]->data);
560 prefetchw(pref);
561 prefetchw(pref + EHEA_CACHE_LINE);
562
563 skb = skb_array[wqe_index];
564 skb_array[wqe_index] = NULL;
565 return skb;
566}
567
568static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
569 struct ehea_cqe *cqe, int *processed_rq2,
570 int *processed_rq3)
571{
572 struct sk_buff *skb;
573
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100574 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
575 pr->p_stats.err_tcp_cksum++;
576 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
577 pr->p_stats.err_ip_cksum++;
578 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
579 pr->p_stats.err_frame_crc++;
580
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200581 if (rq == 2) {
582 *processed_rq2 += 1;
583 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
584 dev_kfree_skb(skb);
585 } else if (rq == 3) {
586 *processed_rq3 += 1;
587 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
588 dev_kfree_skb(skb);
589 }
590
591 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100592 if (netif_msg_rx_err(pr->port)) {
593 ehea_error("Critical receive error for QP %d. "
594 "Resetting port.", pr->qp->init_attr.qp_nr);
595 ehea_dump(cqe, sizeof(*cqe), "CQE");
596 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100597 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200598 return 1;
599 }
600
601 return 0;
602}
603
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700604static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
605 void **tcph, u64 *hdr_flags, void *priv)
606{
607 struct ehea_cqe *cqe = priv;
608 unsigned int ip_len;
609 struct iphdr *iph;
610
611 /* non tcp/udp packets */
612 if (!cqe->header_length)
613 return -1;
614
615 /* non tcp packet */
616 skb_reset_network_header(skb);
617 iph = ip_hdr(skb);
618 if (iph->protocol != IPPROTO_TCP)
619 return -1;
620
621 ip_len = ip_hdrlen(skb);
622 skb_set_transport_header(skb, ip_len);
623 *tcph = tcp_hdr(skb);
624
625 /* check if ip header and tcp header are complete */
626 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
627 return -1;
628
629 *hdr_flags = LRO_IPV4 | LRO_TCP;
630 *iphdr = iph;
631
632 return 0;
633}
634
635static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
636 struct sk_buff *skb)
637{
638 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
639 && pr->port->vgrp;
640
641 if (use_lro) {
642 if (vlan_extracted)
643 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
644 pr->port->vgrp,
645 cqe->vlan_tag,
646 cqe);
647 else
648 lro_receive_skb(&pr->lro_mgr, skb, cqe);
649 } else {
650 if (vlan_extracted)
651 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
652 cqe->vlan_tag);
653 else
654 netif_receive_skb(skb);
655 }
656}
657
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700658static int ehea_proc_rwqes(struct net_device *dev,
659 struct ehea_port_res *pr,
660 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200661{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100662 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200663 struct ehea_qp *qp = pr->qp;
664 struct ehea_cqe *cqe;
665 struct sk_buff *skb;
666 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
667 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
668 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
669 int skb_arr_rq1_len = pr->rq1_skba.len;
670 int skb_arr_rq2_len = pr->rq2_skba.len;
671 int skb_arr_rq3_len = pr->rq3_skba.len;
672 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700673 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200674
675 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
676 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200677
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200678 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700679 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200680 ehea_inc_rq1(qp);
681 processed_rq1++;
682 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200683 if (netif_msg_rx_status(port))
684 ehea_dump(cqe, sizeof(*cqe), "CQE");
685
686 last_wqe_index = wqe_index;
687 rmb();
688 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600689 if (rq == 1) {
690 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200691 skb = get_skb_by_index_ll(skb_arr_rq1,
692 skb_arr_rq1_len,
693 wqe_index);
694 if (unlikely(!skb)) {
695 if (netif_msg_rx_err(port))
696 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100697
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700698 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200699 EHEA_L_PKT_SIZE);
700 if (!skb)
701 break;
702 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600703 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200704 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700705 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600706 } else if (rq == 2) {
707 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 skb = get_skb_by_index(skb_arr_rq2,
709 skb_arr_rq2_len, cqe);
710 if (unlikely(!skb)) {
711 if (netif_msg_rx_err(port))
712 ehea_error("rq2: skb=NULL");
713 break;
714 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700715 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600717 } else {
718 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 skb = get_skb_by_index(skb_arr_rq3,
720 skb_arr_rq3_len, cqe);
721 if (unlikely(!skb)) {
722 if (netif_msg_rx_err(port))
723 ehea_error("rq3: skb=NULL");
724 break;
725 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700726 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727 processed_rq3++;
728 }
729
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700730 ehea_proc_skb(pr, cqe, skb);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700731 dev->last_rx = jiffies;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100732 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100733 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 port_reset = ehea_treat_poll_error(pr, rq, cqe,
735 &processed_rq2,
736 &processed_rq3);
737 if (port_reset)
738 break;
739 }
740 cqe = ehea_poll_rq1(qp, &wqe_index);
741 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700742 if (use_lro)
743 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200744
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 pr->rx_packets += processed;
746
747 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
748 ehea_refill_rq2(pr, processed_rq2);
749 ehea_refill_rq3(pr, processed_rq3);
750
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700751 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200752}
753
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100754static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100756 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200757 struct ehea_cq *send_cq = pr->send_cq;
758 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100759 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 int cqe_counter = 0;
761 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100762 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763 unsigned long flags;
764
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100765 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600766 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100767 ehea_inc_cq(send_cq);
768
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200769 cqe_counter++;
770 rmb();
771 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
772 ehea_error("Send Completion Error: Resetting port");
773 if (netif_msg_tx_err(pr->port))
774 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100775 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200776 break;
777 }
778
779 if (netif_msg_tx_done(pr->port))
780 ehea_dump(cqe, sizeof(*cqe), "CQE");
781
782 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100783 == EHEA_SWQE2_TYPE)) {
784
785 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
786 skb = pr->sq_skba.arr[index];
787 dev_kfree_skb(skb);
788 pr->sq_skba.arr[index] = NULL;
789 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200790
791 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
792 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100793
794 cqe = ehea_poll_cq(send_cq);
795 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200796
797 ehea_update_feca(send_cq, cqe_counter);
798 atomic_add(swqe_av, &pr->swqe_avail);
799
800 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100801
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200802 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
803 >= pr->swqe_refill_th)) {
804 netif_wake_queue(pr->port->netdev);
805 pr->queue_stopped = 0;
806 }
807 spin_unlock_irqrestore(&pr->netif_queue, flags);
808
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100809 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200810}
811
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100812#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700813#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100814
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700815static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816{
Doug Maxey508d2b52008-01-31 20:20:49 -0600817 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
818 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700819 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100820 struct ehea_cqe *cqe;
821 struct ehea_cqe *cqe_skb = NULL;
822 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700823 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100824
825 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700826 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100827
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700828 if (!force_irq)
829 rx += ehea_proc_rwqes(dev, pr, budget - rx);
830
831 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100832 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700833 force_irq = 0;
834 netif_rx_complete(dev, napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100835 ehea_reset_cq_ep(pr->recv_cq);
836 ehea_reset_cq_ep(pr->send_cq);
837 ehea_reset_cq_n1(pr->recv_cq);
838 ehea_reset_cq_n1(pr->send_cq);
839 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
840 cqe_skb = ehea_poll_cq(pr->send_cq);
841
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100842 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700843 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100844
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700845 if (!netif_rx_reschedule(dev, napi))
846 return rx;
847
848 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
849 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100850 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100851
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700852 pr->poll_counter++;
853 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200854}
855
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200856#ifdef CONFIG_NET_POLL_CONTROLLER
857static void ehea_netpoll(struct net_device *dev)
858{
859 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700860 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200861
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700862 for (i = 0; i < port->num_def_qps; i++)
863 netif_rx_schedule(dev, &port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200864}
865#endif
866
David Howells7d12e782006-10-05 14:55:46 +0100867static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868{
869 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100870
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700871 netif_rx_schedule(pr->port->netdev, &pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100872
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200873 return IRQ_HANDLED;
874}
875
David Howells7d12e782006-10-05 14:55:46 +0100876static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877{
878 struct ehea_port *port = param;
879 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100880 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200881 u32 qp_token;
882
883 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100884
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200885 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200886 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100887 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
888 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100889
890 qp = port->port_res[qp_token].qp;
891 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100892 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200893 }
894
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100895 ehea_schedule_port_reset(port);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100896
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200897 return IRQ_HANDLED;
898}
899
900static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
901 int logical_port)
902{
903 int i;
904
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100905 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100906 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200907 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100908 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200909 return NULL;
910}
911
912int ehea_sense_port_attr(struct ehea_port *port)
913{
914 int ret;
915 u64 hret;
916 struct hcp_ehea_port_cb0 *cb0;
917
Doug Maxey508d2b52008-01-31 20:20:49 -0600918 /* may be called via ehea_neq_tasklet() */
919 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
920 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200921 ehea_error("no mem for cb0");
922 ret = -ENOMEM;
923 goto out;
924 }
925
926 hret = ehea_h_query_ehea_port(port->adapter->handle,
927 port->logical_port_id, H_PORT_CB0,
928 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
929 cb0);
930 if (hret != H_SUCCESS) {
931 ret = -EIO;
932 goto out_free;
933 }
934
935 /* MAC address */
936 port->mac_addr = cb0->port_mac_addr << 16;
937
Doug Maxey508d2b52008-01-31 20:20:49 -0600938 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200939 ret = -EADDRNOTAVAIL;
940 goto out_free;
941 }
942
943 /* Port speed */
944 switch (cb0->port_speed) {
945 case H_SPEED_10M_H:
946 port->port_speed = EHEA_SPEED_10M;
947 port->full_duplex = 0;
948 break;
949 case H_SPEED_10M_F:
950 port->port_speed = EHEA_SPEED_10M;
951 port->full_duplex = 1;
952 break;
953 case H_SPEED_100M_H:
954 port->port_speed = EHEA_SPEED_100M;
955 port->full_duplex = 0;
956 break;
957 case H_SPEED_100M_F:
958 port->port_speed = EHEA_SPEED_100M;
959 port->full_duplex = 1;
960 break;
961 case H_SPEED_1G_F:
962 port->port_speed = EHEA_SPEED_1G;
963 port->full_duplex = 1;
964 break;
965 case H_SPEED_10G_F:
966 port->port_speed = EHEA_SPEED_10G;
967 port->full_duplex = 1;
968 break;
969 default:
970 port->port_speed = 0;
971 port->full_duplex = 0;
972 break;
973 }
974
Thomas Kleine919b592007-01-22 12:53:20 +0100975 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100976 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100977
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200978 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100979 if (use_mcs)
980 port->num_def_qps = cb0->num_default_qps;
981 else
982 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983
984 if (!port->num_def_qps) {
985 ret = -EINVAL;
986 goto out_free;
987 }
988
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100989 port->num_tx_qps = num_tx_qps;
990
991 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 port->num_add_tx_qps = 0;
993 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100994 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200995
996 ret = 0;
997out_free:
998 if (ret || netif_msg_probe(port))
999 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
1000 kfree(cb0);
1001out:
1002 return ret;
1003}
1004
1005int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1006{
1007 struct hcp_ehea_port_cb4 *cb4;
1008 u64 hret;
1009 int ret = 0;
1010
Thomas Kleina1d261c2006-11-03 17:48:23 +01001011 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001012 if (!cb4) {
1013 ehea_error("no mem for cb4");
1014 ret = -ENOMEM;
1015 goto out;
1016 }
1017
1018 cb4->port_speed = port_speed;
1019
1020 netif_carrier_off(port->netdev);
1021
1022 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1023 port->logical_port_id,
1024 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1025 if (hret == H_SUCCESS) {
1026 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1027
1028 hret = ehea_h_query_ehea_port(port->adapter->handle,
1029 port->logical_port_id,
1030 H_PORT_CB4, H_PORT_CB4_SPEED,
1031 cb4);
1032 if (hret == H_SUCCESS) {
1033 switch (cb4->port_speed) {
1034 case H_SPEED_10M_H:
1035 port->port_speed = EHEA_SPEED_10M;
1036 port->full_duplex = 0;
1037 break;
1038 case H_SPEED_10M_F:
1039 port->port_speed = EHEA_SPEED_10M;
1040 port->full_duplex = 1;
1041 break;
1042 case H_SPEED_100M_H:
1043 port->port_speed = EHEA_SPEED_100M;
1044 port->full_duplex = 0;
1045 break;
1046 case H_SPEED_100M_F:
1047 port->port_speed = EHEA_SPEED_100M;
1048 port->full_duplex = 1;
1049 break;
1050 case H_SPEED_1G_F:
1051 port->port_speed = EHEA_SPEED_1G;
1052 port->full_duplex = 1;
1053 break;
1054 case H_SPEED_10G_F:
1055 port->port_speed = EHEA_SPEED_10G;
1056 port->full_duplex = 1;
1057 break;
1058 default:
1059 port->port_speed = 0;
1060 port->full_duplex = 0;
1061 break;
1062 }
1063 } else {
1064 ehea_error("Failed sensing port speed");
1065 ret = -EIO;
1066 }
1067 } else {
1068 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001069 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001070 ret = -EPERM;
1071 } else {
1072 ret = -EIO;
1073 ehea_error("Failed setting port speed");
1074 }
1075 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001076 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1077 netif_carrier_on(port->netdev);
1078
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001079 kfree(cb4);
1080out:
1081 return ret;
1082}
1083
1084static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1085{
1086 int ret;
1087 u8 ec;
1088 u8 portnum;
1089 struct ehea_port *port;
1090
1091 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1092 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1093 port = ehea_get_port(adapter, portnum);
1094
1095 switch (ec) {
1096 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1097
1098 if (!port) {
1099 ehea_error("unknown portnum %x", portnum);
1100 break;
1101 }
1102
1103 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1104 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001105 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001106 if (ret) {
1107 ehea_error("failed resensing port "
1108 "attributes");
1109 break;
1110 }
1111
1112 if (netif_msg_link(port))
1113 ehea_info("%s: Logical port up: %dMbps "
1114 "%s Duplex",
1115 port->netdev->name,
1116 port->port_speed,
1117 port->full_duplex ==
1118 1 ? "Full" : "Half");
1119
1120 netif_carrier_on(port->netdev);
1121 netif_wake_queue(port->netdev);
1122 }
1123 } else
1124 if (netif_carrier_ok(port->netdev)) {
1125 if (netif_msg_link(port))
1126 ehea_info("%s: Logical port down",
1127 port->netdev->name);
1128 netif_carrier_off(port->netdev);
1129 netif_stop_queue(port->netdev);
1130 }
1131
1132 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001133 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 if (netif_msg_link(port))
1135 ehea_info("%s: Physical port up",
1136 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001137 if (prop_carrier_state)
1138 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001140 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 if (netif_msg_link(port))
1142 ehea_info("%s: Physical port down",
1143 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001144 if (prop_carrier_state)
1145 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001146 }
1147
1148 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1149 ehea_info("External switch port is primary port");
1150 else
1151 ehea_info("External switch port is backup port");
1152
1153 break;
1154 case EHEA_EC_ADAPTER_MALFUNC:
1155 ehea_error("Adapter malfunction");
1156 break;
1157 case EHEA_EC_PORT_MALFUNC:
1158 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1159 netif_carrier_off(port->netdev);
1160 netif_stop_queue(port->netdev);
1161 break;
1162 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001163 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001164 break;
1165 }
1166}
1167
1168static void ehea_neq_tasklet(unsigned long data)
1169{
Doug Maxey508d2b52008-01-31 20:20:49 -06001170 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001171 struct ehea_eqe *eqe;
1172 u64 event_mask;
1173
1174 eqe = ehea_poll_eq(adapter->neq);
1175 ehea_debug("eqe=%p", eqe);
1176
1177 while (eqe) {
1178 ehea_debug("*eqe=%lx", eqe->entry);
1179 ehea_parse_eqe(adapter, eqe->entry);
1180 eqe = ehea_poll_eq(adapter->neq);
1181 ehea_debug("next eqe=%p", eqe);
1182 }
1183
1184 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1185 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1186 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1187
1188 ehea_h_reset_events(adapter->handle,
1189 adapter->neq->fw_handle, event_mask);
1190}
1191
David Howells7d12e782006-10-05 14:55:46 +01001192static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001193{
1194 struct ehea_adapter *adapter = param;
1195 tasklet_hi_schedule(&adapter->neq_tasklet);
1196 return IRQ_HANDLED;
1197}
1198
1199
1200static int ehea_fill_port_res(struct ehea_port_res *pr)
1201{
1202 int ret;
1203 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1204
1205 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1206 - init_attr->act_nr_rwqes_rq2
1207 - init_attr->act_nr_rwqes_rq3 - 1);
1208
1209 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1210
1211 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1212
1213 return ret;
1214}
1215
1216static int ehea_reg_interrupts(struct net_device *dev)
1217{
1218 struct ehea_port *port = netdev_priv(dev);
1219 struct ehea_port_res *pr;
1220 int i, ret;
1221
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222
1223 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1224 dev->name);
1225
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001226 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001228 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229 if (ret) {
1230 ehea_error("failed registering irq for qp_aff_irq_handler:"
1231 "ist=%X", port->qp_eq->attr.ist1);
1232 goto out_free_qpeq;
1233 }
1234
1235 if (netif_msg_ifup(port))
1236 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1237 "registered", port->qp_eq->attr.ist1);
1238
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001239
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001240 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1241 pr = &port->port_res[i];
1242 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001243 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001244 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001245 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001246 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 pr);
1248 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001249 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001251 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001252 goto out_free_req;
1253 }
1254 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001255 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1256 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001257 }
1258out:
1259 return ret;
1260
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001261
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001262out_free_req:
1263 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001264 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001265 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001267
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001269 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001270 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001271
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001273
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001274}
1275
1276static void ehea_free_interrupts(struct net_device *dev)
1277{
1278 struct ehea_port *port = netdev_priv(dev);
1279 struct ehea_port_res *pr;
1280 int i;
1281
1282 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001283
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001284 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1285 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001286 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 if (netif_msg_intr(port))
1288 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001289 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 }
1291
1292 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001293 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294 if (netif_msg_intr(port))
1295 ehea_info("associated event interrupt for handle 0x%X freed",
1296 port->qp_eq->attr.ist1);
1297}
1298
1299static int ehea_configure_port(struct ehea_port *port)
1300{
1301 int ret, i;
1302 u64 hret, mask;
1303 struct hcp_ehea_port_cb0 *cb0;
1304
1305 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +01001306 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307 if (!cb0)
1308 goto out;
1309
1310 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1311 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1312 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1313 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1314 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1315 PXLY_RC_VLAN_FILTER)
1316 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1317
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001318 for (i = 0; i < port->num_mcs; i++)
1319 if (use_mcs)
1320 cb0->default_qpn_arr[i] =
1321 port->port_res[i].qp->init_attr.qp_nr;
1322 else
1323 cb0->default_qpn_arr[i] =
1324 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326 if (netif_msg_ifup(port))
1327 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1328
1329 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1330 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1331
1332 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1333 port->logical_port_id,
1334 H_PORT_CB0, mask, cb0);
1335 ret = -EIO;
1336 if (hret != H_SUCCESS)
1337 goto out_free;
1338
1339 ret = 0;
1340
1341out_free:
1342 kfree(cb0);
1343out:
1344 return ret;
1345}
1346
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001347int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001349 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 struct ehea_adapter *adapter = pr->port->adapter;
1351
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001352 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1353 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 goto out;
1355
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001356 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1357 if (ret)
1358 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359
1360 return 0;
1361
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001362out_free:
1363 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001365 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 return -EIO;
1367}
1368
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001369int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001371 if ((ehea_rem_mr(&pr->send_mr))
1372 || (ehea_rem_mr(&pr->recv_mr)))
1373 return -EIO;
1374 else
1375 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376}
1377
1378static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1379{
Doug Maxey508d2b52008-01-31 20:20:49 -06001380 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001381
1382 q_skba->arr = vmalloc(arr_size);
1383 if (!q_skba->arr)
1384 return -ENOMEM;
1385
1386 memset(q_skba->arr, 0, arr_size);
1387
1388 q_skba->len = max_q_entries;
1389 q_skba->index = 0;
1390 q_skba->os_skbs = 0;
1391
1392 return 0;
1393}
1394
1395static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1396 struct port_res_cfg *pr_cfg, int queue_token)
1397{
1398 struct ehea_adapter *adapter = port->adapter;
1399 enum ehea_eq_type eq_type = EHEA_EQ;
1400 struct ehea_qp_init_attr *init_attr = NULL;
1401 int ret = -EIO;
1402
1403 memset(pr, 0, sizeof(struct ehea_port_res));
1404
1405 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001406 spin_lock_init(&pr->xmit_lock);
1407 spin_lock_init(&pr->netif_queue);
1408
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001409 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1410 if (!pr->eq) {
1411 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412 goto out_free;
1413 }
1414
1415 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001416 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001417 port->logical_port_id);
1418 if (!pr->recv_cq) {
1419 ehea_error("create_cq failed (cq_recv)");
1420 goto out_free;
1421 }
1422
1423 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001424 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001425 port->logical_port_id);
1426 if (!pr->send_cq) {
1427 ehea_error("create_cq failed (cq_send)");
1428 goto out_free;
1429 }
1430
1431 if (netif_msg_ifup(port))
1432 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1433 pr->send_cq->attr.act_nr_of_cqes,
1434 pr->recv_cq->attr.act_nr_of_cqes);
1435
1436 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1437 if (!init_attr) {
1438 ret = -ENOMEM;
1439 ehea_error("no mem for ehea_qp_init_attr");
1440 goto out_free;
1441 }
1442
1443 init_attr->low_lat_rq1 = 1;
1444 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1445 init_attr->rq_count = 3;
1446 init_attr->qp_token = queue_token;
1447 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1448 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1449 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1450 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1451 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1452 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1453 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1454 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1455 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1456 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1457 init_attr->port_nr = port->logical_port_id;
1458 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1459 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1460 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1461
1462 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1463 if (!pr->qp) {
1464 ehea_error("create_qp failed");
1465 ret = -EIO;
1466 goto out_free;
1467 }
1468
1469 if (netif_msg_ifup(port))
1470 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1471 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1472 init_attr->act_nr_send_wqes,
1473 init_attr->act_nr_rwqes_rq1,
1474 init_attr->act_nr_rwqes_rq2,
1475 init_attr->act_nr_rwqes_rq3);
1476
Thomas Klein44fb3122008-04-04 15:04:53 +02001477 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1478
1479 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1481 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1482 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1483 if (ret)
1484 goto out_free;
1485
1486 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1487 if (ehea_gen_smrs(pr) != 0) {
1488 ret = -EIO;
1489 goto out_free;
1490 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001491
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1493
1494 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001495
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001496 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001497
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001498 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1499 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1500 pr->lro_mgr.lro_arr = pr->lro_desc;
1501 pr->lro_mgr.get_skb_header = get_skb_hdr;
1502 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1503 pr->lro_mgr.dev = port->netdev;
1504 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1505 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1506
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507 ret = 0;
1508 goto out;
1509
1510out_free:
1511 kfree(init_attr);
1512 vfree(pr->sq_skba.arr);
1513 vfree(pr->rq1_skba.arr);
1514 vfree(pr->rq2_skba.arr);
1515 vfree(pr->rq3_skba.arr);
1516 ehea_destroy_qp(pr->qp);
1517 ehea_destroy_cq(pr->send_cq);
1518 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001519 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001520out:
1521 return ret;
1522}
1523
1524static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1525{
1526 int ret, i;
1527
1528 ret = ehea_destroy_qp(pr->qp);
1529
1530 if (!ret) {
1531 ehea_destroy_cq(pr->send_cq);
1532 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001533 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001534
1535 for (i = 0; i < pr->rq1_skba.len; i++)
1536 if (pr->rq1_skba.arr[i])
1537 dev_kfree_skb(pr->rq1_skba.arr[i]);
1538
1539 for (i = 0; i < pr->rq2_skba.len; i++)
1540 if (pr->rq2_skba.arr[i])
1541 dev_kfree_skb(pr->rq2_skba.arr[i]);
1542
1543 for (i = 0; i < pr->rq3_skba.len; i++)
1544 if (pr->rq3_skba.arr[i])
1545 dev_kfree_skb(pr->rq3_skba.arr[i]);
1546
1547 for (i = 0; i < pr->sq_skba.len; i++)
1548 if (pr->sq_skba.arr[i])
1549 dev_kfree_skb(pr->sq_skba.arr[i]);
1550
1551 vfree(pr->rq1_skba.arr);
1552 vfree(pr->rq2_skba.arr);
1553 vfree(pr->rq3_skba.arr);
1554 vfree(pr->sq_skba.arr);
1555 ret = ehea_rem_smrs(pr);
1556 }
1557 return ret;
1558}
1559
1560/*
1561 * The write_* functions store information in swqe which is used by
1562 * the hardware to calculate the ip/tcp/udp checksum
1563 */
1564
1565static inline void write_ip_start_end(struct ehea_swqe *swqe,
1566 const struct sk_buff *skb)
1567{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001568 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001569 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570}
1571
1572static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1573 const struct sk_buff *skb)
1574{
1575 swqe->tcp_offset =
1576 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1577
1578 swqe->tcp_end = (u16)skb->len - 1;
1579}
1580
1581static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1582 const struct sk_buff *skb)
1583{
1584 swqe->tcp_offset =
1585 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1586
1587 swqe->tcp_end = (u16)skb->len - 1;
1588}
1589
1590
1591static void write_swqe2_TSO(struct sk_buff *skb,
1592 struct ehea_swqe *swqe, u32 lkey)
1593{
1594 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1595 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1596 int skb_data_size = skb->len - skb->data_len;
1597 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001598
1599 /* Packet is TCP with TSO enabled */
1600 swqe->tx_control |= EHEA_SWQE_TSO;
1601 swqe->mss = skb_shinfo(skb)->gso_size;
1602 /* copy only eth/ip/tcp headers to immediate data and
1603 * the rest of skb->data to sg1entry
1604 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001605 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606
1607 skb_data_size = skb->len - skb->data_len;
1608
1609 if (skb_data_size >= headersize) {
1610 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001611 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001612 swqe->immediate_data_length = headersize;
1613
1614 if (skb_data_size > headersize) {
1615 /* set sg1entry data */
1616 sg1entry->l_key = lkey;
1617 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001618 sg1entry->vaddr =
1619 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001620 swqe->descriptors++;
1621 }
1622 } else
1623 ehea_error("cannot handle fragmented headers");
1624}
1625
1626static void write_swqe2_nonTSO(struct sk_buff *skb,
1627 struct ehea_swqe *swqe, u32 lkey)
1628{
1629 int skb_data_size = skb->len - skb->data_len;
1630 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1631 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632
1633 /* Packet is any nonTSO type
1634 *
1635 * Copy as much as possible skb->data to immediate data and
1636 * the rest to sg1entry
1637 */
1638 if (skb_data_size >= SWQE2_MAX_IMM) {
1639 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001640 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001641
1642 swqe->immediate_data_length = SWQE2_MAX_IMM;
1643
1644 if (skb_data_size > SWQE2_MAX_IMM) {
1645 /* copy sg1entry data */
1646 sg1entry->l_key = lkey;
1647 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001648 sg1entry->vaddr =
1649 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650 swqe->descriptors++;
1651 }
1652 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001653 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 swqe->immediate_data_length = skb_data_size;
1655 }
1656}
1657
1658static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1659 struct ehea_swqe *swqe, u32 lkey)
1660{
1661 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1662 skb_frag_t *frag;
1663 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664
1665 nfrags = skb_shinfo(skb)->nr_frags;
1666 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001667 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001668 swqe->descriptors = 0;
1669 sg1entry_contains_frag_data = 0;
1670
1671 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1672 write_swqe2_TSO(skb, swqe, lkey);
1673 else
1674 write_swqe2_nonTSO(skb, swqe, lkey);
1675
1676 /* write descriptors */
1677 if (nfrags > 0) {
1678 if (swqe->descriptors == 0) {
1679 /* sg1entry not yet used */
1680 frag = &skb_shinfo(skb)->frags[0];
1681
1682 /* copy sg1entry data */
1683 sg1entry->l_key = lkey;
1684 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001685 sg1entry->vaddr =
1686 ehea_map_vaddr(page_address(frag->page)
1687 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001688 swqe->descriptors++;
1689 sg1entry_contains_frag_data = 1;
1690 }
1691
1692 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1693
1694 frag = &skb_shinfo(skb)->frags[i];
1695 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1696
1697 sgentry->l_key = lkey;
1698 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001699 sgentry->vaddr =
1700 ehea_map_vaddr(page_address(frag->page)
1701 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001702 swqe->descriptors++;
1703 }
1704 }
1705}
1706
1707static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1708{
1709 int ret = 0;
1710 u64 hret;
1711 u8 reg_type;
1712
1713 /* De/Register untagged packets */
1714 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1715 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1716 port->logical_port_id,
1717 reg_type, port->mac_addr, 0, hcallid);
1718 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001719 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001720 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001721 ret = -EIO;
1722 goto out_herr;
1723 }
1724
1725 /* De/Register VLAN packets */
1726 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1727 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1728 port->logical_port_id,
1729 reg_type, port->mac_addr, 0, hcallid);
1730 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001731 ehea_error("%sregistering bc address failed (vlan)",
1732 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001733 ret = -EIO;
1734 }
1735out_herr:
1736 return ret;
1737}
1738
1739static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1740{
1741 struct ehea_port *port = netdev_priv(dev);
1742 struct sockaddr *mac_addr = sa;
1743 struct hcp_ehea_port_cb0 *cb0;
1744 int ret;
1745 u64 hret;
1746
1747 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1748 ret = -EADDRNOTAVAIL;
1749 goto out;
1750 }
1751
Thomas Kleina1d261c2006-11-03 17:48:23 +01001752 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753 if (!cb0) {
1754 ehea_error("no mem for cb0");
1755 ret = -ENOMEM;
1756 goto out;
1757 }
1758
1759 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1760
1761 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1762
1763 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1764 port->logical_port_id, H_PORT_CB0,
1765 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1766 if (hret != H_SUCCESS) {
1767 ret = -EIO;
1768 goto out_free;
1769 }
1770
1771 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1772
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001773 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001774
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001775 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001776 if (port->state == EHEA_PORT_UP) {
1777 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1778 if (ret)
1779 goto out_upregs;
1780 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781
1782 port->mac_addr = cb0->port_mac_addr << 16;
1783
1784 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001785 if (port->state == EHEA_PORT_UP) {
1786 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1787 if (ret)
1788 goto out_upregs;
1789 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790
1791 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001792
1793out_upregs:
1794 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001795 spin_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001796out_free:
1797 kfree(cb0);
1798out:
1799 return ret;
1800}
1801
1802static void ehea_promiscuous_error(u64 hret, int enable)
1803{
Thomas Klein7674a582007-01-22 12:54:20 +01001804 if (hret == H_AUTHORITY)
1805 ehea_info("Hypervisor denied %sabling promiscuous mode",
1806 enable == 1 ? "en" : "dis");
1807 else
1808 ehea_error("failed %sabling promiscuous mode",
1809 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001810}
1811
1812static void ehea_promiscuous(struct net_device *dev, int enable)
1813{
1814 struct ehea_port *port = netdev_priv(dev);
1815 struct hcp_ehea_port_cb7 *cb7;
1816 u64 hret;
1817
1818 if ((enable && port->promisc) || (!enable && !port->promisc))
1819 return;
1820
Thomas Kleina1d261c2006-11-03 17:48:23 +01001821 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001822 if (!cb7) {
1823 ehea_error("no mem for cb7");
1824 goto out;
1825 }
1826
1827 /* Modify Pxs_DUCQPN in CB7 */
1828 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1829
1830 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1831 port->logical_port_id,
1832 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1833 if (hret) {
1834 ehea_promiscuous_error(hret, enable);
1835 goto out;
1836 }
1837
1838 port->promisc = enable;
1839out:
1840 kfree(cb7);
1841 return;
1842}
1843
1844static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1845 u32 hcallid)
1846{
1847 u64 hret;
1848 u8 reg_type;
1849
1850 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1851 | EHEA_BCMC_UNTAGGED;
1852
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, mc_mac_addr, 0, hcallid);
1856 if (hret)
1857 goto out;
1858
1859 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1860 | EHEA_BCMC_VLANID_ALL;
1861
1862 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1863 port->logical_port_id,
1864 reg_type, mc_mac_addr, 0, hcallid);
1865out:
1866 return hret;
1867}
1868
1869static int ehea_drop_multicast_list(struct net_device *dev)
1870{
1871 struct ehea_port *port = netdev_priv(dev);
1872 struct ehea_mc_list *mc_entry = port->mc_list;
1873 struct list_head *pos;
1874 struct list_head *temp;
1875 int ret = 0;
1876 u64 hret;
1877
1878 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1879 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1880
1881 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1882 H_DEREG_BCMC);
1883 if (hret) {
1884 ehea_error("failed deregistering mcast MAC");
1885 ret = -EIO;
1886 }
1887
1888 list_del(pos);
1889 kfree(mc_entry);
1890 }
1891 return ret;
1892}
1893
1894static void ehea_allmulti(struct net_device *dev, int enable)
1895{
1896 struct ehea_port *port = netdev_priv(dev);
1897 u64 hret;
1898
1899 if (!port->allmulti) {
1900 if (enable) {
1901 /* Enable ALLMULTI */
1902 ehea_drop_multicast_list(dev);
1903 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1904 if (!hret)
1905 port->allmulti = 1;
1906 else
1907 ehea_error("failed enabling IFF_ALLMULTI");
1908 }
1909 } else
1910 if (!enable) {
1911 /* Disable ALLMULTI */
1912 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1913 if (!hret)
1914 port->allmulti = 0;
1915 else
1916 ehea_error("failed disabling IFF_ALLMULTI");
1917 }
1918}
1919
Doug Maxey508d2b52008-01-31 20:20:49 -06001920static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921{
1922 struct ehea_mc_list *ehea_mcl_entry;
1923 u64 hret;
1924
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001925 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926 if (!ehea_mcl_entry) {
1927 ehea_error("no mem for mcl_entry");
1928 return;
1929 }
1930
1931 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1932
1933 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1934
1935 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1936 H_REG_BCMC);
1937 if (!hret)
1938 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1939 else {
1940 ehea_error("failed registering mcast MAC");
1941 kfree(ehea_mcl_entry);
1942 }
1943}
1944
1945static void ehea_set_multicast_list(struct net_device *dev)
1946{
1947 struct ehea_port *port = netdev_priv(dev);
1948 struct dev_mc_list *k_mcl_entry;
1949 int ret, i;
1950
1951 if (dev->flags & IFF_PROMISC) {
1952 ehea_promiscuous(dev, 1);
1953 return;
1954 }
1955 ehea_promiscuous(dev, 0);
1956
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001957 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001958
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001959 if (dev->flags & IFF_ALLMULTI) {
1960 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001961 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001962 }
1963 ehea_allmulti(dev, 0);
1964
1965 if (dev->mc_count) {
1966 ret = ehea_drop_multicast_list(dev);
1967 if (ret) {
1968 /* Dropping the current multicast list failed.
1969 * Enabling ALL_MULTI is the best we can do.
1970 */
1971 ehea_allmulti(dev, 1);
1972 }
1973
1974 if (dev->mc_count > port->adapter->max_mc_mac) {
1975 ehea_info("Mcast registration limit reached (0x%lx). "
1976 "Use ALLMULTI!",
1977 port->adapter->max_mc_mac);
1978 goto out;
1979 }
1980
Doug Maxey508d2b52008-01-31 20:20:49 -06001981 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1982 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001983 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001984
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001985 }
1986out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001987 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001988 spin_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001989 return;
1990}
1991
1992static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1993{
1994 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1995 return -EINVAL;
1996 dev->mtu = new_mtu;
1997 return 0;
1998}
1999
2000static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2001 struct ehea_swqe *swqe, u32 lkey)
2002{
2003 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002004 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002005
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002006 /* IPv4 */
2007 swqe->tx_control |= EHEA_SWQE_CRC
2008 | EHEA_SWQE_IP_CHECKSUM
2009 | EHEA_SWQE_TCP_CHECKSUM
2010 | EHEA_SWQE_IMM_DATA_PRESENT
2011 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2012
2013 write_ip_start_end(swqe, skb);
2014
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002015 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002016 if ((iph->frag_off & IP_MF)
2017 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002018 /* IP fragment, so don't change cs */
2019 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2020 else
2021 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002022 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002023 write_tcp_offset_end(swqe, skb);
2024 }
2025
2026 /* icmp (big data) and ip segmentation packets (all other ip
2027 packets) do not require any special handling */
2028
2029 } else {
2030 /* Other Ethernet Protocol */
2031 swqe->tx_control |= EHEA_SWQE_CRC
2032 | EHEA_SWQE_IMM_DATA_PRESENT
2033 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2034 }
2035
2036 write_swqe2_data(skb, dev, swqe, lkey);
2037}
2038
2039static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2040 struct ehea_swqe *swqe)
2041{
2042 int nfrags = skb_shinfo(skb)->nr_frags;
2043 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2044 skb_frag_t *frag;
2045 int i;
2046
2047 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002048 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002049
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002050 /* IPv4 */
2051 write_ip_start_end(swqe, skb);
2052
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002053 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002054 swqe->tx_control |= EHEA_SWQE_CRC
2055 | EHEA_SWQE_IP_CHECKSUM
2056 | EHEA_SWQE_TCP_CHECKSUM
2057 | EHEA_SWQE_IMM_DATA_PRESENT;
2058
2059 write_tcp_offset_end(swqe, skb);
2060
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002061 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002062 if ((iph->frag_off & IP_MF)
2063 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002064 /* IP fragment, so don't change cs */
2065 swqe->tx_control |= EHEA_SWQE_CRC
2066 | EHEA_SWQE_IMM_DATA_PRESENT;
2067 else {
2068 swqe->tx_control |= EHEA_SWQE_CRC
2069 | EHEA_SWQE_IP_CHECKSUM
2070 | EHEA_SWQE_TCP_CHECKSUM
2071 | EHEA_SWQE_IMM_DATA_PRESENT;
2072
2073 write_udp_offset_end(swqe, skb);
2074 }
2075 } else {
2076 /* icmp (big data) and
2077 ip segmentation packets (all other ip packets) */
2078 swqe->tx_control |= EHEA_SWQE_CRC
2079 | EHEA_SWQE_IP_CHECKSUM
2080 | EHEA_SWQE_IMM_DATA_PRESENT;
2081 }
2082 } else {
2083 /* Other Ethernet Protocol */
2084 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2085 }
2086 /* copy (immediate) data */
2087 if (nfrags == 0) {
2088 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002089 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002090 } else {
2091 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002092 skb_copy_from_linear_data(skb, imm_data,
2093 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002094 imm_data += skb->len - skb->data_len;
2095
2096 /* ... then copy data from the fragments */
2097 for (i = 0; i < nfrags; i++) {
2098 frag = &skb_shinfo(skb)->frags[i];
2099 memcpy(imm_data,
2100 page_address(frag->page) + frag->page_offset,
2101 frag->size);
2102 imm_data += frag->size;
2103 }
2104 }
2105 swqe->immediate_data_length = skb->len;
2106 dev_kfree_skb(skb);
2107}
2108
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002109static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2110{
2111 struct tcphdr *tcp;
2112 u32 tmp;
2113
2114 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002115 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002116 tcp = (struct tcphdr *)(skb_network_header(skb) +
2117 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002118 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002119 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002120 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002121 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002122 return 0;
2123}
2124
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002125static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2126{
2127 struct ehea_port *port = netdev_priv(dev);
2128 struct ehea_swqe *swqe;
2129 unsigned long flags;
2130 u32 lkey;
2131 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002132 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002133
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002134 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2135
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002136 if (!spin_trylock(&pr->xmit_lock))
2137 return NETDEV_TX_BUSY;
2138
2139 if (pr->queue_stopped) {
2140 spin_unlock(&pr->xmit_lock);
2141 return NETDEV_TX_BUSY;
2142 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002143
2144 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2145 memset(swqe, 0, SWQE_HEADER_SIZE);
2146 atomic_dec(&pr->swqe_avail);
2147
2148 if (skb->len <= SWQE3_MAX_IMM) {
2149 u32 sig_iv = port->sig_comp_iv;
2150 u32 swqe_num = pr->swqe_id_counter;
2151 ehea_xmit3(skb, dev, swqe);
2152 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2153 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2154 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2155 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2156 sig_iv);
2157 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2158 pr->swqe_ll_count = 0;
2159 } else
2160 pr->swqe_ll_count += 1;
2161 } else {
2162 swqe->wr_id =
2163 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2164 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002165 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002166 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2167 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2168
2169 pr->sq_skba.index++;
2170 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2171
2172 lkey = pr->send_mr.lkey;
2173 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002174 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002175 }
2176 pr->swqe_id_counter += 1;
2177
2178 if (port->vgrp && vlan_tx_tag_present(skb)) {
2179 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2180 swqe->vlan_tag = vlan_tx_tag_get(skb);
2181 }
2182
2183 if (netif_msg_tx_queued(port)) {
2184 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002185 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002186 }
2187
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002188 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2189 netif_stop_queue(dev);
2190 swqe->tx_control |= EHEA_SWQE_PURGE;
2191 }
Thomas Klein44c82152007-07-11 16:32:00 +02002192
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002194 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002195
2196 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2197 spin_lock_irqsave(&pr->netif_queue, flags);
2198 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002199 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002200 netif_stop_queue(dev);
2201 pr->queue_stopped = 1;
2202 }
2203 spin_unlock_irqrestore(&pr->netif_queue, flags);
2204 }
2205 dev->trans_start = jiffies;
2206 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002207
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002208 return NETDEV_TX_OK;
2209}
2210
2211static void ehea_vlan_rx_register(struct net_device *dev,
2212 struct vlan_group *grp)
2213{
2214 struct ehea_port *port = netdev_priv(dev);
2215 struct ehea_adapter *adapter = port->adapter;
2216 struct hcp_ehea_port_cb1 *cb1;
2217 u64 hret;
2218
2219 port->vgrp = grp;
2220
Thomas Kleina1d261c2006-11-03 17:48:23 +01002221 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002222 if (!cb1) {
2223 ehea_error("no mem for cb1");
2224 goto out;
2225 }
2226
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2228 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2229 if (hret != H_SUCCESS)
2230 ehea_error("modify_ehea_port failed");
2231
2232 kfree(cb1);
2233out:
2234 return;
2235}
2236
2237static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2238{
2239 struct ehea_port *port = netdev_priv(dev);
2240 struct ehea_adapter *adapter = port->adapter;
2241 struct hcp_ehea_port_cb1 *cb1;
2242 int index;
2243 u64 hret;
2244
Thomas Kleina1d261c2006-11-03 17:48:23 +01002245 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002246 if (!cb1) {
2247 ehea_error("no mem for cb1");
2248 goto out;
2249 }
2250
2251 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2252 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2253 if (hret != H_SUCCESS) {
2254 ehea_error("query_ehea_port failed");
2255 goto out;
2256 }
2257
2258 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002259 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002260
2261 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2262 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2263 if (hret != H_SUCCESS)
2264 ehea_error("modify_ehea_port failed");
2265out:
2266 kfree(cb1);
2267 return;
2268}
2269
2270static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2271{
2272 struct ehea_port *port = netdev_priv(dev);
2273 struct ehea_adapter *adapter = port->adapter;
2274 struct hcp_ehea_port_cb1 *cb1;
2275 int index;
2276 u64 hret;
2277
Dan Aloni5c15bde2007-03-02 20:44:51 -08002278 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002279
Thomas Kleina1d261c2006-11-03 17:48:23 +01002280 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002281 if (!cb1) {
2282 ehea_error("no mem for cb1");
2283 goto out;
2284 }
2285
2286 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2287 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2288 if (hret != H_SUCCESS) {
2289 ehea_error("query_ehea_port failed");
2290 goto out;
2291 }
2292
2293 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002294 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002295
2296 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2297 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2298 if (hret != H_SUCCESS)
2299 ehea_error("modify_ehea_port failed");
2300out:
2301 kfree(cb1);
2302 return;
2303}
2304
2305int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2306{
2307 int ret = -EIO;
2308 u64 hret;
2309 u16 dummy16 = 0;
2310 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002311 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312
Thomas Kleina1d261c2006-11-03 17:48:23 +01002313 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002314 if (!cb0) {
2315 ret = -ENOMEM;
2316 goto out;
2317 }
2318
2319 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2320 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2321 if (hret != H_SUCCESS) {
2322 ehea_error("query_ehea_qp failed (1)");
2323 goto out;
2324 }
2325
2326 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2327 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2328 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2329 &dummy64, &dummy64, &dummy16, &dummy16);
2330 if (hret != H_SUCCESS) {
2331 ehea_error("modify_ehea_qp failed (1)");
2332 goto out;
2333 }
2334
2335 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2336 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2337 if (hret != H_SUCCESS) {
2338 ehea_error("query_ehea_qp failed (2)");
2339 goto out;
2340 }
2341
2342 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2343 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2344 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2345 &dummy64, &dummy64, &dummy16, &dummy16);
2346 if (hret != H_SUCCESS) {
2347 ehea_error("modify_ehea_qp failed (2)");
2348 goto out;
2349 }
2350
2351 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2352 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2353 if (hret != H_SUCCESS) {
2354 ehea_error("query_ehea_qp failed (3)");
2355 goto out;
2356 }
2357
2358 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2359 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2360 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2361 &dummy64, &dummy64, &dummy16, &dummy16);
2362 if (hret != H_SUCCESS) {
2363 ehea_error("modify_ehea_qp failed (3)");
2364 goto out;
2365 }
2366
2367 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2368 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2369 if (hret != H_SUCCESS) {
2370 ehea_error("query_ehea_qp failed (4)");
2371 goto out;
2372 }
2373
2374 ret = 0;
2375out:
2376 kfree(cb0);
2377 return ret;
2378}
2379
2380static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2381 int add_tx_qps)
2382{
2383 int ret, i;
2384 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2385 enum ehea_eq_type eq_type = EHEA_EQ;
2386
2387 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2388 EHEA_MAX_ENTRIES_EQ, 1);
2389 if (!port->qp_eq) {
2390 ret = -EINVAL;
2391 ehea_error("ehea_create_eq failed (qp_eq)");
2392 goto out_kill_eq;
2393 }
2394
2395 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002396 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397 pr_cfg.max_entries_sq = sq_entries;
2398 pr_cfg.max_entries_rq1 = rq1_entries;
2399 pr_cfg.max_entries_rq2 = rq2_entries;
2400 pr_cfg.max_entries_rq3 = rq3_entries;
2401
2402 pr_cfg_small_rx.max_entries_rcq = 1;
2403 pr_cfg_small_rx.max_entries_scq = sq_entries;
2404 pr_cfg_small_rx.max_entries_sq = sq_entries;
2405 pr_cfg_small_rx.max_entries_rq1 = 1;
2406 pr_cfg_small_rx.max_entries_rq2 = 1;
2407 pr_cfg_small_rx.max_entries_rq3 = 1;
2408
2409 for (i = 0; i < def_qps; i++) {
2410 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2411 if (ret)
2412 goto out_clean_pr;
2413 }
2414 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2415 ret = ehea_init_port_res(port, &port->port_res[i],
2416 &pr_cfg_small_rx, i);
2417 if (ret)
2418 goto out_clean_pr;
2419 }
2420
2421 return 0;
2422
2423out_clean_pr:
2424 while (--i >= 0)
2425 ehea_clean_portres(port, &port->port_res[i]);
2426
2427out_kill_eq:
2428 ehea_destroy_eq(port->qp_eq);
2429 return ret;
2430}
2431
2432static int ehea_clean_all_portres(struct ehea_port *port)
2433{
2434 int ret = 0;
2435 int i;
2436
Doug Maxey508d2b52008-01-31 20:20:49 -06002437 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002438 ret |= ehea_clean_portres(port, &port->port_res[i]);
2439
2440 ret |= ehea_destroy_eq(port->qp_eq);
2441
2442 return ret;
2443}
2444
Thomas Klein35cf2e22007-08-06 13:55:14 +02002445static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002446{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002447 if (adapter->active_ports)
2448 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002449
2450 ehea_rem_mr(&adapter->mr);
2451}
2452
Thomas Klein35cf2e22007-08-06 13:55:14 +02002453static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002454{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002455 if (adapter->active_ports)
2456 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002457
2458 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2459}
2460
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002461static int ehea_up(struct net_device *dev)
2462{
2463 int ret, i;
2464 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002465
2466 if (port->state == EHEA_PORT_UP)
2467 return 0;
2468
Daniel Walker9f71a562008-03-28 14:41:26 -07002469 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002470
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002471 ret = ehea_port_res_setup(port, port->num_def_qps,
2472 port->num_add_tx_qps);
2473 if (ret) {
2474 ehea_error("port_res_failed");
2475 goto out;
2476 }
2477
2478 /* Set default QP for this port */
2479 ret = ehea_configure_port(port);
2480 if (ret) {
2481 ehea_error("ehea_configure_port failed. ret:%d", ret);
2482 goto out_clean_pr;
2483 }
2484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002485 ret = ehea_reg_interrupts(dev);
2486 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002487 ehea_error("reg_interrupts failed. ret:%d", ret);
2488 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002489 }
2490
Doug Maxey508d2b52008-01-31 20:20:49 -06002491 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002492 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2493 if (ret) {
2494 ehea_error("activate_qp failed");
2495 goto out_free_irqs;
2496 }
2497 }
2498
Doug Maxey508d2b52008-01-31 20:20:49 -06002499 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002500 ret = ehea_fill_port_res(&port->port_res[i]);
2501 if (ret) {
2502 ehea_error("out_free_irqs");
2503 goto out_free_irqs;
2504 }
2505 }
2506
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002507 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002508
2509 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2510 if (ret) {
2511 ret = -EIO;
2512 goto out_free_irqs;
2513 }
2514
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002515 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002516
2517 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002518 goto out;
2519
2520out_free_irqs:
2521 ehea_free_interrupts(dev);
2522
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002523out_clean_pr:
2524 ehea_clean_all_portres(port);
2525out:
Thomas Klein44c82152007-07-11 16:32:00 +02002526 if (ret)
2527 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2528
Thomas Klein21eee2d2008-02-13 16:18:33 +01002529 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002530 spin_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002531
2532 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002533 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002535 return ret;
2536}
2537
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002538static void port_napi_disable(struct ehea_port *port)
2539{
2540 int i;
2541
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002542 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002543 napi_disable(&port->port_res[i].napi);
2544}
2545
2546static void port_napi_enable(struct ehea_port *port)
2547{
2548 int i;
2549
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002550 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002551 napi_enable(&port->port_res[i].napi);
2552}
2553
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002554static int ehea_open(struct net_device *dev)
2555{
2556 int ret;
2557 struct ehea_port *port = netdev_priv(dev);
2558
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002559 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002560
2561 if (netif_msg_ifup(port))
2562 ehea_info("enabling port %s", dev->name);
2563
2564 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002565 if (!ret) {
2566 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002567 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002568 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002570 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002571
2572 return ret;
2573}
2574
2575static int ehea_down(struct net_device *dev)
2576{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002577 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002578 struct ehea_port *port = netdev_priv(dev);
2579
2580 if (port->state == EHEA_PORT_DOWN)
2581 return 0;
2582
Daniel Walkerdbbcbb22008-03-28 14:41:27 -07002583 mutex_lock(&ehea_fw_handles.lock);
2584
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002585 spin_lock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002586 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002587 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589 ehea_free_interrupts(dev);
2590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002592
Thomas Klein21eee2d2008-02-13 16:18:33 +01002593 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002594 spin_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002595
Thomas Klein44c82152007-07-11 16:32:00 +02002596 ret = ehea_clean_all_portres(port);
2597 if (ret)
2598 ehea_info("Failed freeing resources for %s. ret=%i",
2599 dev->name, ret);
2600
Thomas Klein21eee2d2008-02-13 16:18:33 +01002601 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002602 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002603
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604 return ret;
2605}
2606
2607static int ehea_stop(struct net_device *dev)
2608{
2609 int ret;
2610 struct ehea_port *port = netdev_priv(dev);
2611
2612 if (netif_msg_ifdown(port))
2613 ehea_info("disabling port %s", dev->name);
2614
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002615 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002616 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002617 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002618 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002619 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002621 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002622 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 return ret;
2624}
2625
Andrew Morton22559c52008-04-18 13:50:39 -07002626static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002627{
2628 struct ehea_qp qp = *orig_qp;
2629 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2630 struct ehea_swqe *swqe;
2631 int wqe_index;
2632 int i;
2633
2634 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2635 swqe = ehea_get_swqe(&qp, &wqe_index);
2636 swqe->tx_control |= EHEA_SWQE_PURGE;
2637 }
2638}
2639
Andrew Morton22559c52008-04-18 13:50:39 -07002640static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002641{
2642 int i;
2643
2644 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2645 struct ehea_port_res *pr = &port->port_res[i];
2646 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2647 int k = 0;
2648 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2649 msleep(5);
2650 if (++k == 20)
2651 break;
2652 }
2653 }
2654}
2655
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002656int ehea_stop_qps(struct net_device *dev)
2657{
2658 struct ehea_port *port = netdev_priv(dev);
2659 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002660 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002661 int ret = -EIO;
2662 int dret;
2663 int i;
2664 u64 hret;
2665 u64 dummy64 = 0;
2666 u16 dummy16 = 0;
2667
2668 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2669 if (!cb0) {
2670 ret = -ENOMEM;
2671 goto out;
2672 }
2673
2674 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2675 struct ehea_port_res *pr = &port->port_res[i];
2676 struct ehea_qp *qp = pr->qp;
2677
2678 /* Purge send queue */
2679 ehea_purge_sq(qp);
2680
2681 /* Disable queue pair */
2682 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2683 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2684 cb0);
2685 if (hret != H_SUCCESS) {
2686 ehea_error("query_ehea_qp failed (1)");
2687 goto out;
2688 }
2689
2690 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2691 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2692
2693 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2694 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2695 1), cb0, &dummy64,
2696 &dummy64, &dummy16, &dummy16);
2697 if (hret != H_SUCCESS) {
2698 ehea_error("modify_ehea_qp failed (1)");
2699 goto out;
2700 }
2701
2702 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2703 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2704 cb0);
2705 if (hret != H_SUCCESS) {
2706 ehea_error("query_ehea_qp failed (2)");
2707 goto out;
2708 }
2709
2710 /* deregister shared memory regions */
2711 dret = ehea_rem_smrs(pr);
2712 if (dret) {
2713 ehea_error("unreg shared memory region failed");
2714 goto out;
2715 }
2716 }
2717
2718 ret = 0;
2719out:
2720 kfree(cb0);
2721
2722 return ret;
2723}
2724
Doug Maxey508d2b52008-01-31 20:20:49 -06002725void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002726{
2727 struct ehea_qp qp = *orig_qp;
2728 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2729 struct ehea_rwqe *rwqe;
2730 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2731 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2732 struct sk_buff *skb;
2733 u32 lkey = pr->recv_mr.lkey;
2734
2735
2736 int i;
2737 int index;
2738
2739 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2740 rwqe = ehea_get_next_rwqe(&qp, 2);
2741 rwqe->sg_list[0].l_key = lkey;
2742 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2743 skb = skba_rq2[index];
2744 if (skb)
2745 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2746 }
2747
2748 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2749 rwqe = ehea_get_next_rwqe(&qp, 3);
2750 rwqe->sg_list[0].l_key = lkey;
2751 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2752 skb = skba_rq3[index];
2753 if (skb)
2754 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2755 }
2756}
2757
2758int ehea_restart_qps(struct net_device *dev)
2759{
2760 struct ehea_port *port = netdev_priv(dev);
2761 struct ehea_adapter *adapter = port->adapter;
2762 int ret = 0;
2763 int i;
2764
Doug Maxey508d2b52008-01-31 20:20:49 -06002765 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002766 u64 hret;
2767 u64 dummy64 = 0;
2768 u16 dummy16 = 0;
2769
2770 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2771 if (!cb0) {
2772 ret = -ENOMEM;
2773 goto out;
2774 }
2775
2776 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2777 struct ehea_port_res *pr = &port->port_res[i];
2778 struct ehea_qp *qp = pr->qp;
2779
2780 ret = ehea_gen_smrs(pr);
2781 if (ret) {
2782 ehea_error("creation of shared memory regions failed");
2783 goto out;
2784 }
2785
2786 ehea_update_rqs(qp, pr);
2787
2788 /* Enable queue pair */
2789 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2790 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2791 cb0);
2792 if (hret != H_SUCCESS) {
2793 ehea_error("query_ehea_qp failed (1)");
2794 goto out;
2795 }
2796
2797 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2798 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2799
2800 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2801 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2802 1), cb0, &dummy64,
2803 &dummy64, &dummy16, &dummy16);
2804 if (hret != H_SUCCESS) {
2805 ehea_error("modify_ehea_qp failed (1)");
2806 goto out;
2807 }
2808
2809 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2810 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2811 cb0);
2812 if (hret != H_SUCCESS) {
2813 ehea_error("query_ehea_qp failed (2)");
2814 goto out;
2815 }
2816
2817 /* refill entire queue */
2818 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2819 ehea_refill_rq2(pr, 0);
2820 ehea_refill_rq3(pr, 0);
2821 }
2822out:
2823 kfree(cb0);
2824
2825 return ret;
2826}
2827
David Howellsc4028952006-11-22 14:57:56 +00002828static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002829{
2830 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002831 struct ehea_port *port =
2832 container_of(work, struct ehea_port, reset_task);
2833 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002834
2835 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002836 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002837 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002838
2839 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002840
Thomas Klein44c82152007-07-11 16:32:00 +02002841 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002842
2843 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002844 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002845 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002846
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002847 ehea_set_multicast_list(dev);
2848
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002849 if (netif_msg_timer(port))
2850 ehea_info("Device %s resetted successfully", dev->name);
2851
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002852 port_napi_enable(port);
2853
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002854 netif_wake_queue(dev);
2855out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002856 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002857 return;
2858}
2859
Thomas Klein44c82152007-07-11 16:32:00 +02002860static void ehea_rereg_mrs(struct work_struct *work)
2861{
2862 int ret, i;
2863 struct ehea_adapter *adapter;
2864
Daniel Walker06f89ed2008-03-28 14:41:26 -07002865 mutex_lock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002866 ehea_info("LPAR memory enlarged - re-initializing driver");
2867
2868 list_for_each_entry(adapter, &adapter_list, list)
2869 if (adapter->active_ports) {
2870 /* Shutdown all ports */
2871 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2872 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002873 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002874
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002875 if (!port)
2876 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002877
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002878 dev = port->netdev;
2879
2880 if (dev->flags & IFF_UP) {
2881 mutex_lock(&port->port_lock);
2882 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002883 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002884 ret = ehea_stop_qps(dev);
2885 if (ret) {
2886 mutex_unlock(&port->port_lock);
2887 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002888 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002889 port_napi_disable(port);
2890 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002891 }
2892 }
2893
2894 /* Unregister old memory region */
2895 ret = ehea_rem_mr(&adapter->mr);
2896 if (ret) {
2897 ehea_error("unregister MR failed - driver"
2898 " inoperable!");
2899 goto out;
2900 }
2901 }
2902
2903 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002904 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002905 if (ret) {
2906 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002907 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002908 }
Thomas Klein44c82152007-07-11 16:32:00 +02002909
2910 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2911
2912 list_for_each_entry(adapter, &adapter_list, list)
2913 if (adapter->active_ports) {
2914 /* Register new memory region */
2915 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2916 if (ret) {
2917 ehea_error("register MR failed - driver"
2918 " inoperable!");
2919 goto out;
2920 }
2921
2922 /* Restart all ports */
2923 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2924 struct ehea_port *port = adapter->port[i];
2925
2926 if (port) {
2927 struct net_device *dev = port->netdev;
2928
2929 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002930 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002931 port_napi_enable(port);
2932 ret = ehea_restart_qps(dev);
2933 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002934 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002935 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002936 }
2937 }
2938 }
2939 }
Daniel Walker06f89ed2008-03-28 14:41:26 -07002940 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002941 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002942out:
2943 return;
2944}
2945
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002946static void ehea_tx_watchdog(struct net_device *dev)
2947{
2948 struct ehea_port *port = netdev_priv(dev);
2949
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002950 if (netif_carrier_ok(dev) &&
2951 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002952 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002953}
2954
2955int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2956{
2957 struct hcp_query_ehea *cb;
2958 u64 hret;
2959 int ret;
2960
Thomas Kleina1d261c2006-11-03 17:48:23 +01002961 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962 if (!cb) {
2963 ret = -ENOMEM;
2964 goto out;
2965 }
2966
2967 hret = ehea_h_query_ehea(adapter->handle, cb);
2968
2969 if (hret != H_SUCCESS) {
2970 ret = -EIO;
2971 goto out_herr;
2972 }
2973
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002974 adapter->max_mc_mac = cb->max_mc_mac - 1;
2975 ret = 0;
2976
2977out_herr:
2978 kfree(cb);
2979out:
2980 return ret;
2981}
2982
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2984{
2985 struct hcp_ehea_port_cb4 *cb4;
2986 u64 hret;
2987 int ret = 0;
2988
2989 *jumbo = 0;
2990
2991 /* (Try to) enable *jumbo frames */
2992 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2993 if (!cb4) {
2994 ehea_error("no mem for cb4");
2995 ret = -ENOMEM;
2996 goto out;
2997 } else {
2998 hret = ehea_h_query_ehea_port(port->adapter->handle,
2999 port->logical_port_id,
3000 H_PORT_CB4,
3001 H_PORT_CB4_JUMBO, cb4);
3002 if (hret == H_SUCCESS) {
3003 if (cb4->jumbo_frame)
3004 *jumbo = 1;
3005 else {
3006 cb4->jumbo_frame = 1;
3007 hret = ehea_h_modify_ehea_port(port->adapter->
3008 handle,
3009 port->
3010 logical_port_id,
3011 H_PORT_CB4,
3012 H_PORT_CB4_JUMBO,
3013 cb4);
3014 if (hret == H_SUCCESS)
3015 *jumbo = 1;
3016 }
3017 } else
3018 ret = -EINVAL;
3019
3020 kfree(cb4);
3021 }
3022out:
3023 return ret;
3024}
3025
3026static ssize_t ehea_show_port_id(struct device *dev,
3027 struct device_attribute *attr, char *buf)
3028{
3029 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003030 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003031}
3032
3033static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3034 NULL);
3035
3036static void __devinit logical_port_release(struct device *dev)
3037{
3038 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3039 of_node_put(port->ofdev.node);
3040}
3041
3042static struct device *ehea_register_port(struct ehea_port *port,
3043 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003044{
3045 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003046
3047 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003048 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003049 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003050
Thomas Kleind1dea382007-04-26 11:56:13 +02003051 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003052 port->ofdev.dev.release = logical_port_release;
3053
3054 ret = of_device_register(&port->ofdev);
3055 if (ret) {
3056 ehea_error("failed to register device. ret=%d", ret);
3057 goto out;
3058 }
3059
3060 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003061 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003062 ehea_error("failed to register attributes, ret=%d", ret);
3063 goto out_unreg_of_dev;
3064 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003065
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003066 return &port->ofdev.dev;
3067
3068out_unreg_of_dev:
3069 of_device_unregister(&port->ofdev);
3070out:
3071 return NULL;
3072}
3073
3074static void ehea_unregister_port(struct ehea_port *port)
3075{
3076 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3077 of_device_unregister(&port->ofdev);
3078}
3079
3080struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3081 u32 logical_port_id,
3082 struct device_node *dn)
3083{
3084 int ret;
3085 struct net_device *dev;
3086 struct ehea_port *port;
3087 struct device *port_dev;
3088 int jumbo;
3089
3090 /* allocate memory for the port structures */
3091 dev = alloc_etherdev(sizeof(struct ehea_port));
3092
3093 if (!dev) {
3094 ehea_error("no mem for net_device");
3095 ret = -ENOMEM;
3096 goto out_err;
3097 }
3098
3099 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003100
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003101 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003102 port->state = EHEA_PORT_DOWN;
3103 port->sig_comp_iv = sq_entries / 10;
3104
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 port->adapter = adapter;
3106 port->netdev = dev;
3107 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003108
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003109 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003110
3111 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3112 if (!port->mc_list) {
3113 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003115 }
3116
3117 INIT_LIST_HEAD(&port->mc_list->list);
3118
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003119 ret = ehea_sense_port_attr(port);
3120 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003121 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003122
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003123 port_dev = ehea_register_port(port, dn);
3124 if (!port_dev)
3125 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003126
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003127 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003128
3129 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003130 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3131
3132 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02003133#ifdef CONFIG_NET_POLL_CONTROLLER
3134 dev->poll_controller = ehea_netpoll;
3135#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003136 dev->stop = ehea_stop;
3137 dev->hard_start_xmit = ehea_start_xmit;
3138 dev->get_stats = ehea_get_stats;
3139 dev->set_multicast_list = ehea_set_multicast_list;
3140 dev->set_mac_address = ehea_set_mac_addr;
3141 dev->change_mtu = ehea_change_mtu;
3142 dev->vlan_rx_register = ehea_vlan_rx_register;
3143 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3144 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3145 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003146 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003147 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3148 | NETIF_F_LLTX;
3149 dev->tx_timeout = &ehea_tx_watchdog;
3150 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3151
David Howellsc4028952006-11-22 14:57:56 +00003152 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003153 ehea_set_ethtool_ops(dev);
3154
3155 ret = register_netdev(dev);
3156 if (ret) {
3157 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003158 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159 }
3160
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003161 port->lro_max_aggr = lro_max_aggr;
3162
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003164 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 ehea_error("failed determining jumbo frame status for %s",
3166 port->netdev->name);
3167
Thomas Klein9c750b72007-01-29 18:44:01 +01003168 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3169 jumbo == 1 ? "en" : "dis");
3170
Thomas Klein44c82152007-07-11 16:32:00 +02003171 adapter->active_ports++;
3172
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003173 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003174
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003175out_unreg_port:
3176 ehea_unregister_port(port);
3177
3178out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003179 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180
3181out_free_ethdev:
3182 free_netdev(dev);
3183
3184out_err:
3185 ehea_error("setting up logical port with id=%d failed, ret=%d",
3186 logical_port_id, ret);
3187 return NULL;
3188}
3189
3190static void ehea_shutdown_single_port(struct ehea_port *port)
3191{
Brian King7fb1c2a2008-05-14 09:48:25 -05003192 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003193 unregister_netdev(port->netdev);
3194 ehea_unregister_port(port);
3195 kfree(port->mc_list);
3196 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003197 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003198}
3199
3200static int ehea_setup_ports(struct ehea_adapter *adapter)
3201{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003202 struct device_node *lhea_dn;
3203 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003204
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003205 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003207
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003208 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003209 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003210
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003211 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003212 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213 if (!dn_log_port_id) {
3214 ehea_error("bad device node: eth_dn name=%s",
3215 eth_dn->full_name);
3216 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003217 }
3218
Thomas Klein1211bb62007-04-26 11:56:43 +02003219 if (ehea_add_adapter_mr(adapter)) {
3220 ehea_error("creating MR failed");
3221 of_node_put(eth_dn);
3222 return -EIO;
3223 }
3224
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003225 adapter->port[i] = ehea_setup_single_port(adapter,
3226 *dn_log_port_id,
3227 eth_dn);
3228 if (adapter->port[i])
3229 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003230 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003232 else
3233 ehea_remove_adapter_mr(adapter);
3234
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003235 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003236 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003237 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003238}
3239
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003240static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3241 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242{
3243 struct device_node *lhea_dn;
3244 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003245 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003247 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003248 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003249
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003250 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003251 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252 if (dn_log_port_id)
3253 if (*dn_log_port_id == logical_port_id)
3254 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003255 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003256
3257 return NULL;
3258}
3259
3260static ssize_t ehea_probe_port(struct device *dev,
3261 struct device_attribute *attr,
3262 const char *buf, size_t count)
3263{
3264 struct ehea_adapter *adapter = dev->driver_data;
3265 struct ehea_port *port;
3266 struct device_node *eth_dn = NULL;
3267 int i;
3268
3269 u32 logical_port_id;
3270
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003271 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003272
3273 port = ehea_get_port(adapter, logical_port_id);
3274
3275 if (port) {
3276 ehea_info("adding port with logical port id=%d failed. port "
3277 "already configured as %s.", logical_port_id,
3278 port->netdev->name);
3279 return -EINVAL;
3280 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003281
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003282 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3283
3284 if (!eth_dn) {
3285 ehea_info("no logical port with id %d found", logical_port_id);
3286 return -EINVAL;
3287 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003288
Thomas Klein1211bb62007-04-26 11:56:43 +02003289 if (ehea_add_adapter_mr(adapter)) {
3290 ehea_error("creating MR failed");
3291 return -EIO;
3292 }
3293
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003294 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3295
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003296 of_node_put(eth_dn);
3297
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003298 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003299 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300 if (!adapter->port[i]) {
3301 adapter->port[i] = port;
3302 break;
3303 }
3304
3305 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3306 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003307 } else {
3308 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003309 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003310 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003311
3312 return (ssize_t) count;
3313}
3314
3315static ssize_t ehea_remove_port(struct device *dev,
3316 struct device_attribute *attr,
3317 const char *buf, size_t count)
3318{
3319 struct ehea_adapter *adapter = dev->driver_data;
3320 struct ehea_port *port;
3321 int i;
3322 u32 logical_port_id;
3323
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003324 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325
3326 port = ehea_get_port(adapter, logical_port_id);
3327
3328 if (port) {
3329 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3330 logical_port_id);
3331
3332 ehea_shutdown_single_port(port);
3333
Doug Maxey508d2b52008-01-31 20:20:49 -06003334 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003335 if (adapter->port[i] == port) {
3336 adapter->port[i] = NULL;
3337 break;
3338 }
3339 } else {
3340 ehea_error("removing port with logical port id=%d failed. port "
3341 "not configured.", logical_port_id);
3342 return -EINVAL;
3343 }
3344
Thomas Klein1211bb62007-04-26 11:56:43 +02003345 ehea_remove_adapter_mr(adapter);
3346
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347 return (ssize_t) count;
3348}
3349
3350static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3351static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3352
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003353int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003354{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003355 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003356 if (ret)
3357 goto out;
3358
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003359 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003360out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003361 return ret;
3362}
3363
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003364void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003366 device_remove_file(&dev->dev, &dev_attr_probe_port);
3367 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003368}
3369
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003370static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003371 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003372{
3373 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003374 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375 int ret;
3376
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003377 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003378 ehea_error("Invalid ibmebus device probed");
3379 return -EINVAL;
3380 }
Daniel Walker9f71a562008-03-28 14:41:26 -07003381 mutex_lock(&ehea_fw_handles.lock);
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003382
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003383 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3384 if (!adapter) {
3385 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003386 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003387 goto out;
3388 }
3389
Thomas Klein44c82152007-07-11 16:32:00 +02003390 list_add(&adapter->list, &adapter_list);
3391
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003392 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003393
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003394 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003395 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003396 if (adapter_handle)
3397 adapter->handle = *adapter_handle;
3398
3399 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003400 dev_err(&dev->dev, "failed getting handle for adapter"
3401 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003402 ret = -ENODEV;
3403 goto out_free_ad;
3404 }
3405
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406 adapter->pd = EHEA_PD_ID;
3407
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003408 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003410
3411 /* initialize adapter and ports */
3412 /* get adapter properties */
3413 ret = ehea_sense_adapter_attr(adapter);
3414 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003415 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003416 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003417 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003418
3419 adapter->neq = ehea_create_eq(adapter,
3420 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3421 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003422 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003423 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003424 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003425 }
3426
3427 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3428 (unsigned long)adapter);
3429
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003430 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003431 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003432 "ehea_neq", adapter);
3433 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003434 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003435 goto out_kill_eq;
3436 }
3437
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003438 ret = ehea_create_device_sysfs(dev);
3439 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003440 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003441
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003442 ret = ehea_setup_ports(adapter);
3443 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003444 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003445 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003446 }
3447
3448 ret = 0;
3449 goto out;
3450
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451out_rem_dev_sysfs:
3452 ehea_remove_device_sysfs(dev);
3453
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003454out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003455 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003456
3457out_kill_eq:
3458 ehea_destroy_eq(adapter->neq);
3459
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003460out_free_ad:
3461 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003462
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003463out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003464 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003465 mutex_unlock(&ehea_fw_handles.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 return ret;
3467}
3468
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003469static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003470{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003471 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003472 int i;
3473
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003474 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475 if (adapter->port[i]) {
3476 ehea_shutdown_single_port(adapter->port[i]);
3477 adapter->port[i] = NULL;
3478 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479
3480 ehea_remove_device_sysfs(dev);
3481
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003482 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003483
Daniel Walker9f71a562008-03-28 14:41:26 -07003484 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003485
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003486 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003487 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488
3489 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003490 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003491 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003493
Thomas Klein21eee2d2008-02-13 16:18:33 +01003494 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003495 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003496
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003497 return 0;
3498}
3499
Thomas Klein21eee2d2008-02-13 16:18:33 +01003500void ehea_crash_handler(void)
3501{
3502 int i;
3503
3504 if (ehea_fw_handles.arr)
3505 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3506 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3507 ehea_fw_handles.arr[i].fwh,
3508 FORCE_FREE);
3509
3510 if (ehea_bcmc_regs.arr)
3511 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3512 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3513 ehea_bcmc_regs.arr[i].port_id,
3514 ehea_bcmc_regs.arr[i].reg_type,
3515 ehea_bcmc_regs.arr[i].macaddr,
3516 0, H_DEREG_BCMC);
3517}
3518
Hannes Hering48cfb142008-05-07 14:43:36 +02003519static int ehea_mem_notifier(struct notifier_block *nb,
3520 unsigned long action, void *data)
3521{
3522 switch (action) {
3523 case MEM_OFFLINE:
3524 ehea_info("memory has been removed");
3525 ehea_rereg_mrs(NULL);
3526 break;
3527 default:
3528 break;
3529 }
3530 return NOTIFY_OK;
3531}
3532
3533static struct notifier_block ehea_mem_nb = {
3534 .notifier_call = ehea_mem_notifier,
3535};
3536
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003537static int ehea_reboot_notifier(struct notifier_block *nb,
3538 unsigned long action, void *unused)
3539{
3540 if (action == SYS_RESTART) {
3541 ehea_info("Reboot: freeing all eHEA resources");
3542 ibmebus_unregister_driver(&ehea_driver);
3543 }
3544 return NOTIFY_DONE;
3545}
3546
3547static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003548 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003549};
3550
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003551static int check_module_parm(void)
3552{
3553 int ret = 0;
3554
3555 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3556 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3557 ehea_info("Bad parameter: rq1_entries");
3558 ret = -EINVAL;
3559 }
3560 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3561 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3562 ehea_info("Bad parameter: rq2_entries");
3563 ret = -EINVAL;
3564 }
3565 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3566 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3567 ehea_info("Bad parameter: rq3_entries");
3568 ret = -EINVAL;
3569 }
3570 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3571 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3572 ehea_info("Bad parameter: sq_entries");
3573 ret = -EINVAL;
3574 }
3575
3576 return ret;
3577}
3578
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003579static ssize_t ehea_show_capabilities(struct device_driver *drv,
3580 char *buf)
3581{
3582 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3583}
3584
3585static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3586 ehea_show_capabilities, NULL);
3587
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588int __init ehea_module_init(void)
3589{
3590 int ret;
3591
3592 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3593 DRV_VERSION);
3594
Thomas Klein44c82152007-07-11 16:32:00 +02003595
3596 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003597 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3598 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3599
Daniel Walker9f71a562008-03-28 14:41:26 -07003600 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003601 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003602
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003603 ret = check_module_parm();
3604 if (ret)
3605 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003606
3607 ret = ehea_create_busmap();
3608 if (ret)
3609 goto out;
3610
Thomas Klein21eee2d2008-02-13 16:18:33 +01003611 ret = register_reboot_notifier(&ehea_reboot_nb);
3612 if (ret)
3613 ehea_info("failed registering reboot notifier");
3614
Hannes Hering48cfb142008-05-07 14:43:36 +02003615 ret = register_memory_notifier(&ehea_mem_nb);
3616 if (ret)
3617 ehea_info("failed registering memory remove notifier");
3618
Thomas Klein21eee2d2008-02-13 16:18:33 +01003619 ret = crash_shutdown_register(&ehea_crash_handler);
3620 if (ret)
3621 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003622
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003623 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003624 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003625 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003626 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003627 }
3628
3629 ret = driver_create_file(&ehea_driver.driver,
3630 &driver_attr_capabilities);
3631 if (ret) {
3632 ehea_error("failed to register capabilities attribute, ret=%d",
3633 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003634 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003635 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003636
Thomas Klein21eee2d2008-02-13 16:18:33 +01003637 return ret;
3638
3639out3:
3640 ibmebus_unregister_driver(&ehea_driver);
3641out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003642 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003643 unregister_reboot_notifier(&ehea_reboot_nb);
3644 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003645out:
3646 return ret;
3647}
3648
3649static void __exit ehea_module_exit(void)
3650{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003651 int ret;
3652
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003653 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003654 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003655 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003656 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003657 ret = crash_shutdown_unregister(&ehea_crash_handler);
3658 if (ret)
3659 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003660 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003661 kfree(ehea_fw_handles.arr);
3662 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003663 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003664}
3665
3666module_init(ehea_module_init);
3667module_exit(ehea_module_exit);