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