Skip to contentSkip to conversation

net: ethernet: mtk_eth_soc: support named IRQs

PATCH Superseded Frank Wunderlich 3 participants 6 messages Jun 15, 2025

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ethernet: mtk_eth_soc: support named IRQs

From: Frank Wunderlich <[email protected]>

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

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

---
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 | 39 +++++++++++++++------
 1 file changed, 28 insertions(+), 11 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +28 -11
index b76d35069887..81ae8a6fe838 100644
@@ -3337,6 +3337,30 @@ 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;
+
+	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;
+
+	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 +5130,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]);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines

From: Frank Wunderlich <[email protected]>

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

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

Hi Frank,

I guess my comments on v1 apply even in v2. Can you please take a look?

Regards,
Lorenzo

Quoted 69 lines

---
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 | 39 +++++++++++++++------
 1 file changed, 28 insertions(+), 11 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +28 -11
index b76d35069887..81ae8a6fe838 100644
@@ -3337,6 +3337,30 @@ 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;
+
+	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;
+
+	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 +5130,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]);
Signature · 1 line
2.43.0
#5 lore raw
In reply to Frank Wunderlich
Quoted 23 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

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

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

---
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 | 39 +++++++++++++++------
 1 file changed, 28 insertions(+), 11 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +0 -0
index b76d35069887..81ae8a6fe838 100644

drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_tx_timeout(struct net_device *dev, unsigned int txqueue) · line 3345

Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -0
@@ -3337,6 +3337,30 @@ 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;
+
+	eth->irq[1] = platform_get_irq_byname(pdev, "tx");
+	eth->irq[2] = platform_get_irq_byname(pdev, "rx");

In addition to Lorenzo's comment to reduce the array to the actually used IRQs, I think it would be nice to introduce precompiler macros for the irq array index, ie. once the array is reduce to size 2 it could be something like

#define MTK_ETH_IRQ_SHARED 0
#define MTK_ETH_IRQ_TX 0
#define MTK_ETH_IRQ_RX 1
#define __MTK_ETH_IRQ_MAX MTK_ETH_IRQ_RX

That would make all the IRQ code more readable than having to deal with numerical values.

Quoted 46 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +22 -11
+	if (eth->irq[1] >= 0 && eth->irq[2] >= 0)
+		return 0;
+
+	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 +5130,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]);
Signature · 1 line
2.43.0
#2 lore raw
In reply to Lorenzo Bianconi

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 7 lines
Quoted 7 lines

From: Frank Wunderlich <[email protected]>

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

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

Quoted 6 lines
Quoted 2 lines

Hi Frank,

I guess my comments on v1 apply even in v2. Can you please take a look?

adding your comments (and mine as context) from v1 here:

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 22 lines
Quoted 5 lines

From: Frank Wunderlich <[email protected]>

I had to leave flow compatible with this:

<https://github.com/frank-w/BPI-Router-Linux/blob/bd7e1983b9f0a69cf47cc9b9631138910d6c1d72/drivers/net/ethernet/mediatek/mtk_eth_soc.c#L5176>

I guess the best would be to start from 0 even here (and wherever it is necessary) and avoid reading current irq[0] since it is not actually used for !shared_int devices (e.g. MT7988). Agree?

Quoted 11 lines

Here the irqs are taken from index 1 and 2 for
registration (!shared_int else only 0). So i avoided changing the index,but yes index 0 is unset at this time.

I guess the irq0 is not really used here...
I tested the code on bpi-r4 and have traffic
rx+tx and no crash.
imho this field is not used on !shared_int
because other irq-handlers are used and
assigned in position above.

Quoted 2 lines

agree. I have not reviewed the code in detail, but this is why I think we can avoid reading it.

i areee, but imho it should be a separate patch because these are 2 different changes

Quoted 15 lines
Quoted 7 lines

It looks like the irq[0] is read before...there is a
message printed for mediatek frame engine which uses index 0 and shows an irq 102 on index way and 0 on named version...but the 102 in index way is not visible in /proc/interrupts.
So imho this message is misleading.

Quoted 7 lines

Intention for this patch is that irq 0 and 3 on
mt7988 (sdk) are reserved (0 is skipped on
!shared_int and 3 never read) and should imho
not listed in devicetree. For further cleaner
devicetrees (with only needed irqs) and to
extend additional irqs for rss/lro imho irq
names make it better readable.

Quoted 2 lines

Same here, if you are not listing them in the device tree, you can remove them in the driver too (and adjust the code to keep the backward compatibility).

afaik i have no SHARED_INT board (only mt7621, mt7628) so changing the index-logic will require testing on such boards too.

i looked a bit into it and see mt7623 and mt7622 have 3 IRQs defined (!SHARED_INT) and i'm not 100% sure if the first is also skipped (as far as i understood code it should always be skipped).

In the end i would change the irq-index part in separate patch once this is accepted to have clean changes and not mixing index with names (at least to allow a revert of second in case of regression).

Am 2025-06-15 11:26, schrieb Daniel Golle:

Quoted 5 lines

In addition to Lorenzo's comment to reduce the array to the actually used IRQs, I think it would be nice to introduce precompiler macros for the irq array index, ie. once the array is reduce to size 2 it could be something like

Quoted 7 lines

#define MTK_ETH_IRQ_SHARED 0
#define MTK_ETH_IRQ_TX 0
#define MTK_ETH_IRQ_RX 1
#define __MTK_ETH_IRQ_MAX MTK_ETH_IRQ_RX

That would make all the IRQ code more readable than having to deal with numerical values.

makes sense, i will take this into the second patch.

I hope you can agree my thoughts about not mixing these 2 parts :)

regards Frank

maintainer
#3 lore raw
Quoted 15 lines

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 14 lines
Quoted 10 lines

From: Frank Wunderlich <[email protected]>

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

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

Hi Frank,

I guess my comments on v1 apply even in v2. Can you please take a look?

sure

Quoted 27 lines

adding your comments (and mine as context) from v1 here:

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 23 lines
Quoted 5 lines

From: Frank Wunderlich <[email protected]>

I had to leave flow compatible with this:

<https://github.com/frank-w/BPI-Router-Linux/blob/bd7e1983b9f0a69cf47cc9b9631138910d6c1d72/drivers/net/ethernet/mediatek/mtk_eth_soc.c#L5176>

I guess the best would be to start from 0 even here (and wherever it is necessary) and avoid reading current irq[0] since it is not actually used for
!shared_int devices (e.g. MT7988). Agree?

Quoted 11 lines

Here the irqs are taken from index 1 and 2 for
registration (!shared_int else only 0). So i avoided changing the index,but yes index 0 is unset at this time.

I guess the irq0 is not really used here...
I tested the code on bpi-r4 and have traffic
rx+tx and no crash.
imho this field is not used on !shared_int
because other irq-handlers are used and
assigned in position above.

Quoted 5 lines
Quoted 2 lines

agree. I have not reviewed the code in detail, but this is why I think we can avoid reading it.

i areee, but imho it should be a separate patch because these are 2 different changes

I am fine to have it in a separate patch but I would prefer to have this patch in the same series, I think it is more clear.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

It looks like the irq[0] is read before...there is a
message printed for mediatek frame engine which uses index 0 and shows an irq 102 on index way and 0 on named version...but the 102 in index way is not visible in /proc/interrupts.
So imho this message is misleading.

Intention for this patch is that irq 0 and 3 on
mt7988 (sdk) are reserved (0 is skipped on
!shared_int and 3 never read) and should imho
not listed in devicetree. For further cleaner
devicetrees (with only needed irqs) and to
extend additional irqs for rss/lro imho irq
names make it better readable.

Quoted 7 lines
Quoted 4 lines

Same here, if you are not listing them in the device tree, you can remove them
in the driver too (and adjust the code to keep the backward compatibility).

afaik i have no SHARED_INT board (only mt7621, mt7628) so changing the index-logic will require testing on such boards too.

I think the change will not heavily impact SHARED_INT devices.

Regards,
Lorenzo

Quoted 31 lines

i looked a bit into it and see mt7623 and mt7622 have 3 IRQs defined (!SHARED_INT) and i'm not 100% sure if the first is also skipped (as far as i understood code it should always be skipped).

In the end i would change the irq-index part in separate patch once this is accepted to have clean changes and not mixing index with names (at least to allow a revert of second in case of regression).

Am 2025-06-15 11:26, schrieb Daniel Golle:

Quoted 8 lines

In addition to Lorenzo's comment to reduce the array to the actually used
IRQs, I think it would be nice to introduce precompiler macros for the irq
array index, ie. once the array is reduce to size 2 it could be something
like

Quoted 7 lines

#define MTK_ETH_IRQ_SHARED 0
#define MTK_ETH_IRQ_TX 0
#define MTK_ETH_IRQ_RX 1
#define __MTK_ETH_IRQ_MAX MTK_ETH_IRQ_RX

That would make all the IRQ code more readable than having to deal with numerical values.

makes sense, i will take this into the second patch.

I hope you can agree my thoughts about not mixing these 2 parts :)

regards Frank

#4 lore raw

Am 2025-06-15 12:13, schrieb Lorenzo Bianconi:

Quoted 8 lines
Quoted 6 lines

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 5 lines
Quoted 2 lines

From: Frank Wunderlich <[email protected]>

Hi Frank,

I guess my comments on v1 apply even in v2. Can you please take a look?

sure

:)

Quoted 5 lines
Quoted 2 lines

Am 2025-06-15 10:57, schrieb Lorenzo Bianconi:

Quoted 1 line
Quoted 1 line

From: Frank Wunderlich <[email protected]>

I am fine to have it in a separate patch but I would prefer to have this patch in the same series, I think it is more clear.

I added changes for your and daniels comments to my repo (top 2 commits):

https://github.com/frank-w/BPI-Router-Linux/commits/6.16-mt7988upstream/

i would squash daniels suggestions in this patch here (MAX without __ and fixed value of 3 to use for the loop - i guess this was intended for this purpose) and then the change for index in second patch.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Same here, if you are not listing them in the device tree, you can remove them
in the driver too (and adjust the code to keep the backward compatibility).

i plan to use named IRQs on mt7988 without the reserved ones (only rx+tx + RSS IRQs), and loading not index based.

Quoted 4 lines
Quoted 2 lines

afaik i have no SHARED_INT board (only mt7621, mt7628) so changing the index-logic will require testing on such boards too.

I think the change will not heavily impact SHARED_INT devices.

I hope so ;)

Quoted 2 lines

Regards,
Lorenzo

regards Frank