nvme_fabrics: move ctrlr_scan to common code.

This function is identical between the two transports.

Change-Id: If50b781259f224eb2c21de7da14564e6ce487650
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471778
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Seth Howell 2019-10-18 16:54:06 -07:00 committed by Jim Harris
parent 08d4d977e8
commit 6035f73d7b
4 changed files with 69 additions and 121 deletions

View File

@ -219,6 +219,72 @@ nvme_fabric_get_discovery_log_page(struct spdk_nvme_ctrlr *ctrlr,
return 0;
}
int
nvme_fabric_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
bool direct_connect)
{
struct spdk_nvme_ctrlr_opts discovery_opts;
struct spdk_nvme_ctrlr *discovery_ctrlr;
union spdk_nvme_cc_register cc;
int rc;
struct nvme_completion_poll_status status;
if (strcmp(probe_ctx->trid.subnqn, SPDK_NVMF_DISCOVERY_NQN) != 0) {
/* It is not a discovery_ctrlr info and try to directly connect it */
rc = nvme_ctrlr_probe(&probe_ctx->trid, probe_ctx, NULL);
return rc;
}
spdk_nvme_ctrlr_get_default_ctrlr_opts(&discovery_opts, sizeof(discovery_opts));
/* For discovery_ctrlr set the timeout to 0 */
discovery_opts.keep_alive_timeout_ms = 0;
discovery_ctrlr = nvme_transport_ctrlr_construct(&probe_ctx->trid, &discovery_opts, NULL);
if (discovery_ctrlr == NULL) {
return -1;
}
/* TODO: this should be using the normal NVMe controller initialization process +1 */
cc.raw = 0;
cc.bits.en = 1;
cc.bits.iosqes = 6; /* SQ entry size == 64 == 2^6 */
cc.bits.iocqes = 4; /* CQ entry size == 16 == 2^4 */
rc = nvme_transport_ctrlr_set_reg_4(discovery_ctrlr, offsetof(struct spdk_nvme_registers, cc.raw),
cc.raw);
if (rc < 0) {
SPDK_ERRLOG("Failed to set cc\n");
nvme_ctrlr_destruct(discovery_ctrlr);
return -1;
}
/* get the cdata info */
rc = nvme_ctrlr_cmd_identify(discovery_ctrlr, SPDK_NVME_IDENTIFY_CTRLR, 0, 0,
&discovery_ctrlr->cdata, sizeof(discovery_ctrlr->cdata),
nvme_completion_poll_cb, &status);
if (rc != 0) {
SPDK_ERRLOG("Failed to identify cdata\n");
return rc;
}
if (spdk_nvme_wait_for_completion(discovery_ctrlr->adminq, &status)) {
SPDK_ERRLOG("nvme_identify_controller failed!\n");
return -ENXIO;
}
/* Direct attach through spdk_nvme_connect() API */
if (direct_connect == true) {
/* Set the ready state to skip the normal init process */
discovery_ctrlr->state = NVME_CTRLR_STATE_READY;
nvme_ctrlr_connected(probe_ctx, discovery_ctrlr);
nvme_ctrlr_add_process(discovery_ctrlr, 0);
return 0;
}
rc = nvme_fabric_ctrlr_discover(discovery_ctrlr, probe_ctx);
nvme_ctrlr_destruct(discovery_ctrlr);
return rc;
}
int
nvme_fabric_ctrlr_discover(struct spdk_nvme_ctrlr *ctrlr,
struct spdk_nvme_probe_ctx *probe_ctx)

View File

@ -867,6 +867,7 @@ void nvme_ns_destruct(struct spdk_nvme_ns *ns);
int nvme_fabric_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
int nvme_fabric_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
int nvme_fabric_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value);
int nvme_fabric_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx, bool direct_connect);
int nvme_fabric_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value);
int nvme_fabric_ctrlr_discover(struct spdk_nvme_ctrlr *ctrlr,
struct spdk_nvme_probe_ctx *probe_ctx);

View File

@ -1517,66 +1517,7 @@ int
nvme_rdma_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
bool direct_connect)
{
struct spdk_nvme_ctrlr_opts discovery_opts;
struct spdk_nvme_ctrlr *discovery_ctrlr;
union spdk_nvme_cc_register cc;
int rc;
struct nvme_completion_poll_status status;
if (strcmp(probe_ctx->trid.subnqn, SPDK_NVMF_DISCOVERY_NQN) != 0) {
/* It is not a discovery_ctrlr info and try to directly connect it */
rc = nvme_ctrlr_probe(&probe_ctx->trid, probe_ctx, NULL);
return rc;
}
spdk_nvme_ctrlr_get_default_ctrlr_opts(&discovery_opts, sizeof(discovery_opts));
/* For discovery_ctrlr set the timeout to 0 */
discovery_opts.keep_alive_timeout_ms = 0;
discovery_ctrlr = nvme_rdma_ctrlr_construct(&probe_ctx->trid, &discovery_opts, NULL);
if (discovery_ctrlr == NULL) {
return -1;
}
/* TODO: this should be using the normal NVMe controller initialization process */
cc.raw = 0;
cc.bits.en = 1;
cc.bits.iosqes = 6; /* SQ entry size == 64 == 2^6 */
cc.bits.iocqes = 4; /* CQ entry size == 16 == 2^4 */
rc = nvme_transport_ctrlr_set_reg_4(discovery_ctrlr, offsetof(struct spdk_nvme_registers, cc.raw),
cc.raw);
if (rc < 0) {
SPDK_ERRLOG("Failed to set cc\n");
nvme_ctrlr_destruct(discovery_ctrlr);
return -1;
}
/* get the cdata info */
rc = nvme_ctrlr_cmd_identify(discovery_ctrlr, SPDK_NVME_IDENTIFY_CTRLR, 0, 0,
&discovery_ctrlr->cdata, sizeof(discovery_ctrlr->cdata),
nvme_completion_poll_cb, &status);
if (rc != 0) {
SPDK_ERRLOG("Failed to identify cdata\n");
return rc;
}
if (spdk_nvme_wait_for_completion(discovery_ctrlr->adminq, &status)) {
SPDK_ERRLOG("nvme_identify_controller failed!\n");
return -ENXIO;
}
/* Direct attach through spdk_nvme_connect() API */
if (direct_connect == true) {
/* Set the ready state to skip the normal init process */
discovery_ctrlr->state = NVME_CTRLR_STATE_READY;
nvme_ctrlr_connected(probe_ctx, discovery_ctrlr);
nvme_ctrlr_add_process(discovery_ctrlr, 0);
return 0;
}
rc = nvme_fabric_ctrlr_discover(discovery_ctrlr, probe_ctx);
nvme_ctrlr_destruct(discovery_ctrlr);
return rc;
return nvme_fabric_ctrlr_scan(probe_ctx, direct_connect);
}
struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_transport_id *trid,

View File

@ -277,67 +277,7 @@ int
nvme_tcp_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
bool direct_connect)
{
struct spdk_nvme_ctrlr_opts discovery_opts;
struct spdk_nvme_ctrlr *discovery_ctrlr;
union spdk_nvme_cc_register cc;
int rc;
struct nvme_completion_poll_status status;
if (strcmp(probe_ctx->trid.subnqn, SPDK_NVMF_DISCOVERY_NQN) != 0) {
/* Not a discovery controller - connect directly. */
rc = nvme_ctrlr_probe(&probe_ctx->trid, probe_ctx, NULL);
return rc;
}
spdk_nvme_ctrlr_get_default_ctrlr_opts(&discovery_opts, sizeof(discovery_opts));
/* For discovery_ctrlr set the timeout to 0 */
discovery_opts.keep_alive_timeout_ms = 0;
discovery_ctrlr = nvme_tcp_ctrlr_construct(&probe_ctx->trid, &discovery_opts, NULL);
if (discovery_ctrlr == NULL) {
return -1;
}
/* TODO: this should be using the normal NVMe controller initialization process */
cc.raw = 0;
cc.bits.en = 1;
cc.bits.iosqes = 6; /* SQ entry size == 64 == 2^6 */
cc.bits.iocqes = 4; /* CQ entry size == 16 == 2^4 */
rc = nvme_transport_ctrlr_set_reg_4(discovery_ctrlr, offsetof(struct spdk_nvme_registers, cc.raw),
cc.raw);
if (rc < 0) {
SPDK_ERRLOG("Failed to set cc\n");
nvme_ctrlr_destruct(discovery_ctrlr);
return -1;
}
/* get the cdata info */
status.done = false;
rc = nvme_ctrlr_cmd_identify(discovery_ctrlr, SPDK_NVME_IDENTIFY_CTRLR, 0, 0,
&discovery_ctrlr->cdata, sizeof(discovery_ctrlr->cdata),
nvme_completion_poll_cb, &status);
if (rc != 0) {
SPDK_ERRLOG("Failed to identify cdata\n");
return rc;
}
if (spdk_nvme_wait_for_completion(discovery_ctrlr->adminq, &status)) {
SPDK_ERRLOG("nvme_identify_controller failed!\n");
return -ENXIO;
}
/* Direct attach through spdk_nvme_connect() API */
if (direct_connect == true) {
/* Set the ready state to skip the normal init process */
discovery_ctrlr->state = NVME_CTRLR_STATE_READY;
nvme_ctrlr_connected(probe_ctx, discovery_ctrlr);
nvme_ctrlr_add_process(discovery_ctrlr, 0);
return 0;
}
rc = nvme_fabric_ctrlr_discover(discovery_ctrlr, probe_ctx);
nvme_ctrlr_destruct(discovery_ctrlr);
return rc;
return nvme_fabric_ctrlr_scan(probe_ctx, direct_connect);
}
int