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 #include "gt/intel_gt_print.h"
10 
11 #include "../i915_selftest.h"
12 #include "igt_flush_test.h"
13 #include "igt_live_test.h"
14 
15 int igt_live_test_begin(struct igt_live_test *t,
16 			struct drm_i915_private *i915,
17 			const char *func,
18 			const char *name)
19 {
20 	struct intel_engine_cs *engine;
21 	enum intel_engine_id id;
22 	struct intel_gt *gt;
23 	unsigned int i;
24 	int err;
25 
26 	t->i915 = i915;
27 	t->func = func;
28 	t->name = name;
29 
30 	for_each_gt(gt, i915, i) {
31 
32 		err = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
33 		if (err) {
34 			gt_err(gt, "%s(%s): GT failed to idle before, with err=%d!",
35 			       func, name, err);
36 			return err;
37 		}
38 
39 		for_each_engine(engine, gt, id)
40 			t->reset_engine[id] =
41 			i915_reset_engine_count(&i915->gpu_error, engine);
42 	}
43 
44 	t->reset_global = i915_reset_count(&i915->gpu_error);
45 
46 	return 0;
47 }
48 
49 int igt_live_test_end(struct igt_live_test *t)
50 {
51 	struct drm_i915_private *i915 = t->i915;
52 	struct intel_engine_cs *engine;
53 	enum intel_engine_id id;
54 	struct intel_gt *gt;
55 	unsigned int i;
56 
57 	if (igt_flush_test(i915))
58 		return -EIO;
59 
60 	if (t->reset_global != i915_reset_count(&i915->gpu_error)) {
61 		pr_err("%s(%s): GPU was reset %d times!\n",
62 		       t->func, t->name,
63 		       i915_reset_count(&i915->gpu_error) - t->reset_global);
64 		return -EIO;
65 	}
66 
67 	for_each_gt(gt, i915, i) {
68 		for_each_engine(engine, gt, id) {
69 			if (t->reset_engine[id] ==
70 			    i915_reset_engine_count(&i915->gpu_error, engine))
71 				continue;
72 
73 			gt_err(gt, "%s(%s): engine '%s' was reset %d times!\n",
74 			       t->func, t->name, engine->name,
75 			       i915_reset_engine_count(&i915->gpu_error, engine) -
76 			       t->reset_engine[id]);
77 			return -EIO;
78 		}
79 	}
80 
81 	return 0;
82 }
83