pci.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. #include "ahb.h"
  23. /*
  24. * maximum number of bytes that can be handled atomically by DiagRead/DiagWrite
  25. */
  26. #define DIAG_TRANSFER_LIMIT 2048
  27. /*
  28. * maximum number of bytes that can be
  29. * handled atomically by DiagRead/DiagWrite
  30. */
  31. #define DIAG_TRANSFER_LIMIT 2048
  32. struct bmi_xfer {
  33. bool tx_done;
  34. bool rx_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. __le32 pipenum;
  87. __le32 pipedir;
  88. __le32 nentries;
  89. __le32 nbytes_max;
  90. __le32 flags;
  91. __le32 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. __le32 service_id;
  112. __le32 pipedir;
  113. __le32 pipenum;
  114. };
  115. /* Per-pipe state. */
  116. struct ath10k_pci_pipe {
  117. /* Handle of underlying Copy Engine */
  118. struct ath10k_ce_pipe *ce_hdl;
  119. /* Our pipe number; facilitiates use of pipe_info ptrs. */
  120. u8 pipe_num;
  121. /* Convenience back pointer to hif_ce_state. */
  122. struct ath10k *hif_ce_state;
  123. size_t buf_sz;
  124. /* protects compl_free and num_send_allowed */
  125. spinlock_t pipe_lock;
  126. };
  127. struct ath10k_pci_supp_chip {
  128. u32 dev_id;
  129. u32 rev_id;
  130. };
  131. struct ath10k_bus_ops {
  132. u32 (*read32)(struct ath10k *ar, u32 offset);
  133. void (*write32)(struct ath10k *ar, u32 offset, u32 value);
  134. int (*get_num_banks)(struct ath10k *ar);
  135. };
  136. enum ath10k_pci_irq_mode {
  137. ATH10K_PCI_IRQ_AUTO = 0,
  138. ATH10K_PCI_IRQ_LEGACY = 1,
  139. ATH10K_PCI_IRQ_MSI = 2,
  140. };
  141. struct ath10k_pci {
  142. struct pci_dev *pdev;
  143. struct device *dev;
  144. struct ath10k *ar;
  145. void __iomem *mem;
  146. size_t mem_len;
  147. /* Operating interrupt mode */
  148. enum ath10k_pci_irq_mode oper_irq_mode;
  149. struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
  150. /* Copy Engine used for Diagnostic Accesses */
  151. struct ath10k_ce_pipe *ce_diag;
  152. /* FIXME: document what this really protects */
  153. spinlock_t ce_lock;
  154. /* Map CE id to ce_state */
  155. struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
  156. struct timer_list rx_post_retry;
  157. /* Due to HW quirks it is recommended to disable ASPM during device
  158. * bootup. To do that the original PCI-E Link Control is stored before
  159. * device bootup is executed and re-programmed later.
  160. */
  161. u16 link_ctl;
  162. /* Protects ps_awake and ps_wake_refcount */
  163. spinlock_t ps_lock;
  164. /* The device has a special powersave-oriented register. When device is
  165. * considered asleep it drains less power and driver is forbidden from
  166. * accessing most MMIO registers. If host were to access them without
  167. * waking up the device might scribble over host memory or return
  168. * 0xdeadbeef readouts.
  169. */
  170. unsigned long ps_wake_refcount;
  171. /* Waking up takes some time (up to 2ms in some cases) so it can be bad
  172. * for latency. To mitigate this the device isn't immediately allowed
  173. * to sleep after all references are undone - instead there's a grace
  174. * period after which the powersave register is updated unless some
  175. * activity to/from device happened in the meantime.
  176. *
  177. * Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.
  178. */
  179. struct timer_list ps_timer;
  180. /* MMIO registers are used to communicate with the device. With
  181. * intensive traffic accessing powersave register would be a bit
  182. * wasteful overhead and would needlessly stall CPU. It is far more
  183. * efficient to rely on a variable in RAM and update it only upon
  184. * powersave register state changes.
  185. */
  186. bool ps_awake;
  187. /* pci power save, disable for QCA988X and QCA99X0.
  188. * Writing 'false' to this variable avoids frequent locking
  189. * on MMIO read/write.
  190. */
  191. bool pci_ps;
  192. const struct ath10k_bus_ops *bus_ops;
  193. /* Chip specific pci reset routine used to do a safe reset */
  194. int (*pci_soft_reset)(struct ath10k *ar);
  195. /* Chip specific pci full reset function */
  196. int (*pci_hard_reset)(struct ath10k *ar);
  197. /* chip specific methods for converting target CPU virtual address
  198. * space to CE address space
  199. */
  200. u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);
  201. /* Keep this entry in the last, memory for struct ath10k_ahb is
  202. * allocated (ahb support enabled case) in the continuation of
  203. * this struct.
  204. */
  205. struct ath10k_ahb ahb[0];
  206. };
  207. static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
  208. {
  209. return (struct ath10k_pci *)ar->drv_priv;
  210. }
  211. #define ATH10K_PCI_RX_POST_RETRY_MS 50
  212. #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
  213. #define PCIE_WAKE_TIMEOUT 30000 /* 30ms */
  214. #define PCIE_WAKE_LATE_US 10000 /* 10ms */
  215. #define BAR_NUM 0
  216. #define CDC_WAR_MAGIC_STR 0xceef0000
  217. #define CDC_WAR_DATA_CE 4
  218. /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
  219. #define DIAG_ACCESS_CE_TIMEOUT_MS 10
  220. void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);
  221. void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);
  222. void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);
  223. u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);
  224. u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);
  225. u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);
  226. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  227. struct ath10k_hif_sg_item *items, int n_items);
  228. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  229. size_t buf_len);
  230. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  231. const void *data, int nbytes);
  232. int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, void *req, u32 req_len,
  233. void *resp, u32 *resp_len);
  234. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  235. u8 *ul_pipe, u8 *dl_pipe);
  236. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, u8 *ul_pipe,
  237. u8 *dl_pipe);
  238. void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  239. int force);
  240. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe);
  241. void ath10k_pci_hif_power_down(struct ath10k *ar);
  242. int ath10k_pci_alloc_pipes(struct ath10k *ar);
  243. void ath10k_pci_free_pipes(struct ath10k *ar);
  244. void ath10k_pci_free_pipes(struct ath10k *ar);
  245. void ath10k_pci_rx_replenish_retry(unsigned long ptr);
  246. void ath10k_pci_ce_deinit(struct ath10k *ar);
  247. void ath10k_pci_init_napi(struct ath10k *ar);
  248. int ath10k_pci_init_pipes(struct ath10k *ar);
  249. int ath10k_pci_init_config(struct ath10k *ar);
  250. void ath10k_pci_rx_post(struct ath10k *ar);
  251. void ath10k_pci_flush(struct ath10k *ar);
  252. void ath10k_pci_enable_legacy_irq(struct ath10k *ar);
  253. bool ath10k_pci_irq_pending(struct ath10k *ar);
  254. void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar);
  255. void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar);
  256. int ath10k_pci_wait_for_target_init(struct ath10k *ar);
  257. int ath10k_pci_setup_resource(struct ath10k *ar);
  258. void ath10k_pci_release_resource(struct ath10k *ar);
  259. /* QCA6174 is known to have Tx/Rx issues when SOC_WAKE register is poked too
  260. * frequently. To avoid this put SoC to sleep after a very conservative grace
  261. * period. Adjust with great care.
  262. */
  263. #define ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC 60
  264. #endif /* _PCI_H_ */