* [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
[not found] <CGME20230509083312epcas2p375f77d18a9026f7d263750baf9c9a5bb@epcas2p3.samsung.com>
@ 2023-05-09 8:24 ` Kiwoong Kim
2023-05-10 10:14 ` Avri Altman
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Kiwoong Kim @ 2023-05-09 8:24 UTC (permalink / raw)
To: linux-scsi, linux-kernel, alim.akhtar, avri.altman, jejb,
martin.petersen, beanhuo, adrian.hunter, sc.suh, hy50.seo,
sh425.lee, kwangwon.min
Cc: Kiwoong Kim
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 <kwmad.kim@samsung.com>
---
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-09 8:24 ` [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command Kiwoong Kim
@ 2023-05-10 10:14 ` Avri Altman
2023-05-16 3:30 ` Kiwoong Kim
2023-05-10 18:53 ` Bart Van Assche
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Avri Altman @ 2023-05-10 10:14 UTC (permalink / raw)
To: Kiwoong Kim, linux-scsi, linux-kernel, alim.akhtar, jejb,
martin.petersen, beanhuo, adrian.hunter, sc.suh, hy50.seo,
sh425.lee, kwangwon.min
> 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 <kwmad.kim@samsung.com>
Is this replaces your previous suggestion - https://lore.kernel.org/lkml/1682385635-43601-1-git-send-email-kwmad.kim@samsung.com/
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-09 8:24 ` [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command Kiwoong Kim
2023-05-10 10:14 ` Avri Altman
@ 2023-05-10 18:53 ` Bart Van Assche
2023-05-10 21:24 ` Bao D. Nguyen
2023-05-11 5:22 ` Adrian Hunter
3 siblings, 0 replies; 10+ messages in thread
From: Bart Van Assche @ 2023-05-10 18:53 UTC (permalink / raw)
To: Kiwoong Kim, linux-scsi, linux-kernel, alim.akhtar, avri.altman,
jejb, martin.petersen, beanhuo, adrian.hunter, sc.suh, hy50.seo,
sh425.lee, kwangwon.min
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 <kwmad.kim@samsung.com>
> ---
> 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 <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-09 8:24 ` [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command Kiwoong Kim
2023-05-10 10:14 ` Avri Altman
2023-05-10 18:53 ` Bart Van Assche
@ 2023-05-10 21:24 ` Bao D. Nguyen
2023-05-10 21:46 ` Bart Van Assche
` (2 more replies)
2023-05-11 5:22 ` Adrian Hunter
3 siblings, 3 replies; 10+ messages in thread
From: Bao D. Nguyen @ 2023-05-10 21:24 UTC (permalink / raw)
To: Kiwoong Kim, linux-scsi, linux-kernel, alim.akhtar, avri.altman,
jejb, martin.petersen, beanhuo, adrian.hunter, sc.suh, hy50.seo,
sh425.lee, kwangwon.min
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 <kwmad.kim@samsung.com>
> ---
> 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;
> }
>
> /**
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-10 21:24 ` Bao D. Nguyen
@ 2023-05-10 21:46 ` Bart Van Assche
2023-05-10 23:35 ` Kiwoong Kim
2023-05-16 3:28 ` Kiwoong Kim
2 siblings, 0 replies; 10+ messages in thread
From: Bart Van Assche @ 2023-05-10 21:46 UTC (permalink / raw)
To: Bao D. Nguyen, Kiwoong Kim, linux-scsi, linux-kernel,
alim.akhtar, avri.altman, jejb, martin.petersen, beanhuo,
adrian.hunter, sc.suh, hy50.seo, sh425.lee, kwangwon.min
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-10 21:24 ` Bao D. Nguyen
2023-05-10 21:46 ` Bart Van Assche
@ 2023-05-10 23:35 ` Kiwoong Kim
2023-05-16 3:28 ` Kiwoong Kim
2 siblings, 0 replies; 10+ messages in thread
From: Kiwoong Kim @ 2023-05-10 23:35 UTC (permalink / raw)
To: 'Bao D. Nguyen',
linux-scsi, linux-kernel, alim.akhtar, avri.altman, jejb,
martin.petersen, beanhuo, adrian.hunter, sc.suh, hy50.seo,
sh425.lee, kwangwon.min
> 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 <kwmad.kim@samsung.com>
> > ---
> > 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;
> > }
> >
> > /**
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-09 8:24 ` [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command Kiwoong Kim
` (2 preceding siblings ...)
2023-05-10 21:24 ` Bao D. Nguyen
@ 2023-05-11 5:22 ` Adrian Hunter
2023-05-12 0:56 ` Kiwoong Kim
3 siblings, 1 reply; 10+ messages in thread
From: Adrian Hunter @ 2023-05-11 5:22 UTC (permalink / raw)
To: Kiwoong Kim, linux-scsi, linux-kernel, alim.akhtar, avri.altman,
jejb, martin.petersen, beanhuo, sc.suh, hy50.seo, sh425.lee,
kwangwon.min
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 <kwmad.kim@samsung.com>
> ---
> 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;
> }
>
> /**
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-11 5:22 ` Adrian Hunter
@ 2023-05-12 0:56 ` Kiwoong Kim
0 siblings, 0 replies; 10+ messages in thread
From: Kiwoong Kim @ 2023-05-12 0:56 UTC (permalink / raw)
To: 'Adrian Hunter', linux-scsi
> 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
It makes sense. Got it. Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-10 21:24 ` Bao D. Nguyen
2023-05-10 21:46 ` Bart Van Assche
2023-05-10 23:35 ` Kiwoong Kim
@ 2023-05-16 3:28 ` Kiwoong Kim
2 siblings, 0 replies; 10+ messages in thread
From: Kiwoong Kim @ 2023-05-16 3:28 UTC (permalink / raw)
To: 'Bao D. Nguyen',
linux-scsi, sc.suh, hy50.seo, sh425.lee, kwangwon.min
> > + 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()?
You're right. Let me fix it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command
2023-05-10 10:14 ` Avri Altman
@ 2023-05-16 3:30 ` Kiwoong Kim
0 siblings, 0 replies; 10+ messages in thread
From: Kiwoong Kim @ 2023-05-16 3:30 UTC (permalink / raw)
To: 'Avri Altman',
linux-scsi, sc.suh, hy50.seo, sh425.lee, kwangwon.min
> > 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 <kwmad.kim@samsung.com>
> Is this replaces your previous suggestion -
> https://lore.kernel.org/lkml/1682385635-43601-1-git-send-email-
> kwmad.kim@samsung.com/
> Or is it addressing another issue?
>
> Thanks,
> Avri
>
No, they are different. This is about reporting UIC ready and what you mentioned
is about reporting UIC busy in a certain race condition.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-05-16 3:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20230509083312epcas2p375f77d18a9026f7d263750baf9c9a5bb@epcas2p3.samsung.com>
2023-05-09 8:24 ` [RFC PATCH v1] ufs: poll HCS.UCRDY before issuing a UIC command Kiwoong Kim
2023-05-10 10:14 ` Avri Altman
2023-05-16 3:30 ` Kiwoong Kim
2023-05-10 18:53 ` Bart Van Assche
2023-05-10 21:24 ` Bao D. Nguyen
2023-05-10 21:46 ` Bart Van Assche
2023-05-10 23:35 ` Kiwoong Kim
2023-05-16 3:28 ` Kiwoong Kim
2023-05-11 5:22 ` Adrian Hunter
2023-05-12 0:56 ` Kiwoong Kim
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.