net: usb: lan78xx: program MAC_CR for LAN7801 fixed-PHY link
Subsystems (3)
PATCH 1/1 net: usb: lan78xx: program MAC_CR for LAN7801 fixed-PHY link
While bringing up a LAN7801 wired over RGMII to an MDIO-less switch, I hit a link that the fixed PHY reported as "up" but that could not pass a single packet: every frame came out corrupted at the switch and no ARP reply ever made it back.
It turned out the MAC_CR speed/duplex bits are never set on this path. lan7801_phy_init() registers a fixed PHY at SPEED_1000/DUPLEX_FULL, but nothing programs the MAC to match: there is no PHY state machine for a fixed link, and lan78xx_reset() only sets the auto speed/duplex bits for the 7800. So the 7801 comes up at 10M/half, clocks RGMII TXC at 2.5 MHz instead of 125 MHz, and mangles everything it transmits.
Fix it by programming MAC_CR to 1G/full in the fixed-PHY branch, to match fphy_status. Only that branch is touched, so boards with a real external PHY (and the 7800/7850) are unaffected.
Mainline fixes this differently via the phylink conversion in v6.16, commit e110bc825897 ("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management"), which is far too large to backport, so this is a small fix for stable only.
Please apply to 6.1.y, 6.6.y and 6.12.y, the pre-phylink branches that still carry this bug. Built and tested on 6.6.y; the touched code is identical on 6.1.y and 6.12.y.
--- drivers/net/usb/lan78xx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/usb/lan78xx.c +16 -0
@@ -2325,6 +2325,22 @@ static struct phy_device *lan7801_phy_init(struct lan78xx_net *dev) buf |=HW_CFG_CLK125_EN_ ; buf |=HW_CFG_REFCLK25_EN_ ; ret =lan78xx_write_reg (dev,HW_CFG , buf); + +/* Nothing programs MAC_CR for the fixed link: reset() only +* sets speed/duplex for the 7800, so the 7801 is left at +* 10M/half and mangles every frame it sends. Force it to +* match the 1G/full fphy_status above. +*/ + ret =lan78xx_read_reg (dev,MAC_CR , &buf); +if (ret <0 ) +return NULL ; + buf &= ~(MAC_CR_AUTO_DUPLEX_ |MAC_CR_AUTO_SPEED_ | +MAC_CR_ADP_ |MAC_CR_GMII_EN_ | +MAC_CR_SPEED_MASK_ ); + buf |=MAC_CR_SPEED_1000_ |MAC_CR_FULL_DUPLEX_ ; + ret =lan78xx_write_reg (dev,MAC_CR , buf); +if (ret <0 ) +return NULL ; }else {if (!phydev->drv) {netdev_err (dev->net,"no PHY driver found\n" );
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 12 lines · Nguyen Minh Tien
While bringing up a LAN7801 wired over RGMII to an MDIO-less switch, I hit a link that the fixed PHY reported as "up" but that could not pass a single packet: every frame came out corrupted at the switch and no ARP reply ever made it back.
It turned out the
MAC_CRspeed/duplex bits are never set on this path.lan7801_phy_init()registers a fixed PHY at SPEED_1000/DUPLEX_FULL, but nothing programs the MAC to match: there is no PHY state machine for a fixed link, andlan78xx_reset()only sets the auto speed/duplex bits for the 7800. So the 7801 comes up at 10M/half, clocks RGMII TXC at 2.5 MHz instead of 125 MHz, and mangles everything it transmits.
Quoted 8 lines
Fix it by programming
MAC_CRto 1G/full in the fixed-PHY branch, to matchfphy_status. Only that branch is touched, so boards with a real external PHY (and the 7800/7850) are unaffected.Mainline fixes this differently via the phylink conversion in v6.16, commit
e110bc825897("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management"), which is far too large to backport, so this is a small fix for stable only.
Why is that too large? If we take this, we then diverge and any future fixes will not apply here :(
Please backport exactly what is in the mainline tree, otherwise odds are, this one-off fix will be found incorrect (we always get it wrong...)
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CAH9t78zjHGm-EFmjeJy3fMZ0fs3m+ZKWynaJkd8GDZdWoZDLHw@mail.gmail.com
Greg KH
maintainerQuoted 16 lines · Minh Tiến Nguyễn
Quoted 2 lines
Please backport exactly what is in the mainline tree, otherwise odds are, this one-off fix will be found incorrect (we always get it wrong...)
Hi Greg,
Sorry for the long silence. In June the board was still in development and I only made the link work; I've only now had time to recheck this against mainline and test it on the hardware.You were right. Please drop my patch; these two mainline commits fix the same bug:
5160b129f65f("lan78xx: Enable 125 MHz CLK configuration for LAN7801 if
NO EEPROM is detected")
799f532de136("lan78xx: Enable Auto Speed and Auto Duplex configuration
for LAN7801 if NO EEPROM is detected")
Quoted 5 lines
Could you apply them, in that order, to the stable trees that don't have them yet (6.6.y and older)? They apply cleanly. I tested them with the 6.6.y and 6.1.y driver on the board: without them the LAN7801 MAC stays at 10 Mb/s and passes no traffic, with them the link runs at 1000/full with no errors.
Now queued up, thanks.
greg k-h