1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* KUnit tests for TPE element handling
*
* Copyright (C) 2024 Intel Corporation
*/
#include <kunit/test.h>
#include "../ieee80211_i.h"
MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
static struct ieee80211_channel chan6g_1 = {
.band = NL80211_BAND_6GHZ,
.center_freq = 5955,
};
static struct ieee80211_channel chan6g_33 = {
.band = NL80211_BAND_6GHZ,
.center_freq = 6115,
};
static struct ieee80211_channel chan6g_61 = {
.band = NL80211_BAND_6GHZ,
.center_freq = 6255,
};
static const struct subchan_test_case {
const char *desc;
struct cfg80211_chan_def c;
u8 n;
int expect;
} subchan_offset_cases[] = {
{
.desc = "identical 20 MHz",
.c.width = NL80211_CHAN_WIDTH_20,
.c.chan = &chan6g_1,
.c.center_freq1 = 5955,
.n = 1,
.expect = 0,
},
{
.desc = "identical 40 MHz",
.c.width = NL80211_CHAN_WIDTH_40,
.c.chan = &chan6g_1,
.c.center_freq1 = 5965,
.n = 2,
.expect = 0,
},
{
.desc = "identical 80+80 MHz",
/* not really is valid? doesn't matter for the test */
.c.width = NL80211_CHAN_WIDTH_80P80,
.c.chan = &chan6g_1,
.c.center_freq1 = 5985,
.c.center_freq2 = 6225,
.n = 16,
.expect = 0,
},
{
.desc = "identical 320 MHz",
.c.width = NL80211_CHAN_WIDTH_320,
.c.chan = &chan6g_1,
.c.center_freq1 = 6105,
.n = 16,
.expect = 0,
},
{
.desc = "lower 160 MHz of 320 MHz",
.c.width = NL80211_CHAN_WIDTH_320,
.c.chan = &chan6g_1,
.c.center_freq1 = 6105,
.n = 8,
.expect = 0,
},
{
.desc = "upper 160 MHz of 320 MHz",
.c.width = NL80211_CHAN_WIDTH_320,
.c.chan = &chan6g_61,
.c.center_freq1 = 6105,
.n = 8,
.expect = 8,
},
{
.desc = "upper 160 MHz of 320 MHz, go to 40",
.c.width = NL80211_CHAN_WIDTH_320,
.c.chan = &chan6g_61,
.c.center_freq1 = 6105,
.n = 2,
.expect = 8 + 4 + 2,
},
{
.desc = "secondary 80 above primary in 80+80 MHz",
/* not really is valid? doesn't matter for the test */
.c.width = NL80211_CHAN_WIDTH_80P80,
.c.chan = &chan6g_1,
.c.center_freq1 = 5985,
.c.center_freq2 = 6225,
.n = 4,
.expect = 0,
},
{
.desc = "secondary 80 below primary in 80+80 MHz",
/* not really is valid? doesn't matter for the test */
.c.width = NL80211_CHAN_WIDTH_80P80,
.c.chan = &chan6g_61,
.c.center_freq1 = 6225,
.c.center_freq2 = 5985,
.n = 4,
.expect = 4,
},
{
.desc = "secondary 80 below primary in 80+80 MHz, go to 20",
/* not really is valid? doesn't matter for the test */
.c.width = NL80211_CHAN_WIDTH_80P80,
.c.chan = &chan6g_61,
.c.center_freq1 = 6225,
.c.center_freq2 = 5985,
.n = 1,
.expect = 7,
},
};
KUNIT_ARRAY_PARAM_DESC(subchan_offset, subchan_offset_cases, desc);
static void subchan_offset(struct kunit *test)
{
const struct subchan_test_case *params = test->param_value;
int offset;
KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(¶ms->c), true);
offset = ieee80211_calc_chandef_subchan_offset(¶ms->c, params->n);
KUNIT_EXPECT_EQ(test, params->expect, offset);
}
static const struct psd_reorder_test_case {
const char *desc;
struct cfg80211_chan_def ap, used;
struct ieee80211_parsed_tpe_psd psd, out;
} psd_reorder_cases[] = {
{
.desc = "no changes, 320 MHz",
.ap.width = NL80211_CHAN_WIDTH_320,
.ap.chan = &chan6g_1,
.ap.center_freq1 = 6105,
.used.width = NL80211_CHAN_WIDTH_320,
.used.chan = &chan6g_1,
.used.center_freq1 = 6105,
.psd.valid = true,
.psd.count = 16,
.psd.n = 8,
.psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
.out.valid = true,
.out.count = 16,
.out.n = 8,
.out.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
},
{
.desc = "no changes, 320 MHz, 160 MHz used, n=0",
.ap.width = NL80211_CHAN_WIDTH_320,
.ap.chan = &chan6g_1,
.ap.center_freq1 = 6105,
.used.width = NL80211_CHAN_WIDTH_160,
.used.chan = &chan6g_1,
.used.center_freq1 = 6025,
.psd.valid = true,
.psd.count = 16,
.psd.n = 0,
.psd.power = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
.out.valid = true,
.out.count = 8,
.out.n = 0,
.out.power = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
},
{
.desc = "320 MHz, HE is 80, used 160, all lower",
.ap.width = NL80211_CHAN_WIDTH_320,
.ap.chan = &chan6g_1,
.ap.center_freq1 = 6105,
.used.width = NL80211_CHAN_WIDTH_160,
.used.chan = &chan6g_1,
.used.center_freq1 = 6025,
.psd.valid = true,
.psd.count = 16,
.psd.n = 4,
.psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
.out.valid = true,
.out.count = 8,
.out.n = 4,
.out.power = { 0, 1, 2, 3, 4, 5, 6, 7, 127, 127, 127, 127, 127, 127, 127, 127},
},
{
.desc = "320 MHz, HE is 80, used 160, all upper",
/*
* EHT: | | | | | | | | | | | | | | | | |
* HE: | | | | |
* used: | | | | | | | | |
*/
.ap.width = NL80211_CHAN_WIDTH_320,
.ap.chan = &chan6g_61,
.ap.center_freq1 = 6105,
.used.width = NL80211_CHAN_WIDTH_160,
.used.chan = &chan6g_61,
.used.center_freq1 = 6185,
.psd.valid = true,
.psd.count = 16,
.psd.n = 4,
.psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
.out.valid = true,
.out.count = 8,
.out.n = 4,
.out.power = { 12, 13, 14, 15, 0, 1, 2, 3, 127, 127, 127, 127, 127, 127, 127, 127},
},
{
.desc = "320 MHz, HE is 80, used 160, split",
/*
* EHT: | | | | | | | | | | | | | | | | |
* HE: | | | | |
* used: | | | | | | | | |
*/
.ap.width = NL80211_CHAN_WIDTH_320,
.ap.chan = &chan6g_33,
.ap.center_freq1 = 6105,
.used.width = NL80211_CHAN_WIDTH_160,
.used.chan = &chan6g_33,
.used.center_freq1 = 6185,
.psd.valid = true,
.psd.count = 16,
.psd.n = 4,
.psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
.out.valid = true,
.out.count = 8,
.out.n = 4,
.out.power = { 0, 1, 2, 3, 12, 13, 14, 15, 127, 127, 127, 127, 127, 127, 127, 127},
},
};
KUNIT_ARRAY_PARAM_DESC(psd_reorder, psd_reorder_cases, desc);
static void psd_reorder(struct kunit *test)
{
const struct psd_reorder_test_case *params = test->param_value;
struct ieee80211_parsed_tpe_psd tmp = params->psd;
KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(¶ms->ap), true);
KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(¶ms->used), true);
ieee80211_rearrange_tpe_psd(&tmp, ¶ms->ap, ¶ms->used);
KUNIT_EXPECT_MEMEQ(test, &tmp, ¶ms->out, sizeof(tmp));
}
static struct kunit_case tpe_test_cases[] = {
KUNIT_CASE_PARAM(subchan_offset, subchan_offset_gen_params),
KUNIT_CASE_PARAM(psd_reorder, psd_reorder_gen_params),
{}
};
static struct kunit_suite tpe = {
.name = "mac80211-tpe",
.test_cases = tpe_test_cases,
};
kunit_test_suite(tpe);
|