1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2018 Intel Corporation
5  */
6 
7 #include "i915_drv.h"
8 #include "gt/intel_gt.h"
9 
10 #include "../i915_selftest.h"
11 #include "igt_flush_test.h"
12 #include "igt_live_test.h"
13 
igt_live_test_begin(struct igt_live_test * t,struct drm_i915_private * i915,const char * func,const char * name)14 int igt_live_test_begin(struct igt_live_test *t,
15 			struct drm_i915_private *i915,
16 			const char *func,
17 			const char *name)
18 {
19 	struct intel_gt *gt = to_gt(i915);
20 	struct intel_engine_cs *engine;
21 	enum intel_engine_id id;
22 	int err;
23 
24 	t->i915 = i915;
25 	t->func = func;
26 	t->name = name;
27 
28 	err = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
29 	if (err) {
30 		pr_err("%s(%s): failed to idle before, with err=%d!",
31 		       func, name, err);
32 		return err;
33 	}
34 
35 	t->reset_global = i915_reset_count(&i915->gpu_error);
36 
37 	for_each_engine(engine, gt, id)
38 		t->reset_engine[id] =
39 			i915_reset_engine_count(&i915->gpu_error, engine);
40 
41 	return 0;
42 }
43 
igt_live_test_end(struct igt_live_test * t)44 int igt_live_test_end(struct igt_live_test *t)
45 {
46 	struct drm_i915_private *i915 = t->i915;
47 	struct intel_engine_cs *engine;
48 	enum intel_engine_id id;
49 
50 	if (igt_flush_test(i915))
51 		return -EIO;
52 
53 	if (t->reset_global != i915_reset_count(&i915->gpu_error)) {
54 		pr_err("%s(%s): GPU was reset %d times!\n",
55 		       t->func, t->name,
56 		       i915_reset_count(&i915->gpu_error) - t->reset_global);
57 		return -EIO;
58 	}
59 
60 	for_each_engine(engine, to_gt(i915), id) {
61 		if (t->reset_engine[id] ==
62 		    i915_reset_engine_count(&i915->gpu_error, engine))
63 			continue;
64 
65 		pr_err("%s(%s): engine '%s' was reset %d times!\n",
66 		       t->func, t->name, engine->name,
67 		       i915_reset_engine_count(&i915->gpu_error, engine) -
68 		       t->reset_engine[id]);
69 		return -EIO;
70 	}
71 
72 	return 0;
73 }
74