hif_io32_pci.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef __HIF_IO32_PCI_H__
  27. #define __HIF_IO32_PCI_H__
  28. #ifdef HIF_PCI
  29. #include "hif_main.h"
  30. #include "regtable.h"
  31. #include "ce_reg.h"
  32. #include "cdf_atomic.h"
  33. #include "if_pci.h"
  34. /*
  35. * For maximum performance and no power management, set this to 1.
  36. * For power management at the cost of performance, set this to 0.
  37. */
  38. #define CONFIG_ATH_PCIE_MAX_PERF 0
  39. /*
  40. * For keeping the target awake till the driver is
  41. * loaded, set this to 1
  42. */
  43. #define CONFIG_ATH_PCIE_AWAKE_WHILE_DRIVER_LOAD 1
  44. /*
  45. * When CONFIG_ATH_PCIE_MAX_PERF is 0:
  46. * To use LIKELY hints, set this to 1 (slightly better performance, more power)
  47. * To ignore "LIKELY" hints, set this to 0 (slightly worse performance,
  48. * less power)
  49. */
  50. #if defined(CONFIG_ATH_PCIE_MAX_PERF)
  51. #define CONFIG_ATH_PCIE_ACCESS_LIKELY 0
  52. #else
  53. #define CONFIG_ATH_PCIE_ACCESS_LIKELY 1
  54. #endif
  55. /*
  56. * PCI-E L1 ASPPM sub-states
  57. * To enable clock gating in L1 state, set this to 1.
  58. * (less power, slightly more wakeup latency)
  59. * To disable clock gating in L1 state, set this to 0. (slighly more power)
  60. */
  61. #define CONFIG_PCIE_ENABLE_L1_CLOCK_GATE 1
  62. /*
  63. * PCIE_ACCESS_LOG_NUM specifies the number of
  64. * read/write records to store
  65. */
  66. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  67. #define PCIE_ACCESS_LOG_NUM 500
  68. #endif
  69. /* 64-bit MSI support */
  70. #define CONFIG_PCIE_64BIT_MSI 0
  71. /* BAR0 ready checking for AR6320v2 */
  72. #define PCIE_BAR0_READY_CHECKING 0
  73. /* AXI gating when L1, L2 to reduce power consumption */
  74. #define CONFIG_PCIE_ENABLE_AXI_CLK_GATE 0
  75. #define hif_read32_mb(addr) ioread32((void __iomem *)addr)
  76. #define hif_write32_mb(addr, value) \
  77. iowrite32((u32)(value), (void __iomem *)(addr))
  78. extern int hif_target_sleep_state_adjust(struct hif_softc *scn,
  79. bool sleep_ok,
  80. bool wait_for_it);
  81. #if CONFIG_ATH_PCIE_MAX_PERF
  82. #define A_TARGET_ACCESS_BEGIN(scn) \
  83. do {struct hif_softc *unused = scn; \
  84. unused = unused; } while (0)
  85. #define A_TARGET_ACCESS_END(scn) \
  86. do {struct hif_softc *unused = scn; \
  87. unused = unused; } while (0)
  88. #define A_TARGET_ACCESS_OK(scn) 1
  89. #define A_TARGET_ACCESS_LIKELY(scn) \
  90. do {struct hif_softc *unused = scn; \
  91. unused = unused; } while (0)
  92. #define A_TARGET_ACCESS_UNLIKELY(scn) \
  93. do {struct hif_softc *unused = scn; \
  94. unused = unused; } while (0)
  95. #define A_TARGET_READ(scn, offset) \
  96. hif_read32_mb(scn->mem + (offset))
  97. void war_pci_write32(char *addr, u32 offset, u32 value);
  98. #define A_TARGET_WRITE(scn, offset, value) \
  99. war_pci_write32(scn->mem, (offset), (value))
  100. #define A_TARGET_ACCESS_BEGIN_RET(scn) \
  101. do {struct hif_softc *unused = scn; \
  102. unused = unused; } while (0)
  103. #define A_TARGET_ACCESS_BEGIN_RET_EXT(scn, val) \
  104. do {struct hif_softc *unused = scn; \
  105. unused = unused; } while (0)
  106. #define A_TARGET_ACCESS_BEGIN_RET_PTR(scn) \
  107. do {struct hif_softc *unused = scn; \
  108. unused = unused; } while (0)
  109. #define A_TARGET_ACCESS_END_RET(scn) \
  110. do {struct hif_softc *unused = scn; \
  111. unused = unused; } while (0)
  112. #define A_TARGET_ACCESS_END_RET_EXT(scn, val) \
  113. do {struct hif_softc *unused = scn; \
  114. unused = unused; } while (0)
  115. #define A_TARGET_ACCESS_END_RET_PTR(scn) \
  116. do {struct hif_softc *unused = scn; \
  117. unused = unused; } while (0)
  118. #else /* CONFIG_ATH_PCIE_MAX_PERF */
  119. void war_pci_write32(char *addr, u32 offset, u32 value);
  120. #define A_TARGET_ACCESS_BEGIN_RET_EXT(scn, val) \
  121. do { \
  122. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  123. Q_TARGET_ACCESS_BEGIN(scn) < 0) \
  124. val = -1; \
  125. } while (0)
  126. #define A_TARGET_ACCESS_BEGIN_RET(scn) \
  127. do { \
  128. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  129. Q_TARGET_ACCESS_BEGIN(scn) < 0) \
  130. return ATH_ISR_NOSCHED; \
  131. } while (0)
  132. #define A_TARGET_ACCESS_BEGIN_RET_PTR(scn) \
  133. do { \
  134. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  135. Q_TARGET_ACCESS_BEGIN(scn) < 0) \
  136. return NULL; \
  137. } while (0)
  138. #define A_TARGET_ACCESS_BEGIN(scn) \
  139. do { \
  140. if (Q_TARGET_ACCESS_BEGIN(scn) < 0) \
  141. return; \
  142. } while (0)
  143. #define Q_TARGET_ACCESS_BEGIN(scn) \
  144. hif_target_sleep_state_adjust(scn, false, true)
  145. #define A_TARGET_ACCESS_END_RET(scn) \
  146. do { \
  147. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  148. Q_TARGET_ACCESS_END(scn) < 0) \
  149. return ATH_ISR_NOSCHED; \
  150. } while (0)
  151. #define A_TARGET_ACCESS_END_RET_EXT(scn, val) \
  152. do { \
  153. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  154. Q_TARGET_ACCESS_END(scn) < 0) \
  155. val = -1; \
  156. } while (0)
  157. #define A_TARGET_ACCESS_END_RET_PTR(scn) \
  158. do { \
  159. if (!WLAN_IS_EPPING_ENABLED(cds_get_conparam()) && \
  160. Q_TARGET_ACCESS_END(scn) < 0) \
  161. return NULL; \
  162. } while (0)
  163. #define A_TARGET_ACCESS_END(scn) \
  164. do { \
  165. if (Q_TARGET_ACCESS_END(scn) < 0) \
  166. return; \
  167. } while (0)
  168. #define Q_TARGET_ACCESS_END(scn) \
  169. hif_target_sleep_state_adjust(scn, true, false)
  170. #define A_TARGET_ACCESS_OK(scn) hif_target_forced_awake(scn)
  171. #if CONFIG_ATH_PCIE_ACCESS_LIKELY
  172. #define A_TARGET_ACCESS_LIKELY(scn) \
  173. hif_target_sleep_state_adjust(scn, false, false)
  174. #define A_TARGET_ACCESS_UNLIKELY(scn) \
  175. hif_target_sleep_state_adjust(scn, true, false)
  176. #else /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
  177. #define A_TARGET_ACCESS_LIKELY(scn) \
  178. do { \
  179. unsigned long unused = (unsigned long)(scn); \
  180. unused = unused; \
  181. } while (0)
  182. #define A_TARGET_ACCESS_UNLIKELY(scn) \
  183. do { \
  184. unsigned long unused = (unsigned long)(scn); \
  185. unused = unused; \
  186. } while (0)
  187. #endif /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
  188. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  189. extern uint32_t hif_target_read_checked(struct hif_softc *scn,
  190. uint32_t offset);
  191. extern void hif_target_write_checked(struct hif_softc *scn, uint32_t offset,
  192. uint32_t value);
  193. #define A_TARGET_READ(scn, offset) \
  194. hif_target_read_checked(scn, (offset))
  195. #define A_TARGET_WRITE(scn, offset, value) \
  196. hif_target_write_checked(scn, (offset), (value))
  197. #else /* CONFIG_ATH_PCIE_ACCESS_DEBUG */
  198. #define A_TARGET_READ(scn, offset) \
  199. hif_read32_mb(scn->mem + (offset))
  200. #define A_TARGET_WRITE(scn, offset, value) \
  201. war_pci_write32(scn->mem, (offset), (value))
  202. #endif
  203. #endif /* CONFIG_ATH_PCIE_MAX_PERF */
  204. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg);
  205. /**
  206. * ce_irq_enable() - ce_irq_enable
  207. * @scn: hif_softc
  208. * @ce_id: ce_id
  209. *
  210. * Return: void
  211. */
  212. static inline void ce_irq_enable(struct hif_softc *scn, int ce_id)
  213. {
  214. uint32_t tmp = 1 << ce_id;
  215. struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
  216. cdf_spin_lock_irqsave(&sc->irq_lock);
  217. scn->ce_irq_summary &= ~tmp;
  218. if (scn->ce_irq_summary == 0) {
  219. /* Enable Legacy PCI line interrupts */
  220. if (LEGACY_INTERRUPTS(sc) &&
  221. (scn->target_status != OL_TRGET_STATUS_RESET) &&
  222. (!cdf_atomic_read(&scn->link_suspended))) {
  223. hif_write32_mb(scn->mem +
  224. (SOC_CORE_BASE_ADDRESS |
  225. PCIE_INTR_ENABLE_ADDRESS),
  226. HOST_GROUP0_MASK);
  227. hif_read32_mb(scn->mem +
  228. (SOC_CORE_BASE_ADDRESS |
  229. PCIE_INTR_ENABLE_ADDRESS));
  230. }
  231. }
  232. if (scn->hif_init_done == true)
  233. A_TARGET_ACCESS_END(scn);
  234. cdf_spin_unlock_irqrestore(&sc->irq_lock);
  235. /* check for missed firmware crash */
  236. hif_fw_interrupt_handler(0, scn);
  237. }
  238. /**
  239. * ce_irq_disable() - ce_irq_disable
  240. * @scn: hif_softc
  241. * @ce_id: ce_id
  242. *
  243. * Return: void
  244. */
  245. static inline void ce_irq_disable(struct hif_softc *scn, int ce_id)
  246. {
  247. /* For Rome only need to wake up target */
  248. A_TARGET_ACCESS_BEGIN(scn);
  249. }
  250. /**
  251. * soc_wake_reset() - soc_wake_reset
  252. * @scn: hif_softc
  253. *
  254. * Return: void
  255. */
  256. static inline void soc_wake_reset(struct hif_softc *scn)
  257. {
  258. hif_write32_mb(scn->mem +
  259. PCIE_LOCAL_BASE_ADDRESS +
  260. PCIE_SOC_WAKE_ADDRESS,
  261. PCIE_SOC_WAKE_RESET);
  262. }
  263. #endif /* HIF_PCI */
  264. #endif /* __HIF_IO32_PCI_H__ */