ce.h 5.6 KB

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