All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support
@ 2026-12-01  1:15 Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet Satish Kharat
                   ` (11 more replies)
  0 siblings, 12 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

This RFC adds native XDP RX, TX, and redirect, followed by AF_XDP
zero-copy RX and TX, to enic on physical VIC vNICs with mixed RQ
descriptor support. It also adds WQ descriptor ownership and completion
accounting, RX page geometry, queue counters, and an XSK detach selftest.

The driver advertises XDP features only on capable vNICs. It stops RX
before publishing a replacement XDP program, disables RX VLAN stripping
while XDP is active so packet actions see tag bytes, and restores the
requested strip mode on detach. When RX VLAN stripping is disabled for
XDP, receive buffers are sized for a full-MTU packet with two in-band
VLAN tags. XSK bind checks that the frame can hold such a packet even
if XDP is attached later; a bound socket stayed active across that
attach in testing. Partial RQ refill batches are published before RX
wakeup is cleared. RX and TX updates to a shared XSK pool's NEED_WAKEUP
state are serialized. A zero-budget NAPI poll completes only whole
skb-owned WQ CQ spans and defers RX, XDP, and XSK work.

This revision folds a final-XDP-detach ownership and transient-reopen
fix into 08/12. Once a BPF link is released, a failed queue reopen must
not restore its old program. The driver keeps NULL published, releases
its program reference, and retries the reopen once before considering
reset work.

AF_XDP zero-copy XDP_PASS also needs the generic
xdp_build_skb_from_zc() head-sizing fix posted separately by Björn Töpel
as [PATCH net v2 2/4] on 2026-11-30:
https://lore.kernel.org/netdev/20261130123737.125432-3-bjorn@kernel.org/
That patch is a prerequisite for this RFC's AF_XDP path. It is not one
of the 12 patches below; the prerequisite-patch-id at the end of this
cover identifies the exact posted v2 diff. Its upstream merge was not
verified when this candidate was prepared.

LLM assistance was used for design review, code review, and test case
development for this RFC.

Validation:

  - The previous 12-patch RFC tip was built as an enic module for a
    7.4.0-rc2 test kernel and loaded on a VIC 15237 PCI-passthrough vNIC
    (firmware 5.3(4.75)), with a separate hardware peer. Its applicable
    single-buffer IPv4/IPv6 xdp.py cases passed 12/12, covering XDP_PASS,
    XDP_DROP, XDP_TX, and queue statistics. AF_XDP zero-copy TX posted
    and completed 64/64 frames.
  - On E1, a fail-closed guard on the original generic helper recorded
    five would-overruns at 2048-byte UMEM chunks and MTU 1500:
    need=1776, avail=1728. It dropped those packets before the unchecked
    copy. A locally drafted helper fix delivered 5/5 probes with the same
    fixture. That targeted result does not test Björn's exact v2 diff.
  - On E1, the original final BPF-link detach with an injected one-shot
    enic_open() error retained the ENIC-owned program after the link
    disappeared. The ENIC change folded into 08/12 was tested under the
    same fault: the link and program were gone, the direct retry restored
    service, and E1 and E2 each passed 10/10 IPv4 and 10/10 IPv6 probes.
  - This exact candidate, including Björn's posted v2 patch, passed a
    focused CONFIG_WERROR=y object build and a full 7.4.0-rc2 kernel and
    2,590-module build. It booted on the E1 VIC 15237 guest. The first
    applicable native XDP selftest run passed 11/12; qstats.drop_ipv4
    failed in bpftool map selection before traffic because more than one
    map matched its global name. The identical full retry passed 12/12
    single-buffer IPv4/IPv6 PASS, DROP, TX, and qstats cases. The duplicate
    map's owner was not captured, so its cause remains open.
  - A bound zero-copy XSK smoke test on this candidate recorded 151 ENIC
    XSK RX packets and 151 xdp_build_skb_from_zc() calls. The BPF link and
    program disappeared after detach with the socket open; peer IPv4 and
    IPv6 probes passed 3/3 each. The fixture did not consume RX descriptors
    or check their payload and did not test AF_XDP TX. Its undrained fill
    ring produced a large fill-empty count. The dedicated 2048-byte
    near-MTU test of Björn's exact v2 patch remains deferred.
  - After the suite, E1 returned to its saved known-good kernel with native
    Cilium XDP attached; all three nodes and Cilium pods were Ready and
    two-way peer traffic passed. The candidate kernel remains non-default.
  - On the 11-patch precursor, Cilium native load balancing, devmap
    redirect, XSK bind/unbind, program replacement, MTU changes, and
    zero-budget netpoll were exercised. The full Cilium CLI run had an
    intermittent IPv6 timeout and two pre-existing cluster-health
    failures. The native regression suite had two bounded timing
    failures. These broader runs were not repeated after the queue
    statistics and detach fixes.

Persistent reopen failure/reset recovery, deterministic partial-FILL
and NEED_WAKEUP interleavings, mixed XSK/XDP completions in zero-budget
netpoll, pool-bound reset/reload, AF_XDP userspace RX/TX, Cilium service
end-to-end qualification, full 9K QinQ, a real firmware-command failure,
and other VIC families remain untested on this candidate. This
is a request for review of the driver and teardown design, not a claim
of merge readiness or a support announcement.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
Satish Kharat (12):
      net: enic: bound skb TX rollback to current packet
      net: enic: tag work queue descriptor ownership
      net: enic: gate native XDP on mixed RQ descriptor capability
      net: enic: expose per-queue XDP and AF_XDP counters
      net: enic: complete XDP frames by WQ descriptor ownership
      net: enic: reserve XDP head and tailroom in RX pages
      net: enic: publish partial receive descriptor batches
      net: enic: add native XDP RX, TX, and redirect
      net: enic: batch AF_XDP TX completions by pool
      net: enic: add AF_XDP zero-copy RX and TX
      selftests/xsk: exercise XDP detach with bound socket
      net: enic: count XDP and AF_XDP TX in queue statistics

 drivers/net/ethernet/cisco/enic/Makefile         |   3 +-
 drivers/net/ethernet/cisco/enic/enic.h           |  49 ++
 drivers/net/ethernet/cisco/enic/enic_admin.c     |   8 +-
 drivers/net/ethernet/cisco/enic/enic_api.c       |   9 +
 drivers/net/ethernet/cisco/enic/enic_dev.c       |   8 +
 drivers/net/ethernet/cisco/enic/enic_dev.h       |   1 +
 drivers/net/ethernet/cisco/enic/enic_ethtool.c   |  15 +
 drivers/net/ethernet/cisco/enic/enic_main.c      | 755 ++++++++++++++++++++---
 drivers/net/ethernet/cisco/enic/enic_rq.c        |  86 ++-
 drivers/net/ethernet/cisco/enic/enic_wq.c        | 121 +++-
 drivers/net/ethernet/cisco/enic/enic_wq.h        |   2 +-
 drivers/net/ethernet/cisco/enic/enic_xdp.c       | 726 ++++++++++++++++++++++
 drivers/net/ethernet/cisco/enic/enic_xdp.h       |  53 ++
 drivers/net/ethernet/cisco/enic/vnic_dev.c       |  16 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.h       |   2 +
 drivers/net/ethernet/cisco/enic/vnic_enet.h      |   1 +
 drivers/net/ethernet/cisco/enic/vnic_rq.h        |  21 +-
 drivers/net/ethernet/cisco/enic/vnic_wq.h        |  15 +
 tools/testing/selftests/net/lib/xsk/test_xsk.c   |  51 +-
 tools/testing/selftests/net/lib/xsk/test_xsk.h   |   2 +
 tools/testing/selftests/net/lib/xsk/xsk.c        |   4 +-
 tools/testing/selftests/net/lib/xsk/xsk.h        |   2 +-
 tools/testing/selftests/net/lib/xsk/xskxceiver.c |  23 +-
 23 files changed, 1829 insertions(+), 144 deletions(-)
---
base-commit: cf0dd134a16e2e5bb090b385acdbd745d4395807
change-id: 20261130-enic-xdp-rfc-p1-20261130-388b0907802a
prerequisite-patch-id: e90ee2f97349eb5a3bf16169aeeb928a28ec6bf7

Best regards,
--  
Satish Kharat <satishkh@cisco.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 02/12] net: enic: tag work queue descriptor ownership Satish Kharat
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

A DMA mapping failure must unwind only descriptors posted for the
current skb. The old loop stopped at an os_buf marker, but an
outstanding AF_XDP descriptor has no os_buf. Save the producer position
before posting and return to that boundary, restoring one credit per
descriptor. If xmit_more deferred an earlier skb, ring the surviving
producer position before leaving the error path.

Code inspection during shared-WQ AF_XDP work identified this rollback
boundary. A test-only failure after a non-EOP TSO descriptor
exercised rollback with an outstanding XSK descriptor on an E2
VIC 1137:0043 vNIC. With this fix, all 16,000 XSK frames completed
and arrived once, and a concurrent 1 GiB TCP transfer finished.
The test did not force a real DMA mapping failure, ring wrap, or
deferred xmit_more.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic_main.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index dde9098357d1..f88ae4bd85be 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -825,6 +825,7 @@ static inline int enic_queue_wq_skb_encap(struct enic *enic, struct vnic_wq *wq,
 static inline int enic_queue_wq_skb(struct enic *enic,
 	struct vnic_wq *wq, struct sk_buff *skb)
 {
+	struct vnic_wq_buf *first = wq->to_use;
 	unsigned int mss = skb_shinfo(skb)->gso_size;
 	unsigned int vlan_tag = 0;
 	int vlan_tag_insert = 0;
@@ -857,16 +858,12 @@ static inline int enic_queue_wq_skb(struct enic *enic,
 	if (unlikely(err)) {
 		struct vnic_wq_buf *buf;
 
-		buf = wq->to_use->prev;
-		/* while not EOP of previous pkt && queue not empty.
-		 * For all non EOP bufs, os_buf is NULL.
-		 */
-		while (!buf->os_buf && (buf->next != wq->to_clean)) {
+		while (wq->to_use != first) {
+			buf = wq->to_use->prev;
 			enic_free_wq_buf(wq, buf);
 			wq->ring.desc_avail++;
-			buf = buf->prev;
+			wq->to_use = buf;
 		}
-		wq->to_use = buf->next;
 		dev_kfree_skb(skb);
 	}
 	return err;
@@ -917,8 +914,12 @@ static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
 		return NETDEV_TX_BUSY;
 	}
 
-	if (enic_queue_wq_skb(enic, wq, skb))
+	if (enic_queue_wq_skb(enic, wq, skb)) {
+		/* Do not strand an earlier skb deferred by xmit_more. */
+		if (wq->to_use != wq->to_clean)
+			vnic_wq_doorbell(wq);
 		goto error;
+	}
 
 	if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS) {
 		netif_tx_stop_queue(txq);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 02/12] net: enic: tag work queue descriptor ownership
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 03/12] net: enic: gate native XDP on mixed RQ descriptor capability Satish Kharat
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Record whether a WQ descriptor belongs to an skb, XDP frame, or AF_XDP
TX. Initialize normal skb postings explicitly so later completion paths
can use the tag without changing existing skb behavior. Store the DMA
mapping and XSK pool ownership alongside the descriptor for the
corresponding completion path.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/vnic_wq.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/cisco/enic/vnic_wq.h b/drivers/net/ethernet/cisco/enic/vnic_wq.h
index 1d448b7a9ba2..b631bab49b1c 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_wq.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_wq.h
@@ -12,6 +12,8 @@
 #include "vnic_dev.h"
 #include "vnic_cq.h"
 
+struct xsk_buff_pool;
+
 /* Work queue control */
 struct vnic_wq_ctrl {
 	u64 ring_base;			/* 0x00 */
@@ -37,6 +39,13 @@ struct vnic_wq_ctrl {
 	u32 pad9;
 };
 
+enum vnic_wq_buf_type {
+	VNIC_WQ_BUF_SKB,
+	VNIC_WQ_BUF_XDP,
+	VNIC_WQ_BUF_XSK,
+	VNIC_WQ_BUF_XSK_RX,
+};
+
 struct vnic_wq_buf {
 	struct vnic_wq_buf *next;
 	dma_addr_t dma_addr;
@@ -49,6 +58,9 @@ struct vnic_wq_buf {
 	uint8_t cq_entry; /* Gets completion event from hw */
 	uint8_t desc_skip_cnt; /* Num descs to occupy */
 	uint8_t compressed_send; /* Both hdr and payload in one desc */
+	u8 type;
+	bool xdp_dma_mapped;
+	struct xsk_buff_pool *xsk_pool;
 	struct vnic_wq_buf *prev;
 };
 
@@ -131,6 +143,9 @@ static inline void vnic_wq_post(struct vnic_wq *wq,
 	buf->dma_addr = dma_addr;
 	buf->len = len;
 	buf->wr_id = wrid;
+	buf->type = VNIC_WQ_BUF_SKB;
+	buf->xdp_dma_mapped = false;
+	buf->xsk_pool = NULL;
 
 	buf = buf->next;
 	wq->to_use = buf;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 03/12] net: enic: gate native XDP on mixed RQ descriptor capability
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 02/12] net: enic: tag work queue descriptor ownership Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters Satish Kharat
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

The VIC firmware advertises whether a vNIC supports mixed SOP and
non-SOP receive descriptors. Native XDP also requires a supported
physical-function vNIC. Centralize these checks so attach, AF_XDP pool
setup, and feature advertisement use the same gate.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h      | 1 +
 drivers/net/ethernet/cisco/enic/enic_main.c | 7 +++++++
 drivers/net/ethernet/cisco/enic/vnic_enet.h | 1 +
 3 files changed, 9 insertions(+)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index a4f9f58c1adf..1dc2be74f1cd 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -475,6 +475,7 @@ int enic_sriov_enabled(struct enic *enic);
 int enic_is_valid_vf(struct enic *enic, int vf);
 int enic_is_dynamic(struct enic *enic);
 int enic_is_sriov_vf_v2(struct enic *enic);
+bool enic_xdp_supported(struct enic *enic);
 void enic_set_ethtool_ops(struct net_device *netdev);
 int __enic_set_rsskey(struct enic *enic);
 void enic_ext_cq(struct enic *enic);
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index f88ae4bd85be..430fd6b210e8 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -321,6 +321,13 @@ int enic_is_sriov_vf_v2(struct enic *enic)
 	return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_VF_V2;
 }
 
+bool enic_xdp_supported(struct enic *enic)
+{
+	return ENIC_SETTING(enic, MIXED_RQ_DESC_TYPE) &&
+	       !enic_is_dynamic(enic) &&
+	       !enic_is_sriov_vf(enic);
+}
+
 int enic_is_valid_vf(struct enic *enic, int vf)
 {
 #ifdef CONFIG_PCI_IOV
diff --git a/drivers/net/ethernet/cisco/enic/vnic_enet.h b/drivers/net/ethernet/cisco/enic/vnic_enet.h
index 519d2969990b..895261c68dd0 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_enet.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_enet.h
@@ -43,6 +43,7 @@ struct vnic_enet_config {
 #define VENETF_RSSHASH_TCPIPV6_EX 0x400	/* Hash on TCP + IPv6 ext. fields */
 #define VENETF_LOOP		0x800	/* Loopback enabled */
 #define VENETF_VXLAN		0x10000	/* VxLAN offload */
+#define VENETF_MIXED_RQ_DESC_TYPE 0x2000000 /* SOP/non-SOP descs on RQ */
 
 #define VENET_INTR_TYPE_MIN	0	/* Timer specs min interrupt spacing */
 #define VENET_INTR_TYPE_IDLE	1	/* Timer specs idle time before irq */

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (2 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 03/12] net: enic: gate native XDP on mixed RQ descriptor capability Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-02  1:16   ` sashiko-bot
  2026-12-01  1:15 ` [PATCH RFC net-next 05/12] net: enic: complete XDP frames by WQ descriptor ownership Satish Kharat
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Add receive action, AF_XDP fill, and AF_XDP transmit counters to the
existing ethtool per-queue statistics. The data paths added later in
this series update these counters.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h         | 15 +++++++++++++++
 drivers/net/ethernet/cisco/enic/enic_ethtool.c | 15 +++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 1dc2be74f1cd..02fc3880a22b 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -200,6 +200,10 @@ struct enic_wq_stats {
 	u64 null_pkt;		/* skb length <= 0 */
 	u64 skb_linear_fail;	/* linearize failures */
 	u64 desc_full_awake;	/* TX ring full while queue awake */
+	u64 xsk_tx_pkts;
+	u64 xsk_tx_bytes;
+	u64 xsk_tx_no_room;
+	u64 xsk_tx_completed;
 };
 
 struct enic_rq_stats {
@@ -217,6 +221,17 @@ struct enic_rq_stats {
 	u64 no_skb;			/* out of skbs */
 	u64 desc_skip;			/* Rx pkt went into later buffer */
 	u64 pp_alloc_fail;		/* page pool alloc failure */
+	u64 xdp_pass;
+	u64 xdp_drop;
+	u64 xdp_tx;
+	u64 xdp_tx_drops;
+	u64 xdp_redirect;
+	u64 xdp_redirect_drops;
+	u64 xdp_aborted;
+	u64 xdp_invalid;
+	u64 xsk_rx_pkts;
+	u64 xsk_rx_bytes;
+	u64 xsk_fill_empty;
 };
 
 struct enic_wq {
diff --git a/drivers/net/ethernet/cisco/enic/enic_ethtool.c b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
index 61541fb8db7b..ca1d9ae27d82 100644
--- a/drivers/net/ethernet/cisco/enic/enic_ethtool.c
+++ b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
@@ -51,6 +51,17 @@ static const struct enic_stat enic_per_rq_stats[] = {
 	ENIC_PER_RQ_STAT(napi_repoll),
 	ENIC_PER_RQ_STAT(no_skb),
 	ENIC_PER_RQ_STAT(desc_skip),
+	ENIC_PER_RQ_STAT(xdp_pass),
+	ENIC_PER_RQ_STAT(xdp_drop),
+	ENIC_PER_RQ_STAT(xdp_tx),
+	ENIC_PER_RQ_STAT(xdp_tx_drops),
+	ENIC_PER_RQ_STAT(xdp_redirect),
+	ENIC_PER_RQ_STAT(xdp_redirect_drops),
+	ENIC_PER_RQ_STAT(xdp_aborted),
+	ENIC_PER_RQ_STAT(xdp_invalid),
+	ENIC_PER_RQ_STAT(xsk_rx_pkts),
+	ENIC_PER_RQ_STAT(xsk_rx_bytes),
+	ENIC_PER_RQ_STAT(xsk_fill_empty),
 };
 
 #define NUM_ENIC_PER_RQ_STATS   ARRAY_SIZE(enic_per_rq_stats)
@@ -64,6 +75,10 @@ static const struct enic_stat enic_per_wq_stats[] = {
 	ENIC_PER_WQ_STAT(null_pkt),
 	ENIC_PER_WQ_STAT(skb_linear_fail),
 	ENIC_PER_WQ_STAT(desc_full_awake),
+	ENIC_PER_WQ_STAT(xsk_tx_pkts),
+	ENIC_PER_WQ_STAT(xsk_tx_bytes),
+	ENIC_PER_WQ_STAT(xsk_tx_no_room),
+	ENIC_PER_WQ_STAT(xsk_tx_completed),
 };
 
 #define NUM_ENIC_PER_WQ_STATS   ARRAY_SIZE(enic_per_wq_stats)

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 05/12] net: enic: complete XDP frames by WQ descriptor ownership
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (3 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages Satish Kharat
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

The common WQ cleanup path also serves XDP frames. Use the ownership
tag to unmap DMA only when the driver mapped it, then return the frame.
The skb path is unchanged. XDP posting is enabled later in the series.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic_wq.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/net/ethernet/cisco/enic/enic_wq.c b/drivers/net/ethernet/cisco/enic/enic_wq.c
index 07936f8b4231..ceab5a8e68cf 100644
--- a/drivers/net/ethernet/cisco/enic/enic_wq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_wq.c
@@ -2,6 +2,7 @@
 // Copyright 2025 Cisco Systems, Inc.  All rights reserved.
 
 #include <net/netdev_queues.h>
+#include <net/xdp.h>
 #include "enic_res.h"
 #include "enic.h"
 #include "enic_wq.h"
@@ -41,6 +42,21 @@ static void enic_wq_cq_desc_dec(const struct cq_desc *desc_arg, bool ext_wq,
 void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
 {
 	struct enic *enic = vnic_dev_priv(wq->vdev);
+	struct xdp_frame *xdpf;
+
+	if (buf->type == VNIC_WQ_BUF_XDP) {
+		xdpf = buf->os_buf;
+		if (buf->xdp_dma_mapped)
+			dma_unmap_single(&enic->pdev->dev, buf->dma_addr,
+					 buf->len, DMA_TO_DEVICE);
+		if (xdpf)
+			xdp_return_frame(xdpf);
+		buf->os_buf = NULL;
+		buf->dma_addr = 0;
+		buf->xdp_dma_mapped = false;
+		buf->type = VNIC_WQ_BUF_SKB;
+		return;
+	}
 
 	if (buf->sop)
 		dma_unmap_single(&enic->pdev->dev, buf->dma_addr, buf->len,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (4 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 05/12] net: enic: complete XDP frames by WQ descriptor ownership Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-02  1:16   ` sashiko-bot
  2026-12-01  1:15 ` [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches Satish Kharat
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Reserve XDP_PACKET_HEADROOM and skb_shared_info tailroom when an RQ is
marked for native XDP. Derive descriptor DMA from the adjusted offset.
The flag is set by the later attach patch; ordinary RX keeps its
existing buffer geometry.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h     |  1 +
 drivers/net/ethernet/cisco/enic/enic_rq.c  | 11 ++++++++---
 drivers/net/ethernet/cisco/enic/enic_xdp.h | 13 +++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 02fc3880a22b..eff80481c4ac 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -244,6 +244,7 @@ struct enic_rq {
 	struct vnic_rq vrq;
 	struct enic_rq_stats stats;
 	struct page_pool *pool;
+	bool xdp_enabled;
 } ____cacheline_aligned;
 
 enum enic_vf_type {
diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
index ccbf5c9a21d0..82ef15296a10 100644
--- a/drivers/net/ethernet/cisco/enic/enic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
@@ -7,6 +7,7 @@
 #include "enic.h"
 #include "enic_res.h"
 #include "enic_rq.h"
+#include "enic_xdp.h"
 #include "vnic_rq.h"
 #include "cq_enet_desc.h"
 
@@ -273,13 +274,17 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
 	struct net_device *netdev = enic->netdev;
 	struct enic_rq *erq = &enic->rq[rq->index];
 	struct enic_rq_stats *rqstats = &erq->stats;
+	unsigned int headroom = erq->xdp_enabled ? ENIC_XDP_HEADROOM : 0;
 	unsigned int offset = 0;
 	unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
 	unsigned int os_buf_index = 0;
 	dma_addr_t dma_addr;
 	struct vnic_rq_buf *buf = rq->to_use;
 	struct page *page;
-	unsigned int truesize = len;
+	unsigned int truesize = len + headroom;
+
+	if (erq->xdp_enabled)
+		truesize += ENIC_XDP_TAILROOM;
 
 	if (buf->os_buf) {
 		enic_queue_rq_desc(rq, buf->os_buf, os_buf_index, buf->dma_addr,
@@ -293,9 +298,9 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
 		rqstats->pp_alloc_fail++;
 		return -ENOMEM;
 	}
-	buf->offset = offset;
+	buf->offset = offset + headroom;
 	buf->truesize = truesize;
-	dma_addr = page_pool_get_dma_addr(page) + offset;
+	dma_addr = page_pool_get_dma_addr(page) + buf->offset;
 	enic_queue_rq_desc(rq, (void *)page, os_buf_index, dma_addr, len);
 
 	return 0;
diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.h b/drivers/net/ethernet/cisco/enic/enic_xdp.h
new file mode 100644
index 000000000000..87ae61c4974d
--- /dev/null
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright 2026 Cisco Systems, Inc.  All rights reserved. */
+
+#ifndef _ENIC_XDP_H_
+#define _ENIC_XDP_H_
+
+#include <linux/skbuff.h>
+#include <net/xdp.h>
+
+#define ENIC_XDP_HEADROOM	XDP_PACKET_HEADROOM
+#define ENIC_XDP_TAILROOM	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
+
+#endif /* _ENIC_XDP_H_ */

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (5 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-02  1:16   ` sashiko-bot
  2026-12-01  1:15 ` [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect Satish Kharat
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

The receive queue only advanced posted_index at a 16-descriptor
boundary. If refill ran out of buffers before that boundary, the
descriptors already filled in this pass could remain invisible to the
device, including on the admin receive queue.

Publish a nonempty partial tail after each refill attempt, on success
or failure. Preserve the existing full-batch write in vnic_rq_post()
and order descriptor contents before advancing posted_index.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic_admin.c |  8 +++++---
 drivers/net/ethernet/cisco/enic/vnic_rq.h    | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic_admin.c b/drivers/net/ethernet/cisco/enic/enic_admin.c
index d4f3f58a0ec2..3ffd59bbc051 100644
--- a/drivers/net/ethernet/cisco/enic/enic_admin.c
+++ b/drivers/net/ethernet/cisco/enic/enic_admin.c
@@ -88,15 +88,17 @@ static int enic_admin_rq_post_one(struct enic *enic, gfp_t gfp)
 static int enic_admin_rq_fill(struct enic *enic, gfp_t gfp)
 {
 	struct vnic_rq *rq = &enic->admin_rq;
-	int err;
+	struct vnic_rq_buf *first = rq->to_use;
+	int err = 0;
 
 	while (vnic_rq_desc_avail(rq) > 0) {
 		err = enic_admin_rq_post_one(enic, gfp);
 		if (err)
-			return err;
+			break;
 	}
 
-	return 0;
+	vnic_rq_publish_tail(rq, first);
+	return err;
 }
 
 static void enic_admin_rq_drain(struct enic *enic)
diff --git a/drivers/net/ethernet/cisco/enic/vnic_rq.h b/drivers/net/ethernet/cisco/enic/vnic_rq.h
index 9fc2090eac44..6c347599d233 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_rq.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_rq.h
@@ -140,6 +140,19 @@ static inline void vnic_rq_post(struct vnic_rq *rq,
 	}
 }
 
+static inline void vnic_rq_publish_tail(struct vnic_rq *rq,
+					struct vnic_rq_buf *first)
+{
+	/* A full batch was already published by vnic_rq_post(). */
+	if (rq->to_use == first ||
+	    !(rq->to_use->index & VNIC_RQ_RETURN_RATE))
+		return;
+
+	/* Make descriptor contents visible before advancing the device index. */
+	wmb();
+	iowrite32(rq->to_use->index, &rq->ctrl->posted_index);
+}
+
 static inline void vnic_rq_return_descs(struct vnic_rq *rq, unsigned int count)
 {
 	rq->ring.desc_avail += count;
@@ -181,16 +194,18 @@ static inline void vnic_rq_service(struct vnic_rq *rq,
 static inline int vnic_rq_fill(struct vnic_rq *rq,
 	int (*buf_fill)(struct vnic_rq *rq))
 {
-	int err;
+	struct vnic_rq_buf *first = rq->to_use;
+	int err = 0;
 
 	while (vnic_rq_desc_avail(rq) > 0) {
 
 		err = (*buf_fill)(rq);
 		if (err)
-			return err;
+			break;
 	}
 
-	return 0;
+	vnic_rq_publish_tail(rq, first);
+	return err;
 }
 
 void vnic_rq_free(struct vnic_rq *rq);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (6 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-02  1:16   ` sashiko-bot
  2026-12-01  1:15 ` [PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool Satish Kharat
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Register page-backed RX queues with XDP, run packet actions, and post
and complete XDP frames on shared WQs while reserving space for stack
skbs. Stop data queues and preserve DMA ownership before freeing
buffers during detach or reopen.

RX VLAN stripping hides tags from XDP_TX and redirect. Quiesce RX before
publishing the new program, apply the requested NIC_CFG mode, and reopen
the queues. Restore the user-selected strip mode on final detach and
roll back on configuration failure. Advertise native actions only for
the supported mixed-RQ physical vNIC.

With stripping off, reserve room for two VLAN headers in each RQ
descriptor and RX page. Preserve the one-tag envelope when hardware
stripping is on.

At zero NAPI budget, service only whole skb-owned WQ CQ spans and
return their credits. Defer XDP and RX work to a positive-budget
poll without completing NAPI or unmasking interrupts.

On final XDP detach, a BPF link release cannot roll back the old
program if the queue reopen fails. Keep NULL published and release
the driver reference even on that error. Retry the reopen once
directly with the detached configuration before scheduling reset
work as a best-effort fallback. Preserve rollback for first attach.

AI-assisted code review identified the final-detach ownership
failure in an RFC draft. On an E1 VIC 15237 vNIC, a test-only
one-shot enic_open() -EIO during BPF-link release reproduced a
driver-held program after the link disappeared. With this fix,
the same injected fault released the program and direct retry
restored carrier. E1 and E2 each passed 10/10 IPv4 and 10/10
IPv6 peer probes. Persistent reopen failure and reset recovery
were not tested.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/Makefile    |   3 +-
 drivers/net/ethernet/cisco/enic/enic.h      |  25 ++
 drivers/net/ethernet/cisco/enic/enic_api.c  |   9 +
 drivers/net/ethernet/cisco/enic/enic_dev.c  |   8 +
 drivers/net/ethernet/cisco/enic/enic_dev.h  |   1 +
 drivers/net/ethernet/cisco/enic/enic_main.c | 615 ++++++++++++++++++++++++----
 drivers/net/ethernet/cisco/enic/enic_rq.c   |  29 +-
 drivers/net/ethernet/cisco/enic/enic_wq.c   |  34 +-
 drivers/net/ethernet/cisco/enic/enic_wq.h   |   2 +-
 drivers/net/ethernet/cisco/enic/enic_xdp.c  | 322 +++++++++++++++
 drivers/net/ethernet/cisco/enic/enic_xdp.h  |  23 ++
 drivers/net/ethernet/cisco/enic/vnic_dev.c  |  16 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.h  |   2 +
 13 files changed, 991 insertions(+), 98 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/Makefile b/drivers/net/ethernet/cisco/enic/Makefile
index e38aaf34c148..dc1b9d87c11d 100644
--- a/drivers/net/ethernet/cisco/enic/Makefile
+++ b/drivers/net/ethernet/cisco/enic/Makefile
@@ -4,5 +4,4 @@ obj-$(CONFIG_ENIC) := enic.o
 enic-y := enic_main.o vnic_cq.o vnic_intr.o vnic_wq.o \
 	enic_res.o enic_dev.o enic_pp.o vnic_dev.o vnic_rq.o vnic_vic.o \
 	enic_ethtool.o enic_api.o enic_clsf.o enic_rq.o enic_wq.o \
-	enic_admin.o enic_mbox.o
-
+	enic_admin.o enic_mbox.o enic_xdp.o
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index eff80481c4ac..8a4d0194a5c9 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -16,8 +16,10 @@
 #include "vnic_stats.h"
 #include "vnic_nic.h"
 #include "vnic_rss.h"
+#include <linux/if_vlan.h>
 #include <linux/irq.h>
 #include <net/page_pool/helpers.h>
+#include <net/xdp.h>
 
 #define DRV_NAME		"enic"
 #define DRV_DESCRIPTION		"Cisco VIC Ethernet NIC Driver"
@@ -69,6 +71,9 @@
 
 #define ENIC_WQ_NAPI_BUDGET	256
 
+/* Ethernet header plus two VLAN tags for full-payload QinQ receive. */
+#define ENIC_RX_MAX_L2_LEN	(VLAN_ETH_HLEN + VLAN_HLEN)
+
 #define ENIC_AIC_LARGE_PKT_DIFF	3
 
 enum ext_cq {
@@ -238,13 +243,16 @@ struct enic_wq {
 	spinlock_t lock;		/* spinlock for wq */
 	struct vnic_wq vwq;
 	struct enic_wq_stats stats;
+	bool xdp_tx_pending;
 } ____cacheline_aligned;
 
 struct enic_rq {
 	struct vnic_rq vrq;
 	struct enic_rq_stats stats;
 	struct page_pool *pool;
+	struct xdp_rxq_info xdp_rxq;
 	bool xdp_enabled;
+	bool xdp_flush_pending;
 } ____cacheline_aligned;
 
 enum enic_vf_type {
@@ -310,6 +318,9 @@ struct enic {
 	unsigned int rq_count;
 	struct vxlan_offload vxlan;
 	struct napi_struct *napi;
+	struct bpf_prog __rcu *xdp_prog;
+	bool datapath_open;
+	bool dma_blocked;
 
 	struct vnic_intr *intr;
 	unsigned int intr_avail;
@@ -321,6 +332,13 @@ struct enic {
 	unsigned int cq_count;
 	struct enic_rfs_flw_tbl rfs_h;
 	u8 rss_key[ENIC_RSS_LEN];
+	/* Reuse the active RSS parameters for an RX VLAN NIC_CFG update. */
+	u8 niccfg_rss_hash_type;
+	u8 niccfg_rss_enable;
+	bool niccfg_valid;
+	bool rx_vlan_strip;
+	bool rx_vlan_strip_applied;
+	bool vlan_rewrite_valid;
 	struct vnic_gen_stats gen_stats;
 	enum ext_cq ext_cq;
 
@@ -328,6 +346,8 @@ struct enic {
 	bool has_admin_channel;
 	/* QUARANTINED retains admin DMA until a final teardown recheck. */
 	enum enic_admin_chan_state admin_chan_state;
+	/* A forced data-queue reset defers admin reopen until datapath open. */
+	bool admin_reopen_pending;
 	/* Blocks sends throughout close, partial open and timeout recovery. */
 	bool mbox_send_disabled;
 	struct vnic_wq admin_wq;
@@ -371,6 +391,11 @@ struct enic {
 	} *vf_state;
 };
 
+static inline unsigned int enic_rx_l2_len(const struct enic *enic)
+{
+	return enic->rx_vlan_strip ? VLAN_ETH_HLEN : ENIC_RX_MAX_L2_LEN;
+}
+
 static inline struct net_device *vnic_get_netdev(struct vnic_dev *vdev)
 {
 	struct enic *enic = vdev->priv;
diff --git a/drivers/net/ethernet/cisco/enic/enic_api.c b/drivers/net/ethernet/cisco/enic/enic_api.c
index e3b700c28bc4..2a047057dfa9 100644
--- a/drivers/net/ethernet/cisco/enic/enic_api.c
+++ b/drivers/net/ethernet/cisco/enic/enic_api.c
@@ -18,12 +18,21 @@ int enic_api_devcmd_proxy_by_index(struct net_device *netdev, int vf,
 	struct enic *enic = netdev_priv(netdev);
 	struct vnic_dev *vdev = enic->vdev;
 
+	if (READ_ONCE(enic->dma_blocked))
+		return -EIO;
+
 	spin_lock(&enic->enic_api_lock);
 	while (enic->enic_api_busy) {
 		spin_unlock(&enic->enic_api_lock);
+		if (READ_ONCE(enic->dma_blocked))
+			return -EIO;
 		cpu_relax();
 		spin_lock(&enic->enic_api_lock);
 	}
+	if (READ_ONCE(enic->dma_blocked)) {
+		spin_unlock(&enic->enic_api_lock);
+		return -EIO;
+	}
 
 	spin_lock_bh(&enic->devcmd_lock);
 
diff --git a/drivers/net/ethernet/cisco/enic/enic_dev.c b/drivers/net/ethernet/cisco/enic/enic_dev.c
index 7d5298e6df02..dc8ade5310cb 100644
--- a/drivers/net/ethernet/cisco/enic/enic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/enic_dev.c
@@ -99,6 +99,9 @@ int enic_dev_notify_unset(struct enic *enic)
 {
 	int err;
 
+	if (READ_ONCE(enic->dma_blocked))
+		return 0;
+
 	spin_lock_bh(&enic->devcmd_lock);
 	err = vnic_dev_notify_unset(enic->vdev);
 	spin_unlock_bh(&enic->devcmd_lock);
@@ -106,6 +109,11 @@ int enic_dev_notify_unset(struct enic *enic)
 	return err;
 }
 
+void enic_dev_notify_free(struct enic *enic)
+{
+	vnic_dev_notify_free(enic->vdev);
+}
+
 int enic_dev_hang_notify(struct enic *enic)
 {
 	int err;
diff --git a/drivers/net/ethernet/cisco/enic/enic_dev.h b/drivers/net/ethernet/cisco/enic/enic_dev.h
index eed1674ff30f..bbbb1975c2dd 100644
--- a/drivers/net/ethernet/cisco/enic/enic_dev.h
+++ b/drivers/net/ethernet/cisco/enic/enic_dev.h
@@ -35,6 +35,7 @@ int enic_dev_del_addr(struct enic *enic, const u8 *addr);
 int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid);
 int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid);
 int enic_dev_notify_unset(struct enic *enic);
+void enic_dev_notify_free(struct enic *enic);
 int enic_dev_hang_notify(struct enic *enic);
 int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic);
 int enic_dev_enable(struct enic *enic);
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 430fd6b210e8..4c1ea75654bb 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -62,6 +62,7 @@
 #include "enic_wq.h"
 #include "enic_admin.h"
 #include "enic_mbox.h"
+#include "enic_xdp.h"
 
 #define ENIC_NOTIFY_TIMER_PERIOD	(2 * HZ)
 
@@ -1383,10 +1384,18 @@ static int enic_poll(struct napi_struct *napi, int budget)
 	unsigned int  work_done, rq_work_done = 0, wq_work_done;
 	int err;
 
-	wq_work_done = enic_wq_cq_service(enic, cq_wq, wq_work_to_do);
+	wq_work_done = enic_wq_cq_service(enic, cq_wq, wq_work_to_do, !budget);
+	if (!budget) {
+		if (wq_work_done)
+			vnic_intr_return_credits(&enic->intr[intr], wq_work_done,
+						 0, 0);
+		return 0;
+	}
 
 	if (budget > 0)
 		rq_work_done = enic_rq_cq_service(enic, cq_rq, rq_work_to_do);
+	enic_xdp_tx_flush(enic, 0);
+	enic_xdp_redirect_flush(enic, 0);
 
 	/* Accumulate intr event credits for this polling
 	 * cycle.  An intr event is the completion of a
@@ -1486,7 +1495,13 @@ static int enic_poll_msix_wq(struct napi_struct *napi, int budget)
 	cq = enic_cq_wq(enic, wq_irq);
 	intr = enic_msix_wq_intr(enic, wq_irq);
 
-	wq_work_done = enic_wq_cq_service(enic, cq, wq_work_to_do);
+	wq_work_done = enic_wq_cq_service(enic, cq, wq_work_to_do, !budget);
+	if (!budget) {
+		if (wq_work_done)
+			vnic_intr_return_credits(&enic->intr[intr], wq_work_done,
+						 0, 1);
+		return 0;
+	}
 
 	vnic_intr_return_credits(&enic->intr[intr], wq_work_done,
 				 0 /* don't unmask intr */,
@@ -1511,11 +1526,16 @@ static int enic_poll_msix_rq(struct napi_struct *napi, int budget)
 	unsigned int work_done = 0;
 	int err;
 
+	if (!budget)
+		return 0;
+
 	/* Service RQ
 	 */
 
 	if (budget > 0)
 		work_done = enic_rq_cq_service(enic, cq, work_to_do);
+	enic_xdp_tx_flush(enic, rq);
+	enic_xdp_redirect_flush(enic, rq);
 
 	/* Return intr event credits for this polling
 	 * cycle.  An intr event is the completion of a
@@ -1726,19 +1746,173 @@ static void enic_notify_timer_start(struct enic *enic)
 	}
 }
 
+static int enic_dev_soft_reset(struct enic *enic);
+static int enic_set_rss_nic_cfg(struct enic *enic);
+static int enic_apply_nic_cfg(struct enic *enic);
+static void enic_admin_chan_reopen(struct enic *enic);
+
+static bool enic_disable_data_queues(struct enic *enic)
+{
+	struct net_device *netdev = enic->netdev;
+	bool failed = false;
+	unsigned int i;
+	int err;
+
+	for (i = 0; i < enic->wq_count; i++) {
+		/* Pair with the datapath_open recheck under wq->lock in every
+		 * XDP posting path. Once this barrier completes, no new descriptor
+		 * can be posted while the queue is being disabled.
+		 */
+		spin_lock_bh(&enic->wq[i].lock);
+		spin_unlock_bh(&enic->wq[i].lock);
+		err = vnic_wq_disable(&enic->wq[i].vwq);
+		if (err) {
+			netdev_warn(netdev, "Failed to disable WQ[%u]: %d\n",
+				    i, err);
+			failed = true;
+		}
+	}
+	for (i = 0; i < enic->rq_count; i++) {
+		err = vnic_rq_disable(&enic->rq[i].vrq);
+		if (err) {
+			netdev_warn(netdev, "Failed to disable RQ[%u]: %d\n",
+				    i, err);
+			failed = true;
+		}
+	}
+
+	return failed;
+}
+
+static void enic_block_pci_dma(struct enic *enic)
+{
+	pci_clear_master(enic->pdev);
+	WRITE_ONCE(enic->dma_blocked, true);
+}
+
+static bool enic_force_dma_quiesce(struct enic *enic, bool *api_was_busy)
+{
+	bool admin_was_up;
+	int err;
+
+	spin_lock(&enic->enic_api_lock);
+	*api_was_busy = enic->enic_api_busy;
+	enic->enic_api_busy = true;
+	spin_unlock(&enic->enic_api_lock);
+
+	/* A quarantined admin graph has no queue-stop proof. Never reset or
+	 * release it; contain all DMA before reclaiming datapath buffers.
+	 */
+	admin_was_up = READ_ONCE(enic->admin_chan_state) ==
+			ENIC_ADMIN_CHAN_LIVE;
+	if (enic_admin_channel_is_quarantined(enic)) {
+		enic->admin_reopen_pending = false;
+		enic_block_pci_dma(enic);
+		return false;
+	}
+	if (admin_was_up) {
+		enic_admin_channel_close(enic);
+		if (enic_is_sriov_vf_v2(enic)) {
+			WRITE_ONCE(enic->vf_registered, false);
+			/* The PF will provide fresh link state after registration. */
+			enic_mbox_vf_link_state_reset(enic);
+		}
+		if (enic_admin_channel_is_quarantined(enic)) {
+			enic->admin_reopen_pending = false;
+			enic_block_pci_dma(enic);
+			return false;
+		}
+		/* A failed enic_open() must not reopen admin queues. */
+		enic->admin_reopen_pending = true;
+	}
+	err = enic_dev_soft_reset(enic);
+	if (!err)
+		return true;
+
+	/* Queue ownership must still be released for ndo_stop and forced XDP
+	 * teardown, both of which are non-failable. Prevent any further DMA
+	 * before reclaiming buffers if firmware could not reset the vNIC.
+	 */
+	netdev_err(enic->netdev,
+		   "vNIC reset failed after queue disable timeout: %d; blocking PCI DMA\n",
+		   err);
+	enic_block_pci_dma(enic);
+
+	return false;
+}
+
+static void enic_clean_data_queues(struct enic *enic)
+{
+	unsigned int i;
+
+	for (i = 0; i < enic->wq_count; i++) {
+		spin_lock_bh(&enic->wq[i].lock);
+		vnic_wq_clean(&enic->wq[i].vwq, enic_free_wq_buf);
+		WRITE_ONCE(enic->wq[i].xdp_tx_pending, false);
+		spin_unlock_bh(&enic->wq[i].lock);
+	}
+	for (i = 0; i < enic->rq_count; i++) {
+		vnic_rq_clean(&enic->rq[i].vrq, enic_free_rq_buf);
+		enic_xdp_rxq_teardown(&enic->rq[i]);
+		if (enic->rq[i].pool)
+			page_pool_destroy(enic->rq[i].pool);
+		enic->rq[i].pool = NULL;
+	}
+	for (i = 0; i < enic->cq_count; i++)
+		vnic_cq_clean(&enic->cq[i]);
+	for (i = 0; i < enic->intr_count; i++)
+		vnic_intr_clean(&enic->intr[i]);
+}
+
+static void enic_finish_dma_quiesce(struct enic *enic, bool reset_done,
+				    bool api_was_busy)
+{
+	int err;
+
+	if (reset_done) {
+		enic_reset_addr_lists(enic);
+		enic_init_vnic_resources(enic);
+		enic->vlan_rewrite_valid = false;
+		err = enic_set_rss_nic_cfg(enic);
+		if (err)
+			netdev_err(enic->netdev,
+				   "failed to restore NIC configuration after forced reset: %d\n",
+				   err);
+		err = enic_dev_set_ig_vlan_rewrite_mode(enic);
+		if (err)
+			netdev_err(enic->netdev,
+				   "failed to restore ingress VLAN rewrite after forced reset: %d\n",
+				   err);
+		else
+			enic->vlan_rewrite_valid = true;
+		enic_ext_cq(enic);
+	}
+
+	if (!api_was_busy) {
+		spin_lock(&enic->enic_api_lock);
+		enic->enic_api_busy = false;
+		spin_unlock(&enic->enic_api_lock);
+		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+	}
+}
+
 /* rtnl lock is held, process context */
 static int enic_open(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
+	bool xdp_enabled = enic_xdp_attached(enic);
+	bool api_was_busy = false;
+	bool forced_quiesce = false, reset_done = false;
 	unsigned int i;
-	int err, ret;
-	unsigned int max_pkt_len = netdev->mtu + VLAN_ETH_HLEN;
+	int err;
+	unsigned int max_pkt_len = netdev->mtu + enic_rx_l2_len(enic) +
+		(xdp_enabled ? ENIC_XDP_HEADROOM + ENIC_XDP_TAILROOM : 0);
 	struct page_pool_params pp_params = {
 		.order = get_order(max_pkt_len),
 		.pool_size = enic->config.rq_desc_count,
 		.nid = dev_to_node(&enic->pdev->dev),
 		.dev = &enic->pdev->dev,
-		.dma_dir = DMA_FROM_DEVICE,
+		.dma_dir = xdp_enabled ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
 		.max_len = (max_pkt_len > PAGE_SIZE) ? max_pkt_len : PAGE_SIZE,
 		.netdev = netdev,
 		.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
@@ -1751,6 +1925,26 @@ static int enic_open(struct net_device *netdev)
 	    enic_admin_channel_is_quarantined(enic))
 		return -EBUSY;
 
+	WRITE_ONCE(enic->datapath_open, false);
+	if (READ_ONCE(enic->dma_blocked))
+		return -EIO;
+	if (!enic->vlan_rewrite_valid) {
+		err = enic_dev_set_ig_vlan_rewrite_mode(enic);
+		if (err) {
+			netdev_err(netdev,
+				   "Failed to configure ingress VLAN rewrite before RX: %d\n",
+				   err);
+			return err;
+		}
+		enic->vlan_rewrite_valid = true;
+	}
+	err = enic_apply_nic_cfg(enic);
+	if (err) {
+		netdev_err(netdev, "Failed to configure NIC before RX: %d\n",
+			   err);
+		return err;
+	}
+
 	err = enic_request_intr(enic);
 	if (err) {
 		netdev_err(netdev, "Unable to request irq.\n");
@@ -1761,12 +1955,18 @@ static int enic_open(struct net_device *netdev)
 
 	err = enic_dev_notify_set(enic);
 	if (err) {
-		netdev_err(netdev,
-			"Failed to alloc notify buffer, aborting.\n");
-		goto err_out_free_intr;
+		netdev_err(netdev, "Failed to set notify buffer: %d\n", err);
+		if (!vnic_dev_notify_is_allocated(enic->vdev))
+			goto err_out_free_intr;
+		/* CMD_NOTIFY may have reached firmware. Retain its coherent
+		 * buffer until the vNIC is reset or PCI DMA is blocked.
+		 */
+		forced_quiesce = true;
+		goto err_out_free_rq;
 	}
 
 	for (i = 0; i < enic->rq_count; i++) {
+		enic->rq[i].xdp_enabled = xdp_enabled;
 		/* create a page pool for each RQ */
 		pp_params.napi = &enic->napi[i];
 		pp_params.queue_idx = i;
@@ -1776,6 +1976,9 @@ static int enic_open(struct net_device *netdev)
 			enic->rq[i].pool = NULL;
 			goto err_out_free_rq;
 		}
+		err = enic_xdp_rxq_setup(enic, i);
+		if (err)
+			goto err_out_free_rq;
 
 		/* enable rq before updating rq desc */
 		vnic_rq_enable(&enic->rq[i].vrq);
@@ -1813,10 +2016,21 @@ static int enic_open(struct net_device *netdev)
 	for (i = 0; i < enic->intr_count; i++)
 		vnic_intr_unmask(&enic->intr[i]);
 
+	WRITE_ONCE(enic->datapath_open, true);
 	enic_notify_timer_start(enic);
 	enic_rfs_timer_start(enic);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_set_running(enic, true);
+	if (enic->admin_reopen_pending) {
+		/* Reopen control queues only after the data path is usable. */
+		if (READ_ONCE(enic->admin_chan_state) == ENIC_ADMIN_CHAN_DOWN)
+			enic_admin_chan_reopen(enic);
+		enic->admin_reopen_pending =
+			READ_ONCE(enic->admin_chan_state) == ENIC_ADMIN_CHAN_DOWN;
+		if (enic_is_sriov_vf_v2(enic) &&
+		    enic_admin_channel_is_quarantined(enic))
+			schedule_work(&enic->reset);
+	}
 
 	return 0;
 
@@ -1829,18 +2043,23 @@ static int enic_open(struct net_device *netdev)
 	netif_tx_disable(netdev);
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_del_station_addr(enic);
-	for (i = 0; i < enic->wq_count; i++)
-		vnic_wq_disable(&enic->wq[i].vwq);
 err_out_free_rq:
-	for (i = 0; i < enic->rq_count; i++) {
-		ret = vnic_rq_disable(&enic->rq[i].vrq);
-		if (!ret) {
-			vnic_rq_clean(&enic->rq[i].vrq, enic_free_rq_buf);
-			page_pool_destroy(enic->rq[i].pool);
-			enic->rq[i].pool = NULL;
-		}
-	}
-	enic_dev_notify_unset(enic);
+	forced_quiesce |= enic_disable_data_queues(enic);
+	enic_unset_affinity_hint(enic);
+	enic_free_intr(enic);
+	if (forced_quiesce)
+		reset_done = enic_force_dma_quiesce(enic, &api_was_busy);
+	if (!forced_quiesce && enic_dev_notify_unset(enic)) {
+		netdev_warn(netdev, "Failed to unset notify buffer\n");
+		forced_quiesce = true;
+		reset_done = enic_force_dma_quiesce(enic, &api_was_busy);
+	}
+	enic_dev_notify_free(enic);
+	enic_clean_data_queues(enic);
+	if (forced_quiesce)
+		enic_finish_dma_quiesce(enic, reset_done, api_was_busy);
+	return err;
+
 err_out_free_intr:
 	enic_unset_affinity_hint(enic);
 	enic_free_intr(enic);
@@ -1849,12 +2068,20 @@ static int enic_open(struct net_device *netdev)
 }
 
 /* rtnl lock is held, process context */
-static int enic_stop(struct net_device *netdev)
+static int __enic_stop(struct net_device *netdev, bool *reset_performed)
 {
 	struct enic *enic = netdev_priv(netdev);
+	bool api_was_busy = false;
+	bool forced_quiesce = false, reset_done = false;
 	unsigned int i;
 	int err;
 
+	if (reset_performed)
+		*reset_performed = false;
+	if (!READ_ONCE(enic->datapath_open))
+		return 0;
+	WRITE_ONCE(enic->datapath_open, false);
+
 	for (i = 0; i < enic->intr_count; i++) {
 		vnic_intr_mask(&enic->intr[i]);
 		(void)vnic_intr_masked(&enic->intr[i]); /* flush write */
@@ -1865,7 +2092,11 @@ static int enic_stop(struct net_device *netdev)
 	timer_delete_sync(&enic->notify_timer);
 	enic_rfs_flw_tbl_free(enic);
 
-	enic_dev_disable(enic);
+	err = enic_dev_disable(enic);
+	if (err) {
+		netdev_warn(netdev, "Failed to disable device: %d\n", err);
+		forced_quiesce = true;
+	}
 
 	for (i = 0; i < enic->rq_count; i++)
 		napi_disable(&enic->napi[i]);
@@ -1882,42 +2113,100 @@ static int enic_stop(struct net_device *netdev)
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_del_station_addr(enic);
 
-	for (i = 0; i < enic->wq_count; i++) {
-		err = vnic_wq_disable(&enic->wq[i].vwq);
-		if (err)
-			return err;
-	}
-	for (i = 0; i < enic->rq_count; i++) {
-		err = vnic_rq_disable(&enic->rq[i].vrq);
-		if (err)
-			return err;
-	}
+	forced_quiesce |= enic_disable_data_queues(enic);
 
-	enic_dev_notify_unset(enic);
 	enic_unset_affinity_hint(enic);
 	enic_free_intr(enic);
 
-	for (i = 0; i < enic->wq_count; i++)
-		vnic_wq_clean(&enic->wq[i].vwq, enic_free_wq_buf);
-	for (i = 0; i < enic->rq_count; i++) {
-		vnic_rq_clean(&enic->rq[i].vrq, enic_free_rq_buf);
-		page_pool_destroy(enic->rq[i].pool);
-		enic->rq[i].pool = NULL;
+	if (forced_quiesce)
+		reset_done = enic_force_dma_quiesce(enic, &api_was_busy);
+	if (!forced_quiesce && enic_dev_notify_unset(enic)) {
+		netdev_warn(netdev, "Failed to unset notify buffer\n");
+		forced_quiesce = true;
+		reset_done = enic_force_dma_quiesce(enic, &api_was_busy);
 	}
-	for (i = 0; i < enic->cq_count; i++)
-		vnic_cq_clean(&enic->cq[i]);
-	for (i = 0; i < enic->intr_count; i++)
-		vnic_intr_clean(&enic->intr[i]);
+	enic_dev_notify_free(enic);
+	enic_clean_data_queues(enic);
+	if (forced_quiesce)
+		enic_finish_dma_quiesce(enic, reset_done, api_was_busy);
+	if (reset_performed)
+		*reset_performed = reset_done;
 
 	return 0;
 }
 
+static int enic_stop(struct net_device *netdev)
+{
+	return __enic_stop(netdev, NULL);
+}
+
+int enic_xdp_reload(struct net_device *netdev, struct bpf_prog *old_prog,
+		    struct bpf_prog *new_prog)
+{
+	struct enic *enic = netdev_priv(netdev);
+	bool running = netif_running(netdev);
+	int err, rollback_err;
+
+	ASSERT_RTNL();
+	if (!running) {
+		rcu_assign_pointer(enic->xdp_prog, new_prog);
+		netdev_update_features(netdev);
+		return 0;
+	}
+
+	enic_stop(netdev);
+	if (new_prog && READ_ONCE(enic->dma_blocked))
+		return -EIO;
+
+	/* No RX poll can observe the new program with the old RQ format. */
+	rcu_assign_pointer(enic->xdp_prog, new_prog);
+	netdev_update_features(netdev);
+	err = enic_open(netdev);
+	if (!err)
+		return 0;
+
+	/* BPF link release cannot roll back a detached program. Retry the
+	 * reopen directly in case the error was transient.
+	 */
+	if (!new_prog) {
+		netdev_warn(netdev, "failed to reopen after XDP detach: %d\n",
+			    err);
+		if (!READ_ONCE(enic->dma_blocked)) {
+			err = enic_open(netdev);
+			if (err) {
+				netdev_err(netdev,
+					   "XDP detach reopen retry failed: %d\n",
+					   err);
+				if (!READ_ONCE(enic->dma_blocked))
+					schedule_work(&enic->reset);
+			}
+		}
+		return 0;
+	}
+
+	/* enic_open() cleaned the failed configuration. Restore the old
+	 * program and make a best effort to bring its datapath back.
+	 */
+	rcu_assign_pointer(enic->xdp_prog, old_prog);
+	netdev_update_features(netdev);
+	rollback_err = enic_open(netdev);
+	if (rollback_err)
+		netdev_err(netdev,
+			   "failed to restore interface after XDP setup error: %d\n",
+			   rollback_err);
+	if (rollback_err && !READ_ONCE(enic->dma_blocked))
+		schedule_work(&enic->reset);
+
+	return err;
+}
+
 static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
 {
 	bool running = netif_running(netdev);
 	int err = 0;
 
 	ASSERT_RTNL();
+
 	if (running) {
 		err = enic_stop(netdev);
 		if (err)
@@ -1950,6 +2239,59 @@ static int enic_change_mtu(struct net_device *netdev, int new_mtu)
 	return _enic_change_mtu(netdev, new_mtu);
 }
 
+static int enic_set_features(struct net_device *netdev,
+			     netdev_features_t features)
+{
+	struct enic *enic = netdev_priv(netdev);
+	bool strip = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
+	bool old_strip = enic->rx_vlan_strip;
+	bool running = READ_ONCE(enic->datapath_open);
+	int err, rollback_err;
+
+	ASSERT_RTNL();
+	if (strip == old_strip)
+		return 0;
+	if (running) {
+		err = enic_stop(netdev);
+		if (err)
+			return err;
+		if (READ_ONCE(enic->dma_blocked))
+			return -EIO;
+	}
+
+	enic->rx_vlan_strip = strip;
+	if (!running)
+		return 0;
+
+	err = enic_open(netdev);
+	if (!err)
+		return 0;
+
+	enic->rx_vlan_strip = old_strip;
+	if (READ_ONCE(enic->dma_blocked))
+		return err;
+	rollback_err = enic_open(netdev);
+	if (rollback_err) {
+		netdev_err(netdev,
+			   "failed to restore RX VLAN mode after error: %d\n",
+			   rollback_err);
+		schedule_work(&enic->reset);
+	}
+
+	return err;
+}
+
+static netdev_features_t enic_fix_features(struct net_device *netdev,
+					   netdev_features_t features)
+{
+	struct enic *enic = netdev_priv(netdev);
+
+	if (enic_xdp_attached(enic))
+		features &= ~NETIF_F_HW_VLAN_CTAG_RX;
+
+	return features;
+}
+
 static void enic_change_mtu_work(struct work_struct *work)
 {
 	struct enic *enic = container_of(work, struct enic, change_mtu_work);
@@ -2138,19 +2480,19 @@ static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu,
 	u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable)
 {
 	const u8 tso_ipid_split_en = 0;
-	const u8 ig_vlan_strip_en = 1;
 	int err;
 
-	/* Enable VLAN tag stripping.
-	*/
-
 	spin_lock_bh(&enic->devcmd_lock);
 	err = enic_set_nic_cfg(enic,
 		rss_default_cpu, rss_hash_type,
 		rss_hash_bits, rss_base_cpu,
 		rss_enable, tso_ipid_split_en,
-		ig_vlan_strip_en);
+		enic->rx_vlan_strip);
 	spin_unlock_bh(&enic->devcmd_lock);
+	if (err)
+		enic->niccfg_valid = false;
+	else
+		enic->rx_vlan_strip_applied = enic->rx_vlan_strip;
 
 	return err;
 }
@@ -2165,6 +2507,8 @@ static int enic_set_rss_nic_cfg(struct enic *enic)
 	int res;
 	u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1);
 
+	enic->niccfg_valid = false;
+
 	spin_lock_bh(&enic->devcmd_lock);
 	res = vnic_dev_capable_rss_hash_type(enic->vdev, &rss_hash_type);
 	spin_unlock_bh(&enic->devcmd_lock);
@@ -2190,8 +2534,26 @@ static int enic_set_rss_nic_cfg(struct enic *enic)
 		}
 	}
 
-	return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
-		rss_hash_bits, rss_base_cpu, rss_enable);
+	res = enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
+			      rss_hash_bits, rss_base_cpu, rss_enable);
+	if (!res) {
+		enic->niccfg_rss_hash_type = rss_hash_type;
+		enic->niccfg_rss_enable = rss_enable;
+		enic->niccfg_valid = true;
+	}
+
+	return res;
+}
+
+static int enic_apply_nic_cfg(struct enic *enic)
+{
+	if (!enic->niccfg_valid)
+		return enic_set_rss_nic_cfg(enic);
+	if (enic->rx_vlan_strip == enic->rx_vlan_strip_applied)
+		return 0;
+
+	return enic_set_niccfg(enic, 0, enic->niccfg_rss_hash_type, 7, 0,
+			       enic->niccfg_rss_enable);
 }
 
 static void enic_set_api_busy(struct enic *enic, bool busy)
@@ -2284,11 +2646,17 @@ static void enic_admin_chan_reopen(struct enic *enic)
 static void enic_reset(struct work_struct *work)
 {
 	struct enic *enic = container_of(work, struct enic, reset);
+	bool stop_reset_done;
+	int err;
 
 	if (!netif_running(enic->netdev))
 		return;
 
 	rtnl_lock();
+	if (!netif_running(enic->netdev) || READ_ONCE(enic->dma_blocked)) {
+		rtnl_unlock();
+		return;
+	}
 
 	if (!netif_running(enic->netdev))
 		goto unlock;
@@ -2311,28 +2679,61 @@ static void enic_reset(struct work_struct *work)
 		dev_close(enic->netdev);
 		goto reset_out;
 	}
+	if (enic_has_admin_chan(enic))
+		enic->admin_reopen_pending = true;
 
-	enic_stop(enic->netdev);
+	/* A forced stop can already have reset the vNIC. */
+	__enic_stop(enic->netdev, &stop_reset_done);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
+	if (READ_ONCE(enic->dma_blocked)) {
+		enic_set_api_busy(enic, false);
+		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+		rtnl_unlock();
+		return;
+	}
 
-	enic_dev_soft_reset(enic);
-	enic_reset_addr_lists(enic);
-	enic_init_vnic_resources(enic);
-	enic_set_rss_nic_cfg(enic);
-	enic_dev_set_ig_vlan_rewrite_mode(enic);
-	enic_ext_cq(enic);
+	if (!stop_reset_done) {
+		/* The admin channel is down; quarantine was handled above. */
+		err = enic_dev_soft_reset(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "soft reset failed: %d; blocking PCI DMA\n",
+				   err);
+			enic_block_pci_dma(enic);
+			enic_set_api_busy(enic, false);
+			call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+			rtnl_unlock();
+			return;
+		}
+		enic_reset_addr_lists(enic);
+		enic_init_vnic_resources(enic);
+		enic->vlan_rewrite_valid = false;
+		err = enic_set_rss_nic_cfg(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "failed to restore NIC configuration after reset: %d\n",
+				   err);
+			goto reset_out;
+		}
+		err = enic_dev_set_ig_vlan_rewrite_mode(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "failed to restore ingress VLAN rewrite after reset: %d\n",
+				   err);
+			goto reset_out;
+		}
+		enic->vlan_rewrite_valid = true;
+		enic_ext_cq(enic);
+	}
 
-	if (enic_open(enic->netdev))
+	err = enic_open(enic->netdev);
+	if (err) {
+		netdev_err(enic->netdev,
+			   "failed to reopen interface after reset: %d\n", err);
 		goto reset_out;
+	}
 
-	/* Re-establish the admin/MBOX channel after the data path is back up.
-	 * It was fully torn down by enic_admin_channel_close() above;
-	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
-	 * state, or for a VF re-runs the probe-time PF handshake.
-	 */
-	if (enic_has_admin_chan(enic))
-		enic_admin_chan_reopen(enic);
 	if (enic_is_sriov_vf_v2(enic) &&
 	    enic_admin_channel_is_quarantined(enic))
 		dev_close(enic->netdev);
@@ -2350,8 +2751,14 @@ static void enic_reset(struct work_struct *work)
 static void enic_tx_hang_reset(struct work_struct *work)
 {
 	struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+	bool stop_reset_done;
+	int err;
 
 	rtnl_lock();
+	if (!netif_running(enic->netdev) || READ_ONCE(enic->dma_blocked)) {
+		rtnl_unlock();
+		return;
+	}
 
 	if (!netif_running(enic->netdev))
 		goto unlock;
@@ -2373,29 +2780,61 @@ static void enic_tx_hang_reset(struct work_struct *work)
 		dev_close(enic->netdev);
 		goto reset_out;
 	}
-
+	if (enic_has_admin_chan(enic))
+		enic->admin_reopen_pending = true;
 	enic_dev_hang_notify(enic);
-	enic_stop(enic->netdev);
+	__enic_stop(enic->netdev, &stop_reset_done);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
+	if (READ_ONCE(enic->dma_blocked)) {
+		enic_set_api_busy(enic, false);
+		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+		rtnl_unlock();
+		return;
+	}
 
-	enic_dev_hang_reset(enic);
-	enic_reset_addr_lists(enic);
-	enic_init_vnic_resources(enic);
-	enic_set_rss_nic_cfg(enic);
-	enic_dev_set_ig_vlan_rewrite_mode(enic);
-	enic_ext_cq(enic);
+	if (!stop_reset_done) {
+		/* The admin channel is down; quarantine was handled above. */
+		err = enic_dev_hang_reset(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "hang reset failed: %d; blocking PCI DMA\n",
+				   err);
+			enic_block_pci_dma(enic);
+			enic_set_api_busy(enic, false);
+			call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+			rtnl_unlock();
+			return;
+		}
+		enic_reset_addr_lists(enic);
+		enic_init_vnic_resources(enic);
+		enic->vlan_rewrite_valid = false;
+		err = enic_set_rss_nic_cfg(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "failed to restore NIC configuration after hang reset: %d\n",
+				   err);
+			goto reset_out;
+		}
+		err = enic_dev_set_ig_vlan_rewrite_mode(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "failed to restore ingress VLAN rewrite after hang reset: %d\n",
+				   err);
+			goto reset_out;
+		}
+		enic->vlan_rewrite_valid = true;
+		enic_ext_cq(enic);
+	}
 
-	if (enic_open(enic->netdev))
+	err = enic_open(enic->netdev);
+	if (err) {
+		netdev_err(enic->netdev,
+			   "failed to reopen interface after hang reset: %d\n",
+			   err);
 		goto reset_out;
+	}
 
-	/* Re-establish the admin/MBOX channel after the data path is back up.
-	 * It was fully torn down by enic_admin_channel_close() above;
-	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
-	 * state, or for a VF re-runs the probe-time PF handshake.
-	 */
-	if (enic_has_admin_chan(enic))
-		enic_admin_chan_reopen(enic);
 	if (enic_is_sriov_vf_v2(enic) &&
 	    enic_admin_channel_is_quarantined(enic))
 		dev_close(enic->netdev);
@@ -2643,6 +3082,10 @@ static const struct net_device_ops enic_netdev_dynamic_ops = {
 	.ndo_rx_flow_steer	= enic_rx_flow_steer,
 #endif
 	.ndo_features_check	= enic_features_check,
+	.ndo_fix_features	= enic_fix_features,
+	.ndo_set_features	= enic_set_features,
+	.ndo_bpf		= enic_xdp,
+	.ndo_xdp_xmit		= enic_xdp_xmit,
 };
 
 static const struct net_device_ops enic_netdev_ops = {
@@ -2667,6 +3110,10 @@ static const struct net_device_ops enic_netdev_ops = {
 	.ndo_rx_flow_steer	= enic_rx_flow_steer,
 #endif
 	.ndo_features_check	= enic_features_check,
+	.ndo_fix_features	= enic_fix_features,
+	.ndo_set_features	= enic_set_features,
+	.ndo_bpf		= enic_xdp,
+	.ndo_xdp_xmit		= enic_xdp_xmit,
 };
 
 static const struct netdev_stat_ops enic_netdev_stat_ops = {
@@ -3207,6 +3654,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	spin_lock_init(&enic->devcmd_lock);
 	spin_lock_init(&enic->enic_api_lock);
+	enic->rx_vlan_strip = true;
 
 	/*
 	 * Set ingress vlan rewrite mode before vnic initialization
@@ -3218,6 +3666,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 			"Failed to set ingress vlan rewrite mode, aborting.\n");
 		goto err_out_dev_close;
 	}
+	enic->vlan_rewrite_valid = true;
 
 	/* Issue device init to initialize the vnic-to-switch link.
 	 * We'll start with carrier off and wait for link UP
@@ -3324,11 +3773,17 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	else
 		netdev->netdev_ops = &enic_netdev_ops;
 	netdev->stat_ops = &enic_netdev_stat_ops;
+	if (enic_xdp_supported(enic)) {
+		netdev->xdp_features = NETDEV_XDP_ACT_BASIC |
+			NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_NDO_XMIT;
+	}
 
 	netdev->watchdog_timeo = 2 * HZ;
 	enic_set_ethtool_ops(netdev);
 
 	netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
+	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
+		netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
 	if (ENIC_SETTING(enic, LOOP)) {
 		netdev->features &= ~NETIF_F_HW_VLAN_CTAG_TX;
 		enic->loop_enable = 1;
diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
index 82ef15296a10..350e42c556ad 100644
--- a/drivers/net/ethernet/cisco/enic/enic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
@@ -276,7 +276,7 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
 	struct enic_rq_stats *rqstats = &erq->stats;
 	unsigned int headroom = erq->xdp_enabled ? ENIC_XDP_HEADROOM : 0;
 	unsigned int offset = 0;
-	unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
+	unsigned int len = netdev->mtu + enic_rx_l2_len(enic);
 	unsigned int os_buf_index = 0;
 	dma_addr_t dma_addr;
 	struct vnic_rq_buf *buf = rq->to_use;
@@ -314,17 +314,20 @@ void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
 	if (!buf->os_buf)
 		return;
 
-	page_pool_put_full_page(erq->pool, (struct page *)buf->os_buf, true);
+	page_pool_put_full_page(erq->pool, (struct page *)buf->os_buf,
+				true);
 	buf->os_buf = NULL;
+	buf->dma_addr = 0;
 }
 
 static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 				 struct vnic_rq_buf *buf, void *cq_desc,
 				 u8 type, u16 q_number, u16 completed_index)
 {
+	struct enic_rq *erq = &enic->rq[rq->index];
 	struct sk_buff *skb;
 	struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)];
-	struct enic_rq_stats *rqstats = &enic->rq[rq->index].stats;
+	struct enic_rq_stats *rqstats = &erq->stats;
 	struct napi_struct *napi;
 
 	u8 eop, sop, ingress_port, vlan_stripped;
@@ -352,6 +355,15 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 		/* Good receive
 		 */
 		rqstats->bytes += bytes_written;
+		if (erq->xdp_enabled) {
+			page_pool_dma_sync_for_cpu(erq->pool,
+						   buf->os_buf, buf->offset,
+						   bytes_written);
+			if (enic_xdp_run(enic, erq, buf,
+					 &bytes_written))
+				return;
+		}
+
 		napi = &enic->napi[rq->index];
 		skb = napi_get_frags(napi);
 		if (unlikely(!skb)) {
@@ -359,13 +371,20 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 					     enic->netdev->name, rq->index,
 					     completed_index);
 			rqstats->no_skb++;
+			if (erq->xdp_enabled) {
+				page_pool_recycle_direct(erq->pool, buf->os_buf);
+				buf->os_buf = NULL;
+				buf->dma_addr = 0;
+			}
 			return;
 		}
 
 		prefetch(skb->data - NET_IP_ALIGN);
 
-		dma_sync_single_for_cpu(&enic->pdev->dev, buf->dma_addr,
-					bytes_written, DMA_FROM_DEVICE);
+		if (!erq->xdp_enabled)
+			page_pool_dma_sync_for_cpu(erq->pool,
+						   buf->os_buf, buf->offset,
+						   bytes_written);
 		skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
 				(struct page *)buf->os_buf, buf->offset,
 				bytes_written, buf->truesize);
diff --git a/drivers/net/ethernet/cisco/enic/enic_wq.c b/drivers/net/ethernet/cisco/enic/enic_wq.c
index ceab5a8e68cf..c02829e4c41e 100644
--- a/drivers/net/ethernet/cisco/enic/enic_wq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_wq.c
@@ -6,6 +6,7 @@
 #include "enic_res.h"
 #include "enic.h"
 #include "enic_wq.h"
+#include "enic_xdp.h"
 
 #define ENET_CQ_DESC_COMP_NDX_BITS 14
 #define ENET_CQ_DESC_COMP_NDX_MASK GENMASK(ENET_CQ_DESC_COMP_NDX_BITS - 1, 0)
@@ -79,14 +80,33 @@ static void enic_wq_free_buf(struct vnic_wq *wq, struct cq_desc *cq_desc,
 	enic_free_wq_buf(wq, buf);
 }
 
-static void enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
-			    u8 type, u16 q_number, u16 completed_index)
+static bool enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
+			    u8 type, u16 q_number, u16 completed_index,
+			    bool skbs_only)
 {
 	struct enic *enic = vnic_dev_priv(vdev);
+	struct vnic_wq_buf *buf;
+	struct vnic_wq *vwq;
 
 	spin_lock(&enic->wq[q_number].lock);
+	vwq = &enic->wq[q_number].vwq;
+	if (skbs_only) {
+		/* A CQ entry can complete several descriptors. Defer the whole
+		 * entry if any buffer needs XDP or page-pool completion.
+		 */
+		buf = vwq->to_clean;
+		while (1) {
+			if (buf->type != VNIC_WQ_BUF_SKB) {
+				spin_unlock(&enic->wq[q_number].lock);
+				return false;
+			}
+			if (buf->index == completed_index)
+				break;
+			buf = buf->next;
+		}
+	}
 
-	vnic_wq_service(&enic->wq[q_number].vwq, cq_desc,
+	vnic_wq_service(vwq, cq_desc,
 			completed_index, enic_wq_free_buf, NULL);
 
 	if (netif_tx_queue_stopped(netdev_get_tx_queue(enic->netdev, q_number))
@@ -97,10 +117,11 @@ static void enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
 	}
 
 	spin_unlock(&enic->wq[q_number].lock);
+	return true;
 }
 
 unsigned int enic_wq_cq_service(struct enic *enic, unsigned int cq_index,
-				unsigned int work_to_do)
+				unsigned int work_to_do, bool skbs_only)
 {
 	struct vnic_cq *cq = &enic->cq[cq_index];
 	u16 q_number, completed_index;
@@ -116,8 +137,9 @@ unsigned int enic_wq_cq_service(struct enic *enic, unsigned int cq_index,
 			    &q_number, &completed_index);
 
 	while (color != cq->last_color) {
-		enic_wq_service(cq->vdev, cq_desc, type, q_number,
-				completed_index);
+		if (!enic_wq_service(cq->vdev, cq_desc, type, q_number,
+				     completed_index, skbs_only))
+			break;
 
 		vnic_cq_inc_to_clean(cq);
 
diff --git a/drivers/net/ethernet/cisco/enic/enic_wq.h b/drivers/net/ethernet/cisco/enic/enic_wq.h
index 12acb3f2fbc9..c6ea1867e0e3 100644
--- a/drivers/net/ethernet/cisco/enic/enic_wq.h
+++ b/drivers/net/ethernet/cisco/enic/enic_wq.h
@@ -4,4 +4,4 @@
 
 void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
 unsigned int enic_wq_cq_service(struct enic *enic, unsigned int cq_index,
-				unsigned int work_to_do);
+				unsigned int work_to_do, bool skbs_only);
diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.c b/drivers/net/ethernet/cisco/enic/enic_xdp.c
new file mode 100644
index 000000000000..dbb5f0e6c14f
--- /dev/null
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.c
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright 2026 Cisco Systems, Inc.  All rights reserved.
+
+#include <linux/bpf.h>
+#include <linux/filter.h>
+#include <linux/if_vlan.h>
+#include <linux/netdevice.h>
+#include <linux/netlink.h>
+#include <linux/rcupdate.h>
+#include <net/page_pool/helpers.h>
+#include <net/xdp.h>
+#include <trace/events/xdp.h>
+
+#include "enic.h"
+#include "enic_res.h"
+#include "enic_xdp.h"
+
+bool enic_xdp_attached(struct enic *enic)
+{
+	return rcu_access_pointer(enic->xdp_prog);
+}
+
+int enic_xdp_rxq_setup(struct enic *enic, unsigned int rq_index)
+{
+	struct enic_rq *rq = &enic->rq[rq_index];
+	int err;
+
+	if (!rq->xdp_enabled)
+		return 0;
+
+	err = xdp_rxq_info_reg(&rq->xdp_rxq, enic->netdev, rq_index,
+			       enic->napi[rq_index].napi_id);
+	if (err)
+		return err;
+
+	err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq,
+					 MEM_TYPE_PAGE_POOL, rq->pool);
+	if (err)
+		xdp_rxq_info_unreg(&rq->xdp_rxq);
+
+	return err;
+}
+
+void enic_xdp_rxq_teardown(struct enic_rq *rq)
+{
+	if (xdp_rxq_info_is_reg(&rq->xdp_rxq))
+		xdp_rxq_info_unreg(&rq->xdp_rxq);
+
+	rq->xdp_enabled = false;
+	rq->xdp_flush_pending = false;
+}
+
+static int enic_xdp_xmit_frame(struct enic *enic, unsigned int wq_index,
+			       struct xdp_frame *xdpf, dma_addr_t dma_addr,
+			       bool dma_mapped)
+{
+	struct enic_wq *wq;
+	struct vnic_wq_buf *buf;
+	struct vnic_wq *vwq;
+
+	if (unlikely(!xdpf->len))
+		return -EINVAL;
+	if (unlikely(xdp_frame_has_frags(xdpf)))
+		return -EOPNOTSUPP;
+	if (unlikely(xdpf->len > WQ_ENET_MAX_DESC_LEN))
+		return -E2BIG;
+
+	wq = &enic->wq[wq_index];
+	vwq = &wq->vwq;
+
+	spin_lock(&wq->lock);
+	if (unlikely(!READ_ONCE(enic->datapath_open))) {
+		spin_unlock(&wq->lock);
+		return -ENETDOWN;
+	}
+
+	/* Keep enough descriptors available for a maximum-sized stack skb.
+	 * XDP_TX and stack traffic share this WQ.
+	 */
+	if (unlikely(vnic_wq_desc_avail(vwq) <=
+		     MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)) {
+		spin_unlock(&wq->lock);
+		return -ENOSPC;
+	}
+
+	buf = vwq->to_use;
+	enic_queue_wq_desc(vwq, xdpf, dma_addr, xdpf->len, 0, 0, 1, 0);
+	buf->type = VNIC_WQ_BUF_XDP;
+	buf->xdp_dma_mapped = dma_mapped;
+	WRITE_ONCE(wq->xdp_tx_pending, true);
+
+	spin_unlock(&wq->lock);
+
+	return 0;
+}
+
+static void enic_xdp_wq_flush(struct enic *enic, struct enic_wq *wq)
+{
+	if (!READ_ONCE(wq->xdp_tx_pending))
+		return;
+
+	spin_lock(&wq->lock);
+	if (!READ_ONCE(enic->datapath_open)) {
+		WRITE_ONCE(wq->xdp_tx_pending, false);
+	} else if (wq->xdp_tx_pending) {
+		vnic_wq_doorbell(&wq->vwq);
+		WRITE_ONCE(wq->xdp_tx_pending, false);
+	}
+	spin_unlock(&wq->lock);
+}
+
+void enic_xdp_tx_flush(struct enic *enic, unsigned int rq_index)
+{
+	if (unlikely(!enic->wq_count))
+		return;
+
+	enic_xdp_wq_flush(enic, &enic->wq[rq_index % enic->wq_count]);
+}
+
+void enic_xdp_redirect_flush(struct enic *enic, unsigned int rq_index)
+{
+	struct enic_rq *rq = &enic->rq[rq_index];
+
+	if (rq->xdp_flush_pending) {
+		rq->xdp_flush_pending = false;
+		xdp_do_flush();
+	}
+}
+
+static void enic_xdp_recycle(struct enic_rq *rq, struct vnic_rq_buf *buf)
+{
+	page_pool_recycle_direct(rq->pool, buf->os_buf);
+	buf->os_buf = NULL;
+	buf->dma_addr = 0;
+}
+
+bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,
+		  struct vnic_rq_buf *buf, u16 *len)
+{
+	struct page *page = buf->os_buf;
+	unsigned char *page_addr = page_address(page);
+	struct bpf_prog *prog;
+	struct xdp_buff xdp;
+	u32 act;
+
+	xdp_init_buff(&xdp, buf->truesize, &rq->xdp_rxq);
+	xdp_prepare_buff(&xdp, page_addr + buf->offset - ENIC_XDP_HEADROOM,
+			 ENIC_XDP_HEADROOM, *len, false);
+	/* napi_get_frags() cannot preserve metadata stored in the RX page. */
+	xdp_set_data_meta_invalid(&xdp);
+
+	rcu_read_lock();
+	prog = rcu_dereference(enic->xdp_prog);
+	if (unlikely(!prog)) {
+		rcu_read_unlock();
+		return false;
+	}
+	act = bpf_prog_run_xdp(prog, &xdp);
+
+	switch (act) {
+	case XDP_PASS:
+		buf->offset = (unsigned char *)xdp.data - page_addr;
+		*len = xdp.data_end - xdp.data;
+		rq->stats.xdp_pass++;
+		rcu_read_unlock();
+		return false;
+	case XDP_TX: {
+		struct xdp_frame *xdpf;
+		dma_addr_t dma_addr;
+
+		xdpf = xdp_convert_buff_to_frame(&xdp);
+		if (unlikely(!xdpf)) {
+			trace_xdp_exception(enic->netdev, prog, act);
+			rq->stats.xdp_aborted++;
+			enic_xdp_recycle(rq, buf);
+			rcu_read_unlock();
+			return true;
+		}
+
+		dma_addr = page_pool_get_dma_addr(page) +
+			   ((unsigned char *)xdpf->data - page_addr);
+		dma_sync_single_for_device(&enic->pdev->dev, dma_addr, xdpf->len,
+					   DMA_BIDIRECTIONAL);
+		buf->os_buf = NULL;
+		buf->dma_addr = 0;
+		if (unlikely(!enic->wq_count ||
+			     enic_xdp_xmit_frame(enic,
+						 rq->vrq.index % enic->wq_count,
+						 xdpf, dma_addr, false))) {
+			xdp_return_frame_rx_napi(xdpf);
+			rq->stats.xdp_tx_drops++;
+		} else {
+			rq->stats.xdp_tx++;
+		}
+		rcu_read_unlock();
+		return true;
+	}
+	case XDP_DROP:
+		rq->stats.xdp_drop++;
+		break;
+	case XDP_REDIRECT:
+		if (unlikely(xdp_do_redirect(enic->netdev, &xdp, prog))) {
+			rq->stats.xdp_redirect_drops++;
+			break;
+		}
+		buf->os_buf = NULL;
+		buf->dma_addr = 0;
+		rq->stats.xdp_redirect++;
+		rq->xdp_flush_pending = true;
+		rcu_read_unlock();
+		return true;
+	case XDP_ABORTED:
+		trace_xdp_exception(enic->netdev, prog, act);
+		rq->stats.xdp_aborted++;
+		break;
+	default:
+		bpf_warn_invalid_xdp_action(enic->netdev, prog, act);
+		trace_xdp_exception(enic->netdev, prog, act);
+		rq->stats.xdp_invalid++;
+		break;
+	}
+
+	enic_xdp_recycle(rq, buf);
+	rcu_read_unlock();
+	return true;
+}
+
+static int enic_xdp_setup(struct net_device *netdev, struct bpf_prog *prog,
+			  struct netlink_ext_ack *extack)
+{
+	struct enic *enic = netdev_priv(netdev);
+	struct bpf_prog *old;
+	bool reload;
+	int err;
+
+	ASSERT_RTNL();
+	if (prog && !enic_xdp_supported(enic)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "XDP requires mixed RQ descriptors on a supported vNIC");
+		return -EOPNOTSUPP;
+	}
+
+	old = rcu_dereference_protected(enic->xdp_prog,
+					lockdep_rtnl_is_held());
+	reload = !old != !prog;
+
+	if (reload) {
+		err = enic_xdp_reload(netdev, old, prog);
+		if (err) {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "failed to reload ENIC receive queues for XDP");
+			return err;
+		}
+	} else {
+		rcu_assign_pointer(enic->xdp_prog, prog);
+	}
+
+	if (old)
+		bpf_prog_put(old);
+
+	return 0;
+}
+
+int enic_xdp(struct net_device *netdev, struct netdev_bpf *bpf)
+{
+	switch (bpf->command) {
+	case XDP_SETUP_PROG:
+		return enic_xdp_setup(netdev, bpf->prog, bpf->extack);
+	default:
+		return -EINVAL;
+	}
+}
+
+int enic_xdp_xmit(struct net_device *netdev, int n,
+		  struct xdp_frame **frames, u32 flags)
+{
+	struct enic *enic = netdev_priv(netdev);
+	struct enic_wq *wq;
+	unsigned int wq_index;
+	int sent = 0;
+
+	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
+		return -EINVAL;
+	if (unlikely(!enic_xdp_supported(enic)))
+		return -EOPNOTSUPP;
+	if (unlikely(!netif_running(netdev) || !netif_carrier_ok(netdev) ||
+		     !READ_ONCE(enic->datapath_open)))
+		return -ENETDOWN;
+	if (unlikely(!enic->wq_count))
+		return -ENXIO;
+
+	wq_index = smp_processor_id() % enic->wq_count;
+	wq = &enic->wq[wq_index];
+
+	while (sent < n) {
+		struct xdp_frame *xdpf = frames[sent];
+		dma_addr_t dma_addr;
+		int err;
+
+		if (unlikely(!xdpf->len || xdp_frame_has_frags(xdpf) ||
+			     xdpf->len > WQ_ENET_MAX_DESC_LEN))
+			break;
+
+		dma_addr = dma_map_single(&enic->pdev->dev, xdpf->data,
+					  xdpf->len, DMA_TO_DEVICE);
+		if (unlikely(dma_mapping_error(&enic->pdev->dev, dma_addr)))
+			break;
+
+		err = enic_xdp_xmit_frame(enic, wq_index, xdpf, dma_addr, true);
+		if (unlikely(err)) {
+			dma_unmap_single(&enic->pdev->dev, dma_addr, xdpf->len,
+					 DMA_TO_DEVICE);
+			break;
+		}
+		sent++;
+	}
+
+	if (flags & XDP_XMIT_FLUSH)
+		enic_xdp_wq_flush(enic, wq);
+
+	return sent;
+}
diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.h b/drivers/net/ethernet/cisco/enic/enic_xdp.h
index 87ae61c4974d..de6abc9c4e65 100644
--- a/drivers/net/ethernet/cisco/enic/enic_xdp.h
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.h
@@ -5,9 +5,32 @@
 #define _ENIC_XDP_H_
 
 #include <linux/skbuff.h>
+#include <linux/types.h>
 #include <net/xdp.h>
 
+struct enic;
+struct enic_rq;
+struct bpf_prog;
+struct net_device;
+struct netdev_bpf;
+struct vnic_rq_buf;
+struct xdp_frame;
+
 #define ENIC_XDP_HEADROOM	XDP_PACKET_HEADROOM
 #define ENIC_XDP_TAILROOM	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
 
+bool enic_xdp_attached(struct enic *enic);
+int enic_xdp(struct net_device *netdev, struct netdev_bpf *bpf);
+int enic_xdp_xmit(struct net_device *netdev, int n,
+		  struct xdp_frame **frames, u32 flags);
+int enic_xdp_reload(struct net_device *netdev, struct bpf_prog *old_prog,
+		    struct bpf_prog *new_prog);
+int enic_xdp_rxq_setup(struct enic *enic, unsigned int rq_index);
+void enic_xdp_rxq_teardown(struct enic_rq *rq);
+
+bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,
+		  struct vnic_rq_buf *buf, u16 *len);
+void enic_xdp_tx_flush(struct enic *enic, unsigned int rq_index);
+void enic_xdp_redirect_flush(struct enic *enic, unsigned int rq_index);
+
 #endif /* _ENIC_XDP_H_ */
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
index 92eec1455ceb..ffd59aa0b22b 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
@@ -889,6 +889,11 @@ int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
 	return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
 }
 
+bool vnic_dev_notify_is_allocated(struct vnic_dev *vdev)
+{
+	return vdev->notify;
+}
+
 static int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
 {
 	u64 a0, a1;
@@ -900,21 +905,24 @@ static int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
 	a1 += sizeof(struct vnic_devcmd_notify);
 
 	err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
-	vdev->notify = NULL;
-	vdev->notify_pa = 0;
-	vdev->notify_sz = 0;
 
 	return err;
 }
 
-int vnic_dev_notify_unset(struct vnic_dev *vdev)
+void vnic_dev_notify_free(struct vnic_dev *vdev)
 {
 	if (vdev->notify) {
 		dma_free_coherent(&vdev->pdev->dev,
 				  sizeof(struct vnic_devcmd_notify),
 				  vdev->notify, vdev->notify_pa);
 	}
+	vdev->notify = NULL;
+	vdev->notify_pa = 0;
+	vdev->notify_sz = 0;
+}
 
+int vnic_dev_notify_unset(struct vnic_dev *vdev)
+{
 	return vnic_dev_notify_unsetcmd(vdev);
 }
 
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.h b/drivers/net/ethernet/cisco/enic/vnic_dev.h
index 6a4d7ce3b636..690624ca8ade 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.h
@@ -143,7 +143,9 @@ int vnic_dev_add_addr(struct vnic_dev *vdev, const u8 *addr);
 int vnic_dev_del_addr(struct vnic_dev *vdev, const u8 *addr);
 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr);
 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr);
+bool vnic_dev_notify_is_allocated(struct vnic_dev *vdev);
 int vnic_dev_notify_unset(struct vnic_dev *vdev);
+void vnic_dev_notify_free(struct vnic_dev *vdev);
 int vnic_dev_link_status(struct vnic_dev *vdev);
 u32 vnic_dev_port_speed(struct vnic_dev *vdev);
 u32 vnic_dev_msg_lvl(struct vnic_dev *vdev);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (7 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX Satish Kharat
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Keep a per-CQ batch of adjacent AF_XDP TX descriptors owned by the same
pool. Complete the batch on pool change and before leaving CQ service.
The producer is enabled by the following patch.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic_wq.c | 63 ++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic_wq.c b/drivers/net/ethernet/cisco/enic/enic_wq.c
index c02829e4c41e..0f01721fb9a2 100644
--- a/drivers/net/ethernet/cisco/enic/enic_wq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_wq.c
@@ -3,6 +3,7 @@
 
 #include <net/netdev_queues.h>
 #include <net/xdp.h>
+#include <net/xdp_sock_drv.h>
 #include "enic_res.h"
 #include "enic.h"
 #include "enic_wq.h"
@@ -11,6 +12,41 @@
 #define ENET_CQ_DESC_COMP_NDX_BITS 14
 #define ENET_CQ_DESC_COMP_NDX_MASK GENMASK(ENET_CQ_DESC_COMP_NDX_BITS - 1, 0)
 
+struct enic_xsk_tx_completion {
+	struct xsk_buff_pool *pool;
+	u32 count;
+};
+
+static void enic_xsk_tx_complete(struct enic *enic, struct vnic_wq *wq,
+				 struct xsk_buff_pool *pool, u32 count)
+{
+	if (!count)
+		return;
+
+	xsk_tx_completed(pool, count);
+	enic->wq[wq->index].stats.xsk_tx_completed += count;
+}
+
+static void enic_xsk_tx_completion_flush(struct enic *enic,
+					 struct vnic_wq *wq,
+					 struct enic_xsk_tx_completion *comp)
+{
+	if (!comp->count)
+		return;
+
+	enic_xsk_tx_complete(enic, wq, comp->pool, comp->count);
+	comp->pool = NULL;
+	comp->count = 0;
+}
+
+static void enic_xsk_tx_buf_clear(struct vnic_wq_buf *buf)
+{
+	buf->os_buf = NULL;
+	buf->dma_addr = 0;
+	buf->xsk_pool = NULL;
+	buf->type = VNIC_WQ_BUF_SKB;
+}
+
 static void enic_wq_cq_desc_dec(const struct cq_desc *desc_arg, bool ext_wq,
 				u8 *type, u8 *color, u16 *q_number,
 				u16 *completed_index)
@@ -45,6 +81,16 @@ void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
 	struct enic *enic = vnic_dev_priv(wq->vdev);
 	struct xdp_frame *xdpf;
 
+	if (buf->type == VNIC_WQ_BUF_XSK) {
+		if (WARN_ON_ONCE(!buf->xsk_pool)) {
+			enic_xsk_tx_buf_clear(buf);
+			return;
+		}
+		enic_xsk_tx_complete(enic, wq, buf->xsk_pool, 1);
+		enic_xsk_tx_buf_clear(buf);
+		return;
+	}
+
 	if (buf->type == VNIC_WQ_BUF_XDP) {
 		xdpf = buf->os_buf;
 		if (buf->xdp_dma_mapped)
@@ -73,10 +119,21 @@ void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
 static void enic_wq_free_buf(struct vnic_wq *wq, struct cq_desc *cq_desc,
 			     struct vnic_wq_buf *buf, void *opaque)
 {
+	struct enic_xsk_tx_completion *comp = opaque;
 	struct enic *enic = vnic_dev_priv(wq->vdev);
 
 	enic->wq[wq->index].stats.cq_work++;
 	enic->wq[wq->index].stats.cq_bytes += buf->len;
+	if (buf->type == VNIC_WQ_BUF_XSK) {
+		if (comp->count && comp->pool != buf->xsk_pool)
+			enic_xsk_tx_completion_flush(enic, wq, comp);
+		comp->pool = buf->xsk_pool;
+		comp->count++;
+		enic_xsk_tx_buf_clear(buf);
+		return;
+	}
+
+	enic_xsk_tx_completion_flush(enic, wq, comp);
 	enic_free_wq_buf(wq, buf);
 }
 
@@ -84,6 +141,7 @@ static bool enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
 			    u8 type, u16 q_number, u16 completed_index,
 			    bool skbs_only)
 {
+	struct enic_xsk_tx_completion comp = {};
 	struct enic *enic = vnic_dev_priv(vdev);
 	struct vnic_wq_buf *buf;
 	struct vnic_wq *vwq;
@@ -92,7 +150,7 @@ static bool enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
 	vwq = &enic->wq[q_number].vwq;
 	if (skbs_only) {
 		/* A CQ entry can complete several descriptors. Defer the whole
-		 * entry if any buffer needs XDP or page-pool completion.
+		 * entry if any buffer needs XDP, XSK, or page-pool completion.
 		 */
 		buf = vwq->to_clean;
 		while (1) {
@@ -107,7 +165,8 @@ static bool enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
 	}
 
 	vnic_wq_service(vwq, cq_desc,
-			completed_index, enic_wq_free_buf, NULL);
+			completed_index, enic_wq_free_buf, &comp);
+	enic_xsk_tx_completion_flush(enic, vwq, &comp);
 
 	if (netif_tx_queue_stopped(netdev_get_tx_queue(enic->netdev, q_number))
 	    && vnic_wq_desc_avail(&enic->wq[q_number].vwq) >=

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (8 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-02  1:16   ` sashiko-bot
  2026-12-01  1:15 ` [PATCH RFC net-next 11/12] selftests/xsk: exercise XDP detach with bound socket Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 12/12] net: enic: count XDP and AF_XDP TX in queue statistics Satish Kharat
  11 siblings, 1 reply; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Bind AF_XDP UMEM per queue, switch the receive memory model, process
XSK RX actions and zero-copy TX batches, and account completions by
pool. Use the queue stop boundary before unmapping a pool.

Avoid reading the program-attach extack union member during XSK setup.
Preserve the initial TX NEED_WAKEUP state when an RX-only bound pool
later gains a TX socket.

Serialize RX and TX updates to the shared XSK wakeup byte. Clear RX
NEED_WAKEUP only after successful descriptor publication, and require
a frame large enough for two VLAN headers because XDP can disable
hardware stripping after pool binding.

At zero NAPI budget, complete only whole skb-owned WQ CQ spans;
defer XDP/XSK and RX work to a positive-budget poll.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h      |   7 +
 drivers/net/ethernet/cisco/enic/enic_main.c | 118 +++++++-
 drivers/net/ethernet/cisco/enic/enic_rq.c   |  50 +++-
 drivers/net/ethernet/cisco/enic/enic_wq.c   |  12 +-
 drivers/net/ethernet/cisco/enic/enic_xdp.c  | 402 +++++++++++++++++++++++++++-
 drivers/net/ethernet/cisco/enic/enic_xdp.h  |  17 ++
 6 files changed, 587 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 8a4d0194a5c9..3caa5ed77d50 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -243,6 +243,7 @@ struct enic_wq {
 	spinlock_t lock;		/* spinlock for wq */
 	struct vnic_wq vwq;
 	struct enic_wq_stats stats;
+	struct xsk_buff_pool *xsk_pool;
 	bool xdp_tx_pending;
 } ____cacheline_aligned;
 
@@ -250,8 +251,13 @@ struct enic_rq {
 	struct vnic_rq vrq;
 	struct enic_rq_stats stats;
 	struct page_pool *pool;
+	struct xsk_buff_pool *xsk_pool;
 	struct xdp_rxq_info xdp_rxq;
+	spinlock_t xsk_wakeup_lock;	/* serializes RX and TX wakeup bits */
+	spinlock_t xsk_tx_done_lock;	/* protects xsk_tx_done */
+	struct list_head xsk_tx_done;
 	bool xdp_enabled;
+	bool xsk_rx_active;
 	bool xdp_flush_pending;
 } ____cacheline_aligned;
 
@@ -321,6 +327,7 @@ struct enic {
 	struct bpf_prog __rcu *xdp_prog;
 	bool datapath_open;
 	bool dma_blocked;
+	bool xsk_wakeup_enabled;
 
 	struct vnic_intr *intr;
 	unsigned int intr_avail;
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 4c1ea75654bb..d14bc66f4178 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1382,6 +1382,7 @@ static int enic_poll(struct napi_struct *napi, int budget)
 	unsigned int rq_work_to_do = budget;
 	unsigned int wq_work_to_do = ENIC_WQ_NAPI_BUDGET;
 	unsigned int  work_done, rq_work_done = 0, wq_work_done;
+	bool xsk_tx_done;
 	int err;
 
 	wq_work_done = enic_wq_cq_service(enic, cq_wq, wq_work_to_do, !budget);
@@ -1391,11 +1392,13 @@ static int enic_poll(struct napi_struct *napi, int budget)
 						 0, 0);
 		return 0;
 	}
+	enic_xsk_rx_tx_flush(enic, 0);
 
 	if (budget > 0)
 		rq_work_done = enic_rq_cq_service(enic, cq_rq, rq_work_to_do);
 	enic_xdp_tx_flush(enic, 0);
 	enic_xdp_redirect_flush(enic, 0);
+	xsk_tx_done = enic_xsk_tx_service(enic, 0);
 
 	/* Accumulate intr event credits for this polling
 	 * cycle.  An intr event is the completion of a
@@ -1411,12 +1414,15 @@ static int enic_poll(struct napi_struct *napi, int budget)
 			0 /* don't reset intr timer */);
 
 	err = vnic_rq_fill(&enic->rq[0].vrq, enic_rq_alloc_buf);
+	enic_xsk_rx_refill_done(&enic->rq[0], err);
 
 	/* Buffer allocation failed. Stay in polling
 	 * mode so we can try to fill the ring again.
 	 */
 
-	if (err)
+	if (err && !enic_xsk_rx_need_wakeup(&enic->rq[0]))
+		rq_work_done = rq_work_to_do;
+	if (!xsk_tx_done)
 		rq_work_done = rq_work_to_do;
 	if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
 		/* Call the function which refreshes the intr coalescing timer
@@ -1490,6 +1496,7 @@ static int enic_poll_msix_wq(struct napi_struct *napi, int budget)
 	unsigned int wq_work_to_do = ENIC_WQ_NAPI_BUDGET;
 	unsigned int wq_work_done;
 	unsigned int wq_irq;
+	bool xsk_tx_done;
 
 	wq_irq = wq->index;
 	cq = enic_cq_wq(enic, wq_irq);
@@ -1502,11 +1509,12 @@ static int enic_poll_msix_wq(struct napi_struct *napi, int budget)
 						 0, 1);
 		return 0;
 	}
+	xsk_tx_done = enic_xsk_tx_service(enic, wq_index);
 
 	vnic_intr_return_credits(&enic->intr[intr], wq_work_done,
 				 0 /* don't unmask intr */,
 				 1 /* reset intr timer */);
-	if (!wq_work_done) {
+	if (!wq_work_done && xsk_tx_done) {
 		napi_complete(napi);
 		vnic_intr_unmask(&enic->intr[intr]);
 		return 0;
@@ -1529,6 +1537,8 @@ static int enic_poll_msix_rq(struct napi_struct *napi, int budget)
 	if (!budget)
 		return 0;
 
+	enic_xsk_rx_tx_flush(enic, rq);
+
 	/* Service RQ
 	 */
 
@@ -1549,12 +1559,13 @@ static int enic_poll_msix_rq(struct napi_struct *napi, int budget)
 			0 /* don't reset intr timer */);
 
 	err = vnic_rq_fill(&enic->rq[rq].vrq, enic_rq_alloc_buf);
+	enic_xsk_rx_refill_done(&enic->rq[rq], err);
 
 	/* Buffer allocation failed. Stay in polling mode
 	 * so we can try to fill the ring again.
 	 */
 
-	if (err)
+	if (err && !enic_xsk_rx_need_wakeup(&enic->rq[rq]))
 		work_done = work_to_do;
 	if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
 		/* Call the function which refreshes the intr coalescing timer
@@ -1851,6 +1862,8 @@ static void enic_clean_data_queues(struct enic *enic)
 		WRITE_ONCE(enic->wq[i].xdp_tx_pending, false);
 		spin_unlock_bh(&enic->wq[i].lock);
 	}
+	for (i = 0; i < enic->rq_count; i++)
+		enic_xsk_rx_tx_flush(enic, i);
 	for (i = 0; i < enic->rq_count; i++) {
 		vnic_rq_clean(&enic->rq[i].vrq, enic_free_rq_buf);
 		enic_xdp_rxq_teardown(&enic->rq[i]);
@@ -1926,6 +1939,7 @@ static int enic_open(struct net_device *netdev)
 		return -EBUSY;
 
 	WRITE_ONCE(enic->datapath_open, false);
+	WRITE_ONCE(enic->xsk_wakeup_enabled, false);
 	if (READ_ONCE(enic->dma_blocked))
 		return -EIO;
 	if (!enic->vlan_rewrite_valid) {
@@ -1966,15 +1980,21 @@ static int enic_open(struct net_device *netdev)
 	}
 
 	for (i = 0; i < enic->rq_count; i++) {
+		/* A bound XSK pool must not starve stack RX while no XDP
+		 * program is attached. Keep ordinary page-backed RX active.
+		 */
 		enic->rq[i].xdp_enabled = xdp_enabled;
-		/* create a page pool for each RQ */
-		pp_params.napi = &enic->napi[i];
-		pp_params.queue_idx = i;
-		enic->rq[i].pool = page_pool_create(&pp_params);
-		if (IS_ERR(enic->rq[i].pool)) {
-			err = PTR_ERR(enic->rq[i].pool);
-			enic->rq[i].pool = NULL;
-			goto err_out_free_rq;
+		enic->rq[i].xsk_rx_active = xdp_enabled && enic->rq[i].xsk_pool;
+		if (!enic->rq[i].xsk_rx_active) {
+			/* create a page pool for each page-backed RQ */
+			pp_params.napi = &enic->napi[i];
+			pp_params.queue_idx = i;
+			enic->rq[i].pool = page_pool_create(&pp_params);
+			if (IS_ERR(enic->rq[i].pool)) {
+				err = PTR_ERR(enic->rq[i].pool);
+				enic->rq[i].pool = NULL;
+				goto err_out_free_rq;
+			}
 		}
 		err = enic_xdp_rxq_setup(enic, i);
 		if (err)
@@ -1982,9 +2002,11 @@ static int enic_open(struct net_device *netdev)
 
 		/* enable rq before updating rq desc */
 		vnic_rq_enable(&enic->rq[i].vrq);
-		vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
+		err = vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
+		enic_xsk_rx_refill_done(&enic->rq[i], err);
 		/* Need at least one buffer on ring to get going */
-		if (vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
+		if (!enic->rq[i].xsk_rx_active &&
+		    vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
 			netdev_err(netdev, "Unable to alloc receive buffers\n");
 			err = -ENOMEM;
 			goto err_out_free_rq;
@@ -2016,6 +2038,7 @@ static int enic_open(struct net_device *netdev)
 	for (i = 0; i < enic->intr_count; i++)
 		vnic_intr_unmask(&enic->intr[i]);
 
+	WRITE_ONCE(enic->xsk_wakeup_enabled, true);
 	WRITE_ONCE(enic->datapath_open, true);
 	enic_notify_timer_start(enic);
 	enic_rfs_timer_start(enic);
@@ -2078,6 +2101,7 @@ static int __enic_stop(struct net_device *netdev, bool *reset_performed)
 
 	if (reset_performed)
 		*reset_performed = false;
+	WRITE_ONCE(enic->xsk_wakeup_enabled, false);
 	if (!READ_ONCE(enic->datapath_open))
 		return 0;
 	WRITE_ONCE(enic->datapath_open, false);
@@ -2200,12 +2224,69 @@ int enic_xdp_reload(struct net_device *netdev, struct bpf_prog *old_prog,
 	return err;
 }
 
+int enic_xdp_reload_pool_swap(struct net_device *netdev,
+			      unsigned int rq_index,
+			      struct xsk_buff_pool *new_pool,
+			      struct xsk_buff_pool **old_pool)
+{
+	struct enic *enic = netdev_priv(netdev);
+	int err, rollback_err;
+
+	ASSERT_RTNL();
+
+	*old_pool = enic->rq[rq_index].xsk_pool;
+	if (!netif_running(netdev)) {
+		enic->rq[rq_index].xsk_pool = new_pool;
+		enic->wq[rq_index].xsk_pool = new_pool;
+		return 0;
+	}
+
+	err = enic_stop(netdev);
+	if (err)
+		return err;
+
+	/* NAPI and both hardware rings are now quiesced. */
+	enic->rq[rq_index].xsk_pool = new_pool;
+	enic->wq[rq_index].xsk_pool = new_pool;
+	err = enic_open(netdev);
+	if (!err)
+		return 0;
+	if (!new_pool) {
+		if (READ_ONCE(enic->dma_blocked)) {
+			netdev_err(netdev,
+				   "failed to reopen after XSK pool removal: PCI DMA is blocked\n");
+		} else {
+			netdev_err(netdev,
+				   "failed to reopen after XSK pool removal: %d; scheduling reset\n",
+				   err);
+			schedule_work(&enic->reset);
+		}
+		return 0;
+	}
+
+	enic->rq[rq_index].xsk_pool = *old_pool;
+	enic->wq[rq_index].xsk_pool = *old_pool;
+	rollback_err = enic_open(netdev);
+	if (rollback_err)
+		netdev_err(netdev,
+			   "failed to restore interface after XSK pool setup error: %d\n",
+			   rollback_err);
+	if (rollback_err && !READ_ONCE(enic->dma_blocked))
+		schedule_work(&enic->reset);
+
+	return err;
+}
+
 static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
 {
+	struct enic *enic = netdev_priv(netdev);
 	bool running = netif_running(netdev);
 	int err = 0;
 
 	ASSERT_RTNL();
+	err = enic_xsk_validate_mtu(enic, new_mtu);
+	if (err)
+		return err;
 
 	if (running) {
 		err = enic_stop(netdev);
@@ -3086,6 +3167,7 @@ static const struct net_device_ops enic_netdev_dynamic_ops = {
 	.ndo_set_features	= enic_set_features,
 	.ndo_bpf		= enic_xdp,
 	.ndo_xdp_xmit		= enic_xdp_xmit,
+	.ndo_xsk_wakeup		= enic_xsk_wakeup,
 };
 
 static const struct net_device_ops enic_netdev_ops = {
@@ -3114,6 +3196,7 @@ static const struct net_device_ops enic_netdev_ops = {
 	.ndo_set_features	= enic_set_features,
 	.ndo_bpf		= enic_xdp,
 	.ndo_xdp_xmit		= enic_xdp_xmit,
+	.ndo_xsk_wakeup		= enic_xsk_wakeup,
 };
 
 static const struct netdev_stat_ops enic_netdev_stat_ops = {
@@ -3750,6 +3833,11 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	for (i = 0; i < enic->wq_count; i++)
 		spin_lock_init(&enic->wq[i].lock);
+	for (i = 0; i < enic->rq_count; i++) {
+		spin_lock_init(&enic->rq[i].xsk_wakeup_lock);
+		spin_lock_init(&enic->rq[i].xsk_tx_done_lock);
+		INIT_LIST_HEAD(&enic->rq[i].xsk_tx_done);
+	}
 
 	/* Register net device
 	 */
@@ -3775,7 +3863,9 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	netdev->stat_ops = &enic_netdev_stat_ops;
 	if (enic_xdp_supported(enic)) {
 		netdev->xdp_features = NETDEV_XDP_ACT_BASIC |
-			NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_NDO_XMIT;
+			NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_NDO_XMIT |
+			NETDEV_XDP_ACT_XSK_ZEROCOPY;
+		netdev->xdp_zc_max_segs = 1;
 	}
 
 	netdev->watchdog_timeo = 2 * HZ;
diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
index 350e42c556ad..f30de4757613 100644
--- a/drivers/net/ethernet/cisco/enic/enic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
@@ -4,6 +4,7 @@
 #include <linux/skbuff.h>
 #include <linux/if_vlan.h>
 #include <net/busy_poll.h>
+#include <net/xdp_sock_drv.h>
 #include "enic.h"
 #include "enic_res.h"
 #include "enic_rq.h"
@@ -282,6 +283,31 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
 	struct vnic_rq_buf *buf = rq->to_use;
 	struct page *page;
 	unsigned int truesize = len + headroom;
+	struct xdp_buff *xdp;
+
+	if (erq->xsk_rx_active) {
+		xdp = buf->os_buf;
+		if (!xdp) {
+			/* Set before checking the fill ring so userspace cannot
+			 * miss need_wakeup when the ring is empty.
+			 */
+			if (xsk_uses_need_wakeup(erq->xsk_pool))
+				enic_xsk_set_rx_need_wakeup(erq);
+			xdp = xsk_buff_alloc(erq->xsk_pool);
+			if (unlikely(!xdp)) {
+				rqstats->xsk_fill_empty++;
+				return -ENOMEM;
+			}
+			enic_xsk_buff_init(xdp);
+		}
+
+		buf->offset = 0;
+		buf->truesize = xdp->frame_sz;
+		dma_addr = xsk_buff_xdp_get_dma(xdp);
+		enic_queue_rq_desc(rq, xdp, os_buf_index, dma_addr, len);
+
+		return 0;
+	}
 
 	if (erq->xdp_enabled)
 		truesize += ENIC_XDP_TAILROOM;
@@ -314,8 +340,11 @@ void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
 	if (!buf->os_buf)
 		return;
 
-	page_pool_put_full_page(erq->pool, (struct page *)buf->os_buf,
-				true);
+	if (erq->xsk_rx_active)
+		xsk_buff_free(buf->os_buf);
+	else
+		page_pool_put_full_page(erq->pool, (struct page *)buf->os_buf,
+					true);
 	buf->os_buf = NULL;
 	buf->dma_addr = 0;
 }
@@ -355,6 +384,23 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 		/* Good receive
 		 */
 		rqstats->bytes += bytes_written;
+		if (erq->xsk_rx_active) {
+			napi = &enic->napi[rq->index];
+			skb = enic_xdp_run_xsk(enic, erq, buf, bytes_written);
+			if (!skb)
+				return;
+
+			enic_rq_set_skb_flags(rq, type, rss_hash, rss_type, fcoe,
+					      fcoe_fc_crc_ok, vlan_stripped,
+					      csum_not_calc, tcp_udp_csum_ok,
+					      ipv6, ipv4_csum_ok, vlan_tci, skb);
+			napi_gro_receive(napi, skb);
+			if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
+				enic_intr_update_pkt_size(&cq->pkt_size_counter,
+							  bytes_written);
+			return;
+		}
+
 		if (erq->xdp_enabled) {
 			page_pool_dma_sync_for_cpu(erq->pool,
 						   buf->os_buf, buf->offset,
diff --git a/drivers/net/ethernet/cisco/enic/enic_wq.c b/drivers/net/ethernet/cisco/enic/enic_wq.c
index 0f01721fb9a2..b165335d292a 100644
--- a/drivers/net/ethernet/cisco/enic/enic_wq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_wq.c
@@ -81,6 +81,16 @@ void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
 	struct enic *enic = vnic_dev_priv(wq->vdev);
 	struct xdp_frame *xdpf;
 
+	if (buf->type == VNIC_WQ_BUF_XSK_RX) {
+		if (WARN_ON_ONCE(!buf->os_buf)) {
+			enic_xsk_tx_buf_clear(buf);
+			return;
+		}
+		enic_xsk_rx_tx_complete(enic, buf->os_buf);
+		enic_xsk_tx_buf_clear(buf);
+		return;
+	}
+
 	if (buf->type == VNIC_WQ_BUF_XSK) {
 		if (WARN_ON_ONCE(!buf->xsk_pool)) {
 			enic_xsk_tx_buf_clear(buf);
@@ -149,7 +159,7 @@ static bool enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
 	spin_lock(&enic->wq[q_number].lock);
 	vwq = &enic->wq[q_number].vwq;
 	if (skbs_only) {
-		/* A CQ entry can complete several descriptors. Defer the whole
+		/* A CQ entry can complete several descriptors.  Defer the whole
 		 * entry if any buffer needs XDP, XSK, or page-pool completion.
 		 */
 		buf = vwq->to_clean;
diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.c b/drivers/net/ethernet/cisco/enic/enic_xdp.c
index dbb5f0e6c14f..b6989a4dd79b 100644
--- a/drivers/net/ethernet/cisco/enic/enic_xdp.c
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.c
@@ -9,12 +9,33 @@
 #include <linux/rcupdate.h>
 #include <net/page_pool/helpers.h>
 #include <net/xdp.h>
+#include <net/xdp_sock_drv.h>
 #include <trace/events/xdp.h>
 
 #include "enic.h"
 #include "enic_res.h"
 #include "enic_xdp.h"
 
+#define ENIC_XSK_TX_BATCH 64
+
+/* Overlay the driver-private XSK scratch space after struct xdp_buff. */
+struct enic_xsk_buff {
+	struct xdp_buff xdp;
+	struct list_head tx_done;
+};
+
+static struct enic_xsk_buff *enic_xsk_buff(struct xdp_buff *xdp)
+{
+	XSK_CHECK_PRIV_TYPE(struct enic_xsk_buff);
+
+	return container_of(xdp, struct enic_xsk_buff, xdp);
+}
+
+void enic_xsk_buff_init(struct xdp_buff *xdp)
+{
+	INIT_LIST_HEAD(&enic_xsk_buff(xdp)->tx_done);
+}
+
 bool enic_xdp_attached(struct enic *enic)
 {
 	return rcu_access_pointer(enic->xdp_prog);
@@ -33,8 +54,13 @@ int enic_xdp_rxq_setup(struct enic *enic, unsigned int rq_index)
 	if (err)
 		return err;
 
-	err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq,
-					 MEM_TYPE_PAGE_POOL, rq->pool);
+	if (rq->xsk_rx_active)
+		err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq,
+						 MEM_TYPE_XSK_BUFF_POOL,
+						 rq->xsk_pool);
+	else
+		err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq,
+						 MEM_TYPE_PAGE_POOL, rq->pool);
 	if (err)
 		xdp_rxq_info_unreg(&rq->xdp_rxq);
 
@@ -47,6 +73,7 @@ void enic_xdp_rxq_teardown(struct enic_rq *rq)
 		xdp_rxq_info_unreg(&rq->xdp_rxq);
 
 	rq->xdp_enabled = false;
+	rq->xsk_rx_active = false;
 	rq->xdp_flush_pending = false;
 }
 
@@ -94,6 +121,36 @@ static int enic_xdp_xmit_frame(struct enic *enic, unsigned int wq_index,
 	return 0;
 }
 
+static int enic_xdp_xmit_xsk_rx(struct enic *enic, unsigned int wq_index,
+				struct xdp_buff *xdp, dma_addr_t dma_addr,
+				unsigned int len)
+{
+	struct enic_wq *wq = &enic->wq[wq_index];
+	struct vnic_wq_buf *buf;
+
+	if (unlikely(!len || len > WQ_ENET_MAX_DESC_LEN))
+		return -EINVAL;
+
+	spin_lock(&wq->lock);
+	if (unlikely(!READ_ONCE(enic->datapath_open))) {
+		spin_unlock(&wq->lock);
+		return -ENETDOWN;
+	}
+	if (unlikely(vnic_wq_desc_avail(&wq->vwq) <=
+		     MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)) {
+		spin_unlock(&wq->lock);
+		return -ENOSPC;
+	}
+
+	buf = wq->vwq.to_use;
+	enic_queue_wq_desc(&wq->vwq, xdp, dma_addr, len, 0, 0, 1, 0);
+	buf->type = VNIC_WQ_BUF_XSK_RX;
+	WRITE_ONCE(wq->xdp_tx_pending, true);
+	spin_unlock(&wq->lock);
+
+	return 0;
+}
+
 static void enic_xdp_wq_flush(struct enic *enic, struct enic_wq *wq)
 {
 	if (!READ_ONCE(wq->xdp_tx_pending))
@@ -225,6 +282,345 @@ bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,
 	return true;
 }
 
+struct sk_buff *enic_xdp_run_xsk(struct enic *enic, struct enic_rq *rq,
+				 struct vnic_rq_buf *buf, u16 len)
+{
+	struct xdp_buff *xdp = buf->os_buf;
+	struct bpf_prog *prog;
+	struct sk_buff *skb;
+	u32 act;
+
+	xsk_buff_dma_sync_for_cpu(xdp);
+	xsk_buff_set_size(xdp, len);
+	rq->stats.xsk_rx_pkts++;
+	rq->stats.xsk_rx_bytes += len;
+
+	rcu_read_lock();
+	prog = rcu_dereference(enic->xdp_prog);
+	/* A pool may remain bound without an attached XDP program. */
+	act = prog ? bpf_prog_run_xdp(prog, xdp) : XDP_PASS;
+	switch (act) {
+	case XDP_PASS:
+		skb = xdp_build_skb_from_zc(xdp);
+		if (unlikely(!skb)) {
+			rq->stats.no_skb++;
+			rq->stats.xdp_drop++;
+			goto out_free;
+		}
+		buf->os_buf = NULL;
+		buf->dma_addr = 0;
+		rq->stats.xdp_pass++;
+		rcu_read_unlock();
+		return skb;
+	case XDP_TX: {
+		unsigned int xdp_len = xdp->data_end - xdp->data;
+		dma_addr_t dma_addr;
+
+		if (unlikely(!xdp_len || xdp_len > WQ_ENET_MAX_DESC_LEN)) {
+			rq->stats.xdp_tx_drops++;
+			break;
+		}
+
+		/* xdp->data may have moved. Derive DMA from the UMEM frame base
+		 * and synchronize the exact post-BPF range for the device.
+		 */
+		dma_addr = xsk_buff_xdp_get_frame_dma(xdp) +
+			   xsk_pool_get_headroom(rq->xsk_pool) -
+			   XDP_PACKET_HEADROOM +
+			   (xdp->data - xdp->data_hard_start);
+		xsk_buff_raw_dma_sync_for_device(rq->xsk_pool, dma_addr, xdp_len);
+		if (unlikely(!enic->wq_count ||
+			     enic_xdp_xmit_xsk_rx(enic,
+						  rq->vrq.index %
+						  enic->wq_count,
+						  xdp, dma_addr, xdp_len))) {
+			rq->stats.xdp_tx_drops++;
+		} else {
+			buf->os_buf = NULL;
+			buf->dma_addr = 0;
+			rq->stats.xdp_tx++;
+			rcu_read_unlock();
+			return NULL;
+		}
+		break;
+	}
+	case XDP_REDIRECT:
+		if (unlikely(xdp_do_redirect(enic->netdev, xdp, prog))) {
+			rq->stats.xdp_redirect_drops++;
+			break;
+		}
+		buf->os_buf = NULL;
+		buf->dma_addr = 0;
+		rq->stats.xdp_redirect++;
+		rq->xdp_flush_pending = true;
+		rcu_read_unlock();
+		return NULL;
+	case XDP_DROP:
+		rq->stats.xdp_drop++;
+		break;
+	case XDP_ABORTED:
+		trace_xdp_exception(enic->netdev, prog, act);
+		rq->stats.xdp_aborted++;
+		break;
+	default:
+		bpf_warn_invalid_xdp_action(enic->netdev, prog, act);
+		trace_xdp_exception(enic->netdev, prog, act);
+		rq->stats.xdp_invalid++;
+		break;
+	}
+
+out_free:
+	xsk_buff_free(xdp);
+	buf->os_buf = NULL;
+	buf->dma_addr = 0;
+	rcu_read_unlock();
+	return NULL;
+}
+
+int enic_xsk_validate_mtu(struct enic *enic, unsigned int mtu)
+{
+	unsigned int frame_size, i;
+
+	for (i = 0; i < enic->rq_count; i++) {
+		if (!enic->rq[i].xsk_pool)
+			continue;
+
+		frame_size = xsk_pool_get_rx_frame_size(enic->rq[i].xsk_pool);
+		if (frame_size >= mtu + ENIC_RX_MAX_L2_LEN)
+			continue;
+
+		netdev_err(enic->netdev,
+			   "MTU %u requires an XSK frame of at least %u bytes on queue %u (have %u)\n",
+			   mtu, mtu + ENIC_RX_MAX_L2_LEN, i, frame_size);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+bool enic_xsk_rx_need_wakeup(struct enic_rq *rq)
+{
+	return rq->xsk_rx_active && xsk_uses_need_wakeup(rq->xsk_pool);
+}
+
+void enic_xsk_set_rx_need_wakeup(struct enic_rq *rq)
+{
+	spin_lock_bh(&rq->xsk_wakeup_lock);
+	xsk_set_rx_need_wakeup(rq->xsk_pool);
+	spin_unlock_bh(&rq->xsk_wakeup_lock);
+}
+
+void enic_xsk_rx_refill_done(struct enic_rq *rq, int err)
+{
+	if (err || !enic_xsk_rx_need_wakeup(rq))
+		return;
+
+	spin_lock_bh(&rq->xsk_wakeup_lock);
+	xsk_clear_rx_need_wakeup(rq->xsk_pool);
+	spin_unlock_bh(&rq->xsk_wakeup_lock);
+}
+
+bool enic_xsk_tx_service(struct enic *enic, unsigned int wq_index)
+{
+	const unsigned int reserve = MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS;
+	struct enic_wq *wq = &enic->wq[wq_index];
+	struct xsk_buff_pool *pool = wq->xsk_pool;
+	struct xdp_desc *descs;
+	unsigned int capacity;
+	unsigned int sent = 0;
+	unsigned int i;
+	bool done;
+
+	if (!pool)
+		return true;
+	if (!pool->tx_descs)
+		return true;
+	/* Set before checking carrier or the TX ring to close the producer race.
+	 * Clear it again only when this NAPI remains in polling mode.
+	 */
+	if (xsk_uses_need_wakeup(pool)) {
+		spin_lock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
+		xsk_set_tx_need_wakeup(pool);
+		spin_unlock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
+	}
+
+	if (unlikely(!netif_carrier_ok(enic->netdev)))
+		return true;
+
+	spin_lock(&wq->lock);
+	if (unlikely(!READ_ONCE(enic->datapath_open))) {
+		done = true;
+		goto out_need_wakeup;
+	}
+
+	capacity = vnic_wq_desc_avail(&wq->vwq);
+	if (capacity <= reserve) {
+		wq->stats.xsk_tx_no_room++;
+		/* Outstanding WQ descriptors will raise the next completion
+		 * interrupt; do not spin this NAPI while waiting for room.
+		 */
+		done = true;
+		goto out_need_wakeup;
+	}
+	capacity = min(capacity - reserve, ENIC_XSK_TX_BATCH);
+
+	/* The batch API transfers ownership of every returned descriptor.
+	 * Bound the batch by available WQ space first, then post the whole batch
+	 * while holding the same lock.
+	 */
+	sent = xsk_tx_peek_release_desc_batch(pool, capacity);
+	descs = pool->tx_descs;
+	for (i = 0; i < sent; i++) {
+		struct vnic_wq_buf *buf = wq->vwq.to_use;
+		dma_addr_t dma_addr;
+
+		dma_addr = xsk_buff_raw_get_dma(pool, descs[i].addr);
+		xsk_buff_raw_dma_sync_for_device(pool, dma_addr, descs[i].len);
+		enic_queue_wq_desc(&wq->vwq, NULL, dma_addr, descs[i].len,
+				   0, 0, 1, 0);
+		buf->type = VNIC_WQ_BUF_XSK;
+		buf->xsk_pool = pool;
+		wq->stats.xsk_tx_pkts++;
+		wq->stats.xsk_tx_bytes += descs[i].len;
+	}
+
+	if (sent) {
+		vnic_wq_doorbell(&wq->vwq);
+		WRITE_ONCE(wq->xdp_tx_pending, false);
+	}
+	done = sent < capacity;
+
+out_need_wakeup:
+	spin_unlock(&wq->lock);
+	if (!done && xsk_uses_need_wakeup(pool)) {
+		spin_lock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
+		xsk_clear_tx_need_wakeup(pool);
+		spin_unlock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
+	}
+
+	return done;
+}
+
+static void enic_xsk_schedule_napi(struct napi_struct *napi)
+{
+	if (!napi_if_scheduled_mark_missed(napi))
+		napi_schedule(napi);
+}
+
+void enic_xsk_rx_tx_complete(struct enic *enic, struct xdp_buff *xdp)
+{
+	struct enic_xsk_buff *xskb = enic_xsk_buff(xdp);
+	unsigned int rq_index = xdp->rxq->queue_index;
+	struct enic_rq *rq;
+
+	if (WARN_ON_ONCE(rq_index >= enic->rq_count) ||
+	    WARN_ON_ONCE(!list_empty(&xskb->tx_done)))
+		return;
+
+	rq = &enic->rq[rq_index];
+	spin_lock_bh(&rq->xsk_tx_done_lock);
+	list_add_tail(&xskb->tx_done, &rq->xsk_tx_done);
+	spin_unlock_bh(&rq->xsk_tx_done_lock);
+
+	if (READ_ONCE(enic->xsk_wakeup_enabled) &&
+	    vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
+		enic_xsk_schedule_napi(&enic->napi[rq_index]);
+}
+
+void enic_xsk_rx_tx_flush(struct enic *enic, unsigned int rq_index)
+{
+	struct enic_rq *rq = &enic->rq[rq_index];
+	struct enic_xsk_buff *xskb, *tmp;
+	LIST_HEAD(done);
+
+	spin_lock_bh(&rq->xsk_tx_done_lock);
+	list_splice_init(&rq->xsk_tx_done, &done);
+	spin_unlock_bh(&rq->xsk_tx_done_lock);
+
+	list_for_each_entry_safe(xskb, tmp, &done, tx_done) {
+		list_del_init(&xskb->tx_done);
+		xsk_buff_free(&xskb->xdp);
+	}
+}
+
+int enic_xsk_wakeup(struct net_device *netdev, u32 queue_id, u32 flags)
+{
+	struct enic *enic = netdev_priv(netdev);
+	struct xsk_buff_pool *pool;
+
+	if (flags & ~(XDP_WAKEUP_RX | XDP_WAKEUP_TX))
+		return -EINVAL;
+	if (!flags)
+		flags = XDP_WAKEUP_RX | XDP_WAKEUP_TX;
+	if (!netif_running(netdev) ||
+	    !READ_ONCE(enic->xsk_wakeup_enabled))
+		return -ENETDOWN;
+	if (queue_id >= enic->rq_count || queue_id >= enic->wq_count)
+		return -EINVAL;
+
+	pool = READ_ONCE(enic->rq[queue_id].xsk_pool);
+	if (!pool || pool != READ_ONCE(enic->wq[queue_id].xsk_pool))
+		return -ENXIO;
+
+	if (vnic_dev_get_intr_mode(enic->vdev) != VNIC_DEV_INTR_MODE_MSIX) {
+		enic_xsk_schedule_napi(&enic->napi[0]);
+		return 0;
+	}
+
+	if (flags & XDP_WAKEUP_RX)
+		enic_xsk_schedule_napi(&enic->napi[queue_id]);
+	if (flags & XDP_WAKEUP_TX)
+		enic_xsk_schedule_napi(&enic->napi[enic_cq_wq(enic,
+							      queue_id)]);
+
+	return 0;
+}
+
+static int enic_xsk_setup_pool(struct net_device *netdev,
+			       struct netdev_bpf *bpf)
+{
+	struct xsk_buff_pool *pool = bpf->xsk.pool;
+	struct xsk_buff_pool *old_pool;
+	struct enic *enic = netdev_priv(netdev);
+	unsigned int queue_id = bpf->xsk.queue_id;
+	unsigned int frame_size;
+	int err;
+
+	ASSERT_RTNL();
+
+	if (pool && !enic_xdp_supported(enic))
+		return -EOPNOTSUPP;
+
+	if (queue_id >= enic->rq_count || queue_id >= enic->wq_count)
+		return -EINVAL;
+	if (pool == enic->rq[queue_id].xsk_pool)
+		return 0;
+
+	if (pool) {
+		frame_size = xsk_pool_get_rx_frame_size(pool);
+		if (frame_size < netdev->mtu + ENIC_RX_MAX_L2_LEN)
+			return -EINVAL;
+		if (xsk_pool_get_chunk_size(pool) > WQ_ENET_MAX_DESC_LEN)
+			return -EINVAL;
+
+		err = xsk_pool_dma_map(pool, &enic->pdev->dev, 0);
+		if (err)
+			return err;
+	}
+
+	err = enic_xdp_reload_pool_swap(netdev, queue_id, pool, &old_pool);
+	if (err) {
+		if (pool)
+			xsk_pool_dma_unmap(pool, 0);
+		return err;
+	}
+
+	if (old_pool)
+		xsk_pool_dma_unmap(old_pool, 0);
+
+	return 0;
+}
+
 static int enic_xdp_setup(struct net_device *netdev, struct bpf_prog *prog,
 			  struct netlink_ext_ack *extack)
 {
@@ -266,6 +662,8 @@ int enic_xdp(struct net_device *netdev, struct netdev_bpf *bpf)
 	switch (bpf->command) {
 	case XDP_SETUP_PROG:
 		return enic_xdp_setup(netdev, bpf->prog, bpf->extack);
+	case XDP_SETUP_XSK_POOL:
+		return enic_xsk_setup_pool(netdev, bpf);
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.h b/drivers/net/ethernet/cisco/enic/enic_xdp.h
index de6abc9c4e65..2abdff4ba123 100644
--- a/drivers/net/ethernet/cisco/enic/enic_xdp.h
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.h
@@ -15,6 +15,7 @@ struct net_device;
 struct netdev_bpf;
 struct vnic_rq_buf;
 struct xdp_frame;
+struct xsk_buff_pool;
 
 #define ENIC_XDP_HEADROOM	XDP_PACKET_HEADROOM
 #define ENIC_XDP_TAILROOM	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
@@ -25,11 +26,27 @@ int enic_xdp_xmit(struct net_device *netdev, int n,
 		  struct xdp_frame **frames, u32 flags);
 int enic_xdp_reload(struct net_device *netdev, struct bpf_prog *old_prog,
 		    struct bpf_prog *new_prog);
+int enic_xdp_reload_pool_swap(struct net_device *netdev,
+			      unsigned int rq_index,
+			      struct xsk_buff_pool *new_pool,
+			      struct xsk_buff_pool **old_pool);
+int enic_xsk_validate_mtu(struct enic *enic, unsigned int mtu);
+bool enic_xsk_rx_need_wakeup(struct enic_rq *rq);
+void enic_xsk_set_rx_need_wakeup(struct enic_rq *rq);
+void enic_xsk_rx_refill_done(struct enic_rq *rq, int err);
+bool enic_xsk_tx_service(struct enic *enic, unsigned int wq_index);
+int enic_xsk_wakeup(struct net_device *netdev, u32 queue_id, u32 flags);
+void enic_xsk_buff_init(struct xdp_buff *xdp);
+void enic_xsk_rx_tx_complete(struct enic *enic, struct xdp_buff *xdp);
+void enic_xsk_rx_tx_flush(struct enic *enic, unsigned int rq_index);
+
 int enic_xdp_rxq_setup(struct enic *enic, unsigned int rq_index);
 void enic_xdp_rxq_teardown(struct enic_rq *rq);
 
 bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,
 		  struct vnic_rq_buf *buf, u16 *len);
+struct sk_buff *enic_xdp_run_xsk(struct enic *enic, struct enic_rq *rq,
+				 struct vnic_rq_buf *buf, u16 len);
 void enic_xdp_tx_flush(struct enic *enic, unsigned int rq_index);
 void enic_xdp_redirect_flush(struct enic *enic, unsigned int rq_index);
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 11/12] selftests/xsk: exercise XDP detach with bound socket
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (9 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  2026-12-01  1:15 ` [PATCH RFC net-next 12/12] net: enic: count XDP and AF_XDP TX in queue statistics Satish Kharat
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

Check the detach return status and test traffic after XDP detach and
reattach while an XSK remains bound. Clean socket and UMEM owners on
second-step barrier failure.

Port the registration and documentation to the current net-next selftest
layout.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 tools/testing/selftests/net/lib/xsk/test_xsk.c   | 51 +++++++++++++++++++++++-
 tools/testing/selftests/net/lib/xsk/test_xsk.h   |  2 +
 tools/testing/selftests/net/lib/xsk/xsk.c        |  4 +-
 tools/testing/selftests/net/lib/xsk/xsk.h        |  2 +-
 tools/testing/selftests/net/lib/xsk/xskxceiver.c | 23 ++++++-----
 5 files changed, 67 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index ca161511f1e5..edcaca946ac5 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1728,7 +1728,11 @@ static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog
 {
 	int err;
 
-	xsk_detach_xdp_program(ifobj->ifindex, mode_to_xdp_flags(ifobj->mode));
+	err = xsk_detach_xdp_program(ifobj->ifindex,
+				     mode_to_xdp_flags(ifobj->mode));
+	if (err)
+		return err;
+
 	err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode));
 	if (err) {
 		ksft_print_msg("Error attaching XDP program\n");
@@ -1841,7 +1845,12 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
 			test->use_barrier = false;
 			pthread_join(t0, NULL);
 			clean_sockets(test, ifobj1);
-			clean_umem(test, ifobj1, NULL);
+			if (test->current_step > 1) {
+				clean_sockets(test, ifobj2);
+				clean_umem(test, ifobj1, ifobj2);
+			} else {
+				clean_umem(test, ifobj1, NULL);
+			}
 			return TEST_FAILURE;
 		}
 	}
@@ -1975,6 +1984,44 @@ int testapp_xdp_prog_cleanup(struct test_spec *test)
 	return testapp_validate_traffic(test);
 }
 
+int testapp_xdp_prog_detach_xsk_bound(struct test_spec *test)
+{
+	struct ifobject *ifobj_rx = test->ifobj_rx;
+	int err;
+
+	test->total_steps = 2;
+	err = testapp_validate_traffic(test);
+	if (err) {
+		if (err == TEST_FAILURE)
+			test->fail = true;
+		return err;
+	}
+
+	err = xsk_detach_xdp_program(ifobj_rx->ifindex,
+				     mode_to_xdp_flags(ifobj_rx->mode));
+	if (err) {
+		ksft_print_msg("Error detaching XDP program while XSK is bound: %s\n",
+			       strerror(-err));
+		test->fail = true;
+		clean_sockets(test, test->ifobj_rx);
+		clean_sockets(test, test->ifobj_tx);
+		clean_umem(test, test->ifobj_rx, test->ifobj_tx);
+		return TEST_FAILURE;
+	}
+
+	ifobj_rx->xdp_prog = NULL;
+	err = testapp_validate_traffic(test);
+	if (err == TEST_FAILURE)
+		test->fail = true;
+	if (err && test->current_step < test->total_steps) {
+		clean_sockets(test, test->ifobj_rx);
+		clean_sockets(test, test->ifobj_tx);
+		clean_umem(test, test->ifobj_rx, test->ifobj_tx);
+	}
+
+	return err;
+}
+
 int testapp_headroom(struct test_spec *test)
 {
 	test->ifobj_rx->xsk->umem->frame_headroom = UMEM_HEADROOM_TEST_SIZE;
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 2506b0dcc6bf..12b9fc7e2933 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -266,6 +266,7 @@ int testapp_unaligned_inv_desc_mb(struct test_spec *test);
 int testapp_xdp_drop(struct test_spec *test);
 int testapp_xdp_metadata(struct test_spec *test);
 int testapp_xdp_metadata_mb(struct test_spec *test);
+int testapp_xdp_prog_detach_xsk_bound(struct test_spec *test);
 int testapp_xdp_prog_cleanup(struct test_spec *test);
 int testapp_xdp_shared_umem(struct test_spec *test);
 
@@ -297,6 +298,7 @@ static const struct test_spec tests[] = {
 	{.name = "TOO_MANY_FRAGS", .test_func = testapp_too_many_frags},
 	{.name = "XDP_ADJUST_TAIL_SHRINK", .test_func = testapp_adjust_tail_shrink},
 	{.name = "TX_QUEUE_CONSUMER", .test_func = testapp_tx_queue_consumer},
+	{.name = "XDP_PROG_DETACH_XSK_BOUND", .test_func = testapp_xdp_prog_detach_xsk_bound},
 	/* Flaky tests */
 	{.name = "XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF", .test_func = testapp_adjust_tail_shrink_mb},
 	{.name = "XDP_ADJUST_TAIL_GROW", .test_func = testapp_adjust_tail_grow},
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c
index 4e9d14f883ac..f16a233dd83d 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk.c
@@ -429,9 +429,9 @@ int xsk_attach_xdp_program(struct bpf_program *prog, int ifindex, u32 xdp_flags)
 	return bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL);
 }
 
-void xsk_detach_xdp_program(int ifindex, u32 xdp_flags)
+int xsk_detach_xdp_program(int ifindex, u32 xdp_flags)
 {
-	bpf_xdp_detach(ifindex, xdp_flags, NULL);
+	return bpf_xdp_detach(ifindex, xdp_flags, NULL);
 }
 
 void xsk_clear_xskmap(struct bpf_map *map)
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h
index 3f1fea999763..6d3f40becbdb 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk.h
@@ -205,7 +205,7 @@ struct xsk_umem_config {
 };
 
 int xsk_attach_xdp_program(struct bpf_program *prog, int ifindex, u32 xdp_flags);
-void xsk_detach_xdp_program(int ifindex, u32 xdp_flags);
+int xsk_detach_xdp_program(int ifindex, u32 xdp_flags);
 int xsk_update_xskmap(struct bpf_map *map, struct xsk_socket *xsk, u32 index);
 void xsk_clear_xskmap(struct bpf_map *map);
 bool xsk_is_in_mode(u32 ifindex, int mode);
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 0a63651434a5..af096119d6b2 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -41,18 +41,21 @@
  *            Reduce the size of the RX ring to a fraction of the fill ring size.
  *       iv.  fill queue empty
  *            Do not populate the fill queue and then try to receive pkts.
- *    f. bpf_link resource persistence
- *       Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,
- *       then remove xsk sockets from queue 0 on both veth interfaces and
- *       finally run a traffic on queues ids 1
- *    g. unaligned mode
- *    h. tests for invalid and corner case Tx descriptors so that the correct ones
+ *    f. XDP program resource persistence
+ *       Configure two sockets per interface, run traffic on the first socket,
+ *       replace the XSKMAP entry with the second socket without reattaching the
+ *       program, then verify traffic again.
+ *    g. XDP program detach while an XSK is bound
+ *       Run traffic, detach and reattach the XDP program without closing the
+ *       socket, then verify traffic again.
+ *    h. unaligned mode
+ *    i. tests for invalid and corner case Tx descriptors so that the correct ones
  *       are discarded and let through, respectively.
- *    i. 2K frame size tests
- *    j. If multi-buffer is supported, send 9k packets divided into 3 frames
- *    k. If multi-buffer and huge pages are supported, send 9k packets in a single frame
+ *    j. 2K frame size tests
+ *    k. If multi-buffer is supported, send 9k packets divided into 3 frames
+ *    l. If multi-buffer and huge pages are supported, send 9k packets in a single frame
  *       using unaligned mode
- *    l. If multi-buffer is supported, try various nasty combinations of descriptors to
+ *    m. If multi-buffer is supported, try various nasty combinations of descriptors to
  *       check if they pass the validation or not
  *
  * Flow:

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC net-next 12/12] net: enic: count XDP and AF_XDP TX in queue statistics
  2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
                   ` (10 preceding siblings ...)
  2026-12-01  1:15 ` [PATCH RFC net-next 11/12] selftests/xsk: exercise XDP detach with bound socket Satish Kharat
@ 2026-12-01  1:15 ` Satish Kharat
  11 siblings, 0 replies; 18+ messages in thread
From: Satish Kharat @ 2026-12-01  1:15 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Magnus Karlsson, Maciej Fijalkowski, Simon Horman, Shuah Khan,
	bpf, linux-kselftest, linux-kernel, Satish Kharat, Hyong Youb Kim

The netdev TX queue-statistics callback reports packets and bytes from
the ENIC work queue. Stack skb transmit updates these counters, but
native XDP and AF_XDP transmit do not. The XDP driver selftest therefore
sees fewer TX packets than the XDP program transmitted.

Count successfully queued XDP frames, XSK RX-to-TX frames, and AF_XDP TX
descriptors under the existing work-queue lock. Keep the XSK-specific
counters for AF_XDP diagnostics.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic_xdp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.c b/drivers/net/ethernet/cisco/enic/enic_xdp.c
index b6989a4dd79b..f9d3090251ec 100644
--- a/drivers/net/ethernet/cisco/enic/enic_xdp.c
+++ b/drivers/net/ethernet/cisco/enic/enic_xdp.c
@@ -114,6 +114,8 @@ static int enic_xdp_xmit_frame(struct enic *enic, unsigned int wq_index,
 	enic_queue_wq_desc(vwq, xdpf, dma_addr, xdpf->len, 0, 0, 1, 0);
 	buf->type = VNIC_WQ_BUF_XDP;
 	buf->xdp_dma_mapped = dma_mapped;
+	wq->stats.packets++;
+	wq->stats.bytes += xdpf->len;
 	WRITE_ONCE(wq->xdp_tx_pending, true);
 
 	spin_unlock(&wq->lock);
@@ -145,6 +147,8 @@ static int enic_xdp_xmit_xsk_rx(struct enic *enic, unsigned int wq_index,
 	buf = wq->vwq.to_use;
 	enic_queue_wq_desc(&wq->vwq, xdp, dma_addr, len, 0, 0, 1, 0);
 	buf->type = VNIC_WQ_BUF_XSK_RX;
+	wq->stats.packets++;
+	wq->stats.bytes += len;
 	WRITE_ONCE(wq->xdp_tx_pending, true);
 	spin_unlock(&wq->lock);
 
@@ -480,6 +484,8 @@ bool enic_xsk_tx_service(struct enic *enic, unsigned int wq_index)
 				   0, 0, 1, 0);
 		buf->type = VNIC_WQ_BUF_XSK;
 		buf->xsk_pool = pool;
+		wq->stats.packets++;
+		wq->stats.bytes += descs[i].len;
 		wq->stats.xsk_tx_pkts++;
 		wq->stats.xsk_tx_bytes += descs[i].len;
 	}

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters
  2026-12-01  1:15 ` [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters Satish Kharat
@ 2026-12-02  1:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-02  1:16 UTC (permalink / raw)
  To: Satish Kharat; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: enic: per-queue XSK packet, byte, and alloc stats in
  ethtool -S
--

commit b7fb77ac6d4bb8b7f60d52b0b1a25ef5f8a5098c
Author: Satish Kharat <satishkh@cisco.com>

net: enic: expose per-queue XDP and AF_XDP counters

This commit adds per-queue XDP and AF_XDP statistics to struct
enic_rq_stats and struct enic_wq_stats and exposes them through
ethtool -S.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_ethtool.c b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
> index 61541fb8db7b7..ca1d9ae27d82f 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_ethtool.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
> @@ -51,6 +51,17 @@ static const struct enic_stat enic_per_rq_stats[] = {
>  	ENIC_PER_RQ_STAT(napi_repoll),
>  	ENIC_PER_RQ_STAT(no_skb),
>  	ENIC_PER_RQ_STAT(desc_skip),
> +	ENIC_PER_RQ_STAT(xdp_pass),
> +	ENIC_PER_RQ_STAT(xdp_drop),
> +	ENIC_PER_RQ_STAT(xdp_tx),
> +	ENIC_PER_RQ_STAT(xdp_tx_drops),
> +	ENIC_PER_RQ_STAT(xdp_redirect),
> +	ENIC_PER_RQ_STAT(xdp_redirect_drops),
> +	ENIC_PER_RQ_STAT(xdp_aborted),
> +	ENIC_PER_RQ_STAT(xdp_invalid),
> +	ENIC_PER_RQ_STAT(xsk_rx_pkts),
> +	ENIC_PER_RQ_STAT(xsk_rx_bytes),
> +	ENIC_PER_RQ_STAT(xsk_fill_empty),
>  };
>  
>  #define NUM_ENIC_PER_RQ_STATS   ARRAY_SIZE(enic_per_rq_stats)
> @@ -64,6 +75,10 @@ static const struct enic_stat enic_per_wq_stats[] = {
>  	ENIC_PER_WQ_STAT(null_pkt),
>  	ENIC_PER_WQ_STAT(skb_linear_fail),
>  	ENIC_PER_WQ_STAT(desc_full_awake),
> +	ENIC_PER_WQ_STAT(xsk_tx_pkts),
> +	ENIC_PER_WQ_STAT(xsk_tx_bytes),
> +	ENIC_PER_WQ_STAT(xsk_tx_no_room),
> +	ENIC_PER_WQ_STAT(xsk_tx_completed),
>  };

[Severity: Medium]
Should xsk_rx_pkts, xsk_rx_bytes, xsk_fill_empty, xsk_tx_pkts, and
xsk_tx_bytes be reported through standard statistics interfaces instead
of ethtool -S?

ethtool -S is reserved for driver-private counters without a standard
uAPI (Documentation/networking/statistics.rst).  Per-queue RX/TX packet,
byte, and RX buffer allocation failure counters are covered by
netdev_queue_stats_rx and netdev_queue_stats_tx, which enic already
implements in enic_get_queue_stats_rx() and enic_get_queue_stats_tx()
(and commit bde04d9876c0 ("enic: Report some per queue statistics in
ethtool") excluded per-queue packets, bytes, and pp_alloc_fail from
ethtool -S for that reason).  AF_XDP fill ring empty events are also
already tracked by xsk_buff_alloc() in pool->fq->queue_empty_descs and
exposed via SOL_XDP XDP_STATISTICS and sock_diag.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=4

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages
  2026-12-01  1:15 ` [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages Satish Kharat
@ 2026-12-02  1:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-02  1:16 UTC (permalink / raw)
  To: Satish Kharat; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] net: enic: unaligned truesize in enic_rq_alloc_buf() misaligns
  skb_shared_info
--

commit cd93cb3238544785656020716a596e6aff1448f8
Author: Satish Kharat <satishkh@cisco.com>

net: enic: reserve XDP head and tailroom in RX pages

This commit adds an xdp_enabled flag to struct enic_rq and reserves XDP
headroom and skb_shared_info tailroom in enic_rq_alloc_buf() when the flag
is set.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
> index ccbf5c9a21d0f..82ef15296a100 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_rq.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
> @@ -273,13 +274,17 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
>  	struct net_device *netdev = enic->netdev;
>  	struct enic_rq *erq = &enic->rq[rq->index];
>  	struct enic_rq_stats *rqstats = &erq->stats;
> +	unsigned int headroom = erq->xdp_enabled ? ENIC_XDP_HEADROOM : 0;
>  	unsigned int offset = 0;
>  	unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
>  	unsigned int os_buf_index = 0;
>  	dma_addr_t dma_addr;
>  	struct vnic_rq_buf *buf = rq->to_use;
>  	struct page *page;
> -	unsigned int truesize = len;
> +	unsigned int truesize = len + headroom;
> +
> +	if (erq->xdp_enabled)
> +		truesize += ENIC_XDP_TAILROOM;
>  
>  	if (buf->os_buf) {
>  		enic_queue_rq_desc(rq, buf->os_buf, os_buf_index, buf->dma_addr,
> @@ -293,9 +298,9 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
>  		rqstats->pp_alloc_fail++;
>  		return -ENOMEM;
>  	}
> -	buf->offset = offset;
> +	buf->offset = offset + headroom;
>  	buf->truesize = truesize;

[Severity: High]
Does leaving truesize unaligned misalign struct skb_shared_info when
page_pool_dev_alloc() allocates multiple fragments per page?

With VLAN_ETH_HLEN (18 bytes), len + headroom + ENIC_XDP_TAILROOM is only
2-byte aligned for standard MTUs (or 1-byte aligned for odd MTUs).  When a
page holds more than one fragment, page_pool_alloc_netmem() passes *size
by value to page_pool_alloc_frag_netmem() and leaves the caller's truesize
unchanged for non-terminal fragments:

include/net/page_pool/helpers.h:page_pool_alloc_netmem() {
    ...
	netmem = page_pool_alloc_frag_netmem(pool, offset, *size, gfp);
	if (unlikely(!netmem))
		return 0;

	/* There is very likely not enough space for another fragment, so append
	 * the remaining size to the current fragment to avoid truesize
	 * underestimate problem.
	 */
	if (pool->frag_offset + *size > max_size) {
		*size = max_size - *offset;
		pool->frag_offset = max_size;
	}
    ...
}

When buf->truesize is later passed to xdp_init_buff() as frame_sz,
xdp_data_hard_end() and xdp_get_shared_info_from_buff() place
struct skb_shared_info at an unaligned address, causing misaligned atomic
and pointer accesses.  Aligning truesize with SKB_DATA_ALIGN() before
calling page_pool_dev_alloc() would keep the end of the frame aligned.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=6

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches
  2026-12-01  1:15 ` [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches Satish Kharat
@ 2026-12-02  1:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-02  1:16 UTC (permalink / raw)
  To: Satish Kharat; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: enic: vnic_rq_publish_tail() defeats RX posted_index
  MMIO batching
--

commit 03c983008b4dfdb0aae778c95dfa0b6e84d91445
Author: Satish Kharat <satishkh@cisco.com>

net: enic: publish partial receive descriptor batches

This commit adds vnic_rq_publish_tail() and calls it at the end of
vnic_rq_fill() and enic_admin_rq_fill() so partial batches of fewer than 16
receive descriptors are published to the device.

> diff --git a/drivers/net/ethernet/cisco/enic/vnic_rq.h b/drivers/net/ethernet/cisco/enic/vnic_rq.h
> index 9fc2090eac447..6c347599d233d 100644
> --- a/drivers/net/ethernet/cisco/enic/vnic_rq.h
> +++ b/drivers/net/ethernet/cisco/enic/vnic_rq.h
> @@ -140,6 +140,19 @@ static inline void vnic_rq_post(struct vnic_rq *rq,
>  	}
>  }
>  
> +static inline void vnic_rq_publish_tail(struct vnic_rq *rq,
> +					struct vnic_rq_buf *first)
> +{
> +	/* A full batch was already published by vnic_rq_post(). */
> +	if (rq->to_use == first ||
> +	    !(rq->to_use->index & VNIC_RQ_RETURN_RATE))
> +		return;
> +
> +	/* Make descriptor contents visible before advancing the device index. */
> +	wmb();
> +	iowrite32(rq->to_use->index, &rq->ctrl->posted_index);
> +}
> +
>  static inline void vnic_rq_return_descs(struct vnic_rq *rq, unsigned int count)
>  {
>  	rq->ring.desc_avail += count;
> @@ -181,16 +194,18 @@ static inline void vnic_rq_service(struct vnic_rq *rq,
>  static inline int vnic_rq_fill(struct vnic_rq *rq,
>  	int (*buf_fill)(struct vnic_rq *rq))
>  {
> -	int err;
> +	struct vnic_rq_buf *first = rq->to_use;
> +	int err = 0;
>  
>  	while (vnic_rq_desc_avail(rq) > 0) {
>  
>  		err = (*buf_fill)(rq);
>  		if (err)
> -			return err;
> +			break;
>  	}
>  
> -	return 0;
> +	vnic_rq_publish_tail(rq, first);
> +	return err;
>  }

[Severity: Medium]
Does calling vnic_rq_publish_tail() unconditionally at the end of
vnic_rq_fill() defeat the 16-descriptor posted_index batching in
vnic_rq_post() on the NAPI RX path?

vnic_dev_alloc_desc_ring() aligns ring->desc_count to a multiple of 32 and
initializes ring->desc_avail to ring->desc_count - 1.  When the ring is
completely filled during enic_open(), rq->to_use->index ends at
desc_count - 1 (15 mod 16) and vnic_rq_publish_tail() writes it to
posted_index.

Because vnic_rq_post() still flushes whenever (buf->index & 0xf) == 0, the
very first descriptor refilled on the next NAPI poll wraps buf->index to a
multiple of 16 and triggers an immediate wmb() and iowrite32() for a single
descriptor, and the end of the poll leaves rq->to_use->index unaligned again
so vnic_rq_publish_tail() issues another write.  Every full-budget 64-packet
NAPI poll permanently performs 5 posted_index MMIO writes (batches of 1, 16,
16, 16, and 15) instead of 4, and a 16-packet poll performs 2 writes instead
of 1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=7

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect
  2026-12-01  1:15 ` [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect Satish Kharat
@ 2026-12-02  1:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-02  1:16 UTC (permalink / raw)
  To: Satish Kharat; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] net: enic: unaligned truesize in enic_rq_alloc_buf() misaligns
  skb_shared_info
- [Medium] net: enic: datapath_open set after unmasking IRQs in
  enic_open()
- [Medium] net: enic: skipped enic_ext_cq() on reset error paths
--

commit 4b53d4ae435146c6750ed4d9efd1c19cb925255f
Author: Satish Kharat <satishkh@cisco.com>

net: enic: add native XDP RX, TX, and redirect

This commit adds native XDP support to enic, including page-pool RX queue
registration, XDP_PASS/DROP/TX/REDIRECT handling, ndo_xdp_xmit, and RX VLAN
stripping reconfiguration when XDP is attached.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 430fd6b210e88..4c1ea75654bb0 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1813,10 +2016,21 @@ static int enic_open(struct net_device *netdev)
>  	for (i = 0; i < enic->intr_count; i++)
>  		vnic_intr_unmask(&enic->intr[i]);
>  
> +	WRITE_ONCE(enic->datapath_open, true);

[Severity: Medium]
Should datapath_open be set to true before unmasking interrupts in
enic_open()?

NAPI and the device are already enabled at this point, so an RQ interrupt
can fire as soon as its vector is unmasked while the loop is still
unmasking the remaining vectors:

CPU0                              CPU1
enic_open()
  vnic_intr_unmask(&intr[0])
                                  enic_isr_msix()
                                    ...
                                      enic_poll_msix_rq()
                                        ...
                                          enic_xdp_run()
                                            enic_xdp_xmit_frame()
                                              !READ_ONCE(enic->datapath_open)
                                                <-- drops XDP_TX frame
  WRITE_ONCE(enic->datapath_open, true)

Any XDP_TX (or concurrent enic_xdp_xmit()) frame processed in that window
sees datapath_open == false and is dropped with -ENETDOWN.

[ ... ]

> @@ -2311,28 +2679,61 @@ static void enic_reset(struct work_struct *work)
>  		dev_close(enic->netdev);
>  		goto reset_out;
>  	}
> +	if (enic_has_admin_chan(enic))
> +		enic->admin_reopen_pending = true;
>  
> -	enic_stop(enic->netdev);
> +	/* A forced stop can already have reset the vNIC. */
> +	__enic_stop(enic->netdev, &stop_reset_done);
>  	if (enic_is_sriov_vf_v2(enic))
>  		enic_mbox_vf_link_state_reset(enic);
> +	if (READ_ONCE(enic->dma_blocked)) {
> +		enic_set_api_busy(enic, false);
> +		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
> +		rtnl_unlock();
> +		return;
> +	}
>  
> -	enic_dev_soft_reset(enic);
> -	enic_reset_addr_lists(enic);
> -	enic_init_vnic_resources(enic);
> -	enic_set_rss_nic_cfg(enic);
> -	enic_dev_set_ig_vlan_rewrite_mode(enic);
> -	enic_ext_cq(enic);
> +	if (!stop_reset_done) {
> +		/* The admin channel is down; quarantine was handled above. */
> +		err = enic_dev_soft_reset(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "soft reset failed: %d; blocking PCI DMA\n",
> +				   err);
> +			enic_block_pci_dma(enic);
> +			enic_set_api_busy(enic, false);
> +			call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
> +			rtnl_unlock();
> +			return;
> +		}
> +		enic_reset_addr_lists(enic);
> +		enic_init_vnic_resources(enic);
> +		enic->vlan_rewrite_valid = false;
> +		err = enic_set_rss_nic_cfg(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "failed to restore NIC configuration after reset: %d\n",
> +				   err);
> +			goto reset_out;
> +		}
> +		err = enic_dev_set_ig_vlan_rewrite_mode(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "failed to restore ingress VLAN rewrite after reset: %d\n",
> +				   err);
> +			goto reset_out;
> +		}
> +		enic->vlan_rewrite_valid = true;
> +		enic_ext_cq(enic);
> +	}

[Severity: Medium]
If enic_set_rss_nic_cfg() or enic_dev_set_ig_vlan_rewrite_mode() fails
here (or in the identical block in enic_tx_hang_reset()), does jumping to
reset_out leave the hardware RQ CQ entry size out of sync with
enic->ext_cq?

The soft or hang reset reverts the vNIC firmware to 16-byte RQ CQ entries.
A later enic_open() retries VLAN rewrite and NIC_CFG through
vlan_rewrite_valid and niccfg_valid, but it does not call enic_ext_cq(), so
RX and admin RQ completion polling will decode 32-byte or 64-byte CQ
entries while firmware writes 16-byte entries.  enic_finish_dma_quiesce()
avoids this by still calling enic_ext_cq() when those commands fail.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
> index 82ef15296a100..350e42c556ade 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_rq.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
> @@ -276,7 +276,7 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
>  	struct enic_rq_stats *rqstats = &erq->stats;
>  	unsigned int headroom = erq->xdp_enabled ? ENIC_XDP_HEADROOM : 0;
>  	unsigned int offset = 0;
> -	unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
> +	unsigned int len = netdev->mtu + enic_rx_l2_len(enic);
>  	unsigned int os_buf_index = 0;
>  	dma_addr_t dma_addr;
>  	struct vnic_rq_buf *buf = rq->to_use;

[Severity: High]
Can unaligned buf->truesize in enic_rq_alloc_buf() misalign
skb_shared_info when an XDP buffer or frame is converted to an skb?

With XDP attached, rx_vlan_strip is false, so enic_rx_l2_len(enic) is
ENIC_RX_MAX_L2_LEN (22 bytes) and truesize is netdev->mtu + 22 +
ENIC_XDP_HEADROOM + ENIC_XDP_TAILROOM, which is not aligned to
SKB_DATA_ALIGN() (for example, 2098 bytes at MTU 1500).

drivers/net/ethernet/cisco/enic/enic_rq.c:enic_rq_alloc_buf() {
    ...
	unsigned int truesize = len + headroom;

	if (erq->xdp_enabled)
		truesize += ENIC_XDP_TAILROOM;
    ...
	page = page_pool_dev_alloc(erq->pool, &offset, &truesize);
    ...
	buf->truesize = truesize;
}

When two or more buffers fit in a page (such as MTU <= 1450 on 4K pages, or
MTU 1500 on 16K/64K pages), page_pool_alloc_netmem() aligns its internal
frag_offset step but only writes the aligned size back to *size on the
last fragment of the page.  Non-final fragments keep the unaligned
truesize, which enic_xdp_run() passes to xdp_init_buff() as frame_sz,
placing xdp_data_hard_end() and skb_shinfo(skb) at an unaligned address
when building an skb (e.g. after XDP_REDIRECT to cpumap or veth).

Aligning truesize with SKB_DATA_ALIGN() (or aligning len before computing
truesize) in enic_rq_alloc_buf() and enic_open() avoids this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=8

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX
  2026-12-01  1:15 ` [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX Satish Kharat
@ 2026-12-02  1:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-02  1:16 UTC (permalink / raw)
  To: Satish Kharat; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] net: enic: TX need_wakeup not restored across stop/open in
  enic_open()
- [High] net: enic: RX stall in enic_open() when XSK fill ring is
  initially empty
- [High] net: enic: list corruption in enic_rq_alloc_buf() via
  enic_xsk_buff_init()
- [Medium] net: enic: per-descriptor lock and false wakeup in
  enic_rq_alloc_buf()
- [Medium] net: enic: per-packet XSK_RX TX completion locking and
  enic_rq false sharing
- [Low] net: enic: unconditional spin_lock_bh() in
  enic_xsk_rx_tx_flush() on RX poll
--

commit 867968ead5e974fd4a4138cb6db78c85d73c1863
Author: Satish Kharat <satishkh@cisco.com>

net: enic: add AF_XDP zero-copy RX and TX

This commit adds AF_XDP zero-copy receive and transmit support to the enic
driver, including UMEM pool setup, XSK RX buffer allocation and XDP
action handling, zero-copy TX batching, and ndo_xsk_wakeup support.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 4c1ea75654bb0..d14bc66f4178e 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c

[ ... ]

> @@ -1982,9 +2002,11 @@ static int enic_open(struct net_device *netdev)
>  
>  		/* enable rq before updating rq desc */
>  		vnic_rq_enable(&enic->rq[i].vrq);
> -		vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
> +		err = vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
> +		enic_xsk_rx_refill_done(&enic->rq[i], err);
>  		/* Need at least one buffer on ring to get going */
> -		if (vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
> +		if (!enic->rq[i].xsk_rx_active &&
> +		    vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
>  			netdev_err(netdev, "Unable to alloc receive buffers\n");
>  			err = -ENOMEM;
>  			goto err_out_free_rq;

[Severity: High]
Can RX on queue i permanently stall when an XSK pool is bound without
XDP_USE_NEED_WAKEUP and the fill ring is initially empty during
enic_open()?

When xsk_buff_alloc() returns NULL here, vnic_rq_fill() returns -ENOMEM
with zero descriptors posted and enic_open() continues.  Because
xsk_uses_need_wakeup(erq->xsk_pool) is false, enic_rq_alloc_buf() does not
set XDP_WAKEUP_RX in pool->cached_need_wakeup, and enic_open() never
schedules enic->napi[i] after napi_enable(&enic->napi[i]).

With no descriptors posted to the hardware RQ, no RX interrupt can fire.
Userspace __xsk_recvmsg() sees (pool->cached_need_wakeup & XDP_WAKEUP_RX)
== 0 and skips ndo_xsk_wakeup, while xsk_poll() only passes XDP_WAKEUP_TX,
which in MSI-X mode schedules only the WQ NAPI.  As a result,
vnic_rq_fill() is never retried.  Should enic_open() schedule
enic->napi[i] after napi_enable() when vnic_rq_fill() fails and
!enic_xsk_rx_need_wakeup(&enic->rq[i])?

> diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
> index 350e42c556ade..f30de4757613d 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_rq.c
> +++ b/drivers/net/ethernet/cisco/enic_rq.c
> @@ -282,6 +283,31 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
>  	struct vnic_rq_buf *buf = rq->to_use;
>  	struct page *page;
>  	unsigned int truesize = len + headroom;
> +	struct xdp_buff *xdp;
> +
> +	if (erq->xsk_rx_active) {
> +		xdp = buf->os_buf;
> +		if (!xdp) {
> +			/* Set before checking the fill ring so userspace cannot
> +			 * miss need_wakeup when the ring is empty.
> +			 */
> +			if (xsk_uses_need_wakeup(erq->xsk_pool))
> +				enic_xsk_set_rx_need_wakeup(erq);
> +			xdp = xsk_buff_alloc(erq->xsk_pool);
> +			if (unlikely(!xdp)) {
> +				rqstats->xsk_fill_empty++;
> +				return -ENOMEM;
> +			}
> +			enic_xsk_buff_init(xdp);
> +		}

[Severity: High]
Can enic_xsk_buff_init(xdp) corrupt rq->xsk_tx_done when the userspace fill
ring contains duplicate chunk addresses in aligned UMEM mode?

In aligned mode, xsk_buff_alloc() indexes directly into pool->heads[] by
the chunk address from the fill ring, so duplicate fill-ring entries return
the same struct xdp_buff pointer.  If that buffer was previously
transmitted via XDP_TX and completed onto rq->xsk_tx_done, a later
vnic_rq_fill() popping the duplicate address reinitializes xskb->tx_done in
place without unlinking it or holding rq->xsk_tx_done_lock:

CPU0 (RQ NAPI)                    CPU1 (WQ NAPI)
enic_poll_msix_rq()
  enic_xsk_rx_tx_flush()
  ...
                                  enic_free_wq_buf()
                                    enic_xsk_rx_tx_complete(xdp)
                                      list_add_tail(&xskb->tx_done,
                                                    &rq->xsk_tx_done)
  vnic_rq_fill()
    enic_rq_alloc_buf()
      xdp = xsk_buff_alloc(...)
      enic_xsk_buff_init(xdp)
        INIT_LIST_HEAD(&xskb->tx_done)
  ...
enic_poll_msix_rq()
  enic_xsk_rx_tx_flush()
    list_splice_init(&rq->xsk_tx_done, &done)
    list_for_each_entry_safe(...)  <-- spins forever in softirq

Overwriting xskb->tx_done.next to point to itself while linked on
rq->xsk_tx_done causes list_for_each_entry_safe() in enic_xsk_rx_tx_flush()
to loop endlessly when another entry follows xskb.

[Severity: Medium]
Does calling enic_xsk_set_rx_need_wakeup() before xsk_buff_alloc() on every
descriptor acquire rq->xsk_wakeup_lock per packet and advertise a false
XDP_RING_NEED_WAKEUP while the fill ring is non-empty?

vnic_rq_fill() invokes enic_rq_alloc_buf() in a per-descriptor loop, so
refilling N descriptors takes and releases spin_lock_bh(&rq->xsk_wakeup_lock)
N + 1 times (including enic_xsk_rx_refill_done()), contending with
enic_xsk_tx_service() on the WQ NAPI.  It also leaves XDP_RING_NEED_WAKEUP
set in shared fill-ring flags across the entire refill loop and its MMIO
doorbell writes before enic_xsk_rx_refill_done() clears it, causing a
concurrent userspace producer to issue unnecessary wakeup syscalls on a
non-empty fill ring.  Setting rx_need_wakeup only when xsk_buff_alloc()
returns NULL (and rechecking xsk_pool_can_alloc() under the lock) would
avoid both the per-descriptor lock and the transient wakeup flag.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.c b/drivers/net/ethernet/cisco/enic/enic_xdp.c
> index dbb5f0e6c14f6..b6989a4dd79b3 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_xdp.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_xdp.c

[ ... ]

> @@ -225,6 +282,345 @@ bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,

[ ... ]

> +bool enic_xsk_tx_service(struct enic *enic, unsigned int wq_index)
> +{

[ ... ]

> +out_need_wakeup:
> +	spin_unlock(&wq->lock);
> +	if (!done && xsk_uses_need_wakeup(pool)) {
> +		spin_lock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
> +		xsk_clear_tx_need_wakeup(pool);
> +		spin_unlock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
> +	}
> +
> +	return done;
> +}

[Severity: High]
Can clearing TX need_wakeup here permanently wedge AF_XDP TX if the
interface goes through a stop/open cycle while the WQ NAPI is still
polling?

When enic_xsk_tx_service() posts a full batch (sent == capacity), done is
false and xsk_clear_tx_need_wakeup(pool) clears XDP_RING_NEED_WAKEUP in
the TX ring and XDP_WAKEUP_TX in pool->cached_need_wakeup because NAPI
expects to keep polling.  If a stop/open cycle then runs across all queues
(for example via enic_xdp_reload_pool_swap() when binding or unbinding a
pool on another queue, enic_xdp_reload(), or _enic_change_mtu()),
__enic_stop() disables all NAPIs and cleans all in-flight WQ descriptors,
and enic_open() re-enables the WQ NAPIs without restoring
xsk_set_tx_need_wakeup(pool) or scheduling the WQ NAPI.

After enic_open(), the WQ NAPI is idle with no descriptors in flight to
raise a completion interrupt, and __xsk_sendmsg() and xsk_poll() see
(pool->cached_need_wakeup & XDP_WAKEUP_TX) == 0 and never call
ndo_xsk_wakeup.  Restoring xsk_set_tx_need_wakeup(pool) (or scheduling the
WQ NAPI) for bound pools during enic_open() would prevent this stall.

> +
> +static void enic_xsk_schedule_napi(struct napi_struct *napi)
> +{
> +	if (!napi_if_scheduled_mark_missed(napi))
> +		napi_schedule(napi);
> +}
> +
> +void enic_xsk_rx_tx_complete(struct enic *enic, struct xdp_buff *xdp)
> +{
> +	struct enic_xsk_buff *xskb = enic_xsk_buff(xdp);
> +	unsigned int rq_index = xdp->rxq->queue_index;
> +	struct enic_rq *rq;
> +
> +	if (WARN_ON_ONCE(rq_index >= enic->rq_count) ||
> +	    WARN_ON_ONCE(!list_empty(&xskb->tx_done)))
> +		return;
> +
> +	rq = &enic->rq[rq_index];
> +	spin_lock_bh(&rq->xsk_tx_done_lock);
> +	list_add_tail(&xskb->tx_done, &rq->xsk_tx_done);
> +	spin_unlock_bh(&rq->xsk_tx_done_lock);
> +
> +	if (READ_ONCE(enic->xsk_wakeup_enabled) &&
> +	    vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
> +		enic_xsk_schedule_napi(&enic->napi[rq_index]);
> +}

[Severity: Medium]
Can VNIC_WQ_BUF_XSK_RX completions be batched in enic_wq_service() the way
VNIC_WQ_BUF_XSK completions are?

Right now enic_free_wq_buf() calls enic_xsk_rx_tx_complete() on every
completed descriptor while holding wq->lock, so each packet individually
acquires spin_lock_bh(&rq->xsk_tx_done_lock) and performs an atomic
cmpxchg on enic->napi[rq_index].state via enic_xsk_schedule_napi().  In
addition, struct enic_rq places xsk_wakeup_lock, xsk_tx_done_lock, and
xsk_tx_done right after the cacheline-aligned struct xdp_rxq_info xdp_rxq
(64 bytes), putting those WQ-modified locks on the same cacheline as the
read-mostly RX flags xdp_enabled, xsk_rx_active, and xdp_flush_pending.

> +
> +void enic_xsk_rx_tx_flush(struct enic *enic, unsigned int rq_index)
> +{
> +	struct enic_rq *rq = &enic->rq[rq_index];
> +	struct enic_xsk_buff *xskb, *tmp;
> +	LIST_HEAD(done);
> +
> +	spin_lock_bh(&rq->xsk_tx_done_lock);
> +	list_splice_init(&rq->xsk_tx_done, &done);
> +	spin_unlock_bh(&rq->xsk_tx_done_lock);
> +
> +	list_for_each_entry_safe(xskb, tmp, &done, tx_done) {
> +		list_del_init(&xskb->tx_done);
> +		xsk_buff_free(&xskb->xdp);
> +	}
> +}

[Severity: Low]
Should enic_xsk_rx_tx_flush() return early when list_empty(&rq->xsk_tx_done)
before taking spin_lock_bh(&rq->xsk_tx_done_lock)?

enic_poll() and enic_poll_msix_rq() call enic_xsk_rx_tx_flush() on every
positive-budget RX NAPI poll, so without an unlocked list_empty() check
every RX poll pays an atomic lock/unlock and BH disable/enable even when
AF_XDP is not in use.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=10

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-12-02  1:16 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 02/12] net: enic: tag work queue descriptor ownership Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 03/12] net: enic: gate native XDP on mixed RQ descriptor capability Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters Satish Kharat
2026-12-02  1:16   ` sashiko-bot
2026-12-01  1:15 ` [PATCH RFC net-next 05/12] net: enic: complete XDP frames by WQ descriptor ownership Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages Satish Kharat
2026-12-02  1:16   ` sashiko-bot
2026-12-01  1:15 ` [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches Satish Kharat
2026-12-02  1:16   ` sashiko-bot
2026-12-01  1:15 ` [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect Satish Kharat
2026-12-02  1:16   ` sashiko-bot
2026-12-01  1:15 ` [PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX Satish Kharat
2026-12-02  1:16   ` sashiko-bot
2026-12-01  1:15 ` [PATCH RFC net-next 11/12] selftests/xsk: exercise XDP detach with bound socket Satish Kharat
2026-12-01  1:15 ` [PATCH RFC net-next 12/12] net: enic: count XDP and AF_XDP TX in queue statistics Satish Kharat

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.