1 /******************************************************************************
3 * Copyright(c) 2005 - 2007 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>
31 #include <net/ieee80211.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/delay.h>
37 #include <linux/workqueue.h>
39 #include <net/mac80211.h>
40 #include <linux/wireless.h>
44 #include "../net/mac80211/ieee80211_rate.h"
47 #include "iwl-helpers.h"
49 #define RS_NAME "iwl-4965-rs"
51 #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
52 #define IWL_NUMBER_TRY 1
53 #define IWL_HT_NUMBER_TRY 3
55 #define IWL_RATE_MAX_WINDOW 62
56 #define IWL_RATE_HIGH_TH 10880
57 #define IWL_RATE_MIN_FAILURE_TH 6
58 #define IWL_RATE_MIN_SUCCESS_TH 8
59 #define IWL_RATE_DECREASE_TH 1920
60 #define IWL_RATE_INCREASE_TH 8960
61 #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */
63 static u8 rs_ht_to_legacy[] = {
64 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
65 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
67 IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
68 IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
69 IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
70 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
75 } __attribute__ ((packed));
77 struct iwl_rate_scale_data {
86 struct iwl_scale_tbl_info {
87 enum iwl_table_type lq_type;
88 enum iwl_antenna_type antenna_type;
94 struct iwl_rate current_rate;
95 struct iwl_rate_scale_data win[IWL_RATE_COUNT];
98 struct iwl_rate_scale_priv {
102 u8 search_better_tbl;
104 u32 table_count_limit;
105 u32 max_failure_limit;
106 u32 max_success_limit;
120 u16 active_siso_rate;
121 u16 active_mimo_rate;
122 u16 active_rate_basic;
123 struct iwl_link_quality_cmd lq;
124 struct iwl_scale_tbl_info lq_info[LQ_SIZE];
125 #ifdef CONFIG_MAC80211_DEBUGFS
126 struct dentry *rs_sta_dbgfs_scale_table_file;
127 struct iwl_rate dbg_fixed;
128 struct iwl_priv *drv;
132 static void rs_rate_scale_perform(struct iwl_priv *priv,
133 struct net_device *dev,
134 struct ieee80211_hdr *hdr,
135 struct sta_info *sta);
136 static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
137 struct iwl_rate *tx_mcs,
138 struct iwl_link_quality_cmd *tbl);
141 #ifdef CONFIG_MAC80211_DEBUGFS
142 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
143 struct iwl_rate *mcs, int index);
145 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
146 struct iwl_rate *mcs, int index)
149 static s32 expected_tpt_A[IWL_RATE_COUNT] = {
150 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
153 static s32 expected_tpt_G[IWL_RATE_COUNT] = {
154 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
157 static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = {
158 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
161 static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
162 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
165 static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = {
166 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
169 static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = {
170 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
173 static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = {
174 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
177 static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
178 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
181 static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = {
182 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
185 static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
186 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
189 static int iwl_lq_sync_callback(struct iwl_priv *priv,
190 struct iwl_cmd *cmd, struct sk_buff *skb)
192 /*We didn't cache the SKB; let the caller free it */
196 static inline u8 iwl_rate_get_rate(u32 rate_n_flags)
198 return (u8)(rate_n_flags & 0xFF);
201 static int rs_send_lq_cmd(struct iwl_priv *priv,
202 struct iwl_link_quality_cmd *lq, u8 flags)
204 #ifdef CONFIG_IWLWIFI_DEBUG
209 struct iwl_host_cmd cmd = {
210 .id = REPLY_TX_LINK_QUALITY_CMD,
211 .len = sizeof(struct iwl_link_quality_cmd),
216 if ((lq->sta_id == 0xFF) &&
217 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
220 if (lq->sta_id == 0xFF)
221 lq->sta_id = IWL_AP_ID;
223 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
224 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
225 lq->general_params.single_stream_ant_msk,
226 lq->general_params.dual_stream_ant_msk);
227 #ifdef CONFIG_IWLWIFI_DEBUG
228 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
229 IWL_DEBUG_RATE("lq index %d 0x%X\n",
230 i, lq->rs_table[i].rate_n_flags);
233 if (flags & CMD_ASYNC)
234 cmd.meta.u.callback = iwl_lq_sync_callback;
236 if (iwl_is_associated(priv) && priv->assoc_station_added &&
237 priv->lq_mngr.lq_ready)
238 rc = iwl_send_cmd(priv, &cmd);
243 static int rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
246 window->success_counter = 0;
247 window->success_ratio = IWL_INVALID_VALUE;
249 window->average_tpt = IWL_INVALID_VALUE;
255 static int rs_collect_tx_data(struct iwl_rate_scale_data *windows,
256 int scale_index, s32 tpt, u32 status)
259 struct iwl_rate_scale_data *window = NULL;
261 u8 win_size = IWL_RATE_MAX_WINDOW;
267 if (scale_index >= IWL_RATE_COUNT)
270 window = &(windows[scale_index]);
272 if (window->counter >= win_size) {
274 window->counter = win_size - 1;
276 mask = (mask << (win_size - 1));
277 if ((window->data & mask)) {
278 window->data &= ~mask;
279 window->success_counter = window->success_counter - 1;
283 window->counter = window->counter + 1;
285 window->data = (mask << 1);
287 window->success_counter = window->success_counter + 1;
291 if (window->counter > 0)
292 window->success_ratio = 128 * (100 * window->success_counter)
295 window->success_ratio = IWL_INVALID_VALUE;
297 fail_count = window->counter - window->success_counter;
299 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
300 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
301 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
303 window->average_tpt = IWL_INVALID_VALUE;
305 window->stamp = jiffies;
310 int static rs_mcs_from_tbl(struct iwl_rate *mcs_rate,
311 struct iwl_scale_tbl_info *tbl,
312 int index, u8 use_green)
316 if (is_legacy(tbl->lq_type)) {
317 mcs_rate->rate_n_flags = iwl_rates[index].plcp;
318 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
319 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
321 } else if (is_siso(tbl->lq_type)) {
322 if (index > IWL_LAST_OFDM_RATE)
323 index = IWL_LAST_OFDM_RATE;
324 mcs_rate->rate_n_flags = iwl_rates[index].plcp_siso |
327 if (index > IWL_LAST_OFDM_RATE)
328 index = IWL_LAST_OFDM_RATE;
329 mcs_rate->rate_n_flags = iwl_rates[index].plcp_mimo |
333 switch (tbl->antenna_type) {
335 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
338 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
341 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
347 if (is_legacy(tbl->lq_type))
352 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
354 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
357 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
360 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
361 if (is_siso(tbl->lq_type))
362 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
367 static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate,
368 int phymode, struct iwl_scale_tbl_info *tbl,
374 index = iwl_rate_index_from_plcp(mcs_rate->rate_n_flags);
376 if (index == IWL_RATE_INVALID) {
383 tbl->antenna_type = ANT_BOTH;
385 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
386 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
388 if (ant_msk == RATE_MCS_ANT_AB_MSK)
389 tbl->lq_type = LQ_NONE;
392 if (phymode == MODE_IEEE80211A)
397 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
398 tbl->antenna_type = ANT_MAIN;
400 tbl->antenna_type = ANT_AUX;
404 } else if (iwl_rate_get_rate(mcs_rate->rate_n_flags)
405 <= IWL_RATE_SISO_60M_PLCP) {
406 tbl->lq_type = LQ_SISO;
408 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
409 if (ant_msk == RATE_MCS_ANT_AB_MSK)
410 tbl->lq_type = LQ_NONE;
412 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
413 tbl->antenna_type = ANT_MAIN;
415 tbl->antenna_type = ANT_AUX;
417 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
420 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
421 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
424 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
429 tbl->lq_type = LQ_MIMO;
430 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
433 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
434 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
437 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
444 static inline void rs_toggle_antenna(struct iwl_rate *new_rate,
445 struct iwl_scale_tbl_info *tbl)
447 if (tbl->antenna_type == ANT_AUX) {
448 tbl->antenna_type = ANT_MAIN;
449 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK;
450 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
452 tbl->antenna_type = ANT_AUX;
453 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
454 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
458 static inline s8 rs_use_green(struct iwl_priv *priv)
461 #ifdef CONFIG_IWLWIFI_HT
462 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
465 if ((priv->current_assoc_ht.is_green_field) &&
466 !(priv->current_assoc_ht.operating_mode & 0x4))
468 #endif /*CONFIG_IWLWIFI_HT */
473 * rs_get_supported_rates - get the available rates
475 * if management frame or broadcast frame only return
476 * basic available rates.
479 static void rs_get_supported_rates(struct iwl_rate_scale_priv *lq_data,
480 struct ieee80211_hdr *hdr,
481 enum iwl_table_type rate_type,
484 if (is_legacy(rate_type))
485 *data_rate = lq_data->active_rate;
487 if (is_siso(rate_type))
488 *data_rate = lq_data->active_siso_rate;
490 *data_rate = lq_data->active_mimo_rate;
493 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
494 lq_data->active_rate_basic)
495 *data_rate = lq_data->active_rate_basic;
498 static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
500 u8 high = IWL_RATE_INVALID;
501 u8 low = IWL_RATE_INVALID;
503 /* 802.11A or ht walks to the next literal adjascent rate in
505 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
509 /* Find the previous rate that is in the rate mask */
511 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
512 if (rate_mask & mask) {
518 /* Find the next rate that is in the rate mask */
520 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
521 if (rate_mask & mask) {
527 return (high << 8) | low;
531 while (low != IWL_RATE_INVALID) {
532 low = iwl_rates[low].prev_rs;
533 if (low == IWL_RATE_INVALID)
535 if (rate_mask & (1 << low))
537 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
541 while (high != IWL_RATE_INVALID) {
542 high = iwl_rates[high].next_rs;
543 if (high == IWL_RATE_INVALID)
545 if (rate_mask & (1 << high))
547 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
550 return (high << 8) | low;
553 static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data,
554 struct iwl_scale_tbl_info *tbl, u8 scale_index,
555 u8 ht_possible, struct iwl_rate *mcs_rate)
560 u8 switch_to_legacy = 0;
561 u8 is_green = lq_data->is_green;
563 /* check if we need to switch from HT to legacy rates.
564 * assumption is that mandatory rates (1Mbps or 6Mbps)
565 * are always supported (spec demand) */
566 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
567 switch_to_legacy = 1;
568 scale_index = rs_ht_to_legacy[scale_index];
569 if (lq_data->phymode == MODE_IEEE80211A)
574 if ((tbl->antenna_type == ANT_BOTH) ||
575 (tbl->antenna_type == ANT_NONE))
576 tbl->antenna_type = ANT_MAIN;
582 rs_get_supported_rates(lq_data, NULL, tbl->lq_type, &rate_mask);
584 /* mask with station rate restriction */
585 if (is_legacy(tbl->lq_type)) {
586 if (lq_data->phymode == (u8) MODE_IEEE80211A)
587 rate_mask = (u16)(rate_mask &
588 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
590 rate_mask = (u16)(rate_mask & lq_data->supp_rates);
593 /* if we did switched from HT to legacy check current rate */
594 if ((switch_to_legacy) &&
595 (rate_mask & (1 << scale_index))) {
596 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
600 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
601 low = high_low & 0xff;
603 if (low != IWL_RATE_INVALID)
604 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
606 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
611 static void rs_tx_status(void *priv_rate,
612 struct net_device *dev,
614 struct ieee80211_tx_status *tx_resp)
618 int rs_index, index = 0;
619 struct iwl_rate_scale_priv *lq;
620 struct iwl_link_quality_cmd *table;
621 struct sta_info *sta;
622 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
623 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
624 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
625 struct iwl_rate_scale_data *window = NULL;
626 struct iwl_rate_scale_data *search_win = NULL;
627 struct iwl_rate tx_mcs;
628 struct iwl_scale_tbl_info tbl_type;
629 struct iwl_scale_tbl_info *curr_tbl, *search_tbl;
631 u16 fc = le16_to_cpu(hdr->frame_control);
634 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
636 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
639 retries = tx_resp->retry_count;
645 sta = sta_info_get(local, hdr->addr1);
647 if (!sta || !sta->rate_ctrl_priv) {
653 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
655 if (!priv->lq_mngr.lq_ready)
658 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added)
662 active_index = lq->active_tbl;
664 lq->antenna = (lq->valid_antenna & local->hw.conf.antenna_sel_tx);
666 lq->antenna = lq->valid_antenna;
668 lq->antenna = lq->valid_antenna;
669 curr_tbl = &(lq->lq_info[active_index]);
670 search_tbl = &(lq->lq_info[(1 - active_index)]);
671 window = (struct iwl_rate_scale_data *)
673 search_win = (struct iwl_rate_scale_data *)
674 &(search_tbl->win[0]);
676 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
678 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
679 &tbl_type, &rs_index);
680 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
681 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
682 rs_index, tx_mcs.rate_n_flags);
688 (tx_mcs.rate_n_flags !=
689 le32_to_cpu(table->rs_table[0].rate_n_flags))) {
690 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
692 le32_to_cpu(table->rs_table[0].rate_n_flags));
698 tx_mcs.rate_n_flags =
699 le32_to_cpu(table->rs_table[index].rate_n_flags);
700 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
701 &tbl_type, &rs_index);
703 if ((tbl_type.lq_type == search_tbl->lq_type) &&
704 (tbl_type.antenna_type == search_tbl->antenna_type) &&
705 (tbl_type.is_SGI == search_tbl->is_SGI)) {
706 if (search_tbl->expected_tpt)
707 tpt = search_tbl->expected_tpt[rs_index];
710 rs_collect_tx_data(search_win,
712 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
713 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
714 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
715 if (curr_tbl->expected_tpt)
716 tpt = curr_tbl->expected_tpt[rs_index];
719 rs_collect_tx_data(window, rs_index, tpt, 0);
728 if (!tx_resp->retry_count)
729 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
731 tx_mcs.rate_n_flags =
732 le32_to_cpu(table->rs_table[index].rate_n_flags);
734 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
735 &tbl_type, &rs_index);
737 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
742 if ((tbl_type.lq_type == search_tbl->lq_type) &&
743 (tbl_type.antenna_type == search_tbl->antenna_type) &&
744 (tbl_type.is_SGI == search_tbl->is_SGI)) {
745 if (search_tbl->expected_tpt)
746 tpt = search_tbl->expected_tpt[rs_index];
749 rs_collect_tx_data(search_win,
750 rs_index, tpt, status);
751 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
752 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
753 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
754 if (curr_tbl->expected_tpt)
755 tpt = curr_tbl->expected_tpt[rs_index];
758 rs_collect_tx_data(window, rs_index, tpt, status);
761 if (lq->stay_in_tbl) {
768 rs_rate_scale_perform(priv, dev, hdr, sta);
773 static u8 rs_is_ant_connected(u8 valid_antenna,
774 enum iwl_antenna_type antenna_type)
776 if (antenna_type == ANT_AUX)
777 return ((valid_antenna & 0x2) ? 1:0);
778 else if (antenna_type == ANT_MAIN)
779 return ((valid_antenna & 0x1) ? 1:0);
780 else if (antenna_type == ANT_BOTH) {
781 if ((valid_antenna & 0x3) == 0x3)
790 static u8 rs_is_other_ant_connected(u8 valid_antenna,
791 enum iwl_antenna_type antenna_type)
793 if (antenna_type == ANT_AUX)
794 return (rs_is_ant_connected(valid_antenna, ANT_MAIN));
796 return (rs_is_ant_connected(valid_antenna, ANT_AUX));
801 static void rs_set_stay_in_table(u8 is_legacy,
802 struct iwl_rate_scale_priv *lq_data)
804 IWL_DEBUG_HT("we are staying in the same table\n");
805 lq_data->stay_in_tbl = 1;
807 lq_data->table_count_limit = IWL_LEGACY_TABLE_COUNT;
808 lq_data->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
809 lq_data->max_success_limit = IWL_LEGACY_TABLE_COUNT;
811 lq_data->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
812 lq_data->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
813 lq_data->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
815 lq_data->table_count = 0;
816 lq_data->total_failed = 0;
817 lq_data->total_success = 0;
820 static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data,
821 struct iwl_scale_tbl_info *tbl)
823 if (is_legacy(tbl->lq_type)) {
824 if (!is_a_band(tbl->lq_type))
825 tbl->expected_tpt = expected_tpt_G;
827 tbl->expected_tpt = expected_tpt_A;
828 } else if (is_siso(tbl->lq_type)) {
829 if (tbl->is_fat && !lq_data->is_dup)
831 tbl->expected_tpt = expected_tpt_siso40MHzSGI;
833 tbl->expected_tpt = expected_tpt_siso40MHz;
834 else if (tbl->is_SGI)
835 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
837 tbl->expected_tpt = expected_tpt_siso20MHz;
839 } else if (is_mimo(tbl->lq_type)) {
840 if (tbl->is_fat && !lq_data->is_dup)
842 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
844 tbl->expected_tpt = expected_tpt_mimo40MHz;
845 else if (tbl->is_SGI)
846 tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
848 tbl->expected_tpt = expected_tpt_mimo20MHz;
850 tbl->expected_tpt = expected_tpt_G;
853 #ifdef CONFIG_IWLWIFI_HT
854 static s32 rs_get_best_rate(struct iwl_priv *priv,
855 struct iwl_rate_scale_priv *lq_data,
856 struct iwl_scale_tbl_info *tbl,
857 u16 rate_mask, s8 index, s8 rate)
859 struct iwl_scale_tbl_info *active_tbl =
860 &(lq_data->lq_info[lq_data->active_tbl]);
861 s32 new_rate, high, low, start_hi;
862 s32 active_sr = active_tbl->win[index].success_ratio;
863 s32 *tpt_tbl = tbl->expected_tpt;
864 s32 active_tpt = active_tbl->expected_tpt[index];
867 new_rate = high = low = start_hi = IWL_RATE_INVALID;
870 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
872 low = high_low & 0xff;
873 high = (high_low >> 8) & 0xff;
875 if ((((100 * tpt_tbl[rate]) > lq_data->last_tpt) &&
876 ((active_sr > IWL_RATE_DECREASE_TH) &&
877 (active_sr <= IWL_RATE_HIGH_TH) &&
878 (tpt_tbl[rate] <= active_tpt))) ||
879 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
880 (tpt_tbl[rate] > active_tpt))) {
882 if (start_hi != IWL_RATE_INVALID) {
887 if (low != IWL_RATE_INVALID)
892 if (new_rate != IWL_RATE_INVALID)
894 else if (high != IWL_RATE_INVALID) {
906 #endif /* CONFIG_IWLWIFI_HT */
908 static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
910 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
913 static int rs_switch_to_mimo(struct iwl_priv *priv,
914 struct iwl_rate_scale_priv *lq_data,
915 struct iwl_scale_tbl_info *tbl, int index)
918 #ifdef CONFIG_IWLWIFI_HT
921 s8 is_green = lq_data->is_green;
923 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
926 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
927 tbl->lq_type = LQ_MIMO;
928 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
931 if (priv->current_assoc_ht.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
934 if (!rs_is_both_ant_supp(lq_data->antenna))
938 tbl->is_dup = lq_data->is_dup;
940 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
946 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
950 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
955 rs_get_expected_tpt_table(lq_data, tbl);
957 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
959 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
960 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
962 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
964 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
965 tbl->current_rate.rate_n_flags, is_green);
967 #endif /*CONFIG_IWLWIFI_HT */
971 static int rs_switch_to_siso(struct iwl_priv *priv,
972 struct iwl_rate_scale_priv *lq_data,
973 struct iwl_scale_tbl_info *tbl, int index)
976 #ifdef CONFIG_IWLWIFI_HT
978 u8 is_green = lq_data->is_green;
981 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
982 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
986 tbl->is_dup = lq_data->is_dup;
987 tbl->lq_type = LQ_SISO;
989 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
992 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
998 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
1002 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
1010 rs_get_expected_tpt_table(lq_data, tbl);
1011 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
1013 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
1014 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1015 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
1019 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1020 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1021 tbl->current_rate.rate_n_flags, is_green);
1023 #endif /*CONFIG_IWLWIFI_HT */
1027 static int rs_move_legacy_other(struct iwl_priv *priv,
1028 struct iwl_rate_scale_priv *lq_data,
1032 struct iwl_scale_tbl_info *tbl =
1033 &(lq_data->lq_info[lq_data->active_tbl]);
1034 struct iwl_scale_tbl_info *search_tbl =
1035 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1036 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1037 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1038 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1039 u8 start_action = tbl->action;
1042 switch (tbl->action) {
1043 case IWL_LEGACY_SWITCH_ANTENNA:
1044 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1046 search_tbl->lq_type = LQ_NONE;
1047 lq_data->action_counter++;
1048 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1050 if (!rs_is_other_ant_connected(lq_data->antenna,
1054 memcpy(search_tbl, tbl, sz);
1056 rs_toggle_antenna(&(search_tbl->current_rate),
1058 rs_get_expected_tpt_table(lq_data, search_tbl);
1059 lq_data->search_better_tbl = 1;
1062 case IWL_LEGACY_SWITCH_SISO:
1063 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1064 memcpy(search_tbl, tbl, sz);
1065 search_tbl->lq_type = LQ_SISO;
1066 search_tbl->is_SGI = 0;
1067 search_tbl->is_fat = 0;
1068 rc = rs_switch_to_siso(priv, lq_data, search_tbl,
1071 lq_data->search_better_tbl = 1;
1072 lq_data->action_counter = 0;
1078 case IWL_LEGACY_SWITCH_MIMO:
1079 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1080 memcpy(search_tbl, tbl, sz);
1081 search_tbl->lq_type = LQ_MIMO;
1082 search_tbl->is_SGI = 0;
1083 search_tbl->is_fat = 0;
1084 search_tbl->antenna_type = ANT_BOTH;
1085 rc = rs_switch_to_mimo(priv, lq_data, search_tbl,
1088 lq_data->search_better_tbl = 1;
1089 lq_data->action_counter = 0;
1096 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1097 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1099 if (tbl->action == start_action)
1107 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1108 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1113 static int rs_move_siso_to_other(struct iwl_priv *priv,
1114 struct iwl_rate_scale_priv *lq_data,
1118 u8 is_green = lq_data->is_green;
1119 struct iwl_scale_tbl_info *tbl =
1120 &(lq_data->lq_info[lq_data->active_tbl]);
1121 struct iwl_scale_tbl_info *search_tbl =
1122 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1123 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1124 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1125 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1126 u8 start_action = tbl->action;
1129 lq_data->action_counter++;
1130 switch (tbl->action) {
1131 case IWL_SISO_SWITCH_ANTENNA:
1132 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1133 search_tbl->lq_type = LQ_NONE;
1134 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1136 if (!rs_is_other_ant_connected(lq_data->antenna,
1140 memcpy(search_tbl, tbl, sz);
1141 search_tbl->action = IWL_SISO_SWITCH_MIMO;
1142 rs_toggle_antenna(&(search_tbl->current_rate),
1144 lq_data->search_better_tbl = 1;
1148 case IWL_SISO_SWITCH_MIMO:
1149 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1150 memcpy(search_tbl, tbl, sz);
1151 search_tbl->lq_type = LQ_MIMO;
1152 search_tbl->is_SGI = 0;
1153 search_tbl->is_fat = 0;
1154 search_tbl->antenna_type = ANT_BOTH;
1155 rc = rs_switch_to_mimo(priv, lq_data, search_tbl,
1158 lq_data->search_better_tbl = 1;
1163 case IWL_SISO_SWITCH_GI:
1164 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1165 memcpy(search_tbl, tbl, sz);
1166 search_tbl->action = 0;
1167 if (search_tbl->is_SGI)
1168 search_tbl->is_SGI = 0;
1170 search_tbl->is_SGI = 1;
1173 lq_data->search_better_tbl = 1;
1174 if ((tbl->lq_type == LQ_SISO) &&
1176 s32 tpt = lq_data->last_tpt / 100;
1177 if (((!tbl->is_fat) &&
1178 (tpt >= expected_tpt_siso20MHz[index])) ||
1180 (tpt >= expected_tpt_siso40MHz[index])))
1181 lq_data->search_better_tbl = 0;
1183 rs_get_expected_tpt_table(lq_data, search_tbl);
1184 rs_mcs_from_tbl(&search_tbl->current_rate,
1185 search_tbl, index, is_green);
1189 if (tbl->action > IWL_SISO_SWITCH_GI)
1190 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1192 if (tbl->action == start_action)
1199 if (tbl->action > IWL_SISO_SWITCH_GI)
1200 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1204 static int rs_move_mimo_to_other(struct iwl_priv *priv,
1205 struct iwl_rate_scale_priv *lq_data,
1209 s8 is_green = lq_data->is_green;
1210 struct iwl_scale_tbl_info *tbl =
1211 &(lq_data->lq_info[lq_data->active_tbl]);
1212 struct iwl_scale_tbl_info *search_tbl =
1213 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1214 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1215 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1216 u8 start_action = tbl->action;
1219 lq_data->action_counter++;
1220 switch (tbl->action) {
1221 case IWL_MIMO_SWITCH_ANTENNA_A:
1222 case IWL_MIMO_SWITCH_ANTENNA_B:
1223 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1224 memcpy(search_tbl, tbl, sz);
1225 search_tbl->lq_type = LQ_SISO;
1226 search_tbl->is_SGI = 0;
1227 search_tbl->is_fat = 0;
1228 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1229 search_tbl->antenna_type = ANT_MAIN;
1231 search_tbl->antenna_type = ANT_AUX;
1233 rc = rs_switch_to_siso(priv, lq_data, search_tbl,
1236 lq_data->search_better_tbl = 1;
1241 case IWL_MIMO_SWITCH_GI:
1242 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1243 memcpy(search_tbl, tbl, sz);
1244 search_tbl->lq_type = LQ_MIMO;
1245 search_tbl->antenna_type = ANT_BOTH;
1246 search_tbl->action = 0;
1247 if (search_tbl->is_SGI)
1248 search_tbl->is_SGI = 0;
1250 search_tbl->is_SGI = 1;
1251 lq_data->search_better_tbl = 1;
1252 if ((tbl->lq_type == LQ_MIMO) &&
1254 s32 tpt = lq_data->last_tpt / 100;
1255 if (((!tbl->is_fat) &&
1256 (tpt >= expected_tpt_mimo20MHz[index])) ||
1258 (tpt >= expected_tpt_mimo40MHz[index])))
1259 lq_data->search_better_tbl = 0;
1261 rs_get_expected_tpt_table(lq_data, search_tbl);
1262 rs_mcs_from_tbl(&search_tbl->current_rate,
1263 search_tbl, index, is_green);
1268 if (tbl->action > IWL_MIMO_SWITCH_GI)
1269 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1271 if (tbl->action == start_action)
1278 if (tbl->action > IWL_MIMO_SWITCH_GI)
1279 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1284 static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data)
1286 struct iwl_scale_tbl_info *tbl;
1289 int flush_interval_passed = 0;
1291 active_tbl = lq_data->active_tbl;
1293 tbl = &(lq_data->lq_info[active_tbl]);
1295 if (lq_data->stay_in_tbl) {
1297 if (lq_data->flush_timer)
1298 flush_interval_passed =
1300 (unsigned long)(lq_data->flush_timer +
1301 IWL_RATE_SCALE_FLUSH_INTVL));
1303 flush_interval_passed = 0;
1304 if ((lq_data->total_failed > lq_data->max_failure_limit) ||
1305 (lq_data->total_success > lq_data->max_success_limit) ||
1306 ((!lq_data->search_better_tbl) && (lq_data->flush_timer)
1307 && (flush_interval_passed))) {
1308 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1309 lq_data->total_failed,
1310 lq_data->total_success,
1311 flush_interval_passed);
1312 lq_data->stay_in_tbl = 0;
1313 lq_data->total_failed = 0;
1314 lq_data->total_success = 0;
1315 lq_data->flush_timer = 0;
1316 } else if (lq_data->table_count > 0) {
1317 lq_data->table_count++;
1318 if (lq_data->table_count >=
1319 lq_data->table_count_limit) {
1320 lq_data->table_count = 0;
1322 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1323 for (i = 0; i < IWL_RATE_COUNT; i++)
1324 rs_rate_scale_clear_window(
1329 if (!lq_data->stay_in_tbl) {
1330 for (i = 0; i < IWL_RATE_COUNT; i++)
1331 rs_rate_scale_clear_window(&(tbl->win[i]));
1336 static void rs_rate_scale_perform(struct iwl_priv *priv,
1337 struct net_device *dev,
1338 struct ieee80211_hdr *hdr,
1339 struct sta_info *sta)
1341 int low = IWL_RATE_INVALID;
1342 int high = IWL_RATE_INVALID;
1345 struct iwl_rate_scale_data *window = NULL;
1346 int current_tpt = IWL_INVALID_VALUE;
1347 int low_tpt = IWL_INVALID_VALUE;
1348 int high_tpt = IWL_INVALID_VALUE;
1350 s8 scale_action = 0;
1353 struct iwl_rate_scale_priv *lq_data;
1354 struct iwl_scale_tbl_info *tbl, *tbl1;
1355 u16 rate_scale_index_msk = 0;
1356 struct iwl_rate mcs_rate;
1362 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1364 fc = le16_to_cpu(hdr->frame_control);
1365 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1366 /* Send management frames and broadcast/multicast data using
1368 /* TODO: this could probably be improved.. */
1372 if (!sta || !sta->rate_ctrl_priv)
1375 if (!priv->lq_mngr.lq_ready) {
1376 IWL_DEBUG_RATE("still rate scaling not ready\n");
1379 lq_data = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1381 if (!lq_data->search_better_tbl)
1382 active_tbl = lq_data->active_tbl;
1384 active_tbl = 1 - lq_data->active_tbl;
1386 tbl = &(lq_data->lq_info[active_tbl]);
1387 is_green = lq_data->is_green;
1389 index = sta->last_txrate;
1391 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1394 rs_get_supported_rates(lq_data, hdr, tbl->lq_type,
1397 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1399 /* mask with station rate restriction */
1400 if (is_legacy(tbl->lq_type)) {
1401 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1402 rate_scale_index_msk = (u16) (rate_mask &
1403 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
1405 rate_scale_index_msk = (u16) (rate_mask &
1406 lq_data->supp_rates);
1409 rate_scale_index_msk = rate_mask;
1411 if (!rate_scale_index_msk)
1412 rate_scale_index_msk = rate_mask;
1414 if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
1415 index = IWL_INVALID_VALUE;
1418 /* get the lowest availabe rate */
1419 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1420 if ((1 << i) & rate_scale_index_msk)
1424 if (index == IWL_INVALID_VALUE) {
1425 IWL_WARNING("Can not find a suitable rate\n");
1430 if (!tbl->expected_tpt)
1431 rs_get_expected_tpt_table(lq_data, tbl);
1433 window = &(tbl->win[index]);
1435 fail_count = window->counter - window->success_counter;
1436 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1437 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
1438 || (tbl->expected_tpt == NULL)) {
1439 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1441 window->success_counter, window->counter, index);
1442 window->average_tpt = IWL_INVALID_VALUE;
1443 rs_stay_in_table(lq_data);
1445 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1446 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1447 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1452 window->average_tpt = ((window->success_ratio *
1453 tbl->expected_tpt[index] + 64) / 128);
1455 if (lq_data->search_better_tbl) {
1456 int success_limit = IWL_RATE_SCALE_SWITCH;
1458 if ((window->success_ratio > success_limit) ||
1459 (window->average_tpt > lq_data->last_tpt)) {
1460 if (!is_legacy(tbl->lq_type)) {
1461 IWL_DEBUG_HT("LQ: we are switching to HT"
1462 " rate suc %d current tpt %d"
1464 window->success_ratio,
1465 window->average_tpt,
1467 lq_data->enable_counter = 1;
1469 lq_data->active_tbl = active_tbl;
1470 current_tpt = window->average_tpt;
1472 tbl->lq_type = LQ_NONE;
1473 active_tbl = lq_data->active_tbl;
1474 tbl = &(lq_data->lq_info[active_tbl]);
1476 index = iwl_rate_index_from_plcp(
1477 tbl->current_rate.rate_n_flags);
1480 current_tpt = lq_data->last_tpt;
1481 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1483 lq_data->search_better_tbl = 0;
1488 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
1490 low = high_low & 0xff;
1491 high = (high_low >> 8) & 0xff;
1493 current_tpt = window->average_tpt;
1495 if (low != IWL_RATE_INVALID)
1496 low_tpt = tbl->win[low].average_tpt;
1498 if (high != IWL_RATE_INVALID)
1499 high_tpt = tbl->win[high].average_tpt;
1504 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
1505 (current_tpt == 0)) {
1506 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1508 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1509 (high_tpt == IWL_INVALID_VALUE))
1511 else if ((low_tpt != IWL_INVALID_VALUE) &&
1512 (high_tpt != IWL_INVALID_VALUE) &&
1513 (low_tpt < current_tpt) &&
1514 (high_tpt < current_tpt))
1517 if (high_tpt != IWL_INVALID_VALUE) {
1518 if (high_tpt > current_tpt)
1522 ("decrease rate because of high tpt\n");
1525 } else if (low_tpt != IWL_INVALID_VALUE) {
1526 if (low_tpt > current_tpt) {
1528 ("decrease rate because of low tpt\n");
1535 if (scale_action == -1) {
1536 if ((low != IWL_RATE_INVALID) &&
1537 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1538 (current_tpt > (100 * tbl->expected_tpt[low]))))
1540 } else if ((scale_action == 1) &&
1541 (window->success_ratio < IWL_RATE_INCREASE_TH))
1544 switch (scale_action) {
1546 if (low != IWL_RATE_INVALID) {
1552 if (high != IWL_RATE_INVALID) {
1563 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1564 "high %d type %d\n",
1565 index, scale_action, low, high, tbl->lq_type);
1569 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1570 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1571 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1573 rs_stay_in_table(lq_data);
1575 if (!update_lq && !done_search && !lq_data->stay_in_tbl) {
1576 lq_data->last_tpt = current_tpt;
1578 if (is_legacy(tbl->lq_type))
1579 rs_move_legacy_other(priv, lq_data, index);
1580 else if (is_siso(tbl->lq_type))
1581 rs_move_siso_to_other(priv, lq_data, index);
1583 rs_move_mimo_to_other(priv, lq_data, index);
1585 if (lq_data->search_better_tbl) {
1586 tbl = &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1587 for (i = 0; i < IWL_RATE_COUNT; i++)
1588 rs_rate_scale_clear_window(&(tbl->win[i]));
1590 index = iwl_rate_index_from_plcp(
1591 tbl->current_rate.rate_n_flags);
1593 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1594 tbl->current_rate.rate_n_flags, index);
1595 rs_fill_link_cmd(lq_data, &tbl->current_rate,
1597 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1599 tbl1 = &(lq_data->lq_info[lq_data->active_tbl]);
1601 if (is_legacy(tbl1->lq_type) &&
1602 #ifdef CONFIG_IWLWIFI_HT
1603 !priv->current_assoc_ht.is_ht &&
1605 (lq_data->action_counter >= 1)) {
1606 lq_data->action_counter = 0;
1607 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1608 rs_set_stay_in_table(1, lq_data);
1611 if (lq_data->enable_counter &&
1612 (lq_data->action_counter >= IWL_ACTION_LIMIT)) {
1613 #ifdef CONFIG_IWLWIFI_HT_AGG
1614 if ((lq_data->last_tpt > TID_AGG_TPT_THREHOLD) &&
1615 (priv->lq_mngr.agg_ctrl.auto_agg)) {
1616 priv->lq_mngr.agg_ctrl.tid_retry =
1618 schedule_work(&priv->agg_work);
1620 #endif /*CONFIG_IWLWIFI_HT_AGG */
1621 lq_data->action_counter = 0;
1622 rs_set_stay_in_table(0, lq_data);
1625 if ((!update_lq) && (!done_search) && (!lq_data->flush_timer))
1626 lq_data->flush_timer = jiffies;
1630 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
1632 sta->last_txrate = i;
1634 /* sta->txrate is an index to A mode rates which start
1635 * at IWL_FIRST_OFDM_RATE
1637 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1638 sta->txrate = i - IWL_FIRST_OFDM_RATE;
1646 static void rs_initialize_lq(struct iwl_priv *priv,
1647 struct sta_info *sta)
1650 struct iwl_rate_scale_priv *lq;
1651 struct iwl_scale_tbl_info *tbl;
1654 u8 use_green = rs_use_green(priv);
1655 struct iwl_rate mcs_rate;
1657 if (!sta || !sta->rate_ctrl_priv)
1660 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1661 i = sta->last_txrate;
1663 if ((lq->lq.sta_id == 0xff) &&
1664 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
1667 if (!lq->search_better_tbl)
1668 active_tbl = lq->active_tbl;
1670 active_tbl = 1 - lq->active_tbl;
1672 tbl = &(lq->lq_info[active_tbl]);
1674 if ((i < 0) || (i >= IWL_RATE_COUNT))
1677 mcs_rate.rate_n_flags = iwl_rates[i].plcp ;
1678 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
1679 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
1681 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
1682 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
1684 tbl->antenna_type = ANT_AUX;
1685 rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx);
1686 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
1687 rs_toggle_antenna(&mcs_rate, tbl);
1689 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
1690 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
1691 rs_get_expected_tpt_table(lq, tbl);
1692 rs_fill_link_cmd(lq, &mcs_rate, &lq->lq);
1693 rs_send_lq_cmd(priv, &lq->lq, CMD_ASYNC);
1698 static struct ieee80211_rate *rs_get_lowest_rate(struct ieee80211_local
1701 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
1704 for (i = 0; i < mode->num_rates; i++) {
1705 struct ieee80211_rate *rate = &mode->rates[i];
1707 if (rate->flags & IEEE80211_RATE_SUPPORTED)
1711 return &mode->rates[0];
1714 static struct ieee80211_rate *rs_get_rate(void *priv_rate,
1715 struct net_device *dev,
1716 struct sk_buff *skb,
1717 struct rate_control_extra
1722 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1723 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1724 struct sta_info *sta;
1726 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1727 struct iwl_rate_scale_priv *lq;
1729 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1731 memset(extra, 0, sizeof(*extra));
1733 fc = le16_to_cpu(hdr->frame_control);
1734 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1735 /* Send management frames and broadcast/multicast data using
1737 /* TODO: this could probably be improved.. */
1738 return rs_get_lowest_rate(local);
1741 sta = sta_info_get(local, hdr->addr1);
1743 if (!sta || !sta->rate_ctrl_priv) {
1746 return rs_get_lowest_rate(local);
1749 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1750 i = sta->last_txrate;
1752 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) {
1753 u8 sta_id = iwl_hw_find_station(priv, hdr->addr1);
1754 DECLARE_MAC_BUF(mac);
1756 if (sta_id == IWL_INVALID_STATION) {
1757 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1758 print_mac(mac, hdr->addr1));
1759 sta_id = iwl_add_station(priv,
1760 hdr->addr1, 0, CMD_ASYNC);
1762 if ((sta_id != IWL_INVALID_STATION)) {
1763 lq->lq.sta_id = sta_id;
1764 lq->lq.rs_table[0].rate_n_flags = 0;
1765 lq->ibss_sta_added = 1;
1766 rs_initialize_lq(priv, sta);
1768 if (!lq->ibss_sta_added)
1774 if ((i < 0) || (i > IWL_RATE_COUNT))
1775 return rs_get_lowest_rate(local);
1777 return &priv->ieee_rates[i];
1780 static void *rs_alloc_sta(void *priv, gfp_t gfp)
1782 struct iwl_rate_scale_priv *crl;
1785 IWL_DEBUG_RATE("create station rate scale window\n");
1787 crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp);
1791 crl->lq.sta_id = 0xff;
1794 for (j = 0; j < LQ_SIZE; j++)
1795 for (i = 0; i < IWL_RATE_COUNT; i++)
1796 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1801 static void rs_rate_init(void *priv_rate, void *priv_sta,
1802 struct ieee80211_local *local,
1803 struct sta_info *sta)
1806 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
1807 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1808 struct iwl_rate_scale_priv *crl = priv_sta;
1810 crl->flush_timer = 0;
1811 crl->supp_rates = sta->supp_rates;
1813 for (j = 0; j < LQ_SIZE; j++)
1814 for (i = 0; i < IWL_RATE_COUNT; i++)
1815 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1817 IWL_DEBUG_RATE("rate scale global init\n");
1818 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1819 * the lowest or the highest rate.. Could consider using RSSI from
1820 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1823 crl->ibss_sta_added = 0;
1824 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1825 u8 sta_id = iwl_hw_find_station(priv, sta->addr);
1826 DECLARE_MAC_BUF(mac);
1828 /* for IBSS the call are from tasklet */
1829 IWL_DEBUG_HT("LQ: ADD station %s\n",
1830 print_mac(mac, sta->addr));
1832 if (sta_id == IWL_INVALID_STATION) {
1833 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1834 print_mac(mac, sta->addr));
1835 sta_id = iwl_add_station(priv,
1836 sta->addr, 0, CMD_ASYNC);
1838 if ((sta_id != IWL_INVALID_STATION)) {
1839 crl->lq.sta_id = sta_id;
1840 crl->lq.rs_table[0].rate_n_flags = 0;
1842 /* FIXME: this is w/a remove it later */
1843 priv->assoc_station_added = 1;
1846 for (i = 0; i < mode->num_rates; i++) {
1847 if ((sta->supp_rates & BIT(i)) &&
1848 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))
1851 sta->last_txrate = sta->txrate;
1852 /* For MODE_IEEE80211A mode cck rate are at end
1855 if (local->hw.conf.phymode == MODE_IEEE80211A)
1856 sta->last_txrate += IWL_FIRST_OFDM_RATE;
1858 crl->is_dup = priv->is_dup;
1859 crl->valid_antenna = priv->valid_antenna;
1860 crl->antenna = priv->antenna;
1861 crl->is_green = rs_use_green(priv);
1862 crl->active_rate = priv->active_rate;
1863 crl->active_rate &= ~(0x1000);
1864 crl->active_rate_basic = priv->active_rate_basic;
1865 crl->phymode = priv->phymode;
1866 #ifdef CONFIG_IWLWIFI_HT
1867 crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1);
1868 crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1);
1869 crl->active_siso_rate &= ~((u16)0x2);
1870 crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE;
1872 crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1);
1873 crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1);
1874 crl->active_mimo_rate &= ~((u16)0x2);
1875 crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE;
1876 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate,
1877 crl->active_mimo_rate);
1878 #endif /*CONFIG_IWLWIFI_HT*/
1879 #ifdef CONFIG_MAC80211_DEBUGFS
1883 if (priv->assoc_station_added)
1884 priv->lq_mngr.lq_ready = 1;
1886 rs_initialize_lq(priv, sta);
1889 static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
1890 struct iwl_rate *tx_mcs,
1891 struct iwl_link_quality_cmd *lq_cmd)
1895 int repeat_rate = 0;
1896 u8 ant_toggle_count = 0;
1897 u8 use_ht_possible = 1;
1898 struct iwl_rate new_rate;
1899 struct iwl_scale_tbl_info tbl_type = { 0 };
1901 rs_dbgfs_set_mcs(lq_data, tx_mcs, index);
1903 rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode,
1904 &tbl_type, &rate_idx);
1906 if (is_legacy(tbl_type.lq_type)) {
1907 ant_toggle_count = 1;
1908 repeat_rate = IWL_NUMBER_TRY;
1910 repeat_rate = IWL_HT_NUMBER_TRY;
1912 lq_cmd->general_params.mimo_delimiter =
1913 is_mimo(tbl_type.lq_type) ? 1 : 0;
1914 lq_cmd->rs_table[index].rate_n_flags =
1915 cpu_to_le32(tx_mcs->rate_n_flags);
1916 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
1918 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))
1919 lq_cmd->general_params.single_stream_ant_msk = 1;
1921 lq_cmd->general_params.single_stream_ant_msk = 2;
1926 while (index < LINK_QUAL_MAX_RETRY_NUM) {
1927 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
1928 if (is_legacy(tbl_type.lq_type)) {
1929 if (ant_toggle_count <
1930 NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1933 rs_toggle_antenna(&new_rate, &tbl_type);
1934 ant_toggle_count = 1;
1938 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1939 lq_cmd->rs_table[index].rate_n_flags =
1940 cpu_to_le32(new_rate.rate_n_flags);
1945 rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type,
1948 if (is_mimo(tbl_type.lq_type))
1949 lq_cmd->general_params.mimo_delimiter = index;
1951 rs_get_lower_rate(lq_data, &tbl_type, rate_idx,
1952 use_ht_possible, &new_rate);
1954 if (is_legacy(tbl_type.lq_type)) {
1955 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1958 rs_toggle_antenna(&new_rate, &tbl_type);
1959 ant_toggle_count = 1;
1961 repeat_rate = IWL_NUMBER_TRY;
1963 repeat_rate = IWL_HT_NUMBER_TRY;
1965 use_ht_possible = 0;
1967 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1968 lq_cmd->rs_table[index].rate_n_flags =
1969 cpu_to_le32(new_rate.rate_n_flags);
1975 lq_cmd->general_params.dual_stream_ant_msk = 3;
1976 lq_cmd->agg_params.agg_dis_start_th = 3;
1977 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
1980 static void *rs_alloc(struct ieee80211_local *local)
1982 return local->hw.priv;
1984 /* rate scale requires free function to be implemented */
1985 static void rs_free(void *priv_rate)
1990 static void rs_clear(void *priv_rate)
1992 struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
1994 IWL_DEBUG_RATE("enter\n");
1996 priv->lq_mngr.lq_ready = 0;
1997 #ifdef CONFIG_IWLWIFI_HT
1998 #ifdef CONFIG_IWLWIFI_HT_AGG
1999 if (priv->lq_mngr.agg_ctrl.granted_ba)
2000 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);
2001 #endif /*CONFIG_IWLWIFI_HT_AGG */
2002 #endif /* CONFIG_IWLWIFI_HT */
2004 IWL_DEBUG_RATE("leave\n");
2007 static void rs_free_sta(void *priv, void *priv_sta)
2009 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2011 IWL_DEBUG_RATE("enter\n");
2013 IWL_DEBUG_RATE("leave\n");
2017 #ifdef CONFIG_MAC80211_DEBUGFS
2018 static int open_file_generic(struct inode *inode, struct file *file)
2020 file->private_data = inode->i_private;
2023 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
2024 struct iwl_rate *mcs, int index)
2026 const u32 cck_rate = 0x820A;
2027 if (rs_priv->dbg_fixed.rate_n_flags) {
2029 mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags;
2031 mcs->rate_n_flags = cck_rate;
2032 IWL_DEBUG_RATE("Fixed rate ON\n");
2036 IWL_DEBUG_RATE("Fixed rate OFF\n");
2039 static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2040 const char __user *user_buf, size_t count, loff_t *ppos)
2042 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2047 memset(buf, 0, sizeof(buf));
2048 buf_size = min(count, sizeof(buf) - 1);
2049 if (copy_from_user(buf, user_buf, buf_size))
2052 if (sscanf(buf, "%x", &parsed_rate) == 1)
2053 rs_priv->dbg_fixed.rate_n_flags = parsed_rate;
2055 rs_priv->dbg_fixed.rate_n_flags = 0;
2057 rs_priv->active_rate = 0x0FFF;
2058 rs_priv->active_siso_rate = 0x1FD0;
2059 rs_priv->active_mimo_rate = 0x1FD0;
2061 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2062 rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags);
2064 if (rs_priv->dbg_fixed.rate_n_flags) {
2065 rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq);
2066 rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC);
2071 static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2072 char __user *user_buf, size_t count, loff_t *ppos)
2078 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2080 desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id);
2081 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2082 rs_priv->total_failed, rs_priv->total_success,
2083 rs_priv->active_rate);
2084 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2085 rs_priv->dbg_fixed.rate_n_flags);
2086 desc += sprintf(buff+desc, "general:"
2087 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2088 rs_priv->lq.general_params.flags,
2089 rs_priv->lq.general_params.mimo_delimiter,
2090 rs_priv->lq.general_params.single_stream_ant_msk,
2091 rs_priv->lq.general_params.dual_stream_ant_msk);
2093 desc += sprintf(buff+desc, "agg:"
2094 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2095 le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit),
2096 rs_priv->lq.agg_params.agg_dis_start_th,
2097 rs_priv->lq.agg_params.agg_frame_cnt_limit);
2099 desc += sprintf(buff+desc,
2100 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2101 rs_priv->lq.general_params.start_rate_index[0],
2102 rs_priv->lq.general_params.start_rate_index[1],
2103 rs_priv->lq.general_params.start_rate_index[2],
2104 rs_priv->lq.general_params.start_rate_index[3]);
2107 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
2108 desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
2109 i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags));
2111 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2114 static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2115 .write = rs_sta_dbgfs_scale_table_write,
2116 .read = rs_sta_dbgfs_scale_table_read,
2117 .open = open_file_generic,
2120 static void rs_add_debugfs(void *priv, void *priv_sta,
2123 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2124 rs_priv->rs_sta_dbgfs_scale_table_file =
2125 debugfs_create_file("rate_scale_table", 0444, dir,
2126 rs_priv, &rs_sta_dbgfs_scale_table_ops);
2129 static void rs_remove_debugfs(void *priv, void *priv_sta)
2131 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2132 debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file);
2136 static struct rate_control_ops rs_ops = {
2139 .tx_status = rs_tx_status,
2140 .get_rate = rs_get_rate,
2141 .rate_init = rs_rate_init,
2145 .alloc_sta = rs_alloc_sta,
2146 .free_sta = rs_free_sta,
2147 #ifdef CONFIG_MAC80211_DEBUGFS
2148 .add_sta_debugfs = rs_add_debugfs,
2149 .remove_sta_debugfs = rs_remove_debugfs,
2153 int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2155 struct ieee80211_local *local = hw_to_local(hw);
2156 struct iwl_priv *priv = hw->priv;
2157 struct iwl_rate_scale_priv *rs_priv;
2158 struct sta_info *sta;
2160 u32 samples = 0, success = 0, good = 0;
2161 unsigned long now = jiffies;
2163 u8 lq_type, antenna;
2165 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2166 if (!sta || !sta->rate_ctrl_priv) {
2169 IWL_DEBUG_RATE("leave - no private rate data!\n");
2171 IWL_DEBUG_RATE("leave - no station!\n");
2172 return sprintf(buf, "station %d not found\n", sta_id);
2175 rs_priv = (void *)sta->rate_ctrl_priv;
2177 lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type;
2178 antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type;
2180 if (is_legacy(lq_type))
2181 i = IWL_RATE_54M_INDEX;
2183 i = IWL_RATE_60M_INDEX;
2187 int active = rs_priv->active_tbl;
2190 sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2);
2192 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2193 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
2195 (rs_priv->lq_info[active].win[i].data & mask)
2198 samples += rs_priv->lq_info[active].win[i].counter;
2199 good += rs_priv->lq_info[active].win[i].success_counter;
2200 success += rs_priv->lq_info[active].win[i].success_counter *
2203 if (rs_priv->lq_info[active].win[i].stamp) {
2205 jiffies_to_msecs(now -
2206 rs_priv->lq_info[active].win[i].stamp);
2208 if (delta > max_time)
2211 count += sprintf(&buf[count], "%5dms\n", delta);
2213 buf[count++] = '\n';
2215 j = iwl_get_prev_ieee_rate(i);
2221 /* Display the average rate of all samples taken.
2223 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2224 * added from iwl_rates is actually 2X the rate */
2226 count += sprintf(&buf[count],
2227 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2228 "%3d%% success (%d good packets over %d tries)\n",
2229 success / (2 * samples), (success * 5 / samples) % 10,
2230 max_time, good * 100 / samples, good, samples);
2232 count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
2233 count += sprintf(&buf[count], "\nrate scale type %d anntena %d "
2234 "active_search %d rate index %d\n", lq_type, antenna,
2235 rs_priv->search_better_tbl, sta->last_txrate);
2241 void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
2243 struct iwl_priv *priv = hw->priv;
2245 priv->lq_mngr.lq_ready = 1;
2248 void iwl_rate_control_register(struct ieee80211_hw *hw)
2250 ieee80211_rate_control_register(&rs_ops);
2253 void iwl_rate_control_unregister(struct ieee80211_hw *hw)
2255 ieee80211_rate_control_unregister(&rs_ops);