ce.h 14 KB

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