blob: db0d79ebae8142cf4e1c2df9d7253220caa61351 [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:
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
12 *
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>
36#include <net/ip.h>
37
38#include "ehea.h"
39#include "ehea_qmr.h"
40#include "ehea_phyp.h"
41
42
43MODULE_LICENSE("GPL");
44MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
45MODULE_DESCRIPTION("IBM eServer HEA Driver");
46MODULE_VERSION(DRV_VERSION);
47
48
49static int msg_level = -1;
50static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
51static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
52static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
53static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010054static int use_mcs = 0;
55static int num_tx_qps = EHEA_NUM_TX_QP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020056
57module_param(msg_level, int, 0);
58module_param(rq1_entries, int, 0);
59module_param(rq2_entries, int, 0);
60module_param(rq3_entries, int, 0);
61module_param(sq_entries, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010062module_param(use_mcs, int, 0);
63module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020064
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010065MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066MODULE_PARM_DESC(msg_level, "msg_level");
67MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
68 "[2^x - 1], x = [6..14]. Default = "
69 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
70MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
71 "[2^x - 1], x = [6..14]. Default = "
72 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
73MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
74 "[2^x - 1], x = [6..14]. Default = "
75 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
76MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
77 "[2^x - 1], x = [6..14]. Default = "
78 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010079MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 1 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080
81void ehea_dump(void *adr, int len, char *msg) {
82 int x;
83 unsigned char *deb = adr;
84 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +010085 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020086 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
87 deb += 16;
88 }
89}
90
91static struct net_device_stats *ehea_get_stats(struct net_device *dev)
92{
93 struct ehea_port *port = netdev_priv(dev);
94 struct net_device_stats *stats = &port->stats;
95 struct hcp_ehea_port_cb2 *cb2;
96 u64 hret, rx_packets;
97 int i;
98
99 memset(stats, 0, sizeof(*stats));
100
Thomas Kleina1d261c2006-11-03 17:48:23 +0100101 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200102 if (!cb2) {
103 ehea_error("no mem for cb2");
104 goto out;
105 }
106
107 hret = ehea_h_query_ehea_port(port->adapter->handle,
108 port->logical_port_id,
109 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
110 if (hret != H_SUCCESS) {
111 ehea_error("query_ehea_port failed");
112 goto out_herr;
113 }
114
115 if (netif_msg_hw(port))
116 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
117
118 rx_packets = 0;
119 for (i = 0; i < port->num_def_qps; i++)
120 rx_packets += port->port_res[i].rx_packets;
121
122 stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp;
123 stats->multicast = cb2->rxmcp;
124 stats->rx_errors = cb2->rxuerr;
125 stats->rx_bytes = cb2->rxo;
126 stats->tx_bytes = cb2->txo;
127 stats->rx_packets = rx_packets;
128
129out_herr:
130 kfree(cb2);
131out:
132 return stats;
133}
134
135static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
136{
137 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
138 struct net_device *dev = pr->port->netdev;
139 int max_index_mask = pr->rq1_skba.len - 1;
140 int i;
141
142 if (!nr_of_wqes)
143 return;
144
145 for (i = 0; i < nr_of_wqes; i++) {
146 if (!skb_arr_rq1[index]) {
147 skb_arr_rq1[index] = netdev_alloc_skb(dev,
148 EHEA_L_PKT_SIZE);
149 if (!skb_arr_rq1[index]) {
150 ehea_error("%s: no mem for skb/%d wqes filled",
151 dev->name, i);
152 break;
153 }
154 }
155 index--;
156 index &= max_index_mask;
157 }
158 /* Ring doorbell */
159 ehea_update_rq1a(pr->qp, i);
160}
161
162static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
163{
164 int ret = 0;
165 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
166 struct net_device *dev = pr->port->netdev;
167 int i;
168
169 for (i = 0; i < pr->rq1_skba.len; i++) {
170 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
171 if (!skb_arr_rq1[i]) {
172 ehea_error("%s: no mem for skb/%d wqes filled",
173 dev->name, i);
174 ret = -ENOMEM;
175 goto out;
176 }
177 }
178 /* Ring doorbell */
179 ehea_update_rq1a(pr->qp, nr_rq1a);
180out:
181 return ret;
182}
183
184static int ehea_refill_rq_def(struct ehea_port_res *pr,
185 struct ehea_q_skb_arr *q_skba, int rq_nr,
186 int num_wqes, int wqe_type, int packet_size)
187{
188 struct net_device *dev = pr->port->netdev;
189 struct ehea_qp *qp = pr->qp;
190 struct sk_buff **skb_arr = q_skba->arr;
191 struct ehea_rwqe *rwqe;
192 int i, index, max_index_mask, fill_wqes;
193 int ret = 0;
194
195 fill_wqes = q_skba->os_skbs + num_wqes;
196
197 if (!fill_wqes)
198 return ret;
199
200 index = q_skba->index;
201 max_index_mask = q_skba->len - 1;
202 for (i = 0; i < fill_wqes; i++) {
203 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
204 if (!skb) {
205 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100206 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200207 q_skba->os_skbs = fill_wqes - i;
208 ret = -ENOMEM;
209 break;
210 }
211 skb_reserve(skb, NET_IP_ALIGN);
212
213 skb_arr[index] = skb;
214
215 rwqe = ehea_get_next_rwqe(qp, rq_nr);
216 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
217 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
218 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
219 rwqe->sg_list[0].vaddr = (u64)skb->data;
220 rwqe->sg_list[0].len = packet_size;
221 rwqe->data_segments = 1;
222
223 index++;
224 index &= max_index_mask;
225 }
226 q_skba->index = index;
227
228 /* Ring doorbell */
229 iosync();
230 if (rq_nr == 2)
231 ehea_update_rq2a(pr->qp, i);
232 else
233 ehea_update_rq3a(pr->qp, i);
234
235 return ret;
236}
237
238
239static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
240{
241 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
242 nr_of_wqes, EHEA_RWQE2_TYPE,
243 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
244}
245
246
247static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
248{
249 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
250 nr_of_wqes, EHEA_RWQE3_TYPE,
251 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
252}
253
254static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
255{
256 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
257 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
258 return 0;
259 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
260 (cqe->header_length == 0))
261 return 0;
262 return -EINVAL;
263}
264
265static inline void ehea_fill_skb(struct net_device *dev,
266 struct sk_buff *skb, struct ehea_cqe *cqe)
267{
268 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
269
270 skb_put(skb, length);
271 skb->ip_summed = CHECKSUM_UNNECESSARY;
272 skb->protocol = eth_type_trans(skb, dev);
273}
274
275static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
276 int arr_len,
277 struct ehea_cqe *cqe)
278{
279 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
280 struct sk_buff *skb;
281 void *pref;
282 int x;
283
284 x = skb_index + 1;
285 x &= (arr_len - 1);
286
287 pref = skb_array[x];
288 prefetchw(pref);
289 prefetchw(pref + EHEA_CACHE_LINE);
290
291 pref = (skb_array[x]->data);
292 prefetch(pref);
293 prefetch(pref + EHEA_CACHE_LINE);
294 prefetch(pref + EHEA_CACHE_LINE * 2);
295 prefetch(pref + EHEA_CACHE_LINE * 3);
296 skb = skb_array[skb_index];
297 skb_array[skb_index] = NULL;
298 return skb;
299}
300
301static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
302 int arr_len, int wqe_index)
303{
304 struct sk_buff *skb;
305 void *pref;
306 int x;
307
308 x = wqe_index + 1;
309 x &= (arr_len - 1);
310
311 pref = skb_array[x];
312 prefetchw(pref);
313 prefetchw(pref + EHEA_CACHE_LINE);
314
315 pref = (skb_array[x]->data);
316 prefetchw(pref);
317 prefetchw(pref + EHEA_CACHE_LINE);
318
319 skb = skb_array[wqe_index];
320 skb_array[wqe_index] = NULL;
321 return skb;
322}
323
324static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
325 struct ehea_cqe *cqe, int *processed_rq2,
326 int *processed_rq3)
327{
328 struct sk_buff *skb;
329
330 if (netif_msg_rx_err(pr->port)) {
331 ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr);
332 ehea_dump(cqe, sizeof(*cqe), "CQE");
333 }
334
335 if (rq == 2) {
336 *processed_rq2 += 1;
337 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
338 dev_kfree_skb(skb);
339 } else if (rq == 3) {
340 *processed_rq3 += 1;
341 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
342 dev_kfree_skb(skb);
343 }
344
345 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
346 ehea_error("Critical receive error. Resetting port.");
347 queue_work(pr->port->adapter->ehea_wq, &pr->port->reset_task);
348 return 1;
349 }
350
351 return 0;
352}
353
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100354static struct ehea_cqe *ehea_proc_rwqes(struct net_device *dev,
355 struct ehea_port_res *pr,
356 int *budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200357{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100358 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 struct ehea_qp *qp = pr->qp;
360 struct ehea_cqe *cqe;
361 struct sk_buff *skb;
362 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
363 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
364 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
365 int skb_arr_rq1_len = pr->rq1_skba.len;
366 int skb_arr_rq2_len = pr->rq2_skba.len;
367 int skb_arr_rq3_len = pr->rq3_skba.len;
368 int processed, processed_rq1, processed_rq2, processed_rq3;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100369 int wqe_index, last_wqe_index, rq, my_quota, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370
371 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
372 last_wqe_index = 0;
373 my_quota = min(*budget, dev->quota);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200375 cqe = ehea_poll_rq1(qp, &wqe_index);
376 while ((my_quota > 0) && cqe) {
377 ehea_inc_rq1(qp);
378 processed_rq1++;
379 processed++;
380 my_quota--;
381 if (netif_msg_rx_status(port))
382 ehea_dump(cqe, sizeof(*cqe), "CQE");
383
384 last_wqe_index = wqe_index;
385 rmb();
386 if (!ehea_check_cqe(cqe, &rq)) {
387 if (rq == 1) { /* LL RQ1 */
388 skb = get_skb_by_index_ll(skb_arr_rq1,
389 skb_arr_rq1_len,
390 wqe_index);
391 if (unlikely(!skb)) {
392 if (netif_msg_rx_err(port))
393 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100394
395 skb = netdev_alloc_skb(port->netdev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200396 EHEA_L_PKT_SIZE);
397 if (!skb)
398 break;
399 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300400 skb_copy_to_linear_data(skb, ((char*)cqe) + 64,
401 cqe->num_bytes_transfered - 4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200402 ehea_fill_skb(dev, skb, cqe);
403 } else if (rq == 2) { /* RQ2 */
404 skb = get_skb_by_index(skb_arr_rq2,
405 skb_arr_rq2_len, cqe);
406 if (unlikely(!skb)) {
407 if (netif_msg_rx_err(port))
408 ehea_error("rq2: skb=NULL");
409 break;
410 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100411 ehea_fill_skb(port->netdev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412 processed_rq2++;
413 } else { /* RQ3 */
414 skb = get_skb_by_index(skb_arr_rq3,
415 skb_arr_rq3_len, cqe);
416 if (unlikely(!skb)) {
417 if (netif_msg_rx_err(port))
418 ehea_error("rq3: skb=NULL");
419 break;
420 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100421 ehea_fill_skb(port->netdev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 processed_rq3++;
423 }
424
425 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
426 vlan_hwaccel_receive_skb(skb, port->vgrp,
427 cqe->vlan_tag);
428 else
429 netif_receive_skb(skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100430 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431 pr->p_state.poll_receive_errors++;
432 port_reset = ehea_treat_poll_error(pr, rq, cqe,
433 &processed_rq2,
434 &processed_rq3);
435 if (port_reset)
436 break;
437 }
438 cqe = ehea_poll_rq1(qp, &wqe_index);
439 }
440
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200441 pr->rx_packets += processed;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100442 *budget -= processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200443
444 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
445 ehea_refill_rq2(pr, processed_rq2);
446 ehea_refill_rq3(pr, processed_rq3);
447
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100448 cqe = ehea_poll_rq1(qp, &wqe_index);
449 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450}
451
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100452static void ehea_free_sent_skbs(struct ehea_cqe *cqe, struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453{
454 struct sk_buff *skb;
455 int index, max_index_mask, i;
456
457 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
458 max_index_mask = pr->sq_skba.len - 1;
459 for (i = 0; i < EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); i++) {
460 skb = pr->sq_skba.arr[index];
461 if (likely(skb)) {
462 dev_kfree_skb(skb);
463 pr->sq_skba.arr[index] = NULL;
464 } else {
465 ehea_error("skb=NULL, wr_id=%lX, loop=%d, index=%d",
466 cqe->wr_id, i, index);
467 }
468 index--;
469 index &= max_index_mask;
470 }
471}
472
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100473static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200474{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475 struct ehea_cq *send_cq = pr->send_cq;
476 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100477 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478 int cqe_counter = 0;
479 int swqe_av = 0;
480 unsigned long flags;
481
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100482 cqe = ehea_poll_cq(send_cq);
483 while(cqe && (quota > 0)) {
484 ehea_inc_cq(send_cq);
485
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200486 cqe_counter++;
487 rmb();
488 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
489 ehea_error("Send Completion Error: Resetting port");
490 if (netif_msg_tx_err(pr->port))
491 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
492 queue_work(pr->port->adapter->ehea_wq,
493 &pr->port->reset_task);
494 break;
495 }
496
497 if (netif_msg_tx_done(pr->port))
498 ehea_dump(cqe, sizeof(*cqe), "CQE");
499
500 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
501 == EHEA_SWQE2_TYPE))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100502 ehea_free_sent_skbs(cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503
504 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
505 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100506
507 cqe = ehea_poll_cq(send_cq);
508 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509
510 ehea_update_feca(send_cq, cqe_counter);
511 atomic_add(swqe_av, &pr->swqe_avail);
512
513 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100514
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
516 >= pr->swqe_refill_th)) {
517 netif_wake_queue(pr->port->netdev);
518 pr->queue_stopped = 0;
519 }
520 spin_unlock_irqrestore(&pr->netif_queue, flags);
521
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100522 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200523}
524
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100525#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
526
527static int ehea_poll(struct net_device *dev, int *budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200528{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100529 struct ehea_port_res *pr = dev->priv;
530 struct ehea_cqe *cqe;
531 struct ehea_cqe *cqe_skb = NULL;
532 int force_irq, wqe_index;
533
534 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
535 cqe_skb = ehea_poll_cq(pr->send_cq);
536
537 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
538
539 if ((!cqe && !cqe_skb) || force_irq) {
540 pr->poll_counter = 0;
541 netif_rx_complete(dev);
542 ehea_reset_cq_ep(pr->recv_cq);
543 ehea_reset_cq_ep(pr->send_cq);
544 ehea_reset_cq_n1(pr->recv_cq);
545 ehea_reset_cq_n1(pr->send_cq);
546 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
547 cqe_skb = ehea_poll_cq(pr->send_cq);
548
549 if (!cqe && !cqe_skb)
550 return 0;
551
552 if (!netif_rx_reschedule(dev, dev->quota))
553 return 0;
554 }
555
556 cqe = ehea_proc_rwqes(dev, pr, budget);
557 cqe_skb = ehea_proc_cqes(pr, 300);
558
559 if (cqe || cqe_skb)
560 pr->poll_counter++;
561
562 return 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200563}
564
David Howells7d12e782006-10-05 14:55:46 +0100565static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200566{
567 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100568
569 netif_rx_schedule(pr->d_netdev);
570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200571 return IRQ_HANDLED;
572}
573
David Howells7d12e782006-10-05 14:55:46 +0100574static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200575{
576 struct ehea_port *port = param;
577 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100578 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200579 u32 qp_token;
580
581 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200583 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200584 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100585 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
586 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100587
588 qp = port->port_res[qp_token].qp;
589 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100590 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200591 }
592
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100593 queue_work(port->adapter->ehea_wq, &port->reset_task);
594
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200595 return IRQ_HANDLED;
596}
597
598static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
599 int logical_port)
600{
601 int i;
602
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100603 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100604 if (adapter->port[i])
605 if (adapter->port[i]->logical_port_id == logical_port)
606 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200607 return NULL;
608}
609
610int ehea_sense_port_attr(struct ehea_port *port)
611{
612 int ret;
613 u64 hret;
614 struct hcp_ehea_port_cb0 *cb0;
615
Thomas Kleina1d261c2006-11-03 17:48:23 +0100616 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */
617 if (!cb0) { /* ehea_neq_tasklet() */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200618 ehea_error("no mem for cb0");
619 ret = -ENOMEM;
620 goto out;
621 }
622
623 hret = ehea_h_query_ehea_port(port->adapter->handle,
624 port->logical_port_id, H_PORT_CB0,
625 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
626 cb0);
627 if (hret != H_SUCCESS) {
628 ret = -EIO;
629 goto out_free;
630 }
631
632 /* MAC address */
633 port->mac_addr = cb0->port_mac_addr << 16;
634
635 if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
636 ret = -EADDRNOTAVAIL;
637 goto out_free;
638 }
639
640 /* Port speed */
641 switch (cb0->port_speed) {
642 case H_SPEED_10M_H:
643 port->port_speed = EHEA_SPEED_10M;
644 port->full_duplex = 0;
645 break;
646 case H_SPEED_10M_F:
647 port->port_speed = EHEA_SPEED_10M;
648 port->full_duplex = 1;
649 break;
650 case H_SPEED_100M_H:
651 port->port_speed = EHEA_SPEED_100M;
652 port->full_duplex = 0;
653 break;
654 case H_SPEED_100M_F:
655 port->port_speed = EHEA_SPEED_100M;
656 port->full_duplex = 1;
657 break;
658 case H_SPEED_1G_F:
659 port->port_speed = EHEA_SPEED_1G;
660 port->full_duplex = 1;
661 break;
662 case H_SPEED_10G_F:
663 port->port_speed = EHEA_SPEED_10G;
664 port->full_duplex = 1;
665 break;
666 default:
667 port->port_speed = 0;
668 port->full_duplex = 0;
669 break;
670 }
671
Thomas Kleine919b592007-01-22 12:53:20 +0100672 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100673 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100674
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200675 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100676 if (use_mcs)
677 port->num_def_qps = cb0->num_default_qps;
678 else
679 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200680
681 if (!port->num_def_qps) {
682 ret = -EINVAL;
683 goto out_free;
684 }
685
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100686 port->num_tx_qps = num_tx_qps;
687
688 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200689 port->num_add_tx_qps = 0;
690 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100691 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200692
693 ret = 0;
694out_free:
695 if (ret || netif_msg_probe(port))
696 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
697 kfree(cb0);
698out:
699 return ret;
700}
701
702int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
703{
704 struct hcp_ehea_port_cb4 *cb4;
705 u64 hret;
706 int ret = 0;
707
Thomas Kleina1d261c2006-11-03 17:48:23 +0100708 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200709 if (!cb4) {
710 ehea_error("no mem for cb4");
711 ret = -ENOMEM;
712 goto out;
713 }
714
715 cb4->port_speed = port_speed;
716
717 netif_carrier_off(port->netdev);
718
719 hret = ehea_h_modify_ehea_port(port->adapter->handle,
720 port->logical_port_id,
721 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
722 if (hret == H_SUCCESS) {
723 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
724
725 hret = ehea_h_query_ehea_port(port->adapter->handle,
726 port->logical_port_id,
727 H_PORT_CB4, H_PORT_CB4_SPEED,
728 cb4);
729 if (hret == H_SUCCESS) {
730 switch (cb4->port_speed) {
731 case H_SPEED_10M_H:
732 port->port_speed = EHEA_SPEED_10M;
733 port->full_duplex = 0;
734 break;
735 case H_SPEED_10M_F:
736 port->port_speed = EHEA_SPEED_10M;
737 port->full_duplex = 1;
738 break;
739 case H_SPEED_100M_H:
740 port->port_speed = EHEA_SPEED_100M;
741 port->full_duplex = 0;
742 break;
743 case H_SPEED_100M_F:
744 port->port_speed = EHEA_SPEED_100M;
745 port->full_duplex = 1;
746 break;
747 case H_SPEED_1G_F:
748 port->port_speed = EHEA_SPEED_1G;
749 port->full_duplex = 1;
750 break;
751 case H_SPEED_10G_F:
752 port->port_speed = EHEA_SPEED_10G;
753 port->full_duplex = 1;
754 break;
755 default:
756 port->port_speed = 0;
757 port->full_duplex = 0;
758 break;
759 }
760 } else {
761 ehea_error("Failed sensing port speed");
762 ret = -EIO;
763 }
764 } else {
765 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +0100766 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 ret = -EPERM;
768 } else {
769 ret = -EIO;
770 ehea_error("Failed setting port speed");
771 }
772 }
773 netif_carrier_on(port->netdev);
774 kfree(cb4);
775out:
776 return ret;
777}
778
779static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
780{
781 int ret;
782 u8 ec;
783 u8 portnum;
784 struct ehea_port *port;
785
786 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
787 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
788 port = ehea_get_port(adapter, portnum);
789
790 switch (ec) {
791 case EHEA_EC_PORTSTATE_CHG: /* port state change */
792
793 if (!port) {
794 ehea_error("unknown portnum %x", portnum);
795 break;
796 }
797
798 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
799 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +0200800 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200801 if (ret) {
802 ehea_error("failed resensing port "
803 "attributes");
804 break;
805 }
806
807 if (netif_msg_link(port))
808 ehea_info("%s: Logical port up: %dMbps "
809 "%s Duplex",
810 port->netdev->name,
811 port->port_speed,
812 port->full_duplex ==
813 1 ? "Full" : "Half");
814
815 netif_carrier_on(port->netdev);
816 netif_wake_queue(port->netdev);
817 }
818 } else
819 if (netif_carrier_ok(port->netdev)) {
820 if (netif_msg_link(port))
821 ehea_info("%s: Logical port down",
822 port->netdev->name);
823 netif_carrier_off(port->netdev);
824 netif_stop_queue(port->netdev);
825 }
826
827 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
828 if (netif_msg_link(port))
829 ehea_info("%s: Physical port up",
830 port->netdev->name);
831 } else {
832 if (netif_msg_link(port))
833 ehea_info("%s: Physical port down",
834 port->netdev->name);
835 }
836
837 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
838 ehea_info("External switch port is primary port");
839 else
840 ehea_info("External switch port is backup port");
841
842 break;
843 case EHEA_EC_ADAPTER_MALFUNC:
844 ehea_error("Adapter malfunction");
845 break;
846 case EHEA_EC_PORT_MALFUNC:
847 ehea_info("Port malfunction: Device: %s", port->netdev->name);
848 netif_carrier_off(port->netdev);
849 netif_stop_queue(port->netdev);
850 break;
851 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +0200852 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200853 break;
854 }
855}
856
857static void ehea_neq_tasklet(unsigned long data)
858{
859 struct ehea_adapter *adapter = (struct ehea_adapter*)data;
860 struct ehea_eqe *eqe;
861 u64 event_mask;
862
863 eqe = ehea_poll_eq(adapter->neq);
864 ehea_debug("eqe=%p", eqe);
865
866 while (eqe) {
867 ehea_debug("*eqe=%lx", eqe->entry);
868 ehea_parse_eqe(adapter, eqe->entry);
869 eqe = ehea_poll_eq(adapter->neq);
870 ehea_debug("next eqe=%p", eqe);
871 }
872
873 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
874 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
875 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
876
877 ehea_h_reset_events(adapter->handle,
878 adapter->neq->fw_handle, event_mask);
879}
880
David Howells7d12e782006-10-05 14:55:46 +0100881static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882{
883 struct ehea_adapter *adapter = param;
884 tasklet_hi_schedule(&adapter->neq_tasklet);
885 return IRQ_HANDLED;
886}
887
888
889static int ehea_fill_port_res(struct ehea_port_res *pr)
890{
891 int ret;
892 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
893
894 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
895 - init_attr->act_nr_rwqes_rq2
896 - init_attr->act_nr_rwqes_rq3 - 1);
897
898 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
899
900 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
901
902 return ret;
903}
904
905static int ehea_reg_interrupts(struct net_device *dev)
906{
907 struct ehea_port *port = netdev_priv(dev);
908 struct ehea_port_res *pr;
909 int i, ret;
910
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911
912 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
913 dev->name);
914
915 ret = ibmebus_request_irq(NULL, port->qp_eq->attr.ist1,
916 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -0800917 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200918 if (ret) {
919 ehea_error("failed registering irq for qp_aff_irq_handler:"
920 "ist=%X", port->qp_eq->attr.ist1);
921 goto out_free_qpeq;
922 }
923
924 if (netif_msg_ifup(port))
925 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
926 "registered", port->qp_eq->attr.ist1);
927
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100928
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
930 pr = &port->port_res[i];
931 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100932 "%s-queue%d", dev->name, i);
933 ret = ibmebus_request_irq(NULL, pr->eq->attr.ist1,
934 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -0800935 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200936 pr);
937 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200939 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100940 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200941 goto out_free_req;
942 }
943 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100944 ehea_info("irq_handle 0x%X for function ehea_queue_int "
945 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200946 }
947out:
948 return ret;
949
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100950
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200951out_free_req:
952 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100953 u32 ist = port->port_res[i].eq->attr.ist1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200954 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
955 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100956
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200957out_free_qpeq:
958 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
959 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100960
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200961 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100962
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200963}
964
965static void ehea_free_interrupts(struct net_device *dev)
966{
967 struct ehea_port *port = netdev_priv(dev);
968 struct ehea_port_res *pr;
969 int i;
970
971 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
974 pr = &port->port_res[i];
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100975 ibmebus_free_irq(NULL, pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200976 if (netif_msg_intr(port))
977 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100978 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979 }
980
981 /* associated events */
982 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
983 if (netif_msg_intr(port))
984 ehea_info("associated event interrupt for handle 0x%X freed",
985 port->qp_eq->attr.ist1);
986}
987
988static int ehea_configure_port(struct ehea_port *port)
989{
990 int ret, i;
991 u64 hret, mask;
992 struct hcp_ehea_port_cb0 *cb0;
993
994 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +0100995 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200996 if (!cb0)
997 goto out;
998
999 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1000 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1001 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1002 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1003 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1004 PXLY_RC_VLAN_FILTER)
1005 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1006
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001007 for (i = 0; i < port->num_mcs; i++)
1008 if (use_mcs)
1009 cb0->default_qpn_arr[i] =
1010 port->port_res[i].qp->init_attr.qp_nr;
1011 else
1012 cb0->default_qpn_arr[i] =
1013 port->port_res[0].qp->init_attr.qp_nr;
1014
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001015 if (netif_msg_ifup(port))
1016 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1017
1018 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1019 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1020
1021 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1022 port->logical_port_id,
1023 H_PORT_CB0, mask, cb0);
1024 ret = -EIO;
1025 if (hret != H_SUCCESS)
1026 goto out_free;
1027
1028 ret = 0;
1029
1030out_free:
1031 kfree(cb0);
1032out:
1033 return ret;
1034}
1035
1036static int ehea_gen_smrs(struct ehea_port_res *pr)
1037{
1038 u64 hret;
1039 struct ehea_adapter *adapter = pr->port->adapter;
1040
1041 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1042 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1043 adapter->pd, &pr->send_mr);
1044 if (hret != H_SUCCESS)
1045 goto out;
1046
1047 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1048 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1049 adapter->pd, &pr->recv_mr);
1050 if (hret != H_SUCCESS)
1051 goto out_freeres;
1052
1053 return 0;
1054
1055out_freeres:
1056 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1057 if (hret != H_SUCCESS)
1058 ehea_error("failed freeing SMR");
1059out:
1060 return -EIO;
1061}
1062
1063static int ehea_rem_smrs(struct ehea_port_res *pr)
1064{
1065 struct ehea_adapter *adapter = pr->port->adapter;
1066 int ret = 0;
1067 u64 hret;
1068
1069 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1070 if (hret != H_SUCCESS) {
1071 ret = -EIO;
1072 ehea_error("failed freeing send SMR for pr=%p", pr);
1073 }
1074
1075 hret = ehea_h_free_resource(adapter->handle, pr->recv_mr.handle);
1076 if (hret != H_SUCCESS) {
1077 ret = -EIO;
1078 ehea_error("failed freeing recv SMR for pr=%p", pr);
1079 }
1080
1081 return ret;
1082}
1083
1084static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1085{
1086 int arr_size = sizeof(void*) * max_q_entries;
1087
1088 q_skba->arr = vmalloc(arr_size);
1089 if (!q_skba->arr)
1090 return -ENOMEM;
1091
1092 memset(q_skba->arr, 0, arr_size);
1093
1094 q_skba->len = max_q_entries;
1095 q_skba->index = 0;
1096 q_skba->os_skbs = 0;
1097
1098 return 0;
1099}
1100
1101static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1102 struct port_res_cfg *pr_cfg, int queue_token)
1103{
1104 struct ehea_adapter *adapter = port->adapter;
1105 enum ehea_eq_type eq_type = EHEA_EQ;
1106 struct ehea_qp_init_attr *init_attr = NULL;
1107 int ret = -EIO;
1108
1109 memset(pr, 0, sizeof(struct ehea_port_res));
1110
1111 pr->port = port;
1112 spin_lock_init(&pr->send_lock);
1113 spin_lock_init(&pr->recv_lock);
1114 spin_lock_init(&pr->xmit_lock);
1115 spin_lock_init(&pr->netif_queue);
1116
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001117 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1118 if (!pr->eq) {
1119 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001120 goto out_free;
1121 }
1122
1123 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001124 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001125 port->logical_port_id);
1126 if (!pr->recv_cq) {
1127 ehea_error("create_cq failed (cq_recv)");
1128 goto out_free;
1129 }
1130
1131 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001132 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001133 port->logical_port_id);
1134 if (!pr->send_cq) {
1135 ehea_error("create_cq failed (cq_send)");
1136 goto out_free;
1137 }
1138
1139 if (netif_msg_ifup(port))
1140 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1141 pr->send_cq->attr.act_nr_of_cqes,
1142 pr->recv_cq->attr.act_nr_of_cqes);
1143
1144 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1145 if (!init_attr) {
1146 ret = -ENOMEM;
1147 ehea_error("no mem for ehea_qp_init_attr");
1148 goto out_free;
1149 }
1150
1151 init_attr->low_lat_rq1 = 1;
1152 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1153 init_attr->rq_count = 3;
1154 init_attr->qp_token = queue_token;
1155 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1156 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1157 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1158 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1159 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1160 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1161 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1162 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1163 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1164 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1165 init_attr->port_nr = port->logical_port_id;
1166 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1167 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1168 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1169
1170 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1171 if (!pr->qp) {
1172 ehea_error("create_qp failed");
1173 ret = -EIO;
1174 goto out_free;
1175 }
1176
1177 if (netif_msg_ifup(port))
1178 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1179 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1180 init_attr->act_nr_send_wqes,
1181 init_attr->act_nr_rwqes_rq1,
1182 init_attr->act_nr_rwqes_rq2,
1183 init_attr->act_nr_rwqes_rq3);
1184
1185 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1186 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1187 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1188 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1189 if (ret)
1190 goto out_free;
1191
1192 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1193 if (ehea_gen_smrs(pr) != 0) {
1194 ret = -EIO;
1195 goto out_free;
1196 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001197
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001198 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1199
1200 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001201
1202 pr->d_netdev = alloc_netdev(0, "", ether_setup);
1203 if (!pr->d_netdev)
1204 goto out_free;
1205 pr->d_netdev->priv = pr;
1206 pr->d_netdev->weight = 64;
1207 pr->d_netdev->poll = ehea_poll;
1208 set_bit(__LINK_STATE_START, &pr->d_netdev->state);
1209 strcpy(pr->d_netdev->name, port->netdev->name);
1210
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211 ret = 0;
1212 goto out;
1213
1214out_free:
1215 kfree(init_attr);
1216 vfree(pr->sq_skba.arr);
1217 vfree(pr->rq1_skba.arr);
1218 vfree(pr->rq2_skba.arr);
1219 vfree(pr->rq3_skba.arr);
1220 ehea_destroy_qp(pr->qp);
1221 ehea_destroy_cq(pr->send_cq);
1222 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001223 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224out:
1225 return ret;
1226}
1227
1228static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1229{
1230 int ret, i;
1231
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001232 free_netdev(pr->d_netdev);
1233
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 ret = ehea_destroy_qp(pr->qp);
1235
1236 if (!ret) {
1237 ehea_destroy_cq(pr->send_cq);
1238 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001239 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001240
1241 for (i = 0; i < pr->rq1_skba.len; i++)
1242 if (pr->rq1_skba.arr[i])
1243 dev_kfree_skb(pr->rq1_skba.arr[i]);
1244
1245 for (i = 0; i < pr->rq2_skba.len; i++)
1246 if (pr->rq2_skba.arr[i])
1247 dev_kfree_skb(pr->rq2_skba.arr[i]);
1248
1249 for (i = 0; i < pr->rq3_skba.len; i++)
1250 if (pr->rq3_skba.arr[i])
1251 dev_kfree_skb(pr->rq3_skba.arr[i]);
1252
1253 for (i = 0; i < pr->sq_skba.len; i++)
1254 if (pr->sq_skba.arr[i])
1255 dev_kfree_skb(pr->sq_skba.arr[i]);
1256
1257 vfree(pr->rq1_skba.arr);
1258 vfree(pr->rq2_skba.arr);
1259 vfree(pr->rq3_skba.arr);
1260 vfree(pr->sq_skba.arr);
1261 ret = ehea_rem_smrs(pr);
1262 }
1263 return ret;
1264}
1265
1266/*
1267 * The write_* functions store information in swqe which is used by
1268 * the hardware to calculate the ip/tcp/udp checksum
1269 */
1270
1271static inline void write_ip_start_end(struct ehea_swqe *swqe,
1272 const struct sk_buff *skb)
1273{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001274 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001275 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001276}
1277
1278static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1279 const struct sk_buff *skb)
1280{
1281 swqe->tcp_offset =
1282 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1283
1284 swqe->tcp_end = (u16)skb->len - 1;
1285}
1286
1287static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1288 const struct sk_buff *skb)
1289{
1290 swqe->tcp_offset =
1291 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1292
1293 swqe->tcp_end = (u16)skb->len - 1;
1294}
1295
1296
1297static void write_swqe2_TSO(struct sk_buff *skb,
1298 struct ehea_swqe *swqe, u32 lkey)
1299{
1300 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1301 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1302 int skb_data_size = skb->len - skb->data_len;
1303 int headersize;
1304 u64 tmp_addr;
1305
1306 /* Packet is TCP with TSO enabled */
1307 swqe->tx_control |= EHEA_SWQE_TSO;
1308 swqe->mss = skb_shinfo(skb)->gso_size;
1309 /* copy only eth/ip/tcp headers to immediate data and
1310 * the rest of skb->data to sg1entry
1311 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001312 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001313
1314 skb_data_size = skb->len - skb->data_len;
1315
1316 if (skb_data_size >= headersize) {
1317 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001318 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001319 swqe->immediate_data_length = headersize;
1320
1321 if (skb_data_size > headersize) {
1322 /* set sg1entry data */
1323 sg1entry->l_key = lkey;
1324 sg1entry->len = skb_data_size - headersize;
1325
1326 tmp_addr = (u64)(skb->data + headersize);
1327 sg1entry->vaddr = tmp_addr;
1328 swqe->descriptors++;
1329 }
1330 } else
1331 ehea_error("cannot handle fragmented headers");
1332}
1333
1334static void write_swqe2_nonTSO(struct sk_buff *skb,
1335 struct ehea_swqe *swqe, u32 lkey)
1336{
1337 int skb_data_size = skb->len - skb->data_len;
1338 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1339 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1340 u64 tmp_addr;
1341
1342 /* Packet is any nonTSO type
1343 *
1344 * Copy as much as possible skb->data to immediate data and
1345 * the rest to sg1entry
1346 */
1347 if (skb_data_size >= SWQE2_MAX_IMM) {
1348 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001349 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350
1351 swqe->immediate_data_length = SWQE2_MAX_IMM;
1352
1353 if (skb_data_size > SWQE2_MAX_IMM) {
1354 /* copy sg1entry data */
1355 sg1entry->l_key = lkey;
1356 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1357 tmp_addr = (u64)(skb->data + SWQE2_MAX_IMM);
1358 sg1entry->vaddr = tmp_addr;
1359 swqe->descriptors++;
1360 }
1361 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001362 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001363 swqe->immediate_data_length = skb_data_size;
1364 }
1365}
1366
1367static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1368 struct ehea_swqe *swqe, u32 lkey)
1369{
1370 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1371 skb_frag_t *frag;
1372 int nfrags, sg1entry_contains_frag_data, i;
1373 u64 tmp_addr;
1374
1375 nfrags = skb_shinfo(skb)->nr_frags;
1376 sg1entry = &swqe->u.immdata_desc.sg_entry;
1377 sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
1378 swqe->descriptors = 0;
1379 sg1entry_contains_frag_data = 0;
1380
1381 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1382 write_swqe2_TSO(skb, swqe, lkey);
1383 else
1384 write_swqe2_nonTSO(skb, swqe, lkey);
1385
1386 /* write descriptors */
1387 if (nfrags > 0) {
1388 if (swqe->descriptors == 0) {
1389 /* sg1entry not yet used */
1390 frag = &skb_shinfo(skb)->frags[0];
1391
1392 /* copy sg1entry data */
1393 sg1entry->l_key = lkey;
1394 sg1entry->len = frag->size;
1395 tmp_addr = (u64)(page_address(frag->page)
1396 + frag->page_offset);
1397 sg1entry->vaddr = tmp_addr;
1398 swqe->descriptors++;
1399 sg1entry_contains_frag_data = 1;
1400 }
1401
1402 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1403
1404 frag = &skb_shinfo(skb)->frags[i];
1405 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1406
1407 sgentry->l_key = lkey;
1408 sgentry->len = frag->size;
1409
1410 tmp_addr = (u64)(page_address(frag->page)
1411 + frag->page_offset);
1412 sgentry->vaddr = tmp_addr;
1413 swqe->descriptors++;
1414 }
1415 }
1416}
1417
1418static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1419{
1420 int ret = 0;
1421 u64 hret;
1422 u8 reg_type;
1423
1424 /* De/Register untagged packets */
1425 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1426 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1427 port->logical_port_id,
1428 reg_type, port->mac_addr, 0, hcallid);
1429 if (hret != H_SUCCESS) {
1430 ehea_error("reg_dereg_bcmc failed (tagged)");
1431 ret = -EIO;
1432 goto out_herr;
1433 }
1434
1435 /* De/Register VLAN packets */
1436 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1437 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1438 port->logical_port_id,
1439 reg_type, port->mac_addr, 0, hcallid);
1440 if (hret != H_SUCCESS) {
1441 ehea_error("reg_dereg_bcmc failed (vlan)");
1442 ret = -EIO;
1443 }
1444out_herr:
1445 return ret;
1446}
1447
1448static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1449{
1450 struct ehea_port *port = netdev_priv(dev);
1451 struct sockaddr *mac_addr = sa;
1452 struct hcp_ehea_port_cb0 *cb0;
1453 int ret;
1454 u64 hret;
1455
1456 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1457 ret = -EADDRNOTAVAIL;
1458 goto out;
1459 }
1460
Thomas Kleina1d261c2006-11-03 17:48:23 +01001461 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001462 if (!cb0) {
1463 ehea_error("no mem for cb0");
1464 ret = -ENOMEM;
1465 goto out;
1466 }
1467
1468 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1469
1470 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1471
1472 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1473 port->logical_port_id, H_PORT_CB0,
1474 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1475 if (hret != H_SUCCESS) {
1476 ret = -EIO;
1477 goto out_free;
1478 }
1479
1480 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1481
1482 /* Deregister old MAC in pHYP */
1483 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1484 if (ret)
1485 goto out_free;
1486
1487 port->mac_addr = cb0->port_mac_addr << 16;
1488
1489 /* Register new MAC in pHYP */
1490 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1491 if (ret)
1492 goto out_free;
1493
1494 ret = 0;
1495out_free:
1496 kfree(cb0);
1497out:
1498 return ret;
1499}
1500
1501static void ehea_promiscuous_error(u64 hret, int enable)
1502{
Thomas Klein7674a582007-01-22 12:54:20 +01001503 if (hret == H_AUTHORITY)
1504 ehea_info("Hypervisor denied %sabling promiscuous mode",
1505 enable == 1 ? "en" : "dis");
1506 else
1507 ehea_error("failed %sabling promiscuous mode",
1508 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509}
1510
1511static void ehea_promiscuous(struct net_device *dev, int enable)
1512{
1513 struct ehea_port *port = netdev_priv(dev);
1514 struct hcp_ehea_port_cb7 *cb7;
1515 u64 hret;
1516
1517 if ((enable && port->promisc) || (!enable && !port->promisc))
1518 return;
1519
Thomas Kleina1d261c2006-11-03 17:48:23 +01001520 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001521 if (!cb7) {
1522 ehea_error("no mem for cb7");
1523 goto out;
1524 }
1525
1526 /* Modify Pxs_DUCQPN in CB7 */
1527 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1528
1529 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1530 port->logical_port_id,
1531 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1532 if (hret) {
1533 ehea_promiscuous_error(hret, enable);
1534 goto out;
1535 }
1536
1537 port->promisc = enable;
1538out:
1539 kfree(cb7);
1540 return;
1541}
1542
1543static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1544 u32 hcallid)
1545{
1546 u64 hret;
1547 u8 reg_type;
1548
1549 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1550 | EHEA_BCMC_UNTAGGED;
1551
1552 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1553 port->logical_port_id,
1554 reg_type, mc_mac_addr, 0, hcallid);
1555 if (hret)
1556 goto out;
1557
1558 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1559 | EHEA_BCMC_VLANID_ALL;
1560
1561 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1562 port->logical_port_id,
1563 reg_type, mc_mac_addr, 0, hcallid);
1564out:
1565 return hret;
1566}
1567
1568static int ehea_drop_multicast_list(struct net_device *dev)
1569{
1570 struct ehea_port *port = netdev_priv(dev);
1571 struct ehea_mc_list *mc_entry = port->mc_list;
1572 struct list_head *pos;
1573 struct list_head *temp;
1574 int ret = 0;
1575 u64 hret;
1576
1577 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1578 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1579
1580 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1581 H_DEREG_BCMC);
1582 if (hret) {
1583 ehea_error("failed deregistering mcast MAC");
1584 ret = -EIO;
1585 }
1586
1587 list_del(pos);
1588 kfree(mc_entry);
1589 }
1590 return ret;
1591}
1592
1593static void ehea_allmulti(struct net_device *dev, int enable)
1594{
1595 struct ehea_port *port = netdev_priv(dev);
1596 u64 hret;
1597
1598 if (!port->allmulti) {
1599 if (enable) {
1600 /* Enable ALLMULTI */
1601 ehea_drop_multicast_list(dev);
1602 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1603 if (!hret)
1604 port->allmulti = 1;
1605 else
1606 ehea_error("failed enabling IFF_ALLMULTI");
1607 }
1608 } else
1609 if (!enable) {
1610 /* Disable ALLMULTI */
1611 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1612 if (!hret)
1613 port->allmulti = 0;
1614 else
1615 ehea_error("failed disabling IFF_ALLMULTI");
1616 }
1617}
1618
1619static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
1620{
1621 struct ehea_mc_list *ehea_mcl_entry;
1622 u64 hret;
1623
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001624 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625 if (!ehea_mcl_entry) {
1626 ehea_error("no mem for mcl_entry");
1627 return;
1628 }
1629
1630 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1631
1632 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1633
1634 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1635 H_REG_BCMC);
1636 if (!hret)
1637 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1638 else {
1639 ehea_error("failed registering mcast MAC");
1640 kfree(ehea_mcl_entry);
1641 }
1642}
1643
1644static void ehea_set_multicast_list(struct net_device *dev)
1645{
1646 struct ehea_port *port = netdev_priv(dev);
1647 struct dev_mc_list *k_mcl_entry;
1648 int ret, i;
1649
1650 if (dev->flags & IFF_PROMISC) {
1651 ehea_promiscuous(dev, 1);
1652 return;
1653 }
1654 ehea_promiscuous(dev, 0);
1655
1656 if (dev->flags & IFF_ALLMULTI) {
1657 ehea_allmulti(dev, 1);
1658 return;
1659 }
1660 ehea_allmulti(dev, 0);
1661
1662 if (dev->mc_count) {
1663 ret = ehea_drop_multicast_list(dev);
1664 if (ret) {
1665 /* Dropping the current multicast list failed.
1666 * Enabling ALL_MULTI is the best we can do.
1667 */
1668 ehea_allmulti(dev, 1);
1669 }
1670
1671 if (dev->mc_count > port->adapter->max_mc_mac) {
1672 ehea_info("Mcast registration limit reached (0x%lx). "
1673 "Use ALLMULTI!",
1674 port->adapter->max_mc_mac);
1675 goto out;
1676 }
1677
1678 for (i = 0, k_mcl_entry = dev->mc_list;
1679 i < dev->mc_count;
1680 i++, k_mcl_entry = k_mcl_entry->next) {
1681 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1682 }
1683 }
1684out:
1685 return;
1686}
1687
1688static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1689{
1690 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1691 return -EINVAL;
1692 dev->mtu = new_mtu;
1693 return 0;
1694}
1695
1696static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1697 struct ehea_swqe *swqe, u32 lkey)
1698{
1699 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001700 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001701 /* IPv4 */
1702 swqe->tx_control |= EHEA_SWQE_CRC
1703 | EHEA_SWQE_IP_CHECKSUM
1704 | EHEA_SWQE_TCP_CHECKSUM
1705 | EHEA_SWQE_IMM_DATA_PRESENT
1706 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1707
1708 write_ip_start_end(swqe, skb);
1709
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001710 if (iph->protocol == IPPROTO_UDP) {
1711 if ((iph->frag_off & IP_MF) ||
1712 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001713 /* IP fragment, so don't change cs */
1714 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
1715 else
1716 write_udp_offset_end(swqe, skb);
1717
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001718 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001719 write_tcp_offset_end(swqe, skb);
1720 }
1721
1722 /* icmp (big data) and ip segmentation packets (all other ip
1723 packets) do not require any special handling */
1724
1725 } else {
1726 /* Other Ethernet Protocol */
1727 swqe->tx_control |= EHEA_SWQE_CRC
1728 | EHEA_SWQE_IMM_DATA_PRESENT
1729 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1730 }
1731
1732 write_swqe2_data(skb, dev, swqe, lkey);
1733}
1734
1735static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
1736 struct ehea_swqe *swqe)
1737{
1738 int nfrags = skb_shinfo(skb)->nr_frags;
1739 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
1740 skb_frag_t *frag;
1741 int i;
1742
1743 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001744 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745 /* IPv4 */
1746 write_ip_start_end(swqe, skb);
1747
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001748 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001749 swqe->tx_control |= EHEA_SWQE_CRC
1750 | EHEA_SWQE_IP_CHECKSUM
1751 | EHEA_SWQE_TCP_CHECKSUM
1752 | EHEA_SWQE_IMM_DATA_PRESENT;
1753
1754 write_tcp_offset_end(swqe, skb);
1755
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001756 } else if (iph->protocol == IPPROTO_UDP) {
1757 if ((iph->frag_off & IP_MF) ||
1758 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001759 /* IP fragment, so don't change cs */
1760 swqe->tx_control |= EHEA_SWQE_CRC
1761 | EHEA_SWQE_IMM_DATA_PRESENT;
1762 else {
1763 swqe->tx_control |= EHEA_SWQE_CRC
1764 | EHEA_SWQE_IP_CHECKSUM
1765 | EHEA_SWQE_TCP_CHECKSUM
1766 | EHEA_SWQE_IMM_DATA_PRESENT;
1767
1768 write_udp_offset_end(swqe, skb);
1769 }
1770 } else {
1771 /* icmp (big data) and
1772 ip segmentation packets (all other ip packets) */
1773 swqe->tx_control |= EHEA_SWQE_CRC
1774 | EHEA_SWQE_IP_CHECKSUM
1775 | EHEA_SWQE_IMM_DATA_PRESENT;
1776 }
1777 } else {
1778 /* Other Ethernet Protocol */
1779 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
1780 }
1781 /* copy (immediate) data */
1782 if (nfrags == 0) {
1783 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001784 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785 } else {
1786 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001787 skb_copy_from_linear_data(skb, imm_data,
1788 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001789 imm_data += skb->len - skb->data_len;
1790
1791 /* ... then copy data from the fragments */
1792 for (i = 0; i < nfrags; i++) {
1793 frag = &skb_shinfo(skb)->frags[i];
1794 memcpy(imm_data,
1795 page_address(frag->page) + frag->page_offset,
1796 frag->size);
1797 imm_data += frag->size;
1798 }
1799 }
1800 swqe->immediate_data_length = skb->len;
1801 dev_kfree_skb(skb);
1802}
1803
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001804static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
1805{
1806 struct tcphdr *tcp;
1807 u32 tmp;
1808
1809 if ((skb->protocol == htons(ETH_P_IP)) &&
1810 (skb->nh.iph->protocol == IPPROTO_TCP)) {
1811 tcp = (struct tcphdr*)(skb->nh.raw + (skb->nh.iph->ihl * 4));
1812 tmp = (tcp->source + (tcp->dest << 16)) % 31;
1813 tmp += skb->nh.iph->daddr % 31;
1814 return tmp % num_qps;
1815 }
1816 else
1817 return 0;
1818}
1819
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001820static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
1821{
1822 struct ehea_port *port = netdev_priv(dev);
1823 struct ehea_swqe *swqe;
1824 unsigned long flags;
1825 u32 lkey;
1826 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001827 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001828
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001829 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
1830
1831
1832 if (!spin_trylock(&pr->xmit_lock))
1833 return NETDEV_TX_BUSY;
1834
1835 if (pr->queue_stopped) {
1836 spin_unlock(&pr->xmit_lock);
1837 return NETDEV_TX_BUSY;
1838 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001839
1840 swqe = ehea_get_swqe(pr->qp, &swqe_index);
1841 memset(swqe, 0, SWQE_HEADER_SIZE);
1842 atomic_dec(&pr->swqe_avail);
1843
1844 if (skb->len <= SWQE3_MAX_IMM) {
1845 u32 sig_iv = port->sig_comp_iv;
1846 u32 swqe_num = pr->swqe_id_counter;
1847 ehea_xmit3(skb, dev, swqe);
1848 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
1849 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
1850 if (pr->swqe_ll_count >= (sig_iv - 1)) {
1851 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1852 sig_iv);
1853 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1854 pr->swqe_ll_count = 0;
1855 } else
1856 pr->swqe_ll_count += 1;
1857 } else {
1858 swqe->wr_id =
1859 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
1860 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
1861 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
1862 pr->sq_skba.arr[pr->sq_skba.index] = skb;
1863
1864 pr->sq_skba.index++;
1865 pr->sq_skba.index &= (pr->sq_skba.len - 1);
1866
1867 lkey = pr->send_mr.lkey;
1868 ehea_xmit2(skb, dev, swqe, lkey);
1869
1870 if (pr->swqe_count >= (EHEA_SIG_IV_LONG - 1)) {
1871 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1872 EHEA_SIG_IV_LONG);
1873 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1874 pr->swqe_count = 0;
1875 } else
1876 pr->swqe_count += 1;
1877 }
1878 pr->swqe_id_counter += 1;
1879
1880 if (port->vgrp && vlan_tx_tag_present(skb)) {
1881 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
1882 swqe->vlan_tag = vlan_tx_tag_get(skb);
1883 }
1884
1885 if (netif_msg_tx_queued(port)) {
1886 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001887 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001888 }
1889
1890 ehea_post_swqe(pr->qp, swqe);
1891 pr->tx_packets++;
1892
1893 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1894 spin_lock_irqsave(&pr->netif_queue, flags);
1895 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1896 netif_stop_queue(dev);
1897 pr->queue_stopped = 1;
1898 }
1899 spin_unlock_irqrestore(&pr->netif_queue, flags);
1900 }
1901 dev->trans_start = jiffies;
1902 spin_unlock(&pr->xmit_lock);
1903
1904 return NETDEV_TX_OK;
1905}
1906
1907static void ehea_vlan_rx_register(struct net_device *dev,
1908 struct vlan_group *grp)
1909{
1910 struct ehea_port *port = netdev_priv(dev);
1911 struct ehea_adapter *adapter = port->adapter;
1912 struct hcp_ehea_port_cb1 *cb1;
1913 u64 hret;
1914
1915 port->vgrp = grp;
1916
Thomas Kleina1d261c2006-11-03 17:48:23 +01001917 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001918 if (!cb1) {
1919 ehea_error("no mem for cb1");
1920 goto out;
1921 }
1922
1923 if (grp)
1924 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
1925 else
1926 memset(cb1->vlan_filter, 0xFF, sizeof(cb1->vlan_filter));
1927
1928 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1929 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1930 if (hret != H_SUCCESS)
1931 ehea_error("modify_ehea_port failed");
1932
1933 kfree(cb1);
1934out:
1935 return;
1936}
1937
1938static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1939{
1940 struct ehea_port *port = netdev_priv(dev);
1941 struct ehea_adapter *adapter = port->adapter;
1942 struct hcp_ehea_port_cb1 *cb1;
1943 int index;
1944 u64 hret;
1945
Thomas Kleina1d261c2006-11-03 17:48:23 +01001946 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 if (!cb1) {
1948 ehea_error("no mem for cb1");
1949 goto out;
1950 }
1951
1952 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1953 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1954 if (hret != H_SUCCESS) {
1955 ehea_error("query_ehea_port failed");
1956 goto out;
1957 }
1958
1959 index = (vid / 64);
1960 cb1->vlan_filter[index] |= ((u64)(1 << (vid & 0x3F)));
1961
1962 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1963 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1964 if (hret != H_SUCCESS)
1965 ehea_error("modify_ehea_port failed");
1966out:
1967 kfree(cb1);
1968 return;
1969}
1970
1971static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1972{
1973 struct ehea_port *port = netdev_priv(dev);
1974 struct ehea_adapter *adapter = port->adapter;
1975 struct hcp_ehea_port_cb1 *cb1;
1976 int index;
1977 u64 hret;
1978
Dan Aloni5c15bde2007-03-02 20:44:51 -08001979 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001980
Thomas Kleina1d261c2006-11-03 17:48:23 +01001981 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001982 if (!cb1) {
1983 ehea_error("no mem for cb1");
1984 goto out;
1985 }
1986
1987 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1988 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1989 if (hret != H_SUCCESS) {
1990 ehea_error("query_ehea_port failed");
1991 goto out;
1992 }
1993
1994 index = (vid / 64);
1995 cb1->vlan_filter[index] &= ~((u64)(1 << (vid & 0x3F)));
1996
1997 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1998 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1999 if (hret != H_SUCCESS)
2000 ehea_error("modify_ehea_port failed");
2001out:
2002 kfree(cb1);
2003 return;
2004}
2005
2006int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2007{
2008 int ret = -EIO;
2009 u64 hret;
2010 u16 dummy16 = 0;
2011 u64 dummy64 = 0;
2012 struct hcp_modify_qp_cb0* cb0;
2013
Thomas Kleina1d261c2006-11-03 17:48:23 +01002014 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002015 if (!cb0) {
2016 ret = -ENOMEM;
2017 goto out;
2018 }
2019
2020 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2021 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2022 if (hret != H_SUCCESS) {
2023 ehea_error("query_ehea_qp failed (1)");
2024 goto out;
2025 }
2026
2027 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2028 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2029 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2030 &dummy64, &dummy64, &dummy16, &dummy16);
2031 if (hret != H_SUCCESS) {
2032 ehea_error("modify_ehea_qp failed (1)");
2033 goto out;
2034 }
2035
2036 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2037 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2038 if (hret != H_SUCCESS) {
2039 ehea_error("query_ehea_qp failed (2)");
2040 goto out;
2041 }
2042
2043 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2044 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2045 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2046 &dummy64, &dummy64, &dummy16, &dummy16);
2047 if (hret != H_SUCCESS) {
2048 ehea_error("modify_ehea_qp failed (2)");
2049 goto out;
2050 }
2051
2052 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2053 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2054 if (hret != H_SUCCESS) {
2055 ehea_error("query_ehea_qp failed (3)");
2056 goto out;
2057 }
2058
2059 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2060 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2061 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2062 &dummy64, &dummy64, &dummy16, &dummy16);
2063 if (hret != H_SUCCESS) {
2064 ehea_error("modify_ehea_qp failed (3)");
2065 goto out;
2066 }
2067
2068 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2069 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2070 if (hret != H_SUCCESS) {
2071 ehea_error("query_ehea_qp failed (4)");
2072 goto out;
2073 }
2074
2075 ret = 0;
2076out:
2077 kfree(cb0);
2078 return ret;
2079}
2080
2081static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2082 int add_tx_qps)
2083{
2084 int ret, i;
2085 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2086 enum ehea_eq_type eq_type = EHEA_EQ;
2087
2088 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2089 EHEA_MAX_ENTRIES_EQ, 1);
2090 if (!port->qp_eq) {
2091 ret = -EINVAL;
2092 ehea_error("ehea_create_eq failed (qp_eq)");
2093 goto out_kill_eq;
2094 }
2095
2096 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002097 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002098 pr_cfg.max_entries_sq = sq_entries;
2099 pr_cfg.max_entries_rq1 = rq1_entries;
2100 pr_cfg.max_entries_rq2 = rq2_entries;
2101 pr_cfg.max_entries_rq3 = rq3_entries;
2102
2103 pr_cfg_small_rx.max_entries_rcq = 1;
2104 pr_cfg_small_rx.max_entries_scq = sq_entries;
2105 pr_cfg_small_rx.max_entries_sq = sq_entries;
2106 pr_cfg_small_rx.max_entries_rq1 = 1;
2107 pr_cfg_small_rx.max_entries_rq2 = 1;
2108 pr_cfg_small_rx.max_entries_rq3 = 1;
2109
2110 for (i = 0; i < def_qps; i++) {
2111 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2112 if (ret)
2113 goto out_clean_pr;
2114 }
2115 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2116 ret = ehea_init_port_res(port, &port->port_res[i],
2117 &pr_cfg_small_rx, i);
2118 if (ret)
2119 goto out_clean_pr;
2120 }
2121
2122 return 0;
2123
2124out_clean_pr:
2125 while (--i >= 0)
2126 ehea_clean_portres(port, &port->port_res[i]);
2127
2128out_kill_eq:
2129 ehea_destroy_eq(port->qp_eq);
2130 return ret;
2131}
2132
2133static int ehea_clean_all_portres(struct ehea_port *port)
2134{
2135 int ret = 0;
2136 int i;
2137
2138 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2139 ret |= ehea_clean_portres(port, &port->port_res[i]);
2140
2141 ret |= ehea_destroy_eq(port->qp_eq);
2142
2143 return ret;
2144}
2145
2146static int ehea_up(struct net_device *dev)
2147{
2148 int ret, i;
2149 struct ehea_port *port = netdev_priv(dev);
2150 u64 mac_addr = 0;
2151
2152 if (port->state == EHEA_PORT_UP)
2153 return 0;
2154
2155 ret = ehea_port_res_setup(port, port->num_def_qps,
2156 port->num_add_tx_qps);
2157 if (ret) {
2158 ehea_error("port_res_failed");
2159 goto out;
2160 }
2161
2162 /* Set default QP for this port */
2163 ret = ehea_configure_port(port);
2164 if (ret) {
2165 ehea_error("ehea_configure_port failed. ret:%d", ret);
2166 goto out_clean_pr;
2167 }
2168
2169 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2170 if (ret) {
2171 ret = -EIO;
2172 ehea_error("out_clean_pr");
2173 goto out_clean_pr;
2174 }
2175 mac_addr = (*(u64*)dev->dev_addr) >> 16;
2176
2177 ret = ehea_reg_interrupts(dev);
2178 if (ret) {
2179 ehea_error("out_dereg_bc");
2180 goto out_dereg_bc;
2181 }
2182
2183 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2184 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2185 if (ret) {
2186 ehea_error("activate_qp failed");
2187 goto out_free_irqs;
2188 }
2189 }
2190
2191 for(i = 0; i < port->num_def_qps; i++) {
2192 ret = ehea_fill_port_res(&port->port_res[i]);
2193 if (ret) {
2194 ehea_error("out_free_irqs");
2195 goto out_free_irqs;
2196 }
2197 }
2198
2199 ret = 0;
2200 port->state = EHEA_PORT_UP;
2201 goto out;
2202
2203out_free_irqs:
2204 ehea_free_interrupts(dev);
2205
2206out_dereg_bc:
2207 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2208
2209out_clean_pr:
2210 ehea_clean_all_portres(port);
2211out:
2212 return ret;
2213}
2214
2215static int ehea_open(struct net_device *dev)
2216{
2217 int ret;
2218 struct ehea_port *port = netdev_priv(dev);
2219
2220 down(&port->port_lock);
2221
2222 if (netif_msg_ifup(port))
2223 ehea_info("enabling port %s", dev->name);
2224
2225 ret = ehea_up(dev);
2226 if (!ret)
2227 netif_start_queue(dev);
2228
2229 up(&port->port_lock);
2230
2231 return ret;
2232}
2233
2234static int ehea_down(struct net_device *dev)
2235{
2236 int ret, i;
2237 struct ehea_port *port = netdev_priv(dev);
2238
2239 if (port->state == EHEA_PORT_DOWN)
2240 return 0;
2241
2242 ehea_drop_multicast_list(dev);
2243 ehea_free_interrupts(dev);
2244
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002245 for (i = 0; i < port->num_def_qps; i++)
2246 while (test_bit(__LINK_STATE_RX_SCHED,
2247 &port->port_res[i].d_netdev->state))
2248 msleep(1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002249
2250 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2251 ret = ehea_clean_all_portres(port);
2252 port->state = EHEA_PORT_DOWN;
2253 return ret;
2254}
2255
2256static int ehea_stop(struct net_device *dev)
2257{
2258 int ret;
2259 struct ehea_port *port = netdev_priv(dev);
2260
2261 if (netif_msg_ifdown(port))
2262 ehea_info("disabling port %s", dev->name);
2263
2264 flush_workqueue(port->adapter->ehea_wq);
2265 down(&port->port_lock);
2266 netif_stop_queue(dev);
2267 ret = ehea_down(dev);
2268 up(&port->port_lock);
2269 return ret;
2270}
2271
David Howellsc4028952006-11-22 14:57:56 +00002272static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273{
2274 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002275 struct ehea_port *port =
2276 container_of(work, struct ehea_port, reset_task);
2277 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002278
2279 port->resets++;
2280 down(&port->port_lock);
2281 netif_stop_queue(dev);
2282 netif_poll_disable(dev);
2283
2284 ret = ehea_down(dev);
2285 if (ret)
2286 ehea_error("ehea_down failed. not all resources are freed");
2287
2288 ret = ehea_up(dev);
2289 if (ret) {
2290 ehea_error("Reset device %s failed: ret=%d", dev->name, ret);
2291 goto out;
2292 }
2293
2294 if (netif_msg_timer(port))
2295 ehea_info("Device %s resetted successfully", dev->name);
2296
2297 netif_poll_enable(dev);
2298 netif_wake_queue(dev);
2299out:
2300 up(&port->port_lock);
2301 return;
2302}
2303
2304static void ehea_tx_watchdog(struct net_device *dev)
2305{
2306 struct ehea_port *port = netdev_priv(dev);
2307
2308 if (netif_carrier_ok(dev))
2309 queue_work(port->adapter->ehea_wq, &port->reset_task);
2310}
2311
2312int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2313{
2314 struct hcp_query_ehea *cb;
2315 u64 hret;
2316 int ret;
2317
Thomas Kleina1d261c2006-11-03 17:48:23 +01002318 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319 if (!cb) {
2320 ret = -ENOMEM;
2321 goto out;
2322 }
2323
2324 hret = ehea_h_query_ehea(adapter->handle, cb);
2325
2326 if (hret != H_SUCCESS) {
2327 ret = -EIO;
2328 goto out_herr;
2329 }
2330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 adapter->max_mc_mac = cb->max_mc_mac - 1;
2332 ret = 0;
2333
2334out_herr:
2335 kfree(cb);
2336out:
2337 return ret;
2338}
2339
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002340int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2341{
2342 struct hcp_ehea_port_cb4 *cb4;
2343 u64 hret;
2344 int ret = 0;
2345
2346 *jumbo = 0;
2347
2348 /* (Try to) enable *jumbo frames */
2349 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2350 if (!cb4) {
2351 ehea_error("no mem for cb4");
2352 ret = -ENOMEM;
2353 goto out;
2354 } else {
2355 hret = ehea_h_query_ehea_port(port->adapter->handle,
2356 port->logical_port_id,
2357 H_PORT_CB4,
2358 H_PORT_CB4_JUMBO, cb4);
2359 if (hret == H_SUCCESS) {
2360 if (cb4->jumbo_frame)
2361 *jumbo = 1;
2362 else {
2363 cb4->jumbo_frame = 1;
2364 hret = ehea_h_modify_ehea_port(port->adapter->
2365 handle,
2366 port->
2367 logical_port_id,
2368 H_PORT_CB4,
2369 H_PORT_CB4_JUMBO,
2370 cb4);
2371 if (hret == H_SUCCESS)
2372 *jumbo = 1;
2373 }
2374 } else
2375 ret = -EINVAL;
2376
2377 kfree(cb4);
2378 }
2379out:
2380 return ret;
2381}
2382
2383static ssize_t ehea_show_port_id(struct device *dev,
2384 struct device_attribute *attr, char *buf)
2385{
2386 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
2387 return sprintf(buf, "0x%X", port->logical_port_id);
2388}
2389
2390static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2391 NULL);
2392
2393static void __devinit logical_port_release(struct device *dev)
2394{
2395 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
2396 of_node_put(port->ofdev.node);
2397}
2398
2399static struct device *ehea_register_port(struct ehea_port *port,
2400 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401{
2402 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002403
2404 port->ofdev.node = of_node_get(dn);
2405 port->ofdev.dev.parent = &port->adapter->ebus_dev->ofdev.dev;
2406
2407 sprintf(port->ofdev.dev.bus_id, "port%d", port->logical_port_id);
2408 port->ofdev.dev.release = logical_port_release;
2409
2410 ret = of_device_register(&port->ofdev);
2411 if (ret) {
2412 ehea_error("failed to register device. ret=%d", ret);
2413 goto out;
2414 }
2415
2416 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
2417 if (ret) {
2418 ehea_error("failed to register attributes, ret=%d", ret);
2419 goto out_unreg_of_dev;
2420 }
2421
2422 return &port->ofdev.dev;
2423
2424out_unreg_of_dev:
2425 of_device_unregister(&port->ofdev);
2426out:
2427 return NULL;
2428}
2429
2430static void ehea_unregister_port(struct ehea_port *port)
2431{
2432 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2433 of_device_unregister(&port->ofdev);
2434}
2435
2436struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
2437 u32 logical_port_id,
2438 struct device_node *dn)
2439{
2440 int ret;
2441 struct net_device *dev;
2442 struct ehea_port *port;
2443 struct device *port_dev;
2444 int jumbo;
2445
2446 /* allocate memory for the port structures */
2447 dev = alloc_etherdev(sizeof(struct ehea_port));
2448
2449 if (!dev) {
2450 ehea_error("no mem for net_device");
2451 ret = -ENOMEM;
2452 goto out_err;
2453 }
2454
2455 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002456
2457 sema_init(&port->port_lock, 1);
2458 port->state = EHEA_PORT_DOWN;
2459 port->sig_comp_iv = sq_entries / 10;
2460
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002461 port->adapter = adapter;
2462 port->netdev = dev;
2463 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002464
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002465 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002466
2467 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2468 if (!port->mc_list) {
2469 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002470 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002471 }
2472
2473 INIT_LIST_HEAD(&port->mc_list->list);
2474
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002475 ret = ehea_sense_port_attr(port);
2476 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002477 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002479 port_dev = ehea_register_port(port, dn);
2480 if (!port_dev)
2481 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01002482
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002483 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002484
2485 /* initialize net_device structure */
2486 SET_MODULE_OWNER(dev);
2487
2488 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2489
2490 dev->open = ehea_open;
2491 dev->poll = ehea_poll;
2492 dev->weight = 64;
2493 dev->stop = ehea_stop;
2494 dev->hard_start_xmit = ehea_start_xmit;
2495 dev->get_stats = ehea_get_stats;
2496 dev->set_multicast_list = ehea_set_multicast_list;
2497 dev->set_mac_address = ehea_set_mac_addr;
2498 dev->change_mtu = ehea_change_mtu;
2499 dev->vlan_rx_register = ehea_vlan_rx_register;
2500 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
2501 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
2502 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
2503 | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX
2504 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
2505 | NETIF_F_LLTX;
2506 dev->tx_timeout = &ehea_tx_watchdog;
2507 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
2508
David Howellsc4028952006-11-22 14:57:56 +00002509 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002510
2511 ehea_set_ethtool_ops(dev);
2512
2513 ret = register_netdev(dev);
2514 if (ret) {
2515 ehea_error("register_netdev failed. ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002516 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002517 }
2518
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002519 ret = ehea_get_jumboframe_status(port, &jumbo);
2520 if (ret)
2521 ehea_error("failed determining jumbo frame status for %s",
2522 port->netdev->name);
2523
Thomas Klein9c750b72007-01-29 18:44:01 +01002524 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2525 jumbo == 1 ? "en" : "dis");
2526
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002527 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002528
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002529out_unreg_port:
2530 ehea_unregister_port(port);
2531
2532out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002533 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002534
2535out_free_ethdev:
2536 free_netdev(dev);
2537
2538out_err:
2539 ehea_error("setting up logical port with id=%d failed, ret=%d",
2540 logical_port_id, ret);
2541 return NULL;
2542}
2543
2544static void ehea_shutdown_single_port(struct ehea_port *port)
2545{
2546 unregister_netdev(port->netdev);
2547 ehea_unregister_port(port);
2548 kfree(port->mc_list);
2549 free_netdev(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002550}
2551
2552static int ehea_setup_ports(struct ehea_adapter *adapter)
2553{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002554 struct device_node *lhea_dn;
2555 struct device_node *eth_dn = NULL;
2556
2557 u32 *dn_log_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558 int port_setup_ok = 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002559 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002560
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002561 lhea_dn = adapter->ebus_dev->ofdev.node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002562 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
2563
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002564 dn_log_port_id = (u32*)get_property(eth_dn, "ibm,hea-port-no",
2565 NULL);
2566 if (!dn_log_port_id) {
2567 ehea_error("bad device node: eth_dn name=%s",
2568 eth_dn->full_name);
2569 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002570 }
2571
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002572 adapter->port[i] = ehea_setup_single_port(adapter,
2573 *dn_log_port_id,
2574 eth_dn);
2575 if (adapter->port[i])
2576 ehea_info("%s -> logical port id #%d",
2577 adapter->port[i]->netdev->name,
2578 *dn_log_port_id);
2579 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002580 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002581
2582 /* Check for succesfully set up ports */
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002583 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002584 if (adapter->port[i])
2585 port_setup_ok++;
2586
2587 if (port_setup_ok)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002588 return 0; /* At least some ports are setup correctly */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002590 return -EINVAL;
2591}
2592
2593static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
2594 u32 logical_port_id)
2595{
2596 struct device_node *lhea_dn;
2597 struct device_node *eth_dn = NULL;
2598 u32 *dn_log_port_id;
2599
2600 lhea_dn = adapter->ebus_dev->ofdev.node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002601 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
2602
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002603 dn_log_port_id = (u32*)get_property(eth_dn, "ibm,hea-port-no",
2604 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002605 if (dn_log_port_id)
2606 if (*dn_log_port_id == logical_port_id)
2607 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002608 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002609
2610 return NULL;
2611}
2612
2613static ssize_t ehea_probe_port(struct device *dev,
2614 struct device_attribute *attr,
2615 const char *buf, size_t count)
2616{
2617 struct ehea_adapter *adapter = dev->driver_data;
2618 struct ehea_port *port;
2619 struct device_node *eth_dn = NULL;
2620 int i;
2621
2622 u32 logical_port_id;
2623
2624 sscanf(buf, "%X", &logical_port_id);
2625
2626 port = ehea_get_port(adapter, logical_port_id);
2627
2628 if (port) {
2629 ehea_info("adding port with logical port id=%d failed. port "
2630 "already configured as %s.", logical_port_id,
2631 port->netdev->name);
2632 return -EINVAL;
2633 }
2634
2635 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
2636
2637 if (!eth_dn) {
2638 ehea_info("no logical port with id %d found", logical_port_id);
2639 return -EINVAL;
2640 }
2641
2642 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
2643
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002644 of_node_put(eth_dn);
2645
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002646 if (port) {
2647 for (i=0; i < EHEA_MAX_PORTS; i++)
2648 if (!adapter->port[i]) {
2649 adapter->port[i] = port;
2650 break;
2651 }
2652
2653 ehea_info("added %s (logical port id=%d)", port->netdev->name,
2654 logical_port_id);
2655 } else
2656 return -EIO;
2657
2658 return (ssize_t) count;
2659}
2660
2661static ssize_t ehea_remove_port(struct device *dev,
2662 struct device_attribute *attr,
2663 const char *buf, size_t count)
2664{
2665 struct ehea_adapter *adapter = dev->driver_data;
2666 struct ehea_port *port;
2667 int i;
2668 u32 logical_port_id;
2669
2670 sscanf(buf, "%X", &logical_port_id);
2671
2672 port = ehea_get_port(adapter, logical_port_id);
2673
2674 if (port) {
2675 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
2676 logical_port_id);
2677
2678 ehea_shutdown_single_port(port);
2679
2680 for (i=0; i < EHEA_MAX_PORTS; i++)
2681 if (adapter->port[i] == port) {
2682 adapter->port[i] = NULL;
2683 break;
2684 }
2685 } else {
2686 ehea_error("removing port with logical port id=%d failed. port "
2687 "not configured.", logical_port_id);
2688 return -EINVAL;
2689 }
2690
2691 return (ssize_t) count;
2692}
2693
2694static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
2695static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
2696
2697int ehea_create_device_sysfs(struct ibmebus_dev *dev)
2698{
2699 int ret = device_create_file(&dev->ofdev.dev, &dev_attr_probe_port);
2700 if (ret)
2701 goto out;
2702
2703 ret = device_create_file(&dev->ofdev.dev, &dev_attr_remove_port);
2704out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002705 return ret;
2706}
2707
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002708void ehea_remove_device_sysfs(struct ibmebus_dev *dev)
2709{
2710 device_remove_file(&dev->ofdev.dev, &dev_attr_probe_port);
2711 device_remove_file(&dev->ofdev.dev, &dev_attr_remove_port);
2712}
2713
2714static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
2715 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716{
2717 struct ehea_adapter *adapter;
2718 u64 *adapter_handle;
2719 int ret;
2720
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002721 if (!dev || !dev->ofdev.node) {
2722 ehea_error("Invalid ibmebus device probed");
2723 return -EINVAL;
2724 }
2725
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
2727 if (!adapter) {
2728 ret = -ENOMEM;
2729 dev_err(&dev->ofdev.dev, "no mem for ehea_adapter\n");
2730 goto out;
2731 }
2732
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002733 adapter->ebus_dev = dev;
2734
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle",
2736 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01002737 if (adapter_handle)
2738 adapter->handle = *adapter_handle;
2739
2740 if (!adapter->handle) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002741 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
2742 " '%s'\n", dev->ofdev.node->full_name);
2743 ret = -ENODEV;
2744 goto out_free_ad;
2745 }
2746
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002747 adapter->pd = EHEA_PD_ID;
2748
2749 dev->ofdev.dev.driver_data = adapter;
2750
2751 ret = ehea_reg_mr_adapter(adapter);
2752 if (ret) {
2753 dev_err(&dev->ofdev.dev, "reg_mr_adapter failed\n");
2754 goto out_free_ad;
2755 }
2756
2757 /* initialize adapter and ports */
2758 /* get adapter properties */
2759 ret = ehea_sense_adapter_attr(adapter);
2760 if (ret) {
2761 dev_err(&dev->ofdev.dev, "sense_adapter_attr failed: %d", ret);
2762 goto out_free_res;
2763 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002764
2765 adapter->neq = ehea_create_eq(adapter,
2766 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
2767 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002768 ret = -EIO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002769 dev_err(&dev->ofdev.dev, "NEQ creation failed");
2770 goto out_free_res;
2771 }
2772
2773 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
2774 (unsigned long)adapter);
2775
2776 ret = ibmebus_request_irq(NULL, adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08002777 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002778 "ehea_neq", adapter);
2779 if (ret) {
2780 dev_err(&dev->ofdev.dev, "requesting NEQ IRQ failed");
2781 goto out_kill_eq;
2782 }
2783
2784 adapter->ehea_wq = create_workqueue("ehea_wq");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002785 if (!adapter->ehea_wq) {
2786 ret = -EIO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002787 goto out_free_irq;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002788 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002789
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01002790 ret = ehea_create_device_sysfs(dev);
2791 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002792 goto out_kill_wq;
2793
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002794 ret = ehea_setup_ports(adapter);
2795 if (ret) {
2796 dev_err(&dev->ofdev.dev, "setup_ports failed");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002797 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002798 }
2799
2800 ret = 0;
2801 goto out;
2802
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002803out_rem_dev_sysfs:
2804 ehea_remove_device_sysfs(dev);
2805
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002806out_kill_wq:
2807 destroy_workqueue(adapter->ehea_wq);
2808
2809out_free_irq:
2810 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2811
2812out_kill_eq:
2813 ehea_destroy_eq(adapter->neq);
2814
2815out_free_res:
2816 ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2817
2818out_free_ad:
2819 kfree(adapter);
2820out:
2821 return ret;
2822}
2823
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002824static int __devexit ehea_remove(struct ibmebus_dev *dev)
2825{
2826 struct ehea_adapter *adapter = dev->ofdev.dev.driver_data;
2827 u64 hret;
2828 int i;
2829
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002830 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002831 if (adapter->port[i]) {
2832 ehea_shutdown_single_port(adapter->port[i]);
2833 adapter->port[i] = NULL;
2834 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002835
2836 ehea_remove_device_sysfs(dev);
2837
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002838 destroy_workqueue(adapter->ehea_wq);
2839
2840 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01002841 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002842
2843 ehea_destroy_eq(adapter->neq);
2844
2845 hret = ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2846 if (hret) {
2847 dev_err(&dev->ofdev.dev, "free_resource_mr failed");
2848 return -EIO;
2849 }
2850 kfree(adapter);
2851 return 0;
2852}
2853
2854static int check_module_parm(void)
2855{
2856 int ret = 0;
2857
2858 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
2859 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
2860 ehea_info("Bad parameter: rq1_entries");
2861 ret = -EINVAL;
2862 }
2863 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
2864 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
2865 ehea_info("Bad parameter: rq2_entries");
2866 ret = -EINVAL;
2867 }
2868 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
2869 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
2870 ehea_info("Bad parameter: rq3_entries");
2871 ret = -EINVAL;
2872 }
2873 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
2874 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
2875 ehea_info("Bad parameter: sq_entries");
2876 ret = -EINVAL;
2877 }
2878
2879 return ret;
2880}
2881
2882static struct of_device_id ehea_device_table[] = {
2883 {
2884 .name = "lhea",
2885 .compatible = "IBM,lhea",
2886 },
2887 {},
2888};
2889
2890static struct ibmebus_driver ehea_driver = {
2891 .name = "ehea",
2892 .id_table = ehea_device_table,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002893 .probe = ehea_probe_adapter,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002894 .remove = ehea_remove,
2895};
2896
2897int __init ehea_module_init(void)
2898{
2899 int ret;
2900
2901 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
2902 DRV_VERSION);
2903
2904 ret = check_module_parm();
2905 if (ret)
2906 goto out;
2907 ret = ibmebus_register_driver(&ehea_driver);
2908 if (ret)
2909 ehea_error("failed registering eHEA device driver on ebus");
2910
2911out:
2912 return ret;
2913}
2914
2915static void __exit ehea_module_exit(void)
2916{
2917 ibmebus_unregister_driver(&ehea_driver);
2918}
2919
2920module_init(ehea_module_init);
2921module_exit(ehea_module_exit);