pci.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. /* Per-pipe state. */
  74. struct ath10k_pci_pipe {
  75. /* Handle of underlying Copy Engine */
  76. struct ath10k_ce_pipe *ce_hdl;
  77. /* Our pipe number; facilitiates use of pipe_info ptrs. */
  78. u8 pipe_num;
  79. /* Convenience back pointer to hif_ce_state. */
  80. struct ath10k *hif_ce_state;
  81. size_t buf_sz;
  82. /* protects compl_free and num_send_allowed */
  83. spinlock_t pipe_lock;
  84. };
  85. struct ath10k_pci_supp_chip {
  86. u32 dev_id;
  87. u32 rev_id;
  88. };
  89. enum ath10k_pci_irq_mode {
  90. ATH10K_PCI_IRQ_AUTO = 0,
  91. ATH10K_PCI_IRQ_LEGACY = 1,
  92. ATH10K_PCI_IRQ_MSI = 2,
  93. };
  94. struct ath10k_pci {
  95. struct pci_dev *pdev;
  96. struct device *dev;
  97. struct ath10k *ar;
  98. void __iomem *mem;
  99. size_t mem_len;
  100. /* Operating interrupt mode */
  101. enum ath10k_pci_irq_mode oper_irq_mode;
  102. struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
  103. /* Copy Engine used for Diagnostic Accesses */
  104. struct ath10k_ce_pipe *ce_diag;
  105. struct ath10k_ce ce;
  106. struct timer_list rx_post_retry;
  107. /* Due to HW quirks it is recommended to disable ASPM during device
  108. * bootup. To do that the original PCI-E Link Control is stored before
  109. * device bootup is executed and re-programmed later.
  110. */
  111. u16 link_ctl;
  112. /* Protects ps_awake and ps_wake_refcount */
  113. spinlock_t ps_lock;
  114. /* The device has a special powersave-oriented register. When device is
  115. * considered asleep it drains less power and driver is forbidden from
  116. * accessing most MMIO registers. If host were to access them without
  117. * waking up the device might scribble over host memory or return
  118. * 0xdeadbeef readouts.
  119. */
  120. unsigned long ps_wake_refcount;
  121. /* Waking up takes some time (up to 2ms in some cases) so it can be bad
  122. * for latency. To mitigate this the device isn't immediately allowed
  123. * to sleep after all references are undone - instead there's a grace
  124. * period after which the powersave register is updated unless some
  125. * activity to/from device happened in the meantime.
  126. *
  127. * Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.
  128. */
  129. struct timer_list ps_timer;
  130. /* MMIO registers are used to communicate with the device. With
  131. * intensive traffic accessing powersave register would be a bit
  132. * wasteful overhead and would needlessly stall CPU. It is far more
  133. * efficient to rely on a variable in RAM and update it only upon
  134. * powersave register state changes.
  135. */
  136. bool ps_awake;
  137. /* pci power save, disable for QCA988X and QCA99X0.
  138. * Writing 'false' to this variable avoids frequent locking
  139. * on MMIO read/write.
  140. */
  141. bool pci_ps;
  142. /* Chip specific pci reset routine used to do a safe reset */
  143. int (*pci_soft_reset)(struct ath10k *ar);
  144. /* Chip specific pci full reset function */
  145. int (*pci_hard_reset)(struct ath10k *ar);
  146. /* chip specific methods for converting target CPU virtual address
  147. * space to CE address space
  148. */
  149. u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);
  150. /* Keep this entry in the last, memory for struct ath10k_ahb is
  151. * allocated (ahb support enabled case) in the continuation of
  152. * this struct.
  153. */
  154. struct ath10k_ahb ahb[0];
  155. };
  156. static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
  157. {
  158. return (struct ath10k_pci *)ar->drv_priv;
  159. }
  160. #define ATH10K_PCI_RX_POST_RETRY_MS 50
  161. #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
  162. #define PCIE_WAKE_TIMEOUT 30000 /* 30ms */
  163. #define PCIE_WAKE_LATE_US 10000 /* 10ms */
  164. #define BAR_NUM 0
  165. #define CDC_WAR_MAGIC_STR 0xceef0000
  166. #define CDC_WAR_DATA_CE 4
  167. /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
  168. #define DIAG_ACCESS_CE_TIMEOUT_MS 10
  169. void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);
  170. void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);
  171. void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);
  172. u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);
  173. u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);
  174. u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);
  175. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  176. struct ath10k_hif_sg_item *items, int n_items);
  177. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  178. size_t buf_len);
  179. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  180. const void *data, int nbytes);
  181. int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, void *req, u32 req_len,
  182. void *resp, u32 *resp_len);
  183. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  184. u8 *ul_pipe, u8 *dl_pipe);
  185. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, u8 *ul_pipe,
  186. u8 *dl_pipe);
  187. void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  188. int force);
  189. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe);
  190. void ath10k_pci_hif_power_down(struct ath10k *ar);
  191. int ath10k_pci_alloc_pipes(struct ath10k *ar);
  192. void ath10k_pci_free_pipes(struct ath10k *ar);
  193. void ath10k_pci_free_pipes(struct ath10k *ar);
  194. void ath10k_pci_rx_replenish_retry(struct timer_list *t);
  195. void ath10k_pci_ce_deinit(struct ath10k *ar);
  196. void ath10k_pci_init_napi(struct ath10k *ar);
  197. int ath10k_pci_init_pipes(struct ath10k *ar);
  198. int ath10k_pci_init_config(struct ath10k *ar);
  199. void ath10k_pci_rx_post(struct ath10k *ar);
  200. void ath10k_pci_flush(struct ath10k *ar);
  201. void ath10k_pci_enable_legacy_irq(struct ath10k *ar);
  202. bool ath10k_pci_irq_pending(struct ath10k *ar);
  203. void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar);
  204. void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar);
  205. int ath10k_pci_wait_for_target_init(struct ath10k *ar);
  206. int ath10k_pci_setup_resource(struct ath10k *ar);
  207. void ath10k_pci_release_resource(struct ath10k *ar);
  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_ */