Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / include / bcmdefs.h
blobf506af988cfd4b433d21f4145680a1d027041d63
1 /*
2 * Misc system wide definitions
4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id: bcmdefs.h,v 13.69.10.2 2010-10-05 00:46:12 Exp $
21 #ifndef _bcmdefs_h_
22 #define _bcmdefs_h_
25 * One doesn't need to include this file explicitly, gets included automatically if
26 * typedefs.h is included.
29 /* Use BCM_REFERENCE to suppress warnings about intentionally-unused function
30 * arguments or local variables.
32 #define BCM_REFERENCE(data) ((void)data)
34 /* Reclaiming text and data :
35 * The following macros specify special linker sections that can be reclaimed
36 * after a system is considered 'up'.
37 * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN,
38 * as in most cases, the attach function calls the detach function to clean up on error).
40 #ifdef DONGLEBUILD
42 extern bool bcmreclaimed;
44 #define BCMATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data
45 #define BCMATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
47 #define BCMPREATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data
48 #define BCMPREATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
50 #if defined(BCMRECLAIM)
51 #define BCMINITDATA(_data) __attribute__ ((__section__ (".dataini1." #_data))) _data
52 #define BCMINITFN(_fn) __attribute__ ((__section__ (".textini1." #_fn), noinline)) _fn
53 #define CONST
54 #else
55 #define BCMINITDATA(_data) _data
56 #define BCMINITFN(_fn) _fn
57 #define CONST const
58 #endif
60 /* Non-manufacture or internal attach function/dat */
61 #if !defined(WLTEST)
62 #define BCMNMIATTACHFN(_fn) BCMATTACHFN(_fn)
63 #define BCMNMIATTACHDATA(_data) BCMATTACHDATA(_data)
64 #else
65 #define BCMNMIATTACHFN(_fn) _fn
66 #define BCMNMIATTACHDATA(_data) _data
67 #endif
69 #define BCMUNINITFN(_fn) _fn
71 #define BCMFASTPATH
73 #ifdef DONGLEOVERLAYS
74 #define BCMOVERLAY0DATA(_sym) __attribute__ ((__section__ (".r0overlay." #_sym))) _sym
75 #define BCMOVERLAY0FN(_fn) __attribute__ ((__section__ (".r0overlay." #_fn))) _fn
76 #define BCMOVERLAY1DATA(_sym) __attribute__ ((__section__ (".r1overlay." #_sym))) _sym
77 #define BCMOVERLAY1FN(_fn) __attribute__ ((__section__ (".r1overlay." #_fn))) _fn
78 #define BCMOVERLAYERRFN(_fn) __attribute__ ((__section__ (".overlayerr." #_fn))) _fn
79 #else
80 #define BCMOVERLAY0DATA(_sym) _sym
81 #define BCMOVERLAY0FN(_fn) _fn
82 #define BCMOVERLAY1DATA(_sym) _sym
83 #define BCMOVERLAY1FN(_fn) _fn
84 #define BCMOVERLAYERRFN(_fn) _fn
85 #endif /* DONGLEOVERLAYS */
87 #else /* DONGLEBUILD */
89 #define bcmreclaimed 0
90 #define BCMATTACHDATA(_data) _data
91 #define BCMATTACHFN(_fn) _fn
92 #define BCMPREATTACHDATA(_data) _data
93 #define BCMPREATTACHFN(_fn) _fn
94 #define BCMINITDATA(_data) _data
95 #define BCMINITFN(_fn) _fn
96 #define BCMUNINITFN(_fn) _fn
97 #define BCMNMIATTACHFN(_fn) _fn
98 #define BCMNMIATTACHDATA(_data) _data
99 #define BCMOVERLAY0DATA(_sym) _sym
100 #define BCMOVERLAY0FN(_fn) _fn
101 #define BCMOVERLAY1DATA(_sym) _sym
102 #define BCMOVERLAY1FN(_fn) _fn
103 #define BCMOVERLAYERRFN(_fn) _fn
104 #define CONST const
105 #ifdef mips
106 #define BCMFASTPATH __attribute__ ((__section__(".text.fastpath")))
107 #else
108 #define BCMFASTPATH
109 #endif
111 #endif /* DONGLEBUILD */
113 #if defined(BCMROMBUILD)
114 typedef struct {
115 uint16 esiz;
116 uint16 cnt;
117 void *addr;
118 } bcmromdat_patch_t;
119 #endif
121 /* Put some library data/code into ROM to reduce RAM requirements */
122 #if defined(BCMROMBUILD)
123 #include <bcmjmptbl.h>
124 #define STATIC static
125 #else /* !BCMROMBUILD */
126 #define BCMROMDATA(_data) _data
127 #define BCMROMDAT_NAME(_data) _data
128 #define BCMROMFN(_fn) _fn
129 #define BCMROMFN_NAME(_fn) _fn
130 #define STATIC static
131 #define BCMROMDAT_ARYSIZ(data) ARRAYSIZE(data)
132 #define BCMROMDAT_SIZEOF(data) sizeof(data)
133 #define BCMROMDAT_APATCH(data)
134 #define BCMROMDAT_SPATCH(data)
135 #endif /* !BCMROMBUILD */
137 /* overlay function tagging */
138 #ifdef DONGLEBUILD
139 #ifdef DONGLEOVERLAYS
140 /* force a func to be inline if it's only accessed by overlays and ATTACH code */
141 #define OVERLAY_INLINE __attribute__ ((always_inline))
142 #define OSTATIC
143 #define BCMOVERLAYDATA(_ovly, _sym) \
144 __attribute__ ((aligned(4), __section__ (".r" #_ovly "overlay." #_sym))) _sym
145 #define BCMOVERLAYFN(_ovly, _fn) \
146 __attribute__ ((__section__ (".r" #_ovly "overlay." #_fn))) _fn
147 #define BCMOVERLAYERRFN(_fn) \
148 __attribute__ ((__section__ (".overlayerr." #_fn))) _fn
149 #define BCMROMOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym)
150 #define BCMROMOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn)
151 #define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym)
152 #define BCMATTACHOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn)
153 #define BCMINITOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym)
154 #define BCMINITOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn)
155 #define BCMUNINITOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn)
156 #else
157 #define OVERLAY_INLINE
158 #define OSTATIC static
159 #define BCMOVERLAYDATA(_ovly, _sym) _sym
160 #define BCMOVERLAYFN(_ovly, _fn) _fn
161 #define BCMOVERLAYERRFN(_fn) _fn
162 /* revert to standard definitions for BCMATTACH* and BCMINIT* if not overlay build */
163 #define BCMROMOVERLAYDATA(_ovly, _data) BCMROMDATA(_data)
164 #define BCMROMOVERLAYFN(_ovly, _fn) BCMROMFN(_fn)
165 #define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMATTACHDATA(_sym)
166 #define BCMATTACHOVERLAYFN(_ovly, _fn) BCMATTACHFN(_fn)
167 #define BCMINITOVERLAYDATA(_ovly, _sym) BCMINITDATA(_sym)
168 #define BCMINITOVERLAYFN(_ovly, _fn) BCMINITFN(_fn)
169 #define BCMUNINITOVERLAYFN(_ovly, _fn) BCMUNINITFN(_fn)
170 #endif /* DONGLEOVERLAYS */
172 #else
174 #define OVERLAY_INLINE
175 #define OSTATIC static
176 #define BCMOVERLAYDATA(_ovly, _sym) _sym
177 #define BCMOVERLAYFN(_ovly, _fn) _fn
178 #define BCMOVERLAYERRFN(_fn) _fn
179 #define BCMROMOVERLAYDATA(_ovly, _data) BCMROMDATA(_data)
180 #define BCMROMOVERLAYFN(_ovly, _fn) BCMROMFN(_fn)
181 #define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMATTACHDATA(_sym)
182 #define BCMATTACHOVERLAYFN(_ovly, _fn) BCMATTACHFN(_fn)
183 #define BCMINITOVERLAYDATA(_ovly, _sym) BCMINITDATA(_sym)
184 #define BCMINITOVERLAYFN(_ovly, _fn) BCMINITFN(_fn)
185 #define BCMUNINITOVERLAYFN(_ovly, _fn) BCMUNINITFN(_fn)
187 #endif /* DONGLEBUILD */
189 /* Bus types */
190 #define SI_BUS 0 /* SOC Interconnect */
191 #define PCI_BUS 1 /* PCI target */
192 #define PCMCIA_BUS 2 /* PCMCIA target */
193 #define SDIO_BUS 3 /* SDIO target */
194 #define JTAG_BUS 4 /* JTAG */
195 #define USB_BUS 5 /* USB (does not support R/W REG) */
196 #define SPI_BUS 6 /* gSPI target */
197 #define RPC_BUS 7 /* RPC target */
199 /* Allows size optimization for single-bus image */
200 #ifdef BCMBUSTYPE
201 #define BUSTYPE(bus) (BCMBUSTYPE)
202 #else
203 #define BUSTYPE(bus) (bus)
204 #endif
206 /* Allows size optimization for single-backplane image */
207 #ifdef BCMCHIPTYPE
208 #define CHIPTYPE(bus) (BCMCHIPTYPE)
209 #else
210 #define CHIPTYPE(bus) (bus)
211 #endif
214 /* Allows size optimization for SPROM support */
215 #if defined(BCMSPROMBUS)
216 #define SPROMBUS (BCMSPROMBUS)
217 #elif defined(SI_PCMCIA_SROM)
218 #define SPROMBUS (PCMCIA_BUS)
219 #else
220 #define SPROMBUS (PCI_BUS)
221 #endif
223 /* Allows size optimization for single-chip image */
224 #ifdef BCMCHIPID
225 #define CHIPID(chip) (BCMCHIPID)
226 #else
227 #define CHIPID(chip) (chip)
228 #endif
230 #ifdef BCMCHIPREV
231 #define CHIPREV(rev) (BCMCHIPREV)
232 #else
233 #define CHIPREV(rev) (rev)
234 #endif
236 /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
237 #define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */
238 #define DMADDR_MASK_30 0xc0000000 /* Address mask for 30-bits */
239 #define DMADDR_MASK_0 0xffffffff /* Address mask for 0-bits (hi-part) */
241 #define DMADDRWIDTH_30 30 /* 30-bit addressing capability */
242 #define DMADDRWIDTH_32 32 /* 32-bit addressing capability */
243 #define DMADDRWIDTH_63 63 /* 64-bit addressing capability */
244 #define DMADDRWIDTH_64 64 /* 64-bit addressing capability */
246 #ifdef BCMDMA64OSL
247 typedef struct {
248 uint32 loaddr;
249 uint32 hiaddr;
250 } dma64addr_t;
252 typedef dma64addr_t dmaaddr_t;
253 #define PHYSADDRHI(_pa) ((_pa).hiaddr)
254 #define PHYSADDRHISET(_pa, _val) \
255 do { \
256 (_pa).hiaddr = (_val); \
257 } while (0)
258 #define PHYSADDRLO(_pa) ((_pa).loaddr)
259 #define PHYSADDRLOSET(_pa, _val) \
260 do { \
261 (_pa).loaddr = (_val); \
262 } while (0)
264 #else
265 typedef unsigned long dmaaddr_t;
266 #define PHYSADDRHI(_pa) (0)
267 #define PHYSADDRHISET(_pa, _val)
268 #define PHYSADDRLO(_pa) ((_pa))
269 #define PHYSADDRLOSET(_pa, _val) \
270 do { \
271 (_pa) = (_val); \
272 } while (0)
273 #endif /* BCMDMA64OSL */
275 /* One physical DMA segment */
276 typedef struct {
277 dmaaddr_t addr;
278 uint32 length;
279 } hnddma_seg_t;
281 #if defined(MACOSX)
282 /* In MacOS, the OS API may return large number of segments. Setting this number lower
283 * will result in failure of dma map
285 #define MAX_DMA_SEGS 8
286 #elif defined(__NetBSD__)
287 #define MAX_DMA_SEGS 16
288 #else
289 #define MAX_DMA_SEGS 4
290 #endif
293 typedef struct {
294 void *oshdmah; /* Opaque handle for OSL to store its information */
295 uint origsize; /* Size of the virtual packet */
296 uint nsegs;
297 hnddma_seg_t segs[MAX_DMA_SEGS];
298 } hnddma_seg_map_t;
301 /* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF).
302 * By doing, we avoid the need to allocate an extra buffer for the header when bridging to WL.
303 * There is a compile time check in wlc.c which ensure that this value is at least as big
304 * as TXOFF. This value is used in dma_rxfill (hnddma.c).
307 #if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY)
308 /* add 40 bytes to allow for extra RPC header and info */
309 #define BCMEXTRAHDROOM 220
310 #else /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
311 #ifdef CTFMAP
312 #define BCMEXTRAHDROOM 176
313 #else /* CTFMAP */
314 #define BCMEXTRAHDROOM 172
315 #endif /* CTFMAP */
316 #endif /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
318 /* Packet alignment for most efficient SDIO (can change based on platform) */
319 #ifndef SDALIGN
320 #define SDALIGN 32
321 #endif
323 /* Headroom required for dongle-to-host communication. Packets allocated
324 * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
325 * leave this much room in front for low-level message headers which may
326 * be needed to get across the dongle bus to the host. (These messages
327 * don't go over the network, so room for the full WL header above would
328 * be a waste.).
330 #define BCMDONGLEHDRSZ 12
331 #define BCMDONGLEPADSZ 16
333 #define BCMDONGLEOVERHEAD (BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
335 #ifdef BCMDBG
337 #ifndef BCMDBG_ERR
338 #define BCMDBG_ERR
339 #endif /* BCMDBG_ERR */
341 #ifndef BCMDBG_ASSERT
342 #define BCMDBG_ASSERT
343 #endif /* BCMDBG_ASSERT */
345 #endif /* BCMDBG */
347 #if defined(BCMDBG_ASSERT)
348 #define BCMASSERT_SUPPORT
349 #endif
351 /* Macros for doing definition and get/set of bitfields
352 * Usage example, e.g. a three-bit field (bits 4-6):
353 * #define <NAME>_M BITFIELD_MASK(3)
354 * #define <NAME>_S 4
355 * ...
356 * regval = R_REG(osh, &regs->regfoo);
357 * field = GFIELD(regval, <NAME>);
358 * regval = SFIELD(regval, <NAME>, 1);
359 * W_REG(osh, &regs->regfoo, regval);
361 #define BITFIELD_MASK(width) \
362 (((unsigned)1 << (width)) - 1)
363 #define GFIELD(val, field) \
364 (((val) >> field ## _S) & field ## _M)
365 #define SFIELD(val, field, bits) \
366 (((val) & (~(field ## _M << field ## _S))) | \
367 ((unsigned)(bits) << field ## _S))
369 /* define BCMSMALL to remove misc features for memory-constrained environments */
370 #ifdef BCMSMALL
371 #undef BCMSPACE
372 #define bcmspace FALSE /* if (bcmspace) code is discarded */
373 #else
374 #define BCMSPACE
375 #define bcmspace TRUE /* if (bcmspace) code is retained */
376 #endif
378 /* Max. nvram variable table size */
379 #define MAXSZ_NVRAM_VARS 4096
381 #define LOCATOR_EXTERN static
383 #endif /* _bcmdefs_h_ */