msm_pcie.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */
  3. #ifndef __MSM_PCIE_H
  4. #define __MSM_PCIE_H
  5. #include <linux/types.h>
  6. #include <linux/pci.h>
  7. enum msm_pcie_config {
  8. MSM_PCIE_CONFIG_INVALID = 0,
  9. MSM_PCIE_CONFIG_LINKDOWN = BIT(0),
  10. MSM_PCIE_CONFIG_NO_RECOVERY = BIT(1),
  11. MSM_PCIE_CONFIG_NO_L1SS_TO = BIT(2),
  12. MSM_PCIE_CONFIG_NO_DRV_PC = BIT(3),
  13. MSM_PCIE_CONFIG_FORCE_SUSP = BIT(4),
  14. };
  15. enum msm_pcie_pm_opt {
  16. MSM_PCIE_DRV_SUSPEND,
  17. MSM_PCIE_SUSPEND,
  18. MSM_PCIE_RESUME,
  19. MSM_PCIE_DISABLE_PC,
  20. MSM_PCIE_ENABLE_PC,
  21. MSM_PCIE_HANDLE_LINKDOWN,
  22. MSM_PCIE_DRV_PC_CTRL,
  23. };
  24. enum msm_pcie_event {
  25. MSM_PCIE_EVENT_INVALID = 0,
  26. MSM_PCIE_EVENT_LINKDOWN = 0x1,
  27. MSM_PCIE_EVENT_LINKUP = 0x2,
  28. MSM_PCIE_EVENT_WAKEUP = 0x4,
  29. MSM_PCIE_EVENT_L1SS_TIMEOUT = BIT(3),
  30. MSM_PCIE_EVENT_DRV_CONNECT = BIT(4),
  31. MSM_PCIE_EVENT_DRV_DISCONNECT = BIT(5),
  32. MSM_PCIE_EVENT_LINK_RECOVER = BIT(6),
  33. };
  34. enum msm_pcie_trigger {
  35. MSM_PCIE_TRIGGER_CALLBACK,
  36. MSM_PCIE_TRIGGER_COMPLETION,
  37. };
  38. struct msm_pcie_notify {
  39. enum msm_pcie_event event;
  40. void *user;
  41. void *data;
  42. u32 options;
  43. };
  44. struct msm_pcie_register_event {
  45. struct list_head node;
  46. u32 events;
  47. void *user;
  48. enum msm_pcie_trigger mode;
  49. void (*callback)(struct msm_pcie_notify *notify);
  50. struct msm_pcie_notify notify;
  51. struct completion *completion;
  52. u32 options;
  53. };
  54. void msm_msi_config_access(struct irq_domain *domain, bool allow);
  55. void msm_msi_config(struct irq_domain *domain);
  56. int msm_msi_init(struct device *dev);
  57. #if IS_ENABLED(CONFIG_PCI_MSM)
  58. /**
  59. * msm_pcie_set_target_link_speed - sets the upper bound of GEN speed PCIe can
  60. * link up with
  61. * @rc_idx: root complex port number that endpoint is connected to
  62. * @target_link_speed: new target link speed PCIe can link up with
  63. * @force: override DT specified link speed
  64. *
  65. * Provide PCIe clients the option to control upper bound of GEN speed PCIe
  66. * can link up with. Clients may choose only GEN speed within root complex's
  67. * controller capability or up to what is defined in devicetree,
  68. * qcom,target-link-speed.
  69. *
  70. * Client may also pass 0 for target_link_speed to have PCIe root complex
  71. * reset and use the default TLS.
  72. *
  73. * Return 0 on success, negative value on error
  74. */
  75. int msm_pcie_set_target_link_speed(u32 rc_idx, u32 target_link_speed,
  76. bool force);
  77. /**
  78. * msm_pcie_allow_l1 - allow PCIe link to re-enter L1
  79. * @pci_dev: client's pci device structure
  80. *
  81. * This function gives PCIe clients the control to allow the link to re-enter
  82. * L1. Should only be used after msm_pcie_prevent_l1 has been called.
  83. */
  84. void msm_pcie_allow_l1(struct pci_dev *pci_dev);
  85. /**
  86. * msm_pcie_prevent_l1 - keeps PCIe link out of L1
  87. * @pci_dev: client's pci device structure
  88. *
  89. * This function gives PCIe clients the control to exit and prevent the link
  90. * from entering L1.
  91. *
  92. * Return 0 on success, negative value on error
  93. */
  94. int msm_pcie_prevent_l1(struct pci_dev *pci_dev);
  95. /**
  96. * msm_pcie_set_link_bandwidth - updates the number of lanes and speed of PCIe
  97. * link.
  98. * @pci_dev: client's pci device structure
  99. * @target_link_speed: gen speed
  100. * @target_link_width: number of lanes
  101. *
  102. * This function gives PCIe clients the control to update the number of lanes
  103. * and gen speed of the link.
  104. *
  105. * Return: 0 on success, negative value on error
  106. */
  107. int msm_pcie_set_link_bandwidth(struct pci_dev *pci_dev, u16 target_link_speed,
  108. u16 target_link_width);
  109. /**
  110. * msm_pcie_l1ss_timeout_disable - disable L1ss timeout feature
  111. * @pci_dev: client's pci device structure
  112. *
  113. * This function gives PCIe clients the control to disable L1ss timeout
  114. * feature.
  115. */
  116. void msm_pcie_l1ss_timeout_disable(struct pci_dev *pci_dev);
  117. /**
  118. * msm_pcie_l1ss_timeout_enable - enable L1ss timeout feature
  119. * @pci_dev: client's pci device structure
  120. *
  121. * This function gives PCIe clients the control to enable L1ss timeout
  122. * feature.
  123. */
  124. void msm_pcie_l1ss_timeout_enable(struct pci_dev *pci_dev);
  125. /**
  126. * msm_pcie_pm_control - control the power state of a PCIe link.
  127. * @pm_opt: power management operation
  128. * @busnr: bus number of PCIe endpoint
  129. * @user: handle of the caller
  130. * @data: private data from the caller
  131. * @options: options for pm control
  132. *
  133. * This function gives PCIe endpoint device drivers the control to change
  134. * the power state of a PCIe link for their device.
  135. *
  136. * Return: 0 on success, negative value on error
  137. */
  138. int msm_pcie_pm_control(enum msm_pcie_pm_opt pm_opt, u32 busnr, void *user,
  139. void *data, u32 options);
  140. /**
  141. * msm_pcie_register_event - register an event with PCIe bus driver.
  142. * @reg: event structure
  143. *
  144. * This function gives PCIe endpoint device drivers an option to register
  145. * events with PCIe bus driver.
  146. *
  147. * Return: 0 on success, negative value on error
  148. */
  149. int msm_pcie_register_event(struct msm_pcie_register_event *reg);
  150. /**
  151. * msm_pcie_deregister_event - deregister an event with PCIe bus driver.
  152. * @reg: event structure
  153. *
  154. * This function gives PCIe endpoint device drivers an option to deregister
  155. * events with PCIe bus driver.
  156. *
  157. * Return: 0 on success, negative value on error
  158. */
  159. int msm_pcie_deregister_event(struct msm_pcie_register_event *reg);
  160. /**
  161. * msm_pcie_enumerate - enumerate Endpoints.
  162. * @rc_idx: RC that Endpoints connect to.
  163. *
  164. * This function enumerates Endpoints connected to RC.
  165. *
  166. * Return: 0 on success, negative value on error
  167. */
  168. int msm_pcie_enumerate(u32 rc_idx);
  169. /**
  170. * msm_pcie_deenumerate - deenumerates the Endpoints.
  171. * @rc_idx: RC that Endpoints connect to.
  172. *
  173. * This function de-enumerates Endpoints connected to RC.
  174. *
  175. * Return: 0 on success, negative value on error
  176. */
  177. int msm_pcie_deenumerate(u32 rc_idx);
  178. /*
  179. * msm_pcie_debug_info - run a PCIe specific debug testcase.
  180. * @dev: pci device structure
  181. * @option: specifies which PCIe debug testcase to execute
  182. * @base: PCIe specific range
  183. * @offset: offset of destination register
  184. * @mask: mask the bit(s) of destination register
  185. * @value: value to be written to destination register
  186. *
  187. * This function gives PCIe endpoint device drivers the control to
  188. * run a debug testcase.
  189. *
  190. * Return: 0 on success, negative value on error
  191. */
  192. int msm_pcie_debug_info(struct pci_dev *dev, u32 option, u32 base,
  193. u32 offset, u32 mask, u32 value);
  194. /*
  195. * msm_pcie_reg_dump - dump pcie regsters for debug
  196. * @pci_dev: pci device structure
  197. * @buffer: destination buffer address
  198. * @len: length of buffer
  199. *
  200. * This functions dumps PCIE registers for debug. Sould be used when
  201. * link is already enabled
  202. */
  203. int msm_pcie_reg_dump(struct pci_dev *pci_dev, u8 *buff, u32 len);
  204. /*
  205. * msm_pcie_dsp_link_control - enable/disable DSP link
  206. * @pci_dev: pci device structure, endpoint of this DSP
  207. * @link_enable true to enable, false to disable
  208. *
  209. * This function enable(include training)/disable link between PCIe
  210. * switch DSP and endpoint attached.
  211. * Return: 0 on success, negative value on error
  212. */
  213. int msm_pcie_dsp_link_control(struct pci_dev *pci_dev,
  214. bool link_enable);
  215. #else /* !CONFIG_PCI_MSM */
  216. static inline int msm_pcie_pm_control(enum msm_pcie_pm_opt pm_opt, u32 busnr,
  217. void *user, void *data, u32 options)
  218. {
  219. return -ENODEV;
  220. }
  221. static inline int msm_pcie_set_target_link_speed(u32 rc_idx,
  222. u32 target_link_speed)
  223. {
  224. return -ENODEV;
  225. }
  226. static inline void msm_pcie_allow_l1(struct pci_dev *pci_dev)
  227. {
  228. }
  229. static inline int msm_pcie_prevent_l1(struct pci_dev *pci_dev)
  230. {
  231. return -ENODEV;
  232. }
  233. static inline int msm_pcie_l1ss_timeout_disable(struct pci_dev *pci_dev)
  234. {
  235. return -ENODEV;
  236. }
  237. static inline int msm_pcie_l1ss_timeout_enable(struct pci_dev *pci_dev)
  238. {
  239. return -ENODEV;
  240. }
  241. static inline int msm_pcie_register_event(struct msm_pcie_register_event *reg)
  242. {
  243. return -ENODEV;
  244. }
  245. static inline int msm_pcie_deregister_event(struct msm_pcie_register_event *reg)
  246. {
  247. return -ENODEV;
  248. }
  249. static inline int msm_pcie_enumerate(u32 rc_idx)
  250. {
  251. return -ENODEV;
  252. }
  253. static inline int msm_pcie_deenumerate(u32 rc_idx)
  254. {
  255. return -ENODEV;
  256. }
  257. static inline int msm_pcie_debug_info(struct pci_dev *dev, u32 option, u32 base,
  258. u32 offset, u32 mask, u32 value)
  259. {
  260. return -ENODEV;
  261. }
  262. static inline int msm_pcie_reg_dump(struct pci_dev *pci_dev, u8 *buff, u32 len)
  263. {
  264. return -ENODEV;
  265. }
  266. static inline int msm_pcie_dsp_link_control(struct pci_dev *pci_dev,
  267. bool link_enable)
  268. {
  269. return -ENODEV;
  270. }
  271. #endif /* CONFIG_PCI_MSM */
  272. #ifdef CONFIG_SEC_PCIE_L1SS
  273. enum l1ss_ctrl_ids {
  274. L1SS_SYSFS,
  275. L1SS_MST,
  276. L1SS_AUDIO,
  277. L1SS_MAX
  278. };
  279. extern void sec_pcie_set_use_ep_loaded(struct pci_dev *dev);
  280. extern void sec_pcie_set_ep_driver_loaded(struct pci_dev *dev, bool is_loaded);
  281. extern int sec_pcie_l1ss_enable(int ctrl_id);
  282. extern int sec_pcie_l1ss_disable(int ctrl_id);
  283. #else
  284. static inline void sec_pcie_set_use_ep_loaded(dev) {}
  285. static inline void sec_pcie_set_ep_driver_loaded(dev, is_loaded) {}
  286. static inline int sec_pcie_l1ss_enable(int ctrl_id)
  287. {
  288. return -ENODEV;
  289. }
  290. static inline int sec_pcie_l1ss_disable(int ctrl_id)
  291. {
  292. return -ENODEV;
  293. }
  294. #endif
  295. #endif /* __MSM_PCIE_H */