ce.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. struct ath10k_bus_ops {
  103. u32 (*read32)(struct ath10k *ar, u32 offset);
  104. void (*write32)(struct ath10k *ar, u32 offset, u32 value);
  105. int (*get_num_banks)(struct ath10k *ar);
  106. };
  107. static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
  108. {
  109. return (struct ath10k_ce *)ar->ce_priv;
  110. }
  111. struct ath10k_ce {
  112. /* protects CE info */
  113. spinlock_t ce_lock;
  114. const struct ath10k_bus_ops *bus_ops;
  115. struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
  116. };
  117. /*==================Send====================*/
  118. /* ath10k_ce_send flags */
  119. #define CE_SEND_FLAG_BYTE_SWAP 1
  120. /*
  121. * Queue a source buffer to be sent to an anonymous destination buffer.
  122. * ce - which copy engine to use
  123. * buffer - address of buffer
  124. * nbytes - number of bytes to send
  125. * transfer_id - arbitrary ID; reflected to destination
  126. * flags - CE_SEND_FLAG_* values
  127. * Returns 0 on success; otherwise an error status.
  128. *
  129. * Note: If no flags are specified, use CE's default data swap mode.
  130. *
  131. * Implementation note: pushes 1 buffer to Source ring
  132. */
  133. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  134. void *per_transfer_send_context,
  135. u32 buffer,
  136. unsigned int nbytes,
  137. /* 14 bits */
  138. unsigned int transfer_id,
  139. unsigned int flags);
  140. int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  141. void *per_transfer_context,
  142. u32 buffer,
  143. unsigned int nbytes,
  144. unsigned int transfer_id,
  145. unsigned int flags);
  146. void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
  147. int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
  148. /*==================Recv=======================*/
  149. int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
  150. int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr);
  151. int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr);
  152. void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
  153. /* recv flags */
  154. /* Data is byte-swapped */
  155. #define CE_RECV_FLAG_SWAPPED 1
  156. /*
  157. * Supply data for the next completed unprocessed receive descriptor.
  158. * Pops buffer from Dest ring.
  159. */
  160. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  161. void **per_transfer_contextp,
  162. unsigned int *nbytesp);
  163. /*
  164. * Supply data for the next completed unprocessed send descriptor.
  165. * Pops 1 completed send buffer from Source ring.
  166. */
  167. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  168. void **per_transfer_contextp);
  169. int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  170. void **per_transfer_contextp);
  171. /*==================CE Engine Initialization=======================*/
  172. int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
  173. const struct ce_attr *attr);
  174. void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
  175. int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
  176. const struct ce_attr *attr);
  177. void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
  178. /*==================CE Engine Shutdown=======================*/
  179. /*
  180. * Support clean shutdown by allowing the caller to revoke
  181. * receive buffers. Target DMA must be stopped before using
  182. * this API.
  183. */
  184. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  185. void **per_transfer_contextp,
  186. u32 *bufferp);
  187. int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  188. void **per_transfer_contextp,
  189. unsigned int *nbytesp);
  190. /*
  191. * Support clean shutdown by allowing the caller to cancel
  192. * pending sends. Target DMA must be stopped before using
  193. * this API.
  194. */
  195. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  196. void **per_transfer_contextp,
  197. u32 *bufferp,
  198. unsigned int *nbytesp,
  199. unsigned int *transfer_idp);
  200. /*==================CE Interrupt Handlers====================*/
  201. void ath10k_ce_per_engine_service_any(struct ath10k *ar);
  202. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
  203. int ath10k_ce_disable_interrupts(struct ath10k *ar);
  204. void ath10k_ce_enable_interrupts(struct ath10k *ar);
  205. void ath10k_ce_dump_registers(struct ath10k *ar,
  206. struct ath10k_fw_crash_data *crash_data);
  207. /* ce_attr.flags values */
  208. /* Use NonSnooping PCIe accesses? */
  209. #define CE_ATTR_NO_SNOOP 1
  210. /* Byte swap data words */
  211. #define CE_ATTR_BYTE_SWAP_DATA 2
  212. /* Swizzle descriptors? */
  213. #define CE_ATTR_SWIZZLE_DESCRIPTORS 4
  214. /* no interrupt on copy completion */
  215. #define CE_ATTR_DIS_INTR 8
  216. /* Attributes of an instance of a Copy Engine */
  217. struct ce_attr {
  218. /* CE_ATTR_* values */
  219. unsigned int flags;
  220. /* #entries in source ring - Must be a power of 2 */
  221. unsigned int src_nentries;
  222. /*
  223. * Max source send size for this CE.
  224. * This is also the minimum size of a destination buffer.
  225. */
  226. unsigned int src_sz_max;
  227. /* #entries in destination ring - Must be a power of 2 */
  228. unsigned int dest_nentries;
  229. void (*send_cb)(struct ath10k_ce_pipe *);
  230. void (*recv_cb)(struct ath10k_ce_pipe *);
  231. };
  232. static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
  233. {
  234. return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
  235. }
  236. #define CE_SRC_RING_TO_DESC(baddr, idx) \
  237. (&(((struct ce_desc *)baddr)[idx]))
  238. #define CE_DEST_RING_TO_DESC(baddr, idx) \
  239. (&(((struct ce_desc *)baddr)[idx]))
  240. /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
  241. #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
  242. (((int)(toidx) - (int)(fromidx)) & (nentries_mask))
  243. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  244. #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
  245. (((idx) + (num)) & (nentries_mask))
  246. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
  247. ar->regs->ce_wrap_intr_sum_host_msi_lsb
  248. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
  249. ar->regs->ce_wrap_intr_sum_host_msi_mask
  250. #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
  251. (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
  252. CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
  253. #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
  254. static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
  255. {
  256. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  257. return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
  258. ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
  259. CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
  260. }
  261. #endif /* _CE_H_ */