2 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
22 #include <linux/netdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/ethtool.h>
25 #include <linux/rtnetlink.h>
31 #define BNAD_NUM_TXF_COUNTERS 12
32 #define BNAD_NUM_RXF_COUNTERS 10
33 #define BNAD_NUM_CQ_COUNTERS (3 + 5)
34 #define BNAD_NUM_RXQ_COUNTERS 6
35 #define BNAD_NUM_TXQ_COUNTERS 5
37 #define BNAD_ETHTOOL_STATS_NUM \
38 (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
39 sizeof(struct bnad_drv_stats) / sizeof(u64) + \
40 offsetof(struct bfi_enet_stats, rxf_stats[0]) / sizeof(u64))
42 static const char *bnad_net_stats_strings
[BNAD_ETHTOOL_STATS_NUM
] = {
64 "tx_heartbeat_errors",
72 "netif_queue_stopped",
82 "tx_skb_mss_too_long",
83 "tx_skb_tso_too_short",
85 "tx_skb_non_tso_too_long",
89 "tx_skb_headlen_too_long",
90 "tx_skb_headlen_zero",
92 "tx_skb_len_mismatch",
100 "rxp_info_alloc_failed",
101 "mbox_intr_disabled",
103 "tx_unmap_q_alloc_failed",
104 "rx_unmap_q_alloc_failed",
105 "rxbuf_alloc_failed",
113 "mac_frame_512_1023",
114 "mac_frame_1024_1518",
115 "mac_frame_1518_1522",
121 "mac_rx_control_frames",
123 "mac_rx_unknown_opcode",
124 "mac_rx_alignment_error",
125 "mac_rx_frame_length_error",
127 "mac_rx_carrier_sense_error",
140 "mac_tx_excessive_deferral",
141 "mac_tx_single_collision",
142 "mac_tx_muliple_collision",
143 "mac_tx_late_collision",
144 "mac_tx_excessive_collision",
145 "mac_tx_total_collision",
146 "mac_tx_pause_honored",
150 "mac_tx_control_frame",
163 "bpc_tx_zero_pause_0",
164 "bpc_tx_zero_pause_1",
165 "bpc_tx_zero_pause_2",
166 "bpc_tx_zero_pause_3",
167 "bpc_tx_zero_pause_4",
168 "bpc_tx_zero_pause_5",
169 "bpc_tx_zero_pause_6",
170 "bpc_tx_zero_pause_7",
171 "bpc_tx_first_pause_0",
172 "bpc_tx_first_pause_1",
173 "bpc_tx_first_pause_2",
174 "bpc_tx_first_pause_3",
175 "bpc_tx_first_pause_4",
176 "bpc_tx_first_pause_5",
177 "bpc_tx_first_pause_6",
178 "bpc_tx_first_pause_7",
188 "bpc_rx_zero_pause_0",
189 "bpc_rx_zero_pause_1",
190 "bpc_rx_zero_pause_2",
191 "bpc_rx_zero_pause_3",
192 "bpc_rx_zero_pause_4",
193 "bpc_rx_zero_pause_5",
194 "bpc_rx_zero_pause_6",
195 "bpc_rx_zero_pause_7",
196 "bpc_rx_first_pause_0",
197 "bpc_rx_first_pause_1",
198 "bpc_rx_first_pause_2",
199 "bpc_rx_first_pause_3",
200 "bpc_rx_first_pause_4",
201 "bpc_rx_first_pause_5",
202 "bpc_rx_first_pause_6",
203 "bpc_rx_first_pause_7",
207 "rad_rx_vlan_frames",
209 "rad_rx_ucast_octets",
212 "rad_rx_mcast_octets",
215 "rad_rx_bcast_octets",
221 "rlb_rad_rx_vlan_frames",
223 "rlb_rad_rx_ucast_octets",
224 "rlb_rad_rx_ucast_vlan",
226 "rlb_rad_rx_mcast_octets",
227 "rlb_rad_rx_mcast_vlan",
229 "rlb_rad_rx_bcast_octets",
230 "rlb_rad_rx_bcast_vlan",
233 "fc_rx_ucast_octets",
236 "fc_rx_mcast_octets",
239 "fc_rx_bcast_octets",
243 "fc_tx_ucast_octets",
246 "fc_tx_mcast_octets",
249 "fc_tx_bcast_octets",
252 "fc_tx_parity_errors",
254 "fc_tx_fid_parity_errors",
258 bnad_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
260 cmd
->supported
= SUPPORTED_10000baseT_Full
;
261 cmd
->advertising
= ADVERTISED_10000baseT_Full
;
262 cmd
->autoneg
= AUTONEG_DISABLE
;
263 cmd
->supported
|= SUPPORTED_FIBRE
;
264 cmd
->advertising
|= ADVERTISED_FIBRE
;
265 cmd
->port
= PORT_FIBRE
;
266 cmd
->phy_address
= 0;
268 if (netif_carrier_ok(netdev
)) {
269 ethtool_cmd_speed_set(cmd
, SPEED_10000
);
270 cmd
->duplex
= DUPLEX_FULL
;
272 ethtool_cmd_speed_set(cmd
, SPEED_UNKNOWN
);
273 cmd
->duplex
= DUPLEX_UNKNOWN
;
275 cmd
->transceiver
= XCVR_EXTERNAL
;
283 bnad_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
285 /* 10G full duplex setting supported only */
286 if (cmd
->autoneg
== AUTONEG_ENABLE
)
287 return -EOPNOTSUPP
; else {
288 if ((ethtool_cmd_speed(cmd
) == SPEED_10000
)
289 && (cmd
->duplex
== DUPLEX_FULL
))
297 bnad_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
299 struct bnad
*bnad
= netdev_priv(netdev
);
300 struct bfa_ioc_attr
*ioc_attr
;
303 strlcpy(drvinfo
->driver
, BNAD_NAME
, sizeof(drvinfo
->driver
));
304 strlcpy(drvinfo
->version
, BNAD_VERSION
, sizeof(drvinfo
->version
));
306 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
308 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
309 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
310 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
312 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
313 sizeof(drvinfo
->fw_version
));
317 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
318 sizeof(drvinfo
->bus_info
));
322 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
324 wolinfo
->supported
= 0;
325 wolinfo
->wolopts
= 0;
329 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
331 struct bnad
*bnad
= netdev_priv(netdev
);
334 /* Lock rqd. to access bnad->bna_lock */
335 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
336 coalesce
->use_adaptive_rx_coalesce
=
337 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
338 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
340 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
341 BFI_COALESCING_TIMER_UNIT
;
342 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
343 BFI_COALESCING_TIMER_UNIT
;
344 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
350 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
352 struct bnad
*bnad
= netdev_priv(netdev
);
356 if (coalesce
->rx_coalesce_usecs
== 0 ||
357 coalesce
->rx_coalesce_usecs
>
358 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
361 if (coalesce
->tx_coalesce_usecs
== 0 ||
362 coalesce
->tx_coalesce_usecs
>
363 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
366 mutex_lock(&bnad
->conf_mutex
);
368 * Do not need to store rx_coalesce_usecs here
369 * Every time DIM is disabled, we can get it from the
372 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
373 if (coalesce
->use_adaptive_rx_coalesce
) {
374 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
375 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
376 bnad_dim_timer_start(bnad
);
379 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
380 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
381 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
382 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
384 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
388 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
390 del_timer_sync(&bnad
->dim_timer
);
391 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
392 bnad_rx_coalescing_timeo_set(bnad
);
395 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
396 BFI_COALESCING_TIMER_UNIT
) {
397 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
398 BFI_COALESCING_TIMER_UNIT
;
399 bnad_tx_coalescing_timeo_set(bnad
);
402 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
403 BFI_COALESCING_TIMER_UNIT
) {
404 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
405 BFI_COALESCING_TIMER_UNIT
;
407 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
408 bnad_rx_coalescing_timeo_set(bnad
);
412 /* Add Tx Inter-pkt DMA count? */
414 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
416 mutex_unlock(&bnad
->conf_mutex
);
421 bnad_get_ringparam(struct net_device
*netdev
,
422 struct ethtool_ringparam
*ringparam
)
424 struct bnad
*bnad
= netdev_priv(netdev
);
426 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
427 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
429 ringparam
->rx_pending
= bnad
->rxq_depth
;
430 ringparam
->tx_pending
= bnad
->txq_depth
;
434 bnad_set_ringparam(struct net_device
*netdev
,
435 struct ethtool_ringparam
*ringparam
)
437 int i
, current_err
, err
= 0;
438 struct bnad
*bnad
= netdev_priv(netdev
);
441 mutex_lock(&bnad
->conf_mutex
);
442 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
443 ringparam
->tx_pending
== bnad
->txq_depth
) {
444 mutex_unlock(&bnad
->conf_mutex
);
448 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
449 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
450 !is_power_of_2(ringparam
->rx_pending
)) {
451 mutex_unlock(&bnad
->conf_mutex
);
454 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
455 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
456 !is_power_of_2(ringparam
->tx_pending
)) {
457 mutex_unlock(&bnad
->conf_mutex
);
461 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
462 bnad
->rxq_depth
= ringparam
->rx_pending
;
463 if (!netif_running(netdev
)) {
464 mutex_unlock(&bnad
->conf_mutex
);
468 for (i
= 0; i
< bnad
->num_rx
; i
++) {
469 if (!bnad
->rx_info
[i
].rx
)
471 bnad_destroy_rx(bnad
, i
);
472 current_err
= bnad_setup_rx(bnad
, i
);
473 if (current_err
&& !err
)
477 if (!err
&& bnad
->rx_info
[0].rx
) {
478 /* restore rx configuration */
479 bnad_restore_vlans(bnad
, 0);
480 bnad_enable_default_bcast(bnad
);
481 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
482 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
483 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
484 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
486 bnad_set_rx_mode(netdev
);
489 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
490 bnad
->txq_depth
= ringparam
->tx_pending
;
491 if (!netif_running(netdev
)) {
492 mutex_unlock(&bnad
->conf_mutex
);
496 for (i
= 0; i
< bnad
->num_tx
; i
++) {
497 if (!bnad
->tx_info
[i
].tx
)
499 bnad_destroy_tx(bnad
, i
);
500 current_err
= bnad_setup_tx(bnad
, i
);
501 if (current_err
&& !err
)
506 mutex_unlock(&bnad
->conf_mutex
);
511 bnad_get_pauseparam(struct net_device
*netdev
,
512 struct ethtool_pauseparam
*pauseparam
)
514 struct bnad
*bnad
= netdev_priv(netdev
);
516 pauseparam
->autoneg
= 0;
517 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
518 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
522 bnad_set_pauseparam(struct net_device
*netdev
,
523 struct ethtool_pauseparam
*pauseparam
)
525 struct bnad
*bnad
= netdev_priv(netdev
);
526 struct bna_pause_config pause_config
;
529 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
532 mutex_lock(&bnad
->conf_mutex
);
533 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
534 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
535 pause_config
.rx_pause
= pauseparam
->rx_pause
;
536 pause_config
.tx_pause
= pauseparam
->tx_pause
;
537 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
538 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
539 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
541 mutex_unlock(&bnad
->conf_mutex
);
546 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
548 struct bnad
*bnad
= netdev_priv(netdev
);
552 mutex_lock(&bnad
->conf_mutex
);
556 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
557 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
559 memcpy(string
, bnad_net_stats_strings
[i
],
561 string
+= ETH_GSTRING_LEN
;
563 bmap
= bna_tx_rid_mask(&bnad
->bna
);
564 for (i
= 0; bmap
; i
++) {
566 sprintf(string
, "txf%d_ucast_octets", i
);
567 string
+= ETH_GSTRING_LEN
;
568 sprintf(string
, "txf%d_ucast", i
);
569 string
+= ETH_GSTRING_LEN
;
570 sprintf(string
, "txf%d_ucast_vlan", i
);
571 string
+= ETH_GSTRING_LEN
;
572 sprintf(string
, "txf%d_mcast_octets", i
);
573 string
+= ETH_GSTRING_LEN
;
574 sprintf(string
, "txf%d_mcast", i
);
575 string
+= ETH_GSTRING_LEN
;
576 sprintf(string
, "txf%d_mcast_vlan", i
);
577 string
+= ETH_GSTRING_LEN
;
578 sprintf(string
, "txf%d_bcast_octets", i
);
579 string
+= ETH_GSTRING_LEN
;
580 sprintf(string
, "txf%d_bcast", i
);
581 string
+= ETH_GSTRING_LEN
;
582 sprintf(string
, "txf%d_bcast_vlan", i
);
583 string
+= ETH_GSTRING_LEN
;
584 sprintf(string
, "txf%d_errors", i
);
585 string
+= ETH_GSTRING_LEN
;
586 sprintf(string
, "txf%d_filter_vlan", i
);
587 string
+= ETH_GSTRING_LEN
;
588 sprintf(string
, "txf%d_filter_mac_sa", i
);
589 string
+= ETH_GSTRING_LEN
;
594 bmap
= bna_rx_rid_mask(&bnad
->bna
);
595 for (i
= 0; bmap
; i
++) {
597 sprintf(string
, "rxf%d_ucast_octets", i
);
598 string
+= ETH_GSTRING_LEN
;
599 sprintf(string
, "rxf%d_ucast", i
);
600 string
+= ETH_GSTRING_LEN
;
601 sprintf(string
, "rxf%d_ucast_vlan", i
);
602 string
+= ETH_GSTRING_LEN
;
603 sprintf(string
, "rxf%d_mcast_octets", i
);
604 string
+= ETH_GSTRING_LEN
;
605 sprintf(string
, "rxf%d_mcast", i
);
606 string
+= ETH_GSTRING_LEN
;
607 sprintf(string
, "rxf%d_mcast_vlan", i
);
608 string
+= ETH_GSTRING_LEN
;
609 sprintf(string
, "rxf%d_bcast_octets", i
);
610 string
+= ETH_GSTRING_LEN
;
611 sprintf(string
, "rxf%d_bcast", i
);
612 string
+= ETH_GSTRING_LEN
;
613 sprintf(string
, "rxf%d_bcast_vlan", i
);
614 string
+= ETH_GSTRING_LEN
;
615 sprintf(string
, "rxf%d_frame_drops", i
);
616 string
+= ETH_GSTRING_LEN
;
622 for (i
= 0; i
< bnad
->num_rx
; i
++) {
623 if (!bnad
->rx_info
[i
].rx
)
625 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
626 sprintf(string
, "cq%d_producer_index", q_num
);
627 string
+= ETH_GSTRING_LEN
;
628 sprintf(string
, "cq%d_consumer_index", q_num
);
629 string
+= ETH_GSTRING_LEN
;
630 sprintf(string
, "cq%d_hw_producer_index",
632 string
+= ETH_GSTRING_LEN
;
633 sprintf(string
, "cq%d_intr", q_num
);
634 string
+= ETH_GSTRING_LEN
;
635 sprintf(string
, "cq%d_poll", q_num
);
636 string
+= ETH_GSTRING_LEN
;
637 sprintf(string
, "cq%d_schedule", q_num
);
638 string
+= ETH_GSTRING_LEN
;
639 sprintf(string
, "cq%d_keep_poll", q_num
);
640 string
+= ETH_GSTRING_LEN
;
641 sprintf(string
, "cq%d_complete", q_num
);
642 string
+= ETH_GSTRING_LEN
;
648 for (i
= 0; i
< bnad
->num_rx
; i
++) {
649 if (!bnad
->rx_info
[i
].rx
)
651 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
652 sprintf(string
, "rxq%d_packets", q_num
);
653 string
+= ETH_GSTRING_LEN
;
654 sprintf(string
, "rxq%d_bytes", q_num
);
655 string
+= ETH_GSTRING_LEN
;
656 sprintf(string
, "rxq%d_packets_with_error",
658 string
+= ETH_GSTRING_LEN
;
659 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
660 string
+= ETH_GSTRING_LEN
;
661 sprintf(string
, "rxq%d_producer_index", q_num
);
662 string
+= ETH_GSTRING_LEN
;
663 sprintf(string
, "rxq%d_consumer_index", q_num
);
664 string
+= ETH_GSTRING_LEN
;
666 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
667 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
669 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
671 sprintf(string
, "rxq%d_packets", q_num
);
672 string
+= ETH_GSTRING_LEN
;
673 sprintf(string
, "rxq%d_bytes", q_num
);
674 string
+= ETH_GSTRING_LEN
;
676 "rxq%d_packets_with_error", q_num
);
677 string
+= ETH_GSTRING_LEN
;
678 sprintf(string
, "rxq%d_allocbuf_failed",
680 string
+= ETH_GSTRING_LEN
;
681 sprintf(string
, "rxq%d_producer_index",
683 string
+= ETH_GSTRING_LEN
;
684 sprintf(string
, "rxq%d_consumer_index",
686 string
+= ETH_GSTRING_LEN
;
693 for (i
= 0; i
< bnad
->num_tx
; i
++) {
694 if (!bnad
->tx_info
[i
].tx
)
696 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
697 sprintf(string
, "txq%d_packets", q_num
);
698 string
+= ETH_GSTRING_LEN
;
699 sprintf(string
, "txq%d_bytes", q_num
);
700 string
+= ETH_GSTRING_LEN
;
701 sprintf(string
, "txq%d_producer_index", q_num
);
702 string
+= ETH_GSTRING_LEN
;
703 sprintf(string
, "txq%d_consumer_index", q_num
);
704 string
+= ETH_GSTRING_LEN
;
705 sprintf(string
, "txq%d_hw_consumer_index",
707 string
+= ETH_GSTRING_LEN
;
718 mutex_unlock(&bnad
->conf_mutex
);
722 bnad_get_stats_count_locked(struct net_device
*netdev
)
724 struct bnad
*bnad
= netdev_priv(netdev
);
725 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
728 bmap
= bna_tx_rid_mask(&bnad
->bna
);
729 for (i
= 0; bmap
; i
++) {
734 bmap
= bna_rx_rid_mask(&bnad
->bna
);
735 for (i
= 0; bmap
; i
++) {
740 count
= BNAD_ETHTOOL_STATS_NUM
+
741 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
742 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
744 for (i
= 0; i
< bnad
->num_rx
; i
++) {
745 if (!bnad
->rx_info
[i
].rx
)
747 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
748 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
749 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
750 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
751 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
752 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
753 count
+= BNAD_NUM_RXQ_COUNTERS
;
756 for (i
= 0; i
< bnad
->num_tx
; i
++) {
757 if (!bnad
->tx_info
[i
].tx
)
759 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
765 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
768 struct bna_rcb
*rcb
= NULL
;
769 struct bna_tcb
*tcb
= NULL
;
771 for (i
= 0; i
< bnad
->num_rx
; i
++) {
772 if (!bnad
->rx_info
[i
].rx
)
774 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
775 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
776 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
777 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
778 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
780 buf
[bi
++] = 0; /* ccb->consumer_index */
781 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
782 ccb
->hw_producer_index
);
784 buf
[bi
++] = bnad
->rx_info
[i
].
785 rx_ctrl
[j
].rx_intr_ctr
;
786 buf
[bi
++] = bnad
->rx_info
[i
].
787 rx_ctrl
[j
].rx_poll_ctr
;
788 buf
[bi
++] = bnad
->rx_info
[i
].
789 rx_ctrl
[j
].rx_schedule
;
790 buf
[bi
++] = bnad
->rx_info
[i
].
791 rx_ctrl
[j
].rx_keep_poll
;
792 buf
[bi
++] = bnad
->rx_info
[i
].
793 rx_ctrl
[j
].rx_complete
;
796 for (i
= 0; i
< bnad
->num_rx
; i
++) {
797 if (!bnad
->rx_info
[i
].rx
)
799 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
800 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
801 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
802 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
804 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
806 buf
[bi
++] = rcb
->rxq
->rx_packets
;
807 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
808 buf
[bi
++] = rcb
->rxq
->
809 rx_packets_with_error
;
810 buf
[bi
++] = rcb
->rxq
->
812 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
813 buf
[bi
++] = rcb
->producer_index
;
814 buf
[bi
++] = rcb
->consumer_index
;
816 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
817 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
819 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
821 buf
[bi
++] = rcb
->rxq
->rx_packets
;
822 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
823 buf
[bi
++] = rcb
->rxq
->
824 rx_packets_with_error
;
825 buf
[bi
++] = rcb
->rxq
->
827 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
828 buf
[bi
++] = rcb
->producer_index
;
829 buf
[bi
++] = rcb
->consumer_index
;
834 for (i
= 0; i
< bnad
->num_tx
; i
++) {
835 if (!bnad
->tx_info
[i
].tx
)
837 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
838 if (bnad
->tx_info
[i
].tcb
[j
] &&
839 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
840 tcb
= bnad
->tx_info
[i
].tcb
[j
];
841 buf
[bi
++] = tcb
->txq
->tx_packets
;
842 buf
[bi
++] = tcb
->txq
->tx_bytes
;
843 buf
[bi
++] = tcb
->producer_index
;
844 buf
[bi
++] = tcb
->consumer_index
;
845 buf
[bi
++] = *(tcb
->hw_consumer_index
);
853 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
856 struct bnad
*bnad
= netdev_priv(netdev
);
859 struct rtnl_link_stats64
*net_stats64
;
863 mutex_lock(&bnad
->conf_mutex
);
864 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
865 mutex_unlock(&bnad
->conf_mutex
);
870 * Used bna_lock to sync reads from bna_stats, which is written
871 * under the same lock
873 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
875 memset(buf
, 0, stats
->n_stats
* sizeof(u64
));
877 net_stats64
= (struct rtnl_link_stats64
*)buf
;
878 bnad_netdev_qstats_fill(bnad
, net_stats64
);
879 bnad_netdev_hwstats_fill(bnad
, net_stats64
);
881 bi
= sizeof(*net_stats64
) / sizeof(u64
);
883 /* Get netif_queue_stopped from stack */
884 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
886 /* Fill driver stats into ethtool buffers */
887 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
888 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
889 buf
[bi
++] = stats64
[i
];
891 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
892 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
894 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
897 buf
[bi
++] = stats64
[i
];
899 /* Fill txf stats into ethtool buffers */
900 bmap
= bna_tx_rid_mask(&bnad
->bna
);
901 for (i
= 0; bmap
; i
++) {
903 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
904 hw_stats
.txf_stats
[i
];
905 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
907 buf
[bi
++] = stats64
[j
];
912 /* Fill rxf stats into ethtool buffers */
913 bmap
= bna_rx_rid_mask(&bnad
->bna
);
914 for (i
= 0; bmap
; i
++) {
916 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
917 hw_stats
.rxf_stats
[i
];
918 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
920 buf
[bi
++] = stats64
[j
];
925 /* Fill per Q stats into ethtool buffers */
926 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
928 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
930 mutex_unlock(&bnad
->conf_mutex
);
934 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
938 return bnad_get_stats_count_locked(netdev
);
945 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
948 struct bfa_flash_attr
*flash_attr
;
949 struct bnad_iocmd_comp fcomp
;
950 u32 i
, flash_part
= 0, ret
;
951 unsigned long flags
= 0;
953 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
958 fcomp
.comp_status
= 0;
960 init_completion(&fcomp
.comp
);
961 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
962 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
963 bnad_cb_completion
, &fcomp
);
964 if (ret
!= BFA_STATUS_OK
) {
965 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
969 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
970 wait_for_completion(&fcomp
.comp
);
971 ret
= fcomp
.comp_status
;
973 /* Check for the flash type & base offset value */
974 if (ret
== BFA_STATUS_OK
) {
975 for (i
= 0; i
< flash_attr
->npart
; i
++) {
976 if (offset
>= flash_attr
->part
[i
].part_off
&&
977 offset
< (flash_attr
->part
[i
].part_off
+
978 flash_attr
->part
[i
].part_size
)) {
979 flash_part
= flash_attr
->part
[i
].part_type
;
980 *base_offset
= flash_attr
->part
[i
].part_off
;
990 bnad_get_eeprom_len(struct net_device
*netdev
)
992 return BFA_TOTAL_FLASH_SIZE
;
996 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
999 struct bnad
*bnad
= netdev_priv(netdev
);
1000 struct bnad_iocmd_comp fcomp
;
1001 u32 flash_part
= 0, base_offset
= 0;
1002 unsigned long flags
= 0;
1005 /* Fill the magic value */
1006 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
1008 /* Query the flash partition based on the offset */
1009 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1010 eeprom
->offset
, &base_offset
);
1011 if (flash_part
== 0)
1015 fcomp
.comp_status
= 0;
1017 init_completion(&fcomp
.comp
);
1018 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1019 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1020 bnad
->id
, bytes
, eeprom
->len
,
1021 eeprom
->offset
- base_offset
,
1022 bnad_cb_completion
, &fcomp
);
1023 if (ret
!= BFA_STATUS_OK
) {
1024 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1028 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1029 wait_for_completion(&fcomp
.comp
);
1030 ret
= fcomp
.comp_status
;
1036 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1039 struct bnad
*bnad
= netdev_priv(netdev
);
1040 struct bnad_iocmd_comp fcomp
;
1041 u32 flash_part
= 0, base_offset
= 0;
1042 unsigned long flags
= 0;
1045 /* Check if the flash update request is valid */
1046 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1047 (bnad
->pcidev
->device
<< 16)))
1050 /* Query the flash partition based on the offset */
1051 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1052 eeprom
->offset
, &base_offset
);
1053 if (flash_part
== 0)
1057 fcomp
.comp_status
= 0;
1059 init_completion(&fcomp
.comp
);
1060 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1061 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1062 bnad
->id
, bytes
, eeprom
->len
,
1063 eeprom
->offset
- base_offset
,
1064 bnad_cb_completion
, &fcomp
);
1065 if (ret
!= BFA_STATUS_OK
) {
1066 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1070 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1071 wait_for_completion(&fcomp
.comp
);
1072 ret
= fcomp
.comp_status
;
1078 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1080 struct bnad
*bnad
= netdev_priv(netdev
);
1081 struct bnad_iocmd_comp fcomp
;
1082 const struct firmware
*fw
;
1085 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1087 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1092 fcomp
.comp_status
= 0;
1094 init_completion(&fcomp
.comp
);
1095 spin_lock_irq(&bnad
->bna_lock
);
1096 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1097 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1098 bnad_cb_completion
, &fcomp
);
1099 if (ret
!= BFA_STATUS_OK
) {
1100 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1102 spin_unlock_irq(&bnad
->bna_lock
);
1106 spin_unlock_irq(&bnad
->bna_lock
);
1107 wait_for_completion(&fcomp
.comp
);
1108 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1111 "firmware image update failed with err=%d\n",
1115 release_firmware(fw
);
1119 static const struct ethtool_ops bnad_ethtool_ops
= {
1120 .get_settings
= bnad_get_settings
,
1121 .set_settings
= bnad_set_settings
,
1122 .get_drvinfo
= bnad_get_drvinfo
,
1123 .get_wol
= bnad_get_wol
,
1124 .get_link
= ethtool_op_get_link
,
1125 .get_coalesce
= bnad_get_coalesce
,
1126 .set_coalesce
= bnad_set_coalesce
,
1127 .get_ringparam
= bnad_get_ringparam
,
1128 .set_ringparam
= bnad_set_ringparam
,
1129 .get_pauseparam
= bnad_get_pauseparam
,
1130 .set_pauseparam
= bnad_set_pauseparam
,
1131 .get_strings
= bnad_get_strings
,
1132 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1133 .get_sset_count
= bnad_get_sset_count
,
1134 .get_eeprom_len
= bnad_get_eeprom_len
,
1135 .get_eeprom
= bnad_get_eeprom
,
1136 .set_eeprom
= bnad_set_eeprom
,
1137 .flash_device
= bnad_flash_device
,
1138 .get_ts_info
= ethtool_op_get_ts_info
,
1142 bnad_set_ethtool_ops(struct net_device
*netdev
)
1144 netdev
->ethtool_ops
= &bnad_ethtool_ops
;