linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V8 0/1] scsi: ufs: Let devices remain runtime suspended during system suspend
@ 2021-10-27 13:06 Adrian Hunter
  2021-10-27 13:06 ` [PATCH V8 1/1] " Adrian Hunter
  2021-12-03  3:03 ` [PATCH V8 0/1] " Martin K. Petersen
  0 siblings, 2 replies; 7+ messages in thread
From: Adrian Hunter @ 2021-10-27 13:06 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Asutosh Das, Bart Van Assche, Kiwoong Kim,
	Manivannan Sadhasivam, Wei Li, linux-scsi

Hi

UFS devices can remain runtime suspended at system suspend time,
if the conditions are right.  Add support for that, first fixing
the impediments.


Changes in V8:

      scsi: ufs: Fix runtime PM dependencies getting broken
	Dropped because superseded by "scsi: core: pm: Only runtime resume
	if necessary"

      scsi: ufs: Let devices remain runtime suspended during system suspend
	Updated commit message
	Re-based

Changes in V7:

      scsi: ufs: Fix error handler clear ua deadlock
	Dropped because superseded by "scsi: ufs: core: Stop clearing
	UNIT ATTENTIONS"

      scsi: ufs: Let devices remain runtime suspended during system suspend
	Re-based

Changes in V6:

      scsi: ufs: Fix error handler clear ua deadlock
	Ensure data byte count bits 1:0 are 11b
	Use ufshcd_compose_dev_cmd() to set up command

Changes in V5:

      scsi: ufs: Fix error handler clear ua deadlock
	Update commit message
	Try to abort REQUEST SENSE if it times out

Changes in V4:

      scsi: ufs: Fix error handler clear ua deadlock

	Do request-sense directly

Changes in V3:

      scsi: ufs: Fix error handler clear ua deadlock

	Correct commit message.
	Amend stable tags to add dependent cherry picks

Changes in V2:

    scsi: ufs: Let devices remain runtime suspended during system suspend

	The ufs-hisi driver uses different RPM and SPM, but it is made
	explicit by a new parameter to suspend prepare.


Adrian Hunter (1):
      scsi: ufs: Let devices remain runtime suspended during system suspend

 drivers/scsi/ufs/ufs-hisi.c |  8 +++++++-
 drivers/scsi/ufs/ufshcd.c   | 45 ++++++++++++++++++++++++++++++++++++++++-----
 drivers/scsi/ufs/ufshcd.h   | 11 +++++++++++
 3 files changed, 58 insertions(+), 6 deletions(-)


Regards
Adrian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH V8 1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-10-27 13:06 [PATCH V8 0/1] scsi: ufs: Let devices remain runtime suspended during system suspend Adrian Hunter
@ 2021-10-27 13:06 ` Adrian Hunter
  2021-11-12  7:09   ` Adrian Hunter
  2021-11-24 15:06   ` Bean Huo
  2021-12-03  3:03 ` [PATCH V8 0/1] " Martin K. Petersen
  1 sibling, 2 replies; 7+ messages in thread
From: Adrian Hunter @ 2021-10-27 13:06 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Asutosh Das, Bart Van Assche, Kiwoong Kim,
	Manivannan Sadhasivam, Wei Li, linux-scsi

If the UFS Device WLUN is runtime suspended and is in the same power
mode, link state and b_rpm_dev_flush_capable (BKOP or WB buffer flush etc)
state, then it can remain runtime suspended instead of being runtime
resumed and then system suspended.

The following patch has cleared the way for that to happen:
  scsi: core: pm: Only runtime resume if necessary

So amend the logic accordingly.

Note, the ufs-hisi driver uses different RPM and SPM, but it is made
explicit by a new parameter to suspend prepare.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>
---
 drivers/scsi/ufs/ufs-hisi.c |  8 ++++++-
 drivers/scsi/ufs/ufshcd.c   | 45 ++++++++++++++++++++++++++++++++-----
 drivers/scsi/ufs/ufshcd.h   | 11 +++++++++
 3 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-hisi.c b/drivers/scsi/ufs/ufs-hisi.c
index 8c7e8d321746..ab1a7ebd89b1 100644
--- a/drivers/scsi/ufs/ufs-hisi.c
+++ b/drivers/scsi/ufs/ufs-hisi.c
@@ -396,6 +396,12 @@ static int ufs_hisi_pwr_change_notify(struct ufs_hba *hba,
 	return ret;
 }
 
+static int ufs_hisi_suspend_prepare(struct device *dev)
+{
+	/* RPM and SPM are different. Refer ufs_hisi_suspend() */
+	return __ufshcd_suspend_prepare(dev, false);
+}
+
 static int ufs_hisi_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
 	enum ufs_notify_change_status status)
 {
@@ -578,7 +584,7 @@ static int ufs_hisi_remove(struct platform_device *pdev)
 static const struct dev_pm_ops ufs_hisi_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
 	SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
-	.prepare	 = ufshcd_suspend_prepare,
+	.prepare	 = ufs_hisi_suspend_prepare,
 	.complete	 = ufshcd_resume_complete,
 };
 
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 04cb67995750..115ea16f5a22 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -9707,7 +9707,27 @@ void ufshcd_resume_complete(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(ufshcd_resume_complete);
 
-int ufshcd_suspend_prepare(struct device *dev)
+static bool ufshcd_rpm_ok_for_spm(struct ufs_hba *hba)
+{
+	struct device *dev = &hba->sdev_ufs_device->sdev_gendev;
+	enum ufs_dev_pwr_mode dev_pwr_mode;
+	enum uic_link_state link_state;
+	unsigned long flags;
+	bool res;
+
+	spin_lock_irqsave(&dev->power.lock, flags);
+	dev_pwr_mode = ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl);
+	link_state = ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl);
+	res = pm_runtime_suspended(dev) &&
+	      hba->curr_dev_pwr_mode == dev_pwr_mode &&
+	      hba->uic_link_state == link_state &&
+	      !hba->dev_info.b_rpm_dev_flush_capable;
+	spin_unlock_irqrestore(&dev->power.lock, flags);
+
+	return res;
+}
+
+int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm)
 {
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 	int ret;
@@ -9719,15 +9739,30 @@ int ufshcd_suspend_prepare(struct device *dev)
 	 * Refer ufshcd_resume_complete()
 	 */
 	if (hba->sdev_ufs_device) {
-		ret = ufshcd_rpm_get_sync(hba);
-		if (ret < 0 && ret != -EACCES) {
-			ufshcd_rpm_put(hba);
-			return ret;
+		/* Prevent runtime suspend */
+		ufshcd_rpm_get_noresume(hba);
+		/*
+		 * Check if already runtime suspended in same state as system
+		 * suspend would be.
+		 */
+		if (!rpm_ok_for_spm || !ufshcd_rpm_ok_for_spm(hba)) {
+			/* RPM state is not ok for SPM, so runtime resume */
+			ret = ufshcd_rpm_resume(hba);
+			if (ret < 0 && ret != -EACCES) {
+				ufshcd_rpm_put(hba);
+				return ret;
+			}
 		}
 		hba->complete_put = true;
 	}
 	return 0;
 }
+EXPORT_SYMBOL_GPL(__ufshcd_suspend_prepare);
+
+int ufshcd_suspend_prepare(struct device *dev)
+{
+	return __ufshcd_suspend_prepare(dev, true);
+}
 EXPORT_SYMBOL_GPL(ufshcd_suspend_prepare);
 
 #ifdef CONFIG_PM_SLEEP
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 3f5dc6732fe1..b9492f300bd1 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -1199,6 +1199,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
 
 int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
 int ufshcd_suspend_prepare(struct device *dev);
+int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);
 void ufshcd_resume_complete(struct device *dev);
 
 /* Wrapper functions for safely calling variant operations */
@@ -1408,6 +1409,16 @@ static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
 	return pm_runtime_put_sync(&hba->sdev_ufs_device->sdev_gendev);
 }
 
+static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
+{
+	pm_runtime_get_noresume(&hba->sdev_ufs_device->sdev_gendev);
+}
+
+static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
+{
+	return pm_runtime_resume(&hba->sdev_ufs_device->sdev_gendev);
+}
+
 static inline int ufshcd_rpm_put(struct ufs_hba *hba)
 {
 	return pm_runtime_put(&hba->sdev_ufs_device->sdev_gendev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V8 1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-10-27 13:06 ` [PATCH V8 1/1] " Adrian Hunter
@ 2021-11-12  7:09   ` Adrian Hunter
  2021-11-23  6:34     ` Adrian Hunter
  2021-11-24 15:06   ` Bean Huo
  1 sibling, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2021-11-12  7:09 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Asutosh Das, Bart Van Assche, Kiwoong Kim,
	Manivannan Sadhasivam, Wei Li, linux-scsi

On 27/10/2021 16:06, Adrian Hunter wrote:
> If the UFS Device WLUN is runtime suspended and is in the same power
> mode, link state and b_rpm_dev_flush_capable (BKOP or WB buffer flush etc)
> state, then it can remain runtime suspended instead of being runtime
> resumed and then system suspended.
> 
> The following patch has cleared the way for that to happen:
>   scsi: core: pm: Only runtime resume if necessary
> 
> So amend the logic accordingly.
> 
> Note, the ufs-hisi driver uses different RPM and SPM, but it is made
> explicit by a new parameter to suspend prepare.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

Any more comments on this?

> ---
>  drivers/scsi/ufs/ufs-hisi.c |  8 ++++++-
>  drivers/scsi/ufs/ufshcd.c   | 45 ++++++++++++++++++++++++++++++++-----
>  drivers/scsi/ufs/ufshcd.h   | 11 +++++++++
>  3 files changed, 58 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-hisi.c b/drivers/scsi/ufs/ufs-hisi.c
> index 8c7e8d321746..ab1a7ebd89b1 100644
> --- a/drivers/scsi/ufs/ufs-hisi.c
> +++ b/drivers/scsi/ufs/ufs-hisi.c
> @@ -396,6 +396,12 @@ static int ufs_hisi_pwr_change_notify(struct ufs_hba *hba,
>  	return ret;
>  }
>  
> +static int ufs_hisi_suspend_prepare(struct device *dev)
> +{
> +	/* RPM and SPM are different. Refer ufs_hisi_suspend() */
> +	return __ufshcd_suspend_prepare(dev, false);
> +}
> +
>  static int ufs_hisi_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
>  	enum ufs_notify_change_status status)
>  {
> @@ -578,7 +584,7 @@ static int ufs_hisi_remove(struct platform_device *pdev)
>  static const struct dev_pm_ops ufs_hisi_pm_ops = {
>  	SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
>  	SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
> -	.prepare	 = ufshcd_suspend_prepare,
> +	.prepare	 = ufs_hisi_suspend_prepare,
>  	.complete	 = ufshcd_resume_complete,
>  };
>  
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 04cb67995750..115ea16f5a22 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -9707,7 +9707,27 @@ void ufshcd_resume_complete(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(ufshcd_resume_complete);
>  
> -int ufshcd_suspend_prepare(struct device *dev)
> +static bool ufshcd_rpm_ok_for_spm(struct ufs_hba *hba)
> +{
> +	struct device *dev = &hba->sdev_ufs_device->sdev_gendev;
> +	enum ufs_dev_pwr_mode dev_pwr_mode;
> +	enum uic_link_state link_state;
> +	unsigned long flags;
> +	bool res;
> +
> +	spin_lock_irqsave(&dev->power.lock, flags);
> +	dev_pwr_mode = ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl);
> +	link_state = ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl);
> +	res = pm_runtime_suspended(dev) &&
> +	      hba->curr_dev_pwr_mode == dev_pwr_mode &&
> +	      hba->uic_link_state == link_state &&
> +	      !hba->dev_info.b_rpm_dev_flush_capable;
> +	spin_unlock_irqrestore(&dev->power.lock, flags);
> +
> +	return res;
> +}
> +
> +int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm)
>  {
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
>  	int ret;
> @@ -9719,15 +9739,30 @@ int ufshcd_suspend_prepare(struct device *dev)
>  	 * Refer ufshcd_resume_complete()
>  	 */
>  	if (hba->sdev_ufs_device) {
> -		ret = ufshcd_rpm_get_sync(hba);
> -		if (ret < 0 && ret != -EACCES) {
> -			ufshcd_rpm_put(hba);
> -			return ret;
> +		/* Prevent runtime suspend */
> +		ufshcd_rpm_get_noresume(hba);
> +		/*
> +		 * Check if already runtime suspended in same state as system
> +		 * suspend would be.
> +		 */
> +		if (!rpm_ok_for_spm || !ufshcd_rpm_ok_for_spm(hba)) {
> +			/* RPM state is not ok for SPM, so runtime resume */
> +			ret = ufshcd_rpm_resume(hba);
> +			if (ret < 0 && ret != -EACCES) {
> +				ufshcd_rpm_put(hba);
> +				return ret;
> +			}
>  		}
>  		hba->complete_put = true;
>  	}
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(__ufshcd_suspend_prepare);
> +
> +int ufshcd_suspend_prepare(struct device *dev)
> +{
> +	return __ufshcd_suspend_prepare(dev, true);
> +}
>  EXPORT_SYMBOL_GPL(ufshcd_suspend_prepare);
>  
>  #ifdef CONFIG_PM_SLEEP
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 3f5dc6732fe1..b9492f300bd1 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -1199,6 +1199,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
>  
>  int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
>  int ufshcd_suspend_prepare(struct device *dev);
> +int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);
>  void ufshcd_resume_complete(struct device *dev);
>  
>  /* Wrapper functions for safely calling variant operations */
> @@ -1408,6 +1409,16 @@ static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
>  	return pm_runtime_put_sync(&hba->sdev_ufs_device->sdev_gendev);
>  }
>  
> +static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
> +{
> +	pm_runtime_get_noresume(&hba->sdev_ufs_device->sdev_gendev);
> +}
> +
> +static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
> +{
> +	return pm_runtime_resume(&hba->sdev_ufs_device->sdev_gendev);
> +}
> +
>  static inline int ufshcd_rpm_put(struct ufs_hba *hba)
>  {
>  	return pm_runtime_put(&hba->sdev_ufs_device->sdev_gendev);
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V8 1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-11-12  7:09   ` Adrian Hunter
@ 2021-11-23  6:34     ` Adrian Hunter
  2021-11-30  3:39       ` Martin K. Petersen
  0 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2021-11-23  6:34 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Asutosh Das, Bart Van Assche, Kiwoong Kim,
	Manivannan Sadhasivam, Wei Li, linux-scsi

On 12/11/2021 09:09, Adrian Hunter wrote:
> On 27/10/2021 16:06, Adrian Hunter wrote:
>> If the UFS Device WLUN is runtime suspended and is in the same power
>> mode, link state and b_rpm_dev_flush_capable (BKOP or WB buffer flush etc)
>> state, then it can remain runtime suspended instead of being runtime
>> resumed and then system suspended.
>>
>> The following patch has cleared the way for that to happen:
>>   scsi: core: pm: Only runtime resume if necessary
>>
>> So amend the logic accordingly.
>>
>> Note, the ufs-hisi driver uses different RPM and SPM, but it is made
>> explicit by a new parameter to suspend prepare.
>>
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>
> 
> Any more comments on this?

Seems like there are no objections, so can this be applied for 5.17 ?

> 
>> ---
>>  drivers/scsi/ufs/ufs-hisi.c |  8 ++++++-
>>  drivers/scsi/ufs/ufshcd.c   | 45 ++++++++++++++++++++++++++++++++-----
>>  drivers/scsi/ufs/ufshcd.h   | 11 +++++++++
>>  3 files changed, 58 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/scsi/ufs/ufs-hisi.c b/drivers/scsi/ufs/ufs-hisi.c
>> index 8c7e8d321746..ab1a7ebd89b1 100644
>> --- a/drivers/scsi/ufs/ufs-hisi.c
>> +++ b/drivers/scsi/ufs/ufs-hisi.c
>> @@ -396,6 +396,12 @@ static int ufs_hisi_pwr_change_notify(struct ufs_hba *hba,
>>  	return ret;
>>  }
>>  
>> +static int ufs_hisi_suspend_prepare(struct device *dev)
>> +{
>> +	/* RPM and SPM are different. Refer ufs_hisi_suspend() */
>> +	return __ufshcd_suspend_prepare(dev, false);
>> +}
>> +
>>  static int ufs_hisi_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
>>  	enum ufs_notify_change_status status)
>>  {
>> @@ -578,7 +584,7 @@ static int ufs_hisi_remove(struct platform_device *pdev)
>>  static const struct dev_pm_ops ufs_hisi_pm_ops = {
>>  	SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
>>  	SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
>> -	.prepare	 = ufshcd_suspend_prepare,
>> +	.prepare	 = ufs_hisi_suspend_prepare,
>>  	.complete	 = ufshcd_resume_complete,
>>  };
>>  
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index 04cb67995750..115ea16f5a22 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -9707,7 +9707,27 @@ void ufshcd_resume_complete(struct device *dev)
>>  }
>>  EXPORT_SYMBOL_GPL(ufshcd_resume_complete);
>>  
>> -int ufshcd_suspend_prepare(struct device *dev)
>> +static bool ufshcd_rpm_ok_for_spm(struct ufs_hba *hba)
>> +{
>> +	struct device *dev = &hba->sdev_ufs_device->sdev_gendev;
>> +	enum ufs_dev_pwr_mode dev_pwr_mode;
>> +	enum uic_link_state link_state;
>> +	unsigned long flags;
>> +	bool res;
>> +
>> +	spin_lock_irqsave(&dev->power.lock, flags);
>> +	dev_pwr_mode = ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl);
>> +	link_state = ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl);
>> +	res = pm_runtime_suspended(dev) &&
>> +	      hba->curr_dev_pwr_mode == dev_pwr_mode &&
>> +	      hba->uic_link_state == link_state &&
>> +	      !hba->dev_info.b_rpm_dev_flush_capable;
>> +	spin_unlock_irqrestore(&dev->power.lock, flags);
>> +
>> +	return res;
>> +}
>> +
>> +int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm)
>>  {
>>  	struct ufs_hba *hba = dev_get_drvdata(dev);
>>  	int ret;
>> @@ -9719,15 +9739,30 @@ int ufshcd_suspend_prepare(struct device *dev)
>>  	 * Refer ufshcd_resume_complete()
>>  	 */
>>  	if (hba->sdev_ufs_device) {
>> -		ret = ufshcd_rpm_get_sync(hba);
>> -		if (ret < 0 && ret != -EACCES) {
>> -			ufshcd_rpm_put(hba);
>> -			return ret;
>> +		/* Prevent runtime suspend */
>> +		ufshcd_rpm_get_noresume(hba);
>> +		/*
>> +		 * Check if already runtime suspended in same state as system
>> +		 * suspend would be.
>> +		 */
>> +		if (!rpm_ok_for_spm || !ufshcd_rpm_ok_for_spm(hba)) {
>> +			/* RPM state is not ok for SPM, so runtime resume */
>> +			ret = ufshcd_rpm_resume(hba);
>> +			if (ret < 0 && ret != -EACCES) {
>> +				ufshcd_rpm_put(hba);
>> +				return ret;
>> +			}
>>  		}
>>  		hba->complete_put = true;
>>  	}
>>  	return 0;
>>  }
>> +EXPORT_SYMBOL_GPL(__ufshcd_suspend_prepare);
>> +
>> +int ufshcd_suspend_prepare(struct device *dev)
>> +{
>> +	return __ufshcd_suspend_prepare(dev, true);
>> +}
>>  EXPORT_SYMBOL_GPL(ufshcd_suspend_prepare);
>>  
>>  #ifdef CONFIG_PM_SLEEP
>> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
>> index 3f5dc6732fe1..b9492f300bd1 100644
>> --- a/drivers/scsi/ufs/ufshcd.h
>> +++ b/drivers/scsi/ufs/ufshcd.h
>> @@ -1199,6 +1199,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
>>  
>>  int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
>>  int ufshcd_suspend_prepare(struct device *dev);
>> +int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);
>>  void ufshcd_resume_complete(struct device *dev);
>>  
>>  /* Wrapper functions for safely calling variant operations */
>> @@ -1408,6 +1409,16 @@ static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
>>  	return pm_runtime_put_sync(&hba->sdev_ufs_device->sdev_gendev);
>>  }
>>  
>> +static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
>> +{
>> +	pm_runtime_get_noresume(&hba->sdev_ufs_device->sdev_gendev);
>> +}
>> +
>> +static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
>> +{
>> +	return pm_runtime_resume(&hba->sdev_ufs_device->sdev_gendev);
>> +}
>> +
>>  static inline int ufshcd_rpm_put(struct ufs_hba *hba)
>>  {
>>  	return pm_runtime_put(&hba->sdev_ufs_device->sdev_gendev);
>>
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V8 1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-10-27 13:06 ` [PATCH V8 1/1] " Adrian Hunter
  2021-11-12  7:09   ` Adrian Hunter
@ 2021-11-24 15:06   ` Bean Huo
  1 sibling, 0 replies; 7+ messages in thread
From: Bean Huo @ 2021-11-24 15:06 UTC (permalink / raw)
  To: Adrian Hunter, Martin K . Petersen
  Cc: James E . J . Bottomley, Avri Altman, Alim Akhtar, Can Guo,
	Asutosh Das, Bart Van Assche, Kiwoong Kim, Manivannan Sadhasivam,
	Wei Li, linux-scsi

On Wed, 2021-10-27 at 16:06 +0300, Adrian Hunter wrote:
> If the UFS Device WLUN is runtime suspended and is in the same power
> 
> mode, link state and b_rpm_dev_flush_capable (BKOP or WB buffer flush
> etc)
> 
> state, then it can remain runtime suspended instead of being runtime
> 
> resumed and then system suspended.
> 
> 
> 
> The following patch has cleared the way for that to happen:
> 
>   scsi: core: pm: Only runtime resume if necessary
> 
> 
> 
> So amend the logic accordingly.
> 
> 
> 
> Note, the ufs-hisi driver uses different RPM and SPM, but it is made
> 
> explicit by a new parameter to suspend prepare.
> 
> 
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> 
> Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

Reviewed-by: Bean Huo <beanhuo@micron.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V8 1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-11-23  6:34     ` Adrian Hunter
@ 2021-11-30  3:39       ` Martin K. Petersen
  0 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2021-11-30  3:39 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, James E . J . Bottomley, Bean Huo,
	Avri Altman, Alim Akhtar, Can Guo, Asutosh Das, Bart Van Assche,
	Kiwoong Kim, Manivannan Sadhasivam, Wei Li, linux-scsi


Adrian,

> Seems like there are no objections, so can this be applied for 5.17 ?

Applied to 5.17/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V8 0/1] scsi: ufs: Let devices remain runtime suspended during system suspend
  2021-10-27 13:06 [PATCH V8 0/1] scsi: ufs: Let devices remain runtime suspended during system suspend Adrian Hunter
  2021-10-27 13:06 ` [PATCH V8 1/1] " Adrian Hunter
@ 2021-12-03  3:03 ` Martin K. Petersen
  1 sibling, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2021-12-03  3:03 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, Alim Akhtar, Wei Li, Avri Altman, Can Guo,
	linux-scsi, Bean Huo, Asutosh Das, Kiwoong Kim,
	Manivannan Sadhasivam, Bart Van Assche, James E . J . Bottomley

On Wed, 27 Oct 2021 16:06:13 +0300, Adrian Hunter wrote:

> UFS devices can remain runtime suspended at system suspend time,
> if the conditions are right.  Add support for that, first fixing
> the impediments.
> 
> 
> Changes in V8:
> 
> [...]

Applied to 5.17/scsi-queue, thanks!

[1/1] scsi: ufs: Let devices remain runtime suspended during system suspend
      https://git.kernel.org/mkp/scsi/c/ddba1cf7a506

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-03  3:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 13:06 [PATCH V8 0/1] scsi: ufs: Let devices remain runtime suspended during system suspend Adrian Hunter
2021-10-27 13:06 ` [PATCH V8 1/1] " Adrian Hunter
2021-11-12  7:09   ` Adrian Hunter
2021-11-23  6:34     ` Adrian Hunter
2021-11-30  3:39       ` Martin K. Petersen
2021-11-24 15:06   ` Bean Huo
2021-12-03  3:03 ` [PATCH V8 0/1] " Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).