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