2023-06-05 01:32:43

by Kiwoong Kim

[permalink] [raw]
Subject: [PATCH v2 0/3] change UIC command handling

v1 -> v2: remove an unused variable in __ufshcd_send_uic_cmd

There are two issues on UIC command handling related to auto hibern8.
https://lore.kernel.org/linux-scsi/[email protected]/
https://lore.kernel.org/linux-scsi/[email protected]/

Now I combine the two things into this thread.
And one thing added to make part of submitting a UIC command apart
from the critical section w/ host_lock.

Kiwoong Kim (3):
ufs: make __ufshcd_send_uic_cmd not wrapped by host_lock
ufs: poll HCS.UCRDY before issuing a UIC command
ufs: poll pmc until another pa request is completed

drivers/ufs/core/ufshcd.c | 110 ++++++++++++++++++++++++++++++++--------------
1 file changed, 77 insertions(+), 33 deletions(-)

--
2.7.4



2023-06-05 01:32:54

by Kiwoong Kim

[permalink] [raw]
Subject: [PATCH v2 2/3] ufs: poll HCS.UCRDY before issuing a UIC command

v1 -> v2: replace usleep_range with udelay
because it's a sleepable period.

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 a89d39a..1f58a20 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -2365,7 +2365,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;
+ udelay(500);
+ } while (ktime_before(ktime_get(), timeout));
+
+ return val ? true : false;
}

/**
--
2.7.4


2023-06-05 01:33:09

by Kiwoong Kim

[permalink] [raw]
Subject: [PATCH v2 1/3] ufs: make __ufshcd_send_uic_cmd not wrapped by host_lock

__ufshcd_send_uic_cmd is wrapped uic_cmd_mutex and
its related contexts are accessed within the period wrappted
by uic_cmd_mutex. Thus, wrapping with host_lock is
redundant.

Signed-off-by: Kiwoong Kim <[email protected]>
---
drivers/ufs/core/ufshcd.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9434328..a89d39a 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -2457,7 +2457,6 @@ __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd,
bool completion)
{
lockdep_assert_held(&hba->uic_cmd_mutex);
- lockdep_assert_held(hba->host->host_lock);

if (!ufshcd_ready_for_uic_cmd(hba)) {
dev_err(hba->dev,
@@ -2484,7 +2483,6 @@ __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd,
int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
{
int ret;
- unsigned long flags;

if (hba->quirks & UFSHCD_QUIRK_BROKEN_UIC_CMD)
return 0;
@@ -2493,9 +2491,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
mutex_lock(&hba->uic_cmd_mutex);
ufshcd_add_delay_before_dme_cmd(hba);

- spin_lock_irqsave(hba->host->host_lock, flags);
ret = __ufshcd_send_uic_cmd(hba, uic_cmd, true);
- spin_unlock_irqrestore(hba->host->host_lock, flags);
if (!ret)
ret = ufshcd_wait_for_uic_cmd(hba, uic_cmd);

@@ -4180,8 +4176,8 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
wmb();
reenable_intr = true;
}
- ret = __ufshcd_send_uic_cmd(hba, cmd, false);
spin_unlock_irqrestore(hba->host->host_lock, flags);
+ ret = __ufshcd_send_uic_cmd(hba, cmd, false);
if (ret) {
dev_err(hba->dev,
"pwr ctrl cmd 0x%x with mode 0x%x uic error %d\n",
--
2.7.4


2023-06-05 07:31:13

by Avri Altman

[permalink] [raw]
Subject: RE: [PATCH v2 2/3] ufs: poll HCS.UCRDY before issuing a UIC command


> v1 -> v2: replace usleep_range with udelay because it's a sleepable period.
>
> 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
> a89d39a..1f58a20 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -2365,7 +2365,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;
> + udelay(500);
> + } while (ktime_before(ktime_get(), timeout));
> +
> + return val ? true : false;
> }
Can you use read_poll_timeout() instead?

Thanks,
Avri

>
> /**
> --
> 2.7.4

2023-06-07 19:11:06

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] ufs: make __ufshcd_send_uic_cmd not wrapped by host_lock

On 6/4/23 18:15, Kiwoong Kim wrote:
> __ufshcd_send_uic_cmd is wrapped uic_cmd_mutex and
> its related contexts are accessed within the period wrappted
> by uic_cmd_mutex. Thus, wrapping with host_lock is
> redundant.

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