blob: d1b6d4e7495d1dee77247c74e1aa061b23e89026 [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};
121
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000122static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200123 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200125 .probe = ehea_probe_adapter,
126 .remove = ehea_remove,
127};
128
Doug Maxey508d2b52008-01-31 20:20:49 -0600129void ehea_dump(void *adr, int len, char *msg)
130{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200131 int x;
132 unsigned char *deb = adr;
133 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100134 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600135 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200136 deb += 16;
137 }
138}
139
Thomas Klein21eee2d2008-02-13 16:18:33 +0100140static void ehea_update_firmware_handles(void)
141{
142 struct ehea_fw_handle_entry *arr = NULL;
143 struct ehea_adapter *adapter;
144 int num_adapters = 0;
145 int num_ports = 0;
146 int num_portres = 0;
147 int i = 0;
148 int num_fw_handles, k, l;
149
150 /* Determine number of handles */
151 list_for_each_entry(adapter, &adapter_list, list) {
152 num_adapters++;
153
154 for (k = 0; k < EHEA_MAX_PORTS; k++) {
155 struct ehea_port *port = adapter->port[k];
156
157 if (!port || (port->state != EHEA_PORT_UP))
158 continue;
159
160 num_ports++;
161 num_portres += port->num_def_qps + port->num_add_tx_qps;
162 }
163 }
164
165 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
166 num_ports * EHEA_NUM_PORT_FW_HANDLES +
167 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
168
169 if (num_fw_handles) {
170 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
171 if (!arr)
172 return; /* Keep the existing array */
173 } else
174 goto out_update;
175
176 list_for_each_entry(adapter, &adapter_list, list) {
177 for (k = 0; k < EHEA_MAX_PORTS; k++) {
178 struct ehea_port *port = adapter->port[k];
179
180 if (!port || (port->state != EHEA_PORT_UP))
181 continue;
182
183 for (l = 0;
184 l < port->num_def_qps + port->num_add_tx_qps;
185 l++) {
186 struct ehea_port_res *pr = &port->port_res[l];
187
188 arr[i].adh = adapter->handle;
189 arr[i++].fwh = pr->qp->fw_handle;
190 arr[i].adh = adapter->handle;
191 arr[i++].fwh = pr->send_cq->fw_handle;
192 arr[i].adh = adapter->handle;
193 arr[i++].fwh = pr->recv_cq->fw_handle;
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->eq->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_mr.handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_mr.handle;
200 }
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = port->qp_eq->fw_handle;
203 }
204
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = adapter->neq->fw_handle;
207
208 if (adapter->mr.handle) {
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = adapter->mr.handle;
211 }
212 }
213
214out_update:
215 kfree(ehea_fw_handles.arr);
216 ehea_fw_handles.arr = arr;
217 ehea_fw_handles.num_entries = i;
218}
219
220static void ehea_update_bcmc_registrations(void)
221{
222 struct ehea_bcmc_reg_entry *arr = NULL;
223 struct ehea_adapter *adapter;
224 struct ehea_mc_list *mc_entry;
225 int num_registrations = 0;
226 int i = 0;
227 int k;
228
229 /* Determine number of registrations */
230 list_for_each_entry(adapter, &adapter_list, list)
231 for (k = 0; k < EHEA_MAX_PORTS; k++) {
232 struct ehea_port *port = adapter->port[k];
233
234 if (!port || (port->state != EHEA_PORT_UP))
235 continue;
236
237 num_registrations += 2; /* Broadcast registrations */
238
239 list_for_each_entry(mc_entry, &port->mc_list->list,list)
240 num_registrations += 2;
241 }
242
243 if (num_registrations) {
244 arr = kzalloc(num_registrations * sizeof(*arr), GFP_KERNEL);
245 if (!arr)
246 return; /* Keep the existing array */
247 } else
248 goto out_update;
249
250 list_for_each_entry(adapter, &adapter_list, list) {
251 for (k = 0; k < EHEA_MAX_PORTS; k++) {
252 struct ehea_port *port = adapter->port[k];
253
254 if (!port || (port->state != EHEA_PORT_UP))
255 continue;
256
257 arr[i].adh = adapter->handle;
258 arr[i].port_id = port->logical_port_id;
259 arr[i].reg_type = EHEA_BCMC_BROADCAST |
260 EHEA_BCMC_UNTAGGED;
261 arr[i++].macaddr = port->mac_addr;
262
263 arr[i].adh = adapter->handle;
264 arr[i].port_id = port->logical_port_id;
265 arr[i].reg_type = EHEA_BCMC_BROADCAST |
266 EHEA_BCMC_VLANID_ALL;
267 arr[i++].macaddr = port->mac_addr;
268
269 list_for_each_entry(mc_entry,
270 &port->mc_list->list, list) {
271 arr[i].adh = adapter->handle;
272 arr[i].port_id = port->logical_port_id;
273 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
274 EHEA_BCMC_MULTICAST |
275 EHEA_BCMC_UNTAGGED;
276 arr[i++].macaddr = mc_entry->macaddr;
277
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_VLANID_ALL;
283 arr[i++].macaddr = mc_entry->macaddr;
284 }
285 }
286 }
287
288out_update:
289 kfree(ehea_bcmc_regs.arr);
290 ehea_bcmc_regs.arr = arr;
291 ehea_bcmc_regs.num_entries = i;
292}
293
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200294static struct net_device_stats *ehea_get_stats(struct net_device *dev)
295{
296 struct ehea_port *port = netdev_priv(dev);
297 struct net_device_stats *stats = &port->stats;
298 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100299 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200300 int i;
301
302 memset(stats, 0, sizeof(*stats));
303
Thomas Kleina1d261c2006-11-03 17:48:23 +0100304 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200305 if (!cb2) {
306 ehea_error("no mem for cb2");
307 goto out;
308 }
309
310 hret = ehea_h_query_ehea_port(port->adapter->handle,
311 port->logical_port_id,
312 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
313 if (hret != H_SUCCESS) {
314 ehea_error("query_ehea_port failed");
315 goto out_herr;
316 }
317
318 if (netif_msg_hw(port))
319 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
320
321 rx_packets = 0;
322 for (i = 0; i < port->num_def_qps; i++)
323 rx_packets += port->port_res[i].rx_packets;
324
Thomas Klein7393b872007-11-21 17:37:58 +0100325 tx_packets = 0;
326 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
327 tx_packets += port->port_res[i].tx_packets;
328
329 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200330 stats->multicast = cb2->rxmcp;
331 stats->rx_errors = cb2->rxuerr;
332 stats->rx_bytes = cb2->rxo;
333 stats->tx_bytes = cb2->txo;
334 stats->rx_packets = rx_packets;
335
336out_herr:
337 kfree(cb2);
338out:
339 return stats;
340}
341
342static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
343{
344 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
345 struct net_device *dev = pr->port->netdev;
346 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200347 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
348 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200349 int i;
350
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200351 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200352
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200353 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200354 if (nr_of_wqes > 0)
355 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200356 pr->rq1_skba.os_skbs = fill_wqes;
357 return;
358 }
359
360 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200361 if (!skb_arr_rq1[index]) {
362 skb_arr_rq1[index] = netdev_alloc_skb(dev,
363 EHEA_L_PKT_SIZE);
364 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200365 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 ehea_error("%s: no mem for skb/%d wqes filled",
367 dev->name, i);
368 break;
369 }
370 }
371 index--;
372 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200373 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200375
376 if (adder == 0)
377 return;
378
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200380 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200381}
382
383static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
384{
385 int ret = 0;
386 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
387 struct net_device *dev = pr->port->netdev;
388 int i;
389
390 for (i = 0; i < pr->rq1_skba.len; i++) {
391 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
392 if (!skb_arr_rq1[i]) {
393 ehea_error("%s: no mem for skb/%d wqes filled",
394 dev->name, i);
395 ret = -ENOMEM;
396 goto out;
397 }
398 }
399 /* Ring doorbell */
400 ehea_update_rq1a(pr->qp, nr_rq1a);
401out:
402 return ret;
403}
404
405static int ehea_refill_rq_def(struct ehea_port_res *pr,
406 struct ehea_q_skb_arr *q_skba, int rq_nr,
407 int num_wqes, int wqe_type, int packet_size)
408{
409 struct net_device *dev = pr->port->netdev;
410 struct ehea_qp *qp = pr->qp;
411 struct sk_buff **skb_arr = q_skba->arr;
412 struct ehea_rwqe *rwqe;
413 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200414 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200415 int ret = 0;
416
417 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200419
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200420 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
421 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200423 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424
425 index = q_skba->index;
426 max_index_mask = q_skba->len - 1;
427 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200428 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
430 if (!skb) {
431 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100432 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200433 q_skba->os_skbs = fill_wqes - i;
434 ret = -ENOMEM;
435 break;
436 }
437 skb_reserve(skb, NET_IP_ALIGN);
438
439 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200440 tmp_addr = ehea_map_vaddr(skb->data);
441 if (tmp_addr == -1) {
442 dev_kfree_skb(skb);
443 q_skba->os_skbs = fill_wqes - i;
444 ret = 0;
445 break;
446 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200447
448 rwqe = ehea_get_next_rwqe(qp, rq_nr);
449 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200450 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200452 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453 rwqe->sg_list[0].len = packet_size;
454 rwqe->data_segments = 1;
455
456 index++;
457 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200458 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200459 }
Thomas Klein44c82152007-07-11 16:32:00 +0200460
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 if (adder == 0)
463 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200464
465 /* Ring doorbell */
466 iosync();
467 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200470 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200471out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472 return ret;
473}
474
475
476static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
477{
478 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
479 nr_of_wqes, EHEA_RWQE2_TYPE,
480 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
481}
482
483
484static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
485{
486 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
487 nr_of_wqes, EHEA_RWQE3_TYPE,
488 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
489}
490
491static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
492{
493 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
494 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
495 return 0;
496 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
497 (cqe->header_length == 0))
498 return 0;
499 return -EINVAL;
500}
501
502static inline void ehea_fill_skb(struct net_device *dev,
503 struct sk_buff *skb, struct ehea_cqe *cqe)
504{
505 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
506
507 skb_put(skb, length);
508 skb->ip_summed = CHECKSUM_UNNECESSARY;
509 skb->protocol = eth_type_trans(skb, dev);
510}
511
512static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
513 int arr_len,
514 struct ehea_cqe *cqe)
515{
516 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
517 struct sk_buff *skb;
518 void *pref;
519 int x;
520
521 x = skb_index + 1;
522 x &= (arr_len - 1);
523
524 pref = skb_array[x];
525 prefetchw(pref);
526 prefetchw(pref + EHEA_CACHE_LINE);
527
528 pref = (skb_array[x]->data);
529 prefetch(pref);
530 prefetch(pref + EHEA_CACHE_LINE);
531 prefetch(pref + EHEA_CACHE_LINE * 2);
532 prefetch(pref + EHEA_CACHE_LINE * 3);
533 skb = skb_array[skb_index];
534 skb_array[skb_index] = NULL;
535 return skb;
536}
537
538static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
539 int arr_len, int wqe_index)
540{
541 struct sk_buff *skb;
542 void *pref;
543 int x;
544
545 x = wqe_index + 1;
546 x &= (arr_len - 1);
547
548 pref = skb_array[x];
549 prefetchw(pref);
550 prefetchw(pref + EHEA_CACHE_LINE);
551
552 pref = (skb_array[x]->data);
553 prefetchw(pref);
554 prefetchw(pref + EHEA_CACHE_LINE);
555
556 skb = skb_array[wqe_index];
557 skb_array[wqe_index] = NULL;
558 return skb;
559}
560
561static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
562 struct ehea_cqe *cqe, int *processed_rq2,
563 int *processed_rq3)
564{
565 struct sk_buff *skb;
566
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100567 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
568 pr->p_stats.err_tcp_cksum++;
569 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
570 pr->p_stats.err_ip_cksum++;
571 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
572 pr->p_stats.err_frame_crc++;
573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200574 if (rq == 2) {
575 *processed_rq2 += 1;
576 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
577 dev_kfree_skb(skb);
578 } else if (rq == 3) {
579 *processed_rq3 += 1;
580 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
581 dev_kfree_skb(skb);
582 }
583
584 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100585 if (netif_msg_rx_err(pr->port)) {
586 ehea_error("Critical receive error for QP %d. "
587 "Resetting port.", pr->qp->init_attr.qp_nr);
588 ehea_dump(cqe, sizeof(*cqe), "CQE");
589 }
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200590 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200591 return 1;
592 }
593
594 return 0;
595}
596
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700597static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
598 void **tcph, u64 *hdr_flags, void *priv)
599{
600 struct ehea_cqe *cqe = priv;
601 unsigned int ip_len;
602 struct iphdr *iph;
603
604 /* non tcp/udp packets */
605 if (!cqe->header_length)
606 return -1;
607
608 /* non tcp packet */
609 skb_reset_network_header(skb);
610 iph = ip_hdr(skb);
611 if (iph->protocol != IPPROTO_TCP)
612 return -1;
613
614 ip_len = ip_hdrlen(skb);
615 skb_set_transport_header(skb, ip_len);
616 *tcph = tcp_hdr(skb);
617
618 /* check if ip header and tcp header are complete */
619 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
620 return -1;
621
622 *hdr_flags = LRO_IPV4 | LRO_TCP;
623 *iphdr = iph;
624
625 return 0;
626}
627
628static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
629 struct sk_buff *skb)
630{
631 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
632 && pr->port->vgrp;
633
634 if (use_lro) {
635 if (vlan_extracted)
636 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
637 pr->port->vgrp,
638 cqe->vlan_tag,
639 cqe);
640 else
641 lro_receive_skb(&pr->lro_mgr, skb, cqe);
642 } else {
643 if (vlan_extracted)
644 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
645 cqe->vlan_tag);
646 else
647 netif_receive_skb(skb);
648 }
649}
650
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700651static int ehea_proc_rwqes(struct net_device *dev,
652 struct ehea_port_res *pr,
653 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200654{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100655 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200656 struct ehea_qp *qp = pr->qp;
657 struct ehea_cqe *cqe;
658 struct sk_buff *skb;
659 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
660 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
661 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
662 int skb_arr_rq1_len = pr->rq1_skba.len;
663 int skb_arr_rq2_len = pr->rq2_skba.len;
664 int skb_arr_rq3_len = pr->rq3_skba.len;
665 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700666 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200667
668 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
669 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200670
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200671 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700672 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200673 ehea_inc_rq1(qp);
674 processed_rq1++;
675 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200676 if (netif_msg_rx_status(port))
677 ehea_dump(cqe, sizeof(*cqe), "CQE");
678
679 last_wqe_index = wqe_index;
680 rmb();
681 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600682 if (rq == 1) {
683 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200684 skb = get_skb_by_index_ll(skb_arr_rq1,
685 skb_arr_rq1_len,
686 wqe_index);
687 if (unlikely(!skb)) {
688 if (netif_msg_rx_err(port))
689 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100690
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700691 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200692 EHEA_L_PKT_SIZE);
693 if (!skb)
694 break;
695 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600696 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200697 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700698 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600699 } else if (rq == 2) {
700 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200701 skb = get_skb_by_index(skb_arr_rq2,
702 skb_arr_rq2_len, cqe);
703 if (unlikely(!skb)) {
704 if (netif_msg_rx_err(port))
705 ehea_error("rq2: skb=NULL");
706 break;
707 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700708 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200709 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600710 } else {
711 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712 skb = get_skb_by_index(skb_arr_rq3,
713 skb_arr_rq3_len, cqe);
714 if (unlikely(!skb)) {
715 if (netif_msg_rx_err(port))
716 ehea_error("rq3: skb=NULL");
717 break;
718 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700719 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720 processed_rq3++;
721 }
722
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700723 ehea_proc_skb(pr, cqe, skb);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700724 dev->last_rx = jiffies;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100725 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100726 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727 port_reset = ehea_treat_poll_error(pr, rq, cqe,
728 &processed_rq2,
729 &processed_rq3);
730 if (port_reset)
731 break;
732 }
733 cqe = ehea_poll_rq1(qp, &wqe_index);
734 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700735 if (use_lro)
736 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200738 pr->rx_packets += processed;
739
740 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
741 ehea_refill_rq2(pr, processed_rq2);
742 ehea_refill_rq3(pr, processed_rq3);
743
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700744 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745}
746
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100747static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100749 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750 struct ehea_cq *send_cq = pr->send_cq;
751 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100752 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200753 int cqe_counter = 0;
754 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100755 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756 unsigned long flags;
757
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100758 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600759 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100760 ehea_inc_cq(send_cq);
761
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200762 cqe_counter++;
763 rmb();
764 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
765 ehea_error("Send Completion Error: Resetting port");
766 if (netif_msg_tx_err(pr->port))
767 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200768 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200769 break;
770 }
771
772 if (netif_msg_tx_done(pr->port))
773 ehea_dump(cqe, sizeof(*cqe), "CQE");
774
775 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100776 == EHEA_SWQE2_TYPE)) {
777
778 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
779 skb = pr->sq_skba.arr[index];
780 dev_kfree_skb(skb);
781 pr->sq_skba.arr[index] = NULL;
782 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200783
784 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
785 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100786
787 cqe = ehea_poll_cq(send_cq);
788 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200789
790 ehea_update_feca(send_cq, cqe_counter);
791 atomic_add(swqe_av, &pr->swqe_avail);
792
793 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100794
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200795 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
796 >= pr->swqe_refill_th)) {
797 netif_wake_queue(pr->port->netdev);
798 pr->queue_stopped = 0;
799 }
800 spin_unlock_irqrestore(&pr->netif_queue, flags);
801
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100802 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200803}
804
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100805#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700806#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100807
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700808static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200809{
Doug Maxey508d2b52008-01-31 20:20:49 -0600810 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
811 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700812 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813 struct ehea_cqe *cqe;
814 struct ehea_cqe *cqe_skb = NULL;
815 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700816 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100817
818 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700819 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100820
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700821 if (!force_irq)
822 rx += ehea_proc_rwqes(dev, pr, budget - rx);
823
824 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100825 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700826 force_irq = 0;
827 netif_rx_complete(dev, napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100828 ehea_reset_cq_ep(pr->recv_cq);
829 ehea_reset_cq_ep(pr->send_cq);
830 ehea_reset_cq_n1(pr->recv_cq);
831 ehea_reset_cq_n1(pr->send_cq);
832 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
833 cqe_skb = ehea_poll_cq(pr->send_cq);
834
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100835 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700836 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100837
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700838 if (!netif_rx_reschedule(dev, napi))
839 return rx;
840
841 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
842 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100843 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100844
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700845 pr->poll_counter++;
846 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200847}
848
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200849#ifdef CONFIG_NET_POLL_CONTROLLER
850static void ehea_netpoll(struct net_device *dev)
851{
852 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700853 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200854
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700855 for (i = 0; i < port->num_def_qps; i++)
856 netif_rx_schedule(dev, &port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200857}
858#endif
859
David Howells7d12e782006-10-05 14:55:46 +0100860static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861{
862 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100863
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700864 netif_rx_schedule(pr->port->netdev, &pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100865
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200866 return IRQ_HANDLED;
867}
868
David Howells7d12e782006-10-05 14:55:46 +0100869static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200870{
871 struct ehea_port *port = param;
872 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100873 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200874 u32 qp_token;
875
876 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100877
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200878 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100880 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
881 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100882
883 qp = port->port_res[qp_token].qp;
884 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100885 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200886 }
887
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200888 schedule_work(&port->reset_task);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100889
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200890 return IRQ_HANDLED;
891}
892
893static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
894 int logical_port)
895{
896 int i;
897
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100898 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100899 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200900 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100901 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902 return NULL;
903}
904
905int ehea_sense_port_attr(struct ehea_port *port)
906{
907 int ret;
908 u64 hret;
909 struct hcp_ehea_port_cb0 *cb0;
910
Doug Maxey508d2b52008-01-31 20:20:49 -0600911 /* may be called via ehea_neq_tasklet() */
912 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
913 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200914 ehea_error("no mem for cb0");
915 ret = -ENOMEM;
916 goto out;
917 }
918
919 hret = ehea_h_query_ehea_port(port->adapter->handle,
920 port->logical_port_id, H_PORT_CB0,
921 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
922 cb0);
923 if (hret != H_SUCCESS) {
924 ret = -EIO;
925 goto out_free;
926 }
927
928 /* MAC address */
929 port->mac_addr = cb0->port_mac_addr << 16;
930
Doug Maxey508d2b52008-01-31 20:20:49 -0600931 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200932 ret = -EADDRNOTAVAIL;
933 goto out_free;
934 }
935
936 /* Port speed */
937 switch (cb0->port_speed) {
938 case H_SPEED_10M_H:
939 port->port_speed = EHEA_SPEED_10M;
940 port->full_duplex = 0;
941 break;
942 case H_SPEED_10M_F:
943 port->port_speed = EHEA_SPEED_10M;
944 port->full_duplex = 1;
945 break;
946 case H_SPEED_100M_H:
947 port->port_speed = EHEA_SPEED_100M;
948 port->full_duplex = 0;
949 break;
950 case H_SPEED_100M_F:
951 port->port_speed = EHEA_SPEED_100M;
952 port->full_duplex = 1;
953 break;
954 case H_SPEED_1G_F:
955 port->port_speed = EHEA_SPEED_1G;
956 port->full_duplex = 1;
957 break;
958 case H_SPEED_10G_F:
959 port->port_speed = EHEA_SPEED_10G;
960 port->full_duplex = 1;
961 break;
962 default:
963 port->port_speed = 0;
964 port->full_duplex = 0;
965 break;
966 }
967
Thomas Kleine919b592007-01-22 12:53:20 +0100968 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100969 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100970
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200971 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100972 if (use_mcs)
973 port->num_def_qps = cb0->num_default_qps;
974 else
975 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200976
977 if (!port->num_def_qps) {
978 ret = -EINVAL;
979 goto out_free;
980 }
981
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100982 port->num_tx_qps = num_tx_qps;
983
984 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 port->num_add_tx_qps = 0;
986 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100987 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988
989 ret = 0;
990out_free:
991 if (ret || netif_msg_probe(port))
992 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
993 kfree(cb0);
994out:
995 return ret;
996}
997
998int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
999{
1000 struct hcp_ehea_port_cb4 *cb4;
1001 u64 hret;
1002 int ret = 0;
1003
Thomas Kleina1d261c2006-11-03 17:48:23 +01001004 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001005 if (!cb4) {
1006 ehea_error("no mem for cb4");
1007 ret = -ENOMEM;
1008 goto out;
1009 }
1010
1011 cb4->port_speed = port_speed;
1012
1013 netif_carrier_off(port->netdev);
1014
1015 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1016 port->logical_port_id,
1017 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1018 if (hret == H_SUCCESS) {
1019 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1020
1021 hret = ehea_h_query_ehea_port(port->adapter->handle,
1022 port->logical_port_id,
1023 H_PORT_CB4, H_PORT_CB4_SPEED,
1024 cb4);
1025 if (hret == H_SUCCESS) {
1026 switch (cb4->port_speed) {
1027 case H_SPEED_10M_H:
1028 port->port_speed = EHEA_SPEED_10M;
1029 port->full_duplex = 0;
1030 break;
1031 case H_SPEED_10M_F:
1032 port->port_speed = EHEA_SPEED_10M;
1033 port->full_duplex = 1;
1034 break;
1035 case H_SPEED_100M_H:
1036 port->port_speed = EHEA_SPEED_100M;
1037 port->full_duplex = 0;
1038 break;
1039 case H_SPEED_100M_F:
1040 port->port_speed = EHEA_SPEED_100M;
1041 port->full_duplex = 1;
1042 break;
1043 case H_SPEED_1G_F:
1044 port->port_speed = EHEA_SPEED_1G;
1045 port->full_duplex = 1;
1046 break;
1047 case H_SPEED_10G_F:
1048 port->port_speed = EHEA_SPEED_10G;
1049 port->full_duplex = 1;
1050 break;
1051 default:
1052 port->port_speed = 0;
1053 port->full_duplex = 0;
1054 break;
1055 }
1056 } else {
1057 ehea_error("Failed sensing port speed");
1058 ret = -EIO;
1059 }
1060 } else {
1061 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001062 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001063 ret = -EPERM;
1064 } else {
1065 ret = -EIO;
1066 ehea_error("Failed setting port speed");
1067 }
1068 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001069 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1070 netif_carrier_on(port->netdev);
1071
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001072 kfree(cb4);
1073out:
1074 return ret;
1075}
1076
1077static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1078{
1079 int ret;
1080 u8 ec;
1081 u8 portnum;
1082 struct ehea_port *port;
1083
1084 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1085 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1086 port = ehea_get_port(adapter, portnum);
1087
1088 switch (ec) {
1089 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1090
1091 if (!port) {
1092 ehea_error("unknown portnum %x", portnum);
1093 break;
1094 }
1095
1096 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1097 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001098 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001099 if (ret) {
1100 ehea_error("failed resensing port "
1101 "attributes");
1102 break;
1103 }
1104
1105 if (netif_msg_link(port))
1106 ehea_info("%s: Logical port up: %dMbps "
1107 "%s Duplex",
1108 port->netdev->name,
1109 port->port_speed,
1110 port->full_duplex ==
1111 1 ? "Full" : "Half");
1112
1113 netif_carrier_on(port->netdev);
1114 netif_wake_queue(port->netdev);
1115 }
1116 } else
1117 if (netif_carrier_ok(port->netdev)) {
1118 if (netif_msg_link(port))
1119 ehea_info("%s: Logical port down",
1120 port->netdev->name);
1121 netif_carrier_off(port->netdev);
1122 netif_stop_queue(port->netdev);
1123 }
1124
1125 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001126 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001127 if (netif_msg_link(port))
1128 ehea_info("%s: Physical port up",
1129 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001130 if (prop_carrier_state)
1131 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001132 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001133 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 if (netif_msg_link(port))
1135 ehea_info("%s: Physical port down",
1136 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001137 if (prop_carrier_state)
1138 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 }
1140
1141 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1142 ehea_info("External switch port is primary port");
1143 else
1144 ehea_info("External switch port is backup port");
1145
1146 break;
1147 case EHEA_EC_ADAPTER_MALFUNC:
1148 ehea_error("Adapter malfunction");
1149 break;
1150 case EHEA_EC_PORT_MALFUNC:
1151 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1152 netif_carrier_off(port->netdev);
1153 netif_stop_queue(port->netdev);
1154 break;
1155 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001156 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001157 break;
1158 }
1159}
1160
1161static void ehea_neq_tasklet(unsigned long data)
1162{
Doug Maxey508d2b52008-01-31 20:20:49 -06001163 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001164 struct ehea_eqe *eqe;
1165 u64 event_mask;
1166
1167 eqe = ehea_poll_eq(adapter->neq);
1168 ehea_debug("eqe=%p", eqe);
1169
1170 while (eqe) {
1171 ehea_debug("*eqe=%lx", eqe->entry);
1172 ehea_parse_eqe(adapter, eqe->entry);
1173 eqe = ehea_poll_eq(adapter->neq);
1174 ehea_debug("next eqe=%p", eqe);
1175 }
1176
1177 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1178 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1179 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1180
1181 ehea_h_reset_events(adapter->handle,
1182 adapter->neq->fw_handle, event_mask);
1183}
1184
David Howells7d12e782006-10-05 14:55:46 +01001185static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001186{
1187 struct ehea_adapter *adapter = param;
1188 tasklet_hi_schedule(&adapter->neq_tasklet);
1189 return IRQ_HANDLED;
1190}
1191
1192
1193static int ehea_fill_port_res(struct ehea_port_res *pr)
1194{
1195 int ret;
1196 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1197
1198 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1199 - init_attr->act_nr_rwqes_rq2
1200 - init_attr->act_nr_rwqes_rq3 - 1);
1201
1202 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1203
1204 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1205
1206 return ret;
1207}
1208
1209static int ehea_reg_interrupts(struct net_device *dev)
1210{
1211 struct ehea_port *port = netdev_priv(dev);
1212 struct ehea_port_res *pr;
1213 int i, ret;
1214
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001215
1216 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1217 dev->name);
1218
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001219 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001220 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001221 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001222 if (ret) {
1223 ehea_error("failed registering irq for qp_aff_irq_handler:"
1224 "ist=%X", port->qp_eq->attr.ist1);
1225 goto out_free_qpeq;
1226 }
1227
1228 if (netif_msg_ifup(port))
1229 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1230 "registered", port->qp_eq->attr.ist1);
1231
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001232
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001233 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1234 pr = &port->port_res[i];
1235 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001236 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001237 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001238 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001239 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001240 pr);
1241 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001242 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001244 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245 goto out_free_req;
1246 }
1247 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001248 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1249 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250 }
1251out:
1252 return ret;
1253
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001254
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001255out_free_req:
1256 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001257 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001258 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001259 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001260
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001262 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001263 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001264
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001265 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001266
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001267}
1268
1269static void ehea_free_interrupts(struct net_device *dev)
1270{
1271 struct ehea_port *port = netdev_priv(dev);
1272 struct ehea_port_res *pr;
1273 int i;
1274
1275 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001276
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001277 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1278 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001279 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001280 if (netif_msg_intr(port))
1281 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001282 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283 }
1284
1285 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001286 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 if (netif_msg_intr(port))
1288 ehea_info("associated event interrupt for handle 0x%X freed",
1289 port->qp_eq->attr.ist1);
1290}
1291
1292static int ehea_configure_port(struct ehea_port *port)
1293{
1294 int ret, i;
1295 u64 hret, mask;
1296 struct hcp_ehea_port_cb0 *cb0;
1297
1298 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +01001299 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300 if (!cb0)
1301 goto out;
1302
1303 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1304 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1305 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1306 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1307 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1308 PXLY_RC_VLAN_FILTER)
1309 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1310
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001311 for (i = 0; i < port->num_mcs; i++)
1312 if (use_mcs)
1313 cb0->default_qpn_arr[i] =
1314 port->port_res[i].qp->init_attr.qp_nr;
1315 else
1316 cb0->default_qpn_arr[i] =
1317 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001318
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001319 if (netif_msg_ifup(port))
1320 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1321
1322 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1323 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1324
1325 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1326 port->logical_port_id,
1327 H_PORT_CB0, mask, cb0);
1328 ret = -EIO;
1329 if (hret != H_SUCCESS)
1330 goto out_free;
1331
1332 ret = 0;
1333
1334out_free:
1335 kfree(cb0);
1336out:
1337 return ret;
1338}
1339
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001340int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001341{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001342 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001343 struct ehea_adapter *adapter = pr->port->adapter;
1344
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001345 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1346 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 goto out;
1348
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001349 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1350 if (ret)
1351 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001352
1353 return 0;
1354
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001355out_free:
1356 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001358 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359 return -EIO;
1360}
1361
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001362int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001363{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001364 if ((ehea_rem_mr(&pr->send_mr))
1365 || (ehea_rem_mr(&pr->recv_mr)))
1366 return -EIO;
1367 else
1368 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369}
1370
1371static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1372{
Doug Maxey508d2b52008-01-31 20:20:49 -06001373 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374
1375 q_skba->arr = vmalloc(arr_size);
1376 if (!q_skba->arr)
1377 return -ENOMEM;
1378
1379 memset(q_skba->arr, 0, arr_size);
1380
1381 q_skba->len = max_q_entries;
1382 q_skba->index = 0;
1383 q_skba->os_skbs = 0;
1384
1385 return 0;
1386}
1387
1388static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1389 struct port_res_cfg *pr_cfg, int queue_token)
1390{
1391 struct ehea_adapter *adapter = port->adapter;
1392 enum ehea_eq_type eq_type = EHEA_EQ;
1393 struct ehea_qp_init_attr *init_attr = NULL;
1394 int ret = -EIO;
1395
1396 memset(pr, 0, sizeof(struct ehea_port_res));
1397
1398 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001399 spin_lock_init(&pr->xmit_lock);
1400 spin_lock_init(&pr->netif_queue);
1401
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001402 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1403 if (!pr->eq) {
1404 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001405 goto out_free;
1406 }
1407
1408 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001409 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410 port->logical_port_id);
1411 if (!pr->recv_cq) {
1412 ehea_error("create_cq failed (cq_recv)");
1413 goto out_free;
1414 }
1415
1416 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001417 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418 port->logical_port_id);
1419 if (!pr->send_cq) {
1420 ehea_error("create_cq failed (cq_send)");
1421 goto out_free;
1422 }
1423
1424 if (netif_msg_ifup(port))
1425 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1426 pr->send_cq->attr.act_nr_of_cqes,
1427 pr->recv_cq->attr.act_nr_of_cqes);
1428
1429 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1430 if (!init_attr) {
1431 ret = -ENOMEM;
1432 ehea_error("no mem for ehea_qp_init_attr");
1433 goto out_free;
1434 }
1435
1436 init_attr->low_lat_rq1 = 1;
1437 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1438 init_attr->rq_count = 3;
1439 init_attr->qp_token = queue_token;
1440 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1441 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1442 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1443 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1444 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1445 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1446 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1447 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1448 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1449 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1450 init_attr->port_nr = port->logical_port_id;
1451 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1452 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1453 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1454
1455 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1456 if (!pr->qp) {
1457 ehea_error("create_qp failed");
1458 ret = -EIO;
1459 goto out_free;
1460 }
1461
1462 if (netif_msg_ifup(port))
1463 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1464 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1465 init_attr->act_nr_send_wqes,
1466 init_attr->act_nr_rwqes_rq1,
1467 init_attr->act_nr_rwqes_rq2,
1468 init_attr->act_nr_rwqes_rq3);
1469
Thomas Klein44fb3122008-04-04 15:04:53 +02001470 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1471
1472 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001473 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1474 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1475 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1476 if (ret)
1477 goto out_free;
1478
1479 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1480 if (ehea_gen_smrs(pr) != 0) {
1481 ret = -EIO;
1482 goto out_free;
1483 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1486
1487 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001488
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001489 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001490
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001491 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1492 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1493 pr->lro_mgr.lro_arr = pr->lro_desc;
1494 pr->lro_mgr.get_skb_header = get_skb_hdr;
1495 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1496 pr->lro_mgr.dev = port->netdev;
1497 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1498 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500 ret = 0;
1501 goto out;
1502
1503out_free:
1504 kfree(init_attr);
1505 vfree(pr->sq_skba.arr);
1506 vfree(pr->rq1_skba.arr);
1507 vfree(pr->rq2_skba.arr);
1508 vfree(pr->rq3_skba.arr);
1509 ehea_destroy_qp(pr->qp);
1510 ehea_destroy_cq(pr->send_cq);
1511 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001512 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001513out:
1514 return ret;
1515}
1516
1517static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1518{
1519 int ret, i;
1520
1521 ret = ehea_destroy_qp(pr->qp);
1522
1523 if (!ret) {
1524 ehea_destroy_cq(pr->send_cq);
1525 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001526 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001527
1528 for (i = 0; i < pr->rq1_skba.len; i++)
1529 if (pr->rq1_skba.arr[i])
1530 dev_kfree_skb(pr->rq1_skba.arr[i]);
1531
1532 for (i = 0; i < pr->rq2_skba.len; i++)
1533 if (pr->rq2_skba.arr[i])
1534 dev_kfree_skb(pr->rq2_skba.arr[i]);
1535
1536 for (i = 0; i < pr->rq3_skba.len; i++)
1537 if (pr->rq3_skba.arr[i])
1538 dev_kfree_skb(pr->rq3_skba.arr[i]);
1539
1540 for (i = 0; i < pr->sq_skba.len; i++)
1541 if (pr->sq_skba.arr[i])
1542 dev_kfree_skb(pr->sq_skba.arr[i]);
1543
1544 vfree(pr->rq1_skba.arr);
1545 vfree(pr->rq2_skba.arr);
1546 vfree(pr->rq3_skba.arr);
1547 vfree(pr->sq_skba.arr);
1548 ret = ehea_rem_smrs(pr);
1549 }
1550 return ret;
1551}
1552
1553/*
1554 * The write_* functions store information in swqe which is used by
1555 * the hardware to calculate the ip/tcp/udp checksum
1556 */
1557
1558static inline void write_ip_start_end(struct ehea_swqe *swqe,
1559 const struct sk_buff *skb)
1560{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001561 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001562 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563}
1564
1565static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1566 const struct sk_buff *skb)
1567{
1568 swqe->tcp_offset =
1569 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1570
1571 swqe->tcp_end = (u16)skb->len - 1;
1572}
1573
1574static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1575 const struct sk_buff *skb)
1576{
1577 swqe->tcp_offset =
1578 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1579
1580 swqe->tcp_end = (u16)skb->len - 1;
1581}
1582
1583
1584static void write_swqe2_TSO(struct sk_buff *skb,
1585 struct ehea_swqe *swqe, u32 lkey)
1586{
1587 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1588 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1589 int skb_data_size = skb->len - skb->data_len;
1590 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001591
1592 /* Packet is TCP with TSO enabled */
1593 swqe->tx_control |= EHEA_SWQE_TSO;
1594 swqe->mss = skb_shinfo(skb)->gso_size;
1595 /* copy only eth/ip/tcp headers to immediate data and
1596 * the rest of skb->data to sg1entry
1597 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001598 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599
1600 skb_data_size = skb->len - skb->data_len;
1601
1602 if (skb_data_size >= headersize) {
1603 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001604 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001605 swqe->immediate_data_length = headersize;
1606
1607 if (skb_data_size > headersize) {
1608 /* set sg1entry data */
1609 sg1entry->l_key = lkey;
1610 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001611 sg1entry->vaddr =
1612 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001613 swqe->descriptors++;
1614 }
1615 } else
1616 ehea_error("cannot handle fragmented headers");
1617}
1618
1619static void write_swqe2_nonTSO(struct sk_buff *skb,
1620 struct ehea_swqe *swqe, u32 lkey)
1621{
1622 int skb_data_size = skb->len - skb->data_len;
1623 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1624 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625
1626 /* Packet is any nonTSO type
1627 *
1628 * Copy as much as possible skb->data to immediate data and
1629 * the rest to sg1entry
1630 */
1631 if (skb_data_size >= SWQE2_MAX_IMM) {
1632 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001633 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634
1635 swqe->immediate_data_length = SWQE2_MAX_IMM;
1636
1637 if (skb_data_size > SWQE2_MAX_IMM) {
1638 /* copy sg1entry data */
1639 sg1entry->l_key = lkey;
1640 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001641 sg1entry->vaddr =
1642 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643 swqe->descriptors++;
1644 }
1645 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001646 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001647 swqe->immediate_data_length = skb_data_size;
1648 }
1649}
1650
1651static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1652 struct ehea_swqe *swqe, u32 lkey)
1653{
1654 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1655 skb_frag_t *frag;
1656 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001657
1658 nfrags = skb_shinfo(skb)->nr_frags;
1659 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001660 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001661 swqe->descriptors = 0;
1662 sg1entry_contains_frag_data = 0;
1663
1664 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1665 write_swqe2_TSO(skb, swqe, lkey);
1666 else
1667 write_swqe2_nonTSO(skb, swqe, lkey);
1668
1669 /* write descriptors */
1670 if (nfrags > 0) {
1671 if (swqe->descriptors == 0) {
1672 /* sg1entry not yet used */
1673 frag = &skb_shinfo(skb)->frags[0];
1674
1675 /* copy sg1entry data */
1676 sg1entry->l_key = lkey;
1677 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001678 sg1entry->vaddr =
1679 ehea_map_vaddr(page_address(frag->page)
1680 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001681 swqe->descriptors++;
1682 sg1entry_contains_frag_data = 1;
1683 }
1684
1685 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1686
1687 frag = &skb_shinfo(skb)->frags[i];
1688 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1689
1690 sgentry->l_key = lkey;
1691 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001692 sgentry->vaddr =
1693 ehea_map_vaddr(page_address(frag->page)
1694 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001695 swqe->descriptors++;
1696 }
1697 }
1698}
1699
1700static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1701{
1702 int ret = 0;
1703 u64 hret;
1704 u8 reg_type;
1705
1706 /* De/Register untagged packets */
1707 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1708 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1709 port->logical_port_id,
1710 reg_type, port->mac_addr, 0, hcallid);
1711 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001712 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001713 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001714 ret = -EIO;
1715 goto out_herr;
1716 }
1717
1718 /* De/Register VLAN packets */
1719 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1720 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1721 port->logical_port_id,
1722 reg_type, port->mac_addr, 0, hcallid);
1723 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001724 ehea_error("%sregistering bc address failed (vlan)",
1725 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 ret = -EIO;
1727 }
1728out_herr:
1729 return ret;
1730}
1731
1732static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1733{
1734 struct ehea_port *port = netdev_priv(dev);
1735 struct sockaddr *mac_addr = sa;
1736 struct hcp_ehea_port_cb0 *cb0;
1737 int ret;
1738 u64 hret;
1739
1740 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1741 ret = -EADDRNOTAVAIL;
1742 goto out;
1743 }
1744
Thomas Kleina1d261c2006-11-03 17:48:23 +01001745 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746 if (!cb0) {
1747 ehea_error("no mem for cb0");
1748 ret = -ENOMEM;
1749 goto out;
1750 }
1751
1752 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1753
1754 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1755
1756 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1757 port->logical_port_id, H_PORT_CB0,
1758 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1759 if (hret != H_SUCCESS) {
1760 ret = -EIO;
1761 goto out_free;
1762 }
1763
1764 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1765
Daniel Walkerda59cde2008-03-28 14:41:28 -07001766 mutex_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001767
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768 /* Deregister old MAC in pHYP */
1769 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1770 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001771 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001772
1773 port->mac_addr = cb0->port_mac_addr << 16;
1774
1775 /* Register new MAC in pHYP */
1776 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1777 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001778 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779
1780 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001781
1782out_upregs:
1783 ehea_update_bcmc_registrations();
Daniel Walkerda59cde2008-03-28 14:41:28 -07001784 mutex_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785out_free:
1786 kfree(cb0);
1787out:
1788 return ret;
1789}
1790
1791static void ehea_promiscuous_error(u64 hret, int enable)
1792{
Thomas Klein7674a582007-01-22 12:54:20 +01001793 if (hret == H_AUTHORITY)
1794 ehea_info("Hypervisor denied %sabling promiscuous mode",
1795 enable == 1 ? "en" : "dis");
1796 else
1797 ehea_error("failed %sabling promiscuous mode",
1798 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799}
1800
1801static void ehea_promiscuous(struct net_device *dev, int enable)
1802{
1803 struct ehea_port *port = netdev_priv(dev);
1804 struct hcp_ehea_port_cb7 *cb7;
1805 u64 hret;
1806
1807 if ((enable && port->promisc) || (!enable && !port->promisc))
1808 return;
1809
Thomas Kleina1d261c2006-11-03 17:48:23 +01001810 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001811 if (!cb7) {
1812 ehea_error("no mem for cb7");
1813 goto out;
1814 }
1815
1816 /* Modify Pxs_DUCQPN in CB7 */
1817 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1818
1819 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1820 port->logical_port_id,
1821 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1822 if (hret) {
1823 ehea_promiscuous_error(hret, enable);
1824 goto out;
1825 }
1826
1827 port->promisc = enable;
1828out:
1829 kfree(cb7);
1830 return;
1831}
1832
1833static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1834 u32 hcallid)
1835{
1836 u64 hret;
1837 u8 reg_type;
1838
1839 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1840 | EHEA_BCMC_UNTAGGED;
1841
1842 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1843 port->logical_port_id,
1844 reg_type, mc_mac_addr, 0, hcallid);
1845 if (hret)
1846 goto out;
1847
1848 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1849 | EHEA_BCMC_VLANID_ALL;
1850
1851 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1852 port->logical_port_id,
1853 reg_type, mc_mac_addr, 0, hcallid);
1854out:
1855 return hret;
1856}
1857
1858static int ehea_drop_multicast_list(struct net_device *dev)
1859{
1860 struct ehea_port *port = netdev_priv(dev);
1861 struct ehea_mc_list *mc_entry = port->mc_list;
1862 struct list_head *pos;
1863 struct list_head *temp;
1864 int ret = 0;
1865 u64 hret;
1866
1867 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1868 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1869
1870 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1871 H_DEREG_BCMC);
1872 if (hret) {
1873 ehea_error("failed deregistering mcast MAC");
1874 ret = -EIO;
1875 }
1876
1877 list_del(pos);
1878 kfree(mc_entry);
1879 }
1880 return ret;
1881}
1882
1883static void ehea_allmulti(struct net_device *dev, int enable)
1884{
1885 struct ehea_port *port = netdev_priv(dev);
1886 u64 hret;
1887
1888 if (!port->allmulti) {
1889 if (enable) {
1890 /* Enable ALLMULTI */
1891 ehea_drop_multicast_list(dev);
1892 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1893 if (!hret)
1894 port->allmulti = 1;
1895 else
1896 ehea_error("failed enabling IFF_ALLMULTI");
1897 }
1898 } else
1899 if (!enable) {
1900 /* Disable ALLMULTI */
1901 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1902 if (!hret)
1903 port->allmulti = 0;
1904 else
1905 ehea_error("failed disabling IFF_ALLMULTI");
1906 }
1907}
1908
Doug Maxey508d2b52008-01-31 20:20:49 -06001909static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001910{
1911 struct ehea_mc_list *ehea_mcl_entry;
1912 u64 hret;
1913
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001914 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001915 if (!ehea_mcl_entry) {
1916 ehea_error("no mem for mcl_entry");
1917 return;
1918 }
1919
1920 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1921
1922 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1923
1924 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1925 H_REG_BCMC);
1926 if (!hret)
1927 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1928 else {
1929 ehea_error("failed registering mcast MAC");
1930 kfree(ehea_mcl_entry);
1931 }
1932}
1933
1934static void ehea_set_multicast_list(struct net_device *dev)
1935{
1936 struct ehea_port *port = netdev_priv(dev);
1937 struct dev_mc_list *k_mcl_entry;
1938 int ret, i;
1939
1940 if (dev->flags & IFF_PROMISC) {
1941 ehea_promiscuous(dev, 1);
1942 return;
1943 }
1944 ehea_promiscuous(dev, 0);
1945
Daniel Walkerda59cde2008-03-28 14:41:28 -07001946 mutex_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001947
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948 if (dev->flags & IFF_ALLMULTI) {
1949 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001950 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951 }
1952 ehea_allmulti(dev, 0);
1953
1954 if (dev->mc_count) {
1955 ret = ehea_drop_multicast_list(dev);
1956 if (ret) {
1957 /* Dropping the current multicast list failed.
1958 * Enabling ALL_MULTI is the best we can do.
1959 */
1960 ehea_allmulti(dev, 1);
1961 }
1962
1963 if (dev->mc_count > port->adapter->max_mc_mac) {
1964 ehea_info("Mcast registration limit reached (0x%lx). "
1965 "Use ALLMULTI!",
1966 port->adapter->max_mc_mac);
1967 goto out;
1968 }
1969
Doug Maxey508d2b52008-01-31 20:20:49 -06001970 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1971 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001972 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001973
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001974 }
1975out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001976 ehea_update_bcmc_registrations();
Daniel Walkerda59cde2008-03-28 14:41:28 -07001977 mutex_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001978 return;
1979}
1980
1981static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1982{
1983 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1984 return -EINVAL;
1985 dev->mtu = new_mtu;
1986 return 0;
1987}
1988
1989static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1990 struct ehea_swqe *swqe, u32 lkey)
1991{
1992 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001993 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001994
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001995 /* IPv4 */
1996 swqe->tx_control |= EHEA_SWQE_CRC
1997 | EHEA_SWQE_IP_CHECKSUM
1998 | EHEA_SWQE_TCP_CHECKSUM
1999 | EHEA_SWQE_IMM_DATA_PRESENT
2000 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2001
2002 write_ip_start_end(swqe, skb);
2003
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002004 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002005 if ((iph->frag_off & IP_MF)
2006 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002007 /* IP fragment, so don't change cs */
2008 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2009 else
2010 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002011 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002012 write_tcp_offset_end(swqe, skb);
2013 }
2014
2015 /* icmp (big data) and ip segmentation packets (all other ip
2016 packets) do not require any special handling */
2017
2018 } else {
2019 /* Other Ethernet Protocol */
2020 swqe->tx_control |= EHEA_SWQE_CRC
2021 | EHEA_SWQE_IMM_DATA_PRESENT
2022 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2023 }
2024
2025 write_swqe2_data(skb, dev, swqe, lkey);
2026}
2027
2028static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2029 struct ehea_swqe *swqe)
2030{
2031 int nfrags = skb_shinfo(skb)->nr_frags;
2032 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2033 skb_frag_t *frag;
2034 int i;
2035
2036 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002037 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002038
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002039 /* IPv4 */
2040 write_ip_start_end(swqe, skb);
2041
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002042 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 swqe->tx_control |= EHEA_SWQE_CRC
2044 | EHEA_SWQE_IP_CHECKSUM
2045 | EHEA_SWQE_TCP_CHECKSUM
2046 | EHEA_SWQE_IMM_DATA_PRESENT;
2047
2048 write_tcp_offset_end(swqe, skb);
2049
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002050 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002051 if ((iph->frag_off & IP_MF)
2052 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053 /* IP fragment, so don't change cs */
2054 swqe->tx_control |= EHEA_SWQE_CRC
2055 | EHEA_SWQE_IMM_DATA_PRESENT;
2056 else {
2057 swqe->tx_control |= EHEA_SWQE_CRC
2058 | EHEA_SWQE_IP_CHECKSUM
2059 | EHEA_SWQE_TCP_CHECKSUM
2060 | EHEA_SWQE_IMM_DATA_PRESENT;
2061
2062 write_udp_offset_end(swqe, skb);
2063 }
2064 } else {
2065 /* icmp (big data) and
2066 ip segmentation packets (all other ip packets) */
2067 swqe->tx_control |= EHEA_SWQE_CRC
2068 | EHEA_SWQE_IP_CHECKSUM
2069 | EHEA_SWQE_IMM_DATA_PRESENT;
2070 }
2071 } else {
2072 /* Other Ethernet Protocol */
2073 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2074 }
2075 /* copy (immediate) data */
2076 if (nfrags == 0) {
2077 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002078 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002079 } else {
2080 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002081 skb_copy_from_linear_data(skb, imm_data,
2082 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002083 imm_data += skb->len - skb->data_len;
2084
2085 /* ... then copy data from the fragments */
2086 for (i = 0; i < nfrags; i++) {
2087 frag = &skb_shinfo(skb)->frags[i];
2088 memcpy(imm_data,
2089 page_address(frag->page) + frag->page_offset,
2090 frag->size);
2091 imm_data += frag->size;
2092 }
2093 }
2094 swqe->immediate_data_length = skb->len;
2095 dev_kfree_skb(skb);
2096}
2097
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002098static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2099{
2100 struct tcphdr *tcp;
2101 u32 tmp;
2102
2103 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002104 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002105 tcp = (struct tcphdr *)(skb_network_header(skb) +
2106 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002107 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002108 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002109 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002110 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002111 return 0;
2112}
2113
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002114static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2115{
2116 struct ehea_port *port = netdev_priv(dev);
2117 struct ehea_swqe *swqe;
2118 unsigned long flags;
2119 u32 lkey;
2120 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002121 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002122
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002123 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2124
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002125 if (!spin_trylock(&pr->xmit_lock))
2126 return NETDEV_TX_BUSY;
2127
2128 if (pr->queue_stopped) {
2129 spin_unlock(&pr->xmit_lock);
2130 return NETDEV_TX_BUSY;
2131 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002132
2133 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2134 memset(swqe, 0, SWQE_HEADER_SIZE);
2135 atomic_dec(&pr->swqe_avail);
2136
2137 if (skb->len <= SWQE3_MAX_IMM) {
2138 u32 sig_iv = port->sig_comp_iv;
2139 u32 swqe_num = pr->swqe_id_counter;
2140 ehea_xmit3(skb, dev, swqe);
2141 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2142 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2143 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2144 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2145 sig_iv);
2146 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2147 pr->swqe_ll_count = 0;
2148 } else
2149 pr->swqe_ll_count += 1;
2150 } else {
2151 swqe->wr_id =
2152 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2153 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002154 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002155 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2156 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2157
2158 pr->sq_skba.index++;
2159 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2160
2161 lkey = pr->send_mr.lkey;
2162 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002163 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164 }
2165 pr->swqe_id_counter += 1;
2166
2167 if (port->vgrp && vlan_tx_tag_present(skb)) {
2168 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2169 swqe->vlan_tag = vlan_tx_tag_get(skb);
2170 }
2171
2172 if (netif_msg_tx_queued(port)) {
2173 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002174 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002175 }
2176
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002177 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2178 netif_stop_queue(dev);
2179 swqe->tx_control |= EHEA_SWQE_PURGE;
2180 }
Thomas Klein44c82152007-07-11 16:32:00 +02002181
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002183 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184
2185 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2186 spin_lock_irqsave(&pr->netif_queue, flags);
2187 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002188 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189 netif_stop_queue(dev);
2190 pr->queue_stopped = 1;
2191 }
2192 spin_unlock_irqrestore(&pr->netif_queue, flags);
2193 }
2194 dev->trans_start = jiffies;
2195 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002196
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002197 return NETDEV_TX_OK;
2198}
2199
2200static void ehea_vlan_rx_register(struct net_device *dev,
2201 struct vlan_group *grp)
2202{
2203 struct ehea_port *port = netdev_priv(dev);
2204 struct ehea_adapter *adapter = port->adapter;
2205 struct hcp_ehea_port_cb1 *cb1;
2206 u64 hret;
2207
2208 port->vgrp = grp;
2209
Thomas Kleina1d261c2006-11-03 17:48:23 +01002210 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002211 if (!cb1) {
2212 ehea_error("no mem for cb1");
2213 goto out;
2214 }
2215
Thomas Kleindec590c2007-06-06 20:53:16 +02002216 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002217
2218 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2219 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2220 if (hret != H_SUCCESS)
2221 ehea_error("modify_ehea_port failed");
2222
2223 kfree(cb1);
2224out:
2225 return;
2226}
2227
2228static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2229{
2230 struct ehea_port *port = netdev_priv(dev);
2231 struct ehea_adapter *adapter = port->adapter;
2232 struct hcp_ehea_port_cb1 *cb1;
2233 int index;
2234 u64 hret;
2235
Thomas Kleina1d261c2006-11-03 17:48:23 +01002236 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002237 if (!cb1) {
2238 ehea_error("no mem for cb1");
2239 goto out;
2240 }
2241
2242 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2243 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2244 if (hret != H_SUCCESS) {
2245 ehea_error("query_ehea_port failed");
2246 goto out;
2247 }
2248
2249 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002250 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251
2252 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2253 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2254 if (hret != H_SUCCESS)
2255 ehea_error("modify_ehea_port failed");
2256out:
2257 kfree(cb1);
2258 return;
2259}
2260
2261static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2262{
2263 struct ehea_port *port = netdev_priv(dev);
2264 struct ehea_adapter *adapter = port->adapter;
2265 struct hcp_ehea_port_cb1 *cb1;
2266 int index;
2267 u64 hret;
2268
Dan Aloni5c15bde2007-03-02 20:44:51 -08002269 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002270
Thomas Kleina1d261c2006-11-03 17:48:23 +01002271 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002272 if (!cb1) {
2273 ehea_error("no mem for cb1");
2274 goto out;
2275 }
2276
2277 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2278 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2279 if (hret != H_SUCCESS) {
2280 ehea_error("query_ehea_port failed");
2281 goto out;
2282 }
2283
2284 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002285 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002286
2287 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2288 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2289 if (hret != H_SUCCESS)
2290 ehea_error("modify_ehea_port failed");
2291out:
2292 kfree(cb1);
2293 return;
2294}
2295
2296int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2297{
2298 int ret = -EIO;
2299 u64 hret;
2300 u16 dummy16 = 0;
2301 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002302 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303
Thomas Kleina1d261c2006-11-03 17:48:23 +01002304 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002305 if (!cb0) {
2306 ret = -ENOMEM;
2307 goto out;
2308 }
2309
2310 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2311 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2312 if (hret != H_SUCCESS) {
2313 ehea_error("query_ehea_qp failed (1)");
2314 goto out;
2315 }
2316
2317 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2318 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2319 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2320 &dummy64, &dummy64, &dummy16, &dummy16);
2321 if (hret != H_SUCCESS) {
2322 ehea_error("modify_ehea_qp failed (1)");
2323 goto out;
2324 }
2325
2326 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2327 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2328 if (hret != H_SUCCESS) {
2329 ehea_error("query_ehea_qp failed (2)");
2330 goto out;
2331 }
2332
2333 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2334 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2335 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2336 &dummy64, &dummy64, &dummy16, &dummy16);
2337 if (hret != H_SUCCESS) {
2338 ehea_error("modify_ehea_qp failed (2)");
2339 goto out;
2340 }
2341
2342 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2343 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2344 if (hret != H_SUCCESS) {
2345 ehea_error("query_ehea_qp failed (3)");
2346 goto out;
2347 }
2348
2349 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2350 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2351 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2352 &dummy64, &dummy64, &dummy16, &dummy16);
2353 if (hret != H_SUCCESS) {
2354 ehea_error("modify_ehea_qp failed (3)");
2355 goto out;
2356 }
2357
2358 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2359 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2360 if (hret != H_SUCCESS) {
2361 ehea_error("query_ehea_qp failed (4)");
2362 goto out;
2363 }
2364
2365 ret = 0;
2366out:
2367 kfree(cb0);
2368 return ret;
2369}
2370
2371static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2372 int add_tx_qps)
2373{
2374 int ret, i;
2375 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2376 enum ehea_eq_type eq_type = EHEA_EQ;
2377
2378 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2379 EHEA_MAX_ENTRIES_EQ, 1);
2380 if (!port->qp_eq) {
2381 ret = -EINVAL;
2382 ehea_error("ehea_create_eq failed (qp_eq)");
2383 goto out_kill_eq;
2384 }
2385
2386 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002387 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002388 pr_cfg.max_entries_sq = sq_entries;
2389 pr_cfg.max_entries_rq1 = rq1_entries;
2390 pr_cfg.max_entries_rq2 = rq2_entries;
2391 pr_cfg.max_entries_rq3 = rq3_entries;
2392
2393 pr_cfg_small_rx.max_entries_rcq = 1;
2394 pr_cfg_small_rx.max_entries_scq = sq_entries;
2395 pr_cfg_small_rx.max_entries_sq = sq_entries;
2396 pr_cfg_small_rx.max_entries_rq1 = 1;
2397 pr_cfg_small_rx.max_entries_rq2 = 1;
2398 pr_cfg_small_rx.max_entries_rq3 = 1;
2399
2400 for (i = 0; i < def_qps; i++) {
2401 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2402 if (ret)
2403 goto out_clean_pr;
2404 }
2405 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2406 ret = ehea_init_port_res(port, &port->port_res[i],
2407 &pr_cfg_small_rx, i);
2408 if (ret)
2409 goto out_clean_pr;
2410 }
2411
2412 return 0;
2413
2414out_clean_pr:
2415 while (--i >= 0)
2416 ehea_clean_portres(port, &port->port_res[i]);
2417
2418out_kill_eq:
2419 ehea_destroy_eq(port->qp_eq);
2420 return ret;
2421}
2422
2423static int ehea_clean_all_portres(struct ehea_port *port)
2424{
2425 int ret = 0;
2426 int i;
2427
Doug Maxey508d2b52008-01-31 20:20:49 -06002428 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002429 ret |= ehea_clean_portres(port, &port->port_res[i]);
2430
2431 ret |= ehea_destroy_eq(port->qp_eq);
2432
2433 return ret;
2434}
2435
Thomas Klein35cf2e22007-08-06 13:55:14 +02002436static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002437{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002438 if (adapter->active_ports)
2439 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002440
2441 ehea_rem_mr(&adapter->mr);
2442}
2443
Thomas Klein35cf2e22007-08-06 13:55:14 +02002444static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002445{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002446 if (adapter->active_ports)
2447 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002448
2449 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2450}
2451
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002452static int ehea_up(struct net_device *dev)
2453{
2454 int ret, i;
2455 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002456
2457 if (port->state == EHEA_PORT_UP)
2458 return 0;
2459
Daniel Walker9f71a562008-03-28 14:41:26 -07002460 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002461
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 ret = ehea_port_res_setup(port, port->num_def_qps,
2463 port->num_add_tx_qps);
2464 if (ret) {
2465 ehea_error("port_res_failed");
2466 goto out;
2467 }
2468
2469 /* Set default QP for this port */
2470 ret = ehea_configure_port(port);
2471 if (ret) {
2472 ehea_error("ehea_configure_port failed. ret:%d", ret);
2473 goto out_clean_pr;
2474 }
2475
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002476 ret = ehea_reg_interrupts(dev);
2477 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002478 ehea_error("reg_interrupts failed. ret:%d", ret);
2479 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002480 }
2481
Doug Maxey508d2b52008-01-31 20:20:49 -06002482 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2484 if (ret) {
2485 ehea_error("activate_qp failed");
2486 goto out_free_irqs;
2487 }
2488 }
2489
Doug Maxey508d2b52008-01-31 20:20:49 -06002490 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002491 ret = ehea_fill_port_res(&port->port_res[i]);
2492 if (ret) {
2493 ehea_error("out_free_irqs");
2494 goto out_free_irqs;
2495 }
2496 }
2497
Daniel Walkerda59cde2008-03-28 14:41:28 -07002498 mutex_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002499
2500 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2501 if (ret) {
2502 ret = -EIO;
2503 goto out_free_irqs;
2504 }
2505
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002506 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002507
2508 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002509 goto out;
2510
2511out_free_irqs:
2512 ehea_free_interrupts(dev);
2513
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002514out_clean_pr:
2515 ehea_clean_all_portres(port);
2516out:
Thomas Klein44c82152007-07-11 16:32:00 +02002517 if (ret)
2518 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2519
Thomas Klein21eee2d2008-02-13 16:18:33 +01002520 ehea_update_bcmc_registrations();
Daniel Walkerda59cde2008-03-28 14:41:28 -07002521 mutex_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002522
2523 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002524 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002525
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002526 return ret;
2527}
2528
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002529static void port_napi_disable(struct ehea_port *port)
2530{
2531 int i;
2532
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002533 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002534 napi_disable(&port->port_res[i].napi);
2535}
2536
2537static void port_napi_enable(struct ehea_port *port)
2538{
2539 int i;
2540
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002541 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002542 napi_enable(&port->port_res[i].napi);
2543}
2544
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002545static int ehea_open(struct net_device *dev)
2546{
2547 int ret;
2548 struct ehea_port *port = netdev_priv(dev);
2549
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002550 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002551
2552 if (netif_msg_ifup(port))
2553 ehea_info("enabling port %s", dev->name);
2554
2555 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002556 if (!ret) {
2557 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002559 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002560
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002561 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002562
2563 return ret;
2564}
2565
2566static int ehea_down(struct net_device *dev)
2567{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002568 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569 struct ehea_port *port = netdev_priv(dev);
2570
2571 if (port->state == EHEA_PORT_DOWN)
2572 return 0;
2573
Daniel Walkerdbbcbb22008-03-28 14:41:27 -07002574 mutex_lock(&ehea_fw_handles.lock);
2575
Daniel Walkerda59cde2008-03-28 14:41:28 -07002576 mutex_lock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002577 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002578 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2579
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580 ehea_free_interrupts(dev);
2581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002582 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002583
Thomas Klein21eee2d2008-02-13 16:18:33 +01002584 ehea_update_bcmc_registrations();
Daniel Walkerda59cde2008-03-28 14:41:28 -07002585 mutex_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002586
Thomas Klein44c82152007-07-11 16:32:00 +02002587 ret = ehea_clean_all_portres(port);
2588 if (ret)
2589 ehea_info("Failed freeing resources for %s. ret=%i",
2590 dev->name, ret);
2591
Thomas Klein21eee2d2008-02-13 16:18:33 +01002592 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002593 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002594
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002595 return ret;
2596}
2597
2598static int ehea_stop(struct net_device *dev)
2599{
2600 int ret;
2601 struct ehea_port *port = netdev_priv(dev);
2602
2603 if (netif_msg_ifdown(port))
2604 ehea_info("disabling port %s", dev->name);
2605
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002606 flush_scheduled_work();
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002607 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002608 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002609 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002611 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612 return ret;
2613}
2614
Andrew Morton22559c52008-04-18 13:50:39 -07002615static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002616{
2617 struct ehea_qp qp = *orig_qp;
2618 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2619 struct ehea_swqe *swqe;
2620 int wqe_index;
2621 int i;
2622
2623 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2624 swqe = ehea_get_swqe(&qp, &wqe_index);
2625 swqe->tx_control |= EHEA_SWQE_PURGE;
2626 }
2627}
2628
Andrew Morton22559c52008-04-18 13:50:39 -07002629static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002630{
2631 int i;
2632
2633 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2634 struct ehea_port_res *pr = &port->port_res[i];
2635 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2636 int k = 0;
2637 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2638 msleep(5);
2639 if (++k == 20)
2640 break;
2641 }
2642 }
2643}
2644
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002645int ehea_stop_qps(struct net_device *dev)
2646{
2647 struct ehea_port *port = netdev_priv(dev);
2648 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002649 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002650 int ret = -EIO;
2651 int dret;
2652 int i;
2653 u64 hret;
2654 u64 dummy64 = 0;
2655 u16 dummy16 = 0;
2656
2657 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2658 if (!cb0) {
2659 ret = -ENOMEM;
2660 goto out;
2661 }
2662
2663 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2664 struct ehea_port_res *pr = &port->port_res[i];
2665 struct ehea_qp *qp = pr->qp;
2666
2667 /* Purge send queue */
2668 ehea_purge_sq(qp);
2669
2670 /* Disable queue pair */
2671 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2672 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2673 cb0);
2674 if (hret != H_SUCCESS) {
2675 ehea_error("query_ehea_qp failed (1)");
2676 goto out;
2677 }
2678
2679 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2680 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2681
2682 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2683 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2684 1), cb0, &dummy64,
2685 &dummy64, &dummy16, &dummy16);
2686 if (hret != H_SUCCESS) {
2687 ehea_error("modify_ehea_qp failed (1)");
2688 goto out;
2689 }
2690
2691 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2692 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2693 cb0);
2694 if (hret != H_SUCCESS) {
2695 ehea_error("query_ehea_qp failed (2)");
2696 goto out;
2697 }
2698
2699 /* deregister shared memory regions */
2700 dret = ehea_rem_smrs(pr);
2701 if (dret) {
2702 ehea_error("unreg shared memory region failed");
2703 goto out;
2704 }
2705 }
2706
2707 ret = 0;
2708out:
2709 kfree(cb0);
2710
2711 return ret;
2712}
2713
Doug Maxey508d2b52008-01-31 20:20:49 -06002714void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002715{
2716 struct ehea_qp qp = *orig_qp;
2717 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2718 struct ehea_rwqe *rwqe;
2719 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2720 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2721 struct sk_buff *skb;
2722 u32 lkey = pr->recv_mr.lkey;
2723
2724
2725 int i;
2726 int index;
2727
2728 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2729 rwqe = ehea_get_next_rwqe(&qp, 2);
2730 rwqe->sg_list[0].l_key = lkey;
2731 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2732 skb = skba_rq2[index];
2733 if (skb)
2734 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2735 }
2736
2737 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2738 rwqe = ehea_get_next_rwqe(&qp, 3);
2739 rwqe->sg_list[0].l_key = lkey;
2740 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2741 skb = skba_rq3[index];
2742 if (skb)
2743 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2744 }
2745}
2746
2747int ehea_restart_qps(struct net_device *dev)
2748{
2749 struct ehea_port *port = netdev_priv(dev);
2750 struct ehea_adapter *adapter = port->adapter;
2751 int ret = 0;
2752 int i;
2753
Doug Maxey508d2b52008-01-31 20:20:49 -06002754 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002755 u64 hret;
2756 u64 dummy64 = 0;
2757 u16 dummy16 = 0;
2758
2759 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2760 if (!cb0) {
2761 ret = -ENOMEM;
2762 goto out;
2763 }
2764
2765 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2766 struct ehea_port_res *pr = &port->port_res[i];
2767 struct ehea_qp *qp = pr->qp;
2768
2769 ret = ehea_gen_smrs(pr);
2770 if (ret) {
2771 ehea_error("creation of shared memory regions failed");
2772 goto out;
2773 }
2774
2775 ehea_update_rqs(qp, pr);
2776
2777 /* Enable queue pair */
2778 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2779 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2780 cb0);
2781 if (hret != H_SUCCESS) {
2782 ehea_error("query_ehea_qp failed (1)");
2783 goto out;
2784 }
2785
2786 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2787 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2788
2789 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2790 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2791 1), cb0, &dummy64,
2792 &dummy64, &dummy16, &dummy16);
2793 if (hret != H_SUCCESS) {
2794 ehea_error("modify_ehea_qp failed (1)");
2795 goto out;
2796 }
2797
2798 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2799 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2800 cb0);
2801 if (hret != H_SUCCESS) {
2802 ehea_error("query_ehea_qp failed (2)");
2803 goto out;
2804 }
2805
2806 /* refill entire queue */
2807 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2808 ehea_refill_rq2(pr, 0);
2809 ehea_refill_rq3(pr, 0);
2810 }
2811out:
2812 kfree(cb0);
2813
2814 return ret;
2815}
2816
David Howellsc4028952006-11-22 14:57:56 +00002817static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002818{
2819 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002820 struct ehea_port *port =
2821 container_of(work, struct ehea_port, reset_task);
2822 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002823
2824 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002825 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002826 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002827
2828 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002829
Thomas Klein44c82152007-07-11 16:32:00 +02002830 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002831
2832 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002833 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002834 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002835
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002836 ehea_set_multicast_list(dev);
2837
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002838 if (netif_msg_timer(port))
2839 ehea_info("Device %s resetted successfully", dev->name);
2840
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002841 port_napi_enable(port);
2842
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002843 netif_wake_queue(dev);
2844out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002845 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002846 return;
2847}
2848
Thomas Klein44c82152007-07-11 16:32:00 +02002849static void ehea_rereg_mrs(struct work_struct *work)
2850{
2851 int ret, i;
2852 struct ehea_adapter *adapter;
2853
Daniel Walker06f89ed2008-03-28 14:41:26 -07002854 mutex_lock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002855 ehea_info("LPAR memory enlarged - re-initializing driver");
2856
2857 list_for_each_entry(adapter, &adapter_list, list)
2858 if (adapter->active_ports) {
2859 /* Shutdown all ports */
2860 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2861 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002862 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002863
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002864 if (!port)
2865 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002866
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002867 dev = port->netdev;
2868
2869 if (dev->flags & IFF_UP) {
2870 mutex_lock(&port->port_lock);
2871 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002872 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002873 ret = ehea_stop_qps(dev);
2874 if (ret) {
2875 mutex_unlock(&port->port_lock);
2876 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002877 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002878 port_napi_disable(port);
2879 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002880 }
2881 }
2882
2883 /* Unregister old memory region */
2884 ret = ehea_rem_mr(&adapter->mr);
2885 if (ret) {
2886 ehea_error("unregister MR failed - driver"
2887 " inoperable!");
2888 goto out;
2889 }
2890 }
2891
2892 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002893 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002894 if (ret) {
2895 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002896 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002897 }
Thomas Klein44c82152007-07-11 16:32:00 +02002898
2899 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2900
2901 list_for_each_entry(adapter, &adapter_list, list)
2902 if (adapter->active_ports) {
2903 /* Register new memory region */
2904 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2905 if (ret) {
2906 ehea_error("register MR failed - driver"
2907 " inoperable!");
2908 goto out;
2909 }
2910
2911 /* Restart all ports */
2912 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2913 struct ehea_port *port = adapter->port[i];
2914
2915 if (port) {
2916 struct net_device *dev = port->netdev;
2917
2918 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002919 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002920 port_napi_enable(port);
2921 ret = ehea_restart_qps(dev);
2922 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002923 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002924 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002925 }
2926 }
2927 }
2928 }
Daniel Walker06f89ed2008-03-28 14:41:26 -07002929 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002930 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002931out:
2932 return;
2933}
2934
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002935static void ehea_tx_watchdog(struct net_device *dev)
2936{
2937 struct ehea_port *port = netdev_priv(dev);
2938
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002939 if (netif_carrier_ok(dev) &&
2940 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002941 schedule_work(&port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002942}
2943
2944int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2945{
2946 struct hcp_query_ehea *cb;
2947 u64 hret;
2948 int ret;
2949
Thomas Kleina1d261c2006-11-03 17:48:23 +01002950 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002951 if (!cb) {
2952 ret = -ENOMEM;
2953 goto out;
2954 }
2955
2956 hret = ehea_h_query_ehea(adapter->handle, cb);
2957
2958 if (hret != H_SUCCESS) {
2959 ret = -EIO;
2960 goto out_herr;
2961 }
2962
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002963 adapter->max_mc_mac = cb->max_mc_mac - 1;
2964 ret = 0;
2965
2966out_herr:
2967 kfree(cb);
2968out:
2969 return ret;
2970}
2971
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002972int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2973{
2974 struct hcp_ehea_port_cb4 *cb4;
2975 u64 hret;
2976 int ret = 0;
2977
2978 *jumbo = 0;
2979
2980 /* (Try to) enable *jumbo frames */
2981 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2982 if (!cb4) {
2983 ehea_error("no mem for cb4");
2984 ret = -ENOMEM;
2985 goto out;
2986 } else {
2987 hret = ehea_h_query_ehea_port(port->adapter->handle,
2988 port->logical_port_id,
2989 H_PORT_CB4,
2990 H_PORT_CB4_JUMBO, cb4);
2991 if (hret == H_SUCCESS) {
2992 if (cb4->jumbo_frame)
2993 *jumbo = 1;
2994 else {
2995 cb4->jumbo_frame = 1;
2996 hret = ehea_h_modify_ehea_port(port->adapter->
2997 handle,
2998 port->
2999 logical_port_id,
3000 H_PORT_CB4,
3001 H_PORT_CB4_JUMBO,
3002 cb4);
3003 if (hret == H_SUCCESS)
3004 *jumbo = 1;
3005 }
3006 } else
3007 ret = -EINVAL;
3008
3009 kfree(cb4);
3010 }
3011out:
3012 return ret;
3013}
3014
3015static ssize_t ehea_show_port_id(struct device *dev,
3016 struct device_attribute *attr, char *buf)
3017{
3018 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003019 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003020}
3021
3022static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3023 NULL);
3024
3025static void __devinit logical_port_release(struct device *dev)
3026{
3027 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3028 of_node_put(port->ofdev.node);
3029}
3030
3031static struct device *ehea_register_port(struct ehea_port *port,
3032 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003033{
3034 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003035
3036 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003037 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003038 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003039
Thomas Kleind1dea382007-04-26 11:56:13 +02003040 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003041 port->ofdev.dev.release = logical_port_release;
3042
3043 ret = of_device_register(&port->ofdev);
3044 if (ret) {
3045 ehea_error("failed to register device. ret=%d", ret);
3046 goto out;
3047 }
3048
3049 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003050 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051 ehea_error("failed to register attributes, ret=%d", ret);
3052 goto out_unreg_of_dev;
3053 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003054
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055 return &port->ofdev.dev;
3056
3057out_unreg_of_dev:
3058 of_device_unregister(&port->ofdev);
3059out:
3060 return NULL;
3061}
3062
3063static void ehea_unregister_port(struct ehea_port *port)
3064{
3065 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3066 of_device_unregister(&port->ofdev);
3067}
3068
3069struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3070 u32 logical_port_id,
3071 struct device_node *dn)
3072{
3073 int ret;
3074 struct net_device *dev;
3075 struct ehea_port *port;
3076 struct device *port_dev;
3077 int jumbo;
3078
3079 /* allocate memory for the port structures */
3080 dev = alloc_etherdev(sizeof(struct ehea_port));
3081
3082 if (!dev) {
3083 ehea_error("no mem for net_device");
3084 ret = -ENOMEM;
3085 goto out_err;
3086 }
3087
3088 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003089
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003090 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003091 port->state = EHEA_PORT_DOWN;
3092 port->sig_comp_iv = sq_entries / 10;
3093
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003094 port->adapter = adapter;
3095 port->netdev = dev;
3096 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003097
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099
3100 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3101 if (!port->mc_list) {
3102 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003104 }
3105
3106 INIT_LIST_HEAD(&port->mc_list->list);
3107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003108 ret = ehea_sense_port_attr(port);
3109 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003110 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003111
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112 port_dev = ehea_register_port(port, dn);
3113 if (!port_dev)
3114 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003115
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003117
3118 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003119 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3120
3121 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02003122#ifdef CONFIG_NET_POLL_CONTROLLER
3123 dev->poll_controller = ehea_netpoll;
3124#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003125 dev->stop = ehea_stop;
3126 dev->hard_start_xmit = ehea_start_xmit;
3127 dev->get_stats = ehea_get_stats;
3128 dev->set_multicast_list = ehea_set_multicast_list;
3129 dev->set_mac_address = ehea_set_mac_addr;
3130 dev->change_mtu = ehea_change_mtu;
3131 dev->vlan_rx_register = ehea_vlan_rx_register;
3132 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3133 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3134 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003135 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003136 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3137 | NETIF_F_LLTX;
3138 dev->tx_timeout = &ehea_tx_watchdog;
3139 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3140
David Howellsc4028952006-11-22 14:57:56 +00003141 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003142 ehea_set_ethtool_ops(dev);
3143
3144 ret = register_netdev(dev);
3145 if (ret) {
3146 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003147 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003148 }
3149
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003150 port->lro_max_aggr = lro_max_aggr;
3151
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003152 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003153 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003154 ehea_error("failed determining jumbo frame status for %s",
3155 port->netdev->name);
3156
Thomas Klein9c750b72007-01-29 18:44:01 +01003157 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3158 jumbo == 1 ? "en" : "dis");
3159
Thomas Klein44c82152007-07-11 16:32:00 +02003160 adapter->active_ports++;
3161
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003163
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003164out_unreg_port:
3165 ehea_unregister_port(port);
3166
3167out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003168 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169
3170out_free_ethdev:
3171 free_netdev(dev);
3172
3173out_err:
3174 ehea_error("setting up logical port with id=%d failed, ret=%d",
3175 logical_port_id, ret);
3176 return NULL;
3177}
3178
3179static void ehea_shutdown_single_port(struct ehea_port *port)
3180{
3181 unregister_netdev(port->netdev);
3182 ehea_unregister_port(port);
3183 kfree(port->mc_list);
3184 free_netdev(port->netdev);
Thomas Klein44c82152007-07-11 16:32:00 +02003185 port->adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003186}
3187
3188static int ehea_setup_ports(struct ehea_adapter *adapter)
3189{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 struct device_node *lhea_dn;
3191 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003192
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003193 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003194 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003195
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003196 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003197 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003198
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003199 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003200 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201 if (!dn_log_port_id) {
3202 ehea_error("bad device node: eth_dn name=%s",
3203 eth_dn->full_name);
3204 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003205 }
3206
Thomas Klein1211bb62007-04-26 11:56:43 +02003207 if (ehea_add_adapter_mr(adapter)) {
3208 ehea_error("creating MR failed");
3209 of_node_put(eth_dn);
3210 return -EIO;
3211 }
3212
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213 adapter->port[i] = ehea_setup_single_port(adapter,
3214 *dn_log_port_id,
3215 eth_dn);
3216 if (adapter->port[i])
3217 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003218 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003220 else
3221 ehea_remove_adapter_mr(adapter);
3222
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003223 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003224 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003225 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226}
3227
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003228static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3229 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230{
3231 struct device_node *lhea_dn;
3232 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003233 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003234
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003235 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003236 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003237
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003238 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003239 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 if (dn_log_port_id)
3241 if (*dn_log_port_id == logical_port_id)
3242 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003243 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244
3245 return NULL;
3246}
3247
3248static ssize_t ehea_probe_port(struct device *dev,
3249 struct device_attribute *attr,
3250 const char *buf, size_t count)
3251{
3252 struct ehea_adapter *adapter = dev->driver_data;
3253 struct ehea_port *port;
3254 struct device_node *eth_dn = NULL;
3255 int i;
3256
3257 u32 logical_port_id;
3258
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003259 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260
3261 port = ehea_get_port(adapter, logical_port_id);
3262
3263 if (port) {
3264 ehea_info("adding port with logical port id=%d failed. port "
3265 "already configured as %s.", logical_port_id,
3266 port->netdev->name);
3267 return -EINVAL;
3268 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003269
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003270 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3271
3272 if (!eth_dn) {
3273 ehea_info("no logical port with id %d found", logical_port_id);
3274 return -EINVAL;
3275 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003276
Thomas Klein1211bb62007-04-26 11:56:43 +02003277 if (ehea_add_adapter_mr(adapter)) {
3278 ehea_error("creating MR failed");
3279 return -EIO;
3280 }
3281
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003282 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3283
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003284 of_node_put(eth_dn);
3285
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003286 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003287 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003288 if (!adapter->port[i]) {
3289 adapter->port[i] = port;
3290 break;
3291 }
3292
3293 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3294 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003295 } else {
3296 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003297 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003298 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003299
3300 return (ssize_t) count;
3301}
3302
3303static ssize_t ehea_remove_port(struct device *dev,
3304 struct device_attribute *attr,
3305 const char *buf, size_t count)
3306{
3307 struct ehea_adapter *adapter = dev->driver_data;
3308 struct ehea_port *port;
3309 int i;
3310 u32 logical_port_id;
3311
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003312 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003313
3314 port = ehea_get_port(adapter, logical_port_id);
3315
3316 if (port) {
3317 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3318 logical_port_id);
3319
3320 ehea_shutdown_single_port(port);
3321
Doug Maxey508d2b52008-01-31 20:20:49 -06003322 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003323 if (adapter->port[i] == port) {
3324 adapter->port[i] = NULL;
3325 break;
3326 }
3327 } else {
3328 ehea_error("removing port with logical port id=%d failed. port "
3329 "not configured.", logical_port_id);
3330 return -EINVAL;
3331 }
3332
Thomas Klein1211bb62007-04-26 11:56:43 +02003333 ehea_remove_adapter_mr(adapter);
3334
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003335 return (ssize_t) count;
3336}
3337
3338static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3339static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3340
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003341int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003342{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003343 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344 if (ret)
3345 goto out;
3346
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003347 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003348out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003349 return ret;
3350}
3351
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003352void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003353{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003354 device_remove_file(&dev->dev, &dev_attr_probe_port);
3355 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003356}
3357
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003358static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003360{
3361 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003362 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003363 int ret;
3364
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003365 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003366 ehea_error("Invalid ibmebus device probed");
3367 return -EINVAL;
3368 }
Daniel Walker9f71a562008-03-28 14:41:26 -07003369 mutex_lock(&ehea_fw_handles.lock);
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003370
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3372 if (!adapter) {
3373 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003374 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375 goto out;
3376 }
3377
Thomas Klein44c82152007-07-11 16:32:00 +02003378 list_add(&adapter->list, &adapter_list);
3379
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003380 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003381
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003382 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003383 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003384 if (adapter_handle)
3385 adapter->handle = *adapter_handle;
3386
3387 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003388 dev_err(&dev->dev, "failed getting handle for adapter"
3389 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003390 ret = -ENODEV;
3391 goto out_free_ad;
3392 }
3393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003394 adapter->pd = EHEA_PD_ID;
3395
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003396 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003398
3399 /* initialize adapter and ports */
3400 /* get adapter properties */
3401 ret = ehea_sense_adapter_attr(adapter);
3402 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003403 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003404 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003405 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406
3407 adapter->neq = ehea_create_eq(adapter,
3408 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3409 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003410 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003411 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003412 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003413 }
3414
3415 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3416 (unsigned long)adapter);
3417
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003418 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003419 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003420 "ehea_neq", adapter);
3421 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003422 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003423 goto out_kill_eq;
3424 }
3425
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003426 ret = ehea_create_device_sysfs(dev);
3427 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003428 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003429
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003430 ret = ehea_setup_ports(adapter);
3431 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003432 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003434 }
3435
3436 ret = 0;
3437 goto out;
3438
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003439out_rem_dev_sysfs:
3440 ehea_remove_device_sysfs(dev);
3441
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003442out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003443 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003444
3445out_kill_eq:
3446 ehea_destroy_eq(adapter->neq);
3447
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003448out_free_ad:
3449 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003450
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003451out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003452 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003453 mutex_unlock(&ehea_fw_handles.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003454 return ret;
3455}
3456
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003457static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003459 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003460 int i;
3461
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003462 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003463 if (adapter->port[i]) {
3464 ehea_shutdown_single_port(adapter->port[i]);
3465 adapter->port[i] = NULL;
3466 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003467
3468 ehea_remove_device_sysfs(dev);
3469
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003470 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471
Daniel Walker9f71a562008-03-28 14:41:26 -07003472 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003473
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003474 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003475 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003476
3477 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003478 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003479 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003481
Thomas Klein21eee2d2008-02-13 16:18:33 +01003482 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003483 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003485 return 0;
3486}
3487
Thomas Klein21eee2d2008-02-13 16:18:33 +01003488void ehea_crash_handler(void)
3489{
3490 int i;
3491
3492 if (ehea_fw_handles.arr)
3493 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3494 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3495 ehea_fw_handles.arr[i].fwh,
3496 FORCE_FREE);
3497
3498 if (ehea_bcmc_regs.arr)
3499 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3500 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3501 ehea_bcmc_regs.arr[i].port_id,
3502 ehea_bcmc_regs.arr[i].reg_type,
3503 ehea_bcmc_regs.arr[i].macaddr,
3504 0, H_DEREG_BCMC);
3505}
3506
Hannes Hering48cfb142008-05-07 14:43:36 +02003507static int ehea_mem_notifier(struct notifier_block *nb,
3508 unsigned long action, void *data)
3509{
3510 switch (action) {
3511 case MEM_OFFLINE:
3512 ehea_info("memory has been removed");
3513 ehea_rereg_mrs(NULL);
3514 break;
3515 default:
3516 break;
3517 }
3518 return NOTIFY_OK;
3519}
3520
3521static struct notifier_block ehea_mem_nb = {
3522 .notifier_call = ehea_mem_notifier,
3523};
3524
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003525static int ehea_reboot_notifier(struct notifier_block *nb,
3526 unsigned long action, void *unused)
3527{
3528 if (action == SYS_RESTART) {
3529 ehea_info("Reboot: freeing all eHEA resources");
3530 ibmebus_unregister_driver(&ehea_driver);
3531 }
3532 return NOTIFY_DONE;
3533}
3534
3535static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003536 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003537};
3538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539static int check_module_parm(void)
3540{
3541 int ret = 0;
3542
3543 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3544 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3545 ehea_info("Bad parameter: rq1_entries");
3546 ret = -EINVAL;
3547 }
3548 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3549 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3550 ehea_info("Bad parameter: rq2_entries");
3551 ret = -EINVAL;
3552 }
3553 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3554 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3555 ehea_info("Bad parameter: rq3_entries");
3556 ret = -EINVAL;
3557 }
3558 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3559 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3560 ehea_info("Bad parameter: sq_entries");
3561 ret = -EINVAL;
3562 }
3563
3564 return ret;
3565}
3566
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003567static ssize_t ehea_show_capabilities(struct device_driver *drv,
3568 char *buf)
3569{
3570 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3571}
3572
3573static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3574 ehea_show_capabilities, NULL);
3575
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003576int __init ehea_module_init(void)
3577{
3578 int ret;
3579
3580 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3581 DRV_VERSION);
3582
Thomas Klein44c82152007-07-11 16:32:00 +02003583
3584 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003585 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3586 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3587
Daniel Walker9f71a562008-03-28 14:41:26 -07003588 mutex_init(&ehea_fw_handles.lock);
Daniel Walkerda59cde2008-03-28 14:41:28 -07003589 mutex_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003591 ret = check_module_parm();
3592 if (ret)
3593 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003594
3595 ret = ehea_create_busmap();
3596 if (ret)
3597 goto out;
3598
Thomas Klein21eee2d2008-02-13 16:18:33 +01003599 ret = register_reboot_notifier(&ehea_reboot_nb);
3600 if (ret)
3601 ehea_info("failed registering reboot notifier");
3602
Hannes Hering48cfb142008-05-07 14:43:36 +02003603 ret = register_memory_notifier(&ehea_mem_nb);
3604 if (ret)
3605 ehea_info("failed registering memory remove notifier");
3606
Thomas Klein21eee2d2008-02-13 16:18:33 +01003607 ret = crash_shutdown_register(&ehea_crash_handler);
3608 if (ret)
3609 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003610
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003611 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003612 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003613 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003614 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003615 }
3616
3617 ret = driver_create_file(&ehea_driver.driver,
3618 &driver_attr_capabilities);
3619 if (ret) {
3620 ehea_error("failed to register capabilities attribute, ret=%d",
3621 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003622 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003623 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003624
Thomas Klein21eee2d2008-02-13 16:18:33 +01003625 return ret;
3626
3627out3:
3628 ibmebus_unregister_driver(&ehea_driver);
3629out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003630 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003631 unregister_reboot_notifier(&ehea_reboot_nb);
3632 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003633out:
3634 return ret;
3635}
3636
3637static void __exit ehea_module_exit(void)
3638{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003639 int ret;
3640
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003641 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003642 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003643 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003644 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003645 ret = crash_shutdown_unregister(&ehea_crash_handler);
3646 if (ret)
3647 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003648 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003649 kfree(ehea_fw_handles.arr);
3650 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003651 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003652}
3653
3654module_init(ehea_module_init);
3655module_exit(ehea_module_exit);