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
;
66 static int lro_max_aggr
= EHEA_LRO_MAX_AGGR
;
67 static int num_tx_qps
= EHEA_NUM_TX_QP
;
68 static int prop_carrier_state
;
70 module_param(msg_level
, int, 0);
71 module_param(rq1_entries
, int, 0);
72 module_param(rq2_entries
, int, 0);
73 module_param(rq3_entries
, int, 0);
74 module_param(sq_entries
, int, 0);
75 module_param(prop_carrier_state
, int, 0);
76 module_param(use_mcs
, int, 0);
77 module_param(use_lro
, int, 0);
78 module_param(lro_max_aggr
, int, 0);
79 module_param(num_tx_qps
, int, 0);
81 MODULE_PARM_DESC(num_tx_qps
, "Number of TX-QPS");
82 MODULE_PARM_DESC(msg_level
, "msg_level");
83 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
84 "port to stack. 1:yes, 0:no. Default = 0 ");
85 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
88 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
91 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
94 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
95 "[2^x - 1], x = [6..14]. Default = "
96 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
97 MODULE_PARM_DESC(use_mcs
, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
99 MODULE_PARM_DESC(lro_max_aggr
, " LRO: Max packets to be aggregated. Default = "
100 __MODULE_STRING(EHEA_LRO_MAX_AGGR
));
101 MODULE_PARM_DESC(use_lro
, " Large Receive Offload, 1: enable, 0: disable, "
104 static int port_name_cnt
;
105 static LIST_HEAD(adapter_list
);
106 static unsigned long ehea_driver_flags
;
107 static DEFINE_MUTEX(dlpar_mem_lock
);
108 struct ehea_fw_handle_array ehea_fw_handles
;
109 struct ehea_bcmc_reg_array ehea_bcmc_regs
;
112 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
113 const struct of_device_id
*id
);
115 static int __devexit
ehea_remove(struct platform_device
*dev
);
117 static struct of_device_id ehea_device_table
[] = {
120 .compatible
= "IBM,lhea",
124 MODULE_DEVICE_TABLE(of
, ehea_device_table
);
126 static struct of_platform_driver ehea_driver
= {
129 .owner
= THIS_MODULE
,
130 .of_match_table
= ehea_device_table
,
132 .probe
= ehea_probe_adapter
,
133 .remove
= ehea_remove
,
136 void ehea_dump(void *adr
, int len
, char *msg
)
139 unsigned char *deb
= adr
;
140 for (x
= 0; x
< len
; x
+= 16) {
141 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
142 msg
, deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
147 void ehea_schedule_port_reset(struct ehea_port
*port
)
149 if (!test_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
))
150 schedule_work(&port
->reset_task
);
153 static void ehea_update_firmware_handles(void)
155 struct ehea_fw_handle_entry
*arr
= NULL
;
156 struct ehea_adapter
*adapter
;
157 int num_adapters
= 0;
161 int num_fw_handles
, k
, l
;
163 /* Determine number of handles */
164 mutex_lock(&ehea_fw_handles
.lock
);
166 list_for_each_entry(adapter
, &adapter_list
, list
) {
169 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
170 struct ehea_port
*port
= adapter
->port
[k
];
172 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
176 num_portres
+= port
->num_def_qps
+ port
->num_add_tx_qps
;
180 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
181 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
182 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
184 if (num_fw_handles
) {
185 arr
= kcalloc(num_fw_handles
, sizeof(*arr
), GFP_KERNEL
);
187 goto out
; /* Keep the existing array */
191 list_for_each_entry(adapter
, &adapter_list
, list
) {
192 if (num_adapters
== 0)
195 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
196 struct ehea_port
*port
= adapter
->port
[k
];
198 if (!port
|| (port
->state
!= EHEA_PORT_UP
) ||
203 l
< port
->num_def_qps
+ port
->num_add_tx_qps
;
205 struct ehea_port_res
*pr
= &port
->port_res
[l
];
207 arr
[i
].adh
= adapter
->handle
;
208 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
209 arr
[i
].adh
= adapter
->handle
;
210 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
211 arr
[i
].adh
= adapter
->handle
;
212 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
213 arr
[i
].adh
= adapter
->handle
;
214 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
215 arr
[i
].adh
= adapter
->handle
;
216 arr
[i
++].fwh
= pr
->send_mr
.handle
;
217 arr
[i
].adh
= adapter
->handle
;
218 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
220 arr
[i
].adh
= adapter
->handle
;
221 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
225 arr
[i
].adh
= adapter
->handle
;
226 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
228 if (adapter
->mr
.handle
) {
229 arr
[i
].adh
= adapter
->handle
;
230 arr
[i
++].fwh
= adapter
->mr
.handle
;
236 kfree(ehea_fw_handles
.arr
);
237 ehea_fw_handles
.arr
= arr
;
238 ehea_fw_handles
.num_entries
= i
;
240 mutex_unlock(&ehea_fw_handles
.lock
);
243 static void ehea_update_bcmc_registrations(void)
246 struct ehea_bcmc_reg_entry
*arr
= NULL
;
247 struct ehea_adapter
*adapter
;
248 struct ehea_mc_list
*mc_entry
;
249 int num_registrations
= 0;
253 spin_lock_irqsave(&ehea_bcmc_regs
.lock
, flags
);
255 /* Determine number of registrations */
256 list_for_each_entry(adapter
, &adapter_list
, list
)
257 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
258 struct ehea_port
*port
= adapter
->port
[k
];
260 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
263 num_registrations
+= 2; /* Broadcast registrations */
265 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
266 num_registrations
+= 2;
269 if (num_registrations
) {
270 arr
= kcalloc(num_registrations
, sizeof(*arr
), GFP_ATOMIC
);
272 goto out
; /* Keep the existing array */
276 list_for_each_entry(adapter
, &adapter_list
, list
) {
277 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
278 struct ehea_port
*port
= adapter
->port
[k
];
280 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
283 if (num_registrations
== 0)
286 arr
[i
].adh
= adapter
->handle
;
287 arr
[i
].port_id
= port
->logical_port_id
;
288 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
290 arr
[i
++].macaddr
= port
->mac_addr
;
292 arr
[i
].adh
= adapter
->handle
;
293 arr
[i
].port_id
= port
->logical_port_id
;
294 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
295 EHEA_BCMC_VLANID_ALL
;
296 arr
[i
++].macaddr
= port
->mac_addr
;
297 num_registrations
-= 2;
299 list_for_each_entry(mc_entry
,
300 &port
->mc_list
->list
, list
) {
301 if (num_registrations
== 0)
304 arr
[i
].adh
= adapter
->handle
;
305 arr
[i
].port_id
= port
->logical_port_id
;
306 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
307 EHEA_BCMC_MULTICAST
|
309 arr
[i
++].macaddr
= mc_entry
->macaddr
;
311 arr
[i
].adh
= adapter
->handle
;
312 arr
[i
].port_id
= port
->logical_port_id
;
313 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
314 EHEA_BCMC_MULTICAST
|
315 EHEA_BCMC_VLANID_ALL
;
316 arr
[i
++].macaddr
= mc_entry
->macaddr
;
317 num_registrations
-= 2;
323 kfree(ehea_bcmc_regs
.arr
);
324 ehea_bcmc_regs
.arr
= arr
;
325 ehea_bcmc_regs
.num_entries
= i
;
327 spin_unlock_irqrestore(&ehea_bcmc_regs
.lock
, flags
);
330 static struct net_device_stats
*ehea_get_stats(struct net_device
*dev
)
332 struct ehea_port
*port
= netdev_priv(dev
);
333 struct net_device_stats
*stats
= &port
->stats
;
334 struct hcp_ehea_port_cb2
*cb2
;
335 u64 hret
, rx_packets
, tx_packets
, rx_bytes
= 0, tx_bytes
= 0;
338 memset(stats
, 0, sizeof(*stats
));
340 cb2
= (void *)get_zeroed_page(GFP_KERNEL
);
342 netdev_err(dev
, "no mem for cb2\n");
346 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
347 port
->logical_port_id
,
348 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
349 if (hret
!= H_SUCCESS
) {
350 netdev_err(dev
, "query_ehea_port failed\n");
354 if (netif_msg_hw(port
))
355 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
358 for (i
= 0; i
< port
->num_def_qps
; i
++) {
359 rx_packets
+= port
->port_res
[i
].rx_packets
;
360 rx_bytes
+= port
->port_res
[i
].rx_bytes
;
364 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
365 tx_packets
+= port
->port_res
[i
].tx_packets
;
366 tx_bytes
+= port
->port_res
[i
].tx_bytes
;
369 stats
->tx_packets
= tx_packets
;
370 stats
->multicast
= cb2
->rxmcp
;
371 stats
->rx_errors
= cb2
->rxuerr
;
372 stats
->rx_bytes
= rx_bytes
;
373 stats
->tx_bytes
= tx_bytes
;
374 stats
->rx_packets
= rx_packets
;
377 free_page((unsigned long)cb2
);
382 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
384 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
385 struct net_device
*dev
= pr
->port
->netdev
;
386 int max_index_mask
= pr
->rq1_skba
.len
- 1;
387 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
391 pr
->rq1_skba
.os_skbs
= 0;
393 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
395 pr
->rq1_skba
.index
= index
;
396 pr
->rq1_skba
.os_skbs
= fill_wqes
;
400 for (i
= 0; i
< fill_wqes
; i
++) {
401 if (!skb_arr_rq1
[index
]) {
402 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
404 if (!skb_arr_rq1
[index
]) {
405 netdev_info(dev
, "Unable to allocate enough skb in the array\n");
406 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
411 index
&= max_index_mask
;
419 ehea_update_rq1a(pr
->qp
, adder
);
422 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
424 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
425 struct net_device
*dev
= pr
->port
->netdev
;
428 if (nr_rq1a
> pr
->rq1_skba
.len
) {
429 netdev_err(dev
, "NR_RQ1A bigger than skb array len\n");
433 for (i
= 0; i
< nr_rq1a
; i
++) {
434 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
435 if (!skb_arr_rq1
[i
]) {
436 netdev_info(dev
, "Not enough memory to allocate skb array\n");
441 ehea_update_rq1a(pr
->qp
, i
- 1);
444 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
445 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
446 int num_wqes
, int wqe_type
, int packet_size
)
448 struct net_device
*dev
= pr
->port
->netdev
;
449 struct ehea_qp
*qp
= pr
->qp
;
450 struct sk_buff
**skb_arr
= q_skba
->arr
;
451 struct ehea_rwqe
*rwqe
;
452 int i
, index
, max_index_mask
, fill_wqes
;
456 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
459 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
460 q_skba
->os_skbs
= fill_wqes
;
464 index
= q_skba
->index
;
465 max_index_mask
= q_skba
->len
- 1;
466 for (i
= 0; i
< fill_wqes
; i
++) {
470 skb
= netdev_alloc_skb_ip_align(dev
, packet_size
);
472 q_skba
->os_skbs
= fill_wqes
- i
;
473 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
474 netdev_info(pr
->port
->netdev
,
475 "rq%i ran dry - no mem for skb\n",
482 skb_arr
[index
] = skb
;
483 tmp_addr
= ehea_map_vaddr(skb
->data
);
484 if (tmp_addr
== -1) {
486 q_skba
->os_skbs
= fill_wqes
- i
;
491 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
492 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
493 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
494 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
495 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
496 rwqe
->sg_list
[0].len
= packet_size
;
497 rwqe
->data_segments
= 1;
500 index
&= max_index_mask
;
504 q_skba
->index
= index
;
511 ehea_update_rq2a(pr
->qp
, adder
);
513 ehea_update_rq3a(pr
->qp
, adder
);
519 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
521 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
522 nr_of_wqes
, EHEA_RWQE2_TYPE
,
527 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
529 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
530 nr_of_wqes
, EHEA_RWQE3_TYPE
,
531 EHEA_MAX_PACKET_SIZE
);
534 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
536 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
537 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
539 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
540 (cqe
->header_length
== 0))
545 static inline void ehea_fill_skb(struct net_device
*dev
,
546 struct sk_buff
*skb
, struct ehea_cqe
*cqe
)
548 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
550 skb_put(skb
, length
);
551 skb
->protocol
= eth_type_trans(skb
, dev
);
553 /* The packet was not an IPV4 packet so a complemented checksum was
554 calculated. The value is found in the Internet Checksum field. */
555 if (cqe
->status
& EHEA_CQE_BLIND_CKSUM
) {
556 skb
->ip_summed
= CHECKSUM_COMPLETE
;
557 skb
->csum
= csum_unfold(~cqe
->inet_checksum_value
);
559 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
562 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
564 struct ehea_cqe
*cqe
)
566 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
577 prefetchw(pref
+ EHEA_CACHE_LINE
);
579 pref
= (skb_array
[x
]->data
);
581 prefetch(pref
+ EHEA_CACHE_LINE
);
582 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
583 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
586 skb
= skb_array
[skb_index
];
587 skb_array
[skb_index
] = NULL
;
591 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
592 int arr_len
, int wqe_index
)
604 prefetchw(pref
+ EHEA_CACHE_LINE
);
606 pref
= (skb_array
[x
]->data
);
608 prefetchw(pref
+ EHEA_CACHE_LINE
);
611 skb
= skb_array
[wqe_index
];
612 skb_array
[wqe_index
] = NULL
;
616 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
617 struct ehea_cqe
*cqe
, int *processed_rq2
,
622 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
623 pr
->p_stats
.err_tcp_cksum
++;
624 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
625 pr
->p_stats
.err_ip_cksum
++;
626 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
627 pr
->p_stats
.err_frame_crc
++;
631 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
633 } else if (rq
== 3) {
635 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
639 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
640 if (netif_msg_rx_err(pr
->port
)) {
641 pr_err("Critical receive error for QP %d. Resetting port.\n",
642 pr
->qp
->init_attr
.qp_nr
);
643 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
645 ehea_schedule_port_reset(pr
->port
);
652 static int get_skb_hdr(struct sk_buff
*skb
, void **iphdr
,
653 void **tcph
, u64
*hdr_flags
, void *priv
)
655 struct ehea_cqe
*cqe
= priv
;
659 /* non tcp/udp packets */
660 if (!cqe
->header_length
)
664 skb_reset_network_header(skb
);
666 if (iph
->protocol
!= IPPROTO_TCP
)
669 ip_len
= ip_hdrlen(skb
);
670 skb_set_transport_header(skb
, ip_len
);
671 *tcph
= tcp_hdr(skb
);
673 /* check if ip header and tcp header are complete */
674 if (ntohs(iph
->tot_len
) < ip_len
+ tcp_hdrlen(skb
))
677 *hdr_flags
= LRO_IPV4
| LRO_TCP
;
683 static void ehea_proc_skb(struct ehea_port_res
*pr
, struct ehea_cqe
*cqe
,
686 int vlan_extracted
= ((cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
) &&
689 if (skb
->dev
->features
& NETIF_F_LRO
) {
691 lro_vlan_hwaccel_receive_skb(&pr
->lro_mgr
, skb
,
696 lro_receive_skb(&pr
->lro_mgr
, skb
, cqe
);
699 vlan_hwaccel_receive_skb(skb
, pr
->port
->vgrp
,
702 netif_receive_skb(skb
);
706 static int ehea_proc_rwqes(struct net_device
*dev
,
707 struct ehea_port_res
*pr
,
710 struct ehea_port
*port
= pr
->port
;
711 struct ehea_qp
*qp
= pr
->qp
;
712 struct ehea_cqe
*cqe
;
714 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
715 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
716 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
717 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
718 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
719 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
720 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
721 u64 processed_bytes
= 0;
722 int wqe_index
, last_wqe_index
, rq
, port_reset
;
724 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
727 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
728 while ((processed
< budget
) && cqe
) {
732 if (netif_msg_rx_status(port
))
733 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
735 last_wqe_index
= wqe_index
;
737 if (!ehea_check_cqe(cqe
, &rq
)) {
740 skb
= get_skb_by_index_ll(skb_arr_rq1
,
743 if (unlikely(!skb
)) {
744 netif_info(port
, rx_err
, dev
,
745 "LL rq1: skb=NULL\n");
747 skb
= netdev_alloc_skb(dev
,
750 netdev_err(dev
, "Not enough memory to allocate skb\n");
754 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
755 cqe
->num_bytes_transfered
- 4);
756 ehea_fill_skb(dev
, skb
, cqe
);
757 } else if (rq
== 2) {
759 skb
= get_skb_by_index(skb_arr_rq2
,
760 skb_arr_rq2_len
, cqe
);
761 if (unlikely(!skb
)) {
762 netif_err(port
, rx_err
, dev
,
766 ehea_fill_skb(dev
, skb
, cqe
);
770 skb
= get_skb_by_index(skb_arr_rq3
,
771 skb_arr_rq3_len
, cqe
);
772 if (unlikely(!skb
)) {
773 netif_err(port
, rx_err
, dev
,
777 ehea_fill_skb(dev
, skb
, cqe
);
781 processed_bytes
+= skb
->len
;
782 ehea_proc_skb(pr
, cqe
, skb
);
784 pr
->p_stats
.poll_receive_errors
++;
785 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
791 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
793 if (dev
->features
& NETIF_F_LRO
)
794 lro_flush_all(&pr
->lro_mgr
);
796 pr
->rx_packets
+= processed
;
797 pr
->rx_bytes
+= processed_bytes
;
799 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
800 ehea_refill_rq2(pr
, processed_rq2
);
801 ehea_refill_rq3(pr
, processed_rq3
);
806 #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
808 static void reset_sq_restart_flag(struct ehea_port
*port
)
812 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
813 struct ehea_port_res
*pr
= &port
->port_res
[i
];
814 pr
->sq_restart_flag
= 0;
816 wake_up(&port
->restart_wq
);
819 static void check_sqs(struct ehea_port
*port
)
821 struct ehea_swqe
*swqe
;
825 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
826 struct ehea_port_res
*pr
= &port
->port_res
[i
];
829 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
830 memset(swqe
, 0, SWQE_HEADER_SIZE
);
831 atomic_dec(&pr
->swqe_avail
);
833 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
834 swqe
->wr_id
= SWQE_RESTART_CHECK
;
835 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
836 swqe
->tx_control
|= EHEA_SWQE_IMM_DATA_PRESENT
;
837 swqe
->immediate_data_length
= 80;
839 ehea_post_swqe(pr
->qp
, swqe
);
841 ret
= wait_event_timeout(port
->restart_wq
,
842 pr
->sq_restart_flag
== 0,
843 msecs_to_jiffies(100));
846 pr_err("HW/SW queues out of sync\n");
847 ehea_schedule_port_reset(pr
->port
);
854 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
857 struct ehea_cq
*send_cq
= pr
->send_cq
;
858 struct ehea_cqe
*cqe
;
859 int quota
= my_quota
;
865 cqe
= ehea_poll_cq(send_cq
);
866 while (cqe
&& (quota
> 0)) {
867 ehea_inc_cq(send_cq
);
872 if (cqe
->wr_id
== SWQE_RESTART_CHECK
) {
873 pr
->sq_restart_flag
= 1;
878 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
879 pr_err("Bad send completion status=0x%04X\n",
882 if (netif_msg_tx_err(pr
->port
))
883 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
885 if (cqe
->status
& EHEA_CQE_STAT_RESET_MASK
) {
886 pr_err("Resetting port\n");
887 ehea_schedule_port_reset(pr
->port
);
892 if (netif_msg_tx_done(pr
->port
))
893 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
895 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
896 == EHEA_SWQE2_TYPE
)) {
898 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
899 skb
= pr
->sq_skba
.arr
[index
];
901 pr
->sq_skba
.arr
[index
] = NULL
;
904 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
907 cqe
= ehea_poll_cq(send_cq
);
910 ehea_update_feca(send_cq
, cqe_counter
);
911 atomic_add(swqe_av
, &pr
->swqe_avail
);
913 spin_lock_irqsave(&pr
->netif_queue
, flags
);
915 if (pr
->queue_stopped
&& (atomic_read(&pr
->swqe_avail
)
916 >= pr
->swqe_refill_th
)) {
917 netif_wake_queue(pr
->port
->netdev
);
918 pr
->queue_stopped
= 0;
920 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
921 wake_up(&pr
->port
->swqe_avail_wq
);
926 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
927 #define EHEA_POLL_MAX_CQES 65535
929 static int ehea_poll(struct napi_struct
*napi
, int budget
)
931 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
933 struct net_device
*dev
= pr
->port
->netdev
;
934 struct ehea_cqe
*cqe
;
935 struct ehea_cqe
*cqe_skb
= NULL
;
936 int force_irq
, wqe_index
;
939 force_irq
= (pr
->poll_counter
> EHEA_NAPI_POLL_NUM_BEFORE_IRQ
);
940 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
943 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
945 while ((rx
!= budget
) || force_irq
) {
946 pr
->poll_counter
= 0;
949 ehea_reset_cq_ep(pr
->recv_cq
);
950 ehea_reset_cq_ep(pr
->send_cq
);
951 ehea_reset_cq_n1(pr
->recv_cq
);
952 ehea_reset_cq_n1(pr
->send_cq
);
954 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
955 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
957 if (!cqe
&& !cqe_skb
)
960 if (!napi_reschedule(napi
))
963 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
964 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
971 #ifdef CONFIG_NET_POLL_CONTROLLER
972 static void ehea_netpoll(struct net_device
*dev
)
974 struct ehea_port
*port
= netdev_priv(dev
);
977 for (i
= 0; i
< port
->num_def_qps
; i
++)
978 napi_schedule(&port
->port_res
[i
].napi
);
982 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
984 struct ehea_port_res
*pr
= param
;
986 napi_schedule(&pr
->napi
);
991 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
993 struct ehea_port
*port
= param
;
994 struct ehea_eqe
*eqe
;
997 u64 resource_type
, aer
, aerr
;
1000 eqe
= ehea_poll_eq(port
->qp_eq
);
1003 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
1004 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
1005 eqe
->entry
, qp_token
);
1007 qp
= port
->port_res
[qp_token
].qp
;
1009 resource_type
= ehea_error_data(port
->adapter
, qp
->fw_handle
,
1012 if (resource_type
== EHEA_AER_RESTYPE_QP
) {
1013 if ((aer
& EHEA_AER_RESET_MASK
) ||
1014 (aerr
& EHEA_AERR_RESET_MASK
))
1017 reset_port
= 1; /* Reset in case of CQ or EQ error */
1019 eqe
= ehea_poll_eq(port
->qp_eq
);
1023 pr_err("Resetting port\n");
1024 ehea_schedule_port_reset(port
);
1030 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
1035 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
1036 if (adapter
->port
[i
])
1037 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
1038 return adapter
->port
[i
];
1042 int ehea_sense_port_attr(struct ehea_port
*port
)
1046 struct hcp_ehea_port_cb0
*cb0
;
1048 /* may be called via ehea_neq_tasklet() */
1049 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
1051 pr_err("no mem for cb0\n");
1056 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1057 port
->logical_port_id
, H_PORT_CB0
,
1058 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
1060 if (hret
!= H_SUCCESS
) {
1066 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1068 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
1069 ret
= -EADDRNOTAVAIL
;
1074 switch (cb0
->port_speed
) {
1076 port
->port_speed
= EHEA_SPEED_10M
;
1077 port
->full_duplex
= 0;
1080 port
->port_speed
= EHEA_SPEED_10M
;
1081 port
->full_duplex
= 1;
1083 case H_SPEED_100M_H
:
1084 port
->port_speed
= EHEA_SPEED_100M
;
1085 port
->full_duplex
= 0;
1087 case H_SPEED_100M_F
:
1088 port
->port_speed
= EHEA_SPEED_100M
;
1089 port
->full_duplex
= 1;
1092 port
->port_speed
= EHEA_SPEED_1G
;
1093 port
->full_duplex
= 1;
1096 port
->port_speed
= EHEA_SPEED_10G
;
1097 port
->full_duplex
= 1;
1100 port
->port_speed
= 0;
1101 port
->full_duplex
= 0;
1106 port
->num_mcs
= cb0
->num_default_qps
;
1108 /* Number of default QPs */
1110 port
->num_def_qps
= cb0
->num_default_qps
;
1112 port
->num_def_qps
= 1;
1114 if (!port
->num_def_qps
) {
1119 port
->num_tx_qps
= num_tx_qps
;
1121 if (port
->num_def_qps
>= port
->num_tx_qps
)
1122 port
->num_add_tx_qps
= 0;
1124 port
->num_add_tx_qps
= port
->num_tx_qps
- port
->num_def_qps
;
1128 if (ret
|| netif_msg_probe(port
))
1129 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1130 free_page((unsigned long)cb0
);
1135 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1137 struct hcp_ehea_port_cb4
*cb4
;
1141 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1143 pr_err("no mem for cb4\n");
1148 cb4
->port_speed
= port_speed
;
1150 netif_carrier_off(port
->netdev
);
1152 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1153 port
->logical_port_id
,
1154 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1155 if (hret
== H_SUCCESS
) {
1156 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1158 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1159 port
->logical_port_id
,
1160 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1162 if (hret
== H_SUCCESS
) {
1163 switch (cb4
->port_speed
) {
1165 port
->port_speed
= EHEA_SPEED_10M
;
1166 port
->full_duplex
= 0;
1169 port
->port_speed
= EHEA_SPEED_10M
;
1170 port
->full_duplex
= 1;
1172 case H_SPEED_100M_H
:
1173 port
->port_speed
= EHEA_SPEED_100M
;
1174 port
->full_duplex
= 0;
1176 case H_SPEED_100M_F
:
1177 port
->port_speed
= EHEA_SPEED_100M
;
1178 port
->full_duplex
= 1;
1181 port
->port_speed
= EHEA_SPEED_1G
;
1182 port
->full_duplex
= 1;
1185 port
->port_speed
= EHEA_SPEED_10G
;
1186 port
->full_duplex
= 1;
1189 port
->port_speed
= 0;
1190 port
->full_duplex
= 0;
1194 pr_err("Failed sensing port speed\n");
1198 if (hret
== H_AUTHORITY
) {
1199 pr_info("Hypervisor denied setting port speed\n");
1203 pr_err("Failed setting port speed\n");
1206 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1207 netif_carrier_on(port
->netdev
);
1209 free_page((unsigned long)cb4
);
1214 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1219 struct ehea_port
*port
;
1220 struct net_device
*dev
;
1222 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1223 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1224 port
= ehea_get_port(adapter
, portnum
);
1228 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1231 netdev_err(dev
, "unknown portnum %x\n", portnum
);
1235 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1236 if (!netif_carrier_ok(dev
)) {
1237 ret
= ehea_sense_port_attr(port
);
1239 netdev_err(dev
, "failed resensing port attributes\n");
1243 netif_info(port
, link
, dev
,
1244 "Logical port up: %dMbps %s Duplex\n",
1246 port
->full_duplex
== 1 ?
1249 netif_carrier_on(dev
);
1250 netif_wake_queue(dev
);
1253 if (netif_carrier_ok(dev
)) {
1254 netif_info(port
, link
, dev
,
1255 "Logical port down\n");
1256 netif_carrier_off(dev
);
1257 netif_stop_queue(dev
);
1260 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1261 port
->phy_link
= EHEA_PHY_LINK_UP
;
1262 netif_info(port
, link
, dev
,
1263 "Physical port up\n");
1264 if (prop_carrier_state
)
1265 netif_carrier_on(dev
);
1267 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1268 netif_info(port
, link
, dev
,
1269 "Physical port down\n");
1270 if (prop_carrier_state
)
1271 netif_carrier_off(dev
);
1274 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1276 "External switch port is primary port\n");
1279 "External switch port is backup port\n");
1282 case EHEA_EC_ADAPTER_MALFUNC
:
1283 netdev_err(dev
, "Adapter malfunction\n");
1285 case EHEA_EC_PORT_MALFUNC
:
1286 netdev_info(dev
, "Port malfunction\n");
1287 netif_carrier_off(dev
);
1288 netif_stop_queue(dev
);
1291 netdev_err(dev
, "unknown event code %x, eqe=0x%llX\n", ec
, eqe
);
1296 static void ehea_neq_tasklet(unsigned long data
)
1298 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1299 struct ehea_eqe
*eqe
;
1302 eqe
= ehea_poll_eq(adapter
->neq
);
1303 pr_debug("eqe=%p\n", eqe
);
1306 pr_debug("*eqe=%lx\n", (unsigned long) eqe
->entry
);
1307 ehea_parse_eqe(adapter
, eqe
->entry
);
1308 eqe
= ehea_poll_eq(adapter
->neq
);
1309 pr_debug("next eqe=%p\n", eqe
);
1312 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1313 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1314 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1316 ehea_h_reset_events(adapter
->handle
,
1317 adapter
->neq
->fw_handle
, event_mask
);
1320 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1322 struct ehea_adapter
*adapter
= param
;
1323 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1328 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1331 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1333 ehea_init_fill_rq1(pr
, pr
->rq1_skba
.len
);
1335 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1337 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1342 static int ehea_reg_interrupts(struct net_device
*dev
)
1344 struct ehea_port
*port
= netdev_priv(dev
);
1345 struct ehea_port_res
*pr
;
1349 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1352 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1353 ehea_qp_aff_irq_handler
,
1354 IRQF_DISABLED
, port
->int_aff_name
, port
);
1356 netdev_err(dev
, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1357 port
->qp_eq
->attr
.ist1
);
1361 netif_info(port
, ifup
, dev
,
1362 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1363 port
->qp_eq
->attr
.ist1
);
1366 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1367 pr
= &port
->port_res
[i
];
1368 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1369 "%s-queue%d", dev
->name
, i
);
1370 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1371 ehea_recv_irq_handler
,
1372 IRQF_DISABLED
, pr
->int_send_name
,
1375 netdev_err(dev
, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1376 i
, pr
->eq
->attr
.ist1
);
1379 netif_info(port
, ifup
, dev
,
1380 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1381 pr
->eq
->attr
.ist1
, i
);
1389 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1390 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1394 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1395 i
= port
->num_def_qps
;
1401 static void ehea_free_interrupts(struct net_device
*dev
)
1403 struct ehea_port
*port
= netdev_priv(dev
);
1404 struct ehea_port_res
*pr
;
1409 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1410 pr
= &port
->port_res
[i
];
1411 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1412 netif_info(port
, intr
, dev
,
1413 "free send irq for res %d with handle 0x%X\n",
1414 i
, pr
->eq
->attr
.ist1
);
1417 /* associated events */
1418 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1419 netif_info(port
, intr
, dev
,
1420 "associated event interrupt for handle 0x%X freed\n",
1421 port
->qp_eq
->attr
.ist1
);
1424 static int ehea_configure_port(struct ehea_port
*port
)
1428 struct hcp_ehea_port_cb0
*cb0
;
1431 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1435 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1436 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1437 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1440 PXLY_RC_VLAN_FILTER
)
1441 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1443 for (i
= 0; i
< port
->num_mcs
; i
++)
1445 cb0
->default_qpn_arr
[i
] =
1446 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1448 cb0
->default_qpn_arr
[i
] =
1449 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1451 if (netif_msg_ifup(port
))
1452 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1454 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1455 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1457 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1458 port
->logical_port_id
,
1459 H_PORT_CB0
, mask
, cb0
);
1461 if (hret
!= H_SUCCESS
)
1467 free_page((unsigned long)cb0
);
1472 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1475 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1477 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1481 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1488 ehea_rem_mr(&pr
->send_mr
);
1490 pr_err("Generating SMRS failed\n");
1494 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1496 if ((ehea_rem_mr(&pr
->send_mr
)) ||
1497 (ehea_rem_mr(&pr
->recv_mr
)))
1503 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1505 int arr_size
= sizeof(void *) * max_q_entries
;
1507 q_skba
->arr
= vzalloc(arr_size
);
1511 q_skba
->len
= max_q_entries
;
1513 q_skba
->os_skbs
= 0;
1518 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1519 struct port_res_cfg
*pr_cfg
, int queue_token
)
1521 struct ehea_adapter
*adapter
= port
->adapter
;
1522 enum ehea_eq_type eq_type
= EHEA_EQ
;
1523 struct ehea_qp_init_attr
*init_attr
= NULL
;
1525 u64 tx_bytes
, rx_bytes
, tx_packets
, rx_packets
;
1527 tx_bytes
= pr
->tx_bytes
;
1528 tx_packets
= pr
->tx_packets
;
1529 rx_bytes
= pr
->rx_bytes
;
1530 rx_packets
= pr
->rx_packets
;
1532 memset(pr
, 0, sizeof(struct ehea_port_res
));
1534 pr
->tx_bytes
= rx_bytes
;
1535 pr
->tx_packets
= tx_packets
;
1536 pr
->rx_bytes
= rx_bytes
;
1537 pr
->rx_packets
= rx_packets
;
1540 spin_lock_init(&pr
->xmit_lock
);
1541 spin_lock_init(&pr
->netif_queue
);
1543 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1545 pr_err("create_eq failed (eq)\n");
1549 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1551 port
->logical_port_id
);
1553 pr_err("create_cq failed (cq_recv)\n");
1557 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1559 port
->logical_port_id
);
1561 pr_err("create_cq failed (cq_send)\n");
1565 if (netif_msg_ifup(port
))
1566 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1567 pr
->send_cq
->attr
.act_nr_of_cqes
,
1568 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1570 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1573 pr_err("no mem for ehea_qp_init_attr\n");
1577 init_attr
->low_lat_rq1
= 1;
1578 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1579 init_attr
->rq_count
= 3;
1580 init_attr
->qp_token
= queue_token
;
1581 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1582 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1583 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1584 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1585 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1586 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1587 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1588 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1589 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1590 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1591 init_attr
->port_nr
= port
->logical_port_id
;
1592 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1593 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1594 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1596 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1598 pr_err("create_qp failed\n");
1603 if (netif_msg_ifup(port
))
1604 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",
1606 init_attr
->act_nr_send_wqes
,
1607 init_attr
->act_nr_rwqes_rq1
,
1608 init_attr
->act_nr_rwqes_rq2
,
1609 init_attr
->act_nr_rwqes_rq3
);
1611 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1613 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1614 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1615 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1616 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1620 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1621 if (ehea_gen_smrs(pr
) != 0) {
1626 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1630 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1632 pr
->lro_mgr
.max_aggr
= pr
->port
->lro_max_aggr
;
1633 pr
->lro_mgr
.max_desc
= MAX_LRO_DESCRIPTORS
;
1634 pr
->lro_mgr
.lro_arr
= pr
->lro_desc
;
1635 pr
->lro_mgr
.get_skb_header
= get_skb_hdr
;
1636 pr
->lro_mgr
.features
= LRO_F_NAPI
| LRO_F_EXTRACT_VLAN_ID
;
1637 pr
->lro_mgr
.dev
= port
->netdev
;
1638 pr
->lro_mgr
.ip_summed
= CHECKSUM_UNNECESSARY
;
1639 pr
->lro_mgr
.ip_summed_aggr
= CHECKSUM_UNNECESSARY
;
1646 vfree(pr
->sq_skba
.arr
);
1647 vfree(pr
->rq1_skba
.arr
);
1648 vfree(pr
->rq2_skba
.arr
);
1649 vfree(pr
->rq3_skba
.arr
);
1650 ehea_destroy_qp(pr
->qp
);
1651 ehea_destroy_cq(pr
->send_cq
);
1652 ehea_destroy_cq(pr
->recv_cq
);
1653 ehea_destroy_eq(pr
->eq
);
1658 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1663 netif_napi_del(&pr
->napi
);
1665 ret
= ehea_destroy_qp(pr
->qp
);
1668 ehea_destroy_cq(pr
->send_cq
);
1669 ehea_destroy_cq(pr
->recv_cq
);
1670 ehea_destroy_eq(pr
->eq
);
1672 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1673 if (pr
->rq1_skba
.arr
[i
])
1674 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1676 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1677 if (pr
->rq2_skba
.arr
[i
])
1678 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1680 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1681 if (pr
->rq3_skba
.arr
[i
])
1682 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1684 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1685 if (pr
->sq_skba
.arr
[i
])
1686 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1688 vfree(pr
->rq1_skba
.arr
);
1689 vfree(pr
->rq2_skba
.arr
);
1690 vfree(pr
->rq3_skba
.arr
);
1691 vfree(pr
->sq_skba
.arr
);
1692 ret
= ehea_rem_smrs(pr
);
1698 * The write_* functions store information in swqe which is used by
1699 * the hardware to calculate the ip/tcp/udp checksum
1702 static inline void write_ip_start_end(struct ehea_swqe
*swqe
,
1703 const struct sk_buff
*skb
)
1705 swqe
->ip_start
= skb_network_offset(skb
);
1706 swqe
->ip_end
= (u8
)(swqe
->ip_start
+ ip_hdrlen(skb
) - 1);
1709 static inline void write_tcp_offset_end(struct ehea_swqe
*swqe
,
1710 const struct sk_buff
*skb
)
1713 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct tcphdr
, check
));
1715 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1718 static inline void write_udp_offset_end(struct ehea_swqe
*swqe
,
1719 const struct sk_buff
*skb
)
1722 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct udphdr
, check
));
1724 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1728 static void write_swqe2_TSO(struct sk_buff
*skb
,
1729 struct ehea_swqe
*swqe
, u32 lkey
)
1731 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1732 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1733 int skb_data_size
= skb_headlen(skb
);
1736 /* Packet is TCP with TSO enabled */
1737 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1738 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1739 /* copy only eth/ip/tcp headers to immediate data and
1740 * the rest of skb->data to sg1entry
1742 headersize
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1744 skb_data_size
= skb_headlen(skb
);
1746 if (skb_data_size
>= headersize
) {
1747 /* copy immediate data */
1748 skb_copy_from_linear_data(skb
, imm_data
, headersize
);
1749 swqe
->immediate_data_length
= headersize
;
1751 if (skb_data_size
> headersize
) {
1752 /* set sg1entry data */
1753 sg1entry
->l_key
= lkey
;
1754 sg1entry
->len
= skb_data_size
- headersize
;
1756 ehea_map_vaddr(skb
->data
+ headersize
);
1757 swqe
->descriptors
++;
1760 pr_err("cannot handle fragmented headers\n");
1763 static void write_swqe2_nonTSO(struct sk_buff
*skb
,
1764 struct ehea_swqe
*swqe
, u32 lkey
)
1766 int skb_data_size
= skb_headlen(skb
);
1767 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1768 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1770 /* Packet is any nonTSO type
1772 * Copy as much as possible skb->data to immediate data and
1773 * the rest to sg1entry
1775 if (skb_data_size
>= SWQE2_MAX_IMM
) {
1776 /* copy immediate data */
1777 skb_copy_from_linear_data(skb
, imm_data
, SWQE2_MAX_IMM
);
1779 swqe
->immediate_data_length
= SWQE2_MAX_IMM
;
1781 if (skb_data_size
> SWQE2_MAX_IMM
) {
1782 /* copy sg1entry data */
1783 sg1entry
->l_key
= lkey
;
1784 sg1entry
->len
= skb_data_size
- SWQE2_MAX_IMM
;
1786 ehea_map_vaddr(skb
->data
+ SWQE2_MAX_IMM
);
1787 swqe
->descriptors
++;
1790 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1791 swqe
->immediate_data_length
= skb_data_size
;
1795 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1796 struct ehea_swqe
*swqe
, u32 lkey
)
1798 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1800 int nfrags
, sg1entry_contains_frag_data
, i
;
1802 nfrags
= skb_shinfo(skb
)->nr_frags
;
1803 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1804 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1805 swqe
->descriptors
= 0;
1806 sg1entry_contains_frag_data
= 0;
1808 if ((dev
->features
& NETIF_F_TSO
) && skb_shinfo(skb
)->gso_size
)
1809 write_swqe2_TSO(skb
, swqe
, lkey
);
1811 write_swqe2_nonTSO(skb
, swqe
, lkey
);
1813 /* write descriptors */
1815 if (swqe
->descriptors
== 0) {
1816 /* sg1entry not yet used */
1817 frag
= &skb_shinfo(skb
)->frags
[0];
1819 /* copy sg1entry data */
1820 sg1entry
->l_key
= lkey
;
1821 sg1entry
->len
= frag
->size
;
1823 ehea_map_vaddr(page_address(frag
->page
)
1824 + frag
->page_offset
);
1825 swqe
->descriptors
++;
1826 sg1entry_contains_frag_data
= 1;
1829 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1831 frag
= &skb_shinfo(skb
)->frags
[i
];
1832 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1834 sgentry
->l_key
= lkey
;
1835 sgentry
->len
= frag
->size
;
1837 ehea_map_vaddr(page_address(frag
->page
)
1838 + frag
->page_offset
);
1839 swqe
->descriptors
++;
1844 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1850 /* De/Register untagged packets */
1851 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1852 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1853 port
->logical_port_id
,
1854 reg_type
, port
->mac_addr
, 0, hcallid
);
1855 if (hret
!= H_SUCCESS
) {
1856 pr_err("%sregistering bc address failed (tagged)\n",
1857 hcallid
== H_REG_BCMC
? "" : "de");
1862 /* De/Register VLAN packets */
1863 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1864 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1865 port
->logical_port_id
,
1866 reg_type
, port
->mac_addr
, 0, hcallid
);
1867 if (hret
!= H_SUCCESS
) {
1868 pr_err("%sregistering bc address failed (vlan)\n",
1869 hcallid
== H_REG_BCMC
? "" : "de");
1876 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1878 struct ehea_port
*port
= netdev_priv(dev
);
1879 struct sockaddr
*mac_addr
= sa
;
1880 struct hcp_ehea_port_cb0
*cb0
;
1884 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1885 ret
= -EADDRNOTAVAIL
;
1889 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1891 pr_err("no mem for cb0\n");
1896 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1898 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1900 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1901 port
->logical_port_id
, H_PORT_CB0
,
1902 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1903 if (hret
!= H_SUCCESS
) {
1908 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1910 /* Deregister old MAC in pHYP */
1911 if (port
->state
== EHEA_PORT_UP
) {
1912 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1917 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1919 /* Register new MAC in pHYP */
1920 if (port
->state
== EHEA_PORT_UP
) {
1921 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1929 ehea_update_bcmc_registrations();
1931 free_page((unsigned long)cb0
);
1936 static void ehea_promiscuous_error(u64 hret
, int enable
)
1938 if (hret
== H_AUTHORITY
)
1939 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1940 enable
== 1 ? "en" : "dis");
1942 pr_err("failed %sabling promiscuous mode\n",
1943 enable
== 1 ? "en" : "dis");
1946 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1948 struct ehea_port
*port
= netdev_priv(dev
);
1949 struct hcp_ehea_port_cb7
*cb7
;
1952 if (enable
== port
->promisc
)
1955 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1957 pr_err("no mem for cb7\n");
1961 /* Modify Pxs_DUCQPN in CB7 */
1962 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1964 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1965 port
->logical_port_id
,
1966 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1968 ehea_promiscuous_error(hret
, enable
);
1972 port
->promisc
= enable
;
1974 free_page((unsigned long)cb7
);
1977 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1983 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1984 | EHEA_BCMC_UNTAGGED
;
1986 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1987 port
->logical_port_id
,
1988 reg_type
, mc_mac_addr
, 0, hcallid
);
1992 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1993 | EHEA_BCMC_VLANID_ALL
;
1995 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1996 port
->logical_port_id
,
1997 reg_type
, mc_mac_addr
, 0, hcallid
);
2002 static int ehea_drop_multicast_list(struct net_device
*dev
)
2004 struct ehea_port
*port
= netdev_priv(dev
);
2005 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
2006 struct list_head
*pos
;
2007 struct list_head
*temp
;
2011 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
2012 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
2014 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
2017 pr_err("failed deregistering mcast MAC\n");
2027 static void ehea_allmulti(struct net_device
*dev
, int enable
)
2029 struct ehea_port
*port
= netdev_priv(dev
);
2032 if (!port
->allmulti
) {
2034 /* Enable ALLMULTI */
2035 ehea_drop_multicast_list(dev
);
2036 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
2041 "failed enabling IFF_ALLMULTI\n");
2045 /* Disable ALLMULTI */
2046 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
2051 "failed disabling IFF_ALLMULTI\n");
2055 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
2057 struct ehea_mc_list
*ehea_mcl_entry
;
2060 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
2061 if (!ehea_mcl_entry
) {
2062 pr_err("no mem for mcl_entry\n");
2066 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
2068 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
2070 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
2073 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
2075 pr_err("failed registering mcast MAC\n");
2076 kfree(ehea_mcl_entry
);
2080 static void ehea_set_multicast_list(struct net_device
*dev
)
2082 struct ehea_port
*port
= netdev_priv(dev
);
2083 struct netdev_hw_addr
*ha
;
2086 if (dev
->flags
& IFF_PROMISC
) {
2087 ehea_promiscuous(dev
, 1);
2090 ehea_promiscuous(dev
, 0);
2092 if (dev
->flags
& IFF_ALLMULTI
) {
2093 ehea_allmulti(dev
, 1);
2096 ehea_allmulti(dev
, 0);
2098 if (!netdev_mc_empty(dev
)) {
2099 ret
= ehea_drop_multicast_list(dev
);
2101 /* Dropping the current multicast list failed.
2102 * Enabling ALL_MULTI is the best we can do.
2104 ehea_allmulti(dev
, 1);
2107 if (netdev_mc_count(dev
) > port
->adapter
->max_mc_mac
) {
2108 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
2109 port
->adapter
->max_mc_mac
);
2113 netdev_for_each_mc_addr(ha
, dev
)
2114 ehea_add_multicast_entry(port
, ha
->addr
);
2118 ehea_update_bcmc_registrations();
2121 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
2123 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
2129 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2130 struct ehea_swqe
*swqe
, u32 lkey
)
2132 if (skb
->protocol
== htons(ETH_P_IP
)) {
2133 const struct iphdr
*iph
= ip_hdr(skb
);
2136 swqe
->tx_control
|= EHEA_SWQE_CRC
2137 | EHEA_SWQE_IP_CHECKSUM
2138 | EHEA_SWQE_TCP_CHECKSUM
2139 | EHEA_SWQE_IMM_DATA_PRESENT
2140 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
2142 write_ip_start_end(swqe
, skb
);
2144 if (iph
->protocol
== IPPROTO_UDP
) {
2145 if ((iph
->frag_off
& IP_MF
) ||
2146 (iph
->frag_off
& IP_OFFSET
))
2147 /* IP fragment, so don't change cs */
2148 swqe
->tx_control
&= ~EHEA_SWQE_TCP_CHECKSUM
;
2150 write_udp_offset_end(swqe
, skb
);
2151 } else if (iph
->protocol
== IPPROTO_TCP
) {
2152 write_tcp_offset_end(swqe
, skb
);
2155 /* icmp (big data) and ip segmentation packets (all other ip
2156 packets) do not require any special handling */
2159 /* Other Ethernet Protocol */
2160 swqe
->tx_control
|= EHEA_SWQE_CRC
2161 | EHEA_SWQE_IMM_DATA_PRESENT
2162 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
2165 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2168 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2169 struct ehea_swqe
*swqe
)
2171 int nfrags
= skb_shinfo(skb
)->nr_frags
;
2172 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2176 if (skb
->protocol
== htons(ETH_P_IP
)) {
2177 const struct iphdr
*iph
= ip_hdr(skb
);
2180 write_ip_start_end(swqe
, skb
);
2182 if (iph
->protocol
== IPPROTO_TCP
) {
2183 swqe
->tx_control
|= EHEA_SWQE_CRC
2184 | EHEA_SWQE_IP_CHECKSUM
2185 | EHEA_SWQE_TCP_CHECKSUM
2186 | EHEA_SWQE_IMM_DATA_PRESENT
;
2188 write_tcp_offset_end(swqe
, skb
);
2190 } else if (iph
->protocol
== IPPROTO_UDP
) {
2191 if ((iph
->frag_off
& IP_MF
) ||
2192 (iph
->frag_off
& IP_OFFSET
))
2193 /* IP fragment, so don't change cs */
2194 swqe
->tx_control
|= EHEA_SWQE_CRC
2195 | EHEA_SWQE_IMM_DATA_PRESENT
;
2197 swqe
->tx_control
|= EHEA_SWQE_CRC
2198 | EHEA_SWQE_IP_CHECKSUM
2199 | EHEA_SWQE_TCP_CHECKSUM
2200 | EHEA_SWQE_IMM_DATA_PRESENT
;
2202 write_udp_offset_end(swqe
, skb
);
2205 /* icmp (big data) and
2206 ip segmentation packets (all other ip packets) */
2207 swqe
->tx_control
|= EHEA_SWQE_CRC
2208 | EHEA_SWQE_IP_CHECKSUM
2209 | EHEA_SWQE_IMM_DATA_PRESENT
;
2212 /* Other Ethernet Protocol */
2213 swqe
->tx_control
|= EHEA_SWQE_CRC
| EHEA_SWQE_IMM_DATA_PRESENT
;
2215 /* copy (immediate) data */
2217 /* data is in a single piece */
2218 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2220 /* first copy data from the skb->data buffer ... */
2221 skb_copy_from_linear_data(skb
, imm_data
,
2223 imm_data
+= skb_headlen(skb
);
2225 /* ... then copy data from the fragments */
2226 for (i
= 0; i
< nfrags
; i
++) {
2227 frag
= &skb_shinfo(skb
)->frags
[i
];
2229 page_address(frag
->page
) + frag
->page_offset
,
2231 imm_data
+= frag
->size
;
2234 swqe
->immediate_data_length
= skb
->len
;
2238 static inline int ehea_hash_skb(struct sk_buff
*skb
, int num_qps
)
2243 if ((skb
->protocol
== htons(ETH_P_IP
)) &&
2244 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)) {
2245 tcp
= (struct tcphdr
*)(skb_network_header(skb
) +
2246 (ip_hdr(skb
)->ihl
* 4));
2247 tmp
= (tcp
->source
+ (tcp
->dest
<< 16)) % 31;
2248 tmp
+= ip_hdr(skb
)->daddr
% 31;
2249 return tmp
% num_qps
;
2254 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2256 struct ehea_port
*port
= netdev_priv(dev
);
2257 struct ehea_swqe
*swqe
;
2258 unsigned long flags
;
2261 struct ehea_port_res
*pr
;
2263 pr
= &port
->port_res
[ehea_hash_skb(skb
, port
->num_tx_qps
)];
2265 if (!spin_trylock(&pr
->xmit_lock
))
2266 return NETDEV_TX_BUSY
;
2268 if (pr
->queue_stopped
) {
2269 spin_unlock(&pr
->xmit_lock
);
2270 return NETDEV_TX_BUSY
;
2273 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2274 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2275 atomic_dec(&pr
->swqe_avail
);
2277 if (vlan_tx_tag_present(skb
)) {
2278 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2279 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2283 pr
->tx_bytes
+= skb
->len
;
2285 if (skb
->len
<= SWQE3_MAX_IMM
) {
2286 u32 sig_iv
= port
->sig_comp_iv
;
2287 u32 swqe_num
= pr
->swqe_id_counter
;
2288 ehea_xmit3(skb
, dev
, swqe
);
2289 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2290 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2291 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2292 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2294 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2295 pr
->swqe_ll_count
= 0;
2297 pr
->swqe_ll_count
+= 1;
2300 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2301 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2302 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2303 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2304 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2306 pr
->sq_skba
.index
++;
2307 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2309 lkey
= pr
->send_mr
.lkey
;
2310 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2311 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2313 pr
->swqe_id_counter
+= 1;
2315 netif_info(port
, tx_queued
, dev
,
2316 "post swqe on QP %d\n", pr
->qp
->init_attr
.qp_nr
);
2317 if (netif_msg_tx_queued(port
))
2318 ehea_dump(swqe
, 512, "swqe");
2320 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2321 netif_stop_queue(dev
);
2322 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2325 ehea_post_swqe(pr
->qp
, swqe
);
2327 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2328 spin_lock_irqsave(&pr
->netif_queue
, flags
);
2329 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2330 pr
->p_stats
.queue_stopped
++;
2331 netif_stop_queue(dev
);
2332 pr
->queue_stopped
= 1;
2334 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
2336 dev
->trans_start
= jiffies
; /* NETIF_F_LLTX driver :( */
2337 spin_unlock(&pr
->xmit_lock
);
2339 return NETDEV_TX_OK
;
2342 static void ehea_vlan_rx_register(struct net_device
*dev
,
2343 struct vlan_group
*grp
)
2345 struct ehea_port
*port
= netdev_priv(dev
);
2346 struct ehea_adapter
*adapter
= port
->adapter
;
2347 struct hcp_ehea_port_cb1
*cb1
;
2352 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2354 pr_err("no mem for cb1\n");
2358 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2359 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2360 if (hret
!= H_SUCCESS
)
2361 pr_err("modify_ehea_port failed\n");
2363 free_page((unsigned long)cb1
);
2368 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2370 struct ehea_port
*port
= netdev_priv(dev
);
2371 struct ehea_adapter
*adapter
= port
->adapter
;
2372 struct hcp_ehea_port_cb1
*cb1
;
2376 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2378 pr_err("no mem for cb1\n");
2382 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2383 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2384 if (hret
!= H_SUCCESS
) {
2385 pr_err("query_ehea_port failed\n");
2390 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2392 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2393 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2394 if (hret
!= H_SUCCESS
)
2395 pr_err("modify_ehea_port failed\n");
2397 free_page((unsigned long)cb1
);
2401 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2403 struct ehea_port
*port
= netdev_priv(dev
);
2404 struct ehea_adapter
*adapter
= port
->adapter
;
2405 struct hcp_ehea_port_cb1
*cb1
;
2409 vlan_group_set_device(port
->vgrp
, vid
, NULL
);
2411 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2413 pr_err("no mem for cb1\n");
2417 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2418 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2419 if (hret
!= H_SUCCESS
) {
2420 pr_err("query_ehea_port failed\n");
2425 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2427 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2428 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2429 if (hret
!= H_SUCCESS
)
2430 pr_err("modify_ehea_port failed\n");
2432 free_page((unsigned long)cb1
);
2435 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2441 struct hcp_modify_qp_cb0
*cb0
;
2443 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2449 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2450 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2451 if (hret
!= H_SUCCESS
) {
2452 pr_err("query_ehea_qp failed (1)\n");
2456 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2457 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2459 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2460 if (hret
!= H_SUCCESS
) {
2461 pr_err("modify_ehea_qp failed (1)\n");
2465 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2466 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2467 if (hret
!= H_SUCCESS
) {
2468 pr_err("query_ehea_qp failed (2)\n");
2472 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2473 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2474 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2475 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2476 if (hret
!= H_SUCCESS
) {
2477 pr_err("modify_ehea_qp failed (2)\n");
2481 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2482 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2483 if (hret
!= H_SUCCESS
) {
2484 pr_err("query_ehea_qp failed (3)\n");
2488 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2489 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2490 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2491 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2492 if (hret
!= H_SUCCESS
) {
2493 pr_err("modify_ehea_qp failed (3)\n");
2497 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2498 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2499 if (hret
!= H_SUCCESS
) {
2500 pr_err("query_ehea_qp failed (4)\n");
2506 free_page((unsigned long)cb0
);
2510 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
,
2514 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2515 enum ehea_eq_type eq_type
= EHEA_EQ
;
2517 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2518 EHEA_MAX_ENTRIES_EQ
, 1);
2521 pr_err("ehea_create_eq failed (qp_eq)\n");
2525 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2526 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2527 pr_cfg
.max_entries_sq
= sq_entries
;
2528 pr_cfg
.max_entries_rq1
= rq1_entries
;
2529 pr_cfg
.max_entries_rq2
= rq2_entries
;
2530 pr_cfg
.max_entries_rq3
= rq3_entries
;
2532 pr_cfg_small_rx
.max_entries_rcq
= 1;
2533 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2534 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2535 pr_cfg_small_rx
.max_entries_rq1
= 1;
2536 pr_cfg_small_rx
.max_entries_rq2
= 1;
2537 pr_cfg_small_rx
.max_entries_rq3
= 1;
2539 for (i
= 0; i
< def_qps
; i
++) {
2540 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2544 for (i
= def_qps
; i
< def_qps
+ add_tx_qps
; i
++) {
2545 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2546 &pr_cfg_small_rx
, i
);
2555 ehea_clean_portres(port
, &port
->port_res
[i
]);
2558 ehea_destroy_eq(port
->qp_eq
);
2562 static int ehea_clean_all_portres(struct ehea_port
*port
)
2567 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2568 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2570 ret
|= ehea_destroy_eq(port
->qp_eq
);
2575 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2577 if (adapter
->active_ports
)
2580 ehea_rem_mr(&adapter
->mr
);
2583 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2585 if (adapter
->active_ports
)
2588 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2591 static int ehea_up(struct net_device
*dev
)
2594 struct ehea_port
*port
= netdev_priv(dev
);
2596 if (port
->state
== EHEA_PORT_UP
)
2599 ret
= ehea_port_res_setup(port
, port
->num_def_qps
,
2600 port
->num_add_tx_qps
);
2602 netdev_err(dev
, "port_res_failed\n");
2606 /* Set default QP for this port */
2607 ret
= ehea_configure_port(port
);
2609 netdev_err(dev
, "ehea_configure_port failed. ret:%d\n", ret
);
2613 ret
= ehea_reg_interrupts(dev
);
2615 netdev_err(dev
, "reg_interrupts failed. ret:%d\n", ret
);
2619 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2620 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2622 netdev_err(dev
, "activate_qp failed\n");
2627 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2628 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2630 netdev_err(dev
, "out_free_irqs\n");
2635 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2641 port
->state
= EHEA_PORT_UP
;
2647 ehea_free_interrupts(dev
);
2650 ehea_clean_all_portres(port
);
2653 netdev_info(dev
, "Failed starting. ret=%i\n", ret
);
2655 ehea_update_bcmc_registrations();
2656 ehea_update_firmware_handles();
2661 static void port_napi_disable(struct ehea_port
*port
)
2665 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2666 napi_disable(&port
->port_res
[i
].napi
);
2669 static void port_napi_enable(struct ehea_port
*port
)
2673 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2674 napi_enable(&port
->port_res
[i
].napi
);
2677 static int ehea_open(struct net_device
*dev
)
2680 struct ehea_port
*port
= netdev_priv(dev
);
2682 mutex_lock(&port
->port_lock
);
2684 netif_info(port
, ifup
, dev
, "enabling port\n");
2688 port_napi_enable(port
);
2689 netif_start_queue(dev
);
2692 mutex_unlock(&port
->port_lock
);
2697 static int ehea_down(struct net_device
*dev
)
2700 struct ehea_port
*port
= netdev_priv(dev
);
2702 if (port
->state
== EHEA_PORT_DOWN
)
2705 ehea_drop_multicast_list(dev
);
2706 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2708 ehea_free_interrupts(dev
);
2710 port
->state
= EHEA_PORT_DOWN
;
2712 ehea_update_bcmc_registrations();
2714 ret
= ehea_clean_all_portres(port
);
2716 netdev_info(dev
, "Failed freeing resources. ret=%i\n", ret
);
2718 ehea_update_firmware_handles();
2723 static int ehea_stop(struct net_device
*dev
)
2726 struct ehea_port
*port
= netdev_priv(dev
);
2728 netif_info(port
, ifdown
, dev
, "disabling port\n");
2730 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2731 cancel_work_sync(&port
->reset_task
);
2732 mutex_lock(&port
->port_lock
);
2733 netif_stop_queue(dev
);
2734 port_napi_disable(port
);
2735 ret
= ehea_down(dev
);
2736 mutex_unlock(&port
->port_lock
);
2737 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2741 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2743 struct ehea_qp qp
= *orig_qp
;
2744 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2745 struct ehea_swqe
*swqe
;
2749 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2750 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2751 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2755 static void ehea_flush_sq(struct ehea_port
*port
)
2759 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2760 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2761 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2764 ret
= wait_event_timeout(port
->swqe_avail_wq
,
2765 atomic_read(&pr
->swqe_avail
) >= swqe_max
,
2766 msecs_to_jiffies(100));
2769 pr_err("WARNING: sq not flushed completely\n");
2775 int ehea_stop_qps(struct net_device
*dev
)
2777 struct ehea_port
*port
= netdev_priv(dev
);
2778 struct ehea_adapter
*adapter
= port
->adapter
;
2779 struct hcp_modify_qp_cb0
*cb0
;
2787 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2793 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2794 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2795 struct ehea_qp
*qp
= pr
->qp
;
2797 /* Purge send queue */
2800 /* Disable queue pair */
2801 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2802 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2804 if (hret
!= H_SUCCESS
) {
2805 pr_err("query_ehea_qp failed (1)\n");
2809 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2810 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2812 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2813 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2815 &dummy64
, &dummy16
, &dummy16
);
2816 if (hret
!= H_SUCCESS
) {
2817 pr_err("modify_ehea_qp failed (1)\n");
2821 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2822 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2824 if (hret
!= H_SUCCESS
) {
2825 pr_err("query_ehea_qp failed (2)\n");
2829 /* deregister shared memory regions */
2830 dret
= ehea_rem_smrs(pr
);
2832 pr_err("unreg shared memory region failed\n");
2839 free_page((unsigned long)cb0
);
2844 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2846 struct ehea_qp qp
= *orig_qp
;
2847 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2848 struct ehea_rwqe
*rwqe
;
2849 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2850 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2851 struct sk_buff
*skb
;
2852 u32 lkey
= pr
->recv_mr
.lkey
;
2858 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2859 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2860 rwqe
->sg_list
[0].l_key
= lkey
;
2861 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2862 skb
= skba_rq2
[index
];
2864 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2867 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2868 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2869 rwqe
->sg_list
[0].l_key
= lkey
;
2870 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2871 skb
= skba_rq3
[index
];
2873 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2877 int ehea_restart_qps(struct net_device
*dev
)
2879 struct ehea_port
*port
= netdev_priv(dev
);
2880 struct ehea_adapter
*adapter
= port
->adapter
;
2884 struct hcp_modify_qp_cb0
*cb0
;
2889 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2895 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2896 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2897 struct ehea_qp
*qp
= pr
->qp
;
2899 ret
= ehea_gen_smrs(pr
);
2901 netdev_err(dev
, "creation of shared memory regions failed\n");
2905 ehea_update_rqs(qp
, pr
);
2907 /* Enable queue pair */
2908 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2909 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2911 if (hret
!= H_SUCCESS
) {
2912 netdev_err(dev
, "query_ehea_qp failed (1)\n");
2916 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2917 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2919 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2920 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2922 &dummy64
, &dummy16
, &dummy16
);
2923 if (hret
!= H_SUCCESS
) {
2924 netdev_err(dev
, "modify_ehea_qp failed (1)\n");
2928 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2929 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2931 if (hret
!= H_SUCCESS
) {
2932 netdev_err(dev
, "query_ehea_qp failed (2)\n");
2936 /* refill entire queue */
2937 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2938 ehea_refill_rq2(pr
, 0);
2939 ehea_refill_rq3(pr
, 0);
2942 free_page((unsigned long)cb0
);
2947 static void ehea_reset_port(struct work_struct
*work
)
2950 struct ehea_port
*port
=
2951 container_of(work
, struct ehea_port
, reset_task
);
2952 struct net_device
*dev
= port
->netdev
;
2954 mutex_lock(&dlpar_mem_lock
);
2956 mutex_lock(&port
->port_lock
);
2957 netif_stop_queue(dev
);
2959 port_napi_disable(port
);
2967 ehea_set_multicast_list(dev
);
2969 netif_info(port
, timer
, dev
, "reset successful\n");
2971 port_napi_enable(port
);
2973 netif_wake_queue(dev
);
2975 mutex_unlock(&port
->port_lock
);
2976 mutex_unlock(&dlpar_mem_lock
);
2979 static void ehea_rereg_mrs(void)
2982 struct ehea_adapter
*adapter
;
2984 pr_info("LPAR memory changed - re-initializing driver\n");
2986 list_for_each_entry(adapter
, &adapter_list
, list
)
2987 if (adapter
->active_ports
) {
2988 /* Shutdown all ports */
2989 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2990 struct ehea_port
*port
= adapter
->port
[i
];
2991 struct net_device
*dev
;
2998 if (dev
->flags
& IFF_UP
) {
2999 mutex_lock(&port
->port_lock
);
3000 netif_stop_queue(dev
);
3001 ehea_flush_sq(port
);
3002 ret
= ehea_stop_qps(dev
);
3004 mutex_unlock(&port
->port_lock
);
3007 port_napi_disable(port
);
3008 mutex_unlock(&port
->port_lock
);
3010 reset_sq_restart_flag(port
);
3013 /* Unregister old memory region */
3014 ret
= ehea_rem_mr(&adapter
->mr
);
3016 pr_err("unregister MR failed - driver inoperable!\n");
3021 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3023 list_for_each_entry(adapter
, &adapter_list
, list
)
3024 if (adapter
->active_ports
) {
3025 /* Register new memory region */
3026 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
3028 pr_err("register MR failed - driver inoperable!\n");
3032 /* Restart all ports */
3033 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
3034 struct ehea_port
*port
= adapter
->port
[i
];
3037 struct net_device
*dev
= port
->netdev
;
3039 if (dev
->flags
& IFF_UP
) {
3040 mutex_lock(&port
->port_lock
);
3041 ret
= ehea_restart_qps(dev
);
3044 port_napi_enable(port
);
3045 netif_wake_queue(dev
);
3047 netdev_err(dev
, "Unable to restart QPS\n");
3049 mutex_unlock(&port
->port_lock
);
3054 pr_info("re-initializing driver complete\n");
3059 static void ehea_tx_watchdog(struct net_device
*dev
)
3061 struct ehea_port
*port
= netdev_priv(dev
);
3063 if (netif_carrier_ok(dev
) &&
3064 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
3065 ehea_schedule_port_reset(port
);
3068 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
3070 struct hcp_query_ehea
*cb
;
3074 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
3080 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
3082 if (hret
!= H_SUCCESS
) {
3087 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
3091 free_page((unsigned long)cb
);
3096 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
3098 struct hcp_ehea_port_cb4
*cb4
;
3104 /* (Try to) enable *jumbo frames */
3105 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
3107 pr_err("no mem for cb4\n");
3111 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
3112 port
->logical_port_id
,
3114 H_PORT_CB4_JUMBO
, cb4
);
3115 if (hret
== H_SUCCESS
) {
3116 if (cb4
->jumbo_frame
)
3119 cb4
->jumbo_frame
= 1;
3120 hret
= ehea_h_modify_ehea_port(port
->adapter
->
3127 if (hret
== H_SUCCESS
)
3133 free_page((unsigned long)cb4
);
3139 static ssize_t
ehea_show_port_id(struct device
*dev
,
3140 struct device_attribute
*attr
, char *buf
)
3142 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
3143 return sprintf(buf
, "%d", port
->logical_port_id
);
3146 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
3149 static void __devinit
logical_port_release(struct device
*dev
)
3151 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
3152 of_node_put(port
->ofdev
.dev
.of_node
);
3155 static struct device
*ehea_register_port(struct ehea_port
*port
,
3156 struct device_node
*dn
)
3160 port
->ofdev
.dev
.of_node
= of_node_get(dn
);
3161 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
3162 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
3164 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
3165 port
->ofdev
.dev
.release
= logical_port_release
;
3167 ret
= of_device_register(&port
->ofdev
);
3169 pr_err("failed to register device. ret=%d\n", ret
);
3173 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3175 pr_err("failed to register attributes, ret=%d\n", ret
);
3176 goto out_unreg_of_dev
;
3179 return &port
->ofdev
.dev
;
3182 of_device_unregister(&port
->ofdev
);
3187 static void ehea_unregister_port(struct ehea_port
*port
)
3189 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3190 of_device_unregister(&port
->ofdev
);
3193 static const struct net_device_ops ehea_netdev_ops
= {
3194 .ndo_open
= ehea_open
,
3195 .ndo_stop
= ehea_stop
,
3196 .ndo_start_xmit
= ehea_start_xmit
,
3197 #ifdef CONFIG_NET_POLL_CONTROLLER
3198 .ndo_poll_controller
= ehea_netpoll
,
3200 .ndo_get_stats
= ehea_get_stats
,
3201 .ndo_set_mac_address
= ehea_set_mac_addr
,
3202 .ndo_validate_addr
= eth_validate_addr
,
3203 .ndo_set_multicast_list
= ehea_set_multicast_list
,
3204 .ndo_change_mtu
= ehea_change_mtu
,
3205 .ndo_vlan_rx_register
= ehea_vlan_rx_register
,
3206 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
3207 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
3208 .ndo_tx_timeout
= ehea_tx_watchdog
,
3211 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
3212 u32 logical_port_id
,
3213 struct device_node
*dn
)
3216 struct net_device
*dev
;
3217 struct ehea_port
*port
;
3218 struct device
*port_dev
;
3221 /* allocate memory for the port structures */
3222 dev
= alloc_etherdev(sizeof(struct ehea_port
));
3225 pr_err("no mem for net_device\n");
3230 port
= netdev_priv(dev
);
3232 mutex_init(&port
->port_lock
);
3233 port
->state
= EHEA_PORT_DOWN
;
3234 port
->sig_comp_iv
= sq_entries
/ 10;
3236 port
->adapter
= adapter
;
3238 port
->logical_port_id
= logical_port_id
;
3240 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3242 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3243 if (!port
->mc_list
) {
3245 goto out_free_ethdev
;
3248 INIT_LIST_HEAD(&port
->mc_list
->list
);
3250 ret
= ehea_sense_port_attr(port
);
3252 goto out_free_mc_list
;
3254 port_dev
= ehea_register_port(port
, dn
);
3256 goto out_free_mc_list
;
3258 SET_NETDEV_DEV(dev
, port_dev
);
3260 /* initialize net_device structure */
3261 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3263 dev
->netdev_ops
= &ehea_netdev_ops
;
3264 ehea_set_ethtool_ops(dev
);
3266 dev
->hw_features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3267 | NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
| NETIF_F_LRO
;
3268 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3269 | NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
3270 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3271 | NETIF_F_LLTX
| NETIF_F_RXCSUM
;
3272 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3275 dev
->features
|= NETIF_F_LRO
;
3277 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3279 init_waitqueue_head(&port
->swqe_avail_wq
);
3280 init_waitqueue_head(&port
->restart_wq
);
3282 ret
= register_netdev(dev
);
3284 pr_err("register_netdev failed. ret=%d\n", ret
);
3285 goto out_unreg_port
;
3288 port
->lro_max_aggr
= lro_max_aggr
;
3290 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3292 netdev_err(dev
, "failed determining jumbo frame status\n");
3294 netdev_info(dev
, "Jumbo frames are %sabled\n",
3295 jumbo
== 1 ? "en" : "dis");
3297 adapter
->active_ports
++;
3302 ehea_unregister_port(port
);
3305 kfree(port
->mc_list
);
3311 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3312 logical_port_id
, ret
);
3316 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3318 struct ehea_adapter
*adapter
= port
->adapter
;
3320 cancel_work_sync(&port
->reset_task
);
3321 unregister_netdev(port
->netdev
);
3322 ehea_unregister_port(port
);
3323 kfree(port
->mc_list
);
3324 free_netdev(port
->netdev
);
3325 adapter
->active_ports
--;
3328 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3330 struct device_node
*lhea_dn
;
3331 struct device_node
*eth_dn
= NULL
;
3333 const u32
*dn_log_port_id
;
3336 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3337 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3339 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3341 if (!dn_log_port_id
) {
3342 pr_err("bad device node: eth_dn name=%s\n",
3347 if (ehea_add_adapter_mr(adapter
)) {
3348 pr_err("creating MR failed\n");
3349 of_node_put(eth_dn
);
3353 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3356 if (adapter
->port
[i
])
3357 netdev_info(adapter
->port
[i
]->netdev
,
3358 "logical port id #%d\n", *dn_log_port_id
);
3360 ehea_remove_adapter_mr(adapter
);
3367 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3368 u32 logical_port_id
)
3370 struct device_node
*lhea_dn
;
3371 struct device_node
*eth_dn
= NULL
;
3372 const u32
*dn_log_port_id
;
3374 lhea_dn
= adapter
->ofdev
->dev
.of_node
;
3375 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3377 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3380 if (*dn_log_port_id
== logical_port_id
)
3387 static ssize_t
ehea_probe_port(struct device
*dev
,
3388 struct device_attribute
*attr
,
3389 const char *buf
, size_t count
)
3391 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3392 struct ehea_port
*port
;
3393 struct device_node
*eth_dn
= NULL
;
3396 u32 logical_port_id
;
3398 sscanf(buf
, "%d", &logical_port_id
);
3400 port
= ehea_get_port(adapter
, logical_port_id
);
3403 netdev_info(port
->netdev
, "adding port with logical port id=%d failed: port already configured\n",
3408 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3411 pr_info("no logical port with id %d found\n", logical_port_id
);
3415 if (ehea_add_adapter_mr(adapter
)) {
3416 pr_err("creating MR failed\n");
3420 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3422 of_node_put(eth_dn
);
3425 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3426 if (!adapter
->port
[i
]) {
3427 adapter
->port
[i
] = port
;
3431 netdev_info(port
->netdev
, "added: (logical port id=%d)\n",
3434 ehea_remove_adapter_mr(adapter
);
3438 return (ssize_t
) count
;
3441 static ssize_t
ehea_remove_port(struct device
*dev
,
3442 struct device_attribute
*attr
,
3443 const char *buf
, size_t count
)
3445 struct ehea_adapter
*adapter
= dev_get_drvdata(dev
);
3446 struct ehea_port
*port
;
3448 u32 logical_port_id
;
3450 sscanf(buf
, "%d", &logical_port_id
);
3452 port
= ehea_get_port(adapter
, logical_port_id
);
3455 netdev_info(port
->netdev
, "removed: (logical port id=%d)\n",
3458 ehea_shutdown_single_port(port
);
3460 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3461 if (adapter
->port
[i
] == port
) {
3462 adapter
->port
[i
] = NULL
;
3466 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3471 ehea_remove_adapter_mr(adapter
);
3473 return (ssize_t
) count
;
3476 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3477 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3479 int ehea_create_device_sysfs(struct platform_device
*dev
)
3481 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3485 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3490 void ehea_remove_device_sysfs(struct platform_device
*dev
)
3492 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3493 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3496 static int __devinit
ehea_probe_adapter(struct platform_device
*dev
,
3497 const struct of_device_id
*id
)
3499 struct ehea_adapter
*adapter
;
3500 const u64
*adapter_handle
;
3503 if (!dev
|| !dev
->dev
.of_node
) {
3504 pr_err("Invalid ibmebus device probed\n");
3508 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3511 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3515 list_add(&adapter
->list
, &adapter_list
);
3517 adapter
->ofdev
= dev
;
3519 adapter_handle
= of_get_property(dev
->dev
.of_node
, "ibm,hea-handle",
3522 adapter
->handle
= *adapter_handle
;
3524 if (!adapter
->handle
) {
3525 dev_err(&dev
->dev
, "failed getting handle for adapter"
3526 " '%s'\n", dev
->dev
.of_node
->full_name
);
3531 adapter
->pd
= EHEA_PD_ID
;
3533 dev_set_drvdata(&dev
->dev
, adapter
);
3536 /* initialize adapter and ports */
3537 /* get adapter properties */
3538 ret
= ehea_sense_adapter_attr(adapter
);
3540 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3544 adapter
->neq
= ehea_create_eq(adapter
,
3545 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3546 if (!adapter
->neq
) {
3548 dev_err(&dev
->dev
, "NEQ creation failed\n");
3552 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3553 (unsigned long)adapter
);
3555 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3556 ehea_interrupt_neq
, IRQF_DISABLED
,
3557 "ehea_neq", adapter
);
3559 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3563 ret
= ehea_create_device_sysfs(dev
);
3567 ret
= ehea_setup_ports(adapter
);
3569 dev_err(&dev
->dev
, "setup_ports failed\n");
3570 goto out_rem_dev_sysfs
;
3577 ehea_remove_device_sysfs(dev
);
3580 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3583 ehea_destroy_eq(adapter
->neq
);
3586 list_del(&adapter
->list
);
3590 ehea_update_firmware_handles();
3595 static int __devexit
ehea_remove(struct platform_device
*dev
)
3597 struct ehea_adapter
*adapter
= dev_get_drvdata(&dev
->dev
);
3600 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3601 if (adapter
->port
[i
]) {
3602 ehea_shutdown_single_port(adapter
->port
[i
]);
3603 adapter
->port
[i
] = NULL
;
3606 ehea_remove_device_sysfs(dev
);
3608 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3609 tasklet_kill(&adapter
->neq_tasklet
);
3611 ehea_destroy_eq(adapter
->neq
);
3612 ehea_remove_adapter_mr(adapter
);
3613 list_del(&adapter
->list
);
3616 ehea_update_firmware_handles();
3621 void ehea_crash_handler(void)
3625 if (ehea_fw_handles
.arr
)
3626 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3627 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3628 ehea_fw_handles
.arr
[i
].fwh
,
3631 if (ehea_bcmc_regs
.arr
)
3632 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3633 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3634 ehea_bcmc_regs
.arr
[i
].port_id
,
3635 ehea_bcmc_regs
.arr
[i
].reg_type
,
3636 ehea_bcmc_regs
.arr
[i
].macaddr
,
3640 static int ehea_mem_notifier(struct notifier_block
*nb
,
3641 unsigned long action
, void *data
)
3643 int ret
= NOTIFY_BAD
;
3644 struct memory_notify
*arg
= data
;
3646 mutex_lock(&dlpar_mem_lock
);
3649 case MEM_CANCEL_OFFLINE
:
3650 pr_info("memory offlining canceled");
3651 /* Readd canceled memory block */
3653 pr_info("memory is going online");
3654 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3655 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3659 case MEM_GOING_OFFLINE
:
3660 pr_info("memory is going offline");
3661 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3662 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3670 ehea_update_firmware_handles();
3674 mutex_unlock(&dlpar_mem_lock
);
3678 static struct notifier_block ehea_mem_nb
= {
3679 .notifier_call
= ehea_mem_notifier
,
3682 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3683 unsigned long action
, void *unused
)
3685 if (action
== SYS_RESTART
) {
3686 pr_info("Reboot: freeing all eHEA resources\n");
3687 ibmebus_unregister_driver(&ehea_driver
);
3692 static struct notifier_block ehea_reboot_nb
= {
3693 .notifier_call
= ehea_reboot_notifier
,
3696 static int check_module_parm(void)
3700 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3701 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3702 pr_info("Bad parameter: rq1_entries\n");
3705 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3706 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3707 pr_info("Bad parameter: rq2_entries\n");
3710 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3711 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3712 pr_info("Bad parameter: rq3_entries\n");
3715 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3716 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3717 pr_info("Bad parameter: sq_entries\n");
3724 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3727 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3730 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3731 ehea_show_capabilities
, NULL
);
3733 int __init
ehea_module_init(void)
3737 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION
);
3739 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3740 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3742 mutex_init(&ehea_fw_handles
.lock
);
3743 spin_lock_init(&ehea_bcmc_regs
.lock
);
3745 ret
= check_module_parm();
3749 ret
= ehea_create_busmap();
3753 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3755 pr_info("failed registering reboot notifier\n");
3757 ret
= register_memory_notifier(&ehea_mem_nb
);
3759 pr_info("failed registering memory remove notifier\n");
3761 ret
= crash_shutdown_register(ehea_crash_handler
);
3763 pr_info("failed registering crash handler\n");
3765 ret
= ibmebus_register_driver(&ehea_driver
);
3767 pr_err("failed registering eHEA device driver on ebus\n");
3771 ret
= driver_create_file(&ehea_driver
.driver
,
3772 &driver_attr_capabilities
);
3774 pr_err("failed to register capabilities attribute, ret=%d\n",
3782 ibmebus_unregister_driver(&ehea_driver
);
3784 unregister_memory_notifier(&ehea_mem_nb
);
3785 unregister_reboot_notifier(&ehea_reboot_nb
);
3786 crash_shutdown_unregister(ehea_crash_handler
);
3791 static void __exit
ehea_module_exit(void)
3795 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3796 ibmebus_unregister_driver(&ehea_driver
);
3797 unregister_reboot_notifier(&ehea_reboot_nb
);
3798 ret
= crash_shutdown_unregister(ehea_crash_handler
);
3800 pr_info("failed unregistering crash handler\n");
3801 unregister_memory_notifier(&ehea_mem_nb
);
3802 kfree(ehea_fw_handles
.arr
);
3803 kfree(ehea_bcmc_regs
.arr
);
3804 ehea_destroy_busmap();
3807 module_init(ehea_module_init
);
3808 module_exit(ehea_module_exit
);