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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
|
// SPDX-License-Identifier: MIT
/*
* Copyright(c) 2024 Intel Corporation. All rights reserved.
*/
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <sys/stat.h>
#include "drmtest.h"
#include "igt_core.h"
#include "igt_device.h"
#include "igt_kmod.h"
#include "igt_pci.h"
#include "igt_sriov_device.h"
#include "intel_chipset.h"
#include "intel_vram.h"
#include "linux_scaffold.h"
#include "xe/xe_mmio.h"
#include "xe/xe_query.h"
#include "xe/xe_sriov_provisioning.h"
#include "xe/xe_sriov_debugfs.h"
/**
* TEST: xe_sriov_flr
* Category: Core
* Mega feature: SR-IOV
* Sub-category: SR-IOV Reset tests
* Functionality: FLR
* Description: Examine behavior of SR-IOV VF FLR
*
* SUBTEST: flr-basic
* Run type: BAT
* Description:
* Initiates FLR without any additional state checks.
* Useful as a basic smoke test of the reset sysfs write path.
*
* SUBTEST: flr-vf1-clear
* Run type: BAT
* Description:
* Verifies that LMEM, GGTT, and SCRATCH_REGS are properly cleared
* on VF1 following a Function Level Reset (FLR).
*
* SUBTEST: flr-each-isolation
* Run type: FULL
* Description:
* Sequentially performs FLR on each VF to verify isolation and
* clearing of LMEM, GGTT, and SCRATCH_REGS on the reset VF only.
*
* SUBTEST: flr-vfs-parallel
* Run type: FULL
* Description:
* Executes FLR on all VFs simultaneously to validate correct behavior during parallel resets.
*
* SUBTEST: flr-twice
* Run type: FULL
* Description:
* Initiates FLR twice in parallel on the same VF to validate behavior
* when multiple resets occur within a short time frame, as seen in some
* real-world scenarios (e.g., when starting a QEMU VM with a passed VF).
*/
IGT_TEST_DESCRIPTION("Xe tests for SR-IOV VF FLR (Functional Level Reset)");
static const char STOP_REASON_ABORT[] = "ABORT";
static const char STOP_REASON_FAIL[] = "FAIL";
static const char STOP_REASON_SKIP[] = "SKIP";
static const char XE_VFIO_PCI_MODULE[] = "xe_vfio_pci";
#define DRIVER_OVERRIDE_TIMEOUT_MS 200
static int g_wait_flr_ms = 200;
static bool g_use_xe_vfio_pci = true;
static bool g_extended_scope;
static bool g_xe_vfio_loaded_initially;
static struct g_mmio {
struct xe_mmio *mmio;
unsigned int num_vfs;
} g_mmio;
static inline struct xe_mmio *xe_mmio_for_vf(unsigned int vf)
{
igt_assert_f(g_mmio.mmio, "MMIO not initialized\n");
igt_assert_f(vf <= g_mmio.num_vfs, "VF%u out of range (<= %u)\n", vf,
g_mmio.num_vfs);
return &g_mmio.mmio[vf];
}
static void init_mmio(int pf_fd, unsigned int num_vfs)
{
igt_assert_f(!g_mmio.mmio, "MMIO already initialized\n");
g_mmio.mmio = calloc(num_vfs + 1, sizeof(*g_mmio.mmio));
igt_assert(g_mmio.mmio);
for (unsigned int i = 0; i <= num_vfs; ++i)
xe_mmio_vf_access_init(pf_fd, i, &g_mmio.mmio[i]);
g_mmio.num_vfs = num_vfs;
}
static void cleanup_mmio(void)
{
if (!g_mmio.mmio)
return;
for (size_t i = 0; i <= g_mmio.num_vfs; ++i)
if (xe_mmio_is_initialized(&g_mmio.mmio[i]))
xe_mmio_access_fini(&g_mmio.mmio[i]);
free(g_mmio.mmio);
g_mmio.mmio = NULL;
g_mmio.num_vfs = 0;
}
/**
* struct subcheck_data - Base structure for subcheck data.
*
* This structure serves as a foundational data model for various subchecks. It is designed
* to be extended by more specific subcheck structures as needed. The structure includes
* essential information about the subcheck environment and conditions, which are used
* across different testing operations.
*
* @pf_fd: File descriptor for the Physical Function.
* @num_vfs: Number of Virtual Functions (VFs) enabled and under test. This count is
* used to iterate over and manage the VFs during the testing process.
* @tile: Tile under test.
* @stop_reason: Pointer to a string that indicates why a subcheck should skip or fail.
* This field is crucial for controlling the flow of subcheck execution.
* If set, it should prevent further execution of the current subcheck,
* allowing subcheck operations to check this field and return early if
* a skip or failure condition is indicated. This mechanism ensures
* that while one subcheck may stop due to a failure or a skip condition,
* other subchecks can continue execution.
*
* Example usage:
* A typical use of this structure involves initializing it with the necessary test setup
* parameters, checking the `stop_reason` field before proceeding with each subcheck operation,
* and using `pf_fd`, `num_vfs`, and `tile` as needed based on the specific subcheck requirements.
*/
struct subcheck_data {
int pf_fd;
int num_vfs;
uint8_t tile;
char *stop_reason;
};
/**
* struct subcheck - Defines operations for managing a subcheck scenario.
*
* This structure holds function pointers for the key operations required
* to manage the lifecycle of a subcheck scenario. It is used by the `verify_flr`
* function, which acts as a template method, to call these operations in a
* specific sequence.
*
* @data: Shared data necessary for all operations in the subcheck.
*
* @name: Name of the subcheck operation, used for identification and reporting.
*
* @init: Initialize the subcheck environment.
* Sets up the initial state required for the subcheck, including preparing
* resources and ensuring the system is ready for testing.
* @param data: Shared data needed for initialization.
*
* @prepare_vf: Prepare subcheck data for a specific VF.
* Called for each VF before FLR is performed. It might involve marking
* specific memory regions or setting up PTE addresses.
* @param vf_id: Identifier of the VF being prepared.
* @param data: Shared common data.
*
* @verify_vf: Verify the state of a VF after FLR.
* Checks the VF's state post FLR to ensure the expected results,
* such as verifying that only the FLRed VF has its state reset.
* @param vf_id: Identifier of the VF to verify.
* @param flr_vf_id: Identifier of the VF that underwent FLR.
* @param data: Shared common data.
*
* @cleanup: Clean up the subcheck environment.
* Releases resources and restores the system to its original state
* after the subchecks, ensuring no resource leaks and preparing the system
* for subsequent tests.
* @param data: Shared common data.
*/
struct subcheck {
struct subcheck_data *data;
const char *name;
void (*init)(struct subcheck_data *data);
void (*prepare_vf)(int vf_id, struct subcheck_data *data);
void (*verify_vf)(int vf_id, int flr_vf_id, struct subcheck_data *data);
void (*cleanup)(struct subcheck_data *data);
};
__attribute__((format(printf, 3, 0)))
static void set_stop_reason_v(struct subcheck_data *data, const char *prefix,
const char *format, va_list args)
{
char *formatted_message;
int result;
if (igt_warn_on_f(data->stop_reason, "Stop reason already set\n"))
return;
result = vasprintf(&formatted_message, format, args);
igt_assert_neq(result, -1);
result = asprintf(&data->stop_reason, "%s : %s", prefix,
formatted_message);
igt_assert_neq(result, -1);
free(formatted_message);
}
__attribute__((format(printf, 2, 3)))
static void set_skip_reason(struct subcheck_data *data, const char *format, ...)
{
va_list args;
va_start(args, format);
set_stop_reason_v(data, STOP_REASON_SKIP, format, args);
va_end(args);
}
__attribute__((format(printf, 2, 3)))
static void set_fail_reason(struct subcheck_data *data, const char *format, ...)
{
va_list args;
va_start(args, format);
set_stop_reason_v(data, STOP_REASON_FAIL, format, args);
va_end(args);
}
__attribute__((format(printf, 2, 3)))
static void set_abort_reason(struct subcheck_data *data, const char *format, ...)
{
va_list args;
va_start(args, format);
set_stop_reason_v(data, STOP_REASON_ABORT, format, args);
va_end(args);
}
static bool subcheck_can_proceed(const struct subcheck *check)
{
return !check->data->stop_reason;
}
static int count_subchecks_with_stop_reason(struct subcheck *checks, int num_checks)
{
int subchecks_with_stop_reason = 0;
for (int i = 0; i < num_checks; ++i)
if (!subcheck_can_proceed(&checks[i]))
subchecks_with_stop_reason++;
return subchecks_with_stop_reason;
}
static bool no_subchecks_can_proceed(struct subcheck *checks, int num_checks)
{
return count_subchecks_with_stop_reason(checks, num_checks) == num_checks;
}
static bool is_subcheck_skipped(struct subcheck *subcheck)
{
return subcheck->data && subcheck->data->stop_reason &&
!strncmp(STOP_REASON_SKIP, subcheck->data->stop_reason, strlen(STOP_REASON_SKIP));
}
static void subchecks_report_results(struct subcheck *checks, int num_checks)
{
int fails = 0, skips = 0;
for (int i = 0; i < num_checks; ++i) {
if (checks[i].data->stop_reason) {
if (is_subcheck_skipped(&checks[i])) {
igt_info("%s: Tile%u: %s\n", checks[i].name,
checks[i].data->tile,
checks[i].data->stop_reason);
skips++;
} else {
igt_critical("%s: Tile%u: %s\n", checks[i].name,
checks[i].data->tile,
checks[i].data->stop_reason);
fails++;
}
} else {
igt_info("%s: Tile%u: SUCCESS\n", checks[i].name,
checks[i].data->tile);
}
}
igt_fail_on_f(fails, "%d out of %d checks failed\n", fails, num_checks);
igt_skip_on(skips == num_checks);
}
static bool vf_bind_driver_override(int pf_fd, unsigned int vf_id,
const char *driver)
{
char *slot = igt_sriov_get_vf_pci_slot_alloc(pf_fd, vf_id);
int ret;
char bound[64] = "none";
int bound_ret;
igt_assert(slot);
igt_assert(driver);
ret = igt_pci_bind_driver_override(slot, driver, DRIVER_OVERRIDE_TIMEOUT_MS);
if (ret < 0) {
bound_ret = igt_pci_get_bound_driver_name(slot, bound, sizeof(bound));
if (bound_ret <= 0)
snprintf(bound, sizeof(bound), "%s", "none");
igt_warn_on_f(true,
"bind %s (VF%u) to %s ret=%d (currently bound: %s)\n",
slot, vf_id, driver, ret, bound);
}
free(slot);
return ret >= 0;
}
static void vf_unbind_driver_override(int pf_fd, unsigned int vf_id)
{
char *slot = igt_sriov_get_vf_pci_slot_alloc(pf_fd, vf_id);
int ret;
igt_assert(slot);
ret = igt_pci_unbind_driver_override(slot, DRIVER_OVERRIDE_TIMEOUT_MS);
igt_warn_on_f(ret < 0, "unbind %s (VF%u) driver_override ret=%d\n",
slot, vf_id, ret);
free(slot);
}
static bool __restore_xe_vfio_module_state(void)
{
bool loaded = igt_kmod_is_loaded(XE_VFIO_PCI_MODULE);
int ret;
if (loaded == g_xe_vfio_loaded_initially)
return true;
ret = g_xe_vfio_loaded_initially ?
igt_kmod_load(XE_VFIO_PCI_MODULE, NULL) :
igt_kmod_unload(XE_VFIO_PCI_MODULE);
if (ret)
return false;
loaded = igt_kmod_is_loaded(XE_VFIO_PCI_MODULE);
return loaded == g_xe_vfio_loaded_initially;
}
static void restore_xe_vfio_module_or_abort(void)
{
igt_abort_on_f(!__restore_xe_vfio_module_state(),
"Failed to restore %s to %s during cleanup\n",
XE_VFIO_PCI_MODULE,
g_xe_vfio_loaded_initially ? "loaded" : "unloaded");
}
static void restore_xe_vfio_module_best_effort(void)
{
igt_warn_on_f(!__restore_xe_vfio_module_state(),
"Failed to restore %s to %s during exit cleanup\n",
XE_VFIO_PCI_MODULE,
g_xe_vfio_loaded_initially ? "loaded" : "unloaded");
}
static void exit_cleanup(int pf_fd, int sig, void *data)
{
(void)pf_fd;
(void)sig;
(void)data;
restore_xe_vfio_module_best_effort();
}
/**
* flr_exec_strategy - Function pointer for FLR execution strategy
* @pf_fd: File descriptor for the Physical Function (PF).
* @num_vfs: Total number of Virtual Functions (VFs) to test.
* @checks: Array of subchecks.
* @num_checks: Number of subchecks.
* @wait_flr_ms: Time to wait (in milliseconds) for FLR to complete
*
* Defines a strategy for executing FLRs (Functional Level Resets)
* across multiple VFs. The strategy determines the order and
* manner (e.g., sequential or parallel) in which FLRs are performed.
* It is expected to initiate FLRs and handle related operations,
* such as verifying and preparing subchecks.
*
* Return: The ID of the last VF for which FLR was successfully initiated.
*/
typedef int (*flr_exec_strategy)(int pf_fd, int num_vfs,
struct subcheck *checks, int num_checks,
const int wait_flr_ms);
/**
* verify_flr - Orchestrates the verification of Function Level Reset (FLR)
* across multiple Virtual Functions (VFs).
*
* This function performs FLR on each VF to ensure that only the reset VF has
* its state cleared, while other VFs remain unaffected. It handles initialization,
* preparation, verification, and cleanup for each test operation defined in `checks`.
*
* @pf_fd: File descriptor for the Physical Function (PF).
* @num_vfs: Total number of Virtual Functions (VFs) to test.
* @checks: Array of subchecks.
* @num_checks: Number of subchecks.
* @flr_exec_strategy: Execution strategy for FLR (e.g., sequential or parallel).
*
* Detailed Workflow:
* - Initializes and prepares VFs for testing.
* - Executes the FLR operation using the provided execution strategy
* (e.g., sequential or parallel) and validates that the reset VF behaves
* as expected.
* - Cleans up resources and reports results after all VFs have been tested
* or in the case of an early exit.
*
* A timeout is used to wait for FLR operations to complete.
*/
static void verify_flr(int pf_fd, int num_vfs, struct subcheck *checks,
int num_checks, flr_exec_strategy exec_strategy)
{
const int wait_flr_ms = g_wait_flr_ms;
int i, vf_id, flr_vf_id = -1;
bool xe_vfio_loaded;
bool *vf_bound = NULL;
igt_sriov_disable_driver_autoprobe(pf_fd);
igt_sriov_enable_vfs(pf_fd, num_vfs);
if (igt_warn_on(!igt_sriov_device_reset_exists(pf_fd, 1)))
goto disable_vfs;
/* Refresh PCI state */
if (igt_warn_on(igt_pci_system_reinit()))
goto disable_vfs;
xe_vfio_loaded = false;
if (g_use_xe_vfio_pci)
xe_vfio_loaded = igt_kmod_load(XE_VFIO_PCI_MODULE, NULL) >= 0;
if (xe_vfio_loaded) {
vf_bound = calloc(num_vfs + 1, sizeof(*vf_bound));
igt_assert(vf_bound);
igt_sriov_enable_driver_autoprobe(pf_fd);
for (vf_id = 1; vf_id <= num_vfs; vf_id++)
vf_bound[vf_id] = vf_bind_driver_override(pf_fd, vf_id, "xe-vfio-pci");
}
init_mmio(pf_fd, num_vfs);
for (i = 0; i < num_checks; ++i)
checks[i].init(checks[i].data);
for (vf_id = 1; vf_id <= num_vfs; ++vf_id)
for (i = 0; i < num_checks; ++i)
if (subcheck_can_proceed(&checks[i]))
checks[i].prepare_vf(vf_id, checks[i].data);
if (no_subchecks_can_proceed(checks, num_checks))
goto cleanup;
/* Execute the chosen FLR strategy */
flr_vf_id = exec_strategy(pf_fd, num_vfs, checks, num_checks, wait_flr_ms);
cleanup:
for (i = 0; i < num_checks; ++i)
checks[i].cleanup(checks[i].data);
cleanup_mmio();
if (xe_vfio_loaded) {
for (vf_id = 1; vf_id <= num_vfs; vf_id++)
if (vf_bound && vf_bound[vf_id])
vf_unbind_driver_override(pf_fd, vf_id);
}
free(vf_bound);
disable_vfs:
igt_sriov_disable_vfs(pf_fd);
if (flr_vf_id > 0 || no_subchecks_can_proceed(checks, num_checks))
subchecks_report_results(checks, num_checks);
else
igt_skip("No checks executed\n");
}
static int execute_sequential_flr(int pf_fd, int num_vfs,
struct subcheck *checks, int num_checks,
const int wait_flr_ms)
{
int i, vf_id, flr_vf_id = 1;
do {
if (igt_warn_on_f(!igt_sriov_device_reset(pf_fd, flr_vf_id),
"Initiating VF%u FLR failed\n", flr_vf_id))
break;
/* Assume FLR is finished after wait_flr_ms */
usleep(wait_flr_ms * 1000);
for (vf_id = 1; vf_id <= num_vfs; ++vf_id)
for (i = 0; i < num_checks; ++i)
if (subcheck_can_proceed(&checks[i]))
checks[i].verify_vf(vf_id, flr_vf_id, checks[i].data);
/* Reinitialize test data for the FLRed VF */
if (flr_vf_id < num_vfs)
for (i = 0; i < num_checks; ++i)
if (subcheck_can_proceed(&checks[i]))
checks[i].prepare_vf(flr_vf_id, checks[i].data);
if (no_subchecks_can_proceed(checks, num_checks))
break;
} while (++flr_vf_id <= num_vfs);
return flr_vf_id - 1;
}
pthread_mutex_t signal_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t signal_cond = PTHREAD_COND_INITIALIZER;
enum thread_signal {
SIGNAL_WAIT,
SIGNAL_START,
SIGNAL_SKIP
} thread_signal = SIGNAL_WAIT;
struct flr_thread_data {
int pf_fd;
int vf_id;
int flr_instance;
int result;
};
static void *flr_thread(void *arg)
{
struct flr_thread_data *data = (struct flr_thread_data *)arg;
pthread_mutex_lock(&signal_mutex);
while (thread_signal == SIGNAL_WAIT)
pthread_cond_wait(&signal_cond, &signal_mutex);
pthread_mutex_unlock(&signal_mutex);
if (thread_signal == SIGNAL_START &&
igt_warn_on_f(!igt_sriov_device_reset(data->pf_fd, data->vf_id),
"Initiating VF%u FLR failed (flr_instance=%u)\n",
data->vf_id, data->flr_instance))
data->result = -1;
return NULL;
}
static int execute_parallel_flr_(int pf_fd, int num_vfs,
struct subcheck *checks,
int num_checks, const int wait_flr_ms,
unsigned int num_flrs_per_vf)
{
const unsigned int total_flrs = num_vfs * num_flrs_per_vf;
pthread_t threads[total_flrs];
struct flr_thread_data thread_data[total_flrs];
int vf_id = 0, last_vf_id = 0;
int i, j, k, created_threads = 0;
igt_assert(total_flrs > 0);
for (i = 0; i < num_vfs; ++i) {
for (j = 0; j < num_flrs_per_vf; ++j) {
thread_data[created_threads].pf_fd = pf_fd;
thread_data[created_threads].vf_id = i + 1; // VF IDs are 1-based
thread_data[created_threads].flr_instance = j;
thread_data[created_threads].result = 0;
if (pthread_create(&threads[created_threads], NULL,
flr_thread,
&thread_data[created_threads])) {
last_vf_id = i + 1;
goto cleanup_threads;
} else {
created_threads++;
}
}
}
cleanup_threads:
pthread_mutex_lock(&signal_mutex);
thread_signal = (created_threads == total_flrs) ? SIGNAL_START :
SIGNAL_SKIP;
pthread_cond_broadcast(&signal_cond);
pthread_mutex_unlock(&signal_mutex);
for (i = 0; i < created_threads; ++i)
pthread_join(threads[i], NULL);
if (last_vf_id) {
for (k = 0; k < num_checks; ++k)
set_skip_reason(checks[k].data,
"Thread creation failed for VF%u\n", last_vf_id);
return 0;
}
/* Assume FLRs finished after wait_flr_ms */
usleep(wait_flr_ms * 1000);
/* Verify results */
for (i = 0; i < created_threads; ++i) {
vf_id = thread_data[i].vf_id;
/* Skip already checked VF or if the FLR initiation failed */
if (vf_id == last_vf_id || thread_data[i].result != 0)
continue;
for (k = 0; k < num_checks; ++k)
if (subcheck_can_proceed(&checks[k]))
checks[k].verify_vf(vf_id, vf_id, checks[k].data);
if (no_subchecks_can_proceed(checks, num_checks))
break;
last_vf_id = vf_id;
}
return last_vf_id;
}
static int execute_parallel_flr(int pf_fd, int num_vfs, struct subcheck *checks,
int num_checks, const int wait_flr_ms)
{
return execute_parallel_flr_(pf_fd, num_vfs, checks, num_checks,
wait_flr_ms, 1);
}
static int execute_parallel_flr_twice(int pf_fd, int num_vfs,
struct subcheck *checks, int num_checks,
const int wait_flr_ms)
{
return execute_parallel_flr_(pf_fd, num_vfs, checks, num_checks,
wait_flr_ms, 2);
}
#define GEN12_VF_CAP_REG 0x1901f8
#define GGTT_PTE_TEST_FIELD_MASK GENMASK_ULL(19, 12)
#define GGTT_PTE_ADDR_SHIFT 12
struct ggtt_ops {
void (*set_pte)(struct xe_mmio *mmio, uint8_t tile, uint32_t pte_offset, xe_ggtt_pte_t pte);
xe_ggtt_pte_t (*get_pte)(struct xe_mmio *mmio, uint8_t tile, uint32_t pte_offset);
};
struct ggtt_provisioned_offset_range {
uint32_t start;
uint32_t end;
};
#define for_each_pte_offset(pte_offset__, ggtt_offset_range__) \
for ((pte_offset__) = ((ggtt_offset_range__)->start); \
(pte_offset__) <= ((ggtt_offset_range__)->end); \
(pte_offset__) += sizeof(xe_ggtt_pte_t))
struct ggtt_data {
struct subcheck_data base;
struct ggtt_provisioned_offset_range *pte_offsets;
struct ggtt_ops ggtt;
};
static xe_ggtt_pte_t intel_get_pte(struct xe_mmio *mmio, uint8_t tile, uint32_t pte_offset)
{
return xe_mmio_ggtt_read(mmio, tile, pte_offset);
}
static void intel_set_pte(struct xe_mmio *mmio, uint8_t tile,
uint32_t pte_offset, xe_ggtt_pte_t pte)
{
xe_mmio_ggtt_write(mmio, tile, pte_offset, pte);
}
static void intel_mtl_set_pte(struct xe_mmio *mmio, uint8_t tile,
uint32_t pte_offset, xe_ggtt_pte_t pte)
{
xe_mmio_ggtt_write(mmio, tile, pte_offset, pte);
/* force flush by read some MMIO register */
xe_mmio_tile_read32(mmio, tile, GEN12_VF_CAP_REG);
}
static bool set_pte_gpa(struct ggtt_ops *ggtt, struct xe_mmio *mmio, uint8_t tile,
uint32_t pte_offset, uint8_t gpa, xe_ggtt_pte_t *out)
{
xe_ggtt_pte_t pte;
pte = ggtt->get_pte(mmio, tile, pte_offset);
pte &= ~GGTT_PTE_TEST_FIELD_MASK;
pte |= ((xe_ggtt_pte_t)gpa << GGTT_PTE_ADDR_SHIFT) & GGTT_PTE_TEST_FIELD_MASK;
ggtt->set_pte(mmio, tile, pte_offset, pte);
*out = ggtt->get_pte(mmio, tile, pte_offset);
return *out == pte;
}
static bool check_pte_gpa(struct ggtt_ops *ggtt, struct xe_mmio *mmio, uint8_t tile,
uint32_t pte_offset, uint8_t expected_gpa, xe_ggtt_pte_t *out)
{
uint8_t val;
*out = ggtt->get_pte(mmio, tile, pte_offset);
val = (uint8_t)((*out & GGTT_PTE_TEST_FIELD_MASK) >> GGTT_PTE_ADDR_SHIFT);
return val == expected_gpa;
}
static int populate_ggtt_pte_offsets(struct ggtt_data *gdata)
{
int ret, pf_fd = gdata->base.pf_fd, num_vfs = gdata->base.num_vfs;
struct xe_sriov_provisioned_range *ranges;
uint8_t tile = gdata->base.tile;
unsigned int nr_ranges;
struct xe_mmio *mmio = xe_mmio_for_vf(0);
gdata->pte_offsets = calloc(num_vfs + 1, sizeof(*gdata->pte_offsets));
igt_assert(gdata->pte_offsets);
ret = xe_sriov_find_ggtt_provisioned_pte_offsets(pf_fd, tile, mmio,
&ranges, &nr_ranges);
if (ret) {
set_abort_reason(&gdata->base, "Failed to scan GGTT PTE offset ranges (%d)\n",
ret);
return -1;
}
for (unsigned int i = 0; i < nr_ranges; ++i) {
const unsigned int vf_id = ranges[i].vf_id;
if (vf_id == 0)
continue;
if (vf_id < 1 || vf_id > num_vfs) {
set_abort_reason(&gdata->base,
"Unexpected VF%u at range entry %u [%#" PRIx64
"-%#" PRIx64 "], num_vfs=%u\n",
vf_id, i, ranges[i].start, ranges[i].end, num_vfs);
free(ranges);
return -1;
}
if (gdata->pte_offsets[vf_id].end) {
set_abort_reason(&gdata->base, "Duplicate GGTT PTE offset range for VF%u\n",
vf_id);
free(ranges);
return -1;
}
gdata->pte_offsets[vf_id].start = ranges[i].start;
gdata->pte_offsets[vf_id].end = ranges[i].end;
}
free(ranges);
for (int vf_id = 1; vf_id <= num_vfs; ++vf_id)
if (!gdata->pte_offsets[vf_id].end) {
set_abort_reason(&gdata->base,
"Failed to find VF%u provisioned GGTT PTE offset range\n",
vf_id);
return -1;
}
return 0;
}
static void ggtt_subcheck_init(struct subcheck_data *data)
{
struct ggtt_data *gdata = (struct ggtt_data *)data;
gdata->ggtt.get_pte = intel_get_pte;
if (IS_METEORLAKE(intel_get_drm_devid(data->pf_fd)))
gdata->ggtt.set_pte = intel_mtl_set_pte;
else
gdata->ggtt.set_pte = intel_set_pte;
if (populate_ggtt_pte_offsets(gdata))
/* skip reason set in populate_ggtt_pte_offsets */
return;
}
static void ggtt_subcheck_prepare_vf(int vf_id, struct subcheck_data *data)
{
struct ggtt_data *gdata = (struct ggtt_data *)data;
struct xe_mmio *mmio = xe_mmio_for_vf(0);
xe_ggtt_pte_t pte;
uint32_t pte_offset;
if (data->stop_reason)
return;
igt_debug("Tile%u: Prepare gpa on VF%u offset range [%#x-%#x]\n",
gdata->base.tile, vf_id,
gdata->pte_offsets[vf_id].start,
gdata->pte_offsets[vf_id].end);
for_each_pte_offset(pte_offset, &gdata->pte_offsets[vf_id]) {
if (!set_pte_gpa(&gdata->ggtt, mmio, data->tile, pte_offset,
(uint8_t)vf_id, &pte)) {
set_abort_reason(data,
"Prepare VF%u failed, unexpected gpa: Read PTE: %#" PRIx64 " at offset: %#x\n",
vf_id, pte, pte_offset);
return;
}
}
}
static void ggtt_subcheck_verify_vf(int vf_id, int flr_vf_id, struct subcheck_data *data)
{
struct ggtt_data *gdata = (struct ggtt_data *)data;
uint8_t expected = (vf_id == flr_vf_id) ? 0 : vf_id;
struct xe_mmio *mmio = xe_mmio_for_vf(0);
xe_ggtt_pte_t pte;
uint32_t pte_offset;
if (data->stop_reason)
return;
for_each_pte_offset(pte_offset, &gdata->pte_offsets[vf_id]) {
if (!check_pte_gpa(&gdata->ggtt, mmio, data->tile, pte_offset,
expected, &pte)) {
set_fail_reason(data,
"GGTT check after VF%u FLR failed on VF%u: Read PTE: %#" PRIx64 " at offset: %#x\n",
flr_vf_id, vf_id, pte, pte_offset);
return;
}
}
}
static void ggtt_subcheck_cleanup(struct subcheck_data *data)
{
struct ggtt_data *gdata = (struct ggtt_data *)data;
free(gdata->pte_offsets);
}
struct lmem_data {
struct subcheck_data base;
size_t *vf_lmem_size;
};
const size_t STEP = SZ_1M;
static bool lmem_write_pattern(struct vram_mapping *m, uint8_t value, size_t start, size_t step)
{
uint8_t read;
for (; start < m->size; start += step) {
read = intel_vram_write_readback8(m, start, value);
if (igt_debug_on_f(read != value, "LMEM[%zu]=%u != %u\n", start, read, value))
return false;
}
return true;
}
static bool lmem_contains_expected_values_(struct vram_mapping *m,
uint8_t expected, size_t start,
size_t step)
{
uint8_t read;
for (; start < m->size; start += step) {
read = intel_vram_read8(m, start);
if (igt_debug_on_f(read != expected,
"LMEM[%zu]=%u != %u\n", start, read, expected))
return false;
}
return true;
}
static bool lmem_contains_expected_values(int pf_fd, int vf_num, size_t length,
char expected)
{
struct vram_mapping vram;
bool result;
if (igt_debug_on(intel_vram_mmap(pf_fd, vf_num, 0, length, PROT_READ | PROT_WRITE, &vram)))
return false;
result = lmem_contains_expected_values_(&vram, expected, 0, STEP);
intel_vram_munmap(&vram);
return result;
}
static bool lmem_mmap_write_munmap(int pf_fd, int vf_num, size_t length, char value)
{
struct vram_mapping vram;
bool result;
if (igt_debug_on(intel_vram_mmap(pf_fd, vf_num, 0, length, PROT_READ | PROT_WRITE, &vram)))
return false;
result = lmem_write_pattern(&vram, value, 0, STEP);
intel_vram_munmap(&vram);
return result;
}
static int populate_vf_lmem_sizes(struct subcheck_data *data)
{
struct lmem_data *ldata = (struct lmem_data *)data;
struct xe_sriov_provisioned_range *ranges;
unsigned int nr_ranges, main_gt;
int ret;
main_gt = xe_tile_get_main_gt_id(data->pf_fd, data->tile);
ldata->vf_lmem_size = calloc(data->num_vfs + 1, sizeof(size_t));
igt_assert(ldata->vf_lmem_size);
ret = xe_sriov_pf_debugfs_read_provisioned_ranges(data->pf_fd,
XE_SRIOV_SHARED_RES_LMEM,
main_gt, &ranges, &nr_ranges);
if (ret) {
set_abort_reason(data, "Failed read %s on main GT (%d)\n",
xe_sriov_debugfs_provisioned_attr_name(XE_SRIOV_SHARED_RES_LMEM),
ret);
return -1;
}
for (unsigned int i = 0; i < nr_ranges; ++i) {
const unsigned int vf_id = ranges[i].vf_id;
igt_assert(vf_id >= 1 && vf_id <= data->num_vfs);
/* Sum the allocation for vf_id (inclusive range) */
ldata->vf_lmem_size[vf_id] += ranges[i].end - ranges[i].start + 1;
}
free(ranges);
for (int vf_id = 1; vf_id <= data->num_vfs; ++vf_id)
if (!ldata->vf_lmem_size[vf_id]) {
set_abort_reason(data, "No LMEM provisioned for VF%u\n", vf_id);
return -1;
}
return 0;
}
static void lmem_subcheck_init(struct subcheck_data *data)
{
igt_assert_fd(data->pf_fd);
igt_assert(data->num_vfs);
if (!xe_has_vram(data->pf_fd)) {
set_skip_reason(data, "No LMEM\n");
return;
}
if (populate_vf_lmem_sizes(data))
/* skip reason set in populate_vf_lmem_sizes */
return;
}
static void lmem_subcheck_prepare_vf(int vf_id, struct subcheck_data *data)
{
struct lmem_data *ldata = (struct lmem_data *)data;
if (data->stop_reason)
return;
igt_assert(vf_id > 0 && vf_id <= data->num_vfs);
if (!lmem_mmap_write_munmap(data->pf_fd, vf_id,
ldata->vf_lmem_size[vf_id], vf_id)) {
set_abort_reason(data, "LMEM write failed on VF%u\n", vf_id);
}
}
static void lmem_subcheck_verify_vf(int vf_id, int flr_vf_id, struct subcheck_data *data)
{
struct lmem_data *ldata = (struct lmem_data *)data;
char expected = (vf_id == flr_vf_id) ? 0 : vf_id;
if (data->stop_reason)
return;
if (!lmem_contains_expected_values(data->pf_fd, vf_id,
ldata->vf_lmem_size[vf_id], expected)) {
set_fail_reason(data,
"LMEM check after VF%u FLR failed on VF%u\n",
flr_vf_id, vf_id);
}
}
static void lmem_subcheck_cleanup(struct subcheck_data *data)
{
struct lmem_data *ldata = (struct lmem_data *)data;
free(ldata->vf_lmem_size);
}
#define SCRATCH_REG 0x190240
#define SCRATCH_REG_COUNT 4
#define MED_SCRATCH_REG 0x190310
#define MED_SCRATCH_REG_COUNT 4
struct regs_data {
struct subcheck_data base;
uint32_t reg_addr;
int reg_count;
};
static void regs_subcheck_init(struct subcheck_data *data)
{
struct regs_data *rdata = (struct regs_data *)data;
if (!xe_has_media_gt(data->pf_fd) &&
rdata->reg_addr == MED_SCRATCH_REG) {
set_skip_reason(data, "No media GT\n");
}
}
static void regs_subcheck_prepare_vf(int vf_id, struct subcheck_data *data)
{
struct regs_data *rdata = (struct regs_data *)data;
struct xe_mmio *mmio = xe_mmio_for_vf(vf_id);
uint8_t tile = data->tile;
uint32_t reg;
int i;
if (data->stop_reason)
return;
for (i = 0; i < rdata->reg_count; i++) {
reg = rdata->reg_addr + i * 4;
xe_mmio_tile_write32(mmio, tile, reg, vf_id);
if (xe_mmio_tile_read32(mmio, tile, reg) != vf_id) {
set_abort_reason(data, "Registers write/read check failed on VF%u\n",
vf_id);
return;
}
}
}
static void regs_subcheck_verify_vf(int vf_id, int flr_vf_id, struct subcheck_data *data)
{
struct regs_data *rdata = (struct regs_data *)data;
uint32_t expected = (vf_id == flr_vf_id) ? 0 : vf_id;
struct xe_mmio *mmio = xe_mmio_for_vf(vf_id);
uint32_t reg;
int i;
if (data->stop_reason)
return;
for (i = 0; i < rdata->reg_count; i++) {
reg = rdata->reg_addr + i * 4;
if (xe_mmio_tile_read32(mmio, data->tile, reg) != expected) {
set_fail_reason(data,
"Registers check after VF%u FLR failed on VF%u\n",
flr_vf_id, vf_id);
return;
}
}
}
static void regs_subcheck_cleanup(struct subcheck_data *data)
{
}
static void reset_only_subcheck_init(struct subcheck_data *data)
{
if (!g_use_xe_vfio_pci) {
set_skip_reason(data, "xe-vfio-pci binding is disabled\n");
return;
}
if (!igt_kmod_is_loaded(XE_VFIO_PCI_MODULE))
set_skip_reason(data, "xe_vfio_pci is not loaded\n");
}
static void reset_only_subcheck_prepare_vf(int vf_id, struct subcheck_data *data)
{
char *slot = igt_sriov_get_vf_pci_slot_alloc(data->pf_fd, vf_id);
char bound[64];
int bound_ret;
igt_assert(slot);
bound_ret = igt_pci_get_bound_driver_name(slot, bound, sizeof(bound));
if (bound_ret <= 0 || strcmp(bound, "xe-vfio-pci") != 0)
set_skip_reason(data, "VF%u not bound to xe-vfio-pci\n", vf_id);
free(slot);
}
static void noop_subcheck_verify_vf(int vf_id, int flr_vf_id, struct subcheck_data *data)
{
}
static void noop_subcheck_cleanup(struct subcheck_data *data)
{
}
static void reset_only_test(int pf_fd, int num_vfs, flr_exec_strategy exec_strategy)
{
struct subcheck_data base = {
.pf_fd = pf_fd,
.num_vfs = num_vfs,
.tile = 0,
.stop_reason = NULL,
};
struct subcheck check = {
.data = &base,
.name = "reset-only",
.init = reset_only_subcheck_init,
.prepare_vf = reset_only_subcheck_prepare_vf,
.verify_vf = noop_subcheck_verify_vf,
.cleanup = noop_subcheck_cleanup,
};
verify_flr(pf_fd, num_vfs, &check, 1, exec_strategy);
}
static void clear_tests(int pf_fd, int num_vfs, flr_exec_strategy exec_strategy)
{
const uint8_t num_tiles = xe_tiles_count(pf_fd);
struct subcheck_data base;
struct ggtt_data gdata[num_tiles];
struct lmem_data ldata[num_tiles];
struct regs_data scratch_data[num_tiles];
struct regs_data media_scratch_data[num_tiles];
const unsigned int subcheck_count = 4;
const unsigned int num_checks = subcheck_count * num_tiles;
struct subcheck checks[num_checks];
unsigned int i = 0, t;
xe_for_each_tile(pf_fd, t) {
igt_assert_lt(i, num_tiles);
base = (struct subcheck_data){ .pf_fd = pf_fd,
.num_vfs = num_vfs,
.tile = t };
gdata[i] = (struct ggtt_data){
.base = base,
};
checks[i * subcheck_count + 0] = (struct subcheck){
.data = (struct subcheck_data *)&gdata[i],
.name = "clear-ggtt",
.init = ggtt_subcheck_init,
.prepare_vf = ggtt_subcheck_prepare_vf,
.verify_vf = ggtt_subcheck_verify_vf,
.cleanup = ggtt_subcheck_cleanup
};
ldata[i] = (struct lmem_data){
.base = base,
};
checks[i * subcheck_count + 1] = (struct subcheck){
.data = (struct subcheck_data *)&ldata[i],
.name = "clear-lmem",
.init = lmem_subcheck_init,
.prepare_vf = lmem_subcheck_prepare_vf,
.verify_vf = lmem_subcheck_verify_vf,
.cleanup = lmem_subcheck_cleanup
};
scratch_data[i] = (struct regs_data){
.base = base,
.reg_addr = SCRATCH_REG,
.reg_count = SCRATCH_REG_COUNT,
};
checks[i * subcheck_count + 2] = (struct subcheck){
.data = (struct subcheck_data *)&scratch_data[i],
.name = "clear-scratch-regs",
.init = regs_subcheck_init,
.prepare_vf = regs_subcheck_prepare_vf,
.verify_vf = regs_subcheck_verify_vf,
.cleanup = regs_subcheck_cleanup
};
media_scratch_data[i] = (struct regs_data){
.base = base,
.reg_addr = MED_SCRATCH_REG,
.reg_count = MED_SCRATCH_REG_COUNT,
};
checks[i * subcheck_count + 3] = (struct subcheck){
.data = (struct subcheck_data *)&media_scratch_data[i],
.name = "clear-media-scratch-regs",
.init = regs_subcheck_init,
.prepare_vf = regs_subcheck_prepare_vf,
.verify_vf = regs_subcheck_verify_vf,
.cleanup = regs_subcheck_cleanup
};
i++;
}
igt_assert_eq(i, num_tiles);
igt_assert_eq(i * subcheck_count, num_checks);
verify_flr(pf_fd, num_vfs, checks, num_checks, exec_strategy);
}
static int opt_handler(int opt, int opt_index, void *data)
{
char *end = NULL;
long val;
switch (opt) {
case 'e':
g_extended_scope = true;
break;
case 'v':
g_use_xe_vfio_pci = false;
igt_info("xe-vfio-pci binding: disabled\n");
break;
case 'w':
errno = 0;
val = strtol(optarg, &end, 0);
if (errno || !end || *end != '\0' || val < 0 || val > INT_MAX)
return IGT_OPT_HANDLER_ERROR;
g_wait_flr_ms = (int)val;
igt_info("Using wait_flr_ms=%d\n", g_wait_flr_ms);
break;
default:
return IGT_OPT_HANDLER_ERROR;
}
return IGT_OPT_HANDLER_SUCCESS;
}
static const struct option long_options[] = {
{ .name = "extended", .has_arg = false, .val = 'e', },
{ .name = "no-xe-vfio-pci", .has_arg = false, .val = 'v', },
{ .name = "wait-flr-ms", .has_arg = true, .val = 'w', },
{},
};
static const char help_str[] =
" --extended\t\tRun extended scope\n"
" --no-xe-vfio-pci\tDo not load/bind xe-vfio-pci for VFs\n"
" --wait-flr-ms=MS\tSleep MS milliseconds after VF reset sysfs write (default: 200)\n";
int igt_main_args("evw:", long_options, help_str, opt_handler, NULL)
{
int pf_fd;
bool autoprobe;
igt_fixture() {
pf_fd = drm_open_driver(DRIVER_XE);
igt_require(igt_sriov_is_pf(pf_fd));
igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);
autoprobe = igt_sriov_is_driver_autoprobe_enabled(pf_fd);
g_xe_vfio_loaded_initially = igt_kmod_is_loaded(XE_VFIO_PCI_MODULE);
igt_sriov_install_exit_handler(pf_fd, exit_cleanup, NULL);
}
igt_describe("Initiate FLR without any additional state checks.");
igt_subtest_with_dynamic("flr-basic") {
for_each_sriov_num_vfs(pf_fd, vf_num) {
if (!g_extended_scope && vf_num > 1)
break;
igt_dynamic_f("numvfs-%u", vf_num)
reset_only_test(pf_fd, vf_num, execute_sequential_flr);
}
}
igt_describe("Verify LMEM, GGTT, and SCRATCH_REGS are properly cleared after VF1 FLR");
igt_subtest("flr-vf1-clear") {
clear_tests(pf_fd, 1, execute_sequential_flr);
}
igt_describe("Perform sequential FLR on each VF, verifying that LMEM, GGTT, and SCRATCH_REGS are cleared only on the reset VF.");
igt_subtest("flr-each-isolation") {
unsigned int total_vfs = igt_sriov_get_total_vfs(pf_fd);
igt_require(total_vfs > 1);
clear_tests(pf_fd, total_vfs > 3 ? 3 : total_vfs, execute_sequential_flr);
}
igt_describe("Perform FLR on all VFs in parallel, ensuring correct behavior during simultaneous resets.");
igt_subtest("flr-vfs-parallel") {
unsigned int total_vfs = igt_sriov_get_total_vfs(pf_fd);
igt_require(total_vfs > 1);
clear_tests(pf_fd, total_vfs, execute_parallel_flr);
}
igt_describe("Initiate FLR twice in parallel on same VF.");
igt_subtest("flr-twice") {
clear_tests(pf_fd, 1, execute_parallel_flr_twice);
}
igt_fixture() {
igt_sriov_disable_vfs(pf_fd);
/* abort to avoid execution of next tests with enabled VFs */
igt_abort_on_f(igt_sriov_get_enabled_vfs(pf_fd) > 0, "Failed to disable VF(s)");
autoprobe ? igt_sriov_enable_driver_autoprobe(pf_fd) :
igt_sriov_disable_driver_autoprobe(pf_fd);
igt_abort_on_f(autoprobe != igt_sriov_is_driver_autoprobe_enabled(pf_fd),
"Failed to restore sriov_drivers_autoprobe value\n");
restore_xe_vfio_module_or_abort();
igt_sriov_clear_exit_handler();
close(pf_fd);
}
}
|