dp_rx_buffer_pool.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef _DP_RX_BUFFER_POOL_H_
  20. #define _DP_RX_BUFFER_POOL_H_
  21. #include "dp_types.h"
  22. #include "qdf_nbuf.h"
  23. #include "qdf_module.h"
  24. #include "athdefs.h"
  25. #include "wlan_cfg.h"
  26. #include "dp_internal.h"
  27. #include "dp_rx.h"
  28. #ifdef WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL
  29. /**
  30. * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
  31. * @soc: SoC handle
  32. * @mac_id: MAC ID
  33. *
  34. * Return: None
  35. */
  36. void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id);
  37. /**
  38. * dp_rx_buffer_pool_deinit() - De-Initialize emergency buffer pool
  39. * @soc: SoC handle
  40. * @mac_id: MAC ID
  41. *
  42. * Return: None
  43. */
  44. void dp_rx_buffer_pool_deinit(struct dp_soc *soc, u8 mac_id);
  45. /**
  46. * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
  47. * refill the emergency buffer pool
  48. * @soc: SoC handle
  49. * @nbuf: RX buffer
  50. * @mac_id: MAC ID
  51. *
  52. * Return: Whether the rx nbuf is consumed into the pool or not.
  53. */
  54. bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id);
  55. /**
  56. * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
  57. * back into the pool
  58. * @soc: SoC handle
  59. * @nbuf: RX buffer
  60. * @mac_id: MAC ID
  61. *
  62. * Return: None
  63. */
  64. void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
  65. u8 mac_id);
  66. /**
  67. * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
  68. * give nbuf from the pool if allocation fails
  69. * @soc: SoC handle
  70. * @mac_id: MAC ID
  71. * @rx_desc_pool: RX descriptor pool
  72. * @num_available_buffers: number of available buffers in the ring.
  73. *
  74. * Return: nbuf
  75. */
  76. qdf_nbuf_t dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
  77. struct rx_desc_pool *rx_desc_pool,
  78. uint32_t num_available_buffers);
  79. /**
  80. * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
  81. * @soc: SoC handle
  82. * @rx_desc_pool: RX descriptor pool
  83. * @nbuf_frag_info_t: nbuf frag info
  84. *
  85. * Return: nbuf
  86. */
  87. QDF_STATUS
  88. dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
  89. struct rx_desc_pool *rx_desc_pool,
  90. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t);
  91. /**
  92. * dp_rx_schedule_refill_thread() - Schedule RX refill thread to enqueue
  93. * buffers in refill pool
  94. * @soc: SoC handle
  95. *
  96. */
  97. static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc)
  98. {
  99. struct rx_refill_buff_pool *buff_pool = &soc->rx_refill_buff_pool;
  100. uint16_t head = buff_pool->head;
  101. uint16_t tail = buff_pool->tail;
  102. uint16_t num_refill;
  103. if (!buff_pool->is_initialized)
  104. return;
  105. if (tail > head)
  106. num_refill = (tail - head - 1);
  107. else
  108. num_refill = (buff_pool->max_bufq_len - head + tail - 1);
  109. if (soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread &&
  110. num_refill >= DP_RX_REFILL_THRD_THRESHOLD)
  111. soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread(
  112. dp_soc_to_cdp_soc_t(soc));
  113. }
  114. #else
  115. /**
  116. * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
  117. * @soc: SoC handle
  118. * @mac_id: MAC ID
  119. *
  120. * Return: None
  121. */
  122. static inline
  123. void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id)
  124. {
  125. soc->rx_buff_pool[mac_id].is_initialized = false;
  126. }
  127. /**
  128. * dp_rx_buffer_pool_deinit() - De-Initialize emergency buffer pool
  129. * @soc: SoC handle
  130. * @mac_id: MAC ID
  131. *
  132. * Return: None
  133. */
  134. static inline
  135. void dp_rx_buffer_pool_deinit(struct dp_soc *soc, u8 mac_id)
  136. {
  137. }
  138. /**
  139. * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
  140. * refill the emergency buffer pool
  141. * @soc: SoC handle
  142. * @nbuf: RX buffer
  143. * @mac_id: MAC ID
  144. *
  145. * Return: Whether the rx nbuf is consumed into the pool or not.
  146. */
  147. static inline
  148. bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id)
  149. {
  150. return false;
  151. }
  152. /**
  153. * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
  154. * back into the pool
  155. * @soc: SoC handle
  156. * @nbuf: RX buffer
  157. * @mac_id: MAC ID
  158. *
  159. * Return: None
  160. */
  161. static inline
  162. void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
  163. u8 mac_id)
  164. {
  165. qdf_nbuf_free(nbuf);
  166. }
  167. /**
  168. * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
  169. * give nbuf from the pool if allocation fails
  170. * @soc: SoC handle
  171. * @mac_id: MAC ID
  172. * @rx_desc_pool: RX descriptor pool
  173. * @num_available_buffers: number of available buffers in the ring.
  174. *
  175. * Return: nbuf
  176. */
  177. static inline qdf_nbuf_t
  178. dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
  179. struct rx_desc_pool *rx_desc_pool,
  180. uint32_t num_available_buffers)
  181. {
  182. return qdf_nbuf_alloc(soc->osdev, rx_desc_pool->buf_size,
  183. RX_BUFFER_RESERVATION,
  184. rx_desc_pool->buf_alignment, FALSE);
  185. }
  186. /**
  187. * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
  188. * @soc: SoC handle
  189. * @rx_desc_pool: RX descriptor pool
  190. * @nbuf_frag_info_t: nbuf frag info
  191. *
  192. * Return: nbuf
  193. */
  194. static inline QDF_STATUS
  195. dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
  196. struct rx_desc_pool *rx_desc_pool,
  197. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  198. {
  199. QDF_STATUS status;
  200. status = qdf_nbuf_map_nbytes_single(soc->osdev,
  201. (nbuf_frag_info_t->virt_addr).nbuf,
  202. QDF_DMA_FROM_DEVICE,
  203. rx_desc_pool->buf_size);
  204. if (QDF_IS_STATUS_ERROR(status))
  205. return status;
  206. dp_audio_smmu_map(soc->osdev,
  207. qdf_mem_paddr_from_dmaaddr(soc->osdev,
  208. QDF_NBUF_CB_PADDR((nbuf_frag_info_t->virt_addr).nbuf)),
  209. QDF_NBUF_CB_PADDR((nbuf_frag_info_t->virt_addr).nbuf),
  210. rx_desc_pool->buf_size);
  211. return status;
  212. }
  213. static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc) { }
  214. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  215. #endif /* _DP_RX_BUFFER_POOL_H_ */