Re: [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup

From: Maxime Chevallier

Date: Sun Nov 22 2026 - 12:35:31 EST


Hi,

On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
>
> Both PHYs sit behind the mux, but the mux is registered only after
> stmmac_pltfr_probe() has registered the netdev, so an early open does
> not find the PHY. On remove, the mux goes away before
> unregister_netdev(), and unbinding with the link up oopses in
> phy_stop().
>
> Register and unregister the mux through the new mdio_init() and
> mdio_exit() hooks.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>

Looks good, I tested that on Allwinner H2+, the mux probes fine. This
has run on the stmmac netdevCI anyways and no breakage reported on
other plaftorms.

Reviewed-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>
Tested-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>

Maxime

> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 41 ++++++-----------------
> 1 file changed, 10 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 4acfda235394..0ec25ae0b77e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -17,7 +17,6 @@
> #include <linux/of_platform.h>
> #include <linux/phy.h>
> #include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
> #include <linux/regulator/consumer.h>
> #include <linux/regmap.h>
> #include <linux/stmmac.h>
> @@ -941,6 +940,13 @@ static int sun8i_dwmac_register_mdio_mux(struct stmmac_priv *priv)
> return ret;
> }
>
> +static void sun8i_dwmac_unregister_mdio_mux(struct stmmac_priv *priv)
> +{
> + struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
> +
> + mdio_mux_uninit(gmac->mux_handle);
> +}
> +
> static int sun8i_dwmac_set_syscon(struct device *dev,
> struct plat_stmmacenet_data *plat)
> {
> @@ -1133,8 +1139,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> struct stmmac_resources stmmac_res;
> struct sunxi_priv_data *gmac;
> struct device *dev = &pdev->dev;
> - struct stmmac_priv *priv;
> - struct net_device *ndev;
> struct regmap *regmap;
> int ret;
>
> @@ -1217,6 +1221,9 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> ret = get_ephy_nodes(dev, gmac);
> if (ret)
> return ret;
> +
> + plat_dat->mdio_init = sun8i_dwmac_register_mdio_mux;
> + plat_dat->mdio_exit = sun8i_dwmac_unregister_mdio_mux;
> }
>
> ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
> @@ -1227,33 +1234,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> if (ret)
> goto dwmac_syscon;
>
> - ndev = dev_get_drvdata(&pdev->dev);
> - priv = netdev_priv(ndev);
> -
> - /* the MAC is runtime suspended after stmmac_dvr_probe(), so we
> - * need to ensure the MAC resume back before other operations such
> - * as reset.
> - */
> - pm_runtime_get_sync(&pdev->dev);
> -
> - /* The mux must be registered after parent MDIO
> - * so after stmmac_dvr_probe()
> - */
> - if (gmac->variant->soc_has_internal_phy) {
> - ret = sun8i_dwmac_register_mdio_mux(priv);
> - if (ret) {
> - dev_err(&pdev->dev, "Failed to register mux\n");
> - goto dwmac_remove;
> - }
> - }
> -
> - pm_runtime_put(&pdev->dev);
> -
> return 0;
>
> -dwmac_remove:
> - pm_runtime_put_noidle(&pdev->dev);
> - stmmac_pltfr_remove(pdev);
> dwmac_syscon:
> sun8i_dwmac_unset_syscon(gmac);
> dwmac_ephy:
> @@ -1269,9 +1251,6 @@ static void sun8i_dwmac_remove(struct platform_device *pdev)
> struct stmmac_priv *priv = netdev_priv(ndev);
> struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
>
> - if (gmac->variant->soc_has_internal_phy)
> - mdio_mux_uninit(gmac->mux_handle);
> -
> stmmac_pltfr_remove(pdev);
> reset_control_put(gmac->rst_ephy);
> clk_put(gmac->ephy_clk);
>