1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Linux OS Independent 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: linux_osl.h 815919 2019-04-22 09:06:50Z $
29 */
30
31 #ifndef _linux_osl_h_
32 #define _linux_osl_h_
33
34 #include <typedefs.h>
35 #define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x)))
36
37 /* Linux Kernel: File Operations: start */
38 extern void * osl_os_open_image(char * filename);
39 extern int osl_os_get_image_block(char * buf, int len, void * image);
40 extern void osl_os_close_image(void * image);
41 extern int osl_os_image_size(void *image);
42 /* Linux Kernel: File Operations: end */
43
44 #ifdef BCMDRIVER
45
46 /* OSL initialization */
47 extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
48
49 extern void osl_detach(osl_t *osh);
50 extern int osl_static_mem_init(osl_t *osh, void *adapter);
51 extern int osl_static_mem_deinit(osl_t *osh, void *adapter);
52 extern void osl_set_bus_handle(osl_t *osh, void *bus_handle);
53 extern void* osl_get_bus_handle(osl_t *osh);
54 #ifdef DHD_MAP_LOGGING
55 extern void osl_dma_map_dump(osl_t *osh);
56 #define OSL_DMA_MAP_DUMP(osh) osl_dma_map_dump(osh)
57 #else
58 #define OSL_DMA_MAP_DUMP(osh) do {} while (0)
59 #endif /* DHD_MAP_LOGGING */
60
61 /* Global ASSERT type */
62 extern uint32 g_assert_type;
63
64 #ifdef CONFIG_PHYS_ADDR_T_64BIT
65 #define PRI_FMT_x "llx"
66 #define PRI_FMT_X "llX"
67 #define PRI_FMT_o "llo"
68 #define PRI_FMT_d "lld"
69 #else
70 #define PRI_FMT_x "x"
71 #define PRI_FMT_X "X"
72 #define PRI_FMT_o "o"
73 #define PRI_FMT_d "d"
74 #endif /* CONFIG_PHYS_ADDR_T_64BIT */
75 /* ASSERT */
76 #ifndef ASSERT
77 #if defined(BCMASSERT_LOG)
78 #define ASSERT(exp) \
79 do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
80 extern void osl_assert(const char *exp, const char *file, int line);
81 #else
82 #ifdef __GNUC__
83 #define GCC_VERSION \
84 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
85 #if GCC_VERSION > 30100
86 #define ASSERT(exp) do {} while (0)
87 #else
88 /* ASSERT could cause segmentation fault on GCC3.1, use empty instead */
89 #define ASSERT(exp)
90 #endif /* GCC_VERSION > 30100 */
91 #endif /* __GNUC__ */
92 #endif // endif
93 #endif /* ASSERT */
94
95 /* bcm_prefetch_32B */
bcm_prefetch_32B(const uint8 * addr,const int cachelines_32B)96 static inline void bcm_prefetch_32B(const uint8 *addr, const int cachelines_32B)
97 {
98 #if (defined(STB) && defined(__arm__)) && (__LINUX_ARM_ARCH__ >= 5)
99 switch (cachelines_32B) {
100 case 4: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 96) : "cc");
101 case 3: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 64) : "cc");
102 case 2: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 32) : "cc");
103 case 1: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 0) : "cc");
104 }
105 #endif // endif
106 }
107
108 /* microsecond delay */
109 #define OSL_DELAY(usec) osl_delay(usec)
110 extern void osl_delay(uint usec);
111
112 #define OSL_SLEEP(ms) osl_sleep(ms)
113 extern void osl_sleep(uint ms);
114
115 #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
116 osl_pcmcia_read_attr((osh), (offset), (buf), (size))
117 #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
118 osl_pcmcia_write_attr((osh), (offset), (buf), (size))
119 extern void osl_pcmcia_read_attr(osl_t *osh, uint offset, void *buf, int size);
120 extern void osl_pcmcia_write_attr(osl_t *osh, uint offset, void *buf, int size);
121
122 /* PCI configuration space access macros */
123 #define OSL_PCI_READ_CONFIG(osh, offset, size) \
124 osl_pci_read_config((osh), (offset), (size))
125 #define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
126 osl_pci_write_config((osh), (offset), (size), (val))
127 extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
128 extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
129
130 /* PCI device bus # and slot # */
131 #define OSL_PCI_BUS(osh) osl_pci_bus(osh)
132 #define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
133 #define OSL_PCIE_DOMAIN(osh) osl_pcie_domain(osh)
134 #define OSL_PCIE_BUS(osh) osl_pcie_bus(osh)
135 extern uint osl_pci_bus(osl_t *osh);
136 extern uint osl_pci_slot(osl_t *osh);
137 extern uint osl_pcie_domain(osl_t *osh);
138 extern uint osl_pcie_bus(osl_t *osh);
139 extern struct pci_dev *osl_pci_device(osl_t *osh);
140
141 #define OSL_ACP_COHERENCE (1<<1L)
142 #define OSL_FWDERBUF (1<<2L)
143
144 /* Pkttag flag should be part of public information */
145 typedef struct {
146 bool pkttag;
147 bool mmbus; /**< Bus supports memory-mapped register accesses */
148 pktfree_cb_fn_t tx_fn; /**< Callback function for PKTFREE */
149 void *tx_ctx; /**< Context to the callback function */
150 void *unused[3];
151 void (*rx_fn)(void *rx_ctx, void *p);
152 void *rx_ctx;
153 } osl_pubinfo_t;
154
155 extern void osl_flag_set(osl_t *osh, uint32 mask);
156 extern void osl_flag_clr(osl_t *osh, uint32 mask);
157 extern bool osl_is_flag_set(osl_t *osh, uint32 mask);
158
159 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
160 do { \
161 ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn; \
162 ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx; \
163 } while (0)
164
165 #define PKTFREESETRXCB(osh, _rx_fn, _rx_ctx) \
166 do { \
167 ((osl_pubinfo_t*)osh)->rx_fn = _rx_fn; \
168 ((osl_pubinfo_t*)osh)->rx_ctx = _rx_ctx; \
169 } while (0)
170
171 /* host/bus architecture-specific byte swap */
172 #define BUS_SWAP32(v) (v)
173 #define MALLOC(osh, size) osl_malloc((osh), (size))
174 #define MALLOCZ(osh, size) osl_mallocz((osh), (size))
175 #define MFREE(osh, addr, size) osl_mfree((osh), (addr), (size))
176 #define VMALLOC(osh, size) osl_vmalloc((osh), (size))
177 #define VMALLOCZ(osh, size) osl_vmallocz((osh), (size))
178 #define VMFREE(osh, addr, size) osl_vmfree((osh), (addr), (size))
179 #define MALLOCED(osh) osl_malloced((osh))
180 #define MEMORY_LEFTOVER(osh) osl_check_memleak(osh)
181 extern void *osl_malloc(osl_t *osh, uint size);
182 extern void *osl_mallocz(osl_t *osh, uint size);
183 extern void osl_mfree(osl_t *osh, void *addr, uint size);
184 extern void *osl_vmalloc(osl_t *osh, uint size);
185 extern void *osl_vmallocz(osl_t *osh, uint size);
186 extern void osl_vmfree(osl_t *osh, void *addr, uint size);
187 extern uint osl_malloced(osl_t *osh);
188 extern uint osl_check_memleak(osl_t *osh);
189
190 #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
191 extern uint osl_malloc_failed(osl_t *osh);
192
193 /* allocate/free shared (dma-able) consistent memory */
194 #define DMA_CONSISTENT_ALIGN osl_dma_consistent_align()
195 #define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
196 osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
197 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
198 osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
199
200 #define DMA_ALLOC_CONSISTENT_FORCE32(osh, size, align, tot, pap, dmah) \
201 osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
202 #define DMA_FREE_CONSISTENT_FORCE32(osh, va, size, pa, dmah) \
203 osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
204
205 extern uint osl_dma_consistent_align(void);
206 extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, uint16 align,
207 uint *tot, dmaaddr_t *pap);
208 extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa);
209
210 /* map/unmap direction */
211 #define DMA_NO 0 /* Used to skip cache op */
212 #define DMA_TX 1 /* TX direction for DMA */
213 #define DMA_RX 2 /* RX direction for DMA */
214
215 /* map/unmap shared (dma-able) memory */
216 #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
217 osl_dma_unmap((osh), (pa), (size), (direction))
218 extern void osl_dma_flush(osl_t *osh, void *va, uint size, int direction, void *p,
219 hnddma_seg_map_t *txp_dmah);
220 extern dmaaddr_t osl_dma_map(osl_t *osh, void *va, uint size, int direction, void *p,
221 hnddma_seg_map_t *txp_dmah);
222 extern void osl_dma_unmap(osl_t *osh, dmaaddr_t pa, uint size, int direction);
223
224 #ifndef PHYS_TO_VIRT
225 #define PHYS_TO_VIRT(pa) osl_phys_to_virt(pa)
226 #endif // endif
227 #ifndef VIRT_TO_PHYS
228 #define VIRT_TO_PHYS(va) osl_virt_to_phys(va)
229 #endif // endif
230 extern void * osl_phys_to_virt(void * pa);
231 extern void * osl_virt_to_phys(void * va);
232
233 /* API for DMA addressing capability */
234 #define OSL_DMADDRWIDTH(osh, addrwidth) ({BCM_REFERENCE(osh); BCM_REFERENCE(addrwidth);})
235
236 #define OSL_SMP_WMB() smp_wmb()
237
238 /* API for CPU relax */
239 extern void osl_cpu_relax(void);
240 #define OSL_CPU_RELAX() osl_cpu_relax()
241
242 extern void osl_preempt_disable(osl_t *osh);
243 extern void osl_preempt_enable(osl_t *osh);
244 #define OSL_DISABLE_PREEMPTION(osh) osl_preempt_disable(osh)
245 #define OSL_ENABLE_PREEMPTION(osh) osl_preempt_enable(osh)
246
247 #if (!defined(DHD_USE_COHERENT_MEM_FOR_RING) && defined(__ARM_ARCH_7A__)) || \
248 defined(STB_SOC_WIFI)
249 extern void osl_cache_flush(void *va, uint size);
250 extern void osl_cache_inv(void *va, uint size);
251 extern void osl_prefetch(const void *ptr);
252 #define OSL_CACHE_FLUSH(va, len) osl_cache_flush((void *)(va), len)
253 #define OSL_CACHE_INV(va, len) osl_cache_inv((void *)(va), len)
254 #define OSL_PREFETCH(ptr) osl_prefetch(ptr)
255 #if defined(__ARM_ARCH_7A__) || defined(STB_SOC_WIFI)
256 extern int osl_arch_is_coherent(void);
257 #define OSL_ARCH_IS_COHERENT() osl_arch_is_coherent()
258 extern int osl_acp_war_enab(void);
259 #define OSL_ACP_WAR_ENAB() osl_acp_war_enab()
260 #else /* !__ARM_ARCH_7A__ */
261 #define OSL_ARCH_IS_COHERENT() NULL
262 #define OSL_ACP_WAR_ENAB() NULL
263 #endif /* !__ARM_ARCH_7A__ */
264 #else /* !__mips__ && !__ARM_ARCH_7A__ */
265 #define OSL_CACHE_FLUSH(va, len) BCM_REFERENCE(va)
266 #define OSL_CACHE_INV(va, len) BCM_REFERENCE(va)
267 #define OSL_PREFETCH(ptr) BCM_REFERENCE(ptr)
268
269 #define OSL_ARCH_IS_COHERENT() NULL
270 #define OSL_ACP_WAR_ENAB() NULL
271 #endif // endif
272
273 #ifdef BCM_BACKPLANE_TIMEOUT
274 extern void osl_set_bpt_cb(osl_t *osh, void *bpt_cb, void *bpt_ctx);
275 extern void osl_bpt_rreg(osl_t *osh, ulong addr, volatile void *v, uint size);
276 #endif /* BCM_BACKPLANE_TIMEOUT */
277
278 #if (defined(STB) && defined(__arm__))
279 extern void osl_pcie_rreg(osl_t *osh, ulong addr, volatile void *v, uint size);
280 #endif // endif
281
282 /* register access macros */
283 #if defined(BCMSDIO)
284 #include <bcmsdh.h>
285 #define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(osl_get_bus_handle(osh), \
286 (uintptr)(r), sizeof(*(r)), (v)))
287 #define OSL_READ_REG(osh, r) (bcmsdh_reg_read(osl_get_bus_handle(osh), \
288 (uintptr)(r), sizeof(*(r))))
289 #elif defined(BCM_BACKPLANE_TIMEOUT)
290 #define OSL_READ_REG(osh, r) \
291 ({\
292 __typeof(*(r)) __osl_v; \
293 osl_bpt_rreg(osh, (uintptr)(r), &__osl_v, sizeof(*(r))); \
294 __osl_v; \
295 })
296 #elif (defined(STB) && defined(__arm__))
297 #define OSL_READ_REG(osh, r) \
298 ({\
299 __typeof(*(r)) __osl_v; \
300 osl_pcie_rreg(osh, (uintptr)(r), &__osl_v, sizeof(*(r))); \
301 __osl_v; \
302 })
303 #endif // endif
304
305 #if defined(BCM_BACKPLANE_TIMEOUT) || (defined(STB) && defined(__arm__))
306 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
307 #define SELECT_BUS_READ(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); bus_op;})
308 #else /* !BCM47XX_CA9 && !BCM_BACKPLANE_TIMEOUT && !(STB && __arm__) */
309 #if defined(BCMSDIO)
310 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
311 mmap_op else bus_op
312 #define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
313 mmap_op : bus_op
314 #else
315 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
316 #define SELECT_BUS_READ(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
317 #endif // endif
318 #endif // endif
319
320 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
321 extern int osl_error(int bcmerror);
322
323 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
324 #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
325
326 #define OSH_NULL NULL
327
328 /*
329 * BINOSL selects the slightly slower function-call-based binary compatible osl.
330 * Macros expand to calls to functions defined in linux_osl.c .
331 */
332 #include <linuxver.h> /* use current 2.4.x calling conventions */
333 #include <linux/kernel.h> /* for vsn/printf's */
334 #include <linux/string.h> /* for mem*, str* */
335 extern uint64 osl_sysuptime_us(void);
336 #define OSL_SYSUPTIME() ((uint32)jiffies_to_msecs(jiffies))
337 #define OSL_SYSUPTIME_US() osl_sysuptime_us()
338 extern uint64 osl_localtime_ns(void);
339 extern void osl_get_localtime(uint64 *sec, uint64 *usec);
340 extern uint64 osl_systztime_us(void);
341 #define OSL_LOCALTIME_NS() osl_localtime_ns()
342 #define OSL_GET_LOCALTIME(sec, usec) osl_get_localtime((sec), (usec))
343 #define OSL_SYSTZTIME_US() osl_systztime_us()
344 #define printf(fmt, args...) printk(DHD_LOG_PREFIXS fmt , ## args)
345 #include <linux/kernel.h> /* for vsn/printf's */
346 #include <linux/string.h> /* for mem*, str* */
347 /* bcopy's: Linux kernel doesn't provide these (anymore) */
348 #define bcopy_hw(src, dst, len) memcpy((dst), (src), (len))
349 #define bcopy_hw_async(src, dst, len) memcpy((dst), (src), (len))
350 #define bcopy_hw_poll_for_completion()
351 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
352 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
353 #define bzero(b, len) memset((b), '\0', (len))
354
355 /* register access macros */
356
357 #ifdef CONFIG_64BIT
358 /* readq is defined only for 64 bit platform */
359 #define R_REG(osh, r) (\
360 SELECT_BUS_READ(osh, \
361 ({ \
362 __typeof(*(r)) __osl_v = 0; \
363 BCM_REFERENCE(osh); \
364 switch (sizeof(*(r))) { \
365 case sizeof(uint8): __osl_v = \
366 readb((volatile uint8*)(r)); break; \
367 case sizeof(uint16): __osl_v = \
368 readw((volatile uint16*)(r)); break; \
369 case sizeof(uint32): __osl_v = \
370 readl((volatile uint32*)(r)); break; \
371 case sizeof(uint64): __osl_v = \
372 readq((volatile uint64*)(r)); break; \
373 } \
374 __osl_v; \
375 }), \
376 OSL_READ_REG(osh, r)) \
377 )
378 #else /* !CONFIG_64BIT */
379 #define R_REG(osh, r) (\
380 SELECT_BUS_READ(osh, \
381 ({ \
382 __typeof(*(r)) __osl_v = 0; \
383 switch (sizeof(*(r))) { \
384 case sizeof(uint8): __osl_v = \
385 readb((volatile uint8*)(r)); break; \
386 case sizeof(uint16): __osl_v = \
387 readw((volatile uint16*)(r)); break; \
388 case sizeof(uint32): __osl_v = \
389 readl((volatile uint32*)(r)); break; \
390 } \
391 __osl_v; \
392 }), \
393 OSL_READ_REG(osh, r)) \
394 )
395 #endif /* CONFIG_64BIT */
396
397 #ifdef CONFIG_64BIT
398 /* writeq is defined only for 64 bit platform */
399 #define W_REG(osh, r, v) do { \
400 SELECT_BUS_WRITE(osh, \
401 switch (sizeof(*(r))) { \
402 case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
403 case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
404 case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
405 case sizeof(uint64): writeq((uint64)(v), (volatile uint64*)(r)); break; \
406 }, \
407 (OSL_WRITE_REG(osh, r, v))); \
408 } while (0)
409
410 #else /* !CONFIG_64BIT */
411 #define W_REG(osh, r, v) do { \
412 SELECT_BUS_WRITE(osh, \
413 switch (sizeof(*(r))) { \
414 case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
415 case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
416 case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
417 }, \
418 (OSL_WRITE_REG(osh, r, v))); \
419 } while (0)
420 #endif /* CONFIG_64BIT */
421
422 #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
423 #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
424
425 /* bcopy, bcmp, and bzero functions */
426 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
427 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
428 #define bzero(b, len) memset((b), '\0', (len))
429
430 /* uncached/cached virtual address */
431 #define OSL_UNCACHED(va) ((void *)va)
432 #define OSL_CACHED(va) ((void *)va)
433
434 #define OSL_PREF_RANGE_LD(va, sz) BCM_REFERENCE(va)
435 #define OSL_PREF_RANGE_ST(va, sz) BCM_REFERENCE(va)
436
437 /* get processor cycle count */
438 #if defined(__i386__)
439 #define OSL_GETCYCLES(x) rdtscl((x))
440 #else
441 #define OSL_GETCYCLES(x) ((x) = 0)
442 #endif // endif
443
444 /* dereference an address that may cause a bus exception */
445 #define BUSPROBE(val, addr) ({ (val) = R_REG(NULL, (addr)); 0; })
446
447 /* map/unmap physical to virtual I/O */
448 #if !defined(CONFIG_MMC_MSM7X00A)
449 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0))
450 #define REG_MAP(pa, size) ioremap((unsigned long)(pa), (unsigned long)(size))
451 #else
452 #define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
453 #endif
454 #else
455 #define REG_MAP(pa, size) (void *)(0)
456 #endif /* !defined(CONFIG_MMC_MSM7X00A */
457 #define REG_UNMAP(va) iounmap((va))
458
459 /* shared (dma-able) memory access macros */
460 #define R_SM(r) *(r)
461 #define W_SM(r, v) (*(r) = (v))
462 #define BZERO_SM(r, len) memset((r), '\0', (len))
463
464 /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for
465 * performance reasons), we need the Linux headers.
466 */
467 #include <linuxver.h> /* use current 2.4.x calling conventions */
468
469 #define OSL_RAND() osl_rand()
470 extern uint32 osl_rand(void);
471
472 #define DMA_FLUSH(osh, va, size, direction, p, dmah) \
473 osl_dma_flush((osh), (va), (size), (direction), (p), (dmah))
474 #if !defined(BCM_SECURE_DMA)
475 #define DMA_MAP(osh, va, size, direction, p, dmah) \
476 osl_dma_map((osh), (va), (size), (direction), (p), (dmah))
477 #endif /* !(defined(BCM_SECURE_DMA)) */
478
479 #else /* ! BCMDRIVER */
480
481 /* ASSERT */
482 #define ASSERT(exp) do {} while (0)
483
484 /* MALLOC and MFREE */
485 #define MALLOC(o, l) malloc(l)
486 #define MFREE(o, p, l) free(p)
487 #include <stdlib.h>
488
489 /* str* and mem* functions */
490 #include <string.h>
491
492 /* *printf functions */
493 #include <stdio.h>
494
495 /* bcopy, bcmp, and bzero */
496 extern void bcopy(const void *src, void *dst, size_t len);
497 extern int bcmp(const void *b1, const void *b2, size_t len);
498 extern void bzero(void *b, size_t len);
499 #endif /* ! BCMDRIVER */
500
501 /* Current STB 7445D1 doesn't use ACP and it is non-coherrent.
502 * Adding these dummy values for build apss only
503 * When we revisit need to change these.
504 */
505
506 #ifdef BCM_SECURE_DMA
507
508 #define SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) \
509 osl_sec_dma_map((osh), (va), (size), (direction), (p), (dmah), (pcma), (offset))
510 #define SECURE_DMA_DD_MAP(osh, va, size, direction, p, dmah) \
511 osl_sec_dma_dd_map((osh), (va), (size), (direction), (p), (dmah))
512 #define SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) \
513 osl_sec_dma_map_txmeta((osh), (va), (size), (direction), (p), (dmah), (pcma))
514 #define SECURE_DMA_UNMAP(osh, pa, size, direction, p, dmah, pcma, offset) \
515 osl_sec_dma_unmap((osh), (pa), (size), (direction), (p), (dmah), (pcma), (offset))
516 #define SECURE_DMA_UNMAP_ALL(osh, pcma) \
517 osl_sec_dma_unmap_all((osh), (pcma))
518
519 #define DMA_MAP(osh, va, size, direction, p, dmah)
520
521 typedef struct sec_cma_info {
522 struct sec_mem_elem *sec_alloc_list;
523 struct sec_mem_elem *sec_alloc_list_tail;
524 } sec_cma_info_t;
525
526 #if defined(__ARM_ARCH_7A__)
527 #define CMA_BUFSIZE_4K 4096
528 #define CMA_BUFSIZE_2K 2048
529 #define CMA_BUFSIZE_512 512
530
531 #define CMA_BUFNUM 2048
532 #define SEC_CMA_COHERENT_BLK 0x8000 /* 32768 */
533 #define SEC_CMA_COHERENT_MAX 278
534 #define CMA_DMA_DESC_MEMBLOCK (SEC_CMA_COHERENT_BLK * SEC_CMA_COHERENT_MAX)
535 #define CMA_DMA_DATA_MEMBLOCK (CMA_BUFSIZE_4K*CMA_BUFNUM)
536 #define CMA_MEMBLOCK (CMA_DMA_DESC_MEMBLOCK + CMA_DMA_DATA_MEMBLOCK)
537 #define CONT_REGION 0x02 /* Region CMA */
538 #else
539 #define CONT_REGION 0x00 /* To access the MIPs mem, Not yet... */
540 #endif /* !defined __ARM_ARCH_7A__ */
541
542 #define SEC_DMA_ALIGN (1<<16)
543 typedef struct sec_mem_elem {
544 size_t size;
545 int direction;
546 phys_addr_t pa_cma; /**< physical address */
547 void *va; /**< virtual address of driver pkt */
548 dma_addr_t dma_handle; /**< bus address assign by linux */
549 void *vac; /**< virtual address of cma buffer */
550 struct page *pa_cma_page; /* phys to page address */
551 struct sec_mem_elem *next;
552 } sec_mem_elem_t;
553
554 extern dma_addr_t osl_sec_dma_map(osl_t *osh, void *va, uint size, int direction, void *p,
555 hnddma_seg_map_t *dmah, void *ptr_cma_info, uint offset);
556 extern dma_addr_t osl_sec_dma_dd_map(osl_t *osh, void *va, uint size, int direction, void *p,
557 hnddma_seg_map_t *dmah);
558 extern dma_addr_t osl_sec_dma_map_txmeta(osl_t *osh, void *va, uint size,
559 int direction, void *p, hnddma_seg_map_t *dmah, void *ptr_cma_info);
560 extern void osl_sec_dma_unmap(osl_t *osh, dma_addr_t dma_handle, uint size, int direction,
561 void *p, hnddma_seg_map_t *map, void *ptr_cma_info, uint offset);
562 extern void osl_sec_dma_unmap_all(osl_t *osh, void *ptr_cma_info);
563
564 #endif /* BCM_SECURE_DMA */
565
566 typedef struct sk_buff_head PKT_LIST;
567 #define PKTLIST_INIT(x) skb_queue_head_init((x))
568 #define PKTLIST_ENQ(x, y) skb_queue_head((struct sk_buff_head *)(x), (struct sk_buff *)(y))
569 #define PKTLIST_DEQ(x) skb_dequeue((struct sk_buff_head *)(x))
570 #define PKTLIST_UNLINK(x, y) skb_unlink((struct sk_buff *)(y), (struct sk_buff_head *)(x))
571 #define PKTLIST_FINI(x) skb_queue_purge((struct sk_buff_head *)(x))
572
573 #ifndef _linuxver_h_
574 typedef struct timer_list_compat timer_list_compat_t;
575 #endif /* _linuxver_h_ */
576 typedef struct osl_timer {
577 timer_list_compat_t *timer;
578 bool set;
579 } osl_timer_t;
580
581 typedef void (*linux_timer_fn)(ulong arg);
582
583 extern osl_timer_t * osl_timer_init(osl_t *osh, const char *name, void (*fn)(void *arg), void *arg);
584 extern void osl_timer_add(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic);
585 extern void osl_timer_update(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic);
586 extern bool osl_timer_del(osl_t *osh, osl_timer_t *t);
587
588 typedef atomic_t osl_atomic_t;
589 #define OSL_ATOMIC_SET(osh, v, x) atomic_set(v, x)
590 #define OSL_ATOMIC_INIT(osh, v) atomic_set(v, 0)
591 #define OSL_ATOMIC_INC(osh, v) atomic_inc(v)
592 #define OSL_ATOMIC_INC_RETURN(osh, v) atomic_inc_return(v)
593 #define OSL_ATOMIC_DEC(osh, v) atomic_dec(v)
594 #define OSL_ATOMIC_DEC_RETURN(osh, v) atomic_dec_return(v)
595 #define OSL_ATOMIC_READ(osh, v) atomic_read(v)
596 #define OSL_ATOMIC_ADD(osh, v, x) atomic_add(v, x)
597
598 #ifndef atomic_set_mask
599 #define OSL_ATOMIC_OR(osh, v, x) atomic_or(x, v)
600 #define OSL_ATOMIC_AND(osh, v, x) atomic_and(x, v)
601 #else
602 #define OSL_ATOMIC_OR(osh, v, x) atomic_set_mask(x, v)
603 #define OSL_ATOMIC_AND(osh, v, x) atomic_clear_mask(~x, v)
604 #endif // endif
605
606 #include <linux/rbtree.h>
607
608 typedef struct rb_node osl_rb_node_t;
609 typedef struct rb_root osl_rb_root_t;
610
611 #define OSL_RB_ENTRY(ptr, type, member) rb_entry(ptr, type, member)
612 #define OSL_RB_INSERT_COLOR(root, node) rb_insert_color(root, node)
613 #define OSL_RB_ERASE(node, root) rb_erase(node, root)
614 #define OSL_RB_FIRST(root) rb_first(root)
615 #define OSL_RB_LAST(root) rb_last(root)
616 #define OSL_RB_LINK_NODE(node, parent, rb_link) \
617 rb_link_node(node, parent, rb_link)
618
619 extern void *osl_spin_lock_init(osl_t *osh);
620 extern void osl_spin_lock_deinit(osl_t *osh, void *lock);
621 extern unsigned long osl_spin_lock(void *lock);
622 extern void osl_spin_unlock(void *lock, unsigned long flags);
623
624 typedef struct osl_timespec {
625 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0))
626 __kernel_old_time_t tv_sec; /* seconds */
627 #else
628 __kernel_time_t tv_sec; /* seconds */
629 #endif
630 __kernel_suseconds_t tv_usec; /* microseconds */
631 long tv_nsec; /* nanoseconds */
632 } osl_timespec_t;
633 extern void osl_do_gettimeofday(struct osl_timespec *ts);
634 extern void osl_get_monotonic_boottime(struct osl_timespec *ts);
635 extern uint32 osl_do_gettimediff(struct osl_timespec *cur_ts, struct osl_timespec *old_ts);
636 #endif /* _linux_osl_h_ */
637