dp_rx_buffer_pool.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #else
  103. /**
  104. * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
  105. * @soc: SoC handle
  106. * @mac_id: MAC ID
  107. *
  108. * Return: None
  109. */
  110. static inline
  111. void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id)
  112. {
  113. soc->rx_buff_pool[mac_id].is_initialized = false;
  114. }
  115. /**
  116. * dp_rx_buffer_pool_deinit() - De-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_deinit(struct dp_soc *soc, u8 mac_id)
  124. {
  125. }
  126. /**
  127. * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
  128. * refill the emergency buffer pool
  129. * @soc: SoC handle
  130. * @nbuf: RX buffer
  131. * @mac_id: MAC ID
  132. *
  133. * Return: Whether the rx nbuf is consumed into the pool or not.
  134. */
  135. static inline
  136. bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id)
  137. {
  138. return false;
  139. }
  140. /**
  141. * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
  142. * back into the pool
  143. * @soc: SoC handle
  144. * @nbuf: RX buffer
  145. * @mac_id: MAC ID
  146. *
  147. * Return: None
  148. */
  149. static inline
  150. void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
  151. u8 mac_id)
  152. {
  153. qdf_nbuf_free(nbuf);
  154. }
  155. /**
  156. * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
  157. * give nbuf from the pool if allocation fails
  158. * @soc: SoC handle
  159. * @mac_id: MAC ID
  160. * @rx_desc_pool: RX descriptor pool
  161. * @num_available_buffers: number of available buffers in the ring.
  162. *
  163. * Return: nbuf
  164. */
  165. static inline qdf_nbuf_t
  166. dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
  167. struct rx_desc_pool *rx_desc_pool,
  168. uint32_t num_available_buffers)
  169. {
  170. return qdf_nbuf_alloc(soc->osdev, rx_desc_pool->buf_size,
  171. RX_BUFFER_RESERVATION,
  172. rx_desc_pool->buf_alignment, FALSE);
  173. }
  174. /**
  175. * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
  176. * @soc: SoC handle
  177. * @rx_desc_pool: RX descriptor pool
  178. * @nbuf_frag_info_t: nbuf frag info
  179. *
  180. * Return: nbuf
  181. */
  182. static inline QDF_STATUS
  183. dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
  184. struct rx_desc_pool *rx_desc_pool,
  185. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  186. {
  187. return qdf_nbuf_map_nbytes_single(soc->osdev,
  188. (nbuf_frag_info_t->virt_addr).nbuf,
  189. QDF_DMA_FROM_DEVICE,
  190. rx_desc_pool->buf_size);
  191. }
  192. static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc) { }
  193. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  194. #endif /* _DP_RX_BUFFER_POOL_H_ */