1 // SPDX-License-Identifier: GPL-2.0-only
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
14 #include <linux/netdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/ethtool.h>
17 #include <linux/rtnetlink.h>
23 #define BNAD_NUM_TXF_COUNTERS 12
24 #define BNAD_NUM_RXF_COUNTERS 10
25 #define BNAD_NUM_CQ_COUNTERS (3 + 5)
26 #define BNAD_NUM_RXQ_COUNTERS 7
27 #define BNAD_NUM_TXQ_COUNTERS 5
29 static const char *bnad_net_stats_strings
[] = {
47 "netif_queue_stopped",
57 "tx_skb_mss_too_long",
58 "tx_skb_tso_too_short",
60 "tx_skb_non_tso_too_long",
64 "tx_skb_headlen_too_long",
65 "tx_skb_headlen_zero",
67 "tx_skb_len_mismatch",
75 "rxp_info_alloc_failed",
78 "tx_unmap_q_alloc_failed",
79 "rx_unmap_q_alloc_failed",
89 "mac_frame_1024_1518",
90 "mac_frame_1518_1522",
96 "mac_rx_control_frames",
98 "mac_rx_unknown_opcode",
99 "mac_rx_alignment_error",
100 "mac_rx_frame_length_error",
102 "mac_rx_carrier_sense_error",
115 "mac_tx_excessive_deferral",
116 "mac_tx_single_collision",
117 "mac_tx_muliple_collision",
118 "mac_tx_late_collision",
119 "mac_tx_excessive_collision",
120 "mac_tx_total_collision",
121 "mac_tx_pause_honored",
125 "mac_tx_control_frame",
138 "bpc_tx_zero_pause_0",
139 "bpc_tx_zero_pause_1",
140 "bpc_tx_zero_pause_2",
141 "bpc_tx_zero_pause_3",
142 "bpc_tx_zero_pause_4",
143 "bpc_tx_zero_pause_5",
144 "bpc_tx_zero_pause_6",
145 "bpc_tx_zero_pause_7",
146 "bpc_tx_first_pause_0",
147 "bpc_tx_first_pause_1",
148 "bpc_tx_first_pause_2",
149 "bpc_tx_first_pause_3",
150 "bpc_tx_first_pause_4",
151 "bpc_tx_first_pause_5",
152 "bpc_tx_first_pause_6",
153 "bpc_tx_first_pause_7",
163 "bpc_rx_zero_pause_0",
164 "bpc_rx_zero_pause_1",
165 "bpc_rx_zero_pause_2",
166 "bpc_rx_zero_pause_3",
167 "bpc_rx_zero_pause_4",
168 "bpc_rx_zero_pause_5",
169 "bpc_rx_zero_pause_6",
170 "bpc_rx_zero_pause_7",
171 "bpc_rx_first_pause_0",
172 "bpc_rx_first_pause_1",
173 "bpc_rx_first_pause_2",
174 "bpc_rx_first_pause_3",
175 "bpc_rx_first_pause_4",
176 "bpc_rx_first_pause_5",
177 "bpc_rx_first_pause_6",
178 "bpc_rx_first_pause_7",
182 "rad_rx_vlan_frames",
184 "rad_rx_ucast_octets",
187 "rad_rx_mcast_octets",
190 "rad_rx_bcast_octets",
196 "rlb_rad_rx_vlan_frames",
198 "rlb_rad_rx_ucast_octets",
199 "rlb_rad_rx_ucast_vlan",
201 "rlb_rad_rx_mcast_octets",
202 "rlb_rad_rx_mcast_vlan",
204 "rlb_rad_rx_bcast_octets",
205 "rlb_rad_rx_bcast_vlan",
208 "fc_rx_ucast_octets",
211 "fc_rx_mcast_octets",
214 "fc_rx_bcast_octets",
218 "fc_tx_ucast_octets",
221 "fc_tx_mcast_octets",
224 "fc_tx_bcast_octets",
227 "fc_tx_parity_errors",
229 "fc_tx_fid_parity_errors",
232 #define BNAD_ETHTOOL_STATS_NUM ARRAY_SIZE(bnad_net_stats_strings)
235 bnad_get_link_ksettings(struct net_device
*netdev
,
236 struct ethtool_link_ksettings
*cmd
)
238 u32 supported
, advertising
;
240 supported
= SUPPORTED_10000baseT_Full
;
241 advertising
= ADVERTISED_10000baseT_Full
;
242 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
243 supported
|= SUPPORTED_FIBRE
;
244 advertising
|= ADVERTISED_FIBRE
;
245 cmd
->base
.port
= PORT_FIBRE
;
246 cmd
->base
.phy_address
= 0;
248 if (netif_carrier_ok(netdev
)) {
249 cmd
->base
.speed
= SPEED_10000
;
250 cmd
->base
.duplex
= DUPLEX_FULL
;
252 cmd
->base
.speed
= SPEED_UNKNOWN
;
253 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
256 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
258 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
265 bnad_set_link_ksettings(struct net_device
*netdev
,
266 const struct ethtool_link_ksettings
*cmd
)
268 /* 10G full duplex setting supported only */
269 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
)
272 if ((cmd
->base
.speed
== SPEED_10000
) &&
273 (cmd
->base
.duplex
== DUPLEX_FULL
))
280 bnad_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
282 struct bnad
*bnad
= netdev_priv(netdev
);
283 struct bfa_ioc_attr
*ioc_attr
;
286 strlcpy(drvinfo
->driver
, BNAD_NAME
, sizeof(drvinfo
->driver
));
287 strlcpy(drvinfo
->version
, BNAD_VERSION
, sizeof(drvinfo
->version
));
289 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
291 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
292 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
293 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
295 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
296 sizeof(drvinfo
->fw_version
));
300 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
301 sizeof(drvinfo
->bus_info
));
305 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
307 wolinfo
->supported
= 0;
308 wolinfo
->wolopts
= 0;
312 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
314 struct bnad
*bnad
= netdev_priv(netdev
);
317 /* Lock rqd. to access bnad->bna_lock */
318 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
319 coalesce
->use_adaptive_rx_coalesce
=
320 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
321 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
323 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
324 BFI_COALESCING_TIMER_UNIT
;
325 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
326 BFI_COALESCING_TIMER_UNIT
;
327 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
333 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
335 struct bnad
*bnad
= netdev_priv(netdev
);
339 if (coalesce
->rx_coalesce_usecs
== 0 ||
340 coalesce
->rx_coalesce_usecs
>
341 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
344 if (coalesce
->tx_coalesce_usecs
== 0 ||
345 coalesce
->tx_coalesce_usecs
>
346 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
349 mutex_lock(&bnad
->conf_mutex
);
351 * Do not need to store rx_coalesce_usecs here
352 * Every time DIM is disabled, we can get it from the
355 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
356 if (coalesce
->use_adaptive_rx_coalesce
) {
357 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
358 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
359 bnad_dim_timer_start(bnad
);
362 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
363 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
364 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
365 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
367 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
371 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
373 del_timer_sync(&bnad
->dim_timer
);
374 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
375 bnad_rx_coalescing_timeo_set(bnad
);
378 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
379 BFI_COALESCING_TIMER_UNIT
) {
380 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
381 BFI_COALESCING_TIMER_UNIT
;
382 bnad_tx_coalescing_timeo_set(bnad
);
385 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
386 BFI_COALESCING_TIMER_UNIT
) {
387 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
388 BFI_COALESCING_TIMER_UNIT
;
390 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
391 bnad_rx_coalescing_timeo_set(bnad
);
395 /* Add Tx Inter-pkt DMA count? */
397 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
399 mutex_unlock(&bnad
->conf_mutex
);
404 bnad_get_ringparam(struct net_device
*netdev
,
405 struct ethtool_ringparam
*ringparam
)
407 struct bnad
*bnad
= netdev_priv(netdev
);
409 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
410 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
412 ringparam
->rx_pending
= bnad
->rxq_depth
;
413 ringparam
->tx_pending
= bnad
->txq_depth
;
417 bnad_set_ringparam(struct net_device
*netdev
,
418 struct ethtool_ringparam
*ringparam
)
420 int i
, current_err
, err
= 0;
421 struct bnad
*bnad
= netdev_priv(netdev
);
424 mutex_lock(&bnad
->conf_mutex
);
425 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
426 ringparam
->tx_pending
== bnad
->txq_depth
) {
427 mutex_unlock(&bnad
->conf_mutex
);
431 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
432 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
433 !is_power_of_2(ringparam
->rx_pending
)) {
434 mutex_unlock(&bnad
->conf_mutex
);
437 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
438 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
439 !is_power_of_2(ringparam
->tx_pending
)) {
440 mutex_unlock(&bnad
->conf_mutex
);
444 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
445 bnad
->rxq_depth
= ringparam
->rx_pending
;
446 if (!netif_running(netdev
)) {
447 mutex_unlock(&bnad
->conf_mutex
);
451 for (i
= 0; i
< bnad
->num_rx
; i
++) {
452 if (!bnad
->rx_info
[i
].rx
)
454 bnad_destroy_rx(bnad
, i
);
455 current_err
= bnad_setup_rx(bnad
, i
);
456 if (current_err
&& !err
)
460 if (!err
&& bnad
->rx_info
[0].rx
) {
461 /* restore rx configuration */
462 bnad_restore_vlans(bnad
, 0);
463 bnad_enable_default_bcast(bnad
);
464 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
465 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
466 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
467 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
469 bnad_set_rx_mode(netdev
);
472 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
473 bnad
->txq_depth
= ringparam
->tx_pending
;
474 if (!netif_running(netdev
)) {
475 mutex_unlock(&bnad
->conf_mutex
);
479 for (i
= 0; i
< bnad
->num_tx
; i
++) {
480 if (!bnad
->tx_info
[i
].tx
)
482 bnad_destroy_tx(bnad
, i
);
483 current_err
= bnad_setup_tx(bnad
, i
);
484 if (current_err
&& !err
)
489 mutex_unlock(&bnad
->conf_mutex
);
494 bnad_get_pauseparam(struct net_device
*netdev
,
495 struct ethtool_pauseparam
*pauseparam
)
497 struct bnad
*bnad
= netdev_priv(netdev
);
499 pauseparam
->autoneg
= 0;
500 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
501 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
505 bnad_set_pauseparam(struct net_device
*netdev
,
506 struct ethtool_pauseparam
*pauseparam
)
508 struct bnad
*bnad
= netdev_priv(netdev
);
509 struct bna_pause_config pause_config
;
512 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
515 mutex_lock(&bnad
->conf_mutex
);
516 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
517 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
518 pause_config
.rx_pause
= pauseparam
->rx_pause
;
519 pause_config
.tx_pause
= pauseparam
->tx_pause
;
520 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
521 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
522 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
524 mutex_unlock(&bnad
->conf_mutex
);
529 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
531 struct bnad
*bnad
= netdev_priv(netdev
);
535 mutex_lock(&bnad
->conf_mutex
);
539 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
540 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
542 strncpy(string
, bnad_net_stats_strings
[i
],
544 string
+= ETH_GSTRING_LEN
;
546 bmap
= bna_tx_rid_mask(&bnad
->bna
);
547 for (i
= 0; bmap
; i
++) {
549 sprintf(string
, "txf%d_ucast_octets", i
);
550 string
+= ETH_GSTRING_LEN
;
551 sprintf(string
, "txf%d_ucast", i
);
552 string
+= ETH_GSTRING_LEN
;
553 sprintf(string
, "txf%d_ucast_vlan", i
);
554 string
+= ETH_GSTRING_LEN
;
555 sprintf(string
, "txf%d_mcast_octets", i
);
556 string
+= ETH_GSTRING_LEN
;
557 sprintf(string
, "txf%d_mcast", i
);
558 string
+= ETH_GSTRING_LEN
;
559 sprintf(string
, "txf%d_mcast_vlan", i
);
560 string
+= ETH_GSTRING_LEN
;
561 sprintf(string
, "txf%d_bcast_octets", i
);
562 string
+= ETH_GSTRING_LEN
;
563 sprintf(string
, "txf%d_bcast", i
);
564 string
+= ETH_GSTRING_LEN
;
565 sprintf(string
, "txf%d_bcast_vlan", i
);
566 string
+= ETH_GSTRING_LEN
;
567 sprintf(string
, "txf%d_errors", i
);
568 string
+= ETH_GSTRING_LEN
;
569 sprintf(string
, "txf%d_filter_vlan", i
);
570 string
+= ETH_GSTRING_LEN
;
571 sprintf(string
, "txf%d_filter_mac_sa", i
);
572 string
+= ETH_GSTRING_LEN
;
577 bmap
= bna_rx_rid_mask(&bnad
->bna
);
578 for (i
= 0; bmap
; i
++) {
580 sprintf(string
, "rxf%d_ucast_octets", i
);
581 string
+= ETH_GSTRING_LEN
;
582 sprintf(string
, "rxf%d_ucast", i
);
583 string
+= ETH_GSTRING_LEN
;
584 sprintf(string
, "rxf%d_ucast_vlan", i
);
585 string
+= ETH_GSTRING_LEN
;
586 sprintf(string
, "rxf%d_mcast_octets", i
);
587 string
+= ETH_GSTRING_LEN
;
588 sprintf(string
, "rxf%d_mcast", i
);
589 string
+= ETH_GSTRING_LEN
;
590 sprintf(string
, "rxf%d_mcast_vlan", i
);
591 string
+= ETH_GSTRING_LEN
;
592 sprintf(string
, "rxf%d_bcast_octets", i
);
593 string
+= ETH_GSTRING_LEN
;
594 sprintf(string
, "rxf%d_bcast", i
);
595 string
+= ETH_GSTRING_LEN
;
596 sprintf(string
, "rxf%d_bcast_vlan", i
);
597 string
+= ETH_GSTRING_LEN
;
598 sprintf(string
, "rxf%d_frame_drops", i
);
599 string
+= ETH_GSTRING_LEN
;
605 for (i
= 0; i
< bnad
->num_rx
; i
++) {
606 if (!bnad
->rx_info
[i
].rx
)
608 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
609 sprintf(string
, "cq%d_producer_index", q_num
);
610 string
+= ETH_GSTRING_LEN
;
611 sprintf(string
, "cq%d_consumer_index", q_num
);
612 string
+= ETH_GSTRING_LEN
;
613 sprintf(string
, "cq%d_hw_producer_index",
615 string
+= ETH_GSTRING_LEN
;
616 sprintf(string
, "cq%d_intr", q_num
);
617 string
+= ETH_GSTRING_LEN
;
618 sprintf(string
, "cq%d_poll", q_num
);
619 string
+= ETH_GSTRING_LEN
;
620 sprintf(string
, "cq%d_schedule", q_num
);
621 string
+= ETH_GSTRING_LEN
;
622 sprintf(string
, "cq%d_keep_poll", q_num
);
623 string
+= ETH_GSTRING_LEN
;
624 sprintf(string
, "cq%d_complete", q_num
);
625 string
+= ETH_GSTRING_LEN
;
631 for (i
= 0; i
< bnad
->num_rx
; i
++) {
632 if (!bnad
->rx_info
[i
].rx
)
634 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
635 sprintf(string
, "rxq%d_packets", q_num
);
636 string
+= ETH_GSTRING_LEN
;
637 sprintf(string
, "rxq%d_bytes", q_num
);
638 string
+= ETH_GSTRING_LEN
;
639 sprintf(string
, "rxq%d_packets_with_error",
641 string
+= ETH_GSTRING_LEN
;
642 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
643 string
+= ETH_GSTRING_LEN
;
644 sprintf(string
, "rxq%d_mapbuf_failed", q_num
);
645 string
+= ETH_GSTRING_LEN
;
646 sprintf(string
, "rxq%d_producer_index", q_num
);
647 string
+= ETH_GSTRING_LEN
;
648 sprintf(string
, "rxq%d_consumer_index", q_num
);
649 string
+= ETH_GSTRING_LEN
;
651 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
652 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
654 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
656 sprintf(string
, "rxq%d_packets", q_num
);
657 string
+= ETH_GSTRING_LEN
;
658 sprintf(string
, "rxq%d_bytes", q_num
);
659 string
+= ETH_GSTRING_LEN
;
661 "rxq%d_packets_with_error", q_num
);
662 string
+= ETH_GSTRING_LEN
;
663 sprintf(string
, "rxq%d_allocbuf_failed",
665 string
+= ETH_GSTRING_LEN
;
666 sprintf(string
, "rxq%d_mapbuf_failed",
668 string
+= ETH_GSTRING_LEN
;
669 sprintf(string
, "rxq%d_producer_index",
671 string
+= ETH_GSTRING_LEN
;
672 sprintf(string
, "rxq%d_consumer_index",
674 string
+= ETH_GSTRING_LEN
;
681 for (i
= 0; i
< bnad
->num_tx
; i
++) {
682 if (!bnad
->tx_info
[i
].tx
)
684 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
685 sprintf(string
, "txq%d_packets", q_num
);
686 string
+= ETH_GSTRING_LEN
;
687 sprintf(string
, "txq%d_bytes", q_num
);
688 string
+= ETH_GSTRING_LEN
;
689 sprintf(string
, "txq%d_producer_index", q_num
);
690 string
+= ETH_GSTRING_LEN
;
691 sprintf(string
, "txq%d_consumer_index", q_num
);
692 string
+= ETH_GSTRING_LEN
;
693 sprintf(string
, "txq%d_hw_consumer_index",
695 string
+= ETH_GSTRING_LEN
;
706 mutex_unlock(&bnad
->conf_mutex
);
710 bnad_get_stats_count_locked(struct net_device
*netdev
)
712 struct bnad
*bnad
= netdev_priv(netdev
);
713 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
716 bmap
= bna_tx_rid_mask(&bnad
->bna
);
717 for (i
= 0; bmap
; i
++) {
722 bmap
= bna_rx_rid_mask(&bnad
->bna
);
723 for (i
= 0; bmap
; i
++) {
728 count
= BNAD_ETHTOOL_STATS_NUM
+
729 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
730 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
732 for (i
= 0; i
< bnad
->num_rx
; i
++) {
733 if (!bnad
->rx_info
[i
].rx
)
735 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
736 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
737 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
738 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
739 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
740 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
741 count
+= BNAD_NUM_RXQ_COUNTERS
;
744 for (i
= 0; i
< bnad
->num_tx
; i
++) {
745 if (!bnad
->tx_info
[i
].tx
)
747 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
753 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
756 struct bna_rcb
*rcb
= NULL
;
757 struct bna_tcb
*tcb
= NULL
;
759 for (i
= 0; i
< bnad
->num_rx
; i
++) {
760 if (!bnad
->rx_info
[i
].rx
)
762 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
763 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
764 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
765 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
766 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
768 buf
[bi
++] = 0; /* ccb->consumer_index */
769 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
770 ccb
->hw_producer_index
);
772 buf
[bi
++] = bnad
->rx_info
[i
].
773 rx_ctrl
[j
].rx_intr_ctr
;
774 buf
[bi
++] = bnad
->rx_info
[i
].
775 rx_ctrl
[j
].rx_poll_ctr
;
776 buf
[bi
++] = bnad
->rx_info
[i
].
777 rx_ctrl
[j
].rx_schedule
;
778 buf
[bi
++] = bnad
->rx_info
[i
].
779 rx_ctrl
[j
].rx_keep_poll
;
780 buf
[bi
++] = bnad
->rx_info
[i
].
781 rx_ctrl
[j
].rx_complete
;
784 for (i
= 0; i
< bnad
->num_rx
; i
++) {
785 if (!bnad
->rx_info
[i
].rx
)
787 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
788 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
789 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
790 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
792 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
794 buf
[bi
++] = rcb
->rxq
->rx_packets
;
795 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
796 buf
[bi
++] = rcb
->rxq
->
797 rx_packets_with_error
;
798 buf
[bi
++] = rcb
->rxq
->
800 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
801 buf
[bi
++] = rcb
->producer_index
;
802 buf
[bi
++] = rcb
->consumer_index
;
804 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
805 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
807 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
809 buf
[bi
++] = rcb
->rxq
->rx_packets
;
810 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
811 buf
[bi
++] = rcb
->rxq
->
812 rx_packets_with_error
;
813 buf
[bi
++] = rcb
->rxq
->
815 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
816 buf
[bi
++] = rcb
->producer_index
;
817 buf
[bi
++] = rcb
->consumer_index
;
822 for (i
= 0; i
< bnad
->num_tx
; i
++) {
823 if (!bnad
->tx_info
[i
].tx
)
825 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
826 if (bnad
->tx_info
[i
].tcb
[j
] &&
827 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
828 tcb
= bnad
->tx_info
[i
].tcb
[j
];
829 buf
[bi
++] = tcb
->txq
->tx_packets
;
830 buf
[bi
++] = tcb
->txq
->tx_bytes
;
831 buf
[bi
++] = tcb
->producer_index
;
832 buf
[bi
++] = tcb
->consumer_index
;
833 buf
[bi
++] = *(tcb
->hw_consumer_index
);
841 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
844 struct bnad
*bnad
= netdev_priv(netdev
);
847 struct rtnl_link_stats64 net_stats64
;
851 mutex_lock(&bnad
->conf_mutex
);
852 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
853 mutex_unlock(&bnad
->conf_mutex
);
858 * Used bna_lock to sync reads from bna_stats, which is written
859 * under the same lock
861 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
863 memset(&net_stats64
, 0, sizeof(net_stats64
));
864 bnad_netdev_qstats_fill(bnad
, &net_stats64
);
865 bnad_netdev_hwstats_fill(bnad
, &net_stats64
);
867 buf
[bi
++] = net_stats64
.rx_packets
;
868 buf
[bi
++] = net_stats64
.tx_packets
;
869 buf
[bi
++] = net_stats64
.rx_bytes
;
870 buf
[bi
++] = net_stats64
.tx_bytes
;
871 buf
[bi
++] = net_stats64
.rx_errors
;
872 buf
[bi
++] = net_stats64
.tx_errors
;
873 buf
[bi
++] = net_stats64
.rx_dropped
;
874 buf
[bi
++] = net_stats64
.tx_dropped
;
875 buf
[bi
++] = net_stats64
.multicast
;
876 buf
[bi
++] = net_stats64
.collisions
;
877 buf
[bi
++] = net_stats64
.rx_length_errors
;
878 buf
[bi
++] = net_stats64
.rx_crc_errors
;
879 buf
[bi
++] = net_stats64
.rx_frame_errors
;
880 buf
[bi
++] = net_stats64
.tx_fifo_errors
;
882 /* Get netif_queue_stopped from stack */
883 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
885 /* Fill driver stats into ethtool buffers */
886 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
887 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
888 buf
[bi
++] = stats64
[i
];
890 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
891 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
893 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
896 buf
[bi
++] = stats64
[i
];
898 /* Fill txf stats into ethtool buffers */
899 bmap
= bna_tx_rid_mask(&bnad
->bna
);
900 for (i
= 0; bmap
; i
++) {
902 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
903 hw_stats
.txf_stats
[i
];
904 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
906 buf
[bi
++] = stats64
[j
];
911 /* Fill rxf stats into ethtool buffers */
912 bmap
= bna_rx_rid_mask(&bnad
->bna
);
913 for (i
= 0; bmap
; i
++) {
915 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
916 hw_stats
.rxf_stats
[i
];
917 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
919 buf
[bi
++] = stats64
[j
];
924 /* Fill per Q stats into ethtool buffers */
925 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
927 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
929 mutex_unlock(&bnad
->conf_mutex
);
933 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
937 return bnad_get_stats_count_locked(netdev
);
944 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
947 struct bfa_flash_attr
*flash_attr
;
948 struct bnad_iocmd_comp fcomp
;
949 u32 i
, flash_part
= 0, ret
;
950 unsigned long flags
= 0;
952 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
957 fcomp
.comp_status
= 0;
959 init_completion(&fcomp
.comp
);
960 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
961 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
962 bnad_cb_completion
, &fcomp
);
963 if (ret
!= BFA_STATUS_OK
) {
964 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
968 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
969 wait_for_completion(&fcomp
.comp
);
970 ret
= fcomp
.comp_status
;
972 /* Check for the flash type & base offset value */
973 if (ret
== BFA_STATUS_OK
) {
974 for (i
= 0; i
< flash_attr
->npart
; i
++) {
975 if (offset
>= flash_attr
->part
[i
].part_off
&&
976 offset
< (flash_attr
->part
[i
].part_off
+
977 flash_attr
->part
[i
].part_size
)) {
978 flash_part
= flash_attr
->part
[i
].part_type
;
979 *base_offset
= flash_attr
->part
[i
].part_off
;
989 bnad_get_eeprom_len(struct net_device
*netdev
)
991 return BFA_TOTAL_FLASH_SIZE
;
995 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
998 struct bnad
*bnad
= netdev_priv(netdev
);
999 struct bnad_iocmd_comp fcomp
;
1000 u32 flash_part
= 0, base_offset
= 0;
1001 unsigned long flags
= 0;
1004 /* Fill the magic value */
1005 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
1007 /* Query the flash partition based on the offset */
1008 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1009 eeprom
->offset
, &base_offset
);
1010 if (flash_part
== 0)
1014 fcomp
.comp_status
= 0;
1016 init_completion(&fcomp
.comp
);
1017 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1018 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1019 bnad
->id
, bytes
, eeprom
->len
,
1020 eeprom
->offset
- base_offset
,
1021 bnad_cb_completion
, &fcomp
);
1022 if (ret
!= BFA_STATUS_OK
) {
1023 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1027 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1028 wait_for_completion(&fcomp
.comp
);
1029 ret
= fcomp
.comp_status
;
1035 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1038 struct bnad
*bnad
= netdev_priv(netdev
);
1039 struct bnad_iocmd_comp fcomp
;
1040 u32 flash_part
= 0, base_offset
= 0;
1041 unsigned long flags
= 0;
1044 /* Check if the flash update request is valid */
1045 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1046 (bnad
->pcidev
->device
<< 16)))
1049 /* Query the flash partition based on the offset */
1050 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1051 eeprom
->offset
, &base_offset
);
1052 if (flash_part
== 0)
1056 fcomp
.comp_status
= 0;
1058 init_completion(&fcomp
.comp
);
1059 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1060 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1061 bnad
->id
, bytes
, eeprom
->len
,
1062 eeprom
->offset
- base_offset
,
1063 bnad_cb_completion
, &fcomp
);
1064 if (ret
!= BFA_STATUS_OK
) {
1065 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1069 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1070 wait_for_completion(&fcomp
.comp
);
1071 ret
= fcomp
.comp_status
;
1077 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1079 struct bnad
*bnad
= netdev_priv(netdev
);
1080 struct bnad_iocmd_comp fcomp
;
1081 const struct firmware
*fw
;
1084 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1086 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1091 fcomp
.comp_status
= 0;
1093 init_completion(&fcomp
.comp
);
1094 spin_lock_irq(&bnad
->bna_lock
);
1095 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1096 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1097 bnad_cb_completion
, &fcomp
);
1098 if (ret
!= BFA_STATUS_OK
) {
1099 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1101 spin_unlock_irq(&bnad
->bna_lock
);
1105 spin_unlock_irq(&bnad
->bna_lock
);
1106 wait_for_completion(&fcomp
.comp
);
1107 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1110 "firmware image update failed with err=%d\n",
1114 release_firmware(fw
);
1118 static const struct ethtool_ops bnad_ethtool_ops
= {
1119 .get_drvinfo
= bnad_get_drvinfo
,
1120 .get_wol
= bnad_get_wol
,
1121 .get_link
= ethtool_op_get_link
,
1122 .get_coalesce
= bnad_get_coalesce
,
1123 .set_coalesce
= bnad_set_coalesce
,
1124 .get_ringparam
= bnad_get_ringparam
,
1125 .set_ringparam
= bnad_set_ringparam
,
1126 .get_pauseparam
= bnad_get_pauseparam
,
1127 .set_pauseparam
= bnad_set_pauseparam
,
1128 .get_strings
= bnad_get_strings
,
1129 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1130 .get_sset_count
= bnad_get_sset_count
,
1131 .get_eeprom_len
= bnad_get_eeprom_len
,
1132 .get_eeprom
= bnad_get_eeprom
,
1133 .set_eeprom
= bnad_set_eeprom
,
1134 .flash_device
= bnad_flash_device
,
1135 .get_ts_info
= ethtool_op_get_ts_info
,
1136 .get_link_ksettings
= bnad_get_link_ksettings
,
1137 .set_link_ksettings
= bnad_set_link_ksettings
,
1141 bnad_set_ethtool_ops(struct net_device
*netdev
)
1143 netdev
->ethtool_ops
= &bnad_ethtool_ops
;