git: d8aba82b5ca7 - main - ena: Store ticks of last Tx cleanup

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

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

commit d8aba82b5ca75f1a5bff609af141844c4fc9de70
Author:     Dawid Gorecki <dgr@semihalf.com>
AuthorDate: 2022-06-10 09:18:09 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-06-30 15:31:44 +0000

    ena: Store ticks of last Tx cleanup
    
    Store timestamp of last cleanup in Tx ring structure. This does not
    change anything during normal operation of the driver but could be
    useful when the device fails for some reason.
    
    Obtained from: Semihalf
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
---
 sys/dev/ena/ena.c          | 17 ++++++++++++++---
 sys/dev/ena/ena.h          |  2 ++
 sys/dev/ena/ena_datapath.c |  2 ++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index b8c9efb288ea..b4b38051b035 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -439,6 +439,7 @@ ena_init_io_rings_advanced(struct ena_adapter *adapter)
 		/* Allocate Tx statistics. */
 		ena_alloc_counters((counter_u64_t *)&txr->tx_stats,
 		    sizeof(txr->tx_stats));
+		txr->tx_last_cleanup_ticks = ticks;
 
 		/* Allocate Rx statistics. */
 		ena_alloc_counters((counter_u64_t *)&rxr->rx_stats,
@@ -3007,6 +3008,8 @@ check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
 	device_t pdev = adapter->pdev;
 	struct bintime curtime, time;
 	struct ena_tx_buffer *tx_buf;
+	int time_since_last_cleanup;
+	int missing_tx_comp_to;
 	sbintime_t time_offset;
 	uint32_t missed_tx = 0;
 	int i, rc = 0;
@@ -3040,10 +3043,18 @@ check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
 		/* Check again if packet is still waiting */
 		if (unlikely(time_offset > adapter->missing_tx_timeout)) {
 
-			if (!tx_buf->print_once)
+			if (!tx_buf->print_once) {
+				time_since_last_cleanup = TICKS_2_USEC(ticks -
+				    tx_ring->tx_last_cleanup_ticks);
+				missing_tx_comp_to =
+				    sbttoms(adapter->missing_tx_timeout);
 				ena_log(pdev, WARN, "Found a Tx that wasn't "
-				    "completed on time, qid %d, index %d.\n",
-				    tx_ring->qid, i);
+				    "completed on time, qid %d, index %d."
+				    "%d usecs have passed since last cleanup."
+				    "Missing Tx timeout value %d msecs.\n",
+				    tx_ring->qid, i, time_since_last_cleanup,
+				    missing_tx_comp_to);
+			}
 
 			tx_buf->print_once = true;
 			missed_tx++;
diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h
index 85f353e7ab54..56e14bd800ff 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -374,6 +374,8 @@ struct ena_ring {
 	/* Used for LLQ */
 	uint8_t *push_buf_intermediate_buf;
 
+	int tx_last_cleanup_ticks;
+
 #ifdef DEV_NETMAP
 	bool initialized;
 #endif /* DEV_NETMAP */
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index 6c18a4f5c1f9..85e9274eef14 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -344,6 +344,8 @@ ena_tx_cleanup(struct ena_ring *tx_ring)
 		ENA_RING_MTX_UNLOCK(tx_ring);
 	}
 
+	tx_ring->tx_last_cleanup_ticks = ticks;
+
 	return (work_done);
 }