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