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