Re: [PATCH net-next v6 2/2] net: macb: distribute evenly Tx SRAM segments

From: netdev-bot+sashiko

Date: Tue Nov 17 2026 - 14:43:47 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The commit message says TXQSEGALLOC must be re-applied "if/when
number of active queues is modified", but the patch only programs it…
- [Medium] gem_sram_distribute_segments() can build a TXQSEGALLOC value
whose total segment count is larger than the num_segments that…

--

net: macb: distribute evenly Tx SRAM segments

This patch programs the GEM TXQSEGALLOC register from macb_init_hw(). It
spreads the Tx SRAM segments advertised in DCFG6 across the active
queues, with each queue's share encoded as a power of two. The new
MACB_CAPS_TXQSEGALLOC capability is enabled for ZynqMP, Versal and EyeQ5.

> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index e7325af4b399c..dc1624815f71e 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -3432,6 +3432,63 @@ static void macb_context_swap_end(struct macb *bp,

[ ... ]

> +static u32 gem_sram_distribute_segments(unsigned int num_queues,
> + unsigned int num_segments)
> +{

[ ... ]

> + /* pow=0 for all queues. ilog2(0) is dangerous. */
> + if (num_queues >= num_segments)
> + return 0;

[ ... ]

> + for (i = 0; i < num_advantaged_queues; i++)
> + val |= field_prep(GEM_TXQSEGALLOC_MASK(i), pow + 1);
> + for (i = num_advantaged_queues; i < num_queues; i++)
> + val |= field_prep(GEM_TXQSEGALLOC_MASK(i), pow);
> +
> + return val;
> +}

[Severity: Medium]
Can the value built by gem_sram_distribute_segments() add up to more
segments than the num_segments read from DCFG6?

A field value of 0 still means 2^0 = 1 segment. There seem to be two ways
to over-allocate.

First, when num_queues > num_segments, the early return gives every
active queue 1 segment. The comment above uses num_queues=4 and
num_segments=2 as an example, which claims 4 segments out of 2.

Second, the loops only fill fields for i < num_queues. macb_init_hw()
passes bp->ctx->num_queues, not the hardware queue count. The fields for
hardware queues from ctx->num_queues up to bp->max_num_queues stay at 0.
Each of those still claims 1 segment, on top of an active split that
already uses every segment. With 4 hardware queues and 16 segments:

num_queues=2: 8 + 8 + 1 + 1 = 18
num_queues=3: 8 + 4 + 4 + 1 = 17

On Versal and EyeQ5 (MACB_CAPS_QUEUE_DISABLE), this happens after
ethtool -L while the interface is down, followed by an open. The reset
value is an even split over all hardware queues, so it adds up to the
available segments.

If the GEM requires the total to stay within the DCFG6 count, could this
give queues overlapping or out-of-range Tx SRAM regions?

> @@ -3465,6 +3522,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->ctx->num_queues,
> + num_segments);
> + gem_writel(bp, TXQSEGALLOC_LOWER, val);
> + }

[Severity: High]
The commit message says the distribution needs care "if/when number of
active queues is modified". Is that case covered when the queue count
changes on a running interface?

Only macb_open() and the resume path call macb_init_hw(). Running
ethtool -L ethX combined N while the interface is up goes through:

macb_set_channels()
macb_context_swap_start()
macb_context_swap_end(bp, new_ctx)
macb_init_buffers()
macb_configure_dma()

macb_context_swap_end() installs a context with the new num_queues and
turns RE/TE back on. Nothing on this path rewrites GEM_TXQSEGALLOC_LOWER.
The Tx SRAM split stays sized for the old queue count until the next
down/up or suspend/resume.

Two examples:

Open with 1 queue. q0 gets 8 segments and the other fields stay at 0
(1 segment each). If the interface then grows to N queues while up, each
new queue runs with a single segment while TXPBMS is set in DMACFG.

Going from 2 queues to 1 while up leaves half of the SRAM assigned to
the disabled queue.

Versal and EyeQ5 set both MACB_CAPS_QUEUE_DISABLE and
MACB_CAPS_TXQSEGALLOC, so this path is reachable there.

Could the write be moved into a helper and also called from
macb_context_swap_end() under bp->lock, next to macb_configure_dma()?

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-macb-set-channels-v6-0-5de59d9e7f02%40bootlin.com