abefde7109cd8bdb972d8eb4cb56c09be71f8594
[openwrt/staging/jow.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 26 Dec 2020 13:56:42 +0100
3 Subject: [PATCH] mac80211: minstrel_ht: add support for OFDM rates on
4 non-HT clients
5
6 The legacy minstrel code is essentially unmaintained and receives only very
7 little testing. In order to bring the significant algorithm improvements from
8 minstrel_ht to legacy clients, this patch adds support for OFDM rates to
9 minstrel_ht and removes the fallback to the legacy codepath.
10 This also makes it work much better on hardware with rate selection constraints,
11 e.g. mt76.
12
13 Signed-off-by: Felix Fietkau <nbd@nbd.name>
14 ---
15
16 --- a/net/mac80211/rc80211_minstrel.h
17 +++ b/net/mac80211/rc80211_minstrel.h
18 @@ -152,6 +152,7 @@ struct minstrel_priv {
19 unsigned int lookaround_rate_mrr;
20
21 u8 cck_rates[4];
22 + u8 ofdm_rates[NUM_NL80211_BANDS][8];
23
24 #ifdef CPTCFG_MAC80211_DEBUGFS
25 /*
26 --- a/net/mac80211/rc80211_minstrel_ht.c
27 +++ b/net/mac80211/rc80211_minstrel_ht.c
28 @@ -163,6 +163,38 @@
29
30 #define CCK_GROUP __CCK_GROUP(CCK_GROUP_SHIFT)
31
32 +#define OFDM_DURATION(_bitrate) \
33 + (1000 * (16 /* SIFS + signal ext */ + \
34 + 16 /* T_PREAMBLE */ + \
35 + 4 /* T_SIGNAL */ + \
36 + 4 * (((16 + 80 * (AVG_PKT_SIZE + 4) + 6) / \
37 + ((_bitrate) * 4)))))
38 +
39 +#define OFDM_DURATION_LIST(_s) \
40 + OFDM_DURATION(60) >> _s, \
41 + OFDM_DURATION(90) >> _s, \
42 + OFDM_DURATION(120) >> _s, \
43 + OFDM_DURATION(180) >> _s, \
44 + OFDM_DURATION(240) >> _s, \
45 + OFDM_DURATION(360) >> _s, \
46 + OFDM_DURATION(480) >> _s, \
47 + OFDM_DURATION(540) >> _s
48 +
49 +#define __OFDM_GROUP(_s) \
50 + [MINSTREL_OFDM_GROUP] = { \
51 + .streams = 1, \
52 + .flags = 0, \
53 + .shift = _s, \
54 + .duration = { \
55 + OFDM_DURATION_LIST(_s), \
56 + } \
57 + }
58 +
59 +#define OFDM_GROUP_SHIFT \
60 + GROUP_SHIFT(OFDM_DURATION(60))
61 +
62 +#define OFDM_GROUP __OFDM_GROUP(OFDM_GROUP_SHIFT)
63 +
64
65 static bool minstrel_vht_only = true;
66 module_param(minstrel_vht_only, bool, 0644);
67 @@ -199,6 +231,7 @@ const struct mcs_group minstrel_mcs_grou
68 MCS_GROUP(4, 1, BW_40),
69
70 CCK_GROUP,
71 + OFDM_GROUP,
72
73 VHT_GROUP(1, 0, BW_20),
74 VHT_GROUP(2, 0, BW_20),
75 @@ -231,6 +264,8 @@ const struct mcs_group minstrel_mcs_grou
76 VHT_GROUP(4, 1, BW_80),
77 };
78
79 +const s16 minstrel_cck_bitrates[4] = { 10, 20, 55, 110 };
80 +const s16 minstrel_ofdm_bitrates[8] = { 60, 90, 120, 180, 240, 360, 480, 540 };
81 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
82
83 static void
84 @@ -275,6 +310,13 @@ minstrel_get_valid_vht_rates(int bw, int
85 return 0x3ff & ~mask;
86 }
87
88 +static bool
89 +minstrel_ht_is_legacy_group(int group)
90 +{
91 + return group == MINSTREL_CCK_GROUP ||
92 + group == MINSTREL_OFDM_GROUP;
93 +}
94 +
95 /*
96 * Look up an MCS group index based on mac80211 rate information
97 */
98 @@ -304,21 +346,34 @@ minstrel_ht_get_stats(struct minstrel_pr
99 if (rate->flags & IEEE80211_TX_RC_MCS) {
100 group = minstrel_ht_get_group_idx(rate);
101 idx = rate->idx % 8;
102 - } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
103 + goto out;
104 + }
105 +
106 + if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
107 group = minstrel_vht_get_group_idx(rate);
108 idx = ieee80211_rate_get_vht_mcs(rate);
109 - } else {
110 - group = MINSTREL_CCK_GROUP;
111 + goto out;
112 + }
113
114 - for (idx = 0; idx < ARRAY_SIZE(mp->cck_rates); idx++)
115 - if (rate->idx == mp->cck_rates[idx])
116 - break;
117 + group = MINSTREL_CCK_GROUP;
118 + for (idx = 0; idx < ARRAY_SIZE(mp->cck_rates); idx++) {
119 + if (rate->idx != mp->cck_rates[idx])
120 + continue;
121
122 /* short preamble */
123 if ((mi->supported[group] & BIT(idx + 4)) &&
124 (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
125 - idx += 4;
126 + idx += 4;
127 + goto out;
128 }
129 +
130 + group = MINSTREL_OFDM_GROUP;
131 + for (idx = 0; idx < ARRAY_SIZE(mp->ofdm_rates[0]); idx++)
132 + if (rate->idx == mp->ofdm_rates[mi->band][idx])
133 + goto out;
134 +
135 + idx = 0;
136 +out:
137 return &mi->groups[group].rates[idx];
138 }
139
140 @@ -352,7 +407,7 @@ minstrel_ht_get_tp_avg(struct minstrel_h
141 if (prob_avg < MINSTREL_FRAC(10, 100))
142 return 0;
143
144 - if (group == MINSTREL_CCK_GROUP)
145 + if (minstrel_ht_is_legacy_group(group))
146 overhead = mi->overhead_legacy;
147 else
148 ampdu_len = minstrel_ht_avg_ampdu_len(mi);
149 @@ -439,8 +494,8 @@ minstrel_ht_set_best_prob_rate(struct mi
150 /* if max_tp_rate[0] is from MCS_GROUP max_prob_rate get selected from
151 * MCS_GROUP as well as CCK_GROUP rates do not allow aggregation */
152 max_tp_group = mi->max_tp_rate[0] / MCS_GROUP_RATES;
153 - if((index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) &&
154 - (max_tp_group != MINSTREL_CCK_GROUP))
155 + if (minstrel_ht_is_legacy_group(index / MCS_GROUP_RATES) &&
156 + !minstrel_ht_is_legacy_group(max_tp_group))
157 return;
158
159 max_gpr_group = mg->max_group_prob_rate / MCS_GROUP_RATES;
160 @@ -476,13 +531,13 @@ minstrel_ht_set_best_prob_rate(struct mi
161 static void
162 minstrel_ht_assign_best_tp_rates(struct minstrel_ht_sta *mi,
163 u16 tmp_mcs_tp_rate[MAX_THR_RATES],
164 - u16 tmp_cck_tp_rate[MAX_THR_RATES])
165 + u16 tmp_legacy_tp_rate[MAX_THR_RATES])
166 {
167 unsigned int tmp_group, tmp_idx, tmp_cck_tp, tmp_mcs_tp, tmp_prob;
168 int i;
169
170 - tmp_group = tmp_cck_tp_rate[0] / MCS_GROUP_RATES;
171 - tmp_idx = tmp_cck_tp_rate[0] % MCS_GROUP_RATES;
172 + tmp_group = tmp_legacy_tp_rate[0] / MCS_GROUP_RATES;
173 + tmp_idx = tmp_legacy_tp_rate[0] % MCS_GROUP_RATES;
174 tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_avg;
175 tmp_cck_tp = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx, tmp_prob);
176
177 @@ -493,7 +548,7 @@ minstrel_ht_assign_best_tp_rates(struct
178
179 if (tmp_cck_tp > tmp_mcs_tp) {
180 for(i = 0; i < MAX_THR_RATES; i++) {
181 - minstrel_ht_sort_best_tp_rates(mi, tmp_cck_tp_rate[i],
182 + minstrel_ht_sort_best_tp_rates(mi, tmp_legacy_tp_rate[i],
183 tmp_mcs_tp_rate);
184 }
185 }
186 @@ -511,6 +566,9 @@ minstrel_ht_prob_rate_reduce_streams(str
187 int tmp_max_streams, group, tmp_idx, tmp_prob;
188 int tmp_tp = 0;
189
190 + if (!mi->sta->ht_cap.ht_supported)
191 + return;
192 +
193 tmp_max_streams = minstrel_mcs_groups[mi->max_tp_rate[0] /
194 MCS_GROUP_RATES].streams;
195 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
196 @@ -675,7 +733,8 @@ minstrel_ht_update_stats(struct minstrel
197 struct minstrel_rate_stats *mrs;
198 int group, i, j, cur_prob;
199 u16 tmp_mcs_tp_rate[MAX_THR_RATES], tmp_group_tp_rate[MAX_THR_RATES];
200 - u16 tmp_cck_tp_rate[MAX_THR_RATES], index;
201 + u16 tmp_legacy_tp_rate[MAX_THR_RATES], index;
202 + bool ht_supported = mi->sta->ht_cap.ht_supported;
203
204 mi->sample_mode = MINSTREL_SAMPLE_IDLE;
205
206 @@ -704,21 +763,29 @@ minstrel_ht_update_stats(struct minstrel
207 mi->sample_count = 0;
208
209 memset(tmp_mcs_tp_rate, 0, sizeof(tmp_mcs_tp_rate));
210 - memset(tmp_cck_tp_rate, 0, sizeof(tmp_cck_tp_rate));
211 + memset(tmp_legacy_tp_rate, 0, sizeof(tmp_legacy_tp_rate));
212 if (mi->supported[MINSTREL_CCK_GROUP])
213 - for (j = 0; j < ARRAY_SIZE(tmp_cck_tp_rate); j++)
214 - tmp_cck_tp_rate[j] = MINSTREL_CCK_GROUP * MCS_GROUP_RATES;
215 + for (j = 0; j < ARRAY_SIZE(tmp_legacy_tp_rate); j++)
216 + tmp_legacy_tp_rate[j] = MINSTREL_CCK_GROUP * MCS_GROUP_RATES;
217 + else if (mi->supported[MINSTREL_OFDM_GROUP])
218 + for (j = 0; j < ARRAY_SIZE(tmp_legacy_tp_rate); j++)
219 + tmp_legacy_tp_rate[j] = MINSTREL_OFDM_GROUP * MCS_GROUP_RATES;
220
221 if (mi->supported[MINSTREL_VHT_GROUP_0])
222 index = MINSTREL_VHT_GROUP_0 * MCS_GROUP_RATES;
223 - else
224 + else if (ht_supported)
225 index = MINSTREL_HT_GROUP_0 * MCS_GROUP_RATES;
226 + else if (mi->supported[MINSTREL_CCK_GROUP])
227 + index = MINSTREL_CCK_GROUP * MCS_GROUP_RATES;
228 + else
229 + index = MINSTREL_OFDM_GROUP * MCS_GROUP_RATES;
230
231 for (j = 0; j < ARRAY_SIZE(tmp_mcs_tp_rate); j++)
232 tmp_mcs_tp_rate[j] = index;
233
234 /* Find best rate sets within all MCS groups*/
235 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
236 + u16 *tp_rate = tmp_mcs_tp_rate;
237
238 mg = &mi->groups[group];
239 if (!mi->supported[group])
240 @@ -730,6 +797,9 @@ minstrel_ht_update_stats(struct minstrel
241 for(j = 0; j < MAX_THR_RATES; j++)
242 tmp_group_tp_rate[j] = MCS_GROUP_RATES * group;
243
244 + if (group == MINSTREL_CCK_GROUP && ht_supported)
245 + tp_rate = tmp_legacy_tp_rate;
246 +
247 for (i = 0; i < MCS_GROUP_RATES; i++) {
248 if (!(mi->supported[group] & BIT(i)))
249 continue;
250 @@ -745,13 +815,7 @@ minstrel_ht_update_stats(struct minstrel
251 continue;
252
253 /* Find max throughput rate set */
254 - if (group != MINSTREL_CCK_GROUP) {
255 - minstrel_ht_sort_best_tp_rates(mi, index,
256 - tmp_mcs_tp_rate);
257 - } else if (group == MINSTREL_CCK_GROUP) {
258 - minstrel_ht_sort_best_tp_rates(mi, index,
259 - tmp_cck_tp_rate);
260 - }
261 + minstrel_ht_sort_best_tp_rates(mi, index, tp_rate);
262
263 /* Find max throughput rate set within a group */
264 minstrel_ht_sort_best_tp_rates(mi, index,
265 @@ -766,7 +830,8 @@ minstrel_ht_update_stats(struct minstrel
266 }
267
268 /* Assign new rate set per sta */
269 - minstrel_ht_assign_best_tp_rates(mi, tmp_mcs_tp_rate, tmp_cck_tp_rate);
270 + minstrel_ht_assign_best_tp_rates(mi, tmp_mcs_tp_rate,
271 + tmp_legacy_tp_rate);
272 memcpy(mi->max_tp_rate, tmp_mcs_tp_rate, sizeof(mi->max_tp_rate));
273
274 /* Try to increase robustness of max_prob_rate*/
275 @@ -795,8 +860,11 @@ minstrel_ht_update_stats(struct minstrel
276 }
277
278 static bool
279 -minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct ieee80211_tx_rate *rate)
280 +minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
281 + struct ieee80211_tx_rate *rate)
282 {
283 + int i;
284 +
285 if (rate->idx < 0)
286 return false;
287
288 @@ -807,10 +875,15 @@ minstrel_ht_txstat_valid(struct minstrel
289 rate->flags & IEEE80211_TX_RC_VHT_MCS)
290 return true;
291
292 - return rate->idx == mp->cck_rates[0] ||
293 - rate->idx == mp->cck_rates[1] ||
294 - rate->idx == mp->cck_rates[2] ||
295 - rate->idx == mp->cck_rates[3];
296 + for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++)
297 + if (rate->idx == mp->cck_rates[i])
298 + return true;
299 +
300 + for (i = 0; i < ARRAY_SIZE(mp->ofdm_rates[0]); i++)
301 + if (rate->idx == mp->ofdm_rates[mi->band][i])
302 + return true;
303 +
304 + return false;
305 }
306
307 static void
308 @@ -897,11 +970,6 @@ minstrel_ht_tx_status(void *priv, struct
309 bool sample_status = false;
310 int i;
311
312 - if (!msp->is_ht)
313 - return mac80211_minstrel.tx_status_ext(priv, sband,
314 - &msp->legacy, st);
315 -
316 -
317 /* This packet was aggregated but doesn't carry status info */
318 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
319 !(info->flags & IEEE80211_TX_STAT_AMPDU))
320 @@ -930,10 +998,10 @@ minstrel_ht_tx_status(void *priv, struct
321 if (mi->sample_mode != MINSTREL_SAMPLE_IDLE)
322 rate_sample = minstrel_get_ratestats(mi, mi->sample_rate);
323
324 - last = !minstrel_ht_txstat_valid(mp, &ar[0]);
325 + last = !minstrel_ht_txstat_valid(mp, mi, &ar[0]);
326 for (i = 0; !last; i++) {
327 last = (i == IEEE80211_TX_MAX_RATES - 1) ||
328 - !minstrel_ht_txstat_valid(mp, &ar[i + 1]);
329 + !minstrel_ht_txstat_valid(mp, mi, &ar[i + 1]);
330
331 rate = minstrel_ht_get_stats(mp, mi, &ar[i]);
332 if (rate == rate_sample)
333 @@ -1031,7 +1099,7 @@ minstrel_calc_retransmit(struct minstrel
334 ctime += (t_slot * cw) >> 1;
335 cw = min((cw << 1) | 1, mp->cw_max);
336
337 - if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
338 + if (minstrel_ht_is_legacy_group(index / MCS_GROUP_RATES)) {
339 overhead = mi->overhead_legacy;
340 overhead_rtscts = mi->overhead_legacy_rtscts;
341 } else {
342 @@ -1064,7 +1132,8 @@ static void
343 minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
344 struct ieee80211_sta_rates *ratetbl, int offset, int index)
345 {
346 - const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
347 + int group_idx = index / MCS_GROUP_RATES;
348 + const struct mcs_group *group = &minstrel_mcs_groups[group_idx];
349 struct minstrel_rate_stats *mrs;
350 u8 idx;
351 u16 flags = group->flags;
352 @@ -1083,13 +1152,17 @@ minstrel_ht_set_rate(struct minstrel_pri
353 ratetbl->rate[offset].count_rts = mrs->retry_count_rtscts;
354 }
355
356 - if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP)
357 + index %= MCS_GROUP_RATES;
358 + if (group_idx == MINSTREL_CCK_GROUP)
359 idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
360 + else if (group_idx == MINSTREL_OFDM_GROUP)
361 + idx = mp->ofdm_rates[mi->band][index %
362 + ARRAY_SIZE(mp->ofdm_rates[0])];
363 else if (flags & IEEE80211_TX_RC_VHT_MCS)
364 idx = ((group->streams - 1) << 4) |
365 - ((index % MCS_GROUP_RATES) & 0xF);
366 + (index & 0xF);
367 else
368 - idx = index % MCS_GROUP_RATES + (group->streams - 1) * 8;
369 + idx = index + (group->streams - 1) * 8;
370
371 /* enable RTS/CTS if needed:
372 * - if station is in dynamic SMPS (and streams > 1)
373 @@ -1304,11 +1377,8 @@ minstrel_ht_get_rate(void *priv, struct
374 struct minstrel_priv *mp = priv;
375 int sample_idx;
376
377 - if (!msp->is_ht)
378 - return mac80211_minstrel.get_rate(priv, sta, &msp->legacy, txrc);
379 -
380 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
381 - mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
382 + !minstrel_ht_is_legacy_group(mi->max_prob_rate / MCS_GROUP_RATES))
383 minstrel_aggr_check(sta, txrc->skb);
384
385 info->flags |= mi->tx_flags;
386 @@ -1349,6 +1419,9 @@ minstrel_ht_get_rate(void *priv, struct
387 if (sample_group == &minstrel_mcs_groups[MINSTREL_CCK_GROUP]) {
388 int idx = sample_idx % ARRAY_SIZE(mp->cck_rates);
389 rate->idx = mp->cck_rates[idx];
390 + } else if (sample_group == &minstrel_mcs_groups[MINSTREL_OFDM_GROUP]) {
391 + int idx = sample_idx % ARRAY_SIZE(mp->ofdm_rates[0]);
392 + rate->idx = mp->ofdm_rates[mi->band][idx];
393 } else if (sample_group->flags & IEEE80211_TX_RC_VHT_MCS) {
394 ieee80211_rate_set_vht(rate, sample_idx % MCS_GROUP_RATES,
395 sample_group->streams);
396 @@ -1369,11 +1442,13 @@ minstrel_ht_update_cck(struct minstrel_p
397 if (sband->band != NL80211_BAND_2GHZ)
398 return;
399
400 - if (!ieee80211_hw_check(mp->hw, SUPPORTS_HT_CCK_RATES))
401 + if (sta->ht_cap.ht_supported &&
402 + !ieee80211_hw_check(mp->hw, SUPPORTS_HT_CCK_RATES))
403 return;
404
405 for (i = 0; i < 4; i++) {
406 - if (!rate_supported(sta, sband->band, mp->cck_rates[i]))
407 + if (mp->cck_rates[i] == 0xff ||
408 + !rate_supported(sta, sband->band, mp->cck_rates[i]))
409 continue;
410
411 mi->supported[MINSTREL_CCK_GROUP] |= BIT(i);
412 @@ -1383,9 +1458,30 @@ minstrel_ht_update_cck(struct minstrel_p
413 }
414
415 static void
416 +minstrel_ht_update_ofdm(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
417 + struct ieee80211_supported_band *sband,
418 + struct ieee80211_sta *sta)
419 +{
420 + const u8 *rates;
421 + int i;
422 +
423 + if (sta->ht_cap.ht_supported)
424 + return;
425 +
426 + rates = mp->ofdm_rates[sband->band];
427 + for (i = 0; i < ARRAY_SIZE(mp->ofdm_rates[0]); i++) {
428 + if (rates[i] == 0xff ||
429 + !rate_supported(sta, sband->band, rates[i]))
430 + continue;
431 +
432 + mi->supported[MINSTREL_OFDM_GROUP] |= BIT(i);
433 + }
434 +}
435 +
436 +static void
437 minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
438 struct cfg80211_chan_def *chandef,
439 - struct ieee80211_sta *sta, void *priv_sta)
440 + struct ieee80211_sta *sta, void *priv_sta)
441 {
442 struct minstrel_priv *mp = priv;
443 struct minstrel_ht_sta_priv *msp = priv_sta;
444 @@ -1401,10 +1497,6 @@ minstrel_ht_update_caps(void *priv, stru
445 int stbc;
446 int i;
447
448 - /* fall back to the old minstrel for legacy stations */
449 - if (!sta->ht_cap.ht_supported)
450 - goto use_legacy;
451 -
452 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
453
454 if (vht_cap->vht_supported)
455 @@ -1412,10 +1504,10 @@ minstrel_ht_update_caps(void *priv, stru
456 else
457 use_vht = 0;
458
459 - msp->is_ht = true;
460 memset(mi, 0, sizeof(*mi));
461
462 mi->sta = sta;
463 + mi->band = sband->band;
464 mi->last_stats_update = jiffies;
465
466 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1, 0);
467 @@ -1464,10 +1556,8 @@ minstrel_ht_update_caps(void *priv, stru
468 int bw, nss;
469
470 mi->supported[i] = 0;
471 - if (i == MINSTREL_CCK_GROUP) {
472 - minstrel_ht_update_cck(mp, mi, sband, sta);
473 + if (minstrel_ht_is_legacy_group(i))
474 continue;
475 - }
476
477 if (gflags & IEEE80211_TX_RC_SHORT_GI) {
478 if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
479 @@ -1528,22 +1618,12 @@ minstrel_ht_update_caps(void *priv, stru
480 n_supported++;
481 }
482
483 - if (!n_supported)
484 - goto use_legacy;
485 + minstrel_ht_update_cck(mp, mi, sband, sta);
486 + minstrel_ht_update_ofdm(mp, mi, sband, sta);
487
488 /* create an initial rate table with the lowest supported rates */
489 minstrel_ht_update_stats(mp, mi, true);
490 minstrel_ht_update_rates(mp, mi);
491 -
492 - return;
493 -
494 -use_legacy:
495 - msp->is_ht = false;
496 - memset(&msp->legacy, 0, sizeof(msp->legacy));
497 - msp->legacy.r = msp->ratelist;
498 - msp->legacy.sample_table = msp->sample_table;
499 - return mac80211_minstrel.rate_init(priv, sband, chandef, sta,
500 - &msp->legacy);
501 }
502
503 static void
504 @@ -1611,40 +1691,70 @@ minstrel_ht_free_sta(void *priv, struct
505 }
506
507 static void
508 -minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
509 +minstrel_ht_fill_rate_array(u8 *dest, struct ieee80211_supported_band *sband,
510 + const s16 *bitrates, int n_rates, u32 rate_flags)
511 {
512 - static const int bitrates[4] = { 10, 20, 55, 110 };
513 - struct ieee80211_supported_band *sband;
514 - u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
515 int i, j;
516
517 - sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
518 - if (!sband)
519 - return;
520 -
521 for (i = 0; i < sband->n_bitrates; i++) {
522 struct ieee80211_rate *rate = &sband->bitrates[i];
523
524 - if (rate->flags & IEEE80211_RATE_ERP_G)
525 - continue;
526 -
527 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
528 continue;
529
530 - for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
531 + for (j = 0; j < n_rates; j++) {
532 if (rate->bitrate != bitrates[j])
533 continue;
534
535 - mp->cck_rates[j] = i;
536 + dest[j] = i;
537 break;
538 }
539 }
540 }
541
542 +static void
543 +minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
544 +{
545 + static const s16 bitrates[4] = { 10, 20, 55, 110 };
546 + struct ieee80211_supported_band *sband;
547 + u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
548 +
549 + memset(mp->cck_rates, 0xff, sizeof(mp->cck_rates));
550 + sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
551 + if (!sband)
552 + return;
553 +
554 + BUILD_BUG_ON(ARRAY_SIZE(mp->cck_rates) != ARRAY_SIZE(bitrates));
555 + minstrel_ht_fill_rate_array(mp->cck_rates, sband,
556 + minstrel_cck_bitrates,
557 + ARRAY_SIZE(minstrel_cck_bitrates),
558 + rate_flags);
559 +}
560 +
561 +static void
562 +minstrel_ht_init_ofdm_rates(struct minstrel_priv *mp, enum nl80211_band band)
563 +{
564 + static const s16 bitrates[8] = { 60, 90, 120, 180, 240, 360, 480, 540 };
565 + struct ieee80211_supported_band *sband;
566 + u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
567 +
568 + memset(mp->ofdm_rates[band], 0xff, sizeof(mp->ofdm_rates[band]));
569 + sband = mp->hw->wiphy->bands[band];
570 + if (!sband)
571 + return;
572 +
573 + BUILD_BUG_ON(ARRAY_SIZE(mp->ofdm_rates[band]) != ARRAY_SIZE(bitrates));
574 + minstrel_ht_fill_rate_array(mp->ofdm_rates[band], sband,
575 + minstrel_ofdm_bitrates,
576 + ARRAY_SIZE(minstrel_ofdm_bitrates),
577 + rate_flags);
578 +}
579 +
580 static void *
581 minstrel_ht_alloc(struct ieee80211_hw *hw)
582 {
583 struct minstrel_priv *mp;
584 + int i;
585
586 mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
587 if (!mp)
588 @@ -1681,6 +1791,8 @@ minstrel_ht_alloc(struct ieee80211_hw *h
589 mp->new_avg = true;
590
591 minstrel_ht_init_cck_rates(mp);
592 + for (i = 0; i < ARRAY_SIZE(mp->hw->wiphy->bands); i++)
593 + minstrel_ht_init_ofdm_rates(mp, i);
594
595 return mp;
596 }
597 @@ -1713,9 +1825,6 @@ static u32 minstrel_ht_get_expected_thro
598 struct minstrel_ht_sta *mi = &msp->ht;
599 int i, j, prob, tp_avg;
600
601 - if (!msp->is_ht)
602 - return mac80211_minstrel.get_expected_throughput(priv_sta);
603 -
604 i = mi->max_tp_rate[0] / MCS_GROUP_RATES;
605 j = mi->max_tp_rate[0] % MCS_GROUP_RATES;
606 prob = mi->groups[i].rates[j].prob_avg;
607 --- a/net/mac80211/rc80211_minstrel_ht.h
608 +++ b/net/mac80211/rc80211_minstrel_ht.h
609 @@ -18,14 +18,15 @@
610 MINSTREL_HT_STREAM_GROUPS)
611 #define MINSTREL_VHT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
612 MINSTREL_VHT_STREAM_GROUPS)
613 -#define MINSTREL_CCK_GROUPS_NB 1
614 +#define MINSTREL_LEGACY_GROUPS_NB 2
615 #define MINSTREL_GROUPS_NB (MINSTREL_HT_GROUPS_NB + \
616 MINSTREL_VHT_GROUPS_NB + \
617 - MINSTREL_CCK_GROUPS_NB)
618 + MINSTREL_LEGACY_GROUPS_NB)
619
620 #define MINSTREL_HT_GROUP_0 0
621 #define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
622 -#define MINSTREL_VHT_GROUP_0 (MINSTREL_CCK_GROUP + 1)
623 +#define MINSTREL_OFDM_GROUP (MINSTREL_CCK_GROUP + 1)
624 +#define MINSTREL_VHT_GROUP_0 (MINSTREL_OFDM_GROUP + 1)
625
626 #define MCS_GROUP_RATES 10
627
628 @@ -37,6 +38,8 @@ struct mcs_group {
629 u16 duration[MCS_GROUP_RATES];
630 };
631
632 +extern const s16 minstrel_cck_bitrates[4];
633 +extern const s16 minstrel_ofdm_bitrates[8];
634 extern const struct mcs_group minstrel_mcs_groups[];
635
636 struct minstrel_mcs_group_data {
637 @@ -99,6 +102,8 @@ struct minstrel_ht_sta {
638 /* current MCS group to be sampled */
639 u8 sample_group;
640
641 + u8 band;
642 +
643 /* Bitfield of supported MCS rates of all groups */
644 u16 supported[MINSTREL_GROUPS_NB];
645
646 @@ -107,13 +112,9 @@ struct minstrel_ht_sta {
647 };
648
649 struct minstrel_ht_sta_priv {
650 - union {
651 - struct minstrel_ht_sta ht;
652 - struct minstrel_sta_info legacy;
653 - };
654 + struct minstrel_ht_sta ht;
655 void *ratelist;
656 void *sample_table;
657 - bool is_ht;
658 };
659
660 void minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
661 --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
662 +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
663 @@ -52,7 +52,6 @@ minstrel_ht_stats_dump(struct minstrel_h
664
665 for (j = 0; j < MCS_GROUP_RATES; j++) {
666 struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
667 - static const int bitrates[4] = { 10, 20, 55, 110 };
668 int idx = i * MCS_GROUP_RATES + j;
669 unsigned int duration;
670
671 @@ -67,6 +66,9 @@ minstrel_ht_stats_dump(struct minstrel_h
672 p += sprintf(p, "VHT%c0 ", htmode);
673 p += sprintf(p, "%cGI ", gimode);
674 p += sprintf(p, "%d ", mg->streams);
675 + } else if (i == MINSTREL_OFDM_GROUP) {
676 + p += sprintf(p, "OFDM ");
677 + p += sprintf(p, "1 ");
678 } else {
679 p += sprintf(p, "CCK ");
680 p += sprintf(p, "%cP ", j < 4 ? 'L' : 'S');
681 @@ -84,7 +86,12 @@ minstrel_ht_stats_dump(struct minstrel_h
682 } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
683 p += sprintf(p, " MCS%-1u/%1u", j, mg->streams);
684 } else {
685 - int r = bitrates[j % 4];
686 + int r;
687 +
688 + if (i == MINSTREL_OFDM_GROUP)
689 + r = minstrel_ofdm_bitrates[j % 8];
690 + else
691 + r = minstrel_cck_bitrates[j % 4];
692
693 p += sprintf(p, " %2u.%1uM", r / 10, r % 10);
694 }
695 @@ -124,16 +131,8 @@ minstrel_ht_stats_open(struct inode *ino
696 struct minstrel_ht_sta *mi = &msp->ht;
697 struct minstrel_debugfs_info *ms;
698 unsigned int i;
699 - int ret;
700 char *p;
701
702 - if (!msp->is_ht) {
703 - inode->i_private = &msp->legacy;
704 - ret = minstrel_stats_open(inode, file);
705 - inode->i_private = msp;
706 - return ret;
707 - }
708 -
709 ms = kmalloc(32768, GFP_KERNEL);
710 if (!ms)
711 return -ENOMEM;
712 @@ -199,7 +198,6 @@ minstrel_ht_stats_csv_dump(struct minstr
713
714 for (j = 0; j < MCS_GROUP_RATES; j++) {
715 struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
716 - static const int bitrates[4] = { 10, 20, 55, 110 };
717 int idx = i * MCS_GROUP_RATES + j;
718 unsigned int duration;
719
720 @@ -214,6 +212,8 @@ minstrel_ht_stats_csv_dump(struct minstr
721 p += sprintf(p, "VHT%c0,", htmode);
722 p += sprintf(p, "%cGI,", gimode);
723 p += sprintf(p, "%d,", mg->streams);
724 + } else if (i == MINSTREL_OFDM_GROUP) {
725 + p += sprintf(p, "OFDM,,1,");
726 } else {
727 p += sprintf(p, "CCK,");
728 p += sprintf(p, "%cP,", j < 4 ? 'L' : 'S');
729 @@ -231,7 +231,13 @@ minstrel_ht_stats_csv_dump(struct minstr
730 } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
731 p += sprintf(p, ",MCS%-1u/%1u,", j, mg->streams);
732 } else {
733 - int r = bitrates[j % 4];
734 + int r;
735 +
736 + if (i == MINSTREL_OFDM_GROUP)
737 + r = minstrel_ofdm_bitrates[j % 8];
738 + else
739 + r = minstrel_cck_bitrates[j % 4];
740 +
741 p += sprintf(p, ",%2u.%1uM,", r / 10, r % 10);
742 }
743
744 @@ -274,18 +280,9 @@ minstrel_ht_stats_csv_open(struct inode
745 struct minstrel_ht_sta *mi = &msp->ht;
746 struct minstrel_debugfs_info *ms;
747 unsigned int i;
748 - int ret;
749 char *p;
750
751 - if (!msp->is_ht) {
752 - inode->i_private = &msp->legacy;
753 - ret = minstrel_stats_csv_open(inode, file);
754 - inode->i_private = msp;
755 - return ret;
756 - }
757 -
758 ms = kmalloc(32768, GFP_KERNEL);
759 -
760 if (!ms)
761 return -ENOMEM;
762