Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Aug 2024 18:03:12 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 112d3053486c - stable/14 - nvmecontrol: Use the NVMEV macro instead of expanded versions
Message-ID:  <202408261803.47QI3CBF042393@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jhb:

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

commit 112d3053486c949fff6bc02394c88b2b04018961
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-01-29 18:34:02 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-08-26 17:26:08 +0000

    nvmecontrol: Use the NVMEV macro instead of expanded versions
    
    Reviewed by:    imp
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D43597
    
    (cherry picked from commit fba73a408314d8e32056d4a812c9a2eb5f618b5d)
---
 sbin/nvmecontrol/devlist.c      |   6 +-
 sbin/nvmecontrol/firmware.c     |   9 +--
 sbin/nvmecontrol/format.c       |  27 +++-----
 sbin/nvmecontrol/identify.c     | 109 +++++++++++++----------------
 sbin/nvmecontrol/identify_ext.c | 149 ++++++++++++++++------------------------
 sbin/nvmecontrol/logpage.c      |  63 ++++++-----------
 sbin/nvmecontrol/ns.c           |  39 ++++-------
 sbin/nvmecontrol/power.c        |  12 ++--
 sbin/nvmecontrol/sanitize.c     |  12 ++--
 sbin/nvmecontrol/selftest.c     |   3 +-
 10 files changed, 167 insertions(+), 262 deletions(-)

diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c
index 7e3dfe60fff4..b5e95b38937e 100644
--- a/sbin/nvmecontrol/devlist.c
+++ b/sbin/nvmecontrol/devlist.c
@@ -83,10 +83,8 @@ ns_get_sector_size(struct nvme_namespace_data *nsdata)
 {
 	uint8_t flbas_fmt, lbads;
 
-	flbas_fmt = (nsdata->flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) &
-		NVME_NS_DATA_FLBAS_FORMAT_MASK;
-	lbads = (nsdata->lbaf[flbas_fmt] >> NVME_NS_DATA_LBAF_LBADS_SHIFT) &
-		NVME_NS_DATA_LBAF_LBADS_MASK;
+	flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsdata->flbas);
+	lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, nsdata->lbaf[flbas_fmt]);
 
 	return (1 << lbads);
 }
diff --git a/sbin/nvmecontrol/firmware.c b/sbin/nvmecontrol/firmware.c
index 80bbff032cf2..8fcc4ba4f46e 100644
--- a/sbin/nvmecontrol/firmware.c
+++ b/sbin/nvmecontrol/firmware.c
@@ -278,21 +278,18 @@ firmware(const struct cmd *f, int argc, char *argv[])
 	if (read_controller_data(fd, &cdata))
 		errx(EX_IOERR, "Identify request failed");
 
-	oacs_fw = (cdata.oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) &
-		NVME_CTRLR_DATA_OACS_FIRMWARE_MASK;
+	oacs_fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, cdata.oacs);
 
 	if (oacs_fw == 0)
 		errx(EX_UNAVAILABLE,
 		    "controller does not support firmware activate/download");
 
-	fw_slot1_ro = (cdata.frmw >> NVME_CTRLR_DATA_FRMW_SLOT1_RO_SHIFT) &
-		NVME_CTRLR_DATA_FRMW_SLOT1_RO_MASK;
+	fw_slot1_ro = NVMEV(NVME_CTRLR_DATA_FRMW_SLOT1_RO, cdata.frmw);
 
 	if (opt.fw_img && opt.slot == 1 && fw_slot1_ro)
 		errx(EX_UNAVAILABLE, "slot %d is marked as read only", opt.slot);
 
-	fw_num_slots = (cdata.frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) &
-		NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK;
+	fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata.frmw);
 
 	if (opt.slot > fw_num_slots)
 		errx(EX_UNAVAILABLE,
diff --git a/sbin/nvmecontrol/format.c b/sbin/nvmecontrol/format.c
index 541b207b373f..a56027089ff5 100644
--- a/sbin/nvmecontrol/format.c
+++ b/sbin/nvmecontrol/format.c
@@ -160,38 +160,33 @@ format(const struct cmd *f, int argc, char *argv[])
 	/* Check that controller can execute this command. */
 	if (read_controller_data(fd, &cd))
 		errx(EX_IOERR, "Identify request failed");
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_FORMAT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_FORMAT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_FORMAT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support format");
-	if (((cd.fna >> NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_SHIFT) &
-	    NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_MASK) == 0 && ses == SES_CRYPTO)
+	if (NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cd.fna) == 0 &&
+	    ses == SES_CRYPTO)
 		errx(EX_UNAVAILABLE, "controller does not support cryptographic erase");
 
 	if (nsid != NVME_GLOBAL_NAMESPACE_TAG) {
-		if (((cd.fna >> NVME_CTRLR_DATA_FNA_FORMAT_ALL_SHIFT) &
-		    NVME_CTRLR_DATA_FNA_FORMAT_ALL_MASK) && ses == SES_NONE)
+		if (NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cd.fna) &&
+		    ses == SES_NONE)
 			errx(EX_UNAVAILABLE, "controller does not support per-NS format");
-		if (((cd.fna >> NVME_CTRLR_DATA_FNA_ERASE_ALL_SHIFT) &
-		    NVME_CTRLR_DATA_FNA_ERASE_ALL_MASK) && ses != SES_NONE)
+		if (NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cd.fna) &&
+		    ses != SES_NONE)
 			errx(EX_UNAVAILABLE, "controller does not support per-NS erase");
 
 		/* Try to keep previous namespace parameters. */
 		if (read_namespace_data(fd, nsid, &nsd))
 			errx(EX_IOERR, "Identify request failed");
 		if (lbaf < 0)
-			lbaf = (nsd.flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT)
-			    & NVME_NS_DATA_FLBAS_FORMAT_MASK;
+			lbaf = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsd.flbas);
 		if (lbaf > nsd.nlbaf)
 			errx(EX_USAGE, "LBA format is out of range");
 		if (ms < 0)
-			ms = (nsd.flbas >> NVME_NS_DATA_FLBAS_EXTENDED_SHIFT)
-			    & NVME_NS_DATA_FLBAS_EXTENDED_MASK;
+			ms = NVMEV(NVME_NS_DATA_FLBAS_EXTENDED, nsd.flbas);
 		if (pi < 0)
-			pi = (nsd.dps >> NVME_NS_DATA_DPS_MD_START_SHIFT)
-			    & NVME_NS_DATA_DPS_MD_START_MASK;
+			pi = NVMEV(NVME_NS_DATA_DPS_MD_START, nsd.dps);
 		if (pil < 0)
-			pil = (nsd.dps >> NVME_NS_DATA_DPS_PIT_SHIFT)
-			    & NVME_NS_DATA_DPS_PIT_MASK;
+			pil = NVMEV(NVME_NS_DATA_DPS_PIT, nsd.dps);
 	} else {
 
 		/* We have no previous parameters, so default to zeroes. */
diff --git a/sbin/nvmecontrol/identify.c b/sbin/nvmecontrol/identify.c
index 50698e8bfc70..81aebad0e0d6 100644
--- a/sbin/nvmecontrol/identify.c
+++ b/sbin/nvmecontrol/identify.c
@@ -67,11 +67,9 @@ print_namespace(struct nvme_namespace_data *nsdata)
 	uint8_t		thin_prov, ptype;
 	uint8_t		flbas_fmt, t;
 
-	thin_prov = (nsdata->nsfeat >> NVME_NS_DATA_NSFEAT_THIN_PROV_SHIFT) &
-		NVME_NS_DATA_NSFEAT_THIN_PROV_MASK;
+	thin_prov = NVMEV(NVME_NS_DATA_NSFEAT_THIN_PROV, nsdata->nsfeat);
 
-	flbas_fmt = (nsdata->flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) &
-		NVME_NS_DATA_FLBAS_FORMAT_MASK;
+	flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsdata->flbas);
 
 	printf("Size:                        %lld blocks\n",
 	    (long long)nsdata->nsze);
@@ -83,83 +81,77 @@ print_namespace(struct nvme_namespace_data *nsdata)
 		thin_prov ? "Supported" : "Not Supported");
 	printf("Number of LBA Formats:       %d\n", nsdata->nlbaf+1);
 	printf("Current LBA Format:          LBA Format #%02d", flbas_fmt);
-	if (nsdata->lbaf[flbas_fmt] >> NVME_NS_DATA_LBAF_MS_SHIFT & NVME_NS_DATA_LBAF_MS_MASK)
-		printf(" %s metadata\n", nsdata->flbas >> NVME_NS_DATA_FLBAS_EXTENDED_SHIFT &
-		    NVME_NS_DATA_FLBAS_EXTENDED_MASK ? "Extended" : "Separate");
+	if (NVMEV(NVME_NS_DATA_LBAF_MS, nsdata->lbaf[flbas_fmt]) != 0)
+		printf(" %s metadata\n",
+		    NVMEV(NVME_NS_DATA_FLBAS_EXTENDED, nsdata->flbas) != 0 ?
+		    "Extended" : "Separate");
 	else
 		printf("\n");
 	printf("Metadata Capabilities\n");
 	printf("  Extended:                  %s\n",
-		nsdata->mc >> NVME_NS_DATA_MC_EXTENDED_SHIFT & NVME_NS_DATA_MC_EXTENDED_MASK ? "Supported" : "Not Supported");
+	    NVMEV(NVME_NS_DATA_MC_EXTENDED, nsdata->mc) != 0 ? "Supported" :
+	    "Not Supported");
 	printf("  Separate:                  %s\n",
-		nsdata->mc >> NVME_NS_DATA_MC_POINTER_SHIFT & NVME_NS_DATA_MC_POINTER_MASK ? "Supported" : "Not Supported");
+	    NVMEV(NVME_NS_DATA_MC_POINTER, nsdata->mc) != 0 ? "Supported" :
+	    "Not Supported");
 	printf("Data Protection Caps:        %s%s%s%s%s%s\n",
 	    (nsdata->dpc == 0) ? "Not Supported" : "",
-	    ((nsdata->dpc >> NVME_NS_DATA_DPC_MD_END_SHIFT) &
-	     NVME_NS_DATA_DPC_MD_END_MASK) ? "Last Bytes, " : "",
-	    ((nsdata->dpc >> NVME_NS_DATA_DPC_MD_START_SHIFT) &
-	     NVME_NS_DATA_DPC_MD_START_MASK) ? "First Bytes, " : "",
-	    ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT3_SHIFT) &
-	     NVME_NS_DATA_DPC_PIT3_MASK) ? "Type 3, " : "",
-	    ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT2_SHIFT) &
-	     NVME_NS_DATA_DPC_PIT2_MASK) ? "Type 2, " : "",
-	    ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT1_SHIFT) &
-	     NVME_NS_DATA_DPC_PIT1_MASK) ? "Type 1" : "");
+	    NVMEV(NVME_NS_DATA_DPC_MD_END, nsdata->dpc) != 0 ? "Last Bytes, " :
+	    "",
+	    NVMEV(NVME_NS_DATA_DPC_MD_START, nsdata->dpc) != 0 ?
+	    "First Bytes, " : "",
+	    NVMEV(NVME_NS_DATA_DPC_PIT3, nsdata->dpc) != 0 ? "Type 3, " : "",
+	    NVMEV(NVME_NS_DATA_DPC_PIT2, nsdata->dpc) != 0 ? "Type 2, " : "",
+	    NVMEV(NVME_NS_DATA_DPC_PIT1, nsdata->dpc) != 0 ? "Type 1" : "");
 	printf("Data Protection Settings:    ");
-	ptype = (nsdata->dps >> NVME_NS_DATA_DPS_PIT_SHIFT) &
-	    NVME_NS_DATA_DPS_PIT_MASK;
-	if (ptype) {
+	ptype = NVMEV(NVME_NS_DATA_DPS_PIT, nsdata->dps);
+	if (ptype != 0) {
 		printf("Type %d, %s Bytes\n", ptype,
-		    ((nsdata->dps >> NVME_NS_DATA_DPS_MD_START_SHIFT) &
-		     NVME_NS_DATA_DPS_MD_START_MASK) ? "First" : "Last");
+		    NVMEV(NVME_NS_DATA_DPS_MD_START, nsdata->dps) != 0 ?
+		    "First" : "Last");
 	} else {
 		printf("Not Enabled\n");
 	}
 	printf("Multi-Path I/O Capabilities: %s%s\n",
 	    (nsdata->nmic == 0) ? "Not Supported" : "",
-	    ((nsdata->nmic >> NVME_NS_DATA_NMIC_MAY_BE_SHARED_SHIFT) &
-	     NVME_NS_DATA_NMIC_MAY_BE_SHARED_MASK) ? "May be shared" : "");
+	    NVMEV(NVME_NS_DATA_NMIC_MAY_BE_SHARED, nsdata->nmic) != 0 ?
+	    "May be shared" : "");
 	printf("Reservation Capabilities:    %s%s%s%s%s%s%s%s%s\n",
 	    (nsdata->rescap == 0) ? "Not Supported" : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_IEKEY13_SHIFT) &
-	     NVME_NS_DATA_RESCAP_IEKEY13_MASK) ? "IEKEY13, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_AR_SHIFT) &
-	     NVME_NS_DATA_RESCAP_EX_AC_AR_MASK) ? "EX_AC_AR, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_AR_SHIFT) &
-	     NVME_NS_DATA_RESCAP_WR_EX_AR_MASK) ? "WR_EX_AR, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_RO_SHIFT) &
-	     NVME_NS_DATA_RESCAP_EX_AC_RO_MASK) ? "EX_AC_RO, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_RO_SHIFT) &
-	     NVME_NS_DATA_RESCAP_WR_EX_RO_MASK) ? "WR_EX_RO, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_SHIFT) &
-	     NVME_NS_DATA_RESCAP_EX_AC_MASK) ? "EX_AC, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_SHIFT) &
-	     NVME_NS_DATA_RESCAP_WR_EX_MASK) ? "WR_EX, " : "",
-	    ((nsdata->rescap >> NVME_NS_DATA_RESCAP_PTPL_SHIFT) &
-	     NVME_NS_DATA_RESCAP_PTPL_MASK) ? "PTPL" : "");
+	    NVMEV(NVME_NS_DATA_RESCAP_IEKEY13, nsdata->rescap) != 0 ?
+	    "IEKEY13, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_EX_AC_AR, nsdata->rescap) != 0 ?
+	    "EX_AC_AR, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_WR_EX_AR, nsdata->rescap) != 0 ?
+	    "WR_EX_AR, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_EX_AC_RO, nsdata->rescap) != 0 ?
+	    "EX_AC_RO, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_WR_EX_RO, nsdata->rescap) != 0 ?
+	    "WR_EX_RO, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_EX_AC, nsdata->rescap) != 0 ?
+	    "EX_AC, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_WR_EX, nsdata->rescap) != 0 ?
+	    "WR_EX, " : "",
+	    NVMEV(NVME_NS_DATA_RESCAP_PTPL, nsdata->rescap) != 0 ? "PTPL" : "");
 	printf("Format Progress Indicator:   ");
-	if ((nsdata->fpi >> NVME_NS_DATA_FPI_SUPP_SHIFT) &
-	    NVME_NS_DATA_FPI_SUPP_MASK) {
+	if (NVMEV(NVME_NS_DATA_FPI_SUPP, nsdata->fpi) != 0) {
 		printf("%u%% remains\n",
-		    (nsdata->fpi >> NVME_NS_DATA_FPI_PERC_SHIFT) &
-		    NVME_NS_DATA_FPI_PERC_MASK);
+		    NVMEV(NVME_NS_DATA_FPI_PERC, nsdata->fpi));
 	} else
 		printf("Not Supported\n");
-	t = (nsdata->dlfeat >> NVME_NS_DATA_DLFEAT_READ_SHIFT) &
-	    NVME_NS_DATA_DLFEAT_READ_MASK;
+	t = NVMEV(NVME_NS_DATA_DLFEAT_READ, nsdata->dlfeat);
 	printf("Deallocate Logical Block:    Read %s%s%s\n",
 	    (t == NVME_NS_DATA_DLFEAT_READ_NR) ? "Not Reported" :
 	    (t == NVME_NS_DATA_DLFEAT_READ_00) ? "00h" :
 	    (t == NVME_NS_DATA_DLFEAT_READ_FF) ? "FFh" : "Unknown",
-	    (nsdata->dlfeat >> NVME_NS_DATA_DLFEAT_DWZ_SHIFT) &
-	     NVME_NS_DATA_DLFEAT_DWZ_MASK ? ", Write Zero" : "",
-	    (nsdata->dlfeat >> NVME_NS_DATA_DLFEAT_GCRC_SHIFT) &
-	     NVME_NS_DATA_DLFEAT_GCRC_MASK ? ", Guard CRC" : "");
+	    NVMEV(NVME_NS_DATA_DLFEAT_DWZ, nsdata->dlfeat) != 0 ?
+	    ", Write Zero" : "",
+	    NVMEV(NVME_NS_DATA_DLFEAT_GCRC, nsdata->dlfeat) != 0 ?
+	    ", Guard CRC" : "");
 	printf("Optimal I/O Boundary:        %u blocks\n", nsdata->noiob);
 	printf("NVM Capacity:                %s bytes\n",
 	   uint128_to_str(to128(nsdata->nvmcap), cbuf, sizeof(cbuf)));
-	if ((nsdata->nsfeat >> NVME_NS_DATA_NSFEAT_NPVALID_SHIFT) &
-	    NVME_NS_DATA_NSFEAT_NPVALID_MASK) {
+	if (NVMEV(NVME_NS_DATA_NSFEAT_NPVALID, nsdata->nsfeat) != 0) {
 		printf("Preferred Write Granularity: %u blocks\n",
 		    nsdata->npwg + 1);
 		printf("Preferred Write Alignment:   %u blocks\n",
@@ -181,14 +173,11 @@ print_namespace(struct nvme_namespace_data *nsdata)
 	printf("\n");
 	for (i = 0; i <= nsdata->nlbaf; i++) {
 		lbaf = nsdata->lbaf[i];
-		lbads = (lbaf >> NVME_NS_DATA_LBAF_LBADS_SHIFT) &
-			NVME_NS_DATA_LBAF_LBADS_MASK;
+		lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, lbaf);
 		if (lbads == 0)
 			continue;
-		ms = (lbaf >> NVME_NS_DATA_LBAF_MS_SHIFT) &
-			NVME_NS_DATA_LBAF_MS_MASK;
-		rp = (lbaf >> NVME_NS_DATA_LBAF_RP_SHIFT) &
-			NVME_NS_DATA_LBAF_RP_MASK;
+		ms = NVMEV(NVME_NS_DATA_LBAF_MS, lbaf);
+		rp = NVMEV(NVME_NS_DATA_LBAF_RP, lbaf);
 		printf("LBA Format #%02d: Data Size: %5d  Metadata Size: %5d"
 		    "  Performance: %s\n",
 		    i, 1 << lbads, ms, (rp == 0) ? "Best" :
diff --git a/sbin/nvmecontrol/identify_ext.c b/sbin/nvmecontrol/identify_ext.c
index 72b1ff5ccd7b..cc30ba0d6349 100644
--- a/sbin/nvmecontrol/identify_ext.c
+++ b/sbin/nvmecontrol/identify_ext.c
@@ -57,41 +57,27 @@ nvme_print_controller(struct nvme_controller_data *cdata)
 	uint8_t fwug;
 
 	oncs = cdata->oncs;
-	compare = (oncs >> NVME_CTRLR_DATA_ONCS_COMPARE_SHIFT) &
-		NVME_CTRLR_DATA_ONCS_COMPARE_MASK;
-	write_unc = (oncs >> NVME_CTRLR_DATA_ONCS_WRITE_UNC_SHIFT) &
-		NVME_CTRLR_DATA_ONCS_WRITE_UNC_MASK;
-	dsm = (oncs >> NVME_CTRLR_DATA_ONCS_DSM_SHIFT) &
-		NVME_CTRLR_DATA_ONCS_DSM_MASK;
+	compare = NVMEV(NVME_CTRLR_DATA_ONCS_COMPARE, oncs);
+	write_unc = NVMEV(NVME_CTRLR_DATA_ONCS_WRITE_UNC, oncs);
+	dsm = NVMEV(NVME_CTRLR_DATA_ONCS_DSM, oncs);
 
 	oacs = cdata->oacs;
-	security = (oacs >> NVME_CTRLR_DATA_OACS_SECURITY_SHIFT) &
-		NVME_CTRLR_DATA_OACS_SECURITY_MASK;
-	fmt = (oacs >> NVME_CTRLR_DATA_OACS_FORMAT_SHIFT) &
-		NVME_CTRLR_DATA_OACS_FORMAT_MASK;
-	fw = (oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) &
-		NVME_CTRLR_DATA_OACS_FIRMWARE_MASK;
-	nsmgmt = (oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-		NVME_CTRLR_DATA_OACS_NSMGMT_MASK;
+	security = NVMEV(NVME_CTRLR_DATA_OACS_SECURITY, oacs);
+	fmt = NVMEV(NVME_CTRLR_DATA_OACS_FORMAT, oacs);
+	fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, oacs);
+	nsmgmt = NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, oacs);
 
-	fw_num_slots = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) &
-		NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK;
-	fw_slot1_ro = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_SLOT1_RO_SHIFT) &
-		NVME_CTRLR_DATA_FRMW_SLOT1_RO_MASK;
+	fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
+	fw_slot1_ro = NVMEV(NVME_CTRLR_DATA_FRMW_SLOT1_RO, cdata->frmw);
 	fwug = cdata->fwug;
 
-	ns_smart = (cdata->lpa >> NVME_CTRLR_DATA_LPA_NS_SMART_SHIFT) &
-		NVME_CTRLR_DATA_LPA_NS_SMART_MASK;
+	ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata->lpa);
 
-	sqes_min = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MIN_SHIFT) &
-		NVME_CTRLR_DATA_SQES_MIN_MASK;
-	sqes_max = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MAX_SHIFT) &
-		NVME_CTRLR_DATA_SQES_MAX_MASK;
+	sqes_min = NVMEV(NVME_CTRLR_DATA_SQES_MIN, cdata->sqes);
+	sqes_max = NVMEV(NVME_CTRLR_DATA_SQES_MAX, cdata->sqes);
 
-	cqes_min = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MIN_SHIFT) &
-		NVME_CTRLR_DATA_CQES_MIN_MASK;
-	cqes_max = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MAX_SHIFT) &
-		NVME_CTRLR_DATA_CQES_MAX_MASK;
+	cqes_min = NVMEV(NVME_CTRLR_DATA_CQES_MIN, cdata->cqes);
+	cqes_max = NVMEV(NVME_CTRLR_DATA_CQES_MAX, cdata->cqes);
 
 	printf("Controller Capabilities/Features\n");
 	printf("================================\n");
@@ -108,14 +94,14 @@ nvme_print_controller(struct nvme_controller_data *cdata)
 		cdata->ieee[2], cdata->ieee[1], cdata->ieee[0]);
 	printf("Multi-Path I/O Capabilities: %s%s%s%s%s\n",
 	    (cdata->mic == 0) ? "Not Supported" : "",
-	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_ANAR_SHIFT) &
-	     NVME_CTRLR_DATA_MIC_SRIOVVF_MASK) ? "Asymmetric, " : "",
-	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_SRIOVVF_SHIFT) &
-	     NVME_CTRLR_DATA_MIC_SRIOVVF_MASK) ? "SR-IOV VF, " : "",
-	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_MCTRLRS_SHIFT) &
-	     NVME_CTRLR_DATA_MIC_MCTRLRS_MASK) ? "Multiple controllers, " : "",
-	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_MPORTS_SHIFT) &
-	     NVME_CTRLR_DATA_MIC_MPORTS_MASK) ? "Multiple ports" : "");
+	    NVMEV(NVME_CTRLR_DATA_MIC_ANAR, cdata->mic) != 0 ?
+	    "Asymmetric, " : "",
+	    NVMEV(NVME_CTRLR_DATA_MIC_SRIOVVF, cdata->mic) != 0 ?
+	    "SR-IOV VF, " : "",
+	    NVMEV(NVME_CTRLR_DATA_MIC_MCTRLRS, cdata->mic) != 0 ?
+	    "Multiple controllers, " : "",
+	    NVMEV(NVME_CTRLR_DATA_MIC_MPORTS, cdata->mic) != 0 ?
+	    "Multiple ports" : "");
 	/* TODO: Use CAP.MPSMIN to determine true memory page size. */
 	printf("Max Data Transfer Size:      ");
 	if (cdata->mdts == 0)
@@ -123,24 +109,19 @@ nvme_print_controller(struct nvme_controller_data *cdata)
 	else
 		printf("%ld bytes\n", PAGE_SIZE * (1L << cdata->mdts));
 	printf("Sanitize Crypto Erase:       %s\n",
-		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_CES_SHIFT) &
-		    NVME_CTRLR_DATA_SANICAP_CES_MASK) ?
-		    "Supported" : "Not Supported");
+	    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
+	    "Supported" : "Not Supported");
 	printf("Sanitize Block Erase:        %s\n",
-		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_BES_SHIFT) &
-		    NVME_CTRLR_DATA_SANICAP_BES_MASK) ?
-		    "Supported" : "Not Supported");
+	    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
+	    "Supported" : "Not Supported");
 	printf("Sanitize Overwrite:          %s\n",
-		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_OWS_SHIFT) &
-		    NVME_CTRLR_DATA_SANICAP_OWS_MASK) ?
-		    "Supported" : "Not Supported");
+	    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
+	    "Supported" : "Not Supported");
 	printf("Sanitize NDI:                %s\n",
-		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_NDI_SHIFT) &
-		    NVME_CTRLR_DATA_SANICAP_NDI_MASK) ?
-		    "Supported" : "Not Supported");
+	    NVMEV(NVME_CTRLR_DATA_SANICAP_NDI, cdata->sanicap) != 0 ?
+	    "Supported" : "Not Supported");
 	printf("Sanitize NODMMAS:            ");
-	switch (((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_NODMMAS_SHIFT) &
-	    NVME_CTRLR_DATA_SANICAP_NODMMAS_MASK)) {
+	switch (NVMEV(NVME_CTRLR_DATA_SANICAP_NODMMAS, cdata->sanicap)) {
 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_UNDEF:
 		printf("Undefined\n");
 		break;
@@ -171,32 +152,26 @@ nvme_print_controller(struct nvme_controller_data *cdata)
 	printf("Namespace Management:        %s\n",
 		nsmgmt ? "Supported" : "Not Supported");
 	printf("Device Self-test:            %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_SELFTEST_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_SELFTEST_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, oacs) != 0 ? "" : "Not ");
 	printf("Directives:                  %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_DIRECTIVES_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_DIRECTIVES_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_DIRECTIVES, oacs) != 0 ? "" : "Not ");
 	printf("NVMe-MI Send/Receive:        %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_NVMEMI_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_NVMEMI_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_NVMEMI, oacs) != 0 ? "" : "Not ");
 	printf("Virtualization Management:   %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_VM_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_VM_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_VM, oacs) != 0 ? "" : "Not ");
 	printf("Doorbell Buffer Config:      %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_DBBUFFER_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_DBBUFFER_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_DBBUFFER, oacs) != 0 ? "" : "Not ");
 	printf("Get LBA Status:              %sSupported\n",
-	    ((oacs >> NVME_CTRLR_DATA_OACS_GETLBA_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_GETLBA_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_OACS_GETLBA, oacs) != 0 ? "" : "Not ");
 	printf("Sanitize:                    ");
 	if (cdata->sanicap != 0) {
 		printf("%s%s%s\n",
-		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_CES_SHIFT) &
-		     NVME_CTRLR_DATA_SANICAP_CES_MASK) ? "crypto, " : "",
-		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_BES_SHIFT) &
-		     NVME_CTRLR_DATA_SANICAP_BES_MASK) ? "block, " : "",
-		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_OWS_SHIFT) &
-		     NVME_CTRLR_DATA_SANICAP_OWS_MASK) ? "overwrite" : "");
+		    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
+		    "crypto, " : "",
+		    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
+		    "block, " : "",
+		    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
+		    "overwrite" : "");
 	} else {
 		printf("Not Supported\n");
 	}
@@ -245,36 +220,30 @@ nvme_print_controller(struct nvme_controller_data *cdata)
 	printf("Dataset Management Command:  %s\n",
 		dsm ? "Supported" : "Not Supported");
 	printf("Write Zeroes Command:        %sSupported\n",
-	    ((oncs >> NVME_CTRLR_DATA_ONCS_WRZERO_SHIFT) &
-	     NVME_CTRLR_DATA_ONCS_WRZERO_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_ONCS_WRZERO, oncs) != 0 ? "" : "Not ");
 	printf("Save Features:               %sSupported\n",
-	    ((oncs >> NVME_CTRLR_DATA_ONCS_SAVEFEAT_SHIFT) &
-	     NVME_CTRLR_DATA_ONCS_SAVEFEAT_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_ONCS_SAVEFEAT, oncs) != 0 ? "" : "Not ");
 	printf("Reservations:                %sSupported\n",
-	    ((oncs >> NVME_CTRLR_DATA_ONCS_RESERV_SHIFT) &
-	     NVME_CTRLR_DATA_ONCS_RESERV_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_ONCS_RESERV, oncs) != 0 ? "" : "Not ");
 	printf("Timestamp feature:           %sSupported\n",
-	    ((oncs >> NVME_CTRLR_DATA_ONCS_TIMESTAMP_SHIFT) &
-	     NVME_CTRLR_DATA_ONCS_TIMESTAMP_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, oncs) != 0 ? "" : "Not ");
 	printf("Verify feature:              %sSupported\n",
-	    ((oncs >> NVME_CTRLR_DATA_ONCS_VERIFY_SHIFT) &
-	     NVME_CTRLR_DATA_ONCS_VERIFY_MASK) ? "" : "Not ");
+	    NVMEV(NVME_CTRLR_DATA_ONCS_VERIFY, oncs) != 0 ? "" : "Not ");
 	printf("Fused Operation Support:     %s%s\n",
 	    (cdata->fuses == 0) ? "Not Supported" : "",
-	    ((cdata->fuses >> NVME_CTRLR_DATA_FUSES_CNW_SHIFT) &
-	     NVME_CTRLR_DATA_FUSES_CNW_MASK) ? "Compare and Write" : "");
+	    NVMEV(NVME_CTRLR_DATA_FUSES_CNW, cdata->fuses) != 0 ?
+	    "Compare and Write" : "");
 	printf("Format NVM Attributes:       %s%s Erase, %s Format\n",
-	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_SHIFT) &
-	     NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_MASK) ? "Crypto Erase, " : "",
-	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_ERASE_ALL_SHIFT) &
-	     NVME_CTRLR_DATA_FNA_ERASE_ALL_MASK) ? "All-NVM" : "Per-NS",
-	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_FORMAT_ALL_SHIFT) &
-	     NVME_CTRLR_DATA_FNA_FORMAT_ALL_MASK) ? "All-NVM" : "Per-NS");
-	t = (cdata->vwc >> NVME_CTRLR_DATA_VWC_ALL_SHIFT) &
-	    NVME_CTRLR_DATA_VWC_ALL_MASK;
+	    NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cdata->fna) != 0 ?
+	    "Crypto Erase, " : "",
+	    NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cdata->fna) != 0 ?
+	    "All-NVM" : "Per-NS",
+	    NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cdata->fna) != 0 ?
+	    "All-NVM" : "Per-NS");
+	t = NVMEV(NVME_CTRLR_DATA_VWC_ALL, cdata->vwc);
 	printf("Volatile Write Cache:        %s%s\n",
-	    ((cdata->vwc >> NVME_CTRLR_DATA_VWC_PRESENT_SHIFT) &
-	     NVME_CTRLR_DATA_VWC_PRESENT_MASK) ? "Present" : "Not Present",
+	    NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cdata->vwc) != 0 ?
+	    "Present" : "Not Present",
 	    (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
 	    (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
 
diff --git a/sbin/nvmecontrol/logpage.c b/sbin/nvmecontrol/logpage.c
index 31ec3a443716..8c03aa6fb7f4 100644
--- a/sbin/nvmecontrol/logpage.c
+++ b/sbin/nvmecontrol/logpage.c
@@ -402,13 +402,10 @@ print_log_firmware(const struct nvme_controller_data *cdata, void *buf, uint32_t
 	uint16_t			oacs_fw;
 	uint8_t				fw_num_slots;
 
-	afi_slot = fw->afi >> NVME_FIRMWARE_PAGE_AFI_SLOT_SHIFT;
-	afi_slot &= NVME_FIRMWARE_PAGE_AFI_SLOT_MASK;
+	afi_slot = NVMEV(NVME_FIRMWARE_PAGE_AFI_SLOT, fw->afi);
 
-	oacs_fw = (cdata->oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) &
-		NVME_CTRLR_DATA_OACS_FIRMWARE_MASK;
-	fw_num_slots = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) &
-		NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK;
+	oacs_fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, cdata->oacs);
+	fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
 
 	printf("Firmware Slot Log\n");
 	printf("=================\n");
@@ -463,41 +460,27 @@ print_log_command_effects(const struct nvme_controller_data *cdata __unused,
 
 	for (i = 0; i < 255; i++) {
 		s = ce->acs[i];
-		if (((s >> NVME_CE_PAGE_CSUP_SHIFT) &
-		     NVME_CE_PAGE_CSUP_MASK) == 0)
+		if (NVMEV(NVME_CE_PAGE_CSUP, s) == 0)
 			continue;
 		printf("Admin\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
-		    ((s >> NVME_CE_PAGE_LBCC_SHIFT) &
-		     NVME_CE_PAGE_LBCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_NCC_SHIFT) &
-		     NVME_CE_PAGE_NCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_NIC_SHIFT) &
-		     NVME_CE_PAGE_NIC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_CCC_SHIFT) &
-		     NVME_CE_PAGE_CCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_CSE_SHIFT) &
-		     NVME_CE_PAGE_CSE_MASK),
-		    ((s >> NVME_CE_PAGE_UUID_SHIFT) &
-		     NVME_CE_PAGE_UUID_MASK) ? "Yes" : "No");
+		    NVMEV(NVME_CE_PAGE_LBCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_NCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_NIC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_CCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_CSE, s),
+		    NVMEV(NVME_CE_PAGE_UUID, s) != 0 ? "Yes" : "No");
 	}
 	for (i = 0; i < 255; i++) {
 		s = ce->iocs[i];
-		if (((s >> NVME_CE_PAGE_CSUP_SHIFT) &
-		     NVME_CE_PAGE_CSUP_MASK) == 0)
+		if (NVMEV(NVME_CE_PAGE_CSUP, s) == 0)
 			continue;
 		printf("I/O\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
-		    ((s >> NVME_CE_PAGE_LBCC_SHIFT) &
-		     NVME_CE_PAGE_LBCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_NCC_SHIFT) &
-		     NVME_CE_PAGE_NCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_NIC_SHIFT) &
-		     NVME_CE_PAGE_NIC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_CCC_SHIFT) &
-		     NVME_CE_PAGE_CCC_MASK) ? "Yes" : "No",
-		    ((s >> NVME_CE_PAGE_CSE_SHIFT) &
-		     NVME_CE_PAGE_CSE_MASK),
-		    ((s >> NVME_CE_PAGE_UUID_SHIFT) &
-		     NVME_CE_PAGE_UUID_MASK) ? "Yes" : "No");
+		    NVMEV(NVME_CE_PAGE_LBCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_NCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_NIC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_CCC, s) != 0 ? "Yes" : "No",
+		    NVMEV(NVME_CE_PAGE_CSE, s),
+		    NVMEV(NVME_CE_PAGE_UUID, s) != 0 ? "Yes" : "No");
 	}
 }
 
@@ -548,8 +531,7 @@ print_log_sanitize_status(const struct nvme_controller_data *cdata __unused,
 	printf("Sanitize Progress:                   %u%% (%u/65535)\n",
 	    (ss->sprog * 100 + 32768) / 65536, ss->sprog);
 	printf("Sanitize Status:                     ");
-	switch ((ss->sstat >> NVME_SS_PAGE_SSTAT_STATUS_SHIFT) &
-	    NVME_SS_PAGE_SSTAT_STATUS_MASK) {
+	switch (NVMEV(NVME_SS_PAGE_SSTAT_STATUS, ss->sstat)) {
 	case NVME_SS_PAGE_SSTAT_STATUS_NEVER:
 		printf("Never sanitized");
 		break;
@@ -569,12 +551,10 @@ print_log_sanitize_status(const struct nvme_controller_data *cdata __unused,
 		printf("Unknown");
 		break;
 	}
-	p = (ss->sstat >> NVME_SS_PAGE_SSTAT_PASSES_SHIFT) &
-	    NVME_SS_PAGE_SSTAT_PASSES_MASK;
+	p = NVMEV(NVME_SS_PAGE_SSTAT_PASSES, ss->sstat);
 	if (p > 0)
 		printf(", %d passes", p);
-	if ((ss->sstat >> NVME_SS_PAGE_SSTAT_GDE_SHIFT) &
-	    NVME_SS_PAGE_SSTAT_GDE_MASK)
+	if (NVMEV(NVME_SS_PAGE_SSTAT_GDE, ss->sstat) != 0)
 		printf(", Global Data Erased");
 	printf("\n");
 	printf("Sanitize Command Dword 10:           0x%x\n", ss->scdw10);
@@ -796,8 +776,7 @@ logpage(const struct cmd *f, int argc, char *argv[])
 	if (read_controller_data(fd, &cdata))
 		errx(EX_IOERR, "Identify request failed");
 
-	ns_smart = (cdata.lpa >> NVME_CTRLR_DATA_LPA_NS_SMART_SHIFT) &
-		NVME_CTRLR_DATA_LPA_NS_SMART_MASK;
+	ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata.lpa);
 
 	/*
 	 * The log page attributes indicate whether or not the controller
diff --git a/sbin/nvmecontrol/ns.c b/sbin/nvmecontrol/ns.c
index dd678568d5ca..a77f37e0f468 100644
--- a/sbin/nvmecontrol/ns.c
+++ b/sbin/nvmecontrol/ns.c
@@ -417,8 +417,7 @@ nsactive(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
@@ -463,8 +462,7 @@ nsallocated(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
@@ -509,8 +507,7 @@ nscontrollers(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
@@ -571,8 +568,7 @@ nscreate(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&nsdata, 0, sizeof(nsdata));
@@ -630,8 +626,7 @@ nscreate(const struct cmd *f, int argc, char *argv[])
 
 	if (nvme_completion_is_error(&pt.cpl)) {
 		errx(EX_IOERR, "namespace creation failed: %s",
-		    get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) &
-		    NVME_STATUS_SC_MASK));
+		    get_res_str(NVMEV(NVME_STATUS_SC, pt.cpl.status)));
 	}
 	printf("namespace %d created\n", pt.cpl.cdw0);
 	exit(0);
@@ -667,8 +662,7 @@ nsdelete(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
@@ -684,8 +678,7 @@ nsdelete(const struct cmd *f, int argc, char *argv[])
 
 	if (nvme_completion_is_error(&pt.cpl)) {
 		errx(EX_IOERR, "namespace deletion failed: %s",
-		    get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) &
-		    NVME_STATUS_SC_MASK));
+		    get_res_str(NVMEV(NVME_STATUS_SC, pt.cpl.status)));
 	}
 	printf("namespace %d deleted\n", nsid);
 	exit(0);
@@ -734,8 +727,7 @@ nsattach(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	if (attach_opt.ctrlrid == NONE) {
@@ -771,8 +763,7 @@ nsattach(const struct cmd *f, int argc, char *argv[])
 
 	if (nvme_completion_is_error(&pt.cpl)) {
 		errx(EX_IOERR, "namespace attach failed: %s",
-		    get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) &
-		    NVME_STATUS_SC_MASK));
+		    get_res_str(NVMEV(NVME_STATUS_SC, pt.cpl.status)));
 	}
 	printf("namespace %d attached\n", nsid);
 	exit(0);
@@ -806,8 +797,7 @@ nsdetach(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	if (detach_opt.ctrlrid == NONE) {
@@ -850,8 +840,7 @@ nsdetach(const struct cmd *f, int argc, char *argv[])
 
 	if (nvme_completion_is_error(&pt.cpl)) {
 		errx(EX_IOERR, "namespace detach failed: %s",
-		    get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) &
-		    NVME_STATUS_SC_MASK));
+		    get_res_str(NVMEV(NVME_STATUS_SC, pt.cpl.status)));
 	}
 	printf("namespace %d detached\n", nsid);
 	exit(0);
@@ -885,8 +874,7 @@ nsattached(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
@@ -939,8 +927,7 @@ nsidentify(const struct cmd *f, int argc, char *argv[])
 		errx(EX_IOERR, "Identify request failed");
 
 	/* Check that controller can execute this command. */
-	if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
-	    NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, cd.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support namespace management");
 
 	memset(&pt, 0, sizeof(pt));
diff --git a/sbin/nvmecontrol/power.c b/sbin/nvmecontrol/power.c
index 78de46dbc277..887010feb782 100644
--- a/sbin/nvmecontrol/power.c
+++ b/sbin/nvmecontrol/power.c
@@ -63,14 +63,10 @@ power_list_one(int i, struct nvme_power_state *nps)
 	int mpower, apower, ipower;
 	uint8_t mps, nops, aps, apw;
 
-	mps = (nps->mps_nops >> NVME_PWR_ST_MPS_SHIFT) &
-		NVME_PWR_ST_MPS_MASK;
-	nops = (nps->mps_nops >> NVME_PWR_ST_NOPS_SHIFT) &
-		NVME_PWR_ST_NOPS_MASK;
-	apw = (nps->apw_aps >> NVME_PWR_ST_APW_SHIFT) &
-		NVME_PWR_ST_APW_MASK;
-	aps = (nps->apw_aps >> NVME_PWR_ST_APS_SHIFT) &
-		NVME_PWR_ST_APS_MASK;
+	mps = NVMEV(NVME_PWR_ST_MPS, nps->mps_nops);
+	nops = NVMEV(NVME_PWR_ST_NOPS, nps->mps_nops);
+	apw = NVMEV(NVME_PWR_ST_APW, nps->apw_aps);
+	aps = NVMEV(NVME_PWR_ST_APS, nps->apw_aps);
 
 	mpower = nps->mp;
 	if (mps == 0)
diff --git a/sbin/nvmecontrol/sanitize.c b/sbin/nvmecontrol/sanitize.c
index d56a74685651..4611a6964a4d 100644
--- a/sbin/nvmecontrol/sanitize.c
+++ b/sbin/nvmecontrol/sanitize.c
@@ -155,14 +155,11 @@ sanitize(const struct cmd *f, int argc, char *argv[])
 	/* Check that controller can execute this command. */
 	if (read_controller_data(fd, &cd))
 		errx(EX_IOERR, "Identify request failed");
-	if (((cd.sanicap >> NVME_CTRLR_DATA_SANICAP_BES_SHIFT) &
-	     NVME_CTRLR_DATA_SANICAP_BES_MASK) == 0 && sanact == 2)
+	if (NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cd.sanicap) == 0 && sanact == 2)
 		errx(EX_UNAVAILABLE, "controller does not support Block Erase");
-	if (((cd.sanicap >> NVME_CTRLR_DATA_SANICAP_OWS_SHIFT) &
-	     NVME_CTRLR_DATA_SANICAP_OWS_MASK) == 0 && sanact == 3)
+	if (NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cd.sanicap) == 0 && sanact == 3)
 		errx(EX_UNAVAILABLE, "controller does not support Overwrite");
-	if (((cd.sanicap >> NVME_CTRLR_DATA_SANICAP_CES_SHIFT) &
-	     NVME_CTRLR_DATA_SANICAP_CES_MASK) == 0 && sanact == 4)
+	if (NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cd.sanicap) == 0 && sanact == 4)
 		errx(EX_UNAVAILABLE, "controller does not support Crypto Erase");
 
 	/*
@@ -187,8 +184,7 @@ sanitize(const struct cmd *f, int argc, char *argv[])
 wait:
 	read_logpage(fd, NVME_LOG_SANITIZE_STATUS,
 	    NVME_GLOBAL_NAMESPACE_TAG, 0, 0, 0, &ss, sizeof(ss));
-	switch ((ss.sstat >> NVME_SS_PAGE_SSTAT_STATUS_SHIFT) &
-	    NVME_SS_PAGE_SSTAT_STATUS_MASK) {
+	switch (NVMEV(NVME_SS_PAGE_SSTAT_STATUS, ss.sstat)) {
 	case NVME_SS_PAGE_SSTAT_STATUS_NEVER:
 		printf("Never sanitized");
 		break;
diff --git a/sbin/nvmecontrol/selftest.c b/sbin/nvmecontrol/selftest.c
index 6139a7902234..0fae3a3062ae 100644
--- a/sbin/nvmecontrol/selftest.c
+++ b/sbin/nvmecontrol/selftest.c
@@ -100,8 +100,7 @@ selftest(const struct cmd *f, int argc, char *argv[])
 	if (read_controller_data(fd, &cdata))
 		errx(EX_IOERR, "Identify request failed");
 
-	if (((cdata.oacs >> NVME_CTRLR_DATA_OACS_SELFTEST_SHIFT) &
-	     NVME_CTRLR_DATA_OACS_SELFTEST_MASK) == 0)
+	if (NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, cdata.oacs) == 0)
 		errx(EX_UNAVAILABLE, "controller does not support self-test");
 
 	selftest_op(fd, nsid, opt.stc);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202408261803.47QI3CBF042393>