Ethernet Cable test support
Subsystems (6)
Andrew Lunn
maintainerv4 cover Ethernet Cable test support
any copper Ethernet PHY have support for performing diagnostics of the cable. Are the cable shorted, broken, not plugged into anything at the other end? And they can report roughly how far along the cable any fault is.
Add infrastructure in ethtool and phylib support for triggering a cable test and reporting the results. The Marvell 1G PHY driver is then extended to make use of this infrastructure.
For testing, a modified ethtool(1) can be found here:
https://github.com/lunn/ethtool.git feature/cable-test-v4. This also contains extra code for TDR dump, which will be added to the kernel in a later patch series.
Thanks to Chris Healy for extensive testing.
v2:
See individual patches but:
Remove _REPLY messages
Change length into a u32
Grammar fixes
Rename functions for consistency
Extack for cable test already running
Remove ethnl_cable_test_act_ops
Add status attributes
Rename pairs from numbers to letters
v3:
See individual patches but:
Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY from documentation Remove unused cable_test_get_policy
Fixed example in document
Add ETHTOOL_A_CABLE_NEST_* enum
Add ETHTOOL_MSG_CABLE_TEST_NTF to documentation
Poison phydev->skb
Return -EMSGSIZE when ethnl_bcastmsg_put() fails
Return valid error code when nla_nest_start() fails
Use u8 for results
Actually put u32 length into message
s/mavell/marvell/g
Remove include of <uapi/linux/ethtool_netlink.h> EMSGSIZE when ethnl_bcastmsg_put() fails
Print an error message on failure, since this is a void function.
v4:
See individual patches but:
Remove unwanted blank lineENOTSUPP->EOPNOTSUPP
Move EINVAL->EMSGSIZE fix to correct patch
Andrew Lunn (10):
net: phy: Add cable test support to state machine
net: phy: Add support for polling cable test
net: ethtool: netlink: Add support for triggering a cable test
net: ethtool: Add attributes for cable test reports
net: ethtool: Make helpers public
net: ethtool: Add infrastructure for reporting cable test results
net: ethtool: Add helpers for reporting test results
net: phy: marvell: Add cable test support
net: phy: Put interface into oper testing during cable test
net: phy: Send notifier when starting the cable test
Documentation/networking/ethtool-netlink.rst | 57 +++++- drivers/net/phy/marvell.c | 201 +++++++++++++++++++ drivers/net/phy/phy.c | 106 ++++++++++ include/linux/ethtool_netlink.h | 33 +++ include/linux/phy.h | 42 ++++ include/uapi/linux/ethtool_netlink.h | 71 +++++++ net/Kconfig | 1 + net/ethtool/Makefile | 2 +- net/ethtool/cabletest.c | 201 +++++++++++++++++++ net/ethtool/netlink.c | 9 +- net/ethtool/netlink.h | 3 + 11 files changed, 722 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/cabletest.c
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 1/1 net: phy: Send notifier when starting the cable test
Given that it takes time to run a cable test, send a notify message at the start, as well as when it is completed.
v3:
EMSGSIZE when ethnl_bcastmsg_put() fails
Print an error message on failure, since this is a void function.
--- net/ethtool/cabletest.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
net/ethtool/cabletest.c +41 -0
@@ -13,6 +13,43 @@ cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, }; +static int ethnl_cable_test_started (struct phy_device *phydev) +{ +struct sk_buff *skb; +int err = -ENOMEM ; +void *ehdr; + + skb =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!skb) + goto out; + + ehdr =ethnl_bcastmsg_put (skb,ETHTOOL_MSG_CABLE_TEST_NTF ); +if (!ehdr) { + err = -EMSGSIZE ; + goto out; + } + + err =ethnl_fill_reply_header (skb, phydev->attached_dev, +ETHTOOL_A_CABLE_TEST_NTF_HEADER ); +if (err) + goto out; + + err =nla_put_u8 (skb,ETHTOOL_A_CABLE_TEST_NTF_STATUS , +ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED ); +if (err) + goto out; + +genlmsg_end (skb, ehdr); + +return ethnl_multicast (skb, phydev->attached_dev); + +out: +nlmsg_free (skb); +phydev_err (phydev,"%s: Error %pe\n" , __func__,ERR_PTR (err)); + +return err; +} +int ethnl_act_cable_test (struct sk_buff *skb,struct genl_info *info) {struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX +1 ];
@@ -47,6 +84,10 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ret =phy_start_cable_test (dev->phydev, info->extack);ethnl_ops_complete (dev); + +if (!ret) +ethnl_cable_test_started (dev->phydev); + out_rtnl:rtnl_unlock (); out_dev_put:
Signature · 1 line
2.26.2
Andrew Lunn
maintainerRe: [PATCH net-next v4 1/1] net: phy: Send notifier when starting the cable test
Quoted 2 lines · Andrew Lunn
Given that it takes time to run a cable test, send a notify message at the start, as well as when it is completed.
Arg! This patch does not belong in the series!
Andrew
Andrew Lunn
maintainerPATCH v4 1/10 net: phy: Add cable test support to state machine
In reply to Andrew LunnRunning a cable test is desruptive to normal operation of the PHY and can take a 5 to 10 seconds to complete. The RTNL lock cannot be held for this amount of time, and add a new state to the state machine for running a cable test.
The driver is expected to implement two functions. The first is used to start a cable test. Once the test has started, it should return.
The second function is called once per second, or on interrupt to check if the cable test is complete, and to allow the PHY to report the status.
v2:
Rename phy_cable_test_abort to phy_abort_cable_test Return different extack when already running test Use phy_init_hw() to reset the PHY
--- drivers/net/phy/phy.c | 76 +++++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 28 ++++++++++++++++ 2 files changed, 104 insertions(+)
drivers/net/phy/phy.c +76 -0
@@ -15,6 +15,7 @@#include <linux/interrupt.h> #include <linux/delay.h> #include <linux/netdevice.h> +#include <linux/netlink.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/mm.h>
@@ -44,6 +45,7 @@ static const char *phy_state_to_str(enum phy_state st) PHY_STATE_STR(UP) PHY_STATE_STR(RUNNING) PHY_STATE_STR(NOLINK) + PHY_STATE_STR(CABLETEST) PHY_STATE_STR(HALTED) }
@@ -472,6 +474,62 @@ static void phy_trigger_machine(struct phy_device *phydev)phy_queue_state_machine (phydev,0 ); } +static void phy_abort_cable_test (struct phy_device *phydev) +{ +int err; + + err =phy_init_hw (phydev); +if (err) +phydev_err (phydev,"Error while aborting cable test" ); +} + +int phy_start_cable_test (struct phy_device *phydev, +struct netlink_ext_ack *extack) +{ +int err; + +if (!(phydev->drv && + phydev->drv->cable_test_start && + phydev->drv->cable_test_get_status)) { +NL_SET_ERR_MSG (extack, +"PHY driver does not support cable testing" ); +return -EOPNOTSUPP ; + } + +mutex_lock (&phydev->lock); +if (phydev->state ==PHY_CABLETEST ) { +NL_SET_ERR_MSG (extack, +"PHY already performing a test" ); + err = -EBUSY ; + goto out; + } + +if (phydev->state <PHY_UP || + phydev->state >PHY_CABLETEST ) { +NL_SET_ERR_MSG (extack, +"PHY not configured. Try setting interface up" ); + err = -EBUSY ; + goto out; + } + +/* Mark the carrier down until the test is complete */ +phy_link_down (phydev, true); + + err = phydev->drv->cable_test_start (phydev); +if (err) { +phy_link_up (phydev); + goto out; + } + + phydev->state =PHY_CABLETEST ; + +out: +mutex_unlock (&phydev->lock); + +return err; +} +EXPORT_SYMBOL (phy_start_cable_test); +static int phy_config_aneg (struct phy_device *phydev) {if (phydev->drv->config_aneg)
@@ -810,6 +868,9 @@ void phy_stop(struct phy_device *phydev)mutex_lock (&phydev->lock); +if (phydev->state ==PHY_CABLETEST ) +phy_abort_cable_test (phydev); +if (phydev->sfp_bus)sfp_upstream_stop (phydev->sfp_bus);
@@ -872,6 +933,7 @@ void phy_state_machine(struct work_struct *work) container_of(dwork, struct phy_device, state_queue);bool needs_aneg = false, do_suspend = false;enum phy_state old_state; +bool finished = false;int err =0 ;mutex_lock (&phydev->lock);
@@ -890,6 +952,20 @@ void phy_state_machine(struct work_struct *work)case PHY_RUNNING : err =phy_check_link_status (phydev);break ; +case PHY_CABLETEST : + err = phydev->drv->cable_test_get_status (phydev, &finished); +if (err) { +phy_abort_cable_test (phydev); + needs_aneg = true; + phydev->state =PHY_UP ; +break ; + } + +if (finished) { + needs_aneg = true; + phydev->state =PHY_UP ; + } +break ;case PHY_HALTED :if (phydev->link) { phydev->link =0 ;
include/linux/phy.h +28 -0
@@ -15,6 +15,7 @@#include <linux/spinlock.h> #include <linux/ethtool.h> #include <linux/linkmode.h> +#include <linux/netlink.h> #include <linux/mdio.h> #include <linux/mii.h> #include <linux/mii_timestamper.h>
@@ -372,6 +373,12 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);* - irq or timer will set NOLINK if link goes down * - phy_stop moves to HALTED * +* CABLETEST: PHY is performing a cable test. Packet reception/sending +* is not expected to work, carrier will be indicated as down. PHY will be +* poll once per second, or on interrupt for it current state. +* Once complete, move to UP to restart the PHY. +* - phy_stop aborts the running test and moves to HALTED +* * HALTED: PHY is up, but no polling or interrupts are done. Or * PHY is in an error state. * - phy_start moves to UP
@@ -383,6 +390,7 @@ enum phy_state {PHY_UP ,PHY_RUNNING ,PHY_NOLINK , + PHY_CABLETEST, };/**
@@ -689,6 +697,13 @@ struct phy_driver {int (*module_eeprom)(struct phy_device *dev,struct ethtool_eeprom *ee,u8 *data); +/* Start a cable test */ +int (*cable_test_start)(struct phy_device *dev); +/* Once per second, or on interrupt, request the status of the +* test. +*/ +int (*cable_test_get_status)(struct phy_device *dev,bool *finished); +/* Get statistics from the phy using ethtool */ int (*get_sset_count)(struct phy_device *dev);void (*get_strings)(struct phy_device *dev,u8 *data);
@@ -1227,6 +1242,19 @@ int phy_speed_up(struct phy_device *phydev);int phy_restart_aneg (struct phy_device *phydev);int phy_reset_after_clk_enable (struct phy_device *phydev); +#if IS_ENABLED (CONFIG_PHYLIB ) +int phy_start_cable_test (struct phy_device *phydev, +struct netlink_ext_ack *extack); +#else +static inline +int phy_start_cable_test (struct phy_device *phydev, +struct netlink_ext_ack *extack) +{ +NL_SET_ERR_MSG (extack,"Kernel not compiled with PHYLIB support" ); +return -EOPNOTSUPP ; +} +#endif +static inline void phy_device_reset (struct phy_device *phydev,int value) {mdio_device_reset (&phydev->mdio, value);
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 2/10 net: phy: Add support for polling cable test
In reply to Andrew LunnSome PHYs are not capable of generating interrupts when a cable test finished. They do however support interrupts for normal operations, like link up/down. As such, the PHY state machine would normally not poll the PHY.
Add support for indicating the PHY state machine must poll the PHY when performing a cable test.
--- drivers/net/phy/phy.c | 2 ++ include/linux/phy.h | 5 +++++ 2 files changed, 7 insertions(+)
drivers/net/phy/phy.c +2 -0
@@ -523,6 +523,8 @@ int phy_start_cable_test(struct phy_device *phydev, phydev->state =PHY_CABLETEST ; +if (phy_polling_mode (phydev)) +phy_trigger_machine (phydev); out:mutex_unlock (&phydev->lock);
include/linux/phy.h +5 -0
@@ -79,6 +79,7 @@ extern const int phy_10gbit_features_array[1];#define PHY_IS_INTERNAL 0x00000001#define PHY_RST_AFTER_CLK_EN 0x00000002 +#define PHY_POLL_CABLE_TEST 0x00000004#define MDIO_DEVICE_IS_PHY 0x80000000/* Interface Mode definitions */
@@ -1061,6 +1062,10 @@ static inline bool phy_interrupt_is_valid(struct phy_device *phydev)*/ static inline bool phy_polling_mode (struct phy_device *phydev) { +if (phydev->state ==PHY_CABLETEST ) +if (phydev->drv->flags &PHY_POLL_CABLE_TEST ) +return true; +return phydev->irq ==PHY_POLL ; }
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 3/10 net: ethtool: netlink: Add support for triggering a cable test
In reply to Andrew LunnAdd new ethtool netlink calls to trigger the starting of a PHY cable test.
Add Kconfig'ury to ETHTOOL_NETLINK so that PHYLIB is not a module when ETHTOOL_NETLINK is builtin, which would result in kernel linking errors.
v2:
Remove unwanted white space change
Remove ethnl_cable_test_act_ops and use doit handler Rename cable_test_set_policy cable_test_act_policy Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY
v3:
Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY from documentation Remove unused cable_test_get_policy
Add Reviewed-by tags
v4:
Remove unwanted blank line
--- Documentation/networking/ethtool-netlink.rst | 16 +++++- include/uapi/linux/ethtool_netlink.h | 12 +++++ net/Kconfig | 1 + net/ethtool/Makefile | 2 +- net/ethtool/cabletest.c | 54 ++++++++++++++++++++ net/ethtool/netlink.c | 5 ++ net/ethtool/netlink.h | 1 + 7 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 net/ethtool/cabletest.c
Documentation/networking/ethtool-netlink.rst +15 -1
@@ -204,6 +204,7 @@ Userspace to kernel: ``ETHTOOL_MSG_EEE_GET`` get EEE settings ``ETHTOOL_MSG_EEE_SET`` set EEE settings ``ETHTOOL_MSG_TSINFO_GET`` get timestamping info + ``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test ===================================== ================================ Kernel to userspace:
@@ -958,13 +959,25 @@ Kernel response contents: is no special value for this case). The bitset attributes are omitted if they would be empty (no bit set). +CABLE_TEST +========== + +Start a cable test. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_CABLE_TEST_HEADER`` nested request header + ==================================== ====== ========================== + Request translation =================== The following table maps ioctl commands to netlink commands providing their functionality. Entries with "n/a" in right column are commands which do not -have their netlink replacement yet. +have their netlink replacement yet. Entries which "n/a" in the left column +are netlink only. =================================== ===================================== ioctl command netlink command
@@ -1053,4 +1066,5 @@ have their netlink replacement yet. ``ETHTOOL_PHY_STUNABLE`` n/a ``ETHTOOL_GFECPARAM`` n/a ``ETHTOOL_SFECPARAM`` n/a + n/a ''ETHTOOL_MSG_CABLE_TEST_ACT'' =================================== =====================================
include/uapi/linux/ethtool_netlink.h +12 -0
@@ -39,6 +39,7 @@ enum {ETHTOOL_MSG_EEE_GET ,ETHTOOL_MSG_EEE_SET ,ETHTOOL_MSG_TSINFO_GET , +ETHTOOL_MSG_CABLE_TEST_ACT ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -405,6 +406,17 @@ enum { ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1) }; +/* CABLE TEST */ + +enum { +ETHTOOL_A_CABLE_TEST_UNSPEC , +ETHTOOL_A_CABLE_TEST_HEADER ,/* nest - _A_HEADER_* */ + +/* add new constants above here */ + __ETHTOOL_A_CABLE_TEST_CNT, +ETHTOOL_A_CABLE_TEST_MAX = __ETHTOOL_A_CABLE_TEST_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/Kconfig +1 -0
@@ -455,6 +455,7 @@ config FAILOVER config ETHTOOL_NETLINK bool "Netlink interface for ethtool" default y + depends on PHYLIB=y || PHYLIB=n help An alternative userspace interface for ethtool based on generic netlink. It provides better extensibility and some new features,
net/ethtool/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ - channels.o coalesce.o pause.o eee.o tsinfo.o + channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o
net/ethtool/cabletest.c new file +54 -0
54 lines not on this page · raw message
net/ethtool/netlink.c +5 -0
@@ -839,6 +839,11 @@ static const struct genl_ops ethtool_genl_ops[] = { .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, }, + { + .cmd = ETHTOOL_MSG_CABLE_TEST_ACT, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_act_cable_test, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -357,5 +357,6 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info);int ethnl_set_coalesce (struct sk_buff *skb,struct genl_info *info);int ethnl_set_pause (struct sk_buff *skb,struct genl_info *info);int ethnl_set_eee (struct sk_buff *skb,struct genl_info *info); +int ethnl_act_cable_test (struct sk_buff *skb,struct genl_info *info);#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.26.2
Jakub Kicinski
maintainerRe: [PATCH net-next v4 03/10] net: ethtool: netlink: Add support for triggering a cable test
net/Kconfig config FAILOVER · line 461
Quoted 12 lines · On Sun, 10 May 2020 21:12:33 +0200 Andrew Lunn wrote:
net/Kconfig +1
-0@@ -455,6 +455,7 @@ config FAILOVER config ETHTOOL_NETLINK bool "Netlink interface for ethtool" default y + depends on PHYLIB=y || PHYLIB=n help An alternative userspace interface for ethtool based on generic netlink. It provides better extensibility and some new features,
Since ETHTOOL_NETLINK is a bool we end up not enabling it on allmodconfig builds, (PHYLIB=m so ETHTOOL_NETLINK dependency can't be met) - which is v scary for build testing.
Is there a way we can change this dependency? Some REACHABLE shenanigans?
Or since there are just two callbacks maybe phylib can "tell" ethtool core the pointers to call when it loads?
David Miller
maintainerRe: [PATCH net-next v4 03/10] net: ethtool: netlink: Add support for triggering a cable test
From: Jakub Kicinski <[email protected]>
Date: Wed, 1 Jul 2020 15:56:21 -0700
Quoted 18 lines · On Sun, 10 May 2020 21:12:33 +0200 Andrew Lunn wrote:
net/Kconfig config FAILOVER · line 461
Quoted 12 lines
net/Kconfig +1
-0@@ -455,6 +455,7 @@ config FAILOVER config ETHTOOL_NETLINK bool "Netlink interface for ethtool" default y + depends on PHYLIB=y || PHYLIB=n help An alternative userspace interface for ethtool based on generic netlink. It provides better extensibility and some new features,Since
ETHTOOL_NETLINKis a bool we end up not enabling it on allmodconfig builds, (PHYLIB=m soETHTOOL_NETLINKdependency can't be met) - which is v scary for build testing.
Quoted 4 lines
Is there a way we can change this dependency? Some REACHABLE shenanigans?
Or since there are just two callbacks maybe phylib can "tell" ethtool core the pointers to call when it loads?
This has been discussed a few times and it's very irritating to me as well as allmodconfig is the standard test build I do for all new changes.
Re: [PATCH net-next v4 03/10] net: ethtool: netlink: Add support for triggering a cable test
Quoted 21 lines · David Miller
From: Jakub Kicinski <[email protected]>
Date: Wed, 1 Jul 2020 15:56:21 -0700Quoted 18 lines · On Sun, 10 May 2020 21:12:33 +0200 Andrew Lunn wrote:
net/Kconfig config FAILOVER · line 461
Quoted 12 lines
net/Kconfig +1
-0@@ -455,6 +455,7 @@ config FAILOVER config ETHTOOL_NETLINK bool "Netlink interface for ethtool" default y + depends on PHYLIB=y || PHYLIB=n help An alternative userspace interface for ethtool based on generic netlink. It provides better extensibility and some new features,Since
ETHTOOL_NETLINKis a bool we end up not enabling it on allmodconfig builds, (PHYLIB=m soETHTOOL_NETLINKdependency can't be met) - which is v scary for build testing.
Quoted 7 lines
Quoted 4 lines
Is there a way we can change this dependency? Some REACHABLE shenanigans?
Or since there are just two callbacks maybe phylib can "tell" ethtool core the pointers to call when it loads?
This has been discussed a few times and it's very irritating to me as well as allmodconfig is the standard test build I do for all new changes.
Yes this is annoying, I will have some patches posted tonight that untangle the dependency.
Signature · 1 line
Florian
David Miller
maintainerRe: [PATCH net-next v4 03/10] net: ethtool: netlink: Add support for triggering a cable test
From: Florian Fainelli <[email protected]>
Date: Wed, 1 Jul 2020 17:26:23 -0700
Quoted 2 lines
Yes this is annoying, I will have some patches posted tonight that untangle the dependency.
Thank you.
Andrew Lunn
maintainerPATCH v4 4/10 net: ethtool: Add attributes for cable test reports
In reply to Andrew LunnAdd the attributes needed to report cable test results to userspace. The reports are expected to be per twisted pair. A nested property per pair can report the result of the cable test. A nested property can also report the length of the cable to any fault.
v2:
Grammar fixes
Change length from u16 to u32
s/DEV/HEADER/g
Add status attributes
Rename pairs from numbers to letters.
v3:
Fixed example in document
Add ETHTOOL_A_CABLE_NEST_* enum
Add ETHTOOL_MSG_CABLE_TEST_NTF to documentation
--- Documentation/networking/ethtool-netlink.rst | 41 ++++++++++++++ include/uapi/linux/ethtool_netlink.h | 59 ++++++++++++++++++++ 2 files changed, 100 insertions(+)
Documentation/networking/ethtool-netlink.rst +41 -0
@@ -236,6 +236,7 @@ Kernel to userspace: ``ETHTOOL_MSG_EEE_GET_REPLY`` EEE settings ``ETHTOOL_MSG_EEE_NTF`` EEE settings ``ETHTOOL_MSG_TSINFO_GET_REPLY`` timestamping info + ``ETHTOOL_MSG_CABLE_TEST_NTF`` Cable test results ===================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device
@@ -970,6 +971,46 @@ Request contents: ``ETHTOOL_A_CABLE_TEST_HEADER`` nested request header ==================================== ====== ========================== +Notification contents: + +An Ethernet cable typically contains 1, 2 or 4 pairs. The length of +the pair can only be measured when there is a fault in the pair and +hence a reflection. Information about the fault may not be available, +depending on the specific hardware. Hence the contents of the notify +message are mostly optional. The attributes can be repeated an +arbitrary number of times, in an arbitrary order, for an arbitrary +number of pairs. + +The example shows the notification sent when the test is completed for +a T2 cable, i.e. two pairs. One pair is OK and hence has no length +information. The second pair has a fault and does have length +information. + + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_CABLE_TEST_HEADER`` | nested | reply header | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_CABLE_TEST_STATUS`` | u8 | completed | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_CABLE_TEST_NTF_NEST`` | nested | all the results | + +-+-------------------------------------------+--------+---------------------+ + | | ``ETHTOOL_A_CABLE_NEST_RESULT`` | nested | cable test result | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_RESULTS_CODE`` | u8 | result code | + +-+-+-----------------------------------------+--------+---------------------+ + | | ``ETHTOOL_A_CABLE_NEST_RESULT`` | nested | cable test results | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_RESULTS_CODE`` | u8 | result code | + +-+-+-----------------------------------------+--------+---------------------+ + | | ``ETHTOOL_A_CABLE_NEST_FAULT_LENGTH`` | nested | cable length | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR`` | u8 | pair number | + +-+-+-----------------------------------------+--------+---------------------+ + | | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_CM`` | u32 | length in cm | + +-+-+-----------------------------------------+--------+---------------------+ Request translation ===================
include/uapi/linux/ethtool_netlink.h +59 -0
71 lines not on this page · raw message
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 5/10 net: ethtool: Make helpers public
In reply to Andrew LunnMake some helpers for building ethtool netlink messages available outside the compilation unit, so they can be used for building messages which are not simple get/set.
--- net/ethtool/netlink.c | 4 ++-- net/ethtool/netlink.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
net/ethtool/netlink.c +2 -2
@@ -181,13 +181,13 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,return NULL ; } -static void *ethnl_bcastmsg_put (struct sk_buff *skb,u8 cmd) +void *ethnl_bcastmsg_put (struct sk_buff *skb,u8 cmd) {return genlmsg_put (skb,0 , ++ethnl_bcast_seq, ðtool_genl_family,0 , cmd); } -static int ethnl_multicast (struct sk_buff *skb,struct net_device *dev) +int ethnl_multicast (struct sk_buff *skb,struct net_device *dev) {return genlmsg_multicast_netns (ðtool_genl_family,dev_net (dev), skb,0 ,ETHNL_MCGRP_MONITOR ,GFP_KERNEL );
net/ethtool/netlink.h +2 -0
@@ -19,6 +19,8 @@ int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,struct sk_buff *ethnl_reply_init (size_t payload,struct net_device *dev,u8 cmd,u16 hdr_attrtype,struct genl_info *info,void **ehdrp); +void *ethnl_bcastmsg_put (struct sk_buff *skb,u8 cmd); +int ethnl_multicast (struct sk_buff *skb,struct net_device *dev);/** * ethnl_strz_size() - calculate attribute length for fixed size string
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 6/10 net: ethtool: Add infrastructure for reporting cable test results
In reply to Andrew LunnProvide infrastructure for PHY drivers to report the cable test results. A netlink skb is associated to the phydev. Helpers will be added which can add results to this skb. Once the test has finished the results are sent to user space.
When netlink ethtool is not part of the kernel configuration stubs are provided. It is also impossible to trigger a cable test, so the error code returned by the alloc function is of no consequence.
v2:
Include the status complete in the netlink notification message
v4:
Replace -EINVAL with -EMSGSIZE
--- drivers/net/phy/phy.c | 22 +++++++++++-- include/linux/ethtool_netlink.h | 20 ++++++++++++ include/linux/phy.h | 5 +++ net/ethtool/cabletest.c | 55 +++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +20 -2
@@ -22,6 +22,7 @@#include <linux/module.h> #include <linux/mii.h> #include <linux/ethtool.h> +#include <linux/ethtool_netlink.h> #include <linux/phy.h> #include <linux/phy_led_triggers.h> #include <linux/sfp.h>
@@ -30,6 +31,9 @@#include <linux/io.h> #include <linux/uaccess.h> #include <linux/atomic.h> +#include <net/netlink.h> +#include <net/genetlink.h> +#include <net/sock.h> #define PHY_STATE_TIME HZ
@@ -478,6 +482,8 @@ static void phy_abort_cable_test(struct phy_device *phydev) {int err; +ethnl_cable_test_finished (phydev); + err =phy_init_hw (phydev);if (err)phydev_err (phydev,"Error while aborting cable test" );
@@ -486,7 +492,7 @@ static void phy_abort_cable_test(struct phy_device *phydev)int phy_start_cable_test (struct phy_device *phydev,struct netlink_ext_ack *extack) { -int err; +int err = -ENOMEM ; if (!(phydev->drv && phydev->drv->cable_test_start &&
@@ -512,19 +518,30 @@ int phy_start_cable_test(struct phy_device *phydev, goto out; } + err =ethnl_cable_test_alloc (phydev); +if (err) + goto out; +/* Mark the carrier down until the test is complete */ phy_link_down (phydev, true); err = phydev->drv->cable_test_start (phydev);if (err) {phy_link_up (phydev); - goto out; + goto out_free; } phydev->state =PHY_CABLETEST ;if (phy_polling_mode (phydev))phy_trigger_machine (phydev); + +mutex_unlock (&phydev->lock); + +return 0 ; + +out_free: +ethnl_cable_test_free (phydev); out:mutex_unlock (&phydev->lock);
@@ -964,6 +981,7 @@ void phy_state_machine(struct work_struct *work) }if (finished) { +ethnl_cable_test_finished (phydev); needs_aneg = true; phydev->state =PHY_UP ; }
include/linux/ethtool_netlink.h +20 -0
@@ -14,4 +14,24 @@ enum ethtool_multicast_groups { ETHNL_MCGRP_MONITOR, }; +struct phy_device ; + +#if IS_ENABLED (CONFIG_ETHTOOL_NETLINK ) +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); +#else +static inline int ethnl_cable_test_alloc (struct phy_device *phydev) +{ +return -ENOTSUPP ; +} + +static inline void ethnl_cable_test_free (struct phy_device *phydev) +{ +} + +static inline void ethnl_cable_test_finished (struct phy_device *phydev) +{ +} +#endif /* IS_ENABLED(ETHTOOL_NETLINK) */ #endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/linux/phy.h +5 -0
@@ -523,6 +523,11 @@ struct phy_device {/* For use by PHYs inside the same package that need a shared state. */ struct phy_package_shared *shared; +/* Reporting cable test results */ +struct sk_buff *skb; +void *ehdr; +struct nlattr *nest; +/* Interrupt and Polling infrastructure */ struct delayed_work state_queue;
net/ethtool/cabletest.c +55 -0
64 lines not on this page · raw message
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 7/10 net: ethtool: Add helpers for reporting test results
In reply to Andrew LunnThe 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.
v3:
Poison phydev->skb
Return -EMSGSIZE when ethnl_bcastmsg_put() fails Return valid error code when nla_nest_start() fails Use u8 for results
Actually put u32 length into message
v4:
s/ENOTSUPP/EOPNOTSUPP/g
--- include/linux/ethtool_netlink.h | 15 +++++++++- include/linux/phy.h | 4 +++ net/ethtool/cabletest.c | 53 ++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-)
include/linux/ethtool_netlink.h +14 -1
@@ -20,10 +20,12 @@ 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,u8 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) { -return -ENOTSUPP ; +return -EOPNOTSUPP ; }static inline void ethnl_cable_test_free (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, +u8 result) +{ +return -EOPNOTSUPP ; +} + +static inline int ethnl_cable_test_fault_length (struct phy_device *phydev, +u8 pair,u32 cm) +{ +return -EOPNOTSUPP ; +}#endif /* IS_ENABLED(ETHTOOL_NETLINK) */ #endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/linux/phy.h +4 -0
@@ -1265,6 +1265,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);
net/ethtool/cabletest.c +52 -1
74 lines not on this page · raw message
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 8/10 net: phy: marvell: Add cable test support
In reply to Andrew LunnThe Marvell PHYs have a couple of different register sets for performing cable tests. Page 7 provides the simplest to use.
v3:
s/mavell/marvell/g
Remove include of <uapi/linux/ethtool_netlink.h>
--- drivers/net/phy/marvell.c | 201 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+)
drivers/net/phy/marvell.c +201 -0
@@ -27,6 +27,7 @@#include <linux/module.h> #include <linux/mii.h> #include <linux/ethtool.h> +#include <linux/ethtool_netlink.h> #include <linux/phy.h> #include <linux/marvell_phy.h> #include <linux/bitfield.h>
@@ -42,6 +43,7 @@#define MII_MARVELL_MSCR_PAGE 0x02#define MII_MARVELL_LED_PAGE 0x03#define MII_MARVELL_MISC_TEST_PAGE 0x06 +#define MII_MARVELL_VCT7_PAGE 0x07#define MII_MARVELL_WOL_PAGE 0x11#define MII_M1011_IEVENT 0x13
@@ -162,6 +164,36 @@#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1/* SGMII to copper */ #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000/* Soft reset */ +#define MII_VCT7_PAIR_0_DISTANCE 0x10 +#define MII_VCT7_PAIR_1_DISTANCE 0x11 +#define MII_VCT7_PAIR_2_DISTANCE 0x12 +#define MII_VCT7_PAIR_3_DISTANCE 0x13 + +#define MII_VCT7_RESULTS 0x14 +#define MII_VCT7_RESULTS_PAIR3_MASK 0xf000 +#define MII_VCT7_RESULTS_PAIR2_MASK 0x0f00 +#define MII_VCT7_RESULTS_PAIR1_MASK 0x00f0 +#define MII_VCT7_RESULTS_PAIR0_MASK 0x000f +#define MII_VCT7_RESULTS_PAIR3_SHIFT 12 +#define MII_VCT7_RESULTS_PAIR2_SHIFT 8 +#define MII_VCT7_RESULTS_PAIR1_SHIFT 4 +#define MII_VCT7_RESULTS_PAIR0_SHIFT 0 +#define MII_VCT7_RESULTS_INVALID 0 +#define MII_VCT7_RESULTS_OK 1 +#define MII_VCT7_RESULTS_OPEN 2 +#define MII_VCT7_RESULTS_SAME_SHORT 3 +#define MII_VCT7_RESULTS_CROSS_SHORT 4 +#define MII_VCT7_RESULTS_BUSY 9 + +#define MII_VCT7_CTRL 0x15 +#define MII_VCT7_CTRL_RUN_NOW BIT(15) +#define MII_VCT7_CTRL_RUN_ANEG BIT(14) +#define MII_VCT7_CTRL_DISABLE_CROSS BIT(13) +#define MII_VCT7_CTRL_RUN_AFTER_BREAK_LINK BIT(12) +#define MII_VCT7_CTRL_IN_PROGRESS BIT(11) +#define MII_VCT7_CTRL_METERS BIT(10) +#define MII_VCT7_CTRL_CENTIMETERS 0 +#define LPA_PAUSE_FIBER 0x180#define LPA_PAUSE_ASYM_FIBER 0x100
@@ -1658,6 +1690,163 @@ static void marvell_get_stats(struct phy_device *phydev, data[i] =marvell_get_stat (phydev, i); } +static int marvell_vct7_cable_test_start (struct phy_device *phydev) +{ +int bmcr, bmsr, ret; + +/* If auto-negotiation is enabled, but not complete, the cable +* test never completes. So disable auto-neg. +*/ + bmcr =phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmsr =phy_read (phydev,MII_BMSR ); + +if (bmsr <0 ) +return bmsr; + +if (bmcr &BMCR_ANENABLE ) { + ret =phy_modify (phydev,MII_BMCR ,BMCR_ANENABLE ,0 ); +if (ret <0 ) +return ret; + ret =genphy_soft_reset (phydev); +if (ret <0 ) +return ret; + } + +/* If the link is up, allow it some time to go down */ +if (bmsr &BMSR_LSTATUS ) +msleep (1500 ); + +return phy_write_paged (phydev,MII_MARVELL_VCT7_PAGE , +MII_VCT7_CTRL , +MII_VCT7_CTRL_RUN_NOW | +MII_VCT7_CTRL_CENTIMETERS ); +} + +static int marvell_vct7_distance_to_length (int distance,bool meter) +{ +if (meter) + distance *=100 ; + +return distance; +} + +static bool marvell_vct7_distance_valid (int result) +{ +switch (result) { +case MII_VCT7_RESULTS_OPEN : +case MII_VCT7_RESULTS_SAME_SHORT : +case MII_VCT7_RESULTS_CROSS_SHORT : +return true; + } +return false; +} + +static int marvell_vct7_report_length (struct phy_device *phydev, +int pair,bool meter) +{ +int length; +int ret; + + ret =phy_read_paged (phydev,MII_MARVELL_VCT7_PAGE , +MII_VCT7_PAIR_0_DISTANCE + pair); +if (ret <0 ) +return ret; + + length =marvell_vct7_distance_to_length (ret, meter); + +ethnl_cable_test_fault_length (phydev, pair, length); + +return 0 ; +} + +static int marvell_vct7_cable_test_report_trans (int result) +{ +switch (result) { +case MII_VCT7_RESULTS_OK : +return ETHTOOL_A_CABLE_RESULT_CODE_OK ; +case MII_VCT7_RESULTS_OPEN : +return ETHTOOL_A_CABLE_RESULT_CODE_OPEN ; +case MII_VCT7_RESULTS_SAME_SHORT : +return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT ; +case MII_VCT7_RESULTS_CROSS_SHORT : +return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT ; +default : +return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC ; + } +} + +static int marvell_vct7_cable_test_report (struct phy_device *phydev) +{ +int pair0, pair1, pair2, pair3; +bool meter; +int ret; + + ret =phy_read_paged (phydev,MII_MARVELL_VCT7_PAGE , +MII_VCT7_RESULTS ); +if (ret <0 ) +return ret; + + pair3 = (ret &MII_VCT7_RESULTS_PAIR3_MASK ) >> +MII_VCT7_RESULTS_PAIR3_SHIFT ; + pair2 = (ret &MII_VCT7_RESULTS_PAIR2_MASK ) >> +MII_VCT7_RESULTS_PAIR2_SHIFT ; + pair1 = (ret &MII_VCT7_RESULTS_PAIR1_MASK ) >> +MII_VCT7_RESULTS_PAIR1_SHIFT ; + pair0 = (ret &MII_VCT7_RESULTS_PAIR0_MASK ) >> +MII_VCT7_RESULTS_PAIR0_SHIFT ; + +ethnl_cable_test_result (phydev,ETHTOOL_A_CABLE_PAIR_A , +marvell_vct7_cable_test_report_trans (pair0)); +ethnl_cable_test_result (phydev,ETHTOOL_A_CABLE_PAIR_B , +marvell_vct7_cable_test_report_trans (pair1)); +ethnl_cable_test_result (phydev,ETHTOOL_A_CABLE_PAIR_C , +marvell_vct7_cable_test_report_trans (pair2)); +ethnl_cable_test_result (phydev,ETHTOOL_A_CABLE_PAIR_D , +marvell_vct7_cable_test_report_trans (pair3)); + + ret =phy_read_paged (phydev,MII_MARVELL_VCT7_PAGE ,MII_VCT7_CTRL ); +if (ret <0 ) +return ret; + + meter = ret &MII_VCT7_CTRL_METERS ; + +if (marvell_vct7_distance_valid (pair0)) +marvell_vct7_report_length (phydev,0 , meter); +if (marvell_vct7_distance_valid (pair1)) +marvell_vct7_report_length (phydev,1 , meter); +if (marvell_vct7_distance_valid (pair2)) +marvell_vct7_report_length (phydev,2 , meter); +if (marvell_vct7_distance_valid (pair3)) +marvell_vct7_report_length (phydev,3 , meter); + +return 0 ; +} + +static int marvell_vct7_cable_test_get_status (struct phy_device *phydev, +bool *finished) +{ +int ret; + + *finished = false; + + ret =phy_read_paged (phydev,MII_MARVELL_VCT7_PAGE , +MII_VCT7_CTRL ); + +if (ret <0 ) +return ret; + +if (!(ret &MII_VCT7_CTRL_IN_PROGRESS )) { + *finished = true; + +return marvell_vct7_cable_test_report (phydev); + } + +return 0 ; +} +#ifdef CONFIG_HWMON static int m88e1121_get_temp (struct phy_device *phydev,long *temp) {
@@ -2353,6 +2542,7 @@ static struct phy_driver marvell_drivers[] = { .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1510", .features = PHY_GBIT_FIBRE_FEATURES, + .flags = PHY_POLL_CABLE_TEST, .probe = &m88e1510_probe, .config_init = &m88e1510_config_init, .config_aneg = &m88e1510_config_aneg,
@@ -2372,12 +2562,15 @@ static struct phy_driver marvell_drivers[] = { .set_loopback = genphy_loopback, .get_tunable = m88e1011_get_tunable, .set_tunable = m88e1011_set_tunable, + .cable_test_start = marvell_vct7_cable_test_start, + .cable_test_get_status = marvell_vct7_cable_test_get_status, }, { .phy_id = MARVELL_PHY_ID_88E1540, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1540",/* PHY_GBIT_FEATURES */ + .flags = PHY_POLL_CABLE_TEST, .probe = m88e1510_probe, .config_init = &marvell_config_init, .config_aneg = &m88e1510_config_aneg,
@@ -2394,6 +2587,8 @@ static struct phy_driver marvell_drivers[] = { .get_stats = marvell_get_stats, .get_tunable = m88e1540_get_tunable, .set_tunable = m88e1540_set_tunable, + .cable_test_start = marvell_vct7_cable_test_start, + .cable_test_get_status = marvell_vct7_cable_test_get_status, }, { .phy_id = MARVELL_PHY_ID_88E1545,
@@ -2401,6 +2596,7 @@ static struct phy_driver marvell_drivers[] = { .name = "Marvell 88E1545", .probe = m88e1510_probe,/* PHY_GBIT_FEATURES */ + .flags = PHY_POLL_CABLE_TEST, .config_init = &marvell_config_init, .config_aneg = &m88e1510_config_aneg, .read_status = &marvell_read_status,
@@ -2416,6 +2612,8 @@ static struct phy_driver marvell_drivers[] = { .get_stats = marvell_get_stats, .get_tunable = m88e1540_get_tunable, .set_tunable = m88e1540_set_tunable, + .cable_test_start = marvell_vct7_cable_test_start, + .cable_test_get_status = marvell_vct7_cable_test_get_status, }, { .phy_id = MARVELL_PHY_ID_88E3016,
@@ -2442,6 +2640,7 @@ static struct phy_driver marvell_drivers[] = { .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E6390",/* PHY_GBIT_FEATURES */ + .flags = PHY_POLL_CABLE_TEST, .probe = m88e6390_probe, .config_init = &marvell_config_init, .config_aneg = &m88e6390_config_aneg,
@@ -2458,6 +2657,8 @@ static struct phy_driver marvell_drivers[] = { .get_stats = marvell_get_stats, .get_tunable = m88e1540_get_tunable, .set_tunable = m88e1540_set_tunable, + .cable_test_start = marvell_vct7_cable_test_start, + .cable_test_get_status = marvell_vct7_cable_test_get_status, }, };
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 9/10 net: phy: Put interface into oper testing during cable test
In reply to Andrew LunnSince running a cable test is disruptive, put the interface into operative state testing while the test is running.
--- drivers/net/phy/phy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +11 -1
@@ -492,6 +492,7 @@ static void phy_abort_cable_test(struct phy_device *phydev)int phy_start_cable_test (struct phy_device *phydev,struct netlink_ext_ack *extack) { +struct net_device *dev = phydev->attached_dev;int err = -ENOMEM ; if (!(phydev->drv &&
@@ -525,8 +526,10 @@ int phy_start_cable_test(struct phy_device *phydev,/* Mark the carrier down until the test is complete */ phy_link_down (phydev, true); +netif_testing_on (dev); err = phydev->drv->cable_test_start (phydev);if (err) { +netif_testing_off (dev);phy_link_up (phydev); goto out_free; }
@@ -879,6 +882,8 @@ EXPORT_SYMBOL(phy_free_interrupt);*/ void phy_stop (struct phy_device *phydev) { +struct net_device *dev = phydev->attached_dev; +if (!phy_is_started (phydev)) {WARN (1 ,"called from state %s\n" ,phy_state_to_str (phydev->state));
@@ -887,8 +892,10 @@ void phy_stop(struct phy_device *phydev)mutex_lock (&phydev->lock); -if (phydev->state ==PHY_CABLETEST ) +if (phydev->state ==PHY_CABLETEST ) {phy_abort_cable_test (phydev); +netif_testing_off (dev); + }if (phydev->sfp_bus)sfp_upstream_stop (phydev->sfp_bus);
@@ -950,6 +957,7 @@ void phy_state_machine(struct work_struct *work)struct delayed_work *dwork =to_delayed_work (work);struct phy_device *phydev = container_of(dwork, struct phy_device, state_queue); +struct net_device *dev = phydev->attached_dev;bool needs_aneg = false, do_suspend = false;enum phy_state old_state;bool finished = false;
@@ -975,6 +983,7 @@ void phy_state_machine(struct work_struct *work) err = phydev->drv->cable_test_get_status (phydev, &finished);if (err) {phy_abort_cable_test (phydev); +netif_testing_off (dev); needs_aneg = true; phydev->state =PHY_UP ;break ;
@@ -982,6 +991,7 @@ void phy_state_machine(struct work_struct *work)if (finished) {ethnl_cable_test_finished (phydev); +netif_testing_off (dev); needs_aneg = true; phydev->state =PHY_UP ; }
Signature · 1 line
2.26.2
Andrew Lunn
maintainerPATCH v4 10/10 net: phy: Send notifier when starting the cable test
In reply to Andrew LunnGiven that it takes time to run a cable test, send a notify message at the start, as well as when it is completed.
v3:
EMSGSIZE when ethnl_bcastmsg_put() fails
Print an error message on failure, since this is a void function.
--- net/ethtool/cabletest.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
net/ethtool/cabletest.c +41 -0
@@ -13,6 +13,43 @@ cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, }; +static int ethnl_cable_test_started (struct phy_device *phydev) +{ +struct sk_buff *skb; +int err = -ENOMEM ; +void *ehdr; + + skb =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!skb) + goto out; + + ehdr =ethnl_bcastmsg_put (skb,ETHTOOL_MSG_CABLE_TEST_NTF ); +if (!ehdr) { + err = -EMSGSIZE ; + goto out; + } + + err =ethnl_fill_reply_header (skb, phydev->attached_dev, +ETHTOOL_A_CABLE_TEST_NTF_HEADER ); +if (err) + goto out; + + err =nla_put_u8 (skb,ETHTOOL_A_CABLE_TEST_NTF_STATUS , +ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED ); +if (err) + goto out; + +genlmsg_end (skb, ehdr); + +return ethnl_multicast (skb, phydev->attached_dev); + +out: +nlmsg_free (skb); +phydev_err (phydev,"%s: Error %pe\n" , __func__,ERR_PTR (err)); + +return err; +} +int ethnl_act_cable_test (struct sk_buff *skb,struct genl_info *info) {struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX +1 ];
@@ -47,6 +84,10 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ret =phy_start_cable_test (dev->phydev, info->extack);ethnl_ops_complete (dev); + +if (!ret) +ethnl_cable_test_started (dev->phydev); + out_rtnl:rtnl_unlock (); out_dev_put:
Signature · 1 line
2.26.2
Jakub Kicinski
maintainerQuoted 9 lines · On Sun, 10 May 2020 21:12:29 +0200 Andrew Lunn wrote:
any copper Ethernet PHY have support for performing diagnostics of the cable. Are the cable shorted, broken, not plugged into anything at the other end? And they can report roughly how far along the cable any fault is.
Add infrastructure in ethtool and phylib support for triggering a cable test and reporting the results. The Marvell 1G PHY driver is then extended to make use of this infrastructure.
Quoted 6 lines
For testing, a modified ethtool(1) can be found here:
https://github.com/lunn/ethtool.git feature/cable-test-v4. This also contains extra code for TDR dump, which will be added to the kernel in a later patch series.Thanks to Chris Healy for extensive testing.
👍👍
Applied, I'll push out once builds are done (probably an hour).
Thank you!