xref: /linux/drivers/net/wireless/intel/iwlwifi/tests/nvm_parse.c (revision 7a7c52645ce62314cdd69815e9d8fcb33e0042d5)
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);
73