81d14966f73dab859875cdb81020ef5d7ac64784
[openwrt/staging/stintel.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Mon, 25 Mar 2019 09:02:52 +0100
3 Subject: [PATCH] mac80211: minstrel_ht: automatically calculate rate
4 duration shift
5
6 A per-group shift was added to reduce the size of the per-rate transmit
7 duration field to u16 without sacrificing a lot of precision
8 This patch changes the macros to automatically calculate the best value for
9 this shift based on the lowest rate within the group.
10 This simplifies adding more groups and slightly improves accuracy for some of
11 the existing groups.
12
13 Signed-off-by: Felix Fietkau <nbd@nbd.name>
14 ---
15
16 --- a/net/mac80211/rc80211_minstrel_ht.c
17 +++ b/net/mac80211/rc80211_minstrel_ht.c
18 @@ -51,8 +51,11 @@
19 MINSTREL_MAX_STREAMS * _sgi + \
20 _streams - 1
21
22 +#define GROUP_SHIFT(duration) \
23 + (16 - __builtin_clz(duration))
24 +
25 /* MCS rate information for an MCS group */
26 -#define MCS_GROUP(_streams, _sgi, _ht40, _s) \
27 +#define __MCS_GROUP(_streams, _sgi, _ht40, _s) \
28 [GROUP_IDX(_streams, _sgi, _ht40)] = { \
29 .streams = _streams, \
30 .shift = _s, \
31 @@ -72,6 +75,13 @@
32 } \
33 }
34
35 +#define MCS_GROUP_SHIFT(_streams, _sgi, _ht40) \
36 + GROUP_SHIFT(MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26))
37 +
38 +#define MCS_GROUP(_streams, _sgi, _ht40) \
39 + __MCS_GROUP(_streams, _sgi, _ht40, \
40 + MCS_GROUP_SHIFT(_streams, _sgi, _ht40))
41 +
42 #define VHT_GROUP_IDX(_streams, _sgi, _bw) \
43 (MINSTREL_VHT_GROUP_0 + \
44 MINSTREL_MAX_STREAMS * 2 * (_bw) + \
45 @@ -81,7 +91,7 @@
46 #define BW2VBPS(_bw, r3, r2, r1) \
47 (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
48
49 -#define VHT_GROUP(_streams, _sgi, _bw, _s) \
50 +#define __VHT_GROUP(_streams, _sgi, _bw, _s) \
51 [VHT_GROUP_IDX(_streams, _sgi, _bw)] = { \
52 .streams = _streams, \
53 .shift = _s, \
54 @@ -114,6 +124,14 @@
55 } \
56 }
57
58 +#define VHT_GROUP_SHIFT(_streams, _sgi, _bw) \
59 + GROUP_SHIFT(MCS_DURATION(_streams, _sgi, \
60 + BW2VBPS(_bw, 117, 54, 26)))
61 +
62 +#define VHT_GROUP(_streams, _sgi, _bw) \
63 + __VHT_GROUP(_streams, _sgi, _bw, \
64 + VHT_GROUP_SHIFT(_streams, _sgi, _bw))
65 +
66 #define CCK_DURATION(_bitrate, _short, _len) \
67 (1000 * (10 /* SIFS */ + \
68 (_short ? 72 + 24 : 144 + 48) + \
69 @@ -129,7 +147,7 @@
70 CCK_ACK_DURATION(55, _short) >> _s, \
71 CCK_ACK_DURATION(110, _short) >> _s
72
73 -#define CCK_GROUP(_s) \
74 +#define __CCK_GROUP(_s) \
75 [MINSTREL_CCK_GROUP] = { \
76 .streams = 1, \
77 .flags = 0, \
78 @@ -140,6 +158,12 @@
79 } \
80 }
81
82 +#define CCK_GROUP_SHIFT \
83 + GROUP_SHIFT(CCK_ACK_DURATION(10, false))
84 +
85 +#define CCK_GROUP __CCK_GROUP(CCK_GROUP_SHIFT)
86 +
87 +
88 static bool minstrel_vht_only = true;
89 module_param(minstrel_vht_only, bool, 0644);
90 MODULE_PARM_DESC(minstrel_vht_only,
91 @@ -154,57 +178,57 @@ MODULE_PARM_DESC(minstrel_vht_only,
92 * BW -> SGI -> #streams
93 */
94 const struct mcs_group minstrel_mcs_groups[] = {
95 - MCS_GROUP(1, 0, BW_20, 5),
96 - MCS_GROUP(2, 0, BW_20, 4),
97 - MCS_GROUP(3, 0, BW_20, 4),
98 - MCS_GROUP(4, 0, BW_20, 4),
99 + MCS_GROUP(1, 0, BW_20),
100 + MCS_GROUP(2, 0, BW_20),
101 + MCS_GROUP(3, 0, BW_20),
102 + MCS_GROUP(4, 0, BW_20),
103
104 - MCS_GROUP(1, 1, BW_20, 5),
105 - MCS_GROUP(2, 1, BW_20, 4),
106 - MCS_GROUP(3, 1, BW_20, 4),
107 - MCS_GROUP(4, 1, BW_20, 4),
108 + MCS_GROUP(1, 1, BW_20),
109 + MCS_GROUP(2, 1, BW_20),
110 + MCS_GROUP(3, 1, BW_20),
111 + MCS_GROUP(4, 1, BW_20),
112
113 - MCS_GROUP(1, 0, BW_40, 4),
114 - MCS_GROUP(2, 0, BW_40, 4),
115 - MCS_GROUP(3, 0, BW_40, 4),
116 - MCS_GROUP(4, 0, BW_40, 4),
117 + MCS_GROUP(1, 0, BW_40),
118 + MCS_GROUP(2, 0, BW_40),
119 + MCS_GROUP(3, 0, BW_40),
120 + MCS_GROUP(4, 0, BW_40),
121
122 - MCS_GROUP(1, 1, BW_40, 4),
123 - MCS_GROUP(2, 1, BW_40, 4),
124 - MCS_GROUP(3, 1, BW_40, 4),
125 - MCS_GROUP(4, 1, BW_40, 4),
126 + MCS_GROUP(1, 1, BW_40),
127 + MCS_GROUP(2, 1, BW_40),
128 + MCS_GROUP(3, 1, BW_40),
129 + MCS_GROUP(4, 1, BW_40),
130
131 - CCK_GROUP(8),
132 + CCK_GROUP,
133
134 - VHT_GROUP(1, 0, BW_20, 5),
135 - VHT_GROUP(2, 0, BW_20, 4),
136 - VHT_GROUP(3, 0, BW_20, 4),
137 - VHT_GROUP(4, 0, BW_20, 4),
138 + VHT_GROUP(1, 0, BW_20),
139 + VHT_GROUP(2, 0, BW_20),
140 + VHT_GROUP(3, 0, BW_20),
141 + VHT_GROUP(4, 0, BW_20),
142
143 - VHT_GROUP(1, 1, BW_20, 5),
144 - VHT_GROUP(2, 1, BW_20, 4),
145 - VHT_GROUP(3, 1, BW_20, 4),
146 - VHT_GROUP(4, 1, BW_20, 4),
147 + VHT_GROUP(1, 1, BW_20),
148 + VHT_GROUP(2, 1, BW_20),
149 + VHT_GROUP(3, 1, BW_20),
150 + VHT_GROUP(4, 1, BW_20),
151
152 - VHT_GROUP(1, 0, BW_40, 4),
153 - VHT_GROUP(2, 0, BW_40, 4),
154 - VHT_GROUP(3, 0, BW_40, 4),
155 - VHT_GROUP(4, 0, BW_40, 3),
156 + VHT_GROUP(1, 0, BW_40),
157 + VHT_GROUP(2, 0, BW_40),
158 + VHT_GROUP(3, 0, BW_40),
159 + VHT_GROUP(4, 0, BW_40),
160
161 - VHT_GROUP(1, 1, BW_40, 4),
162 - VHT_GROUP(2, 1, BW_40, 4),
163 - VHT_GROUP(3, 1, BW_40, 4),
164 - VHT_GROUP(4, 1, BW_40, 3),
165 + VHT_GROUP(1, 1, BW_40),
166 + VHT_GROUP(2, 1, BW_40),
167 + VHT_GROUP(3, 1, BW_40),
168 + VHT_GROUP(4, 1, BW_40),
169
170 - VHT_GROUP(1, 0, BW_80, 4),
171 - VHT_GROUP(2, 0, BW_80, 4),
172 - VHT_GROUP(3, 0, BW_80, 4),
173 - VHT_GROUP(4, 0, BW_80, 2),
174 + VHT_GROUP(1, 0, BW_80),
175 + VHT_GROUP(2, 0, BW_80),
176 + VHT_GROUP(3, 0, BW_80),
177 + VHT_GROUP(4, 0, BW_80),
178
179 - VHT_GROUP(1, 1, BW_80, 4),
180 - VHT_GROUP(2, 1, BW_80, 4),
181 - VHT_GROUP(3, 1, BW_80, 4),
182 - VHT_GROUP(4, 1, BW_80, 2),
183 + VHT_GROUP(1, 1, BW_80),
184 + VHT_GROUP(2, 1, BW_80),
185 + VHT_GROUP(3, 1, BW_80),
186 + VHT_GROUP(4, 1, BW_80),
187 };
188
189 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;