git: fdeb262d1861 - stable/12 - ena: Store ticks of last Tx cleanup

From: Marcin Wojtas <mw_at_FreeBSD.org>
Date: Tue, 26 Jul 2022 19:33:24 UTC
The branch stable/12 has been updated by mw:

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

commit fdeb262d1861a918c8699021691163ebf856debe
Author:     Dawid Gorecki <dgr@semihalf.com>
AuthorDate: 2022-06-10 09:18:09 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-07-26 19:33:03 +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.
    
    (cherry picked from commit d8aba82b5ca75f1a5bff609af141844c4fc9de70)
---
 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 64066896907e..74dcd37973b5 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,
@@ -3011,6 +3012,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;
@@ -3044,10 +3047,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 43c31269bfd2..b100b091c89f 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -373,6 +373,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 e3d30b32fceb..31de514d4b19 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -345,6 +345,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);
 }