netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shenwei Wang <shenwei.wang@nxp.com>
To: Wei Fang <wei.fang@nxp.com>, Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>
Cc: Shenwei Wang <shenwei.wang@nxp.com>,
	Clark Wang <xiaoning.wang@nxp.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	imx@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-imx@nxp.com
Subject: [PATCH v2 net-next 4/5] net: fec: add change_mtu to support dynamic buffer allocation
Date: Thu, 21 Aug 2025 13:33:35 -0500	[thread overview]
Message-ID: <20250821183336.1063783-5-shenwei.wang@nxp.com> (raw)
In-Reply-To: <20250821183336.1063783-1-shenwei.wang@nxp.com>

Add a fec_change_mtu() handler to recalculate the pagepool_order based
on the new_mtu value. It will update the rx_frame_size accordingly if
the pagepool_order is changed.

If the interface is running, it stops RX/TX, and recreate the pagepool
with the new configuration.

Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
---
 drivers/net/ethernet/freescale/fec_main.c | 44 +++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 6d0d97bb077c..aa85a6d0b44f 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4023,6 +4023,49 @@ 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, done;
+	bool running;
+
+	order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN);
+	if (fep->pagepool_order == order) {
+		WRITE_ONCE(ndev->mtu, new_mtu);
+		return 0;
+	}
+
+	fep->pagepool_order = order;
+	fep->rx_frame_size = (PAGE_SIZE << order) - FEC_ENET_XDP_HEADROOM
+			     - SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+
+	running = netif_running(ndev);
+	if (!running) {
+		WRITE_ONCE(ndev->mtu, new_mtu);
+		return 0;
+	}
+
+	/* Stop TX/RX and free the buffers */
+	napi_disable(&fep->napi);
+	netif_tx_disable(ndev);
+	read_poll_timeout(fec_enet_rx_napi, done, (done == 0),
+			  10, 1000, false, &fep->napi, 10);
+	fec_stop(ndev);
+	fec_enet_free_buffers(ndev);
+
+	WRITE_ONCE(ndev->mtu, new_mtu);
+
+	/* Create the pagepool according the new mtu */
+	if (fec_enet_alloc_buffers(ndev) < 0)
+		return -ENOMEM;
+
+	fec_restart(ndev);
+	napi_enable(&fep->napi);
+	netif_tx_start_all_queues(ndev);
+
+	return 0;
+}
+
 static const struct net_device_ops fec_netdev_ops = {
 	.ndo_open		= fec_enet_open,
 	.ndo_stop		= fec_enet_close,
@@ -4032,6 +4075,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


  parent reply	other threads:[~2025-08-21 18:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 18:33 [PATCH v2 net-next 0/5] net: fec: add the Jumbo frame support Shenwei Wang
2025-08-21 18:33 ` [PATCH v2 net-next 1/5] net: fec: use a member variable for maximum buffer size Shenwei Wang
2025-08-21 18:55   ` Andrew Lunn
2025-08-21 19:31     ` Shenwei Wang
2025-08-21 20:54     ` Shenwei Wang
2025-08-22  8:01   ` Wei Fang
2025-08-21 18:33 ` [PATCH v2 net-next 2/5] net: fec: add pagepool_order to support variable page size Shenwei Wang
2025-08-21 18:33 ` [PATCH v2 net-next 3/5] et: fec: add rx_frame_size to support configurable RX length Shenwei Wang
2025-08-22  8:14   ` Wei Fang
2025-08-22 10:09   ` Wei Fang
2025-08-22 13:33     ` Shenwei Wang
2025-08-25  2:26       ` Wei Fang
2025-08-25 12:38         ` Shenwei Wang
2025-08-26  1:43           ` Wei Fang
2025-08-21 18:33 ` Shenwei Wang [this message]
2025-08-22  8:44   ` [PATCH v2 net-next 4/5] net: fec: add change_mtu to support dynamic buffer allocation Wei Fang
2025-08-23 17:57     ` Shenwei Wang
2025-08-25  1:36       ` Wei Fang
2025-08-22  9:48   ` Wei Fang
2025-08-23 18:38     ` Shenwei Wang
2025-08-25  2:13       ` Wei Fang
2025-08-25 12:34         ` Shenwei Wang
2025-08-26  2:34           ` Wei Fang
2025-08-21 18:33 ` [PATCH v2 net-next 5/5] net: fec: enable the Jumbo frame support for i.MX8QM Shenwei Wang
2025-08-22  9:23   ` Wei Fang

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=20250821183336.1063783-5-shenwei.wang@nxp.com \
    --to=shenwei.wang@nxp.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=wei.fang@nxp.com \
    --cc=xiaoning.wang@nxp.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).