From: netdev-bot+sashiko@kernel.org
To: james.hilliard1@gmail.com
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
skhan@linuxfoundation.org, rdunlap@infradead.org,
o.rempel@pengutronix.de, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH net-next v5 3/3] net: phy: acx00: report receive statistics
Date: Mon, 16 Nov 2026 08:06:09 +0000 [thread overview]
Message-ID: <179481636902.3136.5648060525079274631@kernel.org> (raw)
In-Reply-To: <20261115-submit-acx00-phy-stats-v1-v5-3-ed81a7f54373@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] rx_packets permanently loses successful frames when CRC errors
keep breaking the bracket for 320 s or more.
- [Low] Speculative, depends on undocumented counter behaviour.
--
net: phy: acx00: report receive statistics
This adds update_stats and get_phy_stats support to the AC200/AC300 EPHY
driver. Successful frames (frame count minus CRC errors) go to rx_packets,
CRC errors go to rx_errors, and the hardware byte count goes to
rx_bytes_total. The hardware counters are sampled with carry detection and
a CRC-bracketed packet read. Wrap-adjusted deltas are added to 64-bit
totals, and a delta is discarded when 320 seconds or more have passed since
that counter was last sampled.
> diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c
> index cee6c7ff0278e..691f4931af460 100644
> --- a/drivers/net/phy/xpowers/acx00.c
> +++ b/drivers/net/phy/xpowers/acx00.c
[ ... ]
> @@ -110,6 +138,169 @@ static int acx00_ephy_write_page(struct phy_device *phydev, int page)
[ ... ]
> +/* Return a mask of usable counters, or a negative MDIO error. */
> +static int acx00_ephy_read_counts(struct phy_device *phydev, u32 *counts)
> +{
[ ... ]
> + /* Bracket the packet counter with an unchanged CRC count. */
> + for (i = 0; i < ACX00_COUNTER_READ_ATTEMPTS; i++) {
> + ret = acx00_ephy_read_counter(phydev, ACX00_PAGE9_RX_PACKETS_HIGH_REG,
> + &packets);
> + if (ret < 0)
> + return ret;
> + if (ret)
> + break;
> + ret = acx00_ephy_read_counter(phydev, ACX00_PAGE9_RX_CRC_ERRORS_HIGH_REG,
> + &errors);
> + if (ret < 0)
> + return ret;
> + if (ret)
> + break;
> + if (errors == counts[ACX00_STAT_RX_CRC_ERRORS]) {
> + /* Both hardware counters and their difference wrap at 2^32. */
> + counts[ACX00_STAT_RX_PACKETS] = packets - errors;
> + return BIT(ACX00_STAT_RX_PACKETS) | BIT(ACX00_STAT_RX_CRC_ERRORS);
> + }
> + counts[ACX00_STAT_RX_CRC_ERRORS] = errors;
> + }
> +
> + /* Keep reporting errors even when no coherent packet sample is possible. */
> + return BIT(ACX00_STAT_RX_CRC_ERRORS);
> +}
[Severity: Medium]
Can rx_packets permanently lose successful frames when CRC errors keep
breaking the bracket?
On this path only the CRC bit is returned. __acx00_ephy_update_stats()
therefore leaves stats_last[ACX00_STAT_RX_PACKETS] and
stats_start[ACX00_STAT_RX_PACKETS] at their values from the last coherent
pair, while rx_errors keeps advancing.
When a coherent pair finally arrives, its delta is only accepted if:
if ((priv->stats_valid & BIT(i)) &&
ktime_ms_delta(ktime_get_boottime(), priv->stats_start[i]) <
(s64)ACX00_STATS_MAX_INTERVAL_MS) {
Suppose the CRC count changes in all three bracket windows on every poll
for 320 seconds or more. One example is a bulk transfer over a damaged
cable with a few thousand CRC errors per second. In that case only the
baseline moves, and every successful frame received since the last
coherent pair is dropped from rx_packets. rx_errors stays correct, so the
reported error ratio comes out wrong.
ACX00_STATS_MAX_INTERVAL_MS comes from the byte counter's 4,000,000,000
modulus. The 2^32 packets-minus-errors difference cannot wrap at 100 Mb/s
for about 8 hours (2^32 / 148,810 minimum-size frames/s is roughly
28,862 s). The dropped delta could still have been recovered.
The commit message says:
When CRC errors keep arriving, update rx_errors from the
latest stable error read without advancing the successful-frame baseline.
A later coherent pair accounts for the intervening successful frames.
Is that only true when the incoherent period is shorter than 320 seconds?
Would a separate interval limit for the frame counters, based on their
2^32 modulus, avoid dropping these frames?
> +
> +static int __acx00_ephy_update_stats(struct phy_device *phydev)
> +{
[ ... ]
> + for (i = 0; i < ACX00_NUM_STATS; i++) {
> + u64 count;
> +
> + if (!(ret & BIT(i)))
> + continue;
> + count = counts[i];
> +
> + /* Include sleep and read time; unseen cycles cannot be recovered. */
> + if ((priv->stats_valid & BIT(i)) &&
> + ktime_ms_delta(ktime_get_boottime(), priv->stats_start[i]) <
> + (s64)ACX00_STATS_MAX_INTERVAL_MS) {
> + if (count < priv->stats_last[i])
> + count += i == ACX00_STAT_RX_BYTES ?
> + ACX00_RX_BYTES_WRAP : BIT_ULL(32);
> + priv->stats[i] += count - priv->stats_last[i];
> + }
[Severity: Low]
This depends on counter behaviour that isn't documented. What happens if
the difference computed in acx00_ephy_read_counts() goes down between two
samples?
counts[ACX00_STAT_RX_PACKETS] = packets - errors;
This code treats any drop as a 2^32 wrap, so rx_packets would jump by
about 4.29e9. Totals are kept across resets and power transitions, so the
jump would be permanent.
The difference only stays non-decreasing if two things hold. The frame
counter must include every event the CRC-error counter counts. It must
also never increment later than the CRC counter for the same frame. The
bracket only shows that the CRC count didn't change while the packet
counter was being read.
Two hardware behaviours would break this:
- The CRC/error counter also counts events the frame counter skips, such
as runts, collision fragments, false carrier or RX_ER.
- The frame counter increments at start of frame and the CRC counter at
end of frame. At 10 Mb/s these can be up to about 1.2 ms apart. If no
good frame arrives before the next poll, the difference drops by 1.
Intervals are already limited to under 320 seconds. At 100 Mb/s at most
about 47.6 million frames can arrive in that time. Could a wrap-adjusted
packet delta larger than that be rejected and used as a new baseline,
rather than added to the total?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115-submit-acx00-phy-stats-v1-v5-0-ed81a7f54373%40gmail.com
prev parent reply other threads:[~2026-11-16 8:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 7:45 [PATCH net-next v5 0/3] net: phy: report ACx00 receive statistics James Hilliard
2026-11-15 7:45 ` [PATCH net-next v5 1/3] docs: networking: correct the PHY statistics group name James Hilliard
2026-11-15 15:01 ` Andrew Lunn
2026-11-15 7:45 ` [PATCH net-next v5 2/3] ethtool: add a PHY receive byte total James Hilliard
2026-11-15 15:25 ` Andrew Lunn
2026-11-16 4:12 ` James Hilliard
2026-11-16 4:39 ` Andrew Lunn
2026-11-16 4:56 ` James Hilliard
2026-11-16 8:06 ` netdev-bot+sashiko
2026-11-15 7:45 ` [PATCH net-next v5 3/3] net: phy: acx00: report receive statistics James Hilliard
2026-11-16 8:06 ` netdev-bot+sashiko [this message]
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=179481636902.3136.5648060525079274631@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=james.hilliard1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
/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