From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Russell King <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev,
linux-stm32@st-md-mailman.stormreply.com,
linux-kernel@vger.kernel.org,
Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
Date: Fri, 20 Nov 2026 10:45:33 +0000 [thread overview]
Message-ID: <20261120-sun8i-emac-mux-uaf-v4-2-57eba8915f25@gmail.com> (raw)
In-Reply-To: <20261120-sun8i-emac-mux-uaf-v4-0-57eba8915f25@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
get_ephy_nodes() runs after stmmac_pltfr_probe() has registered the
netdev, so its -EPROBE_DEFER comes too late. An EPHY clock that is not
ready yet does not defer at all: the node is skipped and the probe
fails with -ENODEV.
Look up the clock and reset before stmmac_pltfr_probe(), and defer on
the clock as on the reset.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 34 ++++++++++++++---------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 9fb398f7cf9e..4acfda235394 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -775,16 +775,15 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
}
/* Search in mdio-mux node for internal PHY node and get its clk/reset */
-static int get_ephy_nodes(struct stmmac_priv *priv)
+static int get_ephy_nodes(struct device *dev, struct sunxi_priv_data *gmac)
{
- struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
struct device_node *mdio_internal;
struct device_node *mdio_mux;
int ret;
- mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux");
+ mdio_mux = of_get_child_by_name(dev->of_node, "mdio-mux");
if (!mdio_mux) {
- dev_err(priv->device, "Cannot get mdio-mux node\n");
+ dev_err(dev, "Cannot get mdio-mux node\n");
return -ENODEV;
}
@@ -792,7 +791,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
"allwinner,sun8i-h3-mdio-internal");
of_node_put(mdio_mux);
if (!mdio_internal) {
- dev_err(priv->device, "Cannot get internal_mdio node\n");
+ dev_err(dev, "Cannot get internal_mdio node\n");
return -ENODEV;
}
@@ -801,8 +800,13 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
struct clk *ephy_clk;
ephy_clk = of_clk_get(iphynode, 0);
- if (IS_ERR(ephy_clk))
+ if (IS_ERR(ephy_clk)) {
+ if (PTR_ERR(ephy_clk) == -EPROBE_DEFER) {
+ of_node_put(mdio_internal);
+ return -EPROBE_DEFER;
+ }
continue;
+ }
gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL);
if (IS_ERR(gmac->rst_ephy)) {
ret = PTR_ERR(gmac->rst_ephy);
@@ -814,7 +818,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
continue;
}
gmac->ephy_clk = ephy_clk;
- dev_info(priv->device, "Found internal PHY node\n");
+ dev_info(dev, "Found internal PHY node\n");
of_node_put(mdio_internal);
return 0;
}
@@ -1209,9 +1213,15 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
plat_dat->tx_fifo_size = 4096;
plat_dat->rx_fifo_size = 16384;
+ if (gmac->variant->soc_has_internal_phy) {
+ ret = get_ephy_nodes(dev, gmac);
+ if (ret)
+ return ret;
+ }
+
ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
if (ret)
- return ret;
+ goto dwmac_ephy;
ret = stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
if (ret)
@@ -1230,9 +1240,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
* so after stmmac_dvr_probe()
*/
if (gmac->variant->soc_has_internal_phy) {
- ret = get_ephy_nodes(priv);
- if (ret)
- goto dwmac_remove;
ret = sun8i_dwmac_register_mdio_mux(priv);
if (ret) {
dev_err(&pdev->dev, "Failed to register mux\n");
@@ -1247,10 +1254,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
dwmac_remove:
pm_runtime_put_noidle(&pdev->dev);
stmmac_pltfr_remove(pdev);
- reset_control_put(gmac->rst_ephy);
- clk_put(gmac->ephy_clk);
dwmac_syscon:
sun8i_dwmac_unset_syscon(gmac);
+dwmac_ephy:
+ reset_control_put(gmac->rst_ephy);
+ clk_put(gmac->ephy_clk);
return ret;
}
--
2.55.0
next prev parent reply other threads:[~2026-11-20 10:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
2026-11-22 16:47 ` Maxime Chevallier
2026-11-20 10:45 ` Arun Iyengar via B4 Relay [this message]
2026-11-22 16:51 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Maxime Chevallier
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
2026-11-22 17:03 ` Maxime Chevallier
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
2026-11-22 17:05 ` Maxime Chevallier
2026-11-22 17:35 ` Maxime Chevallier
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
2026-11-22 17:35 ` Maxime Chevallier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120-sun8i-emac-mux-uaf-v4-2-57eba8915f25@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=samuel@sholland.org \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®