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