Skip to content

Commit 7a7c526

Browse files
panjaneyMiriam-Rachel
authored andcommitted
wifi: iwlwifi: add kunit tests for nvm parse
nvm flags is part of nvm parse. Add test for VLP AP/CLIENT enable/disable scenarios. Signed-off-by: Pagadala Yesu Anjaneyulu <[email protected]> Signed-off-by: Miri Korenblit <[email protected]> Link: https://patch.msgid.link/20250909061931.a7a4713fbfee.Ia0caf8865e63b40826c9b66084bd20438554f15c@changeid
1 parent 59cb902 commit 7a7c526

File tree

4 files changed

+152
-72
lines changed

4 files changed

+152
-72
lines changed

drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -139,50 +139,6 @@ static struct ieee80211_rate iwl_cfg80211_rates[] = {
139139
#define RATES_52_OFFS 4
140140
#define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
141141

142-
/**
143-
* enum iwl_nvm_channel_flags - channel flags in NVM
144-
* @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
145-
* @NVM_CHANNEL_IBSS: usable as an IBSS channel and deprecated
146-
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
147-
* @NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY: active scanning allowed and
148-
* AP allowed only in 20 MHz. Valid only
149-
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
150-
* @NVM_CHANNEL_ACTIVE: active scanning allowed and allows IBSS
151-
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
152-
* @NVM_CHANNEL_RADAR: radar detection required
153-
* @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
154-
* @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
155-
* on same channel on 2.4 or same UNII band on 5.2
156-
* @NVM_CHANNEL_UNIFORM: uniform spreading required
157-
* @NVM_CHANNEL_20MHZ: 20 MHz channel okay
158-
* @NVM_CHANNEL_40MHZ: 40 MHz channel okay
159-
* @NVM_CHANNEL_80MHZ: 80 MHz channel okay
160-
* @NVM_CHANNEL_160MHZ: 160 MHz channel okay
161-
* @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
162-
* @NVM_CHANNEL_VLP: client support connection to UHB VLP AP
163-
* @NVM_CHANNEL_AFC: client support connection to UHB AFC AP
164-
* @NVM_CHANNEL_VLP_AP_NOT_ALLOWED: UHB VLP AP not allowed,
165-
* Valid only when %NVM_CHANNEL_VLP is enabled.
166-
*/
167-
enum iwl_nvm_channel_flags {
168-
NVM_CHANNEL_VALID = BIT(0),
169-
NVM_CHANNEL_IBSS = BIT(1),
170-
NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY = BIT(2),
171-
NVM_CHANNEL_ACTIVE = BIT(3),
172-
NVM_CHANNEL_RADAR = BIT(4),
173-
NVM_CHANNEL_INDOOR_ONLY = BIT(5),
174-
NVM_CHANNEL_GO_CONCURRENT = BIT(6),
175-
NVM_CHANNEL_UNIFORM = BIT(7),
176-
NVM_CHANNEL_20MHZ = BIT(8),
177-
NVM_CHANNEL_40MHZ = BIT(9),
178-
NVM_CHANNEL_80MHZ = BIT(10),
179-
NVM_CHANNEL_160MHZ = BIT(11),
180-
NVM_CHANNEL_DC_HIGH = BIT(12),
181-
NVM_CHANNEL_VLP = BIT(13),
182-
NVM_CHANNEL_AFC = BIT(14),
183-
NVM_CHANNEL_VLP_AP_NOT_ALLOWED = BIT(15),
184-
};
185-
186142
/**
187143
* enum iwl_reg_capa_flags_v1 - global flags applied for the whole regulatory
188144
* domain.
@@ -282,30 +238,6 @@ enum iwl_reg_capa_flags_v4 {
282238
*/
283239
#define REG_CAPA_V4_RESP_VER 8
284240

285-
/**
286-
* struct iwl_reg_capa - struct for global regulatory capabilities, Used for
287-
* handling the different APIs of reg_capa_flags.
288-
*
289-
* @allow_40mhz: 11n channel with a width of 40Mhz is allowed
290-
* for this regulatory domain.
291-
* @allow_80mhz: 11ac channel with a width of 80Mhz is allowed
292-
* for this regulatory domain (valid only in 5 and 6 Ghz).
293-
* @allow_160mhz: 11ac channel with a width of 160Mhz is allowed
294-
* for this regulatory domain (valid only in 5 and 6 Ghz).
295-
* @allow_320mhz: 11be channel with a width of 320Mhz is allowed
296-
* for this regulatory domain (valid only in 6 Ghz).
297-
* @disable_11ax: 11ax is forbidden for this regulatory domain.
298-
* @disable_11be: 11be is forbidden for this regulatory domain.
299-
*/
300-
struct iwl_reg_capa {
301-
bool allow_40mhz;
302-
bool allow_80mhz;
303-
bool allow_160mhz;
304-
bool allow_320mhz;
305-
bool disable_11ax;
306-
bool disable_11be;
307-
};
308-
309241
static inline void iwl_nvm_print_channel_flags(struct device *dev, u32 level,
310242
int chan, u32 flags)
311243
{
@@ -1596,9 +1528,10 @@ iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg,
15961528
}
15971529
IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
15981530

1599-
static u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
1600-
int ch_idx, u16 nvm_flags,
1601-
struct iwl_reg_capa reg_capa)
1531+
VISIBLE_IF_IWLWIFI_KUNIT
1532+
u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
1533+
int ch_idx, u16 nvm_flags,
1534+
struct iwl_reg_capa reg_capa)
16021535
{
16031536
u32 flags = NL80211_RRF_NO_HT40;
16041537

@@ -1688,6 +1621,7 @@ static u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
16881621

16891622
return flags;
16901623
}
1624+
EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_nvm_get_regdom_bw_flags);
16911625

16921626
static struct iwl_reg_capa iwl_get_reg_capa(u32 flags, u8 resp_ver)
16931627
{

drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,80 @@ enum iwl_nvm_sbands_flags {
2121
IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ = BIT(1),
2222
};
2323

24+
/**
25+
* struct iwl_reg_capa - struct for global regulatory capabilities, Used for
26+
* handling the different APIs of reg_capa_flags.
27+
*
28+
* @allow_40mhz: 11n channel with a width of 40Mhz is allowed
29+
* for this regulatory domain.
30+
* @allow_80mhz: 11ac channel with a width of 80Mhz is allowed
31+
* for this regulatory domain (valid only in 5 and 6 Ghz).
32+
* @allow_160mhz: 11ac channel with a width of 160Mhz is allowed
33+
* for this regulatory domain (valid only in 5 and 6 Ghz).
34+
* @allow_320mhz: 11be channel with a width of 320Mhz is allowed
35+
* for this regulatory domain (valid only in 6 Ghz).
36+
* @disable_11ax: 11ax is forbidden for this regulatory domain.
37+
* @disable_11be: 11be is forbidden for this regulatory domain.
38+
*/
39+
struct iwl_reg_capa {
40+
bool allow_40mhz;
41+
bool allow_80mhz;
42+
bool allow_160mhz;
43+
bool allow_320mhz;
44+
bool disable_11ax;
45+
bool disable_11be;
46+
};
47+
48+
/**
49+
* enum iwl_nvm_channel_flags - channel flags in NVM
50+
* @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
51+
* @NVM_CHANNEL_IBSS: usable as an IBSS channel and deprecated
52+
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
53+
* @NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY: active scanning allowed and
54+
* AP allowed only in 20 MHz. Valid only
55+
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
56+
* @NVM_CHANNEL_ACTIVE: active scanning allowed and allows IBSS
57+
* when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
58+
* @NVM_CHANNEL_RADAR: radar detection required
59+
* @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
60+
* @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
61+
* on same channel on 2.4 or same UNII band on 5.2
62+
* @NVM_CHANNEL_UNIFORM: uniform spreading required
63+
* @NVM_CHANNEL_20MHZ: 20 MHz channel okay
64+
* @NVM_CHANNEL_40MHZ: 40 MHz channel okay
65+
* @NVM_CHANNEL_80MHZ: 80 MHz channel okay
66+
* @NVM_CHANNEL_160MHZ: 160 MHz channel okay
67+
* @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
68+
* @NVM_CHANNEL_VLP: client support connection to UHB VLP AP
69+
* @NVM_CHANNEL_AFC: client support connection to UHB AFC AP
70+
* @NVM_CHANNEL_VLP_AP_NOT_ALLOWED: UHB VLP AP not allowed,
71+
* Valid only when %NVM_CHANNEL_VLP is enabled.
72+
*/
73+
enum iwl_nvm_channel_flags {
74+
NVM_CHANNEL_VALID = BIT(0),
75+
NVM_CHANNEL_IBSS = BIT(1),
76+
NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY = BIT(2),
77+
NVM_CHANNEL_ACTIVE = BIT(3),
78+
NVM_CHANNEL_RADAR = BIT(4),
79+
NVM_CHANNEL_INDOOR_ONLY = BIT(5),
80+
NVM_CHANNEL_GO_CONCURRENT = BIT(6),
81+
NVM_CHANNEL_UNIFORM = BIT(7),
82+
NVM_CHANNEL_20MHZ = BIT(8),
83+
NVM_CHANNEL_40MHZ = BIT(9),
84+
NVM_CHANNEL_80MHZ = BIT(10),
85+
NVM_CHANNEL_160MHZ = BIT(11),
86+
NVM_CHANNEL_DC_HIGH = BIT(12),
87+
NVM_CHANNEL_VLP = BIT(13),
88+
NVM_CHANNEL_AFC = BIT(14),
89+
NVM_CHANNEL_VLP_AP_NOT_ALLOWED = BIT(15),
90+
};
91+
92+
#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
93+
u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
94+
int ch_idx, u16 nvm_flags,
95+
struct iwl_reg_capa reg_capa);
96+
#endif
97+
2498
/*
2599
* iwl_parse_nvm_data - parse NVM data and return values
26100
*

drivers/net/wireless/intel/iwlwifi/tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
22

3-
iwlwifi-tests-y += module.o devinfo.o utils.o
3+
iwlwifi-tests-y += module.o devinfo.o utils.o nvm_parse.o
44

55
ccflags-y += -I$(src)/../
66

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* KUnit tests for NVM parse
4+
*
5+
* Copyright (C) 2025 Intel Corporation
6+
*/
7+
#include <kunit/static_stub.h>
8+
#include <kunit/test.h>
9+
#include <iwl-nvm-parse.h>
10+
11+
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
12+
13+
static const struct nvm_flag_case {
14+
const char *desc;
15+
u16 nvm_flags;
16+
u32 reg_rule_flags;
17+
u32 set_reg_rule_flags;
18+
u32 clear_reg_rule_flags;
19+
} nvm_flag_cases[] = {
20+
{
21+
.desc = "Restricting VLP client and AP access",
22+
.nvm_flags = 0,
23+
.set_reg_rule_flags = NL80211_RRF_NO_6GHZ_VLP_CLIENT,
24+
.clear_reg_rule_flags = NL80211_RRF_ALLOW_6GHZ_VLP_AP,
25+
},
26+
{
27+
.desc = "Allow VLP client and AP access",
28+
.nvm_flags = NVM_CHANNEL_VLP,
29+
.set_reg_rule_flags = NL80211_RRF_ALLOW_6GHZ_VLP_AP,
30+
.clear_reg_rule_flags = NL80211_RRF_NO_6GHZ_VLP_CLIENT,
31+
},
32+
{
33+
.desc = "Allow VLP client access, while restricting AP access",
34+
.nvm_flags = NVM_CHANNEL_VLP | NVM_CHANNEL_VLP_AP_NOT_ALLOWED,
35+
.set_reg_rule_flags = 0,
36+
.clear_reg_rule_flags = NL80211_RRF_ALLOW_6GHZ_VLP_AP |
37+
NL80211_RRF_NO_6GHZ_VLP_CLIENT,
38+
},
39+
};
40+
41+
KUNIT_ARRAY_PARAM_DESC(nvm_flag, nvm_flag_cases, desc)
42+
43+
static void test_nvm_flags(struct kunit *test)
44+
{
45+
const struct nvm_flag_case *params = test->param_value;
46+
struct iwl_reg_capa reg_capa = {};
47+
u32 flags = 0;
48+
49+
flags = iwl_nvm_get_regdom_bw_flags(NULL, 0, params->nvm_flags,
50+
reg_capa);
51+
52+
if ((params->set_reg_rule_flags & flags) != params->set_reg_rule_flags)
53+
KUNIT_FAIL(test, "Expected set bits:0x%08x flags:0x%08x\n",
54+
params->set_reg_rule_flags, flags);
55+
56+
if (params->clear_reg_rule_flags & flags)
57+
KUNIT_FAIL(test, "Expected clear bits:0x%08x flags:0x%08x\n",
58+
params->clear_reg_rule_flags, flags);
59+
}
60+
61+
static struct kunit_case nvm_flags_test_cases[] = {
62+
KUNIT_CASE_PARAM(test_nvm_flags,
63+
nvm_flag_gen_params),
64+
{},
65+
};
66+
67+
static struct kunit_suite nvm_flags_suite = {
68+
.name = "iwlwifi-nvm_flags",
69+
.test_cases = nvm_flags_test_cases,
70+
};
71+
72+
kunit_test_suite(nvm_flags_suite);

0 commit comments

Comments
 (0)