[PATCH 4/5] nvme: Add a new exported function nvme_request_shutdown().

Sagi Grimberg sagi at grimberg.me
Tue Jan 30 02:58:31 PST 2024


> Sets the shutdown bit but doesn't wait for ready.
> Use from nvme_disable_ctrl(). Export nvme_wait_ready()
> so we can call it from drivers/nvme/host/pci.c.
> 
> Signed-off-by: Jeremy Allison <jallison at ciq.com>
> ---
>   drivers/nvme/host/core.c | 22 ++++++++++++++++------
>   drivers/nvme/host/nvme.h |  3 +++
>   2 files changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index a42c347d08e8..13635ef88569 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2215,7 +2215,7 @@ const struct block_device_operations nvme_bdev_ops = {
>   	.pr_ops		= &nvme_pr_ops,
>   };
>   
> -static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
> +int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
>   		u32 timeout, const char *op)
>   {
>   	unsigned long timeout_jiffies = jiffies + timeout * HZ;
> @@ -2241,18 +2241,28 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
>   
>   	return ret;
>   }
> +EXPORT_SYMBOL_GPL(nvme_wait_ready);
> +
> +int nvme_request_shutdown(struct nvme_ctrl *ctrl)
> +{
> +	ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
> +	ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
> +	return ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
> +}
> +EXPORT_SYMBOL_GPL(nvme_request_shutdown);

I think the name can be better, nvme_request_shutdown makes it seem
that you are actually sending a request to the controller.

Maybe nvme_ctrl_shutdown_start ? or as I suggested before
nvme_shutdown_nowait ?

>   
>   int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown)
>   {
>   	int ret;
>   
> -	ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
> -	if (shutdown)
> -		ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
> -	else
> +	if (shutdown) {
> +		ret = nvme_request_shutdown(ctrl);
> +	} else {
> +		ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
>   		ctrl->ctrl_config &= ~NVME_CC_ENABLE;
> +		ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
> +	}
>   
> -	ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config);
>   	if (ret)
>   		return ret;
>   
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 1700063bc24d..a3409afbebc5 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -758,6 +758,9 @@ blk_status_t nvme_host_path_error(struct request *req);
>   bool nvme_cancel_request(struct request *req, void *data);
>   void nvme_cancel_tagset(struct nvme_ctrl *ctrl);
>   void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl);
> +int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
> +		u32 timeout, const char *op);
> +int nvme_request_shutdown(struct nvme_ctrl *ctrl);
>   bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
>   		enum nvme_ctrl_state new_state);
>   int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown);



More information about the Linux-nvme mailing list