1 /******************************************************************************
3 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
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
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>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/delay.h>
36 #include <linux/workqueue.h>
38 #include "../net/mac80211/rate.h"
42 #include "iwl-helpers.h"
44 #define RS_NAME "iwl-4965-rs"
46 #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
47 #define IWL_NUMBER_TRY 1
48 #define IWL_HT_NUMBER_TRY 3
50 #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 */
54 /* max time to accum history 2 seconds */
55 #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ)
57 static u8 rs_ht_to_legacy[] = {
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
59 IWL_RATE_6M_INDEX, 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
69 } __attribute__ ((packed));
72 * struct iwl4965_rate_scale_data -- tx success history for one rate
74 struct iwl4965_rate_scale_data {
75 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 */
84 * struct iwl4965_scale_tbl_info -- tx params and success history for all rates
86 * There are two of these in struct iwl4965_lq_sta,
87 * one for "active", and one for "search".
89 struct iwl4965_scale_tbl_info {
90 enum iwl_table_type lq_type;
92 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 */
101 #ifdef CONFIG_IWL4965_HT
103 struct iwl4965_traffic_load {
104 unsigned long time_stamp; /* age of the oldest statistics */
105 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time
107 u32 total; /* total num of packets during the
108 * last TID_MAX_TIME_DIFF */
109 u8 queue_count; /* number of queues that has
110 * been used since the last cleanup */
111 u8 head; /* start of the circular buffer */
114 #endif /* CONFIG_IWL4965_HT */
117 * struct iwl4965_lq_sta -- driver's rate scaling private structure
119 * Pointer to this gets passed back and forth between driver and mac80211.
121 struct iwl4965_lq_sta {
122 u8 active_tbl; /* index of active table, range 0-1 */
123 u8 enable_counter; /* indicates HT mode */
124 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
125 u8 search_better_tbl; /* 1: currently trying alternate mode */
128 /* The following determine when to search for a new mode */
129 u32 table_count_limit;
130 u32 max_failure_limit; /* # failed frames before new search */
131 u32 max_success_limit; /* # successful frames before new search */
133 u32 total_failed; /* total failed frames, any/all rates */
134 u32 total_success; /* total successful frames, any/all rates */
135 u32 flush_timer; /* time staying in mode before new search */
137 u8 action_counter; /* # mode-switch actions tried */
142 enum ieee80211_band band;
145 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
148 u16 active_siso_rate;
149 u16 active_mimo2_rate;
150 u16 active_mimo3_rate;
151 u16 active_rate_basic;
153 struct iwl_link_quality_cmd lq;
154 struct iwl4965_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
155 #ifdef CONFIG_IWL4965_HT
156 struct iwl4965_traffic_load load[TID_MAX_LOAD_COUNT];
159 #ifdef CONFIG_MAC80211_DEBUGFS
160 struct dentry *rs_sta_dbgfs_scale_table_file;
161 struct dentry *rs_sta_dbgfs_stats_table_file;
162 #ifdef CONFIG_IWL4965_HT
163 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
165 struct iwl4965_rate dbg_fixed;
166 struct iwl_priv *drv;
170 static void rs_rate_scale_perform(struct iwl_priv *priv,
171 struct net_device *dev,
172 struct ieee80211_hdr *hdr,
173 struct sta_info *sta);
174 static void rs_fill_link_cmd(const struct iwl_priv *priv,
175 struct iwl4965_lq_sta *lq_sta,
176 struct iwl4965_rate *tx_mcs,
177 struct iwl_link_quality_cmd *tbl);
180 #ifdef CONFIG_MAC80211_DEBUGFS
181 static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
182 struct iwl4965_rate *mcs, int index);
184 static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
185 struct iwl4965_rate *mcs, int index)
190 * Expected throughput metrics for following rates:
191 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
192 * "G" is the only table that supports CCK (the first 4 rates).
194 /*FIXME:RS:need to spearate tables for MIMO2/MIMO3*/
195 static s32 expected_tpt_A[IWL_RATE_COUNT] = {
196 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
199 static s32 expected_tpt_G[IWL_RATE_COUNT] = {
200 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
203 static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = {
204 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
207 static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
208 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
211 static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = {
212 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
215 static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = {
216 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
219 static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = {
220 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
223 static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
224 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
227 static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = {
228 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
231 static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
232 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
235 static inline u8 iwl4965_rate_get_rate(u32 rate_n_flags)
237 return (u8)(rate_n_flags & 0xFF);
240 static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window)
243 window->success_counter = 0;
244 window->success_ratio = IWL_INVALID_VALUE;
246 window->average_tpt = IWL_INVALID_VALUE;
250 #ifdef CONFIG_IWL4965_HT
252 * removes the old data from the statistics. All data that is older than
253 * TID_MAX_TIME_DIFF, will be deleted.
255 static void rs_tl_rm_old_stats(struct iwl4965_traffic_load *tl, u32 curr_time)
257 /* The oldest age we want to keep */
258 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
260 while (tl->queue_count &&
261 (tl->time_stamp < oldest_time)) {
262 tl->total -= tl->packet_count[tl->head];
263 tl->packet_count[tl->head] = 0;
264 tl->time_stamp += TID_QUEUE_CELL_SPACING;
267 if (tl->head >= TID_QUEUE_MAX_SIZE)
273 * increment traffic load value for tid and also remove
274 * any old values if passed the certain time period
276 static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid)
278 u32 curr_time = jiffies_to_msecs(jiffies);
281 struct iwl4965_traffic_load *tl = NULL;
283 if (tid >= TID_MAX_LOAD_COUNT)
286 tl = &lq_data->load[tid];
288 curr_time -= curr_time % TID_ROUND_VALUE;
290 /* Happens only for the first packet. Initialize the data */
291 if (!(tl->queue_count)) {
293 tl->time_stamp = curr_time;
296 tl->packet_count[0] = 1;
300 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
301 index = time_diff / TID_QUEUE_CELL_SPACING;
303 /* The history is too long: remove data that is older than */
304 /* TID_MAX_TIME_DIFF */
305 if (index >= TID_QUEUE_MAX_SIZE)
306 rs_tl_rm_old_stats(tl, curr_time);
308 index = (tl->head + index) % TID_QUEUE_MAX_SIZE;
309 tl->packet_count[index] = tl->packet_count[index] + 1;
310 tl->total = tl->total + 1;
312 if ((index + 1) > tl->queue_count)
313 tl->queue_count = index + 1;
317 get the traffic load value for tid
319 static u32 rs_tl_get_load(struct iwl4965_lq_sta *lq_data, u8 tid)
321 u32 curr_time = jiffies_to_msecs(jiffies);
324 struct iwl4965_traffic_load *tl = NULL;
326 if (tid >= TID_MAX_LOAD_COUNT)
329 tl = &(lq_data->load[tid]);
331 curr_time -= curr_time % TID_ROUND_VALUE;
333 if (!(tl->queue_count))
336 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
337 index = time_diff / TID_QUEUE_CELL_SPACING;
339 /* The history is too long: remove data that is older than */
340 /* TID_MAX_TIME_DIFF */
341 if (index >= TID_QUEUE_MAX_SIZE)
342 rs_tl_rm_old_stats(tl, curr_time);
347 static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
348 struct iwl4965_lq_sta *lq_data, u8 tid,
349 struct sta_info *sta)
352 DECLARE_MAC_BUF(mac);
354 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
355 state = sta->ampdu_mlme.tid_state_tx[tid];
356 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
358 if (state == HT_AGG_STATE_IDLE &&
359 rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) {
360 IWL_DEBUG_HT("Starting Tx agg: STA: %s tid: %d\n",
361 print_mac(mac, sta->addr), tid);
362 ieee80211_start_tx_ba_session(priv->hw, sta->addr, tid);
366 static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
367 struct iwl4965_lq_sta *lq_data,
368 struct sta_info *sta)
370 if ((tid < TID_MAX_LOAD_COUNT))
371 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
372 else if (tid == IWL_AGG_ALL_TID)
373 for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++)
374 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
377 #endif /* CONFIG_IWLWIFI_HT */
379 static inline int get_num_of_ant_from_mcs(u32 mcs)
381 return (!!(mcs & RATE_MCS_ANT_A_MSK) +
382 !!(mcs & RATE_MCS_ANT_B_MSK) +
383 !!(mcs & RATE_MCS_ANT_C_MSK));
387 * rs_collect_tx_data - Update the success/failure sliding window
389 * We keep a sliding window of the last 62 packets transmitted
390 * at this rate. window->data contains the bitmask of successful
393 static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
394 int scale_index, s32 tpt, int retries,
397 struct iwl4965_rate_scale_data *window = NULL;
399 u8 win_size = IWL_RATE_MAX_WINDOW;
402 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
405 /* Select data for current tx bit rate */
406 window = &(windows[scale_index]);
409 * Keep track of only the latest 62 tx frame attempts in this rate's
410 * history window; anything older isn't really relevant any more.
411 * If we have filled up the sliding window, drop the oldest attempt;
412 * if the oldest attempt (highest bit in bitmap) shows "success",
413 * subtract "1" from the success counter (this is the main reason
414 * we keep these bitmaps!).
416 while (retries > 0) {
417 if (window->counter >= win_size) {
418 window->counter = win_size - 1;
420 mask = (mask << (win_size - 1));
421 if (window->data & mask) {
422 window->data &= ~mask;
423 window->success_counter =
424 window->success_counter - 1;
428 /* Increment frames-attempted counter */
431 /* Shift bitmap by one frame (throw away oldest history),
432 * OR in "1", and increment "success" if this
433 * frame was successful. */
435 window->data = (mask << 1);
437 window->success_counter = window->success_counter + 1;
445 /* Calculate current success ratio, avoid divide-by-0! */
446 if (window->counter > 0)
447 window->success_ratio = 128 * (100 * window->success_counter)
450 window->success_ratio = IWL_INVALID_VALUE;
452 fail_count = window->counter - window->success_counter;
454 /* Calculate average throughput, if we have enough history. */
455 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
456 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
457 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
459 window->average_tpt = IWL_INVALID_VALUE;
461 /* Tag this window as having been updated */
462 window->stamp = jiffies;
468 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
470 static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate,
471 struct iwl4965_scale_tbl_info *tbl,
472 int index, u8 use_green)
474 if (is_legacy(tbl->lq_type)) {
475 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp;
476 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
477 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
479 } else if (is_Ht(tbl->lq_type)) {
480 if (index > IWL_LAST_OFDM_RATE) {
481 IWL_ERROR("invalid HT rate index %d\n", index);
482 index = IWL_LAST_OFDM_RATE;
484 mcs_rate->rate_n_flags = RATE_MCS_HT_MSK;
486 if (is_siso(tbl->lq_type))
487 mcs_rate->rate_n_flags |=
488 iwl4965_rates[index].plcp_siso;
489 else if (is_mimo2(tbl->lq_type))
490 mcs_rate->rate_n_flags |=
491 iwl4965_rates[index].plcp_mimo2;
493 mcs_rate->rate_n_flags |=
494 iwl4965_rates[index].plcp_mimo3;
496 IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type);
499 mcs_rate->rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
500 RATE_MCS_ANT_ABC_MSK);
502 if (is_legacy(tbl->lq_type))
507 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
509 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
512 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
515 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
516 if (is_siso(tbl->lq_type))
517 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
522 * Interpret uCode API's rate_n_flags format,
523 * fill "search" or "active" tx mode table.
525 static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate,
526 enum ieee80211_band band,
527 struct iwl4965_scale_tbl_info *tbl,
530 u32 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_ABC_MSK);
531 u8 num_of_ant = get_num_of_ant_from_mcs(ant_msk);
533 *rate_idx = iwl4965_hwrate_to_plcp_idx(mcs_rate->rate_n_flags);
535 if (*rate_idx == IWL_RATE_INVALID) {
539 tbl->is_SGI = 0; /* default legacy setup */
542 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
543 tbl->lq_type = LQ_NONE;
545 /* legacy rate format */
546 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
547 if (num_of_ant == 1) {
548 if (band == IEEE80211_BAND_5GHZ)
555 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
558 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
559 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
562 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
566 if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags)
567 <= IWL_RATE_SISO_60M_PLCP) {
570 tbl->lq_type = LQ_SISO; /*else NONE*/
572 } else if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags)
573 <= IWL_RATE_MIMO2_60M_PLCP) {
575 tbl->lq_type = LQ_MIMO2;
579 tbl->lq_type = LQ_MIMO3;
584 /* FIXME:RS: need to toggle also ANT_C, and also AB,AC,BC */
585 static inline void rs_toggle_antenna(struct iwl4965_rate *new_rate,
586 struct iwl4965_scale_tbl_info *tbl)
588 tbl->ant_type ^= ANT_AB;
589 new_rate->rate_n_flags ^= (RATE_MCS_ANT_A_MSK|RATE_MCS_ANT_B_MSK);
592 static inline u8 rs_use_green(struct iwl_priv *priv,
593 struct ieee80211_conf *conf)
595 #ifdef CONFIG_IWL4965_HT
596 return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
597 priv->current_ht_config.is_green_field &&
598 !priv->current_ht_config.non_GF_STA_present);
599 #endif /* CONFIG_IWL4965_HT */
604 * rs_get_supported_rates - get the available rates
606 * if management frame or broadcast frame only return
607 * basic available rates.
610 static void rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta,
611 struct ieee80211_hdr *hdr,
612 enum iwl_table_type rate_type,
615 if (is_legacy(rate_type))
616 *data_rate = lq_sta->active_rate;
618 if (is_siso(rate_type))
619 *data_rate = lq_sta->active_siso_rate;
620 else if (is_mimo2(rate_type))
621 *data_rate = lq_sta->active_mimo2_rate;
623 *data_rate = lq_sta->active_mimo3_rate;
626 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
627 lq_sta->active_rate_basic) {
628 *data_rate = lq_sta->active_rate_basic;
632 static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
634 u8 high = IWL_RATE_INVALID;
635 u8 low = IWL_RATE_INVALID;
637 /* 802.11A or ht walks to the next literal adjacent rate in
639 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
643 /* Find the previous rate that is in the rate mask */
645 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
646 if (rate_mask & mask) {
652 /* Find the next rate that is in the rate mask */
654 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
655 if (rate_mask & mask) {
661 return (high << 8) | low;
665 while (low != IWL_RATE_INVALID) {
666 low = iwl4965_rates[low].prev_rs;
667 if (low == IWL_RATE_INVALID)
669 if (rate_mask & (1 << low))
671 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
675 while (high != IWL_RATE_INVALID) {
676 high = iwl4965_rates[high].next_rs;
677 if (high == IWL_RATE_INVALID)
679 if (rate_mask & (1 << high))
681 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
684 return (high << 8) | low;
687 static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
688 struct iwl4965_scale_tbl_info *tbl, u8 scale_index,
689 u8 ht_possible, struct iwl4965_rate *mcs_rate)
694 u8 switch_to_legacy = 0;
695 u8 is_green = lq_sta->is_green;
697 /* check if we need to switch from HT to legacy rates.
698 * assumption is that mandatory rates (1Mbps or 6Mbps)
699 * are always supported (spec demand) */
700 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
701 switch_to_legacy = 1;
702 scale_index = rs_ht_to_legacy[scale_index];
703 if (lq_sta->band == IEEE80211_BAND_5GHZ)
708 if (num_of_ant(tbl->ant_type > 1))
709 tbl->ant_type = ANT_A;/*FIXME:RS*/
715 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask);
717 /* Mask with station rate restriction */
718 if (is_legacy(tbl->lq_type)) {
719 /* supp_rates has no CCK bits in A mode */
720 if (lq_sta->band == IEEE80211_BAND_5GHZ)
721 rate_mask = (u16)(rate_mask &
722 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
724 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
727 /* If we switched from HT to legacy, check current rate */
728 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
729 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
733 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
734 low = high_low & 0xff;
736 if (low != IWL_RATE_INVALID)
737 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
739 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
743 * mac80211 sends us Tx status
745 static void rs_tx_status(void *priv_rate, struct net_device *dev,
747 struct ieee80211_tx_status *tx_resp)
751 int rs_index, index = 0;
752 struct iwl4965_lq_sta *lq_sta;
753 struct iwl_link_quality_cmd *table;
754 struct sta_info *sta;
755 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
756 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
757 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
758 struct ieee80211_hw *hw = local_to_hw(local);
759 struct iwl4965_rate_scale_data *window = NULL;
760 struct iwl4965_rate_scale_data *search_win = NULL;
761 struct iwl4965_rate tx_mcs;
762 struct iwl4965_scale_tbl_info tbl_type;
763 struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl;
765 u16 fc = le16_to_cpu(hdr->frame_control);
768 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
770 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
773 /* This packet was aggregated but doesn't carry rate scale info */
774 if ((tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) &&
775 !(tx_resp->flags & IEEE80211_TX_STATUS_AMPDU))
778 retries = tx_resp->retry_count;
785 sta = sta_info_get(local, hdr->addr1);
787 if (!sta || !sta->rate_ctrl_priv)
791 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
793 if (!priv->lq_mngr.lq_ready)
796 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
797 !lq_sta->ibss_sta_added)
801 active_index = lq_sta->active_tbl;
803 lq_sta->antenna = lq_sta->valid_antenna;
805 curr_tbl = &(lq_sta->lq_info[active_index]);
806 search_tbl = &(lq_sta->lq_info[(1 - active_index)]);
807 window = (struct iwl4965_rate_scale_data *)
809 search_win = (struct iwl4965_rate_scale_data *)
810 &(search_tbl->win[0]);
813 * Ignore this Tx frame response if its initial rate doesn't match
814 * that of latest Link Quality command. There may be stragglers
815 * from a previous Link Quality command, but we're no longer interested
816 * in those; they're either from the "active" mode while we're trying
817 * to check "search" mode, or a prior "search" mode after we've moved
818 * to a new "search" mode (which might become the new "active" mode).
820 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[0].rate_n_flags);
821 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index);
822 if (priv->band == IEEE80211_BAND_5GHZ)
823 rs_index -= IWL_FIRST_OFDM_RATE;
825 if ((tx_resp->control.tx_rate == NULL) ||
827 !!(tx_resp->control.flags & IEEE80211_TXCTL_SHORT_GI)) ||
829 !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) ||
831 !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) ||
832 (tbl_type.ant_type ^ tx_resp->control.antenna_sel_tx) ||
833 (!!(tx_mcs.rate_n_flags & RATE_MCS_HT_MSK) ^
834 !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) ||
835 (!!(tx_mcs.rate_n_flags & RATE_MCS_GF_MSK) ^
836 !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) ||
837 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate !=
838 tx_resp->control.tx_rate->bitrate)) {
839 IWL_DEBUG_RATE("initial rate does not match 0x%x\n",
840 tx_mcs.rate_n_flags);
844 /* Update frame history window with "failure" for each Tx retry. */
846 /* Look up the rate and other info used for each tx attempt.
847 * Each tx attempt steps one entry deeper in the rate table. */
848 tx_mcs.rate_n_flags =
849 le32_to_cpu(table->rs_table[index].rate_n_flags);
850 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
851 &tbl_type, &rs_index);
853 /* If type matches "search" table,
854 * add failure to "search" history */
855 if ((tbl_type.lq_type == search_tbl->lq_type) &&
856 (tbl_type.ant_type == search_tbl->ant_type) &&
857 (tbl_type.is_SGI == search_tbl->is_SGI)) {
858 if (search_tbl->expected_tpt)
859 tpt = search_tbl->expected_tpt[rs_index];
862 rs_collect_tx_data(search_win, rs_index, tpt, 1, 0);
864 /* Else if type matches "current/active" table,
865 * add failure to "current/active" history */
866 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
867 (tbl_type.ant_type == curr_tbl->ant_type) &&
868 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
869 if (curr_tbl->expected_tpt)
870 tpt = curr_tbl->expected_tpt[rs_index];
873 rs_collect_tx_data(window, rs_index, tpt, 1, 0);
876 /* If not searching for a new mode, increment failed counter
877 * ... this helps determine when to start searching again */
878 if (lq_sta->stay_in_tbl)
879 lq_sta->total_failed++;
886 * Find (by rate) the history window to update with final Tx attempt;
887 * if Tx was successful first try, use original rate,
888 * else look up the rate that was, finally, successful.
890 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[index].rate_n_flags);
891 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index);
893 /* Update frame history window with "success" if Tx got ACKed ... */
894 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
899 /* If type matches "search" table,
900 * add final tx status to "search" history */
901 if ((tbl_type.lq_type == search_tbl->lq_type) &&
902 (tbl_type.ant_type == search_tbl->ant_type) &&
903 (tbl_type.is_SGI == search_tbl->is_SGI)) {
904 if (search_tbl->expected_tpt)
905 tpt = search_tbl->expected_tpt[rs_index];
908 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
909 rs_collect_tx_data(search_win, rs_index, tpt,
910 tx_resp->ampdu_ack_len,
911 tx_resp->ampdu_ack_map);
913 rs_collect_tx_data(search_win, rs_index, tpt,
915 /* Else if type matches "current/active" table,
916 * add final tx status to "current/active" history */
917 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
918 (tbl_type.ant_type == curr_tbl->ant_type) &&
919 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
920 if (curr_tbl->expected_tpt)
921 tpt = curr_tbl->expected_tpt[rs_index];
924 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
925 rs_collect_tx_data(window, rs_index, tpt,
926 tx_resp->ampdu_ack_len,
927 tx_resp->ampdu_ack_map);
929 rs_collect_tx_data(window, rs_index, tpt,
933 /* If not searching for new mode, increment success/failed counter
934 * ... these help determine when to start searching again */
935 if (lq_sta->stay_in_tbl) {
936 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) {
937 lq_sta->total_success += tx_resp->ampdu_ack_map;
938 lq_sta->total_failed +=
939 (tx_resp->ampdu_ack_len - tx_resp->ampdu_ack_map);
942 lq_sta->total_success++;
944 lq_sta->total_failed++;
948 /* See if there's a better rate or modulation mode to try. */
949 rs_rate_scale_perform(priv, dev, hdr, sta);
955 static inline u8 rs_is_ant_connected(u8 valid_antenna, u8 ant_type)
957 return ((ant_type & valid_antenna) == ant_type);
960 /*FIXME:RS: this function should be replaced*/
961 static u8 rs_is_other_ant_connected(u8 valid_antenna, u8 ant_type)
963 if (ant_type == ANT_B)
964 return rs_is_ant_connected(valid_antenna, ANT_A);
966 return rs_is_ant_connected(valid_antenna, ANT_B);
972 * Begin a period of staying with a selected modulation mode.
973 * Set "stay_in_tbl" flag to prevent any mode switches.
974 * Set frame tx success limits according to legacy vs. high-throughput,
975 * and reset overall (spanning all rates) tx success history statistics.
976 * These control how long we stay using same modulation mode before
977 * searching for a new mode.
979 static void rs_set_stay_in_table(u8 is_legacy,
980 struct iwl4965_lq_sta *lq_sta)
982 IWL_DEBUG_HT("we are staying in the same table\n");
983 lq_sta->stay_in_tbl = 1; /* only place this gets set */
985 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
986 lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
987 lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
989 lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
990 lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
991 lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
993 lq_sta->table_count = 0;
994 lq_sta->total_failed = 0;
995 lq_sta->total_success = 0;
999 * Find correct throughput table for given mode of modulation
1001 static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1002 struct iwl4965_scale_tbl_info *tbl)
1004 if (is_legacy(tbl->lq_type)) {
1005 if (!is_a_band(tbl->lq_type))
1006 tbl->expected_tpt = expected_tpt_G;
1008 tbl->expected_tpt = expected_tpt_A;
1009 } else if (is_siso(tbl->lq_type)) {
1010 if (tbl->is_fat && !lq_sta->is_dup)
1012 tbl->expected_tpt = expected_tpt_siso40MHzSGI;
1014 tbl->expected_tpt = expected_tpt_siso40MHz;
1015 else if (tbl->is_SGI)
1016 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
1018 tbl->expected_tpt = expected_tpt_siso20MHz;
1020 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */
1021 if (tbl->is_fat && !lq_sta->is_dup)
1023 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
1025 tbl->expected_tpt = expected_tpt_mimo40MHz;
1026 else if (tbl->is_SGI)
1027 tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
1029 tbl->expected_tpt = expected_tpt_mimo20MHz;
1031 tbl->expected_tpt = expected_tpt_G;
1034 #ifdef CONFIG_IWL4965_HT
1036 * Find starting rate for new "search" high-throughput mode of modulation.
1037 * Goal is to find lowest expected rate (under perfect conditions) that is
1038 * above the current measured throughput of "active" mode, to give new mode
1039 * a fair chance to prove itself without too many challenges.
1041 * This gets called when transitioning to more aggressive modulation
1042 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1043 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1044 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1045 * bit rate will typically need to increase, but not if performance was bad.
1047 static s32 rs_get_best_rate(struct iwl_priv *priv,
1048 struct iwl4965_lq_sta *lq_sta,
1049 struct iwl4965_scale_tbl_info *tbl, /* "search" */
1050 u16 rate_mask, s8 index, s8 rate)
1052 /* "active" values */
1053 struct iwl4965_scale_tbl_info *active_tbl =
1054 &(lq_sta->lq_info[lq_sta->active_tbl]);
1055 s32 active_sr = active_tbl->win[index].success_ratio;
1056 s32 active_tpt = active_tbl->expected_tpt[index];
1058 /* expected "search" throughput */
1059 s32 *tpt_tbl = tbl->expected_tpt;
1061 s32 new_rate, high, low, start_hi;
1064 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1067 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
1069 low = high_low & 0xff;
1070 high = (high_low >> 8) & 0xff;
1073 * Lower the "search" bit rate, to give new "search" mode
1074 * approximately the same throughput as "active" if:
1076 * 1) "Active" mode has been working modestly well (but not
1077 * great), and expected "search" throughput (under perfect
1078 * conditions) at candidate rate is above the actual
1079 * measured "active" throughput (but less than expected
1080 * "active" throughput under perfect conditions).
1082 * 2) "Active" mode has been working perfectly or very well
1083 * and expected "search" throughput (under perfect
1084 * conditions) at candidate rate is above expected
1085 * "active" throughput (under perfect conditions).
1087 if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
1088 ((active_sr > IWL_RATE_DECREASE_TH) &&
1089 (active_sr <= IWL_RATE_HIGH_TH) &&
1090 (tpt_tbl[rate] <= active_tpt))) ||
1091 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
1092 (tpt_tbl[rate] > active_tpt))) {
1094 /* (2nd or later pass)
1095 * If we've already tried to raise the rate, and are
1096 * now trying to lower it, use the higher rate. */
1097 if (start_hi != IWL_RATE_INVALID) {
1098 new_rate = start_hi;
1104 /* Loop again with lower rate */
1105 if (low != IWL_RATE_INVALID)
1108 /* Lower rate not available, use the original */
1112 /* Else try to raise the "search" rate to match "active" */
1114 /* (2nd or later pass)
1115 * If we've already tried to lower the rate, and are
1116 * now trying to raise it, use the lower rate. */
1117 if (new_rate != IWL_RATE_INVALID)
1120 /* Loop again with higher rate */
1121 else if (high != IWL_RATE_INVALID) {
1125 /* Higher rate not available, use the original */
1135 #endif /* CONFIG_IWL4965_HT */
1137 /*FIXME:RS:this function should be replaced*/
1138 static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
1140 return (rs_is_ant_connected(valid_antenna, ANT_AB));
1144 * Set up search table for MIMO
1146 #ifdef CONFIG_IWL4965_HT
1147 static int rs_switch_to_mimo2(struct iwl_priv *priv,
1148 struct iwl4965_lq_sta *lq_sta,
1149 struct ieee80211_conf *conf,
1150 struct sta_info *sta,
1151 struct iwl4965_scale_tbl_info *tbl, int index)
1155 s8 is_green = lq_sta->is_green;
1157 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1158 !sta->ht_info.ht_supported)
1161 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
1162 tbl->lq_type = LQ_MIMO2;
1163 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
1166 if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
1169 /* Need both Tx chains/antennas to support MIMO */
1170 if (!rs_is_both_ant_supp(priv->hw_params.valid_tx_ant))
1173 tbl->is_dup = lq_sta->is_dup;
1175 if (priv->current_ht_config.supported_chan_width
1176 == IWL_CHANNEL_WIDTH_40MHZ)
1182 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1186 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
1191 rs_get_expected_tpt_table(lq_sta, tbl);
1193 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index);
1195 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
1196 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
1198 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1200 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1201 tbl->current_rate.rate_n_flags, is_green);
1205 static int rs_switch_to_mimo2(struct iwl_priv *priv,
1206 struct iwl4965_lq_sta *lq_sta,
1207 struct ieee80211_conf *conf,
1208 struct sta_info *sta,
1209 struct iwl4965_scale_tbl_info *tbl, int index)
1213 #endif /*CONFIG_IWL4965_HT */
1216 * Set up search table for SISO
1218 static int rs_switch_to_siso(struct iwl_priv *priv,
1219 struct iwl4965_lq_sta *lq_sta,
1220 struct ieee80211_conf *conf,
1221 struct sta_info *sta,
1222 struct iwl4965_scale_tbl_info *tbl, int index)
1224 #ifdef CONFIG_IWL4965_HT
1226 u8 is_green = lq_sta->is_green;
1229 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
1230 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1231 !sta->ht_info.ht_supported)
1234 tbl->is_dup = lq_sta->is_dup;
1235 tbl->lq_type = LQ_SISO;
1237 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
1240 if (priv->current_ht_config.supported_chan_width
1241 == IWL_CHANNEL_WIDTH_40MHZ)
1247 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1251 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
1259 rs_get_expected_tpt_table(lq_sta, tbl);
1260 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index);
1262 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
1263 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1264 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
1268 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1269 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1270 tbl->current_rate.rate_n_flags, is_green);
1275 #endif /*CONFIG_IWL4965_HT */
1279 * Try to switch to new modulation mode from legacy
1281 static int rs_move_legacy_other(struct iwl_priv *priv,
1282 struct iwl4965_lq_sta *lq_sta,
1283 struct ieee80211_conf *conf,
1284 struct sta_info *sta,
1287 struct iwl4965_scale_tbl_info *tbl =
1288 &(lq_sta->lq_info[lq_sta->active_tbl]);
1289 struct iwl4965_scale_tbl_info *search_tbl =
1290 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1291 struct iwl4965_rate_scale_data *window = &(tbl->win[index]);
1292 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1293 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1294 u8 start_action = tbl->action;
1295 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1299 switch (tbl->action) {
1300 case IWL_LEGACY_SWITCH_ANTENNA:
1301 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1303 search_tbl->lq_type = LQ_NONE;
1304 lq_sta->action_counter++;
1306 /* Don't change antenna if success has been great */
1307 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1310 /* Don't change antenna if other one is not connected */
1311 if (!rs_is_other_ant_connected(valid_tx_ant,
1315 /* Set up search table to try other antenna */
1316 memcpy(search_tbl, tbl, sz);
1318 rs_toggle_antenna(&(search_tbl->current_rate),
1320 rs_get_expected_tpt_table(lq_sta, search_tbl);
1321 lq_sta->search_better_tbl = 1;
1324 case IWL_LEGACY_SWITCH_SISO:
1325 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1327 /* Set up search table to try SISO */
1328 memcpy(search_tbl, tbl, sz);
1329 search_tbl->lq_type = LQ_SISO;
1330 search_tbl->is_SGI = 0;
1331 search_tbl->is_fat = 0;
1332 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1335 lq_sta->search_better_tbl = 1;
1336 lq_sta->action_counter = 0;
1341 case IWL_LEGACY_SWITCH_MIMO2:
1342 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1344 /* Set up search table to try MIMO */
1345 memcpy(search_tbl, tbl, sz);
1346 search_tbl->lq_type = LQ_MIMO2;
1347 search_tbl->is_SGI = 0;
1348 search_tbl->is_fat = 0;
1349 search_tbl->ant_type = ANT_AB;/*FIXME:RS*/
1350 /*FIXME:RS:need to check ant validity*/
1351 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1354 lq_sta->search_better_tbl = 1;
1355 lq_sta->action_counter = 0;
1361 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2)
1362 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1364 if (tbl->action == start_action)
1372 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2)
1373 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1379 * Try to switch to new modulation mode from SISO
1381 static int rs_move_siso_to_other(struct iwl_priv *priv,
1382 struct iwl4965_lq_sta *lq_sta,
1383 struct ieee80211_conf *conf,
1384 struct sta_info *sta,
1387 u8 is_green = lq_sta->is_green;
1388 struct iwl4965_scale_tbl_info *tbl =
1389 &(lq_sta->lq_info[lq_sta->active_tbl]);
1390 struct iwl4965_scale_tbl_info *search_tbl =
1391 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1392 struct iwl4965_rate_scale_data *window = &(tbl->win[index]);
1393 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1394 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1395 u8 start_action = tbl->action;
1396 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1400 lq_sta->action_counter++;
1401 switch (tbl->action) {
1402 case IWL_SISO_SWITCH_ANTENNA:
1403 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1404 search_tbl->lq_type = LQ_NONE;
1405 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1407 if (!rs_is_other_ant_connected(valid_tx_ant,
1411 memcpy(search_tbl, tbl, sz);
1412 search_tbl->action = IWL_SISO_SWITCH_MIMO2;
1413 rs_toggle_antenna(&(search_tbl->current_rate),
1415 lq_sta->search_better_tbl = 1;
1419 case IWL_SISO_SWITCH_MIMO2:
1420 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO2 FROM SISO\n");
1421 memcpy(search_tbl, tbl, sz);
1422 search_tbl->lq_type = LQ_MIMO2;
1423 search_tbl->is_SGI = 0;
1424 search_tbl->is_fat = 0;
1425 search_tbl->ant_type = ANT_AB; /*FIXME:RS*/
1426 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1429 lq_sta->search_better_tbl = 1;
1433 case IWL_SISO_SWITCH_GI:
1434 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1436 memcpy(search_tbl, tbl, sz);
1437 search_tbl->action = 0;
1438 if (search_tbl->is_SGI)
1439 search_tbl->is_SGI = 0;
1441 search_tbl->is_SGI = 1;
1444 lq_sta->search_better_tbl = 1;
1445 if ((tbl->lq_type == LQ_SISO) &&
1447 s32 tpt = lq_sta->last_tpt / 100;
1448 if (((!tbl->is_fat) &&
1449 (tpt >= expected_tpt_siso20MHz[index])) ||
1451 (tpt >= expected_tpt_siso40MHz[index])))
1452 lq_sta->search_better_tbl = 0;
1454 rs_get_expected_tpt_table(lq_sta, search_tbl);
1455 rs_mcs_from_tbl(&search_tbl->current_rate,
1456 search_tbl, index, is_green);
1460 if (tbl->action > IWL_SISO_SWITCH_GI)
1461 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1463 if (tbl->action == start_action)
1470 if (tbl->action > IWL_SISO_SWITCH_GI)
1471 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1476 * Try to switch to new modulation mode from MIMO
1478 static int rs_move_mimo_to_other(struct iwl_priv *priv,
1479 struct iwl4965_lq_sta *lq_sta,
1480 struct ieee80211_conf *conf,
1481 struct sta_info *sta,
1485 s8 is_green = lq_sta->is_green;
1486 struct iwl4965_scale_tbl_info *tbl =
1487 &(lq_sta->lq_info[lq_sta->active_tbl]);
1488 struct iwl4965_scale_tbl_info *search_tbl =
1489 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1490 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1491 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1492 u8 start_action = tbl->action;
1495 lq_sta->action_counter++;
1496 switch (tbl->action) {
1497 case IWL_MIMO_SWITCH_ANTENNA_A:
1498 case IWL_MIMO_SWITCH_ANTENNA_B:
1499 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1502 /* Set up new search table for SISO */
1503 memcpy(search_tbl, tbl, sz);
1504 search_tbl->lq_type = LQ_SISO;
1505 search_tbl->is_SGI = 0;
1506 search_tbl->is_fat = 0;
1507 /*FIXME:RS:need to check ant validity + C*/
1508 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1509 search_tbl->ant_type = ANT_A;
1511 search_tbl->ant_type = ANT_B;
1513 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1516 lq_sta->search_better_tbl = 1;
1521 case IWL_MIMO_SWITCH_GI:
1522 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1524 /* Set up new search table for MIMO */
1525 memcpy(search_tbl, tbl, sz);
1526 search_tbl->action = 0;
1527 if (search_tbl->is_SGI)
1528 search_tbl->is_SGI = 0;
1530 search_tbl->is_SGI = 1;
1531 lq_sta->search_better_tbl = 1;
1534 * If active table already uses the fastest possible
1535 * modulation (dual stream with short guard interval),
1536 * and it's working well, there's no need to look
1537 * for a better type of modulation!
1539 if ((tbl->lq_type == LQ_MIMO2) &&
1541 s32 tpt = lq_sta->last_tpt / 100;
1542 if (((!tbl->is_fat) &&
1543 (tpt >= expected_tpt_mimo20MHz[index])) ||
1545 (tpt >= expected_tpt_mimo40MHz[index])))
1546 lq_sta->search_better_tbl = 0;
1548 rs_get_expected_tpt_table(lq_sta, search_tbl);
1549 rs_mcs_from_tbl(&search_tbl->current_rate,
1550 search_tbl, index, is_green);
1555 if (tbl->action > IWL_MIMO_SWITCH_GI)
1556 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1558 if (tbl->action == start_action)
1565 if (tbl->action > IWL_MIMO_SWITCH_GI)
1566 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1572 * Check whether we should continue using same modulation mode, or
1573 * begin search for a new mode, based on:
1574 * 1) # tx successes or failures while using this mode
1575 * 2) # times calling this function
1576 * 3) elapsed time in this mode (not used, for now)
1578 static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1580 struct iwl4965_scale_tbl_info *tbl;
1583 int flush_interval_passed = 0;
1585 active_tbl = lq_sta->active_tbl;
1587 tbl = &(lq_sta->lq_info[active_tbl]);
1589 /* If we've been disallowing search, see if we should now allow it */
1590 if (lq_sta->stay_in_tbl) {
1592 /* Elapsed time using current modulation mode */
1593 if (lq_sta->flush_timer)
1594 flush_interval_passed =
1596 (unsigned long)(lq_sta->flush_timer +
1597 IWL_RATE_SCALE_FLUSH_INTVL));
1599 /* For now, disable the elapsed time criterion */
1600 flush_interval_passed = 0;
1603 * Check if we should allow search for new modulation mode.
1604 * If many frames have failed or succeeded, or we've used
1605 * this same modulation for a long time, allow search, and
1606 * reset history stats that keep track of whether we should
1607 * allow a new search. Also (below) reset all bitmaps and
1608 * stats in active history.
1610 if ((lq_sta->total_failed > lq_sta->max_failure_limit) ||
1611 (lq_sta->total_success > lq_sta->max_success_limit) ||
1612 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
1613 && (flush_interval_passed))) {
1614 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1615 lq_sta->total_failed,
1616 lq_sta->total_success,
1617 flush_interval_passed);
1619 /* Allow search for new mode */
1620 lq_sta->stay_in_tbl = 0; /* only place reset */
1621 lq_sta->total_failed = 0;
1622 lq_sta->total_success = 0;
1623 lq_sta->flush_timer = 0;
1626 * Else if we've used this modulation mode enough repetitions
1627 * (regardless of elapsed time or success/failure), reset
1628 * history bitmaps and rate-specific stats for all rates in
1632 lq_sta->table_count++;
1633 if (lq_sta->table_count >=
1634 lq_sta->table_count_limit) {
1635 lq_sta->table_count = 0;
1637 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1638 for (i = 0; i < IWL_RATE_COUNT; i++)
1639 rs_rate_scale_clear_window(
1644 /* If transitioning to allow "search", reset all history
1645 * bitmaps and stats in active table (this will become the new
1646 * "search" table). */
1647 if (!lq_sta->stay_in_tbl) {
1648 for (i = 0; i < IWL_RATE_COUNT; i++)
1649 rs_rate_scale_clear_window(&(tbl->win[i]));
1655 * Do rate scaling and search for new modulation mode.
1657 static void rs_rate_scale_perform(struct iwl_priv *priv,
1658 struct net_device *dev,
1659 struct ieee80211_hdr *hdr,
1660 struct sta_info *sta)
1662 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1663 struct ieee80211_hw *hw = local_to_hw(local);
1664 struct ieee80211_conf *conf = &hw->conf;
1665 int low = IWL_RATE_INVALID;
1666 int high = IWL_RATE_INVALID;
1669 struct iwl4965_rate_scale_data *window = NULL;
1670 int current_tpt = IWL_INVALID_VALUE;
1671 int low_tpt = IWL_INVALID_VALUE;
1672 int high_tpt = IWL_INVALID_VALUE;
1674 s8 scale_action = 0;
1677 struct iwl4965_lq_sta *lq_sta;
1678 struct iwl4965_scale_tbl_info *tbl, *tbl1;
1679 u16 rate_scale_index_msk = 0;
1680 struct iwl4965_rate mcs_rate;
1685 #ifdef CONFIG_IWL4965_HT
1686 u8 tid = MAX_TID_COUNT;
1690 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1692 fc = le16_to_cpu(hdr->frame_control);
1693 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1694 /* Send management frames and broadcast/multicast data using
1696 /* TODO: this could probably be improved.. */
1700 if (!sta || !sta->rate_ctrl_priv)
1703 if (!priv->lq_mngr.lq_ready) {
1704 IWL_DEBUG_RATE("still rate scaling not ready\n");
1707 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
1709 #ifdef CONFIG_IWL4965_HT
1710 qc = ieee80211_get_qos_ctrl(hdr);
1712 tid = (u8)(le16_to_cpu(*qc) & 0xf);
1713 rs_tl_add_packet(lq_sta, tid);
1717 * Select rate-scale / modulation-mode table to work with in
1718 * the rest of this function: "search" if searching for better
1719 * modulation mode, or "active" if doing rate scaling within a mode.
1721 if (!lq_sta->search_better_tbl)
1722 active_tbl = lq_sta->active_tbl;
1724 active_tbl = 1 - lq_sta->active_tbl;
1726 tbl = &(lq_sta->lq_info[active_tbl]);
1727 is_green = lq_sta->is_green;
1729 /* current tx rate */
1730 index = sta->last_txrate_idx;
1732 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1735 /* rates available for this association, and for modulation mode */
1736 rs_get_supported_rates(lq_sta, hdr, tbl->lq_type,
1739 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1741 /* mask with station rate restriction */
1742 if (is_legacy(tbl->lq_type)) {
1743 if (lq_sta->band == IEEE80211_BAND_5GHZ)
1744 /* supp_rates has no CCK bits in A mode */
1745 rate_scale_index_msk = (u16) (rate_mask &
1746 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
1748 rate_scale_index_msk = (u16) (rate_mask &
1749 lq_sta->supp_rates);
1752 rate_scale_index_msk = rate_mask;
1754 if (!rate_scale_index_msk)
1755 rate_scale_index_msk = rate_mask;
1757 /* If current rate is no longer supported on current association,
1758 * or user changed preferences for rates, find a new supported rate. */
1759 if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
1760 index = IWL_INVALID_VALUE;
1763 /* get the highest available rate */
1764 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1765 if ((1 << i) & rate_scale_index_msk)
1769 if (index == IWL_INVALID_VALUE) {
1770 IWL_WARNING("Can not find a suitable rate\n");
1775 /* Get expected throughput table and history window for current rate */
1776 if (!tbl->expected_tpt)
1777 rs_get_expected_tpt_table(lq_sta, tbl);
1779 window = &(tbl->win[index]);
1782 * If there is not enough history to calculate actual average
1783 * throughput, keep analyzing results of more tx frames, without
1784 * changing rate or mode (bypass most of the rest of this function).
1785 * Set up new rate table in uCode only if old rate is not supported
1786 * in current association (use new rate found above).
1788 fail_count = window->counter - window->success_counter;
1789 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1790 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
1791 || (tbl->expected_tpt == NULL)) {
1792 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1794 window->success_counter, window->counter, index);
1796 /* Can't calculate this yet; not enough history */
1797 window->average_tpt = IWL_INVALID_VALUE;
1799 /* Should we stay with this modulation mode,
1800 * or search for a new one? */
1801 rs_stay_in_table(lq_sta);
1803 /* Set up new rate table in uCode, if needed */
1805 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1806 rs_fill_link_cmd(priv, lq_sta, &mcs_rate, &lq_sta->lq);
1807 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
1811 /* Else we have enough samples; calculate estimate of
1812 * actual average throughput */
1814 window->average_tpt = ((window->success_ratio *
1815 tbl->expected_tpt[index] + 64) / 128);
1817 /* If we are searching for better modulation mode, check success. */
1818 if (lq_sta->search_better_tbl) {
1819 int success_limit = IWL_RATE_SCALE_SWITCH;
1821 /* If good success, continue using the "search" mode;
1822 * no need to send new link quality command, since we're
1823 * continuing to use the setup that we've been trying. */
1824 if ((window->success_ratio > success_limit) ||
1825 (window->average_tpt > lq_sta->last_tpt)) {
1826 if (!is_legacy(tbl->lq_type)) {
1827 IWL_DEBUG_HT("LQ: we are switching to HT"
1828 " rate suc %d current tpt %d"
1830 window->success_ratio,
1831 window->average_tpt,
1833 lq_sta->enable_counter = 1;
1835 /* Swap tables; "search" becomes "active" */
1836 lq_sta->active_tbl = active_tbl;
1837 current_tpt = window->average_tpt;
1839 /* Else poor success; go back to mode in "active" table */
1841 /* Nullify "search" table */
1842 tbl->lq_type = LQ_NONE;
1844 /* Revert to "active" table */
1845 active_tbl = lq_sta->active_tbl;
1846 tbl = &(lq_sta->lq_info[active_tbl]);
1848 /* Revert to "active" rate and throughput info */
1849 index = iwl4965_hwrate_to_plcp_idx(
1850 tbl->current_rate.rate_n_flags);
1851 current_tpt = lq_sta->last_tpt;
1853 /* Need to set up a new rate table in uCode */
1855 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1858 /* Either way, we've made a decision; modulation mode
1859 * search is done, allow rate adjustment next time. */
1860 lq_sta->search_better_tbl = 0;
1861 done_search = 1; /* Don't switch modes below! */
1865 /* (Else) not in search of better modulation mode, try for better
1866 * starting rate, while staying in this mode. */
1867 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
1869 low = high_low & 0xff;
1870 high = (high_low >> 8) & 0xff;
1872 /* Collect measured throughputs for current and adjacent rates */
1873 current_tpt = window->average_tpt;
1874 if (low != IWL_RATE_INVALID)
1875 low_tpt = tbl->win[low].average_tpt;
1876 if (high != IWL_RATE_INVALID)
1877 high_tpt = tbl->win[high].average_tpt;
1879 /* Assume rate increase */
1882 /* Too many failures, decrease rate */
1883 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
1884 (current_tpt == 0)) {
1885 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1888 /* No throughput measured yet for adjacent rates; try increase. */
1889 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1890 (high_tpt == IWL_INVALID_VALUE))
1893 /* Both adjacent throughputs are measured, but neither one has better
1894 * throughput; we're using the best rate, don't change it! */
1895 else if ((low_tpt != IWL_INVALID_VALUE) &&
1896 (high_tpt != IWL_INVALID_VALUE) &&
1897 (low_tpt < current_tpt) &&
1898 (high_tpt < current_tpt))
1901 /* At least one adjacent rate's throughput is measured,
1902 * and may have better performance. */
1904 /* Higher adjacent rate's throughput is measured */
1905 if (high_tpt != IWL_INVALID_VALUE) {
1906 /* Higher rate has better throughput */
1907 if (high_tpt > current_tpt)
1911 ("decrease rate because of high tpt\n");
1915 /* Lower adjacent rate's throughput is measured */
1916 } else if (low_tpt != IWL_INVALID_VALUE) {
1917 /* Lower rate has better throughput */
1918 if (low_tpt > current_tpt) {
1920 ("decrease rate because of low tpt\n");
1927 /* Sanity check; asked for decrease, but success rate or throughput
1928 * has been good at old rate. Don't change it. */
1929 if (scale_action == -1) {
1930 if ((low != IWL_RATE_INVALID) &&
1931 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1932 (current_tpt > (100 * tbl->expected_tpt[low]))))
1935 /* Sanity check; asked for increase, but success rate has not been great
1936 * even at old rate, higher rate will be worse. Don't change it. */
1937 } else if ((scale_action == 1) &&
1938 (window->success_ratio < IWL_RATE_INCREASE_TH))
1941 switch (scale_action) {
1943 /* Decrease starting rate, update uCode's rate table */
1944 if (low != IWL_RATE_INVALID) {
1950 /* Increase starting rate, update uCode's rate table */
1951 if (high != IWL_RATE_INVALID) {
1963 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1964 "high %d type %d\n",
1965 index, scale_action, low, high, tbl->lq_type);
1968 /* Replace uCode's rate table for the destination station. */
1970 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1971 rs_fill_link_cmd(priv, lq_sta, &mcs_rate, &lq_sta->lq);
1972 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
1975 /* Should we stay with this modulation mode, or search for a new one? */
1976 rs_stay_in_table(lq_sta);
1979 * Search for new modulation mode if we're:
1980 * 1) Not changing rates right now
1981 * 2) Not just finishing up a search
1982 * 3) Allowing a new search
1984 if (!update_lq && !done_search && !lq_sta->stay_in_tbl) {
1985 /* Save current throughput to compare with "search" throughput*/
1986 lq_sta->last_tpt = current_tpt;
1988 /* Select a new "search" modulation mode to try.
1989 * If one is found, set up the new "search" table. */
1990 if (is_legacy(tbl->lq_type))
1991 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
1992 else if (is_siso(tbl->lq_type))
1993 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
1995 rs_move_mimo_to_other(priv, lq_sta, conf, sta, index);
1997 /* If new "search" mode was selected, set up in uCode table */
1998 if (lq_sta->search_better_tbl) {
1999 /* Access the "search" table, clear its history. */
2000 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
2001 for (i = 0; i < IWL_RATE_COUNT; i++)
2002 rs_rate_scale_clear_window(&(tbl->win[i]));
2004 /* Use new "search" start rate */
2005 index = iwl4965_hwrate_to_plcp_idx(
2006 tbl->current_rate.rate_n_flags);
2008 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
2009 tbl->current_rate.rate_n_flags, index);
2010 rs_fill_link_cmd(priv, lq_sta, &tbl->current_rate,
2012 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2015 /* If the "active" (non-search) mode was legacy,
2016 * and we've tried switching antennas,
2017 * but we haven't been able to try HT modes (not available),
2018 * stay with best antenna legacy modulation for a while
2019 * before next round of mode comparisons. */
2020 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2021 if (is_legacy(tbl1->lq_type) &&
2022 #ifdef CONFIG_IWL4965_HT
2023 (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) &&
2025 (lq_sta->action_counter >= 1)) {
2026 lq_sta->action_counter = 0;
2027 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
2028 rs_set_stay_in_table(1, lq_sta);
2031 /* If we're in an HT mode, and all 3 mode switch actions
2032 * have been tried and compared, stay in this best modulation
2033 * mode for a while before next round of mode comparisons. */
2034 if (lq_sta->enable_counter &&
2035 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) {
2036 #ifdef CONFIG_IWL4965_HT
2037 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2038 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2039 (tid != MAX_TID_COUNT)) {
2040 IWL_DEBUG_HT("try to aggregate tid %d\n", tid);
2041 rs_tl_turn_on_agg(priv, tid, lq_sta, sta);
2043 #endif /*CONFIG_IWL4965_HT */
2044 lq_sta->action_counter = 0;
2045 rs_set_stay_in_table(0, lq_sta);
2049 * Else, don't search for a new modulation mode.
2050 * Put new timestamp in stay-in-modulation-mode flush timer if:
2051 * 1) Not changing rates right now
2052 * 2) Not just finishing up a search
2053 * 3) flush timer is empty
2056 if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer))
2057 lq_sta->flush_timer = jiffies;
2061 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
2063 sta->last_txrate_idx = i;
2065 /* sta->txrate_idx is an index to A mode rates which start
2066 * at IWL_FIRST_OFDM_RATE
2068 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2069 sta->txrate_idx = i - IWL_FIRST_OFDM_RATE;
2071 sta->txrate_idx = i;
2077 static void rs_initialize_lq(struct iwl_priv *priv,
2078 struct ieee80211_conf *conf,
2079 struct sta_info *sta)
2082 struct iwl4965_lq_sta *lq_sta;
2083 struct iwl4965_scale_tbl_info *tbl;
2086 u8 use_green = rs_use_green(priv, conf);
2087 struct iwl4965_rate mcs_rate;
2089 if (!sta || !sta->rate_ctrl_priv)
2092 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
2093 i = sta->last_txrate_idx;
2095 if ((lq_sta->lq.sta_id == 0xff) &&
2096 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
2099 if (!lq_sta->search_better_tbl)
2100 active_tbl = lq_sta->active_tbl;
2102 active_tbl = 1 - lq_sta->active_tbl;
2104 tbl = &(lq_sta->lq_info[active_tbl]);
2106 if ((i < 0) || (i >= IWL_RATE_COUNT))
2109 /* FIXME:RS: This is also wrong in 4965 */
2110 mcs_rate.rate_n_flags = iwl4965_rates[i].plcp ;
2111 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
2112 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
2114 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
2115 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
2117 tbl->ant_type = ANT_B;
2118 rs_get_tbl_info_from_mcs(&mcs_rate, priv->band, tbl, &rate_idx);
2119 if (!rs_is_ant_connected(priv->hw_params.valid_tx_ant, tbl->ant_type))
2120 rs_toggle_antenna(&mcs_rate, tbl);
2122 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
2123 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
2124 rs_get_expected_tpt_table(lq_sta, tbl);
2125 rs_fill_link_cmd(NULL, lq_sta, &mcs_rate, &lq_sta->lq);
2126 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2131 static void rs_get_rate(void *priv_rate, struct net_device *dev,
2132 struct ieee80211_supported_band *sband,
2133 struct sk_buff *skb,
2134 struct rate_selection *sel)
2138 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2139 struct ieee80211_conf *conf = &local->hw.conf;
2140 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2141 struct sta_info *sta;
2143 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
2144 struct iwl4965_lq_sta *lq_sta;
2146 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
2150 sta = sta_info_get(local, hdr->addr1);
2152 /* Send management frames and broadcast/multicast data using lowest
2154 fc = le16_to_cpu(hdr->frame_control);
2155 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
2156 !sta || !sta->rate_ctrl_priv) {
2157 sel->rate = rate_lowest(local, sband, sta);
2161 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
2162 i = sta->last_txrate_idx;
2164 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2165 !lq_sta->ibss_sta_added) {
2166 u8 sta_id = iwl_find_station(priv, hdr->addr1);
2167 DECLARE_MAC_BUF(mac);
2169 if (sta_id == IWL_INVALID_STATION) {
2170 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2171 print_mac(mac, hdr->addr1));
2172 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2173 0, CMD_ASYNC, NULL);
2175 if ((sta_id != IWL_INVALID_STATION)) {
2176 lq_sta->lq.sta_id = sta_id;
2177 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2178 lq_sta->ibss_sta_added = 1;
2179 rs_initialize_lq(priv, conf, sta);
2181 if (!lq_sta->ibss_sta_added)
2186 if ((i < 0) || (i > IWL_RATE_COUNT)) {
2187 sel->rate = rate_lowest(local, sband, sta);
2191 sel->rate = &priv->ieee_rates[i];
2196 static void *rs_alloc_sta(void *priv, gfp_t gfp)
2198 struct iwl4965_lq_sta *lq_sta;
2201 IWL_DEBUG_RATE("create station rate scale window\n");
2203 lq_sta = kzalloc(sizeof(struct iwl4965_lq_sta), gfp);
2207 lq_sta->lq.sta_id = 0xff;
2210 for (j = 0; j < LQ_SIZE; j++)
2211 for (i = 0; i < IWL_RATE_COUNT; i++)
2212 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
2217 static void rs_rate_init(void *priv_rate, void *priv_sta,
2218 struct ieee80211_local *local,
2219 struct sta_info *sta)
2222 struct ieee80211_conf *conf = &local->hw.conf;
2223 struct ieee80211_supported_band *sband;
2224 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
2225 struct iwl4965_lq_sta *lq_sta = priv_sta;
2227 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2229 lq_sta->flush_timer = 0;
2230 lq_sta->supp_rates = sta->supp_rates[sband->band];
2231 sta->txrate_idx = 3;
2232 for (j = 0; j < LQ_SIZE; j++)
2233 for (i = 0; i < IWL_RATE_COUNT; i++)
2234 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
2236 IWL_DEBUG_RATE("rate scale global init\n");
2237 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2238 * the lowest or the highest rate.. Could consider using RSSI from
2239 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2242 lq_sta->ibss_sta_added = 0;
2243 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2244 u8 sta_id = iwl_find_station(priv, sta->addr);
2245 DECLARE_MAC_BUF(mac);
2247 /* for IBSS the call are from tasklet */
2248 IWL_DEBUG_HT("LQ: ADD station %s\n",
2249 print_mac(mac, sta->addr));
2251 if (sta_id == IWL_INVALID_STATION) {
2252 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2253 print_mac(mac, sta->addr));
2254 sta_id = iwl4965_add_station_flags(priv, sta->addr,
2255 0, CMD_ASYNC, NULL);
2257 if ((sta_id != IWL_INVALID_STATION)) {
2258 lq_sta->lq.sta_id = sta_id;
2259 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2261 /* FIXME: this is w/a remove it later */
2262 priv->assoc_station_added = 1;
2265 /* Find highest tx rate supported by hardware and destination station */
2266 for (i = 0; i < sband->n_bitrates; i++)
2267 if (sta->supp_rates[sband->band] & BIT(i))
2268 sta->txrate_idx = i;
2270 sta->last_txrate_idx = sta->txrate_idx;
2271 /* WTF is with this bogus comment? A doesn't have cck rates */
2272 /* For MODE_IEEE80211A, cck rates are at end of rate table */
2273 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
2274 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
2277 lq_sta->is_green = rs_use_green(priv, conf);
2278 lq_sta->active_rate = priv->active_rate;
2279 lq_sta->active_rate &= ~(0x1000);
2280 lq_sta->active_rate_basic = priv->active_rate_basic;
2281 lq_sta->band = priv->band;
2282 #ifdef CONFIG_IWL4965_HT
2284 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2285 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2287 lq_sta->active_siso_rate =
2288 priv->current_ht_config.supp_mcs_set[0] << 1;
2289 lq_sta->active_siso_rate |=
2290 priv->current_ht_config.supp_mcs_set[0] & 0x1;
2291 lq_sta->active_siso_rate &= ~((u16)0x2);
2292 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
2295 lq_sta->active_mimo2_rate =
2296 priv->current_ht_config.supp_mcs_set[1] << 1;
2297 lq_sta->active_mimo2_rate |=
2298 priv->current_ht_config.supp_mcs_set[1] & 0x1;
2299 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2300 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2302 lq_sta->active_mimo3_rate =
2303 priv->current_ht_config.supp_mcs_set[2] << 1;
2304 lq_sta->active_mimo3_rate |=
2305 priv->current_ht_config.supp_mcs_set[2] & 0x1;
2306 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2307 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2309 IWL_DEBUG_HT("SISO RATE %X MIMO2 RATE %X MIMO3 RATE %X\n",
2310 lq_sta->active_siso_rate,
2311 lq_sta->active_mimo2_rate,
2312 lq_sta->active_mimo3_rate);
2314 /* as default allow aggregation for all tids */
2315 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
2316 #endif /*CONFIG_IWL4965_HT*/
2317 #ifdef CONFIG_MAC80211_DEBUGFS
2321 if (priv->assoc_station_added)
2322 priv->lq_mngr.lq_ready = 1;
2324 rs_initialize_lq(priv, conf, sta);
2327 static void rs_fill_link_cmd(const struct iwl_priv *priv,
2328 struct iwl4965_lq_sta *lq_sta,
2329 struct iwl4965_rate *tx_mcs,
2330 struct iwl_link_quality_cmd *lq_cmd)
2334 int repeat_rate = 0;
2335 u8 ant_toggle_count = 0;
2336 u8 use_ht_possible = 1;
2337 struct iwl4965_rate new_rate;
2338 struct iwl4965_scale_tbl_info tbl_type = { 0 };
2340 /* Override starting rate (index 0) if needed for debug purposes */
2341 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index);
2343 /* Interpret rate_n_flags */
2344 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->band,
2345 &tbl_type, &rate_idx);
2347 /* How many times should we repeat the initial rate? */
2348 if (is_legacy(tbl_type.lq_type)) {
2349 ant_toggle_count = 1;
2350 repeat_rate = IWL_NUMBER_TRY;
2352 repeat_rate = IWL_HT_NUMBER_TRY;
2354 lq_cmd->general_params.mimo_delimiter =
2355 is_mimo(tbl_type.lq_type) ? 1 : 0;
2357 /* Fill 1st table entry (index 0) */
2358 lq_cmd->rs_table[index].rate_n_flags =
2359 cpu_to_le32(tx_mcs->rate_n_flags);
2360 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
2363 if (is_mimo(tbl_type.lq_type) || (tbl_type.ant_type == ANT_A))
2364 lq_cmd->general_params.single_stream_ant_msk
2365 = LINK_QUAL_ANT_A_MSK;
2367 lq_cmd->general_params.single_stream_ant_msk
2368 = LINK_QUAL_ANT_B_MSK;
2373 /* Fill rest of rate table */
2374 while (index < LINK_QUAL_MAX_RETRY_NUM) {
2375 /* Repeat initial/next rate.
2376 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2377 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
2378 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
2379 if (is_legacy(tbl_type.lq_type)) {
2380 if (ant_toggle_count <
2381 NUM_TRY_BEFORE_ANTENNA_TOGGLE)
2383 else if (priv && rs_is_other_ant_connected(
2384 priv->hw_params.valid_tx_ant,
2385 tbl_type.ant_type)) {
2386 rs_toggle_antenna(&new_rate, &tbl_type);
2387 ant_toggle_count = 1;
2391 /* Override next rate if needed for debug purposes */
2392 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2394 /* Fill next table entry */
2395 lq_cmd->rs_table[index].rate_n_flags =
2396 cpu_to_le32(new_rate.rate_n_flags);
2401 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->band, &tbl_type,
2404 /* Indicate to uCode which entries might be MIMO.
2405 * If initial rate was MIMO, this will finally end up
2406 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
2407 if (is_mimo(tbl_type.lq_type))
2408 lq_cmd->general_params.mimo_delimiter = index;
2411 rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
2412 use_ht_possible, &new_rate);
2414 /* How many times should we repeat the next rate? */
2415 if (is_legacy(tbl_type.lq_type)) {
2416 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
2418 else if (priv && rs_is_other_ant_connected(
2419 priv->hw_params.valid_tx_ant,
2420 tbl_type.ant_type)) {
2421 rs_toggle_antenna(&new_rate, &tbl_type);
2422 ant_toggle_count = 1;
2424 repeat_rate = IWL_NUMBER_TRY;
2426 repeat_rate = IWL_HT_NUMBER_TRY;
2428 /* Don't allow HT rates after next pass.
2429 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
2430 use_ht_possible = 0;
2432 /* Override next rate if needed for debug purposes */
2433 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2435 /* Fill next table entry */
2436 lq_cmd->rs_table[index].rate_n_flags =
2437 cpu_to_le32(new_rate.rate_n_flags);
2443 lq_cmd->general_params.dual_stream_ant_msk = 3;
2444 lq_cmd->agg_params.agg_dis_start_th = 3;
2445 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
2448 static void *rs_alloc(struct ieee80211_local *local)
2450 return local->hw.priv;
2452 /* rate scale requires free function to be implemented */
2453 static void rs_free(void *priv_rate)
2458 static void rs_clear(void *priv_rate)
2460 struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
2462 IWL_DEBUG_RATE("enter\n");
2464 priv->lq_mngr.lq_ready = 0;
2466 IWL_DEBUG_RATE("leave\n");
2469 static void rs_free_sta(void *priv, void *priv_sta)
2471 struct iwl4965_lq_sta *lq_sta = priv_sta;
2473 IWL_DEBUG_RATE("enter\n");
2475 IWL_DEBUG_RATE("leave\n");
2479 #ifdef CONFIG_MAC80211_DEBUGFS
2480 static int open_file_generic(struct inode *inode, struct file *file)
2482 file->private_data = inode->i_private;
2485 static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
2486 struct iwl4965_rate *mcs, int index)
2490 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2495 if (lq_sta->dbg_fixed.rate_n_flags) {
2497 mcs->rate_n_flags = lq_sta->dbg_fixed.rate_n_flags;
2499 mcs->rate_n_flags = base_rate;
2500 IWL_DEBUG_RATE("Fixed rate ON\n");
2504 IWL_DEBUG_RATE("Fixed rate OFF\n");
2507 static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2508 const char __user *user_buf, size_t count, loff_t *ppos)
2510 struct iwl4965_lq_sta *lq_sta = file->private_data;
2515 memset(buf, 0, sizeof(buf));
2516 buf_size = min(count, sizeof(buf) - 1);
2517 if (copy_from_user(buf, user_buf, buf_size))
2520 if (sscanf(buf, "%x", &parsed_rate) == 1)
2521 lq_sta->dbg_fixed.rate_n_flags = parsed_rate;
2523 lq_sta->dbg_fixed.rate_n_flags = 0;
2525 lq_sta->active_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2526 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2527 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2528 lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2530 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2531 lq_sta->lq.sta_id, lq_sta->dbg_fixed.rate_n_flags);
2533 if (lq_sta->dbg_fixed.rate_n_flags) {
2534 rs_fill_link_cmd(NULL, lq_sta, &lq_sta->dbg_fixed, &lq_sta->lq);
2535 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC);
2541 static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2542 char __user *user_buf, size_t count, loff_t *ppos)
2548 struct iwl4965_lq_sta *lq_sta = file->private_data;
2550 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
2551 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2552 lq_sta->total_failed, lq_sta->total_success,
2553 lq_sta->active_rate);
2554 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2555 lq_sta->dbg_fixed.rate_n_flags);
2556 desc += sprintf(buff+desc, "general:"
2557 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2558 lq_sta->lq.general_params.flags,
2559 lq_sta->lq.general_params.mimo_delimiter,
2560 lq_sta->lq.general_params.single_stream_ant_msk,
2561 lq_sta->lq.general_params.dual_stream_ant_msk);
2563 desc += sprintf(buff+desc, "agg:"
2564 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2565 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
2566 lq_sta->lq.agg_params.agg_dis_start_th,
2567 lq_sta->lq.agg_params.agg_frame_cnt_limit);
2569 desc += sprintf(buff+desc,
2570 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2571 lq_sta->lq.general_params.start_rate_index[0],
2572 lq_sta->lq.general_params.start_rate_index[1],
2573 lq_sta->lq.general_params.start_rate_index[2],
2574 lq_sta->lq.general_params.start_rate_index[3]);
2577 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
2578 desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
2579 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2581 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2584 static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2585 .write = rs_sta_dbgfs_scale_table_write,
2586 .read = rs_sta_dbgfs_scale_table_read,
2587 .open = open_file_generic,
2589 static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2590 char __user *user_buf, size_t count, loff_t *ppos)
2596 struct iwl4965_lq_sta *lq_sta = file->private_data;
2597 for (i = 0; i < LQ_SIZE; i++) {
2598 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2600 lq_sta->active_tbl == i?"*":"x",
2601 lq_sta->lq_info[i].lq_type,
2602 lq_sta->lq_info[i].is_SGI,
2603 lq_sta->lq_info[i].is_fat,
2604 lq_sta->lq_info[i].is_dup,
2605 lq_sta->lq_info[i].current_rate.rate_n_flags);
2606 for (j = 0; j < IWL_RATE_COUNT; j++) {
2607 desc += sprintf(buff+desc,
2608 "counter=%d success=%d %%=%d\n",
2609 lq_sta->lq_info[i].win[j].counter,
2610 lq_sta->lq_info[i].win[j].success_counter,
2611 lq_sta->lq_info[i].win[j].success_ratio);
2614 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2617 static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2618 .read = rs_sta_dbgfs_stats_table_read,
2619 .open = open_file_generic,
2622 static void rs_add_debugfs(void *priv, void *priv_sta,
2625 struct iwl4965_lq_sta *lq_sta = priv_sta;
2626 lq_sta->rs_sta_dbgfs_scale_table_file =
2627 debugfs_create_file("rate_scale_table", 0600, dir,
2628 lq_sta, &rs_sta_dbgfs_scale_table_ops);
2629 lq_sta->rs_sta_dbgfs_stats_table_file =
2630 debugfs_create_file("rate_stats_table", 0600, dir,
2631 lq_sta, &rs_sta_dbgfs_stats_table_ops);
2632 #ifdef CONFIG_IWL4965_HT
2633 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2634 debugfs_create_u8("tx_agg_tid_enable", 0600, dir,
2635 &lq_sta->tx_agg_tid_en);
2640 static void rs_remove_debugfs(void *priv, void *priv_sta)
2642 struct iwl4965_lq_sta *lq_sta = priv_sta;
2643 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2644 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
2645 #ifdef CONFIG_IWL4965_HT
2646 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2651 static struct rate_control_ops rs_ops = {
2654 .tx_status = rs_tx_status,
2655 .get_rate = rs_get_rate,
2656 .rate_init = rs_rate_init,
2660 .alloc_sta = rs_alloc_sta,
2661 .free_sta = rs_free_sta,
2662 #ifdef CONFIG_MAC80211_DEBUGFS
2663 .add_sta_debugfs = rs_add_debugfs,
2664 .remove_sta_debugfs = rs_remove_debugfs,
2668 int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2670 struct ieee80211_local *local = hw_to_local(hw);
2671 struct iwl_priv *priv = hw->priv;
2672 struct iwl4965_lq_sta *lq_sta;
2673 struct sta_info *sta;
2675 u32 samples = 0, success = 0, good = 0;
2676 unsigned long now = jiffies;
2678 u8 lq_type, antenna;
2682 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2683 if (!sta || !sta->rate_ctrl_priv) {
2685 IWL_DEBUG_RATE("leave - no private rate data!\n");
2687 IWL_DEBUG_RATE("leave - no station!\n");
2689 return sprintf(buf, "station %d not found\n", sta_id);
2692 lq_sta = (void *)sta->rate_ctrl_priv;
2694 lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type;
2695 antenna = lq_sta->lq_info[lq_sta->active_tbl].ant_type;
2697 if (is_legacy(lq_type))
2698 i = IWL_RATE_54M_INDEX;
2700 i = IWL_RATE_60M_INDEX;
2704 int active = lq_sta->active_tbl;
2707 sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2);
2709 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2710 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
2712 (lq_sta->lq_info[active].win[i].data & mask)
2715 samples += lq_sta->lq_info[active].win[i].counter;
2716 good += lq_sta->lq_info[active].win[i].success_counter;
2717 success += lq_sta->lq_info[active].win[i].success_counter *
2718 iwl4965_rates[i].ieee;
2720 if (lq_sta->lq_info[active].win[i].stamp) {
2722 jiffies_to_msecs(now -
2723 lq_sta->lq_info[active].win[i].stamp);
2725 if (delta > max_time)
2728 cnt += sprintf(&buf[cnt], "%5dms\n", delta);
2732 j = iwl4965_get_prev_ieee_rate(i);
2738 /* Display the average rate of all samples taken.
2740 * NOTE: We multiply # of samples by 2 since the IEEE measurement
2741 * added from iwl4965_rates is actually 2X the rate */
2743 cnt += sprintf(&buf[cnt],
2744 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2745 "%3d%% success (%d good packets over %d tries)\n",
2746 success / (2 * samples), (success * 5 / samples) % 10,
2747 max_time, good * 100 / samples, good, samples);
2749 cnt += sprintf(&buf[cnt], "\nAverage rate: 0Mbs\n");
2751 cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d "
2752 "active_search %d rate index %d\n", lq_type, antenna,
2753 lq_sta->search_better_tbl, sta->last_txrate_idx);
2759 void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
2761 struct iwl_priv *priv = hw->priv;
2763 priv->lq_mngr.lq_ready = 1;
2766 int iwl4965_rate_control_register(void)
2768 return ieee80211_rate_control_register(&rs_ops);
2771 void iwl4965_rate_control_unregister(void)
2773 ieee80211_rate_control_unregister(&rs_ops);