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 --- a/net/mac80211/Kconfig
14 +++ b/net/mac80211/Kconfig
15 @@ -25,20 +25,6 @@ config MAC80211_RC_MINSTREL
17 This option enables the 'minstrel' TX rate control algorithm
19 -config MAC80211_RC_MINSTREL_HT
20 - bool "Minstrel 802.11n support" if EXPERT
21 - depends on MAC80211_RC_MINSTREL
24 - This option enables the 'minstrel_ht' TX rate control algorithm
26 -config MAC80211_RC_MINSTREL_VHT
27 - bool "Minstrel 802.11ac support" if EXPERT
28 - depends on MAC80211_RC_MINSTREL_HT
31 - This option enables VHT in the 'minstrel_ht' TX rate control algorithm
34 prompt "Default rate control algorithm"
35 depends on MAC80211_HAS_RC
36 @@ -60,8 +46,7 @@ endchoice
38 config MAC80211_RC_DEFAULT
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
46 --- a/net/mac80211/Makefile
47 +++ b/net/mac80211/Makefile
48 @@ -52,13 +52,14 @@ mac80211-$(CONFIG_PM) += pm.o
50 CFLAGS_trace.o := -I$(src)
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
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
64 mac80211-$(CPTCFG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
65 -mac80211-$(CPTCFG_MAC80211_RC_MINSTREL_HT) += $(rc80211_minstrel_ht-y)
68 --- a/net/mac80211/main.c
69 +++ b/net/mac80211/main.c
70 @@ -1319,18 +1319,12 @@ static int __init ieee80211_init(void)
74 - ret = rc80211_minstrel_ht_init();
78 ret = ieee80211_iface_init();
84 - rc80211_minstrel_ht_exit();
86 rc80211_minstrel_exit();
89 @@ -1338,7 +1332,6 @@ static int __init ieee80211_init(void)
91 static void __exit ieee80211_exit(void)
93 - rc80211_minstrel_ht_exit();
94 rc80211_minstrel_exit();
97 --- a/net/mac80211/rate.h
98 +++ b/net/mac80211/rate.h
99 @@ -95,18 +95,5 @@ static inline void rc80211_minstrel_exit
103 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_HT
104 -int rc80211_minstrel_ht_init(void);
105 -void rc80211_minstrel_ht_exit(void);
107 -static inline int rc80211_minstrel_ht_init(void)
111 -static inline void rc80211_minstrel_ht_exit(void)
117 #endif /* IEEE80211_RATE_H */
118 --- a/net/mac80211/rc80211_minstrel.c
119 +++ b/net/mac80211/rc80211_minstrel.c
120 @@ -555,138 +555,6 @@ minstrel_rate_init(void *priv, struct ie
121 minstrel_update_rates(mp, mi);
125 -minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
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;
134 - mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
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;
144 - mi->r = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp);
148 - mi->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
149 - if (!mi->sample_table)
152 - mi->last_stats_update = jiffies;
163 -minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
165 - struct minstrel_sta_info *mi = priv_sta;
167 - kfree(mi->sample_table);
173 -minstrel_init_cck_rates(struct minstrel_priv *mp)
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);
180 - sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
184 - for (i = 0, j = 0; i < sband->n_bitrates; i++) {
185 - struct ieee80211_rate *rate = &sband->bitrates[i];
187 - if (rate->flags & IEEE80211_RATE_ERP_G)
190 - if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
193 - for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
194 - if (rate->bitrate != bitrates[j])
197 - mp->cck_rates[j] = i;
204 -minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
206 - struct minstrel_priv *mp;
208 - mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
212 - /* contention window settings
213 - * Just an approximation. Using the per-queue values would complicate
214 - * the calculations and is probably unnecessary */
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;
224 - /* maximum time that the hw is allowed to stay in one MRR segment */
225 - mp->segment_size = 6000;
227 - if (hw->max_rate_tries > 0)
228 - mp->max_retry = hw->max_rate_tries;
230 - /* safe default, does not necessarily have to match hw properties */
233 - if (hw->max_rates >= 4)
234 - mp->has_mrr = true;
237 - mp->update_interval = 100;
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);
245 - minstrel_init_cck_rates(mp);
251 -minstrel_free(void *priv)
256 static u32 minstrel_get_expected_throughput(void *priv_sta)
258 struct minstrel_sta_info *mi = priv_sta;
259 @@ -705,28 +573,8 @@ static u32 minstrel_get_expected_through
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,
274 .get_expected_throughput = minstrel_get_expected_throughput,
278 -rc80211_minstrel_init(void)
280 - return ieee80211_rate_control_register(&mac80211_minstrel);
284 -rc80211_minstrel_exit(void)
286 - ieee80211_rate_control_unregister(&mac80211_minstrel);
288 --- a/net/mac80211/rc80211_minstrel.h
289 +++ b/net/mac80211/rc80211_minstrel.h
290 @@ -157,7 +157,5 @@ int minstrel_get_tp_avg(struct minstrel_
292 int minstrel_stats_open(struct inode *inode, struct file *file);
293 int minstrel_stats_csv_open(struct inode *inode, struct file *file);
294 -ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
295 -int minstrel_stats_release(struct inode *inode, struct file *file);
298 --- a/net/mac80211/rc80211_minstrel_debugfs.c
299 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
301 #include <net/mac80211.h>
302 #include "rc80211_minstrel.h"
305 -minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
307 - struct minstrel_debugfs_info *ms;
309 - ms = file->private_data;
310 - return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
314 -minstrel_stats_release(struct inode *inode, struct file *file)
316 - kfree(file->private_data);
321 minstrel_stats_open(struct inode *inode, struct file *file)
323 @@ -135,14 +119,6 @@ minstrel_stats_open(struct inode *inode,
327 -static const struct file_operations minstrel_stat_fops = {
328 - .owner = THIS_MODULE,
329 - .open = minstrel_stats_open,
330 - .read = minstrel_stats_read,
331 - .release = minstrel_stats_release,
332 - .llseek = default_llseek,
336 minstrel_stats_csv_open(struct inode *inode, struct file *file)
338 @@ -200,21 +176,3 @@ minstrel_stats_csv_open(struct inode *in
343 -static const struct file_operations minstrel_stat_csv_fops = {
344 - .owner = THIS_MODULE,
345 - .open = minstrel_stats_csv_open,
346 - .read = minstrel_stats_read,
347 - .release = minstrel_stats_release,
348 - .llseek = default_llseek,
352 -minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
354 - struct minstrel_sta_info *mi = priv_sta;
356 - debugfs_create_file("rc_stats", S_IRUGO, dir, mi, &minstrel_stat_fops);
357 - debugfs_create_file("rc_stats_csv", S_IRUGO, dir, mi,
358 - &minstrel_stat_csv_fops);
360 --- a/net/mac80211/rc80211_minstrel_ht.c
361 +++ b/net/mac80211/rc80211_minstrel_ht.c
362 @@ -137,12 +137,10 @@
366 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
367 static bool minstrel_vht_only = true;
368 module_param(minstrel_vht_only, bool, 0644);
369 MODULE_PARM_DESC(minstrel_vht_only,
370 "Use only VHT rates when VHT is supported by sta.");
374 * To enable sufficiently targeted rate sampling, MCS rates are divided into
375 @@ -171,7 +169,6 @@ const struct mcs_group minstrel_mcs_grou
379 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
380 VHT_GROUP(1, 0, BW_20),
381 VHT_GROUP(2, 0, BW_20),
382 VHT_GROUP(3, 0, BW_20),
383 @@ -195,7 +192,6 @@ const struct mcs_group minstrel_mcs_grou
384 VHT_GROUP(1, 1, BW_80),
385 VHT_GROUP(2, 1, BW_80),
386 VHT_GROUP(3, 1, BW_80),
390 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
391 @@ -1151,12 +1147,10 @@ minstrel_ht_update_caps(void *priv, stru
393 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
395 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
396 if (vht_cap->vht_supported)
397 use_vht = vht_cap->vht_mcs.tx_mcs_map != cpu_to_le16(~0);
404 memset(mi, 0, sizeof(*mi));
405 @@ -1231,10 +1225,9 @@ minstrel_ht_update_caps(void *priv, stru
408 if (gflags & IEEE80211_TX_RC_MCS) {
409 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
410 if (use_vht && minstrel_vht_only)
414 mi->supported[i] = mcs->rx_mask[nss - 1];
415 if (mi->supported[i])
417 @@ -1353,16 +1346,88 @@ minstrel_ht_free_sta(void *priv, struct
422 +minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
424 + static const int bitrates[4] = { 10, 20, 55, 110 };
425 + struct ieee80211_supported_band *sband;
426 + u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
429 + sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
433 + for (i = 0, j = 0; i < sband->n_bitrates; i++) {
434 + struct ieee80211_rate *rate = &sband->bitrates[i];
436 + if (rate->flags & IEEE80211_RATE_ERP_G)
439 + if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
442 + for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
443 + if (rate->bitrate != bitrates[j])
446 + mp->cck_rates[j] = i;
453 minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
455 - return mac80211_minstrel.alloc(hw, debugfsdir);
456 + struct minstrel_priv *mp;
458 + mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
462 + /* contention window settings
463 + * Just an approximation. Using the per-queue values would complicate
464 + * the calculations and is probably unnecessary */
468 + /* number of packets (in %) to use for sampling other rates
469 + * sample less often for non-mrr packets, because the overhead
470 + * is much higher than with mrr */
471 + mp->lookaround_rate = 5;
472 + mp->lookaround_rate_mrr = 10;
474 + /* maximum time that the hw is allowed to stay in one MRR segment */
475 + mp->segment_size = 6000;
477 + if (hw->max_rate_tries > 0)
478 + mp->max_retry = hw->max_rate_tries;
480 + /* safe default, does not necessarily have to match hw properties */
483 + if (hw->max_rates >= 4)
484 + mp->has_mrr = true;
487 + mp->update_interval = 100;
489 +#ifdef CPTCFG_MAC80211_DEBUGFS
490 + mp->fixed_rate_idx = (u32) -1;
491 + debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
492 + &mp->fixed_rate_idx);
495 + minstrel_ht_init_cck_rates(mp);
501 minstrel_ht_free(void *priv)
503 - mac80211_minstrel.free(priv);
507 static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
508 @@ -1421,14 +1486,14 @@ static void __init init_sample_table(voi
512 -rc80211_minstrel_ht_init(void)
513 +rc80211_minstrel_init(void)
516 return ieee80211_rate_control_register(&mac80211_minstrel_ht);
520 -rc80211_minstrel_ht_exit(void)
521 +rc80211_minstrel_exit(void)
523 ieee80211_rate_control_unregister(&mac80211_minstrel_ht);
525 --- a/net/mac80211/rc80211_minstrel_ht.h
526 +++ b/net/mac80211/rc80211_minstrel_ht.h
529 #define MINSTREL_MAX_STREAMS 3
530 #define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */
531 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
532 #define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */
534 -#define MINSTREL_VHT_STREAM_GROUPS 0
537 #define MINSTREL_HT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
538 MINSTREL_HT_STREAM_GROUPS)
540 #define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
541 #define MINSTREL_VHT_GROUP_0 (MINSTREL_CCK_GROUP + 1)
543 -#ifdef CPTCFG_MAC80211_RC_MINSTREL_VHT
544 #define MCS_GROUP_RATES 10
546 -#define MCS_GROUP_RATES 8
551 --- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
552 +++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
554 #include "rc80211_minstrel.h"
555 #include "rc80211_minstrel_ht.h"
558 +minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
560 + struct minstrel_debugfs_info *ms;
562 + ms = file->private_data;
563 + return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
567 +minstrel_stats_release(struct inode *inode, struct file *file)
569 + kfree(file->private_data);
574 minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)