371-mac80211-minstrel-merge-with-minstrel_ht-always-enab.patch 14 KB

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