• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Misc system wide definitions
3  *
4  * Copyright (C) 1999-2013, Broadcom Corporation
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 of
16  * the license of that module.  An independent module is a module which is not
17  * 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  * $Id: bcmdefs.h 416231 2013-08-02 07:38:34Z $
25  */
26 
27 #ifndef	_bcmdefs_h_
28 #define	_bcmdefs_h_
29 
30 /*
31  * One doesn't need to include this file explicitly, gets included automatically if
32  * typedefs.h is included.
33  */
34 
35 /* Use BCM_REFERENCE to suppress warnings about intentionally-unused function
36  * arguments or local variables.
37  */
38 #define BCM_REFERENCE(data)	((void)(data))
39 
40 /* Compile-time assert can be used in place of ASSERT if the expression evaluates
41  * to a constant at compile time.
42  */
43 #define STATIC_ASSERT(expr) { \
44 	/* Make sure the expression is constant. */ \
45 	typedef enum { _STATIC_ASSERT_NOT_CONSTANT = (expr) } _static_assert_e; \
46 	/* Make sure the expression is true. */ \
47 	typedef char STATIC_ASSERT_FAIL[(expr) ? 1 : -1]; \
48 }
49 
50 /* Reclaiming text and data :
51  * The following macros specify special linker sections that can be reclaimed
52  * after a system is considered 'up'.
53  * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN,
54  * as in most cases, the attach function calls the detach function to clean up on error).
55  */
56 
57 #define bcmreclaimed 		0
58 #define _data	_data
59 #define _fn	_fn
60 #define BCMPREATTACHDATA(_data)	_data
61 #define BCMPREATTACHFN(_fn)	_fn
62 #define _data	_data
63 #define _fn		_fn
64 #define _fn	_fn
65 #define	BCMNMIATTACHFN(_fn)	_fn
66 #define	BCMNMIATTACHDATA(_data)	_data
67 #define CONST	const
68 
69 /* Do not put BCM47XX and __ARM_ARCH_7A__ to the same line.
70  * DHD build has problem because the BCM47XX will be excluded in DHD release.
71  */
72 #undef BCM47XX_CA9
73 #ifdef __ARM_ARCH_7A__
74 #define BCM47XX_CA9
75 #endif /* __ARM_ARCH_7A__ */
76 #ifndef BCMFASTPATH
77 #if defined(BCM47XX_CA9)
78 #define BCMFASTPATH		__attribute__ ((__section__ (".text.fastpath")))
79 #define BCMFASTPATH_HOST	__attribute__ ((__section__ (".text.fastpath_host")))
80 #else
81 #define BCMFASTPATH
82 #define BCMFASTPATH_HOST
83 #endif
84 #endif /* BCMFASTPATH */
85 
86 
87 /* Put some library data/code into ROM to reduce RAM requirements */
88 #define _data	_data
89 #define BCMROMDAT_NAME(_data)	_data
90 #define _fn		_fn
91 #define _fn	_fn
92 #define STATIC	static
93 #define BCMROMDAT_ARYSIZ(data)	ARRAYSIZE(data)
94 #define BCMROMDAT_SIZEOF(data)	sizeof(data)
95 #define BCMROMDAT_APATCH(data)
96 #define BCMROMDAT_SPATCH(data)
97 
98 /* Bus types */
99 #define	SI_BUS			0	/* SOC Interconnect */
100 #define	PCI_BUS			1	/* PCI target */
101 #define	PCMCIA_BUS		2	/* PCMCIA target */
102 #define SDIO_BUS		3	/* SDIO target */
103 #define JTAG_BUS		4	/* JTAG */
104 #define USB_BUS			5	/* USB (does not support R/W REG) */
105 #define SPI_BUS			6	/* gSPI target */
106 #define RPC_BUS			7	/* RPC target */
107 
108 /* Allows size optimization for single-bus image */
109 #ifdef BCMBUSTYPE
110 #define BUSTYPE(bus) 	(BCMBUSTYPE)
111 #else
112 #define BUSTYPE(bus) 	(bus)
113 #endif
114 
115 /* Allows size optimization for single-backplane image */
116 #ifdef BCMCHIPTYPE
117 #define CHIPTYPE(bus) 	(BCMCHIPTYPE)
118 #else
119 #define CHIPTYPE(bus) 	(bus)
120 #endif
121 
122 
123 /* Allows size optimization for SPROM support */
124 #if defined(BCMSPROMBUS)
125 #define SPROMBUS	(BCMSPROMBUS)
126 #elif defined(SI_PCMCIA_SROM)
127 #define SPROMBUS	(PCMCIA_BUS)
128 #else
129 #define SPROMBUS	(PCI_BUS)
130 #endif
131 
132 /* Allows size optimization for single-chip image */
133 #ifdef BCMCHIPID
134 #define CHIPID(chip)	(BCMCHIPID)
135 #else
136 #define CHIPID(chip)	(chip)
137 #endif
138 
139 #ifdef BCMCHIPREV
140 #define CHIPREV(rev)	(BCMCHIPREV)
141 #else
142 #define CHIPREV(rev)	(rev)
143 #endif
144 
145 /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
146 #define DMADDR_MASK_32 0x0		/* Address mask for 32-bits */
147 #define DMADDR_MASK_30 0xc0000000	/* Address mask for 30-bits */
148 #define DMADDR_MASK_0  0xffffffff	/* Address mask for 0-bits (hi-part) */
149 
150 #define	DMADDRWIDTH_30  30 /* 30-bit addressing capability */
151 #define	DMADDRWIDTH_32  32 /* 32-bit addressing capability */
152 #define	DMADDRWIDTH_63  63 /* 64-bit addressing capability */
153 #define	DMADDRWIDTH_64  64 /* 64-bit addressing capability */
154 
155 #ifdef BCMDMA64OSL
156 typedef struct {
157 	uint32 loaddr;
158 	uint32 hiaddr;
159 } dma64addr_t;
160 
161 typedef dma64addr_t dmaaddr_t;
162 #define PHYSADDRHI(_pa) ((_pa).hiaddr)
163 #define PHYSADDRHISET(_pa, _val) \
164 	do { \
165 		(_pa).hiaddr = (_val);		\
166 	} while (0)
167 #define PHYSADDRLO(_pa) ((_pa).loaddr)
168 #define PHYSADDRLOSET(_pa, _val) \
169 	do { \
170 		(_pa).loaddr = (_val);		\
171 	} while (0)
172 
173 #else
174 typedef unsigned long dmaaddr_t;
175 #define PHYSADDRHI(_pa) (0)
176 #define PHYSADDRHISET(_pa, _val)
177 #define PHYSADDRLO(_pa) ((_pa))
178 #define PHYSADDRLOSET(_pa, _val) \
179 	do { \
180 		(_pa) = (_val);			\
181 	} while (0)
182 #endif /* BCMDMA64OSL */
183 
184 /* One physical DMA segment */
185 typedef struct  {
186 	dmaaddr_t addr;
187 	uint32	  length;
188 } hnddma_seg_t;
189 
190 #define MAX_DMA_SEGS 4
191 
192 
193 typedef struct {
194 	void *oshdmah; /* Opaque handle for OSL to store its information */
195 	uint origsize; /* Size of the virtual packet */
196 	uint nsegs;
197 	hnddma_seg_t segs[MAX_DMA_SEGS];
198 } hnddma_seg_map_t;
199 
200 
201 /* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF).
202  * By doing, we avoid the need  to allocate an extra buffer for the header when bridging to WL.
203  * There is a compile time check in wlc.c which ensure that this value is at least as big
204  * as TXOFF. This value is used in dma_rxfill (hnddma.c).
205  */
206 
207 #if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY)
208 /* add 40 bytes to allow for extra RPC header and info  */
209 #define BCMEXTRAHDROOM 260
210 #else /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
211 #if defined(BCM47XX_CA9)
212 #define BCMEXTRAHDROOM 224
213 #else
214 #define BCMEXTRAHDROOM 204
215 #endif /* linux && BCM47XX_CA9 */
216 #endif /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
217 
218 /* Packet alignment for most efficient SDIO (can change based on platform) */
219 #ifndef SDALIGN
220 #define SDALIGN	32
221 #endif
222 
223 /* Headroom required for dongle-to-host communication.  Packets allocated
224  * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
225  * leave this much room in front for low-level message headers which may
226  * be needed to get across the dongle bus to the host.  (These messages
227  * don't go over the network, so room for the full WL header above would
228  * be a waste.).
229 */
230 #define BCMDONGLEHDRSZ 12
231 #define BCMDONGLEPADSZ 16
232 
233 #define BCMDONGLEOVERHEAD	(BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
234 
235 
236 #if defined(NO_BCMDBG_ASSERT)
237 # undef BCMDBG_ASSERT
238 # undef BCMASSERT_LOG
239 #endif
240 
241 #if defined(BCMASSERT_LOG)
242 #define BCMASSERT_SUPPORT
243 #endif
244 
245 /* Macros for doing definition and get/set of bitfields
246  * Usage example, e.g. a three-bit field (bits 4-6):
247  *    #define <NAME>_M	BITFIELD_MASK(3)
248  *    #define <NAME>_S	4
249  * ...
250  *    regval = R_REG(osh, &regs->regfoo);
251  *    field = GFIELD(regval, <NAME>);
252  *    regval = SFIELD(regval, <NAME>, 1);
253  *    W_REG(osh, &regs->regfoo, regval);
254  */
255 #define BITFIELD_MASK(width) \
256 		(((unsigned)1 << (width)) - 1)
257 #define GFIELD(val, field) \
258 		(((val) >> field ## _S) & field ## _M)
259 #define SFIELD(val, field, bits) \
260 		(((val) & (~(field ## _M << field ## _S))) | \
261 		 ((unsigned)(bits) << field ## _S))
262 
263 /* define BCMSMALL to remove misc features for memory-constrained environments */
264 #ifdef BCMSMALL
265 #undef	BCMSPACE
266 #define bcmspace	FALSE	/* if (bcmspace) code is discarded */
267 #else
268 #define	BCMSPACE
269 #define bcmspace	TRUE	/* if (bcmspace) code is retained */
270 #endif
271 
272 /* Max. nvram variable table size */
273 #define	MAXSZ_NVRAM_VARS	4096
274 
275 
276 /* Max size for reclaimable NVRAM array */
277 #ifdef DL_NVRAM
278 #define NVRAM_ARRAY_MAXSIZE	DL_NVRAM
279 #else
280 #define NVRAM_ARRAY_MAXSIZE	MAXSZ_NVRAM_VARS
281 #endif /* DL_NVRAM */
282 
283 #ifdef BCMUSBDEV_ENABLED
284 extern uint32 gFWID;
285 #endif
286 
287 #endif /* _bcmdefs_h_ */
288