[PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect
From: Satish Kharat
Date: Mon Nov 30 2026 - 20:16:56 EST
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@xxxxxxxxx>
---
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