wbuff.h 3.8 KB

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