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 struct ehea_fw_handle_array ehea_fw_handles
;
98 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 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
;
342 static void ehea_update_stats(struct work_struct
*work
)
344 struct ehea_port
*port
=
345 container_of(work
, struct ehea_port
, stats_work
.work
);
346 struct net_device
*dev
= port
->netdev
;
347 struct rtnl_link_stats64
*stats
= &port
->stats
;
348 struct hcp_ehea_port_cb2
*cb2
;
351 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
353 netdev_err(dev
, "No mem for cb2. Some interface statistics were not updated\n");
357 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
358 port
->logical_port_id
,
359 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
360 if (hret
!= H_SUCCESS
) {
361 netdev_err(dev
, "query_ehea_port failed\n");
365 if (netif_msg_hw(port
))
366 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
368 stats
->multicast
= cb2
->rxmcp
;
369 stats
->rx_errors
= cb2
->rxuerr
;
372 free_page((unsigned long)cb2
);
374 schedule_delayed_work(&port
->stats_work
, msecs_to_jiffies(1000));
377 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
379 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
380 struct net_device
*dev
= pr
->port
->netdev
;
381 int max_index_mask
= pr
->rq1_skba
.len
- 1;
382 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
386 pr
->rq1_skba
.os_skbs
= 0;
388 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
390 pr
->rq1_skba
.index
= index
;
391 pr
->rq1_skba
.os_skbs
= fill_wqes
;
395 for (i
= 0; i
< fill_wqes
; i
++) {
396 if (!skb_arr_rq1
[index
]) {
397 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
399 if (!skb_arr_rq1
[index
]) {
400 netdev_info(dev
, "Unable to allocate enough skb in the array\n");
401 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
406 index
&= max_index_mask
;
414 ehea_update_rq1a(pr
->qp
, adder
);
417 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
419 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
420 struct net_device
*dev
= pr
->port
->netdev
;
423 if (nr_rq1a
> pr
->rq1_skba
.len
) {
424 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
428 for (i
= 0; i
< nr_rq1a
; i
++) {
429 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
430 if (!skb_arr_rq1
[i
]) {
431 netdev_info(dev
, "Not enough memory to allocate skb array\n");
436 ehea_update_rq1a(pr
->qp
, i
- 1);
439 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
440 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
441 int num_wqes
, int wqe_type
, int packet_size
)
443 struct net_device
*dev
= pr
->port
->netdev
;
444 struct ehea_qp
*qp
= pr
->qp
;
445 struct sk_buff
**skb_arr
= q_skba
->arr
;
446 struct ehea_rwqe
*rwqe
;
447 int i
, index
, max_index_mask
, fill_wqes
;
451 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
454 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
455 q_skba
->os_skbs
= fill_wqes
;
459 index
= q_skba
->index
;
460 max_index_mask
= q_skba
->len
- 1;
461 for (i
= 0; i
< fill_wqes
; i
++) {
465 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
467 q_skba
->os_skbs
= fill_wqes
- i
;
468 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
469 netdev_info(pr
->port
->netdev
,
470 "rq%i ran dry - no mem for skb\n",
477 skb_arr
[index
] = skb
;
478 tmp_addr
= ehea_map_vaddr(skb
->data
);
479 if (tmp_addr
== -1) {
481 q_skba
->os_skbs
= fill_wqes
- i
;
486 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
487 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
488 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
489 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
490 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
491 rwqe
->sg_list
[0].len
= packet_size
;
492 rwqe
->data_segments
= 1;
495 index
&= max_index_mask
;
499 q_skba
->index
= index
;
506 ehea_update_rq2a(pr
->qp
, adder
);
508 ehea_update_rq3a(pr
->qp
, adder
);
514 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
516 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
517 nr_of_wqes
, EHEA_RWQE2_TYPE
,
522 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
524 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
525 nr_of_wqes
, EHEA_RWQE3_TYPE
,
526 EHEA_MAX_PACKET_SIZE
);
529 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
531 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
532 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
534 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
535 (cqe
->header_length
== 0))
540 static inline void ehea_fill_skb(struct net_device
*dev
,
541 struct sk_buff
*skb
, struct ehea_cqe
*cqe
,
542 struct ehea_port_res
*pr
)
544 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
546 skb_put(skb
, length
);
547 skb
->protocol
= eth_type_trans(skb
, dev
);
549 /* The packet was not an IPV4 packet so a complemented checksum was
550 calculated. The value is found in the Internet Checksum field. */
551 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
552 skb
->ip_summed
= CHECKSUM_COMPLETE
;
553 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
555 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
557 skb_record_rx_queue(skb
, pr
- &pr
->port
->port_res
[0]);
560 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
562 struct ehea_cqe
*cqe
)
564 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
575 prefetchw(pref
+ EHEA_CACHE_LINE
);
577 pref
= (skb_array
[x
]->data
);
579 prefetch(pref
+ EHEA_CACHE_LINE
);
580 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
581 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
584 skb
= skb_array
[skb_index
];
585 skb_array
[skb_index
] = NULL
;
589 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
590 int arr_len
, int wqe_index
)
602 prefetchw(pref
+ EHEA_CACHE_LINE
);
604 pref
= (skb_array
[x
]->data
);
606 prefetchw(pref
+ EHEA_CACHE_LINE
);
609 skb
= skb_array
[wqe_index
];
610 skb_array
[wqe_index
] = NULL
;
614 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
615 struct ehea_cqe
*cqe
, int *processed_rq2
,
620 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
621 pr
->p_stats
.err_tcp_cksum
++;
622 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
623 pr
->p_stats
.err_ip_cksum
++;
624 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
625 pr
->p_stats
.err_frame_crc
++;
629 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
631 } else if (rq
== 3) {
633 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
637 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
638 if (netif_msg_rx_err(pr
->port
)) {
639 pr_err("Critical receive error for QP %d. Resetting port.\n",
640 pr
->qp
->init_attr
.qp_nr
);
641 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
643 ehea_schedule_port_reset(pr
->port
);
650 static int ehea_proc_rwqes(struct net_device
*dev
,
651 struct ehea_port_res
*pr
,
654 struct ehea_port
*port
= pr
->port
;
655 struct ehea_qp
*qp
= pr
->qp
;
656 struct ehea_cqe
*cqe
;
658 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
659 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
660 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
661 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
662 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
663 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
664 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
665 u64 processed_bytes
= 0;
666 int wqe_index
, last_wqe_index
, rq
, port_reset
;
668 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
671 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
672 while ((processed
< budget
) && cqe
) {
676 if (netif_msg_rx_status(port
))
677 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
679 last_wqe_index
= wqe_index
;
681 if (!ehea_check_cqe(cqe
, &rq
)) {
684 skb
= get_skb_by_index_ll(skb_arr_rq1
,
687 if (unlikely(!skb
)) {
688 netif_info(port
, rx_err
, dev
,
689 "LL rq1: skb=NULL\n");
691 skb
= netdev_alloc_skb(dev
,
694 netdev_err(dev
, "Not enough memory to allocate skb\n");
698 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
699 cqe
->num_bytes_transfered
- 4);
700 ehea_fill_skb(dev
, skb
, cqe
, pr
);
701 } else if (rq
== 2) {
703 skb
= get_skb_by_index(skb_arr_rq2
,
704 skb_arr_rq2_len
, cqe
);
705 if (unlikely(!skb
)) {
706 netif_err(port
, rx_err
, dev
,
710 ehea_fill_skb(dev
, skb
, cqe
, pr
);
714 skb
= get_skb_by_index(skb_arr_rq3
,
715 skb_arr_rq3_len
, cqe
);
716 if (unlikely(!skb
)) {
717 netif_err(port
, rx_err
, dev
,
721 ehea_fill_skb(dev
, skb
, cqe
, pr
);
725 processed_bytes
+= skb
->len
;
727 if (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
728 __vlan_hwaccel_put_tag(skb
, cqe
->vlan_tag
);
730 napi_gro_receive(&pr
->napi
, skb
);
732 pr
->p_stats
.poll_receive_errors
++;
733 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
739 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
742 pr
->rx_packets
+= processed
;
743 pr
->rx_bytes
+= processed_bytes
;
745 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
746 ehea_refill_rq2(pr
, processed_rq2
);
747 ehea_refill_rq3(pr
, processed_rq3
);
752 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
754 static void reset_sq_restart_flag(struct ehea_port
*port
)
758 for (i
= 0; i
< port
->num_def_qps
; i
++) {
759 struct ehea_port_res
*pr
= &port
->port_res
[i
];
760 pr
->sq_restart_flag
= 0;
762 wake_up(&port
->restart_wq
);
765 static void check_sqs(struct ehea_port
*port
)
767 struct ehea_swqe
*swqe
;
771 for (i
= 0; i
< port
->num_def_qps
; i
++) {
772 struct ehea_port_res
*pr
= &port
->port_res
[i
];
775 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
776 memset(swqe
, 0, SWQE_HEADER_SIZE
);
777 atomic_dec(&pr
->swqe_avail
);
779 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
780 swqe
->wr_id
= SWQE_RESTART_CHECK
;
781 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
782 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
783 swqe
->immediate_data_length
= 80;
785 ehea_post_swqe(pr
->qp
, swqe
);
787 ret
= wait_event_timeout(port
->restart_wq
,
788 pr
->sq_restart_flag
== 0,
789 msecs_to_jiffies(100));
792 pr_err("HW/SW queues out of sync\n");
793 ehea_schedule_port_reset(pr
->port
);
800 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
803 struct ehea_cq
*send_cq
= pr
->send_cq
;
804 struct ehea_cqe
*cqe
;
805 int quota
= my_quota
;
809 struct netdev_queue
*txq
= netdev_get_tx_queue(pr
->port
->netdev
,
810 pr
- &pr
->port
->port_res
[0]);
812 cqe
= ehea_poll_cq(send_cq
);
813 while (cqe
&& (quota
> 0)) {
814 ehea_inc_cq(send_cq
);
819 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
820 pr
->sq_restart_flag
= 1;
825 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
826 pr_err("Bad send completion status=0x%04X\n",
829 if (netif_msg_tx_err(pr
->port
))
830 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
832 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
833 pr_err("Resetting port\n");
834 ehea_schedule_port_reset(pr
->port
);
839 if (netif_msg_tx_done(pr
->port
))
840 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
842 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
843 == EHEA_SWQE2_TYPE
)) {
845 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
846 skb
= pr
->sq_skba
.arr
[index
];
848 pr
->sq_skba
.arr
[index
] = NULL
;
851 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
854 cqe
= ehea_poll_cq(send_cq
);
857 ehea_update_feca(send_cq
, cqe_counter
);
858 atomic_add(swqe_av
, &pr
->swqe_avail
);
860 if (unlikely(netif_tx_queue_stopped(txq
) &&
861 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))) {
862 __netif_tx_lock(txq
, smp_processor_id());
863 if (netif_tx_queue_stopped(txq
) &&
864 (atomic_read(&pr
->swqe_avail
) >= pr
->swqe_refill_th
))
865 netif_tx_wake_queue(txq
);
866 __netif_tx_unlock(txq
);
869 wake_up(&pr
->port
->swqe_avail_wq
);
874 #define EHEA_POLL_MAX_CQES 65535
876 static int ehea_poll(struct napi_struct
*napi
, int budget
)
878 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
880 struct net_device
*dev
= pr
->port
->netdev
;
881 struct ehea_cqe
*cqe
;
882 struct ehea_cqe
*cqe_skb
= NULL
;
886 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
887 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
889 while (rx
!= budget
) {
891 ehea_reset_cq_ep(pr
->recv_cq
);
892 ehea_reset_cq_ep(pr
->send_cq
);
893 ehea_reset_cq_n1(pr
->recv_cq
);
894 ehea_reset_cq_n1(pr
->send_cq
);
896 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
897 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
899 if (!cqe
&& !cqe_skb
)
902 if (!napi_reschedule(napi
))
905 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
906 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
912 #ifdef CONFIG_NET_POLL_CONTROLLER
913 static void ehea_netpoll(struct net_device
*dev
)
915 struct ehea_port
*port
= netdev_priv(dev
);
918 for (i
= 0; i
< port
->num_def_qps
; i
++)
919 napi_schedule(&port
->port_res
[i
].napi
);
923 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
925 struct ehea_port_res
*pr
= param
;
927 napi_schedule(&pr
->napi
);
932 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
934 struct ehea_port
*port
= param
;
935 struct ehea_eqe
*eqe
;
938 u64 resource_type
, aer
, aerr
;
941 eqe
= ehea_poll_eq(port
->qp_eq
);
944 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
945 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
946 eqe
->entry
, qp_token
);
948 qp
= port
->port_res
[qp_token
].qp
;
950 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
953 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
954 if ((aer
& EHEA_AER_RESET_MASK
) ||
955 (aerr
& EHEA_AERR_RESET_MASK
))
958 reset_port
= 1; /* Reset in case of CQ or EQ error */
960 eqe
= ehea_poll_eq(port
->qp_eq
);
964 pr_err("Resetting port\n");
965 ehea_schedule_port_reset(port
);
971 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
976 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
977 if (adapter
->port
[i
])
978 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
979 return adapter
->port
[i
];
983 int ehea_sense_port_attr(struct ehea_port
*port
)
987 struct hcp_ehea_port_cb0
*cb0
;
989 /* may be called via ehea_neq_tasklet() */
990 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
992 pr_err("no mem for cb0\n");
997 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
998 port
->logical_port_id
, H_PORT_CB0
,
999 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1001 if (hret
!= H_SUCCESS
) {
1007 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1009 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1010 ret
= -EADDRNOTAVAIL
;
1015 switch (cb0
->port_speed
) {
1017 port
->port_speed
= EHEA_SPEED_10M
;
1018 port
->full_duplex
= 0;
1021 port
->port_speed
= EHEA_SPEED_10M
;
1022 port
->full_duplex
= 1;
1024 case H_SPEED_100M_H
:
1025 port
->port_speed
= EHEA_SPEED_100M
;
1026 port
->full_duplex
= 0;
1028 case H_SPEED_100M_F
:
1029 port
->port_speed
= EHEA_SPEED_100M
;
1030 port
->full_duplex
= 1;
1033 port
->port_speed
= EHEA_SPEED_1G
;
1034 port
->full_duplex
= 1;
1037 port
->port_speed
= EHEA_SPEED_10G
;
1038 port
->full_duplex
= 1;
1041 port
->port_speed
= 0;
1042 port
->full_duplex
= 0;
1047 port
->num_mcs
= cb0
->num_default_qps
;
1049 /* Number of default QPs */
1051 port
->num_def_qps
= cb0
->num_default_qps
;
1053 port
->num_def_qps
= 1;
1055 if (!port
->num_def_qps
) {
1062 if (ret
|| netif_msg_probe(port
))
1063 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1064 free_page((unsigned long)cb0
);
1069 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1071 struct hcp_ehea_port_cb4
*cb4
;
1075 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1077 pr_err("no mem for cb4\n");
1082 cb4
->port_speed
= port_speed
;
1084 netif_carrier_off(port
->netdev
);
1086 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1087 port
->logical_port_id
,
1088 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1089 if (hret
== H_SUCCESS
) {
1090 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1092 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1093 port
->logical_port_id
,
1094 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1096 if (hret
== H_SUCCESS
) {
1097 switch (cb4
->port_speed
) {
1099 port
->port_speed
= EHEA_SPEED_10M
;
1100 port
->full_duplex
= 0;
1103 port
->port_speed
= EHEA_SPEED_10M
;
1104 port
->full_duplex
= 1;
1106 case H_SPEED_100M_H
:
1107 port
->port_speed
= EHEA_SPEED_100M
;
1108 port
->full_duplex
= 0;
1110 case H_SPEED_100M_F
:
1111 port
->port_speed
= EHEA_SPEED_100M
;
1112 port
->full_duplex
= 1;
1115 port
->port_speed
= EHEA_SPEED_1G
;
1116 port
->full_duplex
= 1;
1119 port
->port_speed
= EHEA_SPEED_10G
;
1120 port
->full_duplex
= 1;
1123 port
->port_speed
= 0;
1124 port
->full_duplex
= 0;
1128 pr_err("Failed sensing port speed\n");
1132 if (hret
== H_AUTHORITY
) {
1133 pr_info("Hypervisor denied setting port speed\n");
1137 pr_err("Failed setting port speed\n");
1140 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1141 netif_carrier_on(port
->netdev
);
1143 free_page((unsigned long)cb4
);
1148 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1153 struct ehea_port
*port
;
1154 struct net_device
*dev
;
1156 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1157 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1158 port
= ehea_get_port(adapter
, portnum
);
1162 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1165 netdev_err(dev
, "unknown portnum %x\n", portnum
);
1169 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1170 if (!netif_carrier_ok(dev
)) {
1171 ret
= ehea_sense_port_attr(port
);
1173 netdev_err(dev
, "failed resensing port attributes\n");
1177 netif_info(port
, link
, dev
,
1178 "Logical port up: %dMbps %s Duplex\n",
1180 port
->full_duplex
== 1 ?
1183 netif_carrier_on(dev
);
1184 netif_wake_queue(dev
);
1187 if (netif_carrier_ok(dev
)) {
1188 netif_info(port
, link
, dev
,
1189 "Logical port down\n");
1190 netif_carrier_off(dev
);
1191 netif_tx_disable(dev
);
1194 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1195 port
->phy_link
= EHEA_PHY_LINK_UP
;
1196 netif_info(port
, link
, dev
,
1197 "Physical port up\n");
1198 if (prop_carrier_state
)
1199 netif_carrier_on(dev
);
1201 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1202 netif_info(port
, link
, dev
,
1203 "Physical port down\n");
1204 if (prop_carrier_state
)
1205 netif_carrier_off(dev
);
1208 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1210 "External switch port is primary port\n");
1213 "External switch port is backup port\n");
1216 case EHEA_EC_ADAPTER_MALFUNC
:
1217 netdev_err(dev
, "Adapter malfunction\n");
1219 case EHEA_EC_PORT_MALFUNC
:
1220 netdev_info(dev
, "Port malfunction\n");
1221 netif_carrier_off(dev
);
1222 netif_tx_disable(dev
);
1225 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1230 static void ehea_neq_tasklet(unsigned long data
)
1232 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1233 struct ehea_eqe
*eqe
;
1236 eqe
= ehea_poll_eq(adapter
->neq
);
1237 pr_debug("eqe=%p\n", eqe
);
1240 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1241 ehea_parse_eqe(adapter
, eqe
->entry
);
1242 eqe
= ehea_poll_eq(adapter
->neq
);
1243 pr_debug("next eqe=%p\n", eqe
);
1246 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1247 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1248 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1250 ehea_h_reset_events(adapter
->handle
,
1251 adapter
->neq
->fw_handle
, event_mask
);
1254 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1256 struct ehea_adapter
*adapter
= param
;
1257 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1262 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1265 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1267 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1269 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1271 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1276 static int ehea_reg_interrupts(struct net_device
*dev
)
1278 struct ehea_port
*port
= netdev_priv(dev
);
1279 struct ehea_port_res
*pr
;
1283 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1286 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1287 ehea_qp_aff_irq_handler
,
1288 IRQF_DISABLED
, port
->int_aff_name
, port
);
1290 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1291 port
->qp_eq
->attr
.ist1
);
1295 netif_info(port
, ifup
, dev
,
1296 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1297 port
->qp_eq
->attr
.ist1
);
1300 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1301 pr
= &port
->port_res
[i
];
1302 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1303 "%s-queue%d", dev
->name
, i
);
1304 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1305 ehea_recv_irq_handler
,
1306 IRQF_DISABLED
, pr
->int_send_name
,
1309 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1310 i
, pr
->eq
->attr
.ist1
);
1313 netif_info(port
, ifup
, dev
,
1314 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1315 pr
->eq
->attr
.ist1
, i
);
1323 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1324 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1328 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1329 i
= port
->num_def_qps
;
1335 static void ehea_free_interrupts(struct net_device
*dev
)
1337 struct ehea_port
*port
= netdev_priv(dev
);
1338 struct ehea_port_res
*pr
;
1343 for (i
= 0; i
< port
->num_def_qps
; i
++) {
1344 pr
= &port
->port_res
[i
];
1345 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1346 netif_info(port
, intr
, dev
,
1347 "free send irq for res %d with handle 0x%X\n",
1348 i
, pr
->eq
->attr
.ist1
);
1351 /* associated events */
1352 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1353 netif_info(port
, intr
, dev
,
1354 "associated event interrupt for handle 0x%X freed\n",
1355 port
->qp_eq
->attr
.ist1
);
1358 static int ehea_configure_port(struct ehea_port
*port
)
1362 struct hcp_ehea_port_cb0
*cb0
;
1365 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1369 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1370 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1371 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1372 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1374 PXLY_RC_VLAN_FILTER
)
1375 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1377 for (i
= 0; i
< port
->num_mcs
; i
++)
1379 cb0
->default_qpn_arr
[i
] =
1380 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1382 cb0
->default_qpn_arr
[i
] =
1383 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1385 if (netif_msg_ifup(port
))
1386 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1388 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1389 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1391 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1392 port
->logical_port_id
,
1393 H_PORT_CB0
, mask
, cb0
);
1395 if (hret
!= H_SUCCESS
)
1401 free_page((unsigned long)cb0
);
1406 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1409 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1411 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1415 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1422 ehea_rem_mr(&pr
->send_mr
);
1424 pr_err("Generating SMRS failed\n");
1428 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1430 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1431 (ehea_rem_mr(&pr
->recv_mr
)))
1437 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1439 int arr_size
= sizeof(void *) * max_q_entries
;
1441 q_skba
->arr
= vzalloc(arr_size
);
1445 q_skba
->len
= max_q_entries
;
1447 q_skba
->os_skbs
= 0;
1452 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1453 struct port_res_cfg
*pr_cfg
, int queue_token
)
1455 struct ehea_adapter
*adapter
= port
->adapter
;
1456 enum ehea_eq_type eq_type
= EHEA_EQ
;
1457 struct ehea_qp_init_attr
*init_attr
= NULL
;
1459 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1461 tx_bytes
= pr
->tx_bytes
;
1462 tx_packets
= pr
->tx_packets
;
1463 rx_bytes
= pr
->rx_bytes
;
1464 rx_packets
= pr
->rx_packets
;
1466 memset(pr
, 0, sizeof(struct ehea_port_res
));
1468 pr
->tx_bytes
= rx_bytes
;
1469 pr
->tx_packets
= tx_packets
;
1470 pr
->rx_bytes
= rx_bytes
;
1471 pr
->rx_packets
= rx_packets
;
1475 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1477 pr_err("create_eq failed (eq)\n");
1481 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1483 port
->logical_port_id
);
1485 pr_err("create_cq failed (cq_recv)\n");
1489 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1491 port
->logical_port_id
);
1493 pr_err("create_cq failed (cq_send)\n");
1497 if (netif_msg_ifup(port
))
1498 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1499 pr
->send_cq
->attr
.act_nr_of_cqes
,
1500 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1502 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1505 pr_err("no mem for ehea_qp_init_attr\n");
1509 init_attr
->low_lat_rq1
= 1;
1510 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1511 init_attr
->rq_count
= 3;
1512 init_attr
->qp_token
= queue_token
;
1513 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1514 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1515 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1516 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1517 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1518 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1519 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1520 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1521 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1522 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1523 init_attr
->port_nr
= port
->logical_port_id
;
1524 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1525 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1526 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1528 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1530 pr_err("create_qp failed\n");
1535 if (netif_msg_ifup(port
))
1536 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",
1538 init_attr
->act_nr_send_wqes
,
1539 init_attr
->act_nr_rwqes_rq1
,
1540 init_attr
->act_nr_rwqes_rq2
,
1541 init_attr
->act_nr_rwqes_rq3
);
1543 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1545 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1546 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1547 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1548 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1552 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1553 if (ehea_gen_smrs(pr
) != 0) {
1558 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1562 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1569 vfree(pr
->sq_skba
.arr
);
1570 vfree(pr
->rq1_skba
.arr
);
1571 vfree(pr
->rq2_skba
.arr
);
1572 vfree(pr
->rq3_skba
.arr
);
1573 ehea_destroy_qp(pr
->qp
);
1574 ehea_destroy_cq(pr
->send_cq
);
1575 ehea_destroy_cq(pr
->recv_cq
);
1576 ehea_destroy_eq(pr
->eq
);
1581 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1586 netif_napi_del(&pr
->napi
);
1588 ret
= ehea_destroy_qp(pr
->qp
);
1591 ehea_destroy_cq(pr
->send_cq
);
1592 ehea_destroy_cq(pr
->recv_cq
);
1593 ehea_destroy_eq(pr
->eq
);
1595 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1596 if (pr
->rq1_skba
.arr
[i
])
1597 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1599 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1600 if (pr
->rq2_skba
.arr
[i
])
1601 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1603 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1604 if (pr
->rq3_skba
.arr
[i
])
1605 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1607 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1608 if (pr
->sq_skba
.arr
[i
])
1609 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1611 vfree(pr
->rq1_skba
.arr
);
1612 vfree(pr
->rq2_skba
.arr
);
1613 vfree(pr
->rq3_skba
.arr
);
1614 vfree(pr
->sq_skba
.arr
);
1615 ret
= ehea_rem_smrs(pr
);
1620 static void write_swqe2_immediate(struct sk_buff
*skb
, struct ehea_swqe
*swqe
,
1623 int skb_data_size
= skb_headlen(skb
);
1624 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1625 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1626 unsigned int immediate_len
= SWQE2_MAX_IMM
;
1628 swqe
->descriptors
= 0;
1630 if (skb_is_gso(skb
)) {
1631 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1632 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1634 * For TSO packets we only copy the headers into the
1637 immediate_len
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1640 if (skb_is_gso(skb
) || skb_data_size
>= SWQE2_MAX_IMM
) {
1641 skb_copy_from_linear_data(skb
, imm_data
, immediate_len
);
1642 swqe
->immediate_data_length
= immediate_len
;
1644 if (skb_data_size
> immediate_len
) {
1645 sg1entry
->l_key
= lkey
;
1646 sg1entry
->len
= skb_data_size
- immediate_len
;
1648 ehea_map_vaddr(skb
->data
+ immediate_len
);
1649 swqe
->descriptors
++;
1652 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1653 swqe
->immediate_data_length
= skb_data_size
;
1657 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1658 struct ehea_swqe
*swqe
, u32 lkey
)
1660 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1662 int nfrags
, sg1entry_contains_frag_data
, i
;
1664 nfrags
= skb_shinfo(skb
)->nr_frags
;
1665 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1666 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1667 sg1entry_contains_frag_data
= 0;
1669 write_swqe2_immediate(skb
, swqe
, lkey
);
1671 /* write descriptors */
1673 if (swqe
->descriptors
== 0) {
1674 /* sg1entry not yet used */
1675 frag
= &skb_shinfo(skb
)->frags
[0];
1677 /* copy sg1entry data */
1678 sg1entry
->l_key
= lkey
;
1679 sg1entry
->len
= skb_frag_size(frag
);
1681 ehea_map_vaddr(skb_frag_address(frag
));
1682 swqe
->descriptors
++;
1683 sg1entry_contains_frag_data
= 1;
1686 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1688 frag
= &skb_shinfo(skb
)->frags
[i
];
1689 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1691 sgentry
->l_key
= lkey
;
1692 sgentry
->len
= skb_frag_size(frag
);
1693 sgentry
->vaddr
= ehea_map_vaddr(skb_frag_address(frag
));
1694 swqe
->descriptors
++;
1699 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1705 /* De/Register untagged packets */
1706 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1707 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1708 port
->logical_port_id
,
1709 reg_type
, port
->mac_addr
, 0, hcallid
);
1710 if (hret
!= H_SUCCESS
) {
1711 pr_err("%sregistering bc address failed (tagged)\n",
1712 hcallid
== H_REG_BCMC
? "" : "de");
1717 /* De/Register VLAN packets */
1718 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1719 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1720 port
->logical_port_id
,
1721 reg_type
, port
->mac_addr
, 0, hcallid
);
1722 if (hret
!= H_SUCCESS
) {
1723 pr_err("%sregistering bc address failed (vlan)\n",
1724 hcallid
== H_REG_BCMC
? "" : "de");
1731 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1733 struct ehea_port
*port
= netdev_priv(dev
);
1734 struct sockaddr
*mac_addr
= sa
;
1735 struct hcp_ehea_port_cb0
*cb0
;
1739 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1740 ret
= -EADDRNOTAVAIL
;
1744 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1746 pr_err("no mem for cb0\n");
1751 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1753 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1755 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1756 port
->logical_port_id
, H_PORT_CB0
,
1757 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1758 if (hret
!= H_SUCCESS
) {
1763 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1765 /* Deregister old MAC in pHYP */
1766 if (port
->state
== EHEA_PORT_UP
) {
1767 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1772 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1774 /* Register new MAC in pHYP */
1775 if (port
->state
== EHEA_PORT_UP
) {
1776 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1784 ehea_update_bcmc_registrations();
1786 free_page((unsigned long)cb0
);
1791 static void ehea_promiscuous_error(u64 hret
, int enable
)
1793 if (hret
== H_AUTHORITY
)
1794 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1795 enable
== 1 ? "en" : "dis");
1797 pr_err("failed %sabling promiscuous mode\n",
1798 enable
== 1 ? "en" : "dis");
1801 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1803 struct ehea_port
*port
= netdev_priv(dev
);
1804 struct hcp_ehea_port_cb7
*cb7
;
1807 if (enable
== port
->promisc
)
1810 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1812 pr_err("no mem for cb7\n");
1816 /* Modify Pxs_DUCQPN in CB7 */
1817 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1819 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1820 port
->logical_port_id
,
1821 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1823 ehea_promiscuous_error(hret
, enable
);
1827 port
->promisc
= enable
;
1829 free_page((unsigned long)cb7
);
1832 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1838 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1839 | EHEA_BCMC_UNTAGGED
;
1841 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1842 port
->logical_port_id
,
1843 reg_type
, mc_mac_addr
, 0, hcallid
);
1847 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1848 | EHEA_BCMC_VLANID_ALL
;
1850 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1851 port
->logical_port_id
,
1852 reg_type
, mc_mac_addr
, 0, hcallid
);
1857 static int ehea_drop_multicast_list(struct net_device
*dev
)
1859 struct ehea_port
*port
= netdev_priv(dev
);
1860 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1861 struct list_head
*pos
;
1862 struct list_head
*temp
;
1866 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1867 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1869 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1872 pr_err("failed deregistering mcast MAC\n");
1882 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1884 struct ehea_port
*port
= netdev_priv(dev
);
1887 if (!port
->allmulti
) {
1889 /* Enable ALLMULTI */
1890 ehea_drop_multicast_list(dev
);
1891 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1896 "failed enabling IFF_ALLMULTI\n");
1900 /* Disable ALLMULTI */
1901 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1906 "failed disabling IFF_ALLMULTI\n");
1910 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1912 struct ehea_mc_list
*ehea_mcl_entry
;
1915 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1916 if (!ehea_mcl_entry
) {
1917 pr_err("no mem for mcl_entry\n");
1921 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1923 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1925 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1928 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1930 pr_err("failed registering mcast MAC\n");
1931 kfree(ehea_mcl_entry
);
1935 static void ehea_set_multicast_list(struct net_device
*dev
)
1937 struct ehea_port
*port
= netdev_priv(dev
);
1938 struct netdev_hw_addr
*ha
;
1941 if (port
->promisc
) {
1942 ehea_promiscuous(dev
, 1);
1945 ehea_promiscuous(dev
, 0);
1947 if (dev
->flags
& IFF_ALLMULTI
) {
1948 ehea_allmulti(dev
, 1);
1951 ehea_allmulti(dev
, 0);
1953 if (!netdev_mc_empty(dev
)) {
1954 ret
= ehea_drop_multicast_list(dev
);
1956 /* Dropping the current multicast list failed.
1957 * Enabling ALL_MULTI is the best we can do.
1959 ehea_allmulti(dev
, 1);
1962 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
1963 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1964 port
->adapter
->max_mc_mac
);
1968 netdev_for_each_mc_addr(ha
, dev
)
1969 ehea_add_multicast_entry(port
, ha
->addr
);
1973 ehea_update_bcmc_registrations();
1976 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
1978 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
1984 static void xmit_common(struct sk_buff
*skb
, struct ehea_swqe
*swqe
)
1986 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
| EHEA_SWQE_CRC
;
1988 if (skb
->protocol
!= htons(ETH_P_IP
))
1991 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1992 swqe
->tx_control
|= EHEA_SWQE_IP_CHECKSUM
;
1994 swqe
->ip_start
= skb_network_offset(skb
);
1995 swqe
->ip_end
= swqe
->ip_start
+ ip_hdrlen(skb
) - 1;
1997 switch (ip_hdr(skb
)->protocol
) {
1999 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2000 swqe
->tx_control
|= EHEA_SWQE_TCP_CHECKSUM
;
2002 swqe
->tcp_offset
= swqe
->ip_end
+ 1 +
2003 offsetof(struct udphdr
, check
);
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 tcphdr
, check
);
2016 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2017 struct ehea_swqe
*swqe
, u32 lkey
)
2019 swqe
->tx_control
|= EHEA_SWQE_DESCRIPTORS_PRESENT
;
2021 xmit_common(skb
, swqe
);
2023 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2026 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2027 struct ehea_swqe
*swqe
)
2029 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2031 xmit_common(skb
, swqe
);
2034 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2036 skb_copy_bits(skb
, 0, imm_data
, skb
->len
);
2038 swqe
->immediate_data_length
= skb
->len
;
2042 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2044 struct ehea_port
*port
= netdev_priv(dev
);
2045 struct ehea_swqe
*swqe
;
2048 struct ehea_port_res
*pr
;
2049 struct netdev_queue
*txq
;
2051 pr
= &port
->port_res
[skb_get_queue_mapping(skb
)];
2052 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
2054 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2055 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2056 atomic_dec(&pr
->swqe_avail
);
2058 if (vlan_tx_tag_present(skb
)) {
2059 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2060 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2064 pr
->tx_bytes
+= skb
->len
;
2066 if (skb
->len
<= SWQE3_MAX_IMM
) {
2067 u32 sig_iv
= port
->sig_comp_iv
;
2068 u32 swqe_num
= pr
->swqe_id_counter
;
2069 ehea_xmit3(skb
, dev
, swqe
);
2070 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2071 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2072 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2073 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2075 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2076 pr
->swqe_ll_count
= 0;
2078 pr
->swqe_ll_count
+= 1;
2081 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2082 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2083 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2084 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2085 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2087 pr
->sq_skba
.index
++;
2088 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2090 lkey
= pr
->send_mr
.lkey
;
2091 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2092 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2094 pr
->swqe_id_counter
+= 1;
2096 netif_info(port
, tx_queued
, dev
,
2097 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2098 if (netif_msg_tx_queued(port
))
2099 ehea_dump(swqe
, 512, "swqe");
2101 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2102 netif_tx_stop_queue(txq
);
2103 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2106 ehea_post_swqe(pr
->qp
, swqe
);
2108 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2109 pr
->p_stats
.queue_stopped
++;
2110 netif_tx_stop_queue(txq
);
2113 return NETDEV_TX_OK
;
2116 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2118 struct ehea_port
*port
= netdev_priv(dev
);
2119 struct ehea_adapter
*adapter
= port
->adapter
;
2120 struct hcp_ehea_port_cb1
*cb1
;
2124 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2126 pr_err("no mem for cb1\n");
2130 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2131 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2132 if (hret
!= H_SUCCESS
) {
2133 pr_err("query_ehea_port failed\n");
2138 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2140 hret
= ehea_h_modify_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("modify_ehea_port failed\n");
2145 free_page((unsigned long)cb1
);
2149 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2151 struct ehea_port
*port
= netdev_priv(dev
);
2152 struct ehea_adapter
*adapter
= port
->adapter
;
2153 struct hcp_ehea_port_cb1
*cb1
;
2157 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2159 pr_err("no mem for cb1\n");
2163 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2164 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2165 if (hret
!= H_SUCCESS
) {
2166 pr_err("query_ehea_port failed\n");
2171 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2173 hret
= ehea_h_modify_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("modify_ehea_port failed\n");
2178 free_page((unsigned long)cb1
);
2181 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2187 struct hcp_modify_qp_cb0
*cb0
;
2189 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2195 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2196 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2197 if (hret
!= H_SUCCESS
) {
2198 pr_err("query_ehea_qp failed (1)\n");
2202 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2203 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2204 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2205 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2206 if (hret
!= H_SUCCESS
) {
2207 pr_err("modify_ehea_qp failed (1)\n");
2211 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2212 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2213 if (hret
!= H_SUCCESS
) {
2214 pr_err("query_ehea_qp failed (2)\n");
2218 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2219 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2220 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2221 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2222 if (hret
!= H_SUCCESS
) {
2223 pr_err("modify_ehea_qp failed (2)\n");
2227 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2228 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2229 if (hret
!= H_SUCCESS
) {
2230 pr_err("query_ehea_qp failed (3)\n");
2234 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2235 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2236 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2237 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2238 if (hret
!= H_SUCCESS
) {
2239 pr_err("modify_ehea_qp failed (3)\n");
2243 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2244 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2245 if (hret
!= H_SUCCESS
) {
2246 pr_err("query_ehea_qp failed (4)\n");
2252 free_page((unsigned long)cb0
);
2256 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
)
2259 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2260 enum ehea_eq_type eq_type
= EHEA_EQ
;
2262 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2263 EHEA_MAX_ENTRIES_EQ
, 1);
2266 pr_err("ehea_create_eq failed (qp_eq)\n");
2270 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2271 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2272 pr_cfg
.max_entries_sq
= sq_entries
;
2273 pr_cfg
.max_entries_rq1
= rq1_entries
;
2274 pr_cfg
.max_entries_rq2
= rq2_entries
;
2275 pr_cfg
.max_entries_rq3
= rq3_entries
;
2277 pr_cfg_small_rx
.max_entries_rcq
= 1;
2278 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2279 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2280 pr_cfg_small_rx
.max_entries_rq1
= 1;
2281 pr_cfg_small_rx
.max_entries_rq2
= 1;
2282 pr_cfg_small_rx
.max_entries_rq3
= 1;
2284 for (i
= 0; i
< def_qps
; i
++) {
2285 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2289 for (i
= def_qps
; i
< def_qps
; i
++) {
2290 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2291 &pr_cfg_small_rx
, i
);
2300 ehea_clean_portres(port
, &port
->port_res
[i
]);
2303 ehea_destroy_eq(port
->qp_eq
);
2307 static int ehea_clean_all_portres(struct ehea_port
*port
)
2312 for (i
= 0; i
< port
->num_def_qps
; i
++)
2313 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2315 ret
|= ehea_destroy_eq(port
->qp_eq
);
2320 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2322 if (adapter
->active_ports
)
2325 ehea_rem_mr(&adapter
->mr
);
2328 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2330 if (adapter
->active_ports
)
2333 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2336 static int ehea_up(struct net_device
*dev
)
2339 struct ehea_port
*port
= netdev_priv(dev
);
2341 if (port
->state
== EHEA_PORT_UP
)
2344 ret
= ehea_port_res_setup(port
, port
->num_def_qps
);
2346 netdev_err(dev
, "port_res_failed\n");
2350 /* Set default QP for this port */
2351 ret
= ehea_configure_port(port
);
2353 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2357 ret
= ehea_reg_interrupts(dev
);
2359 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2363 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2364 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2366 netdev_err(dev
, "activate_qp failed\n");
2371 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2372 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2374 netdev_err(dev
, "out_free_irqs\n");
2379 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2385 port
->state
= EHEA_PORT_UP
;
2391 ehea_free_interrupts(dev
);
2394 ehea_clean_all_portres(port
);
2397 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2399 ehea_update_bcmc_registrations();
2400 ehea_update_firmware_handles();
2405 static void port_napi_disable(struct ehea_port
*port
)
2409 for (i
= 0; i
< port
->num_def_qps
; i
++)
2410 napi_disable(&port
->port_res
[i
].napi
);
2413 static void port_napi_enable(struct ehea_port
*port
)
2417 for (i
= 0; i
< port
->num_def_qps
; i
++)
2418 napi_enable(&port
->port_res
[i
].napi
);
2421 static int ehea_open(struct net_device
*dev
)
2424 struct ehea_port
*port
= netdev_priv(dev
);
2426 mutex_lock(&port
->port_lock
);
2428 netif_info(port
, ifup
, dev
, "enabling port\n");
2432 port_napi_enable(port
);
2433 netif_tx_start_all_queues(dev
);
2436 mutex_unlock(&port
->port_lock
);
2437 schedule_delayed_work(&port
->stats_work
, msecs_to_jiffies(1000));
2442 static int ehea_down(struct net_device
*dev
)
2445 struct ehea_port
*port
= netdev_priv(dev
);
2447 if (port
->state
== EHEA_PORT_DOWN
)
2450 ehea_drop_multicast_list(dev
);
2451 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2453 ehea_free_interrupts(dev
);
2455 port
->state
= EHEA_PORT_DOWN
;
2457 ehea_update_bcmc_registrations();
2459 ret
= ehea_clean_all_portres(port
);
2461 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2463 ehea_update_firmware_handles();
2468 static int ehea_stop(struct net_device
*dev
)
2471 struct ehea_port
*port
= netdev_priv(dev
);
2473 netif_info(port
, ifdown
, dev
, "disabling port\n");
2475 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2476 cancel_work_sync(&port
->reset_task
);
2477 cancel_delayed_work_sync(&port
->stats_work
);
2478 mutex_lock(&port
->port_lock
);
2479 netif_tx_stop_all_queues(dev
);
2480 port_napi_disable(port
);
2481 ret
= ehea_down(dev
);
2482 mutex_unlock(&port
->port_lock
);
2483 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2487 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2489 struct ehea_qp qp
= *orig_qp
;
2490 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2491 struct ehea_swqe
*swqe
;
2495 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2496 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2497 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2501 static void ehea_flush_sq(struct ehea_port
*port
)
2505 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2506 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2507 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2510 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2511 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2512 msecs_to_jiffies(100));
2515 pr_err("WARNING: sq not flushed completely\n");
2521 int ehea_stop_qps(struct net_device
*dev
)
2523 struct ehea_port
*port
= netdev_priv(dev
);
2524 struct ehea_adapter
*adapter
= port
->adapter
;
2525 struct hcp_modify_qp_cb0
*cb0
;
2533 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2539 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2540 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2541 struct ehea_qp
*qp
= pr
->qp
;
2543 /* Purge send queue */
2546 /* Disable queue pair */
2547 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2548 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2550 if (hret
!= H_SUCCESS
) {
2551 pr_err("query_ehea_qp failed (1)\n");
2555 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2556 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2558 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2559 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2561 &dummy64
, &dummy16
, &dummy16
);
2562 if (hret
!= H_SUCCESS
) {
2563 pr_err("modify_ehea_qp failed (1)\n");
2567 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2568 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2570 if (hret
!= H_SUCCESS
) {
2571 pr_err("query_ehea_qp failed (2)\n");
2575 /* deregister shared memory regions */
2576 dret
= ehea_rem_smrs(pr
);
2578 pr_err("unreg shared memory region failed\n");
2585 free_page((unsigned long)cb0
);
2590 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2592 struct ehea_qp qp
= *orig_qp
;
2593 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2594 struct ehea_rwqe
*rwqe
;
2595 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2596 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2597 struct sk_buff
*skb
;
2598 u32 lkey
= pr
->recv_mr
.lkey
;
2604 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2605 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2606 rwqe
->sg_list
[0].l_key
= lkey
;
2607 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2608 skb
= skba_rq2
[index
];
2610 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2613 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2614 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2615 rwqe
->sg_list
[0].l_key
= lkey
;
2616 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2617 skb
= skba_rq3
[index
];
2619 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2623 int ehea_restart_qps(struct net_device
*dev
)
2625 struct ehea_port
*port
= netdev_priv(dev
);
2626 struct ehea_adapter
*adapter
= port
->adapter
;
2630 struct hcp_modify_qp_cb0
*cb0
;
2635 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2641 for (i
= 0; i
< (port
->num_def_qps
); i
++) {
2642 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2643 struct ehea_qp
*qp
= pr
->qp
;
2645 ret
= ehea_gen_smrs(pr
);
2647 netdev_err(dev
, "creation of shared memory regions failed\n");
2651 ehea_update_rqs(qp
, pr
);
2653 /* Enable queue pair */
2654 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2655 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2657 if (hret
!= H_SUCCESS
) {
2658 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2662 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2663 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2665 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2666 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2668 &dummy64
, &dummy16
, &dummy16
);
2669 if (hret
!= H_SUCCESS
) {
2670 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2674 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2675 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2677 if (hret
!= H_SUCCESS
) {
2678 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2682 /* refill entire queue */
2683 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2684 ehea_refill_rq2(pr
, 0);
2685 ehea_refill_rq3(pr
, 0);
2688 free_page((unsigned long)cb0
);
2693 static void ehea_reset_port(struct work_struct
*work
)
2696 struct ehea_port
*port
=
2697 container_of(work
, struct ehea_port
, reset_task
);
2698 struct net_device
*dev
= port
->netdev
;
2700 mutex_lock(&dlpar_mem_lock
);
2702 mutex_lock(&port
->port_lock
);
2703 netif_tx_disable(dev
);
2705 port_napi_disable(port
);
2713 ehea_set_multicast_list(dev
);
2715 netif_info(port
, timer
, dev
, "reset successful\n");
2717 port_napi_enable(port
);
2719 netif_tx_wake_all_queues(dev
);
2721 mutex_unlock(&port
->port_lock
);
2722 mutex_unlock(&dlpar_mem_lock
);
2725 static void ehea_rereg_mrs(void)
2728 struct ehea_adapter
*adapter
;
2730 pr_info("LPAR memory changed - re-initializing driver\n");
2732 list_for_each_entry(adapter
, &adapter_list
, list
)
2733 if (adapter
->active_ports
) {
2734 /* Shutdown all ports */
2735 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2736 struct ehea_port
*port
= adapter
->port
[i
];
2737 struct net_device
*dev
;
2744 if (dev
->flags
& IFF_UP
) {
2745 mutex_lock(&port
->port_lock
);
2746 netif_tx_disable(dev
);
2747 ehea_flush_sq(port
);
2748 ret
= ehea_stop_qps(dev
);
2750 mutex_unlock(&port
->port_lock
);
2753 port_napi_disable(port
);
2754 mutex_unlock(&port
->port_lock
);
2756 reset_sq_restart_flag(port
);
2759 /* Unregister old memory region */
2760 ret
= ehea_rem_mr(&adapter
->mr
);
2762 pr_err("unregister MR failed - driver inoperable!\n");
2767 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2769 list_for_each_entry(adapter
, &adapter_list
, list
)
2770 if (adapter
->active_ports
) {
2771 /* Register new memory region */
2772 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2774 pr_err("register MR failed - driver inoperable!\n");
2778 /* Restart all ports */
2779 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2780 struct ehea_port
*port
= adapter
->port
[i
];
2783 struct net_device
*dev
= port
->netdev
;
2785 if (dev
->flags
& IFF_UP
) {
2786 mutex_lock(&port
->port_lock
);
2787 ret
= ehea_restart_qps(dev
);
2790 port_napi_enable(port
);
2791 netif_tx_wake_all_queues(dev
);
2793 netdev_err(dev
, "Unable to restart QPS\n");
2795 mutex_unlock(&port
->port_lock
);
2800 pr_info("re-initializing driver complete\n");
2805 static void ehea_tx_watchdog(struct net_device
*dev
)
2807 struct ehea_port
*port
= netdev_priv(dev
);
2809 if (netif_carrier_ok(dev
) &&
2810 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2811 ehea_schedule_port_reset(port
);
2814 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2816 struct hcp_query_ehea
*cb
;
2820 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2826 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2828 if (hret
!= H_SUCCESS
) {
2833 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2837 free_page((unsigned long)cb
);
2842 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2844 struct hcp_ehea_port_cb4
*cb4
;
2850 /* (Try to) enable *jumbo frames */
2851 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2853 pr_err("no mem for cb4\n");
2857 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2858 port
->logical_port_id
,
2860 H_PORT_CB4_JUMBO
, cb4
);
2861 if (hret
== H_SUCCESS
) {
2862 if (cb4
->jumbo_frame
)
2865 cb4
->jumbo_frame
= 1;
2866 hret
= ehea_h_modify_ehea_port(port
->adapter
->
2873 if (hret
== H_SUCCESS
)
2879 free_page((unsigned long)cb4
);
2885 static ssize_t
ehea_show_port_id(struct device
*dev
,
2886 struct device_attribute
*attr
, char *buf
)
2888 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2889 return sprintf(buf
, "%d", port
->logical_port_id
);
2892 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
2895 static void __devinit
logical_port_release(struct device
*dev
)
2897 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
2898 of_node_put(port
->ofdev
.dev
.of_node
);
2901 static struct device
*ehea_register_port(struct ehea_port
*port
,
2902 struct device_node
*dn
)
2906 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
2907 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
2908 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
2910 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
2911 port
->ofdev
.dev
.release
= logical_port_release
;
2913 ret
= of_device_register(&port
->ofdev
);
2915 pr_err("failed to register device. ret=%d\n", ret
);
2919 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2921 pr_err("failed to register attributes, ret=%d\n", ret
);
2922 goto out_unreg_of_dev
;
2925 return &port
->ofdev
.dev
;
2928 of_device_unregister(&port
->ofdev
);
2933 static void ehea_unregister_port(struct ehea_port
*port
)
2935 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
2936 of_device_unregister(&port
->ofdev
);
2939 static const struct net_device_ops ehea_netdev_ops
= {
2940 .ndo_open
= ehea_open
,
2941 .ndo_stop
= ehea_stop
,
2942 .ndo_start_xmit
= ehea_start_xmit
,
2943 #ifdef CONFIG_NET_POLL_CONTROLLER
2944 .ndo_poll_controller
= ehea_netpoll
,
2946 .ndo_get_stats64
= ehea_get_stats64
,
2947 .ndo_set_mac_address
= ehea_set_mac_addr
,
2948 .ndo_validate_addr
= eth_validate_addr
,
2949 .ndo_set_rx_mode
= ehea_set_multicast_list
,
2950 .ndo_change_mtu
= ehea_change_mtu
,
2951 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
2952 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
2953 .ndo_tx_timeout
= ehea_tx_watchdog
,
2956 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
2957 u32 logical_port_id
,
2958 struct device_node
*dn
)
2961 struct net_device
*dev
;
2962 struct ehea_port
*port
;
2963 struct device
*port_dev
;
2966 /* allocate memory for the port structures */
2967 dev
= alloc_etherdev_mq(sizeof(struct ehea_port
), EHEA_MAX_PORT_RES
);
2970 pr_err("no mem for net_device\n");
2975 port
= netdev_priv(dev
);
2977 mutex_init(&port
->port_lock
);
2978 port
->state
= EHEA_PORT_DOWN
;
2979 port
->sig_comp_iv
= sq_entries
/ 10;
2981 port
->adapter
= adapter
;
2983 port
->logical_port_id
= logical_port_id
;
2985 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
2987 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
2988 if (!port
->mc_list
) {
2990 goto out_free_ethdev
;
2993 INIT_LIST_HEAD(&port
->mc_list
->list
);
2995 ret
= ehea_sense_port_attr(port
);
2997 goto out_free_mc_list
;
2999 netif_set_real_num_rx_queues(dev
, port
->num_def_qps
);
3000 netif_set_real_num_tx_queues(dev
, port
->num_def_qps
);
3002 port_dev
= ehea_register_port(port
, dn
);
3004 goto out_free_mc_list
;
3006 SET_NETDEV_DEV(dev
, port_dev
);
3008 /* initialize net_device structure */
3009 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3011 dev
->netdev_ops
= &ehea_netdev_ops
;
3012 ehea_set_ethtool_ops(dev
);
3014 dev
->hw_features
= NETIF_F_SG
| NETIF_F_TSO
3015 | NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
| NETIF_F_LRO
;
3016 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3017 | NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
3018 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3020 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HIGHDMA
|
3022 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3024 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3025 INIT_DELAYED_WORK(&port
->stats_work
, ehea_update_stats
);
3027 init_waitqueue_head(&port
->swqe_avail_wq
);
3028 init_waitqueue_head(&port
->restart_wq
);
3030 memset(&port
->stats
, 0, sizeof(struct net_device_stats
));
3031 ret
= register_netdev(dev
);
3033 pr_err("register_netdev failed. ret=%d\n", ret
);
3034 goto out_unreg_port
;
3037 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3039 netdev_err(dev
, "failed determining jumbo frame status\n");
3041 netdev_info(dev
, "Jumbo frames are %sabled\n",
3042 jumbo
== 1 ? "en" : "dis");
3044 adapter
->active_ports
++;
3049 ehea_unregister_port(port
);
3052 kfree(port
->mc_list
);
3058 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3059 logical_port_id
, ret
);
3063 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3065 struct ehea_adapter
*adapter
= port
->adapter
;
3067 cancel_work_sync(&port
->reset_task
);
3068 cancel_delayed_work_sync(&port
->stats_work
);
3069 unregister_netdev(port
->netdev
);
3070 ehea_unregister_port(port
);
3071 kfree(port
->mc_list
);
3072 free_netdev(port
->netdev
);
3073 adapter
->active_ports
--;
3076 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3078 struct device_node
*lhea_dn
;
3079 struct device_node
*eth_dn
= NULL
;
3081 const u32
*dn_log_port_id
;
3084 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3085 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3087 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3089 if (!dn_log_port_id
) {
3090 pr_err("bad device node: eth_dn name=%s\n",
3095 if (ehea_add_adapter_mr(adapter
)) {
3096 pr_err("creating MR failed\n");
3097 of_node_put(eth_dn
);
3101 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3104 if (adapter
->port
[i
])
3105 netdev_info(adapter
->port
[i
]->netdev
,
3106 "logical port id #%d\n", *dn_log_port_id
);
3108 ehea_remove_adapter_mr(adapter
);
3115 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3116 u32 logical_port_id
)
3118 struct device_node
*lhea_dn
;
3119 struct device_node
*eth_dn
= NULL
;
3120 const u32
*dn_log_port_id
;
3122 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3123 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3125 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3128 if (*dn_log_port_id
== logical_port_id
)
3135 static ssize_t
ehea_probe_port(struct device
*dev
,
3136 struct device_attribute
*attr
,
3137 const char *buf
, size_t count
)
3139 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3140 struct ehea_port
*port
;
3141 struct device_node
*eth_dn
= NULL
;
3144 u32 logical_port_id
;
3146 sscanf(buf
, "%d", &logical_port_id
);
3148 port
= ehea_get_port(adapter
, logical_port_id
);
3151 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3156 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3159 pr_info("no logical port with id %d found\n", logical_port_id
);
3163 if (ehea_add_adapter_mr(adapter
)) {
3164 pr_err("creating MR failed\n");
3168 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3170 of_node_put(eth_dn
);
3173 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3174 if (!adapter
->port
[i
]) {
3175 adapter
->port
[i
] = port
;
3179 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3182 ehea_remove_adapter_mr(adapter
);
3186 return (ssize_t
) count
;
3189 static ssize_t
ehea_remove_port(struct device
*dev
,
3190 struct device_attribute
*attr
,
3191 const char *buf
, size_t count
)
3193 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3194 struct ehea_port
*port
;
3196 u32 logical_port_id
;
3198 sscanf(buf
, "%d", &logical_port_id
);
3200 port
= ehea_get_port(adapter
, logical_port_id
);
3203 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3206 ehea_shutdown_single_port(port
);
3208 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3209 if (adapter
->port
[i
] == port
) {
3210 adapter
->port
[i
] = NULL
;
3214 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3219 ehea_remove_adapter_mr(adapter
);
3221 return (ssize_t
) count
;
3224 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3225 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3227 int ehea_create_device_sysfs(struct platform_device
*dev
)
3229 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3233 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3238 void ehea_remove_device_sysfs(struct platform_device
*dev
)
3240 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3241 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3244 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
3245 const struct of_device_id
*id
)
3247 struct ehea_adapter
*adapter
;
3248 const u64
*adapter_handle
;
3251 if (!dev
|| !dev
->dev
.of_node
) {
3252 pr_err("Invalid ibmebus device probed\n");
3256 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3259 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3263 list_add(&adapter
->list
, &adapter_list
);
3265 adapter
->ofdev
= dev
;
3267 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3270 adapter
->handle
= *adapter_handle
;
3272 if (!adapter
->handle
) {
3273 dev_err(&dev
->dev
, "failed getting handle for adapter"
3274 " '%s'\n", dev
->dev
.of_node
->full_name
);
3279 adapter
->pd
= EHEA_PD_ID
;
3281 dev_set_drvdata(&dev
->dev
, adapter
);
3284 /* initialize adapter and ports */
3285 /* get adapter properties */
3286 ret
= ehea_sense_adapter_attr(adapter
);
3288 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3292 adapter
->neq
= ehea_create_eq(adapter
,
3293 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3294 if (!adapter
->neq
) {
3296 dev_err(&dev
->dev
, "NEQ creation failed\n");
3300 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3301 (unsigned long)adapter
);
3303 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3304 ehea_interrupt_neq
, IRQF_DISABLED
,
3305 "ehea_neq", adapter
);
3307 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3311 ret
= ehea_create_device_sysfs(dev
);
3315 ret
= ehea_setup_ports(adapter
);
3317 dev_err(&dev
->dev
, "setup_ports failed\n");
3318 goto out_rem_dev_sysfs
;
3325 ehea_remove_device_sysfs(dev
);
3328 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3331 ehea_destroy_eq(adapter
->neq
);
3334 list_del(&adapter
->list
);
3338 ehea_update_firmware_handles();
3343 static int __devexit
ehea_remove(struct platform_device
*dev
)
3345 struct ehea_adapter
*adapter
= dev_get_drvdata(&dev
->dev
);
3348 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3349 if (adapter
->port
[i
]) {
3350 ehea_shutdown_single_port(adapter
->port
[i
]);
3351 adapter
->port
[i
] = NULL
;
3354 ehea_remove_device_sysfs(dev
);
3356 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3357 tasklet_kill(&adapter
->neq_tasklet
);
3359 ehea_destroy_eq(adapter
->neq
);
3360 ehea_remove_adapter_mr(adapter
);
3361 list_del(&adapter
->list
);
3364 ehea_update_firmware_handles();
3369 void ehea_crash_handler(void)
3373 if (ehea_fw_handles
.arr
)
3374 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3375 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3376 ehea_fw_handles
.arr
[i
].fwh
,
3379 if (ehea_bcmc_regs
.arr
)
3380 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3381 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3382 ehea_bcmc_regs
.arr
[i
].port_id
,
3383 ehea_bcmc_regs
.arr
[i
].reg_type
,
3384 ehea_bcmc_regs
.arr
[i
].macaddr
,
3388 static int ehea_mem_notifier(struct notifier_block
*nb
,
3389 unsigned long action
, void *data
)
3391 int ret
= NOTIFY_BAD
;
3392 struct memory_notify
*arg
= data
;
3394 mutex_lock(&dlpar_mem_lock
);
3397 case MEM_CANCEL_OFFLINE
:
3398 pr_info("memory offlining canceled");
3399 /* Readd canceled memory block */
3401 pr_info("memory is going online");
3402 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3403 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3407 case MEM_GOING_OFFLINE
:
3408 pr_info("memory is going offline");
3409 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3410 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3418 ehea_update_firmware_handles();
3422 mutex_unlock(&dlpar_mem_lock
);
3426 static struct notifier_block ehea_mem_nb
= {
3427 .notifier_call
= ehea_mem_notifier
,
3430 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3431 unsigned long action
, void *unused
)
3433 if (action
== SYS_RESTART
) {
3434 pr_info("Reboot: freeing all eHEA resources\n");
3435 ibmebus_unregister_driver(&ehea_driver
);
3440 static struct notifier_block ehea_reboot_nb
= {
3441 .notifier_call
= ehea_reboot_notifier
,
3444 static int check_module_parm(void)
3448 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3449 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3450 pr_info("Bad parameter: rq1_entries\n");
3453 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3454 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3455 pr_info("Bad parameter: rq2_entries\n");
3458 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3459 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3460 pr_info("Bad parameter: rq3_entries\n");
3463 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3464 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3465 pr_info("Bad parameter: sq_entries\n");
3472 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3475 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3478 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3479 ehea_show_capabilities
, NULL
);
3481 int __init
ehea_module_init(void)
3485 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3487 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3488 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3490 mutex_init(&ehea_fw_handles
.lock
);
3491 spin_lock_init(&ehea_bcmc_regs
.lock
);
3493 ret
= check_module_parm();
3497 ret
= ehea_create_busmap();
3501 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3503 pr_info("failed registering reboot notifier\n");
3505 ret
= register_memory_notifier(&ehea_mem_nb
);
3507 pr_info("failed registering memory remove notifier\n");
3509 ret
= crash_shutdown_register(ehea_crash_handler
);
3511 pr_info("failed registering crash handler\n");
3513 ret
= ibmebus_register_driver(&ehea_driver
);
3515 pr_err("failed registering eHEA device driver on ebus\n");
3519 ret
= driver_create_file(&ehea_driver
.driver
,
3520 &driver_attr_capabilities
);
3522 pr_err("failed to register capabilities attribute, ret=%d\n",
3530 ibmebus_unregister_driver(&ehea_driver
);
3532 unregister_memory_notifier(&ehea_mem_nb
);
3533 unregister_reboot_notifier(&ehea_reboot_nb
);
3534 crash_shutdown_unregister(ehea_crash_handler
);
3539 static void __exit
ehea_module_exit(void)
3543 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3544 ibmebus_unregister_driver(&ehea_driver
);
3545 unregister_reboot_notifier(&ehea_reboot_nb
);
3546 ret
= crash_shutdown_unregister(ehea_crash_handler
);
3548 pr_info("failed unregistering crash handler\n");
3549 unregister_memory_notifier(&ehea_mem_nb
);
3550 kfree(ehea_fw_handles
.arr
);
3551 kfree(ehea_bcmc_regs
.arr
);
3552 ehea_destroy_busmap();
3555 module_init(ehea_module_init
);
3556 module_exit(ehea_module_exit
);