ce.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: BSD-3-Clause-Clear */
  2. /*
  3. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  5. */
  6. #ifndef ATH12K_CE_H
  7. #define ATH12K_CE_H
  8. #define CE_COUNT_MAX 16
  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. #define CE_ATTR_FLAGS 0
  15. /* Threshold to poll for tx completion in case of Interrupt disabled CE's */
  16. #define ATH12K_CE_USAGE_THRESHOLD 32
  17. /* Directions for interconnect pipe configuration.
  18. * These definitions may be used during configuration and are shared
  19. * between Host and Target.
  20. *
  21. * Pipe Directions are relative to the Host, so PIPEDIR_IN means
  22. * "coming IN over air through Target to Host" as with a WiFi Rx operation.
  23. * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
  24. * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
  25. * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
  26. * over the interconnect.
  27. */
  28. #define PIPEDIR_NONE 0
  29. #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
  30. #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
  31. #define PIPEDIR_INOUT 3 /* bidirectional */
  32. #define PIPEDIR_INOUT_H2H 4 /* bidirectional, host to host */
  33. /* CE address/mask */
  34. #define CE_HOST_IE_ADDRESS 0x75804C
  35. #define CE_HOST_IE_2_ADDRESS 0x758050
  36. #define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS
  37. #define CE_HOST_IE_3_SHIFT 0xC
  38. #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
  39. #define ATH12K_CE_RX_POST_RETRY_JIFFIES 50
  40. struct ath12k_base;
  41. /* Establish a mapping between a service/direction and a pipe.
  42. * Configuration information for a Copy Engine pipe and services.
  43. * Passed from Host to Target through QMI message and must be in
  44. * little endian format.
  45. */
  46. struct service_to_pipe {
  47. __le32 service_id;
  48. __le32 pipedir;
  49. __le32 pipenum;
  50. };
  51. /* Configuration information for a Copy Engine pipe.
  52. * Passed from Host to Target through QMI message during startup (one per CE).
  53. *
  54. * NOTE: Structure is shared between Host software and Target firmware!
  55. */
  56. struct ce_pipe_config {
  57. __le32 pipenum;
  58. __le32 pipedir;
  59. __le32 nentries;
  60. __le32 nbytes_max;
  61. __le32 flags;
  62. __le32 reserved;
  63. };
  64. struct ce_ie_addr {
  65. u32 ie1_reg_addr;
  66. u32 ie2_reg_addr;
  67. u32 ie3_reg_addr;
  68. };
  69. struct ce_remap {
  70. u32 base;
  71. u32 size;
  72. u32 cmem_offset;
  73. };
  74. struct ce_attr {
  75. /* CE_ATTR_* values */
  76. unsigned int flags;
  77. /* #entries in source ring - Must be a power of 2 */
  78. unsigned int src_nentries;
  79. /* Max source send size for this CE.
  80. * This is also the minimum size of a destination buffer.
  81. */
  82. unsigned int src_sz_max;
  83. /* #entries in destination ring - Must be a power of 2 */
  84. unsigned int dest_nentries;
  85. void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);
  86. };
  87. #define CE_DESC_RING_ALIGN 8
  88. struct ath12k_ce_ring {
  89. /* Number of entries in this ring; must be power of 2 */
  90. unsigned int nentries;
  91. unsigned int nentries_mask;
  92. /* For dest ring, this is the next index to be processed
  93. * by software after it was/is received into.
  94. *
  95. * For src ring, this is the last descriptor that was sent
  96. * and completion processed by software.
  97. *
  98. * Regardless of src or dest ring, this is an invariant
  99. * (modulo ring size):
  100. * write index >= read index >= sw_index
  101. */
  102. unsigned int sw_index;
  103. /* cached copy */
  104. unsigned int write_index;
  105. /* Start of DMA-coherent area reserved for descriptors */
  106. /* Host address space */
  107. void *base_addr_owner_space_unaligned;
  108. /* CE address space */
  109. dma_addr_t base_addr_ce_space_unaligned;
  110. /* Actual start of descriptors.
  111. * Aligned to descriptor-size boundary.
  112. * Points into reserved DMA-coherent area, above.
  113. */
  114. /* Host address space */
  115. void *base_addr_owner_space;
  116. /* CE address space */
  117. dma_addr_t base_addr_ce_space;
  118. /* HAL ring id */
  119. u32 hal_ring_id;
  120. /* keep last */
  121. struct sk_buff *skb[];
  122. };
  123. struct ath12k_ce_pipe {
  124. struct ath12k_base *ab;
  125. u16 pipe_num;
  126. unsigned int attr_flags;
  127. unsigned int buf_sz;
  128. unsigned int rx_buf_needed;
  129. void (*send_cb)(struct ath12k_ce_pipe *pipe);
  130. void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);
  131. struct work_struct intr_wq;
  132. struct ath12k_ce_ring *src_ring;
  133. struct ath12k_ce_ring *dest_ring;
  134. struct ath12k_ce_ring *status_ring;
  135. u64 timestamp;
  136. };
  137. struct ath12k_ce {
  138. struct ath12k_ce_pipe ce_pipe[CE_COUNT_MAX];
  139. /* Protects rings of all ce pipes */
  140. spinlock_t ce_lock;
  141. struct ath12k_hp_update_timer hp_timer[CE_COUNT_MAX];
  142. };
  143. void ath12k_ce_cleanup_pipes(struct ath12k_base *ab);
  144. void ath12k_ce_rx_replenish_retry(struct timer_list *t);
  145. void ath12k_ce_per_engine_service(struct ath12k_base *ab, u16 ce_id);
  146. int ath12k_ce_send(struct ath12k_base *ab, struct sk_buff *skb, u8 pipe_id,
  147. u16 transfer_id);
  148. void ath12k_ce_rx_post_buf(struct ath12k_base *ab);
  149. int ath12k_ce_init_pipes(struct ath12k_base *ab);
  150. int ath12k_ce_alloc_pipes(struct ath12k_base *ab);
  151. void ath12k_ce_free_pipes(struct ath12k_base *ab);
  152. int ath12k_ce_get_attr_flags(struct ath12k_base *ab, int ce_id);
  153. void ath12k_ce_poll_send_completed(struct ath12k_base *ab, u8 pipe_id);
  154. void ath12k_ce_get_shadow_config(struct ath12k_base *ab,
  155. u32 **shadow_cfg, u32 *shadow_cfg_len);
  156. #endif