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