diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h --- a/sys/dev/nvme/nvme.h +++ b/sys/dev/nvme/nvme.h @@ -73,13 +73,13 @@ #define NVME_CAP_LO_REG_TO_SHIFT (24) #define NVME_CAP_LO_REG_TO_MASK (0xFF) #define NVME_CAP_LO_MQES(x) \ - (((x) >> NVME_CAP_LO_REG_MQES_SHIFT) & NVME_CAP_LO_REG_MQES_MASK) + NVMEV(NVME_CAP_LO_REG_MQES, x) #define NVME_CAP_LO_CQR(x) \ - (((x) >> NVME_CAP_LO_REG_CQR_SHIFT) & NVME_CAP_LO_REG_CQR_MASK) + NVMEV(NVME_CAP_LO_REG_CQR, x) #define NVME_CAP_LO_AMS(x) \ - (((x) >> NVME_CAP_LO_REG_AMS_SHIFT) & NVME_CAP_LO_REG_AMS_MASK) + NVMEV(NVME_CAP_LO_REG_AMS, x) #define NVME_CAP_LO_TO(x) \ - (((x) >> NVME_CAP_LO_REG_TO_SHIFT) & NVME_CAP_LO_REG_TO_MASK) + NVMEV(NVME_CAP_LO_REG_TO, x) #define NVME_CAP_HI_REG_DSTRD_SHIFT (0) #define NVME_CAP_HI_REG_DSTRD_MASK (0xF) @@ -108,31 +108,31 @@ #define NVME_CAP_HI_REG_CRIMS_SHIFT (28) #define NVME_CAP_HI_REG_CRIMS_MASK (0x1) #define NVME_CAP_HI_DSTRD(x) \ - (((x) >> NVME_CAP_HI_REG_DSTRD_SHIFT) & NVME_CAP_HI_REG_DSTRD_MASK) + NVMEV(NVME_CAP_HI_REG_DSTRD, x) #define NVME_CAP_HI_NSSRS(x) \ - (((x) >> NVME_CAP_HI_REG_NSSRS_SHIFT) & NVME_CAP_HI_REG_NSSRS_MASK) + NVMEV(NVME_CAP_HI_REG_NSSRS, x) #define NVME_CAP_HI_CSS(x) \ - (((x) >> NVME_CAP_HI_REG_CSS_SHIFT) & NVME_CAP_HI_REG_CSS_MASK) + NVMEV(NVME_CAP_HI_REG_CSS, x) #define NVME_CAP_HI_CSS_NVM(x) \ - (((x) >> NVME_CAP_HI_REG_CSS_NVM_SHIFT) & NVME_CAP_HI_REG_CSS_NVM_MASK) + NVMEV(NVME_CAP_HI_REG_CSS_NVM, x) #define NVME_CAP_HI_BPS(x) \ - (((x) >> NVME_CAP_HI_REG_BPS_SHIFT) & NVME_CAP_HI_REG_BPS_MASK) + NVMEV(NVME_CAP_HI_REG_BPS, x) #define NVME_CAP_HI_CPS(x) \ - (((x) >> NVME_CAP_HI_REG_CPS_SHIFT) & NVME_CAP_HI_REG_CPS_MASK) + NVMEV(NVME_CAP_HI_REG_CPS, x) #define NVME_CAP_HI_MPSMIN(x) \ - (((x) >> NVME_CAP_HI_REG_MPSMIN_SHIFT) & NVME_CAP_HI_REG_MPSMIN_MASK) + NVMEV(NVME_CAP_HI_REG_MPSMIN, x) #define NVME_CAP_HI_MPSMAX(x) \ - (((x) >> NVME_CAP_HI_REG_MPSMAX_SHIFT) & NVME_CAP_HI_REG_MPSMAX_MASK) + NVMEV(NVME_CAP_HI_REG_MPSMAX, x) #define NVME_CAP_HI_PMRS(x) \ - (((x) >> NVME_CAP_HI_REG_PMRS_SHIFT) & NVME_CAP_HI_REG_PMRS_MASK) + NVMEV(NVME_CAP_HI_REG_PMRS, x) #define NVME_CAP_HI_CMBS(x) \ - (((x) >> NVME_CAP_HI_REG_CMBS_SHIFT) & NVME_CAP_HI_REG_CMBS_MASK) + NVMEV(NVME_CAP_HI_REG_CMBS, x) #define NVME_CAP_HI_NSSS(x) \ - (((x) >> NVME_CAP_HI_REG_NSSS_SHIFT) & NVME_CAP_HI_REG_NSSS_MASK) + NVMEV(NVME_CAP_HI_REG_NSSS, x) #define NVME_CAP_HI_CRWMS(x) \ - (((x) >> NVME_CAP_HI_REG_CRWMS_SHIFT) & NVME_CAP_HI_REG_CRWMS_MASK) + NVMEV(NVME_CAP_HI_REG_CRWMS, x) #define NVME_CAP_HI_CRIMS(x) \ - (((x) >> NVME_CAP_HI_REG_CRIMS_SHIFT) & NVME_CAP_HI_REG_CRIMS_MASK) + NVMEV(NVME_CAP_HI_REG_CRIMS, x) #define NVME_CC_REG_EN_SHIFT (0) #define NVME_CC_REG_EN_MASK (0x1) @@ -164,7 +164,8 @@ #define NVME_CSTS_REG_ST_SHIFT (6) #define NVME_CSTS_REG_ST_MASK (0x1) -#define NVME_CSTS_GET_SHST(csts) (((csts) >> NVME_CSTS_REG_SHST_SHIFT) & NVME_CSTS_REG_SHST_MASK) +#define NVME_CSTS_GET_SHST(csts) \ + NVMEV(NVME_CSTS_REG_SHST, csts) #define NVME_AQA_REG_ASQS_SHIFT (0) #define NVME_AQA_REG_ASQS_MASK (0xFFF) @@ -187,19 +188,19 @@ #define NVME_PMRCAP_REG_CMSS_MASK (0x1) #define NVME_PMRCAP_RDS(x) \ - (((x) >> NVME_PMRCAP_REG_RDS_SHIFT) & NVME_PMRCAP_REG_RDS_MASK) + NVMEV(NVME_PMRCAP_REG_RDS, x) #define NVME_PMRCAP_WDS(x) \ - (((x) >> NVME_PMRCAP_REG_WDS_SHIFT) & NVME_PMRCAP_REG_WDS_MASK) + NVMEV(NVME_PMRCAP_REG_WDS, x) #define NVME_PMRCAP_BIR(x) \ - (((x) >> NVME_PMRCAP_REG_BIR_SHIFT) & NVME_PMRCAP_REG_BIR_MASK) + NVMEV(NVME_PMRCAP_REG_BIR, x) #define NVME_PMRCAP_PMRTU(x) \ - (((x) >> NVME_PMRCAP_REG_PMRTU_SHIFT) & NVME_PMRCAP_REG_PMRTU_MASK) + NVMEV(NVME_PMRCAP_REG_PMRTU, x) #define NVME_PMRCAP_PMRWBM(x) \ - (((x) >> NVME_PMRCAP_REG_PMRWBM_SHIFT) & NVME_PMRCAP_REG_PMRWBM_MASK) + NVMEV(NVME_PMRCAP_REG_PMRWBM, x) #define NVME_PMRCAP_PMRTO(x) \ - (((x) >> NVME_PMRCAP_REG_PMRTO_SHIFT) & NVME_PMRCAP_REG_PMRTO_MASK) + NVMEV(NVME_PMRCAP_REG_PMRTO, x) #define NVME_PMRCAP_CMSS(x) \ - (((x) >> NVME_PMRCAP_REG_CMSS_SHIFT) & NVME_PMRCAP_REG_CMSS_MASK) + NVMEV(NVME_PMRCAP_REG_CMSS, x) /* Command field definitions */ @@ -219,12 +220,18 @@ #define NVME_STATUS_DNR_SHIFT (15) #define NVME_STATUS_DNR_MASK (0x1) -#define NVME_STATUS_GET_P(st) (((st) >> NVME_STATUS_P_SHIFT) & NVME_STATUS_P_MASK) -#define NVME_STATUS_GET_SC(st) (((st) >> NVME_STATUS_SC_SHIFT) & NVME_STATUS_SC_MASK) -#define NVME_STATUS_GET_SCT(st) (((st) >> NVME_STATUS_SCT_SHIFT) & NVME_STATUS_SCT_MASK) -#define NVME_STATUS_GET_CRD(st) (((st) >> NVME_STATUS_CRD_SHIFT) & NVME_STATUS_CRD_MASK) -#define NVME_STATUS_GET_M(st) (((st) >> NVME_STATUS_M_SHIFT) & NVME_STATUS_M_MASK) -#define NVME_STATUS_GET_DNR(st) (((st) >> NVME_STATUS_DNR_SHIFT) & NVME_STATUS_DNR_MASK) +#define NVME_STATUS_GET_P(st) \ + NVMEV(NVME_STATUS_P, st) +#define NVME_STATUS_GET_SC(st) \ + NVMEV(NVME_STATUS_SC, st) +#define NVME_STATUS_GET_SCT(st) \ + NVMEV(NVME_STATUS_SCT, st) +#define NVME_STATUS_GET_CRD(st) \ + NVMEV(NVME_STATUS_CRD, st) +#define NVME_STATUS_GET_M(st) \ + NVMEV(NVME_STATUS_M, st) +#define NVME_STATUS_GET_DNR(st) \ + NVMEV(NVME_STATUS_DNR, st) #define NVME_PWR_ST_MPS_SHIFT (0) #define NVME_PWR_ST_MPS_MASK (0x1) @@ -1751,8 +1758,7 @@ nvme_ctrlr_has_dataset_mgmt(const struct nvme_controller_data *cd) { /* Assumes cd was byte swapped by nvme_controller_data_swapbytes() */ - return ((cd->oncs >> NVME_CTRLR_DATA_ONCS_DSM_SHIFT) & - NVME_CTRLR_DATA_ONCS_DSM_MASK); + return (NVMEV(NVME_CTRLR_DATA_ONCS_DSM, cd->oncs) != 0); } /* Namespace helper functions */ diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -247,8 +247,7 @@ csts = nvme_mmio_read_4(ctrlr, csts); if (csts == NVME_GONE) /* Hot unplug. */ return (ENXIO); - if (((csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK) - == desired_val) + if (NVMEV(NVME_CSTS_REG_RDY, csts) == desired_val) break; if (timeout - ticks < 0) { nvme_printf(ctrlr, "controller ready did not become %d " @@ -274,8 +273,8 @@ cc = nvme_mmio_read_4(ctrlr, cc); csts = nvme_mmio_read_4(ctrlr, csts); - en = (cc >> NVME_CC_REG_EN_SHIFT) & NVME_CC_REG_EN_MASK; - rdy = (csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK; + en = NVMEV(NVME_CC_REG_EN, cc); + rdy = NVMEV(NVME_CSTS_REG_RDY, csts); /* * Per 3.1.5 in NVME 1.3 spec, transitioning CC.EN from 0 to 1 @@ -321,8 +320,8 @@ cc = nvme_mmio_read_4(ctrlr, cc); csts = nvme_mmio_read_4(ctrlr, csts); - en = (cc >> NVME_CC_REG_EN_SHIFT) & NVME_CC_REG_EN_MASK; - rdy = (csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK; + en = NVMEV(NVME_CC_REG_EN, cc); + rdy = NVMEV(NVME_CSTS_REG_RDY, csts); /* * See note in nvme_ctrlr_disable. Short circuit if we're already enabled. diff --git a/sys/dev/nvme/nvme_ns.c b/sys/dev/nvme/nvme_ns.c --- a/sys/dev/nvme/nvme_ns.c +++ b/sys/dev/nvme/nvme_ns.c @@ -180,10 +180,8 @@ { uint8_t flbas_fmt, lbads; - flbas_fmt = (ns->data.flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) & - NVME_NS_DATA_FLBAS_FORMAT_MASK; - lbads = (ns->data.lbaf[flbas_fmt] >> NVME_NS_DATA_LBAF_LBADS_SHIFT) & - NVME_NS_DATA_LBAF_LBADS_MASK; + flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, ns->data.flbas); + lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, ns->data.lbaf[flbas_fmt]); return (1 << lbads); } @@ -230,8 +228,7 @@ { uint32_t ss; - if (((ns->data.nsfeat >> NVME_NS_DATA_NSFEAT_NPVALID_SHIFT) & - NVME_NS_DATA_NSFEAT_NPVALID_MASK) != 0) { + if (NVMEV(NVME_NS_DATA_NSFEAT_NPVALID, ns->data.nsfeat) != 0) { ss = nvme_ns_get_sector_size(ns); if (ns->data.npwa != 0) return ((ns->data.npwa + 1) * ss); @@ -551,8 +548,8 @@ if (ns->data.nsze == 0) return (ENXIO); - flbas_fmt = (ns->data.flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) & - NVME_NS_DATA_FLBAS_FORMAT_MASK; + flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, ns->data.flbas); + /* * Note: format is a 0-based value, so > is appropriate here, * not >=. @@ -584,8 +581,7 @@ if (nvme_ctrlr_has_dataset_mgmt(&ctrlr->cdata)) ns->flags |= NVME_NS_DEALLOCATE_SUPPORTED; - vwc_present = (ctrlr->cdata.vwc >> NVME_CTRLR_DATA_VWC_PRESENT_SHIFT) & - NVME_CTRLR_DATA_VWC_PRESENT_MASK; + vwc_present = NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, ctrlr->cdata.vwc); if (vwc_present) ns->flags |= NVME_NS_FLUSH_SUPPORTED; diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c --- a/sys/dev/nvme/nvme_qpair.c +++ b/sys/dev/nvme/nvme_qpair.c @@ -1068,7 +1068,7 @@ * usually doesn't). */ csts = nvme_mmio_read_4(ctrlr, csts); - cfs = (csts >> NVME_CSTS_REG_CFS_SHIFT) & NVME_CSTS_REG_CFS_MASK; + cfs = NVMEV(NVME_CSTS_REG_CFS, csts); if (csts == NVME_GONE || cfs == 1) goto do_reset;