Skip to contentSkip to conversation

net: fec: add the Jumbo frame support

PATCH New Shenwei Wang 2 participants 8 messages Sep 10, 2025 – Sep 14, 2025

Subsystems (4)
lore
Share & tools
lore

Shenwei Wang

author reviewer
#0 lore raw

v7 cover net: fec: add the Jumbo frame support

Changes in v7:
- replaced #ifdef with if statement per Jakub's suggestion.

Changes in v6:
- address the comments from Frank and Jakub.
- only allow changing mtu when the adaptor is not running, simplifying the configuration logic.

Changes in v5:
- move the macro FEC_DRV_RESERVE_SPACE to fec.h
- improve the comments for patch #0004

Changes in v4:
- configure the MAX_FL according to the MTU value, and correct the comments for patch #3.
- in change_mtu function, revert to original setting when buffer allocation fails in patch #4
- only enable the FIFO cut-through mode when mtu greater than (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN)

Changes in v3:
- modify the OPT_FRAME_SIZE definition and drop the condition logic
- address the review comments from Wei Fang

Changes in v2:
- split the v1 patch per Andrew's feedback.

Shenwei Wang (6):
net: fec: use a member variable for maximum buffer size
net: fec: add pagepool_order to support variable page size
net: fec: update MAX_FL based on the current MTU
net: fec: add rx_frame_size to support configurable RX length
net: fec: add change_mtu to support dynamic buffer allocation
net: fec: enable the Jumbo frame support for i.MX8QM

 drivers/net/ethernet/freescale/fec.h      | 11 +++-
 drivers/net/ethernet/freescale/fec_main.c | 68 ++++++++++++++++++-----
 2 files changed, 64 insertions(+), 15 deletions(-)

--
2.43.0

author reviewer
#1 lore raw

PATCH v7 1/6 net: fec: use a member variable for maximum buffer size

Refactor code to support Jumbo frame functionality by adding a member variable in the fec_enet_private structure to store PKT_MAXBUF_SIZE.

Remove the OPT_FRAME_SIZE and define a new macro OPT_ARCH_HAS_MAX_FL to indicate architectures that support configurable maximum frame length. And update the MAX_FL register value to max_buf_size when OPT_ARCH_HAS_MAX_FL is defined as 1.

---
 drivers/net/ethernet/freescale/fec.h      |  1 +
 drivers/net/ethernet/freescale/fec_main.c | 16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
index 5c8fdcef759b..2969088dda09 100644
@@ -619,6 +619,7 @@ struct fec_enet_private {
 
 	unsigned int total_tx_ring_size;
 	unsigned int total_rx_ring_size;
+	unsigned int max_buf_size;
 
 	struct	platform_device *pdev;
 
drivers/net/ethernet/freescale/fec_main.c +10 -6
index 1383918f8a3f..93bd8cec6719 100644
@@ -253,9 +253,9 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
     defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM) || \
     defined(CONFIG_ARM64)
-#define	OPT_FRAME_SIZE	(PKT_MAXBUF_SIZE << 16)
+#define	OPT_ARCH_HAS_MAX_FL	1
 #else
-#define	OPT_FRAME_SIZE	0
+#define	OPT_ARCH_HAS_MAX_FL	0
 #endif
 
 /* FEC MII MMFR bits definition */
@@ -1083,7 +1083,7 @@ static void fec_enet_enable_ring(struct net_device *ndev)
 	for (i = 0; i < fep->num_rx_queues; i++) {
 		rxq = fep->rx_queue[i];
 		writel(rxq->bd.dma, fep->hwp + FEC_R_DES_START(i));
-		writel(PKT_MAXBUF_SIZE, fep->hwp + FEC_R_BUFF_SIZE(i));
+		writel(fep->max_buf_size, fep->hwp + FEC_R_BUFF_SIZE(i));
 
 		/* enable DMA1/2 */
 		if (i)
@@ -1145,8 +1145,11 @@ static void
 fec_restart(struct net_device *ndev)
 {
 	struct fec_enet_private *fep = netdev_priv(ndev);
-	u32 rcntl = OPT_FRAME_SIZE | FEC_RCR_MII;
 	u32 ecntl = FEC_ECR_ETHEREN;
+	u32 rcntl = FEC_RCR_MII;
+
+	if (OPT_ARCH_HAS_MAX_FL)
+		rcntl |= fep->max_buf_size << 16;
 
 	if (fep->bufdesc_ex)
 		fec_ptp_save_state(fep);
@@ -1191,7 +1194,7 @@ fec_restart(struct net_device *ndev)
 		else
 			val &= ~FEC_RACC_OPTIONS;
 		writel(val, fep->hwp + FEC_RACC);
-		writel(PKT_MAXBUF_SIZE, fep->hwp + FEC_FTRL);
+		writel(fep->max_buf_size, fep->hwp + FEC_FTRL);
 	}
 #endif
 
@@ -4559,7 +4562,8 @@ fec_probe(struct platform_device *pdev)
 	fec_enet_clk_enable(ndev, false);
 	pinctrl_pm_select_sleep_state(&pdev->dev);
 
-	ndev->max_mtu = PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN;
+	fep->max_buf_size = PKT_MAXBUF_SIZE;
+	ndev->max_mtu = fep->max_buf_size - ETH_HLEN - ETH_FCS_LEN;
 
 	ret = register_netdev(ndev);
 	if (ret)
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH v7 2/6 net: fec: add pagepool_order to support variable page size

In reply to Shenwei Wang

Add a new pagepool_order member in the fec_enet_private struct to allow dynamic configuration of page size for an instance. This change clears the hardcoded page size assumptions.

---
 drivers/net/ethernet/freescale/fec.h      | 1 +
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
index 2969088dda09..47317346b2f3 100644
@@ -620,6 +620,7 @@ struct fec_enet_private {
 	unsigned int total_tx_ring_size;
 	unsigned int total_rx_ring_size;
 	unsigned int max_buf_size;
+	unsigned int pagepool_order;
 
 	struct	platform_device *pdev;
 
drivers/net/ethernet/freescale/fec_main.c +4 -2
index 93bd8cec6719..5fb9afdafec4 100644
@@ -1783,7 +1783,7 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 	 * These get messed up if we get called due to a busy condition.
 	 */
 	bdp = rxq->bd.cur;
-	xdp_init_buff(&xdp, PAGE_SIZE, &rxq->xdp_rxq);
+	xdp_init_buff(&xdp, PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq);
 
 	while (!((status = fec16_to_cpu(bdp->cbd_sc)) & BD_ENET_RX_EMPTY)) {
 
@@ -1853,7 +1853,8 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 		 * include that when passing upstream as it messes up
 		 * bridging applications.
 		 */
-		skb = build_skb(page_address(page), PAGE_SIZE);
+		skb = build_skb(page_address(page),
+				PAGE_SIZE << fep->pagepool_order);
 		if (unlikely(!skb)) {
 			page_pool_recycle_direct(rxq->page_pool, page);
 			ndev->stats.rx_dropped++;
@@ -4562,6 +4563,7 @@ fec_probe(struct platform_device *pdev)
 	fec_enet_clk_enable(ndev, false);
 	pinctrl_pm_select_sleep_state(&pdev->dev);
 
+	fep->pagepool_order = 0;
 	fep->max_buf_size = PKT_MAXBUF_SIZE;
 	ndev->max_mtu = fep->max_buf_size - ETH_HLEN - ETH_FCS_LEN;
 
Signature · 1 line
2.43.0
author reviewer
#3 lore raw

PATCH v7 3/6 net: fec: update MAX_FL based on the current MTU

In reply to Shenwei Wang

Configure the MAX_FL (Maximum Frame Length) register according to the current MTU value, which ensures that packets exceeding the configured MTU trigger an RX error.

---
 drivers/net/ethernet/freescale/fec_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/freescale/fec_main.c +1 -1
index 5fb9afdafec4..c37ac84ab956 100644
@@ -1149,7 +1149,7 @@ fec_restart(struct net_device *ndev)
 	u32 rcntl = FEC_RCR_MII;
 
 	if (OPT_ARCH_HAS_MAX_FL)
-		rcntl |= fep->max_buf_size << 16;
+		rcntl |= (fep->netdev->mtu + ETH_HLEN + ETH_FCS_LEN) << 16;
 
 	if (fep->bufdesc_ex)
 		fec_ptp_save_state(fep);

--
2.43.0

author reviewer
#4 lore raw

PATCH v7 4/6 net: fec: add rx_frame_size to support configurable RX length

In reply to Shenwei Wang

Add a new rx_frame_size member in the fec_enet_private structure to track the RX buffer size. On the Jumbo frame enabled system, the value will be recalculated whenever the MTU is updated, allowing the driver to allocate RX buffer efficiently.

Configure the TRUNC_FL (Frame Truncation Length) based on the smaller value between max_buf_size and the rx_frame_size to maintain consistent RX error behavior, regardless of whether Jumbo frames are enabled.

---
 drivers/net/ethernet/freescale/fec.h      | 1 +
 drivers/net/ethernet/freescale/fec_main.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/fec.h +1 -0
index 47317346b2f3..f1032a11aa76 100644
@@ -621,6 +621,7 @@ struct fec_enet_private {
 	unsigned int total_rx_ring_size;
 	unsigned int max_buf_size;
 	unsigned int pagepool_order;
+	unsigned int rx_frame_size;
 
 	struct	platform_device *pdev;
 
drivers/net/ethernet/freescale/fec_main.c +2 -1
index c37ac84ab956..96322187a220 100644
@@ -1194,7 +1194,7 @@ fec_restart(struct net_device *ndev)
 		else
 			val &= ~FEC_RACC_OPTIONS;
 		writel(val, fep->hwp + FEC_RACC);
-		writel(fep->max_buf_size, fep->hwp + FEC_FTRL);
+		writel(min(fep->rx_frame_size, fep->max_buf_size), fep->hwp + FEC_FTRL);
 	}
 #endif
 
@@ -4564,6 +4564,7 @@ fec_probe(struct platform_device *pdev)
 	pinctrl_pm_select_sleep_state(&pdev->dev);
 
 	fep->pagepool_order = 0;
+	fep->rx_frame_size = FEC_ENET_RX_FRSIZE;
 	fep->max_buf_size = PKT_MAXBUF_SIZE;
 	ndev->max_mtu = fep->max_buf_size - ETH_HLEN - ETH_FCS_LEN;
 

--
2.43.0

author reviewer
#5 lore raw

PATCH v7 5/6 net: fec: add change_mtu to support dynamic buffer allocation

In reply to Shenwei Wang

Add a fec_change_mtu() handler to recalculate the pagepool_order based on the new_mtu value. And update the rx_frame_size accordingly when pagepool_order changes.

MTU changes are only allowed when the adater is not running.

---
 drivers/net/ethernet/freescale/fec.h      |  5 +++--
 drivers/net/ethernet/freescale/fec_main.c | 22 ++++++++++++++++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/fec.h +3 -2
index f1032a11aa76..0127cfa5529f 100644
@@ -348,10 +348,11 @@ struct bufdesc_ex {
  * the skbuffer directly.
  */
 
+#define FEC_DRV_RESERVE_SPACE (XDP_PACKET_HEADROOM + \
+		SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
 #define FEC_ENET_XDP_HEADROOM	(XDP_PACKET_HEADROOM)
 #define FEC_ENET_RX_PAGES	256
-#define FEC_ENET_RX_FRSIZE	(PAGE_SIZE - FEC_ENET_XDP_HEADROOM \
-		- SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+#define FEC_ENET_RX_FRSIZE	(PAGE_SIZE - FEC_DRV_RESERVE_SPACE)
 #define FEC_ENET_RX_FRPPG	(PAGE_SIZE / FEC_ENET_RX_FRSIZE)
 #define RX_RING_SIZE		(FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
 #define FEC_ENET_TX_FRSIZE	2048
drivers/net/ethernet/freescale/fec_main.c +20 -2
index 96322187a220..7d336d1b2c00 100644
@@ -470,14 +470,14 @@ fec_enet_create_page_pool(struct fec_enet_private *fep,
 {
 	struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
 	struct page_pool_params pp_params = {
-		.order = 0,
+		.order = fep->pagepool_order,
 		.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
 		.pool_size = size,
 		.nid = dev_to_node(&fep->pdev->dev),
 		.dev = &fep->pdev->dev,
 		.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
 		.offset = FEC_ENET_XDP_HEADROOM,
-		.max_len = FEC_ENET_RX_FRSIZE,
+		.max_len = fep->rx_frame_size,
 	};
 	int err;
 
@@ -4024,6 +4024,23 @@ static int fec_hwtstamp_set(struct net_device *ndev,
 	return fec_ptp_set(ndev, config, extack);
 }
 
+static int fec_change_mtu(struct net_device *ndev, int new_mtu)
+{
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	int order;
+
+	if (netif_running(ndev))
+		return -EBUSY;
+
+	order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN
+			  + FEC_DRV_RESERVE_SPACE);
+	fep->rx_frame_size = (PAGE_SIZE << order) - FEC_DRV_RESERVE_SPACE;
+	fep->pagepool_order = order;
+	WRITE_ONCE(ndev->mtu, new_mtu);
+
+	return 0;
+}
+
 static const struct net_device_ops fec_netdev_ops = {
 	.ndo_open		= fec_enet_open,
 	.ndo_stop		= fec_enet_close,
@@ -4033,6 +4050,7 @@ static const struct net_device_ops fec_netdev_ops = {
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_tx_timeout		= fec_timeout,
 	.ndo_set_mac_address	= fec_set_mac_address,
+	.ndo_change_mtu		= fec_change_mtu,
 	.ndo_eth_ioctl		= phy_do_ioctl_running,
 	.ndo_set_features	= fec_set_features,
 	.ndo_bpf		= fec_enet_bpf,

--
2.43.0

author reviewer
#6 lore raw

PATCH v7 6/6 net: fec: enable the Jumbo frame support for i.MX8QM

In reply to Shenwei Wang

Certain i.MX SoCs, such as i.MX8QM and i.MX8QXP, feature enhanced FEC hardware that supports Ethernet Jumbo frames with packet sizes up to 16K bytes.

When Jumbo frames are supported, the TX FIFO may not be large enough to hold an entire frame. To handle this, the FIFO is configured to operate in cut-through mode when the frame size exceeds (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN), which allows transmission to begin once the FIFO reaches a certain threshold.

---
 drivers/net/ethernet/freescale/fec.h      |  3 +++
 drivers/net/ethernet/freescale/fec_main.c | 25 +++++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/fec.h +3 -0
index 0127cfa5529f..41e0d85d15da 100644
@@ -514,6 +514,9 @@ struct bufdesc_ex {
  */
 #define FEC_QUIRK_HAS_MDIO_C45		BIT(24)
 
+/* Jumbo Frame support */
+#define FEC_QUIRK_JUMBO_FRAME		BIT(25)
+
 struct bufdesc_prop {
 	int qid;
 	/* Address of Rx and Tx buffers */
drivers/net/ethernet/freescale/fec_main.c +21 -4
index 7d336d1b2c00..78b0ce862281 100644
@@ -167,7 +167,8 @@ static const struct fec_devinfo fec_imx8qm_info = {
 		  FEC_QUIRK_ERR007885 | FEC_QUIRK_BUG_CAPTURE |
 		  FEC_QUIRK_HAS_RACC | FEC_QUIRK_HAS_COALESCE |
 		  FEC_QUIRK_CLEAR_SETUP_MII | FEC_QUIRK_HAS_MULTI_QUEUES |
-		  FEC_QUIRK_DELAYED_CLKS_SUPPORT | FEC_QUIRK_HAS_MDIO_C45,
+		  FEC_QUIRK_DELAYED_CLKS_SUPPORT | FEC_QUIRK_HAS_MDIO_C45 |
+		  FEC_QUIRK_JUMBO_FRAME,
 };
 
 static const struct fec_devinfo fec_s32v234_info = {
@@ -233,6 +234,7 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
  * 2048 byte skbufs are allocated. However, alignment requirements
  * varies between FEC variants. Worst case is 64, so round down by 64.
  */
+#define MAX_JUMBO_BUF_SIZE	(round_down(16384 - FEC_DRV_RESERVE_SPACE - 64, 64))
 #define PKT_MAXBUF_SIZE		(round_down(2048 - 64, 64))
 #define PKT_MINBUF_SIZE		64
 
@@ -1281,8 +1283,18 @@ fec_restart(struct net_device *ndev)
 	if (fep->quirks & FEC_QUIRK_ENET_MAC) {
 		/* enable ENET endian swap */
 		ecntl |= FEC_ECR_BYTESWP;
-		/* enable ENET store and forward mode */
-		writel(FEC_TXWMRK_STRFWD, fep->hwp + FEC_X_WMRK);
+
+		/* When Jumbo Frame is enabled, the FIFO may not be large enough
+		 * to hold an entire frame. In such cases, if the MTU exceeds
+		 * (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN), configure the interface
+		 * to operate in cut-through mode, triggered by the FIFO threshold.
+		 * Otherwise, enable the ENET store-and-forward mode.
+		 */
+		if ((fep->quirks & FEC_QUIRK_JUMBO_FRAME) &&
+		    (ndev->mtu > (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN)))
+			writel(0xF, fep->hwp + FEC_X_WMRK);
+		else
+			writel(FEC_TXWMRK_STRFWD, fep->hwp + FEC_X_WMRK);
 	}
 
 	if (fep->bufdesc_ex)
@@ -4583,7 +4595,12 @@ fec_probe(struct platform_device *pdev)
 
 	fep->pagepool_order = 0;
 	fep->rx_frame_size = FEC_ENET_RX_FRSIZE;
-	fep->max_buf_size = PKT_MAXBUF_SIZE;
+
+	if (fep->quirks & FEC_QUIRK_JUMBO_FRAME)
+		fep->max_buf_size = MAX_JUMBO_BUF_SIZE;
+	else
+		fep->max_buf_size = PKT_MAXBUF_SIZE;
+
 	ndev->max_mtu = fep->max_buf_size - ETH_HLEN - ETH_FCS_LEN;
 
 	ret = register_netdev(ndev);

--
2.43.0

#7 lore raw
In reply to Shenwei Wang
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 10 Sep 2025 13:52:05 -0500 you wrote:

Changes in v7:
- replaced #ifdef with if statement per Jakub's suggestion.

Changes in v6:
- address the comments from Frank and Jakub.
- only allow changing mtu when the adaptor is not running, simplifying the configuration logic.

[...]

Here is the summary with links:
- [v7,net-next,1/6] net: fec: use a member variable for maximum buffer size

    https://git.kernel.org/netdev/net-next/c/ec2a1681ed4f
  - [v7,net-next,2/6] net: fec: add pagepool_order to support variable page size
    https://git.kernel.org/netdev/net-next/c/29e6d5f89e48
  - [v7,net-next,3/6] net: fec: update MAX_FL based on the current MTU
    https://git.kernel.org/netdev/net-next/c/62b5bb7be7bc

- [v7,net-next,4/6] net: fec: add rx_frame_size to support configurable RX length (no matching commit)
- [v7,net-next,5/6] net: fec: add change_mtu to support dynamic buffer allocation (no matching commit)
- [v7,net-next,6/6] net: fec: enable the Jumbo frame support for i.MX8QM (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html