Message ID | 20200505001821.208534-8-andrew@lunn.ch |
---|---|
State | Changes Requested |
Delegated to: | David Miller |
Headers | show |
Series | Ethernet Cable test support | expand |
On 5/4/2020 5:18 PM, Andrew Lunn wrote: > The PHY drivers can use these helpers for reporting the results. The > results get translated into netlink attributes which are added to the > pre-allocated skbuf. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
On Tue, May 05, 2020 at 02:18:18AM +0200, Andrew Lunn wrote: > The PHY drivers can use these helpers for reporting the results. The > results get translated into netlink attributes which are added to the > pre-allocated skbuf. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> > --- [...] > diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c > index 4c888db33ef0..f500454a54eb 100644 > --- a/net/ethtool/cabletest.c > +++ b/net/ethtool/cabletest.c > @@ -114,3 +114,50 @@ void ethnl_cable_test_finished(struct phy_device *phydev) > ethnl_multicast(phydev->skb, phydev->attached_dev); > } > EXPORT_SYMBOL_GPL(ethnl_cable_test_finished); > + > +int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u16 result) Is there a reason to use u16 for result when the attribute is NLA_U8? > +{ > + struct nlattr *nest; > + int ret = -EMSGSIZE; > + > + nest = nla_nest_start(phydev->skb, ETHTOOL_A_CABLE_TEST_NTF_RESULT); > + if (!nest) > + return -EMSGSIZE; > + > + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_PAIR, pair)) > + goto err; > + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_CODE, result)) > + goto err; > + > + nla_nest_end(phydev->skb, nest); > + return 0; > + > +err: > + nla_nest_cancel(phydev->skb, nest); > + return ret; > +} > +EXPORT_SYMBOL_GPL(ethnl_cable_test_result); > + > +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) > +{ > + struct nlattr *nest; > + int ret = -EMSGSIZE; > + > + nest = nla_nest_start(phydev->skb, > + ETHTOOL_A_CABLE_TEST_NTF_FAULT_LENGTH); > + if (!nest) > + return -EMSGSIZE; > + > + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR, pair)) > + goto err; > + if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) > + goto err; This should be nla_put_u32(). Michal > + > + nla_nest_end(phydev->skb, nest); > + return 0; > + > +err: > + nla_nest_cancel(phydev->skb, nest); > + return ret; > +} > +EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length); > -- > 2.26.2 >
> > +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) > > +{ > > + struct nlattr *nest; > > + int ret = -EMSGSIZE; > > + > > + nest = nla_nest_start(phydev->skb, > > + ETHTOOL_A_CABLE_TEST_NTF_FAULT_LENGTH); > > + if (!nest) > > + return -EMSGSIZE; > > + > > + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR, pair)) > > + goto err; > > + if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) > > + goto err; > > This should be nla_put_u32(). Yes. I think i messed up a rebase merge conflict somewhere. I'm also surprised user space is not complaining. Andrew
On Tue, May 05, 2020 at 03:22:03PM +0200, Andrew Lunn wrote: > > > +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) > > > +{ > > > + struct nlattr *nest; > > > + int ret = -EMSGSIZE; > > > + > > > + nest = nla_nest_start(phydev->skb, > > > + ETHTOOL_A_CABLE_TEST_NTF_FAULT_LENGTH); > > > + if (!nest) > > > + return -EMSGSIZE; > > > + > > > + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR, pair)) > > > + goto err; > > > + if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) > > > + goto err; > > > > This should be nla_put_u32(). > > Yes. I think i messed up a rebase merge conflict somewhere. I'm also > surprised user space is not complaining. There is no difference on little endian architectures as nla_put_*() helpers all call __nla_reserve() which fills the padding with zero bytes. IIRC there was a case where wrong attribute type had been used for quite long without anyone noticing. Michal
diff --git a/include/linux/ethtool_netlink.h b/include/linux/ethtool_netlink.h index 7d763ba22f6f..0d12abbdf3c3 100644 --- a/include/linux/ethtool_netlink.h +++ b/include/linux/ethtool_netlink.h @@ -20,6 +20,8 @@ struct phy_device; int ethnl_cable_test_alloc(struct phy_device *phydev); void ethnl_cable_test_free(struct phy_device *phydev); void ethnl_cable_test_finished(struct phy_device *phydev); +int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u16 result); +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm); #else static inline int ethnl_cable_test_alloc(struct phy_device *phydev) { @@ -33,5 +35,16 @@ static inline void ethnl_cable_test_free(struct phy_device *phydev) static inline void ethnl_cable_test_finished(struct phy_device *phydev) { } +static inline int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, + u16 result) +{ + return -ENOTSUPP; +} + +static inline int ethnl_cable_test_fault_length(struct phy_device *phydev, + u8 pair, u16 cm) +{ + return -ENOTSUPP; +} #endif /* IS_ENABLED(ETHTOOL_NETLINK) */ #endif /* _LINUX_ETHTOOL_NETLINK_H_ */ diff --git a/include/linux/phy.h b/include/linux/phy.h index ee69f781995a..856b4293a645 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1229,6 +1229,10 @@ int phy_start_cable_test(struct phy_device *phydev, } #endif +int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result); +int phy_cable_test_fault_length(struct phy_device *phydev, u8 pair, + u16 cm); + static inline void phy_device_reset(struct phy_device *phydev, int value) { mdio_device_reset(&phydev->mdio, value); diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index 4c888db33ef0..f500454a54eb 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -114,3 +114,50 @@ void ethnl_cable_test_finished(struct phy_device *phydev) ethnl_multicast(phydev->skb, phydev->attached_dev); } EXPORT_SYMBOL_GPL(ethnl_cable_test_finished); + +int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u16 result) +{ + struct nlattr *nest; + int ret = -EMSGSIZE; + + nest = nla_nest_start(phydev->skb, ETHTOOL_A_CABLE_TEST_NTF_RESULT); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_PAIR, pair)) + goto err; + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_RESULT_CODE, result)) + goto err; + + nla_nest_end(phydev->skb, nest); + return 0; + +err: + nla_nest_cancel(phydev->skb, nest); + return ret; +} +EXPORT_SYMBOL_GPL(ethnl_cable_test_result); + +int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) +{ + struct nlattr *nest; + int ret = -EMSGSIZE; + + nest = nla_nest_start(phydev->skb, + ETHTOOL_A_CABLE_TEST_NTF_FAULT_LENGTH); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR, pair)) + goto err; + if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_FAULT_LENGTH_CM, cm)) + goto err; + + nla_nest_end(phydev->skb, nest); + return 0; + +err: + nla_nest_cancel(phydev->skb, nest); + return ret; +} +EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length);
The PHY drivers can use these helpers for reporting the results. The results get translated into netlink attributes which are added to the pre-allocated skbuf. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- include/linux/ethtool_netlink.h | 13 +++++++++ include/linux/phy.h | 4 +++ net/ethtool/cabletest.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+)