pci.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2017 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. #include "ahb.h"
  23. /*
  24. * maximum number of bytes that can be
  25. * handled atomically by DiagRead/DiagWrite
  26. */
  27. #define DIAG_TRANSFER_LIMIT 2048
  28. struct bmi_xfer {
  29. bool tx_done;
  30. bool rx_done;
  31. bool wait_for_resp;
  32. u32 resp_len;
  33. };
  34. /*
  35. * PCI-specific Target state
  36. *
  37. * NOTE: Structure is shared between Host software and Target firmware!
  38. *
  39. * Much of this may be of interest to the Host so
  40. * HOST_INTEREST->hi_interconnect_state points here
  41. * (and all members are 32-bit quantities in order to
  42. * facilitate Host access). In particular, Host software is
  43. * required to initialize pipe_cfg_addr and svc_to_pipe_map.
  44. */
  45. struct pcie_state {
  46. /* Pipe configuration Target address */
  47. /* NB: ce_pipe_config[CE_COUNT] */
  48. u32 pipe_cfg_addr;
  49. /* Service to pipe map Target address */
  50. /* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */
  51. u32 svc_to_pipe_map;
  52. /* number of MSI interrupts requested */
  53. u32 msi_requested;
  54. /* number of MSI interrupts granted */
  55. u32 msi_granted;
  56. /* Message Signalled Interrupt address */
  57. u32 msi_addr;
  58. /* Base data */
  59. u32 msi_data;
  60. /*
  61. * Data for firmware interrupt;
  62. * MSI data for other interrupts are
  63. * in various SoC registers
  64. */
  65. u32 msi_fw_intr_data;
  66. /* PCIE_PWR_METHOD_* */
  67. u32 power_mgmt_method;
  68. /* PCIE_CONFIG_FLAG_* */
  69. u32 config_flags;
  70. };
  71. /* PCIE_CONFIG_FLAG definitions */
  72. #define PCIE_CONFIG_FLAG_ENABLE_L1 0x0000001
  73. /* Host software's Copy Engine configuration. */
  74. #define CE_ATTR_FLAGS 0
  75. /*
  76. * Configuration information for a Copy Engine pipe.
  77. * Passed from Host to Target during startup (one per CE).
  78. *
  79. * NOTE: Structure is shared between Host software and Target firmware!
  80. */
  81. struct ce_pipe_config {
  82. __le32 pipenum;
  83. __le32 pipedir;
  84. __le32 nentries;
  85. __le32 nbytes_max;
  86. __le32 flags;
  87. __le32 reserved;
  88. };
  89. /*
  90. * Directions for interconnect pipe configuration.
  91. * These definitions may be used during configuration and are shared
  92. * between Host and Target.
  93. *
  94. * Pipe Directions are relative to the Host, so PIPEDIR_IN means
  95. * "coming IN over air through Target to Host" as with a WiFi Rx operation.
  96. * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
  97. * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
  98. * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
  99. * over the interconnect.
  100. */
  101. #define PIPEDIR_NONE 0
  102. #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
  103. #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
  104. #define PIPEDIR_INOUT 3 /* bidirectional */
  105. /* Establish a mapping between a service/direction and a pipe. */
  106. struct service_to_pipe {
  107. __le32 service_id;
  108. __le32 pipedir;
  109. __le32 pipenum;
  110. };
  111. /* Per-pipe state. */
  112. struct ath10k_pci_pipe {
  113. /* Handle of underlying Copy Engine */
  114. struct ath10k_ce_pipe *ce_hdl;
  115. /* Our pipe number; facilitiates use of pipe_info ptrs. */
  116. u8 pipe_num;
  117. /* Convenience back pointer to hif_ce_state. */
  118. struct ath10k *hif_ce_state;
  119. size_t buf_sz;
  120. /* protects compl_free and num_send_allowed */
  121. spinlock_t pipe_lock;
  122. };
  123. struct ath10k_pci_supp_chip {
  124. u32 dev_id;
  125. u32 rev_id;
  126. };
  127. enum ath10k_pci_irq_mode {
  128. ATH10K_PCI_IRQ_AUTO = 0,
  129. ATH10K_PCI_IRQ_LEGACY = 1,
  130. ATH10K_PCI_IRQ_MSI = 2,
  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. /* Operating interrupt mode */
  139. enum ath10k_pci_irq_mode oper_irq_mode;
  140. struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
  141. /* Copy Engine used for Diagnostic Accesses */
  142. struct ath10k_ce_pipe *ce_diag;
  143. struct ath10k_ce ce;
  144. struct timer_list rx_post_retry;
  145. /* Due to HW quirks it is recommended to disable ASPM during device
  146. * bootup. To do that the original PCI-E Link Control is stored before
  147. * device bootup is executed and re-programmed later.
  148. */
  149. u16 link_ctl;
  150. /* Protects ps_awake and ps_wake_refcount */
  151. spinlock_t ps_lock;
  152. /* The device has a special powersave-oriented register. When device is
  153. * considered asleep it drains less power and driver is forbidden from
  154. * accessing most MMIO registers. If host were to access them without
  155. * waking up the device might scribble over host memory or return
  156. * 0xdeadbeef readouts.
  157. */
  158. unsigned long ps_wake_refcount;
  159. /* Waking up takes some time (up to 2ms in some cases) so it can be bad
  160. * for latency. To mitigate this the device isn't immediately allowed
  161. * to sleep after all references are undone - instead there's a grace
  162. * period after which the powersave register is updated unless some
  163. * activity to/from device happened in the meantime.
  164. *
  165. * Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.
  166. */
  167. struct timer_list ps_timer;
  168. /* MMIO registers are used to communicate with the device. With
  169. * intensive traffic accessing powersave register would be a bit
  170. * wasteful overhead and would needlessly stall CPU. It is far more
  171. * efficient to rely on a variable in RAM and update it only upon
  172. * powersave register state changes.
  173. */
  174. bool ps_awake;
  175. /* pci power save, disable for QCA988X and QCA99X0.
  176. * Writing 'false' to this variable avoids frequent locking
  177. * on MMIO read/write.
  178. */
  179. bool pci_ps;
  180. /* Chip specific pci reset routine used to do a safe reset */
  181. int (*pci_soft_reset)(struct ath10k *ar);
  182. /* Chip specific pci full reset function */
  183. int (*pci_hard_reset)(struct ath10k *ar);
  184. /* chip specific methods for converting target CPU virtual address
  185. * space to CE address space
  186. */
  187. u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);
  188. /* Keep this entry in the last, memory for struct ath10k_ahb is
  189. * allocated (ahb support enabled case) in the continuation of
  190. * this struct.
  191. */
  192. struct ath10k_ahb ahb[0];
  193. };
  194. static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
  195. {
  196. return (struct ath10k_pci *)ar->drv_priv;
  197. }
  198. #define ATH10K_PCI_RX_POST_RETRY_MS 50
  199. #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
  200. #define PCIE_WAKE_TIMEOUT 30000 /* 30ms */
  201. #define PCIE_WAKE_LATE_US 10000 /* 10ms */
  202. #define BAR_NUM 0
  203. #define CDC_WAR_MAGIC_STR 0xceef0000
  204. #define CDC_WAR_DATA_CE 4
  205. /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
  206. #define DIAG_ACCESS_CE_TIMEOUT_MS 10
  207. void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);
  208. void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);
  209. void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);
  210. u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);
  211. u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);
  212. u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);
  213. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  214. struct ath10k_hif_sg_item *items, int n_items);
  215. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  216. size_t buf_len);
  217. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  218. const void *data, int nbytes);
  219. int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, void *req, u32 req_len,
  220. void *resp, u32 *resp_len);
  221. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  222. u8 *ul_pipe, u8 *dl_pipe);
  223. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, u8 *ul_pipe,
  224. u8 *dl_pipe);
  225. void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  226. int force);
  227. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe);
  228. void ath10k_pci_hif_power_down(struct ath10k *ar);
  229. int ath10k_pci_alloc_pipes(struct ath10k *ar);
  230. void ath10k_pci_free_pipes(struct ath10k *ar);
  231. void ath10k_pci_free_pipes(struct ath10k *ar);
  232. void ath10k_pci_rx_replenish_retry(struct timer_list *t);
  233. void ath10k_pci_ce_deinit(struct ath10k *ar);
  234. void ath10k_pci_init_napi(struct ath10k *ar);
  235. int ath10k_pci_init_pipes(struct ath10k *ar);
  236. int ath10k_pci_init_config(struct ath10k *ar);
  237. void ath10k_pci_rx_post(struct ath10k *ar);
  238. void ath10k_pci_flush(struct ath10k *ar);
  239. void ath10k_pci_enable_legacy_irq(struct ath10k *ar);
  240. bool ath10k_pci_irq_pending(struct ath10k *ar);
  241. void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar);
  242. void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar);
  243. int ath10k_pci_wait_for_target_init(struct ath10k *ar);
  244. int ath10k_pci_setup_resource(struct ath10k *ar);
  245. void ath10k_pci_release_resource(struct ath10k *ar);
  246. /* QCA6174 is known to have Tx/Rx issues when SOC_WAKE register is poked too
  247. * frequently. To avoid this put SoC to sleep after a very conservative grace
  248. * period. Adjust with great care.
  249. */
  250. #define ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC 60
  251. #endif /* _PCI_H_ */