scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode
A message that is not in the archive (sent off-list or not yet received): [email protected]
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'sdev_ref_clk_freqsetting, 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. Callufshcd_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 <[email protected]>
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
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'sdev_ref_clk_freqsetting, 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. Callufshcd_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 <[email protected]>
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]
On Tue, 2026-04-14 at 14:43 +0800, Wang Shuaiwei wrote
Quoted 14 lines
Hi Peter,
In HS-LSS mode, the
ref_clkfrequency 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'sdev_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
Quoted 10 lines · Peter Wang
Hi Shuaiwei,
Okay, the
ref_clkfrequency is automatically detected by the UFS device. But I am still curious, if you are using HS-LSS, why would you set a wronghba->dev_ref_clk_freqvalue, which would then require writing bRefClkFreq?
I mean, you can either set the correcthba->dev_ref_clk_freqvalue, or simply ignore setting thehba->dev_ref_clk_freqvalue, 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]
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_freqvalue. Rather, it's
that the UFS device's default bRefClkFreq value (which may differ across
different manufacturers) is different from the actualref_clkfrequency
being used.
Quoted 8 lines
Additionally, I need to support both HS-LSS and LS-LSS modes,
hba->dev_ref_clk_freqneeds to be set to the actualref_clkfrequency and
cannot simply ignore thehba->dev_ref_clk_freqsetting.Thanks,
Wang Shuaiwei
Hi Shuaiwei,
Thank you for your detailed explanation.
Best regards,
Peter