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