blob: 7e590b349dd7523f76db4c1ff235c53b5434d71b [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Wey-Yi Guyfb4961d2012-01-06 13:16:33 -08003 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080022 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070023 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/skbuff.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070030#include <net/mac80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070031
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/delay.h>
35
36#include <linux/workqueue.h>
37
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Tomas Winkler857485c2008-03-21 13:53:44 -070039#include "iwl-core.h"
Johannes Berga30e3112010-09-22 18:02:01 +020040#include "iwl-agn.h"
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +020041#include "iwl-op-mode.h"
Zhu Yib481de92007-09-25 17:54:57 -070042
Tomas Winklere227cea2008-07-18 13:53:05 +080043#define RS_NAME "iwl-agn-rs"
Zhu Yib481de92007-09-25 17:54:57 -070044
Guy Cohenaade00c2008-04-23 17:14:59 -070045#define NUM_TRY_BEFORE_ANT_TOGGLE 1
Zhu Yib481de92007-09-25 17:54:57 -070046#define IWL_NUMBER_TRY 1
47#define IWL_HT_NUMBER_TRY 3
48
Ben Cahill77626352007-11-29 11:09:44 +080049#define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
50#define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
51#define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
52
Abbas, Mohamed7d049e52009-01-20 21:33:53 -080053/* max allowed rate miss before sync LQ cmd */
54#define IWL_MISSED_RATE_MAX 15
Ben Cahill77626352007-11-29 11:09:44 +080055/* max time to accum history 2 seconds */
Mohamed Abbas447fee72009-04-20 14:37:02 -070056#define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
Zhu Yib481de92007-09-25 17:54:57 -070057
58static u8 rs_ht_to_legacy[] = {
59 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
60 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
61 IWL_RATE_6M_INDEX,
62 IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
63 IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
64 IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
65 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
66};
67
Guy Cohenaade00c2008-04-23 17:14:59 -070068static const u8 ant_toggle_lookup[] = {
69 /*ANT_NONE -> */ ANT_NONE,
70 /*ANT_A -> */ ANT_B,
71 /*ANT_B -> */ ANT_C,
72 /*ANT_AB -> */ ANT_BC,
73 /*ANT_C -> */ ANT_A,
74 /*ANT_AC -> */ ANT_AB,
75 /*ANT_BC -> */ ANT_AC,
76 /*ANT_ABC -> */ ANT_ABC,
77};
78
Johannes Berg635b85b2010-09-22 18:02:04 +020079#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
80 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
81 IWL_RATE_SISO_##s##M_PLCP, \
82 IWL_RATE_MIMO2_##s##M_PLCP,\
83 IWL_RATE_MIMO3_##s##M_PLCP,\
84 IWL_RATE_##r##M_IEEE, \
85 IWL_RATE_##ip##M_INDEX, \
86 IWL_RATE_##in##M_INDEX, \
87 IWL_RATE_##rp##M_INDEX, \
88 IWL_RATE_##rn##M_INDEX, \
89 IWL_RATE_##pp##M_INDEX, \
90 IWL_RATE_##np##M_INDEX }
91
92/*
93 * Parameter order:
94 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
95 *
96 * If there isn't a valid next or previous rate then INV is used which
97 * maps to IWL_RATE_INVALID
98 *
99 */
100const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
101 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
102 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
103 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
104 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
105 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
106 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
107 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
108 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
109 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
110 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
111 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
112 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
113 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
114 /* FIXME:RS: ^^ should be INV (legacy) */
115};
116
Daniel Halperin25205462011-03-18 18:48:55 -0700117static inline u8 rs_extract_rate(u32 rate_n_flags)
118{
119 return (u8)(rate_n_flags & RATE_MCS_RATE_MSK);
120}
121
Johannes Berg635b85b2010-09-22 18:02:04 +0200122static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
123{
124 int idx = 0;
125
126 /* HT rate format */
127 if (rate_n_flags & RATE_MCS_HT_MSK) {
Daniel Halperin25205462011-03-18 18:48:55 -0700128 idx = rs_extract_rate(rate_n_flags);
Johannes Berg635b85b2010-09-22 18:02:04 +0200129
130 if (idx >= IWL_RATE_MIMO3_6M_PLCP)
131 idx = idx - IWL_RATE_MIMO3_6M_PLCP;
132 else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
133 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
134
135 idx += IWL_FIRST_OFDM_RATE;
136 /* skip 9M not supported in ht*/
137 if (idx >= IWL_RATE_9M_INDEX)
138 idx += 1;
139 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
140 return idx;
141
142 /* legacy rate format, search for match in table */
143 } else {
144 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
Daniel Halperin25205462011-03-18 18:48:55 -0700145 if (iwl_rates[idx].plcp ==
146 rs_extract_rate(rate_n_flags))
Johannes Berg635b85b2010-09-22 18:02:04 +0200147 return idx;
148 }
149
150 return -1;
151}
152
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700153static void rs_rate_scale_perform(struct iwl_priv *priv,
Gábor Stefanik514d65c2009-04-23 19:36:08 +0200154 struct sk_buff *skb,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200155 struct ieee80211_sta *sta,
156 struct iwl_lq_sta *lq_sta);
Wey-Yi Guy46f93812009-07-24 11:13:03 -0700157static void rs_fill_link_cmd(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +0800158 struct iwl_lq_sta *lq_sta, u32 rate_n_flags);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -0700159static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search);
Zhu Yib481de92007-09-25 17:54:57 -0700160
161
Zhu Yi98d7e092007-09-27 11:27:42 +0800162#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklere227cea2008-07-18 13:53:05 +0800163static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
164 u32 *rate_n_flags, int index);
Zhu Yi98d7e092007-09-27 11:27:42 +0800165#else
Tomas Winklere227cea2008-07-18 13:53:05 +0800166static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
167 u32 *rate_n_flags, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +0800168{}
169#endif
Ben Cahill77626352007-11-29 11:09:44 +0800170
Daniel C Halperine3949d62009-09-17 10:43:50 -0700171/**
172 * The following tables contain the expected throughput metrics for all rates
173 *
174 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
175 *
176 * where invalid entries are zeros.
177 *
178 * CCK rates are only valid in legacy table and will only be used in G
179 * (2.4 GHz) band.
Ben Cahill77626352007-11-29 11:09:44 +0800180 */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -0700181
Daniel C Halperine3949d62009-09-17 10:43:50 -0700182static s32 expected_tpt_legacy[IWL_RATE_COUNT] = {
183 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0
Zhu Yib481de92007-09-25 17:54:57 -0700184};
185
Daniel C Halperine3949d62009-09-17 10:43:50 -0700186static s32 expected_tpt_siso20MHz[4][IWL_RATE_COUNT] = {
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800187 {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202}, /* Norm */
188 {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210}, /* SGI */
189 {0, 0, 0, 0, 47, 0, 91, 133, 171, 242, 305, 334, 362}, /* AGG */
190 {0, 0, 0, 0, 52, 0, 101, 145, 187, 264, 330, 361, 390}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700191};
192
Daniel C Halperine3949d62009-09-17 10:43:50 -0700193static s32 expected_tpt_siso40MHz[4][IWL_RATE_COUNT] = {
194 {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */
195 {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800196 {0, 0, 0, 0, 94, 0, 177, 249, 313, 423, 512, 550, 586}, /* AGG */
197 {0, 0, 0, 0, 104, 0, 193, 270, 338, 454, 545, 584, 620}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700198};
199
Daniel C Halperine3949d62009-09-17 10:43:50 -0700200static s32 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = {
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800201 {0, 0, 0, 0, 74, 0, 123, 155, 179, 214, 236, 244, 251}, /* Norm */
202 {0, 0, 0, 0, 81, 0, 131, 164, 188, 223, 243, 251, 257}, /* SGI */
203 {0, 0, 0, 0, 89, 0, 167, 235, 296, 402, 488, 526, 560}, /* AGG */
204 {0, 0, 0, 0, 97, 0, 182, 255, 320, 431, 520, 558, 593}, /* AGG+SGI*/
Zhu Yib481de92007-09-25 17:54:57 -0700205};
206
Daniel C Halperine3949d62009-09-17 10:43:50 -0700207static s32 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = {
208 {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */
209 {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */
Wey-Yi Guy7fc11e92011-01-15 09:16:59 -0800210 {0, 0, 0, 0, 171, 0, 305, 410, 496, 634, 731, 771, 805}, /* AGG */
211 {0, 0, 0, 0, 186, 0, 329, 439, 527, 667, 764, 803, 838}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700212};
213
Daniel C Halperine3949d62009-09-17 10:43:50 -0700214static s32 expected_tpt_mimo3_20MHz[4][IWL_RATE_COUNT] = {
215 {0, 0, 0, 0, 99, 0, 153, 186, 208, 239, 256, 263, 268}, /* Norm */
216 {0, 0, 0, 0, 106, 0, 162, 194, 215, 246, 262, 268, 273}, /* SGI */
217 {0, 0, 0, 0, 134, 0, 249, 346, 431, 574, 685, 732, 775}, /* AGG */
218 {0, 0, 0, 0, 148, 0, 272, 376, 465, 614, 727, 775, 818}, /* AGG+SGI */
Zhu Yib481de92007-09-25 17:54:57 -0700219};
220
Daniel C Halperine3949d62009-09-17 10:43:50 -0700221static s32 expected_tpt_mimo3_40MHz[4][IWL_RATE_COUNT] = {
222 {0, 0, 0, 0, 152, 0, 211, 239, 255, 279, 290, 294, 297}, /* Norm */
223 {0, 0, 0, 0, 160, 0, 219, 245, 261, 284, 294, 297, 300}, /* SGI */
224 {0, 0, 0, 0, 254, 0, 443, 584, 695, 868, 984, 1030, 1070}, /* AGG */
225 {0, 0, 0, 0, 277, 0, 478, 624, 737, 911, 1026, 1070, 1109}, /* AGG+SGI */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -0700226};
227
Wey-Yi Guy12b96812009-04-08 11:39:27 -0700228/* mbps, mcs */
Tobias Klauser79496732009-12-23 14:18:11 +0100229static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
Daniel C Halperine3949d62009-09-17 10:43:50 -0700230 { "1", "BPSK DSSS"},
231 { "2", "QPSK DSSS"},
232 {"5.5", "BPSK CCK"},
233 { "11", "QPSK CCK"},
234 { "6", "BPSK 1/2"},
235 { "9", "BPSK 1/2"},
236 { "12", "QPSK 1/2"},
237 { "18", "QPSK 3/4"},
238 { "24", "16QAM 1/2"},
239 { "36", "16QAM 3/4"},
240 { "48", "64QAM 2/3"},
241 { "54", "64QAM 3/4"},
242 { "60", "64QAM 5/6"},
Wey-Yi Guy12b96812009-04-08 11:39:27 -0700243};
244
Wey-Yi Guya9c146b2009-05-22 11:01:48 -0700245#define MCS_INDEX_PER_STREAM (8)
246
Tomas Winklere227cea2008-07-18 13:53:05 +0800247static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
Zhu Yib481de92007-09-25 17:54:57 -0700248{
249 window->data = 0;
250 window->success_counter = 0;
251 window->success_ratio = IWL_INVALID_VALUE;
252 window->counter = 0;
253 window->average_tpt = IWL_INVALID_VALUE;
254 window->stamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700255}
256
Guy Cohenaade00c2008-04-23 17:14:59 -0700257static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
258{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300259 return (ant_type & valid_antenna) == ant_type;
Guy Cohenaade00c2008-04-23 17:14:59 -0700260}
261
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200262/*
263 * removes the old data from the statistics. All data that is older than
264 * TID_MAX_TIME_DIFF, will be deleted.
265 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800266static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200267{
268 /* The oldest age we want to keep */
269 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
270
271 while (tl->queue_count &&
272 (tl->time_stamp < oldest_time)) {
273 tl->total -= tl->packet_count[tl->head];
274 tl->packet_count[tl->head] = 0;
275 tl->time_stamp += TID_QUEUE_CELL_SPACING;
276 tl->queue_count--;
277 tl->head++;
278 if (tl->head >= TID_QUEUE_MAX_SIZE)
279 tl->head = 0;
280 }
281}
282
283/*
284 * increment traffic load value for tid and also remove
285 * any old values if passed the certain time period
286 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800287static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data,
Ron Rindjunskyfaa29712008-06-12 09:46:58 +0800288 struct ieee80211_hdr *hdr)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200289{
290 u32 curr_time = jiffies_to_msecs(jiffies);
291 u32 time_diff;
292 s32 index;
Tomas Winklere227cea2008-07-18 13:53:05 +0800293 struct iwl_traffic_load *tl = NULL;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800294 u8 tid;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200295
Tomas Winkler417f1142008-11-12 13:14:06 -0800296 if (ieee80211_is_data_qos(hdr->frame_control)) {
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700297 u8 *qc = ieee80211_get_qos_ctl(hdr);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800298 tid = qc[0] & 0xf;
299 } else
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700300 return IWL_MAX_TID_COUNT;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200301
Johannes Berga8448552011-12-02 12:25:12 -0800302 if (unlikely(tid >= IWL_MAX_TID_COUNT))
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700303 return IWL_MAX_TID_COUNT;
Reinette Chatree6a6cf42009-08-13 13:30:50 -0700304
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200305 tl = &lq_data->load[tid];
306
307 curr_time -= curr_time % TID_ROUND_VALUE;
308
309 /* Happens only for the first packet. Initialize the data */
310 if (!(tl->queue_count)) {
311 tl->total = 1;
312 tl->time_stamp = curr_time;
313 tl->queue_count = 1;
314 tl->head = 0;
315 tl->packet_count[0] = 1;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700316 return IWL_MAX_TID_COUNT;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200317 }
318
319 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
320 index = time_diff / TID_QUEUE_CELL_SPACING;
321
322 /* The history is too long: remove data that is older than */
323 /* TID_MAX_TIME_DIFF */
324 if (index >= TID_QUEUE_MAX_SIZE)
325 rs_tl_rm_old_stats(tl, curr_time);
326
327 index = (tl->head + index) % TID_QUEUE_MAX_SIZE;
328 tl->packet_count[index] = tl->packet_count[index] + 1;
329 tl->total = tl->total + 1;
330
331 if ((index + 1) > tl->queue_count)
332 tl->queue_count = index + 1;
Ron Rindjunskyfaa29712008-06-12 09:46:58 +0800333
334 return tid;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200335}
336
Wey-Yi Guy54a430c2011-05-20 11:56:18 -0700337#ifdef CONFIG_MAC80211_DEBUGFS
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700338/**
339 * Program the device to use fixed rate for frame transmit
340 * This is for debugging/testing only
341 * once the device start use fixed rate, we need to reload the module
342 * to being back the normal operation.
343 */
Wey-Yi Guy64898542011-05-03 18:05:13 -0700344static void rs_program_fix_rate(struct iwl_priv *priv,
345 struct iwl_lq_sta *lq_sta)
346{
347 struct iwl_station_priv *sta_priv =
348 container_of(lq_sta, struct iwl_station_priv, lq_sta);
Johannes Bergc6892902011-09-20 15:37:21 -0700349 struct iwl_rxon_context *ctx = sta_priv->ctx;
Wey-Yi Guy64898542011-05-03 18:05:13 -0700350
351 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
352 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
353 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
354 lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
355
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -0800356#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700357 /* testmode has higher priority to overwirte the fixed rate */
358 if (priv->tm_fixed_rate)
359 lq_sta->dbg_fixed_rate = priv->tm_fixed_rate;
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -0700360#endif
Wey-Yi Guy64898542011-05-03 18:05:13 -0700361
362 IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700363 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700364
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700365 if (lq_sta->dbg_fixed_rate) {
366 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
Wey-Yi Guy64898542011-05-03 18:05:13 -0700367 iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
368 false);
369 }
370}
371#endif
372
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200373/*
374 get the traffic load value for tid
375*/
Tomas Winklere227cea2008-07-18 13:53:05 +0800376static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200377{
378 u32 curr_time = jiffies_to_msecs(jiffies);
379 u32 time_diff;
380 s32 index;
Tomas Winklere227cea2008-07-18 13:53:05 +0800381 struct iwl_traffic_load *tl = NULL;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200382
Johannes Berga8448552011-12-02 12:25:12 -0800383 if (tid >= IWL_MAX_TID_COUNT)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200384 return 0;
385
386 tl = &(lq_data->load[tid]);
387
388 curr_time -= curr_time % TID_ROUND_VALUE;
389
390 if (!(tl->queue_count))
391 return 0;
392
393 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
394 index = time_diff / TID_QUEUE_CELL_SPACING;
395
396 /* The history is too long: remove data that is older than */
397 /* TID_MAX_TIME_DIFF */
398 if (index >= TID_QUEUE_MAX_SIZE)
399 rs_tl_rm_old_stats(tl, curr_time);
400
401 return tl->total;
402}
403
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700404static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +0800405 struct iwl_lq_sta *lq_data, u8 tid,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200406 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200407{
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700408 int ret = -EAGAIN;
Johannes Berg290f5992010-08-23 07:56:58 -0700409 u32 load;
410
411 /*
412 * Don't create TX aggregation sessions when in high
413 * BT traffic, as they would just be disrupted by BT.
414 */
415 if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) {
416 IWL_ERR(priv, "BT traffic (%d), no aggregation allowed\n",
417 priv->bt_traffic_load);
418 return ret;
419 }
420
421 load = rs_tl_get_load(lq_data, tid);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800422
Wey-Yi Guydd5b6d02011-08-25 23:10:55 -0700423 if ((iwlagn_mod_params.auto_agg) || (load > IWL_AGG_LOAD_THRESHOLD)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800424 IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n",
Johannes Berge1749612008-10-27 15:59:26 -0700425 sta->addr, tid);
Sujith Manoharanbd2ce6e2010-12-15 07:47:10 +0530426 ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800427 if (ret == -EAGAIN) {
428 /*
429 * driver and mac80211 is out of sync
430 * this might be cause by reloading firmware
431 * stop the tx ba session here
432 */
Andy Lutomirski24110542010-07-25 13:14:29 -0400433 IWL_ERR(priv, "Fail start Tx agg on tid: %d\n",
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800434 tid);
Johannes Berg6a8579d2010-05-27 14:41:07 +0200435 ieee80211_stop_tx_ba_session(sta, tid);
Wey-Yi Guy45d42702010-02-03 12:24:44 -0800436 }
Andy Lutomirski24110542010-07-25 13:14:29 -0400437 } else {
Wey-Yi Guy5f88ac22011-05-27 08:40:31 -0700438 IWL_DEBUG_HT(priv, "Aggregation not enabled for tid %d "
Andy Lutomirski24110542010-07-25 13:14:29 -0400439 "because load = %u\n", tid, load);
440 }
Wey-Yi Guy82ca9342010-04-12 14:02:36 -0700441 return ret;
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200442}
443
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700444static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
Tomas Winklere227cea2008-07-18 13:53:05 +0800445 struct iwl_lq_sta *lq_data,
Johannes Berg4b7679a2008-09-18 18:14:18 +0200446 struct ieee80211_sta *sta)
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200447{
Johannes Berga8448552011-12-02 12:25:12 -0800448 if (tid < IWL_MAX_TID_COUNT)
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -0700449 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
450 else
Johannes Berga8448552011-12-02 12:25:12 -0800451 IWL_ERR(priv, "tid exceeds max TID count: %d/%d\n",
452 tid, IWL_MAX_TID_COUNT);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +0200453}
454
Guy Cohen39e88502008-04-23 17:14:57 -0700455static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
Guy Cohenfde0db32008-04-21 15:42:01 -0700456{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300457 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
458 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
459 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
Guy Cohenfde0db32008-04-21 15:42:01 -0700460}
461
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700462/*
463 * Static function to get the expected throughput from an iwl_scale_tbl_info
464 * that wraps a NULL pointer check
465 */
466static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index)
467{
468 if (tbl->expected_tpt)
469 return tbl->expected_tpt[rs_index];
470 return 0;
471}
472
Ben Cahill77626352007-11-29 11:09:44 +0800473/**
474 * rs_collect_tx_data - Update the success/failure sliding window
475 *
476 * We keep a sliding window of the last 62 packets transmitted
477 * at this rate. window->data contains the bitmask of successful
478 * packets.
479 */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700480static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl,
481 int scale_index, int attempts, int successes)
Zhu Yib481de92007-09-25 17:54:57 -0700482{
Tomas Winklere227cea2008-07-18 13:53:05 +0800483 struct iwl_rate_scale_data *window = NULL;
Guy Cohen39e88502008-04-23 17:14:57 -0700484 static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700485 s32 fail_count, tpt;
Zhu Yib481de92007-09-25 17:54:57 -0700486
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800487 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
488 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700489
Daniel C Halperine3949d62009-09-17 10:43:50 -0700490 /* Select window for current tx bit rate */
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700491 window = &(tbl->win[scale_index]);
492
493 /* Get expected throughput */
494 tpt = get_expected_tpt(tbl, scale_index);
Zhu Yib481de92007-09-25 17:54:57 -0700495
Ben Cahill77626352007-11-29 11:09:44 +0800496 /*
497 * Keep track of only the latest 62 tx frame attempts in this rate's
498 * history window; anything older isn't really relevant any more.
499 * If we have filled up the sliding window, drop the oldest attempt;
500 * if the oldest attempt (highest bit in bitmap) shows "success",
501 * subtract "1" from the success counter (this is the main reason
502 * we keep these bitmaps!).
503 */
Daniel C Halperine3949d62009-09-17 10:43:50 -0700504 while (attempts > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700505 if (window->counter >= IWL_RATE_MAX_WINDOW) {
506
507 /* remove earliest */
508 window->counter = IWL_RATE_MAX_WINDOW - 1;
509
Ron Rindjunsky99556432008-01-28 14:07:25 +0200510 if (window->data & mask) {
511 window->data &= ~mask;
Guy Cohen39e88502008-04-23 17:14:57 -0700512 window->success_counter--;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200513 }
Zhu Yib481de92007-09-25 17:54:57 -0700514 }
Zhu Yib481de92007-09-25 17:54:57 -0700515
Ron Rindjunsky99556432008-01-28 14:07:25 +0200516 /* Increment frames-attempted counter */
517 window->counter++;
Ben Cahill77626352007-11-29 11:09:44 +0800518
Daniel C Halperine3949d62009-09-17 10:43:50 -0700519 /* Shift bitmap by one frame to throw away oldest history */
Guy Cohen90d77952008-09-09 10:54:53 +0800520 window->data <<= 1;
Daniel C Halperine3949d62009-09-17 10:43:50 -0700521
522 /* Mark the most recent #successes attempts as successful */
Ron Rindjunsky99556432008-01-28 14:07:25 +0200523 if (successes > 0) {
Guy Cohen39e88502008-04-23 17:14:57 -0700524 window->success_counter++;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200525 window->data |= 0x1;
526 successes--;
527 }
528
Daniel C Halperine3949d62009-09-17 10:43:50 -0700529 attempts--;
Zhu Yib481de92007-09-25 17:54:57 -0700530 }
531
Ben Cahill77626352007-11-29 11:09:44 +0800532 /* Calculate current success ratio, avoid divide-by-0! */
Zhu Yib481de92007-09-25 17:54:57 -0700533 if (window->counter > 0)
534 window->success_ratio = 128 * (100 * window->success_counter)
535 / window->counter;
536 else
537 window->success_ratio = IWL_INVALID_VALUE;
538
539 fail_count = window->counter - window->success_counter;
540
Ben Cahill77626352007-11-29 11:09:44 +0800541 /* Calculate average throughput, if we have enough history. */
Zhu Yib481de92007-09-25 17:54:57 -0700542 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
543 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
544 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
545 else
546 window->average_tpt = IWL_INVALID_VALUE;
547
Ben Cahill77626352007-11-29 11:09:44 +0800548 /* Tag this window as having been updated */
Zhu Yib481de92007-09-25 17:54:57 -0700549 window->stamp = jiffies;
550
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800551 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700552}
553
Ben Cahill77626352007-11-29 11:09:44 +0800554/*
555 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
556 */
Guy Cohen39e88502008-04-23 17:14:57 -0700557/* FIXME:RS:remove this function and put the flags statically in the table */
Tomas Winkler978785a2008-12-19 10:37:31 +0800558static u32 rate_n_flags_from_tbl(struct iwl_priv *priv,
559 struct iwl_scale_tbl_info *tbl,
560 int index, u8 use_green)
Zhu Yib481de92007-09-25 17:54:57 -0700561{
Guy Cohen39e88502008-04-23 17:14:57 -0700562 u32 rate_n_flags = 0;
563
Zhu Yib481de92007-09-25 17:54:57 -0700564 if (is_legacy(tbl->lq_type)) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800565 rate_n_flags = iwl_rates[index].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700566 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -0700567 rate_n_flags |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700568
Guy Cohenfde0db32008-04-21 15:42:01 -0700569 } else if (is_Ht(tbl->lq_type)) {
570 if (index > IWL_LAST_OFDM_RATE) {
Tomas Winkler978785a2008-12-19 10:37:31 +0800571 IWL_ERR(priv, "Invalid HT rate index %d\n", index);
Zhu Yib481de92007-09-25 17:54:57 -0700572 index = IWL_LAST_OFDM_RATE;
Guy Cohenfde0db32008-04-21 15:42:01 -0700573 }
Guy Cohen39e88502008-04-23 17:14:57 -0700574 rate_n_flags = RATE_MCS_HT_MSK;
Guy Cohenfde0db32008-04-21 15:42:01 -0700575
576 if (is_siso(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800577 rate_n_flags |= iwl_rates[index].plcp_siso;
Guy Cohenfde0db32008-04-21 15:42:01 -0700578 else if (is_mimo2(tbl->lq_type))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800579 rate_n_flags |= iwl_rates[index].plcp_mimo2;
Guy Cohenfde0db32008-04-21 15:42:01 -0700580 else
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800581 rate_n_flags |= iwl_rates[index].plcp_mimo3;
Zhu Yib481de92007-09-25 17:54:57 -0700582 } else {
Tomas Winkler978785a2008-12-19 10:37:31 +0800583 IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700584 }
585
Guy Cohen39e88502008-04-23 17:14:57 -0700586 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
Guy Cohenfde0db32008-04-21 15:42:01 -0700587 RATE_MCS_ANT_ABC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700588
Guy Cohen39e88502008-04-23 17:14:57 -0700589 if (is_Ht(tbl->lq_type)) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700590 if (tbl->is_ht40) {
Guy Cohen39e88502008-04-23 17:14:57 -0700591 if (tbl->is_dup)
592 rate_n_flags |= RATE_MCS_DUP_MSK;
593 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700594 rate_n_flags |= RATE_MCS_HT40_MSK;
Guy Cohen39e88502008-04-23 17:14:57 -0700595 }
596 if (tbl->is_SGI)
597 rate_n_flags |= RATE_MCS_SGI_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700598
Guy Cohen39e88502008-04-23 17:14:57 -0700599 if (use_green) {
600 rate_n_flags |= RATE_MCS_GF_MSK;
601 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
602 rate_n_flags &= ~RATE_MCS_SGI_MSK;
Tomas Winkler978785a2008-12-19 10:37:31 +0800603 IWL_ERR(priv, "GF was set with SGI:SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -0700604 }
605 }
Zhu Yib481de92007-09-25 17:54:57 -0700606 }
Guy Cohen39e88502008-04-23 17:14:57 -0700607 return rate_n_flags;
Zhu Yib481de92007-09-25 17:54:57 -0700608}
609
Ben Cahill77626352007-11-29 11:09:44 +0800610/*
611 * Interpret uCode API's rate_n_flags format,
612 * fill "search" or "active" tx mode table.
613 */
Guy Cohen39e88502008-04-23 17:14:57 -0700614static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
Johannes Berg8318d782008-01-24 19:38:38 +0100615 enum ieee80211_band band,
Tomas Winklere227cea2008-07-18 13:53:05 +0800616 struct iwl_scale_tbl_info *tbl,
Zhu Yib481de92007-09-25 17:54:57 -0700617 int *rate_idx)
618{
Guy Cohen39e88502008-04-23 17:14:57 -0700619 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
620 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
621 u8 mcs;
Zhu Yib481de92007-09-25 17:54:57 -0700622
Wey-Yi Guy80e91582010-08-03 08:23:32 -0700623 memset(tbl, 0, sizeof(struct iwl_scale_tbl_info));
Tomas Winklere7d326ac2008-06-12 09:47:11 +0800624 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700625
Guy Cohenfde0db32008-04-21 15:42:01 -0700626 if (*rate_idx == IWL_RATE_INVALID) {
Zhu Yib481de92007-09-25 17:54:57 -0700627 *rate_idx = -1;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800628 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700629 }
Ben Cahill77626352007-11-29 11:09:44 +0800630 tbl->is_SGI = 0; /* default legacy setup */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700631 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700632 tbl->is_dup = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -0700633 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
634 tbl->lq_type = LQ_NONE;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700635 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700636
Ben Cahill77626352007-11-29 11:09:44 +0800637 /* legacy rate format */
Guy Cohen39e88502008-04-23 17:14:57 -0700638 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700639 if (num_of_ant == 1) {
Johannes Berg8318d782008-01-24 19:38:38 +0100640 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700641 tbl->lq_type = LQ_A;
642 else
643 tbl->lq_type = LQ_G;
Zhu Yib481de92007-09-25 17:54:57 -0700644 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700645 /* HT rate format */
Zhu Yib481de92007-09-25 17:54:57 -0700646 } else {
Guy Cohen39e88502008-04-23 17:14:57 -0700647 if (rate_n_flags & RATE_MCS_SGI_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700648 tbl->is_SGI = 1;
649
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700650 if ((rate_n_flags & RATE_MCS_HT40_MSK) ||
Guy Cohen39e88502008-04-23 17:14:57 -0700651 (rate_n_flags & RATE_MCS_DUP_MSK))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700652 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700653
Guy Cohen39e88502008-04-23 17:14:57 -0700654 if (rate_n_flags & RATE_MCS_DUP_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700655 tbl->is_dup = 1;
Guy Cohenfde0db32008-04-21 15:42:01 -0700656
Guy Cohen39e88502008-04-23 17:14:57 -0700657 mcs = rs_extract_rate(rate_n_flags);
Guy Cohenfde0db32008-04-21 15:42:01 -0700658
Guy Cohen39e88502008-04-23 17:14:57 -0700659 /* SISO */
660 if (mcs <= IWL_RATE_SISO_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700661 if (num_of_ant == 1)
662 tbl->lq_type = LQ_SISO; /*else NONE*/
663 /* MIMO2 */
Guy Cohen39e88502008-04-23 17:14:57 -0700664 } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
Guy Cohenfde0db32008-04-21 15:42:01 -0700665 if (num_of_ant == 2)
666 tbl->lq_type = LQ_MIMO2;
667 /* MIMO3 */
668 } else {
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700669 if (num_of_ant == 3) {
670 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Guy Cohenfde0db32008-04-21 15:42:01 -0700671 tbl->lq_type = LQ_MIMO3;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700672 }
Guy Cohenfde0db32008-04-21 15:42:01 -0700673 }
Zhu Yib481de92007-09-25 17:54:57 -0700674 }
675 return 0;
676}
Guy Cohenaade00c2008-04-23 17:14:59 -0700677
678/* switch to another antenna/antennas and return 1 */
679/* if no other valid antenna found, return 0 */
680static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
Tomas Winklere227cea2008-07-18 13:53:05 +0800681 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -0700682{
Guy Cohenaade00c2008-04-23 17:14:59 -0700683 u8 new_ant_type;
684
685 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
686 return 0;
687
688 if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
689 return 0;
690
691 new_ant_type = ant_toggle_lookup[tbl->ant_type];
692
693 while ((new_ant_type != tbl->ant_type) &&
694 !rs_is_valid_ant(valid_ant, new_ant_type))
695 new_ant_type = ant_toggle_lookup[new_ant_type];
696
697 if (new_ant_type == tbl->ant_type)
698 return 0;
699
700 tbl->ant_type = new_ant_type;
701 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
702 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
703 return 1;
Zhu Yib481de92007-09-25 17:54:57 -0700704}
705
Daniel C Halperinb2617932009-08-13 13:30:59 -0700706/**
707 * Green-field mode is valid if the station supports it and
708 * there are no non-GF stations present in the BSS.
709 */
Johannes Berg7e6a5882010-08-23 10:46:46 +0200710static bool rs_use_green(struct ieee80211_sta *sta)
Zhu Yib481de92007-09-25 17:54:57 -0700711{
Johannes Berg7e6a5882010-08-23 10:46:46 +0200712 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -0700713 struct iwl_rxon_context *ctx = sta_priv->ctx;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200714
Daniel C Halperinb2617932009-08-13 13:30:59 -0700715 return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
Johannes Berg7e6a5882010-08-23 10:46:46 +0200716 !(ctx->ht.non_gf_sta_present);
Guy Cohenf935a6d2008-04-23 17:15:02 -0700717}
Zhu Yib481de92007-09-25 17:54:57 -0700718
719/**
720 * rs_get_supported_rates - get the available rates
721 *
722 * if management frame or broadcast frame only return
723 * basic available rates.
724 *
725 */
Tomas Winklere227cea2008-07-18 13:53:05 +0800726static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
727 struct ieee80211_hdr *hdr,
728 enum iwl_table_type rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700729{
Guy Coheneecd6e52008-04-23 17:14:58 -0700730 if (is_legacy(rate_type)) {
731 return lq_sta->active_legacy_rate;
732 } else {
733 if (is_siso(rate_type))
734 return lq_sta->active_siso_rate;
735 else if (is_mimo2(rate_type))
736 return lq_sta->active_mimo2_rate;
737 else
738 return lq_sta->active_mimo3_rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800739 }
Zhu Yib481de92007-09-25 17:54:57 -0700740}
741
Ester Kummerbf403db2008-05-05 10:22:40 +0800742static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
743 int rate_type)
Zhu Yib481de92007-09-25 17:54:57 -0700744{
745 u8 high = IWL_RATE_INVALID;
746 u8 low = IWL_RATE_INVALID;
747
Ian Schram01ebd062007-10-25 17:15:22 +0800748 /* 802.11A or ht walks to the next literal adjacent rate in
Zhu Yib481de92007-09-25 17:54:57 -0700749 * the rate table */
750 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
751 int i;
752 u32 mask;
753
754 /* Find the previous rate that is in the rate mask */
755 i = index - 1;
756 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
757 if (rate_mask & mask) {
758 low = i;
759 break;
760 }
761 }
762
763 /* Find the next rate that is in the rate mask */
764 i = index + 1;
765 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
766 if (rate_mask & mask) {
767 high = i;
768 break;
769 }
770 }
771
772 return (high << 8) | low;
773 }
774
775 low = index;
776 while (low != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800777 low = iwl_rates[low].prev_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700778 if (low == IWL_RATE_INVALID)
779 break;
780 if (rate_mask & (1 << low))
781 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800782 IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low);
Zhu Yib481de92007-09-25 17:54:57 -0700783 }
784
785 high = index;
786 while (high != IWL_RATE_INVALID) {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800787 high = iwl_rates[high].next_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700788 if (high == IWL_RATE_INVALID)
789 break;
790 if (rate_mask & (1 << high))
791 break;
Tomas Winklere1623442009-01-27 14:27:56 -0800792 IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high);
Zhu Yib481de92007-09-25 17:54:57 -0700793 }
794
795 return (high << 8) | low;
796}
797
Tomas Winklere227cea2008-07-18 13:53:05 +0800798static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
799 struct iwl_scale_tbl_info *tbl,
800 u8 scale_index, u8 ht_possible)
Zhu Yib481de92007-09-25 17:54:57 -0700801{
Zhu Yib481de92007-09-25 17:54:57 -0700802 s32 low;
803 u16 rate_mask;
804 u16 high_low;
805 u8 switch_to_legacy = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800806 u8 is_green = lq_sta->is_green;
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700807 struct iwl_priv *priv = lq_sta->drv;
Zhu Yib481de92007-09-25 17:54:57 -0700808
809 /* check if we need to switch from HT to legacy rates.
810 * assumption is that mandatory rates (1Mbps or 6Mbps)
811 * are always supported (spec demand) */
812 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
813 switch_to_legacy = 1;
814 scale_index = rs_ht_to_legacy[scale_index];
Johannes Berg8318d782008-01-24 19:38:38 +0100815 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700816 tbl->lq_type = LQ_A;
817 else
818 tbl->lq_type = LQ_G;
819
Guy Cohen69fdb302008-04-23 17:15:01 -0700820 if (num_of_ant(tbl->ant_type) > 1)
Wey-Yi Guy2ff65782009-09-11 10:38:18 -0700821 tbl->ant_type =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700822 first_antenna(hw_params(priv).valid_tx_ant);
Zhu Yib481de92007-09-25 17:54:57 -0700823
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700824 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700825 tbl->is_SGI = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -0700826 tbl->max_search = IWL_MAX_SEARCH;
Zhu Yib481de92007-09-25 17:54:57 -0700827 }
828
Guy Coheneecd6e52008-04-23 17:14:58 -0700829 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700830
Ben Cahill77626352007-11-29 11:09:44 +0800831 /* Mask with station rate restriction */
Zhu Yib481de92007-09-25 17:54:57 -0700832 if (is_legacy(tbl->lq_type)) {
Ben Cahill77626352007-11-29 11:09:44 +0800833 /* supp_rates has no CCK bits in A mode */
Johannes Berg8318d782008-01-24 19:38:38 +0100834 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -0700835 rate_mask = (u16)(rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -0800836 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -0700837 else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800838 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -0700839 }
840
Ben Cahill77626352007-11-29 11:09:44 +0800841 /* If we switched from HT to legacy, check current rate */
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800842 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
Guy Cohen39e88502008-04-23 17:14:57 -0700843 low = scale_index;
844 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700845 }
846
Ester Kummerbf403db2008-05-05 10:22:40 +0800847 high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
848 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -0700849 low = high_low & 0xff;
850
Guy Cohen39e88502008-04-23 17:14:57 -0700851 if (low == IWL_RATE_INVALID)
852 low = scale_index;
853
854out:
Tomas Winkler978785a2008-12-19 10:37:31 +0800855 return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
Zhu Yib481de92007-09-25 17:54:57 -0700856}
857
Ben Cahill77626352007-11-29 11:09:44 +0800858/*
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700859 * Simple function to compare two rate scale table types
860 */
861static bool table_type_matches(struct iwl_scale_tbl_info *a,
862 struct iwl_scale_tbl_info *b)
863{
864 return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) &&
865 (a->is_SGI == b->is_SGI);
866}
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700867
Johannes Berg7e6a5882010-08-23 10:46:46 +0200868static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
869 struct iwl_lq_sta *lq_sta)
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700870{
871 struct iwl_scale_tbl_info *tbl;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800872 bool full_concurrent = priv->bt_full_concurrent;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700873
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800874 if (priv->bt_ant_couple_ok) {
875 /*
876 * Is there a need to switch between
877 * full concurrency and 3-wire?
878 */
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800879 if (priv->bt_ci_compliance && priv->bt_ant_couple_ok)
880 full_concurrent = true;
881 else
882 full_concurrent = false;
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800883 }
884 if ((priv->bt_traffic_load != priv->last_bt_traffic_load) ||
885 (priv->bt_full_concurrent != full_concurrent)) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700886 priv->bt_full_concurrent = full_concurrent;
887
888 /* Update uCode's rate table. */
889 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
890 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +0200891 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700892
Johannes Berg1ee158d2012-02-17 10:07:44 -0800893 queue_work(priv->workqueue, &priv->bt_full_concurrency);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700894 }
895}
896
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700897/*
Ben Cahill77626352007-11-29 11:09:44 +0800898 * mac80211 sends us Tx status
899 */
Johannes Berg4b7679a2008-09-18 18:14:18 +0200900static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
901 struct ieee80211_sta *sta, void *priv_sta,
Johannes Berge039fa42008-05-15 12:55:29 +0200902 struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700903{
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700904 int legacy_success;
905 int retries;
906 int rs_index, mac_index, i;
Tomas Winkler417f1142008-11-12 13:14:06 -0800907 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winkler66c73db2008-04-15 16:01:40 -0700908 struct iwl_link_quality_cmd *table;
Zhu Yib481de92007-09-25 17:54:57 -0700909 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200910 struct iwl_op_mode *op_mode = (struct iwl_op_mode *)priv_r;
911 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge039fa42008-05-15 12:55:29 +0200912 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel C Halperin50273092009-08-28 09:44:45 -0700913 enum mac80211_rate_control_flags mac_flags;
Guy Cohen39e88502008-04-23 17:14:57 -0700914 u32 tx_rate;
Tomas Winklere227cea2008-07-18 13:53:05 +0800915 struct iwl_scale_tbl_info tbl_type;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -0700916 struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200917 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -0700918 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -0700919
Tomas Winklere1623442009-01-27 14:27:56 -0800920 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -0700921
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800922 /* Treat uninitialized rate scaling data same as non-existing. */
923 if (!lq_sta) {
924 IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n");
925 return;
926 } else if (!lq_sta->drv) {
927 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
928 return;
929 }
930
Tomas Winkler417f1142008-11-12 13:14:06 -0800931 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +0200932 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -0700933 return;
934
Daniel C Halperine3949d62009-09-17 10:43:50 -0700935 /* This packet was aggregated but doesn't carry status info */
Johannes Berge039fa42008-05-15 12:55:29 +0200936 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
937 !(info->flags & IEEE80211_TX_STAT_AMPDU))
Ron Rindjunsky99556432008-01-28 14:07:25 +0200938 return;
939
Ben Cahill77626352007-11-29 11:09:44 +0800940 /*
941 * Ignore this Tx frame response if its initial rate doesn't match
942 * that of latest Link Quality command. There may be stragglers
943 * from a previous Link Quality command, but we're no longer interested
944 * in those; they're either from the "active" mode while we're trying
945 * to check "search" mode, or a prior "search" mode after we've moved
946 * to a new "search" mode (which might become the new "active" mode).
947 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700948 table = &lq_sta->lq;
Guy Cohen39e88502008-04-23 17:14:57 -0700949 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
950 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800951 if (priv->band == IEEE80211_BAND_5GHZ)
952 rs_index -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin50273092009-08-28 09:44:45 -0700953 mac_flags = info->status.rates[0].flags;
954 mac_index = info->status.rates[0].idx;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700955 /* For HT packets, map MCS to PLCP */
956 if (mac_flags & IEEE80211_TX_RC_MCS) {
957 mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */
958 if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
959 mac_index++;
Daniel C Halperin392a0ba2009-09-11 10:38:08 -0700960 /*
961 * mac80211 HT index is always zero-indexed; we need to move
962 * HT OFDM rates after CCK rates in 2.4 GHz band
963 */
964 if (priv->band == IEEE80211_BAND_2GHZ)
965 mac_index += IWL_FIRST_OFDM_RATE;
Daniel C Halperin31513be2009-08-28 09:44:47 -0700966 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700967 /* Here we actually compare this rate to the latest LQ command */
Daniel C Halperin50273092009-08-28 09:44:45 -0700968 if ((mac_index < 0) ||
969 (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
970 (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
971 (tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) ||
Johannes Berge6a98542008-10-21 12:40:02 +0200972 (tbl_type.ant_type != info->antenna_sel_tx) ||
Daniel C Halperin50273092009-08-28 09:44:45 -0700973 (!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
974 (!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
Daniel C Halperin31513be2009-08-28 09:44:47 -0700975 (rs_index != mac_index)) {
976 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 -0700977 /*
978 * Since rates mis-match, the last LQ command may have failed.
979 * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with
980 * ... driver.
Mohamed Abbasd5e49032008-12-12 08:22:15 -0800981 */
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800982 lq_sta->missed_rate_counter++;
983 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
984 lq_sta->missed_rate_counter = 0;
Johannes Berg7e6a5882010-08-23 10:46:46 +0200985 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Abbas, Mohamed7d049e52009-01-20 21:33:53 -0800986 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -0700987 /* Regardless, ignore this status info for outdated rate */
988 return;
989 } else
990 /* Rate did match, so reset the missed_rate_counter */
991 lq_sta->missed_rate_counter = 0;
992
993 /* Figure out if rate scale algorithm is in active or search table */
994 if (table_type_matches(&tbl_type,
995 &(lq_sta->lq_info[lq_sta->active_tbl]))) {
996 curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
997 other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
998 } else if (table_type_matches(&tbl_type,
999 &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
1000 curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1001 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1002 } else {
1003 IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n");
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001004 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1005 IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n",
1006 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
1007 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
1008 IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n",
1009 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
1010 IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n",
1011 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
1012 /*
1013 * no matching table found, let's by-pass the data collection
1014 * and continue to perform rate scale to find the rate table
1015 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001016 rs_stay_in_table(lq_sta, true);
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001017 goto done;
Zhu Yib481de92007-09-25 17:54:57 -07001018 }
Zhu Yib481de92007-09-25 17:54:57 -07001019
Ben Cahill77626352007-11-29 11:09:44 +08001020 /*
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001021 * Updating the frame history depends on whether packets were
1022 * aggregated.
1023 *
1024 * For aggregation, all packets were transmitted at the same rate, the
1025 * first index into rate scale table.
Ben Cahill77626352007-11-29 11:09:44 +08001026 */
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001027 if (info->flags & IEEE80211_TX_STAT_AMPDU) {
1028 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
1029 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type,
1030 &rs_index);
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001031 rs_collect_tx_data(curr_tbl, rs_index,
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001032 info->status.ampdu_len,
1033 info->status.ampdu_ack_len);
Zhu Yib481de92007-09-25 17:54:57 -07001034
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001035 /* Update success/fail counts if not searching for new mode */
1036 if (lq_sta->stay_in_tbl) {
Daniel Halperine3a3cd82010-04-18 09:27:58 -07001037 lq_sta->total_success += info->status.ampdu_ack_len;
1038 lq_sta->total_failed += (info->status.ampdu_len -
1039 info->status.ampdu_ack_len);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001040 }
1041 } else {
1042 /*
1043 * For legacy, update frame history with for each Tx retry.
1044 */
1045 retries = info->status.rates[0].count - 1;
1046 /* HW doesn't send more than 15 retries */
1047 retries = min(retries, 15);
1048
1049 /* The last transmission may have been successful */
1050 legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
1051 /* Collect data for each rate used during failed TX attempts */
1052 for (i = 0; i <= retries; ++i) {
1053 tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
1054 rs_get_tbl_info_from_mcs(tx_rate, priv->band,
1055 &tbl_type, &rs_index);
1056 /*
1057 * Only collect stats if retried rate is in the same RS
1058 * table as active/search.
1059 */
1060 if (table_type_matches(&tbl_type, curr_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001061 tmp_tbl = curr_tbl;
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001062 else if (table_type_matches(&tbl_type, other_tbl))
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001063 tmp_tbl = other_tbl;
Ron Rindjunsky99556432008-01-28 14:07:25 +02001064 else
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001065 continue;
Shanyu Zhao04f2dec2010-03-19 13:34:45 -07001066 rs_collect_tx_data(tmp_tbl, rs_index, 1,
1067 i < retries ? 0 : legacy_success);
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001068 }
1069
1070 /* Update success/fail counts if not searching for new mode */
1071 if (lq_sta->stay_in_tbl) {
1072 lq_sta->total_success += legacy_success;
1073 lq_sta->total_failed += retries + (1 - legacy_success);
Ron Rindjunsky99556432008-01-28 14:07:25 +02001074 }
Zhu Yib481de92007-09-25 17:54:57 -07001075 }
Daniel C Halperin95407aa2009-09-17 10:43:48 -07001076 /* The last TX rate is cached in lq_sta; it's set in if/else above */
1077 lq_sta->last_rate_n_flags = tx_rate;
Wey-Yi Guy80e91582010-08-03 08:23:32 -07001078done:
Ben Cahill77626352007-11-29 11:09:44 +08001079 /* See if there's a better rate or modulation mode to try. */
Abbas, Mohamedc338ba32009-01-21 10:58:02 -08001080 if (sta && sta->supp_rates[sband->band])
Gábor Stefanik514d65c2009-04-23 19:36:08 +02001081 rs_rate_scale_perform(priv, skb, sta, lq_sta);
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -07001082
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -08001083#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_IWLWIFI_DEVICE_TESTMODE)
Wey-Yi Guy4e308112011-07-08 08:46:28 -07001084 if ((priv->tm_fixed_rate) &&
1085 (priv->tm_fixed_rate != lq_sta->dbg_fixed_rate))
Wey-Yi Guy64898542011-05-03 18:05:13 -07001086 rs_program_fix_rate(priv, lq_sta);
1087#endif
Don Fry38622412011-12-16 07:07:36 -08001088 if (cfg(priv)->bt_params && cfg(priv)->bt_params->advanced_bt_coexist)
Johannes Berg7e6a5882010-08-23 10:46:46 +02001089 rs_bt_update_lq(priv, ctx, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001090}
1091
Ben Cahill77626352007-11-29 11:09:44 +08001092/*
1093 * Begin a period of staying with a selected modulation mode.
1094 * Set "stay_in_tbl" flag to prevent any mode switches.
1095 * Set frame tx success limits according to legacy vs. high-throughput,
1096 * and reset overall (spanning all rates) tx success history statistics.
1097 * These control how long we stay using same modulation mode before
1098 * searching for a new mode.
1099 */
Ester Kummerbf403db2008-05-05 10:22:40 +08001100static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
Tomas Winklere227cea2008-07-18 13:53:05 +08001101 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07001102{
Tomas Winklere1623442009-01-27 14:27:56 -08001103 IWL_DEBUG_RATE(priv, "we are staying in the same table\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -08001104 lq_sta->stay_in_tbl = 1; /* only place this gets set */
Zhu Yib481de92007-09-25 17:54:57 -07001105 if (is_legacy) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001106 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
1107 lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
1108 lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001109 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001110 lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
1111 lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
1112 lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -07001113 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001114 lq_sta->table_count = 0;
1115 lq_sta->total_failed = 0;
1116 lq_sta->total_success = 0;
Mohamed Abbas447fee72009-04-20 14:37:02 -07001117 lq_sta->flush_timer = jiffies;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001118 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001119}
1120
Ben Cahill77626352007-11-29 11:09:44 +08001121/*
1122 * Find correct throughput table for given mode of modulation
1123 */
Tomas Winklere227cea2008-07-18 13:53:05 +08001124static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1125 struct iwl_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -07001126{
Daniel C Halperine3949d62009-09-17 10:43:50 -07001127 /* Used to choose among HT tables */
1128 s32 (*ht_tbl_pointer)[IWL_RATE_COUNT];
1129
1130 /* Check for invalid LQ type */
1131 if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
1132 tbl->expected_tpt = expected_tpt_legacy;
1133 return;
1134 }
1135
1136 /* Legacy rates have only one table */
Zhu Yib481de92007-09-25 17:54:57 -07001137 if (is_legacy(tbl->lq_type)) {
Daniel C Halperine3949d62009-09-17 10:43:50 -07001138 tbl->expected_tpt = expected_tpt_legacy;
1139 return;
1140 }
1141
1142 /* Choose among many HT tables depending on number of streams
1143 * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation
1144 * status */
1145 if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1146 ht_tbl_pointer = expected_tpt_siso20MHz;
1147 else if (is_siso(tbl->lq_type))
1148 ht_tbl_pointer = expected_tpt_siso40MHz;
1149 else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1150 ht_tbl_pointer = expected_tpt_mimo2_20MHz;
1151 else if (is_mimo2(tbl->lq_type))
1152 ht_tbl_pointer = expected_tpt_mimo2_40MHz;
1153 else if (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1154 ht_tbl_pointer = expected_tpt_mimo3_20MHz;
1155 else /* if (is_mimo3(tbl->lq_type)) <-- must be true */
1156 ht_tbl_pointer = expected_tpt_mimo3_40MHz;
1157
1158 if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
1159 tbl->expected_tpt = ht_tbl_pointer[0];
1160 else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
1161 tbl->expected_tpt = ht_tbl_pointer[1];
1162 else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
1163 tbl->expected_tpt = ht_tbl_pointer[2];
1164 else /* AGG+SGI */
1165 tbl->expected_tpt = ht_tbl_pointer[3];
Zhu Yib481de92007-09-25 17:54:57 -07001166}
1167
Ben Cahill77626352007-11-29 11:09:44 +08001168/*
1169 * Find starting rate for new "search" high-throughput mode of modulation.
1170 * Goal is to find lowest expected rate (under perfect conditions) that is
1171 * above the current measured throughput of "active" mode, to give new mode
1172 * a fair chance to prove itself without too many challenges.
1173 *
1174 * This gets called when transitioning to more aggressive modulation
1175 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1176 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1177 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1178 * bit rate will typically need to increase, but not if performance was bad.
1179 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001180static s32 rs_get_best_rate(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001181 struct iwl_lq_sta *lq_sta,
1182 struct iwl_scale_tbl_info *tbl, /* "search" */
Guy Cohenf935a6d2008-04-23 17:15:02 -07001183 u16 rate_mask, s8 index)
Zhu Yib481de92007-09-25 17:54:57 -07001184{
Ben Cahill77626352007-11-29 11:09:44 +08001185 /* "active" values */
Tomas Winklere227cea2008-07-18 13:53:05 +08001186 struct iwl_scale_tbl_info *active_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001187 &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001188 s32 active_sr = active_tbl->win[index].success_ratio;
Zhu Yib481de92007-09-25 17:54:57 -07001189 s32 active_tpt = active_tbl->expected_tpt[index];
Ben Cahill77626352007-11-29 11:09:44 +08001190
1191 /* expected "search" throughput */
1192 s32 *tpt_tbl = tbl->expected_tpt;
1193
1194 s32 new_rate, high, low, start_hi;
Zhu Yib481de92007-09-25 17:54:57 -07001195 u16 high_low;
Guy Cohenf935a6d2008-04-23 17:15:02 -07001196 s8 rate = index;
Zhu Yib481de92007-09-25 17:54:57 -07001197
1198 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1199
1200 for (; ;) {
Ester Kummerbf403db2008-05-05 10:22:40 +08001201 high_low = rs_get_adjacent_rate(priv, rate, rate_mask,
1202 tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07001203
1204 low = high_low & 0xff;
1205 high = (high_low >> 8) & 0xff;
1206
Ben Cahill77626352007-11-29 11:09:44 +08001207 /*
1208 * Lower the "search" bit rate, to give new "search" mode
1209 * approximately the same throughput as "active" if:
1210 *
1211 * 1) "Active" mode has been working modestly well (but not
1212 * great), and expected "search" throughput (under perfect
1213 * conditions) at candidate rate is above the actual
1214 * measured "active" throughput (but less than expected
1215 * "active" throughput under perfect conditions).
1216 * OR
1217 * 2) "Active" mode has been working perfectly or very well
1218 * and expected "search" throughput (under perfect
1219 * conditions) at candidate rate is above expected
1220 * "active" throughput (under perfect conditions).
1221 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001222 if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
Zhu Yib481de92007-09-25 17:54:57 -07001223 ((active_sr > IWL_RATE_DECREASE_TH) &&
1224 (active_sr <= IWL_RATE_HIGH_TH) &&
1225 (tpt_tbl[rate] <= active_tpt))) ||
1226 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
1227 (tpt_tbl[rate] > active_tpt))) {
1228
Ben Cahill77626352007-11-29 11:09:44 +08001229 /* (2nd or later pass)
1230 * If we've already tried to raise the rate, and are
1231 * now trying to lower it, use the higher rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001232 if (start_hi != IWL_RATE_INVALID) {
1233 new_rate = start_hi;
1234 break;
1235 }
Ben Cahill77626352007-11-29 11:09:44 +08001236
Zhu Yib481de92007-09-25 17:54:57 -07001237 new_rate = rate;
Ben Cahill77626352007-11-29 11:09:44 +08001238
1239 /* Loop again with lower rate */
Zhu Yib481de92007-09-25 17:54:57 -07001240 if (low != IWL_RATE_INVALID)
1241 rate = low;
Ben Cahill77626352007-11-29 11:09:44 +08001242
1243 /* Lower rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001244 else
1245 break;
Ben Cahill77626352007-11-29 11:09:44 +08001246
1247 /* Else try to raise the "search" rate to match "active" */
Zhu Yib481de92007-09-25 17:54:57 -07001248 } else {
Ben Cahill77626352007-11-29 11:09:44 +08001249 /* (2nd or later pass)
1250 * If we've already tried to lower the rate, and are
1251 * now trying to raise it, use the lower rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001252 if (new_rate != IWL_RATE_INVALID)
1253 break;
Ben Cahill77626352007-11-29 11:09:44 +08001254
1255 /* Loop again with higher rate */
Zhu Yib481de92007-09-25 17:54:57 -07001256 else if (high != IWL_RATE_INVALID) {
1257 start_hi = high;
1258 rate = high;
Ben Cahill77626352007-11-29 11:09:44 +08001259
1260 /* Higher rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001261 } else {
Guy Cohen90d77952008-09-09 10:54:53 +08001262 new_rate = rate;
Zhu Yib481de92007-09-25 17:54:57 -07001263 break;
1264 }
1265 }
1266 }
1267
1268 return new_rate;
1269}
Zhu Yib481de92007-09-25 17:54:57 -07001270
Ben Cahill77626352007-11-29 11:09:44 +08001271/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001272 * Set up search table for MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001273 */
Guy Cohenfde0db32008-04-21 15:42:01 -07001274static int rs_switch_to_mimo2(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001275 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001276 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001277 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001278 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001279{
Zhu Yib481de92007-09-25 17:54:57 -07001280 u16 rate_mask;
1281 s32 rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001282 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001283 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001284 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001285
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001286 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001287 return -1;
1288
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001289 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
Tomas Winkler00c5ae22008-09-03 11:26:42 +08001290 == WLAN_HT_CAP_SM_PS_STATIC)
Zhu Yib481de92007-09-25 17:54:57 -07001291 return -1;
1292
Ben Cahill77626352007-11-29 11:09:44 +08001293 /* Need both Tx chains/antennas to support MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001294 if (hw_params(priv).tx_chains_num < 2)
Zhu Yib481de92007-09-25 17:54:57 -07001295 return -1;
1296
Tomas Winklere1623442009-01-27 14:27:56 -08001297 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001298
1299 tbl->lq_type = LQ_MIMO2;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001300 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001301 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001302 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001303 rate_mask = lq_sta->active_mimo2_rate;
1304
Johannes Berg7e6a5882010-08-23 10:46:46 +02001305 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001306 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001307 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001308 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001309
Guy Coheneecd6e52008-04-23 17:14:58 -07001310 rs_set_expected_tpt_table(lq_sta, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001311
Guy Cohenf935a6d2008-04-23 17:15:02 -07001312 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001313
Tomas Winklere1623442009-01-27 14:27:56 -08001314 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001315 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1316 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1317 rate, rate_mask);
1318 return -1;
1319 }
1320 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Guy Cohen39e88502008-04-23 17:14:57 -07001321
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001322 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1323 tbl->current_rate, is_green);
1324 return 0;
1325}
1326
1327/*
1328 * Set up search table for MIMO3
1329 */
1330static int rs_switch_to_mimo3(struct iwl_priv *priv,
1331 struct iwl_lq_sta *lq_sta,
1332 struct ieee80211_conf *conf,
1333 struct ieee80211_sta *sta,
1334 struct iwl_scale_tbl_info *tbl, int index)
1335{
1336 u16 rate_mask;
1337 s32 rate;
1338 s8 is_green = lq_sta->is_green;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001339 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001340 struct iwl_rxon_context *ctx = sta_priv->ctx;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001341
1342 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1343 return -1;
1344
1345 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1346 == WLAN_HT_CAP_SM_PS_STATIC)
1347 return -1;
1348
1349 /* Need both Tx chains/antennas to support MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001350 if (hw_params(priv).tx_chains_num < 3)
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001351 return -1;
1352
1353 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1354
1355 tbl->lq_type = LQ_MIMO3;
1356 tbl->is_dup = lq_sta->is_dup;
1357 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001358 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001359 rate_mask = lq_sta->active_mimo3_rate;
1360
Johannes Berg7e6a5882010-08-23 10:46:46 +02001361 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001362 tbl->is_ht40 = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001363 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001364 tbl->is_ht40 = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001365
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001366 rs_set_expected_tpt_table(lq_sta, tbl);
1367
1368 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1369
1370 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1371 rate, rate_mask);
Guy Cohen39e88502008-04-23 17:14:57 -07001372 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001373 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001374 rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001375 return -1;
Guy Cohen39e88502008-04-23 17:14:57 -07001376 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001377 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Zhu Yib481de92007-09-25 17:54:57 -07001378
Tomas Winklere1623442009-01-27 14:27:56 -08001379 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001380 tbl->current_rate, is_green);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001381 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001382}
1383
Ben Cahill77626352007-11-29 11:09:44 +08001384/*
1385 * Set up search table for SISO
1386 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001387static int rs_switch_to_siso(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001388 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001389 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001390 struct ieee80211_sta *sta,
Tomas Winklere227cea2008-07-18 13:53:05 +08001391 struct iwl_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001392{
Zhu Yib481de92007-09-25 17:54:57 -07001393 u16 rate_mask;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001394 u8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001395 s32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02001396 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07001397 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07001398
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08001399 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001400 return -1;
1401
Tomas Winklere1623442009-01-27 14:27:56 -08001402 IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n");
Guy Cohen39e88502008-04-23 17:14:57 -07001403
Tomas Winklerc33104f2008-01-14 17:46:21 -08001404 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001405 tbl->lq_type = LQ_SISO;
1406 tbl->action = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001407 tbl->max_search = IWL_MAX_SEARCH;
Guy Cohen39e88502008-04-23 17:14:57 -07001408 rate_mask = lq_sta->active_siso_rate;
Zhu Yib481de92007-09-25 17:54:57 -07001409
Johannes Berg7e6a5882010-08-23 10:46:46 +02001410 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001411 tbl->is_ht40 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001412 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001413 tbl->is_ht40 = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001414
Zhu Yib481de92007-09-25 17:54:57 -07001415 if (is_green)
Guy Cohen39e88502008-04-23 17:14:57 -07001416 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
Zhu Yib481de92007-09-25 17:54:57 -07001417
Guy Coheneecd6e52008-04-23 17:14:58 -07001418 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohenf935a6d2008-04-23 17:15:02 -07001419 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
Zhu Yib481de92007-09-25 17:54:57 -07001420
Tomas Winklere1623442009-01-27 14:27:56 -08001421 IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07001422 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001423 IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001424 rate, rate_mask);
1425 return -1;
1426 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001427 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
Tomas Winklere1623442009-01-27 14:27:56 -08001428 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
Guy Cohen39e88502008-04-23 17:14:57 -07001429 tbl->current_rate, is_green);
Mohamed Abbas403ab562007-11-06 22:06:25 -08001430 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001431}
1432
Ben Cahill77626352007-11-29 11:09:44 +08001433/*
1434 * Try to switch to new modulation mode from legacy
1435 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001436static int rs_move_legacy_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001437 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001438 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001439 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001440 int index)
1441{
Tomas Winklere227cea2008-07-18 13:53:05 +08001442 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1443 struct iwl_scale_tbl_info *search_tbl =
1444 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1445 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1446 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1447 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001448 u8 start_action;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001449 u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
1450 u8 tx_chains_num = hw_params(priv).tx_chains_num;
Guy Cohenfde0db32008-04-21 15:42:01 -07001451 int ret = 0;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001452 u8 update_search_tbl_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001453
Johannes Berg290f5992010-08-23 07:56:58 -07001454 switch (priv->bt_traffic_load) {
1455 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1456 /* nothing */
1457 break;
1458 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1459 /* avoid antenna B unless MIMO */
1460 if (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001461 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001462 break;
1463 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1464 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1465 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001466 valid_tx_ant =
1467 first_antenna(hw_params(priv).valid_tx_ant);
Johannes Berg290f5992010-08-23 07:56:58 -07001468 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 &&
1469 tbl->action != IWL_LEGACY_SWITCH_SISO)
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001470 tbl->action = IWL_LEGACY_SWITCH_SISO;
Johannes Berg290f5992010-08-23 07:56:58 -07001471 break;
1472 default:
1473 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1474 break;
1475 }
1476
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001477 if (!iwl_ht_enabled(priv))
1478 /* stay in Legacy */
1479 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07001480 else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001481 tbl->action > IWL_LEGACY_SWITCH_SISO)
1482 tbl->action = IWL_LEGACY_SWITCH_SISO;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001483
1484 /* configure as 1x1 if bt full concurrency */
1485 if (priv->bt_full_concurrent) {
1486 if (!iwl_ht_enabled(priv))
1487 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1488 else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1489 tbl->action = IWL_LEGACY_SWITCH_SISO;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001490 valid_tx_ant =
1491 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001492 }
1493
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001494 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001495 for (; ;) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001496 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001497 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001498 case IWL_LEGACY_SWITCH_ANTENNA1:
1499 case IWL_LEGACY_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001500 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
Zhu Yib481de92007-09-25 17:54:57 -07001501
Guy Cohen3110bef2008-09-09 10:54:54 +08001502 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1503 tx_chains_num <= 1) ||
1504 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
1505 tx_chains_num <= 2))
1506 break;
1507
Ben Cahill77626352007-11-29 11:09:44 +08001508 /* Don't change antenna if success has been great */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001509 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1510 !priv->bt_full_concurrent &&
1511 priv->bt_traffic_load ==
1512 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001513 break;
Ben Cahill77626352007-11-29 11:09:44 +08001514
Ben Cahill77626352007-11-29 11:09:44 +08001515 /* Set up search table to try other antenna */
Zhu Yib481de92007-09-25 17:54:57 -07001516 memcpy(search_tbl, tbl, sz);
1517
Guy Cohenaade00c2008-04-23 17:14:59 -07001518 if (rs_toggle_antenna(valid_tx_ant,
1519 &search_tbl->current_rate, search_tbl)) {
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001520 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001521 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohenaade00c2008-04-23 17:14:59 -07001522 goto out;
1523 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001524 break;
Zhu Yib481de92007-09-25 17:54:57 -07001525 case IWL_LEGACY_SWITCH_SISO:
Tomas Winklere1623442009-01-27 14:27:56 -08001526 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001527
1528 /* Set up search table to try SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001529 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001530 search_tbl->is_SGI = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001531 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001532 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001533 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001534 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001535 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001536 }
Zhu Yib481de92007-09-25 17:54:57 -07001537
1538 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001539 case IWL_LEGACY_SWITCH_MIMO2_AB:
1540 case IWL_LEGACY_SWITCH_MIMO2_AC:
1541 case IWL_LEGACY_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001542 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n");
Ben Cahill77626352007-11-29 11:09:44 +08001543
1544 /* Set up search table to try MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07001545 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001546 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001547
1548 if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
1549 search_tbl->ant_type = ANT_AB;
1550 else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
1551 search_tbl->ant_type = ANT_AC;
1552 else
1553 search_tbl->ant_type = ANT_BC;
1554
1555 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1556 break;
1557
Guy Cohenfde0db32008-04-21 15:42:01 -07001558 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001559 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001560 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001561 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001562 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001563 }
Zhu Yib481de92007-09-25 17:54:57 -07001564 break;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001565
1566 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1567 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1568
1569 /* Set up search table to try MIMO3 */
1570 memcpy(search_tbl, tbl, sz);
1571 search_tbl->is_SGI = 0;
1572
1573 search_tbl->ant_type = ANT_ABC;
1574
1575 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1576 break;
1577
1578 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1579 search_tbl, index);
1580 if (!ret) {
1581 lq_sta->action_counter = 0;
1582 goto out;
1583 }
1584 break;
Zhu Yib481de92007-09-25 17:54:57 -07001585 }
1586 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001587 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001588 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001589
1590 if (tbl->action == start_action)
1591 break;
1592
1593 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001594 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001595 return 0;
1596
Guy Cohen3110bef2008-09-09 10:54:54 +08001597out:
1598 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001599 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001600 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001601 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001602 if (update_search_tbl_counter)
1603 search_tbl->action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001604 return 0;
1605
1606}
1607
Ben Cahill77626352007-11-29 11:09:44 +08001608/*
1609 * Try to switch to new modulation mode from SISO
1610 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001611static int rs_move_siso_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001612 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001613 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001614 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001615{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001616 u8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001617 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1618 struct iwl_scale_tbl_info *search_tbl =
1619 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1620 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001621 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001622 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1623 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001624 u8 start_action;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001625 u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
1626 u8 tx_chains_num = hw_params(priv).tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001627 u8 update_search_tbl_counter = 0;
Guy Cohenfde0db32008-04-21 15:42:01 -07001628 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001629
Johannes Berg290f5992010-08-23 07:56:58 -07001630 switch (priv->bt_traffic_load) {
1631 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1632 /* nothing */
1633 break;
1634 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1635 /* avoid antenna B unless MIMO */
1636 if (tbl->action == IWL_SISO_SWITCH_ANTENNA2)
Venkataraman, Meenakshi383b0872011-11-10 06:55:25 -08001637 tbl->action = IWL_SISO_SWITCH_MIMO2_AB;
Johannes Berg290f5992010-08-23 07:56:58 -07001638 break;
1639 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1640 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1641 /* avoid antenna B and MIMO */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001642 valid_tx_ant =
1643 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001644 if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
Johannes Berg290f5992010-08-23 07:56:58 -07001645 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1646 break;
1647 default:
1648 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1649 break;
1650 }
1651
Johannes Berg3ad3b922009-08-07 15:41:48 -07001652 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001653 tbl->action > IWL_SISO_SWITCH_ANTENNA2) {
1654 /* stay in SISO */
1655 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1656 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001657
1658 /* configure as 1x1 if bt full concurrency */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001659 if (priv->bt_full_concurrent) {
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001660 valid_tx_ant =
1661 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001662 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1663 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1664 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001665
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001666 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001667 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001668 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001669 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001670 case IWL_SISO_SWITCH_ANTENNA1:
1671 case IWL_SISO_SWITCH_ANTENNA2:
Tomas Winklere1623442009-01-27 14:27:56 -08001672 IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001673 if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001674 tx_chains_num <= 1) ||
Guy Cohen3110bef2008-09-09 10:54:54 +08001675 (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001676 tx_chains_num <= 2))
Guy Cohen3110bef2008-09-09 10:54:54 +08001677 break;
1678
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001679 if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
1680 !priv->bt_full_concurrent &&
1681 priv->bt_traffic_load ==
1682 IWL_BT_COEX_TRAFFIC_LOAD_NONE)
Zhu Yib481de92007-09-25 17:54:57 -07001683 break;
Zhu Yib481de92007-09-25 17:54:57 -07001684
1685 memcpy(search_tbl, tbl, sz);
Guy Cohenaade00c2008-04-23 17:14:59 -07001686 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001687 &search_tbl->current_rate, search_tbl)) {
1688 update_search_tbl_counter = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07001689 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001690 }
Guy Cohena5e8b502008-05-29 16:35:11 +08001691 break;
Guy Cohen3110bef2008-09-09 10:54:54 +08001692 case IWL_SISO_SWITCH_MIMO2_AB:
1693 case IWL_SISO_SWITCH_MIMO2_AC:
1694 case IWL_SISO_SWITCH_MIMO2_BC:
Tomas Winklere1623442009-01-27 14:27:56 -08001695 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n");
Zhu Yib481de92007-09-25 17:54:57 -07001696 memcpy(search_tbl, tbl, sz);
Zhu Yib481de92007-09-25 17:54:57 -07001697 search_tbl->is_SGI = 0;
Guy Cohen3110bef2008-09-09 10:54:54 +08001698
1699 if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
1700 search_tbl->ant_type = ANT_AB;
1701 else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
1702 search_tbl->ant_type = ANT_AC;
1703 else
1704 search_tbl->ant_type = ANT_BC;
1705
1706 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1707 break;
1708
Guy Cohenfde0db32008-04-21 15:42:01 -07001709 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001710 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001711 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001712 goto out;
1713 break;
1714 case IWL_SISO_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001715 if (!tbl->is_ht40 && !(ht_cap->cap &
1716 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001717 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001718 if (tbl->is_ht40 && !(ht_cap->cap &
1719 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001720 break;
1721
Tomas Winklere1623442009-01-27 14:27:56 -08001722 IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001723
Zhu Yib481de92007-09-25 17:54:57 -07001724 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001725 if (is_green) {
1726 if (!tbl->is_SGI)
1727 break;
1728 else
Winkler, Tomas15b16872008-12-19 10:37:33 +08001729 IWL_ERR(priv,
1730 "SGI was set in GF+SISO\n");
Zhu Yib481de92007-09-25 17:54:57 -07001731 }
Guy Cohen39e88502008-04-23 17:14:57 -07001732 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07001733 rs_set_expected_tpt_table(lq_sta, search_tbl);
Guy Cohen39e88502008-04-23 17:14:57 -07001734 if (tbl->is_SGI) {
1735 s32 tpt = lq_sta->last_tpt / 100;
1736 if (tpt >= search_tbl->expected_tpt[index])
1737 break;
1738 }
Tomas Winkler978785a2008-12-19 10:37:31 +08001739 search_tbl->current_rate =
1740 rate_n_flags_from_tbl(priv, search_tbl,
1741 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001742 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001743 goto out;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001744 case IWL_SISO_SWITCH_MIMO3_ABC:
1745 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1746 memcpy(search_tbl, tbl, sz);
1747 search_tbl->is_SGI = 0;
1748 search_tbl->ant_type = ANT_ABC;
1749
1750 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1751 break;
1752
1753 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1754 search_tbl, index);
1755 if (!ret)
1756 goto out;
1757 break;
Zhu Yib481de92007-09-25 17:54:57 -07001758 }
1759 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001760 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001761 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07001762
1763 if (tbl->action == start_action)
1764 break;
1765 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001766 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07001767 return 0;
1768
1769 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08001770 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001771 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001772 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
Guy Cohen3110bef2008-09-09 10:54:54 +08001773 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001774 if (update_search_tbl_counter)
1775 search_tbl->action = tbl->action;
1776
Zhu Yib481de92007-09-25 17:54:57 -07001777 return 0;
1778}
1779
Ben Cahill77626352007-11-29 11:09:44 +08001780/*
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001781 * Try to switch to new modulation mode from MIMO2
Ben Cahill77626352007-11-29 11:09:44 +08001782 */
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001783static int rs_move_mimo2_to_other(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08001784 struct iwl_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001785 struct ieee80211_conf *conf,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001786 struct ieee80211_sta *sta, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001787{
Tomas Winklerc33104f2008-01-14 17:46:21 -08001788 s8 is_green = lq_sta->is_green;
Tomas Winklere227cea2008-07-18 13:53:05 +08001789 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1790 struct iwl_scale_tbl_info *search_tbl =
1791 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Guy Cohen3110bef2008-09-09 10:54:54 +08001792 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001793 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Tomas Winklere227cea2008-07-18 13:53:05 +08001794 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1795 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001796 u8 start_action;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001797 u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
1798 u8 tx_chains_num = hw_params(priv).tx_chains_num;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001799 u8 update_search_tbl_counter = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07001800 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001801
Johannes Berg290f5992010-08-23 07:56:58 -07001802 switch (priv->bt_traffic_load) {
1803 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1804 /* nothing */
1805 break;
1806 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1807 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1808 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001809 if (tbl->action != IWL_MIMO2_SWITCH_SISO_A)
1810 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1811 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001812 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1813 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001814 if (tbl->action == IWL_MIMO2_SWITCH_SISO_B ||
1815 tbl->action == IWL_MIMO2_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001816 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1817 break;
1818 default:
1819 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1820 break;
1821 }
1822
Johannes Berg3ad3b922009-08-07 15:41:48 -07001823 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001824 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1825 tbl->action > IWL_MIMO2_SWITCH_SISO_C)) {
1826 /* switch in SISO */
1827 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1828 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001829
1830 /* configure as 1x1 if bt full concurrency */
1831 if (priv->bt_full_concurrent &&
1832 (tbl->action < IWL_MIMO2_SWITCH_SISO_A ||
1833 tbl->action > IWL_MIMO2_SWITCH_SISO_C))
1834 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1835
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001836 start_action = tbl->action;
Zhu Yib481de92007-09-25 17:54:57 -07001837 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001838 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001839 switch (tbl->action) {
Guy Cohen3110bef2008-09-09 10:54:54 +08001840 case IWL_MIMO2_SWITCH_ANTENNA1:
1841 case IWL_MIMO2_SWITCH_ANTENNA2:
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001842 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
Guy Cohen3110bef2008-09-09 10:54:54 +08001843
1844 if (tx_chains_num <= 2)
1845 break;
1846
1847 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1848 break;
1849
1850 memcpy(search_tbl, tbl, sz);
1851 if (rs_toggle_antenna(valid_tx_ant,
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001852 &search_tbl->current_rate, search_tbl)) {
1853 update_search_tbl_counter = 1;
Guy Cohen3110bef2008-09-09 10:54:54 +08001854 goto out;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001855 }
Guy Cohen3110bef2008-09-09 10:54:54 +08001856 break;
1857 case IWL_MIMO2_SWITCH_SISO_A:
1858 case IWL_MIMO2_SWITCH_SISO_B:
1859 case IWL_MIMO2_SWITCH_SISO_C:
Tomas Winklere1623442009-01-27 14:27:56 -08001860 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n");
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02001861
Ben Cahill77626352007-11-29 11:09:44 +08001862 /* Set up new search table for SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001863 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07001864
Guy Cohen3110bef2008-09-09 10:54:54 +08001865 if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
Guy Cohenfde0db32008-04-21 15:42:01 -07001866 search_tbl->ant_type = ANT_A;
Guy Cohen3110bef2008-09-09 10:54:54 +08001867 else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
Guy Cohenfde0db32008-04-21 15:42:01 -07001868 search_tbl->ant_type = ANT_B;
Guy Cohen3110bef2008-09-09 10:54:54 +08001869 else
1870 search_tbl->ant_type = ANT_C;
1871
1872 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1873 break;
Zhu Yib481de92007-09-25 17:54:57 -07001874
Tomas Winklerc33104f2008-01-14 17:46:21 -08001875 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001876 search_tbl, index);
Guy Cohen3110bef2008-09-09 10:54:54 +08001877 if (!ret)
Zhu Yib481de92007-09-25 17:54:57 -07001878 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08001879
Zhu Yib481de92007-09-25 17:54:57 -07001880 break;
1881
Guy Cohen3110bef2008-09-09 10:54:54 +08001882 case IWL_MIMO2_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001883 if (!tbl->is_ht40 && !(ht_cap->cap &
1884 IEEE80211_HT_CAP_SGI_20))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001885 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001886 if (tbl->is_ht40 && !(ht_cap->cap &
1887 IEEE80211_HT_CAP_SGI_40))
Emmanuel Grumbacha9841012008-05-15 13:54:08 +08001888 break;
1889
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001890 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1891
1892 /* Set up new search table for MIMO2 */
1893 memcpy(search_tbl, tbl, sz);
1894 search_tbl->is_SGI = !tbl->is_SGI;
1895 rs_set_expected_tpt_table(lq_sta, search_tbl);
1896 /*
1897 * If active table already uses the fastest possible
1898 * modulation (dual stream with short guard interval),
1899 * and it's working well, there's no need to look
1900 * for a better type of modulation!
1901 */
1902 if (tbl->is_SGI) {
1903 s32 tpt = lq_sta->last_tpt / 100;
1904 if (tpt >= search_tbl->expected_tpt[index])
1905 break;
1906 }
1907 search_tbl->current_rate =
1908 rate_n_flags_from_tbl(priv, search_tbl,
1909 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001910 update_search_tbl_counter = 1;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001911 goto out;
1912
1913 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1914 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1915 memcpy(search_tbl, tbl, sz);
1916 search_tbl->is_SGI = 0;
1917 search_tbl->ant_type = ANT_ABC;
1918
1919 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1920 break;
1921
1922 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1923 search_tbl, index);
1924 if (!ret)
1925 goto out;
1926
1927 break;
1928 }
1929 tbl->action++;
1930 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1931 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1932
1933 if (tbl->action == start_action)
1934 break;
1935 }
1936 search_tbl->lq_type = LQ_NONE;
1937 return 0;
1938 out:
1939 lq_sta->search_better_tbl = 1;
1940 tbl->action++;
1941 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1942 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001943 if (update_search_tbl_counter)
1944 search_tbl->action = tbl->action;
1945
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001946 return 0;
1947
1948}
1949
1950/*
1951 * Try to switch to new modulation mode from MIMO3
1952 */
1953static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1954 struct iwl_lq_sta *lq_sta,
1955 struct ieee80211_conf *conf,
1956 struct ieee80211_sta *sta, int index)
1957{
1958 s8 is_green = lq_sta->is_green;
1959 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1960 struct iwl_scale_tbl_info *search_tbl =
1961 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1962 struct iwl_rate_scale_data *window = &(tbl->win[index]);
Daniel C Halperin28e6f482009-08-13 13:30:58 -07001963 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001964 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1965 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07001966 u8 start_action;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001967 u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
1968 u8 tx_chains_num = hw_params(priv).tx_chains_num;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001969 int ret;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07001970 u8 update_search_tbl_counter = 0;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07001971
Johannes Berg290f5992010-08-23 07:56:58 -07001972 switch (priv->bt_traffic_load) {
1973 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
1974 /* nothing */
1975 break;
1976 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
1977 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1978 /* avoid antenna B and MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001979 if (tbl->action != IWL_MIMO3_SWITCH_SISO_A)
Johannes Berg290f5992010-08-23 07:56:58 -07001980 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001981 break;
Johannes Berg290f5992010-08-23 07:56:58 -07001982 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
1983 /* avoid antenna B unless MIMO */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001984 if (tbl->action == IWL_MIMO3_SWITCH_SISO_B ||
1985 tbl->action == IWL_MIMO3_SWITCH_SISO_C)
Johannes Berg290f5992010-08-23 07:56:58 -07001986 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
Johannes Berg290f5992010-08-23 07:56:58 -07001987 break;
1988 default:
1989 IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load);
1990 break;
1991 }
1992
Johannes Berg3ad3b922009-08-07 15:41:48 -07001993 if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07001994 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
1995 tbl->action > IWL_MIMO3_SWITCH_SISO_C)) {
1996 /* switch in SISO */
1997 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
1998 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001999
2000 /* configure as 1x1 if bt full concurrency */
2001 if (priv->bt_full_concurrent &&
2002 (tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
2003 tbl->action > IWL_MIMO3_SWITCH_SISO_C))
2004 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
2005
Wey-Yi Guyb1a78852010-07-31 08:52:03 -07002006 start_action = tbl->action;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002007 for (;;) {
2008 lq_sta->action_counter++;
2009 switch (tbl->action) {
2010 case IWL_MIMO3_SWITCH_ANTENNA1:
2011 case IWL_MIMO3_SWITCH_ANTENNA2:
2012 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
2013
2014 if (tx_chains_num <= 3)
2015 break;
2016
2017 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
2018 break;
2019
2020 memcpy(search_tbl, tbl, sz);
2021 if (rs_toggle_antenna(valid_tx_ant,
2022 &search_tbl->current_rate, search_tbl))
2023 goto out;
2024 break;
2025 case IWL_MIMO3_SWITCH_SISO_A:
2026 case IWL_MIMO3_SWITCH_SISO_B:
2027 case IWL_MIMO3_SWITCH_SISO_C:
2028 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
2029
2030 /* Set up new search table for SISO */
2031 memcpy(search_tbl, tbl, sz);
2032
2033 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
2034 search_tbl->ant_type = ANT_A;
2035 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
2036 search_tbl->ant_type = ANT_B;
2037 else
2038 search_tbl->ant_type = ANT_C;
2039
2040 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2041 break;
2042
2043 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
2044 search_tbl, index);
2045 if (!ret)
2046 goto out;
2047
2048 break;
2049
2050 case IWL_MIMO3_SWITCH_MIMO2_AB:
2051 case IWL_MIMO3_SWITCH_MIMO2_AC:
2052 case IWL_MIMO3_SWITCH_MIMO2_BC:
2053 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
2054
2055 memcpy(search_tbl, tbl, sz);
2056 search_tbl->is_SGI = 0;
2057 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
2058 search_tbl->ant_type = ANT_AB;
2059 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
2060 search_tbl->ant_type = ANT_AC;
2061 else
2062 search_tbl->ant_type = ANT_BC;
2063
2064 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
2065 break;
2066
2067 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
2068 search_tbl, index);
2069 if (!ret)
2070 goto out;
2071
2072 break;
2073
2074 case IWL_MIMO3_SWITCH_GI:
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002075 if (!tbl->is_ht40 && !(ht_cap->cap &
2076 IEEE80211_HT_CAP_SGI_20))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002077 break;
Daniel C Halperin28e6f482009-08-13 13:30:58 -07002078 if (tbl->is_ht40 && !(ht_cap->cap &
2079 IEEE80211_HT_CAP_SGI_40))
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002080 break;
2081
2082 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
Ben Cahill77626352007-11-29 11:09:44 +08002083
2084 /* Set up new search table for MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07002085 memcpy(search_tbl, tbl, sz);
Guy Cohen39e88502008-04-23 17:14:57 -07002086 search_tbl->is_SGI = !tbl->is_SGI;
Guy Coheneecd6e52008-04-23 17:14:58 -07002087 rs_set_expected_tpt_table(lq_sta, search_tbl);
Ben Cahill77626352007-11-29 11:09:44 +08002088 /*
2089 * If active table already uses the fastest possible
2090 * modulation (dual stream with short guard interval),
2091 * and it's working well, there's no need to look
2092 * for a better type of modulation!
2093 */
Guy Cohen39e88502008-04-23 17:14:57 -07002094 if (tbl->is_SGI) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002095 s32 tpt = lq_sta->last_tpt / 100;
Guy Cohen39e88502008-04-23 17:14:57 -07002096 if (tpt >= search_tbl->expected_tpt[index])
2097 break;
Zhu Yib481de92007-09-25 17:54:57 -07002098 }
Tomas Winkler978785a2008-12-19 10:37:31 +08002099 search_tbl->current_rate =
2100 rate_n_flags_from_tbl(priv, search_tbl,
2101 index, is_green);
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002102 update_search_tbl_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002103 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002104 }
2105 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002106 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2107 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Zhu Yib481de92007-09-25 17:54:57 -07002108
2109 if (tbl->action == start_action)
2110 break;
2111 }
Guy Cohen3110bef2008-09-09 10:54:54 +08002112 search_tbl->lq_type = LQ_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07002113 return 0;
2114 out:
Guy Cohen3110bef2008-09-09 10:54:54 +08002115 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002116 tbl->action++;
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002117 if (tbl->action > IWL_MIMO3_SWITCH_GI)
2118 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002119 if (update_search_tbl_counter)
2120 search_tbl->action = tbl->action;
2121
Zhu Yib481de92007-09-25 17:54:57 -07002122 return 0;
2123
2124}
2125
Ben Cahill77626352007-11-29 11:09:44 +08002126/*
2127 * Check whether we should continue using same modulation mode, or
2128 * begin search for a new mode, based on:
2129 * 1) # tx successes or failures while using this mode
2130 * 2) # times calling this function
2131 * 3) elapsed time in this mode (not used, for now)
2132 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002133static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
Zhu Yib481de92007-09-25 17:54:57 -07002134{
Tomas Winklere227cea2008-07-18 13:53:05 +08002135 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002136 int i;
2137 int active_tbl;
2138 int flush_interval_passed = 0;
Ester Kummerbf403db2008-05-05 10:22:40 +08002139 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07002140
Ester Kummerbf403db2008-05-05 10:22:40 +08002141 priv = lq_sta->drv;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002142 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002143
Tomas Winklerc33104f2008-01-14 17:46:21 -08002144 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002145
Ben Cahill77626352007-11-29 11:09:44 +08002146 /* If we've been disallowing search, see if we should now allow it */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002147 if (lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002148
Ben Cahill77626352007-11-29 11:09:44 +08002149 /* Elapsed time using current modulation mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002150 if (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002151 flush_interval_passed =
Mohamed Abbas447fee72009-04-20 14:37:02 -07002152 time_after(jiffies,
2153 (unsigned long)(lq_sta->flush_timer +
Zhu Yib481de92007-09-25 17:54:57 -07002154 IWL_RATE_SCALE_FLUSH_INTVL));
2155
Ben Cahill77626352007-11-29 11:09:44 +08002156 /*
2157 * Check if we should allow search for new modulation mode.
2158 * If many frames have failed or succeeded, or we've used
2159 * this same modulation for a long time, allow search, and
2160 * reset history stats that keep track of whether we should
2161 * allow a new search. Also (below) reset all bitmaps and
2162 * stats in active history.
2163 */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002164 if (force_search ||
2165 (lq_sta->total_failed > lq_sta->max_failure_limit) ||
Tomas Winklerc33104f2008-01-14 17:46:21 -08002166 (lq_sta->total_success > lq_sta->max_success_limit) ||
2167 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07002168 && (flush_interval_passed))) {
Tomas Winklere1623442009-01-27 14:27:56 -08002169 IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n:",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002170 lq_sta->total_failed,
2171 lq_sta->total_success,
Zhu Yib481de92007-09-25 17:54:57 -07002172 flush_interval_passed);
Ben Cahill77626352007-11-29 11:09:44 +08002173
2174 /* Allow search for new mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002175 lq_sta->stay_in_tbl = 0; /* only place reset */
2176 lq_sta->total_failed = 0;
2177 lq_sta->total_success = 0;
2178 lq_sta->flush_timer = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002179
2180 /*
2181 * Else if we've used this modulation mode enough repetitions
2182 * (regardless of elapsed time or success/failure), reset
2183 * history bitmaps and rate-specific stats for all rates in
2184 * active table.
2185 */
Mohamed Abbas403ab562007-11-06 22:06:25 -08002186 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002187 lq_sta->table_count++;
2188 if (lq_sta->table_count >=
2189 lq_sta->table_count_limit) {
2190 lq_sta->table_count = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002191
Tomas Winklere1623442009-01-27 14:27:56 -08002192 IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n");
Zhu Yib481de92007-09-25 17:54:57 -07002193 for (i = 0; i < IWL_RATE_COUNT; i++)
2194 rs_rate_scale_clear_window(
2195 &(tbl->win[i]));
2196 }
2197 }
2198
Ben Cahill77626352007-11-29 11:09:44 +08002199 /* If transitioning to allow "search", reset all history
2200 * bitmaps and stats in active table (this will become the new
2201 * "search" table). */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002202 if (!lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07002203 for (i = 0; i < IWL_RATE_COUNT; i++)
2204 rs_rate_scale_clear_window(&(tbl->win[i]));
2205 }
2206 }
2207}
2208
Ben Cahill77626352007-11-29 11:09:44 +08002209/*
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002210 * setup rate table in uCode
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002211 */
Johannes Berg70817b52011-05-11 03:29:25 -07002212static void rs_update_rate_tbl(struct iwl_priv *priv,
2213 struct iwl_rxon_context *ctx,
2214 struct iwl_lq_sta *lq_sta,
2215 struct iwl_scale_tbl_info *tbl,
2216 int index, u8 is_green)
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002217{
2218 u32 rate;
2219
2220 /* Update uCode's rate table. */
2221 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
2222 rs_fill_link_cmd(priv, lq_sta, rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002223 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002224}
2225
2226/*
Ben Cahill77626352007-11-29 11:09:44 +08002227 * Do rate scaling and search for new modulation mode.
2228 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002229static void rs_rate_scale_perform(struct iwl_priv *priv,
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002230 struct sk_buff *skb,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002231 struct ieee80211_sta *sta,
2232 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002233{
Johannes Berg4b7679a2008-09-18 18:14:18 +02002234 struct ieee80211_hw *hw = priv->hw;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002235 struct ieee80211_conf *conf = &hw->conf;
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002236 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2237 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002238 int low = IWL_RATE_INVALID;
2239 int high = IWL_RATE_INVALID;
2240 int index;
2241 int i;
Tomas Winklere227cea2008-07-18 13:53:05 +08002242 struct iwl_rate_scale_data *window = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002243 int current_tpt = IWL_INVALID_VALUE;
2244 int low_tpt = IWL_INVALID_VALUE;
2245 int high_tpt = IWL_INVALID_VALUE;
2246 u32 fail_count;
2247 s8 scale_action = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07002248 u16 rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -07002249 u8 update_lq = 0;
Tomas Winklere227cea2008-07-18 13:53:05 +08002250 struct iwl_scale_tbl_info *tbl, *tbl1;
Zhu Yib481de92007-09-25 17:54:57 -07002251 u16 rate_scale_index_msk = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002252 u8 is_green = 0;
2253 u8 active_tbl = 0;
2254 u8 done_search = 0;
2255 u16 high_low;
Guy Cohena5e8b502008-05-29 16:35:11 +08002256 s32 sr;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002257 u8 tid = IWL_MAX_TID_COUNT;
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002258 struct iwl_tid_data *tid_data;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002259 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002260 struct iwl_rxon_context *ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002261
Tomas Winklere1623442009-01-27 14:27:56 -08002262 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002263
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002264 /* Send management frames and NO_ACK data using lowest rate. */
Tomas Winkler417f1142008-11-12 13:14:06 -08002265 /* TODO: this could probably be improved.. */
2266 if (!ieee80211_is_data(hdr->frame_control) ||
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002267 info->flags & IEEE80211_TX_CTL_NO_ACK)
Zhu Yib481de92007-09-25 17:54:57 -07002268 return;
Zhu Yib481de92007-09-25 17:54:57 -07002269
Johannes Berg4b7679a2008-09-18 18:14:18 +02002270 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
Zhu Yib481de92007-09-25 17:54:57 -07002271
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002272 tid = rs_tl_add_packet(lq_sta, hdr);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002273 if ((tid != IWL_MAX_TID_COUNT) &&
2274 (lq_sta->tx_agg_tid_en & (1 << tid))) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002275 tid_data = &priv->tid_data[lq_sta->lq.sta_id][tid];
Daniel C Halperine3949d62009-09-17 10:43:50 -07002276 if (tid_data->agg.state == IWL_AGG_OFF)
2277 lq_sta->is_agg = 0;
2278 else
2279 lq_sta->is_agg = 1;
2280 } else
2281 lq_sta->is_agg = 0;
Ron Rindjunskyfaa29712008-06-12 09:46:58 +08002282
Ben Cahill77626352007-11-29 11:09:44 +08002283 /*
2284 * Select rate-scale / modulation-mode table to work with in
2285 * the rest of this function: "search" if searching for better
2286 * modulation mode, or "active" if doing rate scaling within a mode.
2287 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002288 if (!lq_sta->search_better_tbl)
2289 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002290 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002291 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002292
Tomas Winklerc33104f2008-01-14 17:46:21 -08002293 tbl = &(lq_sta->lq_info[active_tbl]);
Wey-Yi Guy2681b202009-05-21 13:44:22 -07002294 if (is_legacy(tbl->lq_type))
2295 lq_sta->is_green = 0;
2296 else
Johannes Berg7e6a5882010-08-23 10:46:46 +02002297 lq_sta->is_green = rs_use_green(sta);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002298 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07002299
Ben Cahill77626352007-11-29 11:09:44 +08002300 /* current tx rate */
Johannes Bergb7e35002008-09-11 02:22:58 +02002301 index = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002302
Tomas Winklere1623442009-01-27 14:27:56 -08002303 IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index,
Zhu Yib481de92007-09-25 17:54:57 -07002304 tbl->lq_type);
2305
Ben Cahill77626352007-11-29 11:09:44 +08002306 /* rates available for this association, and for modulation mode */
Guy Coheneecd6e52008-04-23 17:14:58 -07002307 rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
Zhu Yib481de92007-09-25 17:54:57 -07002308
Frans Pop91dd6c22010-03-24 14:19:58 -07002309 IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -07002310
2311 /* mask with station rate restriction */
2312 if (is_legacy(tbl->lq_type)) {
Johannes Berg8318d782008-01-24 19:38:38 +01002313 if (lq_sta->band == IEEE80211_BAND_5GHZ)
Ben Cahill77626352007-11-29 11:09:44 +08002314 /* supp_rates has no CCK bits in A mode */
Zhu Yib481de92007-09-25 17:54:57 -07002315 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002316 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -07002317 else
2318 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08002319 lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -07002320
2321 } else
2322 rate_scale_index_msk = rate_mask;
2323
2324 if (!rate_scale_index_msk)
2325 rate_scale_index_msk = rate_mask;
2326
Guy Cohen07bc28e2008-04-23 17:15:03 -07002327 if (!((1 << index) & rate_scale_index_msk)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002328 IWL_ERR(priv, "Current Rate is not valid\n");
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002329 if (lq_sta->search_better_tbl) {
2330 /* revert to active table if search table is not valid*/
2331 tbl->lq_type = LQ_NONE;
2332 lq_sta->search_better_tbl = 0;
2333 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
2334 /* get "active" rate info */
2335 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Johannes Berg70817b52011-05-11 03:29:25 -07002336 rs_update_rate_tbl(priv, ctx, lq_sta, tbl,
2337 index, is_green);
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002338 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002339 return;
Zhu Yib481de92007-09-25 17:54:57 -07002340 }
2341
Ben Cahill77626352007-11-29 11:09:44 +08002342 /* Get expected throughput table and history window for current rate */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002343 if (!tbl->expected_tpt) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002344 IWL_ERR(priv, "tbl->expected_tpt is NULL\n");
Guy Cohen07bc28e2008-04-23 17:15:03 -07002345 return;
2346 }
Zhu Yib481de92007-09-25 17:54:57 -07002347
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002348 /* force user max rate if set by user */
2349 if ((lq_sta->max_rate_idx != -1) &&
2350 (lq_sta->max_rate_idx < index)) {
2351 index = lq_sta->max_rate_idx;
2352 update_lq = 1;
2353 window = &(tbl->win[index]);
2354 goto lq_update;
2355 }
2356
Zhu Yib481de92007-09-25 17:54:57 -07002357 window = &(tbl->win[index]);
2358
Ben Cahill77626352007-11-29 11:09:44 +08002359 /*
2360 * If there is not enough history to calculate actual average
2361 * throughput, keep analyzing results of more tx frames, without
2362 * changing rate or mode (bypass most of the rest of this function).
2363 * Set up new rate table in uCode only if old rate is not supported
2364 * in current association (use new rate found above).
2365 */
Zhu Yib481de92007-09-25 17:54:57 -07002366 fail_count = window->counter - window->success_counter;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002367 if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
2368 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002369 IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d "
Zhu Yib481de92007-09-25 17:54:57 -07002370 "for index %d\n",
2371 window->success_counter, window->counter, index);
Ben Cahill77626352007-11-29 11:09:44 +08002372
2373 /* Can't calculate this yet; not enough history */
Zhu Yib481de92007-09-25 17:54:57 -07002374 window->average_tpt = IWL_INVALID_VALUE;
Ben Cahill77626352007-11-29 11:09:44 +08002375
2376 /* Should we stay with this modulation mode,
2377 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002378 rs_stay_in_table(lq_sta, false);
Ben Cahill77626352007-11-29 11:09:44 +08002379
Zhu Yib481de92007-09-25 17:54:57 -07002380 goto out;
Guy Cohen3110bef2008-09-09 10:54:54 +08002381 }
Ben Cahill77626352007-11-29 11:09:44 +08002382 /* Else we have enough samples; calculate estimate of
2383 * actual average throughput */
Reinette Chatre3d79b2a2010-05-03 10:55:07 -07002384 if (window->average_tpt != ((window->success_ratio *
2385 tbl->expected_tpt[index] + 64) / 128)) {
2386 IWL_ERR(priv, "expected_tpt should have been calculated by now\n");
2387 window->average_tpt = ((window->success_ratio *
2388 tbl->expected_tpt[index] + 64) / 128);
2389 }
Zhu Yib481de92007-09-25 17:54:57 -07002390
Ben Cahill77626352007-11-29 11:09:44 +08002391 /* If we are searching for better modulation mode, check success. */
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002392 if (lq_sta->search_better_tbl &&
Johannes Berg3ad3b922009-08-07 15:41:48 -07002393 (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) {
Ben Cahill77626352007-11-29 11:09:44 +08002394 /* If good success, continue using the "search" mode;
2395 * no need to send new link quality command, since we're
2396 * continuing to use the setup that we've been trying. */
Guy Cohen07bc28e2008-04-23 17:15:03 -07002397 if (window->average_tpt > lq_sta->last_tpt) {
2398
Tomas Winklere1623442009-01-27 14:27:56 -08002399 IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002400 "suc=%d cur-tpt=%d old-tpt=%d\n",
2401 window->success_ratio,
2402 window->average_tpt,
2403 lq_sta->last_tpt);
2404
2405 if (!is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002406 lq_sta->enable_counter = 1;
Guy Cohen07bc28e2008-04-23 17:15:03 -07002407
Ben Cahill77626352007-11-29 11:09:44 +08002408 /* Swap tables; "search" becomes "active" */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002409 lq_sta->active_tbl = active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002410 current_tpt = window->average_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002411
2412 /* Else poor success; go back to mode in "active" table */
Zhu Yib481de92007-09-25 17:54:57 -07002413 } else {
Guy Cohen07bc28e2008-04-23 17:15:03 -07002414
Tomas Winklere1623442009-01-27 14:27:56 -08002415 IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE "
Guy Cohen07bc28e2008-04-23 17:15:03 -07002416 "suc=%d cur-tpt=%d old-tpt=%d\n",
2417 window->success_ratio,
2418 window->average_tpt,
2419 lq_sta->last_tpt);
2420
Ben Cahill77626352007-11-29 11:09:44 +08002421 /* Nullify "search" table */
Zhu Yib481de92007-09-25 17:54:57 -07002422 tbl->lq_type = LQ_NONE;
Ben Cahill77626352007-11-29 11:09:44 +08002423
2424 /* Revert to "active" table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002425 active_tbl = lq_sta->active_tbl;
2426 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002427
Ben Cahill77626352007-11-29 11:09:44 +08002428 /* Revert to "active" rate and throughput info */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002429 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002430 current_tpt = lq_sta->last_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08002431
2432 /* Need to set up a new rate table in uCode */
2433 update_lq = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002434 }
Ben Cahill77626352007-11-29 11:09:44 +08002435
2436 /* Either way, we've made a decision; modulation mode
2437 * search is done, allow rate adjustment next time. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002438 lq_sta->search_better_tbl = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002439 done_search = 1; /* Don't switch modes below! */
Zhu Yib481de92007-09-25 17:54:57 -07002440 goto lq_update;
2441 }
2442
Ben Cahill77626352007-11-29 11:09:44 +08002443 /* (Else) not in search of better modulation mode, try for better
2444 * starting rate, while staying in this mode. */
Ester Kummerbf403db2008-05-05 10:22:40 +08002445 high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk,
Zhu Yib481de92007-09-25 17:54:57 -07002446 tbl->lq_type);
2447 low = high_low & 0xff;
2448 high = (high_low >> 8) & 0xff;
2449
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002450 /* If user set max rate, dont allow higher than user constrain */
2451 if ((lq_sta->max_rate_idx != -1) &&
2452 (lq_sta->max_rate_idx < high))
2453 high = IWL_RATE_INVALID;
2454
Guy Cohena5e8b502008-05-29 16:35:11 +08002455 sr = window->success_ratio;
2456
Ben Cahill77626352007-11-29 11:09:44 +08002457 /* Collect measured throughputs for current and adjacent rates */
Zhu Yib481de92007-09-25 17:54:57 -07002458 current_tpt = window->average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002459 if (low != IWL_RATE_INVALID)
2460 low_tpt = tbl->win[low].average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002461 if (high != IWL_RATE_INVALID)
2462 high_tpt = tbl->win[high].average_tpt;
2463
Guy Cohena5e8b502008-05-29 16:35:11 +08002464 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002465
Ben Cahill77626352007-11-29 11:09:44 +08002466 /* Too many failures, decrease rate */
Guy Cohena5e8b502008-05-29 16:35:11 +08002467 if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002468 IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n");
Zhu Yib481de92007-09-25 17:54:57 -07002469 scale_action = -1;
Ben Cahill77626352007-11-29 11:09:44 +08002470
2471 /* No throughput measured yet for adjacent rates; try increase. */
Zhu Yib481de92007-09-25 17:54:57 -07002472 } else if ((low_tpt == IWL_INVALID_VALUE) &&
Guy Cohena5e8b502008-05-29 16:35:11 +08002473 (high_tpt == IWL_INVALID_VALUE)) {
2474
2475 if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
2476 scale_action = 1;
2477 else if (low != IWL_RATE_INVALID)
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002478 scale_action = 0;
Guy Cohena5e8b502008-05-29 16:35:11 +08002479 }
Ben Cahill77626352007-11-29 11:09:44 +08002480
2481 /* Both adjacent throughputs are measured, but neither one has better
2482 * throughput; we're using the best rate, don't change it! */
Zhu Yib481de92007-09-25 17:54:57 -07002483 else if ((low_tpt != IWL_INVALID_VALUE) &&
2484 (high_tpt != IWL_INVALID_VALUE) &&
2485 (low_tpt < current_tpt) &&
2486 (high_tpt < current_tpt))
2487 scale_action = 0;
Ben Cahill77626352007-11-29 11:09:44 +08002488
2489 /* At least one adjacent rate's throughput is measured,
2490 * and may have better performance. */
Zhu Yib481de92007-09-25 17:54:57 -07002491 else {
Ben Cahill77626352007-11-29 11:09:44 +08002492 /* Higher adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002493 if (high_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002494 /* Higher rate has better throughput */
Guy Cohena5e8b502008-05-29 16:35:11 +08002495 if (high_tpt > current_tpt &&
2496 sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002497 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002498 } else {
Wey-Yi Guy8fe72312009-03-10 14:35:10 -07002499 scale_action = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002500 }
Ben Cahill77626352007-11-29 11:09:44 +08002501
2502 /* Lower adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07002503 } else if (low_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08002504 /* Lower rate has better throughput */
Zhu Yib481de92007-09-25 17:54:57 -07002505 if (low_tpt > current_tpt) {
Tomas Winklere1623442009-01-27 14:27:56 -08002506 IWL_DEBUG_RATE(priv,
2507 "decrease rate because of low tpt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002508 scale_action = -1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002509 } else if (sr >= IWL_RATE_INCREASE_TH) {
Zhu Yib481de92007-09-25 17:54:57 -07002510 scale_action = 1;
Guy Cohena5e8b502008-05-29 16:35:11 +08002511 }
Zhu Yib481de92007-09-25 17:54:57 -07002512 }
2513 }
2514
Ben Cahill77626352007-11-29 11:09:44 +08002515 /* Sanity check; asked for decrease, but success rate or throughput
2516 * has been good at old rate. Don't change it. */
Guy Cohena5e8b502008-05-29 16:35:11 +08002517 if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
2518 ((sr > IWL_RATE_HIGH_TH) ||
Zhu Yib481de92007-09-25 17:54:57 -07002519 (current_tpt > (100 * tbl->expected_tpt[low]))))
Zhu Yib481de92007-09-25 17:54:57 -07002520 scale_action = 0;
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002521 if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type))
2522 scale_action = -1;
Johannes Berg3ad3b922009-08-07 15:41:48 -07002523 if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002524 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type)))
2525 scale_action = -1;
Johannes Berg290f5992010-08-23 07:56:58 -07002526
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002527 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2528 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2529 if (lq_sta->last_bt_traffic > priv->bt_traffic_load) {
2530 /*
2531 * don't set scale_action, don't want to scale up if
2532 * the rate scale doesn't otherwise think that is a
2533 * good idea.
2534 */
2535 } else if (lq_sta->last_bt_traffic <= priv->bt_traffic_load) {
2536 scale_action = -1;
2537 }
2538 }
2539 lq_sta->last_bt_traffic = priv->bt_traffic_load;
2540
2541 if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) &&
2542 (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) {
2543 /* search for a new modulation */
2544 rs_stay_in_table(lq_sta, true);
2545 goto lq_update;
Johannes Berg290f5992010-08-23 07:56:58 -07002546 }
2547
Zhu Yib481de92007-09-25 17:54:57 -07002548 switch (scale_action) {
2549 case -1:
Ben Cahill77626352007-11-29 11:09:44 +08002550 /* Decrease starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002551 if (low != IWL_RATE_INVALID) {
2552 update_lq = 1;
2553 index = low;
2554 }
Mohamed Abbas447fee72009-04-20 14:37:02 -07002555
Zhu Yib481de92007-09-25 17:54:57 -07002556 break;
2557 case 1:
Ben Cahill77626352007-11-29 11:09:44 +08002558 /* Increase starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002559 if (high != IWL_RATE_INVALID) {
2560 update_lq = 1;
2561 index = high;
2562 }
2563
2564 break;
2565 case 0:
Ben Cahill77626352007-11-29 11:09:44 +08002566 /* No change */
Zhu Yib481de92007-09-25 17:54:57 -07002567 default:
2568 break;
2569 }
2570
Tomas Winklere1623442009-01-27 14:27:56 -08002571 IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d "
Zhu Yib481de92007-09-25 17:54:57 -07002572 "high %d type %d\n",
2573 index, scale_action, low, high, tbl->lq_type);
2574
Guy Cohena5e8b502008-05-29 16:35:11 +08002575lq_update:
Ben Cahill77626352007-11-29 11:09:44 +08002576 /* Replace uCode's rate table for the destination station. */
Wey-Yi Guye3139fe2009-07-24 11:13:00 -07002577 if (update_lq)
Johannes Berg70817b52011-05-11 03:29:25 -07002578 rs_update_rate_tbl(priv, ctx, lq_sta, tbl, index, is_green);
Ben Cahill77626352007-11-29 11:09:44 +08002579
Johannes Berg3ad3b922009-08-07 15:41:48 -07002580 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) {
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002581 /* Should we stay with this modulation mode,
2582 * or search for a new one? */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002583 rs_stay_in_table(lq_sta, false);
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002584 }
Ben Cahill77626352007-11-29 11:09:44 +08002585 /*
2586 * Search for new modulation mode if we're:
2587 * 1) Not changing rates right now
2588 * 2) Not just finishing up a search
2589 * 3) Allowing a new search
2590 */
Guy Cohen47cfd462008-05-27 11:29:34 +08002591 if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) {
Ben Cahill77626352007-11-29 11:09:44 +08002592 /* Save current throughput to compare with "search" throughput*/
Tomas Winklerc33104f2008-01-14 17:46:21 -08002593 lq_sta->last_tpt = current_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07002594
Ben Cahill77626352007-11-29 11:09:44 +08002595 /* Select a new "search" modulation mode to try.
2596 * If one is found, set up the new "search" table. */
Zhu Yib481de92007-09-25 17:54:57 -07002597 if (is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002598 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002599 else if (is_siso(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08002600 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002601 else if (is_mimo2(tbl->lq_type))
2602 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002603 else
Wey-Yi Guy584a0f02009-04-01 14:33:24 -07002604 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07002605
Ben Cahill77626352007-11-29 11:09:44 +08002606 /* If new "search" mode was selected, set up in uCode table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002607 if (lq_sta->search_better_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002608 /* Access the "search" table, clear its history. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002609 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Zhu Yib481de92007-09-25 17:54:57 -07002610 for (i = 0; i < IWL_RATE_COUNT; i++)
2611 rs_rate_scale_clear_window(&(tbl->win[i]));
2612
Ben Cahill77626352007-11-29 11:09:44 +08002613 /* Use new "search" start rate */
Tomas Winklere7d326ac2008-06-12 09:47:11 +08002614 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002615
Tomas Winklere1623442009-01-27 14:27:56 -08002616 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n",
Guy Cohen39e88502008-04-23 17:14:57 -07002617 tbl->current_rate, index);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002618 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
Johannes Berg7e6a5882010-08-23 10:46:46 +02002619 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
Mohamed Abbas447fee72009-04-20 14:37:02 -07002620 } else
2621 done_search = 1;
2622 }
Zhu Yib481de92007-09-25 17:54:57 -07002623
Mohamed Abbas447fee72009-04-20 14:37:02 -07002624 if (done_search && !lq_sta->stay_in_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08002625 /* If the "active" (non-search) mode was legacy,
2626 * and we've tried switching antennas,
2627 * but we haven't been able to try HT modes (not available),
2628 * stay with best antenna legacy modulation for a while
2629 * before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002630 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002631 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
Mohamed Abbasd6e93392009-05-08 13:44:39 -07002632 lq_sta->action_counter > tbl1->max_search) {
Tomas Winklere1623442009-01-27 14:27:56 -08002633 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08002634 rs_set_stay_in_table(priv, 1, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002635 }
2636
Ben Cahill77626352007-11-29 11:09:44 +08002637 /* If we're in an HT mode, and all 3 mode switch actions
2638 * have been tried and compared, stay in this best modulation
2639 * mode for a while before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002640 if (lq_sta->enable_counter &&
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002641 (lq_sta->action_counter >= tbl1->max_search) &&
2642 iwl_ht_enabled(priv)) {
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002643 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2644 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07002645 (tid != IWL_MAX_TID_COUNT)) {
2646 u8 sta_id = lq_sta->lq.sta_id;
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02002647 tid_data = &priv->tid_data[sta_id][tid];
Wey-Yi Guy86b47662009-03-10 14:35:09 -07002648 if (tid_data->agg.state == IWL_AGG_OFF) {
2649 IWL_DEBUG_RATE(priv,
2650 "try to aggregate tid %d\n",
2651 tid);
2652 rs_tl_turn_on_agg(priv, tid,
2653 lq_sta, sta);
2654 }
Zhu Yib481de92007-09-25 17:54:57 -07002655 }
Ester Kummerbf403db2008-05-05 10:22:40 +08002656 rs_set_stay_in_table(priv, 0, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002657 }
Zhu Yib481de92007-09-25 17:54:57 -07002658 }
2659
2660out:
Tomas Winkler978785a2008-12-19 10:37:31 +08002661 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
Wey-Yi Guyc3322b32011-10-10 07:26:58 -07002662 lq_sta->last_txrate_idx = index;
Zhu Yib481de92007-09-25 17:54:57 -07002663}
2664
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002665/**
2666 * rs_initialize_lq - Initialize a station's hardware rate table
2667 *
2668 * The uCode's station table contains a table of fallback rates
2669 * for automatic fallback during transmission.
2670 *
2671 * NOTE: This sets up a default set of values. These will be replaced later
2672 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
2673 * rc80211_simple.
2674 *
2675 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
2676 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
2677 * which requires station table entry to exist).
2678 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002679static void rs_initialize_lq(struct iwl_priv *priv,
Johannes Berg4b7679a2008-09-18 18:14:18 +02002680 struct ieee80211_sta *sta,
2681 struct iwl_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07002682{
Tomas Winklere227cea2008-07-18 13:53:05 +08002683 struct iwl_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002684 int rate_idx;
Guy Cohenaade00c2008-04-23 17:14:59 -07002685 int i;
Guy Cohen39e88502008-04-23 17:14:57 -07002686 u32 rate;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002687 u8 use_green = rs_use_green(sta);
Guy Cohenaade00c2008-04-23 17:14:59 -07002688 u8 active_tbl = 0;
2689 u8 valid_tx_ant;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002690 struct iwl_station_priv *sta_priv;
2691 struct iwl_rxon_context *ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002692
Johannes Berg4b7679a2008-09-18 18:14:18 +02002693 if (!sta || !lq_sta)
Johannes Berg7e6a5882010-08-23 10:46:46 +02002694 return;
2695
2696 sta_priv = (void *)sta->drv_priv;
Johannes Bergc6892902011-09-20 15:37:21 -07002697 ctx = sta_priv->ctx;
Zhu Yib481de92007-09-25 17:54:57 -07002698
Johannes Bergb7e35002008-09-11 02:22:58 +02002699 i = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002700
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002701 valid_tx_ant = hw_params(priv).valid_tx_ant;
Guy Cohenaade00c2008-04-23 17:14:59 -07002702
Tomas Winklerc33104f2008-01-14 17:46:21 -08002703 if (!lq_sta->search_better_tbl)
2704 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002705 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002706 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002707
Tomas Winklerc33104f2008-01-14 17:46:21 -08002708 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002709
2710 if ((i < 0) || (i >= IWL_RATE_COUNT))
2711 i = 0;
2712
Tomas Winkler1826dcc2008-05-15 13:54:02 +08002713 rate = iwl_rates[i].plcp;
Winkler, Tomaseb48dca2008-10-29 14:05:48 -07002714 tbl->ant_type = first_antenna(valid_tx_ant);
2715 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
Zhu Yib481de92007-09-25 17:54:57 -07002716
2717 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
Guy Cohen39e88502008-04-23 17:14:57 -07002718 rate |= RATE_MCS_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002719
Guy Cohen39e88502008-04-23 17:14:57 -07002720 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
Guy Cohenaade00c2008-04-23 17:14:59 -07002721 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2722 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07002723
Tomas Winkler978785a2008-12-19 10:37:31 +08002724 rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green);
Guy Cohen39e88502008-04-23 17:14:57 -07002725 tbl->current_rate = rate;
Guy Coheneecd6e52008-04-23 17:14:58 -07002726 rs_set_expected_tpt_table(lq_sta, tbl);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002727 rs_fill_link_cmd(NULL, lq_sta, rate);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002728 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002729 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true);
Zhu Yib481de92007-09-25 17:54:57 -07002730}
2731
Johannes Berge6a98542008-10-21 12:40:02 +02002732static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2733 struct ieee80211_tx_rate_control *txrc)
Zhu Yib481de92007-09-25 17:54:57 -07002734{
2735
Johannes Berge6a98542008-10-21 12:40:02 +02002736 struct sk_buff *skb = txrc->skb;
2737 struct ieee80211_supported_band *sband = txrc->sband;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002738 struct iwl_op_mode *op_mode __maybe_unused =
2739 (struct iwl_op_mode *)priv_r;
2740 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berge6a98542008-10-21 12:40:02 +02002741 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Tomas Winkler417f1142008-11-12 13:14:06 -08002742 struct iwl_lq_sta *lq_sta = priv_sta;
2743 int rate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002744
Tomas Winklere1623442009-01-27 14:27:56 -08002745 IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002746
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002747 /* Get max rate if user set max rate */
2748 if (lq_sta) {
2749 lq_sta->max_rate_idx = txrc->max_rate_idx;
2750 if ((sband->band == IEEE80211_BAND_5GHZ) &&
2751 (lq_sta->max_rate_idx != -1))
2752 lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
2753 if ((lq_sta->max_rate_idx < 0) ||
2754 (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
2755 lq_sta->max_rate_idx = -1;
2756 }
2757
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002758 /* Treat uninitialized rate scaling data same as non-existing. */
2759 if (lq_sta && !lq_sta->drv) {
2760 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
2761 priv_sta = NULL;
2762 }
2763
Gábor Stefanik514d65c2009-04-23 19:36:08 +02002764 /* Send management frames and NO_ACK data using lowest rate. */
Luis R. Rodriguez4c6d4f52009-07-16 10:05:41 -07002765 if (rate_control_send_low(sta, priv_sta, txrc))
Johannes Berg4b7679a2008-09-18 18:14:18 +02002766 return;
Zhu Yib481de92007-09-25 17:54:57 -07002767
Tomas Winkler417f1142008-11-12 13:14:06 -08002768 rate_idx = lq_sta->last_txrate_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002769
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002770 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
Tomas Winkler417f1142008-11-12 13:14:06 -08002771 rate_idx -= IWL_FIRST_OFDM_RATE;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002772 /* 6M and 9M shared same MCS index */
2773 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2774 if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2775 IWL_RATE_MIMO3_6M_PLCP)
2776 rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
2777 else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2778 IWL_RATE_MIMO2_6M_PLCP)
2779 rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
2780 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2781 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2782 info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
2783 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2784 info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07002785 if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK)
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002786 info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2787 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2788 info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
2789 } else {
Daniel C Halperin50273092009-08-28 09:44:45 -07002790 /* Check for invalid rates */
2791 if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
2792 ((sband->band == IEEE80211_BAND_5GHZ) &&
2793 (rate_idx < IWL_FIRST_OFDM_RATE)))
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002794 rate_idx = rate_lowest_index(sband, sta);
Daniel C Halperin50273092009-08-28 09:44:45 -07002795 /* On valid 5 GHz rate, adjust index */
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002796 else if (sband->band == IEEE80211_BAND_5GHZ)
2797 rate_idx -= IWL_FIRST_OFDM_RATE;
Daniel C Halperin7ebaeff2009-08-21 13:34:20 -07002798 info->control.rates[0].flags = 0;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002799 }
Tomas Winkler417f1142008-11-12 13:14:06 -08002800 info->control.rates[0].idx = rate_idx;
Wey-Yi Guya9c146b2009-05-22 11:01:48 -07002801
Zhu Yib481de92007-09-25 17:54:57 -07002802}
2803
Johannes Berg4b7679a2008-09-18 18:14:18 +02002804static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2805 gfp_t gfp)
Zhu Yib481de92007-09-25 17:54:57 -07002806{
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002807 struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002808 struct iwl_op_mode *op_mode __maybe_unused =
2809 (struct iwl_op_mode *)priv_rate;
2810 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002811
Tomas Winklere1623442009-01-27 14:27:56 -08002812 IWL_DEBUG_RATE(priv, "create station rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -07002813
Johannes Berg08960de2011-04-05 09:41:53 -07002814 return &sta_priv->lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002815}
2816
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002817/*
2818 * Called after adding a new station to initialize rate scaling
2819 */
2820void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002821{
2822 int i, j;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002823 struct ieee80211_hw *hw = priv->hw;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002824 struct ieee80211_conf *conf = &priv->hw->conf;
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002825 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002826 struct iwl_station_priv *sta_priv;
2827 struct iwl_lq_sta *lq_sta;
2828 struct ieee80211_supported_band *sband;
Zhu Yib481de92007-09-25 17:54:57 -07002829
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002830 sta_priv = (struct iwl_station_priv *) sta->drv_priv;
2831 lq_sta = &sta_priv->lq_sta;
2832 sband = hw->wiphy->bands[conf->channel->band];
2833
2834
2835 lq_sta->lq.sta_id = sta_id;
Reinette Chatre5ad13f82009-10-30 14:36:14 -07002836
2837 for (j = 0; j < LQ_SIZE; j++)
2838 for (i = 0; i < IWL_RATE_COUNT; i++)
2839 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2840
Tomas Winklerc33104f2008-01-14 17:46:21 -08002841 lq_sta->flush_timer = 0;
Johannes Berg4b7679a2008-09-18 18:14:18 +02002842 lq_sta->supp_rates = sta->supp_rates[sband->band];
Zhu Yib481de92007-09-25 17:54:57 -07002843 for (j = 0; j < LQ_SIZE; j++)
2844 for (i = 0; i < IWL_RATE_COUNT; i++)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002845 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
Zhu Yib481de92007-09-25 17:54:57 -07002846
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002847 IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n",
2848 sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07002849 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2850 * the lowest or the highest rate.. Could consider using RSSI from
2851 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2852 * after assoc.. */
2853
Tomas Winklerc33104f2008-01-14 17:46:21 -08002854 lq_sta->is_dup = 0;
Abbas, Mohamedc6ec7a92009-01-20 21:33:52 -08002855 lq_sta->max_rate_idx = -1;
Abbas, Mohamed7d049e52009-01-20 21:33:53 -08002856 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002857 lq_sta->is_green = rs_use_green(sta);
Guy Cohen39e88502008-04-23 17:14:57 -07002858 lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
Johannes Berg8318d782008-01-24 19:38:38 +01002859 lq_sta->band = priv->band;
Ben Cahill77626352007-11-29 11:09:44 +08002860 /*
2861 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2862 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2863 */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002864 lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
2865 lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002866 lq_sta->active_siso_rate &= ~((u16)0x2);
2867 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07002868
Ben Cahill77626352007-11-29 11:09:44 +08002869 /* Same here */
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002870 lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
2871 lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002872 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2873 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2874
Daniel C Halperin7869b0e2009-08-13 13:30:52 -07002875 lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
2876 lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
Guy Cohenfde0db32008-04-21 15:42:01 -07002877 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2878 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2879
Tomas Winklere1623442009-01-27 14:27:56 -08002880 IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002881 lq_sta->active_siso_rate,
Guy Cohenfde0db32008-04-21 15:42:01 -07002882 lq_sta->active_mimo2_rate,
2883 lq_sta->active_mimo3_rate);
2884
Tomas Winklera96a27f2008-10-23 23:48:56 -07002885 /* These values will be overridden later */
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002886 lq_sta->lq.general_params.single_stream_ant_msk =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002887 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002888 lq_sta->lq.general_params.dual_stream_ant_msk =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002889 hw_params(priv).valid_tx_ant &
2890 ~first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002891 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2892 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002893 } else if (num_of_ant(hw_params(priv).valid_tx_ant) == 2) {
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002894 lq_sta->lq.general_params.dual_stream_ant_msk =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002895 hw_params(priv).valid_tx_ant;
Wey-Yi Guy3a23d692010-04-03 16:44:39 -07002896 }
Guy Cohen07bc28e2008-04-23 17:15:03 -07002897
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02002898 /* as default allow aggregation for all tids */
2899 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002900 lq_sta->drv = priv;
Zhu Yib481de92007-09-25 17:54:57 -07002901
Daniel C Halperin50273092009-08-28 09:44:45 -07002902 /* Set last_txrate_idx to lowest rate */
2903 lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
2904 if (sband->band == IEEE80211_BAND_5GHZ)
2905 lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
Daniel C Halperine3949d62009-09-17 10:43:50 -07002906 lq_sta->is_agg = 0;
Wey-Yi Guy5ef15cc2011-11-30 13:24:06 -08002907#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
Wey-Yi Guy4e308112011-07-08 08:46:28 -07002908 priv->tm_fixed_rate = 0;
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -07002909#endif
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002910#ifdef CONFIG_MAC80211_DEBUGFS
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002911 lq_sta->dbg_fixed_rate = 0;
Sedat Dilek7d5f01a2010-12-16 12:46:23 +01002912#endif
Shanyu Zhaoa1da0772010-12-02 11:02:54 -08002913
Johannes Berg9b6ca442012-03-07 09:52:11 -08002914 rs_initialize_lq(priv, sta, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002915}
2916
Wey-Yi Guy46f93812009-07-24 11:13:03 -07002917static void rs_fill_link_cmd(struct iwl_priv *priv,
Tomas Winklere227cea2008-07-18 13:53:05 +08002918 struct iwl_lq_sta *lq_sta, u32 new_rate)
Zhu Yib481de92007-09-25 17:54:57 -07002919{
Tomas Winklere227cea2008-07-18 13:53:05 +08002920 struct iwl_scale_tbl_info tbl_type;
Zhu Yib481de92007-09-25 17:54:57 -07002921 int index = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002922 int rate_idx;
Zhu Yi1b696de2007-09-27 11:27:41 +08002923 int repeat_rate = 0;
Guy Cohenaade00c2008-04-23 17:14:59 -07002924 u8 ant_toggle_cnt = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002925 u8 use_ht_possible = 1;
Guy Cohenaade00c2008-04-23 17:14:59 -07002926 u8 valid_tx_ant = 0;
Johannes Berg7b090682011-01-19 02:53:54 -08002927 struct iwl_station_priv *sta_priv =
2928 container_of(lq_sta, struct iwl_station_priv, lq_sta);
Guy Cohen07bc28e2008-04-23 17:15:03 -07002929 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
Zhu Yib481de92007-09-25 17:54:57 -07002930
Ben Cahill77626352007-11-29 11:09:44 +08002931 /* Override starting rate (index 0) if needed for debug purposes */
Guy Cohen39e88502008-04-23 17:14:57 -07002932 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Zhu Yi98d7e092007-09-27 11:27:42 +08002933
Guy Cohen39e88502008-04-23 17:14:57 -07002934 /* Interpret new_rate (rate_n_flags) */
2935 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
Zhu Yib481de92007-09-25 17:54:57 -07002936 &tbl_type, &rate_idx);
2937
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002938 if (priv && priv->bt_full_concurrent) {
2939 /* 1x1 only */
2940 tbl_type.ant_type =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002941 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002942 }
2943
Ben Cahill77626352007-11-29 11:09:44 +08002944 /* How many times should we repeat the initial rate? */
Zhu Yib481de92007-09-25 17:54:57 -07002945 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002946 ant_toggle_cnt = 1;
Zhu Yi1b696de2007-09-27 11:27:41 +08002947 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07002948 } else {
Daniel Halperin374920c2011-03-16 19:16:36 -07002949 repeat_rate = min(IWL_HT_NUMBER_TRY,
2950 LINK_QUAL_AGG_DISABLE_START_DEF - 1);
Guy Cohenaade00c2008-04-23 17:14:59 -07002951 }
Zhu Yib481de92007-09-25 17:54:57 -07002952
2953 lq_cmd->general_params.mimo_delimiter =
2954 is_mimo(tbl_type.lq_type) ? 1 : 0;
Ben Cahill77626352007-11-29 11:09:44 +08002955
2956 /* Fill 1st table entry (index 0) */
Guy Cohen39e88502008-04-23 17:14:57 -07002957 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002958
Guy Cohen07bc28e2008-04-23 17:15:03 -07002959 if (num_of_ant(tbl_type.ant_type) == 1) {
2960 lq_cmd->general_params.single_stream_ant_msk =
2961 tbl_type.ant_type;
2962 } else if (num_of_ant(tbl_type.ant_type) == 2) {
2963 lq_cmd->general_params.dual_stream_ant_msk =
2964 tbl_type.ant_type;
2965 } /* otherwise we don't modify the existing value */
Zhu Yib481de92007-09-25 17:54:57 -07002966
2967 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08002968 repeat_rate--;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002969 if (priv) {
2970 if (priv->bt_full_concurrent)
2971 valid_tx_ant = ANT_A;
2972 else
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07002973 valid_tx_ant = hw_params(priv).valid_tx_ant;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002974 }
Guy Cohenaade00c2008-04-23 17:14:59 -07002975
Ben Cahill77626352007-11-29 11:09:44 +08002976 /* Fill rest of rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002977 while (index < LINK_QUAL_MAX_RETRY_NUM) {
Ben Cahill77626352007-11-29 11:09:44 +08002978 /* Repeat initial/next rate.
2979 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2980 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
Zhu Yi1b696de2007-09-27 11:27:41 +08002981 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
Zhu Yib481de92007-09-25 17:54:57 -07002982 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07002983 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2984 ant_toggle_cnt++;
2985 else if (priv &&
2986 rs_toggle_antenna(valid_tx_ant,
2987 &new_rate, &tbl_type))
2988 ant_toggle_cnt = 1;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002989 }
Zhu Yi98d7e092007-09-27 11:27:42 +08002990
Ben Cahill77626352007-11-29 11:09:44 +08002991 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002992 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08002993
2994 /* Fill next table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002995 lq_cmd->rs_table[index].rate_n_flags =
Guy Cohen39e88502008-04-23 17:14:57 -07002996 cpu_to_le32(new_rate);
Zhu Yi1b696de2007-09-27 11:27:41 +08002997 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07002998 index++;
2999 }
3000
Guy Cohen39e88502008-04-23 17:14:57 -07003001 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
Zhu Yib481de92007-09-25 17:54:57 -07003002 &rate_idx);
3003
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003004 if (priv && priv->bt_full_concurrent) {
3005 /* 1x1 only */
3006 tbl_type.ant_type =
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07003007 first_antenna(hw_params(priv).valid_tx_ant);
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003008 }
3009
Ben Cahill77626352007-11-29 11:09:44 +08003010 /* Indicate to uCode which entries might be MIMO.
3011 * If initial rate was MIMO, this will finally end up
3012 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
Zhu Yib481de92007-09-25 17:54:57 -07003013 if (is_mimo(tbl_type.lq_type))
3014 lq_cmd->general_params.mimo_delimiter = index;
3015
Ben Cahill77626352007-11-29 11:09:44 +08003016 /* Get next rate */
Guy Cohen39e88502008-04-23 17:14:57 -07003017 new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
3018 use_ht_possible);
Zhu Yib481de92007-09-25 17:54:57 -07003019
Ben Cahill77626352007-11-29 11:09:44 +08003020 /* How many times should we repeat the next rate? */
Zhu Yib481de92007-09-25 17:54:57 -07003021 if (is_legacy(tbl_type.lq_type)) {
Guy Cohenaade00c2008-04-23 17:14:59 -07003022 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
3023 ant_toggle_cnt++;
3024 else if (priv &&
3025 rs_toggle_antenna(valid_tx_ant,
3026 &new_rate, &tbl_type))
3027 ant_toggle_cnt = 1;
3028
Zhu Yi1b696de2007-09-27 11:27:41 +08003029 repeat_rate = IWL_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003030 } else {
Zhu Yi1b696de2007-09-27 11:27:41 +08003031 repeat_rate = IWL_HT_NUMBER_TRY;
Guy Cohenaade00c2008-04-23 17:14:59 -07003032 }
Zhu Yib481de92007-09-25 17:54:57 -07003033
Ben Cahill77626352007-11-29 11:09:44 +08003034 /* Don't allow HT rates after next pass.
3035 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
Zhu Yib481de92007-09-25 17:54:57 -07003036 use_ht_possible = 0;
3037
Ben Cahill77626352007-11-29 11:09:44 +08003038 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08003039 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08003040
3041 /* Fill next table entry */
Guy Cohen39e88502008-04-23 17:14:57 -07003042 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07003043
3044 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08003045 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07003046 }
3047
Johannes Berg7b090682011-01-19 02:53:54 -08003048 lq_cmd->agg_params.agg_frame_cnt_limit =
3049 sta_priv->max_agg_bufsize ?: LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003050 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
Wey-Yi Guy74697012010-07-28 09:18:54 -07003051
Wey-Yi Guy13c33a02009-06-03 11:44:11 -07003052 lq_cmd->agg_params.agg_time_limit =
3053 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
Wey-Yi Guy74697012010-07-28 09:18:54 -07003054 /*
3055 * overwrite if needed, pass aggregation time limit
3056 * to uCode in uSec
3057 */
Don Fry38622412011-12-16 07:07:36 -08003058 if (priv && cfg(priv)->bt_params &&
3059 cfg(priv)->bt_params->agg_time_limit &&
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08003060 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
Wey-Yi Guy74697012010-07-28 09:18:54 -07003061 lq_cmd->agg_params.agg_time_limit =
Don Fry38622412011-12-16 07:07:36 -08003062 cpu_to_le16(cfg(priv)->bt_params->agg_time_limit);
Zhu Yib481de92007-09-25 17:54:57 -07003063}
3064
Johannes Berg4b7679a2008-09-18 18:14:18 +02003065static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Zhu Yib481de92007-09-25 17:54:57 -07003066{
Johannes Berg4b7679a2008-09-18 18:14:18 +02003067 return hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003068}
3069/* rate scale requires free function to be implemented */
3070static void rs_free(void *priv_rate)
3071{
3072 return;
3073}
3074
Johannes Berg4b7679a2008-09-18 18:14:18 +02003075static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
3076 void *priv_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003077{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02003078 struct iwl_op_mode *op_mode __maybe_unused = priv_r;
3079 struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003080
Tomas Winklere1623442009-01-27 14:27:56 -08003081 IWL_DEBUG_RATE(priv, "enter\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003082 IWL_DEBUG_RATE(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003083}
3084
Zhu Yi93dc6462007-09-27 11:27:37 +08003085#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklere227cea2008-07-18 13:53:05 +08003086static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
3087 u32 *rate_n_flags, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +08003088{
Ester Kummerbf403db2008-05-05 10:22:40 +08003089 struct iwl_priv *priv;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003090 u8 valid_tx_ant;
3091 u8 ant_sel_tx;
Ester Kummerbf403db2008-05-05 10:22:40 +08003092
3093 priv = lq_sta->drv;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07003094 valid_tx_ant = hw_params(priv).valid_tx_ant;
Guy Cohen39e88502008-04-23 17:14:57 -07003095 if (lq_sta->dbg_fixed_rate) {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003096 ant_sel_tx =
3097 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
3098 >> RATE_MCS_ANT_POS);
3099 if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
Guy Cohen39e88502008-04-23 17:14:57 -07003100 *rate_n_flags = lq_sta->dbg_fixed_rate;
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003101 IWL_DEBUG_RATE(priv, "Fixed rate ON\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003102 } else {
Wey-Yi Guy3c4955f2009-03-10 14:35:12 -07003103 lq_sta->dbg_fixed_rate = 0;
3104 IWL_ERR(priv,
3105 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
3106 ant_sel_tx, valid_tx_ant);
3107 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Guy Cohen39e88502008-04-23 17:14:57 -07003108 }
Guy Cohen39e88502008-04-23 17:14:57 -07003109 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08003110 IWL_DEBUG_RATE(priv, "Fixed rate OFF\n");
Zhu Yi98d7e092007-09-27 11:27:42 +08003111 }
Zhu Yi98d7e092007-09-27 11:27:42 +08003112}
3113
3114static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
3115 const char __user *user_buf, size_t count, loff_t *ppos)
3116{
Tomas Winklere227cea2008-07-18 13:53:05 +08003117 struct iwl_lq_sta *lq_sta = file->private_data;
Ester Kummerbf403db2008-05-05 10:22:40 +08003118 struct iwl_priv *priv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003119 char buf[64];
Stephen Boyd805d7d22011-05-12 16:50:05 -07003120 size_t buf_size;
Zhu Yi98d7e092007-09-27 11:27:42 +08003121 u32 parsed_rate;
Wey-Yi Guy64898542011-05-03 18:05:13 -07003122
Zhu Yi98d7e092007-09-27 11:27:42 +08003123
Ester Kummerbf403db2008-05-05 10:22:40 +08003124 priv = lq_sta->drv;
Zhu Yi98d7e092007-09-27 11:27:42 +08003125 memset(buf, 0, sizeof(buf));
3126 buf_size = min(count, sizeof(buf) - 1);
3127 if (copy_from_user(buf, user_buf, buf_size))
3128 return -EFAULT;
3129
3130 if (sscanf(buf, "%x", &parsed_rate) == 1)
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003131 lq_sta->dbg_fixed_rate = parsed_rate;
Zhu Yi98d7e092007-09-27 11:27:42 +08003132 else
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003133 lq_sta->dbg_fixed_rate = 0;
Zhu Yi98d7e092007-09-27 11:27:42 +08003134
Wey-Yi Guy64898542011-05-03 18:05:13 -07003135 rs_program_fix_rate(priv, lq_sta);
Zhu Yi98d7e092007-09-27 11:27:42 +08003136
3137 return count;
3138}
Zhu Yi0209dc12007-09-27 11:27:43 +08003139
Zhu Yi5ae212c2007-09-27 11:27:38 +08003140static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
3141 char __user *user_buf, size_t count, loff_t *ppos)
3142{
Frank Seidela412c802009-03-01 20:25:38 +01003143 char *buff;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003144 int desc = 0;
3145 int i = 0;
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003146 int index = 0;
Frank Seidela412c802009-03-01 20:25:38 +01003147 ssize_t ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003148
Tomas Winklere227cea2008-07-18 13:53:05 +08003149 struct iwl_lq_sta *lq_sta = file->private_data;
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003150 struct iwl_priv *priv;
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003151 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003152
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003153 priv = lq_sta->drv;
Frank Seidela412c802009-03-01 20:25:38 +01003154 buff = kmalloc(1024, GFP_KERNEL);
3155 if (!buff)
3156 return -ENOMEM;
3157
Tomas Winklerc33104f2008-01-14 17:46:21 -08003158 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
Zhu Yi98d7e092007-09-27 11:27:42 +08003159 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003160 lq_sta->total_failed, lq_sta->total_success,
Guy Cohen39e88502008-04-23 17:14:57 -07003161 lq_sta->active_legacy_rate);
Zhu Yi98d7e092007-09-27 11:27:42 +08003162 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
Wey-Yi Guy4e308112011-07-08 08:46:28 -07003163 lq_sta->dbg_fixed_rate);
Wey-Yi Guyd8ae4f52009-03-10 14:35:07 -07003164 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07003165 (hw_params(priv).valid_tx_ant & ANT_A) ? "ANT_A," : "",
3166 (hw_params(priv).valid_tx_ant & ANT_B) ? "ANT_B," : "",
3167 (hw_params(priv).valid_tx_ant & ANT_C) ? "ANT_C" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003168 desc += sprintf(buff+desc, "lq type %s\n",
3169 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
3170 if (is_Ht(tbl->lq_type)) {
3171 desc += sprintf(buff+desc, " %s",
3172 (is_siso(tbl->lq_type)) ? "SISO" :
3173 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
3174 desc += sprintf(buff+desc, " %s",
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003175 (tbl->is_ht40) ? "40MHz" : "20MHz");
Daniel C Halperine3949d62009-09-17 10:43:50 -07003176 desc += sprintf(buff+desc, " %s %s %s\n", (tbl->is_SGI) ? "SGI" : "",
3177 (lq_sta->is_green) ? "GF enabled" : "",
3178 (lq_sta->is_agg) ? "AGG on" : "");
Wey-Yi Guyadb7b5e2009-03-10 14:35:08 -07003179 }
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003180 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
3181 lq_sta->last_rate_n_flags);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003182 desc += sprintf(buff+desc, "general:"
3183 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003184 lq_sta->lq.general_params.flags,
3185 lq_sta->lq.general_params.mimo_delimiter,
3186 lq_sta->lq.general_params.single_stream_ant_msk,
3187 lq_sta->lq.general_params.dual_stream_ant_msk);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003188
3189 desc += sprintf(buff+desc, "agg:"
3190 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003191 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
3192 lq_sta->lq.agg_params.agg_dis_start_th,
3193 lq_sta->lq.agg_params.agg_frame_cnt_limit);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003194
3195 desc += sprintf(buff+desc,
3196 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003197 lq_sta->lq.general_params.start_rate_index[0],
3198 lq_sta->lq.general_params.start_rate_index[1],
3199 lq_sta->lq.general_params.start_rate_index[2],
3200 lq_sta->lq.general_params.start_rate_index[3]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08003201
Wey-Yi Guy12b96812009-04-08 11:39:27 -07003202 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
3203 index = iwl_hwrate_to_plcp_idx(
3204 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
3205 if (is_legacy(tbl->lq_type)) {
3206 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
3207 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3208 iwl_rate_mcs[index].mbps);
3209 } else {
3210 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
3211 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
3212 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
3213 }
3214 }
Zhu Yi5ae212c2007-09-27 11:27:38 +08003215
Frank Seidela412c802009-03-01 20:25:38 +01003216 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3217 kfree(buff);
3218 return ret;
Zhu Yi5ae212c2007-09-27 11:27:38 +08003219}
3220
3221static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
Zhu Yi98d7e092007-09-27 11:27:42 +08003222 .write = rs_sta_dbgfs_scale_table_write,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003223 .read = rs_sta_dbgfs_scale_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003224 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003225 .llseek = default_llseek,
Zhu Yi5ae212c2007-09-27 11:27:38 +08003226};
Zhu Yi0209dc12007-09-27 11:27:43 +08003227static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
3228 char __user *user_buf, size_t count, loff_t *ppos)
3229{
Frank Seidela412c802009-03-01 20:25:38 +01003230 char *buff;
Zhu Yi0209dc12007-09-27 11:27:43 +08003231 int desc = 0;
3232 int i, j;
Frank Seidela412c802009-03-01 20:25:38 +01003233 ssize_t ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003234
Tomas Winklere227cea2008-07-18 13:53:05 +08003235 struct iwl_lq_sta *lq_sta = file->private_data;
Frank Seidela412c802009-03-01 20:25:38 +01003236
3237 buff = kmalloc(1024, GFP_KERNEL);
3238 if (!buff)
3239 return -ENOMEM;
3240
Zhu Yi0209dc12007-09-27 11:27:43 +08003241 for (i = 0; i < LQ_SIZE; i++) {
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003242 desc += sprintf(buff+desc,
3243 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
Zhu Yi0209dc12007-09-27 11:27:43 +08003244 "rate=0x%X\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003245 lq_sta->active_tbl == i ? "*" : "x",
Tomas Winklerc33104f2008-01-14 17:46:21 -08003246 lq_sta->lq_info[i].lq_type,
3247 lq_sta->lq_info[i].is_SGI,
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07003248 lq_sta->lq_info[i].is_ht40,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003249 lq_sta->lq_info[i].is_dup,
Wey-Yi Guy2681b202009-05-21 13:44:22 -07003250 lq_sta->is_green,
Guy Cohen39e88502008-04-23 17:14:57 -07003251 lq_sta->lq_info[i].current_rate);
Zhu Yi0209dc12007-09-27 11:27:43 +08003252 for (j = 0; j < IWL_RATE_COUNT; j++) {
3253 desc += sprintf(buff+desc,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003254 "counter=%d success=%d %%=%d\n",
3255 lq_sta->lq_info[i].win[j].counter,
3256 lq_sta->lq_info[i].win[j].success_counter,
3257 lq_sta->lq_info[i].win[j].success_ratio);
Zhu Yi0209dc12007-09-27 11:27:43 +08003258 }
3259 }
Frank Seidela412c802009-03-01 20:25:38 +01003260 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3261 kfree(buff);
3262 return ret;
Zhu Yi0209dc12007-09-27 11:27:43 +08003263}
3264
3265static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
3266 .read = rs_sta_dbgfs_stats_table_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003267 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003268 .llseek = default_llseek,
Zhu Yi0209dc12007-09-27 11:27:43 +08003269};
Zhu Yi5ae212c2007-09-27 11:27:38 +08003270
Wey-Yi Guy38167452009-05-08 13:44:43 -07003271static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3272 char __user *user_buf, size_t count, loff_t *ppos)
3273{
Johannes Berg70817b52011-05-11 03:29:25 -07003274 struct iwl_lq_sta *lq_sta = file->private_data;
3275 struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
Wey-Yi Guy38167452009-05-08 13:44:43 -07003276 char buff[120];
3277 int desc = 0;
Wey-Yi Guy38167452009-05-08 13:44:43 -07003278
Wey-Yi Guy38167452009-05-08 13:44:43 -07003279 if (is_Ht(tbl->lq_type))
3280 desc += sprintf(buff+desc,
3281 "Bit Rate= %d Mb/s\n",
3282 tbl->expected_tpt[lq_sta->last_txrate_idx]);
3283 else
3284 desc += sprintf(buff+desc,
3285 "Bit Rate= %d Mb/s\n",
3286 iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003287
Johannes Berg08960de2011-04-05 09:41:53 -07003288 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003289}
3290
3291static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3292 .read = rs_sta_dbgfs_rate_scale_data_read,
Stephen Boyd234e3402012-04-05 14:25:11 -07003293 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02003294 .llseek = default_llseek,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003295};
3296
Zhu Yi93dc6462007-09-27 11:27:37 +08003297static void rs_add_debugfs(void *priv, void *priv_sta,
3298 struct dentry *dir)
3299{
Tomas Winklere227cea2008-07-18 13:53:05 +08003300 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003301 lq_sta->rs_sta_dbgfs_scale_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003302 debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003303 lq_sta, &rs_sta_dbgfs_scale_table_ops);
3304 lq_sta->rs_sta_dbgfs_stats_table_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003305 debugfs_create_file("rate_stats_table", S_IRUSR, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08003306 lq_sta, &rs_sta_dbgfs_stats_table_ops);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003307 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003308 debugfs_create_file("rate_scale_data", S_IRUSR, dir,
Wey-Yi Guy38167452009-05-08 13:44:43 -07003309 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003310 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
Wey-Yi Guy43e85112009-11-20 12:04:58 -08003311 debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003312 &lq_sta->tx_agg_tid_en);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003313
Zhu Yi93dc6462007-09-27 11:27:37 +08003314}
3315
3316static void rs_remove_debugfs(void *priv, void *priv_sta)
3317{
Tomas Winklere227cea2008-07-18 13:53:05 +08003318 struct iwl_lq_sta *lq_sta = priv_sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08003319 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
3320 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
Wey-Yi Guy38167452009-05-08 13:44:43 -07003321 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
Ron Rindjunsky0c11b4d2008-01-28 14:07:26 +02003322 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
Zhu Yi93dc6462007-09-27 11:27:37 +08003323}
3324#endif
3325
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003326/*
3327 * Initialization of rate scaling information is done by driver after
3328 * the station is added. Since mac80211 calls this function before a
3329 * station is added we ignore it.
3330 */
3331static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband,
3332 struct ieee80211_sta *sta, void *priv_sta)
3333{
3334}
Zhu Yib481de92007-09-25 17:54:57 -07003335static struct rate_control_ops rs_ops = {
3336 .module = NULL,
3337 .name = RS_NAME,
3338 .tx_status = rs_tx_status,
3339 .get_rate = rs_get_rate,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003340 .rate_init = rs_rate_init_stub,
Zhu Yib481de92007-09-25 17:54:57 -07003341 .alloc = rs_alloc,
3342 .free = rs_free,
3343 .alloc_sta = rs_alloc_sta,
3344 .free_sta = rs_free_sta,
Zhu Yi93dc6462007-09-27 11:27:37 +08003345#ifdef CONFIG_MAC80211_DEBUGFS
3346 .add_sta_debugfs = rs_add_debugfs,
3347 .remove_sta_debugfs = rs_remove_debugfs,
3348#endif
Zhu Yib481de92007-09-25 17:54:57 -07003349};
3350
Tomas Winklere227cea2008-07-18 13:53:05 +08003351int iwlagn_rate_control_register(void)
Zhu Yib481de92007-09-25 17:54:57 -07003352{
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003353 return ieee80211_rate_control_register(&rs_ops);
Zhu Yib481de92007-09-25 17:54:57 -07003354}
3355
Tomas Winklere227cea2008-07-18 13:53:05 +08003356void iwlagn_rate_control_unregister(void)
Zhu Yib481de92007-09-25 17:54:57 -07003357{
3358 ieee80211_rate_control_unregister(&rs_ops);
3359}
3360