Skip to contentSkip to conversation

scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode

PATCH Peter Wang (王信友) 2 participants 5 messages Apr 14 – Apr 15 3 messages not in the archive SCSI

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 7 lines · 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.

Quoted 6 lines

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.

Hi Shuaiwei,

I'm a bit confused about how this situation could happen. Once it is set to HS-LSS, the ref-clk should already be correct. Why would we still need to set bRefClkFreq separately? In fact, if bRefClkFreq is not set correctly, the UFS host wouldn't be able to communicate with the device at all, much less set the bRefClkFreq.

Thanks.
Peter

#2 lore raw
Quoted 15 lines · Peter Wang
Quoted 7 lines · 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.

Quoted 6 lines

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.

Quoted 8 lines

Hi Shuaiwei,

I'm a bit confused about how this situation could happen. Once it is set to HS-LSS, the ref-clk should already be correct. Why would we still need to set bRefClkFreq separately? In fact, if bRefClkFreq is not set correctly, the UFS host wouldn't be able to communicate with the device at all, much less set the bRefClkFreq.

Hi Peter,

In HS-LSS mode, the ref_clk frequency is automatically detected by the UFS device. The bRefClkFreq attribute is ignored in this mode and should not be write in this mode.

However, the current code does not properly handle this scenario when calling ufshcd_set_dev_ref_clk(). If the UFS device's default bRefClkFreq value differs from the host controller's dev_ref_clk_freq, the function will attempt to write the bRefClkFreq attribute, which will inevitably fail.

So, fix this by adding a check to skip ufshcd_set_dev_ref_clk() when operating in HS-LSS mode.

Thanks,
Wang Shuaiwei.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

On Tue, 2026-04-14 at 14:43 +0800, Wang Shuaiwei wrote

Quoted 14 lines

Hi Peter,

In HS-LSS mode, the ref_clk frequency is automatically detected by the UFS device. The bRefClkFreq attribute is ignored in this mode and should not be write in this mode.

However, the current code does not properly handle this scenario when calling ufshcd_set_dev_ref_clk(). If the UFS device's default bRefClkFreq value differs from the host controller's dev_ref_clk_freq,
the function will attempt to write the bRefClkFreq attribute, which will inevitably fail.

Quoted 6 lines

So, fix this by adding a check to skip ufshcd_set_dev_ref_clk() when operating in HS-LSS mode.

Thanks,
Wang Shuaiwei.

Hi Shuaiwei,

Okay, the ref_clk frequency is automatically detected by the UFS device. But I am still curious, if you are using HS-LSS, why would you set a wrong hba->dev_ref_clk_freq value, which would then require writing bRefClkFreq?
I mean, you can either set the correct hba->dev_ref_clk_freq value, or simply ignore setting the hba->dev_ref_clk_freq value, right?

Thanks.
Peter

#5 lore raw
Quoted 10 lines · Peter Wang

Hi Shuaiwei,

Okay, the ref_clk frequency is automatically detected by the UFS device. But I am still curious, if you are using HS-LSS, why would you set a wrong hba->dev_ref_clk_freq value, which would then require writing bRefClkFreq?
I mean, you can either set the correct hba->dev_ref_clk_freq value, or simply ignore setting the hba->dev_ref_clk_freq value, right?

Quoted 2 lines

Thanks.
Peter

Hi Peter,

It's not about setting a wrong hba->dev_ref_clk_freq value. Rather, it's that the UFS device's default bRefClkFreq value (which may differ across different manufacturers) is different from the actual ref_clk frequency being used.

Additionally, I need to support both HS-LSS and LS-LSS modes, hba->dev_ref_clk_freq needs to be set to the actual ref_clk frequency and cannot simply ignore the hba->dev_ref_clk_freq setting.

Thanks,
Wang Shuaiwei

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

On Tue, 2026-04-14 at 18:50 +0800, Wang Shuaiwei wrote

Quoted 11 lines

Hi Peter,

It's not about setting a wrong hba->dev_ref_clk_freq value. Rather, it's
that the UFS device's default bRefClkFreq value (which may differ across
different manufacturers) is different from the actual ref_clk frequency
being used.

Quoted 8 lines

Additionally, I need to support both HS-LSS and LS-LSS modes, hba->dev_ref_clk_freq needs to be set to the actual ref_clk frequency and
cannot simply ignore the hba->dev_ref_clk_freq setting.

Thanks,
Wang Shuaiwei

Hi Shuaiwei,

Thank you for your detailed explanation.

Best regards,
Peter