Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / include / hndrte_osl.h
blob34f4fb814ea12cd695f2553142f6656f1e80a355
1 /*
2 * HND Run Time Environment OS Abstraction Layer.
4 * Copyright (C) 2010, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: hndrte_osl.h,v 13.98.14.1 2010-05-23 18:19:25 Exp $
15 #ifndef _hndrte_osl_h_
16 #define _hndrte_osl_h_
18 #include <hndrte.h>
19 #include <hndrte_lbuf.h>
21 struct osl_info {
22 uint pktalloced; /* Number of allocated packet buffers */
23 void *dev; /* Device handle */
24 pktfree_cb_fn_t tx_fn; /* Callback function for PKTFREE */
25 void *tx_ctx; /* Context to the callback function */
28 struct pktpool;
29 struct bcmstrbuf;
31 /* PCMCIA attribute space access macros */
32 #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
33 ASSERT(0)
34 #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
35 ASSERT(0)
37 /* PCI configuration space access macros */
38 #ifdef SBPCI
39 #define OSL_PCI_READ_CONFIG(osh, offset, size) \
40 osl_pci_read_config((osh), (offset), (size))
41 #define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
42 osl_pci_write_config((osh), (offset), (size), (val))
43 extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
44 extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
46 /* PCI device bus # and slot # */
47 #define OSL_PCI_BUS(osh) osl_pci_bus(osh)
48 #define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
49 extern uint osl_pci_bus(osl_t *osh);
50 extern uint osl_pci_slot(osl_t *osh);
51 #else /* SBPCI */
52 #define OSL_PCI_READ_CONFIG(osh, offset, size) \
53 (offset == 8 ? 0 : 0xffffffff)
54 #define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
55 do {} while (0)
57 /* PCI device bus # and slot # */
58 #define OSL_PCI_BUS(osh) (0)
59 #define OSL_PCI_SLOT(osh) (0)
60 #endif /* SBPCI */
62 /* register access macros */
63 #define R_REG(osh, r) \
64 (sizeof(*(r)) == sizeof(uint32) ? rreg32((volatile uint32 *)(void *)(r)) : \
65 sizeof(*(r)) == sizeof(uint16) ? rreg16((volatile uint16 *)(void *)(r)) : \
66 rreg8((volatile uint8 *)(void *)(r)))
67 #define W_REG(osh, r, v) \
68 do { \
69 if (sizeof(*(r)) == sizeof(uint32)) \
70 wreg32((volatile uint32 *)(void *)(r), (uint32)(v)); \
71 else if (sizeof(*(r)) == sizeof(uint16)) \
72 wreg16((volatile uint16 *)(void *)(r), (uint16)(v)); \
73 else \
74 wreg8((volatile uint8 *)(void *)(r), (uint8)(v)); \
75 } while (0)
77 #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
78 #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
80 /* OSL initialization */
81 extern osl_t *osl_attach(void *pdev);
82 extern void osl_detach(osl_t *osh);
84 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
85 do { \
86 osh->tx_fn = _tx_fn; \
87 osh->tx_ctx = _tx_ctx; \
88 } while (0)
90 /* general purpose memory allocation */
91 #if defined(BCMDBG_MEM) || defined(BCMDBG_MEMFAIL)
92 #define MALLOC(osh, size) osl_malloc((osh), (size), __FILE__, __LINE__)
93 extern void *osl_malloc(osl_t *osh, uint size, char *file, int line);
94 #else
95 #define MALLOC(osh, size) osl_malloc((osh), (size))
96 extern void *osl_malloc(osl_t *osh, uint size);
97 #endif /* BCMDBG_MEM */
99 #define MFREE(osh, addr, size) osl_mfree((osh), (addr), (size))
100 #define MALLOCED(osh) osl_malloced((osh))
101 #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
102 #define MALLOC_DUMP(osh, b)
103 extern int osl_mfree(osl_t *osh, void *addr, uint size);
104 extern uint osl_malloced(osl_t *osh);
105 extern uint osl_malloc_failed(osl_t *osh);
106 extern int osl_error(int bcmerror);
108 /* microsecond delay */
109 #define OSL_DELAY(usec) hndrte_delay(usec)
111 /* host/bus architecture-specific address byte swap */
112 #define BUS_SWAP32(v) (v)
114 /* get processor cycle count */
115 #define OSL_GETCYCLES(x) ((x) = osl_getcycles())
117 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
119 /* uncached/cached virtual address */
120 #define OSL_UNCACHED(va) hndrte_uncached(va)
121 #define OSL_CACHED(va) hndrte_cached(va)
123 #define OSL_PREF_RANGE_LD(va, sz)
124 #define OSL_PREF_RANGE_ST(va, sz)
126 /* dereference an address that may cause a bus exception */
127 #define BUSPROBE(val, addr) osl_busprobe(&(val), (uint32)(addr))
128 extern int osl_busprobe(uint32 *val, uint32 addr);
130 /* allocate/free shared (dma-able) consistent (uncached) memory */
131 #define DMA_CONSISTENT_ALIGN_BITS 2
132 #define DMA_CONSISTENT_ALIGN (1 << DMA_CONSISTENT_ALIGN_BITS)
134 #if defined(BCMDBG_MEM) || defined(BCMDBG_MEMFAIL)
135 #define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
136 hndrte_dma_alloc_consistent(size, align, (tot), (void *)(pap), __FILE__, __LINE__)
137 #else
138 #define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
139 hndrte_dma_alloc_consistent(size, align, (tot), (void *)(pap))
140 #endif
141 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
142 hndrte_dma_free_consistent((void*)(va))
144 /* map/unmap direction */
145 #define DMA_TX 1 /* TX direction for DMA */
146 #define DMA_RX 2 /* RX direction for DMA */
148 /* API for DMA addressing capability */
149 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
151 /* map/unmap physical to virtual I/O */
152 #define REG_MAP(pa, size) hndrte_reg_map(pa, size)
153 #define REG_UNMAP(va) hndrte_reg_unmap(va)
155 /* map/unmap shared (dma-able) memory */
156 #define DMA_MAP(osh, va, size, direction, lb, dmah) ((dmaaddr_t)hndrte_dma_map(va, size))
157 #define DMA_UNMAP(osh, pa, size, direction, p, dmah) hndrte_dma_unmap((uint32)pa, size)
159 /* shared (dma-able) memory access macros */
160 #define R_SM(r) *(r)
161 #define W_SM(r, v) (*(r) = (v))
162 #define BZERO_SM(r, len) memset((r), '\0', (len))
164 /* assert & debugging */
165 #define assfail hndrte_assfail
167 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
168 #define PKTBUFSZ (MAXPKTBUFSZ - LBUFSZ)
170 /* packet primitives */
171 #define PKTGET(osh, len, send) (void *)osl_pktget((osh), (len))
172 #define PKTFREE(osh, p, send) osl_pktfree((osh), (p), (send))
173 #define PKTDATA(osh, lb) LBP(lb)->data
174 #define PKTLEN(osh, lb) LBP(lb)->len
175 #define PKTHEADROOM(osh, lb) (LBP(lb)->data - LBP(lb)->head)
176 #define PKTTAILROOM(osh, lb) (LBP(lb)->end - (LBP(lb)->data + LBP(lb)->len))
177 #define PKTNEXT(osh, lb) (LBP(lb)->next)
178 #define PKTSETNEXT(osh, lb, x) (LBP(lb)->next = LBP(x))
179 #define PKTSETLEN(osh, lb, len) lb_setlen(LBP(lb), (len))
180 #define PKTPUSH(osh, lb, bytes) lb_push(LBP(lb), (bytes))
181 #define PKTPULL(osh, lb, bytes) lb_pull(LBP(lb), (bytes))
182 #define PKTDUP(osh, p) osl_pktdup((osh), (p))
183 #define PKTTAG(lb) ((void *)((LBP(lb))->pkttag))
184 #define PKTLINK(lb) (LBP(lb)->link)
185 #define PKTSETLINK(lb, x) (LBP(lb)->link = LBP(x))
186 #define PKTPRIO(lb) lb_pri(LBP(lb))
187 #define PKTSETPRIO(lb, x) lb_setpri(LBP(lb), (x))
188 #define PKTSHARED(lb) (lb_isclone(LBP(lb)) || LBP(lb)->refcnt > 1)
189 #define PKTALLOCED(osh) ((osl_t *)osh)->pktalloced
190 #define PKTSUMNEEDED(lb) lb_sumneeded(LBP(lb))
191 #define PKTSETSUMNEEDED(lb, x) lb_setsumneeded(LBP(lb), (x))
192 #define PKTSUMGOOD(lb) lb_sumgood(LBP(lb))
193 #define PKTSETSUMGOOD(lb, x) lb_setsumgood(LBP(lb), (x))
194 #define PKTMSGTRACE(lb) lb_msgtrace(LBP(lb))
195 #define PKTSETMSGTRACE(lb, x) lb_setmsgtrace(LBP(lb), (x))
196 #define PKTDATAOFFSET(lb) lb_dataoff(LBP(lb))
197 #define PKTSETDATAOFFSET(lb, dataOff) lb_setdataoff(LBP(lb), dataOff)
198 #define PKTSETPOOL(osh, lb, x, y) lb_setpool(LBP(lb), (x), (y))
199 #define PKTPOOL(osh, lb) lb_pool(LBP(lb))
200 #ifdef BCMDBG_POOL
201 #define PKTPOOLSTATE(lb) lb_poolstate(LBP(lb))
202 #define PKTPOOLSETSTATE(lb, s) lb_setpoolstate(LBP(lb), s)
203 #endif
205 #define BCM_DMAPAD
206 #define PKTDMAPAD(osh, lb) (LBP(lb)->dmapad)
207 #define PKTSETDMAPAD(osh, lb, pad) (LBP(lb)->dmapad = pad)
210 #ifdef BCMDBG_PKT /* pkt logging for debugging */
211 #define PKTLIST_DUMP(osh, buf) (void)buf
212 #else /* BCMDBG_PKT */
213 #define PKTLIST_DUMP(osh, buf)
214 #endif /* BCMDBG_PKT */
216 #define PKTFRMNATIVE(osh, lb) ((void *)(osl_pktfrmnative((osh), (lb))))
217 #define PKTTONATIVE(osh, p) ((struct lbuf *)(osl_pkttonative((osh), (p))))
220 extern void * osl_pktfrmnative(osl_t *osh, struct lbuf *lb);
221 extern struct lbuf * osl_pkttonative(osl_t *osh, void *p);
222 extern void * osl_pktget(osl_t *osh, uint len);
223 extern void osl_pktfree(osl_t *osh, void *p, bool send);
224 extern void * osl_pktdup(osl_t *osh, void *p);
225 extern void * osl_pktclone(osl_t *osh, void *p, int offset, int len);
227 /* get system up time in milliseconds */
228 #define OSL_SYSUPTIME() (hndrte_time())
230 /* Kernel: File Operations: start */
231 extern void * osl_os_open_image(char * filename);
232 extern int osl_os_get_image_block(char * buf, int len, void * image);
233 extern void osl_os_close_image(void * image);
234 /* Kernel: File Operations: end */
236 /* free memory available in pool */
237 #define OSL_MEM_AVAIL() (hndrte_memavail())
239 #endif /* _hndrte_osl_h_ */