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