All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: <gaohan@iscas.ac.cn>, "Conor Dooley" <conor.dooley@microchip.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Punnaiah Choudary Kalluri" <punnaia@xilinx.com>,
	"Harini Katakam" <harini.katakam@xilinx.com>
Cc: <linux-riscv@lists.infradead.org>,
	"Han Gao" <rabenda.cn@gmail.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Jingkun Zheng" <zhengjingkun@iscas.ac.cn>
Subject: Re: [PATCH net] net: macb: limit jumbo frames to the RX buffer size
Date: Tue, 17 Nov 2026 14:32:38 +0100	[thread overview]
Message-ID: <DMXIVFWKAM8A.29COLJ2EC6MUM@bootlin.com> (raw)
In-Reply-To: <20261114-macb-jumbo-jml-v1-1-f501395eaf9e@iscas.ac.cn>

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


WARNING: multiple messages have this Message-ID (diff)
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: <gaohan@iscas.ac.cn>, "Conor Dooley" <conor.dooley@microchip.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Punnaiah Choudary Kalluri" <punnaia@xilinx.com>,
	"Harini Katakam" <harini.katakam@xilinx.com>
Cc: <linux-riscv@lists.infradead.org>,
	"Han Gao" <rabenda.cn@gmail.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Jingkun Zheng" <zhengjingkun@iscas.ac.cn>
Subject: Re: [PATCH net] net: macb: limit jumbo frames to the RX buffer size
Date: Tue, 17 Nov 2026 14:32:38 +0100	[thread overview]
Message-ID: <DMXIVFWKAM8A.29COLJ2EC6MUM@bootlin.com> (raw)
In-Reply-To: <20261114-macb-jumbo-jml-v1-1-f501395eaf9e@iscas.ac.cn>

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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2026-11-17 13:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  9:51 [PATCH net] net: macb: limit jumbo frames to the RX buffer size Han Gao
2026-11-14  9:51 ` Han Gao via B4 Relay
2026-11-14  9:51 ` Han Gao via B4 Relay
2026-11-15 21:04 ` netdev-bot+sashiko
2026-11-15 21:04   ` netdev-bot+sashiko
2026-11-17 13:32 ` Théo Lebrun [this message]
2026-11-17 13:32   ` Théo Lebrun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DMXIVFWKAM8A.29COLJ2EC6MUM@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor.dooley@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gaohan@iscas.ac.cn \
    --cc=harini.katakam@xilinx.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=punnaia@xilinx.com \
    --cc=rabenda.cn@gmail.com \
    --cc=zhengjingkun@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.