pci.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. /*
  23. * maximum number of bytes that can be handled atomically by DiagRead/DiagWrite
  24. */
  25. #define DIAG_TRANSFER_LIMIT 2048
  26. /*
  27. * maximum number of bytes that can be
  28. * handled atomically by DiagRead/DiagWrite
  29. */
  30. #define DIAG_TRANSFER_LIMIT 2048
  31. struct bmi_xfer {
  32. bool tx_done;
  33. bool rx_done;
  34. bool wait_for_resp;
  35. u32 resp_len;
  36. };
  37. /*
  38. * PCI-specific Target state
  39. *
  40. * NOTE: Structure is shared between Host software and Target firmware!
  41. *
  42. * Much of this may be of interest to the Host so
  43. * HOST_INTEREST->hi_interconnect_state points here
  44. * (and all members are 32-bit quantities in order to
  45. * facilitate Host access). In particular, Host software is
  46. * required to initialize pipe_cfg_addr and svc_to_pipe_map.
  47. */
  48. struct pcie_state {
  49. /* Pipe configuration Target address */
  50. /* NB: ce_pipe_config[CE_COUNT] */
  51. u32 pipe_cfg_addr;
  52. /* Service to pipe map Target address */
  53. /* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */
  54. u32 svc_to_pipe_map;
  55. /* number of MSI interrupts requested */
  56. u32 msi_requested;
  57. /* number of MSI interrupts granted */
  58. u32 msi_granted;
  59. /* Message Signalled Interrupt address */
  60. u32 msi_addr;
  61. /* Base data */
  62. u32 msi_data;
  63. /*
  64. * Data for firmware interrupt;
  65. * MSI data for other interrupts are
  66. * in various SoC registers
  67. */
  68. u32 msi_fw_intr_data;
  69. /* PCIE_PWR_METHOD_* */
  70. u32 power_mgmt_method;
  71. /* PCIE_CONFIG_FLAG_* */
  72. u32 config_flags;
  73. };
  74. /* PCIE_CONFIG_FLAG definitions */
  75. #define PCIE_CONFIG_FLAG_ENABLE_L1 0x0000001
  76. /* Host software's Copy Engine configuration. */
  77. #define CE_ATTR_FLAGS 0
  78. /*
  79. * Configuration information for a Copy Engine pipe.
  80. * Passed from Host to Target during startup (one per CE).
  81. *
  82. * NOTE: Structure is shared between Host software and Target firmware!
  83. */
  84. struct ce_pipe_config {
  85. __le32 pipenum;
  86. __le32 pipedir;
  87. __le32 nentries;
  88. __le32 nbytes_max;
  89. __le32 flags;
  90. __le32 reserved;
  91. };
  92. /*
  93. * Directions for interconnect pipe configuration.
  94. * These definitions may be used during configuration and are shared
  95. * between Host and Target.
  96. *
  97. * Pipe Directions are relative to the Host, so PIPEDIR_IN means
  98. * "coming IN over air through Target to Host" as with a WiFi Rx operation.
  99. * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
  100. * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
  101. * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
  102. * over the interconnect.
  103. */
  104. #define PIPEDIR_NONE 0
  105. #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
  106. #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
  107. #define PIPEDIR_INOUT 3 /* bidirectional */
  108. /* Establish a mapping between a service/direction and a pipe. */
  109. struct service_to_pipe {
  110. __le32 service_id;
  111. __le32 pipedir;
  112. __le32 pipenum;
  113. };
  114. /* Per-pipe state. */
  115. struct ath10k_pci_pipe {
  116. /* Handle of underlying Copy Engine */
  117. struct ath10k_ce_pipe *ce_hdl;
  118. /* Our pipe number; facilitiates use of pipe_info ptrs. */
  119. u8 pipe_num;
  120. /* Convenience back pointer to hif_ce_state. */
  121. struct ath10k *hif_ce_state;
  122. size_t buf_sz;
  123. /* protects compl_free and num_send_allowed */
  124. spinlock_t pipe_lock;
  125. struct ath10k_pci *ar_pci;
  126. struct tasklet_struct intr;
  127. };
  128. struct ath10k_pci_supp_chip {
  129. u32 dev_id;
  130. u32 rev_id;
  131. };
  132. struct ath10k_pci {
  133. struct pci_dev *pdev;
  134. struct device *dev;
  135. struct ath10k *ar;
  136. void __iomem *mem;
  137. size_t mem_len;
  138. /*
  139. * Number of MSI interrupts granted, 0 --> using legacy PCI line
  140. * interrupts.
  141. */
  142. int num_msi_intrs;
  143. struct tasklet_struct intr_tq;
  144. struct tasklet_struct msi_fw_err;
  145. struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
  146. /* Copy Engine used for Diagnostic Accesses */
  147. struct ath10k_ce_pipe *ce_diag;
  148. /* FIXME: document what this really protects */
  149. spinlock_t ce_lock;
  150. /* Map CE id to ce_state */
  151. struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
  152. struct timer_list rx_post_retry;
  153. /* Due to HW quirks it is recommended to disable ASPM during device
  154. * bootup. To do that the original PCI-E Link Control is stored before
  155. * device bootup is executed and re-programmed later.
  156. */
  157. u16 link_ctl;
  158. /* Protects ps_awake and ps_wake_refcount */
  159. spinlock_t ps_lock;
  160. /* The device has a special powersave-oriented register. When device is
  161. * considered asleep it drains less power and driver is forbidden from
  162. * accessing most MMIO registers. If host were to access them without
  163. * waking up the device might scribble over host memory or return
  164. * 0xdeadbeef readouts.
  165. */
  166. unsigned long ps_wake_refcount;
  167. /* Waking up takes some time (up to 2ms in some cases) so it can be bad
  168. * for latency. To mitigate this the device isn't immediately allowed
  169. * to sleep after all references are undone - instead there's a grace
  170. * period after which the powersave register is updated unless some
  171. * activity to/from device happened in the meantime.
  172. *
  173. * Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.
  174. */
  175. struct timer_list ps_timer;
  176. /* MMIO registers are used to communicate with the device. With
  177. * intensive traffic accessing powersave register would be a bit
  178. * wasteful overhead and would needlessly stall CPU. It is far more
  179. * efficient to rely on a variable in RAM and update it only upon
  180. * powersave register state changes.
  181. */
  182. bool ps_awake;
  183. /* pci power save, disable for QCA988X and QCA99X0.
  184. * Writing 'false' to this variable avoids frequent locking
  185. * on MMIO read/write.
  186. */
  187. bool pci_ps;
  188. };
  189. static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
  190. {
  191. return (struct ath10k_pci *)ar->drv_priv;
  192. }
  193. #define ATH10K_PCI_RX_POST_RETRY_MS 50
  194. #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
  195. #define PCIE_WAKE_TIMEOUT 30000 /* 30ms */
  196. #define PCIE_WAKE_LATE_US 10000 /* 10ms */
  197. #define BAR_NUM 0
  198. #define CDC_WAR_MAGIC_STR 0xceef0000
  199. #define CDC_WAR_DATA_CE 4
  200. /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
  201. #define DIAG_ACCESS_CE_TIMEOUT_MS 10
  202. void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);
  203. void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);
  204. void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);
  205. u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);
  206. u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);
  207. u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);
  208. /* QCA6174 is known to have Tx/Rx issues when SOC_WAKE register is poked too
  209. * frequently. To avoid this put SoC to sleep after a very conservative grace
  210. * period. Adjust with great care.
  211. */
  212. #define ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC 60
  213. #endif /* _PCI_H_ */