1/* 2 * Misc system wide definitions 3 * 4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $Id: bcmdefs.h,v 13.69.10.2 2010/10/05 00:46:12 Exp $ 19 */ 20 21#ifndef _bcmdefs_h_ 22#define _bcmdefs_h_ 23 24/* 25 * One doesn't need to include this file explicitly, gets included automatically if 26 * typedefs.h is included. 27 */ 28 29/* Use BCM_REFERENCE to suppress warnings about intentionally-unused function 30 * arguments or local variables. 31 */ 32#define BCM_REFERENCE(data) ((void)data) 33 34/* Reclaiming text and data : 35 * The following macros specify special linker sections that can be reclaimed 36 * after a system is considered 'up'. 37 * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN, 38 * as in most cases, the attach function calls the detach function to clean up on error). 39 */ 40#ifdef DONGLEBUILD 41 42extern bool bcmreclaimed; 43 44#define BCMATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data 45#define BCMATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn 46 47#define BCMPREATTACHDATA(_data) __attribute__ ((__section__ (".dataini2." #_data))) _data 48#define BCMPREATTACHFN(_fn) __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn 49 50#if defined(BCMRECLAIM) 51#define BCMINITDATA(_data) __attribute__ ((__section__ (".dataini1." #_data))) _data 52#define BCMINITFN(_fn) __attribute__ ((__section__ (".textini1." #_fn), noinline)) _fn 53#define CONST 54#else 55#define BCMINITDATA(_data) _data 56#define BCMINITFN(_fn) _fn 57#define CONST const 58#endif 59 60/* Non-manufacture or internal attach function/dat */ 61#if !defined(WLTEST) 62#define BCMNMIATTACHFN(_fn) BCMATTACHFN(_fn) 63#define BCMNMIATTACHDATA(_data) BCMATTACHDATA(_data) 64#else 65#define BCMNMIATTACHFN(_fn) _fn 66#define BCMNMIATTACHDATA(_data) _data 67#endif 68 69#define BCMUNINITFN(_fn) _fn 70 71#define BCMFASTPATH 72 73#ifdef DONGLEOVERLAYS 74#define BCMOVERLAY0DATA(_sym) __attribute__ ((__section__ (".r0overlay." #_sym))) _sym 75#define BCMOVERLAY0FN(_fn) __attribute__ ((__section__ (".r0overlay." #_fn))) _fn 76#define BCMOVERLAY1DATA(_sym) __attribute__ ((__section__ (".r1overlay." #_sym))) _sym 77#define BCMOVERLAY1FN(_fn) __attribute__ ((__section__ (".r1overlay." #_fn))) _fn 78#define BCMOVERLAYERRFN(_fn) __attribute__ ((__section__ (".overlayerr." #_fn))) _fn 79#else 80#define BCMOVERLAY0DATA(_sym) _sym 81#define BCMOVERLAY0FN(_fn) _fn 82#define BCMOVERLAY1DATA(_sym) _sym 83#define BCMOVERLAY1FN(_fn) _fn 84#define BCMOVERLAYERRFN(_fn) _fn 85#endif /* DONGLEOVERLAYS */ 86 87#else /* DONGLEBUILD */ 88 89#define bcmreclaimed 0 90#define BCMATTACHDATA(_data) _data 91#define BCMATTACHFN(_fn) _fn 92#define BCMPREATTACHDATA(_data) _data 93#define BCMPREATTACHFN(_fn) _fn 94#define BCMINITDATA(_data) _data 95#define BCMINITFN(_fn) _fn 96#define BCMUNINITFN(_fn) _fn 97#define BCMNMIATTACHFN(_fn) _fn 98#define BCMNMIATTACHDATA(_data) _data 99#define BCMOVERLAY0DATA(_sym) _sym 100#define BCMOVERLAY0FN(_fn) _fn 101#define BCMOVERLAY1DATA(_sym) _sym 102#define BCMOVERLAY1FN(_fn) _fn 103#define BCMOVERLAYERRFN(_fn) _fn 104#define CONST const 105#ifdef mips 106#define BCMFASTPATH __attribute__ ((__section__(".text.fastpath"))) 107#else 108#define BCMFASTPATH 109#endif 110 111#endif /* DONGLEBUILD */ 112 113#if defined(BCMROMBUILD) 114typedef struct { 115 uint16 esiz; 116 uint16 cnt; 117 void *addr; 118} bcmromdat_patch_t; 119#endif 120 121/* Put some library data/code into ROM to reduce RAM requirements */ 122#if defined(BCMROMBUILD) 123#include <bcmjmptbl.h> 124#define STATIC static 125#else /* !BCMROMBUILD */ 126#define BCMROMDATA(_data) _data 127#define BCMROMDAT_NAME(_data) _data 128#define BCMROMFN(_fn) _fn 129#define BCMROMFN_NAME(_fn) _fn 130#define STATIC static 131#define BCMROMDAT_ARYSIZ(data) ARRAYSIZE(data) 132#define BCMROMDAT_SIZEOF(data) sizeof(data) 133#define BCMROMDAT_APATCH(data) 134#define BCMROMDAT_SPATCH(data) 135#endif /* !BCMROMBUILD */ 136 137/* overlay function tagging */ 138#ifdef DONGLEBUILD 139#ifdef DONGLEOVERLAYS 140/* force a func to be inline if it's only accessed by overlays and ATTACH code */ 141#define OVERLAY_INLINE __attribute__ ((always_inline)) 142#define OSTATIC 143#define BCMOVERLAYDATA(_ovly, _sym) \ 144 __attribute__ ((aligned(4), __section__ (".r" #_ovly "overlay." #_sym))) _sym 145#define BCMOVERLAYFN(_ovly, _fn) \ 146 __attribute__ ((__section__ (".r" #_ovly "overlay." #_fn))) _fn 147#define BCMOVERLAYERRFN(_fn) \ 148 __attribute__ ((__section__ (".overlayerr." #_fn))) _fn 149#define BCMROMOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym) 150#define BCMROMOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn) 151#define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym) 152#define BCMATTACHOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn) 153#define BCMINITOVERLAYDATA(_ovly, _sym) BCMOVERLAYDATA(_ovly, _sym) 154#define BCMINITOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn) 155#define BCMUNINITOVERLAYFN(_ovly, _fn) BCMOVERLAYFN(_ovly, _fn) 156#else 157#define OVERLAY_INLINE 158#define OSTATIC static 159#define BCMOVERLAYDATA(_ovly, _sym) _sym 160#define BCMOVERLAYFN(_ovly, _fn) _fn 161#define BCMOVERLAYERRFN(_fn) _fn 162/* revert to standard definitions for BCMATTACH* and BCMINIT* if not overlay build */ 163#define BCMROMOVERLAYDATA(_ovly, _data) BCMROMDATA(_data) 164#define BCMROMOVERLAYFN(_ovly, _fn) BCMROMFN(_fn) 165#define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMATTACHDATA(_sym) 166#define BCMATTACHOVERLAYFN(_ovly, _fn) BCMATTACHFN(_fn) 167#define BCMINITOVERLAYDATA(_ovly, _sym) BCMINITDATA(_sym) 168#define BCMINITOVERLAYFN(_ovly, _fn) BCMINITFN(_fn) 169#define BCMUNINITOVERLAYFN(_ovly, _fn) BCMUNINITFN(_fn) 170#endif /* DONGLEOVERLAYS */ 171 172#else 173 174#define OVERLAY_INLINE 175#define OSTATIC static 176#define BCMOVERLAYDATA(_ovly, _sym) _sym 177#define BCMOVERLAYFN(_ovly, _fn) _fn 178#define BCMOVERLAYERRFN(_fn) _fn 179#define BCMROMOVERLAYDATA(_ovly, _data) BCMROMDATA(_data) 180#define BCMROMOVERLAYFN(_ovly, _fn) BCMROMFN(_fn) 181#define BCMATTACHOVERLAYDATA(_ovly, _sym) BCMATTACHDATA(_sym) 182#define BCMATTACHOVERLAYFN(_ovly, _fn) BCMATTACHFN(_fn) 183#define BCMINITOVERLAYDATA(_ovly, _sym) BCMINITDATA(_sym) 184#define BCMINITOVERLAYFN(_ovly, _fn) BCMINITFN(_fn) 185#define BCMUNINITOVERLAYFN(_ovly, _fn) BCMUNINITFN(_fn) 186 187#endif /* DONGLEBUILD */ 188 189/* Bus types */ 190#define SI_BUS 0 /* SOC Interconnect */ 191#define PCI_BUS 1 /* PCI target */ 192#define PCMCIA_BUS 2 /* PCMCIA target */ 193#define SDIO_BUS 3 /* SDIO target */ 194#define JTAG_BUS 4 /* JTAG */ 195#define USB_BUS 5 /* USB (does not support R/W REG) */ 196#define SPI_BUS 6 /* gSPI target */ 197#define RPC_BUS 7 /* RPC target */ 198 199/* Allows size optimization for single-bus image */ 200#ifdef BCMBUSTYPE 201#define BUSTYPE(bus) (BCMBUSTYPE) 202#else 203#define BUSTYPE(bus) (bus) 204#endif 205 206/* Allows size optimization for single-backplane image */ 207#ifdef BCMCHIPTYPE 208#define CHIPTYPE(bus) (BCMCHIPTYPE) 209#else 210#define CHIPTYPE(bus) (bus) 211#endif 212 213 214/* Allows size optimization for SPROM support */ 215#if defined(BCMSPROMBUS) 216#define SPROMBUS (BCMSPROMBUS) 217#elif defined(SI_PCMCIA_SROM) 218#define SPROMBUS (PCMCIA_BUS) 219#else 220#define SPROMBUS (PCI_BUS) 221#endif 222 223/* Allows size optimization for single-chip image */ 224#ifdef BCMCHIPID 225#define CHIPID(chip) (BCMCHIPID) 226#else 227#define CHIPID(chip) (chip) 228#endif 229 230#ifdef BCMCHIPREV 231#define CHIPREV(rev) (BCMCHIPREV) 232#else 233#define CHIPREV(rev) (rev) 234#endif 235 236/* Defines for DMA Address Width - Shared between OSL and HNDDMA */ 237#define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */ 238#define DMADDR_MASK_30 0xc0000000 /* Address mask for 30-bits */ 239#define DMADDR_MASK_0 0xffffffff /* Address mask for 0-bits (hi-part) */ 240 241#define DMADDRWIDTH_30 30 /* 30-bit addressing capability */ 242#define DMADDRWIDTH_32 32 /* 32-bit addressing capability */ 243#define DMADDRWIDTH_63 63 /* 64-bit addressing capability */ 244#define DMADDRWIDTH_64 64 /* 64-bit addressing capability */ 245 246#ifdef BCMDMA64OSL 247typedef struct { 248 uint32 loaddr; 249 uint32 hiaddr; 250} dma64addr_t; 251 252typedef dma64addr_t dmaaddr_t; 253#define PHYSADDRHI(_pa) ((_pa).hiaddr) 254#define PHYSADDRHISET(_pa, _val) \ 255 do { \ 256 (_pa).hiaddr = (_val); \ 257 } while (0) 258#define PHYSADDRLO(_pa) ((_pa).loaddr) 259#define PHYSADDRLOSET(_pa, _val) \ 260 do { \ 261 (_pa).loaddr = (_val); \ 262 } while (0) 263 264#else 265typedef unsigned long dmaaddr_t; 266#define PHYSADDRHI(_pa) (0) 267#define PHYSADDRHISET(_pa, _val) 268#define PHYSADDRLO(_pa) ((_pa)) 269#define PHYSADDRLOSET(_pa, _val) \ 270 do { \ 271 (_pa) = (_val); \ 272 } while (0) 273#endif /* BCMDMA64OSL */ 274 275/* One physical DMA segment */ 276typedef struct { 277 dmaaddr_t addr; 278 uint32 length; 279} hnddma_seg_t; 280 281#if defined(MACOSX) 282/* In MacOS, the OS API may return large number of segments. Setting this number lower 283 * will result in failure of dma map 284 */ 285#define MAX_DMA_SEGS 8 286#else 287#define MAX_DMA_SEGS 4 288#endif 289 290 291typedef struct { 292 void *oshdmah; /* Opaque handle for OSL to store its information */ 293 uint origsize; /* Size of the virtual packet */ 294 uint nsegs; 295 hnddma_seg_t segs[MAX_DMA_SEGS]; 296} hnddma_seg_map_t; 297 298 299/* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF). 300 * By doing, we avoid the need to allocate an extra buffer for the header when bridging to WL. 301 * There is a compile time check in wlc.c which ensure that this value is at least as big 302 * as TXOFF. This value is used in dma_rxfill (hnddma.c). 303 */ 304 305#if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY) 306/* add 40 bytes to allow for extra RPC header and info */ 307#define BCMEXTRAHDROOM 220 308#else 309#define BCMEXTRAHDROOM 172 310#endif 311 312/* Packet alignment for most efficient SDIO (can change based on platform) */ 313#ifndef SDALIGN 314#define SDALIGN 32 315#endif 316 317/* Headroom required for dongle-to-host communication. Packets allocated 318 * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should 319 * leave this much room in front for low-level message headers which may 320 * be needed to get across the dongle bus to the host. (These messages 321 * don't go over the network, so room for the full WL header above would 322 * be a waste.). 323*/ 324#define BCMDONGLEHDRSZ 12 325#define BCMDONGLEPADSZ 16 326 327#define BCMDONGLEOVERHEAD (BCMDONGLEHDRSZ + BCMDONGLEPADSZ) 328 329 330#if defined(BCMDBG_ASSERT) 331#define BCMASSERT_SUPPORT 332#endif 333 334/* Macros for doing definition and get/set of bitfields 335 * Usage example, e.g. a three-bit field (bits 4-6): 336 * #define <NAME>_M BITFIELD_MASK(3) 337 * #define <NAME>_S 4 338 * ... 339 * regval = R_REG(osh, ®s->regfoo); 340 * field = GFIELD(regval, <NAME>); 341 * regval = SFIELD(regval, <NAME>, 1); 342 * W_REG(osh, ®s->regfoo, regval); 343 */ 344#define BITFIELD_MASK(width) \ 345 (((unsigned)1 << (width)) - 1) 346#define GFIELD(val, field) \ 347 (((val) >> field ## _S) & field ## _M) 348#define SFIELD(val, field, bits) \ 349 (((val) & (~(field ## _M << field ## _S))) | \ 350 ((unsigned)(bits) << field ## _S)) 351 352/* define BCMSMALL to remove misc features for memory-constrained environments */ 353#ifdef BCMSMALL 354#undef BCMSPACE 355#define bcmspace FALSE /* if (bcmspace) code is discarded */ 356#else 357#define BCMSPACE 358#define bcmspace TRUE /* if (bcmspace) code is retained */ 359#endif 360 361/* Max. nvram variable table size */ 362#define MAXSZ_NVRAM_VARS 4096 363 364#define LOCATOR_EXTERN static 365 366#endif /* _bcmdefs_h_ */ 367