Skip to contentSkip to conversation

net: ethernet: mtk_eth_soc: improve device tree handling

PATCH Applied Daniel Golle 2 participants 5 messages Jul 2, 2025 – Jul 8, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v5 cover net: ethernet: mtk_eth_soc: improve device tree handling

This series further improves the mtk_eth_soc driver in preparation to complete upstream support for the MediaTek MT7988 SoC family.

Frank Wunderlich's previous attempt to have the ethernet node included in mt7988a.dtsi and cover support for MT7988 in the device tree bindings was criticized for the way mtk_eth_soc references SRAM in device tree[1].

Having a 2nd 'reg' property, like introduced by commit ebb1e4f9cf38 ("net: ethernet: mtk_eth_soc: add support for in-SoC SRAM") isn't acceptable and a dedicated "mmio-sram" node should be used instead.

In order to make the code more clean and readable, the existing hardcoded offsets for the scratch ring, RX and TX rings are dropped in favor of using the generic allocator. However, support for the hardcoded offset of the SRAM itself being included as part of the Ethernet's "reg" MMIO space is kept as it will still be required in order to support existing legacy device trees of the MT7986 SoC family.

While at it also replace confusing error messages when using legacy device trees without "interrupt-names" with a warning informing users that they are using a legacy device tree.

[1]: https://patchwork.ozlabs.org/comment/3533543/

Daniel Golle (3):
net: ethernet: mtk_eth_soc: improve support for named interrupts
net: ethernet: mtk_eth_soc: fix kernel-doc comment
net: ethernet: mtk_eth_soc: use generic allocator for SRAM

 drivers/net/ethernet/mediatek/Kconfig       |   1 +
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 167 +++++++++++---------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  11 +-
 3 files changed, 101 insertions(+), 78 deletions(-)
Signature · 1 line
2.50.0
#1 lore raw

PATCH v5 1/3 net: ethernet: mtk_eth_soc: improve support for named interrupts

Use platform_get_irq_byname_optional() to avoid outputting error messages when using legacy device trees which rely identifying interrupts only by index. Instead, output a warning notifying the user to update their device tree.

---
v5: unchanged
v4: unchanged
v3: unchanged
v2: unchanged

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +10 -5
index f8a907747db4..8f55069441f4 100644
@@ -3341,17 +3341,22 @@ static int mtk_get_irqs(struct platform_device *pdev, struct mtk_eth *eth)
 	int i;
 
 	/* future SoCs beginning with MT7988 should use named IRQs in dts */
-	eth->irq[MTK_FE_IRQ_TX] = platform_get_irq_byname(pdev, "fe1");
-	eth->irq[MTK_FE_IRQ_RX] = platform_get_irq_byname(pdev, "fe2");
+	eth->irq[MTK_FE_IRQ_TX] = platform_get_irq_byname_optional(pdev, "fe1");
+	eth->irq[MTK_FE_IRQ_RX] = platform_get_irq_byname_optional(pdev, "fe2");
 	if (eth->irq[MTK_FE_IRQ_TX] >= 0 && eth->irq[MTK_FE_IRQ_RX] >= 0)
 		return 0;
 
-	/* only use legacy mode if platform_get_irq_byname returned -ENXIO */
+	/* only use legacy mode if platform_get_irq_byname_optional returned -ENXIO */
 	if (eth->irq[MTK_FE_IRQ_TX] != -ENXIO)
-		return eth->irq[MTK_FE_IRQ_TX];
+		return dev_err_probe(&pdev->dev, eth->irq[MTK_FE_IRQ_TX],
+				     "Error requesting FE TX IRQ\n");
 
 	if (eth->irq[MTK_FE_IRQ_RX] != -ENXIO)
-		return eth->irq[MTK_FE_IRQ_RX];
+		return dev_err_probe(&pdev->dev, eth->irq[MTK_FE_IRQ_RX],
+				     "Error requesting FE RX IRQ\n");
+
+	if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT))
+		dev_warn(&pdev->dev, "legacy DT: missing interrupt-names.");
 
 	/* legacy way:
 	 * On MTK_SHARED_INT SoCs (MT7621 + MT7628) the first IRQ is taken
Signature · 1 line
2.50.0
#2 lore raw

PATCH v5 2/3 net: ethernet: mtk_eth_soc: fix kernel-doc comment

In reply to Daniel Golle

Fix and add some missing field descriptions to kernel-doc comment of struct mtk_eth.

---
v5: unchanged
v4: unchanged
v3: unchanged
v2: unchanged

 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +2 -1
index 9261c0e13b59..1ad9075a9b69 100644
@@ -1243,8 +1243,9 @@ struct mtk_soc_data {
 /* struct mtk_eth -	This is the main datasructure for holding the state
  *			of the driver
  * @dev:		The device pointer
- * @dev:		The device pointer used for dma mapping/alloc
+ * @dma_dev:		The device pointer used for dma mapping/alloc
  * @base:		The mapped register i/o base
+ * @sram_base:		The mapped SRAM base
  * @page_lock:		Make sure that register operations are atomic
  * @tx_irq__lock:	Make sure that IRQ register operations are atomic
  * @rx_irq__lock:	Make sure that IRQ register operations are atomic
Signature · 1 line
2.50.0
#3 lore raw

PATCH v5 3/3 net: ethernet: mtk_eth_soc: use generic allocator for SRAM

In reply to Daniel Golle

Use a dedicated "mmio-sram" node and the generic allocator instead of open-coding SRAM allocation for DMA rings. Keep support for legacy device trees but notify the user via a warning to update, and let the ethernet driver create the gen_pool in this case.

---
v5: remove unused variable tx_ring_size in mtk_rx_alloc()
avoid long lines
v4: always use gen_pool allocator completely replacing the
previous approach of hardcoded SRAM offsets added missing Kconfig change
v3: fix resource leak on error in mtk_probe()
v2: fix return type of mtk_dma_ring_alloc() in case of error

 drivers/net/ethernet/mediatek/Kconfig       |   1 +
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 152 +++++++++++---------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  10 +-
 3 files changed, 90 insertions(+), 73 deletions(-)
drivers/net/ethernet/mediatek/Kconfig +1 -0
index 7bfd3f230ff5..2ba361f8ce7d 100644
@@ -17,6 +17,7 @@ config NET_MEDIATEK_SOC
 	select PINCTRL
 	select PHYLINK
 	select DIMLIB
+	select GENERIC_ALLOCATOR
 	select PAGE_POOL
 	select PAGE_POOL_STATS
 	select PCS_MTK_LYNXI
drivers/net/ethernet/mediatek/mtk_eth_soc.c +83 -69

236 lines not on this page · raw message

drivers/net/ethernet/mediatek/mtk_eth_soc.h +6 -4
index 1ad9075a9b69..0168e2fbc619 100644
@@ -141,8 +141,10 @@
 #define MTK_GDMA_MAC_ADRH(x)	({ typeof(x) _x = (x); (_x == MTK_GMAC3_ID) ?	\
 				   0x54C : 0x50C + (_x * 0x1000); })
 
-/* Internal SRAM offset */
-#define MTK_ETH_SRAM_OFFSET	0x40000
+/* legacy DT support for internal SRAM */
+#define MTK_ETH_SRAM_OFFSET		0x40000
+#define MTK_ETH_SRAM_GRANULARITY	32
+#define MTK_ETH_NETSYS_V2_SRAM_SIZE	0x40000
 
 /* FE global misc reg*/
 #define MTK_FE_GLO_MISC         0x124
@@ -1245,7 +1247,7 @@ struct mtk_soc_data {
  * @dev:		The device pointer
  * @dma_dev:		The device pointer used for dma mapping/alloc
  * @base:		The mapped register i/o base
- * @sram_base:		The mapped SRAM base
+ * @sram_pool:		Pointer to SRAM pool used for DMA descriptor rings
  * @page_lock:		Make sure that register operations are atomic
  * @tx_irq__lock:	Make sure that IRQ register operations are atomic
  * @rx_irq__lock:	Make sure that IRQ register operations are atomic
@@ -1291,7 +1293,7 @@ struct mtk_eth {
 	struct device			*dev;
 	struct device			*dma_dev;
 	void __iomem			*base;
-	void				*sram_base;
+	struct gen_pool			*sram_pool;
 	spinlock_t			page_lock;
 	spinlock_t			tx_irq_lock;
 	spinlock_t			rx_irq_lock;
Signature · 1 line
2.50.0
#4 lore raw
In reply to Daniel Golle
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 2 Jul 2025 14:14:20 +0100 you wrote:

This series further improves the mtk_eth_soc driver in preparation to complete upstream support for the MediaTek MT7988 SoC family.

Frank Wunderlich's previous attempt to have the ethernet node included in mt7988a.dtsi and cover support for MT7988 in the device tree bindings was criticized for the way mtk_eth_soc references SRAM in device tree[1].

[...]

Here is the summary with links:
- [net-next,v5,1/3] net: ethernet: mtk_eth_soc: improve support for named interrupts

    https://git.kernel.org/netdev/net-next/c/e81d36d48880
  - [net-next,v5,2/3] net: ethernet: mtk_eth_soc: fix kernel-doc comment
    https://git.kernel.org/netdev/net-next/c/d717d32f517f
  - [net-next,v5,3/3] net: ethernet: mtk_eth_soc: use generic allocator for SRAM
    https://git.kernel.org/netdev/net-next/c/04c7aaccdcf6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html