bcmdefs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Misc system wide definitions
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: bcmdefs.h 700870 2017-05-22 19:05:22Z $
  30. */
  31. #ifndef _bcmdefs_h_
  32. #define _bcmdefs_h_
  33. /*
  34. * One doesn't need to include this file explicitly, gets included automatically if
  35. * typedefs.h is included.
  36. */
  37. /* Use BCM_REFERENCE to suppress warnings about intentionally-unused function
  38. * arguments or local variables.
  39. */
  40. #define BCM_REFERENCE(data) ((void)(data))
  41. #include <linux/compiler.h>
  42. /* Allow for suppressing unused variable warnings. */
  43. #ifdef __GNUC__
  44. #define UNUSED_VAR __attribute__ ((unused))
  45. #else
  46. #define UNUSED_VAR
  47. #endif // endif
  48. /* GNU GCC 4.6+ supports selectively turning off a warning.
  49. * Define these diagnostic macros to help suppress cast-qual warning
  50. * until all the work can be done to fix the casting issues.
  51. */
  52. #if (defined(__GNUC__) && defined(STRICT_GCC_WARNINGS) && (__GNUC__ > 4 || (__GNUC__ == \
  53. 4 && __GNUC_MINOR__ >= 6)))
  54. #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST() \
  55. _Pragma("GCC diagnostic push") \
  56. _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
  57. #define GCC_DIAGNOSTIC_POP() \
  58. _Pragma("GCC diagnostic pop")
  59. #else
  60. #define GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST()
  61. #define GCC_DIAGNOSTIC_POP()
  62. #endif /* Diagnostic macros not defined */
  63. /* Support clang for MACOSX compiler */
  64. #ifdef __clang__
  65. #define CLANG_DIAGNOSTIC_PUSH_SUPPRESS_CAST() \
  66. _Pragma("clang diagnostic push") \
  67. _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
  68. #define CLANG_DIAGNOSTIC_PUSH_SUPPRESS_FORMAT() \
  69. _Pragma("clang diagnostic push") \
  70. _Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"")
  71. #define CLANG_DIAGNOSTIC_POP() \
  72. _Pragma("clang diagnostic pop")
  73. #else
  74. #define CLANG_DIAGNOSTIC_PUSH_SUPPRESS_CAST()
  75. #define CLANG_DIAGNOSTIC_PUSH_SUPPRESS_FORMAT()
  76. #define CLANG_DIAGNOSTIC_POP()
  77. #endif // endif
  78. /* Compile-time assert can be used in place of ASSERT if the expression evaluates
  79. * to a constant at compile time.
  80. */
  81. #if (__GNUC__ <= 4 && __GNUC_MINOR__ >= 4)
  82. #define STATIC_ASSERT(expr) { \
  83. /* Make sure the expression is constant. */ \
  84. typedef enum { _STATIC_ASSERT_NOT_CONSTANT = (expr) } _static_assert_e UNUSED_VAR; \
  85. /* Make sure the expression is true. */ \
  86. typedef char STATIC_ASSERT_FAIL[(expr) ? 1 : -1] UNUSED_VAR; \
  87. }
  88. #else
  89. #define STATIC_ASSERT(expr) compiletime_assert(expr, "Compile time condition failure");
  90. #endif /* __GNUC__ <= 4 && __GNUC_MINOR__ >= 4 */
  91. /* Reclaiming text and data :
  92. * The following macros specify special linker sections that can be reclaimed
  93. * after a system is considered 'up'.
  94. * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN,
  95. * as in most cases, the attach function calls the detach function to clean up on error).
  96. */
  97. #if defined(BCM_RECLAIM)
  98. extern bool bcm_reclaimed;
  99. extern bool bcm_attach_part_reclaimed;
  100. extern bool bcm_preattach_part_reclaimed;
  101. extern bool bcm_postattach_part_reclaimed;
  102. #define RECLAIMED() (bcm_reclaimed)
  103. #define ATTACH_PART_RECLAIMED() (bcm_attach_part_reclaimed)
  104. #define PREATTACH_PART_RECLAIMED() (bcm_preattach_part_reclaimed)
  105. #define POSTATTACH_PART_RECLAIMED() (bcm_postattach_part_reclaimed)
  106. #if defined(BCM_RECLAIM_ATTACH_FN_DATA)
  107. #define _data __attribute__ ((__section__ (".dataini2." #_data))) _data
  108. #define _fn __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
  109. /* Relocate attach symbols to save-restore region to increase pre-reclaim heap size. */
  110. #define BCM_SRM_ATTACH_DATA(_data) __attribute__ ((__section__ (".datasrm." #_data))) _data
  111. #define BCM_SRM_ATTACH_FN(_fn) __attribute__ ((__section__ (".textsrm." #_fn), noinline)) _fn
  112. #ifndef PREATTACH_NORECLAIM
  113. #define BCMPREATTACHDATA(_data) __attribute__ ((__section__ (".dataini3." #_data))) _data
  114. #define BCMPREATTACHFN(_fn) __attribute__ ((__section__ (".textini3." #_fn), noinline)) _fn
  115. #else
  116. #define BCMPREATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data
  117. #define BCMPREATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
  118. #endif /* PREATTACH_NORECLAIM */
  119. #define BCMPOSTATTACHDATA(_data) __attribute__ ((__section__ (".dataini5." #_data))) _data
  120. #define BCMPOSTATTACHFN(_fn) __attribute__ ((__section__ (".textini5." #_fn), noinline)) _fn
  121. #else /* BCM_RECLAIM_ATTACH_FN_DATA */
  122. #define _data _data
  123. #define _fn _fn
  124. #define BCMPREATTACHDATA(_data) _data
  125. #define BCMPREATTACHFN(_fn) _fn
  126. #define BCMPOSTATTACHDATA(_data) _data
  127. #define BCMPOSTATTACHFN(_fn) _fn
  128. #endif /* BCM_RECLAIM_ATTACH_FN_DATA */
  129. #ifdef BCMDBG_SR
  130. /*
  131. * Don't reclaim so we can compare SR ASM
  132. */
  133. #define BCMPREATTACHDATASR(_data) _data
  134. #define BCMPREATTACHFNSR(_fn) _fn
  135. #define BCMATTACHDATASR(_data) _data
  136. #define BCMATTACHFNSR(_fn) _fn
  137. #else
  138. #define BCMPREATTACHDATASR(_data) BCMPREATTACHDATA(_data)
  139. #define BCMPREATTACHFNSR(_fn) BCMPREATTACHFN(_fn)
  140. #define BCMATTACHDATASR(_data) _data
  141. #define BCMATTACHFNSR(_fn) _fn
  142. #endif // endif
  143. #if defined(BCM_RECLAIM_INIT_FN_DATA)
  144. #define _data __attribute__ ((__section__ (".dataini1." #_data))) _data
  145. #define _fn __attribute__ ((__section__ (".textini1." #_fn), noinline)) _fn
  146. #define CONST
  147. #else /* BCM_RECLAIM_INIT_FN_DATA */
  148. #define _data _data
  149. #define _fn _fn
  150. #ifndef CONST
  151. #define CONST const
  152. #endif // endif
  153. #endif /* BCM_RECLAIM_INIT_FN_DATA */
  154. /* Non-manufacture or internal attach function/dat */
  155. #define BCMNMIATTACHFN(_fn) _fn
  156. #define BCMNMIATTACHDATA(_data) _data
  157. #if defined(BCM_CISDUMP_NO_RECLAIM)
  158. #define BCMCISDUMPATTACHFN(_fn) _fn
  159. #define BCMCISDUMPATTACHDATA(_data) _data
  160. #else
  161. #define BCMCISDUMPATTACHFN(_fn) BCMNMIATTACHFN(_fn)
  162. #define BCMCISDUMPATTACHDATA(_data) BCMNMIATTACHDATA(_data)
  163. #endif // endif
  164. /* SROM with OTP support */
  165. #if defined(BCMOTPSROM)
  166. #define BCMSROMATTACHFN(_fn) _fn
  167. #define BCMSROMATTACHDATA(_data) _data
  168. #else
  169. #define BCMSROMATTACHFN(_fn) BCMNMIATTACHFN(_fn)
  170. #define BCMSROMATTACHDATA(_data) BCMNMIATTACHFN(_data)
  171. #endif /* BCMOTPSROM */
  172. #if defined(BCM_CISDUMP_NO_RECLAIM)
  173. #define BCMSROMCISDUMPATTACHFN(_fn) _fn
  174. #define BCMSROMCISDUMPATTACHDATA(_data) _data
  175. #else
  176. #define BCMSROMCISDUMPATTACHFN(_fn) BCMSROMATTACHFN(_fn)
  177. #define BCMSROMCISDUMPATTACHDATA(_data) BCMSROMATTACHDATA(_data)
  178. #endif /* BCM_CISDUMP_NO_RECLAIM */
  179. #ifdef BCMNODOWN
  180. #define _fn _fn
  181. #else
  182. #define _fn _fn
  183. #endif // endif
  184. #else /* BCM_RECLAIM */
  185. #define bcm_reclaimed (1)
  186. #define bcm_attach_part_reclaimed (1)
  187. #define bcm_preattach_part_reclaimed (1)
  188. #define bcm_postattach_part_reclaimed (1)
  189. #define _data _data
  190. #define _fn _fn
  191. #define BCM_SRM_ATTACH_DATA(_data) _data
  192. #define BCM_SRM_ATTACH_FN(_fn) _fn
  193. #define BCMPREATTACHDATA(_data) _data
  194. #define BCMPREATTACHFN(_fn) _fn
  195. #define BCMPOSTATTACHDATA(_data) _data
  196. #define BCMPOSTATTACHFN(_fn) _fn
  197. #define _data _data
  198. #define _fn _fn
  199. #define _fn _fn
  200. #define BCMNMIATTACHFN(_fn) _fn
  201. #define BCMNMIATTACHDATA(_data) _data
  202. #define BCMSROMATTACHFN(_fn) _fn
  203. #define BCMSROMATTACHDATA(_data) _data
  204. #define BCMPREATTACHFNSR(_fn) _fn
  205. #define BCMPREATTACHDATASR(_data) _data
  206. #define BCMATTACHFNSR(_fn) _fn
  207. #define BCMATTACHDATASR(_data) _data
  208. #define BCMSROMATTACHFN(_fn) _fn
  209. #define BCMSROMATTACHDATA(_data) _data
  210. #define BCMCISDUMPATTACHFN(_fn) _fn
  211. #define BCMCISDUMPATTACHDATA(_data) _data
  212. #define BCMSROMCISDUMPATTACHFN(_fn) _fn
  213. #define BCMSROMCISDUMPATTACHDATA(_data) _data
  214. #define CONST const
  215. #define RECLAIMED() (bcm_reclaimed)
  216. #define ATTACH_PART_RECLAIMED() (bcm_attach_part_reclaimed)
  217. #define PREATTACH_PART_RECLAIMED() (bcm_preattach_part_reclaimed)
  218. #define POSTATTACH_PART_RECLAIMED() (bcm_postattach_part_reclaimed)
  219. #endif /* BCM_RECLAIM */
  220. #define BCMUCODEDATA(_data) _data
  221. #if defined(BCM_DMA_CT) && !defined(BCM_DMA_CT_DISABLED)
  222. #define BCMUCODEFN(_fn) _fn
  223. #else
  224. #define BCMUCODEFN(_fn) _fn
  225. #endif /* BCM_DMA_CT */
  226. #if !defined STB
  227. #if defined(BCM47XX) && defined(__ARM_ARCH_7A__) && !defined(OEM_ANDROID)
  228. #define BCM47XX_CA9
  229. #else
  230. #undef BCM47XX_CA9
  231. #endif /* BCM47XX && __ARM_ARCH_7A__ && !OEM_ANDROID */
  232. #endif /* STB */
  233. /* BCMFASTPATH Related Macro defines
  234. */
  235. #ifndef BCMFASTPATH
  236. #if defined(STB)
  237. #define BCMFASTPATH __attribute__ ((__section__ (".text.fastpath")))
  238. #define BCMFASTPATH_HOST __attribute__ ((__section__ (".text.fastpath_host")))
  239. #else /* mips || BCM47XX_CA9 || STB */
  240. #define BCMFASTPATH
  241. #define BCMFASTPATH_HOST
  242. #endif // endif
  243. #endif /* BCMFASTPATH */
  244. /* Use the BCMRAMFN() macro to tag functions in source that must be included in RAM (excluded from
  245. * ROM). This should eliminate the need to manually specify these functions in the ROM config file.
  246. * It should only be used in special cases where the function must be in RAM for *all* ROM-based
  247. * chips.
  248. */
  249. #define BCMRAMFN(_fn) _fn
  250. /* Use BCMSPECSYM() macro to tag symbols going to a special output section in the binary. */
  251. #define BCMSPECSYM(_sym) __attribute__ ((__section__ (".special." #_sym))) _sym
  252. #define STATIC static
  253. /* Bus types */
  254. #define SI_BUS 0 /* SOC Interconnect */
  255. #define PCI_BUS 1 /* PCI target */
  256. #define PCMCIA_BUS 2 /* PCMCIA target */
  257. #define SDIO_BUS 3 /* SDIO target */
  258. #define JTAG_BUS 4 /* JTAG */
  259. #define USB_BUS 5 /* USB (does not support R/W REG) */
  260. #define SPI_BUS 6 /* gSPI target */
  261. #define RPC_BUS 7 /* RPC target */
  262. /* Allows size optimization for single-bus image */
  263. #ifdef BCMBUSTYPE
  264. #define BUSTYPE(bus) (BCMBUSTYPE)
  265. #else
  266. #define BUSTYPE(bus) (bus)
  267. #endif // endif
  268. #ifdef BCMBUSCORETYPE
  269. #define BUSCORETYPE(ct) (BCMBUSCORETYPE)
  270. #else
  271. #define BUSCORETYPE(ct) (ct)
  272. #endif // endif
  273. /* Allows size optimization for single-backplane image */
  274. #ifdef BCMCHIPTYPE
  275. #define CHIPTYPE(bus) (BCMCHIPTYPE)
  276. #else
  277. #define CHIPTYPE(bus) (bus)
  278. #endif // endif
  279. /* Allows size optimization for SPROM support */
  280. #if defined(BCMSPROMBUS)
  281. #define SPROMBUS (BCMSPROMBUS)
  282. #elif defined(SI_PCMCIA_SROM)
  283. #define SPROMBUS (PCMCIA_BUS)
  284. #else
  285. #define SPROMBUS (PCI_BUS)
  286. #endif // endif
  287. /* Allows size optimization for single-chip image */
  288. #ifdef BCMCHIPID
  289. #define CHIPID(chip) (BCMCHIPID)
  290. #else
  291. #define CHIPID(chip) (chip)
  292. #endif // endif
  293. #ifdef BCMCHIPREV
  294. #define CHIPREV(rev) (BCMCHIPREV)
  295. #else
  296. #define CHIPREV(rev) (rev)
  297. #endif // endif
  298. #ifdef BCMPCIEREV
  299. #define PCIECOREREV(rev) (BCMPCIEREV)
  300. #else
  301. #define PCIECOREREV(rev) (rev)
  302. #endif // endif
  303. #ifdef BCMPMUREV
  304. #define PMUREV(rev) (BCMPMUREV)
  305. #else
  306. #define PMUREV(rev) (rev)
  307. #endif // endif
  308. #ifdef BCMCCREV
  309. #define CCREV(rev) (BCMCCREV)
  310. #else
  311. #define CCREV(rev) (rev)
  312. #endif // endif
  313. #ifdef BCMGCIREV
  314. #define GCIREV(rev) (BCMGCIREV)
  315. #else
  316. #define GCIREV(rev) (rev)
  317. #endif // endif
  318. #ifdef BCMCR4REV
  319. #define CR4REV (BCMCR4REV)
  320. #endif // endif
  321. /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
  322. #define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */
  323. #define DMADDR_MASK_30 0xc0000000 /* Address mask for 30-bits */
  324. #define DMADDR_MASK_26 0xFC000000 /* Address maks for 26-bits */
  325. #define DMADDR_MASK_0 0xffffffff /* Address mask for 0-bits (hi-part) */
  326. #define DMADDRWIDTH_26 26 /* 26-bit addressing capability */
  327. #define DMADDRWIDTH_30 30 /* 30-bit addressing capability */
  328. #define DMADDRWIDTH_32 32 /* 32-bit addressing capability */
  329. #define DMADDRWIDTH_63 63 /* 64-bit addressing capability */
  330. #define DMADDRWIDTH_64 64 /* 64-bit addressing capability */
  331. typedef struct {
  332. uint32 loaddr;
  333. uint32 hiaddr;
  334. } dma64addr_t;
  335. #define PHYSADDR64HI(_pa) ((_pa).hiaddr)
  336. #define PHYSADDR64HISET(_pa, _val) \
  337. do { \
  338. (_pa).hiaddr = (_val); \
  339. } while (0)
  340. #define PHYSADDR64LO(_pa) ((_pa).loaddr)
  341. #define PHYSADDR64LOSET(_pa, _val) \
  342. do { \
  343. (_pa).loaddr = (_val); \
  344. } while (0)
  345. #ifdef BCMDMA64OSL
  346. typedef dma64addr_t dmaaddr_t;
  347. #define PHYSADDRHI(_pa) PHYSADDR64HI(_pa)
  348. #define PHYSADDRHISET(_pa, _val) PHYSADDR64HISET(_pa, _val)
  349. #define PHYSADDRLO(_pa) PHYSADDR64LO(_pa)
  350. #define PHYSADDRLOSET(_pa, _val) PHYSADDR64LOSET(_pa, _val)
  351. #define PHYSADDRTOULONG(_pa, _ulong) \
  352. do { \
  353. _ulong = ((unsigned long long)(_pa).hiaddr << 32) | ((_pa).loaddr); \
  354. } while (0)
  355. #else
  356. typedef unsigned long dmaaddr_t;
  357. #define PHYSADDRHI(_pa) (0)
  358. #define PHYSADDRHISET(_pa, _val)
  359. #define PHYSADDRLO(_pa) ((_pa))
  360. #define PHYSADDRLOSET(_pa, _val) \
  361. do { \
  362. (_pa) = (_val); \
  363. } while (0)
  364. #endif /* BCMDMA64OSL */
  365. #define PHYSADDRISZERO(_pa) (PHYSADDRLO(_pa) == 0 && PHYSADDRHI(_pa) == 0)
  366. /* One physical DMA segment */
  367. typedef struct {
  368. dmaaddr_t addr;
  369. uint32 length;
  370. } hnddma_seg_t;
  371. #define MAX_DMA_SEGS 8
  372. typedef struct {
  373. void *oshdmah; /* Opaque handle for OSL to store its information */
  374. uint origsize; /* Size of the virtual packet */
  375. uint nsegs;
  376. hnddma_seg_t segs[MAX_DMA_SEGS];
  377. } hnddma_seg_map_t;
  378. /* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF).
  379. * By doing, we avoid the need to allocate an extra buffer for the header when bridging to WL.
  380. * There is a compile time check in wlc.c which ensure that this value is at least as big
  381. * as TXOFF. This value is used in dma_rxfill (hnddma.c).
  382. */
  383. #if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY)
  384. /* add 40 bytes to allow for extra RPC header and info */
  385. #define BCMEXTRAHDROOM 260
  386. #else /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
  387. #if defined(STB)
  388. #define BCMEXTRAHDROOM 224
  389. #else
  390. #define BCMEXTRAHDROOM 204
  391. #endif // endif
  392. #endif /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
  393. /* Packet alignment for most efficient SDIO (can change based on platform) */
  394. #ifndef SDALIGN
  395. #define SDALIGN 32
  396. #endif // endif
  397. /* Headroom required for dongle-to-host communication. Packets allocated
  398. * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
  399. * leave this much room in front for low-level message headers which may
  400. * be needed to get across the dongle bus to the host. (These messages
  401. * don't go over the network, so room for the full WL header above would
  402. * be a waste.).
  403. */
  404. #define BCMDONGLEHDRSZ 12
  405. #define BCMDONGLEPADSZ 16
  406. #define BCMDONGLEOVERHEAD (BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
  407. #if defined(NO_BCMDBG_ASSERT)
  408. # undef BCMDBG_ASSERT
  409. # undef BCMASSERT_LOG
  410. #endif // endif
  411. #if defined(BCMASSERT_LOG)
  412. #define BCMASSERT_SUPPORT
  413. #endif // endif
  414. /* Macros for doing definition and get/set of bitfields
  415. * Usage example, e.g. a three-bit field (bits 4-6):
  416. * #define <NAME>_M BITFIELD_MASK(3)
  417. * #define <NAME>_S 4
  418. * ...
  419. * regval = R_REG(osh, &regs->regfoo);
  420. * field = GFIELD(regval, <NAME>);
  421. * regval = SFIELD(regval, <NAME>, 1);
  422. * W_REG(osh, &regs->regfoo, regval);
  423. */
  424. #define BITFIELD_MASK(width) \
  425. (((unsigned)1 << (width)) - 1)
  426. #define GFIELD(val, field) \
  427. (((val) >> field ## _S) & field ## _M)
  428. #define SFIELD(val, field, bits) \
  429. (((val) & (~(field ## _M << field ## _S))) | \
  430. ((unsigned)(bits) << field ## _S))
  431. /* define BCMSMALL to remove misc features for memory-constrained environments */
  432. #ifdef BCMSMALL
  433. #undef BCMSPACE
  434. #define bcmspace FALSE /* if (bcmspace) code is discarded */
  435. #else
  436. #define BCMSPACE
  437. #define bcmspace TRUE /* if (bcmspace) code is retained */
  438. #endif // endif
  439. /* Max. nvram variable table size */
  440. #ifndef MAXSZ_NVRAM_VARS
  441. #ifdef LARGE_NVRAM_MAXSZ
  442. #define MAXSZ_NVRAM_VARS (LARGE_NVRAM_MAXSZ * 2)
  443. #else
  444. #define LARGE_NVRAM_MAXSZ 8192
  445. #define MAXSZ_NVRAM_VARS (LARGE_NVRAM_MAXSZ * 2)
  446. #endif /* LARGE_NVRAM_MAXSZ */
  447. #endif /* !MAXSZ_NVRAM_VARS */
  448. /* ROM_ENAB_RUNTIME_CHECK may be set based upon the #define below (for ROM builds). It may also
  449. * be defined via makefiles (e.g. ROM auto abandon unoptimized compiles).
  450. */
  451. #ifdef BCMLFRAG /* BCMLFRAG support enab macros */
  452. extern bool _bcmlfrag;
  453. #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
  454. #define BCMLFRAG_ENAB() (_bcmlfrag)
  455. #elif defined(BCMLFRAG_DISABLED)
  456. #define BCMLFRAG_ENAB() (0)
  457. #else
  458. #define BCMLFRAG_ENAB() (1)
  459. #endif
  460. #else
  461. #define BCMLFRAG_ENAB() (0)
  462. #endif /* BCMLFRAG_ENAB */
  463. #ifdef BCMPCIEDEV /* BCMPCIEDEV support enab macros */
  464. extern bool _pciedevenab;
  465. #if defined(ROM_ENAB_RUNTIME_CHECK)
  466. #define BCMPCIEDEV_ENAB() (_pciedevenab)
  467. #elif defined(BCMPCIEDEV_ENABLED)
  468. #define BCMPCIEDEV_ENAB() 1
  469. #else
  470. #define BCMPCIEDEV_ENAB() 0
  471. #endif
  472. #else
  473. #define BCMPCIEDEV_ENAB() 0
  474. #endif /* BCMPCIEDEV */
  475. #ifdef BCMRESVFRAGPOOL /* BCMRESVFRAGPOOL support enab macros */
  476. extern bool _resvfragpool_enab;
  477. #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
  478. #define BCMRESVFRAGPOOL_ENAB() (_resvfragpool_enab)
  479. #elif defined(BCMRESVFRAGPOOL_ENABLED)
  480. #define BCMRESVFRAGPOOL_ENAB() 1
  481. #else
  482. #define BCMRESVFRAGPOOL_ENAB() 0
  483. #endif
  484. #else
  485. #define BCMRESVFRAGPOOL_ENAB() 0
  486. #endif /* BCMPCIEDEV */
  487. #define BCMSDIODEV_ENAB() 0
  488. /* Max size for reclaimable NVRAM array */
  489. #ifdef DL_NVRAM
  490. #define NVRAM_ARRAY_MAXSIZE DL_NVRAM
  491. #else
  492. #define NVRAM_ARRAY_MAXSIZE MAXSZ_NVRAM_VARS
  493. #endif /* DL_NVRAM */
  494. extern uint32 gFWID;
  495. #ifdef BCMFRWDPOOLREORG /* BCMFRWDPOOLREORG support enab macros */
  496. extern bool _bcmfrwdpoolreorg;
  497. #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
  498. #define BCMFRWDPOOLREORG_ENAB() (_bcmfrwdpoolreorg)
  499. #elif defined(BCMFRWDPOOLREORG_DISABLED)
  500. #define BCMFRWDPOOLREORG_ENAB() (0)
  501. #else
  502. #define BCMFRWDPOOLREORG_ENAB() (1)
  503. #endif
  504. #else
  505. #define BCMFRWDPOOLREORG_ENAB() (0)
  506. #endif /* BCMFRWDPOOLREORG */
  507. #ifdef BCMPOOLRECLAIM /* BCMPOOLRECLAIM support enab macros */
  508. extern bool _bcmpoolreclaim;
  509. #if defined(ROM_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
  510. #define BCMPOOLRECLAIM_ENAB() (_bcmpoolreclaim)
  511. #elif defined(BCMPOOLRECLAIM_DISABLED)
  512. #define BCMPOOLRECLAIM_ENAB() (0)
  513. #else
  514. #define BCMPOOLRECLAIM_ENAB() (1)
  515. #endif
  516. #else
  517. #define BCMPOOLRECLAIM_ENAB() (0)
  518. #endif /* BCMPOOLRECLAIM */
  519. /* Chip related low power flags (lpflags) */
  520. #ifndef PAD
  521. #define _PADLINE(line) pad ## line
  522. #define _XSTR(line) _PADLINE(line)
  523. #define PAD _XSTR(__LINE__)
  524. #endif // endif
  525. #ifndef FRAG_HEADROOM
  526. #define FRAG_HEADROOM 224 /* In absence of SFD, use default headroom of 224 */
  527. #endif // endif
  528. #define MODULE_DETACH(var, detach_func)\
  529. if (var) { \
  530. detach_func(var); \
  531. (var) = NULL; \
  532. }
  533. #define MODULE_DETACH_2(var1, var2, detach_func) detach_func(var1, var2)
  534. #define MODULE_DETACH_TYPECASTED(var, detach_func) detach_func(var)
  535. /* When building ROML image use runtime conditional to cause the compiler
  536. * to compile everything but not to complain "defined but not used"
  537. * as #ifdef would cause at the callsites.
  538. * In the end functions called under if (0) {} will not be linked
  539. * into the final binary if they're not called from other places either.
  540. */
  541. #define BCM_ATTACH_REF_DECL()
  542. #define BCM_ATTACH_REF() (1)
  543. /* Const in ROM else normal data in RAM */
  544. #if defined(ROM_ENAB_RUNTIME_CHECK)
  545. #define ROMCONST CONST
  546. #else
  547. #define ROMCONST
  548. #endif // endif
  549. #endif /* _bcmdefs_h_ */