• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Misc system wide definitions
3  *
4  * Copyright (C) 1999-2017, Broadcom Corporation
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  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: bcmdefs.h 657791 2016-09-02 15:14:42Z $
28  */
29 
30 #ifndef    _bcmdefs_h_
31 #define    _bcmdefs_h_
32 
33 /*
34  * One doesn't need to include this file explicitly, gets included automatically if
35  * typedefs.h is included.
36  */
37 
38 /* Use BCM_REFERENCE to suppress warnings about intentionally-unused function
39  * arguments or local variables.
40  */
41 #define BCM_REFERENCE(data)    ((void)(data))
42 
43 /* Allow for suppressing unused variable warnings. */
44 #ifdef __GNUC__
45 #define UNUSED_VAR     __attribute__ ((unused))
46 #else
47 #define UNUSED_VAR
48 #endif
49 
50 /* Compile-time assert can be used in place of ASSERT if the expression evaluates
51  * to a constant at compile time.
52  */
53 #define STATIC_ASSERT(expr) { \
54     /* Make sure the expression is constant. */ \
55     typedef enum { _STATIC_ASSERT_NOT_CONSTANT = (expr) } _static_assert_e UNUSED_VAR; \
56     /* Make sure the expression is true. */ \
57     typedef char STATIC_ASSERT_FAIL[(expr) ? 1 : -1] UNUSED_VAR; \
58 }
59 
60 /* Reclaiming text and data :
61  * The following macros specify special linker sections that can be reclaimed
62  * after a system is considered 'up'.
63  * BCMATTACHFN is also used for detach functions (it's not worth having a BCMDETACHFN,
64  * as in most cases, the attach function calls the detach function to clean up on error).
65  */
66 #if defined(BCM_RECLAIM)
67 
68 extern bool bcm_reclaimed;
69 extern bool bcm_attach_part_reclaimed;
70 extern bool bcm_preattach_part_reclaimed;
71 
72 #if defined(BCM_RECLAIM_ATTACH_FN_DATA)
73 #define _data    __attribute__ ((__section__ (".dataini2." #_data))) _data
74 #define _fn    __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
75 
76 /* Relocate attach symbols to save-restore region to increase pre-reclaim heap size. */
77 #define BCM_SRM_ATTACH_DATA(_data)    __attribute__ ((__section__ (".datasrm." #_data))) _data
78 #define BCM_SRM_ATTACH_FN(_fn)        __attribute__ ((__section__ (".textsrm." #_fn), noinline)) _fn
79 
80 #ifndef PREATTACH_NORECLAIM
81 #define BCMPREATTACHDATA(_data)    __attribute__ ((__section__ (".dataini3." #_data))) _data
82 #define BCMPREATTACHFN(_fn)    __attribute__ ((__section__ (".textini3." #_fn), noinline)) _fn
83 #else
84 #define BCMPREATTACHDATA(_data)    __attribute__ ((__section__ (".dataini2." #_data))) _data
85 #define BCMPREATTACHFN(_fn)    __attribute__ ((__section__ (".textini2." #_fn), noinline)) _fn
86 #endif /* PREATTACH_NORECLAIM  */
87 #else  /* BCM_RECLAIM_ATTACH_FN_DATA  */
88 #define _data    _data
89 #define _fn    _fn
90 #define BCMPREATTACHDATA(_data)    _data
91 #define BCMPREATTACHFN(_fn)    _fn
92 #endif /* BCM_RECLAIM_ATTACH_FN_DATA  */
93 
94 #if defined(BCM_RECLAIM_INIT_FN_DATA)
95 #define _data    __attribute__ ((__section__ (".dataini1." #_data))) _data
96 #define _fn        __attribute__ ((__section__ (".textini1." #_fn), noinline)) _fn
97 #define CONST
98 #else /* BCM_RECLAIM_INIT_FN_DATA  */
99 #define _data    _data
100 #define _fn        _fn
101 #ifndef CONST
102 #define CONST    const
103 #endif
104 #endif /* BCM_RECLAIM_INIT_FN_DATA  */
105 
106 /* Non-manufacture or internal attach function/dat */
107 #define    BCMNMIATTACHFN(_fn)    _fn
108 #define    BCMNMIATTACHDATA(_data)    _data
109 
110 #ifdef BCMNODOWN
111 #define _fn    _fn
112 #else
113 #define _fn    _fn
114 #endif
115 
116 #else /* BCM_RECLAIM */
117 
118 #define bcm_reclaimed               0
119 #define _data        _data
120 #define _fn        _fn
121 #define BCM_SRM_ATTACH_DATA(_data)    _data
122 #define BCM_SRM_ATTACH_FN(_fn)        _fn
123 #define BCMPREATTACHDATA(_data)        _data
124 #define BCMPREATTACHFN(_fn)        _fn
125 #define _data        _data
126 #define _fn            _fn
127 #define _fn        _fn
128 #define    BCMNMIATTACHFN(_fn)        _fn
129 #define    BCMNMIATTACHDATA(_data)        _data
130 #define CONST                const
131 
132 #endif /* BCM_RECLAIM */
133 
134 #if !defined STB
135 #undef BCM47XX_CA9
136 #endif /* STB */
137 
138 /* BCMFASTPATH Related Macro defines
139 */
140 #ifndef BCMFASTPATH
141 #if defined(STB)
142 #define BCMFASTPATH        __attribute__ ((__section__ (".text.fastpath")))
143 #define BCMFASTPATH_HOST    __attribute__ ((__section__ (".text.fastpath_host")))
144 #else
145 #define BCMFASTPATH
146 #define BCMFASTPATH_HOST
147 #endif
148 #endif /* BCMFASTPATH */
149 
150 
151 /* Use the BCMRAMFN() macro to tag functions in source that must be included in RAM (excluded from
152  * ROM). This should eliminate the need to manually specify these functions in the ROM config file.
153  * It should only be used in special cases where the function must be in RAM for *all* ROM-based
154  * chips.
155  */
156     #define BCMRAMFN(_fn)    _fn
157 
158 #define STATIC    static
159 
160 /* Bus types */
161 #define    SI_BUS            0    /* SOC Interconnect */
162 #define    PCI_BUS            1    /* PCI target */
163 #define    PCMCIA_BUS        2    /* PCMCIA target */
164 #define SDIO_BUS        3    /* SDIO target */
165 #define JTAG_BUS        4    /* JTAG */
166 #define USB_BUS            5    /* USB (does not support R/W REG) */
167 #define SPI_BUS            6    /* gSPI target */
168 #define RPC_BUS            7    /* RPC target */
169 
170 /* Allows size optimization for single-bus image */
171 #ifdef BCMBUSTYPE
172 #define BUSTYPE(bus)    (BCMBUSTYPE)
173 #else
174 #define BUSTYPE(bus)    (bus)
175 #endif
176 
177 #ifdef BCMBUSCORETYPE
178 #define BUSCORETYPE(ct)        (BCMBUSCORETYPE)
179 #else
180 #define BUSCORETYPE(ct)        (ct)
181 #endif
182 
183 /* Allows size optimization for single-backplane image */
184 #ifdef BCMCHIPTYPE
185 #define CHIPTYPE(bus)    (BCMCHIPTYPE)
186 #else
187 #define CHIPTYPE(bus)    (bus)
188 #endif
189 
190 
191 /* Allows size optimization for SPROM support */
192 #if defined(BCMSPROMBUS)
193 #define SPROMBUS    (BCMSPROMBUS)
194 #elif defined(SI_PCMCIA_SROM)
195 #define SPROMBUS    (PCMCIA_BUS)
196 #else
197 #define SPROMBUS    (PCI_BUS)
198 #endif
199 
200 /* Allows size optimization for single-chip image */
201 #ifdef BCMCHIPID
202 #define CHIPID(chip)    (BCMCHIPID)
203 #else
204 #define CHIPID(chip)    (chip)
205 #endif
206 
207 #ifdef BCMCHIPREV
208 #define CHIPREV(rev)    (BCMCHIPREV)
209 #else
210 #define CHIPREV(rev)    (rev)
211 #endif
212 
213 #ifdef BCMPCIEREV
214 #define PCIECOREREV(rev)    (BCMPCIEREV)
215 #else
216 #define PCIECOREREV(rev)    (rev)
217 #endif
218 
219 #ifdef BCMPMUREV
220 #define PMUREV(rev)    (BCMPMUREV)
221 #else
222 #define PMUREV(rev)    (rev)
223 #endif
224 
225 #ifdef BCMCCREV
226 #define CCREV(rev)    (BCMCCREV)
227 #else
228 #define CCREV(rev)    (rev)
229 #endif
230 
231 #ifdef BCMGCIREV
232 #define GCIREV(rev)    (BCMGCIREV)
233 #else
234 #define GCIREV(rev)    (rev)
235 #endif
236 
237 /* Defines for DMA Address Width - Shared between OSL and HNDDMA */
238 #define DMADDR_MASK_32 0x0        /* Address mask for 32-bits */
239 #define DMADDR_MASK_30 0xc0000000    /* Address mask for 30-bits */
240 #define DMADDR_MASK_26 0xFC000000    /* Address maks for 26-bits */
241 #define DMADDR_MASK_0  0xffffffff    /* Address mask for 0-bits (hi-part) */
242 
243 #define    DMADDRWIDTH_26  26 /* 26-bit addressing capability */
244 #define    DMADDRWIDTH_30  30 /* 30-bit addressing capability */
245 #define    DMADDRWIDTH_32  32 /* 32-bit addressing capability */
246 #define    DMADDRWIDTH_63  63 /* 64-bit addressing capability */
247 #define    DMADDRWIDTH_64  64 /* 64-bit addressing capability */
248 
249 typedef struct {
250     uint32 loaddr;
251     uint32 hiaddr;
252 } dma64addr_t;
253 
254 #define PHYSADDR64HI(_pa) ((_pa).hiaddr)
255 #define PHYSADDR64HISET(_pa, _val) \
256     do { \
257         (_pa).hiaddr = (_val);        \
258     } while (0)
259 #define PHYSADDR64LO(_pa) ((_pa).loaddr)
260 #define PHYSADDR64LOSET(_pa, _val) \
261     do { \
262         (_pa).loaddr = (_val);        \
263     } while (0)
264 
265 #ifdef BCMDMA64OSL
266 typedef dma64addr_t dmaaddr_t;
267 #define PHYSADDRHI(_pa) PHYSADDR64HI(_pa)
268 #define PHYSADDRHISET(_pa, _val) PHYSADDR64HISET(_pa, _val)
269 #define PHYSADDRLO(_pa)  PHYSADDR64LO(_pa)
270 #define PHYSADDRLOSET(_pa, _val) PHYSADDR64LOSET(_pa, _val)
271 #define PHYSADDRTOULONG(_pa, _ulong) \
272     do { \
273         _ulong = ((unsigned long long)(_pa).hiaddr << 32) | ((_pa).loaddr); \
274     } while (0)
275 
276 #else
277 typedef unsigned long dmaaddr_t;
278 #define PHYSADDRHI(_pa) (0)
279 #define PHYSADDRHISET(_pa, _val)
280 #define PHYSADDRLO(_pa) ((_pa))
281 #define PHYSADDRLOSET(_pa, _val) \
282     do { \
283         (_pa) = (_val);            \
284     } while (0)
285 #endif /* BCMDMA64OSL */
286 #define PHYSADDRISZERO(_pa) (PHYSADDRLO(_pa) == 0 && PHYSADDRHI(_pa) == 0)
287 
288 /* One physical DMA segment */
289 typedef struct  {
290     dmaaddr_t addr;
291     uint32      length;
292 } hnddma_seg_t;
293 
294 #define MAX_DMA_SEGS 8
295 
296 
297 typedef struct {
298     void *oshdmah; /* Opaque handle for OSL to store its information */
299     uint origsize; /* Size of the virtual packet */
300     uint nsegs;
301     hnddma_seg_t segs[MAX_DMA_SEGS];
302 } hnddma_seg_map_t;
303 
304 
305 /* packet headroom necessary to accommodate the largest header in the system, (i.e TXOFF).
306  * By doing, we avoid the need  to allocate an extra buffer for the header when bridging to WL.
307  * There is a compile time check in wlc.c which ensure that this value is at least as big
308  * as TXOFF. This value is used in dma_rxfill (hnddma.c).
309  */
310 
311 #if defined(BCM_RPC_NOCOPY) || defined(BCM_RCP_TXNOCOPY)
312 /* add 40 bytes to allow for extra RPC header and info  */
313 #define BCMEXTRAHDROOM 260
314 #else /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
315 #if defined(STB)
316 #if defined(BCM_GMAC3)
317 #define BCMEXTRAHDROOM 32 /* For FullDongle, no D11 headroom space required. */
318 #else
319 #define BCMEXTRAHDROOM 224
320 #endif /* ! BCM_GMAC3 */
321 #else
322 #define BCMEXTRAHDROOM 204
323 #endif
324 #endif /* BCM_RPC_NOCOPY || BCM_RPC_TXNOCOPY */
325 
326 /* Packet alignment for most efficient SDIO (can change based on platform) */
327 #ifndef SDALIGN
328 #define SDALIGN    32
329 #endif
330 
331 /* Headroom required for dongle-to-host communication.  Packets allocated
332  * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
333  * leave this much room in front for low-level message headers which may
334  * be needed to get across the dongle bus to the host.  (These messages
335  * don't go over the network, so room for the full WL header above would
336  * be a waste.).
337 */
338 #define BCMDONGLEHDRSZ 12
339 #define BCMDONGLEPADSZ 16
340 
341 #define BCMDONGLEOVERHEAD    (BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
342 
343 
344 #if defined(NO_BCMDBG_ASSERT)
345 # undef BCMDBG_ASSERT
346 # undef BCMASSERT_LOG
347 #endif
348 
349 #if defined(BCMASSERT_LOG)
350 #define BCMASSERT_SUPPORT
351 #endif
352 
353 /* Macros for doing definition and get/set of bitfields
354  * Usage example, e.g. a three-bit field (bits 4-6):
355  *    #define <NAME>_M    BITFIELD_MASK(3)
356  *    #define <NAME>_S    4
357  * ...
358  *    regval = R_REG(osh, &regs->regfoo);
359  *    field = GFIELD(regval, <NAME>);
360  *    regval = SFIELD(regval, <NAME>, 1);
361  *    W_REG(osh, &regs->regfoo, regval);
362  */
363 #define BITFIELD_MASK(width) \
364         (((unsigned)1 << (width)) - 1)
365 #define GFIELD(val, field) \
366         (((val) >> field ## _S) & field ## _M)
367 #define SFIELD(val, field, bits) \
368         (((val) & (~(field ## _M << field ## _S))) | \
369          ((unsigned)(bits) << field ## _S))
370 
371 /* define BCMSMALL to remove misc features for memory-constrained environments */
372 #ifdef BCMSMALL
373 #undef    BCMSPACE
374 #define bcmspace    FALSE    /* if (bcmspace) code is discarded */
375 #else
376 #define    BCMSPACE
377 #define bcmspace    TRUE    /* if (bcmspace) code is retained */
378 #endif
379 
380 /* Max. nvram variable table size */
381 #ifndef MAXSZ_NVRAM_VARS
382 #ifdef LARGE_NVRAM_MAXSZ
383 #define MAXSZ_NVRAM_VARS    LARGE_NVRAM_MAXSZ
384 #else
385 /* SROM12 changes */
386 #define    MAXSZ_NVRAM_VARS    6144
387 #endif /* LARGE_NVRAM_MAXSZ */
388 #endif /* !MAXSZ_NVRAM_VARS */
389 
390 
391 
392 /* WL_ENAB_RUNTIME_CHECK may be set based upon the #define below (for ROM builds). It may also
393  * be defined via makefiles (e.g. ROM auto abandon unoptimized compiles).
394  */
395 
396 
397 #ifdef BCMLFRAG /* BCMLFRAG support enab macros  */
398     extern bool _bcmlfrag;
399     #if defined(WL_ENAB_RUNTIME_CHECK) || !defined(DONGLEBUILD)
400         #define BCMLFRAG_ENAB() (_bcmlfrag)
401     #elif defined(BCMLFRAG_DISABLED)
402         #define BCMLFRAG_ENAB()    (0)
403     #else
404         #define BCMLFRAG_ENAB()    (1)
405     #endif
406 #else
407     #define BCMLFRAG_ENAB()        (0)
408 #endif /* BCMLFRAG_ENAB */
409 
410 #ifdef BCMPCIEDEV /* BCMPCIEDEV support enab macros */
411 extern bool _pciedevenab;
412     #if defined(WL_ENAB_RUNTIME_CHECK)
413         #define BCMPCIEDEV_ENAB() (_pciedevenab)
414     #elif defined(BCMPCIEDEV_ENABLED)
415         #define BCMPCIEDEV_ENAB()    1
416     #else
417         #define BCMPCIEDEV_ENAB()    0
418     #endif
419 #else
420     #define BCMPCIEDEV_ENAB()    0
421 #endif /* BCMPCIEDEV */
422 
423     #define BCMSDIODEV_ENAB()    0
424 
425 /* Max size for reclaimable NVRAM array */
426 #ifdef DL_NVRAM
427 #define NVRAM_ARRAY_MAXSIZE    DL_NVRAM
428 #else
429 #define NVRAM_ARRAY_MAXSIZE    MAXSZ_NVRAM_VARS
430 #endif /* DL_NVRAM */
431 
432 extern uint32 gFWID;
433 
434 /* Chip related low power flags (lpflags) */
435 #define LPFLAGS_SI_GLOBAL_DISABLE        (1 << 0)
436 #define LPFLAGS_SI_MEM_STDBY_DISABLE        (1 << 1)
437 #define LPFLAGS_SI_SFLASH_DISABLE        (1 << 2)
438 #define LPFLAGS_SI_BTLDO3P3_DISABLE        (1 << 3)
439 #define LPFLAGS_SI_GCI_FORCE_REGCLK_DISABLE    (1 << 4)
440 #define LPFLAGS_SI_FORCE_PWM_WHEN_RADIO_ON (1 << 5)
441 #define LPFLAGS_PHY_GLOBAL_DISABLE        (1 << 16)
442 #define LPFLAGS_PHY_LP_DISABLE            (1 << 17)
443 #define LPFLAGS_PSM_PHY_CTL            (1 << 18)
444 
445 /* Chip related Cbuck modes */
446 #define PMU_43012_VREG8_DYNAMIC_CBUCK_MODE0 0x00001c03
447 #define PMU_43012_VREG9_DYNAMIC_CBUCK_MODE0 0x00492490
448 #define PMU_43012_VREG8_DYNAMIC_CBUCK_MODE1 0x00001c03
449 #define PMU_43012_VREG9_DYNAMIC_CBUCK_MODE1 0x00490410
450 
451 /* Chip related dynamic cbuck mode mask */
452 
453 #define PMU_43012_VREG8_DYNAMIC_CBUCK_MODE_MASK  0xFFFFFC00
454 #define PMU_43012_VREG9_DYNAMIC_CBUCK_MODE_MASK  0xFFFFFFFF
455 
456 #ifndef PAD
457 #define _PADLINE(line)  pad ## line
458 #define _XSTR(line)     _PADLINE(line)
459 #define PAD             _XSTR(__LINE__)
460 #endif
461 
462 #endif /* _bcmdefs_h_ */
463