21 #include <linux/netdevice.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))
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",
264 if (netif_carrier_ok(netdev)) {
268 ethtool_cmd_speed_set(cmd, -1);
295 struct bnad *
bnad = netdev_priv(netdev);
302 ioc_attr = kzalloc(
sizeof(*ioc_attr),
GFP_KERNEL);
306 spin_unlock_irqrestore(&bnad->bna_lock, flags);
327 struct bnad *bnad = netdev_priv(netdev);
334 spin_unlock_irqrestore(&bnad->bna_lock, flags);
348 struct bnad *bnad = netdev_priv(netdev);
384 spin_unlock_irqrestore(&bnad->bna_lock, flags);
392 BFI_COALESCING_TIMER_UNIT) {
399 BFI_COALESCING_TIMER_UNIT) {
410 spin_unlock_irqrestore(&bnad->bna_lock, flags);
420 struct bnad *bnad = netdev_priv(netdev);
433 int i, current_err,
err = 0;
434 struct bnad *bnad = netdev_priv(netdev);
459 if (!netif_running(netdev)) {
464 for (i = 0; i < bnad->
num_rx; i++) {
469 if (current_err && !err)
473 if (!err && bnad->
rx_info[0].rx) {
479 spin_unlock_irqrestore(&bnad->bna_lock, flags);
487 if (!netif_running(netdev)) {
492 for (i = 0; i < bnad->
num_tx; i++) {
497 if (current_err && !err)
507 bnad_get_pauseparam(
struct net_device *netdev,
510 struct bnad *bnad = netdev_priv(netdev);
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,
521 struct bnad *bnad = netdev_priv(netdev);
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;
535 spin_unlock_irqrestore(&bnad->bna_lock, flags);
544 struct bnad *bnad = netdev_priv(netdev);
555 memcpy(
string, bnad_net_stats_strings[i],
560 for (i = 0;
bmap; i++) {
562 sprintf(
string,
"txf%d_ucast_octets", i);
564 sprintf(
string,
"txf%d_ucast", i);
566 sprintf(
string,
"txf%d_ucast_vlan", i);
568 sprintf(
string,
"txf%d_mcast_octets", i);
570 sprintf(
string,
"txf%d_mcast", i);
572 sprintf(
string,
"txf%d_mcast_vlan", i);
574 sprintf(
string,
"txf%d_bcast_octets", i);
576 sprintf(
string,
"txf%d_bcast", i);
578 sprintf(
string,
"txf%d_bcast_vlan", i);
580 sprintf(
string,
"txf%d_errors", i);
582 sprintf(
string,
"txf%d_filter_vlan", i);
584 sprintf(
string,
"txf%d_filter_mac_sa", i);
591 for (i = 0;
bmap; i++) {
593 sprintf(
string,
"rxf%d_ucast_octets", i);
595 sprintf(
string,
"rxf%d_ucast", i);
597 sprintf(
string,
"rxf%d_ucast_vlan", i);
599 sprintf(
string,
"rxf%d_mcast_octets", i);
601 sprintf(
string,
"rxf%d_mcast", i);
603 sprintf(
string,
"rxf%d_mcast_vlan", i);
605 sprintf(
string,
"rxf%d_bcast_octets", i);
607 sprintf(
string,
"rxf%d_bcast", i);
609 sprintf(
string,
"rxf%d_bcast_vlan", i);
611 sprintf(
string,
"rxf%d_frame_drops", i);
618 for (i = 0; i < bnad->
num_rx; i++) {
622 sprintf(
string,
"cq%d_producer_index", q_num);
624 sprintf(
string,
"cq%d_consumer_index", q_num);
626 sprintf(
string,
"cq%d_hw_producer_index",
629 sprintf(
string,
"cq%d_intr", q_num);
631 sprintf(
string,
"cq%d_poll", q_num);
633 sprintf(
string,
"cq%d_schedule", q_num);
635 sprintf(
string,
"cq%d_keep_poll", q_num);
637 sprintf(
string,
"cq%d_complete", q_num);
644 for (i = 0; i < bnad->
num_rx; i++) {
648 sprintf(
string,
"rxq%d_packets", q_num);
650 sprintf(
string,
"rxq%d_bytes", q_num);
652 sprintf(
string,
"rxq%d_packets_with_error",
655 sprintf(
string,
"rxq%d_allocbuf_failed", q_num);
657 sprintf(
string,
"rxq%d_producer_index", q_num);
659 sprintf(
string,
"rxq%d_consumer_index", q_num);
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);
669 sprintf(
string,
"rxq%d_bytes", q_num);
672 "rxq%d_packets_with_error", q_num);
674 sprintf(
string,
"rxq%d_allocbuf_failed",
677 sprintf(
string,
"rxq%d_producer_index",
680 sprintf(
string,
"rxq%d_consumer_index",
689 for (i = 0; i < bnad->
num_tx; i++) {
693 sprintf(
string,
"txq%d_packets", q_num);
695 sprintf(
string,
"txq%d_bytes", q_num);
697 sprintf(
string,
"txq%d_producer_index", q_num);
699 sprintf(
string,
"txq%d_consumer_index", q_num);
701 sprintf(
string,
"txq%d_hw_consumer_index",
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;
725 for (i = 0;
bmap; i++) {
731 for (i = 0;
bmap; i++) {
736 count = BNAD_ETHTOOL_STATS_NUM +
740 for (i = 0; i < bnad->
num_rx; i++) {
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)
752 for (i = 0; i < bnad->
num_tx; i++) {
761 bnad_per_q_stats_fill(
struct bnad *bnad,
u64 *
buf,
int bi)
767 for (i = 0; i < bnad->
num_rx; i++) {
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) {
777 buf[bi++] = *(bnad->
rx_info[
i].rx_ctrl[
j].
778 ccb->hw_producer_index);
781 rx_ctrl[
j].rx_intr_ctr;
783 rx_ctrl[
j].rx_poll_ctr;
785 rx_ctrl[
j].rx_schedule;
787 rx_ctrl[
j].rx_keep_poll;
789 rx_ctrl[
j].rx_complete;
792 for (i = 0; i < bnad->
num_rx; i++) {
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->
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->
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++) {
833 bnad->
tx_info[i].tcb[j]->txq) {
835 buf[bi++] = tcb->
txq->tx_packets;
836 buf[bi++] = tcb->
txq->tx_bytes;
850 struct bnad *bnad = netdev_priv(netdev);
858 if (bnad_get_stats_count_locked(netdev) != stats->
n_stats) {
875 bi =
sizeof(*net_stats64) /
sizeof(
u64);
878 bnad->
stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
881 stats64 = (
u64 *)&bnad->
stats.drv_stats;
883 buf[bi++] = stats64[i];
886 stats64 = (
u64 *) &bnad->
stats.bna_stats->hw_stats;
891 buf[bi++] = stats64[i];
895 for (i = 0;
bmap; i++) {
897 stats64 = (
u64 *)&bnad->
stats.bna_stats->
898 hw_stats.txf_stats[i];
901 buf[bi++] = stats64[j];
908 for (i = 0;
bmap; i++) {
910 stats64 = (
u64 *)&bnad->
stats.bna_stats->
911 hw_stats.rxf_stats[i];
914 buf[bi++] = stats64[j];
920 bi = bnad_per_q_stats_fill(bnad, buf, bi);
922 spin_unlock_irqrestore(&bnad->bna_lock, flags);
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,
945 unsigned long flags = 0;
952 fcomp.comp_status = 0;
954 init_completion(&fcomp.comp);
959 spin_unlock_irqrestore(&bnad->bna_lock, flags);
963 spin_unlock_irqrestore(&bnad->bna_lock, flags);
965 ret = fcomp.comp_status;
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)
993 struct bnad *bnad = netdev_priv(netdev);
995 u32 flash_part = 0, base_offset = 0;
996 unsigned long flags = 0;
1001 (bnad->
pcidev->device << 16)))
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);
1016 bnad->
id, bytes, eeprom->
len,
1017 eeprom->
offset - base_offset,
1020 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1024 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1026 ret = fcomp.comp_status;
1035 struct bnad *bnad = netdev_priv(netdev);
1037 u32 flash_part = 0, base_offset = 0;
1038 unsigned long flags = 0;
1043 (bnad->
pcidev->device << 16)))
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);
1058 bnad->
id, bytes, eeprom->
len,
1059 eeprom->
offset - base_offset,
1062 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1066 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1068 ret = fcomp.comp_status;
1076 struct bnad *bnad = netdev_priv(netdev);
1083 pr_err(
"BNA: Can't locate firmware %s\n", eflash->
data);
1088 fcomp.comp_status = 0;
1090 init_completion(&fcomp.comp);
1091 spin_lock_irq(&bnad->bna_lock);
1096 pr_warn(
"BNA: Flash update failed with err: %d\n", ret);
1098 spin_unlock_irq(&bnad->bna_lock);
1102 spin_unlock_irq(&bnad->bna_lock);
1106 pr_warn(
"BNA: Firmware image update to flash failed with: %d\n",
1114 static const struct ethtool_ops bnad_ethtool_ops = {
1115 .get_settings = bnad_get_settings,
1116 .set_settings = bnad_set_settings,
1117 .get_drvinfo = bnad_get_drvinfo,
1118 .get_wol = bnad_get_wol,
1120 .get_coalesce = bnad_get_coalesce,
1121 .set_coalesce = bnad_set_coalesce,
1122 .get_ringparam = bnad_get_ringparam,
1123 .set_ringparam = bnad_set_ringparam,
1124 .get_pauseparam = bnad_get_pauseparam,
1125 .set_pauseparam = bnad_set_pauseparam,
1126 .get_strings = bnad_get_strings,
1127 .get_ethtool_stats = bnad_get_ethtool_stats,
1128 .get_sset_count = bnad_get_sset_count,
1129 .get_eeprom_len = bnad_get_eeprom_len,
1130 .get_eeprom = bnad_get_eeprom,
1131 .set_eeprom = bnad_set_eeprom,
1132 .flash_device = bnad_flash_device,