pci.h 7.6 KB

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