[net-next v5 1/3] net: ethernet: mtk_eth_soc: support named IRQs

Frank Wunderlich posted 3 patches 3 months, 3 weeks ago
There is a newer version of this series
[net-next v5 1/3] net: ethernet: mtk_eth_soc: support named IRQs
Posted by Frank Wunderlich 3 months, 3 weeks ago
From: Frank Wunderlich <frank-w@public-files.de>

Add named interrupts and keep index based fallback for existing
devicetrees.

Currently only rx and tx IRQs are defined to be used with mt7988, but
later extended with RSS/LRO support.

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Reviewed-by: Simon Horman <horms@kernel.org>
---
v5:
- fix typo in description
- add comments from previous patch #3 with changes suggested by simon

v2:
- move irqs loading part into own helper function
- reduce indentation
- place mtk_get_irqs helper before the irq_handler (note for simon)
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 46 ++++++++++++++++-----
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index b76d35069887..39b673ed7495 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -3337,6 +3337,37 @@ static void mtk_tx_timeout(struct net_device *dev, unsigned int txqueue)
 	schedule_work(&eth->pending_work);
 }
 
+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[1] = platform_get_irq_byname(pdev, "tx");
+	eth->irq[2] = platform_get_irq_byname(pdev, "rx");
+	if (eth->irq[1] >= 0 && eth->irq[2] >= 0)
+		return 0;
+
+	/* legacy way:
+	 * On MTK_SHARED_INT SoCs (MT7621 + MT7628) the first IRQ is taken
+	 * from devicetree and used for both RX and TX - it is shared.
+	 * On SoCs with non-shared IRQs the first entry is not used,
+	 * the second is for TX, and the third is for RX.
+	 */
+	for (i = 0; i < 3; i++) {
+		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT) && i > 0)
+			eth->irq[i] = eth->irq[0];
+		else
+			eth->irq[i] = platform_get_irq(pdev, i);
+
+		if (eth->irq[i] < 0) {
+			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
+			return -ENXIO;
+		}
+	}
+
+	return 0;
+}
+
 static irqreturn_t mtk_handle_irq_rx(int irq, void *_eth)
 {
 	struct mtk_eth *eth = _eth;
@@ -5106,17 +5137,10 @@ static int mtk_probe(struct platform_device *pdev)
 		}
 	}
 
-	for (i = 0; i < 3; i++) {
-		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT) && i > 0)
-			eth->irq[i] = eth->irq[0];
-		else
-			eth->irq[i] = platform_get_irq(pdev, i);
-		if (eth->irq[i] < 0) {
-			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
-			err = -ENXIO;
-			goto err_wed_exit;
-		}
-	}
+	err = mtk_get_irqs(pdev, eth);
+	if (err)
+		goto err_wed_exit;
+
 	for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
 		eth->clks[i] = devm_clk_get(eth->dev,
 					    mtk_clks_source_name[i]);
-- 
2.43.0
Re: [net-next v5 1/3] net: ethernet: mtk_eth_soc: support named IRQs
Posted by Daniel Golle 3 months, 3 weeks ago
On Wed, Jun 18, 2025 at 03:07:12PM +0200, Frank Wunderlich wrote:
> From: Frank Wunderlich <frank-w@public-files.de>
> 
> Add named interrupts and keep index based fallback for existing
> devicetrees.
> 
> Currently only rx and tx IRQs are defined to be used with mt7988, but
> later extended with RSS/LRO support.
> 
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> Reviewed-by: Simon Horman <horms@kernel.org>
>  
> +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[1] = platform_get_irq_byname(pdev, "tx");
> +	eth->irq[2] = platform_get_irq_byname(pdev, "rx");
> +	if (eth->irq[1] >= 0 && eth->irq[2] >= 0)
> +		return 0;

I'd rather extend that logic and fall back to the legacy way only in case
of -ENXIO. Ie. add here:

if (eth->irq[1] != -ENXIO)
	return eth->irq[1];

if (eth->irq[2] != -ENXIO)
	return eth->irq[2];

Maybe also output a warning at this point in case MTK_SHARED_INT is no
set, to recommend users to update their device tree to named interrupts.

> +
> +	/* legacy way:
> +	 * On MTK_SHARED_INT SoCs (MT7621 + MT7628) the first IRQ is taken
> +	 * from devicetree and used for both RX and TX - it is shared.
> +	 * On SoCs with non-shared IRQs the first entry is not used,
> +	 * the second is for TX, and the third is for RX.
> +	 */
> +	for (i = 0; i < 3; i++) {
> +		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT) && i > 0)
> +			eth->irq[i] = eth->irq[0];
> +		else
> +			eth->irq[i] = platform_get_irq(pdev, i);
> +
> +		if (eth->irq[i] < 0) {
> +			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
> +			return -ENXIO;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  static irqreturn_t mtk_handle_irq_rx(int irq, void *_eth)
>  {
>  	struct mtk_eth *eth = _eth;
> @@ -5106,17 +5137,10 @@ static int mtk_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> -	for (i = 0; i < 3; i++) {
> -		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT) && i > 0)
> -			eth->irq[i] = eth->irq[0];
> -		else
> -			eth->irq[i] = platform_get_irq(pdev, i);
> -		if (eth->irq[i] < 0) {
> -			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
> -			err = -ENXIO;
> -			goto err_wed_exit;
> -		}
> -	}
> +	err = mtk_get_irqs(pdev, eth);
> +	if (err)
> +		goto err_wed_exit;
> +
>  	for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
>  		eth->clks[i] = devm_clk_get(eth->dev,
>  					    mtk_clks_source_name[i]);
> -- 
> 2.43.0
> 
>
Re: [net-next v5 1/3] net: ethernet: mtk_eth_soc: support named IRQs
Posted by Frank Wunderlich 3 months, 3 weeks ago
Am 18. Juni 2025 15:55:45 MESZ schrieb Daniel Golle <daniel@makrotopia.org>:
>On Wed, Jun 18, 2025 at 03:07:12PM +0200, Frank Wunderlich wrote:
>> From: Frank Wunderlich <frank-w@public-files.de>
>> 
>> Add named interrupts and keep index based fallback for existing
>> devicetrees.
>> 
>> Currently only rx and tx IRQs are defined to be used with mt7988, but
>> later extended with RSS/LRO support.
>> 
>> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
>> Reviewed-by: Simon Horman <horms@kernel.org>
>>  
>> +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[1] = platform_get_irq_byname(pdev, "tx");
>> +	eth->irq[2] = platform_get_irq_byname(pdev, "rx");
>> +	if (eth->irq[1] >= 0 && eth->irq[2] >= 0)
>> +		return 0;
>
>I'd rather extend that logic and fall back to the legacy way only in case
>of -ENXIO. Ie. add here:
>
>if (eth->irq[1] != -ENXIO)
>	return eth->irq[1];
>
>if (eth->irq[2] != -ENXIO)
>	return eth->irq[2];

I would do this later after the consts are used
 instead of index numbers,just to not add lines
 that are changed later again.Better adding the
 lines already with the consts.

>Maybe also output a warning at this point in case MTK_SHARED_INT is no
>set, to recommend users to update their device tree to named interrupts.

I understand the reason behind (documentation
 which irq is used for which purpose),but
 previous devicetrees of non-shared SoCs using
 at least the reserved irq 0. Mt7986 has 0 and 3
 defined in dts. That could be tricky in binding,
 so my way was starting with irq names now for
 new additions and leaving existing dts as they
 are.

Maybe i should add the mt7988 ethernet binding change from my dts series here...

regards Frank