[PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool
From: Satish Kharat
Date: Mon Nov 30 2026 - 20:17:16 EST
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@xxxxxxxxx>
---
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