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