block: fix warning with calling smp_processor_id() in preemptible section
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmsmac / pub.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_PUB_H_
18 #define _BRCM_PUB_H_
19
20 #include <brcmu_wifi.h>
21 #include "types.h"
22 #include "defs.h"
23
24 #define BRCMS_NUMRATES  16      /* max # of rates in a rateset */
25 #define MAXMULTILIST    32      /* max # multicast addresses */
26 #define D11_PHY_HDR_LEN 6       /* Phy header length - 6 bytes */
27
28 /* phy types */
29 #define PHY_TYPE_A      0       /* Phy type A */
30 #define PHY_TYPE_G      2       /* Phy type G */
31 #define PHY_TYPE_N      4       /* Phy type N */
32 #define PHY_TYPE_LP     5       /* Phy type Low Power A/B/G */
33 #define PHY_TYPE_SSN    6       /* Phy type Single Stream N */
34 #define PHY_TYPE_LCN    8       /* Phy type Single Stream N */
35 #define PHY_TYPE_LCNXN  9       /* Phy type 2-stream N */
36 #define PHY_TYPE_HT     7       /* Phy type 3-Stream N */
37
38 /* bw */
39 #define BRCMS_10_MHZ    10      /* 10Mhz nphy channel bandwidth */
40 #define BRCMS_20_MHZ    20      /* 20Mhz nphy channel bandwidth */
41 #define BRCMS_40_MHZ    40      /* 40Mhz nphy channel bandwidth */
42
43 #define CHSPEC_WLC_BW(chanspec) (CHSPEC_IS40(chanspec) ? BRCMS_40_MHZ : \
44                                  CHSPEC_IS20(chanspec) ? BRCMS_20_MHZ : \
45                                                          BRCMS_10_MHZ)
46
47 #define BRCMS_RSSI_MINVAL       -200    /* Low value, e.g. for forcing roam */
48 #define BRCMS_RSSI_NO_SIGNAL    -91     /* NDIS RSSI link quality cutoffs */
49 #define BRCMS_RSSI_VERY_LOW     -80     /* Very low quality cutoffs */
50 #define BRCMS_RSSI_LOW          -70     /* Low quality cutoffs */
51 #define BRCMS_RSSI_GOOD         -68     /* Good quality cutoffs */
52 #define BRCMS_RSSI_VERY_GOOD    -58     /* Very good quality cutoffs */
53 #define BRCMS_RSSI_EXCELLENT    -57     /* Excellent quality cutoffs */
54
55 /* macro to perform PHY -> D11 PHY TYPE, currently 1:1 */
56 #define BRCMS_PHYTYPE(_x) (_x)
57
58 #define MA_WINDOW_SZ            8       /* moving average window size */
59
60 #define BRCMS_SNR_INVALID               0       /* invalid SNR value */
61
62 /* a large TX Power as an init value to factor out of min() calculations,
63  * keep low enough to fit in an s8, units are .25 dBm
64  */
65 #define BRCMS_TXPWR_MAX         (127)   /* ~32 dBm = 1,500 mW */
66
67 /* rate related definitions */
68 #define BRCMS_RATE_FLAG 0x80    /* Flag to indicate it is a basic rate */
69 #define BRCMS_RATE_MASK 0x7f    /* Rate value mask w/o basic rate flag */
70
71 /* legacy rx Antenna diversity for SISO rates */
72 #define ANT_RX_DIV_FORCE_0              0       /* Use antenna 0 */
73 #define ANT_RX_DIV_FORCE_1              1       /* Use antenna 1 */
74 #define ANT_RX_DIV_START_1              2       /* Choose starting with 1 */
75 #define ANT_RX_DIV_START_0              3       /* Choose starting with 0 */
76 #define ANT_RX_DIV_ENABLE               3       /* APHY bbConfig Enable RX Diversity */
77 #define ANT_RX_DIV_DEF          ANT_RX_DIV_START_0      /* default antdiv setting */
78
79 /* legacy rx Antenna diversity for SISO rates */
80 #define ANT_TX_FORCE_0          0       /* Tx on antenna 0, "legacy term Main" */
81 #define ANT_TX_FORCE_1          1       /* Tx on antenna 1, "legacy term Aux" */
82 #define ANT_TX_LAST_RX          3       /* Tx on phy's last good Rx antenna */
83 #define ANT_TX_DEF                      3       /* driver's default tx antenna setting */
84
85 #define TXCORE_POLICY_ALL       0x1     /* use all available core for transmit */
86
87 /* Tx Chain values */
88 #define TXCHAIN_DEF             0x1     /* def bitmap of txchain */
89 #define TXCHAIN_DEF_NPHY        0x3     /* default bitmap of tx chains for nphy */
90 #define TXCHAIN_DEF_HTPHY       0x7     /* default bitmap of tx chains for nphy */
91 #define RXCHAIN_DEF             0x1     /* def bitmap of rxchain */
92 #define RXCHAIN_DEF_NPHY        0x3     /* default bitmap of rx chains for nphy */
93 #define RXCHAIN_DEF_HTPHY       0x7     /* default bitmap of rx chains for nphy */
94 #define ANTSWITCH_NONE          0       /* no antenna switch */
95 #define ANTSWITCH_TYPE_1        1       /* antenna switch on 4321CB2, 2of3 */
96 #define ANTSWITCH_TYPE_2        2       /* antenna switch on 4321MPCI, 2of3 */
97 #define ANTSWITCH_TYPE_3        3       /* antenna switch on 4322, 2of3 */
98
99 #define RXBUFSZ         PKTBUFSZ
100 #ifndef AIDMAPSZ
101 #define AIDMAPSZ        (roundup(MAXSCB, NBBY)/NBBY)    /* aid bitmap size in bytes */
102 #endif                          /* AIDMAPSZ */
103
104 #define MAX_STREAMS_SUPPORTED   4       /* max number of streams supported */
105
106 #define WL_SPURAVOID_OFF        0
107 #define WL_SPURAVOID_ON1        1
108 #define WL_SPURAVOID_ON2        2
109
110 struct brcms_tunables {
111         int ntxd;               /* size of tx descriptor table */
112         int nrxd;               /* size of rx descriptor table */
113         int rxbufsz;            /* size of rx buffers to post */
114         int nrxbufpost;         /* # of rx buffers to post */
115         int maxscb;             /* # of SCBs supported */
116         int ampdunummpdu;       /* max number of mpdu in an ampdu */
117         int maxpktcb;           /* max # of packet callbacks */
118         int maxucodebss;        /* max # of BSS handled in ucode bcn/prb */
119         int maxucodebss4;       /* max # of BSS handled in sw bcn/prb */
120         int maxbss;             /* max # of bss info elements in scan list */
121         int datahiwat;          /* data msg txq hiwat mark */
122         int ampdudatahiwat;     /* AMPDU msg txq hiwat mark */
123         int rxbnd;              /* max # of rx bufs to process before deferring to dpc */
124         int txsbnd;             /* max # tx status to process in wlc_txstatus() */
125         int memreserved;        /* memory reserved for BMAC's USB dma rx */
126 };
127
128 struct brcms_rateset {
129         uint count;             /* number of rates in rates[] */
130          /* rates in 500kbps units w/hi bit set if basic */
131         u8 rates[BRCMS_NUMRATES];
132         u8 htphy_membership;    /* HT PHY Membership */
133         u8 mcs[MCSSET_LEN];     /* supported mcs index bit map */
134 };
135
136 struct rsn_parms {
137         u8 flags;               /* misc booleans (e.g., supported) */
138         u8 multicast;   /* multicast cipher */
139         u8 ucount;              /* count of unicast ciphers */
140         u8 unicast[4];  /* unicast ciphers */
141         u8 acount;              /* count of auth modes */
142         u8 auth[4];             /* Authentication modes */
143         u8 PAD[4];              /* padding for future growth */
144 };
145
146 /*
147  * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
148  */
149 #define SSID_FMT_BUF_LEN        ((4 * IEEE80211_MAX_SSID_LEN) + 1)
150
151 #define RSN_FLAGS_SUPPORTED             0x1     /* Flag for rsn_params */
152 #define RSN_FLAGS_PREAUTH               0x2     /* Flag for WPA2 rsn_params */
153
154 /* All the HT-specific default advertised capabilities (including AMPDU)
155  * should be grouped here at one place
156  */
157 #define AMPDU_DEF_MPDU_DENSITY  6       /* default mpdu density (110 ==> 4us) */
158
159 /* defaults for the HT (MIMO) bss */
160 #define HT_CAP  (IEEE80211_HT_CAP_SM_PS |\
161         IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_GRN_FLD |\
162         IEEE80211_HT_CAP_MAX_AMSDU | IEEE80211_HT_CAP_DSSSCCK40)
163
164 /* wlc internal bss_info */
165 struct brcms_bss_info {
166         u8 BSSID[ETH_ALEN];     /* network BSSID */
167         u16 flags;              /* flags for internal attributes */
168         u8 SSID_len;            /* the length of SSID */
169         u8 SSID[32];            /* SSID string */
170         s16 RSSI;               /* receive signal strength (in dBm) */
171         s16 SNR;                /* receive signal SNR in dB */
172         u16 beacon_period;      /* units are Kusec */
173         u16 atim_window;        /* units are Kusec */
174         chanspec_t chanspec;    /* Channel num, bw, ctrl_sb and band */
175         s8 infra;               /* 0=IBSS, 1=infrastructure, 2=unknown */
176         wlc_rateset_t rateset;  /* supported rates */
177         u8 dtim_period; /* DTIM period */
178         s8 phy_noise;           /* noise right after tx (in dBm) */
179         u16 capability; /* Capability information */
180         u8 wme_qosinfo; /* QoS Info from WME IE; valid if BSS_WME flag set */
181         struct rsn_parms wpa;
182         struct rsn_parms wpa2;
183         u16 qbss_load_aac;      /* qbss load available admission capacity */
184         /* qbss_load_chan_free <- (0xff - channel_utilization of qbss_load_ie_t) */
185         u8 qbss_load_chan_free; /* indicates how free the channel is */
186         u8 mcipher;             /* multicast cipher */
187         u8 wpacfg;              /* wpa config index */
188 };
189
190 /* IOVar flags for common error checks */
191 #define IOVF_MFG        (1<<3)  /* flag for mfgtest iovars */
192 #define IOVF_WHL        (1<<4)  /* value must be whole (0-max) */
193 #define IOVF_NTRL       (1<<5)  /* value must be natural (1-max) */
194
195 #define IOVF_SET_UP     (1<<6)  /* set requires driver be up */
196 #define IOVF_SET_DOWN   (1<<7)  /* set requires driver be down */
197 #define IOVF_SET_CLK    (1<<8)  /* set requires core clock */
198 #define IOVF_SET_BAND   (1<<9)  /* set requires fixed band */
199
200 #define IOVF_GET_UP     (1<<10) /* get requires driver be up */
201 #define IOVF_GET_DOWN   (1<<11) /* get requires driver be down */
202 #define IOVF_GET_CLK    (1<<12) /* get requires core clock */
203 #define IOVF_GET_BAND   (1<<13) /* get requires fixed band */
204 #define IOVF_OPEN_ALLOW (1<<14) /* set allowed iovar for opensrc */
205
206 /* watchdog down and dump callback function proto's */
207 typedef int (*watchdog_fn_t) (void *handle);
208 typedef int (*down_fn_t) (void *handle);
209 typedef int (*dump_fn_t) (void *handle, struct brcmu_strbuf *b);
210
211 /* IOVar handler
212  *
213  * handle - a pointer value registered with the function
214  * vi - iovar_info that was looked up
215  * actionid - action ID, calculated by IOV_GVAL() and IOV_SVAL() based on varid.
216  * name - the actual iovar name
217  * params/plen - parameters and length for a get, input only.
218  * arg/len - buffer and length for value to be set or retrieved, input or output.
219  * vsize - value size, valid for integer type only.
220  * wlcif - interface context (brcms_c_if pointer)
221  *
222  * All pointers may point into the same buffer.
223  */
224 typedef int (*iovar_fn_t) (void *handle, const struct brcmu_iovar *vi,
225                            u32 actionid, const char *name, void *params,
226                            uint plen, void *arg, int alen, int vsize,
227                            struct brcms_c_if *wlcif);
228
229 #define MAC80211_PROMISC_BCNS   (1 << 0)
230 #define MAC80211_SCAN           (1 << 1)
231
232 /*
233  * Public portion of "common" os-independent state structure.
234  * The wlc handle points at this.
235  */
236 struct brcms_pub {
237         void *wlc;
238
239         struct ieee80211_hw *ieee_hw;
240         struct scb *global_scb;
241         struct scb_ampdu *global_ampdu;
242         uint mac80211_state;
243         uint unit;              /* device instance number */
244         uint corerev;           /* core revision */
245         struct si_pub *sih;     /* SI handle (cookie for siutils calls) */
246         char *vars;             /* "environment" name=value */
247         bool up;                /* interface up and running */
248         bool hw_off;            /* HW is off */
249         /* tunables: ntxd, nrxd, maxscb, etc. */
250         struct brcms_tunables *tunables;
251         bool hw_up;             /* one time hw up/down(from boot or hibernation) */
252         bool _piomode;          /* true if pio mode *//* BMAC_NOTE: NEED In both */
253         uint _nbands;           /* # bands supported */
254         uint now;               /* # elapsed seconds */
255
256         bool promisc;           /* promiscuous destination address */
257         bool delayed_down;      /* down delayed */
258         bool _ap;               /* AP mode enabled */
259         bool _apsta;            /* simultaneous AP/STA mode enabled */
260         bool _assoc_recreate;   /* association recreation on up transitions */
261         int _wme;               /* WME QoS mode */
262         u8 _mbss;               /* MBSS mode on */
263         bool allmulti;          /* enable all multicasts */
264         bool associated;        /* true:part of [I]BSS, false: not */
265         /* (union of stas_associated, aps_associated) */
266         bool phytest_on;        /* whether a PHY test is running */
267         bool bf_preempt_4306;   /* True to enable 'darwin' mode */
268         bool _ampdu;            /* ampdu enabled or not */
269         bool _cac;              /* 802.11e CAC enabled */
270         u8 _n_enab;             /* bitmap of 11N + HT support */
271         bool _n_reqd;           /* N support required for clients */
272
273         s8 _coex;               /* 20/40 MHz BSS Management AUTO, ENAB, DISABLE */
274         bool _priofc;           /* Priority-based flowcontrol */
275
276         u8 cur_etheraddr[ETH_ALEN];     /* our local ethernet address */
277
278         u8 *multicast;  /* ptr to list of multicast addresses */
279         uint nmulticast;        /* # enabled multicast addresses */
280
281         u32 wlfeatureflag;      /* Flags to control sw features from registry */
282         int psq_pkts_total;     /* total num of ps pkts */
283
284         u16 txmaxpkts;  /* max number of large pkts allowed to be pending */
285
286         /* s/w decryption counters */
287         u32 swdecrypt;  /* s/w decrypt attempts */
288
289         int bcmerror;           /* last bcm error */
290
291         mbool radio_disabled;   /* bit vector for radio disabled reasons */
292         bool radio_active;      /* radio on/off state */
293         u16 roam_time_thresh;   /* Max. # secs. of not hearing beacons
294                                          * before roaming.
295                                          */
296         bool align_wd_tbtt;     /* Align watchdog with tbtt indication
297                                  * handling. This flag is cleared by default
298                                  * and is set by per port code explicitly and
299                                  * you need to make sure the OSL_SYSUPTIME()
300                                  * is implemented properly in osl of that port
301                                  * when it enables this Power Save feature.
302                                  */
303
304         u16 boardrev;   /* version # of particular board */
305         u8 sromrev;             /* version # of the srom */
306         char srom_ccode[BRCM_CNTRY_BUF_SZ];     /* Country Code in SROM */
307         u32 boardflags; /* Board specific flags from srom */
308         u32 boardflags2;        /* More board flags if sromrev >= 4 */
309         bool tempsense_disable; /* disable periodic tempsense check */
310         bool phy_11ncapable;    /* the PHY/HW is capable of 802.11N */
311         bool _ampdumac;         /* mac assist ampdu enabled or not */
312
313         struct wl_cnt *_cnt;    /* low-level counters in driver */
314 };
315
316 /* wl_monitor rx status per packet */
317 struct wl_rxsts {
318         uint pkterror;          /* error flags per pkt */
319         uint phytype;           /* 802.11 A/B/G ... */
320         uint channel;           /* channel */
321         uint datarate;          /* rate in 500kbps */
322         uint antenna;           /* antenna pkts received on */
323         uint pktlength;         /* pkt length minus bcm phy hdr */
324         u32 mactime;            /* time stamp from mac, count per 1us */
325         uint sq;                /* signal quality */
326         s32 signal;             /* in dbm */
327         s32 noise;              /* in dbm */
328         uint preamble;          /* Unknown, short, long */
329         uint encoding;          /* Unknown, CCK, PBCC, OFDM */
330         uint nfrmtype;          /* special 802.11n frames(AMPDU, AMSDU) */
331         struct brcms_if *wlif;  /* wl interface */
332 };
333
334 /* status per error RX pkt */
335 #define WL_RXS_CRC_ERROR                0x00000001      /* CRC Error in packet */
336 #define WL_RXS_RUNT_ERROR               0x00000002      /* Runt packet */
337 #define WL_RXS_ALIGN_ERROR              0x00000004      /* Misaligned packet */
338 #define WL_RXS_OVERSIZE_ERROR           0x00000008      /* packet bigger than RX_LENGTH (usually 1518) */
339 #define WL_RXS_WEP_ICV_ERROR            0x00000010      /* Integrity Check Value error */
340 #define WL_RXS_WEP_ENCRYPTED            0x00000020      /* Encrypted with WEP */
341 #define WL_RXS_PLCP_SHORT               0x00000040      /* Short PLCP error */
342 #define WL_RXS_DECRYPT_ERR              0x00000080      /* Decryption error */
343 #define WL_RXS_OTHER_ERR                0x80000000      /* Other errors */
344
345 /* phy type */
346 #define WL_RXS_PHY_A                    0x00000000      /* A phy type */
347 #define WL_RXS_PHY_B                    0x00000001      /* B phy type */
348 #define WL_RXS_PHY_G                    0x00000002      /* G phy type */
349 #define WL_RXS_PHY_N                    0x00000004      /* N phy type */
350
351 /* encoding */
352 #define WL_RXS_ENCODING_CCK             0x00000000      /* CCK encoding */
353 #define WL_RXS_ENCODING_OFDM            0x00000001      /* OFDM encoding */
354
355 /* preamble */
356 #define WL_RXS_UNUSED_STUB              0x0     /* stub to match with wlc_ethereal.h */
357 #define WL_RXS_PREAMBLE_SHORT           0x00000001      /* Short preamble */
358 #define WL_RXS_PREAMBLE_LONG            0x00000002      /* Long preamble */
359 #define WL_RXS_PREAMBLE_MIMO_MM         0x00000003      /* MIMO mixed mode preamble */
360 #define WL_RXS_PREAMBLE_MIMO_GF         0x00000004      /* MIMO green field preamble */
361
362 #define WL_RXS_NFRM_AMPDU_FIRST         0x00000001      /* first MPDU in A-MPDU */
363 #define WL_RXS_NFRM_AMPDU_SUB           0x00000002      /* subsequent MPDU(s) in A-MPDU */
364 #define WL_RXS_NFRM_AMSDU_FIRST         0x00000004      /* first MSDU in A-MSDU */
365 #define WL_RXS_NFRM_AMSDU_SUB           0x00000008      /* subsequent MSDU(s) in A-MSDU */
366
367 enum wlc_par_id {
368         IOV_MPC = 1,
369         IOV_RTSTHRESH,
370         IOV_QTXPOWER,
371         IOV_BCN_LI_BCN          /* Beacon listen interval in # of beacons */
372 };
373
374 /***********************************************
375  * Feature-related macros to optimize out code *
376  * *********************************************
377  */
378
379 /* AP Support (versus STA) */
380 #define AP_ENAB(pub)    (0)
381
382 /* Macro to check if APSTA mode enabled */
383 #define APSTA_ENAB(pub) (0)
384
385 /* Some useful combinations */
386 #define STA_ONLY(pub)   (!AP_ENAB(pub))
387 #define AP_ONLY(pub)    (AP_ENAB(pub) && !APSTA_ENAB(pub))
388
389 #define ENAB_1x1        0x01
390 #define ENAB_2x2        0x02
391 #define ENAB_3x3        0x04
392 #define ENAB_4x4        0x08
393 #define SUPPORT_11N     (ENAB_1x1|ENAB_2x2)
394 #define SUPPORT_HT      (ENAB_1x1|ENAB_2x2|ENAB_3x3)
395 /* WL11N Support */
396 #if ((defined(NCONF) && (NCONF != 0)) || (defined(LCNCONF) && (LCNCONF != 0)) || \
397         (defined(HTCONF) && (HTCONF != 0)) || (defined(SSLPNCONF) && (SSLPNCONF != 0)))
398 #define N_ENAB(pub) ((pub)->_n_enab & SUPPORT_11N)
399 #define N_REQD(pub) ((pub)->_n_reqd)
400 #else
401 #define N_ENAB(pub)     0
402 #define N_REQD(pub)     0
403 #endif
404
405 #if (defined(HTCONF) && (HTCONF != 0))
406 #define HT_ENAB(pub) (((pub)->_n_enab & SUPPORT_HT) == SUPPORT_HT)
407 #else
408 #define HT_ENAB(pub) 0
409 #endif
410
411 #define AMPDU_AGG_HOST  1
412 #define AMPDU_ENAB(pub) ((pub)->_ampdu)
413
414 #define EDCF_ENAB(pub) (WME_ENAB(pub))
415 #define QOS_ENAB(pub) (WME_ENAB(pub) || N_ENAB(pub))
416
417 #define MONITOR_ENAB(wlc)       ((wlc)->monitor)
418
419 #define PROMISC_ENAB(wlc)       ((wlc)->promisc)
420
421 #define BRCMS_PREC_COUNT        16      /* Max precedence level implemented */
422
423 /* pri is priority encoded in the packet. This maps the Packet priority to
424  * enqueue precedence as defined in wlc_prec_map
425  */
426 extern const u8 wlc_prio2prec_map[];
427 #define BRCMS_PRIO_TO_PREC(pri) wlc_prio2prec_map[(pri) & 7]
428
429 /* This maps priority to one precedence higher - Used by PS-Poll response packets to
430  * simulate enqueue-at-head operation, but still maintain the order on the queue
431  */
432 #define BRCMS_PRIO_TO_HI_PREC(pri)      min(BRCMS_PRIO_TO_PREC(pri) + 1,\
433                                             BRCMS_PREC_COUNT - 1)
434
435 extern const u8 wme_fifo2ac[];
436 #define WME_PRIO2AC(prio)       wme_fifo2ac[prio2fifo[(prio)]]
437
438 /* Mask to describe all precedence levels */
439 #define BRCMS_PREC_BMP_ALL              MAXBITVAL(BRCMS_PREC_COUNT)
440
441 /* Define a bitmap of precedences comprised by each AC */
442 #define BRCMS_PREC_BMP_AC_BE    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_BE)) | \
443                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_BE)) | \
444                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_EE)) |    \
445                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_EE)))
446 #define BRCMS_PREC_BMP_AC_BK    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_BK)) | \
447                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_BK)) | \
448                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_NONE)) |  \
449                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_NONE)))
450 #define BRCMS_PREC_BMP_AC_VI    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_CL)) | \
451                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_CL)) | \
452                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_VI)) |    \
453                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_VI)))
454 #define BRCMS_PREC_BMP_AC_VO    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_VO)) | \
455                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_VO)) | \
456                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_NC)) |    \
457                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_NC)))
458
459 /* WME Support */
460 #define WME_ENAB(pub) ((pub)->_wme != OFF)
461 #define WME_AUTO(wlc) ((wlc)->pub->_wme == AUTO)
462
463 /* invalid core flags, use the saved coreflags */
464 #define BRCMS_USE_COREFLAGS     0xffffffff
465
466
467 /* network protection config */
468 #define BRCMS_PROT_G_SPEC               1       /* SPEC g protection */
469 #define BRCMS_PROT_G_OVR                2       /* SPEC g prot override */
470 #define BRCMS_PROT_G_USER               3       /* gmode specified by user */
471 #define BRCMS_PROT_OVERLAP      4       /* overlap */
472 #define BRCMS_PROT_N_USER               10      /* nmode specified by user */
473 #define BRCMS_PROT_N_CFG                11      /* n protection */
474 #define BRCMS_PROT_N_CFG_OVR    12      /* n protection override */
475 #define BRCMS_PROT_N_NONGF      13      /* non-GF protection */
476 #define BRCMS_PROT_N_NONGF_OVR  14      /* non-GF protection override */
477 #define BRCMS_PROT_N_PAM_OVR    15      /* n preamble override */
478 #define BRCMS_PROT_N_OBSS               16      /* non-HT OBSS present */
479
480 /*
481  * 54g modes (basic bits may still be overridden)
482  *
483  * GMODE_LEGACY_B                       Rateset: 1b, 2b, 5.5, 11
484  *                                      Preamble: Long
485  *                                      Shortslot: Off
486  * GMODE_AUTO                           Rateset: 1b, 2b, 5.5b, 11b, 18, 24, 36, 54
487  *                                      Extended Rateset: 6, 9, 12, 48
488  *                                      Preamble: Long
489  *                                      Shortslot: Auto
490  * GMODE_ONLY                           Rateset: 1b, 2b, 5.5b, 11b, 18, 24b, 36, 54
491  *                                      Extended Rateset: 6b, 9, 12b, 48
492  *                                      Preamble: Short required
493  *                                      Shortslot: Auto
494  * GMODE_B_DEFERRED                     Rateset: 1b, 2b, 5.5b, 11b, 18, 24, 36, 54
495  *                                      Extended Rateset: 6, 9, 12, 48
496  *                                      Preamble: Long
497  *                                      Shortslot: On
498  * GMODE_PERFORMANCE                    Rateset: 1b, 2b, 5.5b, 6b, 9, 11b, 12b, 18, 24b, 36, 48, 54
499  *                                      Preamble: Short required
500  *                                      Shortslot: On and required
501  * GMODE_LRS                            Rateset: 1b, 2b, 5.5b, 11b
502  *                                      Extended Rateset: 6, 9, 12, 18, 24, 36, 48, 54
503  *                                      Preamble: Long
504  *                                      Shortslot: Auto
505  */
506 #define GMODE_LEGACY_B          0
507 #define GMODE_AUTO              1
508 #define GMODE_ONLY              2
509 #define GMODE_B_DEFERRED        3
510 #define GMODE_PERFORMANCE       4
511 #define GMODE_LRS               5
512 #define GMODE_MAX               6
513
514 /* values for PLCPHdr_override */
515 #define BRCMS_PLCP_AUTO -1
516 #define BRCMS_PLCP_SHORT        0
517 #define BRCMS_PLCP_LONG 1
518
519 /* values for g_protection_override and n_protection_override */
520 #define BRCMS_PROTECTION_AUTO           -1
521 #define BRCMS_PROTECTION_OFF            0
522 #define BRCMS_PROTECTION_ON             1
523 #define BRCMS_PROTECTION_MMHDR_ONLY     2
524 #define BRCMS_PROTECTION_CTS_ONLY               3
525
526 /* values for g_protection_control and n_protection_control */
527 #define BRCMS_PROTECTION_CTL_OFF                0
528 #define BRCMS_PROTECTION_CTL_LOCAL      1
529 #define BRCMS_PROTECTION_CTL_OVERLAP    2
530
531 /* values for n_protection */
532 #define BRCMS_N_PROTECTION_OFF          0
533 #define BRCMS_N_PROTECTION_OPTIONAL     1
534 #define BRCMS_N_PROTECTION_20IN40               2
535 #define BRCMS_N_PROTECTION_MIXEDMODE    3
536
537 /* values for band specific 40MHz capabilities */
538 #define BRCMS_N_BW_20ALL                        0
539 #define BRCMS_N_BW_40ALL                        1
540 #define BRCMS_N_BW_20IN2G_40IN5G                2
541
542 /* bitflags for SGI support (sgi_rx iovar) */
543 #define BRCMS_N_SGI_20                  0x01
544 #define BRCMS_N_SGI_40                  0x02
545
546 /* defines used by the nrate iovar */
547 #define NRATE_MCS_INUSE 0x00000080      /* MSC in use,indicates b0-6 holds an mcs */
548 #define NRATE_RATE_MASK 0x0000007f      /* rate/mcs value */
549 #define NRATE_STF_MASK  0x0000ff00      /* stf mode mask: siso, cdd, stbc, sdm */
550 #define NRATE_STF_SHIFT 8       /* stf mode shift */
551 #define NRATE_OVERRIDE  0x80000000      /* bit indicates override both rate & mode */
552 #define NRATE_OVERRIDE_MCS_ONLY 0x40000000      /* bit indicate to override mcs only */
553 #define NRATE_SGI_MASK  0x00800000      /* sgi mode */
554 #define NRATE_SGI_SHIFT 23      /* sgi mode */
555 #define NRATE_LDPC_CODING 0x00400000    /* bit indicates adv coding in use */
556 #define NRATE_LDPC_SHIFT 22     /* ldpc shift */
557
558 #define NRATE_STF_SISO  0       /* stf mode SISO */
559 #define NRATE_STF_CDD   1       /* stf mode CDD */
560 #define NRATE_STF_STBC  2       /* stf mode STBC */
561 #define NRATE_STF_SDM   3       /* stf mode SDM */
562
563 #define ANT_SELCFG_MAX          4       /* max number of antenna configurations */
564
565 #define HIGHEST_SINGLE_STREAM_MCS       7       /* MCS values greater than this enable multiple streams */
566
567 struct brcms_antselcfg {
568         u8 ant_config[ANT_SELCFG_MAX];  /* antenna configuration */
569         u8 num_antcfg;  /* number of available antenna configurations */
570 };
571
572 /* common functions for every port */
573 extern void *brcms_c_attach(struct brcms_info *wl, u16 vendor, u16 device,
574                         uint unit, bool piomode, void *regsva, uint bustype,
575                         void *btparam, uint *perr);
576 extern uint brcms_c_detach(struct brcms_c_info *wlc);
577 extern int brcms_c_up(struct brcms_c_info *wlc);
578 extern uint brcms_c_down(struct brcms_c_info *wlc);
579
580 extern int brcms_c_set(struct brcms_c_info *wlc, int cmd, int arg);
581 extern int brcms_c_get(struct brcms_c_info *wlc, int cmd, int *arg);
582 extern bool brcms_c_chipmatch(u16 vendor, u16 device);
583 extern void brcms_c_init(struct brcms_c_info *wlc);
584 extern void brcms_c_reset(struct brcms_c_info *wlc);
585
586 extern void brcms_c_intrson(struct brcms_c_info *wlc);
587 extern u32 brcms_c_intrsoff(struct brcms_c_info *wlc);
588 extern void brcms_c_intrsrestore(struct brcms_c_info *wlc, u32 macintmask);
589 extern bool brcms_c_intrsupd(struct brcms_c_info *wlc);
590 extern bool brcms_c_isr(struct brcms_c_info *wlc, bool *wantdpc);
591 extern bool brcms_c_dpc(struct brcms_c_info *wlc, bool bounded);
592 extern bool brcms_c_sendpkt_mac80211(struct brcms_c_info *wlc,
593                                      struct sk_buff *sdu,
594                                      struct ieee80211_hw *hw);
595 extern int brcms_c_ioctl(struct brcms_c_info *wlc, int cmd, void *arg, int len,
596                          struct brcms_c_if *wlcif);
597 extern bool brcms_c_aggregatable(struct brcms_c_info *wlc, u8 tid);
598
599 /* helper functions */
600 extern void brcms_c_statsupd(struct brcms_c_info *wlc);
601 extern void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx,
602                                    int val);
603 extern int brcms_c_get_header_len(void);
604 extern void brcms_c_mac_bcn_promisc_change(struct brcms_c_info *wlc,
605                                            bool promisc);
606 extern void brcms_c_set_addrmatch(struct brcms_c_info *wlc,
607                                   int match_reg_offset,
608                                   const u8 *addr);
609 extern void brcms_c_wme_setparams(struct brcms_c_info *wlc, u16 aci,
610                               const struct ieee80211_tx_queue_params *arg,
611                               bool suspend);
612 extern struct brcms_pub *brcms_c_pub(void *wlc);
613
614 /* common functions for every port */
615 extern void brcms_c_mhf(struct brcms_c_info *wlc, u8 idx, u16 mask, u16 val,
616                     int bands);
617 extern void brcms_c_rate_lookup_init(struct brcms_c_info *wlc,
618                                      wlc_rateset_t *rateset);
619 extern void brcms_default_rateset(struct brcms_c_info *wlc, wlc_rateset_t *rs);
620
621 extern void brcms_c_ampdu_flush(struct brcms_c_info *wlc,
622                             struct ieee80211_sta *sta, u16 tid);
623 extern void brcms_c_ampdu_tx_operational(struct brcms_c_info *wlc, u8 tid,
624                                          u8 ba_wsize, uint max_rx_ampdu_bytes);
625 extern int brcms_c_set_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
626                            int val);
627 extern int brcms_c_get_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
628                            int *ret_int_ptr);
629 extern char *getvar(char *vars, const char *name);
630 extern int getintvar(char *vars, const char *name);
631
632 /* wlc_phy.c helper functions */
633 extern void brcms_c_set_ps_ctrl(struct brcms_c_info *wlc);
634 extern void brcms_c_mctrl(struct brcms_c_info *wlc, u32 mask, u32 val);
635
636 extern int brcms_c_module_register(struct brcms_pub *pub,
637                                const char *name, void *hdl,
638                                watchdog_fn_t watchdog_fn, down_fn_t down_fn);
639 extern int brcms_c_module_unregister(struct brcms_pub *pub, const char *name,
640                                  void *hdl);
641 extern void brcms_c_suspend_mac_and_wait(struct brcms_c_info *wlc);
642 extern void brcms_c_enable_mac(struct brcms_c_info *wlc);
643 extern void brcms_c_associate_upd(struct brcms_c_info *wlc, bool state);
644 extern void brcms_c_scan_start(struct brcms_c_info *wlc);
645 extern void brcms_c_scan_stop(struct brcms_c_info *wlc);
646 extern int brcms_c_get_curband(struct brcms_c_info *wlc);
647 extern void brcms_c_wait_for_tx_completion(struct brcms_c_info *wlc,
648                                            bool drop);
649
650 /* helper functions */
651 extern bool brcms_c_check_radio_disabled(struct brcms_c_info *wlc);
652 extern bool brcms_c_radio_monitor_stop(struct brcms_c_info *wlc);
653
654 #define MAXBANDS                2       /* Maximum #of bands */
655 /* bandstate array indices */
656 #define BAND_2G_INDEX           0       /* wlc->bandstate[x] index */
657 #define BAND_5G_INDEX           1       /* wlc->bandstate[x] index */
658
659 #define BAND_2G_NAME            "2.4G"
660 #define BAND_5G_NAME            "5G"
661
662 /* BMAC RPC: 7 u32 params: pkttotlen, fifo, commit, fid, txpktpend, pktflag, rpc_id */
663 #define BRCMS_RPCTX_PARAMS              32
664
665 #endif                          /* _BRCM_PUB_H_ */