pci.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _PCI_H_
  18. #define _PCI_H_
  19. #include <linux/interrupt.h>
  20. #include "hw.h"
  21. #include "ce.h"
  22. /* FW dump area */
  23. #define REG_DUMP_COUNT_QCA988X 60
  24. /*
  25. * maximum number of bytes that can be handled atomically by DiagRead/DiagWrite
  26. */
  27. #define DIAG_TRANSFER_LIMIT 2048
  28. /*
  29. * maximum number of bytes that can be
  30. * handled atomically by DiagRead/DiagWrite
  31. */
  32. #define DIAG_TRANSFER_LIMIT 2048
  33. struct bmi_xfer {
  34. struct completion done;
  35. bool wait_for_resp;
  36. u32 resp_len;
  37. };
  38. /*
  39. * PCI-specific Target state
  40. *
  41. * NOTE: Structure is shared between Host software and Target firmware!
  42. *
  43. * Much of this may be of interest to the Host so
  44. * HOST_INTEREST->hi_interconnect_state points here
  45. * (and all members are 32-bit quantities in order to
  46. * facilitate Host access). In particular, Host software is
  47. * required to initialize pipe_cfg_addr and svc_to_pipe_map.
  48. */
  49. struct pcie_state {
  50. /* Pipe configuration Target address */
  51. /* NB: ce_pipe_config[CE_COUNT] */
  52. u32 pipe_cfg_addr;
  53. /* Service to pipe map Target address */
  54. /* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */
  55. u32 svc_to_pipe_map;
  56. /* number of MSI interrupts requested */
  57. u32 msi_requested;
  58. /* number of MSI interrupts granted */
  59. u32 msi_granted;
  60. /* Message Signalled Interrupt address */
  61. u32 msi_addr;
  62. /* Base data */
  63. u32 msi_data;
  64. /*
  65. * Data for firmware interrupt;
  66. * MSI data for other interrupts are
  67. * in various SoC registers
  68. */
  69. u32 msi_fw_intr_data;
  70. /* PCIE_PWR_METHOD_* */
  71. u32 power_mgmt_method;
  72. /* PCIE_CONFIG_FLAG_* */
  73. u32 config_flags;
  74. };
  75. /* PCIE_CONFIG_FLAG definitions */
  76. #define PCIE_CONFIG_FLAG_ENABLE_L1 0x0000001
  77. /* Host software's Copy Engine configuration. */
  78. #define CE_ATTR_FLAGS 0
  79. /*
  80. * Configuration information for a Copy Engine pipe.
  81. * Passed from Host to Target during startup (one per CE).
  82. *
  83. * NOTE: Structure is shared between Host software and Target firmware!
  84. */
  85. struct ce_pipe_config {
  86. u32 pipenum;
  87. u32 pipedir;
  88. u32 nentries;
  89. u32 nbytes_max;
  90. u32 flags;
  91. u32 reserved;
  92. };
  93. /*
  94. * Directions for interconnect pipe configuration.
  95. * These definitions may be used during configuration and are shared
  96. * between Host and Target.
  97. *
  98. * Pipe Directions are relative to the Host, so PIPEDIR_IN means
  99. * "coming IN over air through Target to Host" as with a WiFi Rx operation.
  100. * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
  101. * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
  102. * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
  103. * over the interconnect.
  104. */
  105. #define PIPEDIR_NONE 0
  106. #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
  107. #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
  108. #define PIPEDIR_INOUT 3 /* bidirectional */
  109. /* Establish a mapping between a service/direction and a pipe. */
  110. struct service_to_pipe {
  111. u32 service_id;
  112. u32 pipedir;
  113. u32 pipenum;
  114. };
  115. enum ath10k_pci_features {
  116. ATH10K_PCI_FEATURE_MSI_X = 0,
  117. ATH10K_PCI_FEATURE_SOC_POWER_SAVE = 1,
  118. /* keep last */
  119. ATH10K_PCI_FEATURE_COUNT
  120. };
  121. /* Per-pipe state. */
  122. struct ath10k_pci_pipe {
  123. /* Handle of underlying Copy Engine */
  124. struct ath10k_ce_pipe *ce_hdl;
  125. /* Our pipe number; facilitiates use of pipe_info ptrs. */
  126. u8 pipe_num;
  127. /* Convenience back pointer to hif_ce_state. */
  128. struct ath10k *hif_ce_state;
  129. size_t buf_sz;
  130. /* protects compl_free and num_send_allowed */
  131. spinlock_t pipe_lock;
  132. struct ath10k_pci *ar_pci;
  133. struct tasklet_struct intr;
  134. };
  135. struct ath10k_pci {
  136. struct pci_dev *pdev;
  137. struct device *dev;
  138. struct ath10k *ar;
  139. void __iomem *mem;
  140. DECLARE_BITMAP(features, ATH10K_PCI_FEATURE_COUNT);
  141. /*
  142. * Number of MSI interrupts granted, 0 --> using legacy PCI line
  143. * interrupts.
  144. */
  145. int num_msi_intrs;
  146. struct tasklet_struct intr_tq;
  147. struct tasklet_struct msi_fw_err;
  148. struct tasklet_struct early_irq_tasklet;
  149. int started;
  150. atomic_t keep_awake_count;
  151. bool verified_awake;
  152. struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
  153. struct ath10k_hif_cb msg_callbacks_current;
  154. /* Copy Engine used for Diagnostic Accesses */
  155. struct ath10k_ce_pipe *ce_diag;
  156. /* FIXME: document what this really protects */
  157. spinlock_t ce_lock;
  158. /* Map CE id to ce_state */
  159. struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
  160. };
  161. static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
  162. {
  163. return ar->hif.priv;
  164. }
  165. static inline u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
  166. {
  167. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  168. return ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
  169. }
  170. static inline void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
  171. {
  172. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  173. iowrite32(val, ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
  174. }
  175. #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
  176. #define PCIE_WAKE_TIMEOUT 5000 /* 5ms */
  177. #define BAR_NUM 0
  178. #define CDC_WAR_MAGIC_STR 0xceef0000
  179. #define CDC_WAR_DATA_CE 4
  180. /*
  181. * TODO: Should be a function call specific to each Target-type.
  182. * This convoluted macro converts from Target CPU Virtual Address Space to CE
  183. * Address Space. As part of this process, we conservatively fetch the current
  184. * PCIE_BAR. MOST of the time, this should match the upper bits of PCI space
  185. * for this device; but that's not guaranteed.
  186. */
  187. #define TARG_CPU_SPACE_TO_CE_SPACE(ar, pci_addr, addr) \
  188. (((ioread32((pci_addr)+(SOC_CORE_BASE_ADDRESS| \
  189. CORE_CTRL_ADDRESS)) & 0x7ff) << 21) | \
  190. 0x100000 | ((addr) & 0xfffff))
  191. /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
  192. #define DIAG_ACCESS_CE_TIMEOUT_MS 10
  193. /*
  194. * This API allows the Host to access Target registers directly
  195. * and relatively efficiently over PCIe.
  196. * This allows the Host to avoid extra overhead associated with
  197. * sending a message to firmware and waiting for a response message
  198. * from firmware, as is done on other interconnects.
  199. *
  200. * Yet there is some complexity with direct accesses because the
  201. * Target's power state is not known a priori. The Host must issue
  202. * special PCIe reads/writes in order to explicitly wake the Target
  203. * and to verify that it is awake and will remain awake.
  204. *
  205. * Usage:
  206. *
  207. * Use ath10k_pci_read32 and ath10k_pci_write32 to access Target space.
  208. * These calls must be bracketed by ath10k_pci_wake and
  209. * ath10k_pci_sleep. A single BEGIN/END pair is adequate for
  210. * multiple READ/WRITE operations.
  211. *
  212. * Use ath10k_pci_wake to put the Target in a state in
  213. * which it is legal for the Host to directly access it. This
  214. * may involve waking the Target from a low power state, which
  215. * may take up to 2Ms!
  216. *
  217. * Use ath10k_pci_sleep to tell the Target that as far as
  218. * this code path is concerned, it no longer needs to remain
  219. * directly accessible. BEGIN/END is under a reference counter;
  220. * multiple code paths may issue BEGIN/END on a single targid.
  221. */
  222. static inline void ath10k_pci_write32(struct ath10k *ar, u32 offset,
  223. u32 value)
  224. {
  225. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  226. iowrite32(value, ar_pci->mem + offset);
  227. }
  228. static inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
  229. {
  230. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  231. return ioread32(ar_pci->mem + offset);
  232. }
  233. static inline u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
  234. {
  235. return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
  236. }
  237. static inline void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
  238. {
  239. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
  240. }
  241. int ath10k_do_pci_wake(struct ath10k *ar);
  242. void ath10k_do_pci_sleep(struct ath10k *ar);
  243. static inline int ath10k_pci_wake(struct ath10k *ar)
  244. {
  245. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  246. if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
  247. return ath10k_do_pci_wake(ar);
  248. return 0;
  249. }
  250. static inline void ath10k_pci_sleep(struct ath10k *ar)
  251. {
  252. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  253. if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
  254. ath10k_do_pci_sleep(ar);
  255. }
  256. #endif /* _PCI_H_ */