1 From 7bac65687510038390a0a54cbe14fba08d037e46 Mon Sep 17 00:00:00 2001
2 From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
3 Date: Thu, 19 Dec 2024 22:20:41 +0530
4 Subject: scsi: ufs: qcom: Power off the PHY if it was already powered on in ufs_qcom_power_up_sequence()
6 From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
8 commit 7bac65687510038390a0a54cbe14fba08d037e46 upstream.
10 PHY might already be powered on during ufs_qcom_power_up_sequence() in a
13 1. During UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH quirk
15 2. Resuming from spm_lvl = 5 suspend
17 In those cases, it is necessary to call phy_power_off() and phy_exit() in
18 ufs_qcom_power_up_sequence() function to power off the PHY before calling
19 phy_init() and phy_power_on().
21 Case (1) is doing it via ufs_qcom_reinit_notify() callback, but case (2) is
22 not handled. So to satisfy both cases, call phy_power_off() and phy_exit()
23 if the phy_count is non-zero. And with this change, the reinit_notify()
24 callback is no longer needed.
26 This fixes the below UFS resume failure with spm_lvl = 5:
28 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
29 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
30 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
31 ufshcd-qcom 1d84000.ufshc: ufshcd_host_reset_and_restore: Host init failed -5
32 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
33 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
34 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
35 ufshcd-qcom 1d84000.ufshc: ufshcd_host_reset_and_restore: Host init failed -5
36 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
37 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
38 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
39 ufshcd-qcom 1d84000.ufshc: ufshcd_host_reset_and_restore: Host init failed -5
40 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
41 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
42 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
43 ufshcd-qcom 1d84000.ufshc: ufshcd_host_reset_and_restore: Host init failed -5
44 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
45 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
46 ufshcd-qcom 1d84000.ufshc: Enabling the controller failed
47 ufshcd-qcom 1d84000.ufshc: ufshcd_host_reset_and_restore: Host init failed -5
48 ufs_device_wlun 0:0:0:49488: ufshcd_wl_resume failed: -5
49 ufs_device_wlun 0:0:0:49488: PM: dpm_run_callback(): scsi_bus_resume returns -5
50 ufs_device_wlun 0:0:0:49488: PM: failed to resume async: error -5
52 Cc: stable@vger.kernel.org # 6.3
53 Fixes: baf5ddac90dc ("scsi: ufs: ufs-qcom: Add support for reinitializing the UFS device")
54 Reported-by: Ram Kumar Dwivedi <quic_rdwivedi@quicinc.com>
55 Tested-by: Amit Pundir <amit.pundir@linaro.org> # on SM8550-HDK
56 Reviewed-by: Bart Van Assche <bvanassche@acm.org>
57 Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
58 Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
59 Link: https://lore.kernel.org/r/20241219-ufs-qcom-suspend-fix-v3-1-63c4b95a70b9@linaro.org
60 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
61 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
63 drivers/ufs/core/ufshcd-priv.h | 6 ------
64 drivers/ufs/core/ufshcd.c | 1 -
65 drivers/ufs/host/ufs-qcom.c | 13 +++++--------
66 include/ufs/ufshcd.h | 2 --
67 4 files changed, 5 insertions(+), 17 deletions(-)
69 --- a/drivers/ufs/core/ufshcd-priv.h
70 +++ b/drivers/ufs/core/ufshcd-priv.h
71 @@ -242,12 +242,6 @@ static inline void ufshcd_vops_config_sc
72 hba->vops->config_scaling_param(hba, p, data);
75 -static inline void ufshcd_vops_reinit_notify(struct ufs_hba *hba)
77 - if (hba->vops && hba->vops->reinit_notify)
78 - hba->vops->reinit_notify(hba);
81 static inline int ufshcd_vops_mcq_config_resource(struct ufs_hba *hba)
83 if (hba->vops && hba->vops->mcq_config_resource)
84 --- a/drivers/ufs/core/ufshcd.c
85 +++ b/drivers/ufs/core/ufshcd.c
86 @@ -8795,7 +8795,6 @@ static int ufshcd_probe_hba(struct ufs_h
87 ufshcd_device_reset(hba);
88 ufs_put_device_desc(hba);
90 - ufshcd_vops_reinit_notify(hba);
91 ret = ufshcd_hba_enable(hba);
93 dev_err(hba->dev, "Host controller enable failed\n");
94 --- a/drivers/ufs/host/ufs-qcom.c
95 +++ b/drivers/ufs/host/ufs-qcom.c
96 @@ -455,6 +455,11 @@ static int ufs_qcom_power_up_sequence(st
97 dev_warn(hba->dev, "%s: host reset returned %d\n",
100 + if (phy->power_count) {
101 + phy_power_off(phy);
105 /* phy initialization - calibrate the phy */
108 @@ -1638,13 +1643,6 @@ static void ufs_qcom_config_scaling_para
112 -static void ufs_qcom_reinit_notify(struct ufs_hba *hba)
114 - struct ufs_qcom_host *host = ufshcd_get_variant(hba);
116 - phy_power_off(host->generic_phy);
120 static const struct ufshcd_res_info ufs_res_info[RES_MAX] = {
121 {.name = "ufs_mem",},
122 @@ -1887,7 +1885,6 @@ static const struct ufs_hba_variant_ops
123 .device_reset = ufs_qcom_device_reset,
124 .config_scaling_param = ufs_qcom_config_scaling_param,
125 .program_key = ufs_qcom_ice_program_key,
126 - .reinit_notify = ufs_qcom_reinit_notify,
127 .mcq_config_resource = ufs_qcom_mcq_config_resource,
128 .get_hba_mac = ufs_qcom_get_hba_mac,
129 .op_runtime_config = ufs_qcom_op_runtime_config,
130 --- a/include/ufs/ufshcd.h
131 +++ b/include/ufs/ufshcd.h
132 @@ -324,7 +324,6 @@ struct ufs_pwr_mode_info {
133 * @config_scaling_param: called to configure clock scaling parameters
134 * @program_key: program or evict an inline encryption key
135 * @event_notify: called to notify important events
136 - * @reinit_notify: called to notify reinit of UFSHCD during max gear switch
137 * @mcq_config_resource: called to configure MCQ platform resources
138 * @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode
139 * @op_runtime_config: called to config Operation and runtime regs Pointers
140 @@ -369,7 +368,6 @@ struct ufs_hba_variant_ops {
141 const union ufs_crypto_cfg_entry *cfg, int slot);
142 void (*event_notify)(struct ufs_hba *hba,
143 enum ufs_event_type evt, void *data);
144 - void (*reinit_notify)(struct ufs_hba *);
145 int (*mcq_config_resource)(struct ufs_hba *hba);
146 int (*get_hba_mac)(struct ufs_hba *hba);
147 int (*op_runtime_config)(struct ufs_hba *hba);