diff mbox series

[net,v1,1/1] net: phy: microchip: Reset LAN88xx PHY to ensure clean link state on LAN7800/7850

Message ID 20241117102147.1688991-1-o.rempel@pengutronix.de (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net,v1,1/1] net: phy: microchip: Reset LAN88xx PHY to ensure clean link state on LAN7800/7850 | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 1 blamed authors not CCed: Woojung.Huh@microchip.com; 1 maintainers not CCed: Woojung.Huh@microchip.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch warning WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 792aec47d59d ("add microchip LAN88xx phy driver")'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-11-17--12-00 (tests: 789)

Commit Message

Oleksij Rempel Nov. 17, 2024, 10:21 a.m. UTC
Fix outdated MII_LPA data in the LAN88xx PHY, which is used in LAN7800
and LAN7850 USB Ethernet controllers. Due to a hardware limitation, the
PHY cannot reliably update link status after parallel detection when the
link partner does not support auto-negotiation. To mitigate this, add a
PHY reset in `lan88xx_link_change_notify()` when `phydev->state` is
`PHY_NOLINK`, ensuring the PHY starts in a clean state and reports
accurate fixed link parallel detection results.

Fixes: 792aec47d59d9 ("add microchip LAN88xx phy driver")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/microchip.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--
2.39.5

Comments

Maxime Chevallier Nov. 18, 2024, 4:48 p.m. UTC | #1
Hi Oleksij,

On Sun, 17 Nov 2024 11:21:47 +0100
Oleksij Rempel <o.rempel@pengutronix.de> wrote:

> Fix outdated MII_LPA data in the LAN88xx PHY, which is used in LAN7800
> and LAN7850 USB Ethernet controllers. Due to a hardware limitation, the
> PHY cannot reliably update link status after parallel detection when the
> link partner does not support auto-negotiation. To mitigate this, add a
> PHY reset in `lan88xx_link_change_notify()` when `phydev->state` is
> `PHY_NOLINK`, ensuring the PHY starts in a clean state and reports
> accurate fixed link parallel detection results.
> 
> Fixes: 792aec47d59d9 ("add microchip LAN88xx phy driver")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

This looks like the issue in the Asix AX88772A, but your patch has
better error handling :)

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime
Oleksij Rempel Nov. 18, 2024, 5:37 p.m. UTC | #2
On Mon, Nov 18, 2024 at 05:48:49PM +0100, Maxime Chevallier wrote:
> Hi Oleksij,
> 
> On Sun, 17 Nov 2024 11:21:47 +0100
> Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> 
> > Fix outdated MII_LPA data in the LAN88xx PHY, which is used in LAN7800
> > and LAN7850 USB Ethernet controllers. Due to a hardware limitation, the
> > PHY cannot reliably update link status after parallel detection when the
> > link partner does not support auto-negotiation. To mitigate this, add a
> > PHY reset in `lan88xx_link_change_notify()` when `phydev->state` is
> > `PHY_NOLINK`, ensuring the PHY starts in a clean state and reports
> > accurate fixed link parallel detection results.
> > 
> > Fixes: 792aec47d59d9 ("add microchip LAN88xx phy driver")
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> 
> This looks like the issue in the Asix AX88772A, but your patch has
> better error handling :)

It was my code in Asix. Need to add proper error handling too. It is not
nice if device is detached but kernel is continuing executing things and
printing a lot of errors.
diff mbox series

Patch

diff --git a/drivers/net/phy/microchip.c b/drivers/net/phy/microchip.c
index d3273bc0da4a..3c8bc87da70e 100644
--- a/drivers/net/phy/microchip.c
+++ b/drivers/net/phy/microchip.c
@@ -351,6 +351,21 @@  static int lan88xx_config_aneg(struct phy_device *phydev)
 static void lan88xx_link_change_notify(struct phy_device *phydev)
 {
 	int temp;
+	int ret;
+
+	/* Reset PHY, otherwise MII_LPA will provide outdated information.
+	 * This issue is reproducible only with after parallel detection
+	 * where link partner do not supports auto-negotiation.
+	 */
+	if (phydev->state == PHY_NOLINK) {
+		ret = phy_init_hw(phydev);
+		if (ret < 0)
+			goto link_change_notify_failed;
+
+		ret = _phy_start_aneg(phydev);
+		if (ret < 0)
+			goto link_change_notify_failed;
+	}

 	/* At forced 100 F/H mode, chip may fail to set mode correctly
 	 * when cable is switched between long(~50+m) and short one.
@@ -377,6 +392,11 @@  static void lan88xx_link_change_notify(struct phy_device *phydev)
 		temp |= LAN88XX_INT_MASK_MDINTPIN_EN_;
 		phy_write(phydev, LAN88XX_INT_MASK, temp);
 	}
+
+	return;
+
+link_change_notify_failed:
+	phydev_err(phydev, "Link change process failed %pe\n", ERR_PTR(ret));
 }

 /**