Skip to contentSkip to conversation

net: airoha: Fix TX scheduler queue mask loop upper bound

PATCH Superseded Wayen Yan 2 participants 5 messages Jun 17 – Jun 18

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wayen Yan

author
#0 lore raw

PATCH 1/1 net: airoha: Fix TX scheduler queue mask loop upper bound

In airoha_qdma_set_chan_tx_sched(), the loop clearing queue mask was using AIROHA_NUM_TX_RING (32) instead of AIROHA_NUM_QOS_QUEUES (8).

Each channel has 8 queues, and TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i) computes BIT(i + (channel * 8)). With i ranging 0..31, this causes:
- channel 0: clears bit 0..31 (all 4 channels) instead of 0..7
- channel 1: clears bit 8..31 (channels 1-3) instead of 8..15
- channel 2: clears bit 16..31 (channels 2-3) instead of 16..23
- channel 3: clears bit 24..31 (channel 3 only) - correct by accident

While BIT(32+) on arm64 produces 64-bit values truncated to 0 in u32 mask parameter, the loop still incorrectly clears queues within the same channel beyond queue 7.

Fix by using AIROHA_NUM_QOS_QUEUES (8) as the loop upper bound.

Fixes ef1ca9271313 ("net: airoha: Add sched HTB offload support")
---
 drivers/net/ethernet/airoha/airoha_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
index 31cdb11cd7..a1eda13400 100644
@@ -2217,7 +2217,7 @@ static int airoha_qdma_set_chan_tx_sched(struct net_device *dev,
 	struct airoha_gdm_port *port = netdev_priv(dev);
 	int i;
 
-	for (i = 0; i < AIROHA_NUM_TX_RING; i++)
+	for (i = 0; i < AIROHA_NUM_QOS_QUEUES; i++)
 		airoha_qdma_clear(port->qdma, REG_QUEUE_CLOSE_CFG(channel),
 				  TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i));
 
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 27 lines

In airoha_qdma_set_chan_tx_sched(), the loop clearing queue mask was using AIROHA_NUM_TX_RING (32) instead of AIROHA_NUM_QOS_QUEUES (8).

Each channel has 8 queues, and TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i) computes BIT(i + (channel * 8)). With i ranging 0..31, this causes:
- channel 0: clears bit 0..31 (all 4 channels) instead of 0..7
- channel 1: clears bit 8..31 (channels 1-3) instead of 8..15
- channel 2: clears bit 16..31 (channels 2-3) instead of 16..23
- channel 3: clears bit 24..31 (channel 3 only) - correct by accident

While BIT(32+) on arm64 produces 64-bit values truncated to 0 in u32 mask parameter, the loop still incorrectly clears queues within the same channel beyond queue 7.

Fix by using AIROHA_NUM_QOS_QUEUES (8) as the loop upper bound.

Fixes ef1ca9271313 ("net: airoha: Add sched HTB offload support")
---
 drivers/net/ethernet/airoha/airoha_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +0 -0
index 31cdb11cd7..a1eda13400 100644

drivers/net/ethernet/airoha/airoha_eth.c static int airoha_qdma_set_chan_tx_sched(struct net_device *dev, · line 2222

Quoted 7 lines
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
@@ -2217,7 +2217,7 @@ static int airoha_qdma_set_chan_tx_sched(struct net_device *dev,
 	struct airoha_gdm_port *port = netdev_priv(dev);
 	int i;
 
-	for (i = 0; i < AIROHA_NUM_TX_RING; i++)
+	for (i = 0; i < AIROHA_NUM_QOS_QUEUES; i++)
 		airoha_qdma_clear(port->qdma, REG_QUEUE_CLOSE_CFG(channel),
 				  TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i));

Even if the current codebase supports just AIROHA_NUM_QOS_CHANNEL (4), the hw exposes 32 hw QoS channels (AIROHA_NUM_TX_RING). Here we are just clearing the configuration, so I guess the current implementation is correct.

Regards,
Lorenzo

Quoted 5 lines
Signature · 2 lines
-- 
2.51.0
author
#2 lore raw
In reply to Wayen Yan
Quoted 3 lines · Lorenzo Bianconi

Even if the current codebase supports just AIROHA_NUM_QOS_CHANNEL (4), the hw exposes 32 hw QoS channels (AIROHA_NUM_TX_RING). Here we are just clearing the configuration, so I guess the current implementation is correct.

Hi Lorenzo,

You are right that there is no functional impact, and I agree this should not go to net. Let me explain the register layout I was worried about, and you can decide whether it is worth a net-next cleanup or should just be dropped.

The two macros are:

	REG_QUEUE_CLOSE_CFG(_n)             = 0x00a0 + ((_n) & 0xfc)
	TXQ_DISABLE_CHAN_QUEUE_MASK(_n, _m) = BIT((_m) + (((_n) & 0x3) << 3))

REG_QUEUE_CLOSE_CFG() masks the channel with 0xfc, and the bit macro folds the channel with & 0x3 (mod 4) shifted by 3. So one 32-bit register holds 4 channels x 8 queues, 8 queue bits per channel:

	channel 0 -> reg 0x00a0, bits  0..7
	channel 1 -> reg 0x00a0, bits  8..15
	channel 2 -> reg 0x00a0, bits 16..23
	channel 3 -> reg 0x00a0, bits 24..31
	channel 4 -> reg 0x00a4, bits  0..7
	...

In airoha_qdma_set_chan_tx_sched() the loop variable 'i' is passed as the *queue* argument _m, not as a channel:

	for (i = 0; i < AIROHA_NUM_TX_RING; i++)   // i = 0..31
		airoha_qdma_clear(qdma, REG_QUEUE_CLOSE_CFG(channel),
				  TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i));

Since each channel only has AIROHA_NUM_QOS_QUEUES (8) queues, the correct logic is to clear the 8 queue bits belonging to 'channel'. With i running up to 31 the BIT() shift instead walks past those 8 bits and into the bit ranges of the other channels folded into the same register. For channel 0 the accumulated mask becomes 0xffffffff, i.e. it touches channels 1..3 as well.

This is harmless today only because REG_QUEUE_CLOSE_CFG is written exclusively here, via airoha_qdma_clear() (RMW clear), and the register resets to 0 and is never set anywhere -- so clearing extra bits is a no-op. Functionally the current code is fine, as you say.

The point is just the loop-bound semantics: 'i' is a per-channel queue index, so the bound should be AIROHA_NUM_QOS_QUEUES (8), not AIROHA_NUM_TX_RING (32). The two happen to be related (32 == 4 channels * 8 queues) but mean different things.

Since there is no functional change, feel free to drop this if you would rather not carry a cosmetic patch. If you think the clarity is worth it I can resend against net-next without the Fixes tag.

Thanks,
Wayen

maintainer
#3 lore raw
Quoted 52 lines · Lorenzo Bianconi
Quoted 3 lines

Even if the current codebase supports just AIROHA_NUM_QOS_CHANNEL (4), the hw exposes 32 hw QoS channels (AIROHA_NUM_TX_RING). Here we are just clearing the configuration, so I guess the current implementation is correct.

Hi Lorenzo,

You are right that there is no functional impact, and I agree this should not go to net. Let me explain the register layout I was worried about, and you can decide whether it is worth a net-next cleanup or should just be dropped.

The two macros are:

	REG_QUEUE_CLOSE_CFG(_n)             = 0x00a0 + ((_n) & 0xfc)
	TXQ_DISABLE_CHAN_QUEUE_MASK(_n, _m) = BIT((_m) + (((_n) & 0x3) << 3))

REG_QUEUE_CLOSE_CFG() masks the channel with 0xfc, and the bit macro folds the channel with & 0x3 (mod 4) shifted by 3. So one 32-bit register holds 4 channels x 8 queues, 8 queue bits per channel:

	channel 0 -> reg 0x00a0, bits  0..7
	channel 1 -> reg 0x00a0, bits  8..15
	channel 2 -> reg 0x00a0, bits 16..23
	channel 3 -> reg 0x00a0, bits 24..31
	channel 4 -> reg 0x00a4, bits  0..7
	...

In airoha_qdma_set_chan_tx_sched() the loop variable 'i' is passed as the *queue* argument _m, not as a channel:

	for (i = 0; i < AIROHA_NUM_TX_RING; i++)   // i = 0..31
		airoha_qdma_clear(qdma, REG_QUEUE_CLOSE_CFG(channel),
				  TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i));

Since each channel only has AIROHA_NUM_QOS_QUEUES (8) queues, the correct logic is to clear the 8 queue bits belonging to 'channel'. With i running up to 31 the BIT() shift instead walks past those 8 bits and into the bit ranges of the other channels folded into the same register. For channel 0 the accumulated mask becomes 0xffffffff, i.e. it touches channels 1..3 as well.

This is harmless today only because REG_QUEUE_CLOSE_CFG is written exclusively here, via airoha_qdma_clear() (RMW clear), and the register resets to 0 and is never set anywhere -- so clearing extra bits is a no-op. Functionally the current code is fine, as you say.

The point is just the loop-bound semantics: 'i' is a per-channel queue index, so the bound should be AIROHA_NUM_QOS_QUEUES (8), not AIROHA_NUM_TX_RING (32). The two happen to be related (32 == 4 channels * 8 queues) but mean different things.

Quoted 7 lines

Since there is no functional change, feel free to drop this if you would rather not carry a cosmetic patch. If you think the clarity is worth it I can resend against net-next without the Fixes tag.

Thanks,
Wayen

Sorry you are right, I misread the code, your patch is correct. Since as you pointed out REG_QUEUE_CLOSE_CFG() is actually never set at the moment and the default register value is 0, I would repost this patch for net-next as soon as it is opened (this will avoid merge conflicts).

Regards,
Lorenzo

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Wayen Yan
Quoted 10 lines

In airoha_qdma_set_chan_tx_sched(), the loop clearing queue mask was using AIROHA_NUM_TX_RING (32) instead of AIROHA_NUM_QOS_QUEUES (8).

Each channel has 8 queues, and TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i) computes BIT(i + (channel * 8)). With i ranging 0..31, this causes:
- channel 0: clears bit 0..31 (all 4 channels) instead of 0..7
- channel 1: clears bit 8..31 (channels 1-3) instead of 8..15
- channel 2: clears bit 16..31 (channels 2-3) instead of 16..23
- channel 3: clears bit 24..31 (channel 3 only) - correct by accident

Quoted 5 lines

While BIT(32+) on arm64 produces 64-bit values truncated to 0 in u32 mask parameter, the loop still incorrectly clears queues within the same channel beyond queue 7.

Fix by using AIROHA_NUM_QOS_QUEUES (8) as the loop upper bound.

I guess it is ok now if you respin this patch on top of net branch. If so, please add my Acked-by.

Quoted 24 lines
Fixes ef1ca9271313 ("net: airoha: Add sched HTB offload support")
---
 drivers/net/ethernet/airoha/airoha_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
index 31cdb11cd7..a1eda13400 100644
@@ -2217,7 +2217,7 @@ static int airoha_qdma_set_chan_tx_sched(struct net_device *dev,
 	struct airoha_gdm_port *port = netdev_priv(dev);
 	int i;
 
-	for (i = 0; i < AIROHA_NUM_TX_RING; i++)
+	for (i = 0; i < AIROHA_NUM_QOS_QUEUES; i++)
 		airoha_qdma_clear(port->qdma, REG_QUEUE_CLOSE_CFG(channel),
 				  TXQ_DISABLE_CHAN_QUEUE_MASK(channel, i));
 
Signature · 1 line
2.51.0