pci.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CNSS_PCI_H
  7. #define _CNSS_PCI_H
  8. #include <linux/cma.h>
  9. #include <linux/iommu.h>
  10. #include <linux/qcom-iommu-util.h>
  11. #include <linux/mhi.h>
  12. #if IS_ENABLED(CONFIG_MHI_BUS_MISC)
  13. #include <linux/mhi_misc.h>
  14. #endif
  15. #if IS_ENABLED(CONFIG_PCI_MSM)
  16. #include <linux/msm_pcie.h>
  17. #endif
  18. #include <linux/of_reserved_mem.h>
  19. #include <linux/pci.h>
  20. #include <linux/sched_clock.h>
  21. #include "main.h"
  22. #define PM_OPTIONS_DEFAULT 0
  23. #define PCI_LINK_DOWN 0
  24. #ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
  25. #define LINK_TRAINING_RETRY_MAX_TIMES 2
  26. #else
  27. #define LINK_TRAINING_RETRY_MAX_TIMES 3
  28. #endif
  29. #define LINK_TRAINING_RETRY_DELAY_MS 500
  30. #define MSI_USERS 4
  31. #define CNSS_MHI_IN_MISSION_MODE(ee) (ee == MHI_EE_AMSS || \
  32. ee == MHI_EE_WFW || \
  33. ee == MHI_EE_FP)
  34. enum cnss_mhi_state {
  35. CNSS_MHI_INIT,
  36. CNSS_MHI_DEINIT,
  37. CNSS_MHI_POWER_ON,
  38. CNSS_MHI_POWERING_OFF,
  39. CNSS_MHI_POWER_OFF,
  40. CNSS_MHI_FORCE_POWER_OFF,
  41. CNSS_MHI_SUSPEND,
  42. CNSS_MHI_RESUME,
  43. CNSS_MHI_TRIGGER_RDDM,
  44. CNSS_MHI_RDDM,
  45. CNSS_MHI_RDDM_DONE,
  46. };
  47. enum pci_link_status {
  48. PCI_GEN1,
  49. PCI_GEN2,
  50. PCI_DEF,
  51. };
  52. enum cnss_rtpm_id {
  53. RTPM_ID_CNSS,
  54. RTPM_ID_MHI,
  55. RTPM_ID_MAX,
  56. };
  57. enum cnss_pci_reg_dev_mask {
  58. REG_MASK_QCA6390,
  59. REG_MASK_QCA6490,
  60. REG_MASK_KIWI,
  61. REG_MASK_MANGO,
  62. REG_MASK_PEACH,
  63. };
  64. enum cnss_smmu_fault_time {
  65. SMMU_CB_ENTRY,
  66. SMMU_CB_DOORBELL_RING,
  67. SMMU_CB_EXIT,
  68. SMMU_CB_MAX,
  69. };
  70. struct cnss_msi_user {
  71. char *name;
  72. int num_vectors;
  73. u32 base_vector;
  74. };
  75. struct cnss_msi_config {
  76. int total_vectors;
  77. int total_users;
  78. struct cnss_msi_user *users;
  79. };
  80. struct cnss_pci_reg {
  81. char *name;
  82. u32 offset;
  83. };
  84. struct cnss_pci_debug_reg {
  85. u32 offset;
  86. u32 val;
  87. };
  88. struct cnss_misc_reg {
  89. unsigned long dev_mask;
  90. u8 wr;
  91. u32 offset;
  92. u32 val;
  93. };
  94. struct cnss_pm_stats {
  95. atomic_t runtime_get;
  96. atomic_t runtime_put;
  97. atomic_t runtime_get_id[RTPM_ID_MAX];
  98. atomic_t runtime_put_id[RTPM_ID_MAX];
  99. u64 runtime_get_timestamp_id[RTPM_ID_MAX];
  100. u64 runtime_put_timestamp_id[RTPM_ID_MAX];
  101. };
  102. struct cnss_print_optimize {
  103. int msi_log_chk[MSI_USERS];
  104. int msi_addr_chk;
  105. };
  106. struct cnss_pci_data {
  107. struct pci_dev *pci_dev;
  108. struct cnss_plat_data *plat_priv;
  109. const struct pci_device_id *pci_device_id;
  110. u32 device_id;
  111. u16 revision_id;
  112. u64 dma_bit_mask;
  113. struct cnss_wlan_driver *driver_ops;
  114. u8 pci_link_state;
  115. u8 pci_link_down_ind;
  116. struct pci_saved_state *saved_state;
  117. struct pci_saved_state *default_state;
  118. #if IS_ENABLED(CONFIG_PCI_MSM)
  119. struct msm_pcie_register_event msm_pci_event;
  120. #endif
  121. struct cnss_pm_stats pm_stats;
  122. atomic_t auto_suspended;
  123. atomic_t drv_connected;
  124. u8 drv_connected_last;
  125. u32 qmi_send_usage_count;
  126. u16 def_link_speed;
  127. u16 def_link_width;
  128. u16 cur_link_speed;
  129. int wake_gpio;
  130. int wake_irq;
  131. u32 wake_counter;
  132. u8 monitor_wake_intr;
  133. struct iommu_domain *iommu_domain;
  134. u8 smmu_s1_enable;
  135. dma_addr_t smmu_iova_start;
  136. size_t smmu_iova_len;
  137. dma_addr_t smmu_iova_ipa_start;
  138. dma_addr_t smmu_iova_ipa_current;
  139. size_t smmu_iova_ipa_len;
  140. void __iomem *bar;
  141. struct cnss_msi_config *msi_config;
  142. u32 msi_ep_base_data;
  143. u32 msix_addr;
  144. struct mhi_controller *mhi_ctrl;
  145. unsigned long mhi_state;
  146. u32 remap_window;
  147. struct timer_list dev_rddm_timer;
  148. struct timer_list boot_debug_timer;
  149. struct delayed_work time_sync_work;
  150. u8 disable_pc;
  151. struct mutex bus_lock; /* mutex for suspend and resume bus */
  152. struct cnss_pci_debug_reg *debug_reg;
  153. struct cnss_misc_reg *wcss_reg;
  154. struct cnss_misc_reg *pcie_reg;
  155. struct cnss_misc_reg *wlaon_reg;
  156. struct cnss_misc_reg *syspm_reg;
  157. unsigned long misc_reg_dev_mask;
  158. u8 iommu_geometry;
  159. bool drv_supported;
  160. bool is_smmu_fault;
  161. unsigned long long smmu_fault_timestamp[SMMU_CB_MAX];
  162. };
  163. static inline void cnss_set_pci_priv(struct pci_dev *pci_dev, void *data)
  164. {
  165. pci_set_drvdata(pci_dev, data);
  166. }
  167. static inline struct cnss_pci_data *cnss_get_pci_priv(struct pci_dev *pci_dev)
  168. {
  169. return pci_get_drvdata(pci_dev);
  170. }
  171. static inline struct cnss_plat_data *cnss_pci_priv_to_plat_priv(void *bus_priv)
  172. {
  173. struct cnss_pci_data *pci_priv = bus_priv;
  174. return pci_priv->plat_priv;
  175. }
  176. static inline void cnss_pci_set_monitor_wake_intr(void *bus_priv, bool val)
  177. {
  178. struct cnss_pci_data *pci_priv = bus_priv;
  179. pci_priv->monitor_wake_intr = val;
  180. }
  181. static inline bool cnss_pci_get_monitor_wake_intr(void *bus_priv)
  182. {
  183. struct cnss_pci_data *pci_priv = bus_priv;
  184. return pci_priv->monitor_wake_intr;
  185. }
  186. static inline void cnss_pci_set_auto_suspended(void *bus_priv, int val)
  187. {
  188. struct cnss_pci_data *pci_priv = bus_priv;
  189. atomic_set(&pci_priv->auto_suspended, val);
  190. }
  191. static inline int cnss_pci_get_auto_suspended(void *bus_priv)
  192. {
  193. struct cnss_pci_data *pci_priv = bus_priv;
  194. return atomic_read(&pci_priv->auto_suspended);
  195. }
  196. static inline void cnss_pci_set_drv_connected(void *bus_priv, int val)
  197. {
  198. struct cnss_pci_data *pci_priv = bus_priv;
  199. atomic_set(&pci_priv->drv_connected, val);
  200. }
  201. static inline int cnss_pci_get_drv_connected(void *bus_priv)
  202. {
  203. struct cnss_pci_data *pci_priv = bus_priv;
  204. return atomic_read(&pci_priv->drv_connected);
  205. }
  206. void cnss_mhi_controller_set_base(struct cnss_pci_data *pci_priv,
  207. phys_addr_t base);
  208. int cnss_pci_check_link_status(struct cnss_pci_data *pci_priv);
  209. int cnss_suspend_pci_link(struct cnss_pci_data *pci_priv);
  210. int cnss_resume_pci_link(struct cnss_pci_data *pci_priv);
  211. int cnss_pci_recover_link_down(struct cnss_pci_data *pci_priv);
  212. int cnss_pci_init(struct cnss_plat_data *plat_priv);
  213. void cnss_pci_deinit(struct cnss_plat_data *plat_priv);
  214. void cnss_pci_add_fw_prefix_name(struct cnss_pci_data *pci_priv,
  215. char *prefix_name, char *name);
  216. int cnss_pci_alloc_fw_mem(struct cnss_pci_data *pci_priv);
  217. int cnss_pci_alloc_qdss_mem(struct cnss_pci_data *pci_priv);
  218. void cnss_pci_free_qdss_mem(struct cnss_pci_data *pci_priv);
  219. int cnss_pci_load_m3(struct cnss_pci_data *pci_priv);
  220. void cnss_pci_free_blob_mem(struct cnss_pci_data *pci_priv);
  221. int cnss_pci_handle_dev_sol_irq(struct cnss_pci_data *pci_priv);
  222. int cnss_pci_start_mhi(struct cnss_pci_data *pci_priv);
  223. void cnss_pci_collect_dump_info(struct cnss_pci_data *pci_priv, bool in_panic);
  224. #ifdef CONFIG_CNSS2_SSR_DRIVER_DUMP
  225. void cnss_pci_collect_host_dump_info(struct cnss_pci_data *pci_priv);
  226. #else
  227. static inline
  228. void cnss_pci_collect_host_dump_info(struct cnss_pci_data *pci_priv)
  229. {
  230. }
  231. #endif
  232. void cnss_pci_device_crashed(struct cnss_pci_data *pci_priv);
  233. void cnss_pci_clear_dump_info(struct cnss_pci_data *pci_priv);
  234. u32 cnss_pci_get_wake_msi(struct cnss_pci_data *pci_priv);
  235. int cnss_pci_force_fw_assert_hdlr(struct cnss_pci_data *pci_priv);
  236. int cnss_pci_qmi_send_get(struct cnss_pci_data *pci_priv);
  237. int cnss_pci_qmi_send_put(struct cnss_pci_data *pci_priv);
  238. void cnss_pci_fw_boot_timeout_hdlr(struct cnss_pci_data *pci_priv);
  239. int cnss_pci_call_driver_probe(struct cnss_pci_data *pci_priv);
  240. int cnss_pci_call_driver_remove(struct cnss_pci_data *pci_priv);
  241. int cnss_pci_dev_powerup(struct cnss_pci_data *pci_priv);
  242. int cnss_pci_dev_shutdown(struct cnss_pci_data *pci_priv);
  243. int cnss_pci_dev_crash_shutdown(struct cnss_pci_data *pci_priv);
  244. int cnss_pci_dev_ramdump(struct cnss_pci_data *pci_priv);
  245. int cnss_pci_register_driver_hdlr(struct cnss_pci_data *pci_priv, void *data);
  246. int cnss_pci_unregister_driver_hdlr(struct cnss_pci_data *pci_priv);
  247. int cnss_pci_call_driver_modem_status(struct cnss_pci_data *pci_priv,
  248. int modem_current_status);
  249. void cnss_pci_pm_runtime_show_usage_count(struct cnss_pci_data *pci_priv);
  250. int cnss_pci_pm_request_resume(struct cnss_pci_data *pci_priv);
  251. int cnss_pci_pm_runtime_resume(struct cnss_pci_data *pci_priv);
  252. int cnss_pci_pm_runtime_get(struct cnss_pci_data *pci_priv,
  253. enum cnss_rtpm_id id);
  254. int cnss_pci_pm_runtime_get_sync(struct cnss_pci_data *pci_priv,
  255. enum cnss_rtpm_id id);
  256. void cnss_pci_pm_runtime_get_noresume(struct cnss_pci_data *pci_priv,
  257. enum cnss_rtpm_id id);
  258. int cnss_pci_pm_runtime_put_autosuspend(struct cnss_pci_data *pci_priv,
  259. enum cnss_rtpm_id id);
  260. void cnss_pci_pm_runtime_put_noidle(struct cnss_pci_data *pci_priv,
  261. enum cnss_rtpm_id id);
  262. void cnss_pci_pm_runtime_mark_last_busy(struct cnss_pci_data *pci_priv);
  263. int cnss_pci_update_status(struct cnss_pci_data *pci_priv,
  264. enum cnss_driver_status status);
  265. int cnss_pci_call_driver_uevent(struct cnss_pci_data *pci_priv,
  266. enum cnss_driver_status status, void *data);
  267. int cnss_pcie_is_device_down(struct cnss_pci_data *pci_priv);
  268. int cnss_pci_suspend_bus(struct cnss_pci_data *pci_priv);
  269. int cnss_pci_resume_bus(struct cnss_pci_data *pci_priv);
  270. int cnss_pci_debug_reg_read(struct cnss_pci_data *pci_priv, u32 offset,
  271. u32 *val, bool raw_access);
  272. int cnss_pci_debug_reg_write(struct cnss_pci_data *pci_priv, u32 offset,
  273. u32 val, bool raw_access);
  274. int cnss_pci_get_iova(struct cnss_pci_data *pci_priv, u64 *addr, u64 *size);
  275. int cnss_pci_get_iova_ipa(struct cnss_pci_data *pci_priv, u64 *addr,
  276. u64 *size);
  277. bool cnss_pci_is_smmu_s1_enabled(struct cnss_pci_data *pci_priv);
  278. void cnss_pci_handle_linkdown(struct cnss_pci_data *pci_priv);
  279. int cnss_pci_update_time_sync_period(struct cnss_pci_data *pci_priv,
  280. unsigned int time_sync_period);
  281. int cnss_pci_set_therm_cdev_state(struct cnss_pci_data *pci_priv,
  282. unsigned long thermal_state,
  283. int tcdev_id);
  284. int cnss_pci_get_user_msi_assignment(struct cnss_pci_data *pci_priv,
  285. char *user_name,
  286. int *num_vectors,
  287. u32 *user_base_data,
  288. u32 *base_vector);
  289. void cnss_register_iommu_fault_handler_irq(struct cnss_pci_data *pci_priv);
  290. #endif /* _CNSS_PCI_H */