git: 86ec26e7a9b8 - stable/14 - ena: Support max large LLQ depth from the device

From: Osama Abboud <osamaabb_at_FreeBSD.org>
Date: Thu, 31 Oct 2024 16:01:41 UTC
The branch stable/14 has been updated by osamaabb:

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

commit 86ec26e7a9b878397c3b664d66fdfc8ecfdee10d
Author:     Osama Abboud <osamaabb@amazon.com>
AuthorDate: 2024-08-07 06:24:22 +0000
Commit:     Osama Abboud <osamaabb@FreeBSD.org>
CommitDate: 2024-10-31 14:54:11 +0000

    ena: Support max large LLQ depth from the device
    
    Large LLQ depth size is currently calculated by dividing the maximum
    possible size of LLQ by 2.
    In newer paltforms, starting from r8g the size of BAR2,
    which contains LLQ, will be increased, and the maximum depth of
    wide LLQ will be set according to a value set by the device, instead of
    hardcoded division by 2.
    
    The new value will be stored by the device in max_wide_llq_depth field
    for drivers that expose ENA_ADMIN_LLQ_FEATURE_VERSION_1 or higher to
    the device.
    
    There is an assumption that max_llq_depth >= max_wide_llq_depth, since
    they both use the same bar, and if it is possible to have a wide LLQ
    of size max_wide_llq_depth, it is possible to have a normal LLQ of the
    same size, since it will occupy half of the space.
    
    Also moved the large LLQ case calculation of max_tx_queue_size
    before its rounddown.
    
    Approved by: cperciva (mentor)
    Sponsored by: Amazon, Inc.
    
    (cherry picked from commit d0419551d96c8f995bdf6388a8e69684be33f9b5)
---
 sys/dev/ena/ena.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index fadba819652b..28a4d7842306 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -2831,28 +2831,34 @@ ena_calc_io_queue_size(struct ena_calc_queue_size_ctx *ctx, struct ena_adapter *
 		    max_queues->max_packet_rx_descs);
 	}
 
-	/* round down to the nearest power of 2 */
-	max_tx_queue_size = 1 << (flsl(max_tx_queue_size) - 1);
-	max_rx_queue_size = 1 << (flsl(max_rx_queue_size) - 1);
-
-	/*
-	 * When using large headers, we multiply the entry size by 2,
-	 * and therefore divide the queue size by 2, leaving the amount
-	 * of memory used by the queues unchanged.
-	 */
 	if (adapter->llq_policy == ENA_ADMIN_LIST_ENTRY_SIZE_256B) {
-		if (ena_dev->tx_mem_queue_type ==
-		    ENA_ADMIN_PLACEMENT_POLICY_DEV) {
-			max_tx_queue_size /= 2;
-			ena_log(ctx->pdev, INFO,
-			    "Using large headers and decreasing maximum Tx queue size to %d\n",
-			    max_tx_queue_size);
+		if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) {
+			if (llq->max_wide_llq_depth != max_tx_queue_size) {
+				if (llq->max_wide_llq_depth == 0) {
+					/* if there is no large llq max depth from device, we divide
+					* the queue size by 2, leaving the amount of memory
+					* used by the queues unchanged.
+					*/
+					max_tx_queue_size /= 2;
+				} else {
+					max_tx_queue_size = llq->max_wide_llq_depth;
+				}
+				ena_log(ctx->pdev, INFO,
+				    "Using large LLQ headers and decreasing maximum Tx queue size to %d\n",
+				    max_tx_queue_size);
+			} else {
+				ena_log(ctx->pdev, INFO, "Using large LLQ headers\n");
+			}
 		} else {
 			ena_log(ctx->pdev, WARN,
 			    "Using large headers failed: LLQ is disabled or device does not support large headers\n");
 		}
 	}
 
+	/* round down to the nearest power of 2 */
+	max_tx_queue_size = 1 << (flsl(max_tx_queue_size) - 1);
+	max_rx_queue_size = 1 << (flsl(max_rx_queue_size) - 1);
+
 	tx_queue_size = clamp_val(tx_queue_size, ENA_MIN_RING_SIZE,
 	    max_tx_queue_size);
 	rx_queue_size = clamp_val(rx_queue_size, ENA_MIN_RING_SIZE,