1 /******************************************************************************
3 * Copyright(c) 2005 - 2009 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 * Intel Linux Wireless <ilw@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>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/delay.h>
36 #include <linux/workqueue.h>
42 #define RS_NAME "iwl-agn-rs"
44 #define NUM_TRY_BEFORE_ANT_TOGGLE 1
45 #define IWL_NUMBER_TRY 1
46 #define IWL_HT_NUMBER_TRY 3
48 #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
49 #define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
50 #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
52 /* max allowed rate miss before sync LQ cmd */
53 #define IWL_MISSED_RATE_MAX 15
54 /* max time to accum history 2 seconds */
55 #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
57 static u8 rs_ht_to_legacy
[] = {
58 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
59 IWL_RATE_6M_INDEX
, IWL_RATE_6M_INDEX
,
61 IWL_RATE_6M_INDEX
, IWL_RATE_9M_INDEX
,
62 IWL_RATE_12M_INDEX
, IWL_RATE_18M_INDEX
,
63 IWL_RATE_24M_INDEX
, IWL_RATE_36M_INDEX
,
64 IWL_RATE_48M_INDEX
, IWL_RATE_54M_INDEX
67 static const u8 ant_toggle_lookup
[] = {
68 /*ANT_NONE -> */ ANT_NONE
,
71 /*ANT_AB -> */ ANT_BC
,
73 /*ANT_AC -> */ ANT_AB
,
74 /*ANT_BC -> */ ANT_AC
,
75 /*ANT_ABC -> */ ANT_ABC
,
79 * struct iwl_rate_scale_data -- tx success history for one rate
81 struct iwl_rate_scale_data
{
82 u64 data
; /* bitmap of successful frames */
83 s32 success_counter
; /* number of frames successful */
84 s32 success_ratio
; /* per-cent * 128 */
85 s32 counter
; /* number of frames attempted */
86 s32 average_tpt
; /* success ratio * expected throughput */
91 * struct iwl_scale_tbl_info -- tx params and success history for all rates
93 * There are two of these in struct iwl_lq_sta,
94 * one for "active", and one for "search".
96 struct iwl_scale_tbl_info
{
97 enum iwl_table_type lq_type
;
99 u8 is_SGI
; /* 1 = short guard interval */
100 u8 is_ht40
; /* 1 = 40 MHz channel width */
101 u8 is_dup
; /* 1 = duplicated data streams */
102 u8 action
; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
103 u8 max_search
; /* maximun number of tables we can search */
104 s32
*expected_tpt
; /* throughput metrics; expected_tpt_G, etc. */
105 u32 current_rate
; /* rate_n_flags, uCode API format */
106 struct iwl_rate_scale_data win
[IWL_RATE_COUNT
]; /* rate histories */
109 struct iwl_traffic_load
{
110 unsigned long time_stamp
; /* age of the oldest statistics */
111 u32 packet_count
[TID_QUEUE_MAX_SIZE
]; /* packet count in this time
113 u32 total
; /* total num of packets during the
114 * last TID_MAX_TIME_DIFF */
115 u8 queue_count
; /* number of queues that has
116 * been used since the last cleanup */
117 u8 head
; /* start of the circular buffer */
121 * struct iwl_lq_sta -- driver's rate scaling private structure
123 * Pointer to this gets passed back and forth between driver and mac80211.
126 u8 active_tbl
; /* index of active table, range 0-1 */
127 u8 enable_counter
; /* indicates HT mode */
128 u8 stay_in_tbl
; /* 1: disallow, 0: allow search for new mode */
129 u8 search_better_tbl
; /* 1: currently trying alternate mode */
132 /* The following determine when to search for a new mode */
133 u32 table_count_limit
;
134 u32 max_failure_limit
; /* # failed frames before new search */
135 u32 max_success_limit
; /* # successful frames before new search */
137 u32 total_failed
; /* total failed frames, any/all rates */
138 u32 total_success
; /* total successful frames, any/all rates */
139 u64 flush_timer
; /* time staying in mode before new search */
141 u8 action_counter
; /* # mode-switch actions tried */
144 enum ieee80211_band band
;
147 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
149 u16 active_legacy_rate
;
150 u16 active_siso_rate
;
151 u16 active_mimo2_rate
;
152 u16 active_mimo3_rate
;
153 u16 active_rate_basic
;
154 s8 max_rate_idx
; /* Max rate set by user */
155 u8 missed_rate_counter
;
157 struct iwl_link_quality_cmd lq
;
158 struct iwl_scale_tbl_info lq_info
[LQ_SIZE
]; /* "active", "search" */
159 struct iwl_traffic_load load
[TID_MAX_LOAD_COUNT
];
161 #ifdef CONFIG_MAC80211_DEBUGFS
162 struct dentry
*rs_sta_dbgfs_scale_table_file
;
163 struct dentry
*rs_sta_dbgfs_stats_table_file
;
164 struct dentry
*rs_sta_dbgfs_rate_scale_data_file
;
165 struct dentry
*rs_sta_dbgfs_tx_agg_tid_en_file
;
168 struct iwl_priv
*drv
;
170 /* used to be in sta_info */
172 /* last tx rate_n_flags */
173 u32 last_rate_n_flags
;
176 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
178 struct ieee80211_sta
*sta
,
179 struct iwl_lq_sta
*lq_sta
);
180 static void rs_fill_link_cmd(struct iwl_priv
*priv
,
181 struct iwl_lq_sta
*lq_sta
, u32 rate_n_flags
);
184 #ifdef CONFIG_MAC80211_DEBUGFS
185 static void rs_dbgfs_set_mcs(struct iwl_lq_sta
*lq_sta
,
186 u32
*rate_n_flags
, int index
);
188 static void rs_dbgfs_set_mcs(struct iwl_lq_sta
*lq_sta
,
189 u32
*rate_n_flags
, int index
)
194 * Expected throughput metrics for following rates:
195 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
196 * "G" is the only table that supports CCK (the first 4 rates).
199 static s32 expected_tpt_A
[IWL_RATE_COUNT
] = {
200 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
203 static s32 expected_tpt_G
[IWL_RATE_COUNT
] = {
204 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
207 static s32 expected_tpt_siso20MHz
[IWL_RATE_COUNT
] = {
208 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
211 static s32 expected_tpt_siso20MHzSGI
[IWL_RATE_COUNT
] = {
212 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
215 static s32 expected_tpt_mimo2_20MHz
[IWL_RATE_COUNT
] = {
216 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
219 static s32 expected_tpt_mimo2_20MHzSGI
[IWL_RATE_COUNT
] = {
220 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
223 static s32 expected_tpt_siso40MHz
[IWL_RATE_COUNT
] = {
224 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
227 static s32 expected_tpt_siso40MHzSGI
[IWL_RATE_COUNT
] = {
228 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
231 static s32 expected_tpt_mimo2_40MHz
[IWL_RATE_COUNT
] = {
232 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
235 static s32 expected_tpt_mimo2_40MHzSGI
[IWL_RATE_COUNT
] = {
236 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
239 /* Expected throughput metric MIMO3 */
240 static s32 expected_tpt_mimo3_20MHz
[IWL_RATE_COUNT
] = {
241 0, 0, 0, 0, 99, 99, 153, 186, 208, 239, 256, 263, 268
244 static s32 expected_tpt_mimo3_20MHzSGI
[IWL_RATE_COUNT
] = {
245 0, 0, 0, 0, 106, 106, 162, 194, 215, 246, 262, 268, 273
248 static s32 expected_tpt_mimo3_40MHz
[IWL_RATE_COUNT
] = {
249 0, 0, 0, 0, 152, 152, 211, 239, 255, 279, 290, 294, 297
252 static s32 expected_tpt_mimo3_40MHzSGI
[IWL_RATE_COUNT
] = {
253 0, 0, 0, 0, 160, 160, 219, 245, 261, 284, 294, 297, 300
257 const static struct iwl_rate_mcs_info iwl_rate_mcs
[IWL_RATE_COUNT
] = {
273 #define MCS_INDEX_PER_STREAM (8)
275 static inline u8
rs_extract_rate(u32 rate_n_flags
)
277 return (u8
)(rate_n_flags
& 0xFF);
280 static void rs_rate_scale_clear_window(struct iwl_rate_scale_data
*window
)
283 window
->success_counter
= 0;
284 window
->success_ratio
= IWL_INVALID_VALUE
;
286 window
->average_tpt
= IWL_INVALID_VALUE
;
290 static inline u8
rs_is_valid_ant(u8 valid_antenna
, u8 ant_type
)
292 return (ant_type
& valid_antenna
) == ant_type
;
296 * removes the old data from the statistics. All data that is older than
297 * TID_MAX_TIME_DIFF, will be deleted.
299 static void rs_tl_rm_old_stats(struct iwl_traffic_load
*tl
, u32 curr_time
)
301 /* The oldest age we want to keep */
302 u32 oldest_time
= curr_time
- TID_MAX_TIME_DIFF
;
304 while (tl
->queue_count
&&
305 (tl
->time_stamp
< oldest_time
)) {
306 tl
->total
-= tl
->packet_count
[tl
->head
];
307 tl
->packet_count
[tl
->head
] = 0;
308 tl
->time_stamp
+= TID_QUEUE_CELL_SPACING
;
311 if (tl
->head
>= TID_QUEUE_MAX_SIZE
)
317 * increment traffic load value for tid and also remove
318 * any old values if passed the certain time period
320 static u8
rs_tl_add_packet(struct iwl_lq_sta
*lq_data
,
321 struct ieee80211_hdr
*hdr
)
323 u32 curr_time
= jiffies_to_msecs(jiffies
);
326 struct iwl_traffic_load
*tl
= NULL
;
329 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
330 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
333 return MAX_TID_COUNT
;
335 if (unlikely(tid
>= TID_MAX_LOAD_COUNT
))
336 return MAX_TID_COUNT
;
338 tl
= &lq_data
->load
[tid
];
340 curr_time
-= curr_time
% TID_ROUND_VALUE
;
342 /* Happens only for the first packet. Initialize the data */
343 if (!(tl
->queue_count
)) {
345 tl
->time_stamp
= curr_time
;
348 tl
->packet_count
[0] = 1;
349 return MAX_TID_COUNT
;
352 time_diff
= TIME_WRAP_AROUND(tl
->time_stamp
, curr_time
);
353 index
= time_diff
/ TID_QUEUE_CELL_SPACING
;
355 /* The history is too long: remove data that is older than */
356 /* TID_MAX_TIME_DIFF */
357 if (index
>= TID_QUEUE_MAX_SIZE
)
358 rs_tl_rm_old_stats(tl
, curr_time
);
360 index
= (tl
->head
+ index
) % TID_QUEUE_MAX_SIZE
;
361 tl
->packet_count
[index
] = tl
->packet_count
[index
] + 1;
362 tl
->total
= tl
->total
+ 1;
364 if ((index
+ 1) > tl
->queue_count
)
365 tl
->queue_count
= index
+ 1;
371 get the traffic load value for tid
373 static u32
rs_tl_get_load(struct iwl_lq_sta
*lq_data
, u8 tid
)
375 u32 curr_time
= jiffies_to_msecs(jiffies
);
378 struct iwl_traffic_load
*tl
= NULL
;
380 if (tid
>= TID_MAX_LOAD_COUNT
)
383 tl
= &(lq_data
->load
[tid
]);
385 curr_time
-= curr_time
% TID_ROUND_VALUE
;
387 if (!(tl
->queue_count
))
390 time_diff
= TIME_WRAP_AROUND(tl
->time_stamp
, curr_time
);
391 index
= time_diff
/ TID_QUEUE_CELL_SPACING
;
393 /* The history is too long: remove data that is older than */
394 /* TID_MAX_TIME_DIFF */
395 if (index
>= TID_QUEUE_MAX_SIZE
)
396 rs_tl_rm_old_stats(tl
, curr_time
);
401 static void rs_tl_turn_on_agg_for_tid(struct iwl_priv
*priv
,
402 struct iwl_lq_sta
*lq_data
, u8 tid
,
403 struct ieee80211_sta
*sta
)
405 if (rs_tl_get_load(lq_data
, tid
) > IWL_AGG_LOAD_THRESHOLD
) {
406 IWL_DEBUG_HT(priv
, "Starting Tx agg: STA: %pM tid: %d\n",
408 ieee80211_start_tx_ba_session(priv
->hw
, sta
->addr
, tid
);
412 static void rs_tl_turn_on_agg(struct iwl_priv
*priv
, u8 tid
,
413 struct iwl_lq_sta
*lq_data
,
414 struct ieee80211_sta
*sta
)
416 if ((tid
< TID_MAX_LOAD_COUNT
))
417 rs_tl_turn_on_agg_for_tid(priv
, lq_data
, tid
, sta
);
418 else if (tid
== IWL_AGG_ALL_TID
)
419 for (tid
= 0; tid
< TID_MAX_LOAD_COUNT
; tid
++)
420 rs_tl_turn_on_agg_for_tid(priv
, lq_data
, tid
, sta
);
421 if (priv
->cfg
->use_rts_for_ht
) {
423 * switch to RTS/CTS if it is the prefer protection method
426 IWL_DEBUG_HT(priv
, "use RTS/CTS protection for HT\n");
427 priv
->staging_rxon
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
428 iwlcore_commit_rxon(priv
);
432 static inline int get_num_of_ant_from_rate(u32 rate_n_flags
)
434 return !!(rate_n_flags
& RATE_MCS_ANT_A_MSK
) +
435 !!(rate_n_flags
& RATE_MCS_ANT_B_MSK
) +
436 !!(rate_n_flags
& RATE_MCS_ANT_C_MSK
);
440 * rs_collect_tx_data - Update the success/failure sliding window
442 * We keep a sliding window of the last 62 packets transmitted
443 * at this rate. window->data contains the bitmask of successful
446 static int rs_collect_tx_data(struct iwl_rate_scale_data
*windows
,
447 int scale_index
, s32 tpt
, int retries
,
450 struct iwl_rate_scale_data
*window
= NULL
;
451 static const u64 mask
= (((u64
)1) << (IWL_RATE_MAX_WINDOW
- 1));
454 if (scale_index
< 0 || scale_index
>= IWL_RATE_COUNT
)
457 /* Select data for current tx bit rate */
458 window
= &(windows
[scale_index
]);
461 * Keep track of only the latest 62 tx frame attempts in this rate's
462 * history window; anything older isn't really relevant any more.
463 * If we have filled up the sliding window, drop the oldest attempt;
464 * if the oldest attempt (highest bit in bitmap) shows "success",
465 * subtract "1" from the success counter (this is the main reason
466 * we keep these bitmaps!).
468 while (retries
> 0) {
469 if (window
->counter
>= IWL_RATE_MAX_WINDOW
) {
471 /* remove earliest */
472 window
->counter
= IWL_RATE_MAX_WINDOW
- 1;
474 if (window
->data
& mask
) {
475 window
->data
&= ~mask
;
476 window
->success_counter
--;
480 /* Increment frames-attempted counter */
483 /* Shift bitmap by one frame (throw away oldest history),
484 * OR in "1", and increment "success" if this
485 * frame was successful. */
488 window
->success_counter
++;
496 /* Calculate current success ratio, avoid divide-by-0! */
497 if (window
->counter
> 0)
498 window
->success_ratio
= 128 * (100 * window
->success_counter
)
501 window
->success_ratio
= IWL_INVALID_VALUE
;
503 fail_count
= window
->counter
- window
->success_counter
;
505 /* Calculate average throughput, if we have enough history. */
506 if ((fail_count
>= IWL_RATE_MIN_FAILURE_TH
) ||
507 (window
->success_counter
>= IWL_RATE_MIN_SUCCESS_TH
))
508 window
->average_tpt
= (window
->success_ratio
* tpt
+ 64) / 128;
510 window
->average_tpt
= IWL_INVALID_VALUE
;
512 /* Tag this window as having been updated */
513 window
->stamp
= jiffies
;
519 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
521 /* FIXME:RS:remove this function and put the flags statically in the table */
522 static u32
rate_n_flags_from_tbl(struct iwl_priv
*priv
,
523 struct iwl_scale_tbl_info
*tbl
,
524 int index
, u8 use_green
)
526 u32 rate_n_flags
= 0;
528 if (is_legacy(tbl
->lq_type
)) {
529 rate_n_flags
= iwl_rates
[index
].plcp
;
530 if (index
>= IWL_FIRST_CCK_RATE
&& index
<= IWL_LAST_CCK_RATE
)
531 rate_n_flags
|= RATE_MCS_CCK_MSK
;
533 } else if (is_Ht(tbl
->lq_type
)) {
534 if (index
> IWL_LAST_OFDM_RATE
) {
535 IWL_ERR(priv
, "Invalid HT rate index %d\n", index
);
536 index
= IWL_LAST_OFDM_RATE
;
538 rate_n_flags
= RATE_MCS_HT_MSK
;
540 if (is_siso(tbl
->lq_type
))
541 rate_n_flags
|= iwl_rates
[index
].plcp_siso
;
542 else if (is_mimo2(tbl
->lq_type
))
543 rate_n_flags
|= iwl_rates
[index
].plcp_mimo2
;
545 rate_n_flags
|= iwl_rates
[index
].plcp_mimo3
;
547 IWL_ERR(priv
, "Invalid tbl->lq_type %d\n", tbl
->lq_type
);
550 rate_n_flags
|= ((tbl
->ant_type
<< RATE_MCS_ANT_POS
) &
551 RATE_MCS_ANT_ABC_MSK
);
553 if (is_Ht(tbl
->lq_type
)) {
556 rate_n_flags
|= RATE_MCS_DUP_MSK
;
558 rate_n_flags
|= RATE_MCS_HT40_MSK
;
561 rate_n_flags
|= RATE_MCS_SGI_MSK
;
564 rate_n_flags
|= RATE_MCS_GF_MSK
;
565 if (is_siso(tbl
->lq_type
) && tbl
->is_SGI
) {
566 rate_n_flags
&= ~RATE_MCS_SGI_MSK
;
567 IWL_ERR(priv
, "GF was set with SGI:SISO\n");
575 * Interpret uCode API's rate_n_flags format,
576 * fill "search" or "active" tx mode table.
578 static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags
,
579 enum ieee80211_band band
,
580 struct iwl_scale_tbl_info
*tbl
,
583 u32 ant_msk
= (rate_n_flags
& RATE_MCS_ANT_ABC_MSK
);
584 u8 num_of_ant
= get_num_of_ant_from_rate(rate_n_flags
);
587 *rate_idx
= iwl_hwrate_to_plcp_idx(rate_n_flags
);
589 if (*rate_idx
== IWL_RATE_INVALID
) {
593 tbl
->is_SGI
= 0; /* default legacy setup */
596 tbl
->ant_type
= (ant_msk
>> RATE_MCS_ANT_POS
);
597 tbl
->lq_type
= LQ_NONE
;
598 tbl
->max_search
= IWL_MAX_SEARCH
;
600 /* legacy rate format */
601 if (!(rate_n_flags
& RATE_MCS_HT_MSK
)) {
602 if (num_of_ant
== 1) {
603 if (band
== IEEE80211_BAND_5GHZ
)
610 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
613 if ((rate_n_flags
& RATE_MCS_HT40_MSK
) ||
614 (rate_n_flags
& RATE_MCS_DUP_MSK
))
617 if (rate_n_flags
& RATE_MCS_DUP_MSK
)
620 mcs
= rs_extract_rate(rate_n_flags
);
623 if (mcs
<= IWL_RATE_SISO_60M_PLCP
) {
625 tbl
->lq_type
= LQ_SISO
; /*else NONE*/
627 } else if (mcs
<= IWL_RATE_MIMO2_60M_PLCP
) {
629 tbl
->lq_type
= LQ_MIMO2
;
632 if (num_of_ant
== 3) {
633 tbl
->max_search
= IWL_MAX_11N_MIMO3_SEARCH
;
634 tbl
->lq_type
= LQ_MIMO3
;
641 /* switch to another antenna/antennas and return 1 */
642 /* if no other valid antenna found, return 0 */
643 static int rs_toggle_antenna(u32 valid_ant
, u32
*rate_n_flags
,
644 struct iwl_scale_tbl_info
*tbl
)
648 if (!tbl
->ant_type
|| tbl
->ant_type
> ANT_ABC
)
651 if (!rs_is_valid_ant(valid_ant
, tbl
->ant_type
))
654 new_ant_type
= ant_toggle_lookup
[tbl
->ant_type
];
656 while ((new_ant_type
!= tbl
->ant_type
) &&
657 !rs_is_valid_ant(valid_ant
, new_ant_type
))
658 new_ant_type
= ant_toggle_lookup
[new_ant_type
];
660 if (new_ant_type
== tbl
->ant_type
)
663 tbl
->ant_type
= new_ant_type
;
664 *rate_n_flags
&= ~RATE_MCS_ANT_ABC_MSK
;
665 *rate_n_flags
|= new_ant_type
<< RATE_MCS_ANT_POS
;
670 * Green-field mode is valid if the station supports it and
671 * there are no non-GF stations present in the BSS.
673 static inline u8
rs_use_green(struct ieee80211_sta
*sta
,
674 struct iwl_ht_info
*ht_conf
)
676 return (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_GRN_FLD
) &&
677 !(ht_conf
->non_GF_STA_present
);
681 * rs_get_supported_rates - get the available rates
683 * if management frame or broadcast frame only return
684 * basic available rates.
687 static u16
rs_get_supported_rates(struct iwl_lq_sta
*lq_sta
,
688 struct ieee80211_hdr
*hdr
,
689 enum iwl_table_type rate_type
)
691 if (hdr
&& is_multicast_ether_addr(hdr
->addr1
) &&
692 lq_sta
->active_rate_basic
)
693 return lq_sta
->active_rate_basic
;
695 if (is_legacy(rate_type
)) {
696 return lq_sta
->active_legacy_rate
;
698 if (is_siso(rate_type
))
699 return lq_sta
->active_siso_rate
;
700 else if (is_mimo2(rate_type
))
701 return lq_sta
->active_mimo2_rate
;
703 return lq_sta
->active_mimo3_rate
;
707 static u16
rs_get_adjacent_rate(struct iwl_priv
*priv
, u8 index
, u16 rate_mask
,
710 u8 high
= IWL_RATE_INVALID
;
711 u8 low
= IWL_RATE_INVALID
;
713 /* 802.11A or ht walks to the next literal adjacent rate in
715 if (is_a_band(rate_type
) || !is_legacy(rate_type
)) {
719 /* Find the previous rate that is in the rate mask */
721 for (mask
= (1 << i
); i
>= 0; i
--, mask
>>= 1) {
722 if (rate_mask
& mask
) {
728 /* Find the next rate that is in the rate mask */
730 for (mask
= (1 << i
); i
< IWL_RATE_COUNT
; i
++, mask
<<= 1) {
731 if (rate_mask
& mask
) {
737 return (high
<< 8) | low
;
741 while (low
!= IWL_RATE_INVALID
) {
742 low
= iwl_rates
[low
].prev_rs
;
743 if (low
== IWL_RATE_INVALID
)
745 if (rate_mask
& (1 << low
))
747 IWL_DEBUG_RATE(priv
, "Skipping masked lower rate: %d\n", low
);
751 while (high
!= IWL_RATE_INVALID
) {
752 high
= iwl_rates
[high
].next_rs
;
753 if (high
== IWL_RATE_INVALID
)
755 if (rate_mask
& (1 << high
))
757 IWL_DEBUG_RATE(priv
, "Skipping masked higher rate: %d\n", high
);
760 return (high
<< 8) | low
;
763 static u32
rs_get_lower_rate(struct iwl_lq_sta
*lq_sta
,
764 struct iwl_scale_tbl_info
*tbl
,
765 u8 scale_index
, u8 ht_possible
)
770 u8 switch_to_legacy
= 0;
771 u8 is_green
= lq_sta
->is_green
;
772 struct iwl_priv
*priv
= lq_sta
->drv
;
774 /* check if we need to switch from HT to legacy rates.
775 * assumption is that mandatory rates (1Mbps or 6Mbps)
776 * are always supported (spec demand) */
777 if (!is_legacy(tbl
->lq_type
) && (!ht_possible
|| !scale_index
)) {
778 switch_to_legacy
= 1;
779 scale_index
= rs_ht_to_legacy
[scale_index
];
780 if (lq_sta
->band
== IEEE80211_BAND_5GHZ
)
785 if (num_of_ant(tbl
->ant_type
) > 1)
787 first_antenna(priv
->hw_params
.valid_tx_ant
);
791 tbl
->max_search
= IWL_MAX_SEARCH
;
794 rate_mask
= rs_get_supported_rates(lq_sta
, NULL
, tbl
->lq_type
);
796 /* Mask with station rate restriction */
797 if (is_legacy(tbl
->lq_type
)) {
798 /* supp_rates has no CCK bits in A mode */
799 if (lq_sta
->band
== IEEE80211_BAND_5GHZ
)
800 rate_mask
= (u16
)(rate_mask
&
801 (lq_sta
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
803 rate_mask
= (u16
)(rate_mask
& lq_sta
->supp_rates
);
806 /* If we switched from HT to legacy, check current rate */
807 if (switch_to_legacy
&& (rate_mask
& (1 << scale_index
))) {
812 high_low
= rs_get_adjacent_rate(lq_sta
->drv
, scale_index
, rate_mask
,
814 low
= high_low
& 0xff;
816 if (low
== IWL_RATE_INVALID
)
820 return rate_n_flags_from_tbl(lq_sta
->drv
, tbl
, low
, is_green
);
824 * mac80211 sends us Tx status
826 static void rs_tx_status(void *priv_r
, struct ieee80211_supported_band
*sband
,
827 struct ieee80211_sta
*sta
, void *priv_sta
,
832 int rs_index
, mac_index
, index
= 0;
833 struct iwl_lq_sta
*lq_sta
= priv_sta
;
834 struct iwl_link_quality_cmd
*table
;
835 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
836 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_r
;
837 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
838 struct iwl_rate_scale_data
*window
= NULL
;
839 struct iwl_rate_scale_data
*search_win
= NULL
;
840 enum mac80211_rate_control_flags mac_flags
;
842 struct iwl_scale_tbl_info tbl_type
;
843 struct iwl_scale_tbl_info
*curr_tbl
, *search_tbl
;
847 IWL_DEBUG_RATE_LIMIT(priv
, "get frame ack response, update rate scale window\n");
849 if (!ieee80211_is_data(hdr
->frame_control
) ||
850 info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
853 /* This packet was aggregated but doesn't carry rate scale info */
854 if ((info
->flags
& IEEE80211_TX_CTL_AMPDU
) &&
855 !(info
->flags
& IEEE80211_TX_STAT_AMPDU
))
858 if (info
->flags
& IEEE80211_TX_STAT_AMPDU
)
861 retries
= info
->status
.rates
[0].count
- 1;
866 if ((priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) &&
867 !lq_sta
->ibss_sta_added
)
871 active_index
= lq_sta
->active_tbl
;
873 curr_tbl
= &(lq_sta
->lq_info
[active_index
]);
874 search_tbl
= &(lq_sta
->lq_info
[(1 - active_index
)]);
875 window
= (struct iwl_rate_scale_data
*)&(curr_tbl
->win
[0]);
876 search_win
= (struct iwl_rate_scale_data
*)&(search_tbl
->win
[0]);
879 * Ignore this Tx frame response if its initial rate doesn't match
880 * that of latest Link Quality command. There may be stragglers
881 * from a previous Link Quality command, but we're no longer interested
882 * in those; they're either from the "active" mode while we're trying
883 * to check "search" mode, or a prior "search" mode after we've moved
884 * to a new "search" mode (which might become the new "active" mode).
886 tx_rate
= le32_to_cpu(table
->rs_table
[0].rate_n_flags
);
887 rs_get_tbl_info_from_mcs(tx_rate
, priv
->band
, &tbl_type
, &rs_index
);
888 if (priv
->band
== IEEE80211_BAND_5GHZ
)
889 rs_index
-= IWL_FIRST_OFDM_RATE
;
890 mac_flags
= info
->status
.rates
[0].flags
;
891 mac_index
= info
->status
.rates
[0].idx
;
892 /* For HT packets, map MCS to PLCP */
893 if (mac_flags
& IEEE80211_TX_RC_MCS
) {
894 mac_index
&= RATE_MCS_CODE_MSK
; /* Remove # of streams */
895 if (mac_index
>= (IWL_RATE_9M_INDEX
- IWL_FIRST_OFDM_RATE
))
898 * mac80211 HT index is always zero-indexed; we need to move
899 * HT OFDM rates after CCK rates in 2.4 GHz band
901 if (priv
->band
== IEEE80211_BAND_2GHZ
)
902 mac_index
+= IWL_FIRST_OFDM_RATE
;
905 if ((mac_index
< 0) ||
906 (tbl_type
.is_SGI
!= !!(mac_flags
& IEEE80211_TX_RC_SHORT_GI
)) ||
907 (tbl_type
.is_ht40
!= !!(mac_flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)) ||
908 (tbl_type
.is_dup
!= !!(mac_flags
& IEEE80211_TX_RC_DUP_DATA
)) ||
909 (tbl_type
.ant_type
!= info
->antenna_sel_tx
) ||
910 (!!(tx_rate
& RATE_MCS_HT_MSK
) != !!(mac_flags
& IEEE80211_TX_RC_MCS
)) ||
911 (!!(tx_rate
& RATE_MCS_GF_MSK
) != !!(mac_flags
& IEEE80211_TX_RC_GREEN_FIELD
)) ||
912 (rs_index
!= mac_index
)) {
913 IWL_DEBUG_RATE(priv
, "initial rate %d does not match %d (0x%x)\n", mac_index
, rs_index
, tx_rate
);
914 /* the last LQ command could failed so the LQ in ucode not
915 * the same in driver sync up
917 lq_sta
->missed_rate_counter
++;
918 if (lq_sta
->missed_rate_counter
> IWL_MISSED_RATE_MAX
) {
919 lq_sta
->missed_rate_counter
= 0;
920 iwl_send_lq_cmd(priv
, &lq_sta
->lq
, CMD_ASYNC
);
925 lq_sta
->missed_rate_counter
= 0;
926 /* Update frame history window with "failure" for each Tx retry. */
928 /* Look up the rate and other info used for each tx attempt.
929 * Each tx attempt steps one entry deeper in the rate table. */
930 tx_rate
= le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
931 rs_get_tbl_info_from_mcs(tx_rate
, priv
->band
,
932 &tbl_type
, &rs_index
);
934 /* If type matches "search" table,
935 * add failure to "search" history */
936 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
937 (tbl_type
.ant_type
== search_tbl
->ant_type
) &&
938 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
939 if (search_tbl
->expected_tpt
)
940 tpt
= search_tbl
->expected_tpt
[rs_index
];
943 rs_collect_tx_data(search_win
, rs_index
, tpt
, 1, 0);
945 /* Else if type matches "current/active" table,
946 * add failure to "current/active" history */
947 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
948 (tbl_type
.ant_type
== curr_tbl
->ant_type
) &&
949 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
950 if (curr_tbl
->expected_tpt
)
951 tpt
= curr_tbl
->expected_tpt
[rs_index
];
954 rs_collect_tx_data(window
, rs_index
, tpt
, 1, 0);
957 /* If not searching for a new mode, increment failed counter
958 * ... this helps determine when to start searching again */
959 if (lq_sta
->stay_in_tbl
)
960 lq_sta
->total_failed
++;
967 * Find (by rate) the history window to update with final Tx attempt;
968 * if Tx was successful first try, use original rate,
969 * else look up the rate that was, finally, successful.
971 tx_rate
= le32_to_cpu(table
->rs_table
[index
].rate_n_flags
);
972 lq_sta
->last_rate_n_flags
= tx_rate
;
973 rs_get_tbl_info_from_mcs(tx_rate
, priv
->band
, &tbl_type
, &rs_index
);
975 /* Update frame history window with "success" if Tx got ACKed ... */
976 status
= !!(info
->flags
& IEEE80211_TX_STAT_ACK
);
978 /* If type matches "search" table,
979 * add final tx status to "search" history */
980 if ((tbl_type
.lq_type
== search_tbl
->lq_type
) &&
981 (tbl_type
.ant_type
== search_tbl
->ant_type
) &&
982 (tbl_type
.is_SGI
== search_tbl
->is_SGI
)) {
983 if (search_tbl
->expected_tpt
)
984 tpt
= search_tbl
->expected_tpt
[rs_index
];
987 if (info
->flags
& IEEE80211_TX_STAT_AMPDU
)
988 rs_collect_tx_data(search_win
, rs_index
, tpt
,
989 info
->status
.ampdu_ack_len
,
990 info
->status
.ampdu_ack_map
);
992 rs_collect_tx_data(search_win
, rs_index
, tpt
,
994 /* Else if type matches "current/active" table,
995 * add final tx status to "current/active" history */
996 } else if ((tbl_type
.lq_type
== curr_tbl
->lq_type
) &&
997 (tbl_type
.ant_type
== curr_tbl
->ant_type
) &&
998 (tbl_type
.is_SGI
== curr_tbl
->is_SGI
)) {
999 if (curr_tbl
->expected_tpt
)
1000 tpt
= curr_tbl
->expected_tpt
[rs_index
];
1003 if (info
->flags
& IEEE80211_TX_STAT_AMPDU
)
1004 rs_collect_tx_data(window
, rs_index
, tpt
,
1005 info
->status
.ampdu_ack_len
,
1006 info
->status
.ampdu_ack_map
);
1008 rs_collect_tx_data(window
, rs_index
, tpt
,
1012 /* If not searching for new mode, increment success/failed counter
1013 * ... these help determine when to start searching again */
1014 if (lq_sta
->stay_in_tbl
) {
1015 if (info
->flags
& IEEE80211_TX_STAT_AMPDU
) {
1016 lq_sta
->total_success
+= info
->status
.ampdu_ack_map
;
1017 lq_sta
->total_failed
+=
1018 (info
->status
.ampdu_ack_len
- info
->status
.ampdu_ack_map
);
1021 lq_sta
->total_success
++;
1023 lq_sta
->total_failed
++;
1027 /* See if there's a better rate or modulation mode to try. */
1028 if (sta
&& sta
->supp_rates
[sband
->band
])
1029 rs_rate_scale_perform(priv
, skb
, sta
, lq_sta
);
1035 * Begin a period of staying with a selected modulation mode.
1036 * Set "stay_in_tbl" flag to prevent any mode switches.
1037 * Set frame tx success limits according to legacy vs. high-throughput,
1038 * and reset overall (spanning all rates) tx success history statistics.
1039 * These control how long we stay using same modulation mode before
1040 * searching for a new mode.
1042 static void rs_set_stay_in_table(struct iwl_priv
*priv
, u8 is_legacy
,
1043 struct iwl_lq_sta
*lq_sta
)
1045 IWL_DEBUG_RATE(priv
, "we are staying in the same table\n");
1046 lq_sta
->stay_in_tbl
= 1; /* only place this gets set */
1048 lq_sta
->table_count_limit
= IWL_LEGACY_TABLE_COUNT
;
1049 lq_sta
->max_failure_limit
= IWL_LEGACY_FAILURE_LIMIT
;
1050 lq_sta
->max_success_limit
= IWL_LEGACY_SUCCESS_LIMIT
;
1052 lq_sta
->table_count_limit
= IWL_NONE_LEGACY_TABLE_COUNT
;
1053 lq_sta
->max_failure_limit
= IWL_NONE_LEGACY_FAILURE_LIMIT
;
1054 lq_sta
->max_success_limit
= IWL_NONE_LEGACY_SUCCESS_LIMIT
;
1056 lq_sta
->table_count
= 0;
1057 lq_sta
->total_failed
= 0;
1058 lq_sta
->total_success
= 0;
1059 lq_sta
->flush_timer
= jiffies
;
1060 lq_sta
->action_counter
= 0;
1064 * Find correct throughput table for given mode of modulation
1066 static void rs_set_expected_tpt_table(struct iwl_lq_sta
*lq_sta
,
1067 struct iwl_scale_tbl_info
*tbl
)
1069 if (is_legacy(tbl
->lq_type
)) {
1070 if (!is_a_band(tbl
->lq_type
))
1071 tbl
->expected_tpt
= expected_tpt_G
;
1073 tbl
->expected_tpt
= expected_tpt_A
;
1074 } else if (is_siso(tbl
->lq_type
)) {
1075 if (tbl
->is_ht40
&& !lq_sta
->is_dup
)
1077 tbl
->expected_tpt
= expected_tpt_siso40MHzSGI
;
1079 tbl
->expected_tpt
= expected_tpt_siso40MHz
;
1080 else if (tbl
->is_SGI
)
1081 tbl
->expected_tpt
= expected_tpt_siso20MHzSGI
;
1083 tbl
->expected_tpt
= expected_tpt_siso20MHz
;
1084 } else if (is_mimo2(tbl
->lq_type
)) {
1085 if (tbl
->is_ht40
&& !lq_sta
->is_dup
)
1087 tbl
->expected_tpt
= expected_tpt_mimo2_40MHzSGI
;
1089 tbl
->expected_tpt
= expected_tpt_mimo2_40MHz
;
1090 else if (tbl
->is_SGI
)
1091 tbl
->expected_tpt
= expected_tpt_mimo2_20MHzSGI
;
1093 tbl
->expected_tpt
= expected_tpt_mimo2_20MHz
;
1094 } else if (is_mimo3(tbl
->lq_type
)) {
1095 if (tbl
->is_ht40
&& !lq_sta
->is_dup
)
1097 tbl
->expected_tpt
= expected_tpt_mimo3_40MHzSGI
;
1099 tbl
->expected_tpt
= expected_tpt_mimo3_40MHz
;
1100 else if (tbl
->is_SGI
)
1101 tbl
->expected_tpt
= expected_tpt_mimo3_20MHzSGI
;
1103 tbl
->expected_tpt
= expected_tpt_mimo3_20MHz
;
1105 tbl
->expected_tpt
= expected_tpt_G
;
1109 * Find starting rate for new "search" high-throughput mode of modulation.
1110 * Goal is to find lowest expected rate (under perfect conditions) that is
1111 * above the current measured throughput of "active" mode, to give new mode
1112 * a fair chance to prove itself without too many challenges.
1114 * This gets called when transitioning to more aggressive modulation
1115 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1116 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1117 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1118 * bit rate will typically need to increase, but not if performance was bad.
1120 static s32
rs_get_best_rate(struct iwl_priv
*priv
,
1121 struct iwl_lq_sta
*lq_sta
,
1122 struct iwl_scale_tbl_info
*tbl
, /* "search" */
1123 u16 rate_mask
, s8 index
)
1125 /* "active" values */
1126 struct iwl_scale_tbl_info
*active_tbl
=
1127 &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
1128 s32 active_sr
= active_tbl
->win
[index
].success_ratio
;
1129 s32 active_tpt
= active_tbl
->expected_tpt
[index
];
1131 /* expected "search" throughput */
1132 s32
*tpt_tbl
= tbl
->expected_tpt
;
1134 s32 new_rate
, high
, low
, start_hi
;
1138 new_rate
= high
= low
= start_hi
= IWL_RATE_INVALID
;
1141 high_low
= rs_get_adjacent_rate(priv
, rate
, rate_mask
,
1144 low
= high_low
& 0xff;
1145 high
= (high_low
>> 8) & 0xff;
1148 * Lower the "search" bit rate, to give new "search" mode
1149 * approximately the same throughput as "active" if:
1151 * 1) "Active" mode has been working modestly well (but not
1152 * great), and expected "search" throughput (under perfect
1153 * conditions) at candidate rate is above the actual
1154 * measured "active" throughput (but less than expected
1155 * "active" throughput under perfect conditions).
1157 * 2) "Active" mode has been working perfectly or very well
1158 * and expected "search" throughput (under perfect
1159 * conditions) at candidate rate is above expected
1160 * "active" throughput (under perfect conditions).
1162 if ((((100 * tpt_tbl
[rate
]) > lq_sta
->last_tpt
) &&
1163 ((active_sr
> IWL_RATE_DECREASE_TH
) &&
1164 (active_sr
<= IWL_RATE_HIGH_TH
) &&
1165 (tpt_tbl
[rate
] <= active_tpt
))) ||
1166 ((active_sr
>= IWL_RATE_SCALE_SWITCH
) &&
1167 (tpt_tbl
[rate
] > active_tpt
))) {
1169 /* (2nd or later pass)
1170 * If we've already tried to raise the rate, and are
1171 * now trying to lower it, use the higher rate. */
1172 if (start_hi
!= IWL_RATE_INVALID
) {
1173 new_rate
= start_hi
;
1179 /* Loop again with lower rate */
1180 if (low
!= IWL_RATE_INVALID
)
1183 /* Lower rate not available, use the original */
1187 /* Else try to raise the "search" rate to match "active" */
1189 /* (2nd or later pass)
1190 * If we've already tried to lower the rate, and are
1191 * now trying to raise it, use the lower rate. */
1192 if (new_rate
!= IWL_RATE_INVALID
)
1195 /* Loop again with higher rate */
1196 else if (high
!= IWL_RATE_INVALID
) {
1200 /* Higher rate not available, use the original */
1212 * Set up search table for MIMO2
1214 static int rs_switch_to_mimo2(struct iwl_priv
*priv
,
1215 struct iwl_lq_sta
*lq_sta
,
1216 struct ieee80211_conf
*conf
,
1217 struct ieee80211_sta
*sta
,
1218 struct iwl_scale_tbl_info
*tbl
, int index
)
1222 s8 is_green
= lq_sta
->is_green
;
1224 if (!conf_is_ht(conf
) || !sta
->ht_cap
.ht_supported
)
1227 if (((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SM_PS
) >> 2)
1228 == WLAN_HT_CAP_SM_PS_STATIC
)
1231 /* Need both Tx chains/antennas to support MIMO */
1232 if (priv
->hw_params
.tx_chains_num
< 2)
1235 IWL_DEBUG_RATE(priv
, "LQ: try to switch to MIMO2\n");
1237 tbl
->lq_type
= LQ_MIMO2
;
1238 tbl
->is_dup
= lq_sta
->is_dup
;
1240 tbl
->max_search
= IWL_MAX_SEARCH
;
1241 rate_mask
= lq_sta
->active_mimo2_rate
;
1243 if (iwl_is_ht40_tx_allowed(priv
, &sta
->ht_cap
))
1248 rs_set_expected_tpt_table(lq_sta
, tbl
);
1250 rate
= rs_get_best_rate(priv
, lq_sta
, tbl
, rate_mask
, index
);
1252 IWL_DEBUG_RATE(priv
, "LQ: MIMO2 best rate %d mask %X\n", rate
, rate_mask
);
1253 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
1254 IWL_DEBUG_RATE(priv
, "Can't switch with index %d rate mask %x\n",
1258 tbl
->current_rate
= rate_n_flags_from_tbl(priv
, tbl
, rate
, is_green
);
1260 IWL_DEBUG_RATE(priv
, "LQ: Switch to new mcs %X index is green %X\n",
1261 tbl
->current_rate
, is_green
);
1266 * Set up search table for MIMO3
1268 static int rs_switch_to_mimo3(struct iwl_priv
*priv
,
1269 struct iwl_lq_sta
*lq_sta
,
1270 struct ieee80211_conf
*conf
,
1271 struct ieee80211_sta
*sta
,
1272 struct iwl_scale_tbl_info
*tbl
, int index
)
1276 s8 is_green
= lq_sta
->is_green
;
1278 if (!conf_is_ht(conf
) || !sta
->ht_cap
.ht_supported
)
1281 if (((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SM_PS
) >> 2)
1282 == WLAN_HT_CAP_SM_PS_STATIC
)
1285 /* Need both Tx chains/antennas to support MIMO */
1286 if (priv
->hw_params
.tx_chains_num
< 3)
1289 IWL_DEBUG_RATE(priv
, "LQ: try to switch to MIMO3\n");
1291 tbl
->lq_type
= LQ_MIMO3
;
1292 tbl
->is_dup
= lq_sta
->is_dup
;
1294 tbl
->max_search
= IWL_MAX_11N_MIMO3_SEARCH
;
1295 rate_mask
= lq_sta
->active_mimo3_rate
;
1297 if (iwl_is_ht40_tx_allowed(priv
, &sta
->ht_cap
))
1302 rs_set_expected_tpt_table(lq_sta
, tbl
);
1304 rate
= rs_get_best_rate(priv
, lq_sta
, tbl
, rate_mask
, index
);
1306 IWL_DEBUG_RATE(priv
, "LQ: MIMO3 best rate %d mask %X\n",
1308 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
1309 IWL_DEBUG_RATE(priv
, "Can't switch with index %d rate mask %x\n",
1313 tbl
->current_rate
= rate_n_flags_from_tbl(priv
, tbl
, rate
, is_green
);
1315 IWL_DEBUG_RATE(priv
, "LQ: Switch to new mcs %X index is green %X\n",
1316 tbl
->current_rate
, is_green
);
1321 * Set up search table for SISO
1323 static int rs_switch_to_siso(struct iwl_priv
*priv
,
1324 struct iwl_lq_sta
*lq_sta
,
1325 struct ieee80211_conf
*conf
,
1326 struct ieee80211_sta
*sta
,
1327 struct iwl_scale_tbl_info
*tbl
, int index
)
1330 u8 is_green
= lq_sta
->is_green
;
1333 if (!conf_is_ht(conf
) || !sta
->ht_cap
.ht_supported
)
1336 IWL_DEBUG_RATE(priv
, "LQ: try to switch to SISO\n");
1338 tbl
->is_dup
= lq_sta
->is_dup
;
1339 tbl
->lq_type
= LQ_SISO
;
1341 tbl
->max_search
= IWL_MAX_SEARCH
;
1342 rate_mask
= lq_sta
->active_siso_rate
;
1344 if (iwl_is_ht40_tx_allowed(priv
, &sta
->ht_cap
))
1350 tbl
->is_SGI
= 0; /*11n spec: no SGI in SISO+Greenfield*/
1352 rs_set_expected_tpt_table(lq_sta
, tbl
);
1353 rate
= rs_get_best_rate(priv
, lq_sta
, tbl
, rate_mask
, index
);
1355 IWL_DEBUG_RATE(priv
, "LQ: get best rate %d mask %X\n", rate
, rate_mask
);
1356 if ((rate
== IWL_RATE_INVALID
) || !((1 << rate
) & rate_mask
)) {
1357 IWL_DEBUG_RATE(priv
, "can not switch with index %d rate mask %x\n",
1361 tbl
->current_rate
= rate_n_flags_from_tbl(priv
, tbl
, rate
, is_green
);
1362 IWL_DEBUG_RATE(priv
, "LQ: Switch to new mcs %X index is green %X\n",
1363 tbl
->current_rate
, is_green
);
1368 * Try to switch to new modulation mode from legacy
1370 static int rs_move_legacy_other(struct iwl_priv
*priv
,
1371 struct iwl_lq_sta
*lq_sta
,
1372 struct ieee80211_conf
*conf
,
1373 struct ieee80211_sta
*sta
,
1376 struct iwl_scale_tbl_info
*tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
1377 struct iwl_scale_tbl_info
*search_tbl
=
1378 &(lq_sta
->lq_info
[(1 - lq_sta
->active_tbl
)]);
1379 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1380 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1381 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1382 u8 start_action
= tbl
->action
;
1383 u8 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
1384 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
1386 u8 update_search_tbl_counter
= 0;
1388 if (!iwl_ht_enabled(priv
))
1389 /* stay in Legacy */
1390 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA1
;
1391 else if (iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_SINGLE
&&
1392 tbl
->action
> IWL_LEGACY_SWITCH_SISO
)
1393 tbl
->action
= IWL_LEGACY_SWITCH_SISO
;
1395 lq_sta
->action_counter
++;
1396 switch (tbl
->action
) {
1397 case IWL_LEGACY_SWITCH_ANTENNA1
:
1398 case IWL_LEGACY_SWITCH_ANTENNA2
:
1399 IWL_DEBUG_RATE(priv
, "LQ: Legacy toggle Antenna\n");
1401 if ((tbl
->action
== IWL_LEGACY_SWITCH_ANTENNA1
&&
1402 tx_chains_num
<= 1) ||
1403 (tbl
->action
== IWL_LEGACY_SWITCH_ANTENNA2
&&
1404 tx_chains_num
<= 2))
1407 /* Don't change antenna if success has been great */
1408 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1411 /* Set up search table to try other antenna */
1412 memcpy(search_tbl
, tbl
, sz
);
1414 if (rs_toggle_antenna(valid_tx_ant
,
1415 &search_tbl
->current_rate
, search_tbl
)) {
1416 update_search_tbl_counter
= 1;
1417 rs_set_expected_tpt_table(lq_sta
, search_tbl
);
1421 case IWL_LEGACY_SWITCH_SISO
:
1422 IWL_DEBUG_RATE(priv
, "LQ: Legacy switch to SISO\n");
1424 /* Set up search table to try SISO */
1425 memcpy(search_tbl
, tbl
, sz
);
1426 search_tbl
->is_SGI
= 0;
1427 ret
= rs_switch_to_siso(priv
, lq_sta
, conf
, sta
,
1430 lq_sta
->action_counter
= 0;
1435 case IWL_LEGACY_SWITCH_MIMO2_AB
:
1436 case IWL_LEGACY_SWITCH_MIMO2_AC
:
1437 case IWL_LEGACY_SWITCH_MIMO2_BC
:
1438 IWL_DEBUG_RATE(priv
, "LQ: Legacy switch to MIMO2\n");
1440 /* Set up search table to try MIMO */
1441 memcpy(search_tbl
, tbl
, sz
);
1442 search_tbl
->is_SGI
= 0;
1444 if (tbl
->action
== IWL_LEGACY_SWITCH_MIMO2_AB
)
1445 search_tbl
->ant_type
= ANT_AB
;
1446 else if (tbl
->action
== IWL_LEGACY_SWITCH_MIMO2_AC
)
1447 search_tbl
->ant_type
= ANT_AC
;
1449 search_tbl
->ant_type
= ANT_BC
;
1451 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1454 ret
= rs_switch_to_mimo2(priv
, lq_sta
, conf
, sta
,
1457 lq_sta
->action_counter
= 0;
1462 case IWL_LEGACY_SWITCH_MIMO3_ABC
:
1463 IWL_DEBUG_RATE(priv
, "LQ: Legacy switch to MIMO3\n");
1465 /* Set up search table to try MIMO3 */
1466 memcpy(search_tbl
, tbl
, sz
);
1467 search_tbl
->is_SGI
= 0;
1469 search_tbl
->ant_type
= ANT_ABC
;
1471 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1474 ret
= rs_switch_to_mimo3(priv
, lq_sta
, conf
, sta
,
1477 lq_sta
->action_counter
= 0;
1483 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO3_ABC
)
1484 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA1
;
1486 if (tbl
->action
== start_action
)
1490 search_tbl
->lq_type
= LQ_NONE
;
1494 lq_sta
->search_better_tbl
= 1;
1496 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO3_ABC
)
1497 tbl
->action
= IWL_LEGACY_SWITCH_ANTENNA1
;
1498 if (update_search_tbl_counter
)
1499 search_tbl
->action
= tbl
->action
;
1505 * Try to switch to new modulation mode from SISO
1507 static int rs_move_siso_to_other(struct iwl_priv
*priv
,
1508 struct iwl_lq_sta
*lq_sta
,
1509 struct ieee80211_conf
*conf
,
1510 struct ieee80211_sta
*sta
, int index
)
1512 u8 is_green
= lq_sta
->is_green
;
1513 struct iwl_scale_tbl_info
*tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
1514 struct iwl_scale_tbl_info
*search_tbl
=
1515 &(lq_sta
->lq_info
[(1 - lq_sta
->active_tbl
)]);
1516 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1517 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1518 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1519 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1520 u8 start_action
= tbl
->action
;
1521 u8 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
1522 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
1523 u8 update_search_tbl_counter
= 0;
1526 if (iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_SINGLE
&&
1527 tbl
->action
> IWL_SISO_SWITCH_ANTENNA2
) {
1529 tbl
->action
= IWL_SISO_SWITCH_ANTENNA1
;
1532 lq_sta
->action_counter
++;
1533 switch (tbl
->action
) {
1534 case IWL_SISO_SWITCH_ANTENNA1
:
1535 case IWL_SISO_SWITCH_ANTENNA2
:
1536 IWL_DEBUG_RATE(priv
, "LQ: SISO toggle Antenna\n");
1538 if ((tbl
->action
== IWL_SISO_SWITCH_ANTENNA1
&&
1539 tx_chains_num
<= 1) ||
1540 (tbl
->action
== IWL_SISO_SWITCH_ANTENNA2
&&
1541 tx_chains_num
<= 2))
1544 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1547 memcpy(search_tbl
, tbl
, sz
);
1548 if (rs_toggle_antenna(valid_tx_ant
,
1549 &search_tbl
->current_rate
, search_tbl
)) {
1550 update_search_tbl_counter
= 1;
1554 case IWL_SISO_SWITCH_MIMO2_AB
:
1555 case IWL_SISO_SWITCH_MIMO2_AC
:
1556 case IWL_SISO_SWITCH_MIMO2_BC
:
1557 IWL_DEBUG_RATE(priv
, "LQ: SISO switch to MIMO2\n");
1558 memcpy(search_tbl
, tbl
, sz
);
1559 search_tbl
->is_SGI
= 0;
1561 if (tbl
->action
== IWL_SISO_SWITCH_MIMO2_AB
)
1562 search_tbl
->ant_type
= ANT_AB
;
1563 else if (tbl
->action
== IWL_SISO_SWITCH_MIMO2_AC
)
1564 search_tbl
->ant_type
= ANT_AC
;
1566 search_tbl
->ant_type
= ANT_BC
;
1568 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1571 ret
= rs_switch_to_mimo2(priv
, lq_sta
, conf
, sta
,
1576 case IWL_SISO_SWITCH_GI
:
1577 if (!tbl
->is_ht40
&& !(ht_cap
->cap
&
1578 IEEE80211_HT_CAP_SGI_20
))
1580 if (tbl
->is_ht40
&& !(ht_cap
->cap
&
1581 IEEE80211_HT_CAP_SGI_40
))
1584 IWL_DEBUG_RATE(priv
, "LQ: SISO toggle SGI/NGI\n");
1586 memcpy(search_tbl
, tbl
, sz
);
1592 "SGI was set in GF+SISO\n");
1594 search_tbl
->is_SGI
= !tbl
->is_SGI
;
1595 rs_set_expected_tpt_table(lq_sta
, search_tbl
);
1597 s32 tpt
= lq_sta
->last_tpt
/ 100;
1598 if (tpt
>= search_tbl
->expected_tpt
[index
])
1601 search_tbl
->current_rate
=
1602 rate_n_flags_from_tbl(priv
, search_tbl
,
1604 update_search_tbl_counter
= 1;
1606 case IWL_SISO_SWITCH_MIMO3_ABC
:
1607 IWL_DEBUG_RATE(priv
, "LQ: SISO switch to MIMO3\n");
1608 memcpy(search_tbl
, tbl
, sz
);
1609 search_tbl
->is_SGI
= 0;
1610 search_tbl
->ant_type
= ANT_ABC
;
1612 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1615 ret
= rs_switch_to_mimo3(priv
, lq_sta
, conf
, sta
,
1622 if (tbl
->action
> IWL_LEGACY_SWITCH_MIMO3_ABC
)
1623 tbl
->action
= IWL_SISO_SWITCH_ANTENNA1
;
1625 if (tbl
->action
== start_action
)
1628 search_tbl
->lq_type
= LQ_NONE
;
1632 lq_sta
->search_better_tbl
= 1;
1634 if (tbl
->action
> IWL_SISO_SWITCH_MIMO3_ABC
)
1635 tbl
->action
= IWL_SISO_SWITCH_ANTENNA1
;
1636 if (update_search_tbl_counter
)
1637 search_tbl
->action
= tbl
->action
;
1643 * Try to switch to new modulation mode from MIMO2
1645 static int rs_move_mimo2_to_other(struct iwl_priv
*priv
,
1646 struct iwl_lq_sta
*lq_sta
,
1647 struct ieee80211_conf
*conf
,
1648 struct ieee80211_sta
*sta
, int index
)
1650 s8 is_green
= lq_sta
->is_green
;
1651 struct iwl_scale_tbl_info
*tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
1652 struct iwl_scale_tbl_info
*search_tbl
=
1653 &(lq_sta
->lq_info
[(1 - lq_sta
->active_tbl
)]);
1654 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1655 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1656 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1657 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1658 u8 start_action
= tbl
->action
;
1659 u8 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
1660 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
1661 u8 update_search_tbl_counter
= 0;
1664 if ((iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_SINGLE
) &&
1665 (tbl
->action
< IWL_MIMO2_SWITCH_SISO_A
||
1666 tbl
->action
> IWL_MIMO2_SWITCH_SISO_C
)) {
1667 /* switch in SISO */
1668 tbl
->action
= IWL_MIMO2_SWITCH_SISO_A
;
1671 lq_sta
->action_counter
++;
1672 switch (tbl
->action
) {
1673 case IWL_MIMO2_SWITCH_ANTENNA1
:
1674 case IWL_MIMO2_SWITCH_ANTENNA2
:
1675 IWL_DEBUG_RATE(priv
, "LQ: MIMO2 toggle Antennas\n");
1677 if (tx_chains_num
<= 2)
1680 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1683 memcpy(search_tbl
, tbl
, sz
);
1684 if (rs_toggle_antenna(valid_tx_ant
,
1685 &search_tbl
->current_rate
, search_tbl
)) {
1686 update_search_tbl_counter
= 1;
1690 case IWL_MIMO2_SWITCH_SISO_A
:
1691 case IWL_MIMO2_SWITCH_SISO_B
:
1692 case IWL_MIMO2_SWITCH_SISO_C
:
1693 IWL_DEBUG_RATE(priv
, "LQ: MIMO2 switch to SISO\n");
1695 /* Set up new search table for SISO */
1696 memcpy(search_tbl
, tbl
, sz
);
1698 if (tbl
->action
== IWL_MIMO2_SWITCH_SISO_A
)
1699 search_tbl
->ant_type
= ANT_A
;
1700 else if (tbl
->action
== IWL_MIMO2_SWITCH_SISO_B
)
1701 search_tbl
->ant_type
= ANT_B
;
1703 search_tbl
->ant_type
= ANT_C
;
1705 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1708 ret
= rs_switch_to_siso(priv
, lq_sta
, conf
, sta
,
1715 case IWL_MIMO2_SWITCH_GI
:
1716 if (!tbl
->is_ht40
&& !(ht_cap
->cap
&
1717 IEEE80211_HT_CAP_SGI_20
))
1719 if (tbl
->is_ht40
&& !(ht_cap
->cap
&
1720 IEEE80211_HT_CAP_SGI_40
))
1723 IWL_DEBUG_RATE(priv
, "LQ: MIMO2 toggle SGI/NGI\n");
1725 /* Set up new search table for MIMO2 */
1726 memcpy(search_tbl
, tbl
, sz
);
1727 search_tbl
->is_SGI
= !tbl
->is_SGI
;
1728 rs_set_expected_tpt_table(lq_sta
, search_tbl
);
1730 * If active table already uses the fastest possible
1731 * modulation (dual stream with short guard interval),
1732 * and it's working well, there's no need to look
1733 * for a better type of modulation!
1736 s32 tpt
= lq_sta
->last_tpt
/ 100;
1737 if (tpt
>= search_tbl
->expected_tpt
[index
])
1740 search_tbl
->current_rate
=
1741 rate_n_flags_from_tbl(priv
, search_tbl
,
1743 update_search_tbl_counter
= 1;
1746 case IWL_MIMO2_SWITCH_MIMO3_ABC
:
1747 IWL_DEBUG_RATE(priv
, "LQ: MIMO2 switch to MIMO3\n");
1748 memcpy(search_tbl
, tbl
, sz
);
1749 search_tbl
->is_SGI
= 0;
1750 search_tbl
->ant_type
= ANT_ABC
;
1752 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1755 ret
= rs_switch_to_mimo3(priv
, lq_sta
, conf
, sta
,
1763 if (tbl
->action
> IWL_MIMO2_SWITCH_MIMO3_ABC
)
1764 tbl
->action
= IWL_MIMO2_SWITCH_ANTENNA1
;
1766 if (tbl
->action
== start_action
)
1769 search_tbl
->lq_type
= LQ_NONE
;
1772 lq_sta
->search_better_tbl
= 1;
1774 if (tbl
->action
> IWL_MIMO2_SWITCH_MIMO3_ABC
)
1775 tbl
->action
= IWL_MIMO2_SWITCH_ANTENNA1
;
1776 if (update_search_tbl_counter
)
1777 search_tbl
->action
= tbl
->action
;
1784 * Try to switch to new modulation mode from MIMO3
1786 static int rs_move_mimo3_to_other(struct iwl_priv
*priv
,
1787 struct iwl_lq_sta
*lq_sta
,
1788 struct ieee80211_conf
*conf
,
1789 struct ieee80211_sta
*sta
, int index
)
1791 s8 is_green
= lq_sta
->is_green
;
1792 struct iwl_scale_tbl_info
*tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
1793 struct iwl_scale_tbl_info
*search_tbl
=
1794 &(lq_sta
->lq_info
[(1 - lq_sta
->active_tbl
)]);
1795 struct iwl_rate_scale_data
*window
= &(tbl
->win
[index
]);
1796 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1797 u32 sz
= (sizeof(struct iwl_scale_tbl_info
) -
1798 (sizeof(struct iwl_rate_scale_data
) * IWL_RATE_COUNT
));
1799 u8 start_action
= tbl
->action
;
1800 u8 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
1801 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
1803 u8 update_search_tbl_counter
= 0;
1805 if ((iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_SINGLE
) &&
1806 (tbl
->action
< IWL_MIMO3_SWITCH_SISO_A
||
1807 tbl
->action
> IWL_MIMO3_SWITCH_SISO_C
)) {
1808 /* switch in SISO */
1809 tbl
->action
= IWL_MIMO3_SWITCH_SISO_A
;
1812 lq_sta
->action_counter
++;
1813 switch (tbl
->action
) {
1814 case IWL_MIMO3_SWITCH_ANTENNA1
:
1815 case IWL_MIMO3_SWITCH_ANTENNA2
:
1816 IWL_DEBUG_RATE(priv
, "LQ: MIMO3 toggle Antennas\n");
1818 if (tx_chains_num
<= 3)
1821 if (window
->success_ratio
>= IWL_RS_GOOD_RATIO
)
1824 memcpy(search_tbl
, tbl
, sz
);
1825 if (rs_toggle_antenna(valid_tx_ant
,
1826 &search_tbl
->current_rate
, search_tbl
))
1829 case IWL_MIMO3_SWITCH_SISO_A
:
1830 case IWL_MIMO3_SWITCH_SISO_B
:
1831 case IWL_MIMO3_SWITCH_SISO_C
:
1832 IWL_DEBUG_RATE(priv
, "LQ: MIMO3 switch to SISO\n");
1834 /* Set up new search table for SISO */
1835 memcpy(search_tbl
, tbl
, sz
);
1837 if (tbl
->action
== IWL_MIMO3_SWITCH_SISO_A
)
1838 search_tbl
->ant_type
= ANT_A
;
1839 else if (tbl
->action
== IWL_MIMO3_SWITCH_SISO_B
)
1840 search_tbl
->ant_type
= ANT_B
;
1842 search_tbl
->ant_type
= ANT_C
;
1844 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1847 ret
= rs_switch_to_siso(priv
, lq_sta
, conf
, sta
,
1854 case IWL_MIMO3_SWITCH_MIMO2_AB
:
1855 case IWL_MIMO3_SWITCH_MIMO2_AC
:
1856 case IWL_MIMO3_SWITCH_MIMO2_BC
:
1857 IWL_DEBUG_RATE(priv
, "LQ: MIMO3 switch to MIMO2\n");
1859 memcpy(search_tbl
, tbl
, sz
);
1860 search_tbl
->is_SGI
= 0;
1861 if (tbl
->action
== IWL_MIMO3_SWITCH_MIMO2_AB
)
1862 search_tbl
->ant_type
= ANT_AB
;
1863 else if (tbl
->action
== IWL_MIMO3_SWITCH_MIMO2_AC
)
1864 search_tbl
->ant_type
= ANT_AC
;
1866 search_tbl
->ant_type
= ANT_BC
;
1868 if (!rs_is_valid_ant(valid_tx_ant
, search_tbl
->ant_type
))
1871 ret
= rs_switch_to_mimo2(priv
, lq_sta
, conf
, sta
,
1878 case IWL_MIMO3_SWITCH_GI
:
1879 if (!tbl
->is_ht40
&& !(ht_cap
->cap
&
1880 IEEE80211_HT_CAP_SGI_20
))
1882 if (tbl
->is_ht40
&& !(ht_cap
->cap
&
1883 IEEE80211_HT_CAP_SGI_40
))
1886 IWL_DEBUG_RATE(priv
, "LQ: MIMO3 toggle SGI/NGI\n");
1888 /* Set up new search table for MIMO */
1889 memcpy(search_tbl
, tbl
, sz
);
1890 search_tbl
->is_SGI
= !tbl
->is_SGI
;
1891 rs_set_expected_tpt_table(lq_sta
, search_tbl
);
1893 * If active table already uses the fastest possible
1894 * modulation (dual stream with short guard interval),
1895 * and it's working well, there's no need to look
1896 * for a better type of modulation!
1899 s32 tpt
= lq_sta
->last_tpt
/ 100;
1900 if (tpt
>= search_tbl
->expected_tpt
[index
])
1903 search_tbl
->current_rate
=
1904 rate_n_flags_from_tbl(priv
, search_tbl
,
1906 update_search_tbl_counter
= 1;
1910 if (tbl
->action
> IWL_MIMO3_SWITCH_GI
)
1911 tbl
->action
= IWL_MIMO3_SWITCH_ANTENNA1
;
1913 if (tbl
->action
== start_action
)
1916 search_tbl
->lq_type
= LQ_NONE
;
1919 lq_sta
->search_better_tbl
= 1;
1921 if (tbl
->action
> IWL_MIMO3_SWITCH_GI
)
1922 tbl
->action
= IWL_MIMO3_SWITCH_ANTENNA1
;
1923 if (update_search_tbl_counter
)
1924 search_tbl
->action
= tbl
->action
;
1931 * Check whether we should continue using same modulation mode, or
1932 * begin search for a new mode, based on:
1933 * 1) # tx successes or failures while using this mode
1934 * 2) # times calling this function
1935 * 3) elapsed time in this mode (not used, for now)
1937 static void rs_stay_in_table(struct iwl_lq_sta
*lq_sta
)
1939 struct iwl_scale_tbl_info
*tbl
;
1942 int flush_interval_passed
= 0;
1943 struct iwl_priv
*priv
;
1946 active_tbl
= lq_sta
->active_tbl
;
1948 tbl
= &(lq_sta
->lq_info
[active_tbl
]);
1950 /* If we've been disallowing search, see if we should now allow it */
1951 if (lq_sta
->stay_in_tbl
) {
1953 /* Elapsed time using current modulation mode */
1954 if (lq_sta
->flush_timer
)
1955 flush_interval_passed
=
1957 (unsigned long)(lq_sta
->flush_timer
+
1958 IWL_RATE_SCALE_FLUSH_INTVL
));
1961 * Check if we should allow search for new modulation mode.
1962 * If many frames have failed or succeeded, or we've used
1963 * this same modulation for a long time, allow search, and
1964 * reset history stats that keep track of whether we should
1965 * allow a new search. Also (below) reset all bitmaps and
1966 * stats in active history.
1968 if ((lq_sta
->total_failed
> lq_sta
->max_failure_limit
) ||
1969 (lq_sta
->total_success
> lq_sta
->max_success_limit
) ||
1970 ((!lq_sta
->search_better_tbl
) && (lq_sta
->flush_timer
)
1971 && (flush_interval_passed
))) {
1972 IWL_DEBUG_RATE(priv
, "LQ: stay is expired %d %d %d\n:",
1973 lq_sta
->total_failed
,
1974 lq_sta
->total_success
,
1975 flush_interval_passed
);
1977 /* Allow search for new mode */
1978 lq_sta
->stay_in_tbl
= 0; /* only place reset */
1979 lq_sta
->total_failed
= 0;
1980 lq_sta
->total_success
= 0;
1981 lq_sta
->flush_timer
= 0;
1984 * Else if we've used this modulation mode enough repetitions
1985 * (regardless of elapsed time or success/failure), reset
1986 * history bitmaps and rate-specific stats for all rates in
1990 lq_sta
->table_count
++;
1991 if (lq_sta
->table_count
>=
1992 lq_sta
->table_count_limit
) {
1993 lq_sta
->table_count
= 0;
1995 IWL_DEBUG_RATE(priv
, "LQ: stay in table clear win\n");
1996 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1997 rs_rate_scale_clear_window(
2002 /* If transitioning to allow "search", reset all history
2003 * bitmaps and stats in active table (this will become the new
2004 * "search" table). */
2005 if (!lq_sta
->stay_in_tbl
) {
2006 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
2007 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
2013 * setup rate table in uCode
2014 * return rate_n_flags as used in the table
2016 static u32
rs_update_rate_tbl(struct iwl_priv
*priv
,
2017 struct iwl_lq_sta
*lq_sta
,
2018 struct iwl_scale_tbl_info
*tbl
,
2019 int index
, u8 is_green
)
2023 /* Update uCode's rate table. */
2024 rate
= rate_n_flags_from_tbl(priv
, tbl
, index
, is_green
);
2025 rs_fill_link_cmd(priv
, lq_sta
, rate
);
2026 iwl_send_lq_cmd(priv
, &lq_sta
->lq
, CMD_ASYNC
);
2032 * Do rate scaling and search for new modulation mode.
2034 static void rs_rate_scale_perform(struct iwl_priv
*priv
,
2035 struct sk_buff
*skb
,
2036 struct ieee80211_sta
*sta
,
2037 struct iwl_lq_sta
*lq_sta
)
2039 struct ieee80211_hw
*hw
= priv
->hw
;
2040 struct ieee80211_conf
*conf
= &hw
->conf
;
2041 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2042 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2043 int low
= IWL_RATE_INVALID
;
2044 int high
= IWL_RATE_INVALID
;
2047 struct iwl_rate_scale_data
*window
= NULL
;
2048 int current_tpt
= IWL_INVALID_VALUE
;
2049 int low_tpt
= IWL_INVALID_VALUE
;
2050 int high_tpt
= IWL_INVALID_VALUE
;
2052 s8 scale_action
= 0;
2055 struct iwl_scale_tbl_info
*tbl
, *tbl1
;
2056 u16 rate_scale_index_msk
= 0;
2063 u8 tid
= MAX_TID_COUNT
;
2064 struct iwl_tid_data
*tid_data
;
2066 IWL_DEBUG_RATE(priv
, "rate scale calculate new rate for skb\n");
2068 /* Send management frames and NO_ACK data using lowest rate. */
2069 /* TODO: this could probably be improved.. */
2070 if (!ieee80211_is_data(hdr
->frame_control
) ||
2071 info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
2074 if (!sta
|| !lq_sta
)
2077 lq_sta
->supp_rates
= sta
->supp_rates
[lq_sta
->band
];
2079 tid
= rs_tl_add_packet(lq_sta
, hdr
);
2082 * Select rate-scale / modulation-mode table to work with in
2083 * the rest of this function: "search" if searching for better
2084 * modulation mode, or "active" if doing rate scaling within a mode.
2086 if (!lq_sta
->search_better_tbl
)
2087 active_tbl
= lq_sta
->active_tbl
;
2089 active_tbl
= 1 - lq_sta
->active_tbl
;
2091 tbl
= &(lq_sta
->lq_info
[active_tbl
]);
2092 if (is_legacy(tbl
->lq_type
))
2093 lq_sta
->is_green
= 0;
2095 lq_sta
->is_green
= rs_use_green(sta
, &priv
->current_ht_config
);
2096 is_green
= lq_sta
->is_green
;
2098 /* current tx rate */
2099 index
= lq_sta
->last_txrate_idx
;
2101 IWL_DEBUG_RATE(priv
, "Rate scale index %d for type %d\n", index
,
2104 /* rates available for this association, and for modulation mode */
2105 rate_mask
= rs_get_supported_rates(lq_sta
, hdr
, tbl
->lq_type
);
2107 IWL_DEBUG_RATE(priv
, "mask 0x%04X \n", rate_mask
);
2109 /* mask with station rate restriction */
2110 if (is_legacy(tbl
->lq_type
)) {
2111 if (lq_sta
->band
== IEEE80211_BAND_5GHZ
)
2112 /* supp_rates has no CCK bits in A mode */
2113 rate_scale_index_msk
= (u16
) (rate_mask
&
2114 (lq_sta
->supp_rates
<< IWL_FIRST_OFDM_RATE
));
2116 rate_scale_index_msk
= (u16
) (rate_mask
&
2117 lq_sta
->supp_rates
);
2120 rate_scale_index_msk
= rate_mask
;
2122 if (!rate_scale_index_msk
)
2123 rate_scale_index_msk
= rate_mask
;
2125 if (!((1 << index
) & rate_scale_index_msk
)) {
2126 IWL_ERR(priv
, "Current Rate is not valid\n");
2127 if (lq_sta
->search_better_tbl
) {
2128 /* revert to active table if search table is not valid*/
2129 tbl
->lq_type
= LQ_NONE
;
2130 lq_sta
->search_better_tbl
= 0;
2131 tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
2132 /* get "active" rate info */
2133 index
= iwl_hwrate_to_plcp_idx(tbl
->current_rate
);
2134 rate
= rs_update_rate_tbl(priv
, lq_sta
,
2135 tbl
, index
, is_green
);
2140 /* Get expected throughput table and history window for current rate */
2141 if (!tbl
->expected_tpt
) {
2142 IWL_ERR(priv
, "tbl->expected_tpt is NULL\n");
2146 /* force user max rate if set by user */
2147 if ((lq_sta
->max_rate_idx
!= -1) &&
2148 (lq_sta
->max_rate_idx
< index
)) {
2149 index
= lq_sta
->max_rate_idx
;
2151 window
= &(tbl
->win
[index
]);
2155 window
= &(tbl
->win
[index
]);
2158 * If there is not enough history to calculate actual average
2159 * throughput, keep analyzing results of more tx frames, without
2160 * changing rate or mode (bypass most of the rest of this function).
2161 * Set up new rate table in uCode only if old rate is not supported
2162 * in current association (use new rate found above).
2164 fail_count
= window
->counter
- window
->success_counter
;
2165 if ((fail_count
< IWL_RATE_MIN_FAILURE_TH
) &&
2166 (window
->success_counter
< IWL_RATE_MIN_SUCCESS_TH
)) {
2167 IWL_DEBUG_RATE(priv
, "LQ: still below TH. succ=%d total=%d "
2169 window
->success_counter
, window
->counter
, index
);
2171 /* Can't calculate this yet; not enough history */
2172 window
->average_tpt
= IWL_INVALID_VALUE
;
2174 /* Should we stay with this modulation mode,
2175 * or search for a new one? */
2176 rs_stay_in_table(lq_sta
);
2181 /* Else we have enough samples; calculate estimate of
2182 * actual average throughput */
2184 BUG_ON(window
->average_tpt
!= ((window
->success_ratio
*
2185 tbl
->expected_tpt
[index
] + 64) / 128));
2187 /* If we are searching for better modulation mode, check success. */
2188 if (lq_sta
->search_better_tbl
&&
2189 (iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_MULTI
)) {
2190 /* If good success, continue using the "search" mode;
2191 * no need to send new link quality command, since we're
2192 * continuing to use the setup that we've been trying. */
2193 if (window
->average_tpt
> lq_sta
->last_tpt
) {
2195 IWL_DEBUG_RATE(priv
, "LQ: SWITCHING TO NEW TABLE "
2196 "suc=%d cur-tpt=%d old-tpt=%d\n",
2197 window
->success_ratio
,
2198 window
->average_tpt
,
2201 if (!is_legacy(tbl
->lq_type
))
2202 lq_sta
->enable_counter
= 1;
2204 /* Swap tables; "search" becomes "active" */
2205 lq_sta
->active_tbl
= active_tbl
;
2206 current_tpt
= window
->average_tpt
;
2208 /* Else poor success; go back to mode in "active" table */
2211 IWL_DEBUG_RATE(priv
, "LQ: GOING BACK TO THE OLD TABLE "
2212 "suc=%d cur-tpt=%d old-tpt=%d\n",
2213 window
->success_ratio
,
2214 window
->average_tpt
,
2217 /* Nullify "search" table */
2218 tbl
->lq_type
= LQ_NONE
;
2220 /* Revert to "active" table */
2221 active_tbl
= lq_sta
->active_tbl
;
2222 tbl
= &(lq_sta
->lq_info
[active_tbl
]);
2224 /* Revert to "active" rate and throughput info */
2225 index
= iwl_hwrate_to_plcp_idx(tbl
->current_rate
);
2226 current_tpt
= lq_sta
->last_tpt
;
2228 /* Need to set up a new rate table in uCode */
2232 /* Either way, we've made a decision; modulation mode
2233 * search is done, allow rate adjustment next time. */
2234 lq_sta
->search_better_tbl
= 0;
2235 done_search
= 1; /* Don't switch modes below! */
2239 /* (Else) not in search of better modulation mode, try for better
2240 * starting rate, while staying in this mode. */
2241 high_low
= rs_get_adjacent_rate(priv
, index
, rate_scale_index_msk
,
2243 low
= high_low
& 0xff;
2244 high
= (high_low
>> 8) & 0xff;
2246 /* If user set max rate, dont allow higher than user constrain */
2247 if ((lq_sta
->max_rate_idx
!= -1) &&
2248 (lq_sta
->max_rate_idx
< high
))
2249 high
= IWL_RATE_INVALID
;
2251 sr
= window
->success_ratio
;
2253 /* Collect measured throughputs for current and adjacent rates */
2254 current_tpt
= window
->average_tpt
;
2255 if (low
!= IWL_RATE_INVALID
)
2256 low_tpt
= tbl
->win
[low
].average_tpt
;
2257 if (high
!= IWL_RATE_INVALID
)
2258 high_tpt
= tbl
->win
[high
].average_tpt
;
2262 /* Too many failures, decrease rate */
2263 if ((sr
<= IWL_RATE_DECREASE_TH
) || (current_tpt
== 0)) {
2264 IWL_DEBUG_RATE(priv
, "decrease rate because of low success_ratio\n");
2267 /* No throughput measured yet for adjacent rates; try increase. */
2268 } else if ((low_tpt
== IWL_INVALID_VALUE
) &&
2269 (high_tpt
== IWL_INVALID_VALUE
)) {
2271 if (high
!= IWL_RATE_INVALID
&& sr
>= IWL_RATE_INCREASE_TH
)
2273 else if (low
!= IWL_RATE_INVALID
)
2277 /* Both adjacent throughputs are measured, but neither one has better
2278 * throughput; we're using the best rate, don't change it! */
2279 else if ((low_tpt
!= IWL_INVALID_VALUE
) &&
2280 (high_tpt
!= IWL_INVALID_VALUE
) &&
2281 (low_tpt
< current_tpt
) &&
2282 (high_tpt
< current_tpt
))
2285 /* At least one adjacent rate's throughput is measured,
2286 * and may have better performance. */
2288 /* Higher adjacent rate's throughput is measured */
2289 if (high_tpt
!= IWL_INVALID_VALUE
) {
2290 /* Higher rate has better throughput */
2291 if (high_tpt
> current_tpt
&&
2292 sr
>= IWL_RATE_INCREASE_TH
) {
2298 /* Lower adjacent rate's throughput is measured */
2299 } else if (low_tpt
!= IWL_INVALID_VALUE
) {
2300 /* Lower rate has better throughput */
2301 if (low_tpt
> current_tpt
) {
2302 IWL_DEBUG_RATE(priv
,
2303 "decrease rate because of low tpt\n");
2305 } else if (sr
>= IWL_RATE_INCREASE_TH
) {
2311 /* Sanity check; asked for decrease, but success rate or throughput
2312 * has been good at old rate. Don't change it. */
2313 if ((scale_action
== -1) && (low
!= IWL_RATE_INVALID
) &&
2314 ((sr
> IWL_RATE_HIGH_TH
) ||
2315 (current_tpt
> (100 * tbl
->expected_tpt
[low
]))))
2317 if (!iwl_ht_enabled(priv
) && !is_legacy(tbl
->lq_type
))
2319 if (iwl_tx_ant_restriction(priv
) != IWL_ANT_OK_MULTI
&&
2320 (is_mimo2(tbl
->lq_type
) || is_mimo3(tbl
->lq_type
)))
2322 switch (scale_action
) {
2324 /* Decrease starting rate, update uCode's rate table */
2325 if (low
!= IWL_RATE_INVALID
) {
2332 /* Increase starting rate, update uCode's rate table */
2333 if (high
!= IWL_RATE_INVALID
) {
2345 IWL_DEBUG_RATE(priv
, "choose rate scale index %d action %d low %d "
2346 "high %d type %d\n",
2347 index
, scale_action
, low
, high
, tbl
->lq_type
);
2350 /* Replace uCode's rate table for the destination station. */
2352 rate
= rs_update_rate_tbl(priv
, lq_sta
,
2353 tbl
, index
, is_green
);
2355 if (iwl_tx_ant_restriction(priv
) == IWL_ANT_OK_MULTI
) {
2356 /* Should we stay with this modulation mode,
2357 * or search for a new one? */
2358 rs_stay_in_table(lq_sta
);
2361 * Search for new modulation mode if we're:
2362 * 1) Not changing rates right now
2363 * 2) Not just finishing up a search
2364 * 3) Allowing a new search
2366 if (!update_lq
&& !done_search
&& !lq_sta
->stay_in_tbl
&& window
->counter
) {
2367 /* Save current throughput to compare with "search" throughput*/
2368 lq_sta
->last_tpt
= current_tpt
;
2370 /* Select a new "search" modulation mode to try.
2371 * If one is found, set up the new "search" table. */
2372 if (is_legacy(tbl
->lq_type
))
2373 rs_move_legacy_other(priv
, lq_sta
, conf
, sta
, index
);
2374 else if (is_siso(tbl
->lq_type
))
2375 rs_move_siso_to_other(priv
, lq_sta
, conf
, sta
, index
);
2376 else if (is_mimo2(tbl
->lq_type
))
2377 rs_move_mimo2_to_other(priv
, lq_sta
, conf
, sta
, index
);
2379 rs_move_mimo3_to_other(priv
, lq_sta
, conf
, sta
, index
);
2381 /* If new "search" mode was selected, set up in uCode table */
2382 if (lq_sta
->search_better_tbl
) {
2383 /* Access the "search" table, clear its history. */
2384 tbl
= &(lq_sta
->lq_info
[(1 - lq_sta
->active_tbl
)]);
2385 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
2386 rs_rate_scale_clear_window(&(tbl
->win
[i
]));
2388 /* Use new "search" start rate */
2389 index
= iwl_hwrate_to_plcp_idx(tbl
->current_rate
);
2391 IWL_DEBUG_RATE(priv
, "Switch current mcs: %X index: %d\n",
2392 tbl
->current_rate
, index
);
2393 rs_fill_link_cmd(priv
, lq_sta
, tbl
->current_rate
);
2394 iwl_send_lq_cmd(priv
, &lq_sta
->lq
, CMD_ASYNC
);
2399 if (done_search
&& !lq_sta
->stay_in_tbl
) {
2400 /* If the "active" (non-search) mode was legacy,
2401 * and we've tried switching antennas,
2402 * but we haven't been able to try HT modes (not available),
2403 * stay with best antenna legacy modulation for a while
2404 * before next round of mode comparisons. */
2405 tbl1
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
2406 if (is_legacy(tbl1
->lq_type
) && !conf_is_ht(conf
) &&
2407 lq_sta
->action_counter
> tbl1
->max_search
) {
2408 IWL_DEBUG_RATE(priv
, "LQ: STAY in legacy table\n");
2409 rs_set_stay_in_table(priv
, 1, lq_sta
);
2412 /* If we're in an HT mode, and all 3 mode switch actions
2413 * have been tried and compared, stay in this best modulation
2414 * mode for a while before next round of mode comparisons. */
2415 if (lq_sta
->enable_counter
&&
2416 (lq_sta
->action_counter
>= tbl1
->max_search
) &&
2417 iwl_ht_enabled(priv
)) {
2418 if ((lq_sta
->last_tpt
> IWL_AGG_TPT_THREHOLD
) &&
2419 (lq_sta
->tx_agg_tid_en
& (1 << tid
)) &&
2420 (tid
!= MAX_TID_COUNT
)) {
2422 &priv
->stations
[lq_sta
->lq
.sta_id
].tid
[tid
];
2423 if (tid_data
->agg
.state
== IWL_AGG_OFF
) {
2424 IWL_DEBUG_RATE(priv
,
2425 "try to aggregate tid %d\n",
2427 rs_tl_turn_on_agg(priv
, tid
,
2431 rs_set_stay_in_table(priv
, 0, lq_sta
);
2436 tbl
->current_rate
= rate_n_flags_from_tbl(priv
, tbl
, index
, is_green
);
2438 lq_sta
->last_txrate_idx
= i
;
2444 static void rs_initialize_lq(struct iwl_priv
*priv
,
2445 struct ieee80211_conf
*conf
,
2446 struct ieee80211_sta
*sta
,
2447 struct iwl_lq_sta
*lq_sta
)
2449 struct iwl_scale_tbl_info
*tbl
;
2453 u8 use_green
= rs_use_green(sta
, &priv
->current_ht_config
);
2457 if (!sta
|| !lq_sta
)
2460 i
= lq_sta
->last_txrate_idx
;
2462 if ((lq_sta
->lq
.sta_id
== 0xff) &&
2463 (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
))
2466 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
2468 if (!lq_sta
->search_better_tbl
)
2469 active_tbl
= lq_sta
->active_tbl
;
2471 active_tbl
= 1 - lq_sta
->active_tbl
;
2473 tbl
= &(lq_sta
->lq_info
[active_tbl
]);
2475 if ((i
< 0) || (i
>= IWL_RATE_COUNT
))
2478 rate
= iwl_rates
[i
].plcp
;
2479 tbl
->ant_type
= first_antenna(valid_tx_ant
);
2480 rate
|= tbl
->ant_type
<< RATE_MCS_ANT_POS
;
2482 if (i
>= IWL_FIRST_CCK_RATE
&& i
<= IWL_LAST_CCK_RATE
)
2483 rate
|= RATE_MCS_CCK_MSK
;
2485 rs_get_tbl_info_from_mcs(rate
, priv
->band
, tbl
, &rate_idx
);
2486 if (!rs_is_valid_ant(valid_tx_ant
, tbl
->ant_type
))
2487 rs_toggle_antenna(valid_tx_ant
, &rate
, tbl
);
2489 rate
= rate_n_flags_from_tbl(priv
, tbl
, rate_idx
, use_green
);
2490 tbl
->current_rate
= rate
;
2491 rs_set_expected_tpt_table(lq_sta
, tbl
);
2492 rs_fill_link_cmd(NULL
, lq_sta
, rate
);
2493 iwl_send_lq_cmd(priv
, &lq_sta
->lq
, CMD_ASYNC
);
2498 static void rs_get_rate(void *priv_r
, struct ieee80211_sta
*sta
, void *priv_sta
,
2499 struct ieee80211_tx_rate_control
*txrc
)
2502 struct sk_buff
*skb
= txrc
->skb
;
2503 struct ieee80211_supported_band
*sband
= txrc
->sband
;
2504 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_r
;
2505 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
2506 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2507 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2508 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2509 struct iwl_lq_sta
*lq_sta
= priv_sta
;
2512 IWL_DEBUG_RATE_LIMIT(priv
, "rate scale calculate new rate for skb\n");
2514 /* Get max rate if user set max rate */
2516 lq_sta
->max_rate_idx
= txrc
->max_rate_idx
;
2517 if ((sband
->band
== IEEE80211_BAND_5GHZ
) &&
2518 (lq_sta
->max_rate_idx
!= -1))
2519 lq_sta
->max_rate_idx
+= IWL_FIRST_OFDM_RATE
;
2520 if ((lq_sta
->max_rate_idx
< 0) ||
2521 (lq_sta
->max_rate_idx
>= IWL_RATE_COUNT
))
2522 lq_sta
->max_rate_idx
= -1;
2525 /* Send management frames and NO_ACK data using lowest rate. */
2526 if (rate_control_send_low(sta
, priv_sta
, txrc
))
2529 rate_idx
= lq_sta
->last_txrate_idx
;
2531 if ((priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) &&
2532 !lq_sta
->ibss_sta_added
) {
2533 u8 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
2535 if (sta_id
== IWL_INVALID_STATION
) {
2536 IWL_DEBUG_RATE(priv
, "LQ: ADD station %pM\n",
2538 sta_id
= iwl_add_station(priv
, hdr
->addr1
,
2539 false, CMD_ASYNC
, ht_cap
);
2541 if ((sta_id
!= IWL_INVALID_STATION
)) {
2542 lq_sta
->lq
.sta_id
= sta_id
;
2543 lq_sta
->lq
.rs_table
[0].rate_n_flags
= 0;
2544 lq_sta
->ibss_sta_added
= 1;
2545 rs_initialize_lq(priv
, conf
, sta
, lq_sta
);
2549 if (lq_sta
->last_rate_n_flags
& RATE_MCS_HT_MSK
) {
2550 rate_idx
-= IWL_FIRST_OFDM_RATE
;
2551 /* 6M and 9M shared same MCS index */
2552 rate_idx
= (rate_idx
> 0) ? (rate_idx
- 1) : 0;
2553 if (rs_extract_rate(lq_sta
->last_rate_n_flags
) >=
2554 IWL_RATE_MIMO3_6M_PLCP
)
2555 rate_idx
= rate_idx
+ (2 * MCS_INDEX_PER_STREAM
);
2556 else if (rs_extract_rate(lq_sta
->last_rate_n_flags
) >=
2557 IWL_RATE_MIMO2_6M_PLCP
)
2558 rate_idx
= rate_idx
+ MCS_INDEX_PER_STREAM
;
2559 info
->control
.rates
[0].flags
= IEEE80211_TX_RC_MCS
;
2560 if (lq_sta
->last_rate_n_flags
& RATE_MCS_SGI_MSK
)
2561 info
->control
.rates
[0].flags
|= IEEE80211_TX_RC_SHORT_GI
;
2562 if (lq_sta
->last_rate_n_flags
& RATE_MCS_DUP_MSK
)
2563 info
->control
.rates
[0].flags
|= IEEE80211_TX_RC_DUP_DATA
;
2564 if (lq_sta
->last_rate_n_flags
& RATE_MCS_HT40_MSK
)
2565 info
->control
.rates
[0].flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
2566 if (lq_sta
->last_rate_n_flags
& RATE_MCS_GF_MSK
)
2567 info
->control
.rates
[0].flags
|= IEEE80211_TX_RC_GREEN_FIELD
;
2569 /* Check for invalid rates */
2570 if ((rate_idx
< 0) || (rate_idx
>= IWL_RATE_COUNT_LEGACY
) ||
2571 ((sband
->band
== IEEE80211_BAND_5GHZ
) &&
2572 (rate_idx
< IWL_FIRST_OFDM_RATE
)))
2573 rate_idx
= rate_lowest_index(sband
, sta
);
2574 /* On valid 5 GHz rate, adjust index */
2575 else if (sband
->band
== IEEE80211_BAND_5GHZ
)
2576 rate_idx
-= IWL_FIRST_OFDM_RATE
;
2577 info
->control
.rates
[0].flags
= 0;
2579 info
->control
.rates
[0].idx
= rate_idx
;
2583 static void *rs_alloc_sta(void *priv_rate
, struct ieee80211_sta
*sta
,
2586 struct iwl_lq_sta
*lq_sta
;
2587 struct iwl_priv
*priv
;
2590 priv
= (struct iwl_priv
*)priv_rate
;
2591 IWL_DEBUG_RATE(priv
, "create station rate scale window\n");
2593 lq_sta
= kzalloc(sizeof(struct iwl_lq_sta
), gfp
);
2597 lq_sta
->lq
.sta_id
= 0xff;
2600 for (j
= 0; j
< LQ_SIZE
; j
++)
2601 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
2602 rs_rate_scale_clear_window(&lq_sta
->lq_info
[j
].win
[i
]);
2607 static void rs_rate_init(void *priv_r
, struct ieee80211_supported_band
*sband
,
2608 struct ieee80211_sta
*sta
, void *priv_sta
)
2611 struct iwl_priv
*priv
= (struct iwl_priv
*)priv_r
;
2612 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
2613 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2614 struct iwl_lq_sta
*lq_sta
= priv_sta
;
2616 lq_sta
->flush_timer
= 0;
2617 lq_sta
->supp_rates
= sta
->supp_rates
[sband
->band
];
2618 for (j
= 0; j
< LQ_SIZE
; j
++)
2619 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
2620 rs_rate_scale_clear_window(&lq_sta
->lq_info
[j
].win
[i
]);
2622 IWL_DEBUG_RATE(priv
, "LQ: *** rate scale station global init ***\n");
2623 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2624 * the lowest or the highest rate.. Could consider using RSSI from
2625 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2628 lq_sta
->ibss_sta_added
= 0;
2629 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
2630 u8 sta_id
= iwl_find_station(priv
,
2633 /* for IBSS the call are from tasklet */
2634 IWL_DEBUG_RATE(priv
, "LQ: ADD station %pM\n", sta
->addr
);
2636 if (sta_id
== IWL_INVALID_STATION
) {
2637 IWL_DEBUG_RATE(priv
, "LQ: ADD station %pM\n", sta
->addr
);
2638 sta_id
= iwl_add_station(priv
, sta
->addr
, false,
2641 if ((sta_id
!= IWL_INVALID_STATION
)) {
2642 lq_sta
->lq
.sta_id
= sta_id
;
2643 lq_sta
->lq
.rs_table
[0].rate_n_flags
= 0;
2645 /* FIXME: this is w/a remove it later */
2646 priv
->assoc_station_added
= 1;
2650 lq_sta
->max_rate_idx
= -1;
2651 lq_sta
->missed_rate_counter
= IWL_MISSED_RATE_MAX
;
2652 lq_sta
->is_green
= rs_use_green(sta
, &priv
->current_ht_config
);
2653 lq_sta
->active_legacy_rate
= priv
->active_rate
& ~(0x1000);
2654 lq_sta
->active_rate_basic
= priv
->active_rate_basic
;
2655 lq_sta
->band
= priv
->band
;
2657 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2658 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2660 lq_sta
->active_siso_rate
= ht_cap
->mcs
.rx_mask
[0] << 1;
2661 lq_sta
->active_siso_rate
|= ht_cap
->mcs
.rx_mask
[0] & 0x1;
2662 lq_sta
->active_siso_rate
&= ~((u16
)0x2);
2663 lq_sta
->active_siso_rate
<<= IWL_FIRST_OFDM_RATE
;
2666 lq_sta
->active_mimo2_rate
= ht_cap
->mcs
.rx_mask
[1] << 1;
2667 lq_sta
->active_mimo2_rate
|= ht_cap
->mcs
.rx_mask
[1] & 0x1;
2668 lq_sta
->active_mimo2_rate
&= ~((u16
)0x2);
2669 lq_sta
->active_mimo2_rate
<<= IWL_FIRST_OFDM_RATE
;
2671 lq_sta
->active_mimo3_rate
= ht_cap
->mcs
.rx_mask
[2] << 1;
2672 lq_sta
->active_mimo3_rate
|= ht_cap
->mcs
.rx_mask
[2] & 0x1;
2673 lq_sta
->active_mimo3_rate
&= ~((u16
)0x2);
2674 lq_sta
->active_mimo3_rate
<<= IWL_FIRST_OFDM_RATE
;
2676 IWL_DEBUG_RATE(priv
, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
2677 lq_sta
->active_siso_rate
,
2678 lq_sta
->active_mimo2_rate
,
2679 lq_sta
->active_mimo3_rate
);
2681 /* These values will be overridden later */
2682 lq_sta
->lq
.general_params
.single_stream_ant_msk
= ANT_A
;
2683 lq_sta
->lq
.general_params
.dual_stream_ant_msk
= ANT_AB
;
2685 /* as default allow aggregation for all tids */
2686 lq_sta
->tx_agg_tid_en
= IWL_AGG_ALL_TID
;
2689 /* Set last_txrate_idx to lowest rate */
2690 lq_sta
->last_txrate_idx
= rate_lowest_index(sband
, sta
);
2691 if (sband
->band
== IEEE80211_BAND_5GHZ
)
2692 lq_sta
->last_txrate_idx
+= IWL_FIRST_OFDM_RATE
;
2694 rs_initialize_lq(priv
, conf
, sta
, lq_sta
);
2697 static void rs_fill_link_cmd(struct iwl_priv
*priv
,
2698 struct iwl_lq_sta
*lq_sta
, u32 new_rate
)
2700 struct iwl_scale_tbl_info tbl_type
;
2703 int repeat_rate
= 0;
2704 u8 ant_toggle_cnt
= 0;
2705 u8 use_ht_possible
= 1;
2706 u8 valid_tx_ant
= 0;
2707 struct iwl_link_quality_cmd
*lq_cmd
= &lq_sta
->lq
;
2709 /* Override starting rate (index 0) if needed for debug purposes */
2710 rs_dbgfs_set_mcs(lq_sta
, &new_rate
, index
);
2712 /* Interpret new_rate (rate_n_flags) */
2713 memset(&tbl_type
, 0, sizeof(tbl_type
));
2714 rs_get_tbl_info_from_mcs(new_rate
, lq_sta
->band
,
2715 &tbl_type
, &rate_idx
);
2717 /* How many times should we repeat the initial rate? */
2718 if (is_legacy(tbl_type
.lq_type
)) {
2720 repeat_rate
= IWL_NUMBER_TRY
;
2722 repeat_rate
= IWL_HT_NUMBER_TRY
;
2725 lq_cmd
->general_params
.mimo_delimiter
=
2726 is_mimo(tbl_type
.lq_type
) ? 1 : 0;
2728 /* Fill 1st table entry (index 0) */
2729 lq_cmd
->rs_table
[index
].rate_n_flags
= cpu_to_le32(new_rate
);
2731 if (num_of_ant(tbl_type
.ant_type
) == 1) {
2732 lq_cmd
->general_params
.single_stream_ant_msk
=
2734 } else if (num_of_ant(tbl_type
.ant_type
) == 2) {
2735 lq_cmd
->general_params
.dual_stream_ant_msk
=
2737 } /* otherwise we don't modify the existing value */
2743 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
2745 /* Fill rest of rate table */
2746 while (index
< LINK_QUAL_MAX_RETRY_NUM
) {
2747 /* Repeat initial/next rate.
2748 * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
2749 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
2750 while (repeat_rate
> 0 && (index
< LINK_QUAL_MAX_RETRY_NUM
)) {
2751 if (is_legacy(tbl_type
.lq_type
)) {
2752 if (ant_toggle_cnt
< NUM_TRY_BEFORE_ANT_TOGGLE
)
2755 rs_toggle_antenna(valid_tx_ant
,
2756 &new_rate
, &tbl_type
))
2760 /* Override next rate if needed for debug purposes */
2761 rs_dbgfs_set_mcs(lq_sta
, &new_rate
, index
);
2763 /* Fill next table entry */
2764 lq_cmd
->rs_table
[index
].rate_n_flags
=
2765 cpu_to_le32(new_rate
);
2770 rs_get_tbl_info_from_mcs(new_rate
, lq_sta
->band
, &tbl_type
,
2773 /* Indicate to uCode which entries might be MIMO.
2774 * If initial rate was MIMO, this will finally end up
2775 * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
2776 if (is_mimo(tbl_type
.lq_type
))
2777 lq_cmd
->general_params
.mimo_delimiter
= index
;
2780 new_rate
= rs_get_lower_rate(lq_sta
, &tbl_type
, rate_idx
,
2783 /* How many times should we repeat the next rate? */
2784 if (is_legacy(tbl_type
.lq_type
)) {
2785 if (ant_toggle_cnt
< NUM_TRY_BEFORE_ANT_TOGGLE
)
2788 rs_toggle_antenna(valid_tx_ant
,
2789 &new_rate
, &tbl_type
))
2792 repeat_rate
= IWL_NUMBER_TRY
;
2794 repeat_rate
= IWL_HT_NUMBER_TRY
;
2797 /* Don't allow HT rates after next pass.
2798 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
2799 use_ht_possible
= 0;
2801 /* Override next rate if needed for debug purposes */
2802 rs_dbgfs_set_mcs(lq_sta
, &new_rate
, index
);
2804 /* Fill next table entry */
2805 lq_cmd
->rs_table
[index
].rate_n_flags
= cpu_to_le32(new_rate
);
2811 lq_cmd
->agg_params
.agg_frame_cnt_limit
= LINK_QUAL_AGG_FRAME_LIMIT_MAX
;
2812 lq_cmd
->agg_params
.agg_dis_start_th
= LINK_QUAL_AGG_DISABLE_START_DEF
;
2813 lq_cmd
->agg_params
.agg_time_limit
=
2814 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
2817 static void *rs_alloc(struct ieee80211_hw
*hw
, struct dentry
*debugfsdir
)
2821 /* rate scale requires free function to be implemented */
2822 static void rs_free(void *priv_rate
)
2827 static void rs_free_sta(void *priv_r
, struct ieee80211_sta
*sta
,
2830 struct iwl_lq_sta
*lq_sta
= priv_sta
;
2831 struct iwl_priv
*priv __maybe_unused
= priv_r
;
2833 IWL_DEBUG_RATE(priv
, "enter\n");
2835 IWL_DEBUG_RATE(priv
, "leave\n");
2839 #ifdef CONFIG_MAC80211_DEBUGFS
2840 static int open_file_generic(struct inode
*inode
, struct file
*file
)
2842 file
->private_data
= inode
->i_private
;
2845 static void rs_dbgfs_set_mcs(struct iwl_lq_sta
*lq_sta
,
2846 u32
*rate_n_flags
, int index
)
2848 struct iwl_priv
*priv
;
2853 valid_tx_ant
= priv
->hw_params
.valid_tx_ant
;
2854 if (lq_sta
->dbg_fixed_rate
) {
2856 ((lq_sta
->dbg_fixed_rate
& RATE_MCS_ANT_ABC_MSK
)
2857 >> RATE_MCS_ANT_POS
);
2858 if ((valid_tx_ant
& ant_sel_tx
) == ant_sel_tx
) {
2859 *rate_n_flags
= lq_sta
->dbg_fixed_rate
;
2860 IWL_DEBUG_RATE(priv
, "Fixed rate ON\n");
2862 lq_sta
->dbg_fixed_rate
= 0;
2864 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
2865 ant_sel_tx
, valid_tx_ant
);
2866 IWL_DEBUG_RATE(priv
, "Fixed rate OFF\n");
2869 IWL_DEBUG_RATE(priv
, "Fixed rate OFF\n");
2873 static ssize_t
rs_sta_dbgfs_scale_table_write(struct file
*file
,
2874 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2876 struct iwl_lq_sta
*lq_sta
= file
->private_data
;
2877 struct iwl_priv
*priv
;
2883 memset(buf
, 0, sizeof(buf
));
2884 buf_size
= min(count
, sizeof(buf
) - 1);
2885 if (copy_from_user(buf
, user_buf
, buf_size
))
2888 if (sscanf(buf
, "%x", &parsed_rate
) == 1)
2889 lq_sta
->dbg_fixed_rate
= parsed_rate
;
2891 lq_sta
->dbg_fixed_rate
= 0;
2893 lq_sta
->active_legacy_rate
= 0x0FFF; /* 1 - 54 MBits, includes CCK */
2894 lq_sta
->active_siso_rate
= 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2895 lq_sta
->active_mimo2_rate
= 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2896 lq_sta
->active_mimo3_rate
= 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2898 IWL_DEBUG_RATE(priv
, "sta_id %d rate 0x%X\n",
2899 lq_sta
->lq
.sta_id
, lq_sta
->dbg_fixed_rate
);
2901 if (lq_sta
->dbg_fixed_rate
) {
2902 rs_fill_link_cmd(NULL
, lq_sta
, lq_sta
->dbg_fixed_rate
);
2903 iwl_send_lq_cmd(lq_sta
->drv
, &lq_sta
->lq
, CMD_ASYNC
);
2909 static ssize_t
rs_sta_dbgfs_scale_table_read(struct file
*file
,
2910 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2918 struct iwl_lq_sta
*lq_sta
= file
->private_data
;
2919 struct iwl_priv
*priv
;
2920 struct iwl_scale_tbl_info
*tbl
= &(lq_sta
->lq_info
[lq_sta
->active_tbl
]);
2923 buff
= kmalloc(1024, GFP_KERNEL
);
2927 desc
+= sprintf(buff
+desc
, "sta_id %d\n", lq_sta
->lq
.sta_id
);
2928 desc
+= sprintf(buff
+desc
, "failed=%d success=%d rate=0%X\n",
2929 lq_sta
->total_failed
, lq_sta
->total_success
,
2930 lq_sta
->active_legacy_rate
);
2931 desc
+= sprintf(buff
+desc
, "fixed rate 0x%X\n",
2932 lq_sta
->dbg_fixed_rate
);
2933 desc
+= sprintf(buff
+desc
, "valid_tx_ant %s%s%s\n",
2934 (priv
->hw_params
.valid_tx_ant
& ANT_A
) ? "ANT_A," : "",
2935 (priv
->hw_params
.valid_tx_ant
& ANT_B
) ? "ANT_B," : "",
2936 (priv
->hw_params
.valid_tx_ant
& ANT_C
) ? "ANT_C" : "");
2937 desc
+= sprintf(buff
+desc
, "lq type %s\n",
2938 (is_legacy(tbl
->lq_type
)) ? "legacy" : "HT");
2939 if (is_Ht(tbl
->lq_type
)) {
2940 desc
+= sprintf(buff
+desc
, " %s",
2941 (is_siso(tbl
->lq_type
)) ? "SISO" :
2942 ((is_mimo2(tbl
->lq_type
)) ? "MIMO2" : "MIMO3"));
2943 desc
+= sprintf(buff
+desc
, " %s",
2944 (tbl
->is_ht40
) ? "40MHz" : "20MHz");
2945 desc
+= sprintf(buff
+desc
, " %s %s\n", (tbl
->is_SGI
) ? "SGI" : "",
2946 (lq_sta
->is_green
) ? "GF enabled" : "");
2948 desc
+= sprintf(buff
+desc
, "last tx rate=0x%X\n",
2949 lq_sta
->last_rate_n_flags
);
2950 desc
+= sprintf(buff
+desc
, "general:"
2951 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2952 lq_sta
->lq
.general_params
.flags
,
2953 lq_sta
->lq
.general_params
.mimo_delimiter
,
2954 lq_sta
->lq
.general_params
.single_stream_ant_msk
,
2955 lq_sta
->lq
.general_params
.dual_stream_ant_msk
);
2957 desc
+= sprintf(buff
+desc
, "agg:"
2958 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2959 le16_to_cpu(lq_sta
->lq
.agg_params
.agg_time_limit
),
2960 lq_sta
->lq
.agg_params
.agg_dis_start_th
,
2961 lq_sta
->lq
.agg_params
.agg_frame_cnt_limit
);
2963 desc
+= sprintf(buff
+desc
,
2964 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2965 lq_sta
->lq
.general_params
.start_rate_index
[0],
2966 lq_sta
->lq
.general_params
.start_rate_index
[1],
2967 lq_sta
->lq
.general_params
.start_rate_index
[2],
2968 lq_sta
->lq
.general_params
.start_rate_index
[3]);
2970 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
2971 index
= iwl_hwrate_to_plcp_idx(
2972 le32_to_cpu(lq_sta
->lq
.rs_table
[i
].rate_n_flags
));
2973 if (is_legacy(tbl
->lq_type
)) {
2974 desc
+= sprintf(buff
+desc
, " rate[%d] 0x%X %smbps\n",
2975 i
, le32_to_cpu(lq_sta
->lq
.rs_table
[i
].rate_n_flags
),
2976 iwl_rate_mcs
[index
].mbps
);
2978 desc
+= sprintf(buff
+desc
, " rate[%d] 0x%X %smbps (%s)\n",
2979 i
, le32_to_cpu(lq_sta
->lq
.rs_table
[i
].rate_n_flags
),
2980 iwl_rate_mcs
[index
].mbps
, iwl_rate_mcs
[index
].mcs
);
2984 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
2989 static const struct file_operations rs_sta_dbgfs_scale_table_ops
= {
2990 .write
= rs_sta_dbgfs_scale_table_write
,
2991 .read
= rs_sta_dbgfs_scale_table_read
,
2992 .open
= open_file_generic
,
2994 static ssize_t
rs_sta_dbgfs_stats_table_read(struct file
*file
,
2995 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
3002 struct iwl_lq_sta
*lq_sta
= file
->private_data
;
3004 buff
= kmalloc(1024, GFP_KERNEL
);
3008 for (i
= 0; i
< LQ_SIZE
; i
++) {
3009 desc
+= sprintf(buff
+desc
,
3010 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
3012 lq_sta
->active_tbl
== i
? "*" : "x",
3013 lq_sta
->lq_info
[i
].lq_type
,
3014 lq_sta
->lq_info
[i
].is_SGI
,
3015 lq_sta
->lq_info
[i
].is_ht40
,
3016 lq_sta
->lq_info
[i
].is_dup
,
3018 lq_sta
->lq_info
[i
].current_rate
);
3019 for (j
= 0; j
< IWL_RATE_COUNT
; j
++) {
3020 desc
+= sprintf(buff
+desc
,
3021 "counter=%d success=%d %%=%d\n",
3022 lq_sta
->lq_info
[i
].win
[j
].counter
,
3023 lq_sta
->lq_info
[i
].win
[j
].success_counter
,
3024 lq_sta
->lq_info
[i
].win
[j
].success_ratio
);
3027 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
3032 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
3033 .read
= rs_sta_dbgfs_stats_table_read
,
3034 .open
= open_file_generic
,
3037 static ssize_t
rs_sta_dbgfs_rate_scale_data_read(struct file
*file
,
3038 char __user
*user_buf
, size_t count
, loff_t
*ppos
)
3044 struct iwl_lq_sta
*lq_sta
= file
->private_data
;
3045 struct iwl_priv
*priv
;
3046 struct iwl_scale_tbl_info
*tbl
= &lq_sta
->lq_info
[lq_sta
->active_tbl
];
3050 if (is_Ht(tbl
->lq_type
))
3051 desc
+= sprintf(buff
+desc
,
3052 "Bit Rate= %d Mb/s\n",
3053 tbl
->expected_tpt
[lq_sta
->last_txrate_idx
]);
3055 desc
+= sprintf(buff
+desc
,
3056 "Bit Rate= %d Mb/s\n",
3057 iwl_rates
[lq_sta
->last_txrate_idx
].ieee
>> 1);
3058 desc
+= sprintf(buff
+desc
,
3059 "Signal Level= %d dBm\tNoise Level= %d dBm\n",
3060 priv
->last_rx_rssi
, priv
->last_rx_noise
);
3061 desc
+= sprintf(buff
+desc
,
3062 "Tsf= 0x%llx\tBeacon time= 0x%08X\n",
3063 priv
->last_tsf
, priv
->last_beacon_time
);
3065 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
3069 static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops
= {
3070 .read
= rs_sta_dbgfs_rate_scale_data_read
,
3071 .open
= open_file_generic
,
3074 static void rs_add_debugfs(void *priv
, void *priv_sta
,
3077 struct iwl_lq_sta
*lq_sta
= priv_sta
;
3078 lq_sta
->rs_sta_dbgfs_scale_table_file
=
3079 debugfs_create_file("rate_scale_table", 0600, dir
,
3080 lq_sta
, &rs_sta_dbgfs_scale_table_ops
);
3081 lq_sta
->rs_sta_dbgfs_stats_table_file
=
3082 debugfs_create_file("rate_stats_table", 0600, dir
,
3083 lq_sta
, &rs_sta_dbgfs_stats_table_ops
);
3084 lq_sta
->rs_sta_dbgfs_rate_scale_data_file
=
3085 debugfs_create_file("rate_scale_data", 0600, dir
,
3086 lq_sta
, &rs_sta_dbgfs_rate_scale_data_ops
);
3087 lq_sta
->rs_sta_dbgfs_tx_agg_tid_en_file
=
3088 debugfs_create_u8("tx_agg_tid_enable", 0600, dir
,
3089 &lq_sta
->tx_agg_tid_en
);
3093 static void rs_remove_debugfs(void *priv
, void *priv_sta
)
3095 struct iwl_lq_sta
*lq_sta
= priv_sta
;
3096 debugfs_remove(lq_sta
->rs_sta_dbgfs_scale_table_file
);
3097 debugfs_remove(lq_sta
->rs_sta_dbgfs_stats_table_file
);
3098 debugfs_remove(lq_sta
->rs_sta_dbgfs_rate_scale_data_file
);
3099 debugfs_remove(lq_sta
->rs_sta_dbgfs_tx_agg_tid_en_file
);
3103 static struct rate_control_ops rs_ops
= {
3106 .tx_status
= rs_tx_status
,
3107 .get_rate
= rs_get_rate
,
3108 .rate_init
= rs_rate_init
,
3111 .alloc_sta
= rs_alloc_sta
,
3112 .free_sta
= rs_free_sta
,
3113 #ifdef CONFIG_MAC80211_DEBUGFS
3114 .add_sta_debugfs
= rs_add_debugfs
,
3115 .remove_sta_debugfs
= rs_remove_debugfs
,
3119 int iwlagn_rate_control_register(void)
3121 return ieee80211_rate_control_register(&rs_ops
);
3124 void iwlagn_rate_control_unregister(void)
3126 ieee80211_rate_control_unregister(&rs_ops
);