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>
41 #include "../net/mac80211/ieee80211_rate.h"
44 #include "iwl-helpers.h"
46 #define RS_NAME "iwl-4965-rs"
48 #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
49 #define IWL_NUMBER_TRY 1
50 #define IWL_HT_NUMBER_TRY 3
52 #define IWL_RATE_MAX_WINDOW 62
53 #define IWL_RATE_HIGH_TH 10880
54 #define IWL_RATE_MIN_FAILURE_TH 6
55 #define IWL_RATE_MIN_SUCCESS_TH 8
56 #define IWL_RATE_DECREASE_TH 1920
57 #define IWL_RATE_INCREASE_TH 8960
58 #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */
60 static u8 rs_ht_to_legacy[] = {
61 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
62 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
64 IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
65 IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
66 IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
67 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
72 } __attribute__ ((packed));
74 struct iwl_rate_scale_data {
83 struct iwl_scale_tbl_info {
84 enum iwl_table_type lq_type;
85 enum iwl_antenna_type antenna_type;
91 struct iwl_rate current_rate;
92 struct iwl_rate_scale_data win[IWL_RATE_COUNT];
95 struct iwl_rate_scale_priv {
101 u32 table_count_limit;
102 u32 max_failure_limit;
103 u32 max_success_limit;
117 u16 active_siso_rate;
118 u16 active_mimo_rate;
119 u16 active_rate_basic;
120 struct iwl_link_quality_cmd lq;
121 struct iwl_scale_tbl_info lq_info[LQ_SIZE];
122 #ifdef CONFIG_MAC80211_DEBUGFS
123 struct dentry *rs_sta_dbgfs_scale_table_file;
124 struct dentry *rs_sta_dbgfs_stats_table_file;
125 struct iwl_rate dbg_fixed;
126 struct iwl_priv *drv;
130 static void rs_rate_scale_perform(struct iwl_priv *priv,
131 struct net_device *dev,
132 struct ieee80211_hdr *hdr,
133 struct sta_info *sta);
134 static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
135 struct iwl_rate *tx_mcs,
136 struct iwl_link_quality_cmd *tbl);
139 #ifdef CONFIG_MAC80211_DEBUGFS
140 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
141 struct iwl_rate *mcs, int index);
143 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
144 struct iwl_rate *mcs, int index)
147 static s32 expected_tpt_A[IWL_RATE_COUNT] = {
148 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
151 static s32 expected_tpt_G[IWL_RATE_COUNT] = {
152 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
155 static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = {
156 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
159 static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
160 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
163 static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = {
164 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
167 static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = {
168 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
171 static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = {
172 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
175 static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
176 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
179 static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = {
180 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
183 static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
184 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
187 static int iwl_lq_sync_callback(struct iwl_priv *priv,
188 struct iwl_cmd *cmd, struct sk_buff *skb)
190 /*We didn't cache the SKB; let the caller free it */
194 static inline u8 iwl_rate_get_rate(u32 rate_n_flags)
196 return (u8)(rate_n_flags & 0xFF);
199 static int rs_send_lq_cmd(struct iwl_priv *priv,
200 struct iwl_link_quality_cmd *lq, u8 flags)
202 #ifdef CONFIG_IWLWIFI_DEBUG
207 struct iwl_host_cmd cmd = {
208 .id = REPLY_TX_LINK_QUALITY_CMD,
209 .len = sizeof(struct iwl_link_quality_cmd),
214 if ((lq->sta_id == 0xFF) &&
215 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
218 if (lq->sta_id == 0xFF)
219 lq->sta_id = IWL_AP_ID;
221 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
222 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
223 lq->general_params.single_stream_ant_msk,
224 lq->general_params.dual_stream_ant_msk);
225 #ifdef CONFIG_IWLWIFI_DEBUG
226 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
227 IWL_DEBUG_RATE("lq index %d 0x%X\n",
228 i, lq->rs_table[i].rate_n_flags);
231 if (flags & CMD_ASYNC)
232 cmd.meta.u.callback = iwl_lq_sync_callback;
234 if (iwl_is_associated(priv) && priv->assoc_station_added &&
235 priv->lq_mngr.lq_ready)
236 rc = iwl_send_cmd(priv, &cmd);
241 static int rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
244 window->success_counter = 0;
245 window->success_ratio = IWL_INVALID_VALUE;
247 window->average_tpt = IWL_INVALID_VALUE;
253 static int rs_collect_tx_data(struct iwl_rate_scale_data *windows,
254 int scale_index, s32 tpt, u32 status)
257 struct iwl_rate_scale_data *window = NULL;
259 u8 win_size = IWL_RATE_MAX_WINDOW;
265 if (scale_index >= IWL_RATE_COUNT)
268 window = &(windows[scale_index]);
270 if (window->counter >= win_size) {
272 window->counter = win_size - 1;
274 mask = (mask << (win_size - 1));
275 if ((window->data & mask)) {
276 window->data &= ~mask;
277 window->success_counter = window->success_counter - 1;
281 window->counter = window->counter + 1;
283 window->data = (mask << 1);
285 window->success_counter = window->success_counter + 1;
289 if (window->counter > 0)
290 window->success_ratio = 128 * (100 * window->success_counter)
293 window->success_ratio = IWL_INVALID_VALUE;
295 fail_count = window->counter - window->success_counter;
297 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
298 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
299 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
301 window->average_tpt = IWL_INVALID_VALUE;
303 window->stamp = jiffies;
308 int static rs_mcs_from_tbl(struct iwl_rate *mcs_rate,
309 struct iwl_scale_tbl_info *tbl,
310 int index, u8 use_green)
314 if (is_legacy(tbl->lq_type)) {
315 mcs_rate->rate_n_flags = iwl_rates[index].plcp;
316 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
317 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
319 } else if (is_siso(tbl->lq_type)) {
320 if (index > IWL_LAST_OFDM_RATE)
321 index = IWL_LAST_OFDM_RATE;
322 mcs_rate->rate_n_flags = iwl_rates[index].plcp_siso |
325 if (index > IWL_LAST_OFDM_RATE)
326 index = IWL_LAST_OFDM_RATE;
327 mcs_rate->rate_n_flags = iwl_rates[index].plcp_mimo |
331 switch (tbl->antenna_type) {
333 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
336 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
339 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
345 if (is_legacy(tbl->lq_type))
350 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
352 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
355 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
358 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
359 if (is_siso(tbl->lq_type))
360 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
365 static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate,
366 int phymode, struct iwl_scale_tbl_info *tbl,
372 index = iwl_rate_index_from_plcp(mcs_rate->rate_n_flags);
374 if (index == IWL_RATE_INVALID) {
381 tbl->antenna_type = ANT_BOTH;
383 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
384 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
386 if (ant_msk == RATE_MCS_ANT_AB_MSK)
387 tbl->lq_type = LQ_NONE;
390 if (phymode == MODE_IEEE80211A)
395 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
396 tbl->antenna_type = ANT_MAIN;
398 tbl->antenna_type = ANT_AUX;
402 } else if (iwl_rate_get_rate(mcs_rate->rate_n_flags)
403 <= IWL_RATE_SISO_60M_PLCP) {
404 tbl->lq_type = LQ_SISO;
406 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
407 if (ant_msk == RATE_MCS_ANT_AB_MSK)
408 tbl->lq_type = LQ_NONE;
410 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
411 tbl->antenna_type = ANT_MAIN;
413 tbl->antenna_type = ANT_AUX;
415 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
418 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
419 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
422 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
427 tbl->lq_type = LQ_MIMO;
428 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
431 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
432 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
435 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
442 static inline void rs_toggle_antenna(struct iwl_rate *new_rate,
443 struct iwl_scale_tbl_info *tbl)
445 if (tbl->antenna_type == ANT_AUX) {
446 tbl->antenna_type = ANT_MAIN;
447 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK;
448 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
450 tbl->antenna_type = ANT_AUX;
451 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
452 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
456 static inline s8 rs_use_green(struct iwl_priv *priv)
459 #ifdef CONFIG_IWLWIFI_HT
460 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
463 if ((priv->current_assoc_ht.is_green_field) &&
464 !(priv->current_assoc_ht.operating_mode & 0x4))
466 #endif /*CONFIG_IWLWIFI_HT */
471 * rs_get_supported_rates - get the available rates
473 * if management frame or broadcast frame only return
474 * basic available rates.
477 static void rs_get_supported_rates(struct iwl_rate_scale_priv *lq_data,
478 struct ieee80211_hdr *hdr,
479 enum iwl_table_type rate_type,
482 if (is_legacy(rate_type))
483 *data_rate = lq_data->active_rate;
485 if (is_siso(rate_type))
486 *data_rate = lq_data->active_siso_rate;
488 *data_rate = lq_data->active_mimo_rate;
491 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
492 lq_data->active_rate_basic)
493 *data_rate = lq_data->active_rate_basic;
496 static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
498 u8 high = IWL_RATE_INVALID;
499 u8 low = IWL_RATE_INVALID;
501 /* 802.11A or ht walks to the next literal adjascent rate in
503 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
507 /* Find the previous rate that is in the rate mask */
509 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
510 if (rate_mask & mask) {
516 /* Find the next rate that is in the rate mask */
518 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
519 if (rate_mask & mask) {
525 return (high << 8) | low;
529 while (low != IWL_RATE_INVALID) {
530 low = iwl_rates[low].prev_rs;
531 if (low == IWL_RATE_INVALID)
533 if (rate_mask & (1 << low))
535 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
539 while (high != IWL_RATE_INVALID) {
540 high = iwl_rates[high].next_rs;
541 if (high == IWL_RATE_INVALID)
543 if (rate_mask & (1 << high))
545 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
548 return (high << 8) | low;
551 static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data,
552 struct iwl_scale_tbl_info *tbl, u8 scale_index,
553 u8 ht_possible, struct iwl_rate *mcs_rate)
558 u8 switch_to_legacy = 0;
559 u8 is_green = lq_data->is_green;
561 /* check if we need to switch from HT to legacy rates.
562 * assumption is that mandatory rates (1Mbps or 6Mbps)
563 * are always supported (spec demand) */
564 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
565 switch_to_legacy = 1;
566 scale_index = rs_ht_to_legacy[scale_index];
567 if (lq_data->phymode == MODE_IEEE80211A)
572 if ((tbl->antenna_type == ANT_BOTH) ||
573 (tbl->antenna_type == ANT_NONE))
574 tbl->antenna_type = ANT_MAIN;
580 rs_get_supported_rates(lq_data, NULL, tbl->lq_type, &rate_mask);
582 /* mask with station rate restriction */
583 if (is_legacy(tbl->lq_type)) {
584 if (lq_data->phymode == (u8) MODE_IEEE80211A)
585 rate_mask = (u16)(rate_mask &
586 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
588 rate_mask = (u16)(rate_mask & lq_data->supp_rates);
591 /* if we did switched from HT to legacy check current rate */
592 if ((switch_to_legacy) &&
593 (rate_mask & (1 << scale_index))) {
594 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
598 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
599 low = high_low & 0xff;
601 if (low != IWL_RATE_INVALID)
602 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
604 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
609 static void rs_tx_status(void *priv_rate,
610 struct net_device *dev,
612 struct ieee80211_tx_status *tx_resp)
616 int rs_index, index = 0;
617 struct iwl_rate_scale_priv *lq;
618 struct iwl_link_quality_cmd *table;
619 struct sta_info *sta;
620 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
621 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
623 struct iwl_rate_scale_data *window = NULL;
624 struct iwl_rate_scale_data *search_win = NULL;
625 struct iwl_rate tx_mcs;
626 struct iwl_scale_tbl_info tbl_type;
627 struct iwl_scale_tbl_info *curr_tbl, *search_tbl;
629 u16 fc = le16_to_cpu(hdr->frame_control);
632 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
634 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
637 retries = tx_resp->retry_count;
643 sta = sta_info_get(local, hdr->addr1);
645 if (!sta || !sta->rate_ctrl_priv) {
651 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
653 if (!priv->lq_mngr.lq_ready)
656 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added)
660 active_index = lq->active_tbl;
662 lq->antenna = (lq->valid_antenna & local->hw.conf.antenna_sel_tx);
664 lq->antenna = lq->valid_antenna;
666 lq->antenna = lq->valid_antenna;
667 curr_tbl = &(lq->lq_info[active_index]);
668 search_tbl = &(lq->lq_info[(1 - active_index)]);
669 window = (struct iwl_rate_scale_data *)
671 search_win = (struct iwl_rate_scale_data *)
672 &(search_tbl->win[0]);
674 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
676 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
677 &tbl_type, &rs_index);
678 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
679 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
680 rs_index, tx_mcs.rate_n_flags);
686 (tx_mcs.rate_n_flags !=
687 le32_to_cpu(table->rs_table[0].rate_n_flags))) {
688 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
690 le32_to_cpu(table->rs_table[0].rate_n_flags));
696 tx_mcs.rate_n_flags =
697 le32_to_cpu(table->rs_table[index].rate_n_flags);
698 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
699 &tbl_type, &rs_index);
701 if ((tbl_type.lq_type == search_tbl->lq_type) &&
702 (tbl_type.antenna_type == search_tbl->antenna_type) &&
703 (tbl_type.is_SGI == search_tbl->is_SGI)) {
704 if (search_tbl->expected_tpt)
705 tpt = search_tbl->expected_tpt[rs_index];
708 rs_collect_tx_data(search_win,
710 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
711 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
712 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
713 if (curr_tbl->expected_tpt)
714 tpt = curr_tbl->expected_tpt[rs_index];
717 rs_collect_tx_data(window, rs_index, tpt, 0);
726 if (!tx_resp->retry_count)
727 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
729 tx_mcs.rate_n_flags =
730 le32_to_cpu(table->rs_table[index].rate_n_flags);
732 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
733 &tbl_type, &rs_index);
735 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
740 if ((tbl_type.lq_type == search_tbl->lq_type) &&
741 (tbl_type.antenna_type == search_tbl->antenna_type) &&
742 (tbl_type.is_SGI == search_tbl->is_SGI)) {
743 if (search_tbl->expected_tpt)
744 tpt = search_tbl->expected_tpt[rs_index];
747 rs_collect_tx_data(search_win,
748 rs_index, tpt, status);
749 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
750 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
751 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
752 if (curr_tbl->expected_tpt)
753 tpt = curr_tbl->expected_tpt[rs_index];
756 rs_collect_tx_data(window, rs_index, tpt, status);
759 if (lq->stay_in_tbl) {
766 rs_rate_scale_perform(priv, dev, hdr, sta);
771 static u8 rs_is_ant_connected(u8 valid_antenna,
772 enum iwl_antenna_type antenna_type)
774 if (antenna_type == ANT_AUX)
775 return ((valid_antenna & 0x2) ? 1:0);
776 else if (antenna_type == ANT_MAIN)
777 return ((valid_antenna & 0x1) ? 1:0);
778 else if (antenna_type == ANT_BOTH) {
779 if ((valid_antenna & 0x3) == 0x3)
788 static u8 rs_is_other_ant_connected(u8 valid_antenna,
789 enum iwl_antenna_type antenna_type)
791 if (antenna_type == ANT_AUX)
792 return (rs_is_ant_connected(valid_antenna, ANT_MAIN));
794 return (rs_is_ant_connected(valid_antenna, ANT_AUX));
799 static void rs_set_stay_in_table(u8 is_legacy,
800 struct iwl_rate_scale_priv *lq_data)
802 IWL_DEBUG_HT("we are staying in the same table\n");
803 lq_data->stay_in_tbl = 1;
805 lq_data->table_count_limit = IWL_LEGACY_TABLE_COUNT;
806 lq_data->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
807 lq_data->max_success_limit = IWL_LEGACY_TABLE_COUNT;
809 lq_data->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
810 lq_data->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
811 lq_data->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
813 lq_data->table_count = 0;
814 lq_data->total_failed = 0;
815 lq_data->total_success = 0;
818 static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data,
819 struct iwl_scale_tbl_info *tbl)
821 if (is_legacy(tbl->lq_type)) {
822 if (!is_a_band(tbl->lq_type))
823 tbl->expected_tpt = expected_tpt_G;
825 tbl->expected_tpt = expected_tpt_A;
826 } else if (is_siso(tbl->lq_type)) {
827 if (tbl->is_fat && !lq_data->is_dup)
829 tbl->expected_tpt = expected_tpt_siso40MHzSGI;
831 tbl->expected_tpt = expected_tpt_siso40MHz;
832 else if (tbl->is_SGI)
833 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
835 tbl->expected_tpt = expected_tpt_siso20MHz;
837 } else if (is_mimo(tbl->lq_type)) {
838 if (tbl->is_fat && !lq_data->is_dup)
840 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
842 tbl->expected_tpt = expected_tpt_mimo40MHz;
843 else if (tbl->is_SGI)
844 tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
846 tbl->expected_tpt = expected_tpt_mimo20MHz;
848 tbl->expected_tpt = expected_tpt_G;
851 #ifdef CONFIG_IWLWIFI_HT
852 static s32 rs_get_best_rate(struct iwl_priv *priv,
853 struct iwl_rate_scale_priv *lq_data,
854 struct iwl_scale_tbl_info *tbl,
855 u16 rate_mask, s8 index, s8 rate)
857 struct iwl_scale_tbl_info *active_tbl =
858 &(lq_data->lq_info[lq_data->active_tbl]);
859 s32 new_rate, high, low, start_hi;
860 s32 active_sr = active_tbl->win[index].success_ratio;
861 s32 *tpt_tbl = tbl->expected_tpt;
862 s32 active_tpt = active_tbl->expected_tpt[index];
865 new_rate = high = low = start_hi = IWL_RATE_INVALID;
868 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
870 low = high_low & 0xff;
871 high = (high_low >> 8) & 0xff;
873 if ((((100 * tpt_tbl[rate]) > lq_data->last_tpt) &&
874 ((active_sr > IWL_RATE_DECREASE_TH) &&
875 (active_sr <= IWL_RATE_HIGH_TH) &&
876 (tpt_tbl[rate] <= active_tpt))) ||
877 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
878 (tpt_tbl[rate] > active_tpt))) {
880 if (start_hi != IWL_RATE_INVALID) {
885 if (low != IWL_RATE_INVALID)
890 if (new_rate != IWL_RATE_INVALID)
892 else if (high != IWL_RATE_INVALID) {
904 #endif /* CONFIG_IWLWIFI_HT */
906 static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
908 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
911 static int rs_switch_to_mimo(struct iwl_priv *priv,
912 struct iwl_rate_scale_priv *lq_data,
913 struct iwl_scale_tbl_info *tbl, int index)
916 #ifdef CONFIG_IWLWIFI_HT
919 s8 is_green = lq_data->is_green;
921 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
924 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
925 tbl->lq_type = LQ_MIMO;
926 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
929 if (priv->current_assoc_ht.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
932 if (!rs_is_both_ant_supp(lq_data->antenna))
936 tbl->is_dup = lq_data->is_dup;
938 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
944 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
948 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
953 rs_get_expected_tpt_table(lq_data, tbl);
955 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
957 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
958 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
960 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
962 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
963 tbl->current_rate.rate_n_flags, is_green);
965 #endif /*CONFIG_IWLWIFI_HT */
969 static int rs_switch_to_siso(struct iwl_priv *priv,
970 struct iwl_rate_scale_priv *lq_data,
971 struct iwl_scale_tbl_info *tbl, int index)
974 #ifdef CONFIG_IWLWIFI_HT
976 u8 is_green = lq_data->is_green;
979 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
980 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
984 tbl->is_dup = lq_data->is_dup;
985 tbl->lq_type = LQ_SISO;
987 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
990 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
996 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
1000 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
1008 rs_get_expected_tpt_table(lq_data, tbl);
1009 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
1011 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
1012 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1013 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
1017 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
1018 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1019 tbl->current_rate.rate_n_flags, is_green);
1021 #endif /*CONFIG_IWLWIFI_HT */
1025 static int rs_move_legacy_other(struct iwl_priv *priv,
1026 struct iwl_rate_scale_priv *lq_data,
1030 struct iwl_scale_tbl_info *tbl =
1031 &(lq_data->lq_info[lq_data->active_tbl]);
1032 struct iwl_scale_tbl_info *search_tbl =
1033 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1034 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1035 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1036 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1037 u8 start_action = tbl->action;
1040 switch (tbl->action) {
1041 case IWL_LEGACY_SWITCH_ANTENNA:
1042 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1044 search_tbl->lq_type = LQ_NONE;
1045 lq_data->action_counter++;
1046 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1048 if (!rs_is_other_ant_connected(lq_data->antenna,
1052 memcpy(search_tbl, tbl, sz);
1054 rs_toggle_antenna(&(search_tbl->current_rate),
1056 rs_get_expected_tpt_table(lq_data, search_tbl);
1057 lq_data->search_better_tbl = 1;
1060 case IWL_LEGACY_SWITCH_SISO:
1061 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1062 memcpy(search_tbl, tbl, sz);
1063 search_tbl->lq_type = LQ_SISO;
1064 search_tbl->is_SGI = 0;
1065 search_tbl->is_fat = 0;
1066 rc = rs_switch_to_siso(priv, lq_data, search_tbl,
1069 lq_data->search_better_tbl = 1;
1070 lq_data->action_counter = 0;
1076 case IWL_LEGACY_SWITCH_MIMO:
1077 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1078 memcpy(search_tbl, tbl, sz);
1079 search_tbl->lq_type = LQ_MIMO;
1080 search_tbl->is_SGI = 0;
1081 search_tbl->is_fat = 0;
1082 search_tbl->antenna_type = ANT_BOTH;
1083 rc = rs_switch_to_mimo(priv, lq_data, search_tbl,
1086 lq_data->search_better_tbl = 1;
1087 lq_data->action_counter = 0;
1094 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1095 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1097 if (tbl->action == start_action)
1105 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1106 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1111 static int rs_move_siso_to_other(struct iwl_priv *priv,
1112 struct iwl_rate_scale_priv *lq_data,
1116 u8 is_green = lq_data->is_green;
1117 struct iwl_scale_tbl_info *tbl =
1118 &(lq_data->lq_info[lq_data->active_tbl]);
1119 struct iwl_scale_tbl_info *search_tbl =
1120 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1121 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1122 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1123 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1124 u8 start_action = tbl->action;
1127 lq_data->action_counter++;
1128 switch (tbl->action) {
1129 case IWL_SISO_SWITCH_ANTENNA:
1130 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1131 search_tbl->lq_type = LQ_NONE;
1132 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1134 if (!rs_is_other_ant_connected(lq_data->antenna,
1138 memcpy(search_tbl, tbl, sz);
1139 search_tbl->action = IWL_SISO_SWITCH_MIMO;
1140 rs_toggle_antenna(&(search_tbl->current_rate),
1142 lq_data->search_better_tbl = 1;
1146 case IWL_SISO_SWITCH_MIMO:
1147 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1148 memcpy(search_tbl, tbl, sz);
1149 search_tbl->lq_type = LQ_MIMO;
1150 search_tbl->is_SGI = 0;
1151 search_tbl->is_fat = 0;
1152 search_tbl->antenna_type = ANT_BOTH;
1153 rc = rs_switch_to_mimo(priv, lq_data, search_tbl,
1156 lq_data->search_better_tbl = 1;
1161 case IWL_SISO_SWITCH_GI:
1162 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1163 memcpy(search_tbl, tbl, sz);
1164 search_tbl->action = 0;
1165 if (search_tbl->is_SGI)
1166 search_tbl->is_SGI = 0;
1168 search_tbl->is_SGI = 1;
1171 lq_data->search_better_tbl = 1;
1172 if ((tbl->lq_type == LQ_SISO) &&
1174 s32 tpt = lq_data->last_tpt / 100;
1175 if (((!tbl->is_fat) &&
1176 (tpt >= expected_tpt_siso20MHz[index])) ||
1178 (tpt >= expected_tpt_siso40MHz[index])))
1179 lq_data->search_better_tbl = 0;
1181 rs_get_expected_tpt_table(lq_data, search_tbl);
1182 rs_mcs_from_tbl(&search_tbl->current_rate,
1183 search_tbl, index, is_green);
1187 if (tbl->action > IWL_SISO_SWITCH_GI)
1188 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1190 if (tbl->action == start_action)
1197 if (tbl->action > IWL_SISO_SWITCH_GI)
1198 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1202 static int rs_move_mimo_to_other(struct iwl_priv *priv,
1203 struct iwl_rate_scale_priv *lq_data,
1207 s8 is_green = lq_data->is_green;
1208 struct iwl_scale_tbl_info *tbl =
1209 &(lq_data->lq_info[lq_data->active_tbl]);
1210 struct iwl_scale_tbl_info *search_tbl =
1211 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1212 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1213 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1214 u8 start_action = tbl->action;
1217 lq_data->action_counter++;
1218 switch (tbl->action) {
1219 case IWL_MIMO_SWITCH_ANTENNA_A:
1220 case IWL_MIMO_SWITCH_ANTENNA_B:
1221 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1222 memcpy(search_tbl, tbl, sz);
1223 search_tbl->lq_type = LQ_SISO;
1224 search_tbl->is_SGI = 0;
1225 search_tbl->is_fat = 0;
1226 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1227 search_tbl->antenna_type = ANT_MAIN;
1229 search_tbl->antenna_type = ANT_AUX;
1231 rc = rs_switch_to_siso(priv, lq_data, search_tbl,
1234 lq_data->search_better_tbl = 1;
1239 case IWL_MIMO_SWITCH_GI:
1240 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1241 memcpy(search_tbl, tbl, sz);
1242 search_tbl->lq_type = LQ_MIMO;
1243 search_tbl->antenna_type = ANT_BOTH;
1244 search_tbl->action = 0;
1245 if (search_tbl->is_SGI)
1246 search_tbl->is_SGI = 0;
1248 search_tbl->is_SGI = 1;
1249 lq_data->search_better_tbl = 1;
1250 if ((tbl->lq_type == LQ_MIMO) &&
1252 s32 tpt = lq_data->last_tpt / 100;
1253 if (((!tbl->is_fat) &&
1254 (tpt >= expected_tpt_mimo20MHz[index])) ||
1256 (tpt >= expected_tpt_mimo40MHz[index])))
1257 lq_data->search_better_tbl = 0;
1259 rs_get_expected_tpt_table(lq_data, search_tbl);
1260 rs_mcs_from_tbl(&search_tbl->current_rate,
1261 search_tbl, index, is_green);
1266 if (tbl->action > IWL_MIMO_SWITCH_GI)
1267 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1269 if (tbl->action == start_action)
1276 if (tbl->action > IWL_MIMO_SWITCH_GI)
1277 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1282 static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data)
1284 struct iwl_scale_tbl_info *tbl;
1287 int flush_interval_passed = 0;
1289 active_tbl = lq_data->active_tbl;
1291 tbl = &(lq_data->lq_info[active_tbl]);
1293 if (lq_data->stay_in_tbl) {
1295 if (lq_data->flush_timer)
1296 flush_interval_passed =
1298 (unsigned long)(lq_data->flush_timer +
1299 IWL_RATE_SCALE_FLUSH_INTVL));
1301 flush_interval_passed = 0;
1302 if ((lq_data->total_failed > lq_data->max_failure_limit) ||
1303 (lq_data->total_success > lq_data->max_success_limit) ||
1304 ((!lq_data->search_better_tbl) && (lq_data->flush_timer)
1305 && (flush_interval_passed))) {
1306 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1307 lq_data->total_failed,
1308 lq_data->total_success,
1309 flush_interval_passed);
1310 lq_data->stay_in_tbl = 0;
1311 lq_data->total_failed = 0;
1312 lq_data->total_success = 0;
1313 lq_data->flush_timer = 0;
1314 } else if (lq_data->table_count > 0) {
1315 lq_data->table_count++;
1316 if (lq_data->table_count >=
1317 lq_data->table_count_limit) {
1318 lq_data->table_count = 0;
1320 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1321 for (i = 0; i < IWL_RATE_COUNT; i++)
1322 rs_rate_scale_clear_window(
1327 if (!lq_data->stay_in_tbl) {
1328 for (i = 0; i < IWL_RATE_COUNT; i++)
1329 rs_rate_scale_clear_window(&(tbl->win[i]));
1334 static void rs_rate_scale_perform(struct iwl_priv *priv,
1335 struct net_device *dev,
1336 struct ieee80211_hdr *hdr,
1337 struct sta_info *sta)
1339 int low = IWL_RATE_INVALID;
1340 int high = IWL_RATE_INVALID;
1343 struct iwl_rate_scale_data *window = NULL;
1344 int current_tpt = IWL_INVALID_VALUE;
1345 int low_tpt = IWL_INVALID_VALUE;
1346 int high_tpt = IWL_INVALID_VALUE;
1348 s8 scale_action = 0;
1351 struct iwl_rate_scale_priv *lq_data;
1352 struct iwl_scale_tbl_info *tbl, *tbl1;
1353 u16 rate_scale_index_msk = 0;
1354 struct iwl_rate mcs_rate;
1360 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1362 fc = le16_to_cpu(hdr->frame_control);
1363 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1364 /* Send management frames and broadcast/multicast data using
1366 /* TODO: this could probably be improved.. */
1370 if (!sta || !sta->rate_ctrl_priv)
1373 if (!priv->lq_mngr.lq_ready) {
1374 IWL_DEBUG_RATE("still rate scaling not ready\n");
1377 lq_data = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1379 if (!lq_data->search_better_tbl)
1380 active_tbl = lq_data->active_tbl;
1382 active_tbl = 1 - lq_data->active_tbl;
1384 tbl = &(lq_data->lq_info[active_tbl]);
1385 is_green = lq_data->is_green;
1387 index = sta->last_txrate;
1389 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1392 rs_get_supported_rates(lq_data, hdr, tbl->lq_type,
1395 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1397 /* mask with station rate restriction */
1398 if (is_legacy(tbl->lq_type)) {
1399 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1400 rate_scale_index_msk = (u16) (rate_mask &
1401 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
1403 rate_scale_index_msk = (u16) (rate_mask &
1404 lq_data->supp_rates);
1407 rate_scale_index_msk = rate_mask;
1409 if (!rate_scale_index_msk)
1410 rate_scale_index_msk = rate_mask;
1412 if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
1413 index = IWL_INVALID_VALUE;
1416 /* get the lowest availabe rate */
1417 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1418 if ((1 << i) & rate_scale_index_msk)
1422 if (index == IWL_INVALID_VALUE) {
1423 IWL_WARNING("Can not find a suitable rate\n");
1428 if (!tbl->expected_tpt)
1429 rs_get_expected_tpt_table(lq_data, tbl);
1431 window = &(tbl->win[index]);
1433 fail_count = window->counter - window->success_counter;
1434 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1435 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
1436 || (tbl->expected_tpt == NULL)) {
1437 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1439 window->success_counter, window->counter, index);
1440 window->average_tpt = IWL_INVALID_VALUE;
1441 rs_stay_in_table(lq_data);
1443 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1444 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1445 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1450 window->average_tpt = ((window->success_ratio *
1451 tbl->expected_tpt[index] + 64) / 128);
1453 if (lq_data->search_better_tbl) {
1454 int success_limit = IWL_RATE_SCALE_SWITCH;
1456 if ((window->success_ratio > success_limit) ||
1457 (window->average_tpt > lq_data->last_tpt)) {
1458 if (!is_legacy(tbl->lq_type)) {
1459 IWL_DEBUG_HT("LQ: we are switching to HT"
1460 " rate suc %d current tpt %d"
1462 window->success_ratio,
1463 window->average_tpt,
1465 lq_data->enable_counter = 1;
1467 lq_data->active_tbl = active_tbl;
1468 current_tpt = window->average_tpt;
1470 tbl->lq_type = LQ_NONE;
1471 active_tbl = lq_data->active_tbl;
1472 tbl = &(lq_data->lq_info[active_tbl]);
1474 index = iwl_rate_index_from_plcp(
1475 tbl->current_rate.rate_n_flags);
1478 current_tpt = lq_data->last_tpt;
1479 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1481 lq_data->search_better_tbl = 0;
1486 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
1488 low = high_low & 0xff;
1489 high = (high_low >> 8) & 0xff;
1491 current_tpt = window->average_tpt;
1493 if (low != IWL_RATE_INVALID)
1494 low_tpt = tbl->win[low].average_tpt;
1496 if (high != IWL_RATE_INVALID)
1497 high_tpt = tbl->win[high].average_tpt;
1502 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
1503 (current_tpt == 0)) {
1504 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1506 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1507 (high_tpt == IWL_INVALID_VALUE))
1509 else if ((low_tpt != IWL_INVALID_VALUE) &&
1510 (high_tpt != IWL_INVALID_VALUE) &&
1511 (low_tpt < current_tpt) &&
1512 (high_tpt < current_tpt))
1515 if (high_tpt != IWL_INVALID_VALUE) {
1516 if (high_tpt > current_tpt)
1520 ("decrease rate because of high tpt\n");
1523 } else if (low_tpt != IWL_INVALID_VALUE) {
1524 if (low_tpt > current_tpt) {
1526 ("decrease rate because of low tpt\n");
1533 if (scale_action == -1) {
1534 if ((low != IWL_RATE_INVALID) &&
1535 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1536 (current_tpt > (100 * tbl->expected_tpt[low]))))
1538 } else if ((scale_action == 1) &&
1539 (window->success_ratio < IWL_RATE_INCREASE_TH))
1542 switch (scale_action) {
1544 if (low != IWL_RATE_INVALID) {
1550 if (high != IWL_RATE_INVALID) {
1561 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1562 "high %d type %d\n",
1563 index, scale_action, low, high, tbl->lq_type);
1567 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1568 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1569 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1571 rs_stay_in_table(lq_data);
1573 if (!update_lq && !done_search && !lq_data->stay_in_tbl) {
1574 lq_data->last_tpt = current_tpt;
1576 if (is_legacy(tbl->lq_type))
1577 rs_move_legacy_other(priv, lq_data, index);
1578 else if (is_siso(tbl->lq_type))
1579 rs_move_siso_to_other(priv, lq_data, index);
1581 rs_move_mimo_to_other(priv, lq_data, index);
1583 if (lq_data->search_better_tbl) {
1584 tbl = &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1585 for (i = 0; i < IWL_RATE_COUNT; i++)
1586 rs_rate_scale_clear_window(&(tbl->win[i]));
1588 index = iwl_rate_index_from_plcp(
1589 tbl->current_rate.rate_n_flags);
1591 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1592 tbl->current_rate.rate_n_flags, index);
1593 rs_fill_link_cmd(lq_data, &tbl->current_rate,
1595 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1597 tbl1 = &(lq_data->lq_info[lq_data->active_tbl]);
1599 if (is_legacy(tbl1->lq_type) &&
1600 #ifdef CONFIG_IWLWIFI_HT
1601 !priv->current_assoc_ht.is_ht &&
1603 (lq_data->action_counter >= 1)) {
1604 lq_data->action_counter = 0;
1605 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1606 rs_set_stay_in_table(1, lq_data);
1609 if (lq_data->enable_counter &&
1610 (lq_data->action_counter >= IWL_ACTION_LIMIT)) {
1611 #ifdef CONFIG_IWLWIFI_HT_AGG
1612 if ((lq_data->last_tpt > TID_AGG_TPT_THREHOLD) &&
1613 (priv->lq_mngr.agg_ctrl.auto_agg)) {
1614 priv->lq_mngr.agg_ctrl.tid_retry =
1616 schedule_work(&priv->agg_work);
1618 #endif /*CONFIG_IWLWIFI_HT_AGG */
1619 lq_data->action_counter = 0;
1620 rs_set_stay_in_table(0, lq_data);
1623 if ((!update_lq) && (!done_search) && (!lq_data->flush_timer))
1624 lq_data->flush_timer = jiffies;
1628 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
1630 sta->last_txrate = i;
1632 /* sta->txrate is an index to A mode rates which start
1633 * at IWL_FIRST_OFDM_RATE
1635 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1636 sta->txrate = i - IWL_FIRST_OFDM_RATE;
1644 static void rs_initialize_lq(struct iwl_priv *priv,
1645 struct sta_info *sta)
1648 struct iwl_rate_scale_priv *lq;
1649 struct iwl_scale_tbl_info *tbl;
1652 u8 use_green = rs_use_green(priv);
1653 struct iwl_rate mcs_rate;
1655 if (!sta || !sta->rate_ctrl_priv)
1658 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1659 i = sta->last_txrate;
1661 if ((lq->lq.sta_id == 0xff) &&
1662 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
1665 if (!lq->search_better_tbl)
1666 active_tbl = lq->active_tbl;
1668 active_tbl = 1 - lq->active_tbl;
1670 tbl = &(lq->lq_info[active_tbl]);
1672 if ((i < 0) || (i >= IWL_RATE_COUNT))
1675 mcs_rate.rate_n_flags = iwl_rates[i].plcp ;
1676 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
1677 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
1679 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
1680 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
1682 tbl->antenna_type = ANT_AUX;
1683 rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx);
1684 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
1685 rs_toggle_antenna(&mcs_rate, tbl);
1687 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
1688 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
1689 rs_get_expected_tpt_table(lq, tbl);
1690 rs_fill_link_cmd(lq, &mcs_rate, &lq->lq);
1691 rs_send_lq_cmd(priv, &lq->lq, CMD_ASYNC);
1696 static struct ieee80211_rate *rs_get_lowest_rate(struct ieee80211_local
1699 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
1702 for (i = 0; i < mode->num_rates; i++) {
1703 struct ieee80211_rate *rate = &mode->rates[i];
1705 if (rate->flags & IEEE80211_RATE_SUPPORTED)
1709 return &mode->rates[0];
1712 static struct ieee80211_rate *rs_get_rate(void *priv_rate,
1713 struct net_device *dev,
1714 struct sk_buff *skb,
1715 struct rate_control_extra
1720 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1721 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1722 struct sta_info *sta;
1724 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1725 struct iwl_rate_scale_priv *lq;
1727 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1729 memset(extra, 0, sizeof(*extra));
1731 fc = le16_to_cpu(hdr->frame_control);
1732 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1733 /* Send management frames and broadcast/multicast data using
1735 /* TODO: this could probably be improved.. */
1736 return rs_get_lowest_rate(local);
1739 sta = sta_info_get(local, hdr->addr1);
1741 if (!sta || !sta->rate_ctrl_priv) {
1744 return rs_get_lowest_rate(local);
1747 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1748 i = sta->last_txrate;
1750 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) {
1751 u8 sta_id = iwl_hw_find_station(priv, hdr->addr1);
1752 DECLARE_MAC_BUF(mac);
1754 if (sta_id == IWL_INVALID_STATION) {
1755 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1756 print_mac(mac, hdr->addr1));
1757 sta_id = iwl_add_station(priv,
1758 hdr->addr1, 0, CMD_ASYNC);
1760 if ((sta_id != IWL_INVALID_STATION)) {
1761 lq->lq.sta_id = sta_id;
1762 lq->lq.rs_table[0].rate_n_flags = 0;
1763 lq->ibss_sta_added = 1;
1764 rs_initialize_lq(priv, sta);
1766 if (!lq->ibss_sta_added)
1772 if ((i < 0) || (i > IWL_RATE_COUNT))
1773 return rs_get_lowest_rate(local);
1775 return &priv->ieee_rates[i];
1778 static void *rs_alloc_sta(void *priv, gfp_t gfp)
1780 struct iwl_rate_scale_priv *crl;
1783 IWL_DEBUG_RATE("create station rate scale window\n");
1785 crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp);
1789 crl->lq.sta_id = 0xff;
1792 for (j = 0; j < LQ_SIZE; j++)
1793 for (i = 0; i < IWL_RATE_COUNT; i++)
1794 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1799 static void rs_rate_init(void *priv_rate, void *priv_sta,
1800 struct ieee80211_local *local,
1801 struct sta_info *sta)
1804 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
1805 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1806 struct iwl_rate_scale_priv *crl = priv_sta;
1808 crl->flush_timer = 0;
1809 crl->supp_rates = sta->supp_rates;
1811 for (j = 0; j < LQ_SIZE; j++)
1812 for (i = 0; i < IWL_RATE_COUNT; i++)
1813 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1815 IWL_DEBUG_RATE("rate scale global init\n");
1816 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1817 * the lowest or the highest rate.. Could consider using RSSI from
1818 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1821 crl->ibss_sta_added = 0;
1822 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1823 u8 sta_id = iwl_hw_find_station(priv, sta->addr);
1824 DECLARE_MAC_BUF(mac);
1826 /* for IBSS the call are from tasklet */
1827 IWL_DEBUG_HT("LQ: ADD station %s\n",
1828 print_mac(mac, sta->addr));
1830 if (sta_id == IWL_INVALID_STATION) {
1831 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1832 print_mac(mac, sta->addr));
1833 sta_id = iwl_add_station(priv,
1834 sta->addr, 0, CMD_ASYNC);
1836 if ((sta_id != IWL_INVALID_STATION)) {
1837 crl->lq.sta_id = sta_id;
1838 crl->lq.rs_table[0].rate_n_flags = 0;
1840 /* FIXME: this is w/a remove it later */
1841 priv->assoc_station_added = 1;
1844 for (i = 0; i < mode->num_rates; i++) {
1845 if ((sta->supp_rates & BIT(i)) &&
1846 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))
1849 sta->last_txrate = sta->txrate;
1850 /* For MODE_IEEE80211A mode cck rate are at end
1853 if (local->hw.conf.phymode == MODE_IEEE80211A)
1854 sta->last_txrate += IWL_FIRST_OFDM_RATE;
1856 crl->is_dup = priv->is_dup;
1857 crl->valid_antenna = priv->valid_antenna;
1858 crl->antenna = priv->antenna;
1859 crl->is_green = rs_use_green(priv);
1860 crl->active_rate = priv->active_rate;
1861 crl->active_rate &= ~(0x1000);
1862 crl->active_rate_basic = priv->active_rate_basic;
1863 crl->phymode = priv->phymode;
1864 #ifdef CONFIG_IWLWIFI_HT
1865 crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1);
1866 crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1);
1867 crl->active_siso_rate &= ~((u16)0x2);
1868 crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE;
1870 crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1);
1871 crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1);
1872 crl->active_mimo_rate &= ~((u16)0x2);
1873 crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE;
1874 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate,
1875 crl->active_mimo_rate);
1876 #endif /*CONFIG_IWLWIFI_HT*/
1877 #ifdef CONFIG_MAC80211_DEBUGFS
1881 if (priv->assoc_station_added)
1882 priv->lq_mngr.lq_ready = 1;
1884 rs_initialize_lq(priv, sta);
1887 static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
1888 struct iwl_rate *tx_mcs,
1889 struct iwl_link_quality_cmd *lq_cmd)
1893 int repeat_rate = 0;
1894 u8 ant_toggle_count = 0;
1895 u8 use_ht_possible = 1;
1896 struct iwl_rate new_rate;
1897 struct iwl_scale_tbl_info tbl_type = { 0 };
1899 rs_dbgfs_set_mcs(lq_data, tx_mcs, index);
1901 rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode,
1902 &tbl_type, &rate_idx);
1904 if (is_legacy(tbl_type.lq_type)) {
1905 ant_toggle_count = 1;
1906 repeat_rate = IWL_NUMBER_TRY;
1908 repeat_rate = IWL_HT_NUMBER_TRY;
1910 lq_cmd->general_params.mimo_delimiter =
1911 is_mimo(tbl_type.lq_type) ? 1 : 0;
1912 lq_cmd->rs_table[index].rate_n_flags =
1913 cpu_to_le32(tx_mcs->rate_n_flags);
1914 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
1916 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))
1917 lq_cmd->general_params.single_stream_ant_msk = 1;
1919 lq_cmd->general_params.single_stream_ant_msk = 2;
1924 while (index < LINK_QUAL_MAX_RETRY_NUM) {
1925 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
1926 if (is_legacy(tbl_type.lq_type)) {
1927 if (ant_toggle_count <
1928 NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1931 rs_toggle_antenna(&new_rate, &tbl_type);
1932 ant_toggle_count = 1;
1936 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1937 lq_cmd->rs_table[index].rate_n_flags =
1938 cpu_to_le32(new_rate.rate_n_flags);
1943 rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type,
1946 if (is_mimo(tbl_type.lq_type))
1947 lq_cmd->general_params.mimo_delimiter = index;
1949 rs_get_lower_rate(lq_data, &tbl_type, rate_idx,
1950 use_ht_possible, &new_rate);
1952 if (is_legacy(tbl_type.lq_type)) {
1953 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1956 rs_toggle_antenna(&new_rate, &tbl_type);
1957 ant_toggle_count = 1;
1959 repeat_rate = IWL_NUMBER_TRY;
1961 repeat_rate = IWL_HT_NUMBER_TRY;
1963 use_ht_possible = 0;
1965 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1966 lq_cmd->rs_table[index].rate_n_flags =
1967 cpu_to_le32(new_rate.rate_n_flags);
1973 lq_cmd->general_params.dual_stream_ant_msk = 3;
1974 lq_cmd->agg_params.agg_dis_start_th = 3;
1975 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
1978 static void *rs_alloc(struct ieee80211_local *local)
1980 return local->hw.priv;
1982 /* rate scale requires free function to be implemented */
1983 static void rs_free(void *priv_rate)
1988 static void rs_clear(void *priv_rate)
1990 struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
1992 IWL_DEBUG_RATE("enter\n");
1994 priv->lq_mngr.lq_ready = 0;
1995 #ifdef CONFIG_IWLWIFI_HT
1996 #ifdef CONFIG_IWLWIFI_HT_AGG
1997 if (priv->lq_mngr.agg_ctrl.granted_ba)
1998 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);
1999 #endif /*CONFIG_IWLWIFI_HT_AGG */
2000 #endif /* CONFIG_IWLWIFI_HT */
2002 IWL_DEBUG_RATE("leave\n");
2005 static void rs_free_sta(void *priv, void *priv_sta)
2007 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2009 IWL_DEBUG_RATE("enter\n");
2011 IWL_DEBUG_RATE("leave\n");
2015 #ifdef CONFIG_MAC80211_DEBUGFS
2016 static int open_file_generic(struct inode *inode, struct file *file)
2018 file->private_data = inode->i_private;
2021 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
2022 struct iwl_rate *mcs, int index)
2026 if (rs_priv->phymode == (u8) MODE_IEEE80211A)
2031 if (rs_priv->dbg_fixed.rate_n_flags) {
2033 mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags;
2035 mcs->rate_n_flags = base_rate;
2036 IWL_DEBUG_RATE("Fixed rate ON\n");
2040 IWL_DEBUG_RATE("Fixed rate OFF\n");
2043 static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2044 const char __user *user_buf, size_t count, loff_t *ppos)
2046 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2051 memset(buf, 0, sizeof(buf));
2052 buf_size = min(count, sizeof(buf) - 1);
2053 if (copy_from_user(buf, user_buf, buf_size))
2056 if (sscanf(buf, "%x", &parsed_rate) == 1)
2057 rs_priv->dbg_fixed.rate_n_flags = parsed_rate;
2059 rs_priv->dbg_fixed.rate_n_flags = 0;
2061 rs_priv->active_rate = 0x0FFF;
2062 rs_priv->active_siso_rate = 0x1FD0;
2063 rs_priv->active_mimo_rate = 0x1FD0;
2065 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2066 rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags);
2068 if (rs_priv->dbg_fixed.rate_n_flags) {
2069 rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq);
2070 rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC);
2076 static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2077 char __user *user_buf, size_t count, loff_t *ppos)
2083 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2085 desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id);
2086 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2087 rs_priv->total_failed, rs_priv->total_success,
2088 rs_priv->active_rate);
2089 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2090 rs_priv->dbg_fixed.rate_n_flags);
2091 desc += sprintf(buff+desc, "general:"
2092 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2093 rs_priv->lq.general_params.flags,
2094 rs_priv->lq.general_params.mimo_delimiter,
2095 rs_priv->lq.general_params.single_stream_ant_msk,
2096 rs_priv->lq.general_params.dual_stream_ant_msk);
2098 desc += sprintf(buff+desc, "agg:"
2099 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2100 le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit),
2101 rs_priv->lq.agg_params.agg_dis_start_th,
2102 rs_priv->lq.agg_params.agg_frame_cnt_limit);
2104 desc += sprintf(buff+desc,
2105 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2106 rs_priv->lq.general_params.start_rate_index[0],
2107 rs_priv->lq.general_params.start_rate_index[1],
2108 rs_priv->lq.general_params.start_rate_index[2],
2109 rs_priv->lq.general_params.start_rate_index[3]);
2112 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
2113 desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
2114 i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags));
2116 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2119 static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2120 .write = rs_sta_dbgfs_scale_table_write,
2121 .read = rs_sta_dbgfs_scale_table_read,
2122 .open = open_file_generic,
2124 static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2125 char __user *user_buf, size_t count, loff_t *ppos)
2131 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2132 for (i = 0; i < LQ_SIZE; i++) {
2133 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2135 rs_priv->active_tbl == i?"*":"x",
2136 rs_priv->lq_info[i].lq_type,
2137 rs_priv->lq_info[i].is_SGI,
2138 rs_priv->lq_info[i].is_fat,
2139 rs_priv->lq_info[i].is_dup,
2140 rs_priv->lq_info[i].current_rate.rate_n_flags);
2141 for (j = 0; j < IWL_RATE_COUNT; j++) {
2142 desc += sprintf(buff+desc,
2143 "counter=%d success=%d %%=%d\n",
2144 rs_priv->lq_info[i].win[j].counter,
2145 rs_priv->lq_info[i].win[j].success_counter,
2146 rs_priv->lq_info[i].win[j].success_ratio);
2149 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2152 static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2153 .read = rs_sta_dbgfs_stats_table_read,
2154 .open = open_file_generic,
2157 static void rs_add_debugfs(void *priv, void *priv_sta,
2160 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2161 rs_priv->rs_sta_dbgfs_scale_table_file =
2162 debugfs_create_file("rate_scale_table", 0600, dir,
2163 rs_priv, &rs_sta_dbgfs_scale_table_ops);
2164 rs_priv->rs_sta_dbgfs_stats_table_file =
2165 debugfs_create_file("rate_stats_table", 0600, dir,
2166 rs_priv, &rs_sta_dbgfs_stats_table_ops);
2169 static void rs_remove_debugfs(void *priv, void *priv_sta)
2171 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2172 debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file);
2173 debugfs_remove(rs_priv->rs_sta_dbgfs_stats_table_file);
2177 static struct rate_control_ops rs_ops = {
2180 .tx_status = rs_tx_status,
2181 .get_rate = rs_get_rate,
2182 .rate_init = rs_rate_init,
2186 .alloc_sta = rs_alloc_sta,
2187 .free_sta = rs_free_sta,
2188 #ifdef CONFIG_MAC80211_DEBUGFS
2189 .add_sta_debugfs = rs_add_debugfs,
2190 .remove_sta_debugfs = rs_remove_debugfs,
2194 int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2196 struct ieee80211_local *local = hw_to_local(hw);
2197 struct iwl_priv *priv = hw->priv;
2198 struct iwl_rate_scale_priv *rs_priv;
2199 struct sta_info *sta;
2201 u32 samples = 0, success = 0, good = 0;
2202 unsigned long now = jiffies;
2204 u8 lq_type, antenna;
2206 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2207 if (!sta || !sta->rate_ctrl_priv) {
2210 IWL_DEBUG_RATE("leave - no private rate data!\n");
2212 IWL_DEBUG_RATE("leave - no station!\n");
2213 return sprintf(buf, "station %d not found\n", sta_id);
2216 rs_priv = (void *)sta->rate_ctrl_priv;
2218 lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type;
2219 antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type;
2221 if (is_legacy(lq_type))
2222 i = IWL_RATE_54M_INDEX;
2224 i = IWL_RATE_60M_INDEX;
2228 int active = rs_priv->active_tbl;
2231 sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2);
2233 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2234 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
2236 (rs_priv->lq_info[active].win[i].data & mask)
2239 samples += rs_priv->lq_info[active].win[i].counter;
2240 good += rs_priv->lq_info[active].win[i].success_counter;
2241 success += rs_priv->lq_info[active].win[i].success_counter *
2244 if (rs_priv->lq_info[active].win[i].stamp) {
2246 jiffies_to_msecs(now -
2247 rs_priv->lq_info[active].win[i].stamp);
2249 if (delta > max_time)
2252 count += sprintf(&buf[count], "%5dms\n", delta);
2254 buf[count++] = '\n';
2256 j = iwl_get_prev_ieee_rate(i);
2262 /* Display the average rate of all samples taken.
2264 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2265 * added from iwl_rates is actually 2X the rate */
2267 count += sprintf(&buf[count],
2268 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2269 "%3d%% success (%d good packets over %d tries)\n",
2270 success / (2 * samples), (success * 5 / samples) % 10,
2271 max_time, good * 100 / samples, good, samples);
2273 count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
2274 count += sprintf(&buf[count], "\nrate scale type %d anntena %d "
2275 "active_search %d rate index %d\n", lq_type, antenna,
2276 rs_priv->search_better_tbl, sta->last_txrate);
2282 void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
2284 struct iwl_priv *priv = hw->priv;
2286 priv->lq_mngr.lq_ready = 1;
2289 void iwl_rate_control_register(struct ieee80211_hw *hw)
2291 ieee80211_rate_control_register(&rs_ops);
2294 void iwl_rate_control_unregister(struct ieee80211_hw *hw)
2296 ieee80211_rate_control_unregister(&rs_ops);