xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/osl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * OS Abstraction Layer
3  *
4  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, Broadcom Corporation
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *      Notwithstanding the above, under no circumstances may you combine this
23  * software in any way with any other Broadcom software provided under a license
24  * other than the GPL, without Broadcom's express prior written consent.
25  *
26  *
27  * <<Broadcom-WL-IPTag/Open:>>
28  *
29  * $Id: osl.h 673906 2016-12-05 19:59:39Z $
30  */
31 
32 #ifndef _osl_h_
33 #define _osl_h_
34 
35 #include <osl_decl.h>
36 
37 enum {
38 	TAIL_BYTES_TYPE_FCS = 1,
39 	TAIL_BYTES_TYPE_ICV = 2,
40 	TAIL_BYTES_TYPE_MIC = 3
41 };
42 
43 #define OSL_PKTTAG_SZ   48 /* standard linux pkttag size is 48 bytes */
44 
45 /* Drivers use PKTFREESETCB to register a callback function when a packet is freed by OSL */
46 typedef void (*pktfree_cb_fn_t)(void *ctx, void *pkt, unsigned int status);
47 
48 /* Drivers use REGOPSSET() to register register read/write funcitons */
49 typedef unsigned int (*osl_rreg_fn_t)(void *ctx, volatile void *reg, unsigned int size);
50 typedef void  (*osl_wreg_fn_t)(void *ctx, volatile void *reg, unsigned int val, unsigned int size);
51 
52 #if defined(WL_UNITTEST)
53 #include <utest_osl.h>
54 #else
55 #include <linux_osl.h>
56 #include <linux_pkt.h>
57 #endif // endif
58 
59 #ifndef PKTDBG_TRACE
60 #define PKTDBG_TRACE(osh, pkt, bit)	BCM_REFERENCE(osh)
61 #endif // endif
62 
63 #define PKTCTFMAP(osh, p)		BCM_REFERENCE(osh)
64 
65 /* --------------------------------------------------------------------------
66 ** Register manipulation macros.
67 */
68 
69 #define	SET_REG(osh, r, mask, val)	W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
70 
71 #ifndef AND_REG
72 #define AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
73 #endif   /* !AND_REG */
74 
75 #ifndef OR_REG
76 #define OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
77 #endif   /* !OR_REG */
78 
79 #if !defined(OSL_SYSUPTIME)
80 #define OSL_SYSUPTIME() (0)
81 #define OSL_SYSUPTIME_NOT_DEFINED 1
82 #endif /* !defined(OSL_SYSUPTIME) */
83 
84 #if !defined(OSL_SYSUPTIME_US)
85 #define OSL_SYSUPTIME_US() (0)
86 #define OSL_SYSUPTIME_US_NOT_DEFINED 1
87 #endif /* !defined(OSL_SYSUPTIME) */
88 
89 #if defined(OSL_SYSUPTIME_NOT_DEFINED) && defined(OSL_SYSUPTIME_US_NOT_DEFINED)
90 #define OSL_SYSUPTIME_SUPPORT FALSE
91 #else
92 #define OSL_SYSUPTIME_SUPPORT TRUE
93 #endif /* OSL_SYSUPTIME */
94 
95 #ifndef OSL_GET_LOCALTIME
96 #define OSL_GET_LOCALTIME(sec, usec)	\
97 	do { \
98 		BCM_REFERENCE(sec); \
99 		BCM_REFERENCE(usec); \
100 	} while (0)
101 #endif /* OSL_GET_LOCALTIME */
102 
103 #ifndef OSL_LOCALTIME_NS
104 #define OSL_LOCALTIME_NS()	(OSL_SYSUPTIME_US() * NSEC_PER_USEC)
105 #endif /* OSL_LOCALTIME_NS */
106 
107 #ifndef OSL_SYSTZTIME_US
108 #define OSL_SYSTZTIME_US()	OSL_SYSUPTIME_US()
109 #endif /* OSL_GET_SYSTZTIME */
110 
111 #ifndef OSL_SYS_HALT
112 #define OSL_SYS_HALT()	do {} while (0)
113 #endif // endif
114 
115 #ifndef DMB
116 #if defined(STB)
117 #define DMB()	mb();
118 #else /* STB */
119 #define DMB()	do {} while (0)
120 #endif /* STB */
121 #endif /* DMB */
122 
123 #ifndef OSL_MEM_AVAIL
124 #define OSL_MEM_AVAIL()	(0xffffffff)
125 #endif // endif
126 
127 #ifndef OSL_OBFUSCATE_BUF
128 /* For security reasons printing pointers is not allowed.
129  * Some OSLs implement OSL_OBFUSCATE_BUF to OS specific obfuscate API.
130  * If OSL_OBFUSCATE_BUF() is not implemented in OSL, then default to
131  * printing the input pointer
132  */
133 #define OSL_OBFUSCATE_BUF(x) (x)
134 #endif /* OSL_OBFUSCATE_BUF */
135 
136 #if !defined(PKTC_DONGLE)
137 
138 #define	PKTCGETATTR(skb)	(0)
139 #define	PKTCSETATTR(skb, f, p, b) BCM_REFERENCE(skb)
140 #define	PKTCCLRATTR(skb)	BCM_REFERENCE(skb)
141 #define	PKTCCNT(skb)		(1)
142 #define	PKTCLEN(skb)		PKTLEN(NULL, skb)
143 #define	PKTCGETFLAGS(skb)	(0)
144 #define	PKTCSETFLAGS(skb, f)	BCM_REFERENCE(skb)
145 #define	PKTCCLRFLAGS(skb)	BCM_REFERENCE(skb)
146 #define	PKTCFLAGS(skb)		(0)
147 #define	PKTCSETCNT(skb, c)	BCM_REFERENCE(skb)
148 #define	PKTCINCRCNT(skb)	BCM_REFERENCE(skb)
149 #define	PKTCADDCNT(skb, c)	BCM_REFERENCE(skb)
150 #define	PKTCSETLEN(skb, l)	BCM_REFERENCE(skb)
151 #define	PKTCADDLEN(skb, l)	BCM_REFERENCE(skb)
152 #define	PKTCSETFLAG(skb, fb)	BCM_REFERENCE(skb)
153 #define	PKTCCLRFLAG(skb, fb)	BCM_REFERENCE(skb)
154 #define	PKTCLINK(skb)		NULL
155 #define	PKTSETCLINK(skb, x)	BCM_REFERENCE(skb)
156 #define FOREACH_CHAINED_PKT(skb, nskb) \
157 	for ((nskb) = NULL; (skb) != NULL; (skb) = (nskb))
158 #define	PKTCFREE		PKTFREE
159 #define PKTCENQTAIL(h, t, p) \
160 do { \
161 	if ((t) == NULL) { \
162 		(h) = (t) = (p); \
163 	} \
164 } while (0)
165 #endif // endif
166 
167 #ifndef PKTSETCHAINED
168 #define PKTSETCHAINED(osh, skb)		BCM_REFERENCE(osh)
169 #endif // endif
170 #ifndef PKTCLRCHAINED
171 #define PKTCLRCHAINED(osh, skb)		BCM_REFERENCE(osh)
172 #endif // endif
173 #ifndef PKTISCHAINED
174 #define PKTISCHAINED(skb)		FALSE
175 #endif // endif
176 
177 /* Lbuf with fraglist */
178 #ifndef PKTFRAGPKTID
179 #define PKTFRAGPKTID(osh, lb)		(0)
180 #endif // endif
181 #ifndef PKTSETFRAGPKTID
182 #define PKTSETFRAGPKTID(osh, lb, id)	BCM_REFERENCE(osh)
183 #endif // endif
184 #ifndef PKTFRAGTOTNUM
185 #define PKTFRAGTOTNUM(osh, lb)		(0)
186 #endif // endif
187 #ifndef PKTSETFRAGTOTNUM
188 #define PKTSETFRAGTOTNUM(osh, lb, tot)	BCM_REFERENCE(osh)
189 #endif // endif
190 #ifndef PKTFRAGTOTLEN
191 #define PKTFRAGTOTLEN(osh, lb)		(0)
192 #endif // endif
193 #ifndef PKTSETFRAGTOTLEN
194 #define PKTSETFRAGTOTLEN(osh, lb, len)	BCM_REFERENCE(osh)
195 #endif // endif
196 #ifndef PKTIFINDEX
197 #define PKTIFINDEX(osh, lb)		(0)
198 #endif // endif
199 #ifndef PKTSETIFINDEX
200 #define PKTSETIFINDEX(osh, lb, idx)	BCM_REFERENCE(osh)
201 #endif // endif
202 #ifndef PKTGETLF
203 #define	PKTGETLF(osh, len, send, lbuf_type)	(0)
204 #endif // endif
205 
206 /* in rx path, reuse totlen as used len */
207 #ifndef PKTFRAGUSEDLEN
208 #define PKTFRAGUSEDLEN(osh, lb)			(0)
209 #endif // endif
210 #ifndef PKTSETFRAGUSEDLEN
211 #define PKTSETFRAGUSEDLEN(osh, lb, len)		BCM_REFERENCE(osh)
212 #endif // endif
213 #ifndef PKTFRAGLEN
214 #define PKTFRAGLEN(osh, lb, ix)			(0)
215 #endif // endif
216 #ifndef PKTSETFRAGLEN
217 #define PKTSETFRAGLEN(osh, lb, ix, len)		BCM_REFERENCE(osh)
218 #endif // endif
219 #ifndef PKTFRAGDATA_LO
220 #define PKTFRAGDATA_LO(osh, lb, ix)		(0)
221 #endif // endif
222 #ifndef PKTSETFRAGDATA_LO
223 #define PKTSETFRAGDATA_LO(osh, lb, ix, addr)	BCM_REFERENCE(osh)
224 #endif // endif
225 #ifndef PKTFRAGDATA_HI
226 #define PKTFRAGDATA_HI(osh, lb, ix)		(0)
227 #endif // endif
228 #ifndef PKTSETFRAGDATA_HI
229 #define PKTSETFRAGDATA_HI(osh, lb, ix, addr)	BCM_REFERENCE(osh)
230 #endif // endif
231 
232 /* RX FRAG */
233 #ifndef PKTISRXFRAG
234 #define PKTISRXFRAG(osh, lb)    	(0)
235 #endif // endif
236 #ifndef PKTSETRXFRAG
237 #define PKTSETRXFRAG(osh, lb)		BCM_REFERENCE(osh)
238 #endif // endif
239 #ifndef PKTRESETRXFRAG
240 #define PKTRESETRXFRAG(osh, lb)		BCM_REFERENCE(osh)
241 #endif // endif
242 
243 /* TX FRAG */
244 #ifndef PKTISTXFRAG
245 #define PKTISTXFRAG(osh, lb)		(0)
246 #endif // endif
247 #ifndef PKTSETTXFRAG
248 #define PKTSETTXFRAG(osh, lb)		BCM_REFERENCE(osh)
249 #endif // endif
250 
251 /* Need Rx completion used for AMPDU reordering */
252 #ifndef PKTNEEDRXCPL
253 #define PKTNEEDRXCPL(osh, lb)           (TRUE)
254 #endif // endif
255 #ifndef PKTSETNORXCPL
256 #define PKTSETNORXCPL(osh, lb)          BCM_REFERENCE(osh)
257 #endif // endif
258 #ifndef PKTRESETNORXCPL
259 #define PKTRESETNORXCPL(osh, lb)        BCM_REFERENCE(osh)
260 #endif // endif
261 #ifndef PKTISFRAG
262 #define PKTISFRAG(osh, lb)		(0)
263 #endif // endif
264 #ifndef PKTFRAGISCHAINED
265 #define PKTFRAGISCHAINED(osh, i)	(0)
266 #endif // endif
267 /* TRIM Tail bytes from lfrag */
268 #ifndef PKTFRAG_TRIM_TAILBYTES
269 #define PKTFRAG_TRIM_TAILBYTES(osh, p, len, type)	PKTSETLEN(osh, p, PKTLEN(osh, p) - len)
270 #endif // endif
271 #ifndef PKTISHDRCONVTD
272 #define PKTISHDRCONVTD(osh, lb)		(0)
273 #endif // endif
274 
275 /* Forwarded pkt indication */
276 #ifndef PKTISFRWDPKT
277 #define PKTISFRWDPKT(osh, lb)		0
278 #endif // endif
279 #ifndef PKTSETFRWDPKT
280 #define PKTSETFRWDPKT(osh, lb)		BCM_REFERENCE(osh)
281 #endif // endif
282 #ifndef PKTRESETFRWDPKT
283 #define PKTRESETFRWDPKT(osh, lb)	BCM_REFERENCE(osh)
284 #endif // endif
285 
286 /* SFD Frame */
287 #ifndef PKTISSFDFRAME
288 #define PKTISSFDFRAME(osh, lb)		(0)
289 #endif // endif
290 #ifndef PKTSETSFDFRAME
291 #define PKTSETSFDFRAME(osh, lb)		BCM_REFERENCE(osh)
292 #endif // endif
293 #ifndef PKTRESETSFDFRAME
294 #define PKTRESETSFDFRAME(osh, lb)	BCM_REFERENCE(osh)
295 #endif // endif
296 #ifndef PKTISSFDTXC
297 #define PKTISSFDTXC(osh, lb)		(0)
298 #endif // endif
299 #ifndef PKTSETSFDTXC
300 #define PKTSETSFDTXC(osh, lb)		BCM_REFERENCE(osh)
301 #endif // endif
302 #ifndef PKTRESETSFDTXC
303 #define PKTRESETSFDTXC(osh, lb)		BCM_REFERENCE(osh)
304 #endif // endif
305 
306 #ifdef BCM_SECURE_DMA
307 #define SECURE_DMA_ENAB(osh) (1)
308 #else
309 
310 #define SECURE_DMA_ENAB(osh) (0)
311 #ifndef BCMDMA64OSL
312 #define	SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) ((dmaaddr_t) ((0)))
313 #else
314 #define	SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) \
315 	((dmaaddr_t) {.hiaddr = 0, .loaddr = 0})
316 #endif // endif
317 #define	SECURE_DMA_DD_MAP(osh, va, size, direction, p, dmah) 0
318 #ifndef BCMDMA64OSL
319 #define	SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) ((dmaaddr_t) ((0)))
320 #else
321 #define	SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) \
322 	((dmaaddr_t) {.hiaddr = 0, .loaddr = 0})
323 #endif // endif
324 #define	SECURE_DMA_UNMAP(osh, pa, size, direction, p, dmah, pcma, offset)
325 #define	SECURE_DMA_UNMAP_ALL(osh, pcma)
326 
327 #endif /* BCMDMA64OSL */
328 
329 #ifndef ROMMABLE_ASSERT
330 #define ROMMABLE_ASSERT(exp) ASSERT(exp)
331 #endif /* ROMMABLE_ASSERT */
332 
333 #ifndef MALLOC_NOPERSIST
334 	#define MALLOC_NOPERSIST MALLOC
335 #endif /* !MALLOC_NOPERSIST */
336 
337 #ifndef MALLOC_PERSIST
338 	#define MALLOC_PERSIST MALLOC
339 #endif /* !MALLOC_PERSIST */
340 
341 #ifndef MALLOC_NOPERSIST
342 	#define MALLOC_NOPERSIST MALLOC
343 #endif /* !MALLOC_NOPERSIST */
344 
345 #ifndef MALLOC_PERSIST_ATTACH
346 	#define MALLOC_PERSIST_ATTACH MALLOC
347 #endif /* !MALLOC_PERSIST_ATTACH */
348 
349 #ifndef MALLOCZ_PERSIST_ATTACH
350 	#define MALLOCZ_PERSIST_ATTACH MALLOCZ
351 #endif /* !MALLOCZ_PERSIST_ATTACH */
352 
353 #ifndef MALLOCZ_NOPERSIST
354 	#define MALLOCZ_NOPERSIST MALLOCZ
355 #endif /* !MALLOCZ_NOPERSIST */
356 
357 #ifndef MALLOCZ_PERSIST
358 	#define MALLOCZ_PERSIST MALLOCZ
359 #endif /* !MALLOCZ_PERSIST */
360 
361 #ifndef MFREE_PERSIST
362 	#define MFREE_PERSIST MFREE
363 #endif /* !MFREE_PERSIST */
364 
365 #ifndef MALLOC_SET_NOPERSIST
366 	#define MALLOC_SET_NOPERSIST(osh)	do { } while (0)
367 #endif /* !MALLOC_SET_NOPERSIST */
368 
369 #ifndef MALLOC_CLEAR_NOPERSIST
370 	#define MALLOC_CLEAR_NOPERSIST(osh)	do { } while (0)
371 #endif /* !MALLOC_CLEAR_NOPERSIST */
372 
373 #if defined(OSL_MEMCHECK)
374 #define MEMCHECK(f, l)	osl_memcheck(f, l)
375 #else
376 #define MEMCHECK(f, l)
377 #endif /* OSL_MEMCHECK */
378 
379 #endif	/* _osl_h_ */
380