33e7ebe7b9779ec59a48674287554fab5b16441f
[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 D11_PHY_HDR_LEN 6       /* Phy header length - 6 bytes */
26
27 /* phy types */
28 #define PHY_TYPE_A      0       /* Phy type A */
29 #define PHY_TYPE_G      2       /* Phy type G */
30 #define PHY_TYPE_N      4       /* Phy type N */
31 #define PHY_TYPE_LP     5       /* Phy type Low Power A/B/G */
32 #define PHY_TYPE_SSN    6       /* Phy type Single Stream N */
33 #define PHY_TYPE_LCN    8       /* Phy type Single Stream N */
34 #define PHY_TYPE_LCNXN  9       /* Phy type 2-stream N */
35 #define PHY_TYPE_HT     7       /* Phy type 3-Stream N */
36
37 /* bw */
38 #define BRCMS_10_MHZ    10      /* 10Mhz nphy channel bandwidth */
39 #define BRCMS_20_MHZ    20      /* 20Mhz nphy channel bandwidth */
40 #define BRCMS_40_MHZ    40      /* 40Mhz nphy channel bandwidth */
41
42 #define BRCMS_RSSI_MINVAL       -200    /* Low value, e.g. for forcing roam */
43 #define BRCMS_RSSI_NO_SIGNAL    -91     /* NDIS RSSI link quality cutoffs */
44 #define BRCMS_RSSI_VERY_LOW     -80     /* Very low quality cutoffs */
45 #define BRCMS_RSSI_LOW          -70     /* Low quality cutoffs */
46 #define BRCMS_RSSI_GOOD         -68     /* Good quality cutoffs */
47 #define BRCMS_RSSI_VERY_GOOD    -58     /* Very good quality cutoffs */
48 #define BRCMS_RSSI_EXCELLENT    -57     /* Excellent quality cutoffs */
49
50 /* a large TX Power as an init value to factor out of min() calculations,
51  * keep low enough to fit in an s8, units are .25 dBm
52  */
53 #define BRCMS_TXPWR_MAX         (127)   /* ~32 dBm = 1,500 mW */
54
55 /* rate related definitions */
56 #define BRCMS_RATE_FLAG 0x80    /* Flag to indicate it is a basic rate */
57 #define BRCMS_RATE_MASK 0x7f    /* Rate value mask w/o basic rate flag */
58
59 /* legacy rx Antenna diversity for SISO rates */
60 #define ANT_RX_DIV_FORCE_0      0       /* Use antenna 0 */
61 #define ANT_RX_DIV_FORCE_1      1       /* Use antenna 1 */
62 #define ANT_RX_DIV_START_1      2       /* Choose starting with 1 */
63 #define ANT_RX_DIV_START_0      3       /* Choose starting with 0 */
64 #define ANT_RX_DIV_ENABLE       3       /* APHY bbConfig Enable RX Diversity */
65 /* default antdiv setting */
66 #define ANT_RX_DIV_DEF          ANT_RX_DIV_START_0
67
68 /* legacy rx Antenna diversity for SISO rates */
69 /* Tx on antenna 0, "legacy term Main" */
70 #define ANT_TX_FORCE_0          0
71 /* Tx on antenna 1, "legacy term Aux" */
72 #define ANT_TX_FORCE_1          1
73 /* Tx on phy's last good Rx antenna */
74 #define ANT_TX_LAST_RX          3
75 /* driver's default tx antenna setting */
76 #define ANT_TX_DEF              3
77
78 /* Tx Chain values */
79 /* def bitmap of txchain */
80 #define TXCHAIN_DEF             0x1
81 /* default bitmap of tx chains for nphy */
82 #define TXCHAIN_DEF_NPHY        0x3
83 /* default bitmap of tx chains for nphy */
84 #define TXCHAIN_DEF_HTPHY       0x7
85 /* def bitmap of rxchain */
86 #define RXCHAIN_DEF             0x1
87 /* default bitmap of rx chains for nphy */
88 #define RXCHAIN_DEF_NPHY        0x3
89 /* default bitmap of rx chains for nphy */
90 #define RXCHAIN_DEF_HTPHY       0x7
91 /* no antenna switch */
92 #define ANTSWITCH_NONE          0
93 /* antenna switch on 4321CB2, 2of3 */
94 #define ANTSWITCH_TYPE_1        1
95 /* antenna switch on 4321MPCI, 2of3 */
96 #define ANTSWITCH_TYPE_2        2
97 /* antenna switch on 4322, 2of3 */
98 #define ANTSWITCH_TYPE_3        3
99
100 #define RXBUFSZ         PKTBUFSZ
101
102 #define MAX_STREAMS_SUPPORTED   4       /* max number of streams supported */
103
104 struct brcms_c_rateset {
105         uint count;             /* number of rates in rates[] */
106          /* rates in 500kbps units w/hi bit set if basic */
107         u8 rates[BRCMS_NUMRATES];
108         u8 htphy_membership;    /* HT PHY Membership */
109         u8 mcs[MCSSET_LEN];     /* supported mcs index bit map */
110 };
111
112 /* All the HT-specific default advertised capabilities (including AMPDU)
113  * should be grouped here at one place
114  */
115 #define AMPDU_DEF_MPDU_DENSITY  6       /* default mpdu density (110 ==> 4us) */
116
117 /* wlc internal bss_info */
118 struct brcms_bss_info {
119         u8 BSSID[ETH_ALEN];     /* network BSSID */
120         u16 flags;              /* flags for internal attributes */
121         u8 SSID_len;            /* the length of SSID */
122         u8 SSID[32];            /* SSID string */
123         s16 RSSI;               /* receive signal strength (in dBm) */
124         s16 SNR;                /* receive signal SNR in dB */
125         u16 beacon_period;      /* units are Kusec */
126         u16 chanspec;   /* Channel num, bw, ctrl_sb and band */
127         struct brcms_c_rateset rateset; /* supported rates */
128 };
129
130 #define MAC80211_PROMISC_BCNS   (1 << 0)
131 #define MAC80211_SCAN           (1 << 1)
132
133 /*
134  * Public portion of common driver state structure.
135  * The wlc handle points at this.
136  */
137 struct brcms_pub {
138         struct brcms_c_info *wlc;
139         struct ieee80211_hw *ieee_hw;
140         struct scb *global_scb;
141         struct scb_ampdu *global_ampdu;
142         uint mac80211_state;
143         uint unit;              /* device instance number */
144         uint corerev;           /* core revision */
145         struct si_pub *sih;     /* SI handle (cookie for siutils calls) */
146         char *vars;             /* "environment" name=value */
147         bool up;                /* interface up and running */
148         bool hw_off;            /* HW is off */
149         bool hw_up;             /* one time hw up/down */
150         bool _piomode;          /* true if pio mode */
151         uint _nbands;           /* # bands supported */
152         uint now;               /* # elapsed seconds */
153
154         bool promisc;           /* promiscuous destination address */
155         bool delayed_down;      /* down delayed */
156         int _wme;               /* WME QoS mode */
157         bool associated;        /* true:part of [I]BSS, false: not */
158         /* (union of stas_associated, aps_associated) */
159         bool _ampdu;            /* ampdu enabled or not */
160         u8 _n_enab;             /* bitmap of 11N + HT support */
161
162         u8 cur_etheraddr[ETH_ALEN];     /* our local ethernet address */
163
164         int bcmerror;           /* last bcm error */
165
166         u32 radio_disabled;     /* bit vector for radio disabled reasons */
167
168         u16 boardrev;   /* version # of particular board */
169         u8 sromrev;             /* version # of the srom */
170         char srom_ccode[BRCM_CNTRY_BUF_SZ];     /* Country Code in SROM */
171         u32 boardflags; /* Board specific flags from srom */
172         u32 boardflags2;        /* More board flags if sromrev >= 4 */
173         bool phy_11ncapable;    /* the PHY/HW is capable of 802.11N */
174
175         struct wl_cnt *_cnt;    /* low-level counters in driver */
176 };
177
178 enum wlc_par_id {
179         IOV_MPC = 1,
180         IOV_RTSTHRESH,
181         IOV_QTXPOWER,
182         IOV_BCN_LI_BCN          /* Beacon listen interval in # of beacons */
183 };
184
185 /***********************************************
186  * Feature-related macros to optimize out code *
187  * *********************************************
188  */
189
190 #define ENAB_1x1        0x01
191 #define ENAB_2x2        0x02
192 #define ENAB_3x3        0x04
193 #define ENAB_4x4        0x08
194 #define SUPPORT_11N     (ENAB_1x1|ENAB_2x2)
195 #define SUPPORT_HT      (ENAB_1x1|ENAB_2x2|ENAB_3x3)
196
197 /* WL11N Support */
198 #define AMPDU_AGG_HOST  1
199
200 #define EDCF_ENAB(pub) ((pub)->_wme != OFF)
201 #define QOS_ENAB(pub) ((pub)->_wme != OFF || (pub)->_n_enab & SUPPORT_11N)
202
203 /* pri is priority encoded in the packet. This maps the Packet priority to
204  * enqueue precedence as defined in wlc_prec_map
205  */
206 extern const u8 wlc_prio2prec_map[];
207 #define BRCMS_PRIO_TO_PREC(pri) wlc_prio2prec_map[(pri) & 7]
208
209 #define BRCMS_PREC_COUNT        16      /* Max precedence level implemented */
210
211 /* Mask to describe all precedence levels */
212 #define BRCMS_PREC_BMP_ALL              MAXBITVAL(BRCMS_PREC_COUNT)
213
214 /*
215  * This maps priority to one precedence higher - Used by PS-Poll response
216  * packets to simulate enqueue-at-head operation, but still maintain the
217  * order on the queue
218  */
219 #define BRCMS_PRIO_TO_HI_PREC(pri)      min(BRCMS_PRIO_TO_PREC(pri) + 1,\
220                                             BRCMS_PREC_COUNT - 1)
221
222 /* Define a bitmap of precedences comprised by each AC */
223 #define BRCMS_PREC_BMP_AC_BE    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_BE)) | \
224                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_BE)) | \
225                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_EE)) |    \
226                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_EE)))
227 #define BRCMS_PREC_BMP_AC_BK    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_BK)) | \
228                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_BK)) | \
229                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_NONE)) |  \
230                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_NONE)))
231 #define BRCMS_PREC_BMP_AC_VI    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_CL)) | \
232                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_CL)) | \
233                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_VI)) |    \
234                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_VI)))
235 #define BRCMS_PREC_BMP_AC_VO    (NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_VO)) | \
236                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_VO)) | \
237                         NBITVAL(BRCMS_PRIO_TO_PREC(PRIO_8021D_NC)) |    \
238                         NBITVAL(BRCMS_PRIO_TO_HI_PREC(PRIO_8021D_NC)))
239
240 /* network protection config */
241 #define BRCMS_PROT_G_SPEC               1       /* SPEC g protection */
242 #define BRCMS_PROT_G_OVR                2       /* SPEC g prot override */
243 #define BRCMS_PROT_G_USER               3       /* gmode specified by user */
244 #define BRCMS_PROT_OVERLAP      4       /* overlap */
245 #define BRCMS_PROT_N_USER               10      /* nmode specified by user */
246 #define BRCMS_PROT_N_CFG                11      /* n protection */
247 #define BRCMS_PROT_N_CFG_OVR    12      /* n protection override */
248 #define BRCMS_PROT_N_NONGF      13      /* non-GF protection */
249 #define BRCMS_PROT_N_NONGF_OVR  14      /* non-GF protection override */
250 #define BRCMS_PROT_N_PAM_OVR    15      /* n preamble override */
251 #define BRCMS_PROT_N_OBSS               16      /* non-HT OBSS present */
252
253 /*
254  * 54g modes (basic bits may still be overridden)
255  *
256  * GMODE_LEGACY_B
257  *      Rateset: 1b, 2b, 5.5, 11
258  *      Preamble: Long
259  *      Shortslot: Off
260  * GMODE_AUTO
261  *      Rateset: 1b, 2b, 5.5b, 11b, 18, 24, 36, 54
262  *      Extended Rateset: 6, 9, 12, 48
263  *      Preamble: Long
264  *      Shortslot: Auto
265  * GMODE_ONLY
266  *      Rateset: 1b, 2b, 5.5b, 11b, 18, 24b, 36, 54
267  *      Extended Rateset: 6b, 9, 12b, 48
268  *      Preamble: Short required
269  *      Shortslot: Auto
270  * GMODE_B_DEFERRED
271  *      Rateset: 1b, 2b, 5.5b, 11b, 18, 24, 36, 54
272  *      Extended Rateset: 6, 9, 12, 48
273  *      Preamble: Long
274  *      Shortslot: On
275  * GMODE_PERFORMANCE
276  *      Rateset: 1b, 2b, 5.5b, 6b, 9, 11b, 12b, 18, 24b, 36, 48, 54
277  *      Preamble: Short required
278  *      Shortslot: On and required
279  * GMODE_LRS
280  *      Rateset: 1b, 2b, 5.5b, 11b
281  *      Extended Rateset: 6, 9, 12, 18, 24, 36, 48, 54
282  *      Preamble: Long
283  *      Shortslot: Auto
284  */
285 #define GMODE_LEGACY_B          0
286 #define GMODE_AUTO              1
287 #define GMODE_ONLY              2
288 #define GMODE_B_DEFERRED        3
289 #define GMODE_PERFORMANCE       4
290 #define GMODE_LRS               5
291 #define GMODE_MAX               6
292
293 /* MCS values greater than this enable multiple streams */
294 #define HIGHEST_SINGLE_STREAM_MCS       7
295
296 #define MAXBANDS                2       /* Maximum #of bands */
297
298 /* max number of antenna configurations */
299 #define ANT_SELCFG_MAX          4
300
301 struct brcms_antselcfg {
302         u8 ant_config[ANT_SELCFG_MAX];  /* antenna configuration */
303         u8 num_antcfg;  /* number of available antenna configurations */
304 };
305
306 /* common functions for every port */
307 struct brcms_c_info *
308 brcms_c_attach(struct brcms_info *wl, u16 vendor, u16 device, uint unit,
309                bool piomode, void __iomem *regsva, struct pci_dev *btparam,
310                uint *perr);
311 extern uint brcms_c_detach(struct brcms_c_info *wlc);
312 extern int brcms_c_up(struct brcms_c_info *wlc);
313 extern uint brcms_c_down(struct brcms_c_info *wlc);
314
315 extern int brcms_c_set(struct brcms_c_info *wlc, int cmd, int arg);
316 extern int brcms_c_get(struct brcms_c_info *wlc, int cmd, int *arg);
317 extern bool brcms_c_chipmatch(u16 vendor, u16 device);
318 extern void brcms_c_init(struct brcms_c_info *wlc);
319 extern void brcms_c_reset(struct brcms_c_info *wlc);
320
321 extern void brcms_c_intrson(struct brcms_c_info *wlc);
322 extern u32 brcms_c_intrsoff(struct brcms_c_info *wlc);
323 extern void brcms_c_intrsrestore(struct brcms_c_info *wlc, u32 macintmask);
324 extern bool brcms_c_intrsupd(struct brcms_c_info *wlc);
325 extern bool brcms_c_isr(struct brcms_c_info *wlc, bool *wantdpc);
326 extern bool brcms_c_dpc(struct brcms_c_info *wlc, bool bounded);
327 extern void brcms_c_sendpkt_mac80211(struct brcms_c_info *wlc,
328                                      struct sk_buff *sdu,
329                                      struct ieee80211_hw *hw);
330 extern int brcms_c_ioctl(struct brcms_c_info *wlc, int cmd, void *arg, int len);
331 extern bool brcms_c_aggregatable(struct brcms_c_info *wlc, u8 tid);
332
333 /* helper functions */
334 extern void brcms_c_statsupd(struct brcms_c_info *wlc);
335 extern void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx,
336                                    int val);
337 extern int brcms_c_get_header_len(void);
338 extern void brcms_c_mac_bcn_promisc_change(struct brcms_c_info *wlc,
339                                            bool promisc);
340 extern void brcms_c_set_addrmatch(struct brcms_c_info *wlc,
341                                   int match_reg_offset,
342                                   const u8 *addr);
343 extern void brcms_c_wme_setparams(struct brcms_c_info *wlc, u16 aci,
344                               const struct ieee80211_tx_queue_params *arg,
345                               bool suspend);
346 extern struct brcms_pub *brcms_c_pub(struct brcms_c_info *wlc);
347
348 /* common functions for every port */
349 extern void brcms_c_mhf(struct brcms_c_info *wlc, u8 idx, u16 mask, u16 val,
350                     int bands);
351 extern void brcms_c_rate_lookup_init(struct brcms_c_info *wlc,
352                                      struct brcms_c_rateset *rateset);
353 extern void brcms_default_rateset(struct brcms_c_info *wlc,
354                                   struct brcms_c_rateset *rs);
355
356 extern void brcms_c_ampdu_flush(struct brcms_c_info *wlc,
357                             struct ieee80211_sta *sta, u16 tid);
358 extern void brcms_c_ampdu_tx_operational(struct brcms_c_info *wlc, u8 tid,
359                                          u8 ba_wsize, uint max_rx_ampdu_bytes);
360 extern int brcms_c_set_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
361                            int val);
362 extern int brcms_c_get_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
363                            int *ret_int_ptr);
364 extern char *getvar(char *vars, const char *name);
365 extern int getintvar(char *vars, const char *name);
366
367 /* wlc_phy.c helper functions */
368 extern void brcms_c_set_ps_ctrl(struct brcms_c_info *wlc);
369 extern void brcms_c_mctrl(struct brcms_c_info *wlc, u32 mask, u32 val);
370
371 extern int brcms_c_module_register(struct brcms_pub *pub,
372                                    const char *name, struct brcms_info *hdl,
373                                    int (*down_fn)(void *handle));
374 extern int brcms_c_module_unregister(struct brcms_pub *pub, const char *name,
375                                      struct brcms_info *hdl);
376 extern void brcms_c_suspend_mac_and_wait(struct brcms_c_info *wlc);
377 extern void brcms_c_enable_mac(struct brcms_c_info *wlc);
378 extern void brcms_c_associate_upd(struct brcms_c_info *wlc, bool state);
379 extern void brcms_c_scan_start(struct brcms_c_info *wlc);
380 extern void brcms_c_scan_stop(struct brcms_c_info *wlc);
381 extern int brcms_c_get_curband(struct brcms_c_info *wlc);
382 extern void brcms_c_wait_for_tx_completion(struct brcms_c_info *wlc,
383                                            bool drop);
384
385 /* helper functions */
386 extern bool brcms_c_check_radio_disabled(struct brcms_c_info *wlc);
387 extern bool brcms_c_radio_monitor_stop(struct brcms_c_info *wlc);
388
389 #endif                          /* _BRCM_PUB_H_ */