blob: 496deac6e371895b8aea8a055ba42e3a71dec968 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02003 * Copyright(c) 2005 - 2014 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 Guy64898542011-05-03 18:05:13 -0700354 IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700355 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700356
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700357 if (lq_sta->dbg_fixed_rate) {
358 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700359 iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
360 false);
361 }
362}
363#endif
364
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200365/*
366 get the traffic load value for tid
367*/
Tomas Winklere227cea2008-07-18 13:53:05 +0800368static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200369{
370 u32 curr_time = jiffies_to_msecs(jiffies);
371 u32 time_diff;
372 s32 index;
Tomas Winklere227cea2008-07-18 13:53:05 +0800373 struct iwl_traffic_load *tl = NULL;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200374
Johannes Berga8448552011-12-02 12:25:12 -0800375 if (tid >= IWL_MAX_TID_COUNT)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200376 return 0;
377
378 tl = &(lq_data->load[tid]);
379
380 curr_time -= curr_time % TID_ROUND_VALUE;
381
382 if (!(tl->queue_count))
383 return 0;
384
385 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
386 index = time_diff / TID_QUEUE_CELL_SPACING;
387
388 /* The history is too long: remove data that is older than */
389 /* TID_MAX_TIME_DIFF */
390 if (index >= TID_QUEUE_MAX_SIZE)
391 rs_tl_rm_old_stats(tl, curr_time);
392
393 return tl->total;
394}
395
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700396static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +0800397 struct iwl_lq_sta *lq_data, u8 tid,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200398 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200399{
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700400 int ret = -EAGAIN;
Johannes Berg290f5992010-08-23 07:56:58 -0700401 u32 load;
402
403 /*
404 * Don't create TX aggregation sessions when in high
405 * BT traffic, as they would just be disrupted by BT.
406 */
407 if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) {
Johannes Berg6690c012013-01-28 09:58:31 +0100408 IWL_DEBUG_COEX(priv,
409 "BT traffic (%d), no aggregation allowed\n",
410 priv->bt_traffic_load);
Johannes Berg290f5992010-08-23 07:56:58 -0700411 return ret;
412 }
413
414 load = rs_tl_get_load(lq_data, tid);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800415
Emmanuel Grumbach44cc4292013-06-18 06:33:49 +0300416 IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n",
417 sta->addr, tid);
418 ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
419 if (ret == -EAGAIN) {
420 /*
421 * driver and mac80211 is out of sync
422 * this might be cause by reloading firmware
423 * stop the tx ba session here
424 */
425 IWL_ERR(priv, "Fail start Tx agg on tid: %d\n",
426 tid);
427 ieee80211_stop_tx_ba_session(sta, tid);
Andy Lutomirski24110542010-07-25 13:14:29 -0400428 }
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700429 return ret;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200430}
431
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700432static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
Tomas Winklere227cea2008-07-18 13:53:05 +0800433 struct iwl_lq_sta *lq_data,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200434 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200435{
Johannes Berga8448552011-12-02 12:25:12 -0800436 if (tid < IWL_MAX_TID_COUNT)
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -0700437 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
438 else
Johannes Berga8448552011-12-02 12:25:12 -0800439 IWL_ERR(priv, "tid exceeds max TID count: %d/%d\n",
440 tid, IWL_MAX_TID_COUNT);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200441}
442
Guy Cohen39e88502008-04-23 17:14:57 -0700443static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
Guy Cohenfde0db32008-04-21 15:42:01 -0700444{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300445 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
446 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
447 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
Guy Cohenfde0db32008-04-21 15:42:01 -0700448}
449
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700450/*
451 * Static function to get the expected throughput from an iwl_scale_tbl_info
452 * that wraps a NULL pointer check
453 */
454static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index)
455{
456 if (tbl->expected_tpt)
457 return tbl->expected_tpt[rs_index];
458 return 0;
459}
460
Ben Cahill77626352007-11-29 11:09:44 +0800461/**
462 * rs_collect_tx_data - Update the success/failure sliding window
463 *
464 * We keep a sliding window of the last 62 packets transmitted
465 * at this rate. window->data contains the bitmask of successful
466 * packets.
467 */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700468static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl,
469 int scale_index, int attempts, int successes)
Zhu Yib481de92007-09-25 17:54:57 -0700470{
Tomas Winklere227cea2008-07-18 13:53:05 +0800471 struct iwl_rate_scale_data *window = NULL;
Guy Cohen39e88502008-04-23 17:14:57 -0700472 static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700473 s32 fail_count, tpt;
Zhu Yib481de92007-09-25 17:54:57 -0700474
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800475 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
476 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700477
Daniel C Halperine3949d62009-09-17 10:43:50 -0700478 /* Select window for current tx bit rate */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700479 window = &(tbl->win[scale_index]);
480
481 /* Get expected throughput */
482 tpt = get_expected_tpt(tbl, scale_index);
Zhu Yib481de92007-09-25 17:54:57 -0700483
Ben Cahill77626352007-11-29 11:09:44 +0800484 /*
485 * Keep track of only the latest 62 tx frame attempts in this rate's
486 * history window; anything older isn't really relevant any more.
487 * If we have filled up the sliding window, drop the oldest attempt;
488 * if the oldest attempt (highest bit in bitmap) shows "success",
489 * subtract "1" from the success counter (this is the main reason
490 * we keep these bitmaps!).
491 */
Daniel C Halperine3949d62009-09-17 10:43:50 -0700492 while (attempts > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700493 if (window->counter >= IWL_RATE_MAX_WINDOW) {
494
495 /* remove earliest */
496 window->counter = IWL_RATE_MAX_WINDOW - 1;
497
Ron Rindjunsky99556432008-01-28 14:07:25 +0200498 if (window->data & mask) {
499 window->data &= ~mask;
Guy Cohen39e88502008-04-23 17:14:57 -0700500 window->success_counter--;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200501 }
Zhu Yib481de92007-09-25 17:54:57 -0700502 }
Zhu Yib481de92007-09-25 17:54:57 -0700503
Ron Rindjunsky99556432008-01-28 14:07:25 +0200504 /* Increment frames-attempted counter */
505 window->counter++;
Ben Cahill77626352007-11-29 11:09:44 +0800506
Daniel C Halperine3949d62009-09-17 10:43:50 -0700507 /* Shift bitmap by one frame to throw away oldest history */
Guy Cohen90d77952008-09-09 10:54:53 +0800508 window->data <<= 1;
Daniel C Halperine3949d62009-09-17 10:43:50 -0700509
510 /* Mark the most recent #successes attempts as successful */
Ron Rindjunsky99556432008-01-28 14:07:25 +0200511 if (successes > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700512 window->success_counter++;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200513 window->data |= 0x1;
514 successes--;
515 }
516
Daniel C Halperine3949d62009-09-17 10:43:50 -0700517 attempts--;
Zhu Yib481de92007-09-25 17:54:57 -0700518 }
519
Ben Cahill77626352007-11-29 11:09:44 +0800520 /* Calculate current success ratio, avoid divide-by-0! */
Zhu Yib481de92007-09-25 17:54:57 -0700521 if (window->counter > 0)
522 window->success_ratio = 128 * (100 * window->success_counter)
523 / window->counter;
524 else
525 window->success_ratio = IWL_INVALID_VALUE;
526
527 fail_count = window->counter - window->success_counter;
528
Ben Cahill77626352007-11-29 11:09:44 +0800529 /* Calculate average throughput, if we have enough history. */
Zhu Yib481de92007-09-25 17:54:57 -0700530 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
531 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
532 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
533 else
534 window->average_tpt = IWL_INVALID_VALUE;
535
Ben Cahill77626352007-11-29 11:09:44 +0800536 /* Tag this window as having been updated */
Zhu Yib481de92007-09-25 17:54:57 -0700537 window->stamp = jiffies;
538
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800539 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700540}
541
Ben Cahill77626352007-11-29 11:09:44 +0800542/*
543 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
544 */
Guy Cohen39e88502008-04-23 17:14:57 -0700545/* FIXME:RS:remove this function and put the flags statically in the table */
Tomas Winkler978785a2008-12-19 10:37:31 +0800546static u32 rate_n_flags_from_tbl(struct iwl_priv *priv,
547 struct iwl_scale_tbl_info *tbl,
548 int index, u8 use_green)
Zhu Yib481de92007-09-25 17:54:57 -0700549{
Guy Cohen39e88502008-04-23 17:14:57 -0700550 u32 rate_n_flags = 0;
551
Zhu Yib481de92007-09-25 17:54:57 -0700552 if (is_legacy(tbl->lq_type)) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800553 rate_n_flags = iwl_rates[index].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700554 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -0700555 rate_n_flags |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700556
Guy Cohenfde0db32008-04-21 15:42:01 -0700557 } else if (is_Ht(tbl->lq_type)) {
558 if (index > IWL_LAST_OFDM_RATE) {
Tomas Winkler978785a2008-12-19 10:37:31 +0800559 IWL_ERR(priv, "Invalid HT rate index %d\n", index);
Zhu Yib481de92007-09-25 17:54:57 -0700560 index = IWL_LAST_OFDM_RATE;
Guy Cohenfde0db32008-04-21 15:42:01 -0700561 }
Guy Cohen39e88502008-04-23 17:14:57 -0700562 rate_n_flags = RATE_MCS_HT_MSK;
Guy Cohenfde0db32008-04-21 15:42:01 -0700563
564 if (is_siso(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800565 rate_n_flags |= iwl_rates[index].plcp_siso;
Guy Cohenfde0db32008-04-21 15:42:01 -0700566 else if (is_mimo2(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800567 rate_n_flags |= iwl_rates[index].plcp_mimo2;
Guy Cohenfde0db32008-04-21 15:42:01 -0700568 else
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800569 rate_n_flags |= iwl_rates[index].plcp_mimo3;
Zhu Yib481de92007-09-25 17:54:57 -0700570 } else {
Tomas Winkler978785a2008-12-19 10:37:31 +0800571 IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700572 }
573
Guy Cohen39e88502008-04-23 17:14:57 -0700574 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
Guy Cohenfde0db32008-04-21 15:42:01 -0700575 RATE_MCS_ANT_ABC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700576
Guy Cohen39e88502008-04-23 17:14:57 -0700577 if (is_Ht(tbl->lq_type)) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700578 if (tbl->is_ht40) {
Guy Cohen39e88502008-04-23 17:14:57 -0700579 if (tbl->is_dup)
580 rate_n_flags |= RATE_MCS_DUP_MSK;
581 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700582 rate_n_flags |= RATE_MCS_HT40_MSK;
Guy Cohen39e88502008-04-23 17:14:57 -0700583 }
584 if (tbl->is_SGI)
585 rate_n_flags |= RATE_MCS_SGI_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700586
Guy Cohen39e88502008-04-23 17:14:57 -0700587 if (use_green) {
588 rate_n_flags |= RATE_MCS_GF_MSK;
589 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
590 rate_n_flags &= ~RATE_MCS_SGI_MSK;
Tomas Winkler978785a2008-12-19 10:37:31 +0800591 IWL_ERR(priv, "GF was set with SGI:SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -0700592 }
593 }
Zhu Yib481de92007-09-25 17:54:57 -0700594 }
Guy Cohen39e88502008-04-23 17:14:57 -0700595 return rate_n_flags;
Zhu Yib481de92007-09-25 17:54:57 -0700596}
597
Ben Cahill77626352007-11-29 11:09:44 +0800598/*
599 * Interpret uCode API's rate_n_flags format,
600 * fill "search" or "active" tx mode table.
601 */
Guy Cohen39e88502008-04-23 17:14:57 -0700602static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
Johannes Berg8318d782008-01-24 19:38:38 +0100603 enum ieee80211_band band,
Tomas Winklere227cea2008-07-18 13:53:05 +0800604 struct iwl_scale_tbl_info *tbl,
Zhu Yib481de92007-09-25 17:54:57 -0700605 int *rate_idx)
606{
Guy Cohen39e88502008-04-23 17:14:57 -0700607 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
608 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
609 u8 mcs;
Zhu Yib481de92007-09-25 17:54:57 -0700610
Wey-Yi Guy80e91582010-08-03 08:23:32 -0700611 memset(tbl, 0, sizeof(struct iwl_scale_tbl_info));
Tomas Winklere7d326ac2008-06-12 09:47:11 +0800612 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700613
Guy Cohenfde0db32008-04-21 15:42:01 -0700614 if (*rate_idx == IWL_RATE_INVALID) {
Zhu Yib481de92007-09-25 17:54:57 -0700615 *rate_idx = -1;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800616 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700617 }
Ben Cahill77626352007-11-29 11:09:44 +0800618 tbl->is_SGI = 0; /* default legacy setup */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700619 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700620 tbl->is_dup = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -0700621 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
622 tbl->lq_type = LQ_NONE;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700623 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700624
Ben Cahill77626352007-11-29 11:09:44 +0800625 /* legacy rate format */
Guy Cohen39e88502008-04-23 17:14:57 -0700626 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700627 if (num_of_ant == 1) {
Johannes Berg8318d782008-01-24 19:38:38 +0100628 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700629 tbl->lq_type = LQ_A;
630 else
631 tbl->lq_type = LQ_G;
Zhu Yib481de92007-09-25 17:54:57 -0700632 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700633 /* HT rate format */
Zhu Yib481de92007-09-25 17:54:57 -0700634 } else {
Guy Cohen39e88502008-04-23 17:14:57 -0700635 if (rate_n_flags & RATE_MCS_SGI_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700636 tbl->is_SGI = 1;
637
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700638 if ((rate_n_flags & RATE_MCS_HT40_MSK) ||
Guy Cohen39e88502008-04-23 17:14:57 -0700639 (rate_n_flags & RATE_MCS_DUP_MSK))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700640 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700641
Guy Cohen39e88502008-04-23 17:14:57 -0700642 if (rate_n_flags & RATE_MCS_DUP_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700643 tbl->is_dup = 1;
Guy Cohenfde0db32008-04-21 15:42:01 -0700644
Guy Cohen39e88502008-04-23 17:14:57 -0700645 mcs = rs_extract_rate(rate_n_flags);
Guy Cohenfde0db32008-04-21 15:42:01 -0700646
Guy Cohen39e88502008-04-23 17:14:57 -0700647 /* SISO */
648 if (mcs <= IWL_RATE_SISO_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700649 if (num_of_ant == 1)
650 tbl->lq_type = LQ_SISO; /*else NONE*/
651 /* MIMO2 */
Guy Cohen39e88502008-04-23 17:14:57 -0700652 } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700653 if (num_of_ant == 2)
654 tbl->lq_type = LQ_MIMO2;
655 /* MIMO3 */
656 } else {
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700657 if (num_of_ant == 3) {
658 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Guy Cohenfde0db32008-04-21 15:42:01 -0700659 tbl->lq_type = LQ_MIMO3;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700660 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700661 }
Zhu Yib481de92007-09-25 17:54:57 -0700662 }
663 return 0;
664}
Guy Cohenaade00c2008-04-23 17:14:59 -0700665
666/* switch to another antenna/antennas and return 1 */
667/* if no other valid antenna found, return 0 */
668static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
Tomas Winklere227cea2008-07-18 13:53:05 +0800669 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -0700670{
Guy Cohenaade00c2008-04-23 17:14:59 -0700671 u8 new_ant_type;
672
673 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
674 return 0;
675
676 if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
677 return 0;
678
679 new_ant_type = ant_toggle_lookup[tbl->ant_type];
680
681 while ((new_ant_type != tbl->ant_type) &&
682 !rs_is_valid_ant(valid_ant, new_ant_type))
683 new_ant_type = ant_toggle_lookup[new_ant_type];
684
685 if (new_ant_type == tbl->ant_type)
686 return 0;
687
688 tbl->ant_type = new_ant_type;
689 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
690 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
691 return 1;
Zhu Yib481de92007-09-25 17:54:57 -0700692}
693
Daniel C Halperinb2617932009-08-13 13:30:59 -0700694/**
695 * Green-field mode is valid if the station supports it and
696 * there are no non-GF stations present in the BSS.
697 */
Johannes Berg7e6a5882010-08-23 10:46:46 +0200698static bool rs_use_green(struct ieee80211_sta *sta)
Zhu Yib481de92007-09-25 17:54:57 -0700699{
Johannes Berg50e2a302012-08-05 18:31:46 +0200700 /*
701 * There's a bug somewhere in this code that causes the
702 * scaling to get stuck because GF+SGI can't be combined
703 * in SISO rates. Until we find that bug, disable GF, it
704 * has only limited benefit and we still interoperate with
705 * GF APs since we can always receive GF transmissions.
706 */
707 return false;
Guy Cohenf935a6d2008-04-23 17:15:02 -0700708}
Zhu Yib481de92007-09-25 17:54:57 -0700709
710/**
711 * rs_get_supported_rates - get the available rates
712 *
713 * if management frame or broadcast frame only return
714 * basic available rates.
715 *
716 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800717static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
718 struct ieee80211_hdr *hdr,
719 enum iwl_table_type rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700720{
Guy Coheneecd6e52008-04-23 17:14:58 -0700721 if (is_legacy(rate_type)) {
722 return lq_sta->active_legacy_rate;
723 } else {
724 if (is_siso(rate_type))
725 return lq_sta->active_siso_rate;
726 else if (is_mimo2(rate_type))
727 return lq_sta->active_mimo2_rate;
728 else
729 return lq_sta->active_mimo3_rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800730 }
Zhu Yib481de92007-09-25 17:54:57 -0700731}
732
Ester Kummerbf403db2008-05-05 10:22:40 +0800733static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
734 int rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700735{
736 u8 high = IWL_RATE_INVALID;
737 u8 low = IWL_RATE_INVALID;
738
Ian Schram01ebd062007-10-25 17:15:22 +0800739 /* 802.11A or ht walks to the next literal adjacent rate in
Zhu Yib481de92007-09-25 17:54:57 -0700740 * the rate table */
741 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
742 int i;
743 u32 mask;
744
745 /* Find the previous rate that is in the rate mask */
746 i = index - 1;
747 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
748 if (rate_mask & mask) {
749 low = i;
750 break;
751 }
752 }
753
754 /* Find the next rate that is in the rate mask */
755 i = index + 1;
756 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
757 if (rate_mask & mask) {
758 high = i;
759 break;
760 }
761 }
762
763 return (high << 8) | low;
764 }
765
766 low = index;
767 while (low != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800768 low = iwl_rates[low].prev_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700769 if (low == IWL_RATE_INVALID)
770 break;
771 if (rate_mask & (1 << low))
772 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800773 IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low);
Zhu Yib481de92007-09-25 17:54:57 -0700774 }
775
776 high = index;
777 while (high != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800778 high = iwl_rates[high].next_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700779 if (high == IWL_RATE_INVALID)
780 break;
781 if (rate_mask & (1 << high))
782 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800783 IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high);
Zhu Yib481de92007-09-25 17:54:57 -0700784 }
785
786 return (high << 8) | low;
787}
788
Tomas Winklere227cea2008-07-18 13:53:05 +0800789static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
790 struct iwl_scale_tbl_info *tbl,
791 u8 scale_index, u8 ht_possible)
Zhu Yib481de92007-09-25 17:54:57 -0700792{
Zhu Yib481de92007-09-25 17:54:57 -0700793 s32 low;
794 u16 rate_mask;
795 u16 high_low;
796 u8 switch_to_legacy = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800797 u8 is_green = lq_sta->is_green;
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700798 struct iwl_priv *priv = lq_sta->drv;
Zhu Yib481de92007-09-25 17:54:57 -0700799
800 /* check if we need to switch from HT to legacy rates.
801 * assumption is that mandatory rates (1Mbps or 6Mbps)
802 * are always supported (spec demand) */
803 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
804 switch_to_legacy = 1;
805 scale_index = rs_ht_to_legacy[scale_index];
Johannes Berg8318d782008-01-24 19:38:38 +0100806 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700807 tbl->lq_type = LQ_A;
808 else
809 tbl->lq_type = LQ_G;
810
Guy Cohen69fdb302008-04-23 17:15:01 -0700811 if (num_of_ant(tbl->ant_type) > 1)
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700812 tbl->ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200813 first_antenna(priv->nvm_data->valid_tx_ant);
Zhu Yib481de92007-09-25 17:54:57 -0700814
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700815 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700816 tbl->is_SGI = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700817 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700818 }
819
Guy Coheneecd6e52008-04-23 17:14:58 -0700820 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700821
Ben Cahill77626352007-11-29 11:09:44 +0800822 /* Mask with station rate restriction */
Zhu Yib481de92007-09-25 17:54:57 -0700823 if (is_legacy(tbl->lq_type)) {
Ben Cahill77626352007-11-29 11:09:44 +0800824 /* supp_rates has no CCK bits in A mode */
Johannes Berg8318d782008-01-24 19:38:38 +0100825 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700826 rate_mask = (u16)(rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -0800827 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -0700828 else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800829 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -0700830 }
831
Ben Cahill77626352007-11-29 11:09:44 +0800832 /* If we switched from HT to legacy, check current rate */
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800833 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
Guy Cohen39e88502008-04-23 17:14:57 -0700834 low = scale_index;
835 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700836 }
837
Ester Kummerbf403db2008-05-05 10:22:40 +0800838 high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
839 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700840 low = high_low & 0xff;
841
Guy Cohen39e88502008-04-23 17:14:57 -0700842 if (low == IWL_RATE_INVALID)
843 low = scale_index;
844
845out:
Tomas Winkler978785a2008-12-19 10:37:31 +0800846 return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
Zhu Yib481de92007-09-25 17:54:57 -0700847}
848
Ben Cahill77626352007-11-29 11:09:44 +0800849/*
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700850 * Simple function to compare two rate scale table types
851 */
852static bool table_type_matches(struct iwl_scale_tbl_info *a,
853 struct iwl_scale_tbl_info *b)
854{
855 return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) &&
856 (a->is_SGI == b->is_SGI);
857}
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700858
Johannes Berg7e6a5882010-08-23 10:46:46 +0200859static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
860 struct iwl_lq_sta *lq_sta)
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700861{
862 struct iwl_scale_tbl_info *tbl;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800863 bool full_concurrent = priv->bt_full_concurrent;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700864
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800865 if (priv->bt_ant_couple_ok) {
866 /*
867 * Is there a need to switch between
868 * full concurrency and 3-wire?
869 */
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800870 if (priv->bt_ci_compliance && priv->bt_ant_couple_ok)
871 full_concurrent = true;
872 else
873 full_concurrent = false;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800874 }
875 if ((priv->bt_traffic_load != priv->last_bt_traffic_load) ||
876 (priv->bt_full_concurrent != full_concurrent)) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700877 priv->bt_full_concurrent = full_concurrent;
Meenakshi Venkataraman882dde82012-05-16 22:35:57 +0200878 priv->last_bt_traffic_load = priv->bt_traffic_load;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700879
880 /* Update uCode's rate table. */
881 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
882 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +0200883 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700884
Johannes Berg1ee158d2012-02-17 10:07:44 -0800885 queue_work(priv->workqueue, &priv->bt_full_concurrency);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700886 }
887}
888
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700889/*
Ben Cahill77626352007-11-29 11:09:44 +0800890 * mac80211 sends us Tx status
891 */
Johannes Berg4b7679a2008-09-18 18:14:18 +0200892static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
893 struct ieee80211_sta *sta, void *priv_sta,
Johannes Berge039fa42008-05-15 12:55:29 +0200894 struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700895{
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700896 int legacy_success;
897 int retries;
898 int rs_index, mac_index, i;
Tomas Winkler417f1142008-11-12 13:14:06 -0800899 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winkler66c73db2008-04-15 16:01:40 -0700900 struct iwl_link_quality_cmd *table;
Zhu Yib481de92007-09-25 17:54:57 -0700901 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200902 struct iwl_op_mode *op_mode = (struct iwl_op_mode *)priv_r;
903 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge039fa42008-05-15 12:55:29 +0200904 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel C Halperin50273092009-08-28 09:44:45 -0700905 enum mac80211_rate_control_flags mac_flags;
Guy Cohen39e88502008-04-23 17:14:57 -0700906 u32 tx_rate;
Tomas Winklere227cea2008-07-18 13:53:05 +0800907 struct iwl_scale_tbl_info tbl_type;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700908 struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200909 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -0700910 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -0700911
Tomas Winklere1623442009-01-27 14:27:56 -0800912 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -0700913
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800914 /* Treat uninitialized rate scaling data same as non-existing. */
915 if (!lq_sta) {
916 IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n");
917 return;
918 } else if (!lq_sta->drv) {
919 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
920 return;
921 }
922
Tomas Winkler417f1142008-11-12 13:14:06 -0800923 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +0200924 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -0700925 return;
926
Daniel C Halperine3949d62009-09-17 10:43:50 -0700927 /* This packet was aggregated but doesn't carry status info */
Johannes Berge039fa42008-05-15 12:55:29 +0200928 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
929 !(info->flags & IEEE80211_TX_STAT_AMPDU))
Ron Rindjunsky99556432008-01-28 14:07:25 +0200930 return;
931
Ben Cahill77626352007-11-29 11:09:44 +0800932 /*
933 * Ignore this Tx frame response if its initial rate doesn't match
934 * that of latest Link Quality command. There may be stragglers
935 * from a previous Link Quality command, but we're no longer interested
936 * in those; they're either from the "active" mode while we're trying
937 * to check "search" mode, or a prior "search" mode after we've moved
938 * to a new "search" mode (which might become the new "active" mode).
939 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700940 table = &lq_sta->lq;
Guy Cohen39e88502008-04-23 17:14:57 -0700941 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
942 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800943 if (priv->band == IEEE80211_BAND_5GHZ)
944 rs_index -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin50273092009-08-28 09:44:45 -0700945 mac_flags = info->status.rates[0].flags;
946 mac_index = info->status.rates[0].idx;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700947 /* For HT packets, map MCS to PLCP */
948 if (mac_flags & IEEE80211_TX_RC_MCS) {
949 mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */
950 if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
951 mac_index++;
Daniel C Halperin392a0ba2009-09-11 10:38:08 -0700952 /*
953 * mac80211 HT index is always zero-indexed; we need to move
954 * HT OFDM rates after CCK rates in 2.4 GHz band
955 */
956 if (priv->band == IEEE80211_BAND_2GHZ)
957 mac_index += IWL_FIRST_OFDM_RATE;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700958 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700959 /* Here we actually compare this rate to the latest LQ command */
Daniel C Halperin50273092009-08-28 09:44:45 -0700960 if ((mac_index < 0) ||
961 (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
962 (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
963 (tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) ||
Johannes Bergd748b462012-03-28 11:04:23 +0200964 (tbl_type.ant_type != info->status.antenna) ||
Daniel C Halperin50273092009-08-28 09:44:45 -0700965 (!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
966 (!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
Daniel C Halperin31513be2009-08-28 09:44:47 -0700967 (rs_index != mac_index)) {
968 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 -0700969 /*
970 * Since rates mis-match, the last LQ command may have failed.
971 * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with
972 * ... driver.
Mohamed Abbasd5e49032008-12-12 08:22:15 -0800973 */
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800974 lq_sta->missed_rate_counter++;
975 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
976 lq_sta->missed_rate_counter = 0;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200977 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800978 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700979 /* Regardless, ignore this status info for outdated rate */
980 return;
981 } else
982 /* Rate did match, so reset the missed_rate_counter */
983 lq_sta->missed_rate_counter = 0;
984
985 /* Figure out if rate scale algorithm is in active or search table */
986 if (table_type_matches(&tbl_type,
987 &(lq_sta->lq_info[lq_sta->active_tbl]))) {
988 curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
989 other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
990 } else if (table_type_matches(&tbl_type,
991 &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
992 curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
993 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
994 } else {
995 IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n");
Wey-Yi Guy80e91582010-08-03 08:23:32 -0700996 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
997 IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n",
998 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
999 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1000 IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n",
1001 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
1002 IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n",
1003 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
1004 /*
1005 * no matching table found, let's by-pass the data collection
1006 * and continue to perform rate scale to find the rate table
1007 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001008 rs_stay_in_table(lq_sta, true);
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001009 goto done;
Zhu Yib481de92007-09-25 17:54:57 -07001010 }
Zhu Yib481de92007-09-25 17:54:57 -07001011
Ben Cahill77626352007-11-29 11:09:44 +08001012 /*
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001013 * Updating the frame history depends on whether packets were
1014 * aggregated.
1015 *
1016 * For aggregation, all packets were transmitted at the same rate, the
1017 * first index into rate scale table.
Ben Cahill77626352007-11-29 11:09:44 +08001018 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001019 if (info->flags & IEEE80211_TX_STAT_AMPDU) {
1020 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
1021 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type,
1022 &rs_index);
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001023 rs_collect_tx_data(curr_tbl, rs_index,
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001024 info->status.ampdu_len,
1025 info->status.ampdu_ack_len);
Zhu Yib481de92007-09-25 17:54:57 -07001026
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001027 /* Update success/fail counts if not searching for new mode */
1028 if (lq_sta->stay_in_tbl) {
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001029 lq_sta->total_success += info->status.ampdu_ack_len;
1030 lq_sta->total_failed += (info->status.ampdu_len -
1031 info->status.ampdu_ack_len);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001032 }
1033 } else {
1034 /*
1035 * For legacy, update frame history with for each Tx retry.
1036 */
1037 retries = info->status.rates[0].count - 1;
1038 /* HW doesn't send more than 15 retries */
1039 retries = min(retries, 15);
1040
1041 /* The last transmission may have been successful */
1042 legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
1043 /* Collect data for each rate used during failed TX attempts */
1044 for (i = 0; i <= retries; ++i) {
1045 tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
1046 rs_get_tbl_info_from_mcs(tx_rate, priv->band,
1047 &tbl_type, &rs_index);
1048 /*
1049 * Only collect stats if retried rate is in the same RS
1050 * table as active/search.
1051 */
1052 if (table_type_matches(&tbl_type, curr_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001053 tmp_tbl = curr_tbl;
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001054 else if (table_type_matches(&tbl_type, other_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001055 tmp_tbl = other_tbl;
Ron Rindjunsky99556432008-01-28 14:07:25 +02001056 else
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001057 continue;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001058 rs_collect_tx_data(tmp_tbl, rs_index, 1,
1059 i < retries ? 0 : legacy_success);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001060 }
1061
1062 /* Update success/fail counts if not searching for new mode */
1063 if (lq_sta->stay_in_tbl) {
1064 lq_sta->total_success += legacy_success;
1065 lq_sta->total_failed += retries + (1 - legacy_success);
Ron Rindjunsky99556432008-01-28 14:07:25 +02001066 }
Zhu Yib481de92007-09-25 17:54:57 -07001067 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001068 /* The last TX rate is cached in lq_sta; it's set in if/else above */
1069 lq_sta->last_rate_n_flags = tx_rate;
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001070done:
Ben Cahill77626352007-11-29 11:09:44 +08001071 /* See if there's a better rate or modulation mode to try. */
Abbas, Mohamedc338ba32009-01-21 10:58:02 -08001072 if (sta && sta->supp_rates[sband->band])
Gábor Stefanik514d65c2009-04-23 19:36:08 +02001073 rs_rate_scale_perform(priv, skb, sta, lq_sta);
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -07001074
Johannes Berg0d8877a2013-05-17 10:36:29 +02001075 if (priv->lib->bt_params && priv->lib->bt_params->advanced_bt_coexist)
Johannes Berg7e6a5882010-08-23 10:46:46 +02001076 rs_bt_update_lq(priv, ctx, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001077}
1078
Ben Cahill77626352007-11-29 11:09:44 +08001079/*
1080 * Begin a period of staying with a selected modulation mode.
1081 * Set "stay_in_tbl" flag to prevent any mode switches.
1082 * Set frame tx success limits according to legacy vs. high-throughput,
1083 * and reset overall (spanning all rates) tx success history statistics.
1084 * These control how long we stay using same modulation mode before
1085 * searching for a new mode.
1086 */
Ester Kummerbf403db2008-05-05 10:22:40 +08001087static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
Tomas Winklere227cea2008-07-18 13:53:05 +08001088 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07001089{
Tomas Winklere1623442009-01-27 14:27:56 -08001090 IWL_DEBUG_RATE(priv, "we are staying in the same table\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -08001091 lq_sta->stay_in_tbl = 1; /* only place this gets set */
Zhu Yib481de92007-09-25 17:54:57 -07001092 if (is_legacy) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001093 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
1094 lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
1095 lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001096 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001097 lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
1098 lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
1099 lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001100 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001101 lq_sta->table_count = 0;
1102 lq_sta->total_failed = 0;
1103 lq_sta->total_success = 0;
Mohamed Abbas447fee72009-04-20 14:37:02 -07001104 lq_sta->flush_timer = jiffies;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001105 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001106}
1107
Ben Cahill77626352007-11-29 11:09:44 +08001108/*
1109 * Find correct throughput table for given mode of modulation
1110 */
Tomas Winklere227cea2008-07-18 13:53:05 +08001111static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1112 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -07001113{
Daniel C Halperine3949d62009-09-17 10:43:50 -07001114 /* Used to choose among HT tables */
1115 s32 (*ht_tbl_pointer)[IWL_RATE_COUNT];
1116
1117 /* Check for invalid LQ type */
1118 if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
1119 tbl->expected_tpt = expected_tpt_legacy;
1120 return;
1121 }
1122
1123 /* Legacy rates have only one table */
Zhu Yib481de92007-09-25 17:54:57 -07001124 if (is_legacy(tbl->lq_type)) {
Daniel C Halperine3949d62009-09-17 10:43:50 -07001125 tbl->expected_tpt = expected_tpt_legacy;
1126 return;
1127 }
1128
1129 /* Choose among many HT tables depending on number of streams
1130 * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation
1131 * status */
1132 if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1133 ht_tbl_pointer = expected_tpt_siso20MHz;
1134 else if (is_siso(tbl->lq_type))
1135 ht_tbl_pointer = expected_tpt_siso40MHz;
1136 else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1137 ht_tbl_pointer = expected_tpt_mimo2_20MHz;
1138 else if (is_mimo2(tbl->lq_type))
1139 ht_tbl_pointer = expected_tpt_mimo2_40MHz;
1140 else if (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1141 ht_tbl_pointer = expected_tpt_mimo3_20MHz;
1142 else /* if (is_mimo3(tbl->lq_type)) <-- must be true */
1143 ht_tbl_pointer = expected_tpt_mimo3_40MHz;
1144
1145 if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
1146 tbl->expected_tpt = ht_tbl_pointer[0];
1147 else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
1148 tbl->expected_tpt = ht_tbl_pointer[1];
1149 else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
1150 tbl->expected_tpt = ht_tbl_pointer[2];
1151 else /* AGG+SGI */
1152 tbl->expected_tpt = ht_tbl_pointer[3];
Zhu Yib481de92007-09-25 17:54:57 -07001153}
1154
Ben Cahill77626352007-11-29 11:09:44 +08001155/*
1156 * Find starting rate for new "search" high-throughput mode of modulation.
1157 * Goal is to find lowest expected rate (under perfect conditions) that is
1158 * above the current measured throughput of "active" mode, to give new mode
1159 * a fair chance to prove itself without too many challenges.
1160 *
1161 * This gets called when transitioning to more aggressive modulation
1162 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1163 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1164 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1165 * bit rate will typically need to increase, but not if performance was bad.
1166 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001167static s32 rs_get_best_rate(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001168 struct iwl_lq_sta *lq_sta,
1169 struct iwl_scale_tbl_info *tbl, /* "search" */
Guy Cohenf935a6d2008-04-23 17:15:02 -07001170 u16 rate_mask, s8 index)
Zhu Yib481de92007-09-25 17:54:57 -07001171{
Ben Cahill77626352007-11-29 11:09:44 +08001172 /* "active" values */
Tomas Winklere227cea2008-07-18 13:53:05 +08001173 struct iwl_scale_tbl_info *active_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001174 &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001175 s32 active_sr = active_tbl->win[index].success_ratio;
Zhu Yib481de92007-09-25 17:54:57 -07001176 s32 active_tpt = active_tbl->expected_tpt[index];
Ben Cahill77626352007-11-29 11:09:44 +08001177
1178 /* expected "search" throughput */
1179 s32 *tpt_tbl = tbl->expected_tpt;
1180
1181 s32 new_rate, high, low, start_hi;
Zhu Yib481de92007-09-25 17:54:57 -07001182 u16 high_low;
Guy Cohenf935a6d2008-04-23 17:15:02 -07001183 s8 rate = index;
Zhu Yib481de92007-09-25 17:54:57 -07001184
1185 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1186
1187 for (; ;) {
Ester Kummerbf403db2008-05-05 10:22:40 +08001188 high_low = rs_get_adjacent_rate(priv, rate, rate_mask,
1189 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07001190
1191 low = high_low & 0xff;
1192 high = (high_low >> 8) & 0xff;
1193
Ben Cahill77626352007-11-29 11:09:44 +08001194 /*
1195 * Lower the "search" bit rate, to give new "search" mode
1196 * approximately the same throughput as "active" if:
1197 *
1198 * 1) "Active" mode has been working modestly well (but not
1199 * great), and expected "search" throughput (under perfect
1200 * conditions) at candidate rate is above the actual
1201 * measured "active" throughput (but less than expected
1202 * "active" throughput under perfect conditions).
1203 * OR
1204 * 2) "Active" mode has been working perfectly or very well
1205 * and expected "search" throughput (under perfect
1206 * conditions) at candidate rate is above expected
1207 * "active" throughput (under perfect conditions).
1208 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001209 if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
Zhu Yib481de92007-09-25 17:54:57 -07001210 ((active_sr > IWL_RATE_DECREASE_TH) &&
1211 (active_sr <= IWL_RATE_HIGH_TH) &&
1212 (tpt_tbl[rate] <= active_tpt))) ||
1213 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
1214 (tpt_tbl[rate] > active_tpt))) {
1215
Ben Cahill77626352007-11-29 11:09:44 +08001216 /* (2nd or later pass)
1217 * If we've already tried to raise the rate, and are
1218 * now trying to lower it, use the higher rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001219 if (start_hi != IWL_RATE_INVALID) {
1220 new_rate = start_hi;
1221 break;
1222 }
Ben Cahill77626352007-11-29 11:09:44 +08001223
Zhu Yib481de92007-09-25 17:54:57 -07001224 new_rate = rate;
Ben Cahill77626352007-11-29 11:09:44 +08001225
1226 /* Loop again with lower rate */
Zhu Yib481de92007-09-25 17:54:57 -07001227 if (low != IWL_RATE_INVALID)
1228 rate = low;
Ben Cahill77626352007-11-29 11:09:44 +08001229
1230 /* Lower rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001231 else
1232 break;
Ben Cahill77626352007-11-29 11:09:44 +08001233
1234 /* Else try to raise the "search" rate to match "active" */
Zhu Yib481de92007-09-25 17:54:57 -07001235 } else {
Ben Cahill77626352007-11-29 11:09:44 +08001236 /* (2nd or later pass)
1237 * If we've already tried to lower the rate, and are
1238 * now trying to raise it, use the lower rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001239 if (new_rate != IWL_RATE_INVALID)
1240 break;
Ben Cahill77626352007-11-29 11:09:44 +08001241
1242 /* Loop again with higher rate */
Zhu Yib481de92007-09-25 17:54:57 -07001243 else if (high != IWL_RATE_INVALID) {
1244 start_hi = high;
1245 rate = high;
Ben Cahill77626352007-11-29 11:09:44 +08001246
1247 /* Higher rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001248 } else {
Guy Cohen90d77952008-09-09 10:54:53 +08001249 new_rate = rate;
Zhu Yib481de92007-09-25 17:54:57 -07001250 break;
1251 }
1252 }
1253 }
1254
1255 return new_rate;
1256}
Zhu Yib481de92007-09-25 17:54:57 -07001257
Ben Cahill77626352007-11-29 11:09:44 +08001258/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001259 * Set up search table for MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001260 */
Guy Cohenfde0db32008-04-21 15:42:01 -07001261static int rs_switch_to_mimo2(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001262 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001263 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001264 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001265 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001266{
Zhu Yib481de92007-09-25 17:54:57 -07001267 u16 rate_mask;
1268 s32 rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001269 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001270 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001271 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001272
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001273 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001274 return -1;
1275
Johannes Bergaf0ed692013-02-12 14:21:00 +01001276 if (sta->smps_mode == IEEE80211_SMPS_STATIC)
Zhu Yib481de92007-09-25 17:54:57 -07001277 return -1;
1278
Ben Cahill77626352007-11-29 11:09:44 +08001279 /* Need both Tx chains/antennas to support MIMO */
Johannes Berg9e295112012-04-09 17:46:55 -07001280 if (priv->hw_params.tx_chains_num < 2)
Zhu Yib481de92007-09-25 17:54:57 -07001281 return -1;
1282
Tomas Winklere1623442009-01-27 14:27:56 -08001283 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001284
1285 tbl->lq_type = LQ_MIMO2;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001286 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001287 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001288 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001289 rate_mask = lq_sta->active_mimo2_rate;
1290
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001291 if (iwl_is_ht40_tx_allowed(priv, ctx, sta))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001292 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001293 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001294 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001295
Guy Coheneecd6e52008-04-23 17:14:58 -07001296 rs_set_expected_tpt_table(lq_sta, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001297
Guy Cohenf935a6d2008-04-23 17:15:02 -07001298 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001299
Tomas Winklere1623442009-01-27 14:27:56 -08001300 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001301 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1302 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1303 rate, rate_mask);
1304 return -1;
1305 }
1306 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Guy Cohen39e88502008-04-23 17:14:57 -07001307
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001308 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1309 tbl->current_rate, is_green);
1310 return 0;
1311}
1312
1313/*
1314 * Set up search table for MIMO3
1315 */
1316static int rs_switch_to_mimo3(struct iwl_priv *priv,
1317 struct iwl_lq_sta *lq_sta,
1318 struct ieee80211_conf *conf,
1319 struct ieee80211_sta *sta,
1320 struct iwl_scale_tbl_info *tbl, int index)
1321{
1322 u16 rate_mask;
1323 s32 rate;
1324 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001325 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001326 struct iwl_rxon_context *ctx = sta_priv->ctx;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001327
1328 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1329 return -1;
1330
Johannes Bergaf0ed692013-02-12 14:21:00 +01001331 if (sta->smps_mode == IEEE80211_SMPS_STATIC)
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001332 return -1;
1333
1334 /* Need both Tx chains/antennas to support MIMO */
Johannes Berg9e295112012-04-09 17:46:55 -07001335 if (priv->hw_params.tx_chains_num < 3)
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001336 return -1;
1337
1338 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1339
1340 tbl->lq_type = LQ_MIMO3;
1341 tbl->is_dup = lq_sta->is_dup;
1342 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001343 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001344 rate_mask = lq_sta->active_mimo3_rate;
1345
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001346 if (iwl_is_ht40_tx_allowed(priv, ctx, sta))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001347 tbl->is_ht40 = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001348 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001349 tbl->is_ht40 = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001350
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001351 rs_set_expected_tpt_table(lq_sta, tbl);
1352
1353 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1354
1355 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1356 rate, rate_mask);
Guy Cohen39e88502008-04-23 17:14:57 -07001357 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001358 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001359 rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001360 return -1;
Guy Cohen39e88502008-04-23 17:14:57 -07001361 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001362 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Zhu Yib481de92007-09-25 17:54:57 -07001363
Tomas Winklere1623442009-01-27 14:27:56 -08001364 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001365 tbl->current_rate, is_green);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001366 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001367}
1368
Ben Cahill77626352007-11-29 11:09:44 +08001369/*
1370 * Set up search table for SISO
1371 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001372static int rs_switch_to_siso(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001373 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001374 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001375 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001376 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001377{
Zhu Yib481de92007-09-25 17:54:57 -07001378 u16 rate_mask;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001379 u8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001380 s32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001381 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001382 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001383
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001384 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001385 return -1;
1386
Tomas Winklere1623442009-01-27 14:27:56 -08001387 IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001388
Tomas Winklerc33104f2008-01-14 17:46:21 -08001389 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001390 tbl->lq_type = LQ_SISO;
1391 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001392 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001393 rate_mask = lq_sta->active_siso_rate;
Zhu Yib481de92007-09-25 17:54:57 -07001394
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001395 if (iwl_is_ht40_tx_allowed(priv, ctx, sta))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001396 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001397 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001398 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001399
Zhu Yib481de92007-09-25 17:54:57 -07001400 if (is_green)
Guy Cohen39e88502008-04-23 17:14:57 -07001401 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
Zhu Yib481de92007-09-25 17:54:57 -07001402
Guy Coheneecd6e52008-04-23 17:14:58 -07001403 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohenf935a6d2008-04-23 17:15:02 -07001404 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001405
Tomas Winklere1623442009-01-27 14:27:56 -08001406 IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001407 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001408 IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001409 rate, rate_mask);
1410 return -1;
1411 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001412 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Tomas Winklere1623442009-01-27 14:27:56 -08001413 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001414 tbl->current_rate, is_green);
Mohamed Abbas403ab562007-11-06 22:06:25 -08001415 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001416}
1417
Ben Cahill77626352007-11-29 11:09:44 +08001418/*
1419 * Try to switch to new modulation mode from legacy
1420 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001421static int rs_move_legacy_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001422 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001423 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001424 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001425 int index)
1426{
Tomas Winklere227cea2008-07-18 13:53:05 +08001427 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1428 struct iwl_scale_tbl_info *search_tbl =
1429 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1430 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1431 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1432 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001433 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001434 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001435 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Guy Cohenfde0db32008-04-21 15:42:01 -07001436 int ret = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001437 u8 update_search_tbl_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001438
Johannes Berg290f5992010-08-23 07:56:58 -07001439 switch (priv->bt_traffic_load) {
1440 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1441 /* nothing */
1442 break;
1443 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1444 /* avoid antenna B unless MIMO */
1445 if (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001446 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001447 break;
1448 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1449 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1450 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001451 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001452 first_antenna(priv->nvm_data->valid_tx_ant);
Johannes Berg290f5992010-08-23 07:56:58 -07001453 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 &&
1454 tbl->action != IWL_LEGACY_SWITCH_SISO)
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001455 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001456 break;
1457 default:
1458 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1459 break;
1460 }
1461
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001462 if (!iwl_ht_enabled(priv))
1463 /* stay in Legacy */
1464 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07001465 else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001466 tbl->action > IWL_LEGACY_SWITCH_SISO)
1467 tbl->action = IWL_LEGACY_SWITCH_SISO;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001468
1469 /* configure as 1x1 if bt full concurrency */
1470 if (priv->bt_full_concurrent) {
1471 if (!iwl_ht_enabled(priv))
1472 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1473 else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1474 tbl->action = IWL_LEGACY_SWITCH_SISO;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001475 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001476 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001477 }
1478
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001479 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001480 for (; ;) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001481 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001482 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001483 case IWL_LEGACY_SWITCH_ANTENNA1:
1484 case IWL_LEGACY_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001485 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
Zhu Yib481de92007-09-25 17:54:57 -07001486
Guy Cohen3110bef2008-09-09 10:54:54 +08001487 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1488 tx_chains_num <= 1) ||
1489 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
1490 tx_chains_num <= 2))
1491 break;
1492
Ben Cahill77626352007-11-29 11:09:44 +08001493 /* Don't change antenna if success has been great */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001494 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1495 !priv->bt_full_concurrent &&
1496 priv->bt_traffic_load ==
1497 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001498 break;
Ben Cahill77626352007-11-29 11:09:44 +08001499
Ben Cahill77626352007-11-29 11:09:44 +08001500 /* Set up search table to try other antenna */
Zhu Yib481de92007-09-25 17:54:57 -07001501 memcpy(search_tbl, tbl, sz);
1502
Guy Cohenaade00c2008-04-23 17:14:59 -07001503 if (rs_toggle_antenna(valid_tx_ant,
1504 &search_tbl->current_rate, search_tbl)) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001505 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001506 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohenaade00c2008-04-23 17:14:59 -07001507 goto out;
1508 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001509 break;
Zhu Yib481de92007-09-25 17:54:57 -07001510 case IWL_LEGACY_SWITCH_SISO:
Tomas Winklere1623442009-01-27 14:27:56 -08001511 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001512
1513 /* Set up search table to try SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001514 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001515 search_tbl->is_SGI = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001516 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001517 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001518 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001519 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001520 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001521 }
Zhu Yib481de92007-09-25 17:54:57 -07001522
1523 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001524 case IWL_LEGACY_SWITCH_MIMO2_AB:
1525 case IWL_LEGACY_SWITCH_MIMO2_AC:
1526 case IWL_LEGACY_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001527 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n");
Ben Cahill77626352007-11-29 11:09:44 +08001528
1529 /* Set up search table to try MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07001530 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001531 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001532
1533 if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
1534 search_tbl->ant_type = ANT_AB;
1535 else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
1536 search_tbl->ant_type = ANT_AC;
1537 else
1538 search_tbl->ant_type = ANT_BC;
1539
1540 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1541 break;
1542
Guy Cohenfde0db32008-04-21 15:42:01 -07001543 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001544 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001545 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001546 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001547 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001548 }
Zhu Yib481de92007-09-25 17:54:57 -07001549 break;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001550
1551 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1552 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1553
1554 /* Set up search table to try MIMO3 */
1555 memcpy(search_tbl, tbl, sz);
1556 search_tbl->is_SGI = 0;
1557
1558 search_tbl->ant_type = ANT_ABC;
1559
1560 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1561 break;
1562
1563 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1564 search_tbl, index);
1565 if (!ret) {
1566 lq_sta->action_counter = 0;
1567 goto out;
1568 }
1569 break;
Zhu Yib481de92007-09-25 17:54:57 -07001570 }
1571 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001572 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001573 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001574
1575 if (tbl->action == start_action)
1576 break;
1577
1578 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001579 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001580 return 0;
1581
Guy Cohen3110bef2008-09-09 10:54:54 +08001582out:
1583 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001584 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001585 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001586 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001587 if (update_search_tbl_counter)
1588 search_tbl->action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001589 return 0;
1590
1591}
1592
Ben Cahill77626352007-11-29 11:09:44 +08001593/*
1594 * Try to switch to new modulation mode from SISO
1595 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001596static int rs_move_siso_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001597 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001598 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001599 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001600{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001601 u8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001602 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1603 struct iwl_scale_tbl_info *search_tbl =
1604 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1605 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001606 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001607 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1608 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001609 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001610 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001611 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001612 u8 update_search_tbl_counter = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -07001613 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001614
Johannes Berg290f5992010-08-23 07:56:58 -07001615 switch (priv->bt_traffic_load) {
1616 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1617 /* nothing */
1618 break;
1619 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1620 /* avoid antenna B unless MIMO */
1621 if (tbl->action == IWL_SISO_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001622 tbl->action = IWL_SISO_SWITCH_MIMO2_AB;
Johannes Berg290f5992010-08-23 07:56:58 -07001623 break;
1624 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1625 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1626 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001627 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001628 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001629 if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
Johannes Berg290f5992010-08-23 07:56:58 -07001630 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1631 break;
1632 default:
1633 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1634 break;
1635 }
1636
Johannes Berg3ad3b922009-08-07 15:41:48 -07001637 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001638 tbl->action > IWL_SISO_SWITCH_ANTENNA2) {
1639 /* stay in SISO */
1640 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1641 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001642
1643 /* configure as 1x1 if bt full concurrency */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001644 if (priv->bt_full_concurrent) {
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001645 valid_tx_ant =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001646 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001647 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1648 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1649 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001650
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001651 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001652 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001653 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001654 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001655 case IWL_SISO_SWITCH_ANTENNA1:
1656 case IWL_SISO_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001657 IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001658 if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001659 tx_chains_num <= 1) ||
Guy Cohen3110bef2008-09-09 10:54:54 +08001660 (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001661 tx_chains_num <= 2))
Guy Cohen3110bef2008-09-09 10:54:54 +08001662 break;
1663
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001664 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1665 !priv->bt_full_concurrent &&
1666 priv->bt_traffic_load ==
1667 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001668 break;
Zhu Yib481de92007-09-25 17:54:57 -07001669
1670 memcpy(search_tbl, tbl, sz);
Guy Cohenaade00c2008-04-23 17:14:59 -07001671 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001672 &search_tbl->current_rate, search_tbl)) {
1673 update_search_tbl_counter = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07001674 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001675 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001676 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001677 case IWL_SISO_SWITCH_MIMO2_AB:
1678 case IWL_SISO_SWITCH_MIMO2_AC:
1679 case IWL_SISO_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001680 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n");
Zhu Yib481de92007-09-25 17:54:57 -07001681 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001682 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001683
1684 if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
1685 search_tbl->ant_type = ANT_AB;
1686 else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
1687 search_tbl->ant_type = ANT_AC;
1688 else
1689 search_tbl->ant_type = ANT_BC;
1690
1691 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1692 break;
1693
Guy Cohenfde0db32008-04-21 15:42:01 -07001694 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001695 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001696 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001697 goto out;
1698 break;
1699 case IWL_SISO_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001700 if (!tbl->is_ht40 && !(ht_cap->cap &
1701 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001702 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001703 if (tbl->is_ht40 && !(ht_cap->cap &
1704 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001705 break;
1706
Tomas Winklere1623442009-01-27 14:27:56 -08001707 IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001708
Zhu Yib481de92007-09-25 17:54:57 -07001709 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001710 if (is_green) {
1711 if (!tbl->is_SGI)
1712 break;
1713 else
Winkler, Tomas15b16872008-12-19 10:37:33 +08001714 IWL_ERR(priv,
1715 "SGI was set in GF+SISO\n");
Zhu Yib481de92007-09-25 17:54:57 -07001716 }
Guy Cohen39e88502008-04-23 17:14:57 -07001717 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07001718 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohen39e88502008-04-23 17:14:57 -07001719 if (tbl->is_SGI) {
1720 s32 tpt = lq_sta->last_tpt / 100;
1721 if (tpt >= search_tbl->expected_tpt[index])
1722 break;
1723 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001724 search_tbl->current_rate =
1725 rate_n_flags_from_tbl(priv, search_tbl,
1726 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001727 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001728 goto out;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001729 case IWL_SISO_SWITCH_MIMO3_ABC:
1730 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1731 memcpy(search_tbl, tbl, sz);
1732 search_tbl->is_SGI = 0;
1733 search_tbl->ant_type = ANT_ABC;
1734
1735 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1736 break;
1737
1738 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1739 search_tbl, index);
1740 if (!ret)
1741 goto out;
1742 break;
Zhu Yib481de92007-09-25 17:54:57 -07001743 }
1744 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001745 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001746 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001747
1748 if (tbl->action == start_action)
1749 break;
1750 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001751 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001752 return 0;
1753
1754 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08001755 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001756 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001757 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001758 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001759 if (update_search_tbl_counter)
1760 search_tbl->action = tbl->action;
1761
Zhu Yib481de92007-09-25 17:54:57 -07001762 return 0;
1763}
1764
Ben Cahill77626352007-11-29 11:09:44 +08001765/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001766 * Try to switch to new modulation mode from MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001767 */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001768static int rs_move_mimo2_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001769 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001770 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001771 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001772{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001773 s8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001774 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1775 struct iwl_scale_tbl_info *search_tbl =
1776 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Guy Cohen3110bef2008-09-09 10:54:54 +08001777 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001778 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001779 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1780 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001781 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001782 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001783 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001784 u8 update_search_tbl_counter = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07001785 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001786
Johannes Berg290f5992010-08-23 07:56:58 -07001787 switch (priv->bt_traffic_load) {
1788 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1789 /* nothing */
1790 break;
1791 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1792 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1793 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001794 if (tbl->action != IWL_MIMO2_SWITCH_SISO_A)
1795 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1796 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001797 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1798 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001799 if (tbl->action == IWL_MIMO2_SWITCH_SISO_B ||
1800 tbl->action == IWL_MIMO2_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001801 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1802 break;
1803 default:
1804 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1805 break;
1806 }
1807
Johannes Berg3ad3b922009-08-07 15:41:48 -07001808 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001809 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1810 tbl->action > IWL_MIMO2_SWITCH_SISO_C)) {
1811 /* switch in SISO */
1812 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1813 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001814
1815 /* configure as 1x1 if bt full concurrency */
1816 if (priv->bt_full_concurrent &&
1817 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1818 tbl->action > IWL_MIMO2_SWITCH_SISO_C))
1819 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1820
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001821 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001822 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001823 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001824 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001825 case IWL_MIMO2_SWITCH_ANTENNA1:
1826 case IWL_MIMO2_SWITCH_ANTENNA2:
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001827 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001828
1829 if (tx_chains_num <= 2)
1830 break;
1831
1832 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1833 break;
1834
1835 memcpy(search_tbl, tbl, sz);
1836 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001837 &search_tbl->current_rate, search_tbl)) {
1838 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001839 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001840 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001841 break;
1842 case IWL_MIMO2_SWITCH_SISO_A:
1843 case IWL_MIMO2_SWITCH_SISO_B:
1844 case IWL_MIMO2_SWITCH_SISO_C:
Tomas Winklere1623442009-01-27 14:27:56 -08001845 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001846
Ben Cahill77626352007-11-29 11:09:44 +08001847 /* Set up new search table for SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001848 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001849
Guy Cohen3110bef2008-09-09 10:54:54 +08001850 if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
Guy Cohenfde0db32008-04-21 15:42:01 -07001851 search_tbl->ant_type = ANT_A;
Guy Cohen3110bef2008-09-09 10:54:54 +08001852 else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
Guy Cohenfde0db32008-04-21 15:42:01 -07001853 search_tbl->ant_type = ANT_B;
Guy Cohen3110bef2008-09-09 10:54:54 +08001854 else
1855 search_tbl->ant_type = ANT_C;
1856
1857 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1858 break;
Zhu Yib481de92007-09-25 17:54:57 -07001859
Tomas Winklerc33104f2008-01-14 17:46:21 -08001860 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001861 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001862 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001863 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08001864
Zhu Yib481de92007-09-25 17:54:57 -07001865 break;
1866
Guy Cohen3110bef2008-09-09 10:54:54 +08001867 case IWL_MIMO2_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001868 if (!tbl->is_ht40 && !(ht_cap->cap &
1869 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001870 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001871 if (tbl->is_ht40 && !(ht_cap->cap &
1872 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001873 break;
1874
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001875 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1876
1877 /* Set up new search table for MIMO2 */
1878 memcpy(search_tbl, tbl, sz);
1879 search_tbl->is_SGI = !tbl->is_SGI;
1880 rs_set_expected_tpt_table(lq_sta, search_tbl);
1881 /*
1882 * If active table already uses the fastest possible
1883 * modulation (dual stream with short guard interval),
1884 * and it's working well, there's no need to look
1885 * for a better type of modulation!
1886 */
1887 if (tbl->is_SGI) {
1888 s32 tpt = lq_sta->last_tpt / 100;
1889 if (tpt >= search_tbl->expected_tpt[index])
1890 break;
1891 }
1892 search_tbl->current_rate =
1893 rate_n_flags_from_tbl(priv, search_tbl,
1894 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001895 update_search_tbl_counter = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001896 goto out;
1897
1898 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1899 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1900 memcpy(search_tbl, tbl, sz);
1901 search_tbl->is_SGI = 0;
1902 search_tbl->ant_type = ANT_ABC;
1903
1904 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1905 break;
1906
1907 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1908 search_tbl, index);
1909 if (!ret)
1910 goto out;
1911
1912 break;
1913 }
1914 tbl->action++;
1915 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1916 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1917
1918 if (tbl->action == start_action)
1919 break;
1920 }
1921 search_tbl->lq_type = LQ_NONE;
1922 return 0;
1923 out:
1924 lq_sta->search_better_tbl = 1;
1925 tbl->action++;
1926 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1927 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001928 if (update_search_tbl_counter)
1929 search_tbl->action = tbl->action;
1930
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001931 return 0;
1932
1933}
1934
1935/*
1936 * Try to switch to new modulation mode from MIMO3
1937 */
1938static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1939 struct iwl_lq_sta *lq_sta,
1940 struct ieee80211_conf *conf,
1941 struct ieee80211_sta *sta, int index)
1942{
1943 s8 is_green = lq_sta->is_green;
1944 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1945 struct iwl_scale_tbl_info *search_tbl =
1946 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1947 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001948 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001949 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1950 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001951 u8 start_action;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001952 u8 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Johannes Berg9e295112012-04-09 17:46:55 -07001953 u8 tx_chains_num = priv->hw_params.tx_chains_num;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001954 int ret;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001955 u8 update_search_tbl_counter = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001956
Johannes Berg290f5992010-08-23 07:56:58 -07001957 switch (priv->bt_traffic_load) {
1958 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1959 /* nothing */
1960 break;
1961 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1962 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1963 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001964 if (tbl->action != IWL_MIMO3_SWITCH_SISO_A)
Johannes Berg290f5992010-08-23 07:56:58 -07001965 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001966 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001967 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1968 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001969 if (tbl->action == IWL_MIMO3_SWITCH_SISO_B ||
1970 tbl->action == IWL_MIMO3_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001971 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Johannes Berg290f5992010-08-23 07:56:58 -07001972 break;
1973 default:
1974 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1975 break;
1976 }
1977
Johannes Berg3ad3b922009-08-07 15:41:48 -07001978 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001979 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
1980 tbl->action > IWL_MIMO3_SWITCH_SISO_C)) {
1981 /* switch in SISO */
1982 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
1983 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001984
1985 /* configure as 1x1 if bt full concurrency */
1986 if (priv->bt_full_concurrent &&
1987 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
1988 tbl->action > IWL_MIMO3_SWITCH_SISO_C))
1989 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
1990
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001991 start_action = tbl->action;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001992 for (;;) {
1993 lq_sta->action_counter++;
1994 switch (tbl->action) {
1995 case IWL_MIMO3_SWITCH_ANTENNA1:
1996 case IWL_MIMO3_SWITCH_ANTENNA2:
1997 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
1998
1999 if (tx_chains_num <= 3)
2000 break;
2001
2002 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
2003 break;
2004
2005 memcpy(search_tbl, tbl, sz);
2006 if (rs_toggle_antenna(valid_tx_ant,
2007 &search_tbl->current_rate, search_tbl))
2008 goto out;
2009 break;
2010 case IWL_MIMO3_SWITCH_SISO_A:
2011 case IWL_MIMO3_SWITCH_SISO_B:
2012 case IWL_MIMO3_SWITCH_SISO_C:
2013 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
2014
2015 /* Set up new search table for SISO */
2016 memcpy(search_tbl, tbl, sz);
2017
2018 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
2019 search_tbl->ant_type = ANT_A;
2020 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
2021 search_tbl->ant_type = ANT_B;
2022 else
2023 search_tbl->ant_type = ANT_C;
2024
2025 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2026 break;
2027
2028 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
2029 search_tbl, index);
2030 if (!ret)
2031 goto out;
2032
2033 break;
2034
2035 case IWL_MIMO3_SWITCH_MIMO2_AB:
2036 case IWL_MIMO3_SWITCH_MIMO2_AC:
2037 case IWL_MIMO3_SWITCH_MIMO2_BC:
2038 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
2039
2040 memcpy(search_tbl, tbl, sz);
2041 search_tbl->is_SGI = 0;
2042 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
2043 search_tbl->ant_type = ANT_AB;
2044 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
2045 search_tbl->ant_type = ANT_AC;
2046 else
2047 search_tbl->ant_type = ANT_BC;
2048
2049 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2050 break;
2051
2052 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
2053 search_tbl, index);
2054 if (!ret)
2055 goto out;
2056
2057 break;
2058
2059 case IWL_MIMO3_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002060 if (!tbl->is_ht40 && !(ht_cap->cap &
2061 IEEE80211_HT_CAP_SGI_20))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002062 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002063 if (tbl->is_ht40 && !(ht_cap->cap &
2064 IEEE80211_HT_CAP_SGI_40))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002065 break;
2066
2067 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
Ben Cahill77626352007-11-29 11:09:44 +08002068
2069 /* Set up new search table for MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07002070 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07002071 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07002072 rs_set_expected_tpt_table(lq_sta, search_tbl);
Ben Cahill77626352007-11-29 11:09:44 +08002073 /*
2074 * If active table already uses the fastest possible
2075 * modulation (dual stream with short guard interval),
2076 * and it's working well, there's no need to look
2077 * for a better type of modulation!
2078 */
Guy Cohen39e88502008-04-23 17:14:57 -07002079 if (tbl->is_SGI) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002080 s32 tpt = lq_sta->last_tpt / 100;
Guy Cohen39e88502008-04-23 17:14:57 -07002081 if (tpt >= search_tbl->expected_tpt[index])
2082 break;
Zhu Yib481de92007-09-25 17:54:57 -07002083 }
Tomas Winkler978785a2008-12-19 10:37:31 +08002084 search_tbl->current_rate =
2085 rate_n_flags_from_tbl(priv, search_tbl,
2086 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002087 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002088 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002089 }
2090 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002091 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2092 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07002093
2094 if (tbl->action == start_action)
2095 break;
2096 }
Guy Cohen3110bef2008-09-09 10:54:54 +08002097 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07002098 return 0;
2099 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08002100 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002101 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002102 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2103 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002104 if (update_search_tbl_counter)
2105 search_tbl->action = tbl->action;
2106
Zhu Yib481de92007-09-25 17:54:57 -07002107 return 0;
2108
2109}
2110
Ben Cahill77626352007-11-29 11:09:44 +08002111/*
2112 * Check whether we should continue using same modulation mode, or
2113 * begin search for a new mode, based on:
2114 * 1) # tx successes or failures while using this mode
2115 * 2) # times calling this function
2116 * 3) elapsed time in this mode (not used, for now)
2117 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002118static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
Zhu Yib481de92007-09-25 17:54:57 -07002119{
Tomas Winklere227cea2008-07-18 13:53:05 +08002120 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002121 int i;
2122 int active_tbl;
2123 int flush_interval_passed = 0;
Ester Kummerbf403db2008-05-05 10:22:40 +08002124 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07002125
Ester Kummerbf403db2008-05-05 10:22:40 +08002126 priv = lq_sta->drv;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002127 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002128
Tomas Winklerc33104f2008-01-14 17:46:21 -08002129 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002130
Ben Cahill77626352007-11-29 11:09:44 +08002131 /* If we've been disallowing search, see if we should now allow it */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002132 if (lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002133
Ben Cahill77626352007-11-29 11:09:44 +08002134 /* Elapsed time using current modulation mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002135 if (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002136 flush_interval_passed =
Mohamed Abbas447fee72009-04-20 14:37:02 -07002137 time_after(jiffies,
2138 (unsigned long)(lq_sta->flush_timer +
Zhu Yib481de92007-09-25 17:54:57 -07002139 IWL_RATE_SCALE_FLUSH_INTVL));
2140
Ben Cahill77626352007-11-29 11:09:44 +08002141 /*
2142 * Check if we should allow search for new modulation mode.
2143 * If many frames have failed or succeeded, or we've used
2144 * this same modulation for a long time, allow search, and
2145 * reset history stats that keep track of whether we should
2146 * allow a new search. Also (below) reset all bitmaps and
2147 * stats in active history.
2148 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002149 if (force_search ||
2150 (lq_sta->total_failed > lq_sta->max_failure_limit) ||
Tomas Winklerc33104f2008-01-14 17:46:21 -08002151 (lq_sta->total_success > lq_sta->max_success_limit) ||
2152 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002153 && (flush_interval_passed))) {
Johannes Berg0ca24da2012-03-15 13:26:46 -07002154 IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002155 lq_sta->total_failed,
2156 lq_sta->total_success,
Zhu Yib481de92007-09-25 17:54:57 -07002157 flush_interval_passed);
Ben Cahill77626352007-11-29 11:09:44 +08002158
2159 /* Allow search for new mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002160 lq_sta->stay_in_tbl = 0; /* only place reset */
2161 lq_sta->total_failed = 0;
2162 lq_sta->total_success = 0;
2163 lq_sta->flush_timer = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002164
2165 /*
2166 * Else if we've used this modulation mode enough repetitions
2167 * (regardless of elapsed time or success/failure), reset
2168 * history bitmaps and rate-specific stats for all rates in
2169 * active table.
2170 */
Mohamed Abbas403ab562007-11-06 22:06:25 -08002171 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002172 lq_sta->table_count++;
2173 if (lq_sta->table_count >=
2174 lq_sta->table_count_limit) {
2175 lq_sta->table_count = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002176
Tomas Winklere1623442009-01-27 14:27:56 -08002177 IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n");
Zhu Yib481de92007-09-25 17:54:57 -07002178 for (i = 0; i < IWL_RATE_COUNT; i++)
2179 rs_rate_scale_clear_window(
2180 &(tbl->win[i]));
2181 }
2182 }
2183
Ben Cahill77626352007-11-29 11:09:44 +08002184 /* If transitioning to allow "search", reset all history
2185 * bitmaps and stats in active table (this will become the new
2186 * "search" table). */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002187 if (!lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002188 for (i = 0; i < IWL_RATE_COUNT; i++)
2189 rs_rate_scale_clear_window(&(tbl->win[i]));
2190 }
2191 }
2192}
2193
Ben Cahill77626352007-11-29 11:09:44 +08002194/*
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002195 * setup rate table in uCode
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002196 */
Johannes Berg70817b52011-05-11 03:29:25 -07002197static void rs_update_rate_tbl(struct iwl_priv *priv,
2198 struct iwl_rxon_context *ctx,
2199 struct iwl_lq_sta *lq_sta,
2200 struct iwl_scale_tbl_info *tbl,
2201 int index, u8 is_green)
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002202{
2203 u32 rate;
2204
2205 /* Update uCode's rate table. */
2206 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
2207 rs_fill_link_cmd(priv, lq_sta, rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002208 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002209}
2210
2211/*
Ben Cahill77626352007-11-29 11:09:44 +08002212 * Do rate scaling and search for new modulation mode.
2213 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002214static void rs_rate_scale_perform(struct iwl_priv *priv,
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002215 struct sk_buff *skb,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002216 struct ieee80211_sta *sta,
2217 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002218{
Johannes Berg4b7679a2008-09-18 18:14:18 +02002219 struct ieee80211_hw *hw = priv->hw;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002220 struct ieee80211_conf *conf = &hw->conf;
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002221 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2222 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002223 int low = IWL_RATE_INVALID;
2224 int high = IWL_RATE_INVALID;
2225 int index;
2226 int i;
Tomas Winklere227cea2008-07-18 13:53:05 +08002227 struct iwl_rate_scale_data *window = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002228 int current_tpt = IWL_INVALID_VALUE;
2229 int low_tpt = IWL_INVALID_VALUE;
2230 int high_tpt = IWL_INVALID_VALUE;
2231 u32 fail_count;
2232 s8 scale_action = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07002233 u16 rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -07002234 u8 update_lq = 0;
Tomas Winklere227cea2008-07-18 13:53:05 +08002235 struct iwl_scale_tbl_info *tbl, *tbl1;
Zhu Yib481de92007-09-25 17:54:57 -07002236 u16 rate_scale_index_msk = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002237 u8 is_green = 0;
2238 u8 active_tbl = 0;
2239 u8 done_search = 0;
2240 u16 high_low;
Guy Cohena5e8b502008-05-29 16:35:11 +08002241 s32 sr;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002242 u8 tid = IWL_MAX_TID_COUNT;
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002243 struct iwl_tid_data *tid_data;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002244 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002245 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002246
Tomas Winklere1623442009-01-27 14:27:56 -08002247 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002248
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002249 /* Send management frames and NO_ACK data using lowest rate. */
Tomas Winkler417f1142008-11-12 13:14:06 -08002250 /* TODO: this could probably be improved.. */
2251 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002252 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -07002253 return;
Zhu Yib481de92007-09-25 17:54:57 -07002254
Johannes Berg4b7679a2008-09-18 18:14:18 +02002255 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
Zhu Yib481de92007-09-25 17:54:57 -07002256
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002257 tid = rs_tl_add_packet(lq_sta, hdr);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002258 if ((tid != IWL_MAX_TID_COUNT) &&
2259 (lq_sta->tx_agg_tid_en & (1 << tid))) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002260 tid_data = &priv->tid_data[lq_sta->lq.sta_id][tid];
Daniel C Halperine3949d62009-09-17 10:43:50 -07002261 if (tid_data->agg.state == IWL_AGG_OFF)
2262 lq_sta->is_agg = 0;
2263 else
2264 lq_sta->is_agg = 1;
2265 } else
2266 lq_sta->is_agg = 0;
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002267
Ben Cahill77626352007-11-29 11:09:44 +08002268 /*
2269 * Select rate-scale / modulation-mode table to work with in
2270 * the rest of this function: "search" if searching for better
2271 * modulation mode, or "active" if doing rate scaling within a mode.
2272 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002273 if (!lq_sta->search_better_tbl)
2274 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002275 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002276 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002277
Tomas Winklerc33104f2008-01-14 17:46:21 -08002278 tbl = &(lq_sta->lq_info[active_tbl]);
Wey-Yi Guy2681b202009-05-21 13:44:22 -07002279 if (is_legacy(tbl->lq_type))
2280 lq_sta->is_green = 0;
2281 else
Johannes Berg7e6a5882010-08-23 10:46:46 +02002282 lq_sta->is_green = rs_use_green(sta);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002283 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07002284
Ben Cahill77626352007-11-29 11:09:44 +08002285 /* current tx rate */
Johannes Bergb7e35002008-09-11 02:22:58 +02002286 index = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002287
Tomas Winklere1623442009-01-27 14:27:56 -08002288 IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index,
Zhu Yib481de92007-09-25 17:54:57 -07002289 tbl->lq_type);
2290
Ben Cahill77626352007-11-29 11:09:44 +08002291 /* rates available for this association, and for modulation mode */
Guy Coheneecd6e52008-04-23 17:14:58 -07002292 rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07002293
Frans Pop91dd6c22010-03-24 14:19:58 -07002294 IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07002295
2296 /* mask with station rate restriction */
2297 if (is_legacy(tbl->lq_type)) {
Johannes Berg8318d782008-01-24 19:38:38 +01002298 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Ben Cahill77626352007-11-29 11:09:44 +08002299 /* supp_rates has no CCK bits in A mode */
Zhu Yib481de92007-09-25 17:54:57 -07002300 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002301 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -07002302 else
2303 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002304 lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -07002305
2306 } else
2307 rate_scale_index_msk = rate_mask;
2308
2309 if (!rate_scale_index_msk)
2310 rate_scale_index_msk = rate_mask;
2311
Guy Cohen07bc28e2008-04-23 17:15:03 -07002312 if (!((1 << index) & rate_scale_index_msk)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002313 IWL_ERR(priv, "Current Rate is not valid\n");
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002314 if (lq_sta->search_better_tbl) {
2315 /* revert to active table if search table is not valid*/
2316 tbl->lq_type = LQ_NONE;
2317 lq_sta->search_better_tbl = 0;
2318 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
2319 /* get "active" rate info */
2320 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Johannes Berg70817b52011-05-11 03:29:25 -07002321 rs_update_rate_tbl(priv, ctx, lq_sta, tbl,
2322 index, is_green);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002323 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002324 return;
Zhu Yib481de92007-09-25 17:54:57 -07002325 }
2326
Ben Cahill77626352007-11-29 11:09:44 +08002327 /* Get expected throughput table and history window for current rate */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002328 if (!tbl->expected_tpt) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002329 IWL_ERR(priv, "tbl->expected_tpt is NULL\n");
Guy Cohen07bc28e2008-04-23 17:15:03 -07002330 return;
2331 }
Zhu Yib481de92007-09-25 17:54:57 -07002332
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002333 /* force user max rate if set by user */
2334 if ((lq_sta->max_rate_idx != -1) &&
2335 (lq_sta->max_rate_idx < index)) {
2336 index = lq_sta->max_rate_idx;
2337 update_lq = 1;
2338 window = &(tbl->win[index]);
2339 goto lq_update;
2340 }
2341
Zhu Yib481de92007-09-25 17:54:57 -07002342 window = &(tbl->win[index]);
2343
Ben Cahill77626352007-11-29 11:09:44 +08002344 /*
2345 * If there is not enough history to calculate actual average
2346 * throughput, keep analyzing results of more tx frames, without
2347 * changing rate or mode (bypass most of the rest of this function).
2348 * Set up new rate table in uCode only if old rate is not supported
2349 * in current association (use new rate found above).
2350 */
Zhu Yib481de92007-09-25 17:54:57 -07002351 fail_count = window->counter - window->success_counter;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002352 if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
2353 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002354 IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d "
Zhu Yib481de92007-09-25 17:54:57 -07002355 "for index %d\n",
2356 window->success_counter, window->counter, index);
Ben Cahill77626352007-11-29 11:09:44 +08002357
2358 /* Can't calculate this yet; not enough history */
Zhu Yib481de92007-09-25 17:54:57 -07002359 window->average_tpt = IWL_INVALID_VALUE;
Ben Cahill77626352007-11-29 11:09:44 +08002360
2361 /* Should we stay with this modulation mode,
2362 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002363 rs_stay_in_table(lq_sta, false);
Ben Cahill77626352007-11-29 11:09:44 +08002364
Zhu Yib481de92007-09-25 17:54:57 -07002365 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08002366 }
Ben Cahill77626352007-11-29 11:09:44 +08002367 /* Else we have enough samples; calculate estimate of
2368 * actual average throughput */
Reinette Chatre3d79b2a2010-05-03 10:55:07 -07002369 if (window->average_tpt != ((window->success_ratio *
2370 tbl->expected_tpt[index] + 64) / 128)) {
2371 IWL_ERR(priv, "expected_tpt should have been calculated by now\n");
2372 window->average_tpt = ((window->success_ratio *
2373 tbl->expected_tpt[index] + 64) / 128);
2374 }
Zhu Yib481de92007-09-25 17:54:57 -07002375
Ben Cahill77626352007-11-29 11:09:44 +08002376 /* If we are searching for better modulation mode, check success. */
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002377 if (lq_sta->search_better_tbl &&
Johannes Berg3ad3b922009-08-07 15:41:48 -07002378 (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) {
Ben Cahill77626352007-11-29 11:09:44 +08002379 /* If good success, continue using the "search" mode;
2380 * no need to send new link quality command, since we're
2381 * continuing to use the setup that we've been trying. */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002382 if (window->average_tpt > lq_sta->last_tpt) {
2383
Tomas Winklere1623442009-01-27 14:27:56 -08002384 IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002385 "suc=%d cur-tpt=%d old-tpt=%d\n",
2386 window->success_ratio,
2387 window->average_tpt,
2388 lq_sta->last_tpt);
2389
2390 if (!is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002391 lq_sta->enable_counter = 1;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002392
Ben Cahill77626352007-11-29 11:09:44 +08002393 /* Swap tables; "search" becomes "active" */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002394 lq_sta->active_tbl = active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002395 current_tpt = window->average_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002396
2397 /* Else poor success; go back to mode in "active" table */
Zhu Yib481de92007-09-25 17:54:57 -07002398 } else {
Guy Cohen07bc28e2008-04-23 17:15:03 -07002399
Tomas Winklere1623442009-01-27 14:27:56 -08002400 IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002401 "suc=%d cur-tpt=%d old-tpt=%d\n",
2402 window->success_ratio,
2403 window->average_tpt,
2404 lq_sta->last_tpt);
2405
Ben Cahill77626352007-11-29 11:09:44 +08002406 /* Nullify "search" table */
Zhu Yib481de92007-09-25 17:54:57 -07002407 tbl->lq_type = LQ_NONE;
Ben Cahill77626352007-11-29 11:09:44 +08002408
2409 /* Revert to "active" table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002410 active_tbl = lq_sta->active_tbl;
2411 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002412
Ben Cahill77626352007-11-29 11:09:44 +08002413 /* Revert to "active" rate and throughput info */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002414 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002415 current_tpt = lq_sta->last_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002416
2417 /* Need to set up a new rate table in uCode */
2418 update_lq = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002419 }
Ben Cahill77626352007-11-29 11:09:44 +08002420
2421 /* Either way, we've made a decision; modulation mode
2422 * search is done, allow rate adjustment next time. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002423 lq_sta->search_better_tbl = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002424 done_search = 1; /* Don't switch modes below! */
Zhu Yib481de92007-09-25 17:54:57 -07002425 goto lq_update;
2426 }
2427
Ben Cahill77626352007-11-29 11:09:44 +08002428 /* (Else) not in search of better modulation mode, try for better
2429 * starting rate, while staying in this mode. */
Ester Kummerbf403db2008-05-05 10:22:40 +08002430 high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk,
Zhu Yib481de92007-09-25 17:54:57 -07002431 tbl->lq_type);
2432 low = high_low & 0xff;
2433 high = (high_low >> 8) & 0xff;
2434
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002435 /* If user set max rate, dont allow higher than user constrain */
2436 if ((lq_sta->max_rate_idx != -1) &&
2437 (lq_sta->max_rate_idx < high))
2438 high = IWL_RATE_INVALID;
2439
Guy Cohena5e8b502008-05-29 16:35:11 +08002440 sr = window->success_ratio;
2441
Ben Cahill77626352007-11-29 11:09:44 +08002442 /* Collect measured throughputs for current and adjacent rates */
Zhu Yib481de92007-09-25 17:54:57 -07002443 current_tpt = window->average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002444 if (low != IWL_RATE_INVALID)
2445 low_tpt = tbl->win[low].average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002446 if (high != IWL_RATE_INVALID)
2447 high_tpt = tbl->win[high].average_tpt;
2448
Guy Cohena5e8b502008-05-29 16:35:11 +08002449 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002450
Ben Cahill77626352007-11-29 11:09:44 +08002451 /* Too many failures, decrease rate */
Guy Cohena5e8b502008-05-29 16:35:11 +08002452 if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002453 IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n");
Zhu Yib481de92007-09-25 17:54:57 -07002454 scale_action = -1;
Ben Cahill77626352007-11-29 11:09:44 +08002455
2456 /* No throughput measured yet for adjacent rates; try increase. */
Zhu Yib481de92007-09-25 17:54:57 -07002457 } else if ((low_tpt == IWL_INVALID_VALUE) &&
Guy Cohena5e8b502008-05-29 16:35:11 +08002458 (high_tpt == IWL_INVALID_VALUE)) {
2459
2460 if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
2461 scale_action = 1;
2462 else if (low != IWL_RATE_INVALID)
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002463 scale_action = 0;
Guy Cohena5e8b502008-05-29 16:35:11 +08002464 }
Ben Cahill77626352007-11-29 11:09:44 +08002465
2466 /* Both adjacent throughputs are measured, but neither one has better
2467 * throughput; we're using the best rate, don't change it! */
Zhu Yib481de92007-09-25 17:54:57 -07002468 else if ((low_tpt != IWL_INVALID_VALUE) &&
2469 (high_tpt != IWL_INVALID_VALUE) &&
2470 (low_tpt < current_tpt) &&
2471 (high_tpt < current_tpt))
2472 scale_action = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002473
2474 /* At least one adjacent rate's throughput is measured,
2475 * and may have better performance. */
Zhu Yib481de92007-09-25 17:54:57 -07002476 else {
Ben Cahill77626352007-11-29 11:09:44 +08002477 /* Higher adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002478 if (high_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002479 /* Higher rate has better throughput */
Guy Cohena5e8b502008-05-29 16:35:11 +08002480 if (high_tpt > current_tpt &&
2481 sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002482 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002483 } else {
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002484 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002485 }
Ben Cahill77626352007-11-29 11:09:44 +08002486
2487 /* Lower adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002488 } else if (low_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002489 /* Lower rate has better throughput */
Zhu Yib481de92007-09-25 17:54:57 -07002490 if (low_tpt > current_tpt) {
Tomas Winklere1623442009-01-27 14:27:56 -08002491 IWL_DEBUG_RATE(priv,
2492 "decrease rate because of low tpt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002493 scale_action = -1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002494 } else if (sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002495 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002496 }
Zhu Yib481de92007-09-25 17:54:57 -07002497 }
2498 }
2499
Ben Cahill77626352007-11-29 11:09:44 +08002500 /* Sanity check; asked for decrease, but success rate or throughput
2501 * has been good at old rate. Don't change it. */
Guy Cohena5e8b502008-05-29 16:35:11 +08002502 if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
2503 ((sr > IWL_RATE_HIGH_TH) ||
Zhu Yib481de92007-09-25 17:54:57 -07002504 (current_tpt > (100 * tbl->expected_tpt[low]))))
Zhu Yib481de92007-09-25 17:54:57 -07002505 scale_action = 0;
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002506 if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type))
2507 scale_action = -1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07002508 if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002509 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type)))
2510 scale_action = -1;
Johannes Berg290f5992010-08-23 07:56:58 -07002511
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002512 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2513 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2514 if (lq_sta->last_bt_traffic > priv->bt_traffic_load) {
2515 /*
2516 * don't set scale_action, don't want to scale up if
2517 * the rate scale doesn't otherwise think that is a
2518 * good idea.
2519 */
2520 } else if (lq_sta->last_bt_traffic <= priv->bt_traffic_load) {
2521 scale_action = -1;
2522 }
2523 }
2524 lq_sta->last_bt_traffic = priv->bt_traffic_load;
2525
2526 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2527 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2528 /* search for a new modulation */
2529 rs_stay_in_table(lq_sta, true);
2530 goto lq_update;
Johannes Berg290f5992010-08-23 07:56:58 -07002531 }
2532
Zhu Yib481de92007-09-25 17:54:57 -07002533 switch (scale_action) {
2534 case -1:
Ben Cahill77626352007-11-29 11:09:44 +08002535 /* Decrease starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002536 if (low != IWL_RATE_INVALID) {
2537 update_lq = 1;
2538 index = low;
2539 }
Mohamed Abbas447fee72009-04-20 14:37:02 -07002540
Zhu Yib481de92007-09-25 17:54:57 -07002541 break;
2542 case 1:
Ben Cahill77626352007-11-29 11:09:44 +08002543 /* Increase starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002544 if (high != IWL_RATE_INVALID) {
2545 update_lq = 1;
2546 index = high;
2547 }
2548
2549 break;
2550 case 0:
Ben Cahill77626352007-11-29 11:09:44 +08002551 /* No change */
Zhu Yib481de92007-09-25 17:54:57 -07002552 default:
2553 break;
2554 }
2555
Tomas Winklere1623442009-01-27 14:27:56 -08002556 IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d "
Zhu Yib481de92007-09-25 17:54:57 -07002557 "high %d type %d\n",
2558 index, scale_action, low, high, tbl->lq_type);
2559
Guy Cohena5e8b502008-05-29 16:35:11 +08002560lq_update:
Ben Cahill77626352007-11-29 11:09:44 +08002561 /* Replace uCode's rate table for the destination station. */
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002562 if (update_lq)
Johannes Berg70817b52011-05-11 03:29:25 -07002563 rs_update_rate_tbl(priv, ctx, lq_sta, tbl, index, is_green);
Ben Cahill77626352007-11-29 11:09:44 +08002564
Johannes Berg3ad3b922009-08-07 15:41:48 -07002565 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) {
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002566 /* Should we stay with this modulation mode,
2567 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002568 rs_stay_in_table(lq_sta, false);
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002569 }
Ben Cahill77626352007-11-29 11:09:44 +08002570 /*
2571 * Search for new modulation mode if we're:
2572 * 1) Not changing rates right now
2573 * 2) Not just finishing up a search
2574 * 3) Allowing a new search
2575 */
Guy Cohen47cfd462008-05-27 11:29:34 +08002576 if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) {
Ben Cahill77626352007-11-29 11:09:44 +08002577 /* Save current throughput to compare with "search" throughput*/
Tomas Winklerc33104f2008-01-14 17:46:21 -08002578 lq_sta->last_tpt = current_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002579
Ben Cahill77626352007-11-29 11:09:44 +08002580 /* Select a new "search" modulation mode to try.
2581 * If one is found, set up the new "search" table. */
Zhu Yib481de92007-09-25 17:54:57 -07002582 if (is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002583 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002584 else if (is_siso(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002585 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002586 else if (is_mimo2(tbl->lq_type))
2587 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002588 else
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002589 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002590
Ben Cahill77626352007-11-29 11:09:44 +08002591 /* If new "search" mode was selected, set up in uCode table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002592 if (lq_sta->search_better_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002593 /* Access the "search" table, clear its history. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002594 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Zhu Yib481de92007-09-25 17:54:57 -07002595 for (i = 0; i < IWL_RATE_COUNT; i++)
2596 rs_rate_scale_clear_window(&(tbl->win[i]));
2597
Ben Cahill77626352007-11-29 11:09:44 +08002598 /* Use new "search" start rate */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002599 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002600
Tomas Winklere1623442009-01-27 14:27:56 -08002601 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n",
Guy Cohen39e88502008-04-23 17:14:57 -07002602 tbl->current_rate, index);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002603 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002604 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Mohamed Abbas447fee72009-04-20 14:37:02 -07002605 } else
2606 done_search = 1;
2607 }
Zhu Yib481de92007-09-25 17:54:57 -07002608
Mohamed Abbas447fee72009-04-20 14:37:02 -07002609 if (done_search && !lq_sta->stay_in_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002610 /* If the "active" (non-search) mode was legacy,
2611 * and we've tried switching antennas,
2612 * but we haven't been able to try HT modes (not available),
2613 * stay with best antenna legacy modulation for a while
2614 * before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002615 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002616 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002617 lq_sta->action_counter > tbl1->max_search) {
Tomas Winklere1623442009-01-27 14:27:56 -08002618 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08002619 rs_set_stay_in_table(priv, 1, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002620 }
2621
Ben Cahill77626352007-11-29 11:09:44 +08002622 /* If we're in an HT mode, and all 3 mode switch actions
2623 * have been tried and compared, stay in this best modulation
2624 * mode for a while before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002625 if (lq_sta->enable_counter &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002626 (lq_sta->action_counter >= tbl1->max_search) &&
2627 iwl_ht_enabled(priv)) {
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002628 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2629 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002630 (tid != IWL_MAX_TID_COUNT)) {
2631 u8 sta_id = lq_sta->lq.sta_id;
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002632 tid_data = &priv->tid_data[sta_id][tid];
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002633 if (tid_data->agg.state == IWL_AGG_OFF) {
2634 IWL_DEBUG_RATE(priv,
2635 "try to aggregate tid %d\n",
2636 tid);
2637 rs_tl_turn_on_agg(priv, tid,
2638 lq_sta, sta);
2639 }
Zhu Yib481de92007-09-25 17:54:57 -07002640 }
Ester Kummerbf403db2008-05-05 10:22:40 +08002641 rs_set_stay_in_table(priv, 0, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002642 }
Zhu Yib481de92007-09-25 17:54:57 -07002643 }
2644
2645out:
Tomas Winkler978785a2008-12-19 10:37:31 +08002646 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
Wey-Yi Guyc3322b32011-10-10 07:26:58 -07002647 lq_sta->last_txrate_idx = index;
Zhu Yib481de92007-09-25 17:54:57 -07002648}
2649
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002650/**
2651 * rs_initialize_lq - Initialize a station's hardware rate table
2652 *
2653 * The uCode's station table contains a table of fallback rates
2654 * for automatic fallback during transmission.
2655 *
2656 * NOTE: This sets up a default set of values. These will be replaced later
2657 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
2658 * rc80211_simple.
2659 *
2660 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
2661 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
2662 * which requires station table entry to exist).
2663 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002664static void rs_initialize_lq(struct iwl_priv *priv,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002665 struct ieee80211_sta *sta,
2666 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002667{
Tomas Winklere227cea2008-07-18 13:53:05 +08002668 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002669 int rate_idx;
Guy Cohenaade00c2008-04-23 17:14:59 -07002670 int i;
Guy Cohen39e88502008-04-23 17:14:57 -07002671 u32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002672 u8 use_green = rs_use_green(sta);
Guy Cohenaade00c2008-04-23 17:14:59 -07002673 u8 active_tbl = 0;
2674 u8 valid_tx_ant;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002675 struct iwl_station_priv *sta_priv;
2676 struct iwl_rxon_context *ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002677
Johannes Berg4b7679a2008-09-18 18:14:18 +02002678 if (!sta || !lq_sta)
Johannes Berg7e6a5882010-08-23 10:46:46 +02002679 return;
2680
2681 sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002682 ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002683
Johannes Bergb7e35002008-09-11 02:22:58 +02002684 i = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002685
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002686 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Guy Cohenaade00c2008-04-23 17:14:59 -07002687
Tomas Winklerc33104f2008-01-14 17:46:21 -08002688 if (!lq_sta->search_better_tbl)
2689 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002690 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002691 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002692
Tomas Winklerc33104f2008-01-14 17:46:21 -08002693 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002694
2695 if ((i < 0) || (i >= IWL_RATE_COUNT))
2696 i = 0;
2697
Tomas Winkler1826dcc2008-05-15 13:54:02 +08002698 rate = iwl_rates[i].plcp;
Winkler, Tomaseb48dca2008-10-29 14:05:48 -07002699 tbl->ant_type = first_antenna(valid_tx_ant);
2700 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
Zhu Yib481de92007-09-25 17:54:57 -07002701
2702 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -07002703 rate |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002704
Guy Cohen39e88502008-04-23 17:14:57 -07002705 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
Guy Cohenaade00c2008-04-23 17:14:59 -07002706 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2707 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07002708
Tomas Winkler978785a2008-12-19 10:37:31 +08002709 rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green);
Guy Cohen39e88502008-04-23 17:14:57 -07002710 tbl->current_rate = rate;
Guy Coheneecd6e52008-04-23 17:14:58 -07002711 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002712 rs_fill_link_cmd(NULL, lq_sta, rate);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002713 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002714 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true);
Zhu Yib481de92007-09-25 17:54:57 -07002715}
2716
Johannes Berge6a98542008-10-21 12:40:02 +02002717static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2718 struct ieee80211_tx_rate_control *txrc)
Zhu Yib481de92007-09-25 17:54:57 -07002719{
2720
Johannes Berge6a98542008-10-21 12:40:02 +02002721 struct sk_buff *skb = txrc->skb;
2722 struct ieee80211_supported_band *sband = txrc->sband;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002723 struct iwl_op_mode *op_mode __maybe_unused =
2724 (struct iwl_op_mode *)priv_r;
2725 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge6a98542008-10-21 12:40:02 +02002726 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Tomas Winkler417f1142008-11-12 13:14:06 -08002727 struct iwl_lq_sta *lq_sta = priv_sta;
2728 int rate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002729
Tomas Winklere1623442009-01-27 14:27:56 -08002730 IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002731
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002732 /* Get max rate if user set max rate */
2733 if (lq_sta) {
2734 lq_sta->max_rate_idx = txrc->max_rate_idx;
2735 if ((sband->band == IEEE80211_BAND_5GHZ) &&
2736 (lq_sta->max_rate_idx != -1))
2737 lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
2738 if ((lq_sta->max_rate_idx < 0) ||
2739 (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
2740 lq_sta->max_rate_idx = -1;
2741 }
2742
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002743 /* Treat uninitialized rate scaling data same as non-existing. */
2744 if (lq_sta && !lq_sta->drv) {
2745 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
2746 priv_sta = NULL;
2747 }
2748
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002749 /* Send management frames and NO_ACK data using lowest rate. */
Luis R. Rodriguez4c6d4f52009-07-16 10:05:41 -07002750 if (rate_control_send_low(sta, priv_sta, txrc))
Johannes Berg4b7679a2008-09-18 18:14:18 +02002751 return;
Zhu Yib481de92007-09-25 17:54:57 -07002752
Tomas Winkler417f1142008-11-12 13:14:06 -08002753 rate_idx = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002754
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002755 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
Tomas Winkler417f1142008-11-12 13:14:06 -08002756 rate_idx -= IWL_FIRST_OFDM_RATE;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002757 /* 6M and 9M shared same MCS index */
2758 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2759 if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2760 IWL_RATE_MIMO3_6M_PLCP)
2761 rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
2762 else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2763 IWL_RATE_MIMO2_6M_PLCP)
2764 rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
2765 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2766 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2767 info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
2768 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2769 info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07002770 if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK)
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002771 info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2772 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2773 info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
2774 } else {
Daniel C Halperin50273092009-08-28 09:44:45 -07002775 /* Check for invalid rates */
2776 if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
2777 ((sband->band == IEEE80211_BAND_5GHZ) &&
2778 (rate_idx < IWL_FIRST_OFDM_RATE)))
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002779 rate_idx = rate_lowest_index(sband, sta);
Daniel C Halperin50273092009-08-28 09:44:45 -07002780 /* On valid 5 GHz rate, adjust index */
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002781 else if (sband->band == IEEE80211_BAND_5GHZ)
2782 rate_idx -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin7ebaeff2009-08-21 13:34:20 -07002783 info->control.rates[0].flags = 0;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002784 }
Tomas Winkler417f1142008-11-12 13:14:06 -08002785 info->control.rates[0].idx = rate_idx;
Moshe Benji622ebe92013-06-03 19:27:16 +03002786 info->control.rates[0].count = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002787}
2788
Johannes Berg4b7679a2008-09-18 18:14:18 +02002789static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2790 gfp_t gfp)
Zhu Yib481de92007-09-25 17:54:57 -07002791{
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002792 struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002793 struct iwl_op_mode *op_mode __maybe_unused =
2794 (struct iwl_op_mode *)priv_rate;
2795 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002796
Tomas Winklere1623442009-01-27 14:27:56 -08002797 IWL_DEBUG_RATE(priv, "create station rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -07002798
Johannes Berg08960de2011-04-05 09:41:53 -07002799 return &sta_priv->lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002800}
2801
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002802/*
2803 * Called after adding a new station to initialize rate scaling
2804 */
2805void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002806{
2807 int i, j;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002808 struct ieee80211_hw *hw = priv->hw;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002809 struct ieee80211_conf *conf = &priv->hw->conf;
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002810 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002811 struct iwl_station_priv *sta_priv;
2812 struct iwl_lq_sta *lq_sta;
2813 struct ieee80211_supported_band *sband;
Johannes Berg3ac40ed2012-03-08 09:18:04 +01002814 unsigned long supp; /* must be unsigned long for for_each_set_bit */
Zhu Yib481de92007-09-25 17:54:57 -07002815
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002816 sta_priv = (struct iwl_station_priv *) sta->drv_priv;
2817 lq_sta = &sta_priv->lq_sta;
Karl Beldan675a0b02013-03-25 16:26:57 +01002818 sband = hw->wiphy->bands[conf->chandef.chan->band];
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002819
2820
2821 lq_sta->lq.sta_id = sta_id;
Reinette Chatre5ad13f82009-10-30 14:36:14 -07002822
2823 for (j = 0; j < LQ_SIZE; j++)
2824 for (i = 0; i < IWL_RATE_COUNT; i++)
2825 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2826
Tomas Winklerc33104f2008-01-14 17:46:21 -08002827 lq_sta->flush_timer = 0;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002828 lq_sta->supp_rates = sta->supp_rates[sband->band];
Zhu Yib481de92007-09-25 17:54:57 -07002829
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002830 IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n",
2831 sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07002832 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2833 * the lowest or the highest rate.. Could consider using RSSI from
2834 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2835 * after assoc.. */
2836
Tomas Winklerc33104f2008-01-14 17:46:21 -08002837 lq_sta->is_dup = 0;
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002838 lq_sta->max_rate_idx = -1;
Abbas, Mohamed7d049e52009-01-20 21:33:53 -08002839 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002840 lq_sta->is_green = rs_use_green(sta);
Johannes Berg3ac40ed2012-03-08 09:18:04 +01002841 lq_sta->band = sband->band;
2842 /*
2843 * active legacy rates as per supported rates bitmap
2844 */
2845 supp = sta->supp_rates[sband->band];
2846 lq_sta->active_legacy_rate = 0;
2847 for_each_set_bit(i, &supp, BITS_PER_LONG)
2848 lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
2849
Ben Cahill77626352007-11-29 11:09:44 +08002850 /*
2851 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2852 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2853 */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002854 lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
2855 lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002856 lq_sta->active_siso_rate &= ~((u16)0x2);
2857 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07002858
Ben Cahill77626352007-11-29 11:09:44 +08002859 /* Same here */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002860 lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
2861 lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002862 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2863 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2864
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002865 lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
2866 lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002867 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2868 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2869
Tomas Winklere1623442009-01-27 14:27:56 -08002870 IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002871 lq_sta->active_siso_rate,
Guy Cohenfde0db32008-04-21 15:42:01 -07002872 lq_sta->active_mimo2_rate,
2873 lq_sta->active_mimo3_rate);
2874
Tomas Winklera96a27f2008-10-23 23:48:56 -07002875 /* These values will be overridden later */
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002876 lq_sta->lq.general_params.single_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002877 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002878 lq_sta->lq.general_params.dual_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002879 priv->nvm_data->valid_tx_ant &
2880 ~first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002881 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2882 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002883 } else if (num_of_ant(priv->nvm_data->valid_tx_ant) == 2) {
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002884 lq_sta->lq.general_params.dual_stream_ant_msk =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002885 priv->nvm_data->valid_tx_ant;
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002886 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002887
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002888 /* as default allow aggregation for all tids */
2889 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002890 lq_sta->drv = priv;
Zhu Yib481de92007-09-25 17:54:57 -07002891
Daniel C Halperin50273092009-08-28 09:44:45 -07002892 /* Set last_txrate_idx to lowest rate */
2893 lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
2894 if (sband->band == IEEE80211_BAND_5GHZ)
2895 lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
Daniel C Halperine3949d62009-09-17 10:43:50 -07002896 lq_sta->is_agg = 0;
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002897#ifdef CONFIG_MAC80211_DEBUGFS
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002898 lq_sta->dbg_fixed_rate = 0;
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002899#endif
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002900
Johannes Berg9b6ca442012-03-07 09:52:11 -08002901 rs_initialize_lq(priv, sta, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002902}
2903
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002904static void rs_fill_link_cmd(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08002905 struct iwl_lq_sta *lq_sta, u32 new_rate)
Zhu Yib481de92007-09-25 17:54:57 -07002906{
Tomas Winklere227cea2008-07-18 13:53:05 +08002907 struct iwl_scale_tbl_info tbl_type;
Zhu Yib481de92007-09-25 17:54:57 -07002908 int index = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002909 int rate_idx;
Zhu Yi1b696de2007-09-27 11:27:41 +08002910 int repeat_rate = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07002911 u8 ant_toggle_cnt = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002912 u8 use_ht_possible = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07002913 u8 valid_tx_ant = 0;
Johannes Berg7b090682011-01-19 02:53:54 -08002914 struct iwl_station_priv *sta_priv =
2915 container_of(lq_sta, struct iwl_station_priv, lq_sta);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002916 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
Zhu Yib481de92007-09-25 17:54:57 -07002917
Ben Cahill77626352007-11-29 11:09:44 +08002918 /* Override starting rate (index 0) if needed for debug purposes */
Guy Cohen39e88502008-04-23 17:14:57 -07002919 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Zhu Yi98d7e092007-09-27 11:27:42 +08002920
Guy Cohen39e88502008-04-23 17:14:57 -07002921 /* Interpret new_rate (rate_n_flags) */
2922 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
Zhu Yib481de92007-09-25 17:54:57 -07002923 &tbl_type, &rate_idx);
2924
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002925 if (priv && priv->bt_full_concurrent) {
2926 /* 1x1 only */
2927 tbl_type.ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002928 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002929 }
2930
Ben Cahill77626352007-11-29 11:09:44 +08002931 /* How many times should we repeat the initial rate? */
Zhu Yib481de92007-09-25 17:54:57 -07002932 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002933 ant_toggle_cnt = 1;
Zhu Yi1b696de2007-09-27 11:27:41 +08002934 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07002935 } else {
Daniel Halperin374920c2011-03-16 19:16:36 -07002936 repeat_rate = min(IWL_HT_NUMBER_TRY,
2937 LINK_QUAL_AGG_DISABLE_START_DEF - 1);
Guy Cohenaade00c2008-04-23 17:14:59 -07002938 }
Zhu Yib481de92007-09-25 17:54:57 -07002939
2940 lq_cmd->general_params.mimo_delimiter =
2941 is_mimo(tbl_type.lq_type) ? 1 : 0;
Ben Cahill77626352007-11-29 11:09:44 +08002942
2943 /* Fill 1st table entry (index 0) */
Guy Cohen39e88502008-04-23 17:14:57 -07002944 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002945
Guy Cohen07bc28e2008-04-23 17:15:03 -07002946 if (num_of_ant(tbl_type.ant_type) == 1) {
2947 lq_cmd->general_params.single_stream_ant_msk =
2948 tbl_type.ant_type;
2949 } else if (num_of_ant(tbl_type.ant_type) == 2) {
2950 lq_cmd->general_params.dual_stream_ant_msk =
2951 tbl_type.ant_type;
2952 } /* otherwise we don't modify the existing value */
Zhu Yib481de92007-09-25 17:54:57 -07002953
2954 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08002955 repeat_rate--;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002956 if (priv) {
2957 if (priv->bt_full_concurrent)
2958 valid_tx_ant = ANT_A;
2959 else
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002960 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002961 }
Guy Cohenaade00c2008-04-23 17:14:59 -07002962
Ben Cahill77626352007-11-29 11:09:44 +08002963 /* Fill rest of rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002964 while (index < LINK_QUAL_MAX_RETRY_NUM) {
Ben Cahill77626352007-11-29 11:09:44 +08002965 /* Repeat initial/next rate.
2966 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2967 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
Zhu Yi1b696de2007-09-27 11:27:41 +08002968 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
Zhu Yib481de92007-09-25 17:54:57 -07002969 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002970 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2971 ant_toggle_cnt++;
2972 else if (priv &&
2973 rs_toggle_antenna(valid_tx_ant,
2974 &new_rate, &tbl_type))
2975 ant_toggle_cnt = 1;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002976 }
Zhu Yi98d7e092007-09-27 11:27:42 +08002977
Ben Cahill77626352007-11-29 11:09:44 +08002978 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002979 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08002980
2981 /* Fill next table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002982 lq_cmd->rs_table[index].rate_n_flags =
Guy Cohen39e88502008-04-23 17:14:57 -07002983 cpu_to_le32(new_rate);
Zhu Yi1b696de2007-09-27 11:27:41 +08002984 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07002985 index++;
2986 }
2987
Guy Cohen39e88502008-04-23 17:14:57 -07002988 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
Zhu Yib481de92007-09-25 17:54:57 -07002989 &rate_idx);
2990
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002991 if (priv && priv->bt_full_concurrent) {
2992 /* 1x1 only */
2993 tbl_type.ant_type =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002994 first_antenna(priv->nvm_data->valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002995 }
2996
Ben Cahill77626352007-11-29 11:09:44 +08002997 /* Indicate to uCode which entries might be MIMO.
2998 * If initial rate was MIMO, this will finally end up
2999 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
Zhu Yib481de92007-09-25 17:54:57 -07003000 if (is_mimo(tbl_type.lq_type))
3001 lq_cmd->general_params.mimo_delimiter = index;
3002
Ben Cahill77626352007-11-29 11:09:44 +08003003 /* Get next rate */
Guy Cohen39e88502008-04-23 17:14:57 -07003004 new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
3005 use_ht_possible);
Zhu Yib481de92007-09-25 17:54:57 -07003006
Ben Cahill77626352007-11-29 11:09:44 +08003007 /* How many times should we repeat the next rate? */
Zhu Yib481de92007-09-25 17:54:57 -07003008 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07003009 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
3010 ant_toggle_cnt++;
3011 else if (priv &&
3012 rs_toggle_antenna(valid_tx_ant,
3013 &new_rate, &tbl_type))
3014 ant_toggle_cnt = 1;
3015
Zhu Yi1b696de2007-09-27 11:27:41 +08003016 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003017 } else {
Zhu Yi1b696de2007-09-27 11:27:41 +08003018 repeat_rate = IWL_HT_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003019 }
Zhu Yib481de92007-09-25 17:54:57 -07003020
Ben Cahill77626352007-11-29 11:09:44 +08003021 /* Don't allow HT rates after next pass.
3022 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
Zhu Yib481de92007-09-25 17:54:57 -07003023 use_ht_possible = 0;
3024
Ben Cahill77626352007-11-29 11:09:44 +08003025 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08003026 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08003027
3028 /* Fill next table entry */
Guy Cohen39e88502008-04-23 17:14:57 -07003029 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07003030
3031 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08003032 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07003033 }
3034
Johannes Berg7b090682011-01-19 02:53:54 -08003035 lq_cmd->agg_params.agg_frame_cnt_limit =
3036 sta_priv->max_agg_bufsize ?: LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003037 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
Wey-Yi Guy74697012010-07-28 09:18:54 -07003038
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003039 lq_cmd->agg_params.agg_time_limit =
3040 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
Wey-Yi Guy74697012010-07-28 09:18:54 -07003041 /*
3042 * overwrite if needed, pass aggregation time limit
3043 * to uCode in uSec
3044 */
Johannes Berg0d8877a2013-05-17 10:36:29 +02003045 if (priv && priv->lib->bt_params &&
3046 priv->lib->bt_params->agg_time_limit &&
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08003047 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
Wey-Yi Guy74697012010-07-28 09:18:54 -07003048 lq_cmd->agg_params.agg_time_limit =
Johannes Berg0d8877a2013-05-17 10:36:29 +02003049 cpu_to_le16(priv->lib->bt_params->agg_time_limit);
Zhu Yib481de92007-09-25 17:54:57 -07003050}
3051
Johannes Berg4b7679a2008-09-18 18:14:18 +02003052static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Zhu Yib481de92007-09-25 17:54:57 -07003053{
Johannes Berg4b7679a2008-09-18 18:14:18 +02003054 return hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003055}
3056/* rate scale requires free function to be implemented */
3057static void rs_free(void *priv_rate)
3058{
3059 return;
3060}
3061
Johannes Berg4b7679a2008-09-18 18:14:18 +02003062static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
3063 void *priv_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003064{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02003065 struct iwl_op_mode *op_mode __maybe_unused = priv_r;
3066 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003067
Tomas Winklere1623442009-01-27 14:27:56 -08003068 IWL_DEBUG_RATE(priv, "enter\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003069 IWL_DEBUG_RATE(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003070}
3071
Zhu Yi93dc6462007-09-27 11:27:37 +08003072#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklere227cea2008-07-18 13:53:05 +08003073static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
3074 u32 *rate_n_flags, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +08003075{
Ester Kummerbf403db2008-05-05 10:22:40 +08003076 struct iwl_priv *priv;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003077 u8 valid_tx_ant;
3078 u8 ant_sel_tx;
Ester Kummerbf403db2008-05-05 10:22:40 +08003079
3080 priv = lq_sta->drv;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02003081 valid_tx_ant = priv->nvm_data->valid_tx_ant;
Guy Cohen39e88502008-04-23 17:14:57 -07003082 if (lq_sta->dbg_fixed_rate) {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003083 ant_sel_tx =
3084 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
3085 >> RATE_MCS_ANT_POS);
3086 if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
Guy Cohen39e88502008-04-23 17:14:57 -07003087 *rate_n_flags = lq_sta->dbg_fixed_rate;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003088 IWL_DEBUG_RATE(priv, "Fixed rate ON\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003089 } else {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003090 lq_sta->dbg_fixed_rate = 0;
3091 IWL_ERR(priv,
3092 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
3093 ant_sel_tx, valid_tx_ant);
3094 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003095 }
Guy Cohen39e88502008-04-23 17:14:57 -07003096 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08003097 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Zhu Yi98d7e092007-09-27 11:27:42 +08003098 }
Zhu Yi98d7e092007-09-27 11:27:42 +08003099}
3100
3101static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
3102 const char __user *user_buf, size_t count, loff_t *ppos)
3103{
Tomas Winklere227cea2008-07-18 13:53:05 +08003104 struct iwl_lq_sta *lq_sta = file->private_data;
Ester Kummerbf403db2008-05-05 10:22:40 +08003105 struct iwl_priv *priv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003106 char buf[64];
Stephen Boyd805d7d22011-05-12 16:50:05 -07003107 size_t buf_size;
Zhu Yi98d7e092007-09-27 11:27:42 +08003108 u32 parsed_rate;
Wey-Yi Guy64898542011-05-03 18:05:13 -07003109
Zhu Yi98d7e092007-09-27 11:27:42 +08003110
Ester Kummerbf403db2008-05-05 10:22:40 +08003111 priv = lq_sta->drv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003112 memset(buf, 0, sizeof(buf));
3113 buf_size = min(count, sizeof(buf) - 1);
3114 if (copy_from_user(buf, user_buf, buf_size))
3115 return -EFAULT;
3116
3117 if (sscanf(buf, "%x", &parsed_rate) == 1)
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003118 lq_sta->dbg_fixed_rate = parsed_rate;
Zhu Yi98d7e092007-09-27 11:27:42 +08003119 else
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003120 lq_sta->dbg_fixed_rate = 0;
Zhu Yi98d7e092007-09-27 11:27:42 +08003121
Wey-Yi Guy64898542011-05-03 18:05:13 -07003122 rs_program_fix_rate(priv, lq_sta);
Zhu Yi98d7e092007-09-27 11:27:42 +08003123
3124 return count;
3125}
Zhu Yi0209dc12007-09-27 11:27:43 +08003126
Zhu Yi5ae212c2007-09-27 11:27:38 +08003127static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
3128 char __user *user_buf, size_t count, loff_t *ppos)
3129{
Frank Seidela412c802009-03-01 20:25:38 +01003130 char *buff;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003131 int desc = 0;
3132 int i = 0;
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003133 int index = 0;
Frank Seidela412c802009-03-01 20:25:38 +01003134 ssize_t ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003135
Tomas Winklere227cea2008-07-18 13:53:05 +08003136 struct iwl_lq_sta *lq_sta = file->private_data;
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003137 struct iwl_priv *priv;
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003138 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003139
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003140 priv = lq_sta->drv;
Frank Seidela412c802009-03-01 20:25:38 +01003141 buff = kmalloc(1024, GFP_KERNEL);
3142 if (!buff)
3143 return -ENOMEM;
3144
Tomas Winklerc33104f2008-01-14 17:46:21 -08003145 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
Zhu Yi98d7e092007-09-27 11:27:42 +08003146 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003147 lq_sta->total_failed, lq_sta->total_success,
Guy Cohen39e88502008-04-23 17:14:57 -07003148 lq_sta->active_legacy_rate);
Zhu Yi98d7e092007-09-27 11:27:42 +08003149 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003150 lq_sta->dbg_fixed_rate);
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003151 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02003152 (priv->nvm_data->valid_tx_ant & ANT_A) ? "ANT_A," : "",
3153 (priv->nvm_data->valid_tx_ant & ANT_B) ? "ANT_B," : "",
3154 (priv->nvm_data->valid_tx_ant & ANT_C) ? "ANT_C" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003155 desc += sprintf(buff+desc, "lq type %s\n",
3156 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
3157 if (is_Ht(tbl->lq_type)) {
3158 desc += sprintf(buff+desc, " %s",
3159 (is_siso(tbl->lq_type)) ? "SISO" :
3160 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
3161 desc += sprintf(buff+desc, " %s",
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003162 (tbl->is_ht40) ? "40MHz" : "20MHz");
Daniel C Halperine3949d62009-09-17 10:43:50 -07003163 desc += sprintf(buff+desc, " %s %s %s\n", (tbl->is_SGI) ? "SGI" : "",
3164 (lq_sta->is_green) ? "GF enabled" : "",
3165 (lq_sta->is_agg) ? "AGG on" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003166 }
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003167 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
3168 lq_sta->last_rate_n_flags);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003169 desc += sprintf(buff+desc, "general:"
3170 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003171 lq_sta->lq.general_params.flags,
3172 lq_sta->lq.general_params.mimo_delimiter,
3173 lq_sta->lq.general_params.single_stream_ant_msk,
3174 lq_sta->lq.general_params.dual_stream_ant_msk);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003175
3176 desc += sprintf(buff+desc, "agg:"
3177 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003178 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
3179 lq_sta->lq.agg_params.agg_dis_start_th,
3180 lq_sta->lq.agg_params.agg_frame_cnt_limit);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003181
3182 desc += sprintf(buff+desc,
3183 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003184 lq_sta->lq.general_params.start_rate_index[0],
3185 lq_sta->lq.general_params.start_rate_index[1],
3186 lq_sta->lq.general_params.start_rate_index[2],
3187 lq_sta->lq.general_params.start_rate_index[3]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003188
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003189 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
3190 index = iwl_hwrate_to_plcp_idx(
3191 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
3192 if (is_legacy(tbl->lq_type)) {
3193 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
3194 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3195 iwl_rate_mcs[index].mbps);
3196 } else {
3197 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
3198 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3199 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
3200 }
3201 }
Zhu Yi5ae212c2007-09-27 11:27:38 +08003202
Frank Seidela412c802009-03-01 20:25:38 +01003203 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3204 kfree(buff);
3205 return ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003206}
3207
3208static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
Zhu Yi98d7e092007-09-27 11:27:42 +08003209 .write = rs_sta_dbgfs_scale_table_write,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003210 .read = rs_sta_dbgfs_scale_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003211 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003212 .llseek = default_llseek,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003213};
Zhu Yi0209dc12007-09-27 11:27:43 +08003214static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
3215 char __user *user_buf, size_t count, loff_t *ppos)
3216{
Frank Seidela412c802009-03-01 20:25:38 +01003217 char *buff;
Zhu Yi0209dc12007-09-27 11:27:43 +08003218 int desc = 0;
3219 int i, j;
Frank Seidela412c802009-03-01 20:25:38 +01003220 ssize_t ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003221
Tomas Winklere227cea2008-07-18 13:53:05 +08003222 struct iwl_lq_sta *lq_sta = file->private_data;
Frank Seidela412c802009-03-01 20:25:38 +01003223
3224 buff = kmalloc(1024, GFP_KERNEL);
3225 if (!buff)
3226 return -ENOMEM;
3227
Zhu Yi0209dc12007-09-27 11:27:43 +08003228 for (i = 0; i < LQ_SIZE; i++) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003229 desc += sprintf(buff+desc,
3230 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
Zhu Yi0209dc12007-09-27 11:27:43 +08003231 "rate=0x%X\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003232 lq_sta->active_tbl == i ? "*" : "x",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003233 lq_sta->lq_info[i].lq_type,
3234 lq_sta->lq_info[i].is_SGI,
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003235 lq_sta->lq_info[i].is_ht40,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003236 lq_sta->lq_info[i].is_dup,
Wey-Yi Guy2681b202009-05-21 13:44:22 -07003237 lq_sta->is_green,
Guy Cohen39e88502008-04-23 17:14:57 -07003238 lq_sta->lq_info[i].current_rate);
Zhu Yi0209dc12007-09-27 11:27:43 +08003239 for (j = 0; j < IWL_RATE_COUNT; j++) {
3240 desc += sprintf(buff+desc,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003241 "counter=%d success=%d %%=%d\n",
3242 lq_sta->lq_info[i].win[j].counter,
3243 lq_sta->lq_info[i].win[j].success_counter,
3244 lq_sta->lq_info[i].win[j].success_ratio);
Zhu Yi0209dc12007-09-27 11:27:43 +08003245 }
3246 }
Frank Seidela412c802009-03-01 20:25:38 +01003247 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3248 kfree(buff);
3249 return ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003250}
3251
3252static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
3253 .read = rs_sta_dbgfs_stats_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003254 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003255 .llseek = default_llseek,
Zhu Yi0209dc12007-09-27 11:27:43 +08003256};
Zhu Yi5ae212c2007-09-27 11:27:38 +08003257
Wey-Yi Guy38167452009-05-08 13:44:43 -07003258static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3259 char __user *user_buf, size_t count, loff_t *ppos)
3260{
Johannes Berg70817b52011-05-11 03:29:25 -07003261 struct iwl_lq_sta *lq_sta = file->private_data;
3262 struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
Wey-Yi Guy38167452009-05-08 13:44:43 -07003263 char buff[120];
3264 int desc = 0;
Wey-Yi Guy38167452009-05-08 13:44:43 -07003265
Wey-Yi Guy38167452009-05-08 13:44:43 -07003266 if (is_Ht(tbl->lq_type))
3267 desc += sprintf(buff+desc,
3268 "Bit Rate= %d Mb/s\n",
3269 tbl->expected_tpt[lq_sta->last_txrate_idx]);
3270 else
3271 desc += sprintf(buff+desc,
3272 "Bit Rate= %d Mb/s\n",
3273 iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003274
Johannes Berg08960de2011-04-05 09:41:53 -07003275 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003276}
3277
3278static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3279 .read = rs_sta_dbgfs_rate_scale_data_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003280 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003281 .llseek = default_llseek,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003282};
3283
Zhu Yi93dc6462007-09-27 11:27:37 +08003284static void rs_add_debugfs(void *priv, void *priv_sta,
3285 struct dentry *dir)
3286{
Tomas Winklere227cea2008-07-18 13:53:05 +08003287 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003288 lq_sta->rs_sta_dbgfs_scale_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003289 debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003290 lq_sta, &rs_sta_dbgfs_scale_table_ops);
3291 lq_sta->rs_sta_dbgfs_stats_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003292 debugfs_create_file("rate_stats_table", S_IRUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003293 lq_sta, &rs_sta_dbgfs_stats_table_ops);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003294 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003295 debugfs_create_file("rate_scale_data", S_IRUSR, dir,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003296 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003297 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003298 debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003299 &lq_sta->tx_agg_tid_en);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003300
Zhu Yi93dc6462007-09-27 11:27:37 +08003301}
3302
3303static void rs_remove_debugfs(void *priv, void *priv_sta)
3304{
Tomas Winklere227cea2008-07-18 13:53:05 +08003305 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003306 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
3307 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003308 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003309 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
Zhu Yi93dc6462007-09-27 11:27:37 +08003310}
3311#endif
3312
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003313/*
3314 * Initialization of rate scaling information is done by driver after
3315 * the station is added. Since mac80211 calls this function before a
3316 * station is added we ignore it.
3317 */
3318static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband,
Simon Wunderlich3de805c2013-07-08 16:55:50 +02003319 struct cfg80211_chan_def *chandef,
3320 struct ieee80211_sta *sta, void *priv_sta)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003321{
3322}
Zhu Yib481de92007-09-25 17:54:57 -07003323static struct rate_control_ops rs_ops = {
3324 .module = NULL,
3325 .name = RS_NAME,
3326 .tx_status = rs_tx_status,
3327 .get_rate = rs_get_rate,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003328 .rate_init = rs_rate_init_stub,
Zhu Yib481de92007-09-25 17:54:57 -07003329 .alloc = rs_alloc,
3330 .free = rs_free,
3331 .alloc_sta = rs_alloc_sta,
3332 .free_sta = rs_free_sta,
Zhu Yi93dc6462007-09-27 11:27:37 +08003333#ifdef CONFIG_MAC80211_DEBUGFS
3334 .add_sta_debugfs = rs_add_debugfs,
3335 .remove_sta_debugfs = rs_remove_debugfs,
3336#endif
Zhu Yib481de92007-09-25 17:54:57 -07003337};
3338
Tomas Winklere227cea2008-07-18 13:53:05 +08003339int iwlagn_rate_control_register(void)
Zhu Yib481de92007-09-25 17:54:57 -07003340{
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003341 return ieee80211_rate_control_register(&rs_ops);
Zhu Yib481de92007-09-25 17:54:57 -07003342}
3343
Tomas Winklere227cea2008-07-18 13:53:05 +08003344void iwlagn_rate_control_unregister(void)
Zhu Yib481de92007-09-25 17:54:57 -07003345{
3346 ieee80211_rate_control_unregister(&rs_ops);
3347}
3348