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
|
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* KUnit tests for the iwlwifi device info table
*
* Copyright (C) 2023-2025 Intel Corporation
*/
#include <kunit/test.h>
#include <linux/pci.h>
#include "iwl-drv.h"
#include "iwl-config.h"
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
static void iwl_pci_print_dev_info(const char *pfx, const struct iwl_dev_info *di)
{
printk(KERN_DEBUG "%sdev=%.4x,subdev=%.4x,mac_type=%.4x,mac_step=%.4x,rf_type=%.4x,cdb=%d,jacket=%d,rf_id=%.2x,bw_limit=%d,cores=%.2x\n",
pfx, di->device, di->subdevice, di->mac_type, di->mac_step,
di->rf_type, di->cdb, di->jacket, di->rf_id, di->bw_limit,
di->cores);
}
static void devinfo_table_order(struct kunit *test)
{
int idx;
for (idx = 0; idx < iwl_dev_info_table_size; idx++) {
const struct iwl_dev_info *di = &iwl_dev_info_table[idx];
const struct iwl_dev_info *ret;
ret = iwl_pci_find_dev_info(di->device, di->subdevice,
di->mac_type, di->mac_step,
di->rf_type, di->cdb,
di->jacket, di->rf_id,
di->bw_limit,
di->cores, di->rf_step);
if (!ret) {
iwl_pci_print_dev_info("No entry found for: ", di);
KUNIT_FAIL(test,
"No entry found for entry at index %d\n", idx);
} else if (ret != di) {
iwl_pci_print_dev_info("searched: ", di);
iwl_pci_print_dev_info("found: ", ret);
KUNIT_FAIL(test,
"unusable entry at index %d (found index %d instead)\n",
idx, (int)(ret - iwl_dev_info_table));
}
}
}
static void devinfo_names(struct kunit *test)
{
int idx;
for (idx = 0; idx < iwl_dev_info_table_size; idx++) {
const struct iwl_dev_info *di = &iwl_dev_info_table[idx];
KUNIT_ASSERT_TRUE(test, di->name);
}
}
static void devinfo_no_cfg_dups(struct kunit *test)
{
/* allocate iwl_dev_info_table_size as upper bound */
const struct iwl_cfg **cfgs = kunit_kcalloc(test,
iwl_dev_info_table_size,
sizeof(*cfgs), GFP_KERNEL);
int p = 0;
KUNIT_ASSERT_NOT_NULL(test, cfgs);
/* build a list of unique (by pointer) configs first */
for (int i = 0; i < iwl_dev_info_table_size; i++) {
bool found = false;
for (int j = 0; j < p; j++) {
if (cfgs[j] == iwl_dev_info_table[i].cfg) {
found = true;
break;
}
}
if (!found) {
cfgs[p] = iwl_dev_info_table[i].cfg;
p++;
}
}
/* check that they're really all different */
for (int i = 0; i < p; i++) {
struct iwl_cfg cfg_i = *cfgs[i];
for (int j = 0; j < i; j++) {
struct iwl_cfg cfg_j = *cfgs[j];
KUNIT_EXPECT_NE_MSG(test, memcmp(&cfg_i, &cfg_j,
sizeof(cfg_i)), 0,
"identical configs: %ps and %ps\n",
cfgs[i], cfgs[j]);
}
}
}
static void devinfo_check_subdev_match(struct kunit *test)
{
for (int i = 0; i < iwl_dev_info_table_size; i++) {
const struct iwl_dev_info *di = &iwl_dev_info_table[i];
/* if BW limit bit is matched then must have a limit */
if (di->bw_limit == 1)
KUNIT_EXPECT_NE(test, di->cfg->bw_limit, 0);
if (di->subdevice == (u16)IWL_CFG_ANY)
continue;
KUNIT_EXPECT_EQ(test, di->rf_id, (u8)IWL_CFG_ANY);
KUNIT_EXPECT_EQ(test, di->bw_limit, (u8)IWL_CFG_ANY);
KUNIT_EXPECT_EQ(test, di->cores, (u8)IWL_CFG_ANY);
}
}
static void devinfo_check_killer_subdev(struct kunit *test)
{
for (int i = 0; i < iwl_dev_info_table_size; i++) {
const struct iwl_dev_info *di = &iwl_dev_info_table[i];
if (!strstr(di->name, "Killer"))
continue;
KUNIT_EXPECT_NE(test, di->subdevice, (u16)IWL_CFG_ANY);
}
}
static void devinfo_pci_ids(struct kunit *test)
{
struct pci_dev *dev;
dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dev);
for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
const struct pci_device_id *s, *t;
s = &iwl_hw_card_ids[i];
dev->vendor = s->vendor;
dev->device = s->device;
dev->subsystem_vendor = s->subvendor;
dev->subsystem_device = s->subdevice;
dev->class = s->class;
t = pci_match_id(iwl_hw_card_ids, dev);
KUNIT_EXPECT_PTR_EQ(test, t, s);
}
}
static void devinfo_no_trans_cfg_dups(struct kunit *test)
{
/* allocate iwl_dev_info_table_size as upper bound */
const struct iwl_cfg_trans_params **cfgs;
int count = 0;
int p = 0;
for (int i = 0; iwl_hw_card_ids[i].vendor; i++)
count++;
cfgs = kunit_kcalloc(test, count, sizeof(*cfgs), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, cfgs);
/* build a list of unique (by pointer) configs first */
for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
struct iwl_cfg_trans_params *cfg;
bool found = false;
cfg = (void *)iwl_hw_card_ids[i].driver_data;
for (int j = 0; j < p; j++) {
if (cfgs[j] == cfg) {
found = true;
break;
}
}
if (!found) {
cfgs[p] = cfg;
p++;
}
}
/* check that they're really all different */
for (int i = 0; i < p; i++) {
for (int j = 0; j < i; j++) {
KUNIT_EXPECT_NE_MSG(test, memcmp(cfgs[i], cfgs[j],
sizeof(*cfgs[i])), 0,
"identical configs: %ps and %ps\n",
cfgs[i], cfgs[j]);
}
}
}
static struct kunit_case devinfo_test_cases[] = {
KUNIT_CASE(devinfo_table_order),
KUNIT_CASE(devinfo_names),
KUNIT_CASE(devinfo_no_cfg_dups),
KUNIT_CASE(devinfo_check_subdev_match),
KUNIT_CASE(devinfo_check_killer_subdev),
KUNIT_CASE(devinfo_pci_ids),
KUNIT_CASE(devinfo_no_trans_cfg_dups),
{}
};
static struct kunit_suite iwlwifi_devinfo = {
.name = "iwlwifi-devinfo",
.test_cases = devinfo_test_cases,
};
kunit_test_suite(iwlwifi_devinfo);
|