xref: /wlan-dirver/qca-wifi-host-cmn/wbuff/inc/wbuff.h (revision 1397a33f48ea6455be40871470b286e535820eb8)
1 /*
2  * Copyright (c) 2018-2019 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  * @func_name: function from which buffer is requested
99  * @line_num: line number in the file
100  *
101  * Return: Network buffer if success
102  *         NULL if failure
103  */
104 qdf_nbuf_t wbuff_buff_get(struct wbuff_mod_handle *hdl, uint32_t len,
105 			  const char *func_name, uint32_t line_num);
106 
107 /**
108  * wbuff_buff_put() - put the buffer back to wbuff pool
109  * @hdl: wbuff_handle corresponding to the module
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