All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shai Brandes <shaibran@amazon.com>
To: <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, Shai Brandes <shaibran@amazon.com>
Subject: [PATCH 04/21] net/ena/base: add IO ring helper functions
Date: Wed, 15 Oct 2025 10:06:50 +0300	[thread overview]
Message-ID: <20251015070707.340-5-shaibran@amazon.com> (raw)
In-Reply-To: <20251015070707.340-1-shaibran@amazon.com>

Add separate utilities to check if Rx/Tx CQ are empty.
Introduce new function to retrieve tx cq descriptor.

Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
Reviewed-by: Yosef Raisman <yraisman@amazon.com>
---
 drivers/net/ena/base/ena_eth_com.c | 43 +++++++++++++++++++++++++-----
 drivers/net/ena/base/ena_eth_com.h |  3 ++-
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ena/base/ena_eth_com.c b/drivers/net/ena/base/ena_eth_com.c
index b68be49ef9..fd98e5ae67 100644
--- a/drivers/net/ena/base/ena_eth_com.c
+++ b/drivers/net/ena/base/ena_eth_com.c
@@ -733,13 +733,42 @@ int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
 	return ena_com_sq_update_reqular_queue_tail(io_sq);
 }
 
-bool ena_com_cq_empty(struct ena_com_io_cq *io_cq)
+bool ena_com_rx_cq_empty(struct ena_com_io_cq *io_cq)
 {
-	struct ena_eth_io_rx_cdesc_ext *cdesc;
+	return (ena_com_get_next_rx_cdesc(io_cq) == NULL);
+}
+
+static struct ena_eth_io_tx_cdesc_ext *ena_com_get_next_tx_cdesc(struct ena_com_io_cq *io_cq)
+{
+	struct ena_eth_io_tx_cdesc_ext *cdesc;
+	u8 expected_phase, cdesc_phase;
+	u16 masked_head;
+
+	masked_head = io_cq->head & (io_cq->q_depth - 1);
+	expected_phase = io_cq->phase;
+
+	cdesc = (struct ena_eth_io_tx_cdesc_ext *)
+		((uintptr_t)io_cq->cdesc_addr.virt_addr +
+		(masked_head * io_cq->cdesc_entry_size_in_bytes));
+
+	/* When the current completion descriptor phase isn't the same as the
+	 * expected, it means that the device didn't update this completion yet.
+	 */
+	cdesc_phase = ENA_FIELD_GET(READ_ONCE8(cdesc->base.flags),
+				    ENA_ETH_IO_TX_CDESC_PHASE_MASK,
+				    ENA_ZERO_SHIFT);
+	if (cdesc_phase != expected_phase)
+		return NULL;
+
+	/* Make sure we read the rest of the descriptor after the phase bit
+	 * has been read
+	 */
+	dma_rmb();
 
-	cdesc = ena_com_get_next_rx_cdesc(io_cq);
-	if (cdesc)
-		return false;
-	else
-		return true;
+	return cdesc;
+}
+
+bool ena_com_tx_cq_empty(struct ena_com_io_cq *io_cq)
+{
+	return (ena_com_get_next_tx_cdesc(io_cq) == NULL);
 }
diff --git a/drivers/net/ena/base/ena_eth_com.h b/drivers/net/ena/base/ena_eth_com.h
index e8f6f09359..e56eb2c173 100644
--- a/drivers/net/ena/base/ena_eth_com.h
+++ b/drivers/net/ena/base/ena_eth_com.h
@@ -74,7 +74,8 @@ int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
 			       struct ena_com_buf *ena_buf,
 			       u16 req_id);
 
-bool ena_com_cq_empty(struct ena_com_io_cq *io_cq);
+bool ena_com_rx_cq_empty(struct ena_com_io_cq *io_cq);
+bool ena_com_tx_cq_empty(struct ena_com_io_cq *io_cq);
 
 static inline bool ena_com_is_extended_tx_cdesc(struct ena_com_io_cq *io_cq)
 {
-- 
2.17.1


  parent reply	other threads:[~2025-10-15  7:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  7:06 [PATCH 00/21] net/ena: Release 2.14.0 Shai Brandes
2025-10-15  7:06 ` [PATCH 01/21] net/ena/base: optimize Tx desc fields setting Shai Brandes
2025-10-15  7:06 ` [PATCH 02/21] net/ena/base: rework admin timeout handling Shai Brandes
2025-10-15  7:06 ` [PATCH 03/21] net/ena/base: add extended Tx cdesc support Shai Brandes
2025-10-15  7:06 ` Shai Brandes [this message]
2025-10-15  8:50 ` [PATCH 00/21] net/ena: Release 2.14.0 Brandes, Shai
2025-10-15 18:12 ` Stephen Hemminger

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=20251015070707.340-5-shaibran@amazon.com \
    --to=shaibran@amazon.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /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.