wbuff.h 4.1 KB

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