Skip to content

Commit 898bdf2

Browse files
david decotignydavem330
authored andcommitted
forcedeth: fix stats on hardware without extended stats support
This change makes sure that tx_packets/rx_bytes ifconfig counters are updated even on NICs that don't provide hardware support for these stats: they are now updated in software. For the sake of consistency, we also now have tx_bytes updated in software (hardware counters include ethernet CRC, and software doesn't account for it). This reverts parts of: - "forcedeth: statistics optimization" (2182816) - "forcedeth: Improve stats counters" (0bdfea8) - "forcedeth: remove unneeded stats updates" (4687f3f) Tested: pktgen + loopback (http://patchwork.ozlabs.org/patch/124698/) reports identical tx_packets/rx_packets and tx_bytes/rx_bytes. Signed-off-by: David Decotigny <david.decotigny@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 77c1c7c commit 898bdf2

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

‎drivers/net/ethernet/nvidia/forcedeth.c‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ struct nv_ethtool_str {
609609
};
610610

611611
static const struct nv_ethtool_str nv_estats_str[] = {
612-
{ "tx_bytes" },
612+
{ "tx_bytes" }, /* includes Ethernet FCS CRC */
613613
{ "tx_zero_rexmt" },
614614
{ "tx_one_rexmt" },
615615
{ "tx_many_rexmt" },
@@ -637,7 +637,7 @@ static const struct nv_ethtool_str nv_estats_str[] = {
637637
/* version 2 stats */
638638
{ "tx_deferral" },
639639
{ "tx_packets" },
640-
{ "rx_bytes" },
640+
{ "rx_bytes" }, /* includes Ethernet FCS CRC */
641641
{ "tx_pause" },
642642
{ "rx_pause" },
643643
{ "rx_drop_frame" },
@@ -649,7 +649,7 @@ static const struct nv_ethtool_str nv_estats_str[] = {
649649
};
650650

651651
struct nv_ethtool_stats {
652-
u64 tx_bytes;
652+
u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
653653
u64 tx_zero_rexmt;
654654
u64 tx_one_rexmt;
655655
u64 tx_many_rexmt;
@@ -670,14 +670,14 @@ struct nv_ethtool_stats {
670670
u64 rx_unicast;
671671
u64 rx_multicast;
672672
u64 rx_broadcast;
673-
u64 rx_packets;
673+
u64 rx_packets; /* should be ifconfig->rx_packets */
674674
u64 rx_errors_total;
675675
u64 tx_errors_total;
676676

677677
/* version 2 stats */
678678
u64 tx_deferral;
679-
u64 tx_packets;
680-
u64 rx_bytes;
679+
u64 tx_packets; /* should be ifconfig->tx_packets */
680+
u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
681681
u64 tx_pause;
682682
u64 rx_pause;
683683
u64 rx_drop_frame;
@@ -1706,10 +1706,17 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev)
17061706
if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) {
17071707
nv_get_hw_stats(dev);
17081708

1709+
/*
1710+
* Note: because HW stats are not always available and
1711+
* for consistency reasons, the following ifconfig
1712+
* stats are managed by software: rx_bytes, tx_bytes,
1713+
* rx_packets and tx_packets. The related hardware
1714+
* stats reported by ethtool should be equivalent to
1715+
* these ifconfig stats, with 4 additional bytes per
1716+
* packet (Ethernet FCS CRC).
1717+
*/
1718+
17091719
/* copy to net_device stats */
1710-
dev->stats.tx_packets = np->estats.tx_packets;
1711-
dev->stats.rx_bytes = np->estats.rx_bytes;
1712-
dev->stats.tx_bytes = np->estats.tx_bytes;
17131720
dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
17141721
dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
17151722
dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
@@ -2380,6 +2387,9 @@ static int nv_tx_done(struct net_device *dev, int limit)
23802387
if (flags & NV_TX_ERROR) {
23812388
if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK))
23822389
nv_legacybackoff_reseed(dev);
2390+
} else {
2391+
dev->stats.tx_packets++;
2392+
dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
23832393
}
23842394
dev_kfree_skb_any(np->get_tx_ctx->skb);
23852395
np->get_tx_ctx->skb = NULL;
@@ -2390,6 +2400,9 @@ static int nv_tx_done(struct net_device *dev, int limit)
23902400
if (flags & NV_TX2_ERROR) {
23912401
if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK))
23922402
nv_legacybackoff_reseed(dev);
2403+
} else {
2404+
dev->stats.tx_packets++;
2405+
dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
23932406
}
23942407
dev_kfree_skb_any(np->get_tx_ctx->skb);
23952408
np->get_tx_ctx->skb = NULL;
@@ -2429,6 +2442,9 @@ static int nv_tx_done_optimized(struct net_device *dev, int limit)
24292442
else
24302443
nv_legacybackoff_reseed(dev);
24312444
}
2445+
} else {
2446+
dev->stats.tx_packets++;
2447+
dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
24322448
}
24332449

24342450
dev_kfree_skb_any(np->get_tx_ctx->skb);
@@ -2678,6 +2694,7 @@ static int nv_rx_process(struct net_device *dev, int limit)
26782694
skb->protocol = eth_type_trans(skb, dev);
26792695
napi_gro_receive(&np->napi, skb);
26802696
dev->stats.rx_packets++;
2697+
dev->stats.rx_bytes += len;
26812698
next_pkt:
26822699
if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
26832700
np->get_rx.orig = np->first_rx.orig;
@@ -2761,6 +2778,7 @@ static int nv_rx_process_optimized(struct net_device *dev, int limit)
27612778
}
27622779
napi_gro_receive(&np->napi, skb);
27632780
dev->stats.rx_packets++;
2781+
dev->stats.rx_bytes += len;
27642782
} else {
27652783
dev_kfree_skb(skb);
27662784
}

0 commit comments

Comments
 (0)