🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Igor Velkov via B4 Relay Tue, 17 Nov 2026 00:54
[PATCH net v2] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
#17548
Author: Igor Velkov via B4 Relay
Date: Tue, 17 Nov 2026 00:54
143 lines
15261 bytes
From: Igor Velkov <iav@iav.lv>

Switching the mux to the internal MDIO bus writes SMI_SRC_MAC together
with USE_INTERNAL and RX_CLK_EPHY to ETH_PHY_CNTL2. The last two move the
MAC data path and RX clock to the internal PHY. On boards whose MAC uses
an external PHY, any access to the internal PHY stops reception until an
access to the external bus switches the mux back.

phylib suspends and resumes the unattached internal PHY across system
sleep. stmmac sets mac_managed_pm, and with Wake-on-LAN in the MAC
phylink_resume() does not start the external PHY, so nothing switches
the mux back. On ODROID-HC4 (RTL8211F), after suspend-to-RAM with WoL in
the MAC and an RTC wakeup, ETH_PHY_CNTL2 stays at 0x260 and the MAC
receives nothing while TX works.

With the MAC on the external PHY, SMI_SRC_MAC alone is enough to read
the internal PHY ID (0x0180/0x3301) while RX keeps running; adding
USE_INTERNAL or RX_CLK_EPHY stops RX.

Set the data path bits only when the PHY the MAC attaches sits on the
internal bus. Look the PHY up with fwnode_get_phy_node(), as stmmac
does, so phy-handle and the deprecated phy and phy-device all count.

Fixes: 7090425104db ("net: phy: add amlogic g12a mdio mux support")
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Tested on ODROID-HC4: three RTC wakeups from suspend-to-RAM with WoL in
the MAC (ETH_PHY_CNTL2 0x40, RX working), one without WoL.
---
Changes in v2:
- Find the PHY with fwnode_get_phy_node(), as stmmac does, so the
  deprecated phy and phy-device references count too (Sashiko).
- Drop the dwmac-rk comparison from the comment and commit message.
- Link to v1: https://lore.kernel.org/r/20261115-g12a-mux-data-path-v1-1-011dad738698@iav.lv
---
 drivers/net/mdio/mdio-mux-meson-g12a.c | 50 ++++++++++++++++++++++++++++++----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/drivers/net/mdio/mdio-mux-meson-g12a.c b/drivers/net/mdio/mdio-mux-meson-g12a.c
index 71c44385489d..e0acbd3ed383 100644
--- a/drivers/net/mdio/mdio-mux-meson-g12a.c
+++ b/drivers/net/mdio/mdio-mux-meson-g12a.c
@@ -12,6 +12,7 @@
 #include <linux/iopoll.h>
 #include <linux/mdio-mux.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/phy.h>
 #include <linux/platform_device.h>
 
@@ -56,6 +57,7 @@ struct g12a_mdio_mux {
 	void __iomem *regs;
 	void *mux_handle;
 	struct clk *pll;
+	bool mac_uses_internal_phy;
 };
 
 struct g12a_ephy_pll {
@@ -149,7 +151,7 @@ static const struct clk_ops g12a_ephy_pll_ops = {
 
 static int g12a_enable_internal_mdio(struct g12a_mdio_mux *priv)
 {
-	u32 value;
+	u32 value, cntl2;
 	int ret;
 
 	/* Enable the phy clock */
@@ -169,10 +171,11 @@ static int g12a_enable_internal_mdio(struct g12a_mdio_mux *priv)
 		PHY_CNTL1_CLK_EN |
 		PHY_CNTL1_CLKFREQ;
 	writel(value, priv->regs + ETH_PHY_CNTL1);
-	writel(PHY_CNTL2_USE_INTERNAL |
-	       PHY_CNTL2_SMI_SRC_MAC |
-	       PHY_CNTL2_RX_CLK_EPHY,
-	       priv->regs + ETH_PHY_CNTL2);
+
+	cntl2 = PHY_CNTL2_SMI_SRC_MAC;
+	if (priv->mac_uses_internal_phy)
+		cntl2 |= PHY_CNTL2_USE_INTERNAL | PHY_CNTL2_RX_CLK_EPHY;
+	writel(cntl2, priv->regs + ETH_PHY_CNTL2);
 
 	value |= PHY_CNTL1_PHY_ENB;
 	writel(value, priv->regs + ETH_PHY_CNTL1);
@@ -301,6 +304,42 @@ static int g12a_ephy_glue_clk_register(struct device *dev)
 	return 0;
 }
 
+/* The data path follows the PHY the MAC attaches, looked up as stmmac does */
+static bool g12a_mac_uses_internal_phy(struct device_node *mux_np)
+{
+	struct device_node *parent_bus, *mac, *phy_bus, *mux;
+	struct fwnode_handle *phy;
+	bool internal = false;
+	u32 reg;
+
+	parent_bus = of_parse_phandle(mux_np, "mdio-parent-bus", 0);
+	if (!parent_bus)
+		return false;
+
+	mac = of_get_parent(parent_bus);
+	of_node_put(parent_bus);
+	if (!mac)
+		return false;
+
+	phy = fwnode_get_phy_node(of_fwnode_handle(mac));
+	of_node_put(mac);
+	if (IS_ERR(phy))
+		return false;
+
+	phy_bus = of_get_parent(to_of_node(phy));
+	fwnode_handle_put(phy);
+	if (!phy_bus)
+		return false;
+
+	mux = of_get_parent(phy_bus);
+	if (mux == mux_np && !of_property_read_u32(phy_bus, "reg", &reg))
+		internal = (reg == MESON_G12A_MDIO_INTERNAL_ID);
+	of_node_put(mux);
+	of_node_put(phy_bus);
+
+	return internal;
+}
+
 static int g12a_mdio_mux_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -313,6 +352,7 @@ static int g12a_mdio_mux_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, priv);
+	priv->mac_uses_internal_phy = g12a_mac_uses_internal_phy(dev->of_node);
 
 	priv->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->regs))

---
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
change-id: 20261115-g12a-mux-data-path-642abdbc7b29

Best regards,
-- 
Igor Velkov <iav@iav.lv>
Re: [PATCH net v2] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
#19105
Author: patchwork-bot+netdevbpf
Date: Thu, 19 Nov 2026 10:50
25 lines
8905 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Tue, 17 Nov 2026 00:54:06 +0000 you wrote:
> From: Igor Velkov <iav@iav.lv>
> 
> Switching the mux to the internal MDIO bus writes SMI_SRC_MAC together
> with USE_INTERNAL and RX_CLK_EPHY to ETH_PHY_CNTL2. The last two move the
> MAC data path and RX clock to the internal PHY. On boards whose MAC uses
> an external PHY, any access to the internal PHY stops reception until an
> access to the external bus switches the mux back.
> 
> [...]

Here is the summary with links:
  - [net,v2] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
    https://git.kernel.org/netdev/net-next/c/cf0dd134a16e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net v2] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
#22095
Author: Igor Velkov
Date: Tue, 24 Nov 2026 21:30
30 lines
11005 bytes
Hi Martin,

On Tue, Nov 24, 2026 at 9:50 PM Martin Blumenstingl
<martin.blumenstingl@googlemail.com> wrote:
> I have just reviewed Lucas patch [0] which adds Ethernet support for the T7 SoC.
> He kept the internal MDIO mux path disabled by default, so boards
> using it will have to enable it.
> Have you tested that approach as well? If not: it would be great if
> you could investigate the pros/cons of your approach vs. Lucas'
> approach.

Not on hardware. By the code it works: mdio-mux registers only the
available child buses, and the g12a driver writes CNTL2 only from
switch_fn. With int_mdio disabled the internal bus never exists, so
CNTL2 only ever gets the external setting.

But that avoids the bug rather than fixes it. The MDIO source and the
data path are separate CNTL2 bits; the driver switched them together.
Disabling int_mdio only keeps that path from running, and only on
boards whose DT does it. The G12A/G12B/SM1/S4/C3 dtsi enable int_mdio,
and ten boards use the internal PHY relying on that. Changing the
default touches all of them, and existing DTBs keep the bug.

The driver change removes the coupling: the data path follows the PHY
the MAC attaches, with any DTB. For a new SoC like T7, int_mdio
disabled in the dtsi is ordinary DT practice, and the two combine. If
one has to pick, the driver change: it fixes the cause.

Igor
Re: [PATCH net v2] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
#22154
Author: Igor Velkov
Date: Tue, 24 Nov 2026 22:36
22 lines
10635 bytes
Hi Martin,

On Tue, Nov 24, 2026 at 10:52 PM Martin Blumenstingl
<martin.blumenstingl@googlemail.com> wrote:
> What caught my eye is that the code now reads strange: we have a mux
> that we're following for half of the register values while another
> part is fixed at probe time.

A cleaner plan, for the record: set the data path once at probe from
the board (USE_INTERNAL, RX_CLK_EPHY, and the ephy PLL when the MAC
uses the internal PHY), and let switch_fn flip only SMI_SRC_MAC. That
also covers the reverse case: today an access to the external bus
writes CNTL2 = 0 and stops the PLL, which would cut a MAC on the
internal PHY. No in-tree board triggers it: their ext_mdio is empty.

I did not do it that way: my boards (ODROID-HC4, N2) all use an
external PHY, so I cannot test the internal PHY side, and these boards
needed the fix. If someone has a board with the internal PHY, that
version can be tried.

Igor
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads