git: 3501d4f17e8c - main - ena: Add ena_ring_tx_doorbell() function

From: Marcin Wojtas <mw_at_FreeBSD.org>
Date: Thu, 30 Jun 2022 16:15:30 UTC
The branch main has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=3501d4f17e8cc0350b8deff671f9991cc7ac280c

commit 3501d4f17e8cc0350b8deff671f9991cc7ac280c
Author:     Dawid Gorecki <dgr@semihalf.com>
AuthorDate: 2022-06-10 09:17:52 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-06-30 15:31:12 +0000

    ena: Add ena_ring_tx_doorbell() function
    
    Add ena_ring_tx_doorbell function to remove code duplication.
    
    Obtained from: Semihalf
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
---
 sys/dev/ena/ena.h          |  8 ++++++++
 sys/dev/ena/ena_datapath.c | 10 ++--------
 sys/dev/ena/ena_netmap.c   | 11 +++--------
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h
index a6aa39829f12..85f353e7ab54 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -543,4 +543,12 @@ ena_trigger_reset(struct ena_adapter *adapter,
 	}
 }
 
+static inline void
+ena_ring_tx_doorbell(struct ena_ring *tx_ring)
+{
+	ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
+	counter_u64_add(tx_ring->tx_stats.doorbells, 1);
+	tx_ring->acum_pkts = 0;
+}
+
 #endif /* !(ENA_H) */
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index c6798b3f7eb3..8d4621947e03 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -1017,9 +1017,7 @@ ena_xmit_mbuf(struct ena_ring *tx_ring, struct mbuf **mbuf)
 		ena_log_io(pdev, DBG,
 		    "llq tx max burst size of queue %d achieved, writing doorbell to send burst\n",
 		    tx_ring->que->id);
-		ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
-		counter_u64_add(tx_ring->tx_stats.doorbells, 1);
-		tx_ring->acum_pkts = 0;
+		ena_ring_tx_doorbell(tx_ring);
 	}
 
 	/* Prepare the packet's descriptors and send them to device */
@@ -1098,7 +1096,6 @@ ena_start_xmit(struct ena_ring *tx_ring)
 {
 	struct mbuf *mbuf;
 	struct ena_adapter *adapter = tx_ring->adapter;
-	struct ena_com_io_sq* io_sq;
 	int ena_qid;
 	int ret = 0;
 
@@ -1111,7 +1108,6 @@ ena_start_xmit(struct ena_ring *tx_ring)
 		return;
 
 	ena_qid = ENA_IO_TXQ_IDX(tx_ring->que->id);
-	io_sq = &adapter->ena_dev->io_sq_queues[ena_qid];
 
 	while ((mbuf = drbr_peek(adapter->ifp, tx_ring->br)) != NULL) {
 		ena_log_io(adapter->pdev, DBG,
@@ -1149,9 +1145,7 @@ ena_start_xmit(struct ena_ring *tx_ring)
 
 	if (likely(tx_ring->acum_pkts != 0)) {
 		/* Trigger the dma engine */
-		ena_com_write_sq_doorbell(io_sq);
-		counter_u64_add(tx_ring->tx_stats.doorbells, 1);
-		tx_ring->acum_pkts = 0;
+		ena_ring_tx_doorbell(tx_ring);
 	}
 
 	if (unlikely(!tx_ring->running))
diff --git a/sys/dev/ena/ena_netmap.c b/sys/dev/ena/ena_netmap.c
index 976e54e4525f..8ca6aad75abf 100644
--- a/sys/dev/ena/ena_netmap.c
+++ b/sys/dev/ena/ena_netmap.c
@@ -375,9 +375,7 @@ ena_netmap_tx_frames(struct ena_netmap_ctx *ctx)
 	/* If any packet was sent... */
 	if (likely(ctx->nm_i != ctx->kring->nr_hwcur)) {
 		/* ...send the doorbell to the device. */
-		ena_com_write_sq_doorbell(ctx->io_sq);
-		counter_u64_add(ctx->ring->tx_stats.doorbells, 1);
-		tx_ring->acum_pkts = 0;
+		ena_ring_tx_doorbell(tx_ring);
 
 		ctx->ring->next_to_use = ctx->nt;
 		ctx->kring->nr_hwcur = ctx->nm_i;
@@ -431,11 +429,8 @@ ena_netmap_tx_frame(struct ena_netmap_ctx *ctx)
 	/* There are no any offloads, as the netmap doesn't support them */
 
 	if (tx_ring->acum_pkts == DB_THRESHOLD ||
-	    ena_com_is_doorbell_needed(ctx->io_sq, &ena_tx_ctx)) {
-		ena_com_write_sq_doorbell(ctx->io_sq);
-		counter_u64_add(tx_ring->tx_stats.doorbells, 1);
-		tx_ring->acum_pkts = 0;
-	}
+	    ena_com_is_doorbell_needed(ctx->io_sq, &ena_tx_ctx))
+		ena_ring_tx_doorbell(tx_ring);
 
 	rc = ena_com_prepare_tx(ctx->io_sq, &ena_tx_ctx, &nb_hw_desc);
 	if (unlikely(rc != 0)) {