net: ethernet: mtk_eth_soc: improve device tree handling
Subsystems (4)
v4 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. In this way support for the hard-coded offset and including the SRAM region 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 | 155 +++++++++++--------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 +- 3 files changed, 95 insertions(+), 72 deletions(-)
Signature · 1 line
2.50.0
PATCH v4 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.
---
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
@@ -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
PATCH v4 2/3 net: ethernet: mtk_eth_soc: fix kernel-doc comment
In reply to Daniel GolleFix and add some missing field descriptions to kernel-doc comment of struct mtk_eth.
---
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
@@ -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
PATCH v4 3/3 net: ethernet: mtk_eth_soc: use generic allocator for SRAM
In reply to Daniel GolleUse 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.
---
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 | 140 +++++++++++--------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 10 +- 3 files changed, 84 insertions(+), 67 deletions(-)
drivers/net/ethernet/mediatek/Kconfig +1 -0
@@ -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 +77 -63
216 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_eth_soc.h +6 -4
@@ -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
Re: [PATCH net-next v4 3/3] net: ethernet: mtk_eth_soc: use generic allocator for SRAM
Quoted 9 lines · 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_poolin this case.Co-developed-by Frank Wunderlich <[email protected]>Signed-off-by Frank Wunderlich <[email protected]>Signed-off-by Daniel Golle <[email protected]>
Andrew