ce.h 11 KB

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