xref: /wlan-dirver/qca-wifi-host-cmn/wbuff/src/i_wbuff.h (revision 9b27c6e104d726e99b1515faf0f55e5a36178530)
1 /*
2  * Copyright (c) 2018 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: i_wbuff.h
22  * wbuff private
23  */
24 
25 #ifndef _I_WBUFF_H
26 #define _I_WBUFF_H
27 
28 #include <qdf_nbuf.h>
29 
30 /* Number of pools supported per module */
31 #define WBUFF_MAX_POOLS 4
32 
33 #define WBUFF_MODULE_ID_SHIFT 4
34 #define WBUFF_MODULE_ID_BITMASK 0xF0
35 
36 #define WBUFF_POOL_ID_SHIFT 1
37 #define WBUFF_POOL_ID_BITMASK 0xE
38 
39 /**
40  * struct wbuff_handle - wbuff handle to the registered module
41  * @id: the identifier for the registered module.
42  */
43 struct wbuff_handle {
44 	uint8_t id;
45 };
46 
47 /**
48  * struct wbuff_pool - structure representing wbuff pool
49  * @initialized: To identify whether pool is initialized
50  * @pool: nbuf pool
51  * @buffer_size: size of the buffer in this @pool
52  * @pool_id: pool identifier
53  */
54 struct wbuff_pool {
55 	bool initialized;
56 	qdf_nbuf_t pool;
57 	uint16_t buffer_size;
58 	uint8_t pool_id;
59 };
60 
61 /**
62  * struct wbuff_module - allocation holder for wbuff registered module
63  * @registered: To identify whether module is registered
64  * @pending_returns: Number of buffers pending to be returned to
65  * wbuff by the module
66  * @lock: Lock for accessing per module buffer pools
67  * @handle: wbuff handle for the registered module
68  * @reserve: nbuf headroom to start with
69  * @align: alignment for the nbuf
70  * @wbuff_pool: pools for all available buffers for the module
71  */
72 struct wbuff_module {
73 	bool registered;
74 	uint16_t pending_returns;
75 	qdf_spinlock_t lock;
76 	struct wbuff_handle handle;
77 	int reserve;
78 	int align;
79 	struct wbuff_pool wbuff_pool[WBUFF_MAX_POOLS];
80 };
81 
82 /**
83  * struct wbuff_holder - allocation holder for wbuff
84  * @initialized: to identified whether module is initialized
85  * @mod: list of modules
86  */
87 struct wbuff_holder {
88 	bool initialized;
89 	struct wbuff_module mod[WBUFF_MAX_MODULES];
90 };
91 #endif /* _WBUFF_H */
92