ce.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: BSD-3-Clause-Clear */
  2. /*
  3. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef ATH11K_CE_H
  7. #define ATH11K_CE_H
  8. #define CE_COUNT_MAX 12
  9. /* Byte swap data words */
  10. #define CE_ATTR_BYTE_SWAP_DATA 2
  11. /* no interrupt on copy completion */
  12. #define CE_ATTR_DIS_INTR 8
  13. /* Host software's Copy Engine configuration. */
  14. #ifdef __BIG_ENDIAN
  15. #define CE_ATTR_FLAGS CE_ATTR_BYTE_SWAP_DATA
  16. #else
  17. #define CE_ATTR_FLAGS 0
  18. #endif
  19. /* Threshold to poll for tx completion in case of Interrupt disabled CE's */
  20. #define ATH11K_CE_USAGE_THRESHOLD 32
  21. void ath11k_ce_byte_swap(void *mem, u32 len);
  22. /*
  23. * Directions for interconnect pipe configuration.
  24. * These definitions may be used during configuration and are shared
  25. * between Host and Target.
  26. *
  27. * Pipe Directions are relative to the Host, so PIPEDIR_IN means
  28. * "coming IN over air through Target to Host" as with a WiFi Rx operation.
  29. * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
  30. * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
  31. * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
  32. * over the interconnect.
  33. */
  34. #define PIPEDIR_NONE 0
  35. #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
  36. #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
  37. #define PIPEDIR_INOUT 3 /* bidirectional */
  38. #define PIPEDIR_INOUT_H2H 4 /* bidirectional, host to host */
  39. /* CE address/mask */
  40. #define CE_HOST_IE_ADDRESS 0x00A1803C
  41. #define CE_HOST_IE_2_ADDRESS 0x00A18040
  42. #define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS
  43. /* CE IE registers are different for IPQ5018 */
  44. #define CE_HOST_IPQ5018_IE_ADDRESS 0x0841804C
  45. #define CE_HOST_IPQ5018_IE_2_ADDRESS 0x08418050
  46. #define CE_HOST_IPQ5018_IE_3_ADDRESS CE_HOST_IPQ5018_IE_ADDRESS
  47. #define CE_HOST_IE_3_SHIFT 0xC
  48. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  49. #define ATH11K_CE_RX_POST_RETRY_JIFFIES 50
  50. struct ath11k_base;
  51. /*
  52. * Establish a mapping between a service/direction and a pipe.
  53. * Configuration information for a Copy Engine pipe and services.
  54. * Passed from Host to Target through QMI message and must be in
  55. * little endian format.
  56. */
  57. struct service_to_pipe {
  58. __le32 service_id;
  59. __le32 pipedir;
  60. __le32 pipenum;
  61. };
  62. /*
  63. * Configuration information for a Copy Engine pipe.
  64. * Passed from Host to Target through QMI message during startup (one per CE).
  65. *
  66. * NOTE: Structure is shared between Host software and Target firmware!
  67. */
  68. struct ce_pipe_config {
  69. __le32 pipenum;
  70. __le32 pipedir;
  71. __le32 nentries;
  72. __le32 nbytes_max;
  73. __le32 flags;
  74. __le32 reserved;
  75. };
  76. struct ce_ie_addr {
  77. u32 ie1_reg_addr;
  78. u32 ie2_reg_addr;
  79. u32 ie3_reg_addr;
  80. };
  81. struct ce_remap {
  82. u32 base;
  83. u32 size;
  84. };
  85. struct ce_attr {
  86. /* CE_ATTR_* values */
  87. unsigned int flags;
  88. /* #entries in source ring - Must be a power of 2 */
  89. unsigned int src_nentries;
  90. /*
  91. * Max source send size for this CE.
  92. * This is also the minimum size of a destination buffer.
  93. */
  94. unsigned int src_sz_max;
  95. /* #entries in destination ring - Must be a power of 2 */
  96. unsigned int dest_nentries;
  97. void (*recv_cb)(struct ath11k_base *, struct sk_buff *);
  98. void (*send_cb)(struct ath11k_base *, struct sk_buff *);
  99. };
  100. #define CE_DESC_RING_ALIGN 8
  101. struct ath11k_ce_ring {
  102. /* Number of entries in this ring; must be power of 2 */
  103. unsigned int nentries;
  104. unsigned int nentries_mask;
  105. /* For dest ring, this is the next index to be processed
  106. * by software after it was/is received into.
  107. *
  108. * For src ring, this is the last descriptor that was sent
  109. * and completion processed by software.
  110. *
  111. * Regardless of src or dest ring, this is an invariant
  112. * (modulo ring size):
  113. * write index >= read index >= sw_index
  114. */
  115. unsigned int sw_index;
  116. /* cached copy */
  117. unsigned int write_index;
  118. /* Start of DMA-coherent area reserved for descriptors */
  119. /* Host address space */
  120. void *base_addr_owner_space_unaligned;
  121. /* CE address space */
  122. dma_addr_t base_addr_ce_space_unaligned;
  123. /* Actual start of descriptors.
  124. * Aligned to descriptor-size boundary.
  125. * Points into reserved DMA-coherent area, above.
  126. */
  127. /* Host address space */
  128. void *base_addr_owner_space;
  129. /* CE address space */
  130. dma_addr_t base_addr_ce_space;
  131. /* HAL ring id */
  132. u32 hal_ring_id;
  133. /* keep last */
  134. struct sk_buff *skb[];
  135. };
  136. struct ath11k_ce_pipe {
  137. struct ath11k_base *ab;
  138. u16 pipe_num;
  139. unsigned int attr_flags;
  140. unsigned int buf_sz;
  141. unsigned int rx_buf_needed;
  142. void (*send_cb)(struct ath11k_base *, struct sk_buff *);
  143. void (*recv_cb)(struct ath11k_base *, struct sk_buff *);
  144. struct tasklet_struct intr_tq;
  145. struct ath11k_ce_ring *src_ring;
  146. struct ath11k_ce_ring *dest_ring;
  147. struct ath11k_ce_ring *status_ring;
  148. u64 timestamp;
  149. };
  150. struct ath11k_ce {
  151. struct ath11k_ce_pipe ce_pipe[CE_COUNT_MAX];
  152. /* Protects rings of all ce pipes */
  153. spinlock_t ce_lock;
  154. struct ath11k_hp_update_timer hp_timer[CE_COUNT_MAX];
  155. };
  156. extern const struct ce_attr ath11k_host_ce_config_ipq8074[];
  157. extern const struct ce_attr ath11k_host_ce_config_qca6390[];
  158. extern const struct ce_attr ath11k_host_ce_config_qcn9074[];
  159. void ath11k_ce_cleanup_pipes(struct ath11k_base *ab);
  160. void ath11k_ce_rx_replenish_retry(struct timer_list *t);
  161. void ath11k_ce_per_engine_service(struct ath11k_base *ab, u16 ce_id);
  162. int ath11k_ce_send(struct ath11k_base *ab, struct sk_buff *skb, u8 pipe_id,
  163. u16 transfer_id);
  164. void ath11k_ce_rx_post_buf(struct ath11k_base *ab);
  165. int ath11k_ce_init_pipes(struct ath11k_base *ab);
  166. int ath11k_ce_alloc_pipes(struct ath11k_base *ab);
  167. void ath11k_ce_free_pipes(struct ath11k_base *ab);
  168. int ath11k_ce_get_attr_flags(struct ath11k_base *ab, int ce_id);
  169. void ath11k_ce_poll_send_completed(struct ath11k_base *ab, u8 pipe_id);
  170. void ath11k_ce_get_shadow_config(struct ath11k_base *ab,
  171. u32 **shadow_cfg, u32 *shadow_cfg_len);
  172. void ath11k_ce_stop_shadow_timers(struct ath11k_base *ab);
  173. #endif