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