1 /******************************************************************************
3 * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/skbuff.h>
29 #include <linux/wireless.h>
30 #include <net/mac80211.h>
31 #include <net/ieee80211.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/delay.h>
37 #include <linux/workqueue.h>
39 #include <net/mac80211.h>
40 #include <linux/wireless.h>
44 #include "../net/mac80211/ieee80211_rate.h"
47 #include "iwl-helpers.h"
49 #define RS_NAME "iwl-4965-rs"
51 #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
52 #define IWL_NUMBER_TRY 1
53 #define IWL_HT_NUMBER_TRY 3
55 #define IWL_RATE_MAX_WINDOW 62
56 #define IWL_RATE_HIGH_TH 10880
57 #define IWL_RATE_MIN_FAILURE_TH 6
58 #define IWL_RATE_MIN_SUCCESS_TH 8
59 #define IWL_RATE_DECREASE_TH 1920
60 #define IWL_RATE_INCREASE_TH 8960
61 #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */
63 static u8 rs_ht_to_legacy
[] = {
64 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
65 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
67 IWL_RATE_6M_INDEX
, IWL_RATE_9M_INDEX
,
68 IWL_RATE_12M_INDEX
, IWL_RATE_18M_INDEX
,
69 IWL_RATE_24M_INDEX
, IWL_RATE_36M_INDEX
,
70 IWL_RATE_48M_INDEX
, IWL_RATE_54M_INDEX
75 } __attribute__ ((packed
));
77 struct iwl_rate_scale_data
{
86 struct iwl_scale_tbl_info
{
87 enum iwl_table_type lq_type
;
88 enum iwl_antenna_type antenna_type
;
94 struct iwl_rate current_rate
;
95 struct iwl_rate_scale_data win
[IWL_RATE_COUNT
];
98 struct iwl_rate_scale_priv
{
102 u8 search_better_tbl
;
104 u32 table_count_limit
;
105 u32 max_failure_limit
;
106 u32 max_success_limit
;
120 u16 active_siso_rate
;
121 u16 active_mimo_rate
;
122 u16 active_rate_basic
;
123 struct iwl_link_quality_cmd lq
;
124 struct iwl_scale_tbl_info lq_info
[LQ_SIZE
];
125 #ifdef CONFIG_MAC80211_DEBUGFS
126 struct dentry
*rs_sta_dbgfs_scale_table_file
;
127 struct dentry
*rs_sta_dbgfs_stats_table_file
;
128 struct iwl_rate dbg_fixed
;
129 struct iwl_priv
*drv
;
133 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
134 struct net_device
*dev
,
135 struct ieee80211_hdr
*hdr
,
136 struct sta_info
*sta
);
137 static void rs_fill_link_cmd(struct iwl_rate_scale_priv
*lq_data
,
138 struct iwl_rate
*tx_mcs
,
139 struct iwl_link_quality_cmd
*tbl
);
142 #ifdef CONFIG_MAC80211_DEBUGFS
143 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
144 struct iwl_rate
*mcs
, int index
);
146 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
147 struct iwl_rate
*mcs
, int index
)
150 static s32 expected_tpt_A
[IWL_RATE_COUNT
] = {
151 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
154 static s32 expected_tpt_G
[IWL_RATE_COUNT
] = {
155 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
158 static s32 expected_tpt_siso20MHz
[IWL_RATE_COUNT
] = {
159 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
162 static s32 expected_tpt_siso20MHzSGI
[IWL_RATE_COUNT
] = {
163 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
166 static s32 expected_tpt_mimo20MHz
[IWL_RATE_COUNT
] = {
167 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
170 static s32 expected_tpt_mimo20MHzSGI
[IWL_RATE_COUNT
] = {
171 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
174 static s32 expected_tpt_siso40MHz
[IWL_RATE_COUNT
] = {
175 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
178 static s32 expected_tpt_siso40MHzSGI
[IWL_RATE_COUNT
] = {
179 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
182 static s32 expected_tpt_mimo40MHz
[IWL_RATE_COUNT
] = {
183 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
186 static s32 expected_tpt_mimo40MHzSGI
[IWL_RATE_COUNT
] = {
187 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
190 static int iwl_lq_sync_callback(struct iwl_priv
*priv
,
191 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
193 /*We didn't cache the SKB; let the caller free it */
197 static inline u8
iwl_rate_get_rate(u32 rate_n_flags
)
199 return (u8
)(rate_n_flags
& 0xFF);
202 static int rs_send_lq_cmd(struct iwl_priv
*priv
,
203 struct iwl_link_quality_cmd
*lq
, u8 flags
)
205 #ifdef CONFIG_IWLWIFI_DEBUG
210 struct iwl_host_cmd cmd
= {
211 .id
= REPLY_TX_LINK_QUALITY_CMD
,
212 .len
= sizeof(struct iwl_link_quality_cmd
),
217 if ((lq
->sta_id
== 0xFF) &&
218 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
221 if (lq
->sta_id
== 0xFF)
222 lq
->sta_id
= IWL_AP_ID
;
224 IWL_DEBUG_RATE("lq station id 0x%x\n", lq
->sta_id
);
225 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
226 lq
->general_params
.single_stream_ant_msk
,
227 lq
->general_params
.dual_stream_ant_msk
);
228 #ifdef CONFIG_IWLWIFI_DEBUG
229 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
230 IWL_DEBUG_RATE("lq index %d 0x%X\n",
231 i
, lq
->rs_table
[i
].rate_n_flags
);
234 if (flags
& CMD_ASYNC
)
235 cmd
.meta
.u
.callback
= iwl_lq_sync_callback
;
237 if (iwl_is_associated(priv
) && priv
->assoc_station_added
&&
238 priv
->lq_mngr
.lq_ready
)
239 rc
= iwl_send_cmd(priv
, &cmd
);
244 static int rs_rate_scale_clear_window(struct iwl_rate_scale_data
*window
)
247 window
->success_counter
= 0;
248 window
->success_ratio
= IWL_INVALID_VALUE
;
250 window
->average_tpt
= IWL_INVALID_VALUE
;
256 static int rs_collect_tx_data(struct iwl_rate_scale_data
*windows
,
257 int scale_index
, s32 tpt
, u32 status
)
260 struct iwl_rate_scale_data
*window
= NULL
;
262 u8 win_size
= IWL_RATE_MAX_WINDOW
;
268 if (scale_index
>= IWL_RATE_COUNT
)
271 window
= &(windows
[scale_index
]);
273 if (window
->counter
>= win_size
) {
275 window
->counter
= win_size
- 1;
277 mask
= (mask
<< (win_size
- 1));
278 if ((window
->data
& mask
)) {
279 window
->data
&= ~mask
;
280 window
->success_counter
= window
->success_counter
- 1;
284 window
->counter
= window
->counter
+ 1;
286 window
->data
= (mask
<< 1);
288 window
->success_counter
= window
->success_counter
+ 1;
292 if (window
->counter
> 0)
293 window
->success_ratio
= 128 * (100 * window
->success_counter
)
296 window
->success_ratio
= IWL_INVALID_VALUE
;
298 fail_count
= window
->counter
- window
->success_counter
;
300 if ((fail_count
>= IWL_RATE_MIN_FAILURE_TH
) ||
301 (window
->success_counter
>= IWL_RATE_MIN_SUCCESS_TH
))
302 window
->average_tpt
= (window
->success_ratio
* tpt
+ 64) / 128;
304 window
->average_tpt
= IWL_INVALID_VALUE
;
306 window
->stamp
= jiffies
;
311 int static rs_mcs_from_tbl(struct iwl_rate
*mcs_rate
,
312 struct iwl_scale_tbl_info
*tbl
,
313 int index
, u8 use_green
)
317 if (is_legacy(tbl
->lq_type
)) {
318 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp
;
319 if (index
>= IWL_FIRST_CCK_RATE
&& index
<= IWL_LAST_CCK_RATE
)
320 mcs_rate
->rate_n_flags
|= RATE_MCS_CCK_MSK
;
322 } else if (is_siso(tbl
->lq_type
)) {
323 if (index
> IWL_LAST_OFDM_RATE
)
324 index
= IWL_LAST_OFDM_RATE
;
325 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp_siso
|
328 if (index
> IWL_LAST_OFDM_RATE
)
329 index
= IWL_LAST_OFDM_RATE
;
330 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp_mimo
|
334 switch (tbl
->antenna_type
) {
336 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_AB_MSK
;
339 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_A_MSK
;
342 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
348 if (is_legacy(tbl
->lq_type
))
353 mcs_rate
->rate_n_flags
|= RATE_MCS_DUP_MSK
;
355 mcs_rate
->rate_n_flags
|= RATE_MCS_FAT_MSK
;
358 mcs_rate
->rate_n_flags
|= RATE_MCS_SGI_MSK
;
361 mcs_rate
->rate_n_flags
|= RATE_MCS_GF_MSK
;
362 if (is_siso(tbl
->lq_type
))
363 mcs_rate
->rate_n_flags
&= ~RATE_MCS_SGI_MSK
;
368 static int rs_get_tbl_info_from_mcs(const struct iwl_rate
*mcs_rate
,
369 int phymode
, struct iwl_scale_tbl_info
*tbl
,
375 index
= iwl_rate_index_from_plcp(mcs_rate
->rate_n_flags
);
377 if (index
== IWL_RATE_INVALID
) {
384 tbl
->antenna_type
= ANT_BOTH
;
386 if (!(mcs_rate
->rate_n_flags
& RATE_MCS_HT_MSK
)) {
387 ant_msk
= (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_AB_MSK
);
389 if (ant_msk
== RATE_MCS_ANT_AB_MSK
)
390 tbl
->lq_type
= LQ_NONE
;
393 if (phymode
== MODE_IEEE80211A
)
398 if (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_A_MSK
)
399 tbl
->antenna_type
= ANT_MAIN
;
401 tbl
->antenna_type
= ANT_AUX
;
405 } else if (iwl_rate_get_rate(mcs_rate
->rate_n_flags
)
406 <= IWL_RATE_SISO_60M_PLCP
) {
407 tbl
->lq_type
= LQ_SISO
;
409 ant_msk
= (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_AB_MSK
);
410 if (ant_msk
== RATE_MCS_ANT_AB_MSK
)
411 tbl
->lq_type
= LQ_NONE
;
413 if (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_A_MSK
)
414 tbl
->antenna_type
= ANT_MAIN
;
416 tbl
->antenna_type
= ANT_AUX
;
418 if (mcs_rate
->rate_n_flags
& RATE_MCS_SGI_MSK
)
421 if ((mcs_rate
->rate_n_flags
& RATE_MCS_FAT_MSK
) ||
422 (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
))
425 if (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
)
430 tbl
->lq_type
= LQ_MIMO
;
431 if (mcs_rate
->rate_n_flags
& RATE_MCS_SGI_MSK
)
434 if ((mcs_rate
->rate_n_flags
& RATE_MCS_FAT_MSK
) ||
435 (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
))
438 if (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
)
445 static inline void rs_toggle_antenna(struct iwl_rate
*new_rate
,
446 struct iwl_scale_tbl_info
*tbl
)
448 if (tbl
->antenna_type
== ANT_AUX
) {
449 tbl
->antenna_type
= ANT_MAIN
;
450 new_rate
->rate_n_flags
&= ~RATE_MCS_ANT_B_MSK
;
451 new_rate
->rate_n_flags
|= RATE_MCS_ANT_A_MSK
;
453 tbl
->antenna_type
= ANT_AUX
;
454 new_rate
->rate_n_flags
&= ~RATE_MCS_ANT_A_MSK
;
455 new_rate
->rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
459 static inline s8
rs_use_green(struct iwl_priv
*priv
)
462 #ifdef CONFIG_IWLWIFI_HT
463 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
466 if ((priv
->current_assoc_ht
.is_green_field
) &&
467 !(priv
->current_assoc_ht
.operating_mode
& 0x4))
469 #endif /*CONFIG_IWLWIFI_HT */
474 * rs_get_supported_rates - get the available rates
476 * if management frame or broadcast frame only return
477 * basic available rates.
480 static void rs_get_supported_rates(struct iwl_rate_scale_priv
*lq_data
,
481 struct ieee80211_hdr
*hdr
,
482 enum iwl_table_type rate_type
,
485 if (is_legacy(rate_type
))
486 *data_rate
= lq_data
->active_rate
;
488 if (is_siso(rate_type
))
489 *data_rate
= lq_data
->active_siso_rate
;
491 *data_rate
= lq_data
->active_mimo_rate
;
494 if (hdr
&& is_multicast_ether_addr(hdr
->addr1
) &&
495 lq_data
->active_rate_basic
)
496 *data_rate
= lq_data
->active_rate_basic
;
499 static u16
rs_get_adjacent_rate(u8 index
, u16 rate_mask
, int rate_type
)
501 u8 high
= IWL_RATE_INVALID
;
502 u8 low
= IWL_RATE_INVALID
;
504 /* 802.11A or ht walks to the next literal adjascent rate in
506 if (is_a_band(rate_type
) || !is_legacy(rate_type
)) {
510 /* Find the previous rate that is in the rate mask */
512 for (mask
= (1 << i
); i
>= 0; i
--, mask
>>= 1) {
513 if (rate_mask
& mask
) {
519 /* Find the next rate that is in the rate mask */
521 for (mask
= (1 << i
); i
< IWL_RATE_COUNT
; i
++, mask
<<= 1) {
522 if (rate_mask
& mask
) {
528 return (high
<< 8) | low
;
532 while (low
!= IWL_RATE_INVALID
) {
533 low
= iwl_rates
[low
].prev_rs
;
534 if (low
== IWL_RATE_INVALID
)
536 if (rate_mask
& (1 << low
))
538 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low
);
542 while (high
!= IWL_RATE_INVALID
) {
543 high
= iwl_rates
[high
].next_rs
;
544 if (high
== IWL_RATE_INVALID
)
546 if (rate_mask
& (1 << high
))
548 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high
);
551 return (high
<< 8) | low
;
554 static int rs_get_lower_rate(struct iwl_rate_scale_priv
*lq_data
,
555 struct iwl_scale_tbl_info
*tbl
, u8 scale_index
,
556 u8 ht_possible
, struct iwl_rate
*mcs_rate
)
561 u8 switch_to_legacy
= 0;
562 u8 is_green
= lq_data
->is_green
;
564 /* check if we need to switch from HT to legacy rates.
565 * assumption is that mandatory rates (1Mbps or 6Mbps)
566 * are always supported (spec demand) */
567 if (!is_legacy(tbl
->lq_type
) && (!ht_possible
|| !scale_index
)) {
568 switch_to_legacy
= 1;
569 scale_index
= rs_ht_to_legacy
[scale_index
];
570 if (lq_data
->phymode
== MODE_IEEE80211A
)
575 if ((tbl
->antenna_type
== ANT_BOTH
) ||
576 (tbl
->antenna_type
== ANT_NONE
))
577 tbl
->antenna_type
= ANT_MAIN
;
583 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
, &rate_mask
);
585 /* mask with station rate restriction */
586 if (is_legacy(tbl
->lq_type
)) {
587 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
588 rate_mask
= (u16
)(rate_mask
&
589 (lq_data
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
591 rate_mask
= (u16
)(rate_mask
& lq_data
->supp_rates
);
594 /* if we did switched from HT to legacy check current rate */
595 if ((switch_to_legacy
) &&
596 (rate_mask
& (1 << scale_index
))) {
597 rs_mcs_from_tbl(mcs_rate
, tbl
, scale_index
, is_green
);
601 high_low
= rs_get_adjacent_rate(scale_index
, rate_mask
, tbl
->lq_type
);
602 low
= high_low
& 0xff;
604 if (low
!= IWL_RATE_INVALID
)
605 rs_mcs_from_tbl(mcs_rate
, tbl
, low
, is_green
);
607 rs_mcs_from_tbl(mcs_rate
, tbl
, scale_index
, is_green
);
612 static void rs_tx_status(void *priv_rate
,
613 struct net_device
*dev
,
615 struct ieee80211_tx_status
*tx_resp
)
619 int rs_index
, index
= 0;
620 struct iwl_rate_scale_priv
*lq
;
621 struct iwl_link_quality_cmd
*table
;
622 struct sta_info
*sta
;
623 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
624 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
625 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
626 struct iwl_rate_scale_data
*window
= NULL
;
627 struct iwl_rate_scale_data
*search_win
= NULL
;
628 struct iwl_rate tx_mcs
;
629 struct iwl_scale_tbl_info tbl_type
;
630 struct iwl_scale_tbl_info
*curr_tbl
, *search_tbl
;
632 u16 fc
= le16_to_cpu(hdr
->frame_control
);
635 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
637 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
))
640 retries
= tx_resp
->retry_count
;
646 sta
= sta_info_get(local
, hdr
->addr1
);
648 if (!sta
|| !sta
->rate_ctrl_priv
) {
654 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
656 if (!priv
->lq_mngr
.lq_ready
)
659 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) && !lq
->ibss_sta_added
)
663 active_index
= lq
->active_tbl
;
665 lq
->antenna
= (lq
->valid_antenna
& local
->hw
.conf
.antenna_sel_tx
);
667 lq
->antenna
= lq
->valid_antenna
;
669 lq
->antenna
= lq
->valid_antenna
;
670 curr_tbl
= &(lq
->lq_info
[active_index
]);
671 search_tbl
= &(lq
->lq_info
[(1 - active_index
)]);
672 window
= (struct iwl_rate_scale_data
*)
674 search_win
= (struct iwl_rate_scale_data
*)
675 &(search_tbl
->win
[0]);
677 tx_mcs
.rate_n_flags
= tx_resp
->control
.tx_rate
;
679 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
680 &tbl_type
, &rs_index
);
681 if ((rs_index
< 0) || (rs_index
>= IWL_RATE_COUNT
)) {
682 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
683 rs_index
, tx_mcs
.rate_n_flags
);
689 (tx_mcs
.rate_n_flags
!=
690 le32_to_cpu(table
->rs_table
[0].rate_n_flags
))) {
691 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
693 le32_to_cpu(table
->rs_table
[0].rate_n_flags
));
699 tx_mcs
.rate_n_flags
=
700 le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
701 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
702 &tbl_type
, &rs_index
);
704 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
705 (tbl_type
.antenna_type
== search_tbl
->antenna_type
) &&
706 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
707 if (search_tbl
->expected_tpt
)
708 tpt
= search_tbl
->expected_tpt
[rs_index
];
711 rs_collect_tx_data(search_win
,
713 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
714 (tbl_type
.antenna_type
== curr_tbl
->antenna_type
) &&
715 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
716 if (curr_tbl
->expected_tpt
)
717 tpt
= curr_tbl
->expected_tpt
[rs_index
];
720 rs_collect_tx_data(window
, rs_index
, tpt
, 0);
729 if (!tx_resp
->retry_count
)
730 tx_mcs
.rate_n_flags
= tx_resp
->control
.tx_rate
;
732 tx_mcs
.rate_n_flags
=
733 le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
735 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
736 &tbl_type
, &rs_index
);
738 if (tx_resp
->flags
& IEEE80211_TX_STATUS_ACK
)
743 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
744 (tbl_type
.antenna_type
== search_tbl
->antenna_type
) &&
745 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
746 if (search_tbl
->expected_tpt
)
747 tpt
= search_tbl
->expected_tpt
[rs_index
];
750 rs_collect_tx_data(search_win
,
751 rs_index
, tpt
, status
);
752 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
753 (tbl_type
.antenna_type
== curr_tbl
->antenna_type
) &&
754 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
755 if (curr_tbl
->expected_tpt
)
756 tpt
= curr_tbl
->expected_tpt
[rs_index
];
759 rs_collect_tx_data(window
, rs_index
, tpt
, status
);
762 if (lq
->stay_in_tbl
) {
769 rs_rate_scale_perform(priv
, dev
, hdr
, sta
);
774 static u8
rs_is_ant_connected(u8 valid_antenna
,
775 enum iwl_antenna_type antenna_type
)
777 if (antenna_type
== ANT_AUX
)
778 return ((valid_antenna
& 0x2) ? 1:0);
779 else if (antenna_type
== ANT_MAIN
)
780 return ((valid_antenna
& 0x1) ? 1:0);
781 else if (antenna_type
== ANT_BOTH
) {
782 if ((valid_antenna
& 0x3) == 0x3)
791 static u8
rs_is_other_ant_connected(u8 valid_antenna
,
792 enum iwl_antenna_type antenna_type
)
794 if (antenna_type
== ANT_AUX
)
795 return (rs_is_ant_connected(valid_antenna
, ANT_MAIN
));
797 return (rs_is_ant_connected(valid_antenna
, ANT_AUX
));
802 static void rs_set_stay_in_table(u8 is_legacy
,
803 struct iwl_rate_scale_priv
*lq_data
)
805 IWL_DEBUG_HT("we are staying in the same table\n");
806 lq_data
->stay_in_tbl
= 1;
808 lq_data
->table_count_limit
= IWL_LEGACY_TABLE_COUNT
;
809 lq_data
->max_failure_limit
= IWL_LEGACY_FAILURE_LIMIT
;
810 lq_data
->max_success_limit
= IWL_LEGACY_TABLE_COUNT
;
812 lq_data
->table_count_limit
= IWL_NONE_LEGACY_TABLE_COUNT
;
813 lq_data
->max_failure_limit
= IWL_NONE_LEGACY_FAILURE_LIMIT
;
814 lq_data
->max_success_limit
= IWL_NONE_LEGACY_SUCCESS_LIMIT
;
816 lq_data
->table_count
= 0;
817 lq_data
->total_failed
= 0;
818 lq_data
->total_success
= 0;
821 static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv
*lq_data
,
822 struct iwl_scale_tbl_info
*tbl
)
824 if (is_legacy(tbl
->lq_type
)) {
825 if (!is_a_band(tbl
->lq_type
))
826 tbl
->expected_tpt
= expected_tpt_G
;
828 tbl
->expected_tpt
= expected_tpt_A
;
829 } else if (is_siso(tbl
->lq_type
)) {
830 if (tbl
->is_fat
&& !lq_data
->is_dup
)
832 tbl
->expected_tpt
= expected_tpt_siso40MHzSGI
;
834 tbl
->expected_tpt
= expected_tpt_siso40MHz
;
835 else if (tbl
->is_SGI
)
836 tbl
->expected_tpt
= expected_tpt_siso20MHzSGI
;
838 tbl
->expected_tpt
= expected_tpt_siso20MHz
;
840 } else if (is_mimo(tbl
->lq_type
)) {
841 if (tbl
->is_fat
&& !lq_data
->is_dup
)
843 tbl
->expected_tpt
= expected_tpt_mimo40MHzSGI
;
845 tbl
->expected_tpt
= expected_tpt_mimo40MHz
;
846 else if (tbl
->is_SGI
)
847 tbl
->expected_tpt
= expected_tpt_mimo20MHzSGI
;
849 tbl
->expected_tpt
= expected_tpt_mimo20MHz
;
851 tbl
->expected_tpt
= expected_tpt_G
;
854 #ifdef CONFIG_IWLWIFI_HT
855 static s32
rs_get_best_rate(struct iwl_priv
*priv
,
856 struct iwl_rate_scale_priv
*lq_data
,
857 struct iwl_scale_tbl_info
*tbl
,
858 u16 rate_mask
, s8 index
, s8 rate
)
860 struct iwl_scale_tbl_info
*active_tbl
=
861 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
862 s32 new_rate
, high
, low
, start_hi
;
863 s32 active_sr
= active_tbl
->win
[index
].success_ratio
;
864 s32
*tpt_tbl
= tbl
->expected_tpt
;
865 s32 active_tpt
= active_tbl
->expected_tpt
[index
];
868 new_rate
= high
= low
= start_hi
= IWL_RATE_INVALID
;
871 high_low
= rs_get_adjacent_rate(rate
, rate_mask
, tbl
->lq_type
);
873 low
= high_low
& 0xff;
874 high
= (high_low
>> 8) & 0xff;
876 if ((((100 * tpt_tbl
[rate
]) > lq_data
->last_tpt
) &&
877 ((active_sr
> IWL_RATE_DECREASE_TH
) &&
878 (active_sr
<= IWL_RATE_HIGH_TH
) &&
879 (tpt_tbl
[rate
] <= active_tpt
))) ||
880 ((active_sr
>= IWL_RATE_SCALE_SWITCH
) &&
881 (tpt_tbl
[rate
] > active_tpt
))) {
883 if (start_hi
!= IWL_RATE_INVALID
) {
888 if (low
!= IWL_RATE_INVALID
)
893 if (new_rate
!= IWL_RATE_INVALID
)
895 else if (high
!= IWL_RATE_INVALID
) {
907 #endif /* CONFIG_IWLWIFI_HT */
909 static inline u8
rs_is_both_ant_supp(u8 valid_antenna
)
911 return (rs_is_ant_connected(valid_antenna
, ANT_BOTH
));
914 static int rs_switch_to_mimo(struct iwl_priv
*priv
,
915 struct iwl_rate_scale_priv
*lq_data
,
916 struct iwl_scale_tbl_info
*tbl
, int index
)
919 #ifdef CONFIG_IWLWIFI_HT
922 s8 is_green
= lq_data
->is_green
;
924 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
927 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
928 tbl
->lq_type
= LQ_MIMO
;
929 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
,
932 if (priv
->current_assoc_ht
.tx_mimo_ps_mode
== IWL_MIMO_PS_STATIC
)
935 if (!rs_is_both_ant_supp(lq_data
->antenna
))
939 tbl
->is_dup
= lq_data
->is_dup
;
941 if (priv
->current_channel_width
== IWL_CHANNEL_WIDTH_40MHZ
)
947 if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_40MHZ_ONLY
)
951 } else if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_20MHZ_ONLY
)
956 rs_get_expected_tpt_table(lq_data
, tbl
);
958 rate
= rs_get_best_rate(priv
, lq_data
, tbl
, rate_mask
, index
, index
);
960 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate
, rate_mask
);
961 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
))
963 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, rate
, is_green
);
965 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
966 tbl
->current_rate
.rate_n_flags
, is_green
);
968 #endif /*CONFIG_IWLWIFI_HT */
972 static int rs_switch_to_siso(struct iwl_priv
*priv
,
973 struct iwl_rate_scale_priv
*lq_data
,
974 struct iwl_scale_tbl_info
*tbl
, int index
)
977 #ifdef CONFIG_IWLWIFI_HT
979 u8 is_green
= lq_data
->is_green
;
982 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
983 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
987 tbl
->is_dup
= lq_data
->is_dup
;
988 tbl
->lq_type
= LQ_SISO
;
990 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
,
993 if (priv
->current_channel_width
== IWL_CHANNEL_WIDTH_40MHZ
)
999 if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_40MHZ_ONLY
)
1003 } else if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_20MHZ_ONLY
)
1011 rs_get_expected_tpt_table(lq_data
, tbl
);
1012 rate
= rs_get_best_rate(priv
, lq_data
, tbl
, rate_mask
, index
, index
);
1014 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate
, rate_mask
);
1015 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
1016 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
1020 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, rate
, is_green
);
1021 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
1022 tbl
->current_rate
.rate_n_flags
, is_green
);
1024 #endif /*CONFIG_IWLWIFI_HT */
1028 static int rs_move_legacy_other(struct iwl_priv
*priv
,
1029 struct iwl_rate_scale_priv
*lq_data
,
1033 struct iwl_scale_tbl_info
*tbl
=
1034 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1035 struct iwl_scale_tbl_info
*search_tbl
=
1036 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1037 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1038 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1039 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1040 u8 start_action
= tbl
->action
;
1043 switch (tbl
->action
) {
1044 case IWL_LEGACY_SWITCH_ANTENNA
:
1045 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1047 search_tbl
->lq_type
= LQ_NONE
;
1048 lq_data
->action_counter
++;
1049 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1051 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1055 memcpy(search_tbl
, tbl
, sz
);
1057 rs_toggle_antenna(&(search_tbl
->current_rate
),
1059 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1060 lq_data
->search_better_tbl
= 1;
1063 case IWL_LEGACY_SWITCH_SISO
:
1064 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1065 memcpy(search_tbl
, tbl
, sz
);
1066 search_tbl
->lq_type
= LQ_SISO
;
1067 search_tbl
->is_SGI
= 0;
1068 search_tbl
->is_fat
= 0;
1069 rc
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1072 lq_data
->search_better_tbl
= 1;
1073 lq_data
->action_counter
= 0;
1079 case IWL_LEGACY_SWITCH_MIMO
:
1080 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1081 memcpy(search_tbl
, tbl
, sz
);
1082 search_tbl
->lq_type
= LQ_MIMO
;
1083 search_tbl
->is_SGI
= 0;
1084 search_tbl
->is_fat
= 0;
1085 search_tbl
->antenna_type
= ANT_BOTH
;
1086 rc
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1089 lq_data
->search_better_tbl
= 1;
1090 lq_data
->action_counter
= 0;
1097 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1098 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1100 if (tbl
->action
== start_action
)
1108 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1109 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1114 static int rs_move_siso_to_other(struct iwl_priv
*priv
,
1115 struct iwl_rate_scale_priv
*lq_data
,
1119 u8 is_green
= lq_data
->is_green
;
1120 struct iwl_scale_tbl_info
*tbl
=
1121 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1122 struct iwl_scale_tbl_info
*search_tbl
=
1123 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1124 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1125 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1126 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1127 u8 start_action
= tbl
->action
;
1130 lq_data
->action_counter
++;
1131 switch (tbl
->action
) {
1132 case IWL_SISO_SWITCH_ANTENNA
:
1133 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1134 search_tbl
->lq_type
= LQ_NONE
;
1135 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1137 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1141 memcpy(search_tbl
, tbl
, sz
);
1142 search_tbl
->action
= IWL_SISO_SWITCH_MIMO
;
1143 rs_toggle_antenna(&(search_tbl
->current_rate
),
1145 lq_data
->search_better_tbl
= 1;
1149 case IWL_SISO_SWITCH_MIMO
:
1150 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1151 memcpy(search_tbl
, tbl
, sz
);
1152 search_tbl
->lq_type
= LQ_MIMO
;
1153 search_tbl
->is_SGI
= 0;
1154 search_tbl
->is_fat
= 0;
1155 search_tbl
->antenna_type
= ANT_BOTH
;
1156 rc
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1159 lq_data
->search_better_tbl
= 1;
1164 case IWL_SISO_SWITCH_GI
:
1165 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1166 memcpy(search_tbl
, tbl
, sz
);
1167 search_tbl
->action
= 0;
1168 if (search_tbl
->is_SGI
)
1169 search_tbl
->is_SGI
= 0;
1171 search_tbl
->is_SGI
= 1;
1174 lq_data
->search_better_tbl
= 1;
1175 if ((tbl
->lq_type
== LQ_SISO
) &&
1177 s32 tpt
= lq_data
->last_tpt
/ 100;
1178 if (((!tbl
->is_fat
) &&
1179 (tpt
>= expected_tpt_siso20MHz
[index
])) ||
1181 (tpt
>= expected_tpt_siso40MHz
[index
])))
1182 lq_data
->search_better_tbl
= 0;
1184 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1185 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1186 search_tbl
, index
, is_green
);
1190 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1191 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1193 if (tbl
->action
== start_action
)
1200 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1201 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1205 static int rs_move_mimo_to_other(struct iwl_priv
*priv
,
1206 struct iwl_rate_scale_priv
*lq_data
,
1210 s8 is_green
= lq_data
->is_green
;
1211 struct iwl_scale_tbl_info
*tbl
=
1212 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1213 struct iwl_scale_tbl_info
*search_tbl
=
1214 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1215 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1216 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1217 u8 start_action
= tbl
->action
;
1220 lq_data
->action_counter
++;
1221 switch (tbl
->action
) {
1222 case IWL_MIMO_SWITCH_ANTENNA_A
:
1223 case IWL_MIMO_SWITCH_ANTENNA_B
:
1224 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1225 memcpy(search_tbl
, tbl
, sz
);
1226 search_tbl
->lq_type
= LQ_SISO
;
1227 search_tbl
->is_SGI
= 0;
1228 search_tbl
->is_fat
= 0;
1229 if (tbl
->action
== IWL_MIMO_SWITCH_ANTENNA_A
)
1230 search_tbl
->antenna_type
= ANT_MAIN
;
1232 search_tbl
->antenna_type
= ANT_AUX
;
1234 rc
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1237 lq_data
->search_better_tbl
= 1;
1242 case IWL_MIMO_SWITCH_GI
:
1243 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1244 memcpy(search_tbl
, tbl
, sz
);
1245 search_tbl
->lq_type
= LQ_MIMO
;
1246 search_tbl
->antenna_type
= ANT_BOTH
;
1247 search_tbl
->action
= 0;
1248 if (search_tbl
->is_SGI
)
1249 search_tbl
->is_SGI
= 0;
1251 search_tbl
->is_SGI
= 1;
1252 lq_data
->search_better_tbl
= 1;
1253 if ((tbl
->lq_type
== LQ_MIMO
) &&
1255 s32 tpt
= lq_data
->last_tpt
/ 100;
1256 if (((!tbl
->is_fat
) &&
1257 (tpt
>= expected_tpt_mimo20MHz
[index
])) ||
1259 (tpt
>= expected_tpt_mimo40MHz
[index
])))
1260 lq_data
->search_better_tbl
= 0;
1262 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1263 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1264 search_tbl
, index
, is_green
);
1269 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1270 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1272 if (tbl
->action
== start_action
)
1279 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1280 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1285 static void rs_stay_in_table(struct iwl_rate_scale_priv
*lq_data
)
1287 struct iwl_scale_tbl_info
*tbl
;
1290 int flush_interval_passed
= 0;
1292 active_tbl
= lq_data
->active_tbl
;
1294 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1296 if (lq_data
->stay_in_tbl
) {
1298 if (lq_data
->flush_timer
)
1299 flush_interval_passed
=
1301 (unsigned long)(lq_data
->flush_timer
+
1302 IWL_RATE_SCALE_FLUSH_INTVL
));
1304 flush_interval_passed
= 0;
1305 if ((lq_data
->total_failed
> lq_data
->max_failure_limit
) ||
1306 (lq_data
->total_success
> lq_data
->max_success_limit
) ||
1307 ((!lq_data
->search_better_tbl
) && (lq_data
->flush_timer
)
1308 && (flush_interval_passed
))) {
1309 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1310 lq_data
->total_failed
,
1311 lq_data
->total_success
,
1312 flush_interval_passed
);
1313 lq_data
->stay_in_tbl
= 0;
1314 lq_data
->total_failed
= 0;
1315 lq_data
->total_success
= 0;
1316 lq_data
->flush_timer
= 0;
1317 } else if (lq_data
->table_count
> 0) {
1318 lq_data
->table_count
++;
1319 if (lq_data
->table_count
>=
1320 lq_data
->table_count_limit
) {
1321 lq_data
->table_count
= 0;
1323 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1324 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1325 rs_rate_scale_clear_window(
1330 if (!lq_data
->stay_in_tbl
) {
1331 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1332 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1337 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
1338 struct net_device
*dev
,
1339 struct ieee80211_hdr
*hdr
,
1340 struct sta_info
*sta
)
1342 int low
= IWL_RATE_INVALID
;
1343 int high
= IWL_RATE_INVALID
;
1346 struct iwl_rate_scale_data
*window
= NULL
;
1347 int current_tpt
= IWL_INVALID_VALUE
;
1348 int low_tpt
= IWL_INVALID_VALUE
;
1349 int high_tpt
= IWL_INVALID_VALUE
;
1351 s8 scale_action
= 0;
1354 struct iwl_rate_scale_priv
*lq_data
;
1355 struct iwl_scale_tbl_info
*tbl
, *tbl1
;
1356 u16 rate_scale_index_msk
= 0;
1357 struct iwl_rate mcs_rate
;
1363 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1365 fc
= le16_to_cpu(hdr
->frame_control
);
1366 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
)) {
1367 /* Send management frames and broadcast/multicast data using
1369 /* TODO: this could probably be improved.. */
1373 if (!sta
|| !sta
->rate_ctrl_priv
)
1376 if (!priv
->lq_mngr
.lq_ready
) {
1377 IWL_DEBUG_RATE("still rate scaling not ready\n");
1380 lq_data
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1382 if (!lq_data
->search_better_tbl
)
1383 active_tbl
= lq_data
->active_tbl
;
1385 active_tbl
= 1 - lq_data
->active_tbl
;
1387 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1388 is_green
= lq_data
->is_green
;
1390 index
= sta
->last_txrate
;
1392 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index
,
1395 rs_get_supported_rates(lq_data
, hdr
, tbl
->lq_type
,
1398 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask
);
1400 /* mask with station rate restriction */
1401 if (is_legacy(tbl
->lq_type
)) {
1402 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1403 rate_scale_index_msk
= (u16
) (rate_mask
&
1404 (lq_data
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
1406 rate_scale_index_msk
= (u16
) (rate_mask
&
1407 lq_data
->supp_rates
);
1410 rate_scale_index_msk
= rate_mask
;
1412 if (!rate_scale_index_msk
)
1413 rate_scale_index_msk
= rate_mask
;
1415 if (index
< 0 || !((1 << index
) & rate_scale_index_msk
)) {
1416 index
= IWL_INVALID_VALUE
;
1419 /* get the lowest availabe rate */
1420 for (i
= 0; i
<= IWL_RATE_COUNT
; i
++) {
1421 if ((1 << i
) & rate_scale_index_msk
)
1425 if (index
== IWL_INVALID_VALUE
) {
1426 IWL_WARNING("Can not find a suitable rate\n");
1431 if (!tbl
->expected_tpt
)
1432 rs_get_expected_tpt_table(lq_data
, tbl
);
1434 window
= &(tbl
->win
[index
]);
1436 fail_count
= window
->counter
- window
->success_counter
;
1437 if (((fail_count
< IWL_RATE_MIN_FAILURE_TH
) &&
1438 (window
->success_counter
< IWL_RATE_MIN_SUCCESS_TH
))
1439 || (tbl
->expected_tpt
== NULL
)) {
1440 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1442 window
->success_counter
, window
->counter
, index
);
1443 window
->average_tpt
= IWL_INVALID_VALUE
;
1444 rs_stay_in_table(lq_data
);
1446 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1447 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1448 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1453 window
->average_tpt
= ((window
->success_ratio
*
1454 tbl
->expected_tpt
[index
] + 64) / 128);
1456 if (lq_data
->search_better_tbl
) {
1457 int success_limit
= IWL_RATE_SCALE_SWITCH
;
1459 if ((window
->success_ratio
> success_limit
) ||
1460 (window
->average_tpt
> lq_data
->last_tpt
)) {
1461 if (!is_legacy(tbl
->lq_type
)) {
1462 IWL_DEBUG_HT("LQ: we are switching to HT"
1463 " rate suc %d current tpt %d"
1465 window
->success_ratio
,
1466 window
->average_tpt
,
1468 lq_data
->enable_counter
= 1;
1470 lq_data
->active_tbl
= active_tbl
;
1471 current_tpt
= window
->average_tpt
;
1473 tbl
->lq_type
= LQ_NONE
;
1474 active_tbl
= lq_data
->active_tbl
;
1475 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1477 index
= iwl_rate_index_from_plcp(
1478 tbl
->current_rate
.rate_n_flags
);
1481 current_tpt
= lq_data
->last_tpt
;
1482 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1484 lq_data
->search_better_tbl
= 0;
1489 high_low
= rs_get_adjacent_rate(index
, rate_scale_index_msk
,
1491 low
= high_low
& 0xff;
1492 high
= (high_low
>> 8) & 0xff;
1494 current_tpt
= window
->average_tpt
;
1496 if (low
!= IWL_RATE_INVALID
)
1497 low_tpt
= tbl
->win
[low
].average_tpt
;
1499 if (high
!= IWL_RATE_INVALID
)
1500 high_tpt
= tbl
->win
[high
].average_tpt
;
1505 if ((window
->success_ratio
<= IWL_RATE_DECREASE_TH
) ||
1506 (current_tpt
== 0)) {
1507 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1509 } else if ((low_tpt
== IWL_INVALID_VALUE
) &&
1510 (high_tpt
== IWL_INVALID_VALUE
))
1512 else if ((low_tpt
!= IWL_INVALID_VALUE
) &&
1513 (high_tpt
!= IWL_INVALID_VALUE
) &&
1514 (low_tpt
< current_tpt
) &&
1515 (high_tpt
< current_tpt
))
1518 if (high_tpt
!= IWL_INVALID_VALUE
) {
1519 if (high_tpt
> current_tpt
)
1523 ("decrease rate because of high tpt\n");
1526 } else if (low_tpt
!= IWL_INVALID_VALUE
) {
1527 if (low_tpt
> current_tpt
) {
1529 ("decrease rate because of low tpt\n");
1536 if (scale_action
== -1) {
1537 if ((low
!= IWL_RATE_INVALID
) &&
1538 ((window
->success_ratio
> IWL_RATE_HIGH_TH
) ||
1539 (current_tpt
> (100 * tbl
->expected_tpt
[low
]))))
1541 } else if ((scale_action
== 1) &&
1542 (window
->success_ratio
< IWL_RATE_INCREASE_TH
))
1545 switch (scale_action
) {
1547 if (low
!= IWL_RATE_INVALID
) {
1553 if (high
!= IWL_RATE_INVALID
) {
1564 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1565 "high %d type %d\n",
1566 index
, scale_action
, low
, high
, tbl
->lq_type
);
1570 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1571 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1572 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1574 rs_stay_in_table(lq_data
);
1576 if (!update_lq
&& !done_search
&& !lq_data
->stay_in_tbl
) {
1577 lq_data
->last_tpt
= current_tpt
;
1579 if (is_legacy(tbl
->lq_type
))
1580 rs_move_legacy_other(priv
, lq_data
, index
);
1581 else if (is_siso(tbl
->lq_type
))
1582 rs_move_siso_to_other(priv
, lq_data
, index
);
1584 rs_move_mimo_to_other(priv
, lq_data
, index
);
1586 if (lq_data
->search_better_tbl
) {
1587 tbl
= &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1588 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1589 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1591 index
= iwl_rate_index_from_plcp(
1592 tbl
->current_rate
.rate_n_flags
);
1594 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1595 tbl
->current_rate
.rate_n_flags
, index
);
1596 rs_fill_link_cmd(lq_data
, &tbl
->current_rate
,
1598 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1600 tbl1
= &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1602 if (is_legacy(tbl1
->lq_type
) &&
1603 #ifdef CONFIG_IWLWIFI_HT
1604 !priv
->current_assoc_ht
.is_ht
&&
1606 (lq_data
->action_counter
>= 1)) {
1607 lq_data
->action_counter
= 0;
1608 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1609 rs_set_stay_in_table(1, lq_data
);
1612 if (lq_data
->enable_counter
&&
1613 (lq_data
->action_counter
>= IWL_ACTION_LIMIT
)) {
1614 #ifdef CONFIG_IWLWIFI_HT_AGG
1615 if ((lq_data
->last_tpt
> TID_AGG_TPT_THREHOLD
) &&
1616 (priv
->lq_mngr
.agg_ctrl
.auto_agg
)) {
1617 priv
->lq_mngr
.agg_ctrl
.tid_retry
=
1619 schedule_work(&priv
->agg_work
);
1621 #endif /*CONFIG_IWLWIFI_HT_AGG */
1622 lq_data
->action_counter
= 0;
1623 rs_set_stay_in_table(0, lq_data
);
1626 if ((!update_lq
) && (!done_search
) && (!lq_data
->flush_timer
))
1627 lq_data
->flush_timer
= jiffies
;
1631 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, index
, is_green
);
1633 sta
->last_txrate
= i
;
1635 /* sta->txrate is an index to A mode rates which start
1636 * at IWL_FIRST_OFDM_RATE
1638 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1639 sta
->txrate
= i
- IWL_FIRST_OFDM_RATE
;
1647 static void rs_initialize_lq(struct iwl_priv
*priv
,
1648 struct sta_info
*sta
)
1651 struct iwl_rate_scale_priv
*lq
;
1652 struct iwl_scale_tbl_info
*tbl
;
1655 u8 use_green
= rs_use_green(priv
);
1656 struct iwl_rate mcs_rate
;
1658 if (!sta
|| !sta
->rate_ctrl_priv
)
1661 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1662 i
= sta
->last_txrate
;
1664 if ((lq
->lq
.sta_id
== 0xff) &&
1665 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
1668 if (!lq
->search_better_tbl
)
1669 active_tbl
= lq
->active_tbl
;
1671 active_tbl
= 1 - lq
->active_tbl
;
1673 tbl
= &(lq
->lq_info
[active_tbl
]);
1675 if ((i
< 0) || (i
>= IWL_RATE_COUNT
))
1678 mcs_rate
.rate_n_flags
= iwl_rates
[i
].plcp
;
1679 mcs_rate
.rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
1680 mcs_rate
.rate_n_flags
&= ~RATE_MCS_ANT_A_MSK
;
1682 if (i
>= IWL_FIRST_CCK_RATE
&& i
<= IWL_LAST_CCK_RATE
)
1683 mcs_rate
.rate_n_flags
|= RATE_MCS_CCK_MSK
;
1685 tbl
->antenna_type
= ANT_AUX
;
1686 rs_get_tbl_info_from_mcs(&mcs_rate
, priv
->phymode
, tbl
, &rate_idx
);
1687 if (!rs_is_ant_connected(priv
->valid_antenna
, tbl
->antenna_type
))
1688 rs_toggle_antenna(&mcs_rate
, tbl
);
1690 rs_mcs_from_tbl(&mcs_rate
, tbl
, rate_idx
, use_green
);
1691 tbl
->current_rate
.rate_n_flags
= mcs_rate
.rate_n_flags
;
1692 rs_get_expected_tpt_table(lq
, tbl
);
1693 rs_fill_link_cmd(lq
, &mcs_rate
, &lq
->lq
);
1694 rs_send_lq_cmd(priv
, &lq
->lq
, CMD_ASYNC
);
1699 static struct ieee80211_rate
*rs_get_lowest_rate(struct ieee80211_local
1702 struct ieee80211_hw_mode
*mode
= local
->oper_hw_mode
;
1705 for (i
= 0; i
< mode
->num_rates
; i
++) {
1706 struct ieee80211_rate
*rate
= &mode
->rates
[i
];
1708 if (rate
->flags
& IEEE80211_RATE_SUPPORTED
)
1712 return &mode
->rates
[0];
1715 static struct ieee80211_rate
*rs_get_rate(void *priv_rate
,
1716 struct net_device
*dev
,
1717 struct sk_buff
*skb
,
1718 struct rate_control_extra
1723 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1724 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1725 struct sta_info
*sta
;
1727 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1728 struct iwl_rate_scale_priv
*lq
;
1730 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1732 memset(extra
, 0, sizeof(*extra
));
1734 fc
= le16_to_cpu(hdr
->frame_control
);
1735 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
)) {
1736 /* Send management frames and broadcast/multicast data using
1738 /* TODO: this could probably be improved.. */
1739 return rs_get_lowest_rate(local
);
1742 sta
= sta_info_get(local
, hdr
->addr1
);
1744 if (!sta
|| !sta
->rate_ctrl_priv
) {
1747 return rs_get_lowest_rate(local
);
1750 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1751 i
= sta
->last_txrate
;
1753 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) && !lq
->ibss_sta_added
) {
1754 u8 sta_id
= iwl_hw_find_station(priv
, hdr
->addr1
);
1755 DECLARE_MAC_BUF(mac
);
1757 if (sta_id
== IWL_INVALID_STATION
) {
1758 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1759 print_mac(mac
, hdr
->addr1
));
1760 sta_id
= iwl_add_station(priv
,
1761 hdr
->addr1
, 0, CMD_ASYNC
);
1763 if ((sta_id
!= IWL_INVALID_STATION
)) {
1764 lq
->lq
.sta_id
= sta_id
;
1765 lq
->lq
.rs_table
[0].rate_n_flags
= 0;
1766 lq
->ibss_sta_added
= 1;
1767 rs_initialize_lq(priv
, sta
);
1769 if (!lq
->ibss_sta_added
)
1775 if ((i
< 0) || (i
> IWL_RATE_COUNT
))
1776 return rs_get_lowest_rate(local
);
1778 return &priv
->ieee_rates
[i
];
1781 static void *rs_alloc_sta(void *priv
, gfp_t gfp
)
1783 struct iwl_rate_scale_priv
*crl
;
1786 IWL_DEBUG_RATE("create station rate scale window\n");
1788 crl
= kzalloc(sizeof(struct iwl_rate_scale_priv
), gfp
);
1792 crl
->lq
.sta_id
= 0xff;
1795 for (j
= 0; j
< LQ_SIZE
; j
++)
1796 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1797 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1802 static void rs_rate_init(void *priv_rate
, void *priv_sta
,
1803 struct ieee80211_local
*local
,
1804 struct sta_info
*sta
)
1807 struct ieee80211_hw_mode
*mode
= local
->oper_hw_mode
;
1808 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1809 struct iwl_rate_scale_priv
*crl
= priv_sta
;
1811 crl
->flush_timer
= 0;
1812 crl
->supp_rates
= sta
->supp_rates
;
1814 for (j
= 0; j
< LQ_SIZE
; j
++)
1815 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1816 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1818 IWL_DEBUG_RATE("rate scale global init\n");
1819 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1820 * the lowest or the highest rate.. Could consider using RSSI from
1821 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1824 crl
->ibss_sta_added
= 0;
1825 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1826 u8 sta_id
= iwl_hw_find_station(priv
, sta
->addr
);
1827 DECLARE_MAC_BUF(mac
);
1829 /* for IBSS the call are from tasklet */
1830 IWL_DEBUG_HT("LQ: ADD station %s\n",
1831 print_mac(mac
, sta
->addr
));
1833 if (sta_id
== IWL_INVALID_STATION
) {
1834 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1835 print_mac(mac
, sta
->addr
));
1836 sta_id
= iwl_add_station(priv
,
1837 sta
->addr
, 0, CMD_ASYNC
);
1839 if ((sta_id
!= IWL_INVALID_STATION
)) {
1840 crl
->lq
.sta_id
= sta_id
;
1841 crl
->lq
.rs_table
[0].rate_n_flags
= 0;
1843 /* FIXME: this is w/a remove it later */
1844 priv
->assoc_station_added
= 1;
1847 for (i
= 0; i
< mode
->num_rates
; i
++) {
1848 if ((sta
->supp_rates
& BIT(i
)) &&
1849 (mode
->rates
[i
].flags
& IEEE80211_RATE_SUPPORTED
))
1852 sta
->last_txrate
= sta
->txrate
;
1853 /* For MODE_IEEE80211A mode cck rate are at end
1856 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
)
1857 sta
->last_txrate
+= IWL_FIRST_OFDM_RATE
;
1859 crl
->is_dup
= priv
->is_dup
;
1860 crl
->valid_antenna
= priv
->valid_antenna
;
1861 crl
->antenna
= priv
->antenna
;
1862 crl
->is_green
= rs_use_green(priv
);
1863 crl
->active_rate
= priv
->active_rate
;
1864 crl
->active_rate
&= ~(0x1000);
1865 crl
->active_rate_basic
= priv
->active_rate_basic
;
1866 crl
->phymode
= priv
->phymode
;
1867 #ifdef CONFIG_IWLWIFI_HT
1868 crl
->active_siso_rate
= (priv
->current_assoc_ht
.supp_rates
[0] << 1);
1869 crl
->active_siso_rate
|= (priv
->current_assoc_ht
.supp_rates
[0] & 0x1);
1870 crl
->active_siso_rate
&= ~((u16
)0x2);
1871 crl
->active_siso_rate
= crl
->active_siso_rate
<< IWL_FIRST_OFDM_RATE
;
1873 crl
->active_mimo_rate
= (priv
->current_assoc_ht
.supp_rates
[1] << 1);
1874 crl
->active_mimo_rate
|= (priv
->current_assoc_ht
.supp_rates
[1] & 0x1);
1875 crl
->active_mimo_rate
&= ~((u16
)0x2);
1876 crl
->active_mimo_rate
= crl
->active_mimo_rate
<< IWL_FIRST_OFDM_RATE
;
1877 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl
->active_siso_rate
,
1878 crl
->active_mimo_rate
);
1879 #endif /*CONFIG_IWLWIFI_HT*/
1880 #ifdef CONFIG_MAC80211_DEBUGFS
1884 if (priv
->assoc_station_added
)
1885 priv
->lq_mngr
.lq_ready
= 1;
1887 rs_initialize_lq(priv
, sta
);
1890 static void rs_fill_link_cmd(struct iwl_rate_scale_priv
*lq_data
,
1891 struct iwl_rate
*tx_mcs
,
1892 struct iwl_link_quality_cmd
*lq_cmd
)
1896 int repeat_rate
= 0;
1897 u8 ant_toggle_count
= 0;
1898 u8 use_ht_possible
= 1;
1899 struct iwl_rate new_rate
;
1900 struct iwl_scale_tbl_info tbl_type
= { 0 };
1902 rs_dbgfs_set_mcs(lq_data
, tx_mcs
, index
);
1904 rs_get_tbl_info_from_mcs(tx_mcs
, lq_data
->phymode
,
1905 &tbl_type
, &rate_idx
);
1907 if (is_legacy(tbl_type
.lq_type
)) {
1908 ant_toggle_count
= 1;
1909 repeat_rate
= IWL_NUMBER_TRY
;
1911 repeat_rate
= IWL_HT_NUMBER_TRY
;
1913 lq_cmd
->general_params
.mimo_delimiter
=
1914 is_mimo(tbl_type
.lq_type
) ? 1 : 0;
1915 lq_cmd
->rs_table
[index
].rate_n_flags
=
1916 cpu_to_le32(tx_mcs
->rate_n_flags
);
1917 new_rate
.rate_n_flags
= tx_mcs
->rate_n_flags
;
1919 if (is_mimo(tbl_type
.lq_type
) || (tbl_type
.antenna_type
== ANT_MAIN
))
1920 lq_cmd
->general_params
.single_stream_ant_msk
= 1;
1922 lq_cmd
->general_params
.single_stream_ant_msk
= 2;
1927 while (index
< LINK_QUAL_MAX_RETRY_NUM
) {
1928 while (repeat_rate
> 0 && (index
< LINK_QUAL_MAX_RETRY_NUM
)) {
1929 if (is_legacy(tbl_type
.lq_type
)) {
1930 if (ant_toggle_count
<
1931 NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1934 rs_toggle_antenna(&new_rate
, &tbl_type
);
1935 ant_toggle_count
= 1;
1939 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1940 lq_cmd
->rs_table
[index
].rate_n_flags
=
1941 cpu_to_le32(new_rate
.rate_n_flags
);
1946 rs_get_tbl_info_from_mcs(&new_rate
, lq_data
->phymode
, &tbl_type
,
1949 if (is_mimo(tbl_type
.lq_type
))
1950 lq_cmd
->general_params
.mimo_delimiter
= index
;
1952 rs_get_lower_rate(lq_data
, &tbl_type
, rate_idx
,
1953 use_ht_possible
, &new_rate
);
1955 if (is_legacy(tbl_type
.lq_type
)) {
1956 if (ant_toggle_count
< NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1959 rs_toggle_antenna(&new_rate
, &tbl_type
);
1960 ant_toggle_count
= 1;
1962 repeat_rate
= IWL_NUMBER_TRY
;
1964 repeat_rate
= IWL_HT_NUMBER_TRY
;
1966 use_ht_possible
= 0;
1968 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1969 lq_cmd
->rs_table
[index
].rate_n_flags
=
1970 cpu_to_le32(new_rate
.rate_n_flags
);
1976 lq_cmd
->general_params
.dual_stream_ant_msk
= 3;
1977 lq_cmd
->agg_params
.agg_dis_start_th
= 3;
1978 lq_cmd
->agg_params
.agg_time_limit
= cpu_to_le16(4000);
1981 static void *rs_alloc(struct ieee80211_local
*local
)
1983 return local
->hw
.priv
;
1985 /* rate scale requires free function to be implemented */
1986 static void rs_free(void *priv_rate
)
1991 static void rs_clear(void *priv_rate
)
1993 struct iwl_priv
*priv
= (struct iwl_priv
*) priv_rate
;
1995 IWL_DEBUG_RATE("enter\n");
1997 priv
->lq_mngr
.lq_ready
= 0;
1998 #ifdef CONFIG_IWLWIFI_HT
1999 #ifdef CONFIG_IWLWIFI_HT_AGG
2000 if (priv
->lq_mngr
.agg_ctrl
.granted_ba
)
2001 iwl4965_turn_off_agg(priv
, TID_ALL_SPECIFIED
);
2002 #endif /*CONFIG_IWLWIFI_HT_AGG */
2003 #endif /* CONFIG_IWLWIFI_HT */
2005 IWL_DEBUG_RATE("leave\n");
2008 static void rs_free_sta(void *priv
, void *priv_sta
)
2010 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2012 IWL_DEBUG_RATE("enter\n");
2014 IWL_DEBUG_RATE("leave\n");
2018 #ifdef CONFIG_MAC80211_DEBUGFS
2019 static int open_file_generic(struct inode
*inode
, struct file
*file
)
2021 file
->private_data
= inode
->i_private
;
2024 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
2025 struct iwl_rate
*mcs
, int index
)
2027 const u32 cck_rate
= 0x820A;
2028 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
2030 mcs
->rate_n_flags
= rs_priv
->dbg_fixed
.rate_n_flags
;
2032 mcs
->rate_n_flags
= cck_rate
;
2033 IWL_DEBUG_RATE("Fixed rate ON\n");
2037 IWL_DEBUG_RATE("Fixed rate OFF\n");
2040 static ssize_t
rs_sta_dbgfs_scale_table_write(struct file
*file
,
2041 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2043 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2048 memset(buf
, 0, sizeof(buf
));
2049 buf_size
= min(count
, sizeof(buf
) - 1);
2050 if (copy_from_user(buf
, user_buf
, buf_size
))
2053 if (sscanf(buf
, "%x", &parsed_rate
) == 1)
2054 rs_priv
->dbg_fixed
.rate_n_flags
= parsed_rate
;
2056 rs_priv
->dbg_fixed
.rate_n_flags
= 0;
2058 rs_priv
->active_rate
= 0x0FFF;
2059 rs_priv
->active_siso_rate
= 0x1FD0;
2060 rs_priv
->active_mimo_rate
= 0x1FD0;
2062 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2063 rs_priv
->lq
.sta_id
, rs_priv
->dbg_fixed
.rate_n_flags
);
2065 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
2066 rs_fill_link_cmd(rs_priv
, &rs_priv
->dbg_fixed
, &rs_priv
->lq
);
2067 rs_send_lq_cmd(rs_priv
->drv
, &rs_priv
->lq
, CMD_ASYNC
);
2073 static ssize_t
rs_sta_dbgfs_scale_table_read(struct file
*file
,
2074 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2080 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2082 desc
+= sprintf(buff
+desc
, "sta_id %d\n", rs_priv
->lq
.sta_id
);
2083 desc
+= sprintf(buff
+desc
, "failed=%d success=%d rate=0%X\n",
2084 rs_priv
->total_failed
, rs_priv
->total_success
,
2085 rs_priv
->active_rate
);
2086 desc
+= sprintf(buff
+desc
, "fixed rate 0x%X\n",
2087 rs_priv
->dbg_fixed
.rate_n_flags
);
2088 desc
+= sprintf(buff
+desc
, "general:"
2089 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2090 rs_priv
->lq
.general_params
.flags
,
2091 rs_priv
->lq
.general_params
.mimo_delimiter
,
2092 rs_priv
->lq
.general_params
.single_stream_ant_msk
,
2093 rs_priv
->lq
.general_params
.dual_stream_ant_msk
);
2095 desc
+= sprintf(buff
+desc
, "agg:"
2096 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2097 le16_to_cpu(rs_priv
->lq
.agg_params
.agg_time_limit
),
2098 rs_priv
->lq
.agg_params
.agg_dis_start_th
,
2099 rs_priv
->lq
.agg_params
.agg_frame_cnt_limit
);
2101 desc
+= sprintf(buff
+desc
,
2102 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2103 rs_priv
->lq
.general_params
.start_rate_index
[0],
2104 rs_priv
->lq
.general_params
.start_rate_index
[1],
2105 rs_priv
->lq
.general_params
.start_rate_index
[2],
2106 rs_priv
->lq
.general_params
.start_rate_index
[3]);
2109 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
2110 desc
+= sprintf(buff
+desc
, " rate[%d] 0x%X\n",
2111 i
, le32_to_cpu(rs_priv
->lq
.rs_table
[i
].rate_n_flags
));
2113 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2116 static const struct file_operations rs_sta_dbgfs_scale_table_ops
= {
2117 .write
= rs_sta_dbgfs_scale_table_write
,
2118 .read
= rs_sta_dbgfs_scale_table_read
,
2119 .open
= open_file_generic
,
2121 static ssize_t
rs_sta_dbgfs_stats_table_read(struct file
*file
,
2122 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2128 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2129 for (i
= 0; i
< LQ_SIZE
; i
++) {
2130 desc
+= sprintf(buff
+desc
, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2132 rs_priv
->active_tbl
== i
?"*":"x",
2133 rs_priv
->lq_info
[i
].lq_type
,
2134 rs_priv
->lq_info
[i
].is_SGI
,
2135 rs_priv
->lq_info
[i
].is_fat
,
2136 rs_priv
->lq_info
[i
].is_dup
,
2137 rs_priv
->lq_info
[i
].current_rate
.rate_n_flags
);
2138 for (j
= 0; j
< IWL_RATE_COUNT
; j
++) {
2139 desc
+= sprintf(buff
+desc
,
2140 "counter=%d success=%d %%=%d\n",
2141 rs_priv
->lq_info
[i
].win
[j
].counter
,
2142 rs_priv
->lq_info
[i
].win
[j
].success_counter
,
2143 rs_priv
->lq_info
[i
].win
[j
].success_ratio
);
2146 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2149 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
2150 .read
= rs_sta_dbgfs_stats_table_read
,
2151 .open
= open_file_generic
,
2154 static void rs_add_debugfs(void *priv
, void *priv_sta
,
2157 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2158 rs_priv
->rs_sta_dbgfs_scale_table_file
=
2159 debugfs_create_file("rate_scale_table", 0600, dir
,
2160 rs_priv
, &rs_sta_dbgfs_scale_table_ops
);
2161 rs_priv
->rs_sta_dbgfs_stats_table_file
=
2162 debugfs_create_file("rate_stats_table", 0600, dir
,
2163 rs_priv
, &rs_sta_dbgfs_stats_table_ops
);
2166 static void rs_remove_debugfs(void *priv
, void *priv_sta
)
2168 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2169 debugfs_remove(rs_priv
->rs_sta_dbgfs_scale_table_file
);
2170 debugfs_remove(rs_priv
->rs_sta_dbgfs_stats_table_file
);
2174 static struct rate_control_ops rs_ops
= {
2177 .tx_status
= rs_tx_status
,
2178 .get_rate
= rs_get_rate
,
2179 .rate_init
= rs_rate_init
,
2183 .alloc_sta
= rs_alloc_sta
,
2184 .free_sta
= rs_free_sta
,
2185 #ifdef CONFIG_MAC80211_DEBUGFS
2186 .add_sta_debugfs
= rs_add_debugfs
,
2187 .remove_sta_debugfs
= rs_remove_debugfs
,
2191 int iwl_fill_rs_info(struct ieee80211_hw
*hw
, char *buf
, u8 sta_id
)
2193 struct ieee80211_local
*local
= hw_to_local(hw
);
2194 struct iwl_priv
*priv
= hw
->priv
;
2195 struct iwl_rate_scale_priv
*rs_priv
;
2196 struct sta_info
*sta
;
2198 u32 samples
= 0, success
= 0, good
= 0;
2199 unsigned long now
= jiffies
;
2201 u8 lq_type
, antenna
;
2203 sta
= sta_info_get(local
, priv
->stations
[sta_id
].sta
.sta
.addr
);
2204 if (!sta
|| !sta
->rate_ctrl_priv
) {
2207 IWL_DEBUG_RATE("leave - no private rate data!\n");
2209 IWL_DEBUG_RATE("leave - no station!\n");
2210 return sprintf(buf
, "station %d not found\n", sta_id
);
2213 rs_priv
= (void *)sta
->rate_ctrl_priv
;
2215 lq_type
= rs_priv
->lq_info
[rs_priv
->active_tbl
].lq_type
;
2216 antenna
= rs_priv
->lq_info
[rs_priv
->active_tbl
].antenna_type
;
2218 if (is_legacy(lq_type
))
2219 i
= IWL_RATE_54M_INDEX
;
2221 i
= IWL_RATE_60M_INDEX
;
2225 int active
= rs_priv
->active_tbl
;
2228 sprintf(&buf
[count
], " %2dMbs: ", iwl_rates
[i
].ieee
/ 2);
2230 mask
= (1ULL << (IWL_RATE_MAX_WINDOW
- 1));
2231 for (j
= 0; j
< IWL_RATE_MAX_WINDOW
; j
++, mask
>>= 1)
2233 (rs_priv
->lq_info
[active
].win
[i
].data
& mask
)
2236 samples
+= rs_priv
->lq_info
[active
].win
[i
].counter
;
2237 good
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
;
2238 success
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
*
2241 if (rs_priv
->lq_info
[active
].win
[i
].stamp
) {
2243 jiffies_to_msecs(now
-
2244 rs_priv
->lq_info
[active
].win
[i
].stamp
);
2246 if (delta
> max_time
)
2249 count
+= sprintf(&buf
[count
], "%5dms\n", delta
);
2251 buf
[count
++] = '\n';
2253 j
= iwl_get_prev_ieee_rate(i
);
2259 /* Display the average rate of all samples taken.
2261 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2262 * added from iwl_rates is actually 2X the rate */
2264 count
+= sprintf(&buf
[count
],
2265 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2266 "%3d%% success (%d good packets over %d tries)\n",
2267 success
/ (2 * samples
), (success
* 5 / samples
) % 10,
2268 max_time
, good
* 100 / samples
, good
, samples
);
2270 count
+= sprintf(&buf
[count
], "\nAverage rate: 0Mbs\n");
2271 count
+= sprintf(&buf
[count
], "\nrate scale type %d anntena %d "
2272 "active_search %d rate index %d\n", lq_type
, antenna
,
2273 rs_priv
->search_better_tbl
, sta
->last_txrate
);
2279 void iwl_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
2281 struct iwl_priv
*priv
= hw
->priv
;
2283 priv
->lq_mngr
.lq_ready
= 1;
2286 void iwl_rate_control_register(struct ieee80211_hw
*hw
)
2288 ieee80211_rate_control_register(&rs_ops
);
2291 void iwl_rate_control_unregister(struct ieee80211_hw
*hw
)
2293 ieee80211_rate_control_unregister(&rs_ops
);