Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ethtool: Add support for specifying information source in cable test results

Enhance the ethtool cable test interface by introducing the ability to
specify the source of the diagnostic information for cable test results.
This is particularly useful for PHYs that offer multiple diagnostic
methods, such as Time Domain Reflectometry (TDR) and Active Link Cable
Diagnostic (ALCD).

Key changes:
- Added `ethnl_cable_test_result_with_src` and
`ethnl_cable_test_fault_length_with_src` functions to allow specifying
the information source when reporting cable test results.
- Updated existing `ethnl_cable_test_result` and
`ethnl_cable_test_fault_length` functions to use TDR as the default
source, ensuring backward compatibility.
- Modified the UAPI to support these new attributes, enabling drivers to
provide more detailed diagnostic information.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20240822120703.1393130-3-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Oleksij Rempel and committed by
Jakub Kicinski
4715d87e abcd3026

+38 -10
+23 -6
include/linux/ethtool_netlink.h
··· 23 23 int ethnl_cable_test_alloc(struct phy_device *phydev, u8 cmd); 24 24 void ethnl_cable_test_free(struct phy_device *phydev); 25 25 void ethnl_cable_test_finished(struct phy_device *phydev); 26 - int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u8 result); 27 - int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm); 26 + int ethnl_cable_test_result_with_src(struct phy_device *phydev, u8 pair, 27 + u8 result, u32 src); 28 + int ethnl_cable_test_fault_length_with_src(struct phy_device *phydev, u8 pair, 29 + u32 cm, u32 src); 28 30 int ethnl_cable_test_amplitude(struct phy_device *phydev, u8 pair, s16 mV); 29 31 int ethnl_cable_test_pulse(struct phy_device *phydev, u16 mV); 30 32 int ethnl_cable_test_step(struct phy_device *phydev, u32 first, u32 last, ··· 56 54 static inline void ethnl_cable_test_finished(struct phy_device *phydev) 57 55 { 58 56 } 59 - static inline int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, 60 - u8 result) 57 + static inline int ethnl_cable_test_result_with_src(struct phy_device *phydev, 58 + u8 pair, u8 result, u32 src) 61 59 { 62 60 return -EOPNOTSUPP; 63 61 } 64 62 65 - static inline int ethnl_cable_test_fault_length(struct phy_device *phydev, 66 - u8 pair, u32 cm) 63 + static inline int ethnl_cable_test_fault_length_with_src(struct phy_device *phydev, 64 + u8 pair, u32 cm, u32 src) 67 65 { 68 66 return -EOPNOTSUPP; 69 67 } ··· 121 119 } 122 120 123 121 #endif /* IS_ENABLED(CONFIG_ETHTOOL_NETLINK) */ 122 + 123 + static inline int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, 124 + u8 result) 125 + { 126 + return ethnl_cable_test_result_with_src(phydev, pair, result, 127 + ETHTOOL_A_CABLE_INF_SRC_TDR); 128 + } 129 + 130 + static inline int ethnl_cable_test_fault_length(struct phy_device *phydev, 131 + u8 pair, u32 cm) 132 + { 133 + return ethnl_cable_test_fault_length_with_src(phydev, pair, cm, 134 + ETHTOOL_A_CABLE_INF_SRC_TDR); 135 + } 136 + 124 137 #endif /* _LINUX_ETHTOOL_NETLINK_H_ */
+15 -4
net/ethtool/cabletest.c
··· 164 164 } 165 165 EXPORT_SYMBOL_GPL(ethnl_cable_test_finished); 166 166 167 - int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u8 result) 167 + int ethnl_cable_test_result_with_src(struct phy_device *phydev, u8 pair, 168 + u8 result, u32 src) 168 169 { 169 170 struct nlattr *nest; 170 171 int ret = -EMSGSIZE; ··· 178 177 goto err; 179 178 if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_CODE, result)) 180 179 goto err; 180 + if (src != ETHTOOL_A_CABLE_INF_SRC_UNSPEC) { 181 + if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_RESULT_SRC, src)) 182 + goto err; 183 + } 181 184 182 185 nla_nest_end(phydev->skb, nest); 183 186 return 0; ··· 190 185 nla_nest_cancel(phydev->skb, nest); 191 186 return ret; 192 187 } 193 - EXPORT_SYMBOL_GPL(ethnl_cable_test_result); 188 + EXPORT_SYMBOL_GPL(ethnl_cable_test_result_with_src); 194 189 195 - int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) 190 + int ethnl_cable_test_fault_length_with_src(struct phy_device *phydev, u8 pair, 191 + u32 cm, u32 src) 196 192 { 197 193 struct nlattr *nest; 198 194 int ret = -EMSGSIZE; ··· 207 201 goto err; 208 202 if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) 209 203 goto err; 204 + if (src != ETHTOOL_A_CABLE_INF_SRC_UNSPEC) { 205 + if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_SRC, 206 + src)) 207 + goto err; 208 + } 210 209 211 210 nla_nest_end(phydev->skb, nest); 212 211 return 0; ··· 220 209 nla_nest_cancel(phydev->skb, nest); 221 210 return ret; 222 211 } 223 - EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length); 212 + EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length_with_src); 224 213 225 214 static const struct nla_policy cable_test_tdr_act_cfg_policy[] = { 226 215 [ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST] = { .type = NLA_U32 },