Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Dec 2025 22:53:55 +0000
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 9b170dc457a4 - main - nvme: Use new method to do async notifications
Message-ID:  <6939fa03.a57e.2d3336d8@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help

The branch main has been updated by imp:

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

commit 9b170dc457a46d3ec3b329116fcd6851fe9b63a0
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2025-12-10 22:52:45 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-12-10 22:52:45 +0000

    nvme: Use new method to do async notifications
    
    Nothing uses these at the moment, but it would be useful to use in the
    future so convert this functionality to an newbus function dispatch.
    
    Sponsored by:           Netflix
    Reviewed by:            dab
    Differential Revision:  https://reviews.freebsd.org/D51390
---
 sys/dev/nvme/nvme.c         | 29 ++++++++++++++---------------
 sys/dev/nvme/nvme_ctrlr.c   | 11 +++++------
 sys/dev/nvme/nvme_private.h |  8 ++++----
 3 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/sys/dev/nvme/nvme.c b/sys/dev/nvme/nvme.c
index 3ff64c781884..dcd0851dd56a 100644
--- a/sys/dev/nvme/nvme.c
+++ b/sys/dev/nvme/nvme.c
@@ -34,6 +34,7 @@
 #include <vm/uma.h>
 
 #include "nvme_private.h"
+#include "nvme_if.h"
 
 struct nvme_consumer {
 	uint32_t		id;
@@ -189,23 +190,21 @@ nvme_notify_new_consumer(struct nvme_consumer *cons)
 }
 
 void
-nvme_notify_async_consumers(struct nvme_controller *ctrlr,
-			    const struct nvme_completion *async_cpl,
-			    uint32_t log_page_id, void *log_page_buffer,
-			    uint32_t log_page_size)
+nvme_notify_async(struct nvme_controller *ctrlr,
+    const struct nvme_completion *async_cpl,
+    uint32_t log_page_id, void *log_page_buffer, uint32_t log_page_size)
 {
-	struct nvme_consumer	*cons;
-	void			*ctrlr_cookie;
-	uint32_t		i;
+	device_t *children;
+	int n_children;
 
-	for (i = 0; i < NVME_MAX_CONSUMERS; i++) {
-		cons = &nvme_consumer[i];
-		if (cons->id != INVALID_CONSUMER_ID && cons->async_fn != NULL &&
-		    (ctrlr_cookie = ctrlr->cons_cookie[i]) != NULL) {
-			(*cons->async_fn)(ctrlr_cookie, async_cpl,
-			    log_page_id, log_page_buffer, log_page_size);
-		}
-	}
+	if (device_get_children(ctrlr->dev, &children, &n_children) != 0)
+		return;
+
+	for (int i = 0; i < n_children; i++)
+		NVME_HANDLE_AEN(children[i], async_cpl, log_page_id,
+		    log_page_buffer, log_page_size);
+
+	free(children, M_TEMP);
 }
 
 void
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index 7a449fdc4727..2f28d8f5cb7f 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -1154,8 +1154,7 @@ nvme_ctrlr_aer_task(void *arg, int pending)
 		 * Repost another asynchronous event request to replace the one
 		 * that just completed.
 		 */
-		nvme_notify_async_consumers(ctrlr, &aer->cpl, aer->log_page_id,
-		    NULL, 0);
+		nvme_notify_async(ctrlr, &aer->cpl, aer->log_page_id, NULL, 0);
 		nvme_ctrlr_construct_and_submit_aer(ctrlr, aer);
 		goto out;
 	}
@@ -1180,8 +1179,8 @@ nvme_ctrlr_aer_task(void *arg, int pending)
 		 * error, don't pass log page data to the consumers.  In
 		 * practice, this case should never happen.
 		 */
-		nvme_notify_async_consumers(aer->ctrlr, &aer->cpl,
-		    aer->log_page_id, NULL, 0);
+		nvme_notify_async(aer->ctrlr, &aer->cpl, aer->log_page_id,
+		    NULL, 0);
 		goto out;
 	}
 
@@ -1261,8 +1260,8 @@ nvme_ctrlr_aer_task(void *arg, int pending)
 	 * Pass the cpl data from the original async event completion, not the
 	 * log page fetch.
 	 */
-	nvme_notify_async_consumers(aer->ctrlr, &aer->cpl,
-	    aer->log_page_id, aer->log_page_buffer, aer->log_page_size);
+	nvme_notify_async(aer->ctrlr, &aer->cpl, aer->log_page_id,
+	    aer->log_page_buffer, aer->log_page_size);
 
 	/*
 	 * Repost another asynchronous event request to replace the one
diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
index cd0ef444150f..27d70d120307 100644
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -556,10 +556,10 @@ nvme_allocate_request_ccb(union ccb *ccb, const int how, nvme_cb_fn_t cb_fn,
 
 #define nvme_free_request(req)	free(req, M_NVME)
 
-void	nvme_notify_async_consumers(struct nvme_controller *ctrlr,
-				    const struct nvme_completion *async_cpl,
-				    uint32_t log_page_id, void *log_page_buffer,
-				    uint32_t log_page_size);
+void	nvme_notify_async(struct nvme_controller *ctrlr,
+	    const struct nvme_completion *async_cpl,
+	    uint32_t log_page_id, void *log_page_buffer,
+	    uint32_t log_page_size);
 void	nvme_notify_fail_consumers(struct nvme_controller *ctrlr);
 
 void	nvme_ctrlr_shared_handler(void *arg);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6939fa03.a57e.2d3336d8>