wbuff.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 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. /**
  20. * DOC: wbuff.h
  21. * wbuff buffer management APIs
  22. */
  23. #ifndef _WBUFF_H
  24. #define _WBUFF_H
  25. #include <qdf_status.h>
  26. #include <qdf_nbuf.h>
  27. /* Number of pools supported per module */
  28. #define WBUFF_MAX_POOLS 16
  29. #define WBUFF_MAX_POOL_ID WBUFF_MAX_POOLS
  30. enum wbuff_module_id {
  31. WBUFF_MODULE_WMI_TX,
  32. WBUFF_MODULE_CE_RX,
  33. WBUFF_MAX_MODULES,
  34. };
  35. /**
  36. * struct wbuff_alloc_request - allocation structure for registering each
  37. * pool for wbuff module.
  38. * @pool_id: pool identifier
  39. * @pool_size: number of buffers for @pool_id
  40. * @buffer_size: size of each buffer in this @pool_id
  41. */
  42. struct wbuff_alloc_request {
  43. uint8_t pool_id;
  44. uint16_t pool_size;
  45. uint16_t buffer_size;
  46. };
  47. /* Opaque handle for wbuff */
  48. struct wbuff_mod_handle;
  49. #ifdef WLAN_FEATURE_WBUFF
  50. /**
  51. * wbuff_module_init() - Initializes the wbuff module
  52. *
  53. * Return: QDF_STATUS_SUCCESS - init success
  54. * QDF_STATUS_E_NOSUPPORT - init failure
  55. */
  56. QDF_STATUS wbuff_module_init(void);
  57. /**
  58. * wbuff_module_deinit() - De-initializes the wbuff module
  59. *
  60. * Return: QDF_STATUS_SUCCESS - de-init success
  61. * QDF_STATUS_E_INVAL - de-init failure (wbuff not initialized)
  62. */
  63. QDF_STATUS wbuff_module_deinit(void);
  64. /**
  65. * wbuff_module_register() - Registers a module with wbuff
  66. * @req: allocation request from registered module
  67. * @num_pools: number of pools required
  68. * @reserve: nbuf headroom to start with
  69. * @align: alignment for the nbuf
  70. * @module_id: module identifier
  71. *
  72. * Return: Handle if registration success
  73. * NULL if registration failure
  74. */
  75. struct wbuff_mod_handle *
  76. wbuff_module_register(struct wbuff_alloc_request *req, uint8_t num_pools,
  77. int reserve, int align, enum wbuff_module_id module_id);
  78. /**
  79. * wbuff_module_deregister() - De-registers a module with wbuff
  80. * @hdl: wbuff_handle corresponding to the module
  81. *
  82. * Return: QDF_STATUS_SUCCESS - deregistration success
  83. * QDF_STATUS_E_INVAL - deregistration failure
  84. */
  85. QDF_STATUS wbuff_module_deregister(struct wbuff_mod_handle *hdl);
  86. /**
  87. * wbuff_buff_get() - return buffer to the requester
  88. * @hdl: wbuff_handle corresponding to the module
  89. * @pool_id: pool identifier
  90. * @len: length of buffer requested
  91. * @func_name: function from which buffer is requested
  92. * @line_num: line number in the file
  93. *
  94. * Return: Network buffer if success
  95. * NULL if failure
  96. */
  97. qdf_nbuf_t
  98. wbuff_buff_get(struct wbuff_mod_handle *hdl, uint8_t pool_id, uint32_t len,
  99. const char *func_name, uint32_t line_num);
  100. /**
  101. * wbuff_buff_put() - put the buffer back to wbuff pool
  102. * @buf: pointer to network buffer
  103. *
  104. * Return: NULL if success (buffer consumed)
  105. * @buf if failure (buffer not consumed)
  106. */
  107. qdf_nbuf_t wbuff_buff_put(qdf_nbuf_t buf);
  108. #else
  109. static inline QDF_STATUS wbuff_module_init(void)
  110. {
  111. return QDF_STATUS_E_NOSUPPORT;
  112. }
  113. static inline QDF_STATUS wbuff_module_deinit(void)
  114. {
  115. return QDF_STATUS_E_NOSUPPORT;
  116. }
  117. static inline struct wbuff_mod_handle *
  118. wbuff_module_register(struct wbuff_alloc_request *req, uint8_t num_pools,
  119. int reserve, int align, enum wbuff_module_id module_id)
  120. {
  121. return NULL;
  122. }
  123. static inline QDF_STATUS wbuff_module_deregister(struct wbuff_mod_handle *hdl)
  124. {
  125. return QDF_STATUS_E_NOSUPPORT;
  126. }
  127. static inline qdf_nbuf_t
  128. wbuff_buff_get(struct wbuff_mod_handle *hdl, uint8_t pool_id, uint32_t len,
  129. const char *func_name, uint32_t line_num)
  130. {
  131. return NULL;
  132. }
  133. static inline qdf_nbuf_t
  134. wbuff_buff_put(qdf_nbuf_t buf)
  135. {
  136. return buf;
  137. }
  138. #endif
  139. #endif /* _WBUFF_H */