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