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 #include <wbuff.h>
30 
31 #define WBUFF_MODULE_ID_SHIFT 4
32 #define WBUFF_MODULE_ID_BITMASK 0xF0
33 
34 #define WBUFF_POOL_ID_SHIFT 1
35 #define WBUFF_POOL_ID_BITMASK 0xE
36 
37 /**
38  * struct wbuff_handle - wbuff handle to the registered module
39  * @id: the identifier for the registered module.
40  */
41 struct wbuff_handle {
42 	uint8_t id;
43 };
44 
45 /**
46  * struct wbuff_pool - structure representing wbuff pool
47  * @initialized: To identify whether pool is initialized
48  * @pool: nbuf pool
49  * @buffer_size: size of the buffer in this @pool
50  * @pool_id: pool identifier
51  * @alloc_success: Successful allocations for this pool
52  * @alloc_fail: Failed allocations for this pool
53  * @mem_alloc: Memory allocated for this pool
54  */
55 struct wbuff_pool {
56 	bool initialized;
57 	qdf_nbuf_t pool;
58 	uint16_t buffer_size;
59 	uint8_t pool_id;
60 	uint64_t alloc_success;
61 	uint64_t alloc_fail;
62 	uint64_t mem_alloc;
63 };
64 
65 /**
66  * struct wbuff_module - allocation holder for wbuff registered module
67  * @registered: To identify whether module is registered
68  * @pending_returns: Number of buffers pending to be returned to
69  * wbuff by the module
70  * @lock: Lock for accessing per module buffer pools
71  * @handle: wbuff handle for the registered module
72  * @reserve: nbuf headroom to start with
73  * @align: alignment for the nbuf
74  * @wbuff_pool: pools for all available buffers for the module
75  */
76 struct wbuff_module {
77 	bool registered;
78 	uint16_t pending_returns;
79 	qdf_spinlock_t lock;
80 	struct wbuff_handle handle;
81 	int reserve;
82 	int align;
83 	struct wbuff_pool wbuff_pool[WBUFF_MAX_POOLS];
84 };
85 
86 /**
87  * struct wbuff_holder - allocation holder for wbuff
88  * @initialized: to identified whether module is initialized
89  * @mod: list of modules
90  * @pf_cache: Reference to page frag cache, used for nbuf allocations
91  * @wbuff_debugfs_dir: wbuff debugfs root directory
92  * @wbuff_stats_dentry: wbuff debugfs stats file
93  */
94 struct wbuff_holder {
95 	bool initialized;
96 	struct wbuff_module mod[WBUFF_MAX_MODULES];
97 	qdf_frag_cache_t pf_cache;
98 	struct dentry *wbuff_debugfs_dir;
99 	struct dentry *wbuff_stats_dentry;
100 };
101 #endif /* _WBUFF_H */
102