Skip to contentSkip to conversation

Subject: [PATCH v3 0/2] Refactor ufshcd_setup_clocks() to remove param skip_ref_clk

PATCH Applied Can Guo 3 participants 9 messages Nov 26, 2020 – Dec 8, 2020

Subsystems (3)
lore
Share & tools
lore

Can Guo

author
#0 lore raw

v3 cover Subject: [PATCH v3 0/2] Refactor ufshcd_setup_clocks() to remove param skip_ref_clk

Allow vendor drivers to decide which clock should be kept on when clk gating or suspend disables clocks while link is active.

Change since v2:
- Fixed a typo in commit title
- Changed naming always_on_while_link_active to keep_link_active

Change since v1:
- Incorporated Stanley's idea which is to refactor func ufshcd_setup_clocks()

Can Guo (2):
scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk
scsi: ufs-qcom: Keep core_clk_unipro ON while link is active

 drivers/scsi/ufs/ufs-qcom.c      |  6 ++++++
 drivers/scsi/ufs/ufshcd-pltfrm.c |  2 ++
 drivers/scsi/ufs/ufshcd.c        | 29 +++++++++--------------------
 drivers/scsi/ufs/ufshcd.h        |  3 +++
 4 files changed, 20 insertions(+), 20 deletions(-)
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#1 lore raw

PATCH v3 1/2 scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk

Remove the param skip_ref_clk from __ufshcd_setup_clocks(), but keep a flag in struct ufs_clk_info to tell whether a clock can be disabled or not while the link is active.

---
 drivers/scsi/ufs/ufshcd-pltfrm.c |  2 ++
 drivers/scsi/ufs/ufshcd.c        | 29 +++++++++--------------------
 drivers/scsi/ufs/ufshcd.h        |  3 +++
 3 files changed, 14 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +2 -0
index 3db0af6..873ef14 100644
@@ -92,6 +92,8 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 		clki->min_freq = clkfreq[i];
 		clki->max_freq = clkfreq[i+1];
 		clki->name = kstrdup(name, GFP_KERNEL);
+		if (!strcmp(name, "ref_clk"))
+			clki->keep_link_active = true;
 		dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
 				clki->min_freq, clki->max_freq, clki->name);
 		list_add_tail(&clki->list, &hba->clk_list_head);
drivers/scsi/ufs/ufshcd.c +9 -20
index a7857f6..44254c9 100644
@@ -221,8 +221,6 @@ static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
 static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
 static void ufshcd_hba_exit(struct ufs_hba *hba);
 static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-				 bool skip_ref_clk);
 static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
 static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);
 static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
@@ -1707,11 +1705,7 @@ static void ufshcd_gate_work(struct work_struct *work)
 
 	ufshcd_disable_irq(hba);
 
-	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
 
 	/*
 	 * In case you are here to cancel this work the gating state
@@ -7990,8 +7984,7 @@ static int ufshcd_init_hba_vreg(struct ufs_hba *hba)
 	return 0;
 }
 
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-					bool skip_ref_clk)
+static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
 {
 	int ret = 0;
 	struct ufs_clk_info *clki;
@@ -8009,7 +8002,12 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
 
 	list_for_each_entry(clki, head, list) {
 		if (!IS_ERR_OR_NULL(clki->clk)) {
-			if (skip_ref_clk && !strcmp(clki->name, "ref_clk"))
+			/*
+			 * Don't disable clocks which are needed
+			 * to keep the link active.
+			 */
+			if (ufshcd_is_link_active(hba) &&
+			    clki->keep_link_active)
 				continue;
 
 			clk_state_changed = on ^ clki->enabled;
@@ -8054,11 +8052,6 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
 	return ret;
 }
 
-static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
-{
-	return  __ufshcd_setup_clocks(hba, on, false);
-}
-
 static int ufshcd_init_clocks(struct ufs_hba *hba)
 {
 	int ret = 0;
@@ -8577,11 +8570,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 	 */
 	ufshcd_disable_irq(hba);
 
-	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
 
 	if (ufshcd_is_clkgating_allowed(hba)) {
 		hba->clk_gating.state = CLKS_OFF;
drivers/scsi/ufs/ufshcd.h +3 -0
index 66e5338..6f0f2d4 100644
@@ -229,6 +229,8 @@ struct ufs_dev_cmd {
  * @max_freq: maximum frequency supported by the clock
  * @min_freq: min frequency that can be used for clock scaling
  * @curr_freq: indicates the current frequency that it is set to
+ * @keep_link_active: indicates that the clk should not be disabled if
+		      link is active
  * @enabled: variable to check against multiple enable/disable
  */
 struct ufs_clk_info {
@@ -238,6 +240,7 @@ struct ufs_clk_info {
 	u32 max_freq;
 	u32 min_freq;
 	u32 curr_freq;
+	bool keep_link_active;
 	bool enabled;
 };
 
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#5 lore raw

PATCH v3 2/2 scsi: ufs-qcom: Keep core_clk_unipro ON while link is active

In reply to Can Guo

If we want to disable clocks to save power but still keep the link active, core_clk_unipro, as same as ref_clk, should not be the one being disabled.

---
 drivers/scsi/ufs/ufs-qcom.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/scsi/ufs/ufs-qcom.c +6 -0
index f9d6ef3..8a7fc62 100644
@@ -977,6 +977,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct ufs_qcom_host *host;
 	struct resource *res;
+	struct ufs_clk_info *clki;
 
 	if (strlen(android_boot_dev) && strcmp(android_boot_dev, dev_name(dev)))
 		return -ENODEV;
@@ -1075,6 +1076,11 @@ static int ufs_qcom_init(struct ufs_hba *hba)
 		}
 	}
 
+	list_for_each_entry(clki, &hba->clk_list_head, list) {
+		if (!strcmp(clki->name, "core_clk_unipro"))
+			clki->keep_link_active = true;
+	}
+
 	err = ufs_qcom_init_lane_clks(host);
 	if (err)
 		goto out_variant_clear;
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#2 lore raw

Re: [PATCH v3 1/2] scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk

In reply to Can Guo
Quoted 116 lines · Can Guo

Remove the param skip_ref_clk from __ufshcd_setup_clocks(), but keep a flag in struct ufs_clk_info to tell whether a clock can be disabled or not while the link is active.

---
  drivers/scsi/ufs/ufshcd-pltfrm.c |  2 ++
  drivers/scsi/ufs/ufshcd.c        | 29 +++++++++--------------------
  drivers/scsi/ufs/ufshcd.h        |  3 +++
  3 files changed, 14 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +2 -0
index 3db0af6..873ef14 100644
@@ -92,6 +92,8 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
  		clki->min_freq = clkfreq[i];
  		clki->max_freq = clkfreq[i+1];
  		clki->name = kstrdup(name, GFP_KERNEL);
+		if (!strcmp(name, "ref_clk"))
+			clki->keep_link_active = true;
  		dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
  				clki->min_freq, clki->max_freq, clki->name);
  		list_add_tail(&clki->list, &hba->clk_list_head);
drivers/scsi/ufs/ufshcd.c +9 -20
index a7857f6..44254c9 100644
@@ -221,8 +221,6 @@ static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
  static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
  static void ufshcd_hba_exit(struct ufs_hba *hba);
  static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-				 bool skip_ref_clk);
  static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
  static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);
  static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
@@ -1707,11 +1705,7 @@ static void ufshcd_gate_work(struct work_struct *work)
 
  	ufshcd_disable_irq(hba);
 
-	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
 
  	/*
  	 * In case you are here to cancel this work the gating state
@@ -7990,8 +7984,7 @@ static int ufshcd_init_hba_vreg(struct ufs_hba *hba)
  	return 0;
  }
 
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-					bool skip_ref_clk)
+static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
  {
  	int ret = 0;
  	struct ufs_clk_info *clki;
@@ -8009,7 +8002,12 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
 
  	list_for_each_entry(clki, head, list) {
  		if (!IS_ERR_OR_NULL(clki->clk)) {
-			if (skip_ref_clk && !strcmp(clki->name, "ref_clk"))
+			/*
+			 * Don't disable clocks which are needed
+			 * to keep the link active.
+			 */
+			if (ufshcd_is_link_active(hba) &&
+			    clki->keep_link_active)
  				continue;
 
  			clk_state_changed = on ^ clki->enabled;
@@ -8054,11 +8052,6 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
  	return ret;
  }
 
-static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
-{
-	return  __ufshcd_setup_clocks(hba, on, false);
-}
-
  static int ufshcd_init_clocks(struct ufs_hba *hba)
  {
  	int ret = 0;
@@ -8577,11 +8570,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
  	 */
  	ufshcd_disable_irq(hba);
 
-	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
 
  	if (ufshcd_is_clkgating_allowed(hba)) {
  		hba->clk_gating.state = CLKS_OFF;
drivers/scsi/ufs/ufshcd.h +2 -0
index 66e5338..6f0f2d4 100644
@@ -229,6 +229,8 @@ struct ufs_dev_cmd {
   * @max_freq: maximum frequency supported by the clock
   * @min_freq: min frequency that can be used for clock scaling
   * @curr_freq: indicates the current frequency that it is set to
+ * @keep_link_active: indicates that the clk should not be disabled if
+		      link is active
   * @enabled: variable to check against multiple enable/disable
   */
  struct ufs_clk_info {

drivers/scsi/ufs/ufshcd.h struct ufs_clk_info { · line 243

Quoted 4 lines
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -238,6 +240,7 @@ struct ufs_clk_info {
  	u32 max_freq;
  	u32 min_freq;
  	u32 curr_freq;
+	bool keep_link_active;

Nitpick - How about 'always-on' instead of 'keep_link_active'?

Quoted 4 lines
drivers/scsi/ufs/ufshcd.h +0 -0
  	bool enabled;
  };
 
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Reviewed-by on v3 2/2
#6 lore raw

Re: [PATCH v3 2/2] scsi: ufs-qcom: Keep core_clk_unipro ON while link is active

In reply to Can Guo
Quoted 6 lines · Can Guo

If we want to disable clocks to save power but still keep the link active, core_clk_unipro, as same as ref_clk, should not be the one being disabled.

---

Quoted 28 lines
  drivers/scsi/ufs/ufs-qcom.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/scsi/ufs/ufs-qcom.c +6 -0
index f9d6ef3..8a7fc62 100644
@@ -977,6 +977,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
  	struct platform_device *pdev = to_platform_device(dev);
  	struct ufs_qcom_host *host;
  	struct resource *res;
+	struct ufs_clk_info *clki;
 
  	if (strlen(android_boot_dev) && strcmp(android_boot_dev, dev_name(dev)))
  		return -ENODEV;
@@ -1075,6 +1076,11 @@ static int ufs_qcom_init(struct ufs_hba *hba)
  		}
  	}
 
+	list_for_each_entry(clki, &hba->clk_list_head, list) {
+		if (!strcmp(clki->name, "core_clk_unipro"))
+			clki->keep_link_active = true;
+	}
+
  	err = ufs_qcom_init_lane_clks(host);
  	if (err)
  		goto out_variant_clear;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project
author
#3 lore raw

Re: [PATCH v3 1/2] scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk

In reply to Asutosh Das (asd)
Quoted 115 lines · Asutosh Das (asd)
Quoted 114 lines · Can Guo

Remove the param skip_ref_clk from __ufshcd_setup_clocks(), but keep a flag in struct ufs_clk_info to tell whether a clock can be disabled or not while the link is active.

---
  drivers/scsi/ufs/ufshcd-pltfrm.c |  2 ++
  drivers/scsi/ufs/ufshcd.c        | 29 +++++++++--------------------
  drivers/scsi/ufs/ufshcd.h        |  3 +++
  3 files changed, 14 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +2 -0
index 3db0af6..873ef14 100644
@@ -92,6 +92,8 @@ static int ufshcd_parse_clock_info(struct ufs_hba 
 *hba)
  		clki->min_freq = clkfreq[i];
  		clki->max_freq = clkfreq[i+1];
  		clki->name = kstrdup(name, GFP_KERNEL);
+		if (!strcmp(name, "ref_clk"))
+			clki->keep_link_active = true;
  		dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
  				clki->min_freq, clki->max_freq, clki->name);
  		list_add_tail(&clki->list, &hba->clk_list_head);
drivers/scsi/ufs/ufshcd.c +0 -2
index a7857f6..44254c9 100644
@@ -221,8 +221,6 @@ static int ufshcd_eh_host_reset_handler(struct 
 scsi_cmnd *cmd);
  static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
  static void ufshcd_hba_exit(struct ufs_hba *hba);
  static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-				 bool skip_ref_clk);
  static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
  static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);

static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba
*hba);

drivers/scsi/ufs/ufshcd.c +9 -14
@@ -1707,11 +1705,7 @@ static void ufshcd_gate_work(struct work_struct 
 *work)
    	ufshcd_disable_irq(hba);
  -	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
    	/*
  	 * In case you are here to cancel this work the gating state
@@ -7990,8 +7984,7 @@ static int ufshcd_init_hba_vreg(struct ufs_hba 
 *hba)
  	return 0;
  }
  -static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-					bool skip_ref_clk)
+static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
  {
  	int ret = 0;
  	struct ufs_clk_info *clki;
@@ -8009,7 +8002,12 @@ static int __ufshcd_setup_clocks(struct ufs_hba 
 *hba, bool on,
    	list_for_each_entry(clki, head, list) {
  		if (!IS_ERR_OR_NULL(clki->clk)) {
-			if (skip_ref_clk && !strcmp(clki->name, "ref_clk"))
+			/*
+			 * Don't disable clocks which are needed
+			 * to keep the link active.
+			 */
+			if (ufshcd_is_link_active(hba) &&
+			    clki->keep_link_active)
  				continue;
    			clk_state_changed = on ^ clki->enabled;
@@ -8054,11 +8052,6 @@ static int __ufshcd_setup_clocks(struct ufs_hba 
 *hba, bool on,
  	return ret;
  }
  -static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
-{
-	return  __ufshcd_setup_clocks(hba, on, false);
-}
-
  static int ufshcd_init_clocks(struct ufs_hba *hba)
  {
  	int ret = 0;
@@ -8577,11 +8570,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, 
 enum ufs_pm_op pm_op)
  	 */
  	ufshcd_disable_irq(hba);
  -	if (!ufshcd_is_link_active(hba))
-		ufshcd_setup_clocks(hba, false);
-	else
-		/* If link is active, device ref_clk can't be switched off */
-		__ufshcd_setup_clocks(hba, false, true);
+	ufshcd_setup_clocks(hba, false);
    	if (ufshcd_is_clkgating_allowed(hba)) {
  		hba->clk_gating.state = CLKS_OFF;
drivers/scsi/ufs/ufshcd.h +1 -0
index 66e5338..6f0f2d4 100644
@@ -229,6 +229,8 @@ struct ufs_dev_cmd {
   * @max_freq: maximum frequency supported by the clock
   * @min_freq: min frequency that can be used for clock scaling
   * @curr_freq: indicates the current frequency that it is set to
+ * @keep_link_active: indicates that the clk should not be disabled 

if

drivers/scsi/ufs/ufshcd.h +1 -0
+		      link is active
   * @enabled: variable to check against multiple enable/disable
   */
Quoted 8 lines

drivers/scsi/ufs/ufshcd.h struct ufs_clk_info { · line 243

Quoted 6 lines
  struct ufs_clk_info {
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -238,6 +240,7 @@ struct ufs_clk_info {
  	u32 max_freq;
  	u32 min_freq;
  	u32 curr_freq;
+	bool keep_link_active;

Nitpick - How about 'always-on' instead of 'keep_link_active'?

Hi Asutosh,

But it is not always-on, during suspend, it is on when rpm/spm-lvl is 1 and 2, off when rpm/spm-lvl is 3, 4 and 5, depending on the link state.

Thanks,

Can Guo.

Quoted 3 lines

drivers/scsi/ufs/ufshcd.h struct ufs_clk_info { · line 246

Quoted 3 lines
drivers/scsi/ufs/ufshcd.h +0 -0
  	bool enabled;
  };
 

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#7 lore raw
In reply to Can Guo

Can,

Quoted 2 lines

Allow vendor drivers to decide which clock should be kept on when clk gating or suspend disables clocks while link is active.

Applied to 5.11/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw

Re: [PATCH v3 1/2] scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk

In reply to Can Guo
Quoted 123 lines · Can Guo
Quoted 113 lines · Asutosh Das (asd)
Quoted 112 lines · Can Guo

Remove the param skip_ref_clk from __ufshcd_setup_clocks(), but keep a flag in struct ufs_clk_info to tell whether a clock can be disabled or not while the link is active.

---
  drivers/scsi/ufs/ufshcd-pltfrm.c |  2 ++ drivers/scsi/ufs/ufshcd.c        | 29 +++++++++-------------------- drivers/scsi/ufs/ufshcd.h        |  3 +++

  3 files changed, 14 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +2 -0
index 3db0af6..873ef14 100644
@@ -92,6 +92,8 @@ static int ufshcd_parse_clock_info(struct ufs_hba 
 *hba)
           clki->min_freq = clkfreq[i];
           clki->max_freq = clkfreq[i+1];
           clki->name = kstrdup(name, GFP_KERNEL);
+        if (!strcmp(name, "ref_clk"))
+            clki->keep_link_active = true;
           dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
                   clki->min_freq, clki->max_freq, clki->name);

          list_add_tail(&clki->list, &hba->clk_list_head);

drivers/scsi/ufs/ufshcd.c +0 -2
index a7857f6..44254c9 100644
@@ -221,8 +221,6 @@ static int ufshcd_eh_host_reset_handler(struct 
 scsi_cmnd *cmd);
   static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
   static void ufshcd_hba_exit(struct ufs_hba *hba);
   static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
-static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-                 bool skip_ref_clk);
   static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
   static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);

  static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);

drivers/scsi/ufs/ufshcd.c +2 -5
@@ -1707,11 +1705,7 @@ static void ufshcd_gate_work(struct 
 work_struct *work)
         ufshcd_disable_irq(hba);
   -    if (!ufshcd_is_link_active(hba))
-        ufshcd_setup_clocks(hba, false);
-    else
-        /* If link is active, device ref_clk can't be switched off */
-        __ufshcd_setup_clocks(hba, false, true);
+    ufshcd_setup_clocks(hba, false);
         /*
        * In case you are here to cancel this work the gating state
@@ -7990,8 +7984,7 @@ static int ufshcd_init_hba_vreg(struct ufs_hba 
 *hba)
       return 0;
   }
   -static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
-                    bool skip_ref_clk)
+static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
   {
       int ret = 0;

      struct ufs_clk_info *clki;

drivers/scsi/ufs/ufshcd.c +6 -5
@@ -8009,7 +8002,12 @@ static int __ufshcd_setup_clocks(struct 
 ufs_hba *hba, bool on,
         list_for_each_entry(clki, head, list) {
           if (!IS_ERR_OR_NULL(clki->clk)) {
-            if (skip_ref_clk && !strcmp(clki->name, "ref_clk"))
+            /*
+             * Don't disable clocks which are needed
+             * to keep the link active.
+             */
+            if (ufshcd_is_link_active(hba) &&
+                clki->keep_link_active)
                   continue;
                 clk_state_changed = on ^ clki->enabled;
@@ -8054,11 +8052,6 @@ static int __ufshcd_setup_clocks(struct 
 ufs_hba *hba, bool on,
       return ret;
   }
   -static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
-{
-    return  __ufshcd_setup_clocks(hba, on, false);
-}
-
   static int ufshcd_init_clocks(struct ufs_hba *hba)
   {

      int ret = 0;

drivers/scsi/ufs/ufshcd.c +1 -4
@@ -8577,11 +8570,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, 
 enum ufs_pm_op pm_op)
        */
       ufshcd_disable_irq(hba);
   -    if (!ufshcd_is_link_active(hba))
-        ufshcd_setup_clocks(hba, false);
-    else
-        /* If link is active, device ref_clk can't be switched off */
-        __ufshcd_setup_clocks(hba, false, true);
+    ufshcd_setup_clocks(hba, false);
         if (ufshcd_is_clkgating_allowed(hba)) {
           hba->clk_gating.state = CLKS_OFF;
drivers/scsi/ufs/ufshcd.h +2 -0
index 66e5338..6f0f2d4 100644
@@ -229,6 +229,8 @@ struct ufs_dev_cmd {
    * @max_freq: maximum frequency supported by the clock
    * @min_freq: min frequency that can be used for clock scaling
    * @curr_freq: indicates the current frequency that it is set to
+ * @keep_link_active: indicates that the clk should not be disabled if
+              link is active
    * @enabled: variable to check against multiple enable/disable
    */
Quoted 8 lines

drivers/scsi/ufs/ufshcd.h struct ufs_clk_info { · line 243

Quoted 6 lines
drivers/scsi/ufs/ufshcd.h +1 -0
   struct ufs_clk_info {
@@ -238,6 +240,7 @@ struct ufs_clk_info {
       u32 max_freq;
       u32 min_freq;
       u32 curr_freq;
+    bool keep_link_active;

Nitpick - How about 'always-on' instead of 'keep_link_active'?

Quoted 5 lines

Hi Asutosh,

But it is not always-on, during suspend, it is on when rpm/spm-lvl is 1 and 2, off when rpm/spm-lvl is 3, 4 and 5, depending on the link state.

Understood & agree.

Quoted 7 lines

Thanks,

Can Guo.

Quoted 3 lines
Quoted 3 lines
drivers/scsi/ufs/ufshcd.h +0 -0
       bool enabled;
   };
 
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#8 lore raw
In reply to Can Guo
Quoted 8 lines · Can Guo

Allow vendor drivers to decide which clock should be kept on when clk gating or suspend disables clocks while link is active.

Change since v2:
- Fixed a typo in commit title
- Changed naming always_on_while_link_active to keep_link_active

[...]

Applied to 5.11/scsi-queue, thanks!

[1/2] scsi: ufs: Refactor ufshcd_setup_clocks() to remove skip_ref_clk

      https://git.kernel.org/mkp/scsi/c/81309c247a4d
[2/2] scsi: ufs-qcom: Keep core_clk_unipro ON while link is active
      https://git.kernel.org/mkp/scsi/c/96f08cc5943c
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering