lib/nvme: add function spdk_nvme_bytes_to_numd to calculate number of dwords

According to kernel, use an inline function spdk_nvme_bytes_to_numd
to transfer paload_size form bytes to numer of dwords.

Signed-off-by: sunshihao <sunshihao@huawei.com>
Change-Id: I8b9ded122bbf4a3c8e46988993ea52404783c0b0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5926
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
sunshihao520 2021-01-15 15:45:39 +08:00 committed by Tomasz Zawadzki
parent 9317f72d09
commit 1572882a7f
7 changed files with 18 additions and 11 deletions

View File

@ -38,7 +38,8 @@ parameter in `spdk_blob_open_opts_init` function.
Added a new function `spdk_nvme_ctrlr_reset_subsystem` to perform a NVMe
subsystem reset. Note: The NVMf target does not support the subsystem reset yet.
Add a new function 'spdk_nvme_bytes_to_numd' to transfer bytes to number of
dwords.
### event
The pci_whitelist and pci_blacklist members of struct spdk_app_opts have been

View File

@ -1398,6 +1398,12 @@ static inline enum spdk_nvme_data_transfer spdk_nvme_opc_get_data_transfer(uint8
return (enum spdk_nvme_data_transfer)(opc & 3);
}
static inline uint32_t
spdk_nvme_bytes_to_numd(uint32_t len)
{
return (len >> 2) - 1;
}
enum spdk_nvme_feat {
/* 0x00 - reserved */

View File

@ -516,7 +516,7 @@ spdk_nvme_ctrlr_cmd_get_log_page_ext(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_
return -EINVAL;
}
numd = payload_size / sizeof(uint32_t) - 1u;
numd = spdk_nvme_bytes_to_numd(payload_size);
numdl = numd & 0xFFFFu;
numdu = (numd >> 16) & 0xFFFFu;
@ -867,7 +867,7 @@ nvme_ctrlr_cmd_fw_image_download(struct spdk_nvme_ctrlr *ctrlr,
cmd = &req->cmd;
cmd->opc = SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD;
cmd->cdw10 = (size >> 2) - 1;
cmd->cdw10 = spdk_nvme_bytes_to_numd(size);
cmd->cdw11 = offset >> 2;
rc = nvme_ctrlr_submit_admin_request(ctrlr, req);

View File

@ -85,7 +85,7 @@ nvme_zns_zone_mgmt_recv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
cmd->nsid = ns->id;
*(uint64_t *)&cmd->cdw10 = slba;
cmd->cdw12 = payload_size / sizeof(uint32_t) - 1u;
cmd->cdw12 = spdk_nvme_bytes_to_numd(payload_size);
cmd->cdw13 = zone_recv_action | zra_spec_field << 8 | zra_spec_feats << 16;
return nvme_qpair_submit_request(qpair, req);

View File

@ -753,7 +753,7 @@ apply_firmware_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg
firm_ctx->transfer = spdk_min(firm_ctx->size_remaining, 4096);
cmd.opc = SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD;
cmd.cdw10 = (firm_ctx->transfer >> 2) - 1;
cmd.cdw10 = spdk_nvme_bytes_to_numd(firm_ctx->transfer);
cmd.cdw11 = firm_ctx->offset >> 2;
rc = spdk_bdev_nvme_admin_passthru(firm_ctx->desc, firm_ctx->ch, &cmd, firm_ctx->p,
firm_ctx->transfer, apply_firmware_complete, firm_ctx);
@ -913,7 +913,7 @@ rpc_bdev_nvme_apply_firmware(struct spdk_jsonrpc_request *request,
memset(cmd, 0, sizeof(struct spdk_nvme_cmd));
cmd->opc = SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD;
cmd->cdw10 = (firm_ctx->transfer >> 2) - 1;
cmd->cdw10 = spdk_nvme_bytes_to_numd(firm_ctx->transfer);
cmd->cdw11 = firm_ctx->offset >> 2;
rc = spdk_bdev_nvme_admin_passthru(firm_ctx->desc, firm_ctx->ch, cmd, firm_ctx->p,

View File

@ -313,7 +313,7 @@ static void verify_fw_commit(struct nvme_request *req)
static void verify_fw_image_download(struct nvme_request *req)
{
CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD);
CU_ASSERT(req->cmd.cdw10 == (fw_img_size >> 2) - 1);
CU_ASSERT(req->cmd.cdw10 == spdk_nvme_bytes_to_numd(fw_img_size));
CU_ASSERT(req->cmd.cdw11 == fw_img_offset >> 2);
}

View File

@ -277,7 +277,7 @@ test_get_log_page(void)
memset(&rsp, 0, sizeof(rsp));
cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE;
cmd.nvme_cmd.cdw10_bits.get_log_page.lid = SPDK_NVME_LOG_ERROR;
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = (req.length / 4 - 1);
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = spdk_nvme_bytes_to_numd(req.length);
CU_ASSERT(nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_SUCCESS);
@ -296,7 +296,7 @@ test_get_log_page(void)
memset(&rsp, 0, sizeof(rsp));
cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE;
cmd.nvme_cmd.cdw10_bits.get_log_page.lid = SPDK_NVME_LOG_ERROR;
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = (req.length / 4 - 1);
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = spdk_nvme_bytes_to_numd(req.length);
cmd.nvme_cmd.cdw12 = 2;
CU_ASSERT(nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
@ -308,7 +308,7 @@ test_get_log_page(void)
req.data = NULL;
cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE;
cmd.nvme_cmd.cdw10_bits.get_log_page.lid = SPDK_NVME_LOG_ERROR;
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = (req.length / 4 - 1);
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = spdk_nvme_bytes_to_numd(req.length);
CU_ASSERT(nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_FIELD);
@ -1946,7 +1946,7 @@ test_rae(void)
cmd[i].nvme_cmd.cdw10_bits.get_log_page.lid =
SPDK_NVME_LOG_CHANGED_NS_LIST;
cmd[i].nvme_cmd.cdw10_bits.get_log_page.numdl =
(req[i].length / 4 - 1);
spdk_nvme_bytes_to_numd(req[i].length);
cmd[i].nvme_cmd.cid = i;
}
cmd[1].nvme_cmd.cdw10_bits.get_log_page.rae = 1;