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_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
245 cmd
->supported
= SUPPORTED_10000baseT_Full
;
246 cmd
->advertising
= ADVERTISED_10000baseT_Full
;
247 cmd
->autoneg
= AUTONEG_DISABLE
;
248 cmd
->supported
|= SUPPORTED_FIBRE
;
249 cmd
->advertising
|= ADVERTISED_FIBRE
;
250 cmd
->port
= PORT_FIBRE
;
251 cmd
->phy_address
= 0;
253 if (netif_carrier_ok(netdev
)) {
254 ethtool_cmd_speed_set(cmd
, SPEED_10000
);
255 cmd
->duplex
= DUPLEX_FULL
;
257 ethtool_cmd_speed_set(cmd
, SPEED_UNKNOWN
);
258 cmd
->duplex
= DUPLEX_UNKNOWN
;
260 cmd
->transceiver
= XCVR_EXTERNAL
;
268 bnad_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
270 /* 10G full duplex setting supported only */
271 if (cmd
->autoneg
== AUTONEG_ENABLE
)
272 return -EOPNOTSUPP
; else {
273 if ((ethtool_cmd_speed(cmd
) == SPEED_10000
)
274 && (cmd
->duplex
== DUPLEX_FULL
))
282 bnad_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
284 struct bnad
*bnad
= netdev_priv(netdev
);
285 struct bfa_ioc_attr
*ioc_attr
;
288 strlcpy(drvinfo
->driver
, BNAD_NAME
, sizeof(drvinfo
->driver
));
289 strlcpy(drvinfo
->version
, BNAD_VERSION
, sizeof(drvinfo
->version
));
291 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
293 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
294 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
295 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
297 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
298 sizeof(drvinfo
->fw_version
));
302 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
303 sizeof(drvinfo
->bus_info
));
307 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
309 wolinfo
->supported
= 0;
310 wolinfo
->wolopts
= 0;
314 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
316 struct bnad
*bnad
= netdev_priv(netdev
);
319 /* Lock rqd. to access bnad->bna_lock */
320 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
321 coalesce
->use_adaptive_rx_coalesce
=
322 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
323 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
325 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
326 BFI_COALESCING_TIMER_UNIT
;
327 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
328 BFI_COALESCING_TIMER_UNIT
;
329 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
335 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
337 struct bnad
*bnad
= netdev_priv(netdev
);
341 if (coalesce
->rx_coalesce_usecs
== 0 ||
342 coalesce
->rx_coalesce_usecs
>
343 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
346 if (coalesce
->tx_coalesce_usecs
== 0 ||
347 coalesce
->tx_coalesce_usecs
>
348 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
351 mutex_lock(&bnad
->conf_mutex
);
353 * Do not need to store rx_coalesce_usecs here
354 * Every time DIM is disabled, we can get it from the
357 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
358 if (coalesce
->use_adaptive_rx_coalesce
) {
359 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
360 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
361 bnad_dim_timer_start(bnad
);
364 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
365 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
366 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
367 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
369 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
373 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
375 del_timer_sync(&bnad
->dim_timer
);
376 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
377 bnad_rx_coalescing_timeo_set(bnad
);
380 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
381 BFI_COALESCING_TIMER_UNIT
) {
382 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
383 BFI_COALESCING_TIMER_UNIT
;
384 bnad_tx_coalescing_timeo_set(bnad
);
387 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
388 BFI_COALESCING_TIMER_UNIT
) {
389 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
390 BFI_COALESCING_TIMER_UNIT
;
392 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
393 bnad_rx_coalescing_timeo_set(bnad
);
397 /* Add Tx Inter-pkt DMA count? */
399 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
401 mutex_unlock(&bnad
->conf_mutex
);
406 bnad_get_ringparam(struct net_device
*netdev
,
407 struct ethtool_ringparam
*ringparam
)
409 struct bnad
*bnad
= netdev_priv(netdev
);
411 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
412 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
414 ringparam
->rx_pending
= bnad
->rxq_depth
;
415 ringparam
->tx_pending
= bnad
->txq_depth
;
419 bnad_set_ringparam(struct net_device
*netdev
,
420 struct ethtool_ringparam
*ringparam
)
422 int i
, current_err
, err
= 0;
423 struct bnad
*bnad
= netdev_priv(netdev
);
426 mutex_lock(&bnad
->conf_mutex
);
427 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
428 ringparam
->tx_pending
== bnad
->txq_depth
) {
429 mutex_unlock(&bnad
->conf_mutex
);
433 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
434 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
435 !is_power_of_2(ringparam
->rx_pending
)) {
436 mutex_unlock(&bnad
->conf_mutex
);
439 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
440 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
441 !is_power_of_2(ringparam
->tx_pending
)) {
442 mutex_unlock(&bnad
->conf_mutex
);
446 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
447 bnad
->rxq_depth
= ringparam
->rx_pending
;
448 if (!netif_running(netdev
)) {
449 mutex_unlock(&bnad
->conf_mutex
);
453 for (i
= 0; i
< bnad
->num_rx
; i
++) {
454 if (!bnad
->rx_info
[i
].rx
)
456 bnad_destroy_rx(bnad
, i
);
457 current_err
= bnad_setup_rx(bnad
, i
);
458 if (current_err
&& !err
)
462 if (!err
&& bnad
->rx_info
[0].rx
) {
463 /* restore rx configuration */
464 bnad_restore_vlans(bnad
, 0);
465 bnad_enable_default_bcast(bnad
);
466 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
467 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
468 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
469 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
471 bnad_set_rx_mode(netdev
);
474 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
475 bnad
->txq_depth
= ringparam
->tx_pending
;
476 if (!netif_running(netdev
)) {
477 mutex_unlock(&bnad
->conf_mutex
);
481 for (i
= 0; i
< bnad
->num_tx
; i
++) {
482 if (!bnad
->tx_info
[i
].tx
)
484 bnad_destroy_tx(bnad
, i
);
485 current_err
= bnad_setup_tx(bnad
, i
);
486 if (current_err
&& !err
)
491 mutex_unlock(&bnad
->conf_mutex
);
496 bnad_get_pauseparam(struct net_device
*netdev
,
497 struct ethtool_pauseparam
*pauseparam
)
499 struct bnad
*bnad
= netdev_priv(netdev
);
501 pauseparam
->autoneg
= 0;
502 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
503 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
507 bnad_set_pauseparam(struct net_device
*netdev
,
508 struct ethtool_pauseparam
*pauseparam
)
510 struct bnad
*bnad
= netdev_priv(netdev
);
511 struct bna_pause_config pause_config
;
514 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
517 mutex_lock(&bnad
->conf_mutex
);
518 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
519 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
520 pause_config
.rx_pause
= pauseparam
->rx_pause
;
521 pause_config
.tx_pause
= pauseparam
->tx_pause
;
522 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
523 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
524 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
526 mutex_unlock(&bnad
->conf_mutex
);
531 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
533 struct bnad
*bnad
= netdev_priv(netdev
);
537 mutex_lock(&bnad
->conf_mutex
);
541 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
542 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
544 memcpy(string
, bnad_net_stats_strings
[i
],
546 string
+= ETH_GSTRING_LEN
;
548 bmap
= bna_tx_rid_mask(&bnad
->bna
);
549 for (i
= 0; bmap
; i
++) {
551 sprintf(string
, "txf%d_ucast_octets", i
);
552 string
+= ETH_GSTRING_LEN
;
553 sprintf(string
, "txf%d_ucast", i
);
554 string
+= ETH_GSTRING_LEN
;
555 sprintf(string
, "txf%d_ucast_vlan", i
);
556 string
+= ETH_GSTRING_LEN
;
557 sprintf(string
, "txf%d_mcast_octets", i
);
558 string
+= ETH_GSTRING_LEN
;
559 sprintf(string
, "txf%d_mcast", i
);
560 string
+= ETH_GSTRING_LEN
;
561 sprintf(string
, "txf%d_mcast_vlan", i
);
562 string
+= ETH_GSTRING_LEN
;
563 sprintf(string
, "txf%d_bcast_octets", i
);
564 string
+= ETH_GSTRING_LEN
;
565 sprintf(string
, "txf%d_bcast", i
);
566 string
+= ETH_GSTRING_LEN
;
567 sprintf(string
, "txf%d_bcast_vlan", i
);
568 string
+= ETH_GSTRING_LEN
;
569 sprintf(string
, "txf%d_errors", i
);
570 string
+= ETH_GSTRING_LEN
;
571 sprintf(string
, "txf%d_filter_vlan", i
);
572 string
+= ETH_GSTRING_LEN
;
573 sprintf(string
, "txf%d_filter_mac_sa", i
);
574 string
+= ETH_GSTRING_LEN
;
579 bmap
= bna_rx_rid_mask(&bnad
->bna
);
580 for (i
= 0; bmap
; i
++) {
582 sprintf(string
, "rxf%d_ucast_octets", i
);
583 string
+= ETH_GSTRING_LEN
;
584 sprintf(string
, "rxf%d_ucast", i
);
585 string
+= ETH_GSTRING_LEN
;
586 sprintf(string
, "rxf%d_ucast_vlan", i
);
587 string
+= ETH_GSTRING_LEN
;
588 sprintf(string
, "rxf%d_mcast_octets", i
);
589 string
+= ETH_GSTRING_LEN
;
590 sprintf(string
, "rxf%d_mcast", i
);
591 string
+= ETH_GSTRING_LEN
;
592 sprintf(string
, "rxf%d_mcast_vlan", i
);
593 string
+= ETH_GSTRING_LEN
;
594 sprintf(string
, "rxf%d_bcast_octets", i
);
595 string
+= ETH_GSTRING_LEN
;
596 sprintf(string
, "rxf%d_bcast", i
);
597 string
+= ETH_GSTRING_LEN
;
598 sprintf(string
, "rxf%d_bcast_vlan", i
);
599 string
+= ETH_GSTRING_LEN
;
600 sprintf(string
, "rxf%d_frame_drops", i
);
601 string
+= ETH_GSTRING_LEN
;
607 for (i
= 0; i
< bnad
->num_rx
; i
++) {
608 if (!bnad
->rx_info
[i
].rx
)
610 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
611 sprintf(string
, "cq%d_producer_index", q_num
);
612 string
+= ETH_GSTRING_LEN
;
613 sprintf(string
, "cq%d_consumer_index", q_num
);
614 string
+= ETH_GSTRING_LEN
;
615 sprintf(string
, "cq%d_hw_producer_index",
617 string
+= ETH_GSTRING_LEN
;
618 sprintf(string
, "cq%d_intr", q_num
);
619 string
+= ETH_GSTRING_LEN
;
620 sprintf(string
, "cq%d_poll", q_num
);
621 string
+= ETH_GSTRING_LEN
;
622 sprintf(string
, "cq%d_schedule", q_num
);
623 string
+= ETH_GSTRING_LEN
;
624 sprintf(string
, "cq%d_keep_poll", q_num
);
625 string
+= ETH_GSTRING_LEN
;
626 sprintf(string
, "cq%d_complete", q_num
);
627 string
+= ETH_GSTRING_LEN
;
633 for (i
= 0; i
< bnad
->num_rx
; i
++) {
634 if (!bnad
->rx_info
[i
].rx
)
636 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
637 sprintf(string
, "rxq%d_packets", q_num
);
638 string
+= ETH_GSTRING_LEN
;
639 sprintf(string
, "rxq%d_bytes", q_num
);
640 string
+= ETH_GSTRING_LEN
;
641 sprintf(string
, "rxq%d_packets_with_error",
643 string
+= ETH_GSTRING_LEN
;
644 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
645 string
+= ETH_GSTRING_LEN
;
646 sprintf(string
, "rxq%d_mapbuf_failed", q_num
);
647 string
+= ETH_GSTRING_LEN
;
648 sprintf(string
, "rxq%d_producer_index", q_num
);
649 string
+= ETH_GSTRING_LEN
;
650 sprintf(string
, "rxq%d_consumer_index", q_num
);
651 string
+= ETH_GSTRING_LEN
;
653 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
654 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
656 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
658 sprintf(string
, "rxq%d_packets", q_num
);
659 string
+= ETH_GSTRING_LEN
;
660 sprintf(string
, "rxq%d_bytes", q_num
);
661 string
+= ETH_GSTRING_LEN
;
663 "rxq%d_packets_with_error", q_num
);
664 string
+= ETH_GSTRING_LEN
;
665 sprintf(string
, "rxq%d_allocbuf_failed",
667 string
+= ETH_GSTRING_LEN
;
668 sprintf(string
, "rxq%d_mapbuf_failed",
670 string
+= ETH_GSTRING_LEN
;
671 sprintf(string
, "rxq%d_producer_index",
673 string
+= ETH_GSTRING_LEN
;
674 sprintf(string
, "rxq%d_consumer_index",
676 string
+= ETH_GSTRING_LEN
;
683 for (i
= 0; i
< bnad
->num_tx
; i
++) {
684 if (!bnad
->tx_info
[i
].tx
)
686 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
687 sprintf(string
, "txq%d_packets", q_num
);
688 string
+= ETH_GSTRING_LEN
;
689 sprintf(string
, "txq%d_bytes", q_num
);
690 string
+= ETH_GSTRING_LEN
;
691 sprintf(string
, "txq%d_producer_index", q_num
);
692 string
+= ETH_GSTRING_LEN
;
693 sprintf(string
, "txq%d_consumer_index", q_num
);
694 string
+= ETH_GSTRING_LEN
;
695 sprintf(string
, "txq%d_hw_consumer_index",
697 string
+= ETH_GSTRING_LEN
;
708 mutex_unlock(&bnad
->conf_mutex
);
712 bnad_get_stats_count_locked(struct net_device
*netdev
)
714 struct bnad
*bnad
= netdev_priv(netdev
);
715 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
718 bmap
= bna_tx_rid_mask(&bnad
->bna
);
719 for (i
= 0; bmap
; i
++) {
724 bmap
= bna_rx_rid_mask(&bnad
->bna
);
725 for (i
= 0; bmap
; i
++) {
730 count
= BNAD_ETHTOOL_STATS_NUM
+
731 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
732 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
734 for (i
= 0; i
< bnad
->num_rx
; i
++) {
735 if (!bnad
->rx_info
[i
].rx
)
737 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
738 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
739 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
740 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
741 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
742 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
743 count
+= BNAD_NUM_RXQ_COUNTERS
;
746 for (i
= 0; i
< bnad
->num_tx
; i
++) {
747 if (!bnad
->tx_info
[i
].tx
)
749 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
755 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
758 struct bna_rcb
*rcb
= NULL
;
759 struct bna_tcb
*tcb
= NULL
;
761 for (i
= 0; i
< bnad
->num_rx
; i
++) {
762 if (!bnad
->rx_info
[i
].rx
)
764 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
765 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
766 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
767 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
768 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
770 buf
[bi
++] = 0; /* ccb->consumer_index */
771 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
772 ccb
->hw_producer_index
);
774 buf
[bi
++] = bnad
->rx_info
[i
].
775 rx_ctrl
[j
].rx_intr_ctr
;
776 buf
[bi
++] = bnad
->rx_info
[i
].
777 rx_ctrl
[j
].rx_poll_ctr
;
778 buf
[bi
++] = bnad
->rx_info
[i
].
779 rx_ctrl
[j
].rx_schedule
;
780 buf
[bi
++] = bnad
->rx_info
[i
].
781 rx_ctrl
[j
].rx_keep_poll
;
782 buf
[bi
++] = bnad
->rx_info
[i
].
783 rx_ctrl
[j
].rx_complete
;
786 for (i
= 0; i
< bnad
->num_rx
; i
++) {
787 if (!bnad
->rx_info
[i
].rx
)
789 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
790 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
791 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
792 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
794 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
796 buf
[bi
++] = rcb
->rxq
->rx_packets
;
797 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
798 buf
[bi
++] = rcb
->rxq
->
799 rx_packets_with_error
;
800 buf
[bi
++] = rcb
->rxq
->
802 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
803 buf
[bi
++] = rcb
->producer_index
;
804 buf
[bi
++] = rcb
->consumer_index
;
806 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
807 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
809 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
811 buf
[bi
++] = rcb
->rxq
->rx_packets
;
812 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
813 buf
[bi
++] = rcb
->rxq
->
814 rx_packets_with_error
;
815 buf
[bi
++] = rcb
->rxq
->
817 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
818 buf
[bi
++] = rcb
->producer_index
;
819 buf
[bi
++] = rcb
->consumer_index
;
824 for (i
= 0; i
< bnad
->num_tx
; i
++) {
825 if (!bnad
->tx_info
[i
].tx
)
827 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
828 if (bnad
->tx_info
[i
].tcb
[j
] &&
829 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
830 tcb
= bnad
->tx_info
[i
].tcb
[j
];
831 buf
[bi
++] = tcb
->txq
->tx_packets
;
832 buf
[bi
++] = tcb
->txq
->tx_bytes
;
833 buf
[bi
++] = tcb
->producer_index
;
834 buf
[bi
++] = tcb
->consumer_index
;
835 buf
[bi
++] = *(tcb
->hw_consumer_index
);
843 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
846 struct bnad
*bnad
= netdev_priv(netdev
);
849 struct rtnl_link_stats64 net_stats64
;
853 mutex_lock(&bnad
->conf_mutex
);
854 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
855 mutex_unlock(&bnad
->conf_mutex
);
860 * Used bna_lock to sync reads from bna_stats, which is written
861 * under the same lock
863 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
865 memset(&net_stats64
, 0, sizeof(net_stats64
));
866 bnad_netdev_qstats_fill(bnad
, &net_stats64
);
867 bnad_netdev_hwstats_fill(bnad
, &net_stats64
);
869 buf
[bi
++] = net_stats64
.rx_packets
;
870 buf
[bi
++] = net_stats64
.tx_packets
;
871 buf
[bi
++] = net_stats64
.rx_bytes
;
872 buf
[bi
++] = net_stats64
.tx_bytes
;
873 buf
[bi
++] = net_stats64
.rx_errors
;
874 buf
[bi
++] = net_stats64
.tx_errors
;
875 buf
[bi
++] = net_stats64
.rx_dropped
;
876 buf
[bi
++] = net_stats64
.tx_dropped
;
877 buf
[bi
++] = net_stats64
.multicast
;
878 buf
[bi
++] = net_stats64
.collisions
;
879 buf
[bi
++] = net_stats64
.rx_length_errors
;
880 buf
[bi
++] = net_stats64
.rx_crc_errors
;
881 buf
[bi
++] = net_stats64
.rx_frame_errors
;
882 buf
[bi
++] = net_stats64
.tx_fifo_errors
;
884 /* Get netif_queue_stopped from stack */
885 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
887 /* Fill driver stats into ethtool buffers */
888 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
889 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
890 buf
[bi
++] = stats64
[i
];
892 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
893 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
895 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
898 buf
[bi
++] = stats64
[i
];
900 /* Fill txf stats into ethtool buffers */
901 bmap
= bna_tx_rid_mask(&bnad
->bna
);
902 for (i
= 0; bmap
; i
++) {
904 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
905 hw_stats
.txf_stats
[i
];
906 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
908 buf
[bi
++] = stats64
[j
];
913 /* Fill rxf stats into ethtool buffers */
914 bmap
= bna_rx_rid_mask(&bnad
->bna
);
915 for (i
= 0; bmap
; i
++) {
917 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
918 hw_stats
.rxf_stats
[i
];
919 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
921 buf
[bi
++] = stats64
[j
];
926 /* Fill per Q stats into ethtool buffers */
927 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
929 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
931 mutex_unlock(&bnad
->conf_mutex
);
935 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
939 return bnad_get_stats_count_locked(netdev
);
946 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
949 struct bfa_flash_attr
*flash_attr
;
950 struct bnad_iocmd_comp fcomp
;
951 u32 i
, flash_part
= 0, ret
;
952 unsigned long flags
= 0;
954 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
959 fcomp
.comp_status
= 0;
961 init_completion(&fcomp
.comp
);
962 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
963 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
964 bnad_cb_completion
, &fcomp
);
965 if (ret
!= BFA_STATUS_OK
) {
966 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
970 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
971 wait_for_completion(&fcomp
.comp
);
972 ret
= fcomp
.comp_status
;
974 /* Check for the flash type & base offset value */
975 if (ret
== BFA_STATUS_OK
) {
976 for (i
= 0; i
< flash_attr
->npart
; i
++) {
977 if (offset
>= flash_attr
->part
[i
].part_off
&&
978 offset
< (flash_attr
->part
[i
].part_off
+
979 flash_attr
->part
[i
].part_size
)) {
980 flash_part
= flash_attr
->part
[i
].part_type
;
981 *base_offset
= flash_attr
->part
[i
].part_off
;
991 bnad_get_eeprom_len(struct net_device
*netdev
)
993 return BFA_TOTAL_FLASH_SIZE
;
997 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1000 struct bnad
*bnad
= netdev_priv(netdev
);
1001 struct bnad_iocmd_comp fcomp
;
1002 u32 flash_part
= 0, base_offset
= 0;
1003 unsigned long flags
= 0;
1006 /* Fill the magic value */
1007 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
1009 /* Query the flash partition based on the offset */
1010 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1011 eeprom
->offset
, &base_offset
);
1012 if (flash_part
== 0)
1016 fcomp
.comp_status
= 0;
1018 init_completion(&fcomp
.comp
);
1019 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1020 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1021 bnad
->id
, bytes
, eeprom
->len
,
1022 eeprom
->offset
- base_offset
,
1023 bnad_cb_completion
, &fcomp
);
1024 if (ret
!= BFA_STATUS_OK
) {
1025 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1029 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1030 wait_for_completion(&fcomp
.comp
);
1031 ret
= fcomp
.comp_status
;
1037 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1040 struct bnad
*bnad
= netdev_priv(netdev
);
1041 struct bnad_iocmd_comp fcomp
;
1042 u32 flash_part
= 0, base_offset
= 0;
1043 unsigned long flags
= 0;
1046 /* Check if the flash update request is valid */
1047 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1048 (bnad
->pcidev
->device
<< 16)))
1051 /* Query the flash partition based on the offset */
1052 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1053 eeprom
->offset
, &base_offset
);
1054 if (flash_part
== 0)
1058 fcomp
.comp_status
= 0;
1060 init_completion(&fcomp
.comp
);
1061 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1062 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1063 bnad
->id
, bytes
, eeprom
->len
,
1064 eeprom
->offset
- base_offset
,
1065 bnad_cb_completion
, &fcomp
);
1066 if (ret
!= BFA_STATUS_OK
) {
1067 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1071 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1072 wait_for_completion(&fcomp
.comp
);
1073 ret
= fcomp
.comp_status
;
1079 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1081 struct bnad
*bnad
= netdev_priv(netdev
);
1082 struct bnad_iocmd_comp fcomp
;
1083 const struct firmware
*fw
;
1086 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1088 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1093 fcomp
.comp_status
= 0;
1095 init_completion(&fcomp
.comp
);
1096 spin_lock_irq(&bnad
->bna_lock
);
1097 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1098 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1099 bnad_cb_completion
, &fcomp
);
1100 if (ret
!= BFA_STATUS_OK
) {
1101 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1103 spin_unlock_irq(&bnad
->bna_lock
);
1107 spin_unlock_irq(&bnad
->bna_lock
);
1108 wait_for_completion(&fcomp
.comp
);
1109 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1112 "firmware image update failed with err=%d\n",
1116 release_firmware(fw
);
1120 static const struct ethtool_ops bnad_ethtool_ops
= {
1121 .get_settings
= bnad_get_settings
,
1122 .set_settings
= bnad_set_settings
,
1123 .get_drvinfo
= bnad_get_drvinfo
,
1124 .get_wol
= bnad_get_wol
,
1125 .get_link
= ethtool_op_get_link
,
1126 .get_coalesce
= bnad_get_coalesce
,
1127 .set_coalesce
= bnad_set_coalesce
,
1128 .get_ringparam
= bnad_get_ringparam
,
1129 .set_ringparam
= bnad_set_ringparam
,
1130 .get_pauseparam
= bnad_get_pauseparam
,
1131 .set_pauseparam
= bnad_set_pauseparam
,
1132 .get_strings
= bnad_get_strings
,
1133 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1134 .get_sset_count
= bnad_get_sset_count
,
1135 .get_eeprom_len
= bnad_get_eeprom_len
,
1136 .get_eeprom
= bnad_get_eeprom
,
1137 .set_eeprom
= bnad_set_eeprom
,
1138 .flash_device
= bnad_flash_device
,
1139 .get_ts_info
= ethtool_op_get_ts_info
,
1143 bnad_set_ethtool_ops(struct net_device
*netdev
)
1145 netdev
->ethtool_ops
= &bnad_ethtool_ops
;