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
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.
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
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
19 This option enables the 'minstrel' TX rate control algorithm
21 -config MAC80211_RC_MINSTREL_HT
22 - bool "Minstrel 802.11n support" if EXPERT
23 - depends on MAC80211_RC_MINSTREL
26 - This option enables the 'minstrel_ht' TX rate control algorithm
28 -config MAC80211_RC_MINSTREL_VHT
29 - bool "Minstrel 802.11ac support" if EXPERT
30 - depends on MAC80211_RC_MINSTREL_HT
33 - This option enables VHT in the 'minstrel_ht' TX rate control algorithm
36 prompt "Default rate control algorithm"
37 depends on MAC80211_HAS_RC
38 @@ -60,8 +46,7 @@ endchoice
40 config MAC80211_RC_DEFAULT
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
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
54 CFLAGS_trace.o := -I$(src)
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
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
68 mac80211-$(CPTCFG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
69 -mac80211-$(CPTCFG_MAC80211_RC_MINSTREL_HT) += $(rc80211_minstrel_ht-y)
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)
80 - ret = rc80211_minstrel_ht_init();
84 ret = ieee80211_iface_init();
90 - rc80211_minstrel_ht_exit();
92 rc80211_minstrel_exit();
95 @@ -1283,7 +1277,6 @@ static int __init ieee80211_init(void)
97 static void __exit ieee80211_exit(void)
99 - rc80211_minstrel_ht_exit();
100 rc80211_minstrel_exit();
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
111 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_HT
112 -int rc80211_minstrel_ht_init(void);
113 -void rc80211_minstrel_ht_exit(void);
115 -static inline int rc80211_minstrel_ht_init(void)
119 -static inline void rc80211_minstrel_ht_exit(void)
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);
135 -minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
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;
144 - mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
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;
154 - mi->r = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp);
158 - mi->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
159 - if (!mi->sample_table)
162 - mi->last_stats_update = jiffies;
173 -minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
175 - struct minstrel_sta_info *mi = priv_sta;
177 - kfree(mi->sample_table);
183 -minstrel_init_cck_rates(struct minstrel_priv *mp)
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);
190 - sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
194 - for (i = 0, j = 0; i < sband->n_bitrates; i++) {
195 - struct ieee80211_rate *rate = &sband->bitrates[i];
197 - if (rate->flags & IEEE80211_RATE_ERP_G)
200 - if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
203 - for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
204 - if (rate->bitrate != bitrates[j])
207 - mp->cck_rates[j] = i;
214 -minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
216 - struct minstrel_priv *mp;
218 - mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
222 - /* contention window settings
223 - * Just an approximation. Using the per-queue values would complicate
224 - * the calculations and is probably unnecessary */
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;
234 - /* maximum time that the hw is allowed to stay in one MRR segment */
235 - mp->segment_size = 6000;
237 - if (hw->max_rate_tries > 0)
238 - mp->max_retry = hw->max_rate_tries;
240 - /* safe default, does not necessarily have to match hw properties */
243 - if (hw->max_rates >= 4)
244 - mp->has_mrr = true;
247 - mp->update_interval = 100;
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);
255 - minstrel_init_cck_rates(mp);
261 -minstrel_free(void *priv)
266 static u32 minstrel_get_expected_throughput(void *priv_sta)
268 struct minstrel_sta_info *mi = priv_sta;
269 @@ -722,29 +590,8 @@ static u32 minstrel_get_expected_through
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,
284 .get_expected_throughput = minstrel_get_expected_throughput,
288 -rc80211_minstrel_init(void)
290 - return ieee80211_rate_control_register(&mac80211_minstrel);
294 -rc80211_minstrel_exit(void)
296 - ieee80211_rate_control_unregister(&mac80211_minstrel);
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_
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);
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
316 #include <net/mac80211.h>
317 #include "rc80211_minstrel.h"
320 -minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
322 - struct minstrel_debugfs_info *ms;
324 - ms = file->private_data;
325 - return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
329 -minstrel_stats_release(struct inode *inode, struct file *file)
331 - kfree(file->private_data);
336 minstrel_stats_open(struct inode *inode, struct file *file)
338 @@ -135,14 +119,6 @@ minstrel_stats_open(struct inode *inode,
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,
351 minstrel_stats_csv_open(struct inode *inode, struct file *file)
353 @@ -200,21 +176,3 @@ minstrel_stats_csv_open(struct inode *in
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,
367 -minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
369 - struct minstrel_sta_info *mi = priv_sta;
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);
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 @@
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.");
391 * To enable sufficiently targeted rate sampling, MCS rates are divided into
392 @@ -171,7 +169,6 @@ const struct mcs_group minstrel_mcs_grou
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),
407 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
408 @@ -1146,12 +1142,10 @@ minstrel_ht_update_caps(void *priv, stru
410 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
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);
421 memset(mi, 0, sizeof(*mi));
422 @@ -1226,10 +1220,9 @@ minstrel_ht_update_caps(void *priv, stru
425 if (gflags & IEEE80211_TX_RC_MCS) {
426 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
427 if (use_vht && minstrel_vht_only)
431 mi->supported[i] = mcs->rx_mask[nss - 1];
432 if (mi->supported[i])
434 @@ -1349,16 +1342,88 @@ minstrel_ht_free_sta(void *priv, struct
439 +minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
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);
446 + sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
450 + for (i = 0, j = 0; i < sband->n_bitrates; i++) {
451 + struct ieee80211_rate *rate = &sband->bitrates[i];
453 + if (rate->flags & IEEE80211_RATE_ERP_G)
456 + if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
459 + for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
460 + if (rate->bitrate != bitrates[j])
463 + mp->cck_rates[j] = i;
470 minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
472 - return mac80211_minstrel.alloc(hw, debugfsdir);
473 + struct minstrel_priv *mp;
475 + mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
479 + /* contention window settings
480 + * Just an approximation. Using the per-queue values would complicate
481 + * the calculations and is probably unnecessary */
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;
491 + /* maximum time that the hw is allowed to stay in one MRR segment */
492 + mp->segment_size = 6000;
494 + if (hw->max_rate_tries > 0)
495 + mp->max_retry = hw->max_rate_tries;
497 + /* safe default, does not necessarily have to match hw properties */
500 + if (hw->max_rates >= 4)
501 + mp->has_mrr = true;
504 + mp->update_interval = 100;
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);
512 + minstrel_ht_init_cck_rates(mp);
518 minstrel_ht_free(void *priv)
520 - mac80211_minstrel.free(priv);
524 static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
525 @@ -1417,14 +1482,14 @@ static void __init init_sample_table(voi
529 -rc80211_minstrel_ht_init(void)
530 +rc80211_minstrel_init(void)
533 return ieee80211_rate_control_register(&mac80211_minstrel_ht);
537 -rc80211_minstrel_ht_exit(void)
538 +rc80211_minstrel_exit(void)
540 ieee80211_rate_control_unregister(&mac80211_minstrel_ht);
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
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) */
553 -#define MINSTREL_VHT_STREAM_GROUPS 0
556 #define MINSTREL_HT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
557 MINSTREL_HT_STREAM_GROUPS)
559 #define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
560 #define MINSTREL_VHT_GROUP_0 (MINSTREL_CCK_GROUP + 1)
562 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
563 #define MCS_GROUP_RATES 10
565 -#define MCS_GROUP_RATES 8
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
575 #include "rc80211_minstrel.h"
576 #include "rc80211_minstrel_ht.h"
579 +minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
581 + struct minstrel_debugfs_info *ms;
583 + ms = file->private_data;
584 + return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
588 +minstrel_stats_release(struct inode *inode, struct file *file)
590 + kfree(file->private_data);
595 minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)