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