2 * Linux network driver for Brocade 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-2010 Brocade Communications Systems, Inc.
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/ethtool.h>
24 #include <linux/rtnetlink.h>
30 #define BNAD_NUM_TXF_COUNTERS 12
31 #define BNAD_NUM_RXF_COUNTERS 10
32 #define BNAD_NUM_CQ_COUNTERS (3 + 5)
33 #define BNAD_NUM_RXQ_COUNTERS 6
34 #define BNAD_NUM_TXQ_COUNTERS 5
36 #define BNAD_ETHTOOL_STATS_NUM \
37 (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
38 sizeof(struct bnad_drv_stats) / sizeof(u64) + \
39 offsetof(struct bfi_enet_stats, rxf_stats[0]) / sizeof(u64))
41 static const char *bnad_net_stats_strings
[BNAD_ETHTOOL_STATS_NUM
] = {
63 "tx_heartbeat_errors",
71 "netif_queue_stopped",
81 "tx_skb_mss_too_long",
82 "tx_skb_tso_too_short",
84 "tx_skb_non_tso_too_long",
88 "tx_skb_headlen_too_long",
89 "tx_skb_headlen_zero",
91 "tx_skb_len_mismatch",
98 "rxp_info_alloc_failed",
101 "tx_unmap_q_alloc_failed",
102 "rx_unmap_q_alloc_failed",
103 "rxbuf_alloc_failed",
109 "mac_frame_512_1023",
110 "mac_frame_1024_1518",
111 "mac_frame_1518_1522",
117 "mac_rx_control_frames",
119 "mac_rx_unknown_opcode",
120 "mac_rx_alignment_error",
121 "mac_rx_frame_length_error",
123 "mac_rx_carrier_sense_error",
136 "mac_tx_excessive_deferral",
137 "mac_tx_single_collision",
138 "mac_tx_muliple_collision",
139 "mac_tx_late_collision",
140 "mac_tx_excessive_collision",
141 "mac_tx_total_collision",
142 "mac_tx_pause_honored",
146 "mac_tx_control_frame",
159 "bpc_tx_zero_pause_0",
160 "bpc_tx_zero_pause_1",
161 "bpc_tx_zero_pause_2",
162 "bpc_tx_zero_pause_3",
163 "bpc_tx_zero_pause_4",
164 "bpc_tx_zero_pause_5",
165 "bpc_tx_zero_pause_6",
166 "bpc_tx_zero_pause_7",
167 "bpc_tx_first_pause_0",
168 "bpc_tx_first_pause_1",
169 "bpc_tx_first_pause_2",
170 "bpc_tx_first_pause_3",
171 "bpc_tx_first_pause_4",
172 "bpc_tx_first_pause_5",
173 "bpc_tx_first_pause_6",
174 "bpc_tx_first_pause_7",
184 "bpc_rx_zero_pause_0",
185 "bpc_rx_zero_pause_1",
186 "bpc_rx_zero_pause_2",
187 "bpc_rx_zero_pause_3",
188 "bpc_rx_zero_pause_4",
189 "bpc_rx_zero_pause_5",
190 "bpc_rx_zero_pause_6",
191 "bpc_rx_zero_pause_7",
192 "bpc_rx_first_pause_0",
193 "bpc_rx_first_pause_1",
194 "bpc_rx_first_pause_2",
195 "bpc_rx_first_pause_3",
196 "bpc_rx_first_pause_4",
197 "bpc_rx_first_pause_5",
198 "bpc_rx_first_pause_6",
199 "bpc_rx_first_pause_7",
203 "rad_rx_vlan_frames",
205 "rad_rx_ucast_octets",
208 "rad_rx_mcast_octets",
211 "rad_rx_bcast_octets",
217 "rlb_rad_rx_vlan_frames",
219 "rlb_rad_rx_ucast_octets",
220 "rlb_rad_rx_ucast_vlan",
222 "rlb_rad_rx_mcast_octets",
223 "rlb_rad_rx_mcast_vlan",
225 "rlb_rad_rx_bcast_octets",
226 "rlb_rad_rx_bcast_vlan",
229 "fc_rx_ucast_octets",
232 "fc_rx_mcast_octets",
235 "fc_rx_bcast_octets",
239 "fc_tx_ucast_octets",
242 "fc_tx_mcast_octets",
245 "fc_tx_bcast_octets",
248 "fc_tx_parity_errors",
250 "fc_tx_fid_parity_errors",
254 bnad_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
256 cmd
->supported
= SUPPORTED_10000baseT_Full
;
257 cmd
->advertising
= ADVERTISED_10000baseT_Full
;
258 cmd
->autoneg
= AUTONEG_DISABLE
;
259 cmd
->supported
|= SUPPORTED_FIBRE
;
260 cmd
->advertising
|= ADVERTISED_FIBRE
;
261 cmd
->port
= PORT_FIBRE
;
262 cmd
->phy_address
= 0;
264 if (netif_carrier_ok(netdev
)) {
265 ethtool_cmd_speed_set(cmd
, SPEED_10000
);
266 cmd
->duplex
= DUPLEX_FULL
;
268 ethtool_cmd_speed_set(cmd
, -1);
271 cmd
->transceiver
= XCVR_EXTERNAL
;
279 bnad_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*cmd
)
281 /* 10G full duplex setting supported only */
282 if (cmd
->autoneg
== AUTONEG_ENABLE
)
283 return -EOPNOTSUPP
; else {
284 if ((ethtool_cmd_speed(cmd
) == SPEED_10000
)
285 && (cmd
->duplex
== DUPLEX_FULL
))
293 bnad_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
295 struct bnad
*bnad
= netdev_priv(netdev
);
296 struct bfa_ioc_attr
*ioc_attr
;
299 strlcpy(drvinfo
->driver
, BNAD_NAME
, sizeof(drvinfo
->driver
));
300 strlcpy(drvinfo
->version
, BNAD_VERSION
, sizeof(drvinfo
->version
));
302 ioc_attr
= kzalloc(sizeof(*ioc_attr
), GFP_KERNEL
);
304 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
305 bfa_nw_ioc_get_attr(&bnad
->bna
.ioceth
.ioc
, ioc_attr
);
306 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
308 strlcpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
309 sizeof(drvinfo
->fw_version
));
313 strlcpy(drvinfo
->bus_info
, pci_name(bnad
->pcidev
),
314 sizeof(drvinfo
->bus_info
));
318 bnad_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wolinfo
)
320 wolinfo
->supported
= 0;
321 wolinfo
->wolopts
= 0;
325 bnad_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
327 struct bnad
*bnad
= netdev_priv(netdev
);
330 /* Lock rqd. to access bnad->bna_lock */
331 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
332 coalesce
->use_adaptive_rx_coalesce
=
333 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
334 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
336 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
337 BFI_COALESCING_TIMER_UNIT
;
338 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
339 BFI_COALESCING_TIMER_UNIT
;
340 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
346 bnad_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*coalesce
)
348 struct bnad
*bnad
= netdev_priv(netdev
);
352 if (coalesce
->rx_coalesce_usecs
== 0 ||
353 coalesce
->rx_coalesce_usecs
>
354 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
357 if (coalesce
->tx_coalesce_usecs
== 0 ||
358 coalesce
->tx_coalesce_usecs
>
359 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
362 mutex_lock(&bnad
->conf_mutex
);
364 * Do not need to store rx_coalesce_usecs here
365 * Every time DIM is disabled, we can get it from the
368 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
369 if (coalesce
->use_adaptive_rx_coalesce
) {
370 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
371 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
372 bnad_dim_timer_start(bnad
);
375 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
376 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
377 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
378 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
380 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
384 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
386 del_timer_sync(&bnad
->dim_timer
);
387 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
388 bnad_rx_coalescing_timeo_set(bnad
);
391 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
392 BFI_COALESCING_TIMER_UNIT
) {
393 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
394 BFI_COALESCING_TIMER_UNIT
;
395 bnad_tx_coalescing_timeo_set(bnad
);
398 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
399 BFI_COALESCING_TIMER_UNIT
) {
400 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
401 BFI_COALESCING_TIMER_UNIT
;
403 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
404 bnad_rx_coalescing_timeo_set(bnad
);
408 /* Add Tx Inter-pkt DMA count? */
410 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
412 mutex_unlock(&bnad
->conf_mutex
);
417 bnad_get_ringparam(struct net_device
*netdev
,
418 struct ethtool_ringparam
*ringparam
)
420 struct bnad
*bnad
= netdev_priv(netdev
);
422 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
423 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
425 ringparam
->rx_pending
= bnad
->rxq_depth
;
426 ringparam
->tx_pending
= bnad
->txq_depth
;
430 bnad_set_ringparam(struct net_device
*netdev
,
431 struct ethtool_ringparam
*ringparam
)
433 int i
, current_err
, err
= 0;
434 struct bnad
*bnad
= netdev_priv(netdev
);
437 mutex_lock(&bnad
->conf_mutex
);
438 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
439 ringparam
->tx_pending
== bnad
->txq_depth
) {
440 mutex_unlock(&bnad
->conf_mutex
);
444 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
445 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
446 !BNA_POWER_OF_2(ringparam
->rx_pending
)) {
447 mutex_unlock(&bnad
->conf_mutex
);
450 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
451 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
452 !BNA_POWER_OF_2(ringparam
->tx_pending
)) {
453 mutex_unlock(&bnad
->conf_mutex
);
457 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
458 bnad
->rxq_depth
= ringparam
->rx_pending
;
459 if (!netif_running(netdev
)) {
460 mutex_unlock(&bnad
->conf_mutex
);
464 for (i
= 0; i
< bnad
->num_rx
; i
++) {
465 if (!bnad
->rx_info
[i
].rx
)
467 bnad_cleanup_rx(bnad
, i
);
468 current_err
= bnad_setup_rx(bnad
, i
);
469 if (current_err
&& !err
)
473 if (!err
&& bnad
->rx_info
[0].rx
) {
474 /* restore rx configuration */
475 bnad_restore_vlans(bnad
, 0);
476 bnad_enable_default_bcast(bnad
);
477 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
478 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
479 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
480 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
482 bnad_set_rx_mode(netdev
);
485 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
486 bnad
->txq_depth
= ringparam
->tx_pending
;
487 if (!netif_running(netdev
)) {
488 mutex_unlock(&bnad
->conf_mutex
);
492 for (i
= 0; i
< bnad
->num_tx
; i
++) {
493 if (!bnad
->tx_info
[i
].tx
)
495 bnad_cleanup_tx(bnad
, i
);
496 current_err
= bnad_setup_tx(bnad
, i
);
497 if (current_err
&& !err
)
502 mutex_unlock(&bnad
->conf_mutex
);
507 bnad_get_pauseparam(struct net_device
*netdev
,
508 struct ethtool_pauseparam
*pauseparam
)
510 struct bnad
*bnad
= netdev_priv(netdev
);
512 pauseparam
->autoneg
= 0;
513 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
514 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
518 bnad_set_pauseparam(struct net_device
*netdev
,
519 struct ethtool_pauseparam
*pauseparam
)
521 struct bnad
*bnad
= netdev_priv(netdev
);
522 struct bna_pause_config pause_config
;
525 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
528 mutex_lock(&bnad
->conf_mutex
);
529 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
530 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
531 pause_config
.rx_pause
= pauseparam
->rx_pause
;
532 pause_config
.tx_pause
= pauseparam
->tx_pause
;
533 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
534 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
, NULL
);
535 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
537 mutex_unlock(&bnad
->conf_mutex
);
542 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
* string
)
544 struct bnad
*bnad
= netdev_priv(netdev
);
548 mutex_lock(&bnad
->conf_mutex
);
552 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
553 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) <
555 memcpy(string
, bnad_net_stats_strings
[i
],
557 string
+= ETH_GSTRING_LEN
;
559 bmap
= bna_tx_rid_mask(&bnad
->bna
);
560 for (i
= 0; bmap
; i
++) {
562 sprintf(string
, "txf%d_ucast_octets", i
);
563 string
+= ETH_GSTRING_LEN
;
564 sprintf(string
, "txf%d_ucast", i
);
565 string
+= ETH_GSTRING_LEN
;
566 sprintf(string
, "txf%d_ucast_vlan", i
);
567 string
+= ETH_GSTRING_LEN
;
568 sprintf(string
, "txf%d_mcast_octets", i
);
569 string
+= ETH_GSTRING_LEN
;
570 sprintf(string
, "txf%d_mcast", i
);
571 string
+= ETH_GSTRING_LEN
;
572 sprintf(string
, "txf%d_mcast_vlan", i
);
573 string
+= ETH_GSTRING_LEN
;
574 sprintf(string
, "txf%d_bcast_octets", i
);
575 string
+= ETH_GSTRING_LEN
;
576 sprintf(string
, "txf%d_bcast", i
);
577 string
+= ETH_GSTRING_LEN
;
578 sprintf(string
, "txf%d_bcast_vlan", i
);
579 string
+= ETH_GSTRING_LEN
;
580 sprintf(string
, "txf%d_errors", i
);
581 string
+= ETH_GSTRING_LEN
;
582 sprintf(string
, "txf%d_filter_vlan", i
);
583 string
+= ETH_GSTRING_LEN
;
584 sprintf(string
, "txf%d_filter_mac_sa", i
);
585 string
+= ETH_GSTRING_LEN
;
590 bmap
= bna_rx_rid_mask(&bnad
->bna
);
591 for (i
= 0; bmap
; i
++) {
593 sprintf(string
, "rxf%d_ucast_octets", i
);
594 string
+= ETH_GSTRING_LEN
;
595 sprintf(string
, "rxf%d_ucast", i
);
596 string
+= ETH_GSTRING_LEN
;
597 sprintf(string
, "rxf%d_ucast_vlan", i
);
598 string
+= ETH_GSTRING_LEN
;
599 sprintf(string
, "rxf%d_mcast_octets", i
);
600 string
+= ETH_GSTRING_LEN
;
601 sprintf(string
, "rxf%d_mcast", i
);
602 string
+= ETH_GSTRING_LEN
;
603 sprintf(string
, "rxf%d_mcast_vlan", i
);
604 string
+= ETH_GSTRING_LEN
;
605 sprintf(string
, "rxf%d_bcast_octets", i
);
606 string
+= ETH_GSTRING_LEN
;
607 sprintf(string
, "rxf%d_bcast", i
);
608 string
+= ETH_GSTRING_LEN
;
609 sprintf(string
, "rxf%d_bcast_vlan", i
);
610 string
+= ETH_GSTRING_LEN
;
611 sprintf(string
, "rxf%d_frame_drops", i
);
612 string
+= ETH_GSTRING_LEN
;
618 for (i
= 0; i
< bnad
->num_rx
; i
++) {
619 if (!bnad
->rx_info
[i
].rx
)
621 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
622 sprintf(string
, "cq%d_producer_index", q_num
);
623 string
+= ETH_GSTRING_LEN
;
624 sprintf(string
, "cq%d_consumer_index", q_num
);
625 string
+= ETH_GSTRING_LEN
;
626 sprintf(string
, "cq%d_hw_producer_index",
628 string
+= ETH_GSTRING_LEN
;
629 sprintf(string
, "cq%d_intr", q_num
);
630 string
+= ETH_GSTRING_LEN
;
631 sprintf(string
, "cq%d_poll", q_num
);
632 string
+= ETH_GSTRING_LEN
;
633 sprintf(string
, "cq%d_schedule", q_num
);
634 string
+= ETH_GSTRING_LEN
;
635 sprintf(string
, "cq%d_keep_poll", q_num
);
636 string
+= ETH_GSTRING_LEN
;
637 sprintf(string
, "cq%d_complete", q_num
);
638 string
+= ETH_GSTRING_LEN
;
644 for (i
= 0; i
< bnad
->num_rx
; i
++) {
645 if (!bnad
->rx_info
[i
].rx
)
647 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
648 sprintf(string
, "rxq%d_packets", q_num
);
649 string
+= ETH_GSTRING_LEN
;
650 sprintf(string
, "rxq%d_bytes", q_num
);
651 string
+= ETH_GSTRING_LEN
;
652 sprintf(string
, "rxq%d_packets_with_error",
654 string
+= ETH_GSTRING_LEN
;
655 sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
656 string
+= ETH_GSTRING_LEN
;
657 sprintf(string
, "rxq%d_producer_index", q_num
);
658 string
+= ETH_GSTRING_LEN
;
659 sprintf(string
, "rxq%d_consumer_index", q_num
);
660 string
+= ETH_GSTRING_LEN
;
662 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
663 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
665 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
667 sprintf(string
, "rxq%d_packets", q_num
);
668 string
+= ETH_GSTRING_LEN
;
669 sprintf(string
, "rxq%d_bytes", q_num
);
670 string
+= ETH_GSTRING_LEN
;
672 "rxq%d_packets_with_error", q_num
);
673 string
+= ETH_GSTRING_LEN
;
674 sprintf(string
, "rxq%d_allocbuf_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
->producer_index
;
809 buf
[bi
++] = rcb
->consumer_index
;
811 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
812 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
814 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
816 buf
[bi
++] = rcb
->rxq
->rx_packets
;
817 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
818 buf
[bi
++] = rcb
->rxq
->
819 rx_packets_with_error
;
820 buf
[bi
++] = rcb
->rxq
->
822 buf
[bi
++] = rcb
->producer_index
;
823 buf
[bi
++] = rcb
->consumer_index
;
828 for (i
= 0; i
< bnad
->num_tx
; i
++) {
829 if (!bnad
->tx_info
[i
].tx
)
831 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
832 if (bnad
->tx_info
[i
].tcb
[j
] &&
833 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
834 tcb
= bnad
->tx_info
[i
].tcb
[j
];
835 buf
[bi
++] = tcb
->txq
->tx_packets
;
836 buf
[bi
++] = tcb
->txq
->tx_bytes
;
837 buf
[bi
++] = tcb
->producer_index
;
838 buf
[bi
++] = tcb
->consumer_index
;
839 buf
[bi
++] = *(tcb
->hw_consumer_index
);
847 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
850 struct bnad
*bnad
= netdev_priv(netdev
);
853 struct rtnl_link_stats64
*net_stats64
;
857 mutex_lock(&bnad
->conf_mutex
);
858 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
859 mutex_unlock(&bnad
->conf_mutex
);
864 * Used bna_lock to sync reads from bna_stats, which is written
865 * under the same lock
867 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
869 memset(buf
, 0, stats
->n_stats
* sizeof(u64
));
871 net_stats64
= (struct rtnl_link_stats64
*)buf
;
872 bnad_netdev_qstats_fill(bnad
, net_stats64
);
873 bnad_netdev_hwstats_fill(bnad
, net_stats64
);
875 bi
= sizeof(*net_stats64
) / sizeof(u64
);
877 /* Get netif_queue_stopped from stack */
878 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
880 /* Fill driver stats into ethtool buffers */
881 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
882 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
883 buf
[bi
++] = stats64
[i
];
885 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
886 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
888 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
891 buf
[bi
++] = stats64
[i
];
893 /* Fill txf stats into ethtool buffers */
894 bmap
= bna_tx_rid_mask(&bnad
->bna
);
895 for (i
= 0; bmap
; i
++) {
897 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
898 hw_stats
.txf_stats
[i
];
899 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
901 buf
[bi
++] = stats64
[j
];
906 /* Fill rxf stats into ethtool buffers */
907 bmap
= bna_rx_rid_mask(&bnad
->bna
);
908 for (i
= 0; bmap
; i
++) {
910 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
911 hw_stats
.rxf_stats
[i
];
912 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
914 buf
[bi
++] = stats64
[j
];
919 /* Fill per Q stats into ethtool buffers */
920 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
922 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
924 mutex_unlock(&bnad
->conf_mutex
);
928 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
932 return bnad_get_stats_count_locked(netdev
);
939 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
942 struct bfa_flash_attr
*flash_attr
;
943 struct bnad_iocmd_comp fcomp
;
944 u32 i
, flash_part
= 0, ret
;
945 unsigned long flags
= 0;
947 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
952 fcomp
.comp_status
= 0;
954 init_completion(&fcomp
.comp
);
955 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
956 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
957 bnad_cb_completion
, &fcomp
);
958 if (ret
!= BFA_STATUS_OK
) {
959 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
963 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
964 wait_for_completion(&fcomp
.comp
);
965 ret
= fcomp
.comp_status
;
967 /* Check for the flash type & base offset value */
968 if (ret
== BFA_STATUS_OK
) {
969 for (i
= 0; i
< flash_attr
->npart
; i
++) {
970 if (offset
>= flash_attr
->part
[i
].part_off
&&
971 offset
< (flash_attr
->part
[i
].part_off
+
972 flash_attr
->part
[i
].part_size
)) {
973 flash_part
= flash_attr
->part
[i
].part_type
;
974 *base_offset
= flash_attr
->part
[i
].part_off
;
984 bnad_get_eeprom_len(struct net_device
*netdev
)
986 return BFA_TOTAL_FLASH_SIZE
;
990 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
993 struct bnad
*bnad
= netdev_priv(netdev
);
994 struct bnad_iocmd_comp fcomp
;
995 u32 flash_part
= 0, base_offset
= 0;
996 unsigned long flags
= 0;
999 /* Check if the flash read request is valid */
1000 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1001 (bnad
->pcidev
->device
<< 16)))
1004 /* Query the flash partition based on the offset */
1005 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1006 eeprom
->offset
, &base_offset
);
1007 if (flash_part
== 0)
1011 fcomp
.comp_status
= 0;
1013 init_completion(&fcomp
.comp
);
1014 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1015 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
1016 bnad
->id
, bytes
, eeprom
->len
,
1017 eeprom
->offset
- base_offset
,
1018 bnad_cb_completion
, &fcomp
);
1019 if (ret
!= BFA_STATUS_OK
) {
1020 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1024 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1025 wait_for_completion(&fcomp
.comp
);
1026 ret
= fcomp
.comp_status
;
1032 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
1035 struct bnad
*bnad
= netdev_priv(netdev
);
1036 struct bnad_iocmd_comp fcomp
;
1037 u32 flash_part
= 0, base_offset
= 0;
1038 unsigned long flags
= 0;
1041 /* Check if the flash update request is valid */
1042 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
1043 (bnad
->pcidev
->device
<< 16)))
1046 /* Query the flash partition based on the offset */
1047 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1048 eeprom
->offset
, &base_offset
);
1049 if (flash_part
== 0)
1053 fcomp
.comp_status
= 0;
1055 init_completion(&fcomp
.comp
);
1056 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1057 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1058 bnad
->id
, bytes
, eeprom
->len
,
1059 eeprom
->offset
- base_offset
,
1060 bnad_cb_completion
, &fcomp
);
1061 if (ret
!= BFA_STATUS_OK
) {
1062 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1066 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1067 wait_for_completion(&fcomp
.comp
);
1068 ret
= fcomp
.comp_status
;
1073 static const struct ethtool_ops bnad_ethtool_ops
= {
1074 .get_settings
= bnad_get_settings
,
1075 .set_settings
= bnad_set_settings
,
1076 .get_drvinfo
= bnad_get_drvinfo
,
1077 .get_wol
= bnad_get_wol
,
1078 .get_link
= ethtool_op_get_link
,
1079 .get_coalesce
= bnad_get_coalesce
,
1080 .set_coalesce
= bnad_set_coalesce
,
1081 .get_ringparam
= bnad_get_ringparam
,
1082 .set_ringparam
= bnad_set_ringparam
,
1083 .get_pauseparam
= bnad_get_pauseparam
,
1084 .set_pauseparam
= bnad_set_pauseparam
,
1085 .get_strings
= bnad_get_strings
,
1086 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1087 .get_sset_count
= bnad_get_sset_count
,
1088 .get_eeprom_len
= bnad_get_eeprom_len
,
1089 .get_eeprom
= bnad_get_eeprom
,
1090 .set_eeprom
= bnad_set_eeprom
,
1094 bnad_set_ethtool_ops(struct net_device
*netdev
)
1096 SET_ETHTOOL_OPS(netdev
, &bnad_ethtool_ops
);