diff --git a/CHANGELOG.md b/CHANGELOG.md index 047cffe631..ca1561a3e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ multiple separate buffers. ### nvme +Wrapper functions spdk_nvme_ctrlr_security_send() and spdk_nvme_ctrlr_security_receive() are +introduced to support further security protocol development. + admin_timeout_ms was added to NVMe controller initialization options, users can change the default value when probing a controller. diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 0252cfb5ec..6b184cebf9 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -1206,16 +1206,14 @@ int spdk_nvme_ctrlr_cmd_set_feature_ns(struct spdk_nvme_ctrlr *ctrlr, uint8_t fe * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security * Protocol EAh. * \param payload The pointer to the payload buffer. - * \param payload_size The size of payload buffer. - * \param cb_fn Callback function to invoke when the security receive has completed. - * \param cb_arg Argument to pass to the callback function. + * \param size The size of payload buffer. * * \return 0 if successfully submitted, negated errno if resources could not be allocated * for this request. */ -int spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, uint16_t spsp, - uint8_t nssf, void *payload, uint32_t payload_size, - spdk_nvme_cmd_cb cb_fn, void *cb_arg); +int +spdk_nvme_ctrlr_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, size_t size); /** * Send security protocol data to controller. @@ -1231,16 +1229,14 @@ int spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security * Protocol EAh. * \param payload The pointer to the payload buffer. - * \param payload_size The size of payload buffer. - * \param cb_fn Callback function to invoke when the security send has completed. - * \param cb_arg Argument to pass to the callback function. + * \param size The size of payload buffer. * * \return 0 if successfully submitted, negated errno if resources could not be allocated * for this request. */ -int spdk_nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, uint16_t spsp, - uint8_t nssf, void *payload, uint32_t payload_size, - spdk_nvme_cmd_cb cb_fn, void *cb_arg); +int +spdk_nvme_ctrlr_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, size_t size); /** * Attach the specified namespace to controllers. diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 2632176552..9b34c78628 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -2742,3 +2742,43 @@ spdk_nvme_ctrlr_is_discovery(struct spdk_nvme_ctrlr *ctrlr) return !strncmp(ctrlr->trid.subnqn, SPDK_NVMF_DISCOVERY_NQN, strlen(SPDK_NVMF_DISCOVERY_NQN)); } + +int +spdk_nvme_ctrlr_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, size_t size) +{ + struct nvme_completion_poll_status status; + int res; + + res = nvme_ctrlr_cmd_security_receive(ctrlr, secp, spsp, nssf, payload, size, + nvme_completion_poll_cb, &status); + if (res) { + return res; + } + if (spdk_nvme_wait_for_completion_robust_lock(ctrlr->adminq, &status, &ctrlr->ctrlr_lock)) { + SPDK_ERRLOG("spdk_nvme_ctrlr_security_receive failed!\n"); + return -ENXIO; + } + + return 0; +} + +int +spdk_nvme_ctrlr_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, size_t size) +{ + struct nvme_completion_poll_status status; + int res; + + res = nvme_ctrlr_cmd_security_send(ctrlr, secp, spsp, nssf, payload, size, nvme_completion_poll_cb, + &status); + if (res) { + return res; + } + if (spdk_nvme_wait_for_completion_robust_lock(ctrlr->adminq, &status, &ctrlr->ctrlr_lock)) { + SPDK_ERRLOG("spdk_nvme_ctrlr_security_send failed!\n"); + return -ENXIO; + } + + return 0; +} diff --git a/lib/nvme/nvme_ctrlr_cmd.c b/lib/nvme/nvme_ctrlr_cmd.c index 750a2d7883..fa13cff557 100644 --- a/lib/nvme/nvme_ctrlr_cmd.c +++ b/lib/nvme/nvme_ctrlr_cmd.c @@ -638,9 +638,9 @@ nvme_ctrlr_cmd_fw_image_download(struct spdk_nvme_ctrlr *ctrlr, } int -spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, - uint16_t spsp, uint8_t nssf, void *payload, - uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) +nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, + uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) { struct nvme_request *req; struct spdk_nvme_cmd *cmd; @@ -666,9 +666,9 @@ spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp } int -spdk_nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, - uint16_t spsp, uint8_t nssf, void *payload, - uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) +nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, + uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) { struct nvme_request *req; struct spdk_nvme_cmd *cmd; diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index 5804fdac8a..d4c76a2252 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -777,6 +777,12 @@ int nvme_ctrlr_cmd_fw_commit(struct spdk_nvme_ctrlr *ctrlr, int nvme_ctrlr_cmd_fw_image_download(struct spdk_nvme_ctrlr *ctrlr, uint32_t size, uint32_t offset, void *payload, spdk_nvme_cmd_cb cb_fn, void *cb_arg); +int nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, uint16_t spsp, + uint8_t nssf, void *payload, uint32_t payload_size, + spdk_nvme_cmd_cb cb_fn, void *cb_arg); +int nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, + uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg); void nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl); int spdk_nvme_wait_for_completion(struct spdk_nvme_qpair *qpair, struct nvme_completion_poll_status *status); diff --git a/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c b/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c index a5afa7bc0e..008189c8f1 100644 --- a/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c +++ b/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c @@ -409,6 +409,23 @@ nvme_ctrlr_cmd_fw_image_download(struct spdk_nvme_ctrlr *ctrlr, return 0; } +int +nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, uint16_t spsp, + uint8_t nssf, void *payload, uint32_t payload_size, + spdk_nvme_cmd_cb cb_fn, void *cb_arg) +{ + return 0; +} + +int +nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, + uint16_t spsp, uint8_t nssf, void *payload, + uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) +{ + return 0; +} + + void nvme_ns_destruct(struct spdk_nvme_ns *ns) {