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
205 struct iwl_host_cmd cmd = {
206 .id = REPLY_TX_LINK_QUALITY_CMD,
207 .len = sizeof(struct iwl_link_quality_cmd),
212 if ((lq->sta_id == 0xFF) &&
213 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
216 if (lq->sta_id == 0xFF)
217 lq->sta_id = IWL_AP_ID;
219 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
220 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
221 lq->general_params.single_stream_ant_msk,
222 lq->general_params.dual_stream_ant_msk);
223 #ifdef CONFIG_IWLWIFI_DEBUG
224 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
225 IWL_DEBUG_RATE("lq index %d 0x%X\n",
226 i, lq->rs_table[i].rate_n_flags);
229 if (flags & CMD_ASYNC)
230 cmd.meta.u.callback = iwl_lq_sync_callback;
232 if (iwl_is_associated(priv) && priv->assoc_station_added &&
233 priv->lq_mngr.lq_ready)
234 return iwl_send_cmd(priv, &cmd);
239 static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
242 window->success_counter = 0;
243 window->success_ratio = IWL_INVALID_VALUE;
245 window->average_tpt = IWL_INVALID_VALUE;
249 static int rs_collect_tx_data(struct iwl_rate_scale_data *windows,
250 int scale_index, s32 tpt, u32 status)
252 struct iwl_rate_scale_data *window = NULL;
254 u8 win_size = IWL_RATE_MAX_WINDOW;
257 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
260 window = &(windows[scale_index]);
262 if (window->counter >= win_size) {
264 window->counter = win_size - 1;
266 mask = (mask << (win_size - 1));
267 if ((window->data & mask)) {
268 window->data &= ~mask;
269 window->success_counter = window->success_counter - 1;
273 window->counter = window->counter + 1;
275 window->data = (mask << 1);
277 window->success_counter = window->success_counter + 1;
281 if (window->counter > 0)
282 window->success_ratio = 128 * (100 * window->success_counter)
285 window->success_ratio = IWL_INVALID_VALUE;
287 fail_count = window->counter - window->success_counter;
289 if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
290 (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
291 window->average_tpt = (window->success_ratio * tpt + 64) / 128;
293 window->average_tpt = IWL_INVALID_VALUE;
295 window->stamp = jiffies;
300 static void rs_mcs_from_tbl(struct iwl_rate *mcs_rate,
301 struct iwl_scale_tbl_info *tbl,
302 int index, u8 use_green)
304 if (is_legacy(tbl->lq_type)) {
305 mcs_rate->rate_n_flags = iwl_rates[index].plcp;
306 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
307 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
309 } else if (is_siso(tbl->lq_type)) {
310 if (index > IWL_LAST_OFDM_RATE)
311 index = IWL_LAST_OFDM_RATE;
312 mcs_rate->rate_n_flags = iwl_rates[index].plcp_siso |
315 if (index > IWL_LAST_OFDM_RATE)
316 index = IWL_LAST_OFDM_RATE;
317 mcs_rate->rate_n_flags = iwl_rates[index].plcp_mimo |
321 switch (tbl->antenna_type) {
323 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
326 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
329 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
335 if (is_legacy(tbl->lq_type))
340 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
342 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
345 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
348 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
349 if (is_siso(tbl->lq_type))
350 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
354 static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate,
355 int phymode, struct iwl_scale_tbl_info *tbl,
361 index = iwl_rate_index_from_plcp(mcs_rate->rate_n_flags);
363 if (index == IWL_RATE_INVALID) {
370 tbl->antenna_type = ANT_BOTH;
372 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
373 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
375 if (ant_msk == RATE_MCS_ANT_AB_MSK)
376 tbl->lq_type = LQ_NONE;
379 if (phymode == MODE_IEEE80211A)
384 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
385 tbl->antenna_type = ANT_MAIN;
387 tbl->antenna_type = ANT_AUX;
391 } else if (iwl_rate_get_rate(mcs_rate->rate_n_flags)
392 <= IWL_RATE_SISO_60M_PLCP) {
393 tbl->lq_type = LQ_SISO;
395 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
396 if (ant_msk == RATE_MCS_ANT_AB_MSK)
397 tbl->lq_type = LQ_NONE;
399 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
400 tbl->antenna_type = ANT_MAIN;
402 tbl->antenna_type = ANT_AUX;
404 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
407 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
408 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
411 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
416 tbl->lq_type = LQ_MIMO;
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)
431 static inline void rs_toggle_antenna(struct iwl_rate *new_rate,
432 struct iwl_scale_tbl_info *tbl)
434 if (tbl->antenna_type == ANT_AUX) {
435 tbl->antenna_type = ANT_MAIN;
436 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK;
437 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
439 tbl->antenna_type = ANT_AUX;
440 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
441 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
445 static inline u8 rs_use_green(struct iwl_priv *priv)
447 #ifdef CONFIG_IWLWIFI_HT
448 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
451 return ((priv->current_assoc_ht.is_green_field) &&
452 !(priv->current_assoc_ht.operating_mode & 0x4));
453 #endif /*CONFIG_IWLWIFI_HT */
458 * rs_get_supported_rates - get the available rates
460 * if management frame or broadcast frame only return
461 * basic available rates.
464 static void rs_get_supported_rates(struct iwl_rate_scale_priv *lq_data,
465 struct ieee80211_hdr *hdr,
466 enum iwl_table_type rate_type,
469 if (is_legacy(rate_type))
470 *data_rate = lq_data->active_rate;
472 if (is_siso(rate_type))
473 *data_rate = lq_data->active_siso_rate;
475 *data_rate = lq_data->active_mimo_rate;
478 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
479 lq_data->active_rate_basic)
480 *data_rate = lq_data->active_rate_basic;
483 static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
485 u8 high = IWL_RATE_INVALID;
486 u8 low = IWL_RATE_INVALID;
488 /* 802.11A or ht walks to the next literal adjacent rate in
490 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
494 /* Find the previous rate that is in the rate mask */
496 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
497 if (rate_mask & mask) {
503 /* Find the next rate that is in the rate mask */
505 for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
506 if (rate_mask & mask) {
512 return (high << 8) | low;
516 while (low != IWL_RATE_INVALID) {
517 low = iwl_rates[low].prev_rs;
518 if (low == IWL_RATE_INVALID)
520 if (rate_mask & (1 << low))
522 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
526 while (high != IWL_RATE_INVALID) {
527 high = iwl_rates[high].next_rs;
528 if (high == IWL_RATE_INVALID)
530 if (rate_mask & (1 << high))
532 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
535 return (high << 8) | low;
538 static void rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data,
539 struct iwl_scale_tbl_info *tbl, u8 scale_index,
540 u8 ht_possible, struct iwl_rate *mcs_rate)
545 u8 switch_to_legacy = 0;
546 u8 is_green = lq_data->is_green;
548 /* check if we need to switch from HT to legacy rates.
549 * assumption is that mandatory rates (1Mbps or 6Mbps)
550 * are always supported (spec demand) */
551 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
552 switch_to_legacy = 1;
553 scale_index = rs_ht_to_legacy[scale_index];
554 if (lq_data->phymode == MODE_IEEE80211A)
559 if ((tbl->antenna_type == ANT_BOTH) ||
560 (tbl->antenna_type == ANT_NONE))
561 tbl->antenna_type = ANT_MAIN;
567 rs_get_supported_rates(lq_data, NULL, tbl->lq_type, &rate_mask);
569 /* mask with station rate restriction */
570 if (is_legacy(tbl->lq_type)) {
571 if (lq_data->phymode == (u8) MODE_IEEE80211A)
572 rate_mask = (u16)(rate_mask &
573 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
575 rate_mask = (u16)(rate_mask & lq_data->supp_rates);
578 /* if we did switched from HT to legacy check current rate */
579 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
580 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
584 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
585 low = high_low & 0xff;
587 if (low != IWL_RATE_INVALID)
588 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
590 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
593 static void rs_tx_status(void *priv_rate,
594 struct net_device *dev,
596 struct ieee80211_tx_status *tx_resp)
600 int rs_index, index = 0;
601 struct iwl_rate_scale_priv *lq;
602 struct iwl_link_quality_cmd *table;
603 struct sta_info *sta;
604 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
605 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
606 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
607 struct iwl_rate_scale_data *window = NULL;
608 struct iwl_rate_scale_data *search_win = NULL;
609 struct iwl_rate tx_mcs;
610 struct iwl_scale_tbl_info tbl_type;
611 struct iwl_scale_tbl_info *curr_tbl, *search_tbl;
613 u16 fc = le16_to_cpu(hdr->frame_control);
616 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
618 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
621 retries = tx_resp->retry_count;
627 sta = sta_info_get(local, hdr->addr1);
629 if (!sta || !sta->rate_ctrl_priv) {
635 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
637 if (!priv->lq_mngr.lq_ready)
640 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added)
644 active_index = lq->active_tbl;
646 lq->antenna = (lq->valid_antenna & local->hw.conf.antenna_sel_tx);
648 lq->antenna = lq->valid_antenna;
650 lq->antenna = lq->valid_antenna;
651 curr_tbl = &(lq->lq_info[active_index]);
652 search_tbl = &(lq->lq_info[(1 - active_index)]);
653 window = (struct iwl_rate_scale_data *)
655 search_win = (struct iwl_rate_scale_data *)
656 &(search_tbl->win[0]);
658 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
660 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
661 &tbl_type, &rs_index);
662 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
663 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
664 rs_index, tx_mcs.rate_n_flags);
670 (tx_mcs.rate_n_flags !=
671 le32_to_cpu(table->rs_table[0].rate_n_flags))) {
672 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
674 le32_to_cpu(table->rs_table[0].rate_n_flags));
680 tx_mcs.rate_n_flags =
681 le32_to_cpu(table->rs_table[index].rate_n_flags);
682 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
683 &tbl_type, &rs_index);
685 if ((tbl_type.lq_type == search_tbl->lq_type) &&
686 (tbl_type.antenna_type == search_tbl->antenna_type) &&
687 (tbl_type.is_SGI == search_tbl->is_SGI)) {
688 if (search_tbl->expected_tpt)
689 tpt = search_tbl->expected_tpt[rs_index];
692 rs_collect_tx_data(search_win,
694 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
695 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
696 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
697 if (curr_tbl->expected_tpt)
698 tpt = curr_tbl->expected_tpt[rs_index];
701 rs_collect_tx_data(window, rs_index, tpt, 0);
710 if (!tx_resp->retry_count)
711 tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
713 tx_mcs.rate_n_flags =
714 le32_to_cpu(table->rs_table[index].rate_n_flags);
716 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
717 &tbl_type, &rs_index);
719 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
724 if ((tbl_type.lq_type == search_tbl->lq_type) &&
725 (tbl_type.antenna_type == search_tbl->antenna_type) &&
726 (tbl_type.is_SGI == search_tbl->is_SGI)) {
727 if (search_tbl->expected_tpt)
728 tpt = search_tbl->expected_tpt[rs_index];
731 rs_collect_tx_data(search_win,
732 rs_index, tpt, status);
733 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
734 (tbl_type.antenna_type == curr_tbl->antenna_type) &&
735 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
736 if (curr_tbl->expected_tpt)
737 tpt = curr_tbl->expected_tpt[rs_index];
740 rs_collect_tx_data(window, rs_index, tpt, status);
743 if (lq->stay_in_tbl) {
750 rs_rate_scale_perform(priv, dev, hdr, sta);
755 static u8 rs_is_ant_connected(u8 valid_antenna,
756 enum iwl_antenna_type antenna_type)
758 if (antenna_type == ANT_AUX)
759 return ((valid_antenna & 0x2) ? 1:0);
760 else if (antenna_type == ANT_MAIN)
761 return ((valid_antenna & 0x1) ? 1:0);
762 else if (antenna_type == ANT_BOTH)
763 return ((valid_antenna & 0x3) == 0x3);
768 static u8 rs_is_other_ant_connected(u8 valid_antenna,
769 enum iwl_antenna_type antenna_type)
771 if (antenna_type == ANT_AUX)
772 return rs_is_ant_connected(valid_antenna, ANT_MAIN);
774 return rs_is_ant_connected(valid_antenna, ANT_AUX);
779 static void rs_set_stay_in_table(u8 is_legacy,
780 struct iwl_rate_scale_priv *lq_data)
782 IWL_DEBUG_HT("we are staying in the same table\n");
783 lq_data->stay_in_tbl = 1;
785 lq_data->table_count_limit = IWL_LEGACY_TABLE_COUNT;
786 lq_data->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
787 lq_data->max_success_limit = IWL_LEGACY_TABLE_COUNT;
789 lq_data->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
790 lq_data->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
791 lq_data->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
793 lq_data->table_count = 0;
794 lq_data->total_failed = 0;
795 lq_data->total_success = 0;
798 static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data,
799 struct iwl_scale_tbl_info *tbl)
801 if (is_legacy(tbl->lq_type)) {
802 if (!is_a_band(tbl->lq_type))
803 tbl->expected_tpt = expected_tpt_G;
805 tbl->expected_tpt = expected_tpt_A;
806 } else if (is_siso(tbl->lq_type)) {
807 if (tbl->is_fat && !lq_data->is_dup)
809 tbl->expected_tpt = expected_tpt_siso40MHzSGI;
811 tbl->expected_tpt = expected_tpt_siso40MHz;
812 else if (tbl->is_SGI)
813 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
815 tbl->expected_tpt = expected_tpt_siso20MHz;
817 } else if (is_mimo(tbl->lq_type)) {
818 if (tbl->is_fat && !lq_data->is_dup)
820 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
822 tbl->expected_tpt = expected_tpt_mimo40MHz;
823 else if (tbl->is_SGI)
824 tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
826 tbl->expected_tpt = expected_tpt_mimo20MHz;
828 tbl->expected_tpt = expected_tpt_G;
831 #ifdef CONFIG_IWLWIFI_HT
832 static s32 rs_get_best_rate(struct iwl_priv *priv,
833 struct iwl_rate_scale_priv *lq_data,
834 struct iwl_scale_tbl_info *tbl,
835 u16 rate_mask, s8 index, s8 rate)
837 struct iwl_scale_tbl_info *active_tbl =
838 &(lq_data->lq_info[lq_data->active_tbl]);
839 s32 new_rate, high, low, start_hi;
840 s32 active_sr = active_tbl->win[index].success_ratio;
841 s32 *tpt_tbl = tbl->expected_tpt;
842 s32 active_tpt = active_tbl->expected_tpt[index];
845 new_rate = high = low = start_hi = IWL_RATE_INVALID;
848 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
850 low = high_low & 0xff;
851 high = (high_low >> 8) & 0xff;
853 if ((((100 * tpt_tbl[rate]) > lq_data->last_tpt) &&
854 ((active_sr > IWL_RATE_DECREASE_TH) &&
855 (active_sr <= IWL_RATE_HIGH_TH) &&
856 (tpt_tbl[rate] <= active_tpt))) ||
857 ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
858 (tpt_tbl[rate] > active_tpt))) {
860 if (start_hi != IWL_RATE_INVALID) {
865 if (low != IWL_RATE_INVALID)
870 if (new_rate != IWL_RATE_INVALID)
872 else if (high != IWL_RATE_INVALID) {
884 #endif /* CONFIG_IWLWIFI_HT */
886 static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
888 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
891 static int rs_switch_to_mimo(struct iwl_priv *priv,
892 struct iwl_rate_scale_priv *lq_data,
893 struct iwl_scale_tbl_info *tbl, int index)
895 #ifdef CONFIG_IWLWIFI_HT
898 s8 is_green = lq_data->is_green;
900 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
903 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
904 tbl->lq_type = LQ_MIMO;
905 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
908 if (priv->current_assoc_ht.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
911 if (!rs_is_both_ant_supp(lq_data->antenna))
914 tbl->is_dup = lq_data->is_dup;
916 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
922 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
926 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
931 rs_get_expected_tpt_table(lq_data, tbl);
933 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
935 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
936 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
938 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
940 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
941 tbl->current_rate.rate_n_flags, is_green);
943 #endif /*CONFIG_IWLWIFI_HT */
947 static int rs_switch_to_siso(struct iwl_priv *priv,
948 struct iwl_rate_scale_priv *lq_data,
949 struct iwl_scale_tbl_info *tbl, int index)
951 #ifdef CONFIG_IWLWIFI_HT
953 u8 is_green = lq_data->is_green;
956 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
957 if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
960 tbl->is_dup = lq_data->is_dup;
961 tbl->lq_type = LQ_SISO;
963 rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
966 if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
972 if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
976 } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
984 rs_get_expected_tpt_table(lq_data, tbl);
985 rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
987 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
988 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
989 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
993 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
994 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
995 tbl->current_rate.rate_n_flags, is_green);
997 #endif /*CONFIG_IWLWIFI_HT */
1001 static int rs_move_legacy_other(struct iwl_priv *priv,
1002 struct iwl_rate_scale_priv *lq_data,
1006 struct iwl_scale_tbl_info *tbl =
1007 &(lq_data->lq_info[lq_data->active_tbl]);
1008 struct iwl_scale_tbl_info *search_tbl =
1009 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1010 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1011 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1012 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1013 u8 start_action = tbl->action;
1016 switch (tbl->action) {
1017 case IWL_LEGACY_SWITCH_ANTENNA:
1018 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1020 search_tbl->lq_type = LQ_NONE;
1021 lq_data->action_counter++;
1022 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1024 if (!rs_is_other_ant_connected(lq_data->antenna,
1028 memcpy(search_tbl, tbl, sz);
1030 rs_toggle_antenna(&(search_tbl->current_rate),
1032 rs_get_expected_tpt_table(lq_data, search_tbl);
1033 lq_data->search_better_tbl = 1;
1036 case IWL_LEGACY_SWITCH_SISO:
1037 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1038 memcpy(search_tbl, tbl, sz);
1039 search_tbl->lq_type = LQ_SISO;
1040 search_tbl->is_SGI = 0;
1041 search_tbl->is_fat = 0;
1042 ret = rs_switch_to_siso(priv, lq_data, search_tbl,
1045 lq_data->search_better_tbl = 1;
1046 lq_data->action_counter = 0;
1051 case IWL_LEGACY_SWITCH_MIMO:
1052 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1053 memcpy(search_tbl, tbl, sz);
1054 search_tbl->lq_type = LQ_MIMO;
1055 search_tbl->is_SGI = 0;
1056 search_tbl->is_fat = 0;
1057 search_tbl->antenna_type = ANT_BOTH;
1058 ret = rs_switch_to_mimo(priv, lq_data, search_tbl,
1061 lq_data->search_better_tbl = 1;
1062 lq_data->action_counter = 0;
1068 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1069 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1071 if (tbl->action == start_action)
1079 if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
1080 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1085 static int rs_move_siso_to_other(struct iwl_priv *priv,
1086 struct iwl_rate_scale_priv *lq_data,
1090 u8 is_green = lq_data->is_green;
1091 struct iwl_scale_tbl_info *tbl =
1092 &(lq_data->lq_info[lq_data->active_tbl]);
1093 struct iwl_scale_tbl_info *search_tbl =
1094 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1095 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1096 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1097 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1098 u8 start_action = tbl->action;
1101 lq_data->action_counter++;
1102 switch (tbl->action) {
1103 case IWL_SISO_SWITCH_ANTENNA:
1104 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1105 search_tbl->lq_type = LQ_NONE;
1106 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1108 if (!rs_is_other_ant_connected(lq_data->antenna,
1112 memcpy(search_tbl, tbl, sz);
1113 search_tbl->action = IWL_SISO_SWITCH_MIMO;
1114 rs_toggle_antenna(&(search_tbl->current_rate),
1116 lq_data->search_better_tbl = 1;
1120 case IWL_SISO_SWITCH_MIMO:
1121 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1122 memcpy(search_tbl, tbl, sz);
1123 search_tbl->lq_type = LQ_MIMO;
1124 search_tbl->is_SGI = 0;
1125 search_tbl->is_fat = 0;
1126 search_tbl->antenna_type = ANT_BOTH;
1127 ret = rs_switch_to_mimo(priv, lq_data, search_tbl,
1130 lq_data->search_better_tbl = 1;
1134 case IWL_SISO_SWITCH_GI:
1135 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1136 memcpy(search_tbl, tbl, sz);
1137 search_tbl->action = 0;
1138 if (search_tbl->is_SGI)
1139 search_tbl->is_SGI = 0;
1141 search_tbl->is_SGI = 1;
1144 lq_data->search_better_tbl = 1;
1145 if ((tbl->lq_type == LQ_SISO) &&
1147 s32 tpt = lq_data->last_tpt / 100;
1148 if (((!tbl->is_fat) &&
1149 (tpt >= expected_tpt_siso20MHz[index])) ||
1151 (tpt >= expected_tpt_siso40MHz[index])))
1152 lq_data->search_better_tbl = 0;
1154 rs_get_expected_tpt_table(lq_data, search_tbl);
1155 rs_mcs_from_tbl(&search_tbl->current_rate,
1156 search_tbl, index, is_green);
1160 if (tbl->action > IWL_SISO_SWITCH_GI)
1161 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1163 if (tbl->action == start_action)
1170 if (tbl->action > IWL_SISO_SWITCH_GI)
1171 tbl->action = IWL_SISO_SWITCH_ANTENNA;
1175 static int rs_move_mimo_to_other(struct iwl_priv *priv,
1176 struct iwl_rate_scale_priv *lq_data,
1180 s8 is_green = lq_data->is_green;
1181 struct iwl_scale_tbl_info *tbl =
1182 &(lq_data->lq_info[lq_data->active_tbl]);
1183 struct iwl_scale_tbl_info *search_tbl =
1184 &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1185 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1186 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1187 u8 start_action = tbl->action;
1190 lq_data->action_counter++;
1191 switch (tbl->action) {
1192 case IWL_MIMO_SWITCH_ANTENNA_A:
1193 case IWL_MIMO_SWITCH_ANTENNA_B:
1194 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1195 memcpy(search_tbl, tbl, sz);
1196 search_tbl->lq_type = LQ_SISO;
1197 search_tbl->is_SGI = 0;
1198 search_tbl->is_fat = 0;
1199 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1200 search_tbl->antenna_type = ANT_MAIN;
1202 search_tbl->antenna_type = ANT_AUX;
1204 ret = rs_switch_to_siso(priv, lq_data, search_tbl,
1207 lq_data->search_better_tbl = 1;
1212 case IWL_MIMO_SWITCH_GI:
1213 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1214 memcpy(search_tbl, tbl, sz);
1215 search_tbl->lq_type = LQ_MIMO;
1216 search_tbl->antenna_type = ANT_BOTH;
1217 search_tbl->action = 0;
1218 if (search_tbl->is_SGI)
1219 search_tbl->is_SGI = 0;
1221 search_tbl->is_SGI = 1;
1222 lq_data->search_better_tbl = 1;
1223 if ((tbl->lq_type == LQ_MIMO) &&
1225 s32 tpt = lq_data->last_tpt / 100;
1226 if (((!tbl->is_fat) &&
1227 (tpt >= expected_tpt_mimo20MHz[index])) ||
1229 (tpt >= expected_tpt_mimo40MHz[index])))
1230 lq_data->search_better_tbl = 0;
1232 rs_get_expected_tpt_table(lq_data, search_tbl);
1233 rs_mcs_from_tbl(&search_tbl->current_rate,
1234 search_tbl, index, is_green);
1239 if (tbl->action > IWL_MIMO_SWITCH_GI)
1240 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1242 if (tbl->action == start_action)
1249 if (tbl->action > IWL_MIMO_SWITCH_GI)
1250 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
1255 static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data)
1257 struct iwl_scale_tbl_info *tbl;
1260 int flush_interval_passed = 0;
1262 active_tbl = lq_data->active_tbl;
1264 tbl = &(lq_data->lq_info[active_tbl]);
1266 if (lq_data->stay_in_tbl) {
1268 if (lq_data->flush_timer)
1269 flush_interval_passed =
1271 (unsigned long)(lq_data->flush_timer +
1272 IWL_RATE_SCALE_FLUSH_INTVL));
1274 flush_interval_passed = 0;
1275 if ((lq_data->total_failed > lq_data->max_failure_limit) ||
1276 (lq_data->total_success > lq_data->max_success_limit) ||
1277 ((!lq_data->search_better_tbl) && (lq_data->flush_timer)
1278 && (flush_interval_passed))) {
1279 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1280 lq_data->total_failed,
1281 lq_data->total_success,
1282 flush_interval_passed);
1283 lq_data->stay_in_tbl = 0;
1284 lq_data->total_failed = 0;
1285 lq_data->total_success = 0;
1286 lq_data->flush_timer = 0;
1287 } else if (lq_data->table_count > 0) {
1288 lq_data->table_count++;
1289 if (lq_data->table_count >=
1290 lq_data->table_count_limit) {
1291 lq_data->table_count = 0;
1293 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1294 for (i = 0; i < IWL_RATE_COUNT; i++)
1295 rs_rate_scale_clear_window(
1300 if (!lq_data->stay_in_tbl) {
1301 for (i = 0; i < IWL_RATE_COUNT; i++)
1302 rs_rate_scale_clear_window(&(tbl->win[i]));
1307 static void rs_rate_scale_perform(struct iwl_priv *priv,
1308 struct net_device *dev,
1309 struct ieee80211_hdr *hdr,
1310 struct sta_info *sta)
1312 int low = IWL_RATE_INVALID;
1313 int high = IWL_RATE_INVALID;
1316 struct iwl_rate_scale_data *window = NULL;
1317 int current_tpt = IWL_INVALID_VALUE;
1318 int low_tpt = IWL_INVALID_VALUE;
1319 int high_tpt = IWL_INVALID_VALUE;
1321 s8 scale_action = 0;
1324 struct iwl_rate_scale_priv *lq_data;
1325 struct iwl_scale_tbl_info *tbl, *tbl1;
1326 u16 rate_scale_index_msk = 0;
1327 struct iwl_rate mcs_rate;
1333 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1335 fc = le16_to_cpu(hdr->frame_control);
1336 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1337 /* Send management frames and broadcast/multicast data using
1339 /* TODO: this could probably be improved.. */
1343 if (!sta || !sta->rate_ctrl_priv)
1346 if (!priv->lq_mngr.lq_ready) {
1347 IWL_DEBUG_RATE("still rate scaling not ready\n");
1350 lq_data = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1352 if (!lq_data->search_better_tbl)
1353 active_tbl = lq_data->active_tbl;
1355 active_tbl = 1 - lq_data->active_tbl;
1357 tbl = &(lq_data->lq_info[active_tbl]);
1358 is_green = lq_data->is_green;
1360 index = sta->last_txrate;
1362 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1365 rs_get_supported_rates(lq_data, hdr, tbl->lq_type,
1368 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1370 /* mask with station rate restriction */
1371 if (is_legacy(tbl->lq_type)) {
1372 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1373 rate_scale_index_msk = (u16) (rate_mask &
1374 (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
1376 rate_scale_index_msk = (u16) (rate_mask &
1377 lq_data->supp_rates);
1380 rate_scale_index_msk = rate_mask;
1382 if (!rate_scale_index_msk)
1383 rate_scale_index_msk = rate_mask;
1385 if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
1386 index = IWL_INVALID_VALUE;
1389 /* get the lowest available rate */
1390 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1391 if ((1 << i) & rate_scale_index_msk)
1395 if (index == IWL_INVALID_VALUE) {
1396 IWL_WARNING("Can not find a suitable rate\n");
1401 if (!tbl->expected_tpt)
1402 rs_get_expected_tpt_table(lq_data, tbl);
1404 window = &(tbl->win[index]);
1406 fail_count = window->counter - window->success_counter;
1407 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1408 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
1409 || (tbl->expected_tpt == NULL)) {
1410 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1412 window->success_counter, window->counter, index);
1413 window->average_tpt = IWL_INVALID_VALUE;
1414 rs_stay_in_table(lq_data);
1416 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1417 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1418 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1423 window->average_tpt = ((window->success_ratio *
1424 tbl->expected_tpt[index] + 64) / 128);
1426 if (lq_data->search_better_tbl) {
1427 int success_limit = IWL_RATE_SCALE_SWITCH;
1429 if ((window->success_ratio > success_limit) ||
1430 (window->average_tpt > lq_data->last_tpt)) {
1431 if (!is_legacy(tbl->lq_type)) {
1432 IWL_DEBUG_HT("LQ: we are switching to HT"
1433 " rate suc %d current tpt %d"
1435 window->success_ratio,
1436 window->average_tpt,
1438 lq_data->enable_counter = 1;
1440 lq_data->active_tbl = active_tbl;
1441 current_tpt = window->average_tpt;
1443 tbl->lq_type = LQ_NONE;
1444 active_tbl = lq_data->active_tbl;
1445 tbl = &(lq_data->lq_info[active_tbl]);
1447 index = iwl_rate_index_from_plcp(
1448 tbl->current_rate.rate_n_flags);
1451 current_tpt = lq_data->last_tpt;
1452 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1454 lq_data->search_better_tbl = 0;
1459 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
1461 low = high_low & 0xff;
1462 high = (high_low >> 8) & 0xff;
1464 current_tpt = window->average_tpt;
1466 if (low != IWL_RATE_INVALID)
1467 low_tpt = tbl->win[low].average_tpt;
1469 if (high != IWL_RATE_INVALID)
1470 high_tpt = tbl->win[high].average_tpt;
1475 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
1476 (current_tpt == 0)) {
1477 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1479 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1480 (high_tpt == IWL_INVALID_VALUE))
1482 else if ((low_tpt != IWL_INVALID_VALUE) &&
1483 (high_tpt != IWL_INVALID_VALUE) &&
1484 (low_tpt < current_tpt) &&
1485 (high_tpt < current_tpt))
1488 if (high_tpt != IWL_INVALID_VALUE) {
1489 if (high_tpt > current_tpt)
1493 ("decrease rate because of high tpt\n");
1496 } else if (low_tpt != IWL_INVALID_VALUE) {
1497 if (low_tpt > current_tpt) {
1499 ("decrease rate because of low tpt\n");
1506 if (scale_action == -1) {
1507 if ((low != IWL_RATE_INVALID) &&
1508 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1509 (current_tpt > (100 * tbl->expected_tpt[low]))))
1511 } else if ((scale_action == 1) &&
1512 (window->success_ratio < IWL_RATE_INCREASE_TH))
1515 switch (scale_action) {
1517 if (low != IWL_RATE_INVALID) {
1523 if (high != IWL_RATE_INVALID) {
1534 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1535 "high %d type %d\n",
1536 index, scale_action, low, high, tbl->lq_type);
1540 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1541 rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
1542 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1544 rs_stay_in_table(lq_data);
1546 if (!update_lq && !done_search && !lq_data->stay_in_tbl) {
1547 lq_data->last_tpt = current_tpt;
1549 if (is_legacy(tbl->lq_type))
1550 rs_move_legacy_other(priv, lq_data, index);
1551 else if (is_siso(tbl->lq_type))
1552 rs_move_siso_to_other(priv, lq_data, index);
1554 rs_move_mimo_to_other(priv, lq_data, index);
1556 if (lq_data->search_better_tbl) {
1557 tbl = &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
1558 for (i = 0; i < IWL_RATE_COUNT; i++)
1559 rs_rate_scale_clear_window(&(tbl->win[i]));
1561 index = iwl_rate_index_from_plcp(
1562 tbl->current_rate.rate_n_flags);
1564 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1565 tbl->current_rate.rate_n_flags, index);
1566 rs_fill_link_cmd(lq_data, &tbl->current_rate,
1568 rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
1570 tbl1 = &(lq_data->lq_info[lq_data->active_tbl]);
1572 if (is_legacy(tbl1->lq_type) &&
1573 #ifdef CONFIG_IWLWIFI_HT
1574 !priv->current_assoc_ht.is_ht &&
1576 (lq_data->action_counter >= 1)) {
1577 lq_data->action_counter = 0;
1578 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1579 rs_set_stay_in_table(1, lq_data);
1582 if (lq_data->enable_counter &&
1583 (lq_data->action_counter >= IWL_ACTION_LIMIT)) {
1584 #ifdef CONFIG_IWLWIFI_HT_AGG
1585 if ((lq_data->last_tpt > TID_AGG_TPT_THREHOLD) &&
1586 (priv->lq_mngr.agg_ctrl.auto_agg)) {
1587 priv->lq_mngr.agg_ctrl.tid_retry =
1589 schedule_work(&priv->agg_work);
1591 #endif /*CONFIG_IWLWIFI_HT_AGG */
1592 lq_data->action_counter = 0;
1593 rs_set_stay_in_table(0, lq_data);
1596 if ((!update_lq) && (!done_search) && (!lq_data->flush_timer))
1597 lq_data->flush_timer = jiffies;
1601 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
1603 sta->last_txrate = i;
1605 /* sta->txrate is an index to A mode rates which start
1606 * at IWL_FIRST_OFDM_RATE
1608 if (lq_data->phymode == (u8) MODE_IEEE80211A)
1609 sta->txrate = i - IWL_FIRST_OFDM_RATE;
1617 static void rs_initialize_lq(struct iwl_priv *priv,
1618 struct sta_info *sta)
1621 struct iwl_rate_scale_priv *lq;
1622 struct iwl_scale_tbl_info *tbl;
1625 u8 use_green = rs_use_green(priv);
1626 struct iwl_rate mcs_rate;
1628 if (!sta || !sta->rate_ctrl_priv)
1631 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1632 i = sta->last_txrate;
1634 if ((lq->lq.sta_id == 0xff) &&
1635 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
1638 if (!lq->search_better_tbl)
1639 active_tbl = lq->active_tbl;
1641 active_tbl = 1 - lq->active_tbl;
1643 tbl = &(lq->lq_info[active_tbl]);
1645 if ((i < 0) || (i >= IWL_RATE_COUNT))
1648 mcs_rate.rate_n_flags = iwl_rates[i].plcp ;
1649 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
1650 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
1652 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
1653 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
1655 tbl->antenna_type = ANT_AUX;
1656 rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx);
1657 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
1658 rs_toggle_antenna(&mcs_rate, tbl);
1660 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
1661 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
1662 rs_get_expected_tpt_table(lq, tbl);
1663 rs_fill_link_cmd(lq, &mcs_rate, &lq->lq);
1664 rs_send_lq_cmd(priv, &lq->lq, CMD_ASYNC);
1669 static void rs_get_rate(void *priv_rate, struct net_device *dev,
1670 struct ieee80211_hw_mode *mode, struct sk_buff *skb,
1671 struct rate_selection *sel)
1675 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1676 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1677 struct sta_info *sta;
1678 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1679 struct iwl_rate_scale_priv *lq;
1681 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1683 sta = sta_info_get(local, hdr->addr1);
1685 if (!sta || !sta->rate_ctrl_priv) {
1686 sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
1692 lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
1693 i = sta->last_txrate;
1695 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) {
1696 u8 sta_id = iwl_hw_find_station(priv, hdr->addr1);
1697 DECLARE_MAC_BUF(mac);
1699 if (sta_id == IWL_INVALID_STATION) {
1700 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1701 print_mac(mac, hdr->addr1));
1702 sta_id = iwl_add_station(priv,
1703 hdr->addr1, 0, CMD_ASYNC);
1705 if ((sta_id != IWL_INVALID_STATION)) {
1706 lq->lq.sta_id = sta_id;
1707 lq->lq.rs_table[0].rate_n_flags = 0;
1708 lq->ibss_sta_added = 1;
1709 rs_initialize_lq(priv, sta);
1711 if (!lq->ibss_sta_added)
1716 if ((i < 0) || (i > IWL_RATE_COUNT)) {
1717 sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
1722 sel->rate = &priv->ieee_rates[i];
1725 static void *rs_alloc_sta(void *priv, gfp_t gfp)
1727 struct iwl_rate_scale_priv *crl;
1730 IWL_DEBUG_RATE("create station rate scale window\n");
1732 crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp);
1736 crl->lq.sta_id = 0xff;
1739 for (j = 0; j < LQ_SIZE; j++)
1740 for (i = 0; i < IWL_RATE_COUNT; i++)
1741 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1746 static void rs_rate_init(void *priv_rate, void *priv_sta,
1747 struct ieee80211_local *local,
1748 struct sta_info *sta)
1751 struct ieee80211_hw_mode *mode = local->oper_hw_mode;
1752 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
1753 struct iwl_rate_scale_priv *crl = priv_sta;
1755 crl->flush_timer = 0;
1756 crl->supp_rates = sta->supp_rates;
1758 for (j = 0; j < LQ_SIZE; j++)
1759 for (i = 0; i < IWL_RATE_COUNT; i++)
1760 rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
1762 IWL_DEBUG_RATE("rate scale global init\n");
1763 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1764 * the lowest or the highest rate.. Could consider using RSSI from
1765 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1768 crl->ibss_sta_added = 0;
1769 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1770 u8 sta_id = iwl_hw_find_station(priv, sta->addr);
1771 DECLARE_MAC_BUF(mac);
1773 /* for IBSS the call are from tasklet */
1774 IWL_DEBUG_HT("LQ: ADD station %s\n",
1775 print_mac(mac, sta->addr));
1777 if (sta_id == IWL_INVALID_STATION) {
1778 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1779 print_mac(mac, sta->addr));
1780 sta_id = iwl_add_station(priv,
1781 sta->addr, 0, CMD_ASYNC);
1783 if ((sta_id != IWL_INVALID_STATION)) {
1784 crl->lq.sta_id = sta_id;
1785 crl->lq.rs_table[0].rate_n_flags = 0;
1787 /* FIXME: this is w/a remove it later */
1788 priv->assoc_station_added = 1;
1791 for (i = 0; i < mode->num_rates; i++) {
1792 if ((sta->supp_rates & BIT(i)) &&
1793 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))
1796 sta->last_txrate = sta->txrate;
1797 /* For MODE_IEEE80211A mode cck rate are at end
1800 if (local->hw.conf.phymode == MODE_IEEE80211A)
1801 sta->last_txrate += IWL_FIRST_OFDM_RATE;
1803 crl->is_dup = priv->is_dup;
1804 crl->valid_antenna = priv->valid_antenna;
1805 crl->antenna = priv->antenna;
1806 crl->is_green = rs_use_green(priv);
1807 crl->active_rate = priv->active_rate;
1808 crl->active_rate &= ~(0x1000);
1809 crl->active_rate_basic = priv->active_rate_basic;
1810 crl->phymode = priv->phymode;
1811 #ifdef CONFIG_IWLWIFI_HT
1812 crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1);
1813 crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1);
1814 crl->active_siso_rate &= ~((u16)0x2);
1815 crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE;
1817 crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1);
1818 crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1);
1819 crl->active_mimo_rate &= ~((u16)0x2);
1820 crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE;
1821 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate,
1822 crl->active_mimo_rate);
1823 #endif /*CONFIG_IWLWIFI_HT*/
1824 #ifdef CONFIG_MAC80211_DEBUGFS
1828 if (priv->assoc_station_added)
1829 priv->lq_mngr.lq_ready = 1;
1831 rs_initialize_lq(priv, sta);
1834 static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
1835 struct iwl_rate *tx_mcs,
1836 struct iwl_link_quality_cmd *lq_cmd)
1840 int repeat_rate = 0;
1841 u8 ant_toggle_count = 0;
1842 u8 use_ht_possible = 1;
1843 struct iwl_rate new_rate;
1844 struct iwl_scale_tbl_info tbl_type = { 0 };
1846 rs_dbgfs_set_mcs(lq_data, tx_mcs, index);
1848 rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode,
1849 &tbl_type, &rate_idx);
1851 if (is_legacy(tbl_type.lq_type)) {
1852 ant_toggle_count = 1;
1853 repeat_rate = IWL_NUMBER_TRY;
1855 repeat_rate = IWL_HT_NUMBER_TRY;
1857 lq_cmd->general_params.mimo_delimiter =
1858 is_mimo(tbl_type.lq_type) ? 1 : 0;
1859 lq_cmd->rs_table[index].rate_n_flags =
1860 cpu_to_le32(tx_mcs->rate_n_flags);
1861 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
1863 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))
1864 lq_cmd->general_params.single_stream_ant_msk = 1;
1866 lq_cmd->general_params.single_stream_ant_msk = 2;
1871 while (index < LINK_QUAL_MAX_RETRY_NUM) {
1872 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
1873 if (is_legacy(tbl_type.lq_type)) {
1874 if (ant_toggle_count <
1875 NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1878 rs_toggle_antenna(&new_rate, &tbl_type);
1879 ant_toggle_count = 1;
1883 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1884 lq_cmd->rs_table[index].rate_n_flags =
1885 cpu_to_le32(new_rate.rate_n_flags);
1890 rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type,
1893 if (is_mimo(tbl_type.lq_type))
1894 lq_cmd->general_params.mimo_delimiter = index;
1896 rs_get_lower_rate(lq_data, &tbl_type, rate_idx,
1897 use_ht_possible, &new_rate);
1899 if (is_legacy(tbl_type.lq_type)) {
1900 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
1903 rs_toggle_antenna(&new_rate, &tbl_type);
1904 ant_toggle_count = 1;
1906 repeat_rate = IWL_NUMBER_TRY;
1908 repeat_rate = IWL_HT_NUMBER_TRY;
1910 use_ht_possible = 0;
1912 rs_dbgfs_set_mcs(lq_data, &new_rate, index);
1913 lq_cmd->rs_table[index].rate_n_flags =
1914 cpu_to_le32(new_rate.rate_n_flags);
1920 lq_cmd->general_params.dual_stream_ant_msk = 3;
1921 lq_cmd->agg_params.agg_dis_start_th = 3;
1922 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
1925 static void *rs_alloc(struct ieee80211_local *local)
1927 return local->hw.priv;
1929 /* rate scale requires free function to be implemented */
1930 static void rs_free(void *priv_rate)
1935 static void rs_clear(void *priv_rate)
1937 struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
1939 IWL_DEBUG_RATE("enter\n");
1941 priv->lq_mngr.lq_ready = 0;
1942 #ifdef CONFIG_IWLWIFI_HT
1943 #ifdef CONFIG_IWLWIFI_HT_AGG
1944 if (priv->lq_mngr.agg_ctrl.granted_ba)
1945 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);
1946 #endif /*CONFIG_IWLWIFI_HT_AGG */
1947 #endif /* CONFIG_IWLWIFI_HT */
1949 IWL_DEBUG_RATE("leave\n");
1952 static void rs_free_sta(void *priv, void *priv_sta)
1954 struct iwl_rate_scale_priv *rs_priv = priv_sta;
1956 IWL_DEBUG_RATE("enter\n");
1958 IWL_DEBUG_RATE("leave\n");
1962 #ifdef CONFIG_MAC80211_DEBUGFS
1963 static int open_file_generic(struct inode *inode, struct file *file)
1965 file->private_data = inode->i_private;
1968 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
1969 struct iwl_rate *mcs, int index)
1973 if (rs_priv->phymode == (u8) MODE_IEEE80211A)
1978 if (rs_priv->dbg_fixed.rate_n_flags) {
1980 mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags;
1982 mcs->rate_n_flags = base_rate;
1983 IWL_DEBUG_RATE("Fixed rate ON\n");
1987 IWL_DEBUG_RATE("Fixed rate OFF\n");
1990 static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
1991 const char __user *user_buf, size_t count, loff_t *ppos)
1993 struct iwl_rate_scale_priv *rs_priv = file->private_data;
1998 memset(buf, 0, sizeof(buf));
1999 buf_size = min(count, sizeof(buf) - 1);
2000 if (copy_from_user(buf, user_buf, buf_size))
2003 if (sscanf(buf, "%x", &parsed_rate) == 1)
2004 rs_priv->dbg_fixed.rate_n_flags = parsed_rate;
2006 rs_priv->dbg_fixed.rate_n_flags = 0;
2008 rs_priv->active_rate = 0x0FFF;
2009 rs_priv->active_siso_rate = 0x1FD0;
2010 rs_priv->active_mimo_rate = 0x1FD0;
2012 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2013 rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags);
2015 if (rs_priv->dbg_fixed.rate_n_flags) {
2016 rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq);
2017 rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC);
2023 static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2024 char __user *user_buf, size_t count, loff_t *ppos)
2030 struct iwl_rate_scale_priv *rs_priv = file->private_data;
2032 desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id);
2033 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2034 rs_priv->total_failed, rs_priv->total_success,
2035 rs_priv->active_rate);
2036 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2037 rs_priv->dbg_fixed.rate_n_flags);
2038 desc += sprintf(buff+desc, "general:"
2039 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2040 rs_priv->lq.general_params.flags,
2041 rs_priv->lq.general_params.mimo_delimiter,
2042 rs_priv->lq.general_params.single_stream_ant_msk,
2043 rs_priv->lq.general_params.dual_stream_ant_msk);
2045 desc += sprintf(buff+desc, "agg:"
2046 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2047 le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit),
2048 rs_priv->lq.agg_params.agg_dis_start_th,
2049 rs_priv->lq.agg_params.agg_frame_cnt_limit);
2051 desc += sprintf(buff+desc,
2052 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2053 rs_priv->lq.general_params.start_rate_index[0],
2054 rs_priv->lq.general_params.start_rate_index[1],
2055 rs_priv->lq.general_params.start_rate_index[2],
2056 rs_priv->lq.general_params.start_rate_index[3]);
2059 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
2060 desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
2061 i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags));
2063 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2066 static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2067 .write = rs_sta_dbgfs_scale_table_write,
2068 .read = rs_sta_dbgfs_scale_table_read,
2069 .open = open_file_generic,
2071 static ssize_t rs_sta_dbgfs_stats_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;
2079 for (i = 0; i < LQ_SIZE; i++) {
2080 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2082 rs_priv->active_tbl == i?"*":"x",
2083 rs_priv->lq_info[i].lq_type,
2084 rs_priv->lq_info[i].is_SGI,
2085 rs_priv->lq_info[i].is_fat,
2086 rs_priv->lq_info[i].is_dup,
2087 rs_priv->lq_info[i].current_rate.rate_n_flags);
2088 for (j = 0; j < IWL_RATE_COUNT; j++) {
2089 desc += sprintf(buff+desc,
2090 "counter=%d success=%d %%=%d\n",
2091 rs_priv->lq_info[i].win[j].counter,
2092 rs_priv->lq_info[i].win[j].success_counter,
2093 rs_priv->lq_info[i].win[j].success_ratio);
2096 return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2099 static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2100 .read = rs_sta_dbgfs_stats_table_read,
2101 .open = open_file_generic,
2104 static void rs_add_debugfs(void *priv, void *priv_sta,
2107 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2108 rs_priv->rs_sta_dbgfs_scale_table_file =
2109 debugfs_create_file("rate_scale_table", 0600, dir,
2110 rs_priv, &rs_sta_dbgfs_scale_table_ops);
2111 rs_priv->rs_sta_dbgfs_stats_table_file =
2112 debugfs_create_file("rate_stats_table", 0600, dir,
2113 rs_priv, &rs_sta_dbgfs_stats_table_ops);
2116 static void rs_remove_debugfs(void *priv, void *priv_sta)
2118 struct iwl_rate_scale_priv *rs_priv = priv_sta;
2119 debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file);
2120 debugfs_remove(rs_priv->rs_sta_dbgfs_stats_table_file);
2124 static struct rate_control_ops rs_ops = {
2127 .tx_status = rs_tx_status,
2128 .get_rate = rs_get_rate,
2129 .rate_init = rs_rate_init,
2133 .alloc_sta = rs_alloc_sta,
2134 .free_sta = rs_free_sta,
2135 #ifdef CONFIG_MAC80211_DEBUGFS
2136 .add_sta_debugfs = rs_add_debugfs,
2137 .remove_sta_debugfs = rs_remove_debugfs,
2141 int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2143 struct ieee80211_local *local = hw_to_local(hw);
2144 struct iwl_priv *priv = hw->priv;
2145 struct iwl_rate_scale_priv *rs_priv;
2146 struct sta_info *sta;
2148 u32 samples = 0, success = 0, good = 0;
2149 unsigned long now = jiffies;
2151 u8 lq_type, antenna;
2153 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2154 if (!sta || !sta->rate_ctrl_priv) {
2157 IWL_DEBUG_RATE("leave - no private rate data!\n");
2159 IWL_DEBUG_RATE("leave - no station!\n");
2160 return sprintf(buf, "station %d not found\n", sta_id);
2163 rs_priv = (void *)sta->rate_ctrl_priv;
2165 lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type;
2166 antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type;
2168 if (is_legacy(lq_type))
2169 i = IWL_RATE_54M_INDEX;
2171 i = IWL_RATE_60M_INDEX;
2175 int active = rs_priv->active_tbl;
2178 sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2);
2180 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2181 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
2183 (rs_priv->lq_info[active].win[i].data & mask)
2186 samples += rs_priv->lq_info[active].win[i].counter;
2187 good += rs_priv->lq_info[active].win[i].success_counter;
2188 success += rs_priv->lq_info[active].win[i].success_counter *
2191 if (rs_priv->lq_info[active].win[i].stamp) {
2193 jiffies_to_msecs(now -
2194 rs_priv->lq_info[active].win[i].stamp);
2196 if (delta > max_time)
2199 count += sprintf(&buf[count], "%5dms\n", delta);
2201 buf[count++] = '\n';
2203 j = iwl_get_prev_ieee_rate(i);
2209 /* Display the average rate of all samples taken.
2211 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2212 * added from iwl_rates is actually 2X the rate */
2214 count += sprintf(&buf[count],
2215 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2216 "%3d%% success (%d good packets over %d tries)\n",
2217 success / (2 * samples), (success * 5 / samples) % 10,
2218 max_time, good * 100 / samples, good, samples);
2220 count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
2221 count += sprintf(&buf[count], "\nrate scale type %d antenna %d "
2222 "active_search %d rate index %d\n", lq_type, antenna,
2223 rs_priv->search_better_tbl, sta->last_txrate);
2229 void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
2231 struct iwl_priv *priv = hw->priv;
2233 priv->lq_mngr.lq_ready = 1;
2236 void iwl_rate_control_register(struct ieee80211_hw *hw)
2238 ieee80211_rate_control_register(&rs_ops);
2241 void iwl_rate_control_unregister(struct ieee80211_hw *hw)
2243 ieee80211_rate_control_unregister(&rs_ops);