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