mac80211: add minstrel improvements/fixes
[openwrt/staging/wigyori.git] / package / kernel / mac80211 / patches / 327-mac80211-minstrel-merge-with-minstrel_ht-always-enab.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 10 Feb 2018 12:43:30 +0100
3 Subject: [PATCH] mac80211: minstrel: merge with minstrel_ht, always enable
4 VHT support
5
6 Legacy-only devices are not very common and the overhead of the extra
7 code for HT and VHT rates is not big enough to justify all those extra
8 lines of code to make it optional.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/net/mac80211/Kconfig
14 +++ b/net/mac80211/Kconfig
15 @@ -25,20 +25,6 @@ config MAC80211_RC_MINSTREL
16 ---help---
17 This option enables the 'minstrel' TX rate control algorithm
18
19 -config MAC80211_RC_MINSTREL_HT
20 - bool "Minstrel 802.11n support" if EXPERT
21 - depends on MAC80211_RC_MINSTREL
22 - default y
23 - ---help---
24 - This option enables the 'minstrel_ht' TX rate control algorithm
25 -
26 -config MAC80211_RC_MINSTREL_VHT
27 - bool "Minstrel 802.11ac support" if EXPERT
28 - depends on MAC80211_RC_MINSTREL_HT
29 - default n
30 - ---help---
31 - This option enables VHT in the 'minstrel_ht' TX rate control algorithm
32 -
33 choice
34 prompt "Default rate control algorithm"
35 depends on MAC80211_HAS_RC
36 @@ -60,8 +46,7 @@ endchoice
37
38 config MAC80211_RC_DEFAULT
39 string
40 - default "minstrel_ht" if MAC80211_RC_DEFAULT_MINSTREL && MAC80211_RC_MINSTREL_HT
41 - default "minstrel" if MAC80211_RC_DEFAULT_MINSTREL
42 + default "minstrel_ht" if MAC80211_RC_DEFAULT_MINSTREL
43 default ""
44
45 endif
46 --- a/net/mac80211/Makefile
47 +++ b/net/mac80211/Makefile
48 @@ -50,13 +50,14 @@ mac80211-$(CONFIG_PM) += pm.o
49
50 CFLAGS_trace.o := -I$(src)
51
52 -rc80211_minstrel-y := rc80211_minstrel.o
53 -rc80211_minstrel-$(CPTCFG_MAC80211_DEBUGFS) += rc80211_minstrel_debugfs.o
54 +rc80211_minstrel-y := \
55 + rc80211_minstrel.o \
56 + rc80211_minstrel_ht.o
57
58 -rc80211_minstrel_ht-y := rc80211_minstrel_ht.o
59 -rc80211_minstrel_ht-$(CPTCFG_MAC80211_DEBUGFS) += rc80211_minstrel_ht_debugfs.o
60 +rc80211_minstrel-$(CPTCFG_MAC80211_DEBUGFS) += \
61 + rc80211_minstrel_debugfs.o \
62 + rc80211_minstrel_ht_debugfs.o
63
64 mac80211-$(CPTCFG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
65 -mac80211-$(CPTCFG_MAC80211_RC_MINSTREL_HT) += $(rc80211_minstrel_ht-y)
66
67 ccflags-y += -DDEBUG
68 --- a/net/mac80211/main.c
69 +++ b/net/mac80211/main.c
70 @@ -1252,18 +1252,12 @@ static int __init ieee80211_init(void)
71 if (ret)
72 return ret;
73
74 - ret = rc80211_minstrel_ht_init();
75 - if (ret)
76 - goto err_minstrel;
77 -
78 ret = ieee80211_iface_init();
79 if (ret)
80 goto err_netdev;
81
82 return 0;
83 err_netdev:
84 - rc80211_minstrel_ht_exit();
85 - err_minstrel:
86 rc80211_minstrel_exit();
87
88 return ret;
89 @@ -1271,7 +1265,6 @@ static int __init ieee80211_init(void)
90
91 static void __exit ieee80211_exit(void)
92 {
93 - rc80211_minstrel_ht_exit();
94 rc80211_minstrel_exit();
95
96 ieee80211s_stop();
97 --- a/net/mac80211/rate.h
98 +++ b/net/mac80211/rate.h
99 @@ -95,18 +95,5 @@ static inline void rc80211_minstrel_exit
100 }
101 #endif
102
103 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_HT
104 -int rc80211_minstrel_ht_init(void);
105 -void rc80211_minstrel_ht_exit(void);
106 -#else
107 -static inline int rc80211_minstrel_ht_init(void)
108 -{
109 - return 0;
110 -}
111 -static inline void rc80211_minstrel_ht_exit(void)
112 -{
113 -}
114 -#endif
115 -
116
117 #endif /* IEEE80211_RATE_H */
118 --- a/net/mac80211/rc80211_minstrel.c
119 +++ b/net/mac80211/rc80211_minstrel.c
120 @@ -482,6 +482,38 @@ init_sample_table(struct minstrel_sta_in
121 }
122
123 static void
124 +minstrel_init_cck_rates(struct minstrel_priv *mp,
125 + struct cfg80211_chan_def *chandef)
126 +{
127 + static const int bitrates[4] = { 10, 20, 55, 110 };
128 + struct ieee80211_supported_band *sband;
129 + u32 rate_flags = ieee80211_chandef_rate_flags(chandef);
130 + int i, j;
131 +
132 + sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
133 + if (!sband)
134 + return;
135 +
136 + for (i = 0, j = 0; i < sband->n_bitrates; i++) {
137 + struct ieee80211_rate *rate = &sband->bitrates[i];
138 +
139 + if (rate->flags & IEEE80211_RATE_ERP_G)
140 + continue;
141 +
142 + if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
143 + continue;
144 +
145 + for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
146 + if (rate->bitrate != bitrates[j])
147 + continue;
148 +
149 + mp->cck_rates[j] = i;
150 + break;
151 + }
152 + }
153 +}
154 +
155 +static void
156 minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
157 struct cfg80211_chan_def *chandef,
158 struct ieee80211_sta *sta, void *priv_sta)
159 @@ -493,6 +525,8 @@ minstrel_rate_init(void *priv, struct ie
160 unsigned int t_slot = 9; /* FIXME: get real slot time */
161 u32 rate_flags;
162
163 + minstrel_init_cck_rates(mp, chandef);
164 +
165 mi->sta = sta;
166 mi->lowest_rix = rate_lowest_index(sband, sta);
167 ctl_rate = &sband->bitrates[mi->lowest_rix];
168 @@ -572,138 +606,6 @@ minstrel_rate_init(void *priv, struct ie
169 minstrel_update_rates(mp, mi);
170 }
171
172 -static void *
173 -minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
174 -{
175 - struct ieee80211_supported_band *sband;
176 - struct minstrel_sta_info *mi;
177 - struct minstrel_priv *mp = priv;
178 - struct ieee80211_hw *hw = mp->hw;
179 - int max_rates = 0;
180 - int i;
181 -
182 - mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
183 - if (!mi)
184 - return NULL;
185 -
186 - for (i = 0; i < NUM_NL80211_BANDS; i++) {
187 - sband = hw->wiphy->bands[i];
188 - if (sband && sband->n_bitrates > max_rates)
189 - max_rates = sband->n_bitrates;
190 - }
191 -
192 - mi->r = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp);
193 - if (!mi->r)
194 - goto error;
195 -
196 - mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
197 - if (!mi->sample_table)
198 - goto error1;
199 -
200 - mi->last_stats_update = jiffies;
201 - return mi;
202 -
203 -error1:
204 - kfree(mi->r);
205 -error:
206 - kfree(mi);
207 - return NULL;
208 -}
209 -
210 -static void
211 -minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
212 -{
213 - struct minstrel_sta_info *mi = priv_sta;
214 -
215 - kfree(mi->sample_table);
216 - kfree(mi->r);
217 - kfree(mi);
218 -}
219 -
220 -static void
221 -minstrel_init_cck_rates(struct minstrel_priv *mp)
222 -{
223 - static const int bitrates[4] = { 10, 20, 55, 110 };
224 - struct ieee80211_supported_band *sband;
225 - u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
226 - int i, j;
227 -
228 - sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
229 - if (!sband)
230 - return;
231 -
232 - for (i = 0, j = 0; i < sband->n_bitrates; i++) {
233 - struct ieee80211_rate *rate = &sband->bitrates[i];
234 -
235 - if (rate->flags & IEEE80211_RATE_ERP_G)
236 - continue;
237 -
238 - if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
239 - continue;
240 -
241 - for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
242 - if (rate->bitrate != bitrates[j])
243 - continue;
244 -
245 - mp->cck_rates[j] = i;
246 - break;
247 - }
248 - }
249 -}
250 -
251 -static void *
252 -minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
253 -{
254 - struct minstrel_priv *mp;
255 -
256 - mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
257 - if (!mp)
258 - return NULL;
259 -
260 - /* contention window settings
261 - * Just an approximation. Using the per-queue values would complicate
262 - * the calculations and is probably unnecessary */
263 - mp->cw_min = 15;
264 - mp->cw_max = 1023;
265 -
266 - /* number of packets (in %) to use for sampling other rates
267 - * sample less often for non-mrr packets, because the overhead
268 - * is much higher than with mrr */
269 - mp->lookaround_rate = 5;
270 - mp->lookaround_rate_mrr = 10;
271 -
272 - /* maximum time that the hw is allowed to stay in one MRR segment */
273 - mp->segment_size = 6000;
274 -
275 - if (hw->max_rate_tries > 0)
276 - mp->max_retry = hw->max_rate_tries;
277 - else
278 - /* safe default, does not necessarily have to match hw properties */
279 - mp->max_retry = 7;
280 -
281 - if (hw->max_rates >= 4)
282 - mp->has_mrr = true;
283 -
284 - mp->hw = hw;
285 - mp->update_interval = 100;
286 -
287 -#ifdef CPTCFG_MAC80211_DEBUGFS
288 - mp->fixed_rate_idx = (u32) -1;
289 - debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
290 - &mp->fixed_rate_idx);
291 -#endif
292 -
293 - minstrel_init_cck_rates(mp);
294 -
295 - return mp;
296 -}
297 -
298 -static void
299 -minstrel_free(void *priv)
300 -{
301 - kfree(priv);
302 -}
303 -
304 static u32 minstrel_get_expected_throughput(void *priv_sta)
305 {
306 struct minstrel_sta_info *mi = priv_sta;
307 @@ -722,29 +624,8 @@ static u32 minstrel_get_expected_through
308 }
309
310 const struct rate_control_ops mac80211_minstrel = {
311 - .name = "minstrel",
312 .tx_status_ext = minstrel_tx_status,
313 .get_rate = minstrel_get_rate,
314 .rate_init = minstrel_rate_init,
315 - .alloc = minstrel_alloc,
316 - .free = minstrel_free,
317 - .alloc_sta = minstrel_alloc_sta,
318 - .free_sta = minstrel_free_sta,
319 -#ifdef CPTCFG_MAC80211_DEBUGFS
320 - .add_sta_debugfs = minstrel_add_sta_debugfs,
321 -#endif
322 .get_expected_throughput = minstrel_get_expected_throughput,
323 };
324 -
325 -int __init
326 -rc80211_minstrel_init(void)
327 -{
328 - return ieee80211_rate_control_register(&mac80211_minstrel);
329 -}
330 -
331 -void
332 -rc80211_minstrel_exit(void)
333 -{
334 - ieee80211_rate_control_unregister(&mac80211_minstrel);
335 -}
336 -
337 --- a/net/mac80211/rc80211_minstrel.h
338 +++ b/net/mac80211/rc80211_minstrel.h
339 @@ -158,7 +158,5 @@ int minstrel_get_tp_avg(struct minstrel_
340 /* debugfs */
341 int minstrel_stats_open(struct inode *inode, struct file *file);
342 int minstrel_stats_csv_open(struct inode *inode, struct file *file);
343 -ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
344 -int minstrel_stats_release(struct inode *inode, struct file *file);
345
346 #endif
347 --- a/net/mac80211/rc80211_minstrel_debugfs.c
348 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
349 @@ -54,22 +54,6 @@
350 #include <net/mac80211.h>
351 #include "rc80211_minstrel.h"
352
353 -ssize_t
354 -minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
355 -{
356 - struct minstrel_debugfs_info *ms;
357 -
358 - ms = file->private_data;
359 - return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
360 -}
361 -
362 -int
363 -minstrel_stats_release(struct inode *inode, struct file *file)
364 -{
365 - kfree(file->private_data);
366 - return 0;
367 -}
368 -
369 int
370 minstrel_stats_open(struct inode *inode, struct file *file)
371 {
372 @@ -135,14 +119,6 @@ minstrel_stats_open(struct inode *inode,
373 return 0;
374 }
375
376 -static const struct file_operations minstrel_stat_fops = {
377 - .owner = THIS_MODULE,
378 - .open = minstrel_stats_open,
379 - .read = minstrel_stats_read,
380 - .release = minstrel_stats_release,
381 - .llseek = default_llseek,
382 -};
383 -
384 int
385 minstrel_stats_csv_open(struct inode *inode, struct file *file)
386 {
387 @@ -200,21 +176,3 @@ minstrel_stats_csv_open(struct inode *in
388
389 return 0;
390 }
391 -
392 -static const struct file_operations minstrel_stat_csv_fops = {
393 - .owner = THIS_MODULE,
394 - .open = minstrel_stats_csv_open,
395 - .read = minstrel_stats_read,
396 - .release = minstrel_stats_release,
397 - .llseek = default_llseek,
398 -};
399 -
400 -void
401 -minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
402 -{
403 - struct minstrel_sta_info *mi = priv_sta;
404 -
405 - debugfs_create_file("rc_stats", S_IRUGO, dir, mi, &minstrel_stat_fops);
406 - debugfs_create_file("rc_stats_csv", S_IRUGO, dir, mi,
407 - &minstrel_stat_csv_fops);
408 -}
409 --- a/net/mac80211/rc80211_minstrel_ht.c
410 +++ b/net/mac80211/rc80211_minstrel_ht.c
411 @@ -137,12 +137,10 @@
412 } \
413 }
414
415 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
416 static bool minstrel_vht_only = true;
417 module_param(minstrel_vht_only, bool, 0644);
418 MODULE_PARM_DESC(minstrel_vht_only,
419 "Use only VHT rates when VHT is supported by sta.");
420 -#endif
421
422 /*
423 * To enable sufficiently targeted rate sampling, MCS rates are divided into
424 @@ -171,7 +169,6 @@ const struct mcs_group minstrel_mcs_grou
425
426 CCK_GROUP,
427
428 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
429 VHT_GROUP(1, 0, BW_20),
430 VHT_GROUP(2, 0, BW_20),
431 VHT_GROUP(3, 0, BW_20),
432 @@ -195,7 +192,6 @@ const struct mcs_group minstrel_mcs_grou
433 VHT_GROUP(1, 1, BW_80),
434 VHT_GROUP(2, 1, BW_80),
435 VHT_GROUP(3, 1, BW_80),
436 -#endif
437 };
438
439 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
440 @@ -1146,12 +1142,10 @@ minstrel_ht_update_caps(void *priv, stru
441
442 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
443
444 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
445 if (vht_cap->vht_supported)
446 use_vht = vht_cap->vht_mcs.tx_mcs_map != cpu_to_le16(~0);
447 else
448 -#endif
449 - use_vht = 0;
450 + use_vht = 0;
451
452 msp->is_ht = true;
453 memset(mi, 0, sizeof(*mi));
454 @@ -1226,10 +1220,9 @@ minstrel_ht_update_caps(void *priv, stru
455
456 /* HT rate */
457 if (gflags & IEEE80211_TX_RC_MCS) {
458 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
459 if (use_vht && minstrel_vht_only)
460 continue;
461 -#endif
462 +
463 mi->supported[i] = mcs->rx_mask[nss - 1];
464 if (mi->supported[i])
465 n_supported++;
466 @@ -1352,13 +1345,52 @@ minstrel_ht_free_sta(void *priv, struct
467 static void *
468 minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
469 {
470 - return mac80211_minstrel.alloc(hw, debugfsdir);
471 + struct minstrel_priv *mp;
472 +
473 + mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
474 + if (!mp)
475 + return NULL;
476 +
477 + /* contention window settings
478 + * Just an approximation. Using the per-queue values would complicate
479 + * the calculations and is probably unnecessary */
480 + mp->cw_min = 15;
481 + mp->cw_max = 1023;
482 +
483 + /* number of packets (in %) to use for sampling other rates
484 + * sample less often for non-mrr packets, because the overhead
485 + * is much higher than with mrr */
486 + mp->lookaround_rate = 5;
487 + mp->lookaround_rate_mrr = 10;
488 +
489 + /* maximum time that the hw is allowed to stay in one MRR segment */
490 + mp->segment_size = 6000;
491 +
492 + if (hw->max_rate_tries > 0)
493 + mp->max_retry = hw->max_rate_tries;
494 + else
495 + /* safe default, does not necessarily have to match hw properties */
496 + mp->max_retry = 7;
497 +
498 + if (hw->max_rates >= 4)
499 + mp->has_mrr = true;
500 +
501 + mp->hw = hw;
502 + mp->update_interval = 100;
503 +
504 +#ifdef CPTCFG_MAC80211_DEBUGFS
505 + mp->fixed_rate_idx = (u32) -1;
506 + debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
507 + &mp->fixed_rate_idx);
508 +#endif
509 +
510 + return mp;
511 }
512
513 static void
514 minstrel_ht_free(void *priv)
515 {
516 - mac80211_minstrel.free(priv);
517 + kfree(priv);
518 }
519
520 static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
521 @@ -1417,14 +1449,14 @@ static void __init init_sample_table(voi
522 }
523
524 int __init
525 -rc80211_minstrel_ht_init(void)
526 +rc80211_minstrel_init(void)
527 {
528 init_sample_table();
529 return ieee80211_rate_control_register(&mac80211_minstrel_ht);
530 }
531
532 void
533 -rc80211_minstrel_ht_exit(void)
534 +rc80211_minstrel_exit(void)
535 {
536 ieee80211_rate_control_unregister(&mac80211_minstrel_ht);
537 }
538 --- a/net/mac80211/rc80211_minstrel_ht.h
539 +++ b/net/mac80211/rc80211_minstrel_ht.h
540 @@ -15,11 +15,7 @@
541 */
542 #define MINSTREL_MAX_STREAMS 3
543 #define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */
544 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
545 #define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */
546 -#else
547 -#define MINSTREL_VHT_STREAM_GROUPS 0
548 -#endif
549
550 #define MINSTREL_HT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
551 MINSTREL_HT_STREAM_GROUPS)
552 @@ -34,11 +30,7 @@
553 #define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
554 #define MINSTREL_VHT_GROUP_0 (MINSTREL_CCK_GROUP + 1)
555
556 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
557 #define MCS_GROUP_RATES 10
558 -#else
559 -#define MCS_GROUP_RATES 8
560 -#endif
561
562 struct mcs_group {
563 u32 flags;
564 --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
565 +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
566 @@ -15,6 +15,22 @@
567 #include "rc80211_minstrel.h"
568 #include "rc80211_minstrel_ht.h"
569
570 +static ssize_t
571 +minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
572 +{
573 + struct minstrel_debugfs_info *ms;
574 +
575 + ms = file->private_data;
576 + return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
577 +}
578 +
579 +static int
580 +minstrel_stats_release(struct inode *inode, struct file *file)
581 +{
582 + kfree(file->private_data);
583 + return 0;
584 +}
585 +
586 static char *
587 minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
588 {