xref: /wlan-driver/qca-wifi-host-cmn/wbuff/inc/wbuff.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name /**
21*5113495bSYour Name  * DOC: wbuff.h
22*5113495bSYour Name  * wbuff buffer management APIs
23*5113495bSYour Name  */
24*5113495bSYour Name 
25*5113495bSYour Name #ifndef _WBUFF_H
26*5113495bSYour Name #define _WBUFF_H
27*5113495bSYour Name 
28*5113495bSYour Name #include <qdf_status.h>
29*5113495bSYour Name #include <qdf_nbuf.h>
30*5113495bSYour Name 
31*5113495bSYour Name /* Number of pools supported per module */
32*5113495bSYour Name #define WBUFF_MAX_POOLS 16
33*5113495bSYour Name #define WBUFF_MAX_POOL_ID WBUFF_MAX_POOLS
34*5113495bSYour Name 
35*5113495bSYour Name enum wbuff_module_id {
36*5113495bSYour Name 	WBUFF_MODULE_WMI_TX,
37*5113495bSYour Name 	WBUFF_MODULE_CE_RX,
38*5113495bSYour Name 	WBUFF_MAX_MODULES,
39*5113495bSYour Name };
40*5113495bSYour Name 
41*5113495bSYour Name /**
42*5113495bSYour Name  * struct wbuff_alloc_request - allocation structure for registering each
43*5113495bSYour Name  * pool for wbuff module.
44*5113495bSYour Name  * @pool_id: pool identifier
45*5113495bSYour Name  * @pool_size: number of buffers for @pool_id
46*5113495bSYour Name  * @buffer_size: size of each buffer in this @pool_id
47*5113495bSYour Name  */
48*5113495bSYour Name struct wbuff_alloc_request {
49*5113495bSYour Name 	uint8_t pool_id;
50*5113495bSYour Name 	uint16_t pool_size;
51*5113495bSYour Name 	uint16_t buffer_size;
52*5113495bSYour Name };
53*5113495bSYour Name 
54*5113495bSYour Name /* Opaque handle for wbuff */
55*5113495bSYour Name struct wbuff_mod_handle;
56*5113495bSYour Name 
57*5113495bSYour Name #ifdef WLAN_FEATURE_WBUFF
58*5113495bSYour Name /**
59*5113495bSYour Name  * wbuff_module_init() - Initializes the wbuff module
60*5113495bSYour Name  *
61*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS - init success
62*5113495bSYour Name  *         QDF_STATUS_E_NOSUPPORT - init failure
63*5113495bSYour Name  */
64*5113495bSYour Name QDF_STATUS wbuff_module_init(void);
65*5113495bSYour Name 
66*5113495bSYour Name /**
67*5113495bSYour Name  * wbuff_module_deinit() - De-initializes the wbuff module
68*5113495bSYour Name  *
69*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS - de-init success
70*5113495bSYour Name  *         QDF_STATUS_E_INVAL - de-init failure (wbuff not initialized)
71*5113495bSYour Name  */
72*5113495bSYour Name QDF_STATUS wbuff_module_deinit(void);
73*5113495bSYour Name 
74*5113495bSYour Name /**
75*5113495bSYour Name  * wbuff_module_register() - Registers a module with wbuff
76*5113495bSYour Name  * @req: allocation request from registered module
77*5113495bSYour Name  * @num_pools: number of pools required
78*5113495bSYour Name  * @reserve: nbuf headroom to start with
79*5113495bSYour Name  * @align: alignment for the nbuf
80*5113495bSYour Name  * @module_id: module identifier
81*5113495bSYour Name  *
82*5113495bSYour Name  * Return: Handle if registration success
83*5113495bSYour Name  *         NULL if registration failure
84*5113495bSYour Name  */
85*5113495bSYour Name struct wbuff_mod_handle *
86*5113495bSYour Name wbuff_module_register(struct wbuff_alloc_request *req, uint8_t num_pools,
87*5113495bSYour Name 		      int reserve, int align, enum wbuff_module_id module_id);
88*5113495bSYour Name 
89*5113495bSYour Name /**
90*5113495bSYour Name  * wbuff_module_deregister() - De-registers a module with wbuff
91*5113495bSYour Name  * @hdl: wbuff_handle corresponding to the module
92*5113495bSYour Name  *
93*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS - deregistration success
94*5113495bSYour Name  *         QDF_STATUS_E_INVAL - deregistration failure
95*5113495bSYour Name  */
96*5113495bSYour Name QDF_STATUS wbuff_module_deregister(struct wbuff_mod_handle *hdl);
97*5113495bSYour Name 
98*5113495bSYour Name /**
99*5113495bSYour Name  * wbuff_buff_get() - return buffer to the requester
100*5113495bSYour Name  * @hdl: wbuff_handle corresponding to the module
101*5113495bSYour Name  * @pool_id: pool identifier
102*5113495bSYour Name  * @len: length of buffer requested
103*5113495bSYour Name  * @func_name: function from which buffer is requested
104*5113495bSYour Name  * @line_num: line number in the file
105*5113495bSYour Name  *
106*5113495bSYour Name  * Return: Network buffer if success
107*5113495bSYour Name  *         NULL if failure
108*5113495bSYour Name  */
109*5113495bSYour Name qdf_nbuf_t
110*5113495bSYour Name wbuff_buff_get(struct wbuff_mod_handle *hdl, uint8_t pool_id, uint32_t len,
111*5113495bSYour Name 	       const char *func_name, uint32_t line_num);
112*5113495bSYour Name 
113*5113495bSYour Name /**
114*5113495bSYour Name  * wbuff_buff_put() - put the buffer back to wbuff pool
115*5113495bSYour Name  * @buf: pointer to network buffer
116*5113495bSYour Name  *
117*5113495bSYour Name  * Return: NULL if success (buffer consumed)
118*5113495bSYour Name  *         @buf if failure (buffer not consumed)
119*5113495bSYour Name  */
120*5113495bSYour Name qdf_nbuf_t wbuff_buff_put(qdf_nbuf_t buf);
121*5113495bSYour Name 
122*5113495bSYour Name #else
123*5113495bSYour Name 
wbuff_module_init(void)124*5113495bSYour Name static inline QDF_STATUS wbuff_module_init(void)
125*5113495bSYour Name {
126*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
127*5113495bSYour Name }
128*5113495bSYour Name 
wbuff_module_deinit(void)129*5113495bSYour Name static inline QDF_STATUS wbuff_module_deinit(void)
130*5113495bSYour Name {
131*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
132*5113495bSYour Name }
133*5113495bSYour Name 
134*5113495bSYour Name static inline struct wbuff_mod_handle *
wbuff_module_register(struct wbuff_alloc_request * req,uint8_t num_pools,int reserve,int align,enum wbuff_module_id module_id)135*5113495bSYour Name wbuff_module_register(struct wbuff_alloc_request *req, uint8_t num_pools,
136*5113495bSYour Name 		      int reserve, int align, enum wbuff_module_id module_id)
137*5113495bSYour Name {
138*5113495bSYour Name 	return NULL;
139*5113495bSYour Name }
140*5113495bSYour Name 
wbuff_module_deregister(struct wbuff_mod_handle * hdl)141*5113495bSYour Name static inline QDF_STATUS wbuff_module_deregister(struct wbuff_mod_handle *hdl)
142*5113495bSYour Name {
143*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
144*5113495bSYour Name }
145*5113495bSYour Name 
146*5113495bSYour Name static inline qdf_nbuf_t
wbuff_buff_get(struct wbuff_mod_handle * hdl,uint8_t pool_id,uint32_t len,const char * func_name,uint32_t line_num)147*5113495bSYour Name wbuff_buff_get(struct wbuff_mod_handle *hdl, uint8_t pool_id, uint32_t len,
148*5113495bSYour Name 	       const char *func_name, uint32_t line_num)
149*5113495bSYour Name {
150*5113495bSYour Name 	return NULL;
151*5113495bSYour Name }
152*5113495bSYour Name 
153*5113495bSYour Name static inline qdf_nbuf_t
wbuff_buff_put(qdf_nbuf_t buf)154*5113495bSYour Name wbuff_buff_put(qdf_nbuf_t buf)
155*5113495bSYour Name {
156*5113495bSYour Name 	return buf;
157*5113495bSYour Name }
158*5113495bSYour Name 
159*5113495bSYour Name #endif
160*5113495bSYour Name #endif /* _WBUFF_H */
161