1 /******************************************************************************
3 * Copyright(c) 2005 - 2011 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/slab.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>
41 #define IL4965_RS_NAME "iwl-4965-rs"
43 #define NUM_TRY_BEFORE_ANT_TOGGLE 1
44 #define IL_NUMBER_TRY 1
45 #define IL_HT_NUMBER_TRY 3
47 #define RATE_MAX_WINDOW 62 /* # tx in history win */
48 #define RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
49 #define RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
51 /* max allowed rate miss before sync LQ cmd */
52 #define IL_MISSED_RATE_MAX 15
53 /* max time to accum history 2 seconds */
54 #define RATE_SCALE_FLUSH_INTVL (3*HZ)
56 static u8 rs_ht_to_legacy[] = {
57 RATE_6M_IDX, RATE_6M_IDX,
58 RATE_6M_IDX, RATE_6M_IDX,
60 RATE_6M_IDX, RATE_9M_IDX,
61 RATE_12M_IDX, RATE_18M_IDX,
62 RATE_24M_IDX, RATE_36M_IDX,
63 RATE_48M_IDX, RATE_54M_IDX
66 static const u8 ant_toggle_lookup[] = {
67 /*ANT_NONE -> */ ANT_NONE,
70 /*ANT_AB -> */ ANT_BC,
72 /*ANT_AC -> */ ANT_AB,
73 /*ANT_BC -> */ ANT_AC,
74 /*ANT_ABC -> */ ANT_ABC,
77 #define IL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
78 [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
79 RATE_SISO_##s##M_PLCP, \
80 RATE_MIMO2_##s##M_PLCP,\
91 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
93 * If there isn't a valid next or previous rate then INV is used which
94 * maps to RATE_INVALID
97 const struct il_rate_info il_rates[RATE_COUNT] = {
98 IL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
99 IL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
100 IL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
101 IL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
102 IL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
103 IL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
104 IL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
105 IL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
106 IL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
107 IL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
108 IL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
109 IL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
110 IL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
113 static int il4965_hwrate_to_plcp_idx(u32 rate_n_flags)
118 if (rate_n_flags & RATE_MCS_HT_MSK) {
119 idx = (rate_n_flags & 0xff);
121 if (idx >= RATE_MIMO2_6M_PLCP)
122 idx = idx - RATE_MIMO2_6M_PLCP;
124 idx += IL_FIRST_OFDM_RATE;
125 /* skip 9M not supported in ht*/
126 if (idx >= RATE_9M_IDX)
128 if (idx >= IL_FIRST_OFDM_RATE && idx <= IL_LAST_OFDM_RATE)
131 /* legacy rate format, search for match in table */
133 for (idx = 0; idx < ARRAY_SIZE(il_rates); idx++)
134 if (il_rates[idx].plcp == (rate_n_flags & 0xFF))
141 static void il4965_rs_rate_scale_perform(struct il_priv *il,
143 struct ieee80211_sta *sta,
144 struct il_lq_sta *lq_sta);
145 static void il4965_rs_fill_link_cmd(struct il_priv *il,
146 struct il_lq_sta *lq_sta, u32 rate_n_flags);
147 static void il4965_rs_stay_in_table(struct il_lq_sta *lq_sta,
150 #ifdef CONFIG_MAC80211_DEBUGFS
151 static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
152 u32 *rate_n_flags, int idx);
154 static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
155 u32 *rate_n_flags, int idx)
160 * The following tables contain the expected throughput metrics for all rates
162 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
164 * where invalid entries are zeros.
166 * CCK rates are only valid in legacy table and will only be used in G
170 static s32 expected_tpt_legacy[RATE_COUNT] = {
171 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0
174 static s32 expected_tpt_siso20MHz[4][RATE_COUNT] = {
175 {0, 0, 0, 0, 42, 0, 76, 102, 124, 158, 183, 193, 202}, /* Norm */
176 {0, 0, 0, 0, 46, 0, 82, 110, 132, 167, 192, 202, 210}, /* SGI */
177 {0, 0, 0, 0, 48, 0, 93, 135, 176, 251, 319, 351, 381}, /* AGG */
178 {0, 0, 0, 0, 53, 0, 102, 149, 193, 275, 348, 381, 413}, /* AGG+SGI */
181 static s32 expected_tpt_siso40MHz[4][RATE_COUNT] = {
182 {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */
183 {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */
184 {0, 0, 0, 0, 96, 0, 182, 259, 328, 451, 553, 598, 640}, /* AGG */
185 {0, 0, 0, 0, 106, 0, 199, 282, 357, 487, 593, 640, 683}, /* AGG+SGI */
188 static s32 expected_tpt_mimo2_20MHz[4][RATE_COUNT] = {
189 {0, 0, 0, 0, 74, 0, 123, 155, 179, 213, 235, 243, 250}, /* Norm */
190 {0, 0, 0, 0, 81, 0, 131, 164, 187, 221, 242, 250, 256}, /* SGI */
191 {0, 0, 0, 0, 92, 0, 175, 250, 317, 436, 534, 578, 619}, /* AGG */
192 {0, 0, 0, 0, 102, 0, 192, 273, 344, 470, 573, 619, 660}, /* AGG+SGI*/
195 static s32 expected_tpt_mimo2_40MHz[4][RATE_COUNT] = {
196 {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */
197 {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */
198 {0, 0, 0, 0, 180, 0, 327, 446, 545, 708, 828, 878, 922}, /* AGG */
199 {0, 0, 0, 0, 197, 0, 355, 481, 584, 752, 872, 922, 966}, /* AGG+SGI */
203 static const struct il_rate_mcs_info il_rate_mcs[RATE_COUNT] = {
212 { "24", "16QAM 1/2"},
213 { "36", "16QAM 3/4"},
214 { "48", "64QAM 2/3"},
215 { "54", "64QAM 3/4"},
216 { "60", "64QAM 5/6"},
219 #define MCS_IDX_PER_STREAM (8)
221 static inline u8 il4965_rs_extract_rate(u32 rate_n_flags)
223 return (u8)(rate_n_flags & 0xFF);
227 il4965_rs_rate_scale_clear_win(struct il_rate_scale_data *win)
230 win->success_counter = 0;
231 win->success_ratio = IL_INVALID_VALUE;
233 win->average_tpt = IL_INVALID_VALUE;
237 static inline u8 il4965_rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
239 return (ant_type & valid_antenna) == ant_type;
243 * removes the old data from the stats. All data that is older than
244 * TID_MAX_TIME_DIFF, will be deleted.
247 il4965_rs_tl_rm_old_stats(struct il_traffic_load *tl, u32 curr_time)
249 /* The oldest age we want to keep */
250 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
252 while (tl->queue_count && tl->time_stamp < oldest_time) {
253 tl->total -= tl->packet_count[tl->head];
254 tl->packet_count[tl->head] = 0;
255 tl->time_stamp += TID_QUEUE_CELL_SPACING;
258 if (tl->head >= TID_QUEUE_MAX_SIZE)
264 * increment traffic load value for tid and also remove
265 * any old values if passed the certain time period
267 static u8 il4965_rs_tl_add_packet(struct il_lq_sta *lq_data,
268 struct ieee80211_hdr *hdr)
270 u32 curr_time = jiffies_to_msecs(jiffies);
273 struct il_traffic_load *tl = NULL;
276 if (ieee80211_is_data_qos(hdr->frame_control)) {
277 u8 *qc = ieee80211_get_qos_ctl(hdr);
280 return MAX_TID_COUNT;
282 if (unlikely(tid >= TID_MAX_LOAD_COUNT))
283 return MAX_TID_COUNT;
285 tl = &lq_data->load[tid];
287 curr_time -= curr_time % TID_ROUND_VALUE;
289 /* Happens only for the first packet. Initialize the data */
290 if (!(tl->queue_count)) {
292 tl->time_stamp = curr_time;
295 tl->packet_count[0] = 1;
296 return MAX_TID_COUNT;
299 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
300 idx = time_diff / TID_QUEUE_CELL_SPACING;
302 /* The history is too long: remove data that is older than */
303 /* TID_MAX_TIME_DIFF */
304 if (idx >= TID_QUEUE_MAX_SIZE)
305 il4965_rs_tl_rm_old_stats(tl, curr_time);
307 idx = (tl->head + idx) % TID_QUEUE_MAX_SIZE;
308 tl->packet_count[idx] = tl->packet_count[idx] + 1;
309 tl->total = tl->total + 1;
311 if ((idx + 1) > tl->queue_count)
312 tl->queue_count = idx + 1;
318 get the traffic load value for tid
320 static u32 il4965_rs_tl_get_load(struct il_lq_sta *lq_data, u8 tid)
322 u32 curr_time = jiffies_to_msecs(jiffies);
325 struct il_traffic_load *tl = NULL;
327 if (tid >= TID_MAX_LOAD_COUNT)
330 tl = &(lq_data->load[tid]);
332 curr_time -= curr_time % TID_ROUND_VALUE;
334 if (!(tl->queue_count))
337 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
338 idx = time_diff / TID_QUEUE_CELL_SPACING;
340 /* The history is too long: remove data that is older than */
341 /* TID_MAX_TIME_DIFF */
342 if (idx >= TID_QUEUE_MAX_SIZE)
343 il4965_rs_tl_rm_old_stats(tl, curr_time);
348 static int il4965_rs_tl_turn_on_agg_for_tid(struct il_priv *il,
349 struct il_lq_sta *lq_data, u8 tid,
350 struct ieee80211_sta *sta)
355 load = il4965_rs_tl_get_load(lq_data, tid);
357 if (load > IL_AGG_LOAD_THRESHOLD) {
358 D_HT("Starting Tx agg: STA: %pM tid: %d\n",
360 ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
361 if (ret == -EAGAIN) {
363 * driver and mac80211 is out of sync
364 * this might be cause by reloading firmware
365 * stop the tx ba session here
367 IL_ERR("Fail start Tx agg on tid: %d\n",
369 ieee80211_stop_tx_ba_session(sta, tid);
372 IL_ERR("Aggregation not enabled for tid %d "
373 "because load = %u\n", tid, load);
378 static void il4965_rs_tl_turn_on_agg(struct il_priv *il, u8 tid,
379 struct il_lq_sta *lq_data,
380 struct ieee80211_sta *sta)
382 if (tid < TID_MAX_LOAD_COUNT)
383 il4965_rs_tl_turn_on_agg_for_tid(il, lq_data, tid, sta);
385 IL_ERR("tid exceeds max load count: %d/%d\n",
386 tid, TID_MAX_LOAD_COUNT);
389 static inline int il4965_get_il4965_num_of_ant_from_rate(u32 rate_n_flags)
391 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
392 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
393 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
397 * Static function to get the expected throughput from an il_scale_tbl_info
398 * that wraps a NULL pointer check
401 il4965_get_expected_tpt(struct il_scale_tbl_info *tbl, int rs_idx)
403 if (tbl->expected_tpt)
404 return tbl->expected_tpt[rs_idx];
409 * il4965_rs_collect_tx_data - Update the success/failure sliding win
411 * We keep a sliding win of the last 62 packets transmitted
412 * at this rate. win->data contains the bitmask of successful
415 static int il4965_rs_collect_tx_data(struct il_scale_tbl_info *tbl,
416 int scale_idx, int attempts, int successes)
418 struct il_rate_scale_data *win = NULL;
419 static const u64 mask = (((u64)1) << (RATE_MAX_WINDOW - 1));
422 if (scale_idx < 0 || scale_idx >= RATE_COUNT)
425 /* Select win for current tx bit rate */
426 win = &(tbl->win[scale_idx]);
428 /* Get expected throughput */
429 tpt = il4965_get_expected_tpt(tbl, scale_idx);
432 * Keep track of only the latest 62 tx frame attempts in this rate's
433 * history win; anything older isn't really relevant any more.
434 * If we have filled up the sliding win, drop the oldest attempt;
435 * if the oldest attempt (highest bit in bitmap) shows "success",
436 * subtract "1" from the success counter (this is the main reason
437 * we keep these bitmaps!).
439 while (attempts > 0) {
440 if (win->counter >= RATE_MAX_WINDOW) {
442 /* remove earliest */
443 win->counter = RATE_MAX_WINDOW - 1;
445 if (win->data & mask) {
447 win->success_counter--;
451 /* Increment frames-attempted counter */
454 /* Shift bitmap by one frame to throw away oldest history */
457 /* Mark the most recent #successes attempts as successful */
459 win->success_counter++;
467 /* Calculate current success ratio, avoid divide-by-0! */
468 if (win->counter > 0)
469 win->success_ratio = 128 * (100 * win->success_counter)
472 win->success_ratio = IL_INVALID_VALUE;
474 fail_count = win->counter - win->success_counter;
476 /* Calculate average throughput, if we have enough history. */
477 if (fail_count >= RATE_MIN_FAILURE_TH ||
478 win->success_counter >= RATE_MIN_SUCCESS_TH)
479 win->average_tpt = (win->success_ratio * tpt + 64) / 128;
481 win->average_tpt = IL_INVALID_VALUE;
483 /* Tag this win as having been updated */
484 win->stamp = jiffies;
490 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
492 static u32 il4965_rate_n_flags_from_tbl(struct il_priv *il,
493 struct il_scale_tbl_info *tbl,
494 int idx, u8 use_green)
496 u32 rate_n_flags = 0;
498 if (is_legacy(tbl->lq_type)) {
499 rate_n_flags = il_rates[idx].plcp;
500 if (idx >= IL_FIRST_CCK_RATE && idx <= IL_LAST_CCK_RATE)
501 rate_n_flags |= RATE_MCS_CCK_MSK;
503 } else if (is_Ht(tbl->lq_type)) {
504 if (idx > IL_LAST_OFDM_RATE) {
505 IL_ERR("Invalid HT rate idx %d\n", idx);
506 idx = IL_LAST_OFDM_RATE;
508 rate_n_flags = RATE_MCS_HT_MSK;
510 if (is_siso(tbl->lq_type))
511 rate_n_flags |= il_rates[idx].plcp_siso;
513 rate_n_flags |= il_rates[idx].plcp_mimo2;
515 IL_ERR("Invalid tbl->lq_type %d\n", tbl->lq_type);
518 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
519 RATE_MCS_ANT_ABC_MSK);
521 if (is_Ht(tbl->lq_type)) {
524 rate_n_flags |= RATE_MCS_DUP_MSK;
526 rate_n_flags |= RATE_MCS_HT40_MSK;
529 rate_n_flags |= RATE_MCS_SGI_MSK;
532 rate_n_flags |= RATE_MCS_GF_MSK;
533 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
534 rate_n_flags &= ~RATE_MCS_SGI_MSK;
535 IL_ERR("GF was set with SGI:SISO\n");
543 * Interpret uCode API's rate_n_flags format,
544 * fill "search" or "active" tx mode table.
546 static int il4965_rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
547 enum ieee80211_band band,
548 struct il_scale_tbl_info *tbl,
551 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
552 u8 il4965_num_of_ant = il4965_get_il4965_num_of_ant_from_rate(rate_n_flags);
555 memset(tbl, 0, sizeof(struct il_scale_tbl_info));
556 *rate_idx = il4965_hwrate_to_plcp_idx(rate_n_flags);
558 if (*rate_idx == RATE_INVALID) {
562 tbl->is_SGI = 0; /* default legacy setup */
565 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
566 tbl->lq_type = LQ_NONE;
567 tbl->max_search = IL_MAX_SEARCH;
569 /* legacy rate format */
570 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
571 if (il4965_num_of_ant == 1) {
572 if (band == IEEE80211_BAND_5GHZ)
579 if (rate_n_flags & RATE_MCS_SGI_MSK)
582 if ((rate_n_flags & RATE_MCS_HT40_MSK) ||
583 (rate_n_flags & RATE_MCS_DUP_MSK))
586 if (rate_n_flags & RATE_MCS_DUP_MSK)
589 mcs = il4965_rs_extract_rate(rate_n_flags);
592 if (mcs <= RATE_SISO_60M_PLCP) {
593 if (il4965_num_of_ant == 1)
594 tbl->lq_type = LQ_SISO; /*else NONE*/
597 if (il4965_num_of_ant == 2)
598 tbl->lq_type = LQ_MIMO2;
604 /* switch to another antenna/antennas and return 1 */
605 /* if no other valid antenna found, return 0 */
606 static int il4965_rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
607 struct il_scale_tbl_info *tbl)
611 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
614 if (!il4965_rs_is_valid_ant(valid_ant, tbl->ant_type))
617 new_ant_type = ant_toggle_lookup[tbl->ant_type];
619 while (new_ant_type != tbl->ant_type &&
620 !il4965_rs_is_valid_ant(valid_ant, new_ant_type))
621 new_ant_type = ant_toggle_lookup[new_ant_type];
623 if (new_ant_type == tbl->ant_type)
626 tbl->ant_type = new_ant_type;
627 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
628 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
633 * Green-field mode is valid if the station supports it and
634 * there are no non-GF stations present in the BSS.
636 static bool il4965_rs_use_green(struct ieee80211_sta *sta)
638 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
639 struct il_rxon_context *ctx = sta_priv->common.ctx;
641 return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
642 !(ctx->ht.non_gf_sta_present);
646 * il4965_rs_get_supported_rates - get the available rates
648 * if management frame or broadcast frame only return
649 * basic available rates.
652 static u16 il4965_rs_get_supported_rates(struct il_lq_sta *lq_sta,
653 struct ieee80211_hdr *hdr,
654 enum il_table_type rate_type)
656 if (is_legacy(rate_type)) {
657 return lq_sta->active_legacy_rate;
659 if (is_siso(rate_type))
660 return lq_sta->active_siso_rate;
662 return lq_sta->active_mimo2_rate;
667 il4965_rs_get_adjacent_rate(struct il_priv *il, u8 idx, u16 rate_mask,
670 u8 high = RATE_INVALID;
671 u8 low = RATE_INVALID;
673 /* 802.11A or ht walks to the next literal adjacent rate in
675 if (is_a_band(rate_type) || !is_legacy(rate_type)) {
679 /* Find the previous rate that is in the rate mask */
681 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
682 if (rate_mask & mask) {
688 /* Find the next rate that is in the rate mask */
690 for (mask = (1 << i); i < RATE_COUNT; i++, mask <<= 1) {
691 if (rate_mask & mask) {
697 return (high << 8) | low;
701 while (low != RATE_INVALID) {
702 low = il_rates[low].prev_rs;
703 if (low == RATE_INVALID)
705 if (rate_mask & (1 << low))
707 D_RATE("Skipping masked lower rate: %d\n", low);
711 while (high != RATE_INVALID) {
712 high = il_rates[high].next_rs;
713 if (high == RATE_INVALID)
715 if (rate_mask & (1 << high))
717 D_RATE("Skipping masked higher rate: %d\n", high);
720 return (high << 8) | low;
723 static u32 il4965_rs_get_lower_rate(struct il_lq_sta *lq_sta,
724 struct il_scale_tbl_info *tbl,
725 u8 scale_idx, u8 ht_possible)
730 u8 switch_to_legacy = 0;
731 u8 is_green = lq_sta->is_green;
732 struct il_priv *il = lq_sta->drv;
734 /* check if we need to switch from HT to legacy rates.
735 * assumption is that mandatory rates (1Mbps or 6Mbps)
736 * are always supported (spec demand) */
737 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_idx)) {
738 switch_to_legacy = 1;
739 scale_idx = rs_ht_to_legacy[scale_idx];
740 if (lq_sta->band == IEEE80211_BAND_5GHZ)
745 if (il4965_num_of_ant(tbl->ant_type) > 1)
747 il4965_first_antenna(il->hw_params.valid_tx_ant);
751 tbl->max_search = IL_MAX_SEARCH;
754 rate_mask = il4965_rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
756 /* Mask with station rate restriction */
757 if (is_legacy(tbl->lq_type)) {
758 /* supp_rates has no CCK bits in A mode */
759 if (lq_sta->band == IEEE80211_BAND_5GHZ)
760 rate_mask = (u16)(rate_mask &
761 (lq_sta->supp_rates << IL_FIRST_OFDM_RATE));
763 rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
766 /* If we switched from HT to legacy, check current rate */
767 if (switch_to_legacy && (rate_mask & (1 << scale_idx))) {
772 high_low = il4965_rs_get_adjacent_rate(lq_sta->drv,
773 scale_idx, rate_mask,
775 low = high_low & 0xff;
777 if (low == RATE_INVALID)
781 return il4965_rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
785 * Simple function to compare two rate scale table types
787 static bool il4965_table_type_matches(struct il_scale_tbl_info *a,
788 struct il_scale_tbl_info *b)
790 return (a->lq_type == b->lq_type && a->ant_type == b->ant_type &&
791 a->is_SGI == b->is_SGI);
795 * mac80211 sends us Tx status
798 il4965_rs_tx_status(void *il_r, struct ieee80211_supported_band *sband,
799 struct ieee80211_sta *sta, void *il_sta,
804 int rs_idx, mac_idx, i;
805 struct il_lq_sta *lq_sta = il_sta;
806 struct il_link_quality_cmd *table;
807 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
808 struct il_priv *il = (struct il_priv *)il_r;
809 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
810 enum mac80211_rate_control_flags mac_flags;
812 struct il_scale_tbl_info tbl_type;
813 struct il_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
814 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
815 struct il_rxon_context *ctx = sta_priv->common.ctx;
818 "get frame ack response, update rate scale win\n");
820 /* Treat uninitialized rate scaling data same as non-existing. */
822 D_RATE("Station rate scaling not created yet.\n");
824 } else if (!lq_sta->drv) {
825 D_RATE("Rate scaling not initialized yet.\n");
829 if (!ieee80211_is_data(hdr->frame_control) ||
830 (info->flags & IEEE80211_TX_CTL_NO_ACK))
833 /* This packet was aggregated but doesn't carry status info */
834 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
835 !(info->flags & IEEE80211_TX_STAT_AMPDU))
839 * Ignore this Tx frame response if its initial rate doesn't match
840 * that of latest Link Quality command. There may be stragglers
841 * from a previous Link Quality command, but we're no longer interested
842 * in those; they're either from the "active" mode while we're trying
843 * to check "search" mode, or a prior "search" mode after we've moved
844 * to a new "search" mode (which might become the new "active" mode).
847 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
848 il4965_rs_get_tbl_info_from_mcs(tx_rate,
849 il->band, &tbl_type, &rs_idx);
850 if (il->band == IEEE80211_BAND_5GHZ)
851 rs_idx -= IL_FIRST_OFDM_RATE;
852 mac_flags = info->status.rates[0].flags;
853 mac_idx = info->status.rates[0].idx;
854 /* For HT packets, map MCS to PLCP */
855 if (mac_flags & IEEE80211_TX_RC_MCS) {
856 mac_idx &= RATE_MCS_CODE_MSK; /* Remove # of streams */
857 if (mac_idx >= (RATE_9M_IDX - IL_FIRST_OFDM_RATE))
860 * mac80211 HT idx is always zero-idxed; we need to move
861 * HT OFDM rates after CCK rates in 2.4 GHz band
863 if (il->band == IEEE80211_BAND_2GHZ)
864 mac_idx += IL_FIRST_OFDM_RATE;
866 /* Here we actually compare this rate to the latest LQ command */
868 tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI) ||
869 tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ||
870 tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA) ||
871 tbl_type.ant_type != info->antenna_sel_tx ||
872 !!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS) ||
873 !!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD) ||
876 "initial rate %d does not match %d (0x%x)\n",
877 mac_idx, rs_idx, tx_rate);
879 * Since rates mis-match, the last LQ command may have failed.
880 * After IL_MISSED_RATE_MAX mis-matches, resync the uCode with
883 lq_sta->missed_rate_counter++;
884 if (lq_sta->missed_rate_counter > IL_MISSED_RATE_MAX) {
885 lq_sta->missed_rate_counter = 0;
886 il_send_lq_cmd(il, ctx, &lq_sta->lq,
889 /* Regardless, ignore this status info for outdated rate */
892 /* Rate did match, so reset the missed_rate_counter */
893 lq_sta->missed_rate_counter = 0;
895 /* Figure out if rate scale algorithm is in active or search table */
896 if (il4965_table_type_matches(&tbl_type,
897 &(lq_sta->lq_info[lq_sta->active_tbl]))) {
898 curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
899 other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
900 } else if (il4965_table_type_matches(&tbl_type,
901 &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
902 curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
903 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
906 "Neither active nor search matches tx rate\n");
907 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
908 D_RATE("active- lq:%x, ant:%x, SGI:%d\n",
909 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
910 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
911 D_RATE("search- lq:%x, ant:%x, SGI:%d\n",
912 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
913 D_RATE("actual- lq:%x, ant:%x, SGI:%d\n",
914 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
916 * no matching table found, let's by-pass the data collection
917 * and continue to perform rate scale to find the rate table
919 il4965_rs_stay_in_table(lq_sta, true);
924 * Updating the frame history depends on whether packets were
927 * For aggregation, all packets were transmitted at the same rate, the
928 * first idx into rate scale table.
930 if (info->flags & IEEE80211_TX_STAT_AMPDU) {
931 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
932 il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band, &tbl_type,
934 il4965_rs_collect_tx_data(curr_tbl, rs_idx,
935 info->status.ampdu_len,
936 info->status.ampdu_ack_len);
938 /* Update success/fail counts if not searching for new mode */
939 if (lq_sta->stay_in_tbl) {
940 lq_sta->total_success += info->status.ampdu_ack_len;
941 lq_sta->total_failed += (info->status.ampdu_len -
942 info->status.ampdu_ack_len);
946 * For legacy, update frame history with for each Tx retry.
948 retries = info->status.rates[0].count - 1;
949 /* HW doesn't send more than 15 retries */
950 retries = min(retries, 15);
952 /* The last transmission may have been successful */
953 legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
954 /* Collect data for each rate used during failed TX attempts */
955 for (i = 0; i <= retries; ++i) {
956 tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
957 il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band,
960 * Only collect stats if retried rate is in the same RS
961 * table as active/search.
963 if (il4965_table_type_matches(&tbl_type, curr_tbl))
965 else if (il4965_table_type_matches(&tbl_type,
970 il4965_rs_collect_tx_data(tmp_tbl, rs_idx, 1,
971 i < retries ? 0 : legacy_success);
974 /* Update success/fail counts if not searching for new mode */
975 if (lq_sta->stay_in_tbl) {
976 lq_sta->total_success += legacy_success;
977 lq_sta->total_failed += retries + (1 - legacy_success);
980 /* The last TX rate is cached in lq_sta; it's set in if/else above */
981 lq_sta->last_rate_n_flags = tx_rate;
983 /* See if there's a better rate or modulation mode to try. */
984 if (sta && sta->supp_rates[sband->band])
985 il4965_rs_rate_scale_perform(il, skb, sta, lq_sta);
989 * Begin a period of staying with a selected modulation mode.
990 * Set "stay_in_tbl" flag to prevent any mode switches.
991 * Set frame tx success limits according to legacy vs. high-throughput,
992 * and reset overall (spanning all rates) tx success history stats.
993 * These control how long we stay using same modulation mode before
994 * searching for a new mode.
996 static void il4965_rs_set_stay_in_table(struct il_priv *il, u8 is_legacy,
997 struct il_lq_sta *lq_sta)
999 D_RATE("we are staying in the same table\n");
1000 lq_sta->stay_in_tbl = 1; /* only place this gets set */
1002 lq_sta->table_count_limit = IL_LEGACY_TBL_COUNT;
1003 lq_sta->max_failure_limit = IL_LEGACY_FAILURE_LIMIT;
1004 lq_sta->max_success_limit = IL_LEGACY_SUCCESS_LIMIT;
1006 lq_sta->table_count_limit = IL_NONE_LEGACY_TBL_COUNT;
1007 lq_sta->max_failure_limit = IL_NONE_LEGACY_FAILURE_LIMIT;
1008 lq_sta->max_success_limit = IL_NONE_LEGACY_SUCCESS_LIMIT;
1010 lq_sta->table_count = 0;
1011 lq_sta->total_failed = 0;
1012 lq_sta->total_success = 0;
1013 lq_sta->flush_timer = jiffies;
1014 lq_sta->action_counter = 0;
1018 * Find correct throughput table for given mode of modulation
1020 static void il4965_rs_set_expected_tpt_table(struct il_lq_sta *lq_sta,
1021 struct il_scale_tbl_info *tbl)
1023 /* Used to choose among HT tables */
1024 s32 (*ht_tbl_pointer)[RATE_COUNT];
1026 /* Check for invalid LQ type */
1027 if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
1028 tbl->expected_tpt = expected_tpt_legacy;
1032 /* Legacy rates have only one table */
1033 if (is_legacy(tbl->lq_type)) {
1034 tbl->expected_tpt = expected_tpt_legacy;
1038 /* Choose among many HT tables depending on number of streams
1039 * (SISO/MIMO2), channel width (20/40), SGI, and aggregation
1041 if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1042 ht_tbl_pointer = expected_tpt_siso20MHz;
1043 else if (is_siso(tbl->lq_type))
1044 ht_tbl_pointer = expected_tpt_siso40MHz;
1045 else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
1046 ht_tbl_pointer = expected_tpt_mimo2_20MHz;
1047 else /* if (is_mimo2(tbl->lq_type)) <-- must be true */
1048 ht_tbl_pointer = expected_tpt_mimo2_40MHz;
1050 if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
1051 tbl->expected_tpt = ht_tbl_pointer[0];
1052 else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
1053 tbl->expected_tpt = ht_tbl_pointer[1];
1054 else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
1055 tbl->expected_tpt = ht_tbl_pointer[2];
1057 tbl->expected_tpt = ht_tbl_pointer[3];
1061 * Find starting rate for new "search" high-throughput mode of modulation.
1062 * Goal is to find lowest expected rate (under perfect conditions) that is
1063 * above the current measured throughput of "active" mode, to give new mode
1064 * a fair chance to prove itself without too many challenges.
1066 * This gets called when transitioning to more aggressive modulation
1067 * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
1068 * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
1069 * to decrease to match "active" throughput. When moving from MIMO to SISO,
1070 * bit rate will typically need to increase, but not if performance was bad.
1072 static s32 il4965_rs_get_best_rate(struct il_priv *il,
1073 struct il_lq_sta *lq_sta,
1074 struct il_scale_tbl_info *tbl, /* "search" */
1075 u16 rate_mask, s8 idx)
1077 /* "active" values */
1078 struct il_scale_tbl_info *active_tbl =
1079 &(lq_sta->lq_info[lq_sta->active_tbl]);
1080 s32 active_sr = active_tbl->win[idx].success_ratio;
1081 s32 active_tpt = active_tbl->expected_tpt[idx];
1083 /* expected "search" throughput */
1084 s32 *tpt_tbl = tbl->expected_tpt;
1086 s32 new_rate, high, low, start_hi;
1090 new_rate = high = low = start_hi = RATE_INVALID;
1093 high_low = il4965_rs_get_adjacent_rate(il, rate, rate_mask,
1096 low = high_low & 0xff;
1097 high = (high_low >> 8) & 0xff;
1100 * Lower the "search" bit rate, to give new "search" mode
1101 * approximately the same throughput as "active" if:
1103 * 1) "Active" mode has been working modestly well (but not
1104 * great), and expected "search" throughput (under perfect
1105 * conditions) at candidate rate is above the actual
1106 * measured "active" throughput (but less than expected
1107 * "active" throughput under perfect conditions).
1109 * 2) "Active" mode has been working perfectly or very well
1110 * and expected "search" throughput (under perfect
1111 * conditions) at candidate rate is above expected
1112 * "active" throughput (under perfect conditions).
1114 if ((100 * tpt_tbl[rate] > lq_sta->last_tpt &&
1115 (active_sr > RATE_DECREASE_TH &&
1116 active_sr <= RATE_HIGH_TH &&
1117 tpt_tbl[rate] <= active_tpt)) ||
1118 (active_sr >= RATE_SCALE_SWITCH &&
1119 tpt_tbl[rate] > active_tpt)) {
1121 /* (2nd or later pass)
1122 * If we've already tried to raise the rate, and are
1123 * now trying to lower it, use the higher rate. */
1124 if (start_hi != RATE_INVALID) {
1125 new_rate = start_hi;
1131 /* Loop again with lower rate */
1132 if (low != RATE_INVALID)
1135 /* Lower rate not available, use the original */
1139 /* Else try to raise the "search" rate to match "active" */
1141 /* (2nd or later pass)
1142 * If we've already tried to lower the rate, and are
1143 * now trying to raise it, use the lower rate. */
1144 if (new_rate != RATE_INVALID)
1147 /* Loop again with higher rate */
1148 else if (high != RATE_INVALID) {
1152 /* Higher rate not available, use the original */
1164 * Set up search table for MIMO2
1166 static int il4965_rs_switch_to_mimo2(struct il_priv *il,
1167 struct il_lq_sta *lq_sta,
1168 struct ieee80211_conf *conf,
1169 struct ieee80211_sta *sta,
1170 struct il_scale_tbl_info *tbl, int idx)
1174 s8 is_green = lq_sta->is_green;
1175 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1176 struct il_rxon_context *ctx = sta_priv->common.ctx;
1178 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1181 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1182 == WLAN_HT_CAP_SM_PS_STATIC)
1185 /* Need both Tx chains/antennas to support MIMO */
1186 if (il->hw_params.tx_chains_num < 2)
1189 D_RATE("LQ: try to switch to MIMO2\n");
1191 tbl->lq_type = LQ_MIMO2;
1192 tbl->is_dup = lq_sta->is_dup;
1194 tbl->max_search = IL_MAX_SEARCH;
1195 rate_mask = lq_sta->active_mimo2_rate;
1197 if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap))
1202 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
1204 rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx);
1206 D_RATE("LQ: MIMO2 best rate %d mask %X\n",
1208 if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) {
1210 "Can't switch with idx %d rate mask %x\n",
1214 tbl->current_rate = il4965_rate_n_flags_from_tbl(il,
1215 tbl, rate, is_green);
1217 D_RATE("LQ: Switch to new mcs %X idx is green %X\n",
1218 tbl->current_rate, is_green);
1223 * Set up search table for SISO
1225 static int il4965_rs_switch_to_siso(struct il_priv *il,
1226 struct il_lq_sta *lq_sta,
1227 struct ieee80211_conf *conf,
1228 struct ieee80211_sta *sta,
1229 struct il_scale_tbl_info *tbl, int idx)
1232 u8 is_green = lq_sta->is_green;
1234 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1235 struct il_rxon_context *ctx = sta_priv->common.ctx;
1237 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1240 D_RATE("LQ: try to switch to SISO\n");
1242 tbl->is_dup = lq_sta->is_dup;
1243 tbl->lq_type = LQ_SISO;
1245 tbl->max_search = IL_MAX_SEARCH;
1246 rate_mask = lq_sta->active_siso_rate;
1248 if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap))
1254 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
1256 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
1257 rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx);
1259 D_RATE("LQ: get best rate %d mask %X\n", rate, rate_mask);
1260 if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) {
1262 "can not switch with idx %d rate mask %x\n",
1266 tbl->current_rate = il4965_rate_n_flags_from_tbl(il,
1267 tbl, rate, is_green);
1268 D_RATE("LQ: Switch to new mcs %X idx is green %X\n",
1269 tbl->current_rate, is_green);
1274 * Try to switch to new modulation mode from legacy
1276 static int il4965_rs_move_legacy_other(struct il_priv *il,
1277 struct il_lq_sta *lq_sta,
1278 struct ieee80211_conf *conf,
1279 struct ieee80211_sta *sta,
1282 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1283 struct il_scale_tbl_info *search_tbl =
1284 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1285 struct il_rate_scale_data *win = &(tbl->win[idx]);
1286 u32 sz = (sizeof(struct il_scale_tbl_info) -
1287 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
1289 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1290 u8 tx_chains_num = il->hw_params.tx_chains_num;
1292 u8 update_search_tbl_counter = 0;
1294 tbl->action = IL_LEGACY_SWITCH_SISO;
1296 start_action = tbl->action;
1298 lq_sta->action_counter++;
1299 switch (tbl->action) {
1300 case IL_LEGACY_SWITCH_ANTENNA1:
1301 case IL_LEGACY_SWITCH_ANTENNA2:
1302 D_RATE("LQ: Legacy toggle Antenna\n");
1304 if ((tbl->action == IL_LEGACY_SWITCH_ANTENNA1 &&
1305 tx_chains_num <= 1) ||
1306 (tbl->action == IL_LEGACY_SWITCH_ANTENNA2 &&
1307 tx_chains_num <= 2))
1310 /* Don't change antenna if success has been great */
1311 if (win->success_ratio >= IL_RS_GOOD_RATIO)
1314 /* Set up search table to try other antenna */
1315 memcpy(search_tbl, tbl, sz);
1317 if (il4965_rs_toggle_antenna(valid_tx_ant,
1318 &search_tbl->current_rate, search_tbl)) {
1319 update_search_tbl_counter = 1;
1320 il4965_rs_set_expected_tpt_table(lq_sta,
1325 case IL_LEGACY_SWITCH_SISO:
1326 D_RATE("LQ: Legacy switch to SISO\n");
1328 /* Set up search table to try SISO */
1329 memcpy(search_tbl, tbl, sz);
1330 search_tbl->is_SGI = 0;
1331 ret = il4965_rs_switch_to_siso(il, lq_sta, conf, sta,
1334 lq_sta->action_counter = 0;
1339 case IL_LEGACY_SWITCH_MIMO2_AB:
1340 case IL_LEGACY_SWITCH_MIMO2_AC:
1341 case IL_LEGACY_SWITCH_MIMO2_BC:
1342 D_RATE("LQ: Legacy switch to MIMO2\n");
1344 /* Set up search table to try MIMO */
1345 memcpy(search_tbl, tbl, sz);
1346 search_tbl->is_SGI = 0;
1348 if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AB)
1349 search_tbl->ant_type = ANT_AB;
1350 else if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AC)
1351 search_tbl->ant_type = ANT_AC;
1353 search_tbl->ant_type = ANT_BC;
1355 if (!il4965_rs_is_valid_ant(valid_tx_ant,
1356 search_tbl->ant_type))
1359 ret = il4965_rs_switch_to_mimo2(il, lq_sta,
1363 lq_sta->action_counter = 0;
1369 if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC)
1370 tbl->action = IL_LEGACY_SWITCH_ANTENNA1;
1372 if (tbl->action == start_action)
1376 search_tbl->lq_type = LQ_NONE;
1380 lq_sta->search_better_tbl = 1;
1382 if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC)
1383 tbl->action = IL_LEGACY_SWITCH_ANTENNA1;
1384 if (update_search_tbl_counter)
1385 search_tbl->action = tbl->action;
1391 * Try to switch to new modulation mode from SISO
1393 static int il4965_rs_move_siso_to_other(struct il_priv *il,
1394 struct il_lq_sta *lq_sta,
1395 struct ieee80211_conf *conf,
1396 struct ieee80211_sta *sta, int idx)
1398 u8 is_green = lq_sta->is_green;
1399 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1400 struct il_scale_tbl_info *search_tbl =
1401 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1402 struct il_rate_scale_data *win = &(tbl->win[idx]);
1403 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1404 u32 sz = (sizeof(struct il_scale_tbl_info) -
1405 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
1407 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1408 u8 tx_chains_num = il->hw_params.tx_chains_num;
1409 u8 update_search_tbl_counter = 0;
1412 start_action = tbl->action;
1415 lq_sta->action_counter++;
1416 switch (tbl->action) {
1417 case IL_SISO_SWITCH_ANTENNA1:
1418 case IL_SISO_SWITCH_ANTENNA2:
1419 D_RATE("LQ: SISO toggle Antenna\n");
1420 if ((tbl->action == IL_SISO_SWITCH_ANTENNA1 &&
1421 tx_chains_num <= 1) ||
1422 (tbl->action == IL_SISO_SWITCH_ANTENNA2 &&
1423 tx_chains_num <= 2))
1426 if (win->success_ratio >= IL_RS_GOOD_RATIO)
1429 memcpy(search_tbl, tbl, sz);
1430 if (il4965_rs_toggle_antenna(valid_tx_ant,
1431 &search_tbl->current_rate, search_tbl)) {
1432 update_search_tbl_counter = 1;
1436 case IL_SISO_SWITCH_MIMO2_AB:
1437 case IL_SISO_SWITCH_MIMO2_AC:
1438 case IL_SISO_SWITCH_MIMO2_BC:
1439 D_RATE("LQ: SISO switch to MIMO2\n");
1440 memcpy(search_tbl, tbl, sz);
1441 search_tbl->is_SGI = 0;
1443 if (tbl->action == IL_SISO_SWITCH_MIMO2_AB)
1444 search_tbl->ant_type = ANT_AB;
1445 else if (tbl->action == IL_SISO_SWITCH_MIMO2_AC)
1446 search_tbl->ant_type = ANT_AC;
1448 search_tbl->ant_type = ANT_BC;
1450 if (!il4965_rs_is_valid_ant(valid_tx_ant,
1451 search_tbl->ant_type))
1454 ret = il4965_rs_switch_to_mimo2(il, lq_sta,
1460 case IL_SISO_SWITCH_GI:
1461 if (!tbl->is_ht40 && !(ht_cap->cap &
1462 IEEE80211_HT_CAP_SGI_20))
1464 if (tbl->is_ht40 && !(ht_cap->cap &
1465 IEEE80211_HT_CAP_SGI_40))
1468 D_RATE("LQ: SISO toggle SGI/NGI\n");
1470 memcpy(search_tbl, tbl, sz);
1476 "SGI was set in GF+SISO\n");
1478 search_tbl->is_SGI = !tbl->is_SGI;
1479 il4965_rs_set_expected_tpt_table(lq_sta, search_tbl);
1481 s32 tpt = lq_sta->last_tpt / 100;
1482 if (tpt >= search_tbl->expected_tpt[idx])
1485 search_tbl->current_rate =
1486 il4965_rate_n_flags_from_tbl(il, search_tbl,
1488 update_search_tbl_counter = 1;
1492 if (tbl->action > IL_SISO_SWITCH_GI)
1493 tbl->action = IL_SISO_SWITCH_ANTENNA1;
1495 if (tbl->action == start_action)
1498 search_tbl->lq_type = LQ_NONE;
1502 lq_sta->search_better_tbl = 1;
1504 if (tbl->action > IL_SISO_SWITCH_GI)
1505 tbl->action = IL_SISO_SWITCH_ANTENNA1;
1506 if (update_search_tbl_counter)
1507 search_tbl->action = tbl->action;
1513 * Try to switch to new modulation mode from MIMO2
1515 static int il4965_rs_move_mimo2_to_other(struct il_priv *il,
1516 struct il_lq_sta *lq_sta,
1517 struct ieee80211_conf *conf,
1518 struct ieee80211_sta *sta, int idx)
1520 s8 is_green = lq_sta->is_green;
1521 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1522 struct il_scale_tbl_info *search_tbl =
1523 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1524 struct il_rate_scale_data *win = &(tbl->win[idx]);
1525 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1526 u32 sz = (sizeof(struct il_scale_tbl_info) -
1527 (sizeof(struct il_rate_scale_data) * RATE_COUNT));
1529 u8 valid_tx_ant = il->hw_params.valid_tx_ant;
1530 u8 tx_chains_num = il->hw_params.tx_chains_num;
1531 u8 update_search_tbl_counter = 0;
1534 start_action = tbl->action;
1536 lq_sta->action_counter++;
1537 switch (tbl->action) {
1538 case IL_MIMO2_SWITCH_ANTENNA1:
1539 case IL_MIMO2_SWITCH_ANTENNA2:
1540 D_RATE("LQ: MIMO2 toggle Antennas\n");
1542 if (tx_chains_num <= 2)
1545 if (win->success_ratio >= IL_RS_GOOD_RATIO)
1548 memcpy(search_tbl, tbl, sz);
1549 if (il4965_rs_toggle_antenna(valid_tx_ant,
1550 &search_tbl->current_rate, search_tbl)) {
1551 update_search_tbl_counter = 1;
1555 case IL_MIMO2_SWITCH_SISO_A:
1556 case IL_MIMO2_SWITCH_SISO_B:
1557 case IL_MIMO2_SWITCH_SISO_C:
1558 D_RATE("LQ: MIMO2 switch to SISO\n");
1560 /* Set up new search table for SISO */
1561 memcpy(search_tbl, tbl, sz);
1563 if (tbl->action == IL_MIMO2_SWITCH_SISO_A)
1564 search_tbl->ant_type = ANT_A;
1565 else if (tbl->action == IL_MIMO2_SWITCH_SISO_B)
1566 search_tbl->ant_type = ANT_B;
1568 search_tbl->ant_type = ANT_C;
1570 if (!il4965_rs_is_valid_ant(valid_tx_ant,
1571 search_tbl->ant_type))
1574 ret = il4965_rs_switch_to_siso(il, lq_sta,
1582 case IL_MIMO2_SWITCH_GI:
1583 if (!tbl->is_ht40 && !(ht_cap->cap &
1584 IEEE80211_HT_CAP_SGI_20))
1586 if (tbl->is_ht40 && !(ht_cap->cap &
1587 IEEE80211_HT_CAP_SGI_40))
1590 D_RATE("LQ: MIMO2 toggle SGI/NGI\n");
1592 /* Set up new search table for MIMO2 */
1593 memcpy(search_tbl, tbl, sz);
1594 search_tbl->is_SGI = !tbl->is_SGI;
1595 il4965_rs_set_expected_tpt_table(lq_sta, search_tbl);
1597 * If active table already uses the fastest possible
1598 * modulation (dual stream with short guard interval),
1599 * and it's working well, there's no need to look
1600 * for a better type of modulation!
1603 s32 tpt = lq_sta->last_tpt / 100;
1604 if (tpt >= search_tbl->expected_tpt[idx])
1607 search_tbl->current_rate =
1608 il4965_rate_n_flags_from_tbl(il, search_tbl,
1610 update_search_tbl_counter = 1;
1615 if (tbl->action > IL_MIMO2_SWITCH_GI)
1616 tbl->action = IL_MIMO2_SWITCH_ANTENNA1;
1618 if (tbl->action == start_action)
1621 search_tbl->lq_type = LQ_NONE;
1624 lq_sta->search_better_tbl = 1;
1626 if (tbl->action > IL_MIMO2_SWITCH_GI)
1627 tbl->action = IL_MIMO2_SWITCH_ANTENNA1;
1628 if (update_search_tbl_counter)
1629 search_tbl->action = tbl->action;
1636 * Check whether we should continue using same modulation mode, or
1637 * begin search for a new mode, based on:
1638 * 1) # tx successes or failures while using this mode
1639 * 2) # times calling this function
1640 * 3) elapsed time in this mode (not used, for now)
1643 il4965_rs_stay_in_table(struct il_lq_sta *lq_sta, bool force_search)
1645 struct il_scale_tbl_info *tbl;
1648 int flush_interval_passed = 0;
1652 active_tbl = lq_sta->active_tbl;
1654 tbl = &(lq_sta->lq_info[active_tbl]);
1656 /* If we've been disallowing search, see if we should now allow it */
1657 if (lq_sta->stay_in_tbl) {
1659 /* Elapsed time using current modulation mode */
1660 if (lq_sta->flush_timer)
1661 flush_interval_passed =
1663 (unsigned long)(lq_sta->flush_timer +
1664 RATE_SCALE_FLUSH_INTVL));
1667 * Check if we should allow search for new modulation mode.
1668 * If many frames have failed or succeeded, or we've used
1669 * this same modulation for a long time, allow search, and
1670 * reset history stats that keep track of whether we should
1671 * allow a new search. Also (below) reset all bitmaps and
1672 * stats in active history.
1675 lq_sta->total_failed > lq_sta->max_failure_limit ||
1676 lq_sta->total_success > lq_sta->max_success_limit ||
1677 (!lq_sta->search_better_tbl && lq_sta->flush_timer &&
1678 flush_interval_passed)) {
1679 D_RATE("LQ: stay is expired %d %d %d\n:",
1680 lq_sta->total_failed,
1681 lq_sta->total_success,
1682 flush_interval_passed);
1684 /* Allow search for new mode */
1685 lq_sta->stay_in_tbl = 0; /* only place reset */
1686 lq_sta->total_failed = 0;
1687 lq_sta->total_success = 0;
1688 lq_sta->flush_timer = 0;
1691 * Else if we've used this modulation mode enough repetitions
1692 * (regardless of elapsed time or success/failure), reset
1693 * history bitmaps and rate-specific stats for all rates in
1697 lq_sta->table_count++;
1698 if (lq_sta->table_count >=
1699 lq_sta->table_count_limit) {
1700 lq_sta->table_count = 0;
1703 "LQ: stay in table clear win\n");
1704 for (i = 0; i < RATE_COUNT; i++)
1705 il4965_rs_rate_scale_clear_win(
1710 /* If transitioning to allow "search", reset all history
1711 * bitmaps and stats in active table (this will become the new
1712 * "search" table). */
1713 if (!lq_sta->stay_in_tbl) {
1714 for (i = 0; i < RATE_COUNT; i++)
1715 il4965_rs_rate_scale_clear_win(
1722 * setup rate table in uCode
1723 * return rate_n_flags as used in the table
1725 static u32 il4965_rs_update_rate_tbl(struct il_priv *il,
1726 struct il_rxon_context *ctx,
1727 struct il_lq_sta *lq_sta,
1728 struct il_scale_tbl_info *tbl,
1729 int idx, u8 is_green)
1733 /* Update uCode's rate table. */
1734 rate = il4965_rate_n_flags_from_tbl(il, tbl, idx, is_green);
1735 il4965_rs_fill_link_cmd(il, lq_sta, rate);
1736 il_send_lq_cmd(il, ctx, &lq_sta->lq, CMD_ASYNC, false);
1742 * Do rate scaling and search for new modulation mode.
1744 static void il4965_rs_rate_scale_perform(struct il_priv *il,
1745 struct sk_buff *skb,
1746 struct ieee80211_sta *sta,
1747 struct il_lq_sta *lq_sta)
1749 struct ieee80211_hw *hw = il->hw;
1750 struct ieee80211_conf *conf = &hw->conf;
1751 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1752 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1753 int low = RATE_INVALID;
1754 int high = RATE_INVALID;
1757 struct il_rate_scale_data *win = NULL;
1758 int current_tpt = IL_INVALID_VALUE;
1759 int low_tpt = IL_INVALID_VALUE;
1760 int high_tpt = IL_INVALID_VALUE;
1762 s8 scale_action = 0;
1765 struct il_scale_tbl_info *tbl, *tbl1;
1766 u16 rate_scale_idx_msk = 0;
1773 u8 tid = MAX_TID_COUNT;
1774 struct il_tid_data *tid_data;
1775 struct il_station_priv *sta_priv = (void *)sta->drv_priv;
1776 struct il_rxon_context *ctx = sta_priv->common.ctx;
1778 D_RATE("rate scale calculate new rate for skb\n");
1780 /* Send management frames and NO_ACK data using lowest rate. */
1781 /* TODO: this could probably be improved.. */
1782 if (!ieee80211_is_data(hdr->frame_control) ||
1783 (info->flags & IEEE80211_TX_CTL_NO_ACK))
1786 if (!sta || !lq_sta)
1789 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
1791 tid = il4965_rs_tl_add_packet(lq_sta, hdr);
1792 if (tid != MAX_TID_COUNT && (lq_sta->tx_agg_tid_en & (1 << tid))) {
1793 tid_data = &il->stations[lq_sta->lq.sta_id].tid[tid];
1794 if (tid_data->agg.state == IL_AGG_OFF)
1802 * Select rate-scale / modulation-mode table to work with in
1803 * the rest of this function: "search" if searching for better
1804 * modulation mode, or "active" if doing rate scaling within a mode.
1806 if (!lq_sta->search_better_tbl)
1807 active_tbl = lq_sta->active_tbl;
1809 active_tbl = 1 - lq_sta->active_tbl;
1811 tbl = &(lq_sta->lq_info[active_tbl]);
1812 if (is_legacy(tbl->lq_type))
1813 lq_sta->is_green = 0;
1815 lq_sta->is_green = il4965_rs_use_green(sta);
1816 is_green = lq_sta->is_green;
1818 /* current tx rate */
1819 idx = lq_sta->last_txrate_idx;
1821 D_RATE("Rate scale idx %d for type %d\n", idx,
1824 /* rates available for this association, and for modulation mode */
1825 rate_mask = il4965_rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
1827 D_RATE("mask 0x%04X\n", rate_mask);
1829 /* mask with station rate restriction */
1830 if (is_legacy(tbl->lq_type)) {
1831 if (lq_sta->band == IEEE80211_BAND_5GHZ)
1832 /* supp_rates has no CCK bits in A mode */
1833 rate_scale_idx_msk = (u16) (rate_mask &
1834 (lq_sta->supp_rates << IL_FIRST_OFDM_RATE));
1836 rate_scale_idx_msk = (u16) (rate_mask &
1837 lq_sta->supp_rates);
1840 rate_scale_idx_msk = rate_mask;
1842 if (!rate_scale_idx_msk)
1843 rate_scale_idx_msk = rate_mask;
1845 if (!((1 << idx) & rate_scale_idx_msk)) {
1846 IL_ERR("Current Rate is not valid\n");
1847 if (lq_sta->search_better_tbl) {
1848 /* revert to active table if search table is not valid*/
1849 tbl->lq_type = LQ_NONE;
1850 lq_sta->search_better_tbl = 0;
1851 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1852 /* get "active" rate info */
1853 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
1854 rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta,
1855 tbl, idx, is_green);
1860 /* Get expected throughput table and history win for current rate */
1861 if (!tbl->expected_tpt) {
1862 IL_ERR("tbl->expected_tpt is NULL\n");
1866 /* force user max rate if set by user */
1867 if (lq_sta->max_rate_idx != -1 &&
1868 lq_sta->max_rate_idx < idx) {
1869 idx = lq_sta->max_rate_idx;
1871 win = &(tbl->win[idx]);
1875 win = &(tbl->win[idx]);
1878 * If there is not enough history to calculate actual average
1879 * throughput, keep analyzing results of more tx frames, without
1880 * changing rate or mode (bypass most of the rest of this function).
1881 * Set up new rate table in uCode only if old rate is not supported
1882 * in current association (use new rate found above).
1884 fail_count = win->counter - win->success_counter;
1885 if (fail_count < RATE_MIN_FAILURE_TH &&
1886 win->success_counter < RATE_MIN_SUCCESS_TH) {
1887 D_RATE("LQ: still below TH. succ=%d total=%d "
1889 win->success_counter, win->counter, idx);
1891 /* Can't calculate this yet; not enough history */
1892 win->average_tpt = IL_INVALID_VALUE;
1894 /* Should we stay with this modulation mode,
1895 * or search for a new one? */
1896 il4965_rs_stay_in_table(lq_sta, false);
1900 /* Else we have enough samples; calculate estimate of
1901 * actual average throughput */
1902 if (win->average_tpt != ((win->success_ratio *
1903 tbl->expected_tpt[idx] + 64) / 128)) {
1905 "expected_tpt should have been calculated by now\n");
1906 win->average_tpt = ((win->success_ratio *
1907 tbl->expected_tpt[idx] + 64) / 128);
1910 /* If we are searching for better modulation mode, check success. */
1911 if (lq_sta->search_better_tbl) {
1912 /* If good success, continue using the "search" mode;
1913 * no need to send new link quality command, since we're
1914 * continuing to use the setup that we've been trying. */
1915 if (win->average_tpt > lq_sta->last_tpt) {
1917 D_RATE("LQ: SWITCHING TO NEW TBL "
1918 "suc=%d cur-tpt=%d old-tpt=%d\n",
1923 if (!is_legacy(tbl->lq_type))
1924 lq_sta->enable_counter = 1;
1926 /* Swap tables; "search" becomes "active" */
1927 lq_sta->active_tbl = active_tbl;
1928 current_tpt = win->average_tpt;
1930 /* Else poor success; go back to mode in "active" table */
1933 D_RATE("LQ: GOING BACK TO THE OLD TBL "
1934 "suc=%d cur-tpt=%d old-tpt=%d\n",
1939 /* Nullify "search" table */
1940 tbl->lq_type = LQ_NONE;
1942 /* Revert to "active" table */
1943 active_tbl = lq_sta->active_tbl;
1944 tbl = &(lq_sta->lq_info[active_tbl]);
1946 /* Revert to "active" rate and throughput info */
1947 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
1948 current_tpt = lq_sta->last_tpt;
1950 /* Need to set up a new rate table in uCode */
1954 /* Either way, we've made a decision; modulation mode
1955 * search is done, allow rate adjustment next time. */
1956 lq_sta->search_better_tbl = 0;
1957 done_search = 1; /* Don't switch modes below! */
1961 /* (Else) not in search of better modulation mode, try for better
1962 * starting rate, while staying in this mode. */
1963 high_low = il4965_rs_get_adjacent_rate(il, idx,
1966 low = high_low & 0xff;
1967 high = (high_low >> 8) & 0xff;
1969 /* If user set max rate, dont allow higher than user constrain */
1970 if (lq_sta->max_rate_idx != -1 &&
1971 lq_sta->max_rate_idx < high)
1972 high = RATE_INVALID;
1974 sr = win->success_ratio;
1976 /* Collect measured throughputs for current and adjacent rates */
1977 current_tpt = win->average_tpt;
1978 if (low != RATE_INVALID)
1979 low_tpt = tbl->win[low].average_tpt;
1980 if (high != RATE_INVALID)
1981 high_tpt = tbl->win[high].average_tpt;
1985 /* Too many failures, decrease rate */
1986 if (sr <= RATE_DECREASE_TH || current_tpt == 0) {
1988 "decrease rate because of low success_ratio\n");
1991 /* No throughput measured yet for adjacent rates; try increase. */
1992 } else if (low_tpt == IL_INVALID_VALUE &&
1993 high_tpt == IL_INVALID_VALUE) {
1995 if (high != RATE_INVALID && sr >= RATE_INCREASE_TH)
1997 else if (low != RATE_INVALID)
2001 /* Both adjacent throughputs are measured, but neither one has better
2002 * throughput; we're using the best rate, don't change it! */
2003 else if (low_tpt != IL_INVALID_VALUE && high_tpt != IL_INVALID_VALUE &&
2004 low_tpt < current_tpt && high_tpt < current_tpt)
2007 /* At least one adjacent rate's throughput is measured,
2008 * and may have better performance. */
2010 /* Higher adjacent rate's throughput is measured */
2011 if (high_tpt != IL_INVALID_VALUE) {
2012 /* Higher rate has better throughput */
2013 if (high_tpt > current_tpt &&
2014 sr >= RATE_INCREASE_TH) {
2020 /* Lower adjacent rate's throughput is measured */
2021 } else if (low_tpt != IL_INVALID_VALUE) {
2022 /* Lower rate has better throughput */
2023 if (low_tpt > current_tpt) {
2025 "decrease rate because of low tpt\n");
2027 } else if (sr >= RATE_INCREASE_TH) {
2033 /* Sanity check; asked for decrease, but success rate or throughput
2034 * has been good at old rate. Don't change it. */
2035 if (scale_action == -1 && low != RATE_INVALID &&
2036 (sr > RATE_HIGH_TH || current_tpt > 100 * tbl->expected_tpt[low]))
2039 switch (scale_action) {
2041 /* Decrease starting rate, update uCode's rate table */
2042 if (low != RATE_INVALID) {
2049 /* Increase starting rate, update uCode's rate table */
2050 if (high != RATE_INVALID) {
2062 D_RATE("choose rate scale idx %d action %d low %d "
2063 "high %d type %d\n",
2064 idx, scale_action, low, high, tbl->lq_type);
2067 /* Replace uCode's rate table for the destination station. */
2069 rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta,
2070 tbl, idx, is_green);
2072 /* Should we stay with this modulation mode,
2073 * or search for a new one? */
2074 il4965_rs_stay_in_table(lq_sta, false);
2077 * Search for new modulation mode if we're:
2078 * 1) Not changing rates right now
2079 * 2) Not just finishing up a search
2080 * 3) Allowing a new search
2082 if (!update_lq && !done_search && !lq_sta->stay_in_tbl &&
2084 /* Save current throughput to compare with "search" throughput*/
2085 lq_sta->last_tpt = current_tpt;
2087 /* Select a new "search" modulation mode to try.
2088 * If one is found, set up the new "search" table. */
2089 if (is_legacy(tbl->lq_type))
2090 il4965_rs_move_legacy_other(il, lq_sta,
2092 else if (is_siso(tbl->lq_type))
2093 il4965_rs_move_siso_to_other(il, lq_sta,
2095 else /* (is_mimo2(tbl->lq_type)) */
2096 il4965_rs_move_mimo2_to_other(il, lq_sta,
2099 /* If new "search" mode was selected, set up in uCode table */
2100 if (lq_sta->search_better_tbl) {
2101 /* Access the "search" table, clear its history. */
2102 tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
2103 for (i = 0; i < RATE_COUNT; i++)
2104 il4965_rs_rate_scale_clear_win(
2107 /* Use new "search" start rate */
2108 idx = il4965_hwrate_to_plcp_idx(tbl->current_rate);
2111 "Switch current mcs: %X idx: %d\n",
2112 tbl->current_rate, idx);
2113 il4965_rs_fill_link_cmd(il, lq_sta,
2115 il_send_lq_cmd(il, ctx,
2116 &lq_sta->lq, CMD_ASYNC, false);
2121 if (done_search && !lq_sta->stay_in_tbl) {
2122 /* If the "active" (non-search) mode was legacy,
2123 * and we've tried switching antennas,
2124 * but we haven't been able to try HT modes (not available),
2125 * stay with best antenna legacy modulation for a while
2126 * before next round of mode comparisons. */
2127 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2128 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
2129 lq_sta->action_counter > tbl1->max_search) {
2130 D_RATE("LQ: STAY in legacy table\n");
2131 il4965_rs_set_stay_in_table(il, 1, lq_sta);
2134 /* If we're in an HT mode, and all 3 mode switch actions
2135 * have been tried and compared, stay in this best modulation
2136 * mode for a while before next round of mode comparisons. */
2137 if (lq_sta->enable_counter &&
2138 lq_sta->action_counter >= tbl1->max_search) {
2139 if (lq_sta->last_tpt > IL_AGG_TPT_THREHOLD &&
2140 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2141 tid != MAX_TID_COUNT) {
2143 &il->stations[lq_sta->lq.sta_id].tid[tid];
2144 if (tid_data->agg.state == IL_AGG_OFF) {
2146 "try to aggregate tid %d\n",
2148 il4965_rs_tl_turn_on_agg(il, tid,
2152 il4965_rs_set_stay_in_table(il, 0, lq_sta);
2157 tbl->current_rate = il4965_rate_n_flags_from_tbl(il, tbl,
2160 lq_sta->last_txrate_idx = i;
2164 * il4965_rs_initialize_lq - Initialize a station's hardware rate table
2166 * The uCode's station table contains a table of fallback rates
2167 * for automatic fallback during transmission.
2169 * NOTE: This sets up a default set of values. These will be replaced later
2170 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
2173 * NOTE: Run C_ADD_STA command to set up station table entry, before
2174 * calling this function (which runs C_TX_LINK_QUALITY_CMD,
2175 * which requires station table entry to exist).
2177 static void il4965_rs_initialize_lq(struct il_priv *il,
2178 struct ieee80211_conf *conf,
2179 struct ieee80211_sta *sta,
2180 struct il_lq_sta *lq_sta)
2182 struct il_scale_tbl_info *tbl;
2186 u8 use_green = il4965_rs_use_green(sta);
2189 struct il_station_priv *sta_priv;
2190 struct il_rxon_context *ctx;
2192 if (!sta || !lq_sta)
2195 sta_priv = (void *)sta->drv_priv;
2196 ctx = sta_priv->common.ctx;
2198 i = lq_sta->last_txrate_idx;
2200 valid_tx_ant = il->hw_params.valid_tx_ant;
2202 if (!lq_sta->search_better_tbl)
2203 active_tbl = lq_sta->active_tbl;
2205 active_tbl = 1 - lq_sta->active_tbl;
2207 tbl = &(lq_sta->lq_info[active_tbl]);
2209 if (i < 0 || i >= RATE_COUNT)
2212 rate = il_rates[i].plcp;
2213 tbl->ant_type = il4965_first_antenna(valid_tx_ant);
2214 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
2216 if (i >= IL_FIRST_CCK_RATE && i <= IL_LAST_CCK_RATE)
2217 rate |= RATE_MCS_CCK_MSK;
2219 il4965_rs_get_tbl_info_from_mcs(rate, il->band, tbl, &rate_idx);
2220 if (!il4965_rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2221 il4965_rs_toggle_antenna(valid_tx_ant, &rate, tbl);
2223 rate = il4965_rate_n_flags_from_tbl(il, tbl, rate_idx, use_green);
2224 tbl->current_rate = rate;
2225 il4965_rs_set_expected_tpt_table(lq_sta, tbl);
2226 il4965_rs_fill_link_cmd(NULL, lq_sta, rate);
2227 il->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
2228 il_send_lq_cmd(il, ctx, &lq_sta->lq, CMD_SYNC, true);
2232 il4965_rs_get_rate(void *il_r, struct ieee80211_sta *sta, void *il_sta,
2233 struct ieee80211_tx_rate_control *txrc)
2236 struct sk_buff *skb = txrc->skb;
2237 struct ieee80211_supported_band *sband = txrc->sband;
2238 struct il_priv *il __maybe_unused = (struct il_priv *)il_r;
2239 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2240 struct il_lq_sta *lq_sta = il_sta;
2243 D_RATE("rate scale calculate new rate for skb\n");
2245 /* Get max rate if user set max rate */
2247 lq_sta->max_rate_idx = txrc->max_rate_idx;
2248 if (sband->band == IEEE80211_BAND_5GHZ &&
2249 lq_sta->max_rate_idx != -1)
2250 lq_sta->max_rate_idx += IL_FIRST_OFDM_RATE;
2251 if (lq_sta->max_rate_idx < 0 ||
2252 lq_sta->max_rate_idx >= RATE_COUNT)
2253 lq_sta->max_rate_idx = -1;
2256 /* Treat uninitialized rate scaling data same as non-existing. */
2257 if (lq_sta && !lq_sta->drv) {
2258 D_RATE("Rate scaling not initialized yet.\n");
2262 /* Send management frames and NO_ACK data using lowest rate. */
2263 if (rate_control_send_low(sta, il_sta, txrc))
2269 rate_idx = lq_sta->last_txrate_idx;
2271 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
2272 rate_idx -= IL_FIRST_OFDM_RATE;
2273 /* 6M and 9M shared same MCS idx */
2274 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2275 if (il4965_rs_extract_rate(lq_sta->last_rate_n_flags) >=
2277 rate_idx = rate_idx + MCS_IDX_PER_STREAM;
2278 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2279 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2280 info->control.rates[0].flags |=
2281 IEEE80211_TX_RC_SHORT_GI;
2282 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2283 info->control.rates[0].flags |=
2284 IEEE80211_TX_RC_DUP_DATA;
2285 if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK)
2286 info->control.rates[0].flags |=
2287 IEEE80211_TX_RC_40_MHZ_WIDTH;
2288 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2289 info->control.rates[0].flags |=
2290 IEEE80211_TX_RC_GREEN_FIELD;
2292 /* Check for invalid rates */
2293 if (rate_idx < 0 || rate_idx >= RATE_COUNT_LEGACY ||
2294 (sband->band == IEEE80211_BAND_5GHZ &&
2295 rate_idx < IL_FIRST_OFDM_RATE))
2296 rate_idx = rate_lowest_index(sband, sta);
2297 /* On valid 5 GHz rate, adjust idx */
2298 else if (sband->band == IEEE80211_BAND_5GHZ)
2299 rate_idx -= IL_FIRST_OFDM_RATE;
2300 info->control.rates[0].flags = 0;
2302 info->control.rates[0].idx = rate_idx;
2306 static void *il4965_rs_alloc_sta(void *il_rate, struct ieee80211_sta *sta,
2309 struct il_lq_sta *lq_sta;
2310 struct il_station_priv *sta_priv =
2311 (struct il_station_priv *) sta->drv_priv;
2314 il = (struct il_priv *)il_rate;
2315 D_RATE("create station rate scale win\n");
2317 lq_sta = &sta_priv->lq_sta;
2323 * Called after adding a new station to initialize rate scaling
2326 il4965_rs_rate_init(struct il_priv *il,
2327 struct ieee80211_sta *sta,
2331 struct ieee80211_hw *hw = il->hw;
2332 struct ieee80211_conf *conf = &il->hw->conf;
2333 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2334 struct il_station_priv *sta_priv;
2335 struct il_lq_sta *lq_sta;
2336 struct ieee80211_supported_band *sband;
2338 sta_priv = (struct il_station_priv *) sta->drv_priv;
2339 lq_sta = &sta_priv->lq_sta;
2340 sband = hw->wiphy->bands[conf->channel->band];
2343 lq_sta->lq.sta_id = sta_id;
2345 for (j = 0; j < LQ_SIZE; j++)
2346 for (i = 0; i < RATE_COUNT; i++)
2347 il4965_rs_rate_scale_clear_win(
2348 &lq_sta->lq_info[j].win[i]);
2350 lq_sta->flush_timer = 0;
2351 lq_sta->supp_rates = sta->supp_rates[sband->band];
2352 for (j = 0; j < LQ_SIZE; j++)
2353 for (i = 0; i < RATE_COUNT; i++)
2354 il4965_rs_rate_scale_clear_win(
2355 &lq_sta->lq_info[j].win[i]);
2358 "*** rate scale station global init for station %d ***\n",
2360 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2361 * the lowest or the highest rate.. Could consider using RSSI from
2362 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2366 lq_sta->max_rate_idx = -1;
2367 lq_sta->missed_rate_counter = IL_MISSED_RATE_MAX;
2368 lq_sta->is_green = il4965_rs_use_green(sta);
2369 lq_sta->active_legacy_rate = il->active_rate & ~(0x1000);
2370 lq_sta->band = il->band;
2372 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2373 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2375 lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
2376 lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
2377 lq_sta->active_siso_rate &= ~((u16)0x2);
2378 lq_sta->active_siso_rate <<= IL_FIRST_OFDM_RATE;
2381 lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
2382 lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
2383 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2384 lq_sta->active_mimo2_rate <<= IL_FIRST_OFDM_RATE;
2386 /* These values will be overridden later */
2387 lq_sta->lq.general_params.single_stream_ant_msk =
2388 il4965_first_antenna(il->hw_params.valid_tx_ant);
2389 lq_sta->lq.general_params.dual_stream_ant_msk =
2390 il->hw_params.valid_tx_ant &
2391 ~il4965_first_antenna(il->hw_params.valid_tx_ant);
2392 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2393 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
2394 } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) {
2395 lq_sta->lq.general_params.dual_stream_ant_msk =
2396 il->hw_params.valid_tx_ant;
2399 /* as default allow aggregation for all tids */
2400 lq_sta->tx_agg_tid_en = IL_AGG_ALL_TID;
2403 /* Set last_txrate_idx to lowest rate */
2404 lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
2405 if (sband->band == IEEE80211_BAND_5GHZ)
2406 lq_sta->last_txrate_idx += IL_FIRST_OFDM_RATE;
2409 #ifdef CONFIG_MAC80211_DEBUGFS
2410 lq_sta->dbg_fixed_rate = 0;
2413 il4965_rs_initialize_lq(il, conf, sta, lq_sta);
2416 static void il4965_rs_fill_link_cmd(struct il_priv *il,
2417 struct il_lq_sta *lq_sta, u32 new_rate)
2419 struct il_scale_tbl_info tbl_type;
2422 int repeat_rate = 0;
2423 u8 ant_toggle_cnt = 0;
2424 u8 use_ht_possible = 1;
2425 u8 valid_tx_ant = 0;
2426 struct il_link_quality_cmd *lq_cmd = &lq_sta->lq;
2428 /* Override starting rate (idx 0) if needed for debug purposes */
2429 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
2431 /* Interpret new_rate (rate_n_flags) */
2432 il4965_rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
2433 &tbl_type, &rate_idx);
2435 /* How many times should we repeat the initial rate? */
2436 if (is_legacy(tbl_type.lq_type)) {
2438 repeat_rate = IL_NUMBER_TRY;
2440 repeat_rate = IL_HT_NUMBER_TRY;
2443 lq_cmd->general_params.mimo_delimiter =
2444 is_mimo(tbl_type.lq_type) ? 1 : 0;
2446 /* Fill 1st table entry (idx 0) */
2447 lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate);
2449 if (il4965_num_of_ant(tbl_type.ant_type) == 1) {
2450 lq_cmd->general_params.single_stream_ant_msk =
2452 } else if (il4965_num_of_ant(tbl_type.ant_type) == 2) {
2453 lq_cmd->general_params.dual_stream_ant_msk =
2455 } /* otherwise we don't modify the existing value */
2460 valid_tx_ant = il->hw_params.valid_tx_ant;
2462 /* Fill rest of rate table */
2463 while (idx < LINK_QUAL_MAX_RETRY_NUM) {
2464 /* Repeat initial/next rate.
2465 * For legacy IL_NUMBER_TRY == 1, this loop will not execute.
2466 * For HT IL_HT_NUMBER_TRY == 3, this executes twice. */
2467 while (repeat_rate > 0 && idx < LINK_QUAL_MAX_RETRY_NUM) {
2468 if (is_legacy(tbl_type.lq_type)) {
2469 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2472 il4965_rs_toggle_antenna(valid_tx_ant,
2473 &new_rate, &tbl_type))
2477 /* Override next rate if needed for debug purposes */
2478 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
2480 /* Fill next table entry */
2481 lq_cmd->rs_table[idx].rate_n_flags =
2482 cpu_to_le32(new_rate);
2487 il4965_rs_get_tbl_info_from_mcs(new_rate,
2488 lq_sta->band, &tbl_type,
2491 /* Indicate to uCode which entries might be MIMO.
2492 * If initial rate was MIMO, this will finally end up
2493 * as (IL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
2494 if (is_mimo(tbl_type.lq_type))
2495 lq_cmd->general_params.mimo_delimiter = idx;
2498 new_rate = il4965_rs_get_lower_rate(lq_sta,
2499 &tbl_type, rate_idx,
2502 /* How many times should we repeat the next rate? */
2503 if (is_legacy(tbl_type.lq_type)) {
2504 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2507 il4965_rs_toggle_antenna(valid_tx_ant,
2508 &new_rate, &tbl_type))
2511 repeat_rate = IL_NUMBER_TRY;
2513 repeat_rate = IL_HT_NUMBER_TRY;
2516 /* Don't allow HT rates after next pass.
2517 * il4965_rs_get_lower_rate() will change type to LQ_A or LQ_G. */
2518 use_ht_possible = 0;
2520 /* Override next rate if needed for debug purposes */
2521 il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx);
2523 /* Fill next table entry */
2524 lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate);
2530 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2531 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
2533 lq_cmd->agg_params.agg_time_limit =
2534 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
2538 *il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
2542 /* rate scale requires free function to be implemented */
2543 static void il4965_rs_free(void *il_rate)
2548 static void il4965_rs_free_sta(void *il_r, struct ieee80211_sta *sta,
2551 struct il_priv *il __maybe_unused = il_r;
2558 #ifdef CONFIG_MAC80211_DEBUGFS
2559 static int il4965_open_file_generic(struct inode *inode, struct file *file)
2561 file->private_data = inode->i_private;
2564 static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta,
2565 u32 *rate_n_flags, int idx)
2572 valid_tx_ant = il->hw_params.valid_tx_ant;
2573 if (lq_sta->dbg_fixed_rate) {
2575 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
2576 >> RATE_MCS_ANT_POS);
2577 if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
2578 *rate_n_flags = lq_sta->dbg_fixed_rate;
2579 D_RATE("Fixed rate ON\n");
2581 lq_sta->dbg_fixed_rate = 0;
2583 "Invalid antenna selection 0x%X, Valid is 0x%X\n",
2584 ant_sel_tx, valid_tx_ant);
2585 D_RATE("Fixed rate OFF\n");
2588 D_RATE("Fixed rate OFF\n");
2592 static ssize_t il4965_rs_sta_dbgfs_scale_table_write(struct file *file,
2593 const char __user *user_buf, size_t count, loff_t *ppos)
2595 struct il_lq_sta *lq_sta = file->private_data;
2600 struct il_station_priv *sta_priv =
2601 container_of(lq_sta, struct il_station_priv, lq_sta);
2602 struct il_rxon_context *ctx = sta_priv->common.ctx;
2605 memset(buf, 0, sizeof(buf));
2606 buf_size = min(count, sizeof(buf) - 1);
2607 if (copy_from_user(buf, user_buf, buf_size))
2610 if (sscanf(buf, "%x", &parsed_rate) == 1)
2611 lq_sta->dbg_fixed_rate = parsed_rate;
2613 lq_sta->dbg_fixed_rate = 0;
2615 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2616 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2617 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2619 D_RATE("sta_id %d rate 0x%X\n",
2620 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
2622 if (lq_sta->dbg_fixed_rate) {
2623 il4965_rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
2624 il_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
2631 static ssize_t il4965_rs_sta_dbgfs_scale_table_read(struct file *file,
2632 char __user *user_buf, size_t count, loff_t *ppos)
2640 struct il_lq_sta *lq_sta = file->private_data;
2642 struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
2645 buff = kmalloc(1024, GFP_KERNEL);
2649 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
2650 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2651 lq_sta->total_failed, lq_sta->total_success,
2652 lq_sta->active_legacy_rate);
2653 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2654 lq_sta->dbg_fixed_rate);
2655 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
2656 (il->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "",
2657 (il->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "",
2658 (il->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : "");
2659 desc += sprintf(buff+desc, "lq type %s\n",
2660 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
2661 if (is_Ht(tbl->lq_type)) {
2662 desc += sprintf(buff+desc, " %s",
2663 (is_siso(tbl->lq_type)) ? "SISO" : "MIMO2");
2664 desc += sprintf(buff+desc, " %s",
2665 (tbl->is_ht40) ? "40MHz" : "20MHz");
2666 desc += sprintf(buff+desc, " %s %s %s\n",
2667 (tbl->is_SGI) ? "SGI" : "",
2668 (lq_sta->is_green) ? "GF enabled" : "",
2669 (lq_sta->is_agg) ? "AGG on" : "");
2671 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
2672 lq_sta->last_rate_n_flags);
2673 desc += sprintf(buff+desc, "general:"
2674 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2675 lq_sta->lq.general_params.flags,
2676 lq_sta->lq.general_params.mimo_delimiter,
2677 lq_sta->lq.general_params.single_stream_ant_msk,
2678 lq_sta->lq.general_params.dual_stream_ant_msk);
2680 desc += sprintf(buff+desc, "agg:"
2681 "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
2682 le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit),
2683 lq_sta->lq.agg_params.agg_dis_start_th,
2684 lq_sta->lq.agg_params.agg_frame_cnt_limit);
2686 desc += sprintf(buff+desc,
2687 "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
2688 lq_sta->lq.general_params.start_rate_idx[0],
2689 lq_sta->lq.general_params.start_rate_idx[1],
2690 lq_sta->lq.general_params.start_rate_idx[2],
2691 lq_sta->lq.general_params.start_rate_idx[3]);
2693 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
2694 idx = il4965_hwrate_to_plcp_idx(
2695 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2696 if (is_legacy(tbl->lq_type)) {
2697 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
2699 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2700 il_rate_mcs[idx].mbps);
2702 desc += sprintf(buff+desc,
2703 " rate[%d] 0x%X %smbps (%s)\n",
2705 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2706 il_rate_mcs[idx].mbps, il_rate_mcs[idx].mcs);
2710 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2715 static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2716 .write = il4965_rs_sta_dbgfs_scale_table_write,
2717 .read = il4965_rs_sta_dbgfs_scale_table_read,
2718 .open = il4965_open_file_generic,
2719 .llseek = default_llseek,
2721 static ssize_t il4965_rs_sta_dbgfs_stats_table_read(struct file *file,
2722 char __user *user_buf, size_t count, loff_t *ppos)
2729 struct il_lq_sta *lq_sta = file->private_data;
2731 buff = kmalloc(1024, GFP_KERNEL);
2735 for (i = 0; i < LQ_SIZE; i++) {
2736 desc += sprintf(buff+desc,
2737 "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n"
2739 lq_sta->active_tbl == i ? "*" : "x",
2740 lq_sta->lq_info[i].lq_type,
2741 lq_sta->lq_info[i].is_SGI,
2742 lq_sta->lq_info[i].is_ht40,
2743 lq_sta->lq_info[i].is_dup,
2745 lq_sta->lq_info[i].current_rate);
2746 for (j = 0; j < RATE_COUNT; j++) {
2747 desc += sprintf(buff+desc,
2748 "counter=%d success=%d %%=%d\n",
2749 lq_sta->lq_info[i].win[j].counter,
2750 lq_sta->lq_info[i].win[j].success_counter,
2751 lq_sta->lq_info[i].win[j].success_ratio);
2754 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2759 static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2760 .read = il4965_rs_sta_dbgfs_stats_table_read,
2761 .open = il4965_open_file_generic,
2762 .llseek = default_llseek,
2765 static ssize_t il4965_rs_sta_dbgfs_rate_scale_data_read(struct file *file,
2766 char __user *user_buf, size_t count, loff_t *ppos)
2772 struct il_lq_sta *lq_sta = file->private_data;
2774 struct il_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
2778 if (is_Ht(tbl->lq_type))
2779 desc += sprintf(buff+desc,
2780 "Bit Rate= %d Mb/s\n",
2781 tbl->expected_tpt[lq_sta->last_txrate_idx]);
2783 desc += sprintf(buff+desc,
2784 "Bit Rate= %d Mb/s\n",
2785 il_rates[lq_sta->last_txrate_idx].ieee >> 1);
2787 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2791 static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
2792 .read = il4965_rs_sta_dbgfs_rate_scale_data_read,
2793 .open = il4965_open_file_generic,
2794 .llseek = default_llseek,
2797 static void il4965_rs_add_debugfs(void *il, void *il_sta,
2800 struct il_lq_sta *lq_sta = il_sta;
2801 lq_sta->rs_sta_dbgfs_scale_table_file =
2802 debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
2803 lq_sta, &rs_sta_dbgfs_scale_table_ops);
2804 lq_sta->rs_sta_dbgfs_stats_table_file =
2805 debugfs_create_file("rate_stats_table", S_IRUSR, dir,
2806 lq_sta, &rs_sta_dbgfs_stats_table_ops);
2807 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
2808 debugfs_create_file("rate_scale_data", S_IRUSR, dir,
2809 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
2810 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2811 debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
2812 &lq_sta->tx_agg_tid_en);
2816 static void il4965_rs_remove_debugfs(void *il, void *il_sta)
2818 struct il_lq_sta *lq_sta = il_sta;
2819 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2820 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
2821 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
2822 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2827 * Initialization of rate scaling information is done by driver after
2828 * the station is added. Since mac80211 calls this function before a
2829 * station is added we ignore it.
2832 il4965_rs_rate_init_stub(void *il_r, struct ieee80211_supported_band *sband,
2833 struct ieee80211_sta *sta, void *il_sta)
2836 static struct rate_control_ops rs_4965_ops = {
2838 .name = IL4965_RS_NAME,
2839 .tx_status = il4965_rs_tx_status,
2840 .get_rate = il4965_rs_get_rate,
2841 .rate_init = il4965_rs_rate_init_stub,
2842 .alloc = il4965_rs_alloc,
2843 .free = il4965_rs_free,
2844 .alloc_sta = il4965_rs_alloc_sta,
2845 .free_sta = il4965_rs_free_sta,
2846 #ifdef CONFIG_MAC80211_DEBUGFS
2847 .add_sta_debugfs = il4965_rs_add_debugfs,
2848 .remove_sta_debugfs = il4965_rs_remove_debugfs,
2852 int il4965_rate_control_register(void)
2854 return ieee80211_rate_control_register(&rs_4965_ops);
2857 void il4965_rate_control_unregister(void)
2859 ieee80211_rate_control_unregister(&rs_4965_ops);