summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include/nvgpu/nvgpu_err.h
blob: 0595fafb8101d489ed4e49dbd405ba612e32ca44 (plain) (blame)
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
/*
 * Copyright (c) 2021, NVIDIA CORPORATION.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef NVGPU_NVGPU_ERR_H
#define NVGPU_NVGPU_ERR_H

/**
 * @file
 *
 * Define indices for HW units and errors. Define structures used to carry error
 * information. Declare prototype for APIs that are used to report GPU HW errors
 * to the Safety_Services framework.
 */

#include <nvgpu/types.h>
#include <nvgpu/atomic.h>

struct gk20a;

/**
 * @defgroup INDICES_FOR_GPU_HW_UNITS
 * Macros used to assign unique index to GPU HW units.
 * @{
 */
#define NVGPU_ERR_MODULE_SM			(0U)
#define NVGPU_ERR_MODULE_FECS		(1U)
#define NVGPU_ERR_MODULE_PMU		(2U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_SM
 * Macros used to assign unique index to errors reported from the SM unit.
 * @{
 */
#define GPU_SM_L1_TAG_ECC_CORRECTED			(0U)
#define GPU_SM_L1_TAG_ECC_UNCORRECTED			(1U)
#define GPU_SM_CBU_ECC_UNCORRECTED			(3U)
#define GPU_SM_LRF_ECC_UNCORRECTED			(5U)
#define GPU_SM_L1_DATA_ECC_UNCORRECTED			(7U)
#define GPU_SM_ICACHE_L0_DATA_ECC_UNCORRECTED		(9U)
#define GPU_SM_ICACHE_L1_DATA_ECC_UNCORRECTED		(11U)
#define GPU_SM_ICACHE_L0_PREDECODE_ECC_UNCORRECTED	(13U)
#define GPU_SM_L1_TAG_MISS_FIFO_ECC_UNCORRECTED		(15U)
#define GPU_SM_L1_TAG_S2R_PIXPRF_ECC_UNCORRECTED	(17U)
#define GPU_SM_ICACHE_L1_PREDECODE_ECC_UNCORRECTED	(20U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_FECS
 * Macros used to assign unique index to errors reported from the FECS unit.
 * @{
 */
#define GPU_FECS_FALCON_IMEM_ECC_CORRECTED	(0U)
#define GPU_FECS_FALCON_IMEM_ECC_UNCORRECTED	(1U)
#define GPU_FECS_FALCON_DMEM_ECC_UNCORRECTED	(3U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_GPCCS
 * Macros used to assign unique index to errors reported from the GPCCS unit.
 * @{
 */
#define GPU_GPCCS_FALCON_IMEM_ECC_CORRECTED	(0U)
#define GPU_GPCCS_FALCON_IMEM_ECC_UNCORRECTED	(1U)
#define GPU_GPCCS_FALCON_DMEM_ECC_UNCORRECTED	(3U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_MMU
 * Macros used to assign unique index to errors reported from the MMU unit.
 * @{
 */
#define GPU_MMU_L1TLB_SA_DATA_ECC_UNCORRECTED	(1U)
#define GPU_MMU_L1TLB_FA_DATA_ECC_UNCORRECTED	(3U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_GCC
 * Macros used to assign unique index to errors reported from the GCC unit.
 * @{
 */
#define GPU_GCC_L15_ECC_UNCORRECTED		(1U)
/**
 * @}
 */


/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_PMU
 * Macros used to assign unique index to errors reported from the PMU unit.
 * @{
 */
#define GPU_PMU_FALCON_IMEM_ECC_CORRECTED	(0U)
#define GPU_PMU_FALCON_IMEM_ECC_UNCORRECTED	(1U)
#define GPU_PMU_FALCON_DMEM_ECC_UNCORRECTED	(3U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_LTC
 * Macros used to assign unique index to errors reported from the LTC unit.
 * @{
 */
#define GPU_LTC_CACHE_DSTG_ECC_CORRECTED	(0U)
#define GPU_LTC_CACHE_DSTG_ECC_UNCORRECTED	(1U)
#define GPU_LTC_CACHE_TSTG_ECC_UNCORRECTED	(3U)
#define GPU_LTC_CACHE_DSTG_BE_ECC_UNCORRECTED	(7U)
/**
 * @}
 */

/**
 * @defgroup LIST_OF_ERRORS_REPORTED_FROM_HUBMMU
 * Macros used to assign unique index to errors reported from the HUBMMU unit.
 * @{
 */
#define GPU_HUBMMU_L2TLB_SA_DATA_ECC_UNCORRECTED	(1U)
#define GPU_HUBMMU_TLB_SA_DATA_ECC_UNCORRECTED		(3U)
#define GPU_HUBMMU_PTE_DATA_ECC_UNCORRECTED		(5U)
#define GPU_HUBMMU_PDE0_DATA_ECC_UNCORRECTED		(7U)
#define GPU_HUBMMU_PAGE_FAULT_ERROR			(8U)


#ifdef CONFIG_NVGPU_SUPPORT_LINUX_ECC_ERROR_REPORTING
/**
 * @}
 */

/**
 * nvgpu_err_desc structure holds fields which describe an error along with
 * function callback which can be used to inject the error.
 */
struct nvgpu_err_desc {
	/** String representation of error. */
	const char *name;

	/** Flag to classify an error as critical or non-critical. */
	bool is_critical;

	/**
	 * Error Threshold: once this threshold value is reached, then the
	 * corresponding error counter will be reset to 0 and the error will be
	 * propagated to Safety_Services.
	 */
	int err_threshold;

	/**
	 * Total number of times an error has occurred (since its last reset).
	 */
	nvgpu_atomic_t err_count;

	/** Error ID. */
	u8 error_id;
};

/**
 * gpu_err_header structure holds fields which are required to identify the
 * version of header, sub-error type, sub-unit id, error address and time stamp.
 */
struct gpu_err_header {
	/** Version of GPU error header. */
	struct {
		/** Major version number. */
		u16 major;
		/** Minor version number. */
		u16 minor;
	} version;

	/** Sub error type corresponding to the error that is being reported. */
	u32 sub_err_type;

	/** ID of the sub-unit in a HW unit which encountered an error. */
	u64 sub_unit_id;

	/** Location of the error. */
	u64 address;

	/** Timestamp in nano seconds. */
	u64 timestamp_ns;
};

struct gpu_ecc_error_info {
	struct gpu_err_header header;

	/** Number of ECC errors. */
	u64 err_cnt;
};

/**
 * nvgpu_err_hw_module structure holds fields which describe the h/w modules
 * error reporting capabilities.
 */
struct nvgpu_err_hw_module {
	/** String representation of a given HW unit. */
	const char *name;

	/** HW unit ID. */
	u32 hw_unit;

	/** Total number of errors reported from a given HW unit. */
	u32 num_errs;

	u32 base_ecc_service_id;

	/** Used to get error description from look-up table. */
	struct nvgpu_err_desc *errs;
};

struct nvgpu_ecc_reporting_ops {
	void (*report_ecc_err)(struct gk20a *g, u32 hw_unit, u32 inst,
		u32 err_id, u64 err_addr, u64 err_count);
};

struct nvgpu_ecc_reporting {
	struct nvgpu_spinlock lock;
	/* This flag is protected by the above spinlock */
	bool ecc_reporting_service_enabled;
	const struct nvgpu_ecc_reporting_ops *ops;
};

 /**
  * This macro is used to initialize the members of nvgpu_err_desc struct.
  */
#define GPU_ERR(err, critical, id, threshold, ecount) \
{									\
		.name = (err),						\
		.is_critical = (critical),				\
		.error_id = (id),					\
		.err_threshold = (threshold),				\
		.err_count = NVGPU_ATOMIC_INIT(ecount),					\
}

/**
 * This macro is used to initialize critical errors.
 */
#define GPU_CRITERR(err, id, threshold, ecount) \
	GPU_ERR(err, true, id, threshold, ecount)

/**
 * This macro is used to initialize non-critical errors.
 */
#define GPU_NONCRITERR(err, id, threshold, ecount) \
	GPU_ERR(err, false, id, threshold, ecount)

/**
 * @brief GPU HW errors need to be reported to Safety_Services via SDL unit.
 *        This function provides an interface to report ECC erros to SDL unit.
 *
 * @param g [in]		- The GPU driver struct.
 * @param hw_unit [in]		- Index of HW unit.
 *				  - List of valid HW unit IDs
 *				    - NVGPU_ERR_MODULE_SM
 *				    - NVGPU_ERR_MODULE_FECS
 *				    - NVGPU_ERR_MODULE_GPCCS
 *				    - NVGPU_ERR_MODULE_MMU
 *				    - NVGPU_ERR_MODULE_GCC
 *				    - NVGPU_ERR_MODULE_PMU
 *				    - NVGPU_ERR_MODULE_LTC
 *				    - NVGPU_ERR_MODULE_HUBMMU
 * @param inst [in]		- Instance ID.
 *				  - In case of multiple instances of the same HW
 *				    unit (e.g., there are multiple instances of
 *				    SM), it is used to identify the instance
 *				    that encountered a fault.
 * @param err_id [in]		- Error index.
 *				  - For SM:
 *				    - Min: GPU_SM_L1_TAG_ECC_CORRECTED
 *				    - Max: GPU_SM_ICACHE_L1_PREDECODE_ECC_UNCORRECTED
 *				  - For FECS:
 *				    - Min: GPU_FECS_FALCON_IMEM_ECC_CORRECTED
 *				    - Max: GPU_FECS_INVALID_ERROR
 *				  - For GPCCS:
 *				    - Min: GPU_GPCCS_FALCON_IMEM_ECC_CORRECTED
 *				    - Max: GPU_GPCCS_FALCON_DMEM_ECC_UNCORRECTED
 *				  - For MMU:
 *				    - Min: GPU_MMU_L1TLB_SA_DATA_ECC_UNCORRECTED
 *				    - Max: GPU_MMU_L1TLB_FA_DATA_ECC_UNCORRECTED
 *				  - For GCC:
 *				    - Min: GPU_GCC_L15_ECC_UNCORRECTED
 *				    - Max: GPU_GCC_L15_ECC_UNCORRECTED
 *				  - For PMU:
 *				    - Min: GPU_PMU_FALCON_IMEM_ECC_CORRECTED
 *				    - Max: GPU_PMU_FALCON_DMEM_ECC_UNCORRECTED
 *				  - For LTC:
 *				    - Min: GPU_LTC_CACHE_DSTG_ECC_CORRECTED
 *				    - Max: GPU_LTC_CACHE_DSTG_BE_ECC_UNCORRECTED
 *				  - For HUBMMU:
 *				    - Min: GPU_HUBMMU_L2TLB_SA_DATA_ECC_UNCORRECTED
 *				    - Max: GPU_HUBMMU_PDE0_DATA_ECC_UNCORRECTED
 * @param err_addr [in]		- Error address.
 *				  - This is the location at which correctable or
 *				    uncorrectable error has occurred.
 * @param err_count [in]	- Error count.
 *
 * - Checks whether SDL is supported in the current GPU platform. If SDL is not
 *   supported, it simply returns.
 * - Validates both \a hw_unit and \a err_id indices. In case of a failure,
 *   invokes #nvgpu_sdl_handle_report_failure() api.
 * - Gets the current time of a clock. In case of a failure, invokes
 *   #nvgpu_sdl_handle_report_failure() api.
 * - Gets error description from internal look-up table using \a hw_unit and
 *   \a err_id indices.
 * - Forms error packet using details such as time-stamp, \a hw_unit, \a err_id,
 *   criticality of the error, \a inst, \a err_addr, \a err_count, error
 *   description, and size of the error packet.
 * - Performs compile-time assert check to ensure that the size of the error
 *   packet does not exceed the maximum allowable size specified in
 *   #MAX_ERR_MSG_SIZE.
 *
 * @return	None
 */
void nvgpu_report_ecc_err(struct gk20a *g, u32 hw_unit, u32 inst,
		u32 err_id, u64 err_addr, u64 err_count);

void nvgpu_init_ecc_reporting(struct gk20a *g);
void nvgpu_enable_ecc_reporting(struct gk20a *g);
void nvgpu_disable_ecc_reporting(struct gk20a *g);
void nvgpu_deinit_ecc_reporting(struct gk20a *g);

#else

static inline void nvgpu_report_ecc_err(struct gk20a *g, u32 hw_unit, u32 inst,
		u32 err_id, u64 err_addr, u64 err_count) {

}

#endif /* CONFIG_NVGPU_SUPPORT_LINUX_ECC_ERROR_REPORTING */

#endif /* NVGPU_NVGPU_ERR_H */