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>
38 #include <asm/kexec.h>
44 #include "ehea_phyp.h"
47 MODULE_LICENSE("GPL");
48 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
49 MODULE_DESCRIPTION("IBM eServer HEA Driver");
50 MODULE_VERSION(DRV_VERSION
);
53 static int msg_level
= -1;
54 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
55 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
56 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
57 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
60 static int lro_max_aggr
= EHEA_LRO_MAX_AGGR
;
61 static int num_tx_qps
= EHEA_NUM_TX_QP
;
62 static int prop_carrier_state
;
64 module_param(msg_level
, int, 0);
65 module_param(rq1_entries
, int, 0);
66 module_param(rq2_entries
, int, 0);
67 module_param(rq3_entries
, int, 0);
68 module_param(sq_entries
, int, 0);
69 module_param(prop_carrier_state
, int, 0);
70 module_param(use_mcs
, int, 0);
71 module_param(use_lro
, int, 0);
72 module_param(lro_max_aggr
, int, 0);
73 module_param(num_tx_qps
, int, 0);
75 MODULE_PARM_DESC(num_tx_qps
, "Number of TX-QPS");
76 MODULE_PARM_DESC(msg_level
, "msg_level");
77 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
78 "port to stack. 1:yes, 0:no. Default = 0 ");
79 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
80 "[2^x - 1], x = [6..14]. Default = "
81 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
82 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
85 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
88 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
91 MODULE_PARM_DESC(use_mcs
, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
93 MODULE_PARM_DESC(lro_max_aggr
, " LRO: Max packets to be aggregated. Default = "
94 __MODULE_STRING(EHEA_LRO_MAX_AGGR
));
95 MODULE_PARM_DESC(use_lro
, " Large Receive Offload, 1: enable, 0: disable, "
98 static int port_name_cnt
;
99 static LIST_HEAD(adapter_list
);
100 u64 ehea_driver_flags
;
101 struct work_struct ehea_rereg_mr_task
;
102 struct semaphore dlpar_mem_lock
;
103 struct ehea_fw_handle_array ehea_fw_handles
;
104 struct ehea_bcmc_reg_array ehea_bcmc_regs
;
107 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
108 const struct of_device_id
*id
);
110 static int __devexit
ehea_remove(struct of_device
*dev
);
112 static struct of_device_id ehea_device_table
[] = {
115 .compatible
= "IBM,lhea",
120 static struct of_platform_driver ehea_driver
= {
122 .match_table
= ehea_device_table
,
123 .probe
= ehea_probe_adapter
,
124 .remove
= ehea_remove
,
127 void ehea_dump(void *adr
, int len
, char *msg
)
130 unsigned char *deb
= adr
;
131 for (x
= 0; x
< len
; x
+= 16) {
132 printk(DRV_NAME
" %s adr=%p ofs=%04x %016lx %016lx\n", msg
,
133 deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
138 static void ehea_update_firmware_handles(void)
140 struct ehea_fw_handle_entry
*arr
= NULL
;
141 struct ehea_adapter
*adapter
;
142 int num_adapters
= 0;
146 int num_fw_handles
, k
, l
;
148 /* Determine number of handles */
149 list_for_each_entry(adapter
, &adapter_list
, list
) {
152 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
153 struct ehea_port
*port
= adapter
->port
[k
];
155 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
159 num_portres
+= port
->num_def_qps
+ port
->num_add_tx_qps
;
163 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
164 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
165 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
167 if (num_fw_handles
) {
168 arr
= kzalloc(num_fw_handles
* sizeof(*arr
), GFP_KERNEL
);
170 return; /* Keep the existing array */
174 list_for_each_entry(adapter
, &adapter_list
, list
) {
175 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
176 struct ehea_port
*port
= adapter
->port
[k
];
178 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
182 l
< port
->num_def_qps
+ port
->num_add_tx_qps
;
184 struct ehea_port_res
*pr
= &port
->port_res
[l
];
186 arr
[i
].adh
= adapter
->handle
;
187 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
188 arr
[i
].adh
= adapter
->handle
;
189 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
190 arr
[i
].adh
= adapter
->handle
;
191 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
192 arr
[i
].adh
= adapter
->handle
;
193 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
194 arr
[i
].adh
= adapter
->handle
;
195 arr
[i
++].fwh
= pr
->send_mr
.handle
;
196 arr
[i
].adh
= adapter
->handle
;
197 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
199 arr
[i
].adh
= adapter
->handle
;
200 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
203 arr
[i
].adh
= adapter
->handle
;
204 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
206 if (adapter
->mr
.handle
) {
207 arr
[i
].adh
= adapter
->handle
;
208 arr
[i
++].fwh
= adapter
->mr
.handle
;
213 kfree(ehea_fw_handles
.arr
);
214 ehea_fw_handles
.arr
= arr
;
215 ehea_fw_handles
.num_entries
= i
;
218 static void ehea_update_bcmc_registrations(void)
220 struct ehea_bcmc_reg_entry
*arr
= NULL
;
221 struct ehea_adapter
*adapter
;
222 struct ehea_mc_list
*mc_entry
;
223 int num_registrations
= 0;
227 /* Determine number of registrations */
228 list_for_each_entry(adapter
, &adapter_list
, list
)
229 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
230 struct ehea_port
*port
= adapter
->port
[k
];
232 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
235 num_registrations
+= 2; /* Broadcast registrations */
237 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
238 num_registrations
+= 2;
241 if (num_registrations
) {
242 arr
= kzalloc(num_registrations
* sizeof(*arr
), GFP_KERNEL
);
244 return; /* Keep the existing array */
248 list_for_each_entry(adapter
, &adapter_list
, list
) {
249 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
250 struct ehea_port
*port
= adapter
->port
[k
];
252 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
255 arr
[i
].adh
= adapter
->handle
;
256 arr
[i
].port_id
= port
->logical_port_id
;
257 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
259 arr
[i
++].macaddr
= port
->mac_addr
;
261 arr
[i
].adh
= adapter
->handle
;
262 arr
[i
].port_id
= port
->logical_port_id
;
263 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
264 EHEA_BCMC_VLANID_ALL
;
265 arr
[i
++].macaddr
= port
->mac_addr
;
267 list_for_each_entry(mc_entry
,
268 &port
->mc_list
->list
, list
) {
269 arr
[i
].adh
= adapter
->handle
;
270 arr
[i
].port_id
= port
->logical_port_id
;
271 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
272 EHEA_BCMC_MULTICAST
|
274 arr
[i
++].macaddr
= mc_entry
->macaddr
;
276 arr
[i
].adh
= adapter
->handle
;
277 arr
[i
].port_id
= port
->logical_port_id
;
278 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
279 EHEA_BCMC_MULTICAST
|
280 EHEA_BCMC_VLANID_ALL
;
281 arr
[i
++].macaddr
= mc_entry
->macaddr
;
287 kfree(ehea_bcmc_regs
.arr
);
288 ehea_bcmc_regs
.arr
= arr
;
289 ehea_bcmc_regs
.num_entries
= i
;
292 static struct net_device_stats
*ehea_get_stats(struct net_device
*dev
)
294 struct ehea_port
*port
= netdev_priv(dev
);
295 struct net_device_stats
*stats
= &port
->stats
;
296 struct hcp_ehea_port_cb2
*cb2
;
297 u64 hret
, rx_packets
, tx_packets
;
300 memset(stats
, 0, sizeof(*stats
));
302 cb2
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
304 ehea_error("no mem for cb2");
308 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
309 port
->logical_port_id
,
310 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
311 if (hret
!= H_SUCCESS
) {
312 ehea_error("query_ehea_port failed");
316 if (netif_msg_hw(port
))
317 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
320 for (i
= 0; i
< port
->num_def_qps
; i
++)
321 rx_packets
+= port
->port_res
[i
].rx_packets
;
324 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
325 tx_packets
+= port
->port_res
[i
].tx_packets
;
327 stats
->tx_packets
= tx_packets
;
328 stats
->multicast
= cb2
->rxmcp
;
329 stats
->rx_errors
= cb2
->rxuerr
;
330 stats
->rx_bytes
= cb2
->rxo
;
331 stats
->tx_bytes
= cb2
->txo
;
332 stats
->rx_packets
= rx_packets
;
340 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
342 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
343 struct net_device
*dev
= pr
->port
->netdev
;
344 int max_index_mask
= pr
->rq1_skba
.len
- 1;
345 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
349 pr
->rq1_skba
.os_skbs
= 0;
351 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
352 pr
->rq1_skba
.index
= index
;
353 pr
->rq1_skba
.os_skbs
= fill_wqes
;
357 for (i
= 0; i
< fill_wqes
; i
++) {
358 if (!skb_arr_rq1
[index
]) {
359 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
361 if (!skb_arr_rq1
[index
]) {
362 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
363 ehea_error("%s: no mem for skb/%d wqes filled",
369 index
&= max_index_mask
;
377 ehea_update_rq1a(pr
->qp
, adder
);
380 static int ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
383 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
384 struct net_device
*dev
= pr
->port
->netdev
;
387 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++) {
388 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
389 if (!skb_arr_rq1
[i
]) {
390 ehea_error("%s: no mem for skb/%d wqes filled",
397 ehea_update_rq1a(pr
->qp
, nr_rq1a
);
402 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
403 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
404 int num_wqes
, int wqe_type
, int packet_size
)
406 struct net_device
*dev
= pr
->port
->netdev
;
407 struct ehea_qp
*qp
= pr
->qp
;
408 struct sk_buff
**skb_arr
= q_skba
->arr
;
409 struct ehea_rwqe
*rwqe
;
410 int i
, index
, max_index_mask
, fill_wqes
;
414 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
417 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
418 q_skba
->os_skbs
= fill_wqes
;
422 index
= q_skba
->index
;
423 max_index_mask
= q_skba
->len
- 1;
424 for (i
= 0; i
< fill_wqes
; i
++) {
426 struct sk_buff
*skb
= netdev_alloc_skb(dev
, packet_size
);
428 ehea_error("%s: no mem for skb/%d wqes filled",
429 pr
->port
->netdev
->name
, i
);
430 q_skba
->os_skbs
= fill_wqes
- i
;
434 skb_reserve(skb
, NET_IP_ALIGN
);
436 skb_arr
[index
] = skb
;
437 tmp_addr
= ehea_map_vaddr(skb
->data
);
438 if (tmp_addr
== -1) {
440 q_skba
->os_skbs
= fill_wqes
- i
;
445 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
446 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
447 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
448 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
449 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
450 rwqe
->sg_list
[0].len
= packet_size
;
451 rwqe
->data_segments
= 1;
454 index
&= max_index_mask
;
458 q_skba
->index
= index
;
465 ehea_update_rq2a(pr
->qp
, adder
);
467 ehea_update_rq3a(pr
->qp
, adder
);
473 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
475 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
476 nr_of_wqes
, EHEA_RWQE2_TYPE
,
477 EHEA_RQ2_PKT_SIZE
+ NET_IP_ALIGN
);
481 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
483 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
484 nr_of_wqes
, EHEA_RWQE3_TYPE
,
485 EHEA_MAX_PACKET_SIZE
+ NET_IP_ALIGN
);
488 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
490 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
491 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
493 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
494 (cqe
->header_length
== 0))
499 static inline void ehea_fill_skb(struct net_device
*dev
,
500 struct sk_buff
*skb
, struct ehea_cqe
*cqe
)
502 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
504 skb_put(skb
, length
);
505 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
506 skb
->protocol
= eth_type_trans(skb
, dev
);
509 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
511 struct ehea_cqe
*cqe
)
513 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
523 prefetchw(pref
+ EHEA_CACHE_LINE
);
525 pref
= (skb_array
[x
]->data
);
527 prefetch(pref
+ EHEA_CACHE_LINE
);
528 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
529 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
530 skb
= skb_array
[skb_index
];
531 skb_array
[skb_index
] = NULL
;
535 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
536 int arr_len
, int wqe_index
)
547 prefetchw(pref
+ EHEA_CACHE_LINE
);
549 pref
= (skb_array
[x
]->data
);
551 prefetchw(pref
+ EHEA_CACHE_LINE
);
553 skb
= skb_array
[wqe_index
];
554 skb_array
[wqe_index
] = NULL
;
558 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
559 struct ehea_cqe
*cqe
, int *processed_rq2
,
564 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
565 pr
->p_stats
.err_tcp_cksum
++;
566 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
567 pr
->p_stats
.err_ip_cksum
++;
568 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
569 pr
->p_stats
.err_frame_crc
++;
573 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
575 } else if (rq
== 3) {
577 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
581 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
582 if (netif_msg_rx_err(pr
->port
)) {
583 ehea_error("Critical receive error for QP %d. "
584 "Resetting port.", pr
->qp
->init_attr
.qp_nr
);
585 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
587 schedule_work(&pr
->port
->reset_task
);
594 static int get_skb_hdr(struct sk_buff
*skb
, void **iphdr
,
595 void **tcph
, u64
*hdr_flags
, void *priv
)
597 struct ehea_cqe
*cqe
= priv
;
601 /* non tcp/udp packets */
602 if (!cqe
->header_length
)
606 skb_reset_network_header(skb
);
608 if (iph
->protocol
!= IPPROTO_TCP
)
611 ip_len
= ip_hdrlen(skb
);
612 skb_set_transport_header(skb
, ip_len
);
613 *tcph
= tcp_hdr(skb
);
615 /* check if ip header and tcp header are complete */
616 if (iph
->tot_len
< ip_len
+ tcp_hdrlen(skb
))
619 *hdr_flags
= LRO_IPV4
| LRO_TCP
;
625 static void ehea_proc_skb(struct ehea_port_res
*pr
, struct ehea_cqe
*cqe
,
628 int vlan_extracted
= (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
633 lro_vlan_hwaccel_receive_skb(&pr
->lro_mgr
, skb
,
638 lro_receive_skb(&pr
->lro_mgr
, skb
, cqe
);
641 vlan_hwaccel_receive_skb(skb
, pr
->port
->vgrp
,
644 netif_receive_skb(skb
);
648 static int ehea_proc_rwqes(struct net_device
*dev
,
649 struct ehea_port_res
*pr
,
652 struct ehea_port
*port
= pr
->port
;
653 struct ehea_qp
*qp
= pr
->qp
;
654 struct ehea_cqe
*cqe
;
656 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
657 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
658 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
659 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
660 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
661 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
662 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
663 int wqe_index
, last_wqe_index
, rq
, port_reset
;
665 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
668 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
669 while ((processed
< budget
) && cqe
) {
673 if (netif_msg_rx_status(port
))
674 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
676 last_wqe_index
= wqe_index
;
678 if (!ehea_check_cqe(cqe
, &rq
)) {
681 skb
= get_skb_by_index_ll(skb_arr_rq1
,
684 if (unlikely(!skb
)) {
685 if (netif_msg_rx_err(port
))
686 ehea_error("LL rq1: skb=NULL");
688 skb
= netdev_alloc_skb(dev
,
693 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
694 cqe
->num_bytes_transfered
- 4);
695 ehea_fill_skb(dev
, skb
, cqe
);
696 } else if (rq
== 2) {
698 skb
= get_skb_by_index(skb_arr_rq2
,
699 skb_arr_rq2_len
, cqe
);
700 if (unlikely(!skb
)) {
701 if (netif_msg_rx_err(port
))
702 ehea_error("rq2: skb=NULL");
705 ehea_fill_skb(dev
, skb
, cqe
);
709 skb
= get_skb_by_index(skb_arr_rq3
,
710 skb_arr_rq3_len
, cqe
);
711 if (unlikely(!skb
)) {
712 if (netif_msg_rx_err(port
))
713 ehea_error("rq3: skb=NULL");
716 ehea_fill_skb(dev
, skb
, cqe
);
720 ehea_proc_skb(pr
, cqe
, skb
);
721 dev
->last_rx
= jiffies
;
723 pr
->p_stats
.poll_receive_errors
++;
724 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
730 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
733 lro_flush_all(&pr
->lro_mgr
);
735 pr
->rx_packets
+= processed
;
737 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
738 ehea_refill_rq2(pr
, processed_rq2
);
739 ehea_refill_rq3(pr
, processed_rq3
);
744 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
747 struct ehea_cq
*send_cq
= pr
->send_cq
;
748 struct ehea_cqe
*cqe
;
749 int quota
= my_quota
;
755 cqe
= ehea_poll_cq(send_cq
);
756 while (cqe
&& (quota
> 0)) {
757 ehea_inc_cq(send_cq
);
761 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
762 ehea_error("Send Completion Error: Resetting port");
763 if (netif_msg_tx_err(pr
->port
))
764 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
765 schedule_work(&pr
->port
->reset_task
);
769 if (netif_msg_tx_done(pr
->port
))
770 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
772 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
773 == EHEA_SWQE2_TYPE
)) {
775 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
776 skb
= pr
->sq_skba
.arr
[index
];
778 pr
->sq_skba
.arr
[index
] = NULL
;
781 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
784 cqe
= ehea_poll_cq(send_cq
);
787 ehea_update_feca(send_cq
, cqe_counter
);
788 atomic_add(swqe_av
, &pr
->swqe_avail
);
790 spin_lock_irqsave(&pr
->netif_queue
, flags
);
792 if (pr
->queue_stopped
&& (atomic_read(&pr
->swqe_avail
)
793 >= pr
->swqe_refill_th
)) {
794 netif_wake_queue(pr
->port
->netdev
);
795 pr
->queue_stopped
= 0;
797 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
802 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
803 #define EHEA_POLL_MAX_CQES 65535
805 static int ehea_poll(struct napi_struct
*napi
, int budget
)
807 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
809 struct net_device
*dev
= pr
->port
->netdev
;
810 struct ehea_cqe
*cqe
;
811 struct ehea_cqe
*cqe_skb
= NULL
;
812 int force_irq
, wqe_index
;
815 force_irq
= (pr
->poll_counter
> EHEA_NAPI_POLL_NUM_BEFORE_IRQ
);
816 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
819 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
821 while ((rx
!= budget
) || force_irq
) {
822 pr
->poll_counter
= 0;
824 netif_rx_complete(dev
, napi
);
825 ehea_reset_cq_ep(pr
->recv_cq
);
826 ehea_reset_cq_ep(pr
->send_cq
);
827 ehea_reset_cq_n1(pr
->recv_cq
);
828 ehea_reset_cq_n1(pr
->send_cq
);
829 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
830 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
832 if (!cqe
&& !cqe_skb
)
835 if (!netif_rx_reschedule(dev
, napi
))
838 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
839 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
846 #ifdef CONFIG_NET_POLL_CONTROLLER
847 static void ehea_netpoll(struct net_device
*dev
)
849 struct ehea_port
*port
= netdev_priv(dev
);
852 for (i
= 0; i
< port
->num_def_qps
; i
++)
853 netif_rx_schedule(dev
, &port
->port_res
[i
].napi
);
857 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
859 struct ehea_port_res
*pr
= param
;
861 netif_rx_schedule(pr
->port
->netdev
, &pr
->napi
);
866 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
868 struct ehea_port
*port
= param
;
869 struct ehea_eqe
*eqe
;
873 eqe
= ehea_poll_eq(port
->qp_eq
);
876 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
877 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
878 eqe
->entry
, qp_token
);
880 qp
= port
->port_res
[qp_token
].qp
;
881 ehea_error_data(port
->adapter
, qp
->fw_handle
);
882 eqe
= ehea_poll_eq(port
->qp_eq
);
885 schedule_work(&port
->reset_task
);
890 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
895 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
896 if (adapter
->port
[i
])
897 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
898 return adapter
->port
[i
];
902 int ehea_sense_port_attr(struct ehea_port
*port
)
906 struct hcp_ehea_port_cb0
*cb0
;
908 /* may be called via ehea_neq_tasklet() */
909 cb0
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
);
911 ehea_error("no mem for cb0");
916 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
917 port
->logical_port_id
, H_PORT_CB0
,
918 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
920 if (hret
!= H_SUCCESS
) {
926 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
928 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
929 ret
= -EADDRNOTAVAIL
;
934 switch (cb0
->port_speed
) {
936 port
->port_speed
= EHEA_SPEED_10M
;
937 port
->full_duplex
= 0;
940 port
->port_speed
= EHEA_SPEED_10M
;
941 port
->full_duplex
= 1;
944 port
->port_speed
= EHEA_SPEED_100M
;
945 port
->full_duplex
= 0;
948 port
->port_speed
= EHEA_SPEED_100M
;
949 port
->full_duplex
= 1;
952 port
->port_speed
= EHEA_SPEED_1G
;
953 port
->full_duplex
= 1;
956 port
->port_speed
= EHEA_SPEED_10G
;
957 port
->full_duplex
= 1;
960 port
->port_speed
= 0;
961 port
->full_duplex
= 0;
966 port
->num_mcs
= cb0
->num_default_qps
;
968 /* Number of default QPs */
970 port
->num_def_qps
= cb0
->num_default_qps
;
972 port
->num_def_qps
= 1;
974 if (!port
->num_def_qps
) {
979 port
->num_tx_qps
= num_tx_qps
;
981 if (port
->num_def_qps
>= port
->num_tx_qps
)
982 port
->num_add_tx_qps
= 0;
984 port
->num_add_tx_qps
= port
->num_tx_qps
- port
->num_def_qps
;
988 if (ret
|| netif_msg_probe(port
))
989 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
995 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
997 struct hcp_ehea_port_cb4
*cb4
;
1001 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1003 ehea_error("no mem for cb4");
1008 cb4
->port_speed
= port_speed
;
1010 netif_carrier_off(port
->netdev
);
1012 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1013 port
->logical_port_id
,
1014 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1015 if (hret
== H_SUCCESS
) {
1016 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1018 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1019 port
->logical_port_id
,
1020 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1022 if (hret
== H_SUCCESS
) {
1023 switch (cb4
->port_speed
) {
1025 port
->port_speed
= EHEA_SPEED_10M
;
1026 port
->full_duplex
= 0;
1029 port
->port_speed
= EHEA_SPEED_10M
;
1030 port
->full_duplex
= 1;
1032 case H_SPEED_100M_H
:
1033 port
->port_speed
= EHEA_SPEED_100M
;
1034 port
->full_duplex
= 0;
1036 case H_SPEED_100M_F
:
1037 port
->port_speed
= EHEA_SPEED_100M
;
1038 port
->full_duplex
= 1;
1041 port
->port_speed
= EHEA_SPEED_1G
;
1042 port
->full_duplex
= 1;
1045 port
->port_speed
= EHEA_SPEED_10G
;
1046 port
->full_duplex
= 1;
1049 port
->port_speed
= 0;
1050 port
->full_duplex
= 0;
1054 ehea_error("Failed sensing port speed");
1058 if (hret
== H_AUTHORITY
) {
1059 ehea_info("Hypervisor denied setting port speed");
1063 ehea_error("Failed setting port speed");
1066 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1067 netif_carrier_on(port
->netdev
);
1074 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1079 struct ehea_port
*port
;
1081 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1082 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1083 port
= ehea_get_port(adapter
, portnum
);
1086 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1089 ehea_error("unknown portnum %x", portnum
);
1093 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1094 if (!netif_carrier_ok(port
->netdev
)) {
1095 ret
= ehea_sense_port_attr(port
);
1097 ehea_error("failed resensing port "
1102 if (netif_msg_link(port
))
1103 ehea_info("%s: Logical port up: %dMbps "
1107 port
->full_duplex
==
1108 1 ? "Full" : "Half");
1110 netif_carrier_on(port
->netdev
);
1111 netif_wake_queue(port
->netdev
);
1114 if (netif_carrier_ok(port
->netdev
)) {
1115 if (netif_msg_link(port
))
1116 ehea_info("%s: Logical port down",
1117 port
->netdev
->name
);
1118 netif_carrier_off(port
->netdev
);
1119 netif_stop_queue(port
->netdev
);
1122 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1123 port
->phy_link
= EHEA_PHY_LINK_UP
;
1124 if (netif_msg_link(port
))
1125 ehea_info("%s: Physical port up",
1126 port
->netdev
->name
);
1127 if (prop_carrier_state
)
1128 netif_carrier_on(port
->netdev
);
1130 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1131 if (netif_msg_link(port
))
1132 ehea_info("%s: Physical port down",
1133 port
->netdev
->name
);
1134 if (prop_carrier_state
)
1135 netif_carrier_off(port
->netdev
);
1138 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1139 ehea_info("External switch port is primary port");
1141 ehea_info("External switch port is backup port");
1144 case EHEA_EC_ADAPTER_MALFUNC
:
1145 ehea_error("Adapter malfunction");
1147 case EHEA_EC_PORT_MALFUNC
:
1148 ehea_info("Port malfunction: Device: %s", port
->netdev
->name
);
1149 netif_carrier_off(port
->netdev
);
1150 netif_stop_queue(port
->netdev
);
1153 ehea_error("unknown event code %x, eqe=0x%lX", ec
, eqe
);
1158 static void ehea_neq_tasklet(unsigned long data
)
1160 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1161 struct ehea_eqe
*eqe
;
1164 eqe
= ehea_poll_eq(adapter
->neq
);
1165 ehea_debug("eqe=%p", eqe
);
1168 ehea_debug("*eqe=%lx", eqe
->entry
);
1169 ehea_parse_eqe(adapter
, eqe
->entry
);
1170 eqe
= ehea_poll_eq(adapter
->neq
);
1171 ehea_debug("next eqe=%p", eqe
);
1174 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1175 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1176 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1178 ehea_h_reset_events(adapter
->handle
,
1179 adapter
->neq
->fw_handle
, event_mask
);
1182 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1184 struct ehea_adapter
*adapter
= param
;
1185 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1190 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1193 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1195 ret
= ehea_init_fill_rq1(pr
, init_attr
->act_nr_rwqes_rq1
1196 - init_attr
->act_nr_rwqes_rq2
1197 - init_attr
->act_nr_rwqes_rq3
- 1);
1199 ret
|= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1201 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1206 static int ehea_reg_interrupts(struct net_device
*dev
)
1208 struct ehea_port
*port
= netdev_priv(dev
);
1209 struct ehea_port_res
*pr
;
1213 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1216 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1217 ehea_qp_aff_irq_handler
,
1218 IRQF_DISABLED
, port
->int_aff_name
, port
);
1220 ehea_error("failed registering irq for qp_aff_irq_handler:"
1221 "ist=%X", port
->qp_eq
->attr
.ist1
);
1225 if (netif_msg_ifup(port
))
1226 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1227 "registered", port
->qp_eq
->attr
.ist1
);
1230 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1231 pr
= &port
->port_res
[i
];
1232 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1233 "%s-queue%d", dev
->name
, i
);
1234 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1235 ehea_recv_irq_handler
,
1236 IRQF_DISABLED
, pr
->int_send_name
,
1239 ehea_error("failed registering irq for ehea_queue "
1240 "port_res_nr:%d, ist=%X", i
,
1244 if (netif_msg_ifup(port
))
1245 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1246 "%d registered", pr
->eq
->attr
.ist1
, i
);
1254 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1255 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1259 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1260 i
= port
->num_def_qps
;
1266 static void ehea_free_interrupts(struct net_device
*dev
)
1268 struct ehea_port
*port
= netdev_priv(dev
);
1269 struct ehea_port_res
*pr
;
1274 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1275 pr
= &port
->port_res
[i
];
1276 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1277 if (netif_msg_intr(port
))
1278 ehea_info("free send irq for res %d with handle 0x%X",
1279 i
, pr
->eq
->attr
.ist1
);
1282 /* associated events */
1283 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1284 if (netif_msg_intr(port
))
1285 ehea_info("associated event interrupt for handle 0x%X freed",
1286 port
->qp_eq
->attr
.ist1
);
1289 static int ehea_configure_port(struct ehea_port
*port
)
1293 struct hcp_ehea_port_cb0
*cb0
;
1296 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1300 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1301 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1302 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1303 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1304 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1305 PXLY_RC_VLAN_FILTER
)
1306 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1308 for (i
= 0; i
< port
->num_mcs
; i
++)
1310 cb0
->default_qpn_arr
[i
] =
1311 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1313 cb0
->default_qpn_arr
[i
] =
1314 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1316 if (netif_msg_ifup(port
))
1317 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1319 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1320 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1322 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1323 port
->logical_port_id
,
1324 H_PORT_CB0
, mask
, cb0
);
1326 if (hret
!= H_SUCCESS
)
1337 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1340 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1342 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1346 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1353 ehea_rem_mr(&pr
->send_mr
);
1355 ehea_error("Generating SMRS failed\n");
1359 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1361 if ((ehea_rem_mr(&pr
->send_mr
))
1362 || (ehea_rem_mr(&pr
->recv_mr
)))
1368 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1370 int arr_size
= sizeof(void *) * max_q_entries
;
1372 q_skba
->arr
= vmalloc(arr_size
);
1376 memset(q_skba
->arr
, 0, arr_size
);
1378 q_skba
->len
= max_q_entries
;
1380 q_skba
->os_skbs
= 0;
1385 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1386 struct port_res_cfg
*pr_cfg
, int queue_token
)
1388 struct ehea_adapter
*adapter
= port
->adapter
;
1389 enum ehea_eq_type eq_type
= EHEA_EQ
;
1390 struct ehea_qp_init_attr
*init_attr
= NULL
;
1393 memset(pr
, 0, sizeof(struct ehea_port_res
));
1396 spin_lock_init(&pr
->xmit_lock
);
1397 spin_lock_init(&pr
->netif_queue
);
1399 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1401 ehea_error("create_eq failed (eq)");
1405 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1407 port
->logical_port_id
);
1409 ehea_error("create_cq failed (cq_recv)");
1413 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1415 port
->logical_port_id
);
1417 ehea_error("create_cq failed (cq_send)");
1421 if (netif_msg_ifup(port
))
1422 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1423 pr
->send_cq
->attr
.act_nr_of_cqes
,
1424 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1426 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1429 ehea_error("no mem for ehea_qp_init_attr");
1433 init_attr
->low_lat_rq1
= 1;
1434 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1435 init_attr
->rq_count
= 3;
1436 init_attr
->qp_token
= queue_token
;
1437 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1438 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1439 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1440 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1441 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1442 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1443 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1444 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1445 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1446 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1447 init_attr
->port_nr
= port
->logical_port_id
;
1448 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1449 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1450 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1452 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1454 ehea_error("create_qp failed");
1459 if (netif_msg_ifup(port
))
1460 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1461 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr
->qp_nr
,
1462 init_attr
->act_nr_send_wqes
,
1463 init_attr
->act_nr_rwqes_rq1
,
1464 init_attr
->act_nr_rwqes_rq2
,
1465 init_attr
->act_nr_rwqes_rq3
);
1467 ret
= ehea_init_q_skba(&pr
->sq_skba
, init_attr
->act_nr_send_wqes
+ 1);
1468 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1469 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1470 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1474 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1475 if (ehea_gen_smrs(pr
) != 0) {
1480 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1484 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1486 pr
->lro_mgr
.max_aggr
= pr
->port
->lro_max_aggr
;
1487 pr
->lro_mgr
.max_desc
= MAX_LRO_DESCRIPTORS
;
1488 pr
->lro_mgr
.lro_arr
= pr
->lro_desc
;
1489 pr
->lro_mgr
.get_skb_header
= get_skb_hdr
;
1490 pr
->lro_mgr
.features
= LRO_F_NAPI
| LRO_F_EXTRACT_VLAN_ID
;
1491 pr
->lro_mgr
.dev
= port
->netdev
;
1492 pr
->lro_mgr
.ip_summed
= CHECKSUM_UNNECESSARY
;
1493 pr
->lro_mgr
.ip_summed_aggr
= CHECKSUM_UNNECESSARY
;
1500 vfree(pr
->sq_skba
.arr
);
1501 vfree(pr
->rq1_skba
.arr
);
1502 vfree(pr
->rq2_skba
.arr
);
1503 vfree(pr
->rq3_skba
.arr
);
1504 ehea_destroy_qp(pr
->qp
);
1505 ehea_destroy_cq(pr
->send_cq
);
1506 ehea_destroy_cq(pr
->recv_cq
);
1507 ehea_destroy_eq(pr
->eq
);
1512 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1516 ret
= ehea_destroy_qp(pr
->qp
);
1519 ehea_destroy_cq(pr
->send_cq
);
1520 ehea_destroy_cq(pr
->recv_cq
);
1521 ehea_destroy_eq(pr
->eq
);
1523 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1524 if (pr
->rq1_skba
.arr
[i
])
1525 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1527 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1528 if (pr
->rq2_skba
.arr
[i
])
1529 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1531 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1532 if (pr
->rq3_skba
.arr
[i
])
1533 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1535 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1536 if (pr
->sq_skba
.arr
[i
])
1537 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1539 vfree(pr
->rq1_skba
.arr
);
1540 vfree(pr
->rq2_skba
.arr
);
1541 vfree(pr
->rq3_skba
.arr
);
1542 vfree(pr
->sq_skba
.arr
);
1543 ret
= ehea_rem_smrs(pr
);
1549 * The write_* functions store information in swqe which is used by
1550 * the hardware to calculate the ip/tcp/udp checksum
1553 static inline void write_ip_start_end(struct ehea_swqe
*swqe
,
1554 const struct sk_buff
*skb
)
1556 swqe
->ip_start
= skb_network_offset(skb
);
1557 swqe
->ip_end
= (u8
)(swqe
->ip_start
+ ip_hdrlen(skb
) - 1);
1560 static inline void write_tcp_offset_end(struct ehea_swqe
*swqe
,
1561 const struct sk_buff
*skb
)
1564 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct tcphdr
, check
));
1566 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1569 static inline void write_udp_offset_end(struct ehea_swqe
*swqe
,
1570 const struct sk_buff
*skb
)
1573 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct udphdr
, check
));
1575 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1579 static void write_swqe2_TSO(struct sk_buff
*skb
,
1580 struct ehea_swqe
*swqe
, u32 lkey
)
1582 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1583 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1584 int skb_data_size
= skb
->len
- skb
->data_len
;
1587 /* Packet is TCP with TSO enabled */
1588 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1589 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1590 /* copy only eth/ip/tcp headers to immediate data and
1591 * the rest of skb->data to sg1entry
1593 headersize
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1595 skb_data_size
= skb
->len
- skb
->data_len
;
1597 if (skb_data_size
>= headersize
) {
1598 /* copy immediate data */
1599 skb_copy_from_linear_data(skb
, imm_data
, headersize
);
1600 swqe
->immediate_data_length
= headersize
;
1602 if (skb_data_size
> headersize
) {
1603 /* set sg1entry data */
1604 sg1entry
->l_key
= lkey
;
1605 sg1entry
->len
= skb_data_size
- headersize
;
1607 ehea_map_vaddr(skb
->data
+ headersize
);
1608 swqe
->descriptors
++;
1611 ehea_error("cannot handle fragmented headers");
1614 static void write_swqe2_nonTSO(struct sk_buff
*skb
,
1615 struct ehea_swqe
*swqe
, u32 lkey
)
1617 int skb_data_size
= skb
->len
- skb
->data_len
;
1618 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1619 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1621 /* Packet is any nonTSO type
1623 * Copy as much as possible skb->data to immediate data and
1624 * the rest to sg1entry
1626 if (skb_data_size
>= SWQE2_MAX_IMM
) {
1627 /* copy immediate data */
1628 skb_copy_from_linear_data(skb
, imm_data
, SWQE2_MAX_IMM
);
1630 swqe
->immediate_data_length
= SWQE2_MAX_IMM
;
1632 if (skb_data_size
> SWQE2_MAX_IMM
) {
1633 /* copy sg1entry data */
1634 sg1entry
->l_key
= lkey
;
1635 sg1entry
->len
= skb_data_size
- SWQE2_MAX_IMM
;
1637 ehea_map_vaddr(skb
->data
+ SWQE2_MAX_IMM
);
1638 swqe
->descriptors
++;
1641 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1642 swqe
->immediate_data_length
= skb_data_size
;
1646 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1647 struct ehea_swqe
*swqe
, u32 lkey
)
1649 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1651 int nfrags
, sg1entry_contains_frag_data
, i
;
1653 nfrags
= skb_shinfo(skb
)->nr_frags
;
1654 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1655 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1656 swqe
->descriptors
= 0;
1657 sg1entry_contains_frag_data
= 0;
1659 if ((dev
->features
& NETIF_F_TSO
) && skb_shinfo(skb
)->gso_size
)
1660 write_swqe2_TSO(skb
, swqe
, lkey
);
1662 write_swqe2_nonTSO(skb
, swqe
, lkey
);
1664 /* write descriptors */
1666 if (swqe
->descriptors
== 0) {
1667 /* sg1entry not yet used */
1668 frag
= &skb_shinfo(skb
)->frags
[0];
1670 /* copy sg1entry data */
1671 sg1entry
->l_key
= lkey
;
1672 sg1entry
->len
= frag
->size
;
1674 ehea_map_vaddr(page_address(frag
->page
)
1675 + frag
->page_offset
);
1676 swqe
->descriptors
++;
1677 sg1entry_contains_frag_data
= 1;
1680 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1682 frag
= &skb_shinfo(skb
)->frags
[i
];
1683 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1685 sgentry
->l_key
= lkey
;
1686 sgentry
->len
= frag
->size
;
1688 ehea_map_vaddr(page_address(frag
->page
)
1689 + frag
->page_offset
);
1690 swqe
->descriptors
++;
1695 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1701 /* De/Register untagged packets */
1702 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1703 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1704 port
->logical_port_id
,
1705 reg_type
, port
->mac_addr
, 0, hcallid
);
1706 if (hret
!= H_SUCCESS
) {
1707 ehea_error("%sregistering bc address failed (tagged)",
1708 hcallid
== H_REG_BCMC
? "" : "de");
1713 /* De/Register VLAN packets */
1714 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1715 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1716 port
->logical_port_id
,
1717 reg_type
, port
->mac_addr
, 0, hcallid
);
1718 if (hret
!= H_SUCCESS
) {
1719 ehea_error("%sregistering bc address failed (vlan)",
1720 hcallid
== H_REG_BCMC
? "" : "de");
1727 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1729 struct ehea_port
*port
= netdev_priv(dev
);
1730 struct sockaddr
*mac_addr
= sa
;
1731 struct hcp_ehea_port_cb0
*cb0
;
1735 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1736 ret
= -EADDRNOTAVAIL
;
1740 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
1742 ehea_error("no mem for cb0");
1747 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1749 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1751 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1752 port
->logical_port_id
, H_PORT_CB0
,
1753 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1754 if (hret
!= H_SUCCESS
) {
1759 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1761 down(&ehea_bcmc_regs
.lock
);
1763 /* Deregister old MAC in pHYP */
1764 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1768 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1770 /* Register new MAC in pHYP */
1771 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1778 ehea_update_bcmc_registrations();
1779 up(&ehea_bcmc_regs
.lock
);
1786 static void ehea_promiscuous_error(u64 hret
, int enable
)
1788 if (hret
== H_AUTHORITY
)
1789 ehea_info("Hypervisor denied %sabling promiscuous mode",
1790 enable
== 1 ? "en" : "dis");
1792 ehea_error("failed %sabling promiscuous mode",
1793 enable
== 1 ? "en" : "dis");
1796 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1798 struct ehea_port
*port
= netdev_priv(dev
);
1799 struct hcp_ehea_port_cb7
*cb7
;
1802 if ((enable
&& port
->promisc
) || (!enable
&& !port
->promisc
))
1805 cb7
= kzalloc(PAGE_SIZE
, GFP_ATOMIC
);
1807 ehea_error("no mem for cb7");
1811 /* Modify Pxs_DUCQPN in CB7 */
1812 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1814 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1815 port
->logical_port_id
,
1816 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1818 ehea_promiscuous_error(hret
, enable
);
1822 port
->promisc
= enable
;
1828 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1834 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1835 | EHEA_BCMC_UNTAGGED
;
1837 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1838 port
->logical_port_id
,
1839 reg_type
, mc_mac_addr
, 0, hcallid
);
1843 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1844 | EHEA_BCMC_VLANID_ALL
;
1846 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1847 port
->logical_port_id
,
1848 reg_type
, mc_mac_addr
, 0, hcallid
);
1853 static int ehea_drop_multicast_list(struct net_device
*dev
)
1855 struct ehea_port
*port
= netdev_priv(dev
);
1856 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1857 struct list_head
*pos
;
1858 struct list_head
*temp
;
1862 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1863 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1865 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1868 ehea_error("failed deregistering mcast MAC");
1878 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1880 struct ehea_port
*port
= netdev_priv(dev
);
1883 if (!port
->allmulti
) {
1885 /* Enable ALLMULTI */
1886 ehea_drop_multicast_list(dev
);
1887 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1891 ehea_error("failed enabling IFF_ALLMULTI");
1895 /* Disable ALLMULTI */
1896 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1900 ehea_error("failed disabling IFF_ALLMULTI");
1904 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1906 struct ehea_mc_list
*ehea_mcl_entry
;
1909 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1910 if (!ehea_mcl_entry
) {
1911 ehea_error("no mem for mcl_entry");
1915 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1917 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1919 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1922 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1924 ehea_error("failed registering mcast MAC");
1925 kfree(ehea_mcl_entry
);
1929 static void ehea_set_multicast_list(struct net_device
*dev
)
1931 struct ehea_port
*port
= netdev_priv(dev
);
1932 struct dev_mc_list
*k_mcl_entry
;
1935 if (dev
->flags
& IFF_PROMISC
) {
1936 ehea_promiscuous(dev
, 1);
1939 ehea_promiscuous(dev
, 0);
1941 down(&ehea_bcmc_regs
.lock
);
1943 if (dev
->flags
& IFF_ALLMULTI
) {
1944 ehea_allmulti(dev
, 1);
1947 ehea_allmulti(dev
, 0);
1949 if (dev
->mc_count
) {
1950 ret
= ehea_drop_multicast_list(dev
);
1952 /* Dropping the current multicast list failed.
1953 * Enabling ALL_MULTI is the best we can do.
1955 ehea_allmulti(dev
, 1);
1958 if (dev
->mc_count
> port
->adapter
->max_mc_mac
) {
1959 ehea_info("Mcast registration limit reached (0x%lx). "
1961 port
->adapter
->max_mc_mac
);
1965 for (i
= 0, k_mcl_entry
= dev
->mc_list
; i
< dev
->mc_count
; i
++,
1966 k_mcl_entry
= k_mcl_entry
->next
)
1967 ehea_add_multicast_entry(port
, k_mcl_entry
->dmi_addr
);
1971 ehea_update_bcmc_registrations();
1972 up(&ehea_bcmc_regs
.lock
);
1976 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1978 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1984 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
1985 struct ehea_swqe
*swqe
, u32 lkey
)
1987 if (skb
->protocol
== htons(ETH_P_IP
)) {
1988 const struct iphdr
*iph
= ip_hdr(skb
);
1991 swqe
->tx_control
|= EHEA_SWQE_CRC
1992 | EHEA_SWQE_IP_CHECKSUM
1993 | EHEA_SWQE_TCP_CHECKSUM
1994 | EHEA_SWQE_IMM_DATA_PRESENT
1995 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
1997 write_ip_start_end(swqe
, skb
);
1999 if (iph
->protocol
== IPPROTO_UDP
) {
2000 if ((iph
->frag_off
& IP_MF
)
2001 || (iph
->frag_off
& IP_OFFSET
))
2002 /* IP fragment, so don't change cs */
2003 swqe
->tx_control
&= ~EHEA_SWQE_TCP_CHECKSUM
;
2005 write_udp_offset_end(swqe
, skb
);
2006 } else if (iph
->protocol
== IPPROTO_TCP
) {
2007 write_tcp_offset_end(swqe
, skb
);
2010 /* icmp (big data) and ip segmentation packets (all other ip
2011 packets) do not require any special handling */
2014 /* Other Ethernet Protocol */
2015 swqe
->tx_control
|= EHEA_SWQE_CRC
2016 | EHEA_SWQE_IMM_DATA_PRESENT
2017 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
2020 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2023 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2024 struct ehea_swqe
*swqe
)
2026 int nfrags
= skb_shinfo(skb
)->nr_frags
;
2027 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2031 if (skb
->protocol
== htons(ETH_P_IP
)) {
2032 const struct iphdr
*iph
= ip_hdr(skb
);
2035 write_ip_start_end(swqe
, skb
);
2037 if (iph
->protocol
== IPPROTO_TCP
) {
2038 swqe
->tx_control
|= EHEA_SWQE_CRC
2039 | EHEA_SWQE_IP_CHECKSUM
2040 | EHEA_SWQE_TCP_CHECKSUM
2041 | EHEA_SWQE_IMM_DATA_PRESENT
;
2043 write_tcp_offset_end(swqe
, skb
);
2045 } else if (iph
->protocol
== IPPROTO_UDP
) {
2046 if ((iph
->frag_off
& IP_MF
)
2047 || (iph
->frag_off
& IP_OFFSET
))
2048 /* IP fragment, so don't change cs */
2049 swqe
->tx_control
|= EHEA_SWQE_CRC
2050 | EHEA_SWQE_IMM_DATA_PRESENT
;
2052 swqe
->tx_control
|= EHEA_SWQE_CRC
2053 | EHEA_SWQE_IP_CHECKSUM
2054 | EHEA_SWQE_TCP_CHECKSUM
2055 | EHEA_SWQE_IMM_DATA_PRESENT
;
2057 write_udp_offset_end(swqe
, skb
);
2060 /* icmp (big data) and
2061 ip segmentation packets (all other ip packets) */
2062 swqe
->tx_control
|= EHEA_SWQE_CRC
2063 | EHEA_SWQE_IP_CHECKSUM
2064 | EHEA_SWQE_IMM_DATA_PRESENT
;
2067 /* Other Ethernet Protocol */
2068 swqe
->tx_control
|= EHEA_SWQE_CRC
| EHEA_SWQE_IMM_DATA_PRESENT
;
2070 /* copy (immediate) data */
2072 /* data is in a single piece */
2073 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2075 /* first copy data from the skb->data buffer ... */
2076 skb_copy_from_linear_data(skb
, imm_data
,
2077 skb
->len
- skb
->data_len
);
2078 imm_data
+= skb
->len
- skb
->data_len
;
2080 /* ... then copy data from the fragments */
2081 for (i
= 0; i
< nfrags
; i
++) {
2082 frag
= &skb_shinfo(skb
)->frags
[i
];
2084 page_address(frag
->page
) + frag
->page_offset
,
2086 imm_data
+= frag
->size
;
2089 swqe
->immediate_data_length
= skb
->len
;
2093 static inline int ehea_hash_skb(struct sk_buff
*skb
, int num_qps
)
2098 if ((skb
->protocol
== htons(ETH_P_IP
)) &&
2099 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)) {
2100 tcp
= (struct tcphdr
*)(skb_network_header(skb
) +
2101 (ip_hdr(skb
)->ihl
* 4));
2102 tmp
= (tcp
->source
+ (tcp
->dest
<< 16)) % 31;
2103 tmp
+= ip_hdr(skb
)->daddr
% 31;
2104 return tmp
% num_qps
;
2109 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2111 struct ehea_port
*port
= netdev_priv(dev
);
2112 struct ehea_swqe
*swqe
;
2113 unsigned long flags
;
2116 struct ehea_port_res
*pr
;
2118 pr
= &port
->port_res
[ehea_hash_skb(skb
, port
->num_tx_qps
)];
2120 if (!spin_trylock(&pr
->xmit_lock
))
2121 return NETDEV_TX_BUSY
;
2123 if (pr
->queue_stopped
) {
2124 spin_unlock(&pr
->xmit_lock
);
2125 return NETDEV_TX_BUSY
;
2128 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2129 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2130 atomic_dec(&pr
->swqe_avail
);
2132 if (skb
->len
<= SWQE3_MAX_IMM
) {
2133 u32 sig_iv
= port
->sig_comp_iv
;
2134 u32 swqe_num
= pr
->swqe_id_counter
;
2135 ehea_xmit3(skb
, dev
, swqe
);
2136 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2137 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2138 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2139 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2141 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2142 pr
->swqe_ll_count
= 0;
2144 pr
->swqe_ll_count
+= 1;
2147 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2148 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2149 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2150 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2151 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2153 pr
->sq_skba
.index
++;
2154 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2156 lkey
= pr
->send_mr
.lkey
;
2157 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2158 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2160 pr
->swqe_id_counter
+= 1;
2162 if (port
->vgrp
&& vlan_tx_tag_present(skb
)) {
2163 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2164 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2167 if (netif_msg_tx_queued(port
)) {
2168 ehea_info("post swqe on QP %d", pr
->qp
->init_attr
.qp_nr
);
2169 ehea_dump(swqe
, 512, "swqe");
2172 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2173 netif_stop_queue(dev
);
2174 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2177 ehea_post_swqe(pr
->qp
, swqe
);
2180 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2181 spin_lock_irqsave(&pr
->netif_queue
, flags
);
2182 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2183 pr
->p_stats
.queue_stopped
++;
2184 netif_stop_queue(dev
);
2185 pr
->queue_stopped
= 1;
2187 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
2189 dev
->trans_start
= jiffies
;
2190 spin_unlock(&pr
->xmit_lock
);
2192 return NETDEV_TX_OK
;
2195 static void ehea_vlan_rx_register(struct net_device
*dev
,
2196 struct vlan_group
*grp
)
2198 struct ehea_port
*port
= netdev_priv(dev
);
2199 struct ehea_adapter
*adapter
= port
->adapter
;
2200 struct hcp_ehea_port_cb1
*cb1
;
2205 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2207 ehea_error("no mem for cb1");
2211 memset(cb1
->vlan_filter
, 0, sizeof(cb1
->vlan_filter
));
2213 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2214 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2215 if (hret
!= H_SUCCESS
)
2216 ehea_error("modify_ehea_port failed");
2223 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2225 struct ehea_port
*port
= netdev_priv(dev
);
2226 struct ehea_adapter
*adapter
= port
->adapter
;
2227 struct hcp_ehea_port_cb1
*cb1
;
2231 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2233 ehea_error("no mem for cb1");
2237 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2238 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2239 if (hret
!= H_SUCCESS
) {
2240 ehea_error("query_ehea_port failed");
2245 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2247 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2248 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2249 if (hret
!= H_SUCCESS
)
2250 ehea_error("modify_ehea_port failed");
2256 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2258 struct ehea_port
*port
= netdev_priv(dev
);
2259 struct ehea_adapter
*adapter
= port
->adapter
;
2260 struct hcp_ehea_port_cb1
*cb1
;
2264 vlan_group_set_device(port
->vgrp
, vid
, NULL
);
2266 cb1
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2268 ehea_error("no mem for cb1");
2272 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2273 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2274 if (hret
!= H_SUCCESS
) {
2275 ehea_error("query_ehea_port failed");
2280 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2282 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2283 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2284 if (hret
!= H_SUCCESS
)
2285 ehea_error("modify_ehea_port failed");
2291 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2297 struct hcp_modify_qp_cb0
*cb0
;
2299 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2305 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2306 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2307 if (hret
!= H_SUCCESS
) {
2308 ehea_error("query_ehea_qp failed (1)");
2312 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2313 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2314 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2315 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2316 if (hret
!= H_SUCCESS
) {
2317 ehea_error("modify_ehea_qp failed (1)");
2321 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2322 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2323 if (hret
!= H_SUCCESS
) {
2324 ehea_error("query_ehea_qp failed (2)");
2328 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2329 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2330 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2331 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2332 if (hret
!= H_SUCCESS
) {
2333 ehea_error("modify_ehea_qp failed (2)");
2337 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2338 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2339 if (hret
!= H_SUCCESS
) {
2340 ehea_error("query_ehea_qp failed (3)");
2344 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2345 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2346 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2347 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2348 if (hret
!= H_SUCCESS
) {
2349 ehea_error("modify_ehea_qp failed (3)");
2353 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2354 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2355 if (hret
!= H_SUCCESS
) {
2356 ehea_error("query_ehea_qp failed (4)");
2366 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
,
2370 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2371 enum ehea_eq_type eq_type
= EHEA_EQ
;
2373 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2374 EHEA_MAX_ENTRIES_EQ
, 1);
2377 ehea_error("ehea_create_eq failed (qp_eq)");
2381 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2382 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2383 pr_cfg
.max_entries_sq
= sq_entries
;
2384 pr_cfg
.max_entries_rq1
= rq1_entries
;
2385 pr_cfg
.max_entries_rq2
= rq2_entries
;
2386 pr_cfg
.max_entries_rq3
= rq3_entries
;
2388 pr_cfg_small_rx
.max_entries_rcq
= 1;
2389 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2390 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2391 pr_cfg_small_rx
.max_entries_rq1
= 1;
2392 pr_cfg_small_rx
.max_entries_rq2
= 1;
2393 pr_cfg_small_rx
.max_entries_rq3
= 1;
2395 for (i
= 0; i
< def_qps
; i
++) {
2396 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2400 for (i
= def_qps
; i
< def_qps
+ add_tx_qps
; i
++) {
2401 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2402 &pr_cfg_small_rx
, i
);
2411 ehea_clean_portres(port
, &port
->port_res
[i
]);
2414 ehea_destroy_eq(port
->qp_eq
);
2418 static int ehea_clean_all_portres(struct ehea_port
*port
)
2423 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2424 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2426 ret
|= ehea_destroy_eq(port
->qp_eq
);
2431 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2433 if (adapter
->active_ports
)
2436 ehea_rem_mr(&adapter
->mr
);
2439 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2441 if (adapter
->active_ports
)
2444 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2447 static int ehea_up(struct net_device
*dev
)
2450 struct ehea_port
*port
= netdev_priv(dev
);
2452 if (port
->state
== EHEA_PORT_UP
)
2455 down(&ehea_fw_handles
.lock
);
2457 ret
= ehea_port_res_setup(port
, port
->num_def_qps
,
2458 port
->num_add_tx_qps
);
2460 ehea_error("port_res_failed");
2464 /* Set default QP for this port */
2465 ret
= ehea_configure_port(port
);
2467 ehea_error("ehea_configure_port failed. ret:%d", ret
);
2471 ret
= ehea_reg_interrupts(dev
);
2473 ehea_error("reg_interrupts failed. ret:%d", ret
);
2477 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2478 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2480 ehea_error("activate_qp failed");
2485 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2486 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2488 ehea_error("out_free_irqs");
2493 down(&ehea_bcmc_regs
.lock
);
2495 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2501 port
->state
= EHEA_PORT_UP
;
2507 ehea_free_interrupts(dev
);
2510 ehea_clean_all_portres(port
);
2513 ehea_info("Failed starting %s. ret=%i", dev
->name
, ret
);
2515 ehea_update_bcmc_registrations();
2516 up(&ehea_bcmc_regs
.lock
);
2518 ehea_update_firmware_handles();
2519 up(&ehea_fw_handles
.lock
);
2524 static void port_napi_disable(struct ehea_port
*port
)
2528 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2529 napi_disable(&port
->port_res
[i
].napi
);
2532 static void port_napi_enable(struct ehea_port
*port
)
2536 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2537 napi_enable(&port
->port_res
[i
].napi
);
2540 static int ehea_open(struct net_device
*dev
)
2543 struct ehea_port
*port
= netdev_priv(dev
);
2545 down(&port
->port_lock
);
2547 if (netif_msg_ifup(port
))
2548 ehea_info("enabling port %s", dev
->name
);
2552 port_napi_enable(port
);
2553 netif_start_queue(dev
);
2556 up(&port
->port_lock
);
2561 static int ehea_down(struct net_device
*dev
)
2564 struct ehea_port
*port
= netdev_priv(dev
);
2566 if (port
->state
== EHEA_PORT_DOWN
)
2569 down(&ehea_bcmc_regs
.lock
);
2570 ehea_drop_multicast_list(dev
);
2571 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2573 ehea_free_interrupts(dev
);
2575 down(&ehea_fw_handles
.lock
);
2577 port
->state
= EHEA_PORT_DOWN
;
2579 ehea_update_bcmc_registrations();
2580 up(&ehea_bcmc_regs
.lock
);
2582 ret
= ehea_clean_all_portres(port
);
2584 ehea_info("Failed freeing resources for %s. ret=%i",
2587 ehea_update_firmware_handles();
2588 up(&ehea_fw_handles
.lock
);
2593 static int ehea_stop(struct net_device
*dev
)
2596 struct ehea_port
*port
= netdev_priv(dev
);
2598 if (netif_msg_ifdown(port
))
2599 ehea_info("disabling port %s", dev
->name
);
2601 flush_scheduled_work();
2602 down(&port
->port_lock
);
2603 netif_stop_queue(dev
);
2604 port_napi_disable(port
);
2605 ret
= ehea_down(dev
);
2606 up(&port
->port_lock
);
2610 void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2612 struct ehea_qp qp
= *orig_qp
;
2613 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2614 struct ehea_swqe
*swqe
;
2618 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2619 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2620 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2624 int ehea_stop_qps(struct net_device
*dev
)
2626 struct ehea_port
*port
= netdev_priv(dev
);
2627 struct ehea_adapter
*adapter
= port
->adapter
;
2628 struct hcp_modify_qp_cb0
*cb0
;
2636 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2642 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2643 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2644 struct ehea_qp
*qp
= pr
->qp
;
2646 /* Purge send queue */
2649 /* Disable queue pair */
2650 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2651 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2653 if (hret
!= H_SUCCESS
) {
2654 ehea_error("query_ehea_qp failed (1)");
2658 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2659 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2661 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2662 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2664 &dummy64
, &dummy16
, &dummy16
);
2665 if (hret
!= H_SUCCESS
) {
2666 ehea_error("modify_ehea_qp failed (1)");
2670 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2671 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2673 if (hret
!= H_SUCCESS
) {
2674 ehea_error("query_ehea_qp failed (2)");
2678 /* deregister shared memory regions */
2679 dret
= ehea_rem_smrs(pr
);
2681 ehea_error("unreg shared memory region failed");
2693 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2695 struct ehea_qp qp
= *orig_qp
;
2696 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2697 struct ehea_rwqe
*rwqe
;
2698 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2699 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2700 struct sk_buff
*skb
;
2701 u32 lkey
= pr
->recv_mr
.lkey
;
2707 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2708 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2709 rwqe
->sg_list
[0].l_key
= lkey
;
2710 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2711 skb
= skba_rq2
[index
];
2713 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2716 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2717 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2718 rwqe
->sg_list
[0].l_key
= lkey
;
2719 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2720 skb
= skba_rq3
[index
];
2722 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2726 int ehea_restart_qps(struct net_device
*dev
)
2728 struct ehea_port
*port
= netdev_priv(dev
);
2729 struct ehea_adapter
*adapter
= port
->adapter
;
2733 struct hcp_modify_qp_cb0
*cb0
;
2738 cb0
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2744 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2745 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2746 struct ehea_qp
*qp
= pr
->qp
;
2748 ret
= ehea_gen_smrs(pr
);
2750 ehea_error("creation of shared memory regions failed");
2754 ehea_update_rqs(qp
, pr
);
2756 /* Enable queue pair */
2757 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2758 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2760 if (hret
!= H_SUCCESS
) {
2761 ehea_error("query_ehea_qp failed (1)");
2765 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2766 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2768 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2769 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2771 &dummy64
, &dummy16
, &dummy16
);
2772 if (hret
!= H_SUCCESS
) {
2773 ehea_error("modify_ehea_qp failed (1)");
2777 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2778 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2780 if (hret
!= H_SUCCESS
) {
2781 ehea_error("query_ehea_qp failed (2)");
2785 /* refill entire queue */
2786 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2787 ehea_refill_rq2(pr
, 0);
2788 ehea_refill_rq3(pr
, 0);
2796 static void ehea_reset_port(struct work_struct
*work
)
2799 struct ehea_port
*port
=
2800 container_of(work
, struct ehea_port
, reset_task
);
2801 struct net_device
*dev
= port
->netdev
;
2804 down(&port
->port_lock
);
2805 netif_stop_queue(dev
);
2807 port_napi_disable(port
);
2815 ehea_set_multicast_list(dev
);
2817 if (netif_msg_timer(port
))
2818 ehea_info("Device %s resetted successfully", dev
->name
);
2820 port_napi_enable(port
);
2822 netif_wake_queue(dev
);
2824 up(&port
->port_lock
);
2828 static void ehea_rereg_mrs(struct work_struct
*work
)
2831 struct ehea_adapter
*adapter
;
2833 down(&dlpar_mem_lock
);
2834 ehea_info("LPAR memory enlarged - re-initializing driver");
2836 list_for_each_entry(adapter
, &adapter_list
, list
)
2837 if (adapter
->active_ports
) {
2838 /* Shutdown all ports */
2839 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2840 struct ehea_port
*port
= adapter
->port
[i
];
2843 struct net_device
*dev
= port
->netdev
;
2845 if (dev
->flags
& IFF_UP
) {
2846 down(&port
->port_lock
);
2847 netif_stop_queue(dev
);
2848 ret
= ehea_stop_qps(dev
);
2850 up(&port
->port_lock
);
2853 port_napi_disable(port
);
2854 up(&port
->port_lock
);
2859 /* Unregister old memory region */
2860 ret
= ehea_rem_mr(&adapter
->mr
);
2862 ehea_error("unregister MR failed - driver"
2868 ehea_destroy_busmap();
2869 ret
= ehea_create_busmap();
2871 ehea_error("creating ehea busmap failed");
2875 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2877 list_for_each_entry(adapter
, &adapter_list
, list
)
2878 if (adapter
->active_ports
) {
2879 /* Register new memory region */
2880 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2882 ehea_error("register MR failed - driver"
2887 /* Restart all ports */
2888 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2889 struct ehea_port
*port
= adapter
->port
[i
];
2892 struct net_device
*dev
= port
->netdev
;
2894 if (dev
->flags
& IFF_UP
) {
2895 down(&port
->port_lock
);
2896 port_napi_enable(port
);
2897 ret
= ehea_restart_qps(dev
);
2899 netif_wake_queue(dev
);
2900 up(&port
->port_lock
);
2905 up(&dlpar_mem_lock
);
2906 ehea_info("re-initializing driver complete");
2911 static void ehea_tx_watchdog(struct net_device
*dev
)
2913 struct ehea_port
*port
= netdev_priv(dev
);
2915 if (netif_carrier_ok(dev
) &&
2916 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2917 schedule_work(&port
->reset_task
);
2920 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2922 struct hcp_query_ehea
*cb
;
2926 cb
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2932 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2934 if (hret
!= H_SUCCESS
) {
2939 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2948 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2950 struct hcp_ehea_port_cb4
*cb4
;
2956 /* (Try to) enable *jumbo frames */
2957 cb4
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2959 ehea_error("no mem for cb4");
2963 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2964 port
->logical_port_id
,
2966 H_PORT_CB4_JUMBO
, cb4
);
2967 if (hret
== H_SUCCESS
) {
2968 if (cb4
->jumbo_frame
)
2971 cb4
->jumbo_frame
= 1;
2972 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2979 if (hret
== H_SUCCESS
)
2991 static ssize_t
ehea_show_port_id(struct device
*dev
,
2992 struct device_attribute
*attr
, char *buf
)
2994 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2995 return sprintf(buf
, "%d", port
->logical_port_id
);
2998 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
3001 static void __devinit
logical_port_release(struct device
*dev
)
3003 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
3004 of_node_put(port
->ofdev
.node
);
3007 static struct device
*ehea_register_port(struct ehea_port
*port
,
3008 struct device_node
*dn
)
3012 port
->ofdev
.node
= of_node_get(dn
);
3013 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
3014 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
3016 sprintf(port
->ofdev
.dev
.bus_id
, "port%d", port_name_cnt
++);
3017 port
->ofdev
.dev
.release
= logical_port_release
;
3019 ret
= of_device_register(&port
->ofdev
);
3021 ehea_error("failed to register device. ret=%d", ret
);
3025 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3027 ehea_error("failed to register attributes, ret=%d", ret
);
3028 goto out_unreg_of_dev
;
3031 return &port
->ofdev
.dev
;
3034 of_device_unregister(&port
->ofdev
);
3039 static void ehea_unregister_port(struct ehea_port
*port
)
3041 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3042 of_device_unregister(&port
->ofdev
);
3045 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
3046 u32 logical_port_id
,
3047 struct device_node
*dn
)
3050 struct net_device
*dev
;
3051 struct ehea_port
*port
;
3052 struct device
*port_dev
;
3055 /* allocate memory for the port structures */
3056 dev
= alloc_etherdev(sizeof(struct ehea_port
));
3059 ehea_error("no mem for net_device");
3064 port
= netdev_priv(dev
);
3066 sema_init(&port
->port_lock
, 1);
3067 port
->state
= EHEA_PORT_DOWN
;
3068 port
->sig_comp_iv
= sq_entries
/ 10;
3070 port
->adapter
= adapter
;
3072 port
->logical_port_id
= logical_port_id
;
3074 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3076 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3077 if (!port
->mc_list
) {
3079 goto out_free_ethdev
;
3082 INIT_LIST_HEAD(&port
->mc_list
->list
);
3084 ret
= ehea_sense_port_attr(port
);
3086 goto out_free_mc_list
;
3088 port_dev
= ehea_register_port(port
, dn
);
3090 goto out_free_mc_list
;
3092 SET_NETDEV_DEV(dev
, port_dev
);
3094 /* initialize net_device structure */
3095 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3097 dev
->open
= ehea_open
;
3098 #ifdef CONFIG_NET_POLL_CONTROLLER
3099 dev
->poll_controller
= ehea_netpoll
;
3101 dev
->stop
= ehea_stop
;
3102 dev
->hard_start_xmit
= ehea_start_xmit
;
3103 dev
->get_stats
= ehea_get_stats
;
3104 dev
->set_multicast_list
= ehea_set_multicast_list
;
3105 dev
->set_mac_address
= ehea_set_mac_addr
;
3106 dev
->change_mtu
= ehea_change_mtu
;
3107 dev
->vlan_rx_register
= ehea_vlan_rx_register
;
3108 dev
->vlan_rx_add_vid
= ehea_vlan_rx_add_vid
;
3109 dev
->vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
;
3110 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3111 | NETIF_F_HIGHDMA
| NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_TX
3112 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3114 dev
->tx_timeout
= &ehea_tx_watchdog
;
3115 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3117 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3118 ehea_set_ethtool_ops(dev
);
3120 ret
= register_netdev(dev
);
3122 ehea_error("register_netdev failed. ret=%d", ret
);
3123 goto out_unreg_port
;
3126 port
->lro_max_aggr
= lro_max_aggr
;
3128 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3130 ehea_error("failed determining jumbo frame status for %s",
3131 port
->netdev
->name
);
3133 ehea_info("%s: Jumbo frames are %sabled", dev
->name
,
3134 jumbo
== 1 ? "en" : "dis");
3136 adapter
->active_ports
++;
3141 ehea_unregister_port(port
);
3144 kfree(port
->mc_list
);
3150 ehea_error("setting up logical port with id=%d failed, ret=%d",
3151 logical_port_id
, ret
);
3155 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3157 unregister_netdev(port
->netdev
);
3158 ehea_unregister_port(port
);
3159 kfree(port
->mc_list
);
3160 free_netdev(port
->netdev
);
3161 port
->adapter
->active_ports
--;
3164 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3166 struct device_node
*lhea_dn
;
3167 struct device_node
*eth_dn
= NULL
;
3169 const u32
*dn_log_port_id
;
3172 lhea_dn
= adapter
->ofdev
->node
;
3173 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3175 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3177 if (!dn_log_port_id
) {
3178 ehea_error("bad device node: eth_dn name=%s",
3183 if (ehea_add_adapter_mr(adapter
)) {
3184 ehea_error("creating MR failed");
3185 of_node_put(eth_dn
);
3189 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3192 if (adapter
->port
[i
])
3193 ehea_info("%s -> logical port id #%d",
3194 adapter
->port
[i
]->netdev
->name
,
3197 ehea_remove_adapter_mr(adapter
);
3204 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3205 u32 logical_port_id
)
3207 struct device_node
*lhea_dn
;
3208 struct device_node
*eth_dn
= NULL
;
3209 const u32
*dn_log_port_id
;
3211 lhea_dn
= adapter
->ofdev
->node
;
3212 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3214 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3217 if (*dn_log_port_id
== logical_port_id
)
3224 static ssize_t
ehea_probe_port(struct device
*dev
,
3225 struct device_attribute
*attr
,
3226 const char *buf
, size_t count
)
3228 struct ehea_adapter
*adapter
= dev
->driver_data
;
3229 struct ehea_port
*port
;
3230 struct device_node
*eth_dn
= NULL
;
3233 u32 logical_port_id
;
3235 sscanf(buf
, "%d", &logical_port_id
);
3237 port
= ehea_get_port(adapter
, logical_port_id
);
3240 ehea_info("adding port with logical port id=%d failed. port "
3241 "already configured as %s.", logical_port_id
,
3242 port
->netdev
->name
);
3246 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3249 ehea_info("no logical port with id %d found", logical_port_id
);
3253 if (ehea_add_adapter_mr(adapter
)) {
3254 ehea_error("creating MR failed");
3258 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3260 of_node_put(eth_dn
);
3263 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3264 if (!adapter
->port
[i
]) {
3265 adapter
->port
[i
] = port
;
3269 ehea_info("added %s (logical port id=%d)", port
->netdev
->name
,
3272 ehea_remove_adapter_mr(adapter
);
3276 return (ssize_t
) count
;
3279 static ssize_t
ehea_remove_port(struct device
*dev
,
3280 struct device_attribute
*attr
,
3281 const char *buf
, size_t count
)
3283 struct ehea_adapter
*adapter
= dev
->driver_data
;
3284 struct ehea_port
*port
;
3286 u32 logical_port_id
;
3288 sscanf(buf
, "%d", &logical_port_id
);
3290 port
= ehea_get_port(adapter
, logical_port_id
);
3293 ehea_info("removed %s (logical port id=%d)", port
->netdev
->name
,
3296 ehea_shutdown_single_port(port
);
3298 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3299 if (adapter
->port
[i
] == port
) {
3300 adapter
->port
[i
] = NULL
;
3304 ehea_error("removing port with logical port id=%d failed. port "
3305 "not configured.", logical_port_id
);
3309 ehea_remove_adapter_mr(adapter
);
3311 return (ssize_t
) count
;
3314 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3315 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3317 int ehea_create_device_sysfs(struct of_device
*dev
)
3319 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3323 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3328 void ehea_remove_device_sysfs(struct of_device
*dev
)
3330 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3331 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3334 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
3335 const struct of_device_id
*id
)
3337 struct ehea_adapter
*adapter
;
3338 const u64
*adapter_handle
;
3341 if (!dev
|| !dev
->node
) {
3342 ehea_error("Invalid ibmebus device probed");
3345 down(&ehea_fw_handles
.lock
);
3347 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3350 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3354 list_add(&adapter
->list
, &adapter_list
);
3356 adapter
->ofdev
= dev
;
3358 adapter_handle
= of_get_property(dev
->node
, "ibm,hea-handle",
3361 adapter
->handle
= *adapter_handle
;
3363 if (!adapter
->handle
) {
3364 dev_err(&dev
->dev
, "failed getting handle for adapter"
3365 " '%s'\n", dev
->node
->full_name
);
3370 adapter
->pd
= EHEA_PD_ID
;
3372 dev
->dev
.driver_data
= adapter
;
3375 /* initialize adapter and ports */
3376 /* get adapter properties */
3377 ret
= ehea_sense_adapter_attr(adapter
);
3379 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3383 adapter
->neq
= ehea_create_eq(adapter
,
3384 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3385 if (!adapter
->neq
) {
3387 dev_err(&dev
->dev
, "NEQ creation failed\n");
3391 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3392 (unsigned long)adapter
);
3394 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3395 ehea_interrupt_neq
, IRQF_DISABLED
,
3396 "ehea_neq", adapter
);
3398 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3402 ret
= ehea_create_device_sysfs(dev
);
3406 ret
= ehea_setup_ports(adapter
);
3408 dev_err(&dev
->dev
, "setup_ports failed\n");
3409 goto out_rem_dev_sysfs
;
3416 ehea_remove_device_sysfs(dev
);
3419 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3422 ehea_destroy_eq(adapter
->neq
);
3428 ehea_update_firmware_handles();
3429 up(&ehea_fw_handles
.lock
);
3433 static int __devexit
ehea_remove(struct of_device
*dev
)
3435 struct ehea_adapter
*adapter
= dev
->dev
.driver_data
;
3438 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3439 if (adapter
->port
[i
]) {
3440 ehea_shutdown_single_port(adapter
->port
[i
]);
3441 adapter
->port
[i
] = NULL
;
3444 ehea_remove_device_sysfs(dev
);
3446 flush_scheduled_work();
3448 down(&ehea_fw_handles
.lock
);
3450 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3451 tasklet_kill(&adapter
->neq_tasklet
);
3453 ehea_destroy_eq(adapter
->neq
);
3454 ehea_remove_adapter_mr(adapter
);
3455 list_del(&adapter
->list
);
3458 ehea_update_firmware_handles();
3459 up(&ehea_fw_handles
.lock
);
3464 void ehea_crash_handler(void)
3468 if (ehea_fw_handles
.arr
)
3469 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3470 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3471 ehea_fw_handles
.arr
[i
].fwh
,
3474 if (ehea_bcmc_regs
.arr
)
3475 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3476 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3477 ehea_bcmc_regs
.arr
[i
].port_id
,
3478 ehea_bcmc_regs
.arr
[i
].reg_type
,
3479 ehea_bcmc_regs
.arr
[i
].macaddr
,
3483 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3484 unsigned long action
, void *unused
)
3486 if (action
== SYS_RESTART
) {
3487 ehea_info("Reboot: freeing all eHEA resources");
3488 ibmebus_unregister_driver(&ehea_driver
);
3493 static struct notifier_block ehea_reboot_nb
= {
3494 .notifier_call
= ehea_reboot_notifier
,
3497 static int check_module_parm(void)
3501 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3502 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3503 ehea_info("Bad parameter: rq1_entries");
3506 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3507 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3508 ehea_info("Bad parameter: rq2_entries");
3511 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3512 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3513 ehea_info("Bad parameter: rq3_entries");
3516 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3517 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3518 ehea_info("Bad parameter: sq_entries");
3525 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3528 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3531 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3532 ehea_show_capabilities
, NULL
);
3534 int __init
ehea_module_init(void)
3538 printk(KERN_INFO
"IBM eHEA ethernet device driver (Release %s)\n",
3542 INIT_WORK(&ehea_rereg_mr_task
, ehea_rereg_mrs
);
3543 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3544 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3546 sema_init(&dlpar_mem_lock
, 1);
3547 sema_init(&ehea_fw_handles
.lock
, 1);
3548 sema_init(&ehea_bcmc_regs
.lock
, 1);
3550 ret
= check_module_parm();
3554 ret
= ehea_create_busmap();
3558 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3560 ehea_info("failed registering reboot notifier");
3562 ret
= crash_shutdown_register(&ehea_crash_handler
);
3564 ehea_info("failed registering crash handler");
3566 ret
= ibmebus_register_driver(&ehea_driver
);
3568 ehea_error("failed registering eHEA device driver on ebus");
3572 ret
= driver_create_file(&ehea_driver
.driver
,
3573 &driver_attr_capabilities
);
3575 ehea_error("failed to register capabilities attribute, ret=%d",
3583 ibmebus_unregister_driver(&ehea_driver
);
3585 unregister_reboot_notifier(&ehea_reboot_nb
);
3586 crash_shutdown_unregister(&ehea_crash_handler
);
3591 static void __exit
ehea_module_exit(void)
3595 flush_scheduled_work();
3596 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3597 ibmebus_unregister_driver(&ehea_driver
);
3598 unregister_reboot_notifier(&ehea_reboot_nb
);
3599 ret
= crash_shutdown_unregister(&ehea_crash_handler
);
3601 ehea_info("failed unregistering crash handler");
3602 kfree(ehea_fw_handles
.arr
);
3603 kfree(ehea_bcmc_regs
.arr
);
3604 ehea_destroy_busmap();
3607 module_init(ehea_module_init
);
3608 module_exit(ehea_module_exit
);