ufshcd-priv.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _UFSHCD_PRIV_H_
  3. #define _UFSHCD_PRIV_H_
  4. #include <linux/pm_runtime.h>
  5. #include "ufshcd.h"
  6. static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba)
  7. {
  8. return !hba->shutting_down;
  9. }
  10. void ufshcd_schedule_eh_work(struct ufs_hba *hba);
  11. static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
  12. struct ufs_hba *hba)
  13. {
  14. return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
  15. }
  16. static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)
  17. {
  18. if (hba->dev_info.wb_buffer_type == WB_BUF_MODE_LU_DEDICATED)
  19. return hba->dev_info.wb_dedicated_lu;
  20. return 0;
  21. }
  22. #ifdef CONFIG_SCSI_UFS_HWMON
  23. void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask);
  24. void ufs_hwmon_remove(struct ufs_hba *hba);
  25. void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask);
  26. #else
  27. static inline void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask) {}
  28. static inline void ufs_hwmon_remove(struct ufs_hba *hba) {}
  29. static inline void ufs_hwmon_notify_event(struct ufs_hba *hba, u8 ee_mask) {}
  30. #endif
  31. int ufshcd_read_desc_param(struct ufs_hba *hba,
  32. enum desc_idn desc_id,
  33. int desc_index,
  34. u8 param_offset,
  35. u8 *param_read_buf,
  36. u8 param_size);
  37. int ufshcd_query_attr_retry(struct ufs_hba *hba, enum query_opcode opcode,
  38. enum attr_idn idn, u8 index, u8 selector,
  39. u32 *attr_val);
  40. int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
  41. enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);
  42. int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
  43. enum flag_idn idn, u8 index, bool *flag_res);
  44. void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
  45. #define SD_ASCII_STD true
  46. #define SD_RAW false
  47. int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
  48. u8 **buf, bool ascii);
  49. int ufshcd_hold(struct ufs_hba *hba, bool async);
  50. void ufshcd_release(struct ufs_hba *hba);
  51. void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
  52. int *desc_length);
  53. int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
  54. int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
  55. struct utp_upiu_req *req_upiu,
  56. struct utp_upiu_req *rsp_upiu,
  57. int msgcode,
  58. u8 *desc_buff, int *buff_len,
  59. enum query_opcode desc_op);
  60. int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
  61. /* Wrapper functions for safely calling variant operations */
  62. static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
  63. {
  64. if (hba->vops)
  65. return hba->vops->name;
  66. return "";
  67. }
  68. static inline void ufshcd_vops_exit(struct ufs_hba *hba)
  69. {
  70. if (hba->vops && hba->vops->exit)
  71. return hba->vops->exit(hba);
  72. }
  73. static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba)
  74. {
  75. if (hba->vops && hba->vops->get_ufs_hci_version)
  76. return hba->vops->get_ufs_hci_version(hba);
  77. return ufshcd_readl(hba, REG_UFS_VERSION);
  78. }
  79. static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba,
  80. bool up, enum ufs_notify_change_status status)
  81. {
  82. if (hba->vops && hba->vops->clk_scale_notify)
  83. return hba->vops->clk_scale_notify(hba, up, status);
  84. return 0;
  85. }
  86. static inline void ufshcd_vops_event_notify(struct ufs_hba *hba,
  87. enum ufs_event_type evt,
  88. void *data)
  89. {
  90. if (hba->vops && hba->vops->event_notify)
  91. hba->vops->event_notify(hba, evt, data);
  92. }
  93. static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on,
  94. enum ufs_notify_change_status status)
  95. {
  96. if (hba->vops && hba->vops->setup_clocks)
  97. return hba->vops->setup_clocks(hba, on, status);
  98. return 0;
  99. }
  100. static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba,
  101. bool status)
  102. {
  103. if (hba->vops && hba->vops->hce_enable_notify)
  104. return hba->vops->hce_enable_notify(hba, status);
  105. return 0;
  106. }
  107. static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba,
  108. bool status)
  109. {
  110. if (hba->vops && hba->vops->link_startup_notify)
  111. return hba->vops->link_startup_notify(hba, status);
  112. return 0;
  113. }
  114. static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba,
  115. enum ufs_notify_change_status status,
  116. struct ufs_pa_layer_attr *dev_max_params,
  117. struct ufs_pa_layer_attr *dev_req_params)
  118. {
  119. if (hba->vops && hba->vops->pwr_change_notify)
  120. return hba->vops->pwr_change_notify(hba, status,
  121. dev_max_params, dev_req_params);
  122. return -ENOTSUPP;
  123. }
  124. static inline void ufshcd_vops_setup_task_mgmt(struct ufs_hba *hba,
  125. int tag, u8 tm_function)
  126. {
  127. if (hba->vops && hba->vops->setup_task_mgmt)
  128. return hba->vops->setup_task_mgmt(hba, tag, tm_function);
  129. }
  130. static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba,
  131. enum uic_cmd_dme cmd,
  132. enum ufs_notify_change_status status)
  133. {
  134. if (hba->vops && hba->vops->hibern8_notify)
  135. return hba->vops->hibern8_notify(hba, cmd, status);
  136. }
  137. static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba)
  138. {
  139. if (hba->vops && hba->vops->apply_dev_quirks)
  140. return hba->vops->apply_dev_quirks(hba);
  141. return 0;
  142. }
  143. static inline void ufshcd_vops_fixup_dev_quirks(struct ufs_hba *hba)
  144. {
  145. if (hba->vops && hba->vops->fixup_dev_quirks)
  146. hba->vops->fixup_dev_quirks(hba);
  147. }
  148. static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op,
  149. enum ufs_notify_change_status status)
  150. {
  151. if (hba->vops && hba->vops->suspend)
  152. return hba->vops->suspend(hba, op, status);
  153. return 0;
  154. }
  155. static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op)
  156. {
  157. if (hba->vops && hba->vops->resume)
  158. return hba->vops->resume(hba, op);
  159. return 0;
  160. }
  161. static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
  162. {
  163. if (hba->vops && hba->vops->dbg_register_dump)
  164. hba->vops->dbg_register_dump(hba);
  165. }
  166. static inline int ufshcd_vops_device_reset(struct ufs_hba *hba)
  167. {
  168. if (hba->vops && hba->vops->device_reset)
  169. return hba->vops->device_reset(hba);
  170. return -EOPNOTSUPP;
  171. }
  172. static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba,
  173. struct devfreq_dev_profile *p,
  174. struct devfreq_simple_ondemand_data *data)
  175. {
  176. if (hba->vops && hba->vops->config_scaling_param)
  177. hba->vops->config_scaling_param(hba, p, data);
  178. }
  179. /**
  180. * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN
  181. * @scsi_lun: scsi LUN id
  182. *
  183. * Returns UPIU LUN id
  184. */
  185. static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun)
  186. {
  187. if (scsi_is_wlun(scsi_lun))
  188. return (scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID)
  189. | UFS_UPIU_WLUN_ID;
  190. else
  191. return scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID;
  192. }
  193. int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);
  194. int ufshcd_write_ee_control(struct ufs_hba *hba);
  195. static inline int ufshcd_update_ee_drv_mask(struct ufs_hba *hba,
  196. u16 set, u16 clr)
  197. {
  198. return ufshcd_update_ee_control(hba, &hba->ee_drv_mask,
  199. &hba->ee_usr_mask, set, clr);
  200. }
  201. static inline int ufshcd_update_ee_usr_mask(struct ufs_hba *hba,
  202. u16 set, u16 clr)
  203. {
  204. return ufshcd_update_ee_control(hba, &hba->ee_usr_mask,
  205. &hba->ee_drv_mask, set, clr);
  206. }
  207. static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
  208. {
  209. return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev);
  210. }
  211. static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)
  212. {
  213. return pm_runtime_put_sync(&hba->ufs_device_wlun->sdev_gendev);
  214. }
  215. static inline void ufshcd_rpm_get_noresume(struct ufs_hba *hba)
  216. {
  217. pm_runtime_get_noresume(&hba->ufs_device_wlun->sdev_gendev);
  218. }
  219. static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
  220. {
  221. return pm_runtime_resume(&hba->ufs_device_wlun->sdev_gendev);
  222. }
  223. static inline int ufshcd_rpm_put(struct ufs_hba *hba)
  224. {
  225. return pm_runtime_put(&hba->ufs_device_wlun->sdev_gendev);
  226. }
  227. /**
  228. * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
  229. * @dev_info: pointer of instance of struct ufs_dev_info
  230. * @lun: LU number to check
  231. * @return: true if the lun has a matching unit descriptor, false otherwise
  232. */
  233. static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info,
  234. u8 lun, u8 param_offset)
  235. {
  236. if (!dev_info || !dev_info->max_lu_supported) {
  237. pr_err("Max General LU supported by UFS isn't initialized\n");
  238. return false;
  239. }
  240. /* WB is available only for the logical unit from 0 to 7 */
  241. if (param_offset == UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS)
  242. return lun < UFS_UPIU_MAX_WB_LUN_ID;
  243. return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported);
  244. }
  245. #endif /* _UFSHCD_PRIV_H_ */