net: spacemit: k1-emac: program frame size registers for jumbo frames
Subsystems (5)
PATCH 1/1 net: spacemit: k1-emac: program frame size registers for jumbo frames
The driver allows changing MTU up to 4K via emac_change_mtu() and allocates appropriately sized DMA buffers, but it never programs the MAC_MAXIMUM_FRAME_SIZE and MAC_RECEIVE_JABBER_SIZE registers.
This causes the MAC hardware to reject frames larger than the default 1518 bytes, even when larger buffers are allocated. Frames exceeding the default size trigger jabber errors and are discarded.
--- drivers/net/ethernet/spacemit/k1_emac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/spacemit/k1_emac.c +6 -0
@@ -228,6 +228,12 @@ static void emac_init_hw(struct emac_priv *priv) DEFAULT_TX_THRESHOLD);emac_wr (priv,MAC_RECEIVE_PACKET_START_THRESHOLD ,DEFAULT_RX_THRESHOLD ); +/* Set maximum frame size and jabber size based on configured buffer +* size. +*/ +emac_wr (priv,MAC_MAXIMUM_FRAME_SIZE , priv->dma_buf_sz); +emac_wr (priv,MAC_RECEIVE_JABBER_SIZE , priv->dma_buf_sz); +/* Configure flow control (enabled in emac_adjust_link() later) */ emac_set_mac_addr_reg (priv, fc_dest_addr,MAC_FC_SOURCE_ADDRESS_HIGH );emac_wr (priv,MAC_FC_PAUSE_HIGH_THRESHOLD ,DEFAULT_FC_FIFO_HIGH );
Signature · 1 line
2.52.0
Quoted 7 lines · Tomas Hlavacek
The driver allows changing MTU up to 4K via
emac_change_mtu()and allocates appropriately sized DMA buffers, but it never programs theMAC_MAXIMUM_FRAME_SIZEandMAC_RECEIVE_JABBER_SIZEregisters.This causes the MAC hardware to reject frames larger than the default 1518 bytes, even when larger buffers are allocated. Frames exceeding the default size trigger jabber errors and are discarded.
This sounds like a fix? Should it have a Fixes: tag? Should it be added to stable?
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Andrew
PATCH v2 1/1 net: spacemit: k1-emac: program frame size registers for jumbo frames
In reply to Tomas HlavacekThe driver allows changing MTU up to 4K via emac_change_mtu() and allocates appropriately sized DMA buffers, but it never programs the MAC_MAXIMUM_FRAME_SIZE and MAC_RECEIVE_JABBER_SIZE registers.
This causes the MAC hardware to reject frames larger than the default 1518 bytes, even when larger buffers are allocated. Frames exceeding the default size trigger jabber errors and are discarded.
---
v2: Added Fixes tag and Cc stable.
drivers/net/ethernet/spacemit/k1_emac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/spacemit/k1_emac.c +6 -0
@@ -228,6 +228,12 @@ static void emac_init_hw(struct emac_priv *priv) DEFAULT_TX_THRESHOLD);emac_wr (priv,MAC_RECEIVE_PACKET_START_THRESHOLD ,DEFAULT_RX_THRESHOLD ); +/* Set maximum frame size and jabber size based on configured buffer +* size. +*/ +emac_wr (priv,MAC_MAXIMUM_FRAME_SIZE , priv->dma_buf_sz); +emac_wr (priv,MAC_RECEIVE_JABBER_SIZE , priv->dma_buf_sz); +/* Configure flow control (enabled in emac_adjust_link() later) */ emac_set_mac_addr_reg (priv, fc_dest_addr,MAC_FC_SOURCE_ADDRESS_HIGH );emac_wr (priv,MAC_FC_PAUSE_HIGH_THRESHOLD ,DEFAULT_FC_FIFO_HIGH );
Signature · 1 line
2.52.0
Hi Tomas,
Quoted 22 lines · Tomas Hlavacek
The driver allows changing MTU up to 4K via
emac_change_mtu()and allocates appropriately sized DMA buffers, but it never programs theMAC_MAXIMUM_FRAME_SIZEandMAC_RECEIVE_JABBER_SIZEregisters.This causes the MAC hardware to reject frames larger than the default 1518 bytes, even when larger buffers are allocated. Frames exceeding the default size trigger jabber errors and are discarded.
Fixes bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")Signed-off-by Tomas Hlavacek <[email protected]>---
v2: Added Fixes tag and Cc stable.drivers/net/ethernet/spacemit/k1_emac.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/ethernet/spacemit/k1_emac.c +0
-0
drivers/net/ethernet/spacemit/k1_emac.c static void emac_init_hw(struct emac_priv *priv) · line 236
Quoted 9 lines
drivers/net/ethernet/spacemit/k1_emac.c +6
-0@@ -228,6 +228,12 @@ static void emac_init_hw(struct emac_priv *priv) DEFAULT_TX_THRESHOLD);emac_wr (priv,MAC_RECEIVE_PACKET_START_THRESHOLD ,DEFAULT_RX_THRESHOLD ); +/* Set maximum frame size and jabber size based on configured buffer +* size. +*/ +emac_wr (priv,MAC_MAXIMUM_FRAME_SIZE , priv->dma_buf_sz); +emac_wr (priv,MAC_RECEIVE_JABBER_SIZE , priv->dma_buf_sz); +
I'm no expert here, but just notice there is additional MAC_TRANSMIT_JABBER_SIZE register which is no need to set? or is the problem on receive side only?
Quoted 6 lines
drivers/net/ethernet/spacemit/k1_emac.c +0
-0/* Configure flow control (enabled in emac_adjust_link() later) */ emac_set_mac_addr_reg (priv, fc_dest_addr,MAC_FC_SOURCE_ADDRESS_HIGH );emac_wr (priv,MAC_FC_PAUSE_HIGH_THRESHOLD ,DEFAULT_FC_FIFO_HIGH );Signature · 1 line
2.52.0
Signature · 1 line
Yixun Lan (dlan)
Hi Tomas,
Thanks for the fix. Just a few more things...
Firstly, I believe it is preferred to send a new patch version in its own thread with a link to the previous version. See Documentation/process/maintainer-netdev.rst:
The new version of patches should be posted as a separate thread, not as a reply to the previous posting. Change log should include a link to the previous posting (see :ref:Changes requested).
You can do that for v3.
Secondly...
Quoted 7 lines · Tomas Hlavacek
[...]
drivers/net/ethernet/spacemit/k1_emac.c +0
-0
drivers/net/ethernet/spacemit/k1_emac.c static void emac_init_hw(struct emac_priv *priv) · line 236
Quoted 9 lines
drivers/net/ethernet/spacemit/k1_emac.c +6
-0@@ -228,6 +228,12 @@ static void emac_init_hw(struct emac_priv *priv) DEFAULT_TX_THRESHOLD);emac_wr (priv,MAC_RECEIVE_PACKET_START_THRESHOLD ,DEFAULT_RX_THRESHOLD ); +/* Set maximum frame size and jabber size based on configured buffer +* size. +*/ +emac_wr (priv,MAC_MAXIMUM_FRAME_SIZE , priv->dma_buf_sz); +emac_wr (priv,MAC_RECEIVE_JABBER_SIZE , priv->dma_buf_sz); +
I tested this (also setting MAC_TRANSMIT_JABBER_SIZE, as Yixun described) and it appears that this has surfaced a latent bug in the code.
I found that the hardware can't actually handle 4096-byte buffers, since the size field is only 12-bit. (It was my fault to assume that existing code was right in this regard...) So MTU larger than ~2000 breaks the hardware, and also triggers the WARN_ON_ONCE() in emac_rx_frame_good(). 4095 works just fine.
Can you include this in v3 as well? Maybe also reword the commit messages a bit. Thanks.
(Here's hoping Thunderbird hasn't destroyed the whitespace...)
drivers/net/ethernet/spacemit/k1_emac.c +3 -3
@@ -38,7 +38,7 @@#define EMAC_DEFAULT_BUFSIZE 1536#define EMAC_RX_BUF_2K 2048 -#define EMAC_RX_BUF_4K 4096 +#define EMAC_RX_BUF_MAX FIELD_MAX(RX_DESC_1_BUFFER_SIZE_1_MASK)/* Tuning parameters from SpacemiT */ #define EMAC_TX_FRAMES 64
@@ -937,7 +937,7 @@ static int emac_change_mtu(struct net_device *ndev, int mtu)else if (frame_len <=EMAC_RX_BUF_2K ) priv->dma_buf_sz =EMAC_RX_BUF_2K ;else - priv->dma_buf_sz =EMAC_RX_BUF_4K ; + priv->dma_buf_sz =EMAC_RX_BUF_MAX ; ndev->mtu = mtu;
@@ -2011,7 +2011,7 @@ static int emac_probe(struct platform_device *pdev) ndev->hw_features =NETIF_F_SG ; ndev->features |= ndev->hw_features; - ndev->max_mtu =EMAC_RX_BUF_4K - (ETH_HLEN +ETH_FCS_LEN ); + ndev->max_mtu =EMAC_RX_BUF_MAX - (ETH_HLEN +ETH_FCS_LEN ); ndev->pcpu_stat_type =NETDEV_PCPU_STAT_DSTATS ; priv =netdev_priv (ndev);
Quoted 22 lines · Tomas Hlavacek
The driver allows changing MTU up to 4K via
emac_change_mtu()and allocates appropriately sized DMA buffers, but it never programs theMAC_MAXIMUM_FRAME_SIZEandMAC_RECEIVE_JABBER_SIZEregisters.This causes the MAC hardware to reject frames larger than the default 1518 bytes, even when larger buffers are allocated. Frames exceeding the default size trigger jabber errors and are discarded.
Fixes bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")Signed-off-by Tomas Hlavacek <[email protected]>---
v2: Added Fixes tag and Cc stable.drivers/net/ethernet/spacemit/k1_emac.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/ethernet/spacemit/k1_emac.c +0
-0
drivers/net/ethernet/spacemit/k1_emac.c static void emac_init_hw(struct emac_priv *priv) · line 236
Quoted 9 lines
drivers/net/ethernet/spacemit/k1_emac.c +6
-0@@ -228,6 +228,12 @@ static void emac_init_hw(struct emac_priv *priv) DEFAULT_TX_THRESHOLD);emac_wr (priv,MAC_RECEIVE_PACKET_START_THRESHOLD ,DEFAULT_RX_THRESHOLD ); +/* Set maximum frame size and jabber size based on configured buffer +* size. +*/ +emac_wr (priv,MAC_MAXIMUM_FRAME_SIZE , priv->dma_buf_sz); +emac_wr (priv,MAC_RECEIVE_JABBER_SIZE , priv->dma_buf_sz); +
Oh and... maybe these should be priv->ndev->mtu + ETH_HLEN + ETH_FCS_LEN?
Jakub Kicinski
maintainerQuoted 1 line · On Tue, 27 Jan 2026 12:58:21 +0800 Vivian Wang wrote:
Oh and... maybe these should be
priv->ndev->mtu+ETH_HLEN+ETH_FCS_LEN?
+ 2 * VLAN_HLEN perhaps?
Quoted 3 lines · Jakub Kicinski
Quoted 1 line · On Tue, 27 Jan 2026 12:58:21 +0800 Vivian Wang wrote:
Oh and... maybe these should be
priv->ndev->mtu+ETH_HLEN+ETH_FCS_LEN?+ 2 *
VLAN_HLENperhaps?
... yeah looks like I've simply messed up the whole MTU and max frame size configuration thing.
* Tomas: Do you still want to deal with all this and figure out all the MTU stuff that needs to be fixed? I can give it a go but I don't want to steal your credit.
Regards,
Vivian "dramforever" Wang