dp_rx_buffer_pool.h 5.8 KB

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