Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmsmac / types.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef _BRCM_TYPES_H_
18 #define _BRCM_TYPES_H_
19
20 #include <linux/types.h>
21 #include <linux/io.h>
22
23 /* Bus types */
24 #define SI_BUS                  0       /* SOC Interconnect */
25 #define PCI_BUS                 1       /* PCI target */
26 #define SDIO_BUS                3       /* SDIO target */
27 #define JTAG_BUS                4       /* JTAG */
28 #define USB_BUS                 5       /* USB (does not support R/W REG) */
29 #define SPI_BUS                 6       /* gSPI target */
30 #define RPC_BUS                 7       /* RPC target */
31
32 #define WL_CHAN_FREQ_RANGE_2G      0
33 #define WL_CHAN_FREQ_RANGE_5GL     1
34 #define WL_CHAN_FREQ_RANGE_5GM     2
35 #define WL_CHAN_FREQ_RANGE_5GH     3
36
37 #define MAX_DMA_SEGS 4
38
39 /* boardflags */
40 #define BFL_PACTRL              0x00000002      /* Board has gpio 9 controlling the PA */
41 #define BFL_NOPLLDOWN           0x00000020      /* Not ok to power down the chip pll and oscillator */
42 #define BFL_FEM                 0x00000800      /* Board supports the Front End Module */
43 #define BFL_EXTLNA              0x00001000      /* Board has an external LNA in 2.4GHz band */
44 #define BFL_NOPA                0x00010000      /* Board has no PA */
45 #define BFL_BUCKBOOST           0x00200000      /* Power topology uses BUCKBOOST */
46 #define BFL_FEM_BT              0x00400000      /* Board has FEM and switch to share antenna w/ BT */
47 #define BFL_NOCBUCK             0x00800000      /* Power topology doesn't use CBUCK */
48 #define BFL_PALDO               0x02000000      /* Power topology uses PALDO */
49 #define BFL_EXTLNA_5GHz         0x10000000      /* Board has an external LNA in 5GHz band */
50
51 /* boardflags2 */
52 #define BFL2_RXBB_INT_REG_DIS   0x00000001      /* Board has an external rxbb regulator */
53 #define BFL2_APLL_WAR           0x00000002      /* Flag to implement alternative A-band PLL settings */
54 #define BFL2_TXPWRCTRL_EN       0x00000004      /* Board permits enabling TX Power Control */
55 #define BFL2_2X4_DIV            0x00000008      /* Board supports the 2X4 diversity switch */
56 #define BFL2_5G_PWRGAIN         0x00000010      /* Board supports 5G band power gain */
57 #define BFL2_PCIEWAR_OVR        0x00000020      /* Board overrides ASPM and Clkreq settings */
58 #define BFL2_LEGACY             0x00000080
59 #define BFL2_SKWRKFEM_BRD       0x00000100      /* 4321mcm93 board uses Skyworks FEM */
60 #define BFL2_SPUR_WAR           0x00000200      /* Board has a WAR for clock-harmonic spurs */
61 #define BFL2_GPLL_WAR           0x00000400      /* Flag to narrow G-band PLL loop b/w */
62 #define BFL2_SINGLEANT_CCK      0x00001000      /* Tx CCK pkts on Ant 0 only */
63 #define BFL2_2G_SPUR_WAR        0x00002000      /* WAR to reduce and avoid clock-harmonic spurs in 2G */
64 #define BFL2_GPLL_WAR2          0x00010000      /* Flag to widen G-band PLL loop b/w */
65 #define BFL2_IPALVLSHIFT_3P3    0x00020000
66 #define BFL2_INTERNDET_TXIQCAL  0x00040000      /* Use internal envelope detector for TX IQCAL */
67 #define BFL2_XTALBUFOUTEN       0x00080000      /* Keep the buffered Xtal output from radio "ON"
68                                                  * Most drivers will turn it off without this flag
69                                                  * to save power.
70                                                  */
71
72 /* board specific GPIO assignment, gpio 0-3 are also customer-configurable led */
73 #define BOARD_GPIO_PACTRL       0x200   /* bit 9 controls the PA on new 4306 boards */
74 #define BOARD_GPIO_12           0x1000  /* gpio 12 */
75 #define BOARD_GPIO_13           0x2000  /* gpio 13 */
76
77 /* **** Core type/rev defaults **** */
78 #define D11CONF         0x0fffffb0      /* Supported  D11 revs: 4, 5, 7-27
79                                          * also need to update wlc.h MAXCOREREV
80                                          */
81
82 #define NCONF           0x000001ff      /* Supported nphy revs:
83                                          *      0       4321a0
84                                          *      1       4321a1
85                                          *      2       4321b0/b1/c0/c1
86                                          *      3       4322a0
87                                          *      4       4322a1
88                                          *      5       4716a0
89                                          *      6       43222a0, 43224a0
90                                          *      7       43226a0
91                                          *      8       5357a0, 43236a0
92                                          */
93
94 #define LCNCONF         0x00000007      /* Supported lcnphy revs:
95                                          *      0       4313a0, 4336a0, 4330a0
96                                          *      1
97                                          *      2       4330a0
98                                          */
99
100 #define SSLPNCONF       0x0000000f      /* Supported sslpnphy revs:
101                                          *      0       4329a0/k0
102                                          *      1       4329b0/4329C0
103                                          *      2       4319a0
104                                          *      3       5356a0
105                                          */
106
107 /********************************************************************
108  * Phy/Core Configuration.  Defines macros to to check core phy/rev *
109  * compile-time configuration.  Defines default core support.       *
110  * ******************************************************************
111  */
112
113 /* Basic macros to check a configuration bitmask */
114
115 #define CONF_HAS(config, val)   ((config) & (1 << (val)))
116 #define CONF_MSK(config, mask)  ((config) & (mask))
117 #define MSK_RANGE(low, hi)      ((1 << ((hi)+1)) - (1 << (low)))
118 #define CONF_RANGE(config, low, hi) (CONF_MSK(config, MSK_RANGE(low, high)))
119
120 #define CONF_IS(config, val)    ((config) == (1 << (val)))
121 #define CONF_GE(config, val)    ((config) & (0-(1 << (val))))
122 #define CONF_GT(config, val)    ((config) & (0-2*(1 << (val))))
123 #define CONF_LT(config, val)    ((config) & ((1 << (val))-1))
124 #define CONF_LE(config, val)    ((config) & (2*(1 << (val))-1))
125
126 /* Wrappers for some of the above, specific to config constants */
127
128 #define NCONF_HAS(val)  CONF_HAS(NCONF, val)
129 #define NCONF_MSK(mask) CONF_MSK(NCONF, mask)
130 #define NCONF_IS(val)   CONF_IS(NCONF, val)
131 #define NCONF_GE(val)   CONF_GE(NCONF, val)
132 #define NCONF_GT(val)   CONF_GT(NCONF, val)
133 #define NCONF_LT(val)   CONF_LT(NCONF, val)
134 #define NCONF_LE(val)   CONF_LE(NCONF, val)
135
136 #define LCNCONF_HAS(val)        CONF_HAS(LCNCONF, val)
137 #define LCNCONF_MSK(mask)       CONF_MSK(LCNCONF, mask)
138 #define LCNCONF_IS(val)         CONF_IS(LCNCONF, val)
139 #define LCNCONF_GE(val)         CONF_GE(LCNCONF, val)
140 #define LCNCONF_GT(val)         CONF_GT(LCNCONF, val)
141 #define LCNCONF_LT(val)         CONF_LT(LCNCONF, val)
142 #define LCNCONF_LE(val)         CONF_LE(LCNCONF, val)
143
144 #define D11CONF_HAS(val) CONF_HAS(D11CONF, val)
145 #define D11CONF_MSK(mask) CONF_MSK(D11CONF, mask)
146 #define D11CONF_IS(val) CONF_IS(D11CONF, val)
147 #define D11CONF_GE(val) CONF_GE(D11CONF, val)
148 #define D11CONF_GT(val) CONF_GT(D11CONF, val)
149 #define D11CONF_LT(val) CONF_LT(D11CONF, val)
150 #define D11CONF_LE(val) CONF_LE(D11CONF, val)
151
152 #define PHYCONF_HAS(val) CONF_HAS(PHYTYPE, val)
153 #define PHYCONF_IS(val) CONF_IS(PHYTYPE, val)
154
155 #define NREV_IS(var, val)       (NCONF_HAS(val) && (NCONF_IS(val) || ((var) == (val))))
156 #define NREV_GE(var, val)       (NCONF_GE(val) && (!NCONF_LT(val) || ((var) >= (val))))
157 #define NREV_GT(var, val)       (NCONF_GT(val) && (!NCONF_LE(val) || ((var) > (val))))
158 #define NREV_LT(var, val)       (NCONF_LT(val) && (!NCONF_GE(val) || ((var) < (val))))
159 #define NREV_LE(var, val)       (NCONF_LE(val) && (!NCONF_GT(val) || ((var) <= (val))))
160
161 #define LCNREV_IS(var, val)     (LCNCONF_HAS(val) && (LCNCONF_IS(val) || ((var) == (val))))
162 #define LCNREV_GE(var, val)     (LCNCONF_GE(val) && (!LCNCONF_LT(val) || ((var) >= (val))))
163 #define LCNREV_GT(var, val)     (LCNCONF_GT(val) && (!LCNCONF_LE(val) || ((var) > (val))))
164 #define LCNREV_LT(var, val)     (LCNCONF_LT(val) && (!LCNCONF_GE(val) || ((var) < (val))))
165 #define LCNREV_LE(var, val)     (LCNCONF_LE(val) && (!LCNCONF_GT(val) || ((var) <= (val))))
166
167 #define D11REV_IS(var, val)     (D11CONF_HAS(val) && (D11CONF_IS(val) || ((var) == (val))))
168 #define D11REV_GE(var, val)     (D11CONF_GE(val) && (!D11CONF_LT(val) || ((var) >= (val))))
169 #define D11REV_GT(var, val)     (D11CONF_GT(val) && (!D11CONF_LE(val) || ((var) > (val))))
170 #define D11REV_LT(var, val)     (D11CONF_LT(val) && (!D11CONF_GE(val) || ((var) < (val))))
171 #define D11REV_LE(var, val)     (D11CONF_LE(val) && (!D11CONF_GT(val) || ((var) <= (val))))
172
173 #define PHYTYPE_IS(var, val)    (PHYCONF_HAS(val) && (PHYCONF_IS(val) || ((var) == (val))))
174
175 /* Finally, early-exit from switch case if anyone wants it... */
176
177 #define CASECHECK(config, val)  if (!(CONF_HAS(config, val))) break
178 #define CASEMSK(config, mask)   if (!(CONF_MSK(config, mask))) break
179
180 /* Set up PHYTYPE automatically: (depends on PHY_TYPE_X, from d11.h) */
181
182 #define _PHYCONF_N (1 << PHY_TYPE_N)
183 #define _PHYCONF_LCN (1 << PHY_TYPE_LCN)
184 #define _PHYCONF_SSLPN (1 << PHY_TYPE_SSN)
185
186 #define PHYTYPE (_PHYCONF_N | _PHYCONF_LCN | _PHYCONF_SSLPN)
187
188 /* Utility macro to identify 802.11n (HT) capable PHYs */
189 #define PHYTYPE_11N_CAP(phytype) \
190         (PHYTYPE_IS(phytype, PHY_TYPE_N) ||     \
191          PHYTYPE_IS(phytype, PHY_TYPE_LCN) || \
192          PHYTYPE_IS(phytype, PHY_TYPE_SSN))
193
194 /* Last but not least: shorter wlc-specific var checks */
195 #define BRCMS_ISNPHY(band)              PHYTYPE_IS((band)->phytype, PHY_TYPE_N)
196 #define BRCMS_ISLCNPHY(band)    PHYTYPE_IS((band)->phytype, PHY_TYPE_LCN)
197 #define BRCMS_ISSSLPNPHY(band)  PHYTYPE_IS((band)->phytype, PHY_TYPE_SSN)
198
199 #define BRCMS_PHY_11N_CAP(band) PHYTYPE_11N_CAP((band)->phytype)
200
201 /**********************************************************************
202  * ------------- End of Core phy/rev configuration. ----------------- *
203  * ********************************************************************
204  */
205
206 /*************************************************
207  * Defaults for tunables (e.g. sizing constants)
208  *
209  * For each new tunable, add a member to the end
210  * of struct brcms_tunables in brcms_c_pub.h to enable
211  * runtime checks of tunable values. (Directly
212  * using the macros in code invalidates ROM code)
213  *
214  * ***********************************************
215  */
216 #define NTXD            256     /* Max # of entries in Tx FIFO based on 4kb page size */
217 #define NRXD            256     /* Max # of entries in Rx FIFO based on 4kb page size */
218 #define NRXBUFPOST      32      /* try to keep this # rbufs posted to the chip */
219 #define MAXSCB          32      /* Maximum SCBs in cache for STA */
220 #define AMPDU_NUM_MPDU          16      /* max allowed number of mpdus in an ampdu (2 streams) */
221
222 /* Count of packet callback structures. either of following
223  * 1. Set to the number of SCBs since a STA
224  * can queue up a rate callback for each IBSS STA it knows about, and an AP can
225  * queue up an "are you there?" Null Data callback for each associated STA
226  * 2. controlled by tunable config file
227  */
228 #define MAXPKTCB        MAXSCB  /* Max number of packet callbacks */
229
230 /* NetBSD also needs to keep track of this */
231
232 /* Number of BSS handled in ucode bcn/prb */
233 #define BRCMS_MAX_UCODE_BSS     (16)
234 /* Number of BSS handled in sw bcn/prb */
235 #define BRCMS_MAX_UCODE_BSS4    (4)
236 /* max # BSS configs */
237 #define BRCMS_MAXBSSCFG         (1)
238 /* max # available networks */
239 #define MAXBSS          64
240 /* data msg txq hiwat mark */
241 #define BRCMS_DATAHIWAT         50
242 #define BRCMS_AMPDUDATAHIWAT 255
243
244 /* bounded rx loops */
245 #define RXBND           8       /* max # frames to process in brcms_c_recv() */
246 #define TXSBND          8       /* max # tx status to process in wlc_txstatus() */
247
248 #define BAND_5G(bt)     ((bt) == BRCM_BAND_5G)
249 #define BAND_2G(bt)     ((bt) == BRCM_BAND_2G)
250
251 #define BCMMSG(dev, fmt, args...)               \
252 do {                                            \
253         if (brcm_msg_level & LOG_TRACE_VAL)     \
254                 wiphy_err(dev, "%s: " fmt, __func__, ##args);   \
255 } while (0)
256
257 #define WL_ERROR_ON()           (brcm_msg_level & LOG_ERROR_VAL)
258
259 /* register access macros */
260 #ifndef __BIG_ENDIAN
261 #ifndef __mips__
262 #define R_REG(r) \
263         ({\
264                 sizeof(*(r)) == sizeof(u8) ? \
265                 readb((u8 *)(r)) : \
266                 sizeof(*(r)) == sizeof(u16) ? readw((u16 *)(r)) : \
267                 readl((u32 *)(r)); \
268         })
269 #else                           /* __mips__ */
270 #define R_REG(r) \
271         ({ \
272                 __typeof(*(r)) __osl_v; \
273                 __asm__ __volatile__("sync"); \
274                 switch (sizeof(*(r))) { \
275                 case sizeof(u8): \
276                         __osl_v = readb((u8 *)(r)); \
277                         break; \
278                 case sizeof(u16): \
279                         __osl_v = readw((u16 *)(r)); \
280                         break; \
281                 case sizeof(u32): \
282                         __osl_v = \
283                         readl((u32 *)(r)); \
284                         break; \
285                 } \
286                 __asm__ __volatile__("sync"); \
287                 __osl_v; \
288         })
289 #endif                          /* __mips__ */
290
291 #define W_REG(r, v) do { \
292                 switch (sizeof(*(r))) { \
293                 case sizeof(u8): \
294                         writeb((u8)(v), (u8 *)(r)); break; \
295                 case sizeof(u16): \
296                         writew((u16)(v), (u16 *)(r)); break; \
297                 case sizeof(u32): \
298                         writel((u32)(v), (u32 *)(r)); break; \
299                 }; \
300         } while (0)
301 #else                           /* __BIG_ENDIAN */
302 #define R_REG(r) \
303         ({ \
304                 __typeof(*(r)) __osl_v; \
305                 switch (sizeof(*(r))) { \
306                 case sizeof(u8): \
307                         __osl_v = \
308                         readb((u8 *)((r)^3)); \
309                         break; \
310                 case sizeof(u16): \
311                         __osl_v = \
312                         readw((u16 *)((r)^2)); \
313                         break; \
314                 case sizeof(u32): \
315                         __osl_v = readl((u32 *)(r)); \
316                         break; \
317                 } \
318                 __osl_v; \
319         })
320
321 #define W_REG(r, v) do { \
322                 switch (sizeof(*(r))) { \
323                 case sizeof(u8):        \
324                         writeb((u8)(v), \
325                         (u8 *)((r)^3)); break; \
326                 case sizeof(u16):       \
327                         writew((u16)(v), \
328                         (u16 *)((r)^2)); break; \
329                 case sizeof(u32):       \
330                         writel((u32)(v), \
331                         (u32 *)(r)); break; \
332                 } \
333         } while (0)
334 #endif                          /* __BIG_ENDIAN */
335
336 #ifdef __mips__
337 /*
338  * bcm4716 (which includes 4717 & 4718), plus 4706 on PCIe can reorder
339  * transactions. As a fix, a read after write is performed on certain places
340  * in the code. Older chips and the newer 5357 family don't require this fix.
341  */
342 #define W_REG_FLUSH(r, v)       ({ W_REG((r), (v)); (void)R_REG(r); })
343 #else
344 #define W_REG_FLUSH(r, v)       W_REG((r), (v))
345 #endif                          /* __mips__ */
346
347 #define AND_REG(r, v)   W_REG((r), R_REG(r) & (v))
348 #define OR_REG(r, v)    W_REG((r), R_REG(r) | (v))
349
350 #define SET_REG(r, mask, val) \
351                 W_REG((r), ((R_REG(r) & ~(mask)) | (val)))
352
353 /* multi-bool data type: set of bools, mbool is true if any is set */
354 typedef u32 mbool;
355 #define mboolset(mb, bit)               ((mb) |= (bit)) /* set one bool */
356 #define mboolclr(mb, bit)               ((mb) &= ~(bit))        /* clear one bool */
357 #define mboolisset(mb, bit)             (((mb) & (bit)) != 0)   /* true if one bool is set */
358 #define mboolmaskset(mb, mask, val)     ((mb) = (((mb) & ~(mask)) | (val)))
359
360 /* forward declarations */
361 struct wiphy;
362 struct ieee80211_sta;
363 struct ieee80211_tx_queue_params;
364 struct brcms_info;
365 struct brcms_c_info;
366 struct brcms_hardware;
367 struct brcms_c_if;
368 struct brcmu_iovar;
369 struct brcmu_strbuf;
370 struct brcms_txq_info;
371 struct brcms_band;
372 struct dma_pub;
373 struct si_pub;
374 struct tx_status;
375 struct d11rxhdr;
376 struct brcms_d11rxhdr;
377 struct txpwr_limits;
378 struct brcms_phy;
379
380 typedef volatile struct intctrlregs intctrlregs_t;
381 typedef volatile struct pio2regs pio2regs_t;
382 typedef volatile struct pio2regp pio2regp_t;
383 typedef volatile struct pio4regs pio4regs_t;
384 typedef volatile struct pio4regp pio4regp_t;
385 typedef volatile struct fifo64 fifo64_t;
386 typedef volatile struct d11regs d11regs_t;
387 typedef volatile struct dma32diag dma32diag_t;
388 typedef volatile struct dma64regs dma64regs_t;
389 typedef struct brcms_rateset wlc_rateset_t;
390 typedef u32 ratespec_t;
391 typedef struct chanvec chanvec_t;
392 typedef s32 fixed;
393 typedef struct _cs32 cs32;
394 typedef volatile union pmqreg pmqreg_t;
395
396 /* brcm_msg_level is a bit vector with defs in defs.h */
397 extern u32 brcm_msg_level;
398
399 #endif                          /* _BRCM_TYPES_H_ */