diff mbox series

[v3] ufs: change the way to complete fDeviceInit

Message ID 1597053747-75171-1-git-send-email-kwmad.kim@samsung.com (mailing list archive)
State Accepted
Headers show
Series [v3] ufs: change the way to complete fDeviceInit | expand

Commit Message

Kiwoong Kim Aug. 10, 2020, 10:02 a.m. UTC
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 | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

Comments

Avri Altman Aug. 10, 2020, 10:15 a.m. UTC | #1
> 
> 
> 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>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Martin K. Petersen Sept. 9, 2020, 2:17 a.m. UTC | #2
On Mon, 10 Aug 2020 19:02:27 +0900, Kiwoong Kim wrote:

> 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.
> 
> [...]

Applied to 5.10/scsi-queue, thanks!

[1/1] scsi: ufs: Change fDeviceInit busy wait
      https://git.kernel.org/mkp/scsi/c/29707fab5845
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 092480a..ed03051 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,9 @@  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 timeout;
 
 	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
 		QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL);
@@ -4161,20 +4164,26 @@  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 */
+	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);
+	} while (ktime_before(ktime_get(), 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;
 }