blob: f4f2497646bd046b82b9380ac32ab399e95f9a07 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
3 * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/skbuff.h>
29#include <linux/wireless.h>
30#include <net/mac80211.h>
31#include <net/ieee80211.h>
32
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/delay.h>
36
37#include <linux/workqueue.h>
38
Zhu Yib481de92007-09-25 17:54:57 -070039#include "../net/mac80211/ieee80211_rate.h"
40
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080041#include "iwl-4965.h"
Zhu Yib481de92007-09-25 17:54:57 -070042#include "iwl-helpers.h"
43
44#define RS_NAME "iwl-4965-rs"
45
46#define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
47#define IWL_NUMBER_TRY 1
48#define IWL_HT_NUMBER_TRY 3
49
Ben Cahill77626352007-11-29 11:09:44 +080050#define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
51#define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
52#define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
53
54/* max time to accum history 2 seconds */
55#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ)
Zhu Yib481de92007-09-25 17:54:57 -070056
57static u8 rs_ht_to_legacy[] = {
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
59 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
60 IWL_RATE_6M_INDEX,
61 IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
62 IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
63 IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
64 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
65};
66
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080067struct iwl4965_rate {
Zhu Yib481de92007-09-25 17:54:57 -070068 u32 rate_n_flags;
69} __attribute__ ((packed));
70
Ben Cahill77626352007-11-29 11:09:44 +080071/**
72 * struct iwl4965_rate_scale_data -- tx success history for one rate
73 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080074struct iwl4965_rate_scale_data {
Ben Cahill77626352007-11-29 11:09:44 +080075 u64 data; /* bitmap of successful frames */
76 s32 success_counter; /* number of frames successful */
77 s32 success_ratio; /* per-cent * 128 */
78 s32 counter; /* number of frames attempted */
79 s32 average_tpt; /* success ratio * expected throughput */
Zhu Yib481de92007-09-25 17:54:57 -070080 unsigned long stamp;
81};
82
Ben Cahill77626352007-11-29 11:09:44 +080083/**
84 * struct iwl4965_scale_tbl_info -- tx params and success history for all rates
85 *
86 * There are two of these in struct iwl_rate_scale_priv,
87 * one for "active", and one for "search".
88 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080089struct iwl4965_scale_tbl_info {
90 enum iwl4965_table_type lq_type;
91 enum iwl4965_antenna_type antenna_type;
Ben Cahill77626352007-11-29 11:09:44 +080092 u8 is_SGI; /* 1 = short guard interval */
93 u8 is_fat; /* 1 = 40 MHz channel width */
94 u8 is_dup; /* 1 = duplicated data streams */
95 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
96 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
97 struct iwl4965_rate current_rate; /* rate_n_flags, uCode API format */
98 struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
Zhu Yib481de92007-09-25 17:54:57 -070099};
100
Ben Cahill77626352007-11-29 11:09:44 +0800101/**
102 * struct iwl_rate_scale_priv -- driver's rate scaling private structure
103 *
104 * Pointer to this gets passed back and forth between driver and mac80211.
105 */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800106struct iwl4965_lq_sta {
Ben Cahill77626352007-11-29 11:09:44 +0800107 u8 active_tbl; /* index of active table, range 0-1 */
108 u8 enable_counter; /* indicates HT mode */
109 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
110 u8 search_better_tbl; /* 1: currently trying alternate mode */
Zhu Yib481de92007-09-25 17:54:57 -0700111 s32 last_tpt;
Ben Cahill77626352007-11-29 11:09:44 +0800112
113 /* The following determine when to search for a new mode */
Zhu Yib481de92007-09-25 17:54:57 -0700114 u32 table_count_limit;
Ben Cahill77626352007-11-29 11:09:44 +0800115 u32 max_failure_limit; /* # failed frames before new search */
116 u32 max_success_limit; /* # successful frames before new search */
Zhu Yib481de92007-09-25 17:54:57 -0700117 u32 table_count;
Ben Cahill77626352007-11-29 11:09:44 +0800118 u32 total_failed; /* total failed frames, any/all rates */
119 u32 total_success; /* total successful frames, any/all rates */
120 u32 flush_timer; /* time staying in mode before new search */
121
122 u8 action_counter; /* # mode-switch actions tried */
Zhu Yib481de92007-09-25 17:54:57 -0700123 u8 antenna;
124 u8 valid_antenna;
125 u8 is_green;
126 u8 is_dup;
127 u8 phymode;
128 u8 ibss_sta_added;
Ben Cahill77626352007-11-29 11:09:44 +0800129
130 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
Zhu Yi02dede02007-09-27 11:27:40 +0800131 u32 supp_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700132 u16 active_rate;
133 u16 active_siso_rate;
134 u16 active_mimo_rate;
135 u16 active_rate_basic;
Ben Cahill77626352007-11-29 11:09:44 +0800136
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800137 struct iwl4965_link_quality_cmd lq;
Ben Cahill77626352007-11-29 11:09:44 +0800138 struct iwl4965_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
Zhu Yi5ae212c2007-09-27 11:27:38 +0800139#ifdef CONFIG_MAC80211_DEBUGFS
Zhu Yi98d7e092007-09-27 11:27:42 +0800140 struct dentry *rs_sta_dbgfs_scale_table_file;
Zhu Yi0209dc12007-09-27 11:27:43 +0800141 struct dentry *rs_sta_dbgfs_stats_table_file;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800142 struct iwl4965_rate dbg_fixed;
143 struct iwl4965_priv *drv;
Zhu Yi5ae212c2007-09-27 11:27:38 +0800144#endif
Zhu Yib481de92007-09-25 17:54:57 -0700145};
146
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800147static void rs_rate_scale_perform(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700148 struct net_device *dev,
149 struct ieee80211_hdr *hdr,
150 struct sta_info *sta);
Tomas Winklerc33104f2008-01-14 17:46:21 -0800151static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800152 struct iwl4965_rate *tx_mcs,
153 struct iwl4965_link_quality_cmd *tbl);
Zhu Yib481de92007-09-25 17:54:57 -0700154
155
Zhu Yi98d7e092007-09-27 11:27:42 +0800156#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklerc33104f2008-01-14 17:46:21 -0800157static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800158 struct iwl4965_rate *mcs, int index);
Zhu Yi98d7e092007-09-27 11:27:42 +0800159#else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800160static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800161 struct iwl4965_rate *mcs, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +0800162{}
163#endif
Ben Cahill77626352007-11-29 11:09:44 +0800164
165/*
166 * Expected throughput metrics for following rates:
167 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
168 * "G" is the only table that supports CCK (the first 4 rates).
169 */
Zhu Yib481de92007-09-25 17:54:57 -0700170static s32 expected_tpt_A[IWL_RATE_COUNT] = {
171 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
172};
173
174static s32 expected_tpt_G[IWL_RATE_COUNT] = {
175 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
176};
177
178static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = {
179 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
180};
181
182static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
183 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
184};
185
186static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = {
187 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
188};
189
190static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = {
191 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
192};
193
194static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = {
195 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
196};
197
198static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
199 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
200};
201
202static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = {
203 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
204};
205
206static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
207 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
208};
209
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800210static int iwl4965_lq_sync_callback(struct iwl4965_priv *priv,
211 struct iwl4965_cmd *cmd, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700212{
213 /*We didn't cache the SKB; let the caller free it */
214 return 1;
215}
216
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800217static inline u8 iwl4965_rate_get_rate(u32 rate_n_flags)
Zhu Yib481de92007-09-25 17:54:57 -0700218{
219 return (u8)(rate_n_flags & 0xFF);
220}
221
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800222static int rs_send_lq_cmd(struct iwl4965_priv *priv,
223 struct iwl4965_link_quality_cmd *lq, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700224{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800225#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700226 int i;
227#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800228 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700229 .id = REPLY_TX_LINK_QUALITY_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800230 .len = sizeof(struct iwl4965_link_quality_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700231 .meta.flags = flags,
232 .data = lq,
233 };
234
235 if ((lq->sta_id == 0xFF) &&
236 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800237 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700238
239 if (lq->sta_id == 0xFF)
240 lq->sta_id = IWL_AP_ID;
241
242 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
243 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
244 lq->general_params.single_stream_ant_msk,
245 lq->general_params.dual_stream_ant_msk);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800246#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700247 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
248 IWL_DEBUG_RATE("lq index %d 0x%X\n",
249 i, lq->rs_table[i].rate_n_flags);
250#endif
251
252 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800253 cmd.meta.u.callback = iwl4965_lq_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -0700254
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800255 if (iwl4965_is_associated(priv) && priv->assoc_station_added &&
Zhu Yib481de92007-09-25 17:54:57 -0700256 priv->lq_mngr.lq_ready)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800257 return iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700258
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800259 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700260}
261
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800262static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window)
Zhu Yib481de92007-09-25 17:54:57 -0700263{
264 window->data = 0;
265 window->success_counter = 0;
266 window->success_ratio = IWL_INVALID_VALUE;
267 window->counter = 0;
268 window->average_tpt = IWL_INVALID_VALUE;
269 window->stamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700270}
271
Ben Cahill77626352007-11-29 11:09:44 +0800272/**
273 * rs_collect_tx_data - Update the success/failure sliding window
274 *
275 * We keep a sliding window of the last 62 packets transmitted
276 * at this rate. window->data contains the bitmask of successful
277 * packets.
278 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800279static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
Ron Rindjunsky99556432008-01-28 14:07:25 +0200280 int scale_index, s32 tpt, int retries,
281 int successes)
Zhu Yib481de92007-09-25 17:54:57 -0700282{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800283 struct iwl4965_rate_scale_data *window = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700284 u64 mask;
285 u8 win_size = IWL_RATE_MAX_WINDOW;
286 s32 fail_count;
287
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800288 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
289 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700290
Ben Cahill77626352007-11-29 11:09:44 +0800291 /* Select data for current tx bit rate */
Zhu Yib481de92007-09-25 17:54:57 -0700292 window = &(windows[scale_index]);
293
Ben Cahill77626352007-11-29 11:09:44 +0800294 /*
295 * Keep track of only the latest 62 tx frame attempts in this rate's
296 * history window; anything older isn't really relevant any more.
297 * If we have filled up the sliding window, drop the oldest attempt;
298 * if the oldest attempt (highest bit in bitmap) shows "success",
299 * subtract "1" from the success counter (this is the main reason
300 * we keep these bitmaps!).
301 */
Ron Rindjunsky99556432008-01-28 14:07:25 +0200302 while (retries > 0) {
303 if (window->counter >= win_size) {
304 window->counter = win_size - 1;
305 mask = 1;
306 mask = (mask << (win_size - 1));
307 if (window->data & mask) {
308 window->data &= ~mask;
309 window->success_counter =
310 window->success_counter - 1;
311 }
Zhu Yib481de92007-09-25 17:54:57 -0700312 }
Zhu Yib481de92007-09-25 17:54:57 -0700313
Ron Rindjunsky99556432008-01-28 14:07:25 +0200314 /* Increment frames-attempted counter */
315 window->counter++;
Ben Cahill77626352007-11-29 11:09:44 +0800316
Ron Rindjunsky99556432008-01-28 14:07:25 +0200317 /* Shift bitmap by one frame (throw away oldest history),
318 * OR in "1", and increment "success" if this
319 * frame was successful. */
320 mask = window->data;
321 window->data = (mask << 1);
322 if (successes > 0) {
323 window->success_counter = window->success_counter + 1;
324 window->data |= 0x1;
325 successes--;
326 }
327
328 retries--;
Zhu Yib481de92007-09-25 17:54:57 -0700329 }
330
Ben Cahill77626352007-11-29 11:09:44 +0800331 /* Calculate current success ratio, avoid divide-by-0! */
Zhu Yib481de92007-09-25 17:54:57 -0700332 if (window->counter > 0)
333 window->success_ratio = 128 * (100 * window->success_counter)
334 / window->counter;
335 else
336 window->success_ratio = IWL_INVALID_VALUE;
337
338 fail_count = window->counter - window->success_counter;
339
Ben Cahill77626352007-11-29 11:09:44 +0800340 /* Calculate average throughput, if we have enough history. */
Zhu Yib481de92007-09-25 17:54:57 -0700341 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
342 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
343 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
344 else
345 window->average_tpt = IWL_INVALID_VALUE;
346
Ben Cahill77626352007-11-29 11:09:44 +0800347 /* Tag this window as having been updated */
Zhu Yib481de92007-09-25 17:54:57 -0700348 window->stamp = jiffies;
349
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800350 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700351}
352
Ben Cahill77626352007-11-29 11:09:44 +0800353/*
354 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
355 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800356static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate,
357 struct iwl4965_scale_tbl_info *tbl,
Zhu Yib481de92007-09-25 17:54:57 -0700358 int index, u8 use_green)
359{
Zhu Yib481de92007-09-25 17:54:57 -0700360 if (is_legacy(tbl->lq_type)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800361 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700362 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
363 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
364
365 } else if (is_siso(tbl->lq_type)) {
366 if (index > IWL_LAST_OFDM_RATE)
367 index = IWL_LAST_OFDM_RATE;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800368 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_siso |
Zhu Yib481de92007-09-25 17:54:57 -0700369 RATE_MCS_HT_MSK;
370 } else {
371 if (index > IWL_LAST_OFDM_RATE)
372 index = IWL_LAST_OFDM_RATE;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800373 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_mimo |
Zhu Yib481de92007-09-25 17:54:57 -0700374 RATE_MCS_HT_MSK;
375 }
376
377 switch (tbl->antenna_type) {
378 case ANT_BOTH:
379 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
380 break;
381 case ANT_MAIN:
382 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
383 break;
384 case ANT_AUX:
385 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
386 break;
387 case ANT_NONE:
388 break;
389 }
390
391 if (is_legacy(tbl->lq_type))
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800392 return;
Zhu Yib481de92007-09-25 17:54:57 -0700393
394 if (tbl->is_fat) {
395 if (tbl->is_dup)
396 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
397 else
398 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
399 }
400 if (tbl->is_SGI)
401 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
402
403 if (use_green) {
404 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
405 if (is_siso(tbl->lq_type))
406 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
407 }
Zhu Yib481de92007-09-25 17:54:57 -0700408}
409
Ben Cahill77626352007-11-29 11:09:44 +0800410/*
411 * Interpret uCode API's rate_n_flags format,
412 * fill "search" or "active" tx mode table.
413 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800414static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate,
415 int phymode, struct iwl4965_scale_tbl_info *tbl,
Zhu Yib481de92007-09-25 17:54:57 -0700416 int *rate_idx)
417{
418 int index;
419 u32 ant_msk;
420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800421 index = iwl4965_rate_index_from_plcp(mcs_rate->rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700422
423 if (index == IWL_RATE_INVALID) {
424 *rate_idx = -1;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800425 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700426 }
Ben Cahill77626352007-11-29 11:09:44 +0800427 tbl->is_SGI = 0; /* default legacy setup */
Zhu Yib481de92007-09-25 17:54:57 -0700428 tbl->is_fat = 0;
429 tbl->is_dup = 0;
Ben Cahill77626352007-11-29 11:09:44 +0800430 tbl->antenna_type = ANT_BOTH; /* default MIMO setup */
Zhu Yib481de92007-09-25 17:54:57 -0700431
Ben Cahill77626352007-11-29 11:09:44 +0800432 /* legacy rate format */
Zhu Yib481de92007-09-25 17:54:57 -0700433 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
434 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
435
436 if (ant_msk == RATE_MCS_ANT_AB_MSK)
437 tbl->lq_type = LQ_NONE;
438 else {
439
440 if (phymode == MODE_IEEE80211A)
441 tbl->lq_type = LQ_A;
442 else
443 tbl->lq_type = LQ_G;
444
445 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
446 tbl->antenna_type = ANT_MAIN;
447 else
448 tbl->antenna_type = ANT_AUX;
449 }
450 *rate_idx = index;
451
Ben Cahill77626352007-11-29 11:09:44 +0800452 /* HT rate format, SISO (might be 20 MHz legacy or 40 MHz fat width) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800453 } else if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags)
Zhu Yib481de92007-09-25 17:54:57 -0700454 <= IWL_RATE_SISO_60M_PLCP) {
455 tbl->lq_type = LQ_SISO;
456
457 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
458 if (ant_msk == RATE_MCS_ANT_AB_MSK)
459 tbl->lq_type = LQ_NONE;
460 else {
461 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
462 tbl->antenna_type = ANT_MAIN;
463 else
464 tbl->antenna_type = ANT_AUX;
465 }
466 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
467 tbl->is_SGI = 1;
468
469 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
470 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
471 tbl->is_fat = 1;
472
473 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
474 tbl->is_dup = 1;
475
476 *rate_idx = index;
Ben Cahill77626352007-11-29 11:09:44 +0800477
478 /* HT rate format, MIMO (might be 20 MHz legacy or 40 MHz fat width) */
Zhu Yib481de92007-09-25 17:54:57 -0700479 } else {
480 tbl->lq_type = LQ_MIMO;
481 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
482 tbl->is_SGI = 1;
483
484 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
485 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
486 tbl->is_fat = 1;
487
488 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
489 tbl->is_dup = 1;
490 *rate_idx = index;
491 }
492 return 0;
493}
494
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800495static inline void rs_toggle_antenna(struct iwl4965_rate *new_rate,
496 struct iwl4965_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -0700497{
498 if (tbl->antenna_type == ANT_AUX) {
499 tbl->antenna_type = ANT_MAIN;
500 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK;
501 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
502 } else {
503 tbl->antenna_type = ANT_AUX;
504 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
505 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
506 }
507}
508
Ron Rindjunsky270243a2007-11-26 16:14:41 +0200509static inline u8 rs_use_green(struct iwl4965_priv *priv,
510 struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -0700511{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800512#ifdef CONFIG_IWL4965_HT
Ron Rindjunsky270243a2007-11-26 16:14:41 +0200513 return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
514 priv->current_ht_config.is_green_field &&
515 !priv->current_ht_config.non_GF_STA_present);
516#endif /* CONFIG_IWL4965_HT */
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800517 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700518}
519
520/**
521 * rs_get_supported_rates - get the available rates
522 *
523 * if management frame or broadcast frame only return
524 * basic available rates.
525 *
526 */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800527static void rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta,
Zhu Yib481de92007-09-25 17:54:57 -0700528 struct ieee80211_hdr *hdr,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800529 enum iwl4965_table_type rate_type,
Zhu Yib481de92007-09-25 17:54:57 -0700530 u16 *data_rate)
531{
532 if (is_legacy(rate_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -0800533 *data_rate = lq_sta->active_rate;
Zhu Yib481de92007-09-25 17:54:57 -0700534 else {
535 if (is_siso(rate_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -0800536 *data_rate = lq_sta->active_siso_rate;
Zhu Yib481de92007-09-25 17:54:57 -0700537 else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800538 *data_rate = lq_sta->active_mimo_rate;
Zhu Yib481de92007-09-25 17:54:57 -0700539 }
540
541 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
Tomas Winklerc33104f2008-01-14 17:46:21 -0800542 lq_sta->active_rate_basic) {
543 *data_rate = lq_sta->active_rate_basic;
544 }
Zhu Yib481de92007-09-25 17:54:57 -0700545}
546
547static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
548{
549 u8 high = IWL_RATE_INVALID;
550 u8 low = IWL_RATE_INVALID;
551
Ian Schram01ebd062007-10-25 17:15:22 +0800552 /* 802.11A or ht walks to the next literal adjacent rate in
Zhu Yib481de92007-09-25 17:54:57 -0700553 * the rate table */
554 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
555 int i;
556 u32 mask;
557
558 /* Find the previous rate that is in the rate mask */
559 i = index - 1;
560 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
561 if (rate_mask & mask) {
562 low = i;
563 break;
564 }
565 }
566
567 /* Find the next rate that is in the rate mask */
568 i = index + 1;
569 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
570 if (rate_mask & mask) {
571 high = i;
572 break;
573 }
574 }
575
576 return (high << 8) | low;
577 }
578
579 low = index;
580 while (low != IWL_RATE_INVALID) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800581 low = iwl4965_rates[low].prev_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700582 if (low == IWL_RATE_INVALID)
583 break;
584 if (rate_mask & (1 << low))
585 break;
586 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
587 }
588
589 high = index;
590 while (high != IWL_RATE_INVALID) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800591 high = iwl4965_rates[high].next_rs;
Zhu Yib481de92007-09-25 17:54:57 -0700592 if (high == IWL_RATE_INVALID)
593 break;
594 if (rate_mask & (1 << high))
595 break;
596 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
597 }
598
599 return (high << 8) | low;
600}
601
Tomas Winklerc33104f2008-01-14 17:46:21 -0800602static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800603 struct iwl4965_scale_tbl_info *tbl, u8 scale_index,
604 u8 ht_possible, struct iwl4965_rate *mcs_rate)
Zhu Yib481de92007-09-25 17:54:57 -0700605{
Zhu Yib481de92007-09-25 17:54:57 -0700606 s32 low;
607 u16 rate_mask;
608 u16 high_low;
609 u8 switch_to_legacy = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800610 u8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -0700611
612 /* check if we need to switch from HT to legacy rates.
613 * assumption is that mandatory rates (1Mbps or 6Mbps)
614 * are always supported (spec demand) */
615 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
616 switch_to_legacy = 1;
617 scale_index = rs_ht_to_legacy[scale_index];
Tomas Winklerc33104f2008-01-14 17:46:21 -0800618 if (lq_sta->phymode == MODE_IEEE80211A)
Zhu Yib481de92007-09-25 17:54:57 -0700619 tbl->lq_type = LQ_A;
620 else
621 tbl->lq_type = LQ_G;
622
623 if ((tbl->antenna_type == ANT_BOTH) ||
624 (tbl->antenna_type == ANT_NONE))
625 tbl->antenna_type = ANT_MAIN;
626
627 tbl->is_fat = 0;
628 tbl->is_SGI = 0;
629 }
630
Tomas Winklerc33104f2008-01-14 17:46:21 -0800631 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask);
Zhu Yib481de92007-09-25 17:54:57 -0700632
Ben Cahill77626352007-11-29 11:09:44 +0800633 /* Mask with station rate restriction */
Zhu Yib481de92007-09-25 17:54:57 -0700634 if (is_legacy(tbl->lq_type)) {
Ben Cahill77626352007-11-29 11:09:44 +0800635 /* supp_rates has no CCK bits in A mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800636 if (lq_sta->phymode == (u8) MODE_IEEE80211A)
Zhu Yib481de92007-09-25 17:54:57 -0700637 rate_mask = (u16)(rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -0800638 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -0700639 else
Tomas Winklerc33104f2008-01-14 17:46:21 -0800640 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -0700641 }
642
Ben Cahill77626352007-11-29 11:09:44 +0800643 /* If we switched from HT to legacy, check current rate */
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800644 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
Zhu Yib481de92007-09-25 17:54:57 -0700645 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800646 return;
Zhu Yib481de92007-09-25 17:54:57 -0700647 }
648
649 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
650 low = high_low & 0xff;
651
652 if (low != IWL_RATE_INVALID)
653 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
654 else
655 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
Zhu Yib481de92007-09-25 17:54:57 -0700656}
657
Ben Cahill77626352007-11-29 11:09:44 +0800658/*
659 * mac80211 sends us Tx status
660 */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800661static void rs_tx_status(void *priv_rate, struct net_device *dev,
Zhu Yib481de92007-09-25 17:54:57 -0700662 struct sk_buff *skb,
663 struct ieee80211_tx_status *tx_resp)
664{
665 int status;
666 u8 retries;
667 int rs_index, index = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -0800668 struct iwl4965_lq_sta *lq_sta;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800669 struct iwl4965_link_quality_cmd *table;
Zhu Yib481de92007-09-25 17:54:57 -0700670 struct sta_info *sta;
671 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800672 struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate;
Zhu Yib481de92007-09-25 17:54:57 -0700673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800674 struct iwl4965_rate_scale_data *window = NULL;
675 struct iwl4965_rate_scale_data *search_win = NULL;
676 struct iwl4965_rate tx_mcs;
677 struct iwl4965_scale_tbl_info tbl_type;
678 struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl;
Zhu Yib481de92007-09-25 17:54:57 -0700679 u8 active_index = 0;
680 u16 fc = le16_to_cpu(hdr->frame_control);
681 s32 tpt = 0;
682
Zhu Yi58826352007-09-27 11:27:39 +0800683 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
Zhu Yib481de92007-09-25 17:54:57 -0700684
685 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
686 return;
687
Ron Rindjunsky99556432008-01-28 14:07:25 +0200688 /* This packet was aggregated but doesn't carry rate scale info */
689 if ((tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) &&
690 !(tx_resp->flags & IEEE80211_TX_STATUS_AMPDU))
691 return;
692
Zhu Yib481de92007-09-25 17:54:57 -0700693 retries = tx_resp->retry_count;
694
695 if (retries > 15)
696 retries = 15;
697
698
699 sta = sta_info_get(local, hdr->addr1);
700
701 if (!sta || !sta->rate_ctrl_priv) {
702 if (sta)
703 sta_info_put(sta);
704 return;
705 }
706
Tomas Winklerc33104f2008-01-14 17:46:21 -0800707 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
Zhu Yib481de92007-09-25 17:54:57 -0700708
709 if (!priv->lq_mngr.lq_ready)
710 return;
711
Tomas Winklerc33104f2008-01-14 17:46:21 -0800712 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
713 !lq_sta->ibss_sta_added)
Zhu Yib481de92007-09-25 17:54:57 -0700714 return;
715
Tomas Winklerc33104f2008-01-14 17:46:21 -0800716 table = &lq_sta->lq;
717 active_index = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -0700718
Ben Cahill77626352007-11-29 11:09:44 +0800719 /* Get mac80211 antenna info */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800720 lq_sta->antenna =
721 (lq_sta->valid_antenna & local->hw.conf.antenna_sel_tx);
722 if (!lq_sta->antenna)
723 lq_sta->antenna = lq_sta->valid_antenna;
Zhu Yib481de92007-09-25 17:54:57 -0700724
Ben Cahill77626352007-11-29 11:09:44 +0800725 /* Ignore mac80211 antenna info for now */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800726 lq_sta->antenna = lq_sta->valid_antenna;
Ben Cahill77626352007-11-29 11:09:44 +0800727
Tomas Winklerc33104f2008-01-14 17:46:21 -0800728 curr_tbl = &(lq_sta->lq_info[active_index]);
729 search_tbl = &(lq_sta->lq_info[(1 - active_index)]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800730 window = (struct iwl4965_rate_scale_data *)
Zhu Yib481de92007-09-25 17:54:57 -0700731 &(curr_tbl->win[0]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800732 search_win = (struct iwl4965_rate_scale_data *)
Zhu Yib481de92007-09-25 17:54:57 -0700733 &(search_tbl->win[0]);
734
735 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
736
737 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
738 &tbl_type, &rs_index);
739 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
740 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
741 rs_index, tx_mcs.rate_n_flags);
742 sta_info_put(sta);
743 return;
744 }
745
Ben Cahill77626352007-11-29 11:09:44 +0800746 /*
747 * Ignore this Tx frame response if its initial rate doesn't match
748 * that of latest Link Quality command. There may be stragglers
749 * from a previous Link Quality command, but we're no longer interested
750 * in those; they're either from the "active" mode while we're trying
751 * to check "search" mode, or a prior "search" mode after we've moved
752 * to a new "search" mode (which might become the new "active" mode).
753 */
Zhu Yib481de92007-09-25 17:54:57 -0700754 if (retries &&
755 (tx_mcs.rate_n_flags !=
756 le32_to_cpu(table->rs_table[0].rate_n_flags))) {
757 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
758 tx_mcs.rate_n_flags,
759 le32_to_cpu(table->rs_table[0].rate_n_flags));
760 sta_info_put(sta);
761 return;
762 }
763
Ben Cahill77626352007-11-29 11:09:44 +0800764 /* Update frame history window with "failure" for each Tx retry. */
Zhu Yib481de92007-09-25 17:54:57 -0700765 while (retries) {
Ben Cahill77626352007-11-29 11:09:44 +0800766 /* Look up the rate and other info used for each tx attempt.
767 * Each tx attempt steps one entry deeper in the rate table. */
Zhu Yib481de92007-09-25 17:54:57 -0700768 tx_mcs.rate_n_flags =
769 le32_to_cpu(table->rs_table[index].rate_n_flags);
770 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
771 &tbl_type, &rs_index);
772
Ben Cahill77626352007-11-29 11:09:44 +0800773 /* If type matches "search" table,
774 * add failure to "search" history */
Zhu Yib481de92007-09-25 17:54:57 -0700775 if ((tbl_type.lq_type == search_tbl->lq_type) &&
776 (tbl_type.antenna_type == search_tbl->antenna_type) &&
777 (tbl_type.is_SGI == search_tbl->is_SGI)) {
778 if (search_tbl->expected_tpt)
779 tpt = search_tbl->expected_tpt[rs_index];
780 else
781 tpt = 0;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200782 rs_collect_tx_data(search_win, rs_index, tpt, 1, 0);
Ben Cahill77626352007-11-29 11:09:44 +0800783
784 /* Else if type matches "current/active" table,
785 * add failure to "current/active" history */
Zhu Yib481de92007-09-25 17:54:57 -0700786 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
787 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
788 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
789 if (curr_tbl->expected_tpt)
790 tpt = curr_tbl->expected_tpt[rs_index];
791 else
792 tpt = 0;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200793 rs_collect_tx_data(window, rs_index, tpt, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700794 }
Ben Cahill77626352007-11-29 11:09:44 +0800795
796 /* If not searching for a new mode, increment failed counter
797 * ... this helps determine when to start searching again */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800798 if (lq_sta->stay_in_tbl)
799 lq_sta->total_failed++;
Zhu Yib481de92007-09-25 17:54:57 -0700800 --retries;
801 index++;
802
803 }
804
Ben Cahill77626352007-11-29 11:09:44 +0800805 /*
806 * Find (by rate) the history window to update with final Tx attempt;
807 * if Tx was successful first try, use original rate,
808 * else look up the rate that was, finally, successful.
809 */
Zhu Yib481de92007-09-25 17:54:57 -0700810 if (!tx_resp->retry_count)
811 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
812 else
813 tx_mcs.rate_n_flags =
814 le32_to_cpu(table->rs_table[index].rate_n_flags);
815
816 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
817 &tbl_type, &rs_index);
818
Ben Cahill77626352007-11-29 11:09:44 +0800819 /* Update frame history window with "success" if Tx got ACKed ... */
Zhu Yib481de92007-09-25 17:54:57 -0700820 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
821 status = 1;
822 else
823 status = 0;
824
Ben Cahill77626352007-11-29 11:09:44 +0800825 /* If type matches "search" table,
826 * add final tx status to "search" history */
Zhu Yib481de92007-09-25 17:54:57 -0700827 if ((tbl_type.lq_type == search_tbl->lq_type) &&
828 (tbl_type.antenna_type == search_tbl->antenna_type) &&
829 (tbl_type.is_SGI == search_tbl->is_SGI)) {
830 if (search_tbl->expected_tpt)
831 tpt = search_tbl->expected_tpt[rs_index];
832 else
833 tpt = 0;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200834 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
835 rs_collect_tx_data(search_win, rs_index, tpt,
836 tx_resp->ampdu_ack_len,
837 tx_resp->ampdu_ack_map);
838 else
839 rs_collect_tx_data(search_win, rs_index, tpt,
840 1, status);
Ben Cahill77626352007-11-29 11:09:44 +0800841 /* Else if type matches "current/active" table,
842 * add final tx status to "current/active" history */
Zhu Yib481de92007-09-25 17:54:57 -0700843 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
844 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
845 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
846 if (curr_tbl->expected_tpt)
847 tpt = curr_tbl->expected_tpt[rs_index];
848 else
849 tpt = 0;
Ron Rindjunsky99556432008-01-28 14:07:25 +0200850 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
851 rs_collect_tx_data(window, rs_index, tpt,
852 tx_resp->ampdu_ack_len,
853 tx_resp->ampdu_ack_map);
854 else
855 rs_collect_tx_data(window, rs_index, tpt,
856 1, status);
Zhu Yib481de92007-09-25 17:54:57 -0700857 }
858
Ben Cahill77626352007-11-29 11:09:44 +0800859 /* If not searching for new mode, increment success/failed counter
860 * ... these help determine when to start searching again */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800861 if (lq_sta->stay_in_tbl) {
Ron Rindjunsky99556432008-01-28 14:07:25 +0200862 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) {
863 lq_sta->total_success += tx_resp->ampdu_ack_map;
864 lq_sta->total_failed +=
865 (tx_resp->ampdu_ack_len - tx_resp->ampdu_ack_map);
866 } else {
867 if (status)
868 lq_sta->total_success++;
869 else
870 lq_sta->total_failed++;
871 }
Zhu Yib481de92007-09-25 17:54:57 -0700872 }
873
Ben Cahill77626352007-11-29 11:09:44 +0800874 /* See if there's a better rate or modulation mode to try. */
Zhu Yib481de92007-09-25 17:54:57 -0700875 rs_rate_scale_perform(priv, dev, hdr, sta);
876 sta_info_put(sta);
877 return;
878}
879
880static u8 rs_is_ant_connected(u8 valid_antenna,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800881 enum iwl4965_antenna_type antenna_type)
Zhu Yib481de92007-09-25 17:54:57 -0700882{
883 if (antenna_type == ANT_AUX)
884 return ((valid_antenna & 0x2) ? 1:0);
885 else if (antenna_type == ANT_MAIN)
886 return ((valid_antenna & 0x1) ? 1:0);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800887 else if (antenna_type == ANT_BOTH)
888 return ((valid_antenna & 0x3) == 0x3);
Zhu Yib481de92007-09-25 17:54:57 -0700889
890 return 1;
891}
892
893static u8 rs_is_other_ant_connected(u8 valid_antenna,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800894 enum iwl4965_antenna_type antenna_type)
Zhu Yib481de92007-09-25 17:54:57 -0700895{
896 if (antenna_type == ANT_AUX)
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800897 return rs_is_ant_connected(valid_antenna, ANT_MAIN);
Zhu Yib481de92007-09-25 17:54:57 -0700898 else
Tomas Winklerdc2453ae2007-10-25 17:15:25 +0800899 return rs_is_ant_connected(valid_antenna, ANT_AUX);
Zhu Yib481de92007-09-25 17:54:57 -0700900
901 return 0;
902}
903
Ben Cahill77626352007-11-29 11:09:44 +0800904/*
905 * Begin a period of staying with a selected modulation mode.
906 * Set "stay_in_tbl" flag to prevent any mode switches.
907 * Set frame tx success limits according to legacy vs. high-throughput,
908 * and reset overall (spanning all rates) tx success history statistics.
909 * These control how long we stay using same modulation mode before
910 * searching for a new mode.
911 */
Zhu Yib481de92007-09-25 17:54:57 -0700912static void rs_set_stay_in_table(u8 is_legacy,
Tomas Winklerc33104f2008-01-14 17:46:21 -0800913 struct iwl4965_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -0700914{
915 IWL_DEBUG_HT("we are staying in the same table\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -0800916 lq_sta->stay_in_tbl = 1; /* only place this gets set */
Zhu Yib481de92007-09-25 17:54:57 -0700917 if (is_legacy) {
Tomas Winklerc33104f2008-01-14 17:46:21 -0800918 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
919 lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
920 lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -0700921 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -0800922 lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
923 lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
924 lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
Zhu Yib481de92007-09-25 17:54:57 -0700925 }
Tomas Winklerc33104f2008-01-14 17:46:21 -0800926 lq_sta->table_count = 0;
927 lq_sta->total_failed = 0;
928 lq_sta->total_success = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700929}
930
Ben Cahill77626352007-11-29 11:09:44 +0800931/*
932 * Find correct throughput table for given mode of modulation
933 */
Tomas Winklerc33104f2008-01-14 17:46:21 -0800934static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800935 struct iwl4965_scale_tbl_info *tbl)
Zhu Yib481de92007-09-25 17:54:57 -0700936{
937 if (is_legacy(tbl->lq_type)) {
938 if (!is_a_band(tbl->lq_type))
939 tbl->expected_tpt = expected_tpt_G;
940 else
941 tbl->expected_tpt = expected_tpt_A;
942 } else if (is_siso(tbl->lq_type)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -0800943 if (tbl->is_fat && !lq_sta->is_dup)
Zhu Yib481de92007-09-25 17:54:57 -0700944 if (tbl->is_SGI)
945 tbl->expected_tpt = expected_tpt_siso40MHzSGI;
946 else
947 tbl->expected_tpt = expected_tpt_siso40MHz;
948 else if (tbl->is_SGI)
949 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
950 else
951 tbl->expected_tpt = expected_tpt_siso20MHz;
952
953 } else if (is_mimo(tbl->lq_type)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -0800954 if (tbl->is_fat && !lq_sta->is_dup)
Zhu Yib481de92007-09-25 17:54:57 -0700955 if (tbl->is_SGI)
956 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
957 else
958 tbl->expected_tpt = expected_tpt_mimo40MHz;
959 else if (tbl->is_SGI)
960 tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
961 else
962 tbl->expected_tpt = expected_tpt_mimo20MHz;
963 } else
964 tbl->expected_tpt = expected_tpt_G;
965}
966
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800967#ifdef CONFIG_IWL4965_HT
Ben Cahill77626352007-11-29 11:09:44 +0800968/*
969 * Find starting rate for new "search" high-throughput mode of modulation.
970 * Goal is to find lowest expected rate (under perfect conditions) that is
971 * above the current measured throughput of "active" mode, to give new mode
972 * a fair chance to prove itself without too many challenges.
973 *
974 * This gets called when transitioning to more aggressive modulation
975 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
976 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
977 * to decrease to match "active" throughput. When moving from MIMO to SISO,
978 * bit rate will typically need to increase, but not if performance was bad.
979 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800980static s32 rs_get_best_rate(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -0800981 struct iwl4965_lq_sta *lq_sta,
Ben Cahill77626352007-11-29 11:09:44 +0800982 struct iwl4965_scale_tbl_info *tbl, /* "search" */
Zhu Yib481de92007-09-25 17:54:57 -0700983 u16 rate_mask, s8 index, s8 rate)
984{
Ben Cahill77626352007-11-29 11:09:44 +0800985 /* "active" values */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800986 struct iwl4965_scale_tbl_info *active_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -0800987 &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -0700988 s32 active_sr = active_tbl->win[index].success_ratio;
Zhu Yib481de92007-09-25 17:54:57 -0700989 s32 active_tpt = active_tbl->expected_tpt[index];
Ben Cahill77626352007-11-29 11:09:44 +0800990
991 /* expected "search" throughput */
992 s32 *tpt_tbl = tbl->expected_tpt;
993
994 s32 new_rate, high, low, start_hi;
Zhu Yib481de92007-09-25 17:54:57 -0700995 u16 high_low;
996
997 new_rate = high = low = start_hi = IWL_RATE_INVALID;
998
999 for (; ;) {
1000 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
1001
1002 low = high_low & 0xff;
1003 high = (high_low >> 8) & 0xff;
1004
Ben Cahill77626352007-11-29 11:09:44 +08001005 /*
1006 * Lower the "search" bit rate, to give new "search" mode
1007 * approximately the same throughput as "active" if:
1008 *
1009 * 1) "Active" mode has been working modestly well (but not
1010 * great), and expected "search" throughput (under perfect
1011 * conditions) at candidate rate is above the actual
1012 * measured "active" throughput (but less than expected
1013 * "active" throughput under perfect conditions).
1014 * OR
1015 * 2) "Active" mode has been working perfectly or very well
1016 * and expected "search" throughput (under perfect
1017 * conditions) at candidate rate is above expected
1018 * "active" throughput (under perfect conditions).
1019 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001020 if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
Zhu Yib481de92007-09-25 17:54:57 -07001021 ((active_sr > IWL_RATE_DECREASE_TH) &&
1022 (active_sr <= IWL_RATE_HIGH_TH) &&
1023 (tpt_tbl[rate] <= active_tpt))) ||
1024 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
1025 (tpt_tbl[rate] > active_tpt))) {
1026
Ben Cahill77626352007-11-29 11:09:44 +08001027 /* (2nd or later pass)
1028 * If we've already tried to raise the rate, and are
1029 * now trying to lower it, use the higher rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001030 if (start_hi != IWL_RATE_INVALID) {
1031 new_rate = start_hi;
1032 break;
1033 }
Ben Cahill77626352007-11-29 11:09:44 +08001034
Zhu Yib481de92007-09-25 17:54:57 -07001035 new_rate = rate;
Ben Cahill77626352007-11-29 11:09:44 +08001036
1037 /* Loop again with lower rate */
Zhu Yib481de92007-09-25 17:54:57 -07001038 if (low != IWL_RATE_INVALID)
1039 rate = low;
Ben Cahill77626352007-11-29 11:09:44 +08001040
1041 /* Lower rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001042 else
1043 break;
Ben Cahill77626352007-11-29 11:09:44 +08001044
1045 /* Else try to raise the "search" rate to match "active" */
Zhu Yib481de92007-09-25 17:54:57 -07001046 } else {
Ben Cahill77626352007-11-29 11:09:44 +08001047 /* (2nd or later pass)
1048 * If we've already tried to lower the rate, and are
1049 * now trying to raise it, use the lower rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001050 if (new_rate != IWL_RATE_INVALID)
1051 break;
Ben Cahill77626352007-11-29 11:09:44 +08001052
1053 /* Loop again with higher rate */
Zhu Yib481de92007-09-25 17:54:57 -07001054 else if (high != IWL_RATE_INVALID) {
1055 start_hi = high;
1056 rate = high;
Ben Cahill77626352007-11-29 11:09:44 +08001057
1058 /* Higher rate not available, use the original */
Zhu Yib481de92007-09-25 17:54:57 -07001059 } else {
1060 new_rate = rate;
1061 break;
1062 }
1063 }
1064 }
1065
1066 return new_rate;
1067}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001068#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001069
1070static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
1071{
1072 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
1073}
1074
Ben Cahill77626352007-11-29 11:09:44 +08001075/*
1076 * Set up search table for MIMO
1077 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001078static int rs_switch_to_mimo(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001079 struct iwl4965_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001080 struct ieee80211_conf *conf,
1081 struct sta_info *sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001082 struct iwl4965_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001083{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001084#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07001085 u16 rate_mask;
1086 s32 rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001087 s8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001088
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001089 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1090 !sta->ht_info.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001091 return -1;
1092
1093 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
1094 tbl->lq_type = LQ_MIMO;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001095 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
Zhu Yib481de92007-09-25 17:54:57 -07001096 &rate_mask);
1097
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001098 if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
Zhu Yib481de92007-09-25 17:54:57 -07001099 return -1;
1100
Ben Cahill77626352007-11-29 11:09:44 +08001101 /* Need both Tx chains/antennas to support MIMO */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001102 if (!rs_is_both_ant_supp(lq_sta->antenna))
Zhu Yib481de92007-09-25 17:54:57 -07001103 return -1;
1104
Tomas Winklerc33104f2008-01-14 17:46:21 -08001105 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001106 tbl->action = 0;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001107 if (priv->current_ht_config.supported_chan_width
1108 == IWL_CHANNEL_WIDTH_40MHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001109 tbl->is_fat = 1;
1110 else
1111 tbl->is_fat = 0;
1112
1113 if (tbl->is_fat) {
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001114 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
Zhu Yib481de92007-09-25 17:54:57 -07001115 tbl->is_SGI = 1;
1116 else
1117 tbl->is_SGI = 0;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001118 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
Zhu Yib481de92007-09-25 17:54:57 -07001119 tbl->is_SGI = 1;
1120 else
1121 tbl->is_SGI = 0;
1122
Tomas Winklerc33104f2008-01-14 17:46:21 -08001123 rs_get_expected_tpt_table(lq_sta, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001124
Tomas Winklerc33104f2008-01-14 17:46:21 -08001125 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index);
Zhu Yib481de92007-09-25 17:54:57 -07001126
1127 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
1128 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
1129 return -1;
1130 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1131
1132 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1133 tbl->current_rate.rate_n_flags, is_green);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001134 return 0;
Mohamed Abbas403ab562007-11-06 22:06:25 -08001135#else
1136 return -1;
1137#endif /*CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001138}
1139
Ben Cahill77626352007-11-29 11:09:44 +08001140/*
1141 * Set up search table for SISO
1142 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001143static int rs_switch_to_siso(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001144 struct iwl4965_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001145 struct ieee80211_conf *conf,
1146 struct sta_info *sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001147 struct iwl4965_scale_tbl_info *tbl, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001148{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001149#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07001150 u16 rate_mask;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001151 u8 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001152 s32 rate;
1153
1154 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001155 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1156 !sta->ht_info.ht_supported)
Zhu Yib481de92007-09-25 17:54:57 -07001157 return -1;
1158
Tomas Winklerc33104f2008-01-14 17:46:21 -08001159 tbl->is_dup = lq_sta->is_dup;
Zhu Yib481de92007-09-25 17:54:57 -07001160 tbl->lq_type = LQ_SISO;
1161 tbl->action = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001162 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
Zhu Yib481de92007-09-25 17:54:57 -07001163 &rate_mask);
1164
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001165 if (priv->current_ht_config.supported_chan_width
1166 == IWL_CHANNEL_WIDTH_40MHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001167 tbl->is_fat = 1;
1168 else
1169 tbl->is_fat = 0;
1170
1171 if (tbl->is_fat) {
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001172 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
Zhu Yib481de92007-09-25 17:54:57 -07001173 tbl->is_SGI = 1;
1174 else
1175 tbl->is_SGI = 0;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001176 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
Zhu Yib481de92007-09-25 17:54:57 -07001177 tbl->is_SGI = 1;
1178 else
1179 tbl->is_SGI = 0;
1180
1181 if (is_green)
1182 tbl->is_SGI = 0;
1183
Tomas Winklerc33104f2008-01-14 17:46:21 -08001184 rs_get_expected_tpt_table(lq_sta, tbl);
1185 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index);
Zhu Yib481de92007-09-25 17:54:57 -07001186
1187 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
1188 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1189 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
1190 rate, rate_mask);
1191 return -1;
1192 }
1193 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1194 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1195 tbl->current_rate.rate_n_flags, is_green);
Mohamed Abbas403ab562007-11-06 22:06:25 -08001196 return 0;
1197#else
1198 return -1;
Zhu Yib481de92007-09-25 17:54:57 -07001199
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001200#endif /*CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001201}
1202
Ben Cahill77626352007-11-29 11:09:44 +08001203/*
1204 * Try to switch to new modulation mode from legacy
1205 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001206static int rs_move_legacy_other(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001207 struct iwl4965_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001208 struct ieee80211_conf *conf,
1209 struct sta_info *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001210 int index)
1211{
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001212 int ret = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001213 struct iwl4965_scale_tbl_info *tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001214 &(lq_sta->lq_info[lq_sta->active_tbl]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001215 struct iwl4965_scale_tbl_info *search_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001216 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001217 struct iwl4965_rate_scale_data *window = &(tbl->win[index]);
1218 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1219 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
Zhu Yib481de92007-09-25 17:54:57 -07001220 u8 start_action = tbl->action;
1221
1222 for (; ;) {
1223 switch (tbl->action) {
1224 case IWL_LEGACY_SWITCH_ANTENNA:
1225 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1226
1227 search_tbl->lq_type = LQ_NONE;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001228 lq_sta->action_counter++;
Ben Cahill77626352007-11-29 11:09:44 +08001229
1230 /* Don't change antenna if success has been great */
Zhu Yib481de92007-09-25 17:54:57 -07001231 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1232 break;
Ben Cahill77626352007-11-29 11:09:44 +08001233
1234 /* Don't change antenna if other one is not connected */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001235 if (!rs_is_other_ant_connected(lq_sta->antenna,
Zhu Yib481de92007-09-25 17:54:57 -07001236 tbl->antenna_type))
1237 break;
1238
Ben Cahill77626352007-11-29 11:09:44 +08001239 /* Set up search table to try other antenna */
Zhu Yib481de92007-09-25 17:54:57 -07001240 memcpy(search_tbl, tbl, sz);
1241
1242 rs_toggle_antenna(&(search_tbl->current_rate),
1243 search_tbl);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001244 rs_get_expected_tpt_table(lq_sta, search_tbl);
1245 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001246 goto out;
1247
1248 case IWL_LEGACY_SWITCH_SISO:
1249 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001250
1251 /* Set up search table to try SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001252 memcpy(search_tbl, tbl, sz);
1253 search_tbl->lq_type = LQ_SISO;
1254 search_tbl->is_SGI = 0;
1255 search_tbl->is_fat = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001256 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001257 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001258 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001259 lq_sta->search_better_tbl = 1;
1260 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001261 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001262 }
Zhu Yib481de92007-09-25 17:54:57 -07001263
1264 break;
1265 case IWL_LEGACY_SWITCH_MIMO:
1266 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001267
1268 /* Set up search table to try MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07001269 memcpy(search_tbl, tbl, sz);
1270 search_tbl->lq_type = LQ_MIMO;
1271 search_tbl->is_SGI = 0;
1272 search_tbl->is_fat = 0;
1273 search_tbl->antenna_type = ANT_BOTH;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001274 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001275 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001276 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001277 lq_sta->search_better_tbl = 1;
1278 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001279 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001280 }
Zhu Yib481de92007-09-25 17:54:57 -07001281 break;
1282 }
1283 tbl->action++;
1284 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1285 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1286
1287 if (tbl->action == start_action)
1288 break;
1289
1290 }
1291 return 0;
1292
1293 out:
1294 tbl->action++;
1295 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1296 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1297 return 0;
1298
1299}
1300
Ben Cahill77626352007-11-29 11:09:44 +08001301/*
1302 * Try to switch to new modulation mode from SISO
1303 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001304static int rs_move_siso_to_other(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001305 struct iwl4965_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001306 struct ieee80211_conf *conf,
1307 struct sta_info *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001308 int index)
1309{
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001310 int ret;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001311 u8 is_green = lq_sta->is_green;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001312 struct iwl4965_scale_tbl_info *tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001313 &(lq_sta->lq_info[lq_sta->active_tbl]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001314 struct iwl4965_scale_tbl_info *search_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001315 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001316 struct iwl4965_rate_scale_data *window = &(tbl->win[index]);
1317 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1318 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
Zhu Yib481de92007-09-25 17:54:57 -07001319 u8 start_action = tbl->action;
1320
1321 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001322 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001323 switch (tbl->action) {
1324 case IWL_SISO_SWITCH_ANTENNA:
1325 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1326 search_tbl->lq_type = LQ_NONE;
1327 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1328 break;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001329 if (!rs_is_other_ant_connected(lq_sta->antenna,
Zhu Yib481de92007-09-25 17:54:57 -07001330 tbl->antenna_type))
1331 break;
1332
1333 memcpy(search_tbl, tbl, sz);
1334 search_tbl->action = IWL_SISO_SWITCH_MIMO;
1335 rs_toggle_antenna(&(search_tbl->current_rate),
1336 search_tbl);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001337 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001338
1339 goto out;
1340
1341 case IWL_SISO_SWITCH_MIMO:
1342 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1343 memcpy(search_tbl, tbl, sz);
1344 search_tbl->lq_type = LQ_MIMO;
1345 search_tbl->is_SGI = 0;
1346 search_tbl->is_fat = 0;
1347 search_tbl->antenna_type = ANT_BOTH;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001348 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001349 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001350 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001351 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001352 goto out;
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001353 }
Zhu Yib481de92007-09-25 17:54:57 -07001354 break;
1355 case IWL_SISO_SWITCH_GI:
1356 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1357 memcpy(search_tbl, tbl, sz);
1358 search_tbl->action = 0;
1359 if (search_tbl->is_SGI)
1360 search_tbl->is_SGI = 0;
1361 else if (!is_green)
1362 search_tbl->is_SGI = 1;
1363 else
1364 break;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001365 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001366 if ((tbl->lq_type == LQ_SISO) &&
1367 (tbl->is_SGI)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001368 s32 tpt = lq_sta->last_tpt / 100;
Zhu Yib481de92007-09-25 17:54:57 -07001369 if (((!tbl->is_fat) &&
1370 (tpt >= expected_tpt_siso20MHz[index])) ||
1371 ((tbl->is_fat) &&
1372 (tpt >= expected_tpt_siso40MHz[index])))
Tomas Winklerc33104f2008-01-14 17:46:21 -08001373 lq_sta->search_better_tbl = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001374 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001375 rs_get_expected_tpt_table(lq_sta, search_tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001376 rs_mcs_from_tbl(&search_tbl->current_rate,
1377 search_tbl, index, is_green);
1378 goto out;
1379 }
1380 tbl->action++;
1381 if (tbl->action > IWL_SISO_SWITCH_GI)
1382 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1383
1384 if (tbl->action == start_action)
1385 break;
1386 }
1387 return 0;
1388
1389 out:
1390 tbl->action++;
1391 if (tbl->action > IWL_SISO_SWITCH_GI)
1392 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1393 return 0;
1394}
1395
Ben Cahill77626352007-11-29 11:09:44 +08001396/*
1397 * Try to switch to new modulation mode from MIMO
1398 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001399static int rs_move_mimo_to_other(struct iwl4965_priv *priv,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001400 struct iwl4965_lq_sta *lq_sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001401 struct ieee80211_conf *conf,
1402 struct sta_info *sta,
Zhu Yib481de92007-09-25 17:54:57 -07001403 int index)
1404{
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001405 int ret;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001406 s8 is_green = lq_sta->is_green;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001407 struct iwl4965_scale_tbl_info *tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001408 &(lq_sta->lq_info[lq_sta->active_tbl]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001409 struct iwl4965_scale_tbl_info *search_tbl =
Tomas Winklerc33104f2008-01-14 17:46:21 -08001410 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001411 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1412 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
Zhu Yib481de92007-09-25 17:54:57 -07001413 u8 start_action = tbl->action;
1414
1415 for (;;) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001416 lq_sta->action_counter++;
Zhu Yib481de92007-09-25 17:54:57 -07001417 switch (tbl->action) {
1418 case IWL_MIMO_SWITCH_ANTENNA_A:
1419 case IWL_MIMO_SWITCH_ANTENNA_B:
1420 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
Ben Cahill77626352007-11-29 11:09:44 +08001421
1422 /* Set up new search table for SISO */
Zhu Yib481de92007-09-25 17:54:57 -07001423 memcpy(search_tbl, tbl, sz);
1424 search_tbl->lq_type = LQ_SISO;
1425 search_tbl->is_SGI = 0;
1426 search_tbl->is_fat = 0;
1427 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1428 search_tbl->antenna_type = ANT_MAIN;
1429 else
1430 search_tbl->antenna_type = ANT_AUX;
1431
Tomas Winklerc33104f2008-01-14 17:46:21 -08001432 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001433 search_tbl, index);
Tomas Winklerdc2453ae2007-10-25 17:15:25 +08001434 if (!ret) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001435 lq_sta->search_better_tbl = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001436 goto out;
1437 }
1438 break;
1439
1440 case IWL_MIMO_SWITCH_GI:
1441 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
Ben Cahill77626352007-11-29 11:09:44 +08001442
1443 /* Set up new search table for MIMO */
Zhu Yib481de92007-09-25 17:54:57 -07001444 memcpy(search_tbl, tbl, sz);
1445 search_tbl->lq_type = LQ_MIMO;
1446 search_tbl->antenna_type = ANT_BOTH;
1447 search_tbl->action = 0;
1448 if (search_tbl->is_SGI)
1449 search_tbl->is_SGI = 0;
1450 else
1451 search_tbl->is_SGI = 1;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001452 lq_sta->search_better_tbl = 1;
Ben Cahill77626352007-11-29 11:09:44 +08001453
1454 /*
1455 * If active table already uses the fastest possible
1456 * modulation (dual stream with short guard interval),
1457 * and it's working well, there's no need to look
1458 * for a better type of modulation!
1459 */
Zhu Yib481de92007-09-25 17:54:57 -07001460 if ((tbl->lq_type == LQ_MIMO) &&
1461 (tbl->is_SGI)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001462 s32 tpt = lq_sta->last_tpt / 100;
Zhu Yib481de92007-09-25 17:54:57 -07001463 if (((!tbl->is_fat) &&
1464 (tpt >= expected_tpt_mimo20MHz[index])) ||
1465 ((tbl->is_fat) &&
1466 (tpt >= expected_tpt_mimo40MHz[index])))
Tomas Winklerc33104f2008-01-14 17:46:21 -08001467 lq_sta->search_better_tbl = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001468 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001469 rs_get_expected_tpt_table(lq_sta, search_tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001470 rs_mcs_from_tbl(&search_tbl->current_rate,
1471 search_tbl, index, is_green);
1472 goto out;
1473
1474 }
1475 tbl->action++;
1476 if (tbl->action > IWL_MIMO_SWITCH_GI)
1477 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1478
1479 if (tbl->action == start_action)
1480 break;
1481 }
1482
1483 return 0;
1484 out:
1485 tbl->action++;
1486 if (tbl->action > IWL_MIMO_SWITCH_GI)
1487 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1488 return 0;
1489
1490}
1491
Ben Cahill77626352007-11-29 11:09:44 +08001492/*
1493 * Check whether we should continue using same modulation mode, or
1494 * begin search for a new mode, based on:
1495 * 1) # tx successes or failures while using this mode
1496 * 2) # times calling this function
1497 * 3) elapsed time in this mode (not used, for now)
1498 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001499static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
Zhu Yib481de92007-09-25 17:54:57 -07001500{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001501 struct iwl4965_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001502 int i;
1503 int active_tbl;
1504 int flush_interval_passed = 0;
1505
Tomas Winklerc33104f2008-01-14 17:46:21 -08001506 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001507
Tomas Winklerc33104f2008-01-14 17:46:21 -08001508 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001509
Ben Cahill77626352007-11-29 11:09:44 +08001510 /* If we've been disallowing search, see if we should now allow it */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001511 if (lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07001512
Ben Cahill77626352007-11-29 11:09:44 +08001513 /* Elapsed time using current modulation mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001514 if (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07001515 flush_interval_passed =
1516 time_after(jiffies,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001517 (unsigned long)(lq_sta->flush_timer +
Zhu Yib481de92007-09-25 17:54:57 -07001518 IWL_RATE_SCALE_FLUSH_INTVL));
1519
Ben Cahill77626352007-11-29 11:09:44 +08001520 /* For now, disable the elapsed time criterion */
Zhu Yib481de92007-09-25 17:54:57 -07001521 flush_interval_passed = 0;
Ben Cahill77626352007-11-29 11:09:44 +08001522
1523 /*
1524 * Check if we should allow search for new modulation mode.
1525 * If many frames have failed or succeeded, or we've used
1526 * this same modulation for a long time, allow search, and
1527 * reset history stats that keep track of whether we should
1528 * allow a new search. Also (below) reset all bitmaps and
1529 * stats in active history.
1530 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001531 if ((lq_sta->total_failed > lq_sta->max_failure_limit) ||
1532 (lq_sta->total_success > lq_sta->max_success_limit) ||
1533 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
Zhu Yib481de92007-09-25 17:54:57 -07001534 && (flush_interval_passed))) {
1535 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
Tomas Winklerc33104f2008-01-14 17:46:21 -08001536 lq_sta->total_failed,
1537 lq_sta->total_success,
Zhu Yib481de92007-09-25 17:54:57 -07001538 flush_interval_passed);
Ben Cahill77626352007-11-29 11:09:44 +08001539
1540 /* Allow search for new mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001541 lq_sta->stay_in_tbl = 0; /* only place reset */
1542 lq_sta->total_failed = 0;
1543 lq_sta->total_success = 0;
1544 lq_sta->flush_timer = 0;
Ben Cahill77626352007-11-29 11:09:44 +08001545
1546 /*
1547 * Else if we've used this modulation mode enough repetitions
1548 * (regardless of elapsed time or success/failure), reset
1549 * history bitmaps and rate-specific stats for all rates in
1550 * active table.
1551 */
Mohamed Abbas403ab562007-11-06 22:06:25 -08001552 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001553 lq_sta->table_count++;
1554 if (lq_sta->table_count >=
1555 lq_sta->table_count_limit) {
1556 lq_sta->table_count = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001557
1558 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1559 for (i = 0; i < IWL_RATE_COUNT; i++)
1560 rs_rate_scale_clear_window(
1561 &(tbl->win[i]));
1562 }
1563 }
1564
Ben Cahill77626352007-11-29 11:09:44 +08001565 /* If transitioning to allow "search", reset all history
1566 * bitmaps and stats in active table (this will become the new
1567 * "search" table). */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001568 if (!lq_sta->stay_in_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07001569 for (i = 0; i < IWL_RATE_COUNT; i++)
1570 rs_rate_scale_clear_window(&(tbl->win[i]));
1571 }
1572 }
1573}
1574
Ben Cahill77626352007-11-29 11:09:44 +08001575/*
1576 * Do rate scaling and search for new modulation mode.
1577 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001578static void rs_rate_scale_perform(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001579 struct net_device *dev,
1580 struct ieee80211_hdr *hdr,
1581 struct sta_info *sta)
1582{
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001583 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1584 struct ieee80211_hw *hw = local_to_hw(local);
1585 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07001586 int low = IWL_RATE_INVALID;
1587 int high = IWL_RATE_INVALID;
1588 int index;
1589 int i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001590 struct iwl4965_rate_scale_data *window = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001591 int current_tpt = IWL_INVALID_VALUE;
1592 int low_tpt = IWL_INVALID_VALUE;
1593 int high_tpt = IWL_INVALID_VALUE;
1594 u32 fail_count;
1595 s8 scale_action = 0;
1596 u16 fc, rate_mask;
1597 u8 update_lq = 0;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001598 struct iwl4965_lq_sta *lq_sta;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001599 struct iwl4965_scale_tbl_info *tbl, *tbl1;
Zhu Yib481de92007-09-25 17:54:57 -07001600 u16 rate_scale_index_msk = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001601 struct iwl4965_rate mcs_rate;
Zhu Yib481de92007-09-25 17:54:57 -07001602 u8 is_green = 0;
1603 u8 active_tbl = 0;
1604 u8 done_search = 0;
1605 u16 high_low;
1606
1607 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1608
1609 fc = le16_to_cpu(hdr->frame_control);
1610 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1611 /* Send management frames and broadcast/multicast data using
1612 * lowest rate. */
1613 /* TODO: this could probably be improved.. */
1614 return;
1615 }
1616
1617 if (!sta || !sta->rate_ctrl_priv)
1618 return;
1619
1620 if (!priv->lq_mngr.lq_ready) {
1621 IWL_DEBUG_RATE("still rate scaling not ready\n");
1622 return;
1623 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08001624 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
Zhu Yib481de92007-09-25 17:54:57 -07001625
Ben Cahill77626352007-11-29 11:09:44 +08001626 /*
1627 * Select rate-scale / modulation-mode table to work with in
1628 * the rest of this function: "search" if searching for better
1629 * modulation mode, or "active" if doing rate scaling within a mode.
1630 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001631 if (!lq_sta->search_better_tbl)
1632 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001633 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08001634 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001635
Tomas Winklerc33104f2008-01-14 17:46:21 -08001636 tbl = &(lq_sta->lq_info[active_tbl]);
1637 is_green = lq_sta->is_green;
Zhu Yib481de92007-09-25 17:54:57 -07001638
Ben Cahill77626352007-11-29 11:09:44 +08001639 /* current tx rate */
Zhu Yib481de92007-09-25 17:54:57 -07001640 index = sta->last_txrate;
1641
1642 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1643 tbl->lq_type);
1644
Ben Cahill77626352007-11-29 11:09:44 +08001645 /* rates available for this association, and for modulation mode */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001646 rs_get_supported_rates(lq_sta, hdr, tbl->lq_type,
Zhu Yib481de92007-09-25 17:54:57 -07001647 &rate_mask);
1648
1649 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1650
1651 /* mask with station rate restriction */
1652 if (is_legacy(tbl->lq_type)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001653 if (lq_sta->phymode == (u8) MODE_IEEE80211A)
Ben Cahill77626352007-11-29 11:09:44 +08001654 /* supp_rates has no CCK bits in A mode */
Zhu Yib481de92007-09-25 17:54:57 -07001655 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08001656 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
Zhu Yib481de92007-09-25 17:54:57 -07001657 else
1658 rate_scale_index_msk = (u16) (rate_mask &
Tomas Winklerc33104f2008-01-14 17:46:21 -08001659 lq_sta->supp_rates);
Zhu Yib481de92007-09-25 17:54:57 -07001660
1661 } else
1662 rate_scale_index_msk = rate_mask;
1663
1664 if (!rate_scale_index_msk)
1665 rate_scale_index_msk = rate_mask;
1666
Ben Cahill77626352007-11-29 11:09:44 +08001667 /* If current rate is no longer supported on current association,
1668 * or user changed preferences for rates, find a new supported rate. */
Zhu Yib481de92007-09-25 17:54:57 -07001669 if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
1670 index = IWL_INVALID_VALUE;
1671 update_lq = 1;
1672
Ben Cahill77626352007-11-29 11:09:44 +08001673 /* get the highest available rate */
Zhu Yib481de92007-09-25 17:54:57 -07001674 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1675 if ((1 << i) & rate_scale_index_msk)
1676 index = i;
1677 }
1678
1679 if (index == IWL_INVALID_VALUE) {
1680 IWL_WARNING("Can not find a suitable rate\n");
1681 return;
1682 }
1683 }
1684
Ben Cahill77626352007-11-29 11:09:44 +08001685 /* Get expected throughput table and history window for current rate */
Zhu Yib481de92007-09-25 17:54:57 -07001686 if (!tbl->expected_tpt)
Tomas Winklerc33104f2008-01-14 17:46:21 -08001687 rs_get_expected_tpt_table(lq_sta, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07001688
1689 window = &(tbl->win[index]);
1690
Ben Cahill77626352007-11-29 11:09:44 +08001691 /*
1692 * If there is not enough history to calculate actual average
1693 * throughput, keep analyzing results of more tx frames, without
1694 * changing rate or mode (bypass most of the rest of this function).
1695 * Set up new rate table in uCode only if old rate is not supported
1696 * in current association (use new rate found above).
1697 */
Zhu Yib481de92007-09-25 17:54:57 -07001698 fail_count = window->counter - window->success_counter;
1699 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1700 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
1701 || (tbl->expected_tpt == NULL)) {
1702 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1703 "for index %d\n",
1704 window->success_counter, window->counter, index);
Ben Cahill77626352007-11-29 11:09:44 +08001705
1706 /* Can't calculate this yet; not enough history */
Zhu Yib481de92007-09-25 17:54:57 -07001707 window->average_tpt = IWL_INVALID_VALUE;
Ben Cahill77626352007-11-29 11:09:44 +08001708
1709 /* Should we stay with this modulation mode,
1710 * or search for a new one? */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001711 rs_stay_in_table(lq_sta);
Ben Cahill77626352007-11-29 11:09:44 +08001712
1713 /* Set up new rate table in uCode, if needed */
Zhu Yib481de92007-09-25 17:54:57 -07001714 if (update_lq) {
1715 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001716 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq);
1717 rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001718 }
1719 goto out;
1720
Ben Cahill77626352007-11-29 11:09:44 +08001721 /* Else we have enough samples; calculate estimate of
1722 * actual average throughput */
Zhu Yib481de92007-09-25 17:54:57 -07001723 } else
1724 window->average_tpt = ((window->success_ratio *
1725 tbl->expected_tpt[index] + 64) / 128);
1726
Ben Cahill77626352007-11-29 11:09:44 +08001727 /* If we are searching for better modulation mode, check success. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001728 if (lq_sta->search_better_tbl) {
Zhu Yib481de92007-09-25 17:54:57 -07001729 int success_limit = IWL_RATE_SCALE_SWITCH;
1730
Ben Cahill77626352007-11-29 11:09:44 +08001731 /* If good success, continue using the "search" mode;
1732 * no need to send new link quality command, since we're
1733 * continuing to use the setup that we've been trying. */
Zhu Yib481de92007-09-25 17:54:57 -07001734 if ((window->success_ratio > success_limit) ||
Tomas Winklerc33104f2008-01-14 17:46:21 -08001735 (window->average_tpt > lq_sta->last_tpt)) {
Zhu Yib481de92007-09-25 17:54:57 -07001736 if (!is_legacy(tbl->lq_type)) {
1737 IWL_DEBUG_HT("LQ: we are switching to HT"
1738 " rate suc %d current tpt %d"
1739 " old tpt %d\n",
1740 window->success_ratio,
1741 window->average_tpt,
Tomas Winklerc33104f2008-01-14 17:46:21 -08001742 lq_sta->last_tpt);
1743 lq_sta->enable_counter = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001744 }
Ben Cahill77626352007-11-29 11:09:44 +08001745 /* Swap tables; "search" becomes "active" */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001746 lq_sta->active_tbl = active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001747 current_tpt = window->average_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08001748
1749 /* Else poor success; go back to mode in "active" table */
Zhu Yib481de92007-09-25 17:54:57 -07001750 } else {
Ben Cahill77626352007-11-29 11:09:44 +08001751 /* Nullify "search" table */
Zhu Yib481de92007-09-25 17:54:57 -07001752 tbl->lq_type = LQ_NONE;
Ben Cahill77626352007-11-29 11:09:44 +08001753
1754 /* Revert to "active" table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001755 active_tbl = lq_sta->active_tbl;
1756 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001757
Ben Cahill77626352007-11-29 11:09:44 +08001758 /* Revert to "active" rate and throughput info */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001759 index = iwl4965_rate_index_from_plcp(
Zhu Yib481de92007-09-25 17:54:57 -07001760 tbl->current_rate.rate_n_flags);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001761 current_tpt = lq_sta->last_tpt;
Ben Cahill77626352007-11-29 11:09:44 +08001762
1763 /* Need to set up a new rate table in uCode */
1764 update_lq = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001765 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1766 }
Ben Cahill77626352007-11-29 11:09:44 +08001767
1768 /* Either way, we've made a decision; modulation mode
1769 * search is done, allow rate adjustment next time. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001770 lq_sta->search_better_tbl = 0;
Ben Cahill77626352007-11-29 11:09:44 +08001771 done_search = 1; /* Don't switch modes below! */
Zhu Yib481de92007-09-25 17:54:57 -07001772 goto lq_update;
1773 }
1774
Ben Cahill77626352007-11-29 11:09:44 +08001775 /* (Else) not in search of better modulation mode, try for better
1776 * starting rate, while staying in this mode. */
Zhu Yib481de92007-09-25 17:54:57 -07001777 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
1778 tbl->lq_type);
1779 low = high_low & 0xff;
1780 high = (high_low >> 8) & 0xff;
1781
Ben Cahill77626352007-11-29 11:09:44 +08001782 /* Collect measured throughputs for current and adjacent rates */
Zhu Yib481de92007-09-25 17:54:57 -07001783 current_tpt = window->average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07001784 if (low != IWL_RATE_INVALID)
1785 low_tpt = tbl->win[low].average_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07001786 if (high != IWL_RATE_INVALID)
1787 high_tpt = tbl->win[high].average_tpt;
1788
Ben Cahill77626352007-11-29 11:09:44 +08001789 /* Assume rate increase */
Zhu Yib481de92007-09-25 17:54:57 -07001790 scale_action = 1;
1791
Ben Cahill77626352007-11-29 11:09:44 +08001792 /* Too many failures, decrease rate */
Zhu Yib481de92007-09-25 17:54:57 -07001793 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
1794 (current_tpt == 0)) {
1795 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1796 scale_action = -1;
Ben Cahill77626352007-11-29 11:09:44 +08001797
1798 /* No throughput measured yet for adjacent rates; try increase. */
Zhu Yib481de92007-09-25 17:54:57 -07001799 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1800 (high_tpt == IWL_INVALID_VALUE))
1801 scale_action = 1;
Ben Cahill77626352007-11-29 11:09:44 +08001802
1803 /* Both adjacent throughputs are measured, but neither one has better
1804 * throughput; we're using the best rate, don't change it! */
Zhu Yib481de92007-09-25 17:54:57 -07001805 else if ((low_tpt != IWL_INVALID_VALUE) &&
1806 (high_tpt != IWL_INVALID_VALUE) &&
1807 (low_tpt < current_tpt) &&
1808 (high_tpt < current_tpt))
1809 scale_action = 0;
Ben Cahill77626352007-11-29 11:09:44 +08001810
1811 /* At least one adjacent rate's throughput is measured,
1812 * and may have better performance. */
Zhu Yib481de92007-09-25 17:54:57 -07001813 else {
Ben Cahill77626352007-11-29 11:09:44 +08001814 /* Higher adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07001815 if (high_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08001816 /* Higher rate has better throughput */
Zhu Yib481de92007-09-25 17:54:57 -07001817 if (high_tpt > current_tpt)
1818 scale_action = 1;
1819 else {
1820 IWL_DEBUG_RATE
1821 ("decrease rate because of high tpt\n");
1822 scale_action = -1;
1823 }
Ben Cahill77626352007-11-29 11:09:44 +08001824
1825 /* Lower adjacent rate's throughput is measured */
Zhu Yib481de92007-09-25 17:54:57 -07001826 } else if (low_tpt != IWL_INVALID_VALUE) {
Ben Cahill77626352007-11-29 11:09:44 +08001827 /* Lower rate has better throughput */
Zhu Yib481de92007-09-25 17:54:57 -07001828 if (low_tpt > current_tpt) {
1829 IWL_DEBUG_RATE
1830 ("decrease rate because of low tpt\n");
1831 scale_action = -1;
1832 } else
1833 scale_action = 1;
1834 }
1835 }
1836
Ben Cahill77626352007-11-29 11:09:44 +08001837 /* Sanity check; asked for decrease, but success rate or throughput
1838 * has been good at old rate. Don't change it. */
Zhu Yib481de92007-09-25 17:54:57 -07001839 if (scale_action == -1) {
1840 if ((low != IWL_RATE_INVALID) &&
1841 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1842 (current_tpt > (100 * tbl->expected_tpt[low]))))
1843 scale_action = 0;
Ben Cahill77626352007-11-29 11:09:44 +08001844
1845 /* Sanity check; asked for increase, but success rate has not been great
1846 * even at old rate, higher rate will be worse. Don't change it. */
Zhu Yib481de92007-09-25 17:54:57 -07001847 } else if ((scale_action == 1) &&
1848 (window->success_ratio < IWL_RATE_INCREASE_TH))
1849 scale_action = 0;
1850
1851 switch (scale_action) {
1852 case -1:
Ben Cahill77626352007-11-29 11:09:44 +08001853 /* Decrease starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07001854 if (low != IWL_RATE_INVALID) {
1855 update_lq = 1;
1856 index = low;
1857 }
1858 break;
1859 case 1:
Ben Cahill77626352007-11-29 11:09:44 +08001860 /* Increase starting rate, update uCode's rate table */
Zhu Yib481de92007-09-25 17:54:57 -07001861 if (high != IWL_RATE_INVALID) {
1862 update_lq = 1;
1863 index = high;
1864 }
1865
1866 break;
1867 case 0:
Ben Cahill77626352007-11-29 11:09:44 +08001868 /* No change */
Zhu Yib481de92007-09-25 17:54:57 -07001869 default:
1870 break;
1871 }
1872
1873 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1874 "high %d type %d\n",
1875 index, scale_action, low, high, tbl->lq_type);
1876
1877 lq_update:
Ben Cahill77626352007-11-29 11:09:44 +08001878 /* Replace uCode's rate table for the destination station. */
Zhu Yib481de92007-09-25 17:54:57 -07001879 if (update_lq) {
1880 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001881 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq);
1882 rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001883 }
Ben Cahill77626352007-11-29 11:09:44 +08001884
1885 /* Should we stay with this modulation mode, or search for a new one? */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001886 rs_stay_in_table(lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001887
Ben Cahill77626352007-11-29 11:09:44 +08001888 /*
1889 * Search for new modulation mode if we're:
1890 * 1) Not changing rates right now
1891 * 2) Not just finishing up a search
1892 * 3) Allowing a new search
1893 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001894 if (!update_lq && !done_search && !lq_sta->stay_in_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08001895 /* Save current throughput to compare with "search" throughput*/
Tomas Winklerc33104f2008-01-14 17:46:21 -08001896 lq_sta->last_tpt = current_tpt;
Zhu Yib481de92007-09-25 17:54:57 -07001897
Ben Cahill77626352007-11-29 11:09:44 +08001898 /* Select a new "search" modulation mode to try.
1899 * If one is found, set up the new "search" table. */
Zhu Yib481de92007-09-25 17:54:57 -07001900 if (is_legacy(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08001901 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07001902 else if (is_siso(tbl->lq_type))
Tomas Winklerc33104f2008-01-14 17:46:21 -08001903 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07001904 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08001905 rs_move_mimo_to_other(priv, lq_sta, conf, sta, index);
Zhu Yib481de92007-09-25 17:54:57 -07001906
Ben Cahill77626352007-11-29 11:09:44 +08001907 /* If new "search" mode was selected, set up in uCode table */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001908 if (lq_sta->search_better_tbl) {
Ben Cahill77626352007-11-29 11:09:44 +08001909 /* Access the "search" table, clear its history. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001910 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
Zhu Yib481de92007-09-25 17:54:57 -07001911 for (i = 0; i < IWL_RATE_COUNT; i++)
1912 rs_rate_scale_clear_window(&(tbl->win[i]));
1913
Ben Cahill77626352007-11-29 11:09:44 +08001914 /* Use new "search" start rate */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001915 index = iwl4965_rate_index_from_plcp(
Zhu Yib481de92007-09-25 17:54:57 -07001916 tbl->current_rate.rate_n_flags);
1917
1918 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1919 tbl->current_rate.rate_n_flags, index);
Tomas Winklerc33104f2008-01-14 17:46:21 -08001920 rs_fill_link_cmd(lq_sta, &tbl->current_rate,
1921 &lq_sta->lq);
1922 rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001923 }
Zhu Yib481de92007-09-25 17:54:57 -07001924
Ben Cahill77626352007-11-29 11:09:44 +08001925 /* If the "active" (non-search) mode was legacy,
1926 * and we've tried switching antennas,
1927 * but we haven't been able to try HT modes (not available),
1928 * stay with best antenna legacy modulation for a while
1929 * before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001930 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07001931 if (is_legacy(tbl1->lq_type) &&
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001932#ifdef CONFIG_IWL4965_HT
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001933 (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) &&
Zhu Yib481de92007-09-25 17:54:57 -07001934#endif
Tomas Winklerc33104f2008-01-14 17:46:21 -08001935 (lq_sta->action_counter >= 1)) {
1936 lq_sta->action_counter = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001937 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -08001938 rs_set_stay_in_table(1, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001939 }
1940
Ben Cahill77626352007-11-29 11:09:44 +08001941 /* If we're in an HT mode, and all 3 mode switch actions
1942 * have been tried and compared, stay in this best modulation
1943 * mode for a while before next round of mode comparisons. */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001944 if (lq_sta->enable_counter &&
1945 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) {
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001946#ifdef CONFIG_IWL4965_HT_AGG
Ben Cahill77626352007-11-29 11:09:44 +08001947 /* If appropriate, set up aggregation! */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001948 if ((lq_sta->last_tpt > TID_AGG_TPT_THREHOLD) &&
Zhu Yib481de92007-09-25 17:54:57 -07001949 (priv->lq_mngr.agg_ctrl.auto_agg)) {
1950 priv->lq_mngr.agg_ctrl.tid_retry =
1951 TID_ALL_SPECIFIED;
1952 schedule_work(&priv->agg_work);
1953 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001954#endif /*CONFIG_IWL4965_HT_AGG */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001955 lq_sta->action_counter = 0;
1956 rs_set_stay_in_table(0, lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07001957 }
Ben Cahill77626352007-11-29 11:09:44 +08001958
1959 /*
1960 * Else, don't search for a new modulation mode.
1961 * Put new timestamp in stay-in-modulation-mode flush timer if:
1962 * 1) Not changing rates right now
1963 * 2) Not just finishing up a search
1964 * 3) flush timer is empty
1965 */
Zhu Yib481de92007-09-25 17:54:57 -07001966 } else {
Tomas Winklerc33104f2008-01-14 17:46:21 -08001967 if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer))
1968 lq_sta->flush_timer = jiffies;
Zhu Yib481de92007-09-25 17:54:57 -07001969 }
1970
1971out:
1972 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
1973 i = index;
1974 sta->last_txrate = i;
1975
1976 /* sta->txrate is an index to A mode rates which start
1977 * at IWL_FIRST_OFDM_RATE
1978 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08001979 if (lq_sta->phymode == (u8) MODE_IEEE80211A)
Zhu Yib481de92007-09-25 17:54:57 -07001980 sta->txrate = i - IWL_FIRST_OFDM_RATE;
1981 else
1982 sta->txrate = i;
1983
1984 return;
1985}
1986
1987
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001988static void rs_initialize_lq(struct iwl4965_priv *priv,
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001989 struct ieee80211_conf *conf,
Zhu Yib481de92007-09-25 17:54:57 -07001990 struct sta_info *sta)
1991{
1992 int i;
Tomas Winklerc33104f2008-01-14 17:46:21 -08001993 struct iwl4965_lq_sta *lq_sta;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001994 struct iwl4965_scale_tbl_info *tbl;
Zhu Yib481de92007-09-25 17:54:57 -07001995 u8 active_tbl = 0;
1996 int rate_idx;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02001997 u8 use_green = rs_use_green(priv, conf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001998 struct iwl4965_rate mcs_rate;
Zhu Yib481de92007-09-25 17:54:57 -07001999
2000 if (!sta || !sta->rate_ctrl_priv)
2001 goto out;
2002
Tomas Winklerc33104f2008-01-14 17:46:21 -08002003 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
Zhu Yib481de92007-09-25 17:54:57 -07002004 i = sta->last_txrate;
2005
Tomas Winklerc33104f2008-01-14 17:46:21 -08002006 if ((lq_sta->lq.sta_id == 0xff) &&
Zhu Yib481de92007-09-25 17:54:57 -07002007 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
2008 goto out;
2009
Tomas Winklerc33104f2008-01-14 17:46:21 -08002010 if (!lq_sta->search_better_tbl)
2011 active_tbl = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002012 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002013 active_tbl = 1 - lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002014
Tomas Winklerc33104f2008-01-14 17:46:21 -08002015 tbl = &(lq_sta->lq_info[active_tbl]);
Zhu Yib481de92007-09-25 17:54:57 -07002016
2017 if ((i < 0) || (i >= IWL_RATE_COUNT))
2018 i = 0;
2019
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002020 mcs_rate.rate_n_flags = iwl4965_rates[i].plcp ;
Zhu Yib481de92007-09-25 17:54:57 -07002021 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
2022 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
2023
2024 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
2025 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
2026
2027 tbl->antenna_type = ANT_AUX;
2028 rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx);
2029 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
Zhu Yi46640a82007-09-27 11:27:34 +08002030 rs_toggle_antenna(&mcs_rate, tbl);
Zhu Yib481de92007-09-25 17:54:57 -07002031
2032 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
2033 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002034 rs_get_expected_tpt_table(lq_sta, tbl);
2035 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq);
2036 rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07002037 out:
2038 return;
2039}
2040
Mattias Nissler1abbe492007-12-20 13:50:07 +01002041static void rs_get_rate(void *priv_rate, struct net_device *dev,
2042 struct ieee80211_hw_mode *mode, struct sk_buff *skb,
2043 struct rate_selection *sel)
Zhu Yib481de92007-09-25 17:54:57 -07002044{
2045
2046 int i;
2047 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002048 struct ieee80211_conf *conf = &local->hw.conf;
Zhu Yib481de92007-09-25 17:54:57 -07002049 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2050 struct sta_info *sta;
Michael Wu2bc454b2007-12-25 19:33:16 -05002051 u16 fc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002052 struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002053 struct iwl4965_lq_sta *lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002054
Zhu Yi58826352007-09-27 11:27:39 +08002055 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
Zhu Yib481de92007-09-25 17:54:57 -07002056
Zhu Yib481de92007-09-25 17:54:57 -07002057 sta = sta_info_get(local, hdr->addr1);
2058
Michael Wu2bc454b2007-12-25 19:33:16 -05002059 /* Send management frames and broadcast/multicast data using lowest
2060 * rate. */
2061 fc = le16_to_cpu(hdr->frame_control);
2062 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
2063 !sta || !sta->rate_ctrl_priv) {
Mattias Nissler1abbe492007-12-20 13:50:07 +01002064 sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
Zhu Yib481de92007-09-25 17:54:57 -07002065 if (sta)
2066 sta_info_put(sta);
Mattias Nissler1abbe492007-12-20 13:50:07 +01002067 return;
Zhu Yib481de92007-09-25 17:54:57 -07002068 }
2069
Tomas Winklerc33104f2008-01-14 17:46:21 -08002070 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
Zhu Yib481de92007-09-25 17:54:57 -07002071 i = sta->last_txrate;
2072
Tomas Winklerc33104f2008-01-14 17:46:21 -08002073 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2074 !lq_sta->ibss_sta_added) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002075 u8 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Joe Perches0795af52007-10-03 17:59:30 -07002076 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002077
2078 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07002079 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2080 print_mac(mac, hdr->addr1));
Ron Rindjunsky67d62032007-11-26 16:14:40 +02002081 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2082 0, CMD_ASYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07002083 }
2084 if ((sta_id != IWL_INVALID_STATION)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002085 lq_sta->lq.sta_id = sta_id;
2086 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2087 lq_sta->ibss_sta_added = 1;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002088 rs_initialize_lq(priv, conf, sta);
Zhu Yib481de92007-09-25 17:54:57 -07002089 }
Tomas Winklerc33104f2008-01-14 17:46:21 -08002090 if (!lq_sta->ibss_sta_added)
Zhu Yib481de92007-09-25 17:54:57 -07002091 goto done;
2092 }
2093
2094 done:
Mattias Nissler1abbe492007-12-20 13:50:07 +01002095 if ((i < 0) || (i > IWL_RATE_COUNT)) {
2096 sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
2097 return;
2098 }
Zhu Yib481de92007-09-25 17:54:57 -07002099 sta_info_put(sta);
Zhu Yib481de92007-09-25 17:54:57 -07002100
Mattias Nissler1abbe492007-12-20 13:50:07 +01002101 sel->rate = &priv->ieee_rates[i];
Zhu Yib481de92007-09-25 17:54:57 -07002102}
2103
2104static void *rs_alloc_sta(void *priv, gfp_t gfp)
2105{
Tomas Winklerc33104f2008-01-14 17:46:21 -08002106 struct iwl4965_lq_sta *lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002107 int i, j;
2108
2109 IWL_DEBUG_RATE("create station rate scale window\n");
2110
Tomas Winklerc33104f2008-01-14 17:46:21 -08002111 lq_sta = kzalloc(sizeof(struct iwl4965_lq_sta), gfp);
Zhu Yib481de92007-09-25 17:54:57 -07002112
Tomas Winklerc33104f2008-01-14 17:46:21 -08002113 if (lq_sta == NULL)
Zhu Yib481de92007-09-25 17:54:57 -07002114 return NULL;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002115 lq_sta->lq.sta_id = 0xff;
Zhu Yib481de92007-09-25 17:54:57 -07002116
Zhu Yi63fddb92007-09-27 11:27:36 +08002117
Zhu Yib481de92007-09-25 17:54:57 -07002118 for (j = 0; j < LQ_SIZE; j++)
2119 for (i = 0; i < IWL_RATE_COUNT; i++)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002120 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
Zhu Yib481de92007-09-25 17:54:57 -07002121
Tomas Winklerc33104f2008-01-14 17:46:21 -08002122 return lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002123}
2124
2125static void rs_rate_init(void *priv_rate, void *priv_sta,
2126 struct ieee80211_local *local,
2127 struct sta_info *sta)
2128{
2129 int i, j;
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002130 struct ieee80211_conf *conf = &local->hw.conf;
Zhu Yib481de92007-09-25 17:54:57 -07002131 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002132 struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002133 struct iwl4965_lq_sta *lq_sta = priv_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002134
Tomas Winklerc33104f2008-01-14 17:46:21 -08002135 lq_sta->flush_timer = 0;
2136 lq_sta->supp_rates = sta->supp_rates;
Zhu Yib481de92007-09-25 17:54:57 -07002137 sta->txrate = 3;
2138 for (j = 0; j < LQ_SIZE; j++)
2139 for (i = 0; i < IWL_RATE_COUNT; i++)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002140 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
Zhu Yib481de92007-09-25 17:54:57 -07002141
2142 IWL_DEBUG_RATE("rate scale global init\n");
2143 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2144 * the lowest or the highest rate.. Could consider using RSSI from
2145 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2146 * after assoc.. */
2147
Tomas Winklerc33104f2008-01-14 17:46:21 -08002148 lq_sta->ibss_sta_added = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002149 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002150 u8 sta_id = iwl4965_hw_find_station(priv, sta->addr);
Joe Perches0795af52007-10-03 17:59:30 -07002151 DECLARE_MAC_BUF(mac);
2152
Zhu Yib481de92007-09-25 17:54:57 -07002153 /* for IBSS the call are from tasklet */
Joe Perches0795af52007-10-03 17:59:30 -07002154 IWL_DEBUG_HT("LQ: ADD station %s\n",
2155 print_mac(mac, sta->addr));
Zhu Yib481de92007-09-25 17:54:57 -07002156
2157 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07002158 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2159 print_mac(mac, sta->addr));
Ron Rindjunsky67d62032007-11-26 16:14:40 +02002160 sta_id = iwl4965_add_station_flags(priv, sta->addr,
2161 0, CMD_ASYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07002162 }
2163 if ((sta_id != IWL_INVALID_STATION)) {
Tomas Winklerc33104f2008-01-14 17:46:21 -08002164 lq_sta->lq.sta_id = sta_id;
2165 lq_sta->lq.rs_table[0].rate_n_flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002166 }
2167 /* FIXME: this is w/a remove it later */
2168 priv->assoc_station_added = 1;
2169 }
2170
Ben Cahill77626352007-11-29 11:09:44 +08002171 /* Find highest tx rate supported by hardware and destination station */
Zhu Yib481de92007-09-25 17:54:57 -07002172 for (i = 0; i < mode->num_rates; i++) {
2173 if ((sta->supp_rates & BIT(i)) &&
2174 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))
2175 sta->txrate = i;
2176 }
2177 sta->last_txrate = sta->txrate;
Ben Cahill77626352007-11-29 11:09:44 +08002178 /* For MODE_IEEE80211A, cck rates are at end of rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002179 if (local->hw.conf.phymode == MODE_IEEE80211A)
2180 sta->last_txrate += IWL_FIRST_OFDM_RATE;
2181
Tomas Winklerc33104f2008-01-14 17:46:21 -08002182 lq_sta->is_dup = 0;
2183 lq_sta->valid_antenna = priv->valid_antenna;
2184 lq_sta->antenna = priv->antenna;
2185 lq_sta->is_green = rs_use_green(priv, conf);
2186 lq_sta->active_rate = priv->active_rate;
2187 lq_sta->active_rate &= ~(0x1000);
2188 lq_sta->active_rate_basic = priv->active_rate_basic;
2189 lq_sta->phymode = priv->phymode;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002190#ifdef CONFIG_IWL4965_HT
Ben Cahill77626352007-11-29 11:09:44 +08002191 /*
2192 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2193 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2194 */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002195 lq_sta->active_siso_rate = (priv->current_ht_config.supp_mcs_set[0] << 1);
2196 lq_sta->active_siso_rate |=
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002197 (priv->current_ht_config.supp_mcs_set[0] & 0x1);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002198 lq_sta->active_siso_rate &= ~((u16)0x2);
2199 lq_sta->active_siso_rate =
2200 lq_sta->active_siso_rate << IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07002201
Ben Cahill77626352007-11-29 11:09:44 +08002202 /* Same here */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002203 lq_sta->active_mimo_rate = (priv->current_ht_config.supp_mcs_set[1] << 1);
2204 lq_sta->active_mimo_rate |=
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002205 (priv->current_ht_config.supp_mcs_set[1] & 0x1);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002206 lq_sta->active_mimo_rate &= ~((u16)0x2);
2207 lq_sta->active_mimo_rate =
2208 lq_sta->active_mimo_rate << IWL_FIRST_OFDM_RATE;
2209 IWL_DEBUG_HT("SISO RATE 0x%X MIMO RATE 0x%X\n",
2210 lq_sta->active_siso_rate,
2211 lq_sta->active_mimo_rate);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002212#endif /*CONFIG_IWL4965_HT*/
Zhu Yi98d7e092007-09-27 11:27:42 +08002213#ifdef CONFIG_MAC80211_DEBUGFS
Tomas Winklerc33104f2008-01-14 17:46:21 -08002214 lq_sta->drv = priv;
Zhu Yi98d7e092007-09-27 11:27:42 +08002215#endif
Zhu Yib481de92007-09-25 17:54:57 -07002216
2217 if (priv->assoc_station_added)
2218 priv->lq_mngr.lq_ready = 1;
2219
Ron Rindjunsky270243a2007-11-26 16:14:41 +02002220 rs_initialize_lq(priv, conf, sta);
Zhu Yib481de92007-09-25 17:54:57 -07002221}
2222
Tomas Winklerc33104f2008-01-14 17:46:21 -08002223static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002224 struct iwl4965_rate *tx_mcs,
2225 struct iwl4965_link_quality_cmd *lq_cmd)
Zhu Yib481de92007-09-25 17:54:57 -07002226{
2227 int index = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002228 int rate_idx;
Zhu Yi1b696de2007-09-27 11:27:41 +08002229 int repeat_rate = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002230 u8 ant_toggle_count = 0;
2231 u8 use_ht_possible = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002232 struct iwl4965_rate new_rate;
2233 struct iwl4965_scale_tbl_info tbl_type = { 0 };
Zhu Yib481de92007-09-25 17:54:57 -07002234
Ben Cahill77626352007-11-29 11:09:44 +08002235 /* Override starting rate (index 0) if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002236 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index);
Zhu Yi98d7e092007-09-27 11:27:42 +08002237
Ben Cahill77626352007-11-29 11:09:44 +08002238 /* Interpret rate_n_flags */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002239 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->phymode,
Zhu Yib481de92007-09-25 17:54:57 -07002240 &tbl_type, &rate_idx);
2241
Ben Cahill77626352007-11-29 11:09:44 +08002242 /* How many times should we repeat the initial rate? */
Zhu Yib481de92007-09-25 17:54:57 -07002243 if (is_legacy(tbl_type.lq_type)) {
2244 ant_toggle_count = 1;
Zhu Yi1b696de2007-09-27 11:27:41 +08002245 repeat_rate = IWL_NUMBER_TRY;
Zhu Yib481de92007-09-25 17:54:57 -07002246 } else
Zhu Yi1b696de2007-09-27 11:27:41 +08002247 repeat_rate = IWL_HT_NUMBER_TRY;
Zhu Yib481de92007-09-25 17:54:57 -07002248
2249 lq_cmd->general_params.mimo_delimiter =
2250 is_mimo(tbl_type.lq_type) ? 1 : 0;
Ben Cahill77626352007-11-29 11:09:44 +08002251
2252 /* Fill 1st table entry (index 0) */
Zhu Yib481de92007-09-25 17:54:57 -07002253 lq_cmd->rs_table[index].rate_n_flags =
2254 cpu_to_le32(tx_mcs->rate_n_flags);
2255 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
2256
2257 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))
Ben Cahill77626352007-11-29 11:09:44 +08002258 lq_cmd->general_params.single_stream_ant_msk
2259 = LINK_QUAL_ANT_A_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002260 else
Ben Cahill77626352007-11-29 11:09:44 +08002261 lq_cmd->general_params.single_stream_ant_msk
2262 = LINK_QUAL_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002263
2264 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08002265 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07002266
Ben Cahill77626352007-11-29 11:09:44 +08002267 /* Fill rest of rate table */
Zhu Yib481de92007-09-25 17:54:57 -07002268 while (index < LINK_QUAL_MAX_RETRY_NUM) {
Ben Cahill77626352007-11-29 11:09:44 +08002269 /* Repeat initial/next rate.
2270 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2271 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
Zhu Yi1b696de2007-09-27 11:27:41 +08002272 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
Zhu Yib481de92007-09-25 17:54:57 -07002273 if (is_legacy(tbl_type.lq_type)) {
2274 if (ant_toggle_count <
2275 NUM_TRY_BEFORE_ANTENNA_TOGGLE)
2276 ant_toggle_count++;
2277 else {
2278 rs_toggle_antenna(&new_rate, &tbl_type);
2279 ant_toggle_count = 1;
2280 }
2281 }
Zhu Yi98d7e092007-09-27 11:27:42 +08002282
Ben Cahill77626352007-11-29 11:09:44 +08002283 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002284 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08002285
2286 /* Fill next table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002287 lq_cmd->rs_table[index].rate_n_flags =
2288 cpu_to_le32(new_rate.rate_n_flags);
Zhu Yi1b696de2007-09-27 11:27:41 +08002289 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07002290 index++;
2291 }
2292
Tomas Winklerc33104f2008-01-14 17:46:21 -08002293 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->phymode, &tbl_type,
Zhu Yib481de92007-09-25 17:54:57 -07002294 &rate_idx);
2295
Ben Cahill77626352007-11-29 11:09:44 +08002296 /* Indicate to uCode which entries might be MIMO.
2297 * If initial rate was MIMO, this will finally end up
2298 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
Zhu Yib481de92007-09-25 17:54:57 -07002299 if (is_mimo(tbl_type.lq_type))
2300 lq_cmd->general_params.mimo_delimiter = index;
2301
Ben Cahill77626352007-11-29 11:09:44 +08002302 /* Get next rate */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002303 rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
Zhu Yi02dede02007-09-27 11:27:40 +08002304 use_ht_possible, &new_rate);
Zhu Yib481de92007-09-25 17:54:57 -07002305
Ben Cahill77626352007-11-29 11:09:44 +08002306 /* How many times should we repeat the next rate? */
Zhu Yib481de92007-09-25 17:54:57 -07002307 if (is_legacy(tbl_type.lq_type)) {
2308 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
2309 ant_toggle_count++;
2310 else {
2311 rs_toggle_antenna(&new_rate, &tbl_type);
2312 ant_toggle_count = 1;
2313 }
Zhu Yi1b696de2007-09-27 11:27:41 +08002314 repeat_rate = IWL_NUMBER_TRY;
Zhu Yib481de92007-09-25 17:54:57 -07002315 } else
Zhu Yi1b696de2007-09-27 11:27:41 +08002316 repeat_rate = IWL_HT_NUMBER_TRY;
Zhu Yib481de92007-09-25 17:54:57 -07002317
Ben Cahill77626352007-11-29 11:09:44 +08002318 /* Don't allow HT rates after next pass.
2319 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
Zhu Yib481de92007-09-25 17:54:57 -07002320 use_ht_possible = 0;
2321
Ben Cahill77626352007-11-29 11:09:44 +08002322 /* Override next rate if needed for debug purposes */
Tomas Winklerc33104f2008-01-14 17:46:21 -08002323 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
Ben Cahill77626352007-11-29 11:09:44 +08002324
2325 /* Fill next table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002326 lq_cmd->rs_table[index].rate_n_flags =
2327 cpu_to_le32(new_rate.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07002328
2329 index++;
Zhu Yi1b696de2007-09-27 11:27:41 +08002330 repeat_rate--;
Zhu Yib481de92007-09-25 17:54:57 -07002331 }
2332
Zhu Yib481de92007-09-25 17:54:57 -07002333 lq_cmd->general_params.dual_stream_ant_msk = 3;
2334 lq_cmd->agg_params.agg_dis_start_th = 3;
2335 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
Zhu Yib481de92007-09-25 17:54:57 -07002336}
2337
2338static void *rs_alloc(struct ieee80211_local *local)
2339{
2340 return local->hw.priv;
2341}
2342/* rate scale requires free function to be implemented */
2343static void rs_free(void *priv_rate)
2344{
2345 return;
2346}
2347
2348static void rs_clear(void *priv_rate)
2349{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002350 struct iwl4965_priv *priv = (struct iwl4965_priv *) priv_rate;
Zhu Yib481de92007-09-25 17:54:57 -07002351
2352 IWL_DEBUG_RATE("enter\n");
2353
2354 priv->lq_mngr.lq_ready = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002355#ifdef CONFIG_IWL4965_HT
2356#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07002357 if (priv->lq_mngr.agg_ctrl.granted_ba)
2358 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002359#endif /*CONFIG_IWL4965_HT_AGG */
2360#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07002361
2362 IWL_DEBUG_RATE("leave\n");
2363}
2364
2365static void rs_free_sta(void *priv, void *priv_sta)
2366{
Tomas Winklerc33104f2008-01-14 17:46:21 -08002367 struct iwl4965_lq_sta *lq_sta = priv_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002368
2369 IWL_DEBUG_RATE("enter\n");
Tomas Winklerc33104f2008-01-14 17:46:21 -08002370 kfree(lq_sta);
Zhu Yib481de92007-09-25 17:54:57 -07002371 IWL_DEBUG_RATE("leave\n");
2372}
2373
2374
Zhu Yi93dc6462007-09-27 11:27:37 +08002375#ifdef CONFIG_MAC80211_DEBUGFS
Zhu Yi5ae212c2007-09-27 11:27:38 +08002376static int open_file_generic(struct inode *inode, struct file *file)
2377{
2378 file->private_data = inode->i_private;
2379 return 0;
2380}
Tomas Winklerc33104f2008-01-14 17:46:21 -08002381static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002382 struct iwl4965_rate *mcs, int index)
Zhu Yi98d7e092007-09-27 11:27:42 +08002383{
Ron Rindjunsky4457e1a2007-10-15 14:40:56 +02002384 u32 base_rate;
2385
Tomas Winklerc33104f2008-01-14 17:46:21 -08002386 if (lq_sta->phymode == (u8) MODE_IEEE80211A)
Ron Rindjunsky4457e1a2007-10-15 14:40:56 +02002387 base_rate = 0x800D;
2388 else
2389 base_rate = 0x820A;
2390
Tomas Winklerc33104f2008-01-14 17:46:21 -08002391 if (lq_sta->dbg_fixed.rate_n_flags) {
Zhu Yi98d7e092007-09-27 11:27:42 +08002392 if (index < 12)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002393 mcs->rate_n_flags = lq_sta->dbg_fixed.rate_n_flags;
Zhu Yi98d7e092007-09-27 11:27:42 +08002394 else
Ron Rindjunsky4457e1a2007-10-15 14:40:56 +02002395 mcs->rate_n_flags = base_rate;
Zhu Yi98d7e092007-09-27 11:27:42 +08002396 IWL_DEBUG_RATE("Fixed rate ON\n");
2397 return;
2398 }
Zhu Yi5ae212c2007-09-27 11:27:38 +08002399
Zhu Yi98d7e092007-09-27 11:27:42 +08002400 IWL_DEBUG_RATE("Fixed rate OFF\n");
2401}
2402
2403static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2404 const char __user *user_buf, size_t count, loff_t *ppos)
2405{
Tomas Winklerc33104f2008-01-14 17:46:21 -08002406 struct iwl4965_lq_sta *lq_sta = file->private_data;
Zhu Yi98d7e092007-09-27 11:27:42 +08002407 char buf[64];
2408 int buf_size;
2409 u32 parsed_rate;
2410
2411 memset(buf, 0, sizeof(buf));
2412 buf_size = min(count, sizeof(buf) - 1);
2413 if (copy_from_user(buf, user_buf, buf_size))
2414 return -EFAULT;
2415
2416 if (sscanf(buf, "%x", &parsed_rate) == 1)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002417 lq_sta->dbg_fixed.rate_n_flags = parsed_rate;
Zhu Yi98d7e092007-09-27 11:27:42 +08002418 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002419 lq_sta->dbg_fixed.rate_n_flags = 0;
Zhu Yi98d7e092007-09-27 11:27:42 +08002420
Tomas Winklerc33104f2008-01-14 17:46:21 -08002421 lq_sta->active_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2422 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2423 lq_sta->active_mimo_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
Zhu Yi98d7e092007-09-27 11:27:42 +08002424
2425 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002426 lq_sta->lq.sta_id, lq_sta->dbg_fixed.rate_n_flags);
Zhu Yi98d7e092007-09-27 11:27:42 +08002427
Tomas Winklerc33104f2008-01-14 17:46:21 -08002428 if (lq_sta->dbg_fixed.rate_n_flags) {
2429 rs_fill_link_cmd(lq_sta, &lq_sta->dbg_fixed, &lq_sta->lq);
2430 rs_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC);
Zhu Yi98d7e092007-09-27 11:27:42 +08002431 }
2432
2433 return count;
2434}
Zhu Yi0209dc12007-09-27 11:27:43 +08002435
Zhu Yi5ae212c2007-09-27 11:27:38 +08002436static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2437 char __user *user_buf, size_t count, loff_t *ppos)
2438{
2439 char buff[1024];
2440 int desc = 0;
2441 int i = 0;
2442
Tomas Winklerc33104f2008-01-14 17:46:21 -08002443 struct iwl4965_lq_sta *lq_sta = file->private_data;
Zhu Yi5ae212c2007-09-27 11:27:38 +08002444
Tomas Winklerc33104f2008-01-14 17:46:21 -08002445 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
Zhu Yi98d7e092007-09-27 11:27:42 +08002446 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002447 lq_sta->total_failed, lq_sta->total_success,
2448 lq_sta->active_rate);
Zhu Yi98d7e092007-09-27 11:27:42 +08002449 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002450 lq_sta->dbg_fixed.rate_n_flags);
Zhu Yi5ae212c2007-09-27 11:27:38 +08002451 desc += sprintf(buff+desc, "general:"
2452 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002453 lq_sta->lq.general_params.flags,
2454 lq_sta->lq.general_params.mimo_delimiter,
2455 lq_sta->lq.general_params.single_stream_ant_msk,
2456 lq_sta->lq.general_params.dual_stream_ant_msk);
Zhu Yi5ae212c2007-09-27 11:27:38 +08002457
2458 desc += sprintf(buff+desc, "agg:"
2459 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002460 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
2461 lq_sta->lq.agg_params.agg_dis_start_th,
2462 lq_sta->lq.agg_params.agg_frame_cnt_limit);
Zhu Yi5ae212c2007-09-27 11:27:38 +08002463
2464 desc += sprintf(buff+desc,
2465 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002466 lq_sta->lq.general_params.start_rate_index[0],
2467 lq_sta->lq.general_params.start_rate_index[1],
2468 lq_sta->lq.general_params.start_rate_index[2],
2469 lq_sta->lq.general_params.start_rate_index[3]);
Zhu Yi5ae212c2007-09-27 11:27:38 +08002470
2471
2472 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
2473 desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002474 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
Zhu Yi5ae212c2007-09-27 11:27:38 +08002475
2476 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2477}
2478
2479static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
Zhu Yi98d7e092007-09-27 11:27:42 +08002480 .write = rs_sta_dbgfs_scale_table_write,
Zhu Yi5ae212c2007-09-27 11:27:38 +08002481 .read = rs_sta_dbgfs_scale_table_read,
2482 .open = open_file_generic,
2483};
Zhu Yi0209dc12007-09-27 11:27:43 +08002484static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2485 char __user *user_buf, size_t count, loff_t *ppos)
2486{
2487 char buff[1024];
2488 int desc = 0;
2489 int i, j;
2490
Tomas Winklerc33104f2008-01-14 17:46:21 -08002491 struct iwl4965_lq_sta *lq_sta = file->private_data;
Zhu Yi0209dc12007-09-27 11:27:43 +08002492 for (i = 0; i < LQ_SIZE; i++) {
2493 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2494 "rate=0x%X\n",
Tomas Winklerc33104f2008-01-14 17:46:21 -08002495 lq_sta->active_tbl == i?"*":"x",
2496 lq_sta->lq_info[i].lq_type,
2497 lq_sta->lq_info[i].is_SGI,
2498 lq_sta->lq_info[i].is_fat,
2499 lq_sta->lq_info[i].is_dup,
2500 lq_sta->lq_info[i].current_rate.rate_n_flags);
Zhu Yi0209dc12007-09-27 11:27:43 +08002501 for (j = 0; j < IWL_RATE_COUNT; j++) {
2502 desc += sprintf(buff+desc,
Tomas Winklerc33104f2008-01-14 17:46:21 -08002503 "counter=%d success=%d %%=%d\n",
2504 lq_sta->lq_info[i].win[j].counter,
2505 lq_sta->lq_info[i].win[j].success_counter,
2506 lq_sta->lq_info[i].win[j].success_ratio);
Zhu Yi0209dc12007-09-27 11:27:43 +08002507 }
2508 }
2509 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2510}
2511
2512static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2513 .read = rs_sta_dbgfs_stats_table_read,
2514 .open = open_file_generic,
2515};
Zhu Yi5ae212c2007-09-27 11:27:38 +08002516
Zhu Yi93dc6462007-09-27 11:27:37 +08002517static void rs_add_debugfs(void *priv, void *priv_sta,
2518 struct dentry *dir)
2519{
Tomas Winklerc33104f2008-01-14 17:46:21 -08002520 struct iwl4965_lq_sta *lq_sta = priv_sta;
2521 lq_sta->rs_sta_dbgfs_scale_table_file =
Zhu Yi0209dc12007-09-27 11:27:43 +08002522 debugfs_create_file("rate_scale_table", 0600, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08002523 lq_sta, &rs_sta_dbgfs_scale_table_ops);
2524 lq_sta->rs_sta_dbgfs_stats_table_file =
Zhu Yi0209dc12007-09-27 11:27:43 +08002525 debugfs_create_file("rate_stats_table", 0600, dir,
Tomas Winklerc33104f2008-01-14 17:46:21 -08002526 lq_sta, &rs_sta_dbgfs_stats_table_ops);
Zhu Yi93dc6462007-09-27 11:27:37 +08002527}
2528
2529static void rs_remove_debugfs(void *priv, void *priv_sta)
2530{
Tomas Winklerc33104f2008-01-14 17:46:21 -08002531 struct iwl4965_lq_sta *lq_sta = priv_sta;
2532 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2533 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
Zhu Yi93dc6462007-09-27 11:27:37 +08002534}
2535#endif
2536
Zhu Yib481de92007-09-25 17:54:57 -07002537static struct rate_control_ops rs_ops = {
2538 .module = NULL,
2539 .name = RS_NAME,
2540 .tx_status = rs_tx_status,
2541 .get_rate = rs_get_rate,
2542 .rate_init = rs_rate_init,
2543 .clear = rs_clear,
2544 .alloc = rs_alloc,
2545 .free = rs_free,
2546 .alloc_sta = rs_alloc_sta,
2547 .free_sta = rs_free_sta,
Zhu Yi93dc6462007-09-27 11:27:37 +08002548#ifdef CONFIG_MAC80211_DEBUGFS
2549 .add_sta_debugfs = rs_add_debugfs,
2550 .remove_sta_debugfs = rs_remove_debugfs,
2551#endif
Zhu Yib481de92007-09-25 17:54:57 -07002552};
2553
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002554int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002555{
2556 struct ieee80211_local *local = hw_to_local(hw);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002557 struct iwl4965_priv *priv = hw->priv;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002558 struct iwl4965_lq_sta *lq_sta;
Zhu Yib481de92007-09-25 17:54:57 -07002559 struct sta_info *sta;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002560 int cnt = 0, i;
Zhu Yib481de92007-09-25 17:54:57 -07002561 u32 samples = 0, success = 0, good = 0;
2562 unsigned long now = jiffies;
2563 u32 max_time = 0;
2564 u8 lq_type, antenna;
2565
2566 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2567 if (!sta || !sta->rate_ctrl_priv) {
2568 if (sta) {
2569 sta_info_put(sta);
2570 IWL_DEBUG_RATE("leave - no private rate data!\n");
2571 } else
2572 IWL_DEBUG_RATE("leave - no station!\n");
2573 return sprintf(buf, "station %d not found\n", sta_id);
2574 }
2575
Tomas Winklerc33104f2008-01-14 17:46:21 -08002576 lq_sta = (void *)sta->rate_ctrl_priv;
Zhu Yib481de92007-09-25 17:54:57 -07002577
Tomas Winklerc33104f2008-01-14 17:46:21 -08002578 lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type;
2579 antenna = lq_sta->lq_info[lq_sta->active_tbl].antenna_type;
Zhu Yib481de92007-09-25 17:54:57 -07002580
2581 if (is_legacy(lq_type))
2582 i = IWL_RATE_54M_INDEX;
2583 else
2584 i = IWL_RATE_60M_INDEX;
2585 while (1) {
2586 u64 mask;
2587 int j;
Tomas Winklerc33104f2008-01-14 17:46:21 -08002588 int active = lq_sta->active_tbl;
Zhu Yib481de92007-09-25 17:54:57 -07002589
Tomas Winklerc33104f2008-01-14 17:46:21 -08002590 cnt +=
2591 sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2);
Zhu Yib481de92007-09-25 17:54:57 -07002592
2593 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2594 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002595 buf[cnt++] =
2596 (lq_sta->lq_info[active].win[i].data & mask)
Zhu Yib481de92007-09-25 17:54:57 -07002597 ? '1' : '0';
2598
Tomas Winklerc33104f2008-01-14 17:46:21 -08002599 samples += lq_sta->lq_info[active].win[i].counter;
2600 good += lq_sta->lq_info[active].win[i].success_counter;
2601 success += lq_sta->lq_info[active].win[i].success_counter *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002602 iwl4965_rates[i].ieee;
Zhu Yib481de92007-09-25 17:54:57 -07002603
Tomas Winklerc33104f2008-01-14 17:46:21 -08002604 if (lq_sta->lq_info[active].win[i].stamp) {
Zhu Yib481de92007-09-25 17:54:57 -07002605 int delta =
2606 jiffies_to_msecs(now -
Tomas Winklerc33104f2008-01-14 17:46:21 -08002607 lq_sta->lq_info[active].win[i].stamp);
Zhu Yib481de92007-09-25 17:54:57 -07002608
2609 if (delta > max_time)
2610 max_time = delta;
2611
Tomas Winklerc33104f2008-01-14 17:46:21 -08002612 cnt += sprintf(&buf[cnt], "%5dms\n", delta);
Zhu Yib481de92007-09-25 17:54:57 -07002613 } else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002614 buf[cnt++] = '\n';
Zhu Yib481de92007-09-25 17:54:57 -07002615
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002616 j = iwl4965_get_prev_ieee_rate(i);
Zhu Yib481de92007-09-25 17:54:57 -07002617 if (j == i)
2618 break;
2619 i = j;
2620 }
2621
2622 /* Display the average rate of all samples taken.
2623 *
Ben Cahill77626352007-11-29 11:09:44 +08002624 * NOTE: We multiply # of samples by 2 since the IEEE measurement
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002625 * added from iwl4965_rates is actually 2X the rate */
Zhu Yib481de92007-09-25 17:54:57 -07002626 if (samples)
Tomas Winklerc33104f2008-01-14 17:46:21 -08002627 cnt += sprintf(&buf[cnt],
Zhu Yib481de92007-09-25 17:54:57 -07002628 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2629 "%3d%% success (%d good packets over %d tries)\n",
2630 success / (2 * samples), (success * 5 / samples) % 10,
2631 max_time, good * 100 / samples, good, samples);
2632 else
Tomas Winklerc33104f2008-01-14 17:46:21 -08002633 cnt += sprintf(&buf[cnt], "\nAverage rate: 0Mbs\n");
2634
2635 cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d "
Zhu Yib481de92007-09-25 17:54:57 -07002636 "active_search %d rate index %d\n", lq_type, antenna,
Tomas Winklerc33104f2008-01-14 17:46:21 -08002637 lq_sta->search_better_tbl, sta->last_txrate);
Zhu Yib481de92007-09-25 17:54:57 -07002638
2639 sta_info_put(sta);
Tomas Winklerc33104f2008-01-14 17:46:21 -08002640 return cnt;
Zhu Yib481de92007-09-25 17:54:57 -07002641}
2642
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002643void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002644{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002645 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002646
2647 priv->lq_mngr.lq_ready = 1;
2648}
2649
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002650void iwl4965_rate_control_register(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002651{
2652 ieee80211_rate_control_register(&rs_ops);
2653}
2654
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002655void iwl4965_rate_control_unregister(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002656{
2657 ieee80211_rate_control_unregister(&rs_ops);
2658}
2659