pci_platform.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. */
  3. #ifndef _CNSS_PCI_PLATFORM_H
  4. #define _CNSS_PCI_PLATFORM_H
  5. #include "pci.h"
  6. #if IS_ENABLED(CONFIG_PCI_MSM)
  7. /**
  8. * _cnss_pci_enumerate() - Enumerate PCIe endpoints
  9. * @plat_priv: driver platform context pointer
  10. * @rc_num: root complex index that an endpoint connects to
  11. *
  12. * This function shall call corresponding PCIe root complex driver APIs
  13. * to power on root complex and enumerate the endpoint connected to it.
  14. *
  15. * Return: 0 for success, negative value for error
  16. */
  17. int _cnss_pci_enumerate(struct cnss_plat_data *plat_priv, u32 rc_num);
  18. /**
  19. * cnss_pci_assert_perst() - Assert PCIe PERST GPIO
  20. * @pci_priv: driver PCI bus context pointer
  21. *
  22. * This function shall call corresponding PCIe root complex driver APIs
  23. * to assert PCIe PERST GPIO.
  24. *
  25. * Return: 0 for success, negative value for error
  26. */
  27. int cnss_pci_assert_perst(struct cnss_pci_data *pci_priv);
  28. /**
  29. * cnss_pci_disable_pc() - Disable PCIe link power collapse from RC driver
  30. * @pci_priv: driver PCI bus context pointer
  31. * @vote: value to indicate disable (true) or enable (false)
  32. *
  33. * This function shall call corresponding PCIe root complex driver APIs
  34. * to disable PCIe power collapse. The purpose of this API is to avoid
  35. * root complex driver still controlling PCIe link from callbacks of
  36. * system suspend/resume. Device driver itself should take full control
  37. * of the link in such cases.
  38. *
  39. * Return: 0 for success, negative value for error
  40. */
  41. int cnss_pci_disable_pc(struct cnss_pci_data *pci_priv, bool vote);
  42. /**
  43. * cnss_pci_set_link_bandwidth() - Update number of lanes and speed of
  44. * PCIe link
  45. * @pci_priv: driver PCI bus context pointer
  46. * @link_speed: PCIe link gen speed
  47. * @link_width: number of lanes for PCIe link
  48. *
  49. * This function shall call corresponding PCIe root complex driver APIs
  50. * to update number of lanes and speed of the link.
  51. *
  52. * Return: 0 for success, negative value for error
  53. */
  54. int cnss_pci_set_link_bandwidth(struct cnss_pci_data *pci_priv,
  55. u16 link_speed, u16 link_width);
  56. /**
  57. * cnss_pci_set_max_link_speed() - Set the maximum speed PCIe can link up with
  58. * @pci_priv: driver PCI bus context pointer
  59. * @rc_num: root complex index that an endpoint connects to
  60. * @link_speed: PCIe link gen speed
  61. *
  62. * This function shall call corresponding PCIe root complex driver APIs
  63. * to update the maximum speed that PCIe can link up with.
  64. *
  65. * Return: 0 for success, negative value for error
  66. */
  67. int cnss_pci_set_max_link_speed(struct cnss_pci_data *pci_priv,
  68. u32 rc_num, u16 link_speed);
  69. /**
  70. * cnss_reg_pci_event() - Register for PCIe events
  71. * @pci_priv: driver PCI bus context pointer
  72. *
  73. * This function shall call corresponding PCIe root complex driver APIs
  74. * to register for PCIe events like link down or WAKE GPIO toggling etc.
  75. * The events should be based on PCIe root complex driver's capability.
  76. *
  77. * Return: 0 for success, negative value for error
  78. */
  79. int cnss_reg_pci_event(struct cnss_pci_data *pci_priv);
  80. void cnss_dereg_pci_event(struct cnss_pci_data *pci_priv);
  81. /**
  82. * cnss_wlan_adsp_pc_enable: Control ADSP power collapse setup
  83. * @dev: Platform driver pci private data structure
  84. * @control: Power collapse enable / disable
  85. *
  86. * This function controls ADSP power collapse (PC). It must be called
  87. * based on wlan state. ADSP power collapse during wlan RTPM suspend state
  88. * results in delay during periodic QMI stats PCI link up/down. This delay
  89. * causes additional power consumption.
  90. *
  91. * Result: 0 Success. negative error codes.
  92. */
  93. int cnss_wlan_adsp_pc_enable(struct cnss_pci_data *pci_priv,
  94. bool control);
  95. int cnss_set_pci_link(struct cnss_pci_data *pci_priv, bool link_up);
  96. int cnss_pci_prevent_l1(struct device *dev);
  97. void cnss_pci_allow_l1(struct device *dev);
  98. int cnss_pci_get_msi_assignment(struct cnss_pci_data *pci_priv);
  99. int cnss_pci_get_one_msi_assignment(struct cnss_pci_data *pci_priv);
  100. bool cnss_pci_fallback_one_msi(struct cnss_pci_data *pci_priv,
  101. int *num_vectors);
  102. bool cnss_pci_is_one_msi(struct cnss_pci_data *pci_priv);
  103. int cnss_pci_get_one_msi_mhi_irq_array_size(struct cnss_pci_data *pci_priv);
  104. bool cnss_pci_is_force_one_msi(struct cnss_pci_data *pci_priv);
  105. int cnss_pci_init_smmu(struct cnss_pci_data *pci_priv);
  106. void cnss_pci_update_drv_supported(struct cnss_pci_data *pci_priv);
  107. int cnss_pci_dsp_link_control(struct cnss_pci_data *pci_priv,
  108. bool link_enable);
  109. /**
  110. * _cnss_pci_get_reg_dump() - Dump PCIe RC registers for debug
  111. * @pci_priv: driver PCI bus context pointer
  112. * @buf: destination buffer pointer
  113. * @len: length of the buffer
  114. *
  115. * This function shall call corresponding PCIe root complex driver API
  116. * to dump PCIe RC registers for debug purpose.
  117. *
  118. * Return: 0 for success, negative value for error
  119. */
  120. int _cnss_pci_get_reg_dump(struct cnss_pci_data *pci_priv,
  121. u8 *buf, u32 len);
  122. int cnss_pci_set_dsp_link_status(struct cnss_pci_data *pci_priv,
  123. bool link_enable);
  124. int cnss_pci_get_dsp_link_status(struct cnss_pci_data *pci_priv);
  125. int cnss_pci_dsp_link_enable(struct cnss_pci_data *pci_priv);
  126. int cnss_pci_dsp_link_retrain(struct cnss_pci_data *pci_priv,
  127. u16 target_link_speed);
  128. #else
  129. int _cnss_pci_enumerate(struct cnss_plat_data *plat_priv, u32 rc_num)
  130. {
  131. return -EOPNOTSUPP;
  132. }
  133. int cnss_pci_assert_perst(struct cnss_pci_data *pci_priv)
  134. {
  135. return -EOPNOTSUPP;
  136. }
  137. int cnss_pci_disable_pc(struct cnss_pci_data *pci_priv, bool vote)
  138. {
  139. return 0;
  140. }
  141. int cnss_pci_set_link_bandwidth(struct cnss_pci_data *pci_priv,
  142. u16 link_speed, u16 link_width)
  143. {
  144. return 0;
  145. }
  146. int cnss_pci_set_max_link_speed(struct cnss_pci_data *pci_priv,
  147. u32 rc_num, u16 link_speed)
  148. {
  149. return 0;
  150. }
  151. int cnss_reg_pci_event(struct cnss_pci_data *pci_priv)
  152. {
  153. return 0;
  154. }
  155. void cnss_dereg_pci_event(struct cnss_pci_data *pci_priv) {}
  156. int cnss_wlan_adsp_pc_enable(struct cnss_pci_data *pci_priv, bool control)
  157. {
  158. return 0;
  159. }
  160. int cnss_set_pci_link(struct cnss_pci_data *pci_priv, bool link_up)
  161. {
  162. return 0;
  163. }
  164. int cnss_pci_prevent_l1(struct device *dev)
  165. {
  166. return 0;
  167. }
  168. EXPORT_SYMBOL(cnss_pci_prevent_l1);
  169. void cnss_pci_allow_l1(struct device *dev)
  170. {
  171. }
  172. EXPORT_SYMBOL(cnss_pci_allow_l1);
  173. int cnss_pci_get_msi_assignment(struct cnss_pci_data *pci_priv)
  174. {
  175. return 0;
  176. }
  177. int cnss_pci_init_smmu(struct cnss_pci_data *pci_priv)
  178. {
  179. return 0;
  180. }
  181. int _cnss_pci_get_reg_dump(struct cnss_pci_data *pci_priv,
  182. u8 *buf, u32 len)
  183. {
  184. return 0;
  185. }
  186. void cnss_pci_update_drv_supported(struct cnss_pci_data *pci_priv)
  187. {
  188. pci_priv->drv_supported = false;
  189. }
  190. int cnss_pci_dsp_link_control(struct cnss_pci_data *pci_priv,
  191. bool link_enable)
  192. {
  193. return -EOPNOTSUPP;
  194. }
  195. int cnss_pci_set_dsp_link_status(struct cnss_pci_data *pci_priv,
  196. bool link_enable)
  197. {
  198. return -EOPNOTSUPP;
  199. }
  200. int cnss_pci_get_dsp_link_status(struct cnss_pci_data *pci_priv)
  201. {
  202. return -EOPNOTSUPP;
  203. }
  204. int cnss_pci_dsp_link_enable(struct cnss_pci_data *pci_priv)
  205. {
  206. return -EOPNOTSUPP;
  207. }
  208. int cnss_pci_dsp_link_retrain(struct cnss_pci_data *pci_priv,
  209. u16 target_link_speed)
  210. {
  211. return -EOPNOTSUPP;
  212. }
  213. #endif /* CONFIG_PCI_MSM */
  214. static inline bool cnss_pci_get_drv_supported(struct cnss_pci_data *pci_priv)
  215. {
  216. return pci_priv->drv_supported;
  217. }
  218. #if IS_ENABLED(CONFIG_ARCH_QCOM)
  219. int cnss_pci_of_reserved_mem_device_init(struct cnss_pci_data *pci_priv);
  220. int cnss_pci_wake_gpio_init(struct cnss_pci_data *pci_priv);
  221. void cnss_pci_wake_gpio_deinit(struct cnss_pci_data *pci_priv);
  222. #endif /* CONFIG_ARCH_QCOM */
  223. #endif /* _CNSS_PCI_PLATFORM_H*/