xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/include/osl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * OS Abstraction Layer
3  *
4  * Copyright (C) 2020, Broadcom.
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *
21  * <<Broadcom-WL-IPTag/Dual:>>
22  */
23 
24 #ifndef _osl_h_
25 #define _osl_h_
26 
27 #include <osl_decl.h>
28 
29 enum {
30 	TAIL_BYTES_TYPE_FCS = 1,
31 	TAIL_BYTES_TYPE_ICV = 2,
32 	TAIL_BYTES_TYPE_MIC = 3
33 };
34 
35 #ifdef DHD_EFI
36 #define OSL_PKTTAG_SZ	40 /* Size of PktTag */
37 #elif defined(MACOSX)
38 #define OSL_PKTTAG_SZ	56
39 #elif defined(__linux__)
40 #define OSL_PKTTAG_SZ   48 /* standard linux pkttag size is 48 bytes */
41 #else
42 #ifndef OSL_PKTTAG_SZ
43 #define OSL_PKTTAG_SZ	32 /* Size of PktTag */
44 #endif /* !OSL_PKTTAG_SZ */
45 #endif /* DHD_EFI */
46 
47 /* Drivers use PKTFREESETCB to register a callback function when a packet is freed by OSL */
48 typedef void (*pktfree_cb_fn_t)(void *ctx, void *pkt, unsigned int status);
49 
50 /* Drivers use REGOPSSET() to register register read/write funcitons */
51 typedef unsigned int (*osl_rreg_fn_t)(void *ctx, volatile void *reg, unsigned int size);
52 typedef void  (*osl_wreg_fn_t)(void *ctx, volatile void *reg, unsigned int val, unsigned int size);
53 
54 #if defined(EFI)
55 #include <efi_osl.h>
56 #elif defined(WL_UNITTEST)
57 #include <utest_osl.h>
58 #elif defined(__linux__)
59 #include <linux_osl.h>
60 #include <linux_pkt.h>
61 #elif defined(NDIS)
62 #include <ndis_osl.h>
63 #elif defined(_RTE_)
64 #include <rte_osl.h>
65 #include <hnd_pkt.h>
66 #elif defined(MACOSX)
67 #include <macosx_osl.h>
68 #else
69 #error "Unsupported OSL requested"
70 #endif /* defined(DOS) */
71 
72 #ifndef PKTDBG_TRACE
73 #define PKTDBG_TRACE(osh, pkt, bit)	BCM_REFERENCE(osh)
74 #endif
75 
76 #ifndef BCM_UPTIME_PROFILE
77 #define OSL_GETCYCLES_PROF(x)
78 #endif
79 
80 /* --------------------------------------------------------------------------
81 ** Register manipulation macros.
82 */
83 
84 #define	SET_REG(osh, r, mask, val)	W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
85 
86 #ifndef AND_REG
87 #define AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
88 #endif   /* !AND_REG */
89 
90 #ifndef OR_REG
91 #define OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
92 #endif   /* !OR_REG */
93 
94 #if !defined(OSL_SYSUPTIME)
95 #define OSL_SYSUPTIME() (0)
96 #define OSL_SYSUPTIME_NOT_DEFINED 1
97 #endif /* !defined(OSL_SYSUPTIME) */
98 
99 #if !defined(OSL_SYSUPTIME_US)
100 #define OSL_SYSUPTIME_US() (0)
101 #define OSL_SYSUPTIME_US_NOT_DEFINED 1
102 #endif /* !defined(OSL_SYSUPTIME) */
103 
104 #if defined(OSL_SYSUPTIME_NOT_DEFINED) && defined(OSL_SYSUPTIME_US_NOT_DEFINED)
105 #define OSL_SYSUPTIME_SUPPORT FALSE
106 #else
107 #define OSL_SYSUPTIME_SUPPORT TRUE
108 #endif /* OSL_SYSUPTIME */
109 
110 #ifndef OSL_GET_LOCALTIME
111 #define OSL_GET_LOCALTIME(sec, usec)	\
112 	do { \
113 		BCM_REFERENCE(sec); \
114 		BCM_REFERENCE(usec); \
115 	} while (0)
116 #endif /* OSL_GET_LOCALTIME */
117 
118 #ifndef OSL_LOCALTIME_NS
119 #define OSL_LOCALTIME_NS()	(OSL_SYSUPTIME_US() * NSEC_PER_USEC)
120 #endif /* OSL_LOCALTIME_NS */
121 
122 #ifndef OSL_SYSTZTIME_US
123 #define OSL_SYSTZTIME_US()	OSL_SYSUPTIME_US()
124 #endif /* OSL_GET_SYSTZTIME */
125 
126 #if !defined(OSL_CPU_COUNTS_PER_US)
127 #define OSL_CPU_COUNTS_PER_US() (0)
128 #define OSL_CPU_COUNTS_PER_US_NOT_DEFINED 1
129 #endif /* !defined(OSL_CPU_COUNTS_PER_US) */
130 
131 #ifndef OSL_SYS_HALT
132 #ifdef __COVERITY__
133 /*
134  * For Coverity builds, provide a definition that allows Coverity
135  * to model the lack of return. This avoids Coverity False Positive
136  * defects associated with data inconsistency being detected after
137  * we otherwise would have halted.
138  */
139 #define OSL_SYS_HALT()   __coverity_panic__()
140 #else /* __COVERITY__ */
141 #define OSL_SYS_HALT()	do {} while (0)
142 #endif /* __COVERITY__ */
143 #endif /* OSL_SYS_HALT */
144 
145 #ifndef DMB
146 #define DMB()	do {} while (0)
147 #endif /* DMB */
148 
149 #ifndef OSL_MEM_AVAIL
150 #define OSL_MEM_AVAIL()	(0xffffffff)
151 #endif
152 
153 #ifndef OSL_OBFUSCATE_BUF
154 #if defined (_RTE_)
155 #define OSL_OBFUSCATE_BUF(x) osl_obfuscate_ptr(x)
156 #else
157 #define OSL_OBFUSCATE_BUF(x) (x)
158 #endif	/* _RTE_ */
159 #endif	/* OSL_OBFUSCATE_BUF */
160 
161 #ifndef OSL_GET_HCAPISTIMESYNC
162 #if defined (_RTE_)
163 #define OSL_GET_HCAPISTIMESYNC() osl_get_hcapistimesync()
164 #else
165 #define OSL_GET_HCAPISTIMESYNC()
166 #endif	/* _RTE_ */
167 #endif	/*  OSL_GET_HCAPISTIMESYNC */
168 
169 #ifndef OSL_GET_HCAPISPKTTXS
170 #if defined (_RTE_)
171 #define OSL_GET_HCAPISPKTTXS() osl_get_hcapispkttxs()
172 #else
173 #define OSL_GET_HCAPISPKTTXS()
174 #endif	/* _RTE_ */
175 #endif	/*  OSL_GET_HCAPISPKTTXS */
176 
177 #if !defined(PKTC_DONGLE)
178 #define	PKTCGETATTR(skb)	(0)
179 #define	PKTCSETATTR(skb, f, p, b) BCM_REFERENCE(skb)
180 #define	PKTCCLRATTR(skb)	BCM_REFERENCE(skb)
181 #define	PKTCCNT(skb)		(1)
182 #define	PKTCLEN(skb)		PKTLEN(NULL, skb)
183 #define	PKTCGETFLAGS(skb)	(0)
184 #define	PKTCSETFLAGS(skb, f)	BCM_REFERENCE(skb)
185 #define	PKTCCLRFLAGS(skb)	BCM_REFERENCE(skb)
186 #define	PKTCFLAGS(skb)		(0)
187 #define	PKTCSETCNT(skb, c)	BCM_REFERENCE(skb)
188 #define	PKTCINCRCNT(skb)	BCM_REFERENCE(skb)
189 #define	PKTCADDCNT(skb, c)	BCM_REFERENCE(skb)
190 #define	PKTCSETLEN(skb, l)	BCM_REFERENCE(skb)
191 #define	PKTCADDLEN(skb, l)	BCM_REFERENCE(skb)
192 #define	PKTCSETFLAG(skb, fb)	BCM_REFERENCE(skb)
193 #define	PKTCCLRFLAG(skb, fb)	BCM_REFERENCE(skb)
194 #define	PKTCLINK(skb)		NULL
195 #define	PKTSETCLINK(skb, x)	BCM_REFERENCE(skb)
196 #define FOREACH_CHAINED_PKT(skb, nskb) \
197 	for ((nskb) = NULL; (skb) != NULL; (skb) = (nskb))
198 #define	PKTCFREE		PKTFREE
199 #define PKTCENQTAIL(h, t, p) \
200 do { \
201 	if ((t) == NULL) { \
202 		(h) = (t) = (p); \
203 	} \
204 } while (0)
205 #endif /* !PKTC_DONGLE */
206 
207 #ifndef PKTSETCHAINED
208 #define PKTSETCHAINED(osh, skb)		BCM_REFERENCE(osh)
209 #endif
210 #ifndef PKTCLRCHAINED
211 #define PKTCLRCHAINED(osh, skb)		BCM_REFERENCE(osh)
212 #endif
213 #ifndef PKTISCHAINED
214 #define PKTISCHAINED(skb)		FALSE
215 #endif
216 
217 #ifndef PKTGETPROFILEIDX
218 #define PKTGETPROFILEIDX(p)		(-1)
219 #endif
220 
221 #ifndef PKTCLRPROFILEIDX
222 #define PKTCLRPROFILEIDX(p)
223 #endif
224 
225 #ifndef PKTSETPROFILEIDX
226 #define PKTSETPROFILEIDX(p, idx)	BCM_REFERENCE(idx)
227 #endif
228 
229 #ifndef _RTE_
230 /* Lbuf with fraglist */
231 #ifndef PKTFRAGPKTID
232 #define PKTFRAGPKTID(osh, lb)		(0)
233 #endif
234 #ifndef PKTSETFRAGPKTID
235 #define PKTSETFRAGPKTID(osh, lb, id)	BCM_REFERENCE(osh)
236 #endif
237 #ifndef PKTFRAGTOTNUM
238 #define PKTFRAGTOTNUM(osh, lb)		(0)
239 #endif
240 #ifndef PKTSETFRAGTOTNUM
241 #define PKTSETFRAGTOTNUM(osh, lb, tot)	BCM_REFERENCE(osh)
242 #endif
243 #ifndef PKTFRAGTOTLEN
244 #define PKTFRAGTOTLEN(osh, lb)		(0)
245 #endif
246 #ifndef PKTSETFRAGTOTLEN
247 #define PKTSETFRAGTOTLEN(osh, lb, len)	BCM_REFERENCE(osh)
248 #endif
249 #ifndef PKTIFINDEX
250 #define PKTIFINDEX(osh, lb)		(0)
251 #endif
252 #ifndef PKTSETIFINDEX
253 #define PKTSETIFINDEX(osh, lb, idx)	BCM_REFERENCE(osh)
254 #endif
255 #ifndef PKTGETLF
256 #define	PKTGETLF(osh, len, send, lbuf_type)	(0)
257 #endif
258 
259 /* in rx path, reuse totlen as used len */
260 #ifndef PKTFRAGUSEDLEN
261 #define PKTFRAGUSEDLEN(osh, lb)			(0)
262 #endif
263 #ifndef PKTSETFRAGUSEDLEN
264 #define PKTSETFRAGUSEDLEN(osh, lb, len)		BCM_REFERENCE(osh)
265 #endif
266 #ifndef PKTFRAGLEN
267 #define PKTFRAGLEN(osh, lb, ix)			(0)
268 #endif
269 #ifndef PKTSETFRAGLEN
270 #define PKTSETFRAGLEN(osh, lb, ix, len)		BCM_REFERENCE(osh)
271 #endif
272 #ifndef PKTFRAGDATA_LO
273 #define PKTFRAGDATA_LO(osh, lb, ix)		(0)
274 #endif
275 #ifndef PKTSETFRAGDATA_LO
276 #define PKTSETFRAGDATA_LO(osh, lb, ix, addr)	BCM_REFERENCE(osh)
277 #endif
278 #ifndef PKTFRAGDATA_HI
279 #define PKTFRAGDATA_HI(osh, lb, ix)		(0)
280 #endif
281 #ifndef PKTSETFRAGDATA_HI
282 #define PKTSETFRAGDATA_HI(osh, lb, ix, addr)	BCM_REFERENCE(osh)
283 #endif
284 
285 #ifndef PKTFRAGMOVE
286 #define PKTFRAGMOVE(osh, dst, src) (BCM_REFERENCE(osh), BCM_REFERENCE(dst), BCM_REFERENCE(src))
287 #endif
288 
289 /* RX FRAG */
290 #ifndef PKTISRXFRAG
291 #define PKTISRXFRAG(osh, lb)		(0)
292 #endif
293 #ifndef PKTSETRXFRAG
294 #define PKTSETRXFRAG(osh, lb)		BCM_REFERENCE(osh)
295 #endif
296 #ifndef PKTRESETRXFRAG
297 #define PKTRESETRXFRAG(osh, lb)		BCM_REFERENCE(osh)
298 #endif
299 
300 /* TX FRAG */
301 #ifndef PKTISTXFRAG
302 #define PKTISTXFRAG(osh, lb)		(0)
303 #endif
304 #ifndef PKTSETTXFRAG
305 #define PKTSETTXFRAG(osh, lb)		BCM_REFERENCE(osh)
306 #endif
307 
308 /* TX ALFRAG */
309 #ifndef PKTISTXALFRAG
310 #define PKTISTXALFRAG(osh, lb)		(0)
311 #endif
312 #ifndef PKTSETTXALFRAG
313 #define PKTSETTXALFRAG(osh, lb)		BCM_REFERENCE(osh)
314 #endif
315 #ifndef PKTRESETTXALFRAG
316 #define PKTRESETTXALFRAG(osh, lb)	BCM_REFERENCE(osh)
317 #endif
318 
319 #ifndef PKTNUMMPDUS
320 #define PKTNUMMPDUS(osh, lb)		(1)
321 #endif
322 #ifndef PKTNUMPKTS
323 #define PKTNUMPKTS(osh, lb)		(1)
324 #endif
325 
326 #ifndef PKTISHWCSO
327 #define PKTISHWCSO(osh, lb)		(FALSE)
328 #endif
329 
330 #ifndef PKTISSUBMSDUTOEHDR
331 #define PKTISSUBMSDUTOEHDR(osh, lb)	(FALSE)
332 #endif
333 
334 #ifndef PKT_IS_HOST_SFHLLC
335 #define PKT_IS_HOST_SFHLLC(osh, lb)	(FALSE)
336 #endif
337 
338 #ifndef PKT_SET_HOST_SFHLLC
339 #define PKT_SET_HOST_SFHLLC(osh, lb)	BCM_REFERENCE(osh)
340 #endif
341 
342 #ifndef PKT_IS_HOST_SFHLLC_DONE
343 #define PKT_IS_HOST_SFHLLC_DONE(osh, lb)	(FALSE)
344 #endif
345 
346 #ifndef PKT_SET_HOST_SFHLLC_DONE
347 #define PKT_SET_HOST_SFHLLC_DONE(osh, lb)	BCM_REFERENCE(osh)
348 #endif
349 
350 /* Need Rx completion used for AMPDU reordering */
351 #ifndef PKTNEEDRXCPL
352 #define PKTNEEDRXCPL(osh, lb)           (TRUE)
353 #endif
354 #ifndef PKTSETNORXCPL
355 #define PKTSETNORXCPL(osh, lb)          BCM_REFERENCE(osh)
356 #endif
357 #ifndef PKTRESETNORXCPL
358 #define PKTRESETNORXCPL(osh, lb)        BCM_REFERENCE(osh)
359 #endif
360 #ifndef PKTISFRAG
361 #define PKTISFRAG(osh, lb)		(0)
362 #endif
363 #ifndef PKTFRAGISCHAINED
364 #define PKTFRAGISCHAINED(osh, i)	(0)
365 #endif
366 #ifndef PKTISHDRCONVTD
367 #define PKTISHDRCONVTD(osh, lb)		(0)
368 #endif
369 
370 /* Forwarded pkt indication */
371 #ifndef PKTISFRWDPKT
372 #define PKTISFRWDPKT(osh, lb)		0
373 #endif
374 #ifndef PKTSETFRWDPKT
375 #define PKTSETFRWDPKT(osh, lb)		BCM_REFERENCE(osh)
376 #endif
377 #ifndef PKTRESETFRWDPKT
378 #define PKTRESETFRWDPKT(osh, lb)	BCM_REFERENCE(osh)
379 #endif
380 
381 /* PKT consumed for totlen calculation */
382 #ifndef PKTISUSEDTOTLEN
383 #define PKTISUSEDTOTLEN(osh, lb)		0
384 #endif
385 #ifndef PKTSETUSEDTOTLEN
386 #define PKTSETUSEDTOTLEN(osh, lb)		BCM_REFERENCE(osh)
387 #endif
388 #ifndef PKTRESETUSEDTOTLEN
389 #define PKTRESETUSEDTOTLEN(osh, lb)             BCM_REFERENCE(osh)
390 #endif
391 
392 /* UDR Packet Indication */
393 #ifndef PKTISUDR
394 #define PKTISUDR(osh, lb)			0
395 #endif
396 
397 #ifndef PKTSETUDR
398 #define PKTSETUDR(osh, lb)			BCM_REFERENCE(osh)
399 #endif
400 
401 #ifndef PKTSETUDR
402 #define PKTRESETUDR(osh, lb)			BCM_REFERENCE(osh)
403 #endif
404 #endif	/* _RTE_ */
405 
406 #if !(defined(__linux__))
407 #define PKTLIST_INIT(x)			BCM_REFERENCE(x)
408 #define PKTLIST_ENQ(x, y)		BCM_REFERENCE(x)
409 #define PKTLIST_DEQ(x)			BCM_REFERENCE(x)
410 #define PKTLIST_UNLINK(x, y)		BCM_REFERENCE(x)
411 #define PKTLIST_FINI(x)			BCM_REFERENCE(x)
412 #endif
413 
414 #ifndef ROMMABLE_ASSERT
415 #define ROMMABLE_ASSERT(exp) ASSERT(exp)
416 #endif /* ROMMABLE_ASSERT */
417 
418 #ifndef MALLOC_NOPERSIST
419 	#define MALLOC_NOPERSIST MALLOC
420 #endif /* !MALLOC_NOPERSIST */
421 
422 #ifndef MALLOC_PERSIST
423 	#define MALLOC_PERSIST MALLOC
424 #endif /* !MALLOC_PERSIST */
425 
426 #ifndef MALLOC_RA
427 	#define MALLOC_RA(osh, size, callsite) MALLOCZ(osh, size)
428 #endif /* !MALLOC_RA */
429 
430 #ifndef MALLOC_PERSIST_ATTACH
431 	#define MALLOC_PERSIST_ATTACH MALLOC
432 #endif /* !MALLOC_PERSIST_ATTACH */
433 
434 #ifndef MALLOCZ_PERSIST_ATTACH
435 	#define MALLOCZ_PERSIST_ATTACH MALLOCZ
436 #endif /* !MALLOCZ_PERSIST_ATTACH */
437 
438 #ifndef MALLOCZ_NOPERSIST
439 	#define MALLOCZ_NOPERSIST MALLOCZ
440 #endif /* !MALLOCZ_NOPERSIST */
441 
442 #ifndef MALLOCZ_PERSIST
443 	#define MALLOCZ_PERSIST MALLOCZ
444 #endif /* !MALLOCZ_PERSIST */
445 
446 #ifndef MFREE_PERSIST
447 	#define MFREE_PERSIST MFREE
448 #endif /* !MFREE_PERSIST */
449 
450 #ifndef MALLOC_SET_NOPERSIST
451 	#define MALLOC_SET_NOPERSIST(osh)	do { } while (0)
452 #endif /* !MALLOC_SET_NOPERSIST */
453 
454 #ifndef MALLOC_CLEAR_NOPERSIST
455 	#define MALLOC_CLEAR_NOPERSIST(osh)	do { } while (0)
456 #endif /* !MALLOC_CLEAR_NOPERSIST */
457 
458 #if defined(OSL_MEMCHECK)
459 #define MEMCHECK(f, l)	osl_memcheck(f, l)
460 #else
461 #define MEMCHECK(f, l)
462 #endif /* OSL_MEMCHECK */
463 
464 #ifndef BCMDBGPERF
465 #define PERF_TRACE_START(id)				do {} while (0)
466 #define PERF_TRACE_END(id)				do {} while (0)
467 #define PERF_TRACE_END2(id, mycounters)			do {} while (0)
468 #define PERF_TRACE_END3(id, mycounters, coreunit)	do {} while (0)
469 #define UPDATE_PERF_TRACE_COUNTER(counter, val)		do {} while (0)
470 #define ADD_PERF_TRACE_COUNTER(counter, val)		do {} while (0)
471 #endif /* OSL_MEMCHECK */
472 
473 /* Virtual/physical address translation. */
474 #if !defined(OSL_VIRT_TO_PHYS_ADDR)
475 	#define OSL_VIRT_TO_PHYS_ADDR(va)	((void*)(uintptr)(va))
476 #endif
477 
478 #if !defined(OSL_PHYS_TO_VIRT_ADDR)
479 	#define OSL_PHYS_TO_VIRT_ADDR(pa)	((void*)(uintptr)(pa))
480 #endif
481 
482 #endif	/* _osl_h_ */
483