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