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