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