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.
31 #include <linux/tcp.h>
32 #include <linux/udp.h>
34 #include <linux/list.h>
35 #include <linux/if_ether.h>
36 #include <linux/notifier.h>
37 #include <linux/reboot.h>
38 #include <linux/memory.h>
39 #include <asm/kexec.h>
40 #include <linux/mutex.h>
46 #include "ehea_phyp.h"
49 MODULE_LICENSE("GPL");
50 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51 MODULE_DESCRIPTION("IBM eServer HEA Driver");
52 MODULE_VERSION(DRV_VERSION
);
55 static int msg_level
= -1;
56 static int rq1_entries
= EHEA_DEF_ENTRIES_RQ1
;
57 static int rq2_entries
= EHEA_DEF_ENTRIES_RQ2
;
58 static int rq3_entries
= EHEA_DEF_ENTRIES_RQ3
;
59 static int sq_entries
= EHEA_DEF_ENTRIES_SQ
;
62 static int lro_max_aggr
= EHEA_LRO_MAX_AGGR
;
63 static int num_tx_qps
= EHEA_NUM_TX_QP
;
64 static int prop_carrier_state
;
66 module_param(msg_level
, int, 0);
67 module_param(rq1_entries
, int, 0);
68 module_param(rq2_entries
, int, 0);
69 module_param(rq3_entries
, int, 0);
70 module_param(sq_entries
, int, 0);
71 module_param(prop_carrier_state
, int, 0);
72 module_param(use_mcs
, int, 0);
73 module_param(use_lro
, int, 0);
74 module_param(lro_max_aggr
, int, 0);
75 module_param(num_tx_qps
, int, 0);
77 MODULE_PARM_DESC(num_tx_qps
, "Number of TX-QPS");
78 MODULE_PARM_DESC(msg_level
, "msg_level");
79 MODULE_PARM_DESC(prop_carrier_state
, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
81 MODULE_PARM_DESC(rq3_entries
, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3
) ")");
84 MODULE_PARM_DESC(rq2_entries
, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2
) ")");
87 MODULE_PARM_DESC(rq1_entries
, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1
) ")");
90 MODULE_PARM_DESC(sq_entries
, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ
) ")");
93 MODULE_PARM_DESC(use_mcs
, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
95 MODULE_PARM_DESC(lro_max_aggr
, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR
));
97 MODULE_PARM_DESC(use_lro
, " Large Receive Offload, 1: enable, 0: disable, "
100 static int port_name_cnt
;
101 static LIST_HEAD(adapter_list
);
102 static unsigned long ehea_driver_flags
;
103 struct work_struct ehea_rereg_mr_task
;
104 static DEFINE_MUTEX(dlpar_mem_lock
);
105 struct ehea_fw_handle_array ehea_fw_handles
;
106 struct ehea_bcmc_reg_array ehea_bcmc_regs
;
109 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
110 const struct of_device_id
*id
);
112 static int __devexit
ehea_remove(struct of_device
*dev
);
114 static struct of_device_id ehea_device_table
[] = {
117 .compatible
= "IBM,lhea",
121 MODULE_DEVICE_TABLE(of
, ehea_device_table
);
123 static struct of_platform_driver ehea_driver
= {
125 .match_table
= ehea_device_table
,
126 .probe
= ehea_probe_adapter
,
127 .remove
= ehea_remove
,
130 void ehea_dump(void *adr
, int len
, char *msg
)
133 unsigned char *deb
= adr
;
134 for (x
= 0; x
< len
; x
+= 16) {
135 printk(DRV_NAME
" %s adr=%p ofs=%04x %016llx %016llx\n", msg
,
136 deb
, x
, *((u64
*)&deb
[0]), *((u64
*)&deb
[8]));
141 void ehea_schedule_port_reset(struct ehea_port
*port
)
143 if (!test_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
))
144 schedule_work(&port
->reset_task
);
147 static void ehea_update_firmware_handles(void)
149 struct ehea_fw_handle_entry
*arr
= NULL
;
150 struct ehea_adapter
*adapter
;
151 int num_adapters
= 0;
155 int num_fw_handles
, k
, l
;
157 /* Determine number of handles */
158 mutex_lock(&ehea_fw_handles
.lock
);
160 list_for_each_entry(adapter
, &adapter_list
, list
) {
163 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
164 struct ehea_port
*port
= adapter
->port
[k
];
166 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
170 num_portres
+= port
->num_def_qps
+ port
->num_add_tx_qps
;
174 num_fw_handles
= num_adapters
* EHEA_NUM_ADAPTER_FW_HANDLES
+
175 num_ports
* EHEA_NUM_PORT_FW_HANDLES
+
176 num_portres
* EHEA_NUM_PORTRES_FW_HANDLES
;
178 if (num_fw_handles
) {
179 arr
= kzalloc(num_fw_handles
* sizeof(*arr
), GFP_KERNEL
);
181 goto out
; /* Keep the existing array */
185 list_for_each_entry(adapter
, &adapter_list
, list
) {
186 if (num_adapters
== 0)
189 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
190 struct ehea_port
*port
= adapter
->port
[k
];
192 if (!port
|| (port
->state
!= EHEA_PORT_UP
)
197 l
< port
->num_def_qps
+ port
->num_add_tx_qps
;
199 struct ehea_port_res
*pr
= &port
->port_res
[l
];
201 arr
[i
].adh
= adapter
->handle
;
202 arr
[i
++].fwh
= pr
->qp
->fw_handle
;
203 arr
[i
].adh
= adapter
->handle
;
204 arr
[i
++].fwh
= pr
->send_cq
->fw_handle
;
205 arr
[i
].adh
= adapter
->handle
;
206 arr
[i
++].fwh
= pr
->recv_cq
->fw_handle
;
207 arr
[i
].adh
= adapter
->handle
;
208 arr
[i
++].fwh
= pr
->eq
->fw_handle
;
209 arr
[i
].adh
= adapter
->handle
;
210 arr
[i
++].fwh
= pr
->send_mr
.handle
;
211 arr
[i
].adh
= adapter
->handle
;
212 arr
[i
++].fwh
= pr
->recv_mr
.handle
;
214 arr
[i
].adh
= adapter
->handle
;
215 arr
[i
++].fwh
= port
->qp_eq
->fw_handle
;
219 arr
[i
].adh
= adapter
->handle
;
220 arr
[i
++].fwh
= adapter
->neq
->fw_handle
;
222 if (adapter
->mr
.handle
) {
223 arr
[i
].adh
= adapter
->handle
;
224 arr
[i
++].fwh
= adapter
->mr
.handle
;
230 kfree(ehea_fw_handles
.arr
);
231 ehea_fw_handles
.arr
= arr
;
232 ehea_fw_handles
.num_entries
= i
;
234 mutex_unlock(&ehea_fw_handles
.lock
);
237 static void ehea_update_bcmc_registrations(void)
240 struct ehea_bcmc_reg_entry
*arr
= NULL
;
241 struct ehea_adapter
*adapter
;
242 struct ehea_mc_list
*mc_entry
;
243 int num_registrations
= 0;
247 spin_lock_irqsave(&ehea_bcmc_regs
.lock
, flags
);
249 /* Determine number of registrations */
250 list_for_each_entry(adapter
, &adapter_list
, list
)
251 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
252 struct ehea_port
*port
= adapter
->port
[k
];
254 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
257 num_registrations
+= 2; /* Broadcast registrations */
259 list_for_each_entry(mc_entry
, &port
->mc_list
->list
,list
)
260 num_registrations
+= 2;
263 if (num_registrations
) {
264 arr
= kzalloc(num_registrations
* sizeof(*arr
), GFP_ATOMIC
);
266 goto out
; /* Keep the existing array */
270 list_for_each_entry(adapter
, &adapter_list
, list
) {
271 for (k
= 0; k
< EHEA_MAX_PORTS
; k
++) {
272 struct ehea_port
*port
= adapter
->port
[k
];
274 if (!port
|| (port
->state
!= EHEA_PORT_UP
))
277 if (num_registrations
== 0)
280 arr
[i
].adh
= adapter
->handle
;
281 arr
[i
].port_id
= port
->logical_port_id
;
282 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
284 arr
[i
++].macaddr
= port
->mac_addr
;
286 arr
[i
].adh
= adapter
->handle
;
287 arr
[i
].port_id
= port
->logical_port_id
;
288 arr
[i
].reg_type
= EHEA_BCMC_BROADCAST
|
289 EHEA_BCMC_VLANID_ALL
;
290 arr
[i
++].macaddr
= port
->mac_addr
;
291 num_registrations
-= 2;
293 list_for_each_entry(mc_entry
,
294 &port
->mc_list
->list
, list
) {
295 if (num_registrations
== 0)
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
|
303 arr
[i
++].macaddr
= mc_entry
->macaddr
;
305 arr
[i
].adh
= adapter
->handle
;
306 arr
[i
].port_id
= port
->logical_port_id
;
307 arr
[i
].reg_type
= EHEA_BCMC_SCOPE_ALL
|
308 EHEA_BCMC_MULTICAST
|
309 EHEA_BCMC_VLANID_ALL
;
310 arr
[i
++].macaddr
= mc_entry
->macaddr
;
311 num_registrations
-= 2;
317 kfree(ehea_bcmc_regs
.arr
);
318 ehea_bcmc_regs
.arr
= arr
;
319 ehea_bcmc_regs
.num_entries
= i
;
321 spin_unlock_irqrestore(&ehea_bcmc_regs
.lock
, flags
);
324 static struct net_device_stats
*ehea_get_stats(struct net_device
*dev
)
326 struct ehea_port
*port
= netdev_priv(dev
);
327 struct net_device_stats
*stats
= &port
->stats
;
328 struct hcp_ehea_port_cb2
*cb2
;
329 u64 hret
, rx_packets
, tx_packets
;
332 memset(stats
, 0, sizeof(*stats
));
334 cb2
= (void *)get_zeroed_page(GFP_ATOMIC
);
336 ehea_error("no mem for cb2");
340 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
341 port
->logical_port_id
,
342 H_PORT_CB2
, H_PORT_CB2_ALL
, cb2
);
343 if (hret
!= H_SUCCESS
) {
344 ehea_error("query_ehea_port failed");
348 if (netif_msg_hw(port
))
349 ehea_dump(cb2
, sizeof(*cb2
), "net_device_stats");
352 for (i
= 0; i
< port
->num_def_qps
; i
++)
353 rx_packets
+= port
->port_res
[i
].rx_packets
;
356 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
357 tx_packets
+= port
->port_res
[i
].tx_packets
;
359 stats
->tx_packets
= tx_packets
;
360 stats
->multicast
= cb2
->rxmcp
;
361 stats
->rx_errors
= cb2
->rxuerr
;
362 stats
->rx_bytes
= cb2
->rxo
;
363 stats
->tx_bytes
= cb2
->txo
;
364 stats
->rx_packets
= rx_packets
;
367 free_page((unsigned long)cb2
);
372 static void ehea_refill_rq1(struct ehea_port_res
*pr
, int index
, int nr_of_wqes
)
374 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
375 struct net_device
*dev
= pr
->port
->netdev
;
376 int max_index_mask
= pr
->rq1_skba
.len
- 1;
377 int fill_wqes
= pr
->rq1_skba
.os_skbs
+ nr_of_wqes
;
381 pr
->rq1_skba
.os_skbs
= 0;
383 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
385 pr
->rq1_skba
.index
= index
;
386 pr
->rq1_skba
.os_skbs
= fill_wqes
;
390 for (i
= 0; i
< fill_wqes
; i
++) {
391 if (!skb_arr_rq1
[index
]) {
392 skb_arr_rq1
[index
] = netdev_alloc_skb(dev
,
394 if (!skb_arr_rq1
[index
]) {
395 pr
->rq1_skba
.os_skbs
= fill_wqes
- i
;
400 index
&= max_index_mask
;
408 ehea_update_rq1a(pr
->qp
, adder
);
411 static void ehea_init_fill_rq1(struct ehea_port_res
*pr
, int nr_rq1a
)
413 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
414 struct net_device
*dev
= pr
->port
->netdev
;
417 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++) {
418 skb_arr_rq1
[i
] = netdev_alloc_skb(dev
, EHEA_L_PKT_SIZE
);
423 ehea_update_rq1a(pr
->qp
, nr_rq1a
);
426 static int ehea_refill_rq_def(struct ehea_port_res
*pr
,
427 struct ehea_q_skb_arr
*q_skba
, int rq_nr
,
428 int num_wqes
, int wqe_type
, int packet_size
)
430 struct net_device
*dev
= pr
->port
->netdev
;
431 struct ehea_qp
*qp
= pr
->qp
;
432 struct sk_buff
**skb_arr
= q_skba
->arr
;
433 struct ehea_rwqe
*rwqe
;
434 int i
, index
, max_index_mask
, fill_wqes
;
438 fill_wqes
= q_skba
->os_skbs
+ num_wqes
;
441 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
442 q_skba
->os_skbs
= fill_wqes
;
446 index
= q_skba
->index
;
447 max_index_mask
= q_skba
->len
- 1;
448 for (i
= 0; i
< fill_wqes
; i
++) {
450 struct sk_buff
*skb
= netdev_alloc_skb(dev
, packet_size
);
452 q_skba
->os_skbs
= fill_wqes
- i
;
453 if (q_skba
->os_skbs
== q_skba
->len
- 2) {
454 ehea_info("%s: rq%i ran dry - no mem for skb",
455 pr
->port
->netdev
->name
, rq_nr
);
460 skb_reserve(skb
, NET_IP_ALIGN
);
462 skb_arr
[index
] = skb
;
463 tmp_addr
= ehea_map_vaddr(skb
->data
);
464 if (tmp_addr
== -1) {
466 q_skba
->os_skbs
= fill_wqes
- i
;
471 rwqe
= ehea_get_next_rwqe(qp
, rq_nr
);
472 rwqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, wqe_type
)
473 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, index
);
474 rwqe
->sg_list
[0].l_key
= pr
->recv_mr
.lkey
;
475 rwqe
->sg_list
[0].vaddr
= tmp_addr
;
476 rwqe
->sg_list
[0].len
= packet_size
;
477 rwqe
->data_segments
= 1;
480 index
&= max_index_mask
;
484 q_skba
->index
= index
;
491 ehea_update_rq2a(pr
->qp
, adder
);
493 ehea_update_rq3a(pr
->qp
, adder
);
499 static int ehea_refill_rq2(struct ehea_port_res
*pr
, int nr_of_wqes
)
501 return ehea_refill_rq_def(pr
, &pr
->rq2_skba
, 2,
502 nr_of_wqes
, EHEA_RWQE2_TYPE
,
503 EHEA_RQ2_PKT_SIZE
+ NET_IP_ALIGN
);
507 static int ehea_refill_rq3(struct ehea_port_res
*pr
, int nr_of_wqes
)
509 return ehea_refill_rq_def(pr
, &pr
->rq3_skba
, 3,
510 nr_of_wqes
, EHEA_RWQE3_TYPE
,
511 EHEA_MAX_PACKET_SIZE
+ NET_IP_ALIGN
);
514 static inline int ehea_check_cqe(struct ehea_cqe
*cqe
, int *rq_num
)
516 *rq_num
= (cqe
->type
& EHEA_CQE_TYPE_RQ
) >> 5;
517 if ((cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) == 0)
519 if (((cqe
->status
& EHEA_CQE_STAT_ERR_TCP
) != 0) &&
520 (cqe
->header_length
== 0))
525 static inline void ehea_fill_skb(struct net_device
*dev
,
526 struct sk_buff
*skb
, struct ehea_cqe
*cqe
)
528 int length
= cqe
->num_bytes_transfered
- 4; /*remove CRC */
530 skb_put(skb
, length
);
531 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
532 skb
->protocol
= eth_type_trans(skb
, dev
);
535 static inline struct sk_buff
*get_skb_by_index(struct sk_buff
**skb_array
,
537 struct ehea_cqe
*cqe
)
539 int skb_index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
550 prefetchw(pref
+ EHEA_CACHE_LINE
);
552 pref
= (skb_array
[x
]->data
);
554 prefetch(pref
+ EHEA_CACHE_LINE
);
555 prefetch(pref
+ EHEA_CACHE_LINE
* 2);
556 prefetch(pref
+ EHEA_CACHE_LINE
* 3);
559 skb
= skb_array
[skb_index
];
560 skb_array
[skb_index
] = NULL
;
564 static inline struct sk_buff
*get_skb_by_index_ll(struct sk_buff
**skb_array
,
565 int arr_len
, int wqe_index
)
577 prefetchw(pref
+ EHEA_CACHE_LINE
);
579 pref
= (skb_array
[x
]->data
);
581 prefetchw(pref
+ EHEA_CACHE_LINE
);
584 skb
= skb_array
[wqe_index
];
585 skb_array
[wqe_index
] = NULL
;
589 static int ehea_treat_poll_error(struct ehea_port_res
*pr
, int rq
,
590 struct ehea_cqe
*cqe
, int *processed_rq2
,
595 if (cqe
->status
& EHEA_CQE_STAT_ERR_TCP
)
596 pr
->p_stats
.err_tcp_cksum
++;
597 if (cqe
->status
& EHEA_CQE_STAT_ERR_IP
)
598 pr
->p_stats
.err_ip_cksum
++;
599 if (cqe
->status
& EHEA_CQE_STAT_ERR_CRC
)
600 pr
->p_stats
.err_frame_crc
++;
604 skb
= get_skb_by_index(pr
->rq2_skba
.arr
, pr
->rq2_skba
.len
, cqe
);
606 } else if (rq
== 3) {
608 skb
= get_skb_by_index(pr
->rq3_skba
.arr
, pr
->rq3_skba
.len
, cqe
);
612 if (cqe
->status
& EHEA_CQE_STAT_FAT_ERR_MASK
) {
613 if (netif_msg_rx_err(pr
->port
)) {
614 ehea_error("Critical receive error for QP %d. "
615 "Resetting port.", pr
->qp
->init_attr
.qp_nr
);
616 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
618 ehea_schedule_port_reset(pr
->port
);
625 static int get_skb_hdr(struct sk_buff
*skb
, void **iphdr
,
626 void **tcph
, u64
*hdr_flags
, void *priv
)
628 struct ehea_cqe
*cqe
= priv
;
632 /* non tcp/udp packets */
633 if (!cqe
->header_length
)
637 skb_reset_network_header(skb
);
639 if (iph
->protocol
!= IPPROTO_TCP
)
642 ip_len
= ip_hdrlen(skb
);
643 skb_set_transport_header(skb
, ip_len
);
644 *tcph
= tcp_hdr(skb
);
646 /* check if ip header and tcp header are complete */
647 if (ntohs(iph
->tot_len
) < ip_len
+ tcp_hdrlen(skb
))
650 *hdr_flags
= LRO_IPV4
| LRO_TCP
;
656 static void ehea_proc_skb(struct ehea_port_res
*pr
, struct ehea_cqe
*cqe
,
659 int vlan_extracted
= (cqe
->status
& EHEA_CQE_VLAN_TAG_XTRACT
)
664 lro_vlan_hwaccel_receive_skb(&pr
->lro_mgr
, skb
,
669 lro_receive_skb(&pr
->lro_mgr
, skb
, cqe
);
672 vlan_hwaccel_receive_skb(skb
, pr
->port
->vgrp
,
675 netif_receive_skb(skb
);
679 static int ehea_proc_rwqes(struct net_device
*dev
,
680 struct ehea_port_res
*pr
,
683 struct ehea_port
*port
= pr
->port
;
684 struct ehea_qp
*qp
= pr
->qp
;
685 struct ehea_cqe
*cqe
;
687 struct sk_buff
**skb_arr_rq1
= pr
->rq1_skba
.arr
;
688 struct sk_buff
**skb_arr_rq2
= pr
->rq2_skba
.arr
;
689 struct sk_buff
**skb_arr_rq3
= pr
->rq3_skba
.arr
;
690 int skb_arr_rq1_len
= pr
->rq1_skba
.len
;
691 int skb_arr_rq2_len
= pr
->rq2_skba
.len
;
692 int skb_arr_rq3_len
= pr
->rq3_skba
.len
;
693 int processed
, processed_rq1
, processed_rq2
, processed_rq3
;
694 int wqe_index
, last_wqe_index
, rq
, port_reset
;
696 processed
= processed_rq1
= processed_rq2
= processed_rq3
= 0;
699 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
700 while ((processed
< budget
) && cqe
) {
704 if (netif_msg_rx_status(port
))
705 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
707 last_wqe_index
= wqe_index
;
709 if (!ehea_check_cqe(cqe
, &rq
)) {
712 skb
= get_skb_by_index_ll(skb_arr_rq1
,
715 if (unlikely(!skb
)) {
716 if (netif_msg_rx_err(port
))
717 ehea_error("LL rq1: skb=NULL");
719 skb
= netdev_alloc_skb(dev
,
724 skb_copy_to_linear_data(skb
, ((char *)cqe
) + 64,
725 cqe
->num_bytes_transfered
- 4);
726 ehea_fill_skb(dev
, skb
, cqe
);
727 } else if (rq
== 2) {
729 skb
= get_skb_by_index(skb_arr_rq2
,
730 skb_arr_rq2_len
, cqe
);
731 if (unlikely(!skb
)) {
732 if (netif_msg_rx_err(port
))
733 ehea_error("rq2: skb=NULL");
736 ehea_fill_skb(dev
, skb
, cqe
);
740 skb
= get_skb_by_index(skb_arr_rq3
,
741 skb_arr_rq3_len
, cqe
);
742 if (unlikely(!skb
)) {
743 if (netif_msg_rx_err(port
))
744 ehea_error("rq3: skb=NULL");
747 ehea_fill_skb(dev
, skb
, cqe
);
751 ehea_proc_skb(pr
, cqe
, skb
);
753 pr
->p_stats
.poll_receive_errors
++;
754 port_reset
= ehea_treat_poll_error(pr
, rq
, cqe
,
760 cqe
= ehea_poll_rq1(qp
, &wqe_index
);
763 lro_flush_all(&pr
->lro_mgr
);
765 pr
->rx_packets
+= processed
;
767 ehea_refill_rq1(pr
, last_wqe_index
, processed_rq1
);
768 ehea_refill_rq2(pr
, processed_rq2
);
769 ehea_refill_rq3(pr
, processed_rq3
);
774 static struct ehea_cqe
*ehea_proc_cqes(struct ehea_port_res
*pr
, int my_quota
)
777 struct ehea_cq
*send_cq
= pr
->send_cq
;
778 struct ehea_cqe
*cqe
;
779 int quota
= my_quota
;
785 cqe
= ehea_poll_cq(send_cq
);
786 while (cqe
&& (quota
> 0)) {
787 ehea_inc_cq(send_cq
);
791 if (cqe
->status
& EHEA_CQE_STAT_ERR_MASK
) {
792 ehea_error("Send Completion Error: Resetting port");
793 if (netif_msg_tx_err(pr
->port
))
794 ehea_dump(cqe
, sizeof(*cqe
), "Send CQE");
795 ehea_schedule_port_reset(pr
->port
);
799 if (netif_msg_tx_done(pr
->port
))
800 ehea_dump(cqe
, sizeof(*cqe
), "CQE");
802 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE
, cqe
->wr_id
)
803 == EHEA_SWQE2_TYPE
)) {
805 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, cqe
->wr_id
);
806 skb
= pr
->sq_skba
.arr
[index
];
808 pr
->sq_skba
.arr
[index
] = NULL
;
811 swqe_av
+= EHEA_BMASK_GET(EHEA_WR_ID_REFILL
, cqe
->wr_id
);
814 cqe
= ehea_poll_cq(send_cq
);
817 ehea_update_feca(send_cq
, cqe_counter
);
818 atomic_add(swqe_av
, &pr
->swqe_avail
);
820 spin_lock_irqsave(&pr
->netif_queue
, flags
);
822 if (pr
->queue_stopped
&& (atomic_read(&pr
->swqe_avail
)
823 >= pr
->swqe_refill_th
)) {
824 netif_wake_queue(pr
->port
->netdev
);
825 pr
->queue_stopped
= 0;
827 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
832 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
833 #define EHEA_POLL_MAX_CQES 65535
835 static int ehea_poll(struct napi_struct
*napi
, int budget
)
837 struct ehea_port_res
*pr
= container_of(napi
, struct ehea_port_res
,
839 struct net_device
*dev
= pr
->port
->netdev
;
840 struct ehea_cqe
*cqe
;
841 struct ehea_cqe
*cqe_skb
= NULL
;
842 int force_irq
, wqe_index
;
845 force_irq
= (pr
->poll_counter
> EHEA_NAPI_POLL_NUM_BEFORE_IRQ
);
846 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
849 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
851 while ((rx
!= budget
) || force_irq
) {
852 pr
->poll_counter
= 0;
855 ehea_reset_cq_ep(pr
->recv_cq
);
856 ehea_reset_cq_ep(pr
->send_cq
);
857 ehea_reset_cq_n1(pr
->recv_cq
);
858 ehea_reset_cq_n1(pr
->send_cq
);
859 cqe
= ehea_poll_rq1(pr
->qp
, &wqe_index
);
860 cqe_skb
= ehea_poll_cq(pr
->send_cq
);
862 if (!cqe
&& !cqe_skb
)
865 if (!napi_reschedule(napi
))
868 cqe_skb
= ehea_proc_cqes(pr
, EHEA_POLL_MAX_CQES
);
869 rx
+= ehea_proc_rwqes(dev
, pr
, budget
- rx
);
876 #ifdef CONFIG_NET_POLL_CONTROLLER
877 static void ehea_netpoll(struct net_device
*dev
)
879 struct ehea_port
*port
= netdev_priv(dev
);
882 for (i
= 0; i
< port
->num_def_qps
; i
++)
883 napi_schedule(&port
->port_res
[i
].napi
);
887 static irqreturn_t
ehea_recv_irq_handler(int irq
, void *param
)
889 struct ehea_port_res
*pr
= param
;
891 napi_schedule(&pr
->napi
);
896 static irqreturn_t
ehea_qp_aff_irq_handler(int irq
, void *param
)
898 struct ehea_port
*port
= param
;
899 struct ehea_eqe
*eqe
;
903 eqe
= ehea_poll_eq(port
->qp_eq
);
906 qp_token
= EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN
, eqe
->entry
);
907 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
908 eqe
->entry
, qp_token
);
910 qp
= port
->port_res
[qp_token
].qp
;
911 ehea_error_data(port
->adapter
, qp
->fw_handle
);
912 eqe
= ehea_poll_eq(port
->qp_eq
);
915 ehea_schedule_port_reset(port
);
920 static struct ehea_port
*ehea_get_port(struct ehea_adapter
*adapter
,
925 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
926 if (adapter
->port
[i
])
927 if (adapter
->port
[i
]->logical_port_id
== logical_port
)
928 return adapter
->port
[i
];
932 int ehea_sense_port_attr(struct ehea_port
*port
)
936 struct hcp_ehea_port_cb0
*cb0
;
938 /* may be called via ehea_neq_tasklet() */
939 cb0
= (void *)get_zeroed_page(GFP_ATOMIC
);
941 ehea_error("no mem for cb0");
946 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
947 port
->logical_port_id
, H_PORT_CB0
,
948 EHEA_BMASK_SET(H_PORT_CB0_ALL
, 0xFFFF),
950 if (hret
!= H_SUCCESS
) {
956 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
958 if (!is_valid_ether_addr((u8
*)&port
->mac_addr
)) {
959 ret
= -EADDRNOTAVAIL
;
964 switch (cb0
->port_speed
) {
966 port
->port_speed
= EHEA_SPEED_10M
;
967 port
->full_duplex
= 0;
970 port
->port_speed
= EHEA_SPEED_10M
;
971 port
->full_duplex
= 1;
974 port
->port_speed
= EHEA_SPEED_100M
;
975 port
->full_duplex
= 0;
978 port
->port_speed
= EHEA_SPEED_100M
;
979 port
->full_duplex
= 1;
982 port
->port_speed
= EHEA_SPEED_1G
;
983 port
->full_duplex
= 1;
986 port
->port_speed
= EHEA_SPEED_10G
;
987 port
->full_duplex
= 1;
990 port
->port_speed
= 0;
991 port
->full_duplex
= 0;
996 port
->num_mcs
= cb0
->num_default_qps
;
998 /* Number of default QPs */
1000 port
->num_def_qps
= cb0
->num_default_qps
;
1002 port
->num_def_qps
= 1;
1004 if (!port
->num_def_qps
) {
1009 port
->num_tx_qps
= num_tx_qps
;
1011 if (port
->num_def_qps
>= port
->num_tx_qps
)
1012 port
->num_add_tx_qps
= 0;
1014 port
->num_add_tx_qps
= port
->num_tx_qps
- port
->num_def_qps
;
1018 if (ret
|| netif_msg_probe(port
))
1019 ehea_dump(cb0
, sizeof(*cb0
), "ehea_sense_port_attr");
1020 free_page((unsigned long)cb0
);
1025 int ehea_set_portspeed(struct ehea_port
*port
, u32 port_speed
)
1027 struct hcp_ehea_port_cb4
*cb4
;
1031 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
1033 ehea_error("no mem for cb4");
1038 cb4
->port_speed
= port_speed
;
1040 netif_carrier_off(port
->netdev
);
1042 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1043 port
->logical_port_id
,
1044 H_PORT_CB4
, H_PORT_CB4_SPEED
, cb4
);
1045 if (hret
== H_SUCCESS
) {
1046 port
->autoneg
= port_speed
== EHEA_SPEED_AUTONEG
? 1 : 0;
1048 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
1049 port
->logical_port_id
,
1050 H_PORT_CB4
, H_PORT_CB4_SPEED
,
1052 if (hret
== H_SUCCESS
) {
1053 switch (cb4
->port_speed
) {
1055 port
->port_speed
= EHEA_SPEED_10M
;
1056 port
->full_duplex
= 0;
1059 port
->port_speed
= EHEA_SPEED_10M
;
1060 port
->full_duplex
= 1;
1062 case H_SPEED_100M_H
:
1063 port
->port_speed
= EHEA_SPEED_100M
;
1064 port
->full_duplex
= 0;
1066 case H_SPEED_100M_F
:
1067 port
->port_speed
= EHEA_SPEED_100M
;
1068 port
->full_duplex
= 1;
1071 port
->port_speed
= EHEA_SPEED_1G
;
1072 port
->full_duplex
= 1;
1075 port
->port_speed
= EHEA_SPEED_10G
;
1076 port
->full_duplex
= 1;
1079 port
->port_speed
= 0;
1080 port
->full_duplex
= 0;
1084 ehea_error("Failed sensing port speed");
1088 if (hret
== H_AUTHORITY
) {
1089 ehea_info("Hypervisor denied setting port speed");
1093 ehea_error("Failed setting port speed");
1096 if (!prop_carrier_state
|| (port
->phy_link
== EHEA_PHY_LINK_UP
))
1097 netif_carrier_on(port
->netdev
);
1099 free_page((unsigned long)cb4
);
1104 static void ehea_parse_eqe(struct ehea_adapter
*adapter
, u64 eqe
)
1109 struct ehea_port
*port
;
1111 ec
= EHEA_BMASK_GET(NEQE_EVENT_CODE
, eqe
);
1112 portnum
= EHEA_BMASK_GET(NEQE_PORTNUM
, eqe
);
1113 port
= ehea_get_port(adapter
, portnum
);
1116 case EHEA_EC_PORTSTATE_CHG
: /* port state change */
1119 ehea_error("unknown portnum %x", portnum
);
1123 if (EHEA_BMASK_GET(NEQE_PORT_UP
, eqe
)) {
1124 if (!netif_carrier_ok(port
->netdev
)) {
1125 ret
= ehea_sense_port_attr(port
);
1127 ehea_error("failed resensing port "
1132 if (netif_msg_link(port
))
1133 ehea_info("%s: Logical port up: %dMbps "
1137 port
->full_duplex
==
1138 1 ? "Full" : "Half");
1140 netif_carrier_on(port
->netdev
);
1141 netif_wake_queue(port
->netdev
);
1144 if (netif_carrier_ok(port
->netdev
)) {
1145 if (netif_msg_link(port
))
1146 ehea_info("%s: Logical port down",
1147 port
->netdev
->name
);
1148 netif_carrier_off(port
->netdev
);
1149 netif_stop_queue(port
->netdev
);
1152 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP
, eqe
)) {
1153 port
->phy_link
= EHEA_PHY_LINK_UP
;
1154 if (netif_msg_link(port
))
1155 ehea_info("%s: Physical port up",
1156 port
->netdev
->name
);
1157 if (prop_carrier_state
)
1158 netif_carrier_on(port
->netdev
);
1160 port
->phy_link
= EHEA_PHY_LINK_DOWN
;
1161 if (netif_msg_link(port
))
1162 ehea_info("%s: Physical port down",
1163 port
->netdev
->name
);
1164 if (prop_carrier_state
)
1165 netif_carrier_off(port
->netdev
);
1168 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY
, eqe
))
1169 ehea_info("External switch port is primary port");
1171 ehea_info("External switch port is backup port");
1174 case EHEA_EC_ADAPTER_MALFUNC
:
1175 ehea_error("Adapter malfunction");
1177 case EHEA_EC_PORT_MALFUNC
:
1178 ehea_info("Port malfunction: Device: %s", port
->netdev
->name
);
1179 netif_carrier_off(port
->netdev
);
1180 netif_stop_queue(port
->netdev
);
1183 ehea_error("unknown event code %x, eqe=0x%llX", ec
, eqe
);
1188 static void ehea_neq_tasklet(unsigned long data
)
1190 struct ehea_adapter
*adapter
= (struct ehea_adapter
*)data
;
1191 struct ehea_eqe
*eqe
;
1194 eqe
= ehea_poll_eq(adapter
->neq
);
1195 ehea_debug("eqe=%p", eqe
);
1198 ehea_debug("*eqe=%lx", eqe
->entry
);
1199 ehea_parse_eqe(adapter
, eqe
->entry
);
1200 eqe
= ehea_poll_eq(adapter
->neq
);
1201 ehea_debug("next eqe=%p", eqe
);
1204 event_mask
= EHEA_BMASK_SET(NELR_PORTSTATE_CHG
, 1)
1205 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC
, 1)
1206 | EHEA_BMASK_SET(NELR_PORT_MALFUNC
, 1);
1208 ehea_h_reset_events(adapter
->handle
,
1209 adapter
->neq
->fw_handle
, event_mask
);
1212 static irqreturn_t
ehea_interrupt_neq(int irq
, void *param
)
1214 struct ehea_adapter
*adapter
= param
;
1215 tasklet_hi_schedule(&adapter
->neq_tasklet
);
1220 static int ehea_fill_port_res(struct ehea_port_res
*pr
)
1223 struct ehea_qp_init_attr
*init_attr
= &pr
->qp
->init_attr
;
1225 ehea_init_fill_rq1(pr
, init_attr
->act_nr_rwqes_rq1
1226 - init_attr
->act_nr_rwqes_rq2
1227 - init_attr
->act_nr_rwqes_rq3
- 1);
1229 ret
= ehea_refill_rq2(pr
, init_attr
->act_nr_rwqes_rq2
- 1);
1231 ret
|= ehea_refill_rq3(pr
, init_attr
->act_nr_rwqes_rq3
- 1);
1236 static int ehea_reg_interrupts(struct net_device
*dev
)
1238 struct ehea_port
*port
= netdev_priv(dev
);
1239 struct ehea_port_res
*pr
;
1243 snprintf(port
->int_aff_name
, EHEA_IRQ_NAME_SIZE
- 1, "%s-aff",
1246 ret
= ibmebus_request_irq(port
->qp_eq
->attr
.ist1
,
1247 ehea_qp_aff_irq_handler
,
1248 IRQF_DISABLED
, port
->int_aff_name
, port
);
1250 ehea_error("failed registering irq for qp_aff_irq_handler:"
1251 "ist=%X", port
->qp_eq
->attr
.ist1
);
1255 if (netif_msg_ifup(port
))
1256 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1257 "registered", port
->qp_eq
->attr
.ist1
);
1260 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1261 pr
= &port
->port_res
[i
];
1262 snprintf(pr
->int_send_name
, EHEA_IRQ_NAME_SIZE
- 1,
1263 "%s-queue%d", dev
->name
, i
);
1264 ret
= ibmebus_request_irq(pr
->eq
->attr
.ist1
,
1265 ehea_recv_irq_handler
,
1266 IRQF_DISABLED
, pr
->int_send_name
,
1269 ehea_error("failed registering irq for ehea_queue "
1270 "port_res_nr:%d, ist=%X", i
,
1274 if (netif_msg_ifup(port
))
1275 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1276 "%d registered", pr
->eq
->attr
.ist1
, i
);
1284 u32 ist
= port
->port_res
[i
].eq
->attr
.ist1
;
1285 ibmebus_free_irq(ist
, &port
->port_res
[i
]);
1289 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1290 i
= port
->num_def_qps
;
1296 static void ehea_free_interrupts(struct net_device
*dev
)
1298 struct ehea_port
*port
= netdev_priv(dev
);
1299 struct ehea_port_res
*pr
;
1304 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
1305 pr
= &port
->port_res
[i
];
1306 ibmebus_free_irq(pr
->eq
->attr
.ist1
, pr
);
1307 if (netif_msg_intr(port
))
1308 ehea_info("free send irq for res %d with handle 0x%X",
1309 i
, pr
->eq
->attr
.ist1
);
1312 /* associated events */
1313 ibmebus_free_irq(port
->qp_eq
->attr
.ist1
, port
);
1314 if (netif_msg_intr(port
))
1315 ehea_info("associated event interrupt for handle 0x%X freed",
1316 port
->qp_eq
->attr
.ist1
);
1319 static int ehea_configure_port(struct ehea_port
*port
)
1323 struct hcp_ehea_port_cb0
*cb0
;
1326 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1330 cb0
->port_rc
= EHEA_BMASK_SET(PXLY_RC_VALID
, 1)
1331 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM
, 1)
1332 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM
, 1)
1333 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT
, 1)
1334 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER
,
1335 PXLY_RC_VLAN_FILTER
)
1336 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME
, 1);
1338 for (i
= 0; i
< port
->num_mcs
; i
++)
1340 cb0
->default_qpn_arr
[i
] =
1341 port
->port_res
[i
].qp
->init_attr
.qp_nr
;
1343 cb0
->default_qpn_arr
[i
] =
1344 port
->port_res
[0].qp
->init_attr
.qp_nr
;
1346 if (netif_msg_ifup(port
))
1347 ehea_dump(cb0
, sizeof(*cb0
), "ehea_configure_port");
1349 mask
= EHEA_BMASK_SET(H_PORT_CB0_PRC
, 1)
1350 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY
, 1);
1352 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1353 port
->logical_port_id
,
1354 H_PORT_CB0
, mask
, cb0
);
1356 if (hret
!= H_SUCCESS
)
1362 free_page((unsigned long)cb0
);
1367 int ehea_gen_smrs(struct ehea_port_res
*pr
)
1370 struct ehea_adapter
*adapter
= pr
->port
->adapter
;
1372 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->send_mr
);
1376 ret
= ehea_gen_smr(adapter
, &adapter
->mr
, &pr
->recv_mr
);
1383 ehea_rem_mr(&pr
->send_mr
);
1385 ehea_error("Generating SMRS failed\n");
1389 int ehea_rem_smrs(struct ehea_port_res
*pr
)
1391 if ((ehea_rem_mr(&pr
->send_mr
))
1392 || (ehea_rem_mr(&pr
->recv_mr
)))
1398 static int ehea_init_q_skba(struct ehea_q_skb_arr
*q_skba
, int max_q_entries
)
1400 int arr_size
= sizeof(void *) * max_q_entries
;
1402 q_skba
->arr
= vmalloc(arr_size
);
1406 memset(q_skba
->arr
, 0, arr_size
);
1408 q_skba
->len
= max_q_entries
;
1410 q_skba
->os_skbs
= 0;
1415 static int ehea_init_port_res(struct ehea_port
*port
, struct ehea_port_res
*pr
,
1416 struct port_res_cfg
*pr_cfg
, int queue_token
)
1418 struct ehea_adapter
*adapter
= port
->adapter
;
1419 enum ehea_eq_type eq_type
= EHEA_EQ
;
1420 struct ehea_qp_init_attr
*init_attr
= NULL
;
1423 memset(pr
, 0, sizeof(struct ehea_port_res
));
1426 spin_lock_init(&pr
->xmit_lock
);
1427 spin_lock_init(&pr
->netif_queue
);
1429 pr
->eq
= ehea_create_eq(adapter
, eq_type
, EHEA_MAX_ENTRIES_EQ
, 0);
1431 ehea_error("create_eq failed (eq)");
1435 pr
->recv_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_rcq
,
1437 port
->logical_port_id
);
1439 ehea_error("create_cq failed (cq_recv)");
1443 pr
->send_cq
= ehea_create_cq(adapter
, pr_cfg
->max_entries_scq
,
1445 port
->logical_port_id
);
1447 ehea_error("create_cq failed (cq_send)");
1451 if (netif_msg_ifup(port
))
1452 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1453 pr
->send_cq
->attr
.act_nr_of_cqes
,
1454 pr
->recv_cq
->attr
.act_nr_of_cqes
);
1456 init_attr
= kzalloc(sizeof(*init_attr
), GFP_KERNEL
);
1459 ehea_error("no mem for ehea_qp_init_attr");
1463 init_attr
->low_lat_rq1
= 1;
1464 init_attr
->signalingtype
= 1; /* generate CQE if specified in WQE */
1465 init_attr
->rq_count
= 3;
1466 init_attr
->qp_token
= queue_token
;
1467 init_attr
->max_nr_send_wqes
= pr_cfg
->max_entries_sq
;
1468 init_attr
->max_nr_rwqes_rq1
= pr_cfg
->max_entries_rq1
;
1469 init_attr
->max_nr_rwqes_rq2
= pr_cfg
->max_entries_rq2
;
1470 init_attr
->max_nr_rwqes_rq3
= pr_cfg
->max_entries_rq3
;
1471 init_attr
->wqe_size_enc_sq
= EHEA_SG_SQ
;
1472 init_attr
->wqe_size_enc_rq1
= EHEA_SG_RQ1
;
1473 init_attr
->wqe_size_enc_rq2
= EHEA_SG_RQ2
;
1474 init_attr
->wqe_size_enc_rq3
= EHEA_SG_RQ3
;
1475 init_attr
->rq2_threshold
= EHEA_RQ2_THRESHOLD
;
1476 init_attr
->rq3_threshold
= EHEA_RQ3_THRESHOLD
;
1477 init_attr
->port_nr
= port
->logical_port_id
;
1478 init_attr
->send_cq_handle
= pr
->send_cq
->fw_handle
;
1479 init_attr
->recv_cq_handle
= pr
->recv_cq
->fw_handle
;
1480 init_attr
->aff_eq_handle
= port
->qp_eq
->fw_handle
;
1482 pr
->qp
= ehea_create_qp(adapter
, adapter
->pd
, init_attr
);
1484 ehea_error("create_qp failed");
1489 if (netif_msg_ifup(port
))
1490 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1491 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr
->qp_nr
,
1492 init_attr
->act_nr_send_wqes
,
1493 init_attr
->act_nr_rwqes_rq1
,
1494 init_attr
->act_nr_rwqes_rq2
,
1495 init_attr
->act_nr_rwqes_rq3
);
1497 pr
->sq_skba_size
= init_attr
->act_nr_send_wqes
+ 1;
1499 ret
= ehea_init_q_skba(&pr
->sq_skba
, pr
->sq_skba_size
);
1500 ret
|= ehea_init_q_skba(&pr
->rq1_skba
, init_attr
->act_nr_rwqes_rq1
+ 1);
1501 ret
|= ehea_init_q_skba(&pr
->rq2_skba
, init_attr
->act_nr_rwqes_rq2
+ 1);
1502 ret
|= ehea_init_q_skba(&pr
->rq3_skba
, init_attr
->act_nr_rwqes_rq3
+ 1);
1506 pr
->swqe_refill_th
= init_attr
->act_nr_send_wqes
/ 10;
1507 if (ehea_gen_smrs(pr
) != 0) {
1512 atomic_set(&pr
->swqe_avail
, init_attr
->act_nr_send_wqes
- 1);
1516 netif_napi_add(pr
->port
->netdev
, &pr
->napi
, ehea_poll
, 64);
1518 pr
->lro_mgr
.max_aggr
= pr
->port
->lro_max_aggr
;
1519 pr
->lro_mgr
.max_desc
= MAX_LRO_DESCRIPTORS
;
1520 pr
->lro_mgr
.lro_arr
= pr
->lro_desc
;
1521 pr
->lro_mgr
.get_skb_header
= get_skb_hdr
;
1522 pr
->lro_mgr
.features
= LRO_F_NAPI
| LRO_F_EXTRACT_VLAN_ID
;
1523 pr
->lro_mgr
.dev
= port
->netdev
;
1524 pr
->lro_mgr
.ip_summed
= CHECKSUM_UNNECESSARY
;
1525 pr
->lro_mgr
.ip_summed_aggr
= CHECKSUM_UNNECESSARY
;
1532 vfree(pr
->sq_skba
.arr
);
1533 vfree(pr
->rq1_skba
.arr
);
1534 vfree(pr
->rq2_skba
.arr
);
1535 vfree(pr
->rq3_skba
.arr
);
1536 ehea_destroy_qp(pr
->qp
);
1537 ehea_destroy_cq(pr
->send_cq
);
1538 ehea_destroy_cq(pr
->recv_cq
);
1539 ehea_destroy_eq(pr
->eq
);
1544 static int ehea_clean_portres(struct ehea_port
*port
, struct ehea_port_res
*pr
)
1548 ret
= ehea_destroy_qp(pr
->qp
);
1551 ehea_destroy_cq(pr
->send_cq
);
1552 ehea_destroy_cq(pr
->recv_cq
);
1553 ehea_destroy_eq(pr
->eq
);
1555 for (i
= 0; i
< pr
->rq1_skba
.len
; i
++)
1556 if (pr
->rq1_skba
.arr
[i
])
1557 dev_kfree_skb(pr
->rq1_skba
.arr
[i
]);
1559 for (i
= 0; i
< pr
->rq2_skba
.len
; i
++)
1560 if (pr
->rq2_skba
.arr
[i
])
1561 dev_kfree_skb(pr
->rq2_skba
.arr
[i
]);
1563 for (i
= 0; i
< pr
->rq3_skba
.len
; i
++)
1564 if (pr
->rq3_skba
.arr
[i
])
1565 dev_kfree_skb(pr
->rq3_skba
.arr
[i
]);
1567 for (i
= 0; i
< pr
->sq_skba
.len
; i
++)
1568 if (pr
->sq_skba
.arr
[i
])
1569 dev_kfree_skb(pr
->sq_skba
.arr
[i
]);
1571 vfree(pr
->rq1_skba
.arr
);
1572 vfree(pr
->rq2_skba
.arr
);
1573 vfree(pr
->rq3_skba
.arr
);
1574 vfree(pr
->sq_skba
.arr
);
1575 ret
= ehea_rem_smrs(pr
);
1581 * The write_* functions store information in swqe which is used by
1582 * the hardware to calculate the ip/tcp/udp checksum
1585 static inline void write_ip_start_end(struct ehea_swqe
*swqe
,
1586 const struct sk_buff
*skb
)
1588 swqe
->ip_start
= skb_network_offset(skb
);
1589 swqe
->ip_end
= (u8
)(swqe
->ip_start
+ ip_hdrlen(skb
) - 1);
1592 static inline void write_tcp_offset_end(struct ehea_swqe
*swqe
,
1593 const struct sk_buff
*skb
)
1596 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct tcphdr
, check
));
1598 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1601 static inline void write_udp_offset_end(struct ehea_swqe
*swqe
,
1602 const struct sk_buff
*skb
)
1605 (u8
)(swqe
->ip_end
+ 1 + offsetof(struct udphdr
, check
));
1607 swqe
->tcp_end
= (u16
)skb
->len
- 1;
1611 static void write_swqe2_TSO(struct sk_buff
*skb
,
1612 struct ehea_swqe
*swqe
, u32 lkey
)
1614 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1615 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1616 int skb_data_size
= skb
->len
- skb
->data_len
;
1619 /* Packet is TCP with TSO enabled */
1620 swqe
->tx_control
|= EHEA_SWQE_TSO
;
1621 swqe
->mss
= skb_shinfo(skb
)->gso_size
;
1622 /* copy only eth/ip/tcp headers to immediate data and
1623 * the rest of skb->data to sg1entry
1625 headersize
= ETH_HLEN
+ ip_hdrlen(skb
) + tcp_hdrlen(skb
);
1627 skb_data_size
= skb
->len
- skb
->data_len
;
1629 if (skb_data_size
>= headersize
) {
1630 /* copy immediate data */
1631 skb_copy_from_linear_data(skb
, imm_data
, headersize
);
1632 swqe
->immediate_data_length
= headersize
;
1634 if (skb_data_size
> headersize
) {
1635 /* set sg1entry data */
1636 sg1entry
->l_key
= lkey
;
1637 sg1entry
->len
= skb_data_size
- headersize
;
1639 ehea_map_vaddr(skb
->data
+ headersize
);
1640 swqe
->descriptors
++;
1643 ehea_error("cannot handle fragmented headers");
1646 static void write_swqe2_nonTSO(struct sk_buff
*skb
,
1647 struct ehea_swqe
*swqe
, u32 lkey
)
1649 int skb_data_size
= skb
->len
- skb
->data_len
;
1650 u8
*imm_data
= &swqe
->u
.immdata_desc
.immediate_data
[0];
1651 struct ehea_vsgentry
*sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1653 /* Packet is any nonTSO type
1655 * Copy as much as possible skb->data to immediate data and
1656 * the rest to sg1entry
1658 if (skb_data_size
>= SWQE2_MAX_IMM
) {
1659 /* copy immediate data */
1660 skb_copy_from_linear_data(skb
, imm_data
, SWQE2_MAX_IMM
);
1662 swqe
->immediate_data_length
= SWQE2_MAX_IMM
;
1664 if (skb_data_size
> SWQE2_MAX_IMM
) {
1665 /* copy sg1entry data */
1666 sg1entry
->l_key
= lkey
;
1667 sg1entry
->len
= skb_data_size
- SWQE2_MAX_IMM
;
1669 ehea_map_vaddr(skb
->data
+ SWQE2_MAX_IMM
);
1670 swqe
->descriptors
++;
1673 skb_copy_from_linear_data(skb
, imm_data
, skb_data_size
);
1674 swqe
->immediate_data_length
= skb_data_size
;
1678 static inline void write_swqe2_data(struct sk_buff
*skb
, struct net_device
*dev
,
1679 struct ehea_swqe
*swqe
, u32 lkey
)
1681 struct ehea_vsgentry
*sg_list
, *sg1entry
, *sgentry
;
1683 int nfrags
, sg1entry_contains_frag_data
, i
;
1685 nfrags
= skb_shinfo(skb
)->nr_frags
;
1686 sg1entry
= &swqe
->u
.immdata_desc
.sg_entry
;
1687 sg_list
= (struct ehea_vsgentry
*)&swqe
->u
.immdata_desc
.sg_list
;
1688 swqe
->descriptors
= 0;
1689 sg1entry_contains_frag_data
= 0;
1691 if ((dev
->features
& NETIF_F_TSO
) && skb_shinfo(skb
)->gso_size
)
1692 write_swqe2_TSO(skb
, swqe
, lkey
);
1694 write_swqe2_nonTSO(skb
, swqe
, lkey
);
1696 /* write descriptors */
1698 if (swqe
->descriptors
== 0) {
1699 /* sg1entry not yet used */
1700 frag
= &skb_shinfo(skb
)->frags
[0];
1702 /* copy sg1entry data */
1703 sg1entry
->l_key
= lkey
;
1704 sg1entry
->len
= frag
->size
;
1706 ehea_map_vaddr(page_address(frag
->page
)
1707 + frag
->page_offset
);
1708 swqe
->descriptors
++;
1709 sg1entry_contains_frag_data
= 1;
1712 for (i
= sg1entry_contains_frag_data
; i
< nfrags
; i
++) {
1714 frag
= &skb_shinfo(skb
)->frags
[i
];
1715 sgentry
= &sg_list
[i
- sg1entry_contains_frag_data
];
1717 sgentry
->l_key
= lkey
;
1718 sgentry
->len
= frag
->size
;
1720 ehea_map_vaddr(page_address(frag
->page
)
1721 + frag
->page_offset
);
1722 swqe
->descriptors
++;
1727 static int ehea_broadcast_reg_helper(struct ehea_port
*port
, u32 hcallid
)
1733 /* De/Register untagged packets */
1734 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_UNTAGGED
;
1735 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1736 port
->logical_port_id
,
1737 reg_type
, port
->mac_addr
, 0, hcallid
);
1738 if (hret
!= H_SUCCESS
) {
1739 ehea_error("%sregistering bc address failed (tagged)",
1740 hcallid
== H_REG_BCMC
? "" : "de");
1745 /* De/Register VLAN packets */
1746 reg_type
= EHEA_BCMC_BROADCAST
| EHEA_BCMC_VLANID_ALL
;
1747 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1748 port
->logical_port_id
,
1749 reg_type
, port
->mac_addr
, 0, hcallid
);
1750 if (hret
!= H_SUCCESS
) {
1751 ehea_error("%sregistering bc address failed (vlan)",
1752 hcallid
== H_REG_BCMC
? "" : "de");
1759 static int ehea_set_mac_addr(struct net_device
*dev
, void *sa
)
1761 struct ehea_port
*port
= netdev_priv(dev
);
1762 struct sockaddr
*mac_addr
= sa
;
1763 struct hcp_ehea_port_cb0
*cb0
;
1767 if (!is_valid_ether_addr(mac_addr
->sa_data
)) {
1768 ret
= -EADDRNOTAVAIL
;
1772 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
1774 ehea_error("no mem for cb0");
1779 memcpy(&(cb0
->port_mac_addr
), &(mac_addr
->sa_data
[0]), ETH_ALEN
);
1781 cb0
->port_mac_addr
= cb0
->port_mac_addr
>> 16;
1783 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1784 port
->logical_port_id
, H_PORT_CB0
,
1785 EHEA_BMASK_SET(H_PORT_CB0_MAC
, 1), cb0
);
1786 if (hret
!= H_SUCCESS
) {
1791 memcpy(dev
->dev_addr
, mac_addr
->sa_data
, dev
->addr_len
);
1793 /* Deregister old MAC in pHYP */
1794 if (port
->state
== EHEA_PORT_UP
) {
1795 ret
= ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
1800 port
->mac_addr
= cb0
->port_mac_addr
<< 16;
1802 /* Register new MAC in pHYP */
1803 if (port
->state
== EHEA_PORT_UP
) {
1804 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
1812 ehea_update_bcmc_registrations();
1814 free_page((unsigned long)cb0
);
1819 static void ehea_promiscuous_error(u64 hret
, int enable
)
1821 if (hret
== H_AUTHORITY
)
1822 ehea_info("Hypervisor denied %sabling promiscuous mode",
1823 enable
== 1 ? "en" : "dis");
1825 ehea_error("failed %sabling promiscuous mode",
1826 enable
== 1 ? "en" : "dis");
1829 static void ehea_promiscuous(struct net_device
*dev
, int enable
)
1831 struct ehea_port
*port
= netdev_priv(dev
);
1832 struct hcp_ehea_port_cb7
*cb7
;
1835 if ((enable
&& port
->promisc
) || (!enable
&& !port
->promisc
))
1838 cb7
= (void *)get_zeroed_page(GFP_ATOMIC
);
1840 ehea_error("no mem for cb7");
1844 /* Modify Pxs_DUCQPN in CB7 */
1845 cb7
->def_uc_qpn
= enable
== 1 ? port
->port_res
[0].qp
->fw_handle
: 0;
1847 hret
= ehea_h_modify_ehea_port(port
->adapter
->handle
,
1848 port
->logical_port_id
,
1849 H_PORT_CB7
, H_PORT_CB7_DUCQPN
, cb7
);
1851 ehea_promiscuous_error(hret
, enable
);
1855 port
->promisc
= enable
;
1857 free_page((unsigned long)cb7
);
1861 static u64
ehea_multicast_reg_helper(struct ehea_port
*port
, u64 mc_mac_addr
,
1867 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1868 | EHEA_BCMC_UNTAGGED
;
1870 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1871 port
->logical_port_id
,
1872 reg_type
, mc_mac_addr
, 0, hcallid
);
1876 reg_type
= EHEA_BCMC_SCOPE_ALL
| EHEA_BCMC_MULTICAST
1877 | EHEA_BCMC_VLANID_ALL
;
1879 hret
= ehea_h_reg_dereg_bcmc(port
->adapter
->handle
,
1880 port
->logical_port_id
,
1881 reg_type
, mc_mac_addr
, 0, hcallid
);
1886 static int ehea_drop_multicast_list(struct net_device
*dev
)
1888 struct ehea_port
*port
= netdev_priv(dev
);
1889 struct ehea_mc_list
*mc_entry
= port
->mc_list
;
1890 struct list_head
*pos
;
1891 struct list_head
*temp
;
1895 list_for_each_safe(pos
, temp
, &(port
->mc_list
->list
)) {
1896 mc_entry
= list_entry(pos
, struct ehea_mc_list
, list
);
1898 hret
= ehea_multicast_reg_helper(port
, mc_entry
->macaddr
,
1901 ehea_error("failed deregistering mcast MAC");
1911 static void ehea_allmulti(struct net_device
*dev
, int enable
)
1913 struct ehea_port
*port
= netdev_priv(dev
);
1916 if (!port
->allmulti
) {
1918 /* Enable ALLMULTI */
1919 ehea_drop_multicast_list(dev
);
1920 hret
= ehea_multicast_reg_helper(port
, 0, H_REG_BCMC
);
1924 ehea_error("failed enabling IFF_ALLMULTI");
1928 /* Disable ALLMULTI */
1929 hret
= ehea_multicast_reg_helper(port
, 0, H_DEREG_BCMC
);
1933 ehea_error("failed disabling IFF_ALLMULTI");
1937 static void ehea_add_multicast_entry(struct ehea_port
*port
, u8
*mc_mac_addr
)
1939 struct ehea_mc_list
*ehea_mcl_entry
;
1942 ehea_mcl_entry
= kzalloc(sizeof(*ehea_mcl_entry
), GFP_ATOMIC
);
1943 if (!ehea_mcl_entry
) {
1944 ehea_error("no mem for mcl_entry");
1948 INIT_LIST_HEAD(&ehea_mcl_entry
->list
);
1950 memcpy(&ehea_mcl_entry
->macaddr
, mc_mac_addr
, ETH_ALEN
);
1952 hret
= ehea_multicast_reg_helper(port
, ehea_mcl_entry
->macaddr
,
1955 list_add(&ehea_mcl_entry
->list
, &port
->mc_list
->list
);
1957 ehea_error("failed registering mcast MAC");
1958 kfree(ehea_mcl_entry
);
1962 static void ehea_set_multicast_list(struct net_device
*dev
)
1964 struct ehea_port
*port
= netdev_priv(dev
);
1965 struct dev_mc_list
*k_mcl_entry
;
1968 if (dev
->flags
& IFF_PROMISC
) {
1969 ehea_promiscuous(dev
, 1);
1972 ehea_promiscuous(dev
, 0);
1974 if (dev
->flags
& IFF_ALLMULTI
) {
1975 ehea_allmulti(dev
, 1);
1978 ehea_allmulti(dev
, 0);
1980 if (dev
->mc_count
) {
1981 ret
= ehea_drop_multicast_list(dev
);
1983 /* Dropping the current multicast list failed.
1984 * Enabling ALL_MULTI is the best we can do.
1986 ehea_allmulti(dev
, 1);
1989 if (dev
->mc_count
> port
->adapter
->max_mc_mac
) {
1990 ehea_info("Mcast registration limit reached (0x%llx). "
1992 port
->adapter
->max_mc_mac
);
1996 for (i
= 0, k_mcl_entry
= dev
->mc_list
; i
< dev
->mc_count
; i
++,
1997 k_mcl_entry
= k_mcl_entry
->next
)
1998 ehea_add_multicast_entry(port
, k_mcl_entry
->dmi_addr
);
2002 ehea_update_bcmc_registrations();
2006 static int ehea_change_mtu(struct net_device
*dev
, int new_mtu
)
2008 if ((new_mtu
< 68) || (new_mtu
> EHEA_MAX_PACKET_SIZE
))
2014 static void ehea_xmit2(struct sk_buff
*skb
, struct net_device
*dev
,
2015 struct ehea_swqe
*swqe
, u32 lkey
)
2017 if (skb
->protocol
== htons(ETH_P_IP
)) {
2018 const struct iphdr
*iph
= ip_hdr(skb
);
2021 swqe
->tx_control
|= EHEA_SWQE_CRC
2022 | EHEA_SWQE_IP_CHECKSUM
2023 | EHEA_SWQE_TCP_CHECKSUM
2024 | EHEA_SWQE_IMM_DATA_PRESENT
2025 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
2027 write_ip_start_end(swqe
, skb
);
2029 if (iph
->protocol
== IPPROTO_UDP
) {
2030 if ((iph
->frag_off
& IP_MF
)
2031 || (iph
->frag_off
& IP_OFFSET
))
2032 /* IP fragment, so don't change cs */
2033 swqe
->tx_control
&= ~EHEA_SWQE_TCP_CHECKSUM
;
2035 write_udp_offset_end(swqe
, skb
);
2036 } else if (iph
->protocol
== IPPROTO_TCP
) {
2037 write_tcp_offset_end(swqe
, skb
);
2040 /* icmp (big data) and ip segmentation packets (all other ip
2041 packets) do not require any special handling */
2044 /* Other Ethernet Protocol */
2045 swqe
->tx_control
|= EHEA_SWQE_CRC
2046 | EHEA_SWQE_IMM_DATA_PRESENT
2047 | EHEA_SWQE_DESCRIPTORS_PRESENT
;
2050 write_swqe2_data(skb
, dev
, swqe
, lkey
);
2053 static void ehea_xmit3(struct sk_buff
*skb
, struct net_device
*dev
,
2054 struct ehea_swqe
*swqe
)
2056 int nfrags
= skb_shinfo(skb
)->nr_frags
;
2057 u8
*imm_data
= &swqe
->u
.immdata_nodesc
.immediate_data
[0];
2061 if (skb
->protocol
== htons(ETH_P_IP
)) {
2062 const struct iphdr
*iph
= ip_hdr(skb
);
2065 write_ip_start_end(swqe
, skb
);
2067 if (iph
->protocol
== IPPROTO_TCP
) {
2068 swqe
->tx_control
|= EHEA_SWQE_CRC
2069 | EHEA_SWQE_IP_CHECKSUM
2070 | EHEA_SWQE_TCP_CHECKSUM
2071 | EHEA_SWQE_IMM_DATA_PRESENT
;
2073 write_tcp_offset_end(swqe
, skb
);
2075 } else if (iph
->protocol
== IPPROTO_UDP
) {
2076 if ((iph
->frag_off
& IP_MF
)
2077 || (iph
->frag_off
& IP_OFFSET
))
2078 /* IP fragment, so don't change cs */
2079 swqe
->tx_control
|= EHEA_SWQE_CRC
2080 | EHEA_SWQE_IMM_DATA_PRESENT
;
2082 swqe
->tx_control
|= EHEA_SWQE_CRC
2083 | EHEA_SWQE_IP_CHECKSUM
2084 | EHEA_SWQE_TCP_CHECKSUM
2085 | EHEA_SWQE_IMM_DATA_PRESENT
;
2087 write_udp_offset_end(swqe
, skb
);
2090 /* icmp (big data) and
2091 ip segmentation packets (all other ip packets) */
2092 swqe
->tx_control
|= EHEA_SWQE_CRC
2093 | EHEA_SWQE_IP_CHECKSUM
2094 | EHEA_SWQE_IMM_DATA_PRESENT
;
2097 /* Other Ethernet Protocol */
2098 swqe
->tx_control
|= EHEA_SWQE_CRC
| EHEA_SWQE_IMM_DATA_PRESENT
;
2100 /* copy (immediate) data */
2102 /* data is in a single piece */
2103 skb_copy_from_linear_data(skb
, imm_data
, skb
->len
);
2105 /* first copy data from the skb->data buffer ... */
2106 skb_copy_from_linear_data(skb
, imm_data
,
2107 skb
->len
- skb
->data_len
);
2108 imm_data
+= skb
->len
- skb
->data_len
;
2110 /* ... then copy data from the fragments */
2111 for (i
= 0; i
< nfrags
; i
++) {
2112 frag
= &skb_shinfo(skb
)->frags
[i
];
2114 page_address(frag
->page
) + frag
->page_offset
,
2116 imm_data
+= frag
->size
;
2119 swqe
->immediate_data_length
= skb
->len
;
2123 static inline int ehea_hash_skb(struct sk_buff
*skb
, int num_qps
)
2128 if ((skb
->protocol
== htons(ETH_P_IP
)) &&
2129 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)) {
2130 tcp
= (struct tcphdr
*)(skb_network_header(skb
) +
2131 (ip_hdr(skb
)->ihl
* 4));
2132 tmp
= (tcp
->source
+ (tcp
->dest
<< 16)) % 31;
2133 tmp
+= ip_hdr(skb
)->daddr
% 31;
2134 return tmp
% num_qps
;
2139 static int ehea_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2141 struct ehea_port
*port
= netdev_priv(dev
);
2142 struct ehea_swqe
*swqe
;
2143 unsigned long flags
;
2146 struct ehea_port_res
*pr
;
2148 pr
= &port
->port_res
[ehea_hash_skb(skb
, port
->num_tx_qps
)];
2150 if (!spin_trylock(&pr
->xmit_lock
))
2151 return NETDEV_TX_BUSY
;
2153 if (pr
->queue_stopped
) {
2154 spin_unlock(&pr
->xmit_lock
);
2155 return NETDEV_TX_BUSY
;
2158 swqe
= ehea_get_swqe(pr
->qp
, &swqe_index
);
2159 memset(swqe
, 0, SWQE_HEADER_SIZE
);
2160 atomic_dec(&pr
->swqe_avail
);
2162 if (skb
->len
<= SWQE3_MAX_IMM
) {
2163 u32 sig_iv
= port
->sig_comp_iv
;
2164 u32 swqe_num
= pr
->swqe_id_counter
;
2165 ehea_xmit3(skb
, dev
, swqe
);
2166 swqe
->wr_id
= EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE3_TYPE
)
2167 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, swqe_num
);
2168 if (pr
->swqe_ll_count
>= (sig_iv
- 1)) {
2169 swqe
->wr_id
|= EHEA_BMASK_SET(EHEA_WR_ID_REFILL
,
2171 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2172 pr
->swqe_ll_count
= 0;
2174 pr
->swqe_ll_count
+= 1;
2177 EHEA_BMASK_SET(EHEA_WR_ID_TYPE
, EHEA_SWQE2_TYPE
)
2178 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT
, pr
->swqe_id_counter
)
2179 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL
, 1)
2180 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX
, pr
->sq_skba
.index
);
2181 pr
->sq_skba
.arr
[pr
->sq_skba
.index
] = skb
;
2183 pr
->sq_skba
.index
++;
2184 pr
->sq_skba
.index
&= (pr
->sq_skba
.len
- 1);
2186 lkey
= pr
->send_mr
.lkey
;
2187 ehea_xmit2(skb
, dev
, swqe
, lkey
);
2188 swqe
->tx_control
|= EHEA_SWQE_SIGNALLED_COMPLETION
;
2190 pr
->swqe_id_counter
+= 1;
2192 if (port
->vgrp
&& vlan_tx_tag_present(skb
)) {
2193 swqe
->tx_control
|= EHEA_SWQE_VLAN_INSERT
;
2194 swqe
->vlan_tag
= vlan_tx_tag_get(skb
);
2197 if (netif_msg_tx_queued(port
)) {
2198 ehea_info("post swqe on QP %d", pr
->qp
->init_attr
.qp_nr
);
2199 ehea_dump(swqe
, 512, "swqe");
2202 if (unlikely(test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))) {
2203 netif_stop_queue(dev
);
2204 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2207 ehea_post_swqe(pr
->qp
, swqe
);
2210 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2211 spin_lock_irqsave(&pr
->netif_queue
, flags
);
2212 if (unlikely(atomic_read(&pr
->swqe_avail
) <= 1)) {
2213 pr
->p_stats
.queue_stopped
++;
2214 netif_stop_queue(dev
);
2215 pr
->queue_stopped
= 1;
2217 spin_unlock_irqrestore(&pr
->netif_queue
, flags
);
2219 dev
->trans_start
= jiffies
;
2220 spin_unlock(&pr
->xmit_lock
);
2222 return NETDEV_TX_OK
;
2225 static void ehea_vlan_rx_register(struct net_device
*dev
,
2226 struct vlan_group
*grp
)
2228 struct ehea_port
*port
= netdev_priv(dev
);
2229 struct ehea_adapter
*adapter
= port
->adapter
;
2230 struct hcp_ehea_port_cb1
*cb1
;
2235 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2237 ehea_error("no mem for cb1");
2241 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2242 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2243 if (hret
!= H_SUCCESS
)
2244 ehea_error("modify_ehea_port failed");
2246 free_page((unsigned long)cb1
);
2251 static void ehea_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
2253 struct ehea_port
*port
= netdev_priv(dev
);
2254 struct ehea_adapter
*adapter
= port
->adapter
;
2255 struct hcp_ehea_port_cb1
*cb1
;
2259 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2261 ehea_error("no mem for cb1");
2265 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2266 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2267 if (hret
!= H_SUCCESS
) {
2268 ehea_error("query_ehea_port failed");
2273 cb1
->vlan_filter
[index
] |= ((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2275 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2276 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2277 if (hret
!= H_SUCCESS
)
2278 ehea_error("modify_ehea_port failed");
2280 free_page((unsigned long)cb1
);
2284 static void ehea_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
2286 struct ehea_port
*port
= netdev_priv(dev
);
2287 struct ehea_adapter
*adapter
= port
->adapter
;
2288 struct hcp_ehea_port_cb1
*cb1
;
2292 vlan_group_set_device(port
->vgrp
, vid
, NULL
);
2294 cb1
= (void *)get_zeroed_page(GFP_KERNEL
);
2296 ehea_error("no mem for cb1");
2300 hret
= ehea_h_query_ehea_port(adapter
->handle
, port
->logical_port_id
,
2301 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2302 if (hret
!= H_SUCCESS
) {
2303 ehea_error("query_ehea_port failed");
2308 cb1
->vlan_filter
[index
] &= ~((u64
)(0x8000000000000000 >> (vid
& 0x3F)));
2310 hret
= ehea_h_modify_ehea_port(adapter
->handle
, port
->logical_port_id
,
2311 H_PORT_CB1
, H_PORT_CB1_ALL
, cb1
);
2312 if (hret
!= H_SUCCESS
)
2313 ehea_error("modify_ehea_port failed");
2315 free_page((unsigned long)cb1
);
2319 int ehea_activate_qp(struct ehea_adapter
*adapter
, struct ehea_qp
*qp
)
2325 struct hcp_modify_qp_cb0
*cb0
;
2327 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2333 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2334 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2335 if (hret
!= H_SUCCESS
) {
2336 ehea_error("query_ehea_qp failed (1)");
2340 cb0
->qp_ctl_reg
= H_QP_CR_STATE_INITIALIZED
;
2341 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2342 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2343 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2344 if (hret
!= H_SUCCESS
) {
2345 ehea_error("modify_ehea_qp failed (1)");
2349 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2350 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2351 if (hret
!= H_SUCCESS
) {
2352 ehea_error("query_ehea_qp failed (2)");
2356 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_INITIALIZED
;
2357 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2358 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2359 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2360 if (hret
!= H_SUCCESS
) {
2361 ehea_error("modify_ehea_qp failed (2)");
2365 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2366 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2367 if (hret
!= H_SUCCESS
) {
2368 ehea_error("query_ehea_qp failed (3)");
2372 cb0
->qp_ctl_reg
= H_QP_CR_ENABLED
| H_QP_CR_STATE_RDY2SND
;
2373 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2374 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
, 1), cb0
,
2375 &dummy64
, &dummy64
, &dummy16
, &dummy16
);
2376 if (hret
!= H_SUCCESS
) {
2377 ehea_error("modify_ehea_qp failed (3)");
2381 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2382 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF), cb0
);
2383 if (hret
!= H_SUCCESS
) {
2384 ehea_error("query_ehea_qp failed (4)");
2390 free_page((unsigned long)cb0
);
2394 static int ehea_port_res_setup(struct ehea_port
*port
, int def_qps
,
2398 struct port_res_cfg pr_cfg
, pr_cfg_small_rx
;
2399 enum ehea_eq_type eq_type
= EHEA_EQ
;
2401 port
->qp_eq
= ehea_create_eq(port
->adapter
, eq_type
,
2402 EHEA_MAX_ENTRIES_EQ
, 1);
2405 ehea_error("ehea_create_eq failed (qp_eq)");
2409 pr_cfg
.max_entries_rcq
= rq1_entries
+ rq2_entries
+ rq3_entries
;
2410 pr_cfg
.max_entries_scq
= sq_entries
* 2;
2411 pr_cfg
.max_entries_sq
= sq_entries
;
2412 pr_cfg
.max_entries_rq1
= rq1_entries
;
2413 pr_cfg
.max_entries_rq2
= rq2_entries
;
2414 pr_cfg
.max_entries_rq3
= rq3_entries
;
2416 pr_cfg_small_rx
.max_entries_rcq
= 1;
2417 pr_cfg_small_rx
.max_entries_scq
= sq_entries
;
2418 pr_cfg_small_rx
.max_entries_sq
= sq_entries
;
2419 pr_cfg_small_rx
.max_entries_rq1
= 1;
2420 pr_cfg_small_rx
.max_entries_rq2
= 1;
2421 pr_cfg_small_rx
.max_entries_rq3
= 1;
2423 for (i
= 0; i
< def_qps
; i
++) {
2424 ret
= ehea_init_port_res(port
, &port
->port_res
[i
], &pr_cfg
, i
);
2428 for (i
= def_qps
; i
< def_qps
+ add_tx_qps
; i
++) {
2429 ret
= ehea_init_port_res(port
, &port
->port_res
[i
],
2430 &pr_cfg_small_rx
, i
);
2439 ehea_clean_portres(port
, &port
->port_res
[i
]);
2442 ehea_destroy_eq(port
->qp_eq
);
2446 static int ehea_clean_all_portres(struct ehea_port
*port
)
2451 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2452 ret
|= ehea_clean_portres(port
, &port
->port_res
[i
]);
2454 ret
|= ehea_destroy_eq(port
->qp_eq
);
2459 static void ehea_remove_adapter_mr(struct ehea_adapter
*adapter
)
2461 if (adapter
->active_ports
)
2464 ehea_rem_mr(&adapter
->mr
);
2467 static int ehea_add_adapter_mr(struct ehea_adapter
*adapter
)
2469 if (adapter
->active_ports
)
2472 return ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2475 static int ehea_up(struct net_device
*dev
)
2478 struct ehea_port
*port
= netdev_priv(dev
);
2480 if (port
->state
== EHEA_PORT_UP
)
2483 ret
= ehea_port_res_setup(port
, port
->num_def_qps
,
2484 port
->num_add_tx_qps
);
2486 ehea_error("port_res_failed");
2490 /* Set default QP for this port */
2491 ret
= ehea_configure_port(port
);
2493 ehea_error("ehea_configure_port failed. ret:%d", ret
);
2497 ret
= ehea_reg_interrupts(dev
);
2499 ehea_error("reg_interrupts failed. ret:%d", ret
);
2503 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2504 ret
= ehea_activate_qp(port
->adapter
, port
->port_res
[i
].qp
);
2506 ehea_error("activate_qp failed");
2511 for (i
= 0; i
< port
->num_def_qps
; i
++) {
2512 ret
= ehea_fill_port_res(&port
->port_res
[i
]);
2514 ehea_error("out_free_irqs");
2519 ret
= ehea_broadcast_reg_helper(port
, H_REG_BCMC
);
2525 port
->state
= EHEA_PORT_UP
;
2531 ehea_free_interrupts(dev
);
2534 ehea_clean_all_portres(port
);
2537 ehea_info("Failed starting %s. ret=%i", dev
->name
, ret
);
2539 ehea_update_bcmc_registrations();
2540 ehea_update_firmware_handles();
2545 static void port_napi_disable(struct ehea_port
*port
)
2549 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2550 napi_disable(&port
->port_res
[i
].napi
);
2553 static void port_napi_enable(struct ehea_port
*port
)
2557 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++)
2558 napi_enable(&port
->port_res
[i
].napi
);
2561 static int ehea_open(struct net_device
*dev
)
2564 struct ehea_port
*port
= netdev_priv(dev
);
2566 mutex_lock(&port
->port_lock
);
2568 if (netif_msg_ifup(port
))
2569 ehea_info("enabling port %s", dev
->name
);
2573 port_napi_enable(port
);
2574 netif_start_queue(dev
);
2577 mutex_unlock(&port
->port_lock
);
2582 static int ehea_down(struct net_device
*dev
)
2585 struct ehea_port
*port
= netdev_priv(dev
);
2587 if (port
->state
== EHEA_PORT_DOWN
)
2590 ehea_drop_multicast_list(dev
);
2591 ehea_broadcast_reg_helper(port
, H_DEREG_BCMC
);
2593 ehea_free_interrupts(dev
);
2595 port
->state
= EHEA_PORT_DOWN
;
2597 ehea_update_bcmc_registrations();
2599 ret
= ehea_clean_all_portres(port
);
2601 ehea_info("Failed freeing resources for %s. ret=%i",
2604 ehea_update_firmware_handles();
2609 static int ehea_stop(struct net_device
*dev
)
2612 struct ehea_port
*port
= netdev_priv(dev
);
2614 if (netif_msg_ifdown(port
))
2615 ehea_info("disabling port %s", dev
->name
);
2617 set_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2618 cancel_work_sync(&port
->reset_task
);
2619 mutex_lock(&port
->port_lock
);
2620 netif_stop_queue(dev
);
2621 port_napi_disable(port
);
2622 ret
= ehea_down(dev
);
2623 mutex_unlock(&port
->port_lock
);
2624 clear_bit(__EHEA_DISABLE_PORT_RESET
, &port
->flags
);
2628 static void ehea_purge_sq(struct ehea_qp
*orig_qp
)
2630 struct ehea_qp qp
= *orig_qp
;
2631 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2632 struct ehea_swqe
*swqe
;
2636 for (i
= 0; i
< init_attr
->act_nr_send_wqes
; i
++) {
2637 swqe
= ehea_get_swqe(&qp
, &wqe_index
);
2638 swqe
->tx_control
|= EHEA_SWQE_PURGE
;
2642 static void ehea_flush_sq(struct ehea_port
*port
)
2646 for (i
= 0; i
< port
->num_def_qps
+ port
->num_add_tx_qps
; i
++) {
2647 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2648 int swqe_max
= pr
->sq_skba_size
- 2 - pr
->swqe_ll_count
;
2650 while (atomic_read(&pr
->swqe_avail
) < swqe_max
) {
2658 int ehea_stop_qps(struct net_device
*dev
)
2660 struct ehea_port
*port
= netdev_priv(dev
);
2661 struct ehea_adapter
*adapter
= port
->adapter
;
2662 struct hcp_modify_qp_cb0
*cb0
;
2670 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2676 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2677 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2678 struct ehea_qp
*qp
= pr
->qp
;
2680 /* Purge send queue */
2683 /* Disable queue pair */
2684 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2685 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2687 if (hret
!= H_SUCCESS
) {
2688 ehea_error("query_ehea_qp failed (1)");
2692 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2693 cb0
->qp_ctl_reg
&= ~H_QP_CR_ENABLED
;
2695 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2696 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2698 &dummy64
, &dummy16
, &dummy16
);
2699 if (hret
!= H_SUCCESS
) {
2700 ehea_error("modify_ehea_qp failed (1)");
2704 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2705 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2707 if (hret
!= H_SUCCESS
) {
2708 ehea_error("query_ehea_qp failed (2)");
2712 /* deregister shared memory regions */
2713 dret
= ehea_rem_smrs(pr
);
2715 ehea_error("unreg shared memory region failed");
2722 free_page((unsigned long)cb0
);
2727 void ehea_update_rqs(struct ehea_qp
*orig_qp
, struct ehea_port_res
*pr
)
2729 struct ehea_qp qp
= *orig_qp
;
2730 struct ehea_qp_init_attr
*init_attr
= &qp
.init_attr
;
2731 struct ehea_rwqe
*rwqe
;
2732 struct sk_buff
**skba_rq2
= pr
->rq2_skba
.arr
;
2733 struct sk_buff
**skba_rq3
= pr
->rq3_skba
.arr
;
2734 struct sk_buff
*skb
;
2735 u32 lkey
= pr
->recv_mr
.lkey
;
2741 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq2
+ 1; i
++) {
2742 rwqe
= ehea_get_next_rwqe(&qp
, 2);
2743 rwqe
->sg_list
[0].l_key
= lkey
;
2744 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2745 skb
= skba_rq2
[index
];
2747 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2750 for (i
= 0; i
< init_attr
->act_nr_rwqes_rq3
+ 1; i
++) {
2751 rwqe
= ehea_get_next_rwqe(&qp
, 3);
2752 rwqe
->sg_list
[0].l_key
= lkey
;
2753 index
= EHEA_BMASK_GET(EHEA_WR_ID_INDEX
, rwqe
->wr_id
);
2754 skb
= skba_rq3
[index
];
2756 rwqe
->sg_list
[0].vaddr
= ehea_map_vaddr(skb
->data
);
2760 int ehea_restart_qps(struct net_device
*dev
)
2762 struct ehea_port
*port
= netdev_priv(dev
);
2763 struct ehea_adapter
*adapter
= port
->adapter
;
2767 struct hcp_modify_qp_cb0
*cb0
;
2772 cb0
= (void *)get_zeroed_page(GFP_KERNEL
);
2778 for (i
= 0; i
< (port
->num_def_qps
+ port
->num_add_tx_qps
); i
++) {
2779 struct ehea_port_res
*pr
= &port
->port_res
[i
];
2780 struct ehea_qp
*qp
= pr
->qp
;
2782 ret
= ehea_gen_smrs(pr
);
2784 ehea_error("creation of shared memory regions failed");
2788 ehea_update_rqs(qp
, pr
);
2790 /* Enable queue pair */
2791 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2792 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2794 if (hret
!= H_SUCCESS
) {
2795 ehea_error("query_ehea_qp failed (1)");
2799 cb0
->qp_ctl_reg
= (cb0
->qp_ctl_reg
& H_QP_CR_RES_STATE
) << 8;
2800 cb0
->qp_ctl_reg
|= H_QP_CR_ENABLED
;
2802 hret
= ehea_h_modify_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2803 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG
,
2805 &dummy64
, &dummy16
, &dummy16
);
2806 if (hret
!= H_SUCCESS
) {
2807 ehea_error("modify_ehea_qp failed (1)");
2811 hret
= ehea_h_query_ehea_qp(adapter
->handle
, 0, qp
->fw_handle
,
2812 EHEA_BMASK_SET(H_QPCB0_ALL
, 0xFFFF),
2814 if (hret
!= H_SUCCESS
) {
2815 ehea_error("query_ehea_qp failed (2)");
2819 /* refill entire queue */
2820 ehea_refill_rq1(pr
, pr
->rq1_skba
.index
, 0);
2821 ehea_refill_rq2(pr
, 0);
2822 ehea_refill_rq3(pr
, 0);
2825 free_page((unsigned long)cb0
);
2830 static void ehea_reset_port(struct work_struct
*work
)
2833 struct ehea_port
*port
=
2834 container_of(work
, struct ehea_port
, reset_task
);
2835 struct net_device
*dev
= port
->netdev
;
2838 mutex_lock(&port
->port_lock
);
2839 netif_stop_queue(dev
);
2841 port_napi_disable(port
);
2849 ehea_set_multicast_list(dev
);
2851 if (netif_msg_timer(port
))
2852 ehea_info("Device %s resetted successfully", dev
->name
);
2854 port_napi_enable(port
);
2856 netif_wake_queue(dev
);
2858 mutex_unlock(&port
->port_lock
);
2862 static void ehea_rereg_mrs(struct work_struct
*work
)
2865 struct ehea_adapter
*adapter
;
2867 mutex_lock(&dlpar_mem_lock
);
2868 ehea_info("LPAR memory changed - re-initializing driver");
2870 list_for_each_entry(adapter
, &adapter_list
, list
)
2871 if (adapter
->active_ports
) {
2872 /* Shutdown all ports */
2873 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2874 struct ehea_port
*port
= adapter
->port
[i
];
2875 struct net_device
*dev
;
2882 if (dev
->flags
& IFF_UP
) {
2883 mutex_lock(&port
->port_lock
);
2884 netif_stop_queue(dev
);
2885 ehea_flush_sq(port
);
2886 ret
= ehea_stop_qps(dev
);
2888 mutex_unlock(&port
->port_lock
);
2891 port_napi_disable(port
);
2892 mutex_unlock(&port
->port_lock
);
2896 /* Unregister old memory region */
2897 ret
= ehea_rem_mr(&adapter
->mr
);
2899 ehea_error("unregister MR failed - driver"
2905 clear_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
2907 list_for_each_entry(adapter
, &adapter_list
, list
)
2908 if (adapter
->active_ports
) {
2909 /* Register new memory region */
2910 ret
= ehea_reg_kernel_mr(adapter
, &adapter
->mr
);
2912 ehea_error("register MR failed - driver"
2917 /* Restart all ports */
2918 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++) {
2919 struct ehea_port
*port
= adapter
->port
[i
];
2922 struct net_device
*dev
= port
->netdev
;
2924 if (dev
->flags
& IFF_UP
) {
2925 mutex_lock(&port
->port_lock
);
2926 port_napi_enable(port
);
2927 ret
= ehea_restart_qps(dev
);
2929 netif_wake_queue(dev
);
2930 mutex_unlock(&port
->port_lock
);
2935 ehea_info("re-initializing driver complete");
2937 mutex_unlock(&dlpar_mem_lock
);
2941 static void ehea_tx_watchdog(struct net_device
*dev
)
2943 struct ehea_port
*port
= netdev_priv(dev
);
2945 if (netif_carrier_ok(dev
) &&
2946 !test_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
))
2947 ehea_schedule_port_reset(port
);
2950 int ehea_sense_adapter_attr(struct ehea_adapter
*adapter
)
2952 struct hcp_query_ehea
*cb
;
2956 cb
= (void *)get_zeroed_page(GFP_KERNEL
);
2962 hret
= ehea_h_query_ehea(adapter
->handle
, cb
);
2964 if (hret
!= H_SUCCESS
) {
2969 adapter
->max_mc_mac
= cb
->max_mc_mac
- 1;
2973 free_page((unsigned long)cb
);
2978 int ehea_get_jumboframe_status(struct ehea_port
*port
, int *jumbo
)
2980 struct hcp_ehea_port_cb4
*cb4
;
2986 /* (Try to) enable *jumbo frames */
2987 cb4
= (void *)get_zeroed_page(GFP_KERNEL
);
2989 ehea_error("no mem for cb4");
2993 hret
= ehea_h_query_ehea_port(port
->adapter
->handle
,
2994 port
->logical_port_id
,
2996 H_PORT_CB4_JUMBO
, cb4
);
2997 if (hret
== H_SUCCESS
) {
2998 if (cb4
->jumbo_frame
)
3001 cb4
->jumbo_frame
= 1;
3002 hret
= ehea_h_modify_ehea_port(port
->adapter
->
3009 if (hret
== H_SUCCESS
)
3015 free_page((unsigned long)cb4
);
3021 static ssize_t
ehea_show_port_id(struct device
*dev
,
3022 struct device_attribute
*attr
, char *buf
)
3024 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
3025 return sprintf(buf
, "%d", port
->logical_port_id
);
3028 static DEVICE_ATTR(log_port_id
, S_IRUSR
| S_IRGRP
| S_IROTH
, ehea_show_port_id
,
3031 static void __devinit
logical_port_release(struct device
*dev
)
3033 struct ehea_port
*port
= container_of(dev
, struct ehea_port
, ofdev
.dev
);
3034 of_node_put(port
->ofdev
.node
);
3037 static struct device
*ehea_register_port(struct ehea_port
*port
,
3038 struct device_node
*dn
)
3042 port
->ofdev
.node
= of_node_get(dn
);
3043 port
->ofdev
.dev
.parent
= &port
->adapter
->ofdev
->dev
;
3044 port
->ofdev
.dev
.bus
= &ibmebus_bus_type
;
3046 dev_set_name(&port
->ofdev
.dev
, "port%d", port_name_cnt
++);
3047 port
->ofdev
.dev
.release
= logical_port_release
;
3049 ret
= of_device_register(&port
->ofdev
);
3051 ehea_error("failed to register device. ret=%d", ret
);
3055 ret
= device_create_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3057 ehea_error("failed to register attributes, ret=%d", ret
);
3058 goto out_unreg_of_dev
;
3061 return &port
->ofdev
.dev
;
3064 of_device_unregister(&port
->ofdev
);
3069 static void ehea_unregister_port(struct ehea_port
*port
)
3071 device_remove_file(&port
->ofdev
.dev
, &dev_attr_log_port_id
);
3072 of_device_unregister(&port
->ofdev
);
3075 static const struct net_device_ops ehea_netdev_ops
= {
3076 .ndo_open
= ehea_open
,
3077 .ndo_stop
= ehea_stop
,
3078 .ndo_start_xmit
= ehea_start_xmit
,
3079 #ifdef CONFIG_NET_POLL_CONTROLLER
3080 .ndo_poll_controller
= ehea_netpoll
,
3082 .ndo_get_stats
= ehea_get_stats
,
3083 .ndo_set_mac_address
= ehea_set_mac_addr
,
3084 .ndo_set_multicast_list
= ehea_set_multicast_list
,
3085 .ndo_change_mtu
= ehea_change_mtu
,
3086 .ndo_vlan_rx_register
= ehea_vlan_rx_register
,
3087 .ndo_vlan_rx_add_vid
= ehea_vlan_rx_add_vid
,
3088 .ndo_vlan_rx_kill_vid
= ehea_vlan_rx_kill_vid
,
3089 .ndo_tx_timeout
= ehea_tx_watchdog
,
3092 struct ehea_port
*ehea_setup_single_port(struct ehea_adapter
*adapter
,
3093 u32 logical_port_id
,
3094 struct device_node
*dn
)
3097 struct net_device
*dev
;
3098 struct ehea_port
*port
;
3099 struct device
*port_dev
;
3102 /* allocate memory for the port structures */
3103 dev
= alloc_etherdev(sizeof(struct ehea_port
));
3106 ehea_error("no mem for net_device");
3111 port
= netdev_priv(dev
);
3113 mutex_init(&port
->port_lock
);
3114 port
->state
= EHEA_PORT_DOWN
;
3115 port
->sig_comp_iv
= sq_entries
/ 10;
3117 port
->adapter
= adapter
;
3119 port
->logical_port_id
= logical_port_id
;
3121 port
->msg_enable
= netif_msg_init(msg_level
, EHEA_MSG_DEFAULT
);
3123 port
->mc_list
= kzalloc(sizeof(struct ehea_mc_list
), GFP_KERNEL
);
3124 if (!port
->mc_list
) {
3126 goto out_free_ethdev
;
3129 INIT_LIST_HEAD(&port
->mc_list
->list
);
3131 ret
= ehea_sense_port_attr(port
);
3133 goto out_free_mc_list
;
3135 port_dev
= ehea_register_port(port
, dn
);
3137 goto out_free_mc_list
;
3139 SET_NETDEV_DEV(dev
, port_dev
);
3141 /* initialize net_device structure */
3142 memcpy(dev
->dev_addr
, &port
->mac_addr
, ETH_ALEN
);
3144 dev
->netdev_ops
= &ehea_netdev_ops
;
3145 ehea_set_ethtool_ops(dev
);
3147 dev
->features
= NETIF_F_SG
| NETIF_F_FRAGLIST
| NETIF_F_TSO
3148 | NETIF_F_HIGHDMA
| NETIF_F_IP_CSUM
| NETIF_F_HW_VLAN_TX
3149 | NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
3151 dev
->watchdog_timeo
= EHEA_WATCH_DOG_TIMEOUT
;
3153 INIT_WORK(&port
->reset_task
, ehea_reset_port
);
3155 ret
= register_netdev(dev
);
3157 ehea_error("register_netdev failed. ret=%d", ret
);
3158 goto out_unreg_port
;
3161 port
->lro_max_aggr
= lro_max_aggr
;
3163 ret
= ehea_get_jumboframe_status(port
, &jumbo
);
3165 ehea_error("failed determining jumbo frame status for %s",
3166 port
->netdev
->name
);
3168 ehea_info("%s: Jumbo frames are %sabled", dev
->name
,
3169 jumbo
== 1 ? "en" : "dis");
3171 adapter
->active_ports
++;
3176 ehea_unregister_port(port
);
3179 kfree(port
->mc_list
);
3185 ehea_error("setting up logical port with id=%d failed, ret=%d",
3186 logical_port_id
, ret
);
3190 static void ehea_shutdown_single_port(struct ehea_port
*port
)
3192 struct ehea_adapter
*adapter
= port
->adapter
;
3193 unregister_netdev(port
->netdev
);
3194 ehea_unregister_port(port
);
3195 kfree(port
->mc_list
);
3196 free_netdev(port
->netdev
);
3197 adapter
->active_ports
--;
3200 static int ehea_setup_ports(struct ehea_adapter
*adapter
)
3202 struct device_node
*lhea_dn
;
3203 struct device_node
*eth_dn
= NULL
;
3205 const u32
*dn_log_port_id
;
3208 lhea_dn
= adapter
->ofdev
->node
;
3209 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3211 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3213 if (!dn_log_port_id
) {
3214 ehea_error("bad device node: eth_dn name=%s",
3219 if (ehea_add_adapter_mr(adapter
)) {
3220 ehea_error("creating MR failed");
3221 of_node_put(eth_dn
);
3225 adapter
->port
[i
] = ehea_setup_single_port(adapter
,
3228 if (adapter
->port
[i
])
3229 ehea_info("%s -> logical port id #%d",
3230 adapter
->port
[i
]->netdev
->name
,
3233 ehea_remove_adapter_mr(adapter
);
3240 static struct device_node
*ehea_get_eth_dn(struct ehea_adapter
*adapter
,
3241 u32 logical_port_id
)
3243 struct device_node
*lhea_dn
;
3244 struct device_node
*eth_dn
= NULL
;
3245 const u32
*dn_log_port_id
;
3247 lhea_dn
= adapter
->ofdev
->node
;
3248 while ((eth_dn
= of_get_next_child(lhea_dn
, eth_dn
))) {
3250 dn_log_port_id
= of_get_property(eth_dn
, "ibm,hea-port-no",
3253 if (*dn_log_port_id
== logical_port_id
)
3260 static ssize_t
ehea_probe_port(struct device
*dev
,
3261 struct device_attribute
*attr
,
3262 const char *buf
, size_t count
)
3264 struct ehea_adapter
*adapter
= dev
->driver_data
;
3265 struct ehea_port
*port
;
3266 struct device_node
*eth_dn
= NULL
;
3269 u32 logical_port_id
;
3271 sscanf(buf
, "%d", &logical_port_id
);
3273 port
= ehea_get_port(adapter
, logical_port_id
);
3276 ehea_info("adding port with logical port id=%d failed. port "
3277 "already configured as %s.", logical_port_id
,
3278 port
->netdev
->name
);
3282 eth_dn
= ehea_get_eth_dn(adapter
, logical_port_id
);
3285 ehea_info("no logical port with id %d found", logical_port_id
);
3289 if (ehea_add_adapter_mr(adapter
)) {
3290 ehea_error("creating MR failed");
3294 port
= ehea_setup_single_port(adapter
, logical_port_id
, eth_dn
);
3296 of_node_put(eth_dn
);
3299 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3300 if (!adapter
->port
[i
]) {
3301 adapter
->port
[i
] = port
;
3305 ehea_info("added %s (logical port id=%d)", port
->netdev
->name
,
3308 ehea_remove_adapter_mr(adapter
);
3312 return (ssize_t
) count
;
3315 static ssize_t
ehea_remove_port(struct device
*dev
,
3316 struct device_attribute
*attr
,
3317 const char *buf
, size_t count
)
3319 struct ehea_adapter
*adapter
= dev
->driver_data
;
3320 struct ehea_port
*port
;
3322 u32 logical_port_id
;
3324 sscanf(buf
, "%d", &logical_port_id
);
3326 port
= ehea_get_port(adapter
, logical_port_id
);
3329 ehea_info("removed %s (logical port id=%d)", port
->netdev
->name
,
3332 ehea_shutdown_single_port(port
);
3334 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3335 if (adapter
->port
[i
] == port
) {
3336 adapter
->port
[i
] = NULL
;
3340 ehea_error("removing port with logical port id=%d failed. port "
3341 "not configured.", logical_port_id
);
3345 ehea_remove_adapter_mr(adapter
);
3347 return (ssize_t
) count
;
3350 static DEVICE_ATTR(probe_port
, S_IWUSR
, NULL
, ehea_probe_port
);
3351 static DEVICE_ATTR(remove_port
, S_IWUSR
, NULL
, ehea_remove_port
);
3353 int ehea_create_device_sysfs(struct of_device
*dev
)
3355 int ret
= device_create_file(&dev
->dev
, &dev_attr_probe_port
);
3359 ret
= device_create_file(&dev
->dev
, &dev_attr_remove_port
);
3364 void ehea_remove_device_sysfs(struct of_device
*dev
)
3366 device_remove_file(&dev
->dev
, &dev_attr_probe_port
);
3367 device_remove_file(&dev
->dev
, &dev_attr_remove_port
);
3370 static int __devinit
ehea_probe_adapter(struct of_device
*dev
,
3371 const struct of_device_id
*id
)
3373 struct ehea_adapter
*adapter
;
3374 const u64
*adapter_handle
;
3377 if (!dev
|| !dev
->node
) {
3378 ehea_error("Invalid ibmebus device probed");
3382 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
3385 dev_err(&dev
->dev
, "no mem for ehea_adapter\n");
3389 list_add(&adapter
->list
, &adapter_list
);
3391 adapter
->ofdev
= dev
;
3393 adapter_handle
= of_get_property(dev
->node
, "ibm,hea-handle",
3396 adapter
->handle
= *adapter_handle
;
3398 if (!adapter
->handle
) {
3399 dev_err(&dev
->dev
, "failed getting handle for adapter"
3400 " '%s'\n", dev
->node
->full_name
);
3405 adapter
->pd
= EHEA_PD_ID
;
3407 dev
->dev
.driver_data
= adapter
;
3410 /* initialize adapter and ports */
3411 /* get adapter properties */
3412 ret
= ehea_sense_adapter_attr(adapter
);
3414 dev_err(&dev
->dev
, "sense_adapter_attr failed: %d\n", ret
);
3418 adapter
->neq
= ehea_create_eq(adapter
,
3419 EHEA_NEQ
, EHEA_MAX_ENTRIES_EQ
, 1);
3420 if (!adapter
->neq
) {
3422 dev_err(&dev
->dev
, "NEQ creation failed\n");
3426 tasklet_init(&adapter
->neq_tasklet
, ehea_neq_tasklet
,
3427 (unsigned long)adapter
);
3429 ret
= ibmebus_request_irq(adapter
->neq
->attr
.ist1
,
3430 ehea_interrupt_neq
, IRQF_DISABLED
,
3431 "ehea_neq", adapter
);
3433 dev_err(&dev
->dev
, "requesting NEQ IRQ failed\n");
3437 ret
= ehea_create_device_sysfs(dev
);
3441 ret
= ehea_setup_ports(adapter
);
3443 dev_err(&dev
->dev
, "setup_ports failed\n");
3444 goto out_rem_dev_sysfs
;
3451 ehea_remove_device_sysfs(dev
);
3454 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3457 ehea_destroy_eq(adapter
->neq
);
3460 list_del(&adapter
->list
);
3464 ehea_update_firmware_handles();
3469 static int __devexit
ehea_remove(struct of_device
*dev
)
3471 struct ehea_adapter
*adapter
= dev
->dev
.driver_data
;
3474 for (i
= 0; i
< EHEA_MAX_PORTS
; i
++)
3475 if (adapter
->port
[i
]) {
3476 ehea_shutdown_single_port(adapter
->port
[i
]);
3477 adapter
->port
[i
] = NULL
;
3480 ehea_remove_device_sysfs(dev
);
3482 flush_scheduled_work();
3484 ibmebus_free_irq(adapter
->neq
->attr
.ist1
, adapter
);
3485 tasklet_kill(&adapter
->neq_tasklet
);
3487 ehea_destroy_eq(adapter
->neq
);
3488 ehea_remove_adapter_mr(adapter
);
3489 list_del(&adapter
->list
);
3492 ehea_update_firmware_handles();
3497 void ehea_crash_handler(void)
3501 if (ehea_fw_handles
.arr
)
3502 for (i
= 0; i
< ehea_fw_handles
.num_entries
; i
++)
3503 ehea_h_free_resource(ehea_fw_handles
.arr
[i
].adh
,
3504 ehea_fw_handles
.arr
[i
].fwh
,
3507 if (ehea_bcmc_regs
.arr
)
3508 for (i
= 0; i
< ehea_bcmc_regs
.num_entries
; i
++)
3509 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs
.arr
[i
].adh
,
3510 ehea_bcmc_regs
.arr
[i
].port_id
,
3511 ehea_bcmc_regs
.arr
[i
].reg_type
,
3512 ehea_bcmc_regs
.arr
[i
].macaddr
,
3516 static int ehea_mem_notifier(struct notifier_block
*nb
,
3517 unsigned long action
, void *data
)
3519 struct memory_notify
*arg
= data
;
3521 case MEM_CANCEL_OFFLINE
:
3522 ehea_info("memory offlining canceled");
3523 /* Readd canceled memory block */
3525 ehea_info("memory is going online");
3526 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3527 if (ehea_add_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3529 ehea_rereg_mrs(NULL
);
3531 case MEM_GOING_OFFLINE
:
3532 ehea_info("memory is going offline");
3533 set_bit(__EHEA_STOP_XFER
, &ehea_driver_flags
);
3534 if (ehea_rem_sect_bmap(arg
->start_pfn
, arg
->nr_pages
))
3536 ehea_rereg_mrs(NULL
);
3542 ehea_update_firmware_handles();
3547 static struct notifier_block ehea_mem_nb
= {
3548 .notifier_call
= ehea_mem_notifier
,
3551 static int ehea_reboot_notifier(struct notifier_block
*nb
,
3552 unsigned long action
, void *unused
)
3554 if (action
== SYS_RESTART
) {
3555 ehea_info("Reboot: freeing all eHEA resources");
3556 ibmebus_unregister_driver(&ehea_driver
);
3561 static struct notifier_block ehea_reboot_nb
= {
3562 .notifier_call
= ehea_reboot_notifier
,
3565 static int check_module_parm(void)
3569 if ((rq1_entries
< EHEA_MIN_ENTRIES_QP
) ||
3570 (rq1_entries
> EHEA_MAX_ENTRIES_RQ1
)) {
3571 ehea_info("Bad parameter: rq1_entries");
3574 if ((rq2_entries
< EHEA_MIN_ENTRIES_QP
) ||
3575 (rq2_entries
> EHEA_MAX_ENTRIES_RQ2
)) {
3576 ehea_info("Bad parameter: rq2_entries");
3579 if ((rq3_entries
< EHEA_MIN_ENTRIES_QP
) ||
3580 (rq3_entries
> EHEA_MAX_ENTRIES_RQ3
)) {
3581 ehea_info("Bad parameter: rq3_entries");
3584 if ((sq_entries
< EHEA_MIN_ENTRIES_QP
) ||
3585 (sq_entries
> EHEA_MAX_ENTRIES_SQ
)) {
3586 ehea_info("Bad parameter: sq_entries");
3593 static ssize_t
ehea_show_capabilities(struct device_driver
*drv
,
3596 return sprintf(buf
, "%d", EHEA_CAPABILITIES
);
3599 static DRIVER_ATTR(capabilities
, S_IRUSR
| S_IRGRP
| S_IROTH
,
3600 ehea_show_capabilities
, NULL
);
3602 int __init
ehea_module_init(void)
3606 printk(KERN_INFO
"IBM eHEA ethernet device driver (Release %s)\n",
3610 INIT_WORK(&ehea_rereg_mr_task
, ehea_rereg_mrs
);
3611 memset(&ehea_fw_handles
, 0, sizeof(ehea_fw_handles
));
3612 memset(&ehea_bcmc_regs
, 0, sizeof(ehea_bcmc_regs
));
3614 mutex_init(&ehea_fw_handles
.lock
);
3615 spin_lock_init(&ehea_bcmc_regs
.lock
);
3617 ret
= check_module_parm();
3621 ret
= ehea_create_busmap();
3625 ret
= register_reboot_notifier(&ehea_reboot_nb
);
3627 ehea_info("failed registering reboot notifier");
3629 ret
= register_memory_notifier(&ehea_mem_nb
);
3631 ehea_info("failed registering memory remove notifier");
3633 ret
= crash_shutdown_register(&ehea_crash_handler
);
3635 ehea_info("failed registering crash handler");
3637 ret
= ibmebus_register_driver(&ehea_driver
);
3639 ehea_error("failed registering eHEA device driver on ebus");
3643 ret
= driver_create_file(&ehea_driver
.driver
,
3644 &driver_attr_capabilities
);
3646 ehea_error("failed to register capabilities attribute, ret=%d",
3654 ibmebus_unregister_driver(&ehea_driver
);
3656 unregister_memory_notifier(&ehea_mem_nb
);
3657 unregister_reboot_notifier(&ehea_reboot_nb
);
3658 crash_shutdown_unregister(&ehea_crash_handler
);
3663 static void __exit
ehea_module_exit(void)
3667 flush_scheduled_work();
3668 driver_remove_file(&ehea_driver
.driver
, &driver_attr_capabilities
);
3669 ibmebus_unregister_driver(&ehea_driver
);
3670 unregister_reboot_notifier(&ehea_reboot_nb
);
3671 ret
= crash_shutdown_unregister(&ehea_crash_handler
);
3673 ehea_info("failed unregistering crash handler");
3674 unregister_memory_notifier(&ehea_mem_nb
);
3675 kfree(ehea_fw_handles
.arr
);
3676 kfree(ehea_bcmc_regs
.arr
);
3677 ehea_destroy_busmap();
3680 module_init(ehea_module_init
);
3681 module_exit(ehea_module_exit
);