[PATCH net] net: macb: limit jumbo frames to the RX buffer size

Théo Lebrun theo.lebrun at bootlin.com
Tue Nov 17 05:32:38 PST 2026


Hello Han,

On Sat Nov 14, 2026 at 10:51 AM CET, Han Gao wrote:
> +/* Longest frame that fits in a single RX buffer */
> +static u32 gem_jumbo_max_len(struct macb *bp)
> +{
> +	u32 len = bp->ctx->rx_buffer_size;
> +
> +	/* Frame data starts NET_IP_ALIGN bytes into the buffer without RSC */
> +	if (!(bp->caps & MACB_CAPS_RSC))
> +		len -= NET_IP_ALIGN;
> +
> +	return min(len, bp->jumbo_max_len);
> +}

Why do

   gem_writel(bp, JML, min(bp->ctx->rx_buffer_size, bp->jumbo_max_len));
   // or
   gem_writel(bp, JML, min(bp->ctx->rx_buffer_size - NET_IP_ALIGN, bp->jumbo_max_len));

And not just

   gem_writel(bp, JML, bp->ctx->rx_buffer_size);
   // or
   gem_writel(bp, JML, bp->ctx->rx_buffer_size - NET_IP_ALIGN);

Asked another way: in what case can rx_buffer_size > jumbo_max_len? It
this can ever occur, it sounds like a bug. It makes no sense to have
buffers larger than the max jumbo length. If we fix it, then we can use
the simpler form.

(This is the same report as Sashiko: your min() picks jumbo_max_len only
for some really specific values of MTU.)

>  /* Configure the receive DMA engine
>   * - use the correct receive buffer size
>   * - set best burst length for DMA operations
> @@ -3286,6 +3298,13 @@ static void macb_configure_dma(struct macb *bp)
>  		netdev_dbg(bp->netdev, "Cadence configure DMA with 0x%08x\n",
>  			   dmacfg);
>  		gem_writel(bp, DMACFG, dmacfg);
> +
> +		/* Jumbo frames are always enabled, so limit their length to
> +		 * what fits in one RX buffer. Longer frames would otherwise be
> +		 * split across several descriptors and dropped by gem_rx().
> +		 */
> +		if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len)
> +			gem_writel(bp, JML, gem_jumbo_max_len(bp));
>  	}
>  }
>  
> @@ -3422,8 +3441,6 @@ static void macb_init_hw(struct macb *bp)
>  		config |= MACB_BIT(NBC);	/* No BroadCast */
>  	config |= macb_dbw(bp);
>  	macb_writel(bp, NCFGR, config);
> -	if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len)
> -		gem_writel(bp, JML, bp->jumbo_max_len);
>  	bp->rx_frm_len_mask = MACB_RX_FRMLEN_MASK;
>  	if (bp->caps & MACB_CAPS_JUMBO)
>  		bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK;

Thanks,

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




More information about the linux-riscv mailing list