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