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 7
35 #define BNAD_NUM_TXQ_COUNTERS 5
37 static const char *bnad_net_stats_strings
[] = {
55 "netif_queue_stopped",
65 "tx_skb_mss_too_long",
66 "tx_skb_tso_too_short",
68 "tx_skb_non_tso_too_long",
72 "tx_skb_headlen_too_long",
73 "tx_skb_headlen_zero",
75 "tx_skb_len_mismatch",
83 "rxp_info_alloc_failed",
86 "tx_unmap_q_alloc_failed",
87 "rx_unmap_q_alloc_failed",
97 "mac_frame_1024_1518",
98 "mac_frame_1518_1522",
104 "mac_rx_control_frames",
106 "mac_rx_unknown_opcode",
107 "mac_rx_alignment_error",
108 "mac_rx_frame_length_error",
110 "mac_rx_carrier_sense_error",
123 "mac_tx_excessive_deferral",
124 "mac_tx_single_collision",
125 "mac_tx_muliple_collision",
126 "mac_tx_late_collision",
127 "mac_tx_excessive_collision",
128 "mac_tx_total_collision",
129 "mac_tx_pause_honored",
133 "mac_tx_control_frame",
146 "bpc_tx_zero_pause_0",
147 "bpc_tx_zero_pause_1",
148 "bpc_tx_zero_pause_2",
149 "bpc_tx_zero_pause_3",
150 "bpc_tx_zero_pause_4",
151 "bpc_tx_zero_pause_5",
152 "bpc_tx_zero_pause_6",
153 "bpc_tx_zero_pause_7",
154 "bpc_tx_first_pause_0",
155 "bpc_tx_first_pause_1",
156 "bpc_tx_first_pause_2",
157 "bpc_tx_first_pause_3",
158 "bpc_tx_first_pause_4",
159 "bpc_tx_first_pause_5",
160 "bpc_tx_first_pause_6",
161 "bpc_tx_first_pause_7",
171 "bpc_rx_zero_pause_0",
172 "bpc_rx_zero_pause_1",
173 "bpc_rx_zero_pause_2",
174 "bpc_rx_zero_pause_3",
175 "bpc_rx_zero_pause_4",
176 "bpc_rx_zero_pause_5",
177 "bpc_rx_zero_pause_6",
178 "bpc_rx_zero_pause_7",
179 "bpc_rx_first_pause_0",
180 "bpc_rx_first_pause_1",
181 "bpc_rx_first_pause_2",
182 "bpc_rx_first_pause_3",
183 "bpc_rx_first_pause_4",
184 "bpc_rx_first_pause_5",
185 "bpc_rx_first_pause_6",
186 "bpc_rx_first_pause_7",
190 "rad_rx_vlan_frames",
192 "rad_rx_ucast_octets",
195 "rad_rx_mcast_octets",
198 "rad_rx_bcast_octets",
204 "rlb_rad_rx_vlan_frames",
206 "rlb_rad_rx_ucast_octets",
207 "rlb_rad_rx_ucast_vlan",
209 "rlb_rad_rx_mcast_octets",
210 "rlb_rad_rx_mcast_vlan",
212 "rlb_rad_rx_bcast_octets",
213 "rlb_rad_rx_bcast_vlan",
216 "fc_rx_ucast_octets",
219 "fc_rx_mcast_octets",
222 "fc_rx_bcast_octets",
226 "fc_tx_ucast_octets",
229 "fc_tx_mcast_octets",
232 "fc_tx_bcast_octets",
235 "fc_tx_parity_errors",
237 "fc_tx_fid_parity_errors",
240 #define BNAD_ETHTOOL_STATS_NUM ARRAY_SIZE(bnad_net_stats_strings)
243 bnad_get_link_ksettings(struct net_device
*netdev
,
244 struct ethtool_link_ksettings
*cmd
)
246 u32 supported
, advertising
;
248 supported
= SUPPORTED_10000baseT_Full
;
249 advertising
= ADVERTISED_10000baseT_Full
;
250 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
251 supported
|= SUPPORTED_FIBRE
;
252 advertising
|= ADVERTISED_FIBRE
;
253 cmd
->base
.port
= PORT_FIBRE
;
254 cmd
->base
.phy_address
= 0;
256 if (netif_carrier_ok(netdev
)) {
257 cmd
->base
.speed
= SPEED_10000
;
258 cmd
->base
.duplex
= DUPLEX_FULL
;
260 cmd
->base
.speed
= SPEED_UNKNOWN
;
261 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
264 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
266 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
273 bnad_set_link_ksettings(struct net_device
*netdev
,
274 const struct ethtool_link_ksettings
*cmd
)
276 /* 10G full duplex setting supported only */
277 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
)
280 if ((cmd
->base
.speed
== SPEED_10000
) &&
281 (cmd
->base
.duplex
== DUPLEX_FULL
))
288 bnad_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
290 struct bnad
*bnad
= netdev_priv(netdev
);
291 struct bfa_ioc_attr
*ioc_attr
;
294 strlcpy(drvinfo
->driver
, BNAD_NAME
, sizeof(drvinfo
->driver
));
295 strlcpy(drvinfo
->version
, BNAD_VERSION
, sizeof(drvinfo
->version
));
297 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
299 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
300 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
301 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
303 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
304 sizeof(drvinfo
->fw_version
));
308 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
309 sizeof(drvinfo
->bus_info
));
313 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
315 wolinfo
->supported
= 0;
316 wolinfo
->wolopts
= 0;
320 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
322 struct bnad
*bnad
= netdev_priv(netdev
);
325 /* Lock rqd. to access bnad->bna_lock */
326 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
327 coalesce
->use_adaptive_rx_coalesce
=
328 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
329 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
331 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
332 BFI_COALESCING_TIMER_UNIT
;
333 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
334 BFI_COALESCING_TIMER_UNIT
;
335 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
341 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
343 struct bnad
*bnad
= netdev_priv(netdev
);
347 if (coalesce
->rx_coalesce_usecs
== 0 ||
348 coalesce
->rx_coalesce_usecs
>
349 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
352 if (coalesce
->tx_coalesce_usecs
== 0 ||
353 coalesce
->tx_coalesce_usecs
>
354 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
357 mutex_lock(&bnad
->conf_mutex
);
359 * Do not need to store rx_coalesce_usecs here
360 * Every time DIM is disabled, we can get it from the
363 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
364 if (coalesce
->use_adaptive_rx_coalesce
) {
365 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
366 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
367 bnad_dim_timer_start(bnad
);
370 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
371 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
372 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
373 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
375 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
379 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
381 del_timer_sync(&bnad
->dim_timer
);
382 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
383 bnad_rx_coalescing_timeo_set(bnad
);
386 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
387 BFI_COALESCING_TIMER_UNIT
) {
388 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
389 BFI_COALESCING_TIMER_UNIT
;
390 bnad_tx_coalescing_timeo_set(bnad
);
393 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
394 BFI_COALESCING_TIMER_UNIT
) {
395 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
396 BFI_COALESCING_TIMER_UNIT
;
398 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
399 bnad_rx_coalescing_timeo_set(bnad
);
403 /* Add Tx Inter-pkt DMA count? */
405 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
407 mutex_unlock(&bnad
->conf_mutex
);
412 bnad_get_ringparam(struct net_device
*netdev
,
413 struct ethtool_ringparam
*ringparam
)
415 struct bnad
*bnad
= netdev_priv(netdev
);
417 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
418 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
420 ringparam
->rx_pending
= bnad
->rxq_depth
;
421 ringparam
->tx_pending
= bnad
->txq_depth
;
425 bnad_set_ringparam(struct net_device
*netdev
,
426 struct ethtool_ringparam
*ringparam
)
428 int i
, current_err
, err
= 0;
429 struct bnad
*bnad
= netdev_priv(netdev
);
432 mutex_lock(&bnad
->conf_mutex
);
433 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
434 ringparam
->tx_pending
== bnad
->txq_depth
) {
435 mutex_unlock(&bnad
->conf_mutex
);
439 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
440 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
441 !is_power_of_2(ringparam
->rx_pending
)) {
442 mutex_unlock(&bnad
->conf_mutex
);
445 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
446 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
447 !is_power_of_2(ringparam
->tx_pending
)) {
448 mutex_unlock(&bnad
->conf_mutex
);
452 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
453 bnad
->rxq_depth
= ringparam
->rx_pending
;
454 if (!netif_running(netdev
)) {
455 mutex_unlock(&bnad
->conf_mutex
);
459 for (i
= 0; i
< bnad
->num_rx
; i
++) {
460 if (!bnad
->rx_info
[i
].rx
)
462 bnad_destroy_rx(bnad
, i
);
463 current_err
= bnad_setup_rx(bnad
, i
);
464 if (current_err
&& !err
)
468 if (!err
&& bnad
->rx_info
[0].rx
) {
469 /* restore rx configuration */
470 bnad_restore_vlans(bnad
, 0);
471 bnad_enable_default_bcast(bnad
);
472 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
473 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
474 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
475 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
477 bnad_set_rx_mode(netdev
);
480 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
481 bnad
->txq_depth
= ringparam
->tx_pending
;
482 if (!netif_running(netdev
)) {
483 mutex_unlock(&bnad
->conf_mutex
);
487 for (i
= 0; i
< bnad
->num_tx
; i
++) {
488 if (!bnad
->tx_info
[i
].tx
)
490 bnad_destroy_tx(bnad
, i
);
491 current_err
= bnad_setup_tx(bnad
, i
);
492 if (current_err
&& !err
)
497 mutex_unlock(&bnad
->conf_mutex
);
502 bnad_get_pauseparam(struct net_device
*netdev
,
503 struct ethtool_pauseparam
*pauseparam
)
505 struct bnad
*bnad
= netdev_priv(netdev
);
507 pauseparam
->autoneg
= 0;
508 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
509 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
513 bnad_set_pauseparam(struct net_device
*netdev
,
514 struct ethtool_pauseparam
*pauseparam
)
516 struct bnad
*bnad
= netdev_priv(netdev
);
517 struct bna_pause_config pause_config
;
520 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
523 mutex_lock(&bnad
->conf_mutex
);
524 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
525 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
526 pause_config
.rx_pause
= pauseparam
->rx_pause
;
527 pause_config
.tx_pause
= pauseparam
->tx_pause
;
528 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
529 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
530 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
532 mutex_unlock(&bnad
->conf_mutex
);
537 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
539 struct bnad
*bnad
= netdev_priv(netdev
);
543 mutex_lock(&bnad
->conf_mutex
);
547 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
548 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
550 strncpy(string
, bnad_net_stats_strings
[i
],
552 string
+= ETH_GSTRING_LEN
;
554 bmap
= bna_tx_rid_mask(&bnad
->bna
);
555 for (i
= 0; bmap
; i
++) {
557 sprintf(string
, "txf%d_ucast_octets", i
);
558 string
+= ETH_GSTRING_LEN
;
559 sprintf(string
, "txf%d_ucast", i
);
560 string
+= ETH_GSTRING_LEN
;
561 sprintf(string
, "txf%d_ucast_vlan", i
);
562 string
+= ETH_GSTRING_LEN
;
563 sprintf(string
, "txf%d_mcast_octets", i
);
564 string
+= ETH_GSTRING_LEN
;
565 sprintf(string
, "txf%d_mcast", i
);
566 string
+= ETH_GSTRING_LEN
;
567 sprintf(string
, "txf%d_mcast_vlan", i
);
568 string
+= ETH_GSTRING_LEN
;
569 sprintf(string
, "txf%d_bcast_octets", i
);
570 string
+= ETH_GSTRING_LEN
;
571 sprintf(string
, "txf%d_bcast", i
);
572 string
+= ETH_GSTRING_LEN
;
573 sprintf(string
, "txf%d_bcast_vlan", i
);
574 string
+= ETH_GSTRING_LEN
;
575 sprintf(string
, "txf%d_errors", i
);
576 string
+= ETH_GSTRING_LEN
;
577 sprintf(string
, "txf%d_filter_vlan", i
);
578 string
+= ETH_GSTRING_LEN
;
579 sprintf(string
, "txf%d_filter_mac_sa", i
);
580 string
+= ETH_GSTRING_LEN
;
585 bmap
= bna_rx_rid_mask(&bnad
->bna
);
586 for (i
= 0; bmap
; i
++) {
588 sprintf(string
, "rxf%d_ucast_octets", i
);
589 string
+= ETH_GSTRING_LEN
;
590 sprintf(string
, "rxf%d_ucast", i
);
591 string
+= ETH_GSTRING_LEN
;
592 sprintf(string
, "rxf%d_ucast_vlan", i
);
593 string
+= ETH_GSTRING_LEN
;
594 sprintf(string
, "rxf%d_mcast_octets", i
);
595 string
+= ETH_GSTRING_LEN
;
596 sprintf(string
, "rxf%d_mcast", i
);
597 string
+= ETH_GSTRING_LEN
;
598 sprintf(string
, "rxf%d_mcast_vlan", i
);
599 string
+= ETH_GSTRING_LEN
;
600 sprintf(string
, "rxf%d_bcast_octets", i
);
601 string
+= ETH_GSTRING_LEN
;
602 sprintf(string
, "rxf%d_bcast", i
);
603 string
+= ETH_GSTRING_LEN
;
604 sprintf(string
, "rxf%d_bcast_vlan", i
);
605 string
+= ETH_GSTRING_LEN
;
606 sprintf(string
, "rxf%d_frame_drops", i
);
607 string
+= ETH_GSTRING_LEN
;
613 for (i
= 0; i
< bnad
->num_rx
; i
++) {
614 if (!bnad
->rx_info
[i
].rx
)
616 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
617 sprintf(string
, "cq%d_producer_index", q_num
);
618 string
+= ETH_GSTRING_LEN
;
619 sprintf(string
, "cq%d_consumer_index", q_num
);
620 string
+= ETH_GSTRING_LEN
;
621 sprintf(string
, "cq%d_hw_producer_index",
623 string
+= ETH_GSTRING_LEN
;
624 sprintf(string
, "cq%d_intr", q_num
);
625 string
+= ETH_GSTRING_LEN
;
626 sprintf(string
, "cq%d_poll", q_num
);
627 string
+= ETH_GSTRING_LEN
;
628 sprintf(string
, "cq%d_schedule", q_num
);
629 string
+= ETH_GSTRING_LEN
;
630 sprintf(string
, "cq%d_keep_poll", q_num
);
631 string
+= ETH_GSTRING_LEN
;
632 sprintf(string
, "cq%d_complete", q_num
);
633 string
+= ETH_GSTRING_LEN
;
639 for (i
= 0; i
< bnad
->num_rx
; i
++) {
640 if (!bnad
->rx_info
[i
].rx
)
642 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
643 sprintf(string
, "rxq%d_packets", q_num
);
644 string
+= ETH_GSTRING_LEN
;
645 sprintf(string
, "rxq%d_bytes", q_num
);
646 string
+= ETH_GSTRING_LEN
;
647 sprintf(string
, "rxq%d_packets_with_error",
649 string
+= ETH_GSTRING_LEN
;
650 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
651 string
+= ETH_GSTRING_LEN
;
652 sprintf(string
, "rxq%d_mapbuf_failed", q_num
);
653 string
+= ETH_GSTRING_LEN
;
654 sprintf(string
, "rxq%d_producer_index", q_num
);
655 string
+= ETH_GSTRING_LEN
;
656 sprintf(string
, "rxq%d_consumer_index", q_num
);
657 string
+= ETH_GSTRING_LEN
;
659 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
660 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
662 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
664 sprintf(string
, "rxq%d_packets", q_num
);
665 string
+= ETH_GSTRING_LEN
;
666 sprintf(string
, "rxq%d_bytes", q_num
);
667 string
+= ETH_GSTRING_LEN
;
669 "rxq%d_packets_with_error", q_num
);
670 string
+= ETH_GSTRING_LEN
;
671 sprintf(string
, "rxq%d_allocbuf_failed",
673 string
+= ETH_GSTRING_LEN
;
674 sprintf(string
, "rxq%d_mapbuf_failed",
676 string
+= ETH_GSTRING_LEN
;
677 sprintf(string
, "rxq%d_producer_index",
679 string
+= ETH_GSTRING_LEN
;
680 sprintf(string
, "rxq%d_consumer_index",
682 string
+= ETH_GSTRING_LEN
;
689 for (i
= 0; i
< bnad
->num_tx
; i
++) {
690 if (!bnad
->tx_info
[i
].tx
)
692 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
693 sprintf(string
, "txq%d_packets", q_num
);
694 string
+= ETH_GSTRING_LEN
;
695 sprintf(string
, "txq%d_bytes", q_num
);
696 string
+= ETH_GSTRING_LEN
;
697 sprintf(string
, "txq%d_producer_index", q_num
);
698 string
+= ETH_GSTRING_LEN
;
699 sprintf(string
, "txq%d_consumer_index", q_num
);
700 string
+= ETH_GSTRING_LEN
;
701 sprintf(string
, "txq%d_hw_consumer_index",
703 string
+= ETH_GSTRING_LEN
;
714 mutex_unlock(&bnad
->conf_mutex
);
718 bnad_get_stats_count_locked(struct net_device
*netdev
)
720 struct bnad
*bnad
= netdev_priv(netdev
);
721 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
724 bmap
= bna_tx_rid_mask(&bnad
->bna
);
725 for (i
= 0; bmap
; i
++) {
730 bmap
= bna_rx_rid_mask(&bnad
->bna
);
731 for (i
= 0; bmap
; i
++) {
736 count
= BNAD_ETHTOOL_STATS_NUM
+
737 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
738 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
740 for (i
= 0; i
< bnad
->num_rx
; i
++) {
741 if (!bnad
->rx_info
[i
].rx
)
743 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
744 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
745 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
746 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
747 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
748 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
749 count
+= BNAD_NUM_RXQ_COUNTERS
;
752 for (i
= 0; i
< bnad
->num_tx
; i
++) {
753 if (!bnad
->tx_info
[i
].tx
)
755 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
761 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
764 struct bna_rcb
*rcb
= NULL
;
765 struct bna_tcb
*tcb
= NULL
;
767 for (i
= 0; i
< bnad
->num_rx
; i
++) {
768 if (!bnad
->rx_info
[i
].rx
)
770 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
771 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
772 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
773 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
774 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
776 buf
[bi
++] = 0; /* ccb->consumer_index */
777 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
778 ccb
->hw_producer_index
);
780 buf
[bi
++] = bnad
->rx_info
[i
].
781 rx_ctrl
[j
].rx_intr_ctr
;
782 buf
[bi
++] = bnad
->rx_info
[i
].
783 rx_ctrl
[j
].rx_poll_ctr
;
784 buf
[bi
++] = bnad
->rx_info
[i
].
785 rx_ctrl
[j
].rx_schedule
;
786 buf
[bi
++] = bnad
->rx_info
[i
].
787 rx_ctrl
[j
].rx_keep_poll
;
788 buf
[bi
++] = bnad
->rx_info
[i
].
789 rx_ctrl
[j
].rx_complete
;
792 for (i
= 0; i
< bnad
->num_rx
; i
++) {
793 if (!bnad
->rx_info
[i
].rx
)
795 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
796 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
797 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
798 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
800 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
802 buf
[bi
++] = rcb
->rxq
->rx_packets
;
803 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
804 buf
[bi
++] = rcb
->rxq
->
805 rx_packets_with_error
;
806 buf
[bi
++] = rcb
->rxq
->
808 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
809 buf
[bi
++] = rcb
->producer_index
;
810 buf
[bi
++] = rcb
->consumer_index
;
812 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
813 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
815 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
817 buf
[bi
++] = rcb
->rxq
->rx_packets
;
818 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
819 buf
[bi
++] = rcb
->rxq
->
820 rx_packets_with_error
;
821 buf
[bi
++] = rcb
->rxq
->
823 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
824 buf
[bi
++] = rcb
->producer_index
;
825 buf
[bi
++] = rcb
->consumer_index
;
830 for (i
= 0; i
< bnad
->num_tx
; i
++) {
831 if (!bnad
->tx_info
[i
].tx
)
833 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
834 if (bnad
->tx_info
[i
].tcb
[j
] &&
835 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
836 tcb
= bnad
->tx_info
[i
].tcb
[j
];
837 buf
[bi
++] = tcb
->txq
->tx_packets
;
838 buf
[bi
++] = tcb
->txq
->tx_bytes
;
839 buf
[bi
++] = tcb
->producer_index
;
840 buf
[bi
++] = tcb
->consumer_index
;
841 buf
[bi
++] = *(tcb
->hw_consumer_index
);
849 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
852 struct bnad
*bnad
= netdev_priv(netdev
);
855 struct rtnl_link_stats64 net_stats64
;
859 mutex_lock(&bnad
->conf_mutex
);
860 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
861 mutex_unlock(&bnad
->conf_mutex
);
866 * Used bna_lock to sync reads from bna_stats, which is written
867 * under the same lock
869 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
871 memset(&net_stats64
, 0, sizeof(net_stats64
));
872 bnad_netdev_qstats_fill(bnad
, &net_stats64
);
873 bnad_netdev_hwstats_fill(bnad
, &net_stats64
);
875 buf
[bi
++] = net_stats64
.rx_packets
;
876 buf
[bi
++] = net_stats64
.tx_packets
;
877 buf
[bi
++] = net_stats64
.rx_bytes
;
878 buf
[bi
++] = net_stats64
.tx_bytes
;
879 buf
[bi
++] = net_stats64
.rx_errors
;
880 buf
[bi
++] = net_stats64
.tx_errors
;
881 buf
[bi
++] = net_stats64
.rx_dropped
;
882 buf
[bi
++] = net_stats64
.tx_dropped
;
883 buf
[bi
++] = net_stats64
.multicast
;
884 buf
[bi
++] = net_stats64
.collisions
;
885 buf
[bi
++] = net_stats64
.rx_length_errors
;
886 buf
[bi
++] = net_stats64
.rx_crc_errors
;
887 buf
[bi
++] = net_stats64
.rx_frame_errors
;
888 buf
[bi
++] = net_stats64
.tx_fifo_errors
;
890 /* Get netif_queue_stopped from stack */
891 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
893 /* Fill driver stats into ethtool buffers */
894 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
895 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
896 buf
[bi
++] = stats64
[i
];
898 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
899 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
901 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
904 buf
[bi
++] = stats64
[i
];
906 /* Fill txf stats into ethtool buffers */
907 bmap
= bna_tx_rid_mask(&bnad
->bna
);
908 for (i
= 0; bmap
; i
++) {
910 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
911 hw_stats
.txf_stats
[i
];
912 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
914 buf
[bi
++] = stats64
[j
];
919 /* Fill rxf stats into ethtool buffers */
920 bmap
= bna_rx_rid_mask(&bnad
->bna
);
921 for (i
= 0; bmap
; i
++) {
923 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
924 hw_stats
.rxf_stats
[i
];
925 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
927 buf
[bi
++] = stats64
[j
];
932 /* Fill per Q stats into ethtool buffers */
933 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
935 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
937 mutex_unlock(&bnad
->conf_mutex
);
941 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
945 return bnad_get_stats_count_locked(netdev
);
952 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
955 struct bfa_flash_attr
*flash_attr
;
956 struct bnad_iocmd_comp fcomp
;
957 u32 i
, flash_part
= 0, ret
;
958 unsigned long flags
= 0;
960 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
965 fcomp
.comp_status
= 0;
967 init_completion(&fcomp
.comp
);
968 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
969 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
970 bnad_cb_completion
, &fcomp
);
971 if (ret
!= BFA_STATUS_OK
) {
972 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
976 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
977 wait_for_completion(&fcomp
.comp
);
978 ret
= fcomp
.comp_status
;
980 /* Check for the flash type & base offset value */
981 if (ret
== BFA_STATUS_OK
) {
982 for (i
= 0; i
< flash_attr
->npart
; i
++) {
983 if (offset
>= flash_attr
->part
[i
].part_off
&&
984 offset
< (flash_attr
->part
[i
].part_off
+
985 flash_attr
->part
[i
].part_size
)) {
986 flash_part
= flash_attr
->part
[i
].part_type
;
987 *base_offset
= flash_attr
->part
[i
].part_off
;
997 bnad_get_eeprom_len(struct net_device
*netdev
)
999 return BFA_TOTAL_FLASH_SIZE
;
1003 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1006 struct bnad
*bnad
= netdev_priv(netdev
);
1007 struct bnad_iocmd_comp fcomp
;
1008 u32 flash_part
= 0, base_offset
= 0;
1009 unsigned long flags
= 0;
1012 /* Fill the magic value */
1013 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
1015 /* Query the flash partition based on the offset */
1016 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1017 eeprom
->offset
, &base_offset
);
1018 if (flash_part
== 0)
1022 fcomp
.comp_status
= 0;
1024 init_completion(&fcomp
.comp
);
1025 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1026 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1027 bnad
->id
, bytes
, eeprom
->len
,
1028 eeprom
->offset
- base_offset
,
1029 bnad_cb_completion
, &fcomp
);
1030 if (ret
!= BFA_STATUS_OK
) {
1031 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1035 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1036 wait_for_completion(&fcomp
.comp
);
1037 ret
= fcomp
.comp_status
;
1043 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1046 struct bnad
*bnad
= netdev_priv(netdev
);
1047 struct bnad_iocmd_comp fcomp
;
1048 u32 flash_part
= 0, base_offset
= 0;
1049 unsigned long flags
= 0;
1052 /* Check if the flash update request is valid */
1053 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1054 (bnad
->pcidev
->device
<< 16)))
1057 /* Query the flash partition based on the offset */
1058 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1059 eeprom
->offset
, &base_offset
);
1060 if (flash_part
== 0)
1064 fcomp
.comp_status
= 0;
1066 init_completion(&fcomp
.comp
);
1067 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1068 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1069 bnad
->id
, bytes
, eeprom
->len
,
1070 eeprom
->offset
- base_offset
,
1071 bnad_cb_completion
, &fcomp
);
1072 if (ret
!= BFA_STATUS_OK
) {
1073 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1077 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1078 wait_for_completion(&fcomp
.comp
);
1079 ret
= fcomp
.comp_status
;
1085 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1087 struct bnad
*bnad
= netdev_priv(netdev
);
1088 struct bnad_iocmd_comp fcomp
;
1089 const struct firmware
*fw
;
1092 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1094 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1099 fcomp
.comp_status
= 0;
1101 init_completion(&fcomp
.comp
);
1102 spin_lock_irq(&bnad
->bna_lock
);
1103 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1104 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1105 bnad_cb_completion
, &fcomp
);
1106 if (ret
!= BFA_STATUS_OK
) {
1107 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1109 spin_unlock_irq(&bnad
->bna_lock
);
1113 spin_unlock_irq(&bnad
->bna_lock
);
1114 wait_for_completion(&fcomp
.comp
);
1115 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1118 "firmware image update failed with err=%d\n",
1122 release_firmware(fw
);
1126 static const struct ethtool_ops bnad_ethtool_ops
= {
1127 .get_drvinfo
= bnad_get_drvinfo
,
1128 .get_wol
= bnad_get_wol
,
1129 .get_link
= ethtool_op_get_link
,
1130 .get_coalesce
= bnad_get_coalesce
,
1131 .set_coalesce
= bnad_set_coalesce
,
1132 .get_ringparam
= bnad_get_ringparam
,
1133 .set_ringparam
= bnad_set_ringparam
,
1134 .get_pauseparam
= bnad_get_pauseparam
,
1135 .set_pauseparam
= bnad_set_pauseparam
,
1136 .get_strings
= bnad_get_strings
,
1137 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1138 .get_sset_count
= bnad_get_sset_count
,
1139 .get_eeprom_len
= bnad_get_eeprom_len
,
1140 .get_eeprom
= bnad_get_eeprom
,
1141 .set_eeprom
= bnad_set_eeprom
,
1142 .flash_device
= bnad_flash_device
,
1143 .get_ts_info
= ethtool_op_get_ts_info
,
1144 .get_link_ksettings
= bnad_get_link_ksettings
,
1145 .set_link_ksettings
= bnad_set_link_ksettings
,
1149 bnad_set_ethtool_ops(struct net_device
*netdev
)
1151 netdev
->ethtool_ops
= &bnad_ethtool_ops
;