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