From: Frank Li <Frank.li@nxp.com>
To: Wei Fang <wei.fang@nxp.com>
Cc: shenwei.wang@nxp.com, xiaoning.wang@nxp.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
bpf@vger.kernel.org
Subject: Re: [PATCH v2 net-next 14/14] net: fec: add AF_XDP zero-copy support
Date: Fri, 16 Jan 2026 09:47:47 -0500 [thread overview]
Message-ID: <aWpPk6PrHuL+zdMr@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260116074027.1603841-15-wei.fang@nxp.com>
On Fri, Jan 16, 2026 at 03:40:27PM +0800, Wei Fang wrote:
> Add AF_XDP zero-copy support for both TX and RX.
>
> For RX, instead of allocating buffers from the page pool, the buffers
> are allocated from xsk pool, so fec_alloc_rxq_buffers_zc() is added to
> allocate RX buffers from xsk pool. And fec_enet_rx_queue_xsk() is used
> to process the frames from the RX queue which is bound to the AF_XDP
> socket. Similar to the XDP copy mode, the zero-copy mode also supports
> XDP_TX, XDP_PASS, XDP_DROP and XDP_REDIRECT actions. In addition,
> fec_enet_xsk_tx_xmit() is similar to fec_enet_xdp_tx_xmit() and is used
> to handle XDP_TX action in zero-copy mode.
>
> For TX, there are two cases, one is the frames from the AF_XDP socket,
> so fec_enet_xsk_xmit() is added to directly transmit the frames from
> the socket and the buffer type is marked as FEC_TXBUF_T_XSK_XMIT. The
> other one is the frams from the RX queue (XDP_TX action), the buffer
> type is marked as FEC_TXBUF_T_XSK_TX. Therefore, fec_enet_tx_queue()
> could correctly clean the TX queue base on the buffer type.
>
> Also, some tests have been done on the i.MX93-EVK board with the xdpsock
> tool, the following are the results.
>
> Env: i.MX93 connects to a packet generator, the link speed is 1Gbps, and
> flow-control is off. The RX packet size is 64 bytes including FCS. Only
> one RX queue (CPU) is used to receive frames.
>
> 1. MAC swap L2 forwarding
> 1.1 Zero-copy mode
> root@imx93evk:~# ./xdpsock -i eth0 -l -z
> sock0@eth0:0 l2fwd xdp-drv
> pps pkts 1.00
> rx 414715 415455
> tx 414715 415455
>
> 1.2 Copy mode
> root@imx93evk:~# ./xdpsock -i eth0 -l -c
> sock0@eth0:0 l2fwd xdp-drv
> pps pkts 1.00
> rx 356396 356609
> tx 356396 356609
>
> 2. TX only
> 2.1 Zero-copy mode
> root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -z
> sock0@eth0:0 txonly xdp-drv
> pps pkts 1.00
> rx 0 0
> tx 1119573 1126720
>
> 2.2 Copy mode
> root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -c
> sock0@eth0:0 txonly xdp-drv
> pps pkts 1.00
> rx 0 0
> tx 406864 407616
>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
> ---
> drivers/net/ethernet/freescale/fec.h | 13 +-
> drivers/net/ethernet/freescale/fec_main.c | 611 ++++++++++++++++++++--
> 2 files changed, 582 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
> index ad7aba1a8536..7176803146f3 100644
> --- a/drivers/net/ethernet/freescale/fec.h
> +++ b/drivers/net/ethernet/freescale/fec.h
...
> static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf)
> {
> struct fec_enet_private *fep = netdev_priv(dev);
> bool is_run = netif_running(dev);
> struct bpf_prog *old_prog;
>
> + /* No need to support the SoCs that require to do the frame swap
> + * because the performance wouldn't be better than the skb mode.
> + */
> + if (fep->quirks & FEC_QUIRK_SWAP_FRAME)
> + return -EOPNOTSUPP;
> +
> switch (bpf->command) {
> case XDP_SETUP_PROG:
> - /* No need to support the SoCs that require to
> - * do the frame swap because the performance wouldn't be
> - * better than the skb mode.
> - */
> - if (fep->quirks & FEC_QUIRK_SWAP_FRAME)
> - return -EOPNOTSUPP;
> -
This part can be new patch.
Code itself look good, but I am not familar XDP's logic.
Frank
> if (!bpf->prog)
> xdp_features_clear_redirect_target(dev);
>
> @@ -3994,7 +4497,8 @@ static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf)
> return 0;
>
> case XDP_SETUP_XSK_POOL:
> - return -EOPNOTSUPP;
> + return fec_setup_xsk_pool(dev, bpf->xsk.pool,
> + bpf->xsk.queue_id);
>
> default:
> return -EOPNOTSUPP;
> @@ -4143,6 +4647,29 @@ static int fec_enet_xdp_xmit(struct net_device *dev,
> return sent_frames;
> }
>
> +static int fec_enet_xsk_wakeup(struct net_device *ndev, u32 queue, u32 flags)
> +{
> + struct fec_enet_private *fep = netdev_priv(ndev);
> + struct fec_enet_priv_rx_q *rxq;
> +
> + if (!netif_running(ndev) || !netif_carrier_ok(ndev))
> + return -ENETDOWN;
> +
> + if (queue >= fep->num_rx_queues || queue >= fep->num_tx_queues)
> + return -ERANGE;
> +
> + rxq = fep->rx_queue[queue];
> + if (!rxq->xsk_pool)
> + return -EINVAL;
> +
> + if (!napi_if_scheduled_mark_missed(&fep->napi)) {
> + if (likely(napi_schedule_prep(&fep->napi)))
> + __napi_schedule(&fep->napi);
> + }
> +
> + return 0;
> +}
> +
> static int fec_hwtstamp_get(struct net_device *ndev,
> struct kernel_hwtstamp_config *config)
> {
> @@ -4205,6 +4732,7 @@ static const struct net_device_ops fec_netdev_ops = {
> .ndo_set_features = fec_set_features,
> .ndo_bpf = fec_enet_bpf,
> .ndo_xdp_xmit = fec_enet_xdp_xmit,
> + .ndo_xsk_wakeup = fec_enet_xsk_wakeup,
> .ndo_hwtstamp_get = fec_hwtstamp_get,
> .ndo_hwtstamp_set = fec_hwtstamp_set,
> };
> @@ -4332,7 +4860,8 @@ static int fec_enet_init(struct net_device *ndev)
>
> if (!(fep->quirks & FEC_QUIRK_SWAP_FRAME))
> ndev->xdp_features = NETDEV_XDP_ACT_BASIC |
> - NETDEV_XDP_ACT_REDIRECT;
> + NETDEV_XDP_ACT_REDIRECT |
> + NETDEV_XDP_ACT_XSK_ZEROCOPY;
>
> fec_restart(ndev);
>
> --
> 2.34.1
>
prev parent reply other threads:[~2026-01-16 14:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-16 7:40 [PATCH v2 net-next 00/14] net: fec: improve XDP copy mode and add AF_XDP zero-copy support Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 01/14] net: fec: add fec_txq_trigger_xmit() helper Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 02/14] net: fec: add fec_rx_error_check() to check RX errors Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 03/14] net: fec: add rx_shift to indicate the extra bytes padded in front of RX frame Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 04/14] net: fec: add fec_build_skb() to build a skb Wei Fang
2026-01-16 14:01 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 05/14] net: fec: improve fec_enet_rx_queue() Wei Fang
2026-01-16 14:03 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 06/14] net: fec: add fec_enet_rx_queue_xdp() for XDP path Wei Fang
2026-01-16 14:19 ` Frank Li
2026-01-17 2:32 ` Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 07/14] net: fec: transmit XDP frames in bulk Wei Fang
2026-01-16 14:04 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 08/14] net: fec: remove unnecessary NULL pointer check when clearing TX BD ring Wei Fang
2026-01-16 14:21 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 09/14] net: fec: use switch statement to check the type of tx_buf Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 10/14] net: fec: remove the size parameter from fec_enet_create_page_pool() Wei Fang
2026-01-16 14:26 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 11/14] net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool() Wei Fang
2026-01-16 14:34 ` Frank Li
2026-01-20 6:39 ` Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 12/14] net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pool Wei Fang
2026-01-16 14:38 ` Frank Li
2026-01-17 2:16 ` Wei Fang
2026-01-20 7:30 ` Wei Fang
2026-01-16 7:40 ` [PATCH v2 net-next 13/14] net: fec: improve fec_enet_tx_queue() Wei Fang
2026-01-16 14:40 ` Frank Li
2026-01-16 7:40 ` [PATCH v2 net-next 14/14] net: fec: add AF_XDP zero-copy support Wei Fang
2026-01-16 12:28 ` kernel test robot
2026-01-16 14:47 ` Frank Li [this message]
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=aWpPk6PrHuL+zdMr@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bpf@vger.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-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shenwei.wang@nxp.com \
--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