Re: [PATCH net-next v3] octeontx2-pf: Retain ethtool stats across interface down/up.
From: Dragos Tatulea
Date: Tue May 12 2026 - 05:54:33 EST
On Tue, May 12, 2026 at 12:53:38PM +0530, Anshumali Gaur wrote:
> Currently the hardware counters reset when the interface is
> brought down, causing stats visible to userspace to drop to zero.
> Save the accumulated stats before bringing the interface down
> so they persist across routine down/up cycles.
>
> Signed-off-by: Anshumali Gaur <agaur@xxxxxxxxxxx>
> ---
> v3:
> - Code format according to kernel coding style
> - Reword commit message
> v2:
> - Fix subject prefix to target net-next
> .../marvell/octeontx2/nic/otx2_common.c | 20 ++++++++++---------
> .../marvell/octeontx2/nic/otx2_common.h | 1 +
> .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 17 ++++++++++++++++
> 3 files changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> index 971fcab1c248..0ffcc613a4b2 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -139,19 +139,21 @@ void otx2_get_stats64(struct net_device *netdev,
> struct rtnl_link_stats64 *stats)
> {
> struct otx2_nic *pfvf = netdev_priv(netdev);
> - struct otx2_dev_stats *dev_stats;
> + struct otx2_dev_stats *dev_stats, *old_stats;
>
> otx2_get_dev_stats(pfvf);
>
> dev_stats = &pfvf->hw.dev_stats;
> - stats->rx_bytes = dev_stats->rx_bytes;
> - stats->rx_packets = dev_stats->rx_frames;
> - stats->rx_dropped = dev_stats->rx_drops;
> - stats->multicast = dev_stats->rx_mcast_frames;
> -
> - stats->tx_bytes = dev_stats->tx_bytes;
> - stats->tx_packets = dev_stats->tx_frames;
> - stats->tx_dropped = dev_stats->tx_drops;
> + old_stats = &pfvf->hw.old_stats;
> +
> + stats->rx_bytes = old_stats->rx_bytes + dev_stats->rx_bytes;
> + stats->rx_packets = old_stats->rx_frames + dev_stats->rx_frames;
> + stats->rx_dropped = old_stats->rx_drops + dev_stats->rx_drops;
> + stats->multicast = old_stats->rx_mcast_frames + dev_stats->rx_mcast_frames;
> +
> + stats->tx_bytes = old_stats->tx_bytes + dev_stats->tx_bytes;
> + stats->tx_packets = old_stats->tx_frames + dev_stats->tx_frames;
> + stats->tx_dropped = old_stats->tx_drops + dev_stats->tx_drops;
> }
Missed comment from v2:
https://lore.kernel.org/netdev/bf626b44-efad-43f2-b8b4-509934f4befa@xxxxxxxxxx/
Thanks,
Dragos