All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	 Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	intel-wired-lan@lists.osuosl.org
Subject: [PATCH v1 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc().
Date: Wed,  2 Dec 2026 15:57:19 +0900	[thread overview]
Message-ID: <20261202065737.207610-2-kuniyu@google.com> (raw)
In-Reply-To: <20261202065737.207610-1-kuniyu@google.com>

idpf_rx_post_buf_desc() and idpf_rx_update_bufq_desc() duplicate
the same header and payload buffer allocation and descriptor setup
logic, except that idpf_rx_post_buf_desc() allocates with
GFP_KERNEL for the initial ring fill while idpf_rx_clean_refillq()
allocates with GFP_ATOMIC from NAPI.

Also, in later commits we will extend buffer allocation to support
coherent header buffers and custom DMA mapping.

Let's add a gfp_t gfp parameter to idpf_rx_update_bufq_desc(), move
it up, and reuse it in idpf_rx_post_buf_desc().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 drivers/net/ethernet/intel/idpf/idpf_txrx.c | 123 ++++++++------------
 1 file changed, 50 insertions(+), 73 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index b1f072ac2cea..7a33ab913069 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -595,48 +595,68 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
 }
 
 /**
- * idpf_rx_post_buf_desc - Post buffer to bufq descriptor ring
- * @bufq: buffer queue to post to
- * @buf_id: buffer id to post
- *
- * Only used for the initial fill, from process context, so it allocates
- * with GFP_KERNEL.
+ * idpf_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @buf_id: buffer ID
+ * @buf_desc: Buffer queue descriptor
+ * @gfp: allocation flags (GFP_KERNEL for initial fill, GFP_ATOMIC from NAPI)
  *
- * Return: %false if buffer could not be allocated, %true otherwise.
+ * Return: 0 on success and negative on failure.
  */
-static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)
+static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
+				    struct virtchnl2_splitq_rx_buf_desc *buf_desc,
+				    gfp_t gfp)
 {
-	struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
 	struct libeth_fq_fp fq = {
-		.count	= bufq->desc_count,
+		.pp		= bufq->pp,
+		.fqes		= bufq->buf,
+		.truesize	= bufq->truesize,
+		.count		= bufq->desc_count,
 	};
-	u16 nta = bufq->next_to_alloc;
 	dma_addr_t addr;
 
-	splitq_rx_desc = &bufq->split_buf[nta];
+	addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+	if (addr == DMA_MAPPING_ERROR)
+		return -ENOMEM;
+
+	buf_desc->pkt_addr = cpu_to_le64(addr);
+	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
 
-	if (idpf_queue_has(HSPLIT_EN, bufq)) {
-		fq.pp = bufq->hdr_pp;
-		fq.fqes = bufq->hdr_buf;
-		fq.truesize = bufq->hdr_truesize;
+	if (!idpf_queue_has(HSPLIT_EN, bufq))
+		return 0;
 
-		addr = __libeth_rx_alloc(&fq, buf_id, GFP_KERNEL);
-		if (addr == DMA_MAPPING_ERROR)
-			return false;
+	fq.pp = bufq->hdr_pp;
+	fq.fqes = bufq->hdr_buf;
+	fq.truesize = bufq->hdr_truesize;
 
-		splitq_rx_desc->hdr_addr = cpu_to_le64(addr);
+	addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+	if (addr == DMA_MAPPING_ERROR) {
+		idpf_rx_page_rel(&bufq->buf[buf_id]);
+		return -ENOMEM;
 	}
 
-	fq.pp = bufq->pp;
-	fq.fqes = bufq->buf;
-	fq.truesize = bufq->truesize;
+	buf_desc->hdr_addr = cpu_to_le64(addr);
 
-	addr = __libeth_rx_alloc(&fq, buf_id, GFP_KERNEL);
-	if (addr == DMA_MAPPING_ERROR)
-		return false;
+	return 0;
+}
 
-	splitq_rx_desc->pkt_addr = cpu_to_le64(addr);
-	splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+/**
+ * idpf_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ *
+ * Only used for the initial fill, from process context, so it allocates
+ * with GFP_KERNEL.
+ *
+ * Return: %false if buffer could not be allocated, %true otherwise.
+ */
+static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)
+{
+	u16 nta = bufq->next_to_alloc;
+
+	if (idpf_rx_update_bufq_desc(bufq, buf_id, &bufq->split_buf[nta],
+				     GFP_KERNEL))
+		return false;
 
 	nta++;
 	if (unlikely(nta == bufq->desc_count))
@@ -3759,50 +3779,6 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
 	return rs.packets;
 }
 
-/**
- * idpf_rx_update_bufq_desc - Update buffer queue descriptor
- * @bufq: Pointer to the buffer queue
- * @buf_id: buffer ID
- * @buf_desc: Buffer queue descriptor
- *
- * Return: 0 on success and negative on failure.
- */
-static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
-				    struct virtchnl2_splitq_rx_buf_desc *buf_desc)
-{
-	struct libeth_fq_fp fq = {
-		.pp		= bufq->pp,
-		.fqes		= bufq->buf,
-		.truesize	= bufq->truesize,
-		.count		= bufq->desc_count,
-	};
-	dma_addr_t addr;
-
-	addr = libeth_rx_alloc(&fq, buf_id);
-	if (addr == DMA_MAPPING_ERROR)
-		return -ENOMEM;
-
-	buf_desc->pkt_addr = cpu_to_le64(addr);
-	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
-
-	if (!idpf_queue_has(HSPLIT_EN, bufq))
-		return 0;
-
-	fq.pp = bufq->hdr_pp;
-	fq.fqes = bufq->hdr_buf;
-	fq.truesize = bufq->hdr_truesize;
-
-	addr = libeth_rx_alloc(&fq, buf_id);
-	if (addr == DMA_MAPPING_ERROR) {
-		idpf_rx_page_rel(&bufq->buf[buf_id]);
-		return -ENOMEM;
-	}
-
-	buf_desc->hdr_addr = cpu_to_le64(addr);
-
-	return 0;
-}
-
 /**
  * idpf_rx_clean_refillq - Clean refill queue buffers
  * @bufq: buffer queue to post buffers back to
@@ -3830,7 +3806,8 @@ static void idpf_rx_clean_refillq(struct idpf_buf_queue *bufq,
 			break;
 
 		buf_id = FIELD_GET(IDPF_RFL_BI_BUFID_M, refill_desc);
-		failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc);
+		failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc,
+						   GFP_ATOMIC);
 		if (failure)
 			break;
 
-- 
2.56.1.911.g883d8bcb20-goog


  reply	other threads:[~2026-12-02  6:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:57 [PATCH v1 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-02  6:57 ` Kuniyuki Iwashima [this message]
2026-12-02  6:57 ` [PATCH v1 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 3/5] page_pool: Set dma_sync_for_cpu only under PP_FLAG_DMA_MAP Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 4/5] libeth: Allow opting out of page_pool DMA mapping on Rx Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202065737.207610-2-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuni1840@gmail.com \
    --cc=przemyslaw.kitszel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.