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