2 * linux/drivers/net/ehea/ehea_main.c
4 * eHEA ethernet device driver for IBM eServer System p
6 * (C) Copyright IBM Corp. 2006
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
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)
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.
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.
31 #include <linux/tcp.h>
32 #include <linux/udp.h>
34 #include <linux/list.h>
35 #include <linux/if_ether.h>
36 #include <linux/notifier.h>
37 #include <linux/reboot.h>
43 #include "ehea_phyp.h"
46 MODULE_LICENSE("GPL");
47 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
48 MODULE_DESCRIPTION("IBM eServer HEA Driver");
49 MODULE_VERSION(DRV_VERSION
);
52 static int msg_level
= -1;
53 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
54 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
55 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
56 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
57 static int use_mcs
= 0;
58 static int use_lro
= 0;
59 static int lro_max_aggr
= EHEA_LRO_MAX_AGGR
;
60 static int num_tx_qps
= EHEA_NUM_TX_QP
;
61 static int prop_carrier_state
= 0;
63 module_param(msg_level
, int, 0);
64 module_param(rq1_entries
, int, 0);
65 module_param(rq2_entries
, int, 0);
66 module_param(rq3_entries
, int, 0);
67 module_param(sq_entries
, int, 0);
68 module_param(prop_carrier_state
, int, 0);
69 module_param(use_mcs
, int, 0);
70 module_param(use_lro
, int, 0);
71 module_param(lro_max_aggr
, int, 0);
72 module_param(num_tx_qps
, int, 0);
74 MODULE_PARM_DESC(num_tx_qps
, "Number of TX-QPS");
75 MODULE_PARM_DESC(msg_level
, "msg_level");
76 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
78 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
81 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
84 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
87 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
90 MODULE_PARM_DESC(use_mcs
, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
92 MODULE_PARM_DESC(lro_max_aggr
, " LRO: Max packets to be aggregated. Default = "
93 __MODULE_STRING(EHEA_LRO_MAX_AGGR
));
94 MODULE_PARM_DESC(use_lro
, " Large Receive Offload, 1: enable, 0: disable, "
97 static int port_name_cnt
= 0;
98 static LIST_HEAD(adapter_list
);
99 u64 ehea_driver_flags
= 0;
100 struct work_struct ehea_rereg_mr_task
;
102 struct semaphore dlpar_mem_lock
;
104 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
105 const struct of_device_id
*id
);
107 static int __devexit
ehea_remove(struct of_device
*dev
);
109 static struct of_device_id ehea_device_table
[] = {
112 .compatible
= "IBM,lhea",
117 static struct of_platform_driver ehea_driver
= {
119 .match_table
= ehea_device_table
,
120 .probe
= ehea_probe_adapter
,
121 .remove
= ehea_remove
,
124 void ehea_dump(void *adr
, int len
, char *msg
) {
126 unsigned char *deb
= adr
;
127 for (x
= 0; x
< len
; x
+= 16) {
128 printk(DRV_NAME
" %s adr=%p ofs=%04x %016lx %016lx\n", msg
,
129 deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
134 static struct net_device_stats
*ehea_get_stats(struct net_device
*dev
)
136 struct ehea_port
*port
= netdev_priv(dev
);
137 struct net_device_stats
*stats
= &port
->stats
;
138 struct hcp_ehea_port_cb2
*cb2
;
139 u64 hret
, rx_packets
;
142 memset(stats
, 0, sizeof(*stats
));
144 cb2
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
146 ehea_error("no mem for cb2");
150 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
151 port
->logical_port_id
,
152 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
153 if (hret
!= H_SUCCESS
) {
154 ehea_error("query_ehea_port failed");
158 if (netif_msg_hw(port
))
159 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
162 for (i
= 0; i
< port
->num_def_qps
; i
++)
163 rx_packets
+= port
->port_res
[i
].rx_packets
;
165 stats
->tx_packets
= cb2
->txucp
+ cb2
->txmcp
+ cb2
->txbcp
;
166 stats
->multicast
= cb2
->rxmcp
;
167 stats
->rx_errors
= cb2
->rxuerr
;
168 stats
->rx_bytes
= cb2
->rxo
;
169 stats
->tx_bytes
= cb2
->txo
;
170 stats
->rx_packets
= rx_packets
;
178 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
180 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
181 struct net_device
*dev
= pr
->port
->netdev
;
182 int max_index_mask
= pr
->rq1_skba
.len
- 1;
183 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
187 pr
->rq1_skba
.os_skbs
= 0;
189 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
190 pr
->rq1_skba
.index
= index
;
191 pr
->rq1_skba
.os_skbs
= fill_wqes
;
195 for (i
= 0; i
< fill_wqes
; i
++) {
196 if (!skb_arr_rq1
[index
]) {
197 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
199 if (!skb_arr_rq1
[index
]) {
200 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
201 ehea_error("%s: no mem for skb/%d wqes filled",
207 index
&= max_index_mask
;
215 ehea_update_rq1a(pr
->qp
, adder
);
218 static int ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
221 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
222 struct net_device
*dev
= pr
->port
->netdev
;
225 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++) {
226 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
227 if (!skb_arr_rq1
[i
]) {
228 ehea_error("%s: no mem for skb/%d wqes filled",
235 ehea_update_rq1a(pr
->qp
, nr_rq1a
);
240 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
241 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
242 int num_wqes
, int wqe_type
, int packet_size
)
244 struct net_device
*dev
= pr
->port
->netdev
;
245 struct ehea_qp
*qp
= pr
->qp
;
246 struct sk_buff
**skb_arr
= q_skba
->arr
;
247 struct ehea_rwqe
*rwqe
;
248 int i
, index
, max_index_mask
, fill_wqes
;
252 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
255 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
256 q_skba
->os_skbs
= fill_wqes
;
260 index
= q_skba
->index
;
261 max_index_mask
= q_skba
->len
- 1;
262 for (i
= 0; i
< fill_wqes
; i
++) {
264 struct sk_buff
*skb
= netdev_alloc_skb(dev
, packet_size
);
266 ehea_error("%s: no mem for skb/%d wqes filled",
267 pr
->port
->netdev
->name
, i
);
268 q_skba
->os_skbs
= fill_wqes
- i
;
272 skb_reserve(skb
, NET_IP_ALIGN
);
274 skb_arr
[index
] = skb
;
275 tmp_addr
= ehea_map_vaddr(skb
->data
);
276 if (tmp_addr
== -1) {
278 q_skba
->os_skbs
= fill_wqes
- i
;
283 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
284 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
285 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
286 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
287 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
288 rwqe
->sg_list
[0].len
= packet_size
;
289 rwqe
->data_segments
= 1;
292 index
&= max_index_mask
;
296 q_skba
->index
= index
;
303 ehea_update_rq2a(pr
->qp
, adder
);
305 ehea_update_rq3a(pr
->qp
, adder
);
311 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
313 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
314 nr_of_wqes
, EHEA_RWQE2_TYPE
,
315 EHEA_RQ2_PKT_SIZE
+ NET_IP_ALIGN
);
319 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
321 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
322 nr_of_wqes
, EHEA_RWQE3_TYPE
,
323 EHEA_MAX_PACKET_SIZE
+ NET_IP_ALIGN
);
326 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
328 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
329 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
331 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
332 (cqe
->header_length
== 0))
337 static inline void ehea_fill_skb(struct net_device
*dev
,
338 struct sk_buff
*skb
, struct ehea_cqe
*cqe
)
340 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
342 skb_put(skb
, length
);
343 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
344 skb
->protocol
= eth_type_trans(skb
, dev
);
347 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
349 struct ehea_cqe
*cqe
)
351 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
361 prefetchw(pref
+ EHEA_CACHE_LINE
);
363 pref
= (skb_array
[x
]->data
);
365 prefetch(pref
+ EHEA_CACHE_LINE
);
366 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
367 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
368 skb
= skb_array
[skb_index
];
369 skb_array
[skb_index
] = NULL
;
373 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
374 int arr_len
, int wqe_index
)
385 prefetchw(pref
+ EHEA_CACHE_LINE
);
387 pref
= (skb_array
[x
]->data
);
389 prefetchw(pref
+ EHEA_CACHE_LINE
);
391 skb
= skb_array
[wqe_index
];
392 skb_array
[wqe_index
] = NULL
;
396 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
397 struct ehea_cqe
*cqe
, int *processed_rq2
,
402 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
403 pr
->p_stats
.err_tcp_cksum
++;
404 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
405 pr
->p_stats
.err_ip_cksum
++;
406 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
407 pr
->p_stats
.err_frame_crc
++;
409 if (netif_msg_rx_err(pr
->port
)) {
410 ehea_error("CQE Error for QP %d", pr
->qp
->init_attr
.qp_nr
);
411 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
416 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
418 } else if (rq
== 3) {
420 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
424 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
425 ehea_error("Critical receive error. Resetting port.");
426 schedule_work(&pr
->port
->reset_task
);
433 static int get_skb_hdr(struct sk_buff
*skb
, void **iphdr
,
434 void **tcph
, u64
*hdr_flags
, void *priv
)
436 struct ehea_cqe
*cqe
= priv
;
440 /* non tcp/udp packets */
441 if (!cqe
->header_length
)
445 skb_reset_network_header(skb
);
447 if (iph
->protocol
!= IPPROTO_TCP
)
450 ip_len
= ip_hdrlen(skb
);
451 skb_set_transport_header(skb
, ip_len
);
452 *tcph
= tcp_hdr(skb
);
454 /* check if ip header and tcp header are complete */
455 if (iph
->tot_len
< ip_len
+ tcp_hdrlen(skb
))
458 *hdr_flags
= LRO_IPV4
| LRO_TCP
;
464 static void ehea_proc_skb(struct ehea_port_res
*pr
, struct ehea_cqe
*cqe
,
467 int vlan_extracted
= (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
472 lro_vlan_hwaccel_receive_skb(&pr
->lro_mgr
, skb
,
477 lro_receive_skb(&pr
->lro_mgr
, skb
, cqe
);
480 vlan_hwaccel_receive_skb(skb
, pr
->port
->vgrp
,
483 netif_receive_skb(skb
);
487 static int ehea_proc_rwqes(struct net_device
*dev
,
488 struct ehea_port_res
*pr
,
491 struct ehea_port
*port
= pr
->port
;
492 struct ehea_qp
*qp
= pr
->qp
;
493 struct ehea_cqe
*cqe
;
495 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
496 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
497 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
498 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
499 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
500 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
501 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
502 int wqe_index
, last_wqe_index
, rq
, port_reset
;
504 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
507 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
508 while ((processed
< budget
) && cqe
) {
512 if (netif_msg_rx_status(port
))
513 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
515 last_wqe_index
= wqe_index
;
517 if (!ehea_check_cqe(cqe
, &rq
)) {
518 if (rq
== 1) { /* LL RQ1 */
519 skb
= get_skb_by_index_ll(skb_arr_rq1
,
522 if (unlikely(!skb
)) {
523 if (netif_msg_rx_err(port
))
524 ehea_error("LL rq1: skb=NULL");
526 skb
= netdev_alloc_skb(dev
,
531 skb_copy_to_linear_data(skb
, ((char*)cqe
) + 64,
532 cqe
->num_bytes_transfered
- 4);
533 ehea_fill_skb(dev
, skb
, cqe
);
534 } else if (rq
== 2) { /* RQ2 */
535 skb
= get_skb_by_index(skb_arr_rq2
,
536 skb_arr_rq2_len
, cqe
);
537 if (unlikely(!skb
)) {
538 if (netif_msg_rx_err(port
))
539 ehea_error("rq2: skb=NULL");
542 ehea_fill_skb(dev
, skb
, cqe
);
545 skb
= get_skb_by_index(skb_arr_rq3
,
546 skb_arr_rq3_len
, cqe
);
547 if (unlikely(!skb
)) {
548 if (netif_msg_rx_err(port
))
549 ehea_error("rq3: skb=NULL");
552 ehea_fill_skb(dev
, skb
, cqe
);
556 ehea_proc_skb(pr
, cqe
, skb
);
557 dev
->last_rx
= jiffies
;
559 pr
->p_stats
.poll_receive_errors
++;
560 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
566 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
569 lro_flush_all(&pr
->lro_mgr
);
571 pr
->rx_packets
+= processed
;
573 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
574 ehea_refill_rq2(pr
, processed_rq2
);
575 ehea_refill_rq3(pr
, processed_rq3
);
580 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
583 struct ehea_cq
*send_cq
= pr
->send_cq
;
584 struct ehea_cqe
*cqe
;
585 int quota
= my_quota
;
591 cqe
= ehea_poll_cq(send_cq
);
592 while(cqe
&& (quota
> 0)) {
593 ehea_inc_cq(send_cq
);
597 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
598 ehea_error("Send Completion Error: Resetting port");
599 if (netif_msg_tx_err(pr
->port
))
600 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
601 schedule_work(&pr
->port
->reset_task
);
605 if (netif_msg_tx_done(pr
->port
))
606 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
608 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
609 == EHEA_SWQE2_TYPE
)) {
611 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
612 skb
= pr
->sq_skba
.arr
[index
];
614 pr
->sq_skba
.arr
[index
] = NULL
;
617 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
620 cqe
= ehea_poll_cq(send_cq
);
623 ehea_update_feca(send_cq
, cqe_counter
);
624 atomic_add(swqe_av
, &pr
->swqe_avail
);
626 spin_lock_irqsave(&pr
->netif_queue
, flags
);
628 if (pr
->queue_stopped
&& (atomic_read(&pr
->swqe_avail
)
629 >= pr
->swqe_refill_th
)) {
630 netif_wake_queue(pr
->port
->netdev
);
631 pr
->queue_stopped
= 0;
633 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
638 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
639 #define EHEA_POLL_MAX_CQES 65535
641 static int ehea_poll(struct napi_struct
*napi
, int budget
)
643 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
, napi
);
644 struct net_device
*dev
= pr
->port
->netdev
;
645 struct ehea_cqe
*cqe
;
646 struct ehea_cqe
*cqe_skb
= NULL
;
647 int force_irq
, wqe_index
;
650 force_irq
= (pr
->poll_counter
> EHEA_NAPI_POLL_NUM_BEFORE_IRQ
);
651 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
654 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
656 while ((rx
!= budget
) || force_irq
) {
657 pr
->poll_counter
= 0;
659 netif_rx_complete(dev
, napi
);
660 ehea_reset_cq_ep(pr
->recv_cq
);
661 ehea_reset_cq_ep(pr
->send_cq
);
662 ehea_reset_cq_n1(pr
->recv_cq
);
663 ehea_reset_cq_n1(pr
->send_cq
);
664 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
665 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
667 if (!cqe
&& !cqe_skb
)
670 if (!netif_rx_reschedule(dev
, napi
))
673 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
674 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
681 #ifdef CONFIG_NET_POLL_CONTROLLER
682 static void ehea_netpoll(struct net_device
*dev
)
684 struct ehea_port
*port
= netdev_priv(dev
);
687 for (i
= 0; i
< port
->num_def_qps
; i
++)
688 netif_rx_schedule(dev
, &port
->port_res
[i
].napi
);
692 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
694 struct ehea_port_res
*pr
= param
;
696 netif_rx_schedule(pr
->port
->netdev
, &pr
->napi
);
701 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
703 struct ehea_port
*port
= param
;
704 struct ehea_eqe
*eqe
;
708 eqe
= ehea_poll_eq(port
->qp_eq
);
711 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
712 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
713 eqe
->entry
, qp_token
);
715 qp
= port
->port_res
[qp_token
].qp
;
716 ehea_error_data(port
->adapter
, qp
->fw_handle
);
717 eqe
= ehea_poll_eq(port
->qp_eq
);
720 schedule_work(&port
->reset_task
);
725 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
730 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
731 if (adapter
->port
[i
])
732 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
733 return adapter
->port
[i
];
737 int ehea_sense_port_attr(struct ehea_port
*port
)
741 struct hcp_ehea_port_cb0
*cb0
;
743 cb0
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
); /* May be called via */
744 if (!cb0
) { /* ehea_neq_tasklet() */
745 ehea_error("no mem for cb0");
750 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
751 port
->logical_port_id
, H_PORT_CB0
,
752 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
754 if (hret
!= H_SUCCESS
) {
760 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
762 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
763 ret
= -EADDRNOTAVAIL
;
768 switch (cb0
->port_speed
) {
770 port
->port_speed
= EHEA_SPEED_10M
;
771 port
->full_duplex
= 0;
774 port
->port_speed
= EHEA_SPEED_10M
;
775 port
->full_duplex
= 1;
778 port
->port_speed
= EHEA_SPEED_100M
;
779 port
->full_duplex
= 0;
782 port
->port_speed
= EHEA_SPEED_100M
;
783 port
->full_duplex
= 1;
786 port
->port_speed
= EHEA_SPEED_1G
;
787 port
->full_duplex
= 1;
790 port
->port_speed
= EHEA_SPEED_10G
;
791 port
->full_duplex
= 1;
794 port
->port_speed
= 0;
795 port
->full_duplex
= 0;
800 port
->num_mcs
= cb0
->num_default_qps
;
802 /* Number of default QPs */
804 port
->num_def_qps
= cb0
->num_default_qps
;
806 port
->num_def_qps
= 1;
808 if (!port
->num_def_qps
) {
813 port
->num_tx_qps
= num_tx_qps
;
815 if (port
->num_def_qps
>= port
->num_tx_qps
)
816 port
->num_add_tx_qps
= 0;
818 port
->num_add_tx_qps
= port
->num_tx_qps
- port
->num_def_qps
;
822 if (ret
|| netif_msg_probe(port
))
823 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
829 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
831 struct hcp_ehea_port_cb4
*cb4
;
835 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
837 ehea_error("no mem for cb4");
842 cb4
->port_speed
= port_speed
;
844 netif_carrier_off(port
->netdev
);
846 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
847 port
->logical_port_id
,
848 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
849 if (hret
== H_SUCCESS
) {
850 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
852 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
853 port
->logical_port_id
,
854 H_PORT_CB4
, H_PORT_CB4_SPEED
,
856 if (hret
== H_SUCCESS
) {
857 switch (cb4
->port_speed
) {
859 port
->port_speed
= EHEA_SPEED_10M
;
860 port
->full_duplex
= 0;
863 port
->port_speed
= EHEA_SPEED_10M
;
864 port
->full_duplex
= 1;
867 port
->port_speed
= EHEA_SPEED_100M
;
868 port
->full_duplex
= 0;
871 port
->port_speed
= EHEA_SPEED_100M
;
872 port
->full_duplex
= 1;
875 port
->port_speed
= EHEA_SPEED_1G
;
876 port
->full_duplex
= 1;
879 port
->port_speed
= EHEA_SPEED_10G
;
880 port
->full_duplex
= 1;
883 port
->port_speed
= 0;
884 port
->full_duplex
= 0;
888 ehea_error("Failed sensing port speed");
892 if (hret
== H_AUTHORITY
) {
893 ehea_info("Hypervisor denied setting port speed");
897 ehea_error("Failed setting port speed");
900 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
901 netif_carrier_on(port
->netdev
);
908 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
913 struct ehea_port
*port
;
915 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
916 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
917 port
= ehea_get_port(adapter
, portnum
);
920 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
923 ehea_error("unknown portnum %x", portnum
);
927 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
928 if (!netif_carrier_ok(port
->netdev
)) {
929 ret
= ehea_sense_port_attr(port
);
931 ehea_error("failed resensing port "
936 if (netif_msg_link(port
))
937 ehea_info("%s: Logical port up: %dMbps "
942 1 ? "Full" : "Half");
944 netif_carrier_on(port
->netdev
);
945 netif_wake_queue(port
->netdev
);
948 if (netif_carrier_ok(port
->netdev
)) {
949 if (netif_msg_link(port
))
950 ehea_info("%s: Logical port down",
952 netif_carrier_off(port
->netdev
);
953 netif_stop_queue(port
->netdev
);
956 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
957 port
->phy_link
= EHEA_PHY_LINK_UP
;
958 if (netif_msg_link(port
))
959 ehea_info("%s: Physical port up",
961 if (prop_carrier_state
)
962 netif_carrier_on(port
->netdev
);
964 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
965 if (netif_msg_link(port
))
966 ehea_info("%s: Physical port down",
968 if (prop_carrier_state
)
969 netif_carrier_off(port
->netdev
);
972 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
973 ehea_info("External switch port is primary port");
975 ehea_info("External switch port is backup port");
978 case EHEA_EC_ADAPTER_MALFUNC
:
979 ehea_error("Adapter malfunction");
981 case EHEA_EC_PORT_MALFUNC
:
982 ehea_info("Port malfunction: Device: %s", port
->netdev
->name
);
983 netif_carrier_off(port
->netdev
);
984 netif_stop_queue(port
->netdev
);
987 ehea_error("unknown event code %x, eqe=0x%lX", ec
, eqe
);
992 static void ehea_neq_tasklet(unsigned long data
)
994 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
995 struct ehea_eqe
*eqe
;
998 eqe
= ehea_poll_eq(adapter
->neq
);
999 ehea_debug("eqe=%p", eqe
);
1002 ehea_debug("*eqe=%lx", eqe
->entry
);
1003 ehea_parse_eqe(adapter
, eqe
->entry
);
1004 eqe
= ehea_poll_eq(adapter
->neq
);
1005 ehea_debug("next eqe=%p", eqe
);
1008 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1009 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1010 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1012 ehea_h_reset_events(adapter
->handle
,
1013 adapter
->neq
->fw_handle
, event_mask
);
1016 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1018 struct ehea_adapter
*adapter
= param
;
1019 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1024 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1027 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1029 ret
= ehea_init_fill_rq1(pr
, init_attr
->act_nr_rwqes_rq1
1030 - init_attr
->act_nr_rwqes_rq2
1031 - init_attr
->act_nr_rwqes_rq3
- 1);
1033 ret
|= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1035 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1040 static int ehea_reg_interrupts(struct net_device
*dev
)
1042 struct ehea_port
*port
= netdev_priv(dev
);
1043 struct ehea_port_res
*pr
;
1047 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1050 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1051 ehea_qp_aff_irq_handler
,
1052 IRQF_DISABLED
, port
->int_aff_name
, port
);
1054 ehea_error("failed registering irq for qp_aff_irq_handler:"
1055 "ist=%X", port
->qp_eq
->attr
.ist1
);
1059 if (netif_msg_ifup(port
))
1060 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1061 "registered", port
->qp_eq
->attr
.ist1
);
1064 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1065 pr
= &port
->port_res
[i
];
1066 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1067 "%s-queue%d", dev
->name
, i
);
1068 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1069 ehea_recv_irq_handler
,
1070 IRQF_DISABLED
, pr
->int_send_name
,
1073 ehea_error("failed registering irq for ehea_queue "
1074 "port_res_nr:%d, ist=%X", i
,
1078 if (netif_msg_ifup(port
))
1079 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1080 "%d registered", pr
->eq
->attr
.ist1
, i
);
1088 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1089 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1093 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1094 i
= port
->num_def_qps
;
1100 static void ehea_free_interrupts(struct net_device
*dev
)
1102 struct ehea_port
*port
= netdev_priv(dev
);
1103 struct ehea_port_res
*pr
;
1108 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1109 pr
= &port
->port_res
[i
];
1110 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1111 if (netif_msg_intr(port
))
1112 ehea_info("free send irq for res %d with handle 0x%X",
1113 i
, pr
->eq
->attr
.ist1
);
1116 /* associated events */
1117 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1118 if (netif_msg_intr(port
))
1119 ehea_info("associated event interrupt for handle 0x%X freed",
1120 port
->qp_eq
->attr
.ist1
);
1123 static int ehea_configure_port(struct ehea_port
*port
)
1127 struct hcp_ehea_port_cb0
*cb0
;
1130 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1134 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1135 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1136 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1137 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1138 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1139 PXLY_RC_VLAN_FILTER
)
1140 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1142 for (i
= 0; i
< port
->num_mcs
; i
++)
1144 cb0
->default_qpn_arr
[i
] =
1145 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1147 cb0
->default_qpn_arr
[i
] =
1148 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1150 if (netif_msg_ifup(port
))
1151 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1153 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1154 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1156 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1157 port
->logical_port_id
,
1158 H_PORT_CB0
, mask
, cb0
);
1160 if (hret
!= H_SUCCESS
)
1171 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1174 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1176 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1180 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1187 ehea_rem_mr(&pr
->send_mr
);
1189 ehea_error("Generating SMRS failed\n");
1193 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1195 if ((ehea_rem_mr(&pr
->send_mr
))
1196 || (ehea_rem_mr(&pr
->recv_mr
)))
1202 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1204 int arr_size
= sizeof(void*) * max_q_entries
;
1206 q_skba
->arr
= vmalloc(arr_size
);
1210 memset(q_skba
->arr
, 0, arr_size
);
1212 q_skba
->len
= max_q_entries
;
1214 q_skba
->os_skbs
= 0;
1219 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1220 struct port_res_cfg
*pr_cfg
, int queue_token
)
1222 struct ehea_adapter
*adapter
= port
->adapter
;
1223 enum ehea_eq_type eq_type
= EHEA_EQ
;
1224 struct ehea_qp_init_attr
*init_attr
= NULL
;
1227 memset(pr
, 0, sizeof(struct ehea_port_res
));
1230 spin_lock_init(&pr
->xmit_lock
);
1231 spin_lock_init(&pr
->netif_queue
);
1233 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1235 ehea_error("create_eq failed (eq)");
1239 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1241 port
->logical_port_id
);
1243 ehea_error("create_cq failed (cq_recv)");
1247 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1249 port
->logical_port_id
);
1251 ehea_error("create_cq failed (cq_send)");
1255 if (netif_msg_ifup(port
))
1256 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1257 pr
->send_cq
->attr
.act_nr_of_cqes
,
1258 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1260 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1263 ehea_error("no mem for ehea_qp_init_attr");
1267 init_attr
->low_lat_rq1
= 1;
1268 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1269 init_attr
->rq_count
= 3;
1270 init_attr
->qp_token
= queue_token
;
1271 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1272 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1273 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1274 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1275 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1276 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1277 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1278 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1279 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1280 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1281 init_attr
->port_nr
= port
->logical_port_id
;
1282 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1283 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1284 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1286 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1288 ehea_error("create_qp failed");
1293 if (netif_msg_ifup(port
))
1294 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1295 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr
->qp_nr
,
1296 init_attr
->act_nr_send_wqes
,
1297 init_attr
->act_nr_rwqes_rq1
,
1298 init_attr
->act_nr_rwqes_rq2
,
1299 init_attr
->act_nr_rwqes_rq3
);
1301 ret
= ehea_init_q_skba(&pr
->sq_skba
, init_attr
->act_nr_send_wqes
+ 1);
1302 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1303 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1304 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1308 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1309 if (ehea_gen_smrs(pr
) != 0) {
1314 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1318 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1320 pr
->lro_mgr
.max_aggr
= pr
->port
->lro_max_aggr
;
1321 pr
->lro_mgr
.max_desc
= MAX_LRO_DESCRIPTORS
;
1322 pr
->lro_mgr
.lro_arr
= pr
->lro_desc
;
1323 pr
->lro_mgr
.get_skb_header
= get_skb_hdr
;
1324 pr
->lro_mgr
.features
= LRO_F_NAPI
| LRO_F_EXTRACT_VLAN_ID
;
1325 pr
->lro_mgr
.dev
= port
->netdev
;
1326 pr
->lro_mgr
.ip_summed
= CHECKSUM_UNNECESSARY
;
1327 pr
->lro_mgr
.ip_summed_aggr
= CHECKSUM_UNNECESSARY
;
1334 vfree(pr
->sq_skba
.arr
);
1335 vfree(pr
->rq1_skba
.arr
);
1336 vfree(pr
->rq2_skba
.arr
);
1337 vfree(pr
->rq3_skba
.arr
);
1338 ehea_destroy_qp(pr
->qp
);
1339 ehea_destroy_cq(pr
->send_cq
);
1340 ehea_destroy_cq(pr
->recv_cq
);
1341 ehea_destroy_eq(pr
->eq
);
1346 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1350 ret
= ehea_destroy_qp(pr
->qp
);
1353 ehea_destroy_cq(pr
->send_cq
);
1354 ehea_destroy_cq(pr
->recv_cq
);
1355 ehea_destroy_eq(pr
->eq
);
1357 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1358 if (pr
->rq1_skba
.arr
[i
])
1359 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1361 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1362 if (pr
->rq2_skba
.arr
[i
])
1363 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1365 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1366 if (pr
->rq3_skba
.arr
[i
])
1367 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1369 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1370 if (pr
->sq_skba
.arr
[i
])
1371 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1373 vfree(pr
->rq1_skba
.arr
);
1374 vfree(pr
->rq2_skba
.arr
);
1375 vfree(pr
->rq3_skba
.arr
);
1376 vfree(pr
->sq_skba
.arr
);
1377 ret
= ehea_rem_smrs(pr
);
1383 * The write_* functions store information in swqe which is used by
1384 * the hardware to calculate the ip/tcp/udp checksum
1387 static inline void write_ip_start_end(struct ehea_swqe
*swqe
,
1388 const struct sk_buff
*skb
)
1390 swqe
->ip_start
= skb_network_offset(skb
);
1391 swqe
->ip_end
= (u8
)(swqe
->ip_start
+ ip_hdrlen(skb
) - 1);
1394 static inline void write_tcp_offset_end(struct ehea_swqe
*swqe
,
1395 const struct sk_buff
*skb
)
1398 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct tcphdr
, check
));
1400 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1403 static inline void write_udp_offset_end(struct ehea_swqe
*swqe
,
1404 const struct sk_buff
*skb
)
1407 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct udphdr
, check
));
1409 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1413 static void write_swqe2_TSO(struct sk_buff
*skb
,
1414 struct ehea_swqe
*swqe
, u32 lkey
)
1416 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1417 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1418 int skb_data_size
= skb
->len
- skb
->data_len
;
1421 /* Packet is TCP with TSO enabled */
1422 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1423 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1424 /* copy only eth/ip/tcp headers to immediate data and
1425 * the rest of skb->data to sg1entry
1427 headersize
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1429 skb_data_size
= skb
->len
- skb
->data_len
;
1431 if (skb_data_size
>= headersize
) {
1432 /* copy immediate data */
1433 skb_copy_from_linear_data(skb
, imm_data
, headersize
);
1434 swqe
->immediate_data_length
= headersize
;
1436 if (skb_data_size
> headersize
) {
1437 /* set sg1entry data */
1438 sg1entry
->l_key
= lkey
;
1439 sg1entry
->len
= skb_data_size
- headersize
;
1441 ehea_map_vaddr(skb
->data
+ headersize
);
1442 swqe
->descriptors
++;
1445 ehea_error("cannot handle fragmented headers");
1448 static void write_swqe2_nonTSO(struct sk_buff
*skb
,
1449 struct ehea_swqe
*swqe
, u32 lkey
)
1451 int skb_data_size
= skb
->len
- skb
->data_len
;
1452 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1453 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1455 /* Packet is any nonTSO type
1457 * Copy as much as possible skb->data to immediate data and
1458 * the rest to sg1entry
1460 if (skb_data_size
>= SWQE2_MAX_IMM
) {
1461 /* copy immediate data */
1462 skb_copy_from_linear_data(skb
, imm_data
, SWQE2_MAX_IMM
);
1464 swqe
->immediate_data_length
= SWQE2_MAX_IMM
;
1466 if (skb_data_size
> SWQE2_MAX_IMM
) {
1467 /* copy sg1entry data */
1468 sg1entry
->l_key
= lkey
;
1469 sg1entry
->len
= skb_data_size
- SWQE2_MAX_IMM
;
1471 ehea_map_vaddr(skb
->data
+ SWQE2_MAX_IMM
);
1472 swqe
->descriptors
++;
1475 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1476 swqe
->immediate_data_length
= skb_data_size
;
1480 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1481 struct ehea_swqe
*swqe
, u32 lkey
)
1483 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1485 int nfrags
, sg1entry_contains_frag_data
, i
;
1487 nfrags
= skb_shinfo(skb
)->nr_frags
;
1488 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1489 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1490 swqe
->descriptors
= 0;
1491 sg1entry_contains_frag_data
= 0;
1493 if ((dev
->features
& NETIF_F_TSO
) && skb_shinfo(skb
)->gso_size
)
1494 write_swqe2_TSO(skb
, swqe
, lkey
);
1496 write_swqe2_nonTSO(skb
, swqe
, lkey
);
1498 /* write descriptors */
1500 if (swqe
->descriptors
== 0) {
1501 /* sg1entry not yet used */
1502 frag
= &skb_shinfo(skb
)->frags
[0];
1504 /* copy sg1entry data */
1505 sg1entry
->l_key
= lkey
;
1506 sg1entry
->len
= frag
->size
;
1508 ehea_map_vaddr(page_address(frag
->page
)
1509 + frag
->page_offset
);
1510 swqe
->descriptors
++;
1511 sg1entry_contains_frag_data
= 1;
1514 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1516 frag
= &skb_shinfo(skb
)->frags
[i
];
1517 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1519 sgentry
->l_key
= lkey
;
1520 sgentry
->len
= frag
->size
;
1522 ehea_map_vaddr(page_address(frag
->page
)
1523 + frag
->page_offset
);
1524 swqe
->descriptors
++;
1529 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1535 /* De/Register untagged packets */
1536 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1537 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1538 port
->logical_port_id
,
1539 reg_type
, port
->mac_addr
, 0, hcallid
);
1540 if (hret
!= H_SUCCESS
) {
1541 ehea_error("%sregistering bc address failed (tagged)",
1542 hcallid
== H_REG_BCMC
? "" : "de");
1547 /* De/Register VLAN packets */
1548 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1549 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1550 port
->logical_port_id
,
1551 reg_type
, port
->mac_addr
, 0, hcallid
);
1552 if (hret
!= H_SUCCESS
) {
1553 ehea_error("%sregistering bc address failed (vlan)",
1554 hcallid
== H_REG_BCMC
? "" : "de");
1561 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1563 struct ehea_port
*port
= netdev_priv(dev
);
1564 struct sockaddr
*mac_addr
= sa
;
1565 struct hcp_ehea_port_cb0
*cb0
;
1569 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1570 ret
= -EADDRNOTAVAIL
;
1574 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1576 ehea_error("no mem for cb0");
1581 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1583 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1585 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1586 port
->logical_port_id
, H_PORT_CB0
,
1587 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1588 if (hret
!= H_SUCCESS
) {
1593 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1595 /* Deregister old MAC in pHYP */
1596 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1600 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1602 /* Register new MAC in pHYP */
1603 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1614 static void ehea_promiscuous_error(u64 hret
, int enable
)
1616 if (hret
== H_AUTHORITY
)
1617 ehea_info("Hypervisor denied %sabling promiscuous mode",
1618 enable
== 1 ? "en" : "dis");
1620 ehea_error("failed %sabling promiscuous mode",
1621 enable
== 1 ? "en" : "dis");
1624 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1626 struct ehea_port
*port
= netdev_priv(dev
);
1627 struct hcp_ehea_port_cb7
*cb7
;
1630 if ((enable
&& port
->promisc
) || (!enable
&& !port
->promisc
))
1633 cb7
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
);
1635 ehea_error("no mem for cb7");
1639 /* Modify Pxs_DUCQPN in CB7 */
1640 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1642 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1643 port
->logical_port_id
,
1644 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1646 ehea_promiscuous_error(hret
, enable
);
1650 port
->promisc
= enable
;
1656 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1662 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1663 | EHEA_BCMC_UNTAGGED
;
1665 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1666 port
->logical_port_id
,
1667 reg_type
, mc_mac_addr
, 0, hcallid
);
1671 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1672 | EHEA_BCMC_VLANID_ALL
;
1674 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1675 port
->logical_port_id
,
1676 reg_type
, mc_mac_addr
, 0, hcallid
);
1681 static int ehea_drop_multicast_list(struct net_device
*dev
)
1683 struct ehea_port
*port
= netdev_priv(dev
);
1684 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1685 struct list_head
*pos
;
1686 struct list_head
*temp
;
1690 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1691 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1693 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1696 ehea_error("failed deregistering mcast MAC");
1706 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1708 struct ehea_port
*port
= netdev_priv(dev
);
1711 if (!port
->allmulti
) {
1713 /* Enable ALLMULTI */
1714 ehea_drop_multicast_list(dev
);
1715 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1719 ehea_error("failed enabling IFF_ALLMULTI");
1723 /* Disable ALLMULTI */
1724 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1728 ehea_error("failed disabling IFF_ALLMULTI");
1732 static void ehea_add_multicast_entry(struct ehea_port
* port
, u8
* mc_mac_addr
)
1734 struct ehea_mc_list
*ehea_mcl_entry
;
1737 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1738 if (!ehea_mcl_entry
) {
1739 ehea_error("no mem for mcl_entry");
1743 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1745 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1747 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1750 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1752 ehea_error("failed registering mcast MAC");
1753 kfree(ehea_mcl_entry
);
1757 static void ehea_set_multicast_list(struct net_device
*dev
)
1759 struct ehea_port
*port
= netdev_priv(dev
);
1760 struct dev_mc_list
*k_mcl_entry
;
1763 if (dev
->flags
& IFF_PROMISC
) {
1764 ehea_promiscuous(dev
, 1);
1767 ehea_promiscuous(dev
, 0);
1769 if (dev
->flags
& IFF_ALLMULTI
) {
1770 ehea_allmulti(dev
, 1);
1773 ehea_allmulti(dev
, 0);
1775 if (dev
->mc_count
) {
1776 ret
= ehea_drop_multicast_list(dev
);
1778 /* Dropping the current multicast list failed.
1779 * Enabling ALL_MULTI is the best we can do.
1781 ehea_allmulti(dev
, 1);
1784 if (dev
->mc_count
> port
->adapter
->max_mc_mac
) {
1785 ehea_info("Mcast registration limit reached (0x%lx). "
1787 port
->adapter
->max_mc_mac
);
1791 for (i
= 0, k_mcl_entry
= dev
->mc_list
;
1793 i
++, k_mcl_entry
= k_mcl_entry
->next
) {
1794 ehea_add_multicast_entry(port
, k_mcl_entry
->dmi_addr
);
1801 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1803 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1809 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
1810 struct ehea_swqe
*swqe
, u32 lkey
)
1812 if (skb
->protocol
== htons(ETH_P_IP
)) {
1813 const struct iphdr
*iph
= ip_hdr(skb
);
1816 swqe
->tx_control
|= EHEA_SWQE_CRC
1817 | EHEA_SWQE_IP_CHECKSUM
1818 | EHEA_SWQE_TCP_CHECKSUM
1819 | EHEA_SWQE_IMM_DATA_PRESENT
1820 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
1822 write_ip_start_end(swqe
, skb
);
1824 if (iph
->protocol
== IPPROTO_UDP
) {
1825 if ((iph
->frag_off
& IP_MF
)
1826 || (iph
->frag_off
& IP_OFFSET
))
1827 /* IP fragment, so don't change cs */
1828 swqe
->tx_control
&= ~EHEA_SWQE_TCP_CHECKSUM
;
1830 write_udp_offset_end(swqe
, skb
);
1831 } else if (iph
->protocol
== IPPROTO_TCP
) {
1832 write_tcp_offset_end(swqe
, skb
);
1835 /* icmp (big data) and ip segmentation packets (all other ip
1836 packets) do not require any special handling */
1839 /* Other Ethernet Protocol */
1840 swqe
->tx_control
|= EHEA_SWQE_CRC
1841 | EHEA_SWQE_IMM_DATA_PRESENT
1842 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
1845 write_swqe2_data(skb
, dev
, swqe
, lkey
);
1848 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
1849 struct ehea_swqe
*swqe
)
1851 int nfrags
= skb_shinfo(skb
)->nr_frags
;
1852 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
1856 if (skb
->protocol
== htons(ETH_P_IP
)) {
1857 const struct iphdr
*iph
= ip_hdr(skb
);
1860 write_ip_start_end(swqe
, skb
);
1862 if (iph
->protocol
== IPPROTO_TCP
) {
1863 swqe
->tx_control
|= EHEA_SWQE_CRC
1864 | EHEA_SWQE_IP_CHECKSUM
1865 | EHEA_SWQE_TCP_CHECKSUM
1866 | EHEA_SWQE_IMM_DATA_PRESENT
;
1868 write_tcp_offset_end(swqe
, skb
);
1870 } else if (iph
->protocol
== IPPROTO_UDP
) {
1871 if ((iph
->frag_off
& IP_MF
)
1872 || (iph
->frag_off
& IP_OFFSET
))
1873 /* IP fragment, so don't change cs */
1874 swqe
->tx_control
|= EHEA_SWQE_CRC
1875 | EHEA_SWQE_IMM_DATA_PRESENT
;
1877 swqe
->tx_control
|= EHEA_SWQE_CRC
1878 | EHEA_SWQE_IP_CHECKSUM
1879 | EHEA_SWQE_TCP_CHECKSUM
1880 | EHEA_SWQE_IMM_DATA_PRESENT
;
1882 write_udp_offset_end(swqe
, skb
);
1885 /* icmp (big data) and
1886 ip segmentation packets (all other ip packets) */
1887 swqe
->tx_control
|= EHEA_SWQE_CRC
1888 | EHEA_SWQE_IP_CHECKSUM
1889 | EHEA_SWQE_IMM_DATA_PRESENT
;
1892 /* Other Ethernet Protocol */
1893 swqe
->tx_control
|= EHEA_SWQE_CRC
| EHEA_SWQE_IMM_DATA_PRESENT
;
1895 /* copy (immediate) data */
1897 /* data is in a single piece */
1898 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
1900 /* first copy data from the skb->data buffer ... */
1901 skb_copy_from_linear_data(skb
, imm_data
,
1902 skb
->len
- skb
->data_len
);
1903 imm_data
+= skb
->len
- skb
->data_len
;
1905 /* ... then copy data from the fragments */
1906 for (i
= 0; i
< nfrags
; i
++) {
1907 frag
= &skb_shinfo(skb
)->frags
[i
];
1909 page_address(frag
->page
) + frag
->page_offset
,
1911 imm_data
+= frag
->size
;
1914 swqe
->immediate_data_length
= skb
->len
;
1918 static inline int ehea_hash_skb(struct sk_buff
*skb
, int num_qps
)
1923 if ((skb
->protocol
== htons(ETH_P_IP
)) &&
1924 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)) {
1925 tcp
= (struct tcphdr
*)(skb_network_header(skb
) + (ip_hdr(skb
)->ihl
* 4));
1926 tmp
= (tcp
->source
+ (tcp
->dest
<< 16)) % 31;
1927 tmp
+= ip_hdr(skb
)->daddr
% 31;
1928 return tmp
% num_qps
;
1934 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1936 struct ehea_port
*port
= netdev_priv(dev
);
1937 struct ehea_swqe
*swqe
;
1938 unsigned long flags
;
1941 struct ehea_port_res
*pr
;
1943 pr
= &port
->port_res
[ehea_hash_skb(skb
, port
->num_tx_qps
)];
1945 if (!spin_trylock(&pr
->xmit_lock
))
1946 return NETDEV_TX_BUSY
;
1948 if (pr
->queue_stopped
) {
1949 spin_unlock(&pr
->xmit_lock
);
1950 return NETDEV_TX_BUSY
;
1953 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
1954 memset(swqe
, 0, SWQE_HEADER_SIZE
);
1955 atomic_dec(&pr
->swqe_avail
);
1957 if (skb
->len
<= SWQE3_MAX_IMM
) {
1958 u32 sig_iv
= port
->sig_comp_iv
;
1959 u32 swqe_num
= pr
->swqe_id_counter
;
1960 ehea_xmit3(skb
, dev
, swqe
);
1961 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
1962 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
1963 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
1964 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
1966 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
1967 pr
->swqe_ll_count
= 0;
1969 pr
->swqe_ll_count
+= 1;
1972 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
1973 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
1974 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
1975 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
1976 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
1978 pr
->sq_skba
.index
++;
1979 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
1981 lkey
= pr
->send_mr
.lkey
;
1982 ehea_xmit2(skb
, dev
, swqe
, lkey
);
1983 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
1985 pr
->swqe_id_counter
+= 1;
1987 if (port
->vgrp
&& vlan_tx_tag_present(skb
)) {
1988 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
1989 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
1992 if (netif_msg_tx_queued(port
)) {
1993 ehea_info("post swqe on QP %d", pr
->qp
->init_attr
.qp_nr
);
1994 ehea_dump(swqe
, 512, "swqe");
1997 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
1998 netif_stop_queue(dev
);
1999 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2002 ehea_post_swqe(pr
->qp
, swqe
);
2004 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2005 spin_lock_irqsave(&pr
->netif_queue
, flags
);
2006 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2007 pr
->p_stats
.queue_stopped
++;
2008 netif_stop_queue(dev
);
2009 pr
->queue_stopped
= 1;
2011 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
2013 dev
->trans_start
= jiffies
;
2014 spin_unlock(&pr
->xmit_lock
);
2016 return NETDEV_TX_OK
;
2019 static void ehea_vlan_rx_register(struct net_device
*dev
,
2020 struct vlan_group
*grp
)
2022 struct ehea_port
*port
= netdev_priv(dev
);
2023 struct ehea_adapter
*adapter
= port
->adapter
;
2024 struct hcp_ehea_port_cb1
*cb1
;
2029 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2031 ehea_error("no mem for cb1");
2035 memset(cb1
->vlan_filter
, 0, sizeof(cb1
->vlan_filter
));
2037 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2038 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2039 if (hret
!= H_SUCCESS
)
2040 ehea_error("modify_ehea_port failed");
2047 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2049 struct ehea_port
*port
= netdev_priv(dev
);
2050 struct ehea_adapter
*adapter
= port
->adapter
;
2051 struct hcp_ehea_port_cb1
*cb1
;
2055 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2057 ehea_error("no mem for cb1");
2061 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2062 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2063 if (hret
!= H_SUCCESS
) {
2064 ehea_error("query_ehea_port failed");
2069 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2071 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2072 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2073 if (hret
!= H_SUCCESS
)
2074 ehea_error("modify_ehea_port failed");
2080 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2082 struct ehea_port
*port
= netdev_priv(dev
);
2083 struct ehea_adapter
*adapter
= port
->adapter
;
2084 struct hcp_ehea_port_cb1
*cb1
;
2088 vlan_group_set_device(port
->vgrp
, vid
, NULL
);
2090 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2092 ehea_error("no mem for cb1");
2096 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2097 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2098 if (hret
!= H_SUCCESS
) {
2099 ehea_error("query_ehea_port failed");
2104 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2106 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2107 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2108 if (hret
!= H_SUCCESS
)
2109 ehea_error("modify_ehea_port failed");
2115 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2121 struct hcp_modify_qp_cb0
* cb0
;
2123 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2129 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2130 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2131 if (hret
!= H_SUCCESS
) {
2132 ehea_error("query_ehea_qp failed (1)");
2136 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2137 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2138 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2139 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2140 if (hret
!= H_SUCCESS
) {
2141 ehea_error("modify_ehea_qp failed (1)");
2145 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2146 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2147 if (hret
!= H_SUCCESS
) {
2148 ehea_error("query_ehea_qp failed (2)");
2152 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2153 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2154 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2155 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2156 if (hret
!= H_SUCCESS
) {
2157 ehea_error("modify_ehea_qp failed (2)");
2161 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2162 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2163 if (hret
!= H_SUCCESS
) {
2164 ehea_error("query_ehea_qp failed (3)");
2168 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2169 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2170 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2171 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2172 if (hret
!= H_SUCCESS
) {
2173 ehea_error("modify_ehea_qp failed (3)");
2177 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2178 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2179 if (hret
!= H_SUCCESS
) {
2180 ehea_error("query_ehea_qp failed (4)");
2190 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
,
2194 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2195 enum ehea_eq_type eq_type
= EHEA_EQ
;
2197 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2198 EHEA_MAX_ENTRIES_EQ
, 1);
2201 ehea_error("ehea_create_eq failed (qp_eq)");
2205 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2206 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2207 pr_cfg
.max_entries_sq
= sq_entries
;
2208 pr_cfg
.max_entries_rq1
= rq1_entries
;
2209 pr_cfg
.max_entries_rq2
= rq2_entries
;
2210 pr_cfg
.max_entries_rq3
= rq3_entries
;
2212 pr_cfg_small_rx
.max_entries_rcq
= 1;
2213 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2214 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2215 pr_cfg_small_rx
.max_entries_rq1
= 1;
2216 pr_cfg_small_rx
.max_entries_rq2
= 1;
2217 pr_cfg_small_rx
.max_entries_rq3
= 1;
2219 for (i
= 0; i
< def_qps
; i
++) {
2220 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2224 for (i
= def_qps
; i
< def_qps
+ add_tx_qps
; i
++) {
2225 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2226 &pr_cfg_small_rx
, i
);
2235 ehea_clean_portres(port
, &port
->port_res
[i
]);
2238 ehea_destroy_eq(port
->qp_eq
);
2242 static int ehea_clean_all_portres(struct ehea_port
*port
)
2247 for(i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2248 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2250 ret
|= ehea_destroy_eq(port
->qp_eq
);
2255 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2257 if (adapter
->active_ports
)
2260 ehea_rem_mr(&adapter
->mr
);
2263 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2265 if (adapter
->active_ports
)
2268 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2271 static int ehea_up(struct net_device
*dev
)
2274 struct ehea_port
*port
= netdev_priv(dev
);
2276 if (port
->state
== EHEA_PORT_UP
)
2279 ret
= ehea_port_res_setup(port
, port
->num_def_qps
,
2280 port
->num_add_tx_qps
);
2282 ehea_error("port_res_failed");
2286 /* Set default QP for this port */
2287 ret
= ehea_configure_port(port
);
2289 ehea_error("ehea_configure_port failed. ret:%d", ret
);
2293 ret
= ehea_reg_interrupts(dev
);
2295 ehea_error("reg_interrupts failed. ret:%d", ret
);
2299 for(i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2300 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2302 ehea_error("activate_qp failed");
2307 for(i
= 0; i
< port
->num_def_qps
; i
++) {
2308 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2310 ehea_error("out_free_irqs");
2316 port
->state
= EHEA_PORT_UP
;
2320 ehea_free_interrupts(dev
);
2323 ehea_clean_all_portres(port
);
2326 ehea_info("Failed starting %s. ret=%i", dev
->name
, ret
);
2331 static void port_napi_disable(struct ehea_port
*port
)
2335 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2336 napi_disable(&port
->port_res
[i
].napi
);
2339 static void port_napi_enable(struct ehea_port
*port
)
2343 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2344 napi_enable(&port
->port_res
[i
].napi
);
2347 static int ehea_open(struct net_device
*dev
)
2350 struct ehea_port
*port
= netdev_priv(dev
);
2352 down(&port
->port_lock
);
2354 if (netif_msg_ifup(port
))
2355 ehea_info("enabling port %s", dev
->name
);
2359 port_napi_enable(port
);
2360 netif_start_queue(dev
);
2363 up(&port
->port_lock
);
2368 static int ehea_down(struct net_device
*dev
)
2371 struct ehea_port
*port
= netdev_priv(dev
);
2373 if (port
->state
== EHEA_PORT_DOWN
)
2376 ehea_drop_multicast_list(dev
);
2377 ehea_free_interrupts(dev
);
2379 port
->state
= EHEA_PORT_DOWN
;
2381 ret
= ehea_clean_all_portres(port
);
2383 ehea_info("Failed freeing resources for %s. ret=%i",
2389 static int ehea_stop(struct net_device
*dev
)
2392 struct ehea_port
*port
= netdev_priv(dev
);
2394 if (netif_msg_ifdown(port
))
2395 ehea_info("disabling port %s", dev
->name
);
2397 flush_scheduled_work();
2398 down(&port
->port_lock
);
2399 netif_stop_queue(dev
);
2400 port_napi_disable(port
);
2401 ret
= ehea_down(dev
);
2402 up(&port
->port_lock
);
2406 void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2408 struct ehea_qp qp
= *orig_qp
;
2409 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2410 struct ehea_swqe
*swqe
;
2414 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2415 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2416 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2420 int ehea_stop_qps(struct net_device
*dev
)
2422 struct ehea_port
*port
= netdev_priv(dev
);
2423 struct ehea_adapter
*adapter
= port
->adapter
;
2424 struct hcp_modify_qp_cb0
* cb0
;
2432 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2438 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2439 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2440 struct ehea_qp
*qp
= pr
->qp
;
2442 /* Purge send queue */
2445 /* Disable queue pair */
2446 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2447 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2449 if (hret
!= H_SUCCESS
) {
2450 ehea_error("query_ehea_qp failed (1)");
2454 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2455 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2457 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2460 &dummy64
, &dummy16
, &dummy16
);
2461 if (hret
!= H_SUCCESS
) {
2462 ehea_error("modify_ehea_qp failed (1)");
2466 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2467 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2469 if (hret
!= H_SUCCESS
) {
2470 ehea_error("query_ehea_qp failed (2)");
2474 /* deregister shared memory regions */
2475 dret
= ehea_rem_smrs(pr
);
2477 ehea_error("unreg shared memory region failed");
2489 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
* pr
)
2491 struct ehea_qp qp
= *orig_qp
;
2492 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2493 struct ehea_rwqe
*rwqe
;
2494 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2495 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2496 struct sk_buff
*skb
;
2497 u32 lkey
= pr
->recv_mr
.lkey
;
2503 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2504 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2505 rwqe
->sg_list
[0].l_key
= lkey
;
2506 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2507 skb
= skba_rq2
[index
];
2509 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2512 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2513 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2514 rwqe
->sg_list
[0].l_key
= lkey
;
2515 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2516 skb
= skba_rq3
[index
];
2518 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2522 int ehea_restart_qps(struct net_device
*dev
)
2524 struct ehea_port
*port
= netdev_priv(dev
);
2525 struct ehea_adapter
*adapter
= port
->adapter
;
2529 struct hcp_modify_qp_cb0
* cb0
;
2534 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2540 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2541 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2542 struct ehea_qp
*qp
= pr
->qp
;
2544 ret
= ehea_gen_smrs(pr
);
2546 ehea_error("creation of shared memory regions failed");
2550 ehea_update_rqs(qp
, pr
);
2552 /* Enable queue pair */
2553 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2554 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2556 if (hret
!= H_SUCCESS
) {
2557 ehea_error("query_ehea_qp failed (1)");
2561 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2562 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2564 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2565 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2567 &dummy64
, &dummy16
, &dummy16
);
2568 if (hret
!= H_SUCCESS
) {
2569 ehea_error("modify_ehea_qp failed (1)");
2573 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2574 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2576 if (hret
!= H_SUCCESS
) {
2577 ehea_error("query_ehea_qp failed (2)");
2581 /* refill entire queue */
2582 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2583 ehea_refill_rq2(pr
, 0);
2584 ehea_refill_rq3(pr
, 0);
2592 static void ehea_reset_port(struct work_struct
*work
)
2595 struct ehea_port
*port
=
2596 container_of(work
, struct ehea_port
, reset_task
);
2597 struct net_device
*dev
= port
->netdev
;
2600 down(&port
->port_lock
);
2601 netif_stop_queue(dev
);
2603 port_napi_disable(port
);
2611 ehea_set_multicast_list(dev
);
2613 if (netif_msg_timer(port
))
2614 ehea_info("Device %s resetted successfully", dev
->name
);
2616 port_napi_enable(port
);
2618 netif_wake_queue(dev
);
2620 up(&port
->port_lock
);
2624 static void ehea_rereg_mrs(struct work_struct
*work
)
2627 struct ehea_adapter
*adapter
;
2629 down(&dlpar_mem_lock
);
2630 ehea_info("LPAR memory enlarged - re-initializing driver");
2632 list_for_each_entry(adapter
, &adapter_list
, list
)
2633 if (adapter
->active_ports
) {
2634 /* Shutdown all ports */
2635 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2636 struct ehea_port
*port
= adapter
->port
[i
];
2639 struct net_device
*dev
= port
->netdev
;
2641 if (dev
->flags
& IFF_UP
) {
2642 down(&port
->port_lock
);
2643 netif_stop_queue(dev
);
2644 ret
= ehea_stop_qps(dev
);
2646 up(&port
->port_lock
);
2649 port_napi_disable(port
);
2650 up(&port
->port_lock
);
2655 /* Unregister old memory region */
2656 ret
= ehea_rem_mr(&adapter
->mr
);
2658 ehea_error("unregister MR failed - driver"
2664 ehea_destroy_busmap();
2665 ret
= ehea_create_busmap();
2667 ehea_error("creating ehea busmap failed");
2671 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2673 list_for_each_entry(adapter
, &adapter_list
, list
)
2674 if (adapter
->active_ports
) {
2675 /* Register new memory region */
2676 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2678 ehea_error("register MR failed - driver"
2683 /* Restart all ports */
2684 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2685 struct ehea_port
*port
= adapter
->port
[i
];
2688 struct net_device
*dev
= port
->netdev
;
2690 if (dev
->flags
& IFF_UP
) {
2691 down(&port
->port_lock
);
2692 port_napi_enable(port
);
2693 ret
= ehea_restart_qps(dev
);
2695 netif_wake_queue(dev
);
2696 up(&port
->port_lock
);
2701 up(&dlpar_mem_lock
);
2702 ehea_info("re-initializing driver complete");
2707 static void ehea_tx_watchdog(struct net_device
*dev
)
2709 struct ehea_port
*port
= netdev_priv(dev
);
2711 if (netif_carrier_ok(dev
) &&
2712 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2713 schedule_work(&port
->reset_task
);
2716 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2718 struct hcp_query_ehea
*cb
;
2722 cb
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2728 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2730 if (hret
!= H_SUCCESS
) {
2735 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2744 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2746 struct hcp_ehea_port_cb4
*cb4
;
2752 /* (Try to) enable *jumbo frames */
2753 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2755 ehea_error("no mem for cb4");
2759 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2760 port
->logical_port_id
,
2762 H_PORT_CB4_JUMBO
, cb4
);
2763 if (hret
== H_SUCCESS
) {
2764 if (cb4
->jumbo_frame
)
2767 cb4
->jumbo_frame
= 1;
2768 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2775 if (hret
== H_SUCCESS
)
2787 static ssize_t
ehea_show_port_id(struct device
*dev
,
2788 struct device_attribute
*attr
, char *buf
)
2790 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2791 return sprintf(buf
, "%d", port
->logical_port_id
);
2794 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2797 static void __devinit
logical_port_release(struct device
*dev
)
2799 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2800 of_node_put(port
->ofdev
.node
);
2803 static int ehea_driver_sysfs_add(struct device
*dev
,
2804 struct device_driver
*driver
)
2808 ret
= sysfs_create_link(&driver
->kobj
, &dev
->kobj
,
2809 kobject_name(&dev
->kobj
));
2811 ret
= sysfs_create_link(&dev
->kobj
, &driver
->kobj
,
2814 sysfs_remove_link(&driver
->kobj
,
2815 kobject_name(&dev
->kobj
));
2820 static void ehea_driver_sysfs_remove(struct device
*dev
,
2821 struct device_driver
*driver
)
2823 struct device_driver
*drv
= driver
;
2826 sysfs_remove_link(&drv
->kobj
, kobject_name(&dev
->kobj
));
2827 sysfs_remove_link(&dev
->kobj
, "driver");
2831 static struct device
*ehea_register_port(struct ehea_port
*port
,
2832 struct device_node
*dn
)
2836 port
->ofdev
.node
= of_node_get(dn
);
2837 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2838 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2840 sprintf(port
->ofdev
.dev
.bus_id
, "port%d", port_name_cnt
++);
2841 port
->ofdev
.dev
.release
= logical_port_release
;
2843 ret
= of_device_register(&port
->ofdev
);
2845 ehea_error("failed to register device. ret=%d", ret
);
2849 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2851 ehea_error("failed to register attributes, ret=%d", ret
);
2852 goto out_unreg_of_dev
;
2855 ret
= ehea_driver_sysfs_add(&port
->ofdev
.dev
, &ehea_driver
.driver
);
2857 ehea_error("failed to register sysfs driver link");
2858 goto out_rem_dev_file
;
2861 return &port
->ofdev
.dev
;
2864 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2866 of_device_unregister(&port
->ofdev
);
2871 static void ehea_unregister_port(struct ehea_port
*port
)
2873 ehea_driver_sysfs_remove(&port
->ofdev
.dev
, &ehea_driver
.driver
);
2874 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2875 of_device_unregister(&port
->ofdev
);
2878 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2879 u32 logical_port_id
,
2880 struct device_node
*dn
)
2883 struct net_device
*dev
;
2884 struct ehea_port
*port
;
2885 struct device
*port_dev
;
2888 /* allocate memory for the port structures */
2889 dev
= alloc_etherdev(sizeof(struct ehea_port
));
2892 ehea_error("no mem for net_device");
2897 port
= netdev_priv(dev
);
2899 sema_init(&port
->port_lock
, 1);
2900 port
->state
= EHEA_PORT_DOWN
;
2901 port
->sig_comp_iv
= sq_entries
/ 10;
2903 port
->adapter
= adapter
;
2905 port
->logical_port_id
= logical_port_id
;
2907 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
2909 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
2910 if (!port
->mc_list
) {
2912 goto out_free_ethdev
;
2915 INIT_LIST_HEAD(&port
->mc_list
->list
);
2917 ret
= ehea_sense_port_attr(port
);
2919 goto out_free_mc_list
;
2921 port_dev
= ehea_register_port(port
, dn
);
2923 goto out_free_mc_list
;
2925 SET_NETDEV_DEV(dev
, port_dev
);
2927 /* initialize net_device structure */
2928 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
2930 dev
->open
= ehea_open
;
2931 #ifdef CONFIG_NET_POLL_CONTROLLER
2932 dev
->poll_controller
= ehea_netpoll
;
2934 dev
->stop
= ehea_stop
;
2935 dev
->hard_start_xmit
= ehea_start_xmit
;
2936 dev
->get_stats
= ehea_get_stats
;
2937 dev
->set_multicast_list
= ehea_set_multicast_list
;
2938 dev
->set_mac_address
= ehea_set_mac_addr
;
2939 dev
->change_mtu
= ehea_change_mtu
;
2940 dev
->vlan_rx_register
= ehea_vlan_rx_register
;
2941 dev
->vlan_rx_add_vid
= ehea_vlan_rx_add_vid
;
2942 dev
->vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
;
2943 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
2944 | NETIF_F_HIGHDMA
| NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_TX
2945 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
2947 dev
->tx_timeout
= &ehea_tx_watchdog
;
2948 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
2950 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
2952 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2955 goto out_unreg_port
;
2958 ehea_set_ethtool_ops(dev
);
2960 ret
= register_netdev(dev
);
2962 ehea_error("register_netdev failed. ret=%d", ret
);
2966 port
->lro_max_aggr
= lro_max_aggr
;
2968 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
2970 ehea_error("failed determining jumbo frame status for %s",
2971 port
->netdev
->name
);
2973 ehea_info("%s: Jumbo frames are %sabled", dev
->name
,
2974 jumbo
== 1 ? "en" : "dis");
2976 adapter
->active_ports
++;
2981 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2984 ehea_unregister_port(port
);
2987 kfree(port
->mc_list
);
2993 ehea_error("setting up logical port with id=%d failed, ret=%d",
2994 logical_port_id
, ret
);
2998 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3000 unregister_netdev(port
->netdev
);
3001 ehea_unregister_port(port
);
3002 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
3003 kfree(port
->mc_list
);
3004 free_netdev(port
->netdev
);
3005 port
->adapter
->active_ports
--;
3008 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3010 struct device_node
*lhea_dn
;
3011 struct device_node
*eth_dn
= NULL
;
3013 const u32
*dn_log_port_id
;
3016 lhea_dn
= adapter
->ofdev
->node
;
3017 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3019 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3021 if (!dn_log_port_id
) {
3022 ehea_error("bad device node: eth_dn name=%s",
3027 if (ehea_add_adapter_mr(adapter
)) {
3028 ehea_error("creating MR failed");
3029 of_node_put(eth_dn
);
3033 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3036 if (adapter
->port
[i
])
3037 ehea_info("%s -> logical port id #%d",
3038 adapter
->port
[i
]->netdev
->name
,
3041 ehea_remove_adapter_mr(adapter
);
3049 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3050 u32 logical_port_id
)
3052 struct device_node
*lhea_dn
;
3053 struct device_node
*eth_dn
= NULL
;
3054 const u32
*dn_log_port_id
;
3056 lhea_dn
= adapter
->ofdev
->node
;
3057 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3059 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3062 if (*dn_log_port_id
== logical_port_id
)
3069 static ssize_t
ehea_probe_port(struct device
*dev
,
3070 struct device_attribute
*attr
,
3071 const char *buf
, size_t count
)
3073 struct ehea_adapter
*adapter
= dev
->driver_data
;
3074 struct ehea_port
*port
;
3075 struct device_node
*eth_dn
= NULL
;
3078 u32 logical_port_id
;
3080 sscanf(buf
, "%d", &logical_port_id
);
3082 port
= ehea_get_port(adapter
, logical_port_id
);
3085 ehea_info("adding port with logical port id=%d failed. port "
3086 "already configured as %s.", logical_port_id
,
3087 port
->netdev
->name
);
3091 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3094 ehea_info("no logical port with id %d found", logical_port_id
);
3098 if (ehea_add_adapter_mr(adapter
)) {
3099 ehea_error("creating MR failed");
3103 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3105 of_node_put(eth_dn
);
3108 for (i
=0; i
< EHEA_MAX_PORTS
; i
++)
3109 if (!adapter
->port
[i
]) {
3110 adapter
->port
[i
] = port
;
3114 ehea_info("added %s (logical port id=%d)", port
->netdev
->name
,
3117 ehea_remove_adapter_mr(adapter
);
3121 return (ssize_t
) count
;
3124 static ssize_t
ehea_remove_port(struct device
*dev
,
3125 struct device_attribute
*attr
,
3126 const char *buf
, size_t count
)
3128 struct ehea_adapter
*adapter
= dev
->driver_data
;
3129 struct ehea_port
*port
;
3131 u32 logical_port_id
;
3133 sscanf(buf
, "%d", &logical_port_id
);
3135 port
= ehea_get_port(adapter
, logical_port_id
);
3138 ehea_info("removed %s (logical port id=%d)", port
->netdev
->name
,
3141 ehea_shutdown_single_port(port
);
3143 for (i
=0; i
< EHEA_MAX_PORTS
; i
++)
3144 if (adapter
->port
[i
] == port
) {
3145 adapter
->port
[i
] = NULL
;
3149 ehea_error("removing port with logical port id=%d failed. port "
3150 "not configured.", logical_port_id
);
3154 ehea_remove_adapter_mr(adapter
);
3156 return (ssize_t
) count
;
3159 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3160 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3162 int ehea_create_device_sysfs(struct of_device
*dev
)
3164 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3168 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3173 void ehea_remove_device_sysfs(struct of_device
*dev
)
3175 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3176 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3179 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
3180 const struct of_device_id
*id
)
3182 struct ehea_adapter
*adapter
;
3183 const u64
*adapter_handle
;
3186 if (!dev
|| !dev
->node
) {
3187 ehea_error("Invalid ibmebus device probed");
3191 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3194 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3198 list_add(&adapter
->list
, &adapter_list
);
3200 adapter
->ofdev
= dev
;
3202 adapter_handle
= of_get_property(dev
->node
, "ibm,hea-handle",
3205 adapter
->handle
= *adapter_handle
;
3207 if (!adapter
->handle
) {
3208 dev_err(&dev
->dev
, "failed getting handle for adapter"
3209 " '%s'\n", dev
->node
->full_name
);
3214 adapter
->pd
= EHEA_PD_ID
;
3216 dev
->dev
.driver_data
= adapter
;
3219 /* initialize adapter and ports */
3220 /* get adapter properties */
3221 ret
= ehea_sense_adapter_attr(adapter
);
3223 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3227 adapter
->neq
= ehea_create_eq(adapter
,
3228 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3229 if (!adapter
->neq
) {
3231 dev_err(&dev
->dev
, "NEQ creation failed\n");
3235 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3236 (unsigned long)adapter
);
3238 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3239 ehea_interrupt_neq
, IRQF_DISABLED
,
3240 "ehea_neq", adapter
);
3242 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3246 ret
= ehea_create_device_sysfs(dev
);
3250 ret
= ehea_setup_ports(adapter
);
3252 dev_err(&dev
->dev
, "setup_ports failed\n");
3253 goto out_rem_dev_sysfs
;
3260 ehea_remove_device_sysfs(dev
);
3263 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3266 ehea_destroy_eq(adapter
->neq
);
3274 static int __devexit
ehea_remove(struct of_device
*dev
)
3276 struct ehea_adapter
*adapter
= dev
->dev
.driver_data
;
3279 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3280 if (adapter
->port
[i
]) {
3281 ehea_shutdown_single_port(adapter
->port
[i
]);
3282 adapter
->port
[i
] = NULL
;
3285 ehea_remove_device_sysfs(dev
);
3287 flush_scheduled_work();
3289 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3290 tasklet_kill(&adapter
->neq_tasklet
);
3292 ehea_destroy_eq(adapter
->neq
);
3293 ehea_remove_adapter_mr(adapter
);
3294 list_del(&adapter
->list
);
3301 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3302 unsigned long action
, void *unused
)
3304 if (action
== SYS_RESTART
) {
3305 ehea_info("Reboot: freeing all eHEA resources");
3306 ibmebus_unregister_driver(&ehea_driver
);
3311 static struct notifier_block ehea_reboot_nb
= {
3312 .notifier_call
= ehea_reboot_notifier
,
3315 static int check_module_parm(void)
3319 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3320 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3321 ehea_info("Bad parameter: rq1_entries");
3324 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3325 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3326 ehea_info("Bad parameter: rq2_entries");
3329 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3330 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3331 ehea_info("Bad parameter: rq3_entries");
3334 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3335 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3336 ehea_info("Bad parameter: sq_entries");
3343 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3346 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3349 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3350 ehea_show_capabilities
, NULL
);
3352 int __init
ehea_module_init(void)
3356 printk(KERN_INFO
"IBM eHEA ethernet device driver (Release %s)\n",
3360 INIT_WORK(&ehea_rereg_mr_task
, ehea_rereg_mrs
);
3361 sema_init(&dlpar_mem_lock
, 1);
3363 ret
= check_module_parm();
3367 ret
= ehea_create_busmap();
3371 register_reboot_notifier(&ehea_reboot_nb
);
3373 ret
= ibmebus_register_driver(&ehea_driver
);
3375 ehea_error("failed registering eHEA device driver on ebus");
3379 ret
= driver_create_file(&ehea_driver
.driver
,
3380 &driver_attr_capabilities
);
3382 ehea_error("failed to register capabilities attribute, ret=%d",
3384 unregister_reboot_notifier(&ehea_reboot_nb
);
3385 ibmebus_unregister_driver(&ehea_driver
);
3393 static void __exit
ehea_module_exit(void)
3395 flush_scheduled_work();
3396 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3397 ibmebus_unregister_driver(&ehea_driver
);
3398 unregister_reboot_notifier(&ehea_reboot_nb
);
3399 ehea_destroy_busmap();
3402 module_init(ehea_module_init
);
3403 module_exit(ehea_module_exit
);