Commit a2d2cadc authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'net-dunamic-dummy-device'

Breno Leitao says:

====================
allocate dummy device dynamically

struct net_device shouldn't be embedded into any structure, instead,
the owner should use the private space to embed their state into
net_device.

But, in some cases the net_device is embedded inside the private
structure, which blocks the usage of zero-length arrays inside
net_device.

Create a helper to allocate a dummy device at dynamically runtime, and
move the Ethernet devices to use it, instead of embedding the dummy
device inside the private structure.

This fixes all the network cases plus some wireless drivers.

PS: Due to lack of hardware, unfortunately most these patches are
compiled tested only, except ath11k that was kindly tested by Kalle Valo.

---
Changelog:

v7:
	* Document the return value of alloc_netdev_dummy()
v6:
	* No code change. Just added Reviewed-by: and fix a commit message
v5:
	* Added a new patch to fix some typos in the previous code
	* Rebased to net-net/main
v4:
	* Added a new patch to add dummy device at free_netdev(), as suggested
	  by Jakub.
	* Added support for some wireless driver.
	* Added some Acked-by and Reviewed-by.
v3:
	* Use free_netdev() instead of kfree() as suggested by Jakub.
	* Change the free_netdev() place in ipa driver, as suggested by
	  Alex Elder.
	* Set err in the error path in the Marvell driver, as suggested
	  by Simon Horman.
v2:
	* Patch 1: Use a pre-defined name ("dummy#") for the dummy
	  net_devices.
	* Patch 2-5: Added users for the new helper.
v1:
	* https://lore.kernel.org/all/20240327200809.512867-1-leitao@debian.org/


====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 55972ce6 bca592ea
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -605,9 +605,13 @@ static int mal_probe(struct platform_device *ofdev)
	INIT_LIST_HEAD(&mal->list);
	spin_lock_init(&mal->lock);

	init_dummy_netdev(&mal->dummy_dev);
	mal->dummy_dev = alloc_netdev_dummy(0);
	if (!mal->dummy_dev) {
		err = -ENOMEM;
		goto fail_unmap;
	}

	netif_napi_add_weight(&mal->dummy_dev, &mal->napi, mal_poll,
	netif_napi_add_weight(mal->dummy_dev, &mal->napi, mal_poll,
			      CONFIG_IBM_EMAC_POLL_WEIGHT);

	/* Load power-on reset defaults */
@@ -637,7 +641,7 @@ static int mal_probe(struct platform_device *ofdev)
					  GFP_KERNEL);
	if (mal->bd_virt == NULL) {
		err = -ENOMEM;
		goto fail_unmap;
		goto fail_dummy;
	}

	for (i = 0; i < mal->num_tx_chans; ++i)
@@ -703,6 +707,8 @@ static int mal_probe(struct platform_device *ofdev)
	free_irq(mal->serr_irq, mal);
 fail2:
	dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
 fail_dummy:
	free_netdev(mal->dummy_dev);
 fail_unmap:
	dcr_unmap(mal->dcr_host, 0x100);
 fail:
@@ -734,6 +740,8 @@ static void mal_remove(struct platform_device *ofdev)

	mal_reset(mal);

	free_netdev(mal->dummy_dev);

	dma_free_coherent(&ofdev->dev,
			  sizeof(struct mal_descriptor) *
			  (NUM_TX_BUFF * mal->num_tx_chans +
+1 −1
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ struct mal_instance {
	int			index;
	spinlock_t		lock;

	struct net_device	dummy_dev;
	struct net_device	*dummy_dev;

	unsigned int features;
};
+12 −3
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ struct prestera_sdma {
	struct dma_pool *desc_pool;
	struct work_struct tx_work;
	struct napi_struct rx_napi;
	struct net_device napi_dev;
	struct net_device *napi_dev;
	u32 map_addr;
	u64 dma_mask;
	/* protect SDMA with concurrent access from multiple CPUs */
@@ -654,13 +654,21 @@ static int prestera_sdma_switch_init(struct prestera_switch *sw)
	if (err)
		goto err_evt_register;

	init_dummy_netdev(&sdma->napi_dev);
	sdma->napi_dev = alloc_netdev_dummy(0);
	if (!sdma->napi_dev) {
		dev_err(dev, "not able to initialize dummy device\n");
		err = -ENOMEM;
		goto err_alloc_dummy;
	}

	netif_napi_add(&sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll);
	netif_napi_add(sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll);
	napi_enable(&sdma->rx_napi);

	return 0;

err_alloc_dummy:
	prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX,
					     prestera_rxtx_handle_event);
err_evt_register:
err_tx_init:
	prestera_sdma_tx_fini(sdma);
@@ -677,6 +685,7 @@ static void prestera_sdma_switch_fini(struct prestera_switch *sw)

	napi_disable(&sdma->rx_napi);
	netif_napi_del(&sdma->rx_napi);
	free_netdev(sdma->napi_dev);
	prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX,
					     prestera_rxtx_handle_event);
	prestera_sdma_tx_fini(sdma);
+13 −4
Original line number Diff line number Diff line
@@ -1710,7 +1710,7 @@ static struct page_pool *mtk_create_page_pool(struct mtk_eth *eth,
	if (IS_ERR(pp))
		return pp;

	err = __xdp_rxq_info_reg(xdp_q, &eth->dummy_dev, id,
	err = __xdp_rxq_info_reg(xdp_q, eth->dummy_dev, id,
				 eth->rx_napi.napi_id, PAGE_SIZE);
	if (err < 0)
		goto err_free_pp;
@@ -4188,6 +4188,8 @@ static int mtk_free_dev(struct mtk_eth *eth)
		metadata_dst_free(eth->dsa_meta[i]);
	}

	free_netdev(eth->dummy_dev);

	return 0;
}

@@ -4983,9 +4985,14 @@ 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
	 */
	init_dummy_netdev(&eth->dummy_dev);
	netif_napi_add(&eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
	netif_napi_add(&eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
	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,
@@ -4993,6 +5000,8 @@ static int mtk_probe(struct platform_device *pdev)

	return 0;

err_unreg_netdev:
	mtk_unreg_dev(eth);
err_deinit_ppe:
	mtk_ppe_deinit(eth);
	mtk_mdio_cleanup(eth);
+1 −1
Original line number Diff line number Diff line
@@ -1242,7 +1242,7 @@ struct mtk_eth {
	spinlock_t			page_lock;
	spinlock_t			tx_irq_lock;
	spinlock_t			rx_irq_lock;
	struct net_device		dummy_dev;
	struct net_device		*dummy_dev;
	struct net_device		*netdev[MTK_MAX_DEVS];
	struct mtk_mac			*mac[MTK_MAX_DEVS];
	int				irq[3];
Loading