1/* 2 * Misc system wide definitions 3 * 4 * Copyright (C) 1999-2013, Broadcom Corporation 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 381895 2013-01-30 07:06:40Z $ 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/* Compile-time assert can be used in place of ASSERT if the expression evaluates 35 * to a constant at compile time. 36 */ 37#define STATIC_ASSERT(expr) { \ 38 /* Make sure the expression is constant. */ \ 39 typedef enum { _STATIC_ASSERT_NOT_CONSTANT = (expr) } _static_assert_e; \ 40 /* Make sure the expression is true. */ \ 41 typedef char STATIC_ASSERT_FAIL[(expr) ? 1 : -1]; \ 42} 43 44/* Reclaiming text and data : 45 * The following macros specify special linker sections that can be reclaimed 46 * after a system is considered 'up'. 47 * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN, 48 * as in most cases, the attach function calls the detach function to clean up on error). 49 */ 50 51#define bcmreclaimed 0 52#define _data _data 53#define _fn _fn 54#define BCMPREATTACHDATA(_data) _data 55#define BCMPREATTACHFN(_fn) _fn 56#define _data _data 57#define _fn _fn 58#define _fn _fn 59#define BCMNMIATTACHFN(_fn) _fn 60#define BCMNMIATTACHDATA(_data) _data 61#define CONST const 62#if defined(__ARM_ARCH_7A__) 63#define BCM47XX_CA9 64#else 65#undef BCM47XX_CA9 66#endif 67#ifndef BCMFASTPATH 68#if defined(BCM47XX_CA9) 69#define BCMFASTPATH __attribute__ ((__section__ (".text.fastpath"))) 70#define BCMFASTPATH_HOST __attribute__ ((__section__ (".text.fastpath_host"))) 71#else 72#define BCMFASTPATH 73#define BCMFASTPATH_HOST 74#endif 75#endif /* BCMFASTPATH */ 76 77 78/* Put some library data/code into ROM to reduce RAM requirements */ 79#define _data _data 80#define BCMROMDAT_NAME(_data) _data 81#define _fn _fn 82#define _fn _fn 83#define STATIC static 84#define BCMROMDAT_ARYSIZ(data) ARRAYSIZE(data) 85#define BCMROMDAT_SIZEOF(data) sizeof(data) 86#define BCMROMDAT_APATCH(data) 87#define BCMROMDAT_SPATCH(data) 88 89/* Bus types */ 90#define SI_BUS 0 /* SOC Interconnect */ 91#define PCI_BUS 1 /* PCI target */ 92#define PCMCIA_BUS 2 /* PCMCIA target */ 93#define SDIO_BUS 3 /* SDIO target */ 94#define JTAG_BUS 4 /* JTAG */ 95#define USB_BUS 5 /* USB (does not support R/W REG) */ 96#define SPI_BUS 6 /* gSPI target */ 97#define RPC_BUS 7 /* RPC target */ 98 99/* Allows size optimization for single-bus image */ 100#ifdef BCMBUSTYPE 101#define BUSTYPE(bus) (BCMBUSTYPE) 102#else 103#define BUSTYPE(bus) (bus) 104#endif 105 106/* Allows size optimization for single-backplane image */ 107#ifdef BCMCHIPTYPE 108#define CHIPTYPE(bus) (BCMCHIPTYPE) 109#else 110#define CHIPTYPE(bus) (bus) 111#endif 112 113 114/* Allows size optimization for SPROM support */ 115#if defined(BCMSPROMBUS) 116#define SPROMBUS (BCMSPROMBUS) 117#elif defined(SI_PCMCIA_SROM) 118#define SPROMBUS (PCMCIA_BUS) 119#else 120#define SPROMBUS (PCI_BUS) 121#endif 122 123/* Allows size optimization for single-chip image */ 124#ifdef BCMCHIPID 125#define CHIPID(chip) (BCMCHIPID) 126#else 127#define CHIPID(chip) (chip) 128#endif 129 130#ifdef BCMCHIPREV 131#define CHIPREV(rev) (BCMCHIPREV) 132#else 133#define CHIPREV(rev) (rev) 134#endif 135 136/* Defines for DMA Address Width - Shared between OSL and HNDDMA */ 137#define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */ 138#define DMADDR_MASK_30 0xc0000000 /* Address mask for 30-bits */ 139#define DMADDR_MASK_0 0xffffffff /* Address mask for 0-bits (hi-part) */ 140 141#define DMADDRWIDTH_30 30 /* 30-bit addressing capability */ 142#define DMADDRWIDTH_32 32 /* 32-bit addressing capability */ 143#define DMADDRWIDTH_63 63 /* 64-bit addressing capability */ 144#define DMADDRWIDTH_64 64 /* 64-bit addressing capability */ 145 146#ifdef BCMDMA64OSL 147typedef struct { 148 uint32 loaddr; 149 uint32 hiaddr; 150} dma64addr_t; 151 152typedef dma64addr_t dmaaddr_t; 153#define PHYSADDRHI(_pa) ((_pa).hiaddr) 154#define PHYSADDRHISET(_pa, _val) \ 155 do { \ 156 (_pa).hiaddr = (_val); \ 157 } while (0) 158#define PHYSADDRLO(_pa) ((_pa).loaddr) 159#define PHYSADDRLOSET(_pa, _val) \ 160 do { \ 161 (_pa).loaddr = (_val); \ 162 } while (0) 163 164#else 165typedef unsigned long dmaaddr_t; 166#define PHYSADDRHI(_pa) (0) 167#define PHYSADDRHISET(_pa, _val) 168#define PHYSADDRLO(_pa) ((_pa)) 169#define PHYSADDRLOSET(_pa, _val) \ 170 do { \ 171 (_pa) = (_val); \ 172 } while (0) 173#endif /* BCMDMA64OSL */ 174 175/* One physical DMA segment */ 176typedef struct { 177 dmaaddr_t addr; 178 uint32 length; 179} hnddma_seg_t; 180 181#define MAX_DMA_SEGS 4 182 183 184typedef struct { 185 void *oshdmah; /* Opaque handle for OSL to store its information */ 186 uint origsize; /* Size of the virtual packet */ 187 uint nsegs; 188 hnddma_seg_t segs[MAX_DMA_SEGS]; 189} hnddma_seg_map_t; 190 191 192/* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF). 193 * By doing, we avoid the need to allocate an extra buffer for the header when bridging to WL. 194 * There is a compile time check in wlc.c which ensure that this value is at least as big 195 * as TXOFF. This value is used in dma_rxfill (hnddma.c). 196 */ 197 198#if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY) 199/* add 40 bytes to allow for extra RPC header and info */ 200#define BCMEXTRAHDROOM 260 201#else /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */ 202#if defined(BCM47XX_CA9) 203#define BCMEXTRAHDROOM 224 204#else 205#define BCMEXTRAHDROOM 204 206#endif /* linux && BCM47XX_CA9 */ 207#endif /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */ 208 209/* Packet alignment for most efficient SDIO (can change based on platform) */ 210#ifndef SDALIGN 211#define SDALIGN 32 212#endif 213 214/* Headroom required for dongle-to-host communication. Packets allocated 215 * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should 216 * leave this much room in front for low-level message headers which may 217 * be needed to get across the dongle bus to the host. (These messages 218 * don't go over the network, so room for the full WL header above would 219 * be a waste.). 220*/ 221#define BCMDONGLEHDRSZ 12 222#define BCMDONGLEPADSZ 16 223 224#define BCMDONGLEOVERHEAD (BCMDONGLEHDRSZ + BCMDONGLEPADSZ) 225 226 227#if defined(NO_BCMDBG_ASSERT) 228# undef BCMDBG_ASSERT 229# undef BCMASSERT_LOG 230#endif 231 232#if defined(BCMASSERT_LOG) 233#define BCMASSERT_SUPPORT 234#endif 235 236/* Macros for doing definition and get/set of bitfields 237 * Usage example, e.g. a three-bit field (bits 4-6): 238 * #define <NAME>_M BITFIELD_MASK(3) 239 * #define <NAME>_S 4 240 * ... 241 * regval = R_REG(osh, ®s->regfoo); 242 * field = GFIELD(regval, <NAME>); 243 * regval = SFIELD(regval, <NAME>, 1); 244 * W_REG(osh, ®s->regfoo, regval); 245 */ 246#define BITFIELD_MASK(width) \ 247 (((unsigned)1 << (width)) - 1) 248#define GFIELD(val, field) \ 249 (((val) >> field ## _S) & field ## _M) 250#define SFIELD(val, field, bits) \ 251 (((val) & (~(field ## _M << field ## _S))) | \ 252 ((unsigned)(bits) << field ## _S)) 253 254/* define BCMSMALL to remove misc features for memory-constrained environments */ 255#ifdef BCMSMALL 256#undef BCMSPACE 257#define bcmspace FALSE /* if (bcmspace) code is discarded */ 258#else 259#define BCMSPACE 260#define bcmspace TRUE /* if (bcmspace) code is retained */ 261#endif 262 263/* Max. nvram variable table size */ 264#define MAXSZ_NVRAM_VARS 4096 265 266 267/* Max size for reclaimable NVRAM array */ 268#ifdef DL_NVRAM 269#define NVRAM_ARRAY_MAXSIZE DL_NVRAM 270#else 271#define NVRAM_ARRAY_MAXSIZE MAXSZ_NVRAM_VARS 272#endif /* DL_NVRAM */ 273 274#ifdef BCMUSBDEV_ENABLED 275extern uint32 gFWID; 276#endif 277 278#endif /* _bcmdefs_h_ */ 279