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