e1000e: add XDP support
Subsystems (4)
v3 cover e1000e: add XDP support
Add XDP support to e1000e driver. First patch adds basic XDP support, while the second one adds support for AF_XDP.
Tested on an Intel 82574L Gigabit card with xdp-bench and xdp-trafficgen
v2: added a missing 'select PAGE_POOL' which triggered a build failure with some configurations.
v3: removed a leftover file.
Matteo Croce (2):
e1000e: add basic XDP support
e1000e: add XDP_REDIRECT support
drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/e1000e/e1000.h | 18 +- drivers/net/ethernet/intel/e1000e/netdev.c | 600 ++++++++++++++++++++- 3 files changed, 607 insertions(+), 12 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/2 e1000e: add basic XDP support
Add XDP support to the e1000e driver covering the actions defined byNETDEV_XDP_ACT_BASIC: XDP_DROP, XDP_PASS, XDP_TX and XDP_ABORTED.
Infrastructure:
- e1000_xdp_setup() / e1000_xdp() for program attach/detach with MTU validation and close/open cycle
- ndo_bpf support in net_device_ops
- xdp_rxq_info registration in setup/free_rx_resources
Receive path:
- e1000_alloc_rx_buffers_xdp() for page-based Rx buffer allocation with XDP_PACKET_HEADROOM
- e1000_clean_rx_irq_xdp() as the XDP receive handler
- e1000_run_xdp() to execute the XDP program on received packets
- SKB building via napi_build_skb() for XDP_PASS with metadata, checksum offload and RSS hash support
Transmit path:
- e1000_xdp_xmit_ring() to DMA-map and enqueue an XDP frame
- e1000_xdp_xmit_back() to convert an xdp_buff to a frame and send it
- e1000_finalize_xdp() to flush the TX ring after XDP processing
- TX completion via xdp_return_frame() with buffer type tracking
--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/e1000e/e1000.h | 18 +- drivers/net/ethernet/intel/e1000e/netdev.c | 523 ++++++++++++++++++++- 3 files changed, 530 insertions(+), 12 deletions(-)
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -63,6 +63,7 @@ config E1000E depends on PCI && (!SPARC32 || BROKEN) depends on PTP_1588_CLOCK_OPTIONAL select CRC32 + select PAGE_POOL help This driver supports the PCI-Express Intel(R) PRO/1000 gigabit ethernet family of adapters. For PCI or PCI-X e1000 adapters,
drivers/net/ethernet/intel/e1000e/e1000.h +17 -1
@@ -19,10 +19,13 @@#include <linux/net_tstamp.h> #include <linux/ptp_clock_kernel.h> #include <linux/ptp_classify.h> +#include <linux/bpf.h> #include <linux/mii.h> #include <linux/mdio.h> #include <linux/mutex.h> #include <linux/pm_qos.h> +#include <net/page_pool/helpers.h> +#include <net/xdp.h> #include "hw.h" struct e1000_info ;
@@ -126,12 +129,21 @@ struct e1000_ps_page {u64 dma;/* must be u64 - written to hw */ }; +enum e1000_tx_buf_type { +E1000_TX_BUF_SKB =0 , +E1000_TX_BUF_XDP , +}; +/* wrappers around a pointer to a socket buffer, * so a DMA handle can be stored along with the buffer */ struct e1000_buffer { dma_addr_t dma; - struct sk_buff *skb; + union { + struct sk_buff *skb; + struct xdp_frame *xdpf; + }; + enum e1000_tx_buf_type type; union { /* Tx */ struct {
@@ -259,6 +271,10 @@ struct e1000_adapter { gfp_t gfp);struct e1000_ring *rx_ring; +struct bpf_prog *xdp_prog; +struct xdp_rxq_info xdp_rxq; +struct page_pool *page_pool; +u32 rx_int_delay;u32 rx_abs_int_delay;
drivers/net/ethernet/intel/e1000e/netdev.c +512 -11
627 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH net-next v3 1/2] e1000e: add basic XDP support
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, · line 736
Quoted 10 lines
+ *
e1000_xdp_xmit_ring- transmit an XDP frame on the TX ring
+ * @adapter: board private structure
+ * @tx_ring: Tx descriptor ring
+ * @xdpf: XDP frame to transmit
+ *
+ * ReturnsE1000_XDP_TXon success,E1000_XDP_CONSUMEDon failure
+ **/drivers/net/ethernet/intel/e1000e/netdev.c +2
-0+static int e1000_xdp_xmit_ring(struct e1000_adapter *adapter, + struct e1000_ring *tx_ring,
minor nit: alignment issue
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, · line 1002
Quoted 12 lines
drivers/net/ethernet/intel/e1000e/netdev.c +12
-0+if (unlikely ((staterr &E1000_RXDEXT_ERR_FRAME_ERR_MASK ) && + !(netdev->features &NETIF_F_RXALL ))) { +page_pool_put_full_page (adapter->page_pool, + buffer_info->page, true); + buffer_info->page =NULL ; + goto next_desc; + } + +/* adjust length to remove Ethernet CRC */ +if (!(adapter->flags2 &FLAG2_CRC_STRIPPING )) { +if (netdev->features &NETIF_F_RXFCS ) + total_rx_bytes -=4 ;
Looks like, total_rx_bytes can go negative here since it is not updated after being initialized to 0. Is this expected?
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, · line 905
Quoted 7 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-7-static inline void e1000_rx_hash (struct net_device *netdev,__le32 rss, -struct sk_buff *skb) -{ -if (netdev->features &NETIF_F_RXHASH ) -skb_set_hash (skb,le32_to_cpu (rss),PKT_HASH_TYPE_L3 ); -} -
The function was just moved. Looks like an unrelated change?
Quoted 36 lines
drivers/net/ethernet/intel/e1000e/netdev.c +36
-0+/** +* e1000_xdp_setup - add/remove an XDP program +* @netdev: network interface device structure +* @bpf: XDP program setup structure +**/ +static int e1000_xdp_setup (struct net_device *netdev,struct netdev_bpf *bpf) +{ +struct e1000_adapter *adapter =netdev_priv (netdev); +struct bpf_prog *prog = bpf->prog, *old_prog; +bool running =netif_running (netdev); +bool need_reset; + +/* XDP is incompatible with jumbo frames */ +if (prog && netdev->mtu >ETH_DATA_LEN ) { +NL_SET_ERR_MSG_MOD (bpf->extack, +"XDP is not supported with jumbo frames" ); +return -EINVAL ; + } + +/* Validate frame fits in a single page with XDP headroom */ +if (prog && netdev->mtu +VLAN_ETH_HLEN +ETH_FCS_LEN + +XDP_PACKET_HEADROOM >PAGE_SIZE ) { +NL_SET_ERR_MSG_MOD (bpf->extack, +"Frame size too large for XDP" ); +return -EINVAL ; + } + + old_prog =xchg (&adapter->xdp_prog, prog); + need_reset = (!!prog != !!old_prog); + +/* Transition between XDP and non-XDP requires ring reconfiguration */ +if (need_reset && running) +e1000e_close (netdev); + +if (old_prog) +bpf_prog_put (old_prog);
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_set_features(struct net_device *netdev, · line 7819
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +10
-0+ +if (!need_reset) +return 0 ; + +if (running) +e1000e_open (netdev); + +return 0 ; +} +
If I am reading it correctly, this can be problematic (maybe with very small likelihood). If e1000e_open() fails here, we will still return success. How about the following?
if (running) {
int err = e1000e_open(netdev);
if (err) {
/* Remove the XDP program since interface is down */
xchg(&adapter->xdp_prog, NULL);
return err;
}
}Re: [PATCH net-next v3 1/2] e1000e: add basic XDP support
Il giorno ven 20 mar 2026 alle ore 22:23 Mohsin Bashir <[email protected]> ha scritto:
Quoted 11 lines
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, · line 736
Quoted 11 lines
+ *
e1000_xdp_xmit_ring- transmit an XDP frame on the TX ring
+ * @adapter: board private structure
+ * @tx_ring: Tx descriptor ring
+ * @xdpf: XDP frame to transmit
+ *
+ * ReturnsE1000_XDP_TXon success,E1000_XDP_CONSUMEDon failure
+ **/drivers/net/ethernet/intel/e1000e/netdev.c +2
-0+static int e1000_xdp_xmit_ring(struct e1000_adapter *adapter, + struct e1000_ring *tx_ring,
Quoted 2 lines
minor nit: alignment issue
Uh funny that checkpatch.pl doesn't notice it.
Quoted 13 lines
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, · line 1002
Quoted 12 lines
drivers/net/ethernet/intel/e1000e/netdev.c +12
-0+if (unlikely ((staterr &E1000_RXDEXT_ERR_FRAME_ERR_MASK ) && + !(netdev->features &NETIF_F_RXALL ))) { +page_pool_put_full_page (adapter->page_pool, + buffer_info->page, true); + buffer_info->page =NULL ; + goto next_desc; + } + +/* adjust length to remove Ethernet CRC */ +if (!(adapter->flags2 &FLAG2_CRC_STRIPPING )) { +if (netdev->features &NETIF_F_RXFCS ) + total_rx_bytes -=4 ;
Quoted 3 lines
Looks like,
total_rx_bytescan go negative here since it is not updated after being initialized to 0. Is this expected?
No, that's a bug. I'll count the crc size separately and take care of it.
Quoted 62 lines
drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, · line 905
Quoted 8 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-7-static inline void e1000_rx_hash (struct net_device *netdev,__le32 rss, -struct sk_buff *skb) -{ -if (netdev->features &NETIF_F_RXHASH ) -skb_set_hash (skb,le32_to_cpu (rss),PKT_HASH_TYPE_L3 ); -} -The function was just moved. Looks like an unrelated change?
Quoted 36 lines
drivers/net/ethernet/intel/e1000e/netdev.c +36
-0+/** +* e1000_xdp_setup - add/remove an XDP program +* @netdev: network interface device structure +* @bpf: XDP program setup structure +**/ +static int e1000_xdp_setup (struct net_device *netdev,struct netdev_bpf *bpf) +{ +struct e1000_adapter *adapter =netdev_priv (netdev); +struct bpf_prog *prog = bpf->prog, *old_prog; +bool running =netif_running (netdev); +bool need_reset; + +/* XDP is incompatible with jumbo frames */ +if (prog && netdev->mtu >ETH_DATA_LEN ) { +NL_SET_ERR_MSG_MOD (bpf->extack, +"XDP is not supported with jumbo frames" ); +return -EINVAL ; + } + +/* Validate frame fits in a single page with XDP headroom */ +if (prog && netdev->mtu +VLAN_ETH_HLEN +ETH_FCS_LEN + +XDP_PACKET_HEADROOM >PAGE_SIZE ) { +NL_SET_ERR_MSG_MOD (bpf->extack, +"Frame size too large for XDP" ); +return -EINVAL ; + } + + old_prog =xchg (&adapter->xdp_prog, prog); + need_reset = (!!prog != !!old_prog); + +/* Transition between XDP and non-XDP requires ring reconfiguration */ +if (need_reset && running) +e1000e_close (netdev); + +if (old_prog) +bpf_prog_put (old_prog);drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_set_features(struct net_device *netdev, · line 7819
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +10
-0+ +if (!need_reset) +return 0 ; + +if (running) +e1000e_open (netdev); + +return 0 ; +} +If I am reading it correctly, this can be problematic (maybe with very small likelihood). If
e1000e_open()fails here, we will still return success. How about the following?
Quoted 11 lines
if (running) {
int err = e1000e_open(netdev);
if (err) {
/* Remove the XDP program since interface is down */
xchg(&adapter->xdp_prog, NULL);
return err;
}
}Makes sense.
I addressed all the comments and I'll send a v4 soon, thanks!
Signature · 3 lines
Matteo Croce
perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplayRe: [PATCH net-next v3 1/2] e1000e: add basic XDP support
Quoted 2 lines · Matteo Croce
Il giorno ven 20 mar 2026 alle ore 22:23 Mohsin Bashir <[email protected]> ha scritto:
[...]
Quoted 1 line
I addressed all the comments and I'll send a v4 soon, thanks!
I was paging through the code last night and I was wondering: have you considered splitting this patch into multiple smaller patches?
It would probably make it easier for reviewers to read and comment on.
Just my 2 cents since you are sending a v4.
Re: [PATCH net-next v3 1/2] e1000e: add basic XDP support
Il giorno mar 24 mar 2026 alle ore 17:41 Joe Damato <[email protected]> ha scritto:
Quoted 7 lines · Matteo Croce
Quoted 2 lines
Il giorno ven 20 mar 2026 alle ore 22:23 Mohsin Bashir <[email protected]> ha scritto:
[...]
Quoted 8 lines
Quoted 1 line
I addressed all the comments and I'll send a v4 soon, thanks!
I was paging through the code last night and I was wondering: have you considered splitting this patch into multiple smaller patches?
It would probably make it easier for reviewers to read and comment on.
Just my 2 cents since you are sending a v4.
I thought that all features included in NETDEV_XDP_ACT_BASIC must be submitted in a single commit.
Signature · 3 lines
Matteo Croce
perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplayPATCH v3 2/2 e1000e: add XDP_REDIRECT support
In reply to Matteo CroceAdd the ability to redirect packets to other devices via XDP_REDIRECT and to receive redirected frames from other devices via ndo_xdp_xmit.
New functionality:
- XDP_REDIRECT case in e1000_run_xdp() using xdp_do_redirect()
- e1000_xdp_xmit() as the ndo_xdp_xmit callback for receiving redirected frames from other devices
- xdp_do_flush() in e1000_finalize_xdp() for REDIR completions
- xdp_features_set/clear_redirect_target() in e1000_xdp_setup()
- NETDEV_XDP_ACT_REDIRECT and NETDEV_XDP_ACT_NDO_XMIT advertised
--- drivers/net/ethernet/intel/e1000e/netdev.c | 85 +++++++++++++++++++++- 1 file changed, 81 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +81 -4
@@ -41,6 +41,7 @@ char e1000e_driver_name[] = "e1000e";#define E1000_XDP_PASS 0#define E1000_XDP_CONSUMED BIT(0)#define E1000_XDP_TX BIT(1) +#define E1000_XDP_REDIR BIT(2)static int debug =-1 ;module_param (debug, int,0 );
@@ -805,6 +806,9 @@ static void e1000_finalize_xdp(struct e1000_adapter *adapter, {struct e1000_ring *tx_ring = adapter->tx_ring; +if (xdp_xmit &E1000_XDP_REDIR ) +xdp_do_flush (); +if (xdp_xmit &E1000_XDP_TX ) {/* Force memory writes to complete before letting h/w * know there are new descriptors to fetch.
@@ -823,13 +827,14 @@ static void e1000_finalize_xdp(struct e1000_adapter *adapter,* @adapter: board private structure * @xdp: XDP buffer containing packet data * -* Returns E1000_XDP_PASS, E1000_XDP_TX, or E1000_XDP_CONSUMED +* Returns E1000_XDP_PASS, E1000_XDP_TX, E1000_XDP_REDIR, or E1000_XDP_CONSUMED **/ static int e1000_run_xdp (struct e1000_adapter *adapter,struct xdp_buff *xdp) {struct bpf_prog *xdp_prog =READ_ONCE (adapter->xdp_prog);struct net_device *netdev = adapter->netdev;int result =E1000_XDP_PASS ; +int err;u32 act;if (!xdp_prog)
@@ -846,6 +851,12 @@ static int e1000_run_xdp(struct e1000_adapter *adapter, struct xdp_buff *xdp)if (result ==E1000_XDP_CONSUMED ) goto out_failure;break ; +case XDP_REDIRECT : + err =xdp_do_redirect (netdev, xdp, xdp_prog); +if (err) + goto out_failure; + result =E1000_XDP_REDIR ; +break ;default :bpf_warn_invalid_xdp_action (netdev, xdp_prog, act); fallthrough;
@@ -1040,11 +1051,11 @@ static bool e1000_clean_rx_irq_xdp(struct e1000_ring *rx_ring, int *work_done,/* page consumed by skb */ buffer_info->page =NULL ; - }else if (xdp_res &E1000_XDP_TX ) { + }else if (xdp_res & (E1000_XDP_TX |E1000_XDP_REDIR )) { xdp_xmit |= xdp_res; total_rx_bytes += length; total_rx_packets++; -/* page consumed by XDP TX */ +/* page consumed by XDP TX/redirect */ buffer_info->page =NULL ; }else {/* XDP_DROP / XDP_ABORTED - recycle page */
@@ -7811,6 +7822,11 @@ static int e1000_xdp_setup(struct net_device *netdev, struct netdev_bpf *bpf)if (!need_reset)return 0 ; +if (prog) +xdp_features_set_redirect_target (netdev, true); +else +xdp_features_clear_redirect_target (netdev); +if (running)e1000e_open (netdev);
@@ -7827,6 +7843,64 @@ static int e1000_xdp(struct net_device *netdev, struct netdev_bpf *xdp) } } +/** +* e1000_xdp_xmit - transmit XDP frames from another device +* @netdev: network interface device structure +* @n: number of frames to transmit +* @frames: array of XDP frame pointers +* @flags: XDP transmit flags +* +* This is the ndo_xdp_xmit callback, called when other devices redirect +* frames to this device. +**/ +static int e1000_xdp_xmit (struct net_device *netdev,int n, +struct xdp_frame **frames,u32 flags) +{ +struct e1000_adapter *adapter =netdev_priv (netdev); +struct e1000_ring *tx_ring = adapter->tx_ring; +struct netdev_queue *nq =netdev_get_tx_queue (netdev,0 ); +int cpu =smp_processor_id (); +int nxmit =0 ; +int i; + +if (unlikely (test_bit (__E1000_DOWN, &adapter->state))) +return -ENETDOWN ; + +if (unlikely (flags & ~XDP_XMIT_FLAGS_MASK )) +return -EINVAL ; + +if (!adapter->xdp_prog) +return -ENXIO ; + +__netif_tx_lock (nq, cpu); +txq_trans_cond_update (nq); + +for (i =0 ; i < n; i++) { +int err; + + err =e1000_xdp_xmit_ring (adapter, tx_ring, frames[i]); +if (err !=E1000_XDP_TX ) +break ; + nxmit++; + } + +if (unlikely (flags &XDP_XMIT_FLUSH )) { +/* Force memory writes to complete before letting h/w +* know there are new descriptors to fetch. +*/ +wmb (); +if (adapter->flags2 &FLAG2_PCIM2PCI_ARBITER_WA ) +e1000e_update_tdt_wa (tx_ring, + tx_ring->next_to_use); +else +writel (tx_ring->next_to_use, tx_ring->tail); + } + +__netif_tx_unlock (nq); + +return nxmit; +} +static const struct net_device_ops e1000e_netdev_ops = { .ndo_open = e1000e_open, .ndo_stop = e1000e_close,
@@ -7850,6 +7924,7 @@ static const struct net_device_ops e1000e_netdev_ops = { .ndo_hwtstamp_get = e1000e_hwtstamp_get, .ndo_hwtstamp_set = e1000e_hwtstamp_set, .ndo_bpf = e1000_xdp, + .ndo_xdp_xmit = e1000_xdp_xmit, };/**
@@ -8060,7 +8135,9 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->max_mtu = adapter->max_hw_frame_size - (VLAN_ETH_HLEN +ETH_FCS_LEN ); - netdev->xdp_features =NETDEV_XDP_ACT_BASIC ; + netdev->xdp_features =NETDEV_XDP_ACT_BASIC | +NETDEV_XDP_ACT_REDIRECT | +NETDEV_XDP_ACT_NDO_XMIT ;if (e1000e_enable_mng_pass_thru (&adapter->hw)) adapter->flags |=FLAG_MNG_PT_ENABLED ;
Signature · 1 line
2.53.0