wbuff.h 4.1 KB

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