git: b354bb04cb51 - main - nvme: Add constants for fields in AER completion dword 0

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Sat, 23 Mar 2024 00:25:36 UTC
The branch main has been updated by jhb:

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

commit b354bb04cb51f373e997cb8911c32dc93243c1d7
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-03-23 00:24:06 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-03-23 00:24:06 +0000

    nvme: Add constants for fields in AER completion dword 0
    
    Reviewed by:    imp
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D44445
---
 sys/dev/nvme/nvme.h       | 8 ++++++++
 sys/dev/nvme/nvme_ctrlr.c | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index 7059421f9fd7..ef262a864121 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -643,6 +643,14 @@ enum nvme_critical_warning_state {
 #define NVME_FEAT_SET_FID_SHIFT				(0)
 #define NVME_FEAT_SET_FID_MASK				(0xff)
 
+/* Async Events */
+#define	NVME_ASYNC_EVENT_TYPE_SHIFT			(0)
+#define	NVME_ASYNC_EVENT_TYPE_MASK			(0x7)
+#define	NVME_ASYNC_EVENT_INFO_SHIFT			(8)
+#define	NVME_ASYNC_EVENT_INFO_MASK			(0xff)
+#define	NVME_ASYNC_EVENT_LOG_PAGE_ID_SHIFT		(16)
+#define	NVME_ASYNC_EVENT_LOG_PAGE_ID_MASK		(0xff)
+
 /* Helper macro to combine *_MASK and *_SHIFT defines */
 #define NVMEM(name)	(name##_MASK << name##_SHIFT)
 
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index 7334c7169efb..e41f32635346 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -783,10 +783,11 @@ nvme_ctrlr_async_event_cb(void *arg, const struct nvme_completion *cpl)
 	}
 
 	/* Associated log page is in bits 23:16 of completion entry dw0. */
-	aer->log_page_id = (cpl->cdw0 & 0xFF0000) >> 16;
+	aer->log_page_id = NVMEV(NVME_ASYNC_EVENT_LOG_PAGE_ID, cpl->cdw0);
 
 	nvme_printf(aer->ctrlr, "async event occurred (type 0x%x, info 0x%02x,"
-	    " page 0x%02x)\n", (cpl->cdw0 & 0x07), (cpl->cdw0 & 0xFF00) >> 8,
+	    " page 0x%02x)\n", NVMEV(NVME_ASYNC_EVENT_TYPE, cpl->cdw0),
+	    NVMEV(NVME_ASYNC_EVENT_INFO, cpl->cdw0),
 	    aer->log_page_id);
 
 	if (is_log_page_id_valid(aer->log_page_id)) {