Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Aug 2024 18:03:23 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: f314e46271f1 - stable/14 - bhyve: Use NVMEF macro to construct fields
Message-ID:  <202408261803.47QI3NhC042941@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=f314e46271f1100c258a72aa8c0e072f0f3ef2e6

commit f314e46271f1100c258a72aa8c0e072f0f3ef2e6
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-01-29 19:02:07 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-08-26 17:27:53 +0000

    bhyve: Use NVMEF macro to construct fields
    
    Reviewed by:    corvink, chuck (older version)
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D43607
    
    (cherry picked from commit c46860dbcb2037933575a260028325418b3e9789)
---
 usr.sbin/bhyve/pci_nvme.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c
index cd81767d950b..45ab1b11fda4 100644
--- a/usr.sbin/bhyve/pci_nvme.c
+++ b/usr.sbin/bhyve/pci_nvme.c
@@ -393,11 +393,11 @@ static void pci_nvme_io_done(struct blockif_req *, int);
 #define	NVME_CSTS_GET_RDY(sts) \
 	NVMEV(NVME_CSTS_REG_RDY, sts)
 
-#define	NVME_CSTS_RDY	(1 << NVME_CSTS_REG_RDY_SHIFT)
-#define	NVME_CSTS_CFS	(1 << NVME_CSTS_REG_CFS_SHIFT)
+#define	NVME_CSTS_RDY	(NVMEF(NVME_CSTS_REG_RDY, 1))
+#define	NVME_CSTS_CFS	(NVMEF(NVME_CSTS_REG_CFS, 1))
 
 /* Completion Queue status word utils */
-#define	NVME_STATUS_P	(1 << NVME_STATUS_P_SHIFT)
+#define	NVME_STATUS_P	(NVMEF(NVME_STATUS_P, 1))
 #define	NVME_STATUS_MASK \
 	(NVMEM(NVME_STATUS_SCT) | \
 	 NVMEM(NVME_STATUS_SC))
@@ -442,8 +442,7 @@ pci_nvme_status_tc(uint16_t *status, uint16_t type, uint16_t code)
 {
 
 	*status &= ~NVME_STATUS_MASK;
-	*status |= (type & NVME_STATUS_SCT_MASK) << NVME_STATUS_SCT_SHIFT |
-		(code & NVME_STATUS_SC_MASK) << NVME_STATUS_SC_SHIFT;
+	*status |= NVMEF(NVME_STATUS_SCT, type) | NVMEF(NVME_STATUS_SC, code);
 }
 
 static __inline void
@@ -536,14 +535,14 @@ pci_nvme_init_ctrldata(struct pci_nvme_softc *sc)
 	cd->ver = NVME_REV(1,4);
 
 	cd->cntrltype = NVME_CNTRLTYPE_IO;
-	cd->oacs = 1 << NVME_CTRLR_DATA_OACS_FORMAT_SHIFT;
+	cd->oacs = NVMEF(NVME_CTRLR_DATA_OACS_FORMAT, 1);
 	cd->oaes = NVMEM(NVME_CTRLR_DATA_OAES_NS_ATTR);
 	cd->acl = 2;
 	cd->aerl = 4;
 
 	/* Advertise 1, Read-only firmware slot */
 	cd->frmw = NVMEM(NVME_CTRLR_DATA_FRMW_SLOT1_RO) |
-	    (1 << NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT);
+	    NVMEF(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, 1);
 	cd->lpa = 0;	/* TODO: support some simple things like SMART */
 	cd->elpe = 0;	/* max error log page entries */
 	/*
@@ -557,13 +556,13 @@ pci_nvme_init_ctrldata(struct pci_nvme_softc *sc)
 	cd->cctemp = 0x0157;
 
 	/* SANICAP must not be 0 for Revision 1.4 and later NVMe Controllers */
-	cd->sanicap = (NVME_CTRLR_DATA_SANICAP_NODMMAS_NO <<
-			NVME_CTRLR_DATA_SANICAP_NODMMAS_SHIFT);
+	cd->sanicap = NVMEF(NVME_CTRLR_DATA_SANICAP_NODMMAS,
+	    NVME_CTRLR_DATA_SANICAP_NODMMAS_NO);
 
-	cd->sqes = (6 << NVME_CTRLR_DATA_SQES_MAX_SHIFT) |
-	    (6 << NVME_CTRLR_DATA_SQES_MIN_SHIFT);
-	cd->cqes = (4 << NVME_CTRLR_DATA_CQES_MAX_SHIFT) |
-	    (4 << NVME_CTRLR_DATA_CQES_MIN_SHIFT);
+	cd->sqes = NVMEF(NVME_CTRLR_DATA_SQES_MAX, 6) |
+	    NVMEF(NVME_CTRLR_DATA_SQES_MIN, 6);
+	cd->cqes = NVMEF(NVME_CTRLR_DATA_CQES_MAX, 4) |
+	    NVMEF(NVME_CTRLR_DATA_CQES_MIN, 4);
 	cd->nn = 1;	/* number of namespaces */
 
 	cd->oncs = 0;
@@ -581,7 +580,7 @@ pci_nvme_init_ctrldata(struct pci_nvme_softc *sc)
 
 	cd->fna = NVMEM(NVME_CTRLR_DATA_FNA_FORMAT_ALL);
 
-	cd->vwc = NVME_CTRLR_DATA_VWC_ALL_NO << NVME_CTRLR_DATA_VWC_ALL_SHIFT;
+	cd->vwc = NVMEF(NVME_CTRLR_DATA_VWC_ALL, NVME_CTRLR_DATA_VWC_ALL_NO);
 
 	ret = snprintf(cd->subnqn, sizeof(cd->subnqn),
 	    "nqn.2013-12.org.freebsd:bhyve-%s-%u-%u-%u",
@@ -634,7 +633,7 @@ pci_nvme_init_nsdata(struct pci_nvme_softc *sc,
 	be64enc(nd->eui64, nvstore->eui64);
 
 	/* LBA data-sz = 2^lbads */
-	nd->lbaf[0] = nvstore->sectsz_bits << NVME_NS_DATA_LBAF_LBADS_SHIFT;
+	nd->lbaf[0] = NVMEF(NVME_NS_DATA_LBAF_LBADS, nvstore->sectsz_bits);
 }
 
 static void
@@ -657,7 +656,7 @@ pci_nvme_init_logpages(struct pci_nvme_softc *sc)
 	sc->health_log.available_spare_threshold = 10;
 
 	/* Set Active Firmware Info to slot 1 */
-	sc->fw_log.afi = (1 << NVME_FIRMWARE_PAGE_AFI_SLOT_SHIFT);
+	sc->fw_log.afi = NVMEF(NVME_FIRMWARE_PAGE_AFI_SLOT, 1);
 	memcpy(&sc->fw_log.revision[0], sc->ctrldata.fr,
 	    sizeof(sc->fw_log.revision[0]));
 
@@ -1003,10 +1002,10 @@ pci_nvme_reset_locked(struct pci_nvme_softc *sc)
 	DPRINTF("%s", __func__);
 
 	sc->regs.cap_lo = (ZERO_BASED(sc->max_qentries) & NVME_CAP_LO_REG_MQES_MASK) |
-	    (1 << NVME_CAP_LO_REG_CQR_SHIFT) |
-	    (60 << NVME_CAP_LO_REG_TO_SHIFT);
+	    NVMEF(NVME_CAP_LO_REG_CQR, 1) |
+	    NVMEF(NVME_CAP_LO_REG_TO, 60);
 
-	sc->regs.cap_hi = 1 << NVME_CAP_HI_REG_CSS_NVM_SHIFT;
+	sc->regs.cap_hi = NVMEF(NVME_CAP_HI_REG_CSS_NVM, 1);
 
 	sc->regs.vs = NVME_REV(1,4);	/* NVMe v1.4 */
 
@@ -2955,8 +2954,8 @@ pci_nvme_write_bar_0(struct pci_nvme_softc *sc, uint64_t offset, int size,
 		if (NVME_CC_GET_SHN(ccreg)) {
 			/* perform shutdown - flush out data to backend */
 			sc->regs.csts &= ~NVMEM(NVME_CSTS_REG_SHST);
-			sc->regs.csts |= NVME_SHST_COMPLETE <<
-			    NVME_CSTS_REG_SHST_SHIFT;
+			sc->regs.csts |= NVMEF(NVME_CSTS_REG_SHST,
+			    NVME_SHST_COMPLETE);
 		}
 		if (NVME_CC_GET_EN(ccreg) != NVME_CC_GET_EN(sc->regs.cc)) {
 			if (NVME_CC_GET_EN(ccreg) == 0)



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