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