Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 Video54 Technologies, Inc. |
| 3 | * Copyright (c) 2004-2008 Atheros Communications, Inc. |
| 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Atheros rate control algorithm |
| 20 | */ |
| 21 | |
| 22 | #include "core.h" |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 23 | /* FIXME: remove this include! */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 24 | #include "../net/mac80211/rate.h" |
| 25 | |
| 26 | static u32 tx_triglevel_max; |
| 27 | |
| 28 | static struct ath_rate_table ar5416_11na_ratetable = { |
| 29 | 42, |
| 30 | { |
| 31 | { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */ |
| 32 | 5400, 0x0b, 0x00, 12, |
| 33 | 0, 2, 1, 0, 0, 0, 0, 0 }, |
| 34 | { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */ |
| 35 | 7800, 0x0f, 0x00, 18, |
| 36 | 0, 3, 1, 1, 1, 1, 1, 0 }, |
| 37 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */ |
| 38 | 10000, 0x0a, 0x00, 24, |
| 39 | 2, 4, 2, 2, 2, 2, 2, 0 }, |
| 40 | { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */ |
| 41 | 13900, 0x0e, 0x00, 36, |
| 42 | 2, 6, 2, 3, 3, 3, 3, 0 }, |
| 43 | { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */ |
| 44 | 17300, 0x09, 0x00, 48, |
| 45 | 4, 10, 3, 4, 4, 4, 4, 0 }, |
| 46 | { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */ |
| 47 | 23000, 0x0d, 0x00, 72, |
| 48 | 4, 14, 3, 5, 5, 5, 5, 0 }, |
| 49 | { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */ |
| 50 | 27400, 0x08, 0x00, 96, |
| 51 | 4, 20, 3, 6, 6, 6, 6, 0 }, |
| 52 | { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */ |
| 53 | 29300, 0x0c, 0x00, 108, |
| 54 | 4, 23, 3, 7, 7, 7, 7, 0 }, |
| 55 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */ |
| 56 | 6400, 0x80, 0x00, 0, |
| 57 | 0, 2, 3, 8, 24, 8, 24, 3216 }, |
| 58 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */ |
| 59 | 12700, 0x81, 0x00, 1, |
| 60 | 2, 4, 3, 9, 25, 9, 25, 6434 }, |
| 61 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */ |
| 62 | 18800, 0x82, 0x00, 2, |
| 63 | 2, 6, 3, 10, 26, 10, 26, 9650 }, |
| 64 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */ |
| 65 | 25000, 0x83, 0x00, 3, |
| 66 | 4, 10, 3, 11, 27, 11, 27, 12868 }, |
| 67 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */ |
| 68 | 36700, 0x84, 0x00, 4, |
| 69 | 4, 14, 3, 12, 28, 12, 28, 19304 }, |
| 70 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */ |
| 71 | 48100, 0x85, 0x00, 5, |
| 72 | 4, 20, 3, 13, 29, 13, 29, 25740 }, |
| 73 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */ |
| 74 | 53500, 0x86, 0x00, 6, |
| 75 | 4, 23, 3, 14, 30, 14, 30, 28956 }, |
| 76 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */ |
| 77 | 59000, 0x87, 0x00, 7, |
| 78 | 4, 25, 3, 15, 31, 15, 32, 32180 }, |
| 79 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */ |
| 80 | 12700, 0x88, 0x00, |
| 81 | 8, 0, 2, 3, 16, 33, 16, 33, 6430 }, |
| 82 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */ |
| 83 | 24800, 0x89, 0x00, 9, |
| 84 | 2, 4, 3, 17, 34, 17, 34, 12860 }, |
| 85 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */ |
| 86 | 36600, 0x8a, 0x00, 10, |
| 87 | 2, 6, 3, 18, 35, 18, 35, 19300 }, |
| 88 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */ |
| 89 | 48100, 0x8b, 0x00, 11, |
| 90 | 4, 10, 3, 19, 36, 19, 36, 25736 }, |
| 91 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */ |
| 92 | 69500, 0x8c, 0x00, 12, |
| 93 | 4, 14, 3, 20, 37, 20, 37, 38600 }, |
| 94 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */ |
| 95 | 89500, 0x8d, 0x00, 13, |
| 96 | 4, 20, 3, 21, 38, 21, 38, 51472 }, |
| 97 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */ |
| 98 | 98900, 0x8e, 0x00, 14, |
| 99 | 4, 23, 3, 22, 39, 22, 39, 57890 }, |
| 100 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */ |
| 101 | 108300, 0x8f, 0x00, 15, |
| 102 | 4, 25, 3, 23, 40, 23, 41, 64320 }, |
| 103 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */ |
| 104 | 13200, 0x80, 0x00, 0, |
| 105 | 0, 2, 3, 8, 24, 24, 24, 6684 }, |
| 106 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */ |
| 107 | 25900, 0x81, 0x00, 1, |
| 108 | 2, 4, 3, 9, 25, 25, 25, 13368 }, |
| 109 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */ |
| 110 | 38600, 0x82, 0x00, 2, |
| 111 | 2, 6, 3, 10, 26, 26, 26, 20052 }, |
| 112 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */ |
| 113 | 49800, 0x83, 0x00, 3, |
| 114 | 4, 10, 3, 11, 27, 27, 27, 26738 }, |
| 115 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */ |
| 116 | 72200, 0x84, 0x00, 4, |
| 117 | 4, 14, 3, 12, 28, 28, 28, 40104 }, |
| 118 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */ |
| 119 | 92900, 0x85, 0x00, 5, |
| 120 | 4, 20, 3, 13, 29, 29, 29, 53476 }, |
| 121 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */ |
| 122 | 102700, 0x86, 0x00, 6, |
| 123 | 4, 23, 3, 14, 30, 30, 30, 60156 }, |
| 124 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */ |
| 125 | 112000, 0x87, 0x00, 7, |
| 126 | 4, 25, 3, 15, 31, 32, 32, 66840 }, |
| 127 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */ |
| 128 | 122000, 0x87, 0x00, 7, |
| 129 | 4, 25, 3, 15, 31, 32, 32, 74200 }, |
| 130 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */ |
| 131 | 25800, 0x88, 0x00, 8, |
| 132 | 0, 2, 3, 16, 33, 33, 33, 13360 }, |
| 133 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */ |
| 134 | 49800, 0x89, 0x00, 9, |
| 135 | 2, 4, 3, 17, 34, 34, 34, 26720 }, |
| 136 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */ |
| 137 | 71900, 0x8a, 0x00, 10, |
| 138 | 2, 6, 3, 18, 35, 35, 35, 40080 }, |
| 139 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */ |
| 140 | 92500, 0x8b, 0x00, 11, |
| 141 | 4, 10, 3, 19, 36, 36, 36, 53440 }, |
| 142 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */ |
| 143 | 130300, 0x8c, 0x00, 12, |
| 144 | 4, 14, 3, 20, 37, 37, 37, 80160 }, |
| 145 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */ |
| 146 | 162800, 0x8d, 0x00, 13, |
| 147 | 4, 20, 3, 21, 38, 38, 38, 106880 }, |
| 148 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */ |
| 149 | 178200, 0x8e, 0x00, 14, |
| 150 | 4, 23, 3, 22, 39, 39, 39, 120240 }, |
| 151 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */ |
| 152 | 192100, 0x8f, 0x00, 15, |
| 153 | 4, 25, 3, 23, 40, 41, 41, 133600 }, |
| 154 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */ |
| 155 | 207000, 0x8f, 0x00, 15, |
| 156 | 4, 25, 3, 23, 40, 41, 41, 148400 }, |
| 157 | }, |
| 158 | 50, /* probe interval */ |
| 159 | 50, /* rssi reduce interval */ |
| 160 | WLAN_RC_HT_FLAG, /* Phy rates allowed initially */ |
| 161 | }; |
| 162 | |
| 163 | /* TRUE_ALL - valid for 20/40/Legacy, |
| 164 | * TRUE - Legacy only, |
| 165 | * TRUE_20 - HT 20 only, |
| 166 | * TRUE_40 - HT 40 only */ |
| 167 | |
| 168 | /* 4ms frame limit not used for NG mode. The values filled |
| 169 | * for HT are the 64K max aggregate limit */ |
| 170 | |
| 171 | static struct ath_rate_table ar5416_11ng_ratetable = { |
| 172 | 46, |
| 173 | { |
| 174 | { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 1000, /* 1 Mb */ |
| 175 | 900, 0x1b, 0x00, 2, |
| 176 | 0, 0, 1, 0, 0, 0, 0, 0 }, |
| 177 | { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 2000, /* 2 Mb */ |
| 178 | 1900, 0x1a, 0x04, 4, |
| 179 | 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 180 | { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 5500, /* 5.5 Mb */ |
| 181 | 4900, 0x19, 0x04, 11, |
| 182 | 2, 2, 2, 2, 2, 2, 2, 0 }, |
| 183 | { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 11000, /* 11 Mb */ |
| 184 | 8100, 0x18, 0x04, 22, |
| 185 | 3, 3, 2, 3, 3, 3, 3, 0 }, |
| 186 | { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */ |
| 187 | 5400, 0x0b, 0x00, 12, |
| 188 | 4, 2, 1, 4, 4, 4, 4, 0 }, |
| 189 | { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */ |
| 190 | 7800, 0x0f, 0x00, 18, |
| 191 | 4, 3, 1, 5, 5, 5, 5, 0 }, |
| 192 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */ |
| 193 | 10100, 0x0a, 0x00, 24, |
| 194 | 6, 4, 1, 6, 6, 6, 6, 0 }, |
| 195 | { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */ |
| 196 | 14100, 0x0e, 0x00, 36, |
| 197 | 6, 6, 2, 7, 7, 7, 7, 0 }, |
| 198 | { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */ |
| 199 | 17700, 0x09, 0x00, 48, |
| 200 | 8, 10, 3, 8, 8, 8, 8, 0 }, |
| 201 | { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */ |
| 202 | 23700, 0x0d, 0x00, 72, |
| 203 | 8, 14, 3, 9, 9, 9, 9, 0 }, |
| 204 | { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */ |
| 205 | 27400, 0x08, 0x00, 96, |
| 206 | 8, 20, 3, 10, 10, 10, 10, 0 }, |
| 207 | { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */ |
| 208 | 30900, 0x0c, 0x00, 108, |
| 209 | 8, 23, 3, 11, 11, 11, 11, 0 }, |
| 210 | { FALSE, FALSE, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */ |
| 211 | 6400, 0x80, 0x00, 0, |
| 212 | 4, 2, 3, 12, 28, 12, 28, 3216 }, |
| 213 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */ |
| 214 | 12700, 0x81, 0x00, 1, |
| 215 | 6, 4, 3, 13, 29, 13, 29, 6434 }, |
| 216 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */ |
| 217 | 18800, 0x82, 0x00, 2, |
| 218 | 6, 6, 3, 14, 30, 14, 30, 9650 }, |
| 219 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */ |
| 220 | 25000, 0x83, 0x00, 3, |
| 221 | 8, 10, 3, 15, 31, 15, 31, 12868 }, |
| 222 | { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */ |
| 223 | 36700, 0x84, 0x00, 4, |
| 224 | 8, 14, 3, 16, 32, 16, 32, 19304 }, |
| 225 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */ |
| 226 | 48100, 0x85, 0x00, 5, |
| 227 | 8, 20, 3, 17, 33, 17, 33, 25740 }, |
| 228 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */ |
| 229 | 53500, 0x86, 0x00, 6, |
| 230 | 8, 23, 3, 18, 34, 18, 34, 28956 }, |
| 231 | { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */ |
| 232 | 59000, 0x87, 0x00, 7, |
| 233 | 8, 25, 3, 19, 35, 19, 36, 32180 }, |
| 234 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */ |
| 235 | 12700, 0x88, 0x00, 8, |
| 236 | 4, 2, 3, 20, 37, 20, 37, 6430 }, |
| 237 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */ |
| 238 | 24800, 0x89, 0x00, 9, |
| 239 | 6, 4, 3, 21, 38, 21, 38, 12860 }, |
| 240 | { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */ |
| 241 | 36600, 0x8a, 0x00, 10, |
| 242 | 6, 6, 3, 22, 39, 22, 39, 19300 }, |
| 243 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */ |
| 244 | 48100, 0x8b, 0x00, 11, |
| 245 | 8, 10, 3, 23, 40, 23, 40, 25736 }, |
| 246 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */ |
| 247 | 69500, 0x8c, 0x00, 12, |
| 248 | 8, 14, 3, 24, 41, 24, 41, 38600 }, |
| 249 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */ |
| 250 | 89500, 0x8d, 0x00, 13, |
| 251 | 8, 20, 3, 25, 42, 25, 42, 51472 }, |
| 252 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */ |
| 253 | 98900, 0x8e, 0x00, 14, |
| 254 | 8, 23, 3, 26, 43, 26, 44, 57890 }, |
| 255 | { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */ |
| 256 | 108300, 0x8f, 0x00, 15, |
| 257 | 8, 25, 3, 27, 44, 27, 45, 64320 }, |
| 258 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */ |
| 259 | 13200, 0x80, 0x00, 0, |
| 260 | 8, 2, 3, 12, 28, 28, 28, 6684 }, |
| 261 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */ |
| 262 | 25900, 0x81, 0x00, 1, |
| 263 | 8, 4, 3, 13, 29, 29, 29, 13368 }, |
| 264 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */ |
| 265 | 38600, 0x82, 0x00, 2, |
| 266 | 8, 6, 3, 14, 30, 30, 30, 20052 }, |
| 267 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */ |
| 268 | 49800, 0x83, 0x00, 3, |
| 269 | 8, 10, 3, 15, 31, 31, 31, 26738 }, |
| 270 | { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */ |
| 271 | 72200, 0x84, 0x00, 4, |
| 272 | 8, 14, 3, 16, 32, 32, 32, 40104 }, |
| 273 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */ |
| 274 | 92900, 0x85, 0x00, 5, |
| 275 | 8, 20, 3, 17, 33, 33, 33, 53476 }, |
| 276 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */ |
| 277 | 102700, 0x86, 0x00, 6, |
| 278 | 8, 23, 3, 18, 34, 34, 34, 60156 }, |
| 279 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */ |
| 280 | 112000, 0x87, 0x00, 7, |
| 281 | 8, 23, 3, 19, 35, 36, 36, 66840 }, |
| 282 | { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */ |
| 283 | 122000, 0x87, 0x00, 7, |
| 284 | 8, 25, 3, 19, 35, 36, 36, 74200 }, |
| 285 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */ |
| 286 | 25800, 0x88, 0x00, 8, |
| 287 | 8, 2, 3, 20, 37, 37, 37, 13360 }, |
| 288 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */ |
| 289 | 49800, 0x89, 0x00, 9, |
| 290 | 8, 4, 3, 21, 38, 38, 38, 26720 }, |
| 291 | { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */ |
| 292 | 71900, 0x8a, 0x00, 10, |
| 293 | 8, 6, 3, 22, 39, 39, 39, 40080 }, |
| 294 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */ |
| 295 | 92500, 0x8b, 0x00, 11, |
| 296 | 8, 10, 3, 23, 40, 40, 40, 53440 }, |
| 297 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */ |
| 298 | 130300, 0x8c, 0x00, 12, |
| 299 | 8, 14, 3, 24, 41, 41, 41, 80160 }, |
| 300 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */ |
| 301 | 162800, 0x8d, 0x00, 13, |
| 302 | 8, 20, 3, 25, 42, 42, 42, 106880 }, |
| 303 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */ |
| 304 | 178200, 0x8e, 0x00, 14, |
| 305 | 8, 23, 3, 26, 43, 43, 43, 120240 }, |
| 306 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */ |
| 307 | 192100, 0x8f, 0x00, 15, |
| 308 | 8, 23, 3, 27, 44, 45, 45, 133600 }, |
| 309 | { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */ |
| 310 | 207000, 0x8f, 0x00, 15, |
| 311 | 8, 25, 3, 27, 44, 45, 45, 148400 }, |
| 312 | }, |
| 313 | 50, /* probe interval */ |
| 314 | 50, /* rssi reduce interval */ |
| 315 | WLAN_RC_HT_FLAG, /* Phy rates allowed initially */ |
| 316 | }; |
| 317 | |
| 318 | static struct ath_rate_table ar5416_11a_ratetable = { |
| 319 | 8, |
| 320 | { |
| 321 | { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */ |
| 322 | 5400, 0x0b, 0x00, (0x80|12), |
| 323 | 0, 2, 1, 0, 0 }, |
| 324 | { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */ |
| 325 | 7800, 0x0f, 0x00, 18, |
| 326 | 0, 3, 1, 1, 0 }, |
| 327 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */ |
| 328 | 10000, 0x0a, 0x00, (0x80|24), |
| 329 | 2, 4, 2, 2, 0 }, |
| 330 | { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */ |
| 331 | 13900, 0x0e, 0x00, 36, |
| 332 | 2, 6, 2, 3, 0 }, |
| 333 | { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */ |
| 334 | 17300, 0x09, 0x00, (0x80|48), |
| 335 | 4, 10, 3, 4, 0 }, |
| 336 | { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */ |
| 337 | 23000, 0x0d, 0x00, 72, |
| 338 | 4, 14, 3, 5, 0 }, |
| 339 | { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */ |
| 340 | 27400, 0x08, 0x00, 96, |
| 341 | 4, 19, 3, 6, 0 }, |
| 342 | { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */ |
| 343 | 29300, 0x0c, 0x00, 108, |
| 344 | 4, 23, 3, 7, 0 }, |
| 345 | }, |
| 346 | 50, /* probe interval */ |
| 347 | 50, /* rssi reduce interval */ |
| 348 | 0, /* Phy rates allowed initially */ |
| 349 | }; |
| 350 | |
| 351 | static struct ath_rate_table ar5416_11a_ratetable_Half = { |
| 352 | 8, |
| 353 | { |
| 354 | { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 6 Mb */ |
| 355 | 2700, 0x0b, 0x00, (0x80|6), |
| 356 | 0, 2, 1, 0, 0}, |
| 357 | { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 9 Mb */ |
| 358 | 3900, 0x0f, 0x00, 9, |
| 359 | 0, 3, 1, 1, 0 }, |
| 360 | { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 12 Mb */ |
| 361 | 5000, 0x0a, 0x00, (0x80|12), |
| 362 | 2, 4, 2, 2, 0 }, |
| 363 | { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 18 Mb */ |
| 364 | 6950, 0x0e, 0x00, 18, |
| 365 | 2, 6, 2, 3, 0 }, |
| 366 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 24 Mb */ |
| 367 | 8650, 0x09, 0x00, (0x80|24), |
| 368 | 4, 10, 3, 4, 0 }, |
| 369 | { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 36 Mb */ |
| 370 | 11500, 0x0d, 0x00, 36, |
| 371 | 4, 14, 3, 5, 0 }, |
| 372 | { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 48 Mb */ |
| 373 | 13700, 0x08, 0x00, 48, |
| 374 | 4, 19, 3, 6, 0 }, |
| 375 | { TRUE, TRUE, WLAN_PHY_OFDM, 27000, /* 54 Mb */ |
| 376 | 14650, 0x0c, 0x00, 54, |
| 377 | 4, 23, 3, 7, 0 }, |
| 378 | }, |
| 379 | 50, /* probe interval */ |
| 380 | 50, /* rssi reduce interval */ |
| 381 | 0, /* Phy rates allowed initially */ |
| 382 | }; |
| 383 | |
| 384 | static struct ath_rate_table ar5416_11a_ratetable_Quarter = { |
| 385 | 8, |
| 386 | { |
| 387 | { TRUE, TRUE, WLAN_PHY_OFDM, 1500, /* 6 Mb */ |
| 388 | 1350, 0x0b, 0x00, (0x80|3), |
| 389 | 0, 2, 1, 0, 0 }, |
| 390 | { TRUE, TRUE, WLAN_PHY_OFDM, 2250, /* 9 Mb */ |
| 391 | 1950, 0x0f, 0x00, 4, |
| 392 | 0, 3, 1, 1, 0 }, |
| 393 | { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 12 Mb */ |
| 394 | 2500, 0x0a, 0x00, (0x80|6), |
| 395 | 2, 4, 2, 2, 0 }, |
| 396 | { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 18 Mb */ |
| 397 | 3475, 0x0e, 0x00, 9, |
| 398 | 2, 6, 2, 3, 0 }, |
| 399 | { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 25 Mb */ |
| 400 | 4325, 0x09, 0x00, (0x80|12), |
| 401 | 4, 10, 3, 4, 0 }, |
| 402 | { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 36 Mb */ |
| 403 | 5750, 0x0d, 0x00, 18, |
| 404 | 4, 14, 3, 5, 0 }, |
| 405 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 48 Mb */ |
| 406 | 6850, 0x08, 0x00, 24, |
| 407 | 4, 19, 3, 6, 0 }, |
| 408 | { TRUE, TRUE, WLAN_PHY_OFDM, 13500, /* 54 Mb */ |
| 409 | 7325, 0x0c, 0x00, 27, |
| 410 | 4, 23, 3, 7, 0 }, |
| 411 | }, |
| 412 | 50, /* probe interval */ |
| 413 | 50, /* rssi reduce interval */ |
| 414 | 0, /* Phy rates allowed initially */ |
| 415 | }; |
| 416 | |
| 417 | static struct ath_rate_table ar5416_11g_ratetable = { |
| 418 | 12, |
| 419 | { |
| 420 | { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */ |
| 421 | 900, 0x1b, 0x00, 2, |
| 422 | 0, 0, 1, 0, 0 }, |
| 423 | { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */ |
| 424 | 1900, 0x1a, 0x04, 4, |
| 425 | 1, 1, 1, 1, 0 }, |
| 426 | { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */ |
| 427 | 4900, 0x19, 0x04, 11, |
| 428 | 2, 2, 2, 2, 0 }, |
| 429 | { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */ |
| 430 | 8100, 0x18, 0x04, 22, |
| 431 | 3, 3, 2, 3, 0 }, |
| 432 | { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */ |
| 433 | 5400, 0x0b, 0x00, 12, |
| 434 | 4, 2, 1, 4, 0 }, |
| 435 | { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */ |
| 436 | 7800, 0x0f, 0x00, 18, |
| 437 | 4, 3, 1, 5, 0 }, |
| 438 | { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */ |
| 439 | 10000, 0x0a, 0x00, 24, |
| 440 | 6, 4, 1, 6, 0 }, |
| 441 | { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */ |
| 442 | 13900, 0x0e, 0x00, 36, |
| 443 | 6, 6, 2, 7, 0 }, |
| 444 | { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */ |
| 445 | 17300, 0x09, 0x00, 48, |
| 446 | 8, 10, 3, 8, 0 }, |
| 447 | { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */ |
| 448 | 23000, 0x0d, 0x00, 72, |
| 449 | 8, 14, 3, 9, 0 }, |
| 450 | { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */ |
| 451 | 27400, 0x08, 0x00, 96, |
| 452 | 8, 19, 3, 10, 0 }, |
| 453 | { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */ |
| 454 | 29300, 0x0c, 0x00, 108, |
| 455 | 8, 23, 3, 11, 0 }, |
| 456 | }, |
| 457 | 50, /* probe interval */ |
| 458 | 50, /* rssi reduce interval */ |
| 459 | 0, /* Phy rates allowed initially */ |
| 460 | }; |
| 461 | |
| 462 | static struct ath_rate_table ar5416_11b_ratetable = { |
| 463 | 4, |
| 464 | { |
| 465 | { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */ |
| 466 | 900, 0x1b, 0x00, (0x80|2), |
| 467 | 0, 0, 1, 0, 0 }, |
| 468 | { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */ |
| 469 | 1800, 0x1a, 0x04, (0x80|4), |
| 470 | 1, 1, 1, 1, 0 }, |
| 471 | { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */ |
| 472 | 4300, 0x19, 0x04, (0x80|11), |
| 473 | 1, 2, 2, 2, 0 }, |
| 474 | { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */ |
| 475 | 7100, 0x18, 0x04, (0x80|22), |
| 476 | 1, 4, 100, 3, 0 }, |
| 477 | }, |
| 478 | 100, /* probe interval */ |
| 479 | 100, /* rssi reduce interval */ |
| 480 | 0, /* Phy rates allowed initially */ |
| 481 | }; |
| 482 | |
| 483 | static void ar5416_attach_ratetables(struct ath_rate_softc *sc) |
| 484 | { |
| 485 | /* |
| 486 | * Attach rate tables. |
| 487 | */ |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 488 | sc->hw_rate_table[ATH9K_MODE_11B] = &ar5416_11b_ratetable; |
| 489 | sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable; |
| 490 | sc->hw_rate_table[ATH9K_MODE_11G] = &ar5416_11g_ratetable; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 491 | |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 492 | sc->hw_rate_table[ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable; |
| 493 | sc->hw_rate_table[ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable; |
| 494 | sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 495 | &ar5416_11na_ratetable; |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 496 | sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 497 | &ar5416_11na_ratetable; |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 498 | sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 499 | &ar5416_11ng_ratetable; |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 500 | sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 501 | &ar5416_11ng_ratetable; |
| 502 | } |
| 503 | |
| 504 | static void ar5416_setquarter_ratetable(struct ath_rate_softc *sc) |
| 505 | { |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 506 | sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Quarter; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | |
| 510 | static void ar5416_sethalf_ratetable(struct ath_rate_softc *sc) |
| 511 | { |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 512 | sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Half; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | |
| 516 | static void ar5416_setfull_ratetable(struct ath_rate_softc *sc) |
| 517 | { |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 518 | sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Return the median of three numbers |
| 524 | */ |
| 525 | static inline int8_t median(int8_t a, int8_t b, int8_t c) |
| 526 | { |
| 527 | if (a >= b) { |
| 528 | if (b >= c) |
| 529 | return b; |
| 530 | else if (a > c) |
| 531 | return c; |
| 532 | else |
| 533 | return a; |
| 534 | } else { |
| 535 | if (a >= c) |
| 536 | return a; |
| 537 | else if (b >= c) |
| 538 | return c; |
| 539 | else |
| 540 | return b; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 545 | struct ath_rate_node *ath_rc_priv) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 546 | { |
| 547 | u8 i, j, idx, idx_next; |
| 548 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 549 | for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 550 | for (j = 0; j <= i-1; j++) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 551 | idx = ath_rc_priv->valid_rate_index[j]; |
| 552 | idx_next = ath_rc_priv->valid_rate_index[j+1]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 553 | |
| 554 | if (rate_table->info[idx].ratekbps > |
| 555 | rate_table->info[idx_next].ratekbps) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 556 | ath_rc_priv->valid_rate_index[j] = idx_next; |
| 557 | ath_rc_priv->valid_rate_index[j+1] = idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | /* Access functions for valid_txrate_mask */ |
| 564 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 565 | static void ath_rc_init_valid_txmask(struct ath_rate_node *ath_rc_priv) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 566 | { |
| 567 | u8 i; |
| 568 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 569 | for (i = 0; i < ath_rc_priv->rate_table_size; i++) |
| 570 | ath_rc_priv->valid_rate_index[i] = FALSE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 573 | static inline void ath_rc_set_valid_txmask(struct ath_rate_node *ath_rc_priv, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 574 | u8 index, int valid_tx_rate) |
| 575 | { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 576 | ASSERT(index <= ath_rc_priv->rate_table_size); |
| 577 | ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? TRUE : FALSE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 580 | static inline int ath_rc_isvalid_txmask(struct ath_rate_node *ath_rc_priv, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 581 | u8 index) |
| 582 | { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 583 | ASSERT(index <= ath_rc_priv->rate_table_size); |
| 584 | return ath_rc_priv->valid_rate_index[index]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* Iterators for valid_txrate_mask */ |
| 588 | static inline int |
| 589 | ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 590 | struct ath_rate_node *ath_rc_priv, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 591 | u8 cur_valid_txrate, |
| 592 | u8 *next_idx) |
| 593 | { |
| 594 | u8 i; |
| 595 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 596 | for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) { |
| 597 | if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) { |
| 598 | *next_idx = ath_rc_priv->valid_rate_index[i+1]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 599 | return TRUE; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /* No more valid rates */ |
| 604 | *next_idx = 0; |
| 605 | return FALSE; |
| 606 | } |
| 607 | |
| 608 | /* Return true only for single stream */ |
| 609 | |
| 610 | static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw) |
| 611 | { |
| 612 | if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG)) |
| 613 | return FALSE; |
| 614 | if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG)) |
| 615 | return FALSE; |
| 616 | if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG)) |
| 617 | return FALSE; |
| 618 | if (!ignore_cw && WLAN_RC_PHY_HT(phy)) |
| 619 | if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG)) |
| 620 | return FALSE; |
| 621 | if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG)) |
| 622 | return FALSE; |
| 623 | return TRUE; |
| 624 | } |
| 625 | |
| 626 | static inline int |
| 627 | ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 628 | struct ath_rate_node *ath_rc_priv, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 629 | u8 cur_valid_txrate, u8 *next_idx) |
| 630 | { |
| 631 | int8_t i; |
| 632 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 633 | for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) { |
| 634 | if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) { |
| 635 | *next_idx = ath_rc_priv->valid_rate_index[i-1]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 636 | return TRUE; |
| 637 | } |
| 638 | } |
| 639 | return FALSE; |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * Initialize the Valid Rate Index from valid entries in Rate Table |
| 644 | */ |
| 645 | static u8 |
| 646 | ath_rc_sib_init_validrates(struct ath_rate_node *ath_rc_priv, |
| 647 | const struct ath_rate_table *rate_table, |
| 648 | u32 capflag) |
| 649 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 650 | u8 i, hi = 0; |
| 651 | u32 valid; |
| 652 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 653 | for (i = 0; i < rate_table->rate_cnt; i++) { |
| 654 | valid = (ath_rc_priv->single_stream ? |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 655 | rate_table->info[i].valid_single_stream : |
| 656 | rate_table->info[i].valid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 657 | if (valid == TRUE) { |
| 658 | u32 phy = rate_table->info[i].phy; |
| 659 | u8 valid_rate_count = 0; |
| 660 | |
| 661 | if (!ath_rc_valid_phyrate(phy, capflag, FALSE)) |
| 662 | continue; |
| 663 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 664 | valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 665 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 666 | ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i; |
| 667 | ath_rc_priv->valid_phy_ratecnt[phy] += 1; |
| 668 | ath_rc_set_valid_txmask(ath_rc_priv, i, TRUE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 669 | hi = A_MAX(hi, i); |
| 670 | } |
| 671 | } |
| 672 | return hi; |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Initialize the Valid Rate Index from Rate Set |
| 677 | */ |
| 678 | static u8 |
| 679 | ath_rc_sib_setvalid_rates(struct ath_rate_node *ath_rc_priv, |
| 680 | const struct ath_rate_table *rate_table, |
| 681 | struct ath_rateset *rateset, |
| 682 | u32 capflag) |
| 683 | { |
| 684 | /* XXX: Clean me up and make identation friendly */ |
| 685 | u8 i, j, hi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 686 | |
| 687 | /* Use intersection of working rates and valid rates */ |
| 688 | for (i = 0; i < rateset->rs_nrates; i++) { |
| 689 | for (j = 0; j < rate_table->rate_cnt; j++) { |
| 690 | u32 phy = rate_table->info[j].phy; |
| 691 | u32 valid = (ath_rc_priv->single_stream ? |
| 692 | rate_table->info[j].valid_single_stream : |
| 693 | rate_table->info[j].valid); |
| 694 | |
| 695 | /* We allow a rate only if its valid and the |
| 696 | * capflag matches one of the validity |
| 697 | * (TRUE/TRUE_20/TRUE_40) flags */ |
| 698 | |
| 699 | /* XXX: catch the negative of this branch |
| 700 | * first and then continue */ |
| 701 | if (((rateset->rs_rates[i] & 0x7F) == |
| 702 | (rate_table->info[j].dot11rate & 0x7F)) && |
| 703 | ((valid & WLAN_RC_CAP_MODE(capflag)) == |
| 704 | WLAN_RC_CAP_MODE(capflag)) && |
| 705 | !WLAN_RC_PHY_HT(phy)) { |
| 706 | |
| 707 | u8 valid_rate_count = 0; |
| 708 | |
| 709 | if (!ath_rc_valid_phyrate(phy, capflag, FALSE)) |
| 710 | continue; |
| 711 | |
| 712 | valid_rate_count = |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 713 | ath_rc_priv->valid_phy_ratecnt[phy]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 714 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 715 | ath_rc_priv->valid_phy_rateidx[phy] |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 716 | [valid_rate_count] = j; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 717 | ath_rc_priv->valid_phy_ratecnt[phy] += 1; |
| 718 | ath_rc_set_valid_txmask(ath_rc_priv, j, TRUE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 719 | hi = A_MAX(hi, j); |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | return hi; |
| 724 | } |
| 725 | |
| 726 | static u8 |
| 727 | ath_rc_sib_setvalid_htrates(struct ath_rate_node *ath_rc_priv, |
| 728 | const struct ath_rate_table *rate_table, |
| 729 | u8 *mcs_set, u32 capflag) |
| 730 | { |
| 731 | u8 i, j, hi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 732 | |
| 733 | /* Use intersection of working rates and valid rates */ |
| 734 | for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) { |
| 735 | for (j = 0; j < rate_table->rate_cnt; j++) { |
| 736 | u32 phy = rate_table->info[j].phy; |
| 737 | u32 valid = (ath_rc_priv->single_stream ? |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 738 | rate_table->info[j].valid_single_stream : |
| 739 | rate_table->info[j].valid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 740 | |
| 741 | if (((((struct ath_rateset *) |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 742 | mcs_set)->rs_rates[i] & 0x7F) != |
| 743 | (rate_table->info[j].dot11rate & 0x7F)) || |
| 744 | !WLAN_RC_PHY_HT(phy) || |
| 745 | !WLAN_RC_PHY_HT_VALID(valid, capflag)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 746 | continue; |
| 747 | |
| 748 | if (!ath_rc_valid_phyrate(phy, capflag, FALSE)) |
| 749 | continue; |
| 750 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 751 | ath_rc_priv->valid_phy_rateidx[phy] |
| 752 | [ath_rc_priv->valid_phy_ratecnt[phy]] = j; |
| 753 | ath_rc_priv->valid_phy_ratecnt[phy] += 1; |
| 754 | ath_rc_set_valid_txmask(ath_rc_priv, j, TRUE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 755 | hi = A_MAX(hi, j); |
| 756 | } |
| 757 | } |
| 758 | return hi; |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * Attach to a device instance. Setup the public definition |
| 763 | * of how much per-node space we need and setup the private |
| 764 | * phy tables that have rate control parameters. |
| 765 | */ |
| 766 | struct ath_rate_softc *ath_rate_attach(struct ath_hal *ah) |
| 767 | { |
| 768 | struct ath_rate_softc *asc; |
| 769 | |
| 770 | /* we are only in user context so we can sleep for memory */ |
| 771 | asc = kzalloc(sizeof(struct ath_rate_softc), GFP_KERNEL); |
| 772 | if (asc == NULL) |
| 773 | return NULL; |
| 774 | |
| 775 | ar5416_attach_ratetables(asc); |
| 776 | |
| 777 | /* Save Maximum TX Trigger Level (used for 11n) */ |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 778 | tx_triglevel_max = ah->ah_caps.tx_triglevel_max; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 779 | /* return alias for ath_rate_softc * */ |
| 780 | return asc; |
| 781 | } |
| 782 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 783 | void ath_rate_detach(struct ath_rate_softc *asc) |
| 784 | { |
| 785 | if (asc != NULL) |
| 786 | kfree(asc); |
| 787 | } |
| 788 | |
| 789 | u8 ath_rate_findrateix(struct ath_softc *sc, |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 790 | u8 dot11rate) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 791 | { |
| 792 | const struct ath_rate_table *ratetable; |
| 793 | struct ath_rate_softc *rsc = sc->sc_rc; |
| 794 | int i; |
| 795 | |
| 796 | ratetable = rsc->hw_rate_table[sc->sc_curmode]; |
| 797 | |
| 798 | if (WARN_ON(!ratetable)) |
| 799 | return 0; |
| 800 | |
| 801 | for (i = 0; i < ratetable->rate_cnt; i++) { |
| 802 | if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f)) |
| 803 | return i; |
| 804 | } |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Update rate-control state on a device state change. When |
| 811 | * operating as a station this includes associate/reassociate |
| 812 | * with an AP. Otherwise this gets called, for example, when |
| 813 | * the we transition to run state when operating as an AP. |
| 814 | */ |
| 815 | void ath_rate_newstate(struct ath_softc *sc, struct ath_vap *avp) |
| 816 | { |
| 817 | struct ath_rate_softc *asc = sc->sc_rc; |
| 818 | |
| 819 | /* For half and quarter rate channles use different |
| 820 | * rate tables |
| 821 | */ |
Sujith | 7c56d24 | 2008-08-11 14:05:26 +0530 | [diff] [blame] | 822 | if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_HALF) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 823 | ar5416_sethalf_ratetable(asc); |
Sujith | 7c56d24 | 2008-08-11 14:05:26 +0530 | [diff] [blame] | 824 | else if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_QUARTER) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 825 | ar5416_setquarter_ratetable(asc); |
| 826 | else /* full rate */ |
| 827 | ar5416_setfull_ratetable(asc); |
| 828 | |
| 829 | if (avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) { |
| 830 | asc->fixedrix = |
| 831 | sc->sc_rixmap[avp->av_config.av_fixed_rateset & 0xff]; |
| 832 | /* NB: check the fixed rate exists */ |
| 833 | if (asc->fixedrix == 0xff) |
| 834 | asc->fixedrix = IEEE80211_FIXED_RATE_NONE; |
| 835 | } else { |
| 836 | asc->fixedrix = IEEE80211_FIXED_RATE_NONE; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static u8 ath_rc_ratefind_ht(struct ath_softc *sc, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 841 | struct ath_rate_node *ath_rc_priv, |
| 842 | const struct ath_rate_table *rate_table, |
| 843 | int probe_allowed, int *is_probing, |
| 844 | int is_retry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 845 | { |
| 846 | u32 dt, best_thruput, this_thruput, now_msec; |
| 847 | u8 rate, next_rate, best_rate, maxindex, minindex; |
| 848 | int8_t rssi_last, rssi_reduce = 0, index = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 849 | |
| 850 | *is_probing = FALSE; |
| 851 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 852 | rssi_last = median(ath_rc_priv->rssi_last, |
| 853 | ath_rc_priv->rssi_last_prev, |
| 854 | ath_rc_priv->rssi_last_prev2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 855 | |
| 856 | /* |
| 857 | * Age (reduce) last ack rssi based on how old it is. |
| 858 | * The bizarre numbers are so the delta is 160msec, |
| 859 | * meaning we divide by 16. |
| 860 | * 0msec <= dt <= 25msec: don't derate |
| 861 | * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB |
| 862 | * 185msec <= dt: derate by 10dB |
| 863 | */ |
| 864 | |
| 865 | now_msec = jiffies_to_msecs(jiffies); |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 866 | dt = now_msec - ath_rc_priv->rssi_time; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 867 | |
| 868 | if (dt >= 185) |
| 869 | rssi_reduce = 10; |
| 870 | else if (dt >= 25) |
| 871 | rssi_reduce = (u8)((dt - 25) >> 4); |
| 872 | |
| 873 | /* Now reduce rssi_last by rssi_reduce */ |
| 874 | if (rssi_last < rssi_reduce) |
| 875 | rssi_last = 0; |
| 876 | else |
| 877 | rssi_last -= rssi_reduce; |
| 878 | |
| 879 | /* |
| 880 | * Now look up the rate in the rssi table and return it. |
| 881 | * If no rates match then we return 0 (lowest rate) |
| 882 | */ |
| 883 | |
| 884 | best_thruput = 0; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 885 | maxindex = ath_rc_priv->max_valid_rate-1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 886 | |
| 887 | minindex = 0; |
| 888 | best_rate = minindex; |
| 889 | |
| 890 | /* |
| 891 | * Try the higher rate first. It will reduce memory moving time |
| 892 | * if we have very good channel characteristics. |
| 893 | */ |
| 894 | for (index = maxindex; index >= minindex ; index--) { |
| 895 | u8 per_thres; |
| 896 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 897 | rate = ath_rc_priv->valid_rate_index[index]; |
| 898 | if (rate > ath_rc_priv->rate_max_phy) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 899 | continue; |
| 900 | |
| 901 | /* |
| 902 | * For TCP the average collision rate is around 11%, |
| 903 | * so we ignore PERs less than this. This is to |
| 904 | * prevent the rate we are currently using (whose |
| 905 | * PER might be in the 10-15 range because of TCP |
| 906 | * collisions) looking worse than the next lower |
| 907 | * rate whose PER has decayed close to 0. If we |
| 908 | * used to next lower rate, its PER would grow to |
| 909 | * 10-15 and we would be worse off then staying |
| 910 | * at the current rate. |
| 911 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 912 | per_thres = ath_rc_priv->state[rate].per; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 913 | if (per_thres < 12) |
| 914 | per_thres = 12; |
| 915 | |
| 916 | this_thruput = rate_table->info[rate].user_ratekbps * |
| 917 | (100 - per_thres); |
| 918 | |
| 919 | if (best_thruput <= this_thruput) { |
| 920 | best_thruput = this_thruput; |
| 921 | best_rate = rate; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | rate = best_rate; |
| 926 | |
| 927 | /* if we are retrying for more than half the number |
| 928 | * of max retries, use the min rate for the next retry |
| 929 | */ |
| 930 | if (is_retry) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 931 | rate = ath_rc_priv->valid_rate_index[minindex]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 932 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 933 | ath_rc_priv->rssi_last_lookup = rssi_last; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 934 | |
| 935 | /* |
| 936 | * Must check the actual rate (ratekbps) to account for |
| 937 | * non-monoticity of 11g's rate table |
| 938 | */ |
| 939 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 940 | if (rate >= ath_rc_priv->rate_max_phy && probe_allowed) { |
| 941 | rate = ath_rc_priv->rate_max_phy; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 942 | |
| 943 | /* Probe the next allowed phy state */ |
| 944 | /* FIXME:XXXX Check to make sure ratMax is checked properly */ |
| 945 | if (ath_rc_get_nextvalid_txrate(rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 946 | ath_rc_priv, rate, &next_rate) && |
| 947 | (now_msec - ath_rc_priv->probe_time > |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 948 | rate_table->probe_interval) && |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 949 | (ath_rc_priv->hw_maxretry_pktcnt >= 1)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 950 | rate = next_rate; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 951 | ath_rc_priv->probe_rate = rate; |
| 952 | ath_rc_priv->probe_time = now_msec; |
| 953 | ath_rc_priv->hw_maxretry_pktcnt = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 954 | *is_probing = TRUE; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * Make sure rate is not higher than the allowed maximum. |
| 960 | * We should also enforce the min, but I suspect the min is |
| 961 | * normally 1 rather than 0 because of the rate 9 vs 6 issue |
| 962 | * in the old code. |
| 963 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 964 | if (rate > (ath_rc_priv->rate_table_size - 1)) |
| 965 | rate = ath_rc_priv->rate_table_size - 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 966 | |
| 967 | ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) || |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 968 | (rate_table->info[rate].valid_single_stream && |
| 969 | ath_rc_priv->single_stream)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 970 | |
| 971 | return rate; |
| 972 | } |
| 973 | |
| 974 | static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table , |
| 975 | struct ath_rc_series *series, |
| 976 | u8 tries, |
| 977 | u8 rix, |
| 978 | int rtsctsenable) |
| 979 | { |
| 980 | series->tries = tries; |
| 981 | series->flags = (rtsctsenable ? ATH_RC_RTSCTS_FLAG : 0) | |
| 982 | (WLAN_RC_PHY_DS(rate_table->info[rix].phy) ? |
| 983 | ATH_RC_DS_FLAG : 0) | |
| 984 | (WLAN_RC_PHY_40(rate_table->info[rix].phy) ? |
| 985 | ATH_RC_CW40_FLAG : 0) | |
| 986 | (WLAN_RC_PHY_SGI(rate_table->info[rix].phy) ? |
| 987 | ATH_RC_SGI_FLAG : 0); |
| 988 | |
| 989 | series->rix = rate_table->info[rix].base_index; |
| 990 | series->max_4ms_framelen = rate_table->info[rix].max_4ms_framelen; |
| 991 | } |
| 992 | |
| 993 | static u8 ath_rc_rate_getidx(struct ath_softc *sc, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 994 | struct ath_rate_node *ath_rc_priv, |
| 995 | const struct ath_rate_table *rate_table, |
| 996 | u8 rix, u16 stepdown, |
| 997 | u16 min_rate) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 998 | { |
| 999 | u32 j; |
| 1000 | u8 nextindex; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1001 | |
| 1002 | if (min_rate) { |
| 1003 | for (j = RATE_TABLE_SIZE; j > 0; j--) { |
| 1004 | if (ath_rc_get_nextlowervalid_txrate(rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1005 | ath_rc_priv, rix, &nextindex)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1006 | rix = nextindex; |
| 1007 | else |
| 1008 | break; |
| 1009 | } |
| 1010 | } else { |
| 1011 | for (j = stepdown; j > 0; j--) { |
| 1012 | if (ath_rc_get_nextlowervalid_txrate(rate_table, |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1013 | ath_rc_priv, rix, &nextindex)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1014 | rix = nextindex; |
| 1015 | else |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | return rix; |
| 1020 | } |
| 1021 | |
| 1022 | static void ath_rc_ratefind(struct ath_softc *sc, |
| 1023 | struct ath_rate_node *ath_rc_priv, |
| 1024 | int num_tries, int num_rates, unsigned int rcflag, |
| 1025 | struct ath_rc_series series[], int *is_probe, |
| 1026 | int is_retry) |
| 1027 | { |
| 1028 | u8 try_per_rate = 0, i = 0, rix, nrix; |
| 1029 | struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc; |
| 1030 | struct ath_rate_table *rate_table; |
| 1031 | |
| 1032 | rate_table = |
| 1033 | (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode]; |
| 1034 | rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1035 | (rcflag & ATH_RC_PROBE_ALLOWED) ? 1 : 0, |
| 1036 | is_probe, is_retry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1037 | nrix = rix; |
| 1038 | |
| 1039 | if ((rcflag & ATH_RC_PROBE_ALLOWED) && (*is_probe)) { |
| 1040 | /* set one try for probe rates. For the |
| 1041 | * probes don't enable rts */ |
| 1042 | ath_rc_rate_set_series(rate_table, |
| 1043 | &series[i++], 1, nrix, FALSE); |
| 1044 | |
| 1045 | try_per_rate = (num_tries/num_rates); |
| 1046 | /* Get the next tried/allowed rate. No RTS for the next series |
| 1047 | * after the probe rate |
| 1048 | */ |
| 1049 | nrix = ath_rc_rate_getidx(sc, |
| 1050 | ath_rc_priv, rate_table, nrix, 1, FALSE); |
| 1051 | ath_rc_rate_set_series(rate_table, |
| 1052 | &series[i++], try_per_rate, nrix, 0); |
| 1053 | } else { |
| 1054 | try_per_rate = (num_tries/num_rates); |
| 1055 | /* Set the choosen rate. No RTS for first series entry. */ |
| 1056 | ath_rc_rate_set_series(rate_table, |
| 1057 | &series[i++], try_per_rate, nrix, FALSE); |
| 1058 | } |
| 1059 | |
| 1060 | /* Fill in the other rates for multirate retry */ |
| 1061 | for ( ; i < num_rates; i++) { |
| 1062 | u8 try_num; |
| 1063 | u8 min_rate; |
| 1064 | |
| 1065 | try_num = ((i + 1) == num_rates) ? |
| 1066 | num_tries - (try_per_rate * i) : try_per_rate ; |
| 1067 | min_rate = (((i + 1) == num_rates) && |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1068 | (rcflag & ATH_RC_MINRATE_LASTRATE)) ? 1 : 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1069 | |
| 1070 | nrix = ath_rc_rate_getidx(sc, ath_rc_priv, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1071 | rate_table, nrix, 1, min_rate); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1072 | /* All other rates in the series have RTS enabled */ |
| 1073 | ath_rc_rate_set_series(rate_table, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1074 | &series[i], try_num, nrix, TRUE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * NB:Change rate series to enable aggregation when operating |
| 1079 | * at lower MCS rates. When first rate in series is MCS2 |
| 1080 | * in HT40 @ 2.4GHz, series should look like: |
| 1081 | * |
| 1082 | * {MCS2, MCS1, MCS0, MCS0}. |
| 1083 | * |
| 1084 | * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should |
| 1085 | * look like: |
| 1086 | * |
| 1087 | * {MCS3, MCS2, MCS1, MCS1} |
| 1088 | * |
| 1089 | * So, set fourth rate in series to be same as third one for |
| 1090 | * above conditions. |
| 1091 | */ |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 1092 | if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) || |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1093 | (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) || |
| 1094 | (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1095 | u8 dot11rate = rate_table->info[rix].dot11rate; |
| 1096 | u8 phy = rate_table->info[rix].phy; |
| 1097 | if (i == 4 && |
| 1098 | ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) || |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1099 | (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1100 | series[3].rix = series[2].rix; |
| 1101 | series[3].flags = series[2].flags; |
| 1102 | series[3].max_4ms_framelen = series[2].max_4ms_framelen; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * Return the Tx rate series. |
| 1109 | */ |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 1110 | static void ath_rate_findrate(struct ath_softc *sc, |
| 1111 | struct ath_rate_node *ath_rc_priv, |
| 1112 | int num_tries, |
| 1113 | int num_rates, |
| 1114 | unsigned int rcflag, |
| 1115 | struct ath_rc_series series[], |
| 1116 | int *is_probe, |
| 1117 | int is_retry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1118 | { |
| 1119 | struct ath_vap *avp = ath_rc_priv->avp; |
| 1120 | |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1121 | DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__); |
| 1122 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1123 | if (!num_rates || !num_tries) |
| 1124 | return; |
| 1125 | |
| 1126 | if (avp->av_config.av_fixed_rateset == IEEE80211_FIXED_RATE_NONE) { |
| 1127 | ath_rc_ratefind(sc, ath_rc_priv, num_tries, num_rates, |
| 1128 | rcflag, series, is_probe, is_retry); |
| 1129 | } else { |
| 1130 | /* Fixed rate */ |
| 1131 | int idx; |
| 1132 | u8 flags; |
| 1133 | u32 rix; |
| 1134 | struct ath_rate_softc *asc = ath_rc_priv->asc; |
| 1135 | struct ath_rate_table *rate_table; |
| 1136 | |
| 1137 | rate_table = (struct ath_rate_table *) |
| 1138 | asc->hw_rate_table[sc->sc_curmode]; |
| 1139 | |
| 1140 | for (idx = 0; idx < 4; idx++) { |
| 1141 | unsigned int mcs; |
| 1142 | u8 series_rix = 0; |
| 1143 | |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1144 | series[idx].tries = IEEE80211_RATE_IDX_ENTRY( |
| 1145 | avp->av_config.av_fixed_retryset, idx); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1146 | |
| 1147 | mcs = IEEE80211_RATE_IDX_ENTRY( |
| 1148 | avp->av_config.av_fixed_rateset, idx); |
| 1149 | |
| 1150 | if (idx == 3 && (mcs & 0xf0) == 0x70) |
| 1151 | mcs = (mcs & ~0xf0)|0x80; |
| 1152 | |
| 1153 | if (!(mcs & 0x80)) |
| 1154 | flags = 0; |
| 1155 | else |
| 1156 | flags = ((ath_rc_priv->ht_cap & |
| 1157 | WLAN_RC_DS_FLAG) ? |
| 1158 | ATH_RC_DS_FLAG : 0) | |
| 1159 | ((ath_rc_priv->ht_cap & |
| 1160 | WLAN_RC_40_FLAG) ? |
| 1161 | ATH_RC_CW40_FLAG : 0) | |
| 1162 | ((ath_rc_priv->ht_cap & |
| 1163 | WLAN_RC_SGI_FLAG) ? |
| 1164 | ((ath_rc_priv->ht_cap & |
| 1165 | WLAN_RC_40_FLAG) ? |
| 1166 | ATH_RC_SGI_FLAG : 0) : 0); |
| 1167 | |
| 1168 | series[idx].rix = sc->sc_rixmap[mcs]; |
| 1169 | series_rix = series[idx].rix; |
| 1170 | |
| 1171 | /* XXX: Give me some cleanup love */ |
| 1172 | if ((flags & ATH_RC_CW40_FLAG) && |
| 1173 | (flags & ATH_RC_SGI_FLAG)) |
| 1174 | rix = rate_table->info[series_rix].ht_index; |
| 1175 | else if (flags & ATH_RC_SGI_FLAG) |
| 1176 | rix = rate_table->info[series_rix].sgi_index; |
| 1177 | else if (flags & ATH_RC_CW40_FLAG) |
| 1178 | rix = rate_table->info[series_rix].cw40index; |
| 1179 | else |
| 1180 | rix = rate_table->info[series_rix].base_index; |
| 1181 | series[idx].max_4ms_framelen = |
| 1182 | rate_table->info[rix].max_4ms_framelen; |
| 1183 | series[idx].flags = flags; |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | static void ath_rc_update_ht(struct ath_softc *sc, |
| 1189 | struct ath_rate_node *ath_rc_priv, |
| 1190 | struct ath_tx_info_priv *info_priv, |
| 1191 | int tx_rate, int xretries, int retries) |
| 1192 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1193 | u32 now_msec = jiffies_to_msecs(jiffies); |
| 1194 | int state_change = FALSE, rate, count; |
| 1195 | u8 last_per; |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1196 | struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1197 | struct ath_rate_table *rate_table = |
| 1198 | (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode]; |
| 1199 | |
| 1200 | static u32 nretry_to_per_lookup[10] = { |
| 1201 | 100 * 0 / 1, |
| 1202 | 100 * 1 / 4, |
| 1203 | 100 * 1 / 2, |
| 1204 | 100 * 3 / 4, |
| 1205 | 100 * 4 / 5, |
| 1206 | 100 * 5 / 6, |
| 1207 | 100 * 6 / 7, |
| 1208 | 100 * 7 / 8, |
| 1209 | 100 * 8 / 9, |
| 1210 | 100 * 9 / 10 |
| 1211 | }; |
| 1212 | |
| 1213 | if (!ath_rc_priv) |
| 1214 | return; |
| 1215 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1216 | ASSERT(tx_rate >= 0); |
| 1217 | if (tx_rate < 0) |
| 1218 | return; |
| 1219 | |
| 1220 | /* To compensate for some imbalance between ctrl and ext. channel */ |
| 1221 | |
| 1222 | if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy)) |
| 1223 | info_priv->tx.ts_rssi = |
| 1224 | info_priv->tx.ts_rssi < 3 ? 0 : |
| 1225 | info_priv->tx.ts_rssi - 3; |
| 1226 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1227 | last_per = ath_rc_priv->state[tx_rate].per; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1228 | |
| 1229 | if (xretries) { |
| 1230 | /* Update the PER. */ |
| 1231 | if (xretries == 1) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1232 | ath_rc_priv->state[tx_rate].per += 30; |
| 1233 | if (ath_rc_priv->state[tx_rate].per > 100) |
| 1234 | ath_rc_priv->state[tx_rate].per = 100; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1235 | } else { |
| 1236 | /* xretries == 2 */ |
Julia Lawall | 87c1687 | 2008-11-09 17:56:10 +0100 | [diff] [blame] | 1237 | count = ARRAY_SIZE(nretry_to_per_lookup); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1238 | if (retries >= count) |
| 1239 | retries = count - 1; |
| 1240 | /* new_PER = 7/8*old_PER + 1/8*(currentPER) */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1241 | ath_rc_priv->state[tx_rate].per = |
| 1242 | (u8)(ath_rc_priv->state[tx_rate].per - |
| 1243 | (ath_rc_priv->state[tx_rate].per >> 3) + |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1244 | ((100) >> 3)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /* xretries == 1 or 2 */ |
| 1248 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1249 | if (ath_rc_priv->probe_rate == tx_rate) |
| 1250 | ath_rc_priv->probe_rate = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1251 | |
| 1252 | } else { /* xretries == 0 */ |
| 1253 | /* Update the PER. */ |
| 1254 | /* Make sure it doesn't index out of array's bounds. */ |
Julia Lawall | 87c1687 | 2008-11-09 17:56:10 +0100 | [diff] [blame] | 1255 | count = ARRAY_SIZE(nretry_to_per_lookup); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1256 | if (retries >= count) |
| 1257 | retries = count - 1; |
| 1258 | if (info_priv->n_bad_frames) { |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1259 | /* new_PER = 7/8*old_PER + 1/8*(currentPER) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1260 | * Assuming that n_frames is not 0. The current PER |
| 1261 | * from the retries is 100 * retries / (retries+1), |
| 1262 | * since the first retries attempts failed, and the |
| 1263 | * next one worked. For the one that worked, |
| 1264 | * n_bad_frames subframes out of n_frames wored, |
| 1265 | * so the PER for that part is |
| 1266 | * 100 * n_bad_frames / n_frames, and it contributes |
| 1267 | * 100 * n_bad_frames / (n_frames * (retries+1)) to |
| 1268 | * the above PER. The expression below is a |
| 1269 | * simplified version of the sum of these two terms. |
| 1270 | */ |
| 1271 | if (info_priv->n_frames > 0) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1272 | ath_rc_priv->state[tx_rate].per |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1273 | = (u8) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1274 | (ath_rc_priv->state[tx_rate].per - |
| 1275 | (ath_rc_priv->state[tx_rate].per >> 3) + |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1276 | ((100*(retries*info_priv->n_frames + |
| 1277 | info_priv->n_bad_frames) / |
| 1278 | (info_priv->n_frames * |
| 1279 | (retries+1))) >> 3)); |
| 1280 | } else { |
| 1281 | /* new_PER = 7/8*old_PER + 1/8*(currentPER) */ |
| 1282 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1283 | ath_rc_priv->state[tx_rate].per = (u8) |
| 1284 | (ath_rc_priv->state[tx_rate].per - |
| 1285 | (ath_rc_priv->state[tx_rate].per >> 3) + |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1286 | (nretry_to_per_lookup[retries] >> 3)); |
| 1287 | } |
| 1288 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1289 | ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev; |
| 1290 | ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last; |
| 1291 | ath_rc_priv->rssi_last = info_priv->tx.ts_rssi; |
| 1292 | ath_rc_priv->rssi_time = now_msec; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* |
| 1295 | * If we got at most one retry then increase the max rate if |
| 1296 | * this was a probe. Otherwise, ignore the probe. |
| 1297 | */ |
| 1298 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1299 | if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1300 | if (retries > 0 || 2 * info_priv->n_bad_frames > |
| 1301 | info_priv->n_frames) { |
| 1302 | /* |
| 1303 | * Since we probed with just a single attempt, |
| 1304 | * any retries means the probe failed. Also, |
| 1305 | * if the attempt worked, but more than half |
| 1306 | * the subframes were bad then also consider |
| 1307 | * the probe a failure. |
| 1308 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1309 | ath_rc_priv->probe_rate = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1310 | } else { |
| 1311 | u8 probe_rate = 0; |
| 1312 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1313 | ath_rc_priv->rate_max_phy = ath_rc_priv->probe_rate; |
| 1314 | probe_rate = ath_rc_priv->probe_rate; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1315 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1316 | if (ath_rc_priv->state[probe_rate].per > 30) |
| 1317 | ath_rc_priv->state[probe_rate].per = 20; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1318 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1319 | ath_rc_priv->probe_rate = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1320 | |
| 1321 | /* |
| 1322 | * Since this probe succeeded, we allow the next |
| 1323 | * probe twice as soon. This allows the maxRate |
| 1324 | * to move up faster if the probes are |
| 1325 | * succesful. |
| 1326 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1327 | ath_rc_priv->probe_time = now_msec - |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1328 | rate_table->probe_interval / 2; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | if (retries > 0) { |
| 1333 | /* |
| 1334 | * Don't update anything. We don't know if |
| 1335 | * this was because of collisions or poor signal. |
| 1336 | * |
| 1337 | * Later: if rssi_ack is close to |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1338 | * ath_rc_priv->state[txRate].rssi_thres and we see lots |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1339 | * of retries, then we could increase |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1340 | * ath_rc_priv->state[txRate].rssi_thres. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1341 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1342 | ath_rc_priv->hw_maxretry_pktcnt = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1343 | } else { |
| 1344 | /* |
| 1345 | * It worked with no retries. First ignore bogus (small) |
| 1346 | * rssi_ack values. |
| 1347 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1348 | if (tx_rate == ath_rc_priv->rate_max_phy && |
| 1349 | ath_rc_priv->hw_maxretry_pktcnt < 255) { |
| 1350 | ath_rc_priv->hw_maxretry_pktcnt++; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | if (info_priv->tx.ts_rssi >= |
| 1354 | rate_table->info[tx_rate].rssi_ack_validmin) { |
| 1355 | /* Average the rssi */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1356 | if (tx_rate != ath_rc_priv->rssi_sum_rate) { |
| 1357 | ath_rc_priv->rssi_sum_rate = tx_rate; |
| 1358 | ath_rc_priv->rssi_sum = |
| 1359 | ath_rc_priv->rssi_sum_cnt = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1362 | ath_rc_priv->rssi_sum += info_priv->tx.ts_rssi; |
| 1363 | ath_rc_priv->rssi_sum_cnt++; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1364 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1365 | if (ath_rc_priv->rssi_sum_cnt > 4) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1366 | int32_t rssi_ackAvg = |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1367 | (ath_rc_priv->rssi_sum + 2) / 4; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1368 | int8_t rssi_thres = |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1369 | ath_rc_priv->state[tx_rate]. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1370 | rssi_thres; |
| 1371 | int8_t rssi_ack_vmin = |
| 1372 | rate_table->info[tx_rate]. |
| 1373 | rssi_ack_validmin; |
| 1374 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1375 | ath_rc_priv->rssi_sum = |
| 1376 | ath_rc_priv->rssi_sum_cnt = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1377 | |
| 1378 | /* Now reduce the current |
| 1379 | * rssi threshold. */ |
| 1380 | if ((rssi_ackAvg < rssi_thres + 2) && |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1381 | (rssi_thres > rssi_ack_vmin)) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1382 | ath_rc_priv->state[tx_rate]. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1383 | rssi_thres--; |
| 1384 | } |
| 1385 | |
| 1386 | state_change = TRUE; |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /* For all cases */ |
| 1393 | |
| 1394 | /* |
| 1395 | * If this rate looks bad (high PER) then stop using it for |
| 1396 | * a while (except if we are probing). |
| 1397 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1398 | if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 && |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1399 | rate_table->info[tx_rate].ratekbps <= |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1400 | rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) { |
| 1401 | ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv, |
| 1402 | (u8) tx_rate, &ath_rc_priv->rate_max_phy); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1403 | |
| 1404 | /* Don't probe for a little while. */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1405 | ath_rc_priv->probe_time = now_msec; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | if (state_change) { |
| 1409 | /* |
| 1410 | * Make sure the rates above this have higher rssi thresholds. |
| 1411 | * (Note: Monotonicity is kept within the OFDM rates and |
| 1412 | * within the CCK rates. However, no adjustment is |
| 1413 | * made to keep the rssi thresholds monotonically |
| 1414 | * increasing between the CCK and OFDM rates.) |
| 1415 | */ |
| 1416 | for (rate = tx_rate; rate < |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1417 | ath_rc_priv->rate_table_size - 1; rate++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1418 | if (rate_table->info[rate+1].phy != |
| 1419 | rate_table->info[tx_rate].phy) |
| 1420 | break; |
| 1421 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1422 | if (ath_rc_priv->state[rate].rssi_thres + |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1423 | rate_table->info[rate].rssi_ack_deltamin > |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1424 | ath_rc_priv->state[rate+1].rssi_thres) { |
| 1425 | ath_rc_priv->state[rate+1].rssi_thres = |
| 1426 | ath_rc_priv->state[rate]. |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1427 | rssi_thres + |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1428 | rate_table->info[rate]. |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1429 | rssi_ack_deltamin; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /* Make sure the rates below this have lower rssi thresholds. */ |
| 1434 | for (rate = tx_rate - 1; rate >= 0; rate--) { |
| 1435 | if (rate_table->info[rate].phy != |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1436 | rate_table->info[tx_rate].phy) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1439 | if (ath_rc_priv->state[rate].rssi_thres + |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1440 | rate_table->info[rate].rssi_ack_deltamin > |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1441 | ath_rc_priv->state[rate+1].rssi_thres) { |
| 1442 | if (ath_rc_priv->state[rate+1].rssi_thres < |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1443 | rate_table->info[rate]. |
| 1444 | rssi_ack_deltamin) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1445 | ath_rc_priv->state[rate].rssi_thres = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1446 | else { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1447 | ath_rc_priv->state[rate].rssi_thres = |
| 1448 | ath_rc_priv->state[rate+1]. |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1449 | rssi_thres - |
| 1450 | rate_table->info[rate]. |
| 1451 | rssi_ack_deltamin; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1454 | if (ath_rc_priv->state[rate].rssi_thres < |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1455 | rate_table->info[rate]. |
| 1456 | rssi_ack_validmin) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1457 | ath_rc_priv->state[rate].rssi_thres = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1458 | rate_table->info[rate]. |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1459 | rssi_ack_validmin; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | /* Make sure the rates below this have lower PER */ |
| 1466 | /* Monotonicity is kept only for rates below the current rate. */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1467 | if (ath_rc_priv->state[tx_rate].per < last_per) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1468 | for (rate = tx_rate - 1; rate >= 0; rate--) { |
| 1469 | if (rate_table->info[rate].phy != |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1470 | rate_table->info[tx_rate].phy) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1473 | if (ath_rc_priv->state[rate].per > |
| 1474 | ath_rc_priv->state[rate+1].per) { |
| 1475 | ath_rc_priv->state[rate].per = |
| 1476 | ath_rc_priv->state[rate+1].per; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | /* Maintain monotonicity for rates above the current rate */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1482 | for (rate = tx_rate; rate < ath_rc_priv->rate_table_size - 1; rate++) { |
| 1483 | if (ath_rc_priv->state[rate+1].per < ath_rc_priv->state[rate].per) |
| 1484 | ath_rc_priv->state[rate+1].per = |
| 1485 | ath_rc_priv->state[rate].per; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /* Every so often, we reduce the thresholds and |
| 1489 | * PER (different for CCK and OFDM). */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1490 | if (now_msec - ath_rc_priv->rssi_down_time >= |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1491 | rate_table->rssi_reduce_interval) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1492 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1493 | for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) { |
| 1494 | if (ath_rc_priv->state[rate].rssi_thres > |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1495 | rate_table->info[rate].rssi_ack_validmin) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1496 | ath_rc_priv->state[rate].rssi_thres -= 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1497 | } |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1498 | ath_rc_priv->rssi_down_time = now_msec; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /* Every so often, we reduce the thresholds |
| 1502 | * and PER (different for CCK and OFDM). */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1503 | if (now_msec - ath_rc_priv->per_down_time >= |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1504 | rate_table->rssi_reduce_interval) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1505 | for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) { |
| 1506 | ath_rc_priv->state[rate].per = |
| 1507 | 7 * ath_rc_priv->state[rate].per / 8; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1510 | ath_rc_priv->per_down_time = now_msec; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | /* |
| 1515 | * This routine is called in rate control callback tx_status() to give |
| 1516 | * the status of previous frames. |
| 1517 | */ |
| 1518 | static void ath_rc_update(struct ath_softc *sc, |
| 1519 | struct ath_rate_node *ath_rc_priv, |
| 1520 | struct ath_tx_info_priv *info_priv, int final_ts_idx, |
| 1521 | int xretries, int long_retry) |
| 1522 | { |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1523 | struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1524 | struct ath_rate_table *rate_table; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1525 | struct ath_rc_series rcs[4]; |
| 1526 | u8 flags; |
| 1527 | u32 series = 0, rix; |
| 1528 | |
| 1529 | memcpy(rcs, info_priv->rcs, 4 * sizeof(rcs[0])); |
| 1530 | rate_table = (struct ath_rate_table *) |
| 1531 | asc->hw_rate_table[sc->sc_curmode]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1532 | ASSERT(rcs[0].tries != 0); |
| 1533 | |
| 1534 | /* |
| 1535 | * If the first rate is not the final index, there |
| 1536 | * are intermediate rate failures to be processed. |
| 1537 | */ |
| 1538 | if (final_ts_idx != 0) { |
| 1539 | /* Process intermediate rates that failed.*/ |
| 1540 | for (series = 0; series < final_ts_idx ; series++) { |
| 1541 | if (rcs[series].tries != 0) { |
| 1542 | flags = rcs[series].flags; |
| 1543 | /* If HT40 and we have switched mode from |
| 1544 | * 40 to 20 => don't update */ |
| 1545 | if ((flags & ATH_RC_CW40_FLAG) && |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1546 | (ath_rc_priv->rc_phy_mode != |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1547 | (flags & ATH_RC_CW40_FLAG))) |
| 1548 | return; |
| 1549 | if ((flags & ATH_RC_CW40_FLAG) && |
| 1550 | (flags & ATH_RC_SGI_FLAG)) |
| 1551 | rix = rate_table->info[ |
| 1552 | rcs[series].rix].ht_index; |
| 1553 | else if (flags & ATH_RC_SGI_FLAG) |
| 1554 | rix = rate_table->info[ |
| 1555 | rcs[series].rix].sgi_index; |
| 1556 | else if (flags & ATH_RC_CW40_FLAG) |
| 1557 | rix = rate_table->info[ |
| 1558 | rcs[series].rix].cw40index; |
| 1559 | else |
| 1560 | rix = rate_table->info[ |
| 1561 | rcs[series].rix].base_index; |
| 1562 | ath_rc_update_ht(sc, ath_rc_priv, |
| 1563 | info_priv, rix, |
| 1564 | xretries ? 1 : 2, |
| 1565 | rcs[series].tries); |
| 1566 | } |
| 1567 | } |
| 1568 | } else { |
| 1569 | /* |
| 1570 | * Handle the special case of MIMO PS burst, where the second |
| 1571 | * aggregate is sent out with only one rate and one try. |
| 1572 | * Treating it as an excessive retry penalizes the rate |
| 1573 | * inordinately. |
| 1574 | */ |
| 1575 | if (rcs[0].tries == 1 && xretries == 1) |
| 1576 | xretries = 2; |
| 1577 | } |
| 1578 | |
| 1579 | flags = rcs[series].flags; |
| 1580 | /* If HT40 and we have switched mode from 40 to 20 => don't update */ |
| 1581 | if ((flags & ATH_RC_CW40_FLAG) && |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1582 | (ath_rc_priv->rc_phy_mode != (flags & ATH_RC_CW40_FLAG))) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1583 | return; |
| 1584 | |
| 1585 | if ((flags & ATH_RC_CW40_FLAG) && (flags & ATH_RC_SGI_FLAG)) |
| 1586 | rix = rate_table->info[rcs[series].rix].ht_index; |
| 1587 | else if (flags & ATH_RC_SGI_FLAG) |
| 1588 | rix = rate_table->info[rcs[series].rix].sgi_index; |
| 1589 | else if (flags & ATH_RC_CW40_FLAG) |
| 1590 | rix = rate_table->info[rcs[series].rix].cw40index; |
| 1591 | else |
| 1592 | rix = rate_table->info[rcs[series].rix].base_index; |
| 1593 | |
| 1594 | ath_rc_update_ht(sc, ath_rc_priv, info_priv, rix, |
| 1595 | xretries, long_retry); |
| 1596 | } |
| 1597 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1598 | /* |
| 1599 | * Process a tx descriptor for a completed transmit (success or failure). |
| 1600 | */ |
| 1601 | static void ath_rate_tx_complete(struct ath_softc *sc, |
| 1602 | struct ath_node *an, |
| 1603 | struct ath_rate_node *rc_priv, |
| 1604 | struct ath_tx_info_priv *info_priv) |
| 1605 | { |
| 1606 | int final_ts_idx = info_priv->tx.ts_rateindex; |
| 1607 | int tx_status = 0, is_underrun = 0; |
| 1608 | struct ath_vap *avp; |
| 1609 | |
| 1610 | avp = rc_priv->avp; |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1611 | if ((avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) || |
| 1612 | (info_priv->tx.ts_status & ATH9K_TXERR_FILT)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1613 | return; |
| 1614 | |
| 1615 | if (info_priv->tx.ts_rssi > 0) { |
| 1616 | ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi, |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1617 | info_priv->tx.ts_rssi); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | * If underrun error is seen assume it as an excessive retry only |
| 1622 | * if prefetch trigger level have reached the max (0x3f for 5416) |
| 1623 | * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY |
| 1624 | * times. This affects how ratectrl updates PER for the failed rate. |
| 1625 | */ |
| 1626 | if (info_priv->tx.ts_flags & |
| 1627 | (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) && |
| 1628 | ((sc->sc_ah->ah_txTrigLevel) >= tx_triglevel_max)) { |
| 1629 | tx_status = 1; |
| 1630 | is_underrun = 1; |
| 1631 | } |
| 1632 | |
| 1633 | if ((info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) || |
| 1634 | (info_priv->tx.ts_status & ATH9K_TXERR_FIFO)) |
| 1635 | tx_status = 1; |
| 1636 | |
| 1637 | ath_rc_update(sc, rc_priv, info_priv, final_ts_idx, tx_status, |
| 1638 | (is_underrun) ? ATH_11N_TXMAXTRY : |
| 1639 | info_priv->tx.ts_longretry); |
| 1640 | } |
| 1641 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1642 | /* |
| 1643 | * Update the SIB's rate control information |
| 1644 | * |
| 1645 | * This should be called when the supported rates change |
| 1646 | * (e.g. SME operation, wireless mode change) |
| 1647 | * |
| 1648 | * It will determine which rates are valid for use. |
| 1649 | */ |
| 1650 | static void ath_rc_sib_update(struct ath_softc *sc, |
| 1651 | struct ath_rate_node *ath_rc_priv, |
| 1652 | u32 capflag, int keep_state, |
| 1653 | struct ath_rateset *negotiated_rates, |
| 1654 | struct ath_rateset *negotiated_htrates) |
| 1655 | { |
| 1656 | struct ath_rate_table *rate_table = NULL; |
| 1657 | struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc; |
| 1658 | struct ath_rateset *rateset = negotiated_rates; |
| 1659 | u8 *ht_mcs = (u8 *)negotiated_htrates; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1660 | u8 i, j, k, hi = 0, hthi = 0; |
| 1661 | |
| 1662 | rate_table = (struct ath_rate_table *) |
| 1663 | asc->hw_rate_table[sc->sc_curmode]; |
| 1664 | |
| 1665 | /* Initial rate table size. Will change depending |
| 1666 | * on the working rate set */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1667 | ath_rc_priv->rate_table_size = MAX_TX_RATE_TBL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1668 | |
| 1669 | /* Initialize thresholds according to the global rate table */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1670 | for (i = 0 ; (i < ath_rc_priv->rate_table_size) && (!keep_state); i++) { |
| 1671 | ath_rc_priv->state[i].rssi_thres = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1672 | rate_table->info[i].rssi_ack_validmin; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1673 | ath_rc_priv->state[i].per = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | /* Determine the valid rates */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1677 | ath_rc_init_valid_txmask(ath_rc_priv); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1678 | |
| 1679 | for (i = 0; i < WLAN_RC_PHY_MAX; i++) { |
| 1680 | for (j = 0; j < MAX_TX_RATE_PHY; j++) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1681 | ath_rc_priv->valid_phy_rateidx[i][j] = 0; |
| 1682 | ath_rc_priv->valid_phy_ratecnt[i] = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1683 | } |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1684 | ath_rc_priv->rc_phy_mode = (capflag & WLAN_RC_40_FLAG); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1685 | |
| 1686 | /* Set stream capability */ |
| 1687 | ath_rc_priv->single_stream = (capflag & WLAN_RC_DS_FLAG) ? 0 : 1; |
| 1688 | |
| 1689 | if (!rateset->rs_nrates) { |
| 1690 | /* No working rate, just initialize valid rates */ |
| 1691 | hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table, |
| 1692 | capflag); |
| 1693 | } else { |
| 1694 | /* Use intersection of working rates and valid rates */ |
| 1695 | hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table, |
| 1696 | rateset, capflag); |
| 1697 | if (capflag & WLAN_RC_HT_FLAG) { |
| 1698 | hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv, |
| 1699 | rate_table, |
| 1700 | ht_mcs, |
| 1701 | capflag); |
| 1702 | } |
| 1703 | hi = A_MAX(hi, hthi); |
| 1704 | } |
| 1705 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1706 | ath_rc_priv->rate_table_size = hi + 1; |
| 1707 | ath_rc_priv->rate_max_phy = 0; |
| 1708 | ASSERT(ath_rc_priv->rate_table_size <= MAX_TX_RATE_TBL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1709 | |
| 1710 | for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) { |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1711 | for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) { |
| 1712 | ath_rc_priv->valid_rate_index[k++] = |
| 1713 | ath_rc_priv->valid_phy_rateidx[i][j]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, TRUE) |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1717 | || !ath_rc_priv->valid_phy_ratecnt[i]) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1718 | continue; |
| 1719 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1720 | ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1721 | } |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1722 | ASSERT(ath_rc_priv->rate_table_size <= MAX_TX_RATE_TBL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1723 | ASSERT(k <= MAX_TX_RATE_TBL); |
| 1724 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1725 | ath_rc_priv->max_valid_rate = k; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1726 | /* |
| 1727 | * Some third party vendors don't send the supported rate series in |
| 1728 | * order. So sorting to make sure its in order, otherwise our RateFind |
| 1729 | * Algo will select wrong rates |
| 1730 | */ |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 1731 | ath_rc_sort_validrates(rate_table, ath_rc_priv); |
| 1732 | ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /* |
| 1736 | * Update rate-control state on station associate/reassociate. |
| 1737 | */ |
| 1738 | static int ath_rate_newassoc(struct ath_softc *sc, |
| 1739 | struct ath_rate_node *ath_rc_priv, |
| 1740 | unsigned int capflag, |
| 1741 | struct ath_rateset *negotiated_rates, |
| 1742 | struct ath_rateset *negotiated_htrates) |
| 1743 | { |
| 1744 | |
| 1745 | |
| 1746 | ath_rc_priv->ht_cap = |
| 1747 | ((capflag & ATH_RC_DS_FLAG) ? WLAN_RC_DS_FLAG : 0) | |
| 1748 | ((capflag & ATH_RC_SGI_FLAG) ? WLAN_RC_SGI_FLAG : 0) | |
| 1749 | ((capflag & ATH_RC_HT_FLAG) ? WLAN_RC_HT_FLAG : 0) | |
| 1750 | ((capflag & ATH_RC_CW40_FLAG) ? WLAN_RC_40_FLAG : 0); |
| 1751 | |
| 1752 | ath_rc_sib_update(sc, ath_rc_priv, ath_rc_priv->ht_cap, 0, |
| 1753 | negotiated_rates, negotiated_htrates); |
| 1754 | |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1758 | void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv) |
| 1759 | { |
| 1760 | struct ath_softc *sc = hw->priv; |
| 1761 | u32 capflag = 0; |
| 1762 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1763 | if (hw->conf.ht.enabled) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1764 | capflag |= ATH_RC_HT_FLAG | ATH_RC_DS_FLAG; |
| 1765 | if (sc->sc_ht_info.tx_chan_width == ATH9K_HT_MACMODE_2040) |
| 1766 | capflag |= ATH_RC_CW40_FLAG; |
| 1767 | } |
| 1768 | |
| 1769 | ath_rate_newassoc(sc, rc_priv, capflag, |
| 1770 | &rc_priv->neg_rates, |
| 1771 | &rc_priv->neg_ht_rates); |
| 1772 | |
| 1773 | } |
| 1774 | |
| 1775 | /* Rate Control callbacks */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1776 | static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband, |
| 1777 | struct ieee80211_sta *sta, void *priv_sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1778 | struct sk_buff *skb) |
| 1779 | { |
| 1780 | struct ath_softc *sc = priv; |
| 1781 | struct ath_tx_info_priv *tx_info_priv; |
| 1782 | struct ath_node *an; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1783 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 1784 | struct ieee80211_hdr *hdr; |
| 1785 | __le16 fc; |
| 1786 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1787 | hdr = (struct ieee80211_hdr *)skb->data; |
| 1788 | fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1789 | /* XXX: UGLY HACK!! */ |
| 1790 | tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1791 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1792 | an = (struct ath_node *)sta->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1793 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1794 | if (tx_info_priv == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1795 | return; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1796 | |
| 1797 | if (an && priv_sta && ieee80211_is_data(fc)) |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1798 | ath_rate_tx_complete(sc, an, priv_sta, tx_info_priv); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1799 | |
| 1800 | kfree(tx_info_priv); |
| 1801 | tx_info->control.vif = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1804 | static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta, |
| 1805 | struct ieee80211_tx_rate_control *txrc) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1806 | { |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1807 | struct ieee80211_supported_band *sband = txrc->sband; |
| 1808 | struct sk_buff *skb = txrc->skb; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1809 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1810 | struct ath_softc *sc = priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1811 | struct ieee80211_hw *hw = sc->hw; |
| 1812 | struct ath_tx_info_priv *tx_info_priv; |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1813 | struct ath_rate_node *ath_rc_priv = priv_sta; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1814 | struct ath_node *an; |
| 1815 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 1816 | int is_probe = FALSE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1817 | s8 lowest_idx; |
| 1818 | __le16 fc = hdr->frame_control; |
| 1819 | u8 *qc, tid; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1820 | |
| 1821 | DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__); |
| 1822 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1823 | /* allocate driver private area of tx_info, XXX: UGLY HACK! */ |
| 1824 | tx_info->control.vif = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC); |
| 1825 | tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif; |
| 1826 | ASSERT(tx_info_priv != NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1827 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1828 | lowest_idx = rate_lowest_index(sband, sta); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1829 | tx_info_priv->min_rate = (sband->bitrates[lowest_idx].bitrate * 2) / 10; |
| 1830 | /* lowest rate for management and multicast/broadcast frames */ |
| 1831 | if (!ieee80211_is_data(fc) || |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1832 | is_multicast_ether_addr(hdr->addr1) || !sta) { |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1833 | tx_info->control.rates[0].idx = lowest_idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1834 | return; |
| 1835 | } |
| 1836 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1837 | /* Find tx rate for unicast frames */ |
| 1838 | ath_rate_findrate(sc, ath_rc_priv, |
| 1839 | ATH_11N_TXMAXTRY, 4, |
| 1840 | ATH_RC_PROBE_ALLOWED, |
| 1841 | tx_info_priv->rcs, |
| 1842 | &is_probe, |
| 1843 | false); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1844 | #if 0 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1845 | if (is_probe) |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1846 | sel->probe_idx = ath_rc_priv->tx_ratectrl.probe_rate; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1847 | #endif |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1848 | |
| 1849 | /* Ratecontrol sometimes returns invalid rate index */ |
| 1850 | if (tx_info_priv->rcs[0].rix != 0xff) |
| 1851 | ath_rc_priv->prev_data_rix = tx_info_priv->rcs[0].rix; |
| 1852 | else |
| 1853 | tx_info_priv->rcs[0].rix = ath_rc_priv->prev_data_rix; |
| 1854 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1855 | tx_info->control.rates[0].idx = tx_info_priv->rcs[0].rix; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1856 | |
| 1857 | /* Check if aggregation has to be enabled for this tid */ |
| 1858 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1859 | if (hw->conf.ht.enabled) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1860 | if (ieee80211_is_data_qos(fc)) { |
| 1861 | qc = ieee80211_get_qos_ctl(hdr); |
| 1862 | tid = qc[0] & 0xf; |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1863 | an = (struct ath_node *)sta->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1864 | |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 1865 | if(ath_tx_aggr_check(sc, an, tid)) |
| 1866 | ieee80211_start_tx_ba_session(hw, hdr->addr1, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | } |
| 1870 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1871 | static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband, |
| 1872 | struct ieee80211_sta *sta, void *priv_sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1873 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1874 | struct ath_softc *sc = priv; |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1875 | struct ath_rate_node *ath_rc_priv = priv_sta; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1876 | int i, j = 0; |
| 1877 | |
Sujith | 7b4d273 | 2008-11-18 09:04:00 +0530 | [diff] [blame^] | 1878 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1879 | if (sta->supp_rates[sband->band] & BIT(i)) { |
| 1880 | ath_rc_priv->neg_rates.rs_rates[j] |
| 1881 | = (sband->bitrates[i].bitrate * 2) / 10; |
| 1882 | j++; |
| 1883 | } |
| 1884 | } |
| 1885 | ath_rc_priv->neg_rates.rs_nrates = j; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1886 | |
Sujith | a4510bf | 2008-10-23 12:15:19 +0530 | [diff] [blame] | 1887 | if (sta->ht_cap.ht_supported) { |
Sujith | 7b4d273 | 2008-11-18 09:04:00 +0530 | [diff] [blame^] | 1888 | for (i = 0, j = 0; i < 77; i++) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1889 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1890 | ath_rc_priv->neg_ht_rates.rs_rates[j++] = i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1891 | if (j == ATH_RATE_MAX) |
| 1892 | break; |
| 1893 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1894 | ath_rc_priv->neg_ht_rates.rs_nrates = j; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1895 | } |
Sujith | 7b4d273 | 2008-11-18 09:04:00 +0530 | [diff] [blame^] | 1896 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1897 | ath_rc_node_update(sc->hw, priv_sta); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1900 | static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1901 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1902 | return hw->priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | static void ath_rate_free(void *priv) |
| 1906 | { |
| 1907 | return; |
| 1908 | } |
| 1909 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1910 | static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1911 | { |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1912 | struct ieee80211_vif *vif; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1913 | struct ath_softc *sc = priv; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1914 | struct ath_vap *avp; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1915 | struct ath_rate_node *rate_priv; |
| 1916 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1917 | vif = sc->sc_vaps[0]; |
| 1918 | ASSERT(vif); |
| 1919 | |
| 1920 | avp = (void *)vif->drv_priv; |
| 1921 | |
Sujith | fe60594 | 2008-11-18 09:03:36 +0530 | [diff] [blame] | 1922 | rate_priv = kzalloc(sizeof(struct ath_rate_node), gfp); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1923 | if (!rate_priv) { |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1924 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1925 | "%s: Unable to allocate private rc structure\n", |
| 1926 | __func__); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1927 | return NULL; |
| 1928 | } |
Sujith | fe60594 | 2008-11-18 09:03:36 +0530 | [diff] [blame] | 1929 | |
| 1930 | rate_priv->avp = avp; |
| 1931 | rate_priv->asc = sc->sc_rc; |
| 1932 | avp->rc_node = rate_priv; |
| 1933 | rate_priv->rssi_down_time = jiffies_to_msecs(jiffies); |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 1934 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1935 | return rate_priv; |
| 1936 | } |
| 1937 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1938 | static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta, |
| 1939 | void *priv_sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1940 | { |
| 1941 | struct ath_rate_node *rate_priv = priv_sta; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1942 | |
Sujith | fe60594 | 2008-11-18 09:03:36 +0530 | [diff] [blame] | 1943 | kfree(rate_priv); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | static struct rate_control_ops ath_rate_ops = { |
| 1947 | .module = NULL, |
| 1948 | .name = "ath9k_rate_control", |
| 1949 | .tx_status = ath_tx_status, |
| 1950 | .get_rate = ath_get_rate, |
| 1951 | .rate_init = ath_rate_init, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1952 | .alloc = ath_rate_alloc, |
| 1953 | .free = ath_rate_free, |
| 1954 | .alloc_sta = ath_rate_alloc_sta, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1955 | .free_sta = ath_rate_free_sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1956 | }; |
| 1957 | |
| 1958 | int ath_rate_control_register(void) |
| 1959 | { |
| 1960 | return ieee80211_rate_control_register(&ath_rate_ops); |
| 1961 | } |
| 1962 | |
| 1963 | void ath_rate_control_unregister(void) |
| 1964 | { |
| 1965 | ieee80211_rate_control_unregister(&ath_rate_ops); |
| 1966 | } |
| 1967 | |