From nobody Mon May 25 00:08:42 2026 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B17D7370AFA; Wed, 20 May 2026 09:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779269667; cv=none; b=XEhJco7Rc3ldfDg8T/Rav7AdCBOQaZPhmUPmF7wLVUelZVndFaR7+wlVhE4/lJYcY2+vzTSiyDt8z+MDRE+5dQheoalQKJzKwYbznf7ibzjS0w8dNCUImmIym/ukHt4qFamYqEjC5mWOsz0zYP4DylmcF6twD9R5n8wsaPh7g3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779269667; c=relaxed/simple; bh=BoblhB4Xpk4LlfwvhT1PyKrbb08G4mcOXJ9gtHhleuU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=tavmz/HyXzrPpsBMo+gEQ+4xXjqvEk6IU0lJuCPrpBKx5PtN+4HTZimBugCARMJISyBcJXjWGFUcAh+P8Btr5qRPmtNx6g7YSHOZIhv+sywK1XsRrV97XBiZ+gJIzFyVB9QetPo88Fg16Qa9ANc4be2wN1cXsbuzuOKtJot9uXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=PQC2yBc6; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="PQC2yBc6" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64K2pmZD3009289; Wed, 20 May 2026 02:34:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pfpt0220; bh=tWEoPTrzvEZ7qqivt3k6eDh pPFiR0vgOIDIx7kdmhaY=; b=PQC2yBc6zFg/1n9iRNMKqY2E9hcR6/tq7NoKIRi xgJx1sWMjC0ZLCRoD6TdhBBYRV89unXYyvFQvgBunltr+e0GO2Y/CKbaa/Uu4qgG hCdpsS7v4dbkU+GpuknUNJwPREFWBViv11/CufwONqPR54tPTE7ih+HJzPcpVs2O 7VFcGHwzjqD3zTXtGmg55Z2hJ4SVn/6o/0/l/4vnQwH9zUPrLUc7X7Ruk4fAQGRN ElaMKkenEPRsRs2r656unBcvK6hK/fePcaY9kMc2F03Tnx2uRHtZz9XRNkFJcP3/ XLckOYgVN9Jwj2cQIP3Y5o+cfmhNyGlHpLSa3qe4hs+XNoQ== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4e8jywcayt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 May 2026 02:34:13 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Wed, 20 May 2026 02:34:12 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Wed, 20 May 2026 02:34:12 -0700 Received: from hyd1vellox1.032marvell.com032caveonetworks.com (unknown [10.29.37.43]) by maili.marvell.com (Postfix) with ESMTP id 6356F5B693E; Wed, 20 May 2026 02:34:08 -0700 (PDT) From: Anshumali Gaur To: , , , , , , , , , , , CC: Anshumali Gaur Subject: [PATCH net-next v5] octeontx2-pf: Retain ethtool stats across interface down/up. Date: Wed, 20 May 2026 15:04:04 +0530 Message-ID: <20260520093404.1945835-1-agaur@marvell.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: vlheHNz2e9Dk8KHYFtohrHYvrX5uUwRz X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTIwMDA5MCBTYWx0ZWRfX3EEhXbd3U6gq sBDET3qP3z63Vz9w18iLwKQiMGIXIhoazv9boofV2BJ/2+LoFlodzAuq2Z0KG7TEOInFfahtpim YtiJLmek0KwrzgME54D1iuaR35zcxVwmC39PdNYJDu0ewJuMYihlKDCtNrseWFUjDEcEBgZkWlW 44M5GpPOIb79tjrPArCJJ5fuR5Eq3cLb2uBQtmF0xn1Ri6Fq7DrulY1W2M5rU8cIZZnV4F3QNBB lFRVeRSt3WqWJJiZjSNWCZ2S6JxBKstSw7BNknlwAIHHrdFqTDCefObeoNEw2SBu1Ys6Rt0ZA2h rnRc5xR+uKQGXy6exTX6LI305UEs0wgFBcKpxV9JR8uHBCtab00e2Nr9q8MYKyxCwqEsESXxtpd 9govGTatdNxrJQFNQ+xEgb2B9fEH+/D/Z65l8dDUkkU8GRFWH1wbV0oT+jc6UdwFffjiG6GbTAA U+y1nnHTOMPMAPMyVdw== X-Proofpoint-ORIG-GUID: vlheHNz2e9Dk8KHYFtohrHYvrX5uUwRz X-Authority-Analysis: v=2.4 cv=QbNWeMbv c=1 sm=1 tr=0 ts=6a0d8015 cx=c_pps a=gIfcoYsirJbf48DBMSPrZA==:117 a=gIfcoYsirJbf48DBMSPrZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=TtqV-g6YmW1Jfm2GSLaY:22 a=M5GUcnROAAAA:8 a=6arj5X4aKY2yYbu-eEwA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-20_02,2026-05-18_01,2025-10-01_01 Content-Type: text/plain; charset="utf-8" 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 --- v5: - Split variable declaration and initialization in otx2_stop (Paolo) - Fix reverse christmas tree order in otx2_get_stats64() (Paolo) - Move stats collection just before otx2_free_hw_resources() to avoid race with NAPI (Paolo/Sashiko) - Remove duplicate otx2_rxtx_enable() call v4: - Move stats accumulation after disabling tx/rx (Dragos) - Fetch latest HW counters before accumulating in otx2_stop() 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 | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/dri= vers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index 971fcab1c248..fce46816446f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -138,20 +138,22 @@ void otx2_get_dev_stats(struct otx2_nic *pfvf) void otx2_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) { + struct otx2_dev_stats *dev_stats, *old_stats; struct otx2_nic *pfvf =3D netdev_priv(netdev); - struct otx2_dev_stats *dev_stats; =20 otx2_get_dev_stats(pfvf); =20 dev_stats =3D &pfvf->hw.dev_stats; - stats->rx_bytes =3D dev_stats->rx_bytes; - stats->rx_packets =3D dev_stats->rx_frames; - stats->rx_dropped =3D dev_stats->rx_drops; - stats->multicast =3D dev_stats->rx_mcast_frames; - - stats->tx_bytes =3D dev_stats->tx_bytes; - stats->tx_packets =3D dev_stats->tx_frames; - stats->tx_dropped =3D dev_stats->tx_drops; + old_stats =3D &pfvf->hw.old_stats; + + stats->rx_bytes =3D old_stats->rx_bytes + dev_stats->rx_bytes; + stats->rx_packets =3D old_stats->rx_frames + dev_stats->rx_frames; + stats->rx_dropped =3D old_stats->rx_drops + dev_stats->rx_drops; + stats->multicast =3D old_stats->rx_mcast_frames + dev_stats->rx_mcast_fra= mes; + + stats->tx_bytes =3D old_stats->tx_bytes + dev_stats->tx_bytes; + stats->tx_packets =3D old_stats->tx_frames + dev_stats->tx_frames; + stats->tx_dropped =3D old_stats->tx_drops + dev_stats->tx_drops; } EXPORT_SYMBOL(otx2_get_stats64); =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/dri= vers/net/ethernet/marvell/octeontx2/nic/otx2_common.h index eecee612b7b2..ad65aa19b80d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h @@ -255,6 +255,7 @@ struct otx2_hw { =20 /* Stats */ struct otx2_dev_stats dev_stats; + struct otx2_dev_stats old_stats; struct otx2_drv_stats drv_stats; u64 cgx_rx_stats[CGX_RX_STATS_COUNT]; u64 cgx_tx_stats[CGX_TX_STATS_COUNT]; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers= /net/ethernet/marvell/octeontx2/nic/otx2_pf.c index ee623476e5ff..3b4e32d899b7 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -2154,6 +2154,7 @@ EXPORT_SYMBOL(otx2_open); int otx2_stop(struct net_device *netdev) { struct otx2_nic *pf =3D netdev_priv(netdev); + struct otx2_dev_stats *old_stats, *dev; struct otx2_cq_poll *cq_poll =3D NULL; struct otx2_qset *qset =3D &pf->qset; int qidx, vec, wrk; @@ -2200,6 +2201,26 @@ int otx2_stop(struct net_device *netdev) cancel_delayed_work_sync(&pf->refill_wrk[wrk].pool_refill_work); devm_kfree(pf->dev, pf->refill_wrk); =20 + /* Read final HW counters and accumulate */ + dev =3D &pf->hw.dev_stats; + old_stats =3D &pf->hw.old_stats; + otx2_get_dev_stats(pf); + + /* Accumulate old stats */ + old_stats->rx_bytes +=3D dev->rx_bytes; + old_stats->rx_drops +=3D dev->rx_drops; + old_stats->rx_bcast_frames +=3D dev->rx_bcast_frames; + old_stats->rx_mcast_frames +=3D dev->rx_mcast_frames; + old_stats->rx_ucast_frames +=3D dev->rx_ucast_frames; + old_stats->rx_frames +=3D dev->rx_frames; + + old_stats->tx_bytes +=3D dev->tx_bytes; + old_stats->tx_drops +=3D dev->tx_drops; + old_stats->tx_bcast_frames +=3D dev->tx_bcast_frames; + old_stats->tx_mcast_frames +=3D dev->tx_mcast_frames; + old_stats->tx_ucast_frames +=3D dev->tx_ucast_frames; + old_stats->tx_frames +=3D dev->tx_frames; + otx2_free_hw_resources(pf); otx2_free_cints(pf, pf->hw.cint_cnt); otx2_disable_napi(pf); --=20 2.25.1