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