Skip to contentSkip to conversation

net: macb: implement ethtool set channels count operation

PATCH Superseded Théo Lebrun 3 participants 12 messages Oct 16 – Nov 13

Subsystems (3)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Théo Lebrun

author maintainer
#0 lore raw

v5 cover net: macb: implement ethtool set channels count operation

Add support for changing the active number of queues. Tested on Mobileye EyeQ5. I had stalled this series, focusing on other topics. It is time to bring it up to date and gather reviews.

I am posting this while the context-swapping series is in the mailing lists as well; context-swapping should land first then we'll care about set_channels. Why we want set_channels:
- To reduce the memory usage of too many queues.
- It makes sense to have before XDP, which is per-queue. In particular testing is simpler.

Have a nice day,
Thanks,
Théo

---
Changes in v5:
- New patch: add missing MACB_CAPS_QUEUE_DISABLE to 3 compatibles based
on publicly available datasheets. That means they can benefit from
the set_channels implementation.
- set_channels patch:
- Refuse set_channels if it disables a queue with active TAPRIO.
- Use TBQP.QUEUE_DISABLE bit to also disable transmit; previously we
only disabled the receive engine.
- Migrate code to newly introduced macb_queue_isr_clear() helper.
- Adapt to newly introduced macb_quiesce_start(), where we want to synchronize_irq() on all queues, even the disabled ones.
- IRQ handler now self-disarms on disabled queues.
- Drop old_count unused stack variable.
- Only allow TAPRIO rules on active queues.
- Fix comments style and text in macb_set_channels(); in particular
mention we'll use context-swapping once it is available.
- Distribute SRAM segments patch:
- Introduce GEM_TXQSEGALLOC_MASK(q) and use field_prep|get() macros.
- Introduce capability for this feature, as many publicly available
GEM datasheets don't document the registers.
- Remove upper register support. Lower register is enough to handle 8
queues, which is the max we support.
- Add edge case kunit for num_segments=128.
- Introduce static_assert(MACB_MAX_QUEUES == 8) in gem_sram_distribute_segments() to signal that code will need
updating if/when the constant changes.
- Update To/Cc list: drop Nicolas and Claudiu, add Conor and Nicolai.
- Rebase onto latest net-next/main (6b3e73774815).
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- macb_set_channels(): drop count == old_count check, it is redundant
with both netlink and ioctl codepaths. See early returns in ethnl_set_channels() and ethtool_set_channels(). Discussion @ V2.
- Rebase to latest net-next (8737d7194d6d); nothing to report.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Makefile: fix compilation of kunit tests. This bug was hidden before
because everything was builtin so it ended up linked together anyway.
Now macb.o is the amalgation of macb_{main,ptp,utils}.o and
macb_test.o is the amalgation of macb_{kunit,utils}.o.
- Kconfig CONFIG_MACB_KUNIT_TEST entry:
- Turn into tristate; no good reason to restrict to bool.
- Drop "depends on MACB". We do not need to compile the full MACB
driver to test gem_sram_distribute_segments().
- Add usual MODULE_*() macros to macb_kunit.c.
- Drop unused init value of ret in macb_set_channels().
- Rebase to latest net-next; nothing to report.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Move gem_sram_distribute_segments() from macb_main.c to macb_utils.c
and kunit tests from macb_main.c to macb_kunit.c.
- macb_set_channels():
- Add comment about MACB_CAPS_QUEUE_DISABLE.
- Refuse operation if netif_running(), with code comment.
- Drop useless sanity checks on ch->{combined,rx,tx}_count.
- Add help text to CONFIG_MACB_KUNIT_TEST.
- Fix checkpatch --max-line-length=80 warnings.
- Rebase onto latest net-next; nothing to report.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Théo Lebrun (3):
net: macb: add QUEUE_DISABLE capability to 3 compatibles
net: macb: implement ethtool_ops.get|set_channels()
net: macb: distribute evenly Tx SRAM segments

 drivers/net/ethernet/cadence/Kconfig      |  12 +++
 drivers/net/ethernet/cadence/Makefile     |   5 +-
 drivers/net/ethernet/cadence/macb.h       |  20 +++++
 drivers/net/ethernet/cadence/macb_kunit.c |  78 +++++++++++++++++
 drivers/net/ethernet/cadence/macb_main.c  | 135 +++++++++++++++++++++++++-----
 drivers/net/ethernet/cadence/macb_utils.c |  60 +++++++++++++
 6 files changed, 287 insertions(+), 23 deletions(-)

---
base-commit: 6b3e73774815910a39d8ca75b9ad7df963f61d50
change-id: 20260305-macb-set-channels-5bf6e07f3270

Best regards,

Signature · 1 line
Théo Lebrun <[email protected]>
author maintainer
#1 lore raw

PATCH v5 1/3 net: macb: add QUEUE_DISABLE capability to 3 compatibles

From datasheets, we know those 3 IP versions support Tx and Rx queue disabling, ie bit 0 in RBQP and TBQP registers.

All revisions I've seen either support it on both Tx & Rx or don't support it at all.

Sources:

   Compatible            | Match data         | Datasheet
   ----------------------|--------------------|-------------------------
   atmel,sama5d29-gem    | sama5d29_config    | DS60001764 [0]
   microchip,mpfs-macb   | mpfs_config        | header files [1]
   microchip,sama7g5-gem | sama7g5_gem_config | DS60001765 [2]

To contrast, check out the SAM9X60 DS60001579C datasheet [3] that does not document bit 0 as anything special on page 1041 and page 1042.

[0]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA5D29-Data-Sheet-ds60001764.pdf

[1]:
https://github.com/polarfire-soc/polarfire-soc-bare-metal-library/blob/614a67ab/src/platform/drivers/mss/mss_ethernet_mac/mss_ethernet_mac_regs.h#L200-L207

[2]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

[3]:
https://ww1.microchip.com/downloads/en/DeviceDoc/SAM9X60-Data-Sheet-DS60001579C.pdf

---
 drivers/net/ethernet/cadence/macb_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +4 -3
index 020a47353d01..625171fd3f9b 100644
@@ -5743,7 +5743,7 @@ static const struct macb_config sama5d2_config = {
 
 static const struct macb_config sama5d29_config = {
 	.caps = MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII | MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_MII,
+		MACB_CAPS_USRIO_HAS_MII | MACB_CAPS_QUEUE_DISABLE,
 	.dma_burst_length = 16,
 	.usrio = &at91_default_usrio,
 };
@@ -5799,7 +5799,8 @@ static const struct macb_config mpfs_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE,
+		MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE |
+		MACB_CAPS_QUEUE_DISABLE,
 	.dma_burst_length = 16,
 	.init = init_reset_optional,
 	.usrio = &mpfs_usrio,
@@ -5812,7 +5813,7 @@ static const struct macb_config sama7g5_gem_config = {
 		MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII |
 		MACB_CAPS_USRIO_HAS_REFCLK_SOURCE |
 		MACB_CAPS_MIIONRGMII | MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_MII,
+		MACB_CAPS_USRIO_HAS_MII | MACB_CAPS_QUEUE_DISABLE,
 	.dma_burst_length = 16,
 	.usrio = &sama7g5_gem_usrio,
 };
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH net-next v5 1/3] net: macb: add QUEUE_DISABLE capability to 3 compatibles

Hi Théo

Quoted 2 lines · Théo Lebrun

From datasheets, we know those 3 IP versions support Tx and Rx queue disabling, ie bit 0 in RBQP and TBQP registers.

nit: Just learned that git am will turn this into >From. Maybe reword the first sentence.

Quoted 38 lines

All revisions I've seen either support it on both Tx & Rx or don't support it at all.

Sources:

Compatible | Match data | Datasheet

----------------------|--------------------|-------------------------

   atmel,sama5d29-gem    | sama5d29_config    | DS60001764 [0]
   microchip,mpfs-macb   | mpfs_config        | header files [1]
   microchip,sama7g5-gem | sama7g5_gem_config | DS60001765 [2]

To contrast, check out the SAM9X60 DS60001579C datasheet [3] that does not document bit 0 as anything special on page 1041 and page 1042.

[0]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA5D29-Data-Sheet-ds60001764.pdf

[1]:
https://github.com/polarfire-soc/polarfire-soc-bare-metal-library/blob/614a67ab/src/platform/drivers/mss/mss_ethernet_mac/mss_ethernet_mac_regs.h#L200-L207

[2]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

[3]:
https://ww1.microchip.com/downloads/en/DeviceDoc/SAM9X60-Data-Sheet-DS60001579C.pdf

---
 drivers/net/ethernet/cadence/macb_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 020a47353d01..625171fd3f9b 100644

drivers/net/ethernet/cadence/macb_main.c static const struct macb_config sama5d2_config = · line 5747

Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
@@ -5743,7 +5743,7 @@ static const struct macb_config sama5d2_config = 
 {
 
 static const struct macb_config sama5d29_config = {
 	.caps = MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII | MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_MII,
+		MACB_CAPS_USRIO_HAS_MII | MACB_CAPS_QUEUE_DISABLE,

AFAIU this also switches WoL suspend on these SoCs from the tieoff ring to QUEUE_DISABLE. Was WoL tested on any of them? Worth a line in the commit message too.

Quoted 22 lines
drivers/net/ethernet/cadence/macb_main.c +0 -0
 	.dma_burst_length = 16,
 	.usrio = &at91_default_usrio,

};

drivers/net/ethernet/cadence/macb_main.c +3 -2
@@ -5799,7 +5799,8 @@ static const struct macb_config mpfs_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE,
+		MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE |
+		MACB_CAPS_QUEUE_DISABLE,
 	.dma_burst_length = 16,
 	.init = init_reset_optional,
 	.usrio = &mpfs_usrio,
@@ -5812,7 +5813,7 @@ static const struct macb_config 
 sama7g5_gem_config = {
 		MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII |
 		MACB_CAPS_USRIO_HAS_REFCLK_SOURCE |
 		MACB_CAPS_MIIONRGMII | MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_MII,
+		MACB_CAPS_USRIO_HAS_MII | MACB_CAPS_QUEUE_DISABLE,
 	.dma_burst_length = 16,
 	.usrio = &sama7g5_gem_usrio,
Quoted 1 line

};

Thanks,
Nicolai

author maintainer
#3 lore raw

Re: [PATCH net-next v5 1/3] net: macb: add QUEUE_DISABLE capability to 3 compatibles

Hello Nicolai,

Quoted 6 lines · Nicolai Buchwitz
Quoted 2 lines · Théo Lebrun

From datasheets, we know those 3 IP versions support Tx and Rx queue disabling, ie bit 0 in RBQP and TBQP registers.

nit: Just learned that git am will turn this into >From. Maybe reword the first sentence.

Fixed! Plain text is nice but sometimes causes trouble. By the way, this patch is in a separate series now.

https://lore.kernel.org/netdev/[email protected]/

Quoted 40 lines
Quoted 40 lines

All revisions I've seen either support it on both Tx & Rx or don't support it at all.

Sources:

Compatible | Match data | Datasheet

----------------------|--------------------|-------------------------

   atmel,sama5d29-gem    | sama5d29_config    | DS60001764 [0]
   microchip,mpfs-macb   | mpfs_config        | header files [1]
   microchip,sama7g5-gem | sama7g5_gem_config | DS60001765 [2]

To contrast, check out the SAM9X60 DS60001579C datasheet [3] that does not document bit 0 as anything special on page 1041 and page 1042.

[0]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA5D29-Data-Sheet-ds60001764.pdf

[1]:
https://github.com/polarfire-soc/polarfire-soc-bare-metal-library/blob/614a67ab/src/platform/drivers/mss/mss_ethernet_mac/mss_ethernet_mac_regs.h#L200-L207

[2]:
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

[3]:
https://ww1.microchip.com/downloads/en/DeviceDoc/SAM9X60-Data-Sheet-DS60001579C.pdf

---
 drivers/net/ethernet/cadence/macb_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 020a47353d01..625171fd3f9b 100644
@@ -5743,7 +5743,7 @@ static const struct macb_config sama5d2_config = 
 {
 
Quoted 9 lines

drivers/net/ethernet/cadence/macb_main.c static const struct macb_config sama5d2_config = { · line 5746

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
 static const struct macb_config sama5d29_config = {
 	.caps = MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII | MACB_CAPS_GEM_HAS_PTP |
-		MACB_CAPS_USRIO_HAS_MII,
+		MACB_CAPS_USRIO_HAS_MII | MACB_CAPS_QUEUE_DISABLE,

AFAIU this also switches WoL suspend on these SoCs from the tieoff ring to
QUEUE_DISABLE. Was WoL tested on any of them? Worth a line in the commit message too.

Not tested, I don't have them. I've added a paragraph to the commit message to explicit this behavior change.

Thanks for the review,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

author maintainer
#4 lore raw

PATCH v5 2/3 net: macb: implement ethtool_ops.get|set_channels()

In reply to Théo Lebrun

bp->num_queues is the total number of queues and is constant from probe. Introduce bp->max_num_queues which takes the current role of bp->num_queues and allow 0 < bp->num_queues <= bp->max_num_queues. MACB/GEM does not know about Rx/Tx specific queues; it only has combined queues.

set_channels is reserved to devices with MACB_CAPS_QUEUE_DISABLE. The tieoff workaround would not work as packets would still be routed into queues with a tieoff descriptor.

Implement .set_channels() operation by refusing if netif_running(). We need context-swapping support upstream for proper on-the-fly channel count change.

Note we refuse the operation if any TAPRIO rules are in place on queues that would get disabled. If we allow the operation to take place, then a transmission window would be reserved but unusable.

Nit: fix an alignment issue inside gem_ethtool_ops which does not deserve its own patch.

---
 drivers/net/ethernet/cadence/macb.h      |   3 +
 drivers/net/ethernet/cadence/macb_main.c | 109 ++++++++++++++++++++++++++-----
 2 files changed, 95 insertions(+), 17 deletions(-)
drivers/net/ethernet/cadence/macb.h +3 -0
index 82499ec6a9f0..51835de0f2a1 100644
@@ -1314,6 +1314,9 @@ struct macb {
 	unsigned int		tx_ring_size;
 
 	unsigned int		num_queues;
+	unsigned int		max_num_queues;
+	/* Queue mask gated by the current TAPRIO schedule (RTNL-protected). */
+	u32			taprio_gated_queues;
 	struct macb_queue	queues[MACB_MAX_QUEUES];
 
 	spinlock_t		lock;
drivers/net/ethernet/cadence/macb_main.c +92 -17

206 lines not on this page · raw message

Signature · 1 line
2.56.0
#5 lore raw

Re: [PATCH net-next v5 2/3] net: macb: implement ethtool_ops.get|set_channels()

Hi Théo

Quoted 43 lines · Théo Lebrun

bp->num_queues is the total number of queues and is constant from probe. Introduce bp->max_num_queues which takes the current role of bp->num_queues and allow 0 < bp->num_queues <= bp->max_num_queues. MACB/GEM does not know about Rx/Tx specific queues; it only has combined queues.

set_channels is reserved to devices with MACB_CAPS_QUEUE_DISABLE. The tieoff workaround would not work as packets would still be routed into queues with a tieoff descriptor.

Implement .set_channels() operation by refusing if netif_running(). We need context-swapping support upstream for proper on-the-fly channel count change.

Note we refuse the operation if any TAPRIO rules are in place on queues that would get disabled. If we allow the operation to take place, then a transmission window would be reserved but unusable.

Nit: fix an alignment issue inside gem_ethtool_ops which does not deserve its own patch.

---

[...]

drivers/net/ethernet/cadence/macb_main.c +9 -0
 
[...]
 
+static int macb_set_channels(struct net_device *netdev,
+			     struct ethtool_channels *ch)
+{
+	struct macb *bp = netdev_priv(netdev);
+	unsigned int count = ch->combined_count;
+	int ret;
+
+	/* MACB_CAPS_QUEUE_DISABLE means that the field QUEUE_DISABLE/BIT0 in
+	 * the per-queue RBQP/TBQP registers disable Tx/Rx queues. If we 

don't

drivers/net/ethernet/cadence/macb_main.c +1 -0
+	 * have that capability we can have multiple queues but we must 

always

drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4294

Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +6 -0
+	 * run with all enabled.
+	 */
+	if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE))
+		return -EOPNOTSUPP;
+
+	/* TODO: reuse context swapping once it is merged. */

Once context swapping is merged, this needs to be addressed in v6 ;-)

drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4305

Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c +8 -0
+	if (netif_running(bp->netdev))
+		return -EBUSY;
+
+	/* If we allow disable a queue which has TAPRIO active, we'll keep a
+	 * transmission window which will be unusable.
+	 */
+	if (bp->taprio_gated_queues >> count) {
+		netdev_err(bp->netdev, "TAPRIO schedule gates queues >= %u; destroy 

the qdisc before reducing channels\n",

drivers/net/ethernet/cadence/macb_main.c +3 -0
+			   count);
+		return -EBUSY;
+	}

I think this can get stuck:

- delete the taprio qdisc after the link has been down for a while
- device is is runtime suspend
- taprio setup bails out before _destroy() is called
- ethtool -L keeps failing with -EBUSY, even though there is no qdisc anymore

Something like:

ip link set eth0 up
tc qdisc replace dev eth0 root taprio ... flags 0x2 ip link set eth0 down
sleep 1
tc qdisc del dev eth0 root
ethtool -L eth0 combined 1

Quoted 1 line

[...]

Thanks,
Nicolai

author maintainer
#6 lore raw

Re: [PATCH net-next v5 2/3] net: macb: implement ethtool_ops.get|set_channels()

Quoted 45 lines · Nicolai Buchwitz
Quoted 44 lines · Théo Lebrun

bp->num_queues is the total number of queues and is constant from probe.
Introduce bp->max_num_queues which takes the current role of bp->num_queues and allow 0 < bp->num_queues <= bp->max_num_queues. MACB/GEM does not know about Rx/Tx specific queues; it only has combined queues.

set_channels is reserved to devices with MACB_CAPS_QUEUE_DISABLE. The tieoff workaround would not work as packets would still be routed into queues with a tieoff descriptor.

Implement .set_channels() operation by refusing if netif_running(). We need context-swapping support upstream for proper on-the-fly channel count change.

Note we refuse the operation if any TAPRIO rules are in place on queues that would get disabled. If we allow the operation to take place, then a transmission window would be reserved but unusable.

Nit: fix an alignment issue inside gem_ethtool_ops which does not deserve its own patch.

---

[...]

drivers/net/ethernet/cadence/macb_main.c +9 -0
 
[...]
 
+static int macb_set_channels(struct net_device *netdev,
+			     struct ethtool_channels *ch)
+{
+	struct macb *bp = netdev_priv(netdev);
+	unsigned int count = ch->combined_count;
+	int ret;
+
+	/* MACB_CAPS_QUEUE_DISABLE means that the field QUEUE_DISABLE/BIT0 in
+	 * the per-queue RBQP/TBQP registers disable Tx/Rx queues. If we 

don't

drivers/net/ethernet/cadence/macb_main.c +1 -0
+	 * have that capability we can have multiple queues but we must 

always

Quoted 8 lines

drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4294

Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +6 -0
+	 * run with all enabled.
+	 */
+	if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE))
+		return -EOPNOTSUPP;
+
+	/* TODO: reuse context swapping once it is merged. */

Once context swapping is merged, this needs to be addressed in v6 ;-)

Done! The patch changed a lot, for the better. num_queues is now part of the context, as any context "parameter" should be. It had no place in the global interface struct.

This highlights a few callbacks that are reading num_queues while interface might be down. I've not attempted to fix those yet. :-)

https://lore.kernel.org/netdev/[email protected]/

Quoted 22 lines

drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4305

Quoted 13 lines
drivers/net/ethernet/cadence/macb_main.c +8 -0
+	if (netif_running(bp->netdev))
+		return -EBUSY;
+
+	/* If we allow disable a queue which has TAPRIO active, we'll keep a
+	 * transmission window which will be unusable.
+	 */
+	if (bp->taprio_gated_queues >> count) {
+		netdev_err(bp->netdev, "TAPRIO schedule gates queues >= %u; destroy 

the qdisc before reducing channels\n",

drivers/net/ethernet/cadence/macb_main.c +3 -0
+			   count);
+		return -EBUSY;
+	}

I think this can get stuck:

- delete the taprio qdisc after the link has been down for a while
- device is is runtime suspend
- taprio setup bails out before _destroy() is called
- ethtool -L keeps failing with -EBUSY, even though there is no qdisc anymore

Quoted 8 lines

Something like:

ip link set eth0 up
tc qdisc replace dev eth0 root taprio ... flags 0x2 ip link set eth0 down
sleep 1
tc qdisc del dev eth0 root
ethtool -L eth0 combined 1

Good catch. I was able to reproduce this. Fixed by running

   // macb_taprio_destroy()
   netdev_reset_tc(netdev);
   bp->taprio_gated_queues = 0;

Even if the interface is down.
We skip over the hardware reconfig however.

Thanks for the review,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

author maintainer
#7 lore raw

PATCH v5 3/3 net: macb: distribute evenly Tx SRAM segments

In reply to Théo Lebrun

GEM has registers to configure the Tx SRAM segments distribution across queues. The reset value is apprioriate (even spread) but we need to care if/when number of active queues is modified (or if we inherited unevenly initialised hardware from bootloader).

To distribute segments, we take as input the number of queues (bp->num_queues) and the number of segments (found inside DCFG6). Its output is a number of segments for each queue, formatted as powers-of-two (eg 2 for queue 0 means it has 2^2=4 segments).

As the distribution logic is quite complex (at least its initial versions had bugs), it is kunit-tested in macb_kunit.c and the implementation lives in macb_utils.c. To test:

⟩ env --unset=CROSS_COMPILE make ARCH=um mrproper
⟩ env --unset=CROSS_COMPILE ./tools/testing/kunit/kunit.py run \
--kconfig_add CONFIG_NET=y \
--kconfig_add CONFIG_COMMON_CLK=y macb

---
 drivers/net/ethernet/cadence/Kconfig      | 12 +++++
 drivers/net/ethernet/cadence/Makefile     |  5 +-
 drivers/net/ethernet/cadence/macb.h       | 17 +++++++
 drivers/net/ethernet/cadence/macb_kunit.c | 78 +++++++++++++++++++++++++++++++
 drivers/net/ethernet/cadence/macb_main.c  | 19 +++++++-
 drivers/net/ethernet/cadence/macb_utils.c | 60 ++++++++++++++++++++++++
 6 files changed, 188 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/Kconfig +12 -0
index 5b2a461dfd28..a901f74fd4ab 100644
@@ -51,4 +51,16 @@ config MACB_PCI
 	  To compile this driver as a module, choose M here: the module
 	  will be called macb_pci.
 
+config MACB_KUNIT_TEST
+	tristate "KUnit test for MACB" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Build KUnit tests for the MACB driver.
+
+	  For more information on KUnit and unit tests in general,
+	  please refer to the KUnit documentation.
+
+	  If unsure, say N.
+
 endif # NET_VENDOR_CADENCE
drivers/net/ethernet/cadence/Makefile +4 -1
index 1f33cdca9a3c..a0740da68649 100644
@@ -2,7 +2,7 @@
 #
 # Makefile for the Atmel network device drivers.
 #
-macb-y	:= macb_main.o
+macb-y	:= macb_main.o macb_utils.o
 
 ifeq ($(CONFIG_MACB_USE_HWSTAMP),y)
 macb-y	+= macb_ptp.o
@@ -10,3 +10,6 @@ endif
 
 obj-$(CONFIG_MACB) += macb.o
 obj-$(CONFIG_MACB_PCI) += macb_pci.o
+
+obj-$(CONFIG_MACB_KUNIT_TEST) += macb_test.o
+macb_test-y := macb_kunit.o macb_utils.o
drivers/net/ethernet/cadence/macb.h +17 -0
index 51835de0f2a1..60d61efbf3e4 100644
@@ -194,6 +194,10 @@
 /* Screener Type 2 match registers */
 #define GEM_SCRT2		0x540
 
+/* Tx queue segment allocation */
+#define GEM_TXQSEGALLOC_LOWER	0x05A0
+#define GEM_TXQSEGALLOC_UPPER	0x05A4
+
 /* EtherType registers */
 #define GEM_ETHT		0x06E0
 
@@ -545,6 +549,8 @@
 #define GEM_PBUF_CUTTHRU_SIZE			1
 #define GEM_DAW64_OFFSET			23
 #define GEM_DAW64_SIZE				1
+#define GEM_SEGMENTS_BIT_SIZE_OFFSET		16
+#define GEM_SEGMENTS_BIT_SIZE_SIZE		3
 
 /* Bitfields in DCFG8. */
 #define GEM_T1SCR_OFFSET			24
@@ -657,6 +663,13 @@
 #define GEM_CMPCEN_OFFSET			30 /* Compare C Enable */
 #define GEM_CMPCEN_SIZE				1
 
+/* Bitfields in TXQSEGALLOC (Q0 at 2:0, Q1 at 6:4, etc.) */
+#define GEM_TXQSEGALLOC_MASK(q_) \
+	({ \
+		typeof(q_) q__ = (q_); \
+		GENMASK(4 * (q__) + 2, 4 * (q__)); \
+	})
+
 /* Bitfields in ETHT */
 #define GEM_ETHTCMP_OFFSET			0 /* EtherType compare value */
 #define GEM_ETHTCMP_SIZE			16
@@ -785,6 +798,7 @@
 #define MACB_CAPS_USRIO_HAS_MII			BIT(26)
 #define MACB_CAPS_USRIO_HAS_REFCLK_SOURCE	BIT(27)
 #define MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE	BIT(28)
+#define MACB_CAPS_TXQSEGALLOC			BIT(29)
 
 /* LSO settings */
 #define MACB_LSO_UFO_ENABLE			0x01
@@ -1511,4 +1525,7 @@ struct macb_queue_enst_config {
 	u32 off_time_bytes;
 };
 
+u32 gem_sram_distribute_segments(unsigned int num_queues,
+				 unsigned int num_segments);
+
 #endif /* _MACB_H */
drivers/net/ethernet/cadence/macb_kunit.c new file +78 -0

78 lines not on this page · raw message

drivers/net/ethernet/cadence/macb_main.c +17 -2
index 2d069454795b..b70b81f51161 100644
@@ -3163,6 +3163,20 @@ static void macb_init_hw(struct macb *bp)
 	if (bp->caps & MACB_CAPS_JUMBO)
 		bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK;
 
+	/* Distribute Tx SRAM segments evenly based on active number of queues.
+	 * TXQSEGALLOC is only documented for some GEM integrations.
+	 */
+	if (bp->caps & MACB_CAPS_TXQSEGALLOC) {
+		unsigned int num_segments;
+		u32 val;
+
+		num_segments = 1U << GEM_BFEXT(SEGMENTS_BIT_SIZE,
+					       gem_readl(bp, DCFG6));
+		val = gem_sram_distribute_segments(bp->num_queues,
+						   num_segments);
+		gem_writel(bp, TXQSEGALLOC_LOWER, val);
+	}
+
 	macb_configure_dma(bp);
 
 	/* Enable RX partial store and forward and set watermark */
@@ -5854,6 +5868,7 @@ static const struct macb_config zynqmp_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_BD_RD_PREFETCH |
+		MACB_CAPS_TXQSEGALLOC |
 		MACB_CAPS_USRIO_HAS_MII,
 	.dma_burst_length = 16,
 	.init = init_reset_optional,
@@ -5906,7 +5921,7 @@ static const struct macb_config versal_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_BD_RD_PREFETCH |
 		MACB_CAPS_NEED_TSUCLK | MACB_CAPS_QUEUE_DISABLE |
-		MACB_CAPS_QBV |
+		MACB_CAPS_QBV | MACB_CAPS_TXQSEGALLOC |
 		MACB_CAPS_USRIO_HAS_MII,
 	.dma_burst_length = 16,
 	.init = init_reset_optional,
@@ -5917,7 +5932,7 @@ static const struct macb_config versal_config = {
 static const struct macb_config eyeq5_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_QUEUE_DISABLE |
-		MACB_CAPS_NO_LSO | MACB_CAPS_EEE,
+		MACB_CAPS_NO_LSO | MACB_CAPS_EEE | MACB_CAPS_TXQSEGALLOC,
 	.dma_burst_length = 16,
 	.init = eyeq5_init,
 	.jumbo_max_len = 10240,
drivers/net/ethernet/cadence/macb_utils.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.56.0
#8 lore raw

Re: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

Hi Théo

Quoted 66 lines · Théo Lebrun

GEM has registers to configure the Tx SRAM segments distribution across queues. The reset value is apprioriate (even spread) but we need to care if/when number of active queues is modified (or if we inherited unevenly initialised hardware from bootloader).

To distribute segments, we take as input the number of queues (bp->num_queues) and the number of segments (found inside DCFG6). Its output is a number of segments for each queue, formatted as powers-of-two (eg 2 for queue 0 means it has 2^2=4 segments).

As the distribution logic is quite complex (at least its initial versions had bugs), it is kunit-tested in macb_kunit.c and the implementation lives in macb_utils.c. To test:

⟩ env --unset=CROSS_COMPILE make ARCH=um mrproper
⟩ env --unset=CROSS_COMPILE ./tools/testing/kunit/kunit.py run \
--kconfig_add CONFIG_NET=y \
--kconfig_add CONFIG_COMMON_CLK=y macb

---
 drivers/net/ethernet/cadence/Kconfig      | 12 +++++
 drivers/net/ethernet/cadence/Makefile     |  5 +-
 drivers/net/ethernet/cadence/macb.h       | 17 +++++++
 drivers/net/ethernet/cadence/macb_kunit.c | 78 
+++++++++++++++++++++++++++++++
 drivers/net/ethernet/cadence/macb_main.c  | 19 +++++++-
 drivers/net/ethernet/cadence/macb_utils.c | 60 
++++++++++++++++++++++++
 6 files changed, 188 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/Kconfig +12 -0
index 5b2a461dfd28..a901f74fd4ab 100644
@@ -51,4 +51,16 @@ config MACB_PCI
 	  To compile this driver as a module, choose M here: the module
 	  will be called macb_pci.
 
+config MACB_KUNIT_TEST
+	tristate "KUnit test for MACB" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Build KUnit tests for the MACB driver.
+
+	  For more information on KUnit and unit tests in general,
+	  please refer to the KUnit documentation.
+
+	  If unsure, say N.
+
 endif # NET_VENDOR_CADENCE
drivers/net/ethernet/cadence/Makefile +1 -1
index 1f33cdca9a3c..a0740da68649 100644
@@ -2,7 +2,7 @@
 #
 # Makefile for the Atmel network device drivers.
 #
-macb-y	:= macb_main.o
+macb-y	:= macb_main.o macb_utils.o
 
 ifeq ($(CONFIG_MACB_USE_HWSTAMP),y)
 macb-y	+= macb_ptp.o

drivers/net/ethernet/cadence/Makefile endif · line 15

Quoted 6 lines
drivers/net/ethernet/cadence/Makefile +3 -0
@@ -10,3 +10,6 @@ endif
 
 obj-$(CONFIG_MACB) += macb.o
 obj-$(CONFIG_MACB_PCI) += macb_pci.o
+
+obj-$(CONFIG_MACB_KUNIT_TEST) += macb_test.o
+macb_test-y := macb_kunit.o macb_utils.o

With MACB=m and MACB_KUNIT_TEST=m (so allmodconfig) kbuild complains:

drivers/net/ethernet/cadence/Makefile: macb_utils.o is added to
multiple modules: macb macb_test

Maybe build the test into macb.ko instead, or use EXPORT_SYMBOL_IF_KUNIT()?

drivers/net/ethernet/cadence/macb.h line 199

Quoted 11 lines
drivers/net/ethernet/cadence/macb.h +3 -0
index 51835de0f2a1..60d61efbf3e4 100644
@@ -194,6 +194,10 @@
 /* Screener Type 2 match registers */
 #define GEM_SCRT2		0x540
 
+/* Tx queue segment allocation */
+#define GEM_TXQSEGALLOC_LOWER	0x05A0
+#define GEM_TXQSEGALLOC_UPPER	0x05A4

nit: unused now?

Quoted 12 lines

[...]

drivers/net/ethernet/cadence/macb_kunit.c +4 -0
 
[...]
 
+static void macb_sram_segments_test(struct kunit *test)
+{
+	const struct macb_sram_segments_case *p = test->param_value;
+	u32 val = gem_sram_distribute_segments(p->num_queues, 

p->num_segments);

drivers/net/ethernet/cadence/macb_kunit.c +1 -0
+	unsigned int i, sum_segments = 0, max_assigned_segments;

drivers/net/ethernet/cadence/macb_kunit.c line 24

Quoted 10 lines
drivers/net/ethernet/cadence/macb_kunit.c +10 -0
+	unsigned int num_queues = min(p->num_queues, p->num_segments);
+
+	for (i = 0; i < num_queues; i++) {
+		unsigned int q_segments = field_get(GEM_TXQSEGALLOC_MASK(i),
+						    val);
+
+		q_segments = 1U << q_segments;
+		sum_segments += q_segments;
+		KUNIT_ASSERT_GT_MSG(test, q_segments, 0, "queue %d, val %#x",
+				    i, val);

This can't fail, 1U << x is always at least 1.

Quoted 5 lines
drivers/net/ethernet/cadence/macb_kunit.c +5 -0
+	}
+
+	for (i = num_queues; i < MACB_MAX_QUEUES; i++) {
+		unsigned int pow = field_get(GEM_TXQSEGALLOC_MASK(i), val);
+

drivers/net/ethernet/cadence/macb_kunit.c line 39

Quoted 10 lines
drivers/net/ethernet/cadence/macb_kunit.c +10 -0
+		KUNIT_ASSERT_EQ_MSG(test, pow, 0, "queue %d, val %#x", i, val);
+	}
+
+	max_assigned_segments = min(p->num_segments,
+				    MACB_MAX_QUEUES * num_queues);
+	KUNIT_ASSERT_EQ_MSG(test, sum_segments, max_assigned_segments,
+			    "val %#x", val);
+}
+
+struct macb_sram_segments_case macb_sram_segments_cases[] = {

static const ... ?

Quoted 29 lines

[...]

drivers/net/ethernet/cadence/macb_main.c +1 -0
index 2d069454795b..b70b81f51161 100644
@@ -3163,6 +3163,20 @@ static void macb_init_hw(struct macb *bp)
 	if (bp->caps & MACB_CAPS_JUMBO)
 		bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK;
 
+	/* Distribute Tx SRAM segments evenly based on active number of 

queues.

drivers/net/ethernet/cadence/macb_main.c +13 -0
+	 * TXQSEGALLOC is only documented for some GEM integrations.
+	 */
+	if (bp->caps & MACB_CAPS_TXQSEGALLOC) {
+		unsigned int num_segments;
+		u32 val;
+
+		num_segments = 1U << GEM_BFEXT(SEGMENTS_BIT_SIZE,
+					       gem_readl(bp, DCFG6));
+		val = gem_sram_distribute_segments(bp->num_queues,
+						   num_segments);
+		gem_writel(bp, TXQSEGALLOC_LOWER, val);
+	}
+
 	macb_configure_dma(bp);
 
 	/* Enable RX partial store and forward and set watermark */

drivers/net/ethernet/cadence/macb_main.c static const struct macb_config zynqmp_config = { · line 5872

Quoted 5 lines
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5854,6 +5868,7 @@ static const struct macb_config zynqmp_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_BD_RD_PREFETCH |
+		MACB_CAPS_TXQSEGALLOC |
 		MACB_CAPS_USRIO_HAS_MII,

AFAIU zynqmp can't change the queue count,so this only rewrites the reset value there?

Also, where does the limit of 8 segments per queue come from? With a single queue and 16 segments half of the Tx SRAM stays unused.

Quoted 1 line

[...]

Thanks,
Nicolai

author maintainer
#9 lore raw

Re: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

Hello Nicolai,

Quoted 80 lines · Nicolai Buchwitz

Hi Théo

Quoted 68 lines · Théo Lebrun

GEM has registers to configure the Tx SRAM segments distribution across queues. The reset value is apprioriate (even spread) but we need to care if/when number of active queues is modified (or if we inherited unevenly initialised hardware from bootloader).

To distribute segments, we take as input the number of queues (bp->num_queues) and the number of segments (found inside DCFG6). Its output is a number of segments for each queue, formatted as powers-of-two (eg 2 for queue 0 means it has 2^2=4 segments).

As the distribution logic is quite complex (at least its initial versions had bugs), it is kunit-tested in macb_kunit.c and the implementation lives in macb_utils.c. To test:

⟩ env --unset=CROSS_COMPILE make ARCH=um mrproper
⟩ env --unset=CROSS_COMPILE ./tools/testing/kunit/kunit.py run \
--kconfig_add CONFIG_NET=y \
--kconfig_add CONFIG_COMMON_CLK=y macb

---
 drivers/net/ethernet/cadence/Kconfig      | 12 +++++
 drivers/net/ethernet/cadence/Makefile     |  5 +-
 drivers/net/ethernet/cadence/macb.h       | 17 +++++++
 drivers/net/ethernet/cadence/macb_kunit.c | 78 
+++++++++++++++++++++++++++++++
 drivers/net/ethernet/cadence/macb_main.c  | 19 +++++++-
 drivers/net/ethernet/cadence/macb_utils.c | 60 
++++++++++++++++++++++++
 6 files changed, 188 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/Kconfig +12 -0
index 5b2a461dfd28..a901f74fd4ab 100644
@@ -51,4 +51,16 @@ config MACB_PCI
 	  To compile this driver as a module, choose M here: the module
 	  will be called macb_pci.
 
+config MACB_KUNIT_TEST
+	tristate "KUnit test for MACB" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Build KUnit tests for the MACB driver.
+
+	  For more information on KUnit and unit tests in general,
+	  please refer to the KUnit documentation.
+
+	  If unsure, say N.
+
 endif # NET_VENDOR_CADENCE
drivers/net/ethernet/cadence/Makefile +1 -1
index 1f33cdca9a3c..a0740da68649 100644
@@ -2,7 +2,7 @@
 #
 # Makefile for the Atmel network device drivers.
 #
-macb-y	:= macb_main.o
+macb-y	:= macb_main.o macb_utils.o
 
 ifeq ($(CONFIG_MACB_USE_HWSTAMP),y)
 macb-y	+= macb_ptp.o

drivers/net/ethernet/cadence/Makefile endif · line 15

Quoted 6 lines
drivers/net/ethernet/cadence/Makefile +3 -0
@@ -10,3 +10,6 @@ endif
 
 obj-$(CONFIG_MACB) += macb.o
 obj-$(CONFIG_MACB_PCI) += macb_pci.o
+
+obj-$(CONFIG_MACB_KUNIT_TEST) += macb_test.o
+macb_test-y := macb_kunit.o macb_utils.o

With MACB=m and MACB_KUNIT_TEST=m (so allmodconfig) kbuild complains:

Quoted 5 lines

drivers/net/ethernet/cadence/Makefile: macb_utils.o is added to
multiple modules: macb macb_test

Maybe build the test into macb.ko instead, or use
EXPORT_SYMBOL_IF_KUNIT()?

This is all dropped, following recommendation from Jakub. LLM will generate that in the future if needed (and the kunits are available on the mailing lists anyway).

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb.h +0 -0
index 51835de0f2a1..60d61efbf3e4 100644
@@ -194,6 +194,10 @@
 /* Screener Type 2 match registers */
 #define GEM_SCRT2		0x540
 
Quoted 5 lines

drivers/net/ethernet/cadence/macb.h line 199

Quoted 3 lines
drivers/net/ethernet/cadence/macb.h +3 -0
+/* Tx queue segment allocation */
+#define GEM_TXQSEGALLOC_LOWER	0x05A0
+#define GEM_TXQSEGALLOC_UPPER	0x05A4

nit: unused now?

Yes. It is unused and I kept it on purpose. I want the offset to appear so that if there is a register offset conflict we see it straight away.

From the datasheets I aggregated, I see no conflict. But that's the kind of offsets that could be reused if the feature is not available on a slightly different IP.

I even thought about adding many more #defines for unused (at the moment) offsets, to act as "documentation". We could even improve the offset comments to export more docs from datasheets to code. Long term, it could be useful. Anyway, this was a long rambling to say that this offset was kept on purpose.

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/cadence/macb_kunit.c +4 -0
 
[...]
 
+static void macb_sram_segments_test(struct kunit *test)
+{
+	const struct macb_sram_segments_case *p = test->param_value;
+	u32 val = gem_sram_distribute_segments(p->num_queues, 

p->num_segments);

drivers/net/ethernet/cadence/macb_kunit.c +5 -0
+	unsigned int i, sum_segments = 0, max_assigned_segments;
+	unsigned int num_queues = min(p->num_queues, p->num_segments);
+
+	for (i = 0; i < num_queues; i++) {
+		unsigned int q_segments = field_get(GEM_TXQSEGALLOC_MASK(i),
Quoted 8 lines

drivers/net/ethernet/cadence/macb_kunit.c line 24

Quoted 6 lines
drivers/net/ethernet/cadence/macb_kunit.c +6 -0
+						    val);
+
+		q_segments = 1U << q_segments;
+		sum_segments += q_segments;
+		KUNIT_ASSERT_GT_MSG(test, q_segments, 0, "queue %d, val %#x",
+				    i, val);

This can't fail, 1U << x is always at least 1.

Code has been dropped!

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb_kunit.c +9 -0
+	}
+
+	for (i = num_queues; i < MACB_MAX_QUEUES; i++) {
+		unsigned int pow = field_get(GEM_TXQSEGALLOC_MASK(i), val);
+
+		KUNIT_ASSERT_EQ_MSG(test, pow, 0, "queue %d, val %#x", i, val);
+	}
+
+	max_assigned_segments = min(p->num_segments,
Quoted 8 lines

drivers/net/ethernet/cadence/macb_kunit.c line 39

Quoted 6 lines
drivers/net/ethernet/cadence/macb_kunit.c +6 -0
+				    MACB_MAX_QUEUES * num_queues);
+	KUNIT_ASSERT_EQ_MSG(test, sum_segments, max_assigned_segments,
+			    "val %#x", val);
+}
+
+struct macb_sram_segments_case macb_sram_segments_cases[] = {

static const ... ?

Yes! I think some proper compiler or static analyser tooling flags could even have warned about that.

Quoted 29 lines
Quoted 29 lines

[...]

drivers/net/ethernet/cadence/macb_main.c +1 -0
index 2d069454795b..b70b81f51161 100644
@@ -3163,6 +3163,20 @@ static void macb_init_hw(struct macb *bp)
 	if (bp->caps & MACB_CAPS_JUMBO)
 		bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK;
 
+	/* Distribute Tx SRAM segments evenly based on active number of 

queues.

drivers/net/ethernet/cadence/macb_main.c +13 -0
+	 * TXQSEGALLOC is only documented for some GEM integrations.
+	 */
+	if (bp->caps & MACB_CAPS_TXQSEGALLOC) {
+		unsigned int num_segments;
+		u32 val;
+
+		num_segments = 1U << GEM_BFEXT(SEGMENTS_BIT_SIZE,
+					       gem_readl(bp, DCFG6));
+		val = gem_sram_distribute_segments(bp->num_queues,
+						   num_segments);
+		gem_writel(bp, TXQSEGALLOC_LOWER, val);
+	}
+
 	macb_configure_dma(bp);
Quoted 10 lines

drivers/net/ethernet/cadence/macb_main.c static const struct macb_config zynqmp_config = { · line 5872

Quoted 7 lines
drivers/net/ethernet/cadence/macb_main.c +1 -0
 	/* Enable RX partial store and forward and set watermark */
@@ -5854,6 +5868,7 @@ static const struct macb_config zynqmp_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
 		MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_BD_RD_PREFETCH |
+		MACB_CAPS_TXQSEGALLOC |
 		MACB_CAPS_USRIO_HAS_MII,

AFAIU zynqmp can't change the queue count,so this only rewrites the reset value there?

Yes. But their datasheets indicate they support segment alloc registers so I prefer putting the caps flag anyway.

Quoted 3 lines

Also, where does the limit of 8 segments per queue come from? With a single queue
and 16 segments half of the Tx SRAM stays unused.

Argh, I was sure I had a good reason for that so I sent V6 and wanted to reply to you afterwards. I thought the number of bits per queue was 2, but no it is 3 and we should have:

num_queues=1 num_segments=16 -> TXQSEGALLOC=0x00000007

But currently we have:

num_queues=1 num_segments=16 -> TXQSEGALLOC=0x00000003

I'm not sure if it matters; it requires HW that has much more segments than queues. For example EyeQ5 has 4 queues (the most I am aware of, equal to mpfs) and 16 segments. To reproduce the bug on a 4 queues platform, we'd need 64 segments.

From the datasheets: zu+ and versal have 1 segment, EyeQ5 has 16 and mpfs is unknown.

This will wait a bit more. I'll send myself a reply on V6 to clarify I have pending changes.

Thanks Nicolai!

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

maintainer
#10 lore raw

Re: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

In reply to Théo Lebrun
Quoted 1 line · On Fri, 16 Oct 2026 18:58:17 +0200 Théo Lebrun wrote:

Subject: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

Does this really belong in the tree ? LLM can generate such test on the fly. Side problem that it doesnt build cleanly, reportedly

author maintainer
#11 lore raw

Re: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

Hello Jakub,

Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Fri, 16 Oct 2026 18:58:17 +0200 Théo Lebrun wrote:

Subject: [PATCH net-next v5 3/3] net: macb: distribute evenly Tx SRAM segments

Does this really belong in the tree ? LLM can generate such test on the fly. Side problem that it doesnt build cleanly, reportedly

Dropped in V6. LLM can indeed generate kunits or extract the function into a separate C file and compile it as userspace code. And in any case, the old kunit tests are available in the mailing lists.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com