Thread (2 messages) flat view 2 messages, 2 authors, 2d ago
WARM2d

[PATCH net-next] octeontx2-pf: add devlink param to reset MAC stats

From: <hidden>
Date: 2026-08-14 10:43:24
Also in: lkml
Subsystem: documentation, marvell octeontx2 physical function driver, marvell octeontx2 rvu admin function driver, networking drivers, networking [general], the rest · Maintainers: Jonathan Corbet, Sunil Goutham, Geetha sowjanya, Ratheesh Kannoth, Subbaraya Sundeep, Bharat Bhushan, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

From: Viswajith Murali <redacted>

Add a runtime devlink parameter to reset CGX/RPM MAC hardware
statistics.

Signed-off-by: Nitin Shetty J <redacted>
Signed-off-by: Viswajith Murali <redacted>
---
 .../networking/devlink/octeontx2.rst          |  9 +++++
 .../ethernet/marvell/octeontx2/af/rvu_cgx.c   |  2 +-
 .../marvell/octeontx2/nic/otx2_devlink.c      | 39 +++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/devlink/octeontx2.rst b/Documentation/networking/devlink/octeontx2.rst
index 84206537aedb..1463cb52ae54 100644
--- a/Documentation/networking/devlink/octeontx2.rst
+++ b/Documentation/networking/devlink/octeontx2.rst
@@ -77,3 +77,12 @@ The ``octeontx2 PF`` driver implements the following driver-specific parameters.
      - Set the maximum number of unicast filters that can be programmed for
        the device. This can be used to achieve better device resource
        utilization, avoiding over consumption of unused MCAM table entries.
+   * - ``mac_stats_reset``
+     - bool
+     - runtime
+     - One-shot trigger to reset CGX/RPM MAC hardware statistics.
+       Write true to reset the counters; reading this parameter always returns
+       false. Supported only on CGX/RPM mapped PF netdevs. The reset fails with
+       ``-EBUSY`` when the CGX port is in use by more than one interface, such
+       as when the PF netdev and one or more VF netdevs are active. Other
+       failures return ``-EIO``.
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
index 87d21889dc49..7e09ca25101d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
@@ -649,7 +649,7 @@ int rvu_mbox_handler_cgx_stats_rst(struct rvu *rvu, struct msg_req *req,
 	 */
 	if (parent_pf->cgx_users > 1) {
 		dev_info(rvu->dev, "CGX busy, could not reset statistics\n");
-		return 0;
+		return -EBUSY;
 	}
 
 	rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_idx, &lmac);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
index 4a5ce0e67dda..daa8fb37f392 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
@@ -125,10 +125,43 @@ static int otx2_dl_ucast_flt_cnt_validate(struct devlink *devlink, u32 id,
 	return 0;
 }
 
+static int otx2_dl_mac_stats_reset_get(struct devlink *devlink, u32 id,
+				       struct devlink_param_gset_ctx *ctx,
+				       struct netlink_ext_ack *extack)
+{
+	/* This is a one-shot trigger, so it has no state */
+	ctx->val.vbool = false;
+	return 0;
+}
+
+static int otx2_dl_mac_stats_reset_set(struct devlink *devlink, u32 id,
+				       struct devlink_param_gset_ctx *ctx,
+				       struct netlink_ext_ack *extack)
+{
+	struct otx2_devlink *otx2_dl = devlink_priv(devlink);
+	struct otx2_nic *pfvf = otx2_dl->pfvf;
+	int err;
+
+	if (!ctx->val.vbool)
+		return 0;
+
+	err = otx2_reset_mac_stats(pfvf);
+	if (err == -EBUSY) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "CGX port shared by multiple interfaces, cannot reset MAC stats");
+		return -EBUSY;
+	} else if (err) {
+		return -EIO;
+	}
+
+	return 0;
+}
+
 enum otx2_dl_param_id {
 	OTX2_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
 	OTX2_DEVLINK_PARAM_ID_MCAM_COUNT,
 	OTX2_DEVLINK_PARAM_ID_UCAST_FLT_CNT,
+	OTX2_DEVLINK_PARAM_ID_MAC_STATS_RST,
 };
 
 static const struct devlink_param otx2_dl_params[] = {
@@ -142,6 +175,12 @@ static const struct devlink_param otx2_dl_params[] = {
 			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
 			     otx2_dl_ucast_flt_cnt_get, otx2_dl_ucast_flt_cnt_set,
 			     otx2_dl_ucast_flt_cnt_validate),
+	DEVLINK_PARAM_DRIVER(OTX2_DEVLINK_PARAM_ID_MAC_STATS_RST,
+			     "mac_stats_reset", DEVLINK_PARAM_TYPE_BOOL,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     otx2_dl_mac_stats_reset_get,
+			     otx2_dl_mac_stats_reset_set,
+			     NULL),
 };
 
 #ifdef CONFIG_RVU_ESWITCH
-- 
2.48.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help