xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/include/bcmdefs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Misc system wide definitions
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2020, Broadcom.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
7*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
8*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
9*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10*4882a593Smuzhiyun  * following added to such license:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
13*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
14*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
15*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
16*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
17*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
18*4882a593Smuzhiyun  * modifications of the software.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Dual:>>
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifndef	_bcmdefs_h_
25*4882a593Smuzhiyun #define	_bcmdefs_h_
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef BCM_FLEX_ARRAY
28*4882a593Smuzhiyun #define BCM_FLEX_ARRAY  (1)
29*4882a593Smuzhiyun #endif /* BCM_FLEX_ARRAY */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun  * One doesn't need to include this file explicitly, gets included automatically if
33*4882a593Smuzhiyun  * typedefs.h is included.
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* Use BCM_REFERENCE to suppress warnings about intentionally-unused function
37*4882a593Smuzhiyun  * arguments or local variables.
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun #define BCM_REFERENCE(data)	((void)(data))
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* Allow for suppressing unused variable warnings. */
42*4882a593Smuzhiyun #ifdef __GNUC__
43*4882a593Smuzhiyun #define UNUSED_VAR     __attribute__ ((unused))
44*4882a593Smuzhiyun #else
45*4882a593Smuzhiyun #define UNUSED_VAR
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* GNU GCC 4.6+ supports selectively turning off a warning.
49*4882a593Smuzhiyun  * Define these diagnostic macros to help suppress cast-qual warning
50*4882a593Smuzhiyun  * until all the work can be done to fix the casting issues.
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun #if (defined(__GNUC__) && defined(STRICT_GCC_WARNINGS) && \
53*4882a593Smuzhiyun 	(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
54*4882a593Smuzhiyun 	defined(__clang__))
55*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST()              \
56*4882a593Smuzhiyun 	_Pragma("GCC diagnostic push")			 \
57*4882a593Smuzhiyun 	_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
58*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_NULL_DEREF()	 \
59*4882a593Smuzhiyun 	_Pragma("GCC diagnostic push")			 \
60*4882a593Smuzhiyun 	_Pragma("GCC diagnostic ignored \"-Wnull-dereference\"")
61*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_POP()                             \
62*4882a593Smuzhiyun 	_Pragma("GCC diagnostic pop")
63*4882a593Smuzhiyun #elif defined(_MSC_VER)
64*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST()              \
65*4882a593Smuzhiyun 	__pragma(warning(push))                          \
66*4882a593Smuzhiyun 	__pragma(warning(disable:4090))
67*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_NULL_DEREF()	 \
68*4882a593Smuzhiyun 	__pragma(warning(push))
69*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_POP()                             \
70*4882a593Smuzhiyun 	__pragma(warning(pop))
71*4882a593Smuzhiyun #else
72*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST()
73*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_NULL_DEREF()
74*4882a593Smuzhiyun #define GCC_DIAGNOSTIC_POP()
75*4882a593Smuzhiyun #endif   /* Diagnostic macros not defined */
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* Macros to allow Coverity modeling contructs in source code */
78*4882a593Smuzhiyun #if defined(__COVERITY__)
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /* Coverity Doc:
81*4882a593Smuzhiyun  * Indicates to the TAINTED_SCALAR checker and the INTEGER_OVERFLOW checker
82*4882a593Smuzhiyun  * that a function taints its argument
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun #define COV_TAINTED_DATA_ARG(arg)  __coverity_tainted_data_argument__(arg)
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /* Coverity Doc:
87*4882a593Smuzhiyun  * Indicates to the TAINTED_SCALAR checker and the INTEGER_OVERFLOW checker
88*4882a593Smuzhiyun  * that a function is a tainted data sink for an argument.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun #define COV_TAINTED_DATA_SINK(arg) __coverity_tainted_data_sink__(arg)
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /* Coverity Doc:
93*4882a593Smuzhiyun  * Models a function that cannot take a negative number as an argument. Used in
94*4882a593Smuzhiyun  * conjunction with other models to indicate that negative arguments are invalid.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun #define COV_NEG_SINK(arg)          __coverity_negative_sink__(arg)
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun #else
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define COV_TAINTED_DATA_ARG(arg)  do { } while (0)
101*4882a593Smuzhiyun #define COV_TAINTED_DATA_SINK(arg) do { } while (0)
102*4882a593Smuzhiyun #define COV_NEG_SINK(arg)          do { } while (0)
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #endif /* __COVERITY__ */
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* Compile-time assert can be used in place of ASSERT if the expression evaluates
107*4882a593Smuzhiyun  * to a constant at compile time.
108*4882a593Smuzhiyun  */
109*4882a593Smuzhiyun #define STATIC_ASSERT(expr) { \
110*4882a593Smuzhiyun 	/* Make sure the expression is constant. */ \
111*4882a593Smuzhiyun 	typedef enum { _STATIC_ASSERT_NOT_CONSTANT = (expr) } _static_assert_e UNUSED_VAR; \
112*4882a593Smuzhiyun 	/* Make sure the expression is true. */ \
113*4882a593Smuzhiyun 	typedef char STATIC_ASSERT_FAIL[(expr) ? 1 : -1] UNUSED_VAR; \
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /* Reclaiming text and data :
117*4882a593Smuzhiyun  * The following macros specify special linker sections that can be reclaimed
118*4882a593Smuzhiyun  * after a system is considered 'up'.
119*4882a593Smuzhiyun  * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN,
120*4882a593Smuzhiyun  * as in most cases, the attach function calls the detach function to clean up on error).
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun #if defined(BCM_RECLAIM)
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun extern bool bcm_reclaimed;
125*4882a593Smuzhiyun extern bool bcm_attach_part_reclaimed;
126*4882a593Smuzhiyun extern bool bcm_preattach_part_reclaimed;
127*4882a593Smuzhiyun extern bool bcm_postattach_part_reclaimed;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define RECLAIMED()			(bcm_reclaimed)
130*4882a593Smuzhiyun #define ATTACH_PART_RECLAIMED()		(bcm_attach_part_reclaimed)
131*4882a593Smuzhiyun #define PREATTACH_PART_RECLAIMED()	(bcm_preattach_part_reclaimed)
132*4882a593Smuzhiyun #define POSTATTACH_PART_RECLAIMED()	(bcm_postattach_part_reclaimed)
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun /* Place _fn/_data symbols in various reclaimed output sections */
135*4882a593Smuzhiyun #define BCMATTACHDATA(_data)	__attribute__ ((__section__ (".dataini2." #_data))) _data
136*4882a593Smuzhiyun #define BCMATTACHFN(_fn)	__attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
137*4882a593Smuzhiyun #define BCMPREATTACHDATA(_data)	__attribute__ ((__section__ (".dataini3." #_data))) _data
138*4882a593Smuzhiyun #define BCMPREATTACHFN(_fn)	__attribute__ ((__section__ (".textini3." #_fn), noinline)) _fn
139*4882a593Smuzhiyun #define BCMPOSTATTACHDATA(_data)	__attribute__ ((__section__ (".dataini5." #_data))) _data
140*4882a593Smuzhiyun #define BCMPOSTATTACHFN(_fn)	__attribute__ ((__section__ (".textini5." #_fn), noinline)) _fn
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /* Relocate attach symbols to save-restore region to increase pre-reclaim heap size. */
143*4882a593Smuzhiyun #define BCM_SRM_ATTACH_DATA(_data)    __attribute__ ((__section__ (".datasrm." #_data))) _data
144*4882a593Smuzhiyun #define BCM_SRM_ATTACH_FN(_fn)        __attribute__ ((__section__ (".textsrm." #_fn), noinline)) _fn
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /* Explicitly place data in .rodata section so it can be write-protected after attach */
147*4882a593Smuzhiyun #define BCMRODATA(_data)	__attribute__ ((__section__ (".shrodata." #_data))) _data
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #ifdef BCMDBG_SR
150*4882a593Smuzhiyun /*
151*4882a593Smuzhiyun  * Don't reclaim so we can compare SR ASM
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun #define BCMPREATTACHDATASR(_data)	_data
154*4882a593Smuzhiyun #define BCMPREATTACHFNSR(_fn)		_fn
155*4882a593Smuzhiyun #define BCMATTACHDATASR(_data)		_data
156*4882a593Smuzhiyun #define BCMATTACHFNSR(_fn)		_fn
157*4882a593Smuzhiyun #else
158*4882a593Smuzhiyun #define BCMPREATTACHDATASR(_data)	BCMPREATTACHDATA(_data)
159*4882a593Smuzhiyun #define BCMPREATTACHFNSR(_fn)		BCMPREATTACHFN(_fn)
160*4882a593Smuzhiyun #define BCMATTACHDATASR(_data)		BCMATTACHDATA(_data)
161*4882a593Smuzhiyun #define BCMATTACHFNSR(_fn)		BCMATTACHFN(_fn)
162*4882a593Smuzhiyun #endif
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #define BCMINITDATA(_data)	_data
165*4882a593Smuzhiyun #define BCMINITFN(_fn)		_fn
166*4882a593Smuzhiyun #ifndef CONST
167*4882a593Smuzhiyun #define CONST	const
168*4882a593Smuzhiyun #endif
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /* Non-manufacture or internal attach function/dat */
171*4882a593Smuzhiyun #if !(defined(WLTEST) || defined(ATE_BUILD))
172*4882a593Smuzhiyun #define	BCMNMIATTACHFN(_fn)	BCMATTACHFN(_fn)
173*4882a593Smuzhiyun #define	BCMNMIATTACHDATA(_data)	BCMATTACHDATA(_data)
174*4882a593Smuzhiyun #else
175*4882a593Smuzhiyun #define	BCMNMIATTACHFN(_fn)	_fn
176*4882a593Smuzhiyun #define	BCMNMIATTACHDATA(_data)	_data
177*4882a593Smuzhiyun #endif	/* WLTEST || ATE_BUILD */
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun #if !defined(ATE_BUILD) && defined(BCM_CISDUMP_NO_RECLAIM)
180*4882a593Smuzhiyun #define	BCMCISDUMPATTACHFN(_fn)		_fn
181*4882a593Smuzhiyun #define	BCMCISDUMPATTACHDATA(_data)	_data
182*4882a593Smuzhiyun #else
183*4882a593Smuzhiyun #define	BCMCISDUMPATTACHFN(_fn)		BCMNMIATTACHFN(_fn)
184*4882a593Smuzhiyun #define	BCMCISDUMPATTACHDATA(_data)	BCMNMIATTACHDATA(_data)
185*4882a593Smuzhiyun #endif /* !ATE_BUILD && BCM_CISDUMP_NO_RECLAIM */
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun /* SROM with OTP support */
188*4882a593Smuzhiyun #if defined(BCMOTPSROM)
189*4882a593Smuzhiyun #define	BCMSROMATTACHFN(_fn)		_fn
190*4882a593Smuzhiyun #define	BCMSROMATTACHDATA(_data)	_data
191*4882a593Smuzhiyun #else
192*4882a593Smuzhiyun #define	BCMSROMATTACHFN(_fn)		BCMNMIATTACHFN(_fn)
193*4882a593Smuzhiyun #define	BCMSROMATTACHDATA(_data)	BCMNMIATTACHFN(_data)
194*4882a593Smuzhiyun #endif	/* BCMOTPSROM */
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun #if defined(BCM_CISDUMP_NO_RECLAIM)
197*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHFN(_fn)	_fn
198*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHDATA(_data)	_data
199*4882a593Smuzhiyun #else
200*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHFN(_fn)	BCMSROMATTACHFN(_fn)
201*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHDATA(_data)	BCMSROMATTACHDATA(_data)
202*4882a593Smuzhiyun #endif /* BCM_CISDUMP_NO_RECLAIM */
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun #define BCMUNINITFN(_fn)	_fn
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun #else /* BCM_RECLAIM */
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun #define bcm_reclaimed			(1)
209*4882a593Smuzhiyun #define bcm_attach_part_reclaimed	(1)
210*4882a593Smuzhiyun #define bcm_preattach_part_reclaimed	(1)
211*4882a593Smuzhiyun #define bcm_postattach_part_reclaimed	(1)
212*4882a593Smuzhiyun #define BCMATTACHDATA(_data)		_data
213*4882a593Smuzhiyun #define BCMATTACHFN(_fn)		_fn
214*4882a593Smuzhiyun #define BCM_SRM_ATTACH_DATA(_data)	_data
215*4882a593Smuzhiyun #define BCM_SRM_ATTACH_FN(_fn)		_fn
216*4882a593Smuzhiyun /* BCMRODATA data is written into at attach time so it cannot be in .rodata */
217*4882a593Smuzhiyun #define BCMRODATA(_data)	__attribute__ ((__section__ (".data." #_data))) _data
218*4882a593Smuzhiyun #define BCMPREATTACHDATA(_data)		_data
219*4882a593Smuzhiyun #define BCMPREATTACHFN(_fn)		_fn
220*4882a593Smuzhiyun #define BCMPOSTATTACHDATA(_data)	_data
221*4882a593Smuzhiyun #define BCMPOSTATTACHFN(_fn)		_fn
222*4882a593Smuzhiyun #define BCMINITDATA(_data)		_data
223*4882a593Smuzhiyun #define BCMINITFN(_fn)			_fn
224*4882a593Smuzhiyun #define BCMUNINITFN(_fn)		_fn
225*4882a593Smuzhiyun #define	BCMNMIATTACHFN(_fn)		_fn
226*4882a593Smuzhiyun #define	BCMNMIATTACHDATA(_data)		_data
227*4882a593Smuzhiyun #define	BCMSROMATTACHFN(_fn)		_fn
228*4882a593Smuzhiyun #define	BCMSROMATTACHDATA(_data)	_data
229*4882a593Smuzhiyun #define BCMPREATTACHFNSR(_fn)		_fn
230*4882a593Smuzhiyun #define BCMPREATTACHDATASR(_data)	_data
231*4882a593Smuzhiyun #define BCMATTACHFNSR(_fn)		_fn
232*4882a593Smuzhiyun #define BCMATTACHDATASR(_data)		_data
233*4882a593Smuzhiyun #define	BCMSROMATTACHFN(_fn)		_fn
234*4882a593Smuzhiyun #define	BCMSROMATTACHDATA(_data)	_data
235*4882a593Smuzhiyun #define	BCMCISDUMPATTACHFN(_fn)		_fn
236*4882a593Smuzhiyun #define	BCMCISDUMPATTACHDATA(_data)	_data
237*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHFN(_fn)	_fn
238*4882a593Smuzhiyun #define	BCMSROMCISDUMPATTACHDATA(_data)	_data
239*4882a593Smuzhiyun #define CONST				const
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun #define RECLAIMED()			(bcm_reclaimed)
242*4882a593Smuzhiyun #define ATTACH_PART_RECLAIMED()		(bcm_attach_part_reclaimed)
243*4882a593Smuzhiyun #define PREATTACH_PART_RECLAIMED()	(bcm_preattach_part_reclaimed)
244*4882a593Smuzhiyun #define POSTATTACH_PART_RECLAIMED()	(bcm_postattach_part_reclaimed)
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun #endif /* BCM_RECLAIM */
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun #define BCMUCODEDATA(_data)		BCMINITDATA(_data)
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun #if defined(BCM_AQM_DMA_DESC) && !defined(BCM_AQM_DMA_DESC_DISABLED) && !defined(DONGLEBUILD)
251*4882a593Smuzhiyun #define BCMUCODEFN(_fn)			BCMINITFN(_fn)
252*4882a593Smuzhiyun #else
253*4882a593Smuzhiyun #define BCMUCODEFN(_fn)			BCMATTACHFN(_fn)
254*4882a593Smuzhiyun #endif /* BCM_AQM_DMA_DESC */
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun /* This feature is for dongle builds only.
257*4882a593Smuzhiyun  * In Rom build use BCMFASTPATH() to mark functions that will excluded from ROM bits if
258*4882a593Smuzhiyun  * BCMFASTPATH_EXCLUDE_FROM_ROM flag is defined (defined by default).
259*4882a593Smuzhiyun  * In romoffload or ram builds all functions that marked by BCMFASTPATH() will be placed
260*4882a593Smuzhiyun  * in "text_fastpath" section and will be used by trap handler.
261*4882a593Smuzhiyun  */
262*4882a593Smuzhiyun #ifndef BCMFASTPATH
263*4882a593Smuzhiyun #if defined(DONGLEBUILD)
264*4882a593Smuzhiyun #if defined(BCMROMBUILD)
265*4882a593Smuzhiyun #if defined(BCMFASTPATH_EXCLUDE_FROM_ROM)
266*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	__attribute__ ((__section__ (".text_ram." #_fn))) _fn
267*4882a593Smuzhiyun #else /* BCMFASTPATH_EXCLUDE_FROM_ROM */
268*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	_fn
269*4882a593Smuzhiyun #endif /* BCMFASTPATH_EXCLUDE_FROM_ROM */
270*4882a593Smuzhiyun #else /* BCMROMBUILD */
271*4882a593Smuzhiyun #ifdef BCMFASTPATH_O3OPT
272*4882a593Smuzhiyun #ifdef ROM_ENAB_RUNTIME_CHECK
273*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	__attribute__ ((__section__ (".text_fastpath." #_fn)))  _fn
274*4882a593Smuzhiyun #else
275*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	__attribute__ ((__section__ (".text_fastpath." #_fn))) \
276*4882a593Smuzhiyun 					__attribute__ ((optimize(3))) _fn
277*4882a593Smuzhiyun #endif /* ROM_ENAB_RUNTIME_CHECK */
278*4882a593Smuzhiyun #else
279*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	__attribute__ ((__section__ (".text_fastpath." #_fn)))  _fn
280*4882a593Smuzhiyun #endif /* BCMFASTPATH_O3OPT */
281*4882a593Smuzhiyun #endif /* BCMROMBUILD */
282*4882a593Smuzhiyun #else /* DONGLEBUILD */
283*4882a593Smuzhiyun 	#define BCMFASTPATH(_fn)	_fn
284*4882a593Smuzhiyun #endif /* DONGLEBUILD */
285*4882a593Smuzhiyun #endif /* BCMFASTPATH */
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /* Use the BCMRAMFN/BCMRAMDATA() macros to tag functions/data in source that must be included in RAM
288*4882a593Smuzhiyun  * (excluded from ROM). This should eliminate the need to manually specify these functions/data in
289*4882a593Smuzhiyun  * the ROM config file. It should only be used in special cases where the function must be in RAM
290*4882a593Smuzhiyun  * for *all* ROM-based chips.
291*4882a593Smuzhiyun  */
292*4882a593Smuzhiyun #if defined(BCMROMBUILD)
293*4882a593Smuzhiyun 	#define BCMRAMFN(_fn)     __attribute__ ((__section__ (".text_ram." #_fn), noinline)) _fn
294*4882a593Smuzhiyun 	#define BCMRAMDATA(_data) __attribute__ ((__section__ (".rodata_ram." #_data))) _data
295*4882a593Smuzhiyun #else
296*4882a593Smuzhiyun 	#define BCMRAMFN(_fn)		_fn
297*4882a593Smuzhiyun 	#define BCMRAMDATA(_data)	_data
298*4882a593Smuzhiyun #endif /* ROMBUILD */
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /* Use BCMSPECSYM() macro to tag symbols going to a special output section in the binary. */
301*4882a593Smuzhiyun #define BCMSPECSYM(_sym)	__attribute__ ((__section__ (".special." #_sym))) _sym
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun #define STATIC	static
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun /* functions that do not examine any values except their arguments, and have no effects except
306*4882a593Smuzhiyun  * the return value should use this keyword. Note that a function that has pointer arguments
307*4882a593Smuzhiyun  * and examines the data pointed to must not be declared as BCMCONSTFN.
308*4882a593Smuzhiyun  */
309*4882a593Smuzhiyun #ifdef __GNUC__
310*4882a593Smuzhiyun #define BCMCONSTFN	__attribute__ ((const))
311*4882a593Smuzhiyun #else
312*4882a593Smuzhiyun #define BCMCONSTFN
313*4882a593Smuzhiyun #endif /* __GNUC__ */
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun /* Bus types */
316*4882a593Smuzhiyun #define	SI_BUS			0	/* SOC Interconnect */
317*4882a593Smuzhiyun #define	PCI_BUS			1	/* PCI target */
318*4882a593Smuzhiyun #define	PCMCIA_BUS		2	/* PCMCIA target */
319*4882a593Smuzhiyun #define SDIO_BUS		3	/* SDIO target */
320*4882a593Smuzhiyun #define JTAG_BUS		4	/* JTAG */
321*4882a593Smuzhiyun #define USB_BUS			5	/* USB (does not support R/W REG) */
322*4882a593Smuzhiyun #define SPI_BUS			6	/* gSPI target */
323*4882a593Smuzhiyun #define RPC_BUS			7	/* RPC target */
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun /* Allows size optimization for single-bus image */
326*4882a593Smuzhiyun #ifdef BCMBUSTYPE
327*4882a593Smuzhiyun #define BUSTYPE(bus)	(BCMBUSTYPE)
328*4882a593Smuzhiyun #else
329*4882a593Smuzhiyun #define BUSTYPE(bus)	(bus)
330*4882a593Smuzhiyun #endif
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun #ifdef BCMBUSCORETYPE
333*4882a593Smuzhiyun #define BUSCORETYPE(ct)		(BCMBUSCORETYPE)
334*4882a593Smuzhiyun #else
335*4882a593Smuzhiyun #define BUSCORETYPE(ct)		(ct)
336*4882a593Smuzhiyun #endif
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun /* Allows size optimization for single-backplane image */
339*4882a593Smuzhiyun #ifdef BCMCHIPTYPE
340*4882a593Smuzhiyun #define CHIPTYPE(bus)	(BCMCHIPTYPE)
341*4882a593Smuzhiyun #else
342*4882a593Smuzhiyun #define CHIPTYPE(bus)	(bus)
343*4882a593Smuzhiyun #endif
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun /* Allows size optimization for SPROM support */
346*4882a593Smuzhiyun #if defined(BCMSPROMBUS)
347*4882a593Smuzhiyun #define SPROMBUS	(BCMSPROMBUS)
348*4882a593Smuzhiyun #else
349*4882a593Smuzhiyun #define SPROMBUS	(PCI_BUS)
350*4882a593Smuzhiyun #endif
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun /* Allows size optimization for single-chip image */
353*4882a593Smuzhiyun /* These macros are NOT meant to encourage writing chip-specific code.
354*4882a593Smuzhiyun  * Use them only when it is appropriate for example in PMU PLL/CHIP/SWREG
355*4882a593Smuzhiyun  * controls and in chip-specific workarounds.
356*4882a593Smuzhiyun  */
357*4882a593Smuzhiyun #ifdef BCMCHIPID
358*4882a593Smuzhiyun #define CHIPID(chip)	(BCMCHIPID)
359*4882a593Smuzhiyun #else
360*4882a593Smuzhiyun #define CHIPID(chip)	(chip)
361*4882a593Smuzhiyun #endif
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun #ifdef BCMCHIPREV
364*4882a593Smuzhiyun #define CHIPREV(rev)	(BCMCHIPREV)
365*4882a593Smuzhiyun #else
366*4882a593Smuzhiyun #define CHIPREV(rev)	(rev)
367*4882a593Smuzhiyun #endif
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun #ifdef BCMPCIEREV
370*4882a593Smuzhiyun #define PCIECOREREV(rev)	(BCMPCIEREV)
371*4882a593Smuzhiyun #else
372*4882a593Smuzhiyun #define PCIECOREREV(rev)	(rev)
373*4882a593Smuzhiyun #endif
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun #ifdef BCMPMUREV
376*4882a593Smuzhiyun #define PMUREV(rev)	(BCMPMUREV)
377*4882a593Smuzhiyun #else
378*4882a593Smuzhiyun #define PMUREV(rev)	(rev)
379*4882a593Smuzhiyun #endif
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun #ifdef BCMCCREV
382*4882a593Smuzhiyun #define CCREV(rev)	(BCMCCREV)
383*4882a593Smuzhiyun #else
384*4882a593Smuzhiyun #define CCREV(rev)	(rev)
385*4882a593Smuzhiyun #endif
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun #ifdef BCMGCIREV
388*4882a593Smuzhiyun #define GCIREV(rev)	(BCMGCIREV)
389*4882a593Smuzhiyun #else
390*4882a593Smuzhiyun #define GCIREV(rev)	(rev)
391*4882a593Smuzhiyun #endif
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun #ifdef BCMCR4REV
394*4882a593Smuzhiyun #define CR4REV(rev)	(BCMCR4REV)
395*4882a593Smuzhiyun #define CR4REV_GE(rev, val)	((BCMCR4REV) >= (val))
396*4882a593Smuzhiyun #else
397*4882a593Smuzhiyun #define CR4REV(rev)	(rev)
398*4882a593Smuzhiyun #define CR4REV_GE(rev, val)	((rev) >= (val))
399*4882a593Smuzhiyun #endif
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun #ifdef BCMLHLREV
402*4882a593Smuzhiyun #define LHLREV(rev)	(BCMLHLREV)
403*4882a593Smuzhiyun #else
404*4882a593Smuzhiyun #define LHLREV(rev)	(rev)
405*4882a593Smuzhiyun #endif
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun #ifdef BCMSPMISREV
408*4882a593Smuzhiyun #define SPMISREV(rev)	(BCMSPMISREV)
409*4882a593Smuzhiyun #else
410*4882a593Smuzhiyun #define	SPMISREV(rev)	(rev)
411*4882a593Smuzhiyun #endif
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
414*4882a593Smuzhiyun #define DMADDR_MASK_32 0x0		/* Address mask for 32-bits */
415*4882a593Smuzhiyun #define DMADDR_MASK_30 0xc0000000	/* Address mask for 30-bits */
416*4882a593Smuzhiyun #define DMADDR_MASK_26 0xFC000000	/* Address maks for 26-bits */
417*4882a593Smuzhiyun #define DMADDR_MASK_0  0xffffffff	/* Address mask for 0-bits (hi-part) */
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun #define	DMADDRWIDTH_26  26 /* 26-bit addressing capability */
420*4882a593Smuzhiyun #define	DMADDRWIDTH_30  30 /* 30-bit addressing capability */
421*4882a593Smuzhiyun #define	DMADDRWIDTH_32  32 /* 32-bit addressing capability */
422*4882a593Smuzhiyun #define	DMADDRWIDTH_63  63 /* 64-bit addressing capability */
423*4882a593Smuzhiyun #define	DMADDRWIDTH_64  64 /* 64-bit addressing capability */
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun typedef struct {
426*4882a593Smuzhiyun 	uint32 loaddr;
427*4882a593Smuzhiyun 	uint32 hiaddr;
428*4882a593Smuzhiyun } dma64addr_t;
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun #define PHYSADDR64HI(_pa) ((_pa).hiaddr)
431*4882a593Smuzhiyun #define PHYSADDR64HISET(_pa, _val) \
432*4882a593Smuzhiyun 	do { \
433*4882a593Smuzhiyun 		(_pa).hiaddr = (_val);		\
434*4882a593Smuzhiyun 	} while (0)
435*4882a593Smuzhiyun #define PHYSADDR64LO(_pa) ((_pa).loaddr)
436*4882a593Smuzhiyun #define PHYSADDR64LOSET(_pa, _val) \
437*4882a593Smuzhiyun 	do { \
438*4882a593Smuzhiyun 		(_pa).loaddr = (_val);		\
439*4882a593Smuzhiyun 	} while (0)
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun #ifdef BCMDMA64OSL
442*4882a593Smuzhiyun typedef dma64addr_t dmaaddr_t;
443*4882a593Smuzhiyun #define PHYSADDRHI(_pa) PHYSADDR64HI(_pa)
444*4882a593Smuzhiyun #define PHYSADDRHISET(_pa, _val) PHYSADDR64HISET(_pa, _val)
445*4882a593Smuzhiyun #define PHYSADDRLO(_pa)  PHYSADDR64LO(_pa)
446*4882a593Smuzhiyun #define PHYSADDRLOSET(_pa, _val) PHYSADDR64LOSET(_pa, _val)
447*4882a593Smuzhiyun #define PHYSADDRTOULONG(_pa, _ulong) \
448*4882a593Smuzhiyun 	do { \
449*4882a593Smuzhiyun 		_ulong = ((unsigned long long)(_pa).hiaddr << 32) | ((_pa).loaddr); \
450*4882a593Smuzhiyun 	} while (0)
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun #else
453*4882a593Smuzhiyun typedef uint32 dmaaddr_t;
454*4882a593Smuzhiyun #define PHYSADDRHI(_pa) (0u)
455*4882a593Smuzhiyun #define PHYSADDRHISET(_pa, _val)
456*4882a593Smuzhiyun #define PHYSADDRLO(_pa) ((_pa))
457*4882a593Smuzhiyun #define PHYSADDRLOSET(_pa, _val) \
458*4882a593Smuzhiyun 	do { \
459*4882a593Smuzhiyun 		(_pa) = (_val);			\
460*4882a593Smuzhiyun 	} while (0)
461*4882a593Smuzhiyun #endif /* BCMDMA64OSL */
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun #define PHYSADDRISZERO(_pa) (PHYSADDRLO(_pa) == 0 && PHYSADDRHI(_pa) == 0)
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun /* One physical DMA segment */
466*4882a593Smuzhiyun typedef struct  {
467*4882a593Smuzhiyun 	dmaaddr_t addr;
468*4882a593Smuzhiyun 	uint32	  length;
469*4882a593Smuzhiyun } hnddma_seg_t;
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun #if defined(__linux__)
472*4882a593Smuzhiyun #define MAX_DMA_SEGS 8
473*4882a593Smuzhiyun #else
474*4882a593Smuzhiyun #define MAX_DMA_SEGS 4
475*4882a593Smuzhiyun #endif
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun typedef struct {
478*4882a593Smuzhiyun 	void *oshdmah; /* Opaque handle for OSL to store its information */
479*4882a593Smuzhiyun 	uint origsize; /* Size of the virtual packet */
480*4882a593Smuzhiyun 	uint nsegs;
481*4882a593Smuzhiyun 	hnddma_seg_t segs[MAX_DMA_SEGS];
482*4882a593Smuzhiyun } hnddma_seg_map_t;
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun /* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF).
485*4882a593Smuzhiyun  * By doing, we avoid the need  to allocate an extra buffer for the header when bridging to WL.
486*4882a593Smuzhiyun  * There is a compile time check in wlc.c which ensure that this value is at least as big
487*4882a593Smuzhiyun  * as TXOFF. This value is used in dma_rxfill (hnddma.c).
488*4882a593Smuzhiyun  */
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun #ifndef BCMEXTRAHDROOM
491*4882a593Smuzhiyun #define BCMEXTRAHDROOM 204
492*4882a593Smuzhiyun #endif
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun /* Packet alignment for most efficient SDIO (can change based on platform) */
495*4882a593Smuzhiyun #ifndef SDALIGN
496*4882a593Smuzhiyun #define SDALIGN	32
497*4882a593Smuzhiyun #endif
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun /* Headroom required for dongle-to-host communication.  Packets allocated
500*4882a593Smuzhiyun  * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
501*4882a593Smuzhiyun  * leave this much room in front for low-level message headers which may
502*4882a593Smuzhiyun  * be needed to get across the dongle bus to the host.  (These messages
503*4882a593Smuzhiyun  * don't go over the network, so room for the full WL header above would
504*4882a593Smuzhiyun  * be a waste.).
505*4882a593Smuzhiyun */
506*4882a593Smuzhiyun /*
507*4882a593Smuzhiyun  * set the numbers to be MAX of all the devices, to avoid problems with ROM builds
508*4882a593Smuzhiyun  * USB BCMDONGLEHDRSZ and BCMDONGLEPADSZ is 0
509*4882a593Smuzhiyun  * SDIO BCMDONGLEHDRSZ 12 and BCMDONGLEPADSZ 16
510*4882a593Smuzhiyun */
511*4882a593Smuzhiyun #define BCMDONGLEHDRSZ 12
512*4882a593Smuzhiyun #define BCMDONGLEPADSZ 16
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun #define BCMDONGLEOVERHEAD	(BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun #ifdef BCMDBG
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun #ifndef BCMDBG_ERR
519*4882a593Smuzhiyun #define BCMDBG_ERR
520*4882a593Smuzhiyun #endif /* BCMDBG_ERR */
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun #ifndef BCMDBG_ASSERT
523*4882a593Smuzhiyun #define BCMDBG_ASSERT
524*4882a593Smuzhiyun #endif /* BCMDBG_ASSERT */
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun #endif /* BCMDBG */
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun #if defined(NO_BCMDBG_ASSERT)
529*4882a593Smuzhiyun 	#undef BCMDBG_ASSERT
530*4882a593Smuzhiyun 	#undef BCMASSERT_LOG
531*4882a593Smuzhiyun #endif
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun #if defined(BCMDBG_ASSERT) || defined(BCMASSERT_LOG)
534*4882a593Smuzhiyun #define BCMASSERT_SUPPORT
535*4882a593Smuzhiyun #endif /* BCMDBG_ASSERT || BCMASSERT_LOG */
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun /* Macros for doing definition and get/set of bitfields
538*4882a593Smuzhiyun  * Usage example, e.g. a three-bit field (bits 4-6):
539*4882a593Smuzhiyun  *    #define <NAME>_M	BITFIELD_MASK(3)
540*4882a593Smuzhiyun  *    #define <NAME>_S	4
541*4882a593Smuzhiyun  * ...
542*4882a593Smuzhiyun  *    regval = R_REG(osh, &regs->regfoo);
543*4882a593Smuzhiyun  *    field = GFIELD(regval, <NAME>);
544*4882a593Smuzhiyun  *    regval = SFIELD(regval, <NAME>, 1);
545*4882a593Smuzhiyun  *    W_REG(osh, &regs->regfoo, regval);
546*4882a593Smuzhiyun  */
547*4882a593Smuzhiyun #define BITFIELD_MASK(width) \
548*4882a593Smuzhiyun 		(((unsigned)1 << (width)) - 1)
549*4882a593Smuzhiyun #define GFIELD(val, field) \
550*4882a593Smuzhiyun 		(((val) >> field ## _S) & field ## _M)
551*4882a593Smuzhiyun #define SFIELD(val, field, bits) \
552*4882a593Smuzhiyun 		(((val) & (~(field ## _M << field ## _S))) | \
553*4882a593Smuzhiyun 		 ((unsigned)(bits) << field ## _S))
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun /* define BCMSMALL to remove misc features for memory-constrained environments */
556*4882a593Smuzhiyun #ifdef BCMSMALL
557*4882a593Smuzhiyun #undef	BCMSPACE
558*4882a593Smuzhiyun #define bcmspace	FALSE	/* if (bcmspace) code is discarded */
559*4882a593Smuzhiyun #else
560*4882a593Smuzhiyun #define	BCMSPACE
561*4882a593Smuzhiyun #define bcmspace	TRUE	/* if (bcmspace) code is retained */
562*4882a593Smuzhiyun #endif
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun /* ROM_ENAB_RUNTIME_CHECK may be set based upon the #define below (for ROM builds). It may also
565*4882a593Smuzhiyun  * be defined via makefiles (e.g. ROM auto abandon unoptimized compiles).
566*4882a593Smuzhiyun  */
567*4882a593Smuzhiyun #if defined(BCMROMBUILD)
568*4882a593Smuzhiyun #ifndef ROM_ENAB_RUNTIME_CHECK
569*4882a593Smuzhiyun 	#define ROM_ENAB_RUNTIME_CHECK
570*4882a593Smuzhiyun #endif
571*4882a593Smuzhiyun #endif /* BCMROMBUILD */
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun #ifdef BCM_SH_SFLASH
574*4882a593Smuzhiyun 	extern bool _bcm_sh_sflash;
575*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
576*4882a593Smuzhiyun 	#define BCM_SH_SFLASH_ENAB() (_bcm_sh_sflash)
577*4882a593Smuzhiyun #elif defined(BCM_SH_SFLASH_DISABLED)
578*4882a593Smuzhiyun 	#define BCM_SH_SFLASH_ENAB()	(0)
579*4882a593Smuzhiyun #else
580*4882a593Smuzhiyun 	#define BCM_SH_SFLASH_ENAB()	(1)
581*4882a593Smuzhiyun #endif
582*4882a593Smuzhiyun #else
583*4882a593Smuzhiyun 	#define BCM_SH_SFLASH_ENAB()   (0)
584*4882a593Smuzhiyun #endif	/* BCM_SH_SFLASH */
585*4882a593Smuzhiyun 
586*4882a593Smuzhiyun #ifdef BCM_SFLASH
587*4882a593Smuzhiyun 	extern bool _bcm_sflash;
588*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
589*4882a593Smuzhiyun 	#define BCM_SFLASH_ENAB() (_bcm_sflash)
590*4882a593Smuzhiyun #elif defined(BCM_SFLASH_DISABLED)
591*4882a593Smuzhiyun 	#define BCM_SFLASH_ENAB()	(0)
592*4882a593Smuzhiyun #else
593*4882a593Smuzhiyun 	#define BCM_SFLASH_ENAB()	(1)
594*4882a593Smuzhiyun #endif
595*4882a593Smuzhiyun #else
596*4882a593Smuzhiyun 	#define BCM_SFLASH_ENAB()   (0)
597*4882a593Smuzhiyun #endif	/* BCM_SFLASH */
598*4882a593Smuzhiyun 
599*4882a593Smuzhiyun #ifdef BCM_DELAY_ON_LTR
600*4882a593Smuzhiyun 	extern bool _bcm_delay_on_ltr;
601*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
602*4882a593Smuzhiyun 	#define BCM_DELAY_ON_LTR_ENAB() (_bcm_delay_on_ltr)
603*4882a593Smuzhiyun #elif defined(BCM_DELAY_ON_LTR_DISABLED)
604*4882a593Smuzhiyun 	#define BCM_DELAY_ON_LTR_ENAB()	(0)
605*4882a593Smuzhiyun #else
606*4882a593Smuzhiyun 	#define BCM_DELAY_ON_LTR_ENAB()	(1)
607*4882a593Smuzhiyun #endif
608*4882a593Smuzhiyun #else
609*4882a593Smuzhiyun 	#define BCM_DELAY_ON_LTR_ENAB()		(0)
610*4882a593Smuzhiyun #endif	/* BCM_DELAY_ON_LTR */
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun /* Max. nvram variable table size */
613*4882a593Smuzhiyun #ifndef MAXSZ_NVRAM_VARS
614*4882a593Smuzhiyun #ifdef LARGE_NVRAM_MAXSZ
615*4882a593Smuzhiyun #define MAXSZ_NVRAM_VARS	(LARGE_NVRAM_MAXSZ * 2)
616*4882a593Smuzhiyun #else
617*4882a593Smuzhiyun #if defined(BCMROMBUILD) || defined(DONGLEBUILD)
618*4882a593Smuzhiyun /* SROM12 changes */
619*4882a593Smuzhiyun #define	MAXSZ_NVRAM_VARS	6144	/* should be reduced */
620*4882a593Smuzhiyun #else
621*4882a593Smuzhiyun #define LARGE_NVRAM_MAXSZ	8192
622*4882a593Smuzhiyun #define MAXSZ_NVRAM_VARS	(LARGE_NVRAM_MAXSZ * 2)
623*4882a593Smuzhiyun #endif /* BCMROMBUILD || DONGLEBUILD */
624*4882a593Smuzhiyun #endif /* LARGE_NVRAM_MAXSZ */
625*4882a593Smuzhiyun #endif /* !MAXSZ_NVRAM_VARS */
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun #ifdef ATE_BUILD
628*4882a593Smuzhiyun #ifndef ATE_NVRAM_MAXSIZE
629*4882a593Smuzhiyun #define ATE_NVRAM_MAXSIZE 32000
630*4882a593Smuzhiyun #endif /* ATE_NVRAM_MAXSIZE */
631*4882a593Smuzhiyun #endif /* ATE_BUILD */
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun #ifdef BCMLFRAG /* BCMLFRAG support enab macros  */
634*4882a593Smuzhiyun 	extern bool _bcmlfrag;
635*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
636*4882a593Smuzhiyun 	#define BCMLFRAG_ENAB() (_bcmlfrag)
637*4882a593Smuzhiyun #elif defined(BCMLFRAG_DISABLED)
638*4882a593Smuzhiyun 	#define BCMLFRAG_ENAB()	(0)
639*4882a593Smuzhiyun #else
640*4882a593Smuzhiyun 	#define BCMLFRAG_ENAB()	(1)
641*4882a593Smuzhiyun #endif
642*4882a593Smuzhiyun #else
643*4882a593Smuzhiyun 	#define BCMLFRAG_ENAB()		(0)
644*4882a593Smuzhiyun #endif /* BCMLFRAG_ENAB */
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun #ifdef BCMPCIEDEV /* BCMPCIEDEV support enab macros */
647*4882a593Smuzhiyun extern bool _pciedevenab;
648*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK)
649*4882a593Smuzhiyun 	#define BCMPCIEDEV_ENAB() (_pciedevenab)
650*4882a593Smuzhiyun #elif defined(BCMPCIEDEV_ENABLED)
651*4882a593Smuzhiyun 	#define BCMPCIEDEV_ENAB()	1
652*4882a593Smuzhiyun #else
653*4882a593Smuzhiyun 	#define BCMPCIEDEV_ENAB()	0
654*4882a593Smuzhiyun #endif
655*4882a593Smuzhiyun #else
656*4882a593Smuzhiyun 	#define BCMPCIEDEV_ENAB()	0
657*4882a593Smuzhiyun #endif /* BCMPCIEDEV */
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun #ifdef BCMRESVFRAGPOOL /* BCMRESVFRAGPOOL support enab macros */
660*4882a593Smuzhiyun extern bool _resvfragpool_enab;
661*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
662*4882a593Smuzhiyun 	#define  BCMRESVFRAGPOOL_ENAB() (_resvfragpool_enab)
663*4882a593Smuzhiyun #elif defined(BCMRESVFRAGPOOL_DISABLED)
664*4882a593Smuzhiyun 	#define BCMRESVFRAGPOOL_ENAB()	(0)
665*4882a593Smuzhiyun #else
666*4882a593Smuzhiyun 	#define BCMRESVFRAGPOOL_ENAB()	(1)
667*4882a593Smuzhiyun #endif
668*4882a593Smuzhiyun #else
669*4882a593Smuzhiyun 	#define BCMRESVFRAGPOOL_ENAB()	0
670*4882a593Smuzhiyun #endif /* BCMPCIEDEV */
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun #ifdef BCMSDIODEV /* BCMSDIODEV support enab macros */
673*4882a593Smuzhiyun extern bool _sdiodevenab;
674*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
675*4882a593Smuzhiyun 	#define BCMSDIODEV_ENAB() (_sdiodevenab)
676*4882a593Smuzhiyun #elif defined(BCMSDIODEV_ENABLED)
677*4882a593Smuzhiyun 	#define BCMSDIODEV_ENAB()	1
678*4882a593Smuzhiyun #else
679*4882a593Smuzhiyun 	#define BCMSDIODEV_ENAB()	0
680*4882a593Smuzhiyun #endif
681*4882a593Smuzhiyun #else
682*4882a593Smuzhiyun 	#define BCMSDIODEV_ENAB()	0
683*4882a593Smuzhiyun #endif /* BCMSDIODEV */
684*4882a593Smuzhiyun 
685*4882a593Smuzhiyun #ifdef BCMSPMIS
686*4882a593Smuzhiyun extern bool _bcmspmi_enab;
687*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
688*4882a593Smuzhiyun 	#define	BCMSPMIS_ENAB()		(_bcmspmi_enab)
689*4882a593Smuzhiyun #elif defined(BCMSPMIS_DISABLED)
690*4882a593Smuzhiyun 	#define	BCMSPMIS_ENAB()		0
691*4882a593Smuzhiyun #else
692*4882a593Smuzhiyun 	#define	BCMSPMIS_ENAB()		1
693*4882a593Smuzhiyun #endif
694*4882a593Smuzhiyun #else
695*4882a593Smuzhiyun 	#define	BCMSPMIS_ENAB()		0
696*4882a593Smuzhiyun #endif /* BCMSPMIS */
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun #ifdef BCMDVFS /* BCMDVFS support enab macros */
699*4882a593Smuzhiyun extern bool _dvfsenab;
700*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK)
701*4882a593Smuzhiyun 	#define BCMDVFS_ENAB() (_dvfsenab)
702*4882a593Smuzhiyun #elif !defined(BCMDVFS_DISABLED)
703*4882a593Smuzhiyun 	#define BCMDVFS_ENAB()	(1)
704*4882a593Smuzhiyun #else
705*4882a593Smuzhiyun 	#define BCMDVFS_ENAB()	(0)
706*4882a593Smuzhiyun #endif
707*4882a593Smuzhiyun #else
708*4882a593Smuzhiyun 	#define BCMDVFS_ENAB()	(0)
709*4882a593Smuzhiyun #endif /* BCMDVFS */
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun /* Max size for reclaimable NVRAM array */
712*4882a593Smuzhiyun #ifndef ATE_BUILD
713*4882a593Smuzhiyun #ifdef DL_NVRAM
714*4882a593Smuzhiyun #define NVRAM_ARRAY_MAXSIZE	DL_NVRAM
715*4882a593Smuzhiyun #else
716*4882a593Smuzhiyun #define NVRAM_ARRAY_MAXSIZE	MAXSZ_NVRAM_VARS
717*4882a593Smuzhiyun #endif /* DL_NVRAM */
718*4882a593Smuzhiyun #else
719*4882a593Smuzhiyun #define NVRAM_ARRAY_MAXSIZE	ATE_NVRAM_MAXSIZE
720*4882a593Smuzhiyun #endif /* ATE_BUILD */
721*4882a593Smuzhiyun 
722*4882a593Smuzhiyun extern uint32 gFWID;
723*4882a593Smuzhiyun 
724*4882a593Smuzhiyun #ifdef BCMFRWDPKT /* BCMFRWDPKT support enab macros  */
725*4882a593Smuzhiyun 	extern bool _bcmfrwdpkt;
726*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
727*4882a593Smuzhiyun 	#define BCMFRWDPKT_ENAB() (_bcmfrwdpkt)
728*4882a593Smuzhiyun #elif defined(BCMFRWDPKT_DISABLED)
729*4882a593Smuzhiyun 	#define BCMFRWDPKT_ENAB()	(0)
730*4882a593Smuzhiyun #else
731*4882a593Smuzhiyun 	#define BCMFRWDPKT_ENAB()	(1)
732*4882a593Smuzhiyun #endif
733*4882a593Smuzhiyun #else
734*4882a593Smuzhiyun 	#define BCMFRWDPKT_ENAB()		(0)
735*4882a593Smuzhiyun #endif /* BCMFRWDPKT */
736*4882a593Smuzhiyun 
737*4882a593Smuzhiyun #ifdef BCMFRWDPOOLREORG /* BCMFRWDPOOLREORG support enab macros  */
738*4882a593Smuzhiyun 	extern bool _bcmfrwdpoolreorg;
739*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
740*4882a593Smuzhiyun 	#define BCMFRWDPOOLREORG_ENAB() (_bcmfrwdpoolreorg)
741*4882a593Smuzhiyun #elif defined(BCMFRWDPOOLREORG_DISABLED)
742*4882a593Smuzhiyun 	#define BCMFRWDPOOLREORG_ENAB()	(0)
743*4882a593Smuzhiyun #else
744*4882a593Smuzhiyun 	#define BCMFRWDPOOLREORG_ENAB()	(1)
745*4882a593Smuzhiyun #endif
746*4882a593Smuzhiyun #else
747*4882a593Smuzhiyun 	#define BCMFRWDPOOLREORG_ENAB()		(0)
748*4882a593Smuzhiyun #endif /* BCMFRWDPOOLREORG */
749*4882a593Smuzhiyun 
750*4882a593Smuzhiyun #ifdef BCMPOOLRECLAIM /* BCMPOOLRECLAIM support enab macros  */
751*4882a593Smuzhiyun 	extern bool _bcmpoolreclaim;
752*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
753*4882a593Smuzhiyun 	#define BCMPOOLRECLAIM_ENAB() (_bcmpoolreclaim)
754*4882a593Smuzhiyun #elif defined(BCMPOOLRECLAIM_DISABLED)
755*4882a593Smuzhiyun 	#define BCMPOOLRECLAIM_ENAB()	(0)
756*4882a593Smuzhiyun #else
757*4882a593Smuzhiyun 	#define BCMPOOLRECLAIM_ENAB()	(1)
758*4882a593Smuzhiyun #endif
759*4882a593Smuzhiyun #else
760*4882a593Smuzhiyun 	#define BCMPOOLRECLAIM_ENAB()		(0)
761*4882a593Smuzhiyun #endif /* BCMPOOLRECLAIM */
762*4882a593Smuzhiyun 
763*4882a593Smuzhiyun /* Chip related low power flags (lpflags) */
764*4882a593Smuzhiyun 
765*4882a593Smuzhiyun #ifndef PAD
766*4882a593Smuzhiyun #define _PADLINE(line)  pad ## line
767*4882a593Smuzhiyun #define _XSTR(line)     _PADLINE(line)
768*4882a593Smuzhiyun #define PAD             _XSTR(__LINE__)
769*4882a593Smuzhiyun #endif
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun #if defined(DONGLEBUILD) && ! defined(__COVERITY__)
772*4882a593Smuzhiyun #define MODULE_DETACH(var, detach_func)\
773*4882a593Smuzhiyun 	do { \
774*4882a593Smuzhiyun 		BCM_REFERENCE(detach_func); \
775*4882a593Smuzhiyun 		OSL_SYS_HALT(); \
776*4882a593Smuzhiyun 	} while (0);
777*4882a593Smuzhiyun #define MODULE_DETACH_2(var1, var2, detach_func) MODULE_DETACH(var1, detach_func)
778*4882a593Smuzhiyun #define MODULE_DETACH_TYPECASTED(var, detach_func)
779*4882a593Smuzhiyun #else
780*4882a593Smuzhiyun #define MODULE_DETACH(var, detach_func)\
781*4882a593Smuzhiyun 	if (var) { \
782*4882a593Smuzhiyun 		detach_func(var); \
783*4882a593Smuzhiyun 		(var) = NULL; \
784*4882a593Smuzhiyun 	}
785*4882a593Smuzhiyun #define MODULE_DETACH_2(var1, var2, detach_func) detach_func(var1, var2)
786*4882a593Smuzhiyun #define MODULE_DETACH_TYPECASTED(var, detach_func) detach_func(var)
787*4882a593Smuzhiyun #endif /* DONGLEBUILD */
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun /* When building ROML image use runtime conditional to cause the compiler
790*4882a593Smuzhiyun  * to compile everything but not to complain "defined but not used"
791*4882a593Smuzhiyun  * as #ifdef would cause at the callsites.
792*4882a593Smuzhiyun  * In the end functions called under if (0) {} will not be linked
793*4882a593Smuzhiyun  * into the final binary if they're not called from other places either.
794*4882a593Smuzhiyun  */
795*4882a593Smuzhiyun #if !defined(BCMROMBUILD) || defined(BCMROMSYMGEN_BUILD)
796*4882a593Smuzhiyun #define BCM_ATTACH_REF_DECL()
797*4882a593Smuzhiyun #define BCM_ATTACH_REF()	(1)
798*4882a593Smuzhiyun #else
799*4882a593Smuzhiyun #define BCM_ATTACH_REF_DECL()	static bool bcm_non_roml_build = 0;
800*4882a593Smuzhiyun #define BCM_ATTACH_REF()	(bcm_non_roml_build)
801*4882a593Smuzhiyun #endif
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun /* For ROM builds, keep it in const section so that it gets ROMmed. If abandoned, move it to
804*4882a593Smuzhiyun  * RO section but before ro region start so that FATAL log buf doesn't use this.
805*4882a593Smuzhiyun  */
806*4882a593Smuzhiyun // Temporary - leave old definition in place until all references are removed elsewhere
807*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
808*4882a593Smuzhiyun #define BCMRODATA_ONTRAP(_data)	_data
809*4882a593Smuzhiyun #else
810*4882a593Smuzhiyun #define BCMRODATA_ONTRAP(_data)	__attribute__ ((__section__ (".ro_ontrap." #_data))) _data
811*4882a593Smuzhiyun #endif
812*4882a593Smuzhiyun // Renamed for consistency with post trap function definition
813*4882a593Smuzhiyun #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
814*4882a593Smuzhiyun #define BCMPOST_TRAP_RODATA(_data)	_data
815*4882a593Smuzhiyun #else
816*4882a593Smuzhiyun #define BCMPOST_TRAP_RODATA(_data) __attribute__ ((__section__ (".ro_ontrap." #_data))) _data
817*4882a593Smuzhiyun #endif
818*4882a593Smuzhiyun 
819*4882a593Smuzhiyun /* Similar to RO data on trap, we want code that's used after a trap to be placed in a special area
820*4882a593Smuzhiyun  * as this means we can use all of the rest of the .text for post trap dumps. Functions with
821*4882a593Smuzhiyun  * the BCMPOSTTRAPFN macro applied will either be in ROM or this protected area.
822*4882a593Smuzhiyun  * For RAMFNs, the ROM build only needs to nkow that they won't be in ROM, but the -roml
823*4882a593Smuzhiyun  * builds need to know to protect them.
824*4882a593Smuzhiyun  */
825*4882a593Smuzhiyun #if defined(BCMROMBUILD)
826*4882a593Smuzhiyun #define BCMPOSTTRAPFN(_fn)		_fn
827*4882a593Smuzhiyun #define BCMPOSTTRAPRAMFN(_fn)	__attribute__ ((__section__ (".text_ram." #_fn))) _fn
828*4882a593Smuzhiyun #if defined(BCMFASTPATH_EXCLUDE_FROM_ROM)
829*4882a593Smuzhiyun #define BCMPOSTTRAPFASTPATH(_fn)	__attribute__ ((__section__ (".text_ram." #_fn))) _fn
830*4882a593Smuzhiyun #else /* BCMFASTPATH_EXCLUDE_FROM_ROM */
831*4882a593Smuzhiyun #define BCMPOSTTRAPFASTPATH(fn)	BCMPOSTTRAPFN(fn)
832*4882a593Smuzhiyun #endif /* BCMFASTPATH_EXCLUDE_FROM_ROM */
833*4882a593Smuzhiyun #else
834*4882a593Smuzhiyun #if defined(DONGLEBUILD)
835*4882a593Smuzhiyun #define BCMPOSTTRAPFN(_fn)	__attribute__ ((__section__ (".text_posttrap." #_fn))) _fn
836*4882a593Smuzhiyun #else
837*4882a593Smuzhiyun #define BCMPOSTTRAPFN(_fn)		_fn
838*4882a593Smuzhiyun #endif /* DONGLEBUILD */
839*4882a593Smuzhiyun #define BCMPOSTTRAPRAMFN(fn)	BCMPOSTTRAPFN(fn)
840*4882a593Smuzhiyun #define BCMPOSTTRAPFASTPATH(fn)	BCMPOSTTRAPFN(fn)
841*4882a593Smuzhiyun #endif /* ROMBUILD */
842*4882a593Smuzhiyun 
843*4882a593Smuzhiyun typedef struct bcm_rng * bcm_rng_handle_t;
844*4882a593Smuzhiyun 
845*4882a593Smuzhiyun /* Use BCM_FUNC_PTR() to tag function pointers for ASLR code implementation. It will perform
846*4882a593Smuzhiyun  * run-time relocation of a function pointer by translating it from a physical to virtual address.
847*4882a593Smuzhiyun  *
848*4882a593Smuzhiyun  * BCM_FUNC_PTR() should only be used where the function name is referenced (corresponding to the
849*4882a593Smuzhiyun  * relocation entry for that symbol). It should not be used when the function pointer is invoked.
850*4882a593Smuzhiyun  */
851*4882a593Smuzhiyun void* BCM_ASLR_CODE_FNPTR_RELOCATOR(void *func_ptr);
852*4882a593Smuzhiyun #if defined(BCM_ASLR_CODE_FNPTR_RELOC)
853*4882a593Smuzhiyun 	/* 'func_ptr_err_chk' performs a compile time error check to ensure that only a constant
854*4882a593Smuzhiyun 	 * function name is passed as an argument to BCM_FUNC_PTR(). This ensures that the macro is
855*4882a593Smuzhiyun 	 * only used for function pointer references, and not for function pointer invocations.
856*4882a593Smuzhiyun 	 */
857*4882a593Smuzhiyun 	#define BCM_FUNC_PTR(func) \
858*4882a593Smuzhiyun 		({ static void *func_ptr_err_chk __attribute__ ((unused)) = (func); \
859*4882a593Smuzhiyun 		BCM_ASLR_CODE_FNPTR_RELOCATOR(func); })
860*4882a593Smuzhiyun #else
861*4882a593Smuzhiyun 	#define BCM_FUNC_PTR(func)         (func)
862*4882a593Smuzhiyun #endif /* BCM_ASLR_CODE_FNPTR_RELOC */
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun /*
865*4882a593Smuzhiyun  * Timestamps have this tag appended following a null byte which
866*4882a593Smuzhiyun  * helps comparison/hashing scripts find and ignore them.
867*4882a593Smuzhiyun  */
868*4882a593Smuzhiyun #define TIMESTAMP_SUFFIX "<TIMESTAMP>"
869*4882a593Smuzhiyun 
870*4882a593Smuzhiyun #ifdef ASLR_STACK
871*4882a593Smuzhiyun /* MMU main thread stack data */
872*4882a593Smuzhiyun #define BCM_MMU_MTH_STK_DATA(_data) __attribute__ ((__section__ (".mmu_mth_stack." #_data))) _data
873*4882a593Smuzhiyun #endif /* ASLR_STACK */
874*4882a593Smuzhiyun 
875*4882a593Smuzhiyun /* Special section for MMU page-tables. */
876*4882a593Smuzhiyun #define BCM_MMU_PAGE_TABLE_DATA(_data) \
877*4882a593Smuzhiyun 	__attribute__ ((__section__ (".mmu_pagetable." #_data))) _data
878*4882a593Smuzhiyun 
879*4882a593Smuzhiyun /* Some phy initialization code/data can't be reclaimed in dualband mode */
880*4882a593Smuzhiyun #if defined(DBAND)
881*4882a593Smuzhiyun #define WLBANDINITDATA(_data)	_data
882*4882a593Smuzhiyun #define WLBANDINITFN(_fn)	_fn
883*4882a593Smuzhiyun #else
884*4882a593Smuzhiyun #define WLBANDINITDATA(_data)	BCMINITDATA(_data)
885*4882a593Smuzhiyun #define WLBANDINITFN(_fn)	BCMINITFN(_fn)
886*4882a593Smuzhiyun #endif
887*4882a593Smuzhiyun 
888*4882a593Smuzhiyun /* Tag struct members to make it explicitly clear that they are physical addresses. These are
889*4882a593Smuzhiyun  * typically used in data structs shared by the firmware and host code (or off-line utilities). The
890*4882a593Smuzhiyun  * use of the macro avoids customer visible API/name changes.
891*4882a593Smuzhiyun  */
892*4882a593Smuzhiyun #if defined(BCM_PHYS_ADDR_NAME_CONVERSION)
893*4882a593Smuzhiyun 	#define PHYS_ADDR_N(name) name ## _phys
894*4882a593Smuzhiyun #else
895*4882a593Smuzhiyun 	#define PHYS_ADDR_N(name) name
896*4882a593Smuzhiyun #endif
897*4882a593Smuzhiyun 
898*4882a593Smuzhiyun /*
899*4882a593Smuzhiyun  * A compact form for a list of valid register address offsets.
900*4882a593Smuzhiyun  * Used for when dumping the contents of the register set for the user.
901*4882a593Smuzhiyun  *
902*4882a593Smuzhiyun  * bmp_cnt has either bitmap or count. If the MSB (bit 31) is set, then
903*4882a593Smuzhiyun  * bmp_cnt[30:0] has count, i.e, number of valid registers whose values are
904*4882a593Smuzhiyun  * contigous from the start address. If MSB is zero, then the value
905*4882a593Smuzhiyun  * should be considered as a bitmap of 31 discreet addresses from the base addr.
906*4882a593Smuzhiyun  * Note: the data type for bmp_cnt is chosen as an array of uint8 to avoid padding.
907*4882a593Smuzhiyun  */
908*4882a593Smuzhiyun typedef struct _regs_bmp_list {
909*4882a593Smuzhiyun 	uint16 addr;		/* start address offset */
910*4882a593Smuzhiyun 	uint8 bmp_cnt[4];	/* bit[31]=1, bit[30:0] is count else it is a bitmap */
911*4882a593Smuzhiyun } regs_list_t;
912*4882a593Smuzhiyun 
913*4882a593Smuzhiyun #endif /* _bcmdefs_h_ */
914