2023-05-09 09:02:34

by Kiwoong Kim

[permalink] [raw]
Subject: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

With auto hibern8 enabled, UIC could be working
for a while to process a hibern8 operation and HCI
reports UIC not ready for a short term through HCS.UCRDY.
And UFS driver can't recognize the operation.
UFSHCI spec specifies UCRDY like this:
whether the host controller is ready to process UIC COMMAND

The 'ready' could be seen as many different meanings. If the meaning
includes not processing any request from HCI, processing a hibern8
operation can be 'not ready'. In this situation, the driver needs to
wait until the operations is completed.

Signed-off-by: Kiwoong Kim <[email protected]>
---
drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 96ce6af..fc79539 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
*/
static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
{
- return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
+ ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
+ u32 val = 0;
+
+ do {
+ val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
+ UIC_COMMAND_READY;
+ if (val)
+ break;
+ usleep_range(500, 1000);
+ } while (ktime_before(ktime_get(), timeout));
+
+ return val ? true : false;
}

/**
--
2.7.4


2023-05-10 10:19:52

by Avri Altman

[permalink] [raw]
Subject: RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

> With auto hibern8 enabled, UIC could be working
> for a while to process a hibern8 operation and HCI
> reports UIC not ready for a short term through HCS.UCRDY.
> And UFS driver can't recognize the operation.
> UFSHCI spec specifies UCRDY like this:
> whether the host controller is ready to process UIC COMMAND
>
> The 'ready' could be seen as many different meanings. If the meaning
> includes not processing any request from HCI, processing a hibern8
> operation can be 'not ready'. In this situation, the driver needs to
> wait until the operations is completed.
>
> Signed-off-by: Kiwoong Kim <[email protected]>
Is this replaces your previous suggestion - https://lore.kernel.org/lkml/[email protected]/
Or is it addressing another issue?

Thanks,
Avri

> ---
> drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 96ce6af..fc79539 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct
> ufs_hba *hba)
> */
> static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
> {
> - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> UIC_COMMAND_READY;
> + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
> + u32 val = 0;
> +
> + do {
> + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> + UIC_COMMAND_READY;
> + if (val)
> + break;
> + usleep_range(500, 1000);
> + } while (ktime_before(ktime_get(), timeout));
> +
> + return val ? true : false;
> }
>
> /**
> --
> 2.7.4

2023-05-10 19:02:05

by Bart Van Assche

[permalink] [raw]
Subject: Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

On 5/9/23 01:24, Kiwoong Kim wrote:
> With auto hibern8 enabled, UIC could be working
> for a while to process a hibern8 operation and HCI
> reports UIC not ready for a short term through HCS.UCRDY.
> And UFS driver can't recognize the operation.
> UFSHCI spec specifies UCRDY like this:
> whether the host controller is ready to process UIC COMMAND
>
> The 'ready' could be seen as many different meanings. If the meaning
> includes not processing any request from HCI, processing a hibern8
> operation can be 'not ready'. In this situation, the driver needs to
> wait until the operations is completed.
>
> Signed-off-by: Kiwoong Kim <[email protected]>
> ---
> drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 96ce6af..fc79539 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
> */
> static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
> {
> - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
> + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
> + u32 val = 0;
> +
> + do {
> + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> + UIC_COMMAND_READY;
> + if (val)
> + break;
> + usleep_range(500, 1000);
> + } while (ktime_before(ktime_get(), timeout));
> +
> + return val ? true : false;
> }
>
> /**

Reviewed-by: Bart Van Assche <[email protected]>

2023-05-10 21:32:18

by Bao D. Nguyen

[permalink] [raw]
Subject: Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

On 5/9/2023 1:24 AM, Kiwoong Kim wrote:
> With auto hibern8 enabled, UIC could be working
> for a while to process a hibern8 operation and HCI
> reports UIC not ready for a short term through HCS.UCRDY.
> And UFS driver can't recognize the operation.
> UFSHCI spec specifies UCRDY like this:
> whether the host controller is ready to process UIC COMMAND
>
> The 'ready' could be seen as many different meanings. If the meaning
> includes not processing any request from HCI, processing a hibern8
> operation can be 'not ready'. In this situation, the driver needs to
> wait until the operations is completed.
>
> Signed-off-by: Kiwoong Kim <[email protected]>
> ---
> drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 96ce6af..fc79539 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
> */
> static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
> {
> - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
> + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
> + u32 val = 0;
> +
> + do {
> + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> + UIC_COMMAND_READY;
> + if (val)
> + break;
> + usleep_range(500, 1000);
Hi Kiwoong,
It looks like you are sleeping while holding the
spin_lock_irqsave(hba->host->host_lock, flags)
in ufshcd_send_uic_cmd()?


> + } while (ktime_before(ktime_get(), timeout));
> +
> + return val ? true : false;
> }
>
> /**


2023-05-10 22:00:27

by Bart Van Assche

[permalink] [raw]
Subject: Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

On 5/10/23 14:24, Bao D. Nguyen wrote:
> It looks like you are sleeping while holding the
> spin_lock_irqsave(hba->host->host_lock, flags)
> in ufshcd_send_uic_cmd()?
Right. Please drop my Reviewed-by.

Thanks,

Bart.

2023-05-11 00:25:41

by Kiwoong Kim

[permalink] [raw]
Subject: RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

> On 5/9/2023 1:24 AM, Kiwoong Kim wrote:
> > With auto hibern8 enabled, UIC could be working for a while to process
> > a hibern8 operation and HCI reports UIC not ready for a short term
> > through HCS.UCRDY.
> > And UFS driver can't recognize the operation.
> > UFSHCI spec specifies UCRDY like this:
> > whether the host controller is ready to process UIC COMMAND
> >
> > The 'ready' could be seen as many different meanings. If the meaning
> > includes not processing any request from HCI, processing a hibern8
> > operation can be 'not ready'. In this situation, the driver needs to
> > wait until the operations is completed.
> >
> > Signed-off-by: Kiwoong Kim <[email protected]>
> > ---
> > drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
> > 1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> > index 96ce6af..fc79539 100644
> > --- a/drivers/ufs/core/ufshcd.c
> > +++ b/drivers/ufs/core/ufshcd.c
> > @@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct
> ufs_hba *hba)
> > */
> > static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
> > {
> > - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
> > + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
> > + u32 val = 0;
> > +
> > + do {
> > + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> > + UIC_COMMAND_READY;
> > + if (val)
> > + break;
> > + usleep_range(500, 1000);
> Hi Kiwoong,
> It looks like you are sleeping while holding the spin_lock_irqsave(hba-
> >host->host_lock, flags) in ufshcd_send_uic_cmd()?

Right. Let me fix it.

Thanks.
Kiwoong Kim

>
>
> > + } while (ktime_before(ktime_get(), timeout));
> > +
> > + return val ? true : false;
> > }
> >
> > /**



2023-05-11 05:32:10

by Adrian Hunter

[permalink] [raw]
Subject: Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command

On 9/05/23 11:24, Kiwoong Kim wrote:
> With auto hibern8 enabled, UIC could be working
> for a while to process a hibern8 operation and HCI
> reports UIC not ready for a short term through HCS.UCRDY.
> And UFS driver can't recognize the operation.
> UFSHCI spec specifies UCRDY like this:
> whether the host controller is ready to process UIC COMMAND
>
> The 'ready' could be seen as many different meanings. If the meaning
> includes not processing any request from HCI, processing a hibern8
> operation can be 'not ready'. In this situation, the driver needs to
> wait until the operations is completed.
>
> Signed-off-by: Kiwoong Kim <[email protected]>
> ---
> drivers/ufs/core/ufshcd.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 96ce6af..fc79539 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -2368,7 +2368,18 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
> */
> static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
> {
> - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
> + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT);
> + u32 val = 0;
> +
> + do {
> + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> + UIC_COMMAND_READY;
> + if (val)
> + break;
> + usleep_range(500, 1000);

Pedantically, the sleep probably needs to be less than the
auto-hibernate idle timer period?

> + } while (ktime_before(ktime_get(), timeout));

read_poll_timeout() would be a better choice for I/O polling

> +
> + return val ? true : false;
> }
>
> /**