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