* [PATCH net] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
@ 2026-11-15 19:22 Igor Velkov via B4 Relay
2026-11-16 19:24 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-15 19:22 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl
Cc: netdev, linux-arm-kernel, linux-amlogic, linux-kernel,
Igor Velkov
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 MAC's phy-handle names a PHY on
the internal bus. As in dwmac-rk, which reads phy-is-integrated from
that node, the node phy-handle names decides; here it is the mux bus
the PHY sits on.
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.
---
drivers/net/mdio/mdio-mux-meson-g12a.c | 49 ++++++++++++++++++++++++++++++----
1 file changed, 44 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..ed688d48eaf0 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,41 @@ static int g12a_ephy_glue_clk_register(struct device *dev)
return 0;
}
+/* Like dwmac-rk: the PHY named by the MAC's phy-handle decides the data path */
+static bool g12a_mac_uses_internal_phy(struct device_node *mux_np)
+{
+ struct device_node *parent_bus, *mac, *phy, *phy_bus, *mux;
+ 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 = of_parse_phandle(mac, "phy-handle", 0);
+ of_node_put(mac);
+ if (!phy)
+ return false;
+
+ phy_bus = of_get_parent(phy);
+ of_node_put(phy);
+ if (!phy_bus)
+ return false;
+
+ mux = of_get_parent(phy_bus);
+ if (mux == mux_np && !of_property_read_u32(phy_bus, "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 +351,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>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
2026-11-15 19:22 [PATCH net] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO Igor Velkov via B4 Relay
@ 2026-11-16 19:24 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:24 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
neil.armstrong, khilman, jbrunet, martin.blumenstingl, netdev,
linux-arm-kernel, linux-amlogic, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch only sets the internal-PHY data-path bits when it
finds the internal PHY through the MAC's "phy-handle" property.
--
net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO
With this change, switching to the internal MDIO bus no longer sets
USE_INTERNAL and RX_CLK_EPHY in ETH_PHY_CNTL2 unconditionally. Those two
bits route the MAC data path and RX clock to the internal PHY. They are
now set only when the MAC's phy-handle points at a PHY on the internal
mux bus. The aim is to stop external-PHY boards from losing RX after
suspend/resume, when phylib touches the unattached internal PHY.
> diff --git a/drivers/net/mdio/mdio-mux-meson-g12a.c b/drivers/net/mdio/mdio-mux-meson-g12a.c
> index 71c44385489d4..ed688d48eaf08 100644
> --- a/drivers/net/mdio/mdio-mux-meson-g12a.c
> +++ b/drivers/net/mdio/mdio-mux-meson-g12a.c
[ ... ]
> @@ -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);
[ ... ]
> @@ -301,6 +304,41 @@ static int g12a_ephy_glue_clk_register(struct device *dev)
> return 0;
> }
>
> +/* Like dwmac-rk: the PHY named by the MAC's phy-handle decides the data path */
> +static bool g12a_mac_uses_internal_phy(struct device_node *mux_np)
> +{
> + struct device_node *parent_bus, *mac, *phy, *phy_bus, *mux;
> + 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 = of_parse_phandle(mac, "phy-handle", 0);
[Severity: Medium]
Can this check pick a different PHY from the one stmmac actually
attaches?
Only "phy-handle" is read here. stmmac_init_phy() and
phylink_fwnode_phy_connect() find the PHY through fwnode_get_phy_node().
On DT, that function also falls back to the legacy "phy" and
"phy-device" properties:
drivers/net/phy/phy_device.c:fwnode_get_phy_node() {
...
phy_node = fwnode_find_reference(fwnode, "phy-handle", 0);
if (!IS_ERR(phy_node) || is_acpi_node(fwnode))
return phy_node;
phy_node = fwnode_find_reference(fwnode, "phy", 0);
if (!IS_ERR(phy_node))
return phy_node;
return fwnode_find_reference(fwnode, "phy-device", 0);
}
ethernet-controller.yaml still lists both names as deprecated aliases of
phy-handle.
Take a DT such as:
ðmac { phy = <&internal_ephy>; phy-mode = "rmii"; };
Before this patch, stmmac attached internal_ephy, and every switch to the
internal bus wrote USE_INTERNAL | SMI_SRC_MAC | RX_CLK_EPHY.
After this patch, g12a_mdio_mux_probe() sets mac_uses_internal_phy to
false. stmmac still attaches the EPHY over MDIO, but
g12a_enable_internal_mdio() writes only SMI_SRC_MAC. The MAC data path
and RX clock then stay on the external pins. Would RX on such a board
stop working, even though the link can come up?
Every in-tree internal-PHY DT (sei510, u200, fbx8am, sei610,
sm1-a95xf3-air, sm1-x96-air, s4-aq222, s4-vim1s, c3 boards) appears to
use phy-handle. So this would only hit out-of-tree or
bootloader-supplied DTs that use the deprecated names.
The comment refers to dwmac-rk. dwmac-rk has read only phy-handle from
the start, though, so it never broke a working setup. Here a setup that
used to work would break.
Would fwnode_get_phy_node(of_fwnode_handle(mac)), or the same
three-property fallback, keep the mux in step with the PHY stmmac
attaches?
> + of_node_put(mac);
> + if (!phy)
> + return false;
[ ... ]
> @@ -313,6 +351,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))
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115-g12a-mux-data-path-v1-1-011dad738698%40iav.lv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 19:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 19:22 [PATCH net] net: mdio: mux-meson-g12a: keep the MAC data path when switching MDIO Igor Velkov via B4 Relay
2026-11-16 19:24 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox