dp_rx_buffer_pool.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #include "dp_rx_mon.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. if (soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread)
  100. soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread(dp_soc_to_cdp_soc_t(soc));
  101. }
  102. /**
  103. * dp_rx_refill_buff_pool_lock() - Acquire Rx refill buff pool lock
  104. * @soc: SoC handle
  105. *
  106. */
  107. static inline void dp_rx_refill_buff_pool_lock(struct dp_soc *soc)
  108. {
  109. struct rx_refill_buff_pool *buff_pool = &soc->rx_refill_buff_pool;
  110. if (buff_pool->is_initialized &&
  111. qdf_spin_trylock_bh(&buff_pool->bufq_lock))
  112. buff_pool->in_rx_refill_lock = true;
  113. }
  114. /**
  115. * dp_rx_refill_buff_pool_unlock() - Release Rx refill buff pool lock
  116. * @soc: SoC handle
  117. *
  118. */
  119. static inline void dp_rx_refill_buff_pool_unlock(struct dp_soc *soc)
  120. {
  121. struct rx_refill_buff_pool *buff_pool = &soc->rx_refill_buff_pool;
  122. if (buff_pool->in_rx_refill_lock) {
  123. qdf_spin_unlock_bh(&buff_pool->bufq_lock);
  124. buff_pool->in_rx_refill_lock = false;
  125. }
  126. }
  127. #else
  128. /**
  129. * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
  130. * @soc: SoC handle
  131. * @mac_id: MAC ID
  132. *
  133. * Return: None
  134. */
  135. static inline
  136. void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id)
  137. {
  138. soc->rx_buff_pool[mac_id].is_initialized = false;
  139. }
  140. /**
  141. * dp_rx_buffer_pool_deinit() - De-Initialize emergency buffer pool
  142. * @soc: SoC handle
  143. * @mac_id: MAC ID
  144. *
  145. * Return: None
  146. */
  147. static inline
  148. void dp_rx_buffer_pool_deinit(struct dp_soc *soc, u8 mac_id)
  149. {
  150. }
  151. /**
  152. * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
  153. * refill the emergency buffer pool
  154. * @soc: SoC handle
  155. * @nbuf: RX buffer
  156. * @mac_id: MAC ID
  157. *
  158. * Return: Whether the rx nbuf is consumed into the pool or not.
  159. */
  160. static inline
  161. bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id)
  162. {
  163. return false;
  164. }
  165. /**
  166. * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
  167. * back into the pool
  168. * @soc: SoC handle
  169. * @nbuf: RX buffer
  170. * @mac_id: MAC ID
  171. *
  172. * Return: None
  173. */
  174. static inline
  175. void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
  176. u8 mac_id)
  177. {
  178. qdf_nbuf_free(nbuf);
  179. }
  180. /**
  181. * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
  182. * give nbuf from the pool if allocation fails
  183. * @soc: SoC handle
  184. * @mac_id: MAC ID
  185. * @rx_desc_pool: RX descriptor pool
  186. * @num_available_buffers: number of available buffers in the ring.
  187. *
  188. * Return: nbuf
  189. */
  190. static inline qdf_nbuf_t
  191. dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
  192. struct rx_desc_pool *rx_desc_pool,
  193. uint32_t num_available_buffers)
  194. {
  195. return qdf_nbuf_alloc(soc->osdev, rx_desc_pool->buf_size,
  196. RX_BUFFER_RESERVATION,
  197. rx_desc_pool->buf_alignment, FALSE);
  198. }
  199. /**
  200. * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
  201. * @soc: SoC handle
  202. * @rx_desc_pool: RX descriptor pool
  203. * @nbuf_frag_info_t: nbuf frag info
  204. *
  205. * Return: nbuf
  206. */
  207. static inline QDF_STATUS
  208. dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
  209. struct rx_desc_pool *rx_desc_pool,
  210. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  211. {
  212. return qdf_nbuf_map_nbytes_single(soc->osdev,
  213. (nbuf_frag_info_t->virt_addr).nbuf,
  214. QDF_DMA_FROM_DEVICE,
  215. rx_desc_pool->buf_size);
  216. }
  217. static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc) { }
  218. static inline void dp_rx_refill_buff_pool_lock(struct dp_soc *soc) { }
  219. static inline void dp_rx_refill_buff_pool_unlock(struct dp_soc *soc) { }
  220. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  221. #endif /* _DP_RX_BUFFER_POOL_H_ */