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
31 #include <linux/device.h>
34 #include <linux/tcp.h>
35 #include <linux/udp.h>
37 #include <linux/list.h>
38 #include <linux/slab.h>
39 #include <linux/if_ether.h>
40 #include <linux/notifier.h>
41 #include <linux/reboot.h>
42 #include <linux/memory.h>
43 #include <asm/kexec.h>
44 #include <linux/mutex.h>
45 #include <linux/prefetch.h>
51 #include "ehea_phyp.h"
54 MODULE_LICENSE("GPL");
55 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
56 MODULE_DESCRIPTION("IBM eServer HEA Driver");
57 MODULE_VERSION(DRV_VERSION
);
60 static int msg_level
= -1;
61 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
62 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
63 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
64 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
65 static int use_mcs
= 1;
66 static int prop_carrier_state
;
68 module_param(msg_level
, int, 0);
69 module_param(rq1_entries
, int, 0);
70 module_param(rq2_entries
, int, 0);
71 module_param(rq3_entries
, int, 0);
72 module_param(sq_entries
, int, 0);
73 module_param(prop_carrier_state
, int, 0);
74 module_param(use_mcs
, int, 0);
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 = [7..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 = [7..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 = [7..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 = [7..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
91 MODULE_PARM_DESC(use_mcs
, " Multiple receive queues, 1: enable, 0: disable, "
94 static int port_name_cnt
;
95 static LIST_HEAD(adapter_list
);
96 static unsigned long ehea_driver_flags
;
97 static DEFINE_MUTEX(dlpar_mem_lock
);
98 static struct ehea_fw_handle_array ehea_fw_handles
;
99 static struct ehea_bcmc_reg_array ehea_bcmc_regs
;
102 static int ehea_probe_adapter(struct platform_device
*dev
);
104 static int ehea_remove(struct platform_device
*dev
);
106 static const struct of_device_id ehea_module_device_table
[] = {
109 .compatible
= "IBM,lhea",
113 .compatible
= "IBM,lhea-ethernet",
117 MODULE_DEVICE_TABLE(of
, ehea_module_device_table
);
119 static const struct of_device_id ehea_device_table
[] = {
122 .compatible
= "IBM,lhea",
127 static struct platform_driver ehea_driver
= {
130 .owner
= THIS_MODULE
,
131 .of_match_table
= ehea_device_table
,
133 .probe
= ehea_probe_adapter
,
134 .remove
= ehea_remove
,
137 void ehea_dump(void *adr
, int len
, char *msg
)
140 unsigned char *deb
= adr
;
141 for (x
= 0; x
< len
; x
+= 16) {
142 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
143 msg
, deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
148 static void ehea_schedule_port_reset(struct ehea_port
*port
)
150 if (!test_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
))
151 schedule_work(&port
->reset_task
);
154 static void ehea_update_firmware_handles(void)
156 struct ehea_fw_handle_entry
*arr
= NULL
;
157 struct ehea_adapter
*adapter
;
158 int num_adapters
= 0;
162 int num_fw_handles
, k
, l
;
164 /* Determine number of handles */
165 mutex_lock(&ehea_fw_handles
.lock
);
167 list_for_each_entry(adapter
, &adapter_list
, list
) {
170 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
171 struct ehea_port
*port
= adapter
->port
[k
];
173 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
177 num_portres
+= port
->num_def_qps
;
181 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
182 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
183 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
185 if (num_fw_handles
) {
186 arr
= kcalloc(num_fw_handles
, sizeof(*arr
), GFP_KERNEL
);
188 goto out
; /* Keep the existing array */
192 list_for_each_entry(adapter
, &adapter_list
, list
) {
193 if (num_adapters
== 0)
196 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
197 struct ehea_port
*port
= adapter
->port
[k
];
199 if (!port
|| (port
->state
!= EHEA_PORT_UP
) ||
203 for (l
= 0; l
< port
->num_def_qps
; l
++) {
204 struct ehea_port_res
*pr
= &port
->port_res
[l
];
206 arr
[i
].adh
= adapter
->handle
;
207 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
208 arr
[i
].adh
= adapter
->handle
;
209 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
210 arr
[i
].adh
= adapter
->handle
;
211 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
212 arr
[i
].adh
= adapter
->handle
;
213 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
214 arr
[i
].adh
= adapter
->handle
;
215 arr
[i
++].fwh
= pr
->send_mr
.handle
;
216 arr
[i
].adh
= adapter
->handle
;
217 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
219 arr
[i
].adh
= adapter
->handle
;
220 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
224 arr
[i
].adh
= adapter
->handle
;
225 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
227 if (adapter
->mr
.handle
) {
228 arr
[i
].adh
= adapter
->handle
;
229 arr
[i
++].fwh
= adapter
->mr
.handle
;
235 kfree(ehea_fw_handles
.arr
);
236 ehea_fw_handles
.arr
= arr
;
237 ehea_fw_handles
.num_entries
= i
;
239 mutex_unlock(&ehea_fw_handles
.lock
);
242 static void ehea_update_bcmc_registrations(void)
245 struct ehea_bcmc_reg_entry
*arr
= NULL
;
246 struct ehea_adapter
*adapter
;
247 struct ehea_mc_list
*mc_entry
;
248 int num_registrations
= 0;
252 spin_lock_irqsave(&ehea_bcmc_regs
.lock
, flags
);
254 /* Determine number of registrations */
255 list_for_each_entry(adapter
, &adapter_list
, list
)
256 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
257 struct ehea_port
*port
= adapter
->port
[k
];
259 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
262 num_registrations
+= 2; /* Broadcast registrations */
264 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
265 num_registrations
+= 2;
268 if (num_registrations
) {
269 arr
= kcalloc(num_registrations
, sizeof(*arr
), GFP_ATOMIC
);
271 goto out
; /* Keep the existing array */
275 list_for_each_entry(adapter
, &adapter_list
, list
) {
276 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
277 struct ehea_port
*port
= adapter
->port
[k
];
279 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
282 if (num_registrations
== 0)
285 arr
[i
].adh
= adapter
->handle
;
286 arr
[i
].port_id
= port
->logical_port_id
;
287 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
289 arr
[i
++].macaddr
= port
->mac_addr
;
291 arr
[i
].adh
= adapter
->handle
;
292 arr
[i
].port_id
= port
->logical_port_id
;
293 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
294 EHEA_BCMC_VLANID_ALL
;
295 arr
[i
++].macaddr
= port
->mac_addr
;
296 num_registrations
-= 2;
298 list_for_each_entry(mc_entry
,
299 &port
->mc_list
->list
, list
) {
300 if (num_registrations
== 0)
303 arr
[i
].adh
= adapter
->handle
;
304 arr
[i
].port_id
= port
->logical_port_id
;
305 arr
[i
].reg_type
= EHEA_BCMC_MULTICAST
|
307 if (mc_entry
->macaddr
== 0)
308 arr
[i
].reg_type
|= EHEA_BCMC_SCOPE_ALL
;
309 arr
[i
++].macaddr
= mc_entry
->macaddr
;
311 arr
[i
].adh
= adapter
->handle
;
312 arr
[i
].port_id
= port
->logical_port_id
;
313 arr
[i
].reg_type
= EHEA_BCMC_MULTICAST
|
314 EHEA_BCMC_VLANID_ALL
;
315 if (mc_entry
->macaddr
== 0)
316 arr
[i
].reg_type
|= EHEA_BCMC_SCOPE_ALL
;
317 arr
[i
++].macaddr
= mc_entry
->macaddr
;
318 num_registrations
-= 2;
324 kfree(ehea_bcmc_regs
.arr
);
325 ehea_bcmc_regs
.arr
= arr
;
326 ehea_bcmc_regs
.num_entries
= i
;
328 spin_unlock_irqrestore(&ehea_bcmc_regs
.lock
, flags
);
331 static void ehea_get_stats64(struct net_device
*dev
,
332 struct rtnl_link_stats64
*stats
)
334 struct ehea_port
*port
= netdev_priv(dev
);
335 u64 rx_packets
= 0, tx_packets
= 0, rx_bytes
= 0, tx_bytes
= 0;
338 for (i
= 0; i
< port
->num_def_qps
; i
++) {
339 rx_packets
+= port
->port_res
[i
].rx_packets
;
340 rx_bytes
+= port
->port_res
[i
].rx_bytes
;
343 for (i
= 0; i
< port
->num_def_qps
; i
++) {
344 tx_packets
+= port
->port_res
[i
].tx_packets
;
345 tx_bytes
+= port
->port_res
[i
].tx_bytes
;
348 stats
->tx_packets
= tx_packets
;
349 stats
->rx_bytes
= rx_bytes
;
350 stats
->tx_bytes
= tx_bytes
;
351 stats
->rx_packets
= rx_packets
;
353 stats
->multicast
= port
->stats
.multicast
;
354 stats
->rx_errors
= port
->stats
.rx_errors
;
357 static void ehea_update_stats(struct work_struct
*work
)
359 struct ehea_port
*port
=
360 container_of(work
, struct ehea_port
, stats_work
.work
);
361 struct net_device
*dev
= port
->netdev
;
362 struct rtnl_link_stats64
*stats
= &port
->stats
;
363 struct hcp_ehea_port_cb2
*cb2
;
366 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
368 netdev_err(dev
, "No mem for cb2. Some interface statistics were not updated\n");
372 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
373 port
->logical_port_id
,
374 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
375 if (hret
!= H_SUCCESS
) {
376 netdev_err(dev
, "query_ehea_port failed\n");
380 if (netif_msg_hw(port
))
381 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
383 stats
->multicast
= cb2
->rxmcp
;
384 stats
->rx_errors
= cb2
->rxuerr
;
387 free_page((unsigned long)cb2
);
389 schedule_delayed_work(&port
->stats_work
,
390 round_jiffies_relative(msecs_to_jiffies(1000)));
393 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
395 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
396 struct net_device
*dev
= pr
->port
->netdev
;
397 int max_index_mask
= pr
->rq1_skba
.len
- 1;
398 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
402 pr
->rq1_skba
.os_skbs
= 0;
404 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
406 pr
->rq1_skba
.index
= index
;
407 pr
->rq1_skba
.os_skbs
= fill_wqes
;
411 for (i
= 0; i
< fill_wqes
; i
++) {
412 if (!skb_arr_rq1
[index
]) {
413 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
415 if (!skb_arr_rq1
[index
]) {
416 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
421 index
&= max_index_mask
;
429 ehea_update_rq1a(pr
->qp
, adder
);
432 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
434 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
435 struct net_device
*dev
= pr
->port
->netdev
;
438 if (nr_rq1a
> pr
->rq1_skba
.len
) {
439 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
443 for (i
= 0; i
< nr_rq1a
; i
++) {
444 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
449 ehea_update_rq1a(pr
->qp
, i
- 1);
452 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
453 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
454 int num_wqes
, int wqe_type
, int packet_size
)
456 struct net_device
*dev
= pr
->port
->netdev
;
457 struct ehea_qp
*qp
= pr
->qp
;
458 struct sk_buff
**skb_arr
= q_skba
->arr
;
459 struct ehea_rwqe
*rwqe
;
460 int i
, index
, max_index_mask
, fill_wqes
;
464 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
467 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
468 q_skba
->os_skbs
= fill_wqes
;
472 index
= q_skba
->index
;
473 max_index_mask
= q_skba
->len
- 1;
474 for (i
= 0; i
< fill_wqes
; i
++) {
478 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
480 q_skba
->os_skbs
= fill_wqes
- i
;
481 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
482 netdev_info(pr
->port
->netdev
,
483 "rq%i ran dry - no mem for skb\n",
490 skb_arr
[index
] = skb
;
491 tmp_addr
= ehea_map_vaddr(skb
->data
);
492 if (tmp_addr
== -1) {
493 dev_consume_skb_any(skb
);
494 q_skba
->os_skbs
= fill_wqes
- i
;
499 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
500 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
501 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
502 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
503 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
504 rwqe
->sg_list
[0].len
= packet_size
;
505 rwqe
->data_segments
= 1;
508 index
&= max_index_mask
;
512 q_skba
->index
= index
;
519 ehea_update_rq2a(pr
->qp
, adder
);
521 ehea_update_rq3a(pr
->qp
, adder
);
527 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
529 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
530 nr_of_wqes
, EHEA_RWQE2_TYPE
,
535 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
537 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
538 nr_of_wqes
, EHEA_RWQE3_TYPE
,
539 EHEA_MAX_PACKET_SIZE
);
542 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
544 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
545 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
547 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
548 (cqe
->header_length
== 0))
553 static inline void ehea_fill_skb(struct net_device
*dev
,
554 struct sk_buff
*skb
, struct ehea_cqe
*cqe
,
555 struct ehea_port_res
*pr
)
557 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
559 skb_put(skb
, length
);
560 skb
->protocol
= eth_type_trans(skb
, dev
);
562 /* The packet was not an IPV4 packet so a complemented checksum was
563 calculated. The value is found in the Internet Checksum field. */
564 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
565 skb
->ip_summed
= CHECKSUM_COMPLETE
;
566 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
568 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
570 skb_record_rx_queue(skb
, pr
- &pr
->port
->port_res
[0]);
573 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
575 struct ehea_cqe
*cqe
)
577 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
588 prefetchw(pref
+ EHEA_CACHE_LINE
);
590 pref
= (skb_array
[x
]->data
);
592 prefetch(pref
+ EHEA_CACHE_LINE
);
593 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
594 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
597 skb
= skb_array
[skb_index
];
598 skb_array
[skb_index
] = NULL
;
602 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
603 int arr_len
, int wqe_index
)
615 prefetchw(pref
+ EHEA_CACHE_LINE
);
617 pref
= (skb_array
[x
]->data
);
619 prefetchw(pref
+ EHEA_CACHE_LINE
);
622 skb
= skb_array
[wqe_index
];
623 skb_array
[wqe_index
] = NULL
;
627 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
628 struct ehea_cqe
*cqe
, int *processed_rq2
,
633 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
634 pr
->p_stats
.err_tcp_cksum
++;
635 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
636 pr
->p_stats
.err_ip_cksum
++;
637 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
638 pr
->p_stats
.err_frame_crc
++;
642 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
644 } else if (rq
== 3) {
646 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
650 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
651 if (netif_msg_rx_err(pr
->port
)) {
652 pr_err("Critical receive error for QP %d. Resetting port.\n",
653 pr
->qp
->init_attr
.qp_nr
);
654 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
656 ehea_schedule_port_reset(pr
->port
);
663 static int ehea_proc_rwqes(struct net_device
*dev
,
664 struct ehea_port_res
*pr
,
667 struct ehea_port
*port
= pr
->port
;
668 struct ehea_qp
*qp
= pr
->qp
;
669 struct ehea_cqe
*cqe
;
671 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
672 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
673 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
674 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
675 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
676 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
677 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
678 u64 processed_bytes
= 0;
679 int wqe_index
, last_wqe_index
, rq
, port_reset
;
681 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
684 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
685 while ((processed
< budget
) && cqe
) {
689 if (netif_msg_rx_status(port
))
690 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
692 last_wqe_index
= wqe_index
;
694 if (!ehea_check_cqe(cqe
, &rq
)) {
697 skb
= get_skb_by_index_ll(skb_arr_rq1
,
700 if (unlikely(!skb
)) {
701 netif_info(port
, rx_err
, dev
,
702 "LL rq1: skb=NULL\n");
704 skb
= netdev_alloc_skb(dev
,
709 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
710 cqe
->num_bytes_transfered
- 4);
711 ehea_fill_skb(dev
, skb
, cqe
, pr
);
712 } else if (rq
== 2) {
714 skb
= get_skb_by_index(skb_arr_rq2
,
715 skb_arr_rq2_len
, cqe
);
716 if (unlikely(!skb
)) {
717 netif_err(port
, rx_err
, dev
,
721 ehea_fill_skb(dev
, skb
, cqe
, pr
);
725 skb
= get_skb_by_index(skb_arr_rq3
,
726 skb_arr_rq3_len
, cqe
);
727 if (unlikely(!skb
)) {
728 netif_err(port
, rx_err
, dev
,
732 ehea_fill_skb(dev
, skb
, cqe
, pr
);
736 processed_bytes
+= skb
->len
;
738 if (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
739 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
),
742 napi_gro_receive(&pr
->napi
, skb
);
744 pr
->p_stats
.poll_receive_errors
++;
745 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
751 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
754 pr
->rx_packets
+= processed
;
755 pr
->rx_bytes
+= processed_bytes
;
757 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
758 ehea_refill_rq2(pr
, processed_rq2
);
759 ehea_refill_rq3(pr
, processed_rq3
);
764 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
766 static void reset_sq_restart_flag(struct ehea_port
*port
)
770 for (i
= 0; i
< port
->num_def_qps
; i
++) {
771 struct ehea_port_res
*pr
= &port
->port_res
[i
];
772 pr
->sq_restart_flag
= 0;
774 wake_up(&port
->restart_wq
);
777 static void check_sqs(struct ehea_port
*port
)
779 struct ehea_swqe
*swqe
;
783 for (i
= 0; i
< port
->num_def_qps
; i
++) {
784 struct ehea_port_res
*pr
= &port
->port_res
[i
];
787 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
788 memset(swqe
, 0, SWQE_HEADER_SIZE
);
789 atomic_dec(&pr
->swqe_avail
);
791 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
792 swqe
->wr_id
= SWQE_RESTART_CHECK
;
793 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
794 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
795 swqe
->immediate_data_length
= 80;
797 ehea_post_swqe(pr
->qp
, swqe
);
799 ret
= wait_event_timeout(port
->restart_wq
,
800 pr
->sq_restart_flag
== 0,
801 msecs_to_jiffies(100));
804 pr_err("HW/SW queues out of sync\n");
805 ehea_schedule_port_reset(pr
->port
);
812 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
815 struct ehea_cq
*send_cq
= pr
->send_cq
;
816 struct ehea_cqe
*cqe
;
817 int quota
= my_quota
;
821 struct netdev_queue
*txq
= netdev_get_tx_queue(pr
->port
->netdev
,
822 pr
- &pr
->port
->port_res
[0]);
824 cqe
= ehea_poll_cq(send_cq
);
825 while (cqe
&& (quota
> 0)) {
826 ehea_inc_cq(send_cq
);
831 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
832 pr
->sq_restart_flag
= 1;
837 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
838 pr_err("Bad send completion status=0x%04X\n",
841 if (netif_msg_tx_err(pr
->port
))
842 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
844 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
845 pr_err("Resetting port\n");
846 ehea_schedule_port_reset(pr
->port
);
851 if (netif_msg_tx_done(pr
->port
))
852 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
854 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
855 == EHEA_SWQE2_TYPE
)) {
857 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
858 skb
= pr
->sq_skba
.arr
[index
];
859 dev_consume_skb_any(skb
);
860 pr
->sq_skba
.arr
[index
] = NULL
;
863 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
866 cqe
= ehea_poll_cq(send_cq
);
869 ehea_update_feca(send_cq
, cqe_counter
);
870 atomic_add(swqe_av
, &pr
->swqe_avail
);
872 if (unlikely(netif_tx_queue_stopped(txq
) &&
873 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))) {
874 __netif_tx_lock(txq
, smp_processor_id());
875 if (netif_tx_queue_stopped(txq
) &&
876 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))
877 netif_tx_wake_queue(txq
);
878 __netif_tx_unlock(txq
);
881 wake_up(&pr
->port
->swqe_avail_wq
);
886 #define EHEA_POLL_MAX_CQES 65535
888 static int ehea_poll(struct napi_struct
*napi
, int budget
)
890 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
892 struct net_device
*dev
= pr
->port
->netdev
;
893 struct ehea_cqe
*cqe
;
894 struct ehea_cqe
*cqe_skb
= NULL
;
898 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
899 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
901 while (rx
!= budget
) {
903 ehea_reset_cq_ep(pr
->recv_cq
);
904 ehea_reset_cq_ep(pr
->send_cq
);
905 ehea_reset_cq_n1(pr
->recv_cq
);
906 ehea_reset_cq_n1(pr
->send_cq
);
908 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
909 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
911 if (!cqe
&& !cqe_skb
)
914 if (!napi_reschedule(napi
))
917 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
918 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
924 #ifdef CONFIG_NET_POLL_CONTROLLER
925 static void ehea_netpoll(struct net_device
*dev
)
927 struct ehea_port
*port
= netdev_priv(dev
);
930 for (i
= 0; i
< port
->num_def_qps
; i
++)
931 napi_schedule(&port
->port_res
[i
].napi
);
935 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
937 struct ehea_port_res
*pr
= param
;
939 napi_schedule(&pr
->napi
);
944 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
946 struct ehea_port
*port
= param
;
947 struct ehea_eqe
*eqe
;
950 u64 resource_type
, aer
, aerr
;
953 eqe
= ehea_poll_eq(port
->qp_eq
);
956 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
957 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
958 eqe
->entry
, qp_token
);
960 qp
= port
->port_res
[qp_token
].qp
;
962 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
965 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
966 if ((aer
& EHEA_AER_RESET_MASK
) ||
967 (aerr
& EHEA_AERR_RESET_MASK
))
970 reset_port
= 1; /* Reset in case of CQ or EQ error */
972 eqe
= ehea_poll_eq(port
->qp_eq
);
976 pr_err("Resetting port\n");
977 ehea_schedule_port_reset(port
);
983 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
988 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
989 if (adapter
->port
[i
])
990 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
991 return adapter
->port
[i
];
995 int ehea_sense_port_attr(struct ehea_port
*port
)
999 struct hcp_ehea_port_cb0
*cb0
;
1001 /* may be called via ehea_neq_tasklet() */
1002 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
1004 pr_err("no mem for cb0\n");
1009 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1010 port
->logical_port_id
, H_PORT_CB0
,
1011 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1013 if (hret
!= H_SUCCESS
) {
1019 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1021 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1022 ret
= -EADDRNOTAVAIL
;
1027 switch (cb0
->port_speed
) {
1029 port
->port_speed
= EHEA_SPEED_10M
;
1030 port
->full_duplex
= 0;
1033 port
->port_speed
= EHEA_SPEED_10M
;
1034 port
->full_duplex
= 1;
1036 case H_SPEED_100M_H
:
1037 port
->port_speed
= EHEA_SPEED_100M
;
1038 port
->full_duplex
= 0;
1040 case H_SPEED_100M_F
:
1041 port
->port_speed
= EHEA_SPEED_100M
;
1042 port
->full_duplex
= 1;
1045 port
->port_speed
= EHEA_SPEED_1G
;
1046 port
->full_duplex
= 1;
1049 port
->port_speed
= EHEA_SPEED_10G
;
1050 port
->full_duplex
= 1;
1053 port
->port_speed
= 0;
1054 port
->full_duplex
= 0;
1059 port
->num_mcs
= cb0
->num_default_qps
;
1061 /* Number of default QPs */
1063 port
->num_def_qps
= cb0
->num_default_qps
;
1065 port
->num_def_qps
= 1;
1067 if (!port
->num_def_qps
) {
1074 if (ret
|| netif_msg_probe(port
))
1075 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1076 free_page((unsigned long)cb0
);
1081 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1083 struct hcp_ehea_port_cb4
*cb4
;
1087 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1089 pr_err("no mem for cb4\n");
1094 cb4
->port_speed
= port_speed
;
1096 netif_carrier_off(port
->netdev
);
1098 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1099 port
->logical_port_id
,
1100 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1101 if (hret
== H_SUCCESS
) {
1102 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1104 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1105 port
->logical_port_id
,
1106 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1108 if (hret
== H_SUCCESS
) {
1109 switch (cb4
->port_speed
) {
1111 port
->port_speed
= EHEA_SPEED_10M
;
1112 port
->full_duplex
= 0;
1115 port
->port_speed
= EHEA_SPEED_10M
;
1116 port
->full_duplex
= 1;
1118 case H_SPEED_100M_H
:
1119 port
->port_speed
= EHEA_SPEED_100M
;
1120 port
->full_duplex
= 0;
1122 case H_SPEED_100M_F
:
1123 port
->port_speed
= EHEA_SPEED_100M
;
1124 port
->full_duplex
= 1;
1127 port
->port_speed
= EHEA_SPEED_1G
;
1128 port
->full_duplex
= 1;
1131 port
->port_speed
= EHEA_SPEED_10G
;
1132 port
->full_duplex
= 1;
1135 port
->port_speed
= 0;
1136 port
->full_duplex
= 0;
1140 pr_err("Failed sensing port speed\n");
1144 if (hret
== H_AUTHORITY
) {
1145 pr_info("Hypervisor denied setting port speed\n");
1149 pr_err("Failed setting port speed\n");
1152 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1153 netif_carrier_on(port
->netdev
);
1155 free_page((unsigned long)cb4
);
1160 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1165 struct ehea_port
*port
;
1166 struct net_device
*dev
;
1168 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1169 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1170 port
= ehea_get_port(adapter
, portnum
);
1172 netdev_err(NULL
, "unknown portnum %x\n", portnum
);
1178 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1180 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1181 if (!netif_carrier_ok(dev
)) {
1182 ret
= ehea_sense_port_attr(port
);
1184 netdev_err(dev
, "failed resensing port attributes\n");
1188 netif_info(port
, link
, dev
,
1189 "Logical port up: %dMbps %s Duplex\n",
1191 port
->full_duplex
== 1 ?
1194 netif_carrier_on(dev
);
1195 netif_wake_queue(dev
);
1198 if (netif_carrier_ok(dev
)) {
1199 netif_info(port
, link
, dev
,
1200 "Logical port down\n");
1201 netif_carrier_off(dev
);
1202 netif_tx_disable(dev
);
1205 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1206 port
->phy_link
= EHEA_PHY_LINK_UP
;
1207 netif_info(port
, link
, dev
,
1208 "Physical port up\n");
1209 if (prop_carrier_state
)
1210 netif_carrier_on(dev
);
1212 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1213 netif_info(port
, link
, dev
,
1214 "Physical port down\n");
1215 if (prop_carrier_state
)
1216 netif_carrier_off(dev
);
1219 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1221 "External switch port is primary port\n");
1224 "External switch port is backup port\n");
1227 case EHEA_EC_ADAPTER_MALFUNC
:
1228 netdev_err(dev
, "Adapter malfunction\n");
1230 case EHEA_EC_PORT_MALFUNC
:
1231 netdev_info(dev
, "Port malfunction\n");
1232 netif_carrier_off(dev
);
1233 netif_tx_disable(dev
);
1236 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1241 static void ehea_neq_tasklet(unsigned long data
)
1243 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1244 struct ehea_eqe
*eqe
;
1247 eqe
= ehea_poll_eq(adapter
->neq
);
1248 pr_debug("eqe=%p\n", eqe
);
1251 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1252 ehea_parse_eqe(adapter
, eqe
->entry
);
1253 eqe
= ehea_poll_eq(adapter
->neq
);
1254 pr_debug("next eqe=%p\n", eqe
);
1257 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1258 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1259 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1261 ehea_h_reset_events(adapter
->handle
,
1262 adapter
->neq
->fw_handle
, event_mask
);
1265 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1267 struct ehea_adapter
*adapter
= param
;
1268 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1273 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1276 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1278 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1280 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1282 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1287 static int ehea_reg_interrupts(struct net_device
*dev
)
1289 struct ehea_port
*port
= netdev_priv(dev
);
1290 struct ehea_port_res
*pr
;
1294 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1297 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1298 ehea_qp_aff_irq_handler
,
1299 0, port
->int_aff_name
, port
);
1301 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1302 port
->qp_eq
->attr
.ist1
);
1306 netif_info(port
, ifup
, dev
,
1307 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1308 port
->qp_eq
->attr
.ist1
);
1311 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1312 pr
= &port
->port_res
[i
];
1313 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1314 "%s-queue%d", dev
->name
, i
);
1315 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1316 ehea_recv_irq_handler
,
1317 0, pr
->int_send_name
, pr
);
1319 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1320 i
, pr
->eq
->attr
.ist1
);
1323 netif_info(port
, ifup
, dev
,
1324 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1325 pr
->eq
->attr
.ist1
, i
);
1333 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1334 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1338 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1339 i
= port
->num_def_qps
;
1345 static void ehea_free_interrupts(struct net_device
*dev
)
1347 struct ehea_port
*port
= netdev_priv(dev
);
1348 struct ehea_port_res
*pr
;
1353 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1354 pr
= &port
->port_res
[i
];
1355 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1356 netif_info(port
, intr
, dev
,
1357 "free send irq for res %d with handle 0x%X\n",
1358 i
, pr
->eq
->attr
.ist1
);
1361 /* associated events */
1362 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1363 netif_info(port
, intr
, dev
,
1364 "associated event interrupt for handle 0x%X freed\n",
1365 port
->qp_eq
->attr
.ist1
);
1368 static int ehea_configure_port(struct ehea_port
*port
)
1372 struct hcp_ehea_port_cb0
*cb0
;
1375 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1379 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1380 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1381 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1382 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1383 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1384 PXLY_RC_VLAN_FILTER
)
1385 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1387 for (i
= 0; i
< port
->num_mcs
; i
++)
1389 cb0
->default_qpn_arr
[i
] =
1390 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1392 cb0
->default_qpn_arr
[i
] =
1393 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1395 if (netif_msg_ifup(port
))
1396 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1398 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1399 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1401 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1402 port
->logical_port_id
,
1403 H_PORT_CB0
, mask
, cb0
);
1405 if (hret
!= H_SUCCESS
)
1411 free_page((unsigned long)cb0
);
1416 static int ehea_gen_smrs(struct ehea_port_res
*pr
)
1419 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1421 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1425 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1432 ehea_rem_mr(&pr
->send_mr
);
1434 pr_err("Generating SMRS failed\n");
1438 static int ehea_rem_smrs(struct ehea_port_res
*pr
)
1440 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1441 (ehea_rem_mr(&pr
->recv_mr
)))
1447 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1449 int arr_size
= sizeof(void *) * max_q_entries
;
1451 q_skba
->arr
= vzalloc(arr_size
);
1455 q_skba
->len
= max_q_entries
;
1457 q_skba
->os_skbs
= 0;
1462 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1463 struct port_res_cfg
*pr_cfg
, int queue_token
)
1465 struct ehea_adapter
*adapter
= port
->adapter
;
1466 enum ehea_eq_type eq_type
= EHEA_EQ
;
1467 struct ehea_qp_init_attr
*init_attr
= NULL
;
1469 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1471 tx_bytes
= pr
->tx_bytes
;
1472 tx_packets
= pr
->tx_packets
;
1473 rx_bytes
= pr
->rx_bytes
;
1474 rx_packets
= pr
->rx_packets
;
1476 memset(pr
, 0, sizeof(struct ehea_port_res
));
1478 pr
->tx_bytes
= rx_bytes
;
1479 pr
->tx_packets
= tx_packets
;
1480 pr
->rx_bytes
= rx_bytes
;
1481 pr
->rx_packets
= rx_packets
;
1485 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1487 pr_err("create_eq failed (eq)\n");
1491 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1493 port
->logical_port_id
);
1495 pr_err("create_cq failed (cq_recv)\n");
1499 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1501 port
->logical_port_id
);
1503 pr_err("create_cq failed (cq_send)\n");
1507 if (netif_msg_ifup(port
))
1508 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1509 pr
->send_cq
->attr
.act_nr_of_cqes
,
1510 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1512 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1515 pr_err("no mem for ehea_qp_init_attr\n");
1519 init_attr
->low_lat_rq1
= 1;
1520 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1521 init_attr
->rq_count
= 3;
1522 init_attr
->qp_token
= queue_token
;
1523 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1524 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1525 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1526 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1527 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1528 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1529 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1530 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1531 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1532 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1533 init_attr
->port_nr
= port
->logical_port_id
;
1534 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1535 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1536 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1538 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1540 pr_err("create_qp failed\n");
1545 if (netif_msg_ifup(port
))
1546 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",
1548 init_attr
->act_nr_send_wqes
,
1549 init_attr
->act_nr_rwqes_rq1
,
1550 init_attr
->act_nr_rwqes_rq2
,
1551 init_attr
->act_nr_rwqes_rq3
);
1553 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1555 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1556 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1557 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1558 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1562 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1563 if (ehea_gen_smrs(pr
) != 0) {
1568 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1572 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1579 vfree(pr
->sq_skba
.arr
);
1580 vfree(pr
->rq1_skba
.arr
);
1581 vfree(pr
->rq2_skba
.arr
);
1582 vfree(pr
->rq3_skba
.arr
);
1583 ehea_destroy_qp(pr
->qp
);
1584 ehea_destroy_cq(pr
->send_cq
);
1585 ehea_destroy_cq(pr
->recv_cq
);
1586 ehea_destroy_eq(pr
->eq
);
1591 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1596 netif_napi_del(&pr
->napi
);
1598 ret
= ehea_destroy_qp(pr
->qp
);
1601 ehea_destroy_cq(pr
->send_cq
);
1602 ehea_destroy_cq(pr
->recv_cq
);
1603 ehea_destroy_eq(pr
->eq
);
1605 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1606 if (pr
->rq1_skba
.arr
[i
])
1607 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1609 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1610 if (pr
->rq2_skba
.arr
[i
])
1611 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1613 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1614 if (pr
->rq3_skba
.arr
[i
])
1615 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1617 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1618 if (pr
->sq_skba
.arr
[i
])
1619 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1621 vfree(pr
->rq1_skba
.arr
);
1622 vfree(pr
->rq2_skba
.arr
);
1623 vfree(pr
->rq3_skba
.arr
);
1624 vfree(pr
->sq_skba
.arr
);
1625 ret
= ehea_rem_smrs(pr
);
1630 static void write_swqe2_immediate(struct sk_buff
*skb
, struct ehea_swqe
*swqe
,
1633 int skb_data_size
= skb_headlen(skb
);
1634 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1635 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1636 unsigned int immediate_len
= SWQE2_MAX_IMM
;
1638 swqe
->descriptors
= 0;
1640 if (skb_is_gso(skb
)) {
1641 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1642 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1644 * For TSO packets we only copy the headers into the
1647 immediate_len
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1650 if (skb_is_gso(skb
) || skb_data_size
>= SWQE2_MAX_IMM
) {
1651 skb_copy_from_linear_data(skb
, imm_data
, immediate_len
);
1652 swqe
->immediate_data_length
= immediate_len
;
1654 if (skb_data_size
> immediate_len
) {
1655 sg1entry
->l_key
= lkey
;
1656 sg1entry
->len
= skb_data_size
- immediate_len
;
1658 ehea_map_vaddr(skb
->data
+ immediate_len
);
1659 swqe
->descriptors
++;
1662 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1663 swqe
->immediate_data_length
= skb_data_size
;
1667 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1668 struct ehea_swqe
*swqe
, u32 lkey
)
1670 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1672 int nfrags
, sg1entry_contains_frag_data
, i
;
1674 nfrags
= skb_shinfo(skb
)->nr_frags
;
1675 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1676 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1677 sg1entry_contains_frag_data
= 0;
1679 write_swqe2_immediate(skb
, swqe
, lkey
);
1681 /* write descriptors */
1683 if (swqe
->descriptors
== 0) {
1684 /* sg1entry not yet used */
1685 frag
= &skb_shinfo(skb
)->frags
[0];
1687 /* copy sg1entry data */
1688 sg1entry
->l_key
= lkey
;
1689 sg1entry
->len
= skb_frag_size(frag
);
1691 ehea_map_vaddr(skb_frag_address(frag
));
1692 swqe
->descriptors
++;
1693 sg1entry_contains_frag_data
= 1;
1696 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1698 frag
= &skb_shinfo(skb
)->frags
[i
];
1699 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1701 sgentry
->l_key
= lkey
;
1702 sgentry
->len
= skb_frag_size(frag
);
1703 sgentry
->vaddr
= ehea_map_vaddr(skb_frag_address(frag
));
1704 swqe
->descriptors
++;
1709 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1715 /* De/Register untagged packets */
1716 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1717 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1718 port
->logical_port_id
,
1719 reg_type
, port
->mac_addr
, 0, hcallid
);
1720 if (hret
!= H_SUCCESS
) {
1721 pr_err("%sregistering bc address failed (tagged)\n",
1722 hcallid
== H_REG_BCMC
? "" : "de");
1727 /* De/Register VLAN packets */
1728 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1729 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1730 port
->logical_port_id
,
1731 reg_type
, port
->mac_addr
, 0, hcallid
);
1732 if (hret
!= H_SUCCESS
) {
1733 pr_err("%sregistering bc address failed (vlan)\n",
1734 hcallid
== H_REG_BCMC
? "" : "de");
1741 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1743 struct ehea_port
*port
= netdev_priv(dev
);
1744 struct sockaddr
*mac_addr
= sa
;
1745 struct hcp_ehea_port_cb0
*cb0
;
1749 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1750 ret
= -EADDRNOTAVAIL
;
1754 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1756 pr_err("no mem for cb0\n");
1761 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1763 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1765 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1766 port
->logical_port_id
, H_PORT_CB0
,
1767 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1768 if (hret
!= H_SUCCESS
) {
1773 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1775 /* Deregister old MAC in pHYP */
1776 if (port
->state
== EHEA_PORT_UP
) {
1777 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1782 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1784 /* Register new MAC in pHYP */
1785 if (port
->state
== EHEA_PORT_UP
) {
1786 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1794 ehea_update_bcmc_registrations();
1796 free_page((unsigned long)cb0
);
1801 static void ehea_promiscuous_error(u64 hret
, int enable
)
1803 if (hret
== H_AUTHORITY
)
1804 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1805 enable
== 1 ? "en" : "dis");
1807 pr_err("failed %sabling promiscuous mode\n",
1808 enable
== 1 ? "en" : "dis");
1811 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1813 struct ehea_port
*port
= netdev_priv(dev
);
1814 struct hcp_ehea_port_cb7
*cb7
;
1817 if (enable
== port
->promisc
)
1820 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1822 pr_err("no mem for cb7\n");
1826 /* Modify Pxs_DUCQPN in CB7 */
1827 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1829 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1830 port
->logical_port_id
,
1831 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1833 ehea_promiscuous_error(hret
, enable
);
1837 port
->promisc
= enable
;
1839 free_page((unsigned long)cb7
);
1842 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1848 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_UNTAGGED
;
1849 if (mc_mac_addr
== 0)
1850 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1852 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1853 port
->logical_port_id
,
1854 reg_type
, mc_mac_addr
, 0, hcallid
);
1858 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_VLANID_ALL
;
1859 if (mc_mac_addr
== 0)
1860 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1862 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1863 port
->logical_port_id
,
1864 reg_type
, mc_mac_addr
, 0, hcallid
);
1869 static int ehea_drop_multicast_list(struct net_device
*dev
)
1871 struct ehea_port
*port
= netdev_priv(dev
);
1872 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1873 struct list_head
*pos
;
1874 struct list_head
*temp
;
1878 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1879 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1881 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1884 pr_err("failed deregistering mcast MAC\n");
1894 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1896 struct ehea_port
*port
= netdev_priv(dev
);
1899 if (!port
->allmulti
) {
1901 /* Enable ALLMULTI */
1902 ehea_drop_multicast_list(dev
);
1903 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1908 "failed enabling IFF_ALLMULTI\n");
1912 /* Disable ALLMULTI */
1913 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1918 "failed disabling IFF_ALLMULTI\n");
1923 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1925 struct ehea_mc_list
*ehea_mcl_entry
;
1928 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1929 if (!ehea_mcl_entry
)
1932 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1934 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1936 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1939 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1941 pr_err("failed registering mcast MAC\n");
1942 kfree(ehea_mcl_entry
);
1946 static void ehea_set_multicast_list(struct net_device
*dev
)
1948 struct ehea_port
*port
= netdev_priv(dev
);
1949 struct netdev_hw_addr
*ha
;
1952 ehea_promiscuous(dev
, !!(dev
->flags
& IFF_PROMISC
));
1954 if (dev
->flags
& IFF_ALLMULTI
) {
1955 ehea_allmulti(dev
, 1);
1958 ehea_allmulti(dev
, 0);
1960 if (!netdev_mc_empty(dev
)) {
1961 ret
= ehea_drop_multicast_list(dev
);
1963 /* Dropping the current multicast list failed.
1964 * Enabling ALL_MULTI is the best we can do.
1966 ehea_allmulti(dev
, 1);
1969 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
1970 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1971 port
->adapter
->max_mc_mac
);
1975 netdev_for_each_mc_addr(ha
, dev
)
1976 ehea_add_multicast_entry(port
, ha
->addr
);
1980 ehea_update_bcmc_registrations();
1983 static void xmit_common(struct sk_buff
*skb
, struct ehea_swqe
*swqe
)
1985 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
| EHEA_SWQE_CRC
;
1987 if (vlan_get_protocol(skb
) != htons(ETH_P_IP
))
1990 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1991 swqe
->tx_control
|= EHEA_SWQE_IP_CHECKSUM
;
1993 swqe
->ip_start
= skb_network_offset(skb
);
1994 swqe
->ip_end
= swqe
->ip_start
+ ip_hdrlen(skb
) - 1;
1996 switch (ip_hdr(skb
)->protocol
) {
1998 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1999 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2001 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2002 offsetof(struct udphdr
, check
);
2006 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2007 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2009 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2010 offsetof(struct tcphdr
, check
);
2015 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2016 struct ehea_swqe
*swqe
, u32 lkey
)
2018 swqe
->tx_control
|= EHEA_SWQE_DESCRIPTORS_PRESENT
;
2020 xmit_common(skb
, swqe
);
2022 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2025 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2026 struct ehea_swqe
*swqe
)
2028 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2030 xmit_common(skb
, swqe
);
2033 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2035 skb_copy_bits(skb
, 0, imm_data
, skb
->len
);
2037 swqe
->immediate_data_length
= skb
->len
;
2038 dev_consume_skb_any(skb
);
2041 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2043 struct ehea_port
*port
= netdev_priv(dev
);
2044 struct ehea_swqe
*swqe
;
2047 struct ehea_port_res
*pr
;
2048 struct netdev_queue
*txq
;
2050 pr
= &port
->port_res
[skb_get_queue_mapping(skb
)];
2051 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
2053 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2054 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2055 atomic_dec(&pr
->swqe_avail
);
2057 if (skb_vlan_tag_present(skb
)) {
2058 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2059 swqe
->vlan_tag
= skb_vlan_tag_get(skb
);
2063 pr
->tx_bytes
+= skb
->len
;
2065 if (skb
->len
<= SWQE3_MAX_IMM
) {
2066 u32 sig_iv
= port
->sig_comp_iv
;
2067 u32 swqe_num
= pr
->swqe_id_counter
;
2068 ehea_xmit3(skb
, dev
, swqe
);
2069 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2070 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2071 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2072 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2074 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2075 pr
->swqe_ll_count
= 0;
2077 pr
->swqe_ll_count
+= 1;
2080 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2081 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2082 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2083 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2084 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2086 pr
->sq_skba
.index
++;
2087 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2089 lkey
= pr
->send_mr
.lkey
;
2090 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2091 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2093 pr
->swqe_id_counter
+= 1;
2095 netif_info(port
, tx_queued
, dev
,
2096 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2097 if (netif_msg_tx_queued(port
))
2098 ehea_dump(swqe
, 512, "swqe");
2100 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2101 netif_tx_stop_queue(txq
);
2102 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2105 ehea_post_swqe(pr
->qp
, swqe
);
2107 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2108 pr
->p_stats
.queue_stopped
++;
2109 netif_tx_stop_queue(txq
);
2112 return NETDEV_TX_OK
;
2115 static int ehea_vlan_rx_add_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
2117 struct ehea_port
*port
= netdev_priv(dev
);
2118 struct ehea_adapter
*adapter
= port
->adapter
;
2119 struct hcp_ehea_port_cb1
*cb1
;
2124 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2126 pr_err("no mem for cb1\n");
2131 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2132 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2133 if (hret
!= H_SUCCESS
) {
2134 pr_err("query_ehea_port failed\n");
2140 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2142 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2143 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2144 if (hret
!= H_SUCCESS
) {
2145 pr_err("modify_ehea_port failed\n");
2149 free_page((unsigned long)cb1
);
2153 static int ehea_vlan_rx_kill_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
2155 struct ehea_port
*port
= netdev_priv(dev
);
2156 struct ehea_adapter
*adapter
= port
->adapter
;
2157 struct hcp_ehea_port_cb1
*cb1
;
2162 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2164 pr_err("no mem for cb1\n");
2169 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2170 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2171 if (hret
!= H_SUCCESS
) {
2172 pr_err("query_ehea_port failed\n");
2178 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2180 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2181 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2182 if (hret
!= H_SUCCESS
) {
2183 pr_err("modify_ehea_port failed\n");
2187 free_page((unsigned long)cb1
);
2191 static int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2197 struct hcp_modify_qp_cb0
*cb0
;
2199 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2205 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2206 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2207 if (hret
!= H_SUCCESS
) {
2208 pr_err("query_ehea_qp failed (1)\n");
2212 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2213 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2214 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2215 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2216 if (hret
!= H_SUCCESS
) {
2217 pr_err("modify_ehea_qp failed (1)\n");
2221 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2222 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2223 if (hret
!= H_SUCCESS
) {
2224 pr_err("query_ehea_qp failed (2)\n");
2228 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2229 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2230 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2231 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2232 if (hret
!= H_SUCCESS
) {
2233 pr_err("modify_ehea_qp failed (2)\n");
2237 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2238 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2239 if (hret
!= H_SUCCESS
) {
2240 pr_err("query_ehea_qp failed (3)\n");
2244 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2245 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2246 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2247 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2248 if (hret
!= H_SUCCESS
) {
2249 pr_err("modify_ehea_qp failed (3)\n");
2253 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2254 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2255 if (hret
!= H_SUCCESS
) {
2256 pr_err("query_ehea_qp failed (4)\n");
2262 free_page((unsigned long)cb0
);
2266 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
)
2269 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2270 enum ehea_eq_type eq_type
= EHEA_EQ
;
2272 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2273 EHEA_MAX_ENTRIES_EQ
, 1);
2276 pr_err("ehea_create_eq failed (qp_eq)\n");
2280 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2281 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2282 pr_cfg
.max_entries_sq
= sq_entries
;
2283 pr_cfg
.max_entries_rq1
= rq1_entries
;
2284 pr_cfg
.max_entries_rq2
= rq2_entries
;
2285 pr_cfg
.max_entries_rq3
= rq3_entries
;
2287 pr_cfg_small_rx
.max_entries_rcq
= 1;
2288 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2289 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2290 pr_cfg_small_rx
.max_entries_rq1
= 1;
2291 pr_cfg_small_rx
.max_entries_rq2
= 1;
2292 pr_cfg_small_rx
.max_entries_rq3
= 1;
2294 for (i
= 0; i
< def_qps
; i
++) {
2295 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2299 for (i
= def_qps
; i
< def_qps
; i
++) {
2300 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2301 &pr_cfg_small_rx
, i
);
2310 ehea_clean_portres(port
, &port
->port_res
[i
]);
2313 ehea_destroy_eq(port
->qp_eq
);
2317 static int ehea_clean_all_portres(struct ehea_port
*port
)
2322 for (i
= 0; i
< port
->num_def_qps
; i
++)
2323 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2325 ret
|= ehea_destroy_eq(port
->qp_eq
);
2330 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2332 if (adapter
->active_ports
)
2335 ehea_rem_mr(&adapter
->mr
);
2338 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2340 if (adapter
->active_ports
)
2343 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2346 static int ehea_up(struct net_device
*dev
)
2349 struct ehea_port
*port
= netdev_priv(dev
);
2351 if (port
->state
== EHEA_PORT_UP
)
2354 ret
= ehea_port_res_setup(port
, port
->num_def_qps
);
2356 netdev_err(dev
, "port_res_failed\n");
2360 /* Set default QP for this port */
2361 ret
= ehea_configure_port(port
);
2363 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2367 ret
= ehea_reg_interrupts(dev
);
2369 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2373 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2374 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2376 netdev_err(dev
, "activate_qp failed\n");
2381 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2382 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2384 netdev_err(dev
, "out_free_irqs\n");
2389 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2395 port
->state
= EHEA_PORT_UP
;
2401 ehea_free_interrupts(dev
);
2404 ehea_clean_all_portres(port
);
2407 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2409 ehea_update_bcmc_registrations();
2410 ehea_update_firmware_handles();
2415 static void port_napi_disable(struct ehea_port
*port
)
2419 for (i
= 0; i
< port
->num_def_qps
; i
++)
2420 napi_disable(&port
->port_res
[i
].napi
);
2423 static void port_napi_enable(struct ehea_port
*port
)
2427 for (i
= 0; i
< port
->num_def_qps
; i
++)
2428 napi_enable(&port
->port_res
[i
].napi
);
2431 static int ehea_open(struct net_device
*dev
)
2434 struct ehea_port
*port
= netdev_priv(dev
);
2436 mutex_lock(&port
->port_lock
);
2438 netif_info(port
, ifup
, dev
, "enabling port\n");
2440 netif_carrier_off(dev
);
2444 port_napi_enable(port
);
2445 netif_tx_start_all_queues(dev
);
2448 mutex_unlock(&port
->port_lock
);
2449 schedule_delayed_work(&port
->stats_work
,
2450 round_jiffies_relative(msecs_to_jiffies(1000)));
2455 static int ehea_down(struct net_device
*dev
)
2458 struct ehea_port
*port
= netdev_priv(dev
);
2460 if (port
->state
== EHEA_PORT_DOWN
)
2463 ehea_drop_multicast_list(dev
);
2464 ehea_allmulti(dev
, 0);
2465 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2467 ehea_free_interrupts(dev
);
2469 port
->state
= EHEA_PORT_DOWN
;
2471 ehea_update_bcmc_registrations();
2473 ret
= ehea_clean_all_portres(port
);
2475 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2477 ehea_update_firmware_handles();
2482 static int ehea_stop(struct net_device
*dev
)
2485 struct ehea_port
*port
= netdev_priv(dev
);
2487 netif_info(port
, ifdown
, dev
, "disabling port\n");
2489 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2490 cancel_work_sync(&port
->reset_task
);
2491 cancel_delayed_work_sync(&port
->stats_work
);
2492 mutex_lock(&port
->port_lock
);
2493 netif_tx_stop_all_queues(dev
);
2494 port_napi_disable(port
);
2495 ret
= ehea_down(dev
);
2496 mutex_unlock(&port
->port_lock
);
2497 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2501 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2503 struct ehea_qp qp
= *orig_qp
;
2504 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2505 struct ehea_swqe
*swqe
;
2509 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2510 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2511 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2515 static void ehea_flush_sq(struct ehea_port
*port
)
2519 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2520 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2521 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2524 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2525 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2526 msecs_to_jiffies(100));
2529 pr_err("WARNING: sq not flushed completely\n");
2535 static int ehea_stop_qps(struct net_device
*dev
)
2537 struct ehea_port
*port
= netdev_priv(dev
);
2538 struct ehea_adapter
*adapter
= port
->adapter
;
2539 struct hcp_modify_qp_cb0
*cb0
;
2547 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2553 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2554 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2555 struct ehea_qp
*qp
= pr
->qp
;
2557 /* Purge send queue */
2560 /* Disable queue pair */
2561 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2562 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2564 if (hret
!= H_SUCCESS
) {
2565 pr_err("query_ehea_qp failed (1)\n");
2569 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2570 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2572 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2573 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2575 &dummy64
, &dummy16
, &dummy16
);
2576 if (hret
!= H_SUCCESS
) {
2577 pr_err("modify_ehea_qp failed (1)\n");
2581 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2582 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2584 if (hret
!= H_SUCCESS
) {
2585 pr_err("query_ehea_qp failed (2)\n");
2589 /* deregister shared memory regions */
2590 dret
= ehea_rem_smrs(pr
);
2592 pr_err("unreg shared memory region failed\n");
2599 free_page((unsigned long)cb0
);
2604 static void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2606 struct ehea_qp qp
= *orig_qp
;
2607 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2608 struct ehea_rwqe
*rwqe
;
2609 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2610 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2611 struct sk_buff
*skb
;
2612 u32 lkey
= pr
->recv_mr
.lkey
;
2618 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2619 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2620 rwqe
->sg_list
[0].l_key
= lkey
;
2621 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2622 skb
= skba_rq2
[index
];
2624 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2627 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2628 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2629 rwqe
->sg_list
[0].l_key
= lkey
;
2630 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2631 skb
= skba_rq3
[index
];
2633 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2637 static int ehea_restart_qps(struct net_device
*dev
)
2639 struct ehea_port
*port
= netdev_priv(dev
);
2640 struct ehea_adapter
*adapter
= port
->adapter
;
2644 struct hcp_modify_qp_cb0
*cb0
;
2649 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2655 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2656 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2657 struct ehea_qp
*qp
= pr
->qp
;
2659 ret
= ehea_gen_smrs(pr
);
2661 netdev_err(dev
, "creation of shared memory regions failed\n");
2665 ehea_update_rqs(qp
, pr
);
2667 /* Enable queue pair */
2668 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2669 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2671 if (hret
!= H_SUCCESS
) {
2672 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2676 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2677 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2679 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2680 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2682 &dummy64
, &dummy16
, &dummy16
);
2683 if (hret
!= H_SUCCESS
) {
2684 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2688 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2689 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2691 if (hret
!= H_SUCCESS
) {
2692 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2696 /* refill entire queue */
2697 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2698 ehea_refill_rq2(pr
, 0);
2699 ehea_refill_rq3(pr
, 0);
2702 free_page((unsigned long)cb0
);
2707 static void ehea_reset_port(struct work_struct
*work
)
2710 struct ehea_port
*port
=
2711 container_of(work
, struct ehea_port
, reset_task
);
2712 struct net_device
*dev
= port
->netdev
;
2714 mutex_lock(&dlpar_mem_lock
);
2716 mutex_lock(&port
->port_lock
);
2717 netif_tx_disable(dev
);
2719 port_napi_disable(port
);
2727 ehea_set_multicast_list(dev
);
2729 netif_info(port
, timer
, dev
, "reset successful\n");
2731 port_napi_enable(port
);
2733 netif_tx_wake_all_queues(dev
);
2735 mutex_unlock(&port
->port_lock
);
2736 mutex_unlock(&dlpar_mem_lock
);
2739 static void ehea_rereg_mrs(void)
2742 struct ehea_adapter
*adapter
;
2744 pr_info("LPAR memory changed - re-initializing driver\n");
2746 list_for_each_entry(adapter
, &adapter_list
, list
)
2747 if (adapter
->active_ports
) {
2748 /* Shutdown all ports */
2749 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2750 struct ehea_port
*port
= adapter
->port
[i
];
2751 struct net_device
*dev
;
2758 if (dev
->flags
& IFF_UP
) {
2759 mutex_lock(&port
->port_lock
);
2760 netif_tx_disable(dev
);
2761 ehea_flush_sq(port
);
2762 ret
= ehea_stop_qps(dev
);
2764 mutex_unlock(&port
->port_lock
);
2767 port_napi_disable(port
);
2768 mutex_unlock(&port
->port_lock
);
2770 reset_sq_restart_flag(port
);
2773 /* Unregister old memory region */
2774 ret
= ehea_rem_mr(&adapter
->mr
);
2776 pr_err("unregister MR failed - driver inoperable!\n");
2781 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2783 list_for_each_entry(adapter
, &adapter_list
, list
)
2784 if (adapter
->active_ports
) {
2785 /* Register new memory region */
2786 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2788 pr_err("register MR failed - driver inoperable!\n");
2792 /* Restart all ports */
2793 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2794 struct ehea_port
*port
= adapter
->port
[i
];
2797 struct net_device
*dev
= port
->netdev
;
2799 if (dev
->flags
& IFF_UP
) {
2800 mutex_lock(&port
->port_lock
);
2801 ret
= ehea_restart_qps(dev
);
2804 port_napi_enable(port
);
2805 netif_tx_wake_all_queues(dev
);
2807 netdev_err(dev
, "Unable to restart QPS\n");
2809 mutex_unlock(&port
->port_lock
);
2814 pr_info("re-initializing driver complete\n");
2819 static void ehea_tx_watchdog(struct net_device
*dev
)
2821 struct ehea_port
*port
= netdev_priv(dev
);
2823 if (netif_carrier_ok(dev
) &&
2824 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2825 ehea_schedule_port_reset(port
);
2828 static int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2830 struct hcp_query_ehea
*cb
;
2834 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2840 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2842 if (hret
!= H_SUCCESS
) {
2847 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2851 free_page((unsigned long)cb
);
2856 static int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2858 struct hcp_ehea_port_cb4
*cb4
;
2864 /* (Try to) enable *jumbo frames */
2865 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2867 pr_err("no mem for cb4\n");
2871 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2872 port
->logical_port_id
,
2874 H_PORT_CB4_JUMBO
, cb4
);
2875 if (hret
== H_SUCCESS
) {
2876 if (cb4
->jumbo_frame
)
2879 cb4
->jumbo_frame
= 1;
2880 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2887 if (hret
== H_SUCCESS
)
2893 free_page((unsigned long)cb4
);
2899 static ssize_t
ehea_show_port_id(struct device
*dev
,
2900 struct device_attribute
*attr
, char *buf
)
2902 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2903 return sprintf(buf
, "%d", port
->logical_port_id
);
2906 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2909 static void logical_port_release(struct device
*dev
)
2911 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2912 of_node_put(port
->ofdev
.dev
.of_node
);
2915 static struct device
*ehea_register_port(struct ehea_port
*port
,
2916 struct device_node
*dn
)
2920 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
2921 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2922 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2924 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
2925 port
->ofdev
.dev
.release
= logical_port_release
;
2927 ret
= of_device_register(&port
->ofdev
);
2929 pr_err("failed to register device. ret=%d\n", ret
);
2933 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2935 pr_err("failed to register attributes, ret=%d\n", ret
);
2936 goto out_unreg_of_dev
;
2939 return &port
->ofdev
.dev
;
2942 of_device_unregister(&port
->ofdev
);
2947 static void ehea_unregister_port(struct ehea_port
*port
)
2949 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2950 of_device_unregister(&port
->ofdev
);
2953 static const struct net_device_ops ehea_netdev_ops
= {
2954 .ndo_open
= ehea_open
,
2955 .ndo_stop
= ehea_stop
,
2956 .ndo_start_xmit
= ehea_start_xmit
,
2957 #ifdef CONFIG_NET_POLL_CONTROLLER
2958 .ndo_poll_controller
= ehea_netpoll
,
2960 .ndo_get_stats64
= ehea_get_stats64
,
2961 .ndo_set_mac_address
= ehea_set_mac_addr
,
2962 .ndo_validate_addr
= eth_validate_addr
,
2963 .ndo_set_rx_mode
= ehea_set_multicast_list
,
2964 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
2965 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
2966 .ndo_tx_timeout
= ehea_tx_watchdog
,
2969 static struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2970 u32 logical_port_id
,
2971 struct device_node
*dn
)
2974 struct net_device
*dev
;
2975 struct ehea_port
*port
;
2976 struct device
*port_dev
;
2979 /* allocate memory for the port structures */
2980 dev
= alloc_etherdev_mq(sizeof(struct ehea_port
), EHEA_MAX_PORT_RES
);
2987 port
= netdev_priv(dev
);
2989 mutex_init(&port
->port_lock
);
2990 port
->state
= EHEA_PORT_DOWN
;
2991 port
->sig_comp_iv
= sq_entries
/ 10;
2993 port
->adapter
= adapter
;
2995 port
->logical_port_id
= logical_port_id
;
2997 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
2999 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3000 if (!port
->mc_list
) {
3002 goto out_free_ethdev
;
3005 INIT_LIST_HEAD(&port
->mc_list
->list
);
3007 ret
= ehea_sense_port_attr(port
);
3009 goto out_free_mc_list
;
3011 netif_set_real_num_rx_queues(dev
, port
->num_def_qps
);
3012 netif_set_real_num_tx_queues(dev
, port
->num_def_qps
);
3014 port_dev
= ehea_register_port(port
, dn
);
3016 goto out_free_mc_list
;
3018 SET_NETDEV_DEV(dev
, port_dev
);
3020 /* initialize net_device structure */
3021 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3023 dev
->netdev_ops
= &ehea_netdev_ops
;
3024 ehea_set_ethtool_ops(dev
);
3026 dev
->hw_features
= NETIF_F_SG
| NETIF_F_TSO
|
3027 NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_CTAG_TX
;
3028 dev
->features
= NETIF_F_SG
| NETIF_F_TSO
|
3029 NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
|
3030 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
|
3031 NETIF_F_HW_VLAN_CTAG_FILTER
| NETIF_F_RXCSUM
;
3032 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HIGHDMA
|
3034 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3036 /* MTU range: 68 - 9022 */
3037 dev
->min_mtu
= ETH_MIN_MTU
;
3038 dev
->max_mtu
= EHEA_MAX_PACKET_SIZE
;
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 ret
= register_netdev(dev
);
3048 pr_err("register_netdev failed. ret=%d\n", ret
);
3049 goto out_unreg_port
;
3052 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3054 netdev_err(dev
, "failed determining jumbo frame status\n");
3056 netdev_info(dev
, "Jumbo frames are %sabled\n",
3057 jumbo
== 1 ? "en" : "dis");
3059 adapter
->active_ports
++;
3064 ehea_unregister_port(port
);
3067 kfree(port
->mc_list
);
3073 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3074 logical_port_id
, ret
);
3078 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3080 struct ehea_adapter
*adapter
= port
->adapter
;
3082 cancel_work_sync(&port
->reset_task
);
3083 cancel_delayed_work_sync(&port
->stats_work
);
3084 unregister_netdev(port
->netdev
);
3085 ehea_unregister_port(port
);
3086 kfree(port
->mc_list
);
3087 free_netdev(port
->netdev
);
3088 adapter
->active_ports
--;
3091 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3093 struct device_node
*lhea_dn
;
3094 struct device_node
*eth_dn
= NULL
;
3096 const u32
*dn_log_port_id
;
3099 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3100 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3102 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3104 if (!dn_log_port_id
) {
3105 pr_err("bad device node: eth_dn name=%pOF\n", eth_dn
);
3109 if (ehea_add_adapter_mr(adapter
)) {
3110 pr_err("creating MR failed\n");
3111 of_node_put(eth_dn
);
3115 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3118 if (adapter
->port
[i
])
3119 netdev_info(adapter
->port
[i
]->netdev
,
3120 "logical port id #%d\n", *dn_log_port_id
);
3122 ehea_remove_adapter_mr(adapter
);
3129 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3130 u32 logical_port_id
)
3132 struct device_node
*lhea_dn
;
3133 struct device_node
*eth_dn
= NULL
;
3134 const u32
*dn_log_port_id
;
3136 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3137 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3139 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3142 if (*dn_log_port_id
== logical_port_id
)
3149 static ssize_t
ehea_probe_port(struct device
*dev
,
3150 struct device_attribute
*attr
,
3151 const char *buf
, size_t count
)
3153 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3154 struct ehea_port
*port
;
3155 struct device_node
*eth_dn
= NULL
;
3158 u32 logical_port_id
;
3160 sscanf(buf
, "%d", &logical_port_id
);
3162 port
= ehea_get_port(adapter
, logical_port_id
);
3165 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3170 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3173 pr_info("no logical port with id %d found\n", logical_port_id
);
3177 if (ehea_add_adapter_mr(adapter
)) {
3178 pr_err("creating MR failed\n");
3182 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3184 of_node_put(eth_dn
);
3187 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3188 if (!adapter
->port
[i
]) {
3189 adapter
->port
[i
] = port
;
3193 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3196 ehea_remove_adapter_mr(adapter
);
3200 return (ssize_t
) count
;
3203 static ssize_t
ehea_remove_port(struct device
*dev
,
3204 struct device_attribute
*attr
,
3205 const char *buf
, size_t count
)
3207 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3208 struct ehea_port
*port
;
3210 u32 logical_port_id
;
3212 sscanf(buf
, "%d", &logical_port_id
);
3214 port
= ehea_get_port(adapter
, logical_port_id
);
3217 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3220 ehea_shutdown_single_port(port
);
3222 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3223 if (adapter
->port
[i
] == port
) {
3224 adapter
->port
[i
] = NULL
;
3228 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3233 ehea_remove_adapter_mr(adapter
);
3235 return (ssize_t
) count
;
3238 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3239 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3241 static int ehea_create_device_sysfs(struct platform_device
*dev
)
3243 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3247 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3252 static void ehea_remove_device_sysfs(struct platform_device
*dev
)
3254 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3255 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3258 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3259 unsigned long action
, void *unused
)
3261 if (action
== SYS_RESTART
) {
3262 pr_info("Reboot: freeing all eHEA resources\n");
3263 ibmebus_unregister_driver(&ehea_driver
);
3268 static struct notifier_block ehea_reboot_nb
= {
3269 .notifier_call
= ehea_reboot_notifier
,
3272 static int ehea_mem_notifier(struct notifier_block
*nb
,
3273 unsigned long action
, void *data
)
3275 int ret
= NOTIFY_BAD
;
3276 struct memory_notify
*arg
= data
;
3278 mutex_lock(&dlpar_mem_lock
);
3281 case MEM_CANCEL_OFFLINE
:
3282 pr_info("memory offlining canceled");
3283 /* Fall through: re-add canceled memory block */
3286 pr_info("memory is going online");
3287 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3288 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3293 case MEM_GOING_OFFLINE
:
3294 pr_info("memory is going offline");
3295 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3296 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3305 ehea_update_firmware_handles();
3309 mutex_unlock(&dlpar_mem_lock
);
3313 static struct notifier_block ehea_mem_nb
= {
3314 .notifier_call
= ehea_mem_notifier
,
3317 static void ehea_crash_handler(void)
3321 if (ehea_fw_handles
.arr
)
3322 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3323 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3324 ehea_fw_handles
.arr
[i
].fwh
,
3327 if (ehea_bcmc_regs
.arr
)
3328 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3329 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3330 ehea_bcmc_regs
.arr
[i
].port_id
,
3331 ehea_bcmc_regs
.arr
[i
].reg_type
,
3332 ehea_bcmc_regs
.arr
[i
].macaddr
,
3336 static atomic_t ehea_memory_hooks_registered
;
3338 /* Register memory hooks on probe of first adapter */
3339 static int ehea_register_memory_hooks(void)
3343 if (atomic_inc_return(&ehea_memory_hooks_registered
) > 1)
3346 ret
= ehea_create_busmap();
3348 pr_info("ehea_create_busmap failed\n");
3352 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3354 pr_info("register_reboot_notifier failed\n");
3358 ret
= register_memory_notifier(&ehea_mem_nb
);
3360 pr_info("register_memory_notifier failed\n");
3364 ret
= crash_shutdown_register(ehea_crash_handler
);
3366 pr_info("crash_shutdown_register failed\n");
3373 unregister_memory_notifier(&ehea_mem_nb
);
3375 unregister_reboot_notifier(&ehea_reboot_nb
);
3377 atomic_dec(&ehea_memory_hooks_registered
);
3381 static void ehea_unregister_memory_hooks(void)
3383 /* Only remove the hooks if we've registered them */
3384 if (atomic_read(&ehea_memory_hooks_registered
) == 0)
3387 unregister_reboot_notifier(&ehea_reboot_nb
);
3388 if (crash_shutdown_unregister(ehea_crash_handler
))
3389 pr_info("failed unregistering crash handler\n");
3390 unregister_memory_notifier(&ehea_mem_nb
);
3393 static int ehea_probe_adapter(struct platform_device
*dev
)
3395 struct ehea_adapter
*adapter
;
3396 const u64
*adapter_handle
;
3400 ret
= ehea_register_memory_hooks();
3404 if (!dev
|| !dev
->dev
.of_node
) {
3405 pr_err("Invalid ibmebus device probed\n");
3409 adapter
= devm_kzalloc(&dev
->dev
, sizeof(*adapter
), GFP_KERNEL
);
3412 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3416 list_add(&adapter
->list
, &adapter_list
);
3418 adapter
->ofdev
= dev
;
3420 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3423 adapter
->handle
= *adapter_handle
;
3425 if (!adapter
->handle
) {
3426 dev_err(&dev
->dev
, "failed getting handle for adapter"
3427 " '%pOF'\n", dev
->dev
.of_node
);
3432 adapter
->pd
= EHEA_PD_ID
;
3434 platform_set_drvdata(dev
, adapter
);
3437 /* initialize adapter and ports */
3438 /* get adapter properties */
3439 ret
= ehea_sense_adapter_attr(adapter
);
3441 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3445 adapter
->neq
= ehea_create_eq(adapter
,
3446 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3447 if (!adapter
->neq
) {
3449 dev_err(&dev
->dev
, "NEQ creation failed\n");
3453 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3454 (unsigned long)adapter
);
3456 ret
= ehea_create_device_sysfs(dev
);
3460 ret
= ehea_setup_ports(adapter
);
3462 dev_err(&dev
->dev
, "setup_ports failed\n");
3463 goto out_rem_dev_sysfs
;
3466 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3467 ehea_interrupt_neq
, 0,
3468 "ehea_neq", adapter
);
3470 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3471 goto out_shutdown_ports
;
3474 /* Handle any events that might be pending. */
3475 tasklet_hi_schedule(&adapter
->neq_tasklet
);
3481 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3482 if (adapter
->port
[i
]) {
3483 ehea_shutdown_single_port(adapter
->port
[i
]);
3484 adapter
->port
[i
] = NULL
;
3488 ehea_remove_device_sysfs(dev
);
3491 ehea_destroy_eq(adapter
->neq
);
3494 list_del(&adapter
->list
);
3497 ehea_update_firmware_handles();
3502 static int ehea_remove(struct platform_device
*dev
)
3504 struct ehea_adapter
*adapter
= platform_get_drvdata(dev
);
3507 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3508 if (adapter
->port
[i
]) {
3509 ehea_shutdown_single_port(adapter
->port
[i
]);
3510 adapter
->port
[i
] = NULL
;
3513 ehea_remove_device_sysfs(dev
);
3515 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3516 tasklet_kill(&adapter
->neq_tasklet
);
3518 ehea_destroy_eq(adapter
->neq
);
3519 ehea_remove_adapter_mr(adapter
);
3520 list_del(&adapter
->list
);
3522 ehea_update_firmware_handles();
3527 static int check_module_parm(void)
3531 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3532 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3533 pr_info("Bad parameter: rq1_entries\n");
3536 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3537 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3538 pr_info("Bad parameter: rq2_entries\n");
3541 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3542 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3543 pr_info("Bad parameter: rq3_entries\n");
3546 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3547 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3548 pr_info("Bad parameter: sq_entries\n");
3555 static ssize_t
capabilities_show(struct device_driver
*drv
, char *buf
)
3557 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3560 static DRIVER_ATTR_RO(capabilities
);
3562 static int __init
ehea_module_init(void)
3566 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3568 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3569 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3571 mutex_init(&ehea_fw_handles
.lock
);
3572 spin_lock_init(&ehea_bcmc_regs
.lock
);
3574 ret
= check_module_parm();
3578 ret
= ibmebus_register_driver(&ehea_driver
);
3580 pr_err("failed registering eHEA device driver on ebus\n");
3584 ret
= driver_create_file(&ehea_driver
.driver
,
3585 &driver_attr_capabilities
);
3587 pr_err("failed to register capabilities attribute, ret=%d\n",
3595 ibmebus_unregister_driver(&ehea_driver
);
3600 static void __exit
ehea_module_exit(void)
3602 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3603 ibmebus_unregister_driver(&ehea_driver
);
3604 ehea_unregister_memory_hooks();
3605 kfree(ehea_fw_handles
.arr
);
3606 kfree(ehea_bcmc_regs
.arr
);
3607 ehea_destroy_busmap();
3610 module_init(ehea_module_init
);
3611 module_exit(ehea_module_exit
);