1dd11376bSBart Van Assche /* SPDX-License-Identifier: GPL-2.0-or-later */
2dd11376bSBart Van Assche
3dd11376bSBart Van Assche #ifndef _UFSHCD_PRIV_H_
4dd11376bSBart Van Assche #define _UFSHCD_PRIV_H_
5dd11376bSBart Van Assche
6dd11376bSBart Van Assche #include <linux/pm_runtime.h>
7dd11376bSBart Van Assche #include <ufs/ufshcd.h>
8dd11376bSBart Van Assche
ufshcd_is_user_access_allowed(struct ufs_hba * hba)9dd11376bSBart Van Assche static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba)
10dd11376bSBart Van Assche {
11dd11376bSBart Van Assche return !hba->shutting_down;
12dd11376bSBart Van Assche }
13dd11376bSBart Van Assche
14dd11376bSBart Van Assche void ufshcd_schedule_eh_work(struct ufs_hba *hba);
15dd11376bSBart Van Assche
ufshcd_keep_autobkops_enabled_except_suspend(struct ufs_hba * hba)16dd11376bSBart Van Assche static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
17dd11376bSBart Van Assche struct ufs_hba *hba)
18dd11376bSBart Van Assche {
19dd11376bSBart Van Assche return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
20dd11376bSBart Van Assche }
21dd11376bSBart Van Assche
ufshcd_wb_get_query_index(struct ufs_hba * hba)22dd11376bSBart Van Assche static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)
23dd11376bSBart Van Assche {
24dd11376bSBart Van Assche if (hba->dev_info.wb_buffer_type == WB_BUF_MODE_LU_DEDICATED)
25dd11376bSBart Van Assche return hba->dev_info.wb_dedicated_lu;
26dd11376bSBart Van Assche return 0;
27dd11376bSBart Van Assche }
28dd11376bSBart Van Assche
ufshcd_is_wb_buf_flush_allowed(struct ufs_hba * hba)2942f8c5cdSJinyoung Choi static inline bool ufshcd_is_wb_buf_flush_allowed(struct ufs_hba *hba)
3042f8c5cdSJinyoung Choi {
3142f8c5cdSJinyoung Choi return ufshcd_is_wb_allowed(hba) &&
3242f8c5cdSJinyoung Choi !(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL);
3342f8c5cdSJinyoung Choi }
3442f8c5cdSJinyoung Choi
35dd11376bSBart Van Assche #ifdef CONFIG_SCSI_UFS_HWMON
36dd11376bSBart Van Assche void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask);
37dd11376bSBart Van Assche void ufs_hwmon_remove(struct ufs_hba *hba);
38dd11376bSBart Van Assche void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask);
39dd11376bSBart Van Assche #else
ufs_hwmon_probe(struct ufs_hba * hba,u8 mask)40dd11376bSBart Van Assche static inline void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask) {}
ufs_hwmon_remove(struct ufs_hba * hba)41dd11376bSBart Van Assche static inline void ufs_hwmon_remove(struct ufs_hba *hba) {}
ufs_hwmon_notify_event(struct ufs_hba * hba,u8 ee_mask)42dd11376bSBart Van Assche static inline void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask) {}
43dd11376bSBart Van Assche #endif
44dd11376bSBart Van Assche
451a2433b0SArthur Simchaev int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
461a2433b0SArthur Simchaev enum query_opcode opcode,
471a2433b0SArthur Simchaev enum desc_idn idn, u8 index,
481a2433b0SArthur Simchaev u8 selector,
491a2433b0SArthur Simchaev u8 *desc_buf, int *buf_len);
50dd11376bSBart Van Assche int ufshcd_read_desc_param(struct ufs_hba *hba,
51dd11376bSBart Van Assche enum desc_idn desc_id,
52dd11376bSBart Van Assche int desc_index,
53dd11376bSBart Van Assche u8 param_offset,
54dd11376bSBart Van Assche u8 *param_read_buf,
55dd11376bSBart Van Assche u8 param_size);
56dd11376bSBart Van Assche int ufshcd_query_attr_retry(struct ufs_hba *hba, enum query_opcode opcode,
57dd11376bSBart Van Assche enum attr_idn idn, u8 index, u8 selector,
58dd11376bSBart Van Assche u32 *attr_val);
59dd11376bSBart Van Assche int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
60dd11376bSBart Van Assche enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);
61dd11376bSBart Van Assche int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
62dd11376bSBart Van Assche enum flag_idn idn, u8 index, bool *flag_res);
63dd11376bSBart Van Assche void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
64c30d8d01SAsutosh Das void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
65c30d8d01SAsutosh Das struct cq_entry *cqe);
6657b1c0efSAsutosh Das int ufshcd_mcq_init(struct ufs_hba *hba);
67af568c7eSBart Van Assche void ufshcd_mcq_disable(struct ufs_hba *hba);
687224c806SAsutosh Das int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba);
694682abfaSAsutosh Das int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);
70854f84e7SAsutosh Das struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba,
71854f84e7SAsutosh Das struct request *req);
72ab248643SBao D. Nguyen void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
73ab248643SBao D. Nguyen struct ufs_hw_queue *hwq);
74adf45261SBao D. Nguyen bool ufshcd_cmd_inflight(struct scsi_cmnd *cmd);
758d729034SBao D. Nguyen int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag);
76f1304d44SBao D. Nguyen int ufshcd_mcq_abort(struct scsi_cmnd *cmd);
77f1304d44SBao D. Nguyen int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag);
78f1304d44SBao D. Nguyen void ufshcd_release_scsi_cmd(struct ufs_hba *hba,
79f1304d44SBao D. Nguyen struct ufshcd_lrb *lrbp);
80dd11376bSBart Van Assche
81dd11376bSBart Van Assche #define SD_ASCII_STD true
82dd11376bSBart Van Assche #define SD_RAW false
83dd11376bSBart Van Assche int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
84dd11376bSBart Van Assche u8 **buf, bool ascii);
85dd11376bSBart Van Assche
86dd11376bSBart Van Assche int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
87dd11376bSBart Van Assche
88dd11376bSBart Van Assche int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
89dd11376bSBart Van Assche struct utp_upiu_req *req_upiu,
90dd11376bSBart Van Assche struct utp_upiu_req *rsp_upiu,
9108108d31SBart Van Assche enum upiu_request_transaction msgcode,
92dd11376bSBart Van Assche u8 *desc_buff, int *buff_len,
93dd11376bSBart Van Assche enum query_opcode desc_op);
94dd11376bSBart Van Assche
95dd11376bSBart Van Assche int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
96dd11376bSBart Van Assche
97dd11376bSBart Van Assche /* Wrapper functions for safely calling variant operations */
ufshcd_get_var_name(struct ufs_hba * hba)98dd11376bSBart Van Assche static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
99dd11376bSBart Van Assche {
100dd11376bSBart Van Assche if (hba->vops)
101dd11376bSBart Van Assche return hba->vops->name;
102dd11376bSBart Van Assche return "";
103dd11376bSBart Van Assche }
104dd11376bSBart Van Assche
ufshcd_vops_exit(struct ufs_hba * hba)105dd11376bSBart Van Assche static inline void ufshcd_vops_exit(struct ufs_hba *hba)
106dd11376bSBart Van Assche {
107dd11376bSBart Van Assche if (hba->vops && hba->vops->exit)
108dd11376bSBart Van Assche return hba->vops->exit(hba);
109dd11376bSBart Van Assche }
110dd11376bSBart Van Assche
ufshcd_vops_get_ufs_hci_version(struct ufs_hba * hba)111dd11376bSBart Van Assche static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba)
112dd11376bSBart Van Assche {
113dd11376bSBart Van Assche if (hba->vops && hba->vops->get_ufs_hci_version)
114dd11376bSBart Van Assche return hba->vops->get_ufs_hci_version(hba);
115dd11376bSBart Van Assche
116dd11376bSBart Van Assche return ufshcd_readl(hba, REG_UFS_VERSION);
117dd11376bSBart Van Assche }
118dd11376bSBart Van Assche
ufshcd_vops_clk_scale_notify(struct ufs_hba * hba,bool up,enum ufs_notify_change_status status)119dd11376bSBart Van Assche static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba,
120dd11376bSBart Van Assche bool up, enum ufs_notify_change_status status)
121dd11376bSBart Van Assche {
122dd11376bSBart Van Assche if (hba->vops && hba->vops->clk_scale_notify)
123dd11376bSBart Van Assche return hba->vops->clk_scale_notify(hba, up, status);
124dd11376bSBart Van Assche return 0;
125dd11376bSBart Van Assche }
126dd11376bSBart Van Assche
ufshcd_vops_event_notify(struct ufs_hba * hba,enum ufs_event_type evt,void * data)127dd11376bSBart Van Assche static inline void ufshcd_vops_event_notify(struct ufs_hba *hba,
128dd11376bSBart Van Assche enum ufs_event_type evt,
129dd11376bSBart Van Assche void *data)
130dd11376bSBart Van Assche {
131dd11376bSBart Van Assche if (hba->vops && hba->vops->event_notify)
132dd11376bSBart Van Assche hba->vops->event_notify(hba, evt, data);
133dd11376bSBart Van Assche }
134dd11376bSBart Van Assche
ufshcd_vops_setup_clocks(struct ufs_hba * hba,bool on,enum ufs_notify_change_status status)135dd11376bSBart Van Assche static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on,
136dd11376bSBart Van Assche enum ufs_notify_change_status status)
137dd11376bSBart Van Assche {
138dd11376bSBart Van Assche if (hba->vops && hba->vops->setup_clocks)
139dd11376bSBart Van Assche return hba->vops->setup_clocks(hba, on, status);
140dd11376bSBart Van Assche return 0;
141dd11376bSBart Van Assche }
142dd11376bSBart Van Assche
ufshcd_vops_hce_enable_notify(struct ufs_hba * hba,bool status)143dd11376bSBart Van Assche static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba,
144dd11376bSBart Van Assche bool status)
145dd11376bSBart Van Assche {
146dd11376bSBart Van Assche if (hba->vops && hba->vops->hce_enable_notify)
147dd11376bSBart Van Assche return hba->vops->hce_enable_notify(hba, status);
148dd11376bSBart Van Assche
149dd11376bSBart Van Assche return 0;
150dd11376bSBart Van Assche }
ufshcd_vops_link_startup_notify(struct ufs_hba * hba,bool status)151dd11376bSBart Van Assche static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba,
152dd11376bSBart Van Assche bool status)
153dd11376bSBart Van Assche {
154dd11376bSBart Van Assche if (hba->vops && hba->vops->link_startup_notify)
155dd11376bSBart Van Assche return hba->vops->link_startup_notify(hba, status);
156dd11376bSBart Van Assche
157dd11376bSBart Van Assche return 0;
158dd11376bSBart Van Assche }
159dd11376bSBart Van Assche
ufshcd_vops_pwr_change_notify(struct ufs_hba * hba,enum ufs_notify_change_status status,struct ufs_pa_layer_attr * dev_max_params,struct ufs_pa_layer_attr * dev_req_params)160dd11376bSBart Van Assche static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba,
161dd11376bSBart Van Assche enum ufs_notify_change_status status,
162dd11376bSBart Van Assche struct ufs_pa_layer_attr *dev_max_params,
163dd11376bSBart Van Assche struct ufs_pa_layer_attr *dev_req_params)
164dd11376bSBart Van Assche {
165dd11376bSBart Van Assche if (hba->vops && hba->vops->pwr_change_notify)
166dd11376bSBart Van Assche return hba->vops->pwr_change_notify(hba, status,
167dd11376bSBart Van Assche dev_max_params, dev_req_params);
168dd11376bSBart Van Assche
169dd11376bSBart Van Assche return -ENOTSUPP;
170dd11376bSBart Van Assche }
171dd11376bSBart Van Assche
ufshcd_vops_setup_task_mgmt(struct ufs_hba * hba,int tag,u8 tm_function)172dd11376bSBart Van Assche static inline void ufshcd_vops_setup_task_mgmt(struct ufs_hba *hba,
173dd11376bSBart Van Assche int tag, u8 tm_function)
174dd11376bSBart Van Assche {
175dd11376bSBart Van Assche if (hba->vops && hba->vops->setup_task_mgmt)
176dd11376bSBart Van Assche return hba->vops->setup_task_mgmt(hba, tag, tm_function);
177dd11376bSBart Van Assche }
178dd11376bSBart Van Assche
ufshcd_vops_hibern8_notify(struct ufs_hba * hba,enum uic_cmd_dme cmd,enum ufs_notify_change_status status)179dd11376bSBart Van Assche static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba,
180dd11376bSBart Van Assche enum uic_cmd_dme cmd,
181dd11376bSBart Van Assche enum ufs_notify_change_status status)
182dd11376bSBart Van Assche {
183dd11376bSBart Van Assche if (hba->vops && hba->vops->hibern8_notify)
184dd11376bSBart Van Assche return hba->vops->hibern8_notify(hba, cmd, status);
185dd11376bSBart Van Assche }
186dd11376bSBart Van Assche
ufshcd_vops_apply_dev_quirks(struct ufs_hba * hba)187dd11376bSBart Van Assche static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba)
188dd11376bSBart Van Assche {
189dd11376bSBart Van Assche if (hba->vops && hba->vops->apply_dev_quirks)
190dd11376bSBart Van Assche return hba->vops->apply_dev_quirks(hba);
191dd11376bSBart Van Assche return 0;
192dd11376bSBart Van Assche }
193dd11376bSBart Van Assche
ufshcd_vops_fixup_dev_quirks(struct ufs_hba * hba)194dd11376bSBart Van Assche static inline void ufshcd_vops_fixup_dev_quirks(struct ufs_hba *hba)
195dd11376bSBart Van Assche {
196dd11376bSBart Van Assche if (hba->vops && hba->vops->fixup_dev_quirks)
197dd11376bSBart Van Assche hba->vops->fixup_dev_quirks(hba);
198dd11376bSBart Van Assche }
199dd11376bSBart Van Assche
ufshcd_vops_suspend(struct ufs_hba * hba,enum ufs_pm_op op,enum ufs_notify_change_status status)200dd11376bSBart Van Assche static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op,
201dd11376bSBart Van Assche enum ufs_notify_change_status status)
202dd11376bSBart Van Assche {
203dd11376bSBart Van Assche if (hba->vops && hba->vops->suspend)
204dd11376bSBart Van Assche return hba->vops->suspend(hba, op, status);
205dd11376bSBart Van Assche
206dd11376bSBart Van Assche return 0;
207dd11376bSBart Van Assche }
208dd11376bSBart Van Assche
ufshcd_vops_resume(struct ufs_hba * hba,enum ufs_pm_op op)209dd11376bSBart Van Assche static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op)
210dd11376bSBart Van Assche {
211dd11376bSBart Van Assche if (hba->vops && hba->vops->resume)
212dd11376bSBart Van Assche return hba->vops->resume(hba, op);
213dd11376bSBart Van Assche
214dd11376bSBart Van Assche return 0;
215dd11376bSBart Van Assche }
216dd11376bSBart Van Assche
ufshcd_vops_dbg_register_dump(struct ufs_hba * hba)217dd11376bSBart Van Assche static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
218dd11376bSBart Van Assche {
219dd11376bSBart Van Assche if (hba->vops && hba->vops->dbg_register_dump)
220dd11376bSBart Van Assche hba->vops->dbg_register_dump(hba);
221dd11376bSBart Van Assche }
222dd11376bSBart Van Assche
ufshcd_vops_device_reset(struct ufs_hba * hba)223dd11376bSBart Van Assche static inline int ufshcd_vops_device_reset(struct ufs_hba *hba)
224dd11376bSBart Van Assche {
225dd11376bSBart Van Assche if (hba->vops && hba->vops->device_reset)
226dd11376bSBart Van Assche return hba->vops->device_reset(hba);
227dd11376bSBart Van Assche
228dd11376bSBart Van Assche return -EOPNOTSUPP;
229dd11376bSBart Van Assche }
230dd11376bSBart Van Assche
ufshcd_vops_config_scaling_param(struct ufs_hba * hba,struct devfreq_dev_profile * p,struct devfreq_simple_ondemand_data * data)231dd11376bSBart Van Assche static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba,
232dd11376bSBart Van Assche struct devfreq_dev_profile *p,
233dd11376bSBart Van Assche struct devfreq_simple_ondemand_data *data)
234dd11376bSBart Van Assche {
235dd11376bSBart Van Assche if (hba->vops && hba->vops->config_scaling_param)
236dd11376bSBart Van Assche hba->vops->config_scaling_param(hba, p, data);
237dd11376bSBart Van Assche }
238dd11376bSBart Van Assche
ufshcd_vops_reinit_notify(struct ufs_hba * hba)239c2c38c57SManivannan Sadhasivam static inline void ufshcd_vops_reinit_notify(struct ufs_hba *hba)
240c2c38c57SManivannan Sadhasivam {
241c2c38c57SManivannan Sadhasivam if (hba->vops && hba->vops->reinit_notify)
242c2c38c57SManivannan Sadhasivam hba->vops->reinit_notify(hba);
243c2c38c57SManivannan Sadhasivam }
244c2c38c57SManivannan Sadhasivam
ufshcd_vops_mcq_config_resource(struct ufs_hba * hba)245c263b4efSAsutosh Das static inline int ufshcd_vops_mcq_config_resource(struct ufs_hba *hba)
246c263b4efSAsutosh Das {
247c263b4efSAsutosh Das if (hba->vops && hba->vops->mcq_config_resource)
248c263b4efSAsutosh Das return hba->vops->mcq_config_resource(hba);
249c263b4efSAsutosh Das
250c263b4efSAsutosh Das return -EOPNOTSUPP;
251c263b4efSAsutosh Das }
252c263b4efSAsutosh Das
ufshcd_mcq_vops_op_runtime_config(struct ufs_hba * hba)2532468da61SAsutosh Das static inline int ufshcd_mcq_vops_op_runtime_config(struct ufs_hba *hba)
2542468da61SAsutosh Das {
2552468da61SAsutosh Das if (hba->vops && hba->vops->op_runtime_config)
2562468da61SAsutosh Das return hba->vops->op_runtime_config(hba);
2572468da61SAsutosh Das
2582468da61SAsutosh Das return -EOPNOTSUPP;
2592468da61SAsutosh Das }
2602468da61SAsutosh Das
ufshcd_vops_get_outstanding_cqs(struct ufs_hba * hba,unsigned long * ocqs)261f87b2c41SAsutosh Das static inline int ufshcd_vops_get_outstanding_cqs(struct ufs_hba *hba,
262f87b2c41SAsutosh Das unsigned long *ocqs)
263f87b2c41SAsutosh Das {
264f87b2c41SAsutosh Das if (hba->vops && hba->vops->get_outstanding_cqs)
265f87b2c41SAsutosh Das return hba->vops->get_outstanding_cqs(hba, ocqs);
266f87b2c41SAsutosh Das
267f87b2c41SAsutosh Das return -EOPNOTSUPP;
268f87b2c41SAsutosh Das }
269f87b2c41SAsutosh Das
ufshcd_mcq_vops_config_esi(struct ufs_hba * hba)270edb0db05SCan Guo static inline int ufshcd_mcq_vops_config_esi(struct ufs_hba *hba)
271edb0db05SCan Guo {
272edb0db05SCan Guo if (hba->vops && hba->vops->config_esi)
273edb0db05SCan Guo return hba->vops->config_esi(hba);
274edb0db05SCan Guo
275edb0db05SCan Guo return -EOPNOTSUPP;
276edb0db05SCan Guo }
277edb0db05SCan Guo
27835d11ec2SKrzysztof Kozlowski extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];
279dd11376bSBart Van Assche
280dd11376bSBart Van Assche /**
281dd11376bSBart Van Assche * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN
282dd11376bSBart Van Assche * @scsi_lun: scsi LUN id
283dd11376bSBart Van Assche *
2843a17fefeSBart Van Assche * Return: UPIU LUN id
285dd11376bSBart Van Assche */
ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun)286dd11376bSBart Van Assche static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun)
287dd11376bSBart Van Assche {
288dd11376bSBart Van Assche if (scsi_is_wlun(scsi_lun))
289dd11376bSBart Van Assche return (scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID)
290dd11376bSBart Van Assche | UFS_UPIU_WLUN_ID;
291dd11376bSBart Van Assche else
292dd11376bSBart Van Assche return scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID;
293dd11376bSBart Van Assche }
294dd11376bSBart Van Assche
295dd11376bSBart Van Assche int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);
296dd11376bSBart Van Assche int ufshcd_write_ee_control(struct ufs_hba *hba);
29735d11ec2SKrzysztof Kozlowski int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,
29835d11ec2SKrzysztof Kozlowski const u16 *other_mask, u16 set, u16 clr);
299dd11376bSBart Van Assche
ufshcd_update_ee_drv_mask(struct ufs_hba * hba,u16 set,u16 clr)300dd11376bSBart Van Assche static inline int ufshcd_update_ee_drv_mask(struct ufs_hba *hba,
301dd11376bSBart Van Assche u16 set, u16 clr)
302dd11376bSBart Van Assche {
303dd11376bSBart Van Assche return ufshcd_update_ee_control(hba, &hba->ee_drv_mask,
304dd11376bSBart Van Assche &hba->ee_usr_mask, set, clr);
305dd11376bSBart Van Assche }
306dd11376bSBart Van Assche
ufshcd_update_ee_usr_mask(struct ufs_hba * hba,u16 set,u16 clr)307dd11376bSBart Van Assche static inline int ufshcd_update_ee_usr_mask(struct ufs_hba *hba,
308dd11376bSBart Van Assche u16 set, u16 clr)
309dd11376bSBart Van Assche {
310dd11376bSBart Van Assche return ufshcd_update_ee_control(hba, &hba->ee_usr_mask,
311dd11376bSBart Van Assche &hba->ee_drv_mask, set, clr);
312dd11376bSBart Van Assche }
313dd11376bSBart Van Assche
ufshcd_rpm_get_sync(struct ufs_hba * hba)314dd11376bSBart Van Assche static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
315dd11376bSBart Van Assche {
316dd11376bSBart Van Assche return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev);
317dd11376bSBart Van Assche }
318dd11376bSBart Van Assche
ufshcd_rpm_get_if_active(struct ufs_hba * hba)319*3911af77SPeter Wang static inline int ufshcd_rpm_get_if_active(struct ufs_hba *hba)
320*3911af77SPeter Wang {
321*3911af77SPeter Wang return pm_runtime_get_if_active(&hba->ufs_device_wlun->sdev_gendev);
322*3911af77SPeter Wang }
323*3911af77SPeter Wang
ufshcd_rpm_put_sync(struct ufs_hba * hba)324dd11376bSBart Van Assche static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
325dd11376bSBart Van Assche {
326dd11376bSBart Van Assche return pm_runtime_put_sync(&hba->ufs_device_wlun->sdev_gendev);
327dd11376bSBart Van Assche }
328dd11376bSBart Van Assche
ufshcd_rpm_get_noresume(struct ufs_hba * hba)329dd11376bSBart Van Assche static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
330dd11376bSBart Van Assche {
331dd11376bSBart Van Assche pm_runtime_get_noresume(&hba->ufs_device_wlun->sdev_gendev);
332dd11376bSBart Van Assche }
333dd11376bSBart Van Assche
ufshcd_rpm_resume(struct ufs_hba * hba)334dd11376bSBart Van Assche static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
335dd11376bSBart Van Assche {
336dd11376bSBart Van Assche return pm_runtime_resume(&hba->ufs_device_wlun->sdev_gendev);
337dd11376bSBart Van Assche }
338dd11376bSBart Van Assche
ufshcd_rpm_put(struct ufs_hba * hba)339dd11376bSBart Van Assche static inline int ufshcd_rpm_put(struct ufs_hba *hba)
340dd11376bSBart Van Assche {
341dd11376bSBart Van Assche return pm_runtime_put(&hba->ufs_device_wlun->sdev_gendev);
342dd11376bSBart Van Assche }
343dd11376bSBart Van Assche
344dd11376bSBart Van Assche /**
345dd11376bSBart Van Assche * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
346dd11376bSBart Van Assche * @dev_info: pointer of instance of struct ufs_dev_info
347dd11376bSBart Van Assche * @lun: LU number to check
348dd11376bSBart Van Assche * @return: true if the lun has a matching unit descriptor, false otherwise
349dd11376bSBart Van Assche */
ufs_is_valid_unit_desc_lun(struct ufs_dev_info * dev_info,u8 lun)350b43678eaSBean Huo static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8 lun)
351dd11376bSBart Van Assche {
352dd11376bSBart Van Assche if (!dev_info || !dev_info->max_lu_supported) {
353dd11376bSBart Van Assche pr_err("Max General LU supported by UFS isn't initialized\n");
354dd11376bSBart Van Assche return false;
355dd11376bSBart Van Assche }
356dd11376bSBart Van Assche return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported);
357dd11376bSBart Van Assche }
358dd11376bSBart Van Assche
ufshcd_inc_sq_tail(struct ufs_hw_queue * q)35922a2d563SAsutosh Das static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q)
3604de243c4SAvri Altman __must_hold(&q->sq_lock)
36122a2d563SAsutosh Das {
36222a2d563SAsutosh Das u32 val;
36322a2d563SAsutosh Das
364e01d05bbSzhanghui q->sq_tail_slot++;
365e01d05bbSzhanghui if (q->sq_tail_slot == q->max_entries)
366e01d05bbSzhanghui q->sq_tail_slot = 0;
36722a2d563SAsutosh Das val = q->sq_tail_slot * sizeof(struct utp_transfer_req_desc);
36822a2d563SAsutosh Das writel(val, q->mcq_sq_tail);
36922a2d563SAsutosh Das }
37022a2d563SAsutosh Das
ufshcd_mcq_update_cq_tail_slot(struct ufs_hw_queue * q)371f87b2c41SAsutosh Das static inline void ufshcd_mcq_update_cq_tail_slot(struct ufs_hw_queue *q)
372f87b2c41SAsutosh Das {
373f87b2c41SAsutosh Das u32 val = readl(q->mcq_cq_tail);
374f87b2c41SAsutosh Das
375f87b2c41SAsutosh Das q->cq_tail_slot = val / sizeof(struct cq_entry);
376f87b2c41SAsutosh Das }
377f87b2c41SAsutosh Das
ufshcd_mcq_is_cq_empty(struct ufs_hw_queue * q)378f87b2c41SAsutosh Das static inline bool ufshcd_mcq_is_cq_empty(struct ufs_hw_queue *q)
379f87b2c41SAsutosh Das {
380f87b2c41SAsutosh Das return q->cq_head_slot == q->cq_tail_slot;
381f87b2c41SAsutosh Das }
382f87b2c41SAsutosh Das
ufshcd_mcq_inc_cq_head_slot(struct ufs_hw_queue * q)383f87b2c41SAsutosh Das static inline void ufshcd_mcq_inc_cq_head_slot(struct ufs_hw_queue *q)
384f87b2c41SAsutosh Das {
385f87b2c41SAsutosh Das q->cq_head_slot++;
386f87b2c41SAsutosh Das if (q->cq_head_slot == q->max_entries)
387f87b2c41SAsutosh Das q->cq_head_slot = 0;
388f87b2c41SAsutosh Das }
389f87b2c41SAsutosh Das
ufshcd_mcq_update_cq_head(struct ufs_hw_queue * q)390f87b2c41SAsutosh Das static inline void ufshcd_mcq_update_cq_head(struct ufs_hw_queue *q)
391f87b2c41SAsutosh Das {
392f87b2c41SAsutosh Das writel(q->cq_head_slot * sizeof(struct cq_entry), q->mcq_cq_head);
393f87b2c41SAsutosh Das }
394f87b2c41SAsutosh Das
ufshcd_mcq_cur_cqe(struct ufs_hw_queue * q)395f87b2c41SAsutosh Das static inline struct cq_entry *ufshcd_mcq_cur_cqe(struct ufs_hw_queue *q)
396f87b2c41SAsutosh Das {
397f87b2c41SAsutosh Das struct cq_entry *cqe = q->cqe_base_addr;
398f87b2c41SAsutosh Das
399f87b2c41SAsutosh Das return cqe + q->cq_head_slot;
400f87b2c41SAsutosh Das }
4018d729034SBao D. Nguyen
ufshcd_mcq_get_sq_head_slot(struct ufs_hw_queue * q)4028d729034SBao D. Nguyen static inline u32 ufshcd_mcq_get_sq_head_slot(struct ufs_hw_queue *q)
4038d729034SBao D. Nguyen {
4048d729034SBao D. Nguyen u32 val = readl(q->mcq_sq_head);
4058d729034SBao D. Nguyen
4068d729034SBao D. Nguyen return val / sizeof(struct utp_transfer_req_desc);
4078d729034SBao D. Nguyen }
4088d729034SBao D. Nguyen
409dd11376bSBart Van Assche #endif /* _UFSHCD_PRIV_H_ */
410