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