Broadcom et driver updates from SDK 5.10.140.0
[tomato.git] / release / src-rt / include / bcmdefs.h
bloba5e95c4e60337c1ec29dc74a16de17c07be69ef0
1 /*
2 * Misc system wide definitions
4 * Copyright (C) 2009, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: bcmdefs.h,v 13.43.2.12 2009/03/12 21:32:38 Exp $
15 #ifndef _bcmdefs_h_
16 #define _bcmdefs_h_
19 * One doesn't need to include this file explicitly, gets included automatically if
20 * typedefs.h is included.
23 /* Reclaiming text and data :
24 * The following macros specify special linker sections that can be reclaimed
25 * after a system is considered 'up'.
29 #ifdef DONGLEBUILD
31 extern bool bcmreclaimed;
33 #define BCMATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data
34 #define BCMATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn))) _fn
36 #if defined(BCMRECLAIM)
37 #define BCMINITDATA(_data) __attribute__ ((__section__ (".dataini1." #_data))) _data
38 #define BCMINITFN(_fn) __attribute__ ((__section__ (".textini1." #_fn))) _fn
39 #define CONST
40 #else
41 #define BCMINITDATA(_data) _data
42 #define BCMINITFN(_fn) _fn
43 #define CONST const
44 #endif
46 /* Non-manufacture or internal attach function/dat */
47 #if !defined(WLTEST)
48 #define BCMNMIATTACHFN(_fn) BCMATTACHFN(_fn)
49 #define BCMNMIATTACHDATA(_data) BCMATTACHDATA(_data)
50 #else
51 #define BCMNMIATTACHFN(_fn) _fn
52 #define BCMNMIATTACHDATA(_data) _data
53 #endif
55 #define BCMUNINITFN(_fn) _fn
57 #define BCMFASTPATH
59 #else /* DONGLEBUILD */
61 #define bcmreclaimed 0
62 #define BCMATTACHDATA(_data) _data
63 #define BCMATTACHFN(_fn) _fn
64 #define BCMINITDATA(_data) _data
65 #define BCMINITFN(_fn) _fn
66 #define BCMUNINITFN(_fn) _fn
67 #define BCMNMIATTACHFN(_fn) _fn
68 #define BCMNMIATTACHDATA(_data) _data
69 #define CONST const
70 #ifdef mips
71 #define BCMFASTPATH __attribute__ ((__section__(".text.fastpath")))
72 #else
73 #define BCMFASTPATH
74 #endif
76 #endif /* DONGLEBUILD */
78 /* Put some library data/code into ROM to reduce RAM requirements */
79 #define BCMROMDATA(_data) _data
80 #define BCMROMFN(_fn) _fn
82 /* Bus types */
83 #define SI_BUS 0 /* SOC Interconnenct */
84 #define PCI_BUS 1 /* PCI target */
85 #define PCMCIA_BUS 2 /* PCMCIA target */
86 #define SDIO_BUS 3 /* SDIO target */
87 #define JTAG_BUS 4 /* JTAG */
88 #define USB_BUS 5 /* USB (does not support R/W REG) */
89 #define SPI_BUS 6 /* gSPI target */
90 #define RPC_BUS 7 /* RPC target */
92 /* Allows size optimization for single-bus image */
93 #ifdef BCMBUSTYPE
94 #define BUSTYPE(bus) (BCMBUSTYPE)
95 #else
96 #define BUSTYPE(bus) (bus)
97 #endif
99 /* Allows size optimization for single-backplane image */
100 #ifdef BCMCHIPTYPE
101 #define CHIPTYPE(bus) (BCMCHIPTYPE)
102 #else
103 #define CHIPTYPE(bus) (bus)
104 #endif
107 /* Allows size optimization for SPROM support */
108 #if defined(BCMSPROMBUS)
109 #define SPROMBUS (BCMSPROMBUS)
110 #elif defined(SI_PCMCIA_SROM)
111 #define SPROMBUS (PCMCIA_BUS)
112 #else
113 #define SPROMBUS (PCI_BUS)
114 #endif
116 /* Allows size optimization for single-chip image */
117 #ifdef BCMCHIPID
118 #define CHIPID(chip) (BCMCHIPID)
119 #else
120 #define CHIPID(chip) (chip)
121 #endif
123 /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
124 #define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */
125 #define DMADDR_MASK_30 0xc0000000 /* Address mask for 30-bits */
126 #define DMADDR_MASK_0 0xffffffff /* Address mask for 0-bits (hi-part) */
128 #define DMADDRWIDTH_30 30 /* 30-bit addressing capability */
129 #define DMADDRWIDTH_32 32 /* 32-bit addressing capability */
130 #define DMADDRWIDTH_63 63 /* 64-bit addressing capability */
131 #define DMADDRWIDTH_64 64 /* 64-bit addressing capability */
133 #ifdef BCMDMA64OSL
134 typedef struct {
135 uint32 loaddr;
136 uint32 hiaddr;
137 } dma64addr_t;
139 typedef dma64addr_t dmaaddr_t;
140 #define PHYSADDRHI(_pa) ((_pa).hiaddr)
141 #define PHYSADDRHISET(_pa, _val) \
142 do { \
143 (_pa).hiaddr = (_val); \
144 } while (0)
145 #define PHYSADDRLO(_pa) ((_pa).loaddr)
146 #define PHYSADDRLOSET(_pa, _val) \
147 do { \
148 (_pa).loaddr = (_val); \
149 } while (0)
151 #else
152 typedef unsigned long dmaaddr_t;
153 #define PHYSADDRHI(_pa) (0)
154 #define PHYSADDRHISET(_pa, _val)
155 #define PHYSADDRLO(_pa) ((_pa))
156 #define PHYSADDRLOSET(_pa, _val) \
157 do { \
158 (_pa) = (_val); \
159 } while (0)
160 #endif /* BCMDMA64OSL */
162 /* One physical DMA segment */
163 typedef struct {
164 dmaaddr_t addr;
165 uint32 length;
166 } hnddma_seg_t;
168 #if defined(MACOSX)
169 /* In MacOS, the OS API may return large number of segments. Setting this number lower
170 * will result in failure of dma map
172 #define MAX_DMA_SEGS 8
173 #else
174 #define MAX_DMA_SEGS 4
175 #endif
178 typedef struct {
179 void *oshdmah; /* Opaque handle for OSL to store its information */
180 uint origsize; /* Size of the virtual packet */
181 uint nsegs;
182 hnddma_seg_t segs[MAX_DMA_SEGS];
183 } hnddma_seg_map_t;
185 /* packet headroom necessary to accomodate the largest header in the system, (i.e TXOFF).
186 * By doing, we avoid the need to allocate an extra buffer for the header when bridging to WL.
187 * There is a compile time check in wlc.c which ensure that this value is at least as big
188 * as TXOFF. This value is used in dma_rxfill (hnddma.c).
191 #if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY)
192 #define BCMEXTRAHDROOM 220
193 #else
194 #define BCMEXTRAHDROOM 172
195 #endif
197 /* Headroom required for dongle-to-host communication. Packets allocated
198 * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
199 * leave this much room in front for low-level message headers which may
200 * be needed to get across the dongle bus to the host. (These messages
201 * don't go over the network, so room for the full WL header above would
202 * be a waste.).
204 #ifdef BCMUSBDEV
205 #define BCMDONGLEHDRSZ 0
206 #else
207 #define BCMDONGLEHDRSZ 12
208 #endif
211 #if defined(BCMDBG_ASSERT) || defined(BCMASSERT_LOG)
212 #define BCMASSERT_SUPPORT
213 #endif /* BCMDBG_ASSERT || BCMASSERT_LOG */
215 /* Brett's nifty macros for doing definition and get/set of bitfields
216 * Usage example, e.g. a three-bit field (bits 4-6):
217 * #define <NAME>_M BITFIELD_MASK(3)
218 * #define <NAME>_S 4
219 * ...
220 * regval = R_REG(osh, &regs->regfoo);
221 * field = GFIELD(regval, <NAME>);
222 * regval = SFIELD(regval, <NAME>, 1);
223 * W_REG(osh, &regs->regfoo, regval);
225 #define BITFIELD_MASK(width) \
226 (((unsigned)1 << (width)) - 1)
227 #define GFIELD(val, field) \
228 (((val) >> field ## _S) & field ## _M)
229 #define SFIELD(val, field, bits) \
230 (((val) & (~(field ## _M << field ## _S))) | \
231 ((unsigned)(bits) << field ## _S))
233 /* define BCMSMALL to remove misc features for memory constrained enviroments */
234 #ifdef BCMSMALL
235 #undef BCMSPACE
236 #define bcmspace FALSE /* if (bcmspace) code is discarded */
237 #else
238 #define BCMSPACE
239 #define bcmspace TRUE /* if (bcmspace) code is retained */
240 #endif
242 /* Max. nvram variable table size */
243 #define MAXSZ_NVRAM_VARS 4096
245 /* How the locator reduces its memory footprint without #ifdef'ing
247 * The locator uses the weak external symbol feature of the linker
248 * plus the compiler's ability to place each function in a unique
249 * text section to allow wl_locator.c to provide an alternate, typically
250 * trivial, implementation for many functions.
252 * Many of these routines would normally be static but they must
253 * be external for this technique to work. Instead of placing these function's
254 * prototypes in a module's public header file and inviting an improper public
255 * usage, use the below LOCATOR_EXTERN macro in the module implementation
256 * file, both on the function declaration and definition. This will cause
257 * these functions to be static in all builds except locator builds.
259 * This methodology also allows the optimizer to possibly discard
260 * dead (static) functions in non locator builds as well as provide
261 * more explicit/grep'able documentation of functions used by the
262 * locator in this way.
266 #define LOCATOR_EXTERN static
268 #endif /* _bcmdefs_h_ */