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.
19 * Atheros rate control algorithm
23 #include "../net/mac80211/rate.h"
25 static u32 tx_triglevel_max
;
27 static struct ath_rate_table ar5416_11na_ratetable
= {
30 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 6000, /* 6 Mb */
32 0, 2, 1, 0, 0, 0, 0, 0 },
33 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 9000, /* 9 Mb */
35 0, 3, 1, 1, 1, 1, 1, 0 },
36 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 12 Mb */
37 10000, 0x0a, 0x00, 24,
38 2, 4, 2, 2, 2, 2, 2, 0 },
39 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 18000, /* 18 Mb */
40 13900, 0x0e, 0x00, 36,
41 2, 6, 2, 3, 3, 3, 3, 0 },
42 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 24000, /* 24 Mb */
43 17300, 0x09, 0x00, 48,
44 4, 10, 3, 4, 4, 4, 4, 0 },
45 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 36000, /* 36 Mb */
46 23000, 0x0d, 0x00, 72,
47 4, 14, 3, 5, 5, 5, 5, 0 },
48 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 48000, /* 48 Mb */
49 27400, 0x08, 0x00, 96,
50 4, 20, 3, 6, 6, 6, 6, 0 },
51 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 54000, /* 54 Mb */
52 29300, 0x0c, 0x00, 108,
53 4, 23, 3, 7, 7, 7, 7, 0 },
54 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 6500, /* 6.5 Mb */
56 0, 2, 3, 8, 24, 8, 24, 3216 },
57 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 13000, /* 13 Mb */
59 2, 4, 3, 9, 25, 9, 25, 6434 },
60 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 19500, /* 19.5 Mb */
62 2, 6, 3, 10, 26, 10, 26, 9650 },
63 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 26000, /* 26 Mb */
65 4, 10, 3, 11, 27, 11, 27, 12868 },
66 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 39000, /* 39 Mb */
68 4, 14, 3, 12, 28, 12, 28, 19304 },
69 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 52000, /* 52 Mb */
71 4, 20, 3, 13, 29, 13, 29, 25740 },
72 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 58500, /* 58.5 Mb */
74 4, 23, 3, 14, 30, 14, 30, 28956 },
75 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 65000, /* 65 Mb */
77 4, 25, 3, 15, 31, 15, 32, 32180 },
78 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 13000, /* 13 Mb */
80 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
81 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 26000, /* 26 Mb */
83 2, 4, 3, 17, 34, 17, 34, 12860 },
84 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 39000, /* 39 Mb */
85 36600, 0x8a, 0x00, 10,
86 2, 6, 3, 18, 35, 18, 35, 19300 },
87 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 52000, /* 52 Mb */
88 48100, 0x8b, 0x00, 11,
89 4, 10, 3, 19, 36, 19, 36, 25736 },
90 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 78000, /* 78 Mb */
91 69500, 0x8c, 0x00, 12,
92 4, 14, 3, 20, 37, 20, 37, 38600 },
93 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 104000, /* 104 Mb */
94 89500, 0x8d, 0x00, 13,
95 4, 20, 3, 21, 38, 21, 38, 51472 },
96 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 117000, /* 117 Mb */
97 98900, 0x8e, 0x00, 14,
98 4, 23, 3, 22, 39, 22, 39, 57890 },
99 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 130000, /* 130 Mb */
100 108300, 0x8f, 0x00, 15,
101 4, 25, 3, 23, 40, 23, 41, 64320 },
102 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 13500, /* 13.5 Mb */
103 13200, 0x80, 0x00, 0,
104 0, 2, 3, 8, 24, 24, 24, 6684 },
105 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 27500, /* 27.0 Mb */
106 25900, 0x81, 0x00, 1,
107 2, 4, 3, 9, 25, 25, 25, 13368 },
108 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 40500, /* 40.5 Mb */
109 38600, 0x82, 0x00, 2,
110 2, 6, 3, 10, 26, 26, 26, 20052 },
111 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 54000, /* 54 Mb */
112 49800, 0x83, 0x00, 3,
113 4, 10, 3, 11, 27, 27, 27, 26738 },
114 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 81500, /* 81 Mb */
115 72200, 0x84, 0x00, 4,
116 4, 14, 3, 12, 28, 28, 28, 40104 },
117 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 108000, /* 108 Mb */
118 92900, 0x85, 0x00, 5,
119 4, 20, 3, 13, 29, 29, 29, 53476 },
120 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 121500, /* 121.5 Mb */
121 102700, 0x86, 0x00, 6,
122 4, 23, 3, 14, 30, 30, 30, 60156 },
123 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 135000, /* 135 Mb */
124 112000, 0x87, 0x00, 7,
125 4, 25, 3, 15, 31, 32, 32, 66840 },
126 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS_HGI
, 150000, /* 150 Mb */
127 122000, 0x87, 0x00, 7,
128 4, 25, 3, 15, 31, 32, 32, 74200 },
129 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 27000, /* 27 Mb */
130 25800, 0x88, 0x00, 8,
131 0, 2, 3, 16, 33, 33, 33, 13360 },
132 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 54000, /* 54 Mb */
133 49800, 0x89, 0x00, 9,
134 2, 4, 3, 17, 34, 34, 34, 26720 },
135 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 81000, /* 81 Mb */
136 71900, 0x8a, 0x00, 10,
137 2, 6, 3, 18, 35, 35, 35, 40080 },
138 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 108000, /* 108 Mb */
139 92500, 0x8b, 0x00, 11,
140 4, 10, 3, 19, 36, 36, 36, 53440 },
141 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 162000, /* 162 Mb */
142 130300, 0x8c, 0x00, 12,
143 4, 14, 3, 20, 37, 37, 37, 80160 },
144 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 216000, /* 216 Mb */
145 162800, 0x8d, 0x00, 13,
146 4, 20, 3, 21, 38, 38, 38, 106880 },
147 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 243000, /* 243 Mb */
148 178200, 0x8e, 0x00, 14,
149 4, 23, 3, 22, 39, 39, 39, 120240 },
150 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 270000, /* 270 Mb */
151 192100, 0x8f, 0x00, 15,
152 4, 25, 3, 23, 40, 41, 41, 133600 },
153 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS_HGI
, 300000, /* 300 Mb */
154 207000, 0x8f, 0x00, 15,
155 4, 25, 3, 23, 40, 41, 41, 148400 },
157 50, /* probe interval */
158 50, /* rssi reduce interval */
159 WLAN_RC_HT_FLAG
, /* Phy rates allowed initially */
162 /* TRUE_ALL - valid for 20/40/Legacy,
163 * TRUE - Legacy only,
164 * TRUE_20 - HT 20 only,
165 * TRUE_40 - HT 40 only */
167 /* 4ms frame limit not used for NG mode. The values filled
168 * for HT are the 64K max aggregate limit */
170 static struct ath_rate_table ar5416_11ng_ratetable
= {
173 { TRUE_ALL
, TRUE_ALL
, WLAN_PHY_CCK
, 1000, /* 1 Mb */
175 0, 0, 1, 0, 0, 0, 0, 0 },
176 { TRUE_ALL
, TRUE_ALL
, WLAN_PHY_CCK
, 2000, /* 2 Mb */
178 1, 1, 1, 1, 1, 1, 1, 0 },
179 { TRUE_ALL
, TRUE_ALL
, WLAN_PHY_CCK
, 5500, /* 5.5 Mb */
180 4900, 0x19, 0x04, 11,
181 2, 2, 2, 2, 2, 2, 2, 0 },
182 { TRUE_ALL
, TRUE_ALL
, WLAN_PHY_CCK
, 11000, /* 11 Mb */
183 8100, 0x18, 0x04, 22,
184 3, 3, 2, 3, 3, 3, 3, 0 },
185 { FALSE
, FALSE
, WLAN_PHY_OFDM
, 6000, /* 6 Mb */
186 5400, 0x0b, 0x00, 12,
187 4, 2, 1, 4, 4, 4, 4, 0 },
188 { FALSE
, FALSE
, WLAN_PHY_OFDM
, 9000, /* 9 Mb */
189 7800, 0x0f, 0x00, 18,
190 4, 3, 1, 5, 5, 5, 5, 0 },
191 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 12 Mb */
192 10100, 0x0a, 0x00, 24,
193 6, 4, 1, 6, 6, 6, 6, 0 },
194 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 18000, /* 18 Mb */
195 14100, 0x0e, 0x00, 36,
196 6, 6, 2, 7, 7, 7, 7, 0 },
197 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 24000, /* 24 Mb */
198 17700, 0x09, 0x00, 48,
199 8, 10, 3, 8, 8, 8, 8, 0 },
200 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 36000, /* 36 Mb */
201 23700, 0x0d, 0x00, 72,
202 8, 14, 3, 9, 9, 9, 9, 0 },
203 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 48000, /* 48 Mb */
204 27400, 0x08, 0x00, 96,
205 8, 20, 3, 10, 10, 10, 10, 0 },
206 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 54000, /* 54 Mb */
207 30900, 0x0c, 0x00, 108,
208 8, 23, 3, 11, 11, 11, 11, 0 },
209 { FALSE
, FALSE
, WLAN_PHY_HT_20_SS
, 6500, /* 6.5 Mb */
211 4, 2, 3, 12, 28, 12, 28, 3216 },
212 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 13000, /* 13 Mb */
213 12700, 0x81, 0x00, 1,
214 6, 4, 3, 13, 29, 13, 29, 6434 },
215 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 19500, /* 19.5 Mb */
216 18800, 0x82, 0x00, 2,
217 6, 6, 3, 14, 30, 14, 30, 9650 },
218 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 26000, /* 26 Mb */
219 25000, 0x83, 0x00, 3,
220 8, 10, 3, 15, 31, 15, 31, 12868 },
221 { TRUE_20
, TRUE_20
, WLAN_PHY_HT_20_SS
, 39000, /* 39 Mb */
222 36700, 0x84, 0x00, 4,
223 8, 14, 3, 16, 32, 16, 32, 19304 },
224 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 52000, /* 52 Mb */
225 48100, 0x85, 0x00, 5,
226 8, 20, 3, 17, 33, 17, 33, 25740 },
227 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 58500, /* 58.5 Mb */
228 53500, 0x86, 0x00, 6,
229 8, 23, 3, 18, 34, 18, 34, 28956 },
230 { FALSE
, TRUE_20
, WLAN_PHY_HT_20_SS
, 65000, /* 65 Mb */
231 59000, 0x87, 0x00, 7,
232 8, 25, 3, 19, 35, 19, 36, 32180 },
233 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 13000, /* 13 Mb */
234 12700, 0x88, 0x00, 8,
235 4, 2, 3, 20, 37, 20, 37, 6430 },
236 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 26000, /* 26 Mb */
237 24800, 0x89, 0x00, 9,
238 6, 4, 3, 21, 38, 21, 38, 12860 },
239 { FALSE
, FALSE
, WLAN_PHY_HT_20_DS
, 39000, /* 39 Mb */
240 36600, 0x8a, 0x00, 10,
241 6, 6, 3, 22, 39, 22, 39, 19300 },
242 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 52000, /* 52 Mb */
243 48100, 0x8b, 0x00, 11,
244 8, 10, 3, 23, 40, 23, 40, 25736 },
245 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 78000, /* 78 Mb */
246 69500, 0x8c, 0x00, 12,
247 8, 14, 3, 24, 41, 24, 41, 38600 },
248 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 104000, /* 104 Mb */
249 89500, 0x8d, 0x00, 13,
250 8, 20, 3, 25, 42, 25, 42, 51472 },
251 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 117000, /* 117 Mb */
252 98900, 0x8e, 0x00, 14,
253 8, 23, 3, 26, 43, 26, 44, 57890 },
254 { TRUE_20
, FALSE
, WLAN_PHY_HT_20_DS
, 130000, /* 130 Mb */
255 108300, 0x8f, 0x00, 15,
256 8, 25, 3, 27, 44, 27, 45, 64320 },
257 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 13500, /* 13.5 Mb */
258 13200, 0x80, 0x00, 0,
259 8, 2, 3, 12, 28, 28, 28, 6684 },
260 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 27500, /* 27.0 Mb */
261 25900, 0x81, 0x00, 1,
262 8, 4, 3, 13, 29, 29, 29, 13368 },
263 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 40500, /* 40.5 Mb */
264 38600, 0x82, 0x00, 2,
265 8, 6, 3, 14, 30, 30, 30, 20052 },
266 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 54000, /* 54 Mb */
267 49800, 0x83, 0x00, 3,
268 8, 10, 3, 15, 31, 31, 31, 26738 },
269 { TRUE_40
, TRUE_40
, WLAN_PHY_HT_40_SS
, 81500, /* 81 Mb */
270 72200, 0x84, 0x00, 4,
271 8, 14, 3, 16, 32, 32, 32, 40104 },
272 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 108000, /* 108 Mb */
273 92900, 0x85, 0x00, 5,
274 8, 20, 3, 17, 33, 33, 33, 53476 },
275 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 121500, /* 121.5 Mb */
276 102700, 0x86, 0x00, 6,
277 8, 23, 3, 18, 34, 34, 34, 60156 },
278 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS
, 135000, /* 135 Mb */
279 112000, 0x87, 0x00, 7,
280 8, 23, 3, 19, 35, 36, 36, 66840 },
281 { FALSE
, TRUE_40
, WLAN_PHY_HT_40_SS_HGI
, 150000, /* 150 Mb */
282 122000, 0x87, 0x00, 7,
283 8, 25, 3, 19, 35, 36, 36, 74200 },
284 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 27000, /* 27 Mb */
285 25800, 0x88, 0x00, 8,
286 8, 2, 3, 20, 37, 37, 37, 13360 },
287 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 54000, /* 54 Mb */
288 49800, 0x89, 0x00, 9,
289 8, 4, 3, 21, 38, 38, 38, 26720 },
290 { FALSE
, FALSE
, WLAN_PHY_HT_40_DS
, 81000, /* 81 Mb */
291 71900, 0x8a, 0x00, 10,
292 8, 6, 3, 22, 39, 39, 39, 40080 },
293 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 108000, /* 108 Mb */
294 92500, 0x8b, 0x00, 11,
295 8, 10, 3, 23, 40, 40, 40, 53440 },
296 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 162000, /* 162 Mb */
297 130300, 0x8c, 0x00, 12,
298 8, 14, 3, 24, 41, 41, 41, 80160 },
299 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 216000, /* 216 Mb */
300 162800, 0x8d, 0x00, 13,
301 8, 20, 3, 25, 42, 42, 42, 106880 },
302 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 243000, /* 243 Mb */
303 178200, 0x8e, 0x00, 14,
304 8, 23, 3, 26, 43, 43, 43, 120240 },
305 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS
, 270000, /* 270 Mb */
306 192100, 0x8f, 0x00, 15,
307 8, 23, 3, 27, 44, 45, 45, 133600 },
308 { TRUE_40
, FALSE
, WLAN_PHY_HT_40_DS_HGI
, 300000, /* 300 Mb */
309 207000, 0x8f, 0x00, 15,
310 8, 25, 3, 27, 44, 45, 45, 148400 },
312 50, /* probe interval */
313 50, /* rssi reduce interval */
314 WLAN_RC_HT_FLAG
, /* Phy rates allowed initially */
317 static struct ath_rate_table ar5416_11a_ratetable
= {
320 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 6000, /* 6 Mb */
321 5400, 0x0b, 0x00, (0x80|12),
323 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 9000, /* 9 Mb */
324 7800, 0x0f, 0x00, 18,
326 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 12 Mb */
327 10000, 0x0a, 0x00, (0x80|24),
329 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 18000, /* 18 Mb */
330 13900, 0x0e, 0x00, 36,
332 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 24000, /* 24 Mb */
333 17300, 0x09, 0x00, (0x80|48),
335 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 36000, /* 36 Mb */
336 23000, 0x0d, 0x00, 72,
338 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 48000, /* 48 Mb */
339 27400, 0x08, 0x00, 96,
341 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 54000, /* 54 Mb */
342 29300, 0x0c, 0x00, 108,
345 50, /* probe interval */
346 50, /* rssi reduce interval */
347 0, /* Phy rates allowed initially */
350 static struct ath_rate_table ar5416_11a_ratetable_Half
= {
353 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 3000, /* 6 Mb */
354 2700, 0x0b, 0x00, (0x80|6),
356 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 4500, /* 9 Mb */
359 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 6000, /* 12 Mb */
360 5000, 0x0a, 0x00, (0x80|12),
362 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 9000, /* 18 Mb */
363 6950, 0x0e, 0x00, 18,
365 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 24 Mb */
366 8650, 0x09, 0x00, (0x80|24),
368 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 18000, /* 36 Mb */
369 11500, 0x0d, 0x00, 36,
371 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 24000, /* 48 Mb */
372 13700, 0x08, 0x00, 48,
374 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 27000, /* 54 Mb */
375 14650, 0x0c, 0x00, 54,
378 50, /* probe interval */
379 50, /* rssi reduce interval */
380 0, /* Phy rates allowed initially */
383 static struct ath_rate_table ar5416_11a_ratetable_Quarter
= {
386 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 1500, /* 6 Mb */
387 1350, 0x0b, 0x00, (0x80|3),
389 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 2250, /* 9 Mb */
392 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 3000, /* 12 Mb */
393 2500, 0x0a, 0x00, (0x80|6),
395 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 4500, /* 18 Mb */
398 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 6000, /* 25 Mb */
399 4325, 0x09, 0x00, (0x80|12),
401 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 9000, /* 36 Mb */
402 5750, 0x0d, 0x00, 18,
404 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 48 Mb */
405 6850, 0x08, 0x00, 24,
407 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 13500, /* 54 Mb */
408 7325, 0x0c, 0x00, 27,
411 50, /* probe interval */
412 50, /* rssi reduce interval */
413 0, /* Phy rates allowed initially */
416 static struct ath_rate_table ar5416_11g_ratetable
= {
419 { TRUE
, TRUE
, WLAN_PHY_CCK
, 1000, /* 1 Mb */
422 { TRUE
, TRUE
, WLAN_PHY_CCK
, 2000, /* 2 Mb */
425 { TRUE
, TRUE
, WLAN_PHY_CCK
, 5500, /* 5.5 Mb */
426 4900, 0x19, 0x04, 11,
428 { TRUE
, TRUE
, WLAN_PHY_CCK
, 11000, /* 11 Mb */
429 8100, 0x18, 0x04, 22,
431 { FALSE
, FALSE
, WLAN_PHY_OFDM
, 6000, /* 6 Mb */
432 5400, 0x0b, 0x00, 12,
434 { FALSE
, FALSE
, WLAN_PHY_OFDM
, 9000, /* 9 Mb */
435 7800, 0x0f, 0x00, 18,
437 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 12000, /* 12 Mb */
438 10000, 0x0a, 0x00, 24,
440 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 18000, /* 18 Mb */
441 13900, 0x0e, 0x00, 36,
443 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 24000, /* 24 Mb */
444 17300, 0x09, 0x00, 48,
446 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 36000, /* 36 Mb */
447 23000, 0x0d, 0x00, 72,
449 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 48000, /* 48 Mb */
450 27400, 0x08, 0x00, 96,
452 { TRUE
, TRUE
, WLAN_PHY_OFDM
, 54000, /* 54 Mb */
453 29300, 0x0c, 0x00, 108,
456 50, /* probe interval */
457 50, /* rssi reduce interval */
458 0, /* Phy rates allowed initially */
461 static struct ath_rate_table ar5416_11b_ratetable
= {
464 { TRUE
, TRUE
, WLAN_PHY_CCK
, 1000, /* 1 Mb */
465 900, 0x1b, 0x00, (0x80|2),
467 { TRUE
, TRUE
, WLAN_PHY_CCK
, 2000, /* 2 Mb */
468 1800, 0x1a, 0x04, (0x80|4),
470 { TRUE
, TRUE
, WLAN_PHY_CCK
, 5500, /* 5.5 Mb */
471 4300, 0x19, 0x04, (0x80|11),
473 { TRUE
, TRUE
, WLAN_PHY_CCK
, 11000, /* 11 Mb */
474 7100, 0x18, 0x04, (0x80|22),
477 100, /* probe interval */
478 100, /* rssi reduce interval */
479 0, /* Phy rates allowed initially */
482 static void ar5416_attach_ratetables(struct ath_rate_softc
*sc
)
485 * Attach rate tables.
487 sc
->hw_rate_table
[ATH9K_MODE_11B
] = &ar5416_11b_ratetable
;
488 sc
->hw_rate_table
[ATH9K_MODE_11A
] = &ar5416_11a_ratetable
;
489 sc
->hw_rate_table
[ATH9K_MODE_11G
] = &ar5416_11g_ratetable
;
491 sc
->hw_rate_table
[ATH9K_MODE_11NA_HT20
] = &ar5416_11na_ratetable
;
492 sc
->hw_rate_table
[ATH9K_MODE_11NG_HT20
] = &ar5416_11ng_ratetable
;
493 sc
->hw_rate_table
[ATH9K_MODE_11NA_HT40PLUS
] =
494 &ar5416_11na_ratetable
;
495 sc
->hw_rate_table
[ATH9K_MODE_11NA_HT40MINUS
] =
496 &ar5416_11na_ratetable
;
497 sc
->hw_rate_table
[ATH9K_MODE_11NG_HT40PLUS
] =
498 &ar5416_11ng_ratetable
;
499 sc
->hw_rate_table
[ATH9K_MODE_11NG_HT40MINUS
] =
500 &ar5416_11ng_ratetable
;
503 static void ar5416_setquarter_ratetable(struct ath_rate_softc
*sc
)
505 sc
->hw_rate_table
[ATH9K_MODE_11A
] = &ar5416_11a_ratetable_Quarter
;
509 static void ar5416_sethalf_ratetable(struct ath_rate_softc
*sc
)
511 sc
->hw_rate_table
[ATH9K_MODE_11A
] = &ar5416_11a_ratetable_Half
;
515 static void ar5416_setfull_ratetable(struct ath_rate_softc
*sc
)
517 sc
->hw_rate_table
[ATH9K_MODE_11A
] = &ar5416_11a_ratetable
;
522 * Return the median of three numbers
524 static inline int8_t median(int8_t a
, int8_t b
, int8_t c
)
543 static void ath_rc_sort_validrates(const struct ath_rate_table
*rate_table
,
544 struct ath_tx_ratectrl
*rate_ctrl
)
546 u8 i
, j
, idx
, idx_next
;
548 for (i
= rate_ctrl
->max_valid_rate
- 1; i
> 0; i
--) {
549 for (j
= 0; j
<= i
-1; j
++) {
550 idx
= rate_ctrl
->valid_rate_index
[j
];
551 idx_next
= rate_ctrl
->valid_rate_index
[j
+1];
553 if (rate_table
->info
[idx
].ratekbps
>
554 rate_table
->info
[idx_next
].ratekbps
) {
555 rate_ctrl
->valid_rate_index
[j
] = idx_next
;
556 rate_ctrl
->valid_rate_index
[j
+1] = idx
;
562 /* Access functions for valid_txrate_mask */
564 static void ath_rc_init_valid_txmask(struct ath_tx_ratectrl
*rate_ctrl
)
568 for (i
= 0; i
< rate_ctrl
->rate_table_size
; i
++)
569 rate_ctrl
->valid_rate_index
[i
] = FALSE
;
572 static inline void ath_rc_set_valid_txmask(struct ath_tx_ratectrl
*rate_ctrl
,
573 u8 index
, int valid_tx_rate
)
575 ASSERT(index
<= rate_ctrl
->rate_table_size
);
576 rate_ctrl
->valid_rate_index
[index
] = valid_tx_rate
? TRUE
: FALSE
;
579 static inline int ath_rc_isvalid_txmask(struct ath_tx_ratectrl
*rate_ctrl
,
582 ASSERT(index
<= rate_ctrl
->rate_table_size
);
583 return rate_ctrl
->valid_rate_index
[index
];
586 /* Iterators for valid_txrate_mask */
588 ath_rc_get_nextvalid_txrate(const struct ath_rate_table
*rate_table
,
589 struct ath_tx_ratectrl
*rate_ctrl
,
595 for (i
= 0; i
< rate_ctrl
->max_valid_rate
- 1; i
++) {
596 if (rate_ctrl
->valid_rate_index
[i
] == cur_valid_txrate
) {
597 *next_idx
= rate_ctrl
->valid_rate_index
[i
+1];
602 /* No more valid rates */
607 /* Return true only for single stream */
609 static int ath_rc_valid_phyrate(u32 phy
, u32 capflag
, int ignore_cw
)
611 if (WLAN_RC_PHY_HT(phy
) & !(capflag
& WLAN_RC_HT_FLAG
))
613 if (WLAN_RC_PHY_DS(phy
) && !(capflag
& WLAN_RC_DS_FLAG
))
615 if (WLAN_RC_PHY_SGI(phy
) && !(capflag
& WLAN_RC_SGI_FLAG
))
617 if (!ignore_cw
&& WLAN_RC_PHY_HT(phy
))
618 if (WLAN_RC_PHY_40(phy
) && !(capflag
& WLAN_RC_40_FLAG
))
620 if (!WLAN_RC_PHY_40(phy
) && (capflag
& WLAN_RC_40_FLAG
))
626 ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table
*rate_table
,
627 struct ath_tx_ratectrl
*rate_ctrl
,
628 u8 cur_valid_txrate
, u8
*next_idx
)
632 for (i
= 1; i
< rate_ctrl
->max_valid_rate
; i
++) {
633 if (rate_ctrl
->valid_rate_index
[i
] == cur_valid_txrate
) {
634 *next_idx
= rate_ctrl
->valid_rate_index
[i
-1];
642 * Initialize the Valid Rate Index from valid entries in Rate Table
645 ath_rc_sib_init_validrates(struct ath_rate_node
*ath_rc_priv
,
646 const struct ath_rate_table
*rate_table
,
649 struct ath_tx_ratectrl
*rate_ctrl
;
653 rate_ctrl
= (struct ath_tx_ratectrl
*)(ath_rc_priv
);
654 for (i
= 0; i
< rate_table
->rate_cnt
; i
++) {
655 valid
= (ath_rc_priv
->single_stream
?
656 rate_table
->info
[i
].valid_single_stream
:
657 rate_table
->info
[i
].valid
);
659 u32 phy
= rate_table
->info
[i
].phy
;
660 u8 valid_rate_count
= 0;
662 if (!ath_rc_valid_phyrate(phy
, capflag
, FALSE
))
665 valid_rate_count
= rate_ctrl
->valid_phy_ratecnt
[phy
];
667 rate_ctrl
->valid_phy_rateidx
[phy
][valid_rate_count
] = i
;
668 rate_ctrl
->valid_phy_ratecnt
[phy
] += 1;
669 ath_rc_set_valid_txmask(rate_ctrl
, i
, TRUE
);
677 * Initialize the Valid Rate Index from Rate Set
680 ath_rc_sib_setvalid_rates(struct ath_rate_node
*ath_rc_priv
,
681 const struct ath_rate_table
*rate_table
,
682 struct ath_rateset
*rateset
,
685 /* XXX: Clean me up and make identation friendly */
687 struct ath_tx_ratectrl
*rate_ctrl
=
688 (struct ath_tx_ratectrl
*)(ath_rc_priv
);
690 /* Use intersection of working rates and valid rates */
691 for (i
= 0; i
< rateset
->rs_nrates
; i
++) {
692 for (j
= 0; j
< rate_table
->rate_cnt
; j
++) {
693 u32 phy
= rate_table
->info
[j
].phy
;
694 u32 valid
= (ath_rc_priv
->single_stream
?
695 rate_table
->info
[j
].valid_single_stream
:
696 rate_table
->info
[j
].valid
);
698 /* We allow a rate only if its valid and the
699 * capflag matches one of the validity
700 * (TRUE/TRUE_20/TRUE_40) flags */
702 /* XXX: catch the negative of this branch
703 * first and then continue */
704 if (((rateset
->rs_rates
[i
] & 0x7F) ==
705 (rate_table
->info
[j
].dot11rate
& 0x7F)) &&
706 ((valid
& WLAN_RC_CAP_MODE(capflag
)) ==
707 WLAN_RC_CAP_MODE(capflag
)) &&
708 !WLAN_RC_PHY_HT(phy
)) {
710 u8 valid_rate_count
= 0;
712 if (!ath_rc_valid_phyrate(phy
, capflag
, FALSE
))
716 rate_ctrl
->valid_phy_ratecnt
[phy
];
718 rate_ctrl
->valid_phy_rateidx
[phy
]
719 [valid_rate_count
] = j
;
720 rate_ctrl
->valid_phy_ratecnt
[phy
] += 1;
721 ath_rc_set_valid_txmask(rate_ctrl
, j
, TRUE
);
730 ath_rc_sib_setvalid_htrates(struct ath_rate_node
*ath_rc_priv
,
731 const struct ath_rate_table
*rate_table
,
732 u8
*mcs_set
, u32 capflag
)
735 struct ath_tx_ratectrl
*rate_ctrl
=
736 (struct ath_tx_ratectrl
*)(ath_rc_priv
);
738 /* Use intersection of working rates and valid rates */
739 for (i
= 0; i
< ((struct ath_rateset
*)mcs_set
)->rs_nrates
; i
++) {
740 for (j
= 0; j
< rate_table
->rate_cnt
; j
++) {
741 u32 phy
= rate_table
->info
[j
].phy
;
742 u32 valid
= (ath_rc_priv
->single_stream
?
743 rate_table
->info
[j
].valid_single_stream
:
744 rate_table
->info
[j
].valid
);
746 if (((((struct ath_rateset
*)
747 mcs_set
)->rs_rates
[i
] & 0x7F) !=
748 (rate_table
->info
[j
].dot11rate
& 0x7F)) ||
749 !WLAN_RC_PHY_HT(phy
) ||
750 !WLAN_RC_PHY_HT_VALID(valid
, capflag
))
753 if (!ath_rc_valid_phyrate(phy
, capflag
, FALSE
))
756 rate_ctrl
->valid_phy_rateidx
[phy
]
757 [rate_ctrl
->valid_phy_ratecnt
[phy
]] = j
;
758 rate_ctrl
->valid_phy_ratecnt
[phy
] += 1;
759 ath_rc_set_valid_txmask(rate_ctrl
, j
, TRUE
);
767 * Attach to a device instance. Setup the public definition
768 * of how much per-node space we need and setup the private
769 * phy tables that have rate control parameters.
771 struct ath_rate_softc
*ath_rate_attach(struct ath_hal
*ah
)
773 struct ath_rate_softc
*asc
;
775 /* we are only in user context so we can sleep for memory */
776 asc
= kzalloc(sizeof(struct ath_rate_softc
), GFP_KERNEL
);
780 ar5416_attach_ratetables(asc
);
782 /* Save Maximum TX Trigger Level (used for 11n) */
783 tx_triglevel_max
= ah
->ah_caps
.tx_triglevel_max
;
784 /* return alias for ath_rate_softc * */
788 static struct ath_rate_node
*ath_rate_node_alloc(struct ath_vap
*avp
,
789 struct ath_rate_softc
*rsc
,
792 struct ath_rate_node
*anode
;
794 anode
= kzalloc(sizeof(struct ath_rate_node
), gfp
);
800 avp
->rc_node
= anode
;
805 static void ath_rate_node_free(struct ath_rate_node
*anode
)
811 void ath_rate_detach(struct ath_rate_softc
*asc
)
817 u8
ath_rate_findrateix(struct ath_softc
*sc
,
820 const struct ath_rate_table
*ratetable
;
821 struct ath_rate_softc
*rsc
= sc
->sc_rc
;
824 ratetable
= rsc
->hw_rate_table
[sc
->sc_curmode
];
826 if (WARN_ON(!ratetable
))
829 for (i
= 0; i
< ratetable
->rate_cnt
; i
++) {
830 if ((ratetable
->info
[i
].dot11rate
& 0x7f) == (dot11rate
& 0x7f))
838 * Update rate-control state on a device state change. When
839 * operating as a station this includes associate/reassociate
840 * with an AP. Otherwise this gets called, for example, when
841 * the we transition to run state when operating as an AP.
843 void ath_rate_newstate(struct ath_softc
*sc
, struct ath_vap
*avp
)
845 struct ath_rate_softc
*asc
= sc
->sc_rc
;
847 /* For half and quarter rate channles use different
850 if (sc
->sc_curchan
.channelFlags
& CHANNEL_HALF
)
851 ar5416_sethalf_ratetable(asc
);
852 else if (sc
->sc_curchan
.channelFlags
& CHANNEL_QUARTER
)
853 ar5416_setquarter_ratetable(asc
);
855 ar5416_setfull_ratetable(asc
);
857 if (avp
->av_config
.av_fixed_rateset
!= IEEE80211_FIXED_RATE_NONE
) {
859 sc
->sc_rixmap
[avp
->av_config
.av_fixed_rateset
& 0xff];
860 /* NB: check the fixed rate exists */
861 if (asc
->fixedrix
== 0xff)
862 asc
->fixedrix
= IEEE80211_FIXED_RATE_NONE
;
864 asc
->fixedrix
= IEEE80211_FIXED_RATE_NONE
;
868 static u8
ath_rc_ratefind_ht(struct ath_softc
*sc
,
869 struct ath_rate_node
*ath_rc_priv
,
870 const struct ath_rate_table
*rate_table
,
871 int probe_allowed
, int *is_probing
,
874 u32 dt
, best_thruput
, this_thruput
, now_msec
;
875 u8 rate
, next_rate
, best_rate
, maxindex
, minindex
;
876 int8_t rssi_last
, rssi_reduce
= 0, index
= 0;
877 struct ath_tx_ratectrl
*rate_ctrl
= NULL
;
879 rate_ctrl
= (struct ath_tx_ratectrl
*)(ath_rc_priv
?
880 (ath_rc_priv
) : NULL
);
884 rssi_last
= median(rate_ctrl
->rssi_last
,
885 rate_ctrl
->rssi_last_prev
,
886 rate_ctrl
->rssi_last_prev2
);
889 * Age (reduce) last ack rssi based on how old it is.
890 * The bizarre numbers are so the delta is 160msec,
891 * meaning we divide by 16.
892 * 0msec <= dt <= 25msec: don't derate
893 * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
894 * 185msec <= dt: derate by 10dB
897 now_msec
= jiffies_to_msecs(jiffies
);
898 dt
= now_msec
- rate_ctrl
->rssi_time
;
903 rssi_reduce
= (u8
)((dt
- 25) >> 4);
905 /* Now reduce rssi_last by rssi_reduce */
906 if (rssi_last
< rssi_reduce
)
909 rssi_last
-= rssi_reduce
;
912 * Now look up the rate in the rssi table and return it.
913 * If no rates match then we return 0 (lowest rate)
917 maxindex
= rate_ctrl
->max_valid_rate
-1;
920 best_rate
= minindex
;
923 * Try the higher rate first. It will reduce memory moving time
924 * if we have very good channel characteristics.
926 for (index
= maxindex
; index
>= minindex
; index
--) {
929 rate
= rate_ctrl
->valid_rate_index
[index
];
930 if (rate
> rate_ctrl
->rate_max_phy
)
934 * For TCP the average collision rate is around 11%,
935 * so we ignore PERs less than this. This is to
936 * prevent the rate we are currently using (whose
937 * PER might be in the 10-15 range because of TCP
938 * collisions) looking worse than the next lower
939 * rate whose PER has decayed close to 0. If we
940 * used to next lower rate, its PER would grow to
941 * 10-15 and we would be worse off then staying
942 * at the current rate.
944 per_thres
= rate_ctrl
->state
[rate
].per
;
948 this_thruput
= rate_table
->info
[rate
].user_ratekbps
*
951 if (best_thruput
<= this_thruput
) {
952 best_thruput
= this_thruput
;
959 /* if we are retrying for more than half the number
960 * of max retries, use the min rate for the next retry
963 rate
= rate_ctrl
->valid_rate_index
[minindex
];
965 rate_ctrl
->rssi_last_lookup
= rssi_last
;
968 * Must check the actual rate (ratekbps) to account for
969 * non-monoticity of 11g's rate table
972 if (rate
>= rate_ctrl
->rate_max_phy
&& probe_allowed
) {
973 rate
= rate_ctrl
->rate_max_phy
;
975 /* Probe the next allowed phy state */
976 /* FIXME:XXXX Check to make sure ratMax is checked properly */
977 if (ath_rc_get_nextvalid_txrate(rate_table
,
978 rate_ctrl
, rate
, &next_rate
) &&
979 (now_msec
- rate_ctrl
->probe_time
>
980 rate_table
->probe_interval
) &&
981 (rate_ctrl
->hw_maxretry_pktcnt
>= 1)) {
983 rate_ctrl
->probe_rate
= rate
;
984 rate_ctrl
->probe_time
= now_msec
;
985 rate_ctrl
->hw_maxretry_pktcnt
= 0;
991 * Make sure rate is not higher than the allowed maximum.
992 * We should also enforce the min, but I suspect the min is
993 * normally 1 rather than 0 because of the rate 9 vs 6 issue
996 if (rate
> (rate_ctrl
->rate_table_size
- 1))
997 rate
= rate_ctrl
->rate_table_size
- 1;
999 ASSERT((rate_table
->info
[rate
].valid
&& !ath_rc_priv
->single_stream
) ||
1000 (rate_table
->info
[rate
].valid_single_stream
&&
1001 ath_rc_priv
->single_stream
));
1006 static void ath_rc_rate_set_series(const struct ath_rate_table
*rate_table
,
1007 struct ath_rc_series
*series
,
1012 series
->tries
= tries
;
1013 series
->flags
= (rtsctsenable
? ATH_RC_RTSCTS_FLAG
: 0) |
1014 (WLAN_RC_PHY_DS(rate_table
->info
[rix
].phy
) ?
1015 ATH_RC_DS_FLAG
: 0) |
1016 (WLAN_RC_PHY_40(rate_table
->info
[rix
].phy
) ?
1017 ATH_RC_CW40_FLAG
: 0) |
1018 (WLAN_RC_PHY_SGI(rate_table
->info
[rix
].phy
) ?
1019 ATH_RC_SGI_FLAG
: 0);
1021 series
->rix
= rate_table
->info
[rix
].base_index
;
1022 series
->max_4ms_framelen
= rate_table
->info
[rix
].max_4ms_framelen
;
1025 static u8
ath_rc_rate_getidx(struct ath_softc
*sc
,
1026 struct ath_rate_node
*ath_rc_priv
,
1027 const struct ath_rate_table
*rate_table
,
1028 u8 rix
, u16 stepdown
,
1033 struct ath_tx_ratectrl
*rate_ctrl
=
1034 (struct ath_tx_ratectrl
*)(ath_rc_priv
);
1037 for (j
= RATE_TABLE_SIZE
; j
> 0; j
--) {
1038 if (ath_rc_get_nextlowervalid_txrate(rate_table
,
1039 rate_ctrl
, rix
, &nextindex
))
1045 for (j
= stepdown
; j
> 0; j
--) {
1046 if (ath_rc_get_nextlowervalid_txrate(rate_table
,
1047 rate_ctrl
, rix
, &nextindex
))
1056 static void ath_rc_ratefind(struct ath_softc
*sc
,
1057 struct ath_rate_node
*ath_rc_priv
,
1058 int num_tries
, int num_rates
, unsigned int rcflag
,
1059 struct ath_rc_series series
[], int *is_probe
,
1062 u8 try_per_rate
= 0, i
= 0, rix
, nrix
;
1063 struct ath_rate_softc
*asc
= (struct ath_rate_softc
*)sc
->sc_rc
;
1064 struct ath_rate_table
*rate_table
;
1067 (struct ath_rate_table
*)asc
->hw_rate_table
[sc
->sc_curmode
];
1068 rix
= ath_rc_ratefind_ht(sc
, ath_rc_priv
, rate_table
,
1069 (rcflag
& ATH_RC_PROBE_ALLOWED
) ? 1 : 0,
1070 is_probe
, is_retry
);
1073 if ((rcflag
& ATH_RC_PROBE_ALLOWED
) && (*is_probe
)) {
1074 /* set one try for probe rates. For the
1075 * probes don't enable rts */
1076 ath_rc_rate_set_series(rate_table
,
1077 &series
[i
++], 1, nrix
, FALSE
);
1079 try_per_rate
= (num_tries
/num_rates
);
1080 /* Get the next tried/allowed rate. No RTS for the next series
1081 * after the probe rate
1083 nrix
= ath_rc_rate_getidx(sc
,
1084 ath_rc_priv
, rate_table
, nrix
, 1, FALSE
);
1085 ath_rc_rate_set_series(rate_table
,
1086 &series
[i
++], try_per_rate
, nrix
, 0);
1088 try_per_rate
= (num_tries
/num_rates
);
1089 /* Set the choosen rate. No RTS for first series entry. */
1090 ath_rc_rate_set_series(rate_table
,
1091 &series
[i
++], try_per_rate
, nrix
, FALSE
);
1094 /* Fill in the other rates for multirate retry */
1095 for ( ; i
< num_rates
; i
++) {
1099 try_num
= ((i
+ 1) == num_rates
) ?
1100 num_tries
- (try_per_rate
* i
) : try_per_rate
;
1101 min_rate
= (((i
+ 1) == num_rates
) &&
1102 (rcflag
& ATH_RC_MINRATE_LASTRATE
)) ? 1 : 0;
1104 nrix
= ath_rc_rate_getidx(sc
, ath_rc_priv
,
1105 rate_table
, nrix
, 1, min_rate
);
1106 /* All other rates in the series have RTS enabled */
1107 ath_rc_rate_set_series(rate_table
,
1108 &series
[i
], try_num
, nrix
, TRUE
);
1112 * NB:Change rate series to enable aggregation when operating
1113 * at lower MCS rates. When first rate in series is MCS2
1114 * in HT40 @ 2.4GHz, series should look like:
1116 * {MCS2, MCS1, MCS0, MCS0}.
1118 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
1121 * {MCS3, MCS2, MCS1, MCS1}
1123 * So, set fourth rate in series to be same as third one for
1126 if ((sc
->sc_curmode
== ATH9K_MODE_11NG_HT20
) ||
1127 (sc
->sc_curmode
== ATH9K_MODE_11NG_HT40PLUS
) ||
1128 (sc
->sc_curmode
== ATH9K_MODE_11NG_HT40MINUS
)) {
1129 u8 dot11rate
= rate_table
->info
[rix
].dot11rate
;
1130 u8 phy
= rate_table
->info
[rix
].phy
;
1132 ((dot11rate
== 2 && phy
== WLAN_RC_PHY_HT_40_SS
) ||
1133 (dot11rate
== 3 && phy
== WLAN_RC_PHY_HT_20_SS
))) {
1134 series
[3].rix
= series
[2].rix
;
1135 series
[3].flags
= series
[2].flags
;
1136 series
[3].max_4ms_framelen
= series
[2].max_4ms_framelen
;
1142 * Return the Tx rate series.
1144 void ath_rate_findrate(struct ath_softc
*sc
,
1145 struct ath_rate_node
*ath_rc_priv
,
1148 unsigned int rcflag
,
1149 struct ath_rc_series series
[],
1153 struct ath_vap
*avp
= ath_rc_priv
->avp
;
1155 DPRINTF(sc
, ATH_DBG_RATE
, "%s", __func__
);
1156 if (!num_rates
|| !num_tries
)
1159 if (avp
->av_config
.av_fixed_rateset
== IEEE80211_FIXED_RATE_NONE
) {
1160 ath_rc_ratefind(sc
, ath_rc_priv
, num_tries
, num_rates
,
1161 rcflag
, series
, is_probe
, is_retry
);
1167 struct ath_rate_softc
*asc
= ath_rc_priv
->asc
;
1168 struct ath_rate_table
*rate_table
;
1170 rate_table
= (struct ath_rate_table
*)
1171 asc
->hw_rate_table
[sc
->sc_curmode
];
1173 for (idx
= 0; idx
< 4; idx
++) {
1178 IEEE80211_RATE_IDX_ENTRY(
1179 avp
->av_config
.av_fixed_retryset
, idx
);
1181 mcs
= IEEE80211_RATE_IDX_ENTRY(
1182 avp
->av_config
.av_fixed_rateset
, idx
);
1184 if (idx
== 3 && (mcs
& 0xf0) == 0x70)
1185 mcs
= (mcs
& ~0xf0)|0x80;
1190 flags
= ((ath_rc_priv
->ht_cap
&
1192 ATH_RC_DS_FLAG
: 0) |
1193 ((ath_rc_priv
->ht_cap
&
1195 ATH_RC_CW40_FLAG
: 0) |
1196 ((ath_rc_priv
->ht_cap
&
1198 ((ath_rc_priv
->ht_cap
&
1200 ATH_RC_SGI_FLAG
: 0) : 0);
1202 series
[idx
].rix
= sc
->sc_rixmap
[mcs
];
1203 series_rix
= series
[idx
].rix
;
1205 /* XXX: Give me some cleanup love */
1206 if ((flags
& ATH_RC_CW40_FLAG
) &&
1207 (flags
& ATH_RC_SGI_FLAG
))
1208 rix
= rate_table
->info
[series_rix
].ht_index
;
1209 else if (flags
& ATH_RC_SGI_FLAG
)
1210 rix
= rate_table
->info
[series_rix
].sgi_index
;
1211 else if (flags
& ATH_RC_CW40_FLAG
)
1212 rix
= rate_table
->info
[series_rix
].cw40index
;
1214 rix
= rate_table
->info
[series_rix
].base_index
;
1215 series
[idx
].max_4ms_framelen
=
1216 rate_table
->info
[rix
].max_4ms_framelen
;
1217 series
[idx
].flags
= flags
;
1222 static void ath_rc_update_ht(struct ath_softc
*sc
,
1223 struct ath_rate_node
*ath_rc_priv
,
1224 struct ath_tx_info_priv
*info_priv
,
1225 int tx_rate
, int xretries
, int retries
)
1227 struct ath_tx_ratectrl
*rate_ctrl
;
1228 u32 now_msec
= jiffies_to_msecs(jiffies
);
1229 int state_change
= FALSE
, rate
, count
;
1231 struct ath_rate_softc
*asc
= (struct ath_rate_softc
*)sc
->sc_rc
;
1232 struct ath_rate_table
*rate_table
=
1233 (struct ath_rate_table
*)asc
->hw_rate_table
[sc
->sc_curmode
];
1235 static u32 nretry_to_per_lookup
[10] = {
1251 rate_ctrl
= (struct ath_tx_ratectrl
*)(ath_rc_priv
);
1253 ASSERT(tx_rate
>= 0);
1257 /* To compensate for some imbalance between ctrl and ext. channel */
1259 if (WLAN_RC_PHY_40(rate_table
->info
[tx_rate
].phy
))
1260 info_priv
->tx
.ts_rssi
=
1261 info_priv
->tx
.ts_rssi
< 3 ? 0 :
1262 info_priv
->tx
.ts_rssi
- 3;
1264 last_per
= rate_ctrl
->state
[tx_rate
].per
;
1267 /* Update the PER. */
1268 if (xretries
== 1) {
1269 rate_ctrl
->state
[tx_rate
].per
+= 30;
1270 if (rate_ctrl
->state
[tx_rate
].per
> 100)
1271 rate_ctrl
->state
[tx_rate
].per
= 100;
1274 count
= sizeof(nretry_to_per_lookup
) /
1275 sizeof(nretry_to_per_lookup
[0]);
1276 if (retries
>= count
)
1277 retries
= count
- 1;
1278 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
1279 rate_ctrl
->state
[tx_rate
].per
=
1280 (u8
)(rate_ctrl
->state
[tx_rate
].per
-
1281 (rate_ctrl
->state
[tx_rate
].per
>> 3) +
1285 /* xretries == 1 or 2 */
1287 if (rate_ctrl
->probe_rate
== tx_rate
)
1288 rate_ctrl
->probe_rate
= 0;
1290 } else { /* xretries == 0 */
1291 /* Update the PER. */
1292 /* Make sure it doesn't index out of array's bounds. */
1293 count
= sizeof(nretry_to_per_lookup
) /
1294 sizeof(nretry_to_per_lookup
[0]);
1295 if (retries
>= count
)
1296 retries
= count
- 1;
1297 if (info_priv
->n_bad_frames
) {
1298 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
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.
1311 if (info_priv
->n_frames
> 0)
1312 rate_ctrl
->state
[tx_rate
].per
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));
1321 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
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));
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
;
1335 * If we got at most one retry then increase the max rate if
1336 * this was a probe. Otherwise, ignore the probe.
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
) {
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.
1349 rate_ctrl
->probe_rate
= 0;
1353 rate_ctrl
->rate_max_phy
= rate_ctrl
->probe_rate
;
1354 probe_rate
= rate_ctrl
->probe_rate
;
1356 if (rate_ctrl
->state
[probe_rate
].per
> 30)
1357 rate_ctrl
->state
[probe_rate
].per
= 20;
1359 rate_ctrl
->probe_rate
= 0;
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
1367 rate_ctrl
->probe_time
= now_msec
-
1368 rate_table
->probe_interval
/ 2;
1374 * Don't update anything. We don't know if
1375 * this was because of collisions or poor signal.
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.
1382 rate_ctrl
->hw_maxretry_pktcnt
= 0;
1385 * It worked with no retries. First ignore bogus (small)
1388 if (tx_rate
== rate_ctrl
->rate_max_phy
&&
1389 rate_ctrl
->hw_maxretry_pktcnt
< 255) {
1390 rate_ctrl
->hw_maxretry_pktcnt
++;
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;
1402 rate_ctrl
->rssi_sum
+= info_priv
->tx
.ts_rssi
;
1403 rate_ctrl
->rssi_sum_cnt
++;
1405 if (rate_ctrl
->rssi_sum_cnt
> 4) {
1406 int32_t rssi_ackAvg
=
1407 (rate_ctrl
->rssi_sum
+ 2) / 4;
1409 rate_ctrl
->state
[tx_rate
].
1411 int8_t rssi_ack_vmin
=
1412 rate_table
->info
[tx_rate
].
1415 rate_ctrl
->rssi_sum
=
1416 rate_ctrl
->rssi_sum_cnt
= 0;
1418 /* Now reduce the current
1419 * rssi threshold. */
1420 if ((rssi_ackAvg
< rssi_thres
+ 2) &&
1421 (rssi_thres
> rssi_ack_vmin
)) {
1422 rate_ctrl
->state
[tx_rate
].
1426 state_change
= TRUE
;
1435 * If this rate looks bad (high PER) then stop using it for
1436 * a while (except if we are probing).
1438 if (rate_ctrl
->state
[tx_rate
].per
>= 55 && tx_rate
> 0 &&
1439 rate_table
->info
[tx_rate
].ratekbps
<=
1440 rate_table
->info
[rate_ctrl
->rate_max_phy
].ratekbps
) {
1441 ath_rc_get_nextlowervalid_txrate(rate_table
, rate_ctrl
,
1442 (u8
) tx_rate
, &rate_ctrl
->rate_max_phy
);
1444 /* Don't probe for a little while. */
1445 rate_ctrl
->probe_time
= now_msec
;
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.)
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
)
1462 if (rate_ctrl
->state
[rate
].rssi_thres
+
1463 rate_table
->info
[rate
].rssi_ack_deltamin
>
1464 rate_ctrl
->state
[rate
+1].rssi_thres
) {
1465 rate_ctrl
->state
[rate
+1].rssi_thres
=
1466 rate_ctrl
->state
[rate
].
1468 rate_table
->info
[rate
].
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
!=
1476 rate_table
->info
[tx_rate
].phy
)
1479 if (rate_ctrl
->state
[rate
].rssi_thres
+
1480 rate_table
->info
[rate
].rssi_ack_deltamin
>
1481 rate_ctrl
->state
[rate
+1].rssi_thres
) {
1482 if (rate_ctrl
->state
[rate
+1].rssi_thres
<
1483 rate_table
->info
[rate
].
1485 rate_ctrl
->state
[rate
].rssi_thres
= 0;
1487 rate_ctrl
->state
[rate
].rssi_thres
=
1488 rate_ctrl
->state
[rate
+1].
1490 rate_table
->info
[rate
].
1494 if (rate_ctrl
->state
[rate
].rssi_thres
<
1495 rate_table
->info
[rate
].
1496 rssi_ack_validmin
) {
1497 rate_ctrl
->state
[rate
].rssi_thres
=
1498 rate_table
->info
[rate
].
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
!=
1510 rate_table
->info
[tx_rate
].phy
)
1513 if (rate_ctrl
->state
[rate
].per
>
1514 rate_ctrl
->state
[rate
+1].per
) {
1515 rate_ctrl
->state
[rate
].per
=
1516 rate_ctrl
->state
[rate
+1].per
;
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
;
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
>=
1531 rate_table
->rssi_reduce_interval
) {
1533 for (rate
= 0; rate
< rate_ctrl
->rate_table_size
; rate
++) {
1534 if (rate_ctrl
->state
[rate
].rssi_thres
>
1535 rate_table
->info
[rate
].rssi_ack_validmin
)
1536 rate_ctrl
->state
[rate
].rssi_thres
-= 1;
1538 rate_ctrl
->rssi_down_time
= now_msec
;
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
>=
1544 rate_table
->rssi_reduce_interval
) {
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;
1550 rate_ctrl
->per_down_time
= now_msec
;
1555 * This routine is called in rate control callback tx_status() to give
1556 * the status of previous frames.
1558 static 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
)
1563 struct ath_rate_softc
*asc
= (struct ath_rate_softc
*)sc
->sc_rc
;
1564 struct ath_rate_table
*rate_table
;
1565 struct ath_tx_ratectrl
*rate_ctrl
;
1566 struct ath_rc_series rcs
[4];
1568 u32 series
= 0, rix
;
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);
1577 * If the first rate is not the final index, there
1578 * are intermediate rate failures to be processed.
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
)))
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
;
1602 rix
= rate_table
->info
[
1603 rcs
[series
].rix
].base_index
;
1604 ath_rc_update_ht(sc
, ath_rc_priv
,
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
1617 if (rcs
[0].tries
== 1 && xretries
== 1)
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
)))
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
;
1634 rix
= rate_table
->info
[rcs
[series
].rix
].base_index
;
1636 ath_rc_update_ht(sc
, ath_rc_priv
, info_priv
, rix
,
1637 xretries
, long_retry
);
1642 * Process a tx descriptor for a completed transmit (success or failure).
1644 static void ath_rate_tx_complete(struct ath_softc
*sc
,
1645 struct ath_node
*an
,
1646 struct ath_rate_node
*rc_priv
,
1647 struct ath_tx_info_priv
*info_priv
)
1649 int final_ts_idx
= info_priv
->tx
.ts_rateindex
;
1650 int tx_status
= 0, is_underrun
= 0;
1651 struct ath_vap
*avp
;
1654 if ((avp
->av_config
.av_fixed_rateset
!= IEEE80211_FIXED_RATE_NONE
)
1655 || info_priv
->tx
.ts_status
& ATH9K_TXERR_FILT
)
1658 if (info_priv
->tx
.ts_rssi
> 0) {
1659 ATH_RSSI_LPF(an
->an_chainmask_sel
.tx_avgrssi
,
1660 info_priv
->tx
.ts_rssi
);
1664 * If underrun error is seen assume it as an excessive retry only
1665 * if prefetch trigger level have reached the max (0x3f for 5416)
1666 * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
1667 * times. This affects how ratectrl updates PER for the failed rate.
1669 if (info_priv
->tx
.ts_flags
&
1670 (ATH9K_TX_DATA_UNDERRUN
| ATH9K_TX_DELIM_UNDERRUN
) &&
1671 ((sc
->sc_ah
->ah_txTrigLevel
) >= tx_triglevel_max
)) {
1676 if ((info_priv
->tx
.ts_status
& ATH9K_TXERR_XRETRY
) ||
1677 (info_priv
->tx
.ts_status
& ATH9K_TXERR_FIFO
))
1680 ath_rc_update(sc
, rc_priv
, info_priv
, final_ts_idx
, tx_status
,
1681 (is_underrun
) ? ATH_11N_TXMAXTRY
:
1682 info_priv
->tx
.ts_longretry
);
1687 * Update the SIB's rate control information
1689 * This should be called when the supported rates change
1690 * (e.g. SME operation, wireless mode change)
1692 * It will determine which rates are valid for use.
1694 static void ath_rc_sib_update(struct ath_softc
*sc
,
1695 struct ath_rate_node
*ath_rc_priv
,
1696 u32 capflag
, int keep_state
,
1697 struct ath_rateset
*negotiated_rates
,
1698 struct ath_rateset
*negotiated_htrates
)
1700 struct ath_rate_table
*rate_table
= NULL
;
1701 struct ath_rate_softc
*asc
= (struct ath_rate_softc
*)sc
->sc_rc
;
1702 struct ath_rateset
*rateset
= negotiated_rates
;
1703 u8
*ht_mcs
= (u8
*)negotiated_htrates
;
1704 struct ath_tx_ratectrl
*rate_ctrl
= (struct ath_tx_ratectrl
*)
1706 u8 i
, j
, k
, hi
= 0, hthi
= 0;
1708 rate_table
= (struct ath_rate_table
*)
1709 asc
->hw_rate_table
[sc
->sc_curmode
];
1711 /* Initial rate table size. Will change depending
1712 * on the working rate set */
1713 rate_ctrl
->rate_table_size
= MAX_TX_RATE_TBL
;
1715 /* Initialize thresholds according to the global rate table */
1716 for (i
= 0 ; (i
< rate_ctrl
->rate_table_size
) && (!keep_state
); i
++) {
1717 rate_ctrl
->state
[i
].rssi_thres
=
1718 rate_table
->info
[i
].rssi_ack_validmin
;
1719 rate_ctrl
->state
[i
].per
= 0;
1722 /* Determine the valid rates */
1723 ath_rc_init_valid_txmask(rate_ctrl
);
1725 for (i
= 0; i
< WLAN_RC_PHY_MAX
; i
++) {
1726 for (j
= 0; j
< MAX_TX_RATE_PHY
; j
++)
1727 rate_ctrl
->valid_phy_rateidx
[i
][j
] = 0;
1728 rate_ctrl
->valid_phy_ratecnt
[i
] = 0;
1730 rate_ctrl
->rc_phy_mode
= (capflag
& WLAN_RC_40_FLAG
);
1732 /* Set stream capability */
1733 ath_rc_priv
->single_stream
= (capflag
& WLAN_RC_DS_FLAG
) ? 0 : 1;
1735 if (!rateset
->rs_nrates
) {
1736 /* No working rate, just initialize valid rates */
1737 hi
= ath_rc_sib_init_validrates(ath_rc_priv
, rate_table
,
1740 /* Use intersection of working rates and valid rates */
1741 hi
= ath_rc_sib_setvalid_rates(ath_rc_priv
, rate_table
,
1743 if (capflag
& WLAN_RC_HT_FLAG
) {
1744 hthi
= ath_rc_sib_setvalid_htrates(ath_rc_priv
,
1749 hi
= A_MAX(hi
, hthi
);
1752 rate_ctrl
->rate_table_size
= hi
+ 1;
1753 rate_ctrl
->rate_max_phy
= 0;
1754 ASSERT(rate_ctrl
->rate_table_size
<= MAX_TX_RATE_TBL
);
1756 for (i
= 0, k
= 0; i
< WLAN_RC_PHY_MAX
; i
++) {
1757 for (j
= 0; j
< rate_ctrl
->valid_phy_ratecnt
[i
]; j
++) {
1758 rate_ctrl
->valid_rate_index
[k
++] =
1759 rate_ctrl
->valid_phy_rateidx
[i
][j
];
1762 if (!ath_rc_valid_phyrate(i
, rate_table
->initial_ratemax
, TRUE
)
1763 || !rate_ctrl
->valid_phy_ratecnt
[i
])
1766 rate_ctrl
->rate_max_phy
= rate_ctrl
->valid_phy_rateidx
[i
][j
-1];
1768 ASSERT(rate_ctrl
->rate_table_size
<= MAX_TX_RATE_TBL
);
1769 ASSERT(k
<= MAX_TX_RATE_TBL
);
1771 rate_ctrl
->max_valid_rate
= k
;
1773 * Some third party vendors don't send the supported rate series in
1774 * order. So sorting to make sure its in order, otherwise our RateFind
1775 * Algo will select wrong rates
1777 ath_rc_sort_validrates(rate_table
, rate_ctrl
);
1778 rate_ctrl
->rate_max_phy
= rate_ctrl
->valid_rate_index
[k
-4];
1782 * Update rate-control state on station associate/reassociate.
1784 static int ath_rate_newassoc(struct ath_softc
*sc
,
1785 struct ath_rate_node
*ath_rc_priv
,
1786 unsigned int capflag
,
1787 struct ath_rateset
*negotiated_rates
,
1788 struct ath_rateset
*negotiated_htrates
)
1792 ath_rc_priv
->ht_cap
=
1793 ((capflag
& ATH_RC_DS_FLAG
) ? WLAN_RC_DS_FLAG
: 0) |
1794 ((capflag
& ATH_RC_SGI_FLAG
) ? WLAN_RC_SGI_FLAG
: 0) |
1795 ((capflag
& ATH_RC_HT_FLAG
) ? WLAN_RC_HT_FLAG
: 0) |
1796 ((capflag
& ATH_RC_CW40_FLAG
) ? WLAN_RC_40_FLAG
: 0);
1798 ath_rc_sib_update(sc
, ath_rc_priv
, ath_rc_priv
->ht_cap
, 0,
1799 negotiated_rates
, negotiated_htrates
);
1805 * This routine is called to initialize the rate control parameters
1806 * in the SIB. It is called initially during system initialization
1807 * or when a station is associated with the AP.
1809 static void ath_rc_sib_init(struct ath_rate_node
*ath_rc_priv
)
1811 struct ath_tx_ratectrl
*rate_ctrl
;
1813 rate_ctrl
= (struct ath_tx_ratectrl
*)(ath_rc_priv
);
1814 rate_ctrl
->rssi_down_time
= jiffies_to_msecs(jiffies
);
1818 static void ath_setup_rates(struct ieee80211_local
*local
, struct sta_info
*sta
)
1821 struct ieee80211_supported_band
*sband
;
1822 struct ieee80211_hw
*hw
= local_to_hw(local
);
1823 struct ath_softc
*sc
= hw
->priv
;
1824 struct ath_rate_node
*rc_priv
= sta
->rate_ctrl_priv
;
1827 DPRINTF(sc
, ATH_DBG_RATE
, "%s", __func__
);
1828 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1829 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1830 if (sta
->supp_rates
[local
->hw
.conf
.channel
->band
] & BIT(i
)) {
1831 rc_priv
->neg_rates
.rs_rates
[j
]
1832 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
1836 rc_priv
->neg_rates
.rs_nrates
= j
;
1839 void ath_rc_node_update(struct ieee80211_hw
*hw
, struct ath_rate_node
*rc_priv
)
1841 struct ath_softc
*sc
= hw
->priv
;
1844 if (hw
->conf
.ht_conf
.ht_supported
) {
1845 capflag
|= ATH_RC_HT_FLAG
| ATH_RC_DS_FLAG
;
1846 if (sc
->sc_ht_info
.tx_chan_width
== ATH9K_HT_MACMODE_2040
)
1847 capflag
|= ATH_RC_CW40_FLAG
;
1850 ath_rate_newassoc(sc
, rc_priv
, capflag
,
1851 &rc_priv
->neg_rates
,
1852 &rc_priv
->neg_ht_rates
);
1856 /* Rate Control callbacks */
1857 static void ath_tx_status(void *priv
, struct net_device
*dev
,
1858 struct sk_buff
*skb
)
1860 struct ath_softc
*sc
= priv
;
1861 struct ath_tx_info_priv
*tx_info_priv
;
1862 struct ath_node
*an
;
1863 struct sta_info
*sta
;
1864 struct ieee80211_local
*local
;
1865 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1866 struct ieee80211_hdr
*hdr
;
1869 local
= hw_to_local(sc
->hw
);
1870 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1871 fc
= hdr
->frame_control
;
1872 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
1874 spin_lock_bh(&sc
->node_lock
);
1875 an
= ath_node_find(sc
, hdr
->addr1
);
1876 spin_unlock_bh(&sc
->node_lock
);
1878 sta
= sta_info_get(local
, hdr
->addr1
);
1879 if (!an
|| !sta
|| !ieee80211_is_data(fc
)) {
1880 if (tx_info
->driver_data
[0] != NULL
) {
1881 kfree(tx_info
->driver_data
[0]);
1882 tx_info
->driver_data
[0] = NULL
;
1886 if (tx_info
->driver_data
[0] != NULL
) {
1887 ath_rate_tx_complete(sc
, an
, sta
->rate_ctrl_priv
, tx_info_priv
);
1888 kfree(tx_info
->driver_data
[0]);
1889 tx_info
->driver_data
[0] = NULL
;
1893 static void ath_tx_aggr_resp(struct ath_softc
*sc
,
1894 struct sta_info
*sta
,
1895 struct ath_node
*an
,
1898 struct ieee80211_hw
*hw
= sc
->hw
;
1899 struct ieee80211_local
*local
;
1900 struct ath_atx_tid
*txtid
;
1901 struct ieee80211_supported_band
*sband
;
1904 DECLARE_MAC_BUF(mac
);
1909 txtid
= ATH_AN_2_TID(an
, tidno
);
1913 local
= hw_to_local(sc
->hw
);
1914 sband
= hw
->wiphy
->bands
[hw
->conf
.channel
->band
];
1915 buffersize
= IEEE80211_MIN_AMPDU_BUF
<<
1916 sband
->ht_info
.ampdu_factor
; /* FIXME */
1917 state
= sta
->ampdu_mlme
.tid_state_tx
[tidno
];
1919 if (state
& HT_ADDBA_RECEIVED_MSK
) {
1920 txtid
->addba_exchangecomplete
= 1;
1921 txtid
->addba_exchangeinprogress
= 0;
1922 txtid
->baw_size
= buffersize
;
1924 DPRINTF(sc
, ATH_DBG_AGGR
,
1925 "%s: Resuming tid, buffersize: %d\n",
1929 ath_tx_resume_tid(sc
, txtid
);
1933 static void ath_get_rate(void *priv
, struct net_device
*dev
,
1934 struct ieee80211_supported_band
*sband
,
1935 struct sk_buff
*skb
,
1936 struct rate_selection
*sel
)
1938 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1939 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1940 struct sta_info
*sta
;
1941 struct ath_softc
*sc
= (struct ath_softc
*)priv
;
1942 struct ieee80211_hw
*hw
= sc
->hw
;
1943 struct ath_tx_info_priv
*tx_info_priv
;
1944 struct ath_rate_node
*ath_rc_priv
;
1945 struct ath_node
*an
;
1946 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1947 int is_probe
, chk
, ret
;
1949 __le16 fc
= hdr
->frame_control
;
1951 DECLARE_MAC_BUF(mac
);
1953 DPRINTF(sc
, ATH_DBG_RATE
, "%s\n", __func__
);
1955 /* allocate driver private area of tx_info */
1956 tx_info
->driver_data
[0] = kzalloc(sizeof(*tx_info_priv
), GFP_ATOMIC
);
1957 ASSERT(tx_info
->driver_data
[0] != NULL
);
1958 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
1960 sta
= sta_info_get(local
, hdr
->addr1
);
1961 lowest_idx
= rate_lowest_index(local
, sband
, sta
);
1962 tx_info_priv
->min_rate
= (sband
->bitrates
[lowest_idx
].bitrate
* 2) / 10;
1963 /* lowest rate for management and multicast/broadcast frames */
1964 if (!ieee80211_is_data(fc
) ||
1965 is_multicast_ether_addr(hdr
->addr1
) || !sta
) {
1966 sel
->rate_idx
= lowest_idx
;
1970 ath_rc_priv
= sta
->rate_ctrl_priv
;
1972 /* Find tx rate for unicast frames */
1973 ath_rate_findrate(sc
, ath_rc_priv
,
1974 ATH_11N_TXMAXTRY
, 4,
1975 ATH_RC_PROBE_ALLOWED
,
1980 sel
->probe_idx
= ((struct ath_tx_ratectrl
*)
1981 sta
->rate_ctrl_priv
)->probe_rate
;
1983 /* Ratecontrol sometimes returns invalid rate index */
1984 if (tx_info_priv
->rcs
[0].rix
!= 0xff)
1985 ath_rc_priv
->prev_data_rix
= tx_info_priv
->rcs
[0].rix
;
1987 tx_info_priv
->rcs
[0].rix
= ath_rc_priv
->prev_data_rix
;
1989 sel
->rate_idx
= tx_info_priv
->rcs
[0].rix
;
1991 /* Check if aggregation has to be enabled for this tid */
1993 if (hw
->conf
.ht_conf
.ht_supported
) {
1994 if (ieee80211_is_data_qos(fc
)) {
1995 qc
= ieee80211_get_qos_ctl(hdr
);
1998 spin_lock_bh(&sc
->node_lock
);
1999 an
= ath_node_find(sc
, hdr
->addr1
);
2000 spin_unlock_bh(&sc
->node_lock
);
2003 DPRINTF(sc
, ATH_DBG_AGGR
,
2004 "%s: Node not found to "
2005 "init/chk TX aggr\n", __func__
);
2009 chk
= ath_tx_aggr_check(sc
, an
, tid
);
2010 if (chk
== AGGR_REQUIRED
) {
2011 ret
= ieee80211_start_tx_ba_session(hw
,
2014 DPRINTF(sc
, ATH_DBG_AGGR
,
2015 "%s: Unable to start tx "
2018 print_mac(mac
, hdr
->addr1
));
2020 DPRINTF(sc
, ATH_DBG_AGGR
,
2021 "%s: Started tx aggr for: %s\n",
2023 print_mac(mac
, hdr
->addr1
));
2024 } else if (chk
== AGGR_EXCHANGE_PROGRESS
)
2025 ath_tx_aggr_resp(sc
, sta
, an
, tid
);
2030 static void ath_rate_init(void *priv
, void *priv_sta
,
2031 struct ieee80211_local
*local
,
2032 struct sta_info
*sta
)
2034 struct ieee80211_supported_band
*sband
;
2035 struct ieee80211_hw
*hw
= local_to_hw(local
);
2036 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2037 struct ath_softc
*sc
= hw
->priv
;
2040 DPRINTF(sc
, ATH_DBG_RATE
, "%s\n", __func__
);
2042 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2043 sta
->txrate_idx
= rate_lowest_index(local
, sband
, sta
);
2045 ath_setup_rates(local
, sta
);
2046 if (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2047 for (i
= 0; i
< MCS_SET_SIZE
; i
++) {
2048 if (conf
->ht_conf
.supp_mcs_set
[i
/8] & (1<<(i
%8)))
2049 ((struct ath_rate_node
*)
2050 priv_sta
)->neg_ht_rates
.rs_rates
[j
++] = i
;
2051 if (j
== ATH_RATE_MAX
)
2054 ((struct ath_rate_node
*)priv_sta
)->neg_ht_rates
.rs_nrates
= j
;
2056 ath_rc_node_update(hw
, priv_sta
);
2059 static void ath_rate_clear(void *priv
)
2064 static void *ath_rate_alloc(struct ieee80211_local
*local
)
2066 struct ieee80211_hw
*hw
= local_to_hw(local
);
2067 struct ath_softc
*sc
= hw
->priv
;
2069 DPRINTF(sc
, ATH_DBG_RATE
, "%s", __func__
);
2070 return local
->hw
.priv
;
2073 static void ath_rate_free(void *priv
)
2078 static void *ath_rate_alloc_sta(void *priv
, gfp_t gfp
)
2080 struct ath_softc
*sc
= priv
;
2081 struct ath_vap
*avp
= sc
->sc_vaps
[0];
2082 struct ath_rate_node
*rate_priv
;
2084 DPRINTF(sc
, ATH_DBG_RATE
, "%s", __func__
);
2085 rate_priv
= ath_rate_node_alloc(avp
, sc
->sc_rc
, gfp
);
2087 DPRINTF(sc
, ATH_DBG_FATAL
, "%s:Unable to allocate"
2088 "private rate control structure", __func__
);
2091 ath_rc_sib_init(rate_priv
);
2095 static void ath_rate_free_sta(void *priv
, void *priv_sta
)
2097 struct ath_rate_node
*rate_priv
= priv_sta
;
2098 struct ath_softc
*sc
= priv
;
2100 DPRINTF(sc
, ATH_DBG_RATE
, "%s", __func__
);
2101 ath_rate_node_free(rate_priv
);
2104 static struct rate_control_ops ath_rate_ops
= {
2106 .name
= "ath9k_rate_control",
2107 .tx_status
= ath_tx_status
,
2108 .get_rate
= ath_get_rate
,
2109 .rate_init
= ath_rate_init
,
2110 .clear
= ath_rate_clear
,
2111 .alloc
= ath_rate_alloc
,
2112 .free
= ath_rate_free
,
2113 .alloc_sta
= ath_rate_alloc_sta
,
2114 .free_sta
= ath_rate_free_sta
2117 int ath_rate_control_register(void)
2119 return ieee80211_rate_control_register(&ath_rate_ops
);
2122 void ath_rate_control_unregister(void)
2124 ieee80211_rate_control_unregister(&ath_rate_ops
);