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