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_IWL4965_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_IWL4965_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_IWL4965_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_IWL4965_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_SUCCESS_LIMIT
;
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_IWL4965_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_IWL4965_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_IWL4965_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
);
943 #endif /*CONFIG_IWL4965_HT */
946 static int rs_switch_to_siso(struct iwl_priv
*priv
,
947 struct iwl_rate_scale_priv
*lq_data
,
948 struct iwl_scale_tbl_info
*tbl
, int index
)
950 #ifdef CONFIG_IWL4965_HT
952 u8 is_green
= lq_data
->is_green
;
955 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
956 if (!priv
->is_ht_enabled
|| !priv
->current_assoc_ht
.is_ht
)
959 tbl
->is_dup
= lq_data
->is_dup
;
960 tbl
->lq_type
= LQ_SISO
;
962 rs_get_supported_rates(lq_data
, NULL
, tbl
->lq_type
,
965 if (priv
->current_channel_width
== IWL_CHANNEL_WIDTH_40MHZ
)
971 if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_40MHZ_ONLY
)
975 } else if (priv
->current_assoc_ht
.sgf
& HT_SHORT_GI_20MHZ_ONLY
)
983 rs_get_expected_tpt_table(lq_data
, tbl
);
984 rate
= rs_get_best_rate(priv
, lq_data
, tbl
, rate_mask
, index
, index
);
986 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate
, rate_mask
);
987 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
988 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
992 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, rate
, is_green
);
993 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
994 tbl
->current_rate
.rate_n_flags
, is_green
);
999 #endif /*CONFIG_IWL4965_HT */
1002 static int rs_move_legacy_other(struct iwl_priv
*priv
,
1003 struct iwl_rate_scale_priv
*lq_data
,
1007 struct iwl_scale_tbl_info
*tbl
=
1008 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1009 struct iwl_scale_tbl_info
*search_tbl
=
1010 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1011 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1012 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1013 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1014 u8 start_action
= tbl
->action
;
1017 switch (tbl
->action
) {
1018 case IWL_LEGACY_SWITCH_ANTENNA
:
1019 IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
1021 search_tbl
->lq_type
= LQ_NONE
;
1022 lq_data
->action_counter
++;
1023 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1025 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1029 memcpy(search_tbl
, tbl
, sz
);
1031 rs_toggle_antenna(&(search_tbl
->current_rate
),
1033 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1034 lq_data
->search_better_tbl
= 1;
1037 case IWL_LEGACY_SWITCH_SISO
:
1038 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
1039 memcpy(search_tbl
, tbl
, sz
);
1040 search_tbl
->lq_type
= LQ_SISO
;
1041 search_tbl
->is_SGI
= 0;
1042 search_tbl
->is_fat
= 0;
1043 ret
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1046 lq_data
->search_better_tbl
= 1;
1047 lq_data
->action_counter
= 0;
1052 case IWL_LEGACY_SWITCH_MIMO
:
1053 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
1054 memcpy(search_tbl
, tbl
, sz
);
1055 search_tbl
->lq_type
= LQ_MIMO
;
1056 search_tbl
->is_SGI
= 0;
1057 search_tbl
->is_fat
= 0;
1058 search_tbl
->antenna_type
= ANT_BOTH
;
1059 ret
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1062 lq_data
->search_better_tbl
= 1;
1063 lq_data
->action_counter
= 0;
1069 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1070 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1072 if (tbl
->action
== start_action
)
1080 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO
)
1081 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA
;
1086 static int rs_move_siso_to_other(struct iwl_priv
*priv
,
1087 struct iwl_rate_scale_priv
*lq_data
,
1091 u8 is_green
= lq_data
->is_green
;
1092 struct iwl_scale_tbl_info
*tbl
=
1093 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1094 struct iwl_scale_tbl_info
*search_tbl
=
1095 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1096 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1097 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1098 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1099 u8 start_action
= tbl
->action
;
1102 lq_data
->action_counter
++;
1103 switch (tbl
->action
) {
1104 case IWL_SISO_SWITCH_ANTENNA
:
1105 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
1106 search_tbl
->lq_type
= LQ_NONE
;
1107 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1109 if (!rs_is_other_ant_connected(lq_data
->antenna
,
1113 memcpy(search_tbl
, tbl
, sz
);
1114 search_tbl
->action
= IWL_SISO_SWITCH_MIMO
;
1115 rs_toggle_antenna(&(search_tbl
->current_rate
),
1117 lq_data
->search_better_tbl
= 1;
1121 case IWL_SISO_SWITCH_MIMO
:
1122 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1123 memcpy(search_tbl
, tbl
, sz
);
1124 search_tbl
->lq_type
= LQ_MIMO
;
1125 search_tbl
->is_SGI
= 0;
1126 search_tbl
->is_fat
= 0;
1127 search_tbl
->antenna_type
= ANT_BOTH
;
1128 ret
= rs_switch_to_mimo(priv
, lq_data
, search_tbl
,
1131 lq_data
->search_better_tbl
= 1;
1135 case IWL_SISO_SWITCH_GI
:
1136 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
1137 memcpy(search_tbl
, tbl
, sz
);
1138 search_tbl
->action
= 0;
1139 if (search_tbl
->is_SGI
)
1140 search_tbl
->is_SGI
= 0;
1142 search_tbl
->is_SGI
= 1;
1145 lq_data
->search_better_tbl
= 1;
1146 if ((tbl
->lq_type
== LQ_SISO
) &&
1148 s32 tpt
= lq_data
->last_tpt
/ 100;
1149 if (((!tbl
->is_fat
) &&
1150 (tpt
>= expected_tpt_siso20MHz
[index
])) ||
1152 (tpt
>= expected_tpt_siso40MHz
[index
])))
1153 lq_data
->search_better_tbl
= 0;
1155 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1156 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1157 search_tbl
, index
, is_green
);
1161 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1162 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1164 if (tbl
->action
== start_action
)
1171 if (tbl
->action
> IWL_SISO_SWITCH_GI
)
1172 tbl
->action
= IWL_SISO_SWITCH_ANTENNA
;
1176 static int rs_move_mimo_to_other(struct iwl_priv
*priv
,
1177 struct iwl_rate_scale_priv
*lq_data
,
1181 s8 is_green
= lq_data
->is_green
;
1182 struct iwl_scale_tbl_info
*tbl
=
1183 &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1184 struct iwl_scale_tbl_info
*search_tbl
=
1185 &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1186 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1187 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1188 u8 start_action
= tbl
->action
;
1191 lq_data
->action_counter
++;
1192 switch (tbl
->action
) {
1193 case IWL_MIMO_SWITCH_ANTENNA_A
:
1194 case IWL_MIMO_SWITCH_ANTENNA_B
:
1195 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
1196 memcpy(search_tbl
, tbl
, sz
);
1197 search_tbl
->lq_type
= LQ_SISO
;
1198 search_tbl
->is_SGI
= 0;
1199 search_tbl
->is_fat
= 0;
1200 if (tbl
->action
== IWL_MIMO_SWITCH_ANTENNA_A
)
1201 search_tbl
->antenna_type
= ANT_MAIN
;
1203 search_tbl
->antenna_type
= ANT_AUX
;
1205 ret
= rs_switch_to_siso(priv
, lq_data
, search_tbl
,
1208 lq_data
->search_better_tbl
= 1;
1213 case IWL_MIMO_SWITCH_GI
:
1214 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
1215 memcpy(search_tbl
, tbl
, sz
);
1216 search_tbl
->lq_type
= LQ_MIMO
;
1217 search_tbl
->antenna_type
= ANT_BOTH
;
1218 search_tbl
->action
= 0;
1219 if (search_tbl
->is_SGI
)
1220 search_tbl
->is_SGI
= 0;
1222 search_tbl
->is_SGI
= 1;
1223 lq_data
->search_better_tbl
= 1;
1224 if ((tbl
->lq_type
== LQ_MIMO
) &&
1226 s32 tpt
= lq_data
->last_tpt
/ 100;
1227 if (((!tbl
->is_fat
) &&
1228 (tpt
>= expected_tpt_mimo20MHz
[index
])) ||
1230 (tpt
>= expected_tpt_mimo40MHz
[index
])))
1231 lq_data
->search_better_tbl
= 0;
1233 rs_get_expected_tpt_table(lq_data
, search_tbl
);
1234 rs_mcs_from_tbl(&search_tbl
->current_rate
,
1235 search_tbl
, index
, is_green
);
1240 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1241 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1243 if (tbl
->action
== start_action
)
1250 if (tbl
->action
> IWL_MIMO_SWITCH_GI
)
1251 tbl
->action
= IWL_MIMO_SWITCH_ANTENNA_A
;
1256 static void rs_stay_in_table(struct iwl_rate_scale_priv
*lq_data
)
1258 struct iwl_scale_tbl_info
*tbl
;
1261 int flush_interval_passed
= 0;
1263 active_tbl
= lq_data
->active_tbl
;
1265 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1267 if (lq_data
->stay_in_tbl
) {
1269 if (lq_data
->flush_timer
)
1270 flush_interval_passed
=
1272 (unsigned long)(lq_data
->flush_timer
+
1273 IWL_RATE_SCALE_FLUSH_INTVL
));
1275 flush_interval_passed
= 0;
1276 if ((lq_data
->total_failed
> lq_data
->max_failure_limit
) ||
1277 (lq_data
->total_success
> lq_data
->max_success_limit
) ||
1278 ((!lq_data
->search_better_tbl
) && (lq_data
->flush_timer
)
1279 && (flush_interval_passed
))) {
1280 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
1281 lq_data
->total_failed
,
1282 lq_data
->total_success
,
1283 flush_interval_passed
);
1284 lq_data
->stay_in_tbl
= 0;
1285 lq_data
->total_failed
= 0;
1286 lq_data
->total_success
= 0;
1287 lq_data
->flush_timer
= 0;
1289 lq_data
->table_count
++;
1290 if (lq_data
->table_count
>=
1291 lq_data
->table_count_limit
) {
1292 lq_data
->table_count
= 0;
1294 IWL_DEBUG_HT("LQ: stay in table clear win\n");
1295 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1296 rs_rate_scale_clear_window(
1301 if (!lq_data
->stay_in_tbl
) {
1302 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1303 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1308 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
1309 struct net_device
*dev
,
1310 struct ieee80211_hdr
*hdr
,
1311 struct sta_info
*sta
)
1313 int low
= IWL_RATE_INVALID
;
1314 int high
= IWL_RATE_INVALID
;
1317 struct iwl_rate_scale_data
*window
= NULL
;
1318 int current_tpt
= IWL_INVALID_VALUE
;
1319 int low_tpt
= IWL_INVALID_VALUE
;
1320 int high_tpt
= IWL_INVALID_VALUE
;
1322 s8 scale_action
= 0;
1325 struct iwl_rate_scale_priv
*lq_data
;
1326 struct iwl_scale_tbl_info
*tbl
, *tbl1
;
1327 u16 rate_scale_index_msk
= 0;
1328 struct iwl_rate mcs_rate
;
1334 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1336 fc
= le16_to_cpu(hdr
->frame_control
);
1337 if (!ieee80211_is_data(fc
) || is_multicast_ether_addr(hdr
->addr1
)) {
1338 /* Send management frames and broadcast/multicast data using
1340 /* TODO: this could probably be improved.. */
1344 if (!sta
|| !sta
->rate_ctrl_priv
)
1347 if (!priv
->lq_mngr
.lq_ready
) {
1348 IWL_DEBUG_RATE("still rate scaling not ready\n");
1351 lq_data
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1353 if (!lq_data
->search_better_tbl
)
1354 active_tbl
= lq_data
->active_tbl
;
1356 active_tbl
= 1 - lq_data
->active_tbl
;
1358 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1359 is_green
= lq_data
->is_green
;
1361 index
= sta
->last_txrate
;
1363 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index
,
1366 rs_get_supported_rates(lq_data
, hdr
, tbl
->lq_type
,
1369 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask
);
1371 /* mask with station rate restriction */
1372 if (is_legacy(tbl
->lq_type
)) {
1373 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1374 rate_scale_index_msk
= (u16
) (rate_mask
&
1375 (lq_data
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
1377 rate_scale_index_msk
= (u16
) (rate_mask
&
1378 lq_data
->supp_rates
);
1381 rate_scale_index_msk
= rate_mask
;
1383 if (!rate_scale_index_msk
)
1384 rate_scale_index_msk
= rate_mask
;
1386 if (index
< 0 || !((1 << index
) & rate_scale_index_msk
)) {
1387 index
= IWL_INVALID_VALUE
;
1390 /* get the lowest available rate */
1391 for (i
= 0; i
<= IWL_RATE_COUNT
; i
++) {
1392 if ((1 << i
) & rate_scale_index_msk
)
1396 if (index
== IWL_INVALID_VALUE
) {
1397 IWL_WARNING("Can not find a suitable rate\n");
1402 if (!tbl
->expected_tpt
)
1403 rs_get_expected_tpt_table(lq_data
, tbl
);
1405 window
= &(tbl
->win
[index
]);
1407 fail_count
= window
->counter
- window
->success_counter
;
1408 if (((fail_count
< IWL_RATE_MIN_FAILURE_TH
) &&
1409 (window
->success_counter
< IWL_RATE_MIN_SUCCESS_TH
))
1410 || (tbl
->expected_tpt
== NULL
)) {
1411 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1413 window
->success_counter
, window
->counter
, index
);
1414 window
->average_tpt
= IWL_INVALID_VALUE
;
1415 rs_stay_in_table(lq_data
);
1417 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1418 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1419 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1424 window
->average_tpt
= ((window
->success_ratio
*
1425 tbl
->expected_tpt
[index
] + 64) / 128);
1427 if (lq_data
->search_better_tbl
) {
1428 int success_limit
= IWL_RATE_SCALE_SWITCH
;
1430 if ((window
->success_ratio
> success_limit
) ||
1431 (window
->average_tpt
> lq_data
->last_tpt
)) {
1432 if (!is_legacy(tbl
->lq_type
)) {
1433 IWL_DEBUG_HT("LQ: we are switching to HT"
1434 " rate suc %d current tpt %d"
1436 window
->success_ratio
,
1437 window
->average_tpt
,
1439 lq_data
->enable_counter
= 1;
1441 lq_data
->active_tbl
= active_tbl
;
1442 current_tpt
= window
->average_tpt
;
1444 tbl
->lq_type
= LQ_NONE
;
1445 active_tbl
= lq_data
->active_tbl
;
1446 tbl
= &(lq_data
->lq_info
[active_tbl
]);
1448 index
= iwl_rate_index_from_plcp(
1449 tbl
->current_rate
.rate_n_flags
);
1452 current_tpt
= lq_data
->last_tpt
;
1453 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1455 lq_data
->search_better_tbl
= 0;
1460 high_low
= rs_get_adjacent_rate(index
, rate_scale_index_msk
,
1462 low
= high_low
& 0xff;
1463 high
= (high_low
>> 8) & 0xff;
1465 current_tpt
= window
->average_tpt
;
1467 if (low
!= IWL_RATE_INVALID
)
1468 low_tpt
= tbl
->win
[low
].average_tpt
;
1470 if (high
!= IWL_RATE_INVALID
)
1471 high_tpt
= tbl
->win
[high
].average_tpt
;
1476 if ((window
->success_ratio
<= IWL_RATE_DECREASE_TH
) ||
1477 (current_tpt
== 0)) {
1478 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1480 } else if ((low_tpt
== IWL_INVALID_VALUE
) &&
1481 (high_tpt
== IWL_INVALID_VALUE
))
1483 else if ((low_tpt
!= IWL_INVALID_VALUE
) &&
1484 (high_tpt
!= IWL_INVALID_VALUE
) &&
1485 (low_tpt
< current_tpt
) &&
1486 (high_tpt
< current_tpt
))
1489 if (high_tpt
!= IWL_INVALID_VALUE
) {
1490 if (high_tpt
> current_tpt
)
1494 ("decrease rate because of high tpt\n");
1497 } else if (low_tpt
!= IWL_INVALID_VALUE
) {
1498 if (low_tpt
> current_tpt
) {
1500 ("decrease rate because of low tpt\n");
1507 if (scale_action
== -1) {
1508 if ((low
!= IWL_RATE_INVALID
) &&
1509 ((window
->success_ratio
> IWL_RATE_HIGH_TH
) ||
1510 (current_tpt
> (100 * tbl
->expected_tpt
[low
]))))
1512 } else if ((scale_action
== 1) &&
1513 (window
->success_ratio
< IWL_RATE_INCREASE_TH
))
1516 switch (scale_action
) {
1518 if (low
!= IWL_RATE_INVALID
) {
1524 if (high
!= IWL_RATE_INVALID
) {
1535 IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
1536 "high %d type %d\n",
1537 index
, scale_action
, low
, high
, tbl
->lq_type
);
1541 rs_mcs_from_tbl(&mcs_rate
, tbl
, index
, is_green
);
1542 rs_fill_link_cmd(lq_data
, &mcs_rate
, &lq_data
->lq
);
1543 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1545 rs_stay_in_table(lq_data
);
1547 if (!update_lq
&& !done_search
&& !lq_data
->stay_in_tbl
) {
1548 lq_data
->last_tpt
= current_tpt
;
1550 if (is_legacy(tbl
->lq_type
))
1551 rs_move_legacy_other(priv
, lq_data
, index
);
1552 else if (is_siso(tbl
->lq_type
))
1553 rs_move_siso_to_other(priv
, lq_data
, index
);
1555 rs_move_mimo_to_other(priv
, lq_data
, index
);
1557 if (lq_data
->search_better_tbl
) {
1558 tbl
= &(lq_data
->lq_info
[(1 - lq_data
->active_tbl
)]);
1559 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1560 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
1562 index
= iwl_rate_index_from_plcp(
1563 tbl
->current_rate
.rate_n_flags
);
1565 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
1566 tbl
->current_rate
.rate_n_flags
, index
);
1567 rs_fill_link_cmd(lq_data
, &tbl
->current_rate
,
1569 rs_send_lq_cmd(priv
, &lq_data
->lq
, CMD_ASYNC
);
1571 tbl1
= &(lq_data
->lq_info
[lq_data
->active_tbl
]);
1573 if (is_legacy(tbl1
->lq_type
) &&
1574 #ifdef CONFIG_IWL4965_HT
1575 !priv
->current_assoc_ht
.is_ht
&&
1577 (lq_data
->action_counter
>= 1)) {
1578 lq_data
->action_counter
= 0;
1579 IWL_DEBUG_HT("LQ: STAY in legacy table\n");
1580 rs_set_stay_in_table(1, lq_data
);
1583 if (lq_data
->enable_counter
&&
1584 (lq_data
->action_counter
>= IWL_ACTION_LIMIT
)) {
1585 #ifdef CONFIG_IWL4965_HT_AGG
1586 if ((lq_data
->last_tpt
> TID_AGG_TPT_THREHOLD
) &&
1587 (priv
->lq_mngr
.agg_ctrl
.auto_agg
)) {
1588 priv
->lq_mngr
.agg_ctrl
.tid_retry
=
1590 schedule_work(&priv
->agg_work
);
1592 #endif /*CONFIG_IWL4965_HT_AGG */
1593 lq_data
->action_counter
= 0;
1594 rs_set_stay_in_table(0, lq_data
);
1597 if ((!update_lq
) && (!done_search
) && (!lq_data
->flush_timer
))
1598 lq_data
->flush_timer
= jiffies
;
1602 rs_mcs_from_tbl(&tbl
->current_rate
, tbl
, index
, is_green
);
1604 sta
->last_txrate
= i
;
1606 /* sta->txrate is an index to A mode rates which start
1607 * at IWL_FIRST_OFDM_RATE
1609 if (lq_data
->phymode
== (u8
) MODE_IEEE80211A
)
1610 sta
->txrate
= i
- IWL_FIRST_OFDM_RATE
;
1618 static void rs_initialize_lq(struct iwl_priv
*priv
,
1619 struct sta_info
*sta
)
1622 struct iwl_rate_scale_priv
*lq
;
1623 struct iwl_scale_tbl_info
*tbl
;
1626 u8 use_green
= rs_use_green(priv
);
1627 struct iwl_rate mcs_rate
;
1629 if (!sta
|| !sta
->rate_ctrl_priv
)
1632 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1633 i
= sta
->last_txrate
;
1635 if ((lq
->lq
.sta_id
== 0xff) &&
1636 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
1639 if (!lq
->search_better_tbl
)
1640 active_tbl
= lq
->active_tbl
;
1642 active_tbl
= 1 - lq
->active_tbl
;
1644 tbl
= &(lq
->lq_info
[active_tbl
]);
1646 if ((i
< 0) || (i
>= IWL_RATE_COUNT
))
1649 mcs_rate
.rate_n_flags
= iwl_rates
[i
].plcp
;
1650 mcs_rate
.rate_n_flags
|= RATE_MCS_ANT_B_MSK
;
1651 mcs_rate
.rate_n_flags
&= ~RATE_MCS_ANT_A_MSK
;
1653 if (i
>= IWL_FIRST_CCK_RATE
&& i
<= IWL_LAST_CCK_RATE
)
1654 mcs_rate
.rate_n_flags
|= RATE_MCS_CCK_MSK
;
1656 tbl
->antenna_type
= ANT_AUX
;
1657 rs_get_tbl_info_from_mcs(&mcs_rate
, priv
->phymode
, tbl
, &rate_idx
);
1658 if (!rs_is_ant_connected(priv
->valid_antenna
, tbl
->antenna_type
))
1659 rs_toggle_antenna(&mcs_rate
, tbl
);
1661 rs_mcs_from_tbl(&mcs_rate
, tbl
, rate_idx
, use_green
);
1662 tbl
->current_rate
.rate_n_flags
= mcs_rate
.rate_n_flags
;
1663 rs_get_expected_tpt_table(lq
, tbl
);
1664 rs_fill_link_cmd(lq
, &mcs_rate
, &lq
->lq
);
1665 rs_send_lq_cmd(priv
, &lq
->lq
, CMD_ASYNC
);
1670 static void rs_get_rate(void *priv_rate
, struct net_device
*dev
,
1671 struct ieee80211_hw_mode
*mode
, struct sk_buff
*skb
,
1672 struct rate_selection
*sel
)
1676 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1677 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1678 struct sta_info
*sta
;
1679 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1680 struct iwl_rate_scale_priv
*lq
;
1682 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
1684 sta
= sta_info_get(local
, hdr
->addr1
);
1686 if (!sta
|| !sta
->rate_ctrl_priv
) {
1687 sel
->rate
= rate_lowest(local
, local
->oper_hw_mode
, sta
);
1693 lq
= (struct iwl_rate_scale_priv
*)sta
->rate_ctrl_priv
;
1694 i
= sta
->last_txrate
;
1696 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) && !lq
->ibss_sta_added
) {
1697 u8 sta_id
= iwl_hw_find_station(priv
, hdr
->addr1
);
1698 DECLARE_MAC_BUF(mac
);
1700 if (sta_id
== IWL_INVALID_STATION
) {
1701 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1702 print_mac(mac
, hdr
->addr1
));
1703 sta_id
= iwl_add_station(priv
,
1704 hdr
->addr1
, 0, CMD_ASYNC
);
1706 if ((sta_id
!= IWL_INVALID_STATION
)) {
1707 lq
->lq
.sta_id
= sta_id
;
1708 lq
->lq
.rs_table
[0].rate_n_flags
= 0;
1709 lq
->ibss_sta_added
= 1;
1710 rs_initialize_lq(priv
, sta
);
1712 if (!lq
->ibss_sta_added
)
1717 if ((i
< 0) || (i
> IWL_RATE_COUNT
)) {
1718 sel
->rate
= rate_lowest(local
, local
->oper_hw_mode
, sta
);
1723 sel
->rate
= &priv
->ieee_rates
[i
];
1726 static void *rs_alloc_sta(void *priv
, gfp_t gfp
)
1728 struct iwl_rate_scale_priv
*crl
;
1731 IWL_DEBUG_RATE("create station rate scale window\n");
1733 crl
= kzalloc(sizeof(struct iwl_rate_scale_priv
), gfp
);
1737 crl
->lq
.sta_id
= 0xff;
1740 for (j
= 0; j
< LQ_SIZE
; j
++)
1741 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1742 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1747 static void rs_rate_init(void *priv_rate
, void *priv_sta
,
1748 struct ieee80211_local
*local
,
1749 struct sta_info
*sta
)
1752 struct ieee80211_hw_mode
*mode
= local
->oper_hw_mode
;
1753 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_rate
;
1754 struct iwl_rate_scale_priv
*crl
= priv_sta
;
1756 crl
->flush_timer
= 0;
1757 crl
->supp_rates
= sta
->supp_rates
;
1759 for (j
= 0; j
< LQ_SIZE
; j
++)
1760 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1761 rs_rate_scale_clear_window(&(crl
->lq_info
[j
].win
[i
]));
1763 IWL_DEBUG_RATE("rate scale global init\n");
1764 /* TODO: what is a good starting rate for STA? About middle? Maybe not
1765 * the lowest or the highest rate.. Could consider using RSSI from
1766 * previous packets? Need to have IEEE 802.1X auth succeed immediately
1769 crl
->ibss_sta_added
= 0;
1770 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1771 u8 sta_id
= iwl_hw_find_station(priv
, sta
->addr
);
1772 DECLARE_MAC_BUF(mac
);
1774 /* for IBSS the call are from tasklet */
1775 IWL_DEBUG_HT("LQ: ADD station %s\n",
1776 print_mac(mac
, sta
->addr
));
1778 if (sta_id
== IWL_INVALID_STATION
) {
1779 IWL_DEBUG_RATE("LQ: ADD station %s\n",
1780 print_mac(mac
, sta
->addr
));
1781 sta_id
= iwl_add_station(priv
,
1782 sta
->addr
, 0, CMD_ASYNC
);
1784 if ((sta_id
!= IWL_INVALID_STATION
)) {
1785 crl
->lq
.sta_id
= sta_id
;
1786 crl
->lq
.rs_table
[0].rate_n_flags
= 0;
1788 /* FIXME: this is w/a remove it later */
1789 priv
->assoc_station_added
= 1;
1792 for (i
= 0; i
< mode
->num_rates
; i
++) {
1793 if ((sta
->supp_rates
& BIT(i
)) &&
1794 (mode
->rates
[i
].flags
& IEEE80211_RATE_SUPPORTED
))
1797 sta
->last_txrate
= sta
->txrate
;
1798 /* For MODE_IEEE80211A mode cck rate are at end
1801 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
)
1802 sta
->last_txrate
+= IWL_FIRST_OFDM_RATE
;
1804 crl
->is_dup
= priv
->is_dup
;
1805 crl
->valid_antenna
= priv
->valid_antenna
;
1806 crl
->antenna
= priv
->antenna
;
1807 crl
->is_green
= rs_use_green(priv
);
1808 crl
->active_rate
= priv
->active_rate
;
1809 crl
->active_rate
&= ~(0x1000);
1810 crl
->active_rate_basic
= priv
->active_rate_basic
;
1811 crl
->phymode
= priv
->phymode
;
1812 #ifdef CONFIG_IWL4965_HT
1813 crl
->active_siso_rate
= (priv
->current_assoc_ht
.supp_rates
[0] << 1);
1814 crl
->active_siso_rate
|= (priv
->current_assoc_ht
.supp_rates
[0] & 0x1);
1815 crl
->active_siso_rate
&= ~((u16
)0x2);
1816 crl
->active_siso_rate
= crl
->active_siso_rate
<< IWL_FIRST_OFDM_RATE
;
1818 crl
->active_mimo_rate
= (priv
->current_assoc_ht
.supp_rates
[1] << 1);
1819 crl
->active_mimo_rate
|= (priv
->current_assoc_ht
.supp_rates
[1] & 0x1);
1820 crl
->active_mimo_rate
&= ~((u16
)0x2);
1821 crl
->active_mimo_rate
= crl
->active_mimo_rate
<< IWL_FIRST_OFDM_RATE
;
1822 IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl
->active_siso_rate
,
1823 crl
->active_mimo_rate
);
1824 #endif /*CONFIG_IWL4965_HT*/
1825 #ifdef CONFIG_MAC80211_DEBUGFS
1829 if (priv
->assoc_station_added
)
1830 priv
->lq_mngr
.lq_ready
= 1;
1832 rs_initialize_lq(priv
, sta
);
1835 static void rs_fill_link_cmd(struct iwl_rate_scale_priv
*lq_data
,
1836 struct iwl_rate
*tx_mcs
,
1837 struct iwl_link_quality_cmd
*lq_cmd
)
1841 int repeat_rate
= 0;
1842 u8 ant_toggle_count
= 0;
1843 u8 use_ht_possible
= 1;
1844 struct iwl_rate new_rate
;
1845 struct iwl_scale_tbl_info tbl_type
= { 0 };
1847 rs_dbgfs_set_mcs(lq_data
, tx_mcs
, index
);
1849 rs_get_tbl_info_from_mcs(tx_mcs
, lq_data
->phymode
,
1850 &tbl_type
, &rate_idx
);
1852 if (is_legacy(tbl_type
.lq_type
)) {
1853 ant_toggle_count
= 1;
1854 repeat_rate
= IWL_NUMBER_TRY
;
1856 repeat_rate
= IWL_HT_NUMBER_TRY
;
1858 lq_cmd
->general_params
.mimo_delimiter
=
1859 is_mimo(tbl_type
.lq_type
) ? 1 : 0;
1860 lq_cmd
->rs_table
[index
].rate_n_flags
=
1861 cpu_to_le32(tx_mcs
->rate_n_flags
);
1862 new_rate
.rate_n_flags
= tx_mcs
->rate_n_flags
;
1864 if (is_mimo(tbl_type
.lq_type
) || (tbl_type
.antenna_type
== ANT_MAIN
))
1865 lq_cmd
->general_params
.single_stream_ant_msk
= 1;
1867 lq_cmd
->general_params
.single_stream_ant_msk
= 2;
1872 while (index
< LINK_QUAL_MAX_RETRY_NUM
) {
1873 while (repeat_rate
> 0 && (index
< LINK_QUAL_MAX_RETRY_NUM
)) {
1874 if (is_legacy(tbl_type
.lq_type
)) {
1875 if (ant_toggle_count
<
1876 NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1879 rs_toggle_antenna(&new_rate
, &tbl_type
);
1880 ant_toggle_count
= 1;
1884 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1885 lq_cmd
->rs_table
[index
].rate_n_flags
=
1886 cpu_to_le32(new_rate
.rate_n_flags
);
1891 rs_get_tbl_info_from_mcs(&new_rate
, lq_data
->phymode
, &tbl_type
,
1894 if (is_mimo(tbl_type
.lq_type
))
1895 lq_cmd
->general_params
.mimo_delimiter
= index
;
1897 rs_get_lower_rate(lq_data
, &tbl_type
, rate_idx
,
1898 use_ht_possible
, &new_rate
);
1900 if (is_legacy(tbl_type
.lq_type
)) {
1901 if (ant_toggle_count
< NUM_TRY_BEFORE_ANTENNA_TOGGLE
)
1904 rs_toggle_antenna(&new_rate
, &tbl_type
);
1905 ant_toggle_count
= 1;
1907 repeat_rate
= IWL_NUMBER_TRY
;
1909 repeat_rate
= IWL_HT_NUMBER_TRY
;
1911 use_ht_possible
= 0;
1913 rs_dbgfs_set_mcs(lq_data
, &new_rate
, index
);
1914 lq_cmd
->rs_table
[index
].rate_n_flags
=
1915 cpu_to_le32(new_rate
.rate_n_flags
);
1921 lq_cmd
->general_params
.dual_stream_ant_msk
= 3;
1922 lq_cmd
->agg_params
.agg_dis_start_th
= 3;
1923 lq_cmd
->agg_params
.agg_time_limit
= cpu_to_le16(4000);
1926 static void *rs_alloc(struct ieee80211_local
*local
)
1928 return local
->hw
.priv
;
1930 /* rate scale requires free function to be implemented */
1931 static void rs_free(void *priv_rate
)
1936 static void rs_clear(void *priv_rate
)
1938 struct iwl_priv
*priv
= (struct iwl_priv
*) priv_rate
;
1940 IWL_DEBUG_RATE("enter\n");
1942 priv
->lq_mngr
.lq_ready
= 0;
1943 #ifdef CONFIG_IWL4965_HT
1944 #ifdef CONFIG_IWL4965_HT_AGG
1945 if (priv
->lq_mngr
.agg_ctrl
.granted_ba
)
1946 iwl4965_turn_off_agg(priv
, TID_ALL_SPECIFIED
);
1947 #endif /*CONFIG_IWL4965_HT_AGG */
1948 #endif /* CONFIG_IWL4965_HT */
1950 IWL_DEBUG_RATE("leave\n");
1953 static void rs_free_sta(void *priv
, void *priv_sta
)
1955 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
1957 IWL_DEBUG_RATE("enter\n");
1959 IWL_DEBUG_RATE("leave\n");
1963 #ifdef CONFIG_MAC80211_DEBUGFS
1964 static int open_file_generic(struct inode
*inode
, struct file
*file
)
1966 file
->private_data
= inode
->i_private
;
1969 static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv
*rs_priv
,
1970 struct iwl_rate
*mcs
, int index
)
1974 if (rs_priv
->phymode
== (u8
) MODE_IEEE80211A
)
1979 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
1981 mcs
->rate_n_flags
= rs_priv
->dbg_fixed
.rate_n_flags
;
1983 mcs
->rate_n_flags
= base_rate
;
1984 IWL_DEBUG_RATE("Fixed rate ON\n");
1988 IWL_DEBUG_RATE("Fixed rate OFF\n");
1991 static ssize_t
rs_sta_dbgfs_scale_table_write(struct file
*file
,
1992 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
1994 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
1999 memset(buf
, 0, sizeof(buf
));
2000 buf_size
= min(count
, sizeof(buf
) - 1);
2001 if (copy_from_user(buf
, user_buf
, buf_size
))
2004 if (sscanf(buf
, "%x", &parsed_rate
) == 1)
2005 rs_priv
->dbg_fixed
.rate_n_flags
= parsed_rate
;
2007 rs_priv
->dbg_fixed
.rate_n_flags
= 0;
2009 rs_priv
->active_rate
= 0x0FFF;
2010 rs_priv
->active_siso_rate
= 0x1FD0;
2011 rs_priv
->active_mimo_rate
= 0x1FD0;
2013 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2014 rs_priv
->lq
.sta_id
, rs_priv
->dbg_fixed
.rate_n_flags
);
2016 if (rs_priv
->dbg_fixed
.rate_n_flags
) {
2017 rs_fill_link_cmd(rs_priv
, &rs_priv
->dbg_fixed
, &rs_priv
->lq
);
2018 rs_send_lq_cmd(rs_priv
->drv
, &rs_priv
->lq
, CMD_ASYNC
);
2024 static ssize_t
rs_sta_dbgfs_scale_table_read(struct file
*file
,
2025 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2031 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2033 desc
+= sprintf(buff
+desc
, "sta_id %d\n", rs_priv
->lq
.sta_id
);
2034 desc
+= sprintf(buff
+desc
, "failed=%d success=%d rate=0%X\n",
2035 rs_priv
->total_failed
, rs_priv
->total_success
,
2036 rs_priv
->active_rate
);
2037 desc
+= sprintf(buff
+desc
, "fixed rate 0x%X\n",
2038 rs_priv
->dbg_fixed
.rate_n_flags
);
2039 desc
+= sprintf(buff
+desc
, "general:"
2040 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2041 rs_priv
->lq
.general_params
.flags
,
2042 rs_priv
->lq
.general_params
.mimo_delimiter
,
2043 rs_priv
->lq
.general_params
.single_stream_ant_msk
,
2044 rs_priv
->lq
.general_params
.dual_stream_ant_msk
);
2046 desc
+= sprintf(buff
+desc
, "agg:"
2047 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2048 le16_to_cpu(rs_priv
->lq
.agg_params
.agg_time_limit
),
2049 rs_priv
->lq
.agg_params
.agg_dis_start_th
,
2050 rs_priv
->lq
.agg_params
.agg_frame_cnt_limit
);
2052 desc
+= sprintf(buff
+desc
,
2053 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2054 rs_priv
->lq
.general_params
.start_rate_index
[0],
2055 rs_priv
->lq
.general_params
.start_rate_index
[1],
2056 rs_priv
->lq
.general_params
.start_rate_index
[2],
2057 rs_priv
->lq
.general_params
.start_rate_index
[3]);
2060 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
2061 desc
+= sprintf(buff
+desc
, " rate[%d] 0x%X\n",
2062 i
, le32_to_cpu(rs_priv
->lq
.rs_table
[i
].rate_n_flags
));
2064 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2067 static const struct file_operations rs_sta_dbgfs_scale_table_ops
= {
2068 .write
= rs_sta_dbgfs_scale_table_write
,
2069 .read
= rs_sta_dbgfs_scale_table_read
,
2070 .open
= open_file_generic
,
2072 static ssize_t
rs_sta_dbgfs_stats_table_read(struct file
*file
,
2073 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2079 struct iwl_rate_scale_priv
*rs_priv
= file
->private_data
;
2080 for (i
= 0; i
< LQ_SIZE
; i
++) {
2081 desc
+= sprintf(buff
+desc
, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2083 rs_priv
->active_tbl
== i
?"*":"x",
2084 rs_priv
->lq_info
[i
].lq_type
,
2085 rs_priv
->lq_info
[i
].is_SGI
,
2086 rs_priv
->lq_info
[i
].is_fat
,
2087 rs_priv
->lq_info
[i
].is_dup
,
2088 rs_priv
->lq_info
[i
].current_rate
.rate_n_flags
);
2089 for (j
= 0; j
< IWL_RATE_COUNT
; j
++) {
2090 desc
+= sprintf(buff
+desc
,
2091 "counter=%d success=%d %%=%d\n",
2092 rs_priv
->lq_info
[i
].win
[j
].counter
,
2093 rs_priv
->lq_info
[i
].win
[j
].success_counter
,
2094 rs_priv
->lq_info
[i
].win
[j
].success_ratio
);
2097 return simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2100 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
2101 .read
= rs_sta_dbgfs_stats_table_read
,
2102 .open
= open_file_generic
,
2105 static void rs_add_debugfs(void *priv
, void *priv_sta
,
2108 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2109 rs_priv
->rs_sta_dbgfs_scale_table_file
=
2110 debugfs_create_file("rate_scale_table", 0600, dir
,
2111 rs_priv
, &rs_sta_dbgfs_scale_table_ops
);
2112 rs_priv
->rs_sta_dbgfs_stats_table_file
=
2113 debugfs_create_file("rate_stats_table", 0600, dir
,
2114 rs_priv
, &rs_sta_dbgfs_stats_table_ops
);
2117 static void rs_remove_debugfs(void *priv
, void *priv_sta
)
2119 struct iwl_rate_scale_priv
*rs_priv
= priv_sta
;
2120 debugfs_remove(rs_priv
->rs_sta_dbgfs_scale_table_file
);
2121 debugfs_remove(rs_priv
->rs_sta_dbgfs_stats_table_file
);
2125 static struct rate_control_ops rs_ops
= {
2128 .tx_status
= rs_tx_status
,
2129 .get_rate
= rs_get_rate
,
2130 .rate_init
= rs_rate_init
,
2134 .alloc_sta
= rs_alloc_sta
,
2135 .free_sta
= rs_free_sta
,
2136 #ifdef CONFIG_MAC80211_DEBUGFS
2137 .add_sta_debugfs
= rs_add_debugfs
,
2138 .remove_sta_debugfs
= rs_remove_debugfs
,
2142 int iwl_fill_rs_info(struct ieee80211_hw
*hw
, char *buf
, u8 sta_id
)
2144 struct ieee80211_local
*local
= hw_to_local(hw
);
2145 struct iwl_priv
*priv
= hw
->priv
;
2146 struct iwl_rate_scale_priv
*rs_priv
;
2147 struct sta_info
*sta
;
2149 u32 samples
= 0, success
= 0, good
= 0;
2150 unsigned long now
= jiffies
;
2152 u8 lq_type
, antenna
;
2154 sta
= sta_info_get(local
, priv
->stations
[sta_id
].sta
.sta
.addr
);
2155 if (!sta
|| !sta
->rate_ctrl_priv
) {
2158 IWL_DEBUG_RATE("leave - no private rate data!\n");
2160 IWL_DEBUG_RATE("leave - no station!\n");
2161 return sprintf(buf
, "station %d not found\n", sta_id
);
2164 rs_priv
= (void *)sta
->rate_ctrl_priv
;
2166 lq_type
= rs_priv
->lq_info
[rs_priv
->active_tbl
].lq_type
;
2167 antenna
= rs_priv
->lq_info
[rs_priv
->active_tbl
].antenna_type
;
2169 if (is_legacy(lq_type
))
2170 i
= IWL_RATE_54M_INDEX
;
2172 i
= IWL_RATE_60M_INDEX
;
2176 int active
= rs_priv
->active_tbl
;
2179 sprintf(&buf
[count
], " %2dMbs: ", iwl_rates
[i
].ieee
/ 2);
2181 mask
= (1ULL << (IWL_RATE_MAX_WINDOW
- 1));
2182 for (j
= 0; j
< IWL_RATE_MAX_WINDOW
; j
++, mask
>>= 1)
2184 (rs_priv
->lq_info
[active
].win
[i
].data
& mask
)
2187 samples
+= rs_priv
->lq_info
[active
].win
[i
].counter
;
2188 good
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
;
2189 success
+= rs_priv
->lq_info
[active
].win
[i
].success_counter
*
2192 if (rs_priv
->lq_info
[active
].win
[i
].stamp
) {
2194 jiffies_to_msecs(now
-
2195 rs_priv
->lq_info
[active
].win
[i
].stamp
);
2197 if (delta
> max_time
)
2200 count
+= sprintf(&buf
[count
], "%5dms\n", delta
);
2202 buf
[count
++] = '\n';
2204 j
= iwl_get_prev_ieee_rate(i
);
2210 /* Display the average rate of all samples taken.
2212 * NOTE: We multiple # of samples by 2 since the IEEE measurement
2213 * added from iwl_rates is actually 2X the rate */
2215 count
+= sprintf(&buf
[count
],
2216 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2217 "%3d%% success (%d good packets over %d tries)\n",
2218 success
/ (2 * samples
), (success
* 5 / samples
) % 10,
2219 max_time
, good
* 100 / samples
, good
, samples
);
2221 count
+= sprintf(&buf
[count
], "\nAverage rate: 0Mbs\n");
2222 count
+= sprintf(&buf
[count
], "\nrate scale type %d antenna %d "
2223 "active_search %d rate index %d\n", lq_type
, antenna
,
2224 rs_priv
->search_better_tbl
, sta
->last_txrate
);
2230 void iwl_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
2232 struct iwl_priv
*priv
= hw
->priv
;
2234 priv
->lq_mngr
.lq_ready
= 1;
2237 void iwl_rate_control_register(struct ieee80211_hw
*hw
)
2239 ieee80211_rate_control_register(&rs_ops
);
2242 void iwl_rate_control_unregister(struct ieee80211_hw
*hw
)
2244 ieee80211_rate_control_unregister(&rs_ops
);