Re: [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks

From: Maxime Chevallier

Date: Sun Nov 22 2026 - 12:36:02 EST


Hi again,

On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
>
> A glue driver that adds devices on top of the stmmac MDIO bus, such as
> an MDIO mux, can only do so after stmmac_dvr_probe() has registered the
> netdev.
>
> Add mdio_init(), called once the bus is registered, and mdio_exit(),
> called before it is unregistered.
>
> Suggested-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>
> Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>

Manually tested on H2+,

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

Maxime

> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 11 +++++++++++
> include/linux/stmmac.h | 2 ++
> 2 files changed, 13 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 7396b68899c6..fb1f7b1a5323 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -682,8 +682,16 @@ int stmmac_mdio_register(struct net_device *ndev)
> bus_register_done:
> priv->mii = new_bus;
>
> + if (priv->plat->mdio_init) {
> + err = priv->plat->mdio_init(priv);
> + if (err)
> + goto mdio_init_fail;
> + }
> +
> return 0;
>
> +mdio_init_fail:
> + priv->mii = NULL;
> no_phy_found:
> mdiobus_unregister(new_bus);
> bus_register_fail:
> @@ -703,6 +711,9 @@ int stmmac_mdio_unregister(struct net_device *ndev)
> if (!priv->mii)
> return 0;
>
> + if (priv->plat->mdio_exit)
> + priv->plat->mdio_exit(priv);
> +
> mdiobus_unregister(priv->mii);
> priv->mii->priv = NULL;
> mdiobus_free(priv->mii);
> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 00be2df63d22..e94f9cab973d 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -296,6 +296,8 @@ struct plat_stmmacenet_data {
> int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
> void *ctx);
> void (*dump_debug_regs)(void *priv);
> + int (*mdio_init)(struct stmmac_priv *priv);
> + void (*mdio_exit)(struct stmmac_priv *priv);
> int (*pcs_init)(struct stmmac_priv *priv);
> void (*pcs_exit)(struct stmmac_priv *priv);
> struct phylink_pcs *(*select_pcs)(struct stmmac_priv *priv,
>