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 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 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 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 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 40dd11376bSBart Van Assche static inline void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask) {} 41dd11376bSBart Van Assche static inline void ufs_hwmon_remove(struct ufs_hba *hba) {} 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); 677224c806SAsutosh Das int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba); 684682abfaSAsutosh Das int ufshcd_mcq_memory_alloc(struct ufs_hba *hba); 692468da61SAsutosh Das void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba); 702468da61SAsutosh Das void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds); 712468da61SAsutosh Das void ufshcd_mcq_select_mcq_mode(struct ufs_hba *hba); 72f87b2c41SAsutosh Das u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); 73f87b2c41SAsutosh Das void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); 74f87b2c41SAsutosh Das unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba, 75f87b2c41SAsutosh Das struct ufs_hw_queue *hwq); 76854f84e7SAsutosh Das struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, 77854f84e7SAsutosh Das struct request *req); 78ed975065SAsutosh Das unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, 79ed975065SAsutosh Das struct ufs_hw_queue *hwq); 80dd11376bSBart Van Assche 81adf45261SBao D. Nguyen bool ufshcd_cmd_inflight(struct scsi_cmnd *cmd); 828d729034SBao D. Nguyen int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag); 83*f1304d44SBao D. Nguyen int ufshcd_mcq_abort(struct scsi_cmnd *cmd); 84*f1304d44SBao D. Nguyen int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag); 85*f1304d44SBao D. Nguyen void ufshcd_release_scsi_cmd(struct ufs_hba *hba, 86*f1304d44SBao D. Nguyen struct ufshcd_lrb *lrbp); 878d729034SBao D. Nguyen 88854f84e7SAsutosh Das #define UFSHCD_MCQ_IO_QUEUE_OFFSET 1 89dd11376bSBart Van Assche #define SD_ASCII_STD true 90dd11376bSBart Van Assche #define SD_RAW false 91dd11376bSBart Van Assche int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, 92dd11376bSBart Van Assche u8 **buf, bool ascii); 93dd11376bSBart Van Assche 94dd11376bSBart Van Assche int ufshcd_hold(struct ufs_hba *hba, bool async); 95dd11376bSBart Van Assche void ufshcd_release(struct ufs_hba *hba); 96dd11376bSBart Van Assche 97dd11376bSBart Van Assche int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); 98dd11376bSBart Van Assche 99dd11376bSBart Van Assche int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, 100dd11376bSBart Van Assche struct utp_upiu_req *req_upiu, 101dd11376bSBart Van Assche struct utp_upiu_req *rsp_upiu, 102dd11376bSBart Van Assche int msgcode, 103dd11376bSBart Van Assche u8 *desc_buff, int *buff_len, 104dd11376bSBart Van Assche enum query_opcode desc_op); 105dd11376bSBart Van Assche 106dd11376bSBart Van Assche int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable); 107dd11376bSBart Van Assche 108dd11376bSBart Van Assche /* Wrapper functions for safely calling variant operations */ 109dd11376bSBart Van Assche static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) 110dd11376bSBart Van Assche { 111dd11376bSBart Van Assche if (hba->vops) 112dd11376bSBart Van Assche return hba->vops->name; 113dd11376bSBart Van Assche return ""; 114dd11376bSBart Van Assche } 115dd11376bSBart Van Assche 116dd11376bSBart Van Assche static inline void ufshcd_vops_exit(struct ufs_hba *hba) 117dd11376bSBart Van Assche { 118dd11376bSBart Van Assche if (hba->vops && hba->vops->exit) 119dd11376bSBart Van Assche return hba->vops->exit(hba); 120dd11376bSBart Van Assche } 121dd11376bSBart Van Assche 122dd11376bSBart Van Assche static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba) 123dd11376bSBart Van Assche { 124dd11376bSBart Van Assche if (hba->vops && hba->vops->get_ufs_hci_version) 125dd11376bSBart Van Assche return hba->vops->get_ufs_hci_version(hba); 126dd11376bSBart Van Assche 127dd11376bSBart Van Assche return ufshcd_readl(hba, REG_UFS_VERSION); 128dd11376bSBart Van Assche } 129dd11376bSBart Van Assche 130dd11376bSBart Van Assche static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba, 131dd11376bSBart Van Assche bool up, enum ufs_notify_change_status status) 132dd11376bSBart Van Assche { 133dd11376bSBart Van Assche if (hba->vops && hba->vops->clk_scale_notify) 134dd11376bSBart Van Assche return hba->vops->clk_scale_notify(hba, up, status); 135dd11376bSBart Van Assche return 0; 136dd11376bSBart Van Assche } 137dd11376bSBart Van Assche 138dd11376bSBart Van Assche static inline void ufshcd_vops_event_notify(struct ufs_hba *hba, 139dd11376bSBart Van Assche enum ufs_event_type evt, 140dd11376bSBart Van Assche void *data) 141dd11376bSBart Van Assche { 142dd11376bSBart Van Assche if (hba->vops && hba->vops->event_notify) 143dd11376bSBart Van Assche hba->vops->event_notify(hba, evt, data); 144dd11376bSBart Van Assche } 145dd11376bSBart Van Assche 146dd11376bSBart Van Assche static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on, 147dd11376bSBart Van Assche enum ufs_notify_change_status status) 148dd11376bSBart Van Assche { 149dd11376bSBart Van Assche if (hba->vops && hba->vops->setup_clocks) 150dd11376bSBart Van Assche return hba->vops->setup_clocks(hba, on, status); 151dd11376bSBart Van Assche return 0; 152dd11376bSBart Van Assche } 153dd11376bSBart Van Assche 154dd11376bSBart Van Assche static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba, 155dd11376bSBart Van Assche bool status) 156dd11376bSBart Van Assche { 157dd11376bSBart Van Assche if (hba->vops && hba->vops->hce_enable_notify) 158dd11376bSBart Van Assche return hba->vops->hce_enable_notify(hba, status); 159dd11376bSBart Van Assche 160dd11376bSBart Van Assche return 0; 161dd11376bSBart Van Assche } 162dd11376bSBart Van Assche static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba, 163dd11376bSBart Van Assche bool status) 164dd11376bSBart Van Assche { 165dd11376bSBart Van Assche if (hba->vops && hba->vops->link_startup_notify) 166dd11376bSBart Van Assche return hba->vops->link_startup_notify(hba, status); 167dd11376bSBart Van Assche 168dd11376bSBart Van Assche return 0; 169dd11376bSBart Van Assche } 170dd11376bSBart Van Assche 171dd11376bSBart Van Assche static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba, 172dd11376bSBart Van Assche enum ufs_notify_change_status status, 173dd11376bSBart Van Assche struct ufs_pa_layer_attr *dev_max_params, 174dd11376bSBart Van Assche struct ufs_pa_layer_attr *dev_req_params) 175dd11376bSBart Van Assche { 176dd11376bSBart Van Assche if (hba->vops && hba->vops->pwr_change_notify) 177dd11376bSBart Van Assche return hba->vops->pwr_change_notify(hba, status, 178dd11376bSBart Van Assche dev_max_params, dev_req_params); 179dd11376bSBart Van Assche 180dd11376bSBart Van Assche return -ENOTSUPP; 181dd11376bSBart Van Assche } 182dd11376bSBart Van Assche 183dd11376bSBart Van Assche static inline void ufshcd_vops_setup_task_mgmt(struct ufs_hba *hba, 184dd11376bSBart Van Assche int tag, u8 tm_function) 185dd11376bSBart Van Assche { 186dd11376bSBart Van Assche if (hba->vops && hba->vops->setup_task_mgmt) 187dd11376bSBart Van Assche return hba->vops->setup_task_mgmt(hba, tag, tm_function); 188dd11376bSBart Van Assche } 189dd11376bSBart Van Assche 190dd11376bSBart Van Assche static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba, 191dd11376bSBart Van Assche enum uic_cmd_dme cmd, 192dd11376bSBart Van Assche enum ufs_notify_change_status status) 193dd11376bSBart Van Assche { 194dd11376bSBart Van Assche if (hba->vops && hba->vops->hibern8_notify) 195dd11376bSBart Van Assche return hba->vops->hibern8_notify(hba, cmd, status); 196dd11376bSBart Van Assche } 197dd11376bSBart Van Assche 198dd11376bSBart Van Assche static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba) 199dd11376bSBart Van Assche { 200dd11376bSBart Van Assche if (hba->vops && hba->vops->apply_dev_quirks) 201dd11376bSBart Van Assche return hba->vops->apply_dev_quirks(hba); 202dd11376bSBart Van Assche return 0; 203dd11376bSBart Van Assche } 204dd11376bSBart Van Assche 205dd11376bSBart Van Assche static inline void ufshcd_vops_fixup_dev_quirks(struct ufs_hba *hba) 206dd11376bSBart Van Assche { 207dd11376bSBart Van Assche if (hba->vops && hba->vops->fixup_dev_quirks) 208dd11376bSBart Van Assche hba->vops->fixup_dev_quirks(hba); 209dd11376bSBart Van Assche } 210dd11376bSBart Van Assche 211dd11376bSBart Van Assche static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op, 212dd11376bSBart Van Assche enum ufs_notify_change_status status) 213dd11376bSBart Van Assche { 214dd11376bSBart Van Assche if (hba->vops && hba->vops->suspend) 215dd11376bSBart Van Assche return hba->vops->suspend(hba, op, status); 216dd11376bSBart Van Assche 217dd11376bSBart Van Assche return 0; 218dd11376bSBart Van Assche } 219dd11376bSBart Van Assche 220dd11376bSBart Van Assche static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op) 221dd11376bSBart Van Assche { 222dd11376bSBart Van Assche if (hba->vops && hba->vops->resume) 223dd11376bSBart Van Assche return hba->vops->resume(hba, op); 224dd11376bSBart Van Assche 225dd11376bSBart Van Assche return 0; 226dd11376bSBart Van Assche } 227dd11376bSBart Van Assche 228dd11376bSBart Van Assche static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba) 229dd11376bSBart Van Assche { 230dd11376bSBart Van Assche if (hba->vops && hba->vops->dbg_register_dump) 231dd11376bSBart Van Assche hba->vops->dbg_register_dump(hba); 232dd11376bSBart Van Assche } 233dd11376bSBart Van Assche 234dd11376bSBart Van Assche static inline int ufshcd_vops_device_reset(struct ufs_hba *hba) 235dd11376bSBart Van Assche { 236dd11376bSBart Van Assche if (hba->vops && hba->vops->device_reset) 237dd11376bSBart Van Assche return hba->vops->device_reset(hba); 238dd11376bSBart Van Assche 239dd11376bSBart Van Assche return -EOPNOTSUPP; 240dd11376bSBart Van Assche } 241dd11376bSBart Van Assche 242dd11376bSBart Van Assche static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba, 243dd11376bSBart Van Assche struct devfreq_dev_profile *p, 244dd11376bSBart Van Assche struct devfreq_simple_ondemand_data *data) 245dd11376bSBart Van Assche { 246dd11376bSBart Van Assche if (hba->vops && hba->vops->config_scaling_param) 247dd11376bSBart Van Assche hba->vops->config_scaling_param(hba, p, data); 248dd11376bSBart Van Assche } 249dd11376bSBart Van Assche 250c2c38c57SManivannan Sadhasivam static inline void ufshcd_vops_reinit_notify(struct ufs_hba *hba) 251c2c38c57SManivannan Sadhasivam { 252c2c38c57SManivannan Sadhasivam if (hba->vops && hba->vops->reinit_notify) 253c2c38c57SManivannan Sadhasivam hba->vops->reinit_notify(hba); 254c2c38c57SManivannan Sadhasivam } 255c2c38c57SManivannan Sadhasivam 256c263b4efSAsutosh Das static inline int ufshcd_vops_mcq_config_resource(struct ufs_hba *hba) 257c263b4efSAsutosh Das { 258c263b4efSAsutosh Das if (hba->vops && hba->vops->mcq_config_resource) 259c263b4efSAsutosh Das return hba->vops->mcq_config_resource(hba); 260c263b4efSAsutosh Das 261c263b4efSAsutosh Das return -EOPNOTSUPP; 262c263b4efSAsutosh Das } 263c263b4efSAsutosh Das 2647224c806SAsutosh Das static inline int ufshcd_mcq_vops_get_hba_mac(struct ufs_hba *hba) 2657224c806SAsutosh Das { 2667224c806SAsutosh Das if (hba->vops && hba->vops->get_hba_mac) 2677224c806SAsutosh Das return hba->vops->get_hba_mac(hba); 2687224c806SAsutosh Das 2697224c806SAsutosh Das return -EOPNOTSUPP; 2707224c806SAsutosh Das } 2717224c806SAsutosh Das 2722468da61SAsutosh Das static inline int ufshcd_mcq_vops_op_runtime_config(struct ufs_hba *hba) 2732468da61SAsutosh Das { 2742468da61SAsutosh Das if (hba->vops && hba->vops->op_runtime_config) 2752468da61SAsutosh Das return hba->vops->op_runtime_config(hba); 2762468da61SAsutosh Das 2772468da61SAsutosh Das return -EOPNOTSUPP; 2782468da61SAsutosh Das } 2792468da61SAsutosh Das 280f87b2c41SAsutosh Das static inline int ufshcd_vops_get_outstanding_cqs(struct ufs_hba *hba, 281f87b2c41SAsutosh Das unsigned long *ocqs) 282f87b2c41SAsutosh Das { 283f87b2c41SAsutosh Das if (hba->vops && hba->vops->get_outstanding_cqs) 284f87b2c41SAsutosh Das return hba->vops->get_outstanding_cqs(hba, ocqs); 285f87b2c41SAsutosh Das 286f87b2c41SAsutosh Das return -EOPNOTSUPP; 287f87b2c41SAsutosh Das } 288f87b2c41SAsutosh Das 289edb0db05SCan Guo static inline int ufshcd_mcq_vops_config_esi(struct ufs_hba *hba) 290edb0db05SCan Guo { 291edb0db05SCan Guo if (hba->vops && hba->vops->config_esi) 292edb0db05SCan Guo return hba->vops->config_esi(hba); 293edb0db05SCan Guo 294edb0db05SCan Guo return -EOPNOTSUPP; 295edb0db05SCan Guo } 296edb0db05SCan Guo 29735d11ec2SKrzysztof Kozlowski extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[]; 298dd11376bSBart Van Assche 299dd11376bSBart Van Assche /** 300dd11376bSBart Van Assche * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN 301dd11376bSBart Van Assche * @scsi_lun: scsi LUN id 302dd11376bSBart Van Assche * 303dd11376bSBart Van Assche * Returns UPIU LUN id 304dd11376bSBart Van Assche */ 305dd11376bSBart Van Assche static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun) 306dd11376bSBart Van Assche { 307dd11376bSBart Van Assche if (scsi_is_wlun(scsi_lun)) 308dd11376bSBart Van Assche return (scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID) 309dd11376bSBart Van Assche | UFS_UPIU_WLUN_ID; 310dd11376bSBart Van Assche else 311dd11376bSBart Van Assche return scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID; 312dd11376bSBart Van Assche } 313dd11376bSBart Van Assche 314dd11376bSBart Van Assche int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask); 315dd11376bSBart Van Assche int ufshcd_write_ee_control(struct ufs_hba *hba); 31635d11ec2SKrzysztof Kozlowski int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask, 31735d11ec2SKrzysztof Kozlowski const u16 *other_mask, u16 set, u16 clr); 318dd11376bSBart Van Assche 319dd11376bSBart Van Assche static inline int ufshcd_update_ee_drv_mask(struct ufs_hba *hba, 320dd11376bSBart Van Assche u16 set, u16 clr) 321dd11376bSBart Van Assche { 322dd11376bSBart Van Assche return ufshcd_update_ee_control(hba, &hba->ee_drv_mask, 323dd11376bSBart Van Assche &hba->ee_usr_mask, set, clr); 324dd11376bSBart Van Assche } 325dd11376bSBart Van Assche 326dd11376bSBart Van Assche static inline int ufshcd_update_ee_usr_mask(struct ufs_hba *hba, 327dd11376bSBart Van Assche u16 set, u16 clr) 328dd11376bSBart Van Assche { 329dd11376bSBart Van Assche return ufshcd_update_ee_control(hba, &hba->ee_usr_mask, 330dd11376bSBart Van Assche &hba->ee_drv_mask, set, clr); 331dd11376bSBart Van Assche } 332dd11376bSBart Van Assche 333dd11376bSBart Van Assche static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba) 334dd11376bSBart Van Assche { 335dd11376bSBart Van Assche return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev); 336dd11376bSBart Van Assche } 337dd11376bSBart Van Assche 338dd11376bSBart Van Assche static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba) 339dd11376bSBart Van Assche { 340dd11376bSBart Van Assche return pm_runtime_put_sync(&hba->ufs_device_wlun->sdev_gendev); 341dd11376bSBart Van Assche } 342dd11376bSBart Van Assche 343dd11376bSBart Van Assche static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba) 344dd11376bSBart Van Assche { 345dd11376bSBart Van Assche pm_runtime_get_noresume(&hba->ufs_device_wlun->sdev_gendev); 346dd11376bSBart Van Assche } 347dd11376bSBart Van Assche 348dd11376bSBart Van Assche static inline int ufshcd_rpm_resume(struct ufs_hba *hba) 349dd11376bSBart Van Assche { 350dd11376bSBart Van Assche return pm_runtime_resume(&hba->ufs_device_wlun->sdev_gendev); 351dd11376bSBart Van Assche } 352dd11376bSBart Van Assche 353dd11376bSBart Van Assche static inline int ufshcd_rpm_put(struct ufs_hba *hba) 354dd11376bSBart Van Assche { 355dd11376bSBart Van Assche return pm_runtime_put(&hba->ufs_device_wlun->sdev_gendev); 356dd11376bSBart Van Assche } 357dd11376bSBart Van Assche 358dd11376bSBart Van Assche /** 359dd11376bSBart Van Assche * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor 360dd11376bSBart Van Assche * @dev_info: pointer of instance of struct ufs_dev_info 361dd11376bSBart Van Assche * @lun: LU number to check 362dd11376bSBart Van Assche * @return: true if the lun has a matching unit descriptor, false otherwise 363dd11376bSBart Van Assche */ 364b43678eaSBean Huo static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8 lun) 365dd11376bSBart Van Assche { 366dd11376bSBart Van Assche if (!dev_info || !dev_info->max_lu_supported) { 367dd11376bSBart Van Assche pr_err("Max General LU supported by UFS isn't initialized\n"); 368dd11376bSBart Van Assche return false; 369dd11376bSBart Van Assche } 370dd11376bSBart Van Assche return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported); 371dd11376bSBart Van Assche } 372dd11376bSBart Van Assche 37322a2d563SAsutosh Das static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q) 3744de243c4SAvri Altman __must_hold(&q->sq_lock) 37522a2d563SAsutosh Das { 37622a2d563SAsutosh Das u32 mask = q->max_entries - 1; 37722a2d563SAsutosh Das u32 val; 37822a2d563SAsutosh Das 37922a2d563SAsutosh Das q->sq_tail_slot = (q->sq_tail_slot + 1) & mask; 38022a2d563SAsutosh Das val = q->sq_tail_slot * sizeof(struct utp_transfer_req_desc); 38122a2d563SAsutosh Das writel(val, q->mcq_sq_tail); 38222a2d563SAsutosh Das } 38322a2d563SAsutosh Das 384f87b2c41SAsutosh Das static inline void ufshcd_mcq_update_cq_tail_slot(struct ufs_hw_queue *q) 385f87b2c41SAsutosh Das { 386f87b2c41SAsutosh Das u32 val = readl(q->mcq_cq_tail); 387f87b2c41SAsutosh Das 388f87b2c41SAsutosh Das q->cq_tail_slot = val / sizeof(struct cq_entry); 389f87b2c41SAsutosh Das } 390f87b2c41SAsutosh Das 391f87b2c41SAsutosh Das static inline bool ufshcd_mcq_is_cq_empty(struct ufs_hw_queue *q) 392f87b2c41SAsutosh Das { 393f87b2c41SAsutosh Das return q->cq_head_slot == q->cq_tail_slot; 394f87b2c41SAsutosh Das } 395f87b2c41SAsutosh Das 396f87b2c41SAsutosh Das static inline void ufshcd_mcq_inc_cq_head_slot(struct ufs_hw_queue *q) 397f87b2c41SAsutosh Das { 398f87b2c41SAsutosh Das q->cq_head_slot++; 399f87b2c41SAsutosh Das if (q->cq_head_slot == q->max_entries) 400f87b2c41SAsutosh Das q->cq_head_slot = 0; 401f87b2c41SAsutosh Das } 402f87b2c41SAsutosh Das 403f87b2c41SAsutosh Das static inline void ufshcd_mcq_update_cq_head(struct ufs_hw_queue *q) 404f87b2c41SAsutosh Das { 405f87b2c41SAsutosh Das writel(q->cq_head_slot * sizeof(struct cq_entry), q->mcq_cq_head); 406f87b2c41SAsutosh Das } 407f87b2c41SAsutosh Das 408f87b2c41SAsutosh Das static inline struct cq_entry *ufshcd_mcq_cur_cqe(struct ufs_hw_queue *q) 409f87b2c41SAsutosh Das { 410f87b2c41SAsutosh Das struct cq_entry *cqe = q->cqe_base_addr; 411f87b2c41SAsutosh Das 412f87b2c41SAsutosh Das return cqe + q->cq_head_slot; 413f87b2c41SAsutosh Das } 4148d729034SBao D. Nguyen 4158d729034SBao D. Nguyen static inline u32 ufshcd_mcq_get_sq_head_slot(struct ufs_hw_queue *q) 4168d729034SBao D. Nguyen { 4178d729034SBao D. Nguyen u32 val = readl(q->mcq_sq_head); 4188d729034SBao D. Nguyen 4198d729034SBao D. Nguyen return val / sizeof(struct utp_transfer_req_desc); 4208d729034SBao D. Nguyen } 4218d729034SBao D. Nguyen 422dd11376bSBart Van Assche #endif /* _UFSHCD_PRIV_H_ */ 423