Re: [PATCH 2/9] nvme: use nvme_wait_ready in nvme_shutdown_ctrl

Pankaj Raghav
2022-11-30T14:27:54Z

On 2022-11-30 14:57, Christoph Hellwig wrote:
> On Tue, Nov 29, 2022 at 04:57:18PM +0100, Pankaj Raghav wrote:
>> The timeout_jiffies calculation in nvme_shutdown_ctrl is:
>> unsigned long timeout = jiffies + (ctrl->shutdown_timeout * HZ);
>>
>> Aren't we changing the timeout with this change to something
>> different compared to what it was before for shutdown?
>
> Indeed. the timeout fields in the spec are in a different granularity
> than the shutdown_timeout field. This version should fix that:
>
> ---
> From 2f862232c4428d57dcfdc3b332866a9b2743711d Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@lst.de>
> Date: Wed, 16 Nov 2022 08:54:26 +0100
> Subject: nvme: use nvme_wait_ready in nvme_shutdown_ctrl
>
> Refactor the code to wait for CSTS state changes so that it can be reused
> by nvme_shutdown_ctrl.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

One minor nit: I also notice that nvme_wait_ready busy loop sleeps for
1~2ms, while the existing shutdown code busy loop sleeps for 100ms. Though,
I don't think it is an issue.

Apart from that, the new version looks good to me. Feel free to add to it:

Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
> ---
> drivers/nvme/host/core.c | 38 ++++++++++++--------------------------
> 1 file changed, 12 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 7961e146bbb163..03b2e34dcf7249 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2252,16 +2252,17 @@ static const struct block_device_operations nvme_bdev_ops = {
> .pr_ops = &nvme_pr_ops,
> };
>
> -static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 timeout, bool enabled)
> +static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
> + u32 timeout, const char *op)
> {
> - unsigned long timeout_jiffies = ((timeout + 1) * HZ / 2) + jiffies;
> - u32 csts, bit = enabled ? NVME_CSTS_RDY : 0;
> + unsigned long timeout_jiffies = jiffies + timeout * HZ;
> + u32 csts;
> int ret;
>
> while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) {
> if (csts == ~0)
> return -ENODEV;
> - if ((csts & NVME_CSTS_RDY) == bit)
> + if ((csts & mask) == val)
> break;
>
> usleep_range(1000, 2000);
<snip>

> - msleep(100);
> - if (fatal_signal_pending(current))
> - return -EINTR;