802.11: clean up/fix HT support
[linux-block.git] / drivers / net / wireless / ath9k / rc.c
CommitLineData
f078f209
LR
1/*
2 * Copyright (c) 2004 Video54 Technologies, Inc.
3 * Copyright (c) 2004-2008 Atheros Communications, Inc.
4 *
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.
8 *
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.
16 */
17
18/*
19 * Atheros rate control algorithm
20 */
21
22#include "core.h"
4b7679a5 23/* FIXME: remove this include! */
f078f209
LR
24#include "../net/mac80211/rate.h"
25
26static u32 tx_triglevel_max;
27
28static struct ath_rate_table ar5416_11na_ratetable = {
29 42,
30 {
31 { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
32 5400, 0x0b, 0x00, 12,
33 0, 2, 1, 0, 0, 0, 0, 0 },
34 { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
35 7800, 0x0f, 0x00, 18,
36 0, 3, 1, 1, 1, 1, 1, 0 },
37 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
38 10000, 0x0a, 0x00, 24,
39 2, 4, 2, 2, 2, 2, 2, 0 },
40 { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
41 13900, 0x0e, 0x00, 36,
42 2, 6, 2, 3, 3, 3, 3, 0 },
43 { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
44 17300, 0x09, 0x00, 48,
45 4, 10, 3, 4, 4, 4, 4, 0 },
46 { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
47 23000, 0x0d, 0x00, 72,
48 4, 14, 3, 5, 5, 5, 5, 0 },
49 { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
50 27400, 0x08, 0x00, 96,
51 4, 20, 3, 6, 6, 6, 6, 0 },
52 { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
53 29300, 0x0c, 0x00, 108,
54 4, 23, 3, 7, 7, 7, 7, 0 },
55 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
56 6400, 0x80, 0x00, 0,
57 0, 2, 3, 8, 24, 8, 24, 3216 },
58 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
59 12700, 0x81, 0x00, 1,
60 2, 4, 3, 9, 25, 9, 25, 6434 },
61 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
62 18800, 0x82, 0x00, 2,
63 2, 6, 3, 10, 26, 10, 26, 9650 },
64 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
65 25000, 0x83, 0x00, 3,
66 4, 10, 3, 11, 27, 11, 27, 12868 },
67 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
68 36700, 0x84, 0x00, 4,
69 4, 14, 3, 12, 28, 12, 28, 19304 },
70 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
71 48100, 0x85, 0x00, 5,
72 4, 20, 3, 13, 29, 13, 29, 25740 },
73 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
74 53500, 0x86, 0x00, 6,
75 4, 23, 3, 14, 30, 14, 30, 28956 },
76 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
77 59000, 0x87, 0x00, 7,
78 4, 25, 3, 15, 31, 15, 32, 32180 },
79 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
80 12700, 0x88, 0x00,
81 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
82 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
83 24800, 0x89, 0x00, 9,
84 2, 4, 3, 17, 34, 17, 34, 12860 },
85 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
86 36600, 0x8a, 0x00, 10,
87 2, 6, 3, 18, 35, 18, 35, 19300 },
88 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
89 48100, 0x8b, 0x00, 11,
90 4, 10, 3, 19, 36, 19, 36, 25736 },
91 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
92 69500, 0x8c, 0x00, 12,
93 4, 14, 3, 20, 37, 20, 37, 38600 },
94 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
95 89500, 0x8d, 0x00, 13,
96 4, 20, 3, 21, 38, 21, 38, 51472 },
97 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
98 98900, 0x8e, 0x00, 14,
99 4, 23, 3, 22, 39, 22, 39, 57890 },
100 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
101 108300, 0x8f, 0x00, 15,
102 4, 25, 3, 23, 40, 23, 41, 64320 },
103 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
104 13200, 0x80, 0x00, 0,
105 0, 2, 3, 8, 24, 24, 24, 6684 },
106 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
107 25900, 0x81, 0x00, 1,
108 2, 4, 3, 9, 25, 25, 25, 13368 },
109 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
110 38600, 0x82, 0x00, 2,
111 2, 6, 3, 10, 26, 26, 26, 20052 },
112 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
113 49800, 0x83, 0x00, 3,
114 4, 10, 3, 11, 27, 27, 27, 26738 },
115 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
116 72200, 0x84, 0x00, 4,
117 4, 14, 3, 12, 28, 28, 28, 40104 },
118 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
119 92900, 0x85, 0x00, 5,
120 4, 20, 3, 13, 29, 29, 29, 53476 },
121 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
122 102700, 0x86, 0x00, 6,
123 4, 23, 3, 14, 30, 30, 30, 60156 },
124 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
125 112000, 0x87, 0x00, 7,
126 4, 25, 3, 15, 31, 32, 32, 66840 },
127 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
128 122000, 0x87, 0x00, 7,
129 4, 25, 3, 15, 31, 32, 32, 74200 },
130 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
131 25800, 0x88, 0x00, 8,
132 0, 2, 3, 16, 33, 33, 33, 13360 },
133 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
134 49800, 0x89, 0x00, 9,
135 2, 4, 3, 17, 34, 34, 34, 26720 },
136 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
137 71900, 0x8a, 0x00, 10,
138 2, 6, 3, 18, 35, 35, 35, 40080 },
139 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
140 92500, 0x8b, 0x00, 11,
141 4, 10, 3, 19, 36, 36, 36, 53440 },
142 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
143 130300, 0x8c, 0x00, 12,
144 4, 14, 3, 20, 37, 37, 37, 80160 },
145 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
146 162800, 0x8d, 0x00, 13,
147 4, 20, 3, 21, 38, 38, 38, 106880 },
148 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
149 178200, 0x8e, 0x00, 14,
150 4, 23, 3, 22, 39, 39, 39, 120240 },
151 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
152 192100, 0x8f, 0x00, 15,
153 4, 25, 3, 23, 40, 41, 41, 133600 },
154 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
155 207000, 0x8f, 0x00, 15,
156 4, 25, 3, 23, 40, 41, 41, 148400 },
157 },
158 50, /* probe interval */
159 50, /* rssi reduce interval */
160 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
161};
162
163/* TRUE_ALL - valid for 20/40/Legacy,
164 * TRUE - Legacy only,
165 * TRUE_20 - HT 20 only,
166 * TRUE_40 - HT 40 only */
167
168/* 4ms frame limit not used for NG mode. The values filled
169 * for HT are the 64K max aggregate limit */
170
171static struct ath_rate_table ar5416_11ng_ratetable = {
172 46,
173 {
174 { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 1000, /* 1 Mb */
175 900, 0x1b, 0x00, 2,
176 0, 0, 1, 0, 0, 0, 0, 0 },
177 { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 2000, /* 2 Mb */
178 1900, 0x1a, 0x04, 4,
179 1, 1, 1, 1, 1, 1, 1, 0 },
180 { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
181 4900, 0x19, 0x04, 11,
182 2, 2, 2, 2, 2, 2, 2, 0 },
183 { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 11000, /* 11 Mb */
184 8100, 0x18, 0x04, 22,
185 3, 3, 2, 3, 3, 3, 3, 0 },
186 { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
187 5400, 0x0b, 0x00, 12,
188 4, 2, 1, 4, 4, 4, 4, 0 },
189 { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
190 7800, 0x0f, 0x00, 18,
191 4, 3, 1, 5, 5, 5, 5, 0 },
192 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
193 10100, 0x0a, 0x00, 24,
194 6, 4, 1, 6, 6, 6, 6, 0 },
195 { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
196 14100, 0x0e, 0x00, 36,
197 6, 6, 2, 7, 7, 7, 7, 0 },
198 { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
199 17700, 0x09, 0x00, 48,
200 8, 10, 3, 8, 8, 8, 8, 0 },
201 { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
202 23700, 0x0d, 0x00, 72,
203 8, 14, 3, 9, 9, 9, 9, 0 },
204 { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
205 27400, 0x08, 0x00, 96,
206 8, 20, 3, 10, 10, 10, 10, 0 },
207 { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
208 30900, 0x0c, 0x00, 108,
209 8, 23, 3, 11, 11, 11, 11, 0 },
210 { FALSE, FALSE, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
211 6400, 0x80, 0x00, 0,
212 4, 2, 3, 12, 28, 12, 28, 3216 },
213 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
214 12700, 0x81, 0x00, 1,
215 6, 4, 3, 13, 29, 13, 29, 6434 },
216 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
217 18800, 0x82, 0x00, 2,
218 6, 6, 3, 14, 30, 14, 30, 9650 },
219 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
220 25000, 0x83, 0x00, 3,
221 8, 10, 3, 15, 31, 15, 31, 12868 },
222 { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
223 36700, 0x84, 0x00, 4,
224 8, 14, 3, 16, 32, 16, 32, 19304 },
225 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
226 48100, 0x85, 0x00, 5,
227 8, 20, 3, 17, 33, 17, 33, 25740 },
228 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
229 53500, 0x86, 0x00, 6,
230 8, 23, 3, 18, 34, 18, 34, 28956 },
231 { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
232 59000, 0x87, 0x00, 7,
233 8, 25, 3, 19, 35, 19, 36, 32180 },
234 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
235 12700, 0x88, 0x00, 8,
236 4, 2, 3, 20, 37, 20, 37, 6430 },
237 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
238 24800, 0x89, 0x00, 9,
239 6, 4, 3, 21, 38, 21, 38, 12860 },
240 { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
241 36600, 0x8a, 0x00, 10,
242 6, 6, 3, 22, 39, 22, 39, 19300 },
243 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
244 48100, 0x8b, 0x00, 11,
245 8, 10, 3, 23, 40, 23, 40, 25736 },
246 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
247 69500, 0x8c, 0x00, 12,
248 8, 14, 3, 24, 41, 24, 41, 38600 },
249 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
250 89500, 0x8d, 0x00, 13,
251 8, 20, 3, 25, 42, 25, 42, 51472 },
252 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
253 98900, 0x8e, 0x00, 14,
254 8, 23, 3, 26, 43, 26, 44, 57890 },
255 { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
256 108300, 0x8f, 0x00, 15,
257 8, 25, 3, 27, 44, 27, 45, 64320 },
258 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
259 13200, 0x80, 0x00, 0,
260 8, 2, 3, 12, 28, 28, 28, 6684 },
261 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
262 25900, 0x81, 0x00, 1,
263 8, 4, 3, 13, 29, 29, 29, 13368 },
264 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
265 38600, 0x82, 0x00, 2,
266 8, 6, 3, 14, 30, 30, 30, 20052 },
267 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
268 49800, 0x83, 0x00, 3,
269 8, 10, 3, 15, 31, 31, 31, 26738 },
270 { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
271 72200, 0x84, 0x00, 4,
272 8, 14, 3, 16, 32, 32, 32, 40104 },
273 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
274 92900, 0x85, 0x00, 5,
275 8, 20, 3, 17, 33, 33, 33, 53476 },
276 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
277 102700, 0x86, 0x00, 6,
278 8, 23, 3, 18, 34, 34, 34, 60156 },
279 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
280 112000, 0x87, 0x00, 7,
281 8, 23, 3, 19, 35, 36, 36, 66840 },
282 { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
283 122000, 0x87, 0x00, 7,
284 8, 25, 3, 19, 35, 36, 36, 74200 },
285 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
286 25800, 0x88, 0x00, 8,
287 8, 2, 3, 20, 37, 37, 37, 13360 },
288 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
289 49800, 0x89, 0x00, 9,
290 8, 4, 3, 21, 38, 38, 38, 26720 },
291 { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
292 71900, 0x8a, 0x00, 10,
293 8, 6, 3, 22, 39, 39, 39, 40080 },
294 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
295 92500, 0x8b, 0x00, 11,
296 8, 10, 3, 23, 40, 40, 40, 53440 },
297 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
298 130300, 0x8c, 0x00, 12,
299 8, 14, 3, 24, 41, 41, 41, 80160 },
300 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
301 162800, 0x8d, 0x00, 13,
302 8, 20, 3, 25, 42, 42, 42, 106880 },
303 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
304 178200, 0x8e, 0x00, 14,
305 8, 23, 3, 26, 43, 43, 43, 120240 },
306 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
307 192100, 0x8f, 0x00, 15,
308 8, 23, 3, 27, 44, 45, 45, 133600 },
309 { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
310 207000, 0x8f, 0x00, 15,
311 8, 25, 3, 27, 44, 45, 45, 148400 },
312 },
313 50, /* probe interval */
314 50, /* rssi reduce interval */
315 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
316};
317
318static struct ath_rate_table ar5416_11a_ratetable = {
319 8,
320 {
321 { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
322 5400, 0x0b, 0x00, (0x80|12),
323 0, 2, 1, 0, 0 },
324 { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
325 7800, 0x0f, 0x00, 18,
326 0, 3, 1, 1, 0 },
327 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
328 10000, 0x0a, 0x00, (0x80|24),
329 2, 4, 2, 2, 0 },
330 { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
331 13900, 0x0e, 0x00, 36,
332 2, 6, 2, 3, 0 },
333 { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
334 17300, 0x09, 0x00, (0x80|48),
335 4, 10, 3, 4, 0 },
336 { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
337 23000, 0x0d, 0x00, 72,
338 4, 14, 3, 5, 0 },
339 { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
340 27400, 0x08, 0x00, 96,
341 4, 19, 3, 6, 0 },
342 { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
343 29300, 0x0c, 0x00, 108,
344 4, 23, 3, 7, 0 },
345 },
346 50, /* probe interval */
347 50, /* rssi reduce interval */
348 0, /* Phy rates allowed initially */
349};
350
351static struct ath_rate_table ar5416_11a_ratetable_Half = {
352 8,
353 {
354 { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 6 Mb */
355 2700, 0x0b, 0x00, (0x80|6),
356 0, 2, 1, 0, 0},
357 { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 9 Mb */
358 3900, 0x0f, 0x00, 9,
359 0, 3, 1, 1, 0 },
360 { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 12 Mb */
361 5000, 0x0a, 0x00, (0x80|12),
362 2, 4, 2, 2, 0 },
363 { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 18 Mb */
364 6950, 0x0e, 0x00, 18,
365 2, 6, 2, 3, 0 },
366 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 24 Mb */
367 8650, 0x09, 0x00, (0x80|24),
368 4, 10, 3, 4, 0 },
369 { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 36 Mb */
370 11500, 0x0d, 0x00, 36,
371 4, 14, 3, 5, 0 },
372 { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 48 Mb */
373 13700, 0x08, 0x00, 48,
374 4, 19, 3, 6, 0 },
375 { TRUE, TRUE, WLAN_PHY_OFDM, 27000, /* 54 Mb */
376 14650, 0x0c, 0x00, 54,
377 4, 23, 3, 7, 0 },
378 },
379 50, /* probe interval */
380 50, /* rssi reduce interval */
381 0, /* Phy rates allowed initially */
382};
383
384static struct ath_rate_table ar5416_11a_ratetable_Quarter = {
385 8,
386 {
387 { TRUE, TRUE, WLAN_PHY_OFDM, 1500, /* 6 Mb */
388 1350, 0x0b, 0x00, (0x80|3),
389 0, 2, 1, 0, 0 },
390 { TRUE, TRUE, WLAN_PHY_OFDM, 2250, /* 9 Mb */
391 1950, 0x0f, 0x00, 4,
392 0, 3, 1, 1, 0 },
393 { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 12 Mb */
394 2500, 0x0a, 0x00, (0x80|6),
395 2, 4, 2, 2, 0 },
396 { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 18 Mb */
397 3475, 0x0e, 0x00, 9,
398 2, 6, 2, 3, 0 },
399 { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 25 Mb */
400 4325, 0x09, 0x00, (0x80|12),
401 4, 10, 3, 4, 0 },
402 { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 36 Mb */
403 5750, 0x0d, 0x00, 18,
404 4, 14, 3, 5, 0 },
405 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 48 Mb */
406 6850, 0x08, 0x00, 24,
407 4, 19, 3, 6, 0 },
408 { TRUE, TRUE, WLAN_PHY_OFDM, 13500, /* 54 Mb */
409 7325, 0x0c, 0x00, 27,
410 4, 23, 3, 7, 0 },
411 },
412 50, /* probe interval */
413 50, /* rssi reduce interval */
414 0, /* Phy rates allowed initially */
415};
416
417static struct ath_rate_table ar5416_11g_ratetable = {
418 12,
419 {
420 { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
421 900, 0x1b, 0x00, 2,
422 0, 0, 1, 0, 0 },
423 { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
424 1900, 0x1a, 0x04, 4,
425 1, 1, 1, 1, 0 },
426 { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
427 4900, 0x19, 0x04, 11,
428 2, 2, 2, 2, 0 },
429 { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
430 8100, 0x18, 0x04, 22,
431 3, 3, 2, 3, 0 },
432 { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
433 5400, 0x0b, 0x00, 12,
434 4, 2, 1, 4, 0 },
435 { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
436 7800, 0x0f, 0x00, 18,
437 4, 3, 1, 5, 0 },
438 { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
439 10000, 0x0a, 0x00, 24,
440 6, 4, 1, 6, 0 },
441 { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
442 13900, 0x0e, 0x00, 36,
443 6, 6, 2, 7, 0 },
444 { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
445 17300, 0x09, 0x00, 48,
446 8, 10, 3, 8, 0 },
447 { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
448 23000, 0x0d, 0x00, 72,
449 8, 14, 3, 9, 0 },
450 { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
451 27400, 0x08, 0x00, 96,
452 8, 19, 3, 10, 0 },
453 { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
454 29300, 0x0c, 0x00, 108,
455 8, 23, 3, 11, 0 },
456 },
457 50, /* probe interval */
458 50, /* rssi reduce interval */
459 0, /* Phy rates allowed initially */
460};
461
462static struct ath_rate_table ar5416_11b_ratetable = {
463 4,
464 {
465 { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
466 900, 0x1b, 0x00, (0x80|2),
467 0, 0, 1, 0, 0 },
468 { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
469 1800, 0x1a, 0x04, (0x80|4),
470 1, 1, 1, 1, 0 },
471 { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
472 4300, 0x19, 0x04, (0x80|11),
473 1, 2, 2, 2, 0 },
474 { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
475 7100, 0x18, 0x04, (0x80|22),
476 1, 4, 100, 3, 0 },
477 },
478 100, /* probe interval */
479 100, /* rssi reduce interval */
480 0, /* Phy rates allowed initially */
481};
482
483static void ar5416_attach_ratetables(struct ath_rate_softc *sc)
484{
485 /*
486 * Attach rate tables.
487 */
86b89eed
S
488 sc->hw_rate_table[ATH9K_MODE_11B] = &ar5416_11b_ratetable;
489 sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
490 sc->hw_rate_table[ATH9K_MODE_11G] = &ar5416_11g_ratetable;
f078f209 491
86b89eed
S
492 sc->hw_rate_table[ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable;
493 sc->hw_rate_table[ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable;
494 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
f078f209 495 &ar5416_11na_ratetable;
86b89eed 496 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
f078f209 497 &ar5416_11na_ratetable;
86b89eed 498 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
f078f209 499 &ar5416_11ng_ratetable;
86b89eed 500 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
f078f209
LR
501 &ar5416_11ng_ratetable;
502}
503
504static void ar5416_setquarter_ratetable(struct ath_rate_softc *sc)
505{
86b89eed 506 sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Quarter;
f078f209
LR
507 return;
508}
509
510static void ar5416_sethalf_ratetable(struct ath_rate_softc *sc)
511{
86b89eed 512 sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Half;
f078f209
LR
513 return;
514}
515
516static void ar5416_setfull_ratetable(struct ath_rate_softc *sc)
517{
86b89eed 518 sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
f078f209
LR
519 return;
520}
521
522/*
523 * Return the median of three numbers
524 */
525static inline int8_t median(int8_t a, int8_t b, int8_t c)
526{
527 if (a >= b) {
528 if (b >= c)
529 return b;
530 else if (a > c)
531 return c;
532 else
533 return a;
534 } else {
535 if (a >= c)
536 return a;
537 else if (b >= c)
538 return c;
539 else
540 return b;
541 }
542}
543
544static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
545 struct ath_tx_ratectrl *rate_ctrl)
546{
547 u8 i, j, idx, idx_next;
548
549 for (i = rate_ctrl->max_valid_rate - 1; i > 0; i--) {
550 for (j = 0; j <= i-1; j++) {
551 idx = rate_ctrl->valid_rate_index[j];
552 idx_next = rate_ctrl->valid_rate_index[j+1];
553
554 if (rate_table->info[idx].ratekbps >
555 rate_table->info[idx_next].ratekbps) {
556 rate_ctrl->valid_rate_index[j] = idx_next;
557 rate_ctrl->valid_rate_index[j+1] = idx;
558 }
559 }
560 }
561}
562
563/* Access functions for valid_txrate_mask */
564
565static void ath_rc_init_valid_txmask(struct ath_tx_ratectrl *rate_ctrl)
566{
567 u8 i;
568
569 for (i = 0; i < rate_ctrl->rate_table_size; i++)
570 rate_ctrl->valid_rate_index[i] = FALSE;
571}
572
573static inline void ath_rc_set_valid_txmask(struct ath_tx_ratectrl *rate_ctrl,
574 u8 index, int valid_tx_rate)
575{
576 ASSERT(index <= rate_ctrl->rate_table_size);
577 rate_ctrl->valid_rate_index[index] = valid_tx_rate ? TRUE : FALSE;
578}
579
580static inline int ath_rc_isvalid_txmask(struct ath_tx_ratectrl *rate_ctrl,
581 u8 index)
582{
583 ASSERT(index <= rate_ctrl->rate_table_size);
584 return rate_ctrl->valid_rate_index[index];
585}
586
587/* Iterators for valid_txrate_mask */
588static inline int
589ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
590 struct ath_tx_ratectrl *rate_ctrl,
591 u8 cur_valid_txrate,
592 u8 *next_idx)
593{
594 u8 i;
595
596 for (i = 0; i < rate_ctrl->max_valid_rate - 1; i++) {
597 if (rate_ctrl->valid_rate_index[i] == cur_valid_txrate) {
598 *next_idx = rate_ctrl->valid_rate_index[i+1];
599 return TRUE;
600 }
601 }
602
603 /* No more valid rates */
604 *next_idx = 0;
605 return FALSE;
606}
607
608/* Return true only for single stream */
609
610static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
611{
612 if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG))
613 return FALSE;
614 if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
615 return FALSE;
616 if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
617 return FALSE;
618 if (!ignore_cw && WLAN_RC_PHY_HT(phy))
619 if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
620 return FALSE;
621 if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
622 return FALSE;
623 return TRUE;
624}
625
626static inline int
627ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table,
628 struct ath_tx_ratectrl *rate_ctrl,
629 u8 cur_valid_txrate, u8 *next_idx)
630{
631 int8_t i;
632
633 for (i = 1; i < rate_ctrl->max_valid_rate ; i++) {
634 if (rate_ctrl->valid_rate_index[i] == cur_valid_txrate) {
635 *next_idx = rate_ctrl->valid_rate_index[i-1];
636 return TRUE;
637 }
638 }
639 return FALSE;
640}
641
642/*
643 * Initialize the Valid Rate Index from valid entries in Rate Table
644 */
645static u8
646ath_rc_sib_init_validrates(struct ath_rate_node *ath_rc_priv,
647 const struct ath_rate_table *rate_table,
648 u32 capflag)
649{
650 struct ath_tx_ratectrl *rate_ctrl;
651 u8 i, hi = 0;
652 u32 valid;
653
654 rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
655 for (i = 0; i < rate_table->rate_cnt; i++) {
656 valid = (ath_rc_priv->single_stream ?
dc2222a8
S
657 rate_table->info[i].valid_single_stream :
658 rate_table->info[i].valid);
f078f209
LR
659 if (valid == TRUE) {
660 u32 phy = rate_table->info[i].phy;
661 u8 valid_rate_count = 0;
662
663 if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
664 continue;
665
666 valid_rate_count = rate_ctrl->valid_phy_ratecnt[phy];
667
668 rate_ctrl->valid_phy_rateidx[phy][valid_rate_count] = i;
669 rate_ctrl->valid_phy_ratecnt[phy] += 1;
670 ath_rc_set_valid_txmask(rate_ctrl, i, TRUE);
671 hi = A_MAX(hi, i);
672 }
673 }
674 return hi;
675}
676
677/*
678 * Initialize the Valid Rate Index from Rate Set
679 */
680static u8
681ath_rc_sib_setvalid_rates(struct ath_rate_node *ath_rc_priv,
682 const struct ath_rate_table *rate_table,
683 struct ath_rateset *rateset,
684 u32 capflag)
685{
686 /* XXX: Clean me up and make identation friendly */
687 u8 i, j, hi = 0;
688 struct ath_tx_ratectrl *rate_ctrl =
689 (struct ath_tx_ratectrl *)(ath_rc_priv);
690
691 /* Use intersection of working rates and valid rates */
692 for (i = 0; i < rateset->rs_nrates; i++) {
693 for (j = 0; j < rate_table->rate_cnt; j++) {
694 u32 phy = rate_table->info[j].phy;
695 u32 valid = (ath_rc_priv->single_stream ?
696 rate_table->info[j].valid_single_stream :
697 rate_table->info[j].valid);
698
699 /* We allow a rate only if its valid and the
700 * capflag matches one of the validity
701 * (TRUE/TRUE_20/TRUE_40) flags */
702
703 /* XXX: catch the negative of this branch
704 * first and then continue */
705 if (((rateset->rs_rates[i] & 0x7F) ==
706 (rate_table->info[j].dot11rate & 0x7F)) &&
707 ((valid & WLAN_RC_CAP_MODE(capflag)) ==
708 WLAN_RC_CAP_MODE(capflag)) &&
709 !WLAN_RC_PHY_HT(phy)) {
710
711 u8 valid_rate_count = 0;
712
713 if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
714 continue;
715
716 valid_rate_count =
717 rate_ctrl->valid_phy_ratecnt[phy];
718
719 rate_ctrl->valid_phy_rateidx[phy]
720 [valid_rate_count] = j;
721 rate_ctrl->valid_phy_ratecnt[phy] += 1;
722 ath_rc_set_valid_txmask(rate_ctrl, j, TRUE);
723 hi = A_MAX(hi, j);
724 }
725 }
726 }
727 return hi;
728}
729
730static u8
731ath_rc_sib_setvalid_htrates(struct ath_rate_node *ath_rc_priv,
732 const struct ath_rate_table *rate_table,
733 u8 *mcs_set, u32 capflag)
734{
735 u8 i, j, hi = 0;
736 struct ath_tx_ratectrl *rate_ctrl =
737 (struct ath_tx_ratectrl *)(ath_rc_priv);
738
739 /* Use intersection of working rates and valid rates */
740 for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) {
741 for (j = 0; j < rate_table->rate_cnt; j++) {
742 u32 phy = rate_table->info[j].phy;
743 u32 valid = (ath_rc_priv->single_stream ?
dc2222a8
S
744 rate_table->info[j].valid_single_stream :
745 rate_table->info[j].valid);
f078f209
LR
746
747 if (((((struct ath_rateset *)
dc2222a8
S
748 mcs_set)->rs_rates[i] & 0x7F) !=
749 (rate_table->info[j].dot11rate & 0x7F)) ||
750 !WLAN_RC_PHY_HT(phy) ||
751 !WLAN_RC_PHY_HT_VALID(valid, capflag))
f078f209
LR
752 continue;
753
754 if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
755 continue;
756
757 rate_ctrl->valid_phy_rateidx[phy]
758 [rate_ctrl->valid_phy_ratecnt[phy]] = j;
759 rate_ctrl->valid_phy_ratecnt[phy] += 1;
760 ath_rc_set_valid_txmask(rate_ctrl, j, TRUE);
761 hi = A_MAX(hi, j);
762 }
763 }
764 return hi;
765}
766
767/*
768 * Attach to a device instance. Setup the public definition
769 * of how much per-node space we need and setup the private
770 * phy tables that have rate control parameters.
771 */
772struct ath_rate_softc *ath_rate_attach(struct ath_hal *ah)
773{
774 struct ath_rate_softc *asc;
775
776 /* we are only in user context so we can sleep for memory */
777 asc = kzalloc(sizeof(struct ath_rate_softc), GFP_KERNEL);
778 if (asc == NULL)
779 return NULL;
780
781 ar5416_attach_ratetables(asc);
782
783 /* Save Maximum TX Trigger Level (used for 11n) */
60b67f51 784 tx_triglevel_max = ah->ah_caps.tx_triglevel_max;
f078f209
LR
785 /* return alias for ath_rate_softc * */
786 return asc;
787}
788
789static struct ath_rate_node *ath_rate_node_alloc(struct ath_vap *avp,
790 struct ath_rate_softc *rsc,
791 gfp_t gfp)
792{
793 struct ath_rate_node *anode;
794
795 anode = kzalloc(sizeof(struct ath_rate_node), gfp);
796 if (anode == NULL)
797 return NULL;
798
799 anode->avp = avp;
800 anode->asc = rsc;
801 avp->rc_node = anode;
802
803 return anode;
804}
805
806static void ath_rate_node_free(struct ath_rate_node *anode)
807{
808 if (anode != NULL)
809 kfree(anode);
810}
811
812void ath_rate_detach(struct ath_rate_softc *asc)
813{
814 if (asc != NULL)
815 kfree(asc);
816}
817
818u8 ath_rate_findrateix(struct ath_softc *sc,
819 u8 dot11rate)
820{
821 const struct ath_rate_table *ratetable;
822 struct ath_rate_softc *rsc = sc->sc_rc;
823 int i;
824
825 ratetable = rsc->hw_rate_table[sc->sc_curmode];
826
827 if (WARN_ON(!ratetable))
828 return 0;
829
830 for (i = 0; i < ratetable->rate_cnt; i++) {
831 if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f))
832 return i;
833 }
834
835 return 0;
836}
837
838/*
839 * Update rate-control state on a device state change. When
840 * operating as a station this includes associate/reassociate
841 * with an AP. Otherwise this gets called, for example, when
842 * the we transition to run state when operating as an AP.
843 */
844void ath_rate_newstate(struct ath_softc *sc, struct ath_vap *avp)
845{
846 struct ath_rate_softc *asc = sc->sc_rc;
847
848 /* For half and quarter rate channles use different
849 * rate tables
850 */
7c56d24b 851 if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_HALF)
f078f209 852 ar5416_sethalf_ratetable(asc);
7c56d24b 853 else if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_QUARTER)
f078f209
LR
854 ar5416_setquarter_ratetable(asc);
855 else /* full rate */
856 ar5416_setfull_ratetable(asc);
857
858 if (avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) {
859 asc->fixedrix =
860 sc->sc_rixmap[avp->av_config.av_fixed_rateset & 0xff];
861 /* NB: check the fixed rate exists */
862 if (asc->fixedrix == 0xff)
863 asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
864 } else {
865 asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
866 }
867}
868
869static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
dc2222a8
S
870 struct ath_rate_node *ath_rc_priv,
871 const struct ath_rate_table *rate_table,
872 int probe_allowed, int *is_probing,
873 int is_retry)
f078f209
LR
874{
875 u32 dt, best_thruput, this_thruput, now_msec;
876 u8 rate, next_rate, best_rate, maxindex, minindex;
877 int8_t rssi_last, rssi_reduce = 0, index = 0;
878 struct ath_tx_ratectrl *rate_ctrl = NULL;
879
880 rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv ?
881 (ath_rc_priv) : NULL);
882
883 *is_probing = FALSE;
884
885 rssi_last = median(rate_ctrl->rssi_last,
886 rate_ctrl->rssi_last_prev,
887 rate_ctrl->rssi_last_prev2);
888
889 /*
890 * Age (reduce) last ack rssi based on how old it is.
891 * The bizarre numbers are so the delta is 160msec,
892 * meaning we divide by 16.
893 * 0msec <= dt <= 25msec: don't derate
894 * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
895 * 185msec <= dt: derate by 10dB
896 */
897
898 now_msec = jiffies_to_msecs(jiffies);
899 dt = now_msec - rate_ctrl->rssi_time;
900
901 if (dt >= 185)
902 rssi_reduce = 10;
903 else if (dt >= 25)
904 rssi_reduce = (u8)((dt - 25) >> 4);
905
906 /* Now reduce rssi_last by rssi_reduce */
907 if (rssi_last < rssi_reduce)
908 rssi_last = 0;
909 else
910 rssi_last -= rssi_reduce;
911
912 /*
913 * Now look up the rate in the rssi table and return it.
914 * If no rates match then we return 0 (lowest rate)
915 */
916
917 best_thruput = 0;
918 maxindex = rate_ctrl->max_valid_rate-1;
919
920 minindex = 0;
921 best_rate = minindex;
922
923 /*
924 * Try the higher rate first. It will reduce memory moving time
925 * if we have very good channel characteristics.
926 */
927 for (index = maxindex; index >= minindex ; index--) {
928 u8 per_thres;
929
930 rate = rate_ctrl->valid_rate_index[index];
931 if (rate > rate_ctrl->rate_max_phy)
932 continue;
933
934 /*
935 * For TCP the average collision rate is around 11%,
936 * so we ignore PERs less than this. This is to
937 * prevent the rate we are currently using (whose
938 * PER might be in the 10-15 range because of TCP
939 * collisions) looking worse than the next lower
940 * rate whose PER has decayed close to 0. If we
941 * used to next lower rate, its PER would grow to
942 * 10-15 and we would be worse off then staying
943 * at the current rate.
944 */
945 per_thres = rate_ctrl->state[rate].per;
946 if (per_thres < 12)
947 per_thres = 12;
948
949 this_thruput = rate_table->info[rate].user_ratekbps *
950 (100 - per_thres);
951
952 if (best_thruput <= this_thruput) {
953 best_thruput = this_thruput;
954 best_rate = rate;
955 }
956 }
957
958 rate = best_rate;
959
960 /* if we are retrying for more than half the number
961 * of max retries, use the min rate for the next retry
962 */
963 if (is_retry)
964 rate = rate_ctrl->valid_rate_index[minindex];
965
966 rate_ctrl->rssi_last_lookup = rssi_last;
967
968 /*
969 * Must check the actual rate (ratekbps) to account for
970 * non-monoticity of 11g's rate table
971 */
972
973 if (rate >= rate_ctrl->rate_max_phy && probe_allowed) {
974 rate = rate_ctrl->rate_max_phy;
975
976 /* Probe the next allowed phy state */
977 /* FIXME:XXXX Check to make sure ratMax is checked properly */
978 if (ath_rc_get_nextvalid_txrate(rate_table,
979 rate_ctrl, rate, &next_rate) &&
980 (now_msec - rate_ctrl->probe_time >
981 rate_table->probe_interval) &&
982 (rate_ctrl->hw_maxretry_pktcnt >= 1)) {
983 rate = next_rate;
984 rate_ctrl->probe_rate = rate;
985 rate_ctrl->probe_time = now_msec;
986 rate_ctrl->hw_maxretry_pktcnt = 0;
987 *is_probing = TRUE;
988 }
989 }
990
991 /*
992 * Make sure rate is not higher than the allowed maximum.
993 * We should also enforce the min, but I suspect the min is
994 * normally 1 rather than 0 because of the rate 9 vs 6 issue
995 * in the old code.
996 */
997 if (rate > (rate_ctrl->rate_table_size - 1))
998 rate = rate_ctrl->rate_table_size - 1;
999
1000 ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) ||
dc2222a8
S
1001 (rate_table->info[rate].valid_single_stream &&
1002 ath_rc_priv->single_stream));
f078f209
LR
1003
1004 return rate;
1005}
1006
1007static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table ,
1008 struct ath_rc_series *series,
1009 u8 tries,
1010 u8 rix,
1011 int rtsctsenable)
1012{
1013 series->tries = tries;
1014 series->flags = (rtsctsenable ? ATH_RC_RTSCTS_FLAG : 0) |
1015 (WLAN_RC_PHY_DS(rate_table->info[rix].phy) ?
1016 ATH_RC_DS_FLAG : 0) |
1017 (WLAN_RC_PHY_40(rate_table->info[rix].phy) ?
1018 ATH_RC_CW40_FLAG : 0) |
1019 (WLAN_RC_PHY_SGI(rate_table->info[rix].phy) ?
1020 ATH_RC_SGI_FLAG : 0);
1021
1022 series->rix = rate_table->info[rix].base_index;
1023 series->max_4ms_framelen = rate_table->info[rix].max_4ms_framelen;
1024}
1025
1026static u8 ath_rc_rate_getidx(struct ath_softc *sc,
dc2222a8
S
1027 struct ath_rate_node *ath_rc_priv,
1028 const struct ath_rate_table *rate_table,
1029 u8 rix, u16 stepdown,
1030 u16 min_rate)
f078f209
LR
1031{
1032 u32 j;
1033 u8 nextindex;
1034 struct ath_tx_ratectrl *rate_ctrl =
1035 (struct ath_tx_ratectrl *)(ath_rc_priv);
1036
1037 if (min_rate) {
1038 for (j = RATE_TABLE_SIZE; j > 0; j--) {
1039 if (ath_rc_get_nextlowervalid_txrate(rate_table,
1040 rate_ctrl, rix, &nextindex))
1041 rix = nextindex;
1042 else
1043 break;
1044 }
1045 } else {
1046 for (j = stepdown; j > 0; j--) {
1047 if (ath_rc_get_nextlowervalid_txrate(rate_table,
1048 rate_ctrl, rix, &nextindex))
1049 rix = nextindex;
1050 else
1051 break;
1052 }
1053 }
1054 return rix;
1055}
1056
1057static void ath_rc_ratefind(struct ath_softc *sc,
1058 struct ath_rate_node *ath_rc_priv,
1059 int num_tries, int num_rates, unsigned int rcflag,
1060 struct ath_rc_series series[], int *is_probe,
1061 int is_retry)
1062{
1063 u8 try_per_rate = 0, i = 0, rix, nrix;
1064 struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
1065 struct ath_rate_table *rate_table;
1066
1067 rate_table =
1068 (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
1069 rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table,
dc2222a8
S
1070 (rcflag & ATH_RC_PROBE_ALLOWED) ? 1 : 0,
1071 is_probe, is_retry);
f078f209
LR
1072 nrix = rix;
1073
1074 if ((rcflag & ATH_RC_PROBE_ALLOWED) && (*is_probe)) {
1075 /* set one try for probe rates. For the
1076 * probes don't enable rts */
1077 ath_rc_rate_set_series(rate_table,
1078 &series[i++], 1, nrix, FALSE);
1079
1080 try_per_rate = (num_tries/num_rates);
1081 /* Get the next tried/allowed rate. No RTS for the next series
1082 * after the probe rate
1083 */
1084 nrix = ath_rc_rate_getidx(sc,
1085 ath_rc_priv, rate_table, nrix, 1, FALSE);
1086 ath_rc_rate_set_series(rate_table,
1087 &series[i++], try_per_rate, nrix, 0);
1088 } else {
1089 try_per_rate = (num_tries/num_rates);
1090 /* Set the choosen rate. No RTS for first series entry. */
1091 ath_rc_rate_set_series(rate_table,
1092 &series[i++], try_per_rate, nrix, FALSE);
1093 }
1094
1095 /* Fill in the other rates for multirate retry */
1096 for ( ; i < num_rates; i++) {
1097 u8 try_num;
1098 u8 min_rate;
1099
1100 try_num = ((i + 1) == num_rates) ?
1101 num_tries - (try_per_rate * i) : try_per_rate ;
1102 min_rate = (((i + 1) == num_rates) &&
dc2222a8 1103 (rcflag & ATH_RC_MINRATE_LASTRATE)) ? 1 : 0;
f078f209
LR
1104
1105 nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
dc2222a8 1106 rate_table, nrix, 1, min_rate);
f078f209
LR
1107 /* All other rates in the series have RTS enabled */
1108 ath_rc_rate_set_series(rate_table,
dc2222a8 1109 &series[i], try_num, nrix, TRUE);
f078f209
LR
1110 }
1111
1112 /*
1113 * NB:Change rate series to enable aggregation when operating
1114 * at lower MCS rates. When first rate in series is MCS2
1115 * in HT40 @ 2.4GHz, series should look like:
1116 *
1117 * {MCS2, MCS1, MCS0, MCS0}.
1118 *
1119 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
1120 * look like:
1121 *
1122 * {MCS3, MCS2, MCS1, MCS1}
1123 *
1124 * So, set fourth rate in series to be same as third one for
1125 * above conditions.
1126 */
86b89eed 1127 if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) ||
dc2222a8
S
1128 (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) ||
1129 (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) {
f078f209
LR
1130 u8 dot11rate = rate_table->info[rix].dot11rate;
1131 u8 phy = rate_table->info[rix].phy;
1132 if (i == 4 &&
1133 ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
dc2222a8 1134 (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
f078f209
LR
1135 series[3].rix = series[2].rix;
1136 series[3].flags = series[2].flags;
1137 series[3].max_4ms_framelen = series[2].max_4ms_framelen;
1138 }
1139 }
1140}
1141
1142/*
1143 * Return the Tx rate series.
1144 */
5701ed84
S
1145static void ath_rate_findrate(struct ath_softc *sc,
1146 struct ath_rate_node *ath_rc_priv,
1147 int num_tries,
1148 int num_rates,
1149 unsigned int rcflag,
1150 struct ath_rc_series series[],
1151 int *is_probe,
1152 int is_retry)
f078f209
LR
1153{
1154 struct ath_vap *avp = ath_rc_priv->avp;
1155
dc2222a8
S
1156 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
1157
f078f209
LR
1158 if (!num_rates || !num_tries)
1159 return;
1160
1161 if (avp->av_config.av_fixed_rateset == IEEE80211_FIXED_RATE_NONE) {
1162 ath_rc_ratefind(sc, ath_rc_priv, num_tries, num_rates,
1163 rcflag, series, is_probe, is_retry);
1164 } else {
1165 /* Fixed rate */
1166 int idx;
1167 u8 flags;
1168 u32 rix;
1169 struct ath_rate_softc *asc = ath_rc_priv->asc;
1170 struct ath_rate_table *rate_table;
1171
1172 rate_table = (struct ath_rate_table *)
1173 asc->hw_rate_table[sc->sc_curmode];
1174
1175 for (idx = 0; idx < 4; idx++) {
1176 unsigned int mcs;
1177 u8 series_rix = 0;
1178
dc2222a8
S
1179 series[idx].tries = IEEE80211_RATE_IDX_ENTRY(
1180 avp->av_config.av_fixed_retryset, idx);
f078f209
LR
1181
1182 mcs = IEEE80211_RATE_IDX_ENTRY(
1183 avp->av_config.av_fixed_rateset, idx);
1184
1185 if (idx == 3 && (mcs & 0xf0) == 0x70)
1186 mcs = (mcs & ~0xf0)|0x80;
1187
1188 if (!(mcs & 0x80))
1189 flags = 0;
1190 else
1191 flags = ((ath_rc_priv->ht_cap &
1192 WLAN_RC_DS_FLAG) ?
1193 ATH_RC_DS_FLAG : 0) |
1194 ((ath_rc_priv->ht_cap &
1195 WLAN_RC_40_FLAG) ?
1196 ATH_RC_CW40_FLAG : 0) |
1197 ((ath_rc_priv->ht_cap &
1198 WLAN_RC_SGI_FLAG) ?
1199 ((ath_rc_priv->ht_cap &
1200 WLAN_RC_40_FLAG) ?
1201 ATH_RC_SGI_FLAG : 0) : 0);
1202
1203 series[idx].rix = sc->sc_rixmap[mcs];
1204 series_rix = series[idx].rix;
1205
1206 /* XXX: Give me some cleanup love */
1207 if ((flags & ATH_RC_CW40_FLAG) &&
1208 (flags & ATH_RC_SGI_FLAG))
1209 rix = rate_table->info[series_rix].ht_index;
1210 else if (flags & ATH_RC_SGI_FLAG)
1211 rix = rate_table->info[series_rix].sgi_index;
1212 else if (flags & ATH_RC_CW40_FLAG)
1213 rix = rate_table->info[series_rix].cw40index;
1214 else
1215 rix = rate_table->info[series_rix].base_index;
1216 series[idx].max_4ms_framelen =
1217 rate_table->info[rix].max_4ms_framelen;
1218 series[idx].flags = flags;
1219 }
1220 }
1221}
1222
1223static void ath_rc_update_ht(struct ath_softc *sc,
1224 struct ath_rate_node *ath_rc_priv,
1225 struct ath_tx_info_priv *info_priv,
1226 int tx_rate, int xretries, int retries)
1227{
1228 struct ath_tx_ratectrl *rate_ctrl;
1229 u32 now_msec = jiffies_to_msecs(jiffies);
1230 int state_change = FALSE, rate, count;
1231 u8 last_per;
dc2222a8 1232 struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
f078f209
LR
1233 struct ath_rate_table *rate_table =
1234 (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
1235
1236 static u32 nretry_to_per_lookup[10] = {
1237 100 * 0 / 1,
1238 100 * 1 / 4,
1239 100 * 1 / 2,
1240 100 * 3 / 4,
1241 100 * 4 / 5,
1242 100 * 5 / 6,
1243 100 * 6 / 7,
1244 100 * 7 / 8,
1245 100 * 8 / 9,
1246 100 * 9 / 10
1247 };
1248
1249 if (!ath_rc_priv)
1250 return;
1251
1252 rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
1253
1254 ASSERT(tx_rate >= 0);
1255 if (tx_rate < 0)
1256 return;
1257
1258 /* To compensate for some imbalance between ctrl and ext. channel */
1259
1260 if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
1261 info_priv->tx.ts_rssi =
1262 info_priv->tx.ts_rssi < 3 ? 0 :
1263 info_priv->tx.ts_rssi - 3;
1264
1265 last_per = rate_ctrl->state[tx_rate].per;
1266
1267 if (xretries) {
1268 /* Update the PER. */
1269 if (xretries == 1) {
1270 rate_ctrl->state[tx_rate].per += 30;
1271 if (rate_ctrl->state[tx_rate].per > 100)
1272 rate_ctrl->state[tx_rate].per = 100;
1273 } else {
1274 /* xretries == 2 */
1275 count = sizeof(nretry_to_per_lookup) /
dc2222a8 1276 sizeof(nretry_to_per_lookup[0]);
f078f209
LR
1277 if (retries >= count)
1278 retries = count - 1;
1279 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
1280 rate_ctrl->state[tx_rate].per =
1281 (u8)(rate_ctrl->state[tx_rate].per -
dc2222a8
S
1282 (rate_ctrl->state[tx_rate].per >> 3) +
1283 ((100) >> 3));
f078f209
LR
1284 }
1285
1286 /* xretries == 1 or 2 */
1287
1288 if (rate_ctrl->probe_rate == tx_rate)
1289 rate_ctrl->probe_rate = 0;
1290
1291 } else { /* xretries == 0 */
1292 /* Update the PER. */
1293 /* Make sure it doesn't index out of array's bounds. */
1294 count = sizeof(nretry_to_per_lookup) /
1295 sizeof(nretry_to_per_lookup[0]);
1296 if (retries >= count)
1297 retries = count - 1;
1298 if (info_priv->n_bad_frames) {
dc2222a8 1299 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
f078f209
LR
1300 * Assuming that n_frames is not 0. The current PER
1301 * from the retries is 100 * retries / (retries+1),
1302 * since the first retries attempts failed, and the
1303 * next one worked. For the one that worked,
1304 * n_bad_frames subframes out of n_frames wored,
1305 * so the PER for that part is
1306 * 100 * n_bad_frames / n_frames, and it contributes
1307 * 100 * n_bad_frames / (n_frames * (retries+1)) to
1308 * the above PER. The expression below is a
1309 * simplified version of the sum of these two terms.
1310 */
1311 if (info_priv->n_frames > 0)
1312 rate_ctrl->state[tx_rate].per
1313 = (u8)
1314 (rate_ctrl->state[tx_rate].per -
1315 (rate_ctrl->state[tx_rate].per >> 3) +
1316 ((100*(retries*info_priv->n_frames +
1317 info_priv->n_bad_frames) /
1318 (info_priv->n_frames *
1319 (retries+1))) >> 3));
1320 } else {
1321 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
1322
1323 rate_ctrl->state[tx_rate].per = (u8)
1324 (rate_ctrl->state[tx_rate].per -
1325 (rate_ctrl->state[tx_rate].per >> 3) +
1326 (nretry_to_per_lookup[retries] >> 3));
1327 }
1328
1329 rate_ctrl->rssi_last_prev2 = rate_ctrl->rssi_last_prev;
1330 rate_ctrl->rssi_last_prev = rate_ctrl->rssi_last;
1331 rate_ctrl->rssi_last = info_priv->tx.ts_rssi;
1332 rate_ctrl->rssi_time = now_msec;
1333
1334 /*
1335 * If we got at most one retry then increase the max rate if
1336 * this was a probe. Otherwise, ignore the probe.
1337 */
1338
1339 if (rate_ctrl->probe_rate && rate_ctrl->probe_rate == tx_rate) {
1340 if (retries > 0 || 2 * info_priv->n_bad_frames >
1341 info_priv->n_frames) {
1342 /*
1343 * Since we probed with just a single attempt,
1344 * any retries means the probe failed. Also,
1345 * if the attempt worked, but more than half
1346 * the subframes were bad then also consider
1347 * the probe a failure.
1348 */
1349 rate_ctrl->probe_rate = 0;
1350 } else {
1351 u8 probe_rate = 0;
1352
1353 rate_ctrl->rate_max_phy = rate_ctrl->probe_rate;
1354 probe_rate = rate_ctrl->probe_rate;
1355
1356 if (rate_ctrl->state[probe_rate].per > 30)
1357 rate_ctrl->state[probe_rate].per = 20;
1358
1359 rate_ctrl->probe_rate = 0;
1360
1361 /*
1362 * Since this probe succeeded, we allow the next
1363 * probe twice as soon. This allows the maxRate
1364 * to move up faster if the probes are
1365 * succesful.
1366 */
1367 rate_ctrl->probe_time = now_msec -
1368 rate_table->probe_interval / 2;
1369 }
1370 }
1371
1372 if (retries > 0) {
1373 /*
1374 * Don't update anything. We don't know if
1375 * this was because of collisions or poor signal.
1376 *
1377 * Later: if rssi_ack is close to
1378 * rate_ctrl->state[txRate].rssi_thres and we see lots
1379 * of retries, then we could increase
1380 * rate_ctrl->state[txRate].rssi_thres.
1381 */
1382 rate_ctrl->hw_maxretry_pktcnt = 0;
1383 } else {
1384 /*
1385 * It worked with no retries. First ignore bogus (small)
1386 * rssi_ack values.
1387 */
1388 if (tx_rate == rate_ctrl->rate_max_phy &&
dc2222a8 1389 rate_ctrl->hw_maxretry_pktcnt < 255) {
f078f209
LR
1390 rate_ctrl->hw_maxretry_pktcnt++;
1391 }
1392
1393 if (info_priv->tx.ts_rssi >=
1394 rate_table->info[tx_rate].rssi_ack_validmin) {
1395 /* Average the rssi */
1396 if (tx_rate != rate_ctrl->rssi_sum_rate) {
1397 rate_ctrl->rssi_sum_rate = tx_rate;
1398 rate_ctrl->rssi_sum =
1399 rate_ctrl->rssi_sum_cnt = 0;
1400 }
1401
1402 rate_ctrl->rssi_sum += info_priv->tx.ts_rssi;
1403 rate_ctrl->rssi_sum_cnt++;
1404
1405 if (rate_ctrl->rssi_sum_cnt > 4) {
1406 int32_t rssi_ackAvg =
1407 (rate_ctrl->rssi_sum + 2) / 4;
1408 int8_t rssi_thres =
1409 rate_ctrl->state[tx_rate].
1410 rssi_thres;
1411 int8_t rssi_ack_vmin =
1412 rate_table->info[tx_rate].
1413 rssi_ack_validmin;
1414
1415 rate_ctrl->rssi_sum =
1416 rate_ctrl->rssi_sum_cnt = 0;
1417
1418 /* Now reduce the current
1419 * rssi threshold. */
1420 if ((rssi_ackAvg < rssi_thres + 2) &&
dc2222a8 1421 (rssi_thres > rssi_ack_vmin)) {
f078f209
LR
1422 rate_ctrl->state[tx_rate].
1423 rssi_thres--;
1424 }
1425
1426 state_change = TRUE;
1427 }
1428 }
1429 }
1430 }
1431
1432 /* For all cases */
1433
1434 /*
1435 * If this rate looks bad (high PER) then stop using it for
1436 * a while (except if we are probing).
1437 */
1438 if (rate_ctrl->state[tx_rate].per >= 55 && tx_rate > 0 &&
dc2222a8
S
1439 rate_table->info[tx_rate].ratekbps <=
1440 rate_table->info[rate_ctrl->rate_max_phy].ratekbps) {
f078f209 1441 ath_rc_get_nextlowervalid_txrate(rate_table, rate_ctrl,
dc2222a8 1442 (u8) tx_rate, &rate_ctrl->rate_max_phy);
f078f209
LR
1443
1444 /* Don't probe for a little while. */
1445 rate_ctrl->probe_time = now_msec;
1446 }
1447
1448 if (state_change) {
1449 /*
1450 * Make sure the rates above this have higher rssi thresholds.
1451 * (Note: Monotonicity is kept within the OFDM rates and
1452 * within the CCK rates. However, no adjustment is
1453 * made to keep the rssi thresholds monotonically
1454 * increasing between the CCK and OFDM rates.)
1455 */
1456 for (rate = tx_rate; rate <
1457 rate_ctrl->rate_table_size - 1; rate++) {
1458 if (rate_table->info[rate+1].phy !=
1459 rate_table->info[tx_rate].phy)
1460 break;
1461
1462 if (rate_ctrl->state[rate].rssi_thres +
dc2222a8
S
1463 rate_table->info[rate].rssi_ack_deltamin >
1464 rate_ctrl->state[rate+1].rssi_thres) {
f078f209
LR
1465 rate_ctrl->state[rate+1].rssi_thres =
1466 rate_ctrl->state[rate].
dc2222a8 1467 rssi_thres +
f078f209 1468 rate_table->info[rate].
dc2222a8 1469 rssi_ack_deltamin;
f078f209
LR
1470 }
1471 }
1472
1473 /* Make sure the rates below this have lower rssi thresholds. */
1474 for (rate = tx_rate - 1; rate >= 0; rate--) {
1475 if (rate_table->info[rate].phy !=
dc2222a8 1476 rate_table->info[tx_rate].phy)
f078f209
LR
1477 break;
1478
1479 if (rate_ctrl->state[rate].rssi_thres +
dc2222a8
S
1480 rate_table->info[rate].rssi_ack_deltamin >
1481 rate_ctrl->state[rate+1].rssi_thres) {
f078f209 1482 if (rate_ctrl->state[rate+1].rssi_thres <
dc2222a8
S
1483 rate_table->info[rate].
1484 rssi_ack_deltamin)
f078f209
LR
1485 rate_ctrl->state[rate].rssi_thres = 0;
1486 else {
1487 rate_ctrl->state[rate].rssi_thres =
1488 rate_ctrl->state[rate+1].
dc2222a8
S
1489 rssi_thres -
1490 rate_table->info[rate].
1491 rssi_ack_deltamin;
f078f209
LR
1492 }
1493
1494 if (rate_ctrl->state[rate].rssi_thres <
dc2222a8
S
1495 rate_table->info[rate].
1496 rssi_ack_validmin) {
f078f209
LR
1497 rate_ctrl->state[rate].rssi_thres =
1498 rate_table->info[rate].
dc2222a8 1499 rssi_ack_validmin;
f078f209
LR
1500 }
1501 }
1502 }
1503 }
1504
1505 /* Make sure the rates below this have lower PER */
1506 /* Monotonicity is kept only for rates below the current rate. */
1507 if (rate_ctrl->state[tx_rate].per < last_per) {
1508 for (rate = tx_rate - 1; rate >= 0; rate--) {
1509 if (rate_table->info[rate].phy !=
dc2222a8 1510 rate_table->info[tx_rate].phy)
f078f209
LR
1511 break;
1512
1513 if (rate_ctrl->state[rate].per >
dc2222a8 1514 rate_ctrl->state[rate+1].per) {
f078f209
LR
1515 rate_ctrl->state[rate].per =
1516 rate_ctrl->state[rate+1].per;
1517 }
1518 }
1519 }
1520
1521 /* Maintain monotonicity for rates above the current rate */
1522 for (rate = tx_rate; rate < rate_ctrl->rate_table_size - 1; rate++) {
1523 if (rate_ctrl->state[rate+1].per < rate_ctrl->state[rate].per)
1524 rate_ctrl->state[rate+1].per =
1525 rate_ctrl->state[rate].per;
1526 }
1527
1528 /* Every so often, we reduce the thresholds and
1529 * PER (different for CCK and OFDM). */
1530 if (now_msec - rate_ctrl->rssi_down_time >=
dc2222a8 1531 rate_table->rssi_reduce_interval) {
f078f209
LR
1532
1533 for (rate = 0; rate < rate_ctrl->rate_table_size; rate++) {
1534 if (rate_ctrl->state[rate].rssi_thres >
dc2222a8 1535 rate_table->info[rate].rssi_ack_validmin)
f078f209
LR
1536 rate_ctrl->state[rate].rssi_thres -= 1;
1537 }
1538 rate_ctrl->rssi_down_time = now_msec;
1539 }
1540
1541 /* Every so often, we reduce the thresholds
1542 * and PER (different for CCK and OFDM). */
1543 if (now_msec - rate_ctrl->per_down_time >=
dc2222a8 1544 rate_table->rssi_reduce_interval) {
f078f209
LR
1545 for (rate = 0; rate < rate_ctrl->rate_table_size; rate++) {
1546 rate_ctrl->state[rate].per =
1547 7 * rate_ctrl->state[rate].per / 8;
1548 }
1549
1550 rate_ctrl->per_down_time = now_msec;
1551 }
1552}
1553
1554/*
1555 * This routine is called in rate control callback tx_status() to give
1556 * the status of previous frames.
1557 */
1558static void ath_rc_update(struct ath_softc *sc,
1559 struct ath_rate_node *ath_rc_priv,
1560 struct ath_tx_info_priv *info_priv, int final_ts_idx,
1561 int xretries, int long_retry)
1562{
dc2222a8 1563 struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
f078f209
LR
1564 struct ath_rate_table *rate_table;
1565 struct ath_tx_ratectrl *rate_ctrl;
1566 struct ath_rc_series rcs[4];
1567 u8 flags;
1568 u32 series = 0, rix;
1569
1570 memcpy(rcs, info_priv->rcs, 4 * sizeof(rcs[0]));
1571 rate_table = (struct ath_rate_table *)
1572 asc->hw_rate_table[sc->sc_curmode];
1573 rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
1574 ASSERT(rcs[0].tries != 0);
1575
1576 /*
1577 * If the first rate is not the final index, there
1578 * are intermediate rate failures to be processed.
1579 */
1580 if (final_ts_idx != 0) {
1581 /* Process intermediate rates that failed.*/
1582 for (series = 0; series < final_ts_idx ; series++) {
1583 if (rcs[series].tries != 0) {
1584 flags = rcs[series].flags;
1585 /* If HT40 and we have switched mode from
1586 * 40 to 20 => don't update */
1587 if ((flags & ATH_RC_CW40_FLAG) &&
1588 (rate_ctrl->rc_phy_mode !=
1589 (flags & ATH_RC_CW40_FLAG)))
1590 return;
1591 if ((flags & ATH_RC_CW40_FLAG) &&
1592 (flags & ATH_RC_SGI_FLAG))
1593 rix = rate_table->info[
1594 rcs[series].rix].ht_index;
1595 else if (flags & ATH_RC_SGI_FLAG)
1596 rix = rate_table->info[
1597 rcs[series].rix].sgi_index;
1598 else if (flags & ATH_RC_CW40_FLAG)
1599 rix = rate_table->info[
1600 rcs[series].rix].cw40index;
1601 else
1602 rix = rate_table->info[
1603 rcs[series].rix].base_index;
1604 ath_rc_update_ht(sc, ath_rc_priv,
1605 info_priv, rix,
1606 xretries ? 1 : 2,
1607 rcs[series].tries);
1608 }
1609 }
1610 } else {
1611 /*
1612 * Handle the special case of MIMO PS burst, where the second
1613 * aggregate is sent out with only one rate and one try.
1614 * Treating it as an excessive retry penalizes the rate
1615 * inordinately.
1616 */
1617 if (rcs[0].tries == 1 && xretries == 1)
1618 xretries = 2;
1619 }
1620
1621 flags = rcs[series].flags;
1622 /* If HT40 and we have switched mode from 40 to 20 => don't update */
1623 if ((flags & ATH_RC_CW40_FLAG) &&
1624 (rate_ctrl->rc_phy_mode != (flags & ATH_RC_CW40_FLAG)))
1625 return;
1626
1627 if ((flags & ATH_RC_CW40_FLAG) && (flags & ATH_RC_SGI_FLAG))
1628 rix = rate_table->info[rcs[series].rix].ht_index;
1629 else if (flags & ATH_RC_SGI_FLAG)
1630 rix = rate_table->info[rcs[series].rix].sgi_index;
1631 else if (flags & ATH_RC_CW40_FLAG)
1632 rix = rate_table->info[rcs[series].rix].cw40index;
1633 else
1634 rix = rate_table->info[rcs[series].rix].base_index;
1635
1636 ath_rc_update_ht(sc, ath_rc_priv, info_priv, rix,
1637 xretries, long_retry);
1638}
1639
f078f209
LR
1640/*
1641 * Process a tx descriptor for a completed transmit (success or failure).
1642 */
1643static void ath_rate_tx_complete(struct ath_softc *sc,
1644 struct ath_node *an,
1645 struct ath_rate_node *rc_priv,
1646 struct ath_tx_info_priv *info_priv)
1647{
1648 int final_ts_idx = info_priv->tx.ts_rateindex;
1649 int tx_status = 0, is_underrun = 0;
1650 struct ath_vap *avp;
1651
1652 avp = rc_priv->avp;
dc2222a8
S
1653 if ((avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) ||
1654 (info_priv->tx.ts_status & ATH9K_TXERR_FILT))
f078f209
LR
1655 return;
1656
1657 if (info_priv->tx.ts_rssi > 0) {
1658 ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi,
dc2222a8 1659 info_priv->tx.ts_rssi);
f078f209
LR
1660 }
1661
1662 /*
1663 * If underrun error is seen assume it as an excessive retry only
1664 * if prefetch trigger level have reached the max (0x3f for 5416)
1665 * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
1666 * times. This affects how ratectrl updates PER for the failed rate.
1667 */
1668 if (info_priv->tx.ts_flags &
1669 (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
1670 ((sc->sc_ah->ah_txTrigLevel) >= tx_triglevel_max)) {
1671 tx_status = 1;
1672 is_underrun = 1;
1673 }
1674
1675 if ((info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
1676 (info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
1677 tx_status = 1;
1678
1679 ath_rc_update(sc, rc_priv, info_priv, final_ts_idx, tx_status,
1680 (is_underrun) ? ATH_11N_TXMAXTRY :
1681 info_priv->tx.ts_longretry);
1682}
1683
f078f209
LR
1684/*
1685 * Update the SIB's rate control information
1686 *
1687 * This should be called when the supported rates change
1688 * (e.g. SME operation, wireless mode change)
1689 *
1690 * It will determine which rates are valid for use.
1691 */
1692static void ath_rc_sib_update(struct ath_softc *sc,
1693 struct ath_rate_node *ath_rc_priv,
1694 u32 capflag, int keep_state,
1695 struct ath_rateset *negotiated_rates,
1696 struct ath_rateset *negotiated_htrates)
1697{
1698 struct ath_rate_table *rate_table = NULL;
1699 struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
1700 struct ath_rateset *rateset = negotiated_rates;
1701 u8 *ht_mcs = (u8 *)negotiated_htrates;
dc2222a8
S
1702 struct ath_tx_ratectrl *rate_ctrl =
1703 (struct ath_tx_ratectrl *)ath_rc_priv;
f078f209
LR
1704 u8 i, j, k, hi = 0, hthi = 0;
1705
1706 rate_table = (struct ath_rate_table *)
1707 asc->hw_rate_table[sc->sc_curmode];
1708
1709 /* Initial rate table size. Will change depending
1710 * on the working rate set */
1711 rate_ctrl->rate_table_size = MAX_TX_RATE_TBL;
1712
1713 /* Initialize thresholds according to the global rate table */
1714 for (i = 0 ; (i < rate_ctrl->rate_table_size) && (!keep_state); i++) {
1715 rate_ctrl->state[i].rssi_thres =
1716 rate_table->info[i].rssi_ack_validmin;
1717 rate_ctrl->state[i].per = 0;
1718 }
1719
1720 /* Determine the valid rates */
1721 ath_rc_init_valid_txmask(rate_ctrl);
1722
1723 for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
1724 for (j = 0; j < MAX_TX_RATE_PHY; j++)
1725 rate_ctrl->valid_phy_rateidx[i][j] = 0;
1726 rate_ctrl->valid_phy_ratecnt[i] = 0;
1727 }
1728 rate_ctrl->rc_phy_mode = (capflag & WLAN_RC_40_FLAG);
1729
1730 /* Set stream capability */
1731 ath_rc_priv->single_stream = (capflag & WLAN_RC_DS_FLAG) ? 0 : 1;
1732
1733 if (!rateset->rs_nrates) {
1734 /* No working rate, just initialize valid rates */
1735 hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table,
1736 capflag);
1737 } else {
1738 /* Use intersection of working rates and valid rates */
1739 hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table,
1740 rateset, capflag);
1741 if (capflag & WLAN_RC_HT_FLAG) {
1742 hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv,
1743 rate_table,
1744 ht_mcs,
1745 capflag);
1746 }
1747 hi = A_MAX(hi, hthi);
1748 }
1749
1750 rate_ctrl->rate_table_size = hi + 1;
1751 rate_ctrl->rate_max_phy = 0;
1752 ASSERT(rate_ctrl->rate_table_size <= MAX_TX_RATE_TBL);
1753
1754 for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
1755 for (j = 0; j < rate_ctrl->valid_phy_ratecnt[i]; j++) {
1756 rate_ctrl->valid_rate_index[k++] =
1757 rate_ctrl->valid_phy_rateidx[i][j];
1758 }
1759
1760 if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, TRUE)
1761 || !rate_ctrl->valid_phy_ratecnt[i])
1762 continue;
1763
1764 rate_ctrl->rate_max_phy = rate_ctrl->valid_phy_rateidx[i][j-1];
1765 }
1766 ASSERT(rate_ctrl->rate_table_size <= MAX_TX_RATE_TBL);
1767 ASSERT(k <= MAX_TX_RATE_TBL);
1768
1769 rate_ctrl->max_valid_rate = k;
1770 /*
1771 * Some third party vendors don't send the supported rate series in
1772 * order. So sorting to make sure its in order, otherwise our RateFind
1773 * Algo will select wrong rates
1774 */
1775 ath_rc_sort_validrates(rate_table, rate_ctrl);
1776 rate_ctrl->rate_max_phy = rate_ctrl->valid_rate_index[k-4];
1777}
1778
1779/*
1780 * Update rate-control state on station associate/reassociate.
1781 */
1782static int ath_rate_newassoc(struct ath_softc *sc,
1783 struct ath_rate_node *ath_rc_priv,
1784 unsigned int capflag,
1785 struct ath_rateset *negotiated_rates,
1786 struct ath_rateset *negotiated_htrates)
1787{
1788
1789
1790 ath_rc_priv->ht_cap =
1791 ((capflag & ATH_RC_DS_FLAG) ? WLAN_RC_DS_FLAG : 0) |
1792 ((capflag & ATH_RC_SGI_FLAG) ? WLAN_RC_SGI_FLAG : 0) |
1793 ((capflag & ATH_RC_HT_FLAG) ? WLAN_RC_HT_FLAG : 0) |
1794 ((capflag & ATH_RC_CW40_FLAG) ? WLAN_RC_40_FLAG : 0);
1795
1796 ath_rc_sib_update(sc, ath_rc_priv, ath_rc_priv->ht_cap, 0,
1797 negotiated_rates, negotiated_htrates);
1798
1799 return 0;
1800}
1801
1802/*
1803 * This routine is called to initialize the rate control parameters
1804 * in the SIB. It is called initially during system initialization
1805 * or when a station is associated with the AP.
1806 */
1807static void ath_rc_sib_init(struct ath_rate_node *ath_rc_priv)
1808{
1809 struct ath_tx_ratectrl *rate_ctrl;
1810
1811 rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
1812 rate_ctrl->rssi_down_time = jiffies_to_msecs(jiffies);
1813}
1814
1815
4b7679a5
JB
1816static void ath_setup_rates(struct ath_softc *sc,
1817 struct ieee80211_supported_band *sband,
1818 struct ieee80211_sta *sta,
1819 struct ath_rate_node *rc_priv)
f078f209
LR
1820
1821{
f078f209
LR
1822 int i, j = 0;
1823
dc2222a8
S
1824 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
1825
f078f209 1826 for (i = 0; i < sband->n_bitrates; i++) {
4b7679a5 1827 if (sta->supp_rates[sband->band] & BIT(i)) {
f078f209
LR
1828 rc_priv->neg_rates.rs_rates[j]
1829 = (sband->bitrates[i].bitrate * 2) / 10;
1830 j++;
1831 }
1832 }
1833 rc_priv->neg_rates.rs_nrates = j;
1834}
1835
1836void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv)
1837{
1838 struct ath_softc *sc = hw->priv;
1839 u32 capflag = 0;
1840
d9fe60de 1841 if (hw->conf.ht_cap.ht_supported) {
f078f209
LR
1842 capflag |= ATH_RC_HT_FLAG | ATH_RC_DS_FLAG;
1843 if (sc->sc_ht_info.tx_chan_width == ATH9K_HT_MACMODE_2040)
1844 capflag |= ATH_RC_CW40_FLAG;
1845 }
1846
1847 ath_rate_newassoc(sc, rc_priv, capflag,
1848 &rc_priv->neg_rates,
1849 &rc_priv->neg_ht_rates);
1850
1851}
1852
1853/* Rate Control callbacks */
4b7679a5
JB
1854static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1855 struct ieee80211_sta *sta, void *priv_sta,
f078f209
LR
1856 struct sk_buff *skb)
1857{
1858 struct ath_softc *sc = priv;
1859 struct ath_tx_info_priv *tx_info_priv;
1860 struct ath_node *an;
f078f209
LR
1861 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1862 struct ieee80211_hdr *hdr;
1863 __le16 fc;
1864
f078f209
LR
1865 hdr = (struct ieee80211_hdr *)skb->data;
1866 fc = hdr->frame_control;
1867 tx_info_priv = (struct ath_tx_info_priv *)tx_info->driver_data[0];
1868
1869 spin_lock_bh(&sc->node_lock);
1870 an = ath_node_find(sc, hdr->addr1);
1871 spin_unlock_bh(&sc->node_lock);
1872
4b7679a5 1873 if (!an || !priv_sta || !ieee80211_is_data(fc)) {
f078f209
LR
1874 if (tx_info->driver_data[0] != NULL) {
1875 kfree(tx_info->driver_data[0]);
1876 tx_info->driver_data[0] = NULL;
1877 }
1878 return;
1879 }
1880 if (tx_info->driver_data[0] != NULL) {
4b7679a5 1881 ath_rate_tx_complete(sc, an, priv_sta, tx_info_priv);
f078f209
LR
1882 kfree(tx_info->driver_data[0]);
1883 tx_info->driver_data[0] = NULL;
1884 }
1885}
1886
1887static void ath_tx_aggr_resp(struct ath_softc *sc,
4b7679a5
JB
1888 struct ieee80211_supported_band *sband,
1889 struct ieee80211_sta *sta,
f078f209
LR
1890 struct ath_node *an,
1891 u8 tidno)
1892{
f078f209 1893 struct ath_atx_tid *txtid;
f078f209
LR
1894 u16 buffersize = 0;
1895 int state;
4b7679a5 1896 struct sta_info *si;
f078f209 1897
672840ac 1898 if (!(sc->sc_flags & SC_OP_TXAGGR))
f078f209
LR
1899 return;
1900
1901 txtid = ATH_AN_2_TID(an, tidno);
1902 if (!txtid->paused)
1903 return;
1904
4b7679a5
JB
1905 /*
1906 * XXX: This is entirely busted, we aren't supposed to
1907 * access the sta from here because it's internal
1908 * to mac80211, and looking at the state without
1909 * locking is wrong too.
1910 */
1911 si = container_of(sta, struct sta_info, sta);
f078f209 1912 buffersize = IEEE80211_MIN_AMPDU_BUF <<
d9fe60de 1913 sband->ht_cap.ampdu_factor; /* FIXME */
4b7679a5 1914 state = si->ampdu_mlme.tid_state_tx[tidno];
f078f209
LR
1915
1916 if (state & HT_ADDBA_RECEIVED_MSK) {
1917 txtid->addba_exchangecomplete = 1;
1918 txtid->addba_exchangeinprogress = 0;
1919 txtid->baw_size = buffersize;
1920
1921 DPRINTF(sc, ATH_DBG_AGGR,
1922 "%s: Resuming tid, buffersize: %d\n",
1923 __func__,
1924 buffersize);
1925
1926 ath_tx_resume_tid(sc, txtid);
1927 }
1928}
1929
4b7679a5
JB
1930static void ath_get_rate(void *priv, struct ieee80211_supported_band *sband,
1931 struct ieee80211_sta *sta, void *priv_sta,
1932 struct sk_buff *skb, struct rate_selection *sel)
f078f209
LR
1933{
1934 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4b7679a5 1935 struct ath_softc *sc = priv;
f078f209
LR
1936 struct ieee80211_hw *hw = sc->hw;
1937 struct ath_tx_info_priv *tx_info_priv;
4b7679a5 1938 struct ath_rate_node *ath_rc_priv = priv_sta;
f078f209
LR
1939 struct ath_node *an;
1940 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
5701ed84 1941 int is_probe = FALSE, chk, ret;
f078f209
LR
1942 s8 lowest_idx;
1943 __le16 fc = hdr->frame_control;
1944 u8 *qc, tid;
f078f209
LR
1945
1946 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
1947
1948 /* allocate driver private area of tx_info */
1949 tx_info->driver_data[0] = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
1950 ASSERT(tx_info->driver_data[0] != NULL);
1951 tx_info_priv = (struct ath_tx_info_priv *)tx_info->driver_data[0];
1952
4b7679a5 1953 lowest_idx = rate_lowest_index(sband, sta);
f078f209
LR
1954 tx_info_priv->min_rate = (sband->bitrates[lowest_idx].bitrate * 2) / 10;
1955 /* lowest rate for management and multicast/broadcast frames */
1956 if (!ieee80211_is_data(fc) ||
dc2222a8 1957 is_multicast_ether_addr(hdr->addr1) || !sta) {
f078f209
LR
1958 sel->rate_idx = lowest_idx;
1959 return;
1960 }
1961
f078f209
LR
1962 /* Find tx rate for unicast frames */
1963 ath_rate_findrate(sc, ath_rc_priv,
1964 ATH_11N_TXMAXTRY, 4,
1965 ATH_RC_PROBE_ALLOWED,
1966 tx_info_priv->rcs,
1967 &is_probe,
1968 false);
1969 if (is_probe)
4b7679a5 1970 sel->probe_idx = ath_rc_priv->tx_ratectrl.probe_rate;
f078f209
LR
1971
1972 /* Ratecontrol sometimes returns invalid rate index */
1973 if (tx_info_priv->rcs[0].rix != 0xff)
1974 ath_rc_priv->prev_data_rix = tx_info_priv->rcs[0].rix;
1975 else
1976 tx_info_priv->rcs[0].rix = ath_rc_priv->prev_data_rix;
1977
1978 sel->rate_idx = tx_info_priv->rcs[0].rix;
1979
1980 /* Check if aggregation has to be enabled for this tid */
1981
d9fe60de 1982 if (hw->conf.ht_cap.ht_supported) {
f078f209
LR
1983 if (ieee80211_is_data_qos(fc)) {
1984 qc = ieee80211_get_qos_ctl(hdr);
1985 tid = qc[0] & 0xf;
1986
1987 spin_lock_bh(&sc->node_lock);
1988 an = ath_node_find(sc, hdr->addr1);
1989 spin_unlock_bh(&sc->node_lock);
1990
1991 if (!an) {
1992 DPRINTF(sc, ATH_DBG_AGGR,
1993 "%s: Node not found to "
1994 "init/chk TX aggr\n", __func__);
1995 return;
1996 }
1997
1998 chk = ath_tx_aggr_check(sc, an, tid);
1999 if (chk == AGGR_REQUIRED) {
2000 ret = ieee80211_start_tx_ba_session(hw,
2001 hdr->addr1, tid);
2002 if (ret)
2003 DPRINTF(sc, ATH_DBG_AGGR,
2004 "%s: Unable to start tx "
e174961c 2005 "aggr for: %pM\n",
f078f209 2006 __func__,
e174961c 2007 hdr->addr1);
f078f209
LR
2008 else
2009 DPRINTF(sc, ATH_DBG_AGGR,
e174961c 2010 "%s: Started tx aggr for: %pM\n",
f078f209 2011 __func__,
e174961c 2012 hdr->addr1);
f078f209 2013 } else if (chk == AGGR_EXCHANGE_PROGRESS)
4b7679a5 2014 ath_tx_aggr_resp(sc, sband, sta, an, tid);
f078f209
LR
2015 }
2016 }
2017}
2018
4b7679a5
JB
2019static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
2020 struct ieee80211_sta *sta, void *priv_sta)
f078f209 2021{
4b7679a5 2022 struct ath_softc *sc = priv;
dc2222a8 2023 struct ath_rate_node *ath_rc_priv = priv_sta;
f078f209
LR
2024 int i, j = 0;
2025
2026 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
2027
4b7679a5
JB
2028 ath_setup_rates(sc, sband, sta, ath_rc_priv);
2029 if (sc->hw->conf.flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
d9fe60de
JB
2030 for (i = 0; i < 77; i++) {
2031 if (sc->hw->conf.ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
dc2222a8 2032 ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
f078f209
LR
2033 if (j == ATH_RATE_MAX)
2034 break;
2035 }
dc2222a8 2036 ath_rc_priv->neg_ht_rates.rs_nrates = j;
f078f209 2037 }
4b7679a5 2038 ath_rc_node_update(sc->hw, priv_sta);
f078f209
LR
2039}
2040
2041static void ath_rate_clear(void *priv)
2042{
2043 return;
2044}
2045
4b7679a5 2046static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
f078f209 2047{
f078f209
LR
2048 struct ath_softc *sc = hw->priv;
2049
dc2222a8 2050 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
4b7679a5 2051 return hw->priv;
f078f209
LR
2052}
2053
2054static void ath_rate_free(void *priv)
2055{
2056 return;
2057}
2058
4b7679a5 2059static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
f078f209
LR
2060{
2061 struct ath_softc *sc = priv;
2062 struct ath_vap *avp = sc->sc_vaps[0];
2063 struct ath_rate_node *rate_priv;
2064
dc2222a8
S
2065 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
2066
f078f209
LR
2067 rate_priv = ath_rate_node_alloc(avp, sc->sc_rc, gfp);
2068 if (!rate_priv) {
dc2222a8
S
2069 DPRINTF(sc, ATH_DBG_FATAL,
2070 "%s: Unable to allocate private rc structure\n",
2071 __func__);
f078f209
LR
2072 return NULL;
2073 }
2074 ath_rc_sib_init(rate_priv);
dc2222a8 2075
f078f209
LR
2076 return rate_priv;
2077}
2078
4b7679a5
JB
2079static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
2080 void *priv_sta)
f078f209
LR
2081{
2082 struct ath_rate_node *rate_priv = priv_sta;
2083 struct ath_softc *sc = priv;
2084
2085 DPRINTF(sc, ATH_DBG_RATE, "%s", __func__);
2086 ath_rate_node_free(rate_priv);
2087}
2088
2089static struct rate_control_ops ath_rate_ops = {
2090 .module = NULL,
2091 .name = "ath9k_rate_control",
2092 .tx_status = ath_tx_status,
2093 .get_rate = ath_get_rate,
2094 .rate_init = ath_rate_init,
2095 .clear = ath_rate_clear,
2096 .alloc = ath_rate_alloc,
2097 .free = ath_rate_free,
2098 .alloc_sta = ath_rate_alloc_sta,
4b7679a5 2099 .free_sta = ath_rate_free_sta,
f078f209
LR
2100};
2101
2102int ath_rate_control_register(void)
2103{
2104 return ieee80211_rate_control_register(&ath_rate_ops);
2105}
2106
2107void ath_rate_control_unregister(void)
2108{
2109 ieee80211_rate_control_unregister(&ath_rate_ops);
2110}
2111