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",
110 "mac_frame_512_1023",
111 "mac_frame_1024_1518",
112 "mac_frame_1518_1522",
118 "mac_rx_control_frames",
120 "mac_rx_unknown_opcode",
121 "mac_rx_alignment_error",
122 "mac_rx_frame_length_error",
124 "mac_rx_carrier_sense_error",
137 "mac_tx_excessive_deferral",
138 "mac_tx_single_collision",
139 "mac_tx_muliple_collision",
140 "mac_tx_late_collision",
141 "mac_tx_excessive_collision",
142 "mac_tx_total_collision",
143 "mac_tx_pause_honored",
147 "mac_tx_control_frame",
160 "bpc_tx_zero_pause_0",
161 "bpc_tx_zero_pause_1",
162 "bpc_tx_zero_pause_2",
163 "bpc_tx_zero_pause_3",
164 "bpc_tx_zero_pause_4",
165 "bpc_tx_zero_pause_5",
166 "bpc_tx_zero_pause_6",
167 "bpc_tx_zero_pause_7",
168 "bpc_tx_first_pause_0",
169 "bpc_tx_first_pause_1",
170 "bpc_tx_first_pause_2",
171 "bpc_tx_first_pause_3",
172 "bpc_tx_first_pause_4",
173 "bpc_tx_first_pause_5",
174 "bpc_tx_first_pause_6",
175 "bpc_tx_first_pause_7",
185 "bpc_rx_zero_pause_0",
186 "bpc_rx_zero_pause_1",
187 "bpc_rx_zero_pause_2",
188 "bpc_rx_zero_pause_3",
189 "bpc_rx_zero_pause_4",
190 "bpc_rx_zero_pause_5",
191 "bpc_rx_zero_pause_6",
192 "bpc_rx_zero_pause_7",
193 "bpc_rx_first_pause_0",
194 "bpc_rx_first_pause_1",
195 "bpc_rx_first_pause_2",
196 "bpc_rx_first_pause_3",
197 "bpc_rx_first_pause_4",
198 "bpc_rx_first_pause_5",
199 "bpc_rx_first_pause_6",
200 "bpc_rx_first_pause_7",
204 "rad_rx_vlan_frames",
206 "rad_rx_ucast_octets",
209 "rad_rx_mcast_octets",
212 "rad_rx_bcast_octets",
218 "rlb_rad_rx_vlan_frames",
220 "rlb_rad_rx_ucast_octets",
221 "rlb_rad_rx_ucast_vlan",
223 "rlb_rad_rx_mcast_octets",
224 "rlb_rad_rx_mcast_vlan",
226 "rlb_rad_rx_bcast_octets",
227 "rlb_rad_rx_bcast_vlan",
230 "fc_rx_ucast_octets",
233 "fc_rx_mcast_octets",
236 "fc_rx_bcast_octets",
240 "fc_tx_ucast_octets",
243 "fc_tx_mcast_octets",
246 "fc_tx_bcast_octets",
249 "fc_tx_parity_errors",
251 "fc_tx_fid_parity_errors",
255 bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
257 cmd->supported = SUPPORTED_10000baseT_Full;
258 cmd->advertising = ADVERTISED_10000baseT_Full;
259 cmd->autoneg = AUTONEG_DISABLE;
260 cmd->supported |= SUPPORTED_FIBRE;
261 cmd->advertising |= ADVERTISED_FIBRE;
262 cmd->port = PORT_FIBRE;
263 cmd->phy_address = 0;
265 if (netif_carrier_ok(netdev)) {
266 ethtool_cmd_speed_set(cmd, SPEED_10000);
267 cmd->duplex = DUPLEX_FULL;
269 ethtool_cmd_speed_set(cmd, -1);
272 cmd->transceiver = XCVR_EXTERNAL;
280 bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
282 /* 10G full duplex setting supported only */
283 if (cmd->autoneg == AUTONEG_ENABLE)
284 return -EOPNOTSUPP; else {
285 if ((ethtool_cmd_speed(cmd) == SPEED_10000)
286 && (cmd->duplex == DUPLEX_FULL))
294 bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
296 struct bnad *bnad = netdev_priv(netdev);
297 struct bfa_ioc_attr *ioc_attr;
300 strlcpy(drvinfo->driver, BNAD_NAME, sizeof(drvinfo->driver));
301 strlcpy(drvinfo->version, BNAD_VERSION, sizeof(drvinfo->version));
303 ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
305 spin_lock_irqsave(&bnad->bna_lock, flags);
306 bfa_nw_ioc_get_attr(&bnad->bna.ioceth.ioc, ioc_attr);
307 spin_unlock_irqrestore(&bnad->bna_lock, flags);
309 strlcpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
310 sizeof(drvinfo->fw_version));
314 strlcpy(drvinfo->bus_info, pci_name(bnad->pcidev),
315 sizeof(drvinfo->bus_info));
319 bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
321 wolinfo->supported = 0;
322 wolinfo->wolopts = 0;
326 bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
328 struct bnad *bnad = netdev_priv(netdev);
331 /* Lock rqd. to access bnad->bna_lock */
332 spin_lock_irqsave(&bnad->bna_lock, flags);
333 coalesce->use_adaptive_rx_coalesce =
334 (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
335 spin_unlock_irqrestore(&bnad->bna_lock, flags);
337 coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
338 BFI_COALESCING_TIMER_UNIT;
339 coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
340 BFI_COALESCING_TIMER_UNIT;
341 coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
347 bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
349 struct bnad *bnad = netdev_priv(netdev);
353 if (coalesce->rx_coalesce_usecs == 0 ||
354 coalesce->rx_coalesce_usecs >
355 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
358 if (coalesce->tx_coalesce_usecs == 0 ||
359 coalesce->tx_coalesce_usecs >
360 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
363 mutex_lock(&bnad->conf_mutex);
365 * Do not need to store rx_coalesce_usecs here
366 * Every time DIM is disabled, we can get it from the
369 spin_lock_irqsave(&bnad->bna_lock, flags);
370 if (coalesce->use_adaptive_rx_coalesce) {
371 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
372 bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
373 bnad_dim_timer_start(bnad);
376 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
377 bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
378 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
379 test_bit(BNAD_RF_DIM_TIMER_RUNNING,
381 clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
385 spin_unlock_irqrestore(&bnad->bna_lock, flags);
387 del_timer_sync(&bnad->dim_timer);
388 spin_lock_irqsave(&bnad->bna_lock, flags);
389 bnad_rx_coalescing_timeo_set(bnad);
392 if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
393 BFI_COALESCING_TIMER_UNIT) {
394 bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
395 BFI_COALESCING_TIMER_UNIT;
396 bnad_tx_coalescing_timeo_set(bnad);
399 if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
400 BFI_COALESCING_TIMER_UNIT) {
401 bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
402 BFI_COALESCING_TIMER_UNIT;
404 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
405 bnad_rx_coalescing_timeo_set(bnad);
409 /* Add Tx Inter-pkt DMA count? */
411 spin_unlock_irqrestore(&bnad->bna_lock, flags);
413 mutex_unlock(&bnad->conf_mutex);
418 bnad_get_ringparam(struct net_device *netdev,
419 struct ethtool_ringparam *ringparam)
421 struct bnad *bnad = netdev_priv(netdev);
423 ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
424 ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
426 ringparam->rx_pending = bnad->rxq_depth;
427 ringparam->tx_pending = bnad->txq_depth;
431 bnad_set_ringparam(struct net_device *netdev,
432 struct ethtool_ringparam *ringparam)
434 int i, current_err, err = 0;
435 struct bnad *bnad = netdev_priv(netdev);
438 mutex_lock(&bnad->conf_mutex);
439 if (ringparam->rx_pending == bnad->rxq_depth &&
440 ringparam->tx_pending == bnad->txq_depth) {
441 mutex_unlock(&bnad->conf_mutex);
445 if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
446 ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
447 !BNA_POWER_OF_2(ringparam->rx_pending)) {
448 mutex_unlock(&bnad->conf_mutex);
451 if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
452 ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
453 !BNA_POWER_OF_2(ringparam->tx_pending)) {
454 mutex_unlock(&bnad->conf_mutex);
458 if (ringparam->rx_pending != bnad->rxq_depth) {
459 bnad->rxq_depth = ringparam->rx_pending;
460 if (!netif_running(netdev)) {
461 mutex_unlock(&bnad->conf_mutex);
465 for (i = 0; i < bnad->num_rx; i++) {
466 if (!bnad->rx_info[i].rx)
468 bnad_destroy_rx(bnad, i);
469 current_err = bnad_setup_rx(bnad, i);
470 if (current_err && !err)
474 if (!err && bnad->rx_info[0].rx) {
475 /* restore rx configuration */
476 bnad_restore_vlans(bnad, 0);
477 bnad_enable_default_bcast(bnad);
478 spin_lock_irqsave(&bnad->bna_lock, flags);
479 bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
480 spin_unlock_irqrestore(&bnad->bna_lock, flags);
481 bnad->cfg_flags &= ~(BNAD_CF_ALLMULTI |
483 bnad_set_rx_mode(netdev);
486 if (ringparam->tx_pending != bnad->txq_depth) {
487 bnad->txq_depth = ringparam->tx_pending;
488 if (!netif_running(netdev)) {
489 mutex_unlock(&bnad->conf_mutex);
493 for (i = 0; i < bnad->num_tx; i++) {
494 if (!bnad->tx_info[i].tx)
496 bnad_destroy_tx(bnad, i);
497 current_err = bnad_setup_tx(bnad, i);
498 if (current_err && !err)
503 mutex_unlock(&bnad->conf_mutex);
508 bnad_get_pauseparam(struct net_device *netdev,
509 struct ethtool_pauseparam *pauseparam)
511 struct bnad *bnad = netdev_priv(netdev);
513 pauseparam->autoneg = 0;
514 pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
515 pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
519 bnad_set_pauseparam(struct net_device *netdev,
520 struct ethtool_pauseparam *pauseparam)
522 struct bnad *bnad = netdev_priv(netdev);
523 struct bna_pause_config pause_config;
526 if (pauseparam->autoneg == AUTONEG_ENABLE)
529 mutex_lock(&bnad->conf_mutex);
530 if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
531 pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
532 pause_config.rx_pause = pauseparam->rx_pause;
533 pause_config.tx_pause = pauseparam->tx_pause;
534 spin_lock_irqsave(&bnad->bna_lock, flags);
535 bna_enet_pause_config(&bnad->bna.enet, &pause_config, NULL);
536 spin_unlock_irqrestore(&bnad->bna_lock, flags);
538 mutex_unlock(&bnad->conf_mutex);
543 bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
545 struct bnad *bnad = netdev_priv(netdev);
549 mutex_lock(&bnad->conf_mutex);
553 for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
554 BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
556 memcpy(string, bnad_net_stats_strings[i],
558 string += ETH_GSTRING_LEN;
560 bmap = bna_tx_rid_mask(&bnad->bna);
561 for (i = 0; bmap; i++) {
563 sprintf(string, "txf%d_ucast_octets", i);
564 string += ETH_GSTRING_LEN;
565 sprintf(string, "txf%d_ucast", i);
566 string += ETH_GSTRING_LEN;
567 sprintf(string, "txf%d_ucast_vlan", i);
568 string += ETH_GSTRING_LEN;
569 sprintf(string, "txf%d_mcast_octets", i);
570 string += ETH_GSTRING_LEN;
571 sprintf(string, "txf%d_mcast", i);
572 string += ETH_GSTRING_LEN;
573 sprintf(string, "txf%d_mcast_vlan", i);
574 string += ETH_GSTRING_LEN;
575 sprintf(string, "txf%d_bcast_octets", i);
576 string += ETH_GSTRING_LEN;
577 sprintf(string, "txf%d_bcast", i);
578 string += ETH_GSTRING_LEN;
579 sprintf(string, "txf%d_bcast_vlan", i);
580 string += ETH_GSTRING_LEN;
581 sprintf(string, "txf%d_errors", i);
582 string += ETH_GSTRING_LEN;
583 sprintf(string, "txf%d_filter_vlan", i);
584 string += ETH_GSTRING_LEN;
585 sprintf(string, "txf%d_filter_mac_sa", i);
586 string += ETH_GSTRING_LEN;
591 bmap = bna_rx_rid_mask(&bnad->bna);
592 for (i = 0; bmap; i++) {
594 sprintf(string, "rxf%d_ucast_octets", i);
595 string += ETH_GSTRING_LEN;
596 sprintf(string, "rxf%d_ucast", i);
597 string += ETH_GSTRING_LEN;
598 sprintf(string, "rxf%d_ucast_vlan", i);
599 string += ETH_GSTRING_LEN;
600 sprintf(string, "rxf%d_mcast_octets", i);
601 string += ETH_GSTRING_LEN;
602 sprintf(string, "rxf%d_mcast", i);
603 string += ETH_GSTRING_LEN;
604 sprintf(string, "rxf%d_mcast_vlan", i);
605 string += ETH_GSTRING_LEN;
606 sprintf(string, "rxf%d_bcast_octets", i);
607 string += ETH_GSTRING_LEN;
608 sprintf(string, "rxf%d_bcast", i);
609 string += ETH_GSTRING_LEN;
610 sprintf(string, "rxf%d_bcast_vlan", i);
611 string += ETH_GSTRING_LEN;
612 sprintf(string, "rxf%d_frame_drops", i);
613 string += ETH_GSTRING_LEN;
619 for (i = 0; i < bnad->num_rx; i++) {
620 if (!bnad->rx_info[i].rx)
622 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
623 sprintf(string, "cq%d_producer_index", q_num);
624 string += ETH_GSTRING_LEN;
625 sprintf(string, "cq%d_consumer_index", q_num);
626 string += ETH_GSTRING_LEN;
627 sprintf(string, "cq%d_hw_producer_index",
629 string += ETH_GSTRING_LEN;
630 sprintf(string, "cq%d_intr", q_num);
631 string += ETH_GSTRING_LEN;
632 sprintf(string, "cq%d_poll", q_num);
633 string += ETH_GSTRING_LEN;
634 sprintf(string, "cq%d_schedule", q_num);
635 string += ETH_GSTRING_LEN;
636 sprintf(string, "cq%d_keep_poll", q_num);
637 string += ETH_GSTRING_LEN;
638 sprintf(string, "cq%d_complete", q_num);
639 string += ETH_GSTRING_LEN;
645 for (i = 0; i < bnad->num_rx; i++) {
646 if (!bnad->rx_info[i].rx)
648 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
649 sprintf(string, "rxq%d_packets", q_num);
650 string += ETH_GSTRING_LEN;
651 sprintf(string, "rxq%d_bytes", q_num);
652 string += ETH_GSTRING_LEN;
653 sprintf(string, "rxq%d_packets_with_error",
655 string += ETH_GSTRING_LEN;
656 sprintf(string, "rxq%d_allocbuf_failed", q_num);
657 string += ETH_GSTRING_LEN;
658 sprintf(string, "rxq%d_producer_index", q_num);
659 string += ETH_GSTRING_LEN;
660 sprintf(string, "rxq%d_consumer_index", q_num);
661 string += ETH_GSTRING_LEN;
663 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
664 bnad->rx_info[i].rx_ctrl[j].ccb->
666 bnad->rx_info[i].rx_ctrl[j].ccb->
668 sprintf(string, "rxq%d_packets", q_num);
669 string += ETH_GSTRING_LEN;
670 sprintf(string, "rxq%d_bytes", q_num);
671 string += ETH_GSTRING_LEN;
673 "rxq%d_packets_with_error", q_num);
674 string += ETH_GSTRING_LEN;
675 sprintf(string, "rxq%d_allocbuf_failed",
677 string += ETH_GSTRING_LEN;
678 sprintf(string, "rxq%d_producer_index",
680 string += ETH_GSTRING_LEN;
681 sprintf(string, "rxq%d_consumer_index",
683 string += ETH_GSTRING_LEN;
690 for (i = 0; i < bnad->num_tx; i++) {
691 if (!bnad->tx_info[i].tx)
693 for (j = 0; j < bnad->num_txq_per_tx; j++) {
694 sprintf(string, "txq%d_packets", q_num);
695 string += ETH_GSTRING_LEN;
696 sprintf(string, "txq%d_bytes", q_num);
697 string += ETH_GSTRING_LEN;
698 sprintf(string, "txq%d_producer_index", q_num);
699 string += ETH_GSTRING_LEN;
700 sprintf(string, "txq%d_consumer_index", q_num);
701 string += ETH_GSTRING_LEN;
702 sprintf(string, "txq%d_hw_consumer_index",
704 string += ETH_GSTRING_LEN;
715 mutex_unlock(&bnad->conf_mutex);
719 bnad_get_stats_count_locked(struct net_device *netdev)
721 struct bnad *bnad = netdev_priv(netdev);
722 int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
725 bmap = bna_tx_rid_mask(&bnad->bna);
726 for (i = 0; bmap; i++) {
731 bmap = bna_rx_rid_mask(&bnad->bna);
732 for (i = 0; bmap; i++) {
737 count = BNAD_ETHTOOL_STATS_NUM +
738 txf_active_num * BNAD_NUM_TXF_COUNTERS +
739 rxf_active_num * BNAD_NUM_RXF_COUNTERS;
741 for (i = 0; i < bnad->num_rx; i++) {
742 if (!bnad->rx_info[i].rx)
744 count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
745 count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
746 for (j = 0; j < bnad->num_rxp_per_rx; j++)
747 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
748 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
749 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
750 count += BNAD_NUM_RXQ_COUNTERS;
753 for (i = 0; i < bnad->num_tx; i++) {
754 if (!bnad->tx_info[i].tx)
756 count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
762 bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
765 struct bna_rcb *rcb = NULL;
766 struct bna_tcb *tcb = NULL;
768 for (i = 0; i < bnad->num_rx; i++) {
769 if (!bnad->rx_info[i].rx)
771 for (j = 0; j < bnad->num_rxp_per_rx; j++)
772 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
773 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
774 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
775 buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
777 buf[bi++] = 0; /* ccb->consumer_index */
778 buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
779 ccb->hw_producer_index);
781 buf[bi++] = bnad->rx_info[i].
782 rx_ctrl[j].rx_intr_ctr;
783 buf[bi++] = bnad->rx_info[i].
784 rx_ctrl[j].rx_poll_ctr;
785 buf[bi++] = bnad->rx_info[i].
786 rx_ctrl[j].rx_schedule;
787 buf[bi++] = bnad->rx_info[i].
788 rx_ctrl[j].rx_keep_poll;
789 buf[bi++] = bnad->rx_info[i].
790 rx_ctrl[j].rx_complete;
793 for (i = 0; i < bnad->num_rx; i++) {
794 if (!bnad->rx_info[i].rx)
796 for (j = 0; j < bnad->num_rxp_per_rx; j++)
797 if (bnad->rx_info[i].rx_ctrl[j].ccb) {
798 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
799 bnad->rx_info[i].rx_ctrl[j].ccb->
801 rcb = bnad->rx_info[i].rx_ctrl[j].
803 buf[bi++] = rcb->rxq->rx_packets;
804 buf[bi++] = rcb->rxq->rx_bytes;
805 buf[bi++] = rcb->rxq->
806 rx_packets_with_error;
807 buf[bi++] = rcb->rxq->
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->producer_index;
824 buf[bi++] = rcb->consumer_index;
829 for (i = 0; i < bnad->num_tx; i++) {
830 if (!bnad->tx_info[i].tx)
832 for (j = 0; j < bnad->num_txq_per_tx; j++)
833 if (bnad->tx_info[i].tcb[j] &&
834 bnad->tx_info[i].tcb[j]->txq) {
835 tcb = bnad->tx_info[i].tcb[j];
836 buf[bi++] = tcb->txq->tx_packets;
837 buf[bi++] = tcb->txq->tx_bytes;
838 buf[bi++] = tcb->producer_index;
839 buf[bi++] = tcb->consumer_index;
840 buf[bi++] = *(tcb->hw_consumer_index);
848 bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
851 struct bnad *bnad = netdev_priv(netdev);
854 struct rtnl_link_stats64 *net_stats64;
858 mutex_lock(&bnad->conf_mutex);
859 if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
860 mutex_unlock(&bnad->conf_mutex);
865 * Used bna_lock to sync reads from bna_stats, which is written
866 * under the same lock
868 spin_lock_irqsave(&bnad->bna_lock, flags);
870 memset(buf, 0, stats->n_stats * sizeof(u64));
872 net_stats64 = (struct rtnl_link_stats64 *)buf;
873 bnad_netdev_qstats_fill(bnad, net_stats64);
874 bnad_netdev_hwstats_fill(bnad, net_stats64);
876 bi = sizeof(*net_stats64) / sizeof(u64);
878 /* Get netif_queue_stopped from stack */
879 bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
881 /* Fill driver stats into ethtool buffers */
882 stats64 = (u64 *)&bnad->stats.drv_stats;
883 for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
884 buf[bi++] = stats64[i];
886 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
887 stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
889 i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
892 buf[bi++] = stats64[i];
894 /* Fill txf stats into ethtool buffers */
895 bmap = bna_tx_rid_mask(&bnad->bna);
896 for (i = 0; bmap; i++) {
898 stats64 = (u64 *)&bnad->stats.bna_stats->
899 hw_stats.txf_stats[i];
900 for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
902 buf[bi++] = stats64[j];
907 /* Fill rxf stats into ethtool buffers */
908 bmap = bna_rx_rid_mask(&bnad->bna);
909 for (i = 0; bmap; i++) {
911 stats64 = (u64 *)&bnad->stats.bna_stats->
912 hw_stats.rxf_stats[i];
913 for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
915 buf[bi++] = stats64[j];
920 /* Fill per Q stats into ethtool buffers */
921 bi = bnad_per_q_stats_fill(bnad, buf, bi);
923 spin_unlock_irqrestore(&bnad->bna_lock, flags);
925 mutex_unlock(&bnad->conf_mutex);
929 bnad_get_sset_count(struct net_device *netdev, int sset)
933 return bnad_get_stats_count_locked(netdev);
940 bnad_get_flash_partition_by_offset(struct bnad *bnad, u32 offset,
943 struct bfa_flash_attr *flash_attr;
944 struct bnad_iocmd_comp fcomp;
945 u32 i, flash_part = 0, ret;
946 unsigned long flags = 0;
948 flash_attr = kzalloc(sizeof(struct bfa_flash_attr), GFP_KERNEL);
953 fcomp.comp_status = 0;
955 init_completion(&fcomp.comp);
956 spin_lock_irqsave(&bnad->bna_lock, flags);
957 ret = bfa_nw_flash_get_attr(&bnad->bna.flash, flash_attr,
958 bnad_cb_completion, &fcomp);
959 if (ret != BFA_STATUS_OK) {
960 spin_unlock_irqrestore(&bnad->bna_lock, flags);
964 spin_unlock_irqrestore(&bnad->bna_lock, flags);
965 wait_for_completion(&fcomp.comp);
966 ret = fcomp.comp_status;
968 /* Check for the flash type & base offset value */
969 if (ret == BFA_STATUS_OK) {
970 for (i = 0; i < flash_attr->npart; i++) {
971 if (offset >= flash_attr->part[i].part_off &&
972 offset < (flash_attr->part[i].part_off +
973 flash_attr->part[i].part_size)) {
974 flash_part = flash_attr->part[i].part_type;
975 *base_offset = flash_attr->part[i].part_off;
985 bnad_get_eeprom_len(struct net_device *netdev)
987 return BFA_TOTAL_FLASH_SIZE;
991 bnad_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
994 struct bnad *bnad = netdev_priv(netdev);
995 struct bnad_iocmd_comp fcomp;
996 u32 flash_part = 0, base_offset = 0;
997 unsigned long flags = 0;
1000 /* Check if the flash read request is valid */
1001 if (eeprom->magic != (bnad->pcidev->vendor |
1002 (bnad->pcidev->device << 16)))
1005 /* Query the flash partition based on the offset */
1006 flash_part = bnad_get_flash_partition_by_offset(bnad,
1007 eeprom->offset, &base_offset);
1008 if (flash_part == 0)
1012 fcomp.comp_status = 0;
1014 init_completion(&fcomp.comp);
1015 spin_lock_irqsave(&bnad->bna_lock, flags);
1016 ret = bfa_nw_flash_read_part(&bnad->bna.flash, flash_part,
1017 bnad->id, bytes, eeprom->len,
1018 eeprom->offset - base_offset,
1019 bnad_cb_completion, &fcomp);
1020 if (ret != BFA_STATUS_OK) {
1021 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1025 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1026 wait_for_completion(&fcomp.comp);
1027 ret = fcomp.comp_status;
1033 bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
1036 struct bnad *bnad = netdev_priv(netdev);
1037 struct bnad_iocmd_comp fcomp;
1038 u32 flash_part = 0, base_offset = 0;
1039 unsigned long flags = 0;
1042 /* Check if the flash update request is valid */
1043 if (eeprom->magic != (bnad->pcidev->vendor |
1044 (bnad->pcidev->device << 16)))
1047 /* Query the flash partition based on the offset */
1048 flash_part = bnad_get_flash_partition_by_offset(bnad,
1049 eeprom->offset, &base_offset);
1050 if (flash_part == 0)
1054 fcomp.comp_status = 0;
1056 init_completion(&fcomp.comp);
1057 spin_lock_irqsave(&bnad->bna_lock, flags);
1058 ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part,
1059 bnad->id, bytes, eeprom->len,
1060 eeprom->offset - base_offset,
1061 bnad_cb_completion, &fcomp);
1062 if (ret != BFA_STATUS_OK) {
1063 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1067 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1068 wait_for_completion(&fcomp.comp);
1069 ret = fcomp.comp_status;
1075 bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash)
1077 struct bnad *bnad = netdev_priv(netdev);
1078 struct bnad_iocmd_comp fcomp;
1079 const struct firmware *fw;
1082 ret = request_firmware(&fw, eflash->data, &bnad->pcidev->dev);
1084 pr_err("BNA: Can't locate firmware %s\n", eflash->data);
1089 fcomp.comp_status = 0;
1091 init_completion(&fcomp.comp);
1092 spin_lock_irq(&bnad->bna_lock);
1093 ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG,
1094 bnad->id, (u8 *)fw->data, fw->size, 0,
1095 bnad_cb_completion, &fcomp);
1096 if (ret != BFA_STATUS_OK) {
1097 pr_warn("BNA: Flash update failed with err: %d\n", ret);
1099 spin_unlock_irq(&bnad->bna_lock);
1103 spin_unlock_irq(&bnad->bna_lock);
1104 wait_for_completion(&fcomp.comp);
1105 if (fcomp.comp_status != BFA_STATUS_OK) {
1107 pr_warn("BNA: Firmware image update to flash failed with: %d\n",
1111 release_firmware(fw);
1115 static const struct ethtool_ops bnad_ethtool_ops = {
1116 .get_settings = bnad_get_settings,
1117 .set_settings = bnad_set_settings,
1118 .get_drvinfo = bnad_get_drvinfo,
1119 .get_wol = bnad_get_wol,
1120 .get_link = ethtool_op_get_link,
1121 .get_coalesce = bnad_get_coalesce,
1122 .set_coalesce = bnad_set_coalesce,
1123 .get_ringparam = bnad_get_ringparam,
1124 .set_ringparam = bnad_set_ringparam,
1125 .get_pauseparam = bnad_get_pauseparam,
1126 .set_pauseparam = bnad_set_pauseparam,
1127 .get_strings = bnad_get_strings,
1128 .get_ethtool_stats = bnad_get_ethtool_stats,
1129 .get_sset_count = bnad_get_sset_count,
1130 .get_eeprom_len = bnad_get_eeprom_len,
1131 .get_eeprom = bnad_get_eeprom,
1132 .set_eeprom = bnad_set_eeprom,
1133 .flash_device = bnad_flash_device,
1137 bnad_set_ethtool_ops(struct net_device *netdev)
1139 SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);