[PATCH] fec_main: Register net device before initializing the MDIO bus

From: Paul Geurts
Date: Thu Jun 13 2024 - 10:57:02 EST


Registration of the FEC MDIO bus triggers a probe of all devices
connected to that bus. DSA based Ethernet switch devices connect to the
uplink Ethernet port during probe. When a DSA based, MDIO controlled
Ethernet switch is connected to FEC, it cannot connect the uplink port,
as the FEC MDIO port is registered before the net device is being
registered. This causes an unnecessary defer of the Ethernet switch
driver probe.

Register the net device before initializing and registering the MDIO
bus.

Fixes: e6b043d512fa ("netdev/fec.c: add phylib supporting to enable carrier detection (v2)")
Signed-off-by: Paul Geurts <paul.geurts@xxxxxxxxxxxxxxxxxxxxxxxxx>
---
drivers/net/ethernet/freescale/fec_main.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 881ece735dcf..ed71f1f25ab9 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4500,10 +4500,6 @@ fec_probe(struct platform_device *pdev)
/* Decide which interrupt line is wakeup capable */
fec_enet_get_wakeup_irq(pdev);

- ret = fec_enet_mii_init(pdev);
- if (ret)
- goto failed_mii_init;
-
/* Carrier starts down, phylib will bring it up */
netif_carrier_off(ndev);
fec_enet_clk_enable(ndev, false);
@@ -4515,6 +4511,10 @@ fec_probe(struct platform_device *pdev)
if (ret)
goto failed_register;

+ ret = fec_enet_mii_init(pdev);
+ if (ret)
+ goto failed_mii_init;
+
device_init_wakeup(&ndev->dev, fep->wol_flag &
FEC_WOL_HAS_MAGIC_PACKET);

@@ -4528,9 +4528,9 @@ fec_probe(struct platform_device *pdev)

return 0;

-failed_register:
- fec_enet_mii_remove(fep);
failed_mii_init:
+ unregister_netdev(ndev);
+failed_register:
failed_irq:
fec_enet_deinit(ndev);
failed_init:
@@ -4577,8 +4577,8 @@ fec_drv_remove(struct platform_device *pdev)

cancel_work_sync(&fep->tx_timeout_work);
fec_ptp_stop(pdev);
- unregister_netdev(ndev);
fec_enet_mii_remove(fep);
+ unregister_netdev(ndev);
if (fep->reg_phy)
regulator_disable(fep->reg_phy);

--
2.30.2