diff mbox series

[v4] ufs: change the way to complete fDeviceInit

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

Commit Message

Kiwoong Kim Aug. 7, 2020, 6:35 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.

Signed-off-by: Kiwoong Kim <kwmad.kim@samsung.com>
---
 drivers/scsi/ufs/ufshcd.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

Comments

Kiwoong Kim Aug. 7, 2020, 7 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.
> 
> Signed-off-by: Kiwoong Kim <kwmad.kim@samsung.com>
> ---
>  drivers/scsi/ufs/ufshcd.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index
> 092480a..c508931 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -4148,7 +4148,8 @@ EXPORT_SYMBOL_GPL(ufshcd_config_pwr_mode);
>   */
>  static int ufshcd_complete_dev_init(struct ufs_hba *hba)  {
> -	int i;
> +	u32 dev_init_compl_in_ms = 1500;
> +	unsigned long timeout;
>  	int err;
>  	bool flag_res = true;
> 
> @@ -4161,20 +4162,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 = jiffies + msecs_to_jiffies(dev_init_compl_in_ms);
> +	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 (time_before(jiffies, 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

I'll post again with v1 because this patch is teared from the patch set
That I had posted before. Sorry for bothering you.

Thanks.
Kiwoong Kim
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 092480a..c508931 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4148,7 +4148,8 @@  EXPORT_SYMBOL_GPL(ufshcd_config_pwr_mode);
  */
 static int ufshcd_complete_dev_init(struct ufs_hba *hba)
 {
-	int i;
+	u32 dev_init_compl_in_ms = 1500;
+	unsigned long timeout;
 	int err;
 	bool flag_res = true;
 
@@ -4161,20 +4162,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 = jiffies + msecs_to_jiffies(dev_init_compl_in_ms);
+	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 (time_before(jiffies, 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;
 }