Skip to contentSkip to conversation

ufs: core: add missing post notify for power mode change

PATCH Superseded [email protected] 2 participants 3 messages Nov 20, 2024 – Nov 22, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 7eb584db73be ("ufs: refactor configuring power mode")
---
 drivers/ufs/core/ufshcd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ufs/core/ufshcd.c +4 -3
index abbe7135a977..814402e93a1e 100644
@@ -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
#1 lore raw

drivers/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 the
POST_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.

#2 lore raw
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_CHANGE callback. I think that &final_params should be changed into
&hba->pwr_info above.

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

Quoted 8 lines

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.

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