Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3 | * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [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 | * Intel Linux Wireless <ilw@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/slab.h> |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 31 | #include <net/mac80211.h> |
| 32 | |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/delay.h> |
| 36 | |
| 37 | #include <linux/workqueue.h> |
| 38 | |
Stanislaw Gruszka | d4459a9 | 2011-08-31 10:59:02 +0200 | [diff] [blame] | 39 | #include "commands.h" |
Stanislaw Gruszka | 6bbb137 | 2011-08-30 14:12:12 +0200 | [diff] [blame] | 40 | #include "3945.h" |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 41 | |
| 42 | #define RS_NAME "iwl-3945-rs" |
| 43 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 44 | static s32 il3945_expected_tpt_g[RATE_COUNT_3945] = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 45 | 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202 |
| 46 | }; |
| 47 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 48 | static s32 il3945_expected_tpt_g_prot[RATE_COUNT_3945] = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 49 | 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125 |
| 50 | }; |
| 51 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 52 | static s32 il3945_expected_tpt_a[RATE_COUNT_3945] = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 53 | 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186 |
| 54 | }; |
| 55 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 56 | static s32 il3945_expected_tpt_b[RATE_COUNT_3945] = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 57 | 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0 |
| 58 | }; |
| 59 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 60 | struct il3945_tpt_entry { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 61 | s8 min_rssi; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 62 | u8 idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 65 | static struct il3945_tpt_entry il3945_tpt_table_a[] = { |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 66 | {-60, RATE_54M_IDX}, |
| 67 | {-64, RATE_48M_IDX}, |
| 68 | {-72, RATE_36M_IDX}, |
| 69 | {-80, RATE_24M_IDX}, |
| 70 | {-84, RATE_18M_IDX}, |
| 71 | {-85, RATE_12M_IDX}, |
| 72 | {-87, RATE_9M_IDX}, |
| 73 | {-89, RATE_6M_IDX} |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 76 | static struct il3945_tpt_entry il3945_tpt_table_g[] = { |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 77 | {-60, RATE_54M_IDX}, |
| 78 | {-64, RATE_48M_IDX}, |
| 79 | {-68, RATE_36M_IDX}, |
| 80 | {-80, RATE_24M_IDX}, |
| 81 | {-84, RATE_18M_IDX}, |
| 82 | {-85, RATE_12M_IDX}, |
| 83 | {-86, RATE_11M_IDX}, |
| 84 | {-88, RATE_5M_IDX}, |
| 85 | {-90, RATE_2M_IDX}, |
| 86 | {-92, RATE_1M_IDX} |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 89 | #define RATE_MAX_WINDOW 62 |
| 90 | #define RATE_FLUSH (3*HZ) |
| 91 | #define RATE_WIN_FLUSH (HZ/2) |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 92 | #define IL39_RATE_HIGH_TH 11520 |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 93 | #define IL_SUCCESS_UP_TH 8960 |
| 94 | #define IL_SUCCESS_DOWN_TH 10880 |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 95 | #define RATE_MIN_FAILURE_TH 6 |
| 96 | #define RATE_MIN_SUCCESS_TH 8 |
| 97 | #define RATE_DECREASE_TH 1920 |
| 98 | #define RATE_RETRY_TH 15 |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 99 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 100 | static u8 |
| 101 | il3945_get_rate_idx_by_rssi(s32 rssi, enum ieee80211_band band) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 102 | { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 103 | u32 idx = 0; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 104 | u32 table_size = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 105 | struct il3945_tpt_entry *tpt_table = NULL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 106 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 107 | if (rssi < IL_MIN_RSSI_VAL || rssi > IL_MAX_RSSI_VAL) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 108 | rssi = IL_MIN_RSSI_VAL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 109 | |
| 110 | switch (band) { |
| 111 | case IEEE80211_BAND_2GHZ: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 112 | tpt_table = il3945_tpt_table_g; |
| 113 | table_size = ARRAY_SIZE(il3945_tpt_table_g); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | case IEEE80211_BAND_5GHZ: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 117 | tpt_table = il3945_tpt_table_a; |
| 118 | table_size = ARRAY_SIZE(il3945_tpt_table_a); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | default: |
| 122 | BUG(); |
| 123 | break; |
| 124 | } |
| 125 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 126 | while (idx < table_size && rssi < tpt_table[idx].min_rssi) |
| 127 | idx++; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 128 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 129 | idx = min(idx, (table_size - 1)); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 130 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 131 | return tpt_table[idx].idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 134 | static void |
| 135 | il3945_clear_win(struct il3945_rate_scale_data *win) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 136 | { |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 137 | win->data = 0; |
| 138 | win->success_counter = 0; |
| 139 | win->success_ratio = -1; |
| 140 | win->counter = 0; |
| 141 | win->average_tpt = IL_INVALID_VALUE; |
| 142 | win->stamp = 0; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 146 | * il3945_rate_scale_flush_wins - flush out the rate scale wins |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 147 | * |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 148 | * Returns the number of wins that have gathered data but were |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 149 | * not flushed. If there were any that were not flushed, then |
| 150 | * reschedule the rate flushing routine. |
| 151 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 152 | static int |
| 153 | il3945_rate_scale_flush_wins(struct il3945_rs_sta *rs_sta) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 154 | { |
| 155 | int unflushed = 0; |
| 156 | int i; |
| 157 | unsigned long flags; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 158 | struct il_priv *il __maybe_unused = rs_sta->il; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * For each rate, if we have collected data on that rate |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 162 | * and it has been more than RATE_WIN_FLUSH |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 163 | * since we flushed, clear out the gathered stats |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 164 | */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 165 | for (i = 0; i < RATE_COUNT_3945; i++) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 166 | if (!rs_sta->win[i].counter) |
| 167 | continue; |
| 168 | |
| 169 | spin_lock_irqsave(&rs_sta->lock, flags); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 170 | if (time_after(jiffies, rs_sta->win[i].stamp + RATE_WIN_FLUSH)) { |
| 171 | D_RATE("flushing %d samples of rate " "idx %d\n", |
| 172 | rs_sta->win[i].counter, i); |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 173 | il3945_clear_win(&rs_sta->win[i]); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 174 | } else |
| 175 | unflushed++; |
| 176 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 177 | } |
| 178 | |
| 179 | return unflushed; |
| 180 | } |
| 181 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 182 | #define RATE_FLUSH_MAX 5000 /* msec */ |
| 183 | #define RATE_FLUSH_MIN 50 /* msec */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 184 | #define IL_AVERAGE_PACKETS 1500 |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 185 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 186 | static void |
| 187 | il3945_bg_rate_scale_flush(unsigned long data) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 188 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 189 | struct il3945_rs_sta *rs_sta = (void *)data; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 190 | struct il_priv *il __maybe_unused = rs_sta->il; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 191 | int unflushed = 0; |
| 192 | unsigned long flags; |
| 193 | u32 packet_count, duration, pps; |
| 194 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 195 | D_RATE("enter\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 196 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 197 | unflushed = il3945_rate_scale_flush_wins(rs_sta); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 198 | |
| 199 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 200 | |
| 201 | /* Number of packets Rx'd since last time this timer ran */ |
| 202 | packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; |
| 203 | |
| 204 | rs_sta->last_tx_packets = rs_sta->tx_packets + 1; |
| 205 | |
| 206 | if (unflushed) { |
| 207 | duration = |
| 208 | jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); |
| 209 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 210 | D_RATE("Tx'd %d packets in %dms\n", packet_count, duration); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 211 | |
| 212 | /* Determine packets per second */ |
| 213 | if (duration) |
| 214 | pps = (packet_count * 1000) / duration; |
| 215 | else |
| 216 | pps = 0; |
| 217 | |
| 218 | if (pps) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 219 | duration = (IL_AVERAGE_PACKETS * 1000) / pps; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 220 | if (duration < RATE_FLUSH_MIN) |
| 221 | duration = RATE_FLUSH_MIN; |
| 222 | else if (duration > RATE_FLUSH_MAX) |
| 223 | duration = RATE_FLUSH_MAX; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 224 | } else |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 225 | duration = RATE_FLUSH_MAX; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 226 | |
| 227 | rs_sta->flush_time = msecs_to_jiffies(duration); |
| 228 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 229 | D_RATE("new flush period: %d msec ave %d\n", duration, |
| 230 | packet_count); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 231 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 232 | mod_timer(&rs_sta->rate_scale_flush, |
| 233 | jiffies + rs_sta->flush_time); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 234 | |
| 235 | rs_sta->last_partial_flush = jiffies; |
| 236 | } else { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 237 | rs_sta->flush_time = RATE_FLUSH; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 238 | rs_sta->flush_pending = 0; |
| 239 | } |
| 240 | /* If there weren't any unflushed entries, we don't schedule the timer |
| 241 | * to run again */ |
| 242 | |
| 243 | rs_sta->last_flush = jiffies; |
| 244 | |
| 245 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 246 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 247 | D_RATE("leave\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 251 | * il3945_collect_tx_data - Update the success/failure sliding win |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 252 | * |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 253 | * We keep a sliding win of the last 64 packets transmitted |
| 254 | * at this rate. win->data contains the bitmask of successful |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 255 | * packets. |
| 256 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 257 | static void |
| 258 | il3945_collect_tx_data(struct il3945_rs_sta *rs_sta, |
| 259 | struct il3945_rate_scale_data *win, int success, |
| 260 | int retries, int idx) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 261 | { |
| 262 | unsigned long flags; |
| 263 | s32 fail_count; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 264 | struct il_priv *il __maybe_unused = rs_sta->il; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 265 | |
| 266 | if (!retries) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 267 | D_RATE("leave: retries == 0 -- should be at least 1\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | |
| 271 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 272 | |
| 273 | /* |
| 274 | * Keep track of only the latest 62 tx frame attempts in this rate's |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 275 | * history win; anything older isn't really relevant any more. |
| 276 | * If we have filled up the sliding win, drop the oldest attempt; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 277 | * if the oldest attempt (highest bit in bitmap) shows "success", |
| 278 | * subtract "1" from the success counter (this is the main reason |
| 279 | * we keep these bitmaps!). |
| 280 | * */ |
| 281 | while (retries > 0) { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 282 | if (win->counter >= RATE_MAX_WINDOW) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 283 | |
| 284 | /* remove earliest */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 285 | win->counter = RATE_MAX_WINDOW - 1; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 286 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 287 | if (win->data & (1ULL << (RATE_MAX_WINDOW - 1))) { |
| 288 | win->data &= ~(1ULL << (RATE_MAX_WINDOW - 1)); |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 289 | win->success_counter--; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | /* Increment frames-attempted counter */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 294 | win->counter++; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 295 | |
| 296 | /* Shift bitmap by one frame (throw away oldest history), |
| 297 | * OR in "1", and increment "success" if this |
| 298 | * frame was successful. */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 299 | win->data <<= 1; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 300 | if (success > 0) { |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 301 | win->success_counter++; |
| 302 | win->data |= 0x1; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 303 | success--; |
| 304 | } |
| 305 | |
| 306 | retries--; |
| 307 | } |
| 308 | |
| 309 | /* Calculate current success ratio, avoid divide-by-0! */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 310 | if (win->counter > 0) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 311 | win->success_ratio = |
| 312 | 128 * (100 * win->success_counter) / win->counter; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 313 | else |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 314 | win->success_ratio = IL_INVALID_VALUE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 315 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 316 | fail_count = win->counter - win->success_counter; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 317 | |
| 318 | /* Calculate average throughput, if we have enough history. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 319 | if (fail_count >= RATE_MIN_FAILURE_TH || |
| 320 | win->success_counter >= RATE_MIN_SUCCESS_TH) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 321 | win->average_tpt = |
| 322 | ((win->success_ratio * rs_sta->expected_tpt[idx] + |
| 323 | 64) / 128); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 324 | else |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 325 | win->average_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 326 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 327 | /* Tag this win as having been updated */ |
| 328 | win->stamp = jiffies; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 329 | |
| 330 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 331 | |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Called after adding a new station to initialize rate scaling |
| 336 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 337 | void |
| 338 | il3945_rs_rate_init(struct il_priv *il, struct ieee80211_sta *sta, u8 sta_id) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 339 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 340 | struct ieee80211_hw *hw = il->hw; |
| 341 | struct ieee80211_conf *conf = &il->hw->conf; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 342 | struct il3945_sta_priv *psta; |
| 343 | struct il3945_rs_sta *rs_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 344 | struct ieee80211_supported_band *sband; |
| 345 | int i; |
| 346 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 347 | D_INFO("enter\n"); |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 348 | if (sta_id == il->ctx.bcast_sta_id) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 349 | goto out; |
| 350 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 351 | psta = (struct il3945_sta_priv *)sta->drv_priv; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 352 | rs_sta = &psta->rs_sta; |
| 353 | sband = hw->wiphy->bands[conf->channel->band]; |
| 354 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 355 | rs_sta->il = il; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 356 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 357 | rs_sta->start_rate = RATE_INVALID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 358 | |
| 359 | /* default to just 802.11b */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 360 | rs_sta->expected_tpt = il3945_expected_tpt_b; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 361 | |
| 362 | rs_sta->last_partial_flush = jiffies; |
| 363 | rs_sta->last_flush = jiffies; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 364 | rs_sta->flush_time = RATE_FLUSH; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 365 | rs_sta->last_tx_packets = 0; |
| 366 | |
| 367 | rs_sta->rate_scale_flush.data = (unsigned long)rs_sta; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 368 | rs_sta->rate_scale_flush.function = il3945_bg_rate_scale_flush; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 369 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 370 | for (i = 0; i < RATE_COUNT_3945; i++) |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 371 | il3945_clear_win(&rs_sta->win[i]); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 372 | |
| 373 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
| 374 | * the lowest or the highest rate.. Could consider using RSSI from |
| 375 | * previous packets? Need to have IEEE 802.1X auth succeed immediately |
| 376 | * after assoc.. */ |
| 377 | |
| 378 | for (i = sband->n_bitrates - 1; i >= 0; i--) { |
| 379 | if (sta->supp_rates[sband->band] & (1 << i)) { |
| 380 | rs_sta->last_txrate_idx = i; |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 385 | il->_3945.sta_supp_rates = sta->supp_rates[sband->band]; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 386 | /* For 5 GHz band it start at IL_FIRST_OFDM_RATE */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 387 | if (sband->band == IEEE80211_BAND_5GHZ) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 388 | rs_sta->last_txrate_idx += IL_FIRST_OFDM_RATE; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 389 | il->_3945.sta_supp_rates = |
| 390 | il->_3945.sta_supp_rates << IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 394 | il->stations[sta_id].used &= ~IL_STA_UCODE_INPROGRESS; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 395 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 396 | D_INFO("leave\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 399 | static void * |
| 400 | il3945_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 401 | { |
| 402 | return hw->priv; |
| 403 | } |
| 404 | |
| 405 | /* rate scale requires free function to be implemented */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 406 | static void |
| 407 | il3945_rs_free(void *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 408 | { |
| 409 | return; |
| 410 | } |
| 411 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 412 | static void * |
| 413 | il3945_rs_alloc_sta(void *il_priv, struct ieee80211_sta *sta, gfp_t gfp) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 414 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 415 | struct il3945_rs_sta *rs_sta; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 416 | struct il3945_sta_priv *psta = (void *)sta->drv_priv; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 417 | struct il_priv *il __maybe_unused = il_priv; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 418 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 419 | D_RATE("enter\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 420 | |
| 421 | rs_sta = &psta->rs_sta; |
| 422 | |
| 423 | spin_lock_init(&rs_sta->lock); |
| 424 | init_timer(&rs_sta->rate_scale_flush); |
| 425 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 426 | D_RATE("leave\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 427 | |
| 428 | return rs_sta; |
| 429 | } |
| 430 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 431 | static void |
| 432 | il3945_rs_free_sta(void *il_priv, struct ieee80211_sta *sta, void *il_sta) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 433 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 434 | struct il3945_rs_sta *rs_sta = il_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 435 | |
| 436 | /* |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 437 | * Be careful not to use any members of il3945_rs_sta (like trying |
| 438 | * to use il_priv to print out debugging) since it may not be fully |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 439 | * initialized at this point. |
| 440 | */ |
| 441 | del_timer_sync(&rs_sta->rate_scale_flush); |
| 442 | } |
| 443 | |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 444 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 445 | * il3945_rs_tx_status - Update rate control values based on Tx results |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 446 | * |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 447 | * NOTE: Uses il_priv->retry_rate for the # of retries attempted by |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 448 | * the hardware for each rate. |
| 449 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 450 | static void |
| 451 | il3945_rs_tx_status(void *il_rate, struct ieee80211_supported_band *sband, |
| 452 | struct ieee80211_sta *sta, void *il_sta, |
| 453 | struct sk_buff *skb) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 454 | { |
| 455 | s8 retries = 0, current_count; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 456 | int scale_rate_idx, first_idx, last_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 457 | unsigned long flags; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 458 | struct il_priv *il = (struct il_priv *)il_rate; |
| 459 | struct il3945_rs_sta *rs_sta = il_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 460 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 461 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 462 | D_RATE("enter\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 463 | |
| 464 | retries = info->status.rates[0].count; |
| 465 | /* Sanity Check for retries */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 466 | if (retries > RATE_RETRY_TH) |
| 467 | retries = RATE_RETRY_TH; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 468 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 469 | first_idx = sband->bitrates[info->status.rates[0].idx].hw_value; |
| 470 | if (first_idx < 0 || first_idx >= RATE_COUNT_3945) { |
| 471 | D_RATE("leave: Rate out of bounds: %d\n", first_idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 475 | if (!il_sta) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 476 | D_RATE("leave: No STA il data to update!\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
| 480 | /* Treat uninitialized rate scaling data same as non-existing. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 481 | if (!rs_sta->il) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 482 | D_RATE("leave: STA il data uninitialized!\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 483 | return; |
| 484 | } |
| 485 | |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 486 | rs_sta->tx_packets++; |
| 487 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 488 | scale_rate_idx = first_idx; |
| 489 | last_idx = first_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 490 | |
| 491 | /* |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 492 | * Update the win for each rate. We determine which rates |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 493 | * were Tx'd based on the total number of retries vs. the number |
| 494 | * of retries configured for each rate -- currently set to the |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 495 | * il value 'retry_rate' vs. rate specific |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 496 | * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 497 | * On exit from this while loop last_idx indicates the rate |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 498 | * at which the frame was finally transmitted (or failed if no |
| 499 | * ACK) |
| 500 | */ |
| 501 | while (retries > 1) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 502 | if ((retries - 1) < il->retry_rate) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 503 | current_count = (retries - 1); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 504 | last_idx = scale_rate_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 505 | } else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 506 | current_count = il->retry_rate; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 507 | last_idx = il3945_rs_next_rate(il, scale_rate_idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* Update this rate accounting for as many retries |
| 511 | * as was used for it (per current_count) */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 512 | il3945_collect_tx_data(rs_sta, &rs_sta->win[scale_rate_idx], 0, |
| 513 | current_count, scale_rate_idx); |
| 514 | D_RATE("Update rate %d for %d retries.\n", scale_rate_idx, |
| 515 | current_count); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 516 | |
| 517 | retries -= current_count; |
| 518 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 519 | scale_rate_idx = last_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 522 | /* Update the last idx win with success/failure based on ACK */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 523 | D_RATE("Update rate %d with %s.\n", last_idx, |
| 524 | (info->flags & IEEE80211_TX_STAT_ACK) ? "success" : "failure"); |
| 525 | il3945_collect_tx_data(rs_sta, &rs_sta->win[last_idx], |
| 526 | info->flags & IEEE80211_TX_STAT_ACK, 1, |
| 527 | last_idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 528 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 529 | /* We updated the rate scale win -- if its been more than |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 530 | * flush_time since the last run, schedule the flush |
| 531 | * again */ |
| 532 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 533 | |
| 534 | if (!rs_sta->flush_pending && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 535 | time_after(jiffies, rs_sta->last_flush + rs_sta->flush_time)) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 536 | |
| 537 | rs_sta->last_partial_flush = jiffies; |
| 538 | rs_sta->flush_pending = 1; |
| 539 | mod_timer(&rs_sta->rate_scale_flush, |
| 540 | jiffies + rs_sta->flush_time); |
| 541 | } |
| 542 | |
| 543 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 544 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 545 | D_RATE("leave\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 548 | static u16 |
| 549 | il3945_get_adjacent_rate(struct il3945_rs_sta *rs_sta, u8 idx, u16 rate_mask, |
| 550 | enum ieee80211_band band) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 551 | { |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 552 | u8 high = RATE_INVALID; |
| 553 | u8 low = RATE_INVALID; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 554 | struct il_priv *il __maybe_unused = rs_sta->il; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 555 | |
| 556 | /* 802.11A walks to the next literal adjacent rate in |
| 557 | * the rate table */ |
| 558 | if (unlikely(band == IEEE80211_BAND_5GHZ)) { |
| 559 | int i; |
| 560 | u32 mask; |
| 561 | |
| 562 | /* Find the previous rate that is in the rate mask */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 563 | i = idx - 1; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 564 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 565 | if (rate_mask & mask) { |
| 566 | low = i; |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /* Find the next rate that is in the rate mask */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 572 | i = idx + 1; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 573 | for (mask = (1 << i); i < RATE_COUNT_3945; i++, mask <<= 1) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 574 | if (rate_mask & mask) { |
| 575 | high = i; |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | return (high << 8) | low; |
| 581 | } |
| 582 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 583 | low = idx; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 584 | while (low != RATE_INVALID) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 585 | if (rs_sta->tgg) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 586 | low = il3945_rates[low].prev_rs_tgg; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 587 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 588 | low = il3945_rates[low].prev_rs; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 589 | if (low == RATE_INVALID) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 590 | break; |
| 591 | if (rate_mask & (1 << low)) |
| 592 | break; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 593 | D_RATE("Skipping masked lower rate: %d\n", low); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 596 | high = idx; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 597 | while (high != RATE_INVALID) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 598 | if (rs_sta->tgg) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 599 | high = il3945_rates[high].next_rs_tgg; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 600 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 601 | high = il3945_rates[high].next_rs; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 602 | if (high == RATE_INVALID) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 603 | break; |
| 604 | if (rate_mask & (1 << high)) |
| 605 | break; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 606 | D_RATE("Skipping masked higher rate: %d\n", high); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | return (high << 8) | low; |
| 610 | } |
| 611 | |
| 612 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 613 | * il3945_rs_get_rate - find the rate for the requested packet |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 614 | * |
| 615 | * Returns the ieee80211_rate structure allocated by the driver. |
| 616 | * |
| 617 | * The rate control algorithm has no internal mapping between hw_mode's |
| 618 | * rate ordering and the rate ordering used by the rate control algorithm. |
| 619 | * |
| 620 | * The rate control algorithm uses a single table of rates that goes across |
| 621 | * the entire A/B/G spectrum vs. being limited to just one particular |
| 622 | * hw_mode. |
| 623 | * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 624 | * As such, we can't convert the idx obtained below into the hw_mode's |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 625 | * rate table and must reference the driver allocated rate table |
| 626 | * |
| 627 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 628 | static void |
| 629 | il3945_rs_get_rate(void *il_r, struct ieee80211_sta *sta, void *il_sta, |
| 630 | struct ieee80211_tx_rate_control *txrc) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 631 | { |
| 632 | struct ieee80211_supported_band *sband = txrc->sband; |
| 633 | struct sk_buff *skb = txrc->skb; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 634 | u8 low = RATE_INVALID; |
| 635 | u8 high = RATE_INVALID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 636 | u16 high_low; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 637 | int idx; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 638 | struct il3945_rs_sta *rs_sta = il_sta; |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 639 | struct il3945_rate_scale_data *win = NULL; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 640 | int current_tpt = IL_INVALID_VALUE; |
| 641 | int low_tpt = IL_INVALID_VALUE; |
| 642 | int high_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 643 | u32 fail_count; |
| 644 | s8 scale_action = 0; |
| 645 | unsigned long flags; |
Dan Carpenter | c3371d6 | 2011-02-26 04:56:53 +0300 | [diff] [blame] | 646 | u16 rate_mask; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 647 | s8 max_rate_idx = -1; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 648 | struct il_priv *il __maybe_unused = (struct il_priv *)il_r; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 649 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 650 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 651 | D_RATE("enter\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 652 | |
| 653 | /* Treat uninitialized rate scaling data same as non-existing. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 654 | if (rs_sta && !rs_sta->il) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 655 | D_RATE("Rate scaling information not initialized yet.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 656 | il_sta = NULL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 659 | if (rate_control_send_low(sta, il_sta, txrc)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 660 | return; |
| 661 | |
| 662 | rate_mask = sta->supp_rates[sband->band]; |
| 663 | |
| 664 | /* get user max rate if set */ |
| 665 | max_rate_idx = txrc->max_rate_idx; |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 666 | if (sband->band == IEEE80211_BAND_5GHZ && max_rate_idx != -1) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 667 | max_rate_idx += IL_FIRST_OFDM_RATE; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 668 | if (max_rate_idx < 0 || max_rate_idx >= RATE_COUNT) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 669 | max_rate_idx = -1; |
| 670 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 671 | idx = min(rs_sta->last_txrate_idx & 0xffff, RATE_COUNT_3945 - 1); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 672 | |
| 673 | if (sband->band == IEEE80211_BAND_5GHZ) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 674 | rate_mask = rate_mask << IL_FIRST_OFDM_RATE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 675 | |
| 676 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 677 | |
| 678 | /* for recent assoc, choose best rate regarding |
| 679 | * to rssi value |
| 680 | */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 681 | if (rs_sta->start_rate != RATE_INVALID) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 682 | if (rs_sta->start_rate < idx && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 683 | (rate_mask & (1 << rs_sta->start_rate))) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 684 | idx = rs_sta->start_rate; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 685 | rs_sta->start_rate = RATE_INVALID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /* force user max rate if set by user */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 689 | if (max_rate_idx != -1 && max_rate_idx < idx) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 690 | if (rate_mask & (1 << max_rate_idx)) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 691 | idx = max_rate_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 694 | win = &(rs_sta->win[idx]); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 695 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 696 | fail_count = win->counter - win->success_counter; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 697 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 698 | if (fail_count < RATE_MIN_FAILURE_TH && |
| 699 | win->success_counter < RATE_MIN_SUCCESS_TH) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 700 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 701 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 702 | D_RATE("Invalid average_tpt on rate %d: " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 703 | "counter: %d, success_counter: %d, " |
| 704 | "expected_tpt is %sNULL\n", idx, win->counter, |
| 705 | win->success_counter, |
| 706 | rs_sta->expected_tpt ? "not " : ""); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 707 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 708 | /* Can't calculate this yet; not enough history */ |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 709 | win->average_tpt = IL_INVALID_VALUE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 710 | goto out; |
| 711 | |
| 712 | } |
| 713 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 714 | current_tpt = win->average_tpt; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 715 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 716 | high_low = |
| 717 | il3945_get_adjacent_rate(rs_sta, idx, rate_mask, sband->band); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 718 | low = high_low & 0xff; |
| 719 | high = (high_low >> 8) & 0xff; |
| 720 | |
| 721 | /* If user set max rate, dont allow higher than user constrain */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 722 | if (max_rate_idx != -1 && max_rate_idx < high) |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 723 | high = RATE_INVALID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 724 | |
| 725 | /* Collect Measured throughputs of adjacent rates */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 726 | if (low != RATE_INVALID) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 727 | low_tpt = rs_sta->win[low].average_tpt; |
| 728 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 729 | if (high != RATE_INVALID) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 730 | high_tpt = rs_sta->win[high].average_tpt; |
| 731 | |
| 732 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 733 | |
| 734 | scale_action = 0; |
| 735 | |
| 736 | /* Low success ratio , need to drop the rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 737 | if (win->success_ratio < RATE_DECREASE_TH || !current_tpt) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 738 | D_RATE("decrease rate because of low success_ratio\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 739 | scale_action = -1; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 740 | /* No throughput measured yet for adjacent rates, |
| 741 | * try increase */ |
| 742 | } else if (low_tpt == IL_INVALID_VALUE && high_tpt == IL_INVALID_VALUE) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 743 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 744 | if (high != RATE_INVALID && |
| 745 | win->success_ratio >= RATE_INCREASE_TH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 746 | scale_action = 1; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 747 | else if (low != RATE_INVALID) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 748 | scale_action = 0; |
| 749 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 750 | /* Both adjacent throughputs are measured, but neither one has |
| 751 | * better throughput; we're using the best rate, don't change |
| 752 | * it! */ |
| 753 | } else if (low_tpt != IL_INVALID_VALUE && high_tpt != IL_INVALID_VALUE |
| 754 | && low_tpt < current_tpt && high_tpt < current_tpt) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 755 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 756 | D_RATE("No action -- low [%d] & high [%d] < " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 757 | "current_tpt [%d]\n", low_tpt, high_tpt, current_tpt); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 758 | scale_action = 0; |
| 759 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 760 | /* At least one of the rates has better throughput */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 761 | } else { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 762 | if (high_tpt != IL_INVALID_VALUE) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 763 | |
| 764 | /* High rate has better throughput, Increase |
| 765 | * rate */ |
| 766 | if (high_tpt > current_tpt && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 767 | win->success_ratio >= RATE_INCREASE_TH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 768 | scale_action = 1; |
| 769 | else { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 770 | D_RATE("decrease rate because of high tpt\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 771 | scale_action = 0; |
| 772 | } |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 773 | } else if (low_tpt != IL_INVALID_VALUE) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 774 | if (low_tpt > current_tpt) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 775 | D_RATE("decrease rate because of low tpt\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 776 | scale_action = -1; |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 777 | } else if (win->success_ratio >= RATE_INCREASE_TH) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 778 | /* Lower rate has better |
| 779 | * throughput,decrease rate */ |
| 780 | scale_action = 1; |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /* Sanity check; asked for decrease, but success rate or throughput |
| 786 | * has been good at old rate. Don't change it. */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 787 | if (scale_action == -1 && low != RATE_INVALID && |
| 788 | (win->success_ratio > RATE_HIGH_TH || |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 789 | current_tpt > 100 * rs_sta->expected_tpt[low])) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 790 | scale_action = 0; |
| 791 | |
| 792 | switch (scale_action) { |
| 793 | case -1: |
| 794 | |
| 795 | /* Decrese rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 796 | if (low != RATE_INVALID) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 797 | idx = low; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case 1: |
| 801 | /* Increase rate */ |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 802 | if (high != RATE_INVALID) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 803 | idx = high; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 804 | |
| 805 | break; |
| 806 | |
| 807 | case 0: |
| 808 | default: |
| 809 | /* No change */ |
| 810 | break; |
| 811 | } |
| 812 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 813 | D_RATE("Selected %d (action %d) - low %d high %d\n", idx, scale_action, |
| 814 | low, high); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 815 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 816 | out: |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 817 | |
Stanislaw Gruszka | 7c25101 | 2011-08-26 17:24:59 +0200 | [diff] [blame] | 818 | if (sband->band == IEEE80211_BAND_5GHZ) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 819 | if (WARN_ON_ONCE(idx < IL_FIRST_OFDM_RATE)) |
| 820 | idx = IL_FIRST_OFDM_RATE; |
| 821 | rs_sta->last_txrate_idx = idx; |
| 822 | info->control.rates[0].idx = idx - IL_FIRST_OFDM_RATE; |
Stanislaw Gruszka | 7c25101 | 2011-08-26 17:24:59 +0200 | [diff] [blame] | 823 | } else { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 824 | rs_sta->last_txrate_idx = idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 825 | info->control.rates[0].idx = rs_sta->last_txrate_idx; |
Stanislaw Gruszka | 7c25101 | 2011-08-26 17:24:59 +0200 | [diff] [blame] | 826 | } |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 827 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 828 | D_RATE("leave: %d\n", idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | #ifdef CONFIG_MAC80211_DEBUGFS |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 832 | static int |
| 833 | il3945_open_file_generic(struct inode *inode, struct file *file) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 834 | { |
| 835 | file->private_data = inode->i_private; |
| 836 | return 0; |
| 837 | } |
| 838 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 839 | static ssize_t |
| 840 | il3945_sta_dbgfs_stats_table_read(struct file *file, char __user * user_buf, |
| 841 | size_t count, loff_t * ppos) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 842 | { |
| 843 | char *buff; |
| 844 | int desc = 0; |
| 845 | int j; |
| 846 | ssize_t ret; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 847 | struct il3945_rs_sta *lq_sta = file->private_data; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 848 | |
| 849 | buff = kmalloc(1024, GFP_KERNEL); |
| 850 | if (!buff) |
| 851 | return -ENOMEM; |
| 852 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 853 | desc += |
| 854 | sprintf(buff + desc, |
| 855 | "tx packets=%d last rate idx=%d\n" |
| 856 | "rate=0x%X flush time %d\n", lq_sta->tx_packets, |
| 857 | lq_sta->last_txrate_idx, lq_sta->start_rate, |
| 858 | jiffies_to_msecs(lq_sta->flush_time)); |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 859 | for (j = 0; j < RATE_COUNT_3945; j++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 860 | desc += |
| 861 | sprintf(buff + desc, "counter=%d success=%d %%=%d\n", |
| 862 | lq_sta->win[j].counter, |
| 863 | lq_sta->win[j].success_counter, |
| 864 | lq_sta->win[j].success_ratio); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 865 | } |
| 866 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 867 | kfree(buff); |
| 868 | return ret; |
| 869 | } |
| 870 | |
| 871 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 872 | .read = il3945_sta_dbgfs_stats_table_read, |
| 873 | .open = il3945_open_file_generic, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 874 | .llseek = default_llseek, |
| 875 | }; |
| 876 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 877 | static void |
| 878 | il3945_add_debugfs(void *il, void *il_sta, struct dentry *dir) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 879 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 880 | struct il3945_rs_sta *lq_sta = il_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 881 | |
| 882 | lq_sta->rs_sta_dbgfs_stats_table_file = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 883 | debugfs_create_file("rate_stats_table", 0600, dir, lq_sta, |
| 884 | &rs_sta_dbgfs_stats_table_ops); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 885 | |
| 886 | } |
| 887 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 888 | static void |
| 889 | il3945_remove_debugfs(void *il, void *il_sta) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 890 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 891 | struct il3945_rs_sta *lq_sta = il_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 892 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); |
| 893 | } |
| 894 | #endif |
| 895 | |
| 896 | /* |
| 897 | * Initialization of rate scaling information is done by driver after |
| 898 | * the station is added. Since mac80211 calls this function before a |
| 899 | * station is added we ignore it. |
| 900 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 901 | static void |
| 902 | il3945_rs_rate_init_stub(void *il_r, struct ieee80211_supported_band *sband, |
| 903 | struct ieee80211_sta *sta, void *il_sta) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 904 | { |
| 905 | } |
| 906 | |
| 907 | static struct rate_control_ops rs_ops = { |
| 908 | .module = NULL, |
| 909 | .name = RS_NAME, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 910 | .tx_status = il3945_rs_tx_status, |
| 911 | .get_rate = il3945_rs_get_rate, |
| 912 | .rate_init = il3945_rs_rate_init_stub, |
| 913 | .alloc = il3945_rs_alloc, |
| 914 | .free = il3945_rs_free, |
| 915 | .alloc_sta = il3945_rs_alloc_sta, |
| 916 | .free_sta = il3945_rs_free_sta, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 917 | #ifdef CONFIG_MAC80211_DEBUGFS |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 918 | .add_sta_debugfs = il3945_add_debugfs, |
| 919 | .remove_sta_debugfs = il3945_remove_debugfs, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 920 | #endif |
| 921 | |
| 922 | }; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 923 | |
| 924 | void |
| 925 | il3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 926 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 927 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 928 | s32 rssi = 0; |
| 929 | unsigned long flags; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 930 | struct il3945_rs_sta *rs_sta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 931 | struct ieee80211_sta *sta; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 932 | struct il3945_sta_priv *psta; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 933 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 934 | D_RATE("enter\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 935 | |
| 936 | rcu_read_lock(); |
| 937 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 938 | sta = |
| 939 | ieee80211_find_sta(il->ctx.vif, il->stations[sta_id].sta.sta.addr); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 940 | if (!sta) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 941 | D_RATE("Unable to find station to initialize rate scaling.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 942 | rcu_read_unlock(); |
| 943 | return; |
| 944 | } |
| 945 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 946 | psta = (void *)sta->drv_priv; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 947 | rs_sta = &psta->rs_sta; |
| 948 | |
| 949 | spin_lock_irqsave(&rs_sta->lock, flags); |
| 950 | |
| 951 | rs_sta->tgg = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 952 | switch (il->band) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 953 | case IEEE80211_BAND_2GHZ: |
| 954 | /* TODO: this always does G, not a regression */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 955 | if (il->ctx.active.flags & RXON_FLG_TGG_PROTECT_MSK) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 956 | rs_sta->tgg = 1; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 957 | rs_sta->expected_tpt = il3945_expected_tpt_g_prot; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 958 | } else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 959 | rs_sta->expected_tpt = il3945_expected_tpt_g; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 960 | break; |
| 961 | |
| 962 | case IEEE80211_BAND_5GHZ: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 963 | rs_sta->expected_tpt = il3945_expected_tpt_a; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 964 | break; |
| 965 | case IEEE80211_NUM_BANDS: |
| 966 | BUG(); |
| 967 | break; |
| 968 | } |
| 969 | |
| 970 | spin_unlock_irqrestore(&rs_sta->lock, flags); |
| 971 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 972 | rssi = il->_3945.last_rx_rssi; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 973 | if (rssi == 0) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 974 | rssi = IL_MIN_RSSI_VAL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 975 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 976 | D_RATE("Network RSSI: %d\n", rssi); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 977 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 978 | rs_sta->start_rate = il3945_get_rate_idx_by_rssi(rssi, il->band); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 979 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 980 | D_RATE("leave: rssi %d assign rate idx: " "%d (plcp 0x%x)\n", rssi, |
| 981 | rs_sta->start_rate, il3945_rates[rs_sta->start_rate].plcp); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 982 | rcu_read_unlock(); |
| 983 | } |
| 984 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 985 | int |
| 986 | il3945_rate_control_register(void) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 987 | { |
| 988 | return ieee80211_rate_control_register(&rs_ops); |
| 989 | } |
| 990 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame^] | 991 | void |
| 992 | il3945_rate_control_unregister(void) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 993 | { |
| 994 | ieee80211_rate_control_unregister(&rs_ops); |
| 995 | } |