Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 
0003 #ifndef _UFSHCD_PRIV_H_
0004 #define _UFSHCD_PRIV_H_
0005 
0006 #include <linux/pm_runtime.h>
0007 #include <ufs/ufshcd.h>
0008 
0009 static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba)
0010 {
0011     return !hba->shutting_down;
0012 }
0013 
0014 void ufshcd_schedule_eh_work(struct ufs_hba *hba);
0015 
0016 static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
0017                             struct ufs_hba *hba)
0018 {
0019     return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
0020 }
0021 
0022 static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)
0023 {
0024     if (hba->dev_info.wb_buffer_type == WB_BUF_MODE_LU_DEDICATED)
0025         return hba->dev_info.wb_dedicated_lu;
0026     return 0;
0027 }
0028 
0029 #ifdef CONFIG_SCSI_UFS_HWMON
0030 void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask);
0031 void ufs_hwmon_remove(struct ufs_hba *hba);
0032 void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask);
0033 #else
0034 static inline void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask) {}
0035 static inline void ufs_hwmon_remove(struct ufs_hba *hba) {}
0036 static inline void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask) {}
0037 #endif
0038 
0039 int ufshcd_read_desc_param(struct ufs_hba *hba,
0040                enum desc_idn desc_id,
0041                int desc_index,
0042                u8 param_offset,
0043                u8 *param_read_buf,
0044                u8 param_size);
0045 int ufshcd_query_attr_retry(struct ufs_hba *hba, enum query_opcode opcode,
0046                 enum attr_idn idn, u8 index, u8 selector,
0047                 u32 *attr_val);
0048 int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
0049               enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);
0050 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
0051     enum flag_idn idn, u8 index, bool *flag_res);
0052 void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
0053 
0054 #define SD_ASCII_STD true
0055 #define SD_RAW false
0056 int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
0057                 u8 **buf, bool ascii);
0058 
0059 int ufshcd_hold(struct ufs_hba *hba, bool async);
0060 void ufshcd_release(struct ufs_hba *hba);
0061 
0062 void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
0063                   int *desc_length);
0064 
0065 int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
0066 
0067 int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
0068                  struct utp_upiu_req *req_upiu,
0069                  struct utp_upiu_req *rsp_upiu,
0070                  int msgcode,
0071                  u8 *desc_buff, int *buff_len,
0072                  enum query_opcode desc_op);
0073 
0074 int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
0075 
0076 /* Wrapper functions for safely calling variant operations */
0077 static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
0078 {
0079     if (hba->vops)
0080         return hba->vops->name;
0081     return "";
0082 }
0083 
0084 static inline void ufshcd_vops_exit(struct ufs_hba *hba)
0085 {
0086     if (hba->vops && hba->vops->exit)
0087         return hba->vops->exit(hba);
0088 }
0089 
0090 static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba)
0091 {
0092     if (hba->vops && hba->vops->get_ufs_hci_version)
0093         return hba->vops->get_ufs_hci_version(hba);
0094 
0095     return ufshcd_readl(hba, REG_UFS_VERSION);
0096 }
0097 
0098 static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba,
0099             bool up, enum ufs_notify_change_status status)
0100 {
0101     if (hba->vops && hba->vops->clk_scale_notify)
0102         return hba->vops->clk_scale_notify(hba, up, status);
0103     return 0;
0104 }
0105 
0106 static inline void ufshcd_vops_event_notify(struct ufs_hba *hba,
0107                         enum ufs_event_type evt,
0108                         void *data)
0109 {
0110     if (hba->vops && hba->vops->event_notify)
0111         hba->vops->event_notify(hba, evt, data);
0112 }
0113 
0114 static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on,
0115                     enum ufs_notify_change_status status)
0116 {
0117     if (hba->vops && hba->vops->setup_clocks)
0118         return hba->vops->setup_clocks(hba, on, status);
0119     return 0;
0120 }
0121 
0122 static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba,
0123                         bool status)
0124 {
0125     if (hba->vops && hba->vops->hce_enable_notify)
0126         return hba->vops->hce_enable_notify(hba, status);
0127 
0128     return 0;
0129 }
0130 static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba,
0131                         bool status)
0132 {
0133     if (hba->vops && hba->vops->link_startup_notify)
0134         return hba->vops->link_startup_notify(hba, status);
0135 
0136     return 0;
0137 }
0138 
0139 static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba,
0140                   enum ufs_notify_change_status status,
0141                   struct ufs_pa_layer_attr *dev_max_params,
0142                   struct ufs_pa_layer_attr *dev_req_params)
0143 {
0144     if (hba->vops && hba->vops->pwr_change_notify)
0145         return hba->vops->pwr_change_notify(hba, status,
0146                     dev_max_params, dev_req_params);
0147 
0148     return -ENOTSUPP;
0149 }
0150 
0151 static inline void ufshcd_vops_setup_task_mgmt(struct ufs_hba *hba,
0152                     int tag, u8 tm_function)
0153 {
0154     if (hba->vops && hba->vops->setup_task_mgmt)
0155         return hba->vops->setup_task_mgmt(hba, tag, tm_function);
0156 }
0157 
0158 static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba,
0159                     enum uic_cmd_dme cmd,
0160                     enum ufs_notify_change_status status)
0161 {
0162     if (hba->vops && hba->vops->hibern8_notify)
0163         return hba->vops->hibern8_notify(hba, cmd, status);
0164 }
0165 
0166 static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba)
0167 {
0168     if (hba->vops && hba->vops->apply_dev_quirks)
0169         return hba->vops->apply_dev_quirks(hba);
0170     return 0;
0171 }
0172 
0173 static inline void ufshcd_vops_fixup_dev_quirks(struct ufs_hba *hba)
0174 {
0175     if (hba->vops && hba->vops->fixup_dev_quirks)
0176         hba->vops->fixup_dev_quirks(hba);
0177 }
0178 
0179 static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op,
0180                 enum ufs_notify_change_status status)
0181 {
0182     if (hba->vops && hba->vops->suspend)
0183         return hba->vops->suspend(hba, op, status);
0184 
0185     return 0;
0186 }
0187 
0188 static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op)
0189 {
0190     if (hba->vops && hba->vops->resume)
0191         return hba->vops->resume(hba, op);
0192 
0193     return 0;
0194 }
0195 
0196 static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
0197 {
0198     if (hba->vops && hba->vops->dbg_register_dump)
0199         hba->vops->dbg_register_dump(hba);
0200 }
0201 
0202 static inline int ufshcd_vops_device_reset(struct ufs_hba *hba)
0203 {
0204     if (hba->vops && hba->vops->device_reset)
0205         return hba->vops->device_reset(hba);
0206 
0207     return -EOPNOTSUPP;
0208 }
0209 
0210 static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba,
0211         struct devfreq_dev_profile *p,
0212         struct devfreq_simple_ondemand_data *data)
0213 {
0214     if (hba->vops && hba->vops->config_scaling_param)
0215         hba->vops->config_scaling_param(hba, p, data);
0216 }
0217 
0218 extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];
0219 
0220 /**
0221  * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN
0222  * @scsi_lun: scsi LUN id
0223  *
0224  * Returns UPIU LUN id
0225  */
0226 static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun)
0227 {
0228     if (scsi_is_wlun(scsi_lun))
0229         return (scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID)
0230             | UFS_UPIU_WLUN_ID;
0231     else
0232         return scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID;
0233 }
0234 
0235 int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);
0236 int ufshcd_write_ee_control(struct ufs_hba *hba);
0237 int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,
0238                  const u16 *other_mask, u16 set, u16 clr);
0239 
0240 static inline int ufshcd_update_ee_drv_mask(struct ufs_hba *hba,
0241                         u16 set, u16 clr)
0242 {
0243     return ufshcd_update_ee_control(hba, &hba->ee_drv_mask,
0244                     &hba->ee_usr_mask, set, clr);
0245 }
0246 
0247 static inline int ufshcd_update_ee_usr_mask(struct ufs_hba *hba,
0248                         u16 set, u16 clr)
0249 {
0250     return ufshcd_update_ee_control(hba, &hba->ee_usr_mask,
0251                     &hba->ee_drv_mask, set, clr);
0252 }
0253 
0254 static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
0255 {
0256     return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev);
0257 }
0258 
0259 static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
0260 {
0261     return pm_runtime_put_sync(&hba->ufs_device_wlun->sdev_gendev);
0262 }
0263 
0264 static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
0265 {
0266     pm_runtime_get_noresume(&hba->ufs_device_wlun->sdev_gendev);
0267 }
0268 
0269 static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
0270 {
0271     return pm_runtime_resume(&hba->ufs_device_wlun->sdev_gendev);
0272 }
0273 
0274 static inline int ufshcd_rpm_put(struct ufs_hba *hba)
0275 {
0276     return pm_runtime_put(&hba->ufs_device_wlun->sdev_gendev);
0277 }
0278 
0279 /**
0280  * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
0281  * @dev_info: pointer of instance of struct ufs_dev_info
0282  * @lun: LU number to check
0283  * @return: true if the lun has a matching unit descriptor, false otherwise
0284  */
0285 static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info,
0286         u8 lun, u8 param_offset)
0287 {
0288     if (!dev_info || !dev_info->max_lu_supported) {
0289         pr_err("Max General LU supported by UFS isn't initialized\n");
0290         return false;
0291     }
0292     /* WB is available only for the logical unit from 0 to 7 */
0293     if (param_offset == UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS)
0294         return lun < UFS_UPIU_MAX_WB_LUN_ID;
0295     return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported);
0296 }
0297 
0298 #endif /* _UFSHCD_PRIV_H_ */