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