git: 58ce49d185c3 - main - ufshci: reserve one queue entry for an admin request

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sun, 31 Aug 2025 18:40:51 UTC
The branch main has been updated by imp:

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

commit 58ce49d185c3ee96c0d6c7c9381c5b6fed51523e
Author:     Jaeyoon Choi <j_yoon.choi@samsung.com>
AuthorDate: 2025-08-31 18:36:36 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-08-31 18:36:36 +0000

    ufshci: reserve one queue entry for an admin request
    
    This patch reduces num_entries by 1 to reserve a admin slot. It
    resolves the issue where admin requests cannot be executed
    during QD32 because all queue entries are used.
    
    It also resolve the issue of accessing the queue before it is
    created by moving the queue construct point to before interrupt
    enable.
    
    Sponsored by:           Samsung Electronic
    Reviewed by:            imp
    Differential Revision:  https://reviews.freebsd.org/D51894
---
 sys/dev/ufshci/ufshci_ctrlr.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/sys/dev/ufshci/ufshci_ctrlr.c b/sys/dev/ufshci/ufshci_ctrlr.c
index 7bebfd2b0f9c..36be94b8b8b7 100644
--- a/sys/dev/ufshci/ufshci_ctrlr.c
+++ b/sys/dev/ufshci/ufshci_ctrlr.c
@@ -146,6 +146,16 @@ ufshci_ctrlr_construct(struct ufshci_controller *ctrlr, device_t dev)
 		return (ENXIO);
 	}
 
+	/* Allocate and initialize UTP Task Management Request List. */
+	error = ufshci_utmr_req_queue_construct(ctrlr);
+	if (error)
+		return (error);
+
+	/* Allocate and initialize UTP Transfer Request List or SQ/CQ. */
+	error = ufshci_utr_req_queue_construct(ctrlr);
+	if (error)
+		return (error);
+
 	/* Enable additional interrupts by programming the IE register. */
 	ie = ufshci_mmio_read_4(ctrlr, ie);
 	ie |= UFSHCIM(UFSHCI_IE_REG_UTRCE);  /* UTR Completion */
@@ -160,19 +170,12 @@ ufshci_ctrlr_construct(struct ufshci_controller *ctrlr, device_t dev)
 
 	/* TODO: Initialize interrupt Aggregation Control Register (UTRIACR) */
 
-	/* Allocate and initialize UTP Task Management Request List. */
-	error = ufshci_utmr_req_queue_construct(ctrlr);
-	if (error)
-		return (error);
-
-	/* Allocate and initialize UTP Transfer Request List or SQ/CQ. */
-	error = ufshci_utr_req_queue_construct(ctrlr);
-	if (error)
-		return (error);
-
 	/* TODO: Separate IO and Admin slot */
-	/* max_hw_pend_io is the number of slots in the transfer_req_queue */
-	ctrlr->max_hw_pend_io = ctrlr->transfer_req_queue.num_entries;
+	/*
+	 * max_hw_pend_io is the number of slots in the transfer_req_queue.
+	 * Reduce num_entries by one to reserve an admin slot.
+	 */
+	ctrlr->max_hw_pend_io = ctrlr->transfer_req_queue.num_entries - 1;
 
 	return (0);
 }