Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: mtk_eth_soc: allocate dummy netdev before registering netdevs
@ 2026-09-15 18:55 Sandeep Haemoon
  2026-09-16 13:32 ` Lorenzo Bianconi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sandeep Haemoon @ 2026-09-15 18:55 UTC (permalink / raw)
  To: netdev; +Cc: Felix Fietkau, Lorenzo Bianconi, stable

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sandeep Haemoon <sandeeph@loljews.com>
Date: Tue, 15 Sep 2026 22:00:00 +0300
Subject: [PATCH] net: ethernet: mtk_eth_soc: allocate dummy netdev before registering netdevs

The DMA ring and NAPI are shared between the multiple MAC netdevs and are
carried by an internal "dummy" netdev (eth->dummy_dev). mtk_probe() creates
that dummy device only after the MAC netdevs have been registered, so for a
brief window the netdevs are visible to the network core while
eth->dummy_dev is still NULL.

If anything brings the first netdev up during that window (e.g. netifd
opening the WAN link the instant the interface is registered), mtk_open()
takes the first-open path and runs mtk_start_dma() -> mtk_dma_init() ->
mtk_rx_alloc(), which calls __xdp_rxq_info_reg() with eth->dummy_dev ==
NULL. That triggers

  WARNING: CPU: ... Missing net_device from driver

in net/core/xdp.c and returns -ENODEV, so mtk_open() fails and the
interface (e.g. the WAN port on MediaTek MT7988) stays down until it is
manually brought up after probe has completed.

Allocate the dummy netdev and add the shared tx/rx NAPI to it before
registering the MAC netdevs, and free it from the probe error path instead
of the now-unneeded err_unreg_netdev cleanup.

Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 31 ++++++++++++++--------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index fd7a49a..ae6a19b 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -5337,6 +5337,22 @@ static int mtk_probe(struct platform_device *pdev)
 		}
 	}
 
+	/* we run 2 devices on the same DMA ring so we need a dummy device
+	 * for NAPI to work. Allocate it before registering the netdevs so a
+	 * concurrent ndo_open (e.g. netifd bringing the first netdev up) never
+	 * observes eth->dummy_dev == NULL, which would make mtk_rx_alloc() ->
+	 * __xdp_rxq_info_reg() warn ("Missing net_device from driver",
+	 * net/core/xdp.c) and leave the interface down on boot.
+	 */
+	eth->dummy_dev = alloc_netdev_dummy(0);
+	if (!eth->dummy_dev) {
+		err = -ENOMEM;
+		dev_err(eth->dev, "failed to allocated dummy device\n");
+		goto err_deinit_ppe;
+	}
+	netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
+	netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
+
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
 		if (!eth->netdev[i])
 			continue;
@@ -5351,17 +5367,6 @@ static int mtk_probe(struct platform_device *pdev)
 				   eth->netdev[i]->base_addr, eth->irq[MTK_FE_IRQ_SHARED]);
 	}
 
-	/* we run 2 devices on the same DMA ring so we need a dummy device
-	 * for NAPI to work
-	 */
-	eth->dummy_dev = alloc_netdev_dummy(0);
-	if (!eth->dummy_dev) {
-		err = -ENOMEM;
-		dev_err(eth->dev, "failed to allocated dummy device\n");
-		goto err_unreg_netdev;
-	}
-	netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
-	netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
 
 	platform_set_drvdata(pdev, eth);
 	schedule_delayed_work(&eth->reset.monitor_work,
@@ -5369,9 +5374,9 @@ static int mtk_probe(struct platform_device *pdev)
 
 	return 0;
 
-err_unreg_netdev:
-	mtk_unreg_dev(eth);
 err_deinit_ppe:
+	if (eth->dummy_dev)
+		free_netdev(eth->dummy_dev);
 	mtk_ppe_deinit(eth);
 	mtk_mdio_cleanup(eth);
 err_free_dev:
-- 
2.39.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-24 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-15 18:55 [PATCH] net: ethernet: mtk_eth_soc: allocate dummy netdev before registering netdevs Sandeep Haemoon
2026-09-16 13:32 ` Lorenzo Bianconi
2026-09-19  1:52 ` netdev-bot+sashiko
2026-09-20 17:38 ` [PATCH net v2] " Sandeep Haemoon
2026-09-24 16:31   ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox