Commit | Line | Data |
---|---|---|
b481de9c ZY |
1 | /****************************************************************************** |
2 | * | |
01f8162a | 3 | * Copyright(c) 2005 - 2009 Intel Corporation. All rights reserved. |
b481de9c ZY |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | |
17 | * | |
18 | * The full GNU General Public License is included in this distribution in the | |
19 | * file called LICENSE. | |
20 | * | |
21 | * Contact Information: | |
759ef89f | 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
b481de9c ZY |
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
24 | * | |
25 | *****************************************************************************/ | |
26 | #include <linux/kernel.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/skbuff.h> | |
29 | #include <linux/wireless.h> | |
30 | #include <net/mac80211.h> | |
b481de9c ZY |
31 | |
32 | #include <linux/netdevice.h> | |
33 | #include <linux/etherdevice.h> | |
34 | #include <linux/delay.h> | |
35 | ||
36 | #include <linux/workqueue.h> | |
37 | ||
3e0d4cb1 | 38 | #include "iwl-dev.h" |
be1f3ab6 | 39 | #include "iwl-sta.h" |
857485c0 | 40 | #include "iwl-core.h" |
b481de9c | 41 | |
e227ceac | 42 | #define RS_NAME "iwl-agn-rs" |
b481de9c | 43 | |
aade00ce | 44 | #define NUM_TRY_BEFORE_ANT_TOGGLE 1 |
b481de9c ZY |
45 | #define IWL_NUMBER_TRY 1 |
46 | #define IWL_HT_NUMBER_TRY 3 | |
47 | ||
77626355 BC |
48 | #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ |
49 | #define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */ | |
50 | #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */ | |
51 | ||
7d049e5a AM |
52 | /* max allowed rate miss before sync LQ cmd */ |
53 | #define IWL_MISSED_RATE_MAX 15 | |
77626355 | 54 | /* max time to accum history 2 seconds */ |
447fee70 | 55 | #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ) |
b481de9c ZY |
56 | |
57 | static u8 rs_ht_to_legacy[] = { | |
58 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, | |
59 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, | |
60 | IWL_RATE_6M_INDEX, | |
61 | IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX, | |
62 | IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX, | |
63 | IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX, | |
64 | IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX | |
65 | }; | |
66 | ||
aade00ce GC |
67 | static const u8 ant_toggle_lookup[] = { |
68 | /*ANT_NONE -> */ ANT_NONE, | |
69 | /*ANT_A -> */ ANT_B, | |
70 | /*ANT_B -> */ ANT_C, | |
71 | /*ANT_AB -> */ ANT_BC, | |
72 | /*ANT_C -> */ ANT_A, | |
73 | /*ANT_AC -> */ ANT_AB, | |
74 | /*ANT_BC -> */ ANT_AC, | |
75 | /*ANT_ABC -> */ ANT_ABC, | |
76 | }; | |
77 | ||
77626355 | 78 | /** |
e227ceac | 79 | * struct iwl_rate_scale_data -- tx success history for one rate |
77626355 | 80 | */ |
e227ceac | 81 | struct iwl_rate_scale_data { |
77626355 BC |
82 | u64 data; /* bitmap of successful frames */ |
83 | s32 success_counter; /* number of frames successful */ | |
84 | s32 success_ratio; /* per-cent * 128 */ | |
85 | s32 counter; /* number of frames attempted */ | |
86 | s32 average_tpt; /* success ratio * expected throughput */ | |
b481de9c ZY |
87 | unsigned long stamp; |
88 | }; | |
89 | ||
77626355 | 90 | /** |
e227ceac | 91 | * struct iwl_scale_tbl_info -- tx params and success history for all rates |
77626355 | 92 | * |
e227ceac | 93 | * There are two of these in struct iwl_lq_sta, |
77626355 BC |
94 | * one for "active", and one for "search". |
95 | */ | |
e227ceac | 96 | struct iwl_scale_tbl_info { |
fde0db31 GC |
97 | enum iwl_table_type lq_type; |
98 | u8 ant_type; | |
77626355 BC |
99 | u8 is_SGI; /* 1 = short guard interval */ |
100 | u8 is_fat; /* 1 = 40 MHz channel width */ | |
101 | u8 is_dup; /* 1 = duplicated data streams */ | |
102 | u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ | |
d6e93399 | 103 | u8 max_search; /* maximun number of tables we can search */ |
77626355 | 104 | s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ |
39e88504 | 105 | u32 current_rate; /* rate_n_flags, uCode API format */ |
e227ceac | 106 | struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ |
b481de9c ZY |
107 | }; |
108 | ||
e227ceac | 109 | struct iwl_traffic_load { |
0c11b4de RR |
110 | unsigned long time_stamp; /* age of the oldest statistics */ |
111 | u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time | |
112 | * slice */ | |
113 | u32 total; /* total num of packets during the | |
114 | * last TID_MAX_TIME_DIFF */ | |
115 | u8 queue_count; /* number of queues that has | |
116 | * been used since the last cleanup */ | |
117 | u8 head; /* start of the circular buffer */ | |
118 | }; | |
119 | ||
77626355 | 120 | /** |
e227ceac | 121 | * struct iwl_lq_sta -- driver's rate scaling private structure |
77626355 BC |
122 | * |
123 | * Pointer to this gets passed back and forth between driver and mac80211. | |
124 | */ | |
e227ceac | 125 | struct iwl_lq_sta { |
77626355 BC |
126 | u8 active_tbl; /* index of active table, range 0-1 */ |
127 | u8 enable_counter; /* indicates HT mode */ | |
128 | u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */ | |
129 | u8 search_better_tbl; /* 1: currently trying alternate mode */ | |
b481de9c | 130 | s32 last_tpt; |
77626355 BC |
131 | |
132 | /* The following determine when to search for a new mode */ | |
b481de9c | 133 | u32 table_count_limit; |
77626355 BC |
134 | u32 max_failure_limit; /* # failed frames before new search */ |
135 | u32 max_success_limit; /* # successful frames before new search */ | |
b481de9c | 136 | u32 table_count; |
77626355 BC |
137 | u32 total_failed; /* total failed frames, any/all rates */ |
138 | u32 total_success; /* total successful frames, any/all rates */ | |
447fee70 | 139 | u64 flush_timer; /* time staying in mode before new search */ |
77626355 BC |
140 | |
141 | u8 action_counter; /* # mode-switch actions tried */ | |
b481de9c ZY |
142 | u8 is_green; |
143 | u8 is_dup; | |
8318d78a | 144 | enum ieee80211_band band; |
b481de9c | 145 | u8 ibss_sta_added; |
77626355 BC |
146 | |
147 | /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ | |
02dede04 | 148 | u32 supp_rates; |
39e88504 | 149 | u16 active_legacy_rate; |
b481de9c | 150 | u16 active_siso_rate; |
fde0db31 GC |
151 | u16 active_mimo2_rate; |
152 | u16 active_mimo3_rate; | |
b481de9c | 153 | u16 active_rate_basic; |
c6ec7a9b | 154 | s8 max_rate_idx; /* Max rate set by user */ |
7d049e5a | 155 | u8 missed_rate_counter; |
77626355 | 156 | |
66c73db7 | 157 | struct iwl_link_quality_cmd lq; |
e227ceac TW |
158 | struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ |
159 | struct iwl_traffic_load load[TID_MAX_LOAD_COUNT]; | |
0c11b4de | 160 | u8 tx_agg_tid_en; |
5ae212c9 | 161 | #ifdef CONFIG_MAC80211_DEBUGFS |
98d7e09a | 162 | struct dentry *rs_sta_dbgfs_scale_table_file; |
0209dc11 | 163 | struct dentry *rs_sta_dbgfs_stats_table_file; |
38167459 | 164 | struct dentry *rs_sta_dbgfs_rate_scale_data_file; |
0c11b4de | 165 | struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; |
39e88504 | 166 | u32 dbg_fixed_rate; |
5ae212c9 | 167 | #endif |
6243065d | 168 | struct iwl_priv *drv; |
b7e35008 JB |
169 | |
170 | /* used to be in sta_info */ | |
171 | int last_txrate_idx; | |
12b96817 WYG |
172 | /* last tx rate_n_flags */ |
173 | u32 last_rate_n_flags; | |
b481de9c ZY |
174 | }; |
175 | ||
c79dd5b5 | 176 | static void rs_rate_scale_perform(struct iwl_priv *priv, |
514d65c1 | 177 | struct sk_buff *skb, |
4b7679a5 JB |
178 | struct ieee80211_sta *sta, |
179 | struct iwl_lq_sta *lq_sta); | |
fde0db31 | 180 | static void rs_fill_link_cmd(const struct iwl_priv *priv, |
e227ceac | 181 | struct iwl_lq_sta *lq_sta, u32 rate_n_flags); |
b481de9c ZY |
182 | |
183 | ||
98d7e09a | 184 | #ifdef CONFIG_MAC80211_DEBUGFS |
e227ceac TW |
185 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
186 | u32 *rate_n_flags, int index); | |
98d7e09a | 187 | #else |
e227ceac TW |
188 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
189 | u32 *rate_n_flags, int index) | |
98d7e09a ZY |
190 | {} |
191 | #endif | |
77626355 BC |
192 | |
193 | /* | |
194 | * Expected throughput metrics for following rates: | |
195 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits | |
196 | * "G" is the only table that supports CCK (the first 4 rates). | |
197 | */ | |
584a0f00 | 198 | |
b481de9c ZY |
199 | static s32 expected_tpt_A[IWL_RATE_COUNT] = { |
200 | 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 | |
201 | }; | |
202 | ||
203 | static s32 expected_tpt_G[IWL_RATE_COUNT] = { | |
204 | 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186 | |
205 | }; | |
206 | ||
207 | static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = { | |
208 | 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202 | |
209 | }; | |
210 | ||
211 | static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = { | |
212 | 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211 | |
213 | }; | |
214 | ||
584a0f00 | 215 | static s32 expected_tpt_mimo2_20MHz[IWL_RATE_COUNT] = { |
b481de9c ZY |
216 | 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251 |
217 | }; | |
218 | ||
584a0f00 | 219 | static s32 expected_tpt_mimo2_20MHzSGI[IWL_RATE_COUNT] = { |
b481de9c ZY |
220 | 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257 |
221 | }; | |
222 | ||
223 | static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = { | |
224 | 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257 | |
225 | }; | |
226 | ||
227 | static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = { | |
228 | 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264 | |
229 | }; | |
230 | ||
584a0f00 | 231 | static s32 expected_tpt_mimo2_40MHz[IWL_RATE_COUNT] = { |
b481de9c ZY |
232 | 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289 |
233 | }; | |
234 | ||
584a0f00 | 235 | static s32 expected_tpt_mimo2_40MHzSGI[IWL_RATE_COUNT] = { |
b481de9c ZY |
236 | 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 |
237 | }; | |
238 | ||
584a0f00 WYG |
239 | /* Expected throughput metric MIMO3 */ |
240 | static s32 expected_tpt_mimo3_20MHz[IWL_RATE_COUNT] = { | |
241 | 0, 0, 0, 0, 99, 99, 153, 186, 208, 239, 256, 263, 268 | |
242 | }; | |
243 | ||
244 | static s32 expected_tpt_mimo3_20MHzSGI[IWL_RATE_COUNT] = { | |
245 | 0, 0, 0, 0, 106, 106, 162, 194, 215, 246, 262, 268, 273 | |
246 | }; | |
247 | ||
248 | static s32 expected_tpt_mimo3_40MHz[IWL_RATE_COUNT] = { | |
249 | 0, 0, 0, 0, 152, 152, 211, 239, 255, 279, 290, 294, 297 | |
250 | }; | |
251 | ||
252 | static s32 expected_tpt_mimo3_40MHzSGI[IWL_RATE_COUNT] = { | |
253 | 0, 0, 0, 0, 160, 160, 219, 245, 261, 284, 294, 297, 300 | |
254 | }; | |
255 | ||
12b96817 WYG |
256 | /* mbps, mcs */ |
257 | const static struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = { | |
258 | {"1", ""}, | |
259 | {"2", ""}, | |
260 | {"5.5", ""}, | |
261 | {"11", ""}, | |
262 | {"6", "BPSK 1/2"}, | |
263 | {"9", "BPSK 1/2"}, | |
264 | {"12", "QPSK 1/2"}, | |
265 | {"18", "QPSK 3/4"}, | |
266 | {"24", "16QAM 1/2"}, | |
267 | {"36", "16QAM 3/4"}, | |
268 | {"48", "64QAM 2/3"}, | |
269 | {"54", "64QAM 3/4"}, | |
270 | {"60", "64QAM 5/6"} | |
271 | }; | |
272 | ||
39e88504 | 273 | static inline u8 rs_extract_rate(u32 rate_n_flags) |
b481de9c ZY |
274 | { |
275 | return (u8)(rate_n_flags & 0xFF); | |
276 | } | |
277 | ||
e227ceac | 278 | static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) |
b481de9c ZY |
279 | { |
280 | window->data = 0; | |
281 | window->success_counter = 0; | |
282 | window->success_ratio = IWL_INVALID_VALUE; | |
283 | window->counter = 0; | |
284 | window->average_tpt = IWL_INVALID_VALUE; | |
285 | window->stamp = 0; | |
b481de9c ZY |
286 | } |
287 | ||
aade00ce GC |
288 | static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type) |
289 | { | |
3ac7f146 | 290 | return (ant_type & valid_antenna) == ant_type; |
aade00ce GC |
291 | } |
292 | ||
0c11b4de RR |
293 | /* |
294 | * removes the old data from the statistics. All data that is older than | |
295 | * TID_MAX_TIME_DIFF, will be deleted. | |
296 | */ | |
e227ceac | 297 | static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time) |
0c11b4de RR |
298 | { |
299 | /* The oldest age we want to keep */ | |
300 | u32 oldest_time = curr_time - TID_MAX_TIME_DIFF; | |
301 | ||
302 | while (tl->queue_count && | |
303 | (tl->time_stamp < oldest_time)) { | |
304 | tl->total -= tl->packet_count[tl->head]; | |
305 | tl->packet_count[tl->head] = 0; | |
306 | tl->time_stamp += TID_QUEUE_CELL_SPACING; | |
307 | tl->queue_count--; | |
308 | tl->head++; | |
309 | if (tl->head >= TID_QUEUE_MAX_SIZE) | |
310 | tl->head = 0; | |
311 | } | |
312 | } | |
313 | ||
314 | /* | |
315 | * increment traffic load value for tid and also remove | |
316 | * any old values if passed the certain time period | |
317 | */ | |
e227ceac | 318 | static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data, |
faa29718 | 319 | struct ieee80211_hdr *hdr) |
0c11b4de RR |
320 | { |
321 | u32 curr_time = jiffies_to_msecs(jiffies); | |
322 | u32 time_diff; | |
323 | s32 index; | |
e227ceac | 324 | struct iwl_traffic_load *tl = NULL; |
54dbb525 | 325 | u8 tid; |
0c11b4de | 326 | |
417f114b | 327 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
fd7c8a40 | 328 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
54dbb525 TW |
329 | tid = qc[0] & 0xf; |
330 | } else | |
faa29718 | 331 | return MAX_TID_COUNT; |
0c11b4de RR |
332 | |
333 | tl = &lq_data->load[tid]; | |
334 | ||
335 | curr_time -= curr_time % TID_ROUND_VALUE; | |
336 | ||
337 | /* Happens only for the first packet. Initialize the data */ | |
338 | if (!(tl->queue_count)) { | |
339 | tl->total = 1; | |
340 | tl->time_stamp = curr_time; | |
341 | tl->queue_count = 1; | |
342 | tl->head = 0; | |
343 | tl->packet_count[0] = 1; | |
faa29718 | 344 | return MAX_TID_COUNT; |
0c11b4de RR |
345 | } |
346 | ||
347 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); | |
348 | index = time_diff / TID_QUEUE_CELL_SPACING; | |
349 | ||
350 | /* The history is too long: remove data that is older than */ | |
351 | /* TID_MAX_TIME_DIFF */ | |
352 | if (index >= TID_QUEUE_MAX_SIZE) | |
353 | rs_tl_rm_old_stats(tl, curr_time); | |
354 | ||
355 | index = (tl->head + index) % TID_QUEUE_MAX_SIZE; | |
356 | tl->packet_count[index] = tl->packet_count[index] + 1; | |
357 | tl->total = tl->total + 1; | |
358 | ||
359 | if ((index + 1) > tl->queue_count) | |
360 | tl->queue_count = index + 1; | |
faa29718 RR |
361 | |
362 | return tid; | |
0c11b4de RR |
363 | } |
364 | ||
365 | /* | |
366 | get the traffic load value for tid | |
367 | */ | |
e227ceac | 368 | static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid) |
0c11b4de RR |
369 | { |
370 | u32 curr_time = jiffies_to_msecs(jiffies); | |
371 | u32 time_diff; | |
372 | s32 index; | |
e227ceac | 373 | struct iwl_traffic_load *tl = NULL; |
0c11b4de RR |
374 | |
375 | if (tid >= TID_MAX_LOAD_COUNT) | |
376 | return 0; | |
377 | ||
378 | tl = &(lq_data->load[tid]); | |
379 | ||
380 | curr_time -= curr_time % TID_ROUND_VALUE; | |
381 | ||
382 | if (!(tl->queue_count)) | |
383 | return 0; | |
384 | ||
385 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); | |
386 | index = time_diff / TID_QUEUE_CELL_SPACING; | |
387 | ||
388 | /* The history is too long: remove data that is older than */ | |
389 | /* TID_MAX_TIME_DIFF */ | |
390 | if (index >= TID_QUEUE_MAX_SIZE) | |
391 | rs_tl_rm_old_stats(tl, curr_time); | |
392 | ||
393 | return tl->total; | |
394 | } | |
395 | ||
c79dd5b5 | 396 | static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv, |
e227ceac | 397 | struct iwl_lq_sta *lq_data, u8 tid, |
4b7679a5 | 398 | struct ieee80211_sta *sta) |
0c11b4de | 399 | { |
ff550cb4 | 400 | if (rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) { |
e1623446 | 401 | IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n", |
e174961c | 402 | sta->addr, tid); |
4b7679a5 | 403 | ieee80211_start_tx_ba_session(priv->hw, sta->addr, tid); |
0c11b4de RR |
404 | } |
405 | } | |
406 | ||
c79dd5b5 | 407 | static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid, |
e227ceac | 408 | struct iwl_lq_sta *lq_data, |
4b7679a5 | 409 | struct ieee80211_sta *sta) |
0c11b4de RR |
410 | { |
411 | if ((tid < TID_MAX_LOAD_COUNT)) | |
412 | rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); | |
413 | else if (tid == IWL_AGG_ALL_TID) | |
414 | for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++) | |
415 | rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); | |
416 | } | |
417 | ||
39e88504 | 418 | static inline int get_num_of_ant_from_rate(u32 rate_n_flags) |
fde0db31 | 419 | { |
3ac7f146 TW |
420 | return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) + |
421 | !!(rate_n_flags & RATE_MCS_ANT_B_MSK) + | |
422 | !!(rate_n_flags & RATE_MCS_ANT_C_MSK); | |
fde0db31 GC |
423 | } |
424 | ||
77626355 BC |
425 | /** |
426 | * rs_collect_tx_data - Update the success/failure sliding window | |
427 | * | |
428 | * We keep a sliding window of the last 62 packets transmitted | |
429 | * at this rate. window->data contains the bitmask of successful | |
430 | * packets. | |
431 | */ | |
e227ceac | 432 | static int rs_collect_tx_data(struct iwl_rate_scale_data *windows, |
99556438 RR |
433 | int scale_index, s32 tpt, int retries, |
434 | int successes) | |
b481de9c | 435 | { |
e227ceac | 436 | struct iwl_rate_scale_data *window = NULL; |
39e88504 | 437 | static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1)); |
b481de9c ZY |
438 | s32 fail_count; |
439 | ||
dc2453ae TW |
440 | if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) |
441 | return -EINVAL; | |
b481de9c | 442 | |
77626355 | 443 | /* Select data for current tx bit rate */ |
b481de9c ZY |
444 | window = &(windows[scale_index]); |
445 | ||
77626355 BC |
446 | /* |
447 | * Keep track of only the latest 62 tx frame attempts in this rate's | |
448 | * history window; anything older isn't really relevant any more. | |
449 | * If we have filled up the sliding window, drop the oldest attempt; | |
450 | * if the oldest attempt (highest bit in bitmap) shows "success", | |
451 | * subtract "1" from the success counter (this is the main reason | |
452 | * we keep these bitmaps!). | |
453 | */ | |
99556438 | 454 | while (retries > 0) { |
39e88504 GC |
455 | if (window->counter >= IWL_RATE_MAX_WINDOW) { |
456 | ||
457 | /* remove earliest */ | |
458 | window->counter = IWL_RATE_MAX_WINDOW - 1; | |
459 | ||
99556438 RR |
460 | if (window->data & mask) { |
461 | window->data &= ~mask; | |
39e88504 | 462 | window->success_counter--; |
99556438 | 463 | } |
b481de9c | 464 | } |
b481de9c | 465 | |
99556438 RR |
466 | /* Increment frames-attempted counter */ |
467 | window->counter++; | |
468 | ||
469 | /* Shift bitmap by one frame (throw away oldest history), | |
470 | * OR in "1", and increment "success" if this | |
471 | * frame was successful. */ | |
90d7795e | 472 | window->data <<= 1; |
99556438 | 473 | if (successes > 0) { |
39e88504 | 474 | window->success_counter++; |
99556438 RR |
475 | window->data |= 0x1; |
476 | successes--; | |
477 | } | |
77626355 | 478 | |
99556438 | 479 | retries--; |
b481de9c ZY |
480 | } |
481 | ||
77626355 | 482 | /* Calculate current success ratio, avoid divide-by-0! */ |
b481de9c ZY |
483 | if (window->counter > 0) |
484 | window->success_ratio = 128 * (100 * window->success_counter) | |
485 | / window->counter; | |
486 | else | |
487 | window->success_ratio = IWL_INVALID_VALUE; | |
488 | ||
489 | fail_count = window->counter - window->success_counter; | |
490 | ||
77626355 | 491 | /* Calculate average throughput, if we have enough history. */ |
b481de9c ZY |
492 | if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || |
493 | (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) | |
494 | window->average_tpt = (window->success_ratio * tpt + 64) / 128; | |
495 | else | |
496 | window->average_tpt = IWL_INVALID_VALUE; | |
497 | ||
77626355 | 498 | /* Tag this window as having been updated */ |
b481de9c ZY |
499 | window->stamp = jiffies; |
500 | ||
dc2453ae | 501 | return 0; |
b481de9c ZY |
502 | } |
503 | ||
77626355 BC |
504 | /* |
505 | * Fill uCode API rate_n_flags field, based on "search" or "active" table. | |
506 | */ | |
39e88504 | 507 | /* FIXME:RS:remove this function and put the flags statically in the table */ |
978785a3 TW |
508 | static u32 rate_n_flags_from_tbl(struct iwl_priv *priv, |
509 | struct iwl_scale_tbl_info *tbl, | |
510 | int index, u8 use_green) | |
b481de9c | 511 | { |
39e88504 GC |
512 | u32 rate_n_flags = 0; |
513 | ||
b481de9c | 514 | if (is_legacy(tbl->lq_type)) { |
1826dcc0 | 515 | rate_n_flags = iwl_rates[index].plcp; |
b481de9c | 516 | if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) |
39e88504 | 517 | rate_n_flags |= RATE_MCS_CCK_MSK; |
b481de9c | 518 | |
fde0db31 GC |
519 | } else if (is_Ht(tbl->lq_type)) { |
520 | if (index > IWL_LAST_OFDM_RATE) { | |
978785a3 | 521 | IWL_ERR(priv, "Invalid HT rate index %d\n", index); |
b481de9c | 522 | index = IWL_LAST_OFDM_RATE; |
fde0db31 | 523 | } |
39e88504 | 524 | rate_n_flags = RATE_MCS_HT_MSK; |
fde0db31 GC |
525 | |
526 | if (is_siso(tbl->lq_type)) | |
1826dcc0 | 527 | rate_n_flags |= iwl_rates[index].plcp_siso; |
fde0db31 | 528 | else if (is_mimo2(tbl->lq_type)) |
1826dcc0 | 529 | rate_n_flags |= iwl_rates[index].plcp_mimo2; |
fde0db31 | 530 | else |
1826dcc0 | 531 | rate_n_flags |= iwl_rates[index].plcp_mimo3; |
b481de9c | 532 | } else { |
978785a3 | 533 | IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type); |
b481de9c ZY |
534 | } |
535 | ||
39e88504 | 536 | rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) & |
fde0db31 | 537 | RATE_MCS_ANT_ABC_MSK); |
b481de9c | 538 | |
39e88504 GC |
539 | if (is_Ht(tbl->lq_type)) { |
540 | if (tbl->is_fat) { | |
541 | if (tbl->is_dup) | |
542 | rate_n_flags |= RATE_MCS_DUP_MSK; | |
543 | else | |
544 | rate_n_flags |= RATE_MCS_FAT_MSK; | |
545 | } | |
546 | if (tbl->is_SGI) | |
547 | rate_n_flags |= RATE_MCS_SGI_MSK; | |
548 | ||
549 | if (use_green) { | |
550 | rate_n_flags |= RATE_MCS_GF_MSK; | |
551 | if (is_siso(tbl->lq_type) && tbl->is_SGI) { | |
552 | rate_n_flags &= ~RATE_MCS_SGI_MSK; | |
978785a3 | 553 | IWL_ERR(priv, "GF was set with SGI:SISO\n"); |
39e88504 GC |
554 | } |
555 | } | |
b481de9c | 556 | } |
39e88504 | 557 | return rate_n_flags; |
b481de9c ZY |
558 | } |
559 | ||
77626355 BC |
560 | /* |
561 | * Interpret uCode API's rate_n_flags format, | |
562 | * fill "search" or "active" tx mode table. | |
563 | */ | |
39e88504 | 564 | static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags, |
8318d78a | 565 | enum ieee80211_band band, |
e227ceac | 566 | struct iwl_scale_tbl_info *tbl, |
b481de9c ZY |
567 | int *rate_idx) |
568 | { | |
39e88504 GC |
569 | u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK); |
570 | u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags); | |
571 | u8 mcs; | |
b481de9c | 572 | |
e7d326ac | 573 | *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags); |
b481de9c | 574 | |
fde0db31 | 575 | if (*rate_idx == IWL_RATE_INVALID) { |
b481de9c | 576 | *rate_idx = -1; |
dc2453ae | 577 | return -EINVAL; |
b481de9c | 578 | } |
77626355 | 579 | tbl->is_SGI = 0; /* default legacy setup */ |
b481de9c ZY |
580 | tbl->is_fat = 0; |
581 | tbl->is_dup = 0; | |
fde0db31 GC |
582 | tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); |
583 | tbl->lq_type = LQ_NONE; | |
d6e93399 | 584 | tbl->max_search = IWL_MAX_SEARCH; |
b481de9c | 585 | |
77626355 | 586 | /* legacy rate format */ |
39e88504 | 587 | if (!(rate_n_flags & RATE_MCS_HT_MSK)) { |
fde0db31 | 588 | if (num_of_ant == 1) { |
8318d78a | 589 | if (band == IEEE80211_BAND_5GHZ) |
b481de9c ZY |
590 | tbl->lq_type = LQ_A; |
591 | else | |
592 | tbl->lq_type = LQ_G; | |
b481de9c | 593 | } |
fde0db31 | 594 | /* HT rate format */ |
b481de9c | 595 | } else { |
39e88504 | 596 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
b481de9c ZY |
597 | tbl->is_SGI = 1; |
598 | ||
39e88504 GC |
599 | if ((rate_n_flags & RATE_MCS_FAT_MSK) || |
600 | (rate_n_flags & RATE_MCS_DUP_MSK)) | |
b481de9c ZY |
601 | tbl->is_fat = 1; |
602 | ||
39e88504 | 603 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
b481de9c | 604 | tbl->is_dup = 1; |
fde0db31 | 605 | |
39e88504 | 606 | mcs = rs_extract_rate(rate_n_flags); |
fde0db31 | 607 | |
39e88504 GC |
608 | /* SISO */ |
609 | if (mcs <= IWL_RATE_SISO_60M_PLCP) { | |
fde0db31 GC |
610 | if (num_of_ant == 1) |
611 | tbl->lq_type = LQ_SISO; /*else NONE*/ | |
612 | /* MIMO2 */ | |
39e88504 | 613 | } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) { |
fde0db31 GC |
614 | if (num_of_ant == 2) |
615 | tbl->lq_type = LQ_MIMO2; | |
616 | /* MIMO3 */ | |
617 | } else { | |
d6e93399 MA |
618 | if (num_of_ant == 3) { |
619 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; | |
fde0db31 | 620 | tbl->lq_type = LQ_MIMO3; |
d6e93399 | 621 | } |
fde0db31 | 622 | } |
b481de9c ZY |
623 | } |
624 | return 0; | |
625 | } | |
aade00ce GC |
626 | |
627 | /* switch to another antenna/antennas and return 1 */ | |
628 | /* if no other valid antenna found, return 0 */ | |
629 | static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, | |
e227ceac | 630 | struct iwl_scale_tbl_info *tbl) |
b481de9c | 631 | { |
aade00ce GC |
632 | u8 new_ant_type; |
633 | ||
634 | if (!tbl->ant_type || tbl->ant_type > ANT_ABC) | |
635 | return 0; | |
636 | ||
637 | if (!rs_is_valid_ant(valid_ant, tbl->ant_type)) | |
638 | return 0; | |
639 | ||
640 | new_ant_type = ant_toggle_lookup[tbl->ant_type]; | |
641 | ||
642 | while ((new_ant_type != tbl->ant_type) && | |
643 | !rs_is_valid_ant(valid_ant, new_ant_type)) | |
644 | new_ant_type = ant_toggle_lookup[new_ant_type]; | |
645 | ||
646 | if (new_ant_type == tbl->ant_type) | |
647 | return 0; | |
648 | ||
649 | tbl->ant_type = new_ant_type; | |
650 | *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK; | |
651 | *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS; | |
652 | return 1; | |
b481de9c ZY |
653 | } |
654 | ||
2681b20b WYG |
655 | /* in 4965 we don't use greenfield at all */ |
656 | static inline u8 rs_use_green(struct iwl_priv *priv, | |
657 | struct ieee80211_conf *conf) | |
b481de9c | 658 | { |
2681b20b WYG |
659 | u8 is_green; |
660 | ||
661 | if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) | |
662 | is_green = 0; | |
663 | else | |
664 | is_green = (conf_is_ht(conf) && | |
665 | priv->current_ht_config.is_green_field && | |
666 | !priv->current_ht_config.non_GF_STA_present); | |
667 | return is_green; | |
b481de9c ZY |
668 | } |
669 | ||
670 | /** | |
671 | * rs_get_supported_rates - get the available rates | |
672 | * | |
673 | * if management frame or broadcast frame only return | |
674 | * basic available rates. | |
675 | * | |
676 | */ | |
e227ceac TW |
677 | static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, |
678 | struct ieee80211_hdr *hdr, | |
679 | enum iwl_table_type rate_type) | |
b481de9c | 680 | { |
eecd6e57 GC |
681 | if (hdr && is_multicast_ether_addr(hdr->addr1) && |
682 | lq_sta->active_rate_basic) | |
683 | return lq_sta->active_rate_basic; | |
684 | ||
685 | if (is_legacy(rate_type)) { | |
686 | return lq_sta->active_legacy_rate; | |
687 | } else { | |
b481de9c | 688 | if (is_siso(rate_type)) |
eecd6e57 | 689 | return lq_sta->active_siso_rate; |
fde0db31 | 690 | else if (is_mimo2(rate_type)) |
eecd6e57 | 691 | return lq_sta->active_mimo2_rate; |
b481de9c | 692 | else |
eecd6e57 | 693 | return lq_sta->active_mimo3_rate; |
c33104f0 | 694 | } |
b481de9c ZY |
695 | } |
696 | ||
bf403db8 EK |
697 | static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask, |
698 | int rate_type) | |
b481de9c ZY |
699 | { |
700 | u8 high = IWL_RATE_INVALID; | |
701 | u8 low = IWL_RATE_INVALID; | |
702 | ||
01ebd063 | 703 | /* 802.11A or ht walks to the next literal adjacent rate in |
b481de9c ZY |
704 | * the rate table */ |
705 | if (is_a_band(rate_type) || !is_legacy(rate_type)) { | |
706 | int i; | |
707 | u32 mask; | |
708 | ||
709 | /* Find the previous rate that is in the rate mask */ | |
710 | i = index - 1; | |
711 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { | |
712 | if (rate_mask & mask) { | |
713 | low = i; | |
714 | break; | |
715 | } | |
716 | } | |
717 | ||
718 | /* Find the next rate that is in the rate mask */ | |
719 | i = index + 1; | |
720 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { | |
721 | if (rate_mask & mask) { | |
722 | high = i; | |
723 | break; | |
724 | } | |
725 | } | |
726 | ||
727 | return (high << 8) | low; | |
728 | } | |
729 | ||
730 | low = index; | |
731 | while (low != IWL_RATE_INVALID) { | |
1826dcc0 | 732 | low = iwl_rates[low].prev_rs; |
b481de9c ZY |
733 | if (low == IWL_RATE_INVALID) |
734 | break; | |
735 | if (rate_mask & (1 << low)) | |
736 | break; | |
e1623446 | 737 | IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low); |
b481de9c ZY |
738 | } |
739 | ||
740 | high = index; | |
741 | while (high != IWL_RATE_INVALID) { | |
1826dcc0 | 742 | high = iwl_rates[high].next_rs; |
b481de9c ZY |
743 | if (high == IWL_RATE_INVALID) |
744 | break; | |
745 | if (rate_mask & (1 << high)) | |
746 | break; | |
e1623446 | 747 | IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high); |
b481de9c ZY |
748 | } |
749 | ||
750 | return (high << 8) | low; | |
751 | } | |
752 | ||
e227ceac TW |
753 | static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta, |
754 | struct iwl_scale_tbl_info *tbl, | |
755 | u8 scale_index, u8 ht_possible) | |
b481de9c | 756 | { |
b481de9c ZY |
757 | s32 low; |
758 | u16 rate_mask; | |
759 | u16 high_low; | |
760 | u8 switch_to_legacy = 0; | |
c33104f0 | 761 | u8 is_green = lq_sta->is_green; |
b481de9c ZY |
762 | |
763 | /* check if we need to switch from HT to legacy rates. | |
764 | * assumption is that mandatory rates (1Mbps or 6Mbps) | |
765 | * are always supported (spec demand) */ | |
766 | if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) { | |
767 | switch_to_legacy = 1; | |
768 | scale_index = rs_ht_to_legacy[scale_index]; | |
8318d78a | 769 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
b481de9c ZY |
770 | tbl->lq_type = LQ_A; |
771 | else | |
772 | tbl->lq_type = LQ_G; | |
773 | ||
69fdb309 | 774 | if (num_of_ant(tbl->ant_type) > 1) |
fde0db31 | 775 | tbl->ant_type = ANT_A;/*FIXME:RS*/ |
b481de9c ZY |
776 | |
777 | tbl->is_fat = 0; | |
778 | tbl->is_SGI = 0; | |
d6e93399 | 779 | tbl->max_search = IWL_MAX_SEARCH; |
b481de9c ZY |
780 | } |
781 | ||
eecd6e57 | 782 | rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); |
b481de9c | 783 | |
77626355 | 784 | /* Mask with station rate restriction */ |
b481de9c | 785 | if (is_legacy(tbl->lq_type)) { |
77626355 | 786 | /* supp_rates has no CCK bits in A mode */ |
8318d78a | 787 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
b481de9c | 788 | rate_mask = (u16)(rate_mask & |
c33104f0 | 789 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); |
b481de9c | 790 | else |
c33104f0 | 791 | rate_mask = (u16)(rate_mask & lq_sta->supp_rates); |
b481de9c ZY |
792 | } |
793 | ||
77626355 | 794 | /* If we switched from HT to legacy, check current rate */ |
dc2453ae | 795 | if (switch_to_legacy && (rate_mask & (1 << scale_index))) { |
39e88504 GC |
796 | low = scale_index; |
797 | goto out; | |
b481de9c ZY |
798 | } |
799 | ||
bf403db8 EK |
800 | high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask, |
801 | tbl->lq_type); | |
b481de9c ZY |
802 | low = high_low & 0xff; |
803 | ||
39e88504 GC |
804 | if (low == IWL_RATE_INVALID) |
805 | low = scale_index; | |
806 | ||
807 | out: | |
978785a3 | 808 | return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green); |
b481de9c ZY |
809 | } |
810 | ||
77626355 BC |
811 | /* |
812 | * mac80211 sends us Tx status | |
813 | */ | |
4b7679a5 JB |
814 | static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband, |
815 | struct ieee80211_sta *sta, void *priv_sta, | |
e039fa4a | 816 | struct sk_buff *skb) |
b481de9c ZY |
817 | { |
818 | int status; | |
819 | u8 retries; | |
820 | int rs_index, index = 0; | |
417f114b | 821 | struct iwl_lq_sta *lq_sta = priv_sta; |
66c73db7 | 822 | struct iwl_link_quality_cmd *table; |
b481de9c | 823 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
4b7679a5 JB |
824 | struct iwl_priv *priv = (struct iwl_priv *)priv_r; |
825 | struct ieee80211_hw *hw = priv->hw; | |
e039fa4a | 826 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e227ceac TW |
827 | struct iwl_rate_scale_data *window = NULL; |
828 | struct iwl_rate_scale_data *search_win = NULL; | |
39e88504 | 829 | u32 tx_rate; |
e227ceac TW |
830 | struct iwl_scale_tbl_info tbl_type; |
831 | struct iwl_scale_tbl_info *curr_tbl, *search_tbl; | |
b481de9c | 832 | u8 active_index = 0; |
b481de9c ZY |
833 | s32 tpt = 0; |
834 | ||
e1623446 | 835 | IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); |
b481de9c | 836 | |
417f114b | 837 | if (!ieee80211_is_data(hdr->frame_control) || |
514d65c1 | 838 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
b481de9c ZY |
839 | return; |
840 | ||
99556438 | 841 | /* This packet was aggregated but doesn't carry rate scale info */ |
e039fa4a JB |
842 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && |
843 | !(info->flags & IEEE80211_TX_STAT_AMPDU)) | |
99556438 RR |
844 | return; |
845 | ||
8fe72311 WYG |
846 | if (info->flags & IEEE80211_TX_STAT_AMPDU) |
847 | retries = 0; | |
848 | else | |
849 | retries = info->status.rates[0].count - 1; | |
b481de9c ZY |
850 | |
851 | if (retries > 15) | |
852 | retries = 15; | |
853 | ||
05c914fe | 854 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && |
c33104f0 | 855 | !lq_sta->ibss_sta_added) |
f4d6082d | 856 | goto out; |
b481de9c | 857 | |
c33104f0 TW |
858 | table = &lq_sta->lq; |
859 | active_index = lq_sta->active_tbl; | |
b481de9c | 860 | |
c33104f0 TW |
861 | curr_tbl = &(lq_sta->lq_info[active_index]); |
862 | search_tbl = &(lq_sta->lq_info[(1 - active_index)]); | |
e227ceac TW |
863 | window = (struct iwl_rate_scale_data *)&(curr_tbl->win[0]); |
864 | search_win = (struct iwl_rate_scale_data *)&(search_tbl->win[0]); | |
b481de9c | 865 | |
77626355 BC |
866 | /* |
867 | * Ignore this Tx frame response if its initial rate doesn't match | |
868 | * that of latest Link Quality command. There may be stragglers | |
869 | * from a previous Link Quality command, but we're no longer interested | |
870 | * in those; they're either from the "active" mode while we're trying | |
871 | * to check "search" mode, or a prior "search" mode after we've moved | |
872 | * to a new "search" mode (which might become the new "active" mode). | |
873 | */ | |
39e88504 GC |
874 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); |
875 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); | |
4c424e4c RR |
876 | if (priv->band == IEEE80211_BAND_5GHZ) |
877 | rs_index -= IWL_FIRST_OFDM_RATE; | |
878 | ||
e6a9854b JB |
879 | if ((info->status.rates[0].idx < 0) || |
880 | (tbl_type.is_SGI != !!(info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)) || | |
881 | (tbl_type.is_fat != !!(info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) || | |
882 | (tbl_type.is_dup != !!(info->status.rates[0].flags & IEEE80211_TX_RC_DUP_DATA)) || | |
883 | (tbl_type.ant_type != info->antenna_sel_tx) || | |
884 | (!!(tx_rate & RATE_MCS_HT_MSK) != !!(info->status.rates[0].flags & IEEE80211_TX_RC_MCS)) || | |
885 | (!!(tx_rate & RATE_MCS_GF_MSK) != !!(info->status.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)) || | |
4c424e4c | 886 | (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate != |
e6a9854b | 887 | hw->wiphy->bands[info->band]->bitrates[info->status.rates[0].idx].bitrate)) { |
e1623446 | 888 | IWL_DEBUG_RATE(priv, "initial rate does not match 0x%x\n", tx_rate); |
d5e49036 MA |
889 | /* the last LQ command could failed so the LQ in ucode not |
890 | * the same in driver sync up | |
891 | */ | |
7d049e5a AM |
892 | lq_sta->missed_rate_counter++; |
893 | if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { | |
894 | lq_sta->missed_rate_counter = 0; | |
895 | iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); | |
896 | } | |
f4d6082d | 897 | goto out; |
b481de9c ZY |
898 | } |
899 | ||
7d049e5a | 900 | lq_sta->missed_rate_counter = 0; |
77626355 | 901 | /* Update frame history window with "failure" for each Tx retry. */ |
b481de9c | 902 | while (retries) { |
77626355 BC |
903 | /* Look up the rate and other info used for each tx attempt. |
904 | * Each tx attempt steps one entry deeper in the rate table. */ | |
39e88504 GC |
905 | tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags); |
906 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, | |
b481de9c ZY |
907 | &tbl_type, &rs_index); |
908 | ||
77626355 BC |
909 | /* If type matches "search" table, |
910 | * add failure to "search" history */ | |
b481de9c | 911 | if ((tbl_type.lq_type == search_tbl->lq_type) && |
fde0db31 | 912 | (tbl_type.ant_type == search_tbl->ant_type) && |
b481de9c ZY |
913 | (tbl_type.is_SGI == search_tbl->is_SGI)) { |
914 | if (search_tbl->expected_tpt) | |
915 | tpt = search_tbl->expected_tpt[rs_index]; | |
916 | else | |
917 | tpt = 0; | |
99556438 | 918 | rs_collect_tx_data(search_win, rs_index, tpt, 1, 0); |
77626355 BC |
919 | |
920 | /* Else if type matches "current/active" table, | |
921 | * add failure to "current/active" history */ | |
b481de9c | 922 | } else if ((tbl_type.lq_type == curr_tbl->lq_type) && |
fde0db31 | 923 | (tbl_type.ant_type == curr_tbl->ant_type) && |
b481de9c ZY |
924 | (tbl_type.is_SGI == curr_tbl->is_SGI)) { |
925 | if (curr_tbl->expected_tpt) | |
926 | tpt = curr_tbl->expected_tpt[rs_index]; | |
927 | else | |
928 | tpt = 0; | |
99556438 | 929 | rs_collect_tx_data(window, rs_index, tpt, 1, 0); |
b481de9c | 930 | } |
77626355 BC |
931 | |
932 | /* If not searching for a new mode, increment failed counter | |
933 | * ... this helps determine when to start searching again */ | |
c33104f0 TW |
934 | if (lq_sta->stay_in_tbl) |
935 | lq_sta->total_failed++; | |
b481de9c ZY |
936 | --retries; |
937 | index++; | |
938 | ||
939 | } | |
940 | ||
77626355 BC |
941 | /* |
942 | * Find (by rate) the history window to update with final Tx attempt; | |
943 | * if Tx was successful first try, use original rate, | |
944 | * else look up the rate that was, finally, successful. | |
945 | */ | |
39e88504 | 946 | tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags); |
12b96817 | 947 | lq_sta->last_rate_n_flags = tx_rate; |
39e88504 | 948 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); |
b481de9c | 949 | |
77626355 | 950 | /* Update frame history window with "success" if Tx got ACKed ... */ |
e039fa4a | 951 | status = !!(info->flags & IEEE80211_TX_STAT_ACK); |
b481de9c | 952 | |
77626355 BC |
953 | /* If type matches "search" table, |
954 | * add final tx status to "search" history */ | |
b481de9c | 955 | if ((tbl_type.lq_type == search_tbl->lq_type) && |
fde0db31 | 956 | (tbl_type.ant_type == search_tbl->ant_type) && |
b481de9c ZY |
957 | (tbl_type.is_SGI == search_tbl->is_SGI)) { |
958 | if (search_tbl->expected_tpt) | |
959 | tpt = search_tbl->expected_tpt[rs_index]; | |
960 | else | |
961 | tpt = 0; | |
df36c044 | 962 | if (info->flags & IEEE80211_TX_STAT_AMPDU) |
99556438 | 963 | rs_collect_tx_data(search_win, rs_index, tpt, |
e039fa4a JB |
964 | info->status.ampdu_ack_len, |
965 | info->status.ampdu_ack_map); | |
99556438 RR |
966 | else |
967 | rs_collect_tx_data(search_win, rs_index, tpt, | |
968 | 1, status); | |
77626355 BC |
969 | /* Else if type matches "current/active" table, |
970 | * add final tx status to "current/active" history */ | |
b481de9c | 971 | } else if ((tbl_type.lq_type == curr_tbl->lq_type) && |
fde0db31 | 972 | (tbl_type.ant_type == curr_tbl->ant_type) && |
b481de9c ZY |
973 | (tbl_type.is_SGI == curr_tbl->is_SGI)) { |
974 | if (curr_tbl->expected_tpt) | |
975 | tpt = curr_tbl->expected_tpt[rs_index]; | |
976 | else | |
977 | tpt = 0; | |
df36c044 | 978 | if (info->flags & IEEE80211_TX_STAT_AMPDU) |
99556438 | 979 | rs_collect_tx_data(window, rs_index, tpt, |
e039fa4a JB |
980 | info->status.ampdu_ack_len, |
981 | info->status.ampdu_ack_map); | |
99556438 RR |
982 | else |
983 | rs_collect_tx_data(window, rs_index, tpt, | |
984 | 1, status); | |
b481de9c ZY |
985 | } |
986 | ||
77626355 BC |
987 | /* If not searching for new mode, increment success/failed counter |
988 | * ... these help determine when to start searching again */ | |
c33104f0 | 989 | if (lq_sta->stay_in_tbl) { |
df36c044 | 990 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
e039fa4a | 991 | lq_sta->total_success += info->status.ampdu_ack_map; |
99556438 | 992 | lq_sta->total_failed += |
e039fa4a | 993 | (info->status.ampdu_ack_len - info->status.ampdu_ack_map); |
99556438 RR |
994 | } else { |
995 | if (status) | |
996 | lq_sta->total_success++; | |
997 | else | |
998 | lq_sta->total_failed++; | |
999 | } | |
b481de9c ZY |
1000 | } |
1001 | ||
77626355 | 1002 | /* See if there's a better rate or modulation mode to try. */ |
c338ba3c | 1003 | if (sta && sta->supp_rates[sband->band]) |
514d65c1 | 1004 | rs_rate_scale_perform(priv, skb, sta, lq_sta); |
f4d6082d | 1005 | out: |
b481de9c ZY |
1006 | return; |
1007 | } | |
1008 | ||
77626355 BC |
1009 | /* |
1010 | * Begin a period of staying with a selected modulation mode. | |
1011 | * Set "stay_in_tbl" flag to prevent any mode switches. | |
1012 | * Set frame tx success limits according to legacy vs. high-throughput, | |
1013 | * and reset overall (spanning all rates) tx success history statistics. | |
1014 | * These control how long we stay using same modulation mode before | |
1015 | * searching for a new mode. | |
1016 | */ | |
bf403db8 | 1017 | static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy, |
e227ceac | 1018 | struct iwl_lq_sta *lq_sta) |
b481de9c | 1019 | { |
e1623446 | 1020 | IWL_DEBUG_RATE(priv, "we are staying in the same table\n"); |
c33104f0 | 1021 | lq_sta->stay_in_tbl = 1; /* only place this gets set */ |
b481de9c | 1022 | if (is_legacy) { |
c33104f0 TW |
1023 | lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; |
1024 | lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; | |
1025 | lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT; | |
b481de9c | 1026 | } else { |
c33104f0 TW |
1027 | lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; |
1028 | lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; | |
1029 | lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; | |
b481de9c | 1030 | } |
c33104f0 TW |
1031 | lq_sta->table_count = 0; |
1032 | lq_sta->total_failed = 0; | |
1033 | lq_sta->total_success = 0; | |
447fee70 | 1034 | lq_sta->flush_timer = jiffies; |
d6e93399 | 1035 | lq_sta->action_counter = 0; |
b481de9c ZY |
1036 | } |
1037 | ||
77626355 BC |
1038 | /* |
1039 | * Find correct throughput table for given mode of modulation | |
1040 | */ | |
e227ceac TW |
1041 | static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, |
1042 | struct iwl_scale_tbl_info *tbl) | |
b481de9c ZY |
1043 | { |
1044 | if (is_legacy(tbl->lq_type)) { | |
1045 | if (!is_a_band(tbl->lq_type)) | |
1046 | tbl->expected_tpt = expected_tpt_G; | |
1047 | else | |
1048 | tbl->expected_tpt = expected_tpt_A; | |
1049 | } else if (is_siso(tbl->lq_type)) { | |
c33104f0 | 1050 | if (tbl->is_fat && !lq_sta->is_dup) |
b481de9c ZY |
1051 | if (tbl->is_SGI) |
1052 | tbl->expected_tpt = expected_tpt_siso40MHzSGI; | |
1053 | else | |
1054 | tbl->expected_tpt = expected_tpt_siso40MHz; | |
1055 | else if (tbl->is_SGI) | |
1056 | tbl->expected_tpt = expected_tpt_siso20MHzSGI; | |
1057 | else | |
1058 | tbl->expected_tpt = expected_tpt_siso20MHz; | |
584a0f00 WYG |
1059 | } else if (is_mimo2(tbl->lq_type)) { |
1060 | if (tbl->is_fat && !lq_sta->is_dup) | |
1061 | if (tbl->is_SGI) | |
1062 | tbl->expected_tpt = expected_tpt_mimo2_40MHzSGI; | |
1063 | else | |
1064 | tbl->expected_tpt = expected_tpt_mimo2_40MHz; | |
1065 | else if (tbl->is_SGI) | |
1066 | tbl->expected_tpt = expected_tpt_mimo2_20MHzSGI; | |
1067 | else | |
1068 | tbl->expected_tpt = expected_tpt_mimo2_20MHz; | |
1069 | } else if (is_mimo3(tbl->lq_type)) { | |
c33104f0 | 1070 | if (tbl->is_fat && !lq_sta->is_dup) |
b481de9c | 1071 | if (tbl->is_SGI) |
584a0f00 | 1072 | tbl->expected_tpt = expected_tpt_mimo3_40MHzSGI; |
b481de9c | 1073 | else |
584a0f00 | 1074 | tbl->expected_tpt = expected_tpt_mimo3_40MHz; |
b481de9c | 1075 | else if (tbl->is_SGI) |
584a0f00 | 1076 | tbl->expected_tpt = expected_tpt_mimo3_20MHzSGI; |
b481de9c | 1077 | else |
584a0f00 | 1078 | tbl->expected_tpt = expected_tpt_mimo3_20MHz; |
b481de9c ZY |
1079 | } else |
1080 | tbl->expected_tpt = expected_tpt_G; | |
1081 | } | |
1082 | ||
77626355 BC |
1083 | /* |
1084 | * Find starting rate for new "search" high-throughput mode of modulation. | |
1085 | * Goal is to find lowest expected rate (under perfect conditions) that is | |
1086 | * above the current measured throughput of "active" mode, to give new mode | |
1087 | * a fair chance to prove itself without too many challenges. | |
1088 | * | |
1089 | * This gets called when transitioning to more aggressive modulation | |
1090 | * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive | |
1091 | * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need | |
1092 | * to decrease to match "active" throughput. When moving from MIMO to SISO, | |
1093 | * bit rate will typically need to increase, but not if performance was bad. | |
1094 | */ | |
c79dd5b5 | 1095 | static s32 rs_get_best_rate(struct iwl_priv *priv, |
e227ceac TW |
1096 | struct iwl_lq_sta *lq_sta, |
1097 | struct iwl_scale_tbl_info *tbl, /* "search" */ | |
f935a6da | 1098 | u16 rate_mask, s8 index) |
b481de9c | 1099 | { |
77626355 | 1100 | /* "active" values */ |
e227ceac | 1101 | struct iwl_scale_tbl_info *active_tbl = |
c33104f0 | 1102 | &(lq_sta->lq_info[lq_sta->active_tbl]); |
b481de9c | 1103 | s32 active_sr = active_tbl->win[index].success_ratio; |
b481de9c | 1104 | s32 active_tpt = active_tbl->expected_tpt[index]; |
77626355 BC |
1105 | |
1106 | /* expected "search" throughput */ | |
1107 | s32 *tpt_tbl = tbl->expected_tpt; | |
1108 | ||
1109 | s32 new_rate, high, low, start_hi; | |
b481de9c | 1110 | u16 high_low; |
f935a6da | 1111 | s8 rate = index; |
b481de9c ZY |
1112 | |
1113 | new_rate = high = low = start_hi = IWL_RATE_INVALID; | |
1114 | ||
1115 | for (; ;) { | |
bf403db8 EK |
1116 | high_low = rs_get_adjacent_rate(priv, rate, rate_mask, |
1117 | tbl->lq_type); | |
b481de9c ZY |
1118 | |
1119 | low = high_low & 0xff; | |
1120 | high = (high_low >> 8) & 0xff; | |
1121 | ||
77626355 BC |
1122 | /* |
1123 | * Lower the "search" bit rate, to give new "search" mode | |
1124 | * approximately the same throughput as "active" if: | |
1125 | * | |
1126 | * 1) "Active" mode has been working modestly well (but not | |
1127 | * great), and expected "search" throughput (under perfect | |
1128 | * conditions) at candidate rate is above the actual | |
1129 | * measured "active" throughput (but less than expected | |
1130 | * "active" throughput under perfect conditions). | |
1131 | * OR | |
1132 | * 2) "Active" mode has been working perfectly or very well | |
1133 | * and expected "search" throughput (under perfect | |
1134 | * conditions) at candidate rate is above expected | |
1135 | * "active" throughput (under perfect conditions). | |
1136 | */ | |
c33104f0 | 1137 | if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) && |
b481de9c ZY |
1138 | ((active_sr > IWL_RATE_DECREASE_TH) && |
1139 | (active_sr <= IWL_RATE_HIGH_TH) && | |
1140 | (tpt_tbl[rate] <= active_tpt))) || | |
1141 | ((active_sr >= IWL_RATE_SCALE_SWITCH) && | |
1142 | (tpt_tbl[rate] > active_tpt))) { | |
1143 | ||
77626355 BC |
1144 | /* (2nd or later pass) |
1145 | * If we've already tried to raise the rate, and are | |
1146 | * now trying to lower it, use the higher rate. */ | |
b481de9c ZY |
1147 | if (start_hi != IWL_RATE_INVALID) { |
1148 | new_rate = start_hi; | |
1149 | break; | |
1150 | } | |
77626355 | 1151 | |
b481de9c | 1152 | new_rate = rate; |
77626355 BC |
1153 | |
1154 | /* Loop again with lower rate */ | |
b481de9c ZY |
1155 | if (low != IWL_RATE_INVALID) |
1156 | rate = low; | |
77626355 BC |
1157 | |
1158 | /* Lower rate not available, use the original */ | |
b481de9c ZY |
1159 | else |
1160 | break; | |
77626355 BC |
1161 | |
1162 | /* Else try to raise the "search" rate to match "active" */ | |
b481de9c | 1163 | } else { |
77626355 BC |
1164 | /* (2nd or later pass) |
1165 | * If we've already tried to lower the rate, and are | |
1166 | * now trying to raise it, use the lower rate. */ | |
b481de9c ZY |
1167 | if (new_rate != IWL_RATE_INVALID) |
1168 | break; | |
77626355 BC |
1169 | |
1170 | /* Loop again with higher rate */ | |
b481de9c ZY |
1171 | else if (high != IWL_RATE_INVALID) { |
1172 | start_hi = high; | |
1173 | rate = high; | |
77626355 BC |
1174 | |
1175 | /* Higher rate not available, use the original */ | |
b481de9c | 1176 | } else { |
90d7795e | 1177 | new_rate = rate; |
b481de9c ZY |
1178 | break; |
1179 | } | |
1180 | } | |
1181 | } | |
1182 | ||
1183 | return new_rate; | |
1184 | } | |
b481de9c | 1185 | |
77626355 | 1186 | /* |
584a0f00 | 1187 | * Set up search table for MIMO2 |
77626355 | 1188 | */ |
fde0db31 | 1189 | static int rs_switch_to_mimo2(struct iwl_priv *priv, |
e227ceac | 1190 | struct iwl_lq_sta *lq_sta, |
270243a5 | 1191 | struct ieee80211_conf *conf, |
4b7679a5 | 1192 | struct ieee80211_sta *sta, |
e227ceac | 1193 | struct iwl_scale_tbl_info *tbl, int index) |
b481de9c | 1194 | { |
b481de9c ZY |
1195 | u16 rate_mask; |
1196 | s32 rate; | |
c33104f0 | 1197 | s8 is_green = lq_sta->is_green; |
b481de9c | 1198 | |
de27e64e | 1199 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
b481de9c ZY |
1200 | return -1; |
1201 | ||
d9fe60de | 1202 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) |
00c5ae2f | 1203 | == WLAN_HT_CAP_SM_PS_STATIC) |
b481de9c ZY |
1204 | return -1; |
1205 | ||
77626355 | 1206 | /* Need both Tx chains/antennas to support MIMO */ |
aade00ce | 1207 | if (priv->hw_params.tx_chains_num < 2) |
b481de9c ZY |
1208 | return -1; |
1209 | ||
e1623446 | 1210 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n"); |
39e88504 GC |
1211 | |
1212 | tbl->lq_type = LQ_MIMO2; | |
c33104f0 | 1213 | tbl->is_dup = lq_sta->is_dup; |
b481de9c | 1214 | tbl->action = 0; |
d6e93399 | 1215 | tbl->max_search = IWL_MAX_SEARCH; |
39e88504 GC |
1216 | rate_mask = lq_sta->active_mimo2_rate; |
1217 | ||
a30199f1 | 1218 | if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap)) |
b481de9c ZY |
1219 | tbl->is_fat = 1; |
1220 | else | |
1221 | tbl->is_fat = 0; | |
1222 | ||
39e88504 | 1223 | /* FIXME: - don't toggle SGI here |
b481de9c | 1224 | if (tbl->is_fat) { |
270243a5 | 1225 | if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) |
b481de9c ZY |
1226 | tbl->is_SGI = 1; |
1227 | else | |
1228 | tbl->is_SGI = 0; | |
270243a5 | 1229 | } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY) |
b481de9c ZY |
1230 | tbl->is_SGI = 1; |
1231 | else | |
1232 | tbl->is_SGI = 0; | |
39e88504 | 1233 | */ |
b481de9c | 1234 | |
eecd6e57 | 1235 | rs_set_expected_tpt_table(lq_sta, tbl); |
b481de9c | 1236 | |
f935a6da | 1237 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); |
b481de9c | 1238 | |
e1623446 | 1239 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); |
584a0f00 WYG |
1240 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
1241 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", | |
1242 | rate, rate_mask); | |
1243 | return -1; | |
1244 | } | |
1245 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); | |
1246 | ||
1247 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", | |
1248 | tbl->current_rate, is_green); | |
1249 | return 0; | |
1250 | } | |
1251 | ||
1252 | /* | |
1253 | * Set up search table for MIMO3 | |
1254 | */ | |
1255 | static int rs_switch_to_mimo3(struct iwl_priv *priv, | |
1256 | struct iwl_lq_sta *lq_sta, | |
1257 | struct ieee80211_conf *conf, | |
1258 | struct ieee80211_sta *sta, | |
1259 | struct iwl_scale_tbl_info *tbl, int index) | |
1260 | { | |
1261 | u16 rate_mask; | |
1262 | s32 rate; | |
1263 | s8 is_green = lq_sta->is_green; | |
1264 | ||
1265 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) | |
1266 | return -1; | |
1267 | ||
1268 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) | |
1269 | == WLAN_HT_CAP_SM_PS_STATIC) | |
1270 | return -1; | |
1271 | ||
1272 | /* Need both Tx chains/antennas to support MIMO */ | |
1273 | if (priv->hw_params.tx_chains_num < 3) | |
1274 | return -1; | |
1275 | ||
1276 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n"); | |
1277 | ||
1278 | tbl->lq_type = LQ_MIMO3; | |
1279 | tbl->is_dup = lq_sta->is_dup; | |
1280 | tbl->action = 0; | |
d6e93399 | 1281 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; |
584a0f00 WYG |
1282 | rate_mask = lq_sta->active_mimo3_rate; |
1283 | ||
a30199f1 | 1284 | if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap)) |
584a0f00 WYG |
1285 | tbl->is_fat = 1; |
1286 | else | |
1287 | tbl->is_fat = 0; | |
39e88504 | 1288 | |
584a0f00 WYG |
1289 | /* FIXME: - don't toggle SGI here |
1290 | if (tbl->is_fat) { | |
1291 | if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) | |
1292 | tbl->is_SGI = 1; | |
1293 | else | |
1294 | tbl->is_SGI = 0; | |
1295 | } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY) | |
1296 | tbl->is_SGI = 1; | |
1297 | else | |
1298 | tbl->is_SGI = 0; | |
1299 | */ | |
1300 | ||
1301 | rs_set_expected_tpt_table(lq_sta, tbl); | |
1302 | ||
1303 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); | |
1304 | ||
1305 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n", | |
1306 | rate, rate_mask); | |
39e88504 | 1307 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
e1623446 | 1308 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", |
39e88504 | 1309 | rate, rate_mask); |
b481de9c | 1310 | return -1; |
39e88504 | 1311 | } |
978785a3 | 1312 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); |
b481de9c | 1313 | |
e1623446 | 1314 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", |
39e88504 | 1315 | tbl->current_rate, is_green); |
dc2453ae | 1316 | return 0; |
fde0db31 | 1317 | } |
b481de9c | 1318 | |
77626355 BC |
1319 | /* |
1320 | * Set up search table for SISO | |
1321 | */ | |
c79dd5b5 | 1322 | static int rs_switch_to_siso(struct iwl_priv *priv, |
e227ceac | 1323 | struct iwl_lq_sta *lq_sta, |
270243a5 | 1324 | struct ieee80211_conf *conf, |
4b7679a5 | 1325 | struct ieee80211_sta *sta, |
e227ceac | 1326 | struct iwl_scale_tbl_info *tbl, int index) |
b481de9c | 1327 | { |
b481de9c | 1328 | u16 rate_mask; |
c33104f0 | 1329 | u8 is_green = lq_sta->is_green; |
b481de9c ZY |
1330 | s32 rate; |
1331 | ||
de27e64e | 1332 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
b481de9c ZY |
1333 | return -1; |
1334 | ||
e1623446 | 1335 | IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n"); |
39e88504 | 1336 | |
c33104f0 | 1337 | tbl->is_dup = lq_sta->is_dup; |
b481de9c ZY |
1338 | tbl->lq_type = LQ_SISO; |
1339 | tbl->action = 0; | |
d6e93399 | 1340 | tbl->max_search = IWL_MAX_SEARCH; |
39e88504 | 1341 | rate_mask = lq_sta->active_siso_rate; |
b481de9c | 1342 | |
a30199f1 | 1343 | if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap)) |
b481de9c ZY |
1344 | tbl->is_fat = 1; |
1345 | else | |
1346 | tbl->is_fat = 0; | |
1347 | ||
39e88504 | 1348 | /* FIXME: - don't toggle SGI here |
b481de9c | 1349 | if (tbl->is_fat) { |
270243a5 | 1350 | if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) |
b481de9c ZY |
1351 | tbl->is_SGI = 1; |
1352 | else | |
1353 | tbl->is_SGI = 0; | |
270243a5 | 1354 | } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY) |
b481de9c ZY |
1355 | tbl->is_SGI = 1; |
1356 | else | |
1357 | tbl->is_SGI = 0; | |
39e88504 | 1358 | */ |
b481de9c ZY |
1359 | |
1360 | if (is_green) | |
39e88504 | 1361 | tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/ |
b481de9c | 1362 | |
eecd6e57 | 1363 | rs_set_expected_tpt_table(lq_sta, tbl); |
f935a6da | 1364 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); |
b481de9c | 1365 | |
e1623446 | 1366 | IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask); |
b481de9c | 1367 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
e1623446 | 1368 | IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n", |
b481de9c ZY |
1369 | rate, rate_mask); |
1370 | return -1; | |
1371 | } | |
978785a3 | 1372 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); |
e1623446 | 1373 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", |
39e88504 | 1374 | tbl->current_rate, is_green); |
403ab56b | 1375 | return 0; |
b481de9c ZY |
1376 | } |
1377 | ||
77626355 BC |
1378 | /* |
1379 | * Try to switch to new modulation mode from legacy | |
1380 | */ | |
c79dd5b5 | 1381 | static int rs_move_legacy_other(struct iwl_priv *priv, |
e227ceac | 1382 | struct iwl_lq_sta *lq_sta, |
270243a5 | 1383 | struct ieee80211_conf *conf, |
4b7679a5 | 1384 | struct ieee80211_sta *sta, |
b481de9c ZY |
1385 | int index) |
1386 | { | |
e227ceac TW |
1387 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
1388 | struct iwl_scale_tbl_info *search_tbl = | |
1389 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | |
1390 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | |
1391 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | |
1392 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | |
b481de9c | 1393 | u8 start_action = tbl->action; |
fde0db31 | 1394 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
3110bef7 | 1395 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
fde0db31 | 1396 | int ret = 0; |
d6e93399 | 1397 | u8 update_search_tbl_counter = 0; |
b481de9c ZY |
1398 | |
1399 | for (; ;) { | |
d6e93399 | 1400 | lq_sta->action_counter++; |
b481de9c | 1401 | switch (tbl->action) { |
3110bef7 GC |
1402 | case IWL_LEGACY_SWITCH_ANTENNA1: |
1403 | case IWL_LEGACY_SWITCH_ANTENNA2: | |
e1623446 | 1404 | IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n"); |
b481de9c | 1405 | |
3110bef7 GC |
1406 | if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 && |
1407 | tx_chains_num <= 1) || | |
1408 | (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 && | |
1409 | tx_chains_num <= 2)) | |
1410 | break; | |
1411 | ||
77626355 | 1412 | /* Don't change antenna if success has been great */ |
b481de9c ZY |
1413 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) |
1414 | break; | |
77626355 | 1415 | |
77626355 | 1416 | /* Set up search table to try other antenna */ |
b481de9c ZY |
1417 | memcpy(search_tbl, tbl, sz); |
1418 | ||
aade00ce GC |
1419 | if (rs_toggle_antenna(valid_tx_ant, |
1420 | &search_tbl->current_rate, search_tbl)) { | |
d6e93399 | 1421 | update_search_tbl_counter = 1; |
3110bef7 | 1422 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
aade00ce GC |
1423 | goto out; |
1424 | } | |
a5e8b505 | 1425 | break; |
b481de9c | 1426 | case IWL_LEGACY_SWITCH_SISO: |
e1623446 | 1427 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n"); |
77626355 BC |
1428 | |
1429 | /* Set up search table to try SISO */ | |
b481de9c | 1430 | memcpy(search_tbl, tbl, sz); |
b481de9c | 1431 | search_tbl->is_SGI = 0; |
c33104f0 | 1432 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, |
270243a5 | 1433 | search_tbl, index); |
dc2453ae | 1434 | if (!ret) { |
c33104f0 | 1435 | lq_sta->action_counter = 0; |
b481de9c | 1436 | goto out; |
dc2453ae | 1437 | } |
b481de9c ZY |
1438 | |
1439 | break; | |
3110bef7 GC |
1440 | case IWL_LEGACY_SWITCH_MIMO2_AB: |
1441 | case IWL_LEGACY_SWITCH_MIMO2_AC: | |
1442 | case IWL_LEGACY_SWITCH_MIMO2_BC: | |
e1623446 | 1443 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n"); |
77626355 BC |
1444 | |
1445 | /* Set up search table to try MIMO */ | |
b481de9c | 1446 | memcpy(search_tbl, tbl, sz); |
b481de9c | 1447 | search_tbl->is_SGI = 0; |
3110bef7 GC |
1448 | |
1449 | if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB) | |
1450 | search_tbl->ant_type = ANT_AB; | |
1451 | else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC) | |
1452 | search_tbl->ant_type = ANT_AC; | |
1453 | else | |
1454 | search_tbl->ant_type = ANT_BC; | |
1455 | ||
1456 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1457 | break; | |
1458 | ||
fde0db31 | 1459 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, |
270243a5 | 1460 | search_tbl, index); |
dc2453ae | 1461 | if (!ret) { |
c33104f0 | 1462 | lq_sta->action_counter = 0; |
b481de9c | 1463 | goto out; |
dc2453ae | 1464 | } |
b481de9c | 1465 | break; |
584a0f00 WYG |
1466 | |
1467 | case IWL_LEGACY_SWITCH_MIMO3_ABC: | |
1468 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n"); | |
1469 | ||
1470 | /* Set up search table to try MIMO3 */ | |
1471 | memcpy(search_tbl, tbl, sz); | |
1472 | search_tbl->is_SGI = 0; | |
1473 | ||
1474 | search_tbl->ant_type = ANT_ABC; | |
1475 | ||
1476 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1477 | break; | |
1478 | ||
1479 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | |
1480 | search_tbl, index); | |
1481 | if (!ret) { | |
1482 | lq_sta->action_counter = 0; | |
1483 | goto out; | |
1484 | } | |
1485 | break; | |
b481de9c ZY |
1486 | } |
1487 | tbl->action++; | |
584a0f00 | 1488 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
3110bef7 | 1489 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
b481de9c ZY |
1490 | |
1491 | if (tbl->action == start_action) | |
1492 | break; | |
1493 | ||
1494 | } | |
3110bef7 | 1495 | search_tbl->lq_type = LQ_NONE; |
b481de9c ZY |
1496 | return 0; |
1497 | ||
3110bef7 GC |
1498 | out: |
1499 | lq_sta->search_better_tbl = 1; | |
b481de9c | 1500 | tbl->action++; |
584a0f00 | 1501 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
3110bef7 | 1502 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
d6e93399 MA |
1503 | if (update_search_tbl_counter) |
1504 | search_tbl->action = tbl->action; | |
b481de9c ZY |
1505 | return 0; |
1506 | ||
1507 | } | |
1508 | ||
77626355 BC |
1509 | /* |
1510 | * Try to switch to new modulation mode from SISO | |
1511 | */ | |
c79dd5b5 | 1512 | static int rs_move_siso_to_other(struct iwl_priv *priv, |
e227ceac | 1513 | struct iwl_lq_sta *lq_sta, |
270243a5 | 1514 | struct ieee80211_conf *conf, |
4b7679a5 | 1515 | struct ieee80211_sta *sta, int index) |
b481de9c | 1516 | { |
c33104f0 | 1517 | u8 is_green = lq_sta->is_green; |
e227ceac TW |
1518 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
1519 | struct iwl_scale_tbl_info *search_tbl = | |
1520 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | |
1521 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | |
1522 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | |
1523 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | |
b481de9c | 1524 | u8 start_action = tbl->action; |
fde0db31 | 1525 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
3110bef7 | 1526 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
d6e93399 | 1527 | u8 update_search_tbl_counter = 0; |
fde0db31 | 1528 | int ret; |
b481de9c ZY |
1529 | |
1530 | for (;;) { | |
c33104f0 | 1531 | lq_sta->action_counter++; |
b481de9c | 1532 | switch (tbl->action) { |
3110bef7 GC |
1533 | case IWL_SISO_SWITCH_ANTENNA1: |
1534 | case IWL_SISO_SWITCH_ANTENNA2: | |
e1623446 | 1535 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n"); |
3110bef7 GC |
1536 | |
1537 | if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 && | |
1538 | tx_chains_num <= 1) || | |
1539 | (tbl->action == IWL_SISO_SWITCH_ANTENNA2 && | |
1540 | tx_chains_num <= 2)) | |
1541 | break; | |
1542 | ||
b481de9c ZY |
1543 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) |
1544 | break; | |
b481de9c ZY |
1545 | |
1546 | memcpy(search_tbl, tbl, sz); | |
aade00ce | 1547 | if (rs_toggle_antenna(valid_tx_ant, |
d6e93399 MA |
1548 | &search_tbl->current_rate, search_tbl)) { |
1549 | update_search_tbl_counter = 1; | |
aade00ce | 1550 | goto out; |
d6e93399 | 1551 | } |
a5e8b505 | 1552 | break; |
3110bef7 GC |
1553 | case IWL_SISO_SWITCH_MIMO2_AB: |
1554 | case IWL_SISO_SWITCH_MIMO2_AC: | |
1555 | case IWL_SISO_SWITCH_MIMO2_BC: | |
e1623446 | 1556 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n"); |
b481de9c | 1557 | memcpy(search_tbl, tbl, sz); |
b481de9c | 1558 | search_tbl->is_SGI = 0; |
3110bef7 GC |
1559 | |
1560 | if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB) | |
1561 | search_tbl->ant_type = ANT_AB; | |
1562 | else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC) | |
1563 | search_tbl->ant_type = ANT_AC; | |
1564 | else | |
1565 | search_tbl->ant_type = ANT_BC; | |
1566 | ||
1567 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1568 | break; | |
1569 | ||
fde0db31 | 1570 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, |
270243a5 | 1571 | search_tbl, index); |
3110bef7 | 1572 | if (!ret) |
b481de9c ZY |
1573 | goto out; |
1574 | break; | |
1575 | case IWL_SISO_SWITCH_GI: | |
a9841013 EG |
1576 | if (!tbl->is_fat && |
1577 | !(priv->current_ht_config.sgf & | |
1578 | HT_SHORT_GI_20MHZ)) | |
1579 | break; | |
1580 | if (tbl->is_fat && | |
1581 | !(priv->current_ht_config.sgf & | |
1582 | HT_SHORT_GI_40MHZ)) | |
1583 | break; | |
1584 | ||
e1623446 | 1585 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n"); |
0c11b4de | 1586 | |
b481de9c | 1587 | memcpy(search_tbl, tbl, sz); |
39e88504 GC |
1588 | if (is_green) { |
1589 | if (!tbl->is_SGI) | |
1590 | break; | |
1591 | else | |
15b1687c WT |
1592 | IWL_ERR(priv, |
1593 | "SGI was set in GF+SISO\n"); | |
b481de9c | 1594 | } |
39e88504 | 1595 | search_tbl->is_SGI = !tbl->is_SGI; |
eecd6e57 | 1596 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
39e88504 GC |
1597 | if (tbl->is_SGI) { |
1598 | s32 tpt = lq_sta->last_tpt / 100; | |
1599 | if (tpt >= search_tbl->expected_tpt[index]) | |
1600 | break; | |
1601 | } | |
978785a3 TW |
1602 | search_tbl->current_rate = |
1603 | rate_n_flags_from_tbl(priv, search_tbl, | |
1604 | index, is_green); | |
d6e93399 | 1605 | update_search_tbl_counter = 1; |
b481de9c | 1606 | goto out; |
584a0f00 WYG |
1607 | case IWL_SISO_SWITCH_MIMO3_ABC: |
1608 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n"); | |
1609 | memcpy(search_tbl, tbl, sz); | |
1610 | search_tbl->is_SGI = 0; | |
1611 | search_tbl->ant_type = ANT_ABC; | |
1612 | ||
1613 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1614 | break; | |
1615 | ||
1616 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | |
1617 | search_tbl, index); | |
1618 | if (!ret) | |
1619 | goto out; | |
1620 | break; | |
b481de9c ZY |
1621 | } |
1622 | tbl->action++; | |
584a0f00 | 1623 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
3110bef7 | 1624 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
b481de9c ZY |
1625 | |
1626 | if (tbl->action == start_action) | |
1627 | break; | |
1628 | } | |
3110bef7 | 1629 | search_tbl->lq_type = LQ_NONE; |
b481de9c ZY |
1630 | return 0; |
1631 | ||
1632 | out: | |
3110bef7 | 1633 | lq_sta->search_better_tbl = 1; |
b481de9c | 1634 | tbl->action++; |
584a0f00 | 1635 | if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC) |
3110bef7 | 1636 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
d6e93399 MA |
1637 | if (update_search_tbl_counter) |
1638 | search_tbl->action = tbl->action; | |
1639 | ||
b481de9c ZY |
1640 | return 0; |
1641 | } | |
1642 | ||
77626355 | 1643 | /* |
584a0f00 | 1644 | * Try to switch to new modulation mode from MIMO2 |
77626355 | 1645 | */ |
584a0f00 | 1646 | static int rs_move_mimo2_to_other(struct iwl_priv *priv, |
e227ceac | 1647 | struct iwl_lq_sta *lq_sta, |
270243a5 | 1648 | struct ieee80211_conf *conf, |
4b7679a5 | 1649 | struct ieee80211_sta *sta, int index) |
b481de9c | 1650 | { |
c33104f0 | 1651 | s8 is_green = lq_sta->is_green; |
e227ceac TW |
1652 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
1653 | struct iwl_scale_tbl_info *search_tbl = | |
1654 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | |
3110bef7 | 1655 | struct iwl_rate_scale_data *window = &(tbl->win[index]); |
e227ceac TW |
1656 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
1657 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | |
b481de9c | 1658 | u8 start_action = tbl->action; |
3110bef7 GC |
1659 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
1660 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | |
d6e93399 | 1661 | u8 update_search_tbl_counter = 0; |
aade00ce | 1662 | int ret; |
b481de9c ZY |
1663 | |
1664 | for (;;) { | |
c33104f0 | 1665 | lq_sta->action_counter++; |
b481de9c | 1666 | switch (tbl->action) { |
3110bef7 GC |
1667 | case IWL_MIMO2_SWITCH_ANTENNA1: |
1668 | case IWL_MIMO2_SWITCH_ANTENNA2: | |
584a0f00 | 1669 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n"); |
3110bef7 GC |
1670 | |
1671 | if (tx_chains_num <= 2) | |
1672 | break; | |
1673 | ||
1674 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) | |
1675 | break; | |
1676 | ||
1677 | memcpy(search_tbl, tbl, sz); | |
1678 | if (rs_toggle_antenna(valid_tx_ant, | |
d6e93399 MA |
1679 | &search_tbl->current_rate, search_tbl)) { |
1680 | update_search_tbl_counter = 1; | |
3110bef7 | 1681 | goto out; |
d6e93399 | 1682 | } |
3110bef7 GC |
1683 | break; |
1684 | case IWL_MIMO2_SWITCH_SISO_A: | |
1685 | case IWL_MIMO2_SWITCH_SISO_B: | |
1686 | case IWL_MIMO2_SWITCH_SISO_C: | |
e1623446 | 1687 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n"); |
0c11b4de | 1688 | |
77626355 | 1689 | /* Set up new search table for SISO */ |
b481de9c | 1690 | memcpy(search_tbl, tbl, sz); |
39e88504 | 1691 | |
3110bef7 | 1692 | if (tbl->action == IWL_MIMO2_SWITCH_SISO_A) |
fde0db31 | 1693 | search_tbl->ant_type = ANT_A; |
3110bef7 | 1694 | else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B) |
fde0db31 | 1695 | search_tbl->ant_type = ANT_B; |
3110bef7 GC |
1696 | else |
1697 | search_tbl->ant_type = ANT_C; | |
1698 | ||
1699 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1700 | break; | |
b481de9c | 1701 | |
c33104f0 | 1702 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, |
270243a5 | 1703 | search_tbl, index); |
3110bef7 | 1704 | if (!ret) |
b481de9c | 1705 | goto out; |
3110bef7 | 1706 | |
b481de9c ZY |
1707 | break; |
1708 | ||
3110bef7 | 1709 | case IWL_MIMO2_SWITCH_GI: |
a9841013 EG |
1710 | if (!tbl->is_fat && |
1711 | !(priv->current_ht_config.sgf & | |
1712 | HT_SHORT_GI_20MHZ)) | |
1713 | break; | |
1714 | if (tbl->is_fat && | |
1715 | !(priv->current_ht_config.sgf & | |
1716 | HT_SHORT_GI_40MHZ)) | |
1717 | break; | |
1718 | ||
584a0f00 | 1719 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n"); |
77626355 | 1720 | |
584a0f00 | 1721 | /* Set up new search table for MIMO2 */ |
b481de9c | 1722 | memcpy(search_tbl, tbl, sz); |
39e88504 | 1723 | search_tbl->is_SGI = !tbl->is_SGI; |
eecd6e57 | 1724 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
77626355 BC |
1725 | /* |
1726 | * If active table already uses the fastest possible | |
1727 | * modulation (dual stream with short guard interval), | |
1728 | * and it's working well, there's no need to look | |
1729 | * for a better type of modulation! | |
1730 | */ | |
39e88504 | 1731 | if (tbl->is_SGI) { |
c33104f0 | 1732 | s32 tpt = lq_sta->last_tpt / 100; |
39e88504 GC |
1733 | if (tpt >= search_tbl->expected_tpt[index]) |
1734 | break; | |
b481de9c | 1735 | } |
978785a3 TW |
1736 | search_tbl->current_rate = |
1737 | rate_n_flags_from_tbl(priv, search_tbl, | |
1738 | index, is_green); | |
d6e93399 | 1739 | update_search_tbl_counter = 1; |
b481de9c ZY |
1740 | goto out; |
1741 | ||
584a0f00 WYG |
1742 | case IWL_MIMO2_SWITCH_MIMO3_ABC: |
1743 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n"); | |
1744 | memcpy(search_tbl, tbl, sz); | |
1745 | search_tbl->is_SGI = 0; | |
1746 | search_tbl->ant_type = ANT_ABC; | |
1747 | ||
1748 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1749 | break; | |
1750 | ||
1751 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | |
1752 | search_tbl, index); | |
1753 | if (!ret) | |
1754 | goto out; | |
1755 | ||
1756 | break; | |
b481de9c ZY |
1757 | } |
1758 | tbl->action++; | |
584a0f00 | 1759 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) |
3110bef7 | 1760 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; |
b481de9c ZY |
1761 | |
1762 | if (tbl->action == start_action) | |
1763 | break; | |
1764 | } | |
3110bef7 | 1765 | search_tbl->lq_type = LQ_NONE; |
b481de9c ZY |
1766 | return 0; |
1767 | out: | |
3110bef7 | 1768 | lq_sta->search_better_tbl = 1; |
b481de9c | 1769 | tbl->action++; |
584a0f00 | 1770 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) |
3110bef7 | 1771 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; |
d6e93399 MA |
1772 | if (update_search_tbl_counter) |
1773 | search_tbl->action = tbl->action; | |
1774 | ||
b481de9c ZY |
1775 | return 0; |
1776 | ||
1777 | } | |
1778 | ||
584a0f00 WYG |
1779 | /* |
1780 | * Try to switch to new modulation mode from MIMO3 | |
1781 | */ | |
1782 | static int rs_move_mimo3_to_other(struct iwl_priv *priv, | |
1783 | struct iwl_lq_sta *lq_sta, | |
1784 | struct ieee80211_conf *conf, | |
1785 | struct ieee80211_sta *sta, int index) | |
1786 | { | |
1787 | s8 is_green = lq_sta->is_green; | |
1788 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | |
1789 | struct iwl_scale_tbl_info *search_tbl = | |
1790 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | |
1791 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | |
1792 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | |
1793 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | |
1794 | u8 start_action = tbl->action; | |
1795 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; | |
1796 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | |
1797 | int ret; | |
d6e93399 | 1798 | u8 update_search_tbl_counter = 0; |
584a0f00 WYG |
1799 | |
1800 | for (;;) { | |
1801 | lq_sta->action_counter++; | |
1802 | switch (tbl->action) { | |
1803 | case IWL_MIMO3_SWITCH_ANTENNA1: | |
1804 | case IWL_MIMO3_SWITCH_ANTENNA2: | |
1805 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n"); | |
1806 | ||
1807 | if (tx_chains_num <= 3) | |
1808 | break; | |
1809 | ||
1810 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) | |
1811 | break; | |
1812 | ||
1813 | memcpy(search_tbl, tbl, sz); | |
1814 | if (rs_toggle_antenna(valid_tx_ant, | |
1815 | &search_tbl->current_rate, search_tbl)) | |
1816 | goto out; | |
1817 | break; | |
1818 | case IWL_MIMO3_SWITCH_SISO_A: | |
1819 | case IWL_MIMO3_SWITCH_SISO_B: | |
1820 | case IWL_MIMO3_SWITCH_SISO_C: | |
1821 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n"); | |
1822 | ||
1823 | /* Set up new search table for SISO */ | |
1824 | memcpy(search_tbl, tbl, sz); | |
1825 | ||
1826 | if (tbl->action == IWL_MIMO3_SWITCH_SISO_A) | |
1827 | search_tbl->ant_type = ANT_A; | |
1828 | else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B) | |
1829 | search_tbl->ant_type = ANT_B; | |
1830 | else | |
1831 | search_tbl->ant_type = ANT_C; | |
1832 | ||
1833 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1834 | break; | |
1835 | ||
1836 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, | |
1837 | search_tbl, index); | |
1838 | if (!ret) | |
1839 | goto out; | |
1840 | ||
1841 | break; | |
1842 | ||
1843 | case IWL_MIMO3_SWITCH_MIMO2_AB: | |
1844 | case IWL_MIMO3_SWITCH_MIMO2_AC: | |
1845 | case IWL_MIMO3_SWITCH_MIMO2_BC: | |
1846 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n"); | |
1847 | ||
1848 | memcpy(search_tbl, tbl, sz); | |
1849 | search_tbl->is_SGI = 0; | |
1850 | if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB) | |
1851 | search_tbl->ant_type = ANT_AB; | |
1852 | else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC) | |
1853 | search_tbl->ant_type = ANT_AC; | |
1854 | else | |
1855 | search_tbl->ant_type = ANT_BC; | |
1856 | ||
1857 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | |
1858 | break; | |
1859 | ||
1860 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, | |
1861 | search_tbl, index); | |
1862 | if (!ret) | |
1863 | goto out; | |
1864 | ||
1865 | break; | |
1866 | ||
1867 | case IWL_MIMO3_SWITCH_GI: | |
1868 | if (!tbl->is_fat && | |
1869 | !(priv->current_ht_config.sgf & | |
1870 | HT_SHORT_GI_20MHZ)) | |
1871 | break; | |
1872 | if (tbl->is_fat && | |
1873 | !(priv->current_ht_config.sgf & | |
1874 | HT_SHORT_GI_40MHZ)) | |
1875 | break; | |
1876 | ||
1877 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n"); | |
1878 | ||
1879 | /* Set up new search table for MIMO */ | |
1880 | memcpy(search_tbl, tbl, sz); | |
1881 | search_tbl->is_SGI = !tbl->is_SGI; | |
1882 | rs_set_expected_tpt_table(lq_sta, search_tbl); | |
1883 | /* | |
1884 | * If active table already uses the fastest possible | |
1885 | * modulation (dual stream with short guard interval), | |
1886 | * and it's working well, there's no need to look | |
1887 | * for a better type of modulation! | |
1888 | */ | |
1889 | if (tbl->is_SGI) { | |
1890 | s32 tpt = lq_sta->last_tpt / 100; | |
1891 | if (tpt >= search_tbl->expected_tpt[index]) | |
1892 | break; | |
1893 | } | |
1894 | search_tbl->current_rate = | |
1895 | rate_n_flags_from_tbl(priv, search_tbl, | |
1896 | index, is_green); | |
d6e93399 | 1897 | update_search_tbl_counter = 1; |
584a0f00 WYG |
1898 | goto out; |
1899 | } | |
1900 | tbl->action++; | |
1901 | if (tbl->action > IWL_MIMO3_SWITCH_GI) | |
1902 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; | |
1903 | ||
1904 | if (tbl->action == start_action) | |
1905 | break; | |
1906 | } | |
1907 | search_tbl->lq_type = LQ_NONE; | |
1908 | return 0; | |
1909 | out: | |
1910 | lq_sta->search_better_tbl = 1; | |
1911 | tbl->action++; | |
1912 | if (tbl->action > IWL_MIMO3_SWITCH_GI) | |
1913 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; | |
d6e93399 MA |
1914 | if (update_search_tbl_counter) |
1915 | search_tbl->action = tbl->action; | |
1916 | ||
584a0f00 WYG |
1917 | return 0; |
1918 | ||
1919 | } | |
1920 | ||
77626355 BC |
1921 | /* |
1922 | * Check whether we should continue using same modulation mode, or | |
1923 | * begin search for a new mode, based on: | |
1924 | * 1) # tx successes or failures while using this mode | |
1925 | * 2) # times calling this function | |
1926 | * 3) elapsed time in this mode (not used, for now) | |
1927 | */ | |
e227ceac | 1928 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta) |
b481de9c | 1929 | { |
e227ceac | 1930 | struct iwl_scale_tbl_info *tbl; |
b481de9c ZY |
1931 | int i; |
1932 | int active_tbl; | |
1933 | int flush_interval_passed = 0; | |
bf403db8 | 1934 | struct iwl_priv *priv; |
b481de9c | 1935 | |
bf403db8 | 1936 | priv = lq_sta->drv; |
c33104f0 | 1937 | active_tbl = lq_sta->active_tbl; |
b481de9c | 1938 | |
c33104f0 | 1939 | tbl = &(lq_sta->lq_info[active_tbl]); |
b481de9c | 1940 | |
77626355 | 1941 | /* If we've been disallowing search, see if we should now allow it */ |
c33104f0 | 1942 | if (lq_sta->stay_in_tbl) { |
b481de9c | 1943 | |
77626355 | 1944 | /* Elapsed time using current modulation mode */ |
c33104f0 | 1945 | if (lq_sta->flush_timer) |
b481de9c | 1946 | flush_interval_passed = |
447fee70 MA |
1947 | time_after(jiffies, |
1948 | (unsigned long)(lq_sta->flush_timer + | |
b481de9c ZY |
1949 | IWL_RATE_SCALE_FLUSH_INTVL)); |
1950 | ||
77626355 BC |
1951 | /* |
1952 | * Check if we should allow search for new modulation mode. | |
1953 | * If many frames have failed or succeeded, or we've used | |
1954 | * this same modulation for a long time, allow search, and | |
1955 | * reset history stats that keep track of whether we should | |
1956 | * allow a new search. Also (below) reset all bitmaps and | |
1957 | * stats in active history. | |
1958 | */ | |
c33104f0 TW |
1959 | if ((lq_sta->total_failed > lq_sta->max_failure_limit) || |
1960 | (lq_sta->total_success > lq_sta->max_success_limit) || | |
1961 | ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) | |
b481de9c | 1962 | && (flush_interval_passed))) { |
e1623446 | 1963 | IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n:", |
c33104f0 TW |
1964 | lq_sta->total_failed, |
1965 | lq_sta->total_success, | |
b481de9c | 1966 | flush_interval_passed); |
77626355 BC |
1967 | |
1968 | /* Allow search for new mode */ | |
c33104f0 TW |
1969 | lq_sta->stay_in_tbl = 0; /* only place reset */ |
1970 | lq_sta->total_failed = 0; | |
1971 | lq_sta->total_success = 0; | |
1972 | lq_sta->flush_timer = 0; | |
77626355 BC |
1973 | |
1974 | /* | |
1975 | * Else if we've used this modulation mode enough repetitions | |
1976 | * (regardless of elapsed time or success/failure), reset | |
1977 | * history bitmaps and rate-specific stats for all rates in | |
1978 | * active table. | |
1979 | */ | |
403ab56b | 1980 | } else { |
c33104f0 TW |
1981 | lq_sta->table_count++; |
1982 | if (lq_sta->table_count >= | |
1983 | lq_sta->table_count_limit) { | |
1984 | lq_sta->table_count = 0; | |
b481de9c | 1985 | |
e1623446 | 1986 | IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n"); |
b481de9c ZY |
1987 | for (i = 0; i < IWL_RATE_COUNT; i++) |
1988 | rs_rate_scale_clear_window( | |
1989 | &(tbl->win[i])); | |
1990 | } | |
1991 | } | |
1992 | ||
77626355 BC |
1993 | /* If transitioning to allow "search", reset all history |
1994 | * bitmaps and stats in active table (this will become the new | |
1995 | * "search" table). */ | |
c33104f0 | 1996 | if (!lq_sta->stay_in_tbl) { |
b481de9c ZY |
1997 | for (i = 0; i < IWL_RATE_COUNT; i++) |
1998 | rs_rate_scale_clear_window(&(tbl->win[i])); | |
1999 | } | |
2000 | } | |
2001 | } | |
2002 | ||
77626355 BC |
2003 | /* |
2004 | * Do rate scaling and search for new modulation mode. | |
2005 | */ | |
c79dd5b5 | 2006 | static void rs_rate_scale_perform(struct iwl_priv *priv, |
514d65c1 | 2007 | struct sk_buff *skb, |
4b7679a5 JB |
2008 | struct ieee80211_sta *sta, |
2009 | struct iwl_lq_sta *lq_sta) | |
b481de9c | 2010 | { |
4b7679a5 | 2011 | struct ieee80211_hw *hw = priv->hw; |
270243a5 | 2012 | struct ieee80211_conf *conf = &hw->conf; |
514d65c1 GS |
2013 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
2014 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
b481de9c ZY |
2015 | int low = IWL_RATE_INVALID; |
2016 | int high = IWL_RATE_INVALID; | |
2017 | int index; | |
2018 | int i; | |
e227ceac | 2019 | struct iwl_rate_scale_data *window = NULL; |
b481de9c ZY |
2020 | int current_tpt = IWL_INVALID_VALUE; |
2021 | int low_tpt = IWL_INVALID_VALUE; | |
2022 | int high_tpt = IWL_INVALID_VALUE; | |
2023 | u32 fail_count; | |
2024 | s8 scale_action = 0; | |
fd7c8a40 | 2025 | u16 rate_mask; |
b481de9c | 2026 | u8 update_lq = 0; |
e227ceac | 2027 | struct iwl_scale_tbl_info *tbl, *tbl1; |
b481de9c | 2028 | u16 rate_scale_index_msk = 0; |
39e88504 | 2029 | u32 rate; |
b481de9c ZY |
2030 | u8 is_green = 0; |
2031 | u8 active_tbl = 0; | |
2032 | u8 done_search = 0; | |
2033 | u16 high_low; | |
a5e8b505 | 2034 | s32 sr; |
0c11b4de | 2035 | u8 tid = MAX_TID_COUNT; |
86b4766b | 2036 | struct iwl_tid_data *tid_data; |
b481de9c | 2037 | |
e1623446 | 2038 | IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); |
b481de9c | 2039 | |
514d65c1 | 2040 | /* Send management frames and NO_ACK data using lowest rate. */ |
417f114b TW |
2041 | /* TODO: this could probably be improved.. */ |
2042 | if (!ieee80211_is_data(hdr->frame_control) || | |
514d65c1 | 2043 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
b481de9c | 2044 | return; |
b481de9c | 2045 | |
4b7679a5 | 2046 | if (!sta || !lq_sta) |
b481de9c ZY |
2047 | return; |
2048 | ||
4b7679a5 | 2049 | lq_sta->supp_rates = sta->supp_rates[lq_sta->band]; |
b481de9c | 2050 | |
faa29718 RR |
2051 | tid = rs_tl_add_packet(lq_sta, hdr); |
2052 | ||
77626355 BC |
2053 | /* |
2054 | * Select rate-scale / modulation-mode table to work with in | |
2055 | * the rest of this function: "search" if searching for better | |
2056 | * modulation mode, or "active" if doing rate scaling within a mode. | |
2057 | */ | |
c33104f0 TW |
2058 | if (!lq_sta->search_better_tbl) |
2059 | active_tbl = lq_sta->active_tbl; | |
b481de9c | 2060 | else |
c33104f0 | 2061 | active_tbl = 1 - lq_sta->active_tbl; |
b481de9c | 2062 | |
c33104f0 | 2063 | tbl = &(lq_sta->lq_info[active_tbl]); |
2681b20b WYG |
2064 | if (is_legacy(tbl->lq_type)) |
2065 | lq_sta->is_green = 0; | |
2066 | else | |
2067 | lq_sta->is_green = rs_use_green(priv, conf); | |
c33104f0 | 2068 | is_green = lq_sta->is_green; |
b481de9c | 2069 | |
77626355 | 2070 | /* current tx rate */ |
b7e35008 | 2071 | index = lq_sta->last_txrate_idx; |
b481de9c | 2072 | |
e1623446 | 2073 | IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index, |
b481de9c ZY |
2074 | tbl->lq_type); |
2075 | ||
77626355 | 2076 | /* rates available for this association, and for modulation mode */ |
eecd6e57 | 2077 | rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type); |
b481de9c | 2078 | |
e1623446 | 2079 | IWL_DEBUG_RATE(priv, "mask 0x%04X \n", rate_mask); |
b481de9c ZY |
2080 | |
2081 | /* mask with station rate restriction */ | |
2082 | if (is_legacy(tbl->lq_type)) { | |
8318d78a | 2083 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
77626355 | 2084 | /* supp_rates has no CCK bits in A mode */ |
b481de9c | 2085 | rate_scale_index_msk = (u16) (rate_mask & |
c33104f0 | 2086 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); |
b481de9c ZY |
2087 | else |
2088 | rate_scale_index_msk = (u16) (rate_mask & | |
c33104f0 | 2089 | lq_sta->supp_rates); |
b481de9c ZY |
2090 | |
2091 | } else | |
2092 | rate_scale_index_msk = rate_mask; | |
2093 | ||
2094 | if (!rate_scale_index_msk) | |
2095 | rate_scale_index_msk = rate_mask; | |
2096 | ||
07bc28ed | 2097 | if (!((1 << index) & rate_scale_index_msk)) { |
15b1687c | 2098 | IWL_ERR(priv, "Current Rate is not valid\n"); |
07bc28ed | 2099 | return; |
b481de9c ZY |
2100 | } |
2101 | ||
77626355 | 2102 | /* Get expected throughput table and history window for current rate */ |
07bc28ed | 2103 | if (!tbl->expected_tpt) { |
15b1687c | 2104 | IWL_ERR(priv, "tbl->expected_tpt is NULL\n"); |
07bc28ed GC |
2105 | return; |
2106 | } | |
b481de9c | 2107 | |
c6ec7a9b AM |
2108 | /* force user max rate if set by user */ |
2109 | if ((lq_sta->max_rate_idx != -1) && | |
2110 | (lq_sta->max_rate_idx < index)) { | |
2111 | index = lq_sta->max_rate_idx; | |
2112 | update_lq = 1; | |
2113 | window = &(tbl->win[index]); | |
2114 | goto lq_update; | |
2115 | } | |
2116 | ||
b481de9c ZY |
2117 | window = &(tbl->win[index]); |
2118 | ||
77626355 BC |
2119 | /* |
2120 | * If there is not enough history to calculate actual average | |
2121 | * throughput, keep analyzing results of more tx frames, without | |
2122 | * changing rate or mode (bypass most of the rest of this function). | |
2123 | * Set up new rate table in uCode only if old rate is not supported | |
2124 | * in current association (use new rate found above). | |
2125 | */ | |
b481de9c | 2126 | fail_count = window->counter - window->success_counter; |
07bc28ed GC |
2127 | if ((fail_count < IWL_RATE_MIN_FAILURE_TH) && |
2128 | (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) { | |
e1623446 | 2129 | IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d " |
b481de9c ZY |
2130 | "for index %d\n", |
2131 | window->success_counter, window->counter, index); | |
77626355 BC |
2132 | |
2133 | /* Can't calculate this yet; not enough history */ | |
b481de9c | 2134 | window->average_tpt = IWL_INVALID_VALUE; |
77626355 BC |
2135 | |
2136 | /* Should we stay with this modulation mode, | |
2137 | * or search for a new one? */ | |
c33104f0 | 2138 | rs_stay_in_table(lq_sta); |
77626355 | 2139 | |
b481de9c | 2140 | goto out; |
3110bef7 | 2141 | } |
b481de9c | 2142 | |
77626355 BC |
2143 | /* Else we have enough samples; calculate estimate of |
2144 | * actual average throughput */ | |
3110bef7 GC |
2145 | |
2146 | BUG_ON(window->average_tpt != ((window->success_ratio * | |
2147 | tbl->expected_tpt[index] + 64) / 128)); | |
b481de9c | 2148 | |
77626355 | 2149 | /* If we are searching for better modulation mode, check success. */ |
c33104f0 | 2150 | if (lq_sta->search_better_tbl) { |
b481de9c | 2151 | |
77626355 BC |
2152 | /* If good success, continue using the "search" mode; |
2153 | * no need to send new link quality command, since we're | |
2154 | * continuing to use the setup that we've been trying. */ | |
07bc28ed GC |
2155 | if (window->average_tpt > lq_sta->last_tpt) { |
2156 | ||
e1623446 | 2157 | IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE " |
07bc28ed GC |
2158 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
2159 | window->success_ratio, | |
2160 | window->average_tpt, | |
2161 | lq_sta->last_tpt); | |
2162 | ||
2163 | if (!is_legacy(tbl->lq_type)) | |
c33104f0 | 2164 | lq_sta->enable_counter = 1; |
07bc28ed | 2165 | |
77626355 | 2166 | /* Swap tables; "search" becomes "active" */ |
c33104f0 | 2167 | lq_sta->active_tbl = active_tbl; |
b481de9c | 2168 | current_tpt = window->average_tpt; |
77626355 BC |
2169 | |
2170 | /* Else poor success; go back to mode in "active" table */ | |
b481de9c | 2171 | } else { |
07bc28ed | 2172 | |
e1623446 | 2173 | IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE " |
07bc28ed GC |
2174 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
2175 | window->success_ratio, | |
2176 | window->average_tpt, | |
2177 | lq_sta->last_tpt); | |
2178 | ||
77626355 | 2179 | /* Nullify "search" table */ |
b481de9c | 2180 | tbl->lq_type = LQ_NONE; |
77626355 BC |
2181 | |
2182 | /* Revert to "active" table */ | |
c33104f0 TW |
2183 | active_tbl = lq_sta->active_tbl; |
2184 | tbl = &(lq_sta->lq_info[active_tbl]); | |
b481de9c | 2185 | |
77626355 | 2186 | /* Revert to "active" rate and throughput info */ |
e7d326ac | 2187 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); |
c33104f0 | 2188 | current_tpt = lq_sta->last_tpt; |
b481de9c | 2189 | |
77626355 | 2190 | /* Need to set up a new rate table in uCode */ |
b481de9c | 2191 | update_lq = 1; |
b481de9c | 2192 | } |
77626355 BC |
2193 | |
2194 | /* Either way, we've made a decision; modulation mode | |
2195 | * search is done, allow rate adjustment next time. */ | |
c33104f0 | 2196 | lq_sta->search_better_tbl = 0; |
77626355 | 2197 | done_search = 1; /* Don't switch modes below! */ |
b481de9c ZY |
2198 | goto lq_update; |
2199 | } | |
2200 | ||
77626355 BC |
2201 | /* (Else) not in search of better modulation mode, try for better |
2202 | * starting rate, while staying in this mode. */ | |
bf403db8 | 2203 | high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk, |
b481de9c ZY |
2204 | tbl->lq_type); |
2205 | low = high_low & 0xff; | |
2206 | high = (high_low >> 8) & 0xff; | |
2207 | ||
c6ec7a9b AM |
2208 | /* If user set max rate, dont allow higher than user constrain */ |
2209 | if ((lq_sta->max_rate_idx != -1) && | |
2210 | (lq_sta->max_rate_idx < high)) | |
2211 | high = IWL_RATE_INVALID; | |
2212 | ||
a5e8b505 GC |
2213 | sr = window->success_ratio; |
2214 | ||
77626355 | 2215 | /* Collect measured throughputs for current and adjacent rates */ |
b481de9c | 2216 | current_tpt = window->average_tpt; |
b481de9c ZY |
2217 | if (low != IWL_RATE_INVALID) |
2218 | low_tpt = tbl->win[low].average_tpt; | |
b481de9c ZY |
2219 | if (high != IWL_RATE_INVALID) |
2220 | high_tpt = tbl->win[high].average_tpt; | |
2221 | ||
a5e8b505 | 2222 | scale_action = 0; |
b481de9c | 2223 | |
77626355 | 2224 | /* Too many failures, decrease rate */ |
a5e8b505 | 2225 | if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) { |
e1623446 | 2226 | IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n"); |
b481de9c | 2227 | scale_action = -1; |
77626355 BC |
2228 | |
2229 | /* No throughput measured yet for adjacent rates; try increase. */ | |
b481de9c | 2230 | } else if ((low_tpt == IWL_INVALID_VALUE) && |
a5e8b505 GC |
2231 | (high_tpt == IWL_INVALID_VALUE)) { |
2232 | ||
2233 | if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH) | |
2234 | scale_action = 1; | |
2235 | else if (low != IWL_RATE_INVALID) | |
8fe72311 | 2236 | scale_action = 0; |
a5e8b505 | 2237 | } |
77626355 BC |
2238 | |
2239 | /* Both adjacent throughputs are measured, but neither one has better | |
2240 | * throughput; we're using the best rate, don't change it! */ | |
b481de9c ZY |
2241 | else if ((low_tpt != IWL_INVALID_VALUE) && |
2242 | (high_tpt != IWL_INVALID_VALUE) && | |
2243 | (low_tpt < current_tpt) && | |
2244 | (high_tpt < current_tpt)) | |
2245 | scale_action = 0; | |
77626355 BC |
2246 | |
2247 | /* At least one adjacent rate's throughput is measured, | |
2248 | * and may have better performance. */ | |
b481de9c | 2249 | else { |
77626355 | 2250 | /* Higher adjacent rate's throughput is measured */ |
b481de9c | 2251 | if (high_tpt != IWL_INVALID_VALUE) { |
77626355 | 2252 | /* Higher rate has better throughput */ |
a5e8b505 GC |
2253 | if (high_tpt > current_tpt && |
2254 | sr >= IWL_RATE_INCREASE_TH) { | |
b481de9c | 2255 | scale_action = 1; |
a5e8b505 | 2256 | } else { |
8fe72311 | 2257 | scale_action = 0; |
b481de9c | 2258 | } |
77626355 BC |
2259 | |
2260 | /* Lower adjacent rate's throughput is measured */ | |
b481de9c | 2261 | } else if (low_tpt != IWL_INVALID_VALUE) { |
77626355 | 2262 | /* Lower rate has better throughput */ |
b481de9c | 2263 | if (low_tpt > current_tpt) { |
e1623446 TW |
2264 | IWL_DEBUG_RATE(priv, |
2265 | "decrease rate because of low tpt\n"); | |
b481de9c | 2266 | scale_action = -1; |
a5e8b505 | 2267 | } else if (sr >= IWL_RATE_INCREASE_TH) { |
b481de9c | 2268 | scale_action = 1; |
a5e8b505 | 2269 | } |
b481de9c ZY |
2270 | } |
2271 | } | |
2272 | ||
77626355 BC |
2273 | /* Sanity check; asked for decrease, but success rate or throughput |
2274 | * has been good at old rate. Don't change it. */ | |
a5e8b505 GC |
2275 | if ((scale_action == -1) && (low != IWL_RATE_INVALID) && |
2276 | ((sr > IWL_RATE_HIGH_TH) || | |
b481de9c | 2277 | (current_tpt > (100 * tbl->expected_tpt[low])))) |
b481de9c ZY |
2278 | scale_action = 0; |
2279 | ||
2280 | switch (scale_action) { | |
2281 | case -1: | |
77626355 | 2282 | /* Decrease starting rate, update uCode's rate table */ |
b481de9c ZY |
2283 | if (low != IWL_RATE_INVALID) { |
2284 | update_lq = 1; | |
2285 | index = low; | |
2286 | } | |
447fee70 | 2287 | |
b481de9c ZY |
2288 | break; |
2289 | case 1: | |
77626355 | 2290 | /* Increase starting rate, update uCode's rate table */ |
b481de9c ZY |
2291 | if (high != IWL_RATE_INVALID) { |
2292 | update_lq = 1; | |
2293 | index = high; | |
2294 | } | |
2295 | ||
2296 | break; | |
2297 | case 0: | |
77626355 | 2298 | /* No change */ |
b481de9c ZY |
2299 | default: |
2300 | break; | |
2301 | } | |
2302 | ||
e1623446 | 2303 | IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d " |
b481de9c ZY |
2304 | "high %d type %d\n", |
2305 | index, scale_action, low, high, tbl->lq_type); | |
2306 | ||
a5e8b505 | 2307 | lq_update: |
77626355 | 2308 | /* Replace uCode's rate table for the destination station. */ |
b481de9c | 2309 | if (update_lq) { |
978785a3 | 2310 | rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); |
07bc28ed | 2311 | rs_fill_link_cmd(priv, lq_sta, rate); |
66c73db7 | 2312 | iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); |
b481de9c | 2313 | } |
77626355 BC |
2314 | |
2315 | /* Should we stay with this modulation mode, or search for a new one? */ | |
c33104f0 | 2316 | rs_stay_in_table(lq_sta); |
b481de9c | 2317 | |
77626355 BC |
2318 | /* |
2319 | * Search for new modulation mode if we're: | |
2320 | * 1) Not changing rates right now | |
2321 | * 2) Not just finishing up a search | |
2322 | * 3) Allowing a new search | |
2323 | */ | |
47cfd463 | 2324 | if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) { |
77626355 | 2325 | /* Save current throughput to compare with "search" throughput*/ |
c33104f0 | 2326 | lq_sta->last_tpt = current_tpt; |
b481de9c | 2327 | |
77626355 BC |
2328 | /* Select a new "search" modulation mode to try. |
2329 | * If one is found, set up the new "search" table. */ | |
b481de9c | 2330 | if (is_legacy(tbl->lq_type)) |
c33104f0 | 2331 | rs_move_legacy_other(priv, lq_sta, conf, sta, index); |
b481de9c | 2332 | else if (is_siso(tbl->lq_type)) |
c33104f0 | 2333 | rs_move_siso_to_other(priv, lq_sta, conf, sta, index); |
584a0f00 WYG |
2334 | else if (is_mimo2(tbl->lq_type)) |
2335 | rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index); | |
b481de9c | 2336 | else |
584a0f00 | 2337 | rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index); |
b481de9c | 2338 | |
77626355 | 2339 | /* If new "search" mode was selected, set up in uCode table */ |
c33104f0 | 2340 | if (lq_sta->search_better_tbl) { |
77626355 | 2341 | /* Access the "search" table, clear its history. */ |
c33104f0 | 2342 | tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
b481de9c ZY |
2343 | for (i = 0; i < IWL_RATE_COUNT; i++) |
2344 | rs_rate_scale_clear_window(&(tbl->win[i])); | |
2345 | ||
77626355 | 2346 | /* Use new "search" start rate */ |
e7d326ac | 2347 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); |
b481de9c | 2348 | |
e1623446 | 2349 | IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n", |
39e88504 | 2350 | tbl->current_rate, index); |
07bc28ed | 2351 | rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); |
66c73db7 | 2352 | iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); |
447fee70 MA |
2353 | } else |
2354 | done_search = 1; | |
2355 | } | |
b481de9c | 2356 | |
447fee70 | 2357 | if (done_search && !lq_sta->stay_in_tbl) { |
77626355 BC |
2358 | /* If the "active" (non-search) mode was legacy, |
2359 | * and we've tried switching antennas, | |
2360 | * but we haven't been able to try HT modes (not available), | |
2361 | * stay with best antenna legacy modulation for a while | |
2362 | * before next round of mode comparisons. */ | |
c33104f0 | 2363 | tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); |
de27e64e | 2364 | if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) && |
d6e93399 | 2365 | lq_sta->action_counter > tbl1->max_search) { |
e1623446 | 2366 | IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n"); |
bf403db8 | 2367 | rs_set_stay_in_table(priv, 1, lq_sta); |
b481de9c ZY |
2368 | } |
2369 | ||
77626355 BC |
2370 | /* If we're in an HT mode, and all 3 mode switch actions |
2371 | * have been tried and compared, stay in this best modulation | |
2372 | * mode for a while before next round of mode comparisons. */ | |
c33104f0 | 2373 | if (lq_sta->enable_counter && |
d6e93399 | 2374 | (lq_sta->action_counter >= tbl1->max_search)) { |
0c11b4de RR |
2375 | if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && |
2376 | (lq_sta->tx_agg_tid_en & (1 << tid)) && | |
2377 | (tid != MAX_TID_COUNT)) { | |
86b4766b WYG |
2378 | tid_data = |
2379 | &priv->stations[lq_sta->lq.sta_id].tid[tid]; | |
2380 | if (tid_data->agg.state == IWL_AGG_OFF) { | |
2381 | IWL_DEBUG_RATE(priv, | |
2382 | "try to aggregate tid %d\n", | |
2383 | tid); | |
2384 | rs_tl_turn_on_agg(priv, tid, | |
2385 | lq_sta, sta); | |
2386 | } | |
b481de9c | 2387 | } |
bf403db8 | 2388 | rs_set_stay_in_table(priv, 0, lq_sta); |
b481de9c | 2389 | } |
b481de9c ZY |
2390 | } |
2391 | ||
2392 | out: | |
978785a3 | 2393 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); |
b481de9c | 2394 | i = index; |
b7e35008 | 2395 | lq_sta->last_txrate_idx = i; |
b481de9c | 2396 | |
b481de9c ZY |
2397 | return; |
2398 | } | |
2399 | ||
2400 | ||
c79dd5b5 | 2401 | static void rs_initialize_lq(struct iwl_priv *priv, |
270243a5 | 2402 | struct ieee80211_conf *conf, |
4b7679a5 JB |
2403 | struct ieee80211_sta *sta, |
2404 | struct iwl_lq_sta *lq_sta) | |
b481de9c | 2405 | { |
e227ceac | 2406 | struct iwl_scale_tbl_info *tbl; |
b481de9c | 2407 | int rate_idx; |
aade00ce | 2408 | int i; |
39e88504 | 2409 | u32 rate; |
aade00ce GC |
2410 | u8 use_green = rs_use_green(priv, conf); |
2411 | u8 active_tbl = 0; | |
2412 | u8 valid_tx_ant; | |
b481de9c | 2413 | |
4b7679a5 | 2414 | if (!sta || !lq_sta) |
b481de9c ZY |
2415 | goto out; |
2416 | ||
b7e35008 | 2417 | i = lq_sta->last_txrate_idx; |
b481de9c | 2418 | |
c33104f0 | 2419 | if ((lq_sta->lq.sta_id == 0xff) && |
05c914fe | 2420 | (priv->iw_mode == NL80211_IFTYPE_ADHOC)) |
b481de9c ZY |
2421 | goto out; |
2422 | ||
aade00ce GC |
2423 | valid_tx_ant = priv->hw_params.valid_tx_ant; |
2424 | ||
c33104f0 TW |
2425 | if (!lq_sta->search_better_tbl) |
2426 | active_tbl = lq_sta->active_tbl; | |
b481de9c | 2427 | else |
c33104f0 | 2428 | active_tbl = 1 - lq_sta->active_tbl; |
b481de9c | 2429 | |
c33104f0 | 2430 | tbl = &(lq_sta->lq_info[active_tbl]); |
b481de9c ZY |
2431 | |
2432 | if ((i < 0) || (i >= IWL_RATE_COUNT)) | |
2433 | i = 0; | |
2434 | ||
1826dcc0 | 2435 | rate = iwl_rates[i].plcp; |
eb48dcaf WT |
2436 | tbl->ant_type = first_antenna(valid_tx_ant); |
2437 | rate |= tbl->ant_type << RATE_MCS_ANT_POS; | |
b481de9c ZY |
2438 | |
2439 | if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) | |
39e88504 | 2440 | rate |= RATE_MCS_CCK_MSK; |
b481de9c | 2441 | |
39e88504 | 2442 | rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx); |
aade00ce GC |
2443 | if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type)) |
2444 | rs_toggle_antenna(valid_tx_ant, &rate, tbl); | |
b481de9c | 2445 | |
978785a3 | 2446 | rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green); |
39e88504 | 2447 | tbl->current_rate = rate; |
eecd6e57 | 2448 | rs_set_expected_tpt_table(lq_sta, tbl); |
07bc28ed | 2449 | rs_fill_link_cmd(NULL, lq_sta, rate); |
66c73db7 | 2450 | iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); |
b481de9c ZY |
2451 | out: |
2452 | return; | |
2453 | } | |
2454 | ||
e6a9854b JB |
2455 | static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta, |
2456 | struct ieee80211_tx_rate_control *txrc) | |
b481de9c ZY |
2457 | { |
2458 | ||
e6a9854b JB |
2459 | struct sk_buff *skb = txrc->skb; |
2460 | struct ieee80211_supported_band *sband = txrc->sband; | |
4b7679a5 JB |
2461 | struct iwl_priv *priv = (struct iwl_priv *)priv_r; |
2462 | struct ieee80211_conf *conf = &priv->hw->conf; | |
b481de9c | 2463 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
e6a9854b | 2464 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
417f114b TW |
2465 | struct iwl_lq_sta *lq_sta = priv_sta; |
2466 | int rate_idx; | |
c338ba3c | 2467 | u64 mask_bit = 0; |
b481de9c | 2468 | |
e1623446 | 2469 | IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n"); |
b481de9c | 2470 | |
c6ec7a9b AM |
2471 | /* Get max rate if user set max rate */ |
2472 | if (lq_sta) { | |
2473 | lq_sta->max_rate_idx = txrc->max_rate_idx; | |
2474 | if ((sband->band == IEEE80211_BAND_5GHZ) && | |
2475 | (lq_sta->max_rate_idx != -1)) | |
2476 | lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE; | |
2477 | if ((lq_sta->max_rate_idx < 0) || | |
2478 | (lq_sta->max_rate_idx >= IWL_RATE_COUNT)) | |
2479 | lq_sta->max_rate_idx = -1; | |
2480 | } | |
2481 | ||
c338ba3c AM |
2482 | if (sta) |
2483 | mask_bit = sta->supp_rates[sband->band]; | |
2484 | ||
514d65c1 | 2485 | /* Send management frames and NO_ACK data using lowest rate. */ |
417f114b | 2486 | if (!ieee80211_is_data(hdr->frame_control) || |
514d65c1 | 2487 | info->flags & IEEE80211_TX_CTL_NO_ACK || !sta || !lq_sta) { |
c338ba3c AM |
2488 | if (!mask_bit) |
2489 | info->control.rates[0].idx = | |
2490 | rate_lowest_index(sband, NULL); | |
2491 | else | |
2492 | info->control.rates[0].idx = | |
2493 | rate_lowest_index(sband, sta); | |
514d65c1 GS |
2494 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) |
2495 | info->control.rates[0].count = 1; | |
4b7679a5 | 2496 | return; |
b481de9c ZY |
2497 | } |
2498 | ||
417f114b | 2499 | rate_idx = lq_sta->last_txrate_idx; |
b481de9c | 2500 | |
05c914fe | 2501 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && |
c33104f0 | 2502 | !lq_sta->ibss_sta_added) { |
e11bc028 AK |
2503 | u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, |
2504 | hdr->addr1); | |
b481de9c ZY |
2505 | |
2506 | if (sta_id == IWL_INVALID_STATION) { | |
e1623446 | 2507 | IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", |
e174961c | 2508 | hdr->addr1); |
06fd3d86 | 2509 | sta_id = priv->cfg->ops->smgmt->add_station(priv, |
e11bc028 AK |
2510 | hdr->addr1, 0, |
2511 | CMD_ASYNC, NULL); | |
b481de9c ZY |
2512 | } |
2513 | if ((sta_id != IWL_INVALID_STATION)) { | |
c33104f0 TW |
2514 | lq_sta->lq.sta_id = sta_id; |
2515 | lq_sta->lq.rs_table[0].rate_n_flags = 0; | |
2516 | lq_sta->ibss_sta_added = 1; | |
4b7679a5 | 2517 | rs_initialize_lq(priv, conf, sta, lq_sta); |
b481de9c | 2518 | } |
b481de9c ZY |
2519 | } |
2520 | ||
417f114b TW |
2521 | if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT) |
2522 | rate_idx = rate_lowest_index(sband, sta); | |
2523 | else if (sband->band == IEEE80211_BAND_5GHZ) | |
2524 | rate_idx -= IWL_FIRST_OFDM_RATE; | |
b481de9c | 2525 | |
417f114b | 2526 | info->control.rates[0].idx = rate_idx; |
b481de9c ZY |
2527 | } |
2528 | ||
4b7679a5 JB |
2529 | static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta, |
2530 | gfp_t gfp) | |
b481de9c | 2531 | { |
e227ceac | 2532 | struct iwl_lq_sta *lq_sta; |
bf403db8 | 2533 | struct iwl_priv *priv; |
b481de9c ZY |
2534 | int i, j; |
2535 | ||
bf403db8 | 2536 | priv = (struct iwl_priv *)priv_rate; |
e1623446 | 2537 | IWL_DEBUG_RATE(priv, "create station rate scale window\n"); |
b481de9c | 2538 | |
e227ceac | 2539 | lq_sta = kzalloc(sizeof(struct iwl_lq_sta), gfp); |
b481de9c | 2540 | |
c33104f0 | 2541 | if (lq_sta == NULL) |
b481de9c | 2542 | return NULL; |
c33104f0 | 2543 | lq_sta->lq.sta_id = 0xff; |
b481de9c | 2544 | |
63fddb9f | 2545 | |
b481de9c ZY |
2546 | for (j = 0; j < LQ_SIZE; j++) |
2547 | for (i = 0; i < IWL_RATE_COUNT; i++) | |
3ac7f146 | 2548 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); |
b481de9c | 2549 | |
c33104f0 | 2550 | return lq_sta; |
b481de9c ZY |
2551 | } |
2552 | ||
4b7679a5 JB |
2553 | static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband, |
2554 | struct ieee80211_sta *sta, void *priv_sta) | |
b481de9c ZY |
2555 | { |
2556 | int i, j; | |
4b7679a5 JB |
2557 | struct iwl_priv *priv = (struct iwl_priv *)priv_r; |
2558 | struct ieee80211_conf *conf = &priv->hw->conf; | |
e227ceac | 2559 | struct iwl_lq_sta *lq_sta = priv_sta; |
d5e49036 | 2560 | u16 mask_bit = 0; |
7d049e5a AM |
2561 | int count; |
2562 | int start_rate = 0; | |
b481de9c | 2563 | |
c33104f0 | 2564 | lq_sta->flush_timer = 0; |
4b7679a5 | 2565 | lq_sta->supp_rates = sta->supp_rates[sband->band]; |
b481de9c ZY |
2566 | for (j = 0; j < LQ_SIZE; j++) |
2567 | for (i = 0; i < IWL_RATE_COUNT; i++) | |
3ac7f146 | 2568 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); |
b481de9c | 2569 | |
e1623446 | 2570 | IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init ***\n"); |
b481de9c ZY |
2571 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
2572 | * the lowest or the highest rate.. Could consider using RSSI from | |
2573 | * previous packets? Need to have IEEE 802.1X auth succeed immediately | |
2574 | * after assoc.. */ | |
2575 | ||
c33104f0 | 2576 | lq_sta->ibss_sta_added = 0; |
05c914fe | 2577 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
e11bc028 AK |
2578 | u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, |
2579 | sta->addr); | |
0795af57 | 2580 | |
b481de9c | 2581 | /* for IBSS the call are from tasklet */ |
e1623446 | 2582 | IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); |
b481de9c ZY |
2583 | |
2584 | if (sta_id == IWL_INVALID_STATION) { | |
e1623446 | 2585 | IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); |
06fd3d86 | 2586 | sta_id = priv->cfg->ops->smgmt->add_station(priv, |
e11bc028 AK |
2587 | sta->addr, 0, |
2588 | CMD_ASYNC, NULL); | |
b481de9c ZY |
2589 | } |
2590 | if ((sta_id != IWL_INVALID_STATION)) { | |
c33104f0 TW |
2591 | lq_sta->lq.sta_id = sta_id; |
2592 | lq_sta->lq.rs_table[0].rate_n_flags = 0; | |
b481de9c ZY |
2593 | } |
2594 | /* FIXME: this is w/a remove it later */ | |
2595 | priv->assoc_station_added = 1; | |
2596 | } | |
2597 | ||
c33104f0 | 2598 | lq_sta->is_dup = 0; |
c6ec7a9b | 2599 | lq_sta->max_rate_idx = -1; |
7d049e5a | 2600 | lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; |
c33104f0 | 2601 | lq_sta->is_green = rs_use_green(priv, conf); |
39e88504 | 2602 | lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000); |
c33104f0 | 2603 | lq_sta->active_rate_basic = priv->active_rate_basic; |
8318d78a | 2604 | lq_sta->band = priv->band; |
77626355 BC |
2605 | /* |
2606 | * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), | |
2607 | * supp_rates[] does not; shift to convert format, force 9 MBits off. | |
2608 | */ | |
ae5eb026 JB |
2609 | lq_sta->active_siso_rate = sta->ht_cap.mcs.rx_mask[0] << 1; |
2610 | lq_sta->active_siso_rate |= sta->ht_cap.mcs.rx_mask[0] & 0x1; | |
c33104f0 | 2611 | lq_sta->active_siso_rate &= ~((u16)0x2); |
fde0db31 | 2612 | lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE; |
b481de9c | 2613 | |
77626355 | 2614 | /* Same here */ |
ae5eb026 JB |
2615 | lq_sta->active_mimo2_rate = sta->ht_cap.mcs.rx_mask[1] << 1; |
2616 | lq_sta->active_mimo2_rate |= sta->ht_cap.mcs.rx_mask[1] & 0x1; | |
fde0db31 GC |
2617 | lq_sta->active_mimo2_rate &= ~((u16)0x2); |
2618 | lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE; | |
2619 | ||
ae5eb026 JB |
2620 | lq_sta->active_mimo3_rate = sta->ht_cap.mcs.rx_mask[2] << 1; |
2621 | lq_sta->active_mimo3_rate |= sta->ht_cap.mcs.rx_mask[2] & 0x1; | |
fde0db31 GC |
2622 | lq_sta->active_mimo3_rate &= ~((u16)0x2); |
2623 | lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE; | |
2624 | ||
e1623446 | 2625 | IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n", |
c33104f0 | 2626 | lq_sta->active_siso_rate, |
fde0db31 GC |
2627 | lq_sta->active_mimo2_rate, |
2628 | lq_sta->active_mimo3_rate); | |
2629 | ||
a96a27f9 | 2630 | /* These values will be overridden later */ |
07bc28ed GC |
2631 | lq_sta->lq.general_params.single_stream_ant_msk = ANT_A; |
2632 | lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB; | |
2633 | ||
0c11b4de RR |
2634 | /* as default allow aggregation for all tids */ |
2635 | lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; | |
c33104f0 | 2636 | lq_sta->drv = priv; |
b481de9c | 2637 | |
d5e49036 | 2638 | /* Find highest tx rate supported by hardware and destination station */ |
7d049e5a AM |
2639 | mask_bit = sta->supp_rates[sband->band]; |
2640 | count = sband->n_bitrates; | |
2641 | if (sband->band == IEEE80211_BAND_5GHZ) { | |
2642 | count += IWL_FIRST_OFDM_RATE; | |
2643 | start_rate = IWL_FIRST_OFDM_RATE; | |
2644 | mask_bit <<= IWL_FIRST_OFDM_RATE; | |
2645 | } | |
2646 | ||
2647 | mask_bit = mask_bit & lq_sta->active_legacy_rate; | |
2648 | lq_sta->last_txrate_idx = 4; | |
2649 | for (i = start_rate; i < count; i++) | |
d5e49036 MA |
2650 | if (mask_bit & BIT(i)) |
2651 | lq_sta->last_txrate_idx = i; | |
2652 | ||
4b7679a5 | 2653 | rs_initialize_lq(priv, conf, sta, lq_sta); |
b481de9c ZY |
2654 | } |
2655 | ||
fde0db31 | 2656 | static void rs_fill_link_cmd(const struct iwl_priv *priv, |
e227ceac | 2657 | struct iwl_lq_sta *lq_sta, u32 new_rate) |
b481de9c | 2658 | { |
e227ceac | 2659 | struct iwl_scale_tbl_info tbl_type; |
b481de9c | 2660 | int index = 0; |
b481de9c | 2661 | int rate_idx; |
1b696de2 | 2662 | int repeat_rate = 0; |
aade00ce | 2663 | u8 ant_toggle_cnt = 0; |
b481de9c | 2664 | u8 use_ht_possible = 1; |
aade00ce | 2665 | u8 valid_tx_ant = 0; |
07bc28ed | 2666 | struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq; |
b481de9c | 2667 | |
77626355 | 2668 | /* Override starting rate (index 0) if needed for debug purposes */ |
39e88504 | 2669 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
98d7e09a | 2670 | |
39e88504 | 2671 | /* Interpret new_rate (rate_n_flags) */ |
aade00ce | 2672 | memset(&tbl_type, 0, sizeof(tbl_type)); |
39e88504 | 2673 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, |
b481de9c ZY |
2674 | &tbl_type, &rate_idx); |
2675 | ||
77626355 | 2676 | /* How many times should we repeat the initial rate? */ |
b481de9c | 2677 | if (is_legacy(tbl_type.lq_type)) { |
aade00ce | 2678 | ant_toggle_cnt = 1; |
1b696de2 | 2679 | repeat_rate = IWL_NUMBER_TRY; |
aade00ce | 2680 | } else { |
1b696de2 | 2681 | repeat_rate = IWL_HT_NUMBER_TRY; |
aade00ce | 2682 | } |
b481de9c ZY |
2683 | |
2684 | lq_cmd->general_params.mimo_delimiter = | |
2685 | is_mimo(tbl_type.lq_type) ? 1 : 0; | |
77626355 BC |
2686 | |
2687 | /* Fill 1st table entry (index 0) */ | |
39e88504 | 2688 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); |
b481de9c | 2689 | |
07bc28ed GC |
2690 | if (num_of_ant(tbl_type.ant_type) == 1) { |
2691 | lq_cmd->general_params.single_stream_ant_msk = | |
2692 | tbl_type.ant_type; | |
2693 | } else if (num_of_ant(tbl_type.ant_type) == 2) { | |
2694 | lq_cmd->general_params.dual_stream_ant_msk = | |
2695 | tbl_type.ant_type; | |
2696 | } /* otherwise we don't modify the existing value */ | |
b481de9c ZY |
2697 | |
2698 | index++; | |
1b696de2 | 2699 | repeat_rate--; |
b481de9c | 2700 | |
aade00ce GC |
2701 | if (priv) |
2702 | valid_tx_ant = priv->hw_params.valid_tx_ant; | |
2703 | ||
77626355 | 2704 | /* Fill rest of rate table */ |
b481de9c | 2705 | while (index < LINK_QUAL_MAX_RETRY_NUM) { |
77626355 BC |
2706 | /* Repeat initial/next rate. |
2707 | * For legacy IWL_NUMBER_TRY == 1, this loop will not execute. | |
2708 | * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ | |
1b696de2 | 2709 | while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { |
b481de9c | 2710 | if (is_legacy(tbl_type.lq_type)) { |
aade00ce GC |
2711 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) |
2712 | ant_toggle_cnt++; | |
2713 | else if (priv && | |
2714 | rs_toggle_antenna(valid_tx_ant, | |
2715 | &new_rate, &tbl_type)) | |
2716 | ant_toggle_cnt = 1; | |
2717 | } | |
98d7e09a | 2718 | |
77626355 | 2719 | /* Override next rate if needed for debug purposes */ |
c33104f0 | 2720 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
77626355 BC |
2721 | |
2722 | /* Fill next table entry */ | |
b481de9c | 2723 | lq_cmd->rs_table[index].rate_n_flags = |
39e88504 | 2724 | cpu_to_le32(new_rate); |
1b696de2 | 2725 | repeat_rate--; |
b481de9c ZY |
2726 | index++; |
2727 | } | |
2728 | ||
39e88504 | 2729 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type, |
b481de9c ZY |
2730 | &rate_idx); |
2731 | ||
77626355 BC |
2732 | /* Indicate to uCode which entries might be MIMO. |
2733 | * If initial rate was MIMO, this will finally end up | |
2734 | * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ | |
b481de9c ZY |
2735 | if (is_mimo(tbl_type.lq_type)) |
2736 | lq_cmd->general_params.mimo_delimiter = index; | |
2737 | ||
77626355 | 2738 | /* Get next rate */ |
39e88504 GC |
2739 | new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, |
2740 | use_ht_possible); | |
b481de9c | 2741 | |
77626355 | 2742 | /* How many times should we repeat the next rate? */ |
b481de9c | 2743 | if (is_legacy(tbl_type.lq_type)) { |
aade00ce GC |
2744 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) |
2745 | ant_toggle_cnt++; | |
2746 | else if (priv && | |
2747 | rs_toggle_antenna(valid_tx_ant, | |
2748 | &new_rate, &tbl_type)) | |
2749 | ant_toggle_cnt = 1; | |
2750 | ||
1b696de2 | 2751 | repeat_rate = IWL_NUMBER_TRY; |
aade00ce | 2752 | } else { |
1b696de2 | 2753 | repeat_rate = IWL_HT_NUMBER_TRY; |
aade00ce | 2754 | } |
b481de9c | 2755 | |
77626355 BC |
2756 | /* Don't allow HT rates after next pass. |
2757 | * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ | |
b481de9c ZY |
2758 | use_ht_possible = 0; |
2759 | ||
77626355 | 2760 | /* Override next rate if needed for debug purposes */ |
c33104f0 | 2761 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
77626355 BC |
2762 | |
2763 | /* Fill next table entry */ | |
39e88504 | 2764 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); |
b481de9c ZY |
2765 | |
2766 | index++; | |
1b696de2 | 2767 | repeat_rate--; |
b481de9c ZY |
2768 | } |
2769 | ||
5e1dd8dc | 2770 | lq_cmd->agg_params.agg_frame_cnt_limit = 64; |
b481de9c ZY |
2771 | lq_cmd->agg_params.agg_dis_start_th = 3; |
2772 | lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); | |
b481de9c ZY |
2773 | } |
2774 | ||
4b7679a5 | 2775 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
b481de9c | 2776 | { |
4b7679a5 | 2777 | return hw->priv; |
b481de9c ZY |
2778 | } |
2779 | /* rate scale requires free function to be implemented */ | |
2780 | static void rs_free(void *priv_rate) | |
2781 | { | |
2782 | return; | |
2783 | } | |
2784 | ||
4b7679a5 JB |
2785 | static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta, |
2786 | void *priv_sta) | |
b481de9c | 2787 | { |
e227ceac | 2788 | struct iwl_lq_sta *lq_sta = priv_sta; |
45527c2c | 2789 | struct iwl_priv *priv __maybe_unused = priv_r; |
b481de9c | 2790 | |
e1623446 | 2791 | IWL_DEBUG_RATE(priv, "enter\n"); |
c33104f0 | 2792 | kfree(lq_sta); |
e1623446 | 2793 | IWL_DEBUG_RATE(priv, "leave\n"); |
b481de9c ZY |
2794 | } |
2795 | ||
2796 | ||
93dc646a | 2797 | #ifdef CONFIG_MAC80211_DEBUGFS |
5ae212c9 ZY |
2798 | static int open_file_generic(struct inode *inode, struct file *file) |
2799 | { | |
2800 | file->private_data = inode->i_private; | |
2801 | return 0; | |
2802 | } | |
e227ceac TW |
2803 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
2804 | u32 *rate_n_flags, int index) | |
98d7e09a | 2805 | { |
bf403db8 | 2806 | struct iwl_priv *priv; |
3c4955f8 WYG |
2807 | u8 valid_tx_ant; |
2808 | u8 ant_sel_tx; | |
bf403db8 EK |
2809 | |
2810 | priv = lq_sta->drv; | |
3c4955f8 | 2811 | valid_tx_ant = priv->hw_params.valid_tx_ant; |
39e88504 | 2812 | if (lq_sta->dbg_fixed_rate) { |
3c4955f8 WYG |
2813 | ant_sel_tx = |
2814 | ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK) | |
2815 | >> RATE_MCS_ANT_POS); | |
2816 | if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) { | |
39e88504 | 2817 | *rate_n_flags = lq_sta->dbg_fixed_rate; |
3c4955f8 | 2818 | IWL_DEBUG_RATE(priv, "Fixed rate ON\n"); |
39e88504 | 2819 | } else { |
3c4955f8 WYG |
2820 | lq_sta->dbg_fixed_rate = 0; |
2821 | IWL_ERR(priv, | |
2822 | "Invalid antenna selection 0x%X, Valid is 0x%X\n", | |
2823 | ant_sel_tx, valid_tx_ant); | |
2824 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); | |
39e88504 | 2825 | } |
39e88504 | 2826 | } else { |
e1623446 | 2827 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); |
98d7e09a | 2828 | } |
98d7e09a | 2829 | } |
5ae212c9 | 2830 | |
98d7e09a ZY |
2831 | static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, |
2832 | const char __user *user_buf, size_t count, loff_t *ppos) | |
2833 | { | |
e227ceac | 2834 | struct iwl_lq_sta *lq_sta = file->private_data; |
bf403db8 | 2835 | struct iwl_priv *priv; |
98d7e09a ZY |
2836 | char buf[64]; |
2837 | int buf_size; | |
2838 | u32 parsed_rate; | |
2839 | ||
bf403db8 | 2840 | priv = lq_sta->drv; |
98d7e09a ZY |
2841 | memset(buf, 0, sizeof(buf)); |
2842 | buf_size = min(count, sizeof(buf) - 1); | |
2843 | if (copy_from_user(buf, user_buf, buf_size)) | |
2844 | return -EFAULT; | |
2845 | ||
2846 | if (sscanf(buf, "%x", &parsed_rate) == 1) | |
39e88504 | 2847 | lq_sta->dbg_fixed_rate = parsed_rate; |
98d7e09a | 2848 | else |
39e88504 | 2849 | lq_sta->dbg_fixed_rate = 0; |
98d7e09a | 2850 | |
39e88504 GC |
2851 | lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ |
2852 | lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | |
2853 | lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | |
2854 | lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | |
98d7e09a | 2855 | |
e1623446 | 2856 | IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n", |
39e88504 | 2857 | lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate); |
98d7e09a | 2858 | |
39e88504 | 2859 | if (lq_sta->dbg_fixed_rate) { |
07bc28ed | 2860 | rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate); |
66c73db7 | 2861 | iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC); |
98d7e09a ZY |
2862 | } |
2863 | ||
2864 | return count; | |
2865 | } | |
0209dc11 | 2866 | |
5ae212c9 ZY |
2867 | static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, |
2868 | char __user *user_buf, size_t count, loff_t *ppos) | |
2869 | { | |
a412c804 | 2870 | char *buff; |
5ae212c9 ZY |
2871 | int desc = 0; |
2872 | int i = 0; | |
12b96817 | 2873 | int index = 0; |
a412c804 | 2874 | ssize_t ret; |
5ae212c9 | 2875 | |
e227ceac | 2876 | struct iwl_lq_sta *lq_sta = file->private_data; |
d8ae4f52 | 2877 | struct iwl_priv *priv; |
adb7b5e6 | 2878 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
5ae212c9 | 2879 | |
d8ae4f52 | 2880 | priv = lq_sta->drv; |
a412c804 FS |
2881 | buff = kmalloc(1024, GFP_KERNEL); |
2882 | if (!buff) | |
2883 | return -ENOMEM; | |
2884 | ||
c33104f0 | 2885 | desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); |
98d7e09a | 2886 | desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", |
c33104f0 | 2887 | lq_sta->total_failed, lq_sta->total_success, |
39e88504 | 2888 | lq_sta->active_legacy_rate); |
98d7e09a | 2889 | desc += sprintf(buff+desc, "fixed rate 0x%X\n", |
39e88504 | 2890 | lq_sta->dbg_fixed_rate); |
d8ae4f52 WYG |
2891 | desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", |
2892 | (priv->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "", | |
2893 | (priv->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "", | |
2894 | (priv->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : ""); | |
adb7b5e6 WYG |
2895 | desc += sprintf(buff+desc, "lq type %s\n", |
2896 | (is_legacy(tbl->lq_type)) ? "legacy" : "HT"); | |
2897 | if (is_Ht(tbl->lq_type)) { | |
2898 | desc += sprintf(buff+desc, " %s", | |
2899 | (is_siso(tbl->lq_type)) ? "SISO" : | |
2900 | ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3")); | |
2901 | desc += sprintf(buff+desc, " %s", | |
2902 | (tbl->is_fat) ? "40MHz" : "20MHz"); | |
2681b20b WYG |
2903 | desc += sprintf(buff+desc, " %s %s\n", (tbl->is_SGI) ? "SGI" : "", |
2904 | (lq_sta->is_green) ? "GF enabled" : ""); | |
adb7b5e6 | 2905 | } |
12b96817 WYG |
2906 | desc += sprintf(buff+desc, "last tx rate=0x%X\n", |
2907 | lq_sta->last_rate_n_flags); | |
5ae212c9 ZY |
2908 | desc += sprintf(buff+desc, "general:" |
2909 | "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", | |
c33104f0 TW |
2910 | lq_sta->lq.general_params.flags, |
2911 | lq_sta->lq.general_params.mimo_delimiter, | |
2912 | lq_sta->lq.general_params.single_stream_ant_msk, | |
2913 | lq_sta->lq.general_params.dual_stream_ant_msk); | |
5ae212c9 ZY |
2914 | |
2915 | desc += sprintf(buff+desc, "agg:" | |
2916 | "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", | |
c33104f0 TW |
2917 | le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit), |
2918 | lq_sta->lq.agg_params.agg_dis_start_th, | |
2919 | lq_sta->lq.agg_params.agg_frame_cnt_limit); | |
5ae212c9 ZY |
2920 | |
2921 | desc += sprintf(buff+desc, | |
2922 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", | |
c33104f0 TW |
2923 | lq_sta->lq.general_params.start_rate_index[0], |
2924 | lq_sta->lq.general_params.start_rate_index[1], | |
2925 | lq_sta->lq.general_params.start_rate_index[2], | |
2926 | lq_sta->lq.general_params.start_rate_index[3]); | |
5ae212c9 | 2927 | |
12b96817 WYG |
2928 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
2929 | index = iwl_hwrate_to_plcp_idx( | |
2930 | le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); | |
2931 | if (is_legacy(tbl->lq_type)) { | |
2932 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n", | |
2933 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), | |
2934 | iwl_rate_mcs[index].mbps); | |
2935 | } else { | |
2936 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n", | |
2937 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), | |
2938 | iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs); | |
2939 | } | |
2940 | } | |
5ae212c9 | 2941 | |
a412c804 FS |
2942 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
2943 | kfree(buff); | |
2944 | return ret; | |
5ae212c9 ZY |
2945 | } |
2946 | ||
2947 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { | |
98d7e09a | 2948 | .write = rs_sta_dbgfs_scale_table_write, |
5ae212c9 ZY |
2949 | .read = rs_sta_dbgfs_scale_table_read, |
2950 | .open = open_file_generic, | |
2951 | }; | |
0209dc11 ZY |
2952 | static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, |
2953 | char __user *user_buf, size_t count, loff_t *ppos) | |
2954 | { | |
a412c804 | 2955 | char *buff; |
0209dc11 ZY |
2956 | int desc = 0; |
2957 | int i, j; | |
a412c804 | 2958 | ssize_t ret; |
0209dc11 | 2959 | |
e227ceac | 2960 | struct iwl_lq_sta *lq_sta = file->private_data; |
a412c804 FS |
2961 | |
2962 | buff = kmalloc(1024, GFP_KERNEL); | |
2963 | if (!buff) | |
2964 | return -ENOMEM; | |
2965 | ||
0209dc11 | 2966 | for (i = 0; i < LQ_SIZE; i++) { |
2681b20b | 2967 | desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d GF=%d\n" |
0209dc11 | 2968 | "rate=0x%X\n", |
c3056065 | 2969 | lq_sta->active_tbl == i ? "*" : "x", |
c33104f0 TW |
2970 | lq_sta->lq_info[i].lq_type, |
2971 | lq_sta->lq_info[i].is_SGI, | |
2972 | lq_sta->lq_info[i].is_fat, | |
2973 | lq_sta->lq_info[i].is_dup, | |
2681b20b | 2974 | lq_sta->is_green, |
39e88504 | 2975 | lq_sta->lq_info[i].current_rate); |
0209dc11 ZY |
2976 | for (j = 0; j < IWL_RATE_COUNT; j++) { |
2977 | desc += sprintf(buff+desc, | |
c33104f0 TW |
2978 | "counter=%d success=%d %%=%d\n", |
2979 | lq_sta->lq_info[i].win[j].counter, | |
2980 | lq_sta->lq_info[i].win[j].success_counter, | |
2981 | lq_sta->lq_info[i].win[j].success_ratio); | |
0209dc11 ZY |
2982 | } |
2983 | } | |
a412c804 FS |
2984 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
2985 | kfree(buff); | |
2986 | return ret; | |
0209dc11 ZY |
2987 | } |
2988 | ||
2989 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { | |
2990 | .read = rs_sta_dbgfs_stats_table_read, | |
2991 | .open = open_file_generic, | |
2992 | }; | |
5ae212c9 | 2993 | |
38167459 WYG |
2994 | static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file, |
2995 | char __user *user_buf, size_t count, loff_t *ppos) | |
2996 | { | |
2997 | char buff[120]; | |
2998 | int desc = 0; | |
2999 | ssize_t ret; | |
3000 | ||
3001 | struct iwl_lq_sta *lq_sta = file->private_data; | |
3002 | struct iwl_priv *priv; | |
3003 | struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl]; | |
3004 | ||
3005 | priv = lq_sta->drv; | |
3006 | ||
3007 | if (is_Ht(tbl->lq_type)) | |
3008 | desc += sprintf(buff+desc, | |
3009 | "Bit Rate= %d Mb/s\n", | |
3010 | tbl->expected_tpt[lq_sta->last_txrate_idx]); | |
3011 | else | |
3012 | desc += sprintf(buff+desc, | |
3013 | "Bit Rate= %d Mb/s\n", | |
3014 | iwl_rates[lq_sta->last_txrate_idx].ieee >> 1); | |
3015 | desc += sprintf(buff+desc, | |
3016 | "Signal Level= %d dBm\tNoise Level= %d dBm\n", | |
3017 | priv->last_rx_rssi, priv->last_rx_noise); | |
3018 | desc += sprintf(buff+desc, | |
3019 | "Tsf= 0x%llx\tBeacon time= 0x%08X\n", | |
3020 | priv->last_tsf, priv->last_beacon_time); | |
3021 | ||
3022 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); | |
3023 | return ret; | |
3024 | } | |
3025 | ||
3026 | static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { | |
3027 | .read = rs_sta_dbgfs_rate_scale_data_read, | |
3028 | .open = open_file_generic, | |
3029 | }; | |
3030 | ||
93dc646a ZY |
3031 | static void rs_add_debugfs(void *priv, void *priv_sta, |
3032 | struct dentry *dir) | |
3033 | { | |
e227ceac | 3034 | struct iwl_lq_sta *lq_sta = priv_sta; |
c33104f0 | 3035 | lq_sta->rs_sta_dbgfs_scale_table_file = |
0209dc11 | 3036 | debugfs_create_file("rate_scale_table", 0600, dir, |
c33104f0 TW |
3037 | lq_sta, &rs_sta_dbgfs_scale_table_ops); |
3038 | lq_sta->rs_sta_dbgfs_stats_table_file = | |
0209dc11 | 3039 | debugfs_create_file("rate_stats_table", 0600, dir, |
c33104f0 | 3040 | lq_sta, &rs_sta_dbgfs_stats_table_ops); |
38167459 WYG |
3041 | lq_sta->rs_sta_dbgfs_rate_scale_data_file = |
3042 | debugfs_create_file("rate_scale_data", 0600, dir, | |
3043 | lq_sta, &rs_sta_dbgfs_rate_scale_data_ops); | |
0c11b4de RR |
3044 | lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = |
3045 | debugfs_create_u8("tx_agg_tid_enable", 0600, dir, | |
3046 | &lq_sta->tx_agg_tid_en); | |
0c11b4de | 3047 | |
93dc646a ZY |
3048 | } |
3049 | ||
3050 | static void rs_remove_debugfs(void *priv, void *priv_sta) | |
3051 | { | |
e227ceac | 3052 | struct iwl_lq_sta *lq_sta = priv_sta; |
c33104f0 TW |
3053 | debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); |
3054 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); | |
38167459 | 3055 | debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file); |
0c11b4de | 3056 | debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); |
93dc646a ZY |
3057 | } |
3058 | #endif | |
3059 | ||
b481de9c ZY |
3060 | static struct rate_control_ops rs_ops = { |
3061 | .module = NULL, | |
3062 | .name = RS_NAME, | |
3063 | .tx_status = rs_tx_status, | |
3064 | .get_rate = rs_get_rate, | |
3065 | .rate_init = rs_rate_init, | |
b481de9c ZY |
3066 | .alloc = rs_alloc, |
3067 | .free = rs_free, | |
3068 | .alloc_sta = rs_alloc_sta, | |
3069 | .free_sta = rs_free_sta, | |
93dc646a ZY |
3070 | #ifdef CONFIG_MAC80211_DEBUGFS |
3071 | .add_sta_debugfs = rs_add_debugfs, | |
3072 | .remove_sta_debugfs = rs_remove_debugfs, | |
3073 | #endif | |
b481de9c ZY |
3074 | }; |
3075 | ||
e227ceac | 3076 | int iwlagn_rate_control_register(void) |
b481de9c | 3077 | { |
897e1cf2 | 3078 | return ieee80211_rate_control_register(&rs_ops); |
b481de9c ZY |
3079 | } |
3080 | ||
e227ceac | 3081 | void iwlagn_rate_control_unregister(void) |
b481de9c ZY |
3082 | { |
3083 | ieee80211_rate_control_unregister(&rs_ops); | |
3084 | } | |
3085 |