]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/brcm80211/sys/wlc_rate.c
Staging: brcm80211: remove FALSE #define
[net-next-2.6.git] / drivers / staging / brcm80211 / sys / wlc_rate.c
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 #include <wlc_cfg.h>
18 #include <typedefs.h>
19 #include <osl.h>
20 #include <linux/kernel.h>
21 #include <linuxver.h>
22 #include <bcmutils.h>
23 #include <siutils.h>
24 #include <bcmendian.h>
25 #include <wlioctl.h>
26
27 #include <proto/802.11.h>
28 #include <d11.h>
29 #include <wlc_rate.h>
30 #include <wl_dbg.h>
31 #include <wlc_pub.h>
32
33 /* Rate info per rate: It tells whether a rate is ofdm or not and its phy_rate value */
34 const u8 rate_info[WLC_MAXRATE + 1] = {
35         /*  0     1     2     3     4     5     6     7     8     9 */
36 /*   0 */ 0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
37 /*  10 */ 0x00, 0x37, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x00,
38 /*  20 */ 0x00, 0x00, 0x6e, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00,
39 /*  30 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00,
40 /*  40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00,
41 /*  50 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 /*  60 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 /*  70 */ 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 /*  80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 /*  90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00,
46 /* 100 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c
47 };
48
49 /* rates are in units of Kbps */
50 const mcs_info_t mcs_table[MCS_TABLE_SIZE] = {
51         /* MCS  0: SS 1, MOD: BPSK,  CR 1/2 */
52         {6500, 13500, CEIL(6500 * 10, 9), CEIL(13500 * 10, 9), 0x00,
53          WLC_RATE_6M},
54         /* MCS  1: SS 1, MOD: QPSK,  CR 1/2 */
55         {13000, 27000, CEIL(13000 * 10, 9), CEIL(27000 * 10, 9), 0x08,
56          WLC_RATE_12M},
57         /* MCS  2: SS 1, MOD: QPSK,  CR 3/4 */
58         {19500, 40500, CEIL(19500 * 10, 9), CEIL(40500 * 10, 9), 0x0A,
59          WLC_RATE_18M},
60         /* MCS  3: SS 1, MOD: 16QAM, CR 1/2 */
61         {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0x10,
62          WLC_RATE_24M},
63         /* MCS  4: SS 1, MOD: 16QAM, CR 3/4 */
64         {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x12,
65          WLC_RATE_36M},
66         /* MCS  5: SS 1, MOD: 64QAM, CR 2/3 */
67         {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0x19,
68          WLC_RATE_48M},
69         /* MCS  6: SS 1, MOD: 64QAM, CR 3/4 */
70         {58500, 121500, CEIL(58500 * 10, 9), CEIL(121500 * 10, 9), 0x1A,
71          WLC_RATE_54M},
72         /* MCS  7: SS 1, MOD: 64QAM, CR 5/6 */
73         {65000, 135000, CEIL(65000 * 10, 9), CEIL(135000 * 10, 9), 0x1C,
74          WLC_RATE_54M},
75         /* MCS  8: SS 2, MOD: BPSK,  CR 1/2 */
76         {13000, 27000, CEIL(13000 * 10, 9), CEIL(27000 * 10, 9), 0x40,
77          WLC_RATE_6M},
78         /* MCS  9: SS 2, MOD: QPSK,  CR 1/2 */
79         {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0x48,
80          WLC_RATE_12M},
81         /* MCS 10: SS 2, MOD: QPSK,  CR 3/4 */
82         {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x4A,
83          WLC_RATE_18M},
84         /* MCS 11: SS 2, MOD: 16QAM, CR 1/2 */
85         {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0x50,
86          WLC_RATE_24M},
87         /* MCS 12: SS 2, MOD: 16QAM, CR 3/4 */
88         {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0x52,
89          WLC_RATE_36M},
90         /* MCS 13: SS 2, MOD: 64QAM, CR 2/3 */
91         {104000, 216000, CEIL(104000 * 10, 9), CEIL(216000 * 10, 9), 0x59,
92          WLC_RATE_48M},
93         /* MCS 14: SS 2, MOD: 64QAM, CR 3/4 */
94         {117000, 243000, CEIL(117000 * 10, 9), CEIL(243000 * 10, 9), 0x5A,
95          WLC_RATE_54M},
96         /* MCS 15: SS 2, MOD: 64QAM, CR 5/6 */
97         {130000, 270000, CEIL(130000 * 10, 9), CEIL(270000 * 10, 9), 0x5C,
98          WLC_RATE_54M},
99         /* MCS 16: SS 3, MOD: BPSK,  CR 1/2 */
100         {19500, 40500, CEIL(19500 * 10, 9), CEIL(40500 * 10, 9), 0x80,
101          WLC_RATE_6M},
102         /* MCS 17: SS 3, MOD: QPSK,  CR 1/2 */
103         {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x88,
104          WLC_RATE_12M},
105         /* MCS 18: SS 3, MOD: QPSK,  CR 3/4 */
106         {58500, 121500, CEIL(58500 * 10, 9), CEIL(121500 * 10, 9), 0x8A,
107          WLC_RATE_18M},
108         /* MCS 19: SS 3, MOD: 16QAM, CR 1/2 */
109         {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0x90,
110          WLC_RATE_24M},
111         /* MCS 20: SS 3, MOD: 16QAM, CR 3/4 */
112         {117000, 243000, CEIL(117000 * 10, 9), CEIL(243000 * 10, 9), 0x92,
113          WLC_RATE_36M},
114         /* MCS 21: SS 3, MOD: 64QAM, CR 2/3 */
115         {156000, 324000, CEIL(156000 * 10, 9), CEIL(324000 * 10, 9), 0x99,
116          WLC_RATE_48M},
117         /* MCS 22: SS 3, MOD: 64QAM, CR 3/4 */
118         {175500, 364500, CEIL(175500 * 10, 9), CEIL(364500 * 10, 9), 0x9A,
119          WLC_RATE_54M},
120         /* MCS 23: SS 3, MOD: 64QAM, CR 5/6 */
121         {195000, 405000, CEIL(195000 * 10, 9), CEIL(405000 * 10, 9), 0x9B,
122          WLC_RATE_54M},
123         /* MCS 24: SS 4, MOD: BPSK,  CR 1/2 */
124         {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0xC0,
125          WLC_RATE_6M},
126         /* MCS 25: SS 4, MOD: QPSK,  CR 1/2 */
127         {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0xC8,
128          WLC_RATE_12M},
129         /* MCS 26: SS 4, MOD: QPSK,  CR 3/4 */
130         {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0xCA,
131          WLC_RATE_18M},
132         /* MCS 27: SS 4, MOD: 16QAM, CR 1/2 */
133         {104000, 216000, CEIL(104000 * 10, 9), CEIL(216000 * 10, 9), 0xD0,
134          WLC_RATE_24M},
135         /* MCS 28: SS 4, MOD: 16QAM, CR 3/4 */
136         {156000, 324000, CEIL(156000 * 10, 9), CEIL(324000 * 10, 9), 0xD2,
137          WLC_RATE_36M},
138         /* MCS 29: SS 4, MOD: 64QAM, CR 2/3 */
139         {208000, 432000, CEIL(208000 * 10, 9), CEIL(432000 * 10, 9), 0xD9,
140          WLC_RATE_48M},
141         /* MCS 30: SS 4, MOD: 64QAM, CR 3/4 */
142         {234000, 486000, CEIL(234000 * 10, 9), CEIL(486000 * 10, 9), 0xDA,
143          WLC_RATE_54M},
144         /* MCS 31: SS 4, MOD: 64QAM, CR 5/6 */
145         {260000, 540000, CEIL(260000 * 10, 9), CEIL(540000 * 10, 9), 0xDB,
146          WLC_RATE_54M},
147         /* MCS 32: SS 1, MOD: BPSK,  CR 1/2 */
148         {0, 6000, 0, CEIL(6000 * 10, 9), 0x00, WLC_RATE_6M},
149 };
150
151 /* phycfg for legacy OFDM frames: code rate, modulation scheme, spatial streams
152  *   Number of spatial streams: always 1
153  *   other fields: refer to table 78 of section 17.3.2.2 of the original .11a standard
154  */
155 typedef struct legacy_phycfg {
156         u32 rate_ofdm;  /* ofdm mac rate */
157         u8 tx_phy_ctl3; /* phy ctl byte 3, code rate, modulation type, # of streams */
158 } legacy_phycfg_t;
159
160 #define LEGACY_PHYCFG_TABLE_SIZE        12      /* Number of legacy_rate_cfg entries in the table */
161
162 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
163 /* Eventually MIMOPHY would also be converted to this format */
164 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
165 static const legacy_phycfg_t legacy_phycfg_table[LEGACY_PHYCFG_TABLE_SIZE] = {
166         {WLC_RATE_1M, 0x00},    /* CCK  1Mbps,  data rate  0 */
167         {WLC_RATE_2M, 0x08},    /* CCK  2Mbps,  data rate  1 */
168         {WLC_RATE_5M5, 0x10},   /* CCK  5.5Mbps,  data rate  2 */
169         {WLC_RATE_11M, 0x18},   /* CCK  11Mbps,  data rate   3 */
170         {WLC_RATE_6M, 0x00},    /* OFDM  6Mbps,  code rate 1/2, BPSK,   1 spatial stream */
171         {WLC_RATE_9M, 0x02},    /* OFDM  9Mbps,  code rate 3/4, BPSK,   1 spatial stream */
172         {WLC_RATE_12M, 0x08},   /* OFDM  12Mbps, code rate 1/2, QPSK,   1 spatial stream */
173         {WLC_RATE_18M, 0x0A},   /* OFDM  18Mbps, code rate 3/4, QPSK,   1 spatial stream */
174         {WLC_RATE_24M, 0x10},   /* OFDM  24Mbps, code rate 1/2, 16-QAM, 1 spatial stream */
175         {WLC_RATE_36M, 0x12},   /* OFDM  36Mbps, code rate 3/4, 16-QAM, 1 spatial stream */
176         {WLC_RATE_48M, 0x19},   /* OFDM  48Mbps, code rate 2/3, 64-QAM, 1 spatial stream */
177         {WLC_RATE_54M, 0x1A},   /* OFDM  54Mbps, code rate 3/4, 64-QAM, 1 spatial stream */
178 };
179
180 /* Hardware rates (also encodes default basic rates) */
181
182 const wlc_rateset_t cck_ofdm_mimo_rates = {
183         12,
184         {                       /*    1b,   2b,   5.5b, 6,    9,    11b,  12,   18,   24,   36,   48,   54 Mbps */
185          0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60,
186          0x6c},
187         0x00,
188         {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189          0x00, 0x00, 0x00, 0x00}
190 };
191
192 const wlc_rateset_t ofdm_mimo_rates = {
193         8,
194         {                       /*    6b,   9,    12b,  18,   24b,  36,   48,   54 Mbps */
195          0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c},
196         0x00,
197         {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198          0x00, 0x00, 0x00, 0x00}
199 };
200
201 /* Default ratesets that include MCS32 for 40BW channels */
202 const wlc_rateset_t cck_ofdm_40bw_mimo_rates = {
203         12,
204         {                       /*    1b,   2b,   5.5b, 6,    9,    11b,  12,   18,   24,   36,   48,   54 Mbps */
205          0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60,
206          0x6c},
207         0x00,
208         {0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209          0x00, 0x00, 0x00, 0x00}
210 };
211
212 const wlc_rateset_t ofdm_40bw_mimo_rates = {
213         8,
214         {                       /*    6b,   9,    12b,  18,   24b,  36,   48,   54 Mbps */
215          0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c},
216         0x00,
217         {0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218          0x00, 0x00, 0x00, 0x00}
219 };
220
221 const wlc_rateset_t cck_ofdm_rates = {
222         12,
223         {                       /*    1b,   2b,   5.5b, 6,    9,    11b,  12,   18,   24,   36,   48,   54 Mbps */
224          0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60,
225          0x6c},
226         0x00,
227         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228          0x00, 0x00, 0x00, 0x00}
229 };
230
231 const wlc_rateset_t gphy_legacy_rates = {
232         4,
233         {                       /*    1b,   2b,   5.5b,  11b Mbps */
234          0x82, 0x84, 0x8b, 0x96},
235         0x00,
236         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237          0x00, 0x00, 0x00, 0x00}
238 };
239
240 const wlc_rateset_t ofdm_rates = {
241         8,
242         {                       /*    6b,   9,    12b,  18,   24b,  36,   48,   54 Mbps */
243          0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c},
244         0x00,
245         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246          0x00, 0x00, 0x00, 0x00}
247 };
248
249 const wlc_rateset_t cck_rates = {
250         4,
251         {                       /*    1b,   2b,   5.5,  11 Mbps */
252          0x82, 0x84, 0x0b, 0x16},
253         0x00,
254         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255          0x00, 0x00, 0x00, 0x00}
256 };
257
258 static bool wlc_rateset_valid(wlc_rateset_t *rs, bool check_brate);
259
260 /* check if rateset is valid.
261  * if check_brate is true, rateset without a basic rate is considered NOT valid.
262  */
263 static bool wlc_rateset_valid(wlc_rateset_t *rs, bool check_brate)
264 {
265         uint idx;
266
267         if (!rs->count)
268                 return false;
269
270         if (!check_brate)
271                 return true;
272
273         /* error if no basic rates */
274         for (idx = 0; idx < rs->count; idx++) {
275                 if (rs->rates[idx] & WLC_RATE_FLAG)
276                         return true;
277         }
278         return false;
279 }
280
281 void wlc_rateset_mcs_upd(wlc_rateset_t *rs, u8 txstreams)
282 {
283         int i;
284         for (i = txstreams; i < MAX_STREAMS_SUPPORTED; i++)
285                 rs->mcs[i] = 0;
286 }
287
288 /* filter based on hardware rateset, and sort filtered rateset with basic bit(s) preserved,
289  * and check if resulting rateset is valid.
290 */
291 bool
292 wlc_rate_hwrs_filter_sort_validate(wlc_rateset_t *rs,
293                                    const wlc_rateset_t *hw_rs,
294                                    bool check_brate, u8 txstreams)
295 {
296         u8 rateset[WLC_MAXRATE + 1];
297         u8 r;
298         uint count;
299         uint i;
300
301         bzero(rateset, sizeof(rateset));
302         count = rs->count;
303
304         for (i = 0; i < count; i++) {
305                 /* mask off "basic rate" bit, WLC_RATE_FLAG */
306                 r = (int)rs->rates[i] & RATE_MASK;
307                 if ((r > WLC_MAXRATE) || (rate_info[r] == 0)) {
308                         continue;
309                 }
310                 rateset[r] = rs->rates[i];      /* preserve basic bit! */
311         }
312
313         /* fill out the rates in order, looking at only supported rates */
314         count = 0;
315         for (i = 0; i < hw_rs->count; i++) {
316                 r = hw_rs->rates[i] & RATE_MASK;
317                 ASSERT(r <= WLC_MAXRATE);
318                 if (rateset[r])
319                         rs->rates[count++] = rateset[r];
320         }
321
322         rs->count = count;
323
324         /* only set the mcs rate bit if the equivalent hw mcs bit is set */
325         for (i = 0; i < MCSSET_LEN; i++)
326                 rs->mcs[i] = (rs->mcs[i] & hw_rs->mcs[i]);
327
328         if (wlc_rateset_valid(rs, check_brate))
329                 return true;
330         else
331                 return false;
332 }
333
334 /* caluclate the rate of a rx'd frame and return it as a ratespec */
335 ratespec_t BCMFASTPATH wlc_compute_rspec(d11rxhdr_t *rxh, u8 *plcp)
336 {
337         int phy_type;
338         ratespec_t rspec = PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT;
339
340         phy_type =
341             ((rxh->RxChan & RXS_CHAN_PHYTYPE_MASK) >> RXS_CHAN_PHYTYPE_SHIFT);
342
343         if ((phy_type == PHY_TYPE_N) || (phy_type == PHY_TYPE_SSN) ||
344             (phy_type == PHY_TYPE_LCN) || (phy_type == PHY_TYPE_HT)) {
345                 switch (rxh->PhyRxStatus_0 & PRXS0_FT_MASK) {
346                 case PRXS0_CCK:
347                         rspec =
348                             CCK_PHY2MAC_RATE(((cck_phy_hdr_t *) plcp)->signal);
349                         break;
350                 case PRXS0_OFDM:
351                         rspec =
352                             OFDM_PHY2MAC_RATE(((ofdm_phy_hdr_t *) plcp)->
353                                               rlpt[0]);
354                         break;
355                 case PRXS0_PREN:
356                         rspec = (plcp[0] & MIMO_PLCP_MCS_MASK) | RSPEC_MIMORATE;
357                         if (plcp[0] & MIMO_PLCP_40MHZ) {
358                                 /* indicate rspec is for 40 MHz mode */
359                                 rspec &= ~RSPEC_BW_MASK;
360                                 rspec |= (PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT);
361                         }
362                         break;
363                 case PRXS0_STDN:
364                         /* fallthru */
365                 default:
366                         /* not supported */
367                         ASSERT(0);
368                         break;
369                 }
370                 if (PLCP3_ISSGI(plcp[3]))
371                         rspec |= RSPEC_SHORT_GI;
372         } else
373             if ((phy_type == PHY_TYPE_A) || (rxh->PhyRxStatus_0 & PRXS0_OFDM))
374                 rspec = OFDM_PHY2MAC_RATE(((ofdm_phy_hdr_t *) plcp)->rlpt[0]);
375         else
376                 rspec = CCK_PHY2MAC_RATE(((cck_phy_hdr_t *) plcp)->signal);
377
378         return rspec;
379 }
380
381 /* copy rateset src to dst as-is (no masking or sorting) */
382 void wlc_rateset_copy(const wlc_rateset_t *src, wlc_rateset_t *dst)
383 {
384         bcopy(src, dst, sizeof(wlc_rateset_t));
385 }
386
387 /*
388  * Copy and selectively filter one rateset to another.
389  * 'basic_only' means only copy basic rates.
390  * 'rates' indicates cck (11b) and ofdm rates combinations.
391  *    - 0: cck and ofdm
392  *    - 1: cck only
393  *    - 2: ofdm only
394  * 'xmask' is the copy mask (typically 0x7f or 0xff).
395  */
396 void
397 wlc_rateset_filter(wlc_rateset_t *src, wlc_rateset_t *dst, bool basic_only,
398                    u8 rates, uint xmask, bool mcsallow)
399 {
400         uint i;
401         uint r;
402         uint count;
403
404         count = 0;
405         for (i = 0; i < src->count; i++) {
406                 r = src->rates[i];
407                 if (basic_only && !(r & WLC_RATE_FLAG))
408                         continue;
409                 if ((rates == WLC_RATES_CCK) && IS_OFDM((r & RATE_MASK)))
410                         continue;
411                 if ((rates == WLC_RATES_OFDM) && IS_CCK((r & RATE_MASK)))
412                         continue;
413                 dst->rates[count++] = r & xmask;
414         }
415         dst->count = count;
416         dst->htphy_membership = src->htphy_membership;
417
418         if (mcsallow && rates != WLC_RATES_CCK)
419                 bcopy(&src->mcs[0], &dst->mcs[0], MCSSET_LEN);
420         else
421                 wlc_rateset_mcs_clear(dst);
422 }
423
424 /* select rateset for a given phy_type and bandtype and filter it, sort it
425  * and fill rs_tgt with result
426  */
427 void
428 wlc_rateset_default(wlc_rateset_t *rs_tgt, const wlc_rateset_t *rs_hw,
429                     uint phy_type, int bandtype, bool cck_only, uint rate_mask,
430                     bool mcsallow, u8 bw, u8 txstreams)
431 {
432         const wlc_rateset_t *rs_dflt;
433         wlc_rateset_t rs_sel;
434         if ((PHYTYPE_IS(phy_type, PHY_TYPE_HT)) ||
435             (PHYTYPE_IS(phy_type, PHY_TYPE_N)) ||
436             (PHYTYPE_IS(phy_type, PHY_TYPE_LCN)) ||
437             (PHYTYPE_IS(phy_type, PHY_TYPE_SSN))) {
438                 if (BAND_5G(bandtype)) {
439                         rs_dflt = (bw == WLC_20_MHZ ?
440                                    &ofdm_mimo_rates : &ofdm_40bw_mimo_rates);
441                 } else {
442                         rs_dflt = (bw == WLC_20_MHZ ?
443                                    &cck_ofdm_mimo_rates :
444                                    &cck_ofdm_40bw_mimo_rates);
445                 }
446         } else if (PHYTYPE_IS(phy_type, PHY_TYPE_LP)) {
447                 rs_dflt = (BAND_5G(bandtype)) ? &ofdm_rates : &cck_ofdm_rates;
448         } else if (PHYTYPE_IS(phy_type, PHY_TYPE_A)) {
449                 rs_dflt = &ofdm_rates;
450         } else if (PHYTYPE_IS(phy_type, PHY_TYPE_G)) {
451                 rs_dflt = &cck_ofdm_rates;
452         } else {
453                 ASSERT(0);      /* should not happen */
454                 rs_dflt = &cck_rates;   /* force cck */
455         }
456
457         /* if hw rateset is not supplied, assign selected rateset to it */
458         if (!rs_hw)
459                 rs_hw = rs_dflt;
460
461         wlc_rateset_copy(rs_dflt, &rs_sel);
462         wlc_rateset_mcs_upd(&rs_sel, txstreams);
463         wlc_rateset_filter(&rs_sel, rs_tgt, false,
464                            cck_only ? WLC_RATES_CCK : WLC_RATES_CCK_OFDM,
465                            rate_mask, mcsallow);
466         wlc_rate_hwrs_filter_sort_validate(rs_tgt, rs_hw, false,
467                                            mcsallow ? txstreams : 1);
468 }
469
470 s16 BCMFASTPATH wlc_rate_legacy_phyctl(uint rate)
471 {
472         uint i;
473         for (i = 0; i < LEGACY_PHYCFG_TABLE_SIZE; i++)
474                 if (rate == legacy_phycfg_table[i].rate_ofdm)
475                         return legacy_phycfg_table[i].tx_phy_ctl3;
476
477         return -1;
478 }
479
480 void wlc_rateset_mcs_clear(wlc_rateset_t *rateset)
481 {
482         uint i;
483         for (i = 0; i < MCSSET_LEN; i++)
484                 rateset->mcs[i] = 0;
485 }
486
487 void wlc_rateset_mcs_build(wlc_rateset_t *rateset, u8 txstreams)
488 {
489         bcopy(&cck_ofdm_mimo_rates.mcs[0], &rateset->mcs[0], MCSSET_LEN);
490         wlc_rateset_mcs_upd(rateset, txstreams);
491 }
492
493 /* Based on bandwidth passed, allow/disallow MCS 32 in the rateset */
494 void wlc_rateset_bw_mcs_filter(wlc_rateset_t *rateset, u8 bw)
495 {
496         if (bw == WLC_40_MHZ)
497                 setbit(rateset->mcs, 32);
498         else
499                 clrbit(rateset->mcs, 32);
500 }