ce.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _CE_H_
  19. #define _CE_H_
  20. #include "hif.h"
  21. #define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
  22. /* Descriptor rings must be aligned to this boundary */
  23. #define CE_DESC_RING_ALIGN 8
  24. #define CE_SEND_FLAG_GATHER 0x00010000
  25. /*
  26. * Copy Engine support: low-level Target-side Copy Engine API.
  27. * This is a hardware access layer used by code that understands
  28. * how to use copy engines.
  29. */
  30. struct ath10k_ce_pipe;
  31. #define CE_DESC_FLAGS_GATHER (1 << 0)
  32. #define CE_DESC_FLAGS_BYTE_SWAP (1 << 1)
  33. #define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
  34. #define CE_DESC_FLAGS_GET_MASK GENMASK(4, 0)
  35. #define CE_DESC_37BIT_ADDR_MASK GENMASK_ULL(37, 0)
  36. /* Following desc flags are used in QCA99X0 */
  37. #define CE_DESC_FLAGS_HOST_INT_DIS (1 << 2)
  38. #define CE_DESC_FLAGS_TGT_INT_DIS (1 << 3)
  39. #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
  40. #define CE_DESC_FLAGS_META_DATA_LSB ar->hw_values->ce_desc_meta_data_lsb
  41. #define CE_DDR_RRI_MASK GENMASK(15, 0)
  42. #define CE_DDR_DRRI_SHIFT 16
  43. struct ce_desc {
  44. __le32 addr;
  45. __le16 nbytes;
  46. __le16 flags; /* %CE_DESC_FLAGS_ */
  47. };
  48. struct ce_desc_64 {
  49. __le64 addr;
  50. __le16 nbytes; /* length in register map */
  51. __le16 flags; /* fw_metadata_high */
  52. __le32 toeplitz_hash_result;
  53. };
  54. #define CE_DESC_SIZE sizeof(struct ce_desc)
  55. #define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
  56. struct ath10k_ce_ring {
  57. /* Number of entries in this ring; must be power of 2 */
  58. unsigned int nentries;
  59. unsigned int nentries_mask;
  60. /*
  61. * For dest ring, this is the next index to be processed
  62. * by software after it was/is received into.
  63. *
  64. * For src ring, this is the last descriptor that was sent
  65. * and completion processed by software.
  66. *
  67. * Regardless of src or dest ring, this is an invariant
  68. * (modulo ring size):
  69. * write index >= read index >= sw_index
  70. */
  71. unsigned int sw_index;
  72. /* cached copy */
  73. unsigned int write_index;
  74. /*
  75. * For src ring, this is the next index not yet processed by HW.
  76. * This is a cached copy of the real HW index (read index), used
  77. * for avoiding reading the HW index register more often than
  78. * necessary.
  79. * This extends the invariant:
  80. * write index >= read index >= hw_index >= sw_index
  81. *
  82. * For dest ring, this is currently unused.
  83. */
  84. /* cached copy */
  85. unsigned int hw_index;
  86. /* Start of DMA-coherent area reserved for descriptors */
  87. /* Host address space */
  88. void *base_addr_owner_space_unaligned;
  89. /* CE address space */
  90. u32 base_addr_ce_space_unaligned;
  91. /*
  92. * Actual start of descriptors.
  93. * Aligned to descriptor-size boundary.
  94. * Points into reserved DMA-coherent area, above.
  95. */
  96. /* Host address space */
  97. void *base_addr_owner_space;
  98. /* CE address space */
  99. u32 base_addr_ce_space;
  100. char *shadow_base_unaligned;
  101. struct ce_desc *shadow_base;
  102. /* keep last */
  103. void *per_transfer_context[0];
  104. };
  105. struct ath10k_ce_pipe {
  106. struct ath10k *ar;
  107. unsigned int id;
  108. unsigned int attr_flags;
  109. u32 ctrl_addr;
  110. void (*send_cb)(struct ath10k_ce_pipe *);
  111. void (*recv_cb)(struct ath10k_ce_pipe *);
  112. unsigned int src_sz_max;
  113. struct ath10k_ce_ring *src_ring;
  114. struct ath10k_ce_ring *dest_ring;
  115. const struct ath10k_ce_ops *ops;
  116. };
  117. /* Copy Engine settable attributes */
  118. struct ce_attr;
  119. struct ath10k_bus_ops {
  120. u32 (*read32)(struct ath10k *ar, u32 offset);
  121. void (*write32)(struct ath10k *ar, u32 offset, u32 value);
  122. int (*get_num_banks)(struct ath10k *ar);
  123. };
  124. static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
  125. {
  126. return (struct ath10k_ce *)ar->ce_priv;
  127. }
  128. struct ath10k_ce {
  129. /* protects CE info */
  130. spinlock_t ce_lock;
  131. const struct ath10k_bus_ops *bus_ops;
  132. struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
  133. u32 *vaddr_rri;
  134. dma_addr_t paddr_rri;
  135. };
  136. /*==================Send====================*/
  137. /* ath10k_ce_send flags */
  138. #define CE_SEND_FLAG_BYTE_SWAP 1
  139. /*
  140. * Queue a source buffer to be sent to an anonymous destination buffer.
  141. * ce - which copy engine to use
  142. * buffer - address of buffer
  143. * nbytes - number of bytes to send
  144. * transfer_id - arbitrary ID; reflected to destination
  145. * flags - CE_SEND_FLAG_* values
  146. * Returns 0 on success; otherwise an error status.
  147. *
  148. * Note: If no flags are specified, use CE's default data swap mode.
  149. *
  150. * Implementation note: pushes 1 buffer to Source ring
  151. */
  152. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  153. void *per_transfer_send_context,
  154. dma_addr_t buffer,
  155. unsigned int nbytes,
  156. /* 14 bits */
  157. unsigned int transfer_id,
  158. unsigned int flags);
  159. int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  160. void *per_transfer_context,
  161. dma_addr_t buffer,
  162. unsigned int nbytes,
  163. unsigned int transfer_id,
  164. unsigned int flags);
  165. void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
  166. int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
  167. /*==================Recv=======================*/
  168. int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
  169. int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
  170. dma_addr_t paddr);
  171. void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
  172. /* recv flags */
  173. /* Data is byte-swapped */
  174. #define CE_RECV_FLAG_SWAPPED 1
  175. /*
  176. * Supply data for the next completed unprocessed receive descriptor.
  177. * Pops buffer from Dest ring.
  178. */
  179. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  180. void **per_transfer_contextp,
  181. unsigned int *nbytesp);
  182. /*
  183. * Supply data for the next completed unprocessed send descriptor.
  184. * Pops 1 completed send buffer from Source ring.
  185. */
  186. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  187. void **per_transfer_contextp);
  188. int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  189. void **per_transfer_contextp);
  190. /*==================CE Engine Initialization=======================*/
  191. int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
  192. const struct ce_attr *attr);
  193. void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
  194. int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
  195. const struct ce_attr *attr);
  196. void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
  197. /*==================CE Engine Shutdown=======================*/
  198. /*
  199. * Support clean shutdown by allowing the caller to revoke
  200. * receive buffers. Target DMA must be stopped before using
  201. * this API.
  202. */
  203. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  204. void **per_transfer_contextp,
  205. dma_addr_t *bufferp);
  206. int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  207. void **per_transfer_contextp,
  208. unsigned int *nbytesp);
  209. /*
  210. * Support clean shutdown by allowing the caller to cancel
  211. * pending sends. Target DMA must be stopped before using
  212. * this API.
  213. */
  214. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  215. void **per_transfer_contextp,
  216. dma_addr_t *bufferp,
  217. unsigned int *nbytesp,
  218. unsigned int *transfer_idp);
  219. /*==================CE Interrupt Handlers====================*/
  220. void ath10k_ce_per_engine_service_any(struct ath10k *ar);
  221. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
  222. int ath10k_ce_disable_interrupts(struct ath10k *ar);
  223. void ath10k_ce_enable_interrupts(struct ath10k *ar);
  224. void ath10k_ce_dump_registers(struct ath10k *ar,
  225. struct ath10k_fw_crash_data *crash_data);
  226. void ath10k_ce_alloc_rri(struct ath10k *ar);
  227. void ath10k_ce_free_rri(struct ath10k *ar);
  228. /* ce_attr.flags values */
  229. /* Use NonSnooping PCIe accesses? */
  230. #define CE_ATTR_NO_SNOOP 1
  231. /* Byte swap data words */
  232. #define CE_ATTR_BYTE_SWAP_DATA 2
  233. /* Swizzle descriptors? */
  234. #define CE_ATTR_SWIZZLE_DESCRIPTORS 4
  235. /* no interrupt on copy completion */
  236. #define CE_ATTR_DIS_INTR 8
  237. /* Attributes of an instance of a Copy Engine */
  238. struct ce_attr {
  239. /* CE_ATTR_* values */
  240. unsigned int flags;
  241. /* #entries in source ring - Must be a power of 2 */
  242. unsigned int src_nentries;
  243. /*
  244. * Max source send size for this CE.
  245. * This is also the minimum size of a destination buffer.
  246. */
  247. unsigned int src_sz_max;
  248. /* #entries in destination ring - Must be a power of 2 */
  249. unsigned int dest_nentries;
  250. void (*send_cb)(struct ath10k_ce_pipe *);
  251. void (*recv_cb)(struct ath10k_ce_pipe *);
  252. };
  253. struct ath10k_ce_ops {
  254. struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
  255. u32 ce_id,
  256. const struct ce_attr *attr);
  257. struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
  258. u32 ce_id,
  259. const struct ce_attr *attr);
  260. int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
  261. dma_addr_t paddr);
  262. int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
  263. void **per_transfer_contextp,
  264. u32 *nbytesp);
  265. int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
  266. void **per_transfer_contextp,
  267. dma_addr_t *nbytesp);
  268. void (*ce_extract_desc_data)(struct ath10k *ar,
  269. struct ath10k_ce_ring *src_ring,
  270. u32 sw_index, dma_addr_t *bufferp,
  271. u32 *nbytesp, u32 *transfer_idp);
  272. void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
  273. int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
  274. void *per_transfer_context,
  275. dma_addr_t buffer, u32 nbytes,
  276. u32 transfer_id, u32 flags);
  277. };
  278. static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
  279. {
  280. return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
  281. }
  282. #define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
  283. - CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
  284. #define CE_SRC_RING_TO_DESC(baddr, idx) \
  285. (&(((struct ce_desc *)baddr)[idx]))
  286. #define CE_DEST_RING_TO_DESC(baddr, idx) \
  287. (&(((struct ce_desc *)baddr)[idx]))
  288. #define CE_SRC_RING_TO_DESC_64(baddr, idx) \
  289. (&(((struct ce_desc_64 *)baddr)[idx]))
  290. #define CE_DEST_RING_TO_DESC_64(baddr, idx) \
  291. (&(((struct ce_desc_64 *)baddr)[idx]))
  292. /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
  293. #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
  294. (((int)(toidx) - (int)(fromidx)) & (nentries_mask))
  295. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  296. #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
  297. (((idx) + (num)) & (nentries_mask))
  298. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
  299. ar->regs->ce_wrap_intr_sum_host_msi_lsb
  300. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
  301. ar->regs->ce_wrap_intr_sum_host_msi_mask
  302. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
  303. (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
  304. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
  305. #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
  306. #define CE_INTERRUPT_SUMMARY (GENMASK(CE_COUNT_MAX - 1, 0))
  307. static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
  308. {
  309. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  310. if (!ar->hw_params.per_ce_irq)
  311. return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
  312. ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
  313. CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
  314. else
  315. return CE_INTERRUPT_SUMMARY;
  316. }
  317. #endif /* _CE_H_ */