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