* [PATCH v2] ufs: change the way to complete fDeviceInit
[not found] <CGME20200810060457epcas2p3023e61584089a0f285338d7e04ccaefe@epcas2p3.samsung.com>
@ 2020-08-10 5:56 ` Kiwoong Kim
2020-08-10 6:54 ` Avri Altman
0 siblings, 1 reply; 3+ messages in thread
From: Kiwoong Kim @ 2020-08-10 5:56 UTC (permalink / raw)
To: linux-scsi, alim.akhtar, avri.altman, jejb, martin.petersen,
beanhuo, asutoshd, cang, bvanassche, grant.jung, sc.suh, hy50.seo,
sh425.lee
Cc: Kiwoong Kim
Currently, UFS driver checks if fDeviceInit
is cleared at several times, not period. This patch
is to wait its completion with the period, not retrying.
Many device vendors usually provides the specification on
it with just period, not a combination of a number of retrying
and period. So it could be proper to regard to the information
coming from device vendors.
v1 -> v2: switch the method to get time from jiffies to ktime
Tested-by: Kiwoong Kim <kwmad.kim@samsung.com>
Signed-off-by: Kiwoong Kim <kwmad.kim@samsung.com>
---
drivers/scsi/ufs/ufshcd.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 092480a..11d61e5 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -72,6 +72,9 @@
/* Default value of wait time before gating device ref clock */
#define UFSHCD_REF_CLK_GATING_WAIT_US 0xFF /* microsecs */
+/* Polling time to wait for fDeviceInit */
+#define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
+
#define ufshcd_toggle_vreg(_dev, _vreg, _on) \
({ \
int _ret; \
@@ -4148,9 +4151,10 @@ EXPORT_SYMBOL_GPL(ufshcd_config_pwr_mode);
*/
static int ufshcd_complete_dev_init(struct ufs_hba *hba)
{
- int i;
int err;
bool flag_res = true;
+ ktime_t start;
+ s64 time;
err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL);
@@ -4161,20 +4165,27 @@ static int ufshcd_complete_dev_init(struct ufs_hba *hba)
goto out;
}
- /* poll for max. 1000 iterations for fDeviceInit flag to clear */
- for (i = 0; i < 1000 && !err && flag_res; i++)
- err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG,
- QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
+ /* Poll fDeviceInit flag to be cleared */
+ start = ktime_get();
+ do {
+ err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
+ QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
+ if (!flag_res)
+ break;
+ usleep_range(5000, 10000);
+ time = ktime_to_ms(ktime_sub(ktime_get(), start));
+ } while (time < FDEVICEINIT_COMPL_TIMEOUT);
- if (err)
+ if (err) {
dev_err(hba->dev,
- "%s reading fDeviceInit flag failed with error %d\n",
- __func__, err);
- else if (flag_res)
+ "%s reading fDeviceInit flag failed with error %d\n",
+ __func__, err);
+ } else if (flag_res) {
dev_err(hba->dev,
- "%s fDeviceInit was not cleared by the device\n",
- __func__);
-
+ "%s fDeviceInit was not cleared by the device\n",
+ __func__);
+ err = -EBUSY;
+ }
out:
return err;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH v2] ufs: change the way to complete fDeviceInit
2020-08-10 5:56 ` [PATCH v2] ufs: change the way to complete fDeviceInit Kiwoong Kim
@ 2020-08-10 6:54 ` Avri Altman
2020-08-10 10:07 ` Kiwoong Kim
0 siblings, 1 reply; 3+ messages in thread
From: Avri Altman @ 2020-08-10 6:54 UTC (permalink / raw)
To: Kiwoong Kim, linux-scsi@vger.kernel.org, alim.akhtar@samsung.com,
jejb@linux.ibm.com, martin.petersen@oracle.com,
beanhuo@micron.com, asutoshd@codeaurora.org, cang@codeaurora.org,
bvanassche@acm.org, grant.jung@samsung.com, sc.suh@samsung.com,
hy50.seo@samsung.com, sh425.lee@samsung.com
> + ktime_t start;
> + s64 time;
Can this be done with less variables? e.g is this working?
ktime_t timeout;
>
> err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
> QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL);
> @@ -4161,20 +4165,27 @@ static int ufshcd_complete_dev_init(struct ufs_hba
> *hba)
> goto out;
> }
>
> - /* poll for max. 1000 iterations for fDeviceInit flag to clear */
> - for (i = 0; i < 1000 && !err && flag_res; i++)
> - err = ufshcd_query_flag_retry(hba,
> UPIU_QUERY_OPCODE_READ_FLAG,
> - QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
> + /* Poll fDeviceInit flag to be cleared */
> + start = ktime_get();
timeout = ktime_add_ms(ktime_get(), FDEVICEINIT_COMPL_TIMEOUT);
> + do {
> + err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
> + QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
> + if (!flag_res)
> + break;
> + usleep_range(5000, 10000);
> + time = ktime_to_ms(ktime_sub(ktime_get(), start));
> + } while (time < FDEVICEINIT_COMPL_TIMEOUT);
while (ktime_before(ktime_get(), timeout));
Thanks,
Avri
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH v2] ufs: change the way to complete fDeviceInit
2020-08-10 6:54 ` Avri Altman
@ 2020-08-10 10:07 ` Kiwoong Kim
0 siblings, 0 replies; 3+ messages in thread
From: Kiwoong Kim @ 2020-08-10 10:07 UTC (permalink / raw)
To: 'Avri Altman', linux-scsi, alim.akhtar, jejb,
martin.petersen, beanhuo, asutoshd, cang, bvanassche, grant.jung,
sc.suh, hy50.seo, sh425.lee
>
> > + ktime_t start;
> > + s64 time;
> Can this be done with less variables? e.g is this working?
> ktime_t timeout;
I checked it worked. Nevertheless, I'll replace with your style.
Thanks.
Kiwoong Kim
>
> >
> > err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
> > QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL); @@ -4161,20
> > +4165,27 @@ static int ufshcd_complete_dev_init(struct ufs_hba
> > *hba)
> > goto out;
> > }
> >
> > - /* poll for max. 1000 iterations for fDeviceInit flag to clear */
> > - for (i = 0; i < 1000 && !err && flag_res; i++)
> > - err = ufshcd_query_flag_retry(hba,
> > UPIU_QUERY_OPCODE_READ_FLAG,
> > - QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
> > + /* Poll fDeviceInit flag to be cleared */
> > + start = ktime_get();
> timeout = ktime_add_ms(ktime_get(), FDEVICEINIT_COMPL_TIMEOUT);
>
> > + do {
> > + err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
> > + QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
> > + if (!flag_res)
> > + break;
> > + usleep_range(5000, 10000);
> > + time = ktime_to_ms(ktime_sub(ktime_get(), start));
> > + } while (time < FDEVICEINIT_COMPL_TIMEOUT);
> while (ktime_before(ktime_get(), timeout));
>
>
>
> Thanks,
> Avri
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-10 10:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20200810060457epcas2p3023e61584089a0f285338d7e04ccaefe@epcas2p3.samsung.com>
2020-08-10 5:56 ` [PATCH v2] ufs: change the way to complete fDeviceInit Kiwoong Kim
2020-08-10 6:54 ` Avri Altman
2020-08-10 10:07 ` 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.