[net,v2,2/2] net: stmmac: dwmac-sun8i: Limit the MTU to 2018

Message ID 20261122-sun8i-emac-mtu-limit-v2-2-c4081e5b83cf@gmail.com (mailing list archive)
State New
Headers
Series net: stmmac: Limit the MTU of normal descriptors to one buffer |

Commit Message

Arun Iyengar via B4 Relay Nov. 22, 2026, 9:13 a.m. UTC
From: Arun Iyengar <aiyengar1990@gmail.com>

The H616 RX DMA fills only 2044 bytes of a buffer, so frames of 2045 to
2047 bytes, allowed by the previous patch, are dropped. Limit the MTU
so that a frame with two VLAN tags and the FCS fits 2044 bytes.

Fixes: 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Chen-Yu Tsai Nov. 22, 2026, 11:39 a.m. UTC | #1
On Sun, Nov 22, 2026 at 5:13 PM Arun Iyengar via B4 Relay
<devnull+aiyengar1990.gmail.com@kernel.org> wrote:
>
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> The H616 RX DMA fills only 2044 bytes of a buffer, so frames of 2045 to
> 2047 bytes, allowed by the previous patch, are dropped. Limit the MTU
> so that a frame with two VLAN tags and the FCS fits 2044 bytes.

FWIW I think this applies to all DWMAC cores.

So I tried to do some research of my own. Google AI search pointed me to
STM32F4 or STM32F7, and some Altera FPGAs (I used the Intel® Arria® 10 Hard
Processor System Technical Reference Manual"), that had some variant or
version of the DWMAC core, and had proper programming guides.

The STM32F4 reference manuals has this note:

Even when the start address of a receive buffer is not aligned to the
system databus width
the system should allocate a receive buffer of a size aligned to the
system bus width. For
example, if the system allocates a 1024 byte (1 KB) receive buffer
starting from address
0x1000, the software can program the buffer start address in the
receive descriptor to have
a 0x1002 offset. The receive DMA writes the frame to this buffer with
dummy data in the first
two locations (0x1000 and 0x1001). The actual frame is written from
location 0x1002. Thus,
the actual useful space in this buffer is 1022 bytes, even though the
buffer size is
programmed as 1024 bytes, due to the start address offset.

The Intel one had the same note. It looks pretty much the same, but I didn't
compare it word-for-word.

So for normal descriptors the buffer size is bound to (2KB - bus width).
Not tested, but I think there is more evidence supporting a cross-platform
limit.


ChenYu

> Fixes: 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 2ece7ba9dd73..ec401cae8187 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -1208,6 +1208,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
>         plat_dat->mac_setup = sun8i_dwmac_setup;
>         plat_dat->tx_fifo_size = 4096;
>         plat_dat->rx_fifo_size = 16384;
> +       plat_dat->maxmtu = 2044 - ETH_HLEN - 2 * VLAN_HLEN - ETH_FCS_LEN;
>
>         ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
>         if (ret)
>
> --
> 2.55.0
>
>
  
Nicolai Buchwitz Nov. 22, 2026, 4:31 p.m. UTC | #2
On 22.11.2026 12:39, Chen-Yu Tsai wrote:
> [...]

> FWIW I think this applies to all DWMAC cores.

> [...]

> So for normal descriptors the buffer size is bound to (2KB - bus 
> width).
> Not tested, but I think there is more evidence supporting a 
> cross-platform
> limit.

The sun8i EMAC isn't a Synopsys core, so this needs a test on one.
Maxime, could you try MTU 2019-2021 on your boards?

> [...]

Regards,
Nicolai
  
Nicolai Buchwitz Nov. 22, 2026, 4:33 p.m. UTC | #3
On 22.11.2026 10:13, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> The H616 RX DMA fills only 2044 bytes of a buffer, so frames of 2045 to
> 2047 bytes, allowed by the previous patch, are dropped. Limit the MTU
> so that a frame with two VLAN tags and the FCS fits 2044 bytes.
> 
> Fixes: 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>

> [...]

Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>

Thanks,
Nicolai
  
Maxime Chevallier Nov. 22, 2026, 4:36 p.m. UTC | #4
Hi,

On 11/22/26 17:31, Nicolai Buchwitz wrote:
> On 22.11.2026 12:39, Chen-Yu Tsai wrote:
>> [...]
> 
>> FWIW I think this applies to all DWMAC cores.
> 
>> [...]
> 
>> So for normal descriptors the buffer size is bound to (2KB - bus width).
>> Not tested, but I think there is more evidence supporting a cross-platform
>> limit.
> 
> The sun8i EMAC isn't a Synopsys core, so this needs a test on one.

It's likely a synopsys core, but with some wrapper around the register accesses,
hard to tell how much of the actual dwmac is in there ._.

> Maxime, could you try MTU 2019-2021 on your boards?

It'll be tested in the nightly runs, I've setup some local MTU sweep tests
following the previous version of that patch :)

wonder what else will come out of it, I'll report in the morning.

Maxime
  
Nicolai Buchwitz Nov. 22, 2026, 4:40 p.m. UTC | #5
On 22.11.2026 17:36, Maxime Chevallier wrote:
> [...]

>> The sun8i EMAC isn't a Synopsys core, so this needs a test on one.
> 
> It's likely a synopsys core, but with some wrapper around the register 
> accesses,
> hard to tell how much of the actual dwmac is in there ._.

Someone really needs to draw fancy cheat sheet with a stmmac family
tree - lots of weird uncles and stepmothers :-)

> 
>> Maxime, could you try MTU 2019-2021 on your boards?
> 
> It'll be tested in the nightly runs, I've setup some local MTU sweep 
> tests
> following the previous version of that patch :)

Thanks!

> 
> wonder what else will come out of it, I'll report in the morning.
> 
> Maxime

Nicolai
  
Andrew Lunn Nov. 22, 2026, 6:56 p.m. UTC | #6
> The STM32F4 reference manuals has this note:
> 
> Even when the start address of a receive buffer is not aligned to the
> system databus width
> the system should allocate a receive buffer of a size aligned to the
> system bus width. For
> example, if the system allocates a 1024 byte (1 KB) receive buffer
> starting from address
> 0x1000, the software can program the buffer start address in the
> receive descriptor to have
> a 0x1002 offset. The receive DMA writes the frame to this buffer with
> dummy data in the first
> two locations (0x1000 and 0x1001). The actual frame is written from
> location 0x1002.

> So for normal descriptors the buffer size is bound to (2KB - bus width).

There is a second use for this, unrelated to bus width. The ethernet
header is 14 bytes in size, 2x 6 octet MAC address plus a 2 octet
ethertype header. By offsetting the start address by two, it means the
data after the ethernet header is then 4 byte aligned, making it more
efficient to access fields in the IP, TCP UDP headers etc.

	  Andrew
  

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 2ece7ba9dd73..ec401cae8187 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1208,6 +1208,7 @@  static int sun8i_dwmac_probe(struct platform_device *pdev)
 	plat_dat->mac_setup = sun8i_dwmac_setup;
 	plat_dat->tx_fifo_size = 4096;
 	plat_dat->rx_fifo_size = 16384;
+	plat_dat->maxmtu = 2044 - ETH_HLEN - 2 * VLAN_HLEN - ETH_FCS_LEN;
 
 	ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
 	if (ret)