* [PATCH v2] scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode
@ 2026-04-14 3:37 Wang Shuaiwei
0 siblings, 0 replies; 2+ messages in thread
From: Wang Shuaiwei @ 2026-04-14 3:37 UTC (permalink / raw)
To: Alim Akhtar, Avri Altman, Bart Van Assche,
James E . J . Bottomley, Martin K . Petersen, Peter Wang,
Bean Huo, Adrian Hunter
Cc: linux-scsi, wanghui33, Wang Shuaiwei
According to the UFS spec, the bRefClkFreq attribute can only be written
when both sub-links are in LS-MODE. However, in HS LSS mode with
resetmode = HS_MODE, if the UFS device's default bRefClkFreq value
differs from the host controller's dev_ref_clk_freq setting, the
write operation will fail.
To fix this issue, introduce ufshcd_get_op_mode() function to detect
the current link operational mode. Call ufshcd_set_dev_ref_clk() only
when both sub-links are in LS-MODE to ensure the attribute can be
written successfully.
Signed-off-by: Wang Shuaiwei <wangshuaiwei1@xiaomi.com>
---
v1->v2:
- modify the coding style
v1: https://lore.kernel.org/linux-scsi/20260413091126.1219552-1-wangshuaiwei1@xiaomi.com/
---
drivers/ufs/core/ufshcd.c | 29 +++++++++++++++++++++++++++--
include/ufs/unipro.h | 5 +++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9ceb6d6d479d..da38e97a199e 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -9103,6 +9103,30 @@ static void ufshcd_config_mcq(struct ufs_hba *hba)
hba->nutrs);
}
+/**
+ * ufshcd_get_op_mode - get UFS operating mode.
+ * @hba: per-adapter instance
+ *
+ * Use the PA_PWRMODE value to represent the operating mode of UFS.
+ *
+ */
+static enum ufs_op_mode ufshcd_get_op_mode(struct ufs_hba *hba)
+{
+ u32 mode;
+ u8 rx_mode;
+ u8 tx_mode;
+
+ ufshcd_dme_get(hba, UIC_ARG_MIB(PA_PWRMODE), &mode);
+ rx_mode = (mode >> PWRMODE_RX_OFFSET) & PWRMODE_MASK;
+ tx_mode = mode & PWRMODE_MASK;
+
+ if ((rx_mode == SLOW_MODE || rx_mode == SLOWAUTO_MODE) &&
+ (tx_mode == SLOW_MODE || tx_mode == SLOWAUTO_MODE))
+ return LS_MODE;
+
+ return HS_MODE;
+}
+
static int ufshcd_post_device_init(struct ufs_hba *hba)
{
int ret;
@@ -9119,11 +9143,12 @@ static int ufshcd_post_device_init(struct ufs_hba *hba)
return 0;
/*
- * Set the right value to bRefClkFreq before attempting to
+ * Set the right value to bRefClkFreq in LS_MODE before attempting to
* switch to HS gears.
*/
- if (hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL)
+ if (ufshcd_get_op_mode(hba) == LS_MODE && hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL)
ufshcd_set_dev_ref_clk(hba);
+
/* Gear up to HS gear. */
ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info);
if (ret) {
diff --git a/include/ufs/unipro.h b/include/ufs/unipro.h
index 59de737490ca..3858ed13b2f3 100644
--- a/include/ufs/unipro.h
+++ b/include/ufs/unipro.h
@@ -198,6 +198,11 @@
#define DME_LocalTC0ReplayTimeOutVal 0xD042
#define DME_LocalAFC0ReqTimeOutVal 0xD043
+enum ufs_op_mode {
+ LS_MODE = 1,
+ HS_MODE = 2,
+};
+
/* PA power modes */
enum ufs_pa_pwr_mode {
FAST_MODE = 1,
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode
[not found] <1776153767068194.12.seg@mailgw02.mediatek.com>
@ 2026-04-15 2:40 ` Peter Wang (王信友)
0 siblings, 0 replies; 2+ messages in thread
From: Peter Wang (王信友) @ 2026-04-15 2:40 UTC (permalink / raw)
To: avri.altman@wdc.com, beanhuo@micron.com, wangshuaiwei1@xiaomi.com,
bvanassche@acm.org, adrian.hunter@intel.com,
alim.akhtar@samsung.com, James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, wanghui33@xiaomi.com
On Tue, 2026-04-14 at 11:37 +0800, Wang Shuaiwei wrote:
> According to the UFS spec, the bRefClkFreq attribute can only be
> written
> when both sub-links are in LS-MODE. However, in HS LSS mode with
> resetmode = HS_MODE, if the UFS device's default bRefClkFreq value
> differs from the host controller's dev_ref_clk_freq setting, the
> write operation will fail.
>
> To fix this issue, introduce ufshcd_get_op_mode() function to detect
> the current link operational mode. Call ufshcd_set_dev_ref_clk() only
> when both sub-links are in LS-MODE to ensure the attribute can be
> written successfully.
>
> Signed-off-by: Wang Shuaiwei <wangshuaiwei1@xiaomi.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-15 2:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1776153767068194.12.seg@mailgw02.mediatek.com>
2026-04-15 2:40 ` [PATCH v2] scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode Peter Wang (王信友)
2026-04-14 3:37 Wang Shuaiwei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox