Thread (4 messages) flat view 4 messages, 3 authors, 4d ago
COOLING4d

[RFC PATCH net-next 1/1] ethtool: Add Clear-fec-stats ethtool handler

From: Pei Lee Ling <hidden>
Date: 2026-09-21 15:46:44
Subsystem: networking drivers, networking [ethtool], networking [general], the rest, yaml netlink (ynl) · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn, Linus Torvalds, Donald Hunter

In high-speed links such as 25G, 100G, and 200G, FEC counters continuously
accumulate over time. When troubleshooting intermittent physical-layer
issues, users need to establish a clean baseline without resetting the
entire device interface. Therefore, this dedicated
FEC counter clear operation avoids unnecessary operational disruptions.

Adding a fec-clear command would also help to standardize the interface
across different network drivers, providing a more consistent and predictable
user experience.

To clear-fec-stats:
ethtool --clear-fec-stats <ETH1>

Signed-off-by: Pei Lee Ling <redacted>
---
 Documentation/netlink/specs/ethtool.yaml       |  3 +++
 include/linux/ethtool.h                        |  1 +
 include/uapi/linux/ethtool_netlink_generated.h |  1 +
 net/ethtool/fec.c                              | 11 ++++++++++-
 net/ethtool/netlink.h                          |  2 +-
 5 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml
index 5dd4d1b5d94b..6943a6280f35 100644
--- a/Documentation/netlink/specs/ethtool.yaml
+++ b/Documentation/netlink/specs/ethtool.yaml
@@ -1312,6 +1312,9 @@ attribute-sets:
         name: stats
         type: nest
         nested-attributes: fec-stat
+      -
+        name: stats-clear
+        type: u8
   -
     name: module-eeprom
     attr-cnt-name: __ethtool-a-module-eeprom-cnt
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 12683b5d125e..d5ec9f415adc 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -1319,6 +1319,7 @@ struct ethtool_ops {
 	void	(*get_fec_stats)(struct net_device *dev,
 				 struct ethtool_fec_stats *fec_stats,
 				 struct ethtool_fec_hist *hist);
+	int	(*clear_fec_stats)(struct net_device *dev);
 	int	(*get_fecparam)(struct net_device *,
 				      struct ethtool_fecparam *);
 	int	(*set_fecparam)(struct net_device *,
diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/linux/ethtool_netlink_generated.h
index 8134baf7860f..01c5b754c3db 100644
--- a/include/uapi/linux/ethtool_netlink_generated.h
+++ b/include/uapi/linux/ethtool_netlink_generated.h
@@ -595,6 +595,7 @@ enum {
 	ETHTOOL_A_FEC_AUTO,
 	ETHTOOL_A_FEC_ACTIVE,
 	ETHTOOL_A_FEC_STATS,
+	ETHTOOL_A_FEC_STATS_CLEAR,
 
 	__ETHTOOL_A_FEC_CNT,
 	ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_CNT - 1)
diff --git a/net/ethtool/fec.c b/net/ethtool/fec.c
index e2d539271060..edfa535477cb 100644
--- a/net/ethtool/fec.c
+++ b/net/ethtool/fec.c
@@ -290,10 +290,11 @@ static int fec_fill_reply(struct sk_buff *skb,
 
 /* FEC_SET */
 
-const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1] = {
+const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_MAX + 1] = {
 	[ETHTOOL_A_FEC_HEADER]	= NLA_POLICY_NESTED(ethnl_header_policy),
 	[ETHTOOL_A_FEC_MODES]	= { .type = NLA_NESTED },
 	[ETHTOOL_A_FEC_AUTO]	= NLA_POLICY_MAX(NLA_U8, 1),
+	[ETHTOOL_A_FEC_STATS_CLEAR] = NLA_POLICY_MAX(NLA_U8, 1),
 };
 
 static int
@@ -315,6 +316,14 @@ ethnl_set_fec(struct ethnl_req_info *req_info, struct genl_info *info)
 	u8 fec_auto;
 	int ret;
 
+	if (tb[ETHTOOL_A_FEC_STATS_CLEAR]) {
+		if (!dev->ethtool_ops->clear_fec_stats)
+			return -EOPNOTSUPP;
+
+		ret = dev->ethtool_ops->clear_fec_stats(dev);
+		return ret < 0 ? ret : 1;
+	}
+
 	ret = dev->ethtool_ops->get_fecparam(dev, &fec);
 	if (ret < 0)
 		return ret;
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 3e969a070f9f..2a2096066b7d 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -508,7 +508,7 @@ extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_
 extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1];
 extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];
 extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1];
-extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1];
+extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_MAX + 1];
 extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS + 1];
 extern const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_SRC + 1];
 extern const struct nla_policy ethnl_phc_vclocks_get_policy[ETHTOOL_A_PHC_VCLOCKS_HEADER + 1];
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help