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 struct rtnl_link_stats64
*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
;
358 static void ehea_update_stats(struct work_struct
*work
)
360 struct ehea_port
*port
=
361 container_of(work
, struct ehea_port
, stats_work
.work
);
362 struct net_device
*dev
= port
->netdev
;
363 struct rtnl_link_stats64
*stats
= &port
->stats
;
364 struct hcp_ehea_port_cb2
*cb2
;
367 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
369 netdev_err(dev
, "No mem for cb2. Some interface statistics were not updated\n");
373 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
374 port
->logical_port_id
,
375 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
376 if (hret
!= H_SUCCESS
) {
377 netdev_err(dev
, "query_ehea_port failed\n");
381 if (netif_msg_hw(port
))
382 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
384 stats
->multicast
= cb2
->rxmcp
;
385 stats
->rx_errors
= cb2
->rxuerr
;
388 free_page((unsigned long)cb2
);
390 schedule_delayed_work(&port
->stats_work
,
391 round_jiffies_relative(msecs_to_jiffies(1000)));
394 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
396 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
397 struct net_device
*dev
= pr
->port
->netdev
;
398 int max_index_mask
= pr
->rq1_skba
.len
- 1;
399 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
403 pr
->rq1_skba
.os_skbs
= 0;
405 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
407 pr
->rq1_skba
.index
= index
;
408 pr
->rq1_skba
.os_skbs
= fill_wqes
;
412 for (i
= 0; i
< fill_wqes
; i
++) {
413 if (!skb_arr_rq1
[index
]) {
414 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
416 if (!skb_arr_rq1
[index
]) {
417 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
422 index
&= max_index_mask
;
430 ehea_update_rq1a(pr
->qp
, adder
);
433 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
435 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
436 struct net_device
*dev
= pr
->port
->netdev
;
439 if (nr_rq1a
> pr
->rq1_skba
.len
) {
440 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
444 for (i
= 0; i
< nr_rq1a
; i
++) {
445 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
450 ehea_update_rq1a(pr
->qp
, i
- 1);
453 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
454 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
455 int num_wqes
, int wqe_type
, int packet_size
)
457 struct net_device
*dev
= pr
->port
->netdev
;
458 struct ehea_qp
*qp
= pr
->qp
;
459 struct sk_buff
**skb_arr
= q_skba
->arr
;
460 struct ehea_rwqe
*rwqe
;
461 int i
, index
, max_index_mask
, fill_wqes
;
465 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
468 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
469 q_skba
->os_skbs
= fill_wqes
;
473 index
= q_skba
->index
;
474 max_index_mask
= q_skba
->len
- 1;
475 for (i
= 0; i
< fill_wqes
; i
++) {
479 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
481 q_skba
->os_skbs
= fill_wqes
- i
;
482 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
483 netdev_info(pr
->port
->netdev
,
484 "rq%i ran dry - no mem for skb\n",
491 skb_arr
[index
] = skb
;
492 tmp_addr
= ehea_map_vaddr(skb
->data
);
493 if (tmp_addr
== -1) {
494 dev_consume_skb_any(skb
);
495 q_skba
->os_skbs
= fill_wqes
- i
;
500 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
501 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
502 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
503 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
504 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
505 rwqe
->sg_list
[0].len
= packet_size
;
506 rwqe
->data_segments
= 1;
509 index
&= max_index_mask
;
513 q_skba
->index
= index
;
520 ehea_update_rq2a(pr
->qp
, adder
);
522 ehea_update_rq3a(pr
->qp
, adder
);
528 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
530 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
531 nr_of_wqes
, EHEA_RWQE2_TYPE
,
536 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
538 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
539 nr_of_wqes
, EHEA_RWQE3_TYPE
,
540 EHEA_MAX_PACKET_SIZE
);
543 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
545 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
546 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
548 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
549 (cqe
->header_length
== 0))
554 static inline void ehea_fill_skb(struct net_device
*dev
,
555 struct sk_buff
*skb
, struct ehea_cqe
*cqe
,
556 struct ehea_port_res
*pr
)
558 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
560 skb_put(skb
, length
);
561 skb
->protocol
= eth_type_trans(skb
, dev
);
563 /* The packet was not an IPV4 packet so a complemented checksum was
564 calculated. The value is found in the Internet Checksum field. */
565 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
566 skb
->ip_summed
= CHECKSUM_COMPLETE
;
567 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
569 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
571 skb_record_rx_queue(skb
, pr
- &pr
->port
->port_res
[0]);
574 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
576 struct ehea_cqe
*cqe
)
578 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
589 prefetchw(pref
+ EHEA_CACHE_LINE
);
591 pref
= (skb_array
[x
]->data
);
593 prefetch(pref
+ EHEA_CACHE_LINE
);
594 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
595 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
598 skb
= skb_array
[skb_index
];
599 skb_array
[skb_index
] = NULL
;
603 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
604 int arr_len
, int wqe_index
)
616 prefetchw(pref
+ EHEA_CACHE_LINE
);
618 pref
= (skb_array
[x
]->data
);
620 prefetchw(pref
+ EHEA_CACHE_LINE
);
623 skb
= skb_array
[wqe_index
];
624 skb_array
[wqe_index
] = NULL
;
628 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
629 struct ehea_cqe
*cqe
, int *processed_rq2
,
634 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
635 pr
->p_stats
.err_tcp_cksum
++;
636 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
637 pr
->p_stats
.err_ip_cksum
++;
638 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
639 pr
->p_stats
.err_frame_crc
++;
643 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
645 } else if (rq
== 3) {
647 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
651 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
652 if (netif_msg_rx_err(pr
->port
)) {
653 pr_err("Critical receive error for QP %d. Resetting port.\n",
654 pr
->qp
->init_attr
.qp_nr
);
655 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
657 ehea_schedule_port_reset(pr
->port
);
664 static int ehea_proc_rwqes(struct net_device
*dev
,
665 struct ehea_port_res
*pr
,
668 struct ehea_port
*port
= pr
->port
;
669 struct ehea_qp
*qp
= pr
->qp
;
670 struct ehea_cqe
*cqe
;
672 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
673 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
674 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
675 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
676 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
677 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
678 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
679 u64 processed_bytes
= 0;
680 int wqe_index
, last_wqe_index
, rq
, port_reset
;
682 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
685 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
686 while ((processed
< budget
) && cqe
) {
690 if (netif_msg_rx_status(port
))
691 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
693 last_wqe_index
= wqe_index
;
695 if (!ehea_check_cqe(cqe
, &rq
)) {
698 skb
= get_skb_by_index_ll(skb_arr_rq1
,
701 if (unlikely(!skb
)) {
702 netif_info(port
, rx_err
, dev
,
703 "LL rq1: skb=NULL\n");
705 skb
= netdev_alloc_skb(dev
,
710 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
711 cqe
->num_bytes_transfered
- 4);
712 ehea_fill_skb(dev
, skb
, cqe
, pr
);
713 } else if (rq
== 2) {
715 skb
= get_skb_by_index(skb_arr_rq2
,
716 skb_arr_rq2_len
, cqe
);
717 if (unlikely(!skb
)) {
718 netif_err(port
, rx_err
, dev
,
722 ehea_fill_skb(dev
, skb
, cqe
, pr
);
726 skb
= get_skb_by_index(skb_arr_rq3
,
727 skb_arr_rq3_len
, cqe
);
728 if (unlikely(!skb
)) {
729 netif_err(port
, rx_err
, dev
,
733 ehea_fill_skb(dev
, skb
, cqe
, pr
);
737 processed_bytes
+= skb
->len
;
739 if (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
740 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
),
743 napi_gro_receive(&pr
->napi
, skb
);
745 pr
->p_stats
.poll_receive_errors
++;
746 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
752 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
755 pr
->rx_packets
+= processed
;
756 pr
->rx_bytes
+= processed_bytes
;
758 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
759 ehea_refill_rq2(pr
, processed_rq2
);
760 ehea_refill_rq3(pr
, processed_rq3
);
765 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
767 static void reset_sq_restart_flag(struct ehea_port
*port
)
771 for (i
= 0; i
< port
->num_def_qps
; i
++) {
772 struct ehea_port_res
*pr
= &port
->port_res
[i
];
773 pr
->sq_restart_flag
= 0;
775 wake_up(&port
->restart_wq
);
778 static void check_sqs(struct ehea_port
*port
)
780 struct ehea_swqe
*swqe
;
784 for (i
= 0; i
< port
->num_def_qps
; i
++) {
785 struct ehea_port_res
*pr
= &port
->port_res
[i
];
788 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
789 memset(swqe
, 0, SWQE_HEADER_SIZE
);
790 atomic_dec(&pr
->swqe_avail
);
792 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
793 swqe
->wr_id
= SWQE_RESTART_CHECK
;
794 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
795 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
796 swqe
->immediate_data_length
= 80;
798 ehea_post_swqe(pr
->qp
, swqe
);
800 ret
= wait_event_timeout(port
->restart_wq
,
801 pr
->sq_restart_flag
== 0,
802 msecs_to_jiffies(100));
805 pr_err("HW/SW queues out of sync\n");
806 ehea_schedule_port_reset(pr
->port
);
813 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
816 struct ehea_cq
*send_cq
= pr
->send_cq
;
817 struct ehea_cqe
*cqe
;
818 int quota
= my_quota
;
822 struct netdev_queue
*txq
= netdev_get_tx_queue(pr
->port
->netdev
,
823 pr
- &pr
->port
->port_res
[0]);
825 cqe
= ehea_poll_cq(send_cq
);
826 while (cqe
&& (quota
> 0)) {
827 ehea_inc_cq(send_cq
);
832 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
833 pr
->sq_restart_flag
= 1;
838 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
839 pr_err("Bad send completion status=0x%04X\n",
842 if (netif_msg_tx_err(pr
->port
))
843 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
845 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
846 pr_err("Resetting port\n");
847 ehea_schedule_port_reset(pr
->port
);
852 if (netif_msg_tx_done(pr
->port
))
853 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
855 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
856 == EHEA_SWQE2_TYPE
)) {
858 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
859 skb
= pr
->sq_skba
.arr
[index
];
860 dev_consume_skb_any(skb
);
861 pr
->sq_skba
.arr
[index
] = NULL
;
864 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
867 cqe
= ehea_poll_cq(send_cq
);
870 ehea_update_feca(send_cq
, cqe_counter
);
871 atomic_add(swqe_av
, &pr
->swqe_avail
);
873 if (unlikely(netif_tx_queue_stopped(txq
) &&
874 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))) {
875 __netif_tx_lock(txq
, smp_processor_id());
876 if (netif_tx_queue_stopped(txq
) &&
877 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))
878 netif_tx_wake_queue(txq
);
879 __netif_tx_unlock(txq
);
882 wake_up(&pr
->port
->swqe_avail_wq
);
887 #define EHEA_POLL_MAX_CQES 65535
889 static int ehea_poll(struct napi_struct
*napi
, int budget
)
891 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
893 struct net_device
*dev
= pr
->port
->netdev
;
894 struct ehea_cqe
*cqe
;
895 struct ehea_cqe
*cqe_skb
= NULL
;
899 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
900 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
902 while (rx
!= budget
) {
904 ehea_reset_cq_ep(pr
->recv_cq
);
905 ehea_reset_cq_ep(pr
->send_cq
);
906 ehea_reset_cq_n1(pr
->recv_cq
);
907 ehea_reset_cq_n1(pr
->send_cq
);
909 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
910 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
912 if (!cqe
&& !cqe_skb
)
915 if (!napi_reschedule(napi
))
918 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
919 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
925 #ifdef CONFIG_NET_POLL_CONTROLLER
926 static void ehea_netpoll(struct net_device
*dev
)
928 struct ehea_port
*port
= netdev_priv(dev
);
931 for (i
= 0; i
< port
->num_def_qps
; i
++)
932 napi_schedule(&port
->port_res
[i
].napi
);
936 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
938 struct ehea_port_res
*pr
= param
;
940 napi_schedule(&pr
->napi
);
945 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
947 struct ehea_port
*port
= param
;
948 struct ehea_eqe
*eqe
;
951 u64 resource_type
, aer
, aerr
;
954 eqe
= ehea_poll_eq(port
->qp_eq
);
957 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
958 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
959 eqe
->entry
, qp_token
);
961 qp
= port
->port_res
[qp_token
].qp
;
963 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
966 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
967 if ((aer
& EHEA_AER_RESET_MASK
) ||
968 (aerr
& EHEA_AERR_RESET_MASK
))
971 reset_port
= 1; /* Reset in case of CQ or EQ error */
973 eqe
= ehea_poll_eq(port
->qp_eq
);
977 pr_err("Resetting port\n");
978 ehea_schedule_port_reset(port
);
984 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
989 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
990 if (adapter
->port
[i
])
991 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
992 return adapter
->port
[i
];
996 int ehea_sense_port_attr(struct ehea_port
*port
)
1000 struct hcp_ehea_port_cb0
*cb0
;
1002 /* may be called via ehea_neq_tasklet() */
1003 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
1005 pr_err("no mem for cb0\n");
1010 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1011 port
->logical_port_id
, H_PORT_CB0
,
1012 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1014 if (hret
!= H_SUCCESS
) {
1020 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1022 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1023 ret
= -EADDRNOTAVAIL
;
1028 switch (cb0
->port_speed
) {
1030 port
->port_speed
= EHEA_SPEED_10M
;
1031 port
->full_duplex
= 0;
1034 port
->port_speed
= EHEA_SPEED_10M
;
1035 port
->full_duplex
= 1;
1037 case H_SPEED_100M_H
:
1038 port
->port_speed
= EHEA_SPEED_100M
;
1039 port
->full_duplex
= 0;
1041 case H_SPEED_100M_F
:
1042 port
->port_speed
= EHEA_SPEED_100M
;
1043 port
->full_duplex
= 1;
1046 port
->port_speed
= EHEA_SPEED_1G
;
1047 port
->full_duplex
= 1;
1050 port
->port_speed
= EHEA_SPEED_10G
;
1051 port
->full_duplex
= 1;
1054 port
->port_speed
= 0;
1055 port
->full_duplex
= 0;
1060 port
->num_mcs
= cb0
->num_default_qps
;
1062 /* Number of default QPs */
1064 port
->num_def_qps
= cb0
->num_default_qps
;
1066 port
->num_def_qps
= 1;
1068 if (!port
->num_def_qps
) {
1075 if (ret
|| netif_msg_probe(port
))
1076 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1077 free_page((unsigned long)cb0
);
1082 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1084 struct hcp_ehea_port_cb4
*cb4
;
1088 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1090 pr_err("no mem for cb4\n");
1095 cb4
->port_speed
= port_speed
;
1097 netif_carrier_off(port
->netdev
);
1099 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1100 port
->logical_port_id
,
1101 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1102 if (hret
== H_SUCCESS
) {
1103 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1105 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1106 port
->logical_port_id
,
1107 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1109 if (hret
== H_SUCCESS
) {
1110 switch (cb4
->port_speed
) {
1112 port
->port_speed
= EHEA_SPEED_10M
;
1113 port
->full_duplex
= 0;
1116 port
->port_speed
= EHEA_SPEED_10M
;
1117 port
->full_duplex
= 1;
1119 case H_SPEED_100M_H
:
1120 port
->port_speed
= EHEA_SPEED_100M
;
1121 port
->full_duplex
= 0;
1123 case H_SPEED_100M_F
:
1124 port
->port_speed
= EHEA_SPEED_100M
;
1125 port
->full_duplex
= 1;
1128 port
->port_speed
= EHEA_SPEED_1G
;
1129 port
->full_duplex
= 1;
1132 port
->port_speed
= EHEA_SPEED_10G
;
1133 port
->full_duplex
= 1;
1136 port
->port_speed
= 0;
1137 port
->full_duplex
= 0;
1141 pr_err("Failed sensing port speed\n");
1145 if (hret
== H_AUTHORITY
) {
1146 pr_info("Hypervisor denied setting port speed\n");
1150 pr_err("Failed setting port speed\n");
1153 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1154 netif_carrier_on(port
->netdev
);
1156 free_page((unsigned long)cb4
);
1161 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1166 struct ehea_port
*port
;
1167 struct net_device
*dev
;
1169 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1170 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1171 port
= ehea_get_port(adapter
, portnum
);
1173 netdev_err(NULL
, "unknown portnum %x\n", portnum
);
1179 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1181 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1182 if (!netif_carrier_ok(dev
)) {
1183 ret
= ehea_sense_port_attr(port
);
1185 netdev_err(dev
, "failed resensing port attributes\n");
1189 netif_info(port
, link
, dev
,
1190 "Logical port up: %dMbps %s Duplex\n",
1192 port
->full_duplex
== 1 ?
1195 netif_carrier_on(dev
);
1196 netif_wake_queue(dev
);
1199 if (netif_carrier_ok(dev
)) {
1200 netif_info(port
, link
, dev
,
1201 "Logical port down\n");
1202 netif_carrier_off(dev
);
1203 netif_tx_disable(dev
);
1206 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1207 port
->phy_link
= EHEA_PHY_LINK_UP
;
1208 netif_info(port
, link
, dev
,
1209 "Physical port up\n");
1210 if (prop_carrier_state
)
1211 netif_carrier_on(dev
);
1213 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1214 netif_info(port
, link
, dev
,
1215 "Physical port down\n");
1216 if (prop_carrier_state
)
1217 netif_carrier_off(dev
);
1220 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1222 "External switch port is primary port\n");
1225 "External switch port is backup port\n");
1228 case EHEA_EC_ADAPTER_MALFUNC
:
1229 netdev_err(dev
, "Adapter malfunction\n");
1231 case EHEA_EC_PORT_MALFUNC
:
1232 netdev_info(dev
, "Port malfunction\n");
1233 netif_carrier_off(dev
);
1234 netif_tx_disable(dev
);
1237 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1242 static void ehea_neq_tasklet(unsigned long data
)
1244 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1245 struct ehea_eqe
*eqe
;
1248 eqe
= ehea_poll_eq(adapter
->neq
);
1249 pr_debug("eqe=%p\n", eqe
);
1252 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1253 ehea_parse_eqe(adapter
, eqe
->entry
);
1254 eqe
= ehea_poll_eq(adapter
->neq
);
1255 pr_debug("next eqe=%p\n", eqe
);
1258 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1259 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1260 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1262 ehea_h_reset_events(adapter
->handle
,
1263 adapter
->neq
->fw_handle
, event_mask
);
1266 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1268 struct ehea_adapter
*adapter
= param
;
1269 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1274 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1277 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1279 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1281 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1283 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1288 static int ehea_reg_interrupts(struct net_device
*dev
)
1290 struct ehea_port
*port
= netdev_priv(dev
);
1291 struct ehea_port_res
*pr
;
1295 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1298 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1299 ehea_qp_aff_irq_handler
,
1300 0, port
->int_aff_name
, port
);
1302 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1303 port
->qp_eq
->attr
.ist1
);
1307 netif_info(port
, ifup
, dev
,
1308 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1309 port
->qp_eq
->attr
.ist1
);
1312 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1313 pr
= &port
->port_res
[i
];
1314 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1315 "%s-queue%d", dev
->name
, i
);
1316 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1317 ehea_recv_irq_handler
,
1318 0, pr
->int_send_name
, pr
);
1320 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1321 i
, pr
->eq
->attr
.ist1
);
1324 netif_info(port
, ifup
, dev
,
1325 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1326 pr
->eq
->attr
.ist1
, i
);
1334 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1335 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1339 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1340 i
= port
->num_def_qps
;
1346 static void ehea_free_interrupts(struct net_device
*dev
)
1348 struct ehea_port
*port
= netdev_priv(dev
);
1349 struct ehea_port_res
*pr
;
1354 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1355 pr
= &port
->port_res
[i
];
1356 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1357 netif_info(port
, intr
, dev
,
1358 "free send irq for res %d with handle 0x%X\n",
1359 i
, pr
->eq
->attr
.ist1
);
1362 /* associated events */
1363 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1364 netif_info(port
, intr
, dev
,
1365 "associated event interrupt for handle 0x%X freed\n",
1366 port
->qp_eq
->attr
.ist1
);
1369 static int ehea_configure_port(struct ehea_port
*port
)
1373 struct hcp_ehea_port_cb0
*cb0
;
1376 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1380 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1381 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1382 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1383 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1384 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1385 PXLY_RC_VLAN_FILTER
)
1386 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1388 for (i
= 0; i
< port
->num_mcs
; i
++)
1390 cb0
->default_qpn_arr
[i
] =
1391 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1393 cb0
->default_qpn_arr
[i
] =
1394 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1396 if (netif_msg_ifup(port
))
1397 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1399 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1400 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1402 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1403 port
->logical_port_id
,
1404 H_PORT_CB0
, mask
, cb0
);
1406 if (hret
!= H_SUCCESS
)
1412 free_page((unsigned long)cb0
);
1417 static int ehea_gen_smrs(struct ehea_port_res
*pr
)
1420 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1422 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1426 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1433 ehea_rem_mr(&pr
->send_mr
);
1435 pr_err("Generating SMRS failed\n");
1439 static int ehea_rem_smrs(struct ehea_port_res
*pr
)
1441 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1442 (ehea_rem_mr(&pr
->recv_mr
)))
1448 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1450 int arr_size
= sizeof(void *) * max_q_entries
;
1452 q_skba
->arr
= vzalloc(arr_size
);
1456 q_skba
->len
= max_q_entries
;
1458 q_skba
->os_skbs
= 0;
1463 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1464 struct port_res_cfg
*pr_cfg
, int queue_token
)
1466 struct ehea_adapter
*adapter
= port
->adapter
;
1467 enum ehea_eq_type eq_type
= EHEA_EQ
;
1468 struct ehea_qp_init_attr
*init_attr
= NULL
;
1470 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1472 tx_bytes
= pr
->tx_bytes
;
1473 tx_packets
= pr
->tx_packets
;
1474 rx_bytes
= pr
->rx_bytes
;
1475 rx_packets
= pr
->rx_packets
;
1477 memset(pr
, 0, sizeof(struct ehea_port_res
));
1479 pr
->tx_bytes
= rx_bytes
;
1480 pr
->tx_packets
= tx_packets
;
1481 pr
->rx_bytes
= rx_bytes
;
1482 pr
->rx_packets
= rx_packets
;
1486 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1488 pr_err("create_eq failed (eq)\n");
1492 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1494 port
->logical_port_id
);
1496 pr_err("create_cq failed (cq_recv)\n");
1500 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1502 port
->logical_port_id
);
1504 pr_err("create_cq failed (cq_send)\n");
1508 if (netif_msg_ifup(port
))
1509 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1510 pr
->send_cq
->attr
.act_nr_of_cqes
,
1511 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1513 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1516 pr_err("no mem for ehea_qp_init_attr\n");
1520 init_attr
->low_lat_rq1
= 1;
1521 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1522 init_attr
->rq_count
= 3;
1523 init_attr
->qp_token
= queue_token
;
1524 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1525 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1526 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1527 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1528 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1529 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1530 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1531 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1532 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1533 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1534 init_attr
->port_nr
= port
->logical_port_id
;
1535 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1536 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1537 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1539 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1541 pr_err("create_qp failed\n");
1546 if (netif_msg_ifup(port
))
1547 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",
1549 init_attr
->act_nr_send_wqes
,
1550 init_attr
->act_nr_rwqes_rq1
,
1551 init_attr
->act_nr_rwqes_rq2
,
1552 init_attr
->act_nr_rwqes_rq3
);
1554 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1556 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1557 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1558 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1559 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1563 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1564 if (ehea_gen_smrs(pr
) != 0) {
1569 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1573 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1580 vfree(pr
->sq_skba
.arr
);
1581 vfree(pr
->rq1_skba
.arr
);
1582 vfree(pr
->rq2_skba
.arr
);
1583 vfree(pr
->rq3_skba
.arr
);
1584 ehea_destroy_qp(pr
->qp
);
1585 ehea_destroy_cq(pr
->send_cq
);
1586 ehea_destroy_cq(pr
->recv_cq
);
1587 ehea_destroy_eq(pr
->eq
);
1592 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1597 netif_napi_del(&pr
->napi
);
1599 ret
= ehea_destroy_qp(pr
->qp
);
1602 ehea_destroy_cq(pr
->send_cq
);
1603 ehea_destroy_cq(pr
->recv_cq
);
1604 ehea_destroy_eq(pr
->eq
);
1606 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1607 if (pr
->rq1_skba
.arr
[i
])
1608 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1610 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1611 if (pr
->rq2_skba
.arr
[i
])
1612 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1614 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1615 if (pr
->rq3_skba
.arr
[i
])
1616 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1618 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1619 if (pr
->sq_skba
.arr
[i
])
1620 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1622 vfree(pr
->rq1_skba
.arr
);
1623 vfree(pr
->rq2_skba
.arr
);
1624 vfree(pr
->rq3_skba
.arr
);
1625 vfree(pr
->sq_skba
.arr
);
1626 ret
= ehea_rem_smrs(pr
);
1631 static void write_swqe2_immediate(struct sk_buff
*skb
, struct ehea_swqe
*swqe
,
1634 int skb_data_size
= skb_headlen(skb
);
1635 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1636 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1637 unsigned int immediate_len
= SWQE2_MAX_IMM
;
1639 swqe
->descriptors
= 0;
1641 if (skb_is_gso(skb
)) {
1642 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1643 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1645 * For TSO packets we only copy the headers into the
1648 immediate_len
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1651 if (skb_is_gso(skb
) || skb_data_size
>= SWQE2_MAX_IMM
) {
1652 skb_copy_from_linear_data(skb
, imm_data
, immediate_len
);
1653 swqe
->immediate_data_length
= immediate_len
;
1655 if (skb_data_size
> immediate_len
) {
1656 sg1entry
->l_key
= lkey
;
1657 sg1entry
->len
= skb_data_size
- immediate_len
;
1659 ehea_map_vaddr(skb
->data
+ immediate_len
);
1660 swqe
->descriptors
++;
1663 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1664 swqe
->immediate_data_length
= skb_data_size
;
1668 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1669 struct ehea_swqe
*swqe
, u32 lkey
)
1671 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1673 int nfrags
, sg1entry_contains_frag_data
, i
;
1675 nfrags
= skb_shinfo(skb
)->nr_frags
;
1676 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1677 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1678 sg1entry_contains_frag_data
= 0;
1680 write_swqe2_immediate(skb
, swqe
, lkey
);
1682 /* write descriptors */
1684 if (swqe
->descriptors
== 0) {
1685 /* sg1entry not yet used */
1686 frag
= &skb_shinfo(skb
)->frags
[0];
1688 /* copy sg1entry data */
1689 sg1entry
->l_key
= lkey
;
1690 sg1entry
->len
= skb_frag_size(frag
);
1692 ehea_map_vaddr(skb_frag_address(frag
));
1693 swqe
->descriptors
++;
1694 sg1entry_contains_frag_data
= 1;
1697 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1699 frag
= &skb_shinfo(skb
)->frags
[i
];
1700 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1702 sgentry
->l_key
= lkey
;
1703 sgentry
->len
= skb_frag_size(frag
);
1704 sgentry
->vaddr
= ehea_map_vaddr(skb_frag_address(frag
));
1705 swqe
->descriptors
++;
1710 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1716 /* De/Register untagged packets */
1717 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1718 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1719 port
->logical_port_id
,
1720 reg_type
, port
->mac_addr
, 0, hcallid
);
1721 if (hret
!= H_SUCCESS
) {
1722 pr_err("%sregistering bc address failed (tagged)\n",
1723 hcallid
== H_REG_BCMC
? "" : "de");
1728 /* De/Register VLAN packets */
1729 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1730 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1731 port
->logical_port_id
,
1732 reg_type
, port
->mac_addr
, 0, hcallid
);
1733 if (hret
!= H_SUCCESS
) {
1734 pr_err("%sregistering bc address failed (vlan)\n",
1735 hcallid
== H_REG_BCMC
? "" : "de");
1742 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1744 struct ehea_port
*port
= netdev_priv(dev
);
1745 struct sockaddr
*mac_addr
= sa
;
1746 struct hcp_ehea_port_cb0
*cb0
;
1750 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1751 ret
= -EADDRNOTAVAIL
;
1755 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1757 pr_err("no mem for cb0\n");
1762 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1764 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1766 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1767 port
->logical_port_id
, H_PORT_CB0
,
1768 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1769 if (hret
!= H_SUCCESS
) {
1774 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1776 /* Deregister old MAC in pHYP */
1777 if (port
->state
== EHEA_PORT_UP
) {
1778 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1783 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1785 /* Register new MAC in pHYP */
1786 if (port
->state
== EHEA_PORT_UP
) {
1787 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1795 ehea_update_bcmc_registrations();
1797 free_page((unsigned long)cb0
);
1802 static void ehea_promiscuous_error(u64 hret
, int enable
)
1804 if (hret
== H_AUTHORITY
)
1805 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1806 enable
== 1 ? "en" : "dis");
1808 pr_err("failed %sabling promiscuous mode\n",
1809 enable
== 1 ? "en" : "dis");
1812 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1814 struct ehea_port
*port
= netdev_priv(dev
);
1815 struct hcp_ehea_port_cb7
*cb7
;
1818 if (enable
== port
->promisc
)
1821 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1823 pr_err("no mem for cb7\n");
1827 /* Modify Pxs_DUCQPN in CB7 */
1828 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1830 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1831 port
->logical_port_id
,
1832 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1834 ehea_promiscuous_error(hret
, enable
);
1838 port
->promisc
= enable
;
1840 free_page((unsigned long)cb7
);
1843 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1849 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_UNTAGGED
;
1850 if (mc_mac_addr
== 0)
1851 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1853 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1854 port
->logical_port_id
,
1855 reg_type
, mc_mac_addr
, 0, hcallid
);
1859 reg_type
= EHEA_BCMC_MULTICAST
| EHEA_BCMC_VLANID_ALL
;
1860 if (mc_mac_addr
== 0)
1861 reg_type
|= EHEA_BCMC_SCOPE_ALL
;
1863 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1864 port
->logical_port_id
,
1865 reg_type
, mc_mac_addr
, 0, hcallid
);
1870 static int ehea_drop_multicast_list(struct net_device
*dev
)
1872 struct ehea_port
*port
= netdev_priv(dev
);
1873 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1874 struct list_head
*pos
;
1875 struct list_head
*temp
;
1879 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1880 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1882 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1885 pr_err("failed deregistering mcast MAC\n");
1895 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1897 struct ehea_port
*port
= netdev_priv(dev
);
1900 if (!port
->allmulti
) {
1902 /* Enable ALLMULTI */
1903 ehea_drop_multicast_list(dev
);
1904 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1909 "failed enabling IFF_ALLMULTI\n");
1913 /* Disable ALLMULTI */
1914 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1919 "failed disabling IFF_ALLMULTI\n");
1924 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1926 struct ehea_mc_list
*ehea_mcl_entry
;
1929 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1930 if (!ehea_mcl_entry
)
1933 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1935 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1937 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1940 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1942 pr_err("failed registering mcast MAC\n");
1943 kfree(ehea_mcl_entry
);
1947 static void ehea_set_multicast_list(struct net_device
*dev
)
1949 struct ehea_port
*port
= netdev_priv(dev
);
1950 struct netdev_hw_addr
*ha
;
1953 ehea_promiscuous(dev
, !!(dev
->flags
& IFF_PROMISC
));
1955 if (dev
->flags
& IFF_ALLMULTI
) {
1956 ehea_allmulti(dev
, 1);
1959 ehea_allmulti(dev
, 0);
1961 if (!netdev_mc_empty(dev
)) {
1962 ret
= ehea_drop_multicast_list(dev
);
1964 /* Dropping the current multicast list failed.
1965 * Enabling ALL_MULTI is the best we can do.
1967 ehea_allmulti(dev
, 1);
1970 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
1971 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1972 port
->adapter
->max_mc_mac
);
1976 netdev_for_each_mc_addr(ha
, dev
)
1977 ehea_add_multicast_entry(port
, ha
->addr
);
1981 ehea_update_bcmc_registrations();
1984 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1986 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1992 static void xmit_common(struct sk_buff
*skb
, struct ehea_swqe
*swqe
)
1994 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
| EHEA_SWQE_CRC
;
1996 if (vlan_get_protocol(skb
) != htons(ETH_P_IP
))
1999 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2000 swqe
->tx_control
|= EHEA_SWQE_IP_CHECKSUM
;
2002 swqe
->ip_start
= skb_network_offset(skb
);
2003 swqe
->ip_end
= swqe
->ip_start
+ ip_hdrlen(skb
) - 1;
2005 switch (ip_hdr(skb
)->protocol
) {
2007 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2008 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2010 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2011 offsetof(struct udphdr
, check
);
2015 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2016 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2018 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2019 offsetof(struct tcphdr
, check
);
2024 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2025 struct ehea_swqe
*swqe
, u32 lkey
)
2027 swqe
->tx_control
|= EHEA_SWQE_DESCRIPTORS_PRESENT
;
2029 xmit_common(skb
, swqe
);
2031 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2034 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2035 struct ehea_swqe
*swqe
)
2037 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2039 xmit_common(skb
, swqe
);
2042 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2044 skb_copy_bits(skb
, 0, imm_data
, skb
->len
);
2046 swqe
->immediate_data_length
= skb
->len
;
2047 dev_consume_skb_any(skb
);
2050 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2052 struct ehea_port
*port
= netdev_priv(dev
);
2053 struct ehea_swqe
*swqe
;
2056 struct ehea_port_res
*pr
;
2057 struct netdev_queue
*txq
;
2059 pr
= &port
->port_res
[skb_get_queue_mapping(skb
)];
2060 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
2062 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2063 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2064 atomic_dec(&pr
->swqe_avail
);
2066 if (skb_vlan_tag_present(skb
)) {
2067 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2068 swqe
->vlan_tag
= skb_vlan_tag_get(skb
);
2072 pr
->tx_bytes
+= skb
->len
;
2074 if (skb
->len
<= SWQE3_MAX_IMM
) {
2075 u32 sig_iv
= port
->sig_comp_iv
;
2076 u32 swqe_num
= pr
->swqe_id_counter
;
2077 ehea_xmit3(skb
, dev
, swqe
);
2078 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2079 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2080 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2081 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2083 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2084 pr
->swqe_ll_count
= 0;
2086 pr
->swqe_ll_count
+= 1;
2089 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2090 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2091 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2092 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2093 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2095 pr
->sq_skba
.index
++;
2096 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2098 lkey
= pr
->send_mr
.lkey
;
2099 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2100 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2102 pr
->swqe_id_counter
+= 1;
2104 netif_info(port
, tx_queued
, dev
,
2105 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2106 if (netif_msg_tx_queued(port
))
2107 ehea_dump(swqe
, 512, "swqe");
2109 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2110 netif_tx_stop_queue(txq
);
2111 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2114 ehea_post_swqe(pr
->qp
, swqe
);
2116 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2117 pr
->p_stats
.queue_stopped
++;
2118 netif_tx_stop_queue(txq
);
2121 return NETDEV_TX_OK
;
2124 static int ehea_vlan_rx_add_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
2126 struct ehea_port
*port
= netdev_priv(dev
);
2127 struct ehea_adapter
*adapter
= port
->adapter
;
2128 struct hcp_ehea_port_cb1
*cb1
;
2133 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2135 pr_err("no mem for cb1\n");
2140 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2141 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2142 if (hret
!= H_SUCCESS
) {
2143 pr_err("query_ehea_port failed\n");
2149 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2151 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2152 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2153 if (hret
!= H_SUCCESS
) {
2154 pr_err("modify_ehea_port failed\n");
2158 free_page((unsigned long)cb1
);
2162 static int ehea_vlan_rx_kill_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
2164 struct ehea_port
*port
= netdev_priv(dev
);
2165 struct ehea_adapter
*adapter
= port
->adapter
;
2166 struct hcp_ehea_port_cb1
*cb1
;
2171 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2173 pr_err("no mem for cb1\n");
2178 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2179 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2180 if (hret
!= H_SUCCESS
) {
2181 pr_err("query_ehea_port failed\n");
2187 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2189 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2190 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2191 if (hret
!= H_SUCCESS
) {
2192 pr_err("modify_ehea_port failed\n");
2196 free_page((unsigned long)cb1
);
2200 static int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2206 struct hcp_modify_qp_cb0
*cb0
;
2208 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2214 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2215 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2216 if (hret
!= H_SUCCESS
) {
2217 pr_err("query_ehea_qp failed (1)\n");
2221 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2222 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2223 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2224 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2225 if (hret
!= H_SUCCESS
) {
2226 pr_err("modify_ehea_qp failed (1)\n");
2230 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2231 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2232 if (hret
!= H_SUCCESS
) {
2233 pr_err("query_ehea_qp failed (2)\n");
2237 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2238 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2239 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2240 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2241 if (hret
!= H_SUCCESS
) {
2242 pr_err("modify_ehea_qp failed (2)\n");
2246 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2247 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2248 if (hret
!= H_SUCCESS
) {
2249 pr_err("query_ehea_qp failed (3)\n");
2253 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2254 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2255 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2256 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2257 if (hret
!= H_SUCCESS
) {
2258 pr_err("modify_ehea_qp failed (3)\n");
2262 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2263 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2264 if (hret
!= H_SUCCESS
) {
2265 pr_err("query_ehea_qp failed (4)\n");
2271 free_page((unsigned long)cb0
);
2275 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
)
2278 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2279 enum ehea_eq_type eq_type
= EHEA_EQ
;
2281 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2282 EHEA_MAX_ENTRIES_EQ
, 1);
2285 pr_err("ehea_create_eq failed (qp_eq)\n");
2289 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2290 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2291 pr_cfg
.max_entries_sq
= sq_entries
;
2292 pr_cfg
.max_entries_rq1
= rq1_entries
;
2293 pr_cfg
.max_entries_rq2
= rq2_entries
;
2294 pr_cfg
.max_entries_rq3
= rq3_entries
;
2296 pr_cfg_small_rx
.max_entries_rcq
= 1;
2297 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2298 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2299 pr_cfg_small_rx
.max_entries_rq1
= 1;
2300 pr_cfg_small_rx
.max_entries_rq2
= 1;
2301 pr_cfg_small_rx
.max_entries_rq3
= 1;
2303 for (i
= 0; i
< def_qps
; i
++) {
2304 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2308 for (i
= def_qps
; i
< def_qps
; i
++) {
2309 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2310 &pr_cfg_small_rx
, i
);
2319 ehea_clean_portres(port
, &port
->port_res
[i
]);
2322 ehea_destroy_eq(port
->qp_eq
);
2326 static int ehea_clean_all_portres(struct ehea_port
*port
)
2331 for (i
= 0; i
< port
->num_def_qps
; i
++)
2332 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2334 ret
|= ehea_destroy_eq(port
->qp_eq
);
2339 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2341 if (adapter
->active_ports
)
2344 ehea_rem_mr(&adapter
->mr
);
2347 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2349 if (adapter
->active_ports
)
2352 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2355 static int ehea_up(struct net_device
*dev
)
2358 struct ehea_port
*port
= netdev_priv(dev
);
2360 if (port
->state
== EHEA_PORT_UP
)
2363 ret
= ehea_port_res_setup(port
, port
->num_def_qps
);
2365 netdev_err(dev
, "port_res_failed\n");
2369 /* Set default QP for this port */
2370 ret
= ehea_configure_port(port
);
2372 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2376 ret
= ehea_reg_interrupts(dev
);
2378 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2382 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2383 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2385 netdev_err(dev
, "activate_qp failed\n");
2390 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2391 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2393 netdev_err(dev
, "out_free_irqs\n");
2398 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2404 port
->state
= EHEA_PORT_UP
;
2410 ehea_free_interrupts(dev
);
2413 ehea_clean_all_portres(port
);
2416 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2418 ehea_update_bcmc_registrations();
2419 ehea_update_firmware_handles();
2424 static void port_napi_disable(struct ehea_port
*port
)
2428 for (i
= 0; i
< port
->num_def_qps
; i
++)
2429 napi_disable(&port
->port_res
[i
].napi
);
2432 static void port_napi_enable(struct ehea_port
*port
)
2436 for (i
= 0; i
< port
->num_def_qps
; i
++)
2437 napi_enable(&port
->port_res
[i
].napi
);
2440 static int ehea_open(struct net_device
*dev
)
2443 struct ehea_port
*port
= netdev_priv(dev
);
2445 mutex_lock(&port
->port_lock
);
2447 netif_info(port
, ifup
, dev
, "enabling port\n");
2451 port_napi_enable(port
);
2452 netif_tx_start_all_queues(dev
);
2455 mutex_unlock(&port
->port_lock
);
2456 schedule_delayed_work(&port
->stats_work
,
2457 round_jiffies_relative(msecs_to_jiffies(1000)));
2462 static int ehea_down(struct net_device
*dev
)
2465 struct ehea_port
*port
= netdev_priv(dev
);
2467 if (port
->state
== EHEA_PORT_DOWN
)
2470 ehea_drop_multicast_list(dev
);
2471 ehea_allmulti(dev
, 0);
2472 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2474 ehea_free_interrupts(dev
);
2476 port
->state
= EHEA_PORT_DOWN
;
2478 ehea_update_bcmc_registrations();
2480 ret
= ehea_clean_all_portres(port
);
2482 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2484 ehea_update_firmware_handles();
2489 static int ehea_stop(struct net_device
*dev
)
2492 struct ehea_port
*port
= netdev_priv(dev
);
2494 netif_info(port
, ifdown
, dev
, "disabling port\n");
2496 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2497 cancel_work_sync(&port
->reset_task
);
2498 cancel_delayed_work_sync(&port
->stats_work
);
2499 mutex_lock(&port
->port_lock
);
2500 netif_tx_stop_all_queues(dev
);
2501 port_napi_disable(port
);
2502 ret
= ehea_down(dev
);
2503 mutex_unlock(&port
->port_lock
);
2504 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2508 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2510 struct ehea_qp qp
= *orig_qp
;
2511 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2512 struct ehea_swqe
*swqe
;
2516 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2517 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2518 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2522 static void ehea_flush_sq(struct ehea_port
*port
)
2526 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2527 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2528 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2531 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2532 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2533 msecs_to_jiffies(100));
2536 pr_err("WARNING: sq not flushed completely\n");
2542 static int ehea_stop_qps(struct net_device
*dev
)
2544 struct ehea_port
*port
= netdev_priv(dev
);
2545 struct ehea_adapter
*adapter
= port
->adapter
;
2546 struct hcp_modify_qp_cb0
*cb0
;
2554 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2560 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2561 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2562 struct ehea_qp
*qp
= pr
->qp
;
2564 /* Purge send queue */
2567 /* Disable queue pair */
2568 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2569 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2571 if (hret
!= H_SUCCESS
) {
2572 pr_err("query_ehea_qp failed (1)\n");
2576 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2577 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2579 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2580 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2582 &dummy64
, &dummy16
, &dummy16
);
2583 if (hret
!= H_SUCCESS
) {
2584 pr_err("modify_ehea_qp failed (1)\n");
2588 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2589 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2591 if (hret
!= H_SUCCESS
) {
2592 pr_err("query_ehea_qp failed (2)\n");
2596 /* deregister shared memory regions */
2597 dret
= ehea_rem_smrs(pr
);
2599 pr_err("unreg shared memory region failed\n");
2606 free_page((unsigned long)cb0
);
2611 static void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2613 struct ehea_qp qp
= *orig_qp
;
2614 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2615 struct ehea_rwqe
*rwqe
;
2616 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2617 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2618 struct sk_buff
*skb
;
2619 u32 lkey
= pr
->recv_mr
.lkey
;
2625 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2626 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2627 rwqe
->sg_list
[0].l_key
= lkey
;
2628 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2629 skb
= skba_rq2
[index
];
2631 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2634 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2635 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2636 rwqe
->sg_list
[0].l_key
= lkey
;
2637 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2638 skb
= skba_rq3
[index
];
2640 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2644 static int ehea_restart_qps(struct net_device
*dev
)
2646 struct ehea_port
*port
= netdev_priv(dev
);
2647 struct ehea_adapter
*adapter
= port
->adapter
;
2651 struct hcp_modify_qp_cb0
*cb0
;
2656 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2662 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2663 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2664 struct ehea_qp
*qp
= pr
->qp
;
2666 ret
= ehea_gen_smrs(pr
);
2668 netdev_err(dev
, "creation of shared memory regions failed\n");
2672 ehea_update_rqs(qp
, pr
);
2674 /* Enable queue pair */
2675 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2676 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2678 if (hret
!= H_SUCCESS
) {
2679 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2683 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2684 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2686 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2687 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2689 &dummy64
, &dummy16
, &dummy16
);
2690 if (hret
!= H_SUCCESS
) {
2691 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2695 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2696 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2698 if (hret
!= H_SUCCESS
) {
2699 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2703 /* refill entire queue */
2704 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2705 ehea_refill_rq2(pr
, 0);
2706 ehea_refill_rq3(pr
, 0);
2709 free_page((unsigned long)cb0
);
2714 static void ehea_reset_port(struct work_struct
*work
)
2717 struct ehea_port
*port
=
2718 container_of(work
, struct ehea_port
, reset_task
);
2719 struct net_device
*dev
= port
->netdev
;
2721 mutex_lock(&dlpar_mem_lock
);
2723 mutex_lock(&port
->port_lock
);
2724 netif_tx_disable(dev
);
2726 port_napi_disable(port
);
2734 ehea_set_multicast_list(dev
);
2736 netif_info(port
, timer
, dev
, "reset successful\n");
2738 port_napi_enable(port
);
2740 netif_tx_wake_all_queues(dev
);
2742 mutex_unlock(&port
->port_lock
);
2743 mutex_unlock(&dlpar_mem_lock
);
2746 static void ehea_rereg_mrs(void)
2749 struct ehea_adapter
*adapter
;
2751 pr_info("LPAR memory changed - re-initializing driver\n");
2753 list_for_each_entry(adapter
, &adapter_list
, list
)
2754 if (adapter
->active_ports
) {
2755 /* Shutdown all ports */
2756 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2757 struct ehea_port
*port
= adapter
->port
[i
];
2758 struct net_device
*dev
;
2765 if (dev
->flags
& IFF_UP
) {
2766 mutex_lock(&port
->port_lock
);
2767 netif_tx_disable(dev
);
2768 ehea_flush_sq(port
);
2769 ret
= ehea_stop_qps(dev
);
2771 mutex_unlock(&port
->port_lock
);
2774 port_napi_disable(port
);
2775 mutex_unlock(&port
->port_lock
);
2777 reset_sq_restart_flag(port
);
2780 /* Unregister old memory region */
2781 ret
= ehea_rem_mr(&adapter
->mr
);
2783 pr_err("unregister MR failed - driver inoperable!\n");
2788 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2790 list_for_each_entry(adapter
, &adapter_list
, list
)
2791 if (adapter
->active_ports
) {
2792 /* Register new memory region */
2793 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2795 pr_err("register MR failed - driver inoperable!\n");
2799 /* Restart all ports */
2800 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2801 struct ehea_port
*port
= adapter
->port
[i
];
2804 struct net_device
*dev
= port
->netdev
;
2806 if (dev
->flags
& IFF_UP
) {
2807 mutex_lock(&port
->port_lock
);
2808 ret
= ehea_restart_qps(dev
);
2811 port_napi_enable(port
);
2812 netif_tx_wake_all_queues(dev
);
2814 netdev_err(dev
, "Unable to restart QPS\n");
2816 mutex_unlock(&port
->port_lock
);
2821 pr_info("re-initializing driver complete\n");
2826 static void ehea_tx_watchdog(struct net_device
*dev
)
2828 struct ehea_port
*port
= netdev_priv(dev
);
2830 if (netif_carrier_ok(dev
) &&
2831 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2832 ehea_schedule_port_reset(port
);
2835 static int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2837 struct hcp_query_ehea
*cb
;
2841 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2847 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2849 if (hret
!= H_SUCCESS
) {
2854 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2858 free_page((unsigned long)cb
);
2863 static int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2865 struct hcp_ehea_port_cb4
*cb4
;
2871 /* (Try to) enable *jumbo frames */
2872 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2874 pr_err("no mem for cb4\n");
2878 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2879 port
->logical_port_id
,
2881 H_PORT_CB4_JUMBO
, cb4
);
2882 if (hret
== H_SUCCESS
) {
2883 if (cb4
->jumbo_frame
)
2886 cb4
->jumbo_frame
= 1;
2887 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2894 if (hret
== H_SUCCESS
)
2900 free_page((unsigned long)cb4
);
2906 static ssize_t
ehea_show_port_id(struct device
*dev
,
2907 struct device_attribute
*attr
, char *buf
)
2909 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2910 return sprintf(buf
, "%d", port
->logical_port_id
);
2913 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2916 static void logical_port_release(struct device
*dev
)
2918 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2919 of_node_put(port
->ofdev
.dev
.of_node
);
2922 static struct device
*ehea_register_port(struct ehea_port
*port
,
2923 struct device_node
*dn
)
2927 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
2928 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2929 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2931 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
2932 port
->ofdev
.dev
.release
= logical_port_release
;
2934 ret
= of_device_register(&port
->ofdev
);
2936 pr_err("failed to register device. ret=%d\n", ret
);
2940 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2942 pr_err("failed to register attributes, ret=%d\n", ret
);
2943 goto out_unreg_of_dev
;
2946 return &port
->ofdev
.dev
;
2949 of_device_unregister(&port
->ofdev
);
2954 static void ehea_unregister_port(struct ehea_port
*port
)
2956 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2957 of_device_unregister(&port
->ofdev
);
2960 static const struct net_device_ops ehea_netdev_ops
= {
2961 .ndo_open
= ehea_open
,
2962 .ndo_stop
= ehea_stop
,
2963 .ndo_start_xmit
= ehea_start_xmit
,
2964 #ifdef CONFIG_NET_POLL_CONTROLLER
2965 .ndo_poll_controller
= ehea_netpoll
,
2967 .ndo_get_stats64
= ehea_get_stats64
,
2968 .ndo_set_mac_address
= ehea_set_mac_addr
,
2969 .ndo_validate_addr
= eth_validate_addr
,
2970 .ndo_set_rx_mode
= ehea_set_multicast_list
,
2971 .ndo_change_mtu
= ehea_change_mtu
,
2972 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
2973 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
2974 .ndo_tx_timeout
= ehea_tx_watchdog
,
2977 static struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2978 u32 logical_port_id
,
2979 struct device_node
*dn
)
2982 struct net_device
*dev
;
2983 struct ehea_port
*port
;
2984 struct device
*port_dev
;
2987 /* allocate memory for the port structures */
2988 dev
= alloc_etherdev_mq(sizeof(struct ehea_port
), EHEA_MAX_PORT_RES
);
2995 port
= netdev_priv(dev
);
2997 mutex_init(&port
->port_lock
);
2998 port
->state
= EHEA_PORT_DOWN
;
2999 port
->sig_comp_iv
= sq_entries
/ 10;
3001 port
->adapter
= adapter
;
3003 port
->logical_port_id
= logical_port_id
;
3005 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3007 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3008 if (!port
->mc_list
) {
3010 goto out_free_ethdev
;
3013 INIT_LIST_HEAD(&port
->mc_list
->list
);
3015 ret
= ehea_sense_port_attr(port
);
3017 goto out_free_mc_list
;
3019 netif_set_real_num_rx_queues(dev
, port
->num_def_qps
);
3020 netif_set_real_num_tx_queues(dev
, port
->num_def_qps
);
3022 port_dev
= ehea_register_port(port
, dn
);
3024 goto out_free_mc_list
;
3026 SET_NETDEV_DEV(dev
, port_dev
);
3028 /* initialize net_device structure */
3029 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3031 dev
->netdev_ops
= &ehea_netdev_ops
;
3032 ehea_set_ethtool_ops(dev
);
3034 dev
->hw_features
= NETIF_F_SG
| NETIF_F_TSO
|
3035 NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_CTAG_TX
;
3036 dev
->features
= NETIF_F_SG
| NETIF_F_TSO
|
3037 NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
|
3038 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
|
3039 NETIF_F_HW_VLAN_CTAG_FILTER
| NETIF_F_RXCSUM
;
3040 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HIGHDMA
|
3042 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3044 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3045 INIT_DELAYED_WORK(&port
->stats_work
, ehea_update_stats
);
3047 init_waitqueue_head(&port
->swqe_avail_wq
);
3048 init_waitqueue_head(&port
->restart_wq
);
3050 memset(&port
->stats
, 0, sizeof(struct net_device_stats
));
3051 ret
= register_netdev(dev
);
3053 pr_err("register_netdev failed. ret=%d\n", ret
);
3054 goto out_unreg_port
;
3057 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3059 netdev_err(dev
, "failed determining jumbo frame status\n");
3061 netdev_info(dev
, "Jumbo frames are %sabled\n",
3062 jumbo
== 1 ? "en" : "dis");
3064 adapter
->active_ports
++;
3069 ehea_unregister_port(port
);
3072 kfree(port
->mc_list
);
3078 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3079 logical_port_id
, ret
);
3083 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3085 struct ehea_adapter
*adapter
= port
->adapter
;
3087 cancel_work_sync(&port
->reset_task
);
3088 cancel_delayed_work_sync(&port
->stats_work
);
3089 unregister_netdev(port
->netdev
);
3090 ehea_unregister_port(port
);
3091 kfree(port
->mc_list
);
3092 free_netdev(port
->netdev
);
3093 adapter
->active_ports
--;
3096 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3098 struct device_node
*lhea_dn
;
3099 struct device_node
*eth_dn
= NULL
;
3101 const u32
*dn_log_port_id
;
3104 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3105 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3107 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3109 if (!dn_log_port_id
) {
3110 pr_err("bad device node: eth_dn name=%s\n",
3115 if (ehea_add_adapter_mr(adapter
)) {
3116 pr_err("creating MR failed\n");
3117 of_node_put(eth_dn
);
3121 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3124 if (adapter
->port
[i
])
3125 netdev_info(adapter
->port
[i
]->netdev
,
3126 "logical port id #%d\n", *dn_log_port_id
);
3128 ehea_remove_adapter_mr(adapter
);
3135 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3136 u32 logical_port_id
)
3138 struct device_node
*lhea_dn
;
3139 struct device_node
*eth_dn
= NULL
;
3140 const u32
*dn_log_port_id
;
3142 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3143 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3145 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3148 if (*dn_log_port_id
== logical_port_id
)
3155 static ssize_t
ehea_probe_port(struct device
*dev
,
3156 struct device_attribute
*attr
,
3157 const char *buf
, size_t count
)
3159 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3160 struct ehea_port
*port
;
3161 struct device_node
*eth_dn
= NULL
;
3164 u32 logical_port_id
;
3166 sscanf(buf
, "%d", &logical_port_id
);
3168 port
= ehea_get_port(adapter
, logical_port_id
);
3171 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3176 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3179 pr_info("no logical port with id %d found\n", logical_port_id
);
3183 if (ehea_add_adapter_mr(adapter
)) {
3184 pr_err("creating MR failed\n");
3188 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3190 of_node_put(eth_dn
);
3193 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3194 if (!adapter
->port
[i
]) {
3195 adapter
->port
[i
] = port
;
3199 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3202 ehea_remove_adapter_mr(adapter
);
3206 return (ssize_t
) count
;
3209 static ssize_t
ehea_remove_port(struct device
*dev
,
3210 struct device_attribute
*attr
,
3211 const char *buf
, size_t count
)
3213 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3214 struct ehea_port
*port
;
3216 u32 logical_port_id
;
3218 sscanf(buf
, "%d", &logical_port_id
);
3220 port
= ehea_get_port(adapter
, logical_port_id
);
3223 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3226 ehea_shutdown_single_port(port
);
3228 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3229 if (adapter
->port
[i
] == port
) {
3230 adapter
->port
[i
] = NULL
;
3234 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3239 ehea_remove_adapter_mr(adapter
);
3241 return (ssize_t
) count
;
3244 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3245 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3247 static int ehea_create_device_sysfs(struct platform_device
*dev
)
3249 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3253 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3258 static void ehea_remove_device_sysfs(struct platform_device
*dev
)
3260 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3261 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3264 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3265 unsigned long action
, void *unused
)
3267 if (action
== SYS_RESTART
) {
3268 pr_info("Reboot: freeing all eHEA resources\n");
3269 ibmebus_unregister_driver(&ehea_driver
);
3274 static struct notifier_block ehea_reboot_nb
= {
3275 .notifier_call
= ehea_reboot_notifier
,
3278 static int ehea_mem_notifier(struct notifier_block
*nb
,
3279 unsigned long action
, void *data
)
3281 int ret
= NOTIFY_BAD
;
3282 struct memory_notify
*arg
= data
;
3284 mutex_lock(&dlpar_mem_lock
);
3287 case MEM_CANCEL_OFFLINE
:
3288 pr_info("memory offlining canceled");
3289 /* Fall through: re-add canceled memory block */
3292 pr_info("memory is going online");
3293 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3294 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3299 case MEM_GOING_OFFLINE
:
3300 pr_info("memory is going offline");
3301 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3302 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3311 ehea_update_firmware_handles();
3315 mutex_unlock(&dlpar_mem_lock
);
3319 static struct notifier_block ehea_mem_nb
= {
3320 .notifier_call
= ehea_mem_notifier
,
3323 static void ehea_crash_handler(void)
3327 if (ehea_fw_handles
.arr
)
3328 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3329 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3330 ehea_fw_handles
.arr
[i
].fwh
,
3333 if (ehea_bcmc_regs
.arr
)
3334 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3335 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3336 ehea_bcmc_regs
.arr
[i
].port_id
,
3337 ehea_bcmc_regs
.arr
[i
].reg_type
,
3338 ehea_bcmc_regs
.arr
[i
].macaddr
,
3342 static atomic_t ehea_memory_hooks_registered
;
3344 /* Register memory hooks on probe of first adapter */
3345 static int ehea_register_memory_hooks(void)
3349 if (atomic_inc_return(&ehea_memory_hooks_registered
) > 1)
3352 ret
= ehea_create_busmap();
3354 pr_info("ehea_create_busmap failed\n");
3358 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3360 pr_info("register_reboot_notifier failed\n");
3364 ret
= register_memory_notifier(&ehea_mem_nb
);
3366 pr_info("register_memory_notifier failed\n");
3370 ret
= crash_shutdown_register(ehea_crash_handler
);
3372 pr_info("crash_shutdown_register failed\n");
3379 unregister_memory_notifier(&ehea_mem_nb
);
3381 unregister_reboot_notifier(&ehea_reboot_nb
);
3383 atomic_dec(&ehea_memory_hooks_registered
);
3387 static void ehea_unregister_memory_hooks(void)
3389 /* Only remove the hooks if we've registered them */
3390 if (atomic_read(&ehea_memory_hooks_registered
) == 0)
3393 unregister_reboot_notifier(&ehea_reboot_nb
);
3394 if (crash_shutdown_unregister(ehea_crash_handler
))
3395 pr_info("failed unregistering crash handler\n");
3396 unregister_memory_notifier(&ehea_mem_nb
);
3399 static int ehea_probe_adapter(struct platform_device
*dev
)
3401 struct ehea_adapter
*adapter
;
3402 const u64
*adapter_handle
;
3406 ret
= ehea_register_memory_hooks();
3410 if (!dev
|| !dev
->dev
.of_node
) {
3411 pr_err("Invalid ibmebus device probed\n");
3415 adapter
= devm_kzalloc(&dev
->dev
, sizeof(*adapter
), GFP_KERNEL
);
3418 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3422 list_add(&adapter
->list
, &adapter_list
);
3424 adapter
->ofdev
= dev
;
3426 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3429 adapter
->handle
= *adapter_handle
;
3431 if (!adapter
->handle
) {
3432 dev_err(&dev
->dev
, "failed getting handle for adapter"
3433 " '%s'\n", dev
->dev
.of_node
->full_name
);
3438 adapter
->pd
= EHEA_PD_ID
;
3440 platform_set_drvdata(dev
, adapter
);
3443 /* initialize adapter and ports */
3444 /* get adapter properties */
3445 ret
= ehea_sense_adapter_attr(adapter
);
3447 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3451 adapter
->neq
= ehea_create_eq(adapter
,
3452 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3453 if (!adapter
->neq
) {
3455 dev_err(&dev
->dev
, "NEQ creation failed\n");
3459 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3460 (unsigned long)adapter
);
3462 ret
= ehea_create_device_sysfs(dev
);
3466 ret
= ehea_setup_ports(adapter
);
3468 dev_err(&dev
->dev
, "setup_ports failed\n");
3469 goto out_rem_dev_sysfs
;
3472 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3473 ehea_interrupt_neq
, 0,
3474 "ehea_neq", adapter
);
3476 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3477 goto out_shutdown_ports
;
3480 /* Handle any events that might be pending. */
3481 tasklet_hi_schedule(&adapter
->neq_tasklet
);
3487 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3488 if (adapter
->port
[i
]) {
3489 ehea_shutdown_single_port(adapter
->port
[i
]);
3490 adapter
->port
[i
] = NULL
;
3494 ehea_remove_device_sysfs(dev
);
3497 ehea_destroy_eq(adapter
->neq
);
3500 list_del(&adapter
->list
);
3503 ehea_update_firmware_handles();
3508 static int ehea_remove(struct platform_device
*dev
)
3510 struct ehea_adapter
*adapter
= platform_get_drvdata(dev
);
3513 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3514 if (adapter
->port
[i
]) {
3515 ehea_shutdown_single_port(adapter
->port
[i
]);
3516 adapter
->port
[i
] = NULL
;
3519 ehea_remove_device_sysfs(dev
);
3521 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3522 tasklet_kill(&adapter
->neq_tasklet
);
3524 ehea_destroy_eq(adapter
->neq
);
3525 ehea_remove_adapter_mr(adapter
);
3526 list_del(&adapter
->list
);
3528 ehea_update_firmware_handles();
3533 static int check_module_parm(void)
3537 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3538 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3539 pr_info("Bad parameter: rq1_entries\n");
3542 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3543 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3544 pr_info("Bad parameter: rq2_entries\n");
3547 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3548 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3549 pr_info("Bad parameter: rq3_entries\n");
3552 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3553 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3554 pr_info("Bad parameter: sq_entries\n");
3561 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3564 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3567 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3568 ehea_show_capabilities
, NULL
);
3570 static int __init
ehea_module_init(void)
3574 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3576 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3577 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3579 mutex_init(&ehea_fw_handles
.lock
);
3580 spin_lock_init(&ehea_bcmc_regs
.lock
);
3582 ret
= check_module_parm();
3586 ret
= ibmebus_register_driver(&ehea_driver
);
3588 pr_err("failed registering eHEA device driver on ebus\n");
3592 ret
= driver_create_file(&ehea_driver
.driver
,
3593 &driver_attr_capabilities
);
3595 pr_err("failed to register capabilities attribute, ret=%d\n",
3603 ibmebus_unregister_driver(&ehea_driver
);
3608 static void __exit
ehea_module_exit(void)
3610 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3611 ibmebus_unregister_driver(&ehea_driver
);
3612 ehea_unregister_memory_hooks();
3613 kfree(ehea_fw_handles
.arr
);
3614 kfree(ehea_bcmc_regs
.arr
);
3615 ehea_destroy_busmap();
3618 module_init(ehea_module_init
);
3619 module_exit(ehea_module_exit
);