Re: [PATCH net-next v2] net: phy: acx00: report receive statistics
From: Andrew Lunn
Date: Mon Nov 02 2026 - 20:25:37 EST
On Mon, Nov 02, 2026 at 04:28:28PM -0700, James Hilliard wrote:
> Expose receive frame and byte totals through the generic PHY statistics
> interface as rx_packets and rx_bytes, alongside CRC errors in rx_errors.
> Report the hardware totals directly: the packet and byte counters include
> errored frames as well as successfully received traffic.
>
> Collect the free-running 32-bit counters through phylib's
> update_stats callback and accumulate wrap-safe deltas in 64-bit totals.
> Read the high half on either side of the low half and retry until both
> high-half reads agree.
>
> Hardware testing confirmed that the receive-byte counter wraps at
> 4,000,000,000, while the receive-packet and CRC-error counters wrap at
> 2^32. Use the corresponding modulus for each counter so rollover does
> not inflate the software totals.
>
> Serialize collection and reporting with the package-state mutex so reads
> cannot race reset or power-off, and the totals are safe on 32-bit systems.
> Commit a sample only after all counter reads and page restoration succeed.
> The reporting callback returns cached totals without accessing MDIO.
>
> Take a best-effort final snapshot before soft reset and suspend. Invalidate
> the hardware baseline before reset or power-off, including failed power-off
> attempts, and establish a fresh baseline after configuration. Preserve the
> software totals across these transitions and retain the live baseline when
> resume reconfigures an already active PHY. A failed initial snapshot can be
> retried by the periodic collector without preventing initialization.
>
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
Andrew