net: phy: Add ability to debug RGMII
Subsystems (3)
v2 cover net: phy: Add ability to debug RGMII
Hi all,
This patch series is primarily intended to reduce the amount of support involved with bringing up RGMII connections with the PHY library (or PHYLINK) for that matter. The idea consists in looping back a packet we just crafted and check whether it did came back correctly, if that is the case, we are good, else we must try configuring the PHY for different delays until it either works or we bail out.
As indicated in the commit message, future improvements could probably be done in order to converge faster on the appropriate configuration. This is intended to be PHY centric, and we are not playing with delays on the MAC side other than through the parsing of the phydev->interface.
The typical output would look like this:
[ 62.668701] bcmgenet 8f00000.ethernet eth0: Trying "rgmii-txid" PHY interface [ 62.676094] bcmgenet 8f00000.ethernet eth0: Determined "rgmii-txid"
to be correct
Feedback highly welcome on this!
Changes in v2:
- differenciate c22 vs. c45 PHYs in phy_loopback()
- print SKB length mismatch
- check that link comes back up between each iteration since we go in and out of loopback mode
- prevent NPD by checking attached_dev later
- moved check for af_packet_priv earlier
Florian Fainelli (2):
net: phy: Use genphy_loopback() by default
net: phy: Add ability to debug RGMII connections
.../ABI/testing/sysfs-class-net-phydev | 11 + drivers/net/phy/Kconfig | 9 + drivers/net/phy/Makefile | 1 + drivers/net/phy/phy-rgmii-debug.c | 284 ++++++++++++++++++ drivers/net/phy/phy_device.c | 35 ++- include/linux/phy.h | 9 + 6 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/phy-rgmii-debug.c
Signature · 1 line
2.17.1
PATCH v2 1/2 net: phy: Use genphy_loopback() by default
The standard way of putting a PHY device into loopback is most often suitable for testing. This is going to be necessary in a subsequent patch that adds RGII debugging capability using the loopback feature.
Clause 45 PHYs are not supported through a generic method yet.
--- drivers/net/phy/phy_device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +3 -1
@@ -1513,8 +1513,10 @@ int phy_loopback(struct phy_device *phydev, bool enable)if (phydev->drv && phydrv->set_loopback) ret = phydrv->set_loopback (phydev, enable); -else +else if (phydev->is_c45) ret = -EOPNOTSUPP ; +else + ret =genphy_loopback (phydev, enable);if (ret) goto out;
Signature · 1 line
2.17.1
Re: [PATCH net-next v2 1/2] net: phy: Use genphy_loopback() by default
Quoted 7 lines · Florian Fainelli
The standard way of putting a PHY device into loopback is most often suitable for testing. This is going to be necessary in a subsequent patch that adds RGII debugging capability using the loopback feature.
Clause 45 PHYs are not supported through a generic method yet.
Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH v2 2/2 net: phy: Add ability to debug RGMII connections
In reply to Florian FainelliRGMII connections are always troublesome because of the need to add delays between the RX or TX clocks and data lines. This can lead to a fair amount of breakage that upsets users.
Introduce a new sysfs write only attribute which can be set to 1 to instruct the PHY library to attempt to probe what the correct RGMII phy_interface_t value should be. When such debugging is requested, the PHY library will do a number of checks whether this debugging is even necessary (RGMII used, Gigabit, not a Generic PHY driver etc.) and if successfull will proceed with:
- putting the PHY in loopback mode
- register a packet handler with an unused Ethernet type value in the kernel (ETH_P_EDSA is a well known unused value)
- re-configure the PHY and MAC with the phy_interface_t value to be tried, which is one of the 4 possible interfaces, starting with the currently defined one
- craft a MTU sized packet with the Ethernet interface's MAC SA and DA set to itself and send that in a process context
- wait for that packet to be received through the registered packet_type handler
If the packet is not received, we have a problem with the RGMII interface, if we do receive something, we check the FCS we calculated on transmit matches the FCS of the packet received, if we have a mismatch it most likely will not.
If all is well, we stop iterating over all possible RGMII combinations and offer the one that is deemed suitable which is what an user should be trying by configuring the platform appropriately.
This is not deemed to be 100% fool proof, but given how much support getting RGMII seems to involved, this seemed like a good tool to have users self-diagnose their connection issues.
Future improvements could be made in order to extrapolate from a specific frame patter the type of skewing between RXC/TXC that is going on so as to refine the search process, and even possibly suggest delays.
The function phy_rgmii_debug_probe() could also be used by an Ethernet controller during its selftests routines instead of open-coding that part.
--- .../ABI/testing/sysfs-class-net-phydev | 11 + drivers/net/phy/Kconfig | 9 + drivers/net/phy/Makefile | 1 + drivers/net/phy/phy-rgmii-debug.c | 284 ++++++++++++++++++ drivers/net/phy/phy_device.c | 31 ++ include/linux/phy.h | 9 + 6 files changed, 345 insertions(+) create mode 100644 drivers/net/phy/phy-rgmii-debug.c
Documentation/ABI/testing/sysfs-class-net-phydev +11 -0
@@ -49,3 +49,14 @@ Description: Boolean value indicating whether the PHY device is used in standalone mode, without a net_device associated, by PHYLINK. Attribute created only when this is the case. + +What: /sys/class/mdio_bus/<bus>/<device>/phy_rgmii_debug +Date: October 2019 +KernelVersion: 5.5 +Contact: [email protected] +Description: + Write only attribute used to trigger the debugging of RGMII + connections. Upon writing, this will either return success + and print to kernel console the correct phy_interface value + or an error will be returned. See CONFIG_PHY_RGMII_DEBUG for + details.
drivers/net/phy/Kconfig +9 -0
@@ -248,6 +248,15 @@ config LED_TRIGGER_PHY <Speed in megabits>Mbps OR <Speed in gigabits>Gbps OR link for any speed known to the PHY. +config PHY_RGMII_DEBUG + bool "Support debugging of RGMII connections" + ---help--- + This enables support for troubleshooting RGMII connections by + making use of the PHY devices standard loopback feature in order to + probe the correct RGMII connection. + + If unsure, say N here. + comment "MII PHY device drivers"
drivers/net/phy/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o endif libphy-$(CONFIG_SWPHY) += swphy.o libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o +libphy-$(CONFIG_PHY_RGMII_DEBUG) += phy-rgmii-debug.o obj-$(CONFIG_PHYLINK) += phylink.o obj-$(CONFIG_PHYLIB) += libphy.o
drivers/net/phy/phy-rgmii-debug.c new file +284 -0
284 lines not on this page · raw message
drivers/net/phy/phy_device.c +31 -0
@@ -537,10 +537,41 @@ phy_has_fixups_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (phy_has_fixups); +static ssize_t +phy_rgmii_debug_enable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct phy_device *phydev =to_phy_device (dev); +unsigned int val; +int ret = -EPERM ; + +if (!capable (CAP_NET_ADMIN )) + goto out; + + ret =kstrtoint (buf,0 , &val); +if (ret) + goto out; + +if (val !=1 ) { + ret = -EINVAL ; + goto out; + } + + ret =phy_rgmii_debug_probe (phydev); +if (ret) +return ret; + + ret = count; +out: +return ret; +} +static DEVICE_ATTR_WO (phy_rgmii_debug_enable); +static struct attribute *phy_dev_attrs[] = { &dev_attr_phy_id.attr, &dev_attr_phy_interface.attr, &dev_attr_phy_has_fixups.attr, + &dev_attr_phy_rgmii_debug_enable.attr,NULL , };ATTRIBUTE_GROUPS (phy_dev);
include/linux/phy.h +9 -0
@@ -1287,4 +1287,13 @@ module_exit(phy_module_exit)bool phy_driver_is_genphy (struct phy_device *phydev);bool phy_driver_is_genphy_10g (struct phy_device *phydev); +#ifdef CONFIG_PHY_RGMII_DEBUG +int phy_rgmii_debug_probe (struct phy_device *phydev); +#else +static inline int phy_rgmii_debug_probe (struct phy_device *phydev) +{ +return -EOPNOTSUPP ; +} +#endif +#endif /* __PHY_H */
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH net-next v2 2/2] net: phy: Add ability to debug RGMII connections
Quoted 3 lines
If all is well, we stop iterating over all possible RGMII combinations and offer the one that is deemed suitable which is what an user should be trying by configuring the platform appropriately.
Hi Florian
This is no longer true. You now iterate over all modes.
drivers/net/phy/phy-rgmii-debug.c line 275
Quoted 10 lines
drivers/net/phy/phy-rgmii-debug.c new file +9
-0+int phy_rgmii_debug_probe (struct phy_device *phydev) +{ +/* Now probe all modes */ +for (i =0 ; i <ARRAY_SIZE (rgmii_modes); i++) { + ret =phy_rgmii_probe_interface (priv, rgmii_modes[i]); +if (ret ==0 ) +netdev_info (ndev,"Determined \"%s\" to be correct\n" , +phy_modes (rgmii_modes[i])); + }
I see two different use cases for this code.
1) Find the right mode
2) Test if the PHY driver is doing the right thing with different modes.
You are concentrating more on the first, but i think the second is also important. I think we can give the novice user a few more guidelines. We can count the number of modes which work. If that count != 1, we know we have a driver problem. We should ask the user to report the problem, including details of the MAC and PHY driver.
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next v2 2/2] net: phy: Add ability to debug RGMII connections
In reply to Florian Fainelliinclude/linux/phy.h module_exit(phy_module_exit) · line 1297
Quoted 8 lines
include/linux/phy.h +8
-0+#ifdef CONFIG_PHY_RGMII_DEBUG +int phy_rgmii_debug_probe (struct phy_device *phydev); +#else +static inline int phy_rgmii_debug_probe (struct phy_device *phydev) +{ +return -EOPNOTSUPP ; +} +#endif
Hi Florian
Jose wanted to make use of this in his self test code for stmmac. I think to make this more user friendly in that setup, it would be good to return the phy_mode which works, if only one works. The MAC driver can then compare the what it thinks the mode should be to what actually works, and report a test failure if they differ.
Andrew