ufs: core: add missing post notify for power mode change
Subsystems (4)
PATCH 1/1 ufs: core: add missing post notify for power mode change
From: Peter Wang <[email protected]>
When the power mode change is successful but the power mode hasn't actually changed, the post notification was missed. Similar to the approach with hibernate/clock scale/hce enable, having pre/post notifications in the same function will make it easier to maintain.
--- drivers/ufs/core/ufshcd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ufs/core/ufshcd.c +4 -3
@@ -4651,9 +4651,6 @@ static int ufshcd_change_power_mode(struct ufs_hba *hba,dev_err (hba->dev,"%s: power mode change failed %d\n" , __func__, ret); }else { -ufshcd_vops_pwr_change_notify (hba,POST_CHANGE ,NULL , - pwr_mode); -memcpy (&hba->pwr_info, pwr_mode,sizeof (struct ufs_pa_layer_attr )); }
@@ -4682,6 +4679,10 @@ int ufshcd_config_pwr_mode(struct ufs_hba *hba, ret =ufshcd_change_power_mode (hba, &final_params); +if (!ret) +ufshcd_vops_pwr_change_notify (hba,POST_CHANGE ,NULL , + &final_params); +return ret; }EXPORT_SYMBOL_GPL (ufshcd_config_pwr_mode);
Signature · 1 line
2.18.0
Bart Van Assche
reviewerdrivers/ufs/core/ufshcd.c int ufshcd_config_pwr_mode(struct ufs_hba *hba, · line 4688
Quoted 11 lines · On 11/20/24 1:55 AM, [email protected] wrote:
drivers/ufs/core/ufshcd.c +4
-0@@ -4682,6 +4679,10 @@ int ufshcd_config_pwr_mode(struct ufs_hba *hba, ret =ufshcd_change_power_mode (hba, &final_params); +if (!ret) +ufshcd_vops_pwr_change_notify (hba,POST_CHANGE ,NULL , + &final_params); +return ret; }EXPORT_SYMBOL_GPL (ufshcd_config_pwr_mode);
This patch causes the wrong power parameters to be passed to thePOST_CHANGE callback. I think that &final_params should be changed into &hba->pwr_info above.
Additionally, this patch includes a subtle but important behavior change. Without this patch, POST_CHANGE callback invocations can influence the power settings that are copied into hba->pwr_info. With this patch applied that is no longer possible. This behavior should not break any UFS host driver as far as I can tell.
Please explain in the comment block above struct ufs_hba_variant_ops that PRE_CHANGE invocations of the pwr_change_notify callback are allowed to modify the power attribute arguments while POST_CHANGE invocations must not modify the power attribute arguments.
Thanks,
Bart.
Quoted 10 lines · Bart Van Assche
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 5 lines · On 11/20/24 1:55 AM, [email protected] wrote:
drivers/ufs/core/ufshcd.c +0
-0@@ -4682,6 +4679,10 @@ int ufshcd_config_pwr_mode(struct ufs_hba *hba, ret =ufshcd_change_power_mode (hba, &final_params);
Quoted 13 lines
Quoted 7 lines
drivers/ufs/core/ufshcd.c +4
-0+if (!ret) +ufshcd_vops_pwr_change_notify (hba,POST_CHANGE ,NULL , + &final_params); +return ret; }EXPORT_SYMBOL_GPL(ufshcd_config_pwr_mode);This patch causes the wrong power parameters to be passed to the
POST_CHANGEcallback. I think that&final_paramsshould be changed into&hba->pwr_infoabove.
Hi Bart,
&final_params represents the final power mode to be switched to. If the power mode change is successful, it will be copied to &hba->pwr_info. So, &final_params should always be equal to &hba->pwr_info if successful, right?"
Quoted 7 lines
Additionally, this patch includes a subtle but important behavior change. Without this patch,
POST_CHANGEcallback invocations can influence the power settings that are copied intohba->pwr_info. With this patch applied that is no longer possible. This behavior should not
break any UFS host driver as far as I can tell.
Quoted 8 lines
Please explain in the comment block above struct
ufs_hba_variant_opsthatPRE_CHANGEinvocations of thepwr_change_notifycallback are allowed to modify the power attribute arguments whilePOST_CHANGEinvocations must not modify the power attribute arguments.Thanks,
Bart.
Yes, currently, POST_CHANGE does not and should not have the host driver modifying final_params. I will add comments to clarify this.
Thanks
Peter