diff mbox series

[net,01/13] net: phy: realtek: Fix events detection failure in LPI mode

Message ID 20230313224237.28757-2-Sergey.Semin@baikalelectronics.ru (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series net: stmmac: Fixes bundle #1 | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
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: 18 this patch: 18
netdev/cc_maintainers warning 3 maintainers not CCed: linux-mediatek@lists.infradead.org angelogioacchino.delregno@collabora.com matthias.bgg@gmail.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 49 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Serge Semin March 13, 2023, 10:42 p.m. UTC
It has been noticed that RTL8211E PHY stops detecting and reporting events
(cable plugging in/out, link state changes, etc) when EEE is successfully
advertised and "RXC stopping in LPI" is enabled. The freeze happens right
after 3.0.10 bit (PC1R "Clock Stop Enable" register) is set. At the same
time LED2 stops blinking as if EEE mode has been disabled, interrupt pin
doesn't change its state (signal tested by oscilloscope). Notably the
network traffic still flows through the PHY with no obvious problem as
long as a network cable is connected. But if any MDIO read/write procedure
is performed after the "RXC stop in LPI" mode is enabled (even from a
non-existent device on the MDIO bus) the PHY gets to be unfrozen, LED2
starts blinking and PHY interrupts happens again (even which have happened
during the freeze). The problem has been noticed on RTL8211E PHY working
together with DW GMAC 3.73a MAC and reporting its event via a dedicated DW
MAC GPIO-IRQ signal. (Obviously the problem has been unnoticed in the
polling mode, since it gets naturally fixed by the periodic MDIO read
procedure from the PHY status register - BMSR.)

In order to fix that problem we suggest to locally re-implement the MMD
write method for RTL8211E PHY and perform a dummy read right after the
PC1R register is accessed to enable the RXC stopping in LPI mode.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>

---

Original patch:
Link: https://lore.kernel.org/netdev/20210208140341.9271-2-Sergey.Semin@baikalelectronics.ru/
---
 drivers/net/phy/realtek.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Comments

Andrew Lunn March 14, 2023, 12:39 a.m. UTC | #1
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

Since this is for net, you need to provide a Fixes: tag.

      Andrew
Serge Semin March 14, 2023, 11:16 a.m. UTC | #2
Hi Andrew

On Tue, Mar 14, 2023 at 01:39:43AM +0100, Andrew Lunn wrote:
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 
> Since this is for net, you need to provide a Fixes: tag.

Hm, for some reason I was sure that all the patches in this series were
equipped with the Fixes-tags. Anyway since the patch fixes the particular
device malfunction then it's relevant to the commit initially adding the
device support:
Fixes: ef3d90491a15 ("net: phy: realtek: add rtl8211e driver")

I'll add that tag on v2. Thanks for reminding.

-Serge(y)

> 
>       Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index 3d99fd6664d7..72ca06bcd53e 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -637,6 +637,42 @@  static int rtl822x_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
 	return ret;
 }
 
+static int rtl8211e_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
+			      u16 val)
+{
+	int ret;
+
+	/* Write to the MMD registers by using the standard control/data pair.
+	 * The only difference is that we need to perform a dummy read after
+	 * the PC1R.CLKSTOP_EN bit is set. It's required to workaround an issue
+	 * of a partial core freeze so LED2 stops blinking in EEE mode, PHY
+	 * stops detecting the link change and raising IRQs until any read from
+	 * its registers performed. That happens only if and right after the PHY
+	 * is enabled to stop RXC in LPI mode.
+	 */
+	ret = __phy_write(phydev, MII_MMD_CTRL, devnum);
+	if (ret)
+		return ret;
+
+	ret = __phy_write(phydev, MII_MMD_DATA, regnum);
+	if (ret)
+		return ret;
+
+	ret = __phy_write(phydev, MII_MMD_CTRL, devnum | MII_MMD_CTRL_NOINCR);
+	if (ret)
+		return ret;
+
+	ret = __phy_write(phydev, MII_MMD_DATA, val);
+	if (ret)
+		return ret;
+
+	if (devnum == MDIO_MMD_PCS && regnum == MDIO_CTRL1 &&
+	    val & MDIO_PCS_CTRL1_CLKSTOP_EN)
+		ret =  __phy_read(phydev, MII_MMD_DATA);
+
+	return ret < 0 ? ret : 0;
+}
+
 static int rtl822x_get_features(struct phy_device *phydev)
 {
 	int val;
@@ -919,6 +955,7 @@  static struct phy_driver realtek_drvs[] = {
 		.resume		= genphy_resume,
 		.read_page	= rtl821x_read_page,
 		.write_page	= rtl821x_write_page,
+		.write_mmd	= rtl8211e_write_mmd,
 	}, {
 		PHY_ID_MATCH_EXACT(0x001cc916),
 		.name		= "RTL8211F Gigabit Ethernet",