Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/wireless.h> |
| 31 | #include <net/mac80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/delay.h> |
| 36 | |
| 37 | #include <linux/workqueue.h> |
| 38 | |
Christoph Hellwig | 5d08cd1 | 2007-10-25 17:15:50 +0800 | [diff] [blame] | 39 | #include "iwl-3945.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | |
| 41 | #define RS_NAME "iwl-3945-rs" |
| 42 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 43 | struct iwl3945_rate_scale_data { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 44 | u64 data; |
| 45 | s32 success_counter; |
| 46 | s32 success_ratio; |
| 47 | s32 counter; |
| 48 | s32 average_tpt; |
| 49 | unsigned long stamp; |
| 50 | }; |
| 51 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 52 | struct iwl3945_rs_sta { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 53 | spinlock_t lock; |
| 54 | s32 *expected_tpt; |
| 55 | unsigned long last_partial_flush; |
| 56 | unsigned long last_flush; |
| 57 | u32 flush_time; |
| 58 | u32 last_tx_packets; |
| 59 | u32 tx_packets; |
| 60 | u8 tgg; |
| 61 | u8 flush_pending; |
| 62 | u8 start_rate; |
| 63 | u8 ibss_sta_added; |
| 64 | struct timer_list rate_scale_flush; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 65 | struct iwl3945_rate_scale_data win[IWL_RATE_COUNT]; |
Abbas, Mohamed | c30e30e | 2008-12-02 12:14:02 -0800 | [diff] [blame] | 66 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 67 | struct dentry *rs_sta_dbgfs_stats_table_file; |
| 68 | #endif |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 69 | |
| 70 | /* used to be in sta_info */ |
| 71 | int last_txrate_idx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 74 | static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = { |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 75 | 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 78 | static s32 iwl3945_expected_tpt_g_prot[IWL_RATE_COUNT] = { |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 79 | 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 82 | static s32 iwl3945_expected_tpt_a[IWL_RATE_COUNT] = { |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 83 | 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 86 | static s32 iwl3945_expected_tpt_b[IWL_RATE_COUNT] = { |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 87 | 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 90 | struct iwl3945_tpt_entry { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 91 | s8 min_rssi; |
| 92 | u8 index; |
| 93 | }; |
| 94 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 95 | static struct iwl3945_tpt_entry iwl3945_tpt_table_a[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 96 | {-60, IWL_RATE_54M_INDEX}, |
| 97 | {-64, IWL_RATE_48M_INDEX}, |
| 98 | {-72, IWL_RATE_36M_INDEX}, |
| 99 | {-80, IWL_RATE_24M_INDEX}, |
| 100 | {-84, IWL_RATE_18M_INDEX}, |
| 101 | {-85, IWL_RATE_12M_INDEX}, |
| 102 | {-87, IWL_RATE_9M_INDEX}, |
| 103 | {-89, IWL_RATE_6M_INDEX} |
| 104 | }; |
| 105 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 106 | static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 107 | {-60, IWL_RATE_54M_INDEX}, |
| 108 | {-64, IWL_RATE_48M_INDEX}, |
| 109 | {-68, IWL_RATE_36M_INDEX}, |
| 110 | {-80, IWL_RATE_24M_INDEX}, |
| 111 | {-84, IWL_RATE_18M_INDEX}, |
| 112 | {-85, IWL_RATE_12M_INDEX}, |
| 113 | {-86, IWL_RATE_11M_INDEX}, |
| 114 | {-88, IWL_RATE_5M_INDEX}, |
| 115 | {-90, IWL_RATE_2M_INDEX}, |
| 116 | {-92, IWL_RATE_1M_INDEX} |
| 117 | }; |
| 118 | |
| 119 | #define IWL_RATE_MAX_WINDOW 62 |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 120 | #define IWL_RATE_FLUSH (3*HZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 121 | #define IWL_RATE_WIN_FLUSH (HZ/2) |
| 122 | #define IWL_RATE_HIGH_TH 11520 |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 123 | #define IWL_SUCCESS_UP_TH 8960 |
| 124 | #define IWL_SUCCESS_DOWN_TH 10880 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 125 | #define IWL_RATE_MIN_FAILURE_TH 8 |
| 126 | #define IWL_RATE_MIN_SUCCESS_TH 8 |
| 127 | #define IWL_RATE_DECREASE_TH 1920 |
| 128 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 129 | static u8 iwl3945_get_rate_index_by_rssi(s32 rssi, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 130 | { |
| 131 | u32 index = 0; |
| 132 | u32 table_size = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 133 | struct iwl3945_tpt_entry *tpt_table = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 134 | |
| 135 | if ((rssi < IWL_MIN_RSSI_VAL) || (rssi > IWL_MAX_RSSI_VAL)) |
| 136 | rssi = IWL_MIN_RSSI_VAL; |
| 137 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 138 | switch (band) { |
| 139 | case IEEE80211_BAND_2GHZ: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 140 | tpt_table = iwl3945_tpt_table_g; |
| 141 | table_size = ARRAY_SIZE(iwl3945_tpt_table_g); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 142 | break; |
| 143 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 144 | case IEEE80211_BAND_5GHZ: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 145 | tpt_table = iwl3945_tpt_table_a; |
| 146 | table_size = ARRAY_SIZE(iwl3945_tpt_table_a); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | break; |
| 148 | |
| 149 | default: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 150 | BUG(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | |
| 154 | while ((index < table_size) && (rssi < tpt_table[index].min_rssi)) |
| 155 | index++; |
| 156 | |
| 157 | index = min(index, (table_size - 1)); |
| 158 | |
| 159 | return tpt_table[index].index; |
| 160 | } |
| 161 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 162 | static void iwl3945_clear_window(struct iwl3945_rate_scale_data *window) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 163 | { |
| 164 | window->data = 0; |
| 165 | window->success_counter = 0; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 166 | window->success_ratio = -1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 167 | window->counter = 0; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 168 | window->average_tpt = IWL_INV_TPT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 169 | window->stamp = 0; |
| 170 | } |
| 171 | |
| 172 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 173 | * iwl3945_rate_scale_flush_windows - flush out the rate scale windows |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 174 | * |
| 175 | * Returns the number of windows that have gathered data but were |
| 176 | * not flushed. If there were any that were not flushed, then |
| 177 | * reschedule the rate flushing routine. |
| 178 | */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 179 | static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | { |
| 181 | int unflushed = 0; |
| 182 | int i; |
| 183 | unsigned long flags; |
| 184 | |
| 185 | /* |
| 186 | * For each rate, if we have collected data on that rate |
| 187 | * and it has been more than IWL_RATE_WIN_FLUSH |
| 188 | * since we flushed, clear out the gathered statistics |
| 189 | */ |
| 190 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 191 | if (!rs_sta->win[i].counter) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 192 | continue; |
| 193 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 194 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 195 | if (time_after(jiffies, rs_sta->win[i].stamp + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 196 | IWL_RATE_WIN_FLUSH)) { |
| 197 | IWL_DEBUG_RATE("flushing %d samples of rate " |
| 198 | "index %d\n", |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 199 | rs_sta->win[i].counter, i); |
| 200 | iwl3945_clear_window(&rs_sta->win[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 201 | } else |
| 202 | unflushed++; |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 203 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | return unflushed; |
| 207 | } |
| 208 | |
| 209 | #define IWL_RATE_FLUSH_MAX 5000 /* msec */ |
| 210 | #define IWL_RATE_FLUSH_MIN 50 /* msec */ |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 211 | #define IWL_AVERAGE_PACKETS 1500 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 212 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 213 | static void iwl3945_bg_rate_scale_flush(unsigned long data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 214 | { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 215 | struct iwl3945_rs_sta *rs_sta = (void *)data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 216 | int unflushed = 0; |
| 217 | unsigned long flags; |
| 218 | u32 packet_count, duration, pps; |
| 219 | |
| 220 | IWL_DEBUG_RATE("enter\n"); |
| 221 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 222 | unflushed = iwl3945_rate_scale_flush_windows(rs_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 223 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 224 | spin_lock_irqsave(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 225 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 226 | /* Number of packets Rx'd since last time this timer ran */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 227 | packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 228 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 229 | rs_sta->last_tx_packets = rs_sta->tx_packets + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 230 | |
| 231 | if (unflushed) { |
| 232 | duration = |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 233 | jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 234 | |
| 235 | IWL_DEBUG_RATE("Tx'd %d packets in %dms\n", |
| 236 | packet_count, duration); |
| 237 | |
| 238 | /* Determine packets per second */ |
| 239 | if (duration) |
| 240 | pps = (packet_count * 1000) / duration; |
| 241 | else |
| 242 | pps = 0; |
| 243 | |
| 244 | if (pps) { |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 245 | duration = (IWL_AVERAGE_PACKETS * 1000) / pps; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 246 | if (duration < IWL_RATE_FLUSH_MIN) |
| 247 | duration = IWL_RATE_FLUSH_MIN; |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 248 | else if (duration > IWL_RATE_FLUSH_MAX) |
| 249 | duration = IWL_RATE_FLUSH_MAX; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 250 | } else |
| 251 | duration = IWL_RATE_FLUSH_MAX; |
| 252 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 253 | rs_sta->flush_time = msecs_to_jiffies(duration); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 254 | |
| 255 | IWL_DEBUG_RATE("new flush period: %d msec ave %d\n", |
| 256 | duration, packet_count); |
| 257 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 258 | mod_timer(&rs_sta->rate_scale_flush, jiffies + |
| 259 | rs_sta->flush_time); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 260 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 261 | rs_sta->last_partial_flush = jiffies; |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 262 | } else { |
| 263 | rs_sta->flush_time = IWL_RATE_FLUSH; |
| 264 | rs_sta->flush_pending = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 265 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | /* If there weren't any unflushed entries, we don't schedule the timer |
| 267 | * to run again */ |
| 268 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 269 | rs_sta->last_flush = jiffies; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 271 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 272 | |
| 273 | IWL_DEBUG_RATE("leave\n"); |
| 274 | } |
| 275 | |
| 276 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 277 | * iwl3945_collect_tx_data - Update the success/failure sliding window |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 278 | * |
| 279 | * We keep a sliding window of the last 64 packets transmitted |
| 280 | * at this rate. window->data contains the bitmask of successful |
| 281 | * packets. |
| 282 | */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 283 | static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 284 | struct iwl3945_rate_scale_data *window, |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 285 | int success, int retries, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | { |
| 287 | unsigned long flags; |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 288 | s32 fail_count; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 289 | |
| 290 | if (!retries) { |
| 291 | IWL_DEBUG_RATE("leave: retries == 0 -- should be at least 1\n"); |
| 292 | return; |
| 293 | } |
| 294 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 295 | spin_lock_irqsave(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 296 | while (retries--) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | |
| 298 | /* If we have filled up the window then subtract one from the |
| 299 | * success counter if the high-bit is counting toward |
| 300 | * success */ |
| 301 | if (window->counter == IWL_RATE_MAX_WINDOW) { |
| 302 | if (window->data & (1ULL << (IWL_RATE_MAX_WINDOW - 1))) |
| 303 | window->success_counter--; |
| 304 | } else |
| 305 | window->counter++; |
| 306 | |
| 307 | /* Slide the window to the left one bit */ |
| 308 | window->data = (window->data << 1); |
| 309 | |
| 310 | /* If this packet was a success then set the low bit high */ |
| 311 | if (success) { |
| 312 | window->success_counter++; |
| 313 | window->data |= 1; |
| 314 | } |
| 315 | |
| 316 | /* window->counter can't be 0 -- it is either >0 or |
| 317 | * IWL_RATE_MAX_WINDOW */ |
| 318 | window->success_ratio = 12800 * window->success_counter / |
| 319 | window->counter; |
| 320 | |
| 321 | /* Tag this window as having been updated */ |
| 322 | window->stamp = jiffies; |
| 323 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 324 | } |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 325 | |
| 326 | fail_count = window->counter - window->success_counter; |
| 327 | if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || |
| 328 | (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) |
| 329 | window->average_tpt = ((window->success_ratio * |
| 330 | rs_sta->expected_tpt[index] + 64) / 128); |
| 331 | else |
| 332 | window->average_tpt = IWL_INV_TPT; |
| 333 | |
| 334 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 335 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 338 | static void rs_rate_init(void *priv, struct ieee80211_supported_band *sband, |
| 339 | struct ieee80211_sta *sta, void *priv_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 340 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 341 | struct iwl3945_rs_sta *rs_sta = priv_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 342 | int i; |
| 343 | |
| 344 | IWL_DEBUG_RATE("enter\n"); |
| 345 | |
| 346 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
| 347 | * the lowest or the highest rate.. Could consider using RSSI from |
| 348 | * previous packets? Need to have IEEE 802.1X auth succeed immediately |
| 349 | * after assoc.. */ |
| 350 | |
| 351 | for (i = IWL_RATE_COUNT - 1; i >= 0; i--) { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 352 | if (sta->supp_rates[sband->band] & (1 << i)) { |
Johannes Berg | ae17e98 | 2008-09-11 03:04:36 +0200 | [diff] [blame] | 353 | rs_sta->last_txrate_idx = i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 354 | break; |
| 355 | } |
| 356 | } |
| 357 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 358 | /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 359 | if (sband->band == IEEE80211_BAND_5GHZ) |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 360 | rs_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 361 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 362 | IWL_DEBUG_RATE("leave\n"); |
| 363 | } |
| 364 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 365 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 367 | return hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 370 | /* rate scale requires free function to be implemented */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | static void rs_free(void *priv) |
| 372 | { |
| 373 | return; |
| 374 | } |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 375 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 376 | static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 377 | { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 378 | struct iwl3945_rs_sta *rs_sta; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 379 | struct iwl3945_sta_priv *psta = (void *) sta->drv_priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | int i; |
| 381 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 382 | /* |
| 383 | * XXX: If it's using sta->drv_priv anyway, it might |
| 384 | * as well just put all the information there. |
| 385 | */ |
| 386 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | IWL_DEBUG_RATE("enter\n"); |
| 388 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 389 | rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp); |
| 390 | if (!rs_sta) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 391 | IWL_DEBUG_RATE("leave: ENOMEM\n"); |
| 392 | return NULL; |
| 393 | } |
| 394 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 395 | psta->rs_sta = rs_sta; |
| 396 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 397 | spin_lock_init(&rs_sta->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 398 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 399 | rs_sta->start_rate = IWL_RATE_INVALID; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 400 | |
| 401 | /* default to just 802.11b */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 402 | rs_sta->expected_tpt = iwl3945_expected_tpt_b; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 403 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 404 | rs_sta->last_partial_flush = jiffies; |
| 405 | rs_sta->last_flush = jiffies; |
| 406 | rs_sta->flush_time = IWL_RATE_FLUSH; |
| 407 | rs_sta->last_tx_packets = 0; |
| 408 | rs_sta->ibss_sta_added = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 410 | init_timer(&rs_sta->rate_scale_flush); |
| 411 | rs_sta->rate_scale_flush.data = (unsigned long)rs_sta; |
| 412 | rs_sta->rate_scale_flush.function = &iwl3945_bg_rate_scale_flush; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 413 | |
| 414 | for (i = 0; i < IWL_RATE_COUNT; i++) |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 415 | iwl3945_clear_window(&rs_sta->win[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 416 | |
| 417 | IWL_DEBUG_RATE("leave\n"); |
| 418 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 419 | return rs_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 422 | static void rs_free_sta(void *priv, struct ieee80211_sta *sta, |
| 423 | void *priv_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 424 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 425 | struct iwl3945_sta_priv *psta = (void *) sta->drv_priv; |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 426 | struct iwl3945_rs_sta *rs_sta = priv_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 427 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 428 | psta->rs_sta = NULL; |
| 429 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 430 | IWL_DEBUG_RATE("enter\n"); |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 431 | del_timer_sync(&rs_sta->rate_scale_flush); |
| 432 | kfree(rs_sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | IWL_DEBUG_RATE("leave\n"); |
| 434 | } |
| 435 | |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 436 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | /** |
| 438 | * rs_tx_status - Update rate control values based on Tx results |
| 439 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 440 | * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 441 | * the hardware for each rate. |
| 442 | */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 443 | static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband, |
| 444 | struct ieee80211_sta *sta, void *priv_sta, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 445 | struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | { |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 447 | s8 retries = 0, current_count; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 448 | int scale_rate_index, first_index, last_index; |
| 449 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 450 | struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 451 | struct iwl3945_rs_sta *rs_sta = priv_sta; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 452 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 453 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 454 | IWL_DEBUG_RATE("enter\n"); |
| 455 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 456 | retries = info->status.rates[0].count; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 457 | |
| 458 | first_index = sband->bitrates[info->status.rates[0].idx].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 459 | if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 460 | IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 464 | if (!priv_sta) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 465 | IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); |
| 466 | return; |
| 467 | } |
| 468 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 469 | rs_sta->tx_packets++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 470 | |
| 471 | scale_rate_index = first_index; |
| 472 | last_index = first_index; |
| 473 | |
| 474 | /* |
| 475 | * Update the window for each rate. We determine which rates |
| 476 | * were Tx'd based on the total number of retries vs. the number |
| 477 | * of retries configured for each rate -- currently set to the |
| 478 | * priv value 'retry_rate' vs. rate specific |
| 479 | * |
| 480 | * On exit from this while loop last_index indicates the rate |
| 481 | * at which the frame was finally transmitted (or failed if no |
| 482 | * ACK) |
| 483 | */ |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 484 | while (retries > 1) { |
| 485 | if ((retries - 1) < priv->retry_rate) { |
| 486 | current_count = (retries - 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 487 | last_index = scale_rate_index; |
| 488 | } else { |
| 489 | current_count = priv->retry_rate; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 490 | last_index = iwl3945_rs_next_rate(priv, |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 491 | scale_rate_index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* Update this rate accounting for as many retries |
| 495 | * as was used for it (per current_count) */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 496 | iwl3945_collect_tx_data(rs_sta, |
| 497 | &rs_sta->win[scale_rate_index], |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 498 | 0, current_count, scale_rate_index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 499 | IWL_DEBUG_RATE("Update rate %d for %d retries.\n", |
| 500 | scale_rate_index, current_count); |
| 501 | |
| 502 | retries -= current_count; |
| 503 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 504 | scale_rate_index = last_index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 507 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 508 | /* Update the last index window with success/failure based on ACK */ |
| 509 | IWL_DEBUG_RATE("Update rate %d with %s.\n", |
| 510 | last_index, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 511 | (info->flags & IEEE80211_TX_STAT_ACK) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 512 | "success" : "failure"); |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 513 | iwl3945_collect_tx_data(rs_sta, |
| 514 | &rs_sta->win[last_index], |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 515 | info->flags & IEEE80211_TX_STAT_ACK, 1, last_index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | |
| 517 | /* We updated the rate scale window -- if its been more than |
| 518 | * flush_time since the last run, schedule the flush |
| 519 | * again */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 520 | spin_lock_irqsave(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 521 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 522 | if (!rs_sta->flush_pending && |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 523 | time_after(jiffies, rs_sta->last_flush + |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 524 | rs_sta->flush_time)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 525 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 526 | rs_sta->last_partial_flush = jiffies; |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 527 | rs_sta->flush_pending = 1; |
| 528 | mod_timer(&rs_sta->rate_scale_flush, |
| 529 | jiffies + rs_sta->flush_time); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 532 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 533 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 534 | IWL_DEBUG_RATE("leave\n"); |
| 535 | |
| 536 | return; |
| 537 | } |
| 538 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 539 | static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 540 | u8 index, u16 rate_mask, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 541 | { |
| 542 | u8 high = IWL_RATE_INVALID; |
| 543 | u8 low = IWL_RATE_INVALID; |
| 544 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 545 | /* 802.11A walks to the next literal adjacent rate in |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | * the rate table */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 547 | if (unlikely(band == IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 548 | int i; |
| 549 | u32 mask; |
| 550 | |
| 551 | /* Find the previous rate that is in the rate mask */ |
| 552 | i = index - 1; |
| 553 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 554 | if (rate_mask & mask) { |
| 555 | low = i; |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /* Find the next rate that is in the rate mask */ |
| 561 | i = index + 1; |
| 562 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { |
| 563 | if (rate_mask & mask) { |
| 564 | high = i; |
| 565 | break; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | return (high << 8) | low; |
| 570 | } |
| 571 | |
| 572 | low = index; |
| 573 | while (low != IWL_RATE_INVALID) { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 574 | if (rs_sta->tgg) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 575 | low = iwl3945_rates[low].prev_rs_tgg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 576 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 577 | low = iwl3945_rates[low].prev_rs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 578 | if (low == IWL_RATE_INVALID) |
| 579 | break; |
| 580 | if (rate_mask & (1 << low)) |
| 581 | break; |
| 582 | IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low); |
| 583 | } |
| 584 | |
| 585 | high = index; |
| 586 | while (high != IWL_RATE_INVALID) { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 587 | if (rs_sta->tgg) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 588 | high = iwl3945_rates[high].next_rs_tgg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 589 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 590 | high = iwl3945_rates[high].next_rs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | if (high == IWL_RATE_INVALID) |
| 592 | break; |
| 593 | if (rate_mask & (1 << high)) |
| 594 | break; |
| 595 | IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high); |
| 596 | } |
| 597 | |
| 598 | return (high << 8) | low; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * rs_get_rate - find the rate for the requested packet |
| 603 | * |
| 604 | * Returns the ieee80211_rate structure allocated by the driver. |
| 605 | * |
| 606 | * The rate control algorithm has no internal mapping between hw_mode's |
| 607 | * rate ordering and the rate ordering used by the rate control algorithm. |
| 608 | * |
| 609 | * The rate control algorithm uses a single table of rates that goes across |
| 610 | * the entire A/B/G spectrum vs. being limited to just one particular |
| 611 | * hw_mode. |
| 612 | * |
| 613 | * As such, we can't convert the index obtained below into the hw_mode's |
| 614 | * rate table and must reference the driver allocated rate table |
| 615 | * |
| 616 | */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 617 | static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, |
| 618 | void *priv_sta, struct ieee80211_tx_rate_control *txrc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 619 | { |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 620 | struct ieee80211_supported_band *sband = txrc->sband; |
| 621 | struct sk_buff *skb = txrc->skb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 622 | u8 low = IWL_RATE_INVALID; |
| 623 | u8 high = IWL_RATE_INVALID; |
| 624 | u16 high_low; |
| 625 | int index; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 626 | struct iwl3945_rs_sta *rs_sta = priv_sta; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 627 | struct iwl3945_rate_scale_data *window = NULL; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 628 | int current_tpt = IWL_INV_TPT; |
| 629 | int low_tpt = IWL_INV_TPT; |
| 630 | int high_tpt = IWL_INV_TPT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 631 | u32 fail_count; |
| 632 | s8 scale_action = 0; |
| 633 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 634 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Michael Wu | 2bc454b | 2007-12-25 19:33:16 -0500 | [diff] [blame] | 635 | u16 fc, rate_mask; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 636 | struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_r; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 637 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | |
| 639 | IWL_DEBUG_RATE("enter\n"); |
| 640 | |
Michael Wu | 2bc454b | 2007-12-25 19:33:16 -0500 | [diff] [blame] | 641 | /* Send management frames and broadcast/multicast data using lowest |
| 642 | * rate. */ |
| 643 | fc = le16_to_cpu(hdr->frame_control); |
| 644 | if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || |
| 645 | is_multicast_ether_addr(hdr->addr1) || |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 646 | !sta || !priv_sta) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 647 | IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 648 | info->control.rates[0].idx = rate_lowest_index(sband, sta); |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 649 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 652 | rate_mask = sta->supp_rates[sband->band]; |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 653 | index = min(rs_sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1); |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 654 | |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 655 | if (sband->band == IEEE80211_BAND_5GHZ) |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 656 | rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 657 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 658 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 659 | !rs_sta->ibss_sta_added) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 660 | u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 661 | |
| 662 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 663 | IWL_DEBUG_RATE("LQ: ADD station %pm\n", |
| 664 | hdr->addr1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 665 | sta_id = iwl3945_add_station(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 666 | hdr->addr1, 0, CMD_ASYNC); |
| 667 | } |
| 668 | if (sta_id != IWL_INVALID_STATION) |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 669 | rs_sta->ibss_sta_added = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 672 | spin_lock_irqsave(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 674 | /* for recent assoc, choose best rate regarding |
| 675 | * to rssi value |
| 676 | */ |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 677 | if (rs_sta->start_rate != IWL_RATE_INVALID) { |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 678 | if (rs_sta->start_rate < index && |
| 679 | (rate_mask & (1 << rs_sta->start_rate))) |
| 680 | index = rs_sta->start_rate; |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 681 | rs_sta->start_rate = IWL_RATE_INVALID; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 684 | window = &(rs_sta->win[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 685 | |
| 686 | fail_count = window->counter - window->success_counter; |
| 687 | |
| 688 | if (((fail_count <= IWL_RATE_MIN_FAILURE_TH) && |
| 689 | (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))) { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 690 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | |
| 692 | IWL_DEBUG_RATE("Invalid average_tpt on rate %d: " |
| 693 | "counter: %d, success_counter: %d, " |
| 694 | "expected_tpt is %sNULL\n", |
| 695 | index, |
| 696 | window->counter, |
| 697 | window->success_counter, |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 698 | rs_sta->expected_tpt ? "not " : ""); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 699 | goto out; |
| 700 | |
| 701 | } |
| 702 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | current_tpt = window->average_tpt; |
| 704 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 705 | high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask, |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 706 | sband->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 707 | low = high_low & 0xff; |
| 708 | high = (high_low >> 8) & 0xff; |
| 709 | |
| 710 | if (low != IWL_RATE_INVALID) |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 711 | low_tpt = rs_sta->win[low].average_tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 712 | |
| 713 | if (high != IWL_RATE_INVALID) |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 714 | high_tpt = rs_sta->win[high].average_tpt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 715 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 716 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 717 | |
| 718 | scale_action = 1; |
| 719 | |
| 720 | if ((window->success_ratio < IWL_RATE_DECREASE_TH) || !current_tpt) { |
| 721 | IWL_DEBUG_RATE("decrease rate because of low success_ratio\n"); |
| 722 | scale_action = -1; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 723 | } else if ((low_tpt == IWL_INV_TPT) && (high_tpt == IWL_INV_TPT)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | scale_action = 1; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 725 | else if ((low_tpt != IWL_INV_TPT) && (high_tpt != IWL_INV_TPT) && |
| 726 | (low_tpt < current_tpt) && (high_tpt < current_tpt)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 727 | IWL_DEBUG_RATE("No action -- low [%d] & high [%d] < " |
| 728 | "current_tpt [%d]\n", |
| 729 | low_tpt, high_tpt, current_tpt); |
| 730 | scale_action = 0; |
| 731 | } else { |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 732 | if (high_tpt != IWL_INV_TPT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 733 | if (high_tpt > current_tpt) |
| 734 | scale_action = 1; |
| 735 | else { |
| 736 | IWL_DEBUG_RATE |
| 737 | ("decrease rate because of high tpt\n"); |
| 738 | scale_action = -1; |
| 739 | } |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 740 | } else if (low_tpt != IWL_INV_TPT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | if (low_tpt > current_tpt) { |
| 742 | IWL_DEBUG_RATE |
| 743 | ("decrease rate because of low tpt\n"); |
| 744 | scale_action = -1; |
| 745 | } else |
| 746 | scale_action = 1; |
| 747 | } |
| 748 | } |
| 749 | |
Abbas, Mohamed | 74221d0 | 2008-12-02 12:14:03 -0800 | [diff] [blame^] | 750 | if (scale_action == -1) { |
| 751 | if (window->success_ratio > IWL_SUCCESS_DOWN_TH) |
| 752 | scale_action = 0; |
| 753 | } else if (scale_action == 1) { |
| 754 | if (window->success_ratio < IWL_SUCCESS_UP_TH) { |
| 755 | IWL_DEBUG_RATE("No action -- success_ratio [%d] < " |
| 756 | "SUCCESS UP\n", window->success_ratio); |
| 757 | scale_action = 0; |
| 758 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | switch (scale_action) { |
| 762 | case -1: |
| 763 | if (low != IWL_RATE_INVALID) |
| 764 | index = low; |
| 765 | break; |
| 766 | |
| 767 | case 1: |
| 768 | if (high != IWL_RATE_INVALID) |
| 769 | index = high; |
| 770 | |
| 771 | break; |
| 772 | |
| 773 | case 0: |
| 774 | default: |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | IWL_DEBUG_RATE("Selected %d (action %d) - low %d high %d\n", |
| 779 | index, scale_action, low, high); |
| 780 | |
| 781 | out: |
| 782 | |
Johannes Berg | b7e3500 | 2008-09-11 02:22:58 +0200 | [diff] [blame] | 783 | rs_sta->last_txrate_idx = index; |
Tomas Winkler | 28447f3 | 2008-03-06 17:36:54 -0800 | [diff] [blame] | 784 | if (sband->band == IEEE80211_BAND_5GHZ) |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 785 | info->control.rates[0].idx = rs_sta->last_txrate_idx - |
| 786 | IWL_FIRST_OFDM_RATE; |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 787 | else |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 788 | info->control.rates[0].idx = rs_sta->last_txrate_idx; |
Mohamed Abbas | 14577f2 | 2007-11-12 11:37:42 +0800 | [diff] [blame] | 789 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 790 | IWL_DEBUG_RATE("leave: %d\n", index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Abbas, Mohamed | c30e30e | 2008-12-02 12:14:02 -0800 | [diff] [blame] | 793 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 794 | static int iwl3945_open_file_generic(struct inode *inode, struct file *file) |
| 795 | { |
| 796 | file->private_data = inode->i_private; |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | static ssize_t iwl3945_sta_dbgfs_stats_table_read(struct file *file, |
| 801 | char __user *user_buf, |
| 802 | size_t count, loff_t *ppos) |
| 803 | { |
| 804 | char buff[1024]; |
| 805 | int desc = 0; |
| 806 | int j; |
| 807 | struct iwl3945_rs_sta *lq_sta = file->private_data; |
| 808 | |
| 809 | desc += sprintf(buff + desc, "tx packets=%d last rate index=%d\n" |
| 810 | "rate=0x%X flush time %d\n", |
| 811 | lq_sta->tx_packets, |
| 812 | lq_sta->last_txrate_idx, |
| 813 | lq_sta->start_rate, jiffies_to_msecs(lq_sta->flush_time)); |
| 814 | for (j = 0; j < IWL_RATE_COUNT; j++) { |
| 815 | desc += sprintf(buff+desc, |
| 816 | "counter=%d success=%d %%=%d\n", |
| 817 | lq_sta->win[j].counter, |
| 818 | lq_sta->win[j].success_counter, |
| 819 | lq_sta->win[j].success_ratio); |
| 820 | } |
| 821 | return simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 822 | } |
| 823 | |
| 824 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
| 825 | .read = iwl3945_sta_dbgfs_stats_table_read, |
| 826 | .open = iwl3945_open_file_generic, |
| 827 | }; |
| 828 | |
| 829 | static void iwl3945_add_debugfs(void *priv, void *priv_sta, |
| 830 | struct dentry *dir) |
| 831 | { |
| 832 | struct iwl3945_rs_sta *lq_sta = priv_sta; |
| 833 | |
| 834 | lq_sta->rs_sta_dbgfs_stats_table_file = |
| 835 | debugfs_create_file("rate_stats_table", 0600, dir, |
| 836 | lq_sta, &rs_sta_dbgfs_stats_table_ops); |
| 837 | |
| 838 | } |
| 839 | |
| 840 | static void iwl3945_remove_debugfs(void *priv, void *priv_sta) |
| 841 | { |
| 842 | struct iwl3945_rs_sta *lq_sta = priv_sta; |
| 843 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); |
| 844 | } |
| 845 | #endif |
| 846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 847 | static struct rate_control_ops rs_ops = { |
| 848 | .module = NULL, |
| 849 | .name = RS_NAME, |
| 850 | .tx_status = rs_tx_status, |
| 851 | .get_rate = rs_get_rate, |
| 852 | .rate_init = rs_rate_init, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 853 | .alloc = rs_alloc, |
| 854 | .free = rs_free, |
| 855 | .alloc_sta = rs_alloc_sta, |
| 856 | .free_sta = rs_free_sta, |
Abbas, Mohamed | c30e30e | 2008-12-02 12:14:02 -0800 | [diff] [blame] | 857 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 858 | .add_sta_debugfs = iwl3945_add_debugfs, |
| 859 | .remove_sta_debugfs = iwl3945_remove_debugfs, |
| 860 | #endif |
| 861 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 862 | }; |
| 863 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 864 | void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 865 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 866 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | s32 rssi = 0; |
| 868 | unsigned long flags; |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 869 | struct iwl3945_rs_sta *rs_sta; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 870 | struct ieee80211_sta *sta; |
| 871 | struct iwl3945_sta_priv *psta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 872 | |
| 873 | IWL_DEBUG_RATE("enter\n"); |
| 874 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 875 | rcu_read_lock(); |
| 876 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 877 | sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr); |
Johannes Berg | 5251818 | 2008-10-11 01:46:25 +0200 | [diff] [blame] | 878 | if (!sta) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 879 | rcu_read_unlock(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | return; |
| 881 | } |
| 882 | |
Johannes Berg | 5251818 | 2008-10-11 01:46:25 +0200 | [diff] [blame] | 883 | psta = (void *) sta->drv_priv; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 884 | rs_sta = psta->rs_sta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 885 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 886 | spin_lock_irqsave(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 887 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 888 | rs_sta->tgg = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 889 | switch (priv->band) { |
| 890 | case IEEE80211_BAND_2GHZ: |
| 891 | /* TODO: this always does G, not a regression */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 892 | if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) { |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 893 | rs_sta->tgg = 1; |
| 894 | rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | } else |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 896 | rs_sta->expected_tpt = iwl3945_expected_tpt_g; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 897 | break; |
| 898 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 899 | case IEEE80211_BAND_5GHZ: |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 900 | rs_sta->expected_tpt = iwl3945_expected_tpt_a; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 902 | case IEEE80211_NUM_BANDS: |
| 903 | BUG(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | break; |
| 905 | } |
| 906 | |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 907 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 908 | |
| 909 | rssi = priv->last_rx_rssi; |
| 910 | if (rssi == 0) |
| 911 | rssi = IWL_MIN_RSSI_VAL; |
| 912 | |
| 913 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RATE, "Network RSSI: %d\n", rssi); |
| 914 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 915 | rs_sta->start_rate = iwl3945_get_rate_index_by_rssi(rssi, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | |
| 917 | IWL_DEBUG_RATE("leave: rssi %d assign rate index: " |
Tomas Winkler | fa254a6 | 2008-01-27 20:41:38 -0800 | [diff] [blame] | 918 | "%d (plcp 0x%x)\n", rssi, rs_sta->start_rate, |
| 919 | iwl3945_rates[rs_sta->start_rate].plcp); |
Johannes Berg | 5251818 | 2008-10-11 01:46:25 +0200 | [diff] [blame] | 920 | rcu_read_unlock(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 923 | int iwl3945_rate_control_register(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 924 | { |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 925 | return ieee80211_rate_control_register(&rs_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 928 | void iwl3945_rate_control_unregister(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 929 | { |
| 930 | ieee80211_rate_control_unregister(&rs_ops); |
| 931 | } |
| 932 | |
| 933 | |