[PATCH 02/13] nvme: move OPAL setup from PCIe to core
Sagi Grimberg
sagi at grimberg.me
Mon Nov 21 02:28:31 PST 2022
On 11/13/22 18:11, Christoph Hellwig wrote:
> Nothing about the TCG Opal support is PCIe transport specific, so move it
> to the core code. For this nvme_init_ctrl_finish grows a new
> was_suspended argument that allows the transport driver to tell the OPAL
> code if the controller came out of a suspend cycle.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> Reviewed-by: Keith Busch <kbusch at kernel.org>
> Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
> Tested-by Gerd Bayer <gbayer at linxu.ibm.com>
> ---
> drivers/nvme/host/apple.c | 2 +-
> drivers/nvme/host/core.c | 25 ++++++++++++++++++++++---
> drivers/nvme/host/fc.c | 2 +-
> drivers/nvme/host/nvme.h | 5 +----
> drivers/nvme/host/pci.c | 14 +-------------
> drivers/nvme/host/rdma.c | 2 +-
> drivers/nvme/host/tcp.c | 2 +-
> drivers/nvme/target/loop.c | 2 +-
> 8 files changed, 29 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
> index 24e224c279a41..a85349a7e938c 100644
> --- a/drivers/nvme/host/apple.c
> +++ b/drivers/nvme/host/apple.c
> @@ -1102,7 +1102,7 @@ static void apple_nvme_reset_work(struct work_struct *work)
> goto out;
> }
>
> - ret = nvme_init_ctrl_finish(&anv->ctrl);
> + ret = nvme_init_ctrl_finish(&anv->ctrl, false);
> if (ret)
> goto out;
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index ce8314aee1ddf..aedacf2fba69e 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2192,7 +2192,7 @@ const struct pr_ops nvme_pr_ops = {
> };
>
> #ifdef CONFIG_BLK_SED_OPAL
> -int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
> +static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
> bool send)
> {
> struct nvme_ctrl *ctrl = data;
> @@ -2209,7 +2209,23 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
> return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len,
> NVME_QID_ANY, 1, 0);
> }
> -EXPORT_SYMBOL_GPL(nvme_sec_submit);
> +
> +static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)
> +{
> + if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) {
> + if (!ctrl->opal_dev)
> + ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit);
> + else if (was_suspended)
> + opal_unlock_from_suspend(ctrl->opal_dev);
> + } else {
> + free_opal_dev(ctrl->opal_dev);
> + ctrl->opal_dev = NULL;
> + }
> +}
> +#else
> +static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)
> +{
> +}
> #endif /* CONFIG_BLK_SED_OPAL */
>
> #ifdef CONFIG_BLK_DEV_ZONED
> @@ -3242,7 +3258,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
> * register in our nvme_ctrl structure. This should be called as soon as
> * the admin queue is fully up and running.
> */
> -int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
> +int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended)
> {
> int ret;
>
> @@ -3273,6 +3289,8 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
> if (ret < 0)
> return ret;
>
> + nvme_configure_opal(ctrl, was_suspended);
> +
> if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) {
> /*
> * Do not return errors unless we are in a controller reset,
> @@ -5007,6 +5025,7 @@ static void nvme_free_ctrl(struct device *dev)
> nvme_auth_stop(ctrl);
> nvme_auth_free(ctrl);
> __free_page(ctrl->discard_page);
> + free_opal_dev(ctrl->opal_dev);
>
> if (subsys) {
> mutex_lock(&nvme_subsystems_lock);
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 2d3c54838496f..1f9f4075794b5 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -3107,7 +3107,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
>
> nvme_start_admin_queue(&ctrl->ctrl);
>
> - ret = nvme_init_ctrl_finish(&ctrl->ctrl);
> + ret = nvme_init_ctrl_finish(&ctrl->ctrl, false);
Completely imaginary question,
Since you correctly indicated that opal is not pcie specific, why is
this passed as always false?
Wandering if a opal fabrics device comes along and becomes
incompatible with this...
Although fabrics call nvme_shutdown_ctrl only when deleting the
controller, so there is no opal_dev in any case... There is no real
suspend in fabrics at all really. So I guess it makes sense.
It's just a bit confusing to think about in the fabrics context.
More information about the Linux-nvme
mailing list