Re: [PATCH] net: stmmac: fix rx queue priority assignment

From: Romain Gantois
Date: Mon Feb 19 2024 - 05:40:48 EST


Hello Piotr,

On Mon, 19 Feb 2024, Piotr Wejman wrote:

> static void dwmac4_rx_queue_priority(struct mac_device_info *hw,
> - u32 prio, u32 queue)
> + u32 prio_mask, u32 queue)
> {
> void __iomem *ioaddr = hw->pcsr;
> - u32 base_register;
> - u32 value;
> + u32 clear_mask = 0;
> + u32 ctrl2, ctrl3;
> + int i;
>
> - base_register = (queue < 4) ? GMAC_RXQ_CTRL2 : GMAC_RXQ_CTRL3;
> - if (queue >= 4)
> - queue -= 4;
> + ctrl2 = readl(ioaddr + GMAC_RXQ_CTRL2);
> + ctrl3 = readl(ioaddr + GMAC_RXQ_CTRL3);
>
> - value = readl(ioaddr + base_register);
> + for (i = 0; i < 4; i++)
> + clear_mask |= ((prio_mask << GMAC_RXQCTRL_PSRQX_SHIFT(i)) &
> + GMAC_RXQCTRL_PSRQX_MASK(i));
>
> - value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue);
> - value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) &
> + ctrl2 &= ~clear_mask;
> + ctrl3 &= ~clear_mask;
> +
> + if (queue < 4) {
> + ctrl2 |= (prio_mask << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) &
This is a bit of a nitpick but do you think it would make sense to replace that
"4" with a macro? Something like GMAC_RXQCTRL_PSRXQ_MAXCTRL2QUEUE?

> GMAC_RXQCTRL_PSRQX_MASK(queue);
> - writel(value, ioaddr + base_register);
> +
> + writel(ctrl2, ioaddr + GMAC_RXQ_CTRL2);
> + writel(ctrl3, ioaddr + GMAC_RXQ_CTRL3);
I suppose that the order of these two writes are somehow important, else these
could be factored out of the conditional block. Could you maybe add a short
comment that explains why the order of these writes matter?

Best Regards,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com