0a3c8ec53b21a3bab86409a0e62c9138a05e9def
[openwrt/staging/ansuel.git] /
1 From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
2 Date: Wed, 4 Sep 2024 19:12:56 +0800
3 Subject: [PATCH] wifi: mac80211: introduce EHT rate support in AQL airtime
4
5 Add definitions related to EHT mode and airtime calculation
6 according to the 802.11BE_D4.0.
7
8 Co-developed-by: Bo Jiao <Bo.Jiao@mediatek.com>
9 Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
10 Signed-off-by: Deren Wu <deren.wu@mediatek.com>
11 Signed-off-by: Quan Zhou <quan.zhou@mediatek.com>
12 Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
13 Link: https://patch.msgid.link/20240904111256.11734-1-mingyen.hsieh@mediatek.com
14 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
15 ---
16
17 --- a/net/mac80211/airtime.c
18 +++ b/net/mac80211/airtime.c
19 @@ -55,10 +55,21 @@
20 #define HE_DURATION_S(shift, streams, gi, bps) \
21 (HE_DURATION(streams, gi, bps) >> shift)
22
23 +/* gi in HE/EHT is identical. It matches enum nl80211_eht_gi as well */
24 +#define EHT_GI_08 HE_GI_08
25 +#define EHT_GI_16 HE_GI_16
26 +#define EHT_GI_32 HE_GI_32
27 +
28 +#define EHT_DURATION(streams, gi, bps) \
29 + HE_DURATION(streams, gi, bps)
30 +#define EHT_DURATION_S(shift, streams, gi, bps) \
31 + HE_DURATION_S(shift, streams, gi, bps)
32 +
33 #define BW_20 0
34 #define BW_40 1
35 #define BW_80 2
36 #define BW_160 3
37 +#define BW_320 4
38
39 /*
40 * Define group sort order: HT40 -> SGI -> #streams
41 @@ -68,17 +79,26 @@
42 #define IEEE80211_VHT_STREAM_GROUPS 8 /* BW(=4) * SGI(=2) */
43
44 #define IEEE80211_HE_MAX_STREAMS 8
45 +#define IEEE80211_HE_STREAM_GROUPS 12 /* BW(=4) * GI(=3) */
46 +
47 +#define IEEE80211_EHT_MAX_STREAMS 8
48 +#define IEEE80211_EHT_STREAM_GROUPS 15 /* BW(=5) * GI(=3) */
49
50 #define IEEE80211_HT_GROUPS_NB (IEEE80211_MAX_STREAMS * \
51 IEEE80211_HT_STREAM_GROUPS)
52 #define IEEE80211_VHT_GROUPS_NB (IEEE80211_MAX_STREAMS * \
53 IEEE80211_VHT_STREAM_GROUPS)
54 +#define IEEE80211_HE_GROUPS_NB (IEEE80211_HE_MAX_STREAMS * \
55 + IEEE80211_HE_STREAM_GROUPS)
56 +#define IEEE80211_EHT_GROUPS_NB (IEEE80211_EHT_MAX_STREAMS * \
57 + IEEE80211_EHT_STREAM_GROUPS)
58
59 #define IEEE80211_HT_GROUP_0 0
60 #define IEEE80211_VHT_GROUP_0 (IEEE80211_HT_GROUP_0 + IEEE80211_HT_GROUPS_NB)
61 #define IEEE80211_HE_GROUP_0 (IEEE80211_VHT_GROUP_0 + IEEE80211_VHT_GROUPS_NB)
62 +#define IEEE80211_EHT_GROUP_0 (IEEE80211_HE_GROUP_0 + IEEE80211_HE_GROUPS_NB)
63
64 -#define MCS_GROUP_RATES 12
65 +#define MCS_GROUP_RATES 14
66
67 #define HT_GROUP_IDX(_streams, _sgi, _ht40) \
68 IEEE80211_HT_GROUP_0 + \
69 @@ -203,6 +223,69 @@
70 #define HE_GROUP(_streams, _gi, _bw) \
71 __HE_GROUP(_streams, _gi, _bw, \
72 HE_GROUP_SHIFT(_streams, _gi, _bw))
73 +
74 +#define EHT_BW2VBPS(_bw, r5, r4, r3, r2, r1) \
75 + ((_bw) == BW_320 ? r5 : BW2VBPS(_bw, r4, r3, r2, r1))
76 +
77 +#define EHT_GROUP_IDX(_streams, _gi, _bw) \
78 + (IEEE80211_EHT_GROUP_0 + \
79 + IEEE80211_EHT_MAX_STREAMS * 3 * (_bw) + \
80 + IEEE80211_EHT_MAX_STREAMS * (_gi) + \
81 + (_streams) - 1)
82 +
83 +#define __EHT_GROUP(_streams, _gi, _bw, _s) \
84 + [EHT_GROUP_IDX(_streams, _gi, _bw)] = { \
85 + .shift = _s, \
86 + .duration = { \
87 + EHT_DURATION_S(_s, _streams, _gi, \
88 + EHT_BW2VBPS(_bw, 1960, 980, 490, 234, 117)), \
89 + EHT_DURATION_S(_s, _streams, _gi, \
90 + EHT_BW2VBPS(_bw, 3920, 1960, 980, 468, 234)), \
91 + EHT_DURATION_S(_s, _streams, _gi, \
92 + EHT_BW2VBPS(_bw, 5880, 2937, 1470, 702, 351)), \
93 + EHT_DURATION_S(_s, _streams, _gi, \
94 + EHT_BW2VBPS(_bw, 7840, 3920, 1960, 936, 468)), \
95 + EHT_DURATION_S(_s, _streams, _gi, \
96 + EHT_BW2VBPS(_bw, 11760, 5880, 2940, 1404, 702)), \
97 + EHT_DURATION_S(_s, _streams, _gi, \
98 + EHT_BW2VBPS(_bw, 15680, 7840, 3920, 1872, 936)), \
99 + EHT_DURATION_S(_s, _streams, _gi, \
100 + EHT_BW2VBPS(_bw, 17640, 8820, 4410, 2106, 1053)), \
101 + EHT_DURATION_S(_s, _streams, _gi, \
102 + EHT_BW2VBPS(_bw, 19600, 9800, 4900, 2340, 1170)), \
103 + EHT_DURATION_S(_s, _streams, _gi, \
104 + EHT_BW2VBPS(_bw, 23520, 11760, 5880, 2808, 1404)), \
105 + EHT_DURATION_S(_s, _streams, _gi, \
106 + EHT_BW2VBPS(_bw, 26133, 13066, 6533, 3120, 1560)), \
107 + EHT_DURATION_S(_s, _streams, _gi, \
108 + EHT_BW2VBPS(_bw, 29400, 14700, 7350, 3510, 1755)), \
109 + EHT_DURATION_S(_s, _streams, _gi, \
110 + EHT_BW2VBPS(_bw, 32666, 16333, 8166, 3900, 1950)), \
111 + EHT_DURATION_S(_s, _streams, _gi, \
112 + EHT_BW2VBPS(_bw, 35280, 17640, 8820, 4212, 2106)), \
113 + EHT_DURATION_S(_s, _streams, _gi, \
114 + EHT_BW2VBPS(_bw, 39200, 19600, 9800, 4680, 2340)) \
115 + } \
116 +}
117 +
118 +#define EHT_GROUP_SHIFT(_streams, _gi, _bw) \
119 + GROUP_SHIFT(EHT_DURATION(_streams, _gi, \
120 + EHT_BW2VBPS(_bw, 1960, 980, 490, 234, 117)))
121 +
122 +#define EHT_GROUP(_streams, _gi, _bw) \
123 + __EHT_GROUP(_streams, _gi, _bw, \
124 + EHT_GROUP_SHIFT(_streams, _gi, _bw))
125 +
126 +#define EHT_GROUP_RANGE(_gi, _bw) \
127 + EHT_GROUP(1, _gi, _bw), \
128 + EHT_GROUP(2, _gi, _bw), \
129 + EHT_GROUP(3, _gi, _bw), \
130 + EHT_GROUP(4, _gi, _bw), \
131 + EHT_GROUP(5, _gi, _bw), \
132 + EHT_GROUP(6, _gi, _bw), \
133 + EHT_GROUP(7, _gi, _bw), \
134 + EHT_GROUP(8, _gi, _bw)
135 +
136 struct mcs_group {
137 u8 shift;
138 u16 duration[MCS_GROUP_RATES];
139 @@ -376,6 +459,26 @@ static const struct mcs_group airtime_mc
140 HE_GROUP(6, HE_GI_32, BW_160),
141 HE_GROUP(7, HE_GI_32, BW_160),
142 HE_GROUP(8, HE_GI_32, BW_160),
143 +
144 + EHT_GROUP_RANGE(EHT_GI_08, BW_20),
145 + EHT_GROUP_RANGE(EHT_GI_16, BW_20),
146 + EHT_GROUP_RANGE(EHT_GI_32, BW_20),
147 +
148 + EHT_GROUP_RANGE(EHT_GI_08, BW_40),
149 + EHT_GROUP_RANGE(EHT_GI_16, BW_40),
150 + EHT_GROUP_RANGE(EHT_GI_32, BW_40),
151 +
152 + EHT_GROUP_RANGE(EHT_GI_08, BW_80),
153 + EHT_GROUP_RANGE(EHT_GI_16, BW_80),
154 + EHT_GROUP_RANGE(EHT_GI_32, BW_80),
155 +
156 + EHT_GROUP_RANGE(EHT_GI_08, BW_160),
157 + EHT_GROUP_RANGE(EHT_GI_16, BW_160),
158 + EHT_GROUP_RANGE(EHT_GI_32, BW_160),
159 +
160 + EHT_GROUP_RANGE(EHT_GI_08, BW_320),
161 + EHT_GROUP_RANGE(EHT_GI_16, BW_320),
162 + EHT_GROUP_RANGE(EHT_GI_32, BW_320),
163 };
164
165 static u32
166 @@ -422,6 +525,9 @@ static u32 ieee80211_get_rate_duration(s
167 case RATE_INFO_BW_160:
168 bw = BW_160;
169 break;
170 + case RATE_INFO_BW_320:
171 + bw = BW_320;
172 + break;
173 default:
174 WARN_ON_ONCE(1);
175 return 0;
176 @@ -443,14 +549,27 @@ static u32 ieee80211_get_rate_duration(s
177 idx = status->rate_idx;
178 group = HE_GROUP_IDX(streams, status->he_gi, bw);
179 break;
180 + case RX_ENC_EHT:
181 + streams = status->nss;
182 + idx = status->rate_idx;
183 + group = EHT_GROUP_IDX(streams, status->eht.gi, bw);
184 + break;
185 default:
186 WARN_ON_ONCE(1);
187 return 0;
188 }
189
190 - if (WARN_ON_ONCE((status->encoding != RX_ENC_HE && streams > 4) ||
191 - (status->encoding == RX_ENC_HE && streams > 8)))
192 - return 0;
193 + switch (status->encoding) {
194 + case RX_ENC_EHT:
195 + case RX_ENC_HE:
196 + if (WARN_ON_ONCE(streams > 8))
197 + return 0;
198 + break;
199 + default:
200 + if (WARN_ON_ONCE(streams > 4))
201 + return 0;
202 + break;
203 + }
204
205 if (idx >= MCS_GROUP_RATES)
206 return 0;
207 @@ -517,7 +636,9 @@ static bool ieee80211_fill_rate_info(str
208 stat->nss = ri->nss;
209 stat->rate_idx = ri->mcs;
210
211 - if (ri->flags & RATE_INFO_FLAGS_HE_MCS)
212 + if (ri->flags & RATE_INFO_FLAGS_EHT_MCS)
213 + stat->encoding = RX_ENC_EHT;
214 + else if (ri->flags & RATE_INFO_FLAGS_HE_MCS)
215 stat->encoding = RX_ENC_HE;
216 else if (ri->flags & RATE_INFO_FLAGS_VHT_MCS)
217 stat->encoding = RX_ENC_VHT;
218 @@ -529,7 +650,14 @@ static bool ieee80211_fill_rate_info(str
219 if (ri->flags & RATE_INFO_FLAGS_SHORT_GI)
220 stat->enc_flags |= RX_ENC_FLAG_SHORT_GI;
221
222 - stat->he_gi = ri->he_gi;
223 + switch (stat->encoding) {
224 + case RX_ENC_EHT:
225 + stat->eht.gi = ri->eht_gi;
226 + break;
227 + default:
228 + stat->he_gi = ri->he_gi;
229 + break;
230 + }
231
232 if (stat->encoding != RX_ENC_LEGACY)
233 return true;