diff mbox series

[V4,2/2] scsi: ufs: Allow an error return value from ->device_reset()

Message ID 20201103141403.2142-3-adrian.hunter@intel.com (mailing list archive)
State Accepted
Headers show
Series scsi: ufs: Add DeepSleep feature | expand

Commit Message

Adrian Hunter Nov. 3, 2020, 2:14 p.m. UTC
It is simpler for drivers to provide a ->device_reset() callback
irrespective of whether the GPIO, or firmware interface necessary to do the
reset, is discovered during probe.

Change ->device_reset() to return an error code.  Drivers that provide
the callback, but do not do the reset operation should return -EOPNOTSUPP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufs-mediatek.c |  4 +++-
 drivers/scsi/ufs/ufs-qcom.c     |  6 ++++--
 drivers/scsi/ufs/ufshcd.h       | 11 +++++++----
 3 files changed, 14 insertions(+), 7 deletions(-)

Comments

Stanley Chu Nov. 4, 2020, 2:55 a.m. UTC | #1
Hi Adrian,

On Tue, 2020-11-03 at 16:14 +0200, Adrian Hunter wrote:
> It is simpler for drivers to provide a ->device_reset() callback
> irrespective of whether the GPIO, or firmware interface necessary to do the
> reset, is discovered during probe.
> 
> Change ->device_reset() to return an error code.  Drivers that provide
> the callback, but do not do the reset operation should return -EOPNOTSUPP.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  drivers/scsi/ufs/ufs-mediatek.c |  4 +++-
>  drivers/scsi/ufs/ufs-qcom.c     |  6 ++++--
>  drivers/scsi/ufs/ufshcd.h       | 11 +++++++----
>  3 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
> index 8df73bc2f8cb..914a827a93ee 100644
> --- a/drivers/scsi/ufs/ufs-mediatek.c
> +++ b/drivers/scsi/ufs/ufs-mediatek.c
> @@ -743,7 +743,7 @@ static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,
>  	return ret;
>  }
>  
> -static void ufs_mtk_device_reset(struct ufs_hba *hba)
> +static int ufs_mtk_device_reset(struct ufs_hba *hba)
>  {
>  	struct arm_smccc_res res;
>  
> @@ -764,6 +764,8 @@ static void ufs_mtk_device_reset(struct ufs_hba *hba)
>  	usleep_range(10000, 15000);
>  
>  	dev_info(hba->dev, "device reset done\n");
> +
> +	return 0;
>  }
>  
>  static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 9a19c6d15d3b..357c3b49321d 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1422,13 +1422,13 @@ static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)
>   *
>   * Toggles the (optional) reset line to reset the attached device.
>   */
> -static void ufs_qcom_device_reset(struct ufs_hba *hba)
> +static int ufs_qcom_device_reset(struct ufs_hba *hba)
>  {
>  	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
>  
>  	/* reset gpio is optional */
>  	if (!host->device_reset)
> -		return;
> +		return -EOPNOTSUPP;
>  
>  	/*
>  	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
> @@ -1439,6 +1439,8 @@ static void ufs_qcom_device_reset(struct ufs_hba *hba)
>  
>  	gpiod_set_value_cansleep(host->device_reset, 0);
>  	usleep_range(10, 15);
> +
> +	return 0;
>  }
>  
>  #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 213be0667b59..5191d87f6263 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -323,7 +323,7 @@ struct ufs_hba_variant_ops {
>  	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>  	void	(*dbg_register_dump)(struct ufs_hba *hba);
>  	int	(*phy_initialization)(struct ufs_hba *);
> -	void	(*device_reset)(struct ufs_hba *hba);
> +	int	(*device_reset)(struct ufs_hba *hba);
>  	void	(*config_scaling_param)(struct ufs_hba *hba,
>  					struct devfreq_dev_profile *profile,
>  					void *data);
> @@ -1207,9 +1207,12 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
>  static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
>  {
>  	if (hba->vops && hba->vops->device_reset) {
> -		hba->vops->device_reset(hba);
> -		ufshcd_set_ufs_dev_active(hba);
> -		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
> +		int err = hba->vops->device_reset(hba);
> +
> +		if (!err)
> +			ufshcd_set_ufs_dev_active(hba);
> +		if (err != -EOPNOTSUPP)
> +			ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, err);
>  	}
>  }

For ufs-mediatek part and related flow,

Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Can Guo Nov. 4, 2020, 8:05 a.m. UTC | #2
On 2020-11-03 22:14, Adrian Hunter wrote:
> It is simpler for drivers to provide a ->device_reset() callback
> irrespective of whether the GPIO, or firmware interface necessary to do 
> the
> reset, is discovered during probe.
> 
> Change ->device_reset() to return an error code.  Drivers that provide
> the callback, but do not do the reset operation should return 
> -EOPNOTSUPP.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Reviewed-by: Can Guo <cang@codeaurora.org>

> ---
>  drivers/scsi/ufs/ufs-mediatek.c |  4 +++-
>  drivers/scsi/ufs/ufs-qcom.c     |  6 ++++--
>  drivers/scsi/ufs/ufshcd.h       | 11 +++++++----
>  3 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-mediatek.c 
> b/drivers/scsi/ufs/ufs-mediatek.c
> index 8df73bc2f8cb..914a827a93ee 100644
> --- a/drivers/scsi/ufs/ufs-mediatek.c
> +++ b/drivers/scsi/ufs/ufs-mediatek.c
> @@ -743,7 +743,7 @@ static int ufs_mtk_link_startup_notify(struct 
> ufs_hba *hba,
>  	return ret;
>  }
> 
> -static void ufs_mtk_device_reset(struct ufs_hba *hba)
> +static int ufs_mtk_device_reset(struct ufs_hba *hba)
>  {
>  	struct arm_smccc_res res;
> 
> @@ -764,6 +764,8 @@ static void ufs_mtk_device_reset(struct ufs_hba 
> *hba)
>  	usleep_range(10000, 15000);
> 
>  	dev_info(hba->dev, "device reset done\n");
> +
> +	return 0;
>  }
> 
>  static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 9a19c6d15d3b..357c3b49321d 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1422,13 +1422,13 @@ static void ufs_qcom_dump_dbg_regs(struct 
> ufs_hba *hba)
>   *
>   * Toggles the (optional) reset line to reset the attached device.
>   */
> -static void ufs_qcom_device_reset(struct ufs_hba *hba)
> +static int ufs_qcom_device_reset(struct ufs_hba *hba)
>  {
>  	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
> 
>  	/* reset gpio is optional */
>  	if (!host->device_reset)
> -		return;
> +		return -EOPNOTSUPP;
> 
>  	/*
>  	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
> @@ -1439,6 +1439,8 @@ static void ufs_qcom_device_reset(struct ufs_hba 
> *hba)
> 
>  	gpiod_set_value_cansleep(host->device_reset, 0);
>  	usleep_range(10, 15);
> +
> +	return 0;
>  }
> 
>  #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 213be0667b59..5191d87f6263 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -323,7 +323,7 @@ struct ufs_hba_variant_ops {
>  	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>  	void	(*dbg_register_dump)(struct ufs_hba *hba);
>  	int	(*phy_initialization)(struct ufs_hba *);
> -	void	(*device_reset)(struct ufs_hba *hba);
> +	int	(*device_reset)(struct ufs_hba *hba);
>  	void	(*config_scaling_param)(struct ufs_hba *hba,
>  					struct devfreq_dev_profile *profile,
>  					void *data);
> @@ -1207,9 +1207,12 @@ static inline void
> ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
>  static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
>  {
>  	if (hba->vops && hba->vops->device_reset) {
> -		hba->vops->device_reset(hba);
> -		ufshcd_set_ufs_dev_active(hba);
> -		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
> +		int err = hba->vops->device_reset(hba);
> +
> +		if (!err)
> +			ufshcd_set_ufs_dev_active(hba);
> +		if (err != -EOPNOTSUPP)
> +			ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, err);
>  	}
>  }
Bean Huo Nov. 4, 2020, 8:44 a.m. UTC | #3
On Tue, 2020-11-03 at 16:14 +0200, Adrian Hunter wrote:
> It is simpler for drivers to provide a ->device_reset() callback
> irrespective of whether the GPIO, or firmware interface necessary to
> do the
> reset, is discovered during probe.
> 
> Change ->device_reset() to return an error code.  Drivers that
> provide
> the callback, but do not do the reset operation should return
> -EOPNOTSUPP.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Bean huo <beanhuo@micron.com>
Asutosh Das (asd) Nov. 4, 2020, 4:35 p.m. UTC | #4
On 11/3/2020 6:14 AM, Adrian Hunter wrote:
> It is simpler for drivers to provide a ->device_reset() callback
> irrespective of whether the GPIO, or firmware interface necessary to do the
> reset, is discovered during probe.
> 
> Change ->device_reset() to return an error code.  Drivers that provide
> the callback, but do not do the reset operation should return -EOPNOTSUPP.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

> ---
>   drivers/scsi/ufs/ufs-mediatek.c |  4 +++-
>   drivers/scsi/ufs/ufs-qcom.c     |  6 ++++--
>   drivers/scsi/ufs/ufshcd.h       | 11 +++++++----
>   3 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
> index 8df73bc2f8cb..914a827a93ee 100644
> --- a/drivers/scsi/ufs/ufs-mediatek.c
> +++ b/drivers/scsi/ufs/ufs-mediatek.c
> @@ -743,7 +743,7 @@ static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,
>   	return ret;
>   }
>   
> -static void ufs_mtk_device_reset(struct ufs_hba *hba)
> +static int ufs_mtk_device_reset(struct ufs_hba *hba)
>   {
>   	struct arm_smccc_res res;
>   
> @@ -764,6 +764,8 @@ static void ufs_mtk_device_reset(struct ufs_hba *hba)
>   	usleep_range(10000, 15000);
>   
>   	dev_info(hba->dev, "device reset done\n");
> +
> +	return 0;
>   }
>   
>   static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 9a19c6d15d3b..357c3b49321d 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1422,13 +1422,13 @@ static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)
>    *
>    * Toggles the (optional) reset line to reset the attached device.
>    */
> -static void ufs_qcom_device_reset(struct ufs_hba *hba)
> +static int ufs_qcom_device_reset(struct ufs_hba *hba)
>   {
>   	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
>   
>   	/* reset gpio is optional */
>   	if (!host->device_reset)
> -		return;
> +		return -EOPNOTSUPP;
>   
>   	/*
>   	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
> @@ -1439,6 +1439,8 @@ static void ufs_qcom_device_reset(struct ufs_hba *hba)
>   
>   	gpiod_set_value_cansleep(host->device_reset, 0);
>   	usleep_range(10, 15);
> +
> +	return 0;
>   }
>   
>   #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 213be0667b59..5191d87f6263 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -323,7 +323,7 @@ struct ufs_hba_variant_ops {
>   	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>   	void	(*dbg_register_dump)(struct ufs_hba *hba);
>   	int	(*phy_initialization)(struct ufs_hba *);
> -	void	(*device_reset)(struct ufs_hba *hba);
> +	int	(*device_reset)(struct ufs_hba *hba);
>   	void	(*config_scaling_param)(struct ufs_hba *hba,
>   					struct devfreq_dev_profile *profile,
>   					void *data);
> @@ -1207,9 +1207,12 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
>   static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
>   {
>   	if (hba->vops && hba->vops->device_reset) {
> -		hba->vops->device_reset(hba);
> -		ufshcd_set_ufs_dev_active(hba);
> -		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
> +		int err = hba->vops->device_reset(hba);
> +
> +		if (!err)
> +			ufshcd_set_ufs_dev_active(hba);
> +		if (err != -EOPNOTSUPP)
> +			ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, err);
>   	}
>   }
>   
>
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
index 8df73bc2f8cb..914a827a93ee 100644
--- a/drivers/scsi/ufs/ufs-mediatek.c
+++ b/drivers/scsi/ufs/ufs-mediatek.c
@@ -743,7 +743,7 @@  static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,
 	return ret;
 }
 
-static void ufs_mtk_device_reset(struct ufs_hba *hba)
+static int ufs_mtk_device_reset(struct ufs_hba *hba)
 {
 	struct arm_smccc_res res;
 
@@ -764,6 +764,8 @@  static void ufs_mtk_device_reset(struct ufs_hba *hba)
 	usleep_range(10000, 15000);
 
 	dev_info(hba->dev, "device reset done\n");
+
+	return 0;
 }
 
 static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 9a19c6d15d3b..357c3b49321d 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1422,13 +1422,13 @@  static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)
  *
  * Toggles the (optional) reset line to reset the attached device.
  */
-static void ufs_qcom_device_reset(struct ufs_hba *hba)
+static int ufs_qcom_device_reset(struct ufs_hba *hba)
 {
 	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
 
 	/* reset gpio is optional */
 	if (!host->device_reset)
-		return;
+		return -EOPNOTSUPP;
 
 	/*
 	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
@@ -1439,6 +1439,8 @@  static void ufs_qcom_device_reset(struct ufs_hba *hba)
 
 	gpiod_set_value_cansleep(host->device_reset, 0);
 	usleep_range(10, 15);
+
+	return 0;
 }
 
 #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 213be0667b59..5191d87f6263 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -323,7 +323,7 @@  struct ufs_hba_variant_ops {
 	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
 	void	(*dbg_register_dump)(struct ufs_hba *hba);
 	int	(*phy_initialization)(struct ufs_hba *);
-	void	(*device_reset)(struct ufs_hba *hba);
+	int	(*device_reset)(struct ufs_hba *hba);
 	void	(*config_scaling_param)(struct ufs_hba *hba,
 					struct devfreq_dev_profile *profile,
 					void *data);
@@ -1207,9 +1207,12 @@  static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
 static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
 {
 	if (hba->vops && hba->vops->device_reset) {
-		hba->vops->device_reset(hba);
-		ufshcd_set_ufs_dev_active(hba);
-		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
+		int err = hba->vops->device_reset(hba);
+
+		if (!err)
+			ufshcd_set_ufs_dev_active(hba);
+		if (err != -EOPNOTSUPP)
+			ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, err);
 	}
 }