]> Pileus Git - ~andy/linux/blob - drivers/staging/brcm80211/brcmsmac/wlc_rate.h
f406a79cb55ac0d900d42329c9ca9ba9715480e5
[~andy/linux] / drivers / staging / brcm80211 / brcmsmac / wlc_rate.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 _WLC_RATE_H_
18 #define _WLC_RATE_H_
19
20 extern const u8 rate_info[];
21 extern const struct wlc_rateset cck_ofdm_mimo_rates;
22 extern const struct wlc_rateset ofdm_mimo_rates;
23 extern const struct wlc_rateset cck_ofdm_rates;
24 extern const struct wlc_rateset ofdm_rates;
25 extern const struct wlc_rateset cck_rates;
26 extern const struct wlc_rateset gphy_legacy_rates;
27 extern const struct wlc_rateset wlc_lrs_rates;
28 extern const struct wlc_rateset rate_limit_1_2;
29
30 typedef struct mcs_info {
31         u32 phy_rate_20;        /* phy rate in kbps [20Mhz] */
32         u32 phy_rate_40;        /* phy rate in kbps [40Mhz] */
33         u32 phy_rate_20_sgi;    /* phy rate in kbps [20Mhz] with SGI */
34         u32 phy_rate_40_sgi;    /* phy rate in kbps [40Mhz] with SGI */
35         u8 tx_phy_ctl3; /* phy ctl byte 3, code rate, modulation type, # of streams */
36         u8 leg_ofdm;            /* matching legacy ofdm rate in 500bkps */
37 } mcs_info_t;
38
39 #define WLC_MAXMCS      32      /* max valid mcs index */
40 #define MCS_TABLE_SIZE  33      /* Number of mcs entries in the table */
41 extern const mcs_info_t mcs_table[];
42
43 #define MCS_INVALID     0xFF
44 #define MCS_CR_MASK     0x07    /* Code Rate bit mask */
45 #define MCS_MOD_MASK    0x38    /* Modulation bit shift */
46 #define MCS_MOD_SHIFT   3       /* MOdulation bit shift */
47 #define MCS_TXS_MASK    0xc0    /* num tx streams - 1 bit mask */
48 #define MCS_TXS_SHIFT   6       /* num tx streams - 1 bit shift */
49 #define MCS_CR(_mcs)    (mcs_table[_mcs].tx_phy_ctl3 & MCS_CR_MASK)
50 #define MCS_MOD(_mcs)   ((mcs_table[_mcs].tx_phy_ctl3 & MCS_MOD_MASK) >> MCS_MOD_SHIFT)
51 #define MCS_TXS(_mcs)   ((mcs_table[_mcs].tx_phy_ctl3 & MCS_TXS_MASK) >> MCS_TXS_SHIFT)
52 #define MCS_RATE(_mcs, _is40, _sgi)     (_sgi ? \
53         (_is40 ? mcs_table[_mcs].phy_rate_40_sgi : mcs_table[_mcs].phy_rate_20_sgi) : \
54         (_is40 ? mcs_table[_mcs].phy_rate_40 : mcs_table[_mcs].phy_rate_20))
55 #define VALID_MCS(_mcs) ((_mcs < MCS_TABLE_SIZE))
56
57 /* rate related definitions */
58 #define WLC_RATE_FLAG   0x80    /* Rate flag to indicate it is a basic rate */
59 #define WLC_RATE_MASK   0x7f    /* Rate value mask w/o basic rate flag */
60
61 /* Macro to use in the rate_info table */
62 #define WLC_RATE_MASK_FULL      0xff /* Rate value mask with basic rate flag */
63
64 #define WLC_RATE_500K_TO_BPS(rate)      ((rate) * 500000)       /* convert 500kbps to bps */
65
66 /* rate spec : holds rate and mode specific information required to generate a tx frame. */
67 /* Legacy CCK and OFDM information is held in the same manner as was done in the past    */
68 /* (in the lower byte) the upper 3 bytes primarily hold MIMO specific information        */
69 typedef u32 ratespec_t;
70
71 /* rate spec bit fields */
72 #define RSPEC_RATE_MASK         0x0000007F      /* Either 500Kbps units or MIMO MCS idx */
73 #define RSPEC_MIMORATE          0x08000000      /* mimo MCS is stored in RSPEC_RATE_MASK */
74 #define RSPEC_BW_MASK           0x00000700      /* mimo bw mask */
75 #define RSPEC_BW_SHIFT          8       /* mimo bw shift */
76 #define RSPEC_STF_MASK          0x00003800      /* mimo Space/Time/Frequency mode mask */
77 #define RSPEC_STF_SHIFT         11      /* mimo Space/Time/Frequency mode shift */
78 #define RSPEC_CT_MASK           0x0000C000      /* mimo coding type mask */
79 #define RSPEC_CT_SHIFT          14      /* mimo coding type shift */
80 #define RSPEC_STC_MASK          0x00300000      /* mimo num STC streams per PLCP defn. */
81 #define RSPEC_STC_SHIFT         20      /* mimo num STC streams per PLCP defn. */
82 #define RSPEC_LDPC_CODING       0x00400000      /* mimo bit indicates adv coding in use */
83 #define RSPEC_SHORT_GI          0x00800000      /* mimo bit indicates short GI in use */
84 #define RSPEC_OVERRIDE          0x80000000      /* bit indicates override both rate & mode */
85 #define RSPEC_OVERRIDE_MCS_ONLY 0x40000000      /* bit indicates override rate only */
86
87 #define WLC_HTPHY               127     /* HT PHY Membership */
88
89 #define RSPEC_ACTIVE(rspec)     (rspec & (RSPEC_RATE_MASK | RSPEC_MIMORATE))
90 #define RSPEC2RATE(rspec)       ((rspec & RSPEC_MIMORATE) ? \
91         MCS_RATE((rspec & RSPEC_RATE_MASK), RSPEC_IS40MHZ(rspec), RSPEC_ISSGI(rspec)) : \
92         (rspec & RSPEC_RATE_MASK))
93 /* return rate in unit of 500Kbps -- for internal use in wlc_rate_sel.c */
94 #define RSPEC2RATE500K(rspec)   ((rspec & RSPEC_MIMORATE) ? \
95                 MCS_RATE((rspec & RSPEC_RATE_MASK), state->is40bw, RSPEC_ISSGI(rspec))/500 : \
96                 (rspec & RSPEC_RATE_MASK))
97 #define CRSPEC2RATE500K(rspec)  ((rspec & RSPEC_MIMORATE) ? \
98                 MCS_RATE((rspec & RSPEC_RATE_MASK), RSPEC_IS40MHZ(rspec), RSPEC_ISSGI(rspec))/500 :\
99                 (rspec & RSPEC_RATE_MASK))
100
101 #define RSPEC2KBPS(rspec)       (IS_MCS(rspec) ? RSPEC2RATE(rspec) : RSPEC2RATE(rspec)*500)
102 #define RSPEC_PHYTXBYTE2(rspec) ((rspec & 0xff00) >> 8)
103 #define RSPEC_GET_BW(rspec)     ((rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT)
104 #define RSPEC_IS40MHZ(rspec)    ((((rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT) == \
105                                 PHY_TXC1_BW_40MHZ) || (((rspec & RSPEC_BW_MASK) >> \
106                                 RSPEC_BW_SHIFT) == PHY_TXC1_BW_40MHZ_DUP))
107 #define RSPEC_ISSGI(rspec)      ((rspec & RSPEC_SHORT_GI) == RSPEC_SHORT_GI)
108 #define RSPEC_MIMOPLCP3(rspec)  ((rspec & 0xf00000) >> 16)
109 #define PLCP3_ISSGI(plcp)       (plcp & (RSPEC_SHORT_GI >> 16))
110 #define RSPEC_STC(rspec)        ((rspec & RSPEC_STC_MASK) >> RSPEC_STC_SHIFT)
111 #define RSPEC_STF(rspec)        ((rspec & RSPEC_STF_MASK) >> RSPEC_STF_SHIFT)
112 #define PLCP3_ISSTBC(plcp)      ((plcp & (RSPEC_STC_MASK) >> 16) == 0x10)
113 #define PLCP3_STC_MASK          0x30
114 #define PLCP3_STC_SHIFT         4
115
116 /* Rate info table; takes a legacy rate or ratespec_t */
117 #define IS_MCS(r)       (r & RSPEC_MIMORATE)
118 #define IS_OFDM(r)      (!IS_MCS(r) && (rate_info[(r) & RSPEC_RATE_MASK] & WLC_RATE_FLAG))
119 #define IS_CCK(r)       (!IS_MCS(r) && ( \
120                          ((r) & WLC_RATE_MASK) == WLC_RATE_1M || \
121                          ((r) & WLC_RATE_MASK) == WLC_RATE_2M || \
122                          ((r) & WLC_RATE_MASK) == WLC_RATE_5M5 || \
123                          ((r) & WLC_RATE_MASK) == WLC_RATE_11M))
124 #define IS_SINGLE_STREAM(mcs)   (((mcs) <= HIGHEST_SINGLE_STREAM_MCS) || ((mcs) == 32))
125 #define CCK_RSPEC(cck)          ((cck) & RSPEC_RATE_MASK)
126 #define OFDM_RSPEC(ofdm)        (((ofdm) & RSPEC_RATE_MASK) |\
127         (PHY_TXC1_MODE_CDD << RSPEC_STF_SHIFT))
128 #define LEGACY_RSPEC(rate)      (IS_CCK(rate) ? CCK_RSPEC(rate) : OFDM_RSPEC(rate))
129
130 #define MCS_RSPEC(mcs)          (((mcs) & RSPEC_RATE_MASK) | RSPEC_MIMORATE | \
131         (IS_SINGLE_STREAM(mcs) ? (PHY_TXC1_MODE_CDD << RSPEC_STF_SHIFT) : \
132         (PHY_TXC1_MODE_SDM << RSPEC_STF_SHIFT)))
133
134 /* Convert encoded rate value in plcp header to numerical rates in 500 KHz increments */
135 extern const u8 ofdm_rate_lookup[];
136 #define OFDM_PHY2MAC_RATE(rlpt)         (ofdm_rate_lookup[rlpt & 0x7])
137 #define CCK_PHY2MAC_RATE(signal)        (signal/5)
138
139 /* Rates specified in wlc_rateset_filter() */
140 #define WLC_RATES_CCK_OFDM      0
141 #define WLC_RATES_CCK           1
142 #define WLC_RATES_OFDM          2
143
144 /* use the stuct form instead of typedef to fix dependency problems */
145 struct wlc_rateset;
146
147 /* sanitize, and sort a rateset with the basic bit(s) preserved, validate rateset */
148 extern bool wlc_rate_hwrs_filter_sort_validate(struct wlc_rateset *rs,
149                                                const struct wlc_rateset *hw_rs,
150                                                bool check_brate,
151                                                u8 txstreams);
152 /* copy rateset src to dst as-is (no masking or sorting) */
153 extern void wlc_rateset_copy(const struct wlc_rateset *src,
154                              struct wlc_rateset *dst);
155
156 /* would be nice to have these documented ... */
157 extern ratespec_t wlc_compute_rspec(d11rxhdr_t *rxh, u8 *plcp);
158
159 extern void wlc_rateset_filter(struct wlc_rateset *src, struct wlc_rateset *dst,
160                                bool basic_only, u8 rates, uint xmask,
161                                bool mcsallow);
162 extern void wlc_rateset_default(struct wlc_rateset *rs_tgt,
163                                 const struct wlc_rateset *rs_hw, uint phy_type,
164                                 int bandtype, bool cck_only, uint rate_mask,
165                                 bool mcsallow, u8 bw, u8 txstreams);
166 extern s16 wlc_rate_legacy_phyctl(uint rate);
167
168 extern void wlc_rateset_mcs_upd(struct wlc_rateset *rs, u8 txstreams);
169 extern void wlc_rateset_mcs_clear(struct wlc_rateset *rateset);
170 extern void wlc_rateset_mcs_build(struct wlc_rateset *rateset, u8 txstreams);
171 extern void wlc_rateset_bw_mcs_filter(struct wlc_rateset *rateset, u8 bw);
172
173 #endif                          /* _WLC_RATE_H_ */