2 * linux/drivers/net/ehea/ehea_main.c
4 * eHEA ethernet device driver for IBM eServer System p
6 * (C) Copyright IBM Corp. 2006
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/tcp.h>
34 #include <linux/udp.h>
36 #include <linux/list.h>
37 #include <linux/slab.h>
38 #include <linux/if_ether.h>
39 #include <linux/notifier.h>
40 #include <linux/reboot.h>
41 #include <linux/memory.h>
42 #include <asm/kexec.h>
43 #include <linux/mutex.h>
44 #include <linux/prefetch.h>
50 #include "ehea_phyp.h"
53 MODULE_LICENSE("GPL");
54 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55 MODULE_DESCRIPTION("IBM eServer HEA Driver");
56 MODULE_VERSION(DRV_VERSION
);
59 static int msg_level
= -1;
60 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
61 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
62 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
63 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
64 static int use_mcs
= 1;
65 static int prop_carrier_state
;
67 module_param(msg_level
, int, 0);
68 module_param(rq1_entries
, int, 0);
69 module_param(rq2_entries
, int, 0);
70 module_param(rq3_entries
, int, 0);
71 module_param(sq_entries
, int, 0);
72 module_param(prop_carrier_state
, int, 0);
73 module_param(use_mcs
, int, 0);
75 MODULE_PARM_DESC(msg_level
, "msg_level");
76 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
78 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
81 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
84 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
87 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
90 MODULE_PARM_DESC(use_mcs
, " Multiple receive queues, 1: enable, 0: disable, "
93 static int port_name_cnt
;
94 static LIST_HEAD(adapter_list
);
95 static unsigned long ehea_driver_flags
;
96 static DEFINE_MUTEX(dlpar_mem_lock
);
97 static struct ehea_fw_handle_array ehea_fw_handles
;
98 static struct ehea_bcmc_reg_array ehea_bcmc_regs
;
101 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
102 const struct of_device_id
*id
);
104 static int __devexit
ehea_remove(struct platform_device
*dev
);
106 static struct of_device_id ehea_device_table
[] = {
109 .compatible
= "IBM,lhea",
113 MODULE_DEVICE_TABLE(of
, ehea_device_table
);
115 static struct of_platform_driver ehea_driver
= {
118 .owner
= THIS_MODULE
,
119 .of_match_table
= ehea_device_table
,
121 .probe
= ehea_probe_adapter
,
122 .remove
= ehea_remove
,
125 void ehea_dump(void *adr
, int len
, char *msg
)
128 unsigned char *deb
= adr
;
129 for (x
= 0; x
< len
; x
+= 16) {
130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg
, deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
136 static void ehea_schedule_port_reset(struct ehea_port
*port
)
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
))
139 schedule_work(&port
->reset_task
);
142 static void ehea_update_firmware_handles(void)
144 struct ehea_fw_handle_entry
*arr
= NULL
;
145 struct ehea_adapter
*adapter
;
146 int num_adapters
= 0;
150 int num_fw_handles
, k
, l
;
152 /* Determine number of handles */
153 mutex_lock(&ehea_fw_handles
.lock
);
155 list_for_each_entry(adapter
, &adapter_list
, list
) {
158 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
159 struct ehea_port
*port
= adapter
->port
[k
];
161 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
165 num_portres
+= port
->num_def_qps
;
169 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
170 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
171 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
173 if (num_fw_handles
) {
174 arr
= kcalloc(num_fw_handles
, sizeof(*arr
), GFP_KERNEL
);
176 goto out
; /* Keep the existing array */
180 list_for_each_entry(adapter
, &adapter_list
, list
) {
181 if (num_adapters
== 0)
184 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
185 struct ehea_port
*port
= adapter
->port
[k
];
187 if (!port
|| (port
->state
!= EHEA_PORT_UP
) ||
191 for (l
= 0; l
< port
->num_def_qps
; l
++) {
192 struct ehea_port_res
*pr
= &port
->port_res
[l
];
194 arr
[i
].adh
= adapter
->handle
;
195 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
196 arr
[i
].adh
= adapter
->handle
;
197 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
198 arr
[i
].adh
= adapter
->handle
;
199 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
200 arr
[i
].adh
= adapter
->handle
;
201 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
202 arr
[i
].adh
= adapter
->handle
;
203 arr
[i
++].fwh
= pr
->send_mr
.handle
;
204 arr
[i
].adh
= adapter
->handle
;
205 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
207 arr
[i
].adh
= adapter
->handle
;
208 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
212 arr
[i
].adh
= adapter
->handle
;
213 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
215 if (adapter
->mr
.handle
) {
216 arr
[i
].adh
= adapter
->handle
;
217 arr
[i
++].fwh
= adapter
->mr
.handle
;
223 kfree(ehea_fw_handles
.arr
);
224 ehea_fw_handles
.arr
= arr
;
225 ehea_fw_handles
.num_entries
= i
;
227 mutex_unlock(&ehea_fw_handles
.lock
);
230 static void ehea_update_bcmc_registrations(void)
233 struct ehea_bcmc_reg_entry
*arr
= NULL
;
234 struct ehea_adapter
*adapter
;
235 struct ehea_mc_list
*mc_entry
;
236 int num_registrations
= 0;
240 spin_lock_irqsave(&ehea_bcmc_regs
.lock
, flags
);
242 /* Determine number of registrations */
243 list_for_each_entry(adapter
, &adapter_list
, list
)
244 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
245 struct ehea_port
*port
= adapter
->port
[k
];
247 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
250 num_registrations
+= 2; /* Broadcast registrations */
252 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
253 num_registrations
+= 2;
256 if (num_registrations
) {
257 arr
= kcalloc(num_registrations
, sizeof(*arr
), GFP_ATOMIC
);
259 goto out
; /* Keep the existing array */
263 list_for_each_entry(adapter
, &adapter_list
, list
) {
264 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
265 struct ehea_port
*port
= adapter
->port
[k
];
267 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
270 if (num_registrations
== 0)
273 arr
[i
].adh
= adapter
->handle
;
274 arr
[i
].port_id
= port
->logical_port_id
;
275 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
277 arr
[i
++].macaddr
= port
->mac_addr
;
279 arr
[i
].adh
= adapter
->handle
;
280 arr
[i
].port_id
= port
->logical_port_id
;
281 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
282 EHEA_BCMC_VLANID_ALL
;
283 arr
[i
++].macaddr
= port
->mac_addr
;
284 num_registrations
-= 2;
286 list_for_each_entry(mc_entry
,
287 &port
->mc_list
->list
, list
) {
288 if (num_registrations
== 0)
291 arr
[i
].adh
= adapter
->handle
;
292 arr
[i
].port_id
= port
->logical_port_id
;
293 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
294 EHEA_BCMC_MULTICAST
|
296 arr
[i
++].macaddr
= mc_entry
->macaddr
;
298 arr
[i
].adh
= adapter
->handle
;
299 arr
[i
].port_id
= port
->logical_port_id
;
300 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
301 EHEA_BCMC_MULTICAST
|
302 EHEA_BCMC_VLANID_ALL
;
303 arr
[i
++].macaddr
= mc_entry
->macaddr
;
304 num_registrations
-= 2;
310 kfree(ehea_bcmc_regs
.arr
);
311 ehea_bcmc_regs
.arr
= arr
;
312 ehea_bcmc_regs
.num_entries
= i
;
314 spin_unlock_irqrestore(&ehea_bcmc_regs
.lock
, flags
);
317 static struct rtnl_link_stats64
*ehea_get_stats64(struct net_device
*dev
,
318 struct rtnl_link_stats64
*stats
)
320 struct ehea_port
*port
= netdev_priv(dev
);
321 u64 rx_packets
= 0, tx_packets
= 0, rx_bytes
= 0, tx_bytes
= 0;
324 for (i
= 0; i
< port
->num_def_qps
; i
++) {
325 rx_packets
+= port
->port_res
[i
].rx_packets
;
326 rx_bytes
+= port
->port_res
[i
].rx_bytes
;
329 for (i
= 0; i
< port
->num_def_qps
; i
++) {
330 tx_packets
+= port
->port_res
[i
].tx_packets
;
331 tx_bytes
+= port
->port_res
[i
].tx_bytes
;
334 stats
->tx_packets
= tx_packets
;
335 stats
->rx_bytes
= rx_bytes
;
336 stats
->tx_bytes
= tx_bytes
;
337 stats
->rx_packets
= rx_packets
;
339 stats
->multicast
= port
->stats
.multicast
;
340 stats
->rx_errors
= port
->stats
.rx_errors
;
344 static void ehea_update_stats(struct work_struct
*work
)
346 struct ehea_port
*port
=
347 container_of(work
, struct ehea_port
, stats_work
.work
);
348 struct net_device
*dev
= port
->netdev
;
349 struct rtnl_link_stats64
*stats
= &port
->stats
;
350 struct hcp_ehea_port_cb2
*cb2
;
353 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
355 netdev_err(dev
, "No mem for cb2. Some interface statistics were not updated\n");
359 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
360 port
->logical_port_id
,
361 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
362 if (hret
!= H_SUCCESS
) {
363 netdev_err(dev
, "query_ehea_port failed\n");
367 if (netif_msg_hw(port
))
368 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
370 stats
->multicast
= cb2
->rxmcp
;
371 stats
->rx_errors
= cb2
->rxuerr
;
374 free_page((unsigned long)cb2
);
376 schedule_delayed_work(&port
->stats_work
,
377 round_jiffies_relative(msecs_to_jiffies(1000)));
380 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
382 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
383 struct net_device
*dev
= pr
->port
->netdev
;
384 int max_index_mask
= pr
->rq1_skba
.len
- 1;
385 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
389 pr
->rq1_skba
.os_skbs
= 0;
391 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
393 pr
->rq1_skba
.index
= index
;
394 pr
->rq1_skba
.os_skbs
= fill_wqes
;
398 for (i
= 0; i
< fill_wqes
; i
++) {
399 if (!skb_arr_rq1
[index
]) {
400 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
402 if (!skb_arr_rq1
[index
]) {
403 netdev_info(dev
, "Unable to allocate enough skb in the array\n");
404 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
409 index
&= max_index_mask
;
417 ehea_update_rq1a(pr
->qp
, adder
);
420 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
422 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
423 struct net_device
*dev
= pr
->port
->netdev
;
426 if (nr_rq1a
> pr
->rq1_skba
.len
) {
427 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
431 for (i
= 0; i
< nr_rq1a
; i
++) {
432 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
433 if (!skb_arr_rq1
[i
]) {
434 netdev_info(dev
, "Not enough memory to allocate skb array\n");
439 ehea_update_rq1a(pr
->qp
, i
- 1);
442 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
443 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
444 int num_wqes
, int wqe_type
, int packet_size
)
446 struct net_device
*dev
= pr
->port
->netdev
;
447 struct ehea_qp
*qp
= pr
->qp
;
448 struct sk_buff
**skb_arr
= q_skba
->arr
;
449 struct ehea_rwqe
*rwqe
;
450 int i
, index
, max_index_mask
, fill_wqes
;
454 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
457 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
458 q_skba
->os_skbs
= fill_wqes
;
462 index
= q_skba
->index
;
463 max_index_mask
= q_skba
->len
- 1;
464 for (i
= 0; i
< fill_wqes
; i
++) {
468 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
470 q_skba
->os_skbs
= fill_wqes
- i
;
471 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
472 netdev_info(pr
->port
->netdev
,
473 "rq%i ran dry - no mem for skb\n",
480 skb_arr
[index
] = skb
;
481 tmp_addr
= ehea_map_vaddr(skb
->data
);
482 if (tmp_addr
== -1) {
484 q_skba
->os_skbs
= fill_wqes
- i
;
489 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
490 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
491 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
492 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
493 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
494 rwqe
->sg_list
[0].len
= packet_size
;
495 rwqe
->data_segments
= 1;
498 index
&= max_index_mask
;
502 q_skba
->index
= index
;
509 ehea_update_rq2a(pr
->qp
, adder
);
511 ehea_update_rq3a(pr
->qp
, adder
);
517 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
519 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
520 nr_of_wqes
, EHEA_RWQE2_TYPE
,
525 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
527 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
528 nr_of_wqes
, EHEA_RWQE3_TYPE
,
529 EHEA_MAX_PACKET_SIZE
);
532 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
534 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
535 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
537 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
538 (cqe
->header_length
== 0))
543 static inline void ehea_fill_skb(struct net_device
*dev
,
544 struct sk_buff
*skb
, struct ehea_cqe
*cqe
,
545 struct ehea_port_res
*pr
)
547 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
549 skb_put(skb
, length
);
550 skb
->protocol
= eth_type_trans(skb
, dev
);
552 /* The packet was not an IPV4 packet so a complemented checksum was
553 calculated. The value is found in the Internet Checksum field. */
554 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
555 skb
->ip_summed
= CHECKSUM_COMPLETE
;
556 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
558 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
560 skb_record_rx_queue(skb
, pr
- &pr
->port
->port_res
[0]);
563 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
565 struct ehea_cqe
*cqe
)
567 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
578 prefetchw(pref
+ EHEA_CACHE_LINE
);
580 pref
= (skb_array
[x
]->data
);
582 prefetch(pref
+ EHEA_CACHE_LINE
);
583 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
584 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
587 skb
= skb_array
[skb_index
];
588 skb_array
[skb_index
] = NULL
;
592 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
593 int arr_len
, int wqe_index
)
605 prefetchw(pref
+ EHEA_CACHE_LINE
);
607 pref
= (skb_array
[x
]->data
);
609 prefetchw(pref
+ EHEA_CACHE_LINE
);
612 skb
= skb_array
[wqe_index
];
613 skb_array
[wqe_index
] = NULL
;
617 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
618 struct ehea_cqe
*cqe
, int *processed_rq2
,
623 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
624 pr
->p_stats
.err_tcp_cksum
++;
625 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
626 pr
->p_stats
.err_ip_cksum
++;
627 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
628 pr
->p_stats
.err_frame_crc
++;
632 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
634 } else if (rq
== 3) {
636 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
640 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
641 if (netif_msg_rx_err(pr
->port
)) {
642 pr_err("Critical receive error for QP %d. Resetting port.\n",
643 pr
->qp
->init_attr
.qp_nr
);
644 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
646 ehea_schedule_port_reset(pr
->port
);
653 static int ehea_proc_rwqes(struct net_device
*dev
,
654 struct ehea_port_res
*pr
,
657 struct ehea_port
*port
= pr
->port
;
658 struct ehea_qp
*qp
= pr
->qp
;
659 struct ehea_cqe
*cqe
;
661 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
662 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
663 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
664 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
665 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
666 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
667 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
668 u64 processed_bytes
= 0;
669 int wqe_index
, last_wqe_index
, rq
, port_reset
;
671 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
674 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
675 while ((processed
< budget
) && cqe
) {
679 if (netif_msg_rx_status(port
))
680 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
682 last_wqe_index
= wqe_index
;
684 if (!ehea_check_cqe(cqe
, &rq
)) {
687 skb
= get_skb_by_index_ll(skb_arr_rq1
,
690 if (unlikely(!skb
)) {
691 netif_info(port
, rx_err
, dev
,
692 "LL rq1: skb=NULL\n");
694 skb
= netdev_alloc_skb(dev
,
697 netdev_err(dev
, "Not enough memory to allocate skb\n");
701 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
702 cqe
->num_bytes_transfered
- 4);
703 ehea_fill_skb(dev
, skb
, cqe
, pr
);
704 } else if (rq
== 2) {
706 skb
= get_skb_by_index(skb_arr_rq2
,
707 skb_arr_rq2_len
, cqe
);
708 if (unlikely(!skb
)) {
709 netif_err(port
, rx_err
, dev
,
713 ehea_fill_skb(dev
, skb
, cqe
, pr
);
717 skb
= get_skb_by_index(skb_arr_rq3
,
718 skb_arr_rq3_len
, cqe
);
719 if (unlikely(!skb
)) {
720 netif_err(port
, rx_err
, dev
,
724 ehea_fill_skb(dev
, skb
, cqe
, pr
);
728 processed_bytes
+= skb
->len
;
730 if (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
731 __vlan_hwaccel_put_tag(skb
, cqe
->vlan_tag
);
733 napi_gro_receive(&pr
->napi
, skb
);
735 pr
->p_stats
.poll_receive_errors
++;
736 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
742 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
745 pr
->rx_packets
+= processed
;
746 pr
->rx_bytes
+= processed_bytes
;
748 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
749 ehea_refill_rq2(pr
, processed_rq2
);
750 ehea_refill_rq3(pr
, processed_rq3
);
755 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
757 static void reset_sq_restart_flag(struct ehea_port
*port
)
761 for (i
= 0; i
< port
->num_def_qps
; i
++) {
762 struct ehea_port_res
*pr
= &port
->port_res
[i
];
763 pr
->sq_restart_flag
= 0;
765 wake_up(&port
->restart_wq
);
768 static void check_sqs(struct ehea_port
*port
)
770 struct ehea_swqe
*swqe
;
774 for (i
= 0; i
< port
->num_def_qps
; i
++) {
775 struct ehea_port_res
*pr
= &port
->port_res
[i
];
778 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
779 memset(swqe
, 0, SWQE_HEADER_SIZE
);
780 atomic_dec(&pr
->swqe_avail
);
782 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
783 swqe
->wr_id
= SWQE_RESTART_CHECK
;
784 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
785 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
786 swqe
->immediate_data_length
= 80;
788 ehea_post_swqe(pr
->qp
, swqe
);
790 ret
= wait_event_timeout(port
->restart_wq
,
791 pr
->sq_restart_flag
== 0,
792 msecs_to_jiffies(100));
795 pr_err("HW/SW queues out of sync\n");
796 ehea_schedule_port_reset(pr
->port
);
803 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
806 struct ehea_cq
*send_cq
= pr
->send_cq
;
807 struct ehea_cqe
*cqe
;
808 int quota
= my_quota
;
812 struct netdev_queue
*txq
= netdev_get_tx_queue(pr
->port
->netdev
,
813 pr
- &pr
->port
->port_res
[0]);
815 cqe
= ehea_poll_cq(send_cq
);
816 while (cqe
&& (quota
> 0)) {
817 ehea_inc_cq(send_cq
);
822 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
823 pr
->sq_restart_flag
= 1;
828 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
829 pr_err("Bad send completion status=0x%04X\n",
832 if (netif_msg_tx_err(pr
->port
))
833 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
835 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
836 pr_err("Resetting port\n");
837 ehea_schedule_port_reset(pr
->port
);
842 if (netif_msg_tx_done(pr
->port
))
843 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
845 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
846 == EHEA_SWQE2_TYPE
)) {
848 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
849 skb
= pr
->sq_skba
.arr
[index
];
851 pr
->sq_skba
.arr
[index
] = NULL
;
854 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
857 cqe
= ehea_poll_cq(send_cq
);
860 ehea_update_feca(send_cq
, cqe_counter
);
861 atomic_add(swqe_av
, &pr
->swqe_avail
);
863 if (unlikely(netif_tx_queue_stopped(txq
) &&
864 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))) {
865 __netif_tx_lock(txq
, smp_processor_id());
866 if (netif_tx_queue_stopped(txq
) &&
867 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))
868 netif_tx_wake_queue(txq
);
869 __netif_tx_unlock(txq
);
872 wake_up(&pr
->port
->swqe_avail_wq
);
877 #define EHEA_POLL_MAX_CQES 65535
879 static int ehea_poll(struct napi_struct
*napi
, int budget
)
881 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
883 struct net_device
*dev
= pr
->port
->netdev
;
884 struct ehea_cqe
*cqe
;
885 struct ehea_cqe
*cqe_skb
= NULL
;
889 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
890 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
892 while (rx
!= budget
) {
894 ehea_reset_cq_ep(pr
->recv_cq
);
895 ehea_reset_cq_ep(pr
->send_cq
);
896 ehea_reset_cq_n1(pr
->recv_cq
);
897 ehea_reset_cq_n1(pr
->send_cq
);
899 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
900 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
902 if (!cqe
&& !cqe_skb
)
905 if (!napi_reschedule(napi
))
908 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
909 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
915 #ifdef CONFIG_NET_POLL_CONTROLLER
916 static void ehea_netpoll(struct net_device
*dev
)
918 struct ehea_port
*port
= netdev_priv(dev
);
921 for (i
= 0; i
< port
->num_def_qps
; i
++)
922 napi_schedule(&port
->port_res
[i
].napi
);
926 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
928 struct ehea_port_res
*pr
= param
;
930 napi_schedule(&pr
->napi
);
935 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
937 struct ehea_port
*port
= param
;
938 struct ehea_eqe
*eqe
;
941 u64 resource_type
, aer
, aerr
;
944 eqe
= ehea_poll_eq(port
->qp_eq
);
947 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
948 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
949 eqe
->entry
, qp_token
);
951 qp
= port
->port_res
[qp_token
].qp
;
953 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
956 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
957 if ((aer
& EHEA_AER_RESET_MASK
) ||
958 (aerr
& EHEA_AERR_RESET_MASK
))
961 reset_port
= 1; /* Reset in case of CQ or EQ error */
963 eqe
= ehea_poll_eq(port
->qp_eq
);
967 pr_err("Resetting port\n");
968 ehea_schedule_port_reset(port
);
974 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
979 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
980 if (adapter
->port
[i
])
981 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
982 return adapter
->port
[i
];
986 int ehea_sense_port_attr(struct ehea_port
*port
)
990 struct hcp_ehea_port_cb0
*cb0
;
992 /* may be called via ehea_neq_tasklet() */
993 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
995 pr_err("no mem for cb0\n");
1000 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1001 port
->logical_port_id
, H_PORT_CB0
,
1002 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1004 if (hret
!= H_SUCCESS
) {
1010 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1012 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1013 ret
= -EADDRNOTAVAIL
;
1018 switch (cb0
->port_speed
) {
1020 port
->port_speed
= EHEA_SPEED_10M
;
1021 port
->full_duplex
= 0;
1024 port
->port_speed
= EHEA_SPEED_10M
;
1025 port
->full_duplex
= 1;
1027 case H_SPEED_100M_H
:
1028 port
->port_speed
= EHEA_SPEED_100M
;
1029 port
->full_duplex
= 0;
1031 case H_SPEED_100M_F
:
1032 port
->port_speed
= EHEA_SPEED_100M
;
1033 port
->full_duplex
= 1;
1036 port
->port_speed
= EHEA_SPEED_1G
;
1037 port
->full_duplex
= 1;
1040 port
->port_speed
= EHEA_SPEED_10G
;
1041 port
->full_duplex
= 1;
1044 port
->port_speed
= 0;
1045 port
->full_duplex
= 0;
1050 port
->num_mcs
= cb0
->num_default_qps
;
1052 /* Number of default QPs */
1054 port
->num_def_qps
= cb0
->num_default_qps
;
1056 port
->num_def_qps
= 1;
1058 if (!port
->num_def_qps
) {
1065 if (ret
|| netif_msg_probe(port
))
1066 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1067 free_page((unsigned long)cb0
);
1072 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1074 struct hcp_ehea_port_cb4
*cb4
;
1078 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1080 pr_err("no mem for cb4\n");
1085 cb4
->port_speed
= port_speed
;
1087 netif_carrier_off(port
->netdev
);
1089 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1090 port
->logical_port_id
,
1091 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1092 if (hret
== H_SUCCESS
) {
1093 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1095 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1096 port
->logical_port_id
,
1097 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1099 if (hret
== H_SUCCESS
) {
1100 switch (cb4
->port_speed
) {
1102 port
->port_speed
= EHEA_SPEED_10M
;
1103 port
->full_duplex
= 0;
1106 port
->port_speed
= EHEA_SPEED_10M
;
1107 port
->full_duplex
= 1;
1109 case H_SPEED_100M_H
:
1110 port
->port_speed
= EHEA_SPEED_100M
;
1111 port
->full_duplex
= 0;
1113 case H_SPEED_100M_F
:
1114 port
->port_speed
= EHEA_SPEED_100M
;
1115 port
->full_duplex
= 1;
1118 port
->port_speed
= EHEA_SPEED_1G
;
1119 port
->full_duplex
= 1;
1122 port
->port_speed
= EHEA_SPEED_10G
;
1123 port
->full_duplex
= 1;
1126 port
->port_speed
= 0;
1127 port
->full_duplex
= 0;
1131 pr_err("Failed sensing port speed\n");
1135 if (hret
== H_AUTHORITY
) {
1136 pr_info("Hypervisor denied setting port speed\n");
1140 pr_err("Failed setting port speed\n");
1143 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1144 netif_carrier_on(port
->netdev
);
1146 free_page((unsigned long)cb4
);
1151 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1156 struct ehea_port
*port
;
1157 struct net_device
*dev
;
1159 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1160 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1161 port
= ehea_get_port(adapter
, portnum
);
1165 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1168 netdev_err(dev
, "unknown portnum %x\n", portnum
);
1172 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1173 if (!netif_carrier_ok(dev
)) {
1174 ret
= ehea_sense_port_attr(port
);
1176 netdev_err(dev
, "failed resensing port attributes\n");
1180 netif_info(port
, link
, dev
,
1181 "Logical port up: %dMbps %s Duplex\n",
1183 port
->full_duplex
== 1 ?
1186 netif_carrier_on(dev
);
1187 netif_wake_queue(dev
);
1190 if (netif_carrier_ok(dev
)) {
1191 netif_info(port
, link
, dev
,
1192 "Logical port down\n");
1193 netif_carrier_off(dev
);
1194 netif_tx_disable(dev
);
1197 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1198 port
->phy_link
= EHEA_PHY_LINK_UP
;
1199 netif_info(port
, link
, dev
,
1200 "Physical port up\n");
1201 if (prop_carrier_state
)
1202 netif_carrier_on(dev
);
1204 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1205 netif_info(port
, link
, dev
,
1206 "Physical port down\n");
1207 if (prop_carrier_state
)
1208 netif_carrier_off(dev
);
1211 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1213 "External switch port is primary port\n");
1216 "External switch port is backup port\n");
1219 case EHEA_EC_ADAPTER_MALFUNC
:
1220 netdev_err(dev
, "Adapter malfunction\n");
1222 case EHEA_EC_PORT_MALFUNC
:
1223 netdev_info(dev
, "Port malfunction\n");
1224 netif_carrier_off(dev
);
1225 netif_tx_disable(dev
);
1228 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1233 static void ehea_neq_tasklet(unsigned long data
)
1235 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1236 struct ehea_eqe
*eqe
;
1239 eqe
= ehea_poll_eq(adapter
->neq
);
1240 pr_debug("eqe=%p\n", eqe
);
1243 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1244 ehea_parse_eqe(adapter
, eqe
->entry
);
1245 eqe
= ehea_poll_eq(adapter
->neq
);
1246 pr_debug("next eqe=%p\n", eqe
);
1249 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1250 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1251 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1253 ehea_h_reset_events(adapter
->handle
,
1254 adapter
->neq
->fw_handle
, event_mask
);
1257 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1259 struct ehea_adapter
*adapter
= param
;
1260 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1265 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1268 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1270 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1272 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1274 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1279 static int ehea_reg_interrupts(struct net_device
*dev
)
1281 struct ehea_port
*port
= netdev_priv(dev
);
1282 struct ehea_port_res
*pr
;
1286 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1289 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1290 ehea_qp_aff_irq_handler
,
1291 IRQF_DISABLED
, port
->int_aff_name
, port
);
1293 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1294 port
->qp_eq
->attr
.ist1
);
1298 netif_info(port
, ifup
, dev
,
1299 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1300 port
->qp_eq
->attr
.ist1
);
1303 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1304 pr
= &port
->port_res
[i
];
1305 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1306 "%s-queue%d", dev
->name
, i
);
1307 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1308 ehea_recv_irq_handler
,
1309 IRQF_DISABLED
, pr
->int_send_name
,
1312 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1313 i
, pr
->eq
->attr
.ist1
);
1316 netif_info(port
, ifup
, dev
,
1317 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1318 pr
->eq
->attr
.ist1
, i
);
1326 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1327 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1331 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1332 i
= port
->num_def_qps
;
1338 static void ehea_free_interrupts(struct net_device
*dev
)
1340 struct ehea_port
*port
= netdev_priv(dev
);
1341 struct ehea_port_res
*pr
;
1346 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1347 pr
= &port
->port_res
[i
];
1348 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1349 netif_info(port
, intr
, dev
,
1350 "free send irq for res %d with handle 0x%X\n",
1351 i
, pr
->eq
->attr
.ist1
);
1354 /* associated events */
1355 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1356 netif_info(port
, intr
, dev
,
1357 "associated event interrupt for handle 0x%X freed\n",
1358 port
->qp_eq
->attr
.ist1
);
1361 static int ehea_configure_port(struct ehea_port
*port
)
1365 struct hcp_ehea_port_cb0
*cb0
;
1368 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1372 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1374 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1375 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1376 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1377 PXLY_RC_VLAN_FILTER
)
1378 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1380 for (i
= 0; i
< port
->num_mcs
; i
++)
1382 cb0
->default_qpn_arr
[i
] =
1383 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1385 cb0
->default_qpn_arr
[i
] =
1386 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1388 if (netif_msg_ifup(port
))
1389 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1391 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1392 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1394 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1395 port
->logical_port_id
,
1396 H_PORT_CB0
, mask
, cb0
);
1398 if (hret
!= H_SUCCESS
)
1404 free_page((unsigned long)cb0
);
1409 static int ehea_gen_smrs(struct ehea_port_res
*pr
)
1412 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1414 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1418 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1425 ehea_rem_mr(&pr
->send_mr
);
1427 pr_err("Generating SMRS failed\n");
1431 static int ehea_rem_smrs(struct ehea_port_res
*pr
)
1433 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1434 (ehea_rem_mr(&pr
->recv_mr
)))
1440 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1442 int arr_size
= sizeof(void *) * max_q_entries
;
1444 q_skba
->arr
= vzalloc(arr_size
);
1448 q_skba
->len
= max_q_entries
;
1450 q_skba
->os_skbs
= 0;
1455 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1456 struct port_res_cfg
*pr_cfg
, int queue_token
)
1458 struct ehea_adapter
*adapter
= port
->adapter
;
1459 enum ehea_eq_type eq_type
= EHEA_EQ
;
1460 struct ehea_qp_init_attr
*init_attr
= NULL
;
1462 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1464 tx_bytes
= pr
->tx_bytes
;
1465 tx_packets
= pr
->tx_packets
;
1466 rx_bytes
= pr
->rx_bytes
;
1467 rx_packets
= pr
->rx_packets
;
1469 memset(pr
, 0, sizeof(struct ehea_port_res
));
1471 pr
->tx_bytes
= rx_bytes
;
1472 pr
->tx_packets
= tx_packets
;
1473 pr
->rx_bytes
= rx_bytes
;
1474 pr
->rx_packets
= rx_packets
;
1478 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1480 pr_err("create_eq failed (eq)\n");
1484 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1486 port
->logical_port_id
);
1488 pr_err("create_cq failed (cq_recv)\n");
1492 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1494 port
->logical_port_id
);
1496 pr_err("create_cq failed (cq_send)\n");
1500 if (netif_msg_ifup(port
))
1501 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1502 pr
->send_cq
->attr
.act_nr_of_cqes
,
1503 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1505 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1508 pr_err("no mem for ehea_qp_init_attr\n");
1512 init_attr
->low_lat_rq1
= 1;
1513 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1514 init_attr
->rq_count
= 3;
1515 init_attr
->qp_token
= queue_token
;
1516 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1517 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1518 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1519 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1520 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1521 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1522 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1523 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1524 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1525 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1526 init_attr
->port_nr
= port
->logical_port_id
;
1527 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1528 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1529 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1531 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1533 pr_err("create_qp failed\n");
1538 if (netif_msg_ifup(port
))
1539 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",
1541 init_attr
->act_nr_send_wqes
,
1542 init_attr
->act_nr_rwqes_rq1
,
1543 init_attr
->act_nr_rwqes_rq2
,
1544 init_attr
->act_nr_rwqes_rq3
);
1546 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1548 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1549 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1550 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1551 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1555 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1556 if (ehea_gen_smrs(pr
) != 0) {
1561 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1565 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1572 vfree(pr
->sq_skba
.arr
);
1573 vfree(pr
->rq1_skba
.arr
);
1574 vfree(pr
->rq2_skba
.arr
);
1575 vfree(pr
->rq3_skba
.arr
);
1576 ehea_destroy_qp(pr
->qp
);
1577 ehea_destroy_cq(pr
->send_cq
);
1578 ehea_destroy_cq(pr
->recv_cq
);
1579 ehea_destroy_eq(pr
->eq
);
1584 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1589 netif_napi_del(&pr
->napi
);
1591 ret
= ehea_destroy_qp(pr
->qp
);
1594 ehea_destroy_cq(pr
->send_cq
);
1595 ehea_destroy_cq(pr
->recv_cq
);
1596 ehea_destroy_eq(pr
->eq
);
1598 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1599 if (pr
->rq1_skba
.arr
[i
])
1600 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1602 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1603 if (pr
->rq2_skba
.arr
[i
])
1604 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1606 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1607 if (pr
->rq3_skba
.arr
[i
])
1608 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1610 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1611 if (pr
->sq_skba
.arr
[i
])
1612 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1614 vfree(pr
->rq1_skba
.arr
);
1615 vfree(pr
->rq2_skba
.arr
);
1616 vfree(pr
->rq3_skba
.arr
);
1617 vfree(pr
->sq_skba
.arr
);
1618 ret
= ehea_rem_smrs(pr
);
1623 static void write_swqe2_immediate(struct sk_buff
*skb
, struct ehea_swqe
*swqe
,
1626 int skb_data_size
= skb_headlen(skb
);
1627 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1628 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1629 unsigned int immediate_len
= SWQE2_MAX_IMM
;
1631 swqe
->descriptors
= 0;
1633 if (skb_is_gso(skb
)) {
1634 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1635 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1637 * For TSO packets we only copy the headers into the
1640 immediate_len
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1643 if (skb_is_gso(skb
) || skb_data_size
>= SWQE2_MAX_IMM
) {
1644 skb_copy_from_linear_data(skb
, imm_data
, immediate_len
);
1645 swqe
->immediate_data_length
= immediate_len
;
1647 if (skb_data_size
> immediate_len
) {
1648 sg1entry
->l_key
= lkey
;
1649 sg1entry
->len
= skb_data_size
- immediate_len
;
1651 ehea_map_vaddr(skb
->data
+ immediate_len
);
1652 swqe
->descriptors
++;
1655 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1656 swqe
->immediate_data_length
= skb_data_size
;
1660 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1661 struct ehea_swqe
*swqe
, u32 lkey
)
1663 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1665 int nfrags
, sg1entry_contains_frag_data
, i
;
1667 nfrags
= skb_shinfo(skb
)->nr_frags
;
1668 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1669 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1670 sg1entry_contains_frag_data
= 0;
1672 write_swqe2_immediate(skb
, swqe
, lkey
);
1674 /* write descriptors */
1676 if (swqe
->descriptors
== 0) {
1677 /* sg1entry not yet used */
1678 frag
= &skb_shinfo(skb
)->frags
[0];
1680 /* copy sg1entry data */
1681 sg1entry
->l_key
= lkey
;
1682 sg1entry
->len
= skb_frag_size(frag
);
1684 ehea_map_vaddr(skb_frag_address(frag
));
1685 swqe
->descriptors
++;
1686 sg1entry_contains_frag_data
= 1;
1689 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1691 frag
= &skb_shinfo(skb
)->frags
[i
];
1692 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1694 sgentry
->l_key
= lkey
;
1695 sgentry
->len
= skb_frag_size(frag
);
1696 sgentry
->vaddr
= ehea_map_vaddr(skb_frag_address(frag
));
1697 swqe
->descriptors
++;
1702 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1708 /* De/Register untagged packets */
1709 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1710 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1711 port
->logical_port_id
,
1712 reg_type
, port
->mac_addr
, 0, hcallid
);
1713 if (hret
!= H_SUCCESS
) {
1714 pr_err("%sregistering bc address failed (tagged)\n",
1715 hcallid
== H_REG_BCMC
? "" : "de");
1720 /* De/Register VLAN packets */
1721 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1722 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1723 port
->logical_port_id
,
1724 reg_type
, port
->mac_addr
, 0, hcallid
);
1725 if (hret
!= H_SUCCESS
) {
1726 pr_err("%sregistering bc address failed (vlan)\n",
1727 hcallid
== H_REG_BCMC
? "" : "de");
1734 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1736 struct ehea_port
*port
= netdev_priv(dev
);
1737 struct sockaddr
*mac_addr
= sa
;
1738 struct hcp_ehea_port_cb0
*cb0
;
1742 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1743 ret
= -EADDRNOTAVAIL
;
1747 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1749 pr_err("no mem for cb0\n");
1754 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1756 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1758 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1759 port
->logical_port_id
, H_PORT_CB0
,
1760 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1761 if (hret
!= H_SUCCESS
) {
1766 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1768 /* Deregister old MAC in pHYP */
1769 if (port
->state
== EHEA_PORT_UP
) {
1770 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1775 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1777 /* Register new MAC in pHYP */
1778 if (port
->state
== EHEA_PORT_UP
) {
1779 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1787 ehea_update_bcmc_registrations();
1789 free_page((unsigned long)cb0
);
1794 static void ehea_promiscuous_error(u64 hret
, int enable
)
1796 if (hret
== H_AUTHORITY
)
1797 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1798 enable
== 1 ? "en" : "dis");
1800 pr_err("failed %sabling promiscuous mode\n",
1801 enable
== 1 ? "en" : "dis");
1804 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1806 struct ehea_port
*port
= netdev_priv(dev
);
1807 struct hcp_ehea_port_cb7
*cb7
;
1810 if (enable
== port
->promisc
)
1813 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1815 pr_err("no mem for cb7\n");
1819 /* Modify Pxs_DUCQPN in CB7 */
1820 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1822 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1823 port
->logical_port_id
,
1824 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1826 ehea_promiscuous_error(hret
, enable
);
1830 port
->promisc
= enable
;
1832 free_page((unsigned long)cb7
);
1835 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1841 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1842 | EHEA_BCMC_UNTAGGED
;
1844 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1845 port
->logical_port_id
,
1846 reg_type
, mc_mac_addr
, 0, hcallid
);
1850 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1851 | EHEA_BCMC_VLANID_ALL
;
1853 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1854 port
->logical_port_id
,
1855 reg_type
, mc_mac_addr
, 0, hcallid
);
1860 static int ehea_drop_multicast_list(struct net_device
*dev
)
1862 struct ehea_port
*port
= netdev_priv(dev
);
1863 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1864 struct list_head
*pos
;
1865 struct list_head
*temp
;
1869 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1870 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1872 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1875 pr_err("failed deregistering mcast MAC\n");
1885 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1887 struct ehea_port
*port
= netdev_priv(dev
);
1890 if (!port
->allmulti
) {
1892 /* Enable ALLMULTI */
1893 ehea_drop_multicast_list(dev
);
1894 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1899 "failed enabling IFF_ALLMULTI\n");
1903 /* Disable ALLMULTI */
1904 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1909 "failed disabling IFF_ALLMULTI\n");
1913 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1915 struct ehea_mc_list
*ehea_mcl_entry
;
1918 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1919 if (!ehea_mcl_entry
) {
1920 pr_err("no mem for mcl_entry\n");
1924 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1926 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1928 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1931 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1933 pr_err("failed registering mcast MAC\n");
1934 kfree(ehea_mcl_entry
);
1938 static void ehea_set_multicast_list(struct net_device
*dev
)
1940 struct ehea_port
*port
= netdev_priv(dev
);
1941 struct netdev_hw_addr
*ha
;
1944 if (port
->promisc
) {
1945 ehea_promiscuous(dev
, 1);
1948 ehea_promiscuous(dev
, 0);
1950 if (dev
->flags
& IFF_ALLMULTI
) {
1951 ehea_allmulti(dev
, 1);
1954 ehea_allmulti(dev
, 0);
1956 if (!netdev_mc_empty(dev
)) {
1957 ret
= ehea_drop_multicast_list(dev
);
1959 /* Dropping the current multicast list failed.
1960 * Enabling ALL_MULTI is the best we can do.
1962 ehea_allmulti(dev
, 1);
1965 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
1966 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1967 port
->adapter
->max_mc_mac
);
1971 netdev_for_each_mc_addr(ha
, dev
)
1972 ehea_add_multicast_entry(port
, ha
->addr
);
1976 ehea_update_bcmc_registrations();
1979 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1981 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1987 static void xmit_common(struct sk_buff
*skb
, struct ehea_swqe
*swqe
)
1989 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
| EHEA_SWQE_CRC
;
1991 if (skb
->protocol
!= htons(ETH_P_IP
))
1994 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1995 swqe
->tx_control
|= EHEA_SWQE_IP_CHECKSUM
;
1997 swqe
->ip_start
= skb_network_offset(skb
);
1998 swqe
->ip_end
= swqe
->ip_start
+ ip_hdrlen(skb
) - 1;
2000 switch (ip_hdr(skb
)->protocol
) {
2002 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2003 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2005 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2006 offsetof(struct udphdr
, check
);
2010 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2011 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2013 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2014 offsetof(struct tcphdr
, check
);
2019 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2020 struct ehea_swqe
*swqe
, u32 lkey
)
2022 swqe
->tx_control
|= EHEA_SWQE_DESCRIPTORS_PRESENT
;
2024 xmit_common(skb
, swqe
);
2026 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2029 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2030 struct ehea_swqe
*swqe
)
2032 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2034 xmit_common(skb
, swqe
);
2037 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2039 skb_copy_bits(skb
, 0, imm_data
, skb
->len
);
2041 swqe
->immediate_data_length
= skb
->len
;
2045 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2047 struct ehea_port
*port
= netdev_priv(dev
);
2048 struct ehea_swqe
*swqe
;
2051 struct ehea_port_res
*pr
;
2052 struct netdev_queue
*txq
;
2054 pr
= &port
->port_res
[skb_get_queue_mapping(skb
)];
2055 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
2057 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2058 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2059 atomic_dec(&pr
->swqe_avail
);
2061 if (vlan_tx_tag_present(skb
)) {
2062 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2063 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2067 pr
->tx_bytes
+= skb
->len
;
2069 if (skb
->len
<= SWQE3_MAX_IMM
) {
2070 u32 sig_iv
= port
->sig_comp_iv
;
2071 u32 swqe_num
= pr
->swqe_id_counter
;
2072 ehea_xmit3(skb
, dev
, swqe
);
2073 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2074 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2075 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2076 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2078 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2079 pr
->swqe_ll_count
= 0;
2081 pr
->swqe_ll_count
+= 1;
2084 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2085 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2086 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2087 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2088 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2090 pr
->sq_skba
.index
++;
2091 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2093 lkey
= pr
->send_mr
.lkey
;
2094 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2095 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2097 pr
->swqe_id_counter
+= 1;
2099 netif_info(port
, tx_queued
, dev
,
2100 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2101 if (netif_msg_tx_queued(port
))
2102 ehea_dump(swqe
, 512, "swqe");
2104 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2105 netif_tx_stop_queue(txq
);
2106 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2109 ehea_post_swqe(pr
->qp
, swqe
);
2111 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2112 pr
->p_stats
.queue_stopped
++;
2113 netif_tx_stop_queue(txq
);
2116 return NETDEV_TX_OK
;
2119 static int ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2121 struct ehea_port
*port
= netdev_priv(dev
);
2122 struct ehea_adapter
*adapter
= port
->adapter
;
2123 struct hcp_ehea_port_cb1
*cb1
;
2128 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2130 pr_err("no mem for cb1\n");
2135 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2136 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2137 if (hret
!= H_SUCCESS
) {
2138 pr_err("query_ehea_port failed\n");
2144 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2146 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2147 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2148 if (hret
!= H_SUCCESS
) {
2149 pr_err("modify_ehea_port failed\n");
2153 free_page((unsigned long)cb1
);
2157 static int ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2159 struct ehea_port
*port
= netdev_priv(dev
);
2160 struct ehea_adapter
*adapter
= port
->adapter
;
2161 struct hcp_ehea_port_cb1
*cb1
;
2166 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2168 pr_err("no mem for cb1\n");
2173 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2174 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2175 if (hret
!= H_SUCCESS
) {
2176 pr_err("query_ehea_port failed\n");
2182 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2184 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2185 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2186 if (hret
!= H_SUCCESS
) {
2187 pr_err("modify_ehea_port failed\n");
2191 free_page((unsigned long)cb1
);
2195 static int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2201 struct hcp_modify_qp_cb0
*cb0
;
2203 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2209 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2210 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2211 if (hret
!= H_SUCCESS
) {
2212 pr_err("query_ehea_qp failed (1)\n");
2216 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2217 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2218 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2219 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2220 if (hret
!= H_SUCCESS
) {
2221 pr_err("modify_ehea_qp failed (1)\n");
2225 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2226 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2227 if (hret
!= H_SUCCESS
) {
2228 pr_err("query_ehea_qp failed (2)\n");
2232 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2233 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2234 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2235 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2236 if (hret
!= H_SUCCESS
) {
2237 pr_err("modify_ehea_qp failed (2)\n");
2241 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2242 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2243 if (hret
!= H_SUCCESS
) {
2244 pr_err("query_ehea_qp failed (3)\n");
2248 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2249 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2250 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2251 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2252 if (hret
!= H_SUCCESS
) {
2253 pr_err("modify_ehea_qp failed (3)\n");
2257 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2258 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2259 if (hret
!= H_SUCCESS
) {
2260 pr_err("query_ehea_qp failed (4)\n");
2266 free_page((unsigned long)cb0
);
2270 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
)
2273 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2274 enum ehea_eq_type eq_type
= EHEA_EQ
;
2276 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2277 EHEA_MAX_ENTRIES_EQ
, 1);
2280 pr_err("ehea_create_eq failed (qp_eq)\n");
2284 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2285 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2286 pr_cfg
.max_entries_sq
= sq_entries
;
2287 pr_cfg
.max_entries_rq1
= rq1_entries
;
2288 pr_cfg
.max_entries_rq2
= rq2_entries
;
2289 pr_cfg
.max_entries_rq3
= rq3_entries
;
2291 pr_cfg_small_rx
.max_entries_rcq
= 1;
2292 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2293 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2294 pr_cfg_small_rx
.max_entries_rq1
= 1;
2295 pr_cfg_small_rx
.max_entries_rq2
= 1;
2296 pr_cfg_small_rx
.max_entries_rq3
= 1;
2298 for (i
= 0; i
< def_qps
; i
++) {
2299 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2303 for (i
= def_qps
; i
< def_qps
; i
++) {
2304 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2305 &pr_cfg_small_rx
, i
);
2314 ehea_clean_portres(port
, &port
->port_res
[i
]);
2317 ehea_destroy_eq(port
->qp_eq
);
2321 static int ehea_clean_all_portres(struct ehea_port
*port
)
2326 for (i
= 0; i
< port
->num_def_qps
; i
++)
2327 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2329 ret
|= ehea_destroy_eq(port
->qp_eq
);
2334 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2336 if (adapter
->active_ports
)
2339 ehea_rem_mr(&adapter
->mr
);
2342 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2344 if (adapter
->active_ports
)
2347 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2350 static int ehea_up(struct net_device
*dev
)
2353 struct ehea_port
*port
= netdev_priv(dev
);
2355 if (port
->state
== EHEA_PORT_UP
)
2358 ret
= ehea_port_res_setup(port
, port
->num_def_qps
);
2360 netdev_err(dev
, "port_res_failed\n");
2364 /* Set default QP for this port */
2365 ret
= ehea_configure_port(port
);
2367 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2371 ret
= ehea_reg_interrupts(dev
);
2373 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2377 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2378 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2380 netdev_err(dev
, "activate_qp failed\n");
2385 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2386 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2388 netdev_err(dev
, "out_free_irqs\n");
2393 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2399 port
->state
= EHEA_PORT_UP
;
2405 ehea_free_interrupts(dev
);
2408 ehea_clean_all_portres(port
);
2411 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2413 ehea_update_bcmc_registrations();
2414 ehea_update_firmware_handles();
2419 static void port_napi_disable(struct ehea_port
*port
)
2423 for (i
= 0; i
< port
->num_def_qps
; i
++)
2424 napi_disable(&port
->port_res
[i
].napi
);
2427 static void port_napi_enable(struct ehea_port
*port
)
2431 for (i
= 0; i
< port
->num_def_qps
; i
++)
2432 napi_enable(&port
->port_res
[i
].napi
);
2435 static int ehea_open(struct net_device
*dev
)
2438 struct ehea_port
*port
= netdev_priv(dev
);
2440 mutex_lock(&port
->port_lock
);
2442 netif_info(port
, ifup
, dev
, "enabling port\n");
2446 port_napi_enable(port
);
2447 netif_tx_start_all_queues(dev
);
2450 mutex_unlock(&port
->port_lock
);
2451 schedule_delayed_work(&port
->stats_work
,
2452 round_jiffies_relative(msecs_to_jiffies(1000)));
2457 static int ehea_down(struct net_device
*dev
)
2460 struct ehea_port
*port
= netdev_priv(dev
);
2462 if (port
->state
== EHEA_PORT_DOWN
)
2465 ehea_drop_multicast_list(dev
);
2466 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2468 ehea_free_interrupts(dev
);
2470 port
->state
= EHEA_PORT_DOWN
;
2472 ehea_update_bcmc_registrations();
2474 ret
= ehea_clean_all_portres(port
);
2476 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2478 ehea_update_firmware_handles();
2483 static int ehea_stop(struct net_device
*dev
)
2486 struct ehea_port
*port
= netdev_priv(dev
);
2488 netif_info(port
, ifdown
, dev
, "disabling port\n");
2490 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2491 cancel_work_sync(&port
->reset_task
);
2492 cancel_delayed_work_sync(&port
->stats_work
);
2493 mutex_lock(&port
->port_lock
);
2494 netif_tx_stop_all_queues(dev
);
2495 port_napi_disable(port
);
2496 ret
= ehea_down(dev
);
2497 mutex_unlock(&port
->port_lock
);
2498 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2502 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2504 struct ehea_qp qp
= *orig_qp
;
2505 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2506 struct ehea_swqe
*swqe
;
2510 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2511 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2512 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2516 static void ehea_flush_sq(struct ehea_port
*port
)
2520 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2521 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2522 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2525 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2526 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2527 msecs_to_jiffies(100));
2530 pr_err("WARNING: sq not flushed completely\n");
2536 static int ehea_stop_qps(struct net_device
*dev
)
2538 struct ehea_port
*port
= netdev_priv(dev
);
2539 struct ehea_adapter
*adapter
= port
->adapter
;
2540 struct hcp_modify_qp_cb0
*cb0
;
2548 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2554 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2555 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2556 struct ehea_qp
*qp
= pr
->qp
;
2558 /* Purge send queue */
2561 /* Disable queue pair */
2562 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2563 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2565 if (hret
!= H_SUCCESS
) {
2566 pr_err("query_ehea_qp failed (1)\n");
2570 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2571 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2573 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2574 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2576 &dummy64
, &dummy16
, &dummy16
);
2577 if (hret
!= H_SUCCESS
) {
2578 pr_err("modify_ehea_qp failed (1)\n");
2582 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2583 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2585 if (hret
!= H_SUCCESS
) {
2586 pr_err("query_ehea_qp failed (2)\n");
2590 /* deregister shared memory regions */
2591 dret
= ehea_rem_smrs(pr
);
2593 pr_err("unreg shared memory region failed\n");
2600 free_page((unsigned long)cb0
);
2605 static void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2607 struct ehea_qp qp
= *orig_qp
;
2608 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2609 struct ehea_rwqe
*rwqe
;
2610 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2611 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2612 struct sk_buff
*skb
;
2613 u32 lkey
= pr
->recv_mr
.lkey
;
2619 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2620 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2621 rwqe
->sg_list
[0].l_key
= lkey
;
2622 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2623 skb
= skba_rq2
[index
];
2625 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2628 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2629 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2630 rwqe
->sg_list
[0].l_key
= lkey
;
2631 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2632 skb
= skba_rq3
[index
];
2634 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2638 static int ehea_restart_qps(struct net_device
*dev
)
2640 struct ehea_port
*port
= netdev_priv(dev
);
2641 struct ehea_adapter
*adapter
= port
->adapter
;
2645 struct hcp_modify_qp_cb0
*cb0
;
2650 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2656 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2657 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2658 struct ehea_qp
*qp
= pr
->qp
;
2660 ret
= ehea_gen_smrs(pr
);
2662 netdev_err(dev
, "creation of shared memory regions failed\n");
2666 ehea_update_rqs(qp
, pr
);
2668 /* Enable queue pair */
2669 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2670 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2672 if (hret
!= H_SUCCESS
) {
2673 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2677 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2678 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2680 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2681 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2683 &dummy64
, &dummy16
, &dummy16
);
2684 if (hret
!= H_SUCCESS
) {
2685 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2689 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2690 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2692 if (hret
!= H_SUCCESS
) {
2693 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2697 /* refill entire queue */
2698 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2699 ehea_refill_rq2(pr
, 0);
2700 ehea_refill_rq3(pr
, 0);
2703 free_page((unsigned long)cb0
);
2708 static void ehea_reset_port(struct work_struct
*work
)
2711 struct ehea_port
*port
=
2712 container_of(work
, struct ehea_port
, reset_task
);
2713 struct net_device
*dev
= port
->netdev
;
2715 mutex_lock(&dlpar_mem_lock
);
2717 mutex_lock(&port
->port_lock
);
2718 netif_tx_disable(dev
);
2720 port_napi_disable(port
);
2728 ehea_set_multicast_list(dev
);
2730 netif_info(port
, timer
, dev
, "reset successful\n");
2732 port_napi_enable(port
);
2734 netif_tx_wake_all_queues(dev
);
2736 mutex_unlock(&port
->port_lock
);
2737 mutex_unlock(&dlpar_mem_lock
);
2740 static void ehea_rereg_mrs(void)
2743 struct ehea_adapter
*adapter
;
2745 pr_info("LPAR memory changed - re-initializing driver\n");
2747 list_for_each_entry(adapter
, &adapter_list
, list
)
2748 if (adapter
->active_ports
) {
2749 /* Shutdown all ports */
2750 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2751 struct ehea_port
*port
= adapter
->port
[i
];
2752 struct net_device
*dev
;
2759 if (dev
->flags
& IFF_UP
) {
2760 mutex_lock(&port
->port_lock
);
2761 netif_tx_disable(dev
);
2762 ehea_flush_sq(port
);
2763 ret
= ehea_stop_qps(dev
);
2765 mutex_unlock(&port
->port_lock
);
2768 port_napi_disable(port
);
2769 mutex_unlock(&port
->port_lock
);
2771 reset_sq_restart_flag(port
);
2774 /* Unregister old memory region */
2775 ret
= ehea_rem_mr(&adapter
->mr
);
2777 pr_err("unregister MR failed - driver inoperable!\n");
2782 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2784 list_for_each_entry(adapter
, &adapter_list
, list
)
2785 if (adapter
->active_ports
) {
2786 /* Register new memory region */
2787 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2789 pr_err("register MR failed - driver inoperable!\n");
2793 /* Restart all ports */
2794 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2795 struct ehea_port
*port
= adapter
->port
[i
];
2798 struct net_device
*dev
= port
->netdev
;
2800 if (dev
->flags
& IFF_UP
) {
2801 mutex_lock(&port
->port_lock
);
2802 ret
= ehea_restart_qps(dev
);
2805 port_napi_enable(port
);
2806 netif_tx_wake_all_queues(dev
);
2808 netdev_err(dev
, "Unable to restart QPS\n");
2810 mutex_unlock(&port
->port_lock
);
2815 pr_info("re-initializing driver complete\n");
2820 static void ehea_tx_watchdog(struct net_device
*dev
)
2822 struct ehea_port
*port
= netdev_priv(dev
);
2824 if (netif_carrier_ok(dev
) &&
2825 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2826 ehea_schedule_port_reset(port
);
2829 static int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2831 struct hcp_query_ehea
*cb
;
2835 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2841 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2843 if (hret
!= H_SUCCESS
) {
2848 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2852 free_page((unsigned long)cb
);
2857 static int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2859 struct hcp_ehea_port_cb4
*cb4
;
2865 /* (Try to) enable *jumbo frames */
2866 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2868 pr_err("no mem for cb4\n");
2872 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2873 port
->logical_port_id
,
2875 H_PORT_CB4_JUMBO
, cb4
);
2876 if (hret
== H_SUCCESS
) {
2877 if (cb4
->jumbo_frame
)
2880 cb4
->jumbo_frame
= 1;
2881 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2888 if (hret
== H_SUCCESS
)
2894 free_page((unsigned long)cb4
);
2900 static ssize_t
ehea_show_port_id(struct device
*dev
,
2901 struct device_attribute
*attr
, char *buf
)
2903 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2904 return sprintf(buf
, "%d", port
->logical_port_id
);
2907 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2910 static void __devinit
logical_port_release(struct device
*dev
)
2912 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2913 of_node_put(port
->ofdev
.dev
.of_node
);
2916 static struct device
*ehea_register_port(struct ehea_port
*port
,
2917 struct device_node
*dn
)
2921 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
2922 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2923 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2925 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
2926 port
->ofdev
.dev
.release
= logical_port_release
;
2928 ret
= of_device_register(&port
->ofdev
);
2930 pr_err("failed to register device. ret=%d\n", ret
);
2934 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2936 pr_err("failed to register attributes, ret=%d\n", ret
);
2937 goto out_unreg_of_dev
;
2940 return &port
->ofdev
.dev
;
2943 of_device_unregister(&port
->ofdev
);
2948 static void ehea_unregister_port(struct ehea_port
*port
)
2950 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2951 of_device_unregister(&port
->ofdev
);
2954 static const struct net_device_ops ehea_netdev_ops
= {
2955 .ndo_open
= ehea_open
,
2956 .ndo_stop
= ehea_stop
,
2957 .ndo_start_xmit
= ehea_start_xmit
,
2958 #ifdef CONFIG_NET_POLL_CONTROLLER
2959 .ndo_poll_controller
= ehea_netpoll
,
2961 .ndo_get_stats64
= ehea_get_stats64
,
2962 .ndo_set_mac_address
= ehea_set_mac_addr
,
2963 .ndo_validate_addr
= eth_validate_addr
,
2964 .ndo_set_rx_mode
= ehea_set_multicast_list
,
2965 .ndo_change_mtu
= ehea_change_mtu
,
2966 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
2967 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
2968 .ndo_tx_timeout
= ehea_tx_watchdog
,
2971 static struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2972 u32 logical_port_id
,
2973 struct device_node
*dn
)
2976 struct net_device
*dev
;
2977 struct ehea_port
*port
;
2978 struct device
*port_dev
;
2981 /* allocate memory for the port structures */
2982 dev
= alloc_etherdev_mq(sizeof(struct ehea_port
), EHEA_MAX_PORT_RES
);
2985 pr_err("no mem for net_device\n");
2990 port
= netdev_priv(dev
);
2992 mutex_init(&port
->port_lock
);
2993 port
->state
= EHEA_PORT_DOWN
;
2994 port
->sig_comp_iv
= sq_entries
/ 10;
2996 port
->adapter
= adapter
;
2998 port
->logical_port_id
= logical_port_id
;
3000 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3002 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3003 if (!port
->mc_list
) {
3005 goto out_free_ethdev
;
3008 INIT_LIST_HEAD(&port
->mc_list
->list
);
3010 ret
= ehea_sense_port_attr(port
);
3012 goto out_free_mc_list
;
3014 netif_set_real_num_rx_queues(dev
, port
->num_def_qps
);
3015 netif_set_real_num_tx_queues(dev
, port
->num_def_qps
);
3017 port_dev
= ehea_register_port(port
, dn
);
3019 goto out_free_mc_list
;
3021 SET_NETDEV_DEV(dev
, port_dev
);
3023 /* initialize net_device structure */
3024 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3026 dev
->netdev_ops
= &ehea_netdev_ops
;
3027 ehea_set_ethtool_ops(dev
);
3029 dev
->hw_features
= NETIF_F_SG
| NETIF_F_TSO
3030 | NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
| NETIF_F_LRO
;
3031 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3032 | NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
3033 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3035 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HIGHDMA
|
3037 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3039 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3040 INIT_DELAYED_WORK(&port
->stats_work
, ehea_update_stats
);
3042 init_waitqueue_head(&port
->swqe_avail_wq
);
3043 init_waitqueue_head(&port
->restart_wq
);
3045 memset(&port
->stats
, 0, sizeof(struct net_device_stats
));
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=%s\n",
3110 if (ehea_add_adapter_mr(adapter
)) {
3111 pr_err("creating MR failed\n");
3112 of_node_put(eth_dn
);
3116 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3119 if (adapter
->port
[i
])
3120 netdev_info(adapter
->port
[i
]->netdev
,
3121 "logical port id #%d\n", *dn_log_port_id
);
3123 ehea_remove_adapter_mr(adapter
);
3130 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3131 u32 logical_port_id
)
3133 struct device_node
*lhea_dn
;
3134 struct device_node
*eth_dn
= NULL
;
3135 const u32
*dn_log_port_id
;
3137 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3138 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3140 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3143 if (*dn_log_port_id
== logical_port_id
)
3150 static ssize_t
ehea_probe_port(struct device
*dev
,
3151 struct device_attribute
*attr
,
3152 const char *buf
, size_t count
)
3154 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3155 struct ehea_port
*port
;
3156 struct device_node
*eth_dn
= NULL
;
3159 u32 logical_port_id
;
3161 sscanf(buf
, "%d", &logical_port_id
);
3163 port
= ehea_get_port(adapter
, logical_port_id
);
3166 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3171 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3174 pr_info("no logical port with id %d found\n", logical_port_id
);
3178 if (ehea_add_adapter_mr(adapter
)) {
3179 pr_err("creating MR failed\n");
3183 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3185 of_node_put(eth_dn
);
3188 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3189 if (!adapter
->port
[i
]) {
3190 adapter
->port
[i
] = port
;
3194 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3197 ehea_remove_adapter_mr(adapter
);
3201 return (ssize_t
) count
;
3204 static ssize_t
ehea_remove_port(struct device
*dev
,
3205 struct device_attribute
*attr
,
3206 const char *buf
, size_t count
)
3208 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3209 struct ehea_port
*port
;
3211 u32 logical_port_id
;
3213 sscanf(buf
, "%d", &logical_port_id
);
3215 port
= ehea_get_port(adapter
, logical_port_id
);
3218 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3221 ehea_shutdown_single_port(port
);
3223 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3224 if (adapter
->port
[i
] == port
) {
3225 adapter
->port
[i
] = NULL
;
3229 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3234 ehea_remove_adapter_mr(adapter
);
3236 return (ssize_t
) count
;
3239 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3240 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3242 static int ehea_create_device_sysfs(struct platform_device
*dev
)
3244 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3248 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3253 static void ehea_remove_device_sysfs(struct platform_device
*dev
)
3255 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3256 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3259 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
3260 const struct of_device_id
*id
)
3262 struct ehea_adapter
*adapter
;
3263 const u64
*adapter_handle
;
3266 if (!dev
|| !dev
->dev
.of_node
) {
3267 pr_err("Invalid ibmebus device probed\n");
3271 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3274 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3278 list_add(&adapter
->list
, &adapter_list
);
3280 adapter
->ofdev
= dev
;
3282 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3285 adapter
->handle
= *adapter_handle
;
3287 if (!adapter
->handle
) {
3288 dev_err(&dev
->dev
, "failed getting handle for adapter"
3289 " '%s'\n", dev
->dev
.of_node
->full_name
);
3294 adapter
->pd
= EHEA_PD_ID
;
3296 dev_set_drvdata(&dev
->dev
, adapter
);
3299 /* initialize adapter and ports */
3300 /* get adapter properties */
3301 ret
= ehea_sense_adapter_attr(adapter
);
3303 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3307 adapter
->neq
= ehea_create_eq(adapter
,
3308 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3309 if (!adapter
->neq
) {
3311 dev_err(&dev
->dev
, "NEQ creation failed\n");
3315 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3316 (unsigned long)adapter
);
3318 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3319 ehea_interrupt_neq
, IRQF_DISABLED
,
3320 "ehea_neq", adapter
);
3322 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3326 ret
= ehea_create_device_sysfs(dev
);
3330 ret
= ehea_setup_ports(adapter
);
3332 dev_err(&dev
->dev
, "setup_ports failed\n");
3333 goto out_rem_dev_sysfs
;
3340 ehea_remove_device_sysfs(dev
);
3343 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3346 ehea_destroy_eq(adapter
->neq
);
3349 list_del(&adapter
->list
);
3353 ehea_update_firmware_handles();
3358 static int __devexit
ehea_remove(struct platform_device
*dev
)
3360 struct ehea_adapter
*adapter
= dev_get_drvdata(&dev
->dev
);
3363 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3364 if (adapter
->port
[i
]) {
3365 ehea_shutdown_single_port(adapter
->port
[i
]);
3366 adapter
->port
[i
] = NULL
;
3369 ehea_remove_device_sysfs(dev
);
3371 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3372 tasklet_kill(&adapter
->neq_tasklet
);
3374 ehea_destroy_eq(adapter
->neq
);
3375 ehea_remove_adapter_mr(adapter
);
3376 list_del(&adapter
->list
);
3379 ehea_update_firmware_handles();
3384 static void ehea_crash_handler(void)
3388 if (ehea_fw_handles
.arr
)
3389 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3390 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3391 ehea_fw_handles
.arr
[i
].fwh
,
3394 if (ehea_bcmc_regs
.arr
)
3395 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3396 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3397 ehea_bcmc_regs
.arr
[i
].port_id
,
3398 ehea_bcmc_regs
.arr
[i
].reg_type
,
3399 ehea_bcmc_regs
.arr
[i
].macaddr
,
3403 static int ehea_mem_notifier(struct notifier_block
*nb
,
3404 unsigned long action
, void *data
)
3406 int ret
= NOTIFY_BAD
;
3407 struct memory_notify
*arg
= data
;
3409 mutex_lock(&dlpar_mem_lock
);
3412 case MEM_CANCEL_OFFLINE
:
3413 pr_info("memory offlining canceled");
3414 /* Readd canceled memory block */
3416 pr_info("memory is going online");
3417 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3418 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3422 case MEM_GOING_OFFLINE
:
3423 pr_info("memory is going offline");
3424 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3425 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3433 ehea_update_firmware_handles();
3437 mutex_unlock(&dlpar_mem_lock
);
3441 static struct notifier_block ehea_mem_nb
= {
3442 .notifier_call
= ehea_mem_notifier
,
3445 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3446 unsigned long action
, void *unused
)
3448 if (action
== SYS_RESTART
) {
3449 pr_info("Reboot: freeing all eHEA resources\n");
3450 ibmebus_unregister_driver(&ehea_driver
);
3455 static struct notifier_block ehea_reboot_nb
= {
3456 .notifier_call
= ehea_reboot_notifier
,
3459 static int check_module_parm(void)
3463 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3464 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3465 pr_info("Bad parameter: rq1_entries\n");
3468 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3469 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3470 pr_info("Bad parameter: rq2_entries\n");
3473 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3474 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3475 pr_info("Bad parameter: rq3_entries\n");
3478 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3479 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3480 pr_info("Bad parameter: sq_entries\n");
3487 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3490 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3493 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3494 ehea_show_capabilities
, NULL
);
3496 static int __init
ehea_module_init(void)
3500 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3502 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3503 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3505 mutex_init(&ehea_fw_handles
.lock
);
3506 spin_lock_init(&ehea_bcmc_regs
.lock
);
3508 ret
= check_module_parm();
3512 ret
= ehea_create_busmap();
3516 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3518 pr_info("failed registering reboot notifier\n");
3520 ret
= register_memory_notifier(&ehea_mem_nb
);
3522 pr_info("failed registering memory remove notifier\n");
3524 ret
= crash_shutdown_register(ehea_crash_handler
);
3526 pr_info("failed registering crash handler\n");
3528 ret
= ibmebus_register_driver(&ehea_driver
);
3530 pr_err("failed registering eHEA device driver on ebus\n");
3534 ret
= driver_create_file(&ehea_driver
.driver
,
3535 &driver_attr_capabilities
);
3537 pr_err("failed to register capabilities attribute, ret=%d\n",
3545 ibmebus_unregister_driver(&ehea_driver
);
3547 unregister_memory_notifier(&ehea_mem_nb
);
3548 unregister_reboot_notifier(&ehea_reboot_nb
);
3549 crash_shutdown_unregister(ehea_crash_handler
);
3554 static void __exit
ehea_module_exit(void)
3558 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3559 ibmebus_unregister_driver(&ehea_driver
);
3560 unregister_reboot_notifier(&ehea_reboot_nb
);
3561 ret
= crash_shutdown_unregister(ehea_crash_handler
);
3563 pr_info("failed unregistering crash handler\n");
3564 unregister_memory_notifier(&ehea_mem_nb
);
3565 kfree(ehea_fw_handles
.arr
);
3566 kfree(ehea_bcmc_regs
.arr
);
3567 ehea_destroy_busmap();
3570 module_init(ehea_module_init
);
3571 module_exit(ehea_module_exit
);