blob: f3dd0da60d8a43247084cd0f798b132e4b28ba7a [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Wey-Yi Guyfb4961d2012-01-06 13:16:33 -08003 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080022 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070023 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070030#include <net/mac80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070031
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/delay.h>
35
36#include <linux/workqueue.h>
37
Johannes Berg1023fdc2012-05-15 12:16:34 +020038#include "dev.h"
39#include "agn.h"
Zhu Yib481de92007-09-25 17:54:57 -070040
Tomas Winklere227cea2008-07-18 13:53:05 +080041#define RS_NAME "iwl-agn-rs"
Zhu Yib481de92007-09-25 17:54:57 -070042
Guy Cohenaade00c2008-04-23 17:14:59 -070043#define NUM_TRY_BEFORE_ANT_TOGGLE 1
Zhu Yib481de92007-09-25 17:54:57 -070044#define IWL_NUMBER_TRY 1
45#define IWL_HT_NUMBER_TRY 3
46
Ben Cahill77626352007-11-29 11:09:44 +080047#define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
48#define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
49#define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
50
Abbas, Mohamed7d049e52009-01-20 21:33:53 -080051/* max allowed rate miss before sync LQ cmd */
52#define IWL_MISSED_RATE_MAX 15
Ben Cahill77626352007-11-29 11:09:44 +080053/* max time to accum history 2 seconds */
Mohamed Abbas447fee72009-04-20 14:37:02 -070054#define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
Zhu Yib481de92007-09-25 17:54:57 -070055
56static u8 rs_ht_to_legacy[] = {
57 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
59 IWL_RATE_6M_INDEX,
60 IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
61 IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
62 IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
63 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
64};
65
Guy Cohenaade00c2008-04-23 17:14:59 -070066static 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
Johannes Berg635b85b2010-09-22 18:02:04 +020077#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
78 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
79 IWL_RATE_SISO_##s##M_PLCP, \
80 IWL_RATE_MIMO2_##s##M_PLCP,\
81 IWL_RATE_MIMO3_##s##M_PLCP,\
82 IWL_RATE_##r##M_IEEE, \
83 IWL_RATE_##ip##M_INDEX, \
84 IWL_RATE_##in##M_INDEX, \
85 IWL_RATE_##rp##M_INDEX, \
86 IWL_RATE_##rn##M_INDEX, \
87 IWL_RATE_##pp##M_INDEX, \
88 IWL_RATE_##np##M_INDEX }
89
90/*
91 * Parameter order:
92 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
93 *
94 * If there isn't a valid next or previous rate then INV is used which
95 * maps to IWL_RATE_INVALID
96 *
97 */
98const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
99 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
100 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
101 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
102 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
103 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
104 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
105 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
106 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
107 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
108 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
109 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
110 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
111 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
112 /* FIXME:RS: ^^ should be INV (legacy) */
113};
114
Daniel Halperin25205462011-03-18 18:48:55 -0700115static inline u8 rs_extract_rate(u32 rate_n_flags)
116{
117 return (u8)(rate_n_flags & RATE_MCS_RATE_MSK);
118}
119
Johannes Berg635b85b2010-09-22 18:02:04 +0200120static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
121{
122 int idx = 0;
123
124 /* HT rate format */
125 if (rate_n_flags & RATE_MCS_HT_MSK) {
Daniel Halperin25205462011-03-18 18:48:55 -0700126 idx = rs_extract_rate(rate_n_flags);
Johannes Berg635b85b2010-09-22 18:02:04 +0200127
128 if (idx >= IWL_RATE_MIMO3_6M_PLCP)
129 idx = idx - IWL_RATE_MIMO3_6M_PLCP;
130 else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
131 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
132
133 idx += IWL_FIRST_OFDM_RATE;
134 /* skip 9M not supported in ht*/
135 if (idx >= IWL_RATE_9M_INDEX)
136 idx += 1;
137 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
138 return idx;
139
140 /* legacy rate format, search for match in table */
141 } else {
142 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
Daniel Halperin25205462011-03-18 18:48:55 -0700143 if (iwl_rates[idx].plcp ==
144 rs_extract_rate(rate_n_flags))
Johannes Berg635b85b2010-09-22 18:02:04 +0200145 return idx;
146 }
147
148 return -1;
149}
150
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700151static void rs_rate_scale_perform(struct iwl_priv *priv,
Gábor Stefanik514d65c2009-04-23 19:36:08 +0200152 struct sk_buff *skb,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200153 struct ieee80211_sta *sta,
154 struct iwl_lq_sta *lq_sta);
Wey-Yi Guy46f93812009-07-24 11:13:03 -0700155static void rs_fill_link_cmd(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +0800156 struct iwl_lq_sta *lq_sta, u32 rate_n_flags);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -0700157static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search);
Zhu Yib481de92007-09-25 17:54:57 -0700158
159
Zhu Yi98d7e092007-09-27 11:27:42 +0800160#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklere227cea2008-07-18 13:53:05 +0800161static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
162 u32 *rate_n_flags, int index);
Zhu Yi98d7e092007-09-27 11:27:42 +0800163#else
Tomas Winklere227cea2008-07-18 13:53:05 +0800164static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
165 u32 *rate_n_flags, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +0800166{}
167#endif
Ben Cahill77626352007-11-29 11:09:44 +0800168
Daniel C Halperine3949d62009-09-17 10:43:50 -0700169/**
170 * The following tables contain the expected throughput metrics for all rates
171 *
172 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
173 *
174 * where invalid entries are zeros.
175 *
176 * CCK rates are only valid in legacy table and will only be used in G
177 * (2.4 GHz) band.
Ben Cahill77626352007-11-29 11:09:44 +0800178 */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -0700179
Daniel C Halperine3949d62009-09-17 10:43:50 -0700180static s32 expected_tpt_legacy[IWL_RATE_COUNT] = {
181 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0
Zhu Yib481de92007-09-25 17:54:57 -0700182};
183
Daniel C Halperine3949d62009-09-17 10:43:50 -0700184static s32 expected_tpt_siso20MHz[4][IWL_RATE_COUNT] = {
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800185 {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202}, /* Norm */
186 {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210}, /* SGI */
187 {0, 0, 0, 0, 47, 0, 91, 133, 171, 242, 305, 334, 362}, /* AGG */
188 {0, 0, 0, 0, 52, 0, 101, 145, 187, 264, 330, 361, 390}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700189};
190
Daniel C Halperine3949d62009-09-17 10:43:50 -0700191static s32 expected_tpt_siso40MHz[4][IWL_RATE_COUNT] = {
192 {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */
193 {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800194 {0, 0, 0, 0, 94, 0, 177, 249, 313, 423, 512, 550, 586}, /* AGG */
195 {0, 0, 0, 0, 104, 0, 193, 270, 338, 454, 545, 584, 620}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700196};
197
Daniel C Halperine3949d62009-09-17 10:43:50 -0700198static s32 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = {
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800199 {0, 0, 0, 0, 74, 0, 123, 155, 179, 214, 236, 244, 251}, /* Norm */
200 {0, 0, 0, 0, 81, 0, 131, 164, 188, 223, 243, 251, 257}, /* SGI */
201 {0, 0, 0, 0, 89, 0, 167, 235, 296, 402, 488, 526, 560}, /* AGG */
202 {0, 0, 0, 0, 97, 0, 182, 255, 320, 431, 520, 558, 593}, /* AGG+SGI*/
Zhu Yib481de92007-09-25 17:54:57 -0700203};
204
Daniel C Halperine3949d62009-09-17 10:43:50 -0700205static s32 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = {
206 {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */
207 {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800208 {0, 0, 0, 0, 171, 0, 305, 410, 496, 634, 731, 771, 805}, /* AGG */
209 {0, 0, 0, 0, 186, 0, 329, 439, 527, 667, 764, 803, 838}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700210};
211
Daniel C Halperine3949d62009-09-17 10:43:50 -0700212static s32 expected_tpt_mimo3_20MHz[4][IWL_RATE_COUNT] = {
213 {0, 0, 0, 0, 99, 0, 153, 186, 208, 239, 256, 263, 268}, /* Norm */
214 {0, 0, 0, 0, 106, 0, 162, 194, 215, 246, 262, 268, 273}, /* SGI */
215 {0, 0, 0, 0, 134, 0, 249, 346, 431, 574, 685, 732, 775}, /* AGG */
216 {0, 0, 0, 0, 148, 0, 272, 376, 465, 614, 727, 775, 818}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700217};
218
Daniel C Halperine3949d62009-09-17 10:43:50 -0700219static s32 expected_tpt_mimo3_40MHz[4][IWL_RATE_COUNT] = {
220 {0, 0, 0, 0, 152, 0, 211, 239, 255, 279, 290, 294, 297}, /* Norm */
221 {0, 0, 0, 0, 160, 0, 219, 245, 261, 284, 294, 297, 300}, /* SGI */
222 {0, 0, 0, 0, 254, 0, 443, 584, 695, 868, 984, 1030, 1070}, /* AGG */
223 {0, 0, 0, 0, 277, 0, 478, 624, 737, 911, 1026, 1070, 1109}, /* AGG+SGI */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -0700224};
225
Wey-Yi Guy12b96812009-04-08 11:39:27 -0700226/* mbps, mcs */
Tobias Klauser79496732009-12-23 14:18:11 +0100227static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
Daniel C Halperine3949d62009-09-17 10:43:50 -0700228 { "1", "BPSK DSSS"},
229 { "2", "QPSK DSSS"},
230 {"5.5", "BPSK CCK"},
231 { "11", "QPSK CCK"},
232 { "6", "BPSK 1/2"},
233 { "9", "BPSK 1/2"},
234 { "12", "QPSK 1/2"},
235 { "18", "QPSK 3/4"},
236 { "24", "16QAM 1/2"},
237 { "36", "16QAM 3/4"},
238 { "48", "64QAM 2/3"},
239 { "54", "64QAM 3/4"},
240 { "60", "64QAM 5/6"},
Wey-Yi Guy12b96812009-04-08 11:39:27 -0700241};
242
Wey-Yi Guya9c146b2009-05-22 11:01:48 -0700243#define MCS_INDEX_PER_STREAM (8)
244
Tomas Winklere227cea2008-07-18 13:53:05 +0800245static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
Zhu Yib481de92007-09-25 17:54:57 -0700246{
247 window->data = 0;
248 window->success_counter = 0;
249 window->success_ratio = IWL_INVALID_VALUE;
250 window->counter = 0;
251 window->average_tpt = IWL_INVALID_VALUE;
252 window->stamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700253}
254
Guy Cohenaade00c2008-04-23 17:14:59 -0700255static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
256{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300257 return (ant_type & valid_antenna) == ant_type;
Guy Cohenaade00c2008-04-23 17:14:59 -0700258}
259
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200260/*
261 * removes the old data from the statistics. All data that is older than
262 * TID_MAX_TIME_DIFF, will be deleted.
263 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800264static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200265{
266 /* The oldest age we want to keep */
267 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
268
269 while (tl->queue_count &&
270 (tl->time_stamp < oldest_time)) {
271 tl->total -= tl->packet_count[tl->head];
272 tl->packet_count[tl->head] = 0;
273 tl->time_stamp += TID_QUEUE_CELL_SPACING;
274 tl->queue_count--;
275 tl->head++;
276 if (tl->head >= TID_QUEUE_MAX_SIZE)
277 tl->head = 0;
278 }
279}
280
281/*
282 * increment traffic load value for tid and also remove
283 * any old values if passed the certain time period
284 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800285static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data,
Ron Rindjunskyfaa29712008-06-12 09:46:58 +0800286 struct ieee80211_hdr *hdr)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200287{
288 u32 curr_time = jiffies_to_msecs(jiffies);
289 u32 time_diff;
290 s32 index;
Tomas Winklere227cea2008-07-18 13:53:05 +0800291 struct iwl_traffic_load *tl = NULL;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800292 u8 tid;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200293
Tomas Winkler417f1142008-11-12 13:14:06 -0800294 if (ieee80211_is_data_qos(hdr->frame_control)) {
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700295 u8 *qc = ieee80211_get_qos_ctl(hdr);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800296 tid = qc[0] & 0xf;
297 } else
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700298 return IWL_MAX_TID_COUNT;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200299
Johannes Berga8448552011-12-02 12:25:12 -0800300 if (unlikely(tid >= IWL_MAX_TID_COUNT))
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700301 return IWL_MAX_TID_COUNT;
Reinette Chatree6a6cf42009-08-13 13:30:50 -0700302
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200303 tl = &lq_data->load[tid];
304
305 curr_time -= curr_time % TID_ROUND_VALUE;
306
307 /* Happens only for the first packet. Initialize the data */
308 if (!(tl->queue_count)) {
309 tl->total = 1;
310 tl->time_stamp = curr_time;
311 tl->queue_count = 1;
312 tl->head = 0;
313 tl->packet_count[0] = 1;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700314 return IWL_MAX_TID_COUNT;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200315 }
316
317 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
318 index = time_diff / TID_QUEUE_CELL_SPACING;
319
320 /* The history is too long: remove data that is older than */
321 /* TID_MAX_TIME_DIFF */
322 if (index >= TID_QUEUE_MAX_SIZE)
323 rs_tl_rm_old_stats(tl, curr_time);
324
325 index = (tl->head + index) % TID_QUEUE_MAX_SIZE;
326 tl->packet_count[index] = tl->packet_count[index] + 1;
327 tl->total = tl->total + 1;
328
329 if ((index + 1) > tl->queue_count)
330 tl->queue_count = index + 1;
Ron Rindjunskyfaa29712008-06-12 09:46:58 +0800331
332 return tid;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200333}
334
Wey-Yi Guy54a430c2011-05-20 11:56:18 -0700335#ifdef CONFIG_MAC80211_DEBUGFS
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700336/**
337 * Program the device to use fixed rate for frame transmit
338 * This is for debugging/testing only
339 * once the device start use fixed rate, we need to reload the module
340 * to being back the normal operation.
341 */
Wey-Yi Guy64898542011-05-03 18:05:13 -0700342static void rs_program_fix_rate(struct iwl_priv *priv,
343 struct iwl_lq_sta *lq_sta)
344{
345 struct iwl_station_priv *sta_priv =
346 container_of(lq_sta, struct iwl_station_priv, lq_sta);
Johannes Bergc6892902011-09-20 15:37:21 -0700347 struct iwl_rxon_context *ctx = sta_priv->ctx;
Wey-Yi Guy64898542011-05-03 18:05:13 -0700348
349 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
350 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
351 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
352 lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
353
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -0800354#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700355 /* testmode has higher priority to overwirte the fixed rate */
356 if (priv->tm_fixed_rate)
357 lq_sta->dbg_fixed_rate = priv->tm_fixed_rate;
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -0700358#endif
Wey-Yi Guy64898542011-05-03 18:05:13 -0700359
360 IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700361 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700362
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700363 if (lq_sta->dbg_fixed_rate) {
364 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700365 iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
366 false);
367 }
368}
369#endif
370
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200371/*
372 get the traffic load value for tid
373*/
Tomas Winklere227cea2008-07-18 13:53:05 +0800374static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200375{
376 u32 curr_time = jiffies_to_msecs(jiffies);
377 u32 time_diff;
378 s32 index;
Tomas Winklere227cea2008-07-18 13:53:05 +0800379 struct iwl_traffic_load *tl = NULL;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200380
Johannes Berga8448552011-12-02 12:25:12 -0800381 if (tid >= IWL_MAX_TID_COUNT)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200382 return 0;
383
384 tl = &(lq_data->load[tid]);
385
386 curr_time -= curr_time % TID_ROUND_VALUE;
387
388 if (!(tl->queue_count))
389 return 0;
390
391 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
392 index = time_diff / TID_QUEUE_CELL_SPACING;
393
394 /* The history is too long: remove data that is older than */
395 /* TID_MAX_TIME_DIFF */
396 if (index >= TID_QUEUE_MAX_SIZE)
397 rs_tl_rm_old_stats(tl, curr_time);
398
399 return tl->total;
400}
401
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700402static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +0800403 struct iwl_lq_sta *lq_data, u8 tid,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200404 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200405{
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700406 int ret = -EAGAIN;
Johannes Berg290f5992010-08-23 07:56:58 -0700407 u32 load;
408
409 /*
410 * Don't create TX aggregation sessions when in high
411 * BT traffic, as they would just be disrupted by BT.
412 */
413 if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) {
414 IWL_ERR(priv, "BT traffic (%d), no aggregation allowed\n",
415 priv->bt_traffic_load);
416 return ret;
417 }
418
419 load = rs_tl_get_load(lq_data, tid);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800420
Johannes Berg65de7e82012-04-17 07:36:30 -0700421 if ((iwlwifi_mod_params.auto_agg) || (load > IWL_AGG_LOAD_THRESHOLD)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800422 IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n",
Johannes Berge1749612008-10-27 15:59:26 -0700423 sta->addr, tid);
Sujith Manoharanbd2ce6e2010-12-15 07:47:10 +0530424 ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800425 if (ret == -EAGAIN) {
426 /*
427 * driver and mac80211 is out of sync
428 * this might be cause by reloading firmware
429 * stop the tx ba session here
430 */
Andy Lutomirski24110542010-07-25 13:14:29 -0400431 IWL_ERR(priv, "Fail start Tx agg on tid: %d\n",
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800432 tid);
Johannes Berg6a8579d2010-05-27 14:41:07 +0200433 ieee80211_stop_tx_ba_session(sta, tid);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800434 }
Andy Lutomirski24110542010-07-25 13:14:29 -0400435 } else {
Wey-Yi Guy5f88ac22011-05-27 08:40:31 -0700436 IWL_DEBUG_HT(priv, "Aggregation not enabled for tid %d "
Andy Lutomirski24110542010-07-25 13:14:29 -0400437 "because load = %u\n", tid, load);
438 }
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700439 return ret;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200440}
441
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700442static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
Tomas Winklere227cea2008-07-18 13:53:05 +0800443 struct iwl_lq_sta *lq_data,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200444 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200445{
Johannes Berga8448552011-12-02 12:25:12 -0800446 if (tid < IWL_MAX_TID_COUNT)
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -0700447 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
448 else
Johannes Berga8448552011-12-02 12:25:12 -0800449 IWL_ERR(priv, "tid exceeds max TID count: %d/%d\n",
450 tid, IWL_MAX_TID_COUNT);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200451}
452
Guy Cohen39e88502008-04-23 17:14:57 -0700453static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
Guy Cohenfde0db32008-04-21 15:42:01 -0700454{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300455 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
456 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
457 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
Guy Cohenfde0db32008-04-21 15:42:01 -0700458}
459
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700460/*
461 * Static function to get the expected throughput from an iwl_scale_tbl_info
462 * that wraps a NULL pointer check
463 */
464static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index)
465{
466 if (tbl->expected_tpt)
467 return tbl->expected_tpt[rs_index];
468 return 0;
469}
470
Ben Cahill77626352007-11-29 11:09:44 +0800471/**
472 * rs_collect_tx_data - Update the success/failure sliding window
473 *
474 * We keep a sliding window of the last 62 packets transmitted
475 * at this rate. window->data contains the bitmask of successful
476 * packets.
477 */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700478static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl,
479 int scale_index, int attempts, int successes)
Zhu Yib481de92007-09-25 17:54:57 -0700480{
Tomas Winklere227cea2008-07-18 13:53:05 +0800481 struct iwl_rate_scale_data *window = NULL;
Guy Cohen39e88502008-04-23 17:14:57 -0700482 static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700483 s32 fail_count, tpt;
Zhu Yib481de92007-09-25 17:54:57 -0700484
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800485 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
486 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700487
Daniel C Halperine3949d62009-09-17 10:43:50 -0700488 /* Select window for current tx bit rate */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700489 window = &(tbl->win[scale_index]);
490
491 /* Get expected throughput */
492 tpt = get_expected_tpt(tbl, scale_index);
Zhu Yib481de92007-09-25 17:54:57 -0700493
Ben Cahill77626352007-11-29 11:09:44 +0800494 /*
495 * Keep track of only the latest 62 tx frame attempts in this rate's
496 * history window; anything older isn't really relevant any more.
497 * If we have filled up the sliding window, drop the oldest attempt;
498 * if the oldest attempt (highest bit in bitmap) shows "success",
499 * subtract "1" from the success counter (this is the main reason
500 * we keep these bitmaps!).
501 */
Daniel C Halperine3949d62009-09-17 10:43:50 -0700502 while (attempts > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700503 if (window->counter >= IWL_RATE_MAX_WINDOW) {
504
505 /* remove earliest */
506 window->counter = IWL_RATE_MAX_WINDOW - 1;
507
Ron Rindjunsky99556432008-01-28 14:07:25 +0200508 if (window->data & mask) {
509 window->data &= ~mask;
Guy Cohen39e88502008-04-23 17:14:57 -0700510 window->success_counter--;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200511 }
Zhu Yib481de92007-09-25 17:54:57 -0700512 }
Zhu Yib481de92007-09-25 17:54:57 -0700513
Ron Rindjunsky99556432008-01-28 14:07:25 +0200514 /* Increment frames-attempted counter */
515 window->counter++;
Ben Cahill77626352007-11-29 11:09:44 +0800516
Daniel C Halperine3949d62009-09-17 10:43:50 -0700517 /* Shift bitmap by one frame to throw away oldest history */
Guy Cohen90d77952008-09-09 10:54:53 +0800518 window->data <<= 1;
Daniel C Halperine3949d62009-09-17 10:43:50 -0700519
520 /* Mark the most recent #successes attempts as successful */
Ron Rindjunsky99556432008-01-28 14:07:25 +0200521 if (successes > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700522 window->success_counter++;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200523 window->data |= 0x1;
524 successes--;
525 }
526
Daniel C Halperine3949d62009-09-17 10:43:50 -0700527 attempts--;
Zhu Yib481de92007-09-25 17:54:57 -0700528 }
529
Ben Cahill77626352007-11-29 11:09:44 +0800530 /* Calculate current success ratio, avoid divide-by-0! */
Zhu Yib481de92007-09-25 17:54:57 -0700531 if (window->counter > 0)
532 window->success_ratio = 128 * (100 * window->success_counter)
533 / window->counter;
534 else
535 window->success_ratio = IWL_INVALID_VALUE;
536
537 fail_count = window->counter - window->success_counter;
538
Ben Cahill77626352007-11-29 11:09:44 +0800539 /* Calculate average throughput, if we have enough history. */
Zhu Yib481de92007-09-25 17:54:57 -0700540 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
541 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
542 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
543 else
544 window->average_tpt = IWL_INVALID_VALUE;
545
Ben Cahill77626352007-11-29 11:09:44 +0800546 /* Tag this window as having been updated */
Zhu Yib481de92007-09-25 17:54:57 -0700547 window->stamp = jiffies;
548
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800549 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700550}
551
Ben Cahill77626352007-11-29 11:09:44 +0800552/*
553 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
554 */
Guy Cohen39e88502008-04-23 17:14:57 -0700555/* FIXME:RS:remove this function and put the flags statically in the table */
Tomas Winkler978785a2008-12-19 10:37:31 +0800556static u32 rate_n_flags_from_tbl(struct iwl_priv *priv,
557 struct iwl_scale_tbl_info *tbl,
558 int index, u8 use_green)
Zhu Yib481de92007-09-25 17:54:57 -0700559{
Guy Cohen39e88502008-04-23 17:14:57 -0700560 u32 rate_n_flags = 0;
561
Zhu Yib481de92007-09-25 17:54:57 -0700562 if (is_legacy(tbl->lq_type)) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800563 rate_n_flags = iwl_rates[index].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700564 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -0700565 rate_n_flags |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700566
Guy Cohenfde0db32008-04-21 15:42:01 -0700567 } else if (is_Ht(tbl->lq_type)) {
568 if (index > IWL_LAST_OFDM_RATE) {
Tomas Winkler978785a2008-12-19 10:37:31 +0800569 IWL_ERR(priv, "Invalid HT rate index %d\n", index);
Zhu Yib481de92007-09-25 17:54:57 -0700570 index = IWL_LAST_OFDM_RATE;
Guy Cohenfde0db32008-04-21 15:42:01 -0700571 }
Guy Cohen39e88502008-04-23 17:14:57 -0700572 rate_n_flags = RATE_MCS_HT_MSK;
Guy Cohenfde0db32008-04-21 15:42:01 -0700573
574 if (is_siso(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800575 rate_n_flags |= iwl_rates[index].plcp_siso;
Guy Cohenfde0db32008-04-21 15:42:01 -0700576 else if (is_mimo2(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800577 rate_n_flags |= iwl_rates[index].plcp_mimo2;
Guy Cohenfde0db32008-04-21 15:42:01 -0700578 else
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800579 rate_n_flags |= iwl_rates[index].plcp_mimo3;
Zhu Yib481de92007-09-25 17:54:57 -0700580 } else {
Tomas Winkler978785a2008-12-19 10:37:31 +0800581 IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700582 }
583
Guy Cohen39e88502008-04-23 17:14:57 -0700584 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
Guy Cohenfde0db32008-04-21 15:42:01 -0700585 RATE_MCS_ANT_ABC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700586
Guy Cohen39e88502008-04-23 17:14:57 -0700587 if (is_Ht(tbl->lq_type)) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700588 if (tbl->is_ht40) {
Guy Cohen39e88502008-04-23 17:14:57 -0700589 if (tbl->is_dup)
590 rate_n_flags |= RATE_MCS_DUP_MSK;
591 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700592 rate_n_flags |= RATE_MCS_HT40_MSK;
Guy Cohen39e88502008-04-23 17:14:57 -0700593 }
594 if (tbl->is_SGI)
595 rate_n_flags |= RATE_MCS_SGI_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700596
Guy Cohen39e88502008-04-23 17:14:57 -0700597 if (use_green) {
598 rate_n_flags |= RATE_MCS_GF_MSK;
599 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
600 rate_n_flags &= ~RATE_MCS_SGI_MSK;
Tomas Winkler978785a2008-12-19 10:37:31 +0800601 IWL_ERR(priv, "GF was set with SGI:SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -0700602 }
603 }
Zhu Yib481de92007-09-25 17:54:57 -0700604 }
Guy Cohen39e88502008-04-23 17:14:57 -0700605 return rate_n_flags;
Zhu Yib481de92007-09-25 17:54:57 -0700606}
607
Ben Cahill77626352007-11-29 11:09:44 +0800608/*
609 * Interpret uCode API's rate_n_flags format,
610 * fill "search" or "active" tx mode table.
611 */
Guy Cohen39e88502008-04-23 17:14:57 -0700612static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
Johannes Berg8318d782008-01-24 19:38:38 +0100613 enum ieee80211_band band,
Tomas Winklere227cea2008-07-18 13:53:05 +0800614 struct iwl_scale_tbl_info *tbl,
Zhu Yib481de92007-09-25 17:54:57 -0700615 int *rate_idx)
616{
Guy Cohen39e88502008-04-23 17:14:57 -0700617 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
618 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
619 u8 mcs;
Zhu Yib481de92007-09-25 17:54:57 -0700620
Wey-Yi Guy80e91582010-08-03 08:23:32 -0700621 memset(tbl, 0, sizeof(struct iwl_scale_tbl_info));
Tomas Winklere7d326ac2008-06-12 09:47:11 +0800622 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700623
Guy Cohenfde0db32008-04-21 15:42:01 -0700624 if (*rate_idx == IWL_RATE_INVALID) {
Zhu Yib481de92007-09-25 17:54:57 -0700625 *rate_idx = -1;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800626 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700627 }
Ben Cahill77626352007-11-29 11:09:44 +0800628 tbl->is_SGI = 0; /* default legacy setup */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700629 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700630 tbl->is_dup = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -0700631 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
632 tbl->lq_type = LQ_NONE;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700633 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700634
Ben Cahill77626352007-11-29 11:09:44 +0800635 /* legacy rate format */
Guy Cohen39e88502008-04-23 17:14:57 -0700636 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700637 if (num_of_ant == 1) {
Johannes Berg8318d782008-01-24 19:38:38 +0100638 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700639 tbl->lq_type = LQ_A;
640 else
641 tbl->lq_type = LQ_G;
Zhu Yib481de92007-09-25 17:54:57 -0700642 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700643 /* HT rate format */
Zhu Yib481de92007-09-25 17:54:57 -0700644 } else {
Guy Cohen39e88502008-04-23 17:14:57 -0700645 if (rate_n_flags & RATE_MCS_SGI_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700646 tbl->is_SGI = 1;
647
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700648 if ((rate_n_flags & RATE_MCS_HT40_MSK) ||
Guy Cohen39e88502008-04-23 17:14:57 -0700649 (rate_n_flags & RATE_MCS_DUP_MSK))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700650 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700651
Guy Cohen39e88502008-04-23 17:14:57 -0700652 if (rate_n_flags & RATE_MCS_DUP_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700653 tbl->is_dup = 1;
Guy Cohenfde0db32008-04-21 15:42:01 -0700654
Guy Cohen39e88502008-04-23 17:14:57 -0700655 mcs = rs_extract_rate(rate_n_flags);
Guy Cohenfde0db32008-04-21 15:42:01 -0700656
Guy Cohen39e88502008-04-23 17:14:57 -0700657 /* SISO */
658 if (mcs <= IWL_RATE_SISO_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700659 if (num_of_ant == 1)
660 tbl->lq_type = LQ_SISO; /*else NONE*/
661 /* MIMO2 */
Guy Cohen39e88502008-04-23 17:14:57 -0700662 } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700663 if (num_of_ant == 2)
664 tbl->lq_type = LQ_MIMO2;
665 /* MIMO3 */
666 } else {
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700667 if (num_of_ant == 3) {
668 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Guy Cohenfde0db32008-04-21 15:42:01 -0700669 tbl->lq_type = LQ_MIMO3;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700670 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700671 }
Zhu Yib481de92007-09-25 17:54:57 -0700672 }
673 return 0;
674}
Guy Cohenaade00c2008-04-23 17:14:59 -0700675
676/* switch to another antenna/antennas and return 1 */
677/* if no other valid antenna found, return 0 */
678static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
Tomas Winklere227cea2008-07-18 13:53:05 +0800679 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -0700680{
Guy Cohenaade00c2008-04-23 17:14:59 -0700681 u8 new_ant_type;
682
683 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
684 return 0;
685
686 if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
687 return 0;
688
689 new_ant_type = ant_toggle_lookup[tbl->ant_type];
690
691 while ((new_ant_type != tbl->ant_type) &&
692 !rs_is_valid_ant(valid_ant, new_ant_type))
693 new_ant_type = ant_toggle_lookup[new_ant_type];
694
695 if (new_ant_type == tbl->ant_type)
696 return 0;
697
698 tbl->ant_type = new_ant_type;
699 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
700 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
701 return 1;
Zhu Yib481de92007-09-25 17:54:57 -0700702}
703
Daniel C Halperinb2617932009-08-13 13:30:59 -0700704/**
705 * Green-field mode is valid if the station supports it and
706 * there are no non-GF stations present in the BSS.
707 */
Johannes Berg7e6a5882010-08-23 10:46:46 +0200708static bool rs_use_green(struct ieee80211_sta *sta)
Zhu Yib481de92007-09-25 17:54:57 -0700709{
Johannes Berg50e2a302012-08-05 18:31:46 +0200710 /*
711 * There's a bug somewhere in this code that causes the
712 * scaling to get stuck because GF+SGI can't be combined
713 * in SISO rates. Until we find that bug, disable GF, it
714 * has only limited benefit and we still interoperate with
715 * GF APs since we can always receive GF transmissions.
716 */
717 return false;
Guy Cohenf935a6d2008-04-23 17:15:02 -0700718}
Zhu Yib481de92007-09-25 17:54:57 -0700719
720/**
721 * rs_get_supported_rates - get the available rates
722 *
723 * if management frame or broadcast frame only return
724 * basic available rates.
725 *
726 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800727static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
728 struct ieee80211_hdr *hdr,
729 enum iwl_table_type rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Guy Coheneecd6e52008-04-23 17:14:58 -0700731 if (is_legacy(rate_type)) {
732 return lq_sta->active_legacy_rate;
733 } else {
734 if (is_siso(rate_type))
735 return lq_sta->active_siso_rate;
736 else if (is_mimo2(rate_type))
737 return lq_sta->active_mimo2_rate;
738 else
739 return lq_sta->active_mimo3_rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800740 }
Zhu Yib481de92007-09-25 17:54:57 -0700741}
742
Ester Kummerbf403db2008-05-05 10:22:40 +0800743static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
744 int rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700745{
746 u8 high = IWL_RATE_INVALID;
747 u8 low = IWL_RATE_INVALID;
748
Ian Schram01ebd062007-10-25 17:15:22 +0800749 /* 802.11A or ht walks to the next literal adjacent rate in
Zhu Yib481de92007-09-25 17:54:57 -0700750 * the rate table */
751 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
752 int i;
753 u32 mask;
754
755 /* Find the previous rate that is in the rate mask */
756 i = index - 1;
757 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
758 if (rate_mask & mask) {
759 low = i;
760 break;
761 }
762 }
763
764 /* Find the next rate that is in the rate mask */
765 i = index + 1;
766 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
767 if (rate_mask & mask) {
768 high = i;
769 break;
770 }
771 }
772
773 return (high << 8) | low;
774 }
775
776 low = index;
777 while (low != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800778 low = iwl_rates[low].prev_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700779 if (low == IWL_RATE_INVALID)
780 break;
781 if (rate_mask & (1 << low))
782 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800783 IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low);
Zhu Yib481de92007-09-25 17:54:57 -0700784 }
785
786 high = index;
787 while (high != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800788 high = iwl_rates[high].next_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700789 if (high == IWL_RATE_INVALID)
790 break;
791 if (rate_mask & (1 << high))
792 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800793 IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high);
Zhu Yib481de92007-09-25 17:54:57 -0700794 }
795
796 return (high << 8) | low;
797}
798
Tomas Winklere227cea2008-07-18 13:53:05 +0800799static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
800 struct iwl_scale_tbl_info *tbl,
801 u8 scale_index, u8 ht_possible)
Zhu Yib481de92007-09-25 17:54:57 -0700802{
Zhu Yib481de92007-09-25 17:54:57 -0700803 s32 low;
804 u16 rate_mask;
805 u16 high_low;
806 u8 switch_to_legacy = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800807 u8 is_green = lq_sta->is_green;
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700808 struct iwl_priv *priv = lq_sta->drv;
Zhu Yib481de92007-09-25 17:54:57 -0700809
810 /* check if we need to switch from HT to legacy rates.
811 * assumption is that mandatory rates (1Mbps or 6Mbps)
812 * are always supported (spec demand) */
813 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
814 switch_to_legacy = 1;
815 scale_index = rs_ht_to_legacy[scale_index];
Johannes Berg8318d782008-01-24 19:38:38 +0100816 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700817 tbl->lq_type = LQ_A;
818 else
819 tbl->lq_type = LQ_G;
820
Guy Cohen69fdb302008-04-23 17:15:01 -0700821 if (num_of_ant(tbl->ant_type) > 1)
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700822 tbl->ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200823 first_antenna(priv->nvm_data->valid_tx_ant);
Zhu Yib481de92007-09-25 17:54:57 -0700824
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700825 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700826 tbl->is_SGI = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700827 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700828 }
829
Guy Coheneecd6e52008-04-23 17:14:58 -0700830 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700831
Ben Cahill77626352007-11-29 11:09:44 +0800832 /* Mask with station rate restriction */
Zhu Yib481de92007-09-25 17:54:57 -0700833 if (is_legacy(tbl->lq_type)) {
Ben Cahill77626352007-11-29 11:09:44 +0800834 /* supp_rates has no CCK bits in A mode */
Johannes Berg8318d782008-01-24 19:38:38 +0100835 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700836 rate_mask = (u16)(rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -0800837 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -0700838 else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800839 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -0700840 }
841
Ben Cahill77626352007-11-29 11:09:44 +0800842 /* If we switched from HT to legacy, check current rate */
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800843 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
Guy Cohen39e88502008-04-23 17:14:57 -0700844 low = scale_index;
845 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700846 }
847
Ester Kummerbf403db2008-05-05 10:22:40 +0800848 high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
849 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700850 low = high_low & 0xff;
851
Guy Cohen39e88502008-04-23 17:14:57 -0700852 if (low == IWL_RATE_INVALID)
853 low = scale_index;
854
855out:
Tomas Winkler978785a2008-12-19 10:37:31 +0800856 return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
Zhu Yib481de92007-09-25 17:54:57 -0700857}
858
Ben Cahill77626352007-11-29 11:09:44 +0800859/*
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700860 * Simple function to compare two rate scale table types
861 */
862static bool table_type_matches(struct iwl_scale_tbl_info *a,
863 struct iwl_scale_tbl_info *b)
864{
865 return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) &&
866 (a->is_SGI == b->is_SGI);
867}
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700868
Johannes Berg7e6a5882010-08-23 10:46:46 +0200869static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
870 struct iwl_lq_sta *lq_sta)
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700871{
872 struct iwl_scale_tbl_info *tbl;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800873 bool full_concurrent = priv->bt_full_concurrent;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700874
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800875 if (priv->bt_ant_couple_ok) {
876 /*
877 * Is there a need to switch between
878 * full concurrency and 3-wire?
879 */
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800880 if (priv->bt_ci_compliance && priv->bt_ant_couple_ok)
881 full_concurrent = true;
882 else
883 full_concurrent = false;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800884 }
885 if ((priv->bt_traffic_load != priv->last_bt_traffic_load) ||
886 (priv->bt_full_concurrent != full_concurrent)) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700887 priv->bt_full_concurrent = full_concurrent;
Meenakshi Venkataraman882dde82012-05-16 22:35:57 +0200888 priv->last_bt_traffic_load = priv->bt_traffic_load;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700889
890 /* Update uCode's rate table. */
891 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
892 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +0200893 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700894
Johannes Berg1ee158d2012-02-17 10:07:44 -0800895 queue_work(priv->workqueue, &priv->bt_full_concurrency);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700896 }
897}
898
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700899/*
Ben Cahill77626352007-11-29 11:09:44 +0800900 * mac80211 sends us Tx status
901 */
Johannes Berg4b7679a2008-09-18 18:14:18 +0200902static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
903 struct ieee80211_sta *sta, void *priv_sta,
Johannes Berge039fa42008-05-15 12:55:29 +0200904 struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700905{
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700906 int legacy_success;
907 int retries;
908 int rs_index, mac_index, i;
Tomas Winkler417f1142008-11-12 13:14:06 -0800909 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winkler66c73db2008-04-15 16:01:40 -0700910 struct iwl_link_quality_cmd *table;
Zhu Yib481de92007-09-25 17:54:57 -0700911 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200912 struct iwl_op_mode *op_mode = (struct iwl_op_mode *)priv_r;
913 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge039fa42008-05-15 12:55:29 +0200914 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel C Halperin50273092009-08-28 09:44:45 -0700915 enum mac80211_rate_control_flags mac_flags;
Guy Cohen39e88502008-04-23 17:14:57 -0700916 u32 tx_rate;
Tomas Winklere227cea2008-07-18 13:53:05 +0800917 struct iwl_scale_tbl_info tbl_type;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700918 struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200919 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -0700920 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -0700921
Tomas Winklere1623442009-01-27 14:27:56 -0800922 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -0700923
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800924 /* Treat uninitialized rate scaling data same as non-existing. */
925 if (!lq_sta) {
926 IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n");
927 return;
928 } else if (!lq_sta->drv) {
929 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
930 return;
931 }
932
Tomas Winkler417f1142008-11-12 13:14:06 -0800933 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +0200934 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -0700935 return;
936
Daniel C Halperine3949d62009-09-17 10:43:50 -0700937 /* This packet was aggregated but doesn't carry status info */
Johannes Berge039fa42008-05-15 12:55:29 +0200938 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
939 !(info->flags & IEEE80211_TX_STAT_AMPDU))
Ron Rindjunsky99556432008-01-28 14:07:25 +0200940 return;
941
Ben Cahill77626352007-11-29 11:09:44 +0800942 /*
943 * Ignore this Tx frame response if its initial rate doesn't match
944 * that of latest Link Quality command. There may be stragglers
945 * from a previous Link Quality command, but we're no longer interested
946 * in those; they're either from the "active" mode while we're trying
947 * to check "search" mode, or a prior "search" mode after we've moved
948 * to a new "search" mode (which might become the new "active" mode).
949 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700950 table = &lq_sta->lq;
Guy Cohen39e88502008-04-23 17:14:57 -0700951 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
952 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800953 if (priv->band == IEEE80211_BAND_5GHZ)
954 rs_index -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin50273092009-08-28 09:44:45 -0700955 mac_flags = info->status.rates[0].flags;
956 mac_index = info->status.rates[0].idx;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700957 /* For HT packets, map MCS to PLCP */
958 if (mac_flags & IEEE80211_TX_RC_MCS) {
959 mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */
960 if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
961 mac_index++;
Daniel C Halperin392a0ba2009-09-11 10:38:08 -0700962 /*
963 * mac80211 HT index is always zero-indexed; we need to move
964 * HT OFDM rates after CCK rates in 2.4 GHz band
965 */
966 if (priv->band == IEEE80211_BAND_2GHZ)
967 mac_index += IWL_FIRST_OFDM_RATE;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700968 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700969 /* Here we actually compare this rate to the latest LQ command */
Daniel C Halperin50273092009-08-28 09:44:45 -0700970 if ((mac_index < 0) ||
971 (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
972 (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
973 (tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) ||
Johannes Bergd748b462012-03-28 11:04:23 +0200974 (tbl_type.ant_type != info->status.antenna) ||
Daniel C Halperin50273092009-08-28 09:44:45 -0700975 (!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
976 (!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
Daniel C Halperin31513be2009-08-28 09:44:47 -0700977 (rs_index != mac_index)) {
978 IWL_DEBUG_RATE(priv, "initial rate %d does not match %d (0x%x)\n", mac_index, rs_index, tx_rate);
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700979 /*
980 * Since rates mis-match, the last LQ command may have failed.
981 * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with
982 * ... driver.
Mohamed Abbasd5e49032008-12-12 08:22:15 -0800983 */
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800984 lq_sta->missed_rate_counter++;
985 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
986 lq_sta->missed_rate_counter = 0;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200987 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800988 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700989 /* Regardless, ignore this status info for outdated rate */
990 return;
991 } else
992 /* Rate did match, so reset the missed_rate_counter */
993 lq_sta->missed_rate_counter = 0;
994
995 /* Figure out if rate scale algorithm is in active or search table */
996 if (table_type_matches(&tbl_type,
997 &(lq_sta->lq_info[lq_sta->active_tbl]))) {
998 curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
999 other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1000 } else if (table_type_matches(&tbl_type,
1001 &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
1002 curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1003 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1004 } else {
1005 IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n");
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001006 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1007 IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n",
1008 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
1009 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1010 IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n",
1011 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
1012 IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n",
1013 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
1014 /*
1015 * no matching table found, let's by-pass the data collection
1016 * and continue to perform rate scale to find the rate table
1017 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001018 rs_stay_in_table(lq_sta, true);
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001019 goto done;
Zhu Yib481de92007-09-25 17:54:57 -07001020 }
Zhu Yib481de92007-09-25 17:54:57 -07001021
Ben Cahill77626352007-11-29 11:09:44 +08001022 /*
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001023 * Updating the frame history depends on whether packets were
1024 * aggregated.
1025 *
1026 * For aggregation, all packets were transmitted at the same rate, the
1027 * first index into rate scale table.
Ben Cahill77626352007-11-29 11:09:44 +08001028 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001029 if (info->flags & IEEE80211_TX_STAT_AMPDU) {
1030 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
1031 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type,
1032 &rs_index);
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001033 rs_collect_tx_data(curr_tbl, rs_index,
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001034 info->status.ampdu_len,
1035 info->status.ampdu_ack_len);
Zhu Yib481de92007-09-25 17:54:57 -07001036
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001037 /* Update success/fail counts if not searching for new mode */
1038 if (lq_sta->stay_in_tbl) {
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001039 lq_sta->total_success += info->status.ampdu_ack_len;
1040 lq_sta->total_failed += (info->status.ampdu_len -
1041 info->status.ampdu_ack_len);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001042 }
1043 } else {
1044 /*
1045 * For legacy, update frame history with for each Tx retry.
1046 */
1047 retries = info->status.rates[0].count - 1;
1048 /* HW doesn't send more than 15 retries */
1049 retries = min(retries, 15);
1050
1051 /* The last transmission may have been successful */
1052 legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
1053 /* Collect data for each rate used during failed TX attempts */
1054 for (i = 0; i <= retries; ++i) {
1055 tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
1056 rs_get_tbl_info_from_mcs(tx_rate, priv->band,
1057 &tbl_type, &rs_index);
1058 /*
1059 * Only collect stats if retried rate is in the same RS
1060 * table as active/search.
1061 */
1062 if (table_type_matches(&tbl_type, curr_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001063 tmp_tbl = curr_tbl;
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001064 else if (table_type_matches(&tbl_type, other_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001065 tmp_tbl = other_tbl;
Ron Rindjunsky99556432008-01-28 14:07:25 +02001066 else
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001067 continue;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001068 rs_collect_tx_data(tmp_tbl, rs_index, 1,
1069 i < retries ? 0 : legacy_success);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001070 }
1071
1072 /* Update success/fail counts if not searching for new mode */
1073 if (lq_sta->stay_in_tbl) {
1074 lq_sta->total_success += legacy_success;
1075 lq_sta->total_failed += retries + (1 - legacy_success);
Ron Rindjunsky99556432008-01-28 14:07:25 +02001076 }
Zhu Yib481de92007-09-25 17:54:57 -07001077 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001078 /* The last TX rate is cached in lq_sta; it's set in if/else above */
1079 lq_sta->last_rate_n_flags = tx_rate;
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001080done:
Ben Cahill77626352007-11-29 11:09:44 +08001081 /* See if there's a better rate or modulation mode to try. */
Abbas, Mohamedc338ba32009-01-21 10:58:02 -08001082 if (sta && sta->supp_rates[sband->band])
Gábor Stefanik514d65c2009-04-23 19:36:08 +02001083 rs_rate_scale_perform(priv, skb, sta, lq_sta);
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -07001084
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -08001085#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_IWLWIFI_DEVICE_TESTMODE)
Wey-Yi Guy4e308112011-07-08 08:46:28 -07001086 if ((priv->tm_fixed_rate) &&
1087 (priv->tm_fixed_rate != lq_sta->dbg_fixed_rate))
Wey-Yi Guy64898542011-05-03 18:05:13 -07001088 rs_program_fix_rate(priv, lq_sta);
1089#endif
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001090 if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist)
Johannes Berg7e6a5882010-08-23 10:46:46 +02001091 rs_bt_update_lq(priv, ctx, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001092}
1093
Ben Cahill77626352007-11-29 11:09:44 +08001094/*
1095 * Begin a period of staying with a selected modulation mode.
1096 * Set "stay_in_tbl" flag to prevent any mode switches.
1097 * Set frame tx success limits according to legacy vs. high-throughput,
1098 * and reset overall (spanning all rates) tx success history statistics.
1099 * These control how long we stay using same modulation mode before
1100 * searching for a new mode.
1101 */
Ester Kummerbf403db2008-05-05 10:22:40 +08001102static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
Tomas Winklere227cea2008-07-18 13:53:05 +08001103 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07001104{
Tomas Winklere1623442009-01-27 14:27:56 -08001105 IWL_DEBUG_RATE(priv, "we are staying in the same table\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -08001106 lq_sta->stay_in_tbl = 1; /* only place this gets set */
Zhu Yib481de92007-09-25 17:54:57 -07001107 if (is_legacy) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001108 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
1109 lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
1110 lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001111 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001112 lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
1113 lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
1114 lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001115 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001116 lq_sta->table_count = 0;
1117 lq_sta->total_failed = 0;
1118 lq_sta->total_success = 0;
Mohamed Abbas447fee72009-04-20 14:37:02 -07001119 lq_sta->flush_timer = jiffies;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001120 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001121}
1122
Ben Cahill77626352007-11-29 11:09:44 +08001123/*
1124 * Find correct throughput table for given mode of modulation
1125 */
Tomas Winklere227cea2008-07-18 13:53:05 +08001126static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1127 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -07001128{
Daniel C Halperine3949d62009-09-17 10:43:50 -07001129 /* Used to choose among HT tables */
1130 s32 (*ht_tbl_pointer)[IWL_RATE_COUNT];
1131
1132 /* Check for invalid LQ type */
1133 if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
1134 tbl->expected_tpt = expected_tpt_legacy;
1135 return;
1136 }
1137
1138 /* Legacy rates have only one table */
Zhu Yib481de92007-09-25 17:54:57 -07001139 if (is_legacy(tbl->lq_type)) {
Daniel C Halperine3949d62009-09-17 10:43:50 -07001140 tbl->expected_tpt = expected_tpt_legacy;
1141 return;
1142 }
1143
1144 /* Choose among many HT tables depending on number of streams
1145 * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation
1146 * status */
1147 if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1148 ht_tbl_pointer = expected_tpt_siso20MHz;
1149 else if (is_siso(tbl->lq_type))
1150 ht_tbl_pointer = expected_tpt_siso40MHz;
1151 else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1152 ht_tbl_pointer = expected_tpt_mimo2_20MHz;
1153 else if (is_mimo2(tbl->lq_type))
1154 ht_tbl_pointer = expected_tpt_mimo2_40MHz;
1155 else if (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1156 ht_tbl_pointer = expected_tpt_mimo3_20MHz;
1157 else /* if (is_mimo3(tbl->lq_type)) <-- must be true */
1158 ht_tbl_pointer = expected_tpt_mimo3_40MHz;
1159
1160 if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
1161 tbl->expected_tpt = ht_tbl_pointer[0];
1162 else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
1163 tbl->expected_tpt = ht_tbl_pointer[1];
1164 else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
1165 tbl->expected_tpt = ht_tbl_pointer[2];
1166 else /* AGG+SGI */
1167 tbl->expected_tpt = ht_tbl_pointer[3];
Zhu Yib481de92007-09-25 17:54:57 -07001168}
1169
Ben Cahill77626352007-11-29 11:09:44 +08001170/*
1171 * Find starting rate for new "search" high-throughput mode of modulation.
1172 * Goal is to find lowest expected rate (under perfect conditions) that is
1173 * above the current measured throughput of "active" mode, to give new mode
1174 * a fair chance to prove itself without too many challenges.
1175 *
1176 * This gets called when transitioning to more aggressive modulation
1177 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1178 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1179 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1180 * bit rate will typically need to increase, but not if performance was bad.
1181 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001182static s32 rs_get_best_rate(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001183 struct iwl_lq_sta *lq_sta,
1184 struct iwl_scale_tbl_info *tbl, /* "search" */
Guy Cohenf935a6d2008-04-23 17:15:02 -07001185 u16 rate_mask, s8 index)
Zhu Yib481de92007-09-25 17:54:57 -07001186{
Ben Cahill77626352007-11-29 11:09:44 +08001187 /* "active" values */
Tomas Winklere227cea2008-07-18 13:53:05 +08001188 struct iwl_scale_tbl_info *active_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001189 &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001190 s32 active_sr = active_tbl->win[index].success_ratio;
Zhu Yib481de92007-09-25 17:54:57 -07001191 s32 active_tpt = active_tbl->expected_tpt[index];
Ben Cahill77626352007-11-29 11:09:44 +08001192
1193 /* expected "search" throughput */
1194 s32 *tpt_tbl = tbl->expected_tpt;
1195
1196 s32 new_rate, high, low, start_hi;
Zhu Yib481de92007-09-25 17:54:57 -07001197 u16 high_low;
Guy Cohenf935a6d2008-04-23 17:15:02 -07001198 s8 rate = index;
Zhu Yib481de92007-09-25 17:54:57 -07001199
1200 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1201
1202 for (; ;) {
Ester Kummerbf403db2008-05-05 10:22:40 +08001203 high_low = rs_get_adjacent_rate(priv, rate, rate_mask,
1204 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07001205
1206 low = high_low & 0xff;
1207 high = (high_low >> 8) & 0xff;
1208
Ben Cahill77626352007-11-29 11:09:44 +08001209 /*
1210 * Lower the "search" bit rate, to give new "search" mode
1211 * approximately the same throughput as "active" if:
1212 *
1213 * 1) "Active" mode has been working modestly well (but not
1214 * great), and expected "search" throughput (under perfect
1215 * conditions) at candidate rate is above the actual
1216 * measured "active" throughput (but less than expected
1217 * "active" throughput under perfect conditions).
1218 * OR
1219 * 2) "Active" mode has been working perfectly or very well
1220 * and expected "search" throughput (under perfect
1221 * conditions) at candidate rate is above expected
1222 * "active" throughput (under perfect conditions).
1223 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001224 if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
Zhu Yib481de92007-09-25 17:54:57 -07001225 ((active_sr > IWL_RATE_DECREASE_TH) &&
1226 (active_sr <= IWL_RATE_HIGH_TH) &&
1227 (tpt_tbl[rate] <= active_tpt))) ||
1228 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
1229 (tpt_tbl[rate] > active_tpt))) {
1230
Ben Cahill77626352007-11-29 11:09:44 +08001231 /* (2nd or later pass)
1232 * If we've already tried to raise the rate, and are
1233 * now trying to lower it, use the higher rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001234 if (start_hi != IWL_RATE_INVALID) {
1235 new_rate = start_hi;
1236 break;
1237 }
Ben Cahill77626352007-11-29 11:09:44 +08001238
Zhu Yib481de92007-09-25 17:54:57 -07001239 new_rate = rate;
Ben Cahill77626352007-11-29 11:09:44 +08001240
1241 /* Loop again with lower rate */
Zhu Yib481de92007-09-25 17:54:57 -07001242 if (low != IWL_RATE_INVALID)
1243 rate = low;
Ben Cahill77626352007-11-29 11:09:44 +08001244
1245 /* Lower rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001246 else
1247 break;
Ben Cahill77626352007-11-29 11:09:44 +08001248
1249 /* Else try to raise the "search" rate to match "active" */
Zhu Yib481de92007-09-25 17:54:57 -07001250 } else {
Ben Cahill77626352007-11-29 11:09:44 +08001251 /* (2nd or later pass)
1252 * If we've already tried to lower the rate, and are
1253 * now trying to raise it, use the lower rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001254 if (new_rate != IWL_RATE_INVALID)
1255 break;
Ben Cahill77626352007-11-29 11:09:44 +08001256
1257 /* Loop again with higher rate */
Zhu Yib481de92007-09-25 17:54:57 -07001258 else if (high != IWL_RATE_INVALID) {
1259 start_hi = high;
1260 rate = high;
Ben Cahill77626352007-11-29 11:09:44 +08001261
1262 /* Higher rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001263 } else {
Guy Cohen90d77952008-09-09 10:54:53 +08001264 new_rate = rate;
Zhu Yib481de92007-09-25 17:54:57 -07001265 break;
1266 }
1267 }
1268 }
1269
1270 return new_rate;
1271}
Zhu Yib481de92007-09-25 17:54:57 -07001272
Ben Cahill77626352007-11-29 11:09:44 +08001273/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001274 * Set up search table for MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001275 */
Guy Cohenfde0db32008-04-21 15:42:01 -07001276static int rs_switch_to_mimo2(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001277 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001278 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001279 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001280 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001281{
Zhu Yib481de92007-09-25 17:54:57 -07001282 u16 rate_mask;
1283 s32 rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001284 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001285 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001286 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001287
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001288 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001289 return -1;
1290
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001291 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
Tomas Winkler00c5ae22008-09-03 11:26:42 +08001292 == WLAN_HT_CAP_SM_PS_STATIC)
Zhu Yib481de92007-09-25 17:54:57 -07001293 return -1;
1294
Ben Cahill77626352007-11-29 11:09:44 +08001295 /* Need both Tx chains/antennas to support MIMO */
Johannes Berg9e295112012-04-09 17:46:55 -07001296 if (priv->hw_params.tx_chains_num < 2)
Zhu Yib481de92007-09-25 17:54:57 -07001297 return -1;
1298
Tomas Winklere1623442009-01-27 14:27:56 -08001299 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001300
1301 tbl->lq_type = LQ_MIMO2;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001302 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001303 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001304 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001305 rate_mask = lq_sta->active_mimo2_rate;
1306
Johannes Berg7e6a5882010-08-23 10:46:46 +02001307 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001308 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001309 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001310 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001311
Guy Coheneecd6e52008-04-23 17:14:58 -07001312 rs_set_expected_tpt_table(lq_sta, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001313
Guy Cohenf935a6d2008-04-23 17:15:02 -07001314 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001315
Tomas Winklere1623442009-01-27 14:27:56 -08001316 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001317 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1318 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1319 rate, rate_mask);
1320 return -1;
1321 }
1322 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Guy Cohen39e88502008-04-23 17:14:57 -07001323
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001324 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1325 tbl->current_rate, is_green);
1326 return 0;
1327}
1328
1329/*
1330 * Set up search table for MIMO3
1331 */
1332static int rs_switch_to_mimo3(struct iwl_priv *priv,
1333 struct iwl_lq_sta *lq_sta,
1334 struct ieee80211_conf *conf,
1335 struct ieee80211_sta *sta,
1336 struct iwl_scale_tbl_info *tbl, int index)
1337{
1338 u16 rate_mask;
1339 s32 rate;
1340 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001341 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001342 struct iwl_rxon_context *ctx = sta_priv->ctx;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001343
1344 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1345 return -1;
1346
1347 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1348 == WLAN_HT_CAP_SM_PS_STATIC)
1349 return -1;
1350
1351 /* Need both Tx chains/antennas to support MIMO */
Johannes Berg9e295112012-04-09 17:46:55 -07001352 if (priv->hw_params.tx_chains_num < 3)
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001353 return -1;
1354
1355 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1356
1357 tbl->lq_type = LQ_MIMO3;
1358 tbl->is_dup = lq_sta->is_dup;
1359 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001360 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001361 rate_mask = lq_sta->active_mimo3_rate;
1362
Johannes Berg7e6a5882010-08-23 10:46:46 +02001363 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001364 tbl->is_ht40 = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001365 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001366 tbl->is_ht40 = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001367
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001368 rs_set_expected_tpt_table(lq_sta, tbl);
1369
1370 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1371
1372 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1373 rate, rate_mask);
Guy Cohen39e88502008-04-23 17:14:57 -07001374 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001375 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001376 rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001377 return -1;
Guy Cohen39e88502008-04-23 17:14:57 -07001378 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001379 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Zhu Yib481de92007-09-25 17:54:57 -07001380
Tomas Winklere1623442009-01-27 14:27:56 -08001381 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001382 tbl->current_rate, is_green);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001383 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001384}
1385
Ben Cahill77626352007-11-29 11:09:44 +08001386/*
1387 * Set up search table for SISO
1388 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001389static int rs_switch_to_siso(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001390 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001391 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001392 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001393 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001394{
Zhu Yib481de92007-09-25 17:54:57 -07001395 u16 rate_mask;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001396 u8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001397 s32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001398 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001399 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001400
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001401 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001402 return -1;
1403
Tomas Winklere1623442009-01-27 14:27:56 -08001404 IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001405
Tomas Winklerc33104f2008-01-14 17:46:21 -08001406 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001407 tbl->lq_type = LQ_SISO;
1408 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001409 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001410 rate_mask = lq_sta->active_siso_rate;
Zhu Yib481de92007-09-25 17:54:57 -07001411
Johannes Berg7e6a5882010-08-23 10:46:46 +02001412 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001413 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001414 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001415 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001416
Zhu Yib481de92007-09-25 17:54:57 -07001417 if (is_green)
Guy Cohen39e88502008-04-23 17:14:57 -07001418 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
Zhu Yib481de92007-09-25 17:54:57 -07001419
Guy Coheneecd6e52008-04-23 17:14:58 -07001420 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohenf935a6d2008-04-23 17:15:02 -07001421 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001422
Tomas Winklere1623442009-01-27 14:27:56 -08001423 IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001424 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001425 IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001426 rate, rate_mask);
1427 return -1;
1428 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001429 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Tomas Winklere1623442009-01-27 14:27:56 -08001430 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001431 tbl->current_rate, is_green);
Mohamed Abbas403ab562007-11-06 22:06:25 -08001432 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001433}
1434
Ben Cahill77626352007-11-29 11:09:44 +08001435/*
1436 * Try to switch to new modulation mode from legacy
1437 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001438static int rs_move_legacy_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001439 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001440 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001441 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001442 int index)
1443{
Tomas Winklere227cea2008-07-18 13:53:05 +08001444 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1445 struct iwl_scale_tbl_info *search_tbl =
1446 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1447 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1448 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1449 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001450 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001451 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001452 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Guy Cohenfde0db32008-04-21 15:42:01 -07001453 int ret = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001454 u8 update_search_tbl_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001455
Johannes Berg290f5992010-08-23 07:56:58 -07001456 switch (priv->bt_traffic_load) {
1457 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1458 /* nothing */
1459 break;
1460 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1461 /* avoid antenna B unless MIMO */
1462 if (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001463 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001464 break;
1465 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1466 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1467 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001468 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001469 first_antenna(priv->nvm_data->valid_tx_ant);
Johannes Berg290f5992010-08-23 07:56:58 -07001470 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 &&
1471 tbl->action != IWL_LEGACY_SWITCH_SISO)
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001472 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001473 break;
1474 default:
1475 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1476 break;
1477 }
1478
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001479 if (!iwl_ht_enabled(priv))
1480 /* stay in Legacy */
1481 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07001482 else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001483 tbl->action > IWL_LEGACY_SWITCH_SISO)
1484 tbl->action = IWL_LEGACY_SWITCH_SISO;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001485
1486 /* configure as 1x1 if bt full concurrency */
1487 if (priv->bt_full_concurrent) {
1488 if (!iwl_ht_enabled(priv))
1489 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1490 else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1491 tbl->action = IWL_LEGACY_SWITCH_SISO;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001492 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001493 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001494 }
1495
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001496 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001497 for (; ;) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001498 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001499 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001500 case IWL_LEGACY_SWITCH_ANTENNA1:
1501 case IWL_LEGACY_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001502 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
Zhu Yib481de92007-09-25 17:54:57 -07001503
Guy Cohen3110bef2008-09-09 10:54:54 +08001504 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1505 tx_chains_num <= 1) ||
1506 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
1507 tx_chains_num <= 2))
1508 break;
1509
Ben Cahill77626352007-11-29 11:09:44 +08001510 /* Don't change antenna if success has been great */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001511 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1512 !priv->bt_full_concurrent &&
1513 priv->bt_traffic_load ==
1514 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001515 break;
Ben Cahill77626352007-11-29 11:09:44 +08001516
Ben Cahill77626352007-11-29 11:09:44 +08001517 /* Set up search table to try other antenna */
Zhu Yib481de92007-09-25 17:54:57 -07001518 memcpy(search_tbl, tbl, sz);
1519
Guy Cohenaade00c2008-04-23 17:14:59 -07001520 if (rs_toggle_antenna(valid_tx_ant,
1521 &search_tbl->current_rate, search_tbl)) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001522 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001523 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohenaade00c2008-04-23 17:14:59 -07001524 goto out;
1525 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001526 break;
Zhu Yib481de92007-09-25 17:54:57 -07001527 case IWL_LEGACY_SWITCH_SISO:
Tomas Winklere1623442009-01-27 14:27:56 -08001528 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001529
1530 /* Set up search table to try SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001531 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001532 search_tbl->is_SGI = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001533 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001534 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001535 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001536 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001537 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001538 }
Zhu Yib481de92007-09-25 17:54:57 -07001539
1540 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001541 case IWL_LEGACY_SWITCH_MIMO2_AB:
1542 case IWL_LEGACY_SWITCH_MIMO2_AC:
1543 case IWL_LEGACY_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001544 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n");
Ben Cahill77626352007-11-29 11:09:44 +08001545
1546 /* Set up search table to try MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07001547 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001548 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001549
1550 if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
1551 search_tbl->ant_type = ANT_AB;
1552 else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
1553 search_tbl->ant_type = ANT_AC;
1554 else
1555 search_tbl->ant_type = ANT_BC;
1556
1557 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1558 break;
1559
Guy Cohenfde0db32008-04-21 15:42:01 -07001560 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001561 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001562 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001563 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001564 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001565 }
Zhu Yib481de92007-09-25 17:54:57 -07001566 break;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001567
1568 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1569 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1570
1571 /* Set up search table to try MIMO3 */
1572 memcpy(search_tbl, tbl, sz);
1573 search_tbl->is_SGI = 0;
1574
1575 search_tbl->ant_type = ANT_ABC;
1576
1577 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1578 break;
1579
1580 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1581 search_tbl, index);
1582 if (!ret) {
1583 lq_sta->action_counter = 0;
1584 goto out;
1585 }
1586 break;
Zhu Yib481de92007-09-25 17:54:57 -07001587 }
1588 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001589 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001590 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001591
1592 if (tbl->action == start_action)
1593 break;
1594
1595 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001596 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001597 return 0;
1598
Guy Cohen3110bef2008-09-09 10:54:54 +08001599out:
1600 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001601 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001602 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001603 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001604 if (update_search_tbl_counter)
1605 search_tbl->action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001606 return 0;
1607
1608}
1609
Ben Cahill77626352007-11-29 11:09:44 +08001610/*
1611 * Try to switch to new modulation mode from SISO
1612 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001613static int rs_move_siso_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001614 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001615 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001616 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001617{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001618 u8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001619 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1620 struct iwl_scale_tbl_info *search_tbl =
1621 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1622 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001623 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001624 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1625 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001626 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001627 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001628 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001629 u8 update_search_tbl_counter = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -07001630 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001631
Johannes Berg290f5992010-08-23 07:56:58 -07001632 switch (priv->bt_traffic_load) {
1633 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1634 /* nothing */
1635 break;
1636 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1637 /* avoid antenna B unless MIMO */
1638 if (tbl->action == IWL_SISO_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001639 tbl->action = IWL_SISO_SWITCH_MIMO2_AB;
Johannes Berg290f5992010-08-23 07:56:58 -07001640 break;
1641 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1642 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1643 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001644 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001645 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001646 if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
Johannes Berg290f5992010-08-23 07:56:58 -07001647 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1648 break;
1649 default:
1650 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1651 break;
1652 }
1653
Johannes Berg3ad3b922009-08-07 15:41:48 -07001654 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001655 tbl->action > IWL_SISO_SWITCH_ANTENNA2) {
1656 /* stay in SISO */
1657 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1658 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001659
1660 /* configure as 1x1 if bt full concurrency */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001661 if (priv->bt_full_concurrent) {
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001662 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001663 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001664 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1665 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1666 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001667
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001668 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001669 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001670 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001671 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001672 case IWL_SISO_SWITCH_ANTENNA1:
1673 case IWL_SISO_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001674 IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001675 if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001676 tx_chains_num <= 1) ||
Guy Cohen3110bef2008-09-09 10:54:54 +08001677 (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001678 tx_chains_num <= 2))
Guy Cohen3110bef2008-09-09 10:54:54 +08001679 break;
1680
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001681 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1682 !priv->bt_full_concurrent &&
1683 priv->bt_traffic_load ==
1684 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001685 break;
Zhu Yib481de92007-09-25 17:54:57 -07001686
1687 memcpy(search_tbl, tbl, sz);
Guy Cohenaade00c2008-04-23 17:14:59 -07001688 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001689 &search_tbl->current_rate, search_tbl)) {
1690 update_search_tbl_counter = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07001691 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001692 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001693 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001694 case IWL_SISO_SWITCH_MIMO2_AB:
1695 case IWL_SISO_SWITCH_MIMO2_AC:
1696 case IWL_SISO_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001697 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n");
Zhu Yib481de92007-09-25 17:54:57 -07001698 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001699 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001700
1701 if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
1702 search_tbl->ant_type = ANT_AB;
1703 else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
1704 search_tbl->ant_type = ANT_AC;
1705 else
1706 search_tbl->ant_type = ANT_BC;
1707
1708 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1709 break;
1710
Guy Cohenfde0db32008-04-21 15:42:01 -07001711 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001712 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001713 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001714 goto out;
1715 break;
1716 case IWL_SISO_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001717 if (!tbl->is_ht40 && !(ht_cap->cap &
1718 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001719 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001720 if (tbl->is_ht40 && !(ht_cap->cap &
1721 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001722 break;
1723
Tomas Winklere1623442009-01-27 14:27:56 -08001724 IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001725
Zhu Yib481de92007-09-25 17:54:57 -07001726 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001727 if (is_green) {
1728 if (!tbl->is_SGI)
1729 break;
1730 else
Winkler, Tomas15b16872008-12-19 10:37:33 +08001731 IWL_ERR(priv,
1732 "SGI was set in GF+SISO\n");
Zhu Yib481de92007-09-25 17:54:57 -07001733 }
Guy Cohen39e88502008-04-23 17:14:57 -07001734 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07001735 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohen39e88502008-04-23 17:14:57 -07001736 if (tbl->is_SGI) {
1737 s32 tpt = lq_sta->last_tpt / 100;
1738 if (tpt >= search_tbl->expected_tpt[index])
1739 break;
1740 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001741 search_tbl->current_rate =
1742 rate_n_flags_from_tbl(priv, search_tbl,
1743 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001744 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001745 goto out;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001746 case IWL_SISO_SWITCH_MIMO3_ABC:
1747 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1748 memcpy(search_tbl, tbl, sz);
1749 search_tbl->is_SGI = 0;
1750 search_tbl->ant_type = ANT_ABC;
1751
1752 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1753 break;
1754
1755 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1756 search_tbl, index);
1757 if (!ret)
1758 goto out;
1759 break;
Zhu Yib481de92007-09-25 17:54:57 -07001760 }
1761 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001762 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001763 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001764
1765 if (tbl->action == start_action)
1766 break;
1767 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001768 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001769 return 0;
1770
1771 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08001772 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001773 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001774 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001775 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001776 if (update_search_tbl_counter)
1777 search_tbl->action = tbl->action;
1778
Zhu Yib481de92007-09-25 17:54:57 -07001779 return 0;
1780}
1781
Ben Cahill77626352007-11-29 11:09:44 +08001782/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001783 * Try to switch to new modulation mode from MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001784 */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001785static int rs_move_mimo2_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001786 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001787 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001788 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001789{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001790 s8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001791 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1792 struct iwl_scale_tbl_info *search_tbl =
1793 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Guy Cohen3110bef2008-09-09 10:54:54 +08001794 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001795 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001796 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1797 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001798 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001799 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001800 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001801 u8 update_search_tbl_counter = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07001802 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001803
Johannes Berg290f5992010-08-23 07:56:58 -07001804 switch (priv->bt_traffic_load) {
1805 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1806 /* nothing */
1807 break;
1808 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1809 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1810 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001811 if (tbl->action != IWL_MIMO2_SWITCH_SISO_A)
1812 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1813 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001814 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1815 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001816 if (tbl->action == IWL_MIMO2_SWITCH_SISO_B ||
1817 tbl->action == IWL_MIMO2_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001818 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1819 break;
1820 default:
1821 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1822 break;
1823 }
1824
Johannes Berg3ad3b922009-08-07 15:41:48 -07001825 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001826 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1827 tbl->action > IWL_MIMO2_SWITCH_SISO_C)) {
1828 /* switch in SISO */
1829 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1830 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001831
1832 /* configure as 1x1 if bt full concurrency */
1833 if (priv->bt_full_concurrent &&
1834 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1835 tbl->action > IWL_MIMO2_SWITCH_SISO_C))
1836 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1837
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001838 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001839 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001840 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001841 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001842 case IWL_MIMO2_SWITCH_ANTENNA1:
1843 case IWL_MIMO2_SWITCH_ANTENNA2:
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001844 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001845
1846 if (tx_chains_num <= 2)
1847 break;
1848
1849 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1850 break;
1851
1852 memcpy(search_tbl, tbl, sz);
1853 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001854 &search_tbl->current_rate, search_tbl)) {
1855 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001856 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001857 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001858 break;
1859 case IWL_MIMO2_SWITCH_SISO_A:
1860 case IWL_MIMO2_SWITCH_SISO_B:
1861 case IWL_MIMO2_SWITCH_SISO_C:
Tomas Winklere1623442009-01-27 14:27:56 -08001862 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001863
Ben Cahill77626352007-11-29 11:09:44 +08001864 /* Set up new search table for SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001865 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001866
Guy Cohen3110bef2008-09-09 10:54:54 +08001867 if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
Guy Cohenfde0db32008-04-21 15:42:01 -07001868 search_tbl->ant_type = ANT_A;
Guy Cohen3110bef2008-09-09 10:54:54 +08001869 else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
Guy Cohenfde0db32008-04-21 15:42:01 -07001870 search_tbl->ant_type = ANT_B;
Guy Cohen3110bef2008-09-09 10:54:54 +08001871 else
1872 search_tbl->ant_type = ANT_C;
1873
1874 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1875 break;
Zhu Yib481de92007-09-25 17:54:57 -07001876
Tomas Winklerc33104f2008-01-14 17:46:21 -08001877 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001878 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001879 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001880 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08001881
Zhu Yib481de92007-09-25 17:54:57 -07001882 break;
1883
Guy Cohen3110bef2008-09-09 10:54:54 +08001884 case IWL_MIMO2_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001885 if (!tbl->is_ht40 && !(ht_cap->cap &
1886 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001887 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001888 if (tbl->is_ht40 && !(ht_cap->cap &
1889 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001890 break;
1891
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001892 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1893
1894 /* Set up new search table for MIMO2 */
1895 memcpy(search_tbl, tbl, sz);
1896 search_tbl->is_SGI = !tbl->is_SGI;
1897 rs_set_expected_tpt_table(lq_sta, search_tbl);
1898 /*
1899 * If active table already uses the fastest possible
1900 * modulation (dual stream with short guard interval),
1901 * and it's working well, there's no need to look
1902 * for a better type of modulation!
1903 */
1904 if (tbl->is_SGI) {
1905 s32 tpt = lq_sta->last_tpt / 100;
1906 if (tpt >= search_tbl->expected_tpt[index])
1907 break;
1908 }
1909 search_tbl->current_rate =
1910 rate_n_flags_from_tbl(priv, search_tbl,
1911 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001912 update_search_tbl_counter = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001913 goto out;
1914
1915 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1916 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1917 memcpy(search_tbl, tbl, sz);
1918 search_tbl->is_SGI = 0;
1919 search_tbl->ant_type = ANT_ABC;
1920
1921 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1922 break;
1923
1924 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1925 search_tbl, index);
1926 if (!ret)
1927 goto out;
1928
1929 break;
1930 }
1931 tbl->action++;
1932 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1933 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1934
1935 if (tbl->action == start_action)
1936 break;
1937 }
1938 search_tbl->lq_type = LQ_NONE;
1939 return 0;
1940 out:
1941 lq_sta->search_better_tbl = 1;
1942 tbl->action++;
1943 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1944 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001945 if (update_search_tbl_counter)
1946 search_tbl->action = tbl->action;
1947
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001948 return 0;
1949
1950}
1951
1952/*
1953 * Try to switch to new modulation mode from MIMO3
1954 */
1955static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1956 struct iwl_lq_sta *lq_sta,
1957 struct ieee80211_conf *conf,
1958 struct ieee80211_sta *sta, int index)
1959{
1960 s8 is_green = lq_sta->is_green;
1961 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1962 struct iwl_scale_tbl_info *search_tbl =
1963 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1964 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001965 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001966 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1967 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001968 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001969 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001970 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001971 int ret;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001972 u8 update_search_tbl_counter = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001973
Johannes Berg290f5992010-08-23 07:56:58 -07001974 switch (priv->bt_traffic_load) {
1975 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1976 /* nothing */
1977 break;
1978 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1979 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1980 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001981 if (tbl->action != IWL_MIMO3_SWITCH_SISO_A)
Johannes Berg290f5992010-08-23 07:56:58 -07001982 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001983 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001984 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1985 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001986 if (tbl->action == IWL_MIMO3_SWITCH_SISO_B ||
1987 tbl->action == IWL_MIMO3_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001988 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Johannes Berg290f5992010-08-23 07:56:58 -07001989 break;
1990 default:
1991 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1992 break;
1993 }
1994
Johannes Berg3ad3b922009-08-07 15:41:48 -07001995 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001996 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
1997 tbl->action > IWL_MIMO3_SWITCH_SISO_C)) {
1998 /* switch in SISO */
1999 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
2000 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002001
2002 /* configure as 1x1 if bt full concurrency */
2003 if (priv->bt_full_concurrent &&
2004 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
2005 tbl->action > IWL_MIMO3_SWITCH_SISO_C))
2006 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
2007
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07002008 start_action = tbl->action;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002009 for (;;) {
2010 lq_sta->action_counter++;
2011 switch (tbl->action) {
2012 case IWL_MIMO3_SWITCH_ANTENNA1:
2013 case IWL_MIMO3_SWITCH_ANTENNA2:
2014 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
2015
2016 if (tx_chains_num <= 3)
2017 break;
2018
2019 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
2020 break;
2021
2022 memcpy(search_tbl, tbl, sz);
2023 if (rs_toggle_antenna(valid_tx_ant,
2024 &search_tbl->current_rate, search_tbl))
2025 goto out;
2026 break;
2027 case IWL_MIMO3_SWITCH_SISO_A:
2028 case IWL_MIMO3_SWITCH_SISO_B:
2029 case IWL_MIMO3_SWITCH_SISO_C:
2030 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
2031
2032 /* Set up new search table for SISO */
2033 memcpy(search_tbl, tbl, sz);
2034
2035 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
2036 search_tbl->ant_type = ANT_A;
2037 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
2038 search_tbl->ant_type = ANT_B;
2039 else
2040 search_tbl->ant_type = ANT_C;
2041
2042 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2043 break;
2044
2045 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
2046 search_tbl, index);
2047 if (!ret)
2048 goto out;
2049
2050 break;
2051
2052 case IWL_MIMO3_SWITCH_MIMO2_AB:
2053 case IWL_MIMO3_SWITCH_MIMO2_AC:
2054 case IWL_MIMO3_SWITCH_MIMO2_BC:
2055 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
2056
2057 memcpy(search_tbl, tbl, sz);
2058 search_tbl->is_SGI = 0;
2059 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
2060 search_tbl->ant_type = ANT_AB;
2061 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
2062 search_tbl->ant_type = ANT_AC;
2063 else
2064 search_tbl->ant_type = ANT_BC;
2065
2066 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2067 break;
2068
2069 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
2070 search_tbl, index);
2071 if (!ret)
2072 goto out;
2073
2074 break;
2075
2076 case IWL_MIMO3_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002077 if (!tbl->is_ht40 && !(ht_cap->cap &
2078 IEEE80211_HT_CAP_SGI_20))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002079 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002080 if (tbl->is_ht40 && !(ht_cap->cap &
2081 IEEE80211_HT_CAP_SGI_40))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002082 break;
2083
2084 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
Ben Cahill77626352007-11-29 11:09:44 +08002085
2086 /* Set up new search table for MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07002087 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07002088 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07002089 rs_set_expected_tpt_table(lq_sta, search_tbl);
Ben Cahill77626352007-11-29 11:09:44 +08002090 /*
2091 * If active table already uses the fastest possible
2092 * modulation (dual stream with short guard interval),
2093 * and it's working well, there's no need to look
2094 * for a better type of modulation!
2095 */
Guy Cohen39e88502008-04-23 17:14:57 -07002096 if (tbl->is_SGI) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002097 s32 tpt = lq_sta->last_tpt / 100;
Guy Cohen39e88502008-04-23 17:14:57 -07002098 if (tpt >= search_tbl->expected_tpt[index])
2099 break;
Zhu Yib481de92007-09-25 17:54:57 -07002100 }
Tomas Winkler978785a2008-12-19 10:37:31 +08002101 search_tbl->current_rate =
2102 rate_n_flags_from_tbl(priv, search_tbl,
2103 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002104 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002105 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002106 }
2107 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002108 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2109 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07002110
2111 if (tbl->action == start_action)
2112 break;
2113 }
Guy Cohen3110bef2008-09-09 10:54:54 +08002114 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07002115 return 0;
2116 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08002117 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002118 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002119 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2120 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002121 if (update_search_tbl_counter)
2122 search_tbl->action = tbl->action;
2123
Zhu Yib481de92007-09-25 17:54:57 -07002124 return 0;
2125
2126}
2127
Ben Cahill77626352007-11-29 11:09:44 +08002128/*
2129 * Check whether we should continue using same modulation mode, or
2130 * begin search for a new mode, based on:
2131 * 1) # tx successes or failures while using this mode
2132 * 2) # times calling this function
2133 * 3) elapsed time in this mode (not used, for now)
2134 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002135static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
Zhu Yib481de92007-09-25 17:54:57 -07002136{
Tomas Winklere227cea2008-07-18 13:53:05 +08002137 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002138 int i;
2139 int active_tbl;
2140 int flush_interval_passed = 0;
Ester Kummerbf403db2008-05-05 10:22:40 +08002141 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07002142
Ester Kummerbf403db2008-05-05 10:22:40 +08002143 priv = lq_sta->drv;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002144 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002145
Tomas Winklerc33104f2008-01-14 17:46:21 -08002146 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002147
Ben Cahill77626352007-11-29 11:09:44 +08002148 /* If we've been disallowing search, see if we should now allow it */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002149 if (lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002150
Ben Cahill77626352007-11-29 11:09:44 +08002151 /* Elapsed time using current modulation mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002152 if (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002153 flush_interval_passed =
Mohamed Abbas447fee72009-04-20 14:37:02 -07002154 time_after(jiffies,
2155 (unsigned long)(lq_sta->flush_timer +
Zhu Yib481de92007-09-25 17:54:57 -07002156 IWL_RATE_SCALE_FLUSH_INTVL));
2157
Ben Cahill77626352007-11-29 11:09:44 +08002158 /*
2159 * Check if we should allow search for new modulation mode.
2160 * If many frames have failed or succeeded, or we've used
2161 * this same modulation for a long time, allow search, and
2162 * reset history stats that keep track of whether we should
2163 * allow a new search. Also (below) reset all bitmaps and
2164 * stats in active history.
2165 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002166 if (force_search ||
2167 (lq_sta->total_failed > lq_sta->max_failure_limit) ||
Tomas Winklerc33104f2008-01-14 17:46:21 -08002168 (lq_sta->total_success > lq_sta->max_success_limit) ||
2169 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002170 && (flush_interval_passed))) {
Johannes Berg0ca24da2012-03-15 13:26:46 -07002171 IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002172 lq_sta->total_failed,
2173 lq_sta->total_success,
Zhu Yib481de92007-09-25 17:54:57 -07002174 flush_interval_passed);
Ben Cahill77626352007-11-29 11:09:44 +08002175
2176 /* Allow search for new mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002177 lq_sta->stay_in_tbl = 0; /* only place reset */
2178 lq_sta->total_failed = 0;
2179 lq_sta->total_success = 0;
2180 lq_sta->flush_timer = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002181
2182 /*
2183 * Else if we've used this modulation mode enough repetitions
2184 * (regardless of elapsed time or success/failure), reset
2185 * history bitmaps and rate-specific stats for all rates in
2186 * active table.
2187 */
Mohamed Abbas403ab562007-11-06 22:06:25 -08002188 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002189 lq_sta->table_count++;
2190 if (lq_sta->table_count >=
2191 lq_sta->table_count_limit) {
2192 lq_sta->table_count = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002193
Tomas Winklere1623442009-01-27 14:27:56 -08002194 IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n");
Zhu Yib481de92007-09-25 17:54:57 -07002195 for (i = 0; i < IWL_RATE_COUNT; i++)
2196 rs_rate_scale_clear_window(
2197 &(tbl->win[i]));
2198 }
2199 }
2200
Ben Cahill77626352007-11-29 11:09:44 +08002201 /* If transitioning to allow "search", reset all history
2202 * bitmaps and stats in active table (this will become the new
2203 * "search" table). */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002204 if (!lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002205 for (i = 0; i < IWL_RATE_COUNT; i++)
2206 rs_rate_scale_clear_window(&(tbl->win[i]));
2207 }
2208 }
2209}
2210
Ben Cahill77626352007-11-29 11:09:44 +08002211/*
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002212 * setup rate table in uCode
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002213 */
Johannes Berg70817b52011-05-11 03:29:25 -07002214static void rs_update_rate_tbl(struct iwl_priv *priv,
2215 struct iwl_rxon_context *ctx,
2216 struct iwl_lq_sta *lq_sta,
2217 struct iwl_scale_tbl_info *tbl,
2218 int index, u8 is_green)
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002219{
2220 u32 rate;
2221
2222 /* Update uCode's rate table. */
2223 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
2224 rs_fill_link_cmd(priv, lq_sta, rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002225 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002226}
2227
2228/*
Ben Cahill77626352007-11-29 11:09:44 +08002229 * Do rate scaling and search for new modulation mode.
2230 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002231static void rs_rate_scale_perform(struct iwl_priv *priv,
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002232 struct sk_buff *skb,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002233 struct ieee80211_sta *sta,
2234 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002235{
Johannes Berg4b7679a2008-09-18 18:14:18 +02002236 struct ieee80211_hw *hw = priv->hw;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002237 struct ieee80211_conf *conf = &hw->conf;
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002238 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2239 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002240 int low = IWL_RATE_INVALID;
2241 int high = IWL_RATE_INVALID;
2242 int index;
2243 int i;
Tomas Winklere227cea2008-07-18 13:53:05 +08002244 struct iwl_rate_scale_data *window = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002245 int current_tpt = IWL_INVALID_VALUE;
2246 int low_tpt = IWL_INVALID_VALUE;
2247 int high_tpt = IWL_INVALID_VALUE;
2248 u32 fail_count;
2249 s8 scale_action = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07002250 u16 rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -07002251 u8 update_lq = 0;
Tomas Winklere227cea2008-07-18 13:53:05 +08002252 struct iwl_scale_tbl_info *tbl, *tbl1;
Zhu Yib481de92007-09-25 17:54:57 -07002253 u16 rate_scale_index_msk = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002254 u8 is_green = 0;
2255 u8 active_tbl = 0;
2256 u8 done_search = 0;
2257 u16 high_low;
Guy Cohena5e8b502008-05-29 16:35:11 +08002258 s32 sr;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002259 u8 tid = IWL_MAX_TID_COUNT;
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002260 struct iwl_tid_data *tid_data;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002261 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002262 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002263
Tomas Winklere1623442009-01-27 14:27:56 -08002264 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002265
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002266 /* Send management frames and NO_ACK data using lowest rate. */
Tomas Winkler417f1142008-11-12 13:14:06 -08002267 /* TODO: this could probably be improved.. */
2268 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002269 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -07002270 return;
Zhu Yib481de92007-09-25 17:54:57 -07002271
Johannes Berg4b7679a2008-09-18 18:14:18 +02002272 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
Zhu Yib481de92007-09-25 17:54:57 -07002273
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002274 tid = rs_tl_add_packet(lq_sta, hdr);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002275 if ((tid != IWL_MAX_TID_COUNT) &&
2276 (lq_sta->tx_agg_tid_en & (1 << tid))) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002277 tid_data = &priv->tid_data[lq_sta->lq.sta_id][tid];
Daniel C Halperine3949d62009-09-17 10:43:50 -07002278 if (tid_data->agg.state == IWL_AGG_OFF)
2279 lq_sta->is_agg = 0;
2280 else
2281 lq_sta->is_agg = 1;
2282 } else
2283 lq_sta->is_agg = 0;
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002284
Ben Cahill77626352007-11-29 11:09:44 +08002285 /*
2286 * Select rate-scale / modulation-mode table to work with in
2287 * the rest of this function: "search" if searching for better
2288 * modulation mode, or "active" if doing rate scaling within a mode.
2289 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002290 if (!lq_sta->search_better_tbl)
2291 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002292 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002293 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002294
Tomas Winklerc33104f2008-01-14 17:46:21 -08002295 tbl = &(lq_sta->lq_info[active_tbl]);
Wey-Yi Guy2681b202009-05-21 13:44:22 -07002296 if (is_legacy(tbl->lq_type))
2297 lq_sta->is_green = 0;
2298 else
Johannes Berg7e6a5882010-08-23 10:46:46 +02002299 lq_sta->is_green = rs_use_green(sta);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002300 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07002301
Ben Cahill77626352007-11-29 11:09:44 +08002302 /* current tx rate */
Johannes Bergb7e35002008-09-11 02:22:58 +02002303 index = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002304
Tomas Winklere1623442009-01-27 14:27:56 -08002305 IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index,
Zhu Yib481de92007-09-25 17:54:57 -07002306 tbl->lq_type);
2307
Ben Cahill77626352007-11-29 11:09:44 +08002308 /* rates available for this association, and for modulation mode */
Guy Coheneecd6e52008-04-23 17:14:58 -07002309 rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07002310
Frans Pop91dd6c22010-03-24 14:19:58 -07002311 IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07002312
2313 /* mask with station rate restriction */
2314 if (is_legacy(tbl->lq_type)) {
Johannes Berg8318d782008-01-24 19:38:38 +01002315 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Ben Cahill77626352007-11-29 11:09:44 +08002316 /* supp_rates has no CCK bits in A mode */
Zhu Yib481de92007-09-25 17:54:57 -07002317 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002318 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -07002319 else
2320 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002321 lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -07002322
2323 } else
2324 rate_scale_index_msk = rate_mask;
2325
2326 if (!rate_scale_index_msk)
2327 rate_scale_index_msk = rate_mask;
2328
Guy Cohen07bc28e2008-04-23 17:15:03 -07002329 if (!((1 << index) & rate_scale_index_msk)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002330 IWL_ERR(priv, "Current Rate is not valid\n");
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002331 if (lq_sta->search_better_tbl) {
2332 /* revert to active table if search table is not valid*/
2333 tbl->lq_type = LQ_NONE;
2334 lq_sta->search_better_tbl = 0;
2335 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
2336 /* get "active" rate info */
2337 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Johannes Berg70817b52011-05-11 03:29:25 -07002338 rs_update_rate_tbl(priv, ctx, lq_sta, tbl,
2339 index, is_green);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002340 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002341 return;
Zhu Yib481de92007-09-25 17:54:57 -07002342 }
2343
Ben Cahill77626352007-11-29 11:09:44 +08002344 /* Get expected throughput table and history window for current rate */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002345 if (!tbl->expected_tpt) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002346 IWL_ERR(priv, "tbl->expected_tpt is NULL\n");
Guy Cohen07bc28e2008-04-23 17:15:03 -07002347 return;
2348 }
Zhu Yib481de92007-09-25 17:54:57 -07002349
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002350 /* force user max rate if set by user */
2351 if ((lq_sta->max_rate_idx != -1) &&
2352 (lq_sta->max_rate_idx < index)) {
2353 index = lq_sta->max_rate_idx;
2354 update_lq = 1;
2355 window = &(tbl->win[index]);
2356 goto lq_update;
2357 }
2358
Zhu Yib481de92007-09-25 17:54:57 -07002359 window = &(tbl->win[index]);
2360
Ben Cahill77626352007-11-29 11:09:44 +08002361 /*
2362 * If there is not enough history to calculate actual average
2363 * throughput, keep analyzing results of more tx frames, without
2364 * changing rate or mode (bypass most of the rest of this function).
2365 * Set up new rate table in uCode only if old rate is not supported
2366 * in current association (use new rate found above).
2367 */
Zhu Yib481de92007-09-25 17:54:57 -07002368 fail_count = window->counter - window->success_counter;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002369 if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
2370 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002371 IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d "
Zhu Yib481de92007-09-25 17:54:57 -07002372 "for index %d\n",
2373 window->success_counter, window->counter, index);
Ben Cahill77626352007-11-29 11:09:44 +08002374
2375 /* Can't calculate this yet; not enough history */
Zhu Yib481de92007-09-25 17:54:57 -07002376 window->average_tpt = IWL_INVALID_VALUE;
Ben Cahill77626352007-11-29 11:09:44 +08002377
2378 /* Should we stay with this modulation mode,
2379 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002380 rs_stay_in_table(lq_sta, false);
Ben Cahill77626352007-11-29 11:09:44 +08002381
Zhu Yib481de92007-09-25 17:54:57 -07002382 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08002383 }
Ben Cahill77626352007-11-29 11:09:44 +08002384 /* Else we have enough samples; calculate estimate of
2385 * actual average throughput */
Reinette Chatre3d79b2a2010-05-03 10:55:07 -07002386 if (window->average_tpt != ((window->success_ratio *
2387 tbl->expected_tpt[index] + 64) / 128)) {
2388 IWL_ERR(priv, "expected_tpt should have been calculated by now\n");
2389 window->average_tpt = ((window->success_ratio *
2390 tbl->expected_tpt[index] + 64) / 128);
2391 }
Zhu Yib481de92007-09-25 17:54:57 -07002392
Ben Cahill77626352007-11-29 11:09:44 +08002393 /* If we are searching for better modulation mode, check success. */
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002394 if (lq_sta->search_better_tbl &&
Johannes Berg3ad3b922009-08-07 15:41:48 -07002395 (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) {
Ben Cahill77626352007-11-29 11:09:44 +08002396 /* If good success, continue using the "search" mode;
2397 * no need to send new link quality command, since we're
2398 * continuing to use the setup that we've been trying. */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002399 if (window->average_tpt > lq_sta->last_tpt) {
2400
Tomas Winklere1623442009-01-27 14:27:56 -08002401 IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002402 "suc=%d cur-tpt=%d old-tpt=%d\n",
2403 window->success_ratio,
2404 window->average_tpt,
2405 lq_sta->last_tpt);
2406
2407 if (!is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002408 lq_sta->enable_counter = 1;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002409
Ben Cahill77626352007-11-29 11:09:44 +08002410 /* Swap tables; "search" becomes "active" */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002411 lq_sta->active_tbl = active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002412 current_tpt = window->average_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002413
2414 /* Else poor success; go back to mode in "active" table */
Zhu Yib481de92007-09-25 17:54:57 -07002415 } else {
Guy Cohen07bc28e2008-04-23 17:15:03 -07002416
Tomas Winklere1623442009-01-27 14:27:56 -08002417 IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002418 "suc=%d cur-tpt=%d old-tpt=%d\n",
2419 window->success_ratio,
2420 window->average_tpt,
2421 lq_sta->last_tpt);
2422
Ben Cahill77626352007-11-29 11:09:44 +08002423 /* Nullify "search" table */
Zhu Yib481de92007-09-25 17:54:57 -07002424 tbl->lq_type = LQ_NONE;
Ben Cahill77626352007-11-29 11:09:44 +08002425
2426 /* Revert to "active" table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002427 active_tbl = lq_sta->active_tbl;
2428 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002429
Ben Cahill77626352007-11-29 11:09:44 +08002430 /* Revert to "active" rate and throughput info */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002431 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002432 current_tpt = lq_sta->last_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002433
2434 /* Need to set up a new rate table in uCode */
2435 update_lq = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002436 }
Ben Cahill77626352007-11-29 11:09:44 +08002437
2438 /* Either way, we've made a decision; modulation mode
2439 * search is done, allow rate adjustment next time. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002440 lq_sta->search_better_tbl = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002441 done_search = 1; /* Don't switch modes below! */
Zhu Yib481de92007-09-25 17:54:57 -07002442 goto lq_update;
2443 }
2444
Ben Cahill77626352007-11-29 11:09:44 +08002445 /* (Else) not in search of better modulation mode, try for better
2446 * starting rate, while staying in this mode. */
Ester Kummerbf403db2008-05-05 10:22:40 +08002447 high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk,
Zhu Yib481de92007-09-25 17:54:57 -07002448 tbl->lq_type);
2449 low = high_low & 0xff;
2450 high = (high_low >> 8) & 0xff;
2451
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002452 /* If user set max rate, dont allow higher than user constrain */
2453 if ((lq_sta->max_rate_idx != -1) &&
2454 (lq_sta->max_rate_idx < high))
2455 high = IWL_RATE_INVALID;
2456
Guy Cohena5e8b502008-05-29 16:35:11 +08002457 sr = window->success_ratio;
2458
Ben Cahill77626352007-11-29 11:09:44 +08002459 /* Collect measured throughputs for current and adjacent rates */
Zhu Yib481de92007-09-25 17:54:57 -07002460 current_tpt = window->average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002461 if (low != IWL_RATE_INVALID)
2462 low_tpt = tbl->win[low].average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002463 if (high != IWL_RATE_INVALID)
2464 high_tpt = tbl->win[high].average_tpt;
2465
Guy Cohena5e8b502008-05-29 16:35:11 +08002466 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002467
Ben Cahill77626352007-11-29 11:09:44 +08002468 /* Too many failures, decrease rate */
Guy Cohena5e8b502008-05-29 16:35:11 +08002469 if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002470 IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n");
Zhu Yib481de92007-09-25 17:54:57 -07002471 scale_action = -1;
Ben Cahill77626352007-11-29 11:09:44 +08002472
2473 /* No throughput measured yet for adjacent rates; try increase. */
Zhu Yib481de92007-09-25 17:54:57 -07002474 } else if ((low_tpt == IWL_INVALID_VALUE) &&
Guy Cohena5e8b502008-05-29 16:35:11 +08002475 (high_tpt == IWL_INVALID_VALUE)) {
2476
2477 if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
2478 scale_action = 1;
2479 else if (low != IWL_RATE_INVALID)
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002480 scale_action = 0;
Guy Cohena5e8b502008-05-29 16:35:11 +08002481 }
Ben Cahill77626352007-11-29 11:09:44 +08002482
2483 /* Both adjacent throughputs are measured, but neither one has better
2484 * throughput; we're using the best rate, don't change it! */
Zhu Yib481de92007-09-25 17:54:57 -07002485 else if ((low_tpt != IWL_INVALID_VALUE) &&
2486 (high_tpt != IWL_INVALID_VALUE) &&
2487 (low_tpt < current_tpt) &&
2488 (high_tpt < current_tpt))
2489 scale_action = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002490
2491 /* At least one adjacent rate's throughput is measured,
2492 * and may have better performance. */
Zhu Yib481de92007-09-25 17:54:57 -07002493 else {
Ben Cahill77626352007-11-29 11:09:44 +08002494 /* Higher adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002495 if (high_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002496 /* Higher rate has better throughput */
Guy Cohena5e8b502008-05-29 16:35:11 +08002497 if (high_tpt > current_tpt &&
2498 sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002499 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002500 } else {
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002501 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002502 }
Ben Cahill77626352007-11-29 11:09:44 +08002503
2504 /* Lower adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002505 } else if (low_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002506 /* Lower rate has better throughput */
Zhu Yib481de92007-09-25 17:54:57 -07002507 if (low_tpt > current_tpt) {
Tomas Winklere1623442009-01-27 14:27:56 -08002508 IWL_DEBUG_RATE(priv,
2509 "decrease rate because of low tpt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002510 scale_action = -1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002511 } else if (sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002512 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002513 }
Zhu Yib481de92007-09-25 17:54:57 -07002514 }
2515 }
2516
Ben Cahill77626352007-11-29 11:09:44 +08002517 /* Sanity check; asked for decrease, but success rate or throughput
2518 * has been good at old rate. Don't change it. */
Guy Cohena5e8b502008-05-29 16:35:11 +08002519 if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
2520 ((sr > IWL_RATE_HIGH_TH) ||
Zhu Yib481de92007-09-25 17:54:57 -07002521 (current_tpt > (100 * tbl->expected_tpt[low]))))
Zhu Yib481de92007-09-25 17:54:57 -07002522 scale_action = 0;
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002523 if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type))
2524 scale_action = -1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07002525 if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002526 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type)))
2527 scale_action = -1;
Johannes Berg290f5992010-08-23 07:56:58 -07002528
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002529 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2530 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2531 if (lq_sta->last_bt_traffic > priv->bt_traffic_load) {
2532 /*
2533 * don't set scale_action, don't want to scale up if
2534 * the rate scale doesn't otherwise think that is a
2535 * good idea.
2536 */
2537 } else if (lq_sta->last_bt_traffic <= priv->bt_traffic_load) {
2538 scale_action = -1;
2539 }
2540 }
2541 lq_sta->last_bt_traffic = priv->bt_traffic_load;
2542
2543 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2544 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2545 /* search for a new modulation */
2546 rs_stay_in_table(lq_sta, true);
2547 goto lq_update;
Johannes Berg290f5992010-08-23 07:56:58 -07002548 }
2549
Zhu Yib481de92007-09-25 17:54:57 -07002550 switch (scale_action) {
2551 case -1:
Ben Cahill77626352007-11-29 11:09:44 +08002552 /* Decrease starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002553 if (low != IWL_RATE_INVALID) {
2554 update_lq = 1;
2555 index = low;
2556 }
Mohamed Abbas447fee72009-04-20 14:37:02 -07002557
Zhu Yib481de92007-09-25 17:54:57 -07002558 break;
2559 case 1:
Ben Cahill77626352007-11-29 11:09:44 +08002560 /* Increase starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002561 if (high != IWL_RATE_INVALID) {
2562 update_lq = 1;
2563 index = high;
2564 }
2565
2566 break;
2567 case 0:
Ben Cahill77626352007-11-29 11:09:44 +08002568 /* No change */
Zhu Yib481de92007-09-25 17:54:57 -07002569 default:
2570 break;
2571 }
2572
Tomas Winklere1623442009-01-27 14:27:56 -08002573 IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d "
Zhu Yib481de92007-09-25 17:54:57 -07002574 "high %d type %d\n",
2575 index, scale_action, low, high, tbl->lq_type);
2576
Guy Cohena5e8b502008-05-29 16:35:11 +08002577lq_update:
Ben Cahill77626352007-11-29 11:09:44 +08002578 /* Replace uCode's rate table for the destination station. */
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002579 if (update_lq)
Johannes Berg70817b52011-05-11 03:29:25 -07002580 rs_update_rate_tbl(priv, ctx, lq_sta, tbl, index, is_green);
Ben Cahill77626352007-11-29 11:09:44 +08002581
Johannes Berg3ad3b922009-08-07 15:41:48 -07002582 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) {
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002583 /* Should we stay with this modulation mode,
2584 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002585 rs_stay_in_table(lq_sta, false);
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002586 }
Ben Cahill77626352007-11-29 11:09:44 +08002587 /*
2588 * Search for new modulation mode if we're:
2589 * 1) Not changing rates right now
2590 * 2) Not just finishing up a search
2591 * 3) Allowing a new search
2592 */
Guy Cohen47cfd462008-05-27 11:29:34 +08002593 if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) {
Ben Cahill77626352007-11-29 11:09:44 +08002594 /* Save current throughput to compare with "search" throughput*/
Tomas Winklerc33104f2008-01-14 17:46:21 -08002595 lq_sta->last_tpt = current_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002596
Ben Cahill77626352007-11-29 11:09:44 +08002597 /* Select a new "search" modulation mode to try.
2598 * If one is found, set up the new "search" table. */
Zhu Yib481de92007-09-25 17:54:57 -07002599 if (is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002600 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002601 else if (is_siso(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002602 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002603 else if (is_mimo2(tbl->lq_type))
2604 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002605 else
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002606 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002607
Ben Cahill77626352007-11-29 11:09:44 +08002608 /* If new "search" mode was selected, set up in uCode table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002609 if (lq_sta->search_better_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002610 /* Access the "search" table, clear its history. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002611 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Zhu Yib481de92007-09-25 17:54:57 -07002612 for (i = 0; i < IWL_RATE_COUNT; i++)
2613 rs_rate_scale_clear_window(&(tbl->win[i]));
2614
Ben Cahill77626352007-11-29 11:09:44 +08002615 /* Use new "search" start rate */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002616 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002617
Tomas Winklere1623442009-01-27 14:27:56 -08002618 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n",
Guy Cohen39e88502008-04-23 17:14:57 -07002619 tbl->current_rate, index);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002620 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002621 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Mohamed Abbas447fee72009-04-20 14:37:02 -07002622 } else
2623 done_search = 1;
2624 }
Zhu Yib481de92007-09-25 17:54:57 -07002625
Mohamed Abbas447fee72009-04-20 14:37:02 -07002626 if (done_search && !lq_sta->stay_in_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002627 /* If the "active" (non-search) mode was legacy,
2628 * and we've tried switching antennas,
2629 * but we haven't been able to try HT modes (not available),
2630 * stay with best antenna legacy modulation for a while
2631 * before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002632 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002633 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002634 lq_sta->action_counter > tbl1->max_search) {
Tomas Winklere1623442009-01-27 14:27:56 -08002635 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08002636 rs_set_stay_in_table(priv, 1, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002637 }
2638
Ben Cahill77626352007-11-29 11:09:44 +08002639 /* If we're in an HT mode, and all 3 mode switch actions
2640 * have been tried and compared, stay in this best modulation
2641 * mode for a while before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002642 if (lq_sta->enable_counter &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002643 (lq_sta->action_counter >= tbl1->max_search) &&
2644 iwl_ht_enabled(priv)) {
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002645 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2646 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002647 (tid != IWL_MAX_TID_COUNT)) {
2648 u8 sta_id = lq_sta->lq.sta_id;
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002649 tid_data = &priv->tid_data[sta_id][tid];
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002650 if (tid_data->agg.state == IWL_AGG_OFF) {
2651 IWL_DEBUG_RATE(priv,
2652 "try to aggregate tid %d\n",
2653 tid);
2654 rs_tl_turn_on_agg(priv, tid,
2655 lq_sta, sta);
2656 }
Zhu Yib481de92007-09-25 17:54:57 -07002657 }
Ester Kummerbf403db2008-05-05 10:22:40 +08002658 rs_set_stay_in_table(priv, 0, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002659 }
Zhu Yib481de92007-09-25 17:54:57 -07002660 }
2661
2662out:
Tomas Winkler978785a2008-12-19 10:37:31 +08002663 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
Wey-Yi Guyc3322b32011-10-10 07:26:58 -07002664 lq_sta->last_txrate_idx = index;
Zhu Yib481de92007-09-25 17:54:57 -07002665}
2666
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002667/**
2668 * rs_initialize_lq - Initialize a station's hardware rate table
2669 *
2670 * The uCode's station table contains a table of fallback rates
2671 * for automatic fallback during transmission.
2672 *
2673 * NOTE: This sets up a default set of values. These will be replaced later
2674 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
2675 * rc80211_simple.
2676 *
2677 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
2678 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
2679 * which requires station table entry to exist).
2680 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002681static void rs_initialize_lq(struct iwl_priv *priv,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002682 struct ieee80211_sta *sta,
2683 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002684{
Tomas Winklere227cea2008-07-18 13:53:05 +08002685 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002686 int rate_idx;
Guy Cohenaade00c2008-04-23 17:14:59 -07002687 int i;
Guy Cohen39e88502008-04-23 17:14:57 -07002688 u32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002689 u8 use_green = rs_use_green(sta);
Guy Cohenaade00c2008-04-23 17:14:59 -07002690 u8 active_tbl = 0;
2691 u8 valid_tx_ant;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002692 struct iwl_station_priv *sta_priv;
2693 struct iwl_rxon_context *ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002694
Johannes Berg4b7679a2008-09-18 18:14:18 +02002695 if (!sta || !lq_sta)
Johannes Berg7e6a5882010-08-23 10:46:46 +02002696 return;
2697
2698 sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002699 ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002700
Johannes Bergb7e35002008-09-11 02:22:58 +02002701 i = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002702
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002703 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Guy Cohenaade00c2008-04-23 17:14:59 -07002704
Tomas Winklerc33104f2008-01-14 17:46:21 -08002705 if (!lq_sta->search_better_tbl)
2706 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002707 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002708 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002709
Tomas Winklerc33104f2008-01-14 17:46:21 -08002710 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002711
2712 if ((i < 0) || (i >= IWL_RATE_COUNT))
2713 i = 0;
2714
Tomas Winkler1826dcc2008-05-15 13:54:02 +08002715 rate = iwl_rates[i].plcp;
Winkler, Tomaseb48dca2008-10-29 14:05:48 -07002716 tbl->ant_type = first_antenna(valid_tx_ant);
2717 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
Zhu Yib481de92007-09-25 17:54:57 -07002718
2719 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -07002720 rate |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002721
Guy Cohen39e88502008-04-23 17:14:57 -07002722 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
Guy Cohenaade00c2008-04-23 17:14:59 -07002723 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2724 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07002725
Tomas Winkler978785a2008-12-19 10:37:31 +08002726 rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green);
Guy Cohen39e88502008-04-23 17:14:57 -07002727 tbl->current_rate = rate;
Guy Coheneecd6e52008-04-23 17:14:58 -07002728 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002729 rs_fill_link_cmd(NULL, lq_sta, rate);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002730 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002731 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true);
Zhu Yib481de92007-09-25 17:54:57 -07002732}
2733
Johannes Berge6a98542008-10-21 12:40:02 +02002734static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2735 struct ieee80211_tx_rate_control *txrc)
Zhu Yib481de92007-09-25 17:54:57 -07002736{
2737
Johannes Berge6a98542008-10-21 12:40:02 +02002738 struct sk_buff *skb = txrc->skb;
2739 struct ieee80211_supported_band *sband = txrc->sband;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002740 struct iwl_op_mode *op_mode __maybe_unused =
2741 (struct iwl_op_mode *)priv_r;
2742 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge6a98542008-10-21 12:40:02 +02002743 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Tomas Winkler417f1142008-11-12 13:14:06 -08002744 struct iwl_lq_sta *lq_sta = priv_sta;
2745 int rate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002746
Tomas Winklere1623442009-01-27 14:27:56 -08002747 IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002748
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002749 /* Get max rate if user set max rate */
2750 if (lq_sta) {
2751 lq_sta->max_rate_idx = txrc->max_rate_idx;
2752 if ((sband->band == IEEE80211_BAND_5GHZ) &&
2753 (lq_sta->max_rate_idx != -1))
2754 lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
2755 if ((lq_sta->max_rate_idx < 0) ||
2756 (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
2757 lq_sta->max_rate_idx = -1;
2758 }
2759
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002760 /* Treat uninitialized rate scaling data same as non-existing. */
2761 if (lq_sta && !lq_sta->drv) {
2762 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
2763 priv_sta = NULL;
2764 }
2765
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002766 /* Send management frames and NO_ACK data using lowest rate. */
Luis R. Rodriguez4c6d4f52009-07-16 10:05:41 -07002767 if (rate_control_send_low(sta, priv_sta, txrc))
Johannes Berg4b7679a2008-09-18 18:14:18 +02002768 return;
Zhu Yib481de92007-09-25 17:54:57 -07002769
Tomas Winkler417f1142008-11-12 13:14:06 -08002770 rate_idx = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002771
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002772 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
Tomas Winkler417f1142008-11-12 13:14:06 -08002773 rate_idx -= IWL_FIRST_OFDM_RATE;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002774 /* 6M and 9M shared same MCS index */
2775 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2776 if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2777 IWL_RATE_MIMO3_6M_PLCP)
2778 rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
2779 else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2780 IWL_RATE_MIMO2_6M_PLCP)
2781 rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
2782 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2783 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2784 info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
2785 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2786 info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07002787 if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK)
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002788 info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2789 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2790 info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
2791 } else {
Daniel C Halperin50273092009-08-28 09:44:45 -07002792 /* Check for invalid rates */
2793 if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
2794 ((sband->band == IEEE80211_BAND_5GHZ) &&
2795 (rate_idx < IWL_FIRST_OFDM_RATE)))
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002796 rate_idx = rate_lowest_index(sband, sta);
Daniel C Halperin50273092009-08-28 09:44:45 -07002797 /* On valid 5 GHz rate, adjust index */
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002798 else if (sband->band == IEEE80211_BAND_5GHZ)
2799 rate_idx -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin7ebaeff2009-08-21 13:34:20 -07002800 info->control.rates[0].flags = 0;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002801 }
Tomas Winkler417f1142008-11-12 13:14:06 -08002802 info->control.rates[0].idx = rate_idx;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002803
Zhu Yib481de92007-09-25 17:54:57 -07002804}
2805
Johannes Berg4b7679a2008-09-18 18:14:18 +02002806static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2807 gfp_t gfp)
Zhu Yib481de92007-09-25 17:54:57 -07002808{
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002809 struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002810 struct iwl_op_mode *op_mode __maybe_unused =
2811 (struct iwl_op_mode *)priv_rate;
2812 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002813
Tomas Winklere1623442009-01-27 14:27:56 -08002814 IWL_DEBUG_RATE(priv, "create station rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -07002815
Johannes Berg08960de2011-04-05 09:41:53 -07002816 return &sta_priv->lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002817}
2818
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002819/*
2820 * Called after adding a new station to initialize rate scaling
2821 */
2822void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002823{
2824 int i, j;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002825 struct ieee80211_hw *hw = priv->hw;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002826 struct ieee80211_conf *conf = &priv->hw->conf;
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002827 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002828 struct iwl_station_priv *sta_priv;
2829 struct iwl_lq_sta *lq_sta;
2830 struct ieee80211_supported_band *sband;
Johannes Berg3ac40ed2012-03-08 09:18:04 +01002831 unsigned long supp; /* must be unsigned long for for_each_set_bit */
Zhu Yib481de92007-09-25 17:54:57 -07002832
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002833 sta_priv = (struct iwl_station_priv *) sta->drv_priv;
2834 lq_sta = &sta_priv->lq_sta;
2835 sband = hw->wiphy->bands[conf->channel->band];
2836
2837
2838 lq_sta->lq.sta_id = sta_id;
Reinette Chatre5ad13f82009-10-30 14:36:14 -07002839
2840 for (j = 0; j < LQ_SIZE; j++)
2841 for (i = 0; i < IWL_RATE_COUNT; i++)
2842 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2843
Tomas Winklerc33104f2008-01-14 17:46:21 -08002844 lq_sta->flush_timer = 0;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002845 lq_sta->supp_rates = sta->supp_rates[sband->band];
Zhu Yib481de92007-09-25 17:54:57 -07002846 for (j = 0; j < LQ_SIZE; j++)
2847 for (i = 0; i < IWL_RATE_COUNT; i++)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002848 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
Zhu Yib481de92007-09-25 17:54:57 -07002849
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002850 IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n",
2851 sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07002852 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2853 * the lowest or the highest rate.. Could consider using RSSI from
2854 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2855 * after assoc.. */
2856
Tomas Winklerc33104f2008-01-14 17:46:21 -08002857 lq_sta->is_dup = 0;
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002858 lq_sta->max_rate_idx = -1;
Abbas, Mohamed7d049e52009-01-20 21:33:53 -08002859 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002860 lq_sta->is_green = rs_use_green(sta);
Johannes Berg3ac40ed2012-03-08 09:18:04 +01002861 lq_sta->band = sband->band;
2862 /*
2863 * active legacy rates as per supported rates bitmap
2864 */
2865 supp = sta->supp_rates[sband->band];
2866 lq_sta->active_legacy_rate = 0;
2867 for_each_set_bit(i, &supp, BITS_PER_LONG)
2868 lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
2869
Ben Cahill77626352007-11-29 11:09:44 +08002870 /*
2871 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2872 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2873 */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002874 lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
2875 lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002876 lq_sta->active_siso_rate &= ~((u16)0x2);
2877 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07002878
Ben Cahill77626352007-11-29 11:09:44 +08002879 /* Same here */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002880 lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
2881 lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002882 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2883 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2884
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002885 lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
2886 lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002887 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2888 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2889
Tomas Winklere1623442009-01-27 14:27:56 -08002890 IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002891 lq_sta->active_siso_rate,
Guy Cohenfde0db32008-04-21 15:42:01 -07002892 lq_sta->active_mimo2_rate,
2893 lq_sta->active_mimo3_rate);
2894
Tomas Winklera96a27f2008-10-23 23:48:56 -07002895 /* These values will be overridden later */
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002896 lq_sta->lq.general_params.single_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002897 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002898 lq_sta->lq.general_params.dual_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002899 priv->nvm_data->valid_tx_ant &
2900 ~first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002901 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2902 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002903 } else if (num_of_ant(priv->nvm_data->valid_tx_ant) == 2) {
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002904 lq_sta->lq.general_params.dual_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002905 priv->nvm_data->valid_tx_ant;
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002906 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002907
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002908 /* as default allow aggregation for all tids */
2909 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002910 lq_sta->drv = priv;
Zhu Yib481de92007-09-25 17:54:57 -07002911
Daniel C Halperin50273092009-08-28 09:44:45 -07002912 /* Set last_txrate_idx to lowest rate */
2913 lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
2914 if (sband->band == IEEE80211_BAND_5GHZ)
2915 lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
Daniel C Halperine3949d62009-09-17 10:43:50 -07002916 lq_sta->is_agg = 0;
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -08002917#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
Wey-Yi Guy4e308112011-07-08 08:46:28 -07002918 priv->tm_fixed_rate = 0;
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -07002919#endif
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002920#ifdef CONFIG_MAC80211_DEBUGFS
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002921 lq_sta->dbg_fixed_rate = 0;
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002922#endif
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002923
Johannes Berg9b6ca442012-03-07 09:52:11 -08002924 rs_initialize_lq(priv, sta, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002925}
2926
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002927static void rs_fill_link_cmd(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08002928 struct iwl_lq_sta *lq_sta, u32 new_rate)
Zhu Yib481de92007-09-25 17:54:57 -07002929{
Tomas Winklere227cea2008-07-18 13:53:05 +08002930 struct iwl_scale_tbl_info tbl_type;
Zhu Yib481de92007-09-25 17:54:57 -07002931 int index = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002932 int rate_idx;
Zhu Yi1b696de2007-09-27 11:27:41 +08002933 int repeat_rate = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07002934 u8 ant_toggle_cnt = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002935 u8 use_ht_possible = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07002936 u8 valid_tx_ant = 0;
Johannes Berg7b090682011-01-19 02:53:54 -08002937 struct iwl_station_priv *sta_priv =
2938 container_of(lq_sta, struct iwl_station_priv, lq_sta);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002939 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
Zhu Yib481de92007-09-25 17:54:57 -07002940
Ben Cahill77626352007-11-29 11:09:44 +08002941 /* Override starting rate (index 0) if needed for debug purposes */
Guy Cohen39e88502008-04-23 17:14:57 -07002942 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Zhu Yi98d7e092007-09-27 11:27:42 +08002943
Guy Cohen39e88502008-04-23 17:14:57 -07002944 /* Interpret new_rate (rate_n_flags) */
2945 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
Zhu Yib481de92007-09-25 17:54:57 -07002946 &tbl_type, &rate_idx);
2947
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002948 if (priv && priv->bt_full_concurrent) {
2949 /* 1x1 only */
2950 tbl_type.ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002951 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002952 }
2953
Ben Cahill77626352007-11-29 11:09:44 +08002954 /* How many times should we repeat the initial rate? */
Zhu Yib481de92007-09-25 17:54:57 -07002955 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002956 ant_toggle_cnt = 1;
Zhu Yi1b696de2007-09-27 11:27:41 +08002957 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07002958 } else {
Daniel Halperin374920c2011-03-16 19:16:36 -07002959 repeat_rate = min(IWL_HT_NUMBER_TRY,
2960 LINK_QUAL_AGG_DISABLE_START_DEF - 1);
Guy Cohenaade00c2008-04-23 17:14:59 -07002961 }
Zhu Yib481de92007-09-25 17:54:57 -07002962
2963 lq_cmd->general_params.mimo_delimiter =
2964 is_mimo(tbl_type.lq_type) ? 1 : 0;
Ben Cahill77626352007-11-29 11:09:44 +08002965
2966 /* Fill 1st table entry (index 0) */
Guy Cohen39e88502008-04-23 17:14:57 -07002967 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002968
Guy Cohen07bc28e2008-04-23 17:15:03 -07002969 if (num_of_ant(tbl_type.ant_type) == 1) {
2970 lq_cmd->general_params.single_stream_ant_msk =
2971 tbl_type.ant_type;
2972 } else if (num_of_ant(tbl_type.ant_type) == 2) {
2973 lq_cmd->general_params.dual_stream_ant_msk =
2974 tbl_type.ant_type;
2975 } /* otherwise we don't modify the existing value */
Zhu Yib481de92007-09-25 17:54:57 -07002976
2977 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08002978 repeat_rate--;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002979 if (priv) {
2980 if (priv->bt_full_concurrent)
2981 valid_tx_ant = ANT_A;
2982 else
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002983 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002984 }
Guy Cohenaade00c2008-04-23 17:14:59 -07002985
Ben Cahill77626352007-11-29 11:09:44 +08002986 /* Fill rest of rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002987 while (index < LINK_QUAL_MAX_RETRY_NUM) {
Ben Cahill77626352007-11-29 11:09:44 +08002988 /* Repeat initial/next rate.
2989 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2990 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
Zhu Yi1b696de2007-09-27 11:27:41 +08002991 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
Zhu Yib481de92007-09-25 17:54:57 -07002992 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002993 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2994 ant_toggle_cnt++;
2995 else if (priv &&
2996 rs_toggle_antenna(valid_tx_ant,
2997 &new_rate, &tbl_type))
2998 ant_toggle_cnt = 1;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002999 }
Zhu Yi98d7e092007-09-27 11:27:42 +08003000
Ben Cahill77626352007-11-29 11:09:44 +08003001 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08003002 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08003003
3004 /* Fill next table entry */
Zhu Yib481de92007-09-25 17:54:57 -07003005 lq_cmd->rs_table[index].rate_n_flags =
Guy Cohen39e88502008-04-23 17:14:57 -07003006 cpu_to_le32(new_rate);
Zhu Yi1b696de2007-09-27 11:27:41 +08003007 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07003008 index++;
3009 }
3010
Guy Cohen39e88502008-04-23 17:14:57 -07003011 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
Zhu Yib481de92007-09-25 17:54:57 -07003012 &rate_idx);
3013
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003014 if (priv && priv->bt_full_concurrent) {
3015 /* 1x1 only */
3016 tbl_type.ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02003017 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003018 }
3019
Ben Cahill77626352007-11-29 11:09:44 +08003020 /* Indicate to uCode which entries might be MIMO.
3021 * If initial rate was MIMO, this will finally end up
3022 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
Zhu Yib481de92007-09-25 17:54:57 -07003023 if (is_mimo(tbl_type.lq_type))
3024 lq_cmd->general_params.mimo_delimiter = index;
3025
Ben Cahill77626352007-11-29 11:09:44 +08003026 /* Get next rate */
Guy Cohen39e88502008-04-23 17:14:57 -07003027 new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
3028 use_ht_possible);
Zhu Yib481de92007-09-25 17:54:57 -07003029
Ben Cahill77626352007-11-29 11:09:44 +08003030 /* How many times should we repeat the next rate? */
Zhu Yib481de92007-09-25 17:54:57 -07003031 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07003032 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
3033 ant_toggle_cnt++;
3034 else if (priv &&
3035 rs_toggle_antenna(valid_tx_ant,
3036 &new_rate, &tbl_type))
3037 ant_toggle_cnt = 1;
3038
Zhu Yi1b696de2007-09-27 11:27:41 +08003039 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003040 } else {
Zhu Yi1b696de2007-09-27 11:27:41 +08003041 repeat_rate = IWL_HT_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003042 }
Zhu Yib481de92007-09-25 17:54:57 -07003043
Ben Cahill77626352007-11-29 11:09:44 +08003044 /* Don't allow HT rates after next pass.
3045 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
Zhu Yib481de92007-09-25 17:54:57 -07003046 use_ht_possible = 0;
3047
Ben Cahill77626352007-11-29 11:09:44 +08003048 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08003049 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08003050
3051 /* Fill next table entry */
Guy Cohen39e88502008-04-23 17:14:57 -07003052 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07003053
3054 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08003055 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07003056 }
3057
Johannes Berg7b090682011-01-19 02:53:54 -08003058 lq_cmd->agg_params.agg_frame_cnt_limit =
3059 sta_priv->max_agg_bufsize ?: LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003060 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
Wey-Yi Guy74697012010-07-28 09:18:54 -07003061
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003062 lq_cmd->agg_params.agg_time_limit =
3063 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
Wey-Yi Guy74697012010-07-28 09:18:54 -07003064 /*
3065 * overwrite if needed, pass aggregation time limit
3066 * to uCode in uSec
3067 */
Emmanuel Grumbach21522682012-03-22 17:51:44 +02003068 if (priv && priv->cfg->bt_params &&
3069 priv->cfg->bt_params->agg_time_limit &&
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08003070 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
Wey-Yi Guy74697012010-07-28 09:18:54 -07003071 lq_cmd->agg_params.agg_time_limit =
Emmanuel Grumbach21522682012-03-22 17:51:44 +02003072 cpu_to_le16(priv->cfg->bt_params->agg_time_limit);
Zhu Yib481de92007-09-25 17:54:57 -07003073}
3074
Johannes Berg4b7679a2008-09-18 18:14:18 +02003075static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Zhu Yib481de92007-09-25 17:54:57 -07003076{
Johannes Berg4b7679a2008-09-18 18:14:18 +02003077 return hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003078}
3079/* rate scale requires free function to be implemented */
3080static void rs_free(void *priv_rate)
3081{
3082 return;
3083}
3084
Johannes Berg4b7679a2008-09-18 18:14:18 +02003085static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
3086 void *priv_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003087{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02003088 struct iwl_op_mode *op_mode __maybe_unused = priv_r;
3089 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003090
Tomas Winklere1623442009-01-27 14:27:56 -08003091 IWL_DEBUG_RATE(priv, "enter\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003092 IWL_DEBUG_RATE(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003093}
3094
Zhu Yi93dc6462007-09-27 11:27:37 +08003095#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklere227cea2008-07-18 13:53:05 +08003096static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
3097 u32 *rate_n_flags, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +08003098{
Ester Kummerbf403db2008-05-05 10:22:40 +08003099 struct iwl_priv *priv;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003100 u8 valid_tx_ant;
3101 u8 ant_sel_tx;
Ester Kummerbf403db2008-05-05 10:22:40 +08003102
3103 priv = lq_sta->drv;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02003104 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Guy Cohen39e88502008-04-23 17:14:57 -07003105 if (lq_sta->dbg_fixed_rate) {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003106 ant_sel_tx =
3107 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
3108 >> RATE_MCS_ANT_POS);
3109 if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
Guy Cohen39e88502008-04-23 17:14:57 -07003110 *rate_n_flags = lq_sta->dbg_fixed_rate;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003111 IWL_DEBUG_RATE(priv, "Fixed rate ON\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003112 } else {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003113 lq_sta->dbg_fixed_rate = 0;
3114 IWL_ERR(priv,
3115 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
3116 ant_sel_tx, valid_tx_ant);
3117 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003118 }
Guy Cohen39e88502008-04-23 17:14:57 -07003119 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08003120 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Zhu Yi98d7e092007-09-27 11:27:42 +08003121 }
Zhu Yi98d7e092007-09-27 11:27:42 +08003122}
3123
3124static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
3125 const char __user *user_buf, size_t count, loff_t *ppos)
3126{
Tomas Winklere227cea2008-07-18 13:53:05 +08003127 struct iwl_lq_sta *lq_sta = file->private_data;
Ester Kummerbf403db2008-05-05 10:22:40 +08003128 struct iwl_priv *priv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003129 char buf[64];
Stephen Boyd805d7d22011-05-12 16:50:05 -07003130 size_t buf_size;
Zhu Yi98d7e092007-09-27 11:27:42 +08003131 u32 parsed_rate;
Wey-Yi Guy64898542011-05-03 18:05:13 -07003132
Zhu Yi98d7e092007-09-27 11:27:42 +08003133
Ester Kummerbf403db2008-05-05 10:22:40 +08003134 priv = lq_sta->drv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003135 memset(buf, 0, sizeof(buf));
3136 buf_size = min(count, sizeof(buf) - 1);
3137 if (copy_from_user(buf, user_buf, buf_size))
3138 return -EFAULT;
3139
3140 if (sscanf(buf, "%x", &parsed_rate) == 1)
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003141 lq_sta->dbg_fixed_rate = parsed_rate;
Zhu Yi98d7e092007-09-27 11:27:42 +08003142 else
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003143 lq_sta->dbg_fixed_rate = 0;
Zhu Yi98d7e092007-09-27 11:27:42 +08003144
Wey-Yi Guy64898542011-05-03 18:05:13 -07003145 rs_program_fix_rate(priv, lq_sta);
Zhu Yi98d7e092007-09-27 11:27:42 +08003146
3147 return count;
3148}
Zhu Yi0209dc12007-09-27 11:27:43 +08003149
Zhu Yi5ae212c2007-09-27 11:27:38 +08003150static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
3151 char __user *user_buf, size_t count, loff_t *ppos)
3152{
Frank Seidela412c802009-03-01 20:25:38 +01003153 char *buff;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003154 int desc = 0;
3155 int i = 0;
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003156 int index = 0;
Frank Seidela412c802009-03-01 20:25:38 +01003157 ssize_t ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003158
Tomas Winklere227cea2008-07-18 13:53:05 +08003159 struct iwl_lq_sta *lq_sta = file->private_data;
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003160 struct iwl_priv *priv;
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003161 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003162
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003163 priv = lq_sta->drv;
Frank Seidela412c802009-03-01 20:25:38 +01003164 buff = kmalloc(1024, GFP_KERNEL);
3165 if (!buff)
3166 return -ENOMEM;
3167
Tomas Winklerc33104f2008-01-14 17:46:21 -08003168 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
Zhu Yi98d7e092007-09-27 11:27:42 +08003169 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003170 lq_sta->total_failed, lq_sta->total_success,
Guy Cohen39e88502008-04-23 17:14:57 -07003171 lq_sta->active_legacy_rate);
Zhu Yi98d7e092007-09-27 11:27:42 +08003172 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003173 lq_sta->dbg_fixed_rate);
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003174 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02003175 (priv->nvm_data->valid_tx_ant & ANT_A) ? "ANT_A," : "",
3176 (priv->nvm_data->valid_tx_ant & ANT_B) ? "ANT_B," : "",
3177 (priv->nvm_data->valid_tx_ant & ANT_C) ? "ANT_C" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003178 desc += sprintf(buff+desc, "lq type %s\n",
3179 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
3180 if (is_Ht(tbl->lq_type)) {
3181 desc += sprintf(buff+desc, " %s",
3182 (is_siso(tbl->lq_type)) ? "SISO" :
3183 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
3184 desc += sprintf(buff+desc, " %s",
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003185 (tbl->is_ht40) ? "40MHz" : "20MHz");
Daniel C Halperine3949d62009-09-17 10:43:50 -07003186 desc += sprintf(buff+desc, " %s %s %s\n", (tbl->is_SGI) ? "SGI" : "",
3187 (lq_sta->is_green) ? "GF enabled" : "",
3188 (lq_sta->is_agg) ? "AGG on" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003189 }
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003190 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
3191 lq_sta->last_rate_n_flags);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003192 desc += sprintf(buff+desc, "general:"
3193 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003194 lq_sta->lq.general_params.flags,
3195 lq_sta->lq.general_params.mimo_delimiter,
3196 lq_sta->lq.general_params.single_stream_ant_msk,
3197 lq_sta->lq.general_params.dual_stream_ant_msk);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003198
3199 desc += sprintf(buff+desc, "agg:"
3200 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003201 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
3202 lq_sta->lq.agg_params.agg_dis_start_th,
3203 lq_sta->lq.agg_params.agg_frame_cnt_limit);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003204
3205 desc += sprintf(buff+desc,
3206 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003207 lq_sta->lq.general_params.start_rate_index[0],
3208 lq_sta->lq.general_params.start_rate_index[1],
3209 lq_sta->lq.general_params.start_rate_index[2],
3210 lq_sta->lq.general_params.start_rate_index[3]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003211
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003212 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
3213 index = iwl_hwrate_to_plcp_idx(
3214 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
3215 if (is_legacy(tbl->lq_type)) {
3216 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
3217 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3218 iwl_rate_mcs[index].mbps);
3219 } else {
3220 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
3221 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3222 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
3223 }
3224 }
Zhu Yi5ae212c2007-09-27 11:27:38 +08003225
Frank Seidela412c802009-03-01 20:25:38 +01003226 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3227 kfree(buff);
3228 return ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003229}
3230
3231static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
Zhu Yi98d7e092007-09-27 11:27:42 +08003232 .write = rs_sta_dbgfs_scale_table_write,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003233 .read = rs_sta_dbgfs_scale_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003234 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003235 .llseek = default_llseek,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003236};
Zhu Yi0209dc12007-09-27 11:27:43 +08003237static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
3238 char __user *user_buf, size_t count, loff_t *ppos)
3239{
Frank Seidela412c802009-03-01 20:25:38 +01003240 char *buff;
Zhu Yi0209dc12007-09-27 11:27:43 +08003241 int desc = 0;
3242 int i, j;
Frank Seidela412c802009-03-01 20:25:38 +01003243 ssize_t ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003244
Tomas Winklere227cea2008-07-18 13:53:05 +08003245 struct iwl_lq_sta *lq_sta = file->private_data;
Frank Seidela412c802009-03-01 20:25:38 +01003246
3247 buff = kmalloc(1024, GFP_KERNEL);
3248 if (!buff)
3249 return -ENOMEM;
3250
Zhu Yi0209dc12007-09-27 11:27:43 +08003251 for (i = 0; i < LQ_SIZE; i++) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003252 desc += sprintf(buff+desc,
3253 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
Zhu Yi0209dc12007-09-27 11:27:43 +08003254 "rate=0x%X\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003255 lq_sta->active_tbl == i ? "*" : "x",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003256 lq_sta->lq_info[i].lq_type,
3257 lq_sta->lq_info[i].is_SGI,
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003258 lq_sta->lq_info[i].is_ht40,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003259 lq_sta->lq_info[i].is_dup,
Wey-Yi Guy2681b202009-05-21 13:44:22 -07003260 lq_sta->is_green,
Guy Cohen39e88502008-04-23 17:14:57 -07003261 lq_sta->lq_info[i].current_rate);
Zhu Yi0209dc12007-09-27 11:27:43 +08003262 for (j = 0; j < IWL_RATE_COUNT; j++) {
3263 desc += sprintf(buff+desc,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003264 "counter=%d success=%d %%=%d\n",
3265 lq_sta->lq_info[i].win[j].counter,
3266 lq_sta->lq_info[i].win[j].success_counter,
3267 lq_sta->lq_info[i].win[j].success_ratio);
Zhu Yi0209dc12007-09-27 11:27:43 +08003268 }
3269 }
Frank Seidela412c802009-03-01 20:25:38 +01003270 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3271 kfree(buff);
3272 return ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003273}
3274
3275static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
3276 .read = rs_sta_dbgfs_stats_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003277 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003278 .llseek = default_llseek,
Zhu Yi0209dc12007-09-27 11:27:43 +08003279};
Zhu Yi5ae212c2007-09-27 11:27:38 +08003280
Wey-Yi Guy38167452009-05-08 13:44:43 -07003281static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3282 char __user *user_buf, size_t count, loff_t *ppos)
3283{
Johannes Berg70817b52011-05-11 03:29:25 -07003284 struct iwl_lq_sta *lq_sta = file->private_data;
3285 struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
Wey-Yi Guy38167452009-05-08 13:44:43 -07003286 char buff[120];
3287 int desc = 0;
Wey-Yi Guy38167452009-05-08 13:44:43 -07003288
Wey-Yi Guy38167452009-05-08 13:44:43 -07003289 if (is_Ht(tbl->lq_type))
3290 desc += sprintf(buff+desc,
3291 "Bit Rate= %d Mb/s\n",
3292 tbl->expected_tpt[lq_sta->last_txrate_idx]);
3293 else
3294 desc += sprintf(buff+desc,
3295 "Bit Rate= %d Mb/s\n",
3296 iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003297
Johannes Berg08960de2011-04-05 09:41:53 -07003298 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003299}
3300
3301static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3302 .read = rs_sta_dbgfs_rate_scale_data_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003303 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003304 .llseek = default_llseek,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003305};
3306
Zhu Yi93dc6462007-09-27 11:27:37 +08003307static void rs_add_debugfs(void *priv, void *priv_sta,
3308 struct dentry *dir)
3309{
Tomas Winklere227cea2008-07-18 13:53:05 +08003310 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003311 lq_sta->rs_sta_dbgfs_scale_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003312 debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003313 lq_sta, &rs_sta_dbgfs_scale_table_ops);
3314 lq_sta->rs_sta_dbgfs_stats_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003315 debugfs_create_file("rate_stats_table", S_IRUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003316 lq_sta, &rs_sta_dbgfs_stats_table_ops);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003317 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003318 debugfs_create_file("rate_scale_data", S_IRUSR, dir,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003319 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003320 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003321 debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003322 &lq_sta->tx_agg_tid_en);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003323
Zhu Yi93dc6462007-09-27 11:27:37 +08003324}
3325
3326static void rs_remove_debugfs(void *priv, void *priv_sta)
3327{
Tomas Winklere227cea2008-07-18 13:53:05 +08003328 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003329 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
3330 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003331 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003332 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
Zhu Yi93dc6462007-09-27 11:27:37 +08003333}
3334#endif
3335
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003336/*
3337 * Initialization of rate scaling information is done by driver after
3338 * the station is added. Since mac80211 calls this function before a
3339 * station is added we ignore it.
3340 */
3341static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband,
3342 struct ieee80211_sta *sta, void *priv_sta)
3343{
3344}
Zhu Yib481de92007-09-25 17:54:57 -07003345static struct rate_control_ops rs_ops = {
3346 .module = NULL,
3347 .name = RS_NAME,
3348 .tx_status = rs_tx_status,
3349 .get_rate = rs_get_rate,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003350 .rate_init = rs_rate_init_stub,
Zhu Yib481de92007-09-25 17:54:57 -07003351 .alloc = rs_alloc,
3352 .free = rs_free,
3353 .alloc_sta = rs_alloc_sta,
3354 .free_sta = rs_free_sta,
Zhu Yi93dc6462007-09-27 11:27:37 +08003355#ifdef CONFIG_MAC80211_DEBUGFS
3356 .add_sta_debugfs = rs_add_debugfs,
3357 .remove_sta_debugfs = rs_remove_debugfs,
3358#endif
Zhu Yib481de92007-09-25 17:54:57 -07003359};
3360
Tomas Winklere227cea2008-07-18 13:53:05 +08003361int iwlagn_rate_control_register(void)
Zhu Yib481de92007-09-25 17:54:57 -07003362{
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003363 return ieee80211_rate_control_register(&rs_ops);
Zhu Yib481de92007-09-25 17:54:57 -07003364}
3365
Tomas Winklere227cea2008-07-18 13:53:05 +08003366void iwlagn_rate_control_unregister(void)
Zhu Yib481de92007-09-25 17:54:57 -07003367{
3368 ieee80211_rate_control_unregister(&rs_ops);
3369}
3370