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
));
288 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
290 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
291 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
292 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
294 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
295 sizeof(drvinfo
->fw_version
));
299 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
300 sizeof(drvinfo
->bus_info
));
304 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
306 wolinfo
->supported
= 0;
307 wolinfo
->wolopts
= 0;
311 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
313 struct bnad
*bnad
= netdev_priv(netdev
);
316 /* Lock rqd. to access bnad->bna_lock */
317 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
318 coalesce
->use_adaptive_rx_coalesce
=
319 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
320 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
322 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
323 BFI_COALESCING_TIMER_UNIT
;
324 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
325 BFI_COALESCING_TIMER_UNIT
;
326 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
332 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
334 struct bnad
*bnad
= netdev_priv(netdev
);
338 if (coalesce
->rx_coalesce_usecs
== 0 ||
339 coalesce
->rx_coalesce_usecs
>
340 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
343 if (coalesce
->tx_coalesce_usecs
== 0 ||
344 coalesce
->tx_coalesce_usecs
>
345 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
348 mutex_lock(&bnad
->conf_mutex
);
350 * Do not need to store rx_coalesce_usecs here
351 * Every time DIM is disabled, we can get it from the
354 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
355 if (coalesce
->use_adaptive_rx_coalesce
) {
356 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
357 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
358 bnad_dim_timer_start(bnad
);
361 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
362 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
363 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
364 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
366 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
370 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
372 del_timer_sync(&bnad
->dim_timer
);
373 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
374 bnad_rx_coalescing_timeo_set(bnad
);
377 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
378 BFI_COALESCING_TIMER_UNIT
) {
379 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
380 BFI_COALESCING_TIMER_UNIT
;
381 bnad_tx_coalescing_timeo_set(bnad
);
384 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
385 BFI_COALESCING_TIMER_UNIT
) {
386 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
387 BFI_COALESCING_TIMER_UNIT
;
389 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
390 bnad_rx_coalescing_timeo_set(bnad
);
394 /* Add Tx Inter-pkt DMA count? */
396 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
398 mutex_unlock(&bnad
->conf_mutex
);
403 bnad_get_ringparam(struct net_device
*netdev
,
404 struct ethtool_ringparam
*ringparam
)
406 struct bnad
*bnad
= netdev_priv(netdev
);
408 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
409 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
411 ringparam
->rx_pending
= bnad
->rxq_depth
;
412 ringparam
->tx_pending
= bnad
->txq_depth
;
416 bnad_set_ringparam(struct net_device
*netdev
,
417 struct ethtool_ringparam
*ringparam
)
419 int i
, current_err
, err
= 0;
420 struct bnad
*bnad
= netdev_priv(netdev
);
423 mutex_lock(&bnad
->conf_mutex
);
424 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
425 ringparam
->tx_pending
== bnad
->txq_depth
) {
426 mutex_unlock(&bnad
->conf_mutex
);
430 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
431 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
432 !is_power_of_2(ringparam
->rx_pending
)) {
433 mutex_unlock(&bnad
->conf_mutex
);
436 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
437 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
438 !is_power_of_2(ringparam
->tx_pending
)) {
439 mutex_unlock(&bnad
->conf_mutex
);
443 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
444 bnad
->rxq_depth
= ringparam
->rx_pending
;
445 if (!netif_running(netdev
)) {
446 mutex_unlock(&bnad
->conf_mutex
);
450 for (i
= 0; i
< bnad
->num_rx
; i
++) {
451 if (!bnad
->rx_info
[i
].rx
)
453 bnad_destroy_rx(bnad
, i
);
454 current_err
= bnad_setup_rx(bnad
, i
);
455 if (current_err
&& !err
)
459 if (!err
&& bnad
->rx_info
[0].rx
) {
460 /* restore rx configuration */
461 bnad_restore_vlans(bnad
, 0);
462 bnad_enable_default_bcast(bnad
);
463 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
464 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
465 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
466 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
468 bnad_set_rx_mode(netdev
);
471 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
472 bnad
->txq_depth
= ringparam
->tx_pending
;
473 if (!netif_running(netdev
)) {
474 mutex_unlock(&bnad
->conf_mutex
);
478 for (i
= 0; i
< bnad
->num_tx
; i
++) {
479 if (!bnad
->tx_info
[i
].tx
)
481 bnad_destroy_tx(bnad
, i
);
482 current_err
= bnad_setup_tx(bnad
, i
);
483 if (current_err
&& !err
)
488 mutex_unlock(&bnad
->conf_mutex
);
493 bnad_get_pauseparam(struct net_device
*netdev
,
494 struct ethtool_pauseparam
*pauseparam
)
496 struct bnad
*bnad
= netdev_priv(netdev
);
498 pauseparam
->autoneg
= 0;
499 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
500 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
504 bnad_set_pauseparam(struct net_device
*netdev
,
505 struct ethtool_pauseparam
*pauseparam
)
507 struct bnad
*bnad
= netdev_priv(netdev
);
508 struct bna_pause_config pause_config
;
511 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
514 mutex_lock(&bnad
->conf_mutex
);
515 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
516 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
517 pause_config
.rx_pause
= pauseparam
->rx_pause
;
518 pause_config
.tx_pause
= pauseparam
->tx_pause
;
519 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
520 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
521 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
523 mutex_unlock(&bnad
->conf_mutex
);
528 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
530 struct bnad
*bnad
= netdev_priv(netdev
);
534 mutex_lock(&bnad
->conf_mutex
);
538 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
539 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
541 strncpy(string
, bnad_net_stats_strings
[i
],
543 string
+= ETH_GSTRING_LEN
;
545 bmap
= bna_tx_rid_mask(&bnad
->bna
);
546 for (i
= 0; bmap
; i
++) {
548 sprintf(string
, "txf%d_ucast_octets", i
);
549 string
+= ETH_GSTRING_LEN
;
550 sprintf(string
, "txf%d_ucast", i
);
551 string
+= ETH_GSTRING_LEN
;
552 sprintf(string
, "txf%d_ucast_vlan", i
);
553 string
+= ETH_GSTRING_LEN
;
554 sprintf(string
, "txf%d_mcast_octets", i
);
555 string
+= ETH_GSTRING_LEN
;
556 sprintf(string
, "txf%d_mcast", i
);
557 string
+= ETH_GSTRING_LEN
;
558 sprintf(string
, "txf%d_mcast_vlan", i
);
559 string
+= ETH_GSTRING_LEN
;
560 sprintf(string
, "txf%d_bcast_octets", i
);
561 string
+= ETH_GSTRING_LEN
;
562 sprintf(string
, "txf%d_bcast", i
);
563 string
+= ETH_GSTRING_LEN
;
564 sprintf(string
, "txf%d_bcast_vlan", i
);
565 string
+= ETH_GSTRING_LEN
;
566 sprintf(string
, "txf%d_errors", i
);
567 string
+= ETH_GSTRING_LEN
;
568 sprintf(string
, "txf%d_filter_vlan", i
);
569 string
+= ETH_GSTRING_LEN
;
570 sprintf(string
, "txf%d_filter_mac_sa", i
);
571 string
+= ETH_GSTRING_LEN
;
576 bmap
= bna_rx_rid_mask(&bnad
->bna
);
577 for (i
= 0; bmap
; i
++) {
579 sprintf(string
, "rxf%d_ucast_octets", i
);
580 string
+= ETH_GSTRING_LEN
;
581 sprintf(string
, "rxf%d_ucast", i
);
582 string
+= ETH_GSTRING_LEN
;
583 sprintf(string
, "rxf%d_ucast_vlan", i
);
584 string
+= ETH_GSTRING_LEN
;
585 sprintf(string
, "rxf%d_mcast_octets", i
);
586 string
+= ETH_GSTRING_LEN
;
587 sprintf(string
, "rxf%d_mcast", i
);
588 string
+= ETH_GSTRING_LEN
;
589 sprintf(string
, "rxf%d_mcast_vlan", i
);
590 string
+= ETH_GSTRING_LEN
;
591 sprintf(string
, "rxf%d_bcast_octets", i
);
592 string
+= ETH_GSTRING_LEN
;
593 sprintf(string
, "rxf%d_bcast", i
);
594 string
+= ETH_GSTRING_LEN
;
595 sprintf(string
, "rxf%d_bcast_vlan", i
);
596 string
+= ETH_GSTRING_LEN
;
597 sprintf(string
, "rxf%d_frame_drops", i
);
598 string
+= ETH_GSTRING_LEN
;
604 for (i
= 0; i
< bnad
->num_rx
; i
++) {
605 if (!bnad
->rx_info
[i
].rx
)
607 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
608 sprintf(string
, "cq%d_producer_index", q_num
);
609 string
+= ETH_GSTRING_LEN
;
610 sprintf(string
, "cq%d_consumer_index", q_num
);
611 string
+= ETH_GSTRING_LEN
;
612 sprintf(string
, "cq%d_hw_producer_index",
614 string
+= ETH_GSTRING_LEN
;
615 sprintf(string
, "cq%d_intr", q_num
);
616 string
+= ETH_GSTRING_LEN
;
617 sprintf(string
, "cq%d_poll", q_num
);
618 string
+= ETH_GSTRING_LEN
;
619 sprintf(string
, "cq%d_schedule", q_num
);
620 string
+= ETH_GSTRING_LEN
;
621 sprintf(string
, "cq%d_keep_poll", q_num
);
622 string
+= ETH_GSTRING_LEN
;
623 sprintf(string
, "cq%d_complete", q_num
);
624 string
+= ETH_GSTRING_LEN
;
630 for (i
= 0; i
< bnad
->num_rx
; i
++) {
631 if (!bnad
->rx_info
[i
].rx
)
633 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
634 sprintf(string
, "rxq%d_packets", q_num
);
635 string
+= ETH_GSTRING_LEN
;
636 sprintf(string
, "rxq%d_bytes", q_num
);
637 string
+= ETH_GSTRING_LEN
;
638 sprintf(string
, "rxq%d_packets_with_error",
640 string
+= ETH_GSTRING_LEN
;
641 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
642 string
+= ETH_GSTRING_LEN
;
643 sprintf(string
, "rxq%d_mapbuf_failed", q_num
);
644 string
+= ETH_GSTRING_LEN
;
645 sprintf(string
, "rxq%d_producer_index", q_num
);
646 string
+= ETH_GSTRING_LEN
;
647 sprintf(string
, "rxq%d_consumer_index", q_num
);
648 string
+= ETH_GSTRING_LEN
;
650 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
651 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
653 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
655 sprintf(string
, "rxq%d_packets", q_num
);
656 string
+= ETH_GSTRING_LEN
;
657 sprintf(string
, "rxq%d_bytes", q_num
);
658 string
+= ETH_GSTRING_LEN
;
660 "rxq%d_packets_with_error", q_num
);
661 string
+= ETH_GSTRING_LEN
;
662 sprintf(string
, "rxq%d_allocbuf_failed",
664 string
+= ETH_GSTRING_LEN
;
665 sprintf(string
, "rxq%d_mapbuf_failed",
667 string
+= ETH_GSTRING_LEN
;
668 sprintf(string
, "rxq%d_producer_index",
670 string
+= ETH_GSTRING_LEN
;
671 sprintf(string
, "rxq%d_consumer_index",
673 string
+= ETH_GSTRING_LEN
;
680 for (i
= 0; i
< bnad
->num_tx
; i
++) {
681 if (!bnad
->tx_info
[i
].tx
)
683 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
684 sprintf(string
, "txq%d_packets", q_num
);
685 string
+= ETH_GSTRING_LEN
;
686 sprintf(string
, "txq%d_bytes", q_num
);
687 string
+= ETH_GSTRING_LEN
;
688 sprintf(string
, "txq%d_producer_index", q_num
);
689 string
+= ETH_GSTRING_LEN
;
690 sprintf(string
, "txq%d_consumer_index", q_num
);
691 string
+= ETH_GSTRING_LEN
;
692 sprintf(string
, "txq%d_hw_consumer_index",
694 string
+= ETH_GSTRING_LEN
;
705 mutex_unlock(&bnad
->conf_mutex
);
709 bnad_get_stats_count_locked(struct net_device
*netdev
)
711 struct bnad
*bnad
= netdev_priv(netdev
);
712 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
715 bmap
= bna_tx_rid_mask(&bnad
->bna
);
716 for (i
= 0; bmap
; i
++) {
721 bmap
= bna_rx_rid_mask(&bnad
->bna
);
722 for (i
= 0; bmap
; i
++) {
727 count
= BNAD_ETHTOOL_STATS_NUM
+
728 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
729 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
731 for (i
= 0; i
< bnad
->num_rx
; i
++) {
732 if (!bnad
->rx_info
[i
].rx
)
734 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
735 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
736 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
737 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
738 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
739 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
740 count
+= BNAD_NUM_RXQ_COUNTERS
;
743 for (i
= 0; i
< bnad
->num_tx
; i
++) {
744 if (!bnad
->tx_info
[i
].tx
)
746 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
752 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
755 struct bna_rcb
*rcb
= NULL
;
756 struct bna_tcb
*tcb
= NULL
;
758 for (i
= 0; i
< bnad
->num_rx
; i
++) {
759 if (!bnad
->rx_info
[i
].rx
)
761 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
762 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
763 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
764 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
765 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
767 buf
[bi
++] = 0; /* ccb->consumer_index */
768 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
769 ccb
->hw_producer_index
);
771 buf
[bi
++] = bnad
->rx_info
[i
].
772 rx_ctrl
[j
].rx_intr_ctr
;
773 buf
[bi
++] = bnad
->rx_info
[i
].
774 rx_ctrl
[j
].rx_poll_ctr
;
775 buf
[bi
++] = bnad
->rx_info
[i
].
776 rx_ctrl
[j
].rx_schedule
;
777 buf
[bi
++] = bnad
->rx_info
[i
].
778 rx_ctrl
[j
].rx_keep_poll
;
779 buf
[bi
++] = bnad
->rx_info
[i
].
780 rx_ctrl
[j
].rx_complete
;
783 for (i
= 0; i
< bnad
->num_rx
; i
++) {
784 if (!bnad
->rx_info
[i
].rx
)
786 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
787 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
788 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
789 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
791 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
793 buf
[bi
++] = rcb
->rxq
->rx_packets
;
794 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
795 buf
[bi
++] = rcb
->rxq
->
796 rx_packets_with_error
;
797 buf
[bi
++] = rcb
->rxq
->
799 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
800 buf
[bi
++] = rcb
->producer_index
;
801 buf
[bi
++] = rcb
->consumer_index
;
803 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
804 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
806 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
808 buf
[bi
++] = rcb
->rxq
->rx_packets
;
809 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
810 buf
[bi
++] = rcb
->rxq
->
811 rx_packets_with_error
;
812 buf
[bi
++] = rcb
->rxq
->
814 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
815 buf
[bi
++] = rcb
->producer_index
;
816 buf
[bi
++] = rcb
->consumer_index
;
821 for (i
= 0; i
< bnad
->num_tx
; i
++) {
822 if (!bnad
->tx_info
[i
].tx
)
824 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
825 if (bnad
->tx_info
[i
].tcb
[j
] &&
826 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
827 tcb
= bnad
->tx_info
[i
].tcb
[j
];
828 buf
[bi
++] = tcb
->txq
->tx_packets
;
829 buf
[bi
++] = tcb
->txq
->tx_bytes
;
830 buf
[bi
++] = tcb
->producer_index
;
831 buf
[bi
++] = tcb
->consumer_index
;
832 buf
[bi
++] = *(tcb
->hw_consumer_index
);
840 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
843 struct bnad
*bnad
= netdev_priv(netdev
);
846 struct rtnl_link_stats64 net_stats64
;
850 mutex_lock(&bnad
->conf_mutex
);
851 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
852 mutex_unlock(&bnad
->conf_mutex
);
857 * Used bna_lock to sync reads from bna_stats, which is written
858 * under the same lock
860 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
862 memset(&net_stats64
, 0, sizeof(net_stats64
));
863 bnad_netdev_qstats_fill(bnad
, &net_stats64
);
864 bnad_netdev_hwstats_fill(bnad
, &net_stats64
);
866 buf
[bi
++] = net_stats64
.rx_packets
;
867 buf
[bi
++] = net_stats64
.tx_packets
;
868 buf
[bi
++] = net_stats64
.rx_bytes
;
869 buf
[bi
++] = net_stats64
.tx_bytes
;
870 buf
[bi
++] = net_stats64
.rx_errors
;
871 buf
[bi
++] = net_stats64
.tx_errors
;
872 buf
[bi
++] = net_stats64
.rx_dropped
;
873 buf
[bi
++] = net_stats64
.tx_dropped
;
874 buf
[bi
++] = net_stats64
.multicast
;
875 buf
[bi
++] = net_stats64
.collisions
;
876 buf
[bi
++] = net_stats64
.rx_length_errors
;
877 buf
[bi
++] = net_stats64
.rx_crc_errors
;
878 buf
[bi
++] = net_stats64
.rx_frame_errors
;
879 buf
[bi
++] = net_stats64
.tx_fifo_errors
;
881 /* Get netif_queue_stopped from stack */
882 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
884 /* Fill driver stats into ethtool buffers */
885 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
886 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
887 buf
[bi
++] = stats64
[i
];
889 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
890 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
892 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
895 buf
[bi
++] = stats64
[i
];
897 /* Fill txf stats into ethtool buffers */
898 bmap
= bna_tx_rid_mask(&bnad
->bna
);
899 for (i
= 0; bmap
; i
++) {
901 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
902 hw_stats
.txf_stats
[i
];
903 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
905 buf
[bi
++] = stats64
[j
];
910 /* Fill rxf stats into ethtool buffers */
911 bmap
= bna_rx_rid_mask(&bnad
->bna
);
912 for (i
= 0; bmap
; i
++) {
914 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
915 hw_stats
.rxf_stats
[i
];
916 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
918 buf
[bi
++] = stats64
[j
];
923 /* Fill per Q stats into ethtool buffers */
924 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
926 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
928 mutex_unlock(&bnad
->conf_mutex
);
932 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
936 return bnad_get_stats_count_locked(netdev
);
943 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
946 struct bfa_flash_attr
*flash_attr
;
947 struct bnad_iocmd_comp fcomp
;
948 u32 i
, flash_part
= 0, ret
;
949 unsigned long flags
= 0;
951 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
956 fcomp
.comp_status
= 0;
958 init_completion(&fcomp
.comp
);
959 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
960 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
961 bnad_cb_completion
, &fcomp
);
962 if (ret
!= BFA_STATUS_OK
) {
963 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
967 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
968 wait_for_completion(&fcomp
.comp
);
969 ret
= fcomp
.comp_status
;
971 /* Check for the flash type & base offset value */
972 if (ret
== BFA_STATUS_OK
) {
973 for (i
= 0; i
< flash_attr
->npart
; i
++) {
974 if (offset
>= flash_attr
->part
[i
].part_off
&&
975 offset
< (flash_attr
->part
[i
].part_off
+
976 flash_attr
->part
[i
].part_size
)) {
977 flash_part
= flash_attr
->part
[i
].part_type
;
978 *base_offset
= flash_attr
->part
[i
].part_off
;
988 bnad_get_eeprom_len(struct net_device
*netdev
)
990 return BFA_TOTAL_FLASH_SIZE
;
994 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
997 struct bnad
*bnad
= netdev_priv(netdev
);
998 struct bnad_iocmd_comp fcomp
;
999 u32 flash_part
= 0, base_offset
= 0;
1000 unsigned long flags
= 0;
1003 /* Fill the magic value */
1004 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
1006 /* Query the flash partition based on the offset */
1007 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1008 eeprom
->offset
, &base_offset
);
1009 if (flash_part
== 0)
1013 fcomp
.comp_status
= 0;
1015 init_completion(&fcomp
.comp
);
1016 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1017 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1018 bnad
->id
, bytes
, eeprom
->len
,
1019 eeprom
->offset
- base_offset
,
1020 bnad_cb_completion
, &fcomp
);
1021 if (ret
!= BFA_STATUS_OK
) {
1022 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1026 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1027 wait_for_completion(&fcomp
.comp
);
1028 ret
= fcomp
.comp_status
;
1034 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1037 struct bnad
*bnad
= netdev_priv(netdev
);
1038 struct bnad_iocmd_comp fcomp
;
1039 u32 flash_part
= 0, base_offset
= 0;
1040 unsigned long flags
= 0;
1043 /* Check if the flash update request is valid */
1044 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1045 (bnad
->pcidev
->device
<< 16)))
1048 /* Query the flash partition based on the offset */
1049 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1050 eeprom
->offset
, &base_offset
);
1051 if (flash_part
== 0)
1055 fcomp
.comp_status
= 0;
1057 init_completion(&fcomp
.comp
);
1058 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1059 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1060 bnad
->id
, bytes
, eeprom
->len
,
1061 eeprom
->offset
- base_offset
,
1062 bnad_cb_completion
, &fcomp
);
1063 if (ret
!= BFA_STATUS_OK
) {
1064 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1068 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1069 wait_for_completion(&fcomp
.comp
);
1070 ret
= fcomp
.comp_status
;
1076 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1078 struct bnad
*bnad
= netdev_priv(netdev
);
1079 struct bnad_iocmd_comp fcomp
;
1080 const struct firmware
*fw
;
1083 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1085 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1090 fcomp
.comp_status
= 0;
1092 init_completion(&fcomp
.comp
);
1093 spin_lock_irq(&bnad
->bna_lock
);
1094 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1095 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1096 bnad_cb_completion
, &fcomp
);
1097 if (ret
!= BFA_STATUS_OK
) {
1098 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1100 spin_unlock_irq(&bnad
->bna_lock
);
1104 spin_unlock_irq(&bnad
->bna_lock
);
1105 wait_for_completion(&fcomp
.comp
);
1106 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1109 "firmware image update failed with err=%d\n",
1113 release_firmware(fw
);
1117 static const struct ethtool_ops bnad_ethtool_ops
= {
1118 .supported_coalesce_params
= ETHTOOL_COALESCE_USECS
|
1119 ETHTOOL_COALESCE_TX_MAX_FRAMES
|
1120 ETHTOOL_COALESCE_USE_ADAPTIVE_RX
,
1121 .get_drvinfo
= bnad_get_drvinfo
,
1122 .get_wol
= bnad_get_wol
,
1123 .get_link
= ethtool_op_get_link
,
1124 .get_coalesce
= bnad_get_coalesce
,
1125 .set_coalesce
= bnad_set_coalesce
,
1126 .get_ringparam
= bnad_get_ringparam
,
1127 .set_ringparam
= bnad_set_ringparam
,
1128 .get_pauseparam
= bnad_get_pauseparam
,
1129 .set_pauseparam
= bnad_set_pauseparam
,
1130 .get_strings
= bnad_get_strings
,
1131 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1132 .get_sset_count
= bnad_get_sset_count
,
1133 .get_eeprom_len
= bnad_get_eeprom_len
,
1134 .get_eeprom
= bnad_get_eeprom
,
1135 .set_eeprom
= bnad_set_eeprom
,
1136 .flash_device
= bnad_flash_device
,
1137 .get_ts_info
= ethtool_op_get_ts_info
,
1138 .get_link_ksettings
= bnad_get_link_ksettings
,
1139 .set_link_ksettings
= bnad_set_link_ksettings
,
1143 bnad_set_ethtool_ops(struct net_device
*netdev
)
1145 netdev
->ethtool_ops
= &bnad_ethtool_ops
;