nvme: add NVME_CTRLR_STATE_READ_CAP

Read CAP (Capabilities) register as part of controller
initialization instead of controller construction.

For now, still read CAP in the pcie and vfio-user
controller construction, since they need the
drstd (doorbell stride) to construct the admin
queue.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I000fe880f2ec0d6de1d565c883d7ea0ae1ac2c81
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8078
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Jim Harris 2021-05-26 22:58:18 +00:00 committed by Tomasz Zawadzki
parent df01076f70
commit f5ba8a5ef5
7 changed files with 16 additions and 27 deletions

View File

@ -48,6 +48,7 @@ static void nvme_ctrlr_identify_active_ns_async(struct nvme_active_ns_ctx *ctx);
static int nvme_ctrlr_identify_ns_async(struct spdk_nvme_ns *ns);
static int nvme_ctrlr_identify_ns_iocs_specific_async(struct spdk_nvme_ns *ns);
static int nvme_ctrlr_identify_id_desc_async(struct spdk_nvme_ns *ns);
static void nvme_ctrlr_init_cap(struct spdk_nvme_ctrlr *ctrlr);
#define CTRLR_STRING(ctrlr) \
((ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_TCP || ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_RDMA) ? \
@ -1136,6 +1137,8 @@ nvme_ctrlr_state_string(enum nvme_ctrlr_state state)
return "delay init";
case NVME_CTRLR_STATE_READ_VS:
return "read vs";
case NVME_CTRLR_STATE_READ_CAP:
return "read cap";
case NVME_CTRLR_STATE_CHECK_EN:
return "check en";
case NVME_CTRLR_STATE_DISABLE_WAIT_FOR_READY_1:
@ -3128,6 +3131,11 @@ nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr)
case NVME_CTRLR_STATE_READ_VS: /* synonymous with NVME_CTRLR_STATE_INIT */
nvme_ctrlr_get_vs(ctrlr, &ctrlr->vs);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_READ_CAP, NVME_TIMEOUT_INFINITE);
break;
case NVME_CTRLR_STATE_READ_CAP:
nvme_ctrlr_init_cap(ctrlr);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_CHECK_EN, NVME_TIMEOUT_INFINITE);
break;
@ -3410,11 +3418,10 @@ nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr)
return rc;
}
/* This function should be called once at ctrlr initialization to set up constant properties. */
void
nvme_ctrlr_init_cap(struct spdk_nvme_ctrlr *ctrlr, const union spdk_nvme_cap_register *cap)
static void
nvme_ctrlr_init_cap(struct spdk_nvme_ctrlr *ctrlr)
{
ctrlr->cap = *cap;
nvme_ctrlr_get_cap(ctrlr, &ctrlr->cap);
if (ctrlr->cap.bits.ams & SPDK_NVME_CAP_AMS_WRR) {
ctrlr->flags |= SPDK_NVME_CTRLR_WRR_SUPPORTED;

View File

@ -527,6 +527,11 @@ enum nvme_ctrlr_state {
*/
NVME_CTRLR_STATE_INIT = NVME_CTRLR_STATE_READ_VS,
/**
* Read Capabilities (CAP) register.
*/
NVME_CTRLR_STATE_READ_CAP,
/**
* Check EN to prepare for controller initialization.
*/
@ -1042,7 +1047,6 @@ int nvme_ctrlr_get_vs(struct spdk_nvme_ctrlr *ctrlr, union spdk_nvme_vs_register
int nvme_ctrlr_get_cmbsz(struct spdk_nvme_ctrlr *ctrlr, union spdk_nvme_cmbsz_register *cmbsz);
int nvme_ctrlr_get_pmrcap(struct spdk_nvme_ctrlr *ctrlr, union spdk_nvme_pmrcap_register *pmrcap);
bool nvme_ctrlr_multi_iocs_enabled(struct spdk_nvme_ctrlr *ctrlr);
void nvme_ctrlr_init_cap(struct spdk_nvme_ctrlr *ctrlr, const union spdk_nvme_cap_register *cap);
void nvme_ctrlr_process_async_event(struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_cpl *cpl);
void nvme_ctrlr_disconnect_qpair(struct spdk_nvme_qpair *qpair);

View File

@ -959,8 +959,6 @@ static struct spdk_nvme_ctrlr *nvme_pcie_ctrlr_construct(const struct spdk_nvme_
return NULL;
}
nvme_ctrlr_init_cap(&pctrlr->ctrlr, &cap);
/* Doorbell stride is 2 ^ (dstrd + 2),
* but we want multiples of 4, so drop the + 2 */
pctrlr->doorbell_stride_u32 = 1 << cap.bits.dstrd;

View File

@ -1738,7 +1738,6 @@ static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_
void *devhandle)
{
struct nvme_rdma_ctrlr *rctrlr;
union spdk_nvme_cap_register cap;
struct ibv_context **contexts;
struct ibv_device_attr dev_attr;
int i, flag, rc;
@ -1832,18 +1831,11 @@ static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_
goto destruct_ctrlr;
}
if (nvme_ctrlr_get_cap(&rctrlr->ctrlr, &cap)) {
SPDK_ERRLOG("get_cap() failed\n");
goto destruct_ctrlr;
}
if (nvme_ctrlr_add_process(&rctrlr->ctrlr, 0) != 0) {
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
goto destruct_ctrlr;
}
nvme_ctrlr_init_cap(&rctrlr->ctrlr, &cap);
SPDK_DEBUGLOG(nvme, "successfully initialized the nvmf ctrlr\n");
return &rctrlr->ctrlr;

View File

@ -1934,7 +1934,6 @@ static struct spdk_nvme_ctrlr *nvme_tcp_ctrlr_construct(const struct spdk_nvme_t
void *devhandle)
{
struct nvme_tcp_ctrlr *tctrlr;
union spdk_nvme_cap_register cap;
int rc;
tctrlr = calloc(1, sizeof(*tctrlr));
@ -1968,20 +1967,12 @@ static struct spdk_nvme_ctrlr *nvme_tcp_ctrlr_construct(const struct spdk_nvme_t
return NULL;
}
if (nvme_ctrlr_get_cap(&tctrlr->ctrlr, &cap)) {
SPDK_ERRLOG("get_cap() failed\n");
nvme_ctrlr_destruct(&tctrlr->ctrlr);
return NULL;
}
if (nvme_ctrlr_add_process(&tctrlr->ctrlr, 0) != 0) {
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
nvme_ctrlr_destruct(&tctrlr->ctrlr);
return NULL;
}
nvme_ctrlr_init_cap(&tctrlr->ctrlr, &cap);
return &tctrlr->ctrlr;
}

View File

@ -271,7 +271,6 @@ static struct spdk_nvme_ctrlr *
goto exit;
}
nvme_ctrlr_init_cap(&pctrlr->ctrlr, &cap);
/* Doorbell stride is 2 ^ (dstrd + 2),
* but we want multiples of 4, so drop the + 2 */
pctrlr->doorbell_stride_u32 = 1 << cap.bits.dstrd;

View File

@ -73,8 +73,6 @@ DEFINE_STUB(nvme_request_check_timeout, int, (struct nvme_request *req, uint16_t
DEFINE_STUB_V(nvme_ctrlr_destruct_finish, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB(nvme_ctrlr_construct, int, (struct spdk_nvme_ctrlr *ctrlr), 0);
DEFINE_STUB_V(nvme_ctrlr_destruct, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB_V(nvme_ctrlr_init_cap, (struct spdk_nvme_ctrlr *ctrlr,
const union spdk_nvme_cap_register *cap));
DEFINE_STUB(nvme_ctrlr_get_vs, int, (struct spdk_nvme_ctrlr *ctrlr,
union spdk_nvme_vs_register *vs), 0);
DEFINE_STUB(nvme_ctrlr_get_cap, int, (struct spdk_nvme_ctrlr *ctrlr,