From: Marek Vasut <marek.vasut@mailbox.org>
To: netdev@vger.kernel.org
Cc: Marek Vasut <marek.vasut@mailbox.org>,
Andrew Lunn <andrew@lunn.ch>,
Arun Ramadoss <arun.ramadoss@microchip.com>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Tristram Ha <tristram.ha@microchip.com>,
UNGLinuxDriver@microchip.com, Vladimir Oltean <olteanv@gmail.com>,
Woojung Huh <woojung.huh@microchip.com>
Subject: [net-next,PATCH] net: dsa: microchip: Do not count RX/TX Bytes and discards on KSZ87xx
Date: Sun, 10 Aug 2025 18:09:05 +0200 [thread overview]
Message-ID: <20250810160933.10609-1-marek.vasut@mailbox.org> (raw)
Unlike KSZ94xx, the KSZ87xx is missing the last four MIB counters at
address 0x20..0x23, namely rx_total, tx_total, rx_discards, tx_discards.
Using values from rx_total / tx_total in rx_bytes / tx_bytes calculation
results in an underflow, because rx_total / tx_total returns values 0,
and the "raw->rx_total - stats->rx_packets * ETH_FCS_LEN;" calculation
undeflows if rx_packets / tx_packets is > 0 .
Stop using the missing MIB counters on KSZ87xx .
Fixes: c6101dd7ffb8 ("net: dsa: ksz9477: move get_stats64 to ksz_common.c")
Signed-off-by: Marek Vasut <marek.vasut@mailbox.org>
---
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Tristram Ha <tristram.ha@microchip.com>
Cc: UNGLinuxDriver@microchip.com
Cc: Vladimir Oltean <olteanv@gmail.com>
Cc: Woojung Huh <woojung.huh@microchip.com>
Cc: netdev@vger.kernel.org
---
drivers/net/dsa/microchip/ksz_common.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 7292bfe2f7cac..9c01526779a6d 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -2239,20 +2239,23 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port)
/* HW counters are counting bytes + FCS which is not acceptable
* for rtnl_link_stats64 interface
*/
- stats->rx_bytes = raw->rx_total - stats->rx_packets * ETH_FCS_LEN;
- stats->tx_bytes = raw->tx_total - stats->tx_packets * ETH_FCS_LEN;
-
+ if (!ksz_is_ksz87xx(dev)) {
+ stats->rx_bytes = raw->rx_total - stats->rx_packets * ETH_FCS_LEN;
+ stats->tx_bytes = raw->tx_total - stats->tx_packets * ETH_FCS_LEN;
+ }
stats->rx_length_errors = raw->rx_undersize + raw->rx_fragments +
raw->rx_oversize;
stats->rx_crc_errors = raw->rx_crc_err;
stats->rx_frame_errors = raw->rx_align_err;
- stats->rx_dropped = raw->rx_discards;
+ if (!ksz_is_ksz87xx(dev))
+ stats->rx_dropped = raw->rx_discards;
stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
stats->rx_frame_errors + stats->rx_dropped;
stats->tx_window_errors = raw->tx_late_col;
- stats->tx_fifo_errors = raw->tx_discards;
+ if (!ksz_is_ksz87xx(dev))
+ stats->tx_fifo_errors = raw->tx_discards;
stats->tx_aborted_errors = raw->tx_exc_col;
stats->tx_errors = stats->tx_window_errors + stats->tx_fifo_errors +
stats->tx_aborted_errors;
--
2.47.2
next reply other threads:[~2025-08-10 16:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-10 16:09 Marek Vasut [this message]
2025-08-11 20:47 ` [net-next,PATCH] net: dsa: microchip: Do not count RX/TX Bytes and discards on KSZ87xx Tristram.Ha
2025-08-11 20:59 ` Marek Vasut
2025-08-11 22:09 ` Tristram.Ha
2025-08-13 7:03 ` vtpieter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250810160933.10609-1-marek.vasut@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=tristram.ha@microchip.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).