Skip to contentSkip to conversation

Add Clear fec-stats ethtool handler

RFC PATCH In review Pei Lee Ling 3 participants 4 messages Sep 21

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Add Clear fec-stats ethtool handler

ethtool: Add Clear fec-stats ethtool handler

During optical cable re-seating, transceiver swaps, or Bit Error Rate (BER) troubleshooting on 25G/100G/400G+ links, operators need to establish
a clean baseline for physical-layer FEC error counters (corrected/uncorrectable blocks).

Introduce a standardized netlink fec-clear operation using the ETHTOOL_MSG_FEC_SET message type with an ETHTOOL_A_FEC_STATS_CLEAR attribute. This provides a consistent and non-disruptive management interface that can be uniformly supported
across all required drivers.

Pei Lee Ling (1):
ethtool: Add Clear-fec-stats ethtool handler

 Documentation/netlink/specs/ethtool.yaml      |  3 ++
 include/linux/ethtool.h                       |  1 +
 include/uapi/linux/ethtool.h                  |  9 ++++++
 .../uapi/linux/ethtool_netlink_generated.h    |  1 +
 net/ethtool/fec.c                             | 30 +++++++++++++++++--
 net/ethtool/netlink.h                         |  2 +-
 6 files changed, 43 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/1 ethtool: Add Clear-fec-stats ethtool handler

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>

---
 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(-)
Documentation/netlink/specs/ethtool.yaml +3 -0
index 5dd4d1b5d94b..6943a6280f35 100644
@@ -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
include/linux/ethtool.h +1 -0
index 12683b5d125e..d5ec9f415adc 100644
@@ -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 *,
include/uapi/linux/ethtool_netlink_generated.h +1 -0
index 8134baf7860f..01c5b754c3db 100644
@@ -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)
net/ethtool/fec.c +10 -1
index e2d539271060..edfa535477cb 100644
@@ -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;
net/ethtool/netlink.h +1 -1
index 3e969a070f9f..2a2096066b7d 100644
@@ -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];
Signature · 1 line
2.43.0
maintainer
#2 lore raw
In reply to Pei Lee Ling
Quoted 8 lines · Pei Lee Ling

ethtool: Add Clear fec-stats ethtool handler

During optical cable re-seating, transceiver swaps, or Bit Error Rate (BER) troubleshooting on 25G/100G/400G+ links, operators need to establish
a clean baseline for physical-layer FEC error counters (corrected/uncorrectable blocks).

Introduce a standardized netlink fec-clear operation using the ETHTOOL_MSG_FEC_SET message type with an ETHTOOL_A_FEC_STATS_CLEAR attribute.

What makes FEC statistic counters special? As far as i know, no other network statistic can be set back to zero.

Because no other statistic can be reset, user space already has the code to handle delta in counters when needed.

Andrew

maintainer
#3 lore raw
In reply to Pei Lee Ling
Quoted 10 lines · On Mon, 21 Sep 2026 10:46:36 -0500 Pei Lee Ling wrote:

ethtool: Add Clear fec-stats ethtool handler

During optical cable re-seating, transceiver swaps, or Bit Error Rate (BER) troubleshooting on 25G/100G/400G+ links, operators need to establish
a clean baseline for physical-layer FEC error counters (corrected/uncorrectable blocks).

Introduce a standardized netlink fec-clear operation using the ETHTOOL_MSG_FEC_SET message type with an ETHTOOL_A_FEC_STATS_CLEAR attribute. This provides a consistent and non-disruptive management interface that can be uniformly supported
across all required drivers.

What do you really needs this for? Some local testing? Any real deployment will be computing deltas for counters so resettings counters would be meaningless or worse it will make deltas negative. Perhaps you can fix your tests ?