1 // SPDX-License-Identifier: GPL-2.0 AND MIT
2 /*
3 * Copyright © 2024 Intel Corporation
4 */
5
6 #include <kunit/test.h>
7
8 #include "xe_device.h"
9 #include "xe_kunit_helpers.h"
10 #include "xe_pci_test.h"
11
pf_service_test_init(struct kunit * test)12 static int pf_service_test_init(struct kunit *test)
13 {
14 struct xe_pci_fake_data fake = {
15 .sriov_mode = XE_SRIOV_MODE_PF,
16 .platform = XE_TIGERLAKE, /* some random platform */
17 .subplatform = XE_SUBPLATFORM_NONE,
18 };
19 struct xe_device *xe;
20 struct xe_gt *gt;
21
22 test->priv = &fake;
23 xe_kunit_helper_xe_device_test_init(test);
24
25 xe = test->priv;
26 KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0);
27
28 gt = xe_device_get_gt(xe, 0);
29 pf_init_versions(gt);
30
31 /*
32 * sanity check:
33 * - all supported platforms VF/PF ABI versions must be defined
34 * - base version can't be newer than latest
35 */
36 KUNIT_ASSERT_NE(test, 0, gt->sriov.pf.service.version.base.major);
37 KUNIT_ASSERT_NE(test, 0, gt->sriov.pf.service.version.latest.major);
38 KUNIT_ASSERT_LE(test, gt->sriov.pf.service.version.base.major,
39 gt->sriov.pf.service.version.latest.major);
40 if (gt->sriov.pf.service.version.base.major == gt->sriov.pf.service.version.latest.major)
41 KUNIT_ASSERT_LE(test, gt->sriov.pf.service.version.base.minor,
42 gt->sriov.pf.service.version.latest.minor);
43
44 test->priv = gt;
45 return 0;
46 }
47
pf_negotiate_any(struct kunit * test)48 static void pf_negotiate_any(struct kunit *test)
49 {
50 struct xe_gt *gt = test->priv;
51 u32 major, minor;
52
53 KUNIT_ASSERT_EQ(test, 0,
54 pf_negotiate_version(gt, VF2PF_HANDSHAKE_MAJOR_ANY,
55 VF2PF_HANDSHAKE_MINOR_ANY,
56 &major, &minor));
57 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major);
58 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.latest.minor);
59 }
60
pf_negotiate_base_match(struct kunit * test)61 static void pf_negotiate_base_match(struct kunit *test)
62 {
63 struct xe_gt *gt = test->priv;
64 u32 major, minor;
65
66 KUNIT_ASSERT_EQ(test, 0,
67 pf_negotiate_version(gt,
68 gt->sriov.pf.service.version.base.major,
69 gt->sriov.pf.service.version.base.minor,
70 &major, &minor));
71 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.base.major);
72 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.base.minor);
73 }
74
pf_negotiate_base_newer(struct kunit * test)75 static void pf_negotiate_base_newer(struct kunit *test)
76 {
77 struct xe_gt *gt = test->priv;
78 u32 major, minor;
79
80 KUNIT_ASSERT_EQ(test, 0,
81 pf_negotiate_version(gt,
82 gt->sriov.pf.service.version.base.major,
83 gt->sriov.pf.service.version.base.minor + 1,
84 &major, &minor));
85 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.base.major);
86 KUNIT_ASSERT_GE(test, minor, gt->sriov.pf.service.version.base.minor);
87 if (gt->sriov.pf.service.version.base.major == gt->sriov.pf.service.version.latest.major)
88 KUNIT_ASSERT_LE(test, minor, gt->sriov.pf.service.version.latest.minor);
89 else
90 KUNIT_FAIL(test, "FIXME: don't know how to test multi-version yet!\n");
91 }
92
pf_negotiate_base_next(struct kunit * test)93 static void pf_negotiate_base_next(struct kunit *test)
94 {
95 struct xe_gt *gt = test->priv;
96 u32 major, minor;
97
98 KUNIT_ASSERT_EQ(test, 0,
99 pf_negotiate_version(gt,
100 gt->sriov.pf.service.version.base.major + 1, 0,
101 &major, &minor));
102 KUNIT_ASSERT_GE(test, major, gt->sriov.pf.service.version.base.major);
103 KUNIT_ASSERT_LE(test, major, gt->sriov.pf.service.version.latest.major);
104 if (major == gt->sriov.pf.service.version.latest.major)
105 KUNIT_ASSERT_LE(test, minor, gt->sriov.pf.service.version.latest.minor);
106 else
107 KUNIT_FAIL(test, "FIXME: don't know how to test multi-version yet!\n");
108 }
109
pf_negotiate_base_older(struct kunit * test)110 static void pf_negotiate_base_older(struct kunit *test)
111 {
112 struct xe_gt *gt = test->priv;
113 u32 major, minor;
114
115 if (!gt->sriov.pf.service.version.base.minor)
116 kunit_skip(test, "no older minor\n");
117
118 KUNIT_ASSERT_NE(test, 0,
119 pf_negotiate_version(gt,
120 gt->sriov.pf.service.version.base.major,
121 gt->sriov.pf.service.version.base.minor - 1,
122 &major, &minor));
123 }
124
pf_negotiate_base_prev(struct kunit * test)125 static void pf_negotiate_base_prev(struct kunit *test)
126 {
127 struct xe_gt *gt = test->priv;
128 u32 major, minor;
129
130 KUNIT_ASSERT_NE(test, 0,
131 pf_negotiate_version(gt,
132 gt->sriov.pf.service.version.base.major - 1, 1,
133 &major, &minor));
134 }
135
pf_negotiate_latest_match(struct kunit * test)136 static void pf_negotiate_latest_match(struct kunit *test)
137 {
138 struct xe_gt *gt = test->priv;
139 u32 major, minor;
140
141 KUNIT_ASSERT_EQ(test, 0,
142 pf_negotiate_version(gt,
143 gt->sriov.pf.service.version.latest.major,
144 gt->sriov.pf.service.version.latest.minor,
145 &major, &minor));
146 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major);
147 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.latest.minor);
148 }
149
pf_negotiate_latest_newer(struct kunit * test)150 static void pf_negotiate_latest_newer(struct kunit *test)
151 {
152 struct xe_gt *gt = test->priv;
153 u32 major, minor;
154
155 KUNIT_ASSERT_EQ(test, 0,
156 pf_negotiate_version(gt,
157 gt->sriov.pf.service.version.latest.major,
158 gt->sriov.pf.service.version.latest.minor + 1,
159 &major, &minor));
160 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major);
161 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.latest.minor);
162 }
163
pf_negotiate_latest_next(struct kunit * test)164 static void pf_negotiate_latest_next(struct kunit *test)
165 {
166 struct xe_gt *gt = test->priv;
167 u32 major, minor;
168
169 KUNIT_ASSERT_EQ(test, 0,
170 pf_negotiate_version(gt,
171 gt->sriov.pf.service.version.latest.major + 1, 0,
172 &major, &minor));
173 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major);
174 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.latest.minor);
175 }
176
pf_negotiate_latest_older(struct kunit * test)177 static void pf_negotiate_latest_older(struct kunit *test)
178 {
179 struct xe_gt *gt = test->priv;
180 u32 major, minor;
181
182 if (!gt->sriov.pf.service.version.latest.minor)
183 kunit_skip(test, "no older minor\n");
184
185 KUNIT_ASSERT_EQ(test, 0,
186 pf_negotiate_version(gt,
187 gt->sriov.pf.service.version.latest.major,
188 gt->sriov.pf.service.version.latest.minor - 1,
189 &major, &minor));
190 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major);
191 KUNIT_ASSERT_EQ(test, minor, gt->sriov.pf.service.version.latest.minor - 1);
192 }
193
pf_negotiate_latest_prev(struct kunit * test)194 static void pf_negotiate_latest_prev(struct kunit *test)
195 {
196 struct xe_gt *gt = test->priv;
197 u32 major, minor;
198
199 if (gt->sriov.pf.service.version.base.major == gt->sriov.pf.service.version.latest.major)
200 kunit_skip(test, "no prev major");
201
202 KUNIT_ASSERT_EQ(test, 0,
203 pf_negotiate_version(gt,
204 gt->sriov.pf.service.version.latest.major - 1,
205 gt->sriov.pf.service.version.base.minor + 1,
206 &major, &minor));
207 KUNIT_ASSERT_EQ(test, major, gt->sriov.pf.service.version.latest.major - 1);
208 KUNIT_ASSERT_GE(test, major, gt->sriov.pf.service.version.base.major);
209 }
210
211 static struct kunit_case pf_service_test_cases[] = {
212 KUNIT_CASE(pf_negotiate_any),
213 KUNIT_CASE(pf_negotiate_base_match),
214 KUNIT_CASE(pf_negotiate_base_newer),
215 KUNIT_CASE(pf_negotiate_base_next),
216 KUNIT_CASE(pf_negotiate_base_older),
217 KUNIT_CASE(pf_negotiate_base_prev),
218 KUNIT_CASE(pf_negotiate_latest_match),
219 KUNIT_CASE(pf_negotiate_latest_newer),
220 KUNIT_CASE(pf_negotiate_latest_next),
221 KUNIT_CASE(pf_negotiate_latest_older),
222 KUNIT_CASE(pf_negotiate_latest_prev),
223 {}
224 };
225
226 static struct kunit_suite pf_service_suite = {
227 .name = "pf_service",
228 .test_cases = pf_service_test_cases,
229 .init = pf_service_test_init,
230 };
231
232 kunit_test_suite(pf_service_suite);
233