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