ce.h 13 KB

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