ce.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 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. /* Maximum number of Copy Engine's supported */
  21. #define CE_COUNT_MAX 8
  22. #define CE_HTT_H2T_MSG_SRC_NENTRIES 2048
  23. /* Descriptor rings must be aligned to this boundary */
  24. #define CE_DESC_RING_ALIGN 8
  25. #define CE_SENDLIST_ITEMS_MAX 12
  26. #define CE_SEND_FLAG_GATHER 0x00010000
  27. /*
  28. * Copy Engine support: low-level Target-side Copy Engine API.
  29. * This is a hardware access layer used by code that understands
  30. * how to use copy engines.
  31. */
  32. struct ath10k_ce_pipe;
  33. #define CE_DESC_FLAGS_GATHER (1 << 0)
  34. #define CE_DESC_FLAGS_BYTE_SWAP (1 << 1)
  35. #define CE_DESC_FLAGS_META_DATA_MASK 0xFFFC
  36. #define CE_DESC_FLAGS_META_DATA_LSB 3
  37. struct ce_desc {
  38. __le32 addr;
  39. __le16 nbytes;
  40. __le16 flags; /* %CE_DESC_FLAGS_ */
  41. };
  42. struct ath10k_ce_ring {
  43. /* Number of entries in this ring; must be power of 2 */
  44. unsigned int nentries;
  45. unsigned int nentries_mask;
  46. /*
  47. * For dest ring, this is the next index to be processed
  48. * by software after it was/is received into.
  49. *
  50. * For src ring, this is the last descriptor that was sent
  51. * and completion processed by software.
  52. *
  53. * Regardless of src or dest ring, this is an invariant
  54. * (modulo ring size):
  55. * write index >= read index >= sw_index
  56. */
  57. unsigned int sw_index;
  58. /* cached copy */
  59. unsigned int write_index;
  60. /*
  61. * For src ring, this is the next index not yet processed by HW.
  62. * This is a cached copy of the real HW index (read index), used
  63. * for avoiding reading the HW index register more often than
  64. * necessary.
  65. * This extends the invariant:
  66. * write index >= read index >= hw_index >= sw_index
  67. *
  68. * For dest ring, this is currently unused.
  69. */
  70. /* cached copy */
  71. unsigned int hw_index;
  72. /* Start of DMA-coherent area reserved for descriptors */
  73. /* Host address space */
  74. void *base_addr_owner_space_unaligned;
  75. /* CE address space */
  76. u32 base_addr_ce_space_unaligned;
  77. /*
  78. * Actual start of descriptors.
  79. * Aligned to descriptor-size boundary.
  80. * Points into reserved DMA-coherent area, above.
  81. */
  82. /* Host address space */
  83. void *base_addr_owner_space;
  84. /* CE address space */
  85. u32 base_addr_ce_space;
  86. /*
  87. * Start of shadow copy of descriptors, within regular memory.
  88. * Aligned to descriptor-size boundary.
  89. */
  90. void *shadow_base_unaligned;
  91. struct ce_desc *shadow_base;
  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. };
  105. struct ce_sendlist_item {
  106. /* e.g. buffer or desc list */
  107. dma_addr_t data;
  108. union {
  109. /* simple buffer */
  110. unsigned int nbytes;
  111. /* Rx descriptor list */
  112. unsigned int ndesc;
  113. } u;
  114. /* externally-specified flags; OR-ed with internal flags */
  115. u32 flags;
  116. };
  117. struct ce_sendlist {
  118. unsigned int num_items;
  119. struct ce_sendlist_item item[CE_SENDLIST_ITEMS_MAX];
  120. };
  121. /* Copy Engine settable attributes */
  122. struct ce_attr;
  123. /*==================Send====================*/
  124. /* ath10k_ce_send flags */
  125. #define CE_SEND_FLAG_BYTE_SWAP 1
  126. /*
  127. * Queue a source buffer to be sent to an anonymous destination buffer.
  128. * ce - which copy engine to use
  129. * buffer - address of buffer
  130. * nbytes - number of bytes to send
  131. * transfer_id - arbitrary ID; reflected to destination
  132. * flags - CE_SEND_FLAG_* values
  133. * Returns 0 on success; otherwise an error status.
  134. *
  135. * Note: If no flags are specified, use CE's default data swap mode.
  136. *
  137. * Implementation note: pushes 1 buffer to Source ring
  138. */
  139. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  140. void *per_transfer_send_context,
  141. u32 buffer,
  142. unsigned int nbytes,
  143. /* 14 bits */
  144. unsigned int transfer_id,
  145. unsigned int flags);
  146. void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
  147. void (*send_cb)(struct ath10k_ce_pipe *),
  148. int disable_interrupts);
  149. /* Append a simple buffer (address/length) to a sendlist. */
  150. void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist,
  151. u32 buffer,
  152. unsigned int nbytes,
  153. /* OR-ed with internal flags */
  154. u32 flags);
  155. /*
  156. * Queue a "sendlist" of buffers to be sent using gather to a single
  157. * anonymous destination buffer
  158. * ce - which copy engine to use
  159. * sendlist - list of simple buffers to send using gather
  160. * transfer_id - arbitrary ID; reflected to destination
  161. * Returns 0 on success; otherwise an error status.
  162. *
  163. * Implemenation note: Pushes multiple buffers with Gather to Source ring.
  164. */
  165. int ath10k_ce_sendlist_send(struct ath10k_ce_pipe *ce_state,
  166. void *per_transfer_send_context,
  167. struct ce_sendlist *sendlist,
  168. /* 14 bits */
  169. unsigned int transfer_id);
  170. /*==================Recv=======================*/
  171. /*
  172. * Make a buffer available to receive. The buffer must be at least of a
  173. * minimal size appropriate for this copy engine (src_sz_max attribute).
  174. * ce - which copy engine to use
  175. * per_transfer_recv_context - context passed back to caller's recv_cb
  176. * buffer - address of buffer in CE space
  177. * Returns 0 on success; otherwise an error status.
  178. *
  179. * Implemenation note: Pushes a buffer to Dest ring.
  180. */
  181. int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
  182. void *per_transfer_recv_context,
  183. u32 buffer);
  184. void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
  185. void (*recv_cb)(struct ath10k_ce_pipe *));
  186. /* recv flags */
  187. /* Data is byte-swapped */
  188. #define CE_RECV_FLAG_SWAPPED 1
  189. /*
  190. * Supply data for the next completed unprocessed receive descriptor.
  191. * Pops buffer from Dest ring.
  192. */
  193. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  194. void **per_transfer_contextp,
  195. u32 *bufferp,
  196. unsigned int *nbytesp,
  197. unsigned int *transfer_idp,
  198. unsigned int *flagsp);
  199. /*
  200. * Supply data for the next completed unprocessed send descriptor.
  201. * Pops 1 completed send buffer from Source ring.
  202. */
  203. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  204. void **per_transfer_contextp,
  205. u32 *bufferp,
  206. unsigned int *nbytesp,
  207. unsigned int *transfer_idp);
  208. /*==================CE Engine Initialization=======================*/
  209. /* Initialize an instance of a CE */
  210. struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
  211. unsigned int ce_id,
  212. const struct ce_attr *attr);
  213. /*==================CE Engine Shutdown=======================*/
  214. /*
  215. * Support clean shutdown by allowing the caller to revoke
  216. * receive buffers. Target DMA must be stopped before using
  217. * this API.
  218. */
  219. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  220. void **per_transfer_contextp,
  221. u32 *bufferp);
  222. /*
  223. * Support clean shutdown by allowing the caller to cancel
  224. * pending sends. Target DMA must be stopped before using
  225. * this API.
  226. */
  227. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  228. void **per_transfer_contextp,
  229. u32 *bufferp,
  230. unsigned int *nbytesp,
  231. unsigned int *transfer_idp);
  232. void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state);
  233. /*==================CE Interrupt Handlers====================*/
  234. void ath10k_ce_per_engine_service_any(struct ath10k *ar);
  235. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
  236. void ath10k_ce_disable_interrupts(struct ath10k *ar);
  237. /* ce_attr.flags values */
  238. /* Use NonSnooping PCIe accesses? */
  239. #define CE_ATTR_NO_SNOOP 1
  240. /* Byte swap data words */
  241. #define CE_ATTR_BYTE_SWAP_DATA 2
  242. /* Swizzle descriptors? */
  243. #define CE_ATTR_SWIZZLE_DESCRIPTORS 4
  244. /* no interrupt on copy completion */
  245. #define CE_ATTR_DIS_INTR 8
  246. /* Attributes of an instance of a Copy Engine */
  247. struct ce_attr {
  248. /* CE_ATTR_* values */
  249. unsigned int flags;
  250. /* #entries in source ring - Must be a power of 2 */
  251. unsigned int src_nentries;
  252. /*
  253. * Max source send size for this CE.
  254. * This is also the minimum size of a destination buffer.
  255. */
  256. unsigned int src_sz_max;
  257. /* #entries in destination ring - Must be a power of 2 */
  258. unsigned int dest_nentries;
  259. };
  260. /*
  261. * When using sendlist_send to transfer multiple buffer fragments, the
  262. * transfer context of each fragment, except last one, will be filled
  263. * with CE_SENDLIST_ITEM_CTXT. ce_completed_send will return success for
  264. * each fragment done with send and the transfer context would be
  265. * CE_SENDLIST_ITEM_CTXT. Upper layer could use this to identify the
  266. * status of a send completion.
  267. */
  268. #define CE_SENDLIST_ITEM_CTXT ((void *)0xcecebeef)
  269. #define SR_BA_ADDRESS 0x0000
  270. #define SR_SIZE_ADDRESS 0x0004
  271. #define DR_BA_ADDRESS 0x0008
  272. #define DR_SIZE_ADDRESS 0x000c
  273. #define CE_CMD_ADDRESS 0x0018
  274. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MSB 17
  275. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB 17
  276. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK 0x00020000
  277. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(x) \
  278. (((0 | (x)) << CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB) & \
  279. CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK)
  280. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MSB 16
  281. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB 16
  282. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK 0x00010000
  283. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_GET(x) \
  284. (((x) & CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) >> \
  285. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB)
  286. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(x) \
  287. (((0 | (x)) << CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB) & \
  288. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK)
  289. #define CE_CTRL1_DMAX_LENGTH_MSB 15
  290. #define CE_CTRL1_DMAX_LENGTH_LSB 0
  291. #define CE_CTRL1_DMAX_LENGTH_MASK 0x0000ffff
  292. #define CE_CTRL1_DMAX_LENGTH_GET(x) \
  293. (((x) & CE_CTRL1_DMAX_LENGTH_MASK) >> CE_CTRL1_DMAX_LENGTH_LSB)
  294. #define CE_CTRL1_DMAX_LENGTH_SET(x) \
  295. (((0 | (x)) << CE_CTRL1_DMAX_LENGTH_LSB) & CE_CTRL1_DMAX_LENGTH_MASK)
  296. #define CE_CTRL1_ADDRESS 0x0010
  297. #define CE_CTRL1_HW_MASK 0x0007ffff
  298. #define CE_CTRL1_SW_MASK 0x0007ffff
  299. #define CE_CTRL1_HW_WRITE_MASK 0x00000000
  300. #define CE_CTRL1_SW_WRITE_MASK 0x0007ffff
  301. #define CE_CTRL1_RSTMASK 0xffffffff
  302. #define CE_CTRL1_RESET 0x00000080
  303. #define CE_CMD_HALT_STATUS_MSB 3
  304. #define CE_CMD_HALT_STATUS_LSB 3
  305. #define CE_CMD_HALT_STATUS_MASK 0x00000008
  306. #define CE_CMD_HALT_STATUS_GET(x) \
  307. (((x) & CE_CMD_HALT_STATUS_MASK) >> CE_CMD_HALT_STATUS_LSB)
  308. #define CE_CMD_HALT_STATUS_SET(x) \
  309. (((0 | (x)) << CE_CMD_HALT_STATUS_LSB) & CE_CMD_HALT_STATUS_MASK)
  310. #define CE_CMD_HALT_STATUS_RESET 0
  311. #define CE_CMD_HALT_MSB 0
  312. #define CE_CMD_HALT_MASK 0x00000001
  313. #define HOST_IE_COPY_COMPLETE_MSB 0
  314. #define HOST_IE_COPY_COMPLETE_LSB 0
  315. #define HOST_IE_COPY_COMPLETE_MASK 0x00000001
  316. #define HOST_IE_COPY_COMPLETE_GET(x) \
  317. (((x) & HOST_IE_COPY_COMPLETE_MASK) >> HOST_IE_COPY_COMPLETE_LSB)
  318. #define HOST_IE_COPY_COMPLETE_SET(x) \
  319. (((0 | (x)) << HOST_IE_COPY_COMPLETE_LSB) & HOST_IE_COPY_COMPLETE_MASK)
  320. #define HOST_IE_COPY_COMPLETE_RESET 0
  321. #define HOST_IE_ADDRESS 0x002c
  322. #define HOST_IS_DST_RING_LOW_WATERMARK_MASK 0x00000010
  323. #define HOST_IS_DST_RING_HIGH_WATERMARK_MASK 0x00000008
  324. #define HOST_IS_SRC_RING_LOW_WATERMARK_MASK 0x00000004
  325. #define HOST_IS_SRC_RING_HIGH_WATERMARK_MASK 0x00000002
  326. #define HOST_IS_COPY_COMPLETE_MASK 0x00000001
  327. #define HOST_IS_ADDRESS 0x0030
  328. #define MISC_IE_ADDRESS 0x0034
  329. #define MISC_IS_AXI_ERR_MASK 0x00000400
  330. #define MISC_IS_DST_ADDR_ERR_MASK 0x00000200
  331. #define MISC_IS_SRC_LEN_ERR_MASK 0x00000100
  332. #define MISC_IS_DST_MAX_LEN_VIO_MASK 0x00000080
  333. #define MISC_IS_DST_RING_OVERFLOW_MASK 0x00000040
  334. #define MISC_IS_SRC_RING_OVERFLOW_MASK 0x00000020
  335. #define MISC_IS_ADDRESS 0x0038
  336. #define SR_WR_INDEX_ADDRESS 0x003c
  337. #define DST_WR_INDEX_ADDRESS 0x0040
  338. #define CURRENT_SRRI_ADDRESS 0x0044
  339. #define CURRENT_DRRI_ADDRESS 0x0048
  340. #define SRC_WATERMARK_LOW_MSB 31
  341. #define SRC_WATERMARK_LOW_LSB 16
  342. #define SRC_WATERMARK_LOW_MASK 0xffff0000
  343. #define SRC_WATERMARK_LOW_GET(x) \
  344. (((x) & SRC_WATERMARK_LOW_MASK) >> SRC_WATERMARK_LOW_LSB)
  345. #define SRC_WATERMARK_LOW_SET(x) \
  346. (((0 | (x)) << SRC_WATERMARK_LOW_LSB) & SRC_WATERMARK_LOW_MASK)
  347. #define SRC_WATERMARK_LOW_RESET 0
  348. #define SRC_WATERMARK_HIGH_MSB 15
  349. #define SRC_WATERMARK_HIGH_LSB 0
  350. #define SRC_WATERMARK_HIGH_MASK 0x0000ffff
  351. #define SRC_WATERMARK_HIGH_GET(x) \
  352. (((x) & SRC_WATERMARK_HIGH_MASK) >> SRC_WATERMARK_HIGH_LSB)
  353. #define SRC_WATERMARK_HIGH_SET(x) \
  354. (((0 | (x)) << SRC_WATERMARK_HIGH_LSB) & SRC_WATERMARK_HIGH_MASK)
  355. #define SRC_WATERMARK_HIGH_RESET 0
  356. #define SRC_WATERMARK_ADDRESS 0x004c
  357. #define DST_WATERMARK_LOW_LSB 16
  358. #define DST_WATERMARK_LOW_MASK 0xffff0000
  359. #define DST_WATERMARK_LOW_SET(x) \
  360. (((0 | (x)) << DST_WATERMARK_LOW_LSB) & DST_WATERMARK_LOW_MASK)
  361. #define DST_WATERMARK_LOW_RESET 0
  362. #define DST_WATERMARK_HIGH_MSB 15
  363. #define DST_WATERMARK_HIGH_LSB 0
  364. #define DST_WATERMARK_HIGH_MASK 0x0000ffff
  365. #define DST_WATERMARK_HIGH_GET(x) \
  366. (((x) & DST_WATERMARK_HIGH_MASK) >> DST_WATERMARK_HIGH_LSB)
  367. #define DST_WATERMARK_HIGH_SET(x) \
  368. (((0 | (x)) << DST_WATERMARK_HIGH_LSB) & DST_WATERMARK_HIGH_MASK)
  369. #define DST_WATERMARK_HIGH_RESET 0
  370. #define DST_WATERMARK_ADDRESS 0x0050
  371. static inline u32 ath10k_ce_base_address(unsigned int ce_id)
  372. {
  373. return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
  374. }
  375. #define CE_WATERMARK_MASK (HOST_IS_SRC_RING_LOW_WATERMARK_MASK | \
  376. HOST_IS_SRC_RING_HIGH_WATERMARK_MASK | \
  377. HOST_IS_DST_RING_LOW_WATERMARK_MASK | \
  378. HOST_IS_DST_RING_HIGH_WATERMARK_MASK)
  379. #define CE_ERROR_MASK (MISC_IS_AXI_ERR_MASK | \
  380. MISC_IS_DST_ADDR_ERR_MASK | \
  381. MISC_IS_SRC_LEN_ERR_MASK | \
  382. MISC_IS_DST_MAX_LEN_VIO_MASK | \
  383. MISC_IS_DST_RING_OVERFLOW_MASK | \
  384. MISC_IS_SRC_RING_OVERFLOW_MASK)
  385. #define CE_SRC_RING_TO_DESC(baddr, idx) \
  386. (&(((struct ce_desc *)baddr)[idx]))
  387. #define CE_DEST_RING_TO_DESC(baddr, idx) \
  388. (&(((struct ce_desc *)baddr)[idx]))
  389. /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
  390. #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
  391. (((int)(toidx)-(int)(fromidx)) & (nentries_mask))
  392. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  393. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB 8
  394. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK 0x0000ff00
  395. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
  396. (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
  397. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
  398. #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
  399. #define CE_INTERRUPT_SUMMARY(ar) \
  400. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET( \
  401. ath10k_pci_read32((ar), CE_WRAPPER_BASE_ADDRESS + \
  402. CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS))
  403. #endif /* _CE_H_ */