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_multiple_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 ethtool_link_ksettings_zero_link_mode(cmd
, supported
);
239 ethtool_link_ksettings_zero_link_mode(cmd
, advertising
);
241 ethtool_link_ksettings_add_link_mode(cmd
, supported
, 10000baseCR_Full
);
242 ethtool_link_ksettings_add_link_mode(cmd
, supported
, 10000baseSR_Full
);
243 ethtool_link_ksettings_add_link_mode(cmd
, supported
, 10000baseLR_Full
);
244 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, 10000baseCR_Full
);
245 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, 10000baseSR_Full
);
246 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, 10000baseLR_Full
);
247 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
248 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
249 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, FIBRE
);
250 cmd
->base
.port
= PORT_FIBRE
;
251 cmd
->base
.phy_address
= 0;
253 if (netif_carrier_ok(netdev
)) {
254 cmd
->base
.speed
= SPEED_10000
;
255 cmd
->base
.duplex
= DUPLEX_FULL
;
257 cmd
->base
.speed
= SPEED_UNKNOWN
;
258 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
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 strscpy(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 strscpy(drvinfo
->fw_version
, ioc_attr
->adapter_attr
.fw_ver
,
295 sizeof(drvinfo
->fw_version
));
299 strscpy(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;
310 static int bnad_get_coalesce(struct net_device
*netdev
,
311 struct ethtool_coalesce
*coalesce
,
312 struct kernel_ethtool_coalesce
*kernel_coal
,
313 struct netlink_ext_ack
*extack
)
315 struct bnad
*bnad
= netdev_priv(netdev
);
318 /* Lock rqd. to access bnad->bna_lock */
319 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
320 coalesce
->use_adaptive_rx_coalesce
=
321 (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) ? true : false;
322 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
324 coalesce
->rx_coalesce_usecs
= bnad
->rx_coalescing_timeo
*
325 BFI_COALESCING_TIMER_UNIT
;
326 coalesce
->tx_coalesce_usecs
= bnad
->tx_coalescing_timeo
*
327 BFI_COALESCING_TIMER_UNIT
;
328 coalesce
->tx_max_coalesced_frames
= BFI_TX_INTERPKT_COUNT
;
333 static int bnad_set_coalesce(struct net_device
*netdev
,
334 struct ethtool_coalesce
*coalesce
,
335 struct kernel_ethtool_coalesce
*kernel_coal
,
336 struct netlink_ext_ack
*extack
)
338 struct bnad
*bnad
= netdev_priv(netdev
);
342 if (coalesce
->rx_coalesce_usecs
== 0 ||
343 coalesce
->rx_coalesce_usecs
>
344 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
347 if (coalesce
->tx_coalesce_usecs
== 0 ||
348 coalesce
->tx_coalesce_usecs
>
349 BFI_MAX_COALESCING_TIMEO
* BFI_COALESCING_TIMER_UNIT
)
352 mutex_lock(&bnad
->conf_mutex
);
354 * Do not need to store rx_coalesce_usecs here
355 * Every time DIM is disabled, we can get it from the
358 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
359 if (coalesce
->use_adaptive_rx_coalesce
) {
360 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)) {
361 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
362 bnad_dim_timer_start(bnad
);
365 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
) {
366 bnad
->cfg_flags
&= ~BNAD_CF_DIM_ENABLED
;
367 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
368 test_bit(BNAD_RF_DIM_TIMER_RUNNING
,
370 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
,
374 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
376 del_timer_sync(&bnad
->dim_timer
);
377 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
378 bnad_rx_coalescing_timeo_set(bnad
);
381 if (bnad
->tx_coalescing_timeo
!= coalesce
->tx_coalesce_usecs
/
382 BFI_COALESCING_TIMER_UNIT
) {
383 bnad
->tx_coalescing_timeo
= coalesce
->tx_coalesce_usecs
/
384 BFI_COALESCING_TIMER_UNIT
;
385 bnad_tx_coalescing_timeo_set(bnad
);
388 if (bnad
->rx_coalescing_timeo
!= coalesce
->rx_coalesce_usecs
/
389 BFI_COALESCING_TIMER_UNIT
) {
390 bnad
->rx_coalescing_timeo
= coalesce
->rx_coalesce_usecs
/
391 BFI_COALESCING_TIMER_UNIT
;
393 if (!(bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
))
394 bnad_rx_coalescing_timeo_set(bnad
);
398 /* Add Tx Inter-pkt DMA count? */
400 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
402 mutex_unlock(&bnad
->conf_mutex
);
407 bnad_get_ringparam(struct net_device
*netdev
,
408 struct ethtool_ringparam
*ringparam
,
409 struct kernel_ethtool_ringparam
*kernel_ringparam
,
410 struct netlink_ext_ack
*extack
)
412 struct bnad
*bnad
= netdev_priv(netdev
);
414 ringparam
->rx_max_pending
= BNAD_MAX_RXQ_DEPTH
;
415 ringparam
->tx_max_pending
= BNAD_MAX_TXQ_DEPTH
;
417 ringparam
->rx_pending
= bnad
->rxq_depth
;
418 ringparam
->tx_pending
= bnad
->txq_depth
;
422 bnad_set_ringparam(struct net_device
*netdev
,
423 struct ethtool_ringparam
*ringparam
,
424 struct kernel_ethtool_ringparam
*kernel_ringparam
,
425 struct netlink_ext_ack
*extack
)
427 int i
, current_err
, err
= 0;
428 struct bnad
*bnad
= netdev_priv(netdev
);
431 mutex_lock(&bnad
->conf_mutex
);
432 if (ringparam
->rx_pending
== bnad
->rxq_depth
&&
433 ringparam
->tx_pending
== bnad
->txq_depth
) {
434 mutex_unlock(&bnad
->conf_mutex
);
438 if (ringparam
->rx_pending
< BNAD_MIN_Q_DEPTH
||
439 ringparam
->rx_pending
> BNAD_MAX_RXQ_DEPTH
||
440 !is_power_of_2(ringparam
->rx_pending
)) {
441 mutex_unlock(&bnad
->conf_mutex
);
444 if (ringparam
->tx_pending
< BNAD_MIN_Q_DEPTH
||
445 ringparam
->tx_pending
> BNAD_MAX_TXQ_DEPTH
||
446 !is_power_of_2(ringparam
->tx_pending
)) {
447 mutex_unlock(&bnad
->conf_mutex
);
451 if (ringparam
->rx_pending
!= bnad
->rxq_depth
) {
452 bnad
->rxq_depth
= ringparam
->rx_pending
;
453 if (!netif_running(netdev
)) {
454 mutex_unlock(&bnad
->conf_mutex
);
458 for (i
= 0; i
< bnad
->num_rx
; i
++) {
459 if (!bnad
->rx_info
[i
].rx
)
461 bnad_destroy_rx(bnad
, i
);
462 current_err
= bnad_setup_rx(bnad
, i
);
463 if (current_err
&& !err
)
467 if (!err
&& bnad
->rx_info
[0].rx
) {
468 /* restore rx configuration */
469 bnad_restore_vlans(bnad
, 0);
470 bnad_enable_default_bcast(bnad
);
471 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
472 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
473 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
474 bnad
->cfg_flags
&= ~(BNAD_CF_ALLMULTI
|
476 bnad_set_rx_mode(netdev
);
479 if (ringparam
->tx_pending
!= bnad
->txq_depth
) {
480 bnad
->txq_depth
= ringparam
->tx_pending
;
481 if (!netif_running(netdev
)) {
482 mutex_unlock(&bnad
->conf_mutex
);
486 for (i
= 0; i
< bnad
->num_tx
; i
++) {
487 if (!bnad
->tx_info
[i
].tx
)
489 bnad_destroy_tx(bnad
, i
);
490 current_err
= bnad_setup_tx(bnad
, i
);
491 if (current_err
&& !err
)
496 mutex_unlock(&bnad
->conf_mutex
);
501 bnad_get_pauseparam(struct net_device
*netdev
,
502 struct ethtool_pauseparam
*pauseparam
)
504 struct bnad
*bnad
= netdev_priv(netdev
);
506 pauseparam
->autoneg
= 0;
507 pauseparam
->rx_pause
= bnad
->bna
.enet
.pause_config
.rx_pause
;
508 pauseparam
->tx_pause
= bnad
->bna
.enet
.pause_config
.tx_pause
;
512 bnad_set_pauseparam(struct net_device
*netdev
,
513 struct ethtool_pauseparam
*pauseparam
)
515 struct bnad
*bnad
= netdev_priv(netdev
);
516 struct bna_pause_config pause_config
;
519 if (pauseparam
->autoneg
== AUTONEG_ENABLE
)
522 mutex_lock(&bnad
->conf_mutex
);
523 if (pauseparam
->rx_pause
!= bnad
->bna
.enet
.pause_config
.rx_pause
||
524 pauseparam
->tx_pause
!= bnad
->bna
.enet
.pause_config
.tx_pause
) {
525 pause_config
.rx_pause
= pauseparam
->rx_pause
;
526 pause_config
.tx_pause
= pauseparam
->tx_pause
;
527 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
528 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
529 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
531 mutex_unlock(&bnad
->conf_mutex
);
535 static void bnad_get_txf_strings(u8
**string
, int f_num
)
537 ethtool_sprintf(string
, "txf%d_ucast_octets", f_num
);
538 ethtool_sprintf(string
, "txf%d_ucast", f_num
);
539 ethtool_sprintf(string
, "txf%d_ucast_vlan", f_num
);
540 ethtool_sprintf(string
, "txf%d_mcast_octets", f_num
);
541 ethtool_sprintf(string
, "txf%d_mcast", f_num
);
542 ethtool_sprintf(string
, "txf%d_mcast_vlan", f_num
);
543 ethtool_sprintf(string
, "txf%d_bcast_octets", f_num
);
544 ethtool_sprintf(string
, "txf%d_bcast", f_num
);
545 ethtool_sprintf(string
, "txf%d_bcast_vlan", f_num
);
546 ethtool_sprintf(string
, "txf%d_errors", f_num
);
547 ethtool_sprintf(string
, "txf%d_filter_vlan", f_num
);
548 ethtool_sprintf(string
, "txf%d_filter_mac_sa", f_num
);
551 static void bnad_get_rxf_strings(u8
**string
, int f_num
)
553 ethtool_sprintf(string
, "rxf%d_ucast_octets", f_num
);
554 ethtool_sprintf(string
, "rxf%d_ucast", f_num
);
555 ethtool_sprintf(string
, "rxf%d_ucast_vlan", f_num
);
556 ethtool_sprintf(string
, "rxf%d_mcast_octets", f_num
);
557 ethtool_sprintf(string
, "rxf%d_mcast", f_num
);
558 ethtool_sprintf(string
, "rxf%d_mcast_vlan", f_num
);
559 ethtool_sprintf(string
, "rxf%d_bcast_octets", f_num
);
560 ethtool_sprintf(string
, "rxf%d_bcast", f_num
);
561 ethtool_sprintf(string
, "rxf%d_bcast_vlan", f_num
);
562 ethtool_sprintf(string
, "rxf%d_frame_drops", f_num
);
565 static void bnad_get_cq_strings(u8
**string
, int q_num
)
567 ethtool_sprintf(string
, "cq%d_producer_index", q_num
);
568 ethtool_sprintf(string
, "cq%d_consumer_index", q_num
);
569 ethtool_sprintf(string
, "cq%d_hw_producer_index", q_num
);
570 ethtool_sprintf(string
, "cq%d_intr", q_num
);
571 ethtool_sprintf(string
, "cq%d_poll", q_num
);
572 ethtool_sprintf(string
, "cq%d_schedule", q_num
);
573 ethtool_sprintf(string
, "cq%d_keep_poll", q_num
);
574 ethtool_sprintf(string
, "cq%d_complete", q_num
);
577 static void bnad_get_rxq_strings(u8
**string
, int q_num
)
579 ethtool_sprintf(string
, "rxq%d_packets", q_num
);
580 ethtool_sprintf(string
, "rxq%d_bytes", q_num
);
581 ethtool_sprintf(string
, "rxq%d_packets_with_error", q_num
);
582 ethtool_sprintf(string
, "rxq%d_allocbuf_failed", q_num
);
583 ethtool_sprintf(string
, "rxq%d_mapbuf_failed", q_num
);
584 ethtool_sprintf(string
, "rxq%d_producer_index", q_num
);
585 ethtool_sprintf(string
, "rxq%d_consumer_index", q_num
);
588 static void bnad_get_txq_strings(u8
**string
, int q_num
)
590 ethtool_sprintf(string
, "txq%d_packets", q_num
);
591 ethtool_sprintf(string
, "txq%d_bytes", q_num
);
592 ethtool_sprintf(string
, "txq%d_producer_index", q_num
);
593 ethtool_sprintf(string
, "txq%d_consumer_index", q_num
);
594 ethtool_sprintf(string
, "txq%d_hw_consumer_index", q_num
);
598 bnad_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*string
)
600 struct bnad
*bnad
= netdev_priv(netdev
);
604 if (stringset
!= ETH_SS_STATS
)
607 mutex_lock(&bnad
->conf_mutex
);
609 for (i
= 0; i
< BNAD_ETHTOOL_STATS_NUM
; i
++) {
610 BUG_ON(!(strlen(bnad_net_stats_strings
[i
]) < ETH_GSTRING_LEN
));
611 ethtool_puts(&string
, bnad_net_stats_strings
[i
]);
614 bmap
= bna_tx_rid_mask(&bnad
->bna
);
615 for (i
= 0; bmap
; i
++) {
617 bnad_get_txf_strings(&string
, i
);
621 bmap
= bna_rx_rid_mask(&bnad
->bna
);
622 for (i
= 0; bmap
; i
++, bmap
>>= 1) {
624 bnad_get_rxf_strings(&string
, i
);
629 for (i
= 0; i
< bnad
->num_rx
; i
++) {
630 if (!bnad
->rx_info
[i
].rx
)
632 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
633 bnad_get_cq_strings(&string
, q_num
++);
637 for (i
= 0; i
< bnad
->num_rx
; i
++) {
638 if (!bnad
->rx_info
[i
].rx
)
640 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
641 bnad_get_rxq_strings(&string
, q_num
++);
642 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
643 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
644 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
645 bnad_get_rxq_strings(&string
, q_num
++);
650 for (i
= 0; i
< bnad
->num_tx
; i
++) {
651 if (!bnad
->tx_info
[i
].tx
)
653 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
654 bnad_get_txq_strings(&string
, q_num
++);
657 mutex_unlock(&bnad
->conf_mutex
);
661 bnad_get_stats_count_locked(struct net_device
*netdev
)
663 struct bnad
*bnad
= netdev_priv(netdev
);
664 int i
, j
, count
= 0, rxf_active_num
= 0, txf_active_num
= 0;
667 bmap
= bna_tx_rid_mask(&bnad
->bna
);
668 for (i
= 0; bmap
; i
++) {
673 bmap
= bna_rx_rid_mask(&bnad
->bna
);
674 for (i
= 0; bmap
; i
++) {
679 count
= BNAD_ETHTOOL_STATS_NUM
+
680 txf_active_num
* BNAD_NUM_TXF_COUNTERS
+
681 rxf_active_num
* BNAD_NUM_RXF_COUNTERS
;
683 for (i
= 0; i
< bnad
->num_rx
; i
++) {
684 if (!bnad
->rx_info
[i
].rx
)
686 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_CQ_COUNTERS
;
687 count
+= bnad
->num_rxp_per_rx
* BNAD_NUM_RXQ_COUNTERS
;
688 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
689 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
690 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
691 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1]->rxq
)
692 count
+= BNAD_NUM_RXQ_COUNTERS
;
695 for (i
= 0; i
< bnad
->num_tx
; i
++) {
696 if (!bnad
->tx_info
[i
].tx
)
698 count
+= bnad
->num_txq_per_tx
* BNAD_NUM_TXQ_COUNTERS
;
704 bnad_per_q_stats_fill(struct bnad
*bnad
, u64
*buf
, int bi
)
707 struct bna_rcb
*rcb
= NULL
;
708 struct bna_tcb
*tcb
= NULL
;
710 for (i
= 0; i
< bnad
->num_rx
; i
++) {
711 if (!bnad
->rx_info
[i
].rx
)
713 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
714 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
&&
715 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
716 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0]->rxq
) {
717 buf
[bi
++] = bnad
->rx_info
[i
].rx_ctrl
[j
].
719 buf
[bi
++] = 0; /* ccb->consumer_index */
720 buf
[bi
++] = *(bnad
->rx_info
[i
].rx_ctrl
[j
].
721 ccb
->hw_producer_index
);
723 buf
[bi
++] = bnad
->rx_info
[i
].
724 rx_ctrl
[j
].rx_intr_ctr
;
725 buf
[bi
++] = bnad
->rx_info
[i
].
726 rx_ctrl
[j
].rx_poll_ctr
;
727 buf
[bi
++] = bnad
->rx_info
[i
].
728 rx_ctrl
[j
].rx_schedule
;
729 buf
[bi
++] = bnad
->rx_info
[i
].
730 rx_ctrl
[j
].rx_keep_poll
;
731 buf
[bi
++] = bnad
->rx_info
[i
].
732 rx_ctrl
[j
].rx_complete
;
735 for (i
= 0; i
< bnad
->num_rx
; i
++) {
736 if (!bnad
->rx_info
[i
].rx
)
738 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++)
739 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
740 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[0] &&
741 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
743 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
745 buf
[bi
++] = rcb
->rxq
->rx_packets
;
746 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
747 buf
[bi
++] = rcb
->rxq
->
748 rx_packets_with_error
;
749 buf
[bi
++] = rcb
->rxq
->
751 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
752 buf
[bi
++] = rcb
->producer_index
;
753 buf
[bi
++] = rcb
->consumer_index
;
755 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
756 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
758 rcb
= bnad
->rx_info
[i
].rx_ctrl
[j
].
760 buf
[bi
++] = rcb
->rxq
->rx_packets
;
761 buf
[bi
++] = rcb
->rxq
->rx_bytes
;
762 buf
[bi
++] = rcb
->rxq
->
763 rx_packets_with_error
;
764 buf
[bi
++] = rcb
->rxq
->
766 buf
[bi
++] = rcb
->rxq
->rxbuf_map_failed
;
767 buf
[bi
++] = rcb
->producer_index
;
768 buf
[bi
++] = rcb
->consumer_index
;
773 for (i
= 0; i
< bnad
->num_tx
; i
++) {
774 if (!bnad
->tx_info
[i
].tx
)
776 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
777 if (bnad
->tx_info
[i
].tcb
[j
] &&
778 bnad
->tx_info
[i
].tcb
[j
]->txq
) {
779 tcb
= bnad
->tx_info
[i
].tcb
[j
];
780 buf
[bi
++] = tcb
->txq
->tx_packets
;
781 buf
[bi
++] = tcb
->txq
->tx_bytes
;
782 buf
[bi
++] = tcb
->producer_index
;
783 buf
[bi
++] = tcb
->consumer_index
;
784 buf
[bi
++] = *(tcb
->hw_consumer_index
);
792 bnad_get_ethtool_stats(struct net_device
*netdev
, struct ethtool_stats
*stats
,
795 struct bnad
*bnad
= netdev_priv(netdev
);
798 struct rtnl_link_stats64 net_stats64
;
802 mutex_lock(&bnad
->conf_mutex
);
803 if (bnad_get_stats_count_locked(netdev
) != stats
->n_stats
) {
804 mutex_unlock(&bnad
->conf_mutex
);
809 * Used bna_lock to sync reads from bna_stats, which is written
810 * under the same lock
812 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
814 memset(&net_stats64
, 0, sizeof(net_stats64
));
815 bnad_netdev_qstats_fill(bnad
, &net_stats64
);
816 bnad_netdev_hwstats_fill(bnad
, &net_stats64
);
818 buf
[bi
++] = net_stats64
.rx_packets
;
819 buf
[bi
++] = net_stats64
.tx_packets
;
820 buf
[bi
++] = net_stats64
.rx_bytes
;
821 buf
[bi
++] = net_stats64
.tx_bytes
;
822 buf
[bi
++] = net_stats64
.rx_errors
;
823 buf
[bi
++] = net_stats64
.tx_errors
;
824 buf
[bi
++] = net_stats64
.rx_dropped
;
825 buf
[bi
++] = net_stats64
.tx_dropped
;
826 buf
[bi
++] = net_stats64
.multicast
;
827 buf
[bi
++] = net_stats64
.collisions
;
828 buf
[bi
++] = net_stats64
.rx_length_errors
;
829 buf
[bi
++] = net_stats64
.rx_crc_errors
;
830 buf
[bi
++] = net_stats64
.rx_frame_errors
;
831 buf
[bi
++] = net_stats64
.tx_fifo_errors
;
833 /* Get netif_queue_stopped from stack */
834 bnad
->stats
.drv_stats
.netif_queue_stopped
= netif_queue_stopped(netdev
);
836 /* Fill driver stats into ethtool buffers */
837 stats64
= (u64
*)&bnad
->stats
.drv_stats
;
838 for (i
= 0; i
< sizeof(struct bnad_drv_stats
) / sizeof(u64
); i
++)
839 buf
[bi
++] = stats64
[i
];
841 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
842 stats64
= (u64
*) &bnad
->stats
.bna_stats
->hw_stats
;
844 i
< offsetof(struct bfi_enet_stats
, rxf_stats
[0]) /
847 buf
[bi
++] = stats64
[i
];
849 /* Fill txf stats into ethtool buffers */
850 bmap
= bna_tx_rid_mask(&bnad
->bna
);
851 for (i
= 0; bmap
; i
++) {
853 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
854 hw_stats
.txf_stats
[i
];
855 for (j
= 0; j
< sizeof(struct bfi_enet_stats_txf
) /
857 buf
[bi
++] = stats64
[j
];
862 /* Fill rxf stats into ethtool buffers */
863 bmap
= bna_rx_rid_mask(&bnad
->bna
);
864 for (i
= 0; bmap
; i
++) {
866 stats64
= (u64
*)&bnad
->stats
.bna_stats
->
867 hw_stats
.rxf_stats
[i
];
868 for (j
= 0; j
< sizeof(struct bfi_enet_stats_rxf
) /
870 buf
[bi
++] = stats64
[j
];
875 /* Fill per Q stats into ethtool buffers */
876 bi
= bnad_per_q_stats_fill(bnad
, buf
, bi
);
878 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
880 mutex_unlock(&bnad
->conf_mutex
);
884 bnad_get_sset_count(struct net_device
*netdev
, int sset
)
888 return bnad_get_stats_count_locked(netdev
);
895 bnad_get_flash_partition_by_offset(struct bnad
*bnad
, u32 offset
,
898 struct bfa_flash_attr
*flash_attr
;
899 struct bnad_iocmd_comp fcomp
;
900 u32 i
, flash_part
= 0, ret
;
901 unsigned long flags
= 0;
903 flash_attr
= kzalloc(sizeof(struct bfa_flash_attr
), GFP_KERNEL
);
908 fcomp
.comp_status
= 0;
910 init_completion(&fcomp
.comp
);
911 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
912 ret
= bfa_nw_flash_get_attr(&bnad
->bna
.flash
, flash_attr
,
913 bnad_cb_completion
, &fcomp
);
914 if (ret
!= BFA_STATUS_OK
) {
915 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
919 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
920 wait_for_completion(&fcomp
.comp
);
921 ret
= fcomp
.comp_status
;
923 /* Check for the flash type & base offset value */
924 if (ret
== BFA_STATUS_OK
) {
925 for (i
= 0; i
< flash_attr
->npart
; i
++) {
926 if (offset
>= flash_attr
->part
[i
].part_off
&&
927 offset
< (flash_attr
->part
[i
].part_off
+
928 flash_attr
->part
[i
].part_size
)) {
929 flash_part
= flash_attr
->part
[i
].part_type
;
930 *base_offset
= flash_attr
->part
[i
].part_off
;
940 bnad_get_eeprom_len(struct net_device
*netdev
)
942 return BFA_TOTAL_FLASH_SIZE
;
946 bnad_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
949 struct bnad
*bnad
= netdev_priv(netdev
);
950 struct bnad_iocmd_comp fcomp
;
951 u32 flash_part
= 0, base_offset
= 0;
952 unsigned long flags
= 0;
955 /* Fill the magic value */
956 eeprom
->magic
= bnad
->pcidev
->vendor
| (bnad
->pcidev
->device
<< 16);
958 /* Query the flash partition based on the offset */
959 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
960 eeprom
->offset
, &base_offset
);
965 fcomp
.comp_status
= 0;
967 init_completion(&fcomp
.comp
);
968 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
969 ret
= bfa_nw_flash_read_part(&bnad
->bna
.flash
, flash_part
,
970 bnad
->id
, bytes
, eeprom
->len
,
971 eeprom
->offset
- base_offset
,
972 bnad_cb_completion
, &fcomp
);
973 if (ret
!= BFA_STATUS_OK
) {
974 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
978 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
979 wait_for_completion(&fcomp
.comp
);
980 ret
= fcomp
.comp_status
;
986 bnad_set_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
989 struct bnad
*bnad
= netdev_priv(netdev
);
990 struct bnad_iocmd_comp fcomp
;
991 u32 flash_part
= 0, base_offset
= 0;
992 unsigned long flags
= 0;
995 /* Check if the flash update request is valid */
996 if (eeprom
->magic
!= (bnad
->pcidev
->vendor
|
997 (bnad
->pcidev
->device
<< 16)))
1000 /* Query the flash partition based on the offset */
1001 flash_part
= bnad_get_flash_partition_by_offset(bnad
,
1002 eeprom
->offset
, &base_offset
);
1003 if (flash_part
== 0)
1007 fcomp
.comp_status
= 0;
1009 init_completion(&fcomp
.comp
);
1010 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1011 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, flash_part
,
1012 bnad
->id
, bytes
, eeprom
->len
,
1013 eeprom
->offset
- base_offset
,
1014 bnad_cb_completion
, &fcomp
);
1015 if (ret
!= BFA_STATUS_OK
) {
1016 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1020 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1021 wait_for_completion(&fcomp
.comp
);
1022 ret
= fcomp
.comp_status
;
1028 bnad_flash_device(struct net_device
*netdev
, struct ethtool_flash
*eflash
)
1030 struct bnad
*bnad
= netdev_priv(netdev
);
1031 struct bnad_iocmd_comp fcomp
;
1032 const struct firmware
*fw
;
1035 ret
= request_firmware(&fw
, eflash
->data
, &bnad
->pcidev
->dev
);
1037 netdev_err(netdev
, "can't load firmware %s\n", eflash
->data
);
1042 fcomp
.comp_status
= 0;
1044 init_completion(&fcomp
.comp
);
1045 spin_lock_irq(&bnad
->bna_lock
);
1046 ret
= bfa_nw_flash_update_part(&bnad
->bna
.flash
, BFA_FLASH_PART_FWIMG
,
1047 bnad
->id
, (u8
*)fw
->data
, fw
->size
, 0,
1048 bnad_cb_completion
, &fcomp
);
1049 if (ret
!= BFA_STATUS_OK
) {
1050 netdev_warn(netdev
, "flash update failed with err=%d\n", ret
);
1052 spin_unlock_irq(&bnad
->bna_lock
);
1056 spin_unlock_irq(&bnad
->bna_lock
);
1057 wait_for_completion(&fcomp
.comp
);
1058 if (fcomp
.comp_status
!= BFA_STATUS_OK
) {
1061 "firmware image update failed with err=%d\n",
1065 release_firmware(fw
);
1069 static const struct ethtool_ops bnad_ethtool_ops
= {
1070 .supported_coalesce_params
= ETHTOOL_COALESCE_USECS
|
1071 ETHTOOL_COALESCE_TX_MAX_FRAMES
|
1072 ETHTOOL_COALESCE_USE_ADAPTIVE_RX
,
1073 .get_drvinfo
= bnad_get_drvinfo
,
1074 .get_wol
= bnad_get_wol
,
1075 .get_link
= ethtool_op_get_link
,
1076 .get_coalesce
= bnad_get_coalesce
,
1077 .set_coalesce
= bnad_set_coalesce
,
1078 .get_ringparam
= bnad_get_ringparam
,
1079 .set_ringparam
= bnad_set_ringparam
,
1080 .get_pauseparam
= bnad_get_pauseparam
,
1081 .set_pauseparam
= bnad_set_pauseparam
,
1082 .get_strings
= bnad_get_strings
,
1083 .get_ethtool_stats
= bnad_get_ethtool_stats
,
1084 .get_sset_count
= bnad_get_sset_count
,
1085 .get_eeprom_len
= bnad_get_eeprom_len
,
1086 .get_eeprom
= bnad_get_eeprom
,
1087 .set_eeprom
= bnad_set_eeprom
,
1088 .flash_device
= bnad_flash_device
,
1089 .get_ts_info
= ethtool_op_get_ts_info
,
1090 .get_link_ksettings
= bnad_get_link_ksettings
,
1091 .set_link_ksettings
= bnad_set_link_ksettings
,
1095 bnad_set_ethtool_ops(struct net_device
*netdev
)
1097 netdev
->ethtool_ops
= &bnad_ethtool_ops
;