mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: core: Set default runtime/system PM levels before ufshcd_hba_init()
@ 2025-02-19 10:50 Manivannan Sadhasivam
  2025-02-19 20:36 ` Bart Van Assche
  0 siblings, 1 reply; 2+ messages in thread
From: Manivannan Sadhasivam @ 2025-02-19 10:50 UTC (permalink / raw)
  To: alim.akhtar, avri.altman, bvanassche, James.Bottomley, martin.petersen
  Cc: linux-scsi, linux-kernel, Manivannan Sadhasivam, Bao D . Nguyen

Commit bb9850704c04 ("scsi: ufs: core: Honor runtime/system PM levels if
set by host controller drivers") introduced the check for setting default
PM levels only if the levels are uninitialized by the host controller
drivers. But it missed the fact that the levels could initialized to 0
(UFS_PM_LVL_0) on purpose by the controller drivers. Even though none of
the drivers are doing so now, the logic should be fixed irrespectively.

So set the default levels unconditionally before calling ufshcd_hba_init()
API which initializes the controller drivers. It ensures that the
controller drivers could override the default levels if required.

Fixes: bb9850704c04 ("scsi: ufs: core: Honor runtime/system PM levels if set by host controller drivers")
Reported-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/ufs/core/ufshcd.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index cd404ade48dc..9a724ed860a6 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10429,6 +10429,21 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 	hba->irq = irq;
 	hba->vps = &ufs_hba_vps;
 
+	/*
+	 * Set the default power management level for runtime and system PM.
+	 * Host controller drivers can override them in their
+	 * 'ufs_hba_variant_ops::init' callback.
+	 *
+	 * Default power saving mode is to keep UFS link in Hibern8 state
+	 * and UFS device in sleep state.
+	 */
+	hba->rpm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state(
+						UFS_SLEEP_PWR_MODE,
+						UIC_LINK_HIBERN8_STATE);
+	hba->spm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state(
+						UFS_SLEEP_PWR_MODE,
+						UIC_LINK_HIBERN8_STATE);
+
 	err = ufshcd_hba_init(hba);
 	if (err)
 		goto out_error;
@@ -10542,21 +10557,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 		goto out_disable;
 	}
 
-	/*
-	 * Set the default power management level for runtime and system PM if
-	 * not set by the host controller drivers.
-	 * Default power saving mode is to keep UFS link in Hibern8 state
-	 * and UFS device in sleep state.
-	 */
-	if (!hba->rpm_lvl)
-		hba->rpm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state(
-						UFS_SLEEP_PWR_MODE,
-						UIC_LINK_HIBERN8_STATE);
-	if (!hba->spm_lvl)
-		hba->spm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state(
-						UFS_SLEEP_PWR_MODE,
-						UIC_LINK_HIBERN8_STATE);
-
 	INIT_DELAYED_WORK(&hba->rpm_dev_flush_recheck_work, ufshcd_rpm_dev_flush_recheck_work);
 	INIT_DELAYED_WORK(&hba->ufs_rtc_update_work, ufshcd_rtc_work);
 
-- 
2.25.1


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

* Re: [PATCH] scsi: ufs: core: Set default runtime/system PM levels before ufshcd_hba_init()
  2025-02-19 10:50 [PATCH] scsi: ufs: core: Set default runtime/system PM levels before ufshcd_hba_init() Manivannan Sadhasivam
@ 2025-02-19 20:36 ` Bart Van Assche
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2025-02-19 20:36 UTC (permalink / raw)
  To: Manivannan Sadhasivam, alim.akhtar, avri.altman, James.Bottomley,
	martin.petersen
  Cc: linux-scsi, linux-kernel, Bao D . Nguyen

On 2/19/25 2:50 AM, Manivannan Sadhasivam wrote:
> Commit bb9850704c04 ("scsi: ufs: core: Honor runtime/system PM levels if
> set by host controller drivers") introduced the check for setting default
> PM levels only if the levels are uninitialized by the host controller
> drivers. But it missed the fact that the levels could initialized to 0
> (UFS_PM_LVL_0) on purpose by the controller drivers. Even though none of
> the drivers are doing so now, the logic should be fixed irrespectively.
> 
> So set the default levels unconditionally before calling ufshcd_hba_init()
> API which initializes the controller drivers. It ensures that the
> controller drivers could override the default levels if required.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

end of thread, other threads:[~2025-02-19 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-19 10:50 [PATCH] scsi: ufs: core: Set default runtime/system PM levels before ufshcd_hba_init() Manivannan Sadhasivam
2025-02-19 20:36 ` Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®