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

From: netdev-bot+sashiko

Date: Sun Nov 22 2026 - 15:02:04 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] gem_sram_distribute_segments() in
drivers/net/ethernet/cadence/macb_main.c handles num_queues >=…
- [Low] The comment above static_assert(MACB_MAX_QUEUES == 8) in
gem_sram_distribute_segments()…

--

net: macb: distribute evenly Tx SRAM segments

This patch adds gem_sram_distribute_segments(). It programs the GEM
TXQSEGALLOC register so that the Tx SRAM segments reported in DCFG6 are
spread across the active queues as powers of two. It is called from
macb_init_hw() and macb_context_swap_end(), and it is enabled for the
zynqmp, versal and eyeq5 configs.

> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 180da5d62f09a..5d382f0e4aec3 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -3319,6 +3319,69 @@ static u32 macb_dbw(struct macb *bp)
> }
> }
>
> +/*
> + * Distribute evenly available segments across active queues. The computation
> + * is complex because (1) segments are counted in powers of two and (2) a queue
> + * can only use up to 128 segments. There are four types of cases:

[ ... ]

> + * - Sharing all segments is not doable because not enough segments are
> + * available. Take num_queues=4 and num_segments=2.

[ ... ]

> +static void gem_sram_distribute_segments(struct macb *bp)
> +{
> + unsigned int num_segments, pow, remaining_segments, i;
> + unsigned int num_queues = bp->ctx->num_queues;
> + unsigned int num_advantaged_queues = 0;
> + u32 val = 0;
> +
> + if (!(bp->caps & MACB_CAPS_TXQSEGALLOC))
> + return;
> +
> + num_segments = 1U << GEM_BFEXT(SEGMENTS_BIT_SIZE, gem_readl(bp, DCFG6));
> +
> + /* When growing the max # of queues, make sure to return a u64 here and
> + * to write into GEM_TXQSEGALLOC_UPPER.
> + */
> + static_assert(MACB_MAX_QUEUES == 8);

[Severity: Low]
This isn't a bug, but the comment talks about returning a u64.
gem_sram_distribute_segments() is a static void function. It builds its
result in the local u32 val and writes it with:

gem_writel(bp, TXQSEGALLOC_LOWER, val);

To support more than 8 queues, wouldn't the change be to widen (or split)
val and add a second write to TXQSEGALLOC_UPPER, rather than to change a
return type? Could the comment say that instead?

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

[Severity: Low]
What happens here when num_queues is strictly greater than num_segments?

TXQSEGALLOC fields hold log2 of the segment count. The commit message
says "2 for queue 0 means it has 2^2=4 segments", so a field value of 0
means 1 segment, not zero segments.

When num_queues == num_segments, val = 0 gives each queue 1 segment and
the total matches the SRAM size.

When num_queues > num_segments, every active queue still gets 1 segment.
Take the example from the header comment, "num_queues=4 and
num_segments=2". It ends up programmed as 4 x 1 = 4 segments, but DCFG6
reports only 2.

Doesn't that give the hardware more Tx SRAM segments than it has, with
nothing logged? The header comment presents this case as handled.

Would it be better to limit the number of active queues to num_segments
in this case? Another option is to warn and keep the reset value instead
of writing 0.

> +
> + pow = min_t(unsigned int, ilog2(num_segments / num_queues), 7);
> + remaining_segments = num_segments - num_queues * (1U << pow);

[ ... ]

> +
> +writel:
> + gem_writel(bp, TXQSEGALLOC_LOWER, val);
> +}

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-macb-set-channels-v7-0-2dbc00f686af%40bootlin.com