ce.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. #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. /* Following desc flags are used in QCA99X0 */
  33. #define CE_DESC_FLAGS_HOST_INT_DIS (1 << 2)
  34. #define CE_DESC_FLAGS_TGT_INT_DIS (1 << 3)
  35. #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
  36. #define CE_DESC_FLAGS_META_DATA_LSB ar->hw_values->ce_desc_meta_data_lsb
  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. /* keep last */
  87. void *per_transfer_context[0];
  88. };
  89. struct ath10k_ce_pipe {
  90. struct ath10k *ar;
  91. unsigned int id;
  92. unsigned int attr_flags;
  93. u32 ctrl_addr;
  94. void (*send_cb)(struct ath10k_ce_pipe *);
  95. void (*recv_cb)(struct ath10k_ce_pipe *);
  96. unsigned int src_sz_max;
  97. struct ath10k_ce_ring *src_ring;
  98. struct ath10k_ce_ring *dest_ring;
  99. };
  100. /* Copy Engine settable attributes */
  101. struct ce_attr;
  102. /*==================Send====================*/
  103. /* ath10k_ce_send flags */
  104. #define CE_SEND_FLAG_BYTE_SWAP 1
  105. /*
  106. * Queue a source buffer to be sent to an anonymous destination buffer.
  107. * ce - which copy engine to use
  108. * buffer - address of buffer
  109. * nbytes - number of bytes to send
  110. * transfer_id - arbitrary ID; reflected to destination
  111. * flags - CE_SEND_FLAG_* values
  112. * Returns 0 on success; otherwise an error status.
  113. *
  114. * Note: If no flags are specified, use CE's default data swap mode.
  115. *
  116. * Implementation note: pushes 1 buffer to Source ring
  117. */
  118. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  119. void *per_transfer_send_context,
  120. u32 buffer,
  121. unsigned int nbytes,
  122. /* 14 bits */
  123. unsigned int transfer_id,
  124. unsigned int flags);
  125. int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  126. void *per_transfer_context,
  127. u32 buffer,
  128. unsigned int nbytes,
  129. unsigned int transfer_id,
  130. unsigned int flags);
  131. void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
  132. int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
  133. /*==================Recv=======================*/
  134. int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
  135. int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr);
  136. int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr);
  137. void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
  138. /* recv flags */
  139. /* Data is byte-swapped */
  140. #define CE_RECV_FLAG_SWAPPED 1
  141. /*
  142. * Supply data for the next completed unprocessed receive descriptor.
  143. * Pops buffer from Dest ring.
  144. */
  145. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  146. void **per_transfer_contextp,
  147. unsigned int *nbytesp);
  148. /*
  149. * Supply data for the next completed unprocessed send descriptor.
  150. * Pops 1 completed send buffer from Source ring.
  151. */
  152. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  153. void **per_transfer_contextp);
  154. int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  155. void **per_transfer_contextp);
  156. /*==================CE Engine Initialization=======================*/
  157. int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
  158. const struct ce_attr *attr);
  159. void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
  160. int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
  161. const struct ce_attr *attr);
  162. void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
  163. /*==================CE Engine Shutdown=======================*/
  164. /*
  165. * Support clean shutdown by allowing the caller to revoke
  166. * receive buffers. Target DMA must be stopped before using
  167. * this API.
  168. */
  169. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  170. void **per_transfer_contextp,
  171. u32 *bufferp);
  172. int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  173. void **per_transfer_contextp,
  174. unsigned int *nbytesp);
  175. /*
  176. * Support clean shutdown by allowing the caller to cancel
  177. * pending sends. Target DMA must be stopped before using
  178. * this API.
  179. */
  180. int ath10k_ce_cancel_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 Interrupt Handlers====================*/
  186. void ath10k_ce_per_engine_service_any(struct ath10k *ar);
  187. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
  188. int ath10k_ce_disable_interrupts(struct ath10k *ar);
  189. void ath10k_ce_enable_interrupts(struct ath10k *ar);
  190. void ath10k_ce_dump_registers(struct ath10k *ar,
  191. struct ath10k_fw_crash_data *crash_data);
  192. /* ce_attr.flags values */
  193. /* Use NonSnooping PCIe accesses? */
  194. #define CE_ATTR_NO_SNOOP 1
  195. /* Byte swap data words */
  196. #define CE_ATTR_BYTE_SWAP_DATA 2
  197. /* Swizzle descriptors? */
  198. #define CE_ATTR_SWIZZLE_DESCRIPTORS 4
  199. /* no interrupt on copy completion */
  200. #define CE_ATTR_DIS_INTR 8
  201. /* Attributes of an instance of a Copy Engine */
  202. struct ce_attr {
  203. /* CE_ATTR_* values */
  204. unsigned int flags;
  205. /* #entries in source ring - Must be a power of 2 */
  206. unsigned int src_nentries;
  207. /*
  208. * Max source send size for this CE.
  209. * This is also the minimum size of a destination buffer.
  210. */
  211. unsigned int src_sz_max;
  212. /* #entries in destination ring - Must be a power of 2 */
  213. unsigned int dest_nentries;
  214. void (*send_cb)(struct ath10k_ce_pipe *);
  215. void (*recv_cb)(struct ath10k_ce_pipe *);
  216. };
  217. #define SR_BA_ADDRESS 0x0000
  218. #define SR_SIZE_ADDRESS 0x0004
  219. #define DR_BA_ADDRESS 0x0008
  220. #define DR_SIZE_ADDRESS 0x000c
  221. #define CE_CMD_ADDRESS 0x0018
  222. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MSB 17
  223. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB 17
  224. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK 0x00020000
  225. #define CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(x) \
  226. (((0 | (x)) << CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB) & \
  227. CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK)
  228. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MSB 16
  229. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB 16
  230. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK 0x00010000
  231. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_GET(x) \
  232. (((x) & CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) >> \
  233. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB)
  234. #define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(x) \
  235. (((0 | (x)) << CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB) & \
  236. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK)
  237. #define CE_CTRL1_DMAX_LENGTH_MSB 15
  238. #define CE_CTRL1_DMAX_LENGTH_LSB 0
  239. #define CE_CTRL1_DMAX_LENGTH_MASK 0x0000ffff
  240. #define CE_CTRL1_DMAX_LENGTH_GET(x) \
  241. (((x) & CE_CTRL1_DMAX_LENGTH_MASK) >> CE_CTRL1_DMAX_LENGTH_LSB)
  242. #define CE_CTRL1_DMAX_LENGTH_SET(x) \
  243. (((0 | (x)) << CE_CTRL1_DMAX_LENGTH_LSB) & CE_CTRL1_DMAX_LENGTH_MASK)
  244. #define CE_CTRL1_ADDRESS 0x0010
  245. #define CE_CTRL1_HW_MASK 0x0007ffff
  246. #define CE_CTRL1_SW_MASK 0x0007ffff
  247. #define CE_CTRL1_HW_WRITE_MASK 0x00000000
  248. #define CE_CTRL1_SW_WRITE_MASK 0x0007ffff
  249. #define CE_CTRL1_RSTMASK 0xffffffff
  250. #define CE_CTRL1_RESET 0x00000080
  251. #define CE_CMD_HALT_STATUS_MSB 3
  252. #define CE_CMD_HALT_STATUS_LSB 3
  253. #define CE_CMD_HALT_STATUS_MASK 0x00000008
  254. #define CE_CMD_HALT_STATUS_GET(x) \
  255. (((x) & CE_CMD_HALT_STATUS_MASK) >> CE_CMD_HALT_STATUS_LSB)
  256. #define CE_CMD_HALT_STATUS_SET(x) \
  257. (((0 | (x)) << CE_CMD_HALT_STATUS_LSB) & CE_CMD_HALT_STATUS_MASK)
  258. #define CE_CMD_HALT_STATUS_RESET 0
  259. #define CE_CMD_HALT_MSB 0
  260. #define CE_CMD_HALT_MASK 0x00000001
  261. #define HOST_IE_COPY_COMPLETE_MSB 0
  262. #define HOST_IE_COPY_COMPLETE_LSB 0
  263. #define HOST_IE_COPY_COMPLETE_MASK 0x00000001
  264. #define HOST_IE_COPY_COMPLETE_GET(x) \
  265. (((x) & HOST_IE_COPY_COMPLETE_MASK) >> HOST_IE_COPY_COMPLETE_LSB)
  266. #define HOST_IE_COPY_COMPLETE_SET(x) \
  267. (((0 | (x)) << HOST_IE_COPY_COMPLETE_LSB) & HOST_IE_COPY_COMPLETE_MASK)
  268. #define HOST_IE_COPY_COMPLETE_RESET 0
  269. #define HOST_IE_ADDRESS 0x002c
  270. #define HOST_IS_DST_RING_LOW_WATERMARK_MASK 0x00000010
  271. #define HOST_IS_DST_RING_HIGH_WATERMARK_MASK 0x00000008
  272. #define HOST_IS_SRC_RING_LOW_WATERMARK_MASK 0x00000004
  273. #define HOST_IS_SRC_RING_HIGH_WATERMARK_MASK 0x00000002
  274. #define HOST_IS_COPY_COMPLETE_MASK 0x00000001
  275. #define HOST_IS_ADDRESS 0x0030
  276. #define MISC_IE_ADDRESS 0x0034
  277. #define MISC_IS_AXI_ERR_MASK 0x00000400
  278. #define MISC_IS_DST_ADDR_ERR_MASK 0x00000200
  279. #define MISC_IS_SRC_LEN_ERR_MASK 0x00000100
  280. #define MISC_IS_DST_MAX_LEN_VIO_MASK 0x00000080
  281. #define MISC_IS_DST_RING_OVERFLOW_MASK 0x00000040
  282. #define MISC_IS_SRC_RING_OVERFLOW_MASK 0x00000020
  283. #define MISC_IS_ADDRESS 0x0038
  284. #define SR_WR_INDEX_ADDRESS 0x003c
  285. #define DST_WR_INDEX_ADDRESS 0x0040
  286. #define CURRENT_SRRI_ADDRESS 0x0044
  287. #define CURRENT_DRRI_ADDRESS 0x0048
  288. #define SRC_WATERMARK_LOW_MSB 31
  289. #define SRC_WATERMARK_LOW_LSB 16
  290. #define SRC_WATERMARK_LOW_MASK 0xffff0000
  291. #define SRC_WATERMARK_LOW_GET(x) \
  292. (((x) & SRC_WATERMARK_LOW_MASK) >> SRC_WATERMARK_LOW_LSB)
  293. #define SRC_WATERMARK_LOW_SET(x) \
  294. (((0 | (x)) << SRC_WATERMARK_LOW_LSB) & SRC_WATERMARK_LOW_MASK)
  295. #define SRC_WATERMARK_LOW_RESET 0
  296. #define SRC_WATERMARK_HIGH_MSB 15
  297. #define SRC_WATERMARK_HIGH_LSB 0
  298. #define SRC_WATERMARK_HIGH_MASK 0x0000ffff
  299. #define SRC_WATERMARK_HIGH_GET(x) \
  300. (((x) & SRC_WATERMARK_HIGH_MASK) >> SRC_WATERMARK_HIGH_LSB)
  301. #define SRC_WATERMARK_HIGH_SET(x) \
  302. (((0 | (x)) << SRC_WATERMARK_HIGH_LSB) & SRC_WATERMARK_HIGH_MASK)
  303. #define SRC_WATERMARK_HIGH_RESET 0
  304. #define SRC_WATERMARK_ADDRESS 0x004c
  305. #define DST_WATERMARK_LOW_LSB 16
  306. #define DST_WATERMARK_LOW_MASK 0xffff0000
  307. #define DST_WATERMARK_LOW_SET(x) \
  308. (((0 | (x)) << DST_WATERMARK_LOW_LSB) & DST_WATERMARK_LOW_MASK)
  309. #define DST_WATERMARK_LOW_RESET 0
  310. #define DST_WATERMARK_HIGH_MSB 15
  311. #define DST_WATERMARK_HIGH_LSB 0
  312. #define DST_WATERMARK_HIGH_MASK 0x0000ffff
  313. #define DST_WATERMARK_HIGH_GET(x) \
  314. (((x) & DST_WATERMARK_HIGH_MASK) >> DST_WATERMARK_HIGH_LSB)
  315. #define DST_WATERMARK_HIGH_SET(x) \
  316. (((0 | (x)) << DST_WATERMARK_HIGH_LSB) & DST_WATERMARK_HIGH_MASK)
  317. #define DST_WATERMARK_HIGH_RESET 0
  318. #define DST_WATERMARK_ADDRESS 0x0050
  319. static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
  320. {
  321. return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
  322. }
  323. #define CE_WATERMARK_MASK (HOST_IS_SRC_RING_LOW_WATERMARK_MASK | \
  324. HOST_IS_SRC_RING_HIGH_WATERMARK_MASK | \
  325. HOST_IS_DST_RING_LOW_WATERMARK_MASK | \
  326. HOST_IS_DST_RING_HIGH_WATERMARK_MASK)
  327. #define CE_ERROR_MASK (MISC_IS_AXI_ERR_MASK | \
  328. MISC_IS_DST_ADDR_ERR_MASK | \
  329. MISC_IS_SRC_LEN_ERR_MASK | \
  330. MISC_IS_DST_MAX_LEN_VIO_MASK | \
  331. MISC_IS_DST_RING_OVERFLOW_MASK | \
  332. MISC_IS_SRC_RING_OVERFLOW_MASK)
  333. #define CE_SRC_RING_TO_DESC(baddr, idx) \
  334. (&(((struct ce_desc *)baddr)[idx]))
  335. #define CE_DEST_RING_TO_DESC(baddr, idx) \
  336. (&(((struct ce_desc *)baddr)[idx]))
  337. /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
  338. #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
  339. (((int)(toidx) - (int)(fromidx)) & (nentries_mask))
  340. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  341. #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
  342. (((idx) + (num)) & (nentries_mask))
  343. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
  344. ar->regs->ce_wrap_intr_sum_host_msi_lsb
  345. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
  346. ar->regs->ce_wrap_intr_sum_host_msi_mask
  347. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
  348. (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
  349. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
  350. #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
  351. #define CE_INTERRUPT_SUMMARY(ar) \
  352. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET( \
  353. ath10k_pci_read32((ar), CE_WRAPPER_BASE_ADDRESS + \
  354. CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS))
  355. #endif /* _CE_H_ */