blob: f9db9df213210e739e0f441b08ec11898015126a [file] [log] [blame]
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001/******************************************************************************
2 *
3 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
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 * Intel Linux Wireless <ilw@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/slab.h>
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080030#include <net/mac80211.h>
31
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/delay.h>
35
36#include <linux/workqueue.h>
37
Stanislaw Gruszka98613be2011-11-15 14:19:34 +010038#include "common.h"
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020039#include "4965.h"
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080040
Stanislaw Gruszkad3175162011-11-15 11:25:42 +010041#define IL4965_RS_NAME "iwl-4965-rs"
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080042
43#define NUM_TRY_BEFORE_ANT_TOGGLE 1
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020044#define IL_NUMBER_TRY 1
45#define IL_HT_NUMBER_TRY 3
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080046
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020047#define RATE_MAX_WINDOW 62 /* # tx in history win */
48#define RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
49#define RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080050
51/* max allowed rate miss before sync LQ cmd */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020052#define IL_MISSED_RATE_MAX 15
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080053/* max time to accum history 2 seconds */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020054#define RATE_SCALE_FLUSH_INTVL (3*HZ)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080055
56static u8 rs_ht_to_legacy[] = {
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +020057 RATE_6M_IDX, RATE_6M_IDX,
58 RATE_6M_IDX, RATE_6M_IDX,
59 RATE_6M_IDX,
60 RATE_6M_IDX, RATE_9M_IDX,
61 RATE_12M_IDX, RATE_18M_IDX,
62 RATE_24M_IDX, RATE_36M_IDX,
63 RATE_48M_IDX, RATE_54M_IDX
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080064};
65
66static const u8 ant_toggle_lookup[] = {
67 /*ANT_NONE -> */ ANT_NONE,
68 /*ANT_A -> */ ANT_B,
69 /*ANT_B -> */ ANT_C,
70 /*ANT_AB -> */ ANT_BC,
71 /*ANT_C -> */ ANT_A,
72 /*ANT_AC -> */ ANT_AB,
73 /*ANT_BC -> */ ANT_AC,
74 /*ANT_ABC -> */ ANT_ABC,
75};
76
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020077#define IL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +020078 [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020079 RATE_SISO_##s##M_PLCP, \
80 RATE_MIMO2_##s##M_PLCP,\
81 RATE_##r##M_IEEE, \
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +020082 RATE_##ip##M_IDX, \
83 RATE_##in##M_IDX, \
84 RATE_##rp##M_IDX, \
85 RATE_##rn##M_IDX, \
86 RATE_##pp##M_IDX, \
87 RATE_##np##M_IDX }
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080088
89/*
90 * Parameter order:
91 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
92 *
93 * If there isn't a valid next or previous rate then INV is used which
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020094 * maps to RATE_INVALID
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080095 *
96 */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020097const struct il_rate_info il_rates[RATE_COUNT] = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020098 IL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
99 IL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
100 IL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
101 IL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
102 IL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
103 IL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
104 IL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
105 IL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
106 IL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
107 IL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
108 IL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
109 IL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
110 IL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800111};
112
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200113static int il4965_hwrate_to_plcp_idx(u32 rate_n_flags)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800114{
115 int idx = 0;
116
117 /* HT rate format */
118 if (rate_n_flags & RATE_MCS_HT_MSK) {
119 idx = (rate_n_flags & 0xff);
120
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200121 if (idx >= RATE_MIMO2_6M_PLCP)
122 idx = idx - RATE_MIMO2_6M_PLCP;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800123
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200124 idx += IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800125 /* skip 9M not supported in ht*/
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200126 if (idx >= RATE_9M_IDX)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800127 idx += 1;
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200128 if (idx >= IL_FIRST_OFDM_RATE && idx <= IL_LAST_OFDM_RATE)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800129 return idx;
130
131 /* legacy rate format, search for match in table */
132 } else {
Stanislaw Gruszkad2ddf6212011-08-16 14:17:04 +0200133 for (idx = 0; idx < ARRAY_SIZE(il_rates); idx++)
134 if (il_rates[idx].plcp == (rate_n_flags & 0xFF))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800135 return idx;
136 }
137
138 return -1;
139}
140
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200141static void il4965_rs_rate_scale_perform(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800142 struct sk_buff *skb,
143 struct ieee80211_sta *sta,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200144 struct il_lq_sta *lq_sta);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200145static void il4965_rs_fill_link_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200146 struct il_lq_sta *lq_sta, u32 rate_n_flags);
147static void il4965_rs_stay_in_table(struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800148 bool force_search);
149
150#ifdef CONFIG_MAC80211_DEBUGFS
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200151static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100152 u32 *rate_n_flags, int idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800153#else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200154static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100155 u32 *rate_n_flags, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800156{}
157#endif
158
159/**
160 * The following tables contain the expected throughput metrics for all rates
161 *
162 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
163 *
164 * where invalid entries are zeros.
165 *
166 * CCK rates are only valid in legacy table and will only be used in G
167 * (2.4 GHz) band.
168 */
169
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200170static s32 expected_tpt_legacy[RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800171 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0
172};
173
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200174static s32 expected_tpt_siso20MHz[4][RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800175 {0, 0, 0, 0, 42, 0, 76, 102, 124, 158, 183, 193, 202}, /* Norm */
176 {0, 0, 0, 0, 46, 0, 82, 110, 132, 167, 192, 202, 210}, /* SGI */
177 {0, 0, 0, 0, 48, 0, 93, 135, 176, 251, 319, 351, 381}, /* AGG */
178 {0, 0, 0, 0, 53, 0, 102, 149, 193, 275, 348, 381, 413}, /* AGG+SGI */
179};
180
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200181static s32 expected_tpt_siso40MHz[4][RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800182 {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */
183 {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */
184 {0, 0, 0, 0, 96, 0, 182, 259, 328, 451, 553, 598, 640}, /* AGG */
185 {0, 0, 0, 0, 106, 0, 199, 282, 357, 487, 593, 640, 683}, /* AGG+SGI */
186};
187
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200188static s32 expected_tpt_mimo2_20MHz[4][RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800189 {0, 0, 0, 0, 74, 0, 123, 155, 179, 213, 235, 243, 250}, /* Norm */
190 {0, 0, 0, 0, 81, 0, 131, 164, 187, 221, 242, 250, 256}, /* SGI */
191 {0, 0, 0, 0, 92, 0, 175, 250, 317, 436, 534, 578, 619}, /* AGG */
192 {0, 0, 0, 0, 102, 0, 192, 273, 344, 470, 573, 619, 660}, /* AGG+SGI*/
193};
194
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200195static s32 expected_tpt_mimo2_40MHz[4][RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800196 {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */
197 {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */
198 {0, 0, 0, 0, 180, 0, 327, 446, 545, 708, 828, 878, 922}, /* AGG */
199 {0, 0, 0, 0, 197, 0, 355, 481, 584, 752, 872, 922, 966}, /* AGG+SGI */
200};
201
202/* mbps, mcs */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200203static const struct il_rate_mcs_info il_rate_mcs[RATE_COUNT] = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800204 { "1", "BPSK DSSS"},
205 { "2", "QPSK DSSS"},
206 {"5.5", "BPSK CCK"},
207 { "11", "QPSK CCK"},
208 { "6", "BPSK 1/2"},
209 { "9", "BPSK 1/2"},
210 { "12", "QPSK 1/2"},
211 { "18", "QPSK 3/4"},
212 { "24", "16QAM 1/2"},
213 { "36", "16QAM 3/4"},
214 { "48", "64QAM 2/3"},
215 { "54", "64QAM 3/4"},
216 { "60", "64QAM 5/6"},
217};
218
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200219#define MCS_IDX_PER_STREAM (8)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800220
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200221static inline u8 il4965_rs_extract_rate(u32 rate_n_flags)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800222{
223 return (u8)(rate_n_flags & 0xFF);
224}
225
226static void
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200227il4965_rs_rate_scale_clear_win(struct il_rate_scale_data *win)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800228{
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200229 win->data = 0;
230 win->success_counter = 0;
231 win->success_ratio = IL_INVALID_VALUE;
232 win->counter = 0;
233 win->average_tpt = IL_INVALID_VALUE;
234 win->stamp = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800235}
236
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200237static inline u8 il4965_rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800238{
239 return (ant_type & valid_antenna) == ant_type;
240}
241
242/*
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200243 * removes the old data from the stats. All data that is older than
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800244 * TID_MAX_TIME_DIFF, will be deleted.
245 */
246static void
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200247il4965_rs_tl_rm_old_stats(struct il_traffic_load *tl, u32 curr_time)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800248{
249 /* The oldest age we want to keep */
250 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
251
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200252 while (tl->queue_count && tl->time_stamp < oldest_time) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800253 tl->total -= tl->packet_count[tl->head];
254 tl->packet_count[tl->head] = 0;
255 tl->time_stamp += TID_QUEUE_CELL_SPACING;
256 tl->queue_count--;
257 tl->head++;
258 if (tl->head >= TID_QUEUE_MAX_SIZE)
259 tl->head = 0;
260 }
261}
262
263/*
264 * increment traffic load value for tid and also remove
265 * any old values if passed the certain time period
266 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200267static u8 il4965_rs_tl_add_packet(struct il_lq_sta *lq_data,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800268 struct ieee80211_hdr *hdr)
269{
270 u32 curr_time = jiffies_to_msecs(jiffies);
271 u32 time_diff;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100272 s32 idx;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200273 struct il_traffic_load *tl = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800274 u8 tid;
275
276 if (ieee80211_is_data_qos(hdr->frame_control)) {
277 u8 *qc = ieee80211_get_qos_ctl(hdr);
278 tid = qc[0] & 0xf;
279 } else
280 return MAX_TID_COUNT;
281
282 if (unlikely(tid >= TID_MAX_LOAD_COUNT))
283 return MAX_TID_COUNT;
284
285 tl = &lq_data->load[tid];
286
287 curr_time -= curr_time % TID_ROUND_VALUE;
288
289 /* Happens only for the first packet. Initialize the data */
290 if (!(tl->queue_count)) {
291 tl->total = 1;
292 tl->time_stamp = curr_time;
293 tl->queue_count = 1;
294 tl->head = 0;
295 tl->packet_count[0] = 1;
296 return MAX_TID_COUNT;
297 }
298
299 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100300 idx = time_diff / TID_QUEUE_CELL_SPACING;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800301
302 /* The history is too long: remove data that is older than */
303 /* TID_MAX_TIME_DIFF */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100304 if (idx >= TID_QUEUE_MAX_SIZE)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200305 il4965_rs_tl_rm_old_stats(tl, curr_time);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800306
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100307 idx = (tl->head + idx) % TID_QUEUE_MAX_SIZE;
308 tl->packet_count[idx] = tl->packet_count[idx] + 1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800309 tl->total = tl->total + 1;
310
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100311 if ((idx + 1) > tl->queue_count)
312 tl->queue_count = idx + 1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800313
314 return tid;
315}
316
317/*
318 get the traffic load value for tid
319*/
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200320static u32 il4965_rs_tl_get_load(struct il_lq_sta *lq_data, u8 tid)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800321{
322 u32 curr_time = jiffies_to_msecs(jiffies);
323 u32 time_diff;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100324 s32 idx;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200325 struct il_traffic_load *tl = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800326
327 if (tid >= TID_MAX_LOAD_COUNT)
328 return 0;
329
330 tl = &(lq_data->load[tid]);
331
332 curr_time -= curr_time % TID_ROUND_VALUE;
333
334 if (!(tl->queue_count))
335 return 0;
336
337 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100338 idx = time_diff / TID_QUEUE_CELL_SPACING;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800339
340 /* The history is too long: remove data that is older than */
341 /* TID_MAX_TIME_DIFF */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100342 if (idx >= TID_QUEUE_MAX_SIZE)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200343 il4965_rs_tl_rm_old_stats(tl, curr_time);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800344
345 return tl->total;
346}
347
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200348static int il4965_rs_tl_turn_on_agg_for_tid(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200349 struct il_lq_sta *lq_data, u8 tid,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800350 struct ieee80211_sta *sta)
351{
352 int ret = -EAGAIN;
353 u32 load;
354
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200355 load = il4965_rs_tl_get_load(lq_data, tid);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800356
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200357 if (load > IL_AGG_LOAD_THRESHOLD) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100358 D_HT("Starting Tx agg: STA: %pM tid: %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800359 sta->addr, tid);
360 ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
361 if (ret == -EAGAIN) {
362 /*
363 * driver and mac80211 is out of sync
364 * this might be cause by reloading firmware
365 * stop the tx ba session here
366 */
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200367 IL_ERR("Fail start Tx agg on tid: %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800368 tid);
369 ieee80211_stop_tx_ba_session(sta, tid);
370 }
371 } else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200372 IL_ERR("Aggregation not enabled for tid %d "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800373 "because load = %u\n", tid, load);
374 }
375 return ret;
376}
377
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200378static void il4965_rs_tl_turn_on_agg(struct il_priv *il, u8 tid,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200379 struct il_lq_sta *lq_data,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800380 struct ieee80211_sta *sta)
381{
382 if (tid < TID_MAX_LOAD_COUNT)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200383 il4965_rs_tl_turn_on_agg_for_tid(il, lq_data, tid, sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800384 else
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200385 IL_ERR("tid exceeds max load count: %d/%d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800386 tid, TID_MAX_LOAD_COUNT);
387}
388
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200389static inline int il4965_get_il4965_num_of_ant_from_rate(u32 rate_n_flags)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800390{
391 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
392 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
393 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
394}
395
396/*
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200397 * Static function to get the expected throughput from an il_scale_tbl_info
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800398 * that wraps a NULL pointer check
399 */
400static s32
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100401il4965_get_expected_tpt(struct il_scale_tbl_info *tbl, int rs_idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800402{
403 if (tbl->expected_tpt)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100404 return tbl->expected_tpt[rs_idx];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800405 return 0;
406}
407
408/**
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200409 * il4965_rs_collect_tx_data - Update the success/failure sliding win
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800410 *
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200411 * We keep a sliding win of the last 62 packets transmitted
412 * at this rate. win->data contains the bitmask of successful
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800413 * packets.
414 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200415static int il4965_rs_collect_tx_data(struct il_scale_tbl_info *tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100416 int scale_idx, int attempts, int successes)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800417{
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200418 struct il_rate_scale_data *win = NULL;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200419 static const u64 mask = (((u64)1) << (RATE_MAX_WINDOW - 1));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800420 s32 fail_count, tpt;
421
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100422 if (scale_idx < 0 || scale_idx >= RATE_COUNT)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800423 return -EINVAL;
424
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200425 /* Select win for current tx bit rate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100426 win = &(tbl->win[scale_idx]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800427
428 /* Get expected throughput */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100429 tpt = il4965_get_expected_tpt(tbl, scale_idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800430
431 /*
432 * Keep track of only the latest 62 tx frame attempts in this rate's
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200433 * history win; anything older isn't really relevant any more.
434 * If we have filled up the sliding win, drop the oldest attempt;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800435 * if the oldest attempt (highest bit in bitmap) shows "success",
436 * subtract "1" from the success counter (this is the main reason
437 * we keep these bitmaps!).
438 */
439 while (attempts > 0) {
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200440 if (win->counter >= RATE_MAX_WINDOW) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800441
442 /* remove earliest */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200443 win->counter = RATE_MAX_WINDOW - 1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800444
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200445 if (win->data & mask) {
446 win->data &= ~mask;
447 win->success_counter--;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800448 }
449 }
450
451 /* Increment frames-attempted counter */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200452 win->counter++;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800453
454 /* Shift bitmap by one frame to throw away oldest history */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200455 win->data <<= 1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800456
457 /* Mark the most recent #successes attempts as successful */
458 if (successes > 0) {
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200459 win->success_counter++;
460 win->data |= 0x1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800461 successes--;
462 }
463
464 attempts--;
465 }
466
467 /* Calculate current success ratio, avoid divide-by-0! */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200468 if (win->counter > 0)
469 win->success_ratio = 128 * (100 * win->success_counter)
470 / win->counter;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800471 else
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200472 win->success_ratio = IL_INVALID_VALUE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800473
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200474 fail_count = win->counter - win->success_counter;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800475
476 /* Calculate average throughput, if we have enough history. */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200477 if (fail_count >= RATE_MIN_FAILURE_TH ||
478 win->success_counter >= RATE_MIN_SUCCESS_TH)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200479 win->average_tpt = (win->success_ratio * tpt + 64) / 128;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800480 else
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200481 win->average_tpt = IL_INVALID_VALUE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800482
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200483 /* Tag this win as having been updated */
484 win->stamp = jiffies;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800485
486 return 0;
487}
488
489/*
490 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
491 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200492static u32 il4965_rate_n_flags_from_tbl(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200493 struct il_scale_tbl_info *tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100494 int idx, u8 use_green)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800495{
496 u32 rate_n_flags = 0;
497
498 if (is_legacy(tbl->lq_type)) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100499 rate_n_flags = il_rates[idx].plcp;
500 if (idx >= IL_FIRST_CCK_RATE && idx <= IL_LAST_CCK_RATE)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800501 rate_n_flags |= RATE_MCS_CCK_MSK;
502
503 } else if (is_Ht(tbl->lq_type)) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100504 if (idx > IL_LAST_OFDM_RATE) {
505 IL_ERR("Invalid HT rate idx %d\n", idx);
506 idx = IL_LAST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800507 }
508 rate_n_flags = RATE_MCS_HT_MSK;
509
510 if (is_siso(tbl->lq_type))
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100511 rate_n_flags |= il_rates[idx].plcp_siso;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800512 else
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100513 rate_n_flags |= il_rates[idx].plcp_mimo2;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800514 } else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200515 IL_ERR("Invalid tbl->lq_type %d\n", tbl->lq_type);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800516 }
517
518 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
519 RATE_MCS_ANT_ABC_MSK);
520
521 if (is_Ht(tbl->lq_type)) {
522 if (tbl->is_ht40) {
523 if (tbl->is_dup)
524 rate_n_flags |= RATE_MCS_DUP_MSK;
525 else
526 rate_n_flags |= RATE_MCS_HT40_MSK;
527 }
528 if (tbl->is_SGI)
529 rate_n_flags |= RATE_MCS_SGI_MSK;
530
531 if (use_green) {
532 rate_n_flags |= RATE_MCS_GF_MSK;
533 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
534 rate_n_flags &= ~RATE_MCS_SGI_MSK;
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200535 IL_ERR("GF was set with SGI:SISO\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800536 }
537 }
538 }
539 return rate_n_flags;
540}
541
542/*
543 * Interpret uCode API's rate_n_flags format,
544 * fill "search" or "active" tx mode table.
545 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200546static int il4965_rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800547 enum ieee80211_band band,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200548 struct il_scale_tbl_info *tbl,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800549 int *rate_idx)
550{
551 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200552 u8 il4965_num_of_ant = il4965_get_il4965_num_of_ant_from_rate(rate_n_flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800553 u8 mcs;
554
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200555 memset(tbl, 0, sizeof(struct il_scale_tbl_info));
556 *rate_idx = il4965_hwrate_to_plcp_idx(rate_n_flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800557
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200558 if (*rate_idx == RATE_INVALID) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800559 *rate_idx = -1;
560 return -EINVAL;
561 }
562 tbl->is_SGI = 0; /* default legacy setup */
563 tbl->is_ht40 = 0;
564 tbl->is_dup = 0;
565 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
566 tbl->lq_type = LQ_NONE;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200567 tbl->max_search = IL_MAX_SEARCH;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800568
569 /* legacy rate format */
570 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200571 if (il4965_num_of_ant == 1) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800572 if (band == IEEE80211_BAND_5GHZ)
573 tbl->lq_type = LQ_A;
574 else
575 tbl->lq_type = LQ_G;
576 }
577 /* HT rate format */
578 } else {
579 if (rate_n_flags & RATE_MCS_SGI_MSK)
580 tbl->is_SGI = 1;
581
582 if ((rate_n_flags & RATE_MCS_HT40_MSK) ||
583 (rate_n_flags & RATE_MCS_DUP_MSK))
584 tbl->is_ht40 = 1;
585
586 if (rate_n_flags & RATE_MCS_DUP_MSK)
587 tbl->is_dup = 1;
588
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200589 mcs = il4965_rs_extract_rate(rate_n_flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800590
591 /* SISO */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200592 if (mcs <= RATE_SISO_60M_PLCP) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200593 if (il4965_num_of_ant == 1)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800594 tbl->lq_type = LQ_SISO; /*else NONE*/
595 /* MIMO2 */
596 } else {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200597 if (il4965_num_of_ant == 2)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800598 tbl->lq_type = LQ_MIMO2;
599 }
600 }
601 return 0;
602}
603
604/* switch to another antenna/antennas and return 1 */
605/* if no other valid antenna found, return 0 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200606static int il4965_rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
607 struct il_scale_tbl_info *tbl)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800608{
609 u8 new_ant_type;
610
611 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
612 return 0;
613
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200614 if (!il4965_rs_is_valid_ant(valid_ant, tbl->ant_type))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800615 return 0;
616
617 new_ant_type = ant_toggle_lookup[tbl->ant_type];
618
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200619 while (new_ant_type != tbl->ant_type &&
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200620 !il4965_rs_is_valid_ant(valid_ant, new_ant_type))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800621 new_ant_type = ant_toggle_lookup[new_ant_type];
622
623 if (new_ant_type == tbl->ant_type)
624 return 0;
625
626 tbl->ant_type = new_ant_type;
627 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
628 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
629 return 1;
630}
631
632/**
633 * Green-field mode is valid if the station supports it and
634 * there are no non-GF stations present in the BSS.
635 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200636static bool il4965_rs_use_green(struct ieee80211_sta *sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800637{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200638 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
639 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800640
641 return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
642 !(ctx->ht.non_gf_sta_present);
643}
644
645/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200646 * il4965_rs_get_supported_rates - get the available rates
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800647 *
648 * if management frame or broadcast frame only return
649 * basic available rates.
650 *
651 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200652static u16 il4965_rs_get_supported_rates(struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800653 struct ieee80211_hdr *hdr,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200654 enum il_table_type rate_type)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800655{
656 if (is_legacy(rate_type)) {
657 return lq_sta->active_legacy_rate;
658 } else {
659 if (is_siso(rate_type))
660 return lq_sta->active_siso_rate;
661 else
662 return lq_sta->active_mimo2_rate;
663 }
664}
665
666static u16
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100667il4965_rs_get_adjacent_rate(struct il_priv *il, u8 idx, u16 rate_mask,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800668 int rate_type)
669{
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200670 u8 high = RATE_INVALID;
671 u8 low = RATE_INVALID;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800672
673 /* 802.11A or ht walks to the next literal adjacent rate in
674 * the rate table */
675 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
676 int i;
677 u32 mask;
678
679 /* Find the previous rate that is in the rate mask */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100680 i = idx - 1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800681 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
682 if (rate_mask & mask) {
683 low = i;
684 break;
685 }
686 }
687
688 /* Find the next rate that is in the rate mask */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100689 i = idx + 1;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200690 for (mask = (1 << i); i < RATE_COUNT; i++, mask <<= 1) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800691 if (rate_mask & mask) {
692 high = i;
693 break;
694 }
695 }
696
697 return (high << 8) | low;
698 }
699
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100700 low = idx;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200701 while (low != RATE_INVALID) {
Stanislaw Gruszkad2ddf6212011-08-16 14:17:04 +0200702 low = il_rates[low].prev_rs;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200703 if (low == RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800704 break;
705 if (rate_mask & (1 << low))
706 break;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100707 D_RATE("Skipping masked lower rate: %d\n", low);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800708 }
709
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100710 high = idx;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200711 while (high != RATE_INVALID) {
Stanislaw Gruszkad2ddf6212011-08-16 14:17:04 +0200712 high = il_rates[high].next_rs;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200713 if (high == RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800714 break;
715 if (rate_mask & (1 << high))
716 break;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100717 D_RATE("Skipping masked higher rate: %d\n", high);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800718 }
719
720 return (high << 8) | low;
721}
722
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200723static u32 il4965_rs_get_lower_rate(struct il_lq_sta *lq_sta,
724 struct il_scale_tbl_info *tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100725 u8 scale_idx, u8 ht_possible)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800726{
727 s32 low;
728 u16 rate_mask;
729 u16 high_low;
730 u8 switch_to_legacy = 0;
731 u8 is_green = lq_sta->is_green;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200732 struct il_priv *il = lq_sta->drv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800733
734 /* check if we need to switch from HT to legacy rates.
735 * assumption is that mandatory rates (1Mbps or 6Mbps)
736 * are always supported (spec demand) */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100737 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_idx)) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800738 switch_to_legacy = 1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100739 scale_idx = rs_ht_to_legacy[scale_idx];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800740 if (lq_sta->band == IEEE80211_BAND_5GHZ)
741 tbl->lq_type = LQ_A;
742 else
743 tbl->lq_type = LQ_G;
744
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200745 if (il4965_num_of_ant(tbl->ant_type) > 1)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800746 tbl->ant_type =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200747 il4965_first_antenna(il->hw_params.valid_tx_ant);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800748
749 tbl->is_ht40 = 0;
750 tbl->is_SGI = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200751 tbl->max_search = IL_MAX_SEARCH;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800752 }
753
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200754 rate_mask = il4965_rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800755
756 /* Mask with station rate restriction */
757 if (is_legacy(tbl->lq_type)) {
758 /* supp_rates has no CCK bits in A mode */
759 if (lq_sta->band == IEEE80211_BAND_5GHZ)
760 rate_mask = (u16)(rate_mask &
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200761 (lq_sta->supp_rates << IL_FIRST_OFDM_RATE));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800762 else
763 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
764 }
765
766 /* If we switched from HT to legacy, check current rate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100767 if (switch_to_legacy && (rate_mask & (1 << scale_idx))) {
768 low = scale_idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800769 goto out;
770 }
771
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200772 high_low = il4965_rs_get_adjacent_rate(lq_sta->drv,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100773 scale_idx, rate_mask,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800774 tbl->lq_type);
775 low = high_low & 0xff;
776
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200777 if (low == RATE_INVALID)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100778 low = scale_idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800779
780out:
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200781 return il4965_rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800782}
783
784/*
785 * Simple function to compare two rate scale table types
786 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200787static bool il4965_table_type_matches(struct il_scale_tbl_info *a,
788 struct il_scale_tbl_info *b)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800789{
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200790 return (a->lq_type == b->lq_type && a->ant_type == b->ant_type &&
791 a->is_SGI == b->is_SGI);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800792}
793
794/*
795 * mac80211 sends us Tx status
796 */
797static void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200798il4965_rs_tx_status(void *il_r, struct ieee80211_supported_band *sband,
799 struct ieee80211_sta *sta, void *il_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800800 struct sk_buff *skb)
801{
802 int legacy_success;
803 int retries;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100804 int rs_idx, mac_idx, i;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200805 struct il_lq_sta *lq_sta = il_sta;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200806 struct il_link_quality_cmd *table;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800807 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200808 struct il_priv *il = (struct il_priv *)il_r;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800809 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
810 enum mac80211_rate_control_flags mac_flags;
811 u32 tx_rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200812 struct il_scale_tbl_info tbl_type;
813 struct il_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
814 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
815 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800816
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100817 D_RATE(
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200818 "get frame ack response, update rate scale win\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800819
820 /* Treat uninitialized rate scaling data same as non-existing. */
821 if (!lq_sta) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100822 D_RATE("Station rate scaling not created yet.\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800823 return;
824 } else if (!lq_sta->drv) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100825 D_RATE("Rate scaling not initialized yet.\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800826 return;
827 }
828
829 if (!ieee80211_is_data(hdr->frame_control) ||
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200830 (info->flags & IEEE80211_TX_CTL_NO_ACK))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800831 return;
832
833 /* This packet was aggregated but doesn't carry status info */
834 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
835 !(info->flags & IEEE80211_TX_STAT_AMPDU))
836 return;
837
838 /*
839 * Ignore this Tx frame response if its initial rate doesn't match
840 * that of latest Link Quality command. There may be stragglers
841 * from a previous Link Quality command, but we're no longer interested
842 * in those; they're either from the "active" mode while we're trying
843 * to check "search" mode, or a prior "search" mode after we've moved
844 * to a new "search" mode (which might become the new "active" mode).
845 */
846 table = &lq_sta->lq;
847 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200848 il4965_rs_get_tbl_info_from_mcs(tx_rate,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100849 il->band, &tbl_type, &rs_idx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200850 if (il->band == IEEE80211_BAND_5GHZ)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100851 rs_idx -= IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800852 mac_flags = info->status.rates[0].flags;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100853 mac_idx = info->status.rates[0].idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800854 /* For HT packets, map MCS to PLCP */
855 if (mac_flags & IEEE80211_TX_RC_MCS) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100856 mac_idx &= RATE_MCS_CODE_MSK; /* Remove # of streams */
857 if (mac_idx >= (RATE_9M_IDX - IL_FIRST_OFDM_RATE))
858 mac_idx++;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800859 /*
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100860 * mac80211 HT idx is always zero-idxed; we need to move
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800861 * HT OFDM rates after CCK rates in 2.4 GHz band
862 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200863 if (il->band == IEEE80211_BAND_2GHZ)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100864 mac_idx += IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800865 }
866 /* Here we actually compare this rate to the latest LQ command */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100867 if (mac_idx < 0 ||
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200868 tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI) ||
869 tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ||
870 tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA) ||
871 tbl_type.ant_type != info->antenna_sel_tx ||
872 !!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS) ||
873 !!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD) ||
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100874 rs_idx != mac_idx) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100875 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800876 "initial rate %d does not match %d (0x%x)\n",
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100877 mac_idx, rs_idx, tx_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800878 /*
879 * Since rates mis-match, the last LQ command may have failed.
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200880 * After IL_MISSED_RATE_MAX mis-matches, resync the uCode with
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800881 * ... driver.
882 */
883 lq_sta->missed_rate_counter++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200884 if (lq_sta->missed_rate_counter > IL_MISSED_RATE_MAX) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800885 lq_sta->missed_rate_counter = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200886 il_send_lq_cmd(il, ctx, &lq_sta->lq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800887 CMD_ASYNC, false);
888 }
889 /* Regardless, ignore this status info for outdated rate */
890 return;
891 } else
892 /* Rate did match, so reset the missed_rate_counter */
893 lq_sta->missed_rate_counter = 0;
894
895 /* Figure out if rate scale algorithm is in active or search table */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200896 if (il4965_table_type_matches(&tbl_type,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800897 &(lq_sta->lq_info[lq_sta->active_tbl]))) {
898 curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
899 other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200900 } else if (il4965_table_type_matches(&tbl_type,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800901 &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
902 curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
903 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
904 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100905 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800906 "Neither active nor search matches tx rate\n");
907 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100908 D_RATE("active- lq:%x, ant:%x, SGI:%d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800909 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
910 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100911 D_RATE("search- lq:%x, ant:%x, SGI:%d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800912 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100913 D_RATE("actual- lq:%x, ant:%x, SGI:%d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800914 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
915 /*
916 * no matching table found, let's by-pass the data collection
917 * and continue to perform rate scale to find the rate table
918 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200919 il4965_rs_stay_in_table(lq_sta, true);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800920 goto done;
921 }
922
923 /*
924 * Updating the frame history depends on whether packets were
925 * aggregated.
926 *
927 * For aggregation, all packets were transmitted at the same rate, the
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100928 * first idx into rate scale table.
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800929 */
930 if (info->flags & IEEE80211_TX_STAT_AMPDU) {
931 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200932 il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band, &tbl_type,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100933 &rs_idx);
934 il4965_rs_collect_tx_data(curr_tbl, rs_idx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800935 info->status.ampdu_len,
936 info->status.ampdu_ack_len);
937
938 /* Update success/fail counts if not searching for new mode */
939 if (lq_sta->stay_in_tbl) {
940 lq_sta->total_success += info->status.ampdu_ack_len;
941 lq_sta->total_failed += (info->status.ampdu_len -
942 info->status.ampdu_ack_len);
943 }
944 } else {
945 /*
946 * For legacy, update frame history with for each Tx retry.
947 */
948 retries = info->status.rates[0].count - 1;
949 /* HW doesn't send more than 15 retries */
950 retries = min(retries, 15);
951
952 /* The last transmission may have been successful */
953 legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
954 /* Collect data for each rate used during failed TX attempts */
955 for (i = 0; i <= retries; ++i) {
956 tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200957 il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100958 &tbl_type, &rs_idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800959 /*
960 * Only collect stats if retried rate is in the same RS
961 * table as active/search.
962 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200963 if (il4965_table_type_matches(&tbl_type, curr_tbl))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800964 tmp_tbl = curr_tbl;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200965 else if (il4965_table_type_matches(&tbl_type,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800966 other_tbl))
967 tmp_tbl = other_tbl;
968 else
969 continue;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100970 il4965_rs_collect_tx_data(tmp_tbl, rs_idx, 1,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800971 i < retries ? 0 : legacy_success);
972 }
973
974 /* Update success/fail counts if not searching for new mode */
975 if (lq_sta->stay_in_tbl) {
976 lq_sta->total_success += legacy_success;
977 lq_sta->total_failed += retries + (1 - legacy_success);
978 }
979 }
980 /* The last TX rate is cached in lq_sta; it's set in if/else above */
981 lq_sta->last_rate_n_flags = tx_rate;
982done:
983 /* See if there's a better rate or modulation mode to try. */
984 if (sta && sta->supp_rates[sband->band])
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200985 il4965_rs_rate_scale_perform(il, skb, sta, lq_sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800986}
987
988/*
989 * Begin a period of staying with a selected modulation mode.
990 * Set "stay_in_tbl" flag to prevent any mode switches.
991 * Set frame tx success limits according to legacy vs. high-throughput,
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200992 * and reset overall (spanning all rates) tx success history stats.
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800993 * These control how long we stay using same modulation mode before
994 * searching for a new mode.
995 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200996static void il4965_rs_set_stay_in_table(struct il_priv *il, u8 is_legacy,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200997 struct il_lq_sta *lq_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800998{
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100999 D_RATE("we are staying in the same table\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001000 lq_sta->stay_in_tbl = 1; /* only place this gets set */
1001 if (is_legacy) {
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001002 lq_sta->table_count_limit = IL_LEGACY_TBL_COUNT;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001003 lq_sta->max_failure_limit = IL_LEGACY_FAILURE_LIMIT;
1004 lq_sta->max_success_limit = IL_LEGACY_SUCCESS_LIMIT;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001005 } else {
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001006 lq_sta->table_count_limit = IL_NONE_LEGACY_TBL_COUNT;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001007 lq_sta->max_failure_limit = IL_NONE_LEGACY_FAILURE_LIMIT;
1008 lq_sta->max_success_limit = IL_NONE_LEGACY_SUCCESS_LIMIT;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001009 }
1010 lq_sta->table_count = 0;
1011 lq_sta->total_failed = 0;
1012 lq_sta->total_success = 0;
1013 lq_sta->flush_timer = jiffies;
1014 lq_sta->action_counter = 0;
1015}
1016
1017/*
1018 * Find correct throughput table for given mode of modulation
1019 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001020static void il4965_rs_set_expected_tpt_table(struct il_lq_sta *lq_sta,
1021 struct il_scale_tbl_info *tbl)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001022{
1023 /* Used to choose among HT tables */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001024 s32 (*ht_tbl_pointer)[RATE_COUNT];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001025
1026 /* Check for invalid LQ type */
1027 if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
1028 tbl->expected_tpt = expected_tpt_legacy;
1029 return;
1030 }
1031
1032 /* Legacy rates have only one table */
1033 if (is_legacy(tbl->lq_type)) {
1034 tbl->expected_tpt = expected_tpt_legacy;
1035 return;
1036 }
1037
1038 /* Choose among many HT tables depending on number of streams
1039 * (SISO/MIMO2), channel width (20/40), SGI, and aggregation
1040 * status */
1041 if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1042 ht_tbl_pointer = expected_tpt_siso20MHz;
1043 else if (is_siso(tbl->lq_type))
1044 ht_tbl_pointer = expected_tpt_siso40MHz;
1045 else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1046 ht_tbl_pointer = expected_tpt_mimo2_20MHz;
1047 else /* if (is_mimo2(tbl->lq_type)) <-- must be true */
1048 ht_tbl_pointer = expected_tpt_mimo2_40MHz;
1049
1050 if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
1051 tbl->expected_tpt = ht_tbl_pointer[0];
1052 else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
1053 tbl->expected_tpt = ht_tbl_pointer[1];
1054 else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
1055 tbl->expected_tpt = ht_tbl_pointer[2];
1056 else /* AGG+SGI */
1057 tbl->expected_tpt = ht_tbl_pointer[3];
1058}
1059
1060/*
1061 * Find starting rate for new "search" high-throughput mode of modulation.
1062 * Goal is to find lowest expected rate (under perfect conditions) that is
1063 * above the current measured throughput of "active" mode, to give new mode
1064 * a fair chance to prove itself without too many challenges.
1065 *
1066 * This gets called when transitioning to more aggressive modulation
1067 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1068 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1069 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1070 * bit rate will typically need to increase, but not if performance was bad.
1071 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001072static s32 il4965_rs_get_best_rate(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001073 struct il_lq_sta *lq_sta,
1074 struct il_scale_tbl_info *tbl, /* "search" */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001075 u16 rate_mask, s8 idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001076{
1077 /* "active" values */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001078 struct il_scale_tbl_info *active_tbl =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001079 &(lq_sta->lq_info[lq_sta->active_tbl]);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001080 s32 active_sr = active_tbl->win[idx].success_ratio;
1081 s32 active_tpt = active_tbl->expected_tpt[idx];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001082
1083 /* expected "search" throughput */
1084 s32 *tpt_tbl = tbl->expected_tpt;
1085
1086 s32 new_rate, high, low, start_hi;
1087 u16 high_low;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001088 s8 rate = idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001089
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001090 new_rate = high = low = start_hi = RATE_INVALID;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001091
1092 for (; ;) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001093 high_low = il4965_rs_get_adjacent_rate(il, rate, rate_mask,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001094 tbl->lq_type);
1095
1096 low = high_low & 0xff;
1097 high = (high_low >> 8) & 0xff;
1098
1099 /*
1100 * Lower the "search" bit rate, to give new "search" mode
1101 * approximately the same throughput as "active" if:
1102 *
1103 * 1) "Active" mode has been working modestly well (but not
1104 * great), and expected "search" throughput (under perfect
1105 * conditions) at candidate rate is above the actual
1106 * measured "active" throughput (but less than expected
1107 * "active" throughput under perfect conditions).
1108 * OR
1109 * 2) "Active" mode has been working perfectly or very well
1110 * and expected "search" throughput (under perfect
1111 * conditions) at candidate rate is above expected
1112 * "active" throughput (under perfect conditions).
1113 */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001114 if ((100 * tpt_tbl[rate] > lq_sta->last_tpt &&
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001115 (active_sr > RATE_DECREASE_TH &&
1116 active_sr <= RATE_HIGH_TH &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001117 tpt_tbl[rate] <= active_tpt)) ||
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001118 (active_sr >= RATE_SCALE_SWITCH &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001119 tpt_tbl[rate] > active_tpt)) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001120
1121 /* (2nd or later pass)
1122 * If we've already tried to raise the rate, and are
1123 * now trying to lower it, use the higher rate. */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001124 if (start_hi != RATE_INVALID) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001125 new_rate = start_hi;
1126 break;
1127 }
1128
1129 new_rate = rate;
1130
1131 /* Loop again with lower rate */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001132 if (low != RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001133 rate = low;
1134
1135 /* Lower rate not available, use the original */
1136 else
1137 break;
1138
1139 /* Else try to raise the "search" rate to match "active" */
1140 } else {
1141 /* (2nd or later pass)
1142 * If we've already tried to lower the rate, and are
1143 * now trying to raise it, use the lower rate. */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001144 if (new_rate != RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001145 break;
1146
1147 /* Loop again with higher rate */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001148 else if (high != RATE_INVALID) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001149 start_hi = high;
1150 rate = high;
1151
1152 /* Higher rate not available, use the original */
1153 } else {
1154 new_rate = rate;
1155 break;
1156 }
1157 }
1158 }
1159
1160 return new_rate;
1161}
1162
1163/*
1164 * Set up search table for MIMO2
1165 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001166static int il4965_rs_switch_to_mimo2(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001167 struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001168 struct ieee80211_conf *conf,
1169 struct ieee80211_sta *sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001170 struct il_scale_tbl_info *tbl, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001171{
1172 u16 rate_mask;
1173 s32 rate;
1174 s8 is_green = lq_sta->is_green;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001175 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1176 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001177
1178 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1179 return -1;
1180
1181 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1182 == WLAN_HT_CAP_SM_PS_STATIC)
1183 return -1;
1184
1185 /* Need both Tx chains/antennas to support MIMO */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001186 if (il->hw_params.tx_chains_num < 2)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001187 return -1;
1188
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001189 D_RATE("LQ: try to switch to MIMO2\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001190
1191 tbl->lq_type = LQ_MIMO2;
1192 tbl->is_dup = lq_sta->is_dup;
1193 tbl->action = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001194 tbl->max_search = IL_MAX_SEARCH;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001195 rate_mask = lq_sta->active_mimo2_rate;
1196
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001197 if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001198 tbl->is_ht40 = 1;
1199 else
1200 tbl->is_ht40 = 0;
1201
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001202 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001203
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001204 rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001205
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001206 D_RATE("LQ: MIMO2 best rate %d mask %X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001207 rate, rate_mask);
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001208 if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001209 D_RATE(
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001210 "Can't switch with idx %d rate mask %x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001211 rate, rate_mask);
1212 return -1;
1213 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001214 tbl->current_rate = il4965_rate_n_flags_from_tbl(il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001215 tbl, rate, is_green);
1216
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001217 D_RATE("LQ: Switch to new mcs %X idx is green %X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001218 tbl->current_rate, is_green);
1219 return 0;
1220}
1221
1222/*
1223 * Set up search table for SISO
1224 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001225static int il4965_rs_switch_to_siso(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001226 struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001227 struct ieee80211_conf *conf,
1228 struct ieee80211_sta *sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001229 struct il_scale_tbl_info *tbl, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001230{
1231 u16 rate_mask;
1232 u8 is_green = lq_sta->is_green;
1233 s32 rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001234 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1235 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001236
1237 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1238 return -1;
1239
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001240 D_RATE("LQ: try to switch to SISO\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001241
1242 tbl->is_dup = lq_sta->is_dup;
1243 tbl->lq_type = LQ_SISO;
1244 tbl->action = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001245 tbl->max_search = IL_MAX_SEARCH;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001246 rate_mask = lq_sta->active_siso_rate;
1247
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001248 if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001249 tbl->is_ht40 = 1;
1250 else
1251 tbl->is_ht40 = 0;
1252
1253 if (is_green)
1254 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
1255
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001256 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001257 rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001258
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001259 D_RATE("LQ: get best rate %d mask %X\n", rate, rate_mask);
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001260 if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001261 D_RATE(
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001262 "can not switch with idx %d rate mask %x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001263 rate, rate_mask);
1264 return -1;
1265 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001266 tbl->current_rate = il4965_rate_n_flags_from_tbl(il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001267 tbl, rate, is_green);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001268 D_RATE("LQ: Switch to new mcs %X idx is green %X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001269 tbl->current_rate, is_green);
1270 return 0;
1271}
1272
1273/*
1274 * Try to switch to new modulation mode from legacy
1275 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001276static int il4965_rs_move_legacy_other(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001277 struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001278 struct ieee80211_conf *conf,
1279 struct ieee80211_sta *sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001280 int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001281{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001282 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1283 struct il_scale_tbl_info *search_tbl =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001284 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001285 struct il_rate_scale_data *win = &(tbl->win[idx]);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001286 u32 sz = (sizeof(struct il_scale_tbl_info) -
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001287 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001288 u8 start_action;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001289 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1290 u8 tx_chains_num = il->hw_params.tx_chains_num;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001291 int ret = 0;
1292 u8 update_search_tbl_counter = 0;
1293
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001294 tbl->action = IL_LEGACY_SWITCH_SISO;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001295
1296 start_action = tbl->action;
1297 for (; ;) {
1298 lq_sta->action_counter++;
1299 switch (tbl->action) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001300 case IL_LEGACY_SWITCH_ANTENNA1:
1301 case IL_LEGACY_SWITCH_ANTENNA2:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001302 D_RATE("LQ: Legacy toggle Antenna\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001303
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001304 if ((tbl->action == IL_LEGACY_SWITCH_ANTENNA1 &&
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001305 tx_chains_num <= 1) ||
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001306 (tbl->action == IL_LEGACY_SWITCH_ANTENNA2 &&
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001307 tx_chains_num <= 2))
1308 break;
1309
1310 /* Don't change antenna if success has been great */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001311 if (win->success_ratio >= IL_RS_GOOD_RATIO)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001312 break;
1313
1314 /* Set up search table to try other antenna */
1315 memcpy(search_tbl, tbl, sz);
1316
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001317 if (il4965_rs_toggle_antenna(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001318 &search_tbl->current_rate, search_tbl)) {
1319 update_search_tbl_counter = 1;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001320 il4965_rs_set_expected_tpt_table(lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001321 search_tbl);
1322 goto out;
1323 }
1324 break;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001325 case IL_LEGACY_SWITCH_SISO:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001326 D_RATE("LQ: Legacy switch to SISO\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001327
1328 /* Set up search table to try SISO */
1329 memcpy(search_tbl, tbl, sz);
1330 search_tbl->is_SGI = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001331 ret = il4965_rs_switch_to_siso(il, lq_sta, conf, sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001332 search_tbl, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001333 if (!ret) {
1334 lq_sta->action_counter = 0;
1335 goto out;
1336 }
1337
1338 break;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001339 case IL_LEGACY_SWITCH_MIMO2_AB:
1340 case IL_LEGACY_SWITCH_MIMO2_AC:
1341 case IL_LEGACY_SWITCH_MIMO2_BC:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001342 D_RATE("LQ: Legacy switch to MIMO2\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001343
1344 /* Set up search table to try MIMO */
1345 memcpy(search_tbl, tbl, sz);
1346 search_tbl->is_SGI = 0;
1347
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001348 if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AB)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001349 search_tbl->ant_type = ANT_AB;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001350 else if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AC)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001351 search_tbl->ant_type = ANT_AC;
1352 else
1353 search_tbl->ant_type = ANT_BC;
1354
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001355 if (!il4965_rs_is_valid_ant(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001356 search_tbl->ant_type))
1357 break;
1358
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001359 ret = il4965_rs_switch_to_mimo2(il, lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001360 conf, sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001361 search_tbl, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001362 if (!ret) {
1363 lq_sta->action_counter = 0;
1364 goto out;
1365 }
1366 break;
1367 }
1368 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001369 if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC)
1370 tbl->action = IL_LEGACY_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001371
1372 if (tbl->action == start_action)
1373 break;
1374
1375 }
1376 search_tbl->lq_type = LQ_NONE;
1377 return 0;
1378
1379out:
1380 lq_sta->search_better_tbl = 1;
1381 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001382 if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC)
1383 tbl->action = IL_LEGACY_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001384 if (update_search_tbl_counter)
1385 search_tbl->action = tbl->action;
1386 return 0;
1387
1388}
1389
1390/*
1391 * Try to switch to new modulation mode from SISO
1392 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001393static int il4965_rs_move_siso_to_other(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001394 struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001395 struct ieee80211_conf *conf,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001396 struct ieee80211_sta *sta, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001397{
1398 u8 is_green = lq_sta->is_green;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001399 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1400 struct il_scale_tbl_info *search_tbl =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001401 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001402 struct il_rate_scale_data *win = &(tbl->win[idx]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001403 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001404 u32 sz = (sizeof(struct il_scale_tbl_info) -
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001405 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001406 u8 start_action;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001407 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1408 u8 tx_chains_num = il->hw_params.tx_chains_num;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001409 u8 update_search_tbl_counter = 0;
1410 int ret;
1411
1412 start_action = tbl->action;
1413
1414 for (;;) {
1415 lq_sta->action_counter++;
1416 switch (tbl->action) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001417 case IL_SISO_SWITCH_ANTENNA1:
1418 case IL_SISO_SWITCH_ANTENNA2:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001419 D_RATE("LQ: SISO toggle Antenna\n");
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001420 if ((tbl->action == IL_SISO_SWITCH_ANTENNA1 &&
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001421 tx_chains_num <= 1) ||
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001422 (tbl->action == IL_SISO_SWITCH_ANTENNA2 &&
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001423 tx_chains_num <= 2))
1424 break;
1425
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001426 if (win->success_ratio >= IL_RS_GOOD_RATIO)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001427 break;
1428
1429 memcpy(search_tbl, tbl, sz);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001430 if (il4965_rs_toggle_antenna(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001431 &search_tbl->current_rate, search_tbl)) {
1432 update_search_tbl_counter = 1;
1433 goto out;
1434 }
1435 break;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001436 case IL_SISO_SWITCH_MIMO2_AB:
1437 case IL_SISO_SWITCH_MIMO2_AC:
1438 case IL_SISO_SWITCH_MIMO2_BC:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001439 D_RATE("LQ: SISO switch to MIMO2\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001440 memcpy(search_tbl, tbl, sz);
1441 search_tbl->is_SGI = 0;
1442
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001443 if (tbl->action == IL_SISO_SWITCH_MIMO2_AB)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001444 search_tbl->ant_type = ANT_AB;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001445 else if (tbl->action == IL_SISO_SWITCH_MIMO2_AC)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001446 search_tbl->ant_type = ANT_AC;
1447 else
1448 search_tbl->ant_type = ANT_BC;
1449
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001450 if (!il4965_rs_is_valid_ant(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001451 search_tbl->ant_type))
1452 break;
1453
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001454 ret = il4965_rs_switch_to_mimo2(il, lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001455 conf, sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001456 search_tbl, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001457 if (!ret)
1458 goto out;
1459 break;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001460 case IL_SISO_SWITCH_GI:
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001461 if (!tbl->is_ht40 && !(ht_cap->cap &
1462 IEEE80211_HT_CAP_SGI_20))
1463 break;
1464 if (tbl->is_ht40 && !(ht_cap->cap &
1465 IEEE80211_HT_CAP_SGI_40))
1466 break;
1467
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001468 D_RATE("LQ: SISO toggle SGI/NGI\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001469
1470 memcpy(search_tbl, tbl, sz);
1471 if (is_green) {
1472 if (!tbl->is_SGI)
1473 break;
1474 else
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001475 IL_ERR(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001476 "SGI was set in GF+SISO\n");
1477 }
1478 search_tbl->is_SGI = !tbl->is_SGI;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001479 il4965_rs_set_expected_tpt_table(lq_sta, search_tbl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001480 if (tbl->is_SGI) {
1481 s32 tpt = lq_sta->last_tpt / 100;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001482 if (tpt >= search_tbl->expected_tpt[idx])
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001483 break;
1484 }
1485 search_tbl->current_rate =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001486 il4965_rate_n_flags_from_tbl(il, search_tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001487 idx, is_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001488 update_search_tbl_counter = 1;
1489 goto out;
1490 }
1491 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001492 if (tbl->action > IL_SISO_SWITCH_GI)
1493 tbl->action = IL_SISO_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001494
1495 if (tbl->action == start_action)
1496 break;
1497 }
1498 search_tbl->lq_type = LQ_NONE;
1499 return 0;
1500
1501 out:
1502 lq_sta->search_better_tbl = 1;
1503 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001504 if (tbl->action > IL_SISO_SWITCH_GI)
1505 tbl->action = IL_SISO_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001506 if (update_search_tbl_counter)
1507 search_tbl->action = tbl->action;
1508
1509 return 0;
1510}
1511
1512/*
1513 * Try to switch to new modulation mode from MIMO2
1514 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001515static int il4965_rs_move_mimo2_to_other(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001516 struct il_lq_sta *lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001517 struct ieee80211_conf *conf,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001518 struct ieee80211_sta *sta, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001519{
1520 s8 is_green = lq_sta->is_green;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001521 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1522 struct il_scale_tbl_info *search_tbl =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001523 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001524 struct il_rate_scale_data *win = &(tbl->win[idx]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001525 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001526 u32 sz = (sizeof(struct il_scale_tbl_info) -
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001527 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001528 u8 start_action;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001529 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1530 u8 tx_chains_num = il->hw_params.tx_chains_num;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001531 u8 update_search_tbl_counter = 0;
1532 int ret;
1533
1534 start_action = tbl->action;
1535 for (;;) {
1536 lq_sta->action_counter++;
1537 switch (tbl->action) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001538 case IL_MIMO2_SWITCH_ANTENNA1:
1539 case IL_MIMO2_SWITCH_ANTENNA2:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001540 D_RATE("LQ: MIMO2 toggle Antennas\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001541
1542 if (tx_chains_num <= 2)
1543 break;
1544
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001545 if (win->success_ratio >= IL_RS_GOOD_RATIO)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001546 break;
1547
1548 memcpy(search_tbl, tbl, sz);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001549 if (il4965_rs_toggle_antenna(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001550 &search_tbl->current_rate, search_tbl)) {
1551 update_search_tbl_counter = 1;
1552 goto out;
1553 }
1554 break;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001555 case IL_MIMO2_SWITCH_SISO_A:
1556 case IL_MIMO2_SWITCH_SISO_B:
1557 case IL_MIMO2_SWITCH_SISO_C:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001558 D_RATE("LQ: MIMO2 switch to SISO\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001559
1560 /* Set up new search table for SISO */
1561 memcpy(search_tbl, tbl, sz);
1562
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001563 if (tbl->action == IL_MIMO2_SWITCH_SISO_A)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001564 search_tbl->ant_type = ANT_A;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001565 else if (tbl->action == IL_MIMO2_SWITCH_SISO_B)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001566 search_tbl->ant_type = ANT_B;
1567 else
1568 search_tbl->ant_type = ANT_C;
1569
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001570 if (!il4965_rs_is_valid_ant(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001571 search_tbl->ant_type))
1572 break;
1573
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001574 ret = il4965_rs_switch_to_siso(il, lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001575 conf, sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001576 search_tbl, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001577 if (!ret)
1578 goto out;
1579
1580 break;
1581
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001582 case IL_MIMO2_SWITCH_GI:
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001583 if (!tbl->is_ht40 && !(ht_cap->cap &
1584 IEEE80211_HT_CAP_SGI_20))
1585 break;
1586 if (tbl->is_ht40 && !(ht_cap->cap &
1587 IEEE80211_HT_CAP_SGI_40))
1588 break;
1589
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001590 D_RATE("LQ: MIMO2 toggle SGI/NGI\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001591
1592 /* Set up new search table for MIMO2 */
1593 memcpy(search_tbl, tbl, sz);
1594 search_tbl->is_SGI = !tbl->is_SGI;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001595 il4965_rs_set_expected_tpt_table(lq_sta, search_tbl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001596 /*
1597 * If active table already uses the fastest possible
1598 * modulation (dual stream with short guard interval),
1599 * and it's working well, there's no need to look
1600 * for a better type of modulation!
1601 */
1602 if (tbl->is_SGI) {
1603 s32 tpt = lq_sta->last_tpt / 100;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001604 if (tpt >= search_tbl->expected_tpt[idx])
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001605 break;
1606 }
1607 search_tbl->current_rate =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001608 il4965_rate_n_flags_from_tbl(il, search_tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001609 idx, is_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001610 update_search_tbl_counter = 1;
1611 goto out;
1612
1613 }
1614 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001615 if (tbl->action > IL_MIMO2_SWITCH_GI)
1616 tbl->action = IL_MIMO2_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001617
1618 if (tbl->action == start_action)
1619 break;
1620 }
1621 search_tbl->lq_type = LQ_NONE;
1622 return 0;
1623 out:
1624 lq_sta->search_better_tbl = 1;
1625 tbl->action++;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001626 if (tbl->action > IL_MIMO2_SWITCH_GI)
1627 tbl->action = IL_MIMO2_SWITCH_ANTENNA1;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001628 if (update_search_tbl_counter)
1629 search_tbl->action = tbl->action;
1630
1631 return 0;
1632
1633}
1634
1635/*
1636 * Check whether we should continue using same modulation mode, or
1637 * begin search for a new mode, based on:
1638 * 1) # tx successes or failures while using this mode
1639 * 2) # times calling this function
1640 * 3) elapsed time in this mode (not used, for now)
1641 */
1642static void
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001643il4965_rs_stay_in_table(struct il_lq_sta *lq_sta, bool force_search)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001644{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001645 struct il_scale_tbl_info *tbl;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001646 int i;
1647 int active_tbl;
1648 int flush_interval_passed = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001649 struct il_priv *il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001650
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001651 il = lq_sta->drv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001652 active_tbl = lq_sta->active_tbl;
1653
1654 tbl = &(lq_sta->lq_info[active_tbl]);
1655
1656 /* If we've been disallowing search, see if we should now allow it */
1657 if (lq_sta->stay_in_tbl) {
1658
1659 /* Elapsed time using current modulation mode */
1660 if (lq_sta->flush_timer)
1661 flush_interval_passed =
1662 time_after(jiffies,
1663 (unsigned long)(lq_sta->flush_timer +
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001664 RATE_SCALE_FLUSH_INTVL));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001665
1666 /*
1667 * Check if we should allow search for new modulation mode.
1668 * If many frames have failed or succeeded, or we've used
1669 * this same modulation for a long time, allow search, and
1670 * reset history stats that keep track of whether we should
1671 * allow a new search. Also (below) reset all bitmaps and
1672 * stats in active history.
1673 */
1674 if (force_search ||
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001675 lq_sta->total_failed > lq_sta->max_failure_limit ||
1676 lq_sta->total_success > lq_sta->max_success_limit ||
1677 (!lq_sta->search_better_tbl && lq_sta->flush_timer &&
1678 flush_interval_passed)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001679 D_RATE("LQ: stay is expired %d %d %d\n:",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001680 lq_sta->total_failed,
1681 lq_sta->total_success,
1682 flush_interval_passed);
1683
1684 /* Allow search for new mode */
1685 lq_sta->stay_in_tbl = 0; /* only place reset */
1686 lq_sta->total_failed = 0;
1687 lq_sta->total_success = 0;
1688 lq_sta->flush_timer = 0;
1689
1690 /*
1691 * Else if we've used this modulation mode enough repetitions
1692 * (regardless of elapsed time or success/failure), reset
1693 * history bitmaps and rate-specific stats for all rates in
1694 * active table.
1695 */
1696 } else {
1697 lq_sta->table_count++;
1698 if (lq_sta->table_count >=
1699 lq_sta->table_count_limit) {
1700 lq_sta->table_count = 0;
1701
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001702 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001703 "LQ: stay in table clear win\n");
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001704 for (i = 0; i < RATE_COUNT; i++)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001705 il4965_rs_rate_scale_clear_win(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001706 &(tbl->win[i]));
1707 }
1708 }
1709
1710 /* If transitioning to allow "search", reset all history
1711 * bitmaps and stats in active table (this will become the new
1712 * "search" table). */
1713 if (!lq_sta->stay_in_tbl) {
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001714 for (i = 0; i < RATE_COUNT; i++)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001715 il4965_rs_rate_scale_clear_win(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001716 &(tbl->win[i]));
1717 }
1718 }
1719}
1720
1721/*
1722 * setup rate table in uCode
1723 * return rate_n_flags as used in the table
1724 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001725static u32 il4965_rs_update_rate_tbl(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001726 struct il_rxon_context *ctx,
1727 struct il_lq_sta *lq_sta,
1728 struct il_scale_tbl_info *tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001729 int idx, u8 is_green)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001730{
1731 u32 rate;
1732
1733 /* Update uCode's rate table. */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001734 rate = il4965_rate_n_flags_from_tbl(il, tbl, idx, is_green);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001735 il4965_rs_fill_link_cmd(il, lq_sta, rate);
1736 il_send_lq_cmd(il, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001737
1738 return rate;
1739}
1740
1741/*
1742 * Do rate scaling and search for new modulation mode.
1743 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001744static void il4965_rs_rate_scale_perform(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001745 struct sk_buff *skb,
1746 struct ieee80211_sta *sta,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001747 struct il_lq_sta *lq_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001748{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001749 struct ieee80211_hw *hw = il->hw;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001750 struct ieee80211_conf *conf = &hw->conf;
1751 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1752 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001753 int low = RATE_INVALID;
1754 int high = RATE_INVALID;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001755 int idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001756 int i;
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001757 struct il_rate_scale_data *win = NULL;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001758 int current_tpt = IL_INVALID_VALUE;
1759 int low_tpt = IL_INVALID_VALUE;
1760 int high_tpt = IL_INVALID_VALUE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001761 u32 fail_count;
1762 s8 scale_action = 0;
1763 u16 rate_mask;
1764 u8 update_lq = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001765 struct il_scale_tbl_info *tbl, *tbl1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001766 u16 rate_scale_idx_msk = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001767 u32 rate;
1768 u8 is_green = 0;
1769 u8 active_tbl = 0;
1770 u8 done_search = 0;
1771 u16 high_low;
1772 s32 sr;
1773 u8 tid = MAX_TID_COUNT;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001774 struct il_tid_data *tid_data;
1775 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1776 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001777
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001778 D_RATE("rate scale calculate new rate for skb\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001779
1780 /* Send management frames and NO_ACK data using lowest rate. */
1781 /* TODO: this could probably be improved.. */
1782 if (!ieee80211_is_data(hdr->frame_control) ||
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001783 (info->flags & IEEE80211_TX_CTL_NO_ACK))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001784 return;
1785
1786 if (!sta || !lq_sta)
1787 return;
1788
1789 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
1790
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001791 tid = il4965_rs_tl_add_packet(lq_sta, hdr);
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001792 if (tid != MAX_TID_COUNT && (lq_sta->tx_agg_tid_en & (1 << tid))) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001793 tid_data = &il->stations[lq_sta->lq.sta_id].tid[tid];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001794 if (tid_data->agg.state == IL_AGG_OFF)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001795 lq_sta->is_agg = 0;
1796 else
1797 lq_sta->is_agg = 1;
1798 } else
1799 lq_sta->is_agg = 0;
1800
1801 /*
1802 * Select rate-scale / modulation-mode table to work with in
1803 * the rest of this function: "search" if searching for better
1804 * modulation mode, or "active" if doing rate scaling within a mode.
1805 */
1806 if (!lq_sta->search_better_tbl)
1807 active_tbl = lq_sta->active_tbl;
1808 else
1809 active_tbl = 1 - lq_sta->active_tbl;
1810
1811 tbl = &(lq_sta->lq_info[active_tbl]);
1812 if (is_legacy(tbl->lq_type))
1813 lq_sta->is_green = 0;
1814 else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001815 lq_sta->is_green = il4965_rs_use_green(sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001816 is_green = lq_sta->is_green;
1817
1818 /* current tx rate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001819 idx = lq_sta->last_txrate_idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001820
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001821 D_RATE("Rate scale idx %d for type %d\n", idx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001822 tbl->lq_type);
1823
1824 /* rates available for this association, and for modulation mode */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001825 rate_mask = il4965_rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001826
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001827 D_RATE("mask 0x%04X\n", rate_mask);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001828
1829 /* mask with station rate restriction */
1830 if (is_legacy(tbl->lq_type)) {
1831 if (lq_sta->band == IEEE80211_BAND_5GHZ)
1832 /* supp_rates has no CCK bits in A mode */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001833 rate_scale_idx_msk = (u16) (rate_mask &
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001834 (lq_sta->supp_rates << IL_FIRST_OFDM_RATE));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001835 else
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001836 rate_scale_idx_msk = (u16) (rate_mask &
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001837 lq_sta->supp_rates);
1838
1839 } else
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001840 rate_scale_idx_msk = rate_mask;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001841
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001842 if (!rate_scale_idx_msk)
1843 rate_scale_idx_msk = rate_mask;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001844
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001845 if (!((1 << idx) & rate_scale_idx_msk)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001846 IL_ERR("Current Rate is not valid\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001847 if (lq_sta->search_better_tbl) {
1848 /* revert to active table if search table is not valid*/
1849 tbl->lq_type = LQ_NONE;
1850 lq_sta->search_better_tbl = 0;
1851 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1852 /* get "active" rate info */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001853 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001854 rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001855 tbl, idx, is_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001856 }
1857 return;
1858 }
1859
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001860 /* Get expected throughput table and history win for current rate */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001861 if (!tbl->expected_tpt) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001862 IL_ERR("tbl->expected_tpt is NULL\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001863 return;
1864 }
1865
1866 /* force user max rate if set by user */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001867 if (lq_sta->max_rate_idx != -1 &&
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001868 lq_sta->max_rate_idx < idx) {
1869 idx = lq_sta->max_rate_idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001870 update_lq = 1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001871 win = &(tbl->win[idx]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001872 goto lq_update;
1873 }
1874
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001875 win = &(tbl->win[idx]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001876
1877 /*
1878 * If there is not enough history to calculate actual average
1879 * throughput, keep analyzing results of more tx frames, without
1880 * changing rate or mode (bypass most of the rest of this function).
1881 * Set up new rate table in uCode only if old rate is not supported
1882 * in current association (use new rate found above).
1883 */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001884 fail_count = win->counter - win->success_counter;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001885 if (fail_count < RATE_MIN_FAILURE_TH &&
1886 win->success_counter < RATE_MIN_SUCCESS_TH) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001887 D_RATE("LQ: still below TH. succ=%d total=%d "
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001888 "for idx %d\n",
1889 win->success_counter, win->counter, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001890
1891 /* Can't calculate this yet; not enough history */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001892 win->average_tpt = IL_INVALID_VALUE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001893
1894 /* Should we stay with this modulation mode,
1895 * or search for a new one? */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001896 il4965_rs_stay_in_table(lq_sta, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001897
1898 goto out;
1899 }
1900 /* Else we have enough samples; calculate estimate of
1901 * actual average throughput */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001902 if (win->average_tpt != ((win->success_ratio *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001903 tbl->expected_tpt[idx] + 64) / 128)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001904 IL_ERR(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001905 "expected_tpt should have been calculated by now\n");
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001906 win->average_tpt = ((win->success_ratio *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001907 tbl->expected_tpt[idx] + 64) / 128);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001908 }
1909
1910 /* If we are searching for better modulation mode, check success. */
1911 if (lq_sta->search_better_tbl) {
1912 /* If good success, continue using the "search" mode;
1913 * no need to send new link quality command, since we're
1914 * continuing to use the setup that we've been trying. */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001915 if (win->average_tpt > lq_sta->last_tpt) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001916
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001917 D_RATE("LQ: SWITCHING TO NEW TBL "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001918 "suc=%d cur-tpt=%d old-tpt=%d\n",
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001919 win->success_ratio,
1920 win->average_tpt,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001921 lq_sta->last_tpt);
1922
1923 if (!is_legacy(tbl->lq_type))
1924 lq_sta->enable_counter = 1;
1925
1926 /* Swap tables; "search" becomes "active" */
1927 lq_sta->active_tbl = active_tbl;
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001928 current_tpt = win->average_tpt;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001929
1930 /* Else poor success; go back to mode in "active" table */
1931 } else {
1932
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001933 D_RATE("LQ: GOING BACK TO THE OLD TBL "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001934 "suc=%d cur-tpt=%d old-tpt=%d\n",
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001935 win->success_ratio,
1936 win->average_tpt,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001937 lq_sta->last_tpt);
1938
1939 /* Nullify "search" table */
1940 tbl->lq_type = LQ_NONE;
1941
1942 /* Revert to "active" table */
1943 active_tbl = lq_sta->active_tbl;
1944 tbl = &(lq_sta->lq_info[active_tbl]);
1945
1946 /* Revert to "active" rate and throughput info */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001947 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001948 current_tpt = lq_sta->last_tpt;
1949
1950 /* Need to set up a new rate table in uCode */
1951 update_lq = 1;
1952 }
1953
1954 /* Either way, we've made a decision; modulation mode
1955 * search is done, allow rate adjustment next time. */
1956 lq_sta->search_better_tbl = 0;
1957 done_search = 1; /* Don't switch modes below! */
1958 goto lq_update;
1959 }
1960
1961 /* (Else) not in search of better modulation mode, try for better
1962 * starting rate, while staying in this mode. */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001963 high_low = il4965_rs_get_adjacent_rate(il, idx,
1964 rate_scale_idx_msk,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001965 tbl->lq_type);
1966 low = high_low & 0xff;
1967 high = (high_low >> 8) & 0xff;
1968
1969 /* If user set max rate, dont allow higher than user constrain */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001970 if (lq_sta->max_rate_idx != -1 &&
1971 lq_sta->max_rate_idx < high)
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001972 high = RATE_INVALID;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001973
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001974 sr = win->success_ratio;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001975
1976 /* Collect measured throughputs for current and adjacent rates */
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02001977 current_tpt = win->average_tpt;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001978 if (low != RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001979 low_tpt = tbl->win[low].average_tpt;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001980 if (high != RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001981 high_tpt = tbl->win[high].average_tpt;
1982
1983 scale_action = 0;
1984
1985 /* Too many failures, decrease rate */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001986 if (sr <= RATE_DECREASE_TH || current_tpt == 0) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001987 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001988 "decrease rate because of low success_ratio\n");
1989 scale_action = -1;
1990
1991 /* No throughput measured yet for adjacent rates; try increase. */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001992 } else if (low_tpt == IL_INVALID_VALUE &&
1993 high_tpt == IL_INVALID_VALUE) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001994
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001995 if (high != RATE_INVALID && sr >= RATE_INCREASE_TH)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001996 scale_action = 1;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02001997 else if (low != RATE_INVALID)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001998 scale_action = 0;
1999 }
2000
2001 /* Both adjacent throughputs are measured, but neither one has better
2002 * throughput; we're using the best rate, don't change it! */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002003 else if (low_tpt != IL_INVALID_VALUE && high_tpt != IL_INVALID_VALUE &&
2004 low_tpt < current_tpt && high_tpt < current_tpt)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002005 scale_action = 0;
2006
2007 /* At least one adjacent rate's throughput is measured,
2008 * and may have better performance. */
2009 else {
2010 /* Higher adjacent rate's throughput is measured */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002011 if (high_tpt != IL_INVALID_VALUE) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002012 /* Higher rate has better throughput */
2013 if (high_tpt > current_tpt &&
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002014 sr >= RATE_INCREASE_TH) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002015 scale_action = 1;
2016 } else {
2017 scale_action = 0;
2018 }
2019
2020 /* Lower adjacent rate's throughput is measured */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002021 } else if (low_tpt != IL_INVALID_VALUE) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002022 /* Lower rate has better throughput */
2023 if (low_tpt > current_tpt) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002024 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002025 "decrease rate because of low tpt\n");
2026 scale_action = -1;
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002027 } else if (sr >= RATE_INCREASE_TH) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002028 scale_action = 1;
2029 }
2030 }
2031 }
2032
2033 /* Sanity check; asked for decrease, but success rate or throughput
2034 * has been good at old rate. Don't change it. */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002035 if (scale_action == -1 && low != RATE_INVALID &&
2036 (sr > RATE_HIGH_TH || current_tpt > 100 * tbl->expected_tpt[low]))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002037 scale_action = 0;
2038
2039 switch (scale_action) {
2040 case -1:
2041 /* Decrease starting rate, update uCode's rate table */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002042 if (low != RATE_INVALID) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002043 update_lq = 1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002044 idx = low;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002045 }
2046
2047 break;
2048 case 1:
2049 /* Increase starting rate, update uCode's rate table */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002050 if (high != RATE_INVALID) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002051 update_lq = 1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002052 idx = high;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002053 }
2054
2055 break;
2056 case 0:
2057 /* No change */
2058 default:
2059 break;
2060 }
2061
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002062 D_RATE("choose rate scale idx %d action %d low %d "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002063 "high %d type %d\n",
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002064 idx, scale_action, low, high, tbl->lq_type);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002065
2066lq_update:
2067 /* Replace uCode's rate table for the destination station. */
2068 if (update_lq)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002069 rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002070 tbl, idx, is_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002071
2072 /* Should we stay with this modulation mode,
2073 * or search for a new one? */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002074 il4965_rs_stay_in_table(lq_sta, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002075
2076 /*
2077 * Search for new modulation mode if we're:
2078 * 1) Not changing rates right now
2079 * 2) Not just finishing up a search
2080 * 3) Allowing a new search
2081 */
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002082 if (!update_lq && !done_search && !lq_sta->stay_in_tbl &&
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02002083 win->counter) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002084 /* Save current throughput to compare with "search" throughput*/
2085 lq_sta->last_tpt = current_tpt;
2086
2087 /* Select a new "search" modulation mode to try.
2088 * If one is found, set up the new "search" table. */
2089 if (is_legacy(tbl->lq_type))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002090 il4965_rs_move_legacy_other(il, lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002091 conf, sta, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002092 else if (is_siso(tbl->lq_type))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002093 il4965_rs_move_siso_to_other(il, lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002094 conf, sta, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002095 else /* (is_mimo2(tbl->lq_type)) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002096 il4965_rs_move_mimo2_to_other(il, lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002097 conf, sta, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002098
2099 /* If new "search" mode was selected, set up in uCode table */
2100 if (lq_sta->search_better_tbl) {
2101 /* Access the "search" table, clear its history. */
2102 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002103 for (i = 0; i < RATE_COUNT; i++)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02002104 il4965_rs_rate_scale_clear_win(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002105 &(tbl->win[i]));
2106
2107 /* Use new "search" start rate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002108 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002109
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002110 D_RATE(
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002111 "Switch current mcs: %X idx: %d\n",
2112 tbl->current_rate, idx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002113 il4965_rs_fill_link_cmd(il, lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002114 tbl->current_rate);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002115 il_send_lq_cmd(il, ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002116 &lq_sta->lq, CMD_ASYNC, false);
2117 } else
2118 done_search = 1;
2119 }
2120
2121 if (done_search && !lq_sta->stay_in_tbl) {
2122 /* If the "active" (non-search) mode was legacy,
2123 * and we've tried switching antennas,
2124 * but we haven't been able to try HT modes (not available),
2125 * stay with best antenna legacy modulation for a while
2126 * before next round of mode comparisons. */
2127 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2128 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
2129 lq_sta->action_counter > tbl1->max_search) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002130 D_RATE("LQ: STAY in legacy table\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002131 il4965_rs_set_stay_in_table(il, 1, lq_sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002132 }
2133
2134 /* If we're in an HT mode, and all 3 mode switch actions
2135 * have been tried and compared, stay in this best modulation
2136 * mode for a while before next round of mode comparisons. */
2137 if (lq_sta->enable_counter &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002138 lq_sta->action_counter >= tbl1->max_search) {
2139 if (lq_sta->last_tpt > IL_AGG_TPT_THREHOLD &&
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002140 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002141 tid != MAX_TID_COUNT) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002142 tid_data =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002143 &il->stations[lq_sta->lq.sta_id].tid[tid];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002144 if (tid_data->agg.state == IL_AGG_OFF) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002145 D_RATE(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002146 "try to aggregate tid %d\n",
2147 tid);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002148 il4965_rs_tl_turn_on_agg(il, tid,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002149 lq_sta, sta);
2150 }
2151 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002152 il4965_rs_set_stay_in_table(il, 0, lq_sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002153 }
2154 }
2155
2156out:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002157 tbl->current_rate = il4965_rate_n_flags_from_tbl(il, tbl,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002158 idx, is_green);
2159 i = idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002160 lq_sta->last_txrate_idx = i;
2161}
2162
2163/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002164 * il4965_rs_initialize_lq - Initialize a station's hardware rate table
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002165 *
2166 * The uCode's station table contains a table of fallback rates
2167 * for automatic fallback during transmission.
2168 *
2169 * NOTE: This sets up a default set of values. These will be replaced later
2170 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
2171 * rc80211_simple.
2172 *
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02002173 * NOTE: Run C_ADD_STA command to set up station table entry, before
2174 * calling this function (which runs C_TX_LINK_QUALITY_CMD,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002175 * which requires station table entry to exist).
2176 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002177static void il4965_rs_initialize_lq(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002178 struct ieee80211_conf *conf,
2179 struct ieee80211_sta *sta,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002180 struct il_lq_sta *lq_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002181{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002182 struct il_scale_tbl_info *tbl;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002183 int rate_idx;
2184 int i;
2185 u32 rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002186 u8 use_green = il4965_rs_use_green(sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002187 u8 active_tbl = 0;
2188 u8 valid_tx_ant;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002189 struct il_station_priv *sta_priv;
2190 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002191
2192 if (!sta || !lq_sta)
2193 return;
2194
2195 sta_priv = (void *)sta->drv_priv;
2196 ctx = sta_priv->common.ctx;
2197
2198 i = lq_sta->last_txrate_idx;
2199
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002200 valid_tx_ant = il->hw_params.valid_tx_ant;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002201
2202 if (!lq_sta->search_better_tbl)
2203 active_tbl = lq_sta->active_tbl;
2204 else
2205 active_tbl = 1 - lq_sta->active_tbl;
2206
2207 tbl = &(lq_sta->lq_info[active_tbl]);
2208
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002209 if (i < 0 || i >= RATE_COUNT)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002210 i = 0;
2211
Stanislaw Gruszkad2ddf6212011-08-16 14:17:04 +02002212 rate = il_rates[i].plcp;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002213 tbl->ant_type = il4965_first_antenna(valid_tx_ant);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002214 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
2215
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002216 if (i >= IL_FIRST_CCK_RATE && i <= IL_LAST_CCK_RATE)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002217 rate |= RATE_MCS_CCK_MSK;
2218
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002219 il4965_rs_get_tbl_info_from_mcs(rate, il->band, tbl, &rate_idx);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002220 if (!il4965_rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2221 il4965_rs_toggle_antenna(valid_tx_ant, &rate, tbl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002222
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002223 rate = il4965_rate_n_flags_from_tbl(il, tbl, rate_idx, use_green);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002224 tbl->current_rate = rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002225 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
2226 il4965_rs_fill_link_cmd(NULL, lq_sta, rate);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002227 il->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
2228 il_send_lq_cmd(il, ctx, &lq_sta->lq, CMD_SYNC, true);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002229}
2230
2231static void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002232il4965_rs_get_rate(void *il_r, struct ieee80211_sta *sta, void *il_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002233 struct ieee80211_tx_rate_control *txrc)
2234{
2235
2236 struct sk_buff *skb = txrc->skb;
2237 struct ieee80211_supported_band *sband = txrc->sband;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002238 struct il_priv *il __maybe_unused = (struct il_priv *)il_r;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002239 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002240 struct il_lq_sta *lq_sta = il_sta;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002241 int rate_idx;
2242
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002243 D_RATE("rate scale calculate new rate for skb\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002244
2245 /* Get max rate if user set max rate */
2246 if (lq_sta) {
2247 lq_sta->max_rate_idx = txrc->max_rate_idx;
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002248 if (sband->band == IEEE80211_BAND_5GHZ &&
2249 lq_sta->max_rate_idx != -1)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002250 lq_sta->max_rate_idx += IL_FIRST_OFDM_RATE;
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002251 if (lq_sta->max_rate_idx < 0 ||
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002252 lq_sta->max_rate_idx >= RATE_COUNT)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002253 lq_sta->max_rate_idx = -1;
2254 }
2255
2256 /* Treat uninitialized rate scaling data same as non-existing. */
2257 if (lq_sta && !lq_sta->drv) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002258 D_RATE("Rate scaling not initialized yet.\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002259 il_sta = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002260 }
2261
2262 /* Send management frames and NO_ACK data using lowest rate. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002263 if (rate_control_send_low(sta, il_sta, txrc))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002264 return;
2265
Greg Dietsche0c348612011-06-02 22:24:06 -05002266 if (!lq_sta)
2267 return;
2268
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002269 rate_idx = lq_sta->last_txrate_idx;
2270
2271 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002272 rate_idx -= IL_FIRST_OFDM_RATE;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002273 /* 6M and 9M shared same MCS idx */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002274 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002275 if (il4965_rs_extract_rate(lq_sta->last_rate_n_flags) >=
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002276 RATE_MIMO2_6M_PLCP)
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +02002277 rate_idx = rate_idx + MCS_IDX_PER_STREAM;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002278 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2279 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2280 info->control.rates[0].flags |=
2281 IEEE80211_TX_RC_SHORT_GI;
2282 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2283 info->control.rates[0].flags |=
2284 IEEE80211_TX_RC_DUP_DATA;
2285 if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK)
2286 info->control.rates[0].flags |=
2287 IEEE80211_TX_RC_40_MHZ_WIDTH;
2288 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2289 info->control.rates[0].flags |=
2290 IEEE80211_TX_RC_GREEN_FIELD;
2291 } else {
2292 /* Check for invalid rates */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002293 if (rate_idx < 0 || rate_idx >= RATE_COUNT_LEGACY ||
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02002294 (sband->band == IEEE80211_BAND_5GHZ &&
2295 rate_idx < IL_FIRST_OFDM_RATE))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002296 rate_idx = rate_lowest_index(sband, sta);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002297 /* On valid 5 GHz rate, adjust idx */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002298 else if (sband->band == IEEE80211_BAND_5GHZ)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002299 rate_idx -= IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002300 info->control.rates[0].flags = 0;
2301 }
2302 info->control.rates[0].idx = rate_idx;
2303
2304}
2305
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002306static void *il4965_rs_alloc_sta(void *il_rate, struct ieee80211_sta *sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002307 gfp_t gfp)
2308{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002309 struct il_lq_sta *lq_sta;
2310 struct il_station_priv *sta_priv =
2311 (struct il_station_priv *) sta->drv_priv;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002312 struct il_priv *il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002313
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002314 il = (struct il_priv *)il_rate;
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02002315 D_RATE("create station rate scale win\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002316
2317 lq_sta = &sta_priv->lq_sta;
2318
2319 return lq_sta;
2320}
2321
2322/*
2323 * Called after adding a new station to initialize rate scaling
2324 */
2325void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002326il4965_rs_rate_init(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002327 struct ieee80211_sta *sta,
2328 u8 sta_id)
2329{
2330 int i, j;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002331 struct ieee80211_hw *hw = il->hw;
2332 struct ieee80211_conf *conf = &il->hw->conf;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002333 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002334 struct il_station_priv *sta_priv;
2335 struct il_lq_sta *lq_sta;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002336 struct ieee80211_supported_band *sband;
2337
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002338 sta_priv = (struct il_station_priv *) sta->drv_priv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002339 lq_sta = &sta_priv->lq_sta;
2340 sband = hw->wiphy->bands[conf->channel->band];
2341
2342
2343 lq_sta->lq.sta_id = sta_id;
2344
2345 for (j = 0; j < LQ_SIZE; j++)
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002346 for (i = 0; i < RATE_COUNT; i++)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02002347 il4965_rs_rate_scale_clear_win(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002348 &lq_sta->lq_info[j].win[i]);
2349
2350 lq_sta->flush_timer = 0;
2351 lq_sta->supp_rates = sta->supp_rates[sband->band];
2352 for (j = 0; j < LQ_SIZE; j++)
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002353 for (i = 0; i < RATE_COUNT; i++)
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +02002354 il4965_rs_rate_scale_clear_win(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002355 &lq_sta->lq_info[j].win[i]);
2356
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002357 D_RATE("LQ:"
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002358 "*** rate scale station global init for station %d ***\n",
2359 sta_id);
2360 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2361 * the lowest or the highest rate.. Could consider using RSSI from
2362 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2363 * after assoc.. */
2364
2365 lq_sta->is_dup = 0;
2366 lq_sta->max_rate_idx = -1;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002367 lq_sta->missed_rate_counter = IL_MISSED_RATE_MAX;
2368 lq_sta->is_green = il4965_rs_use_green(sta);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002369 lq_sta->active_legacy_rate = il->active_rate & ~(0x1000);
2370 lq_sta->band = il->band;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002371 /*
2372 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2373 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2374 */
2375 lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
2376 lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
2377 lq_sta->active_siso_rate &= ~((u16)0x2);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002378 lq_sta->active_siso_rate <<= IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002379
2380 /* Same here */
2381 lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
2382 lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
2383 lq_sta->active_mimo2_rate &= ~((u16)0x2);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002384 lq_sta->active_mimo2_rate <<= IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002385
2386 /* These values will be overridden later */
2387 lq_sta->lq.general_params.single_stream_ant_msk =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002388 il4965_first_antenna(il->hw_params.valid_tx_ant);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002389 lq_sta->lq.general_params.dual_stream_ant_msk =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002390 il->hw_params.valid_tx_ant &
2391 ~il4965_first_antenna(il->hw_params.valid_tx_ant);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002392 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2393 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002394 } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002395 lq_sta->lq.general_params.dual_stream_ant_msk =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002396 il->hw_params.valid_tx_ant;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002397 }
2398
2399 /* as default allow aggregation for all tids */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002400 lq_sta->tx_agg_tid_en = IL_AGG_ALL_TID;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002401 lq_sta->drv = il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002402
2403 /* Set last_txrate_idx to lowest rate */
2404 lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
2405 if (sband->band == IEEE80211_BAND_5GHZ)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002406 lq_sta->last_txrate_idx += IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002407 lq_sta->is_agg = 0;
2408
2409#ifdef CONFIG_MAC80211_DEBUGFS
2410 lq_sta->dbg_fixed_rate = 0;
2411#endif
2412
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002413 il4965_rs_initialize_lq(il, conf, sta, lq_sta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002414}
2415
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002416static void il4965_rs_fill_link_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002417 struct il_lq_sta *lq_sta, u32 new_rate)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002418{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002419 struct il_scale_tbl_info tbl_type;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002420 int idx = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002421 int rate_idx;
2422 int repeat_rate = 0;
2423 u8 ant_toggle_cnt = 0;
2424 u8 use_ht_possible = 1;
2425 u8 valid_tx_ant = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002426 struct il_link_quality_cmd *lq_cmd = &lq_sta->lq;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002427
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002428 /* Override starting rate (idx 0) if needed for debug purposes */
2429 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002430
2431 /* Interpret new_rate (rate_n_flags) */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002432 il4965_rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002433 &tbl_type, &rate_idx);
2434
2435 /* How many times should we repeat the initial rate? */
2436 if (is_legacy(tbl_type.lq_type)) {
2437 ant_toggle_cnt = 1;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002438 repeat_rate = IL_NUMBER_TRY;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002439 } else {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002440 repeat_rate = IL_HT_NUMBER_TRY;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002441 }
2442
2443 lq_cmd->general_params.mimo_delimiter =
2444 is_mimo(tbl_type.lq_type) ? 1 : 0;
2445
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002446 /* Fill 1st table entry (idx 0) */
2447 lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002448
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002449 if (il4965_num_of_ant(tbl_type.ant_type) == 1) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002450 lq_cmd->general_params.single_stream_ant_msk =
2451 tbl_type.ant_type;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002452 } else if (il4965_num_of_ant(tbl_type.ant_type) == 2) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002453 lq_cmd->general_params.dual_stream_ant_msk =
2454 tbl_type.ant_type;
2455 } /* otherwise we don't modify the existing value */
2456
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002457 idx++;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002458 repeat_rate--;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002459 if (il)
2460 valid_tx_ant = il->hw_params.valid_tx_ant;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002461
2462 /* Fill rest of rate table */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002463 while (idx < LINK_QUAL_MAX_RETRY_NUM) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002464 /* Repeat initial/next rate.
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002465 * For legacy IL_NUMBER_TRY == 1, this loop will not execute.
2466 * For HT IL_HT_NUMBER_TRY == 3, this executes twice. */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002467 while (repeat_rate > 0 && idx < LINK_QUAL_MAX_RETRY_NUM) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002468 if (is_legacy(tbl_type.lq_type)) {
2469 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2470 ant_toggle_cnt++;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002471 else if (il &&
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002472 il4965_rs_toggle_antenna(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002473 &new_rate, &tbl_type))
2474 ant_toggle_cnt = 1;
2475 }
2476
2477 /* Override next rate if needed for debug purposes */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002478 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002479
2480 /* Fill next table entry */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002481 lq_cmd->rs_table[idx].rate_n_flags =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002482 cpu_to_le32(new_rate);
2483 repeat_rate--;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002484 idx++;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002485 }
2486
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002487 il4965_rs_get_tbl_info_from_mcs(new_rate,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002488 lq_sta->band, &tbl_type,
2489 &rate_idx);
2490
2491 /* Indicate to uCode which entries might be MIMO.
2492 * If initial rate was MIMO, this will finally end up
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002493 * as (IL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002494 if (is_mimo(tbl_type.lq_type))
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002495 lq_cmd->general_params.mimo_delimiter = idx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002496
2497 /* Get next rate */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002498 new_rate = il4965_rs_get_lower_rate(lq_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002499 &tbl_type, rate_idx,
2500 use_ht_possible);
2501
2502 /* How many times should we repeat the next rate? */
2503 if (is_legacy(tbl_type.lq_type)) {
2504 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2505 ant_toggle_cnt++;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002506 else if (il &&
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002507 il4965_rs_toggle_antenna(valid_tx_ant,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002508 &new_rate, &tbl_type))
2509 ant_toggle_cnt = 1;
2510
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002511 repeat_rate = IL_NUMBER_TRY;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002512 } else {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002513 repeat_rate = IL_HT_NUMBER_TRY;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002514 }
2515
2516 /* Don't allow HT rates after next pass.
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002517 * il4965_rs_get_lower_rate() will change type to LQ_A or LQ_G. */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002518 use_ht_possible = 0;
2519
2520 /* Override next rate if needed for debug purposes */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002521 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002522
2523 /* Fill next table entry */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002524 lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002525
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002526 idx++;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002527 repeat_rate--;
2528 }
2529
2530 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2531 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
2532
2533 lq_cmd->agg_params.agg_time_limit =
2534 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
2535}
2536
2537static void
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002538*il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002539{
2540 return hw->priv;
2541}
2542/* rate scale requires free function to be implemented */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002543static void il4965_rs_free(void *il_rate)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002544{
2545 return;
2546}
2547
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002548static void il4965_rs_free_sta(void *il_r, struct ieee80211_sta *sta,
2549 void *il_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002550{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002551 struct il_priv *il __maybe_unused = il_r;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002552
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002553 D_RATE("enter\n");
2554 D_RATE("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002555}
2556
2557
2558#ifdef CONFIG_MAC80211_DEBUGFS
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002559static int il4965_open_file_generic(struct inode *inode, struct file *file)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002560{
2561 file->private_data = inode->i_private;
2562 return 0;
2563}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002564static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002565 u32 *rate_n_flags, int idx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002566{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002567 struct il_priv *il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002568 u8 valid_tx_ant;
2569 u8 ant_sel_tx;
2570
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002571 il = lq_sta->drv;
2572 valid_tx_ant = il->hw_params.valid_tx_ant;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002573 if (lq_sta->dbg_fixed_rate) {
2574 ant_sel_tx =
2575 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
2576 >> RATE_MCS_ANT_POS);
2577 if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
2578 *rate_n_flags = lq_sta->dbg_fixed_rate;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002579 D_RATE("Fixed rate ON\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002580 } else {
2581 lq_sta->dbg_fixed_rate = 0;
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002582 IL_ERR(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002583 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
2584 ant_sel_tx, valid_tx_ant);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002585 D_RATE("Fixed rate OFF\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002586 }
2587 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002588 D_RATE("Fixed rate OFF\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002589 }
2590}
2591
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002592static ssize_t il4965_rs_sta_dbgfs_scale_table_write(struct file *file,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002593 const char __user *user_buf, size_t count, loff_t *ppos)
2594{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002595 struct il_lq_sta *lq_sta = file->private_data;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002596 struct il_priv *il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002597 char buf[64];
Stephen Boyd8220ba32011-05-12 16:50:04 -07002598 size_t buf_size;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002599 u32 parsed_rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002600 struct il_station_priv *sta_priv =
2601 container_of(lq_sta, struct il_station_priv, lq_sta);
2602 struct il_rxon_context *ctx = sta_priv->common.ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002603
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002604 il = lq_sta->drv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002605 memset(buf, 0, sizeof(buf));
2606 buf_size = min(count, sizeof(buf) - 1);
2607 if (copy_from_user(buf, user_buf, buf_size))
2608 return -EFAULT;
2609
2610 if (sscanf(buf, "%x", &parsed_rate) == 1)
2611 lq_sta->dbg_fixed_rate = parsed_rate;
2612 else
2613 lq_sta->dbg_fixed_rate = 0;
2614
2615 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2616 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2617 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2618
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002619 D_RATE("sta_id %d rate 0x%X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002620 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
2621
2622 if (lq_sta->dbg_fixed_rate) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002623 il4965_rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
2624 il_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002625 false);
2626 }
2627
2628 return count;
2629}
2630
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002631static ssize_t il4965_rs_sta_dbgfs_scale_table_read(struct file *file,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002632 char __user *user_buf, size_t count, loff_t *ppos)
2633{
2634 char *buff;
2635 int desc = 0;
2636 int i = 0;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002637 int idx = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002638 ssize_t ret;
2639
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002640 struct il_lq_sta *lq_sta = file->private_data;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002641 struct il_priv *il;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002642 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002643
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002644 il = lq_sta->drv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002645 buff = kmalloc(1024, GFP_KERNEL);
2646 if (!buff)
2647 return -ENOMEM;
2648
2649 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
2650 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2651 lq_sta->total_failed, lq_sta->total_success,
2652 lq_sta->active_legacy_rate);
2653 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2654 lq_sta->dbg_fixed_rate);
2655 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002656 (il->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "",
2657 (il->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "",
2658 (il->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : "");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002659 desc += sprintf(buff+desc, "lq type %s\n",
2660 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
2661 if (is_Ht(tbl->lq_type)) {
2662 desc += sprintf(buff+desc, " %s",
2663 (is_siso(tbl->lq_type)) ? "SISO" : "MIMO2");
2664 desc += sprintf(buff+desc, " %s",
2665 (tbl->is_ht40) ? "40MHz" : "20MHz");
2666 desc += sprintf(buff+desc, " %s %s %s\n",
2667 (tbl->is_SGI) ? "SGI" : "",
2668 (lq_sta->is_green) ? "GF enabled" : "",
2669 (lq_sta->is_agg) ? "AGG on" : "");
2670 }
2671 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
2672 lq_sta->last_rate_n_flags);
2673 desc += sprintf(buff+desc, "general:"
2674 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2675 lq_sta->lq.general_params.flags,
2676 lq_sta->lq.general_params.mimo_delimiter,
2677 lq_sta->lq.general_params.single_stream_ant_msk,
2678 lq_sta->lq.general_params.dual_stream_ant_msk);
2679
2680 desc += sprintf(buff+desc, "agg:"
2681 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2682 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
2683 lq_sta->lq.agg_params.agg_dis_start_th,
2684 lq_sta->lq.agg_params.agg_frame_cnt_limit);
2685
2686 desc += sprintf(buff+desc,
2687 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002688 lq_sta->lq.general_params.start_rate_idx[0],
2689 lq_sta->lq.general_params.start_rate_idx[1],
2690 lq_sta->lq.general_params.start_rate_idx[2],
2691 lq_sta->lq.general_params.start_rate_idx[3]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002692
2693 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002694 idx = il4965_hwrate_to_plcp_idx(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002695 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2696 if (is_legacy(tbl->lq_type)) {
2697 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
2698 i,
2699 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002700 il_rate_mcs[idx].mbps);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002701 } else {
2702 desc += sprintf(buff+desc,
2703 " rate[%d] 0x%X %smbps (%s)\n",
2704 i,
2705 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002706 il_rate_mcs[idx].mbps, il_rate_mcs[idx].mcs);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002707 }
2708 }
2709
2710 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2711 kfree(buff);
2712 return ret;
2713}
2714
2715static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002716 .write = il4965_rs_sta_dbgfs_scale_table_write,
2717 .read = il4965_rs_sta_dbgfs_scale_table_read,
2718 .open = il4965_open_file_generic,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002719 .llseek = default_llseek,
2720};
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002721static ssize_t il4965_rs_sta_dbgfs_stats_table_read(struct file *file,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002722 char __user *user_buf, size_t count, loff_t *ppos)
2723{
2724 char *buff;
2725 int desc = 0;
2726 int i, j;
2727 ssize_t ret;
2728
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002729 struct il_lq_sta *lq_sta = file->private_data;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002730
2731 buff = kmalloc(1024, GFP_KERNEL);
2732 if (!buff)
2733 return -ENOMEM;
2734
2735 for (i = 0; i < LQ_SIZE; i++) {
2736 desc += sprintf(buff+desc,
2737 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
2738 "rate=0x%X\n",
2739 lq_sta->active_tbl == i ? "*" : "x",
2740 lq_sta->lq_info[i].lq_type,
2741 lq_sta->lq_info[i].is_SGI,
2742 lq_sta->lq_info[i].is_ht40,
2743 lq_sta->lq_info[i].is_dup,
2744 lq_sta->is_green,
2745 lq_sta->lq_info[i].current_rate);
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002746 for (j = 0; j < RATE_COUNT; j++) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002747 desc += sprintf(buff+desc,
2748 "counter=%d success=%d %%=%d\n",
2749 lq_sta->lq_info[i].win[j].counter,
2750 lq_sta->lq_info[i].win[j].success_counter,
2751 lq_sta->lq_info[i].win[j].success_ratio);
2752 }
2753 }
2754 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2755 kfree(buff);
2756 return ret;
2757}
2758
2759static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002760 .read = il4965_rs_sta_dbgfs_stats_table_read,
2761 .open = il4965_open_file_generic,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002762 .llseek = default_llseek,
2763};
2764
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002765static ssize_t il4965_rs_sta_dbgfs_rate_scale_data_read(struct file *file,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002766 char __user *user_buf, size_t count, loff_t *ppos)
2767{
2768 char buff[120];
2769 int desc = 0;
2770 ssize_t ret;
2771
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002772 struct il_lq_sta *lq_sta = file->private_data;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002773 struct il_priv *il;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002774 struct il_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002775
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002776 il = lq_sta->drv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002777
2778 if (is_Ht(tbl->lq_type))
2779 desc += sprintf(buff+desc,
2780 "Bit Rate= %d Mb/s\n",
2781 tbl->expected_tpt[lq_sta->last_txrate_idx]);
2782 else
2783 desc += sprintf(buff+desc,
2784 "Bit Rate= %d Mb/s\n",
Stanislaw Gruszkad2ddf6212011-08-16 14:17:04 +02002785 il_rates[lq_sta->last_txrate_idx].ieee >> 1);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002786
2787 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2788 return ret;
2789}
2790
2791static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002792 .read = il4965_rs_sta_dbgfs_rate_scale_data_read,
2793 .open = il4965_open_file_generic,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002794 .llseek = default_llseek,
2795};
2796
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002797static void il4965_rs_add_debugfs(void *il, void *il_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002798 struct dentry *dir)
2799{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002800 struct il_lq_sta *lq_sta = il_sta;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002801 lq_sta->rs_sta_dbgfs_scale_table_file =
2802 debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
2803 lq_sta, &rs_sta_dbgfs_scale_table_ops);
2804 lq_sta->rs_sta_dbgfs_stats_table_file =
2805 debugfs_create_file("rate_stats_table", S_IRUSR, dir,
2806 lq_sta, &rs_sta_dbgfs_stats_table_ops);
2807 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
2808 debugfs_create_file("rate_scale_data", S_IRUSR, dir,
2809 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
2810 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2811 debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
2812 &lq_sta->tx_agg_tid_en);
2813
2814}
2815
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002816static void il4965_rs_remove_debugfs(void *il, void *il_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002817{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002818 struct il_lq_sta *lq_sta = il_sta;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002819 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2820 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
2821 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
2822 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2823}
2824#endif
2825
2826/*
2827 * Initialization of rate scaling information is done by driver after
2828 * the station is added. Since mac80211 calls this function before a
2829 * station is added we ignore it.
2830 */
2831static void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002832il4965_rs_rate_init_stub(void *il_r, struct ieee80211_supported_band *sband,
2833 struct ieee80211_sta *sta, void *il_sta)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002834{
2835}
2836static struct rate_control_ops rs_4965_ops = {
2837 .module = NULL,
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002838 .name = IL4965_RS_NAME,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002839 .tx_status = il4965_rs_tx_status,
2840 .get_rate = il4965_rs_get_rate,
2841 .rate_init = il4965_rs_rate_init_stub,
2842 .alloc = il4965_rs_alloc,
2843 .free = il4965_rs_free,
2844 .alloc_sta = il4965_rs_alloc_sta,
2845 .free_sta = il4965_rs_free_sta,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002846#ifdef CONFIG_MAC80211_DEBUGFS
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002847 .add_sta_debugfs = il4965_rs_add_debugfs,
2848 .remove_sta_debugfs = il4965_rs_remove_debugfs,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002849#endif
2850};
2851
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002852int il4965_rate_control_register(void)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002853{
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002854 return ieee80211_rate_control_register(&rs_4965_ops);
2855}
2856
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002857void il4965_rate_control_unregister(void)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002858{
2859 ieee80211_rate_control_unregister(&rs_4965_ops);
2860}