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