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/ieee80211_rate.h"
42 #include "iwl-helpers.h"
44 #define RS_NAME "iwl-4965-rs"
46 #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
47 #define IWL_NUMBER_TRY 1
48 #define IWL_HT_NUMBER_TRY 3
50 #define IWL_RATE_MAX_WINDOW 62
51 #define IWL_RATE_HIGH_TH 10880
52 #define IWL_RATE_MIN_FAILURE_TH 6
53 #define IWL_RATE_MIN_SUCCESS_TH 8
54 #define IWL_RATE_DECREASE_TH 1920
55 #define IWL_RATE_INCREASE_TH 8960
56 #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */
58 static u8 rs_ht_to_legacy
[] = {
59 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
60 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
62 IWL_RATE_6M_INDEX
, IWL_RATE_9M_INDEX
,
63 IWL_RATE_12M_INDEX
, IWL_RATE_18M_INDEX
,
64 IWL_RATE_24M_INDEX
, IWL_RATE_36M_INDEX
,
65 IWL_RATE_48M_INDEX
, IWL_RATE_54M_INDEX
70 } __attribute__ ((packed
));
72 struct iwl_rate_scale_data
{
81 struct iwl_scale_tbl_info
{
82 enum iwl_table_type lq_type
;
83 enum iwl_antenna_type antenna_type
;
89 struct iwl_rate current_rate
;
90 struct iwl_rate_scale_data win
[IWL_RATE_COUNT
];
93 struct iwl_rate_scale_priv
{
99 u32 table_count_limit
;
100 u32 max_failure_limit
;
101 u32 max_success_limit
;
115 u16 active_siso_rate
;
116 u16 active_mimo_rate
;
117 u16 active_rate_basic
;
118 struct iwl_link_quality_cmd lq
;
119 struct iwl_scale_tbl_info lq_info
[LQ_SIZE
];
120 #ifdef CONFIG_MAC80211_DEBUGFS
121 struct dentry
*rs_sta_dbgfs_scale_table_file
;
122 struct dentry
*rs_sta_dbgfs_stats_table_file
;
123 struct iwl_rate dbg_fixed
;
124 struct iwl_priv
*drv
;
128 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
129 struct net_device
*dev
,
130 struct ieee80211_hdr
*hdr
,
131 struct sta_info
*sta
);
132 static void rs_fill_link_cmd(struct iwl_rate_scale_priv
*lq_data
,
133 struct iwl_rate
*tx_mcs
,
134 struct iwl_link_quality_cmd
*tbl
);
137 #ifdef CONFIG_MAC80211_DEBUGFS
138 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
139 struct iwl_rate
*mcs
, int index
);
141 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
142 struct iwl_rate
*mcs
, int index
)
145 static s32 expected_tpt_A
[IWL_RATE_COUNT
] = {
146 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
149 static s32 expected_tpt_G
[IWL_RATE_COUNT
] = {
150 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
153 static s32 expected_tpt_siso20MHz
[IWL_RATE_COUNT
] = {
154 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
157 static s32 expected_tpt_siso20MHzSGI
[IWL_RATE_COUNT
] = {
158 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
161 static s32 expected_tpt_mimo20MHz
[IWL_RATE_COUNT
] = {
162 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
165 static s32 expected_tpt_mimo20MHzSGI
[IWL_RATE_COUNT
] = {
166 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
169 static s32 expected_tpt_siso40MHz
[IWL_RATE_COUNT
] = {
170 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
173 static s32 expected_tpt_siso40MHzSGI
[IWL_RATE_COUNT
] = {
174 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
177 static s32 expected_tpt_mimo40MHz
[IWL_RATE_COUNT
] = {
178 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
181 static s32 expected_tpt_mimo40MHzSGI
[IWL_RATE_COUNT
] = {
182 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
185 static int iwl_lq_sync_callback(struct iwl_priv
*priv
,
186 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
188 /*We didn't cache the SKB; let the caller free it */
192 static inline u8
iwl_rate_get_rate(u32 rate_n_flags
)
194 return (u8
)(rate_n_flags
& 0xFF);
197 static int rs_send_lq_cmd(struct iwl_priv
*priv
,
198 struct iwl_link_quality_cmd
*lq
, u8 flags
)
200 #ifdef CONFIG_IWLWIFI_DEBUG
203 struct iwl_host_cmd cmd
= {
204 .id
= REPLY_TX_LINK_QUALITY_CMD
,
205 .len
= sizeof(struct iwl_link_quality_cmd
),
210 if ((lq
->sta_id
== 0xFF) &&
211 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
214 if (lq
->sta_id
== 0xFF)
215 lq
->sta_id
= IWL_AP_ID
;
217 IWL_DEBUG_RATE("lq station id 0x%x\n", lq
->sta_id
);
218 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
219 lq
->general_params
.single_stream_ant_msk
,
220 lq
->general_params
.dual_stream_ant_msk
);
221 #ifdef CONFIG_IWLWIFI_DEBUG
222 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
223 IWL_DEBUG_RATE("lq index %d 0x%X\n",
224 i
, lq
->rs_table
[i
].rate_n_flags
);
227 if (flags
& CMD_ASYNC
)
228 cmd
.meta
.u
.callback
= iwl_lq_sync_callback
;
230 if (iwl_is_associated(priv
) && priv
->assoc_station_added
&&
231 priv
->lq_mngr
.lq_ready
)
232 return iwl_send_cmd(priv
, &cmd
);
237 static void rs_rate_scale_clear_window(struct iwl_rate_scale_data
*window
)
240 window
->success_counter
= 0;
241 window
->success_ratio
= IWL_INVALID_VALUE
;
243 window
->average_tpt
= IWL_INVALID_VALUE
;
247 static int rs_collect_tx_data(struct iwl_rate_scale_data
*windows
,
248 int scale_index
, s32 tpt
, u32 status
)
250 struct iwl_rate_scale_data
*window
= NULL
;
252 u8 win_size
= IWL_RATE_MAX_WINDOW
;
255 if (scale_index
< 0 || scale_index
>= IWL_RATE_COUNT
)
258 window
= &(windows
[scale_index
]);
260 if (window
->counter
>= win_size
) {
262 window
->counter
= win_size
- 1;
264 mask
= (mask
<< (win_size
- 1));
265 if ((window
->data
& mask
)) {
266 window
->data
&= ~mask
;
267 window
->success_counter
= window
->success_counter
- 1;
271 window
->counter
= window
->counter
+ 1;
273 window
->data
= (mask
<< 1);
275 window
->success_counter
= window
->success_counter
+ 1;
279 if (window
->counter
> 0)
280 window
->success_ratio
= 128 * (100 * window
->success_counter
)
283 window
->success_ratio
= IWL_INVALID_VALUE
;
285 fail_count
= window
->counter
- window
->success_counter
;
287 if ((fail_count
>= IWL_RATE_MIN_FAILURE_TH
) ||
288 (window
->success_counter
>= IWL_RATE_MIN_SUCCESS_TH
))
289 window
->average_tpt
= (window
->success_ratio
* tpt
+ 64) / 128;
291 window
->average_tpt
= IWL_INVALID_VALUE
;
293 window
->stamp
= jiffies
;
298 static void rs_mcs_from_tbl(struct iwl_rate
*mcs_rate
,
299 struct iwl_scale_tbl_info
*tbl
,
300 int index
, u8 use_green
)
302 if (is_legacy(tbl
->lq_type
)) {
303 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp
;
304 if (index
>= IWL_FIRST_CCK_RATE
&& index
<= IWL_LAST_CCK_RATE
)
305 mcs_rate
->rate_n_flags
|= RATE_MCS_CCK_MSK
;
307 } else if (is_siso(tbl
->lq_type
)) {
308 if (index
> IWL_LAST_OFDM_RATE
)
309 index
= IWL_LAST_OFDM_RATE
;
310 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp_siso
|
313 if (index
> IWL_LAST_OFDM_RATE
)
314 index
= IWL_LAST_OFDM_RATE
;
315 mcs_rate
->rate_n_flags
= iwl_rates
[index
].plcp_mimo
|
319 switch (tbl
->antenna_type
) {
321 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_AB_MSK
;
324 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_A_MSK
;
327 mcs_rate
->rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
333 if (is_legacy(tbl
->lq_type
))
338 mcs_rate
->rate_n_flags
|= RATE_MCS_DUP_MSK
;
340 mcs_rate
->rate_n_flags
|= RATE_MCS_FAT_MSK
;
343 mcs_rate
->rate_n_flags
|= RATE_MCS_SGI_MSK
;
346 mcs_rate
->rate_n_flags
|= RATE_MCS_GF_MSK
;
347 if (is_siso(tbl
->lq_type
))
348 mcs_rate
->rate_n_flags
&= ~RATE_MCS_SGI_MSK
;
352 static int rs_get_tbl_info_from_mcs(const struct iwl_rate
*mcs_rate
,
353 int phymode
, struct iwl_scale_tbl_info
*tbl
,
359 index
= iwl_rate_index_from_plcp(mcs_rate
->rate_n_flags
);
361 if (index
== IWL_RATE_INVALID
) {
368 tbl
->antenna_type
= ANT_BOTH
;
370 if (!(mcs_rate
->rate_n_flags
& RATE_MCS_HT_MSK
)) {
371 ant_msk
= (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_AB_MSK
);
373 if (ant_msk
== RATE_MCS_ANT_AB_MSK
)
374 tbl
->lq_type
= LQ_NONE
;
377 if (phymode
== MODE_IEEE80211A
)
382 if (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_A_MSK
)
383 tbl
->antenna_type
= ANT_MAIN
;
385 tbl
->antenna_type
= ANT_AUX
;
389 } else if (iwl_rate_get_rate(mcs_rate
->rate_n_flags
)
390 <= IWL_RATE_SISO_60M_PLCP
) {
391 tbl
->lq_type
= LQ_SISO
;
393 ant_msk
= (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_AB_MSK
);
394 if (ant_msk
== RATE_MCS_ANT_AB_MSK
)
395 tbl
->lq_type
= LQ_NONE
;
397 if (mcs_rate
->rate_n_flags
& RATE_MCS_ANT_A_MSK
)
398 tbl
->antenna_type
= ANT_MAIN
;
400 tbl
->antenna_type
= ANT_AUX
;
402 if (mcs_rate
->rate_n_flags
& RATE_MCS_SGI_MSK
)
405 if ((mcs_rate
->rate_n_flags
& RATE_MCS_FAT_MSK
) ||
406 (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
))
409 if (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
)
414 tbl
->lq_type
= LQ_MIMO
;
415 if (mcs_rate
->rate_n_flags
& RATE_MCS_SGI_MSK
)
418 if ((mcs_rate
->rate_n_flags
& RATE_MCS_FAT_MSK
) ||
419 (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
))
422 if (mcs_rate
->rate_n_flags
& RATE_MCS_DUP_MSK
)
429 static inline void rs_toggle_antenna(struct iwl_rate
*new_rate
,
430 struct iwl_scale_tbl_info
*tbl
)
432 if (tbl
->antenna_type
== ANT_AUX
) {
433 tbl
->antenna_type
= ANT_MAIN
;
434 new_rate
->rate_n_flags
&= ~RATE_MCS_ANT_B_MSK
;
435 new_rate
->rate_n_flags
|= RATE_MCS_ANT_A_MSK
;
437 tbl
->antenna_type
= ANT_AUX
;
438 new_rate
->rate_n_flags
&= ~RATE_MCS_ANT_A_MSK
;
439 new_rate
->rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
443 static inline u8
rs_use_green(struct iwl_priv
*priv
)
445 #ifdef CONFIG_IWLWIFI_HT
446 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
449 return ((priv
->current_assoc_ht
.is_green_field
) &&
450 !(priv
->current_assoc_ht
.operating_mode
& 0x4));
451 #endif /*CONFIG_IWLWIFI_HT */
456 * rs_get_supported_rates - get the available rates
458 * if management frame or broadcast frame only return
459 * basic available rates.
462 static void rs_get_supported_rates(struct iwl_rate_scale_priv
*lq_data
,
463 struct ieee80211_hdr
*hdr
,
464 enum iwl_table_type rate_type
,
467 if (is_legacy(rate_type
))
468 *data_rate
= lq_data
->active_rate
;
470 if (is_siso(rate_type
))
471 *data_rate
= lq_data
->active_siso_rate
;
473 *data_rate
= lq_data
->active_mimo_rate
;
476 if (hdr
&& is_multicast_ether_addr(hdr
->addr1
) &&
477 lq_data
->active_rate_basic
)
478 *data_rate
= lq_data
->active_rate_basic
;
481 static u16
rs_get_adjacent_rate(u8 index
, u16 rate_mask
, int rate_type
)
483 u8 high
= IWL_RATE_INVALID
;
484 u8 low
= IWL_RATE_INVALID
;
486 /* 802.11A or ht walks to the next literal adjacent rate in
488 if (is_a_band(rate_type
) || !is_legacy(rate_type
)) {
492 /* Find the previous rate that is in the rate mask */
494 for (mask
= (1 << i
); i
>= 0; i
--, mask
>>= 1) {
495 if (rate_mask
& mask
) {
501 /* Find the next rate that is in the rate mask */
503 for (mask
= (1 << i
); i
< IWL_RATE_COUNT
; i
++, mask
<<= 1) {
504 if (rate_mask
& mask
) {
510 return (high
<< 8) | low
;
514 while (low
!= IWL_RATE_INVALID
) {
515 low
= iwl_rates
[low
].prev_rs
;
516 if (low
== IWL_RATE_INVALID
)
518 if (rate_mask
& (1 << low
))
520 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low
);
524 while (high
!= IWL_RATE_INVALID
) {
525 high
= iwl_rates
[high
].next_rs
;
526 if (high
== IWL_RATE_INVALID
)
528 if (rate_mask
& (1 << high
))
530 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high
);
533 return (high
<< 8) | low
;
536 static void rs_get_lower_rate(struct iwl_rate_scale_priv
*lq_data
,
537 struct iwl_scale_tbl_info
*tbl
, u8 scale_index
,
538 u8 ht_possible
, struct iwl_rate
*mcs_rate
)
543 u8 switch_to_legacy
= 0;
544 u8 is_green
= lq_data
->is_green
;
546 /* check if we need to switch from HT to legacy rates.
547 * assumption is that mandatory rates (1Mbps or 6Mbps)
548 * are always supported (spec demand) */
549 if (!is_legacy(tbl
->lq_type
) && (!ht_possible
|| !scale_index
)) {
550 switch_to_legacy
= 1;
551 scale_index
= rs_ht_to_legacy
[scale_index
];
552 if (lq_data
->phymode
== MODE_IEEE80211A
)
557 if ((tbl
->antenna_type
== ANT_BOTH
) ||
558 (tbl
->antenna_type
== ANT_NONE
))
559 tbl
->antenna_type
= ANT_MAIN
;
565 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
, &rate_mask
);
567 /* mask with station rate restriction */
568 if (is_legacy(tbl
->lq_type
)) {
569 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
570 rate_mask
= (u16
)(rate_mask
&
571 (lq_data
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
573 rate_mask
= (u16
)(rate_mask
& lq_data
->supp_rates
);
576 /* if we did switched from HT to legacy check current rate */
577 if (switch_to_legacy
&& (rate_mask
& (1 << scale_index
))) {
578 rs_mcs_from_tbl(mcs_rate
, tbl
, scale_index
, is_green
);
582 high_low
= rs_get_adjacent_rate(scale_index
, rate_mask
, tbl
->lq_type
);
583 low
= high_low
& 0xff;
585 if (low
!= IWL_RATE_INVALID
)
586 rs_mcs_from_tbl(mcs_rate
, tbl
, low
, is_green
);
588 rs_mcs_from_tbl(mcs_rate
, tbl
, scale_index
, is_green
);
591 static void rs_tx_status(void *priv_rate
,
592 struct net_device
*dev
,
594 struct ieee80211_tx_status
*tx_resp
)
598 int rs_index
, index
= 0;
599 struct iwl_rate_scale_priv
*lq
;
600 struct iwl_link_quality_cmd
*table
;
601 struct sta_info
*sta
;
602 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
603 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
604 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
605 struct iwl_rate_scale_data
*window
= NULL
;
606 struct iwl_rate_scale_data
*search_win
= NULL
;
607 struct iwl_rate tx_mcs
;
608 struct iwl_scale_tbl_info tbl_type
;
609 struct iwl_scale_tbl_info
*curr_tbl
, *search_tbl
;
611 u16 fc
= le16_to_cpu(hdr
->frame_control
);
614 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
616 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
))
619 retries
= tx_resp
->retry_count
;
625 sta
= sta_info_get(local
, hdr
->addr1
);
627 if (!sta
|| !sta
->rate_ctrl_priv
) {
633 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
635 if (!priv
->lq_mngr
.lq_ready
)
638 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) && !lq
->ibss_sta_added
)
642 active_index
= lq
->active_tbl
;
644 lq
->antenna
= (lq
->valid_antenna
& local
->hw
.conf
.antenna_sel_tx
);
646 lq
->antenna
= lq
->valid_antenna
;
648 lq
->antenna
= lq
->valid_antenna
;
649 curr_tbl
= &(lq
->lq_info
[active_index
]);
650 search_tbl
= &(lq
->lq_info
[(1 - active_index
)]);
651 window
= (struct iwl_rate_scale_data
*)
653 search_win
= (struct iwl_rate_scale_data
*)
654 &(search_tbl
->win
[0]);
656 tx_mcs
.rate_n_flags
= tx_resp
->control
.tx_rate
;
658 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
659 &tbl_type
, &rs_index
);
660 if ((rs_index
< 0) || (rs_index
>= IWL_RATE_COUNT
)) {
661 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
662 rs_index
, tx_mcs
.rate_n_flags
);
668 (tx_mcs
.rate_n_flags
!=
669 le32_to_cpu(table
->rs_table
[0].rate_n_flags
))) {
670 IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
672 le32_to_cpu(table
->rs_table
[0].rate_n_flags
));
678 tx_mcs
.rate_n_flags
=
679 le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
680 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
681 &tbl_type
, &rs_index
);
683 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
684 (tbl_type
.antenna_type
== search_tbl
->antenna_type
) &&
685 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
686 if (search_tbl
->expected_tpt
)
687 tpt
= search_tbl
->expected_tpt
[rs_index
];
690 rs_collect_tx_data(search_win
,
692 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
693 (tbl_type
.antenna_type
== curr_tbl
->antenna_type
) &&
694 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
695 if (curr_tbl
->expected_tpt
)
696 tpt
= curr_tbl
->expected_tpt
[rs_index
];
699 rs_collect_tx_data(window
, rs_index
, tpt
, 0);
708 if (!tx_resp
->retry_count
)
709 tx_mcs
.rate_n_flags
= tx_resp
->control
.tx_rate
;
711 tx_mcs
.rate_n_flags
=
712 le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
714 rs_get_tbl_info_from_mcs(&tx_mcs
, priv
->phymode
,
715 &tbl_type
, &rs_index
);
717 if (tx_resp
->flags
& IEEE80211_TX_STATUS_ACK
)
722 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
723 (tbl_type
.antenna_type
== search_tbl
->antenna_type
) &&
724 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
725 if (search_tbl
->expected_tpt
)
726 tpt
= search_tbl
->expected_tpt
[rs_index
];
729 rs_collect_tx_data(search_win
,
730 rs_index
, tpt
, status
);
731 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
732 (tbl_type
.antenna_type
== curr_tbl
->antenna_type
) &&
733 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
734 if (curr_tbl
->expected_tpt
)
735 tpt
= curr_tbl
->expected_tpt
[rs_index
];
738 rs_collect_tx_data(window
, rs_index
, tpt
, status
);
741 if (lq
->stay_in_tbl
) {
748 rs_rate_scale_perform(priv
, dev
, hdr
, sta
);
753 static u8
rs_is_ant_connected(u8 valid_antenna
,
754 enum iwl_antenna_type antenna_type
)
756 if (antenna_type
== ANT_AUX
)
757 return ((valid_antenna
& 0x2) ? 1:0);
758 else if (antenna_type
== ANT_MAIN
)
759 return ((valid_antenna
& 0x1) ? 1:0);
760 else if (antenna_type
== ANT_BOTH
)
761 return ((valid_antenna
& 0x3) == 0x3);
766 static u8
rs_is_other_ant_connected(u8 valid_antenna
,
767 enum iwl_antenna_type antenna_type
)
769 if (antenna_type
== ANT_AUX
)
770 return rs_is_ant_connected(valid_antenna
, ANT_MAIN
);
772 return rs_is_ant_connected(valid_antenna
, ANT_AUX
);
777 static void rs_set_stay_in_table(u8 is_legacy
,
778 struct iwl_rate_scale_priv
*lq_data
)
780 IWL_DEBUG_HT("we are staying in the same table\n");
781 lq_data
->stay_in_tbl
= 1;
783 lq_data
->table_count_limit
= IWL_LEGACY_TABLE_COUNT
;
784 lq_data
->max_failure_limit
= IWL_LEGACY_FAILURE_LIMIT
;
785 lq_data
->max_success_limit
= IWL_LEGACY_TABLE_COUNT
;
787 lq_data
->table_count_limit
= IWL_NONE_LEGACY_TABLE_COUNT
;
788 lq_data
->max_failure_limit
= IWL_NONE_LEGACY_FAILURE_LIMIT
;
789 lq_data
->max_success_limit
= IWL_NONE_LEGACY_SUCCESS_LIMIT
;
791 lq_data
->table_count
= 0;
792 lq_data
->total_failed
= 0;
793 lq_data
->total_success
= 0;
796 static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv
*lq_data
,
797 struct iwl_scale_tbl_info
*tbl
)
799 if (is_legacy(tbl
->lq_type
)) {
800 if (!is_a_band(tbl
->lq_type
))
801 tbl
->expected_tpt
= expected_tpt_G
;
803 tbl
->expected_tpt
= expected_tpt_A
;
804 } else if (is_siso(tbl
->lq_type
)) {
805 if (tbl
->is_fat
&& !lq_data
->is_dup
)
807 tbl
->expected_tpt
= expected_tpt_siso40MHzSGI
;
809 tbl
->expected_tpt
= expected_tpt_siso40MHz
;
810 else if (tbl
->is_SGI
)
811 tbl
->expected_tpt
= expected_tpt_siso20MHzSGI
;
813 tbl
->expected_tpt
= expected_tpt_siso20MHz
;
815 } else if (is_mimo(tbl
->lq_type
)) {
816 if (tbl
->is_fat
&& !lq_data
->is_dup
)
818 tbl
->expected_tpt
= expected_tpt_mimo40MHzSGI
;
820 tbl
->expected_tpt
= expected_tpt_mimo40MHz
;
821 else if (tbl
->is_SGI
)
822 tbl
->expected_tpt
= expected_tpt_mimo20MHzSGI
;
824 tbl
->expected_tpt
= expected_tpt_mimo20MHz
;
826 tbl
->expected_tpt
= expected_tpt_G
;
829 #ifdef CONFIG_IWLWIFI_HT
830 static s32
rs_get_best_rate(struct iwl_priv
*priv
,
831 struct iwl_rate_scale_priv
*lq_data
,
832 struct iwl_scale_tbl_info
*tbl
,
833 u16 rate_mask
, s8 index
, s8 rate
)
835 struct iwl_scale_tbl_info
*active_tbl
=
836 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
837 s32 new_rate
, high
, low
, start_hi
;
838 s32 active_sr
= active_tbl
->win
[index
].success_ratio
;
839 s32
*tpt_tbl
= tbl
->expected_tpt
;
840 s32 active_tpt
= active_tbl
->expected_tpt
[index
];
843 new_rate
= high
= low
= start_hi
= IWL_RATE_INVALID
;
846 high_low
= rs_get_adjacent_rate(rate
, rate_mask
, tbl
->lq_type
);
848 low
= high_low
& 0xff;
849 high
= (high_low
>> 8) & 0xff;
851 if ((((100 * tpt_tbl
[rate
]) > lq_data
->last_tpt
) &&
852 ((active_sr
> IWL_RATE_DECREASE_TH
) &&
853 (active_sr
<= IWL_RATE_HIGH_TH
) &&
854 (tpt_tbl
[rate
] <= active_tpt
))) ||
855 ((active_sr
>= IWL_RATE_SCALE_SWITCH
) &&
856 (tpt_tbl
[rate
] > active_tpt
))) {
858 if (start_hi
!= IWL_RATE_INVALID
) {
863 if (low
!= IWL_RATE_INVALID
)
868 if (new_rate
!= IWL_RATE_INVALID
)
870 else if (high
!= IWL_RATE_INVALID
) {
882 #endif /* CONFIG_IWLWIFI_HT */
884 static inline u8
rs_is_both_ant_supp(u8 valid_antenna
)
886 return (rs_is_ant_connected(valid_antenna
, ANT_BOTH
));
889 static int rs_switch_to_mimo(struct iwl_priv
*priv
,
890 struct iwl_rate_scale_priv
*lq_data
,
891 struct iwl_scale_tbl_info
*tbl
, int index
)
893 #ifdef CONFIG_IWLWIFI_HT
896 s8 is_green
= lq_data
->is_green
;
898 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
901 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
902 tbl
->lq_type
= LQ_MIMO
;
903 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
,
906 if (priv
->current_assoc_ht
.tx_mimo_ps_mode
== IWL_MIMO_PS_STATIC
)
909 if (!rs_is_both_ant_supp(lq_data
->antenna
))
912 tbl
->is_dup
= lq_data
->is_dup
;
914 if (priv
->current_channel_width
== IWL_CHANNEL_WIDTH_40MHZ
)
920 if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_40MHZ_ONLY
)
924 } else if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_20MHZ_ONLY
)
929 rs_get_expected_tpt_table(lq_data
, tbl
);
931 rate
= rs_get_best_rate(priv
, lq_data
, tbl
, rate_mask
, index
, index
);
933 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate
, rate_mask
);
934 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
))
936 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, rate
, is_green
);
938 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
939 tbl
->current_rate
.rate_n_flags
, is_green
);
941 #endif /*CONFIG_IWLWIFI_HT */
945 static int rs_switch_to_siso(struct iwl_priv
*priv
,
946 struct iwl_rate_scale_priv
*lq_data
,
947 struct iwl_scale_tbl_info
*tbl
, int index
)
949 #ifdef CONFIG_IWLWIFI_HT
951 u8 is_green
= lq_data
->is_green
;
954 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
955 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
958 tbl
->is_dup
= lq_data
->is_dup
;
959 tbl
->lq_type
= LQ_SISO
;
961 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
,
964 if (priv
->current_channel_width
== IWL_CHANNEL_WIDTH_40MHZ
)
970 if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_40MHZ_ONLY
)
974 } else if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_20MHZ_ONLY
)
982 rs_get_expected_tpt_table(lq_data
, tbl
);
983 rate
= rs_get_best_rate(priv
, lq_data
, tbl
, rate_mask
, index
, index
);
985 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate
, rate_mask
);
986 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
987 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
991 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, rate
, is_green
);
992 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
993 tbl
->current_rate
.rate_n_flags
, is_green
);
995 #endif /*CONFIG_IWLWIFI_HT */
999 static int rs_move_legacy_other(struct iwl_priv
*priv
,
1000 struct iwl_rate_scale_priv
*lq_data
,
1004 struct iwl_scale_tbl_info
*tbl
=
1005 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1006 struct iwl_scale_tbl_info
*search_tbl
=
1007 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1008 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1009 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1010 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1011 u8 start_action
= tbl
->action
;
1014 switch (tbl
->action
) {
1015 case IWL_LEGACY_SWITCH_ANTENNA
:
1016 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1018 search_tbl
->lq_type
= LQ_NONE
;
1019 lq_data
->action_counter
++;
1020 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1022 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1026 memcpy(search_tbl
, tbl
, sz
);
1028 rs_toggle_antenna(&(search_tbl
->current_rate
),
1030 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1031 lq_data
->search_better_tbl
= 1;
1034 case IWL_LEGACY_SWITCH_SISO
:
1035 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1036 memcpy(search_tbl
, tbl
, sz
);
1037 search_tbl
->lq_type
= LQ_SISO
;
1038 search_tbl
->is_SGI
= 0;
1039 search_tbl
->is_fat
= 0;
1040 ret
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1043 lq_data
->search_better_tbl
= 1;
1044 lq_data
->action_counter
= 0;
1049 case IWL_LEGACY_SWITCH_MIMO
:
1050 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1051 memcpy(search_tbl
, tbl
, sz
);
1052 search_tbl
->lq_type
= LQ_MIMO
;
1053 search_tbl
->is_SGI
= 0;
1054 search_tbl
->is_fat
= 0;
1055 search_tbl
->antenna_type
= ANT_BOTH
;
1056 ret
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1059 lq_data
->search_better_tbl
= 1;
1060 lq_data
->action_counter
= 0;
1066 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1067 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1069 if (tbl
->action
== start_action
)
1077 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1078 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1083 static int rs_move_siso_to_other(struct iwl_priv
*priv
,
1084 struct iwl_rate_scale_priv
*lq_data
,
1088 u8 is_green
= lq_data
->is_green
;
1089 struct iwl_scale_tbl_info
*tbl
=
1090 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1091 struct iwl_scale_tbl_info
*search_tbl
=
1092 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1093 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1094 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1095 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1096 u8 start_action
= tbl
->action
;
1099 lq_data
->action_counter
++;
1100 switch (tbl
->action
) {
1101 case IWL_SISO_SWITCH_ANTENNA
:
1102 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1103 search_tbl
->lq_type
= LQ_NONE
;
1104 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1106 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1110 memcpy(search_tbl
, tbl
, sz
);
1111 search_tbl
->action
= IWL_SISO_SWITCH_MIMO
;
1112 rs_toggle_antenna(&(search_tbl
->current_rate
),
1114 lq_data
->search_better_tbl
= 1;
1118 case IWL_SISO_SWITCH_MIMO
:
1119 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1120 memcpy(search_tbl
, tbl
, sz
);
1121 search_tbl
->lq_type
= LQ_MIMO
;
1122 search_tbl
->is_SGI
= 0;
1123 search_tbl
->is_fat
= 0;
1124 search_tbl
->antenna_type
= ANT_BOTH
;
1125 ret
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1128 lq_data
->search_better_tbl
= 1;
1132 case IWL_SISO_SWITCH_GI
:
1133 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1134 memcpy(search_tbl
, tbl
, sz
);
1135 search_tbl
->action
= 0;
1136 if (search_tbl
->is_SGI
)
1137 search_tbl
->is_SGI
= 0;
1139 search_tbl
->is_SGI
= 1;
1142 lq_data
->search_better_tbl
= 1;
1143 if ((tbl
->lq_type
== LQ_SISO
) &&
1145 s32 tpt
= lq_data
->last_tpt
/ 100;
1146 if (((!tbl
->is_fat
) &&
1147 (tpt
>= expected_tpt_siso20MHz
[index
])) ||
1149 (tpt
>= expected_tpt_siso40MHz
[index
])))
1150 lq_data
->search_better_tbl
= 0;
1152 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1153 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1154 search_tbl
, index
, is_green
);
1158 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1159 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1161 if (tbl
->action
== start_action
)
1168 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1169 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1173 static int rs_move_mimo_to_other(struct iwl_priv
*priv
,
1174 struct iwl_rate_scale_priv
*lq_data
,
1178 s8 is_green
= lq_data
->is_green
;
1179 struct iwl_scale_tbl_info
*tbl
=
1180 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1181 struct iwl_scale_tbl_info
*search_tbl
=
1182 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1183 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1184 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1185 u8 start_action
= tbl
->action
;
1188 lq_data
->action_counter
++;
1189 switch (tbl
->action
) {
1190 case IWL_MIMO_SWITCH_ANTENNA_A
:
1191 case IWL_MIMO_SWITCH_ANTENNA_B
:
1192 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1193 memcpy(search_tbl
, tbl
, sz
);
1194 search_tbl
->lq_type
= LQ_SISO
;
1195 search_tbl
->is_SGI
= 0;
1196 search_tbl
->is_fat
= 0;
1197 if (tbl
->action
== IWL_MIMO_SWITCH_ANTENNA_A
)
1198 search_tbl
->antenna_type
= ANT_MAIN
;
1200 search_tbl
->antenna_type
= ANT_AUX
;
1202 ret
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1205 lq_data
->search_better_tbl
= 1;
1210 case IWL_MIMO_SWITCH_GI
:
1211 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1212 memcpy(search_tbl
, tbl
, sz
);
1213 search_tbl
->lq_type
= LQ_MIMO
;
1214 search_tbl
->antenna_type
= ANT_BOTH
;
1215 search_tbl
->action
= 0;
1216 if (search_tbl
->is_SGI
)
1217 search_tbl
->is_SGI
= 0;
1219 search_tbl
->is_SGI
= 1;
1220 lq_data
->search_better_tbl
= 1;
1221 if ((tbl
->lq_type
== LQ_MIMO
) &&
1223 s32 tpt
= lq_data
->last_tpt
/ 100;
1224 if (((!tbl
->is_fat
) &&
1225 (tpt
>= expected_tpt_mimo20MHz
[index
])) ||
1227 (tpt
>= expected_tpt_mimo40MHz
[index
])))
1228 lq_data
->search_better_tbl
= 0;
1230 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1231 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1232 search_tbl
, index
, is_green
);
1237 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1238 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1240 if (tbl
->action
== start_action
)
1247 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1248 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1253 static void rs_stay_in_table(struct iwl_rate_scale_priv
*lq_data
)
1255 struct iwl_scale_tbl_info
*tbl
;
1258 int flush_interval_passed
= 0;
1260 active_tbl
= lq_data
->active_tbl
;
1262 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1264 if (lq_data
->stay_in_tbl
) {
1266 if (lq_data
->flush_timer
)
1267 flush_interval_passed
=
1269 (unsigned long)(lq_data
->flush_timer
+
1270 IWL_RATE_SCALE_FLUSH_INTVL
));
1272 flush_interval_passed
= 0;
1273 if ((lq_data
->total_failed
> lq_data
->max_failure_limit
) ||
1274 (lq_data
->total_success
> lq_data
->max_success_limit
) ||
1275 ((!lq_data
->search_better_tbl
) && (lq_data
->flush_timer
)
1276 && (flush_interval_passed
))) {
1277 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1278 lq_data
->total_failed
,
1279 lq_data
->total_success
,
1280 flush_interval_passed
);
1281 lq_data
->stay_in_tbl
= 0;
1282 lq_data
->total_failed
= 0;
1283 lq_data
->total_success
= 0;
1284 lq_data
->flush_timer
= 0;
1285 } else if (lq_data
->table_count
> 0) {
1286 lq_data
->table_count
++;
1287 if (lq_data
->table_count
>=
1288 lq_data
->table_count_limit
) {
1289 lq_data
->table_count
= 0;
1291 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1292 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1293 rs_rate_scale_clear_window(
1298 if (!lq_data
->stay_in_tbl
) {
1299 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1300 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1305 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
1306 struct net_device
*dev
,
1307 struct ieee80211_hdr
*hdr
,
1308 struct sta_info
*sta
)
1310 int low
= IWL_RATE_INVALID
;
1311 int high
= IWL_RATE_INVALID
;
1314 struct iwl_rate_scale_data
*window
= NULL
;
1315 int current_tpt
= IWL_INVALID_VALUE
;
1316 int low_tpt
= IWL_INVALID_VALUE
;
1317 int high_tpt
= IWL_INVALID_VALUE
;
1319 s8 scale_action
= 0;
1322 struct iwl_rate_scale_priv
*lq_data
;
1323 struct iwl_scale_tbl_info
*tbl
, *tbl1
;
1324 u16 rate_scale_index_msk
= 0;
1325 struct iwl_rate mcs_rate
;
1331 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1333 fc
= le16_to_cpu(hdr
->frame_control
);
1334 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
)) {
1335 /* Send management frames and broadcast/multicast data using
1337 /* TODO: this could probably be improved.. */
1341 if (!sta
|| !sta
->rate_ctrl_priv
)
1344 if (!priv
->lq_mngr
.lq_ready
) {
1345 IWL_DEBUG_RATE("still rate scaling not ready\n");
1348 lq_data
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1350 if (!lq_data
->search_better_tbl
)
1351 active_tbl
= lq_data
->active_tbl
;
1353 active_tbl
= 1 - lq_data
->active_tbl
;
1355 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1356 is_green
= lq_data
->is_green
;
1358 index
= sta
->last_txrate
;
1360 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index
,
1363 rs_get_supported_rates(lq_data
, hdr
, tbl
->lq_type
,
1366 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask
);
1368 /* mask with station rate restriction */
1369 if (is_legacy(tbl
->lq_type
)) {
1370 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1371 rate_scale_index_msk
= (u16
) (rate_mask
&
1372 (lq_data
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
1374 rate_scale_index_msk
= (u16
) (rate_mask
&
1375 lq_data
->supp_rates
);
1378 rate_scale_index_msk
= rate_mask
;
1380 if (!rate_scale_index_msk
)
1381 rate_scale_index_msk
= rate_mask
;
1383 if (index
< 0 || !((1 << index
) & rate_scale_index_msk
)) {
1384 index
= IWL_INVALID_VALUE
;
1387 /* get the lowest available rate */
1388 for (i
= 0; i
<= IWL_RATE_COUNT
; i
++) {
1389 if ((1 << i
) & rate_scale_index_msk
)
1393 if (index
== IWL_INVALID_VALUE
) {
1394 IWL_WARNING("Can not find a suitable rate\n");
1399 if (!tbl
->expected_tpt
)
1400 rs_get_expected_tpt_table(lq_data
, tbl
);
1402 window
= &(tbl
->win
[index
]);
1404 fail_count
= window
->counter
- window
->success_counter
;
1405 if (((fail_count
< IWL_RATE_MIN_FAILURE_TH
) &&
1406 (window
->success_counter
< IWL_RATE_MIN_SUCCESS_TH
))
1407 || (tbl
->expected_tpt
== NULL
)) {
1408 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1410 window
->success_counter
, window
->counter
, index
);
1411 window
->average_tpt
= IWL_INVALID_VALUE
;
1412 rs_stay_in_table(lq_data
);
1414 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1415 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1416 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1421 window
->average_tpt
= ((window
->success_ratio
*
1422 tbl
->expected_tpt
[index
] + 64) / 128);
1424 if (lq_data
->search_better_tbl
) {
1425 int success_limit
= IWL_RATE_SCALE_SWITCH
;
1427 if ((window
->success_ratio
> success_limit
) ||
1428 (window
->average_tpt
> lq_data
->last_tpt
)) {
1429 if (!is_legacy(tbl
->lq_type
)) {
1430 IWL_DEBUG_HT("LQ: we are switching to HT"
1431 " rate suc %d current tpt %d"
1433 window
->success_ratio
,
1434 window
->average_tpt
,
1436 lq_data
->enable_counter
= 1;
1438 lq_data
->active_tbl
= active_tbl
;
1439 current_tpt
= window
->average_tpt
;
1441 tbl
->lq_type
= LQ_NONE
;
1442 active_tbl
= lq_data
->active_tbl
;
1443 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1445 index
= iwl_rate_index_from_plcp(
1446 tbl
->current_rate
.rate_n_flags
);
1449 current_tpt
= lq_data
->last_tpt
;
1450 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1452 lq_data
->search_better_tbl
= 0;
1457 high_low
= rs_get_adjacent_rate(index
, rate_scale_index_msk
,
1459 low
= high_low
& 0xff;
1460 high
= (high_low
>> 8) & 0xff;
1462 current_tpt
= window
->average_tpt
;
1464 if (low
!= IWL_RATE_INVALID
)
1465 low_tpt
= tbl
->win
[low
].average_tpt
;
1467 if (high
!= IWL_RATE_INVALID
)
1468 high_tpt
= tbl
->win
[high
].average_tpt
;
1473 if ((window
->success_ratio
<= IWL_RATE_DECREASE_TH
) ||
1474 (current_tpt
== 0)) {
1475 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1477 } else if ((low_tpt
== IWL_INVALID_VALUE
) &&
1478 (high_tpt
== IWL_INVALID_VALUE
))
1480 else if ((low_tpt
!= IWL_INVALID_VALUE
) &&
1481 (high_tpt
!= IWL_INVALID_VALUE
) &&
1482 (low_tpt
< current_tpt
) &&
1483 (high_tpt
< current_tpt
))
1486 if (high_tpt
!= IWL_INVALID_VALUE
) {
1487 if (high_tpt
> current_tpt
)
1491 ("decrease rate because of high tpt\n");
1494 } else if (low_tpt
!= IWL_INVALID_VALUE
) {
1495 if (low_tpt
> current_tpt
) {
1497 ("decrease rate because of low tpt\n");
1504 if (scale_action
== -1) {
1505 if ((low
!= IWL_RATE_INVALID
) &&
1506 ((window
->success_ratio
> IWL_RATE_HIGH_TH
) ||
1507 (current_tpt
> (100 * tbl
->expected_tpt
[low
]))))
1509 } else if ((scale_action
== 1) &&
1510 (window
->success_ratio
< IWL_RATE_INCREASE_TH
))
1513 switch (scale_action
) {
1515 if (low
!= IWL_RATE_INVALID
) {
1521 if (high
!= IWL_RATE_INVALID
) {
1532 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1533 "high %d type %d\n",
1534 index
, scale_action
, low
, high
, tbl
->lq_type
);
1538 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1539 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1540 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1542 rs_stay_in_table(lq_data
);
1544 if (!update_lq
&& !done_search
&& !lq_data
->stay_in_tbl
) {
1545 lq_data
->last_tpt
= current_tpt
;
1547 if (is_legacy(tbl
->lq_type
))
1548 rs_move_legacy_other(priv
, lq_data
, index
);
1549 else if (is_siso(tbl
->lq_type
))
1550 rs_move_siso_to_other(priv
, lq_data
, index
);
1552 rs_move_mimo_to_other(priv
, lq_data
, index
);
1554 if (lq_data
->search_better_tbl
) {
1555 tbl
= &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1556 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1557 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1559 index
= iwl_rate_index_from_plcp(
1560 tbl
->current_rate
.rate_n_flags
);
1562 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1563 tbl
->current_rate
.rate_n_flags
, index
);
1564 rs_fill_link_cmd(lq_data
, &tbl
->current_rate
,
1566 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1568 tbl1
= &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1570 if (is_legacy(tbl1
->lq_type
) &&
1571 #ifdef CONFIG_IWLWIFI_HT
1572 !priv
->current_assoc_ht
.is_ht
&&
1574 (lq_data
->action_counter
>= 1)) {
1575 lq_data
->action_counter
= 0;
1576 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1577 rs_set_stay_in_table(1, lq_data
);
1580 if (lq_data
->enable_counter
&&
1581 (lq_data
->action_counter
>= IWL_ACTION_LIMIT
)) {
1582 #ifdef CONFIG_IWLWIFI_HT_AGG
1583 if ((lq_data
->last_tpt
> TID_AGG_TPT_THREHOLD
) &&
1584 (priv
->lq_mngr
.agg_ctrl
.auto_agg
)) {
1585 priv
->lq_mngr
.agg_ctrl
.tid_retry
=
1587 schedule_work(&priv
->agg_work
);
1589 #endif /*CONFIG_IWLWIFI_HT_AGG */
1590 lq_data
->action_counter
= 0;
1591 rs_set_stay_in_table(0, lq_data
);
1594 if ((!update_lq
) && (!done_search
) && (!lq_data
->flush_timer
))
1595 lq_data
->flush_timer
= jiffies
;
1599 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, index
, is_green
);
1601 sta
->last_txrate
= i
;
1603 /* sta->txrate is an index to A mode rates which start
1604 * at IWL_FIRST_OFDM_RATE
1606 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1607 sta
->txrate
= i
- IWL_FIRST_OFDM_RATE
;
1615 static void rs_initialize_lq(struct iwl_priv
*priv
,
1616 struct sta_info
*sta
)
1619 struct iwl_rate_scale_priv
*lq
;
1620 struct iwl_scale_tbl_info
*tbl
;
1623 u8 use_green
= rs_use_green(priv
);
1624 struct iwl_rate mcs_rate
;
1626 if (!sta
|| !sta
->rate_ctrl_priv
)
1629 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1630 i
= sta
->last_txrate
;
1632 if ((lq
->lq
.sta_id
== 0xff) &&
1633 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
1636 if (!lq
->search_better_tbl
)
1637 active_tbl
= lq
->active_tbl
;
1639 active_tbl
= 1 - lq
->active_tbl
;
1641 tbl
= &(lq
->lq_info
[active_tbl
]);
1643 if ((i
< 0) || (i
>= IWL_RATE_COUNT
))
1646 mcs_rate
.rate_n_flags
= iwl_rates
[i
].plcp
;
1647 mcs_rate
.rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
1648 mcs_rate
.rate_n_flags
&= ~RATE_MCS_ANT_A_MSK
;
1650 if (i
>= IWL_FIRST_CCK_RATE
&& i
<= IWL_LAST_CCK_RATE
)
1651 mcs_rate
.rate_n_flags
|= RATE_MCS_CCK_MSK
;
1653 tbl
->antenna_type
= ANT_AUX
;
1654 rs_get_tbl_info_from_mcs(&mcs_rate
, priv
->phymode
, tbl
, &rate_idx
);
1655 if (!rs_is_ant_connected(priv
->valid_antenna
, tbl
->antenna_type
))
1656 rs_toggle_antenna(&mcs_rate
, tbl
);
1658 rs_mcs_from_tbl(&mcs_rate
, tbl
, rate_idx
, use_green
);
1659 tbl
->current_rate
.rate_n_flags
= mcs_rate
.rate_n_flags
;
1660 rs_get_expected_tpt_table(lq
, tbl
);
1661 rs_fill_link_cmd(lq
, &mcs_rate
, &lq
->lq
);
1662 rs_send_lq_cmd(priv
, &lq
->lq
, CMD_ASYNC
);
1667 static void rs_get_rate(void *priv_rate
, struct net_device
*dev
,
1668 struct ieee80211_hw_mode
*mode
, struct sk_buff
*skb
,
1669 struct rate_selection
*sel
)
1673 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1674 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1675 struct sta_info
*sta
;
1676 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1677 struct iwl_rate_scale_priv
*lq
;
1679 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1681 sta
= sta_info_get(local
, hdr
->addr1
);
1683 if (!sta
|| !sta
->rate_ctrl_priv
) {
1684 sel
->rate
= rate_lowest(local
, local
->oper_hw_mode
, sta
);
1690 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1691 i
= sta
->last_txrate
;
1693 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) && !lq
->ibss_sta_added
) {
1694 u8 sta_id
= iwl_hw_find_station(priv
, hdr
->addr1
);
1695 DECLARE_MAC_BUF(mac
);
1697 if (sta_id
== IWL_INVALID_STATION
) {
1698 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1699 print_mac(mac
, hdr
->addr1
));
1700 sta_id
= iwl_add_station(priv
,
1701 hdr
->addr1
, 0, CMD_ASYNC
);
1703 if ((sta_id
!= IWL_INVALID_STATION
)) {
1704 lq
->lq
.sta_id
= sta_id
;
1705 lq
->lq
.rs_table
[0].rate_n_flags
= 0;
1706 lq
->ibss_sta_added
= 1;
1707 rs_initialize_lq(priv
, sta
);
1709 if (!lq
->ibss_sta_added
)
1714 if ((i
< 0) || (i
> IWL_RATE_COUNT
)) {
1715 sel
->rate
= rate_lowest(local
, local
->oper_hw_mode
, sta
);
1720 sel
->rate
= &priv
->ieee_rates
[i
];
1723 static void *rs_alloc_sta(void *priv
, gfp_t gfp
)
1725 struct iwl_rate_scale_priv
*crl
;
1728 IWL_DEBUG_RATE("create station rate scale window\n");
1730 crl
= kzalloc(sizeof(struct iwl_rate_scale_priv
), gfp
);
1734 crl
->lq
.sta_id
= 0xff;
1737 for (j
= 0; j
< LQ_SIZE
; j
++)
1738 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1739 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1744 static void rs_rate_init(void *priv_rate
, void *priv_sta
,
1745 struct ieee80211_local
*local
,
1746 struct sta_info
*sta
)
1749 struct ieee80211_hw_mode
*mode
= local
->oper_hw_mode
;
1750 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1751 struct iwl_rate_scale_priv
*crl
= priv_sta
;
1753 crl
->flush_timer
= 0;
1754 crl
->supp_rates
= sta
->supp_rates
;
1756 for (j
= 0; j
< LQ_SIZE
; j
++)
1757 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1758 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1760 IWL_DEBUG_RATE("rate scale global init\n");
1761 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1762 * the lowest or the highest rate.. Could consider using RSSI from
1763 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1766 crl
->ibss_sta_added
= 0;
1767 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1768 u8 sta_id
= iwl_hw_find_station(priv
, sta
->addr
);
1769 DECLARE_MAC_BUF(mac
);
1771 /* for IBSS the call are from tasklet */
1772 IWL_DEBUG_HT("LQ: ADD station %s\n",
1773 print_mac(mac
, sta
->addr
));
1775 if (sta_id
== IWL_INVALID_STATION
) {
1776 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1777 print_mac(mac
, sta
->addr
));
1778 sta_id
= iwl_add_station(priv
,
1779 sta
->addr
, 0, CMD_ASYNC
);
1781 if ((sta_id
!= IWL_INVALID_STATION
)) {
1782 crl
->lq
.sta_id
= sta_id
;
1783 crl
->lq
.rs_table
[0].rate_n_flags
= 0;
1785 /* FIXME: this is w/a remove it later */
1786 priv
->assoc_station_added
= 1;
1789 for (i
= 0; i
< mode
->num_rates
; i
++) {
1790 if ((sta
->supp_rates
& BIT(i
)) &&
1791 (mode
->rates
[i
].flags
& IEEE80211_RATE_SUPPORTED
))
1794 sta
->last_txrate
= sta
->txrate
;
1795 /* For MODE_IEEE80211A mode cck rate are at end
1798 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
)
1799 sta
->last_txrate
+= IWL_FIRST_OFDM_RATE
;
1801 crl
->is_dup
= priv
->is_dup
;
1802 crl
->valid_antenna
= priv
->valid_antenna
;
1803 crl
->antenna
= priv
->antenna
;
1804 crl
->is_green
= rs_use_green(priv
);
1805 crl
->active_rate
= priv
->active_rate
;
1806 crl
->active_rate
&= ~(0x1000);
1807 crl
->active_rate_basic
= priv
->active_rate_basic
;
1808 crl
->phymode
= priv
->phymode
;
1809 #ifdef CONFIG_IWLWIFI_HT
1810 crl
->active_siso_rate
= (priv
->current_assoc_ht
.supp_rates
[0] << 1);
1811 crl
->active_siso_rate
|= (priv
->current_assoc_ht
.supp_rates
[0] & 0x1);
1812 crl
->active_siso_rate
&= ~((u16
)0x2);
1813 crl
->active_siso_rate
= crl
->active_siso_rate
<< IWL_FIRST_OFDM_RATE
;
1815 crl
->active_mimo_rate
= (priv
->current_assoc_ht
.supp_rates
[1] << 1);
1816 crl
->active_mimo_rate
|= (priv
->current_assoc_ht
.supp_rates
[1] & 0x1);
1817 crl
->active_mimo_rate
&= ~((u16
)0x2);
1818 crl
->active_mimo_rate
= crl
->active_mimo_rate
<< IWL_FIRST_OFDM_RATE
;
1819 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl
->active_siso_rate
,
1820 crl
->active_mimo_rate
);
1821 #endif /*CONFIG_IWLWIFI_HT*/
1822 #ifdef CONFIG_MAC80211_DEBUGFS
1826 if (priv
->assoc_station_added
)
1827 priv
->lq_mngr
.lq_ready
= 1;
1829 rs_initialize_lq(priv
, sta
);
1832 static void rs_fill_link_cmd(struct iwl_rate_scale_priv
*lq_data
,
1833 struct iwl_rate
*tx_mcs
,
1834 struct iwl_link_quality_cmd
*lq_cmd
)
1838 int repeat_rate
= 0;
1839 u8 ant_toggle_count
= 0;
1840 u8 use_ht_possible
= 1;
1841 struct iwl_rate new_rate
;
1842 struct iwl_scale_tbl_info tbl_type
= { 0 };
1844 rs_dbgfs_set_mcs(lq_data
, tx_mcs
, index
);
1846 rs_get_tbl_info_from_mcs(tx_mcs
, lq_data
->phymode
,
1847 &tbl_type
, &rate_idx
);
1849 if (is_legacy(tbl_type
.lq_type
)) {
1850 ant_toggle_count
= 1;
1851 repeat_rate
= IWL_NUMBER_TRY
;
1853 repeat_rate
= IWL_HT_NUMBER_TRY
;
1855 lq_cmd
->general_params
.mimo_delimiter
=
1856 is_mimo(tbl_type
.lq_type
) ? 1 : 0;
1857 lq_cmd
->rs_table
[index
].rate_n_flags
=
1858 cpu_to_le32(tx_mcs
->rate_n_flags
);
1859 new_rate
.rate_n_flags
= tx_mcs
->rate_n_flags
;
1861 if (is_mimo(tbl_type
.lq_type
) || (tbl_type
.antenna_type
== ANT_MAIN
))
1862 lq_cmd
->general_params
.single_stream_ant_msk
= 1;
1864 lq_cmd
->general_params
.single_stream_ant_msk
= 2;
1869 while (index
< LINK_QUAL_MAX_RETRY_NUM
) {
1870 while (repeat_rate
> 0 && (index
< LINK_QUAL_MAX_RETRY_NUM
)) {
1871 if (is_legacy(tbl_type
.lq_type
)) {
1872 if (ant_toggle_count
<
1873 NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1876 rs_toggle_antenna(&new_rate
, &tbl_type
);
1877 ant_toggle_count
= 1;
1881 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1882 lq_cmd
->rs_table
[index
].rate_n_flags
=
1883 cpu_to_le32(new_rate
.rate_n_flags
);
1888 rs_get_tbl_info_from_mcs(&new_rate
, lq_data
->phymode
, &tbl_type
,
1891 if (is_mimo(tbl_type
.lq_type
))
1892 lq_cmd
->general_params
.mimo_delimiter
= index
;
1894 rs_get_lower_rate(lq_data
, &tbl_type
, rate_idx
,
1895 use_ht_possible
, &new_rate
);
1897 if (is_legacy(tbl_type
.lq_type
)) {
1898 if (ant_toggle_count
< NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1901 rs_toggle_antenna(&new_rate
, &tbl_type
);
1902 ant_toggle_count
= 1;
1904 repeat_rate
= IWL_NUMBER_TRY
;
1906 repeat_rate
= IWL_HT_NUMBER_TRY
;
1908 use_ht_possible
= 0;
1910 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1911 lq_cmd
->rs_table
[index
].rate_n_flags
=
1912 cpu_to_le32(new_rate
.rate_n_flags
);
1918 lq_cmd
->general_params
.dual_stream_ant_msk
= 3;
1919 lq_cmd
->agg_params
.agg_dis_start_th
= 3;
1920 lq_cmd
->agg_params
.agg_time_limit
= cpu_to_le16(4000);
1923 static void *rs_alloc(struct ieee80211_local
*local
)
1925 return local
->hw
.priv
;
1927 /* rate scale requires free function to be implemented */
1928 static void rs_free(void *priv_rate
)
1933 static void rs_clear(void *priv_rate
)
1935 struct iwl_priv
*priv
= (struct iwl_priv
*) priv_rate
;
1937 IWL_DEBUG_RATE("enter\n");
1939 priv
->lq_mngr
.lq_ready
= 0;
1940 #ifdef CONFIG_IWLWIFI_HT
1941 #ifdef CONFIG_IWLWIFI_HT_AGG
1942 if (priv
->lq_mngr
.agg_ctrl
.granted_ba
)
1943 iwl4965_turn_off_agg(priv
, TID_ALL_SPECIFIED
);
1944 #endif /*CONFIG_IWLWIFI_HT_AGG */
1945 #endif /* CONFIG_IWLWIFI_HT */
1947 IWL_DEBUG_RATE("leave\n");
1950 static void rs_free_sta(void *priv
, void *priv_sta
)
1952 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
1954 IWL_DEBUG_RATE("enter\n");
1956 IWL_DEBUG_RATE("leave\n");
1960 #ifdef CONFIG_MAC80211_DEBUGFS
1961 static int open_file_generic(struct inode
*inode
, struct file
*file
)
1963 file
->private_data
= inode
->i_private
;
1966 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
1967 struct iwl_rate
*mcs
, int index
)
1971 if (rs_priv
->phymode
== (u8
) MODE_IEEE80211A
)
1976 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
1978 mcs
->rate_n_flags
= rs_priv
->dbg_fixed
.rate_n_flags
;
1980 mcs
->rate_n_flags
= base_rate
;
1981 IWL_DEBUG_RATE("Fixed rate ON\n");
1985 IWL_DEBUG_RATE("Fixed rate OFF\n");
1988 static ssize_t
rs_sta_dbgfs_scale_table_write(struct file
*file
,
1989 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
1991 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
1996 memset(buf
, 0, sizeof(buf
));
1997 buf_size
= min(count
, sizeof(buf
) - 1);
1998 if (copy_from_user(buf
, user_buf
, buf_size
))
2001 if (sscanf(buf
, "%x", &parsed_rate
) == 1)
2002 rs_priv
->dbg_fixed
.rate_n_flags
= parsed_rate
;
2004 rs_priv
->dbg_fixed
.rate_n_flags
= 0;
2006 rs_priv
->active_rate
= 0x0FFF;
2007 rs_priv
->active_siso_rate
= 0x1FD0;
2008 rs_priv
->active_mimo_rate
= 0x1FD0;
2010 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2011 rs_priv
->lq
.sta_id
, rs_priv
->dbg_fixed
.rate_n_flags
);
2013 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
2014 rs_fill_link_cmd(rs_priv
, &rs_priv
->dbg_fixed
, &rs_priv
->lq
);
2015 rs_send_lq_cmd(rs_priv
->drv
, &rs_priv
->lq
, CMD_ASYNC
);
2021 static ssize_t
rs_sta_dbgfs_scale_table_read(struct file
*file
,
2022 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2028 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2030 desc
+= sprintf(buff
+desc
, "sta_id %d\n", rs_priv
->lq
.sta_id
);
2031 desc
+= sprintf(buff
+desc
, "failed=%d success=%d rate=0%X\n",
2032 rs_priv
->total_failed
, rs_priv
->total_success
,
2033 rs_priv
->active_rate
);
2034 desc
+= sprintf(buff
+desc
, "fixed rate 0x%X\n",
2035 rs_priv
->dbg_fixed
.rate_n_flags
);
2036 desc
+= sprintf(buff
+desc
, "general:"
2037 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2038 rs_priv
->lq
.general_params
.flags
,
2039 rs_priv
->lq
.general_params
.mimo_delimiter
,
2040 rs_priv
->lq
.general_params
.single_stream_ant_msk
,
2041 rs_priv
->lq
.general_params
.dual_stream_ant_msk
);
2043 desc
+= sprintf(buff
+desc
, "agg:"
2044 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2045 le16_to_cpu(rs_priv
->lq
.agg_params
.agg_time_limit
),
2046 rs_priv
->lq
.agg_params
.agg_dis_start_th
,
2047 rs_priv
->lq
.agg_params
.agg_frame_cnt_limit
);
2049 desc
+= sprintf(buff
+desc
,
2050 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2051 rs_priv
->lq
.general_params
.start_rate_index
[0],
2052 rs_priv
->lq
.general_params
.start_rate_index
[1],
2053 rs_priv
->lq
.general_params
.start_rate_index
[2],
2054 rs_priv
->lq
.general_params
.start_rate_index
[3]);
2057 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
2058 desc
+= sprintf(buff
+desc
, " rate[%d] 0x%X\n",
2059 i
, le32_to_cpu(rs_priv
->lq
.rs_table
[i
].rate_n_flags
));
2061 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2064 static const struct file_operations rs_sta_dbgfs_scale_table_ops
= {
2065 .write
= rs_sta_dbgfs_scale_table_write
,
2066 .read
= rs_sta_dbgfs_scale_table_read
,
2067 .open
= open_file_generic
,
2069 static ssize_t
rs_sta_dbgfs_stats_table_read(struct file
*file
,
2070 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2076 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2077 for (i
= 0; i
< LQ_SIZE
; i
++) {
2078 desc
+= sprintf(buff
+desc
, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2080 rs_priv
->active_tbl
== i
?"*":"x",
2081 rs_priv
->lq_info
[i
].lq_type
,
2082 rs_priv
->lq_info
[i
].is_SGI
,
2083 rs_priv
->lq_info
[i
].is_fat
,
2084 rs_priv
->lq_info
[i
].is_dup
,
2085 rs_priv
->lq_info
[i
].current_rate
.rate_n_flags
);
2086 for (j
= 0; j
< IWL_RATE_COUNT
; j
++) {
2087 desc
+= sprintf(buff
+desc
,
2088 "counter=%d success=%d %%=%d\n",
2089 rs_priv
->lq_info
[i
].win
[j
].counter
,
2090 rs_priv
->lq_info
[i
].win
[j
].success_counter
,
2091 rs_priv
->lq_info
[i
].win
[j
].success_ratio
);
2094 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2097 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
2098 .read
= rs_sta_dbgfs_stats_table_read
,
2099 .open
= open_file_generic
,
2102 static void rs_add_debugfs(void *priv
, void *priv_sta
,
2105 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2106 rs_priv
->rs_sta_dbgfs_scale_table_file
=
2107 debugfs_create_file("rate_scale_table", 0600, dir
,
2108 rs_priv
, &rs_sta_dbgfs_scale_table_ops
);
2109 rs_priv
->rs_sta_dbgfs_stats_table_file
=
2110 debugfs_create_file("rate_stats_table", 0600, dir
,
2111 rs_priv
, &rs_sta_dbgfs_stats_table_ops
);
2114 static void rs_remove_debugfs(void *priv
, void *priv_sta
)
2116 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2117 debugfs_remove(rs_priv
->rs_sta_dbgfs_scale_table_file
);
2118 debugfs_remove(rs_priv
->rs_sta_dbgfs_stats_table_file
);
2122 static struct rate_control_ops rs_ops
= {
2125 .tx_status
= rs_tx_status
,
2126 .get_rate
= rs_get_rate
,
2127 .rate_init
= rs_rate_init
,
2131 .alloc_sta
= rs_alloc_sta
,
2132 .free_sta
= rs_free_sta
,
2133 #ifdef CONFIG_MAC80211_DEBUGFS
2134 .add_sta_debugfs
= rs_add_debugfs
,
2135 .remove_sta_debugfs
= rs_remove_debugfs
,
2139 int iwl_fill_rs_info(struct ieee80211_hw
*hw
, char *buf
, u8 sta_id
)
2141 struct ieee80211_local
*local
= hw_to_local(hw
);
2142 struct iwl_priv
*priv
= hw
->priv
;
2143 struct iwl_rate_scale_priv
*rs_priv
;
2144 struct sta_info
*sta
;
2146 u32 samples
= 0, success
= 0, good
= 0;
2147 unsigned long now
= jiffies
;
2149 u8 lq_type
, antenna
;
2151 sta
= sta_info_get(local
, priv
->stations
[sta_id
].sta
.sta
.addr
);
2152 if (!sta
|| !sta
->rate_ctrl_priv
) {
2155 IWL_DEBUG_RATE("leave - no private rate data!\n");
2157 IWL_DEBUG_RATE("leave - no station!\n");
2158 return sprintf(buf
, "station %d not found\n", sta_id
);
2161 rs_priv
= (void *)sta
->rate_ctrl_priv
;
2163 lq_type
= rs_priv
->lq_info
[rs_priv
->active_tbl
].lq_type
;
2164 antenna
= rs_priv
->lq_info
[rs_priv
->active_tbl
].antenna_type
;
2166 if (is_legacy(lq_type
))
2167 i
= IWL_RATE_54M_INDEX
;
2169 i
= IWL_RATE_60M_INDEX
;
2173 int active
= rs_priv
->active_tbl
;
2176 sprintf(&buf
[count
], " %2dMbs: ", iwl_rates
[i
].ieee
/ 2);
2178 mask
= (1ULL << (IWL_RATE_MAX_WINDOW
- 1));
2179 for (j
= 0; j
< IWL_RATE_MAX_WINDOW
; j
++, mask
>>= 1)
2181 (rs_priv
->lq_info
[active
].win
[i
].data
& mask
)
2184 samples
+= rs_priv
->lq_info
[active
].win
[i
].counter
;
2185 good
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
;
2186 success
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
*
2189 if (rs_priv
->lq_info
[active
].win
[i
].stamp
) {
2191 jiffies_to_msecs(now
-
2192 rs_priv
->lq_info
[active
].win
[i
].stamp
);
2194 if (delta
> max_time
)
2197 count
+= sprintf(&buf
[count
], "%5dms\n", delta
);
2199 buf
[count
++] = '\n';
2201 j
= iwl_get_prev_ieee_rate(i
);
2207 /* Display the average rate of all samples taken.
2209 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2210 * added from iwl_rates is actually 2X the rate */
2212 count
+= sprintf(&buf
[count
],
2213 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2214 "%3d%% success (%d good packets over %d tries)\n",
2215 success
/ (2 * samples
), (success
* 5 / samples
) % 10,
2216 max_time
, good
* 100 / samples
, good
, samples
);
2218 count
+= sprintf(&buf
[count
], "\nAverage rate: 0Mbs\n");
2219 count
+= sprintf(&buf
[count
], "\nrate scale type %d antenna %d "
2220 "active_search %d rate index %d\n", lq_type
, antenna
,
2221 rs_priv
->search_better_tbl
, sta
->last_txrate
);
2227 void iwl_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
2229 struct iwl_priv
*priv
= hw
->priv
;
2231 priv
->lq_mngr
.lq_ready
= 1;
2234 void iwl_rate_control_register(struct ieee80211_hw
*hw
)
2236 ieee80211_rate_control_register(&rs_ops
);
2239 void iwl_rate_control_unregister(struct ieee80211_hw
*hw
)
2241 ieee80211_rate_control_unregister(&rs_ops
);