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 #define BNAD_ETHTOOL_STATS_NUM \
38 (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
39 sizeof(struct bnad_drv_stats) / sizeof(u64) + \
40 offsetof(struct bfi_enet_stats, rxf_stats[0]) / sizeof(u64))
42 static const char *bnad_net_stats_strings[BNAD_ETHTOOL_STATS_NUM] = {
64 "tx_heartbeat_errors",
72 "netif_queue_stopped",
82 "tx_skb_mss_too_long",
83 "tx_skb_tso_too_short",
85 "tx_skb_non_tso_too_long",
89 "tx_skb_headlen_too_long",
90 "tx_skb_headlen_zero",
92 "tx_skb_len_mismatch",
100 "rxp_info_alloc_failed",
101 "mbox_intr_disabled",
103 "tx_unmap_q_alloc_failed",
104 "rx_unmap_q_alloc_failed",
105 "rxbuf_alloc_failed",
113 "mac_frame_512_1023",
114 "mac_frame_1024_1518",
115 "mac_frame_1518_1522",
121 "mac_rx_control_frames",
123 "mac_rx_unknown_opcode",
124 "mac_rx_alignment_error",
125 "mac_rx_frame_length_error",
127 "mac_rx_carrier_sense_error",
140 "mac_tx_excessive_deferral",
141 "mac_tx_single_collision",
142 "mac_tx_muliple_collision",
143 "mac_tx_late_collision",
144 "mac_tx_excessive_collision",
145 "mac_tx_total_collision",
146 "mac_tx_pause_honored",
150 "mac_tx_control_frame",
163 "bpc_tx_zero_pause_0",
164 "bpc_tx_zero_pause_1",
165 "bpc_tx_zero_pause_2",
166 "bpc_tx_zero_pause_3",
167 "bpc_tx_zero_pause_4",
168 "bpc_tx_zero_pause_5",
169 "bpc_tx_zero_pause_6",
170 "bpc_tx_zero_pause_7",
171 "bpc_tx_first_pause_0",
172 "bpc_tx_first_pause_1",
173 "bpc_tx_first_pause_2",
174 "bpc_tx_first_pause_3",
175 "bpc_tx_first_pause_4",
176 "bpc_tx_first_pause_5",
177 "bpc_tx_first_pause_6",
178 "bpc_tx_first_pause_7",
188 "bpc_rx_zero_pause_0",
189 "bpc_rx_zero_pause_1",
190 "bpc_rx_zero_pause_2",
191 "bpc_rx_zero_pause_3",
192 "bpc_rx_zero_pause_4",
193 "bpc_rx_zero_pause_5",
194 "bpc_rx_zero_pause_6",
195 "bpc_rx_zero_pause_7",
196 "bpc_rx_first_pause_0",
197 "bpc_rx_first_pause_1",
198 "bpc_rx_first_pause_2",
199 "bpc_rx_first_pause_3",
200 "bpc_rx_first_pause_4",
201 "bpc_rx_first_pause_5",
202 "bpc_rx_first_pause_6",
203 "bpc_rx_first_pause_7",
207 "rad_rx_vlan_frames",
209 "rad_rx_ucast_octets",
212 "rad_rx_mcast_octets",
215 "rad_rx_bcast_octets",
221 "rlb_rad_rx_vlan_frames",
223 "rlb_rad_rx_ucast_octets",
224 "rlb_rad_rx_ucast_vlan",
226 "rlb_rad_rx_mcast_octets",
227 "rlb_rad_rx_mcast_vlan",
229 "rlb_rad_rx_bcast_octets",
230 "rlb_rad_rx_bcast_vlan",
233 "fc_rx_ucast_octets",
236 "fc_rx_mcast_octets",
239 "fc_rx_bcast_octets",
243 "fc_tx_ucast_octets",
246 "fc_tx_mcast_octets",
249 "fc_tx_bcast_octets",
252 "fc_tx_parity_errors",
254 "fc_tx_fid_parity_errors",
258 bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
260 cmd->supported = SUPPORTED_10000baseT_Full;
261 cmd->advertising = ADVERTISED_10000baseT_Full;
262 cmd->autoneg = AUTONEG_DISABLE;
263 cmd->supported |= SUPPORTED_FIBRE;
264 cmd->advertising |= ADVERTISED_FIBRE;
265 cmd->port = PORT_FIBRE;
266 cmd->phy_address = 0;
268 if (netif_carrier_ok(netdev)) {
269 ethtool_cmd_speed_set(cmd, SPEED_10000);
270 cmd->duplex = DUPLEX_FULL;
272 ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
273 cmd->duplex = DUPLEX_UNKNOWN;
275 cmd->transceiver = XCVR_EXTERNAL;
283 bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
285 /* 10G full duplex setting supported only */
286 if (cmd->autoneg == AUTONEG_ENABLE)
287 return -EOPNOTSUPP; else {
288 if ((ethtool_cmd_speed(cmd) == SPEED_10000)
289 && (cmd->duplex == DUPLEX_FULL))
297 bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
299 struct bnad *bnad = netdev_priv(netdev);
300 struct bfa_ioc_attr *ioc_attr;
303 strlcpy(drvinfo->driver, BNAD_NAME, sizeof(drvinfo->driver));
304 strlcpy(drvinfo->version, BNAD_VERSION, sizeof(drvinfo->version));
306 ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
308 spin_lock_irqsave(&bnad->bna_lock, flags);
309 bfa_nw_ioc_get_attr(&bnad->bna.ioceth.ioc, ioc_attr);
310 spin_unlock_irqrestore(&bnad->bna_lock, flags);
312 strlcpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
313 sizeof(drvinfo->fw_version));
317 strlcpy(drvinfo->bus_info, pci_name(bnad->pcidev),
318 sizeof(drvinfo->bus_info));
322 bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
324 wolinfo->supported = 0;
325 wolinfo->wolopts = 0;
329 bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
331 struct bnad *bnad = netdev_priv(netdev);
334 /* Lock rqd. to access bnad->bna_lock */
335 spin_lock_irqsave(&bnad->bna_lock, flags);
336 coalesce->use_adaptive_rx_coalesce =
337 (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
338 spin_unlock_irqrestore(&bnad->bna_lock, flags);
340 coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
341 BFI_COALESCING_TIMER_UNIT;
342 coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
343 BFI_COALESCING_TIMER_UNIT;
344 coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
350 bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
352 struct bnad *bnad = netdev_priv(netdev);
356 if (coalesce->rx_coalesce_usecs == 0 ||
357 coalesce->rx_coalesce_usecs >
358 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
361 if (coalesce->tx_coalesce_usecs == 0 ||
362 coalesce->tx_coalesce_usecs >
363 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
366 mutex_lock(&bnad->conf_mutex);
368 * Do not need to store rx_coalesce_usecs here
369 * Every time DIM is disabled, we can get it from the
372 spin_lock_irqsave(&bnad->bna_lock, flags);
373 if (coalesce->use_adaptive_rx_coalesce) {
374 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
375 bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
376 bnad_dim_timer_start(bnad);
379 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
380 bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
381 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
382 test_bit(BNAD_RF_DIM_TIMER_RUNNING,
384 clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
388 spin_unlock_irqrestore(&bnad->bna_lock, flags);
390 del_timer_sync(&bnad->dim_timer);
391 spin_lock_irqsave(&bnad->bna_lock, flags);
392 bnad_rx_coalescing_timeo_set(bnad);
395 if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
396 BFI_COALESCING_TIMER_UNIT) {
397 bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
398 BFI_COALESCING_TIMER_UNIT;
399 bnad_tx_coalescing_timeo_set(bnad);
402 if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
403 BFI_COALESCING_TIMER_UNIT) {
404 bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
405 BFI_COALESCING_TIMER_UNIT;
407 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
408 bnad_rx_coalescing_timeo_set(bnad);
412 /* Add Tx Inter-pkt DMA count? */
414 spin_unlock_irqrestore(&bnad->bna_lock, flags);
416 mutex_unlock(&bnad->conf_mutex);
421 bnad_get_ringparam(struct net_device *netdev,
422 struct ethtool_ringparam *ringparam)
424 struct bnad *bnad = netdev_priv(netdev);
426 ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
427 ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
429 ringparam->rx_pending = bnad->rxq_depth;
430 ringparam->tx_pending = bnad->txq_depth;
434 bnad_set_ringparam(struct net_device *netdev,
435 struct ethtool_ringparam *ringparam)
437 int i, current_err, err = 0;
438 struct bnad *bnad = netdev_priv(netdev);
441 mutex_lock(&bnad->conf_mutex);
442 if (ringparam->rx_pending == bnad->rxq_depth &&
443 ringparam->tx_pending == bnad->txq_depth) {
444 mutex_unlock(&bnad->conf_mutex);
448 if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
449 ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
450 !is_power_of_2(ringparam->rx_pending)) {
451 mutex_unlock(&bnad->conf_mutex);
454 if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
455 ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
456 !is_power_of_2(ringparam->tx_pending)) {
457 mutex_unlock(&bnad->conf_mutex);
461 if (ringparam->rx_pending != bnad->rxq_depth) {
462 bnad->rxq_depth = ringparam->rx_pending;
463 if (!netif_running(netdev)) {
464 mutex_unlock(&bnad->conf_mutex);
468 for (i = 0; i < bnad->num_rx; i++) {
469 if (!bnad->rx_info[i].rx)
471 bnad_destroy_rx(bnad, i);
472 current_err = bnad_setup_rx(bnad, i);
473 if (current_err && !err)
477 if (!err && bnad->rx_info[0].rx) {
478 /* restore rx configuration */
479 bnad_restore_vlans(bnad, 0);
480 bnad_enable_default_bcast(bnad);
481 spin_lock_irqsave(&bnad->bna_lock, flags);
482 bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
483 spin_unlock_irqrestore(&bnad->bna_lock, flags);
484 bnad->cfg_flags &= ~(BNAD_CF_ALLMULTI |
486 bnad_set_rx_mode(netdev);
489 if (ringparam->tx_pending != bnad->txq_depth) {
490 bnad->txq_depth = ringparam->tx_pending;
491 if (!netif_running(netdev)) {
492 mutex_unlock(&bnad->conf_mutex);
496 for (i = 0; i < bnad->num_tx; i++) {
497 if (!bnad->tx_info[i].tx)
499 bnad_destroy_tx(bnad, i);
500 current_err = bnad_setup_tx(bnad, i);
501 if (current_err && !err)
506 mutex_unlock(&bnad->conf_mutex);
511 bnad_get_pauseparam(struct net_device *netdev,
512 struct ethtool_pauseparam *pauseparam)
514 struct bnad *bnad = netdev_priv(netdev);
516 pauseparam->autoneg = 0;
517 pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
518 pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
522 bnad_set_pauseparam(struct net_device *netdev,
523 struct ethtool_pauseparam *pauseparam)
525 struct bnad *bnad = netdev_priv(netdev);
526 struct bna_pause_config pause_config;
529 if (pauseparam->autoneg == AUTONEG_ENABLE)
532 mutex_lock(&bnad->conf_mutex);
533 if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
534 pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
535 pause_config.rx_pause = pauseparam->rx_pause;
536 pause_config.tx_pause = pauseparam->tx_pause;
537 spin_lock_irqsave(&bnad->bna_lock, flags);
538 bna_enet_pause_config(&bnad->bna.enet, &pause_config);
539 spin_unlock_irqrestore(&bnad->bna_lock, flags);
541 mutex_unlock(&bnad->conf_mutex);
546 bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
548 struct bnad *bnad = netdev_priv(netdev);
552 mutex_lock(&bnad->conf_mutex);
556 for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
557 BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
559 memcpy(string, bnad_net_stats_strings[i],
561 string += ETH_GSTRING_LEN;
563 bmap = bna_tx_rid_mask(&bnad->bna);
564 for (i = 0; bmap; i++) {
566 sprintf(string, "txf%d_ucast_octets", i);
567 string += ETH_GSTRING_LEN;
568 sprintf(string, "txf%d_ucast", i);
569 string += ETH_GSTRING_LEN;
570 sprintf(string, "txf%d_ucast_vlan", i);
571 string += ETH_GSTRING_LEN;
572 sprintf(string, "txf%d_mcast_octets", i);
573 string += ETH_GSTRING_LEN;
574 sprintf(string, "txf%d_mcast", i);
575 string += ETH_GSTRING_LEN;
576 sprintf(string, "txf%d_mcast_vlan", i);
577 string += ETH_GSTRING_LEN;
578 sprintf(string, "txf%d_bcast_octets", i);
579 string += ETH_GSTRING_LEN;
580 sprintf(string, "txf%d_bcast", i);
581 string += ETH_GSTRING_LEN;
582 sprintf(string, "txf%d_bcast_vlan", i);
583 string += ETH_GSTRING_LEN;
584 sprintf(string, "txf%d_errors", i);
585 string += ETH_GSTRING_LEN;
586 sprintf(string, "txf%d_filter_vlan", i);
587 string += ETH_GSTRING_LEN;
588 sprintf(string, "txf%d_filter_mac_sa", i);
589 string += ETH_GSTRING_LEN;
594 bmap = bna_rx_rid_mask(&bnad->bna);
595 for (i = 0; bmap; i++) {
597 sprintf(string, "rxf%d_ucast_octets", i);
598 string += ETH_GSTRING_LEN;
599 sprintf(string, "rxf%d_ucast", i);
600 string += ETH_GSTRING_LEN;
601 sprintf(string, "rxf%d_ucast_vlan", i);
602 string += ETH_GSTRING_LEN;
603 sprintf(string, "rxf%d_mcast_octets", i);
604 string += ETH_GSTRING_LEN;
605 sprintf(string, "rxf%d_mcast", i);
606 string += ETH_GSTRING_LEN;
607 sprintf(string, "rxf%d_mcast_vlan", i);
608 string += ETH_GSTRING_LEN;
609 sprintf(string, "rxf%d_bcast_octets", i);
610 string += ETH_GSTRING_LEN;
611 sprintf(string, "rxf%d_bcast", i);
612 string += ETH_GSTRING_LEN;
613 sprintf(string, "rxf%d_bcast_vlan", i);
614 string += ETH_GSTRING_LEN;
615 sprintf(string, "rxf%d_frame_drops", i);
616 string += ETH_GSTRING_LEN;
622 for (i = 0; i < bnad->num_rx; i++) {
623 if (!bnad->rx_info[i].rx)
625 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
626 sprintf(string, "cq%d_producer_index", q_num);
627 string += ETH_GSTRING_LEN;
628 sprintf(string, "cq%d_consumer_index", q_num);
629 string += ETH_GSTRING_LEN;
630 sprintf(string, "cq%d_hw_producer_index",
632 string += ETH_GSTRING_LEN;
633 sprintf(string, "cq%d_intr", q_num);
634 string += ETH_GSTRING_LEN;
635 sprintf(string, "cq%d_poll", q_num);
636 string += ETH_GSTRING_LEN;
637 sprintf(string, "cq%d_schedule", q_num);
638 string += ETH_GSTRING_LEN;
639 sprintf(string, "cq%d_keep_poll", q_num);
640 string += ETH_GSTRING_LEN;
641 sprintf(string, "cq%d_complete", q_num);
642 string += ETH_GSTRING_LEN;
648 for (i = 0; i < bnad->num_rx; i++) {
649 if (!bnad->rx_info[i].rx)
651 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
652 sprintf(string, "rxq%d_packets", q_num);
653 string += ETH_GSTRING_LEN;
654 sprintf(string, "rxq%d_bytes", q_num);
655 string += ETH_GSTRING_LEN;
656 sprintf(string, "rxq%d_packets_with_error",
658 string += ETH_GSTRING_LEN;
659 sprintf(string, "rxq%d_allocbuf_failed", q_num);
660 string += ETH_GSTRING_LEN;
661 sprintf(string, "rxq%d_mapbuf_failed", q_num);
662 string += ETH_GSTRING_LEN;
663 sprintf(string, "rxq%d_producer_index", q_num);
664 string += ETH_GSTRING_LEN;
665 sprintf(string, "rxq%d_consumer_index", q_num);
666 string += ETH_GSTRING_LEN;
668 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
669 bnad->rx_info[i].rx_ctrl[j].ccb->
671 bnad->rx_info[i].rx_ctrl[j].ccb->
673 sprintf(string, "rxq%d_packets", q_num);
674 string += ETH_GSTRING_LEN;
675 sprintf(string, "rxq%d_bytes", q_num);
676 string += ETH_GSTRING_LEN;
678 "rxq%d_packets_with_error", q_num);
679 string += ETH_GSTRING_LEN;
680 sprintf(string, "rxq%d_allocbuf_failed",
682 string += ETH_GSTRING_LEN;
683 sprintf(string, "rxq%d_mapbuf_failed",
685 string += ETH_GSTRING_LEN;
686 sprintf(string, "rxq%d_producer_index",
688 string += ETH_GSTRING_LEN;
689 sprintf(string, "rxq%d_consumer_index",
691 string += ETH_GSTRING_LEN;
698 for (i = 0; i < bnad->num_tx; i++) {
699 if (!bnad->tx_info[i].tx)
701 for (j = 0; j < bnad->num_txq_per_tx; j++) {
702 sprintf(string, "txq%d_packets", q_num);
703 string += ETH_GSTRING_LEN;
704 sprintf(string, "txq%d_bytes", q_num);
705 string += ETH_GSTRING_LEN;
706 sprintf(string, "txq%d_producer_index", q_num);
707 string += ETH_GSTRING_LEN;
708 sprintf(string, "txq%d_consumer_index", q_num);
709 string += ETH_GSTRING_LEN;
710 sprintf(string, "txq%d_hw_consumer_index",
712 string += ETH_GSTRING_LEN;
723 mutex_unlock(&bnad->conf_mutex);
727 bnad_get_stats_count_locked(struct net_device *netdev)
729 struct bnad *bnad = netdev_priv(netdev);
730 int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
733 bmap = bna_tx_rid_mask(&bnad->bna);
734 for (i = 0; bmap; i++) {
739 bmap = bna_rx_rid_mask(&bnad->bna);
740 for (i = 0; bmap; i++) {
745 count = BNAD_ETHTOOL_STATS_NUM +
746 txf_active_num * BNAD_NUM_TXF_COUNTERS +
747 rxf_active_num * BNAD_NUM_RXF_COUNTERS;
749 for (i = 0; i < bnad->num_rx; i++) {
750 if (!bnad->rx_info[i].rx)
752 count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
753 count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
754 for (j = 0; j < bnad->num_rxp_per_rx; j++)
755 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
756 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
757 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
758 count += BNAD_NUM_RXQ_COUNTERS;
761 for (i = 0; i < bnad->num_tx; i++) {
762 if (!bnad->tx_info[i].tx)
764 count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
770 bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
773 struct bna_rcb *rcb = NULL;
774 struct bna_tcb *tcb = NULL;
776 for (i = 0; i < bnad->num_rx; i++) {
777 if (!bnad->rx_info[i].rx)
779 for (j = 0; j < bnad->num_rxp_per_rx; j++)
780 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
781 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
782 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
783 buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
785 buf[bi++] = 0; /* ccb->consumer_index */
786 buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
787 ccb->hw_producer_index);
789 buf[bi++] = bnad->rx_info[i].
790 rx_ctrl[j].rx_intr_ctr;
791 buf[bi++] = bnad->rx_info[i].
792 rx_ctrl[j].rx_poll_ctr;
793 buf[bi++] = bnad->rx_info[i].
794 rx_ctrl[j].rx_schedule;
795 buf[bi++] = bnad->rx_info[i].
796 rx_ctrl[j].rx_keep_poll;
797 buf[bi++] = bnad->rx_info[i].
798 rx_ctrl[j].rx_complete;
801 for (i = 0; i < bnad->num_rx; i++) {
802 if (!bnad->rx_info[i].rx)
804 for (j = 0; j < bnad->num_rxp_per_rx; j++)
805 if (bnad->rx_info[i].rx_ctrl[j].ccb) {
806 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
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;
821 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
822 bnad->rx_info[i].rx_ctrl[j].ccb->
824 rcb = bnad->rx_info[i].rx_ctrl[j].
826 buf[bi++] = rcb->rxq->rx_packets;
827 buf[bi++] = rcb->rxq->rx_bytes;
828 buf[bi++] = rcb->rxq->
829 rx_packets_with_error;
830 buf[bi++] = rcb->rxq->
832 buf[bi++] = rcb->rxq->rxbuf_map_failed;
833 buf[bi++] = rcb->producer_index;
834 buf[bi++] = rcb->consumer_index;
839 for (i = 0; i < bnad->num_tx; i++) {
840 if (!bnad->tx_info[i].tx)
842 for (j = 0; j < bnad->num_txq_per_tx; j++)
843 if (bnad->tx_info[i].tcb[j] &&
844 bnad->tx_info[i].tcb[j]->txq) {
845 tcb = bnad->tx_info[i].tcb[j];
846 buf[bi++] = tcb->txq->tx_packets;
847 buf[bi++] = tcb->txq->tx_bytes;
848 buf[bi++] = tcb->producer_index;
849 buf[bi++] = tcb->consumer_index;
850 buf[bi++] = *(tcb->hw_consumer_index);
858 bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
861 struct bnad *bnad = netdev_priv(netdev);
864 struct rtnl_link_stats64 *net_stats64;
868 mutex_lock(&bnad->conf_mutex);
869 if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
870 mutex_unlock(&bnad->conf_mutex);
875 * Used bna_lock to sync reads from bna_stats, which is written
876 * under the same lock
878 spin_lock_irqsave(&bnad->bna_lock, flags);
880 memset(buf, 0, stats->n_stats * sizeof(u64));
882 net_stats64 = (struct rtnl_link_stats64 *)buf;
883 bnad_netdev_qstats_fill(bnad, net_stats64);
884 bnad_netdev_hwstats_fill(bnad, net_stats64);
886 bi = sizeof(*net_stats64) / sizeof(u64);
888 /* Get netif_queue_stopped from stack */
889 bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
891 /* Fill driver stats into ethtool buffers */
892 stats64 = (u64 *)&bnad->stats.drv_stats;
893 for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
894 buf[bi++] = stats64[i];
896 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
897 stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
899 i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
902 buf[bi++] = stats64[i];
904 /* Fill txf stats into ethtool buffers */
905 bmap = bna_tx_rid_mask(&bnad->bna);
906 for (i = 0; bmap; i++) {
908 stats64 = (u64 *)&bnad->stats.bna_stats->
909 hw_stats.txf_stats[i];
910 for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
912 buf[bi++] = stats64[j];
917 /* Fill rxf stats into ethtool buffers */
918 bmap = bna_rx_rid_mask(&bnad->bna);
919 for (i = 0; bmap; i++) {
921 stats64 = (u64 *)&bnad->stats.bna_stats->
922 hw_stats.rxf_stats[i];
923 for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
925 buf[bi++] = stats64[j];
930 /* Fill per Q stats into ethtool buffers */
931 bi = bnad_per_q_stats_fill(bnad, buf, bi);
933 spin_unlock_irqrestore(&bnad->bna_lock, flags);
935 mutex_unlock(&bnad->conf_mutex);
939 bnad_get_sset_count(struct net_device *netdev, int sset)
943 return bnad_get_stats_count_locked(netdev);
950 bnad_get_flash_partition_by_offset(struct bnad *bnad, u32 offset,
953 struct bfa_flash_attr *flash_attr;
954 struct bnad_iocmd_comp fcomp;
955 u32 i, flash_part = 0, ret;
956 unsigned long flags = 0;
958 flash_attr = kzalloc(sizeof(struct bfa_flash_attr), GFP_KERNEL);
963 fcomp.comp_status = 0;
965 init_completion(&fcomp.comp);
966 spin_lock_irqsave(&bnad->bna_lock, flags);
967 ret = bfa_nw_flash_get_attr(&bnad->bna.flash, flash_attr,
968 bnad_cb_completion, &fcomp);
969 if (ret != BFA_STATUS_OK) {
970 spin_unlock_irqrestore(&bnad->bna_lock, flags);
974 spin_unlock_irqrestore(&bnad->bna_lock, flags);
975 wait_for_completion(&fcomp.comp);
976 ret = fcomp.comp_status;
978 /* Check for the flash type & base offset value */
979 if (ret == BFA_STATUS_OK) {
980 for (i = 0; i < flash_attr->npart; i++) {
981 if (offset >= flash_attr->part[i].part_off &&
982 offset < (flash_attr->part[i].part_off +
983 flash_attr->part[i].part_size)) {
984 flash_part = flash_attr->part[i].part_type;
985 *base_offset = flash_attr->part[i].part_off;
995 bnad_get_eeprom_len(struct net_device *netdev)
997 return BFA_TOTAL_FLASH_SIZE;
1001 bnad_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
1004 struct bnad *bnad = netdev_priv(netdev);
1005 struct bnad_iocmd_comp fcomp;
1006 u32 flash_part = 0, base_offset = 0;
1007 unsigned long flags = 0;
1010 /* Fill the magic value */
1011 eeprom->magic = bnad->pcidev->vendor | (bnad->pcidev->device << 16);
1013 /* Query the flash partition based on the offset */
1014 flash_part = bnad_get_flash_partition_by_offset(bnad,
1015 eeprom->offset, &base_offset);
1016 if (flash_part == 0)
1020 fcomp.comp_status = 0;
1022 init_completion(&fcomp.comp);
1023 spin_lock_irqsave(&bnad->bna_lock, flags);
1024 ret = bfa_nw_flash_read_part(&bnad->bna.flash, flash_part,
1025 bnad->id, bytes, eeprom->len,
1026 eeprom->offset - base_offset,
1027 bnad_cb_completion, &fcomp);
1028 if (ret != BFA_STATUS_OK) {
1029 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1033 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1034 wait_for_completion(&fcomp.comp);
1035 ret = fcomp.comp_status;
1041 bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
1044 struct bnad *bnad = netdev_priv(netdev);
1045 struct bnad_iocmd_comp fcomp;
1046 u32 flash_part = 0, base_offset = 0;
1047 unsigned long flags = 0;
1050 /* Check if the flash update request is valid */
1051 if (eeprom->magic != (bnad->pcidev->vendor |
1052 (bnad->pcidev->device << 16)))
1055 /* Query the flash partition based on the offset */
1056 flash_part = bnad_get_flash_partition_by_offset(bnad,
1057 eeprom->offset, &base_offset);
1058 if (flash_part == 0)
1062 fcomp.comp_status = 0;
1064 init_completion(&fcomp.comp);
1065 spin_lock_irqsave(&bnad->bna_lock, flags);
1066 ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part,
1067 bnad->id, bytes, eeprom->len,
1068 eeprom->offset - base_offset,
1069 bnad_cb_completion, &fcomp);
1070 if (ret != BFA_STATUS_OK) {
1071 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1075 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1076 wait_for_completion(&fcomp.comp);
1077 ret = fcomp.comp_status;
1083 bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash)
1085 struct bnad *bnad = netdev_priv(netdev);
1086 struct bnad_iocmd_comp fcomp;
1087 const struct firmware *fw;
1090 ret = request_firmware(&fw, eflash->data, &bnad->pcidev->dev);
1092 netdev_err(netdev, "can't load firmware %s\n", eflash->data);
1097 fcomp.comp_status = 0;
1099 init_completion(&fcomp.comp);
1100 spin_lock_irq(&bnad->bna_lock);
1101 ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG,
1102 bnad->id, (u8 *)fw->data, fw->size, 0,
1103 bnad_cb_completion, &fcomp);
1104 if (ret != BFA_STATUS_OK) {
1105 netdev_warn(netdev, "flash update failed with err=%d\n", ret);
1107 spin_unlock_irq(&bnad->bna_lock);
1111 spin_unlock_irq(&bnad->bna_lock);
1112 wait_for_completion(&fcomp.comp);
1113 if (fcomp.comp_status != BFA_STATUS_OK) {
1116 "firmware image update failed with err=%d\n",
1120 release_firmware(fw);
1124 static const struct ethtool_ops bnad_ethtool_ops = {
1125 .get_settings = bnad_get_settings,
1126 .set_settings = bnad_set_settings,
1127 .get_drvinfo = bnad_get_drvinfo,
1128 .get_wol = bnad_get_wol,
1129 .get_link = ethtool_op_get_link,
1130 .get_coalesce = bnad_get_coalesce,
1131 .set_coalesce = bnad_set_coalesce,
1132 .get_ringparam = bnad_get_ringparam,
1133 .set_ringparam = bnad_set_ringparam,
1134 .get_pauseparam = bnad_get_pauseparam,
1135 .set_pauseparam = bnad_set_pauseparam,
1136 .get_strings = bnad_get_strings,
1137 .get_ethtool_stats = bnad_get_ethtool_stats,
1138 .get_sset_count = bnad_get_sset_count,
1139 .get_eeprom_len = bnad_get_eeprom_len,
1140 .get_eeprom = bnad_get_eeprom,
1141 .set_eeprom = bnad_set_eeprom,
1142 .flash_device = bnad_flash_device,
1143 .get_ts_info = ethtool_op_get_ts_info,
1147 bnad_set_ethtool_ops(struct net_device *netdev)
1149 netdev->ethtool_ops = &bnad_ethtool_ops;