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