blob: 51f51afa6da978df9a11fc9a6bdfeb31d27b0987 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
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
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070018#include "core.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020static struct ath_rate_table ar5416_11na_ratetable = {
21 42,
Sujithe63835b2008-11-18 09:07:53 +053022 {0},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023 {
Sujith46d14a52008-11-18 09:08:13 +053024 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070025 5400, 0x0b, 0x00, 12,
26 0, 2, 1, 0, 0, 0, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +053027 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028 7800, 0x0f, 0x00, 18,
29 0, 3, 1, 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +053030 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031 10000, 0x0a, 0x00, 24,
32 2, 4, 2, 2, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +053033 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070034 13900, 0x0e, 0x00, 36,
35 2, 6, 2, 3, 3, 3, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +053036 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037 17300, 0x09, 0x00, 48,
38 4, 10, 3, 4, 4, 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +053039 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040 23000, 0x0d, 0x00, 72,
41 4, 14, 3, 5, 5, 5, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +053042 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070043 27400, 0x08, 0x00, 96,
44 4, 20, 3, 6, 6, 6, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +053045 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070046 29300, 0x0c, 0x00, 108,
47 4, 23, 3, 7, 7, 7, 7, 0 },
Sujith46d14a52008-11-18 09:08:13 +053048 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070049 6400, 0x80, 0x00, 0,
50 0, 2, 3, 8, 24, 8, 24, 3216 },
Sujith46d14a52008-11-18 09:08:13 +053051 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070052 12700, 0x81, 0x00, 1,
53 2, 4, 3, 9, 25, 9, 25, 6434 },
Sujith46d14a52008-11-18 09:08:13 +053054 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070055 18800, 0x82, 0x00, 2,
56 2, 6, 3, 10, 26, 10, 26, 9650 },
Sujith46d14a52008-11-18 09:08:13 +053057 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070058 25000, 0x83, 0x00, 3,
59 4, 10, 3, 11, 27, 11, 27, 12868 },
Sujith46d14a52008-11-18 09:08:13 +053060 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061 36700, 0x84, 0x00, 4,
62 4, 14, 3, 12, 28, 12, 28, 19304 },
Sujith46d14a52008-11-18 09:08:13 +053063 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070064 48100, 0x85, 0x00, 5,
65 4, 20, 3, 13, 29, 13, 29, 25740 },
Sujith46d14a52008-11-18 09:08:13 +053066 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070067 53500, 0x86, 0x00, 6,
68 4, 23, 3, 14, 30, 14, 30, 28956 },
Sujith46d14a52008-11-18 09:08:13 +053069 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 59000, 0x87, 0x00, 7,
71 4, 25, 3, 15, 31, 15, 32, 32180 },
Sujith46d14a52008-11-18 09:08:13 +053072 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073 12700, 0x88, 0x00,
74 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
Sujith46d14a52008-11-18 09:08:13 +053075 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076 24800, 0x89, 0x00, 9,
77 2, 4, 3, 17, 34, 17, 34, 12860 },
Sujith46d14a52008-11-18 09:08:13 +053078 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070079 36600, 0x8a, 0x00, 10,
80 2, 6, 3, 18, 35, 18, 35, 19300 },
Sujith46d14a52008-11-18 09:08:13 +053081 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070082 48100, 0x8b, 0x00, 11,
83 4, 10, 3, 19, 36, 19, 36, 25736 },
Sujith46d14a52008-11-18 09:08:13 +053084 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085 69500, 0x8c, 0x00, 12,
86 4, 14, 3, 20, 37, 20, 37, 38600 },
Sujith46d14a52008-11-18 09:08:13 +053087 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088 89500, 0x8d, 0x00, 13,
89 4, 20, 3, 21, 38, 21, 38, 51472 },
Sujith46d14a52008-11-18 09:08:13 +053090 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070091 98900, 0x8e, 0x00, 14,
92 4, 23, 3, 22, 39, 22, 39, 57890 },
Sujith46d14a52008-11-18 09:08:13 +053093 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 108300, 0x8f, 0x00, 15,
95 4, 25, 3, 23, 40, 23, 41, 64320 },
Sujith46d14a52008-11-18 09:08:13 +053096 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097 13200, 0x80, 0x00, 0,
98 0, 2, 3, 8, 24, 24, 24, 6684 },
Sujith46d14a52008-11-18 09:08:13 +053099 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100 25900, 0x81, 0x00, 1,
101 2, 4, 3, 9, 25, 25, 25, 13368 },
Sujith46d14a52008-11-18 09:08:13 +0530102 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700103 38600, 0x82, 0x00, 2,
104 2, 6, 3, 10, 26, 26, 26, 20052 },
Sujith46d14a52008-11-18 09:08:13 +0530105 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700106 49800, 0x83, 0x00, 3,
107 4, 10, 3, 11, 27, 27, 27, 26738 },
Sujith46d14a52008-11-18 09:08:13 +0530108 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700109 72200, 0x84, 0x00, 4,
110 4, 14, 3, 12, 28, 28, 28, 40104 },
Sujith46d14a52008-11-18 09:08:13 +0530111 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700112 92900, 0x85, 0x00, 5,
113 4, 20, 3, 13, 29, 29, 29, 53476 },
Sujith46d14a52008-11-18 09:08:13 +0530114 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 102700, 0x86, 0x00, 6,
116 4, 23, 3, 14, 30, 30, 30, 60156 },
Sujith46d14a52008-11-18 09:08:13 +0530117 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118 112000, 0x87, 0x00, 7,
119 4, 25, 3, 15, 31, 32, 32, 66840 },
Sujith46d14a52008-11-18 09:08:13 +0530120 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121 122000, 0x87, 0x00, 7,
122 4, 25, 3, 15, 31, 32, 32, 74200 },
Sujith46d14a52008-11-18 09:08:13 +0530123 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124 25800, 0x88, 0x00, 8,
125 0, 2, 3, 16, 33, 33, 33, 13360 },
Sujith46d14a52008-11-18 09:08:13 +0530126 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700127 49800, 0x89, 0x00, 9,
128 2, 4, 3, 17, 34, 34, 34, 26720 },
Sujith46d14a52008-11-18 09:08:13 +0530129 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130 71900, 0x8a, 0x00, 10,
131 2, 6, 3, 18, 35, 35, 35, 40080 },
Sujith46d14a52008-11-18 09:08:13 +0530132 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700133 92500, 0x8b, 0x00, 11,
134 4, 10, 3, 19, 36, 36, 36, 53440 },
Sujith46d14a52008-11-18 09:08:13 +0530135 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700136 130300, 0x8c, 0x00, 12,
137 4, 14, 3, 20, 37, 37, 37, 80160 },
Sujith46d14a52008-11-18 09:08:13 +0530138 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700139 162800, 0x8d, 0x00, 13,
140 4, 20, 3, 21, 38, 38, 38, 106880 },
Sujith46d14a52008-11-18 09:08:13 +0530141 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142 178200, 0x8e, 0x00, 14,
143 4, 23, 3, 22, 39, 39, 39, 120240 },
Sujith46d14a52008-11-18 09:08:13 +0530144 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700145 192100, 0x8f, 0x00, 15,
146 4, 25, 3, 23, 40, 41, 41, 133600 },
Sujith46d14a52008-11-18 09:08:13 +0530147 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700148 207000, 0x8f, 0x00, 15,
149 4, 25, 3, 23, 40, 41, 41, 148400 },
150 },
151 50, /* probe interval */
152 50, /* rssi reduce interval */
153 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
154};
155
Sujith46d14a52008-11-18 09:08:13 +0530156/* VALID_ALL - valid for 20/40/Legacy,
157 * VALID - Legacy only,
158 * VALID_20 - HT 20 only,
159 * VALID_40 - HT 40 only */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700160
161/* 4ms frame limit not used for NG mode. The values filled
162 * for HT are the 64K max aggregate limit */
163
164static struct ath_rate_table ar5416_11ng_ratetable = {
165 46,
Sujithe63835b2008-11-18 09:07:53 +0530166 {0},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700167 {
Sujith46d14a52008-11-18 09:08:13 +0530168 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700169 900, 0x1b, 0x00, 2,
170 0, 0, 1, 0, 0, 0, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530171 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700172 1900, 0x1a, 0x04, 4,
173 1, 1, 1, 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530174 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700175 4900, 0x19, 0x04, 11,
176 2, 2, 2, 2, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530177 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700178 8100, 0x18, 0x04, 22,
179 3, 3, 2, 3, 3, 3, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530180 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700181 5400, 0x0b, 0x00, 12,
182 4, 2, 1, 4, 4, 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530183 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700184 7800, 0x0f, 0x00, 18,
185 4, 3, 1, 5, 5, 5, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530186 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700187 10100, 0x0a, 0x00, 24,
188 6, 4, 1, 6, 6, 6, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530189 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700190 14100, 0x0e, 0x00, 36,
191 6, 6, 2, 7, 7, 7, 7, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530192 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700193 17700, 0x09, 0x00, 48,
194 8, 10, 3, 8, 8, 8, 8, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530195 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700196 23700, 0x0d, 0x00, 72,
197 8, 14, 3, 9, 9, 9, 9, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530198 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700199 27400, 0x08, 0x00, 96,
200 8, 20, 3, 10, 10, 10, 10, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530201 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700202 30900, 0x0c, 0x00, 108,
203 8, 23, 3, 11, 11, 11, 11, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530204 { INVALID, INVALID, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700205 6400, 0x80, 0x00, 0,
206 4, 2, 3, 12, 28, 12, 28, 3216 },
Sujith46d14a52008-11-18 09:08:13 +0530207 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700208 12700, 0x81, 0x00, 1,
209 6, 4, 3, 13, 29, 13, 29, 6434 },
Sujith46d14a52008-11-18 09:08:13 +0530210 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700211 18800, 0x82, 0x00, 2,
212 6, 6, 3, 14, 30, 14, 30, 9650 },
Sujith46d14a52008-11-18 09:08:13 +0530213 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700214 25000, 0x83, 0x00, 3,
215 8, 10, 3, 15, 31, 15, 31, 12868 },
Sujith46d14a52008-11-18 09:08:13 +0530216 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700217 36700, 0x84, 0x00, 4,
218 8, 14, 3, 16, 32, 16, 32, 19304 },
Sujith46d14a52008-11-18 09:08:13 +0530219 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700220 48100, 0x85, 0x00, 5,
221 8, 20, 3, 17, 33, 17, 33, 25740 },
Sujith46d14a52008-11-18 09:08:13 +0530222 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700223 53500, 0x86, 0x00, 6,
224 8, 23, 3, 18, 34, 18, 34, 28956 },
Sujith46d14a52008-11-18 09:08:13 +0530225 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700226 59000, 0x87, 0x00, 7,
227 8, 25, 3, 19, 35, 19, 36, 32180 },
Sujith46d14a52008-11-18 09:08:13 +0530228 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700229 12700, 0x88, 0x00, 8,
230 4, 2, 3, 20, 37, 20, 37, 6430 },
Sujith46d14a52008-11-18 09:08:13 +0530231 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700232 24800, 0x89, 0x00, 9,
233 6, 4, 3, 21, 38, 21, 38, 12860 },
Sujith46d14a52008-11-18 09:08:13 +0530234 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700235 36600, 0x8a, 0x00, 10,
236 6, 6, 3, 22, 39, 22, 39, 19300 },
Sujith46d14a52008-11-18 09:08:13 +0530237 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700238 48100, 0x8b, 0x00, 11,
239 8, 10, 3, 23, 40, 23, 40, 25736 },
Sujith46d14a52008-11-18 09:08:13 +0530240 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700241 69500, 0x8c, 0x00, 12,
242 8, 14, 3, 24, 41, 24, 41, 38600 },
Sujith46d14a52008-11-18 09:08:13 +0530243 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700244 89500, 0x8d, 0x00, 13,
245 8, 20, 3, 25, 42, 25, 42, 51472 },
Sujith46d14a52008-11-18 09:08:13 +0530246 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700247 98900, 0x8e, 0x00, 14,
248 8, 23, 3, 26, 43, 26, 44, 57890 },
Sujith46d14a52008-11-18 09:08:13 +0530249 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700250 108300, 0x8f, 0x00, 15,
251 8, 25, 3, 27, 44, 27, 45, 64320 },
Sujith46d14a52008-11-18 09:08:13 +0530252 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700253 13200, 0x80, 0x00, 0,
254 8, 2, 3, 12, 28, 28, 28, 6684 },
Sujith46d14a52008-11-18 09:08:13 +0530255 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700256 25900, 0x81, 0x00, 1,
257 8, 4, 3, 13, 29, 29, 29, 13368 },
Sujith46d14a52008-11-18 09:08:13 +0530258 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700259 38600, 0x82, 0x00, 2,
260 8, 6, 3, 14, 30, 30, 30, 20052 },
Sujith46d14a52008-11-18 09:08:13 +0530261 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700262 49800, 0x83, 0x00, 3,
263 8, 10, 3, 15, 31, 31, 31, 26738 },
Sujith46d14a52008-11-18 09:08:13 +0530264 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700265 72200, 0x84, 0x00, 4,
266 8, 14, 3, 16, 32, 32, 32, 40104 },
Sujith46d14a52008-11-18 09:08:13 +0530267 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700268 92900, 0x85, 0x00, 5,
269 8, 20, 3, 17, 33, 33, 33, 53476 },
Sujith46d14a52008-11-18 09:08:13 +0530270 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700271 102700, 0x86, 0x00, 6,
272 8, 23, 3, 18, 34, 34, 34, 60156 },
Sujith46d14a52008-11-18 09:08:13 +0530273 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700274 112000, 0x87, 0x00, 7,
275 8, 23, 3, 19, 35, 36, 36, 66840 },
Sujith46d14a52008-11-18 09:08:13 +0530276 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700277 122000, 0x87, 0x00, 7,
278 8, 25, 3, 19, 35, 36, 36, 74200 },
Sujith46d14a52008-11-18 09:08:13 +0530279 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700280 25800, 0x88, 0x00, 8,
281 8, 2, 3, 20, 37, 37, 37, 13360 },
Sujith46d14a52008-11-18 09:08:13 +0530282 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700283 49800, 0x89, 0x00, 9,
284 8, 4, 3, 21, 38, 38, 38, 26720 },
Sujith46d14a52008-11-18 09:08:13 +0530285 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700286 71900, 0x8a, 0x00, 10,
287 8, 6, 3, 22, 39, 39, 39, 40080 },
Sujith46d14a52008-11-18 09:08:13 +0530288 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700289 92500, 0x8b, 0x00, 11,
290 8, 10, 3, 23, 40, 40, 40, 53440 },
Sujith46d14a52008-11-18 09:08:13 +0530291 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700292 130300, 0x8c, 0x00, 12,
293 8, 14, 3, 24, 41, 41, 41, 80160 },
Sujith46d14a52008-11-18 09:08:13 +0530294 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700295 162800, 0x8d, 0x00, 13,
296 8, 20, 3, 25, 42, 42, 42, 106880 },
Sujith46d14a52008-11-18 09:08:13 +0530297 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700298 178200, 0x8e, 0x00, 14,
299 8, 23, 3, 26, 43, 43, 43, 120240 },
Sujith46d14a52008-11-18 09:08:13 +0530300 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700301 192100, 0x8f, 0x00, 15,
302 8, 23, 3, 27, 44, 45, 45, 133600 },
Sujith46d14a52008-11-18 09:08:13 +0530303 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700304 207000, 0x8f, 0x00, 15,
305 8, 25, 3, 27, 44, 45, 45, 148400 },
306 },
307 50, /* probe interval */
308 50, /* rssi reduce interval */
309 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
310};
311
312static struct ath_rate_table ar5416_11a_ratetable = {
313 8,
Sujithe63835b2008-11-18 09:07:53 +0530314 {0},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700315 {
Sujith46d14a52008-11-18 09:08:13 +0530316 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700317 5400, 0x0b, 0x00, (0x80|12),
318 0, 2, 1, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530319 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700320 7800, 0x0f, 0x00, 18,
321 0, 3, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530322 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700323 10000, 0x0a, 0x00, (0x80|24),
324 2, 4, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530325 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700326 13900, 0x0e, 0x00, 36,
327 2, 6, 2, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530328 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700329 17300, 0x09, 0x00, (0x80|48),
330 4, 10, 3, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530331 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700332 23000, 0x0d, 0x00, 72,
333 4, 14, 3, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530334 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335 27400, 0x08, 0x00, 96,
336 4, 19, 3, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530337 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700338 29300, 0x0c, 0x00, 108,
339 4, 23, 3, 7, 0 },
340 },
341 50, /* probe interval */
342 50, /* rssi reduce interval */
343 0, /* Phy rates allowed initially */
344};
345
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700346static struct ath_rate_table ar5416_11g_ratetable = {
347 12,
Sujithe63835b2008-11-18 09:07:53 +0530348 {0},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700349 {
Sujith46d14a52008-11-18 09:08:13 +0530350 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700351 900, 0x1b, 0x00, 2,
352 0, 0, 1, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530353 { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700354 1900, 0x1a, 0x04, 4,
355 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530356 { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700357 4900, 0x19, 0x04, 11,
358 2, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530359 { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700360 8100, 0x18, 0x04, 22,
361 3, 3, 2, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530362 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700363 5400, 0x0b, 0x00, 12,
364 4, 2, 1, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530365 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700366 7800, 0x0f, 0x00, 18,
367 4, 3, 1, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530368 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700369 10000, 0x0a, 0x00, 24,
370 6, 4, 1, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530371 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700372 13900, 0x0e, 0x00, 36,
373 6, 6, 2, 7, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530374 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700375 17300, 0x09, 0x00, 48,
376 8, 10, 3, 8, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530377 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378 23000, 0x0d, 0x00, 72,
379 8, 14, 3, 9, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530380 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 27400, 0x08, 0x00, 96,
382 8, 19, 3, 10, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530383 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700384 29300, 0x0c, 0x00, 108,
385 8, 23, 3, 11, 0 },
386 },
387 50, /* probe interval */
388 50, /* rssi reduce interval */
389 0, /* Phy rates allowed initially */
390};
391
392static struct ath_rate_table ar5416_11b_ratetable = {
393 4,
Sujithe63835b2008-11-18 09:07:53 +0530394 {0},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395 {
Sujith46d14a52008-11-18 09:08:13 +0530396 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397 900, 0x1b, 0x00, (0x80|2),
398 0, 0, 1, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530399 { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700400 1800, 0x1a, 0x04, (0x80|4),
401 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530402 { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403 4300, 0x19, 0x04, (0x80|11),
404 1, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530405 { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406 7100, 0x18, 0x04, (0x80|22),
407 1, 4, 100, 3, 0 },
408 },
409 100, /* probe interval */
410 100, /* rssi reduce interval */
411 0, /* Phy rates allowed initially */
412};
413
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414static inline int8_t median(int8_t a, int8_t b, int8_t c)
415{
416 if (a >= b) {
417 if (b >= c)
418 return b;
419 else if (a > c)
420 return c;
421 else
422 return a;
423 } else {
424 if (a >= c)
425 return a;
426 else if (b >= c)
427 return c;
428 else
429 return b;
430 }
431}
432
Sujithfe7f4a72008-11-18 09:07:06 +0530433static void ath_rc_sort_validrates(struct ath_rate_table *rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530434 struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435{
436 u8 i, j, idx, idx_next;
437
Sujith256b7752008-11-18 09:03:12 +0530438 for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439 for (j = 0; j <= i-1; j++) {
Sujith256b7752008-11-18 09:03:12 +0530440 idx = ath_rc_priv->valid_rate_index[j];
441 idx_next = ath_rc_priv->valid_rate_index[j+1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442
443 if (rate_table->info[idx].ratekbps >
444 rate_table->info[idx_next].ratekbps) {
Sujith256b7752008-11-18 09:03:12 +0530445 ath_rc_priv->valid_rate_index[j] = idx_next;
446 ath_rc_priv->valid_rate_index[j+1] = idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447 }
448 }
449 }
450}
451
Sujith46d14a52008-11-18 09:08:13 +0530452static void ath_rc_init_valid_txmask(struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453{
454 u8 i;
455
Sujith256b7752008-11-18 09:03:12 +0530456 for (i = 0; i < ath_rc_priv->rate_table_size; i++)
Sujith46d14a52008-11-18 09:08:13 +0530457 ath_rc_priv->valid_rate_index[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458}
459
Sujith46d14a52008-11-18 09:08:13 +0530460static inline void ath_rc_set_valid_txmask(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461 u8 index, int valid_tx_rate)
462{
Sujith256b7752008-11-18 09:03:12 +0530463 ASSERT(index <= ath_rc_priv->rate_table_size);
Sujith46d14a52008-11-18 09:08:13 +0530464 ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? 1 : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465}
466
Sujith46d14a52008-11-18 09:08:13 +0530467static inline int ath_rc_isvalid_txmask(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468 u8 index)
469{
Sujith256b7752008-11-18 09:03:12 +0530470 ASSERT(index <= ath_rc_priv->rate_table_size);
471 return ath_rc_priv->valid_rate_index[index];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472}
473
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474static inline int
Sujithfe7f4a72008-11-18 09:07:06 +0530475ath_rc_get_nextvalid_txrate(struct ath_rate_table *rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530476 struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477 u8 cur_valid_txrate,
478 u8 *next_idx)
479{
480 u8 i;
481
Sujith256b7752008-11-18 09:03:12 +0530482 for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
483 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
484 *next_idx = ath_rc_priv->valid_rate_index[i+1];
Sujith46d14a52008-11-18 09:08:13 +0530485 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486 }
487 }
488
489 /* No more valid rates */
490 *next_idx = 0;
Sujith46d14a52008-11-18 09:08:13 +0530491 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492}
493
494/* Return true only for single stream */
495
496static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
497{
498 if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530499 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700500 if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530501 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502 if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530503 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 if (!ignore_cw && WLAN_RC_PHY_HT(phy))
505 if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530506 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507 if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530508 return 0;
509 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510}
511
512static inline int
Sujithfe7f4a72008-11-18 09:07:06 +0530513ath_rc_get_nextlowervalid_txrate(struct ath_rate_table *rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530514 struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700515 u8 cur_valid_txrate, u8 *next_idx)
516{
517 int8_t i;
518
Sujith256b7752008-11-18 09:03:12 +0530519 for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
520 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
521 *next_idx = ath_rc_priv->valid_rate_index[i-1];
Sujith46d14a52008-11-18 09:08:13 +0530522 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523 }
524 }
Sujith46d14a52008-11-18 09:08:13 +0530525 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700526}
527
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528static u8
Sujith46d14a52008-11-18 09:08:13 +0530529ath_rc_sib_init_validrates(struct ath_rate_priv *ath_rc_priv,
Sujithfe7f4a72008-11-18 09:07:06 +0530530 struct ath_rate_table *rate_table,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700531 u32 capflag)
532{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700533 u8 i, hi = 0;
534 u32 valid;
535
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700536 for (i = 0; i < rate_table->rate_cnt; i++) {
537 valid = (ath_rc_priv->single_stream ?
Sujithdc2222a2008-08-14 13:26:55 +0530538 rate_table->info[i].valid_single_stream :
539 rate_table->info[i].valid);
Sujith46d14a52008-11-18 09:08:13 +0530540 if (valid == 1) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700541 u32 phy = rate_table->info[i].phy;
542 u8 valid_rate_count = 0;
543
Sujith46d14a52008-11-18 09:08:13 +0530544 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700545 continue;
546
Sujith256b7752008-11-18 09:03:12 +0530547 valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700548
Sujith256b7752008-11-18 09:03:12 +0530549 ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
550 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530551 ath_rc_set_valid_txmask(ath_rc_priv, i, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700552 hi = A_MAX(hi, i);
553 }
554 }
555 return hi;
556}
557
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700558static u8
Sujith46d14a52008-11-18 09:08:13 +0530559ath_rc_sib_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
Sujithfe7f4a72008-11-18 09:07:06 +0530560 struct ath_rate_table *rate_table,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700561 struct ath_rateset *rateset,
562 u32 capflag)
563{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700564 u8 i, j, hi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700565
566 /* Use intersection of working rates and valid rates */
567 for (i = 0; i < rateset->rs_nrates; i++) {
568 for (j = 0; j < rate_table->rate_cnt; j++) {
569 u32 phy = rate_table->info[j].phy;
570 u32 valid = (ath_rc_priv->single_stream ?
571 rate_table->info[j].valid_single_stream :
572 rate_table->info[j].valid);
573
574 /* We allow a rate only if its valid and the
575 * capflag matches one of the validity
Sujith46d14a52008-11-18 09:08:13 +0530576 * (VALID/VALID_20/VALID_40) flags */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578 if (((rateset->rs_rates[i] & 0x7F) ==
579 (rate_table->info[j].dot11rate & 0x7F)) &&
580 ((valid & WLAN_RC_CAP_MODE(capflag)) ==
581 WLAN_RC_CAP_MODE(capflag)) &&
582 !WLAN_RC_PHY_HT(phy)) {
583
584 u8 valid_rate_count = 0;
585
Sujith46d14a52008-11-18 09:08:13 +0530586 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700587 continue;
588
589 valid_rate_count =
Sujith256b7752008-11-18 09:03:12 +0530590 ath_rc_priv->valid_phy_ratecnt[phy];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700591
Sujith256b7752008-11-18 09:03:12 +0530592 ath_rc_priv->valid_phy_rateidx[phy]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 [valid_rate_count] = j;
Sujith256b7752008-11-18 09:03:12 +0530594 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530595 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700596 hi = A_MAX(hi, j);
597 }
598 }
599 }
600 return hi;
601}
602
603static u8
Sujith46d14a52008-11-18 09:08:13 +0530604ath_rc_sib_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
Sujithfe7f4a72008-11-18 09:07:06 +0530605 struct ath_rate_table *rate_table,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700606 u8 *mcs_set, u32 capflag)
607{
608 u8 i, j, hi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700609
610 /* Use intersection of working rates and valid rates */
611 for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) {
612 for (j = 0; j < rate_table->rate_cnt; j++) {
613 u32 phy = rate_table->info[j].phy;
614 u32 valid = (ath_rc_priv->single_stream ?
Sujithdc2222a2008-08-14 13:26:55 +0530615 rate_table->info[j].valid_single_stream :
616 rate_table->info[j].valid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617
618 if (((((struct ath_rateset *)
Sujithdc2222a2008-08-14 13:26:55 +0530619 mcs_set)->rs_rates[i] & 0x7F) !=
620 (rate_table->info[j].dot11rate & 0x7F)) ||
621 !WLAN_RC_PHY_HT(phy) ||
622 !WLAN_RC_PHY_HT_VALID(valid, capflag))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623 continue;
624
Sujith46d14a52008-11-18 09:08:13 +0530625 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700626 continue;
627
Sujith256b7752008-11-18 09:03:12 +0530628 ath_rc_priv->valid_phy_rateidx[phy]
629 [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
630 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530631 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 hi = A_MAX(hi, j);
633 }
634 }
635 return hi;
636}
637
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638u8 ath_rate_findrateix(struct ath_softc *sc,
Sujith102e0572008-10-29 10:15:16 +0530639 u8 dot11rate)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640{
Sujithfe7f4a72008-11-18 09:07:06 +0530641 struct ath_rate_table *ratetable;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700642 int i;
643
Sujithfe7f4a72008-11-18 09:07:06 +0530644 ratetable = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700645
646 if (WARN_ON(!ratetable))
647 return 0;
648
649 for (i = 0; i < ratetable->rate_cnt; i++) {
650 if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f))
651 return i;
652 }
653
654 return 0;
655}
656
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700657static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +0530658 struct ath_rate_priv *ath_rc_priv,
Sujithfe7f4a72008-11-18 09:07:06 +0530659 struct ath_rate_table *rate_table,
Sujithdc2222a2008-08-14 13:26:55 +0530660 int probe_allowed, int *is_probing,
661 int is_retry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700662{
663 u32 dt, best_thruput, this_thruput, now_msec;
664 u8 rate, next_rate, best_rate, maxindex, minindex;
665 int8_t rssi_last, rssi_reduce = 0, index = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666
Sujith46d14a52008-11-18 09:08:13 +0530667 *is_probing = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668
Sujith256b7752008-11-18 09:03:12 +0530669 rssi_last = median(ath_rc_priv->rssi_last,
670 ath_rc_priv->rssi_last_prev,
671 ath_rc_priv->rssi_last_prev2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672
673 /*
674 * Age (reduce) last ack rssi based on how old it is.
675 * The bizarre numbers are so the delta is 160msec,
676 * meaning we divide by 16.
677 * 0msec <= dt <= 25msec: don't derate
678 * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
679 * 185msec <= dt: derate by 10dB
680 */
681
682 now_msec = jiffies_to_msecs(jiffies);
Sujith256b7752008-11-18 09:03:12 +0530683 dt = now_msec - ath_rc_priv->rssi_time;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684
685 if (dt >= 185)
686 rssi_reduce = 10;
687 else if (dt >= 25)
688 rssi_reduce = (u8)((dt - 25) >> 4);
689
690 /* Now reduce rssi_last by rssi_reduce */
691 if (rssi_last < rssi_reduce)
692 rssi_last = 0;
693 else
694 rssi_last -= rssi_reduce;
695
696 /*
697 * Now look up the rate in the rssi table and return it.
698 * If no rates match then we return 0 (lowest rate)
699 */
700
701 best_thruput = 0;
Sujith256b7752008-11-18 09:03:12 +0530702 maxindex = ath_rc_priv->max_valid_rate-1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700703
704 minindex = 0;
705 best_rate = minindex;
706
707 /*
708 * Try the higher rate first. It will reduce memory moving time
709 * if we have very good channel characteristics.
710 */
711 for (index = maxindex; index >= minindex ; index--) {
712 u8 per_thres;
713
Sujith256b7752008-11-18 09:03:12 +0530714 rate = ath_rc_priv->valid_rate_index[index];
715 if (rate > ath_rc_priv->rate_max_phy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 continue;
717
718 /*
719 * For TCP the average collision rate is around 11%,
720 * so we ignore PERs less than this. This is to
721 * prevent the rate we are currently using (whose
722 * PER might be in the 10-15 range because of TCP
723 * collisions) looking worse than the next lower
724 * rate whose PER has decayed close to 0. If we
725 * used to next lower rate, its PER would grow to
726 * 10-15 and we would be worse off then staying
727 * at the current rate.
728 */
Sujith256b7752008-11-18 09:03:12 +0530729 per_thres = ath_rc_priv->state[rate].per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 if (per_thres < 12)
731 per_thres = 12;
732
733 this_thruput = rate_table->info[rate].user_ratekbps *
734 (100 - per_thres);
735
736 if (best_thruput <= this_thruput) {
737 best_thruput = this_thruput;
738 best_rate = rate;
739 }
740 }
741
742 rate = best_rate;
743
744 /* if we are retrying for more than half the number
745 * of max retries, use the min rate for the next retry
746 */
747 if (is_retry)
Sujith256b7752008-11-18 09:03:12 +0530748 rate = ath_rc_priv->valid_rate_index[minindex];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749
Sujith256b7752008-11-18 09:03:12 +0530750 ath_rc_priv->rssi_last_lookup = rssi_last;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751
752 /*
753 * Must check the actual rate (ratekbps) to account for
754 * non-monoticity of 11g's rate table
755 */
756
Sujith256b7752008-11-18 09:03:12 +0530757 if (rate >= ath_rc_priv->rate_max_phy && probe_allowed) {
758 rate = ath_rc_priv->rate_max_phy;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759
760 /* Probe the next allowed phy state */
761 /* FIXME:XXXX Check to make sure ratMax is checked properly */
762 if (ath_rc_get_nextvalid_txrate(rate_table,
Sujith256b7752008-11-18 09:03:12 +0530763 ath_rc_priv, rate, &next_rate) &&
764 (now_msec - ath_rc_priv->probe_time >
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 rate_table->probe_interval) &&
Sujith256b7752008-11-18 09:03:12 +0530766 (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 rate = next_rate;
Sujith256b7752008-11-18 09:03:12 +0530768 ath_rc_priv->probe_rate = rate;
769 ath_rc_priv->probe_time = now_msec;
770 ath_rc_priv->hw_maxretry_pktcnt = 0;
Sujith46d14a52008-11-18 09:08:13 +0530771 *is_probing = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 }
773 }
774
Sujith256b7752008-11-18 09:03:12 +0530775 if (rate > (ath_rc_priv->rate_table_size - 1))
776 rate = ath_rc_priv->rate_table_size - 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777
778 ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) ||
Sujithdc2222a2008-08-14 13:26:55 +0530779 (rate_table->info[rate].valid_single_stream &&
780 ath_rc_priv->single_stream));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781
782 return rate;
783}
784
Sujithfe7f4a72008-11-18 09:07:06 +0530785static void ath_rc_rate_set_series(struct ath_rate_table *rate_table ,
Sujitha8efee42008-11-18 09:07:30 +0530786 struct ieee80211_tx_rate *rate,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 u8 tries,
788 u8 rix,
789 int rtsctsenable)
790{
Sujitha8efee42008-11-18 09:07:30 +0530791 rate->count = tries;
792 rate->idx = rix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793
Sujitha8efee42008-11-18 09:07:30 +0530794 if (rtsctsenable)
795 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
796 if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
797 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
798 if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
799 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
800 if (WLAN_RC_PHY_HT(rate_table->info[rix].phy))
801 rate->flags |= IEEE80211_TX_RC_MCS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802}
803
804static u8 ath_rc_rate_getidx(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +0530805 struct ath_rate_priv *ath_rc_priv,
Sujithfe7f4a72008-11-18 09:07:06 +0530806 struct ath_rate_table *rate_table,
Sujithdc2222a2008-08-14 13:26:55 +0530807 u8 rix, u16 stepdown,
808 u16 min_rate)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809{
810 u32 j;
811 u8 nextindex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812
813 if (min_rate) {
814 for (j = RATE_TABLE_SIZE; j > 0; j--) {
815 if (ath_rc_get_nextlowervalid_txrate(rate_table,
Sujith256b7752008-11-18 09:03:12 +0530816 ath_rc_priv, rix, &nextindex))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 rix = nextindex;
818 else
819 break;
820 }
821 } else {
822 for (j = stepdown; j > 0; j--) {
823 if (ath_rc_get_nextlowervalid_txrate(rate_table,
Sujith256b7752008-11-18 09:03:12 +0530824 ath_rc_priv, rix, &nextindex))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 rix = nextindex;
826 else
827 break;
828 }
829 }
830 return rix;
831}
832
833static void ath_rc_ratefind(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +0530834 struct ath_rate_priv *ath_rc_priv,
835 int num_tries, int num_rates,
Sujitha8efee42008-11-18 09:07:30 +0530836 struct ieee80211_tx_info *tx_info, int *is_probe,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700837 int is_retry)
838{
839 u8 try_per_rate = 0, i = 0, rix, nrix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700840 struct ath_rate_table *rate_table;
Sujitha8efee42008-11-18 09:07:30 +0530841 struct ieee80211_tx_rate *rates = tx_info->control.rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700842
Sujithfe7f4a72008-11-18 09:07:06 +0530843 rate_table = sc->hw_rate_table[sc->sc_curmode];
Sujith46d14a52008-11-18 09:08:13 +0530844 rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table, 1,
Sujithdc2222a2008-08-14 13:26:55 +0530845 is_probe, is_retry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700846 nrix = rix;
847
Sujith46d14a52008-11-18 09:08:13 +0530848 if (*is_probe) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700849 /* set one try for probe rates. For the
850 * probes don't enable rts */
851 ath_rc_rate_set_series(rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530852 &rates[i++], 1, nrix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700853
854 try_per_rate = (num_tries/num_rates);
855 /* Get the next tried/allowed rate. No RTS for the next series
856 * after the probe rate
857 */
858 nrix = ath_rc_rate_getidx(sc,
Sujith46d14a52008-11-18 09:08:13 +0530859 ath_rc_priv, rate_table, nrix, 1, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700860 ath_rc_rate_set_series(rate_table,
Sujitha8efee42008-11-18 09:07:30 +0530861 &rates[i++], try_per_rate, nrix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700862 } else {
863 try_per_rate = (num_tries/num_rates);
864 /* Set the choosen rate. No RTS for first series entry. */
865 ath_rc_rate_set_series(rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530866 &rates[i++], try_per_rate, nrix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700867 }
868
869 /* Fill in the other rates for multirate retry */
870 for ( ; i < num_rates; i++) {
871 u8 try_num;
872 u8 min_rate;
873
874 try_num = ((i + 1) == num_rates) ?
875 num_tries - (try_per_rate * i) : try_per_rate ;
Sujith46d14a52008-11-18 09:08:13 +0530876 min_rate = (((i + 1) == num_rates) && 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700877
878 nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
Sujithdc2222a2008-08-14 13:26:55 +0530879 rate_table, nrix, 1, min_rate);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700880 /* All other rates in the series have RTS enabled */
881 ath_rc_rate_set_series(rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530882 &rates[i], try_num, nrix, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700883 }
884
885 /*
886 * NB:Change rate series to enable aggregation when operating
887 * at lower MCS rates. When first rate in series is MCS2
888 * in HT40 @ 2.4GHz, series should look like:
889 *
890 * {MCS2, MCS1, MCS0, MCS0}.
891 *
892 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
893 * look like:
894 *
895 * {MCS3, MCS2, MCS1, MCS1}
896 *
897 * So, set fourth rate in series to be same as third one for
898 * above conditions.
899 */
Sujith86b89ee2008-08-07 10:54:57 +0530900 if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) ||
Sujithdc2222a2008-08-14 13:26:55 +0530901 (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) ||
902 (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700903 u8 dot11rate = rate_table->info[rix].dot11rate;
904 u8 phy = rate_table->info[rix].phy;
905 if (i == 4 &&
906 ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
Sujithdc2222a2008-08-14 13:26:55 +0530907 (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
Sujitha8efee42008-11-18 09:07:30 +0530908 rates[3].idx = rates[2].idx;
909 rates[3].flags = rates[2].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700910 }
911 }
912}
913
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700914static void ath_rc_update_ht(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +0530915 struct ath_rate_priv *ath_rc_priv,
916 struct ath_tx_info_priv *tx_info_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700917 int tx_rate, int xretries, int retries)
918{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700919 u32 now_msec = jiffies_to_msecs(jiffies);
Sujith46d14a52008-11-18 09:08:13 +0530920 int state_change = 0, rate, count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700921 u8 last_per;
Sujithfe7f4a72008-11-18 09:07:06 +0530922 struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700923 static u32 nretry_to_per_lookup[10] = {
924 100 * 0 / 1,
925 100 * 1 / 4,
926 100 * 1 / 2,
927 100 * 3 / 4,
928 100 * 4 / 5,
929 100 * 5 / 6,
930 100 * 6 / 7,
931 100 * 7 / 8,
932 100 * 8 / 9,
933 100 * 9 / 10
934 };
935
936 if (!ath_rc_priv)
937 return;
938
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700939 ASSERT(tx_rate >= 0);
940 if (tx_rate < 0)
941 return;
942
943 /* To compensate for some imbalance between ctrl and ext. channel */
944
945 if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
Sujith46d14a52008-11-18 09:08:13 +0530946 tx_info_priv->tx.ts_rssi =
947 tx_info_priv->tx.ts_rssi < 3 ? 0 :
948 tx_info_priv->tx.ts_rssi - 3;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700949
Sujith256b7752008-11-18 09:03:12 +0530950 last_per = ath_rc_priv->state[tx_rate].per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700951
952 if (xretries) {
953 /* Update the PER. */
954 if (xretries == 1) {
Sujith256b7752008-11-18 09:03:12 +0530955 ath_rc_priv->state[tx_rate].per += 30;
956 if (ath_rc_priv->state[tx_rate].per > 100)
957 ath_rc_priv->state[tx_rate].per = 100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700958 } else {
959 /* xretries == 2 */
Julia Lawall87c16872008-11-09 17:56:10 +0100960 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700961 if (retries >= count)
962 retries = count - 1;
963 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
Sujith256b7752008-11-18 09:03:12 +0530964 ath_rc_priv->state[tx_rate].per =
965 (u8)(ath_rc_priv->state[tx_rate].per -
966 (ath_rc_priv->state[tx_rate].per >> 3) +
Sujithdc2222a2008-08-14 13:26:55 +0530967 ((100) >> 3));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700968 }
969
970 /* xretries == 1 or 2 */
971
Sujith256b7752008-11-18 09:03:12 +0530972 if (ath_rc_priv->probe_rate == tx_rate)
973 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700974
975 } else { /* xretries == 0 */
976 /* Update the PER. */
977 /* Make sure it doesn't index out of array's bounds. */
Julia Lawall87c16872008-11-09 17:56:10 +0100978 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700979 if (retries >= count)
980 retries = count - 1;
Sujith46d14a52008-11-18 09:08:13 +0530981 if (tx_info_priv->n_bad_frames) {
Sujithdc2222a2008-08-14 13:26:55 +0530982 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700983 * Assuming that n_frames is not 0. The current PER
984 * from the retries is 100 * retries / (retries+1),
985 * since the first retries attempts failed, and the
986 * next one worked. For the one that worked,
987 * n_bad_frames subframes out of n_frames wored,
988 * so the PER for that part is
989 * 100 * n_bad_frames / n_frames, and it contributes
990 * 100 * n_bad_frames / (n_frames * (retries+1)) to
991 * the above PER. The expression below is a
992 * simplified version of the sum of these two terms.
993 */
Sujith46d14a52008-11-18 09:08:13 +0530994 if (tx_info_priv->n_frames > 0)
Sujith256b7752008-11-18 09:03:12 +0530995 ath_rc_priv->state[tx_rate].per
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700996 = (u8)
Sujith256b7752008-11-18 09:03:12 +0530997 (ath_rc_priv->state[tx_rate].per -
998 (ath_rc_priv->state[tx_rate].per >> 3) +
Sujith46d14a52008-11-18 09:08:13 +0530999 ((100*(retries*tx_info_priv->n_frames +
1000 tx_info_priv->n_bad_frames) /
1001 (tx_info_priv->n_frames *
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001002 (retries+1))) >> 3));
1003 } else {
1004 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
1005
Sujith256b7752008-11-18 09:03:12 +05301006 ath_rc_priv->state[tx_rate].per = (u8)
1007 (ath_rc_priv->state[tx_rate].per -
1008 (ath_rc_priv->state[tx_rate].per >> 3) +
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001009 (nretry_to_per_lookup[retries] >> 3));
1010 }
1011
Sujith256b7752008-11-18 09:03:12 +05301012 ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev;
1013 ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last;
Sujith46d14a52008-11-18 09:08:13 +05301014 ath_rc_priv->rssi_last = tx_info_priv->tx.ts_rssi;
Sujith256b7752008-11-18 09:03:12 +05301015 ath_rc_priv->rssi_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001016
1017 /*
1018 * If we got at most one retry then increase the max rate if
1019 * this was a probe. Otherwise, ignore the probe.
1020 */
1021
Sujith256b7752008-11-18 09:03:12 +05301022 if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
Sujith46d14a52008-11-18 09:08:13 +05301023 if (retries > 0 || 2 * tx_info_priv->n_bad_frames >
1024 tx_info_priv->n_frames) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001025 /*
1026 * Since we probed with just a single attempt,
1027 * any retries means the probe failed. Also,
1028 * if the attempt worked, but more than half
1029 * the subframes were bad then also consider
1030 * the probe a failure.
1031 */
Sujith256b7752008-11-18 09:03:12 +05301032 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001033 } else {
1034 u8 probe_rate = 0;
1035
Sujith256b7752008-11-18 09:03:12 +05301036 ath_rc_priv->rate_max_phy = ath_rc_priv->probe_rate;
1037 probe_rate = ath_rc_priv->probe_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001038
Sujith256b7752008-11-18 09:03:12 +05301039 if (ath_rc_priv->state[probe_rate].per > 30)
1040 ath_rc_priv->state[probe_rate].per = 20;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001041
Sujith256b7752008-11-18 09:03:12 +05301042 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001043
1044 /*
1045 * Since this probe succeeded, we allow the next
1046 * probe twice as soon. This allows the maxRate
1047 * to move up faster if the probes are
1048 * succesful.
1049 */
Sujith256b7752008-11-18 09:03:12 +05301050 ath_rc_priv->probe_time = now_msec -
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001051 rate_table->probe_interval / 2;
1052 }
1053 }
1054
1055 if (retries > 0) {
1056 /*
1057 * Don't update anything. We don't know if
1058 * this was because of collisions or poor signal.
1059 *
1060 * Later: if rssi_ack is close to
Sujith256b7752008-11-18 09:03:12 +05301061 * ath_rc_priv->state[txRate].rssi_thres and we see lots
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001062 * of retries, then we could increase
Sujith256b7752008-11-18 09:03:12 +05301063 * ath_rc_priv->state[txRate].rssi_thres.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001064 */
Sujith256b7752008-11-18 09:03:12 +05301065 ath_rc_priv->hw_maxretry_pktcnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001066 } else {
1067 /*
1068 * It worked with no retries. First ignore bogus (small)
1069 * rssi_ack values.
1070 */
Sujith256b7752008-11-18 09:03:12 +05301071 if (tx_rate == ath_rc_priv->rate_max_phy &&
1072 ath_rc_priv->hw_maxretry_pktcnt < 255) {
1073 ath_rc_priv->hw_maxretry_pktcnt++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001074 }
1075
Sujith46d14a52008-11-18 09:08:13 +05301076 if (tx_info_priv->tx.ts_rssi >=
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001077 rate_table->info[tx_rate].rssi_ack_validmin) {
1078 /* Average the rssi */
Sujith256b7752008-11-18 09:03:12 +05301079 if (tx_rate != ath_rc_priv->rssi_sum_rate) {
1080 ath_rc_priv->rssi_sum_rate = tx_rate;
1081 ath_rc_priv->rssi_sum =
1082 ath_rc_priv->rssi_sum_cnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001083 }
1084
Sujith46d14a52008-11-18 09:08:13 +05301085 ath_rc_priv->rssi_sum += tx_info_priv->tx.ts_rssi;
Sujith256b7752008-11-18 09:03:12 +05301086 ath_rc_priv->rssi_sum_cnt++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001087
Sujith256b7752008-11-18 09:03:12 +05301088 if (ath_rc_priv->rssi_sum_cnt > 4) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001089 int32_t rssi_ackAvg =
Sujith256b7752008-11-18 09:03:12 +05301090 (ath_rc_priv->rssi_sum + 2) / 4;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001091 int8_t rssi_thres =
Sujith256b7752008-11-18 09:03:12 +05301092 ath_rc_priv->state[tx_rate].
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001093 rssi_thres;
1094 int8_t rssi_ack_vmin =
1095 rate_table->info[tx_rate].
1096 rssi_ack_validmin;
1097
Sujith256b7752008-11-18 09:03:12 +05301098 ath_rc_priv->rssi_sum =
1099 ath_rc_priv->rssi_sum_cnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001100
1101 /* Now reduce the current
1102 * rssi threshold. */
1103 if ((rssi_ackAvg < rssi_thres + 2) &&
Sujithdc2222a2008-08-14 13:26:55 +05301104 (rssi_thres > rssi_ack_vmin)) {
Sujith256b7752008-11-18 09:03:12 +05301105 ath_rc_priv->state[tx_rate].
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001106 rssi_thres--;
1107 }
1108
Sujith46d14a52008-11-18 09:08:13 +05301109 state_change = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001110 }
1111 }
1112 }
1113 }
1114
1115 /* For all cases */
1116
1117 /*
1118 * If this rate looks bad (high PER) then stop using it for
1119 * a while (except if we are probing).
1120 */
Sujith256b7752008-11-18 09:03:12 +05301121 if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 &&
Sujithdc2222a2008-08-14 13:26:55 +05301122 rate_table->info[tx_rate].ratekbps <=
Sujith256b7752008-11-18 09:03:12 +05301123 rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
1124 ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv,
1125 (u8) tx_rate, &ath_rc_priv->rate_max_phy);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001126
1127 /* Don't probe for a little while. */
Sujith256b7752008-11-18 09:03:12 +05301128 ath_rc_priv->probe_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001129 }
1130
1131 if (state_change) {
1132 /*
1133 * Make sure the rates above this have higher rssi thresholds.
1134 * (Note: Monotonicity is kept within the OFDM rates and
1135 * within the CCK rates. However, no adjustment is
1136 * made to keep the rssi thresholds monotonically
1137 * increasing between the CCK and OFDM rates.)
1138 */
1139 for (rate = tx_rate; rate <
Sujith256b7752008-11-18 09:03:12 +05301140 ath_rc_priv->rate_table_size - 1; rate++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001141 if (rate_table->info[rate+1].phy !=
1142 rate_table->info[tx_rate].phy)
1143 break;
1144
Sujith256b7752008-11-18 09:03:12 +05301145 if (ath_rc_priv->state[rate].rssi_thres +
Sujithdc2222a2008-08-14 13:26:55 +05301146 rate_table->info[rate].rssi_ack_deltamin >
Sujith256b7752008-11-18 09:03:12 +05301147 ath_rc_priv->state[rate+1].rssi_thres) {
1148 ath_rc_priv->state[rate+1].rssi_thres =
1149 ath_rc_priv->state[rate].
Sujithdc2222a2008-08-14 13:26:55 +05301150 rssi_thres +
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001151 rate_table->info[rate].
Sujithdc2222a2008-08-14 13:26:55 +05301152 rssi_ack_deltamin;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001153 }
1154 }
1155
1156 /* Make sure the rates below this have lower rssi thresholds. */
1157 for (rate = tx_rate - 1; rate >= 0; rate--) {
1158 if (rate_table->info[rate].phy !=
Sujithdc2222a2008-08-14 13:26:55 +05301159 rate_table->info[tx_rate].phy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001160 break;
1161
Sujith256b7752008-11-18 09:03:12 +05301162 if (ath_rc_priv->state[rate].rssi_thres +
Sujithdc2222a2008-08-14 13:26:55 +05301163 rate_table->info[rate].rssi_ack_deltamin >
Sujith256b7752008-11-18 09:03:12 +05301164 ath_rc_priv->state[rate+1].rssi_thres) {
1165 if (ath_rc_priv->state[rate+1].rssi_thres <
Sujithdc2222a2008-08-14 13:26:55 +05301166 rate_table->info[rate].
1167 rssi_ack_deltamin)
Sujith256b7752008-11-18 09:03:12 +05301168 ath_rc_priv->state[rate].rssi_thres = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001169 else {
Sujith256b7752008-11-18 09:03:12 +05301170 ath_rc_priv->state[rate].rssi_thres =
1171 ath_rc_priv->state[rate+1].
Sujithdc2222a2008-08-14 13:26:55 +05301172 rssi_thres -
1173 rate_table->info[rate].
1174 rssi_ack_deltamin;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001175 }
1176
Sujith256b7752008-11-18 09:03:12 +05301177 if (ath_rc_priv->state[rate].rssi_thres <
Sujithdc2222a2008-08-14 13:26:55 +05301178 rate_table->info[rate].
1179 rssi_ack_validmin) {
Sujith256b7752008-11-18 09:03:12 +05301180 ath_rc_priv->state[rate].rssi_thres =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001181 rate_table->info[rate].
Sujithdc2222a2008-08-14 13:26:55 +05301182 rssi_ack_validmin;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001183 }
1184 }
1185 }
1186 }
1187
1188 /* Make sure the rates below this have lower PER */
1189 /* Monotonicity is kept only for rates below the current rate. */
Sujith256b7752008-11-18 09:03:12 +05301190 if (ath_rc_priv->state[tx_rate].per < last_per) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001191 for (rate = tx_rate - 1; rate >= 0; rate--) {
1192 if (rate_table->info[rate].phy !=
Sujithdc2222a2008-08-14 13:26:55 +05301193 rate_table->info[tx_rate].phy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001194 break;
1195
Sujith256b7752008-11-18 09:03:12 +05301196 if (ath_rc_priv->state[rate].per >
1197 ath_rc_priv->state[rate+1].per) {
1198 ath_rc_priv->state[rate].per =
1199 ath_rc_priv->state[rate+1].per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001200 }
1201 }
1202 }
1203
1204 /* Maintain monotonicity for rates above the current rate */
Sujith256b7752008-11-18 09:03:12 +05301205 for (rate = tx_rate; rate < ath_rc_priv->rate_table_size - 1; rate++) {
1206 if (ath_rc_priv->state[rate+1].per < ath_rc_priv->state[rate].per)
1207 ath_rc_priv->state[rate+1].per =
1208 ath_rc_priv->state[rate].per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001209 }
1210
1211 /* Every so often, we reduce the thresholds and
1212 * PER (different for CCK and OFDM). */
Sujith256b7752008-11-18 09:03:12 +05301213 if (now_msec - ath_rc_priv->rssi_down_time >=
Sujithdc2222a2008-08-14 13:26:55 +05301214 rate_table->rssi_reduce_interval) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001215
Sujith256b7752008-11-18 09:03:12 +05301216 for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
1217 if (ath_rc_priv->state[rate].rssi_thres >
Sujithdc2222a2008-08-14 13:26:55 +05301218 rate_table->info[rate].rssi_ack_validmin)
Sujith256b7752008-11-18 09:03:12 +05301219 ath_rc_priv->state[rate].rssi_thres -= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001220 }
Sujith256b7752008-11-18 09:03:12 +05301221 ath_rc_priv->rssi_down_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001222 }
1223
1224 /* Every so often, we reduce the thresholds
1225 * and PER (different for CCK and OFDM). */
Sujith256b7752008-11-18 09:03:12 +05301226 if (now_msec - ath_rc_priv->per_down_time >=
Sujithdc2222a2008-08-14 13:26:55 +05301227 rate_table->rssi_reduce_interval) {
Sujith256b7752008-11-18 09:03:12 +05301228 for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
1229 ath_rc_priv->state[rate].per =
1230 7 * ath_rc_priv->state[rate].per / 8;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001231 }
1232
Sujith256b7752008-11-18 09:03:12 +05301233 ath_rc_priv->per_down_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001234 }
1235}
1236
Sujith46d14a52008-11-18 09:08:13 +05301237static void ath_rc_tx_status(struct ath_softc *sc,
1238 struct ath_rate_priv *ath_rc_priv,
1239 struct ieee80211_tx_info *tx_info,
1240 int final_ts_idx, int xretries, int long_retry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001241{
Sujith46d14a52008-11-18 09:08:13 +05301242 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243 struct ath_rate_table *rate_table;
Sujitha8efee42008-11-18 09:07:30 +05301244 struct ieee80211_tx_rate *rates = tx_info->status.rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001245 u8 flags;
1246 u32 series = 0, rix;
1247
Sujithfe7f4a72008-11-18 09:07:06 +05301248 rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249
1250 /*
1251 * If the first rate is not the final index, there
1252 * are intermediate rate failures to be processed.
1253 */
1254 if (final_ts_idx != 0) {
1255 /* Process intermediate rates that failed.*/
1256 for (series = 0; series < final_ts_idx ; series++) {
Sujithe63835b2008-11-18 09:07:53 +05301257 if (rates[series].count != 0 && (rates[series].idx >= 0)) {
Sujitha8efee42008-11-18 09:07:30 +05301258 flags = rates[series].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001259 /* If HT40 and we have switched mode from
1260 * 40 to 20 => don't update */
Sujitha8efee42008-11-18 09:07:30 +05301261 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithe63835b2008-11-18 09:07:53 +05301262 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263 return;
Sujithe63835b2008-11-18 09:07:53 +05301264
Sujitha8efee42008-11-18 09:07:30 +05301265 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1266 (flags & IEEE80211_TX_RC_SHORT_GI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001267 rix = rate_table->info[
Sujitha8efee42008-11-18 09:07:30 +05301268 rates[series].idx].ht_index;
1269 else if (flags & IEEE80211_TX_RC_SHORT_GI)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001270 rix = rate_table->info[
Sujitha8efee42008-11-18 09:07:30 +05301271 rates[series].idx].sgi_index;
1272 else if (flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273 rix = rate_table->info[
Sujitha8efee42008-11-18 09:07:30 +05301274 rates[series].idx].cw40index;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001275 else
1276 rix = rate_table->info[
Sujitha8efee42008-11-18 09:07:30 +05301277 rates[series].idx].base_index;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001278 ath_rc_update_ht(sc, ath_rc_priv,
Sujith46d14a52008-11-18 09:08:13 +05301279 tx_info_priv, rix,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001280 xretries ? 1 : 2,
Sujitha8efee42008-11-18 09:07:30 +05301281 rates[series].count);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282 }
1283 }
1284 } else {
1285 /*
1286 * Handle the special case of MIMO PS burst, where the second
1287 * aggregate is sent out with only one rate and one try.
1288 * Treating it as an excessive retry penalizes the rate
1289 * inordinately.
1290 */
Sujitha8efee42008-11-18 09:07:30 +05301291 if (rates[0].count == 1 && xretries == 1)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001292 xretries = 2;
1293 }
1294
Sujitha8efee42008-11-18 09:07:30 +05301295 flags = rates[series].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001296 /* If HT40 and we have switched mode from 40 to 20 => don't update */
Sujitha8efee42008-11-18 09:07:30 +05301297 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithe63835b2008-11-18 09:07:53 +05301298 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001299 return;
Sujithe63835b2008-11-18 09:07:53 +05301300 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001301
Sujitha8efee42008-11-18 09:07:30 +05301302 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) && (flags & IEEE80211_TX_RC_SHORT_GI))
1303 rix = rate_table->info[rates[series].idx].ht_index;
1304 else if (flags & IEEE80211_TX_RC_SHORT_GI)
1305 rix = rate_table->info[rates[series].idx].sgi_index;
1306 else if (flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1307 rix = rate_table->info[rates[series].idx].cw40index;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001308 else
Sujitha8efee42008-11-18 09:07:30 +05301309 rix = rate_table->info[rates[series].idx].base_index;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001310
Sujith46d14a52008-11-18 09:08:13 +05301311 ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001312 xretries, long_retry);
1313}
1314
Sujith5ddfac32008-11-18 09:06:44 +05301315static void ath_rc_init(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +05301316 struct ath_rate_priv *ath_rc_priv,
Sujith5ddfac32008-11-18 09:06:44 +05301317 struct ieee80211_supported_band *sband,
1318 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001319{
1320 struct ath_rate_table *rate_table = NULL;
Sujith5ddfac32008-11-18 09:06:44 +05301321 struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
1322 u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001323 u8 i, j, k, hi = 0, hthi = 0;
1324
Sujithfe7f4a72008-11-18 09:07:06 +05301325 rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001326
Sujith5ddfac32008-11-18 09:06:44 +05301327 if (sta->ht_cap.ht_supported) {
1328 if (sband->band == IEEE80211_BAND_2GHZ)
Sujithfe7f4a72008-11-18 09:07:06 +05301329 rate_table = sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
Sujith5ddfac32008-11-18 09:06:44 +05301330 else
Sujithfe7f4a72008-11-18 09:07:06 +05301331 rate_table = sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
Sujith5ddfac32008-11-18 09:06:44 +05301332
1333 ath_rc_priv->ht_cap = (WLAN_RC_HT_FLAG | WLAN_RC_DS_FLAG);
Sujith46d14a52008-11-18 09:08:13 +05301334
Sujith5ddfac32008-11-18 09:06:44 +05301335 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1336 ath_rc_priv->ht_cap |= WLAN_RC_40_FLAG;
1337 }
1338
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001339 /* Initial rate table size. Will change depending
1340 * on the working rate set */
Sujith46d14a52008-11-18 09:08:13 +05301341 ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001342
1343 /* Initialize thresholds according to the global rate table */
Sujith5ddfac32008-11-18 09:06:44 +05301344 for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
Sujith256b7752008-11-18 09:03:12 +05301345 ath_rc_priv->state[i].rssi_thres =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 rate_table->info[i].rssi_ack_validmin;
Sujith256b7752008-11-18 09:03:12 +05301347 ath_rc_priv->state[i].per = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001348 }
1349
1350 /* Determine the valid rates */
Sujith256b7752008-11-18 09:03:12 +05301351 ath_rc_init_valid_txmask(ath_rc_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352
1353 for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
1354 for (j = 0; j < MAX_TX_RATE_PHY; j++)
Sujith256b7752008-11-18 09:03:12 +05301355 ath_rc_priv->valid_phy_rateidx[i][j] = 0;
1356 ath_rc_priv->valid_phy_ratecnt[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001357 }
Sujith5ddfac32008-11-18 09:06:44 +05301358 ath_rc_priv->rc_phy_mode = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001359
1360 /* Set stream capability */
Sujith5ddfac32008-11-18 09:06:44 +05301361 ath_rc_priv->single_stream = (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ? 0 : 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001362
1363 if (!rateset->rs_nrates) {
1364 /* No working rate, just initialize valid rates */
1365 hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table,
Sujith5ddfac32008-11-18 09:06:44 +05301366 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001367 } else {
1368 /* Use intersection of working rates and valid rates */
1369 hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table,
Sujith5ddfac32008-11-18 09:06:44 +05301370 rateset, ath_rc_priv->ht_cap);
1371 if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001372 hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv,
1373 rate_table,
1374 ht_mcs,
Sujith5ddfac32008-11-18 09:06:44 +05301375 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001376 }
1377 hi = A_MAX(hi, hthi);
1378 }
1379
Sujith256b7752008-11-18 09:03:12 +05301380 ath_rc_priv->rate_table_size = hi + 1;
1381 ath_rc_priv->rate_max_phy = 0;
Sujith46d14a52008-11-18 09:08:13 +05301382 ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001383
1384 for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
Sujith256b7752008-11-18 09:03:12 +05301385 for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
1386 ath_rc_priv->valid_rate_index[k++] =
1387 ath_rc_priv->valid_phy_rateidx[i][j];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001388 }
1389
Sujith46d14a52008-11-18 09:08:13 +05301390 if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
Sujith256b7752008-11-18 09:03:12 +05301391 || !ath_rc_priv->valid_phy_ratecnt[i])
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001392 continue;
1393
Sujith256b7752008-11-18 09:03:12 +05301394 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001395 }
Sujith46d14a52008-11-18 09:08:13 +05301396 ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
1397 ASSERT(k <= RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001398
Sujith256b7752008-11-18 09:03:12 +05301399 ath_rc_priv->max_valid_rate = k;
Sujith256b7752008-11-18 09:03:12 +05301400 ath_rc_sort_validrates(rate_table, ath_rc_priv);
1401 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001402}
1403
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001404/* Rate Control callbacks */
Johannes Berg4b7679a2008-09-18 18:14:18 +02001405static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1406 struct ieee80211_sta *sta, void *priv_sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001407 struct sk_buff *skb)
1408{
1409 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301410 struct ath_rate_priv *ath_rc_priv = priv_sta;
1411 struct ath_tx_info_priv *tx_info_priv = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001412 struct ath_node *an;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001413 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1414 struct ieee80211_hdr *hdr;
Sujith46d14a52008-11-18 09:08:13 +05301415 int final_ts_idx, tx_status = 0, is_underrun = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001416 __le16 fc;
1417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001418 hdr = (struct ieee80211_hdr *)skb->data;
1419 fc = hdr->frame_control;
Sujith46d14a52008-11-18 09:08:13 +05301420 tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
Sujithb5aa9bf2008-10-29 10:13:31 +05301421 an = (struct ath_node *)sta->drv_priv;
Sujith46d14a52008-11-18 09:08:13 +05301422 final_ts_idx = tx_info_priv->tx.ts_rateindex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001423
Sujith46d14a52008-11-18 09:08:13 +05301424 if (!an || !priv_sta || !ieee80211_is_data(fc))
1425 goto exit;
Johannes Berge6a98542008-10-21 12:40:02 +02001426
Sujith46d14a52008-11-18 09:08:13 +05301427 if (tx_info_priv->tx.ts_status & ATH9K_TXERR_FILT)
1428 goto exit;
Johannes Berge6a98542008-10-21 12:40:02 +02001429
Sujith46d14a52008-11-18 09:08:13 +05301430 if (tx_info_priv->tx.ts_rssi > 0) {
1431 ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi,
1432 tx_info_priv->tx.ts_rssi);
1433 }
1434
1435 /*
1436 * If underrun error is seen assume it as an excessive retry only
1437 * if prefetch trigger level have reached the max (0x3f for 5416)
1438 * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
1439 * times. This affects how ratectrl updates PER for the failed rate.
1440 */
1441 if (tx_info_priv->tx.ts_flags &
1442 (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
1443 ((sc->sc_ah->ah_txTrigLevel) >= ath_rc_priv->tx_triglevel_max)) {
1444 tx_status = 1;
1445 is_underrun = 1;
1446 }
1447
1448 if ((tx_info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
1449 (tx_info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
1450 tx_status = 1;
1451
1452 ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
1453 (is_underrun) ? ATH_11N_TXMAXTRY :
1454 tx_info_priv->tx.ts_longretry);
1455
1456exit:
Johannes Berge6a98542008-10-21 12:40:02 +02001457 kfree(tx_info_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001458}
1459
Johannes Berge6a98542008-10-21 12:40:02 +02001460static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1461 struct ieee80211_tx_rate_control *txrc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462{
Johannes Berge6a98542008-10-21 12:40:02 +02001463 struct ieee80211_supported_band *sband = txrc->sband;
1464 struct sk_buff *skb = txrc->skb;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001465 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg4b7679a2008-09-18 18:14:18 +02001466 struct ath_softc *sc = priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467 struct ieee80211_hw *hw = sc->hw;
Sujith46d14a52008-11-18 09:08:13 +05301468 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujith46d14a52008-11-18 09:08:13 +05301470 int is_probe = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001471 __le16 fc = hdr->frame_control;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001472
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001473 /* lowest rate for management and multicast/broadcast frames */
Sujitha8efee42008-11-18 09:07:30 +05301474 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1475 tx_info->control.rates[0].idx = rate_lowest_index(sband, sta);
1476 tx_info->control.rates[0].count =
1477 is_multicast_ether_addr(hdr->addr1) ? 1 : ATH_MGT_TXMAXTRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478 return;
1479 }
1480
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001481 /* Find tx rate for unicast frames */
Sujith46d14a52008-11-18 09:08:13 +05301482 ath_rc_ratefind(sc, ath_rc_priv, ATH_11N_TXMAXTRY, 4,
1483 tx_info, &is_probe, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001484
1485 /* Check if aggregation has to be enabled for this tid */
Johannes Bergae5eb022008-10-14 16:58:37 +02001486 if (hw->conf.ht.enabled) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487 if (ieee80211_is_data_qos(fc)) {
Sujith46d14a52008-11-18 09:08:13 +05301488 u8 *qc, tid;
1489 struct ath_node *an;
1490
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491 qc = ieee80211_get_qos_ctl(hdr);
1492 tid = qc[0] & 0xf;
Sujithb5aa9bf2008-10-29 10:13:31 +05301493 an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001494
Sujithccc75c52008-10-29 10:18:14 +05301495 if(ath_tx_aggr_check(sc, an, tid))
1496 ieee80211_start_tx_ba_session(hw, hdr->addr1, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001497 }
1498 }
1499}
1500
Johannes Berg4b7679a2008-09-18 18:14:18 +02001501static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
1502 struct ieee80211_sta *sta, void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503{
Johannes Berg4b7679a2008-09-18 18:14:18 +02001504 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301505 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001506 int i, j = 0;
1507
Sujith7b4d2732008-11-18 09:04:00 +05301508 for (i = 0; i < sband->n_bitrates; i++) {
1509 if (sta->supp_rates[sband->band] & BIT(i)) {
1510 ath_rc_priv->neg_rates.rs_rates[j]
1511 = (sband->bitrates[i].bitrate * 2) / 10;
1512 j++;
1513 }
1514 }
1515 ath_rc_priv->neg_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001516
Sujitha4510bf2008-10-23 12:15:19 +05301517 if (sta->ht_cap.ht_supported) {
Sujith7b4d2732008-11-18 09:04:00 +05301518 for (i = 0, j = 0; i < 77; i++) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001519 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
Sujithdc2222a2008-08-14 13:26:55 +05301520 ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001521 if (j == ATH_RATE_MAX)
1522 break;
1523 }
Sujithdc2222a2008-08-14 13:26:55 +05301524 ath_rc_priv->neg_ht_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525 }
Sujith7b4d2732008-11-18 09:04:00 +05301526
Sujith5ddfac32008-11-18 09:06:44 +05301527 ath_rc_init(sc, priv_sta, sband, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001528}
1529
Johannes Berg4b7679a2008-09-18 18:14:18 +02001530static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001531{
Johannes Berg4b7679a2008-09-18 18:14:18 +02001532 return hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001533}
1534
1535static void ath_rate_free(void *priv)
1536{
1537 return;
1538}
1539
Johannes Berg4b7679a2008-09-18 18:14:18 +02001540static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001541{
1542 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301543 struct ath_rate_priv *rate_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001544
Sujith46d14a52008-11-18 09:08:13 +05301545 rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001546 if (!rate_priv) {
Sujithdc2222a2008-08-14 13:26:55 +05301547 DPRINTF(sc, ATH_DBG_FATAL,
1548 "%s: Unable to allocate private rc structure\n",
1549 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001550 return NULL;
1551 }
Sujithfe605942008-11-18 09:03:36 +05301552
Sujithfe605942008-11-18 09:03:36 +05301553 rate_priv->rssi_down_time = jiffies_to_msecs(jiffies);
Sujithfe7f4a72008-11-18 09:07:06 +05301554 rate_priv->tx_triglevel_max = sc->sc_ah->ah_caps.tx_triglevel_max;
Sujithdc2222a2008-08-14 13:26:55 +05301555
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001556 return rate_priv;
1557}
1558
Johannes Berg4b7679a2008-09-18 18:14:18 +02001559static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
1560 void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001561{
Sujith46d14a52008-11-18 09:08:13 +05301562 struct ath_rate_priv *rate_priv = priv_sta;
Sujithfe605942008-11-18 09:03:36 +05301563 kfree(rate_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001564}
1565
1566static struct rate_control_ops ath_rate_ops = {
1567 .module = NULL,
1568 .name = "ath9k_rate_control",
1569 .tx_status = ath_tx_status,
1570 .get_rate = ath_get_rate,
1571 .rate_init = ath_rate_init,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001572 .alloc = ath_rate_alloc,
1573 .free = ath_rate_free,
1574 .alloc_sta = ath_rate_alloc_sta,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001575 .free_sta = ath_rate_free_sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001576};
1577
Sujithe63835b2008-11-18 09:07:53 +05301578static void ath_setup_rate_table(struct ath_softc *sc,
1579 struct ath_rate_table *rate_table)
1580{
1581 int i;
1582
1583 for (i = 0; i < 256; i++)
1584 rate_table->rateCodeToIndex[i] = (u8)-1;
1585
1586 for (i = 0; i < rate_table->rate_cnt; i++) {
1587 u8 code = rate_table->info[i].ratecode;
1588 u8 cix = rate_table->info[i].ctrl_rate;
1589 u8 sh = rate_table->info[i].short_preamble;
1590
1591 rate_table->rateCodeToIndex[code] = i;
1592 rate_table->rateCodeToIndex[code | sh] = i;
1593
1594 rate_table->info[i].lpAckDuration =
1595 ath9k_hw_computetxtime(sc->sc_ah, rate_table,
1596 WLAN_CTRL_FRAME_SIZE,
1597 cix,
1598 false);
1599 rate_table->info[i].spAckDuration =
1600 ath9k_hw_computetxtime(sc->sc_ah, rate_table,
1601 WLAN_CTRL_FRAME_SIZE,
1602 cix,
1603 true);
1604 }
1605}
1606
Sujithfe7f4a72008-11-18 09:07:06 +05301607void ath_rate_attach(struct ath_softc *sc)
1608{
1609 sc->hw_rate_table[ATH9K_MODE_11B] =
1610 &ar5416_11b_ratetable;
1611 sc->hw_rate_table[ATH9K_MODE_11A] =
1612 &ar5416_11a_ratetable;
1613 sc->hw_rate_table[ATH9K_MODE_11G] =
1614 &ar5416_11g_ratetable;
1615 sc->hw_rate_table[ATH9K_MODE_11NA_HT20] =
1616 &ar5416_11na_ratetable;
1617 sc->hw_rate_table[ATH9K_MODE_11NG_HT20] =
1618 &ar5416_11ng_ratetable;
1619 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
1620 &ar5416_11na_ratetable;
1621 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
1622 &ar5416_11na_ratetable;
1623 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
1624 &ar5416_11ng_ratetable;
1625 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
1626 &ar5416_11ng_ratetable;
Sujithe63835b2008-11-18 09:07:53 +05301627
1628 ath_setup_rate_table(sc, &ar5416_11b_ratetable);
1629 ath_setup_rate_table(sc, &ar5416_11a_ratetable);
1630 ath_setup_rate_table(sc, &ar5416_11g_ratetable);
1631 ath_setup_rate_table(sc, &ar5416_11na_ratetable);
1632 ath_setup_rate_table(sc, &ar5416_11ng_ratetable);
Sujithfe7f4a72008-11-18 09:07:06 +05301633}
1634
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001635int ath_rate_control_register(void)
1636{
1637 return ieee80211_rate_control_register(&ath_rate_ops);
1638}
1639
1640void ath_rate_control_unregister(void)
1641{
1642 ieee80211_rate_control_unregister(&ath_rate_ops);
1643}