]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/brcm80211/sys/wlc_rate.h
Staging: Add initial release of brcm80211 - Broadcom 802.11n wireless LAN driver.
[mirror_ubuntu-artful-kernel.git] / drivers / staging / brcm80211 / sys / 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 uint8 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 uint32 phy_rate_20; /* phy rate in kbps [20Mhz] */
32 uint32 phy_rate_40; /* phy rate in kbps [40Mhz] */
33 uint32 phy_rate_20_sgi; /* phy rate in kbps [20Mhz] with SGI */
34 uint32 phy_rate_40_sgi; /* phy rate in kbps [40Mhz] with SGI */
35 uint8 tx_phy_ctl3; /* phy ctl byte 3, code rate, modulation type, # of streams */
36 uint8 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 #define WLC_RATE_FLAG 0x80 /* Rate flag: basic or ofdm */
58
59 /* Macros to use the rate_info table */
60 #define RATE_MASK 0x7f /* Rate value mask w/o basic rate flag */
61 #define RATE_MASK_FULL 0xff /* Rate value mask with basic rate flag */
62
63 #define WLC_RATE_500K_TO_BPS(rate) ((rate) * 500000) /* convert 500kbps to bps */
64
65 /* rate spec : holds rate and mode specific information required to generate a tx frame. */
66 /* Legacy CCK and OFDM information is held in the same manner as was done in the past */
67 /* (in the lower byte) the upper 3 bytes primarily hold MIMO specific information */
68 typedef uint32 ratespec_t;
69
70 /* rate spec bit fields */
71 #define RSPEC_RATE_MASK 0x0000007F /* Either 500Kbps units or MIMO MCS idx */
72 #define RSPEC_MIMORATE 0x08000000 /* mimo MCS is stored in RSPEC_RATE_MASK */
73 #define RSPEC_BW_MASK 0x00000700 /* mimo bw mask */
74 #define RSPEC_BW_SHIFT 8 /* mimo bw shift */
75 #define RSPEC_STF_MASK 0x00003800 /* mimo Space/Time/Frequency mode mask */
76 #define RSPEC_STF_SHIFT 11 /* mimo Space/Time/Frequency mode shift */
77 #define RSPEC_CT_MASK 0x0000C000 /* mimo coding type mask */
78 #define RSPEC_CT_SHIFT 14 /* mimo coding type shift */
79 #define RSPEC_STC_MASK 0x00300000 /* mimo num STC streams per PLCP defn. */
80 #define RSPEC_STC_SHIFT 20 /* mimo num STC streams per PLCP defn. */
81 #define RSPEC_LDPC_CODING 0x00400000 /* mimo bit indicates adv coding in use */
82 #define RSPEC_SHORT_GI 0x00800000 /* mimo bit indicates short GI in use */
83 #define RSPEC_OVERRIDE 0x80000000 /* bit indicates override both rate & mode */
84 #define RSPEC_OVERRIDE_MCS_ONLY 0x40000000 /* bit indicates override rate only */
85
86 #define WLC_HTPHY 127 /* HT PHY Membership */
87
88 #define RSPEC_ACTIVE(rspec) (rspec & (RSPEC_RATE_MASK | RSPEC_MIMORATE))
89 #define RSPEC2RATE(rspec) ((rspec & RSPEC_MIMORATE) ? \
90 MCS_RATE((rspec & RSPEC_RATE_MASK), RSPEC_IS40MHZ(rspec), RSPEC_ISSGI(rspec)) : \
91 (rspec & RSPEC_RATE_MASK))
92 /* return rate in unit of 500Kbps -- for internal use in wlc_rate_sel.c */
93 #define RSPEC2RATE500K(rspec) ((rspec & RSPEC_MIMORATE) ? \
94 MCS_RATE((rspec & RSPEC_RATE_MASK), state->is40bw, RSPEC_ISSGI(rspec))/500 : \
95 (rspec & RSPEC_RATE_MASK))
96 #define CRSPEC2RATE500K(rspec) ((rspec & RSPEC_MIMORATE) ? \
97 MCS_RATE((rspec & RSPEC_RATE_MASK), RSPEC_IS40MHZ(rspec), RSPEC_ISSGI(rspec))/500 :\
98 (rspec & RSPEC_RATE_MASK))
99
100 #define RSPEC2KBPS(rspec) (IS_MCS(rspec) ? RSPEC2RATE(rspec) : RSPEC2RATE(rspec)*500)
101 #define RSPEC_PHYTXBYTE2(rspec) ((rspec & 0xff00) >> 8)
102 #define RSPEC_GET_BW(rspec) ((rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT)
103 #define RSPEC_IS40MHZ(rspec) ((((rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT) == \
104 PHY_TXC1_BW_40MHZ) || (((rspec & RSPEC_BW_MASK) >> \
105 RSPEC_BW_SHIFT) == PHY_TXC1_BW_40MHZ_DUP))
106 #define RSPEC_ISSGI(rspec) ((rspec & RSPEC_SHORT_GI) == RSPEC_SHORT_GI)
107 #define RSPEC_MIMOPLCP3(rspec) ((rspec & 0xf00000) >> 16)
108 #define PLCP3_ISSGI(plcp) (plcp & (RSPEC_SHORT_GI >> 16))
109 #define RSPEC_STC(rspec) ((rspec & RSPEC_STC_MASK) >> RSPEC_STC_SHIFT)
110 #define RSPEC_STF(rspec) ((rspec & RSPEC_STF_MASK) >> RSPEC_STF_SHIFT)
111 #define PLCP3_ISSTBC(plcp) ((plcp & (RSPEC_STC_MASK) >> 16) == 0x10)
112 #define PLCP3_STC_MASK 0x30
113 #define PLCP3_STC_SHIFT 4
114
115 /* Rate info table; takes a legacy rate or ratespec_t */
116 #define IS_MCS(r) (r & RSPEC_MIMORATE)
117 #define IS_OFDM(r) (!IS_MCS(r) && (rate_info[(r) & RSPEC_RATE_MASK] & WLC_RATE_FLAG))
118 #define IS_CCK(r) (!IS_MCS(r) && (((r) & RATE_MASK) == WLC_RATE_1M || \
119 ((r) & RATE_MASK) == WLC_RATE_2M || \
120 ((r) & RATE_MASK) == WLC_RATE_5M5 || ((r) & RATE_MASK) == WLC_RATE_11M))
121 #define IS_SINGLE_STREAM(mcs) (((mcs) <= HIGHEST_SINGLE_STREAM_MCS) || ((mcs) == 32))
122 #define CCK_RSPEC(cck) ((cck) & RSPEC_RATE_MASK)
123 #define OFDM_RSPEC(ofdm) (((ofdm) & RSPEC_RATE_MASK) |\
124 (PHY_TXC1_MODE_CDD << RSPEC_STF_SHIFT))
125 #define LEGACY_RSPEC(rate) (IS_CCK(rate) ? CCK_RSPEC(rate) : OFDM_RSPEC(rate))
126
127 #define MCS_RSPEC(mcs) (((mcs) & RSPEC_RATE_MASK) | RSPEC_MIMORATE | \
128 (IS_SINGLE_STREAM(mcs) ? (PHY_TXC1_MODE_CDD << RSPEC_STF_SHIFT) : \
129 (PHY_TXC1_MODE_SDM << RSPEC_STF_SHIFT)))
130
131 /* Convert encoded rate value in plcp header to numerical rates in 500 KHz increments */
132 extern const uint8 ofdm_rate_lookup[];
133 #define OFDM_PHY2MAC_RATE(rlpt) (ofdm_rate_lookup[rlpt & 0x7])
134 #define CCK_PHY2MAC_RATE(signal) (signal/5)
135
136 /* Rates specified in wlc_rateset_filter() */
137 #define WLC_RATES_CCK_OFDM 0
138 #define WLC_RATES_CCK 1
139 #define WLC_RATES_OFDM 2
140
141 /* use the stuct form instead of typedef to fix dependency problems */
142 struct wlc_rateset;
143
144 /* sanitize, and sort a rateset with the basic bit(s) preserved, validate rateset */
145 extern bool wlc_rate_hwrs_filter_sort_validate(struct wlc_rateset *rs,
146 const struct wlc_rateset *hw_rs,
147 bool check_brate,
148 uint8 txstreams);
149 /* copy rateset src to dst as-is (no masking or sorting) */
150 extern void wlc_rateset_copy(const struct wlc_rateset *src,
151 struct wlc_rateset *dst);
152
153 /* would be nice to have these documented ... */
154 extern ratespec_t wlc_compute_rspec(d11rxhdr_t * rxh, uint8 * plcp);
155
156 extern void wlc_rateset_filter(struct wlc_rateset *src, struct wlc_rateset *dst,
157 bool basic_only, uint8 rates, uint xmask,
158 bool mcsallow);
159 extern void wlc_rateset_default(struct wlc_rateset *rs_tgt,
160 const struct wlc_rateset *rs_hw, uint phy_type,
161 int bandtype, bool cck_only, uint rate_mask,
162 bool mcsallow, uint8 bw, uint8 txstreams);
163 extern int16 wlc_rate_legacy_phyctl(uint rate);
164
165 extern void wlc_rateset_mcs_upd(struct wlc_rateset *rs, uint8 txstreams);
166 extern void wlc_rateset_mcs_clear(struct wlc_rateset *rateset);
167 extern void wlc_rateset_mcs_build(struct wlc_rateset *rateset, uint8 txstreams);
168 extern void wlc_rateset_bw_mcs_filter(struct wlc_rateset *rateset, uint8 bw);
169
170 #endif /* _WLC_RATE_H_ */