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>
40 #include "ehea_phyp.h"
43 MODULE_LICENSE("GPL");
44 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
45 MODULE_DESCRIPTION("IBM eServer HEA Driver");
46 MODULE_VERSION(DRV_VERSION
);
49 static int msg_level
= -1;
50 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
51 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
52 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
53 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
54 static int use_mcs
= 0;
55 static int use_lro
= 0;
56 static int lro_max_aggr
= EHEA_LRO_MAX_AGGR
;
57 static int num_tx_qps
= EHEA_NUM_TX_QP
;
58 static int prop_carrier_state
= 0;
60 module_param(msg_level
, int, 0);
61 module_param(rq1_entries
, int, 0);
62 module_param(rq2_entries
, int, 0);
63 module_param(rq3_entries
, int, 0);
64 module_param(sq_entries
, int, 0);
65 module_param(prop_carrier_state
, int, 0);
66 module_param(use_mcs
, int, 0);
67 module_param(use_lro
, int, 0);
68 module_param(lro_max_aggr
, int, 0);
69 module_param(num_tx_qps
, int, 0);
71 MODULE_PARM_DESC(num_tx_qps
, "Number of TX-QPS");
72 MODULE_PARM_DESC(msg_level
, "msg_level");
73 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
74 "port to stack. 1:yes, 0:no. Default = 0 ");
75 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
76 "[2^x - 1], x = [6..14]. Default = "
77 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
78 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
81 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
84 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
87 MODULE_PARM_DESC(use_mcs
, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
89 MODULE_PARM_DESC(lro_max_aggr
, " LRO: Max packets to be aggregated. Default = "
90 __MODULE_STRING(EHEA_LRO_MAX_AGGR
));
91 MODULE_PARM_DESC(use_lro
, " Large Receive Offload, 1: enable, 0: disable, "
94 static int port_name_cnt
= 0;
95 static LIST_HEAD(adapter_list
);
96 u64 ehea_driver_flags
= 0;
97 struct work_struct ehea_rereg_mr_task
;
99 struct semaphore dlpar_mem_lock
;
101 static int __devinit
ehea_probe_adapter(struct ibmebus_dev
*dev
,
102 const struct of_device_id
*id
);
104 static int __devexit
ehea_remove(struct ibmebus_dev
*dev
);
106 static struct of_device_id ehea_device_table
[] = {
109 .compatible
= "IBM,lhea",
114 static struct ibmebus_driver ehea_driver
= {
116 .id_table
= ehea_device_table
,
117 .probe
= ehea_probe_adapter
,
118 .remove
= ehea_remove
,
121 void ehea_dump(void *adr
, int len
, char *msg
) {
123 unsigned char *deb
= adr
;
124 for (x
= 0; x
< len
; x
+= 16) {
125 printk(DRV_NAME
" %s adr=%p ofs=%04x %016lx %016lx\n", msg
,
126 deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
131 static struct net_device_stats
*ehea_get_stats(struct net_device
*dev
)
133 struct ehea_port
*port
= netdev_priv(dev
);
134 struct net_device_stats
*stats
= &port
->stats
;
135 struct hcp_ehea_port_cb2
*cb2
;
136 u64 hret
, rx_packets
;
139 memset(stats
, 0, sizeof(*stats
));
141 cb2
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
143 ehea_error("no mem for cb2");
147 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
148 port
->logical_port_id
,
149 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
150 if (hret
!= H_SUCCESS
) {
151 ehea_error("query_ehea_port failed");
155 if (netif_msg_hw(port
))
156 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
159 for (i
= 0; i
< port
->num_def_qps
; i
++)
160 rx_packets
+= port
->port_res
[i
].rx_packets
;
162 stats
->tx_packets
= cb2
->txucp
+ cb2
->txmcp
+ cb2
->txbcp
;
163 stats
->multicast
= cb2
->rxmcp
;
164 stats
->rx_errors
= cb2
->rxuerr
;
165 stats
->rx_bytes
= cb2
->rxo
;
166 stats
->tx_bytes
= cb2
->txo
;
167 stats
->rx_packets
= rx_packets
;
175 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
177 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
178 struct net_device
*dev
= pr
->port
->netdev
;
179 int max_index_mask
= pr
->rq1_skba
.len
- 1;
180 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
184 pr
->rq1_skba
.os_skbs
= 0;
186 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
187 pr
->rq1_skba
.index
= index
;
188 pr
->rq1_skba
.os_skbs
= fill_wqes
;
192 for (i
= 0; i
< fill_wqes
; i
++) {
193 if (!skb_arr_rq1
[index
]) {
194 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
196 if (!skb_arr_rq1
[index
]) {
197 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
198 ehea_error("%s: no mem for skb/%d wqes filled",
204 index
&= max_index_mask
;
212 ehea_update_rq1a(pr
->qp
, adder
);
215 static int ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
218 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
219 struct net_device
*dev
= pr
->port
->netdev
;
222 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++) {
223 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
224 if (!skb_arr_rq1
[i
]) {
225 ehea_error("%s: no mem for skb/%d wqes filled",
232 ehea_update_rq1a(pr
->qp
, nr_rq1a
);
237 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
238 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
239 int num_wqes
, int wqe_type
, int packet_size
)
241 struct net_device
*dev
= pr
->port
->netdev
;
242 struct ehea_qp
*qp
= pr
->qp
;
243 struct sk_buff
**skb_arr
= q_skba
->arr
;
244 struct ehea_rwqe
*rwqe
;
245 int i
, index
, max_index_mask
, fill_wqes
;
249 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
252 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
253 q_skba
->os_skbs
= fill_wqes
;
257 index
= q_skba
->index
;
258 max_index_mask
= q_skba
->len
- 1;
259 for (i
= 0; i
< fill_wqes
; i
++) {
261 struct sk_buff
*skb
= netdev_alloc_skb(dev
, packet_size
);
263 ehea_error("%s: no mem for skb/%d wqes filled",
264 pr
->port
->netdev
->name
, i
);
265 q_skba
->os_skbs
= fill_wqes
- i
;
269 skb_reserve(skb
, NET_IP_ALIGN
);
271 skb_arr
[index
] = skb
;
272 tmp_addr
= ehea_map_vaddr(skb
->data
);
273 if (tmp_addr
== -1) {
275 q_skba
->os_skbs
= fill_wqes
- i
;
280 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
281 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
282 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
283 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
284 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
285 rwqe
->sg_list
[0].len
= packet_size
;
286 rwqe
->data_segments
= 1;
289 index
&= max_index_mask
;
293 q_skba
->index
= index
;
300 ehea_update_rq2a(pr
->qp
, adder
);
302 ehea_update_rq3a(pr
->qp
, adder
);
308 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
310 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
311 nr_of_wqes
, EHEA_RWQE2_TYPE
,
312 EHEA_RQ2_PKT_SIZE
+ NET_IP_ALIGN
);
316 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
318 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
319 nr_of_wqes
, EHEA_RWQE3_TYPE
,
320 EHEA_MAX_PACKET_SIZE
+ NET_IP_ALIGN
);
323 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
325 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
326 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
328 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
329 (cqe
->header_length
== 0))
334 static inline void ehea_fill_skb(struct net_device
*dev
,
335 struct sk_buff
*skb
, struct ehea_cqe
*cqe
)
337 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
339 skb_put(skb
, length
);
340 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
341 skb
->protocol
= eth_type_trans(skb
, dev
);
344 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
346 struct ehea_cqe
*cqe
)
348 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
358 prefetchw(pref
+ EHEA_CACHE_LINE
);
360 pref
= (skb_array
[x
]->data
);
362 prefetch(pref
+ EHEA_CACHE_LINE
);
363 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
364 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
365 skb
= skb_array
[skb_index
];
366 skb_array
[skb_index
] = NULL
;
370 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
371 int arr_len
, int wqe_index
)
382 prefetchw(pref
+ EHEA_CACHE_LINE
);
384 pref
= (skb_array
[x
]->data
);
386 prefetchw(pref
+ EHEA_CACHE_LINE
);
388 skb
= skb_array
[wqe_index
];
389 skb_array
[wqe_index
] = NULL
;
393 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
394 struct ehea_cqe
*cqe
, int *processed_rq2
,
399 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
400 pr
->p_stats
.err_tcp_cksum
++;
401 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
402 pr
->p_stats
.err_ip_cksum
++;
403 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
404 pr
->p_stats
.err_frame_crc
++;
406 if (netif_msg_rx_err(pr
->port
)) {
407 ehea_error("CQE Error for QP %d", pr
->qp
->init_attr
.qp_nr
);
408 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
413 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
415 } else if (rq
== 3) {
417 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
421 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
422 ehea_error("Critical receive error. Resetting port.");
423 schedule_work(&pr
->port
->reset_task
);
430 static int get_skb_hdr(struct sk_buff
*skb
, void **iphdr
,
431 void **tcph
, u64
*hdr_flags
, void *priv
)
433 struct ehea_cqe
*cqe
= priv
;
437 /* non tcp/udp packets */
438 if (!cqe
->header_length
)
442 skb_reset_network_header(skb
);
444 if (iph
->protocol
!= IPPROTO_TCP
)
447 ip_len
= ip_hdrlen(skb
);
448 skb_set_transport_header(skb
, ip_len
);
449 *tcph
= tcp_hdr(skb
);
451 /* check if ip header and tcp header are complete */
452 if (iph
->tot_len
< ip_len
+ tcp_hdrlen(skb
))
455 *hdr_flags
= LRO_IPV4
| LRO_TCP
;
461 static void ehea_proc_skb(struct ehea_port_res
*pr
, struct ehea_cqe
*cqe
,
464 int vlan_extracted
= (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
469 lro_vlan_hwaccel_receive_skb(&pr
->lro_mgr
, skb
,
474 lro_receive_skb(&pr
->lro_mgr
, skb
, cqe
);
477 vlan_hwaccel_receive_skb(skb
, pr
->port
->vgrp
,
480 netif_receive_skb(skb
);
484 static int ehea_proc_rwqes(struct net_device
*dev
,
485 struct ehea_port_res
*pr
,
488 struct ehea_port
*port
= pr
->port
;
489 struct ehea_qp
*qp
= pr
->qp
;
490 struct ehea_cqe
*cqe
;
492 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
493 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
494 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
495 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
496 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
497 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
498 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
499 int wqe_index
, last_wqe_index
, rq
, port_reset
;
501 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
504 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
505 while ((processed
< budget
) && cqe
) {
509 if (netif_msg_rx_status(port
))
510 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
512 last_wqe_index
= wqe_index
;
514 if (!ehea_check_cqe(cqe
, &rq
)) {
515 if (rq
== 1) { /* LL RQ1 */
516 skb
= get_skb_by_index_ll(skb_arr_rq1
,
519 if (unlikely(!skb
)) {
520 if (netif_msg_rx_err(port
))
521 ehea_error("LL rq1: skb=NULL");
523 skb
= netdev_alloc_skb(dev
,
528 skb_copy_to_linear_data(skb
, ((char*)cqe
) + 64,
529 cqe
->num_bytes_transfered
- 4);
530 ehea_fill_skb(dev
, skb
, cqe
);
531 } else if (rq
== 2) { /* RQ2 */
532 skb
= get_skb_by_index(skb_arr_rq2
,
533 skb_arr_rq2_len
, cqe
);
534 if (unlikely(!skb
)) {
535 if (netif_msg_rx_err(port
))
536 ehea_error("rq2: skb=NULL");
539 ehea_fill_skb(dev
, skb
, cqe
);
542 skb
= get_skb_by_index(skb_arr_rq3
,
543 skb_arr_rq3_len
, cqe
);
544 if (unlikely(!skb
)) {
545 if (netif_msg_rx_err(port
))
546 ehea_error("rq3: skb=NULL");
549 ehea_fill_skb(dev
, skb
, cqe
);
553 ehea_proc_skb(pr
, cqe
, skb
);
554 dev
->last_rx
= jiffies
;
556 pr
->p_stats
.poll_receive_errors
++;
557 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
563 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
566 lro_flush_all(&pr
->lro_mgr
);
568 pr
->rx_packets
+= processed
;
570 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
571 ehea_refill_rq2(pr
, processed_rq2
);
572 ehea_refill_rq3(pr
, processed_rq3
);
577 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
580 struct ehea_cq
*send_cq
= pr
->send_cq
;
581 struct ehea_cqe
*cqe
;
582 int quota
= my_quota
;
588 cqe
= ehea_poll_cq(send_cq
);
589 while(cqe
&& (quota
> 0)) {
590 ehea_inc_cq(send_cq
);
594 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
595 ehea_error("Send Completion Error: Resetting port");
596 if (netif_msg_tx_err(pr
->port
))
597 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
598 schedule_work(&pr
->port
->reset_task
);
602 if (netif_msg_tx_done(pr
->port
))
603 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
605 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
606 == EHEA_SWQE2_TYPE
)) {
608 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
609 skb
= pr
->sq_skba
.arr
[index
];
611 pr
->sq_skba
.arr
[index
] = NULL
;
614 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
617 cqe
= ehea_poll_cq(send_cq
);
620 ehea_update_feca(send_cq
, cqe_counter
);
621 atomic_add(swqe_av
, &pr
->swqe_avail
);
623 spin_lock_irqsave(&pr
->netif_queue
, flags
);
625 if (pr
->queue_stopped
&& (atomic_read(&pr
->swqe_avail
)
626 >= pr
->swqe_refill_th
)) {
627 netif_wake_queue(pr
->port
->netdev
);
628 pr
->queue_stopped
= 0;
630 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
635 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
636 #define EHEA_POLL_MAX_CQES 65535
638 static int ehea_poll(struct napi_struct
*napi
, int budget
)
640 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
, napi
);
641 struct net_device
*dev
= pr
->port
->netdev
;
642 struct ehea_cqe
*cqe
;
643 struct ehea_cqe
*cqe_skb
= NULL
;
644 int force_irq
, wqe_index
;
647 force_irq
= (pr
->poll_counter
> EHEA_NAPI_POLL_NUM_BEFORE_IRQ
);
648 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
651 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
653 while ((rx
!= budget
) || force_irq
) {
654 pr
->poll_counter
= 0;
656 netif_rx_complete(dev
, napi
);
657 ehea_reset_cq_ep(pr
->recv_cq
);
658 ehea_reset_cq_ep(pr
->send_cq
);
659 ehea_reset_cq_n1(pr
->recv_cq
);
660 ehea_reset_cq_n1(pr
->send_cq
);
661 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
662 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
664 if (!cqe
&& !cqe_skb
)
667 if (!netif_rx_reschedule(dev
, napi
))
670 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
671 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
678 #ifdef CONFIG_NET_POLL_CONTROLLER
679 static void ehea_netpoll(struct net_device
*dev
)
681 struct ehea_port
*port
= netdev_priv(dev
);
684 for (i
= 0; i
< port
->num_def_qps
; i
++)
685 netif_rx_schedule(dev
, &port
->port_res
[i
].napi
);
689 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
691 struct ehea_port_res
*pr
= param
;
693 netif_rx_schedule(pr
->port
->netdev
, &pr
->napi
);
698 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
700 struct ehea_port
*port
= param
;
701 struct ehea_eqe
*eqe
;
705 eqe
= ehea_poll_eq(port
->qp_eq
);
708 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
709 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
710 eqe
->entry
, qp_token
);
712 qp
= port
->port_res
[qp_token
].qp
;
713 ehea_error_data(port
->adapter
, qp
->fw_handle
);
714 eqe
= ehea_poll_eq(port
->qp_eq
);
717 schedule_work(&port
->reset_task
);
722 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
727 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
728 if (adapter
->port
[i
])
729 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
730 return adapter
->port
[i
];
734 int ehea_sense_port_attr(struct ehea_port
*port
)
738 struct hcp_ehea_port_cb0
*cb0
;
740 cb0
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
); /* May be called via */
741 if (!cb0
) { /* ehea_neq_tasklet() */
742 ehea_error("no mem for cb0");
747 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
748 port
->logical_port_id
, H_PORT_CB0
,
749 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
751 if (hret
!= H_SUCCESS
) {
757 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
759 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
760 ret
= -EADDRNOTAVAIL
;
765 switch (cb0
->port_speed
) {
767 port
->port_speed
= EHEA_SPEED_10M
;
768 port
->full_duplex
= 0;
771 port
->port_speed
= EHEA_SPEED_10M
;
772 port
->full_duplex
= 1;
775 port
->port_speed
= EHEA_SPEED_100M
;
776 port
->full_duplex
= 0;
779 port
->port_speed
= EHEA_SPEED_100M
;
780 port
->full_duplex
= 1;
783 port
->port_speed
= EHEA_SPEED_1G
;
784 port
->full_duplex
= 1;
787 port
->port_speed
= EHEA_SPEED_10G
;
788 port
->full_duplex
= 1;
791 port
->port_speed
= 0;
792 port
->full_duplex
= 0;
797 port
->num_mcs
= cb0
->num_default_qps
;
799 /* Number of default QPs */
801 port
->num_def_qps
= cb0
->num_default_qps
;
803 port
->num_def_qps
= 1;
805 if (!port
->num_def_qps
) {
810 port
->num_tx_qps
= num_tx_qps
;
812 if (port
->num_def_qps
>= port
->num_tx_qps
)
813 port
->num_add_tx_qps
= 0;
815 port
->num_add_tx_qps
= port
->num_tx_qps
- port
->num_def_qps
;
819 if (ret
|| netif_msg_probe(port
))
820 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
826 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
828 struct hcp_ehea_port_cb4
*cb4
;
832 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
834 ehea_error("no mem for cb4");
839 cb4
->port_speed
= port_speed
;
841 netif_carrier_off(port
->netdev
);
843 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
844 port
->logical_port_id
,
845 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
846 if (hret
== H_SUCCESS
) {
847 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
849 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
850 port
->logical_port_id
,
851 H_PORT_CB4
, H_PORT_CB4_SPEED
,
853 if (hret
== H_SUCCESS
) {
854 switch (cb4
->port_speed
) {
856 port
->port_speed
= EHEA_SPEED_10M
;
857 port
->full_duplex
= 0;
860 port
->port_speed
= EHEA_SPEED_10M
;
861 port
->full_duplex
= 1;
864 port
->port_speed
= EHEA_SPEED_100M
;
865 port
->full_duplex
= 0;
868 port
->port_speed
= EHEA_SPEED_100M
;
869 port
->full_duplex
= 1;
872 port
->port_speed
= EHEA_SPEED_1G
;
873 port
->full_duplex
= 1;
876 port
->port_speed
= EHEA_SPEED_10G
;
877 port
->full_duplex
= 1;
880 port
->port_speed
= 0;
881 port
->full_duplex
= 0;
885 ehea_error("Failed sensing port speed");
889 if (hret
== H_AUTHORITY
) {
890 ehea_info("Hypervisor denied setting port speed");
894 ehea_error("Failed setting port speed");
897 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
898 netif_carrier_on(port
->netdev
);
905 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
910 struct ehea_port
*port
;
912 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
913 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
914 port
= ehea_get_port(adapter
, portnum
);
917 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
920 ehea_error("unknown portnum %x", portnum
);
924 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
925 if (!netif_carrier_ok(port
->netdev
)) {
926 ret
= ehea_sense_port_attr(port
);
928 ehea_error("failed resensing port "
933 if (netif_msg_link(port
))
934 ehea_info("%s: Logical port up: %dMbps "
939 1 ? "Full" : "Half");
941 netif_carrier_on(port
->netdev
);
942 netif_wake_queue(port
->netdev
);
945 if (netif_carrier_ok(port
->netdev
)) {
946 if (netif_msg_link(port
))
947 ehea_info("%s: Logical port down",
949 netif_carrier_off(port
->netdev
);
950 netif_stop_queue(port
->netdev
);
953 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
954 port
->phy_link
= EHEA_PHY_LINK_UP
;
955 if (netif_msg_link(port
))
956 ehea_info("%s: Physical port up",
958 if (prop_carrier_state
)
959 netif_carrier_on(port
->netdev
);
961 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
962 if (netif_msg_link(port
))
963 ehea_info("%s: Physical port down",
965 if (prop_carrier_state
)
966 netif_carrier_off(port
->netdev
);
969 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
970 ehea_info("External switch port is primary port");
972 ehea_info("External switch port is backup port");
975 case EHEA_EC_ADAPTER_MALFUNC
:
976 ehea_error("Adapter malfunction");
978 case EHEA_EC_PORT_MALFUNC
:
979 ehea_info("Port malfunction: Device: %s", port
->netdev
->name
);
980 netif_carrier_off(port
->netdev
);
981 netif_stop_queue(port
->netdev
);
984 ehea_error("unknown event code %x, eqe=0x%lX", ec
, eqe
);
989 static void ehea_neq_tasklet(unsigned long data
)
991 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
992 struct ehea_eqe
*eqe
;
995 eqe
= ehea_poll_eq(adapter
->neq
);
996 ehea_debug("eqe=%p", eqe
);
999 ehea_debug("*eqe=%lx", eqe
->entry
);
1000 ehea_parse_eqe(adapter
, eqe
->entry
);
1001 eqe
= ehea_poll_eq(adapter
->neq
);
1002 ehea_debug("next eqe=%p", eqe
);
1005 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1006 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1007 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1009 ehea_h_reset_events(adapter
->handle
,
1010 adapter
->neq
->fw_handle
, event_mask
);
1013 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1015 struct ehea_adapter
*adapter
= param
;
1016 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1021 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1024 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1026 ret
= ehea_init_fill_rq1(pr
, init_attr
->act_nr_rwqes_rq1
1027 - init_attr
->act_nr_rwqes_rq2
1028 - init_attr
->act_nr_rwqes_rq3
- 1);
1030 ret
|= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1032 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1037 static int ehea_reg_interrupts(struct net_device
*dev
)
1039 struct ehea_port
*port
= netdev_priv(dev
);
1040 struct ehea_port_res
*pr
;
1044 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1047 ret
= ibmebus_request_irq(NULL
, port
->qp_eq
->attr
.ist1
,
1048 ehea_qp_aff_irq_handler
,
1049 IRQF_DISABLED
, port
->int_aff_name
, port
);
1051 ehea_error("failed registering irq for qp_aff_irq_handler:"
1052 "ist=%X", port
->qp_eq
->attr
.ist1
);
1056 if (netif_msg_ifup(port
))
1057 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1058 "registered", port
->qp_eq
->attr
.ist1
);
1061 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1062 pr
= &port
->port_res
[i
];
1063 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1064 "%s-queue%d", dev
->name
, i
);
1065 ret
= ibmebus_request_irq(NULL
, pr
->eq
->attr
.ist1
,
1066 ehea_recv_irq_handler
,
1067 IRQF_DISABLED
, pr
->int_send_name
,
1070 ehea_error("failed registering irq for ehea_queue "
1071 "port_res_nr:%d, ist=%X", i
,
1075 if (netif_msg_ifup(port
))
1076 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1077 "%d registered", pr
->eq
->attr
.ist1
, i
);
1085 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1086 ibmebus_free_irq(NULL
, ist
, &port
->port_res
[i
]);
1090 ibmebus_free_irq(NULL
, port
->qp_eq
->attr
.ist1
, port
);
1091 i
= port
->num_def_qps
;
1097 static void ehea_free_interrupts(struct net_device
*dev
)
1099 struct ehea_port
*port
= netdev_priv(dev
);
1100 struct ehea_port_res
*pr
;
1105 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1106 pr
= &port
->port_res
[i
];
1107 ibmebus_free_irq(NULL
, pr
->eq
->attr
.ist1
, pr
);
1108 if (netif_msg_intr(port
))
1109 ehea_info("free send irq for res %d with handle 0x%X",
1110 i
, pr
->eq
->attr
.ist1
);
1113 /* associated events */
1114 ibmebus_free_irq(NULL
, port
->qp_eq
->attr
.ist1
, port
);
1115 if (netif_msg_intr(port
))
1116 ehea_info("associated event interrupt for handle 0x%X freed",
1117 port
->qp_eq
->attr
.ist1
);
1120 static int ehea_configure_port(struct ehea_port
*port
)
1124 struct hcp_ehea_port_cb0
*cb0
;
1127 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1131 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1132 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1133 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1134 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1135 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1136 PXLY_RC_VLAN_FILTER
)
1137 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1139 for (i
= 0; i
< port
->num_mcs
; i
++)
1141 cb0
->default_qpn_arr
[i
] =
1142 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1144 cb0
->default_qpn_arr
[i
] =
1145 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1147 if (netif_msg_ifup(port
))
1148 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1150 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1151 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1153 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1154 port
->logical_port_id
,
1155 H_PORT_CB0
, mask
, cb0
);
1157 if (hret
!= H_SUCCESS
)
1168 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1171 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1173 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1177 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1184 ehea_rem_mr(&pr
->send_mr
);
1186 ehea_error("Generating SMRS failed\n");
1190 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1192 if ((ehea_rem_mr(&pr
->send_mr
))
1193 || (ehea_rem_mr(&pr
->recv_mr
)))
1199 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1201 int arr_size
= sizeof(void*) * max_q_entries
;
1203 q_skba
->arr
= vmalloc(arr_size
);
1207 memset(q_skba
->arr
, 0, arr_size
);
1209 q_skba
->len
= max_q_entries
;
1211 q_skba
->os_skbs
= 0;
1216 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1217 struct port_res_cfg
*pr_cfg
, int queue_token
)
1219 struct ehea_adapter
*adapter
= port
->adapter
;
1220 enum ehea_eq_type eq_type
= EHEA_EQ
;
1221 struct ehea_qp_init_attr
*init_attr
= NULL
;
1224 memset(pr
, 0, sizeof(struct ehea_port_res
));
1227 spin_lock_init(&pr
->xmit_lock
);
1228 spin_lock_init(&pr
->netif_queue
);
1230 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1232 ehea_error("create_eq failed (eq)");
1236 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1238 port
->logical_port_id
);
1240 ehea_error("create_cq failed (cq_recv)");
1244 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1246 port
->logical_port_id
);
1248 ehea_error("create_cq failed (cq_send)");
1252 if (netif_msg_ifup(port
))
1253 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1254 pr
->send_cq
->attr
.act_nr_of_cqes
,
1255 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1257 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1260 ehea_error("no mem for ehea_qp_init_attr");
1264 init_attr
->low_lat_rq1
= 1;
1265 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1266 init_attr
->rq_count
= 3;
1267 init_attr
->qp_token
= queue_token
;
1268 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1269 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1270 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1271 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1272 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1273 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1274 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1275 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1276 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1277 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1278 init_attr
->port_nr
= port
->logical_port_id
;
1279 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1280 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1281 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1283 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1285 ehea_error("create_qp failed");
1290 if (netif_msg_ifup(port
))
1291 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1292 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr
->qp_nr
,
1293 init_attr
->act_nr_send_wqes
,
1294 init_attr
->act_nr_rwqes_rq1
,
1295 init_attr
->act_nr_rwqes_rq2
,
1296 init_attr
->act_nr_rwqes_rq3
);
1298 ret
= ehea_init_q_skba(&pr
->sq_skba
, init_attr
->act_nr_send_wqes
+ 1);
1299 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1300 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1301 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1305 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1306 if (ehea_gen_smrs(pr
) != 0) {
1311 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1315 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1317 pr
->lro_mgr
.max_aggr
= pr
->port
->lro_max_aggr
;
1318 pr
->lro_mgr
.max_desc
= MAX_LRO_DESCRIPTORS
;
1319 pr
->lro_mgr
.lro_arr
= pr
->lro_desc
;
1320 pr
->lro_mgr
.get_skb_header
= get_skb_hdr
;
1321 pr
->lro_mgr
.features
= LRO_F_NAPI
| LRO_F_EXTRACT_VLAN_ID
;
1322 pr
->lro_mgr
.dev
= port
->netdev
;
1323 pr
->lro_mgr
.ip_summed
= CHECKSUM_UNNECESSARY
;
1324 pr
->lro_mgr
.ip_summed_aggr
= CHECKSUM_UNNECESSARY
;
1331 vfree(pr
->sq_skba
.arr
);
1332 vfree(pr
->rq1_skba
.arr
);
1333 vfree(pr
->rq2_skba
.arr
);
1334 vfree(pr
->rq3_skba
.arr
);
1335 ehea_destroy_qp(pr
->qp
);
1336 ehea_destroy_cq(pr
->send_cq
);
1337 ehea_destroy_cq(pr
->recv_cq
);
1338 ehea_destroy_eq(pr
->eq
);
1343 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1347 ret
= ehea_destroy_qp(pr
->qp
);
1350 ehea_destroy_cq(pr
->send_cq
);
1351 ehea_destroy_cq(pr
->recv_cq
);
1352 ehea_destroy_eq(pr
->eq
);
1354 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1355 if (pr
->rq1_skba
.arr
[i
])
1356 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1358 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1359 if (pr
->rq2_skba
.arr
[i
])
1360 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1362 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1363 if (pr
->rq3_skba
.arr
[i
])
1364 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1366 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1367 if (pr
->sq_skba
.arr
[i
])
1368 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1370 vfree(pr
->rq1_skba
.arr
);
1371 vfree(pr
->rq2_skba
.arr
);
1372 vfree(pr
->rq3_skba
.arr
);
1373 vfree(pr
->sq_skba
.arr
);
1374 ret
= ehea_rem_smrs(pr
);
1380 * The write_* functions store information in swqe which is used by
1381 * the hardware to calculate the ip/tcp/udp checksum
1384 static inline void write_ip_start_end(struct ehea_swqe
*swqe
,
1385 const struct sk_buff
*skb
)
1387 swqe
->ip_start
= skb_network_offset(skb
);
1388 swqe
->ip_end
= (u8
)(swqe
->ip_start
+ ip_hdrlen(skb
) - 1);
1391 static inline void write_tcp_offset_end(struct ehea_swqe
*swqe
,
1392 const struct sk_buff
*skb
)
1395 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct tcphdr
, check
));
1397 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1400 static inline void write_udp_offset_end(struct ehea_swqe
*swqe
,
1401 const struct sk_buff
*skb
)
1404 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct udphdr
, check
));
1406 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1410 static void write_swqe2_TSO(struct sk_buff
*skb
,
1411 struct ehea_swqe
*swqe
, u32 lkey
)
1413 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1414 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1415 int skb_data_size
= skb
->len
- skb
->data_len
;
1418 /* Packet is TCP with TSO enabled */
1419 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1420 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1421 /* copy only eth/ip/tcp headers to immediate data and
1422 * the rest of skb->data to sg1entry
1424 headersize
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1426 skb_data_size
= skb
->len
- skb
->data_len
;
1428 if (skb_data_size
>= headersize
) {
1429 /* copy immediate data */
1430 skb_copy_from_linear_data(skb
, imm_data
, headersize
);
1431 swqe
->immediate_data_length
= headersize
;
1433 if (skb_data_size
> headersize
) {
1434 /* set sg1entry data */
1435 sg1entry
->l_key
= lkey
;
1436 sg1entry
->len
= skb_data_size
- headersize
;
1438 ehea_map_vaddr(skb
->data
+ headersize
);
1439 swqe
->descriptors
++;
1442 ehea_error("cannot handle fragmented headers");
1445 static void write_swqe2_nonTSO(struct sk_buff
*skb
,
1446 struct ehea_swqe
*swqe
, u32 lkey
)
1448 int skb_data_size
= skb
->len
- skb
->data_len
;
1449 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1450 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1452 /* Packet is any nonTSO type
1454 * Copy as much as possible skb->data to immediate data and
1455 * the rest to sg1entry
1457 if (skb_data_size
>= SWQE2_MAX_IMM
) {
1458 /* copy immediate data */
1459 skb_copy_from_linear_data(skb
, imm_data
, SWQE2_MAX_IMM
);
1461 swqe
->immediate_data_length
= SWQE2_MAX_IMM
;
1463 if (skb_data_size
> SWQE2_MAX_IMM
) {
1464 /* copy sg1entry data */
1465 sg1entry
->l_key
= lkey
;
1466 sg1entry
->len
= skb_data_size
- SWQE2_MAX_IMM
;
1468 ehea_map_vaddr(skb
->data
+ SWQE2_MAX_IMM
);
1469 swqe
->descriptors
++;
1472 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1473 swqe
->immediate_data_length
= skb_data_size
;
1477 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1478 struct ehea_swqe
*swqe
, u32 lkey
)
1480 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1482 int nfrags
, sg1entry_contains_frag_data
, i
;
1484 nfrags
= skb_shinfo(skb
)->nr_frags
;
1485 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1486 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1487 swqe
->descriptors
= 0;
1488 sg1entry_contains_frag_data
= 0;
1490 if ((dev
->features
& NETIF_F_TSO
) && skb_shinfo(skb
)->gso_size
)
1491 write_swqe2_TSO(skb
, swqe
, lkey
);
1493 write_swqe2_nonTSO(skb
, swqe
, lkey
);
1495 /* write descriptors */
1497 if (swqe
->descriptors
== 0) {
1498 /* sg1entry not yet used */
1499 frag
= &skb_shinfo(skb
)->frags
[0];
1501 /* copy sg1entry data */
1502 sg1entry
->l_key
= lkey
;
1503 sg1entry
->len
= frag
->size
;
1505 ehea_map_vaddr(page_address(frag
->page
)
1506 + frag
->page_offset
);
1507 swqe
->descriptors
++;
1508 sg1entry_contains_frag_data
= 1;
1511 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1513 frag
= &skb_shinfo(skb
)->frags
[i
];
1514 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1516 sgentry
->l_key
= lkey
;
1517 sgentry
->len
= frag
->size
;
1519 ehea_map_vaddr(page_address(frag
->page
)
1520 + frag
->page_offset
);
1521 swqe
->descriptors
++;
1526 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1532 /* De/Register untagged packets */
1533 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1534 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1535 port
->logical_port_id
,
1536 reg_type
, port
->mac_addr
, 0, hcallid
);
1537 if (hret
!= H_SUCCESS
) {
1538 ehea_error("%sregistering bc address failed (tagged)",
1539 hcallid
== H_REG_BCMC
? "" : "de");
1544 /* De/Register VLAN packets */
1545 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1546 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1547 port
->logical_port_id
,
1548 reg_type
, port
->mac_addr
, 0, hcallid
);
1549 if (hret
!= H_SUCCESS
) {
1550 ehea_error("%sregistering bc address failed (vlan)",
1551 hcallid
== H_REG_BCMC
? "" : "de");
1558 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1560 struct ehea_port
*port
= netdev_priv(dev
);
1561 struct sockaddr
*mac_addr
= sa
;
1562 struct hcp_ehea_port_cb0
*cb0
;
1566 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1567 ret
= -EADDRNOTAVAIL
;
1571 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1573 ehea_error("no mem for cb0");
1578 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1580 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1582 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1583 port
->logical_port_id
, H_PORT_CB0
,
1584 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1585 if (hret
!= H_SUCCESS
) {
1590 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1592 /* Deregister old MAC in pHYP */
1593 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1597 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1599 /* Register new MAC in pHYP */
1600 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1611 static void ehea_promiscuous_error(u64 hret
, int enable
)
1613 if (hret
== H_AUTHORITY
)
1614 ehea_info("Hypervisor denied %sabling promiscuous mode",
1615 enable
== 1 ? "en" : "dis");
1617 ehea_error("failed %sabling promiscuous mode",
1618 enable
== 1 ? "en" : "dis");
1621 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1623 struct ehea_port
*port
= netdev_priv(dev
);
1624 struct hcp_ehea_port_cb7
*cb7
;
1627 if ((enable
&& port
->promisc
) || (!enable
&& !port
->promisc
))
1630 cb7
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
);
1632 ehea_error("no mem for cb7");
1636 /* Modify Pxs_DUCQPN in CB7 */
1637 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1639 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1640 port
->logical_port_id
,
1641 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1643 ehea_promiscuous_error(hret
, enable
);
1647 port
->promisc
= enable
;
1653 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1659 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1660 | EHEA_BCMC_UNTAGGED
;
1662 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1663 port
->logical_port_id
,
1664 reg_type
, mc_mac_addr
, 0, hcallid
);
1668 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1669 | EHEA_BCMC_VLANID_ALL
;
1671 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1672 port
->logical_port_id
,
1673 reg_type
, mc_mac_addr
, 0, hcallid
);
1678 static int ehea_drop_multicast_list(struct net_device
*dev
)
1680 struct ehea_port
*port
= netdev_priv(dev
);
1681 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1682 struct list_head
*pos
;
1683 struct list_head
*temp
;
1687 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1688 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1690 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1693 ehea_error("failed deregistering mcast MAC");
1703 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1705 struct ehea_port
*port
= netdev_priv(dev
);
1708 if (!port
->allmulti
) {
1710 /* Enable ALLMULTI */
1711 ehea_drop_multicast_list(dev
);
1712 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1716 ehea_error("failed enabling IFF_ALLMULTI");
1720 /* Disable ALLMULTI */
1721 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1725 ehea_error("failed disabling IFF_ALLMULTI");
1729 static void ehea_add_multicast_entry(struct ehea_port
* port
, u8
* mc_mac_addr
)
1731 struct ehea_mc_list
*ehea_mcl_entry
;
1734 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1735 if (!ehea_mcl_entry
) {
1736 ehea_error("no mem for mcl_entry");
1740 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1742 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1744 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1747 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1749 ehea_error("failed registering mcast MAC");
1750 kfree(ehea_mcl_entry
);
1754 static void ehea_set_multicast_list(struct net_device
*dev
)
1756 struct ehea_port
*port
= netdev_priv(dev
);
1757 struct dev_mc_list
*k_mcl_entry
;
1760 if (dev
->flags
& IFF_PROMISC
) {
1761 ehea_promiscuous(dev
, 1);
1764 ehea_promiscuous(dev
, 0);
1766 if (dev
->flags
& IFF_ALLMULTI
) {
1767 ehea_allmulti(dev
, 1);
1770 ehea_allmulti(dev
, 0);
1772 if (dev
->mc_count
) {
1773 ret
= ehea_drop_multicast_list(dev
);
1775 /* Dropping the current multicast list failed.
1776 * Enabling ALL_MULTI is the best we can do.
1778 ehea_allmulti(dev
, 1);
1781 if (dev
->mc_count
> port
->adapter
->max_mc_mac
) {
1782 ehea_info("Mcast registration limit reached (0x%lx). "
1784 port
->adapter
->max_mc_mac
);
1788 for (i
= 0, k_mcl_entry
= dev
->mc_list
;
1790 i
++, k_mcl_entry
= k_mcl_entry
->next
) {
1791 ehea_add_multicast_entry(port
, k_mcl_entry
->dmi_addr
);
1798 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1800 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1806 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
1807 struct ehea_swqe
*swqe
, u32 lkey
)
1809 if (skb
->protocol
== htons(ETH_P_IP
)) {
1810 const struct iphdr
*iph
= ip_hdr(skb
);
1813 swqe
->tx_control
|= EHEA_SWQE_CRC
1814 | EHEA_SWQE_IP_CHECKSUM
1815 | EHEA_SWQE_TCP_CHECKSUM
1816 | EHEA_SWQE_IMM_DATA_PRESENT
1817 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
1819 write_ip_start_end(swqe
, skb
);
1821 if (iph
->protocol
== IPPROTO_UDP
) {
1822 if ((iph
->frag_off
& IP_MF
)
1823 || (iph
->frag_off
& IP_OFFSET
))
1824 /* IP fragment, so don't change cs */
1825 swqe
->tx_control
&= ~EHEA_SWQE_TCP_CHECKSUM
;
1827 write_udp_offset_end(swqe
, skb
);
1828 } else if (iph
->protocol
== IPPROTO_TCP
) {
1829 write_tcp_offset_end(swqe
, skb
);
1832 /* icmp (big data) and ip segmentation packets (all other ip
1833 packets) do not require any special handling */
1836 /* Other Ethernet Protocol */
1837 swqe
->tx_control
|= EHEA_SWQE_CRC
1838 | EHEA_SWQE_IMM_DATA_PRESENT
1839 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
1842 write_swqe2_data(skb
, dev
, swqe
, lkey
);
1845 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
1846 struct ehea_swqe
*swqe
)
1848 int nfrags
= skb_shinfo(skb
)->nr_frags
;
1849 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
1853 if (skb
->protocol
== htons(ETH_P_IP
)) {
1854 const struct iphdr
*iph
= ip_hdr(skb
);
1857 write_ip_start_end(swqe
, skb
);
1859 if (iph
->protocol
== IPPROTO_TCP
) {
1860 swqe
->tx_control
|= EHEA_SWQE_CRC
1861 | EHEA_SWQE_IP_CHECKSUM
1862 | EHEA_SWQE_TCP_CHECKSUM
1863 | EHEA_SWQE_IMM_DATA_PRESENT
;
1865 write_tcp_offset_end(swqe
, skb
);
1867 } else if (iph
->protocol
== IPPROTO_UDP
) {
1868 if ((iph
->frag_off
& IP_MF
)
1869 || (iph
->frag_off
& IP_OFFSET
))
1870 /* IP fragment, so don't change cs */
1871 swqe
->tx_control
|= EHEA_SWQE_CRC
1872 | EHEA_SWQE_IMM_DATA_PRESENT
;
1874 swqe
->tx_control
|= EHEA_SWQE_CRC
1875 | EHEA_SWQE_IP_CHECKSUM
1876 | EHEA_SWQE_TCP_CHECKSUM
1877 | EHEA_SWQE_IMM_DATA_PRESENT
;
1879 write_udp_offset_end(swqe
, skb
);
1882 /* icmp (big data) and
1883 ip segmentation packets (all other ip packets) */
1884 swqe
->tx_control
|= EHEA_SWQE_CRC
1885 | EHEA_SWQE_IP_CHECKSUM
1886 | EHEA_SWQE_IMM_DATA_PRESENT
;
1889 /* Other Ethernet Protocol */
1890 swqe
->tx_control
|= EHEA_SWQE_CRC
| EHEA_SWQE_IMM_DATA_PRESENT
;
1892 /* copy (immediate) data */
1894 /* data is in a single piece */
1895 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
1897 /* first copy data from the skb->data buffer ... */
1898 skb_copy_from_linear_data(skb
, imm_data
,
1899 skb
->len
- skb
->data_len
);
1900 imm_data
+= skb
->len
- skb
->data_len
;
1902 /* ... then copy data from the fragments */
1903 for (i
= 0; i
< nfrags
; i
++) {
1904 frag
= &skb_shinfo(skb
)->frags
[i
];
1906 page_address(frag
->page
) + frag
->page_offset
,
1908 imm_data
+= frag
->size
;
1911 swqe
->immediate_data_length
= skb
->len
;
1915 static inline int ehea_hash_skb(struct sk_buff
*skb
, int num_qps
)
1920 if ((skb
->protocol
== htons(ETH_P_IP
)) &&
1921 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)) {
1922 tcp
= (struct tcphdr
*)(skb_network_header(skb
) + (ip_hdr(skb
)->ihl
* 4));
1923 tmp
= (tcp
->source
+ (tcp
->dest
<< 16)) % 31;
1924 tmp
+= ip_hdr(skb
)->daddr
% 31;
1925 return tmp
% num_qps
;
1931 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1933 struct ehea_port
*port
= netdev_priv(dev
);
1934 struct ehea_swqe
*swqe
;
1935 unsigned long flags
;
1938 struct ehea_port_res
*pr
;
1940 pr
= &port
->port_res
[ehea_hash_skb(skb
, port
->num_tx_qps
)];
1942 if (!spin_trylock(&pr
->xmit_lock
))
1943 return NETDEV_TX_BUSY
;
1945 if (pr
->queue_stopped
) {
1946 spin_unlock(&pr
->xmit_lock
);
1947 return NETDEV_TX_BUSY
;
1950 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
1951 memset(swqe
, 0, SWQE_HEADER_SIZE
);
1952 atomic_dec(&pr
->swqe_avail
);
1954 if (skb
->len
<= SWQE3_MAX_IMM
) {
1955 u32 sig_iv
= port
->sig_comp_iv
;
1956 u32 swqe_num
= pr
->swqe_id_counter
;
1957 ehea_xmit3(skb
, dev
, swqe
);
1958 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
1959 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
1960 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
1961 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
1963 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
1964 pr
->swqe_ll_count
= 0;
1966 pr
->swqe_ll_count
+= 1;
1969 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
1970 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
1971 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
1972 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
1973 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
1975 pr
->sq_skba
.index
++;
1976 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
1978 lkey
= pr
->send_mr
.lkey
;
1979 ehea_xmit2(skb
, dev
, swqe
, lkey
);
1980 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
1982 pr
->swqe_id_counter
+= 1;
1984 if (port
->vgrp
&& vlan_tx_tag_present(skb
)) {
1985 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
1986 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
1989 if (netif_msg_tx_queued(port
)) {
1990 ehea_info("post swqe on QP %d", pr
->qp
->init_attr
.qp_nr
);
1991 ehea_dump(swqe
, 512, "swqe");
1994 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
1995 netif_stop_queue(dev
);
1996 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
1999 ehea_post_swqe(pr
->qp
, swqe
);
2001 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2002 spin_lock_irqsave(&pr
->netif_queue
, flags
);
2003 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2004 pr
->p_stats
.queue_stopped
++;
2005 netif_stop_queue(dev
);
2006 pr
->queue_stopped
= 1;
2008 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
2010 dev
->trans_start
= jiffies
;
2011 spin_unlock(&pr
->xmit_lock
);
2013 return NETDEV_TX_OK
;
2016 static void ehea_vlan_rx_register(struct net_device
*dev
,
2017 struct vlan_group
*grp
)
2019 struct ehea_port
*port
= netdev_priv(dev
);
2020 struct ehea_adapter
*adapter
= port
->adapter
;
2021 struct hcp_ehea_port_cb1
*cb1
;
2026 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2028 ehea_error("no mem for cb1");
2032 memset(cb1
->vlan_filter
, 0, sizeof(cb1
->vlan_filter
));
2034 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2035 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2036 if (hret
!= H_SUCCESS
)
2037 ehea_error("modify_ehea_port failed");
2044 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2046 struct ehea_port
*port
= netdev_priv(dev
);
2047 struct ehea_adapter
*adapter
= port
->adapter
;
2048 struct hcp_ehea_port_cb1
*cb1
;
2052 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2054 ehea_error("no mem for cb1");
2058 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2059 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2060 if (hret
!= H_SUCCESS
) {
2061 ehea_error("query_ehea_port failed");
2066 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2068 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2069 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2070 if (hret
!= H_SUCCESS
)
2071 ehea_error("modify_ehea_port failed");
2077 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2079 struct ehea_port
*port
= netdev_priv(dev
);
2080 struct ehea_adapter
*adapter
= port
->adapter
;
2081 struct hcp_ehea_port_cb1
*cb1
;
2085 vlan_group_set_device(port
->vgrp
, vid
, NULL
);
2087 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2089 ehea_error("no mem for cb1");
2093 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2094 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2095 if (hret
!= H_SUCCESS
) {
2096 ehea_error("query_ehea_port failed");
2101 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2103 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2104 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2105 if (hret
!= H_SUCCESS
)
2106 ehea_error("modify_ehea_port failed");
2112 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2118 struct hcp_modify_qp_cb0
* cb0
;
2120 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2126 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2127 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2128 if (hret
!= H_SUCCESS
) {
2129 ehea_error("query_ehea_qp failed (1)");
2133 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2134 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2135 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2136 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2137 if (hret
!= H_SUCCESS
) {
2138 ehea_error("modify_ehea_qp failed (1)");
2142 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2143 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2144 if (hret
!= H_SUCCESS
) {
2145 ehea_error("query_ehea_qp failed (2)");
2149 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2150 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2151 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2152 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2153 if (hret
!= H_SUCCESS
) {
2154 ehea_error("modify_ehea_qp failed (2)");
2158 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2159 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2160 if (hret
!= H_SUCCESS
) {
2161 ehea_error("query_ehea_qp failed (3)");
2165 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2166 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2167 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2168 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2169 if (hret
!= H_SUCCESS
) {
2170 ehea_error("modify_ehea_qp failed (3)");
2174 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2175 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2176 if (hret
!= H_SUCCESS
) {
2177 ehea_error("query_ehea_qp failed (4)");
2187 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
,
2191 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2192 enum ehea_eq_type eq_type
= EHEA_EQ
;
2194 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2195 EHEA_MAX_ENTRIES_EQ
, 1);
2198 ehea_error("ehea_create_eq failed (qp_eq)");
2202 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2203 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2204 pr_cfg
.max_entries_sq
= sq_entries
;
2205 pr_cfg
.max_entries_rq1
= rq1_entries
;
2206 pr_cfg
.max_entries_rq2
= rq2_entries
;
2207 pr_cfg
.max_entries_rq3
= rq3_entries
;
2209 pr_cfg_small_rx
.max_entries_rcq
= 1;
2210 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2211 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2212 pr_cfg_small_rx
.max_entries_rq1
= 1;
2213 pr_cfg_small_rx
.max_entries_rq2
= 1;
2214 pr_cfg_small_rx
.max_entries_rq3
= 1;
2216 for (i
= 0; i
< def_qps
; i
++) {
2217 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2221 for (i
= def_qps
; i
< def_qps
+ add_tx_qps
; i
++) {
2222 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2223 &pr_cfg_small_rx
, i
);
2232 ehea_clean_portres(port
, &port
->port_res
[i
]);
2235 ehea_destroy_eq(port
->qp_eq
);
2239 static int ehea_clean_all_portres(struct ehea_port
*port
)
2244 for(i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2245 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2247 ret
|= ehea_destroy_eq(port
->qp_eq
);
2252 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2254 if (adapter
->active_ports
)
2257 ehea_rem_mr(&adapter
->mr
);
2260 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2262 if (adapter
->active_ports
)
2265 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2268 static int ehea_up(struct net_device
*dev
)
2271 struct ehea_port
*port
= netdev_priv(dev
);
2273 if (port
->state
== EHEA_PORT_UP
)
2276 ret
= ehea_port_res_setup(port
, port
->num_def_qps
,
2277 port
->num_add_tx_qps
);
2279 ehea_error("port_res_failed");
2283 /* Set default QP for this port */
2284 ret
= ehea_configure_port(port
);
2286 ehea_error("ehea_configure_port failed. ret:%d", ret
);
2290 ret
= ehea_reg_interrupts(dev
);
2292 ehea_error("reg_interrupts failed. ret:%d", ret
);
2296 for(i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2297 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2299 ehea_error("activate_qp failed");
2304 for(i
= 0; i
< port
->num_def_qps
; i
++) {
2305 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2307 ehea_error("out_free_irqs");
2313 port
->state
= EHEA_PORT_UP
;
2317 ehea_free_interrupts(dev
);
2320 ehea_clean_all_portres(port
);
2323 ehea_info("Failed starting %s. ret=%i", dev
->name
, ret
);
2328 static void port_napi_disable(struct ehea_port
*port
)
2332 for (i
= 0; i
< port
->num_def_qps
; i
++)
2333 napi_disable(&port
->port_res
[i
].napi
);
2336 static void port_napi_enable(struct ehea_port
*port
)
2340 for (i
= 0; i
< port
->num_def_qps
; i
++)
2341 napi_enable(&port
->port_res
[i
].napi
);
2344 static int ehea_open(struct net_device
*dev
)
2347 struct ehea_port
*port
= netdev_priv(dev
);
2349 down(&port
->port_lock
);
2351 if (netif_msg_ifup(port
))
2352 ehea_info("enabling port %s", dev
->name
);
2356 port_napi_enable(port
);
2357 netif_start_queue(dev
);
2360 up(&port
->port_lock
);
2365 static int ehea_down(struct net_device
*dev
)
2368 struct ehea_port
*port
= netdev_priv(dev
);
2370 if (port
->state
== EHEA_PORT_DOWN
)
2373 ehea_drop_multicast_list(dev
);
2374 ehea_free_interrupts(dev
);
2376 port_napi_disable(port
);
2378 port
->state
= EHEA_PORT_DOWN
;
2380 ret
= ehea_clean_all_portres(port
);
2382 ehea_info("Failed freeing resources for %s. ret=%i",
2388 static int ehea_stop(struct net_device
*dev
)
2391 struct ehea_port
*port
= netdev_priv(dev
);
2393 if (netif_msg_ifdown(port
))
2394 ehea_info("disabling port %s", dev
->name
);
2396 flush_scheduled_work();
2397 down(&port
->port_lock
);
2398 netif_stop_queue(dev
);
2399 ret
= ehea_down(dev
);
2400 up(&port
->port_lock
);
2404 void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2406 struct ehea_qp qp
= *orig_qp
;
2407 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2408 struct ehea_swqe
*swqe
;
2412 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2413 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2414 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2418 int ehea_stop_qps(struct net_device
*dev
)
2420 struct ehea_port
*port
= netdev_priv(dev
);
2421 struct ehea_adapter
*adapter
= port
->adapter
;
2422 struct hcp_modify_qp_cb0
* cb0
;
2430 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2436 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2437 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2438 struct ehea_qp
*qp
= pr
->qp
;
2440 /* Purge send queue */
2443 /* Disable queue pair */
2444 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2445 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2447 if (hret
!= H_SUCCESS
) {
2448 ehea_error("query_ehea_qp failed (1)");
2452 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2453 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2455 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2456 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2458 &dummy64
, &dummy16
, &dummy16
);
2459 if (hret
!= H_SUCCESS
) {
2460 ehea_error("modify_ehea_qp failed (1)");
2464 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2465 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2467 if (hret
!= H_SUCCESS
) {
2468 ehea_error("query_ehea_qp failed (2)");
2472 /* deregister shared memory regions */
2473 dret
= ehea_rem_smrs(pr
);
2475 ehea_error("unreg shared memory region failed");
2487 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
* pr
)
2489 struct ehea_qp qp
= *orig_qp
;
2490 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2491 struct ehea_rwqe
*rwqe
;
2492 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2493 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2494 struct sk_buff
*skb
;
2495 u32 lkey
= pr
->recv_mr
.lkey
;
2501 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2502 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2503 rwqe
->sg_list
[0].l_key
= lkey
;
2504 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2505 skb
= skba_rq2
[index
];
2507 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2510 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2511 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2512 rwqe
->sg_list
[0].l_key
= lkey
;
2513 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2514 skb
= skba_rq3
[index
];
2516 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2520 int ehea_restart_qps(struct net_device
*dev
)
2522 struct ehea_port
*port
= netdev_priv(dev
);
2523 struct ehea_adapter
*adapter
= port
->adapter
;
2527 struct hcp_modify_qp_cb0
* cb0
;
2532 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2538 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2539 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2540 struct ehea_qp
*qp
= pr
->qp
;
2542 ret
= ehea_gen_smrs(pr
);
2544 ehea_error("creation of shared memory regions failed");
2548 ehea_update_rqs(qp
, pr
);
2550 /* Enable queue pair */
2551 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2552 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2554 if (hret
!= H_SUCCESS
) {
2555 ehea_error("query_ehea_qp failed (1)");
2559 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2560 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2562 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2563 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2565 &dummy64
, &dummy16
, &dummy16
);
2566 if (hret
!= H_SUCCESS
) {
2567 ehea_error("modify_ehea_qp failed (1)");
2571 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2572 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2574 if (hret
!= H_SUCCESS
) {
2575 ehea_error("query_ehea_qp failed (2)");
2579 /* refill entire queue */
2580 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2581 ehea_refill_rq2(pr
, 0);
2582 ehea_refill_rq3(pr
, 0);
2590 static void ehea_reset_port(struct work_struct
*work
)
2593 struct ehea_port
*port
=
2594 container_of(work
, struct ehea_port
, reset_task
);
2595 struct net_device
*dev
= port
->netdev
;
2598 down(&port
->port_lock
);
2599 netif_stop_queue(dev
);
2601 port_napi_disable(port
);
2609 ehea_set_multicast_list(dev
);
2611 if (netif_msg_timer(port
))
2612 ehea_info("Device %s resetted successfully", dev
->name
);
2614 port_napi_enable(port
);
2616 netif_wake_queue(dev
);
2618 up(&port
->port_lock
);
2622 static void ehea_rereg_mrs(struct work_struct
*work
)
2625 struct ehea_adapter
*adapter
;
2627 down(&dlpar_mem_lock
);
2628 ehea_info("LPAR memory enlarged - re-initializing driver");
2630 list_for_each_entry(adapter
, &adapter_list
, list
)
2631 if (adapter
->active_ports
) {
2632 /* Shutdown all ports */
2633 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2634 struct ehea_port
*port
= adapter
->port
[i
];
2637 struct net_device
*dev
= port
->netdev
;
2639 if (dev
->flags
& IFF_UP
) {
2640 down(&port
->port_lock
);
2641 netif_stop_queue(dev
);
2642 ret
= ehea_stop_qps(dev
);
2644 up(&port
->port_lock
);
2647 port_napi_disable(port
);
2648 up(&port
->port_lock
);
2653 /* Unregister old memory region */
2654 ret
= ehea_rem_mr(&adapter
->mr
);
2656 ehea_error("unregister MR failed - driver"
2662 ehea_destroy_busmap();
2663 ret
= ehea_create_busmap();
2665 ehea_error("creating ehea busmap failed");
2669 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2671 list_for_each_entry(adapter
, &adapter_list
, list
)
2672 if (adapter
->active_ports
) {
2673 /* Register new memory region */
2674 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2676 ehea_error("register MR failed - driver"
2681 /* Restart all ports */
2682 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2683 struct ehea_port
*port
= adapter
->port
[i
];
2686 struct net_device
*dev
= port
->netdev
;
2688 if (dev
->flags
& IFF_UP
) {
2689 down(&port
->port_lock
);
2690 port_napi_enable(port
);
2691 ret
= ehea_restart_qps(dev
);
2693 netif_wake_queue(dev
);
2694 up(&port
->port_lock
);
2699 up(&dlpar_mem_lock
);
2700 ehea_info("re-initializing driver complete");
2705 static void ehea_tx_watchdog(struct net_device
*dev
)
2707 struct ehea_port
*port
= netdev_priv(dev
);
2709 if (netif_carrier_ok(dev
) &&
2710 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2711 schedule_work(&port
->reset_task
);
2714 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2716 struct hcp_query_ehea
*cb
;
2720 cb
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2726 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2728 if (hret
!= H_SUCCESS
) {
2733 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2742 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2744 struct hcp_ehea_port_cb4
*cb4
;
2750 /* (Try to) enable *jumbo frames */
2751 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2753 ehea_error("no mem for cb4");
2757 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2758 port
->logical_port_id
,
2760 H_PORT_CB4_JUMBO
, cb4
);
2761 if (hret
== H_SUCCESS
) {
2762 if (cb4
->jumbo_frame
)
2765 cb4
->jumbo_frame
= 1;
2766 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2773 if (hret
== H_SUCCESS
)
2785 static ssize_t
ehea_show_port_id(struct device
*dev
,
2786 struct device_attribute
*attr
, char *buf
)
2788 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2789 return sprintf(buf
, "%d", port
->logical_port_id
);
2792 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2795 static void __devinit
logical_port_release(struct device
*dev
)
2797 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2798 of_node_put(port
->ofdev
.node
);
2801 static int ehea_driver_sysfs_add(struct device
*dev
,
2802 struct device_driver
*driver
)
2806 ret
= sysfs_create_link(&driver
->kobj
, &dev
->kobj
,
2807 kobject_name(&dev
->kobj
));
2809 ret
= sysfs_create_link(&dev
->kobj
, &driver
->kobj
,
2812 sysfs_remove_link(&driver
->kobj
,
2813 kobject_name(&dev
->kobj
));
2818 static void ehea_driver_sysfs_remove(struct device
*dev
,
2819 struct device_driver
*driver
)
2821 struct device_driver
*drv
= driver
;
2824 sysfs_remove_link(&drv
->kobj
, kobject_name(&dev
->kobj
));
2825 sysfs_remove_link(&dev
->kobj
, "driver");
2829 static struct device
*ehea_register_port(struct ehea_port
*port
,
2830 struct device_node
*dn
)
2834 port
->ofdev
.node
= of_node_get(dn
);
2835 port
->ofdev
.dev
.parent
= &port
->adapter
->ebus_dev
->ofdev
.dev
;
2836 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2838 sprintf(port
->ofdev
.dev
.bus_id
, "port%d", port_name_cnt
++);
2839 port
->ofdev
.dev
.release
= logical_port_release
;
2841 ret
= of_device_register(&port
->ofdev
);
2843 ehea_error("failed to register device. ret=%d", ret
);
2847 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2849 ehea_error("failed to register attributes, ret=%d", ret
);
2850 goto out_unreg_of_dev
;
2853 ret
= ehea_driver_sysfs_add(&port
->ofdev
.dev
, &ehea_driver
.driver
);
2855 ehea_error("failed to register sysfs driver link");
2856 goto out_rem_dev_file
;
2859 return &port
->ofdev
.dev
;
2862 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2864 of_device_unregister(&port
->ofdev
);
2869 static void ehea_unregister_port(struct ehea_port
*port
)
2871 ehea_driver_sysfs_remove(&port
->ofdev
.dev
, &ehea_driver
.driver
);
2872 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2873 of_device_unregister(&port
->ofdev
);
2876 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2877 u32 logical_port_id
,
2878 struct device_node
*dn
)
2881 struct net_device
*dev
;
2882 struct ehea_port
*port
;
2883 struct device
*port_dev
;
2886 /* allocate memory for the port structures */
2887 dev
= alloc_etherdev(sizeof(struct ehea_port
));
2890 ehea_error("no mem for net_device");
2895 port
= netdev_priv(dev
);
2897 sema_init(&port
->port_lock
, 1);
2898 port
->state
= EHEA_PORT_DOWN
;
2899 port
->sig_comp_iv
= sq_entries
/ 10;
2901 port
->adapter
= adapter
;
2903 port
->logical_port_id
= logical_port_id
;
2905 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
2907 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
2908 if (!port
->mc_list
) {
2910 goto out_free_ethdev
;
2913 INIT_LIST_HEAD(&port
->mc_list
->list
);
2915 ret
= ehea_sense_port_attr(port
);
2917 goto out_free_mc_list
;
2919 port_dev
= ehea_register_port(port
, dn
);
2921 goto out_free_mc_list
;
2923 SET_NETDEV_DEV(dev
, port_dev
);
2925 /* initialize net_device structure */
2926 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
2928 dev
->open
= ehea_open
;
2929 #ifdef CONFIG_NET_POLL_CONTROLLER
2930 dev
->poll_controller
= ehea_netpoll
;
2932 dev
->stop
= ehea_stop
;
2933 dev
->hard_start_xmit
= ehea_start_xmit
;
2934 dev
->get_stats
= ehea_get_stats
;
2935 dev
->set_multicast_list
= ehea_set_multicast_list
;
2936 dev
->set_mac_address
= ehea_set_mac_addr
;
2937 dev
->change_mtu
= ehea_change_mtu
;
2938 dev
->vlan_rx_register
= ehea_vlan_rx_register
;
2939 dev
->vlan_rx_add_vid
= ehea_vlan_rx_add_vid
;
2940 dev
->vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
;
2941 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
2942 | NETIF_F_HIGHDMA
| NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_TX
2943 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
2945 dev
->tx_timeout
= &ehea_tx_watchdog
;
2946 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
2948 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
2950 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2953 goto out_unreg_port
;
2956 ehea_set_ethtool_ops(dev
);
2958 ret
= register_netdev(dev
);
2960 ehea_error("register_netdev failed. ret=%d", ret
);
2964 port
->lro_max_aggr
= lro_max_aggr
;
2966 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
2968 ehea_error("failed determining jumbo frame status for %s",
2969 port
->netdev
->name
);
2971 ehea_info("%s: Jumbo frames are %sabled", dev
->name
,
2972 jumbo
== 1 ? "en" : "dis");
2974 adapter
->active_ports
++;
2979 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2982 ehea_unregister_port(port
);
2985 kfree(port
->mc_list
);
2991 ehea_error("setting up logical port with id=%d failed, ret=%d",
2992 logical_port_id
, ret
);
2996 static void ehea_shutdown_single_port(struct ehea_port
*port
)
2998 unregister_netdev(port
->netdev
);
2999 ehea_unregister_port(port
);
3000 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
3001 kfree(port
->mc_list
);
3002 free_netdev(port
->netdev
);
3003 port
->adapter
->active_ports
--;
3006 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3008 struct device_node
*lhea_dn
;
3009 struct device_node
*eth_dn
= NULL
;
3011 const u32
*dn_log_port_id
;
3014 lhea_dn
= adapter
->ebus_dev
->ofdev
.node
;
3015 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3017 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3019 if (!dn_log_port_id
) {
3020 ehea_error("bad device node: eth_dn name=%s",
3025 if (ehea_add_adapter_mr(adapter
)) {
3026 ehea_error("creating MR failed");
3027 of_node_put(eth_dn
);
3031 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3034 if (adapter
->port
[i
])
3035 ehea_info("%s -> logical port id #%d",
3036 adapter
->port
[i
]->netdev
->name
,
3039 ehea_remove_adapter_mr(adapter
);
3047 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3048 u32 logical_port_id
)
3050 struct device_node
*lhea_dn
;
3051 struct device_node
*eth_dn
= NULL
;
3052 const u32
*dn_log_port_id
;
3054 lhea_dn
= adapter
->ebus_dev
->ofdev
.node
;
3055 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3057 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3060 if (*dn_log_port_id
== logical_port_id
)
3067 static ssize_t
ehea_probe_port(struct device
*dev
,
3068 struct device_attribute
*attr
,
3069 const char *buf
, size_t count
)
3071 struct ehea_adapter
*adapter
= dev
->driver_data
;
3072 struct ehea_port
*port
;
3073 struct device_node
*eth_dn
= NULL
;
3076 u32 logical_port_id
;
3078 sscanf(buf
, "%d", &logical_port_id
);
3080 port
= ehea_get_port(adapter
, logical_port_id
);
3083 ehea_info("adding port with logical port id=%d failed. port "
3084 "already configured as %s.", logical_port_id
,
3085 port
->netdev
->name
);
3089 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3092 ehea_info("no logical port with id %d found", logical_port_id
);
3096 if (ehea_add_adapter_mr(adapter
)) {
3097 ehea_error("creating MR failed");
3101 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3103 of_node_put(eth_dn
);
3106 for (i
=0; i
< EHEA_MAX_PORTS
; i
++)
3107 if (!adapter
->port
[i
]) {
3108 adapter
->port
[i
] = port
;
3112 ehea_info("added %s (logical port id=%d)", port
->netdev
->name
,
3115 ehea_remove_adapter_mr(adapter
);
3119 return (ssize_t
) count
;
3122 static ssize_t
ehea_remove_port(struct device
*dev
,
3123 struct device_attribute
*attr
,
3124 const char *buf
, size_t count
)
3126 struct ehea_adapter
*adapter
= dev
->driver_data
;
3127 struct ehea_port
*port
;
3129 u32 logical_port_id
;
3131 sscanf(buf
, "%d", &logical_port_id
);
3133 port
= ehea_get_port(adapter
, logical_port_id
);
3136 ehea_info("removed %s (logical port id=%d)", port
->netdev
->name
,
3139 ehea_shutdown_single_port(port
);
3141 for (i
=0; i
< EHEA_MAX_PORTS
; i
++)
3142 if (adapter
->port
[i
] == port
) {
3143 adapter
->port
[i
] = NULL
;
3147 ehea_error("removing port with logical port id=%d failed. port "
3148 "not configured.", logical_port_id
);
3152 ehea_remove_adapter_mr(adapter
);
3154 return (ssize_t
) count
;
3157 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3158 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3160 int ehea_create_device_sysfs(struct ibmebus_dev
*dev
)
3162 int ret
= device_create_file(&dev
->ofdev
.dev
, &dev_attr_probe_port
);
3166 ret
= device_create_file(&dev
->ofdev
.dev
, &dev_attr_remove_port
);
3171 void ehea_remove_device_sysfs(struct ibmebus_dev
*dev
)
3173 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_probe_port
);
3174 device_remove_file(&dev
->ofdev
.dev
, &dev_attr_remove_port
);
3177 static int __devinit
ehea_probe_adapter(struct ibmebus_dev
*dev
,
3178 const struct of_device_id
*id
)
3180 struct ehea_adapter
*adapter
;
3181 const u64
*adapter_handle
;
3184 if (!dev
|| !dev
->ofdev
.node
) {
3185 ehea_error("Invalid ibmebus device probed");
3189 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3192 dev_err(&dev
->ofdev
.dev
, "no mem for ehea_adapter\n");
3196 list_add(&adapter
->list
, &adapter_list
);
3198 adapter
->ebus_dev
= dev
;
3200 adapter_handle
= of_get_property(dev
->ofdev
.node
, "ibm,hea-handle",
3203 adapter
->handle
= *adapter_handle
;
3205 if (!adapter
->handle
) {
3206 dev_err(&dev
->ofdev
.dev
, "failed getting handle for adapter"
3207 " '%s'\n", dev
->ofdev
.node
->full_name
);
3212 adapter
->pd
= EHEA_PD_ID
;
3214 dev
->ofdev
.dev
.driver_data
= adapter
;
3217 /* initialize adapter and ports */
3218 /* get adapter properties */
3219 ret
= ehea_sense_adapter_attr(adapter
);
3221 dev_err(&dev
->ofdev
.dev
, "sense_adapter_attr failed: %d", ret
);
3225 adapter
->neq
= ehea_create_eq(adapter
,
3226 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3227 if (!adapter
->neq
) {
3229 dev_err(&dev
->ofdev
.dev
, "NEQ creation failed");
3233 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3234 (unsigned long)adapter
);
3236 ret
= ibmebus_request_irq(NULL
, adapter
->neq
->attr
.ist1
,
3237 ehea_interrupt_neq
, IRQF_DISABLED
,
3238 "ehea_neq", adapter
);
3240 dev_err(&dev
->ofdev
.dev
, "requesting NEQ IRQ failed");
3244 ret
= ehea_create_device_sysfs(dev
);
3248 ret
= ehea_setup_ports(adapter
);
3250 dev_err(&dev
->ofdev
.dev
, "setup_ports failed");
3251 goto out_rem_dev_sysfs
;
3258 ehea_remove_device_sysfs(dev
);
3261 ibmebus_free_irq(NULL
, adapter
->neq
->attr
.ist1
, adapter
);
3264 ehea_destroy_eq(adapter
->neq
);
3272 static int __devexit
ehea_remove(struct ibmebus_dev
*dev
)
3274 struct ehea_adapter
*adapter
= dev
->ofdev
.dev
.driver_data
;
3277 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3278 if (adapter
->port
[i
]) {
3279 ehea_shutdown_single_port(adapter
->port
[i
]);
3280 adapter
->port
[i
] = NULL
;
3283 ehea_remove_device_sysfs(dev
);
3285 flush_scheduled_work();
3287 ibmebus_free_irq(NULL
, adapter
->neq
->attr
.ist1
, adapter
);
3288 tasklet_kill(&adapter
->neq_tasklet
);
3290 ehea_destroy_eq(adapter
->neq
);
3291 ehea_remove_adapter_mr(adapter
);
3292 list_del(&adapter
->list
);
3299 static int check_module_parm(void)
3303 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3304 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3305 ehea_info("Bad parameter: rq1_entries");
3308 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3309 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3310 ehea_info("Bad parameter: rq2_entries");
3313 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3314 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3315 ehea_info("Bad parameter: rq3_entries");
3318 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3319 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3320 ehea_info("Bad parameter: sq_entries");
3327 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3330 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3333 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3334 ehea_show_capabilities
, NULL
);
3336 int __init
ehea_module_init(void)
3340 printk(KERN_INFO
"IBM eHEA ethernet device driver (Release %s)\n",
3344 INIT_WORK(&ehea_rereg_mr_task
, ehea_rereg_mrs
);
3345 sema_init(&dlpar_mem_lock
, 1);
3347 ret
= check_module_parm();
3351 ret
= ehea_create_busmap();
3355 ret
= ibmebus_register_driver(&ehea_driver
);
3357 ehea_error("failed registering eHEA device driver on ebus");
3361 ret
= driver_create_file(&ehea_driver
.driver
,
3362 &driver_attr_capabilities
);
3364 ehea_error("failed to register capabilities attribute, ret=%d",
3366 ibmebus_unregister_driver(&ehea_driver
);
3374 static void __exit
ehea_module_exit(void)
3376 flush_scheduled_work();
3377 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3378 ibmebus_unregister_driver(&ehea_driver
);
3379 ehea_destroy_busmap();
3382 module_init(ehea_module_init
);
3383 module_exit(ehea_module_exit
);