2 * Copyright (c) 2004 Video54 Technologies, Inc.
3 * Copyright (c) 2004-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 static struct ath_rate_table ar5416_11na_ratetable = {
24 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
26 0, 2, 1, 0, 0, 0, 0, 0 },
27 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
29 0, 3, 1, 1, 1, 1, 1, 0 },
30 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
31 10000, 0x0a, 0x00, 24,
32 2, 4, 2, 2, 2, 2, 2, 0 },
33 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
34 13900, 0x0e, 0x00, 36,
35 2, 6, 2, 3, 3, 3, 3, 0 },
36 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
37 17300, 0x09, 0x00, 48,
38 4, 10, 3, 4, 4, 4, 4, 0 },
39 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
40 23000, 0x0d, 0x00, 72,
41 4, 14, 3, 5, 5, 5, 5, 0 },
42 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
43 27400, 0x08, 0x00, 96,
44 4, 20, 3, 6, 6, 6, 6, 0 },
45 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
46 29300, 0x0c, 0x00, 108,
47 4, 23, 3, 7, 7, 7, 7, 0 },
48 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
50 0, 2, 3, 8, 24, 8, 24, 3216 },
51 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
53 2, 4, 3, 9, 25, 9, 25, 6434 },
54 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
56 2, 6, 3, 10, 26, 10, 26, 9650 },
57 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
59 4, 10, 3, 11, 27, 11, 27, 12868 },
60 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
62 4, 14, 3, 12, 28, 12, 28, 19304 },
63 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
65 4, 20, 3, 13, 29, 13, 29, 25740 },
66 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
68 4, 23, 3, 14, 30, 14, 30, 28956 },
69 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
71 4, 25, 3, 15, 31, 15, 32, 32180 },
72 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
74 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
75 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
77 2, 4, 3, 17, 34, 17, 34, 12860 },
78 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
79 36600, 0x8a, 0x00, 10,
80 2, 6, 3, 18, 35, 18, 35, 19300 },
81 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
82 48100, 0x8b, 0x00, 11,
83 4, 10, 3, 19, 36, 19, 36, 25736 },
84 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
85 69500, 0x8c, 0x00, 12,
86 4, 14, 3, 20, 37, 20, 37, 38600 },
87 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
88 89500, 0x8d, 0x00, 13,
89 4, 20, 3, 21, 38, 21, 38, 51472 },
90 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
91 98900, 0x8e, 0x00, 14,
92 4, 23, 3, 22, 39, 22, 39, 57890 },
93 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
94 108300, 0x8f, 0x00, 15,
95 4, 25, 3, 23, 40, 23, 41, 64320 },
96 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
98 0, 2, 3, 8, 24, 24, 24, 6684 },
99 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
100 25900, 0x81, 0x00, 1,
101 2, 4, 3, 9, 25, 25, 25, 13368 },
102 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
103 38600, 0x82, 0x00, 2,
104 2, 6, 3, 10, 26, 26, 26, 20052 },
105 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
106 49800, 0x83, 0x00, 3,
107 4, 10, 3, 11, 27, 27, 27, 26738 },
108 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
109 72200, 0x84, 0x00, 4,
110 4, 14, 3, 12, 28, 28, 28, 40104 },
111 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
112 92900, 0x85, 0x00, 5,
113 4, 20, 3, 13, 29, 29, 29, 53476 },
114 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
115 102700, 0x86, 0x00, 6,
116 4, 23, 3, 14, 30, 30, 30, 60156 },
117 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
118 112000, 0x87, 0x00, 7,
119 4, 25, 3, 15, 31, 32, 32, 66840 },
120 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
121 122000, 0x87, 0x00, 7,
122 4, 25, 3, 15, 31, 32, 32, 74200 },
123 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
124 25800, 0x88, 0x00, 8,
125 0, 2, 3, 16, 33, 33, 33, 13360 },
126 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
127 49800, 0x89, 0x00, 9,
128 2, 4, 3, 17, 34, 34, 34, 26720 },
129 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
130 71900, 0x8a, 0x00, 10,
131 2, 6, 3, 18, 35, 35, 35, 40080 },
132 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
133 92500, 0x8b, 0x00, 11,
134 4, 10, 3, 19, 36, 36, 36, 53440 },
135 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
136 130300, 0x8c, 0x00, 12,
137 4, 14, 3, 20, 37, 37, 37, 80160 },
138 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
139 162800, 0x8d, 0x00, 13,
140 4, 20, 3, 21, 38, 38, 38, 106880 },
141 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
142 178200, 0x8e, 0x00, 14,
143 4, 23, 3, 22, 39, 39, 39, 120240 },
144 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
145 192100, 0x8f, 0x00, 15,
146 4, 25, 3, 23, 40, 41, 41, 133600 },
147 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
148 207000, 0x8f, 0x00, 15,
149 4, 25, 3, 23, 40, 41, 41, 148400 },
151 50, /* probe interval */
152 50, /* rssi reduce interval */
153 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
156 /* VALID_ALL - valid for 20/40/Legacy,
157 * VALID - Legacy only,
158 * VALID_20 - HT 20 only,
159 * VALID_40 - HT 40 only */
161 /* 4ms frame limit not used for NG mode. The values filled
162 * for HT are the 64K max aggregate limit */
164 static struct ath_rate_table ar5416_11ng_ratetable = {
168 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
170 0, 0, 1, 0, 0, 0, 0, 0 },
171 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
173 1, 1, 1, 1, 1, 1, 1, 0 },
174 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
175 4900, 0x19, 0x04, 11,
176 2, 2, 2, 2, 2, 2, 2, 0 },
177 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
178 8100, 0x18, 0x04, 22,
179 3, 3, 2, 3, 3, 3, 3, 0 },
180 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
181 5400, 0x0b, 0x00, 12,
182 4, 2, 1, 4, 4, 4, 4, 0 },
183 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
184 7800, 0x0f, 0x00, 18,
185 4, 3, 1, 5, 5, 5, 5, 0 },
186 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
187 10100, 0x0a, 0x00, 24,
188 6, 4, 1, 6, 6, 6, 6, 0 },
189 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
190 14100, 0x0e, 0x00, 36,
191 6, 6, 2, 7, 7, 7, 7, 0 },
192 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
193 17700, 0x09, 0x00, 48,
194 8, 10, 3, 8, 8, 8, 8, 0 },
195 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
196 23700, 0x0d, 0x00, 72,
197 8, 14, 3, 9, 9, 9, 9, 0 },
198 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
199 27400, 0x08, 0x00, 96,
200 8, 20, 3, 10, 10, 10, 10, 0 },
201 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
202 30900, 0x0c, 0x00, 108,
203 8, 23, 3, 11, 11, 11, 11, 0 },
204 { INVALID, INVALID, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
206 4, 2, 3, 12, 28, 12, 28, 3216 },
207 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
208 12700, 0x81, 0x00, 1,
209 6, 4, 3, 13, 29, 13, 29, 6434 },
210 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
211 18800, 0x82, 0x00, 2,
212 6, 6, 3, 14, 30, 14, 30, 9650 },
213 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
214 25000, 0x83, 0x00, 3,
215 8, 10, 3, 15, 31, 15, 31, 12868 },
216 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
217 36700, 0x84, 0x00, 4,
218 8, 14, 3, 16, 32, 16, 32, 19304 },
219 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
220 48100, 0x85, 0x00, 5,
221 8, 20, 3, 17, 33, 17, 33, 25740 },
222 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
223 53500, 0x86, 0x00, 6,
224 8, 23, 3, 18, 34, 18, 34, 28956 },
225 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
226 59000, 0x87, 0x00, 7,
227 8, 25, 3, 19, 35, 19, 36, 32180 },
228 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
229 12700, 0x88, 0x00, 8,
230 4, 2, 3, 20, 37, 20, 37, 6430 },
231 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
232 24800, 0x89, 0x00, 9,
233 6, 4, 3, 21, 38, 21, 38, 12860 },
234 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
235 36600, 0x8a, 0x00, 10,
236 6, 6, 3, 22, 39, 22, 39, 19300 },
237 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
238 48100, 0x8b, 0x00, 11,
239 8, 10, 3, 23, 40, 23, 40, 25736 },
240 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
241 69500, 0x8c, 0x00, 12,
242 8, 14, 3, 24, 41, 24, 41, 38600 },
243 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
244 89500, 0x8d, 0x00, 13,
245 8, 20, 3, 25, 42, 25, 42, 51472 },
246 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
247 98900, 0x8e, 0x00, 14,
248 8, 23, 3, 26, 43, 26, 44, 57890 },
249 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
250 108300, 0x8f, 0x00, 15,
251 8, 25, 3, 27, 44, 27, 45, 64320 },
252 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
253 13200, 0x80, 0x00, 0,
254 8, 2, 3, 12, 28, 28, 28, 6684 },
255 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
256 25900, 0x81, 0x00, 1,
257 8, 4, 3, 13, 29, 29, 29, 13368 },
258 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
259 38600, 0x82, 0x00, 2,
260 8, 6, 3, 14, 30, 30, 30, 20052 },
261 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
262 49800, 0x83, 0x00, 3,
263 8, 10, 3, 15, 31, 31, 31, 26738 },
264 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
265 72200, 0x84, 0x00, 4,
266 8, 14, 3, 16, 32, 32, 32, 40104 },
267 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
268 92900, 0x85, 0x00, 5,
269 8, 20, 3, 17, 33, 33, 33, 53476 },
270 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
271 102700, 0x86, 0x00, 6,
272 8, 23, 3, 18, 34, 34, 34, 60156 },
273 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
274 112000, 0x87, 0x00, 7,
275 8, 23, 3, 19, 35, 36, 36, 66840 },
276 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
277 122000, 0x87, 0x00, 7,
278 8, 25, 3, 19, 35, 36, 36, 74200 },
279 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
280 25800, 0x88, 0x00, 8,
281 8, 2, 3, 20, 37, 37, 37, 13360 },
282 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
283 49800, 0x89, 0x00, 9,
284 8, 4, 3, 21, 38, 38, 38, 26720 },
285 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
286 71900, 0x8a, 0x00, 10,
287 8, 6, 3, 22, 39, 39, 39, 40080 },
288 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
289 92500, 0x8b, 0x00, 11,
290 8, 10, 3, 23, 40, 40, 40, 53440 },
291 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
292 130300, 0x8c, 0x00, 12,
293 8, 14, 3, 24, 41, 41, 41, 80160 },
294 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
295 162800, 0x8d, 0x00, 13,
296 8, 20, 3, 25, 42, 42, 42, 106880 },
297 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
298 178200, 0x8e, 0x00, 14,
299 8, 23, 3, 26, 43, 43, 43, 120240 },
300 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
301 192100, 0x8f, 0x00, 15,
302 8, 23, 3, 27, 44, 45, 45, 133600 },
303 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
304 207000, 0x8f, 0x00, 15,
305 8, 25, 3, 27, 44, 45, 45, 148400 },
307 50, /* probe interval */
308 50, /* rssi reduce interval */
309 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
312 static struct ath_rate_table ar5416_11a_ratetable = {
316 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
317 5400, 0x0b, 0x00, (0x80|12),
319 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
320 7800, 0x0f, 0x00, 18,
322 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
323 10000, 0x0a, 0x00, (0x80|24),
325 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
326 13900, 0x0e, 0x00, 36,
328 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
329 17300, 0x09, 0x00, (0x80|48),
331 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
332 23000, 0x0d, 0x00, 72,
334 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
335 27400, 0x08, 0x00, 96,
337 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
338 29300, 0x0c, 0x00, 108,
341 50, /* probe interval */
342 50, /* rssi reduce interval */
343 0, /* Phy rates allowed initially */
346 static struct ath_rate_table ar5416_11g_ratetable = {
350 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
353 { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
356 { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
357 4900, 0x19, 0x04, 11,
359 { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
360 8100, 0x18, 0x04, 22,
362 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
363 5400, 0x0b, 0x00, 12,
365 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
366 7800, 0x0f, 0x00, 18,
368 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
369 10000, 0x0a, 0x00, 24,
371 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
372 13900, 0x0e, 0x00, 36,
374 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
375 17300, 0x09, 0x00, 48,
377 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
378 23000, 0x0d, 0x00, 72,
380 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
381 27400, 0x08, 0x00, 96,
383 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
384 29300, 0x0c, 0x00, 108,
387 50, /* probe interval */
388 50, /* rssi reduce interval */
389 0, /* Phy rates allowed initially */
392 static struct ath_rate_table ar5416_11b_ratetable = {
396 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
397 900, 0x1b, 0x00, (0x80|2),
399 { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
400 1800, 0x1a, 0x04, (0x80|4),
402 { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
403 4300, 0x19, 0x04, (0x80|11),
405 { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
406 7100, 0x18, 0x04, (0x80|22),
409 100, /* probe interval */
410 100, /* rssi reduce interval */
411 0, /* Phy rates allowed initially */
414 static inline int8_t median(int8_t a, int8_t b, int8_t c)
433 static void ath_rc_sort_validrates(struct ath_rate_table *rate_table,
434 struct ath_rate_priv *ath_rc_priv)
436 u8 i, j, idx, idx_next;
438 for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
439 for (j = 0; j <= i-1; j++) {
440 idx = ath_rc_priv->valid_rate_index[j];
441 idx_next = ath_rc_priv->valid_rate_index[j+1];
443 if (rate_table->info[idx].ratekbps >
444 rate_table->info[idx_next].ratekbps) {
445 ath_rc_priv->valid_rate_index[j] = idx_next;
446 ath_rc_priv->valid_rate_index[j+1] = idx;
452 static void ath_rc_init_valid_txmask(struct ath_rate_priv *ath_rc_priv)
456 for (i = 0; i < ath_rc_priv->rate_table_size; i++)
457 ath_rc_priv->valid_rate_index[i] = 0;
460 static inline void ath_rc_set_valid_txmask(struct ath_rate_priv *ath_rc_priv,
461 u8 index, int valid_tx_rate)
463 ASSERT(index <= ath_rc_priv->rate_table_size);
464 ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? 1 : 0;
467 static inline int ath_rc_isvalid_txmask(struct ath_rate_priv *ath_rc_priv,
470 ASSERT(index <= ath_rc_priv->rate_table_size);
471 return ath_rc_priv->valid_rate_index[index];
475 ath_rc_get_nextvalid_txrate(struct ath_rate_table *rate_table,
476 struct ath_rate_priv *ath_rc_priv,
482 for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
483 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
484 *next_idx = ath_rc_priv->valid_rate_index[i+1];
489 /* No more valid rates */
494 /* Return true only for single stream */
496 static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
498 if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG))
500 if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
502 if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
504 if (!ignore_cw && WLAN_RC_PHY_HT(phy))
505 if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
507 if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
513 ath_rc_get_nextlowervalid_txrate(struct ath_rate_table *rate_table,
514 struct ath_rate_priv *ath_rc_priv,
515 u8 cur_valid_txrate, u8 *next_idx)
519 for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
520 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
521 *next_idx = ath_rc_priv->valid_rate_index[i-1];
529 ath_rc_sib_init_validrates(struct ath_rate_priv *ath_rc_priv,
530 struct ath_rate_table *rate_table,
536 for (i = 0; i < rate_table->rate_cnt; i++) {
537 valid = (ath_rc_priv->single_stream ?
538 rate_table->info[i].valid_single_stream :
539 rate_table->info[i].valid);
541 u32 phy = rate_table->info[i].phy;
542 u8 valid_rate_count = 0;
544 if (!ath_rc_valid_phyrate(phy, capflag, 0))
547 valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
549 ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
550 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
551 ath_rc_set_valid_txmask(ath_rc_priv, i, 1);
559 ath_rc_sib_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
560 struct ath_rate_table *rate_table,
561 struct ath_rateset *rateset,
566 /* Use intersection of working rates and valid rates */
567 for (i = 0; i < rateset->rs_nrates; i++) {
568 for (j = 0; j < rate_table->rate_cnt; j++) {
569 u32 phy = rate_table->info[j].phy;
570 u32 valid = (ath_rc_priv->single_stream ?
571 rate_table->info[j].valid_single_stream :
572 rate_table->info[j].valid);
574 /* We allow a rate only if its valid and the
575 * capflag matches one of the validity
576 * (VALID/VALID_20/VALID_40) flags */
578 if (((rateset->rs_rates[i] & 0x7F) ==
579 (rate_table->info[j].dot11rate & 0x7F)) &&
580 ((valid & WLAN_RC_CAP_MODE(capflag)) ==
581 WLAN_RC_CAP_MODE(capflag)) &&
582 !WLAN_RC_PHY_HT(phy)) {
584 u8 valid_rate_count = 0;
586 if (!ath_rc_valid_phyrate(phy, capflag, 0))
590 ath_rc_priv->valid_phy_ratecnt[phy];
592 ath_rc_priv->valid_phy_rateidx[phy]
593 [valid_rate_count] = j;
594 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
595 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
604 ath_rc_sib_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
605 struct ath_rate_table *rate_table,
606 u8 *mcs_set, u32 capflag)
610 /* Use intersection of working rates and valid rates */
611 for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) {
612 for (j = 0; j < rate_table->rate_cnt; j++) {
613 u32 phy = rate_table->info[j].phy;
614 u32 valid = (ath_rc_priv->single_stream ?
615 rate_table->info[j].valid_single_stream :
616 rate_table->info[j].valid);
618 if (((((struct ath_rateset *)
619 mcs_set)->rs_rates[i] & 0x7F) !=
620 (rate_table->info[j].dot11rate & 0x7F)) ||
621 !WLAN_RC_PHY_HT(phy) ||
622 !WLAN_RC_PHY_HT_VALID(valid, capflag))
625 if (!ath_rc_valid_phyrate(phy, capflag, 0))
628 ath_rc_priv->valid_phy_rateidx[phy]
629 [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
630 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
631 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
638 u8 ath_rate_findrateix(struct ath_softc *sc,
641 struct ath_rate_table *ratetable;
644 ratetable = sc->hw_rate_table[sc->sc_curmode];
646 if (WARN_ON(!ratetable))
649 for (i = 0; i < ratetable->rate_cnt; i++) {
650 if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f))
657 static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
658 struct ath_rate_priv *ath_rc_priv,
659 struct ath_rate_table *rate_table,
660 int probe_allowed, int *is_probing,
663 u32 dt, best_thruput, this_thruput, now_msec;
664 u8 rate, next_rate, best_rate, maxindex, minindex;
665 int8_t rssi_last, rssi_reduce = 0, index = 0;
669 rssi_last = median(ath_rc_priv->rssi_last,
670 ath_rc_priv->rssi_last_prev,
671 ath_rc_priv->rssi_last_prev2);
674 * Age (reduce) last ack rssi based on how old it is.
675 * The bizarre numbers are so the delta is 160msec,
676 * meaning we divide by 16.
677 * 0msec <= dt <= 25msec: don't derate
678 * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
679 * 185msec <= dt: derate by 10dB
682 now_msec = jiffies_to_msecs(jiffies);
683 dt = now_msec - ath_rc_priv->rssi_time;
688 rssi_reduce = (u8)((dt - 25) >> 4);
690 /* Now reduce rssi_last by rssi_reduce */
691 if (rssi_last < rssi_reduce)
694 rssi_last -= rssi_reduce;
697 * Now look up the rate in the rssi table and return it.
698 * If no rates match then we return 0 (lowest rate)
702 maxindex = ath_rc_priv->max_valid_rate-1;
705 best_rate = minindex;
708 * Try the higher rate first. It will reduce memory moving time
709 * if we have very good channel characteristics.
711 for (index = maxindex; index >= minindex ; index--) {
714 rate = ath_rc_priv->valid_rate_index[index];
715 if (rate > ath_rc_priv->rate_max_phy)
719 * For TCP the average collision rate is around 11%,
720 * so we ignore PERs less than this. This is to
721 * prevent the rate we are currently using (whose
722 * PER might be in the 10-15 range because of TCP
723 * collisions) looking worse than the next lower
724 * rate whose PER has decayed close to 0. If we
725 * used to next lower rate, its PER would grow to
726 * 10-15 and we would be worse off then staying
727 * at the current rate.
729 per_thres = ath_rc_priv->state[rate].per;
733 this_thruput = rate_table->info[rate].user_ratekbps *
736 if (best_thruput <= this_thruput) {
737 best_thruput = this_thruput;
744 /* if we are retrying for more than half the number
745 * of max retries, use the min rate for the next retry
748 rate = ath_rc_priv->valid_rate_index[minindex];
750 ath_rc_priv->rssi_last_lookup = rssi_last;
753 * Must check the actual rate (ratekbps) to account for
754 * non-monoticity of 11g's rate table
757 if (rate >= ath_rc_priv->rate_max_phy && probe_allowed) {
758 rate = ath_rc_priv->rate_max_phy;
760 /* Probe the next allowed phy state */
761 /* FIXME:XXXX Check to make sure ratMax is checked properly */
762 if (ath_rc_get_nextvalid_txrate(rate_table,
763 ath_rc_priv, rate, &next_rate) &&
764 (now_msec - ath_rc_priv->probe_time >
765 rate_table->probe_interval) &&
766 (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
768 ath_rc_priv->probe_rate = rate;
769 ath_rc_priv->probe_time = now_msec;
770 ath_rc_priv->hw_maxretry_pktcnt = 0;
775 if (rate > (ath_rc_priv->rate_table_size - 1))
776 rate = ath_rc_priv->rate_table_size - 1;
778 ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) ||
779 (rate_table->info[rate].valid_single_stream &&
780 ath_rc_priv->single_stream));
785 static void ath_rc_rate_set_series(struct ath_rate_table *rate_table ,
786 struct ieee80211_tx_rate *rate,
795 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
796 if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
797 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
798 if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
799 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
800 if (WLAN_RC_PHY_HT(rate_table->info[rix].phy))
801 rate->flags |= IEEE80211_TX_RC_MCS;
804 static u8 ath_rc_rate_getidx(struct ath_softc *sc,
805 struct ath_rate_priv *ath_rc_priv,
806 struct ath_rate_table *rate_table,
807 u8 rix, u16 stepdown,
814 for (j = RATE_TABLE_SIZE; j > 0; j--) {
815 if (ath_rc_get_nextlowervalid_txrate(rate_table,
816 ath_rc_priv, rix, &nextindex))
822 for (j = stepdown; j > 0; j--) {
823 if (ath_rc_get_nextlowervalid_txrate(rate_table,
824 ath_rc_priv, rix, &nextindex))
833 static void ath_rc_ratefind(struct ath_softc *sc,
834 struct ath_rate_priv *ath_rc_priv,
835 int num_tries, int num_rates,
836 struct ieee80211_tx_info *tx_info, int *is_probe,
839 u8 try_per_rate = 0, i = 0, rix, nrix;
840 struct ath_rate_table *rate_table;
841 struct ieee80211_tx_rate *rates = tx_info->control.rates;
843 rate_table = sc->hw_rate_table[sc->sc_curmode];
844 rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table, 1,
849 /* set one try for probe rates. For the
850 * probes don't enable rts */
851 ath_rc_rate_set_series(rate_table,
852 &rates[i++], 1, nrix, 0);
854 try_per_rate = (num_tries/num_rates);
855 /* Get the next tried/allowed rate. No RTS for the next series
856 * after the probe rate
858 nrix = ath_rc_rate_getidx(sc,
859 ath_rc_priv, rate_table, nrix, 1, 0);
860 ath_rc_rate_set_series(rate_table,
861 &rates[i++], try_per_rate, nrix, 0);
863 try_per_rate = (num_tries/num_rates);
864 /* Set the choosen rate. No RTS for first series entry. */
865 ath_rc_rate_set_series(rate_table,
866 &rates[i++], try_per_rate, nrix, 0);
869 /* Fill in the other rates for multirate retry */
870 for ( ; i < num_rates; i++) {
874 try_num = ((i + 1) == num_rates) ?
875 num_tries - (try_per_rate * i) : try_per_rate ;
876 min_rate = (((i + 1) == num_rates) && 0);
878 nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
879 rate_table, nrix, 1, min_rate);
880 /* All other rates in the series have RTS enabled */
881 ath_rc_rate_set_series(rate_table,
882 &rates[i], try_num, nrix, 1);
886 * NB:Change rate series to enable aggregation when operating
887 * at lower MCS rates. When first rate in series is MCS2
888 * in HT40 @ 2.4GHz, series should look like:
890 * {MCS2, MCS1, MCS0, MCS0}.
892 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
895 * {MCS3, MCS2, MCS1, MCS1}
897 * So, set fourth rate in series to be same as third one for
900 if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) ||
901 (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) ||
902 (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) {
903 u8 dot11rate = rate_table->info[rix].dot11rate;
904 u8 phy = rate_table->info[rix].phy;
906 ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
907 (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
908 rates[3].idx = rates[2].idx;
909 rates[3].flags = rates[2].flags;
914 static void ath_rc_update_ht(struct ath_softc *sc,
915 struct ath_rate_priv *ath_rc_priv,
916 struct ath_tx_info_priv *tx_info_priv,
917 int tx_rate, int xretries, int retries)
919 u32 now_msec = jiffies_to_msecs(jiffies);
920 int state_change = 0, rate, count;
922 struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
923 static u32 nretry_to_per_lookup[10] = {
939 ASSERT(tx_rate >= 0);
943 /* To compensate for some imbalance between ctrl and ext. channel */
945 if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
946 tx_info_priv->tx.ts_rssi =
947 tx_info_priv->tx.ts_rssi < 3 ? 0 :
948 tx_info_priv->tx.ts_rssi - 3;
950 last_per = ath_rc_priv->state[tx_rate].per;
953 /* Update the PER. */
955 ath_rc_priv->state[tx_rate].per += 30;
956 if (ath_rc_priv->state[tx_rate].per > 100)
957 ath_rc_priv->state[tx_rate].per = 100;
960 count = ARRAY_SIZE(nretry_to_per_lookup);
961 if (retries >= count)
963 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
964 ath_rc_priv->state[tx_rate].per =
965 (u8)(ath_rc_priv->state[tx_rate].per -
966 (ath_rc_priv->state[tx_rate].per >> 3) +
970 /* xretries == 1 or 2 */
972 if (ath_rc_priv->probe_rate == tx_rate)
973 ath_rc_priv->probe_rate = 0;
975 } else { /* xretries == 0 */
976 /* Update the PER. */
977 /* Make sure it doesn't index out of array's bounds. */
978 count = ARRAY_SIZE(nretry_to_per_lookup);
979 if (retries >= count)
981 if (tx_info_priv->n_bad_frames) {
982 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
983 * Assuming that n_frames is not 0. The current PER
984 * from the retries is 100 * retries / (retries+1),
985 * since the first retries attempts failed, and the
986 * next one worked. For the one that worked,
987 * n_bad_frames subframes out of n_frames wored,
988 * so the PER for that part is
989 * 100 * n_bad_frames / n_frames, and it contributes
990 * 100 * n_bad_frames / (n_frames * (retries+1)) to
991 * the above PER. The expression below is a
992 * simplified version of the sum of these two terms.
994 if (tx_info_priv->n_frames > 0)
995 ath_rc_priv->state[tx_rate].per
997 (ath_rc_priv->state[tx_rate].per -
998 (ath_rc_priv->state[tx_rate].per >> 3) +
999 ((100*(retries*tx_info_priv->n_frames +
1000 tx_info_priv->n_bad_frames) /
1001 (tx_info_priv->n_frames *
1002 (retries+1))) >> 3));
1004 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
1006 ath_rc_priv->state[tx_rate].per = (u8)
1007 (ath_rc_priv->state[tx_rate].per -
1008 (ath_rc_priv->state[tx_rate].per >> 3) +
1009 (nretry_to_per_lookup[retries] >> 3));
1012 ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev;
1013 ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last;
1014 ath_rc_priv->rssi_last = tx_info_priv->tx.ts_rssi;
1015 ath_rc_priv->rssi_time = now_msec;
1018 * If we got at most one retry then increase the max rate if
1019 * this was a probe. Otherwise, ignore the probe.
1022 if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
1023 if (retries > 0 || 2 * tx_info_priv->n_bad_frames >
1024 tx_info_priv->n_frames) {
1026 * Since we probed with just a single attempt,
1027 * any retries means the probe failed. Also,
1028 * if the attempt worked, but more than half
1029 * the subframes were bad then also consider
1030 * the probe a failure.
1032 ath_rc_priv->probe_rate = 0;
1036 ath_rc_priv->rate_max_phy = ath_rc_priv->probe_rate;
1037 probe_rate = ath_rc_priv->probe_rate;
1039 if (ath_rc_priv->state[probe_rate].per > 30)
1040 ath_rc_priv->state[probe_rate].per = 20;
1042 ath_rc_priv->probe_rate = 0;
1045 * Since this probe succeeded, we allow the next
1046 * probe twice as soon. This allows the maxRate
1047 * to move up faster if the probes are
1050 ath_rc_priv->probe_time = now_msec -
1051 rate_table->probe_interval / 2;
1057 * Don't update anything. We don't know if
1058 * this was because of collisions or poor signal.
1060 * Later: if rssi_ack is close to
1061 * ath_rc_priv->state[txRate].rssi_thres and we see lots
1062 * of retries, then we could increase
1063 * ath_rc_priv->state[txRate].rssi_thres.
1065 ath_rc_priv->hw_maxretry_pktcnt = 0;
1068 * It worked with no retries. First ignore bogus (small)
1071 if (tx_rate == ath_rc_priv->rate_max_phy &&
1072 ath_rc_priv->hw_maxretry_pktcnt < 255) {
1073 ath_rc_priv->hw_maxretry_pktcnt++;
1076 if (tx_info_priv->tx.ts_rssi >=
1077 rate_table->info[tx_rate].rssi_ack_validmin) {
1078 /* Average the rssi */
1079 if (tx_rate != ath_rc_priv->rssi_sum_rate) {
1080 ath_rc_priv->rssi_sum_rate = tx_rate;
1081 ath_rc_priv->rssi_sum =
1082 ath_rc_priv->rssi_sum_cnt = 0;
1085 ath_rc_priv->rssi_sum += tx_info_priv->tx.ts_rssi;
1086 ath_rc_priv->rssi_sum_cnt++;
1088 if (ath_rc_priv->rssi_sum_cnt > 4) {
1089 int32_t rssi_ackAvg =
1090 (ath_rc_priv->rssi_sum + 2) / 4;
1092 ath_rc_priv->state[tx_rate].
1094 int8_t rssi_ack_vmin =
1095 rate_table->info[tx_rate].
1098 ath_rc_priv->rssi_sum =
1099 ath_rc_priv->rssi_sum_cnt = 0;
1101 /* Now reduce the current
1102 * rssi threshold. */
1103 if ((rssi_ackAvg < rssi_thres + 2) &&
1104 (rssi_thres > rssi_ack_vmin)) {
1105 ath_rc_priv->state[tx_rate].
1118 * If this rate looks bad (high PER) then stop using it for
1119 * a while (except if we are probing).
1121 if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 &&
1122 rate_table->info[tx_rate].ratekbps <=
1123 rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
1124 ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv,
1125 (u8) tx_rate, &ath_rc_priv->rate_max_phy);
1127 /* Don't probe for a little while. */
1128 ath_rc_priv->probe_time = now_msec;
1133 * Make sure the rates above this have higher rssi thresholds.
1134 * (Note: Monotonicity is kept within the OFDM rates and
1135 * within the CCK rates. However, no adjustment is
1136 * made to keep the rssi thresholds monotonically
1137 * increasing between the CCK and OFDM rates.)
1139 for (rate = tx_rate; rate <
1140 ath_rc_priv->rate_table_size - 1; rate++) {
1141 if (rate_table->info[rate+1].phy !=
1142 rate_table->info[tx_rate].phy)
1145 if (ath_rc_priv->state[rate].rssi_thres +
1146 rate_table->info[rate].rssi_ack_deltamin >
1147 ath_rc_priv->state[rate+1].rssi_thres) {
1148 ath_rc_priv->state[rate+1].rssi_thres =
1149 ath_rc_priv->state[rate].
1151 rate_table->info[rate].
1156 /* Make sure the rates below this have lower rssi thresholds. */
1157 for (rate = tx_rate - 1; rate >= 0; rate--) {
1158 if (rate_table->info[rate].phy !=
1159 rate_table->info[tx_rate].phy)
1162 if (ath_rc_priv->state[rate].rssi_thres +
1163 rate_table->info[rate].rssi_ack_deltamin >
1164 ath_rc_priv->state[rate+1].rssi_thres) {
1165 if (ath_rc_priv->state[rate+1].rssi_thres <
1166 rate_table->info[rate].
1168 ath_rc_priv->state[rate].rssi_thres = 0;
1170 ath_rc_priv->state[rate].rssi_thres =
1171 ath_rc_priv->state[rate+1].
1173 rate_table->info[rate].
1177 if (ath_rc_priv->state[rate].rssi_thres <
1178 rate_table->info[rate].
1179 rssi_ack_validmin) {
1180 ath_rc_priv->state[rate].rssi_thres =
1181 rate_table->info[rate].
1188 /* Make sure the rates below this have lower PER */
1189 /* Monotonicity is kept only for rates below the current rate. */
1190 if (ath_rc_priv->state[tx_rate].per < last_per) {
1191 for (rate = tx_rate - 1; rate >= 0; rate--) {
1192 if (rate_table->info[rate].phy !=
1193 rate_table->info[tx_rate].phy)
1196 if (ath_rc_priv->state[rate].per >
1197 ath_rc_priv->state[rate+1].per) {
1198 ath_rc_priv->state[rate].per =
1199 ath_rc_priv->state[rate+1].per;
1204 /* Maintain monotonicity for rates above the current rate */
1205 for (rate = tx_rate; rate < ath_rc_priv->rate_table_size - 1; rate++) {
1206 if (ath_rc_priv->state[rate+1].per < ath_rc_priv->state[rate].per)
1207 ath_rc_priv->state[rate+1].per =
1208 ath_rc_priv->state[rate].per;
1211 /* Every so often, we reduce the thresholds and
1212 * PER (different for CCK and OFDM). */
1213 if (now_msec - ath_rc_priv->rssi_down_time >=
1214 rate_table->rssi_reduce_interval) {
1216 for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
1217 if (ath_rc_priv->state[rate].rssi_thres >
1218 rate_table->info[rate].rssi_ack_validmin)
1219 ath_rc_priv->state[rate].rssi_thres -= 1;
1221 ath_rc_priv->rssi_down_time = now_msec;
1224 /* Every so often, we reduce the thresholds
1225 * and PER (different for CCK and OFDM). */
1226 if (now_msec - ath_rc_priv->per_down_time >=
1227 rate_table->rssi_reduce_interval) {
1228 for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
1229 ath_rc_priv->state[rate].per =
1230 7 * ath_rc_priv->state[rate].per / 8;
1233 ath_rc_priv->per_down_time = now_msec;
1237 static void ath_rc_tx_status(struct ath_softc *sc,
1238 struct ath_rate_priv *ath_rc_priv,
1239 struct ieee80211_tx_info *tx_info,
1240 int final_ts_idx, int xretries, int long_retry)
1242 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
1243 struct ath_rate_table *rate_table;
1244 struct ieee80211_tx_rate *rates = tx_info->status.rates;
1246 u32 series = 0, rix;
1248 rate_table = sc->hw_rate_table[sc->sc_curmode];
1251 * If the first rate is not the final index, there
1252 * are intermediate rate failures to be processed.
1254 if (final_ts_idx != 0) {
1255 /* Process intermediate rates that failed.*/
1256 for (series = 0; series < final_ts_idx ; series++) {
1257 if (rates[series].count != 0 && (rates[series].idx >= 0)) {
1258 flags = rates[series].flags;
1259 /* If HT40 and we have switched mode from
1260 * 40 to 20 => don't update */
1261 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1262 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG))
1265 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1266 (flags & IEEE80211_TX_RC_SHORT_GI))
1267 rix = rate_table->info[
1268 rates[series].idx].ht_index;
1269 else if (flags & IEEE80211_TX_RC_SHORT_GI)
1270 rix = rate_table->info[
1271 rates[series].idx].sgi_index;
1272 else if (flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1273 rix = rate_table->info[
1274 rates[series].idx].cw40index;
1276 rix = rate_table->info[
1277 rates[series].idx].base_index;
1278 ath_rc_update_ht(sc, ath_rc_priv,
1281 rates[series].count);
1286 * Handle the special case of MIMO PS burst, where the second
1287 * aggregate is sent out with only one rate and one try.
1288 * Treating it as an excessive retry penalizes the rate
1291 if (rates[0].count == 1 && xretries == 1)
1295 flags = rates[series].flags;
1296 /* If HT40 and we have switched mode from 40 to 20 => don't update */
1297 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1298 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG)) {
1302 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) && (flags & IEEE80211_TX_RC_SHORT_GI))
1303 rix = rate_table->info[rates[series].idx].ht_index;
1304 else if (flags & IEEE80211_TX_RC_SHORT_GI)
1305 rix = rate_table->info[rates[series].idx].sgi_index;
1306 else if (flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1307 rix = rate_table->info[rates[series].idx].cw40index;
1309 rix = rate_table->info[rates[series].idx].base_index;
1311 ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
1312 xretries, long_retry);
1315 static void ath_rc_init(struct ath_softc *sc,
1316 struct ath_rate_priv *ath_rc_priv,
1317 struct ieee80211_supported_band *sband,
1318 struct ieee80211_sta *sta)
1320 struct ath_rate_table *rate_table = NULL;
1321 struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
1322 u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
1323 u8 i, j, k, hi = 0, hthi = 0;
1325 rate_table = sc->hw_rate_table[sc->sc_curmode];
1327 if (sta->ht_cap.ht_supported) {
1328 if (sband->band == IEEE80211_BAND_2GHZ)
1329 rate_table = sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
1331 rate_table = sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
1333 ath_rc_priv->ht_cap = (WLAN_RC_HT_FLAG | WLAN_RC_DS_FLAG);
1335 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1336 ath_rc_priv->ht_cap |= WLAN_RC_40_FLAG;
1339 /* Initial rate table size. Will change depending
1340 * on the working rate set */
1341 ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
1343 /* Initialize thresholds according to the global rate table */
1344 for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
1345 ath_rc_priv->state[i].rssi_thres =
1346 rate_table->info[i].rssi_ack_validmin;
1347 ath_rc_priv->state[i].per = 0;
1350 /* Determine the valid rates */
1351 ath_rc_init_valid_txmask(ath_rc_priv);
1353 for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
1354 for (j = 0; j < MAX_TX_RATE_PHY; j++)
1355 ath_rc_priv->valid_phy_rateidx[i][j] = 0;
1356 ath_rc_priv->valid_phy_ratecnt[i] = 0;
1358 ath_rc_priv->rc_phy_mode = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG);
1360 /* Set stream capability */
1361 ath_rc_priv->single_stream = (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ? 0 : 1;
1363 if (!rateset->rs_nrates) {
1364 /* No working rate, just initialize valid rates */
1365 hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table,
1366 ath_rc_priv->ht_cap);
1368 /* Use intersection of working rates and valid rates */
1369 hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table,
1370 rateset, ath_rc_priv->ht_cap);
1371 if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
1372 hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv,
1375 ath_rc_priv->ht_cap);
1377 hi = A_MAX(hi, hthi);
1380 ath_rc_priv->rate_table_size = hi + 1;
1381 ath_rc_priv->rate_max_phy = 0;
1382 ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
1384 for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
1385 for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
1386 ath_rc_priv->valid_rate_index[k++] =
1387 ath_rc_priv->valid_phy_rateidx[i][j];
1390 if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
1391 || !ath_rc_priv->valid_phy_ratecnt[i])
1394 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
1396 ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
1397 ASSERT(k <= RATE_TABLE_SIZE);
1399 ath_rc_priv->max_valid_rate = k;
1400 ath_rc_sort_validrates(rate_table, ath_rc_priv);
1401 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
1404 /* Rate Control callbacks */
1405 static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1406 struct ieee80211_sta *sta, void *priv_sta,
1407 struct sk_buff *skb)
1409 struct ath_softc *sc = priv;
1410 struct ath_rate_priv *ath_rc_priv = priv_sta;
1411 struct ath_tx_info_priv *tx_info_priv = NULL;
1412 struct ath_node *an;
1413 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1414 struct ieee80211_hdr *hdr;
1415 int final_ts_idx, tx_status = 0, is_underrun = 0;
1418 hdr = (struct ieee80211_hdr *)skb->data;
1419 fc = hdr->frame_control;
1420 tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
1421 an = (struct ath_node *)sta->drv_priv;
1422 final_ts_idx = tx_info_priv->tx.ts_rateindex;
1424 if (!an || !priv_sta || !ieee80211_is_data(fc))
1427 if (tx_info_priv->tx.ts_status & ATH9K_TXERR_FILT)
1430 if (tx_info_priv->tx.ts_rssi > 0) {
1431 ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi,
1432 tx_info_priv->tx.ts_rssi);
1436 * If underrun error is seen assume it as an excessive retry only
1437 * if prefetch trigger level have reached the max (0x3f for 5416)
1438 * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
1439 * times. This affects how ratectrl updates PER for the failed rate.
1441 if (tx_info_priv->tx.ts_flags &
1442 (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
1443 ((sc->sc_ah->ah_txTrigLevel) >= ath_rc_priv->tx_triglevel_max)) {
1448 if ((tx_info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
1449 (tx_info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
1452 ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
1453 (is_underrun) ? ATH_11N_TXMAXTRY :
1454 tx_info_priv->tx.ts_longretry);
1457 kfree(tx_info_priv);
1460 static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1461 struct ieee80211_tx_rate_control *txrc)
1463 struct ieee80211_supported_band *sband = txrc->sband;
1464 struct sk_buff *skb = txrc->skb;
1465 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1466 struct ath_softc *sc = priv;
1467 struct ieee80211_hw *hw = sc->hw;
1468 struct ath_rate_priv *ath_rc_priv = priv_sta;
1469 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1471 __le16 fc = hdr->frame_control;
1473 /* lowest rate for management and multicast/broadcast frames */
1474 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1475 tx_info->control.rates[0].idx = rate_lowest_index(sband, sta);
1476 tx_info->control.rates[0].count =
1477 is_multicast_ether_addr(hdr->addr1) ? 1 : ATH_MGT_TXMAXTRY;
1481 /* Find tx rate for unicast frames */
1482 ath_rc_ratefind(sc, ath_rc_priv, ATH_11N_TXMAXTRY, 4,
1483 tx_info, &is_probe, false);
1485 /* Check if aggregation has to be enabled for this tid */
1486 if (hw->conf.ht.enabled) {
1487 if (ieee80211_is_data_qos(fc)) {
1489 struct ath_node *an;
1491 qc = ieee80211_get_qos_ctl(hdr);
1493 an = (struct ath_node *)sta->drv_priv;
1495 if(ath_tx_aggr_check(sc, an, tid))
1496 ieee80211_start_tx_ba_session(hw, hdr->addr1, tid);
1501 static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
1502 struct ieee80211_sta *sta, void *priv_sta)
1504 struct ath_softc *sc = priv;
1505 struct ath_rate_priv *ath_rc_priv = priv_sta;
1508 for (i = 0; i < sband->n_bitrates; i++) {
1509 if (sta->supp_rates[sband->band] & BIT(i)) {
1510 ath_rc_priv->neg_rates.rs_rates[j]
1511 = (sband->bitrates[i].bitrate * 2) / 10;
1515 ath_rc_priv->neg_rates.rs_nrates = j;
1517 if (sta->ht_cap.ht_supported) {
1518 for (i = 0, j = 0; i < 77; i++) {
1519 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
1520 ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
1521 if (j == ATH_RATE_MAX)
1524 ath_rc_priv->neg_ht_rates.rs_nrates = j;
1527 ath_rc_init(sc, priv_sta, sband, sta);
1530 static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1535 static void ath_rate_free(void *priv)
1540 static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
1542 struct ath_softc *sc = priv;
1543 struct ath_rate_priv *rate_priv;
1545 rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
1547 DPRINTF(sc, ATH_DBG_FATAL,
1548 "%s: Unable to allocate private rc structure\n",
1553 rate_priv->rssi_down_time = jiffies_to_msecs(jiffies);
1554 rate_priv->tx_triglevel_max = sc->sc_ah->ah_caps.tx_triglevel_max;
1559 static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
1562 struct ath_rate_priv *rate_priv = priv_sta;
1566 static struct rate_control_ops ath_rate_ops = {
1568 .name = "ath9k_rate_control",
1569 .tx_status = ath_tx_status,
1570 .get_rate = ath_get_rate,
1571 .rate_init = ath_rate_init,
1572 .alloc = ath_rate_alloc,
1573 .free = ath_rate_free,
1574 .alloc_sta = ath_rate_alloc_sta,
1575 .free_sta = ath_rate_free_sta,
1578 static void ath_setup_rate_table(struct ath_softc *sc,
1579 struct ath_rate_table *rate_table)
1583 for (i = 0; i < 256; i++)
1584 rate_table->rateCodeToIndex[i] = (u8)-1;
1586 for (i = 0; i < rate_table->rate_cnt; i++) {
1587 u8 code = rate_table->info[i].ratecode;
1588 u8 cix = rate_table->info[i].ctrl_rate;
1589 u8 sh = rate_table->info[i].short_preamble;
1591 rate_table->rateCodeToIndex[code] = i;
1592 rate_table->rateCodeToIndex[code | sh] = i;
1594 rate_table->info[i].lpAckDuration =
1595 ath9k_hw_computetxtime(sc->sc_ah, rate_table,
1596 WLAN_CTRL_FRAME_SIZE,
1599 rate_table->info[i].spAckDuration =
1600 ath9k_hw_computetxtime(sc->sc_ah, rate_table,
1601 WLAN_CTRL_FRAME_SIZE,
1607 void ath_rate_attach(struct ath_softc *sc)
1609 sc->hw_rate_table[ATH9K_MODE_11B] =
1610 &ar5416_11b_ratetable;
1611 sc->hw_rate_table[ATH9K_MODE_11A] =
1612 &ar5416_11a_ratetable;
1613 sc->hw_rate_table[ATH9K_MODE_11G] =
1614 &ar5416_11g_ratetable;
1615 sc->hw_rate_table[ATH9K_MODE_11NA_HT20] =
1616 &ar5416_11na_ratetable;
1617 sc->hw_rate_table[ATH9K_MODE_11NG_HT20] =
1618 &ar5416_11ng_ratetable;
1619 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
1620 &ar5416_11na_ratetable;
1621 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
1622 &ar5416_11na_ratetable;
1623 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
1624 &ar5416_11ng_ratetable;
1625 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
1626 &ar5416_11ng_ratetable;
1628 ath_setup_rate_table(sc, &ar5416_11b_ratetable);
1629 ath_setup_rate_table(sc, &ar5416_11a_ratetable);
1630 ath_setup_rate_table(sc, &ar5416_11g_ratetable);
1631 ath_setup_rate_table(sc, &ar5416_11na_ratetable);
1632 ath_setup_rate_table(sc, &ar5416_11ng_ratetable);
1635 int ath_rate_control_register(void)
1637 return ieee80211_rate_control_register(&ath_rate_ops);
1640 void ath_rate_control_unregister(void)
1642 ieee80211_rate_control_unregister(&ath_rate_ops);