module: Convert symbol namespace to string literal
[linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / tests / links.c
blob1dc57e02219130b6bfae8cd641768910a32096e0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * KUnit tests for channel helper functions
5 * Copyright (C) 2024 Intel Corporation
6 */
7 #include <net/mac80211.h>
8 #include "../mvm.h"
9 #include <kunit/test.h>
11 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
13 static struct wiphy wiphy = {
14 .mtx = __MUTEX_INITIALIZER(wiphy.mtx),
17 static struct ieee80211_hw hw = {
18 .wiphy = &wiphy,
21 static struct ieee80211_channel chan_5ghz = {
22 .band = NL80211_BAND_5GHZ,
25 static struct ieee80211_channel chan_6ghz = {
26 .band = NL80211_BAND_6GHZ,
29 static struct ieee80211_channel chan_2ghz = {
30 .band = NL80211_BAND_2GHZ,
33 static struct cfg80211_chan_def chandef_a = {};
35 static struct cfg80211_chan_def chandef_b = {};
37 static struct iwl_mvm_phy_ctxt ctx = {};
39 static struct iwl_mvm_vif_link_info mvm_link = {
40 .phy_ctxt = &ctx,
41 .active = true
44 static struct cfg80211_bss bss = {};
46 static struct ieee80211_bss_conf link_conf = {.bss = &bss};
48 static const struct iwl_fw_cmd_version entry = {
49 .group = LEGACY_GROUP,
50 .cmd = BT_PROFILE_NOTIFICATION,
51 .notif_ver = 4
54 static struct iwl_fw fw = {
55 .ucode_capa = {
56 .n_cmd_versions = 1,
57 .cmd_versions = &entry,
61 static struct iwl_mvm mvm = {
62 .hw = &hw,
63 .fw = &fw,
66 static const struct link_grading_case {
67 const char *desc;
68 const struct cfg80211_chan_def chandef;
69 s32 signal;
70 s16 channel_util;
71 int chan_load_by_us;
72 unsigned int grade;
73 } link_grading_cases[] = {
75 .desc = "UHB, RSSI below range, no factors",
76 .chandef = {
77 .chan = &chan_6ghz,
78 .width = NL80211_CHAN_WIDTH_20,
80 .signal = -100,
81 .grade = 177,
84 .desc = "LB, RSSI in range, no factors",
85 .chandef = {
86 .chan = &chan_2ghz,
87 .width = NL80211_CHAN_WIDTH_20,
89 .signal = -84,
90 .grade = 344,
93 .desc = "HB, RSSI above range, no factors",
94 .chandef = {
95 .chan = &chan_5ghz,
96 .width = NL80211_CHAN_WIDTH_20,
98 .signal = -50,
99 .grade = 3442,
102 .desc = "HB, BSS Load IE (20 percent), inactive link, no puncturing factor",
103 .chandef = {
104 .chan = &chan_5ghz,
105 .width = NL80211_CHAN_WIDTH_20,
107 .signal = -66,
108 .channel_util = 51,
109 .grade = 1836,
112 .desc = "LB, BSS Load IE (20 percent), active link, chan_load_by_us=10 percent. No puncturing factor",
113 .chandef = {
114 .chan = &chan_2ghz,
115 .width = NL80211_CHAN_WIDTH_20,
117 .signal = -61,
118 .channel_util = 51,
119 .chan_load_by_us = 10,
120 .grade = 2061,
123 .desc = "UHB, BSS Load IE (40 percent), active link, chan_load_by_us=50 (invalid) percent. No puncturing factor",
124 .chandef = {
125 .chan = &chan_6ghz,
126 .width = NL80211_CHAN_WIDTH_20,
128 .signal = -66,
129 .channel_util = 102,
130 .chan_load_by_us = 50,
131 .grade = 1552,
133 { .desc = "HB, 80 MHz, no channel load factor, punctured percentage 0",
134 .chandef = {
135 .chan = &chan_5ghz,
136 .width = NL80211_CHAN_WIDTH_80,
137 .punctured = 0x0000
139 .signal = -72,
140 .grade = 1750,
142 { .desc = "HB, 160 MHz, no channel load factor, punctured percentage 25",
143 .chandef = {
144 .chan = &chan_5ghz,
145 .width = NL80211_CHAN_WIDTH_160,
146 .punctured = 0x3
148 .signal = -72,
149 .grade = 1312,
151 { .desc = "UHB, 320 MHz, no channel load factor, punctured percentage 12.5 (2/16)",
152 .chandef = {
153 .chan = &chan_6ghz,
154 .width = NL80211_CHAN_WIDTH_320,
155 .punctured = 0x3
157 .signal = -72,
158 .grade = 1806,
160 { .desc = "HB, 160 MHz, channel load 20, channel load by us 10, punctured percentage 25",
161 .chandef = {
162 .chan = &chan_5ghz,
163 .width = NL80211_CHAN_WIDTH_160,
164 .punctured = 0x3
166 .channel_util = 51,
167 .chan_load_by_us = 10,
168 .signal = -72,
169 .grade = 1179,
173 KUNIT_ARRAY_PARAM_DESC(link_grading, link_grading_cases, desc)
175 static void setup_link_conf(struct kunit *test)
177 const struct link_grading_case *params = test->param_value;
178 size_t vif_size = sizeof(struct ieee80211_vif) +
179 sizeof(struct iwl_mvm_vif);
180 struct ieee80211_vif *vif = kunit_kzalloc(test, vif_size, GFP_KERNEL);
181 struct ieee80211_bss_load_elem *bss_load;
182 struct element *element;
183 size_t ies_size = sizeof(struct cfg80211_bss_ies) + sizeof(*bss_load) + sizeof(element);
184 struct cfg80211_bss_ies *ies;
185 struct iwl_mvm_vif *mvmvif;
187 KUNIT_ASSERT_NOT_NULL(test, vif);
189 mvmvif = iwl_mvm_vif_from_mac80211(vif);
190 if (params->chan_load_by_us > 0) {
191 ctx.channel_load_by_us = params->chan_load_by_us;
192 mvmvif->link[0] = &mvm_link;
195 link_conf.vif = vif;
196 link_conf.chanreq.oper = params->chandef;
197 bss.signal = DBM_TO_MBM(params->signal);
199 ies = kunit_kzalloc(test, ies_size, GFP_KERNEL);
200 KUNIT_ASSERT_NOT_NULL(test, ies);
201 ies->len = sizeof(*bss_load) + sizeof(struct element);
203 element = (void *)ies->data;
204 element->datalen = sizeof(*bss_load);
205 element->id = 11;
207 bss_load = (void *)element->data;
208 bss_load->channel_util = params->channel_util;
210 rcu_assign_pointer(bss.ies, ies);
211 rcu_assign_pointer(bss.beacon_ies, ies);
214 static void test_link_grading(struct kunit *test)
216 const struct link_grading_case *params = test->param_value;
217 unsigned int ret;
219 setup_link_conf(test);
221 rcu_read_lock();
222 ret = iwl_mvm_get_link_grade(&link_conf);
223 rcu_read_unlock();
225 KUNIT_EXPECT_EQ(test, ret, params->grade);
227 kunit_kfree(test, link_conf.vif);
228 RCU_INIT_POINTER(bss.ies, NULL);
231 static struct kunit_case link_grading_test_cases[] = {
232 KUNIT_CASE_PARAM(test_link_grading, link_grading_gen_params),
236 static struct kunit_suite link_grading = {
237 .name = "iwlmvm-link-grading",
238 .test_cases = link_grading_test_cases,
241 kunit_test_suite(link_grading);
243 static const struct valid_link_pair_case {
244 const char *desc;
245 bool bt;
246 struct ieee80211_channel *chan_a;
247 struct ieee80211_channel *chan_b;
248 enum nl80211_chan_width cw_a;
249 enum nl80211_chan_width cw_b;
250 s32 sig_a;
251 s32 sig_b;
252 bool csa_a;
253 bool valid;
254 } valid_link_pair_cases[] = {
256 .desc = "HB + UHB, valid.",
257 .chan_a = &chan_6ghz,
258 .chan_b = &chan_5ghz,
259 .valid = true,
262 .desc = "LB + HB, no BT.",
263 .chan_a = &chan_2ghz,
264 .chan_b = &chan_5ghz,
265 .valid = false,
268 .desc = "LB + HB, with BT.",
269 .bt = true,
270 .chan_a = &chan_2ghz,
271 .chan_b = &chan_5ghz,
272 .valid = false,
275 .desc = "Same band",
276 .chan_a = &chan_2ghz,
277 .chan_b = &chan_2ghz,
278 .valid = false,
281 .desc = "RSSI: LB, 20 MHz, low",
282 .chan_a = &chan_2ghz,
283 .cw_a = NL80211_CHAN_WIDTH_20,
284 .sig_a = -68,
285 .chan_b = &chan_5ghz,
286 .valid = false,
289 .desc = "RSSI: UHB, 20 MHz, high",
290 .chan_a = &chan_6ghz,
291 .cw_a = NL80211_CHAN_WIDTH_20,
292 .sig_a = -66,
293 .chan_b = &chan_5ghz,
294 .cw_b = NL80211_CHAN_WIDTH_20,
295 .valid = true,
298 .desc = "RSSI: UHB, 40 MHz, low",
299 .chan_a = &chan_6ghz,
300 .cw_a = NL80211_CHAN_WIDTH_40,
301 .sig_a = -65,
302 .chan_b = &chan_5ghz,
303 .cw_b = NL80211_CHAN_WIDTH_40,
304 .valid = false,
307 .desc = "RSSI: UHB, 40 MHz, high",
308 .chan_a = &chan_6ghz,
309 .cw_a = NL80211_CHAN_WIDTH_40,
310 .sig_a = -63,
311 .chan_b = &chan_5ghz,
312 .cw_b = NL80211_CHAN_WIDTH_40,
313 .valid = true,
316 .desc = "RSSI: UHB, 80 MHz, low",
317 .chan_a = &chan_6ghz,
318 .cw_a = NL80211_CHAN_WIDTH_80,
319 .sig_a = -62,
320 .chan_b = &chan_5ghz,
321 .cw_b = NL80211_CHAN_WIDTH_80,
322 .valid = false,
325 .desc = "RSSI: UHB, 80 MHz, high",
326 .chan_a = &chan_6ghz,
327 .cw_a = NL80211_CHAN_WIDTH_80,
328 .sig_a = -60,
329 .chan_b = &chan_5ghz,
330 .cw_b = NL80211_CHAN_WIDTH_80,
331 .valid = true,
334 .desc = "RSSI: UHB, 160 MHz, low",
335 .chan_a = &chan_6ghz,
336 .cw_a = NL80211_CHAN_WIDTH_160,
337 .sig_a = -59,
338 .chan_b = &chan_5ghz,
339 .cw_b = NL80211_CHAN_WIDTH_160,
340 .valid = false,
343 .desc = "RSSI: HB, 160 MHz, high",
344 .chan_a = &chan_6ghz,
345 .cw_a = NL80211_CHAN_WIDTH_160,
346 .sig_a = -5,
347 .chan_b = &chan_5ghz,
348 .cw_b = NL80211_CHAN_WIDTH_160,
349 .valid = true,
352 .desc = "CSA active",
353 .chan_a = &chan_6ghz,
354 .cw_a = NL80211_CHAN_WIDTH_160,
355 .sig_a = -5,
356 .chan_b = &chan_5ghz,
357 .cw_b = NL80211_CHAN_WIDTH_160,
358 .valid = false,
359 /* same as previous entry with valid=true except for CSA */
360 .csa_a = true,
364 KUNIT_ARRAY_PARAM_DESC(valid_link_pair, valid_link_pair_cases, desc)
366 static void test_valid_link_pair(struct kunit *test)
368 const struct valid_link_pair_case *params = test->param_value;
369 size_t vif_size = sizeof(struct ieee80211_vif) +
370 sizeof(struct iwl_mvm_vif);
371 struct ieee80211_vif *vif = kunit_kzalloc(test, vif_size, GFP_KERNEL);
372 struct iwl_trans *trans = kunit_kzalloc(test, sizeof(struct iwl_trans),
373 GFP_KERNEL);
374 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
375 struct iwl_mvm_link_sel_data link_a = {
376 .chandef = &chandef_a,
377 .link_id = 1,
378 .signal = params->sig_a,
380 struct iwl_mvm_link_sel_data link_b = {
381 .chandef = &chandef_b,
382 .link_id = 5,
383 .signal = params->sig_b,
385 struct ieee80211_bss_conf *conf;
386 bool result;
388 KUNIT_ASSERT_NOT_NULL(test, vif);
389 KUNIT_ASSERT_NOT_NULL(test, trans);
391 chandef_a.chan = params->chan_a;
392 chandef_b.chan = params->chan_b;
394 chandef_a.width = params->cw_a ?: NL80211_CHAN_WIDTH_20;
395 chandef_b.width = params->cw_b ?: NL80211_CHAN_WIDTH_20;
397 mvm.trans = trans;
399 mvm.last_bt_notif.wifi_loss_low_rssi = params->bt;
400 mvmvif->mvm = &mvm;
402 conf = kunit_kzalloc(test, sizeof(*vif->link_conf[0]), GFP_KERNEL);
403 KUNIT_ASSERT_NOT_NULL(test, conf);
404 conf->chanreq.oper = chandef_a;
405 conf->csa_active = params->csa_a;
406 vif->link_conf[link_a.link_id] = (void __rcu *)conf;
408 conf = kunit_kzalloc(test, sizeof(*vif->link_conf[0]), GFP_KERNEL);
409 KUNIT_ASSERT_NOT_NULL(test, conf);
410 conf->chanreq.oper = chandef_b;
411 vif->link_conf[link_b.link_id] = (void __rcu *)conf;
413 wiphy_lock(&wiphy);
414 result = iwl_mvm_mld_valid_link_pair(vif, &link_a, &link_b);
415 wiphy_unlock(&wiphy);
417 KUNIT_EXPECT_EQ(test, result, params->valid);
419 kunit_kfree(test, vif);
420 kunit_kfree(test, trans);
423 static struct kunit_case valid_link_pair_test_cases[] = {
424 KUNIT_CASE_PARAM(test_valid_link_pair, valid_link_pair_gen_params),
428 static struct kunit_suite valid_link_pair = {
429 .name = "iwlmvm-valid-link-pair",
430 .test_cases = valid_link_pair_test_cases,
433 kunit_test_suite(valid_link_pair);