xref: /wlan-dirver/qca-wifi-host-cmn/wbuff/src/i_wbuff.h (revision d93db0f70eb35f5bb04948516ece4686b81fc044)
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 modules supported by wbuff */
31 #define WBUFF_MAX_MODULES 4
32 
33 /* Number of pools supported per module */
34 #define WBUFF_MAX_POOLS 4
35 
36 /* Max buffer size supported by wbuff in bytes */
37 #define WBUFF_MAX_BUFFER_SIZE 2048
38 
39 /* wbuff pool buffer lengths in bytes*/
40 #define WBUFF_LEN_POOL0 256
41 #define WBUFF_LEN_POOL1 512
42 #define WBUFF_LEN_POOL2 1024
43 #define WBUFF_LEN_POOL3 2048
44 
45 /* wbuff max pool sizes */
46 /* Allocation of size 256 bytes */
47 #define WBUFF_POOL_0_MAX 256
48 /* Allocation of size 512 bytes */
49 #define WBUFF_POOL_1_MAX 128
50 /* Allocation of size 1024 bytes */
51 #define WBUFF_POOL_2_MAX 64
52 /* Allocation of size 2048 bytes */
53 #define WBUFF_POOL_3_MAX 32
54 
55 #define WBUFF_MSLOT_SHIFT 4
56 #define WBUFF_MSLOT_BITMASK 0xF0
57 
58 #define WBUFF_PSLOT_SHIFT 1
59 #define WBUFF_PSLOT_BITMASK 0xE
60 
61 /* Comparison array for maximum allocation per pool*/
62 uint16_t wbuff_alloc_max[WBUFF_MAX_POOLS] = {WBUFF_POOL_0_MAX,
63 					     WBUFF_POOL_1_MAX,
64 					     WBUFF_POOL_2_MAX,
65 					     WBUFF_POOL_3_MAX};
66 
67 /**
68  * struct wbuff_handle - wbuff handle to the registered module
69  * @id: the identifier for the registered module.
70  */
71 struct wbuff_handle {
72 	uint8_t id;
73 };
74 
75 /**
76  * struct wbuff_module - allocation holder for wbuff registered module
77  * @registered: To identify whether module is registered
78  * @pending_returns: Number of buffers pending to be returned to
79  * wbuff by the module
80  * @lock: Lock for accessing per module buffer slots
81  * @handle: wbuff handle for the registered module
82  * @reserve: nbuf headroom to start with
83  * @align: alignment for the nbuf
84  * @pool: pools for all available buffers for the module
85  */
86 struct wbuff_module {
87 	bool registered;
88 	uint16_t pending_returns;
89 	qdf_spinlock_t lock;
90 	struct wbuff_handle handle;
91 	int reserve;
92 	int align;
93 	qdf_nbuf_t pool[WBUFF_MAX_POOLS];
94 };
95 
96 /**
97  * struct wbuff_holder - allocation holder for wbuff
98  * @initialized: to identified whether module is initialized
99  * @mod: list of modules
100  */
101 struct wbuff_holder {
102 	bool initialized;
103 	struct wbuff_module mod[WBUFF_MAX_MODULES];
104 };
105 #endif /* _WBUFF_H */
106