linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Bug fixes for UFS multi-frequency scaling on Qcom platform
@ 2025-05-02  4:24 Ziqi Chen
  2025-05-02  4:24 ` [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear() Ziqi Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ziqi Chen @ 2025-05-02  4:24 UTC (permalink / raw)
  To: quic_cang, bvanassche, mani, beanhuo, avri.altman, junwoo80.lee,
	martin.petersen, quic_ziqichen, quic_nguyenb, quic_nitirawa,
	quic_rampraka, neil.armstrong, luca.weiss, konrad.dybcio
  Cc: linux-arm-msm, linux-scsi

This series fixes a few corner cases introduced by multi-frequency scaling feature
on some old Qcom platforms design.

1. On some platforms, the frequency tables for unipro clock and the core clock are different,
   which has led to errors when handling the unipro clock.

2. On some platforms, the maximum gear supported by the host may exceed the maximum gear
   supported by connected UFS device. Therefore, this should be taken into account when
   find mapped gear for frequency.

This series has been tested on below platforms -
sm8550 mtp + UFS3.1
SM8650 MTP + UFS3.1
QCS6490 BR3GEN2 + UFS2.2

For change "scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear()"
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on RB3GEN2

For change "scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq"
           "scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path"
The original pathes of these two changes are tested by: Luca Weiss <luca.weiss@fairphone.com> on
SM6350, but we have reworked the code logic later.


Can Guo (2):
  scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq
  scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path

Ziqi Chen (1):
  scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear()

 drivers/ufs/host/ufs-qcom.c | 134 +++++++++++++++++++++++++++---------
 1 file changed, 103 insertions(+), 31 deletions(-)

-- 
2.34.1


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

* [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear()
  2025-05-02  4:24 [PATCH 0/3] Bug fixes for UFS multi-frequency scaling on Qcom platform Ziqi Chen
@ 2025-05-02  4:24 ` Ziqi Chen
  2025-05-02  5:10   ` Avri Altman
  2025-05-02  4:24 ` [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq Ziqi Chen
  2025-05-02  4:24 ` [PATCH 3/3] scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path Ziqi Chen
  2 siblings, 1 reply; 8+ messages in thread
From: Ziqi Chen @ 2025-05-02  4:24 UTC (permalink / raw)
  To: quic_cang, bvanassche, mani, beanhuo, avri.altman, junwoo80.lee,
	martin.petersen, quic_ziqichen, quic_nguyenb, quic_nitirawa,
	quic_rampraka, neil.armstrong, luca.weiss, konrad.dybcio
  Cc: linux-arm-msm, linux-scsi, Manivannan Sadhasivam,
	James E.J. Bottomley, open list

The vop freq_to_gear() may return a gear greater than the negotiated max
gear, return the negotiated max gear if the mapped gear is greater than it.

Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com>
---
 drivers/ufs/host/ufs-qcom.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 46cca52aa6f1..f5ea703d8ef5 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -1938,9 +1938,11 @@ static u32 ufs_qcom_freq_to_gear_speed(struct ufs_hba *hba, unsigned long freq)
 		break;
 	default:
 		dev_err(hba->dev, "%s: Unsupported clock freq : %lu\n", __func__, freq);
-		break;
+		return gear;
 	}
 
+	gear = min_t(u32, gear, hba->max_pwr_info.info.gear_rx);
+
 	return gear;
 }
 
-- 
2.34.1


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

* [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq
  2025-05-02  4:24 [PATCH 0/3] Bug fixes for UFS multi-frequency scaling on Qcom platform Ziqi Chen
  2025-05-02  4:24 ` [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear() Ziqi Chen
@ 2025-05-02  4:24 ` Ziqi Chen
  2025-05-02  5:13   ` Avri Altman
  2025-05-02  4:24 ` [PATCH 3/3] scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path Ziqi Chen
  2 siblings, 1 reply; 8+ messages in thread
From: Ziqi Chen @ 2025-05-02  4:24 UTC (permalink / raw)
  To: quic_cang, bvanassche, mani, beanhuo, avri.altman, junwoo80.lee,
	martin.petersen, quic_ziqichen, quic_nguyenb, quic_nitirawa,
	quic_rampraka, neil.armstrong, luca.weiss, konrad.dybcio
  Cc: linux-arm-msm, linux-scsi, Manivannan Sadhasivam,
	James E.J. Bottomley, open list

From: Can Guo <quic_cang@quicinc.com>

On some platforms, the devfreq OPP freq may be different than the unipro
core clock freq. Implement ufs_qcom_opp_freq_to_clk_freq() and use it to
find the unipro core clk freq.

Signed-off-by: Can Guo <quic_cang@quicinc.com>
Co-developed-by: Ziqi Chen <quic_ziqichen@quicinc.com>
Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com>
---
 drivers/ufs/host/ufs-qcom.c | 81 ++++++++++++++++++++++++++++++++-----
 1 file changed, 71 insertions(+), 10 deletions(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index f5ea703d8ef5..00ca0b577c96 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -99,7 +99,9 @@ static const struct __ufs_qcom_bw_table {
 };
 
 static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host);
-static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, unsigned long freq);
+static unsigned long ufs_qcom_opp_freq_to_clk_freq(struct ufs_hba *hba, unsigned long freq,
+												   char *name);
+static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, bool is_scale_up, unsigned long freq);
 
 static struct ufs_qcom_host *rcdev_to_ufs_host(struct reset_controller_dev *rcd)
 {
@@ -633,7 +635,7 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
 			return -EINVAL;
 		}
 
-		err = ufs_qcom_set_core_clk_ctrl(hba, ULONG_MAX);
+		err = ufs_qcom_set_core_clk_ctrl(hba, true, ULONG_MAX);
 		if (err)
 			dev_err(hba->dev, "cfg core clk ctrl failed\n");
 		/*
@@ -1352,29 +1354,46 @@ static int ufs_qcom_set_clk_40ns_cycles(struct ufs_hba *hba,
 	return ufshcd_dme_set(hba, UIC_ARG_MIB(PA_VS_CORE_CLK_40NS_CYCLES), reg);
 }
 
-static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, unsigned long freq)
+static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, bool is_scale_up, unsigned long freq)
 {
 	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
 	struct list_head *head = &hba->clk_list_head;
 	struct ufs_clk_info *clki;
 	u32 cycles_in_1us = 0;
 	u32 core_clk_ctrl_reg;
+	unsigned long clk_freq;
 	int err;
 
+	if (hba->use_pm_opp) {
+		clk_freq = ufs_qcom_opp_freq_to_clk_freq(hba, freq, "core_clk_unipro");
+		if (clk_freq) {
+			cycles_in_1us = ceil(clk_freq, HZ_PER_MHZ);
+			goto set_core_clk_ctrl;
+		}
+	}
+
 	list_for_each_entry(clki, head, list) {
 		if (!IS_ERR_OR_NULL(clki->clk) &&
 		    !strcmp(clki->name, "core_clk_unipro")) {
-			if (!clki->max_freq)
+			if (!clki->max_freq) {
 				cycles_in_1us = 150; /* default for backwards compatibility */
-			else if (freq == ULONG_MAX)
+				break;
+			}
+
+			if (freq == ULONG_MAX) {
 				cycles_in_1us = ceil(clki->max_freq, HZ_PER_MHZ);
-			else
-				cycles_in_1us = ceil(freq, HZ_PER_MHZ);
+				break;
+			}
 
+			if (is_scale_up)
+				cycles_in_1us = ceil(clki->max_freq, HZ_PER_MHZ);
+			else
+				cycles_in_1us = ceil(clk_get_rate(clki->clk), HZ_PER_MHZ);
 			break;
 		}
 	}
 
+set_core_clk_ctrl:
 	err = ufshcd_dme_get(hba,
 			    UIC_ARG_MIB(DME_VS_CORE_CLK_CTRL),
 			    &core_clk_ctrl_reg);
@@ -1417,7 +1436,7 @@ static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba, unsigned long f
 		return ret;
 	}
 	/* set unipro core clock attributes and clear clock divider */
-	return ufs_qcom_set_core_clk_ctrl(hba, freq);
+	return ufs_qcom_set_core_clk_ctrl(hba, true, freq);
 }
 
 static int ufs_qcom_clk_scale_up_post_change(struct ufs_hba *hba)
@@ -1449,7 +1468,7 @@ static int ufs_qcom_clk_scale_down_pre_change(struct ufs_hba *hba)
 static int ufs_qcom_clk_scale_down_post_change(struct ufs_hba *hba, unsigned long freq)
 {
 	/* set unipro core clock attributes and clear clock divider */
-	return ufs_qcom_set_core_clk_ctrl(hba, freq);
+	return ufs_qcom_set_core_clk_ctrl(hba, false, freq);
 }
 
 static int ufs_qcom_clk_scale_notify(struct ufs_hba *hba, bool scale_up,
@@ -1914,11 +1933,53 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba)
 	return ret;
 }
 
+static unsigned long ufs_qcom_opp_freq_to_clk_freq(struct ufs_hba *hba,
+												   unsigned long freq, char *name)
+{
+	struct ufs_clk_info *clki;
+	struct dev_pm_opp *opp;
+	unsigned long clk_freq;
+	int idx = 0;
+	bool found = false;
+
+	opp = dev_pm_opp_find_freq_exact_indexed(hba->dev, freq, 0, true);
+	if (IS_ERR(opp)) {
+		dev_err(hba->dev, "Failed to find OPP for exact frequency %lu\n", freq);
+		return 0;
+	}
+
+	list_for_each_entry(clki, &hba->clk_list_head, list) {
+		if (!strcmp(clki->name, name)) {
+			found = true;
+			break;
+		}
+
+		idx++;
+	}
+
+	if (!found) {
+		dev_err(hba->dev, "Failed to find clock '%s' in clk list\n", name);
+		dev_pm_opp_put(opp);
+		return 0;
+	}
+
+	clk_freq = dev_pm_opp_get_freq_indexed(opp, idx);
+
+	dev_pm_opp_put(opp);
+
+	return clk_freq;
+}
+
 static u32 ufs_qcom_freq_to_gear_speed(struct ufs_hba *hba, unsigned long freq)
 {
 	u32 gear = 0;
+	unsigned long unipro_freq;
+
+	if (!hba->use_pm_opp)
+		return gear;
 
-	switch (freq) {
+	unipro_freq = ufs_qcom_opp_freq_to_clk_freq(hba, freq, "core_clk_unipro");
+	switch (unipro_freq) {
 	case 403000000:
 		gear = UFS_HS_G5;
 		break;
-- 
2.34.1


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

* [PATCH 3/3] scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path
  2025-05-02  4:24 [PATCH 0/3] Bug fixes for UFS multi-frequency scaling on Qcom platform Ziqi Chen
  2025-05-02  4:24 ` [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear() Ziqi Chen
  2025-05-02  4:24 ` [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq Ziqi Chen
@ 2025-05-02  4:24 ` Ziqi Chen
  2 siblings, 0 replies; 8+ messages in thread
From: Ziqi Chen @ 2025-05-02  4:24 UTC (permalink / raw)
  To: quic_cang, bvanassche, mani, beanhuo, avri.altman, junwoo80.lee,
	martin.petersen, quic_ziqichen, quic_nguyenb, quic_nitirawa,
	quic_rampraka, neil.armstrong, luca.weiss, konrad.dybcio
  Cc: linux-arm-msm, linux-scsi, Manivannan Sadhasivam,
	James E.J. Bottomley, open list

From: Can Guo <quic_cang@quicinc.com>

ufs_qcom_cfg_timers() is clock freq dependent like ufs_qcom_set_core_clk_
ctrl(), hence move ufs_qcom_cfg_timers() call to clock scaling path. In
addition, do not assume the devfreq OPP freq is always the 'core_clock'
freq although 'core_clock' is the first clock phandle in device tree, use
ufs_qcom_opp_freq_to_clk_freq() to find the core clk freq.

Signed-off-by: Can Guo <quic_cang@quicinc.com>
Co-developed-by: Ziqi Chen <quic_ziqichen@quicinc.com>
Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com>
---
 drivers/ufs/host/ufs-qcom.c | 49 ++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 00ca0b577c96..895972bf44c0 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -576,13 +576,14 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,
  *
  * @hba: host controller instance
  * @is_pre_scale_up: flag to check if pre scale up condition.
+ * @freq: target opp freq
  * Return: zero for success and non-zero in case of a failure.
  */
-static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up)
+static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up, unsigned long freq)
 {
 	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
 	struct ufs_clk_info *clki;
-	unsigned long core_clk_rate = 0;
+	unsigned long clk_freq = 0;
 	u32 core_clk_cycles_per_us;
 
 	/*
@@ -594,22 +595,34 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up)
 	if (host->hw_ver.major < 4 && !ufshcd_is_intr_aggr_allowed(hba))
 		return 0;
 
+	if (hba->use_pm_opp) {
+		clk_freq = ufs_qcom_opp_freq_to_clk_freq(hba, freq, "core_clk");
+		if (clk_freq)
+			goto cfg_timers;
+	}
+
 	list_for_each_entry(clki, &hba->clk_list_head, list) {
 		if (!strcmp(clki->name, "core_clk")) {
+			if (freq == ULONG_MAX) {
+				clk_freq = clki->max_freq;
+				break;
+			}
+
 			if (is_pre_scale_up)
-				core_clk_rate = clki->max_freq;
+				clk_freq = clki->max_freq;
 			else
-				core_clk_rate = clk_get_rate(clki->clk);
+				clk_freq = clk_get_rate(clki->clk);
 			break;
 		}
 
 	}
 
+cfg_timers:
 	/* If frequency is smaller than 1MHz, set to 1MHz */
-	if (core_clk_rate < DEFAULT_CLK_RATE_HZ)
-		core_clk_rate = DEFAULT_CLK_RATE_HZ;
+	if (clk_freq < DEFAULT_CLK_RATE_HZ)
+		clk_freq = DEFAULT_CLK_RATE_HZ;
 
-	core_clk_cycles_per_us = core_clk_rate / USEC_PER_SEC;
+	core_clk_cycles_per_us = clk_freq / USEC_PER_SEC;
 	if (ufshcd_readl(hba, REG_UFS_SYS1CLK_1US) != core_clk_cycles_per_us) {
 		ufshcd_writel(hba, core_clk_cycles_per_us, REG_UFS_SYS1CLK_1US);
 		/*
@@ -629,7 +642,7 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
 
 	switch (status) {
 	case PRE_CHANGE:
-		if (ufs_qcom_cfg_timers(hba, false)) {
+		if (ufs_qcom_cfg_timers(hba, false, ULONG_MAX)) {
 			dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
 				__func__);
 			return -EINVAL;
@@ -885,17 +898,6 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba,
 		}
 		break;
 	case POST_CHANGE:
-		if (ufs_qcom_cfg_timers(hba, false)) {
-			dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
-				__func__);
-			/*
-			 * we return error code at the end of the routine,
-			 * but continue to configure UFS_PHY_TX_LANE_ENABLE
-			 * and bus voting as usual
-			 */
-			ret = -EINVAL;
-		}
-
 		/* cache the power mode parameters to use internally */
 		memcpy(&host->dev_req_params,
 				dev_req_params, sizeof(*dev_req_params));
@@ -1430,7 +1432,7 @@ static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba, unsigned long f
 {
 	int ret;
 
-	ret = ufs_qcom_cfg_timers(hba, true);
+	ret = ufs_qcom_cfg_timers(hba, true, freq);
 	if (ret) {
 		dev_err(hba->dev, "%s ufs cfg timer failed\n", __func__);
 		return ret;
@@ -1467,6 +1469,13 @@ static int ufs_qcom_clk_scale_down_pre_change(struct ufs_hba *hba)
 
 static int ufs_qcom_clk_scale_down_post_change(struct ufs_hba *hba, unsigned long freq)
 {
+	int ret;
+
+	ret = ufs_qcom_cfg_timers(hba, false, freq);
+	if (ret) {
+		dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",	__func__);
+		return ret;
+	}
 	/* set unipro core clock attributes and clear clock divider */
 	return ufs_qcom_set_core_clk_ctrl(hba, false, freq);
 }
-- 
2.34.1


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

* RE: [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear()
  2025-05-02  4:24 ` [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear() Ziqi Chen
@ 2025-05-02  5:10   ` Avri Altman
  2025-05-06  4:10     ` Ziqi Chen
  0 siblings, 1 reply; 8+ messages in thread
From: Avri Altman @ 2025-05-02  5:10 UTC (permalink / raw)
  To: Ziqi Chen, quic_cang@quicinc.com, bvanassche@acm.org,
	mani@kernel.org, beanhuo@micron.com, avri.altman@wdc.com,
	junwoo80.lee@samsung.com, martin.petersen@oracle.com,
	quic_nguyenb@quicinc.com, quic_nitirawa@quicinc.com,
	quic_rampraka@quicinc.com, neil.armstrong@linaro.org,
	luca.weiss@fairphone.com, konrad.dybcio@oss.qualcomm.com
  Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org,
	Manivannan Sadhasivam, James E.J. Bottomley, open list

> The vop freq_to_gear() may return a gear greater than the negotiated max
> gear, return the negotiated max gear if the mapped gear is greater than it.
> 
> Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com>
> ---
>  drivers/ufs/host/ufs-qcom.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index
> 46cca52aa6f1..f5ea703d8ef5 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -1938,9 +1938,11 @@ static u32 ufs_qcom_freq_to_gear_speed(struct
> ufs_hba *hba, unsigned long freq)
>  		break;
>  	default:
>  		dev_err(hba->dev, "%s: Unsupported clock freq : %lu\n",
> __func__, freq);
> -		break;
> +		return gear;
Mayby return 0 so it is clear that you are not returning a gear

>  	}
> 
> +	gear = min_t(u32, gear, hba->max_pwr_info.info.gear_rx);
return min_t(u32, gear, hba->max_pwr_info.info.gear_rx);

Thanks,
Avri
> +
>  	return gear;
>  }
> 
> --
> 2.34.1
> 


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

* RE: [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq
  2025-05-02  4:24 ` [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq Ziqi Chen
@ 2025-05-02  5:13   ` Avri Altman
  2025-05-06  4:07     ` Ziqi Chen
  0 siblings, 1 reply; 8+ messages in thread
From: Avri Altman @ 2025-05-02  5:13 UTC (permalink / raw)
  To: Ziqi Chen, quic_cang@quicinc.com, bvanassche@acm.org,
	mani@kernel.org, beanhuo@micron.com, avri.altman@wdc.com,
	junwoo80.lee@samsung.com, martin.petersen@oracle.com,
	quic_nguyenb@quicinc.com, quic_nitirawa@quicinc.com,
	quic_rampraka@quicinc.com, neil.armstrong@linaro.org,
	luca.weiss@fairphone.com, konrad.dybcio@oss.qualcomm.com
  Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org,
	Manivannan Sadhasivam, James E.J. Bottomley, open list

> +			cycles_in_1us = ceil(clk_freq, HZ_PER_MHZ);
Does ceil() is in fact DIV_ROUND_UP?

Thanks,
Avri

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

* Re: [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq
  2025-05-02  5:13   ` Avri Altman
@ 2025-05-06  4:07     ` Ziqi Chen
  0 siblings, 0 replies; 8+ messages in thread
From: Ziqi Chen @ 2025-05-06  4:07 UTC (permalink / raw)
  To: Avri Altman, quic_cang@quicinc.com, bvanassche@acm.org,
	mani@kernel.org, beanhuo@micron.com, avri.altman@wdc.com,
	junwoo80.lee@samsung.com, martin.petersen@oracle.com,
	quic_nguyenb@quicinc.com, quic_nitirawa@quicinc.com,
	quic_rampraka@quicinc.com, neil.armstrong@linaro.org,
	luca.weiss@fairphone.com, konrad.dybcio@oss.qualcomm.com
  Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org,
	Manivannan Sadhasivam, James E.J. Bottomley, open list


Hi Avri,

On 5/2/2025 1:13 PM, Avri Altman wrote:
>> +			cycles_in_1us = ceil(clk_freq, HZ_PER_MHZ);
> Does ceil() is in fact DIV_ROUND_UP?
>
Yes , Both of these macro definitions, ceil(freq, div) and
DIV_ROUND_UP(n, d), are used to implement the function of rounding up
upwards by different implementation methods.

Ziqi,

> Thanks,
> Avri


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

* Re: [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear()
  2025-05-02  5:10   ` Avri Altman
@ 2025-05-06  4:10     ` Ziqi Chen
  0 siblings, 0 replies; 8+ messages in thread
From: Ziqi Chen @ 2025-05-06  4:10 UTC (permalink / raw)
  To: Avri Altman, quic_cang@quicinc.com, bvanassche@acm.org,
	mani@kernel.org, beanhuo@micron.com, avri.altman@wdc.com,
	junwoo80.lee@samsung.com, martin.petersen@oracle.com,
	quic_nguyenb@quicinc.com, quic_nitirawa@quicinc.com,
	quic_rampraka@quicinc.com, neil.armstrong@linaro.org,
	luca.weiss@fairphone.com, konrad.dybcio@oss.qualcomm.com
  Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org,
	Manivannan Sadhasivam, James E.J. Bottomley, open list

Hi Avri,

On 5/2/2025 1:10 PM, Avri Altman wrote:
>> The vop freq_to_gear() may return a gear greater than the negotiated max
>> gear, return the negotiated max gear if the mapped gear is greater than it.
>>
>> Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
>> Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com>
>> ---
>>   drivers/ufs/host/ufs-qcom.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index
>> 46cca52aa6f1..f5ea703d8ef5 100644
>> --- a/drivers/ufs/host/ufs-qcom.c
>> +++ b/drivers/ufs/host/ufs-qcom.c
>> @@ -1938,9 +1938,11 @@ static u32 ufs_qcom_freq_to_gear_speed(struct
>> ufs_hba *hba, unsigned long freq)
>>   		break;
>>   	default:
>>   		dev_err(hba->dev, "%s: Unsupported clock freq : %lu\n",
>> __func__, freq);
>> -		break;
>> +		return gear;
> Mayby return 0 so it is clear that you are not returning a gear
> 
>>   	}
>>
>> +	gear = min_t(u32, gear, hba->max_pwr_info.info.gear_rx);
> return min_t(u32, gear, hba->max_pwr_info.info.gear_rx);
> 

Thanks, the way you suggested is more concise. I will update and use 
this way.

Ziqi

> Thanks,
> Avri
>> +
>>   	return gear;
>>   }
>>
>> --
>> 2.34.1
>>
> 


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

end of thread, other threads:[~2025-05-06  4:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02  4:24 [PATCH 0/3] Bug fixes for UFS multi-frequency scaling on Qcom platform Ziqi Chen
2025-05-02  4:24 ` [PATCH 1/3] scsi: ufs: qcom: Check gear against max gear in vop freq_to_gear() Ziqi Chen
2025-05-02  5:10   ` Avri Altman
2025-05-06  4:10     ` Ziqi Chen
2025-05-02  4:24 ` [PATCH 2/3] scsi: ufs: qcom: Map devfreq OPP freq to UniPro Core Clock freq Ziqi Chen
2025-05-02  5:13   ` Avri Altman
2025-05-06  4:07     ` Ziqi Chen
2025-05-02  4:24 ` [PATCH 3/3] scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path Ziqi Chen

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).