xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_nbuf_frag.h (revision ec13c2ea397bc11464d596ff86f4da9fdc154da8)
1 /*
2  * Copyright (c) 2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 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: qdf_nbuf_frag.h
22  * This file defines the nbuf frag abstraction.
23  */
24 
25 #ifndef _QDF_NBUF_FRAG_H
26 #define _QDF_NBUF_FRAG_H
27 
28 #include <qdf_util.h>
29 #include <i_qdf_trace.h>
30 #include <i_qdf_nbuf_frag.h>
31 
32 /*
33  * typedef qdf_frag_cache_t - Platform independent
34  * frag cache abstraction
35  */
36 typedef __qdf_frag_cache_t qdf_frag_cache_t;
37 
38 /*
39  * typedef qdf_frag_t - Platform independent frag address abstraction
40  */
41 typedef __qdf_frag_t qdf_frag_t;
42 
43 /**
44  * Maximum number of frags an SKB can hold
45  */
46 #define QDF_NBUF_MAX_FRAGS __QDF_NBUF_MAX_FRAGS
47 
48 #ifdef NBUF_FRAG_MEMORY_DEBUG
49 /**
50  * qdf_frag_debug_init() - Initialize frag debug tracker
51  *
52  * Return: none
53  */
54 void qdf_frag_debug_init(void);
55 
56 /**
57  * qdf_frag_debug_exit() - Destroy frag debug tracker
58  *
59  * Return: none
60  */
61 void qdf_frag_debug_exit(void);
62 
63 /**
64  * qdf_frag_debug_add_node() - Add frag node in the debug hash table
65  * @fragp: Pointer to frag
66  * @func_name: Caller function name
67  * @line_num: Caller function line no.
68  *
69  * Return: none
70  */
71 void qdf_frag_debug_add_node(qdf_frag_t fragp, const char *func_name,
72 			     uint32_t line_num);
73 
74 /**
75  * qdf_frag_debug_refcount_inc() - Increment refcount for frag node
76  * @fragp: Pointer to frag
77  * @func_name: Caller function name
78  * @line_num: Caller function line no.
79  *
80  * Return: none
81  */
82 void qdf_frag_debug_refcount_inc(qdf_frag_t fragp, const char *func_name,
83 				 uint32_t line_num);
84 
85 /**
86  * qdf_frag_debug_refcount_dec() - Decrement refcount for frag node
87  * @fragp: Pointer to frag
88  * @func_name: Caller function name
89  * @line_num: Caller function line no.
90  *
91  * Return: none
92  */
93 void qdf_frag_debug_refcount_dec(qdf_frag_t fragp, const char *func_name,
94 				 uint32_t line_num);
95 
96 /**
97  * qdf_frag_debug_delete_node() - Remove frag node from debug hash table
98  * @fragp: Pointer to frag
99  * @func_name: Caller function name
100  * @line_num: Caller function line no.
101  *
102  * Return: none
103  */
104 void qdf_frag_debug_delete_node(qdf_frag_t fragp, const char *func_name,
105 				uint32_t line_num);
106 
107 /**
108  * qdf_frag_debug_update_addr() - Update frag address in debug tracker
109  * @p_fragp: Previous frag address
110  * @n_fragp: New frag address
111  * @func_name: Caller function name
112  * @line_num: Caller function line no.
113  *
114  * Return: none
115  */
116 void qdf_frag_debug_update_addr(qdf_frag_t p_fragp, qdf_frag_t n_fragp,
117 				const char *func_name, uint32_t line_num);
118 
119 #define qdf_frag_alloc(p, s) \
120 	qdf_frag_alloc_debug(p, s, __func__, __LINE__)
121 
122 /**
123  * qdf_frag_alloc_debug() - Allocate frag memory
124  * @pf_cache: page frag cache
125  * @fragsz: Size of frag memory to be allocated
126  * @func_name: Caller function name
127  * @line_num: Caller function line no.
128  *
129  * Return: Allocated frag address
130  */
131 qdf_frag_t qdf_frag_alloc_debug(qdf_frag_cache_t *pf_cache,
132 				unsigned int fragsz,
133 				const char *func_name,
134 				uint32_t line_num);
135 
136 #define qdf_frag_free(p) \
137 	qdf_frag_free_debug(p, __func__, __LINE__)
138 
139 /**
140  * qdf_frag_free_debug() - Free allocated frag memory
141  * @vaddr: Frag address to be freed
142  * @func_name: Caller function name
143  * @line_num: Caller function line no.
144  *
145  * Return: none
146  */
147 void qdf_frag_free_debug(qdf_frag_t vaddr, const char *func_name,
148 			 uint32_t line_num);
149 
150 #else /* NBUF_FRAG_MEMORY_DEBUG */
151 
152 static inline void qdf_frag_debug_init(void)
153 {
154 }
155 
156 static inline void qdf_frag_debug_exit(void)
157 {
158 }
159 
160 static inline void qdf_frag_debug_add_node(qdf_frag_t fragp,
161 					   const char *func_name,
162 					   uint32_t line_num)
163 {
164 }
165 
166 static inline void qdf_frag_debug_refcount_inc(qdf_frag_t fragp,
167 					       const char *func_name,
168 					       uint32_t line_num)
169 {
170 }
171 
172 static inline void qdf_frag_debug_refcount_dec(qdf_frag_t fragp,
173 					       const char *func_name,
174 					       uint32_t line_num)
175 {
176 }
177 
178 static inline void qdf_frag_debug_delete_node(qdf_frag_t fragp,
179 					      const char *func_name,
180 					      uint32_t line_num)
181 {
182 }
183 
184 static inline void qdf_frag_debug_update_addr(qdf_frag_t p_fragp,
185 					      qdf_frag_t n_fragp,
186 					      const char *func_name,
187 					      uint32_t line_num)
188 {
189 }
190 
191 /**
192  * qdf_frag_alloc() - Allocate frag memory
193  * @pf_cache: page frag cache
194  * @fragsz: Size of frag memory to be allocated
195  *
196  * Return: Allocated frag address
197  */
198 static inline qdf_frag_t qdf_frag_alloc(qdf_frag_cache_t *pf_cache,
199 					unsigned int fragsz)
200 {
201 	return __qdf_frag_alloc(pf_cache, fragsz);
202 }
203 
204 /**
205  * qdf_frag_free() - Free allocated frag memory
206  * @vaddr: Frag address to be freed
207  *
208  * Return: none
209  */
210 static inline void qdf_frag_free(qdf_frag_t vaddr)
211 {
212 	__qdf_frag_free(vaddr);
213 }
214 
215 #endif /* NBUF_FRAG_MEMORY_DEBUG */
216 
217 /**
218  * qdf_frag_count_get() - Get global frag gauge
219  *
220  * Return: Global frag gauge
221  */
222 static inline uint32_t qdf_frag_count_get(void)
223 {
224 	return __qdf_frag_count_get();
225 }
226 
227 /**
228  * qdf_frag_count_inc() - Increment global frag count
229  * @value: Increment value
230  *
231  * Return: none
232  */
233 static inline void qdf_frag_count_inc(uint32_t value)
234 {
235 	return __qdf_frag_count_inc(value);
236 }
237 
238 /**
239  * qdf_frag_count_dec() - Decrement global frag count
240  * @value: Decrement value
241  *
242  * Return: none
243  */
244 static inline void qdf_frag_count_dec(uint32_t value)
245 {
246 	return __qdf_frag_count_dec(value);
247 }
248 
249 /**
250  * qdf_frag_mod_init() - Initialization routine for qdf_frag
251  *
252  * Return: none
253  */
254 static inline void qdf_frag_mod_init(void)
255 {
256 	return __qdf_frag_mod_init();
257 }
258 
259 /**
260  * qdf_frag_mod_exit() - Unintialization routine for qdf_frag
261  *
262  * Return: none
263  */
264 static inline void qdf_frag_mod_exit(void)
265 {
266 	return __qdf_frag_mod_exit();
267 }
268 
269 /**
270  * qdf_mem_map_page() - Map Page
271  * @osdev: qdf_device_t
272  * @buf: Virtual page address to be mapped
273  * @dir: qdf_dma_dir_t
274  * @nbytes: Size of memory to be mapped
275  * @paddr: Corresponding mapped physical address
276  *
277  * Return: QDF_STATUS
278  */
279 static inline QDF_STATUS qdf_mem_map_page(qdf_device_t osdev, qdf_frag_t buf,
280 					  qdf_dma_dir_t dir, size_t nbytes,
281 					  qdf_dma_addr_t *phy_addr)
282 {
283 	return __qdf_mem_map_page(osdev, buf, dir, nbytes, phy_addr);
284 }
285 
286 /**
287  * qdf_mem_unmap_page() - Unmap Page
288  * @osdev: qdf_device_t
289  * @paddr: Physical memory to be unmapped
290  * @nbytes: Size of memory to be unmapped
291  * @dir: qdf_dma_dir_t
292  */
293 static inline void qdf_mem_unmap_page(qdf_device_t osdev, qdf_dma_addr_t paddr,
294 				      size_t nbytes, qdf_dma_dir_t dir)
295 {
296 	__qdf_mem_unmap_page(osdev, paddr, nbytes, dir);
297 }
298 
299 /*
300  * qdf_frag_cache_drain() - Drain page frag cache
301  *
302  * @pf_cache: page frag cache
303  *
304  * Return: void
305  */
306 static inline void qdf_frag_cache_drain(qdf_frag_cache_t *pf_cache)
307 {
308 	__qdf_frag_cache_drain(pf_cache);
309 }
310 #endif /* _QDF_NBUF_FRAG_H */
311