2 * linux/drivers/net/ethernet/ibm/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.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/tcp.h>
34 #include <linux/udp.h>
36 #include <linux/list.h>
37 #include <linux/slab.h>
38 #include <linux/if_ether.h>
39 #include <linux/notifier.h>
40 #include <linux/reboot.h>
41 #include <linux/memory.h>
42 #include <asm/kexec.h>
43 #include <linux/mutex.h>
44 #include <linux/prefetch.h>
50 #include "ehea_phyp.h"
53 MODULE_LICENSE("GPL");
54 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55 MODULE_DESCRIPTION("IBM eServer HEA Driver");
56 MODULE_VERSION(DRV_VERSION
);
59 static int msg_level
= -1;
60 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
61 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
62 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
63 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
64 static int use_mcs
= 1;
65 static int prop_carrier_state
;
67 module_param(msg_level
, int, 0);
68 module_param(rq1_entries
, int, 0);
69 module_param(rq2_entries
, int, 0);
70 module_param(rq3_entries
, int, 0);
71 module_param(sq_entries
, int, 0);
72 module_param(prop_carrier_state
, int, 0);
73 module_param(use_mcs
, int, 0);
75 MODULE_PARM_DESC(msg_level
, "msg_level");
76 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
78 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
81 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
84 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
87 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
90 MODULE_PARM_DESC(use_mcs
, " Multiple receive queues, 1: enable, 0: disable, "
93 static int port_name_cnt
;
94 static LIST_HEAD(adapter_list
);
95 static unsigned long ehea_driver_flags
;
96 static DEFINE_MUTEX(dlpar_mem_lock
);
97 static struct ehea_fw_handle_array ehea_fw_handles
;
98 static struct ehea_bcmc_reg_array ehea_bcmc_regs
;
101 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
102 const struct of_device_id
*id
);
104 static int __devexit
ehea_remove(struct platform_device
*dev
);
106 static struct of_device_id ehea_device_table
[] = {
109 .compatible
= "IBM,lhea",
113 MODULE_DEVICE_TABLE(of
, ehea_device_table
);
115 static struct of_platform_driver ehea_driver
= {
118 .owner
= THIS_MODULE
,
119 .of_match_table
= ehea_device_table
,
121 .probe
= ehea_probe_adapter
,
122 .remove
= ehea_remove
,
125 void ehea_dump(void *adr
, int len
, char *msg
)
128 unsigned char *deb
= adr
;
129 for (x
= 0; x
< len
; x
+= 16) {
130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg
, deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
136 static void ehea_schedule_port_reset(struct ehea_port
*port
)
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
))
139 schedule_work(&port
->reset_task
);
142 static void ehea_update_firmware_handles(void)
144 struct ehea_fw_handle_entry
*arr
= NULL
;
145 struct ehea_adapter
*adapter
;
146 int num_adapters
= 0;
150 int num_fw_handles
, k
, l
;
152 /* Determine number of handles */
153 mutex_lock(&ehea_fw_handles
.lock
);
155 list_for_each_entry(adapter
, &adapter_list
, list
) {
158 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
159 struct ehea_port
*port
= adapter
->port
[k
];
161 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
165 num_portres
+= port
->num_def_qps
;
169 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
170 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
171 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
173 if (num_fw_handles
) {
174 arr
= kcalloc(num_fw_handles
, sizeof(*arr
), GFP_KERNEL
);
176 goto out
; /* Keep the existing array */
180 list_for_each_entry(adapter
, &adapter_list
, list
) {
181 if (num_adapters
== 0)
184 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
185 struct ehea_port
*port
= adapter
->port
[k
];
187 if (!port
|| (port
->state
!= EHEA_PORT_UP
) ||
191 for (l
= 0; l
< port
->num_def_qps
; l
++) {
192 struct ehea_port_res
*pr
= &port
->port_res
[l
];
194 arr
[i
].adh
= adapter
->handle
;
195 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
196 arr
[i
].adh
= adapter
->handle
;
197 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
198 arr
[i
].adh
= adapter
->handle
;
199 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
200 arr
[i
].adh
= adapter
->handle
;
201 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
202 arr
[i
].adh
= adapter
->handle
;
203 arr
[i
++].fwh
= pr
->send_mr
.handle
;
204 arr
[i
].adh
= adapter
->handle
;
205 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
207 arr
[i
].adh
= adapter
->handle
;
208 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
212 arr
[i
].adh
= adapter
->handle
;
213 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
215 if (adapter
->mr
.handle
) {
216 arr
[i
].adh
= adapter
->handle
;
217 arr
[i
++].fwh
= adapter
->mr
.handle
;
223 kfree(ehea_fw_handles
.arr
);
224 ehea_fw_handles
.arr
= arr
;
225 ehea_fw_handles
.num_entries
= i
;
227 mutex_unlock(&ehea_fw_handles
.lock
);
230 static void ehea_update_bcmc_registrations(void)
233 struct ehea_bcmc_reg_entry
*arr
= NULL
;
234 struct ehea_adapter
*adapter
;
235 struct ehea_mc_list
*mc_entry
;
236 int num_registrations
= 0;
240 spin_lock_irqsave(&ehea_bcmc_regs
.lock
, flags
);
242 /* Determine number of registrations */
243 list_for_each_entry(adapter
, &adapter_list
, list
)
244 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
245 struct ehea_port
*port
= adapter
->port
[k
];
247 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
250 num_registrations
+= 2; /* Broadcast registrations */
252 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
253 num_registrations
+= 2;
256 if (num_registrations
) {
257 arr
= kcalloc(num_registrations
, sizeof(*arr
), GFP_ATOMIC
);
259 goto out
; /* Keep the existing array */
263 list_for_each_entry(adapter
, &adapter_list
, list
) {
264 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
265 struct ehea_port
*port
= adapter
->port
[k
];
267 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
270 if (num_registrations
== 0)
273 arr
[i
].adh
= adapter
->handle
;
274 arr
[i
].port_id
= port
->logical_port_id
;
275 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
277 arr
[i
++].macaddr
= port
->mac_addr
;
279 arr
[i
].adh
= adapter
->handle
;
280 arr
[i
].port_id
= port
->logical_port_id
;
281 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
282 EHEA_BCMC_VLANID_ALL
;
283 arr
[i
++].macaddr
= port
->mac_addr
;
284 num_registrations
-= 2;
286 list_for_each_entry(mc_entry
,
287 &port
->mc_list
->list
, list
) {
288 if (num_registrations
== 0)
291 arr
[i
].adh
= adapter
->handle
;
292 arr
[i
].port_id
= port
->logical_port_id
;
293 arr
[i
].reg_type
= EHEA_BCMC_MULTICAST
|
295 if (mc_entry
->macaddr
== 0)
296 arr
[i
].reg_type
|= EHEA_BCMC_SCOPE_ALL
;
297 arr
[i
++].macaddr
= mc_entry
->macaddr
;
299 arr
[i
].adh
= adapter
->handle
;
300 arr
[i
].port_id
= port
->logical_port_id
;
301 arr
[i
].reg_type
= EHEA_BCMC_MULTICAST
|
302 EHEA_BCMC_VLANID_ALL
;
303 if (mc_entry
->macaddr
== 0)
304 arr
[i
].reg_type
|= EHEA_BCMC_SCOPE_ALL
;
305 arr
[i
++].macaddr
= mc_entry
->macaddr
;
306 num_registrations
-= 2;
312 kfree(ehea_bcmc_regs
.arr
);
313 ehea_bcmc_regs
.arr
= arr
;
314 ehea_bcmc_regs
.num_entries
= i
;
316 spin_unlock_irqrestore(&ehea_bcmc_regs
.lock
, flags
);
319 static struct rtnl_link_stats64
*ehea_get_stats64(struct net_device
*dev
,
320 struct rtnl_link_stats64
*stats
)
322 struct ehea_port
*port
= netdev_priv(dev
);
323 u64 rx_packets
= 0, tx_packets
= 0, rx_bytes
= 0, tx_bytes
= 0;
326 for (i
= 0; i
< port
->num_def_qps
; i
++) {
327 rx_packets
+= port
->port_res
[i
].rx_packets
;
328 rx_bytes
+= port
->port_res
[i
].rx_bytes
;
331 for (i
= 0; i
< port
->num_def_qps
; i
++) {
332 tx_packets
+= port
->port_res
[i
].tx_packets
;
333 tx_bytes
+= port
->port_res
[i
].tx_bytes
;
336 stats
->tx_packets
= tx_packets
;
337 stats
->rx_bytes
= rx_bytes
;
338 stats
->tx_bytes
= tx_bytes
;
339 stats
->rx_packets
= rx_packets
;
341 stats
->multicast
= port
->stats
.multicast
;
342 stats
->rx_errors
= port
->stats
.rx_errors
;
346 static void ehea_update_stats(struct work_struct
*work
)
348 struct ehea_port
*port
=
349 container_of(work
, struct ehea_port
, stats_work
.work
);
350 struct net_device
*dev
= port
->netdev
;
351 struct rtnl_link_stats64
*stats
= &port
->stats
;
352 struct hcp_ehea_port_cb2
*cb2
;
355 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
357 netdev_err(dev
, "No mem for cb2. Some interface statistics were not updated\n");
361 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
362 port
->logical_port_id
,
363 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
364 if (hret
!= H_SUCCESS
) {
365 netdev_err(dev
, "query_ehea_port failed\n");
369 if (netif_msg_hw(port
))
370 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
372 stats
->multicast
= cb2
->rxmcp
;
373 stats
->rx_errors
= cb2
->rxuerr
;
376 free_page((unsigned long)cb2
);
378 schedule_delayed_work(&port
->stats_work
,
379 round_jiffies_relative(msecs_to_jiffies(1000)));
382 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
384 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
385 struct net_device
*dev
= pr
->port
->netdev
;
386 int max_index_mask
= pr
->rq1_skba
.len
- 1;
387 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
391 pr
->rq1_skba
.os_skbs
= 0;
393 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
395 pr
->rq1_skba
.index
= index
;
396 pr
->rq1_skba
.os_skbs
= fill_wqes
;
400 for (i
= 0; i
< fill_wqes
; i
++) {
401 if (!skb_arr_rq1
[index
]) {
402 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
404 if (!skb_arr_rq1
[index
]) {
405 netdev_info(dev
, "Unable to allocate enough skb in the array\n");
406 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
411 index
&= max_index_mask
;
419 ehea_update_rq1a(pr
->qp
, adder
);
422 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
424 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
425 struct net_device
*dev
= pr
->port
->netdev
;
428 if (nr_rq1a
> pr
->rq1_skba
.len
) {
429 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
433 for (i
= 0; i
< nr_rq1a
; i
++) {
434 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
435 if (!skb_arr_rq1
[i
]) {
436 netdev_info(dev
, "Not enough memory to allocate skb array\n");
441 ehea_update_rq1a(pr
->qp
, i
- 1);
444 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
445 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
446 int num_wqes
, int wqe_type
, int packet_size
)
448 struct net_device
*dev
= pr
->port
->netdev
;
449 struct ehea_qp
*qp
= pr
->qp
;
450 struct sk_buff
**skb_arr
= q_skba
->arr
;
451 struct ehea_rwqe
*rwqe
;
452 int i
, index
, max_index_mask
, fill_wqes
;
456 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
459 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
460 q_skba
->os_skbs
= fill_wqes
;
464 index
= q_skba
->index
;
465 max_index_mask
= q_skba
->len
- 1;
466 for (i
= 0; i
< fill_wqes
; i
++) {
470 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
472 q_skba
->os_skbs
= fill_wqes
- i
;
473 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
474 netdev_info(pr
->port
->netdev
,
475 "rq%i ran dry - no mem for skb\n",
482 skb_arr
[index
] = skb
;
483 tmp_addr
= ehea_map_vaddr(skb
->data
);
484 if (tmp_addr
== -1) {
486 q_skba
->os_skbs
= fill_wqes
- i
;
491 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
492 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
493 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
494 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
495 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
496 rwqe
->sg_list
[0].len
= packet_size
;
497 rwqe
->data_segments
= 1;
500 index
&= max_index_mask
;
504 q_skba
->index
= index
;
511 ehea_update_rq2a(pr
->qp
, adder
);
513 ehea_update_rq3a(pr
->qp
, adder
);
519 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
521 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
522 nr_of_wqes
, EHEA_RWQE2_TYPE
,
527 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
529 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
530 nr_of_wqes
, EHEA_RWQE3_TYPE
,
531 EHEA_MAX_PACKET_SIZE
);
534 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
536 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
537 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
539 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
540 (cqe
->header_length
== 0))
545 static inline void ehea_fill_skb(struct net_device
*dev
,
546 struct sk_buff
*skb
, struct ehea_cqe
*cqe
,
547 struct ehea_port_res
*pr
)
549 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
551 skb_put(skb
, length
);
552 skb
->protocol
= eth_type_trans(skb
, dev
);
554 /* The packet was not an IPV4 packet so a complemented checksum was
555 calculated. The value is found in the Internet Checksum field. */
556 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
557 skb
->ip_summed
= CHECKSUM_COMPLETE
;
558 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
560 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
562 skb_record_rx_queue(skb
, pr
- &pr
->port
->port_res
[0]);
565 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
567 struct ehea_cqe
*cqe
)
569 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
580 prefetchw(pref
+ EHEA_CACHE_LINE
);
582 pref
= (skb_array
[x
]->data
);
584 prefetch(pref
+ EHEA_CACHE_LINE
);
585 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
586 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
589 skb
= skb_array
[skb_index
];
590 skb_array
[skb_index
] = NULL
;
594 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
595 int arr_len
, int wqe_index
)
607 prefetchw(pref
+ EHEA_CACHE_LINE
);
609 pref
= (skb_array
[x
]->data
);
611 prefetchw(pref
+ EHEA_CACHE_LINE
);
614 skb
= skb_array
[wqe_index
];
615 skb_array
[wqe_index
] = NULL
;
619 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
620 struct ehea_cqe
*cqe
, int *processed_rq2
,
625 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
626 pr
->p_stats
.err_tcp_cksum
++;
627 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
628 pr
->p_stats
.err_ip_cksum
++;
629 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
630 pr
->p_stats
.err_frame_crc
++;
634 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
636 } else if (rq
== 3) {
638 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
642 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
643 if (netif_msg_rx_err(pr
->port
)) {
644 pr_err("Critical receive error for QP %d. Resetting port.\n",
645 pr
->qp
->init_attr
.qp_nr
);
646 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
648 ehea_schedule_port_reset(pr
->port
);
655 static int ehea_proc_rwqes(struct net_device
*dev
,
656 struct ehea_port_res
*pr
,
659 struct ehea_port
*port
= pr
->port
;
660 struct ehea_qp
*qp
= pr
->qp
;
661 struct ehea_cqe
*cqe
;
663 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
664 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
665 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
666 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
667 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
668 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
669 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
670 u64 processed_bytes
= 0;
671 int wqe_index
, last_wqe_index
, rq
, port_reset
;
673 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
676 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
677 while ((processed
< budget
) && cqe
) {
681 if (netif_msg_rx_status(port
))
682 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
684 last_wqe_index
= wqe_index
;
686 if (!ehea_check_cqe(cqe
, &rq
)) {
689 skb
= get_skb_by_index_ll(skb_arr_rq1
,
692 if (unlikely(!skb
)) {
693 netif_info(port
, rx_err
, dev
,
694 "LL rq1: skb=NULL\n");
696 skb
= netdev_alloc_skb(dev
,
699 netdev_err(dev
, "Not enough memory to allocate skb\n");
703 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
704 cqe
->num_bytes_transfered
- 4);
705 ehea_fill_skb(dev
, skb
, cqe
, pr
);
706 } else if (rq
== 2) {
708 skb
= get_skb_by_index(skb_arr_rq2
,
709 skb_arr_rq2_len
, cqe
);
710 if (unlikely(!skb
)) {
711 netif_err(port
, rx_err
, dev
,
715 ehea_fill_skb(dev
, skb
, cqe
, pr
);
719 skb
= get_skb_by_index(skb_arr_rq3
,
720 skb_arr_rq3_len
, cqe
);
721 if (unlikely(!skb
)) {
722 netif_err(port
, rx_err
, dev
,
726 ehea_fill_skb(dev
, skb
, cqe
, pr
);
730 processed_bytes
+= skb
->len
;
732 if (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
733 __vlan_hwaccel_put_tag(skb
, cqe
->vlan_tag
);
735 napi_gro_receive(&pr
->napi
, skb
);
737 pr
->p_stats
.poll_receive_errors
++;
738 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
744 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
747 pr
->rx_packets
+= processed
;
748 pr
->rx_bytes
+= processed_bytes
;
750 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
751 ehea_refill_rq2(pr
, processed_rq2
);
752 ehea_refill_rq3(pr
, processed_rq3
);
757 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
759 static void reset_sq_restart_flag(struct ehea_port
*port
)
763 for (i
= 0; i
< port
->num_def_qps
; i
++) {
764 struct ehea_port_res
*pr
= &port
->port_res
[i
];
765 pr
->sq_restart_flag
= 0;
767 wake_up(&port
->restart_wq
);
770 static void check_sqs(struct ehea_port
*port
)
772 struct ehea_swqe
*swqe
;
776 for (i
= 0; i
< port
->num_def_qps
; i
++) {
777 struct ehea_port_res
*pr
= &port
->port_res
[i
];
780 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
781 memset(swqe
, 0, SWQE_HEADER_SIZE
);
782 atomic_dec(&pr
->swqe_avail
);
784 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
785 swqe
->wr_id
= SWQE_RESTART_CHECK
;
786 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
787 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
788 swqe
->immediate_data_length
= 80;
790 ehea_post_swqe(pr
->qp
, swqe
);
792 ret
= wait_event_timeout(port
->restart_wq
,
793 pr
->sq_restart_flag
== 0,
794 msecs_to_jiffies(100));
797 pr_err("HW/SW queues out of sync\n");
798 ehea_schedule_port_reset(pr
->port
);
805 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
808 struct ehea_cq
*send_cq
= pr
->send_cq
;
809 struct ehea_cqe
*cqe
;
810 int quota
= my_quota
;
814 struct netdev_queue
*txq
= netdev_get_tx_queue(pr
->port
->netdev
,
815 pr
- &pr
->port
->port_res
[0]);
817 cqe
= ehea_poll_cq(send_cq
);
818 while (cqe
&& (quota
> 0)) {
819 ehea_inc_cq(send_cq
);
824 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
825 pr
->sq_restart_flag
= 1;
830 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
831 pr_err("Bad send completion status=0x%04X\n",
834 if (netif_msg_tx_err(pr
->port
))
835 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
837 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
838 pr_err("Resetting port\n");
839 ehea_schedule_port_reset(pr
->port
);
844 if (netif_msg_tx_done(pr
->port
))
845 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
847 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
848 == EHEA_SWQE2_TYPE
)) {
850 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
851 skb
= pr
->sq_skba
.arr
[index
];
853 pr
->sq_skba
.arr
[index
] = NULL
;
856 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
859 cqe
= ehea_poll_cq(send_cq
);
862 ehea_update_feca(send_cq
, cqe_counter
);
863 atomic_add(swqe_av
, &pr
->swqe_avail
);
865 if (unlikely(netif_tx_queue_stopped(txq
) &&
866 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))) {
867 __netif_tx_lock(txq
, smp_processor_id());
868 if (netif_tx_queue_stopped(txq
) &&
869 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))
870 netif_tx_wake_queue(txq
);
871 __netif_tx_unlock(txq
);
874 wake_up(&pr
->port
->swqe_avail_wq
);
879 #define EHEA_POLL_MAX_CQES 65535
881 static int ehea_poll(struct napi_struct
*napi
, int budget
)
883 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
885 struct net_device
*dev
= pr
->port
->netdev
;
886 struct ehea_cqe
*cqe
;
887 struct ehea_cqe
*cqe_skb
= NULL
;
891 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
892 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
894 while (rx
!= budget
) {
896 ehea_reset_cq_ep(pr
->recv_cq
);
897 ehea_reset_cq_ep(pr
->send_cq
);
898 ehea_reset_cq_n1(pr
->recv_cq
);
899 ehea_reset_cq_n1(pr
->send_cq
);
901 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
902 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
904 if (!cqe
&& !cqe_skb
)
907 if (!napi_reschedule(napi
))
910 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
911 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
917 #ifdef CONFIG_NET_POLL_CONTROLLER
918 static void ehea_netpoll(struct net_device
*dev
)
920 struct ehea_port
*port
= netdev_priv(dev
);
923 for (i
= 0; i
< port
->num_def_qps
; i
++)
924 napi_schedule(&port
->port_res
[i
].napi
);
928 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
930 struct ehea_port_res
*pr
= param
;
932 napi_schedule(&pr
->napi
);
937 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
939 struct ehea_port
*port
= param
;
940 struct ehea_eqe
*eqe
;
943 u64 resource_type
, aer
, aerr
;
946 eqe
= ehea_poll_eq(port
->qp_eq
);
949 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
950 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
951 eqe
->entry
, qp_token
);
953 qp
= port
->port_res
[qp_token
].qp
;
955 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
958 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
959 if ((aer
& EHEA_AER_RESET_MASK
) ||
960 (aerr
& EHEA_AERR_RESET_MASK
))
963 reset_port
= 1; /* Reset in case of CQ or EQ error */
965 eqe
= ehea_poll_eq(port
->qp_eq
);
969 pr_err("Resetting port\n");
970 ehea_schedule_port_reset(port
);
976 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
981 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
982 if (adapter
->port
[i
])
983 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
984 return adapter
->port
[i
];
988 int ehea_sense_port_attr(struct ehea_port
*port
)
992 struct hcp_ehea_port_cb0
*cb0
;
994 /* may be called via ehea_neq_tasklet() */
995 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
997 pr_err("no mem for cb0\n");
1002 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1003 port
->logical_port_id
, H_PORT_CB0
,
1004 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1006 if (hret
!= H_SUCCESS
) {
1012 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1014 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1015 ret
= -EADDRNOTAVAIL
;
1020 switch (cb0
->port_speed
) {
1022 port
->port_speed
= EHEA_SPEED_10M
;
1023 port
->full_duplex
= 0;
1026 port
->port_speed
= EHEA_SPEED_10M
;
1027 port
->full_duplex
= 1;
1029 case H_SPEED_100M_H
:
1030 port
->port_speed
= EHEA_SPEED_100M
;
1031 port
->full_duplex
= 0;
1033 case H_SPEED_100M_F
:
1034 port
->port_speed
= EHEA_SPEED_100M
;
1035 port
->full_duplex
= 1;
1038 port
->port_speed
= EHEA_SPEED_1G
;
1039 port
->full_duplex
= 1;
1042 port
->port_speed
= EHEA_SPEED_10G
;
1043 port
->full_duplex
= 1;
1046 port
->port_speed
= 0;
1047 port
->full_duplex
= 0;
1052 port
->num_mcs
= cb0
->num_default_qps
;
1054 /* Number of default QPs */
1056 port
->num_def_qps
= cb0
->num_default_qps
;
1058 port
->num_def_qps
= 1;
1060 if (!port
->num_def_qps
) {
1067 if (ret
|| netif_msg_probe(port
))
1068 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1069 free_page((unsigned long)cb0
);
1074 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1076 struct hcp_ehea_port_cb4
*cb4
;
1080 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1082 pr_err("no mem for cb4\n");
1087 cb4
->port_speed
= port_speed
;
1089 netif_carrier_off(port
->netdev
);
1091 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1092 port
->logical_port_id
,
1093 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1094 if (hret
== H_SUCCESS
) {
1095 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1097 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1098 port
->logical_port_id
,
1099 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1101 if (hret
== H_SUCCESS
) {
1102 switch (cb4
->port_speed
) {
1104 port
->port_speed
= EHEA_SPEED_10M
;
1105 port
->full_duplex
= 0;
1108 port
->port_speed
= EHEA_SPEED_10M
;
1109 port
->full_duplex
= 1;
1111 case H_SPEED_100M_H
:
1112 port
->port_speed
= EHEA_SPEED_100M
;
1113 port
->full_duplex
= 0;
1115 case H_SPEED_100M_F
:
1116 port
->port_speed
= EHEA_SPEED_100M
;
1117 port
->full_duplex
= 1;
1120 port
->port_speed
= EHEA_SPEED_1G
;
1121 port
->full_duplex
= 1;
1124 port
->port_speed
= EHEA_SPEED_10G
;
1125 port
->full_duplex
= 1;
1128 port
->port_speed
= 0;
1129 port
->full_duplex
= 0;
1133 pr_err("Failed sensing port speed\n");
1137 if (hret
== H_AUTHORITY
) {
1138 pr_info("Hypervisor denied setting port speed\n");
1142 pr_err("Failed setting port speed\n");
1145 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1146 netif_carrier_on(port
->netdev
);
1148 free_page((unsigned long)cb4
);
1153 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1158 struct ehea_port
*port
;
1159 struct net_device
*dev
;
1161 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1162 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1163 port
= ehea_get_port(adapter
, portnum
);
1167 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1170 netdev_err(dev
, "unknown portnum %x\n", portnum
);
1174 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1175 if (!netif_carrier_ok(dev
)) {
1176 ret
= ehea_sense_port_attr(port
);
1178 netdev_err(dev
, "failed resensing port attributes\n");
1182 netif_info(port
, link
, dev
,
1183 "Logical port up: %dMbps %s Duplex\n",
1185 port
->full_duplex
== 1 ?
1188 netif_carrier_on(dev
);
1189 netif_wake_queue(dev
);
1192 if (netif_carrier_ok(dev
)) {
1193 netif_info(port
, link
, dev
,
1194 "Logical port down\n");
1195 netif_carrier_off(dev
);
1196 netif_tx_disable(dev
);
1199 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1200 port
->phy_link
= EHEA_PHY_LINK_UP
;
1201 netif_info(port
, link
, dev
,
1202 "Physical port up\n");
1203 if (prop_carrier_state
)
1204 netif_carrier_on(dev
);
1206 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1207 netif_info(port
, link
, dev
,
1208 "Physical port down\n");
1209 if (prop_carrier_state
)
1210 netif_carrier_off(dev
);
1213 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1215 "External switch port is primary port\n");
1218 "External switch port is backup port\n");
1221 case EHEA_EC_ADAPTER_MALFUNC
:
1222 netdev_err(dev
, "Adapter malfunction\n");
1224 case EHEA_EC_PORT_MALFUNC
:
1225 netdev_info(dev
, "Port malfunction\n");
1226 netif_carrier_off(dev
);
1227 netif_tx_disable(dev
);
1230 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1235 static void ehea_neq_tasklet(unsigned long data
)
1237 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1238 struct ehea_eqe
*eqe
;
1241 eqe
= ehea_poll_eq(adapter
->neq
);
1242 pr_debug("eqe=%p\n", eqe
);
1245 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1246 ehea_parse_eqe(adapter
, eqe
->entry
);
1247 eqe
= ehea_poll_eq(adapter
->neq
);
1248 pr_debug("next eqe=%p\n", eqe
);
1251 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1252 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1253 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1255 ehea_h_reset_events(adapter
->handle
,
1256 adapter
->neq
->fw_handle
, event_mask
);
1259 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1261 struct ehea_adapter
*adapter
= param
;
1262 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1267 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1270 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1272 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1274 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1276 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1281 static int ehea_reg_interrupts(struct net_device
*dev
)
1283 struct ehea_port
*port
= netdev_priv(dev
);
1284 struct ehea_port_res
*pr
;
1288 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1291 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1292 ehea_qp_aff_irq_handler
,
1293 IRQF_DISABLED
, port
->int_aff_name
, port
);
1295 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1296 port
->qp_eq
->attr
.ist1
);
1300 netif_info(port
, ifup
, dev
,
1301 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1302 port
->qp_eq
->attr
.ist1
);
1305 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1306 pr
= &port
->port_res
[i
];
1307 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1308 "%s-queue%d", dev
->name
, i
);
1309 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1310 ehea_recv_irq_handler
,
1311 IRQF_DISABLED
, pr
->int_send_name
,
1314 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1315 i
, pr
->eq
->attr
.ist1
);
1318 netif_info(port
, ifup
, dev
,
1319 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1320 pr
->eq
->attr
.ist1
, i
);
1328 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1329 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1333 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1334 i
= port
->num_def_qps
;
1340 static void ehea_free_interrupts(struct net_device
*dev
)
1342 struct ehea_port
*port
= netdev_priv(dev
);
1343 struct ehea_port_res
*pr
;
1348 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1349 pr
= &port
->port_res
[i
];
1350 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1351 netif_info(port
, intr
, dev
,
1352 "free send irq for res %d with handle 0x%X\n",
1353 i
, pr
->eq
->attr
.ist1
);
1356 /* associated events */
1357 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1358 netif_info(port
, intr
, dev
,
1359 "associated event interrupt for handle 0x%X freed\n",
1360 port
->qp_eq
->attr
.ist1
);
1363 static int ehea_configure_port(struct ehea_port
*port
)
1367 struct hcp_ehea_port_cb0
*cb0
;
1370 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1374 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1375 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1376 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1377 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1378 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1379 PXLY_RC_VLAN_FILTER
)
1380 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1382 for (i
= 0; i
< port
->num_mcs
; i
++)
1384 cb0
->default_qpn_arr
[i
] =
1385 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1387 cb0
->default_qpn_arr
[i
] =
1388 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1390 if (netif_msg_ifup(port
))
1391 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1393 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1394 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1396 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1397 port
->logical_port_id
,
1398 H_PORT_CB0
, mask
, cb0
);
1400 if (hret
!= H_SUCCESS
)
1406 free_page((unsigned long)cb0
);
1411 static int ehea_gen_smrs(struct ehea_port_res
*pr
)
1414 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1416 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1420 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1427 ehea_rem_mr(&pr
->send_mr
);
1429 pr_err("Generating SMRS failed\n");
1433 static int ehea_rem_smrs(struct ehea_port_res
*pr
)
1435 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1436 (ehea_rem_mr(&pr
->recv_mr
)))
1442 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1444 int arr_size
= sizeof(void *) * max_q_entries
;
1446 q_skba
->arr
= vzalloc(arr_size
);
1450 q_skba
->len
= max_q_entries
;
1452 q_skba
->os_skbs
= 0;
1457 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1458 struct port_res_cfg
*pr_cfg
, int queue_token
)
1460 struct ehea_adapter
*adapter
= port
->adapter
;
1461 enum ehea_eq_type eq_type
= EHEA_EQ
;
1462 struct ehea_qp_init_attr
*init_attr
= NULL
;
1464 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1466 tx_bytes
= pr
->tx_bytes
;
1467 tx_packets
= pr
->tx_packets
;
1468 rx_bytes
= pr
->rx_bytes
;
1469 rx_packets
= pr
->rx_packets
;
1471 memset(pr
, 0, sizeof(struct ehea_port_res
));
1473 pr
->tx_bytes
= rx_bytes
;
1474 pr
->tx_packets
= tx_packets
;
1475 pr
->rx_bytes
= rx_bytes
;
1476 pr
->rx_packets
= rx_packets
;
1480 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1482 pr_err("create_eq failed (eq)\n");
1486 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1488 port
->logical_port_id
);
1490 pr_err("create_cq failed (cq_recv)\n");
1494 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1496 port
->logical_port_id
);
1498 pr_err("create_cq failed (cq_send)\n");
1502 if (netif_msg_ifup(port
))
1503 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1504 pr
->send_cq
->attr
.act_nr_of_cqes
,
1505 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1507 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1510 pr_err("no mem for ehea_qp_init_attr\n");
1514 init_attr
->low_lat_rq1
= 1;
1515 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1516 init_attr
->rq_count
= 3;
1517 init_attr
->qp_token
= queue_token
;
1518 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1519 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1520 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1521 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1522 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1523 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1524 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1525 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1526 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1527 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1528 init_attr
->port_nr
= port
->logical_port_id
;
1529 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1530 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1531 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1533 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1535 pr_err("create_qp failed\n");
1540 if (netif_msg_ifup(port
))
1541 pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n",
1543 init_attr
->act_nr_send_wqes
,
1544 init_attr
->act_nr_rwqes_rq1
,
1545 init_attr
->act_nr_rwqes_rq2
,
1546 init_attr
->act_nr_rwqes_rq3
);
1548 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1550 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1551 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1552 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1553 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1557 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1558 if (ehea_gen_smrs(pr
) != 0) {
1563 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1567 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1574 vfree(pr
->sq_skba
.arr
);
1575 vfree(pr
->rq1_skba
.arr
);
1576 vfree(pr
->rq2_skba
.arr
);
1577 vfree(pr
->rq3_skba
.arr
);
1578 ehea_destroy_qp(pr
->qp
);
1579 ehea_destroy_cq(pr
->send_cq
);
1580 ehea_destroy_cq(pr
->recv_cq
);
1581 ehea_destroy_eq(pr
->eq
);
1586 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1591 netif_napi_del(&pr
->napi
);
1593 ret
= ehea_destroy_qp(pr
->qp
);
1596 ehea_destroy_cq(pr
->send_cq
);
1597 ehea_destroy_cq(pr
->recv_cq
);
1598 ehea_destroy_eq(pr
->eq
);
1600 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1601 if (pr
->rq1_skba
.arr
[i
])
1602 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1604 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1605 if (pr
->rq2_skba
.arr
[i
])
1606 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1608 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1609 if (pr
->rq3_skba
.arr
[i
])
1610 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1612 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1613 if (pr
->sq_skba
.arr
[i
])
1614 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1616 vfree(pr
->rq1_skba
.arr
);
1617 vfree(pr
->rq2_skba
.arr
);
1618 vfree(pr
->rq3_skba
.arr
);
1619 vfree(pr
->sq_skba
.arr
);
1620 ret
= ehea_rem_smrs(pr
);
1625 static void write_swqe2_immediate(struct sk_buff
*skb
, struct ehea_swqe
*swqe
,
1628 int skb_data_size
= skb_headlen(skb
);
1629 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1630 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1631 unsigned int immediate_len
= SWQE2_MAX_IMM
;
1633 swqe
->descriptors
= 0;
1635 if (skb_is_gso(skb
)) {
1636 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1637 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1639 * For TSO packets we only copy the headers into the
1642 immediate_len
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1645 if (skb_is_gso(skb
) || skb_data_size
>= SWQE2_MAX_IMM
) {
1646 skb_copy_from_linear_data(skb
, imm_data
, immediate_len
);
1647 swqe
->immediate_data_length
= immediate_len
;
1649 if (skb_data_size
> immediate_len
) {
1650 sg1entry
->l_key
= lkey
;
1651 sg1entry
->len
= skb_data_size
- immediate_len
;
1653 ehea_map_vaddr(skb
->data
+ immediate_len
);
1654 swqe
->descriptors
++;
1657 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1658 swqe
->immediate_data_length
= skb_data_size
;
1662 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1663 struct ehea_swqe
*swqe
, u32 lkey
)
1665 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1667 int nfrags
, sg1entry_contains_frag_data
, i
;
1669 nfrags
= skb_shinfo(skb
)->nr_frags
;
1670 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1671 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1672 sg1entry_contains_frag_data
= 0;
1674 write_swqe2_immediate(skb
, swqe
, lkey
);
1676 /* write descriptors */
1678 if (swqe
->descriptors
== 0) {
1679 /* sg1entry not yet used */
1680 frag
= &skb_shinfo(skb
)->frags
[0];
1682 /* copy sg1entry data */
1683 sg1entry
->l_key
= lkey
;
1684 sg1entry
->len
= skb_frag_size(frag
);
1686 ehea_map_vaddr(skb_frag_address(frag
));
1687 swqe
->descriptors
++;
1688 sg1entry_contains_frag_data
= 1;
1691 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1693 frag
= &skb_shinfo(skb
)->frags
[i
];
1694 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1696 sgentry
->l_key
= lkey
;
1697 sgentry
->len
= skb_frag_size(frag
);
1698 sgentry
->vaddr
= ehea_map_vaddr(skb_frag_address(frag
));
1699 swqe
->descriptors
++;
1704 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1710 /* De/Register untagged packets */
1711 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1712 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1713 port
->logical_port_id
,
1714 reg_type
, port
->mac_addr
, 0, hcallid
);
1715 if (hret
!= H_SUCCESS
) {
1716 pr_err("%sregistering bc address failed (tagged)\n",
1717 hcallid
== H_REG_BCMC
? "" : "de");
1722 /* De/Register VLAN packets */
1723 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1724 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1725 port
->logical_port_id
,
1726 reg_type
, port
->mac_addr
, 0, hcallid
);
1727 if (hret
!= H_SUCCESS
) {
1728 pr_err("%sregistering bc address failed (vlan)\n",
1729 hcallid
== H_REG_BCMC
? "" : "de");
1736 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1738 struct ehea_port
*port
= netdev_priv(dev
);
1739 struct sockaddr
*mac_addr
= sa
;
1740 struct hcp_ehea_port_cb0
*cb0
;
1744 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1745 ret
= -EADDRNOTAVAIL
;
1749 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1751 pr_err("no mem for cb0\n");
1756 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1758 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1760 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1761 port
->logical_port_id
, H_PORT_CB0
,
1762 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1763 if (hret
!= H_SUCCESS
) {
1768 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1770 /* Deregister old MAC in pHYP */
1771 if (port
->state
== EHEA_PORT_UP
) {
1772 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1777 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1779 /* Register new MAC in pHYP */
1780 if (port
->state
== EHEA_PORT_UP
) {
1781 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1789 ehea_update_bcmc_registrations();
1791 free_page((unsigned long)cb0
);
1796 static void ehea_promiscuous_error(u64 hret
, int enable
)
1798 if (hret
== H_AUTHORITY
)
1799 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1800 enable
== 1 ? "en" : "dis");
1802 pr_err("failed %sabling promiscuous mode\n",
1803 enable
== 1 ? "en" : "dis");
1806 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1808 struct ehea_port
*port
= netdev_priv(dev
);
1809 struct hcp_ehea_port_cb7
*cb7
;
1812 if (enable
== port
->promisc
)
1815 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1817 pr_err("no mem for cb7\n");
1821 /* Modify Pxs_DUCQPN in CB7 */
1822 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1824 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1825 port
->logical_port_id
,
1826 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1828 ehea_promiscuous_error(hret
, enable
);
1832 port
->promisc
= enable
;
1834 free_page((unsigned long)cb7
);
1837 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1843 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_UNTAGGED
;
1844 if (mc_mac_addr
== 0)
1845 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1847 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1848 port
->logical_port_id
,
1849 reg_type
, mc_mac_addr
, 0, hcallid
);
1853 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_VLANID_ALL
;
1854 if (mc_mac_addr
== 0)
1855 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1857 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1858 port
->logical_port_id
,
1859 reg_type
, mc_mac_addr
, 0, hcallid
);
1864 static int ehea_drop_multicast_list(struct net_device
*dev
)
1866 struct ehea_port
*port
= netdev_priv(dev
);
1867 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1868 struct list_head
*pos
;
1869 struct list_head
*temp
;
1873 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1874 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1876 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1879 pr_err("failed deregistering mcast MAC\n");
1889 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1891 struct ehea_port
*port
= netdev_priv(dev
);
1894 if (!port
->allmulti
) {
1896 /* Enable ALLMULTI */
1897 ehea_drop_multicast_list(dev
);
1898 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1903 "failed enabling IFF_ALLMULTI\n");
1907 /* Disable ALLMULTI */
1908 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1913 "failed disabling IFF_ALLMULTI\n");
1918 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1920 struct ehea_mc_list
*ehea_mcl_entry
;
1923 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1924 if (!ehea_mcl_entry
) {
1925 pr_err("no mem for mcl_entry\n");
1929 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1931 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1933 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1936 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1938 pr_err("failed registering mcast MAC\n");
1939 kfree(ehea_mcl_entry
);
1943 static void ehea_set_multicast_list(struct net_device
*dev
)
1945 struct ehea_port
*port
= netdev_priv(dev
);
1946 struct netdev_hw_addr
*ha
;
1949 ehea_promiscuous(dev
, !!(dev
->flags
& IFF_PROMISC
));
1951 if (dev
->flags
& IFF_ALLMULTI
) {
1952 ehea_allmulti(dev
, 1);
1955 ehea_allmulti(dev
, 0);
1957 if (!netdev_mc_empty(dev
)) {
1958 ret
= ehea_drop_multicast_list(dev
);
1960 /* Dropping the current multicast list failed.
1961 * Enabling ALL_MULTI is the best we can do.
1963 ehea_allmulti(dev
, 1);
1966 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
1967 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1968 port
->adapter
->max_mc_mac
);
1972 netdev_for_each_mc_addr(ha
, dev
)
1973 ehea_add_multicast_entry(port
, ha
->addr
);
1977 ehea_update_bcmc_registrations();
1980 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1982 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1988 static void xmit_common(struct sk_buff
*skb
, struct ehea_swqe
*swqe
)
1990 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
| EHEA_SWQE_CRC
;
1992 if (skb
->protocol
!= htons(ETH_P_IP
))
1995 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1996 swqe
->tx_control
|= EHEA_SWQE_IP_CHECKSUM
;
1998 swqe
->ip_start
= skb_network_offset(skb
);
1999 swqe
->ip_end
= swqe
->ip_start
+ ip_hdrlen(skb
) - 1;
2001 switch (ip_hdr(skb
)->protocol
) {
2003 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2004 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2006 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2007 offsetof(struct udphdr
, check
);
2011 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2012 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2014 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2015 offsetof(struct tcphdr
, check
);
2020 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2021 struct ehea_swqe
*swqe
, u32 lkey
)
2023 swqe
->tx_control
|= EHEA_SWQE_DESCRIPTORS_PRESENT
;
2025 xmit_common(skb
, swqe
);
2027 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2030 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2031 struct ehea_swqe
*swqe
)
2033 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2035 xmit_common(skb
, swqe
);
2038 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2040 skb_copy_bits(skb
, 0, imm_data
, skb
->len
);
2042 swqe
->immediate_data_length
= skb
->len
;
2046 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2048 struct ehea_port
*port
= netdev_priv(dev
);
2049 struct ehea_swqe
*swqe
;
2052 struct ehea_port_res
*pr
;
2053 struct netdev_queue
*txq
;
2055 pr
= &port
->port_res
[skb_get_queue_mapping(skb
)];
2056 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
2058 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2059 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2060 atomic_dec(&pr
->swqe_avail
);
2062 if (vlan_tx_tag_present(skb
)) {
2063 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2064 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2068 pr
->tx_bytes
+= skb
->len
;
2070 if (skb
->len
<= SWQE3_MAX_IMM
) {
2071 u32 sig_iv
= port
->sig_comp_iv
;
2072 u32 swqe_num
= pr
->swqe_id_counter
;
2073 ehea_xmit3(skb
, dev
, swqe
);
2074 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2075 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2076 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2077 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2079 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2080 pr
->swqe_ll_count
= 0;
2082 pr
->swqe_ll_count
+= 1;
2085 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2086 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2087 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2088 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2089 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2091 pr
->sq_skba
.index
++;
2092 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2094 lkey
= pr
->send_mr
.lkey
;
2095 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2096 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2098 pr
->swqe_id_counter
+= 1;
2100 netif_info(port
, tx_queued
, dev
,
2101 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2102 if (netif_msg_tx_queued(port
))
2103 ehea_dump(swqe
, 512, "swqe");
2105 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2106 netif_tx_stop_queue(txq
);
2107 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2110 ehea_post_swqe(pr
->qp
, swqe
);
2112 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2113 pr
->p_stats
.queue_stopped
++;
2114 netif_tx_stop_queue(txq
);
2117 return NETDEV_TX_OK
;
2120 static int ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2122 struct ehea_port
*port
= netdev_priv(dev
);
2123 struct ehea_adapter
*adapter
= port
->adapter
;
2124 struct hcp_ehea_port_cb1
*cb1
;
2129 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2131 pr_err("no mem for cb1\n");
2136 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2137 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2138 if (hret
!= H_SUCCESS
) {
2139 pr_err("query_ehea_port failed\n");
2145 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2147 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2148 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2149 if (hret
!= H_SUCCESS
) {
2150 pr_err("modify_ehea_port failed\n");
2154 free_page((unsigned long)cb1
);
2158 static int ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2160 struct ehea_port
*port
= netdev_priv(dev
);
2161 struct ehea_adapter
*adapter
= port
->adapter
;
2162 struct hcp_ehea_port_cb1
*cb1
;
2167 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2169 pr_err("no mem for cb1\n");
2174 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2175 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2176 if (hret
!= H_SUCCESS
) {
2177 pr_err("query_ehea_port failed\n");
2183 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2185 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2186 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2187 if (hret
!= H_SUCCESS
) {
2188 pr_err("modify_ehea_port failed\n");
2192 free_page((unsigned long)cb1
);
2196 static int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2202 struct hcp_modify_qp_cb0
*cb0
;
2204 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2210 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2211 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2212 if (hret
!= H_SUCCESS
) {
2213 pr_err("query_ehea_qp failed (1)\n");
2217 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2218 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2219 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2220 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2221 if (hret
!= H_SUCCESS
) {
2222 pr_err("modify_ehea_qp failed (1)\n");
2226 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2227 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2228 if (hret
!= H_SUCCESS
) {
2229 pr_err("query_ehea_qp failed (2)\n");
2233 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2234 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2235 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2236 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2237 if (hret
!= H_SUCCESS
) {
2238 pr_err("modify_ehea_qp failed (2)\n");
2242 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2243 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2244 if (hret
!= H_SUCCESS
) {
2245 pr_err("query_ehea_qp failed (3)\n");
2249 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2250 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2251 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2252 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2253 if (hret
!= H_SUCCESS
) {
2254 pr_err("modify_ehea_qp failed (3)\n");
2258 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2259 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2260 if (hret
!= H_SUCCESS
) {
2261 pr_err("query_ehea_qp failed (4)\n");
2267 free_page((unsigned long)cb0
);
2271 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
)
2274 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2275 enum ehea_eq_type eq_type
= EHEA_EQ
;
2277 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2278 EHEA_MAX_ENTRIES_EQ
, 1);
2281 pr_err("ehea_create_eq failed (qp_eq)\n");
2285 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2286 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2287 pr_cfg
.max_entries_sq
= sq_entries
;
2288 pr_cfg
.max_entries_rq1
= rq1_entries
;
2289 pr_cfg
.max_entries_rq2
= rq2_entries
;
2290 pr_cfg
.max_entries_rq3
= rq3_entries
;
2292 pr_cfg_small_rx
.max_entries_rcq
= 1;
2293 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2294 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2295 pr_cfg_small_rx
.max_entries_rq1
= 1;
2296 pr_cfg_small_rx
.max_entries_rq2
= 1;
2297 pr_cfg_small_rx
.max_entries_rq3
= 1;
2299 for (i
= 0; i
< def_qps
; i
++) {
2300 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2304 for (i
= def_qps
; i
< def_qps
; i
++) {
2305 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2306 &pr_cfg_small_rx
, i
);
2315 ehea_clean_portres(port
, &port
->port_res
[i
]);
2318 ehea_destroy_eq(port
->qp_eq
);
2322 static int ehea_clean_all_portres(struct ehea_port
*port
)
2327 for (i
= 0; i
< port
->num_def_qps
; i
++)
2328 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2330 ret
|= ehea_destroy_eq(port
->qp_eq
);
2335 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2337 if (adapter
->active_ports
)
2340 ehea_rem_mr(&adapter
->mr
);
2343 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2345 if (adapter
->active_ports
)
2348 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2351 static int ehea_up(struct net_device
*dev
)
2354 struct ehea_port
*port
= netdev_priv(dev
);
2356 if (port
->state
== EHEA_PORT_UP
)
2359 ret
= ehea_port_res_setup(port
, port
->num_def_qps
);
2361 netdev_err(dev
, "port_res_failed\n");
2365 /* Set default QP for this port */
2366 ret
= ehea_configure_port(port
);
2368 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2372 ret
= ehea_reg_interrupts(dev
);
2374 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2378 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2379 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2381 netdev_err(dev
, "activate_qp failed\n");
2386 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2387 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2389 netdev_err(dev
, "out_free_irqs\n");
2394 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2400 port
->state
= EHEA_PORT_UP
;
2406 ehea_free_interrupts(dev
);
2409 ehea_clean_all_portres(port
);
2412 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2414 ehea_update_bcmc_registrations();
2415 ehea_update_firmware_handles();
2420 static void port_napi_disable(struct ehea_port
*port
)
2424 for (i
= 0; i
< port
->num_def_qps
; i
++)
2425 napi_disable(&port
->port_res
[i
].napi
);
2428 static void port_napi_enable(struct ehea_port
*port
)
2432 for (i
= 0; i
< port
->num_def_qps
; i
++)
2433 napi_enable(&port
->port_res
[i
].napi
);
2436 static int ehea_open(struct net_device
*dev
)
2439 struct ehea_port
*port
= netdev_priv(dev
);
2441 mutex_lock(&port
->port_lock
);
2443 netif_info(port
, ifup
, dev
, "enabling port\n");
2447 port_napi_enable(port
);
2448 netif_tx_start_all_queues(dev
);
2451 mutex_unlock(&port
->port_lock
);
2452 schedule_delayed_work(&port
->stats_work
,
2453 round_jiffies_relative(msecs_to_jiffies(1000)));
2458 static int ehea_down(struct net_device
*dev
)
2461 struct ehea_port
*port
= netdev_priv(dev
);
2463 if (port
->state
== EHEA_PORT_DOWN
)
2466 ehea_drop_multicast_list(dev
);
2467 ehea_allmulti(dev
, 0);
2468 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2470 ehea_free_interrupts(dev
);
2472 port
->state
= EHEA_PORT_DOWN
;
2474 ehea_update_bcmc_registrations();
2476 ret
= ehea_clean_all_portres(port
);
2478 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2480 ehea_update_firmware_handles();
2485 static int ehea_stop(struct net_device
*dev
)
2488 struct ehea_port
*port
= netdev_priv(dev
);
2490 netif_info(port
, ifdown
, dev
, "disabling port\n");
2492 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2493 cancel_work_sync(&port
->reset_task
);
2494 cancel_delayed_work_sync(&port
->stats_work
);
2495 mutex_lock(&port
->port_lock
);
2496 netif_tx_stop_all_queues(dev
);
2497 port_napi_disable(port
);
2498 ret
= ehea_down(dev
);
2499 mutex_unlock(&port
->port_lock
);
2500 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2504 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2506 struct ehea_qp qp
= *orig_qp
;
2507 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2508 struct ehea_swqe
*swqe
;
2512 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2513 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2514 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2518 static void ehea_flush_sq(struct ehea_port
*port
)
2522 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2523 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2524 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2527 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2528 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2529 msecs_to_jiffies(100));
2532 pr_err("WARNING: sq not flushed completely\n");
2538 static int ehea_stop_qps(struct net_device
*dev
)
2540 struct ehea_port
*port
= netdev_priv(dev
);
2541 struct ehea_adapter
*adapter
= port
->adapter
;
2542 struct hcp_modify_qp_cb0
*cb0
;
2550 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2556 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2557 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2558 struct ehea_qp
*qp
= pr
->qp
;
2560 /* Purge send queue */
2563 /* Disable queue pair */
2564 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2565 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2567 if (hret
!= H_SUCCESS
) {
2568 pr_err("query_ehea_qp failed (1)\n");
2572 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2573 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2575 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2576 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2578 &dummy64
, &dummy16
, &dummy16
);
2579 if (hret
!= H_SUCCESS
) {
2580 pr_err("modify_ehea_qp failed (1)\n");
2584 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2585 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2587 if (hret
!= H_SUCCESS
) {
2588 pr_err("query_ehea_qp failed (2)\n");
2592 /* deregister shared memory regions */
2593 dret
= ehea_rem_smrs(pr
);
2595 pr_err("unreg shared memory region failed\n");
2602 free_page((unsigned long)cb0
);
2607 static void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2609 struct ehea_qp qp
= *orig_qp
;
2610 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2611 struct ehea_rwqe
*rwqe
;
2612 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2613 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2614 struct sk_buff
*skb
;
2615 u32 lkey
= pr
->recv_mr
.lkey
;
2621 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2622 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2623 rwqe
->sg_list
[0].l_key
= lkey
;
2624 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2625 skb
= skba_rq2
[index
];
2627 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2630 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2631 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2632 rwqe
->sg_list
[0].l_key
= lkey
;
2633 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2634 skb
= skba_rq3
[index
];
2636 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2640 static int ehea_restart_qps(struct net_device
*dev
)
2642 struct ehea_port
*port
= netdev_priv(dev
);
2643 struct ehea_adapter
*adapter
= port
->adapter
;
2647 struct hcp_modify_qp_cb0
*cb0
;
2652 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2658 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2659 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2660 struct ehea_qp
*qp
= pr
->qp
;
2662 ret
= ehea_gen_smrs(pr
);
2664 netdev_err(dev
, "creation of shared memory regions failed\n");
2668 ehea_update_rqs(qp
, pr
);
2670 /* Enable queue pair */
2671 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2672 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2674 if (hret
!= H_SUCCESS
) {
2675 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2679 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2680 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2682 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2683 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2685 &dummy64
, &dummy16
, &dummy16
);
2686 if (hret
!= H_SUCCESS
) {
2687 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2691 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2692 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2694 if (hret
!= H_SUCCESS
) {
2695 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2699 /* refill entire queue */
2700 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2701 ehea_refill_rq2(pr
, 0);
2702 ehea_refill_rq3(pr
, 0);
2705 free_page((unsigned long)cb0
);
2710 static void ehea_reset_port(struct work_struct
*work
)
2713 struct ehea_port
*port
=
2714 container_of(work
, struct ehea_port
, reset_task
);
2715 struct net_device
*dev
= port
->netdev
;
2717 mutex_lock(&dlpar_mem_lock
);
2719 mutex_lock(&port
->port_lock
);
2720 netif_tx_disable(dev
);
2722 port_napi_disable(port
);
2730 ehea_set_multicast_list(dev
);
2732 netif_info(port
, timer
, dev
, "reset successful\n");
2734 port_napi_enable(port
);
2736 netif_tx_wake_all_queues(dev
);
2738 mutex_unlock(&port
->port_lock
);
2739 mutex_unlock(&dlpar_mem_lock
);
2742 static void ehea_rereg_mrs(void)
2745 struct ehea_adapter
*adapter
;
2747 pr_info("LPAR memory changed - re-initializing driver\n");
2749 list_for_each_entry(adapter
, &adapter_list
, list
)
2750 if (adapter
->active_ports
) {
2751 /* Shutdown all ports */
2752 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2753 struct ehea_port
*port
= adapter
->port
[i
];
2754 struct net_device
*dev
;
2761 if (dev
->flags
& IFF_UP
) {
2762 mutex_lock(&port
->port_lock
);
2763 netif_tx_disable(dev
);
2764 ehea_flush_sq(port
);
2765 ret
= ehea_stop_qps(dev
);
2767 mutex_unlock(&port
->port_lock
);
2770 port_napi_disable(port
);
2771 mutex_unlock(&port
->port_lock
);
2773 reset_sq_restart_flag(port
);
2776 /* Unregister old memory region */
2777 ret
= ehea_rem_mr(&adapter
->mr
);
2779 pr_err("unregister MR failed - driver inoperable!\n");
2784 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2786 list_for_each_entry(adapter
, &adapter_list
, list
)
2787 if (adapter
->active_ports
) {
2788 /* Register new memory region */
2789 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2791 pr_err("register MR failed - driver inoperable!\n");
2795 /* Restart all ports */
2796 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2797 struct ehea_port
*port
= adapter
->port
[i
];
2800 struct net_device
*dev
= port
->netdev
;
2802 if (dev
->flags
& IFF_UP
) {
2803 mutex_lock(&port
->port_lock
);
2804 ret
= ehea_restart_qps(dev
);
2807 port_napi_enable(port
);
2808 netif_tx_wake_all_queues(dev
);
2810 netdev_err(dev
, "Unable to restart QPS\n");
2812 mutex_unlock(&port
->port_lock
);
2817 pr_info("re-initializing driver complete\n");
2822 static void ehea_tx_watchdog(struct net_device
*dev
)
2824 struct ehea_port
*port
= netdev_priv(dev
);
2826 if (netif_carrier_ok(dev
) &&
2827 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2828 ehea_schedule_port_reset(port
);
2831 static int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2833 struct hcp_query_ehea
*cb
;
2837 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2843 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2845 if (hret
!= H_SUCCESS
) {
2850 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2854 free_page((unsigned long)cb
);
2859 static int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2861 struct hcp_ehea_port_cb4
*cb4
;
2867 /* (Try to) enable *jumbo frames */
2868 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2870 pr_err("no mem for cb4\n");
2874 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2875 port
->logical_port_id
,
2877 H_PORT_CB4_JUMBO
, cb4
);
2878 if (hret
== H_SUCCESS
) {
2879 if (cb4
->jumbo_frame
)
2882 cb4
->jumbo_frame
= 1;
2883 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2890 if (hret
== H_SUCCESS
)
2896 free_page((unsigned long)cb4
);
2902 static ssize_t
ehea_show_port_id(struct device
*dev
,
2903 struct device_attribute
*attr
, char *buf
)
2905 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2906 return sprintf(buf
, "%d", port
->logical_port_id
);
2909 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2912 static void __devinit
logical_port_release(struct device
*dev
)
2914 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2915 of_node_put(port
->ofdev
.dev
.of_node
);
2918 static struct device
*ehea_register_port(struct ehea_port
*port
,
2919 struct device_node
*dn
)
2923 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
2924 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2925 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2927 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
2928 port
->ofdev
.dev
.release
= logical_port_release
;
2930 ret
= of_device_register(&port
->ofdev
);
2932 pr_err("failed to register device. ret=%d\n", ret
);
2936 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2938 pr_err("failed to register attributes, ret=%d\n", ret
);
2939 goto out_unreg_of_dev
;
2942 return &port
->ofdev
.dev
;
2945 of_device_unregister(&port
->ofdev
);
2950 static void ehea_unregister_port(struct ehea_port
*port
)
2952 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2953 of_device_unregister(&port
->ofdev
);
2956 static const struct net_device_ops ehea_netdev_ops
= {
2957 .ndo_open
= ehea_open
,
2958 .ndo_stop
= ehea_stop
,
2959 .ndo_start_xmit
= ehea_start_xmit
,
2960 #ifdef CONFIG_NET_POLL_CONTROLLER
2961 .ndo_poll_controller
= ehea_netpoll
,
2963 .ndo_get_stats64
= ehea_get_stats64
,
2964 .ndo_set_mac_address
= ehea_set_mac_addr
,
2965 .ndo_validate_addr
= eth_validate_addr
,
2966 .ndo_set_rx_mode
= ehea_set_multicast_list
,
2967 .ndo_change_mtu
= ehea_change_mtu
,
2968 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
2969 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
2970 .ndo_tx_timeout
= ehea_tx_watchdog
,
2973 static struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2974 u32 logical_port_id
,
2975 struct device_node
*dn
)
2978 struct net_device
*dev
;
2979 struct ehea_port
*port
;
2980 struct device
*port_dev
;
2983 /* allocate memory for the port structures */
2984 dev
= alloc_etherdev_mq(sizeof(struct ehea_port
), EHEA_MAX_PORT_RES
);
2991 port
= netdev_priv(dev
);
2993 mutex_init(&port
->port_lock
);
2994 port
->state
= EHEA_PORT_DOWN
;
2995 port
->sig_comp_iv
= sq_entries
/ 10;
2997 port
->adapter
= adapter
;
2999 port
->logical_port_id
= logical_port_id
;
3001 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3003 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3004 if (!port
->mc_list
) {
3006 goto out_free_ethdev
;
3009 INIT_LIST_HEAD(&port
->mc_list
->list
);
3011 ret
= ehea_sense_port_attr(port
);
3013 goto out_free_mc_list
;
3015 netif_set_real_num_rx_queues(dev
, port
->num_def_qps
);
3016 netif_set_real_num_tx_queues(dev
, port
->num_def_qps
);
3018 port_dev
= ehea_register_port(port
, dn
);
3020 goto out_free_mc_list
;
3022 SET_NETDEV_DEV(dev
, port_dev
);
3024 /* initialize net_device structure */
3025 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3027 dev
->netdev_ops
= &ehea_netdev_ops
;
3028 ehea_set_ethtool_ops(dev
);
3030 dev
->hw_features
= NETIF_F_SG
| NETIF_F_TSO
3031 | NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
| NETIF_F_LRO
;
3032 dev
->features
= NETIF_F_SG
| NETIF_F_TSO
3033 | NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
3034 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3036 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HIGHDMA
|
3038 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3040 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3041 INIT_DELAYED_WORK(&port
->stats_work
, ehea_update_stats
);
3043 init_waitqueue_head(&port
->swqe_avail_wq
);
3044 init_waitqueue_head(&port
->restart_wq
);
3046 memset(&port
->stats
, 0, sizeof(struct net_device_stats
));
3047 ret
= register_netdev(dev
);
3049 pr_err("register_netdev failed. ret=%d\n", ret
);
3050 goto out_unreg_port
;
3053 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3055 netdev_err(dev
, "failed determining jumbo frame status\n");
3057 netdev_info(dev
, "Jumbo frames are %sabled\n",
3058 jumbo
== 1 ? "en" : "dis");
3060 adapter
->active_ports
++;
3065 ehea_unregister_port(port
);
3068 kfree(port
->mc_list
);
3074 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3075 logical_port_id
, ret
);
3079 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3081 struct ehea_adapter
*adapter
= port
->adapter
;
3083 cancel_work_sync(&port
->reset_task
);
3084 cancel_delayed_work_sync(&port
->stats_work
);
3085 unregister_netdev(port
->netdev
);
3086 ehea_unregister_port(port
);
3087 kfree(port
->mc_list
);
3088 free_netdev(port
->netdev
);
3089 adapter
->active_ports
--;
3092 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3094 struct device_node
*lhea_dn
;
3095 struct device_node
*eth_dn
= NULL
;
3097 const u32
*dn_log_port_id
;
3100 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3101 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3103 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3105 if (!dn_log_port_id
) {
3106 pr_err("bad device node: eth_dn name=%s\n",
3111 if (ehea_add_adapter_mr(adapter
)) {
3112 pr_err("creating MR failed\n");
3113 of_node_put(eth_dn
);
3117 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3120 if (adapter
->port
[i
])
3121 netdev_info(adapter
->port
[i
]->netdev
,
3122 "logical port id #%d\n", *dn_log_port_id
);
3124 ehea_remove_adapter_mr(adapter
);
3131 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3132 u32 logical_port_id
)
3134 struct device_node
*lhea_dn
;
3135 struct device_node
*eth_dn
= NULL
;
3136 const u32
*dn_log_port_id
;
3138 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3139 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3141 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3144 if (*dn_log_port_id
== logical_port_id
)
3151 static ssize_t
ehea_probe_port(struct device
*dev
,
3152 struct device_attribute
*attr
,
3153 const char *buf
, size_t count
)
3155 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3156 struct ehea_port
*port
;
3157 struct device_node
*eth_dn
= NULL
;
3160 u32 logical_port_id
;
3162 sscanf(buf
, "%d", &logical_port_id
);
3164 port
= ehea_get_port(adapter
, logical_port_id
);
3167 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3172 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3175 pr_info("no logical port with id %d found\n", logical_port_id
);
3179 if (ehea_add_adapter_mr(adapter
)) {
3180 pr_err("creating MR failed\n");
3184 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3186 of_node_put(eth_dn
);
3189 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3190 if (!adapter
->port
[i
]) {
3191 adapter
->port
[i
] = port
;
3195 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3198 ehea_remove_adapter_mr(adapter
);
3202 return (ssize_t
) count
;
3205 static ssize_t
ehea_remove_port(struct device
*dev
,
3206 struct device_attribute
*attr
,
3207 const char *buf
, size_t count
)
3209 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3210 struct ehea_port
*port
;
3212 u32 logical_port_id
;
3214 sscanf(buf
, "%d", &logical_port_id
);
3216 port
= ehea_get_port(adapter
, logical_port_id
);
3219 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3222 ehea_shutdown_single_port(port
);
3224 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3225 if (adapter
->port
[i
] == port
) {
3226 adapter
->port
[i
] = NULL
;
3230 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3235 ehea_remove_adapter_mr(adapter
);
3237 return (ssize_t
) count
;
3240 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3241 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3243 static int ehea_create_device_sysfs(struct platform_device
*dev
)
3245 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3249 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3254 static void ehea_remove_device_sysfs(struct platform_device
*dev
)
3256 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3257 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3260 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
3261 const struct of_device_id
*id
)
3263 struct ehea_adapter
*adapter
;
3264 const u64
*adapter_handle
;
3268 if (!dev
|| !dev
->dev
.of_node
) {
3269 pr_err("Invalid ibmebus device probed\n");
3273 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3276 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3280 list_add(&adapter
->list
, &adapter_list
);
3282 adapter
->ofdev
= dev
;
3284 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3287 adapter
->handle
= *adapter_handle
;
3289 if (!adapter
->handle
) {
3290 dev_err(&dev
->dev
, "failed getting handle for adapter"
3291 " '%s'\n", dev
->dev
.of_node
->full_name
);
3296 adapter
->pd
= EHEA_PD_ID
;
3298 dev_set_drvdata(&dev
->dev
, adapter
);
3301 /* initialize adapter and ports */
3302 /* get adapter properties */
3303 ret
= ehea_sense_adapter_attr(adapter
);
3305 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3309 adapter
->neq
= ehea_create_eq(adapter
,
3310 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3311 if (!adapter
->neq
) {
3313 dev_err(&dev
->dev
, "NEQ creation failed\n");
3317 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3318 (unsigned long)adapter
);
3320 ret
= ehea_create_device_sysfs(dev
);
3324 ret
= ehea_setup_ports(adapter
);
3326 dev_err(&dev
->dev
, "setup_ports failed\n");
3327 goto out_rem_dev_sysfs
;
3330 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3331 ehea_interrupt_neq
, IRQF_DISABLED
,
3332 "ehea_neq", adapter
);
3334 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3335 goto out_shutdown_ports
;
3338 /* Handle any events that might be pending. */
3339 tasklet_hi_schedule(&adapter
->neq_tasklet
);
3345 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3346 if (adapter
->port
[i
]) {
3347 ehea_shutdown_single_port(adapter
->port
[i
]);
3348 adapter
->port
[i
] = NULL
;
3352 ehea_remove_device_sysfs(dev
);
3355 ehea_destroy_eq(adapter
->neq
);
3358 list_del(&adapter
->list
);
3362 ehea_update_firmware_handles();
3367 static int __devexit
ehea_remove(struct platform_device
*dev
)
3369 struct ehea_adapter
*adapter
= dev_get_drvdata(&dev
->dev
);
3372 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3373 if (adapter
->port
[i
]) {
3374 ehea_shutdown_single_port(adapter
->port
[i
]);
3375 adapter
->port
[i
] = NULL
;
3378 ehea_remove_device_sysfs(dev
);
3380 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3381 tasklet_kill(&adapter
->neq_tasklet
);
3383 ehea_destroy_eq(adapter
->neq
);
3384 ehea_remove_adapter_mr(adapter
);
3385 list_del(&adapter
->list
);
3388 ehea_update_firmware_handles();
3393 static void ehea_crash_handler(void)
3397 if (ehea_fw_handles
.arr
)
3398 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3399 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3400 ehea_fw_handles
.arr
[i
].fwh
,
3403 if (ehea_bcmc_regs
.arr
)
3404 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3405 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3406 ehea_bcmc_regs
.arr
[i
].port_id
,
3407 ehea_bcmc_regs
.arr
[i
].reg_type
,
3408 ehea_bcmc_regs
.arr
[i
].macaddr
,
3412 static int ehea_mem_notifier(struct notifier_block
*nb
,
3413 unsigned long action
, void *data
)
3415 int ret
= NOTIFY_BAD
;
3416 struct memory_notify
*arg
= data
;
3418 mutex_lock(&dlpar_mem_lock
);
3421 case MEM_CANCEL_OFFLINE
:
3422 pr_info("memory offlining canceled");
3423 /* Readd canceled memory block */
3425 pr_info("memory is going online");
3426 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3427 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3431 case MEM_GOING_OFFLINE
:
3432 pr_info("memory is going offline");
3433 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3434 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3442 ehea_update_firmware_handles();
3446 mutex_unlock(&dlpar_mem_lock
);
3450 static struct notifier_block ehea_mem_nb
= {
3451 .notifier_call
= ehea_mem_notifier
,
3454 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3455 unsigned long action
, void *unused
)
3457 if (action
== SYS_RESTART
) {
3458 pr_info("Reboot: freeing all eHEA resources\n");
3459 ibmebus_unregister_driver(&ehea_driver
);
3464 static struct notifier_block ehea_reboot_nb
= {
3465 .notifier_call
= ehea_reboot_notifier
,
3468 static int check_module_parm(void)
3472 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3473 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3474 pr_info("Bad parameter: rq1_entries\n");
3477 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3478 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3479 pr_info("Bad parameter: rq2_entries\n");
3482 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3483 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3484 pr_info("Bad parameter: rq3_entries\n");
3487 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3488 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3489 pr_info("Bad parameter: sq_entries\n");
3496 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3499 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3502 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3503 ehea_show_capabilities
, NULL
);
3505 static int __init
ehea_module_init(void)
3509 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3511 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3512 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3514 mutex_init(&ehea_fw_handles
.lock
);
3515 spin_lock_init(&ehea_bcmc_regs
.lock
);
3517 ret
= check_module_parm();
3521 ret
= ehea_create_busmap();
3525 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3527 pr_info("failed registering reboot notifier\n");
3529 ret
= register_memory_notifier(&ehea_mem_nb
);
3531 pr_info("failed registering memory remove notifier\n");
3533 ret
= crash_shutdown_register(ehea_crash_handler
);
3535 pr_info("failed registering crash handler\n");
3537 ret
= ibmebus_register_driver(&ehea_driver
);
3539 pr_err("failed registering eHEA device driver on ebus\n");
3543 ret
= driver_create_file(&ehea_driver
.driver
,
3544 &driver_attr_capabilities
);
3546 pr_err("failed to register capabilities attribute, ret=%d\n",
3554 ibmebus_unregister_driver(&ehea_driver
);
3556 unregister_memory_notifier(&ehea_mem_nb
);
3557 unregister_reboot_notifier(&ehea_reboot_nb
);
3558 crash_shutdown_unregister(ehea_crash_handler
);
3563 static void __exit
ehea_module_exit(void)
3567 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3568 ibmebus_unregister_driver(&ehea_driver
);
3569 unregister_reboot_notifier(&ehea_reboot_nb
);
3570 ret
= crash_shutdown_unregister(ehea_crash_handler
);
3572 pr_info("failed unregistering crash handler\n");
3573 unregister_memory_notifier(&ehea_mem_nb
);
3574 kfree(ehea_fw_handles
.arr
);
3575 kfree(ehea_bcmc_regs
.arr
);
3576 ehea_destroy_busmap();
3579 module_init(ehea_module_init
);
3580 module_exit(ehea_module_exit
);