pci.h 7.5 KB

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