Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved. |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 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 |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/skbuff.h> |
| 29 | #include <linux/slab.h> |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 30 | #include <net/mac80211.h> |
| 31 | |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/etherdevice.h> |
| 34 | #include <linux/delay.h> |
| 35 | |
| 36 | #include <linux/workqueue.h> |
| 37 | |
Stanislaw Gruszka | 98613be | 2011-11-15 14:19:34 +0100 | [diff] [blame] | 38 | #include "common.h" |
Stanislaw Gruszka | af038f4 | 2011-08-30 13:58:27 +0200 | [diff] [blame] | 39 | #include "4965.h" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 40 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 41 | #define IL4965_RS_NAME "iwl-4965-rs" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 42 | |
| 43 | #define NUM_TRY_BEFORE_ANT_TOGGLE 1 |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 44 | #define IL_NUMBER_TRY 1 |
| 45 | #define IL_HT_NUMBER_TRY 3 |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 46 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 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 */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 50 | |
| 51 | /* max allowed rate miss before sync LQ cmd */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 52 | #define IL_MISSED_RATE_MAX 15 |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 53 | /* max time to accum history 2 seconds */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 54 | #define RATE_SCALE_FLUSH_INTVL (3*HZ) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 55 | |
| 56 | static u8 rs_ht_to_legacy[] = { |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 57 | RATE_6M_IDX, RATE_6M_IDX, |
| 58 | RATE_6M_IDX, RATE_6M_IDX, |
| 59 | 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 |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static const u8 ant_toggle_lookup[] = { |
| 67 | /*ANT_NONE -> */ ANT_NONE, |
| 68 | /*ANT_A -> */ ANT_B, |
| 69 | /*ANT_B -> */ ANT_C, |
| 70 | /*ANT_AB -> */ ANT_BC, |
| 71 | /*ANT_C -> */ ANT_A, |
| 72 | /*ANT_AC -> */ ANT_AB, |
| 73 | /*ANT_BC -> */ ANT_AC, |
| 74 | /*ANT_ABC -> */ ANT_ABC, |
| 75 | }; |
| 76 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 77 | #define IL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 78 | [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 79 | RATE_SISO_##s##M_PLCP, \ |
| 80 | RATE_MIMO2_##s##M_PLCP,\ |
| 81 | RATE_##r##M_IEEE, \ |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 82 | RATE_##ip##M_IDX, \ |
| 83 | RATE_##in##M_IDX, \ |
| 84 | RATE_##rp##M_IDX, \ |
| 85 | RATE_##rn##M_IDX, \ |
| 86 | RATE_##pp##M_IDX, \ |
| 87 | RATE_##np##M_IDX } |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * Parameter order: |
| 91 | * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate |
| 92 | * |
| 93 | * If there isn't a valid next or previous rate then INV is used which |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 94 | * maps to RATE_INVALID |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 95 | * |
| 96 | */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 97 | const struct il_rate_info il_rates[RATE_COUNT] = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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 */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 113 | static int il4965_hwrate_to_plcp_idx(u32 rate_n_flags) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 114 | { |
| 115 | int idx = 0; |
| 116 | |
| 117 | /* HT rate format */ |
| 118 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 119 | idx = (rate_n_flags & 0xff); |
| 120 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 121 | if (idx >= RATE_MIMO2_6M_PLCP) |
| 122 | idx = idx - RATE_MIMO2_6M_PLCP; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 123 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 124 | idx += IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 125 | /* skip 9M not supported in ht*/ |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 126 | if (idx >= RATE_9M_IDX) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 127 | idx += 1; |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 128 | if (idx >= IL_FIRST_OFDM_RATE && idx <= IL_LAST_OFDM_RATE) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 129 | return idx; |
| 130 | |
| 131 | /* legacy rate format, search for match in table */ |
| 132 | } else { |
Stanislaw Gruszka | d2ddf621 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 133 | for (idx = 0; idx < ARRAY_SIZE(il_rates); idx++) |
| 134 | if (il_rates[idx].plcp == (rate_n_flags & 0xFF)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 135 | return idx; |
| 136 | } |
| 137 | |
| 138 | return -1; |
| 139 | } |
| 140 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 141 | static void il4965_rs_rate_scale_perform(struct il_priv *il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 142 | struct sk_buff *skb, |
| 143 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 144 | struct il_lq_sta *lq_sta); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 145 | static void il4965_rs_fill_link_cmd(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 148 | bool force_search); |
| 149 | |
| 150 | #ifdef CONFIG_MAC80211_DEBUGFS |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 151 | static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 152 | u32 *rate_n_flags, int idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 153 | #else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 154 | static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 155 | u32 *rate_n_flags, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 156 | {} |
| 157 | #endif |
| 158 | |
| 159 | /** |
| 160 | * The following tables contain the expected throughput metrics for all rates |
| 161 | * |
| 162 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits |
| 163 | * |
| 164 | * where invalid entries are zeros. |
| 165 | * |
| 166 | * CCK rates are only valid in legacy table and will only be used in G |
| 167 | * (2.4 GHz) band. |
| 168 | */ |
| 169 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 170 | static s32 expected_tpt_legacy[RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 171 | 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0 |
| 172 | }; |
| 173 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 174 | static s32 expected_tpt_siso20MHz[4][RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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 */ |
| 179 | }; |
| 180 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 181 | static s32 expected_tpt_siso40MHz[4][RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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 */ |
| 186 | }; |
| 187 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 188 | static s32 expected_tpt_mimo2_20MHz[4][RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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*/ |
| 193 | }; |
| 194 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 195 | static s32 expected_tpt_mimo2_40MHz[4][RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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 */ |
| 200 | }; |
| 201 | |
| 202 | /* mbps, mcs */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 203 | static const struct il_rate_mcs_info il_rate_mcs[RATE_COUNT] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 204 | { "1", "BPSK DSSS"}, |
| 205 | { "2", "QPSK DSSS"}, |
| 206 | {"5.5", "BPSK CCK"}, |
| 207 | { "11", "QPSK CCK"}, |
| 208 | { "6", "BPSK 1/2"}, |
| 209 | { "9", "BPSK 1/2"}, |
| 210 | { "12", "QPSK 1/2"}, |
| 211 | { "18", "QPSK 3/4"}, |
| 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"}, |
| 217 | }; |
| 218 | |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 219 | #define MCS_IDX_PER_STREAM (8) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 220 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 221 | static inline u8 il4965_rs_extract_rate(u32 rate_n_flags) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 222 | { |
| 223 | return (u8)(rate_n_flags & 0xFF); |
| 224 | } |
| 225 | |
| 226 | static void |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 227 | il4965_rs_rate_scale_clear_win(struct il_rate_scale_data *win) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 228 | { |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 229 | win->data = 0; |
| 230 | win->success_counter = 0; |
| 231 | win->success_ratio = IL_INVALID_VALUE; |
| 232 | win->counter = 0; |
| 233 | win->average_tpt = IL_INVALID_VALUE; |
| 234 | win->stamp = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 237 | static inline u8 il4965_rs_is_valid_ant(u8 valid_antenna, u8 ant_type) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 238 | { |
| 239 | return (ant_type & valid_antenna) == ant_type; |
| 240 | } |
| 241 | |
| 242 | /* |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 243 | * removes the old data from the stats. All data that is older than |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 244 | * TID_MAX_TIME_DIFF, will be deleted. |
| 245 | */ |
| 246 | static void |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 247 | il4965_rs_tl_rm_old_stats(struct il_traffic_load *tl, u32 curr_time) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 248 | { |
| 249 | /* The oldest age we want to keep */ |
| 250 | u32 oldest_time = curr_time - TID_MAX_TIME_DIFF; |
| 251 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 252 | while (tl->queue_count && tl->time_stamp < oldest_time) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 253 | tl->total -= tl->packet_count[tl->head]; |
| 254 | tl->packet_count[tl->head] = 0; |
| 255 | tl->time_stamp += TID_QUEUE_CELL_SPACING; |
| 256 | tl->queue_count--; |
| 257 | tl->head++; |
| 258 | if (tl->head >= TID_QUEUE_MAX_SIZE) |
| 259 | tl->head = 0; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * increment traffic load value for tid and also remove |
| 265 | * any old values if passed the certain time period |
| 266 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 267 | static u8 il4965_rs_tl_add_packet(struct il_lq_sta *lq_data, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 268 | struct ieee80211_hdr *hdr) |
| 269 | { |
| 270 | u32 curr_time = jiffies_to_msecs(jiffies); |
| 271 | u32 time_diff; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 272 | s32 idx; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 273 | struct il_traffic_load *tl = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 274 | u8 tid; |
| 275 | |
| 276 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 277 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 278 | tid = qc[0] & 0xf; |
| 279 | } else |
| 280 | return MAX_TID_COUNT; |
| 281 | |
| 282 | if (unlikely(tid >= TID_MAX_LOAD_COUNT)) |
| 283 | return MAX_TID_COUNT; |
| 284 | |
| 285 | tl = &lq_data->load[tid]; |
| 286 | |
| 287 | curr_time -= curr_time % TID_ROUND_VALUE; |
| 288 | |
| 289 | /* Happens only for the first packet. Initialize the data */ |
| 290 | if (!(tl->queue_count)) { |
| 291 | tl->total = 1; |
| 292 | tl->time_stamp = curr_time; |
| 293 | tl->queue_count = 1; |
| 294 | tl->head = 0; |
| 295 | tl->packet_count[0] = 1; |
| 296 | return MAX_TID_COUNT; |
| 297 | } |
| 298 | |
| 299 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 300 | idx = time_diff / TID_QUEUE_CELL_SPACING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 301 | |
| 302 | /* The history is too long: remove data that is older than */ |
| 303 | /* TID_MAX_TIME_DIFF */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 304 | if (idx >= TID_QUEUE_MAX_SIZE) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 305 | il4965_rs_tl_rm_old_stats(tl, curr_time); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 306 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 307 | idx = (tl->head + idx) % TID_QUEUE_MAX_SIZE; |
| 308 | tl->packet_count[idx] = tl->packet_count[idx] + 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 309 | tl->total = tl->total + 1; |
| 310 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 311 | if ((idx + 1) > tl->queue_count) |
| 312 | tl->queue_count = idx + 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 313 | |
| 314 | return tid; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | get the traffic load value for tid |
| 319 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 320 | static u32 il4965_rs_tl_get_load(struct il_lq_sta *lq_data, u8 tid) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 321 | { |
| 322 | u32 curr_time = jiffies_to_msecs(jiffies); |
| 323 | u32 time_diff; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 324 | s32 idx; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 325 | struct il_traffic_load *tl = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 326 | |
| 327 | if (tid >= TID_MAX_LOAD_COUNT) |
| 328 | return 0; |
| 329 | |
| 330 | tl = &(lq_data->load[tid]); |
| 331 | |
| 332 | curr_time -= curr_time % TID_ROUND_VALUE; |
| 333 | |
| 334 | if (!(tl->queue_count)) |
| 335 | return 0; |
| 336 | |
| 337 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 338 | idx = time_diff / TID_QUEUE_CELL_SPACING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 339 | |
| 340 | /* The history is too long: remove data that is older than */ |
| 341 | /* TID_MAX_TIME_DIFF */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 342 | if (idx >= TID_QUEUE_MAX_SIZE) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 343 | il4965_rs_tl_rm_old_stats(tl, curr_time); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 344 | |
| 345 | return tl->total; |
| 346 | } |
| 347 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 348 | static int il4965_rs_tl_turn_on_agg_for_tid(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 349 | struct il_lq_sta *lq_data, u8 tid, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 350 | struct ieee80211_sta *sta) |
| 351 | { |
| 352 | int ret = -EAGAIN; |
| 353 | u32 load; |
| 354 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 355 | load = il4965_rs_tl_get_load(lq_data, tid); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 356 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 357 | if (load > IL_AGG_LOAD_THRESHOLD) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 358 | D_HT("Starting Tx agg: STA: %pM tid: %d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 359 | sta->addr, tid); |
| 360 | ret = ieee80211_start_tx_ba_session(sta, tid, 5000); |
| 361 | if (ret == -EAGAIN) { |
| 362 | /* |
| 363 | * driver and mac80211 is out of sync |
| 364 | * this might be cause by reloading firmware |
| 365 | * stop the tx ba session here |
| 366 | */ |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 367 | IL_ERR("Fail start Tx agg on tid: %d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 368 | tid); |
| 369 | ieee80211_stop_tx_ba_session(sta, tid); |
| 370 | } |
| 371 | } else { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 372 | IL_ERR("Aggregation not enabled for tid %d " |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 373 | "because load = %u\n", tid, load); |
| 374 | } |
| 375 | return ret; |
| 376 | } |
| 377 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 378 | static void il4965_rs_tl_turn_on_agg(struct il_priv *il, u8 tid, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 379 | struct il_lq_sta *lq_data, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 380 | struct ieee80211_sta *sta) |
| 381 | { |
| 382 | if (tid < TID_MAX_LOAD_COUNT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 383 | il4965_rs_tl_turn_on_agg_for_tid(il, lq_data, tid, sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 384 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 385 | IL_ERR("tid exceeds max load count: %d/%d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 386 | tid, TID_MAX_LOAD_COUNT); |
| 387 | } |
| 388 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 389 | static inline int il4965_get_il4965_num_of_ant_from_rate(u32 rate_n_flags) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 390 | { |
| 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); |
| 394 | } |
| 395 | |
| 396 | /* |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 397 | * Static function to get the expected throughput from an il_scale_tbl_info |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 398 | * that wraps a NULL pointer check |
| 399 | */ |
| 400 | static s32 |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 401 | il4965_get_expected_tpt(struct il_scale_tbl_info *tbl, int rs_idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 402 | { |
| 403 | if (tbl->expected_tpt) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 404 | return tbl->expected_tpt[rs_idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /** |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 409 | * il4965_rs_collect_tx_data - Update the success/failure sliding win |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 410 | * |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 411 | * We keep a sliding win of the last 62 packets transmitted |
| 412 | * at this rate. win->data contains the bitmask of successful |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 413 | * packets. |
| 414 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 415 | static int il4965_rs_collect_tx_data(struct il_scale_tbl_info *tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 416 | int scale_idx, int attempts, int successes) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 417 | { |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 418 | struct il_rate_scale_data *win = NULL; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 419 | static const u64 mask = (((u64)1) << (RATE_MAX_WINDOW - 1)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 420 | s32 fail_count, tpt; |
| 421 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 422 | if (scale_idx < 0 || scale_idx >= RATE_COUNT) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 423 | return -EINVAL; |
| 424 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 425 | /* Select win for current tx bit rate */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 426 | win = &(tbl->win[scale_idx]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 427 | |
| 428 | /* Get expected throughput */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 429 | tpt = il4965_get_expected_tpt(tbl, scale_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 430 | |
| 431 | /* |
| 432 | * Keep track of only the latest 62 tx frame attempts in this rate's |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 433 | * history win; anything older isn't really relevant any more. |
| 434 | * If we have filled up the sliding win, drop the oldest attempt; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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!). |
| 438 | */ |
| 439 | while (attempts > 0) { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 440 | if (win->counter >= RATE_MAX_WINDOW) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 441 | |
| 442 | /* remove earliest */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 443 | win->counter = RATE_MAX_WINDOW - 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 444 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 445 | if (win->data & mask) { |
| 446 | win->data &= ~mask; |
| 447 | win->success_counter--; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
| 451 | /* Increment frames-attempted counter */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 452 | win->counter++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 453 | |
| 454 | /* Shift bitmap by one frame to throw away oldest history */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 455 | win->data <<= 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 456 | |
| 457 | /* Mark the most recent #successes attempts as successful */ |
| 458 | if (successes > 0) { |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 459 | win->success_counter++; |
| 460 | win->data |= 0x1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 461 | successes--; |
| 462 | } |
| 463 | |
| 464 | attempts--; |
| 465 | } |
| 466 | |
| 467 | /* Calculate current success ratio, avoid divide-by-0! */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 468 | if (win->counter > 0) |
| 469 | win->success_ratio = 128 * (100 * win->success_counter) |
| 470 | / win->counter; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 471 | else |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 472 | win->success_ratio = IL_INVALID_VALUE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 473 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 474 | fail_count = win->counter - win->success_counter; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 475 | |
| 476 | /* Calculate average throughput, if we have enough history. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 477 | if (fail_count >= RATE_MIN_FAILURE_TH || |
| 478 | win->success_counter >= RATE_MIN_SUCCESS_TH) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 479 | win->average_tpt = (win->success_ratio * tpt + 64) / 128; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 480 | else |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 481 | win->average_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 482 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 483 | /* Tag this win as having been updated */ |
| 484 | win->stamp = jiffies; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Fill uCode API rate_n_flags field, based on "search" or "active" table. |
| 491 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 492 | static u32 il4965_rate_n_flags_from_tbl(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 493 | struct il_scale_tbl_info *tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 494 | int idx, u8 use_green) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 495 | { |
| 496 | u32 rate_n_flags = 0; |
| 497 | |
| 498 | if (is_legacy(tbl->lq_type)) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 499 | rate_n_flags = il_rates[idx].plcp; |
| 500 | if (idx >= IL_FIRST_CCK_RATE && idx <= IL_LAST_CCK_RATE) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 501 | rate_n_flags |= RATE_MCS_CCK_MSK; |
| 502 | |
| 503 | } else if (is_Ht(tbl->lq_type)) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 504 | if (idx > IL_LAST_OFDM_RATE) { |
| 505 | IL_ERR("Invalid HT rate idx %d\n", idx); |
| 506 | idx = IL_LAST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 507 | } |
| 508 | rate_n_flags = RATE_MCS_HT_MSK; |
| 509 | |
| 510 | if (is_siso(tbl->lq_type)) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 511 | rate_n_flags |= il_rates[idx].plcp_siso; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 512 | else |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 513 | rate_n_flags |= il_rates[idx].plcp_mimo2; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 514 | } else { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 515 | IL_ERR("Invalid tbl->lq_type %d\n", tbl->lq_type); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) & |
| 519 | RATE_MCS_ANT_ABC_MSK); |
| 520 | |
| 521 | if (is_Ht(tbl->lq_type)) { |
| 522 | if (tbl->is_ht40) { |
| 523 | if (tbl->is_dup) |
| 524 | rate_n_flags |= RATE_MCS_DUP_MSK; |
| 525 | else |
| 526 | rate_n_flags |= RATE_MCS_HT40_MSK; |
| 527 | } |
| 528 | if (tbl->is_SGI) |
| 529 | rate_n_flags |= RATE_MCS_SGI_MSK; |
| 530 | |
| 531 | if (use_green) { |
| 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; |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 535 | IL_ERR("GF was set with SGI:SISO\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | } |
| 539 | return rate_n_flags; |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * Interpret uCode API's rate_n_flags format, |
| 544 | * fill "search" or "active" tx mode table. |
| 545 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 546 | static int il4965_rs_get_tbl_info_from_mcs(const u32 rate_n_flags, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 547 | enum ieee80211_band band, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 548 | struct il_scale_tbl_info *tbl, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 549 | int *rate_idx) |
| 550 | { |
| 551 | u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 552 | u8 il4965_num_of_ant = il4965_get_il4965_num_of_ant_from_rate(rate_n_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 553 | u8 mcs; |
| 554 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 555 | memset(tbl, 0, sizeof(struct il_scale_tbl_info)); |
| 556 | *rate_idx = il4965_hwrate_to_plcp_idx(rate_n_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 557 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 558 | if (*rate_idx == RATE_INVALID) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 559 | *rate_idx = -1; |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | tbl->is_SGI = 0; /* default legacy setup */ |
| 563 | tbl->is_ht40 = 0; |
| 564 | tbl->is_dup = 0; |
| 565 | tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); |
| 566 | tbl->lq_type = LQ_NONE; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 567 | tbl->max_search = IL_MAX_SEARCH; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 568 | |
| 569 | /* legacy rate format */ |
| 570 | if (!(rate_n_flags & RATE_MCS_HT_MSK)) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 571 | if (il4965_num_of_ant == 1) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 572 | if (band == IEEE80211_BAND_5GHZ) |
| 573 | tbl->lq_type = LQ_A; |
| 574 | else |
| 575 | tbl->lq_type = LQ_G; |
| 576 | } |
| 577 | /* HT rate format */ |
| 578 | } else { |
| 579 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 580 | tbl->is_SGI = 1; |
| 581 | |
| 582 | if ((rate_n_flags & RATE_MCS_HT40_MSK) || |
| 583 | (rate_n_flags & RATE_MCS_DUP_MSK)) |
| 584 | tbl->is_ht40 = 1; |
| 585 | |
| 586 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
| 587 | tbl->is_dup = 1; |
| 588 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 589 | mcs = il4965_rs_extract_rate(rate_n_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 590 | |
| 591 | /* SISO */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 592 | if (mcs <= RATE_SISO_60M_PLCP) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 593 | if (il4965_num_of_ant == 1) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 594 | tbl->lq_type = LQ_SISO; /*else NONE*/ |
| 595 | /* MIMO2 */ |
| 596 | } else { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 597 | if (il4965_num_of_ant == 2) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 598 | tbl->lq_type = LQ_MIMO2; |
| 599 | } |
| 600 | } |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | /* switch to another antenna/antennas and return 1 */ |
| 605 | /* if no other valid antenna found, return 0 */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 606 | static int il4965_rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, |
| 607 | struct il_scale_tbl_info *tbl) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 608 | { |
| 609 | u8 new_ant_type; |
| 610 | |
| 611 | if (!tbl->ant_type || tbl->ant_type > ANT_ABC) |
| 612 | return 0; |
| 613 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 614 | if (!il4965_rs_is_valid_ant(valid_ant, tbl->ant_type)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 615 | return 0; |
| 616 | |
| 617 | new_ant_type = ant_toggle_lookup[tbl->ant_type]; |
| 618 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 619 | while (new_ant_type != tbl->ant_type && |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 620 | !il4965_rs_is_valid_ant(valid_ant, new_ant_type)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 621 | new_ant_type = ant_toggle_lookup[new_ant_type]; |
| 622 | |
| 623 | if (new_ant_type == tbl->ant_type) |
| 624 | return 0; |
| 625 | |
| 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; |
| 629 | return 1; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Green-field mode is valid if the station supports it and |
| 634 | * there are no non-GF stations present in the BSS. |
| 635 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 636 | static bool il4965_rs_use_green(struct ieee80211_sta *sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 637 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 638 | struct il_station_priv *sta_priv = (void *)sta->drv_priv; |
| 639 | struct il_rxon_context *ctx = sta_priv->common.ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 640 | |
| 641 | return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && |
| 642 | !(ctx->ht.non_gf_sta_present); |
| 643 | } |
| 644 | |
| 645 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 646 | * il4965_rs_get_supported_rates - get the available rates |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 647 | * |
| 648 | * if management frame or broadcast frame only return |
| 649 | * basic available rates. |
| 650 | * |
| 651 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 652 | static u16 il4965_rs_get_supported_rates(struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 653 | struct ieee80211_hdr *hdr, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 654 | enum il_table_type rate_type) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 655 | { |
| 656 | if (is_legacy(rate_type)) { |
| 657 | return lq_sta->active_legacy_rate; |
| 658 | } else { |
| 659 | if (is_siso(rate_type)) |
| 660 | return lq_sta->active_siso_rate; |
| 661 | else |
| 662 | return lq_sta->active_mimo2_rate; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | static u16 |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 667 | il4965_rs_get_adjacent_rate(struct il_priv *il, u8 idx, u16 rate_mask, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 668 | int rate_type) |
| 669 | { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 670 | u8 high = RATE_INVALID; |
| 671 | u8 low = RATE_INVALID; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 672 | |
| 673 | /* 802.11A or ht walks to the next literal adjacent rate in |
| 674 | * the rate table */ |
| 675 | if (is_a_band(rate_type) || !is_legacy(rate_type)) { |
| 676 | int i; |
| 677 | u32 mask; |
| 678 | |
| 679 | /* Find the previous rate that is in the rate mask */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 680 | i = idx - 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 681 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 682 | if (rate_mask & mask) { |
| 683 | low = i; |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /* Find the next rate that is in the rate mask */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 689 | i = idx + 1; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 690 | for (mask = (1 << i); i < RATE_COUNT; i++, mask <<= 1) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 691 | if (rate_mask & mask) { |
| 692 | high = i; |
| 693 | break; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return (high << 8) | low; |
| 698 | } |
| 699 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 700 | low = idx; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 701 | while (low != RATE_INVALID) { |
Stanislaw Gruszka | d2ddf621 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 702 | low = il_rates[low].prev_rs; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 703 | if (low == RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 704 | break; |
| 705 | if (rate_mask & (1 << low)) |
| 706 | break; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 707 | D_RATE("Skipping masked lower rate: %d\n", low); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 708 | } |
| 709 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 710 | high = idx; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 711 | while (high != RATE_INVALID) { |
Stanislaw Gruszka | d2ddf621 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 712 | high = il_rates[high].next_rs; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 713 | if (high == RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 714 | break; |
| 715 | if (rate_mask & (1 << high)) |
| 716 | break; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 717 | D_RATE("Skipping masked higher rate: %d\n", high); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | return (high << 8) | low; |
| 721 | } |
| 722 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 723 | static u32 il4965_rs_get_lower_rate(struct il_lq_sta *lq_sta, |
| 724 | struct il_scale_tbl_info *tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 725 | u8 scale_idx, u8 ht_possible) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 726 | { |
| 727 | s32 low; |
| 728 | u16 rate_mask; |
| 729 | u16 high_low; |
| 730 | u8 switch_to_legacy = 0; |
| 731 | u8 is_green = lq_sta->is_green; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 732 | struct il_priv *il = lq_sta->drv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 733 | |
| 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) */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 737 | if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_idx)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 738 | switch_to_legacy = 1; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 739 | scale_idx = rs_ht_to_legacy[scale_idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 740 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
| 741 | tbl->lq_type = LQ_A; |
| 742 | else |
| 743 | tbl->lq_type = LQ_G; |
| 744 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 745 | if (il4965_num_of_ant(tbl->ant_type) > 1) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 746 | tbl->ant_type = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 747 | il4965_first_antenna(il->hw_params.valid_tx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 748 | |
| 749 | tbl->is_ht40 = 0; |
| 750 | tbl->is_SGI = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 751 | tbl->max_search = IL_MAX_SEARCH; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 754 | rate_mask = il4965_rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 755 | |
| 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 & |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 761 | (lq_sta->supp_rates << IL_FIRST_OFDM_RATE)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 762 | else |
| 763 | rate_mask = (u16)(rate_mask & lq_sta->supp_rates); |
| 764 | } |
| 765 | |
| 766 | /* If we switched from HT to legacy, check current rate */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 767 | if (switch_to_legacy && (rate_mask & (1 << scale_idx))) { |
| 768 | low = scale_idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 769 | goto out; |
| 770 | } |
| 771 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 772 | high_low = il4965_rs_get_adjacent_rate(lq_sta->drv, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 773 | scale_idx, rate_mask, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 774 | tbl->lq_type); |
| 775 | low = high_low & 0xff; |
| 776 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 777 | if (low == RATE_INVALID) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 778 | low = scale_idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 779 | |
| 780 | out: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 781 | return il4965_rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /* |
| 785 | * Simple function to compare two rate scale table types |
| 786 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 787 | static bool il4965_table_type_matches(struct il_scale_tbl_info *a, |
| 788 | struct il_scale_tbl_info *b) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 789 | { |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 790 | return (a->lq_type == b->lq_type && a->ant_type == b->ant_type && |
| 791 | a->is_SGI == b->is_SGI); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* |
| 795 | * mac80211 sends us Tx status |
| 796 | */ |
| 797 | static void |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 798 | il4965_rs_tx_status(void *il_r, struct ieee80211_supported_band *sband, |
| 799 | struct ieee80211_sta *sta, void *il_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 800 | struct sk_buff *skb) |
| 801 | { |
| 802 | int legacy_success; |
| 803 | int retries; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 804 | int rs_idx, mac_idx, i; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 805 | struct il_lq_sta *lq_sta = il_sta; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 806 | struct il_link_quality_cmd *table; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 807 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 808 | struct il_priv *il = (struct il_priv *)il_r; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 809 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 810 | enum mac80211_rate_control_flags mac_flags; |
| 811 | u32 tx_rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 816 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 817 | D_RATE( |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 818 | "get frame ack response, update rate scale win\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 819 | |
| 820 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 821 | if (!lq_sta) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 822 | D_RATE("Station rate scaling not created yet.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 823 | return; |
| 824 | } else if (!lq_sta->drv) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 825 | D_RATE("Rate scaling not initialized yet.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 826 | return; |
| 827 | } |
| 828 | |
| 829 | if (!ieee80211_is_data(hdr->frame_control) || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 830 | (info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 831 | return; |
| 832 | |
| 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)) |
| 836 | return; |
| 837 | |
| 838 | /* |
| 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). |
| 845 | */ |
| 846 | table = &lq_sta->lq; |
| 847 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 848 | il4965_rs_get_tbl_info_from_mcs(tx_rate, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 849 | il->band, &tbl_type, &rs_idx); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 850 | if (il->band == IEEE80211_BAND_5GHZ) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 851 | rs_idx -= IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 852 | mac_flags = info->status.rates[0].flags; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 853 | mac_idx = info->status.rates[0].idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 854 | /* For HT packets, map MCS to PLCP */ |
| 855 | if (mac_flags & IEEE80211_TX_RC_MCS) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 856 | mac_idx &= RATE_MCS_CODE_MSK; /* Remove # of streams */ |
| 857 | if (mac_idx >= (RATE_9M_IDX - IL_FIRST_OFDM_RATE)) |
| 858 | mac_idx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 859 | /* |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 860 | * mac80211 HT idx is always zero-idxed; we need to move |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 861 | * HT OFDM rates after CCK rates in 2.4 GHz band |
| 862 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 863 | if (il->band == IEEE80211_BAND_2GHZ) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 864 | mac_idx += IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 865 | } |
| 866 | /* Here we actually compare this rate to the latest LQ command */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 867 | if (mac_idx < 0 || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 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) || |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 874 | rs_idx != mac_idx) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 875 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 876 | "initial rate %d does not match %d (0x%x)\n", |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 877 | mac_idx, rs_idx, tx_rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 878 | /* |
| 879 | * Since rates mis-match, the last LQ command may have failed. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 880 | * After IL_MISSED_RATE_MAX mis-matches, resync the uCode with |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 881 | * ... driver. |
| 882 | */ |
| 883 | lq_sta->missed_rate_counter++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 884 | if (lq_sta->missed_rate_counter > IL_MISSED_RATE_MAX) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 885 | lq_sta->missed_rate_counter = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 886 | il_send_lq_cmd(il, ctx, &lq_sta->lq, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 887 | CMD_ASYNC, false); |
| 888 | } |
| 889 | /* Regardless, ignore this status info for outdated rate */ |
| 890 | return; |
| 891 | } else |
| 892 | /* Rate did match, so reset the missed_rate_counter */ |
| 893 | lq_sta->missed_rate_counter = 0; |
| 894 | |
| 895 | /* Figure out if rate scale algorithm is in active or search table */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 896 | if (il4965_table_type_matches(&tbl_type, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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]); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 900 | } else if (il4965_table_type_matches(&tbl_type, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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]); |
| 904 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 905 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 906 | "Neither active nor search matches tx rate\n"); |
| 907 | tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 908 | D_RATE("active- lq:%x, ant:%x, SGI:%d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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]); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 911 | D_RATE("search- lq:%x, ant:%x, SGI:%d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 912 | tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 913 | D_RATE("actual- lq:%x, ant:%x, SGI:%d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 914 | tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI); |
| 915 | /* |
| 916 | * no matching table found, let's by-pass the data collection |
| 917 | * and continue to perform rate scale to find the rate table |
| 918 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 919 | il4965_rs_stay_in_table(lq_sta, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 920 | goto done; |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * Updating the frame history depends on whether packets were |
| 925 | * aggregated. |
| 926 | * |
| 927 | * For aggregation, all packets were transmitted at the same rate, the |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 928 | * first idx into rate scale table. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 929 | */ |
| 930 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
| 931 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 932 | il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band, &tbl_type, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 933 | &rs_idx); |
| 934 | il4965_rs_collect_tx_data(curr_tbl, rs_idx, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 935 | info->status.ampdu_len, |
| 936 | info->status.ampdu_ack_len); |
| 937 | |
| 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); |
| 943 | } |
| 944 | } else { |
| 945 | /* |
| 946 | * For legacy, update frame history with for each Tx retry. |
| 947 | */ |
| 948 | retries = info->status.rates[0].count - 1; |
| 949 | /* HW doesn't send more than 15 retries */ |
| 950 | retries = min(retries, 15); |
| 951 | |
| 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); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 957 | il4965_rs_get_tbl_info_from_mcs(tx_rate, il->band, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 958 | &tbl_type, &rs_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 959 | /* |
| 960 | * Only collect stats if retried rate is in the same RS |
| 961 | * table as active/search. |
| 962 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 963 | if (il4965_table_type_matches(&tbl_type, curr_tbl)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 964 | tmp_tbl = curr_tbl; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 965 | else if (il4965_table_type_matches(&tbl_type, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 966 | other_tbl)) |
| 967 | tmp_tbl = other_tbl; |
| 968 | else |
| 969 | continue; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 970 | il4965_rs_collect_tx_data(tmp_tbl, rs_idx, 1, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 971 | i < retries ? 0 : legacy_success); |
| 972 | } |
| 973 | |
| 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); |
| 978 | } |
| 979 | } |
| 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; |
| 982 | done: |
| 983 | /* See if there's a better rate or modulation mode to try. */ |
| 984 | if (sta && sta->supp_rates[sband->band]) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 985 | il4965_rs_rate_scale_perform(il, skb, sta, lq_sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /* |
| 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, |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 992 | * and reset overall (spanning all rates) tx success history stats. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 993 | * These control how long we stay using same modulation mode before |
| 994 | * searching for a new mode. |
| 995 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 996 | static void il4965_rs_set_stay_in_table(struct il_priv *il, u8 is_legacy, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 997 | struct il_lq_sta *lq_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 998 | { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 999 | D_RATE("we are staying in the same table\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1000 | lq_sta->stay_in_tbl = 1; /* only place this gets set */ |
| 1001 | if (is_legacy) { |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1002 | lq_sta->table_count_limit = IL_LEGACY_TBL_COUNT; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1003 | lq_sta->max_failure_limit = IL_LEGACY_FAILURE_LIMIT; |
| 1004 | lq_sta->max_success_limit = IL_LEGACY_SUCCESS_LIMIT; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1005 | } else { |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1006 | lq_sta->table_count_limit = IL_NONE_LEGACY_TBL_COUNT; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1007 | lq_sta->max_failure_limit = IL_NONE_LEGACY_FAILURE_LIMIT; |
| 1008 | lq_sta->max_success_limit = IL_NONE_LEGACY_SUCCESS_LIMIT; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1009 | } |
| 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; |
| 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | * Find correct throughput table for given mode of modulation |
| 1019 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1020 | static void il4965_rs_set_expected_tpt_table(struct il_lq_sta *lq_sta, |
| 1021 | struct il_scale_tbl_info *tbl) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1022 | { |
| 1023 | /* Used to choose among HT tables */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1024 | s32 (*ht_tbl_pointer)[RATE_COUNT]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1025 | |
| 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; |
| 1029 | return; |
| 1030 | } |
| 1031 | |
| 1032 | /* Legacy rates have only one table */ |
| 1033 | if (is_legacy(tbl->lq_type)) { |
| 1034 | tbl->expected_tpt = expected_tpt_legacy; |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | /* Choose among many HT tables depending on number of streams |
| 1039 | * (SISO/MIMO2), channel width (20/40), SGI, and aggregation |
| 1040 | * status */ |
| 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; |
| 1049 | |
| 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]; |
| 1056 | else /* AGG+SGI */ |
| 1057 | tbl->expected_tpt = ht_tbl_pointer[3]; |
| 1058 | } |
| 1059 | |
| 1060 | /* |
| 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. |
| 1065 | * |
| 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. |
| 1071 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1072 | static s32 il4965_rs_get_best_rate(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1073 | struct il_lq_sta *lq_sta, |
| 1074 | struct il_scale_tbl_info *tbl, /* "search" */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1075 | u16 rate_mask, s8 idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1076 | { |
| 1077 | /* "active" values */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1078 | struct il_scale_tbl_info *active_tbl = |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1079 | &(lq_sta->lq_info[lq_sta->active_tbl]); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1080 | s32 active_sr = active_tbl->win[idx].success_ratio; |
| 1081 | s32 active_tpt = active_tbl->expected_tpt[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1082 | |
| 1083 | /* expected "search" throughput */ |
| 1084 | s32 *tpt_tbl = tbl->expected_tpt; |
| 1085 | |
| 1086 | s32 new_rate, high, low, start_hi; |
| 1087 | u16 high_low; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1088 | s8 rate = idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1089 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1090 | new_rate = high = low = start_hi = RATE_INVALID; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1091 | |
| 1092 | for (; ;) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1093 | high_low = il4965_rs_get_adjacent_rate(il, rate, rate_mask, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1094 | tbl->lq_type); |
| 1095 | |
| 1096 | low = high_low & 0xff; |
| 1097 | high = (high_low >> 8) & 0xff; |
| 1098 | |
| 1099 | /* |
| 1100 | * Lower the "search" bit rate, to give new "search" mode |
| 1101 | * approximately the same throughput as "active" if: |
| 1102 | * |
| 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). |
| 1108 | * OR |
| 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). |
| 1113 | */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1114 | if ((100 * tpt_tbl[rate] > lq_sta->last_tpt && |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1115 | (active_sr > RATE_DECREASE_TH && |
| 1116 | active_sr <= RATE_HIGH_TH && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1117 | tpt_tbl[rate] <= active_tpt)) || |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1118 | (active_sr >= RATE_SCALE_SWITCH && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1119 | tpt_tbl[rate] > active_tpt)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1120 | |
| 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. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1124 | if (start_hi != RATE_INVALID) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1125 | new_rate = start_hi; |
| 1126 | break; |
| 1127 | } |
| 1128 | |
| 1129 | new_rate = rate; |
| 1130 | |
| 1131 | /* Loop again with lower rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1132 | if (low != RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1133 | rate = low; |
| 1134 | |
| 1135 | /* Lower rate not available, use the original */ |
| 1136 | else |
| 1137 | break; |
| 1138 | |
| 1139 | /* Else try to raise the "search" rate to match "active" */ |
| 1140 | } else { |
| 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. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1144 | if (new_rate != RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1145 | break; |
| 1146 | |
| 1147 | /* Loop again with higher rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1148 | else if (high != RATE_INVALID) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1149 | start_hi = high; |
| 1150 | rate = high; |
| 1151 | |
| 1152 | /* Higher rate not available, use the original */ |
| 1153 | } else { |
| 1154 | new_rate = rate; |
| 1155 | break; |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | return new_rate; |
| 1161 | } |
| 1162 | |
| 1163 | /* |
| 1164 | * Set up search table for MIMO2 |
| 1165 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1166 | static int il4965_rs_switch_to_mimo2(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1167 | struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1168 | struct ieee80211_conf *conf, |
| 1169 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1170 | struct il_scale_tbl_info *tbl, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1171 | { |
| 1172 | u16 rate_mask; |
| 1173 | s32 rate; |
| 1174 | s8 is_green = lq_sta->is_green; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1175 | struct il_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1176 | struct il_rxon_context *ctx = sta_priv->common.ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1177 | |
| 1178 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
| 1179 | return -1; |
| 1180 | |
| 1181 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) |
| 1182 | == WLAN_HT_CAP_SM_PS_STATIC) |
| 1183 | return -1; |
| 1184 | |
| 1185 | /* Need both Tx chains/antennas to support MIMO */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1186 | if (il->hw_params.tx_chains_num < 2) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1187 | return -1; |
| 1188 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1189 | D_RATE("LQ: try to switch to MIMO2\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1190 | |
| 1191 | tbl->lq_type = LQ_MIMO2; |
| 1192 | tbl->is_dup = lq_sta->is_dup; |
| 1193 | tbl->action = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1194 | tbl->max_search = IL_MAX_SEARCH; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1195 | rate_mask = lq_sta->active_mimo2_rate; |
| 1196 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1197 | if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1198 | tbl->is_ht40 = 1; |
| 1199 | else |
| 1200 | tbl->is_ht40 = 0; |
| 1201 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1202 | il4965_rs_set_expected_tpt_table(lq_sta, tbl); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1203 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1204 | rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1205 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1206 | D_RATE("LQ: MIMO2 best rate %d mask %X\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1207 | rate, rate_mask); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1208 | if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1209 | D_RATE( |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1210 | "Can't switch with idx %d rate mask %x\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1211 | rate, rate_mask); |
| 1212 | return -1; |
| 1213 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1214 | tbl->current_rate = il4965_rate_n_flags_from_tbl(il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1215 | tbl, rate, is_green); |
| 1216 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1217 | D_RATE("LQ: Switch to new mcs %X idx is green %X\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1218 | tbl->current_rate, is_green); |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | /* |
| 1223 | * Set up search table for SISO |
| 1224 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1225 | static int il4965_rs_switch_to_siso(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1226 | struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1227 | struct ieee80211_conf *conf, |
| 1228 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1229 | struct il_scale_tbl_info *tbl, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1230 | { |
| 1231 | u16 rate_mask; |
| 1232 | u8 is_green = lq_sta->is_green; |
| 1233 | s32 rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1234 | struct il_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1235 | struct il_rxon_context *ctx = sta_priv->common.ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1236 | |
| 1237 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
| 1238 | return -1; |
| 1239 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1240 | D_RATE("LQ: try to switch to SISO\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1241 | |
| 1242 | tbl->is_dup = lq_sta->is_dup; |
| 1243 | tbl->lq_type = LQ_SISO; |
| 1244 | tbl->action = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1245 | tbl->max_search = IL_MAX_SEARCH; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1246 | rate_mask = lq_sta->active_siso_rate; |
| 1247 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1248 | if (il_is_ht40_tx_allowed(il, ctx, &sta->ht_cap)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1249 | tbl->is_ht40 = 1; |
| 1250 | else |
| 1251 | tbl->is_ht40 = 0; |
| 1252 | |
| 1253 | if (is_green) |
| 1254 | tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/ |
| 1255 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1256 | il4965_rs_set_expected_tpt_table(lq_sta, tbl); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1257 | rate = il4965_rs_get_best_rate(il, lq_sta, tbl, rate_mask, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1258 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1259 | D_RATE("LQ: get best rate %d mask %X\n", rate, rate_mask); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1260 | if (rate == RATE_INVALID || !((1 << rate) & rate_mask)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1261 | D_RATE( |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1262 | "can not switch with idx %d rate mask %x\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1263 | rate, rate_mask); |
| 1264 | return -1; |
| 1265 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1266 | tbl->current_rate = il4965_rate_n_flags_from_tbl(il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1267 | tbl, rate, is_green); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1268 | D_RATE("LQ: Switch to new mcs %X idx is green %X\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1269 | tbl->current_rate, is_green); |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | /* |
| 1274 | * Try to switch to new modulation mode from legacy |
| 1275 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1276 | static int il4965_rs_move_legacy_other(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1277 | struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1278 | struct ieee80211_conf *conf, |
| 1279 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1280 | int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1281 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1282 | struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1283 | struct il_scale_tbl_info *search_tbl = |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1284 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1285 | struct il_rate_scale_data *win = &(tbl->win[idx]); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1286 | u32 sz = (sizeof(struct il_scale_tbl_info) - |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1287 | (sizeof(struct il_rate_scale_data) * RATE_COUNT)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1288 | u8 start_action; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1289 | u8 valid_tx_ant = il->hw_params.valid_tx_ant; |
| 1290 | u8 tx_chains_num = il->hw_params.tx_chains_num; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1291 | int ret = 0; |
| 1292 | u8 update_search_tbl_counter = 0; |
| 1293 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1294 | tbl->action = IL_LEGACY_SWITCH_SISO; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1295 | |
| 1296 | start_action = tbl->action; |
| 1297 | for (; ;) { |
| 1298 | lq_sta->action_counter++; |
| 1299 | switch (tbl->action) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1300 | case IL_LEGACY_SWITCH_ANTENNA1: |
| 1301 | case IL_LEGACY_SWITCH_ANTENNA2: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1302 | D_RATE("LQ: Legacy toggle Antenna\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1303 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1304 | if ((tbl->action == IL_LEGACY_SWITCH_ANTENNA1 && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1305 | tx_chains_num <= 1) || |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1306 | (tbl->action == IL_LEGACY_SWITCH_ANTENNA2 && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1307 | tx_chains_num <= 2)) |
| 1308 | break; |
| 1309 | |
| 1310 | /* Don't change antenna if success has been great */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1311 | if (win->success_ratio >= IL_RS_GOOD_RATIO) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | /* Set up search table to try other antenna */ |
| 1315 | memcpy(search_tbl, tbl, sz); |
| 1316 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1317 | if (il4965_rs_toggle_antenna(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1318 | &search_tbl->current_rate, search_tbl)) { |
| 1319 | update_search_tbl_counter = 1; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1320 | il4965_rs_set_expected_tpt_table(lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1321 | search_tbl); |
| 1322 | goto out; |
| 1323 | } |
| 1324 | break; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1325 | case IL_LEGACY_SWITCH_SISO: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1326 | D_RATE("LQ: Legacy switch to SISO\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1327 | |
| 1328 | /* Set up search table to try SISO */ |
| 1329 | memcpy(search_tbl, tbl, sz); |
| 1330 | search_tbl->is_SGI = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1331 | ret = il4965_rs_switch_to_siso(il, lq_sta, conf, sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1332 | search_tbl, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1333 | if (!ret) { |
| 1334 | lq_sta->action_counter = 0; |
| 1335 | goto out; |
| 1336 | } |
| 1337 | |
| 1338 | break; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1339 | case IL_LEGACY_SWITCH_MIMO2_AB: |
| 1340 | case IL_LEGACY_SWITCH_MIMO2_AC: |
| 1341 | case IL_LEGACY_SWITCH_MIMO2_BC: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1342 | D_RATE("LQ: Legacy switch to MIMO2\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1343 | |
| 1344 | /* Set up search table to try MIMO */ |
| 1345 | memcpy(search_tbl, tbl, sz); |
| 1346 | search_tbl->is_SGI = 0; |
| 1347 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1348 | if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AB) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1349 | search_tbl->ant_type = ANT_AB; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1350 | else if (tbl->action == IL_LEGACY_SWITCH_MIMO2_AC) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1351 | search_tbl->ant_type = ANT_AC; |
| 1352 | else |
| 1353 | search_tbl->ant_type = ANT_BC; |
| 1354 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1355 | if (!il4965_rs_is_valid_ant(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1356 | search_tbl->ant_type)) |
| 1357 | break; |
| 1358 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1359 | ret = il4965_rs_switch_to_mimo2(il, lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1360 | conf, sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1361 | search_tbl, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1362 | if (!ret) { |
| 1363 | lq_sta->action_counter = 0; |
| 1364 | goto out; |
| 1365 | } |
| 1366 | break; |
| 1367 | } |
| 1368 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1369 | if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC) |
| 1370 | tbl->action = IL_LEGACY_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1371 | |
| 1372 | if (tbl->action == start_action) |
| 1373 | break; |
| 1374 | |
| 1375 | } |
| 1376 | search_tbl->lq_type = LQ_NONE; |
| 1377 | return 0; |
| 1378 | |
| 1379 | out: |
| 1380 | lq_sta->search_better_tbl = 1; |
| 1381 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1382 | if (tbl->action > IL_LEGACY_SWITCH_MIMO2_BC) |
| 1383 | tbl->action = IL_LEGACY_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1384 | if (update_search_tbl_counter) |
| 1385 | search_tbl->action = tbl->action; |
| 1386 | return 0; |
| 1387 | |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | * Try to switch to new modulation mode from SISO |
| 1392 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1393 | static int il4965_rs_move_siso_to_other(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1394 | struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1395 | struct ieee80211_conf *conf, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1396 | struct ieee80211_sta *sta, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1397 | { |
| 1398 | u8 is_green = lq_sta->is_green; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1399 | struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1400 | struct il_scale_tbl_info *search_tbl = |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1401 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1402 | struct il_rate_scale_data *win = &(tbl->win[idx]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1403 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1404 | u32 sz = (sizeof(struct il_scale_tbl_info) - |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1405 | (sizeof(struct il_rate_scale_data) * RATE_COUNT)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1406 | u8 start_action; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1407 | u8 valid_tx_ant = il->hw_params.valid_tx_ant; |
| 1408 | u8 tx_chains_num = il->hw_params.tx_chains_num; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1409 | u8 update_search_tbl_counter = 0; |
| 1410 | int ret; |
| 1411 | |
| 1412 | start_action = tbl->action; |
| 1413 | |
| 1414 | for (;;) { |
| 1415 | lq_sta->action_counter++; |
| 1416 | switch (tbl->action) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1417 | case IL_SISO_SWITCH_ANTENNA1: |
| 1418 | case IL_SISO_SWITCH_ANTENNA2: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1419 | D_RATE("LQ: SISO toggle Antenna\n"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1420 | if ((tbl->action == IL_SISO_SWITCH_ANTENNA1 && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1421 | tx_chains_num <= 1) || |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1422 | (tbl->action == IL_SISO_SWITCH_ANTENNA2 && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1423 | tx_chains_num <= 2)) |
| 1424 | break; |
| 1425 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1426 | if (win->success_ratio >= IL_RS_GOOD_RATIO) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | memcpy(search_tbl, tbl, sz); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1430 | if (il4965_rs_toggle_antenna(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1431 | &search_tbl->current_rate, search_tbl)) { |
| 1432 | update_search_tbl_counter = 1; |
| 1433 | goto out; |
| 1434 | } |
| 1435 | break; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1436 | case IL_SISO_SWITCH_MIMO2_AB: |
| 1437 | case IL_SISO_SWITCH_MIMO2_AC: |
| 1438 | case IL_SISO_SWITCH_MIMO2_BC: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1439 | D_RATE("LQ: SISO switch to MIMO2\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1440 | memcpy(search_tbl, tbl, sz); |
| 1441 | search_tbl->is_SGI = 0; |
| 1442 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1443 | if (tbl->action == IL_SISO_SWITCH_MIMO2_AB) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1444 | search_tbl->ant_type = ANT_AB; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1445 | else if (tbl->action == IL_SISO_SWITCH_MIMO2_AC) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1446 | search_tbl->ant_type = ANT_AC; |
| 1447 | else |
| 1448 | search_tbl->ant_type = ANT_BC; |
| 1449 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1450 | if (!il4965_rs_is_valid_ant(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1451 | search_tbl->ant_type)) |
| 1452 | break; |
| 1453 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1454 | ret = il4965_rs_switch_to_mimo2(il, lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1455 | conf, sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1456 | search_tbl, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1457 | if (!ret) |
| 1458 | goto out; |
| 1459 | break; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1460 | case IL_SISO_SWITCH_GI: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1461 | if (!tbl->is_ht40 && !(ht_cap->cap & |
| 1462 | IEEE80211_HT_CAP_SGI_20)) |
| 1463 | break; |
| 1464 | if (tbl->is_ht40 && !(ht_cap->cap & |
| 1465 | IEEE80211_HT_CAP_SGI_40)) |
| 1466 | break; |
| 1467 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1468 | D_RATE("LQ: SISO toggle SGI/NGI\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1469 | |
| 1470 | memcpy(search_tbl, tbl, sz); |
| 1471 | if (is_green) { |
| 1472 | if (!tbl->is_SGI) |
| 1473 | break; |
| 1474 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1475 | IL_ERR( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1476 | "SGI was set in GF+SISO\n"); |
| 1477 | } |
| 1478 | search_tbl->is_SGI = !tbl->is_SGI; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1479 | il4965_rs_set_expected_tpt_table(lq_sta, search_tbl); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1480 | if (tbl->is_SGI) { |
| 1481 | s32 tpt = lq_sta->last_tpt / 100; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1482 | if (tpt >= search_tbl->expected_tpt[idx]) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1483 | break; |
| 1484 | } |
| 1485 | search_tbl->current_rate = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1486 | il4965_rate_n_flags_from_tbl(il, search_tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1487 | idx, is_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1488 | update_search_tbl_counter = 1; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1492 | if (tbl->action > IL_SISO_SWITCH_GI) |
| 1493 | tbl->action = IL_SISO_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1494 | |
| 1495 | if (tbl->action == start_action) |
| 1496 | break; |
| 1497 | } |
| 1498 | search_tbl->lq_type = LQ_NONE; |
| 1499 | return 0; |
| 1500 | |
| 1501 | out: |
| 1502 | lq_sta->search_better_tbl = 1; |
| 1503 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1504 | if (tbl->action > IL_SISO_SWITCH_GI) |
| 1505 | tbl->action = IL_SISO_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1506 | if (update_search_tbl_counter) |
| 1507 | search_tbl->action = tbl->action; |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | /* |
| 1513 | * Try to switch to new modulation mode from MIMO2 |
| 1514 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1515 | static int il4965_rs_move_mimo2_to_other(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1516 | struct il_lq_sta *lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1517 | struct ieee80211_conf *conf, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1518 | struct ieee80211_sta *sta, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1519 | { |
| 1520 | s8 is_green = lq_sta->is_green; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1521 | struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1522 | struct il_scale_tbl_info *search_tbl = |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1523 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1524 | struct il_rate_scale_data *win = &(tbl->win[idx]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1525 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1526 | u32 sz = (sizeof(struct il_scale_tbl_info) - |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1527 | (sizeof(struct il_rate_scale_data) * RATE_COUNT)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1528 | u8 start_action; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1529 | u8 valid_tx_ant = il->hw_params.valid_tx_ant; |
| 1530 | u8 tx_chains_num = il->hw_params.tx_chains_num; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1531 | u8 update_search_tbl_counter = 0; |
| 1532 | int ret; |
| 1533 | |
| 1534 | start_action = tbl->action; |
| 1535 | for (;;) { |
| 1536 | lq_sta->action_counter++; |
| 1537 | switch (tbl->action) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1538 | case IL_MIMO2_SWITCH_ANTENNA1: |
| 1539 | case IL_MIMO2_SWITCH_ANTENNA2: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1540 | D_RATE("LQ: MIMO2 toggle Antennas\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1541 | |
| 1542 | if (tx_chains_num <= 2) |
| 1543 | break; |
| 1544 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1545 | if (win->success_ratio >= IL_RS_GOOD_RATIO) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1546 | break; |
| 1547 | |
| 1548 | memcpy(search_tbl, tbl, sz); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1549 | if (il4965_rs_toggle_antenna(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1550 | &search_tbl->current_rate, search_tbl)) { |
| 1551 | update_search_tbl_counter = 1; |
| 1552 | goto out; |
| 1553 | } |
| 1554 | break; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1555 | case IL_MIMO2_SWITCH_SISO_A: |
| 1556 | case IL_MIMO2_SWITCH_SISO_B: |
| 1557 | case IL_MIMO2_SWITCH_SISO_C: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1558 | D_RATE("LQ: MIMO2 switch to SISO\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1559 | |
| 1560 | /* Set up new search table for SISO */ |
| 1561 | memcpy(search_tbl, tbl, sz); |
| 1562 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1563 | if (tbl->action == IL_MIMO2_SWITCH_SISO_A) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1564 | search_tbl->ant_type = ANT_A; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1565 | else if (tbl->action == IL_MIMO2_SWITCH_SISO_B) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1566 | search_tbl->ant_type = ANT_B; |
| 1567 | else |
| 1568 | search_tbl->ant_type = ANT_C; |
| 1569 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1570 | if (!il4965_rs_is_valid_ant(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1571 | search_tbl->ant_type)) |
| 1572 | break; |
| 1573 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1574 | ret = il4965_rs_switch_to_siso(il, lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1575 | conf, sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1576 | search_tbl, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1577 | if (!ret) |
| 1578 | goto out; |
| 1579 | |
| 1580 | break; |
| 1581 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1582 | case IL_MIMO2_SWITCH_GI: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1583 | if (!tbl->is_ht40 && !(ht_cap->cap & |
| 1584 | IEEE80211_HT_CAP_SGI_20)) |
| 1585 | break; |
| 1586 | if (tbl->is_ht40 && !(ht_cap->cap & |
| 1587 | IEEE80211_HT_CAP_SGI_40)) |
| 1588 | break; |
| 1589 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1590 | D_RATE("LQ: MIMO2 toggle SGI/NGI\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1591 | |
| 1592 | /* Set up new search table for MIMO2 */ |
| 1593 | memcpy(search_tbl, tbl, sz); |
| 1594 | search_tbl->is_SGI = !tbl->is_SGI; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1595 | il4965_rs_set_expected_tpt_table(lq_sta, search_tbl); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1596 | /* |
| 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! |
| 1601 | */ |
| 1602 | if (tbl->is_SGI) { |
| 1603 | s32 tpt = lq_sta->last_tpt / 100; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1604 | if (tpt >= search_tbl->expected_tpt[idx]) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1605 | break; |
| 1606 | } |
| 1607 | search_tbl->current_rate = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1608 | il4965_rate_n_flags_from_tbl(il, search_tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1609 | idx, is_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1610 | update_search_tbl_counter = 1; |
| 1611 | goto out; |
| 1612 | |
| 1613 | } |
| 1614 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1615 | if (tbl->action > IL_MIMO2_SWITCH_GI) |
| 1616 | tbl->action = IL_MIMO2_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1617 | |
| 1618 | if (tbl->action == start_action) |
| 1619 | break; |
| 1620 | } |
| 1621 | search_tbl->lq_type = LQ_NONE; |
| 1622 | return 0; |
| 1623 | out: |
| 1624 | lq_sta->search_better_tbl = 1; |
| 1625 | tbl->action++; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1626 | if (tbl->action > IL_MIMO2_SWITCH_GI) |
| 1627 | tbl->action = IL_MIMO2_SWITCH_ANTENNA1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1628 | if (update_search_tbl_counter) |
| 1629 | search_tbl->action = tbl->action; |
| 1630 | |
| 1631 | return 0; |
| 1632 | |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 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) |
| 1641 | */ |
| 1642 | static void |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1643 | il4965_rs_stay_in_table(struct il_lq_sta *lq_sta, bool force_search) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1644 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1645 | struct il_scale_tbl_info *tbl; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1646 | int i; |
| 1647 | int active_tbl; |
| 1648 | int flush_interval_passed = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1649 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1650 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1651 | il = lq_sta->drv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1652 | active_tbl = lq_sta->active_tbl; |
| 1653 | |
| 1654 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1655 | |
| 1656 | /* If we've been disallowing search, see if we should now allow it */ |
| 1657 | if (lq_sta->stay_in_tbl) { |
| 1658 | |
| 1659 | /* Elapsed time using current modulation mode */ |
| 1660 | if (lq_sta->flush_timer) |
| 1661 | flush_interval_passed = |
| 1662 | time_after(jiffies, |
| 1663 | (unsigned long)(lq_sta->flush_timer + |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1664 | RATE_SCALE_FLUSH_INTVL)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1665 | |
| 1666 | /* |
| 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. |
| 1673 | */ |
| 1674 | if (force_search || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 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)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1679 | D_RATE("LQ: stay is expired %d %d %d\n:", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1680 | lq_sta->total_failed, |
| 1681 | lq_sta->total_success, |
| 1682 | flush_interval_passed); |
| 1683 | |
| 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; |
| 1689 | |
| 1690 | /* |
| 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 |
| 1694 | * active table. |
| 1695 | */ |
| 1696 | } else { |
| 1697 | lq_sta->table_count++; |
| 1698 | if (lq_sta->table_count >= |
| 1699 | lq_sta->table_count_limit) { |
| 1700 | lq_sta->table_count = 0; |
| 1701 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1702 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1703 | "LQ: stay in table clear win\n"); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1704 | for (i = 0; i < RATE_COUNT; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1705 | il4965_rs_rate_scale_clear_win( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1706 | &(tbl->win[i])); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 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) { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1714 | for (i = 0; i < RATE_COUNT; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1715 | il4965_rs_rate_scale_clear_win( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1716 | &(tbl->win[i])); |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * setup rate table in uCode |
| 1723 | * return rate_n_flags as used in the table |
| 1724 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1725 | static u32 il4965_rs_update_rate_tbl(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1726 | struct il_rxon_context *ctx, |
| 1727 | struct il_lq_sta *lq_sta, |
| 1728 | struct il_scale_tbl_info *tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1729 | int idx, u8 is_green) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1730 | { |
| 1731 | u32 rate; |
| 1732 | |
| 1733 | /* Update uCode's rate table. */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1734 | rate = il4965_rate_n_flags_from_tbl(il, tbl, idx, is_green); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1735 | il4965_rs_fill_link_cmd(il, lq_sta, rate); |
| 1736 | il_send_lq_cmd(il, ctx, &lq_sta->lq, CMD_ASYNC, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1737 | |
| 1738 | return rate; |
| 1739 | } |
| 1740 | |
| 1741 | /* |
| 1742 | * Do rate scaling and search for new modulation mode. |
| 1743 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1744 | static void il4965_rs_rate_scale_perform(struct il_priv *il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1745 | struct sk_buff *skb, |
| 1746 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1747 | struct il_lq_sta *lq_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1748 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1749 | struct ieee80211_hw *hw = il->hw; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1753 | int low = RATE_INVALID; |
| 1754 | int high = RATE_INVALID; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1755 | int idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1756 | int i; |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1757 | struct il_rate_scale_data *win = NULL; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1758 | int current_tpt = IL_INVALID_VALUE; |
| 1759 | int low_tpt = IL_INVALID_VALUE; |
| 1760 | int high_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1761 | u32 fail_count; |
| 1762 | s8 scale_action = 0; |
| 1763 | u16 rate_mask; |
| 1764 | u8 update_lq = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1765 | struct il_scale_tbl_info *tbl, *tbl1; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1766 | u16 rate_scale_idx_msk = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1767 | u32 rate; |
| 1768 | u8 is_green = 0; |
| 1769 | u8 active_tbl = 0; |
| 1770 | u8 done_search = 0; |
| 1771 | u16 high_low; |
| 1772 | s32 sr; |
| 1773 | u8 tid = MAX_TID_COUNT; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1777 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1778 | D_RATE("rate scale calculate new rate for skb\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1779 | |
| 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) || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1783 | (info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1784 | return; |
| 1785 | |
| 1786 | if (!sta || !lq_sta) |
| 1787 | return; |
| 1788 | |
| 1789 | lq_sta->supp_rates = sta->supp_rates[lq_sta->band]; |
| 1790 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1791 | tid = il4965_rs_tl_add_packet(lq_sta, hdr); |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1792 | if (tid != MAX_TID_COUNT && (lq_sta->tx_agg_tid_en & (1 << tid))) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1793 | tid_data = &il->stations[lq_sta->lq.sta_id].tid[tid]; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1794 | if (tid_data->agg.state == IL_AGG_OFF) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1795 | lq_sta->is_agg = 0; |
| 1796 | else |
| 1797 | lq_sta->is_agg = 1; |
| 1798 | } else |
| 1799 | lq_sta->is_agg = 0; |
| 1800 | |
| 1801 | /* |
| 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. |
| 1805 | */ |
| 1806 | if (!lq_sta->search_better_tbl) |
| 1807 | active_tbl = lq_sta->active_tbl; |
| 1808 | else |
| 1809 | active_tbl = 1 - lq_sta->active_tbl; |
| 1810 | |
| 1811 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1812 | if (is_legacy(tbl->lq_type)) |
| 1813 | lq_sta->is_green = 0; |
| 1814 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1815 | lq_sta->is_green = il4965_rs_use_green(sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1816 | is_green = lq_sta->is_green; |
| 1817 | |
| 1818 | /* current tx rate */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1819 | idx = lq_sta->last_txrate_idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1820 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1821 | D_RATE("Rate scale idx %d for type %d\n", idx, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1822 | tbl->lq_type); |
| 1823 | |
| 1824 | /* rates available for this association, and for modulation mode */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1825 | rate_mask = il4965_rs_get_supported_rates(lq_sta, hdr, tbl->lq_type); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1826 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1827 | D_RATE("mask 0x%04X\n", rate_mask); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1828 | |
| 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 */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1833 | rate_scale_idx_msk = (u16) (rate_mask & |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1834 | (lq_sta->supp_rates << IL_FIRST_OFDM_RATE)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1835 | else |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1836 | rate_scale_idx_msk = (u16) (rate_mask & |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1837 | lq_sta->supp_rates); |
| 1838 | |
| 1839 | } else |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1840 | rate_scale_idx_msk = rate_mask; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1841 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1842 | if (!rate_scale_idx_msk) |
| 1843 | rate_scale_idx_msk = rate_mask; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1844 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1845 | if (!((1 << idx) & rate_scale_idx_msk)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1846 | IL_ERR("Current Rate is not valid\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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 */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1853 | idx = il4965_hwrate_to_plcp_idx(tbl->current_rate); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1854 | rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1855 | tbl, idx, is_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1856 | } |
| 1857 | return; |
| 1858 | } |
| 1859 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1860 | /* Get expected throughput table and history win for current rate */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1861 | if (!tbl->expected_tpt) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1862 | IL_ERR("tbl->expected_tpt is NULL\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1863 | return; |
| 1864 | } |
| 1865 | |
| 1866 | /* force user max rate if set by user */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1867 | if (lq_sta->max_rate_idx != -1 && |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1868 | lq_sta->max_rate_idx < idx) { |
| 1869 | idx = lq_sta->max_rate_idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1870 | update_lq = 1; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1871 | win = &(tbl->win[idx]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1872 | goto lq_update; |
| 1873 | } |
| 1874 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1875 | win = &(tbl->win[idx]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1876 | |
| 1877 | /* |
| 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). |
| 1883 | */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1884 | fail_count = win->counter - win->success_counter; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1885 | if (fail_count < RATE_MIN_FAILURE_TH && |
| 1886 | win->success_counter < RATE_MIN_SUCCESS_TH) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1887 | D_RATE("LQ: still below TH. succ=%d total=%d " |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1888 | "for idx %d\n", |
| 1889 | win->success_counter, win->counter, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1890 | |
| 1891 | /* Can't calculate this yet; not enough history */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1892 | win->average_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1893 | |
| 1894 | /* Should we stay with this modulation mode, |
| 1895 | * or search for a new one? */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1896 | il4965_rs_stay_in_table(lq_sta, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1897 | |
| 1898 | goto out; |
| 1899 | } |
| 1900 | /* Else we have enough samples; calculate estimate of |
| 1901 | * actual average throughput */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1902 | if (win->average_tpt != ((win->success_ratio * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1903 | tbl->expected_tpt[idx] + 64) / 128)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1904 | IL_ERR( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1905 | "expected_tpt should have been calculated by now\n"); |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1906 | win->average_tpt = ((win->success_ratio * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1907 | tbl->expected_tpt[idx] + 64) / 128); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1908 | } |
| 1909 | |
| 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. */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1915 | if (win->average_tpt > lq_sta->last_tpt) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1916 | |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1917 | D_RATE("LQ: SWITCHING TO NEW TBL " |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1918 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1919 | win->success_ratio, |
| 1920 | win->average_tpt, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1921 | lq_sta->last_tpt); |
| 1922 | |
| 1923 | if (!is_legacy(tbl->lq_type)) |
| 1924 | lq_sta->enable_counter = 1; |
| 1925 | |
| 1926 | /* Swap tables; "search" becomes "active" */ |
| 1927 | lq_sta->active_tbl = active_tbl; |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1928 | current_tpt = win->average_tpt; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1929 | |
| 1930 | /* Else poor success; go back to mode in "active" table */ |
| 1931 | } else { |
| 1932 | |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1933 | D_RATE("LQ: GOING BACK TO THE OLD TBL " |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1934 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1935 | win->success_ratio, |
| 1936 | win->average_tpt, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1937 | lq_sta->last_tpt); |
| 1938 | |
| 1939 | /* Nullify "search" table */ |
| 1940 | tbl->lq_type = LQ_NONE; |
| 1941 | |
| 1942 | /* Revert to "active" table */ |
| 1943 | active_tbl = lq_sta->active_tbl; |
| 1944 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1945 | |
| 1946 | /* Revert to "active" rate and throughput info */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1947 | idx = il4965_hwrate_to_plcp_idx(tbl->current_rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1948 | current_tpt = lq_sta->last_tpt; |
| 1949 | |
| 1950 | /* Need to set up a new rate table in uCode */ |
| 1951 | update_lq = 1; |
| 1952 | } |
| 1953 | |
| 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! */ |
| 1958 | goto lq_update; |
| 1959 | } |
| 1960 | |
| 1961 | /* (Else) not in search of better modulation mode, try for better |
| 1962 | * starting rate, while staying in this mode. */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1963 | high_low = il4965_rs_get_adjacent_rate(il, idx, |
| 1964 | rate_scale_idx_msk, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1965 | tbl->lq_type); |
| 1966 | low = high_low & 0xff; |
| 1967 | high = (high_low >> 8) & 0xff; |
| 1968 | |
| 1969 | /* If user set max rate, dont allow higher than user constrain */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1970 | if (lq_sta->max_rate_idx != -1 && |
| 1971 | lq_sta->max_rate_idx < high) |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1972 | high = RATE_INVALID; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1973 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1974 | sr = win->success_ratio; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1975 | |
| 1976 | /* Collect measured throughputs for current and adjacent rates */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1977 | current_tpt = win->average_tpt; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1978 | if (low != RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1979 | low_tpt = tbl->win[low].average_tpt; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1980 | if (high != RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1981 | high_tpt = tbl->win[high].average_tpt; |
| 1982 | |
| 1983 | scale_action = 0; |
| 1984 | |
| 1985 | /* Too many failures, decrease rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1986 | if (sr <= RATE_DECREASE_TH || current_tpt == 0) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1987 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1988 | "decrease rate because of low success_ratio\n"); |
| 1989 | scale_action = -1; |
| 1990 | |
| 1991 | /* No throughput measured yet for adjacent rates; try increase. */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1992 | } else if (low_tpt == IL_INVALID_VALUE && |
| 1993 | high_tpt == IL_INVALID_VALUE) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1994 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1995 | if (high != RATE_INVALID && sr >= RATE_INCREASE_TH) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1996 | scale_action = 1; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 1997 | else if (low != RATE_INVALID) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1998 | scale_action = 0; |
| 1999 | } |
| 2000 | |
| 2001 | /* Both adjacent throughputs are measured, but neither one has better |
| 2002 | * throughput; we're using the best rate, don't change it! */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2003 | else if (low_tpt != IL_INVALID_VALUE && high_tpt != IL_INVALID_VALUE && |
| 2004 | low_tpt < current_tpt && high_tpt < current_tpt) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2005 | scale_action = 0; |
| 2006 | |
| 2007 | /* At least one adjacent rate's throughput is measured, |
| 2008 | * and may have better performance. */ |
| 2009 | else { |
| 2010 | /* Higher adjacent rate's throughput is measured */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2011 | if (high_tpt != IL_INVALID_VALUE) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2012 | /* Higher rate has better throughput */ |
| 2013 | if (high_tpt > current_tpt && |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2014 | sr >= RATE_INCREASE_TH) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2015 | scale_action = 1; |
| 2016 | } else { |
| 2017 | scale_action = 0; |
| 2018 | } |
| 2019 | |
| 2020 | /* Lower adjacent rate's throughput is measured */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2021 | } else if (low_tpt != IL_INVALID_VALUE) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2022 | /* Lower rate has better throughput */ |
| 2023 | if (low_tpt > current_tpt) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2024 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2025 | "decrease rate because of low tpt\n"); |
| 2026 | scale_action = -1; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2027 | } else if (sr >= RATE_INCREASE_TH) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2028 | scale_action = 1; |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | /* Sanity check; asked for decrease, but success rate or throughput |
| 2034 | * has been good at old rate. Don't change it. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2035 | if (scale_action == -1 && low != RATE_INVALID && |
| 2036 | (sr > RATE_HIGH_TH || current_tpt > 100 * tbl->expected_tpt[low])) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2037 | scale_action = 0; |
| 2038 | |
| 2039 | switch (scale_action) { |
| 2040 | case -1: |
| 2041 | /* Decrease starting rate, update uCode's rate table */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2042 | if (low != RATE_INVALID) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2043 | update_lq = 1; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2044 | idx = low; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | break; |
| 2048 | case 1: |
| 2049 | /* Increase starting rate, update uCode's rate table */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2050 | if (high != RATE_INVALID) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2051 | update_lq = 1; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2052 | idx = high; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | break; |
| 2056 | case 0: |
| 2057 | /* No change */ |
| 2058 | default: |
| 2059 | break; |
| 2060 | } |
| 2061 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2062 | D_RATE("choose rate scale idx %d action %d low %d " |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2063 | "high %d type %d\n", |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2064 | idx, scale_action, low, high, tbl->lq_type); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2065 | |
| 2066 | lq_update: |
| 2067 | /* Replace uCode's rate table for the destination station. */ |
| 2068 | if (update_lq) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2069 | rate = il4965_rs_update_rate_tbl(il, ctx, lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2070 | tbl, idx, is_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2071 | |
| 2072 | /* Should we stay with this modulation mode, |
| 2073 | * or search for a new one? */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2074 | il4965_rs_stay_in_table(lq_sta, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2075 | |
| 2076 | /* |
| 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 |
| 2081 | */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2082 | if (!update_lq && !done_search && !lq_sta->stay_in_tbl && |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 2083 | win->counter) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2084 | /* Save current throughput to compare with "search" throughput*/ |
| 2085 | lq_sta->last_tpt = current_tpt; |
| 2086 | |
| 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)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2090 | il4965_rs_move_legacy_other(il, lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2091 | conf, sta, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2092 | else if (is_siso(tbl->lq_type)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2093 | il4965_rs_move_siso_to_other(il, lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2094 | conf, sta, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2095 | else /* (is_mimo2(tbl->lq_type)) */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2096 | il4965_rs_move_mimo2_to_other(il, lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2097 | conf, sta, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2098 | |
| 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)]); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2103 | for (i = 0; i < RATE_COUNT; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 2104 | il4965_rs_rate_scale_clear_win( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2105 | &(tbl->win[i])); |
| 2106 | |
| 2107 | /* Use new "search" start rate */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2108 | idx = il4965_hwrate_to_plcp_idx(tbl->current_rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2109 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2110 | D_RATE( |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2111 | "Switch current mcs: %X idx: %d\n", |
| 2112 | tbl->current_rate, idx); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2113 | il4965_rs_fill_link_cmd(il, lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2114 | tbl->current_rate); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2115 | il_send_lq_cmd(il, ctx, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2116 | &lq_sta->lq, CMD_ASYNC, false); |
| 2117 | } else |
| 2118 | done_search = 1; |
| 2119 | } |
| 2120 | |
| 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) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2130 | D_RATE("LQ: STAY in legacy table\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2131 | il4965_rs_set_stay_in_table(il, 1, lq_sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
| 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 && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2138 | lq_sta->action_counter >= tbl1->max_search) { |
| 2139 | if (lq_sta->last_tpt > IL_AGG_TPT_THREHOLD && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2140 | (lq_sta->tx_agg_tid_en & (1 << tid)) && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2141 | tid != MAX_TID_COUNT) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2142 | tid_data = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2143 | &il->stations[lq_sta->lq.sta_id].tid[tid]; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2144 | if (tid_data->agg.state == IL_AGG_OFF) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2145 | D_RATE( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2146 | "try to aggregate tid %d\n", |
| 2147 | tid); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2148 | il4965_rs_tl_turn_on_agg(il, tid, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2149 | lq_sta, sta); |
| 2150 | } |
| 2151 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2152 | il4965_rs_set_stay_in_table(il, 0, lq_sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2157 | tbl->current_rate = il4965_rate_n_flags_from_tbl(il, tbl, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2158 | idx, is_green); |
| 2159 | i = idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2160 | lq_sta->last_txrate_idx = i; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2164 | * il4965_rs_initialize_lq - Initialize a station's hardware rate table |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2165 | * |
| 2166 | * The uCode's station table contains a table of fallback rates |
| 2167 | * for automatic fallback during transmission. |
| 2168 | * |
| 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 |
| 2171 | * rc80211_simple. |
| 2172 | * |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 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, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2175 | * which requires station table entry to exist). |
| 2176 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2177 | static void il4965_rs_initialize_lq(struct il_priv *il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2178 | struct ieee80211_conf *conf, |
| 2179 | struct ieee80211_sta *sta, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2180 | struct il_lq_sta *lq_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2181 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2182 | struct il_scale_tbl_info *tbl; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2183 | int rate_idx; |
| 2184 | int i; |
| 2185 | u32 rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2186 | u8 use_green = il4965_rs_use_green(sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2187 | u8 active_tbl = 0; |
| 2188 | u8 valid_tx_ant; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2189 | struct il_station_priv *sta_priv; |
| 2190 | struct il_rxon_context *ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2191 | |
| 2192 | if (!sta || !lq_sta) |
| 2193 | return; |
| 2194 | |
| 2195 | sta_priv = (void *)sta->drv_priv; |
| 2196 | ctx = sta_priv->common.ctx; |
| 2197 | |
| 2198 | i = lq_sta->last_txrate_idx; |
| 2199 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2200 | valid_tx_ant = il->hw_params.valid_tx_ant; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2201 | |
| 2202 | if (!lq_sta->search_better_tbl) |
| 2203 | active_tbl = lq_sta->active_tbl; |
| 2204 | else |
| 2205 | active_tbl = 1 - lq_sta->active_tbl; |
| 2206 | |
| 2207 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 2208 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2209 | if (i < 0 || i >= RATE_COUNT) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2210 | i = 0; |
| 2211 | |
Stanislaw Gruszka | d2ddf621 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 2212 | rate = il_rates[i].plcp; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2213 | tbl->ant_type = il4965_first_antenna(valid_tx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2214 | rate |= tbl->ant_type << RATE_MCS_ANT_POS; |
| 2215 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2216 | if (i >= IL_FIRST_CCK_RATE && i <= IL_LAST_CCK_RATE) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2217 | rate |= RATE_MCS_CCK_MSK; |
| 2218 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2219 | il4965_rs_get_tbl_info_from_mcs(rate, il->band, tbl, &rate_idx); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2220 | if (!il4965_rs_is_valid_ant(valid_tx_ant, tbl->ant_type)) |
| 2221 | il4965_rs_toggle_antenna(valid_tx_ant, &rate, tbl); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2222 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2223 | rate = il4965_rate_n_flags_from_tbl(il, tbl, rate_idx, use_green); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2224 | tbl->current_rate = rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2225 | il4965_rs_set_expected_tpt_table(lq_sta, tbl); |
| 2226 | il4965_rs_fill_link_cmd(NULL, lq_sta, rate); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 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); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | static void |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2232 | il4965_rs_get_rate(void *il_r, struct ieee80211_sta *sta, void *il_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2233 | struct ieee80211_tx_rate_control *txrc) |
| 2234 | { |
| 2235 | |
| 2236 | struct sk_buff *skb = txrc->skb; |
| 2237 | struct ieee80211_supported_band *sband = txrc->sband; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2238 | struct il_priv *il __maybe_unused = (struct il_priv *)il_r; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2239 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2240 | struct il_lq_sta *lq_sta = il_sta; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2241 | int rate_idx; |
| 2242 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2243 | D_RATE("rate scale calculate new rate for skb\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2244 | |
| 2245 | /* Get max rate if user set max rate */ |
| 2246 | if (lq_sta) { |
| 2247 | lq_sta->max_rate_idx = txrc->max_rate_idx; |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2248 | if (sband->band == IEEE80211_BAND_5GHZ && |
| 2249 | lq_sta->max_rate_idx != -1) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2250 | lq_sta->max_rate_idx += IL_FIRST_OFDM_RATE; |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2251 | if (lq_sta->max_rate_idx < 0 || |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2252 | lq_sta->max_rate_idx >= RATE_COUNT) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2253 | lq_sta->max_rate_idx = -1; |
| 2254 | } |
| 2255 | |
| 2256 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 2257 | if (lq_sta && !lq_sta->drv) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2258 | D_RATE("Rate scaling not initialized yet.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2259 | il_sta = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | /* Send management frames and NO_ACK data using lowest rate. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2263 | if (rate_control_send_low(sta, il_sta, txrc)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2264 | return; |
| 2265 | |
Greg Dietsche | 0c34861 | 2011-06-02 22:24:06 -0500 | [diff] [blame] | 2266 | if (!lq_sta) |
| 2267 | return; |
| 2268 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2269 | rate_idx = lq_sta->last_txrate_idx; |
| 2270 | |
| 2271 | if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2272 | rate_idx -= IL_FIRST_OFDM_RATE; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2273 | /* 6M and 9M shared same MCS idx */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2274 | rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2275 | if (il4965_rs_extract_rate(lq_sta->last_rate_n_flags) >= |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2276 | RATE_MIMO2_6M_PLCP) |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 2277 | rate_idx = rate_idx + MCS_IDX_PER_STREAM; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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; |
| 2291 | } else { |
| 2292 | /* Check for invalid rates */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2293 | if (rate_idx < 0 || rate_idx >= RATE_COUNT_LEGACY || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 2294 | (sband->band == IEEE80211_BAND_5GHZ && |
| 2295 | rate_idx < IL_FIRST_OFDM_RATE)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2296 | rate_idx = rate_lowest_index(sband, sta); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2297 | /* On valid 5 GHz rate, adjust idx */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2298 | else if (sband->band == IEEE80211_BAND_5GHZ) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2299 | rate_idx -= IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2300 | info->control.rates[0].flags = 0; |
| 2301 | } |
| 2302 | info->control.rates[0].idx = rate_idx; |
| 2303 | |
| 2304 | } |
| 2305 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2306 | static void *il4965_rs_alloc_sta(void *il_rate, struct ieee80211_sta *sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2307 | gfp_t gfp) |
| 2308 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2309 | struct il_lq_sta *lq_sta; |
| 2310 | struct il_station_priv *sta_priv = |
| 2311 | (struct il_station_priv *) sta->drv_priv; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2312 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2313 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2314 | il = (struct il_priv *)il_rate; |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 2315 | D_RATE("create station rate scale win\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2316 | |
| 2317 | lq_sta = &sta_priv->lq_sta; |
| 2318 | |
| 2319 | return lq_sta; |
| 2320 | } |
| 2321 | |
| 2322 | /* |
| 2323 | * Called after adding a new station to initialize rate scaling |
| 2324 | */ |
| 2325 | void |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2326 | il4965_rs_rate_init(struct il_priv *il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2327 | struct ieee80211_sta *sta, |
| 2328 | u8 sta_id) |
| 2329 | { |
| 2330 | int i, j; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2331 | struct ieee80211_hw *hw = il->hw; |
| 2332 | struct ieee80211_conf *conf = &il->hw->conf; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2333 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2334 | struct il_station_priv *sta_priv; |
| 2335 | struct il_lq_sta *lq_sta; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2336 | struct ieee80211_supported_band *sband; |
| 2337 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2338 | sta_priv = (struct il_station_priv *) sta->drv_priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2339 | lq_sta = &sta_priv->lq_sta; |
| 2340 | sband = hw->wiphy->bands[conf->channel->band]; |
| 2341 | |
| 2342 | |
| 2343 | lq_sta->lq.sta_id = sta_id; |
| 2344 | |
| 2345 | for (j = 0; j < LQ_SIZE; j++) |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2346 | for (i = 0; i < RATE_COUNT; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 2347 | il4965_rs_rate_scale_clear_win( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2348 | &lq_sta->lq_info[j].win[i]); |
| 2349 | |
| 2350 | lq_sta->flush_timer = 0; |
| 2351 | lq_sta->supp_rates = sta->supp_rates[sband->band]; |
| 2352 | for (j = 0; j < LQ_SIZE; j++) |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2353 | for (i = 0; i < RATE_COUNT; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 2354 | il4965_rs_rate_scale_clear_win( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2355 | &lq_sta->lq_info[j].win[i]); |
| 2356 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2357 | D_RATE("LQ:" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2358 | "*** rate scale station global init for station %d ***\n", |
| 2359 | sta_id); |
| 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 |
| 2363 | * after assoc.. */ |
| 2364 | |
| 2365 | lq_sta->is_dup = 0; |
| 2366 | lq_sta->max_rate_idx = -1; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2367 | lq_sta->missed_rate_counter = IL_MISSED_RATE_MAX; |
| 2368 | lq_sta->is_green = il4965_rs_use_green(sta); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2369 | lq_sta->active_legacy_rate = il->active_rate & ~(0x1000); |
| 2370 | lq_sta->band = il->band; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2371 | /* |
| 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. |
| 2374 | */ |
| 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); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2378 | lq_sta->active_siso_rate <<= IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2379 | |
| 2380 | /* Same here */ |
| 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); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2384 | lq_sta->active_mimo2_rate <<= IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2385 | |
| 2386 | /* These values will be overridden later */ |
| 2387 | lq_sta->lq.general_params.single_stream_ant_msk = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2388 | il4965_first_antenna(il->hw_params.valid_tx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2389 | lq_sta->lq.general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2390 | il->hw_params.valid_tx_ant & |
| 2391 | ~il4965_first_antenna(il->hw_params.valid_tx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2392 | if (!lq_sta->lq.general_params.dual_stream_ant_msk) { |
| 2393 | lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2394 | } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2395 | lq_sta->lq.general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2396 | il->hw_params.valid_tx_ant; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | /* as default allow aggregation for all tids */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2400 | lq_sta->tx_agg_tid_en = IL_AGG_ALL_TID; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2401 | lq_sta->drv = il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2402 | |
| 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) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2406 | lq_sta->last_txrate_idx += IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2407 | lq_sta->is_agg = 0; |
| 2408 | |
| 2409 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2410 | lq_sta->dbg_fixed_rate = 0; |
| 2411 | #endif |
| 2412 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2413 | il4965_rs_initialize_lq(il, conf, sta, lq_sta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2414 | } |
| 2415 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2416 | static void il4965_rs_fill_link_cmd(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2417 | struct il_lq_sta *lq_sta, u32 new_rate) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2418 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2419 | struct il_scale_tbl_info tbl_type; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2420 | int idx = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2421 | int rate_idx; |
| 2422 | int repeat_rate = 0; |
| 2423 | u8 ant_toggle_cnt = 0; |
| 2424 | u8 use_ht_possible = 1; |
| 2425 | u8 valid_tx_ant = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2426 | struct il_link_quality_cmd *lq_cmd = &lq_sta->lq; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2427 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2428 | /* Override starting rate (idx 0) if needed for debug purposes */ |
| 2429 | il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2430 | |
| 2431 | /* Interpret new_rate (rate_n_flags) */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2432 | il4965_rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2433 | &tbl_type, &rate_idx); |
| 2434 | |
| 2435 | /* How many times should we repeat the initial rate? */ |
| 2436 | if (is_legacy(tbl_type.lq_type)) { |
| 2437 | ant_toggle_cnt = 1; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2438 | repeat_rate = IL_NUMBER_TRY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2439 | } else { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2440 | repeat_rate = IL_HT_NUMBER_TRY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | lq_cmd->general_params.mimo_delimiter = |
| 2444 | is_mimo(tbl_type.lq_type) ? 1 : 0; |
| 2445 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2446 | /* Fill 1st table entry (idx 0) */ |
| 2447 | lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2448 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2449 | if (il4965_num_of_ant(tbl_type.ant_type) == 1) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2450 | lq_cmd->general_params.single_stream_ant_msk = |
| 2451 | tbl_type.ant_type; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2452 | } else if (il4965_num_of_ant(tbl_type.ant_type) == 2) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2453 | lq_cmd->general_params.dual_stream_ant_msk = |
| 2454 | tbl_type.ant_type; |
| 2455 | } /* otherwise we don't modify the existing value */ |
| 2456 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2457 | idx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2458 | repeat_rate--; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2459 | if (il) |
| 2460 | valid_tx_ant = il->hw_params.valid_tx_ant; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2461 | |
| 2462 | /* Fill rest of rate table */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2463 | while (idx < LINK_QUAL_MAX_RETRY_NUM) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2464 | /* Repeat initial/next rate. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2465 | * For legacy IL_NUMBER_TRY == 1, this loop will not execute. |
| 2466 | * For HT IL_HT_NUMBER_TRY == 3, this executes twice. */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2467 | while (repeat_rate > 0 && idx < LINK_QUAL_MAX_RETRY_NUM) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2468 | if (is_legacy(tbl_type.lq_type)) { |
| 2469 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) |
| 2470 | ant_toggle_cnt++; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2471 | else if (il && |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2472 | il4965_rs_toggle_antenna(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2473 | &new_rate, &tbl_type)) |
| 2474 | ant_toggle_cnt = 1; |
| 2475 | } |
| 2476 | |
| 2477 | /* Override next rate if needed for debug purposes */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2478 | il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2479 | |
| 2480 | /* Fill next table entry */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2481 | lq_cmd->rs_table[idx].rate_n_flags = |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2482 | cpu_to_le32(new_rate); |
| 2483 | repeat_rate--; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2484 | idx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2487 | il4965_rs_get_tbl_info_from_mcs(new_rate, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2488 | lq_sta->band, &tbl_type, |
| 2489 | &rate_idx); |
| 2490 | |
| 2491 | /* Indicate to uCode which entries might be MIMO. |
| 2492 | * If initial rate was MIMO, this will finally end up |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2493 | * as (IL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2494 | if (is_mimo(tbl_type.lq_type)) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2495 | lq_cmd->general_params.mimo_delimiter = idx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2496 | |
| 2497 | /* Get next rate */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2498 | new_rate = il4965_rs_get_lower_rate(lq_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2499 | &tbl_type, rate_idx, |
| 2500 | use_ht_possible); |
| 2501 | |
| 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) |
| 2505 | ant_toggle_cnt++; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2506 | else if (il && |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2507 | il4965_rs_toggle_antenna(valid_tx_ant, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2508 | &new_rate, &tbl_type)) |
| 2509 | ant_toggle_cnt = 1; |
| 2510 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2511 | repeat_rate = IL_NUMBER_TRY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2512 | } else { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2513 | repeat_rate = IL_HT_NUMBER_TRY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | /* Don't allow HT rates after next pass. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2517 | * il4965_rs_get_lower_rate() will change type to LQ_A or LQ_G. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2518 | use_ht_possible = 0; |
| 2519 | |
| 2520 | /* Override next rate if needed for debug purposes */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2521 | il4965_rs_dbgfs_set_mcs(lq_sta, &new_rate, idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2522 | |
| 2523 | /* Fill next table entry */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2524 | lq_cmd->rs_table[idx].rate_n_flags = cpu_to_le32(new_rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2525 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2526 | idx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2527 | repeat_rate--; |
| 2528 | } |
| 2529 | |
| 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; |
| 2532 | |
| 2533 | lq_cmd->agg_params.agg_time_limit = |
| 2534 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
| 2535 | } |
| 2536 | |
| 2537 | static void |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2538 | *il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2539 | { |
| 2540 | return hw->priv; |
| 2541 | } |
| 2542 | /* rate scale requires free function to be implemented */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2543 | static void il4965_rs_free(void *il_rate) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2544 | { |
| 2545 | return; |
| 2546 | } |
| 2547 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2548 | static void il4965_rs_free_sta(void *il_r, struct ieee80211_sta *sta, |
| 2549 | void *il_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2550 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2551 | struct il_priv *il __maybe_unused = il_r; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2552 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2553 | D_RATE("enter\n"); |
| 2554 | D_RATE("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | |
| 2558 | #ifdef CONFIG_MAC80211_DEBUGFS |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2559 | static int il4965_open_file_generic(struct inode *inode, struct file *file) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2560 | { |
| 2561 | file->private_data = inode->i_private; |
| 2562 | return 0; |
| 2563 | } |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2564 | static void il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2565 | u32 *rate_n_flags, int idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2566 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2567 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2568 | u8 valid_tx_ant; |
| 2569 | u8 ant_sel_tx; |
| 2570 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2571 | il = lq_sta->drv; |
| 2572 | valid_tx_ant = il->hw_params.valid_tx_ant; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2573 | if (lq_sta->dbg_fixed_rate) { |
| 2574 | ant_sel_tx = |
| 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; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2579 | D_RATE("Fixed rate ON\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2580 | } else { |
| 2581 | lq_sta->dbg_fixed_rate = 0; |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 2582 | IL_ERR( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2583 | "Invalid antenna selection 0x%X, Valid is 0x%X\n", |
| 2584 | ant_sel_tx, valid_tx_ant); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2585 | D_RATE("Fixed rate OFF\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2586 | } |
| 2587 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2588 | D_RATE("Fixed rate OFF\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2592 | static ssize_t il4965_rs_sta_dbgfs_scale_table_write(struct file *file, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2593 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 2594 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2595 | struct il_lq_sta *lq_sta = file->private_data; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2596 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2597 | char buf[64]; |
Stephen Boyd | 8220ba3 | 2011-05-12 16:50:04 -0700 | [diff] [blame] | 2598 | size_t buf_size; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2599 | u32 parsed_rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2603 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2604 | il = lq_sta->drv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2605 | memset(buf, 0, sizeof(buf)); |
| 2606 | buf_size = min(count, sizeof(buf) - 1); |
| 2607 | if (copy_from_user(buf, user_buf, buf_size)) |
| 2608 | return -EFAULT; |
| 2609 | |
| 2610 | if (sscanf(buf, "%x", &parsed_rate) == 1) |
| 2611 | lq_sta->dbg_fixed_rate = parsed_rate; |
| 2612 | else |
| 2613 | lq_sta->dbg_fixed_rate = 0; |
| 2614 | |
| 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 */ |
| 2618 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2619 | D_RATE("sta_id %d rate 0x%X\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2620 | lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate); |
| 2621 | |
| 2622 | if (lq_sta->dbg_fixed_rate) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2625 | false); |
| 2626 | } |
| 2627 | |
| 2628 | return count; |
| 2629 | } |
| 2630 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2631 | static ssize_t il4965_rs_sta_dbgfs_scale_table_read(struct file *file, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2632 | char __user *user_buf, size_t count, loff_t *ppos) |
| 2633 | { |
| 2634 | char *buff; |
| 2635 | int desc = 0; |
| 2636 | int i = 0; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2637 | int idx = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2638 | ssize_t ret; |
| 2639 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2640 | struct il_lq_sta *lq_sta = file->private_data; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2641 | struct il_priv *il; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2642 | struct il_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2643 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2644 | il = lq_sta->drv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2645 | buff = kmalloc(1024, GFP_KERNEL); |
| 2646 | if (!buff) |
| 2647 | return -ENOMEM; |
| 2648 | |
| 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", |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 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" : ""); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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" : ""); |
| 2670 | } |
| 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); |
| 2679 | |
| 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); |
| 2685 | |
| 2686 | desc += sprintf(buff+desc, |
| 2687 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 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]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2692 | |
| 2693 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2694 | idx = il4965_hwrate_to_plcp_idx( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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", |
| 2698 | i, |
| 2699 | le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2700 | il_rate_mcs[idx].mbps); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2701 | } else { |
| 2702 | desc += sprintf(buff+desc, |
| 2703 | " rate[%d] 0x%X %smbps (%s)\n", |
| 2704 | i, |
| 2705 | le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 2706 | il_rate_mcs[idx].mbps, il_rate_mcs[idx].mcs); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 2711 | kfree(buff); |
| 2712 | return ret; |
| 2713 | } |
| 2714 | |
| 2715 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2716 | .write = il4965_rs_sta_dbgfs_scale_table_write, |
| 2717 | .read = il4965_rs_sta_dbgfs_scale_table_read, |
| 2718 | .open = il4965_open_file_generic, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2719 | .llseek = default_llseek, |
| 2720 | }; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2721 | static ssize_t il4965_rs_sta_dbgfs_stats_table_read(struct file *file, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2722 | char __user *user_buf, size_t count, loff_t *ppos) |
| 2723 | { |
| 2724 | char *buff; |
| 2725 | int desc = 0; |
| 2726 | int i, j; |
| 2727 | ssize_t ret; |
| 2728 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2729 | struct il_lq_sta *lq_sta = file->private_data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2730 | |
| 2731 | buff = kmalloc(1024, GFP_KERNEL); |
| 2732 | if (!buff) |
| 2733 | return -ENOMEM; |
| 2734 | |
| 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" |
| 2738 | "rate=0x%X\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, |
| 2744 | lq_sta->is_green, |
| 2745 | lq_sta->lq_info[i].current_rate); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 2746 | for (j = 0; j < RATE_COUNT; j++) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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); |
| 2752 | } |
| 2753 | } |
| 2754 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 2755 | kfree(buff); |
| 2756 | return ret; |
| 2757 | } |
| 2758 | |
| 2759 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2760 | .read = il4965_rs_sta_dbgfs_stats_table_read, |
| 2761 | .open = il4965_open_file_generic, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2762 | .llseek = default_llseek, |
| 2763 | }; |
| 2764 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2765 | static ssize_t il4965_rs_sta_dbgfs_rate_scale_data_read(struct file *file, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2766 | char __user *user_buf, size_t count, loff_t *ppos) |
| 2767 | { |
| 2768 | char buff[120]; |
| 2769 | int desc = 0; |
| 2770 | ssize_t ret; |
| 2771 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2772 | struct il_lq_sta *lq_sta = file->private_data; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2773 | struct il_priv *il; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2774 | struct il_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2775 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2776 | il = lq_sta->drv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2777 | |
| 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]); |
| 2782 | else |
| 2783 | desc += sprintf(buff+desc, |
| 2784 | "Bit Rate= %d Mb/s\n", |
Stanislaw Gruszka | d2ddf621 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 2785 | il_rates[lq_sta->last_txrate_idx].ieee >> 1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2786 | |
| 2787 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 2788 | return ret; |
| 2789 | } |
| 2790 | |
| 2791 | static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2792 | .read = il4965_rs_sta_dbgfs_rate_scale_data_read, |
| 2793 | .open = il4965_open_file_generic, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2794 | .llseek = default_llseek, |
| 2795 | }; |
| 2796 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2797 | static void il4965_rs_add_debugfs(void *il, void *il_sta, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2798 | struct dentry *dir) |
| 2799 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2800 | struct il_lq_sta *lq_sta = il_sta; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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); |
| 2813 | |
| 2814 | } |
| 2815 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2816 | static void il4965_rs_remove_debugfs(void *il, void *il_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2817 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2818 | struct il_lq_sta *lq_sta = il_sta; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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); |
| 2823 | } |
| 2824 | #endif |
| 2825 | |
| 2826 | /* |
| 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. |
| 2830 | */ |
| 2831 | static void |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2832 | il4965_rs_rate_init_stub(void *il_r, struct ieee80211_supported_band *sband, |
| 2833 | struct ieee80211_sta *sta, void *il_sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2834 | { |
| 2835 | } |
| 2836 | static struct rate_control_ops rs_4965_ops = { |
| 2837 | .module = NULL, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 2838 | .name = IL4965_RS_NAME, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 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, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2846 | #ifdef CONFIG_MAC80211_DEBUGFS |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2847 | .add_sta_debugfs = il4965_rs_add_debugfs, |
| 2848 | .remove_sta_debugfs = il4965_rs_remove_debugfs, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2849 | #endif |
| 2850 | }; |
| 2851 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2852 | int il4965_rate_control_register(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2853 | { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2854 | return ieee80211_rate_control_register(&rs_4965_ops); |
| 2855 | } |
| 2856 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2857 | void il4965_rate_control_unregister(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 2858 | { |
| 2859 | ieee80211_rate_control_unregister(&rs_4965_ops); |
| 2860 | } |