Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2005 - 2010 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/wireless.h> |
| 31 | #include <net/mac80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/delay.h> |
| 36 | |
| 37 | #include <linux/workqueue.h> |
| 38 | |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 39 | #include "iwl-dev.h" |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 40 | #include "iwl-sta.h" |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 41 | #include "iwl-core.h" |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 42 | #include "iwl-agn.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 43 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 44 | #define RS_NAME "iwl-agn-rs" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 46 | #define NUM_TRY_BEFORE_ANT_TOGGLE 1 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 47 | #define IWL_NUMBER_TRY 1 |
| 48 | #define IWL_HT_NUMBER_TRY 3 |
| 49 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 50 | #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ |
| 51 | #define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */ |
| 52 | #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */ |
| 53 | |
Abbas, Mohamed | 7d049e5 | 2009-01-20 21:33:53 -0800 | [diff] [blame] | 54 | /* max allowed rate miss before sync LQ cmd */ |
| 55 | #define IWL_MISSED_RATE_MAX 15 |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 56 | /* max time to accum history 2 seconds */ |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 57 | #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | |
| 59 | static u8 rs_ht_to_legacy[] = { |
| 60 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, |
| 61 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, |
| 62 | IWL_RATE_6M_INDEX, |
| 63 | IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX, |
| 64 | IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX, |
| 65 | IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX, |
| 66 | IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX |
| 67 | }; |
| 68 | |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 69 | static const u8 ant_toggle_lookup[] = { |
| 70 | /*ANT_NONE -> */ ANT_NONE, |
| 71 | /*ANT_A -> */ ANT_B, |
| 72 | /*ANT_B -> */ ANT_C, |
| 73 | /*ANT_AB -> */ ANT_BC, |
| 74 | /*ANT_C -> */ ANT_A, |
| 75 | /*ANT_AC -> */ ANT_AB, |
| 76 | /*ANT_BC -> */ ANT_AC, |
| 77 | /*ANT_ABC -> */ ANT_ABC, |
| 78 | }; |
| 79 | |
Johannes Berg | 635b85b | 2010-09-22 18:02:04 +0200 | [diff] [blame] | 80 | #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ |
| 81 | [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ |
| 82 | IWL_RATE_SISO_##s##M_PLCP, \ |
| 83 | IWL_RATE_MIMO2_##s##M_PLCP,\ |
| 84 | IWL_RATE_MIMO3_##s##M_PLCP,\ |
| 85 | IWL_RATE_##r##M_IEEE, \ |
| 86 | IWL_RATE_##ip##M_INDEX, \ |
| 87 | IWL_RATE_##in##M_INDEX, \ |
| 88 | IWL_RATE_##rp##M_INDEX, \ |
| 89 | IWL_RATE_##rn##M_INDEX, \ |
| 90 | IWL_RATE_##pp##M_INDEX, \ |
| 91 | IWL_RATE_##np##M_INDEX } |
| 92 | |
| 93 | /* |
| 94 | * Parameter order: |
| 95 | * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate |
| 96 | * |
| 97 | * If there isn't a valid next or previous rate then INV is used which |
| 98 | * maps to IWL_RATE_INVALID |
| 99 | * |
| 100 | */ |
| 101 | const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { |
| 102 | IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */ |
| 103 | IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */ |
| 104 | IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */ |
| 105 | IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */ |
| 106 | IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */ |
| 107 | IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */ |
| 108 | IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */ |
| 109 | IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */ |
| 110 | IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */ |
| 111 | IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */ |
| 112 | IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */ |
| 113 | IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */ |
| 114 | IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */ |
| 115 | /* FIXME:RS: ^^ should be INV (legacy) */ |
| 116 | }; |
| 117 | |
| 118 | static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags) |
| 119 | { |
| 120 | int idx = 0; |
| 121 | |
| 122 | /* HT rate format */ |
| 123 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 124 | idx = (rate_n_flags & 0xff); |
| 125 | |
| 126 | if (idx >= IWL_RATE_MIMO3_6M_PLCP) |
| 127 | idx = idx - IWL_RATE_MIMO3_6M_PLCP; |
| 128 | else if (idx >= IWL_RATE_MIMO2_6M_PLCP) |
| 129 | idx = idx - IWL_RATE_MIMO2_6M_PLCP; |
| 130 | |
| 131 | idx += IWL_FIRST_OFDM_RATE; |
| 132 | /* skip 9M not supported in ht*/ |
| 133 | if (idx >= IWL_RATE_9M_INDEX) |
| 134 | idx += 1; |
| 135 | if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE)) |
| 136 | return idx; |
| 137 | |
| 138 | /* legacy rate format, search for match in table */ |
| 139 | } else { |
| 140 | for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) |
| 141 | if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF)) |
| 142 | return idx; |
| 143 | } |
| 144 | |
| 145 | return -1; |
| 146 | } |
| 147 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 148 | static void rs_rate_scale_perform(struct iwl_priv *priv, |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 149 | struct sk_buff *skb, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 150 | struct ieee80211_sta *sta, |
| 151 | struct iwl_lq_sta *lq_sta); |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 152 | static void rs_fill_link_cmd(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 153 | struct iwl_lq_sta *lq_sta, u32 rate_n_flags); |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 154 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 155 | |
| 156 | |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 157 | #ifdef CONFIG_MAC80211_DEBUGFS |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 158 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
| 159 | u32 *rate_n_flags, int index); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 160 | #else |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 161 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
| 162 | u32 *rate_n_flags, int index) |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 163 | {} |
| 164 | #endif |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 165 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 166 | /** |
| 167 | * The following tables contain the expected throughput metrics for all rates |
| 168 | * |
| 169 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits |
| 170 | * |
| 171 | * where invalid entries are zeros. |
| 172 | * |
| 173 | * CCK rates are only valid in legacy table and will only be used in G |
| 174 | * (2.4 GHz) band. |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 175 | */ |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 176 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 177 | static s32 expected_tpt_legacy[IWL_RATE_COUNT] = { |
| 178 | 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 181 | static s32 expected_tpt_siso20MHz[4][IWL_RATE_COUNT] = { |
| 182 | {0, 0, 0, 0, 42, 0, 76, 102, 124, 158, 183, 193, 202}, /* Norm */ |
| 183 | {0, 0, 0, 0, 46, 0, 82, 110, 132, 167, 192, 202, 210}, /* SGI */ |
| 184 | {0, 0, 0, 0, 48, 0, 93, 135, 176, 251, 319, 351, 381}, /* AGG */ |
| 185 | {0, 0, 0, 0, 53, 0, 102, 149, 193, 275, 348, 381, 413}, /* AGG+SGI */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 188 | static s32 expected_tpt_siso40MHz[4][IWL_RATE_COUNT] = { |
| 189 | {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */ |
| 190 | {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */ |
| 191 | {0, 0, 0, 0, 96, 0, 182, 259, 328, 451, 553, 598, 640}, /* AGG */ |
| 192 | {0, 0, 0, 0, 106, 0, 199, 282, 357, 487, 593, 640, 683}, /* AGG+SGI */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 195 | static s32 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = { |
| 196 | {0, 0, 0, 0, 74, 0, 123, 155, 179, 213, 235, 243, 250}, /* Norm */ |
| 197 | {0, 0, 0, 0, 81, 0, 131, 164, 187, 221, 242, 250, 256}, /* SGI */ |
| 198 | {0, 0, 0, 0, 92, 0, 175, 250, 317, 436, 534, 578, 619}, /* AGG */ |
| 199 | {0, 0, 0, 0, 102, 0, 192, 273, 344, 470, 573, 619, 660}, /* AGG+SGI*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 202 | static s32 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = { |
| 203 | {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */ |
| 204 | {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */ |
| 205 | {0, 0, 0, 0, 180, 0, 327, 446, 545, 708, 828, 878, 922}, /* AGG */ |
| 206 | {0, 0, 0, 0, 197, 0, 355, 481, 584, 752, 872, 922, 966}, /* AGG+SGI */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 209 | static s32 expected_tpt_mimo3_20MHz[4][IWL_RATE_COUNT] = { |
| 210 | {0, 0, 0, 0, 99, 0, 153, 186, 208, 239, 256, 263, 268}, /* Norm */ |
| 211 | {0, 0, 0, 0, 106, 0, 162, 194, 215, 246, 262, 268, 273}, /* SGI */ |
| 212 | {0, 0, 0, 0, 134, 0, 249, 346, 431, 574, 685, 732, 775}, /* AGG */ |
| 213 | {0, 0, 0, 0, 148, 0, 272, 376, 465, 614, 727, 775, 818}, /* AGG+SGI */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 216 | static s32 expected_tpt_mimo3_40MHz[4][IWL_RATE_COUNT] = { |
| 217 | {0, 0, 0, 0, 152, 0, 211, 239, 255, 279, 290, 294, 297}, /* Norm */ |
| 218 | {0, 0, 0, 0, 160, 0, 219, 245, 261, 284, 294, 297, 300}, /* SGI */ |
| 219 | {0, 0, 0, 0, 254, 0, 443, 584, 695, 868, 984, 1030, 1070}, /* AGG */ |
| 220 | {0, 0, 0, 0, 277, 0, 478, 624, 737, 911, 1026, 1070, 1109}, /* AGG+SGI */ |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
Wey-Yi Guy | 12b9681 | 2009-04-08 11:39:27 -0700 | [diff] [blame] | 223 | /* mbps, mcs */ |
Tobias Klauser | 7949673 | 2009-12-23 14:18:11 +0100 | [diff] [blame] | 224 | static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = { |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 225 | { "1", "BPSK DSSS"}, |
| 226 | { "2", "QPSK DSSS"}, |
| 227 | {"5.5", "BPSK CCK"}, |
| 228 | { "11", "QPSK CCK"}, |
| 229 | { "6", "BPSK 1/2"}, |
| 230 | { "9", "BPSK 1/2"}, |
| 231 | { "12", "QPSK 1/2"}, |
| 232 | { "18", "QPSK 3/4"}, |
| 233 | { "24", "16QAM 1/2"}, |
| 234 | { "36", "16QAM 3/4"}, |
| 235 | { "48", "64QAM 2/3"}, |
| 236 | { "54", "64QAM 3/4"}, |
| 237 | { "60", "64QAM 5/6"}, |
Wey-Yi Guy | 12b9681 | 2009-04-08 11:39:27 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 240 | #define MCS_INDEX_PER_STREAM (8) |
| 241 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 242 | static inline u8 rs_extract_rate(u32 rate_n_flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 243 | { |
| 244 | return (u8)(rate_n_flags & 0xFF); |
| 245 | } |
| 246 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 247 | static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 248 | { |
| 249 | window->data = 0; |
| 250 | window->success_counter = 0; |
| 251 | window->success_ratio = IWL_INVALID_VALUE; |
| 252 | window->counter = 0; |
| 253 | window->average_tpt = IWL_INVALID_VALUE; |
| 254 | window->stamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 257 | static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type) |
| 258 | { |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 259 | return (ant_type & valid_antenna) == ant_type; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 262 | /* |
| 263 | * removes the old data from the statistics. All data that is older than |
| 264 | * TID_MAX_TIME_DIFF, will be deleted. |
| 265 | */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 266 | static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time) |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 267 | { |
| 268 | /* The oldest age we want to keep */ |
| 269 | u32 oldest_time = curr_time - TID_MAX_TIME_DIFF; |
| 270 | |
| 271 | while (tl->queue_count && |
| 272 | (tl->time_stamp < oldest_time)) { |
| 273 | tl->total -= tl->packet_count[tl->head]; |
| 274 | tl->packet_count[tl->head] = 0; |
| 275 | tl->time_stamp += TID_QUEUE_CELL_SPACING; |
| 276 | tl->queue_count--; |
| 277 | tl->head++; |
| 278 | if (tl->head >= TID_QUEUE_MAX_SIZE) |
| 279 | tl->head = 0; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * increment traffic load value for tid and also remove |
| 285 | * any old values if passed the certain time period |
| 286 | */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 287 | static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data, |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 288 | struct ieee80211_hdr *hdr) |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 289 | { |
| 290 | u32 curr_time = jiffies_to_msecs(jiffies); |
| 291 | u32 time_diff; |
| 292 | s32 index; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 293 | struct iwl_traffic_load *tl = NULL; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 294 | u8 tid; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 295 | |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 296 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 297 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 298 | tid = qc[0] & 0xf; |
| 299 | } else |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 300 | return MAX_TID_COUNT; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 301 | |
Reinette Chatre | e6a6cf4 | 2009-08-13 13:30:50 -0700 | [diff] [blame] | 302 | if (unlikely(tid >= TID_MAX_LOAD_COUNT)) |
| 303 | return MAX_TID_COUNT; |
| 304 | |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 305 | tl = &lq_data->load[tid]; |
| 306 | |
| 307 | curr_time -= curr_time % TID_ROUND_VALUE; |
| 308 | |
| 309 | /* Happens only for the first packet. Initialize the data */ |
| 310 | if (!(tl->queue_count)) { |
| 311 | tl->total = 1; |
| 312 | tl->time_stamp = curr_time; |
| 313 | tl->queue_count = 1; |
| 314 | tl->head = 0; |
| 315 | tl->packet_count[0] = 1; |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 316 | return MAX_TID_COUNT; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); |
| 320 | index = time_diff / TID_QUEUE_CELL_SPACING; |
| 321 | |
| 322 | /* The history is too long: remove data that is older than */ |
| 323 | /* TID_MAX_TIME_DIFF */ |
| 324 | if (index >= TID_QUEUE_MAX_SIZE) |
| 325 | rs_tl_rm_old_stats(tl, curr_time); |
| 326 | |
| 327 | index = (tl->head + index) % TID_QUEUE_MAX_SIZE; |
| 328 | tl->packet_count[index] = tl->packet_count[index] + 1; |
| 329 | tl->total = tl->total + 1; |
| 330 | |
| 331 | if ((index + 1) > tl->queue_count) |
| 332 | tl->queue_count = index + 1; |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 333 | |
| 334 | return tid; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* |
| 338 | get the traffic load value for tid |
| 339 | */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 340 | static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid) |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 341 | { |
| 342 | u32 curr_time = jiffies_to_msecs(jiffies); |
| 343 | u32 time_diff; |
| 344 | s32 index; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 345 | struct iwl_traffic_load *tl = NULL; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 346 | |
| 347 | if (tid >= TID_MAX_LOAD_COUNT) |
| 348 | return 0; |
| 349 | |
| 350 | tl = &(lq_data->load[tid]); |
| 351 | |
| 352 | curr_time -= curr_time % TID_ROUND_VALUE; |
| 353 | |
| 354 | if (!(tl->queue_count)) |
| 355 | return 0; |
| 356 | |
| 357 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); |
| 358 | index = time_diff / TID_QUEUE_CELL_SPACING; |
| 359 | |
| 360 | /* The history is too long: remove data that is older than */ |
| 361 | /* TID_MAX_TIME_DIFF */ |
| 362 | if (index >= TID_QUEUE_MAX_SIZE) |
| 363 | rs_tl_rm_old_stats(tl, curr_time); |
| 364 | |
| 365 | return tl->total; |
| 366 | } |
| 367 | |
Wey-Yi Guy | 82ca934 | 2010-04-12 14:02:36 -0700 | [diff] [blame] | 368 | static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 369 | struct iwl_lq_sta *lq_data, u8 tid, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 370 | struct ieee80211_sta *sta) |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 371 | { |
Wey-Yi Guy | 82ca934 | 2010-04-12 14:02:36 -0700 | [diff] [blame] | 372 | int ret = -EAGAIN; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 373 | u32 load; |
| 374 | |
| 375 | /* |
| 376 | * Don't create TX aggregation sessions when in high |
| 377 | * BT traffic, as they would just be disrupted by BT. |
| 378 | */ |
| 379 | if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) { |
| 380 | IWL_ERR(priv, "BT traffic (%d), no aggregation allowed\n", |
| 381 | priv->bt_traffic_load); |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | load = rs_tl_get_load(lq_data, tid); |
Wey-Yi Guy | 45d4270 | 2010-02-03 12:24:44 -0800 | [diff] [blame] | 386 | |
Andy Lutomirski | 2411054 | 2010-07-25 13:14:29 -0400 | [diff] [blame] | 387 | if (load > IWL_AGG_LOAD_THRESHOLD) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 388 | IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 389 | sta->addr, tid); |
Wey-Yi Guy | 45d4270 | 2010-02-03 12:24:44 -0800 | [diff] [blame] | 390 | ret = ieee80211_start_tx_ba_session(sta, tid); |
| 391 | if (ret == -EAGAIN) { |
| 392 | /* |
| 393 | * driver and mac80211 is out of sync |
| 394 | * this might be cause by reloading firmware |
| 395 | * stop the tx ba session here |
| 396 | */ |
Andy Lutomirski | 2411054 | 2010-07-25 13:14:29 -0400 | [diff] [blame] | 397 | IWL_ERR(priv, "Fail start Tx agg on tid: %d\n", |
Wey-Yi Guy | 45d4270 | 2010-02-03 12:24:44 -0800 | [diff] [blame] | 398 | tid); |
Johannes Berg | 6a8579d | 2010-05-27 14:41:07 +0200 | [diff] [blame] | 399 | ieee80211_stop_tx_ba_session(sta, tid); |
Wey-Yi Guy | 45d4270 | 2010-02-03 12:24:44 -0800 | [diff] [blame] | 400 | } |
Andy Lutomirski | 2411054 | 2010-07-25 13:14:29 -0400 | [diff] [blame] | 401 | } else { |
| 402 | IWL_ERR(priv, "Aggregation not enabled for tid %d " |
| 403 | "because load = %u\n", tid, load); |
| 404 | } |
Wey-Yi Guy | 82ca934 | 2010-04-12 14:02:36 -0700 | [diff] [blame] | 405 | return ret; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 408 | static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 409 | struct iwl_lq_sta *lq_data, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 410 | struct ieee80211_sta *sta) |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 411 | { |
Wey-Yi Guy | cfecc6b | 2010-06-18 11:33:15 -0700 | [diff] [blame] | 412 | if (tid < TID_MAX_LOAD_COUNT) |
| 413 | rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); |
| 414 | else |
| 415 | IWL_ERR(priv, "tid exceeds max load count: %d/%d\n", |
| 416 | tid, TID_MAX_LOAD_COUNT); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 419 | static inline int get_num_of_ant_from_rate(u32 rate_n_flags) |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 420 | { |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 421 | return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) + |
| 422 | !!(rate_n_flags & RATE_MCS_ANT_B_MSK) + |
| 423 | !!(rate_n_flags & RATE_MCS_ANT_C_MSK); |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 426 | /* |
| 427 | * Static function to get the expected throughput from an iwl_scale_tbl_info |
| 428 | * that wraps a NULL pointer check |
| 429 | */ |
| 430 | static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index) |
| 431 | { |
| 432 | if (tbl->expected_tpt) |
| 433 | return tbl->expected_tpt[rs_index]; |
| 434 | return 0; |
| 435 | } |
| 436 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 437 | /** |
| 438 | * rs_collect_tx_data - Update the success/failure sliding window |
| 439 | * |
| 440 | * We keep a sliding window of the last 62 packets transmitted |
| 441 | * at this rate. window->data contains the bitmask of successful |
| 442 | * packets. |
| 443 | */ |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 444 | static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl, |
| 445 | int scale_index, int attempts, int successes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 447 | struct iwl_rate_scale_data *window = NULL; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 448 | static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1)); |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 449 | s32 fail_count, tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 450 | |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 451 | if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) |
| 452 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 453 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 454 | /* Select window for current tx bit rate */ |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 455 | window = &(tbl->win[scale_index]); |
| 456 | |
| 457 | /* Get expected throughput */ |
| 458 | tpt = get_expected_tpt(tbl, scale_index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 459 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 460 | /* |
| 461 | * Keep track of only the latest 62 tx frame attempts in this rate's |
| 462 | * history window; anything older isn't really relevant any more. |
| 463 | * If we have filled up the sliding window, drop the oldest attempt; |
| 464 | * if the oldest attempt (highest bit in bitmap) shows "success", |
| 465 | * subtract "1" from the success counter (this is the main reason |
| 466 | * we keep these bitmaps!). |
| 467 | */ |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 468 | while (attempts > 0) { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 469 | if (window->counter >= IWL_RATE_MAX_WINDOW) { |
| 470 | |
| 471 | /* remove earliest */ |
| 472 | window->counter = IWL_RATE_MAX_WINDOW - 1; |
| 473 | |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 474 | if (window->data & mask) { |
| 475 | window->data &= ~mask; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 476 | window->success_counter--; |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 477 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 478 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 480 | /* Increment frames-attempted counter */ |
| 481 | window->counter++; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 482 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 483 | /* Shift bitmap by one frame to throw away oldest history */ |
Guy Cohen | 90d7795 | 2008-09-09 10:54:53 +0800 | [diff] [blame] | 484 | window->data <<= 1; |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 485 | |
| 486 | /* Mark the most recent #successes attempts as successful */ |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 487 | if (successes > 0) { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 488 | window->success_counter++; |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 489 | window->data |= 0x1; |
| 490 | successes--; |
| 491 | } |
| 492 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 493 | attempts--; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 496 | /* Calculate current success ratio, avoid divide-by-0! */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 497 | if (window->counter > 0) |
| 498 | window->success_ratio = 128 * (100 * window->success_counter) |
| 499 | / window->counter; |
| 500 | else |
| 501 | window->success_ratio = IWL_INVALID_VALUE; |
| 502 | |
| 503 | fail_count = window->counter - window->success_counter; |
| 504 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 505 | /* Calculate average throughput, if we have enough history. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 506 | if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || |
| 507 | (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) |
| 508 | window->average_tpt = (window->success_ratio * tpt + 64) / 128; |
| 509 | else |
| 510 | window->average_tpt = IWL_INVALID_VALUE; |
| 511 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 512 | /* Tag this window as having been updated */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 513 | window->stamp = jiffies; |
| 514 | |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 515 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 518 | /* |
| 519 | * Fill uCode API rate_n_flags field, based on "search" or "active" table. |
| 520 | */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 521 | /* FIXME:RS:remove this function and put the flags statically in the table */ |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 522 | static u32 rate_n_flags_from_tbl(struct iwl_priv *priv, |
| 523 | struct iwl_scale_tbl_info *tbl, |
| 524 | int index, u8 use_green) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 525 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 526 | u32 rate_n_flags = 0; |
| 527 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 528 | if (is_legacy(tbl->lq_type)) { |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 529 | rate_n_flags = iwl_rates[index].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 531 | rate_n_flags |= RATE_MCS_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 532 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 533 | } else if (is_Ht(tbl->lq_type)) { |
| 534 | if (index > IWL_LAST_OFDM_RATE) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 535 | IWL_ERR(priv, "Invalid HT rate index %d\n", index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 536 | index = IWL_LAST_OFDM_RATE; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 537 | } |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 538 | rate_n_flags = RATE_MCS_HT_MSK; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 539 | |
| 540 | if (is_siso(tbl->lq_type)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 541 | rate_n_flags |= iwl_rates[index].plcp_siso; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 542 | else if (is_mimo2(tbl->lq_type)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 543 | rate_n_flags |= iwl_rates[index].plcp_mimo2; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 544 | else |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 545 | rate_n_flags |= iwl_rates[index].plcp_mimo3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | } else { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 547 | IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 550 | rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) & |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 551 | RATE_MCS_ANT_ABC_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 552 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 553 | if (is_Ht(tbl->lq_type)) { |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 554 | if (tbl->is_ht40) { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 555 | if (tbl->is_dup) |
| 556 | rate_n_flags |= RATE_MCS_DUP_MSK; |
| 557 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 558 | rate_n_flags |= RATE_MCS_HT40_MSK; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 559 | } |
| 560 | if (tbl->is_SGI) |
| 561 | rate_n_flags |= RATE_MCS_SGI_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 562 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 563 | if (use_green) { |
| 564 | rate_n_flags |= RATE_MCS_GF_MSK; |
| 565 | if (is_siso(tbl->lq_type) && tbl->is_SGI) { |
| 566 | rate_n_flags &= ~RATE_MCS_SGI_MSK; |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 567 | IWL_ERR(priv, "GF was set with SGI:SISO\n"); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 570 | } |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 571 | return rate_n_flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 574 | /* |
| 575 | * Interpret uCode API's rate_n_flags format, |
| 576 | * fill "search" or "active" tx mode table. |
| 577 | */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 578 | static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 579 | enum ieee80211_band band, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 580 | struct iwl_scale_tbl_info *tbl, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 581 | int *rate_idx) |
| 582 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 583 | u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK); |
| 584 | u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags); |
| 585 | u8 mcs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 586 | |
Wey-Yi Guy | 80e9158 | 2010-08-03 08:23:32 -0700 | [diff] [blame] | 587 | memset(tbl, 0, sizeof(struct iwl_scale_tbl_info)); |
Tomas Winkler | e7d326ac | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 588 | *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 589 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 590 | if (*rate_idx == IWL_RATE_INVALID) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | *rate_idx = -1; |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 592 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 593 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 594 | tbl->is_SGI = 0; /* default legacy setup */ |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 595 | tbl->is_ht40 = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 596 | tbl->is_dup = 0; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 597 | tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); |
| 598 | tbl->lq_type = LQ_NONE; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 599 | tbl->max_search = IWL_MAX_SEARCH; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 601 | /* legacy rate format */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 602 | if (!(rate_n_flags & RATE_MCS_HT_MSK)) { |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 603 | if (num_of_ant == 1) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 604 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 605 | tbl->lq_type = LQ_A; |
| 606 | else |
| 607 | tbl->lq_type = LQ_G; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 608 | } |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 609 | /* HT rate format */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | } else { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 611 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 612 | tbl->is_SGI = 1; |
| 613 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 614 | if ((rate_n_flags & RATE_MCS_HT40_MSK) || |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 615 | (rate_n_flags & RATE_MCS_DUP_MSK)) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 616 | tbl->is_ht40 = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 617 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 618 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 619 | tbl->is_dup = 1; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 620 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 621 | mcs = rs_extract_rate(rate_n_flags); |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 622 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 623 | /* SISO */ |
| 624 | if (mcs <= IWL_RATE_SISO_60M_PLCP) { |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 625 | if (num_of_ant == 1) |
| 626 | tbl->lq_type = LQ_SISO; /*else NONE*/ |
| 627 | /* MIMO2 */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 628 | } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) { |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 629 | if (num_of_ant == 2) |
| 630 | tbl->lq_type = LQ_MIMO2; |
| 631 | /* MIMO3 */ |
| 632 | } else { |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 633 | if (num_of_ant == 3) { |
| 634 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 635 | tbl->lq_type = LQ_MIMO3; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 636 | } |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 637 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | } |
| 639 | return 0; |
| 640 | } |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 641 | |
| 642 | /* switch to another antenna/antennas and return 1 */ |
| 643 | /* if no other valid antenna found, return 0 */ |
| 644 | static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 645 | struct iwl_scale_tbl_info *tbl) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 646 | { |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 647 | u8 new_ant_type; |
| 648 | |
| 649 | if (!tbl->ant_type || tbl->ant_type > ANT_ABC) |
| 650 | return 0; |
| 651 | |
| 652 | if (!rs_is_valid_ant(valid_ant, tbl->ant_type)) |
| 653 | return 0; |
| 654 | |
| 655 | new_ant_type = ant_toggle_lookup[tbl->ant_type]; |
| 656 | |
| 657 | while ((new_ant_type != tbl->ant_type) && |
| 658 | !rs_is_valid_ant(valid_ant, new_ant_type)) |
| 659 | new_ant_type = ant_toggle_lookup[new_ant_type]; |
| 660 | |
| 661 | if (new_ant_type == tbl->ant_type) |
| 662 | return 0; |
| 663 | |
| 664 | tbl->ant_type = new_ant_type; |
| 665 | *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK; |
| 666 | *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS; |
| 667 | return 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Daniel C Halperin | b261793 | 2009-08-13 13:30:59 -0700 | [diff] [blame] | 670 | /** |
| 671 | * Green-field mode is valid if the station supports it and |
| 672 | * there are no non-GF stations present in the BSS. |
| 673 | */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 674 | static bool rs_use_green(struct ieee80211_sta *sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 675 | { |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 676 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 677 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
| 678 | |
Daniel C Halperin | b261793 | 2009-08-13 13:30:59 -0700 | [diff] [blame] | 679 | return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 680 | !(ctx->ht.non_gf_sta_present); |
Guy Cohen | f935a6d | 2008-04-23 17:15:02 -0700 | [diff] [blame] | 681 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 682 | |
| 683 | /** |
| 684 | * rs_get_supported_rates - get the available rates |
| 685 | * |
| 686 | * if management frame or broadcast frame only return |
| 687 | * basic available rates. |
| 688 | * |
| 689 | */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 690 | static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, |
| 691 | struct ieee80211_hdr *hdr, |
| 692 | enum iwl_table_type rate_type) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 693 | { |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 694 | if (is_legacy(rate_type)) { |
| 695 | return lq_sta->active_legacy_rate; |
| 696 | } else { |
| 697 | if (is_siso(rate_type)) |
| 698 | return lq_sta->active_siso_rate; |
| 699 | else if (is_mimo2(rate_type)) |
| 700 | return lq_sta->active_mimo2_rate; |
| 701 | else |
| 702 | return lq_sta->active_mimo3_rate; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 703 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 706 | static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask, |
| 707 | int rate_type) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 708 | { |
| 709 | u8 high = IWL_RATE_INVALID; |
| 710 | u8 low = IWL_RATE_INVALID; |
| 711 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 712 | /* 802.11A or ht walks to the next literal adjacent rate in |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 713 | * the rate table */ |
| 714 | if (is_a_band(rate_type) || !is_legacy(rate_type)) { |
| 715 | int i; |
| 716 | u32 mask; |
| 717 | |
| 718 | /* Find the previous rate that is in the rate mask */ |
| 719 | i = index - 1; |
| 720 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 721 | if (rate_mask & mask) { |
| 722 | low = i; |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | /* Find the next rate that is in the rate mask */ |
| 728 | i = index + 1; |
| 729 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { |
| 730 | if (rate_mask & mask) { |
| 731 | high = i; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | return (high << 8) | low; |
| 737 | } |
| 738 | |
| 739 | low = index; |
| 740 | while (low != IWL_RATE_INVALID) { |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 741 | low = iwl_rates[low].prev_rs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 742 | if (low == IWL_RATE_INVALID) |
| 743 | break; |
| 744 | if (rate_mask & (1 << low)) |
| 745 | break; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 746 | IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | high = index; |
| 750 | while (high != IWL_RATE_INVALID) { |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 751 | high = iwl_rates[high].next_rs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 752 | if (high == IWL_RATE_INVALID) |
| 753 | break; |
| 754 | if (rate_mask & (1 << high)) |
| 755 | break; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 756 | IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | return (high << 8) | low; |
| 760 | } |
| 761 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 762 | static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta, |
| 763 | struct iwl_scale_tbl_info *tbl, |
| 764 | u8 scale_index, u8 ht_possible) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 765 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 766 | s32 low; |
| 767 | u16 rate_mask; |
| 768 | u16 high_low; |
| 769 | u8 switch_to_legacy = 0; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 770 | u8 is_green = lq_sta->is_green; |
Wey-Yi Guy | 2ff6578 | 2009-09-11 10:38:18 -0700 | [diff] [blame] | 771 | struct iwl_priv *priv = lq_sta->drv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 772 | |
| 773 | /* check if we need to switch from HT to legacy rates. |
| 774 | * assumption is that mandatory rates (1Mbps or 6Mbps) |
| 775 | * are always supported (spec demand) */ |
| 776 | if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) { |
| 777 | switch_to_legacy = 1; |
| 778 | scale_index = rs_ht_to_legacy[scale_index]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 779 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | tbl->lq_type = LQ_A; |
| 781 | else |
| 782 | tbl->lq_type = LQ_G; |
| 783 | |
Guy Cohen | 69fdb30 | 2008-04-23 17:15:01 -0700 | [diff] [blame] | 784 | if (num_of_ant(tbl->ant_type) > 1) |
Wey-Yi Guy | 2ff6578 | 2009-09-11 10:38:18 -0700 | [diff] [blame] | 785 | tbl->ant_type = |
| 786 | first_antenna(priv->hw_params.valid_tx_ant); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 787 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 788 | tbl->is_ht40 = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 789 | tbl->is_SGI = 0; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 790 | tbl->max_search = IWL_MAX_SEARCH; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 793 | rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 794 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 795 | /* Mask with station rate restriction */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 796 | if (is_legacy(tbl->lq_type)) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 797 | /* supp_rates has no CCK bits in A mode */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 798 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | rate_mask = (u16)(rate_mask & |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 800 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 801 | else |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 802 | rate_mask = (u16)(rate_mask & lq_sta->supp_rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 805 | /* If we switched from HT to legacy, check current rate */ |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 806 | if (switch_to_legacy && (rate_mask & (1 << scale_index))) { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 807 | low = scale_index; |
| 808 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 811 | high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask, |
| 812 | tbl->lq_type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 813 | low = high_low & 0xff; |
| 814 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 815 | if (low == IWL_RATE_INVALID) |
| 816 | low = scale_index; |
| 817 | |
| 818 | out: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 819 | return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 822 | /* |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 823 | * Simple function to compare two rate scale table types |
| 824 | */ |
| 825 | static bool table_type_matches(struct iwl_scale_tbl_info *a, |
| 826 | struct iwl_scale_tbl_info *b) |
| 827 | { |
| 828 | return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) && |
| 829 | (a->is_SGI == b->is_SGI); |
| 830 | } |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 831 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 832 | static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 833 | struct iwl_lq_sta *lq_sta) |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 834 | { |
| 835 | struct iwl_scale_tbl_info *tbl; |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame^] | 836 | bool full_concurrent = priv->bt_full_concurrent; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 837 | unsigned long flags; |
| 838 | |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame^] | 839 | if (priv->bt_ant_couple_ok) { |
| 840 | /* |
| 841 | * Is there a need to switch between |
| 842 | * full concurrency and 3-wire? |
| 843 | */ |
| 844 | spin_lock_irqsave(&priv->lock, flags); |
| 845 | if (priv->bt_ci_compliance && priv->bt_ant_couple_ok) |
| 846 | full_concurrent = true; |
| 847 | else |
| 848 | full_concurrent = false; |
| 849 | spin_unlock_irqrestore(&priv->lock, flags); |
| 850 | } |
| 851 | if ((priv->bt_traffic_load != priv->last_bt_traffic_load) || |
| 852 | (priv->bt_full_concurrent != full_concurrent)) { |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 853 | priv->bt_full_concurrent = full_concurrent; |
| 854 | |
| 855 | /* Update uCode's rate table. */ |
| 856 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 857 | rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 858 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 859 | |
| 860 | queue_work(priv->workqueue, &priv->bt_full_concurrency); |
| 861 | } |
| 862 | } |
| 863 | |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 864 | /* |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 865 | * mac80211 sends us Tx status |
| 866 | */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 867 | static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband, |
| 868 | struct ieee80211_sta *sta, void *priv_sta, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 869 | struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 870 | { |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 871 | int legacy_success; |
| 872 | int retries; |
| 873 | int rs_index, mac_index, i; |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 874 | struct iwl_lq_sta *lq_sta = priv_sta; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 875 | struct iwl_link_quality_cmd *table; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 877 | struct iwl_priv *priv = (struct iwl_priv *)priv_r; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 878 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 879 | enum mac80211_rate_control_flags mac_flags; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 880 | u32 tx_rate; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 881 | struct iwl_scale_tbl_info tbl_type; |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 882 | struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 883 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 884 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 885 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 886 | IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 887 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 888 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 889 | if (!lq_sta) { |
| 890 | IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n"); |
| 891 | return; |
| 892 | } else if (!lq_sta->drv) { |
| 893 | IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); |
| 894 | return; |
| 895 | } |
| 896 | |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 897 | if (!ieee80211_is_data(hdr->frame_control) || |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 898 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 899 | return; |
| 900 | |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 901 | /* This packet was aggregated but doesn't carry status info */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 902 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && |
| 903 | !(info->flags & IEEE80211_TX_STAT_AMPDU)) |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 904 | return; |
| 905 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 906 | /* |
| 907 | * Ignore this Tx frame response if its initial rate doesn't match |
| 908 | * that of latest Link Quality command. There may be stragglers |
| 909 | * from a previous Link Quality command, but we're no longer interested |
| 910 | * in those; they're either from the "active" mode while we're trying |
| 911 | * to check "search" mode, or a prior "search" mode after we've moved |
| 912 | * to a new "search" mode (which might become the new "active" mode). |
| 913 | */ |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 914 | table = &lq_sta->lq; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 915 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); |
| 916 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 917 | if (priv->band == IEEE80211_BAND_5GHZ) |
| 918 | rs_index -= IWL_FIRST_OFDM_RATE; |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 919 | mac_flags = info->status.rates[0].flags; |
| 920 | mac_index = info->status.rates[0].idx; |
Daniel C Halperin | 31513be | 2009-08-28 09:44:47 -0700 | [diff] [blame] | 921 | /* For HT packets, map MCS to PLCP */ |
| 922 | if (mac_flags & IEEE80211_TX_RC_MCS) { |
| 923 | mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */ |
| 924 | if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE)) |
| 925 | mac_index++; |
Daniel C Halperin | 392a0ba | 2009-09-11 10:38:08 -0700 | [diff] [blame] | 926 | /* |
| 927 | * mac80211 HT index is always zero-indexed; we need to move |
| 928 | * HT OFDM rates after CCK rates in 2.4 GHz band |
| 929 | */ |
| 930 | if (priv->band == IEEE80211_BAND_2GHZ) |
| 931 | mac_index += IWL_FIRST_OFDM_RATE; |
Daniel C Halperin | 31513be | 2009-08-28 09:44:47 -0700 | [diff] [blame] | 932 | } |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 933 | /* Here we actually compare this rate to the latest LQ command */ |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 934 | if ((mac_index < 0) || |
| 935 | (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) || |
| 936 | (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) || |
| 937 | (tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) || |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 938 | (tbl_type.ant_type != info->antenna_sel_tx) || |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 939 | (!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) || |
| 940 | (!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) || |
Daniel C Halperin | 31513be | 2009-08-28 09:44:47 -0700 | [diff] [blame] | 941 | (rs_index != mac_index)) { |
| 942 | IWL_DEBUG_RATE(priv, "initial rate %d does not match %d (0x%x)\n", mac_index, rs_index, tx_rate); |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 943 | /* |
| 944 | * Since rates mis-match, the last LQ command may have failed. |
| 945 | * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with |
| 946 | * ... driver. |
Mohamed Abbas | d5e4903 | 2008-12-12 08:22:15 -0800 | [diff] [blame] | 947 | */ |
Abbas, Mohamed | 7d049e5 | 2009-01-20 21:33:53 -0800 | [diff] [blame] | 948 | lq_sta->missed_rate_counter++; |
| 949 | if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { |
| 950 | lq_sta->missed_rate_counter = 0; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 951 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); |
Abbas, Mohamed | 7d049e5 | 2009-01-20 21:33:53 -0800 | [diff] [blame] | 952 | } |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 953 | /* Regardless, ignore this status info for outdated rate */ |
| 954 | return; |
| 955 | } else |
| 956 | /* Rate did match, so reset the missed_rate_counter */ |
| 957 | lq_sta->missed_rate_counter = 0; |
| 958 | |
| 959 | /* Figure out if rate scale algorithm is in active or search table */ |
| 960 | if (table_type_matches(&tbl_type, |
| 961 | &(lq_sta->lq_info[lq_sta->active_tbl]))) { |
| 962 | curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 963 | other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
| 964 | } else if (table_type_matches(&tbl_type, |
| 965 | &lq_sta->lq_info[1 - lq_sta->active_tbl])) { |
| 966 | curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
| 967 | other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 968 | } else { |
| 969 | IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n"); |
Wey-Yi Guy | 80e9158 | 2010-08-03 08:23:32 -0700 | [diff] [blame] | 970 | tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 971 | IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n", |
| 972 | tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI); |
| 973 | tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
| 974 | IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n", |
| 975 | tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI); |
| 976 | IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n", |
| 977 | tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI); |
| 978 | /* |
| 979 | * no matching table found, let's by-pass the data collection |
| 980 | * and continue to perform rate scale to find the rate table |
| 981 | */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 982 | rs_stay_in_table(lq_sta, true); |
Wey-Yi Guy | 80e9158 | 2010-08-03 08:23:32 -0700 | [diff] [blame] | 983 | goto done; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 984 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 985 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 986 | /* |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 987 | * Updating the frame history depends on whether packets were |
| 988 | * aggregated. |
| 989 | * |
| 990 | * For aggregation, all packets were transmitted at the same rate, the |
| 991 | * first index into rate scale table. |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 992 | */ |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 993 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
| 994 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); |
| 995 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, |
| 996 | &rs_index); |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 997 | rs_collect_tx_data(curr_tbl, rs_index, |
Daniel Halperin | e3a3cd8 | 2010-04-18 09:27:58 -0700 | [diff] [blame] | 998 | info->status.ampdu_len, |
| 999 | info->status.ampdu_ack_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1000 | |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1001 | /* Update success/fail counts if not searching for new mode */ |
| 1002 | if (lq_sta->stay_in_tbl) { |
Daniel Halperin | e3a3cd8 | 2010-04-18 09:27:58 -0700 | [diff] [blame] | 1003 | lq_sta->total_success += info->status.ampdu_ack_len; |
| 1004 | lq_sta->total_failed += (info->status.ampdu_len - |
| 1005 | info->status.ampdu_ack_len); |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } else { |
| 1008 | /* |
| 1009 | * For legacy, update frame history with for each Tx retry. |
| 1010 | */ |
| 1011 | retries = info->status.rates[0].count - 1; |
| 1012 | /* HW doesn't send more than 15 retries */ |
| 1013 | retries = min(retries, 15); |
| 1014 | |
| 1015 | /* The last transmission may have been successful */ |
| 1016 | legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK); |
| 1017 | /* Collect data for each rate used during failed TX attempts */ |
| 1018 | for (i = 0; i <= retries; ++i) { |
| 1019 | tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags); |
| 1020 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, |
| 1021 | &tbl_type, &rs_index); |
| 1022 | /* |
| 1023 | * Only collect stats if retried rate is in the same RS |
| 1024 | * table as active/search. |
| 1025 | */ |
| 1026 | if (table_type_matches(&tbl_type, curr_tbl)) |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 1027 | tmp_tbl = curr_tbl; |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1028 | else if (table_type_matches(&tbl_type, other_tbl)) |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 1029 | tmp_tbl = other_tbl; |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 1030 | else |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1031 | continue; |
Shanyu Zhao | 04f2dec | 2010-03-19 13:34:45 -0700 | [diff] [blame] | 1032 | rs_collect_tx_data(tmp_tbl, rs_index, 1, |
| 1033 | i < retries ? 0 : legacy_success); |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* Update success/fail counts if not searching for new mode */ |
| 1037 | if (lq_sta->stay_in_tbl) { |
| 1038 | lq_sta->total_success += legacy_success; |
| 1039 | lq_sta->total_failed += retries + (1 - legacy_success); |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 1040 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1041 | } |
Daniel C Halperin | 95407aa | 2009-09-17 10:43:48 -0700 | [diff] [blame] | 1042 | /* The last TX rate is cached in lq_sta; it's set in if/else above */ |
| 1043 | lq_sta->last_rate_n_flags = tx_rate; |
Wey-Yi Guy | 80e9158 | 2010-08-03 08:23:32 -0700 | [diff] [blame] | 1044 | done: |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1045 | /* See if there's a better rate or modulation mode to try. */ |
Abbas, Mohamed | c338ba3 | 2009-01-21 10:58:02 -0800 | [diff] [blame] | 1046 | if (sta && sta->supp_rates[sband->band]) |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 1047 | rs_rate_scale_perform(priv, skb, sta, lq_sta); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1048 | |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame^] | 1049 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1050 | rs_bt_update_lq(priv, ctx, lq_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1053 | /* |
| 1054 | * Begin a period of staying with a selected modulation mode. |
| 1055 | * Set "stay_in_tbl" flag to prevent any mode switches. |
| 1056 | * Set frame tx success limits according to legacy vs. high-throughput, |
| 1057 | * and reset overall (spanning all rates) tx success history statistics. |
| 1058 | * These control how long we stay using same modulation mode before |
| 1059 | * searching for a new mode. |
| 1060 | */ |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1061 | static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1062 | struct iwl_lq_sta *lq_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1063 | { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1064 | IWL_DEBUG_RATE(priv, "we are staying in the same table\n"); |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1065 | lq_sta->stay_in_tbl = 1; /* only place this gets set */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1066 | if (is_legacy) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1067 | lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; |
| 1068 | lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; |
| 1069 | lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1070 | } else { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1071 | lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; |
| 1072 | lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; |
| 1073 | lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1074 | } |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1075 | lq_sta->table_count = 0; |
| 1076 | lq_sta->total_failed = 0; |
| 1077 | lq_sta->total_success = 0; |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 1078 | lq_sta->flush_timer = jiffies; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1079 | lq_sta->action_counter = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1082 | /* |
| 1083 | * Find correct throughput table for given mode of modulation |
| 1084 | */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1085 | static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, |
| 1086 | struct iwl_scale_tbl_info *tbl) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1087 | { |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 1088 | /* Used to choose among HT tables */ |
| 1089 | s32 (*ht_tbl_pointer)[IWL_RATE_COUNT]; |
| 1090 | |
| 1091 | /* Check for invalid LQ type */ |
| 1092 | if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) { |
| 1093 | tbl->expected_tpt = expected_tpt_legacy; |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | /* Legacy rates have only one table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1098 | if (is_legacy(tbl->lq_type)) { |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 1099 | tbl->expected_tpt = expected_tpt_legacy; |
| 1100 | return; |
| 1101 | } |
| 1102 | |
| 1103 | /* Choose among many HT tables depending on number of streams |
| 1104 | * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation |
| 1105 | * status */ |
| 1106 | if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) |
| 1107 | ht_tbl_pointer = expected_tpt_siso20MHz; |
| 1108 | else if (is_siso(tbl->lq_type)) |
| 1109 | ht_tbl_pointer = expected_tpt_siso40MHz; |
| 1110 | else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) |
| 1111 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; |
| 1112 | else if (is_mimo2(tbl->lq_type)) |
| 1113 | ht_tbl_pointer = expected_tpt_mimo2_40MHz; |
| 1114 | else if (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) |
| 1115 | ht_tbl_pointer = expected_tpt_mimo3_20MHz; |
| 1116 | else /* if (is_mimo3(tbl->lq_type)) <-- must be true */ |
| 1117 | ht_tbl_pointer = expected_tpt_mimo3_40MHz; |
| 1118 | |
| 1119 | if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */ |
| 1120 | tbl->expected_tpt = ht_tbl_pointer[0]; |
| 1121 | else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */ |
| 1122 | tbl->expected_tpt = ht_tbl_pointer[1]; |
| 1123 | else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */ |
| 1124 | tbl->expected_tpt = ht_tbl_pointer[2]; |
| 1125 | else /* AGG+SGI */ |
| 1126 | tbl->expected_tpt = ht_tbl_pointer[3]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1129 | /* |
| 1130 | * Find starting rate for new "search" high-throughput mode of modulation. |
| 1131 | * Goal is to find lowest expected rate (under perfect conditions) that is |
| 1132 | * above the current measured throughput of "active" mode, to give new mode |
| 1133 | * a fair chance to prove itself without too many challenges. |
| 1134 | * |
| 1135 | * This gets called when transitioning to more aggressive modulation |
| 1136 | * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive |
| 1137 | * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need |
| 1138 | * to decrease to match "active" throughput. When moving from MIMO to SISO, |
| 1139 | * bit rate will typically need to increase, but not if performance was bad. |
| 1140 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1141 | static s32 rs_get_best_rate(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1142 | struct iwl_lq_sta *lq_sta, |
| 1143 | struct iwl_scale_tbl_info *tbl, /* "search" */ |
Guy Cohen | f935a6d | 2008-04-23 17:15:02 -0700 | [diff] [blame] | 1144 | u16 rate_mask, s8 index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1146 | /* "active" values */ |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1147 | struct iwl_scale_tbl_info *active_tbl = |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1148 | &(lq_sta->lq_info[lq_sta->active_tbl]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | s32 active_sr = active_tbl->win[index].success_ratio; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1150 | s32 active_tpt = active_tbl->expected_tpt[index]; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1151 | |
| 1152 | /* expected "search" throughput */ |
| 1153 | s32 *tpt_tbl = tbl->expected_tpt; |
| 1154 | |
| 1155 | s32 new_rate, high, low, start_hi; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1156 | u16 high_low; |
Guy Cohen | f935a6d | 2008-04-23 17:15:02 -0700 | [diff] [blame] | 1157 | s8 rate = index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1158 | |
| 1159 | new_rate = high = low = start_hi = IWL_RATE_INVALID; |
| 1160 | |
| 1161 | for (; ;) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1162 | high_low = rs_get_adjacent_rate(priv, rate, rate_mask, |
| 1163 | tbl->lq_type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1164 | |
| 1165 | low = high_low & 0xff; |
| 1166 | high = (high_low >> 8) & 0xff; |
| 1167 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1168 | /* |
| 1169 | * Lower the "search" bit rate, to give new "search" mode |
| 1170 | * approximately the same throughput as "active" if: |
| 1171 | * |
| 1172 | * 1) "Active" mode has been working modestly well (but not |
| 1173 | * great), and expected "search" throughput (under perfect |
| 1174 | * conditions) at candidate rate is above the actual |
| 1175 | * measured "active" throughput (but less than expected |
| 1176 | * "active" throughput under perfect conditions). |
| 1177 | * OR |
| 1178 | * 2) "Active" mode has been working perfectly or very well |
| 1179 | * and expected "search" throughput (under perfect |
| 1180 | * conditions) at candidate rate is above expected |
| 1181 | * "active" throughput (under perfect conditions). |
| 1182 | */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1183 | if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1184 | ((active_sr > IWL_RATE_DECREASE_TH) && |
| 1185 | (active_sr <= IWL_RATE_HIGH_TH) && |
| 1186 | (tpt_tbl[rate] <= active_tpt))) || |
| 1187 | ((active_sr >= IWL_RATE_SCALE_SWITCH) && |
| 1188 | (tpt_tbl[rate] > active_tpt))) { |
| 1189 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1190 | /* (2nd or later pass) |
| 1191 | * If we've already tried to raise the rate, and are |
| 1192 | * now trying to lower it, use the higher rate. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | if (start_hi != IWL_RATE_INVALID) { |
| 1194 | new_rate = start_hi; |
| 1195 | break; |
| 1196 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1197 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1198 | new_rate = rate; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1199 | |
| 1200 | /* Loop again with lower rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | if (low != IWL_RATE_INVALID) |
| 1202 | rate = low; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1203 | |
| 1204 | /* Lower rate not available, use the original */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1205 | else |
| 1206 | break; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1207 | |
| 1208 | /* Else try to raise the "search" rate to match "active" */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1209 | } else { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1210 | /* (2nd or later pass) |
| 1211 | * If we've already tried to lower the rate, and are |
| 1212 | * now trying to raise it, use the lower rate. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1213 | if (new_rate != IWL_RATE_INVALID) |
| 1214 | break; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1215 | |
| 1216 | /* Loop again with higher rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1217 | else if (high != IWL_RATE_INVALID) { |
| 1218 | start_hi = high; |
| 1219 | rate = high; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1220 | |
| 1221 | /* Higher rate not available, use the original */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | } else { |
Guy Cohen | 90d7795 | 2008-09-09 10:54:53 +0800 | [diff] [blame] | 1223 | new_rate = rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | break; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | return new_rate; |
| 1230 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1232 | /* |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1233 | * Set up search table for MIMO2 |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1234 | */ |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1235 | static int rs_switch_to_mimo2(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1236 | struct iwl_lq_sta *lq_sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1237 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1238 | struct ieee80211_sta *sta, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1239 | struct iwl_scale_tbl_info *tbl, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1240 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1241 | u16 rate_mask; |
| 1242 | s32 rate; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1243 | s8 is_green = lq_sta->is_green; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1244 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1245 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1246 | |
Luis R. Rodriguez | de27e64 | 2008-12-23 15:58:44 -0800 | [diff] [blame] | 1247 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | return -1; |
| 1249 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 1250 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 1251 | == WLAN_HT_CAP_SM_PS_STATIC) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | return -1; |
| 1253 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1254 | /* Need both Tx chains/antennas to support MIMO */ |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1255 | if (priv->hw_params.tx_chains_num < 2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1256 | return -1; |
| 1257 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1258 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n"); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1259 | |
| 1260 | tbl->lq_type = LQ_MIMO2; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1261 | tbl->is_dup = lq_sta->is_dup; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1262 | tbl->action = 0; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1263 | tbl->max_search = IWL_MAX_SEARCH; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1264 | rate_mask = lq_sta->active_mimo2_rate; |
| 1265 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1266 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1267 | tbl->is_ht40 = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1268 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1269 | tbl->is_ht40 = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 1271 | rs_set_expected_tpt_table(lq_sta, tbl); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1272 | |
Guy Cohen | f935a6d | 2008-04-23 17:15:02 -0700 | [diff] [blame] | 1273 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1274 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1275 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1276 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
| 1277 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", |
| 1278 | rate, rate_mask); |
| 1279 | return -1; |
| 1280 | } |
| 1281 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1282 | |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1283 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", |
| 1284 | tbl->current_rate, is_green); |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * Set up search table for MIMO3 |
| 1290 | */ |
| 1291 | static int rs_switch_to_mimo3(struct iwl_priv *priv, |
| 1292 | struct iwl_lq_sta *lq_sta, |
| 1293 | struct ieee80211_conf *conf, |
| 1294 | struct ieee80211_sta *sta, |
| 1295 | struct iwl_scale_tbl_info *tbl, int index) |
| 1296 | { |
| 1297 | u16 rate_mask; |
| 1298 | s32 rate; |
| 1299 | s8 is_green = lq_sta->is_green; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1300 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1301 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
| 1304 | return -1; |
| 1305 | |
| 1306 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) |
| 1307 | == WLAN_HT_CAP_SM_PS_STATIC) |
| 1308 | return -1; |
| 1309 | |
| 1310 | /* Need both Tx chains/antennas to support MIMO */ |
| 1311 | if (priv->hw_params.tx_chains_num < 3) |
| 1312 | return -1; |
| 1313 | |
| 1314 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n"); |
| 1315 | |
| 1316 | tbl->lq_type = LQ_MIMO3; |
| 1317 | tbl->is_dup = lq_sta->is_dup; |
| 1318 | tbl->action = 0; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1319 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1320 | rate_mask = lq_sta->active_mimo3_rate; |
| 1321 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1322 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1323 | tbl->is_ht40 = 1; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1324 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1325 | tbl->is_ht40 = 0; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1326 | |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1327 | rs_set_expected_tpt_table(lq_sta, tbl); |
| 1328 | |
| 1329 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); |
| 1330 | |
| 1331 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n", |
| 1332 | rate, rate_mask); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1333 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1334 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1335 | rate, rate_mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1336 | return -1; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1337 | } |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 1338 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1339 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1340 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1341 | tbl->current_rate, is_green); |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 1342 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1345 | /* |
| 1346 | * Set up search table for SISO |
| 1347 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1348 | static int rs_switch_to_siso(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1349 | struct iwl_lq_sta *lq_sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1350 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1351 | struct ieee80211_sta *sta, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1352 | struct iwl_scale_tbl_info *tbl, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1353 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1354 | u16 rate_mask; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1355 | u8 is_green = lq_sta->is_green; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1356 | s32 rate; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1357 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1358 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1359 | |
Luis R. Rodriguez | de27e64 | 2008-12-23 15:58:44 -0800 | [diff] [blame] | 1360 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | return -1; |
| 1362 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1363 | IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n"); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1364 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1365 | tbl->is_dup = lq_sta->is_dup; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1366 | tbl->lq_type = LQ_SISO; |
| 1367 | tbl->action = 0; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1368 | tbl->max_search = IWL_MAX_SEARCH; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1369 | rate_mask = lq_sta->active_siso_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 1371 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1372 | tbl->is_ht40 = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1373 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1374 | tbl->is_ht40 = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1375 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1376 | if (is_green) |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1377 | tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1378 | |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 1379 | rs_set_expected_tpt_table(lq_sta, tbl); |
Guy Cohen | f935a6d | 2008-04-23 17:15:02 -0700 | [diff] [blame] | 1380 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1381 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1382 | IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1383 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1384 | IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1385 | rate, rate_mask); |
| 1386 | return -1; |
| 1387 | } |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 1388 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1389 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1390 | tbl->current_rate, is_green); |
Mohamed Abbas | 403ab56 | 2007-11-06 22:06:25 -0800 | [diff] [blame] | 1391 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1394 | /* |
| 1395 | * Try to switch to new modulation mode from legacy |
| 1396 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1397 | static int rs_move_legacy_other(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1398 | struct iwl_lq_sta *lq_sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1399 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1400 | struct ieee80211_sta *sta, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1401 | int index) |
| 1402 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1403 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1404 | struct iwl_scale_tbl_info *search_tbl = |
| 1405 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 1406 | struct iwl_rate_scale_data *window = &(tbl->win[index]); |
| 1407 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1408 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1409 | u8 start_action; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1410 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1411 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1412 | int ret = 0; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1413 | u8 update_search_tbl_counter = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1414 | |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1415 | switch (priv->bt_traffic_load) { |
| 1416 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: |
| 1417 | /* nothing */ |
| 1418 | break; |
| 1419 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: |
| 1420 | /* avoid antenna B unless MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1421 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1422 | if (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2) |
| 1423 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
| 1424 | break; |
| 1425 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: |
| 1426 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: |
| 1427 | /* avoid antenna B and MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1428 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1429 | if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 && |
| 1430 | tbl->action != IWL_LEGACY_SWITCH_SISO) |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1431 | tbl->action = IWL_LEGACY_SWITCH_SISO; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1432 | break; |
| 1433 | default: |
| 1434 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); |
| 1435 | break; |
| 1436 | } |
| 1437 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 1438 | if (!iwl_ht_enabled(priv)) |
| 1439 | /* stay in Legacy */ |
| 1440 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 1441 | else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 1442 | tbl->action > IWL_LEGACY_SWITCH_SISO) |
| 1443 | tbl->action = IWL_LEGACY_SWITCH_SISO; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1444 | |
| 1445 | /* configure as 1x1 if bt full concurrency */ |
| 1446 | if (priv->bt_full_concurrent) { |
| 1447 | if (!iwl_ht_enabled(priv)) |
| 1448 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
| 1449 | else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) |
| 1450 | tbl->action = IWL_LEGACY_SWITCH_SISO; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1451 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1454 | start_action = tbl->action; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1455 | for (; ;) { |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1456 | lq_sta->action_counter++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | switch (tbl->action) { |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1458 | case IWL_LEGACY_SWITCH_ANTENNA1: |
| 1459 | case IWL_LEGACY_SWITCH_ANTENNA2: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1460 | IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1461 | |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1462 | if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 && |
| 1463 | tx_chains_num <= 1) || |
| 1464 | (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 && |
| 1465 | tx_chains_num <= 2)) |
| 1466 | break; |
| 1467 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1468 | /* Don't change antenna if success has been great */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1469 | if (window->success_ratio >= IWL_RS_GOOD_RATIO && |
| 1470 | !priv->bt_full_concurrent && |
| 1471 | priv->bt_traffic_load == |
| 1472 | IWL_BT_COEX_TRAFFIC_LOAD_NONE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1473 | break; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1474 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1475 | /* Set up search table to try other antenna */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1476 | memcpy(search_tbl, tbl, sz); |
| 1477 | |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1478 | if (rs_toggle_antenna(valid_tx_ant, |
| 1479 | &search_tbl->current_rate, search_tbl)) { |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1480 | update_search_tbl_counter = 1; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1481 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1482 | goto out; |
| 1483 | } |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 1484 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1485 | case IWL_LEGACY_SWITCH_SISO: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1486 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n"); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1487 | |
| 1488 | /* Set up search table to try SISO */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1489 | memcpy(search_tbl, tbl, sz); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | search_tbl->is_SGI = 0; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1491 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1492 | search_tbl, index); |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 1493 | if (!ret) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1494 | lq_sta->action_counter = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1495 | goto out; |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 1496 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1497 | |
| 1498 | break; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1499 | case IWL_LEGACY_SWITCH_MIMO2_AB: |
| 1500 | case IWL_LEGACY_SWITCH_MIMO2_AC: |
| 1501 | case IWL_LEGACY_SWITCH_MIMO2_BC: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1502 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n"); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1503 | |
| 1504 | /* Set up search table to try MIMO */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1505 | memcpy(search_tbl, tbl, sz); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1506 | search_tbl->is_SGI = 0; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1507 | |
| 1508 | if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB) |
| 1509 | search_tbl->ant_type = ANT_AB; |
| 1510 | else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC) |
| 1511 | search_tbl->ant_type = ANT_AC; |
| 1512 | else |
| 1513 | search_tbl->ant_type = ANT_BC; |
| 1514 | |
| 1515 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1516 | break; |
| 1517 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1518 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1519 | search_tbl, index); |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 1520 | if (!ret) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1521 | lq_sta->action_counter = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1522 | goto out; |
Tomas Winkler | dc2453ae | 2007-10-25 17:15:25 +0800 | [diff] [blame] | 1523 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1524 | break; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1525 | |
| 1526 | case IWL_LEGACY_SWITCH_MIMO3_ABC: |
| 1527 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n"); |
| 1528 | |
| 1529 | /* Set up search table to try MIMO3 */ |
| 1530 | memcpy(search_tbl, tbl, sz); |
| 1531 | search_tbl->is_SGI = 0; |
| 1532 | |
| 1533 | search_tbl->ant_type = ANT_ABC; |
| 1534 | |
| 1535 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1536 | break; |
| 1537 | |
| 1538 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, |
| 1539 | search_tbl, index); |
| 1540 | if (!ret) { |
| 1541 | lq_sta->action_counter = 0; |
| 1542 | goto out; |
| 1543 | } |
| 1544 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1545 | } |
| 1546 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1547 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1548 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | |
| 1550 | if (tbl->action == start_action) |
| 1551 | break; |
| 1552 | |
| 1553 | } |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1554 | search_tbl->lq_type = LQ_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | return 0; |
| 1556 | |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1557 | out: |
| 1558 | lq_sta->search_better_tbl = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1559 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1560 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1561 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1562 | if (update_search_tbl_counter) |
| 1563 | search_tbl->action = tbl->action; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1564 | return 0; |
| 1565 | |
| 1566 | } |
| 1567 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1568 | /* |
| 1569 | * Try to switch to new modulation mode from SISO |
| 1570 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1571 | static int rs_move_siso_to_other(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1572 | struct iwl_lq_sta *lq_sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1573 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1574 | struct ieee80211_sta *sta, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1576 | u8 is_green = lq_sta->is_green; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1577 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1578 | struct iwl_scale_tbl_info *search_tbl = |
| 1579 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 1580 | struct iwl_rate_scale_data *window = &(tbl->win[index]); |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1581 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1582 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1583 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1584 | u8 start_action; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1585 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1586 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1587 | u8 update_search_tbl_counter = 0; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1588 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1589 | |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1590 | switch (priv->bt_traffic_load) { |
| 1591 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: |
| 1592 | /* nothing */ |
| 1593 | break; |
| 1594 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: |
| 1595 | /* avoid antenna B unless MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1596 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1597 | if (tbl->action == IWL_SISO_SWITCH_ANTENNA2) |
| 1598 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
| 1599 | break; |
| 1600 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: |
| 1601 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: |
| 1602 | /* avoid antenna B and MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1603 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
| 1604 | if (tbl->action != IWL_SISO_SWITCH_ANTENNA1) |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1605 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
| 1606 | break; |
| 1607 | default: |
| 1608 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); |
| 1609 | break; |
| 1610 | } |
| 1611 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 1612 | if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 1613 | tbl->action > IWL_SISO_SWITCH_ANTENNA2) { |
| 1614 | /* stay in SISO */ |
| 1615 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
| 1616 | } |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1617 | |
| 1618 | /* configure as 1x1 if bt full concurrency */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1619 | if (priv->bt_full_concurrent) { |
| 1620 | valid_tx_ant = first_antenna(priv->hw_params.valid_tx_ant); |
| 1621 | if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) |
| 1622 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
| 1623 | } |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1624 | |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1625 | start_action = tbl->action; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1626 | for (;;) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1627 | lq_sta->action_counter++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1628 | switch (tbl->action) { |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1629 | case IWL_SISO_SWITCH_ANTENNA1: |
| 1630 | case IWL_SISO_SWITCH_ANTENNA2: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1631 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n"); |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1632 | if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 && |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1633 | tx_chains_num <= 1) || |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1634 | (tbl->action == IWL_SISO_SWITCH_ANTENNA2 && |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1635 | tx_chains_num <= 2)) |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1636 | break; |
| 1637 | |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1638 | if (window->success_ratio >= IWL_RS_GOOD_RATIO && |
| 1639 | !priv->bt_full_concurrent && |
| 1640 | priv->bt_traffic_load == |
| 1641 | IWL_BT_COEX_TRAFFIC_LOAD_NONE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1642 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1643 | |
| 1644 | memcpy(search_tbl, tbl, sz); |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1645 | if (rs_toggle_antenna(valid_tx_ant, |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1646 | &search_tbl->current_rate, search_tbl)) { |
| 1647 | update_search_tbl_counter = 1; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1648 | goto out; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1649 | } |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 1650 | break; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1651 | case IWL_SISO_SWITCH_MIMO2_AB: |
| 1652 | case IWL_SISO_SWITCH_MIMO2_AC: |
| 1653 | case IWL_SISO_SWITCH_MIMO2_BC: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1654 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1655 | memcpy(search_tbl, tbl, sz); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1656 | search_tbl->is_SGI = 0; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1657 | |
| 1658 | if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB) |
| 1659 | search_tbl->ant_type = ANT_AB; |
| 1660 | else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC) |
| 1661 | search_tbl->ant_type = ANT_AC; |
| 1662 | else |
| 1663 | search_tbl->ant_type = ANT_BC; |
| 1664 | |
| 1665 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1666 | break; |
| 1667 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1668 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1669 | search_tbl, index); |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1670 | if (!ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1671 | goto out; |
| 1672 | break; |
| 1673 | case IWL_SISO_SWITCH_GI: |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1674 | if (!tbl->is_ht40 && !(ht_cap->cap & |
| 1675 | IEEE80211_HT_CAP_SGI_20)) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 1676 | break; |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1677 | if (tbl->is_ht40 && !(ht_cap->cap & |
| 1678 | IEEE80211_HT_CAP_SGI_40)) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 1679 | break; |
| 1680 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1681 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n"); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 1682 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1683 | memcpy(search_tbl, tbl, sz); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1684 | if (is_green) { |
| 1685 | if (!tbl->is_SGI) |
| 1686 | break; |
| 1687 | else |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1688 | IWL_ERR(priv, |
| 1689 | "SGI was set in GF+SISO\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1690 | } |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1691 | search_tbl->is_SGI = !tbl->is_SGI; |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 1692 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1693 | if (tbl->is_SGI) { |
| 1694 | s32 tpt = lq_sta->last_tpt / 100; |
| 1695 | if (tpt >= search_tbl->expected_tpt[index]) |
| 1696 | break; |
| 1697 | } |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 1698 | search_tbl->current_rate = |
| 1699 | rate_n_flags_from_tbl(priv, search_tbl, |
| 1700 | index, is_green); |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1701 | update_search_tbl_counter = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | goto out; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1703 | case IWL_SISO_SWITCH_MIMO3_ABC: |
| 1704 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n"); |
| 1705 | memcpy(search_tbl, tbl, sz); |
| 1706 | search_tbl->is_SGI = 0; |
| 1707 | search_tbl->ant_type = ANT_ABC; |
| 1708 | |
| 1709 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1710 | break; |
| 1711 | |
| 1712 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, |
| 1713 | search_tbl, index); |
| 1714 | if (!ret) |
| 1715 | goto out; |
| 1716 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1717 | } |
| 1718 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1719 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1720 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | |
| 1722 | if (tbl->action == start_action) |
| 1723 | break; |
| 1724 | } |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1725 | search_tbl->lq_type = LQ_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | return 0; |
| 1727 | |
| 1728 | out: |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1729 | lq_sta->search_better_tbl = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1730 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1731 | if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC) |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1732 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1733 | if (update_search_tbl_counter) |
| 1734 | search_tbl->action = tbl->action; |
| 1735 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1736 | return 0; |
| 1737 | } |
| 1738 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1739 | /* |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1740 | * Try to switch to new modulation mode from MIMO2 |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1741 | */ |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1742 | static int rs_move_mimo2_to_other(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1743 | struct iwl_lq_sta *lq_sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1744 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1745 | struct ieee80211_sta *sta, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1746 | { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1747 | s8 is_green = lq_sta->is_green; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1748 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1749 | struct iwl_scale_tbl_info *search_tbl = |
| 1750 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1751 | struct iwl_rate_scale_data *window = &(tbl->win[index]); |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1752 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 1753 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1754 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1755 | u8 start_action; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1756 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
| 1757 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1758 | u8 update_search_tbl_counter = 0; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 1759 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1760 | |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1761 | switch (priv->bt_traffic_load) { |
| 1762 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: |
| 1763 | /* nothing */ |
| 1764 | break; |
| 1765 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: |
| 1766 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: |
| 1767 | /* avoid antenna B and MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1768 | if (tbl->action != IWL_MIMO2_SWITCH_SISO_A) |
| 1769 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; |
| 1770 | break; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1771 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: |
| 1772 | /* avoid antenna B unless MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1773 | if (tbl->action == IWL_MIMO2_SWITCH_SISO_B || |
| 1774 | tbl->action == IWL_MIMO2_SWITCH_SISO_C) |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1775 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; |
| 1776 | break; |
| 1777 | default: |
| 1778 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); |
| 1779 | break; |
| 1780 | } |
| 1781 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 1782 | if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 1783 | (tbl->action < IWL_MIMO2_SWITCH_SISO_A || |
| 1784 | tbl->action > IWL_MIMO2_SWITCH_SISO_C)) { |
| 1785 | /* switch in SISO */ |
| 1786 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; |
| 1787 | } |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1788 | |
| 1789 | /* configure as 1x1 if bt full concurrency */ |
| 1790 | if (priv->bt_full_concurrent && |
| 1791 | (tbl->action < IWL_MIMO2_SWITCH_SISO_A || |
| 1792 | tbl->action > IWL_MIMO2_SWITCH_SISO_C)) |
| 1793 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; |
| 1794 | |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1795 | start_action = tbl->action; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | for (;;) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1797 | lq_sta->action_counter++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1798 | switch (tbl->action) { |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1799 | case IWL_MIMO2_SWITCH_ANTENNA1: |
| 1800 | case IWL_MIMO2_SWITCH_ANTENNA2: |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1801 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n"); |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1802 | |
| 1803 | if (tx_chains_num <= 2) |
| 1804 | break; |
| 1805 | |
| 1806 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) |
| 1807 | break; |
| 1808 | |
| 1809 | memcpy(search_tbl, tbl, sz); |
| 1810 | if (rs_toggle_antenna(valid_tx_ant, |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1811 | &search_tbl->current_rate, search_tbl)) { |
| 1812 | update_search_tbl_counter = 1; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1813 | goto out; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1814 | } |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1815 | break; |
| 1816 | case IWL_MIMO2_SWITCH_SISO_A: |
| 1817 | case IWL_MIMO2_SWITCH_SISO_B: |
| 1818 | case IWL_MIMO2_SWITCH_SISO_C: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1819 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n"); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 1820 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1821 | /* Set up new search table for SISO */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1822 | memcpy(search_tbl, tbl, sz); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1823 | |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1824 | if (tbl->action == IWL_MIMO2_SWITCH_SISO_A) |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1825 | search_tbl->ant_type = ANT_A; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1826 | else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B) |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1827 | search_tbl->ant_type = ANT_B; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1828 | else |
| 1829 | search_tbl->ant_type = ANT_C; |
| 1830 | |
| 1831 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1832 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 1834 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 1835 | search_tbl, index); |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1836 | if (!ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1837 | goto out; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1838 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1839 | break; |
| 1840 | |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 1841 | case IWL_MIMO2_SWITCH_GI: |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1842 | if (!tbl->is_ht40 && !(ht_cap->cap & |
| 1843 | IEEE80211_HT_CAP_SGI_20)) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 1844 | break; |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1845 | if (tbl->is_ht40 && !(ht_cap->cap & |
| 1846 | IEEE80211_HT_CAP_SGI_40)) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 1847 | break; |
| 1848 | |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1849 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n"); |
| 1850 | |
| 1851 | /* Set up new search table for MIMO2 */ |
| 1852 | memcpy(search_tbl, tbl, sz); |
| 1853 | search_tbl->is_SGI = !tbl->is_SGI; |
| 1854 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
| 1855 | /* |
| 1856 | * If active table already uses the fastest possible |
| 1857 | * modulation (dual stream with short guard interval), |
| 1858 | * and it's working well, there's no need to look |
| 1859 | * for a better type of modulation! |
| 1860 | */ |
| 1861 | if (tbl->is_SGI) { |
| 1862 | s32 tpt = lq_sta->last_tpt / 100; |
| 1863 | if (tpt >= search_tbl->expected_tpt[index]) |
| 1864 | break; |
| 1865 | } |
| 1866 | search_tbl->current_rate = |
| 1867 | rate_n_flags_from_tbl(priv, search_tbl, |
| 1868 | index, is_green); |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1869 | update_search_tbl_counter = 1; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1870 | goto out; |
| 1871 | |
| 1872 | case IWL_MIMO2_SWITCH_MIMO3_ABC: |
| 1873 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n"); |
| 1874 | memcpy(search_tbl, tbl, sz); |
| 1875 | search_tbl->is_SGI = 0; |
| 1876 | search_tbl->ant_type = ANT_ABC; |
| 1877 | |
| 1878 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 1879 | break; |
| 1880 | |
| 1881 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, |
| 1882 | search_tbl, index); |
| 1883 | if (!ret) |
| 1884 | goto out; |
| 1885 | |
| 1886 | break; |
| 1887 | } |
| 1888 | tbl->action++; |
| 1889 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) |
| 1890 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; |
| 1891 | |
| 1892 | if (tbl->action == start_action) |
| 1893 | break; |
| 1894 | } |
| 1895 | search_tbl->lq_type = LQ_NONE; |
| 1896 | return 0; |
| 1897 | out: |
| 1898 | lq_sta->search_better_tbl = 1; |
| 1899 | tbl->action++; |
| 1900 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) |
| 1901 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1902 | if (update_search_tbl_counter) |
| 1903 | search_tbl->action = tbl->action; |
| 1904 | |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1905 | return 0; |
| 1906 | |
| 1907 | } |
| 1908 | |
| 1909 | /* |
| 1910 | * Try to switch to new modulation mode from MIMO3 |
| 1911 | */ |
| 1912 | static int rs_move_mimo3_to_other(struct iwl_priv *priv, |
| 1913 | struct iwl_lq_sta *lq_sta, |
| 1914 | struct ieee80211_conf *conf, |
| 1915 | struct ieee80211_sta *sta, int index) |
| 1916 | { |
| 1917 | s8 is_green = lq_sta->is_green; |
| 1918 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1919 | struct iwl_scale_tbl_info *search_tbl = |
| 1920 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 1921 | struct iwl_rate_scale_data *window = &(tbl->win[index]); |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 1922 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1923 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1924 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1925 | u8 start_action; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1926 | u8 valid_tx_ant = priv->hw_params.valid_tx_ant; |
| 1927 | u8 tx_chains_num = priv->hw_params.tx_chains_num; |
| 1928 | int ret; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 1929 | u8 update_search_tbl_counter = 0; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1930 | |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1931 | switch (priv->bt_traffic_load) { |
| 1932 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: |
| 1933 | /* nothing */ |
| 1934 | break; |
| 1935 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: |
| 1936 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: |
| 1937 | /* avoid antenna B and MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1938 | if (tbl->action != IWL_MIMO3_SWITCH_SISO_A) |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1939 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1940 | break; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1941 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: |
| 1942 | /* avoid antenna B unless MIMO */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 1943 | if (tbl->action == IWL_MIMO3_SWITCH_SISO_B || |
| 1944 | tbl->action == IWL_MIMO3_SWITCH_SISO_C) |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1945 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 1946 | break; |
| 1947 | default: |
| 1948 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); |
| 1949 | break; |
| 1950 | } |
| 1951 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 1952 | if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 1953 | (tbl->action < IWL_MIMO3_SWITCH_SISO_A || |
| 1954 | tbl->action > IWL_MIMO3_SWITCH_SISO_C)) { |
| 1955 | /* switch in SISO */ |
| 1956 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; |
| 1957 | } |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 1958 | |
| 1959 | /* configure as 1x1 if bt full concurrency */ |
| 1960 | if (priv->bt_full_concurrent && |
| 1961 | (tbl->action < IWL_MIMO3_SWITCH_SISO_A || |
| 1962 | tbl->action > IWL_MIMO3_SWITCH_SISO_C)) |
| 1963 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; |
| 1964 | |
Wey-Yi Guy | b1a7885 | 2010-07-31 08:52:03 -0700 | [diff] [blame] | 1965 | start_action = tbl->action; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 1966 | for (;;) { |
| 1967 | lq_sta->action_counter++; |
| 1968 | switch (tbl->action) { |
| 1969 | case IWL_MIMO3_SWITCH_ANTENNA1: |
| 1970 | case IWL_MIMO3_SWITCH_ANTENNA2: |
| 1971 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n"); |
| 1972 | |
| 1973 | if (tx_chains_num <= 3) |
| 1974 | break; |
| 1975 | |
| 1976 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) |
| 1977 | break; |
| 1978 | |
| 1979 | memcpy(search_tbl, tbl, sz); |
| 1980 | if (rs_toggle_antenna(valid_tx_ant, |
| 1981 | &search_tbl->current_rate, search_tbl)) |
| 1982 | goto out; |
| 1983 | break; |
| 1984 | case IWL_MIMO3_SWITCH_SISO_A: |
| 1985 | case IWL_MIMO3_SWITCH_SISO_B: |
| 1986 | case IWL_MIMO3_SWITCH_SISO_C: |
| 1987 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n"); |
| 1988 | |
| 1989 | /* Set up new search table for SISO */ |
| 1990 | memcpy(search_tbl, tbl, sz); |
| 1991 | |
| 1992 | if (tbl->action == IWL_MIMO3_SWITCH_SISO_A) |
| 1993 | search_tbl->ant_type = ANT_A; |
| 1994 | else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B) |
| 1995 | search_tbl->ant_type = ANT_B; |
| 1996 | else |
| 1997 | search_tbl->ant_type = ANT_C; |
| 1998 | |
| 1999 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 2000 | break; |
| 2001 | |
| 2002 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, |
| 2003 | search_tbl, index); |
| 2004 | if (!ret) |
| 2005 | goto out; |
| 2006 | |
| 2007 | break; |
| 2008 | |
| 2009 | case IWL_MIMO3_SWITCH_MIMO2_AB: |
| 2010 | case IWL_MIMO3_SWITCH_MIMO2_AC: |
| 2011 | case IWL_MIMO3_SWITCH_MIMO2_BC: |
| 2012 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n"); |
| 2013 | |
| 2014 | memcpy(search_tbl, tbl, sz); |
| 2015 | search_tbl->is_SGI = 0; |
| 2016 | if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB) |
| 2017 | search_tbl->ant_type = ANT_AB; |
| 2018 | else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC) |
| 2019 | search_tbl->ant_type = ANT_AC; |
| 2020 | else |
| 2021 | search_tbl->ant_type = ANT_BC; |
| 2022 | |
| 2023 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) |
| 2024 | break; |
| 2025 | |
| 2026 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, |
| 2027 | search_tbl, index); |
| 2028 | if (!ret) |
| 2029 | goto out; |
| 2030 | |
| 2031 | break; |
| 2032 | |
| 2033 | case IWL_MIMO3_SWITCH_GI: |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 2034 | if (!tbl->is_ht40 && !(ht_cap->cap & |
| 2035 | IEEE80211_HT_CAP_SGI_20)) |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2036 | break; |
Daniel C Halperin | 28e6f48 | 2009-08-13 13:30:58 -0700 | [diff] [blame] | 2037 | if (tbl->is_ht40 && !(ht_cap->cap & |
| 2038 | IEEE80211_HT_CAP_SGI_40)) |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2039 | break; |
| 2040 | |
| 2041 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n"); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2042 | |
| 2043 | /* Set up new search table for MIMO */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | memcpy(search_tbl, tbl, sz); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2045 | search_tbl->is_SGI = !tbl->is_SGI; |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 2046 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2047 | /* |
| 2048 | * If active table already uses the fastest possible |
| 2049 | * modulation (dual stream with short guard interval), |
| 2050 | * and it's working well, there's no need to look |
| 2051 | * for a better type of modulation! |
| 2052 | */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2053 | if (tbl->is_SGI) { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2054 | s32 tpt = lq_sta->last_tpt / 100; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2055 | if (tpt >= search_tbl->expected_tpt[index]) |
| 2056 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | } |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2058 | search_tbl->current_rate = |
| 2059 | rate_n_flags_from_tbl(priv, search_tbl, |
| 2060 | index, is_green); |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 2061 | update_search_tbl_counter = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2062 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2063 | } |
| 2064 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2065 | if (tbl->action > IWL_MIMO3_SWITCH_GI) |
| 2066 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2067 | |
| 2068 | if (tbl->action == start_action) |
| 2069 | break; |
| 2070 | } |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 2071 | search_tbl->lq_type = LQ_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2072 | return 0; |
| 2073 | out: |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 2074 | lq_sta->search_better_tbl = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2075 | tbl->action++; |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2076 | if (tbl->action > IWL_MIMO3_SWITCH_GI) |
| 2077 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 2078 | if (update_search_tbl_counter) |
| 2079 | search_tbl->action = tbl->action; |
| 2080 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2081 | return 0; |
| 2082 | |
| 2083 | } |
| 2084 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2085 | /* |
| 2086 | * Check whether we should continue using same modulation mode, or |
| 2087 | * begin search for a new mode, based on: |
| 2088 | * 1) # tx successes or failures while using this mode |
| 2089 | * 2) # times calling this function |
| 2090 | * 3) elapsed time in this mode (not used, for now) |
| 2091 | */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2092 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2093 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2094 | struct iwl_scale_tbl_info *tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | int i; |
| 2096 | int active_tbl; |
| 2097 | int flush_interval_passed = 0; |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2098 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2099 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2100 | priv = lq_sta->drv; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2101 | active_tbl = lq_sta->active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2102 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2103 | tbl = &(lq_sta->lq_info[active_tbl]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2104 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2105 | /* If we've been disallowing search, see if we should now allow it */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2106 | if (lq_sta->stay_in_tbl) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2108 | /* Elapsed time using current modulation mode */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2109 | if (lq_sta->flush_timer) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2110 | flush_interval_passed = |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 2111 | time_after(jiffies, |
| 2112 | (unsigned long)(lq_sta->flush_timer + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2113 | IWL_RATE_SCALE_FLUSH_INTVL)); |
| 2114 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2115 | /* |
| 2116 | * Check if we should allow search for new modulation mode. |
| 2117 | * If many frames have failed or succeeded, or we've used |
| 2118 | * this same modulation for a long time, allow search, and |
| 2119 | * reset history stats that keep track of whether we should |
| 2120 | * allow a new search. Also (below) reset all bitmaps and |
| 2121 | * stats in active history. |
| 2122 | */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2123 | if (force_search || |
| 2124 | (lq_sta->total_failed > lq_sta->max_failure_limit) || |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2125 | (lq_sta->total_success > lq_sta->max_success_limit) || |
| 2126 | ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2127 | && (flush_interval_passed))) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2128 | IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n:", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2129 | lq_sta->total_failed, |
| 2130 | lq_sta->total_success, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2131 | flush_interval_passed); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2132 | |
| 2133 | /* Allow search for new mode */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2134 | lq_sta->stay_in_tbl = 0; /* only place reset */ |
| 2135 | lq_sta->total_failed = 0; |
| 2136 | lq_sta->total_success = 0; |
| 2137 | lq_sta->flush_timer = 0; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2138 | |
| 2139 | /* |
| 2140 | * Else if we've used this modulation mode enough repetitions |
| 2141 | * (regardless of elapsed time or success/failure), reset |
| 2142 | * history bitmaps and rate-specific stats for all rates in |
| 2143 | * active table. |
| 2144 | */ |
Mohamed Abbas | 403ab56 | 2007-11-06 22:06:25 -0800 | [diff] [blame] | 2145 | } else { |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2146 | lq_sta->table_count++; |
| 2147 | if (lq_sta->table_count >= |
| 2148 | lq_sta->table_count_limit) { |
| 2149 | lq_sta->table_count = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2150 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2151 | IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2152 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2153 | rs_rate_scale_clear_window( |
| 2154 | &(tbl->win[i])); |
| 2155 | } |
| 2156 | } |
| 2157 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2158 | /* If transitioning to allow "search", reset all history |
| 2159 | * bitmaps and stats in active table (this will become the new |
| 2160 | * "search" table). */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2161 | if (!lq_sta->stay_in_tbl) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2162 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2163 | rs_rate_scale_clear_window(&(tbl->win[i])); |
| 2164 | } |
| 2165 | } |
| 2166 | } |
| 2167 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2168 | /* |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2169 | * setup rate table in uCode |
| 2170 | * return rate_n_flags as used in the table |
| 2171 | */ |
| 2172 | static u32 rs_update_rate_tbl(struct iwl_priv *priv, |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2173 | struct iwl_rxon_context *ctx, |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2174 | struct iwl_lq_sta *lq_sta, |
| 2175 | struct iwl_scale_tbl_info *tbl, |
| 2176 | int index, u8 is_green) |
| 2177 | { |
| 2178 | u32 rate; |
| 2179 | |
| 2180 | /* Update uCode's rate table. */ |
| 2181 | rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); |
| 2182 | rs_fill_link_cmd(priv, lq_sta, rate); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2183 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2184 | |
| 2185 | return rate; |
| 2186 | } |
| 2187 | |
| 2188 | /* |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2189 | * Do rate scaling and search for new modulation mode. |
| 2190 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2191 | static void rs_rate_scale_perform(struct iwl_priv *priv, |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 2192 | struct sk_buff *skb, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2193 | struct ieee80211_sta *sta, |
| 2194 | struct iwl_lq_sta *lq_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2195 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2196 | struct ieee80211_hw *hw = priv->hw; |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 2197 | struct ieee80211_conf *conf = &hw->conf; |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 2198 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2199 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2200 | int low = IWL_RATE_INVALID; |
| 2201 | int high = IWL_RATE_INVALID; |
| 2202 | int index; |
| 2203 | int i; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2204 | struct iwl_rate_scale_data *window = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2205 | int current_tpt = IWL_INVALID_VALUE; |
| 2206 | int low_tpt = IWL_INVALID_VALUE; |
| 2207 | int high_tpt = IWL_INVALID_VALUE; |
| 2208 | u32 fail_count; |
| 2209 | s8 scale_action = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2210 | u16 rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2211 | u8 update_lq = 0; |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2212 | struct iwl_scale_tbl_info *tbl, *tbl1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2213 | u16 rate_scale_index_msk = 0; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2214 | u32 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2215 | u8 is_green = 0; |
| 2216 | u8 active_tbl = 0; |
| 2217 | u8 done_search = 0; |
| 2218 | u16 high_low; |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2219 | s32 sr; |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 2220 | u8 tid = MAX_TID_COUNT; |
Wey-Yi Guy | 86b4766 | 2009-03-10 14:35:09 -0700 | [diff] [blame] | 2221 | struct iwl_tid_data *tid_data; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2222 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 2223 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2224 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2225 | IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2226 | |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 2227 | /* Send management frames and NO_ACK data using lowest rate. */ |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 2228 | /* TODO: this could probably be improved.. */ |
| 2229 | if (!ieee80211_is_data(hdr->frame_control) || |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 2230 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2233 | if (!sta || !lq_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2234 | return; |
| 2235 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2236 | lq_sta->supp_rates = sta->supp_rates[lq_sta->band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 2238 | tid = rs_tl_add_packet(lq_sta, hdr); |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 2239 | if ((tid != MAX_TID_COUNT) && (lq_sta->tx_agg_tid_en & (1 << tid))) { |
| 2240 | tid_data = &priv->stations[lq_sta->lq.sta_id].tid[tid]; |
| 2241 | if (tid_data->agg.state == IWL_AGG_OFF) |
| 2242 | lq_sta->is_agg = 0; |
| 2243 | else |
| 2244 | lq_sta->is_agg = 1; |
| 2245 | } else |
| 2246 | lq_sta->is_agg = 0; |
Ron Rindjunsky | faa2971 | 2008-06-12 09:46:58 +0800 | [diff] [blame] | 2247 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2248 | /* |
| 2249 | * Select rate-scale / modulation-mode table to work with in |
| 2250 | * the rest of this function: "search" if searching for better |
| 2251 | * modulation mode, or "active" if doing rate scaling within a mode. |
| 2252 | */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2253 | if (!lq_sta->search_better_tbl) |
| 2254 | active_tbl = lq_sta->active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2255 | else |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2256 | active_tbl = 1 - lq_sta->active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2258 | tbl = &(lq_sta->lq_info[active_tbl]); |
Wey-Yi Guy | 2681b20 | 2009-05-21 13:44:22 -0700 | [diff] [blame] | 2259 | if (is_legacy(tbl->lq_type)) |
| 2260 | lq_sta->is_green = 0; |
| 2261 | else |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2262 | lq_sta->is_green = rs_use_green(sta); |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2263 | is_green = lq_sta->is_green; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2264 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2265 | /* current tx rate */ |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 2266 | index = lq_sta->last_txrate_idx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2268 | IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2269 | tbl->lq_type); |
| 2270 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2271 | /* rates available for this association, and for modulation mode */ |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 2272 | rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2273 | |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 2274 | IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2275 | |
| 2276 | /* mask with station rate restriction */ |
| 2277 | if (is_legacy(tbl->lq_type)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2278 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2279 | /* supp_rates has no CCK bits in A mode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2280 | rate_scale_index_msk = (u16) (rate_mask & |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2281 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2282 | else |
| 2283 | rate_scale_index_msk = (u16) (rate_mask & |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2284 | lq_sta->supp_rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2285 | |
| 2286 | } else |
| 2287 | rate_scale_index_msk = rate_mask; |
| 2288 | |
| 2289 | if (!rate_scale_index_msk) |
| 2290 | rate_scale_index_msk = rate_mask; |
| 2291 | |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2292 | if (!((1 << index) & rate_scale_index_msk)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2293 | IWL_ERR(priv, "Current Rate is not valid\n"); |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2294 | if (lq_sta->search_better_tbl) { |
| 2295 | /* revert to active table if search table is not valid*/ |
| 2296 | tbl->lq_type = LQ_NONE; |
| 2297 | lq_sta->search_better_tbl = 0; |
| 2298 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 2299 | /* get "active" rate info */ |
| 2300 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2301 | rate = rs_update_rate_tbl(priv, ctx, lq_sta, |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2302 | tbl, index, is_green); |
| 2303 | } |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2304 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2307 | /* Get expected throughput table and history window for current rate */ |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2308 | if (!tbl->expected_tpt) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2309 | IWL_ERR(priv, "tbl->expected_tpt is NULL\n"); |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2310 | return; |
| 2311 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | |
Abbas, Mohamed | c6ec7a9 | 2009-01-20 21:33:52 -0800 | [diff] [blame] | 2313 | /* force user max rate if set by user */ |
| 2314 | if ((lq_sta->max_rate_idx != -1) && |
| 2315 | (lq_sta->max_rate_idx < index)) { |
| 2316 | index = lq_sta->max_rate_idx; |
| 2317 | update_lq = 1; |
| 2318 | window = &(tbl->win[index]); |
| 2319 | goto lq_update; |
| 2320 | } |
| 2321 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2322 | window = &(tbl->win[index]); |
| 2323 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2324 | /* |
| 2325 | * If there is not enough history to calculate actual average |
| 2326 | * throughput, keep analyzing results of more tx frames, without |
| 2327 | * changing rate or mode (bypass most of the rest of this function). |
| 2328 | * Set up new rate table in uCode only if old rate is not supported |
| 2329 | * in current association (use new rate found above). |
| 2330 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2331 | fail_count = window->counter - window->success_counter; |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2332 | if ((fail_count < IWL_RATE_MIN_FAILURE_TH) && |
| 2333 | (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2334 | IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2335 | "for index %d\n", |
| 2336 | window->success_counter, window->counter, index); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2337 | |
| 2338 | /* Can't calculate this yet; not enough history */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2339 | window->average_tpt = IWL_INVALID_VALUE; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2340 | |
| 2341 | /* Should we stay with this modulation mode, |
| 2342 | * or search for a new one? */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2343 | rs_stay_in_table(lq_sta, false); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2344 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | goto out; |
Guy Cohen | 3110bef | 2008-09-09 10:54:54 +0800 | [diff] [blame] | 2346 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2347 | /* Else we have enough samples; calculate estimate of |
| 2348 | * actual average throughput */ |
Reinette Chatre | 3d79b2a | 2010-05-03 10:55:07 -0700 | [diff] [blame] | 2349 | if (window->average_tpt != ((window->success_ratio * |
| 2350 | tbl->expected_tpt[index] + 64) / 128)) { |
| 2351 | IWL_ERR(priv, "expected_tpt should have been calculated by now\n"); |
| 2352 | window->average_tpt = ((window->success_ratio * |
| 2353 | tbl->expected_tpt[index] + 64) / 128); |
| 2354 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2355 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2356 | /* If we are searching for better modulation mode, check success. */ |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2357 | if (lq_sta->search_better_tbl && |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 2358 | (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2359 | /* If good success, continue using the "search" mode; |
| 2360 | * no need to send new link quality command, since we're |
| 2361 | * continuing to use the setup that we've been trying. */ |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2362 | if (window->average_tpt > lq_sta->last_tpt) { |
| 2363 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2364 | IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE " |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2365 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
| 2366 | window->success_ratio, |
| 2367 | window->average_tpt, |
| 2368 | lq_sta->last_tpt); |
| 2369 | |
| 2370 | if (!is_legacy(tbl->lq_type)) |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2371 | lq_sta->enable_counter = 1; |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2372 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2373 | /* Swap tables; "search" becomes "active" */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2374 | lq_sta->active_tbl = active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2375 | current_tpt = window->average_tpt; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2376 | |
| 2377 | /* Else poor success; go back to mode in "active" table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2378 | } else { |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2379 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2380 | IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE " |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2381 | "suc=%d cur-tpt=%d old-tpt=%d\n", |
| 2382 | window->success_ratio, |
| 2383 | window->average_tpt, |
| 2384 | lq_sta->last_tpt); |
| 2385 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2386 | /* Nullify "search" table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | tbl->lq_type = LQ_NONE; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2388 | |
| 2389 | /* Revert to "active" table */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2390 | active_tbl = lq_sta->active_tbl; |
| 2391 | tbl = &(lq_sta->lq_info[active_tbl]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2392 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2393 | /* Revert to "active" rate and throughput info */ |
Tomas Winkler | e7d326ac | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 2394 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2395 | current_tpt = lq_sta->last_tpt; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2396 | |
| 2397 | /* Need to set up a new rate table in uCode */ |
| 2398 | update_lq = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2400 | |
| 2401 | /* Either way, we've made a decision; modulation mode |
| 2402 | * search is done, allow rate adjustment next time. */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2403 | lq_sta->search_better_tbl = 0; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2404 | done_search = 1; /* Don't switch modes below! */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2405 | goto lq_update; |
| 2406 | } |
| 2407 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2408 | /* (Else) not in search of better modulation mode, try for better |
| 2409 | * starting rate, while staying in this mode. */ |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2410 | high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2411 | tbl->lq_type); |
| 2412 | low = high_low & 0xff; |
| 2413 | high = (high_low >> 8) & 0xff; |
| 2414 | |
Abbas, Mohamed | c6ec7a9 | 2009-01-20 21:33:52 -0800 | [diff] [blame] | 2415 | /* If user set max rate, dont allow higher than user constrain */ |
| 2416 | if ((lq_sta->max_rate_idx != -1) && |
| 2417 | (lq_sta->max_rate_idx < high)) |
| 2418 | high = IWL_RATE_INVALID; |
| 2419 | |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2420 | sr = window->success_ratio; |
| 2421 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2422 | /* Collect measured throughputs for current and adjacent rates */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2423 | current_tpt = window->average_tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2424 | if (low != IWL_RATE_INVALID) |
| 2425 | low_tpt = tbl->win[low].average_tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | if (high != IWL_RATE_INVALID) |
| 2427 | high_tpt = tbl->win[high].average_tpt; |
| 2428 | |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2429 | scale_action = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2431 | /* Too many failures, decrease rate */ |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2432 | if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2433 | IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2434 | scale_action = -1; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2435 | |
| 2436 | /* No throughput measured yet for adjacent rates; try increase. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2437 | } else if ((low_tpt == IWL_INVALID_VALUE) && |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2438 | (high_tpt == IWL_INVALID_VALUE)) { |
| 2439 | |
| 2440 | if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH) |
| 2441 | scale_action = 1; |
| 2442 | else if (low != IWL_RATE_INVALID) |
Wey-Yi Guy | 8fe7231 | 2009-03-10 14:35:10 -0700 | [diff] [blame] | 2443 | scale_action = 0; |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2444 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2445 | |
| 2446 | /* Both adjacent throughputs are measured, but neither one has better |
| 2447 | * throughput; we're using the best rate, don't change it! */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2448 | else if ((low_tpt != IWL_INVALID_VALUE) && |
| 2449 | (high_tpt != IWL_INVALID_VALUE) && |
| 2450 | (low_tpt < current_tpt) && |
| 2451 | (high_tpt < current_tpt)) |
| 2452 | scale_action = 0; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2453 | |
| 2454 | /* At least one adjacent rate's throughput is measured, |
| 2455 | * and may have better performance. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2456 | else { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2457 | /* Higher adjacent rate's throughput is measured */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2458 | if (high_tpt != IWL_INVALID_VALUE) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2459 | /* Higher rate has better throughput */ |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2460 | if (high_tpt > current_tpt && |
| 2461 | sr >= IWL_RATE_INCREASE_TH) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2462 | scale_action = 1; |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2463 | } else { |
Wey-Yi Guy | 8fe7231 | 2009-03-10 14:35:10 -0700 | [diff] [blame] | 2464 | scale_action = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2465 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2466 | |
| 2467 | /* Lower adjacent rate's throughput is measured */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | } else if (low_tpt != IWL_INVALID_VALUE) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2469 | /* Lower rate has better throughput */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | if (low_tpt > current_tpt) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2471 | IWL_DEBUG_RATE(priv, |
| 2472 | "decrease rate because of low tpt\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2473 | scale_action = -1; |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2474 | } else if (sr >= IWL_RATE_INCREASE_TH) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2475 | scale_action = 1; |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2476 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2480 | /* Sanity check; asked for decrease, but success rate or throughput |
| 2481 | * has been good at old rate. Don't change it. */ |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2482 | if ((scale_action == -1) && (low != IWL_RATE_INVALID) && |
| 2483 | ((sr > IWL_RATE_HIGH_TH) || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2484 | (current_tpt > (100 * tbl->expected_tpt[low])))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2485 | scale_action = 0; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2486 | if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type)) |
| 2487 | scale_action = -1; |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 2488 | if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2489 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) |
| 2490 | scale_action = -1; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 2491 | |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2492 | if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) && |
| 2493 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) { |
| 2494 | if (lq_sta->last_bt_traffic > priv->bt_traffic_load) { |
| 2495 | /* |
| 2496 | * don't set scale_action, don't want to scale up if |
| 2497 | * the rate scale doesn't otherwise think that is a |
| 2498 | * good idea. |
| 2499 | */ |
| 2500 | } else if (lq_sta->last_bt_traffic <= priv->bt_traffic_load) { |
| 2501 | scale_action = -1; |
| 2502 | } |
| 2503 | } |
| 2504 | lq_sta->last_bt_traffic = priv->bt_traffic_load; |
| 2505 | |
| 2506 | if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) && |
| 2507 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) { |
| 2508 | /* search for a new modulation */ |
| 2509 | rs_stay_in_table(lq_sta, true); |
| 2510 | goto lq_update; |
Johannes Berg | 290f599 | 2010-08-23 07:56:58 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2513 | switch (scale_action) { |
| 2514 | case -1: |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2515 | /* Decrease starting rate, update uCode's rate table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2516 | if (low != IWL_RATE_INVALID) { |
| 2517 | update_lq = 1; |
| 2518 | index = low; |
| 2519 | } |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 2520 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2521 | break; |
| 2522 | case 1: |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2523 | /* Increase starting rate, update uCode's rate table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2524 | if (high != IWL_RATE_INVALID) { |
| 2525 | update_lq = 1; |
| 2526 | index = high; |
| 2527 | } |
| 2528 | |
| 2529 | break; |
| 2530 | case 0: |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2531 | /* No change */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | default: |
| 2533 | break; |
| 2534 | } |
| 2535 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2536 | IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2537 | "high %d type %d\n", |
| 2538 | index, scale_action, low, high, tbl->lq_type); |
| 2539 | |
Guy Cohen | a5e8b50 | 2008-05-29 16:35:11 +0800 | [diff] [blame] | 2540 | lq_update: |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2541 | /* Replace uCode's rate table for the destination station. */ |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2542 | if (update_lq) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2543 | rate = rs_update_rate_tbl(priv, ctx, lq_sta, |
Wey-Yi Guy | e3139fe | 2009-07-24 11:13:00 -0700 | [diff] [blame] | 2544 | tbl, index, is_green); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2545 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 2546 | if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) { |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2547 | /* Should we stay with this modulation mode, |
| 2548 | * or search for a new one? */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2549 | rs_stay_in_table(lq_sta, false); |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2550 | } |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2551 | /* |
| 2552 | * Search for new modulation mode if we're: |
| 2553 | * 1) Not changing rates right now |
| 2554 | * 2) Not just finishing up a search |
| 2555 | * 3) Allowing a new search |
| 2556 | */ |
Guy Cohen | 47cfd46 | 2008-05-27 11:29:34 +0800 | [diff] [blame] | 2557 | if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2558 | /* Save current throughput to compare with "search" throughput*/ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2559 | lq_sta->last_tpt = current_tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2561 | /* Select a new "search" modulation mode to try. |
| 2562 | * If one is found, set up the new "search" table. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2563 | if (is_legacy(tbl->lq_type)) |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2564 | rs_move_legacy_other(priv, lq_sta, conf, sta, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2565 | else if (is_siso(tbl->lq_type)) |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2566 | rs_move_siso_to_other(priv, lq_sta, conf, sta, index); |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2567 | else if (is_mimo2(tbl->lq_type)) |
| 2568 | rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2569 | else |
Wey-Yi Guy | 584a0f0 | 2009-04-01 14:33:24 -0700 | [diff] [blame] | 2570 | rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2571 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2572 | /* If new "search" mode was selected, set up in uCode table */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2573 | if (lq_sta->search_better_tbl) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2574 | /* Access the "search" table, clear its history. */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2575 | tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2576 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2577 | rs_rate_scale_clear_window(&(tbl->win[i])); |
| 2578 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2579 | /* Use new "search" start rate */ |
Tomas Winkler | e7d326ac | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 2580 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2581 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2582 | IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2583 | tbl->current_rate, index); |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2584 | rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2585 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 2586 | } else |
| 2587 | done_search = 1; |
| 2588 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2589 | |
Mohamed Abbas | 447fee7 | 2009-04-20 14:37:02 -0700 | [diff] [blame] | 2590 | if (done_search && !lq_sta->stay_in_tbl) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2591 | /* If the "active" (non-search) mode was legacy, |
| 2592 | * and we've tried switching antennas, |
| 2593 | * but we haven't been able to try HT modes (not available), |
| 2594 | * stay with best antenna legacy modulation for a while |
| 2595 | * before next round of mode comparisons. */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2596 | tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Luis R. Rodriguez | de27e64 | 2008-12-23 15:58:44 -0800 | [diff] [blame] | 2597 | if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) && |
Mohamed Abbas | d6e9339 | 2009-05-08 13:44:39 -0700 | [diff] [blame] | 2598 | lq_sta->action_counter > tbl1->max_search) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2599 | IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2600 | rs_set_stay_in_table(priv, 1, lq_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2603 | /* If we're in an HT mode, and all 3 mode switch actions |
| 2604 | * have been tried and compared, stay in this best modulation |
| 2605 | * mode for a while before next round of mode comparisons. */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2606 | if (lq_sta->enable_counter && |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2607 | (lq_sta->action_counter >= tbl1->max_search) && |
| 2608 | iwl_ht_enabled(priv)) { |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 2609 | if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && |
| 2610 | (lq_sta->tx_agg_tid_en & (1 << tid)) && |
| 2611 | (tid != MAX_TID_COUNT)) { |
Wey-Yi Guy | 86b4766 | 2009-03-10 14:35:09 -0700 | [diff] [blame] | 2612 | tid_data = |
| 2613 | &priv->stations[lq_sta->lq.sta_id].tid[tid]; |
| 2614 | if (tid_data->agg.state == IWL_AGG_OFF) { |
| 2615 | IWL_DEBUG_RATE(priv, |
| 2616 | "try to aggregate tid %d\n", |
| 2617 | tid); |
| 2618 | rs_tl_turn_on_agg(priv, tid, |
| 2619 | lq_sta, sta); |
| 2620 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2621 | } |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2622 | rs_set_stay_in_table(priv, 0, lq_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2623 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | out: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2627 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2628 | i = index; |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 2629 | lq_sta->last_txrate_idx = i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2632 | /** |
| 2633 | * rs_initialize_lq - Initialize a station's hardware rate table |
| 2634 | * |
| 2635 | * The uCode's station table contains a table of fallback rates |
| 2636 | * for automatic fallback during transmission. |
| 2637 | * |
| 2638 | * NOTE: This sets up a default set of values. These will be replaced later |
| 2639 | * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of |
| 2640 | * rc80211_simple. |
| 2641 | * |
| 2642 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 2643 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 2644 | * which requires station table entry to exist). |
| 2645 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2646 | static void rs_initialize_lq(struct iwl_priv *priv, |
Ron Rindjunsky | 270243a | 2007-11-26 16:14:41 +0200 | [diff] [blame] | 2647 | struct ieee80211_conf *conf, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2648 | struct ieee80211_sta *sta, |
| 2649 | struct iwl_lq_sta *lq_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2650 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2651 | struct iwl_scale_tbl_info *tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2652 | int rate_idx; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2653 | int i; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2654 | u32 rate; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2655 | u8 use_green = rs_use_green(sta); |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2656 | u8 active_tbl = 0; |
| 2657 | u8 valid_tx_ant; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2658 | struct iwl_station_priv *sta_priv; |
| 2659 | struct iwl_rxon_context *ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2660 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2661 | if (!sta || !lq_sta) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2662 | return; |
| 2663 | |
| 2664 | sta_priv = (void *)sta->drv_priv; |
| 2665 | ctx = sta_priv->common.ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2666 | |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 2667 | i = lq_sta->last_txrate_idx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2668 | |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2669 | valid_tx_ant = priv->hw_params.valid_tx_ant; |
| 2670 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2671 | if (!lq_sta->search_better_tbl) |
| 2672 | active_tbl = lq_sta->active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2673 | else |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2674 | active_tbl = 1 - lq_sta->active_tbl; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2675 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2676 | tbl = &(lq_sta->lq_info[active_tbl]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2677 | |
| 2678 | if ((i < 0) || (i >= IWL_RATE_COUNT)) |
| 2679 | i = 0; |
| 2680 | |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 2681 | rate = iwl_rates[i].plcp; |
Winkler, Tomas | eb48dca | 2008-10-29 14:05:48 -0700 | [diff] [blame] | 2682 | tbl->ant_type = first_antenna(valid_tx_ant); |
| 2683 | rate |= tbl->ant_type << RATE_MCS_ANT_POS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2684 | |
| 2685 | if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2686 | rate |= RATE_MCS_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2687 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2688 | rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx); |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2689 | if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type)) |
| 2690 | rs_toggle_antenna(valid_tx_ant, &rate, tbl); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2692 | rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2693 | tbl->current_rate = rate; |
Guy Cohen | eecd6e5 | 2008-04-23 17:14:58 -0700 | [diff] [blame] | 2694 | rs_set_expected_tpt_table(lq_sta, tbl); |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2695 | rs_fill_link_cmd(NULL, lq_sta, rate); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2696 | priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2697 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2700 | static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta, |
| 2701 | struct ieee80211_tx_rate_control *txrc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2702 | { |
| 2703 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2704 | struct sk_buff *skb = txrc->skb; |
| 2705 | struct ieee80211_supported_band *sband = txrc->sband; |
Reinette Chatre | f875f51 | 2010-04-05 10:43:10 -0700 | [diff] [blame] | 2706 | struct iwl_priv *priv __maybe_unused = (struct iwl_priv *)priv_r; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2707 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 2708 | struct iwl_lq_sta *lq_sta = priv_sta; |
| 2709 | int rate_idx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2711 | IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2712 | |
Abbas, Mohamed | c6ec7a9 | 2009-01-20 21:33:52 -0800 | [diff] [blame] | 2713 | /* Get max rate if user set max rate */ |
| 2714 | if (lq_sta) { |
| 2715 | lq_sta->max_rate_idx = txrc->max_rate_idx; |
| 2716 | if ((sband->band == IEEE80211_BAND_5GHZ) && |
| 2717 | (lq_sta->max_rate_idx != -1)) |
| 2718 | lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE; |
| 2719 | if ((lq_sta->max_rate_idx < 0) || |
| 2720 | (lq_sta->max_rate_idx >= IWL_RATE_COUNT)) |
| 2721 | lq_sta->max_rate_idx = -1; |
| 2722 | } |
| 2723 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2724 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 2725 | if (lq_sta && !lq_sta->drv) { |
| 2726 | IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); |
| 2727 | priv_sta = NULL; |
| 2728 | } |
| 2729 | |
Gábor Stefanik | 514d65c | 2009-04-23 19:36:08 +0200 | [diff] [blame] | 2730 | /* Send management frames and NO_ACK data using lowest rate. */ |
Luis R. Rodriguez | 4c6d4f5 | 2009-07-16 10:05:41 -0700 | [diff] [blame] | 2731 | if (rate_control_send_low(sta, priv_sta, txrc)) |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2732 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 2734 | rate_idx = lq_sta->last_txrate_idx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2735 | |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2736 | if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) { |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 2737 | rate_idx -= IWL_FIRST_OFDM_RATE; |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2738 | /* 6M and 9M shared same MCS index */ |
| 2739 | rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0; |
| 2740 | if (rs_extract_rate(lq_sta->last_rate_n_flags) >= |
| 2741 | IWL_RATE_MIMO3_6M_PLCP) |
| 2742 | rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM); |
| 2743 | else if (rs_extract_rate(lq_sta->last_rate_n_flags) >= |
| 2744 | IWL_RATE_MIMO2_6M_PLCP) |
| 2745 | rate_idx = rate_idx + MCS_INDEX_PER_STREAM; |
| 2746 | info->control.rates[0].flags = IEEE80211_TX_RC_MCS; |
| 2747 | if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK) |
| 2748 | info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI; |
| 2749 | if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK) |
| 2750 | info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA; |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 2751 | if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK) |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2752 | info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 2753 | if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK) |
| 2754 | info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD; |
| 2755 | } else { |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 2756 | /* Check for invalid rates */ |
| 2757 | if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) || |
| 2758 | ((sband->band == IEEE80211_BAND_5GHZ) && |
| 2759 | (rate_idx < IWL_FIRST_OFDM_RATE))) |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2760 | rate_idx = rate_lowest_index(sband, sta); |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 2761 | /* On valid 5 GHz rate, adjust index */ |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2762 | else if (sband->band == IEEE80211_BAND_5GHZ) |
| 2763 | rate_idx -= IWL_FIRST_OFDM_RATE; |
Daniel C Halperin | 7ebaeff | 2009-08-21 13:34:20 -0700 | [diff] [blame] | 2764 | info->control.rates[0].flags = 0; |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2765 | } |
Tomas Winkler | 417f114 | 2008-11-12 13:14:06 -0800 | [diff] [blame] | 2766 | info->control.rates[0].idx = rate_idx; |
Wey-Yi Guy | a9c146b | 2009-05-22 11:01:48 -0700 | [diff] [blame] | 2767 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2770 | static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta, |
| 2771 | gfp_t gfp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2772 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2773 | struct iwl_lq_sta *lq_sta; |
Reinette Chatre | 8d9698b | 2009-10-16 14:25:55 -0700 | [diff] [blame] | 2774 | struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv; |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2775 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2776 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2777 | priv = (struct iwl_priv *)priv_rate; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2778 | IWL_DEBUG_RATE(priv, "create station rate scale window\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2779 | |
Reinette Chatre | 8d9698b | 2009-10-16 14:25:55 -0700 | [diff] [blame] | 2780 | lq_sta = &sta_priv->lq_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2782 | return lq_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2785 | /* |
| 2786 | * Called after adding a new station to initialize rate scaling |
| 2787 | */ |
| 2788 | void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2789 | { |
| 2790 | int i, j; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2791 | struct ieee80211_hw *hw = priv->hw; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2792 | struct ieee80211_conf *conf = &priv->hw->conf; |
Daniel C Halperin | 7869b0e | 2009-08-13 13:30:52 -0700 | [diff] [blame] | 2793 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2794 | struct iwl_station_priv *sta_priv; |
| 2795 | struct iwl_lq_sta *lq_sta; |
| 2796 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2797 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2798 | sta_priv = (struct iwl_station_priv *) sta->drv_priv; |
| 2799 | lq_sta = &sta_priv->lq_sta; |
| 2800 | sband = hw->wiphy->bands[conf->channel->band]; |
| 2801 | |
| 2802 | |
| 2803 | lq_sta->lq.sta_id = sta_id; |
Reinette Chatre | 5ad13f8 | 2009-10-30 14:36:14 -0700 | [diff] [blame] | 2804 | |
| 2805 | for (j = 0; j < LQ_SIZE; j++) |
| 2806 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2807 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); |
| 2808 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2809 | lq_sta->flush_timer = 0; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2810 | lq_sta->supp_rates = sta->supp_rates[sband->band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | for (j = 0; j < LQ_SIZE; j++) |
| 2812 | for (i = 0; i < IWL_RATE_COUNT; i++) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2813 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2814 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 2815 | IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n", |
| 2816 | sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
| 2818 | * the lowest or the highest rate.. Could consider using RSSI from |
| 2819 | * previous packets? Need to have IEEE 802.1X auth succeed immediately |
| 2820 | * after assoc.. */ |
| 2821 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2822 | lq_sta->is_dup = 0; |
Abbas, Mohamed | c6ec7a9 | 2009-01-20 21:33:52 -0800 | [diff] [blame] | 2823 | lq_sta->max_rate_idx = -1; |
Abbas, Mohamed | 7d049e5 | 2009-01-20 21:33:53 -0800 | [diff] [blame] | 2824 | lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 2825 | lq_sta->is_green = rs_use_green(sta); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2826 | lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2827 | lq_sta->band = priv->band; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2828 | /* |
| 2829 | * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), |
| 2830 | * supp_rates[] does not; shift to convert format, force 9 MBits off. |
| 2831 | */ |
Daniel C Halperin | 7869b0e | 2009-08-13 13:30:52 -0700 | [diff] [blame] | 2832 | lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1; |
| 2833 | lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2834 | lq_sta->active_siso_rate &= ~((u16)0x2); |
| 2835 | lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2837 | /* Same here */ |
Daniel C Halperin | 7869b0e | 2009-08-13 13:30:52 -0700 | [diff] [blame] | 2838 | lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1; |
| 2839 | lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2840 | lq_sta->active_mimo2_rate &= ~((u16)0x2); |
| 2841 | lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE; |
| 2842 | |
Daniel C Halperin | 7869b0e | 2009-08-13 13:30:52 -0700 | [diff] [blame] | 2843 | lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1; |
| 2844 | lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2845 | lq_sta->active_mimo3_rate &= ~((u16)0x2); |
| 2846 | lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE; |
| 2847 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2848 | IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2849 | lq_sta->active_siso_rate, |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2850 | lq_sta->active_mimo2_rate, |
| 2851 | lq_sta->active_mimo3_rate); |
| 2852 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2853 | /* These values will be overridden later */ |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 2854 | lq_sta->lq.general_params.single_stream_ant_msk = |
| 2855 | first_antenna(priv->hw_params.valid_tx_ant); |
| 2856 | lq_sta->lq.general_params.dual_stream_ant_msk = |
| 2857 | priv->hw_params.valid_tx_ant & |
| 2858 | ~first_antenna(priv->hw_params.valid_tx_ant); |
| 2859 | if (!lq_sta->lq.general_params.dual_stream_ant_msk) { |
| 2860 | lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB; |
| 2861 | } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { |
| 2862 | lq_sta->lq.general_params.dual_stream_ant_msk = |
| 2863 | priv->hw_params.valid_tx_ant; |
| 2864 | } |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2865 | |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 2866 | /* as default allow aggregation for all tids */ |
| 2867 | lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2868 | lq_sta->drv = priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2869 | |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 2870 | /* Set last_txrate_idx to lowest rate */ |
| 2871 | lq_sta->last_txrate_idx = rate_lowest_index(sband, sta); |
| 2872 | if (sband->band == IEEE80211_BAND_5GHZ) |
| 2873 | lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 2874 | lq_sta->is_agg = 0; |
Mohamed Abbas | d5e4903 | 2008-12-12 08:22:15 -0800 | [diff] [blame] | 2875 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2876 | rs_initialize_lq(priv, conf, sta, lq_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 2879 | static void rs_fill_link_cmd(struct iwl_priv *priv, |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2880 | struct iwl_lq_sta *lq_sta, u32 new_rate) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 2882 | struct iwl_scale_tbl_info tbl_type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2883 | int index = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | int rate_idx; |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2885 | int repeat_rate = 0; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2886 | u8 ant_toggle_cnt = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | u8 use_ht_possible = 1; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2888 | u8 valid_tx_ant = 0; |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2889 | struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2890 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2891 | /* Override starting rate (index 0) if needed for debug purposes */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2892 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 2893 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2894 | /* Interpret new_rate (rate_n_flags) */ |
| 2895 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2896 | &tbl_type, &rate_idx); |
| 2897 | |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2898 | if (priv && priv->bt_full_concurrent) { |
| 2899 | /* 1x1 only */ |
| 2900 | tbl_type.ant_type = |
| 2901 | first_antenna(priv->hw_params.valid_tx_ant); |
| 2902 | } |
| 2903 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2904 | /* How many times should we repeat the initial rate? */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2905 | if (is_legacy(tbl_type.lq_type)) { |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2906 | ant_toggle_cnt = 1; |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2907 | repeat_rate = IWL_NUMBER_TRY; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2908 | } else { |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2909 | repeat_rate = IWL_HT_NUMBER_TRY; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2910 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2911 | |
| 2912 | lq_cmd->general_params.mimo_delimiter = |
| 2913 | is_mimo(tbl_type.lq_type) ? 1 : 0; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2914 | |
| 2915 | /* Fill 1st table entry (index 0) */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2916 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2918 | if (num_of_ant(tbl_type.ant_type) == 1) { |
| 2919 | lq_cmd->general_params.single_stream_ant_msk = |
| 2920 | tbl_type.ant_type; |
| 2921 | } else if (num_of_ant(tbl_type.ant_type) == 2) { |
| 2922 | lq_cmd->general_params.dual_stream_ant_msk = |
| 2923 | tbl_type.ant_type; |
| 2924 | } /* otherwise we don't modify the existing value */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2925 | |
| 2926 | index++; |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2927 | repeat_rate--; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 2928 | if (priv) { |
| 2929 | if (priv->bt_full_concurrent) |
| 2930 | valid_tx_ant = ANT_A; |
| 2931 | else |
| 2932 | valid_tx_ant = priv->hw_params.valid_tx_ant; |
| 2933 | } |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2934 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2935 | /* Fill rest of rate table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2936 | while (index < LINK_QUAL_MAX_RETRY_NUM) { |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2937 | /* Repeat initial/next rate. |
| 2938 | * For legacy IWL_NUMBER_TRY == 1, this loop will not execute. |
| 2939 | * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2940 | while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | if (is_legacy(tbl_type.lq_type)) { |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2942 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) |
| 2943 | ant_toggle_cnt++; |
| 2944 | else if (priv && |
| 2945 | rs_toggle_antenna(valid_tx_ant, |
| 2946 | &new_rate, &tbl_type)) |
| 2947 | ant_toggle_cnt = 1; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2948 | } |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 2949 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2950 | /* Override next rate if needed for debug purposes */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2951 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2952 | |
| 2953 | /* Fill next table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2954 | lq_cmd->rs_table[index].rate_n_flags = |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2955 | cpu_to_le32(new_rate); |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2956 | repeat_rate--; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2957 | index++; |
| 2958 | } |
| 2959 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2960 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2961 | &rate_idx); |
| 2962 | |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2963 | if (priv && priv->bt_full_concurrent) { |
| 2964 | /* 1x1 only */ |
| 2965 | tbl_type.ant_type = |
| 2966 | first_antenna(priv->hw_params.valid_tx_ant); |
| 2967 | } |
| 2968 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2969 | /* Indicate to uCode which entries might be MIMO. |
| 2970 | * If initial rate was MIMO, this will finally end up |
| 2971 | * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | if (is_mimo(tbl_type.lq_type)) |
| 2973 | lq_cmd->general_params.mimo_delimiter = index; |
| 2974 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2975 | /* Get next rate */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 2976 | new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, |
| 2977 | use_ht_possible); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2978 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2979 | /* How many times should we repeat the next rate? */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2980 | if (is_legacy(tbl_type.lq_type)) { |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2981 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) |
| 2982 | ant_toggle_cnt++; |
| 2983 | else if (priv && |
| 2984 | rs_toggle_antenna(valid_tx_ant, |
| 2985 | &new_rate, &tbl_type)) |
| 2986 | ant_toggle_cnt = 1; |
| 2987 | |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2988 | repeat_rate = IWL_NUMBER_TRY; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2989 | } else { |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 2990 | repeat_rate = IWL_HT_NUMBER_TRY; |
Guy Cohen | aade00c | 2008-04-23 17:14:59 -0700 | [diff] [blame] | 2991 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2992 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2993 | /* Don't allow HT rates after next pass. |
| 2994 | * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2995 | use_ht_possible = 0; |
| 2996 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2997 | /* Override next rate if needed for debug purposes */ |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 2998 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 2999 | |
| 3000 | /* Fill next table entry */ |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3001 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3002 | |
| 3003 | index++; |
Zhu Yi | 1b696de | 2007-09-27 11:27:41 +0800 | [diff] [blame] | 3004 | repeat_rate--; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Wey-Yi Guy | 4d80d72 | 2009-10-02 13:44:01 -0700 | [diff] [blame] | 3007 | lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Wey-Yi Guy | 13c33a0 | 2009-06-03 11:44:11 -0700 | [diff] [blame] | 3008 | lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
Wey-Yi Guy | 7469701 | 2010-07-28 09:18:54 -0700 | [diff] [blame] | 3009 | |
Wey-Yi Guy | 13c33a0 | 2009-06-03 11:44:11 -0700 | [diff] [blame] | 3010 | lq_cmd->agg_params.agg_time_limit = |
| 3011 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
Wey-Yi Guy | 7469701 | 2010-07-28 09:18:54 -0700 | [diff] [blame] | 3012 | /* |
| 3013 | * overwrite if needed, pass aggregation time limit |
| 3014 | * to uCode in uSec |
| 3015 | */ |
Wey-Yi Guy | 7cb1b08 | 2010-10-06 08:10:00 -0700 | [diff] [blame] | 3016 | if (priv && priv->cfg->bt_params && |
| 3017 | priv->cfg->bt_params->agg_time_limit && |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame^] | 3018 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) |
Wey-Yi Guy | 7469701 | 2010-07-28 09:18:54 -0700 | [diff] [blame] | 3019 | lq_cmd->agg_params.agg_time_limit = |
Wey-Yi Guy | 7cb1b08 | 2010-10-06 08:10:00 -0700 | [diff] [blame] | 3020 | cpu_to_le16(priv->cfg->bt_params->agg_time_limit); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3023 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3024 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3025 | return hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3026 | } |
| 3027 | /* rate scale requires free function to be implemented */ |
| 3028 | static void rs_free(void *priv_rate) |
| 3029 | { |
| 3030 | return; |
| 3031 | } |
| 3032 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3033 | static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta, |
| 3034 | void *priv_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3035 | { |
Rami Rosen | 45527c2 | 2008-10-07 09:50:01 +0200 | [diff] [blame] | 3036 | struct iwl_priv *priv __maybe_unused = priv_r; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3037 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3038 | IWL_DEBUG_RATE(priv, "enter\n"); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3039 | IWL_DEBUG_RATE(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | |
Zhu Yi | 93dc646 | 2007-09-27 11:27:37 +0800 | [diff] [blame] | 3043 | #ifdef CONFIG_MAC80211_DEBUGFS |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3044 | static int open_file_generic(struct inode *inode, struct file *file) |
| 3045 | { |
| 3046 | file->private_data = inode->i_private; |
| 3047 | return 0; |
| 3048 | } |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3049 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, |
| 3050 | u32 *rate_n_flags, int index) |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3051 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3052 | struct iwl_priv *priv; |
Wey-Yi Guy | 3c4955f | 2009-03-10 14:35:12 -0700 | [diff] [blame] | 3053 | u8 valid_tx_ant; |
| 3054 | u8 ant_sel_tx; |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3055 | |
| 3056 | priv = lq_sta->drv; |
Wey-Yi Guy | 3c4955f | 2009-03-10 14:35:12 -0700 | [diff] [blame] | 3057 | valid_tx_ant = priv->hw_params.valid_tx_ant; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3058 | if (lq_sta->dbg_fixed_rate) { |
Wey-Yi Guy | 3c4955f | 2009-03-10 14:35:12 -0700 | [diff] [blame] | 3059 | ant_sel_tx = |
| 3060 | ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK) |
| 3061 | >> RATE_MCS_ANT_POS); |
| 3062 | if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3063 | *rate_n_flags = lq_sta->dbg_fixed_rate; |
Wey-Yi Guy | 3c4955f | 2009-03-10 14:35:12 -0700 | [diff] [blame] | 3064 | IWL_DEBUG_RATE(priv, "Fixed rate ON\n"); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3065 | } else { |
Wey-Yi Guy | 3c4955f | 2009-03-10 14:35:12 -0700 | [diff] [blame] | 3066 | lq_sta->dbg_fixed_rate = 0; |
| 3067 | IWL_ERR(priv, |
| 3068 | "Invalid antenna selection 0x%X, Valid is 0x%X\n", |
| 3069 | ant_sel_tx, valid_tx_ant); |
| 3070 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3071 | } |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3072 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3073 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3074 | } |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, |
| 3078 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 3079 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3080 | struct iwl_lq_sta *lq_sta = file->private_data; |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3081 | struct iwl_priv *priv; |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3082 | char buf[64]; |
| 3083 | int buf_size; |
| 3084 | u32 parsed_rate; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3085 | struct iwl_station_priv *sta_priv = |
| 3086 | container_of(lq_sta, struct iwl_station_priv, lq_sta); |
| 3087 | struct iwl_rxon_context *ctx = sta_priv->common.ctx; |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3088 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3089 | priv = lq_sta->drv; |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3090 | memset(buf, 0, sizeof(buf)); |
| 3091 | buf_size = min(count, sizeof(buf) - 1); |
| 3092 | if (copy_from_user(buf, user_buf, buf_size)) |
| 3093 | return -EFAULT; |
| 3094 | |
| 3095 | if (sscanf(buf, "%x", &parsed_rate) == 1) |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3096 | lq_sta->dbg_fixed_rate = parsed_rate; |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3097 | else |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3098 | lq_sta->dbg_fixed_rate = 0; |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3099 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3100 | lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ |
| 3101 | lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 3102 | lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 3103 | lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3104 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3105 | IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3106 | lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3107 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3108 | if (lq_sta->dbg_fixed_rate) { |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 3109 | rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3110 | iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC, |
| 3111 | false); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | return count; |
| 3115 | } |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3116 | |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3117 | static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, |
| 3118 | char __user *user_buf, size_t count, loff_t *ppos) |
| 3119 | { |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3120 | char *buff; |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3121 | int desc = 0; |
| 3122 | int i = 0; |
Wey-Yi Guy | 12b9681 | 2009-04-08 11:39:27 -0700 | [diff] [blame] | 3123 | int index = 0; |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3124 | ssize_t ret; |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3125 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3126 | struct iwl_lq_sta *lq_sta = file->private_data; |
Wey-Yi Guy | d8ae4f5 | 2009-03-10 14:35:07 -0700 | [diff] [blame] | 3127 | struct iwl_priv *priv; |
Wey-Yi Guy | adb7b5e | 2009-03-10 14:35:08 -0700 | [diff] [blame] | 3128 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3129 | |
Wey-Yi Guy | d8ae4f5 | 2009-03-10 14:35:07 -0700 | [diff] [blame] | 3130 | priv = lq_sta->drv; |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3131 | buff = kmalloc(1024, GFP_KERNEL); |
| 3132 | if (!buff) |
| 3133 | return -ENOMEM; |
| 3134 | |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3135 | desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3136 | desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3137 | lq_sta->total_failed, lq_sta->total_success, |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3138 | lq_sta->active_legacy_rate); |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3139 | desc += sprintf(buff+desc, "fixed rate 0x%X\n", |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3140 | lq_sta->dbg_fixed_rate); |
Wey-Yi Guy | d8ae4f5 | 2009-03-10 14:35:07 -0700 | [diff] [blame] | 3141 | desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", |
| 3142 | (priv->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "", |
| 3143 | (priv->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "", |
| 3144 | (priv->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : ""); |
Wey-Yi Guy | adb7b5e | 2009-03-10 14:35:08 -0700 | [diff] [blame] | 3145 | desc += sprintf(buff+desc, "lq type %s\n", |
| 3146 | (is_legacy(tbl->lq_type)) ? "legacy" : "HT"); |
| 3147 | if (is_Ht(tbl->lq_type)) { |
| 3148 | desc += sprintf(buff+desc, " %s", |
| 3149 | (is_siso(tbl->lq_type)) ? "SISO" : |
| 3150 | ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3")); |
| 3151 | desc += sprintf(buff+desc, " %s", |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 3152 | (tbl->is_ht40) ? "40MHz" : "20MHz"); |
Daniel C Halperin | e3949d6 | 2009-09-17 10:43:50 -0700 | [diff] [blame] | 3153 | desc += sprintf(buff+desc, " %s %s %s\n", (tbl->is_SGI) ? "SGI" : "", |
| 3154 | (lq_sta->is_green) ? "GF enabled" : "", |
| 3155 | (lq_sta->is_agg) ? "AGG on" : ""); |
Wey-Yi Guy | adb7b5e | 2009-03-10 14:35:08 -0700 | [diff] [blame] | 3156 | } |
Wey-Yi Guy | 12b9681 | 2009-04-08 11:39:27 -0700 | [diff] [blame] | 3157 | desc += sprintf(buff+desc, "last tx rate=0x%X\n", |
| 3158 | lq_sta->last_rate_n_flags); |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3159 | desc += sprintf(buff+desc, "general:" |
| 3160 | "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3161 | lq_sta->lq.general_params.flags, |
| 3162 | lq_sta->lq.general_params.mimo_delimiter, |
| 3163 | lq_sta->lq.general_params.single_stream_ant_msk, |
| 3164 | lq_sta->lq.general_params.dual_stream_ant_msk); |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3165 | |
| 3166 | desc += sprintf(buff+desc, "agg:" |
| 3167 | "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3168 | le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit), |
| 3169 | lq_sta->lq.agg_params.agg_dis_start_th, |
| 3170 | lq_sta->lq.agg_params.agg_frame_cnt_limit); |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3171 | |
| 3172 | desc += sprintf(buff+desc, |
| 3173 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3174 | lq_sta->lq.general_params.start_rate_index[0], |
| 3175 | lq_sta->lq.general_params.start_rate_index[1], |
| 3176 | lq_sta->lq.general_params.start_rate_index[2], |
| 3177 | lq_sta->lq.general_params.start_rate_index[3]); |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3178 | |
Wey-Yi Guy | 12b9681 | 2009-04-08 11:39:27 -0700 | [diff] [blame] | 3179 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 3180 | index = iwl_hwrate_to_plcp_idx( |
| 3181 | le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); |
| 3182 | if (is_legacy(tbl->lq_type)) { |
| 3183 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n", |
| 3184 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), |
| 3185 | iwl_rate_mcs[index].mbps); |
| 3186 | } else { |
| 3187 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n", |
| 3188 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), |
| 3189 | iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs); |
| 3190 | } |
| 3191 | } |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3192 | |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3193 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 3194 | kfree(buff); |
| 3195 | return ret; |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { |
Zhu Yi | 98d7e09 | 2007-09-27 11:27:42 +0800 | [diff] [blame] | 3199 | .write = rs_sta_dbgfs_scale_table_write, |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3200 | .read = rs_sta_dbgfs_scale_table_read, |
| 3201 | .open = open_file_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 3202 | .llseek = default_llseek, |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3203 | }; |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3204 | static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, |
| 3205 | char __user *user_buf, size_t count, loff_t *ppos) |
| 3206 | { |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3207 | char *buff; |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3208 | int desc = 0; |
| 3209 | int i, j; |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3210 | ssize_t ret; |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3211 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3212 | struct iwl_lq_sta *lq_sta = file->private_data; |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3213 | |
| 3214 | buff = kmalloc(1024, GFP_KERNEL); |
| 3215 | if (!buff) |
| 3216 | return -ENOMEM; |
| 3217 | |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3218 | for (i = 0; i < LQ_SIZE; i++) { |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 3219 | desc += sprintf(buff+desc, |
| 3220 | "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n" |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3221 | "rate=0x%X\n", |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 3222 | lq_sta->active_tbl == i ? "*" : "x", |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3223 | lq_sta->lq_info[i].lq_type, |
| 3224 | lq_sta->lq_info[i].is_SGI, |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 3225 | lq_sta->lq_info[i].is_ht40, |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3226 | lq_sta->lq_info[i].is_dup, |
Wey-Yi Guy | 2681b20 | 2009-05-21 13:44:22 -0700 | [diff] [blame] | 3227 | lq_sta->is_green, |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 3228 | lq_sta->lq_info[i].current_rate); |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3229 | for (j = 0; j < IWL_RATE_COUNT; j++) { |
| 3230 | desc += sprintf(buff+desc, |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3231 | "counter=%d success=%d %%=%d\n", |
| 3232 | lq_sta->lq_info[i].win[j].counter, |
| 3233 | lq_sta->lq_info[i].win[j].success_counter, |
| 3234 | lq_sta->lq_info[i].win[j].success_ratio); |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3235 | } |
| 3236 | } |
Frank Seidel | a412c80 | 2009-03-01 20:25:38 +0100 | [diff] [blame] | 3237 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 3238 | kfree(buff); |
| 3239 | return ret; |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
| 3243 | .read = rs_sta_dbgfs_stats_table_read, |
| 3244 | .open = open_file_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 3245 | .llseek = default_llseek, |
Zhu Yi | 0209dc1 | 2007-09-27 11:27:43 +0800 | [diff] [blame] | 3246 | }; |
Zhu Yi | 5ae212c | 2007-09-27 11:27:38 +0800 | [diff] [blame] | 3247 | |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3248 | static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file, |
| 3249 | char __user *user_buf, size_t count, loff_t *ppos) |
| 3250 | { |
| 3251 | char buff[120]; |
| 3252 | int desc = 0; |
| 3253 | ssize_t ret; |
| 3254 | |
| 3255 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 3256 | struct iwl_priv *priv; |
| 3257 | struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl]; |
| 3258 | |
| 3259 | priv = lq_sta->drv; |
| 3260 | |
| 3261 | if (is_Ht(tbl->lq_type)) |
| 3262 | desc += sprintf(buff+desc, |
| 3263 | "Bit Rate= %d Mb/s\n", |
| 3264 | tbl->expected_tpt[lq_sta->last_txrate_idx]); |
| 3265 | else |
| 3266 | desc += sprintf(buff+desc, |
| 3267 | "Bit Rate= %d Mb/s\n", |
| 3268 | iwl_rates[lq_sta->last_txrate_idx].ieee >> 1); |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3269 | |
| 3270 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 3271 | return ret; |
| 3272 | } |
| 3273 | |
| 3274 | static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { |
| 3275 | .read = rs_sta_dbgfs_rate_scale_data_read, |
| 3276 | .open = open_file_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 3277 | .llseek = default_llseek, |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3278 | }; |
| 3279 | |
Zhu Yi | 93dc646 | 2007-09-27 11:27:37 +0800 | [diff] [blame] | 3280 | static void rs_add_debugfs(void *priv, void *priv_sta, |
| 3281 | struct dentry *dir) |
| 3282 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3283 | struct iwl_lq_sta *lq_sta = priv_sta; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3284 | lq_sta->rs_sta_dbgfs_scale_table_file = |
Wey-Yi Guy | 43e8511 | 2009-11-20 12:04:58 -0800 | [diff] [blame] | 3285 | debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir, |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3286 | lq_sta, &rs_sta_dbgfs_scale_table_ops); |
| 3287 | lq_sta->rs_sta_dbgfs_stats_table_file = |
Wey-Yi Guy | 43e8511 | 2009-11-20 12:04:58 -0800 | [diff] [blame] | 3288 | debugfs_create_file("rate_stats_table", S_IRUSR, dir, |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3289 | lq_sta, &rs_sta_dbgfs_stats_table_ops); |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3290 | lq_sta->rs_sta_dbgfs_rate_scale_data_file = |
Wey-Yi Guy | 43e8511 | 2009-11-20 12:04:58 -0800 | [diff] [blame] | 3291 | debugfs_create_file("rate_scale_data", S_IRUSR, dir, |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3292 | lq_sta, &rs_sta_dbgfs_rate_scale_data_ops); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 3293 | lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = |
Wey-Yi Guy | 43e8511 | 2009-11-20 12:04:58 -0800 | [diff] [blame] | 3294 | debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir, |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 3295 | &lq_sta->tx_agg_tid_en); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 3296 | |
Zhu Yi | 93dc646 | 2007-09-27 11:27:37 +0800 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | static void rs_remove_debugfs(void *priv, void *priv_sta) |
| 3300 | { |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3301 | struct iwl_lq_sta *lq_sta = priv_sta; |
Tomas Winkler | c33104f | 2008-01-14 17:46:21 -0800 | [diff] [blame] | 3302 | debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); |
| 3303 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); |
Wey-Yi Guy | 3816745 | 2009-05-08 13:44:43 -0700 | [diff] [blame] | 3304 | debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file); |
Ron Rindjunsky | 0c11b4d | 2008-01-28 14:07:26 +0200 | [diff] [blame] | 3305 | debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); |
Zhu Yi | 93dc646 | 2007-09-27 11:27:37 +0800 | [diff] [blame] | 3306 | } |
| 3307 | #endif |
| 3308 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3309 | /* |
| 3310 | * Initialization of rate scaling information is done by driver after |
| 3311 | * the station is added. Since mac80211 calls this function before a |
| 3312 | * station is added we ignore it. |
| 3313 | */ |
| 3314 | static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband, |
| 3315 | struct ieee80211_sta *sta, void *priv_sta) |
| 3316 | { |
| 3317 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | static struct rate_control_ops rs_ops = { |
| 3319 | .module = NULL, |
| 3320 | .name = RS_NAME, |
| 3321 | .tx_status = rs_tx_status, |
| 3322 | .get_rate = rs_get_rate, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3323 | .rate_init = rs_rate_init_stub, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3324 | .alloc = rs_alloc, |
| 3325 | .free = rs_free, |
| 3326 | .alloc_sta = rs_alloc_sta, |
| 3327 | .free_sta = rs_free_sta, |
Zhu Yi | 93dc646 | 2007-09-27 11:27:37 +0800 | [diff] [blame] | 3328 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 3329 | .add_sta_debugfs = rs_add_debugfs, |
| 3330 | .remove_sta_debugfs = rs_remove_debugfs, |
| 3331 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3332 | }; |
| 3333 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3334 | int iwlagn_rate_control_register(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3335 | { |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 3336 | return ieee80211_rate_control_register(&rs_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 3339 | void iwlagn_rate_control_unregister(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3340 | { |
| 3341 | ieee80211_rate_control_unregister(&rs_ops); |
| 3342 | } |
| 3343 | |