[PATCH net v7 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly
Maxime Chevallier
maxime.chevallier at bootlin.com
Tue Nov 17 05:21:29 PST 2026
Hi,
On 11/14/26 10:21, Ding Hui wrote:
> From: Ding Hui <dinghui at lixiang.com>
>
> An XSK fill ring may supply fewer buffers than the RX ring needs. Those
> unfilled descriptors must remain CPU-owned, including on legacy cores
> whose clear callback only clears the buffer address. Add an ownership
> operation that preserves descriptor size and ring/chain control fields.
>
> Track the number of descriptors awaiting refill independently of the
> ring indices, so an entirely empty ring can be distinguished from one
> with no pending refills. Initialize the pending region after the allocated
> prefix and stop consumption before entering it. Retry pending refills
> on each poll, including userspace wakeups with fewer than a batch of
> buffers, and retain batching during packet processing.
>
> Update the tail after successful refills and kick legacy RX DMA. Use the
> end-of-ring tail address for a refill ending at index zero, including a
> completely empty ring populated before DMA has advanced from the base.
> Select the receive buffer size from the XSK pool even if no buffers were
> available at initialization.
>
> Fixes: bba2556efad6 ("net: stmmac: Enable RX via AF_XDP zero-copy")
> Signed-off-by: Ding Hui <dinghui at lixiang.com>
> ---
> .../ethernet/stmicro/stmmac/dwmac4_descs.c | 6 +++
> .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 6 +++
> .../net/ethernet/stmicro/stmmac/enh_desc.c | 6 +++
> drivers/net/ethernet/stmicro/stmmac/hwif.h | 3 ++
> .../net/ethernet/stmicro/stmmac/norm_desc.c | 6 +++
> drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +
> .../net/ethernet/stmicro/stmmac/stmmac_main.c | 49 +++++++++++++------
> 7 files changed, 63 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
> index c6a8f8d73501..307bbd63dbcb 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
> @@ -176,6 +176,11 @@ static void dwmac4_set_tx_owner(struct dma_desc *p)
> p->des3 |= cpu_to_le32(TDES3_OWN);
> }
>
> +static void dwmac4_clear_rx_owner(struct dma_desc *p)
> +{
> + p->des3 &= cpu_to_le32(~RDES3_OWN);
> +}
> +
> static void dwmac4_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
> {
> u32 flags = (RDES3_OWN | RDES3_BUFFER1_VALID_ADDR);
> @@ -539,6 +544,7 @@ const struct stmmac_desc_ops dwmac4_desc_ops = {
> .rx_status = dwmac4_wrback_get_rx_status,
> .set_tx_owner = dwmac4_set_tx_owner,
> .set_rx_owner = dwmac4_set_rx_owner,
> + .clear_rx_owner = dwmac4_clear_rx_owner,
> .get_rx_vlan_tci = dwmac4_wrback_get_rx_vlan_tci,
> .get_rx_vlan_valid = dwmac4_wrback_get_rx_vlan_valid,
> .get_rx_frame_len = dwmac4_wrback_get_rx_frame_len,
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> index 6719ac6e395b..ad377c76ed4e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> @@ -51,6 +51,11 @@ static void dwxgmac2_set_tx_owner(struct dma_desc *p)
> p->des3 |= cpu_to_le32(XGMAC_TDES3_OWN);
> }
>
> +static void dwxgmac2_clear_rx_owner(struct dma_desc *p)
> +{
> + p->des3 &= cpu_to_le32(~XGMAC_RDES3_OWN);
sparse says :
+../drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c:181:20: warning: cast truncates bits from constant value (ffffffff7fffffff becomes 7fffffff)
+../drivers/net/ethernet/stmicro/stmmac/norm_desc.c:146:20: warning: cast truncates bits from constant value (ffffffff7fffffff becomes 7fffffff)
+../drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:56:20: warning: cast truncates bits from constant value (ffffffff7fffffff becomes 7fffffff)
+../drivers/net/ethernet/stmicro/stmmac/enh_desc.c:304:20: warning: cast truncates bits from constant value (ffffffff7fffffff becomes 7fffffff)
Not too big of a deal, but let's not add new sparse warnings.
We've seen that before, you can maybe use some trickery like here :
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/ethernet/stmicro/stmmac/descs.h#L73
The rests of the series starts to look fairly solid, I've quickly tested
it and it does seem to work, I'll properly review the next iteration,
Thank you,
Maxime
More information about the linux-arm-kernel
mailing list