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