2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/debugfs.h>
25 #include <linux/list.h>
26 #include <linux/module.h>
27 #include <linux/uaccess.h>
28 #include <linux/reboot.h>
29 #include <linux/syscalls.h>
30 #include <linux/pm_runtime.h>
33 #include "amdgpu_ras.h"
34 #include "amdgpu_atomfirmware.h"
35 #include "amdgpu_xgmi.h"
36 #include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
37 #include "nbio_v4_3.h"
39 #include "amdgpu_reset.h"
41 #ifdef CONFIG_X86_MCE_AMD
44 static bool notifier_registered;
46 static const char *RAS_FS_NAME = "ras";
48 const char *ras_error_string[] = {
52 "multi_uncorrectable",
56 const char *ras_block_string[] = {
76 const char *ras_mca_block_string[] = {
83 struct amdgpu_ras_block_list {
85 struct list_head node;
87 struct amdgpu_ras_block_object *ras_obj;
90 const char *get_ras_block_str(struct ras_common_if *ras_block)
95 if (ras_block->block >= AMDGPU_RAS_BLOCK_COUNT)
96 return "OUT OF RANGE";
98 if (ras_block->block == AMDGPU_RAS_BLOCK__MCA)
99 return ras_mca_block_string[ras_block->sub_block_index];
101 return ras_block_string[ras_block->block];
104 #define ras_block_str(_BLOCK_) \
105 (((_BLOCK_) < ARRAY_SIZE(ras_block_string)) ? ras_block_string[_BLOCK_] : "Out Of Range")
107 #define ras_err_str(i) (ras_error_string[ffs(i)])
109 #define RAS_DEFAULT_FLAGS (AMDGPU_RAS_FLAG_INIT_BY_VBIOS)
111 /* inject address is 52 bits */
112 #define RAS_UMC_INJECT_ADDR_LIMIT (0x1ULL << 52)
114 /* typical ECC bad page rate is 1 bad page per 100MB VRAM */
115 #define RAS_BAD_PAGE_COVER (100 * 1024 * 1024ULL)
117 enum amdgpu_ras_retire_page_reservation {
118 AMDGPU_RAS_RETIRE_PAGE_RESERVED,
119 AMDGPU_RAS_RETIRE_PAGE_PENDING,
120 AMDGPU_RAS_RETIRE_PAGE_FAULT,
123 atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);
125 static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
127 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
129 #ifdef CONFIG_X86_MCE_AMD
130 static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev);
131 struct mce_notifier_adev_list {
132 struct amdgpu_device *devs[MAX_GPU_INSTANCE];
135 static struct mce_notifier_adev_list mce_adev_list;
138 void amdgpu_ras_set_error_query_ready(struct amdgpu_device *adev, bool ready)
140 if (adev && amdgpu_ras_get_context(adev))
141 amdgpu_ras_get_context(adev)->error_query_ready = ready;
144 static bool amdgpu_ras_get_error_query_ready(struct amdgpu_device *adev)
146 if (adev && amdgpu_ras_get_context(adev))
147 return amdgpu_ras_get_context(adev)->error_query_ready;
152 static int amdgpu_reserve_page_direct(struct amdgpu_device *adev, uint64_t address)
154 struct ras_err_data err_data = {0, 0, 0, NULL};
155 struct eeprom_table_record err_rec;
157 if ((address >= adev->gmc.mc_vram_size) ||
158 (address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
160 "RAS WARN: input address 0x%llx is invalid.\n",
165 if (amdgpu_ras_check_bad_page(adev, address)) {
167 "RAS WARN: 0x%llx has already been marked as bad page!\n",
172 memset(&err_rec, 0x0, sizeof(struct eeprom_table_record));
173 err_data.err_addr = &err_rec;
174 amdgpu_umc_fill_error_record(&err_data, address,
175 (address >> AMDGPU_GPU_PAGE_SHIFT), 0, 0);
177 if (amdgpu_bad_page_threshold != 0) {
178 amdgpu_ras_add_bad_pages(adev, err_data.err_addr,
179 err_data.err_addr_cnt);
180 amdgpu_ras_save_bad_pages(adev, NULL);
183 dev_warn(adev->dev, "WARNING: THIS IS ONLY FOR TEST PURPOSES AND WILL CORRUPT RAS EEPROM\n");
184 dev_warn(adev->dev, "Clear EEPROM:\n");
185 dev_warn(adev->dev, " echo 1 > /sys/kernel/debug/dri/0/ras/ras_eeprom_reset\n");
190 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
191 size_t size, loff_t *pos)
193 struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
194 struct ras_query_if info = {
200 if (amdgpu_ras_query_error_status(obj->adev, &info))
203 /* Hardware counter will be reset automatically after the query on Vega20 and Arcturus */
204 if (obj->adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 2) &&
205 obj->adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 4)) {
206 if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
207 dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
210 s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
212 "ce", info.ce_count);
217 s = min_t(u64, s, size);
220 if (copy_to_user(buf, &val[*pos], s))
228 static const struct file_operations amdgpu_ras_debugfs_ops = {
229 .owner = THIS_MODULE,
230 .read = amdgpu_ras_debugfs_read,
232 .llseek = default_llseek
235 static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
239 for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
241 if (strcmp(name, ras_block_string[i]) == 0)
247 static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
248 const char __user *buf, size_t size,
249 loff_t *pos, struct ras_debug_if *data)
251 ssize_t s = min_t(u64, 64, size);
259 /* default value is 0 if the mask is not set by user */
260 u32 instance_mask = 0;
266 memset(str, 0, sizeof(str));
267 memset(data, 0, sizeof(*data));
269 if (copy_from_user(str, buf, s))
272 if (sscanf(str, "disable %32s", block_name) == 1)
274 else if (sscanf(str, "enable %32s %8s", block_name, err) == 2)
276 else if (sscanf(str, "inject %32s %8s", block_name, err) == 2)
278 else if (strstr(str, "retire_page") != NULL)
280 else if (str[0] && str[1] && str[2] && str[3])
281 /* ascii string, but commands are not matched. */
286 if (sscanf(str, "%*s 0x%llx", &address) != 1 &&
287 sscanf(str, "%*s %llu", &address) != 1)
291 data->inject.address = address;
296 if (amdgpu_ras_find_block_id_by_name(block_name, &block_id))
299 data->head.block = block_id;
300 /* only ue and ce errors are supported */
301 if (!memcmp("ue", err, 2))
302 data->head.type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
303 else if (!memcmp("ce", err, 2))
304 data->head.type = AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE;
311 if (sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx 0x%x",
312 &sub_block, &address, &value, &instance_mask) != 4 &&
313 sscanf(str, "%*s %*s %*s %u %llu %llu %u",
314 &sub_block, &address, &value, &instance_mask) != 4 &&
315 sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx",
316 &sub_block, &address, &value) != 3 &&
317 sscanf(str, "%*s %*s %*s %u %llu %llu",
318 &sub_block, &address, &value) != 3)
320 data->head.sub_block_index = sub_block;
321 data->inject.address = address;
322 data->inject.value = value;
323 data->inject.instance_mask = instance_mask;
326 if (size < sizeof(*data))
329 if (copy_from_user(data, buf, sizeof(*data)))
337 * DOC: AMDGPU RAS debugfs control interface
339 * The control interface accepts struct ras_debug_if which has two members.
341 * First member: ras_debug_if::head or ras_debug_if::inject.
343 * head is used to indicate which IP block will be under control.
345 * head has four members, they are block, type, sub_block_index, name.
346 * block: which IP will be under control.
347 * type: what kind of error will be enabled/disabled/injected.
348 * sub_block_index: some IPs have subcomponets. say, GFX, sDMA.
349 * name: the name of IP.
351 * inject has three more members than head, they are address, value and mask.
352 * As their names indicate, inject operation will write the
353 * value to the address.
355 * The second member: struct ras_debug_if::op.
356 * It has three kinds of operations.
358 * - 0: disable RAS on the block. Take ::head as its data.
359 * - 1: enable RAS on the block. Take ::head as its data.
360 * - 2: inject errors on the block. Take ::inject as its data.
362 * How to use the interface?
366 * Copy the struct ras_debug_if in your code and initialize it.
367 * Write the struct to the control interface.
371 * .. code-block:: bash
373 * echo "disable <block>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
374 * echo "enable <block> <error>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
375 * echo "inject <block> <error> <sub-block> <address> <value> <mask>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
377 * Where N, is the card which you want to affect.
379 * "disable" requires only the block.
380 * "enable" requires the block and error type.
381 * "inject" requires the block, error type, address, and value.
383 * The block is one of: umc, sdma, gfx, etc.
384 * see ras_block_string[] for details
386 * The error type is one of: ue, ce, where,
387 * ue is multi-uncorrectable
388 * ce is single-correctable
390 * The sub-block is a the sub-block index, pass 0 if there is no sub-block.
391 * The address and value are hexadecimal numbers, leading 0x is optional.
392 * The mask means instance mask, is optional, default value is 0x1.
396 * .. code-block:: bash
398 * echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
399 * echo inject umc ce 0 0 0 3 > /sys/kernel/debug/dri/0/ras/ras_ctrl
400 * echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl
402 * How to check the result of the operation?
404 * To check disable/enable, see "ras" features at,
405 * /sys/class/drm/card[0/1/2...]/device/ras/features
407 * To check inject, see the corresponding error count at,
408 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx|sdma|umc|...]_err_count
411 * Operations are only allowed on blocks which are supported.
412 * Check the "ras" mask at /sys/module/amdgpu/parameters/ras_mask
413 * to see which blocks support RAS on a particular asic.
416 static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f,
417 const char __user *buf,
418 size_t size, loff_t *pos)
420 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
421 struct ras_debug_if data;
424 if (!amdgpu_ras_get_error_query_ready(adev)) {
425 dev_warn(adev->dev, "RAS WARN: error injection "
426 "currently inaccessible\n");
430 ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data);
435 ret = amdgpu_reserve_page_direct(adev, data.inject.address);
442 if (!amdgpu_ras_is_supported(adev, data.head.block))
447 ret = amdgpu_ras_feature_enable(adev, &data.head, 0);
450 ret = amdgpu_ras_feature_enable(adev, &data.head, 1);
453 if ((data.inject.address >= adev->gmc.mc_vram_size) ||
454 (data.inject.address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
455 dev_warn(adev->dev, "RAS WARN: input address "
456 "0x%llx is invalid.",
457 data.inject.address);
462 /* umc ce/ue error injection for a bad page is not allowed */
463 if ((data.head.block == AMDGPU_RAS_BLOCK__UMC) &&
464 amdgpu_ras_check_bad_page(adev, data.inject.address)) {
465 dev_warn(adev->dev, "RAS WARN: inject: 0x%llx has "
466 "already been marked as bad!\n",
467 data.inject.address);
471 /* data.inject.address is offset instead of absolute gpu address */
472 ret = amdgpu_ras_error_inject(adev, &data.inject);
486 * DOC: AMDGPU RAS debugfs EEPROM table reset interface
488 * Some boards contain an EEPROM which is used to persistently store a list of
489 * bad pages which experiences ECC errors in vram. This interface provides
490 * a way to reset the EEPROM, e.g., after testing error injection.
494 * .. code-block:: bash
496 * echo 1 > ../ras/ras_eeprom_reset
498 * will reset EEPROM table to 0 entries.
501 static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f,
502 const char __user *buf,
503 size_t size, loff_t *pos)
505 struct amdgpu_device *adev =
506 (struct amdgpu_device *)file_inode(f)->i_private;
509 ret = amdgpu_ras_eeprom_reset_table(
510 &(amdgpu_ras_get_context(adev)->eeprom_control));
513 /* Something was written to EEPROM.
515 amdgpu_ras_get_context(adev)->flags = RAS_DEFAULT_FLAGS;
522 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
523 .owner = THIS_MODULE,
525 .write = amdgpu_ras_debugfs_ctrl_write,
526 .llseek = default_llseek
529 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
530 .owner = THIS_MODULE,
532 .write = amdgpu_ras_debugfs_eeprom_write,
533 .llseek = default_llseek
537 * DOC: AMDGPU RAS sysfs Error Count Interface
539 * It allows the user to read the error count for each IP block on the gpu through
540 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
542 * It outputs the multiple lines which report the uncorrected (ue) and corrected
545 * The format of one line is below,
551 * .. code-block:: bash
557 static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
558 struct device_attribute *attr, char *buf)
560 struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr);
561 struct ras_query_if info = {
565 if (!amdgpu_ras_get_error_query_ready(obj->adev))
566 return sysfs_emit(buf, "Query currently inaccessible\n");
568 if (amdgpu_ras_query_error_status(obj->adev, &info))
571 if (obj->adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 2) &&
572 obj->adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 4)) {
573 if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
574 dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
577 return sysfs_emit(buf, "%s: %lu\n%s: %lu\n", "ue", info.ue_count,
578 "ce", info.ce_count);
583 #define get_obj(obj) do { (obj)->use++; } while (0)
584 #define alive_obj(obj) ((obj)->use)
586 static inline void put_obj(struct ras_manager *obj)
588 if (obj && (--obj->use == 0))
589 list_del(&obj->node);
590 if (obj && (obj->use < 0))
591 DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", get_ras_block_str(&obj->head));
594 /* make one obj and return it. */
595 static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
596 struct ras_common_if *head)
598 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
599 struct ras_manager *obj;
601 if (!adev->ras_enabled || !con)
604 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
607 if (head->block == AMDGPU_RAS_BLOCK__MCA) {
608 if (head->sub_block_index >= AMDGPU_RAS_MCA_BLOCK__LAST)
611 obj = &con->objs[AMDGPU_RAS_BLOCK__LAST + head->sub_block_index];
613 obj = &con->objs[head->block];
615 /* already exist. return obj? */
621 list_add(&obj->node, &con->head);
627 /* return an obj equal to head, or the first when head is NULL */
628 struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
629 struct ras_common_if *head)
631 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
632 struct ras_manager *obj;
635 if (!adev->ras_enabled || !con)
639 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
642 if (head->block == AMDGPU_RAS_BLOCK__MCA) {
643 if (head->sub_block_index >= AMDGPU_RAS_MCA_BLOCK__LAST)
646 obj = &con->objs[AMDGPU_RAS_BLOCK__LAST + head->sub_block_index];
648 obj = &con->objs[head->block];
653 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT + AMDGPU_RAS_MCA_BLOCK_COUNT; i++) {
664 /* feature ctl begin */
665 static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
666 struct ras_common_if *head)
668 return adev->ras_hw_enabled & BIT(head->block);
671 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
672 struct ras_common_if *head)
674 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
676 return con->features & BIT(head->block);
680 * if obj is not created, then create one.
681 * set feature enable flag.
683 static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
684 struct ras_common_if *head, int enable)
686 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
687 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
689 /* If hardware does not support ras, then do not create obj.
690 * But if hardware support ras, we can create the obj.
691 * Ras framework checks con->hw_supported to see if it need do
692 * corresponding initialization.
693 * IP checks con->support to see if it need disable ras.
695 if (!amdgpu_ras_is_feature_allowed(adev, head))
700 obj = amdgpu_ras_create_obj(adev, head);
704 /* In case we create obj somewhere else */
707 con->features |= BIT(head->block);
709 if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
710 con->features &= ~BIT(head->block);
718 static int amdgpu_ras_check_feature_allowed(struct amdgpu_device *adev,
719 struct ras_common_if *head)
721 if (amdgpu_ras_is_feature_allowed(adev, head) ||
722 amdgpu_ras_is_poison_mode_supported(adev))
728 /* wrapper of psp_ras_enable_features */
729 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
730 struct ras_common_if *head, bool enable)
732 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
733 union ta_ras_cmd_input *info;
739 if (head->block == AMDGPU_RAS_BLOCK__GFX) {
740 info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
745 info->disable_features = (struct ta_ras_disable_features_input) {
746 .block_id = amdgpu_ras_block_to_ta(head->block),
747 .error_type = amdgpu_ras_error_to_ta(head->type),
750 info->enable_features = (struct ta_ras_enable_features_input) {
751 .block_id = amdgpu_ras_block_to_ta(head->block),
752 .error_type = amdgpu_ras_error_to_ta(head->type),
757 /* Do not enable if it is not allowed. */
758 if (enable && !amdgpu_ras_check_feature_allowed(adev, head))
761 /* Only enable ras feature operation handle on host side */
762 if (head->block == AMDGPU_RAS_BLOCK__GFX &&
763 !amdgpu_sriov_vf(adev) &&
764 !amdgpu_ras_intr_triggered()) {
765 ret = psp_ras_enable_features(&adev->psp, info, enable);
767 dev_err(adev->dev, "ras %s %s failed poison:%d ret:%d\n",
768 enable ? "enable":"disable",
769 get_ras_block_str(head),
770 amdgpu_ras_is_poison_mode_supported(adev), ret);
776 __amdgpu_ras_feature_enable(adev, head, enable);
778 if (head->block == AMDGPU_RAS_BLOCK__GFX)
783 /* Only used in device probe stage and called only once. */
784 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
785 struct ras_common_if *head, bool enable)
787 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
793 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
795 /* There is no harm to issue a ras TA cmd regardless of
796 * the currecnt ras state.
797 * If current state == target state, it will do nothing
798 * But sometimes it requests driver to reset and repost
799 * with error code -EAGAIN.
801 ret = amdgpu_ras_feature_enable(adev, head, 1);
802 /* With old ras TA, we might fail to enable ras.
803 * Log it and just setup the object.
804 * TODO need remove this WA in the future.
806 if (ret == -EINVAL) {
807 ret = __amdgpu_ras_feature_enable(adev, head, 1);
810 "RAS INFO: %s setup object\n",
811 get_ras_block_str(head));
814 /* setup the object then issue a ras TA disable cmd.*/
815 ret = __amdgpu_ras_feature_enable(adev, head, 1);
819 /* gfx block ras dsiable cmd must send to ras-ta */
820 if (head->block == AMDGPU_RAS_BLOCK__GFX)
821 con->features |= BIT(head->block);
823 ret = amdgpu_ras_feature_enable(adev, head, 0);
825 /* clean gfx block ras features flag */
826 if (adev->ras_enabled && head->block == AMDGPU_RAS_BLOCK__GFX)
827 con->features &= ~BIT(head->block);
830 ret = amdgpu_ras_feature_enable(adev, head, enable);
835 static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
838 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
839 struct ras_manager *obj, *tmp;
841 list_for_each_entry_safe(obj, tmp, &con->head, node) {
843 * aka just release the obj and corresponding flags
846 if (__amdgpu_ras_feature_enable(adev, &obj->head, 0))
849 if (amdgpu_ras_feature_enable(adev, &obj->head, 0))
854 return con->features;
857 static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
860 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
862 const enum amdgpu_ras_error_type default_ras_type = AMDGPU_RAS_ERROR__NONE;
864 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) {
865 struct ras_common_if head = {
867 .type = default_ras_type,
868 .sub_block_index = 0,
871 if (i == AMDGPU_RAS_BLOCK__MCA)
876 * bypass psp. vbios enable ras for us.
877 * so just create the obj
879 if (__amdgpu_ras_feature_enable(adev, &head, 1))
882 if (amdgpu_ras_feature_enable(adev, &head, 1))
887 for (i = 0; i < AMDGPU_RAS_MCA_BLOCK_COUNT; i++) {
888 struct ras_common_if head = {
889 .block = AMDGPU_RAS_BLOCK__MCA,
890 .type = default_ras_type,
891 .sub_block_index = i,
896 * bypass psp. vbios enable ras for us.
897 * so just create the obj
899 if (__amdgpu_ras_feature_enable(adev, &head, 1))
902 if (amdgpu_ras_feature_enable(adev, &head, 1))
907 return con->features;
909 /* feature ctl end */
911 static int amdgpu_ras_block_match_default(struct amdgpu_ras_block_object *block_obj,
912 enum amdgpu_ras_block block)
917 if (block_obj->ras_comm.block == block)
923 static struct amdgpu_ras_block_object *amdgpu_ras_get_ras_block(struct amdgpu_device *adev,
924 enum amdgpu_ras_block block, uint32_t sub_block_index)
926 struct amdgpu_ras_block_list *node, *tmp;
927 struct amdgpu_ras_block_object *obj;
929 if (block >= AMDGPU_RAS_BLOCK__LAST)
932 list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
933 if (!node->ras_obj) {
934 dev_warn(adev->dev, "Warning: abnormal ras list node.\n");
939 if (obj->ras_block_match) {
940 if (obj->ras_block_match(obj, block, sub_block_index) == 0)
943 if (amdgpu_ras_block_match_default(obj, block) == 0)
951 static void amdgpu_ras_get_ecc_info(struct amdgpu_device *adev, struct ras_err_data *err_data)
953 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
957 * choosing right query method according to
958 * whether smu support query error information
960 ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
961 if (ret == -EOPNOTSUPP) {
962 if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
963 adev->umc.ras->ras_block.hw_ops->query_ras_error_count)
964 adev->umc.ras->ras_block.hw_ops->query_ras_error_count(adev, err_data);
966 /* umc query_ras_error_address is also responsible for clearing
969 if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
970 adev->umc.ras->ras_block.hw_ops->query_ras_error_address)
971 adev->umc.ras->ras_block.hw_ops->query_ras_error_address(adev, err_data);
974 adev->umc.ras->ecc_info_query_ras_error_count)
975 adev->umc.ras->ecc_info_query_ras_error_count(adev, err_data);
978 adev->umc.ras->ecc_info_query_ras_error_address)
979 adev->umc.ras->ecc_info_query_ras_error_address(adev, err_data);
983 /* query/inject/cure begin */
984 int amdgpu_ras_query_error_status(struct amdgpu_device *adev,
985 struct ras_query_if *info)
987 struct amdgpu_ras_block_object *block_obj = NULL;
988 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
989 struct ras_err_data err_data = {0, 0, 0, NULL};
994 if (info->head.block == AMDGPU_RAS_BLOCK__UMC) {
995 amdgpu_ras_get_ecc_info(adev, &err_data);
997 block_obj = amdgpu_ras_get_ras_block(adev, info->head.block, 0);
998 if (!block_obj || !block_obj->hw_ops) {
999 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1000 get_ras_block_str(&info->head));
1004 if (block_obj->hw_ops->query_ras_error_count)
1005 block_obj->hw_ops->query_ras_error_count(adev, &err_data);
1007 if ((info->head.block == AMDGPU_RAS_BLOCK__SDMA) ||
1008 (info->head.block == AMDGPU_RAS_BLOCK__GFX) ||
1009 (info->head.block == AMDGPU_RAS_BLOCK__MMHUB)) {
1010 if (block_obj->hw_ops->query_ras_error_status)
1011 block_obj->hw_ops->query_ras_error_status(adev);
1015 obj->err_data.ue_count += err_data.ue_count;
1016 obj->err_data.ce_count += err_data.ce_count;
1018 info->ue_count = obj->err_data.ue_count;
1019 info->ce_count = obj->err_data.ce_count;
1021 if (err_data.ce_count) {
1022 if (adev->smuio.funcs &&
1023 adev->smuio.funcs->get_socket_id &&
1024 adev->smuio.funcs->get_die_id) {
1025 dev_info(adev->dev, "socket: %d, die: %d "
1026 "%ld correctable hardware errors "
1027 "detected in %s block, no user "
1028 "action is needed.\n",
1029 adev->smuio.funcs->get_socket_id(adev),
1030 adev->smuio.funcs->get_die_id(adev),
1031 obj->err_data.ce_count,
1032 get_ras_block_str(&info->head));
1034 dev_info(adev->dev, "%ld correctable hardware errors "
1035 "detected in %s block, no user "
1036 "action is needed.\n",
1037 obj->err_data.ce_count,
1038 get_ras_block_str(&info->head));
1041 if (err_data.ue_count) {
1042 if (adev->smuio.funcs &&
1043 adev->smuio.funcs->get_socket_id &&
1044 adev->smuio.funcs->get_die_id) {
1045 dev_info(adev->dev, "socket: %d, die: %d "
1046 "%ld uncorrectable hardware errors "
1047 "detected in %s block\n",
1048 adev->smuio.funcs->get_socket_id(adev),
1049 adev->smuio.funcs->get_die_id(adev),
1050 obj->err_data.ue_count,
1051 get_ras_block_str(&info->head));
1053 dev_info(adev->dev, "%ld uncorrectable hardware errors "
1054 "detected in %s block\n",
1055 obj->err_data.ue_count,
1056 get_ras_block_str(&info->head));
1063 int amdgpu_ras_reset_error_status(struct amdgpu_device *adev,
1064 enum amdgpu_ras_block block)
1066 struct amdgpu_ras_block_object *block_obj = amdgpu_ras_get_ras_block(adev, block, 0);
1068 if (!amdgpu_ras_is_supported(adev, block))
1071 if (!block_obj || !block_obj->hw_ops) {
1072 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1073 ras_block_str(block));
1077 if (block_obj->hw_ops->reset_ras_error_count)
1078 block_obj->hw_ops->reset_ras_error_count(adev);
1080 if ((block == AMDGPU_RAS_BLOCK__GFX) ||
1081 (block == AMDGPU_RAS_BLOCK__MMHUB)) {
1082 if (block_obj->hw_ops->reset_ras_error_status)
1083 block_obj->hw_ops->reset_ras_error_status(adev);
1089 /* wrapper of psp_ras_trigger_error */
1090 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
1091 struct ras_inject_if *info)
1093 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1094 struct ta_ras_trigger_error_input block_info = {
1095 .block_id = amdgpu_ras_block_to_ta(info->head.block),
1096 .inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
1097 .sub_block_index = info->head.sub_block_index,
1098 .address = info->address,
1099 .value = info->value,
1102 struct amdgpu_ras_block_object *block_obj = amdgpu_ras_get_ras_block(adev,
1104 info->head.sub_block_index);
1106 /* inject on guest isn't allowed, return success directly */
1107 if (amdgpu_sriov_vf(adev))
1113 if (!block_obj || !block_obj->hw_ops) {
1114 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1115 get_ras_block_str(&info->head));
1119 /* Calculate XGMI relative offset */
1120 if (adev->gmc.xgmi.num_physical_nodes > 1) {
1121 block_info.address =
1122 amdgpu_xgmi_get_relative_phy_addr(adev,
1123 block_info.address);
1126 if (info->head.block == AMDGPU_RAS_BLOCK__GFX) {
1127 if (block_obj->hw_ops->ras_error_inject)
1128 ret = block_obj->hw_ops->ras_error_inject(adev, info, info->instance_mask);
1130 /* If defined special ras_error_inject(e.g: xgmi), implement special ras_error_inject */
1131 if (block_obj->hw_ops->ras_error_inject)
1132 ret = block_obj->hw_ops->ras_error_inject(adev, &block_info,
1133 info->instance_mask);
1134 else /*If not defined .ras_error_inject, use default ras_error_inject*/
1135 ret = psp_ras_trigger_error(&adev->psp, &block_info, info->instance_mask);
1139 dev_err(adev->dev, "ras inject %s failed %d\n",
1140 get_ras_block_str(&info->head), ret);
1146 * amdgpu_ras_query_error_count_helper -- Get error counter for specific IP
1147 * @adev: pointer to AMD GPU device
1148 * @ce_count: pointer to an integer to be set to the count of correctible errors.
1149 * @ue_count: pointer to an integer to be set to the count of uncorrectible errors.
1150 * @query_info: pointer to ras_query_if
1152 * Return 0 for query success or do nothing, otherwise return an error
1155 static int amdgpu_ras_query_error_count_helper(struct amdgpu_device *adev,
1156 unsigned long *ce_count,
1157 unsigned long *ue_count,
1158 struct ras_query_if *query_info)
1163 /* do nothing if query_info is not specified */
1166 ret = amdgpu_ras_query_error_status(adev, query_info);
1170 *ce_count += query_info->ce_count;
1171 *ue_count += query_info->ue_count;
1173 /* some hardware/IP supports read to clear
1174 * no need to explictly reset the err status after the query call */
1175 if (adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 2) &&
1176 adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 4)) {
1177 if (amdgpu_ras_reset_error_status(adev, query_info->head.block))
1179 "Failed to reset error counter and error status\n");
1186 * amdgpu_ras_query_error_count -- Get error counts of all IPs or specific IP
1187 * @adev: pointer to AMD GPU device
1188 * @ce_count: pointer to an integer to be set to the count of correctible errors.
1189 * @ue_count: pointer to an integer to be set to the count of uncorrectible
1191 * @query_info: pointer to ras_query_if if the query request is only for
1192 * specific ip block; if info is NULL, then the qurey request is for
1193 * all the ip blocks that support query ras error counters/status
1195 * If set, @ce_count or @ue_count, count and return the corresponding
1196 * error counts in those integer pointers. Return 0 if the device
1197 * supports RAS. Return -EOPNOTSUPP if the device doesn't support RAS.
1199 int amdgpu_ras_query_error_count(struct amdgpu_device *adev,
1200 unsigned long *ce_count,
1201 unsigned long *ue_count,
1202 struct ras_query_if *query_info)
1204 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1205 struct ras_manager *obj;
1206 unsigned long ce, ue;
1209 if (!adev->ras_enabled || !con)
1212 /* Don't count since no reporting.
1214 if (!ce_count && !ue_count)
1220 /* query all the ip blocks that support ras query interface */
1221 list_for_each_entry(obj, &con->head, node) {
1222 struct ras_query_if info = {
1226 ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, &info);
1229 /* query specific ip block */
1230 ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, query_info);
1244 /* query/inject/cure end */
1249 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1250 struct ras_badpage **bps, unsigned int *count);
1252 static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
1255 case AMDGPU_RAS_RETIRE_PAGE_RESERVED:
1257 case AMDGPU_RAS_RETIRE_PAGE_PENDING:
1259 case AMDGPU_RAS_RETIRE_PAGE_FAULT:
1266 * DOC: AMDGPU RAS sysfs gpu_vram_bad_pages Interface
1268 * It allows user to read the bad pages of vram on the gpu through
1269 * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages
1271 * It outputs multiple lines, and each line stands for one gpu page.
1273 * The format of one line is below,
1274 * gpu pfn : gpu page size : flags
1276 * gpu pfn and gpu page size are printed in hex format.
1277 * flags can be one of below character,
1279 * R: reserved, this gpu page is reserved and not able to use.
1281 * P: pending for reserve, this gpu page is marked as bad, will be reserved
1282 * in next window of page_reserve.
1284 * F: unable to reserve. this gpu page can't be reserved due to some reasons.
1288 * .. code-block:: bash
1290 * 0x00000001 : 0x00001000 : R
1291 * 0x00000002 : 0x00001000 : P
1295 static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
1296 struct kobject *kobj, struct bin_attribute *attr,
1297 char *buf, loff_t ppos, size_t count)
1299 struct amdgpu_ras *con =
1300 container_of(attr, struct amdgpu_ras, badpages_attr);
1301 struct amdgpu_device *adev = con->adev;
1302 const unsigned int element_size =
1303 sizeof("0xabcdabcd : 0x12345678 : R\n") - 1;
1304 unsigned int start = div64_ul(ppos + element_size - 1, element_size);
1305 unsigned int end = div64_ul(ppos + count - 1, element_size);
1307 struct ras_badpage *bps = NULL;
1308 unsigned int bps_count = 0;
1310 memset(buf, 0, count);
1312 if (amdgpu_ras_badpages_read(adev, &bps, &bps_count))
1315 for (; start < end && start < bps_count; start++)
1316 s += scnprintf(&buf[s], element_size + 1,
1317 "0x%08x : 0x%08x : %1s\n",
1320 amdgpu_ras_badpage_flags_str(bps[start].flags));
1327 static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
1328 struct device_attribute *attr, char *buf)
1330 struct amdgpu_ras *con =
1331 container_of(attr, struct amdgpu_ras, features_attr);
1333 return sysfs_emit(buf, "feature mask: 0x%x\n", con->features);
1336 static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
1338 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1340 sysfs_remove_file_from_group(&adev->dev->kobj,
1341 &con->badpages_attr.attr,
1345 static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
1347 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1348 struct attribute *attrs[] = {
1349 &con->features_attr.attr,
1352 struct attribute_group group = {
1353 .name = RAS_FS_NAME,
1357 sysfs_remove_group(&adev->dev->kobj, &group);
1362 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
1363 struct ras_common_if *head)
1365 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1367 if (!obj || obj->attr_inuse)
1372 snprintf(obj->fs_data.sysfs_name, sizeof(obj->fs_data.sysfs_name),
1373 "%s_err_count", head->name);
1375 obj->sysfs_attr = (struct device_attribute){
1377 .name = obj->fs_data.sysfs_name,
1380 .show = amdgpu_ras_sysfs_read,
1382 sysfs_attr_init(&obj->sysfs_attr.attr);
1384 if (sysfs_add_file_to_group(&adev->dev->kobj,
1385 &obj->sysfs_attr.attr,
1391 obj->attr_inuse = 1;
1396 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
1397 struct ras_common_if *head)
1399 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1401 if (!obj || !obj->attr_inuse)
1404 sysfs_remove_file_from_group(&adev->dev->kobj,
1405 &obj->sysfs_attr.attr,
1407 obj->attr_inuse = 0;
1413 static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
1415 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1416 struct ras_manager *obj, *tmp;
1418 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1419 amdgpu_ras_sysfs_remove(adev, &obj->head);
1422 if (amdgpu_bad_page_threshold != 0)
1423 amdgpu_ras_sysfs_remove_bad_page_node(adev);
1425 amdgpu_ras_sysfs_remove_feature_node(adev);
1432 * DOC: AMDGPU RAS Reboot Behavior for Unrecoverable Errors
1434 * Normally when there is an uncorrectable error, the driver will reset
1435 * the GPU to recover. However, in the event of an unrecoverable error,
1436 * the driver provides an interface to reboot the system automatically
1439 * The following file in debugfs provides that interface:
1440 * /sys/kernel/debug/dri/[0/1/2...]/ras/auto_reboot
1444 * .. code-block:: bash
1446 * echo true > .../ras/auto_reboot
1450 static struct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
1452 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1453 struct drm_minor *minor = adev_to_drm(adev)->primary;
1456 dir = debugfs_create_dir(RAS_FS_NAME, minor->debugfs_root);
1457 debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, dir, adev,
1458 &amdgpu_ras_debugfs_ctrl_ops);
1459 debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, dir, adev,
1460 &amdgpu_ras_debugfs_eeprom_ops);
1461 debugfs_create_u32("bad_page_cnt_threshold", 0444, dir,
1462 &con->bad_page_cnt_threshold);
1463 debugfs_create_x32("ras_hw_enabled", 0444, dir, &adev->ras_hw_enabled);
1464 debugfs_create_x32("ras_enabled", 0444, dir, &adev->ras_enabled);
1465 debugfs_create_file("ras_eeprom_size", S_IRUGO, dir, adev,
1466 &amdgpu_ras_debugfs_eeprom_size_ops);
1467 con->de_ras_eeprom_table = debugfs_create_file("ras_eeprom_table",
1469 &amdgpu_ras_debugfs_eeprom_table_ops);
1470 amdgpu_ras_debugfs_set_ret_size(&con->eeprom_control);
1473 * After one uncorrectable error happens, usually GPU recovery will
1474 * be scheduled. But due to the known problem in GPU recovery failing
1475 * to bring GPU back, below interface provides one direct way to
1476 * user to reboot system automatically in such case within
1477 * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine
1478 * will never be called.
1480 debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, dir, &con->reboot);
1483 * User could set this not to clean up hardware's error count register
1484 * of RAS IPs during ras recovery.
1486 debugfs_create_bool("disable_ras_err_cnt_harvest", 0644, dir,
1487 &con->disable_ras_err_cnt_harvest);
1491 static void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
1492 struct ras_fs_if *head,
1495 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
1502 memcpy(obj->fs_data.debugfs_name,
1504 sizeof(obj->fs_data.debugfs_name));
1506 debugfs_create_file(obj->fs_data.debugfs_name, S_IWUGO | S_IRUGO, dir,
1507 obj, &amdgpu_ras_debugfs_ops);
1510 void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
1512 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1514 struct ras_manager *obj;
1515 struct ras_fs_if fs_info;
1518 * it won't be called in resume path, no need to check
1519 * suspend and gpu reset status
1521 if (!IS_ENABLED(CONFIG_DEBUG_FS) || !con)
1524 dir = amdgpu_ras_debugfs_create_ctrl_node(adev);
1526 list_for_each_entry(obj, &con->head, node) {
1527 if (amdgpu_ras_is_supported(adev, obj->head.block) &&
1528 (obj->attr_inuse == 1)) {
1529 sprintf(fs_info.debugfs_name, "%s_err_inject",
1530 get_ras_block_str(&obj->head));
1531 fs_info.head = obj->head;
1532 amdgpu_ras_debugfs_create(adev, &fs_info, dir);
1540 static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
1541 amdgpu_ras_sysfs_badpages_read, NULL, 0);
1542 static DEVICE_ATTR(features, S_IRUGO,
1543 amdgpu_ras_sysfs_features_read, NULL);
1544 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
1546 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1547 struct attribute_group group = {
1548 .name = RAS_FS_NAME,
1550 struct attribute *attrs[] = {
1551 &con->features_attr.attr,
1554 struct bin_attribute *bin_attrs[] = {
1560 /* add features entry */
1561 con->features_attr = dev_attr_features;
1562 group.attrs = attrs;
1563 sysfs_attr_init(attrs[0]);
1565 if (amdgpu_bad_page_threshold != 0) {
1566 /* add bad_page_features entry */
1567 bin_attr_gpu_vram_bad_pages.private = NULL;
1568 con->badpages_attr = bin_attr_gpu_vram_bad_pages;
1569 bin_attrs[0] = &con->badpages_attr;
1570 group.bin_attrs = bin_attrs;
1571 sysfs_bin_attr_init(bin_attrs[0]);
1574 r = sysfs_create_group(&adev->dev->kobj, &group);
1576 dev_err(adev->dev, "Failed to create RAS sysfs group!");
1581 static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
1583 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1584 struct ras_manager *con_obj, *ip_obj, *tmp;
1586 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1587 list_for_each_entry_safe(con_obj, tmp, &con->head, node) {
1588 ip_obj = amdgpu_ras_find_obj(adev, &con_obj->head);
1594 amdgpu_ras_sysfs_remove_all(adev);
1601 /* For the hardware that cannot enable bif ring for both ras_controller_irq
1602 * and ras_err_evnet_athub_irq ih cookies, the driver has to poll status
1603 * register to check whether the interrupt is triggered or not, and properly
1604 * ack the interrupt if it is there
1606 void amdgpu_ras_interrupt_fatal_error_handler(struct amdgpu_device *adev)
1608 /* Fatal error events are handled on host side */
1609 if (amdgpu_sriov_vf(adev))
1612 if (adev->nbio.ras &&
1613 adev->nbio.ras->handle_ras_controller_intr_no_bifring)
1614 adev->nbio.ras->handle_ras_controller_intr_no_bifring(adev);
1616 if (adev->nbio.ras &&
1617 adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring)
1618 adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring(adev);
1621 static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *obj,
1622 struct amdgpu_iv_entry *entry)
1624 bool poison_stat = false;
1625 struct amdgpu_device *adev = obj->adev;
1626 struct amdgpu_ras_block_object *block_obj =
1627 amdgpu_ras_get_ras_block(adev, obj->head.block, 0);
1632 /* both query_poison_status and handle_poison_consumption are optional,
1633 * but at least one of them should be implemented if we need poison
1634 * consumption handler
1636 if (block_obj->hw_ops && block_obj->hw_ops->query_poison_status) {
1637 poison_stat = block_obj->hw_ops->query_poison_status(adev);
1639 /* Not poison consumption interrupt, no need to handle it */
1640 dev_info(adev->dev, "No RAS poison status in %s poison IH.\n",
1641 block_obj->ras_comm.name);
1647 if (!adev->gmc.xgmi.connected_to_cpu)
1648 amdgpu_umc_poison_handler(adev, false);
1650 if (block_obj->hw_ops && block_obj->hw_ops->handle_poison_consumption)
1651 poison_stat = block_obj->hw_ops->handle_poison_consumption(adev);
1653 /* gpu reset is fallback for failed and default cases */
1655 dev_info(adev->dev, "GPU reset for %s RAS poison consumption is issued!\n",
1656 block_obj->ras_comm.name);
1657 amdgpu_ras_reset_gpu(adev);
1659 amdgpu_gfx_poison_consumption_handler(adev, entry);
1663 static void amdgpu_ras_interrupt_poison_creation_handler(struct ras_manager *obj,
1664 struct amdgpu_iv_entry *entry)
1666 dev_info(obj->adev->dev,
1667 "Poison is created, no user action is needed.\n");
1670 static void amdgpu_ras_interrupt_umc_handler(struct ras_manager *obj,
1671 struct amdgpu_iv_entry *entry)
1673 struct ras_ih_data *data = &obj->ih_data;
1674 struct ras_err_data err_data = {0, 0, 0, NULL};
1680 /* Let IP handle its data, maybe we need get the output
1681 * from the callback to update the error type/count, etc
1683 ret = data->cb(obj->adev, &err_data, entry);
1684 /* ue will trigger an interrupt, and in that case
1685 * we need do a reset to recovery the whole system.
1686 * But leave IP do that recovery, here we just dispatch
1689 if (ret == AMDGPU_RAS_SUCCESS) {
1690 /* these counts could be left as 0 if
1691 * some blocks do not count error number
1693 obj->err_data.ue_count += err_data.ue_count;
1694 obj->err_data.ce_count += err_data.ce_count;
1698 static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
1700 struct ras_ih_data *data = &obj->ih_data;
1701 struct amdgpu_iv_entry entry;
1703 while (data->rptr != data->wptr) {
1705 memcpy(&entry, &data->ring[data->rptr],
1706 data->element_size);
1709 data->rptr = (data->aligned_element_size +
1710 data->rptr) % data->ring_size;
1712 if (amdgpu_ras_is_poison_mode_supported(obj->adev)) {
1713 if (obj->head.block == AMDGPU_RAS_BLOCK__UMC)
1714 amdgpu_ras_interrupt_poison_creation_handler(obj, &entry);
1716 amdgpu_ras_interrupt_poison_consumption_handler(obj, &entry);
1718 if (obj->head.block == AMDGPU_RAS_BLOCK__UMC)
1719 amdgpu_ras_interrupt_umc_handler(obj, &entry);
1721 dev_warn(obj->adev->dev,
1722 "No RAS interrupt handler for non-UMC block with poison disabled.\n");
1727 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
1729 struct ras_ih_data *data =
1730 container_of(work, struct ras_ih_data, ih_work);
1731 struct ras_manager *obj =
1732 container_of(data, struct ras_manager, ih_data);
1734 amdgpu_ras_interrupt_handler(obj);
1737 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
1738 struct ras_dispatch_if *info)
1740 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1741 struct ras_ih_data *data = &obj->ih_data;
1746 if (data->inuse == 0)
1749 /* Might be overflow... */
1750 memcpy(&data->ring[data->wptr], info->entry,
1751 data->element_size);
1754 data->wptr = (data->aligned_element_size +
1755 data->wptr) % data->ring_size;
1757 schedule_work(&data->ih_work);
1762 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
1763 struct ras_common_if *head)
1765 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1766 struct ras_ih_data *data;
1771 data = &obj->ih_data;
1772 if (data->inuse == 0)
1775 cancel_work_sync(&data->ih_work);
1778 memset(data, 0, sizeof(*data));
1784 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
1785 struct ras_common_if *head)
1787 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1788 struct ras_ih_data *data;
1789 struct amdgpu_ras_block_object *ras_obj;
1792 /* in case we registe the IH before enable ras feature */
1793 obj = amdgpu_ras_create_obj(adev, head);
1799 ras_obj = container_of(head, struct amdgpu_ras_block_object, ras_comm);
1801 data = &obj->ih_data;
1802 /* add the callback.etc */
1803 *data = (struct ras_ih_data) {
1805 .cb = ras_obj->ras_cb,
1806 .element_size = sizeof(struct amdgpu_iv_entry),
1811 INIT_WORK(&data->ih_work, amdgpu_ras_interrupt_process_handler);
1813 data->aligned_element_size = ALIGN(data->element_size, 8);
1814 /* the ring can store 64 iv entries. */
1815 data->ring_size = 64 * data->aligned_element_size;
1816 data->ring = kmalloc(data->ring_size, GFP_KERNEL);
1828 static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
1830 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1831 struct ras_manager *obj, *tmp;
1833 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1834 amdgpu_ras_interrupt_remove_handler(adev, &obj->head);
1841 /* traversal all IPs except NBIO to query error counter */
1842 static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev)
1844 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1845 struct ras_manager *obj;
1847 if (!adev->ras_enabled || !con)
1850 list_for_each_entry(obj, &con->head, node) {
1851 struct ras_query_if info = {
1856 * PCIE_BIF IP has one different isr by ras controller
1857 * interrupt, the specific ras counter query will be
1858 * done in that isr. So skip such block from common
1859 * sync flood interrupt isr calling.
1861 if (info.head.block == AMDGPU_RAS_BLOCK__PCIE_BIF)
1865 * this is a workaround for aldebaran, skip send msg to
1866 * smu to get ecc_info table due to smu handle get ecc
1867 * info table failed temporarily.
1868 * should be removed until smu fix handle ecc_info table.
1870 if ((info.head.block == AMDGPU_RAS_BLOCK__UMC) &&
1871 (adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 2)))
1874 amdgpu_ras_query_error_status(adev, &info);
1876 if (adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 2) &&
1877 adev->ip_versions[MP0_HWIP][0] != IP_VERSION(11, 0, 4) &&
1878 adev->ip_versions[MP0_HWIP][0] != IP_VERSION(13, 0, 0)) {
1879 if (amdgpu_ras_reset_error_status(adev, info.head.block))
1880 dev_warn(adev->dev, "Failed to reset error counter and error status");
1885 /* Parse RdRspStatus and WrRspStatus */
1886 static void amdgpu_ras_error_status_query(struct amdgpu_device *adev,
1887 struct ras_query_if *info)
1889 struct amdgpu_ras_block_object *block_obj;
1891 * Only two block need to query read/write
1892 * RspStatus at current state
1894 if ((info->head.block != AMDGPU_RAS_BLOCK__GFX) &&
1895 (info->head.block != AMDGPU_RAS_BLOCK__MMHUB))
1898 block_obj = amdgpu_ras_get_ras_block(adev,
1900 info->head.sub_block_index);
1902 if (!block_obj || !block_obj->hw_ops) {
1903 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1904 get_ras_block_str(&info->head));
1908 if (block_obj->hw_ops->query_ras_error_status)
1909 block_obj->hw_ops->query_ras_error_status(adev);
1913 static void amdgpu_ras_query_err_status(struct amdgpu_device *adev)
1915 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1916 struct ras_manager *obj;
1918 if (!adev->ras_enabled || !con)
1921 list_for_each_entry(obj, &con->head, node) {
1922 struct ras_query_if info = {
1926 amdgpu_ras_error_status_query(adev, &info);
1930 /* recovery begin */
1932 /* return 0 on success.
1933 * caller need free bps.
1935 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1936 struct ras_badpage **bps, unsigned int *count)
1938 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1939 struct ras_err_handler_data *data;
1941 int ret = 0, status;
1943 if (!con || !con->eh_data || !bps || !count)
1946 mutex_lock(&con->recovery_lock);
1947 data = con->eh_data;
1948 if (!data || data->count == 0) {
1954 *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
1960 for (; i < data->count; i++) {
1961 (*bps)[i] = (struct ras_badpage){
1962 .bp = data->bps[i].retired_page,
1963 .size = AMDGPU_GPU_PAGE_SIZE,
1964 .flags = AMDGPU_RAS_RETIRE_PAGE_RESERVED,
1966 status = amdgpu_vram_mgr_query_page_status(&adev->mman.vram_mgr,
1967 data->bps[i].retired_page);
1968 if (status == -EBUSY)
1969 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_PENDING;
1970 else if (status == -ENOENT)
1971 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_FAULT;
1974 *count = data->count;
1976 mutex_unlock(&con->recovery_lock);
1980 static void amdgpu_ras_do_recovery(struct work_struct *work)
1982 struct amdgpu_ras *ras =
1983 container_of(work, struct amdgpu_ras, recovery_work);
1984 struct amdgpu_device *remote_adev = NULL;
1985 struct amdgpu_device *adev = ras->adev;
1986 struct list_head device_list, *device_list_handle = NULL;
1988 if (!ras->disable_ras_err_cnt_harvest) {
1989 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
1991 /* Build list of devices to query RAS related errors */
1992 if (hive && adev->gmc.xgmi.num_physical_nodes > 1) {
1993 device_list_handle = &hive->device_list;
1995 INIT_LIST_HEAD(&device_list);
1996 list_add_tail(&adev->gmc.xgmi.head, &device_list);
1997 device_list_handle = &device_list;
2000 list_for_each_entry(remote_adev,
2001 device_list_handle, gmc.xgmi.head) {
2002 amdgpu_ras_query_err_status(remote_adev);
2003 amdgpu_ras_log_on_err_counter(remote_adev);
2006 amdgpu_put_xgmi_hive(hive);
2009 if (amdgpu_device_should_recover_gpu(ras->adev)) {
2010 struct amdgpu_reset_context reset_context;
2011 memset(&reset_context, 0, sizeof(reset_context));
2013 reset_context.method = AMD_RESET_METHOD_NONE;
2014 reset_context.reset_req_dev = adev;
2016 /* Perform full reset in fatal error mode */
2017 if (!amdgpu_ras_is_poison_mode_supported(ras->adev))
2018 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
2020 clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
2022 amdgpu_device_gpu_recover(ras->adev, NULL, &reset_context);
2024 atomic_set(&ras->in_recovery, 0);
2027 /* alloc/realloc bps array */
2028 static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
2029 struct ras_err_handler_data *data, int pages)
2031 unsigned int old_space = data->count + data->space_left;
2032 unsigned int new_space = old_space + pages;
2033 unsigned int align_space = ALIGN(new_space, 512);
2034 void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
2041 memcpy(bps, data->bps,
2042 data->count * sizeof(*data->bps));
2047 data->space_left += align_space - old_space;
2051 /* it deal with vram only. */
2052 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
2053 struct eeprom_table_record *bps, int pages)
2055 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2056 struct ras_err_handler_data *data;
2060 if (!con || !con->eh_data || !bps || pages <= 0)
2063 mutex_lock(&con->recovery_lock);
2064 data = con->eh_data;
2068 for (i = 0; i < pages; i++) {
2069 if (amdgpu_ras_check_bad_page_unlock(con,
2070 bps[i].retired_page << AMDGPU_GPU_PAGE_SHIFT))
2073 if (!data->space_left &&
2074 amdgpu_ras_realloc_eh_data_space(adev, data, 256)) {
2079 amdgpu_vram_mgr_reserve_range(&adev->mman.vram_mgr,
2080 bps[i].retired_page << AMDGPU_GPU_PAGE_SHIFT,
2081 AMDGPU_GPU_PAGE_SIZE);
2083 memcpy(&data->bps[data->count], &bps[i], sizeof(*data->bps));
2088 mutex_unlock(&con->recovery_lock);
2094 * write error record array to eeprom, the function should be
2095 * protected by recovery_lock
2096 * new_cnt: new added UE count, excluding reserved bad pages, can be NULL
2098 int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev,
2099 unsigned long *new_cnt)
2101 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2102 struct ras_err_handler_data *data;
2103 struct amdgpu_ras_eeprom_control *control;
2106 if (!con || !con->eh_data) {
2113 mutex_lock(&con->recovery_lock);
2114 control = &con->eeprom_control;
2115 data = con->eh_data;
2116 save_count = data->count - control->ras_num_recs;
2117 mutex_unlock(&con->recovery_lock);
2120 *new_cnt = save_count / adev->umc.retire_unit;
2122 /* only new entries are saved */
2123 if (save_count > 0) {
2124 if (amdgpu_ras_eeprom_append(control,
2125 &data->bps[control->ras_num_recs],
2127 dev_err(adev->dev, "Failed to save EEPROM table data!");
2131 dev_info(adev->dev, "Saved %d pages to EEPROM table.\n", save_count);
2138 * read error record array in eeprom and reserve enough space for
2139 * storing new bad pages
2141 static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
2143 struct amdgpu_ras_eeprom_control *control =
2144 &adev->psp.ras_context.ras->eeprom_control;
2145 struct eeprom_table_record *bps;
2148 /* no bad page record, skip eeprom access */
2149 if (control->ras_num_recs == 0 || amdgpu_bad_page_threshold == 0)
2152 bps = kcalloc(control->ras_num_recs, sizeof(*bps), GFP_KERNEL);
2156 ret = amdgpu_ras_eeprom_read(control, bps, control->ras_num_recs);
2158 dev_err(adev->dev, "Failed to load EEPROM table records!");
2160 ret = amdgpu_ras_add_bad_pages(adev, bps, control->ras_num_recs);
2166 static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
2169 struct ras_err_handler_data *data = con->eh_data;
2172 addr >>= AMDGPU_GPU_PAGE_SHIFT;
2173 for (i = 0; i < data->count; i++)
2174 if (addr == data->bps[i].retired_page)
2181 * check if an address belongs to bad page
2183 * Note: this check is only for umc block
2185 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
2188 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2191 if (!con || !con->eh_data)
2194 mutex_lock(&con->recovery_lock);
2195 ret = amdgpu_ras_check_bad_page_unlock(con, addr);
2196 mutex_unlock(&con->recovery_lock);
2200 static void amdgpu_ras_validate_threshold(struct amdgpu_device *adev,
2203 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2206 * Justification of value bad_page_cnt_threshold in ras structure
2208 * Generally, 0 <= amdgpu_bad_page_threshold <= max record length
2209 * in eeprom or amdgpu_bad_page_threshold == -2, introduce two
2210 * scenarios accordingly.
2212 * Bad page retirement enablement:
2213 * - If amdgpu_bad_page_threshold = -2,
2214 * bad_page_cnt_threshold = typical value by formula.
2216 * - When the value from user is 0 < amdgpu_bad_page_threshold <
2217 * max record length in eeprom, use it directly.
2219 * Bad page retirement disablement:
2220 * - If amdgpu_bad_page_threshold = 0, bad page retirement
2221 * functionality is disabled, and bad_page_cnt_threshold will
2225 if (amdgpu_bad_page_threshold < 0) {
2226 u64 val = adev->gmc.mc_vram_size;
2228 do_div(val, RAS_BAD_PAGE_COVER);
2229 con->bad_page_cnt_threshold = min(lower_32_bits(val),
2232 con->bad_page_cnt_threshold = min_t(int, max_count,
2233 amdgpu_bad_page_threshold);
2237 int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
2239 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2240 struct ras_err_handler_data **data;
2241 u32 max_eeprom_records_count = 0;
2242 bool exc_err_limit = false;
2245 if (!con || amdgpu_sriov_vf(adev))
2248 /* Allow access to RAS EEPROM via debugfs, when the ASIC
2249 * supports RAS and debugfs is enabled, but when
2250 * adev->ras_enabled is unset, i.e. when "ras_enable"
2251 * module parameter is set to 0.
2255 if (!adev->ras_enabled)
2258 data = &con->eh_data;
2259 *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO);
2265 mutex_init(&con->recovery_lock);
2266 INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
2267 atomic_set(&con->in_recovery, 0);
2268 con->eeprom_control.bad_channel_bitmap = 0;
2270 max_eeprom_records_count = amdgpu_ras_eeprom_max_record_count();
2271 amdgpu_ras_validate_threshold(adev, max_eeprom_records_count);
2273 /* Todo: During test the SMU might fail to read the eeprom through I2C
2274 * when the GPU is pending on XGMI reset during probe time
2275 * (Mostly after second bus reset), skip it now
2277 if (adev->gmc.xgmi.pending_reset)
2279 ret = amdgpu_ras_eeprom_init(&con->eeprom_control, &exc_err_limit);
2281 * This calling fails when exc_err_limit is true or
2284 if (exc_err_limit || ret)
2287 if (con->eeprom_control.ras_num_recs) {
2288 ret = amdgpu_ras_load_bad_pages(adev);
2292 amdgpu_dpm_send_hbm_bad_pages_num(adev, con->eeprom_control.ras_num_recs);
2294 if (con->update_channel_flag == true) {
2295 amdgpu_dpm_send_hbm_bad_channel_flag(adev, con->eeprom_control.bad_channel_bitmap);
2296 con->update_channel_flag = false;
2300 #ifdef CONFIG_X86_MCE_AMD
2301 if ((adev->asic_type == CHIP_ALDEBARAN) &&
2302 (adev->gmc.xgmi.connected_to_cpu))
2303 amdgpu_register_bad_pages_mca_notifier(adev);
2308 kfree((*data)->bps);
2310 con->eh_data = NULL;
2312 dev_warn(adev->dev, "Failed to initialize ras recovery! (%d)\n", ret);
2315 * Except error threshold exceeding case, other failure cases in this
2316 * function would not fail amdgpu driver init.
2326 static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
2328 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2329 struct ras_err_handler_data *data = con->eh_data;
2331 /* recovery_init failed to init it, fini is useless */
2335 cancel_work_sync(&con->recovery_work);
2337 mutex_lock(&con->recovery_lock);
2338 con->eh_data = NULL;
2341 mutex_unlock(&con->recovery_lock);
2347 static bool amdgpu_ras_asic_supported(struct amdgpu_device *adev)
2349 if (amdgpu_sriov_vf(adev)) {
2350 switch (adev->ip_versions[MP0_HWIP][0]) {
2351 case IP_VERSION(13, 0, 2):
2358 if (adev->asic_type == CHIP_IP_DISCOVERY) {
2359 switch (adev->ip_versions[MP0_HWIP][0]) {
2360 case IP_VERSION(13, 0, 0):
2361 case IP_VERSION(13, 0, 10):
2368 return adev->asic_type == CHIP_VEGA10 ||
2369 adev->asic_type == CHIP_VEGA20 ||
2370 adev->asic_type == CHIP_ARCTURUS ||
2371 adev->asic_type == CHIP_ALDEBARAN ||
2372 adev->asic_type == CHIP_SIENNA_CICHLID;
2376 * this is workaround for vega20 workstation sku,
2377 * force enable gfx ras, ignore vbios gfx ras flag
2378 * due to GC EDC can not write
2380 static void amdgpu_ras_get_quirks(struct amdgpu_device *adev)
2382 struct atom_context *ctx = adev->mode_info.atom_context;
2387 if (strnstr(ctx->vbios_version, "D16406",
2388 sizeof(ctx->vbios_version)) ||
2389 strnstr(ctx->vbios_version, "D36002",
2390 sizeof(ctx->vbios_version)))
2391 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__GFX);
2395 * check hardware's ras ability which will be saved in hw_supported.
2396 * if hardware does not support ras, we can skip some ras initializtion and
2397 * forbid some ras operations from IP.
2398 * if software itself, say boot parameter, limit the ras ability. We still
2399 * need allow IP do some limited operations, like disable. In such case,
2400 * we have to initialize ras as normal. but need check if operation is
2401 * allowed or not in each function.
2403 static void amdgpu_ras_check_supported(struct amdgpu_device *adev)
2405 adev->ras_hw_enabled = adev->ras_enabled = 0;
2407 if (!adev->is_atom_fw ||
2408 !amdgpu_ras_asic_supported(adev))
2411 if (!adev->gmc.xgmi.connected_to_cpu) {
2412 if (amdgpu_atomfirmware_mem_ecc_supported(adev)) {
2413 dev_info(adev->dev, "MEM ECC is active.\n");
2414 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__UMC |
2415 1 << AMDGPU_RAS_BLOCK__DF);
2417 dev_info(adev->dev, "MEM ECC is not presented.\n");
2420 if (amdgpu_atomfirmware_sram_ecc_supported(adev)) {
2421 dev_info(adev->dev, "SRAM ECC is active.\n");
2422 if (!amdgpu_sriov_vf(adev))
2423 adev->ras_hw_enabled |= ~(1 << AMDGPU_RAS_BLOCK__UMC |
2424 1 << AMDGPU_RAS_BLOCK__DF);
2426 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__PCIE_BIF |
2427 1 << AMDGPU_RAS_BLOCK__SDMA |
2428 1 << AMDGPU_RAS_BLOCK__GFX);
2430 /* VCN/JPEG RAS can be supported on both bare metal and
2433 if (adev->ip_versions[VCN_HWIP][0] == IP_VERSION(2, 6, 0) ||
2434 adev->ip_versions[VCN_HWIP][0] == IP_VERSION(4, 0, 0))
2435 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__VCN |
2436 1 << AMDGPU_RAS_BLOCK__JPEG);
2438 adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__VCN |
2439 1 << AMDGPU_RAS_BLOCK__JPEG);
2442 * XGMI RAS is not supported if xgmi num physical nodes
2445 if (!adev->gmc.xgmi.num_physical_nodes)
2446 adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__XGMI_WAFL);
2448 dev_info(adev->dev, "SRAM ECC is not presented.\n");
2451 /* driver only manages a few IP blocks RAS feature
2452 * when GPU is connected cpu through XGMI */
2453 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__GFX |
2454 1 << AMDGPU_RAS_BLOCK__SDMA |
2455 1 << AMDGPU_RAS_BLOCK__MMHUB);
2458 amdgpu_ras_get_quirks(adev);
2460 /* hw_supported needs to be aligned with RAS block mask. */
2461 adev->ras_hw_enabled &= AMDGPU_RAS_BLOCK_MASK;
2463 adev->ras_enabled = amdgpu_ras_enable == 0 ? 0 :
2464 adev->ras_hw_enabled & amdgpu_ras_mask;
2467 static void amdgpu_ras_counte_dw(struct work_struct *work)
2469 struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
2470 ras_counte_delay_work.work);
2471 struct amdgpu_device *adev = con->adev;
2472 struct drm_device *dev = adev_to_drm(adev);
2473 unsigned long ce_count, ue_count;
2476 res = pm_runtime_get_sync(dev->dev);
2480 /* Cache new values.
2482 if (amdgpu_ras_query_error_count(adev, &ce_count, &ue_count, NULL) == 0) {
2483 atomic_set(&con->ras_ce_count, ce_count);
2484 atomic_set(&con->ras_ue_count, ue_count);
2487 pm_runtime_mark_last_busy(dev->dev);
2489 pm_runtime_put_autosuspend(dev->dev);
2492 static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
2494 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2495 bool df_poison, umc_poison;
2497 /* poison setting is useless on SRIOV guest */
2498 if (amdgpu_sriov_vf(adev) || !con)
2501 /* Init poison supported flag, the default value is false */
2502 if (adev->gmc.xgmi.connected_to_cpu) {
2503 /* enabled by default when GPU is connected to CPU */
2504 con->poison_supported = true;
2505 } else if (adev->df.funcs &&
2506 adev->df.funcs->query_ras_poison_mode &&
2508 adev->umc.ras->query_ras_poison_mode) {
2510 adev->df.funcs->query_ras_poison_mode(adev);
2512 adev->umc.ras->query_ras_poison_mode(adev);
2514 /* Only poison is set in both DF and UMC, we can support it */
2515 if (df_poison && umc_poison)
2516 con->poison_supported = true;
2517 else if (df_poison != umc_poison)
2519 "Poison setting is inconsistent in DF/UMC(%d:%d)!\n",
2520 df_poison, umc_poison);
2524 int amdgpu_ras_init(struct amdgpu_device *adev)
2526 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2532 con = kmalloc(sizeof(struct amdgpu_ras) +
2533 sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COUNT +
2534 sizeof(struct ras_manager) * AMDGPU_RAS_MCA_BLOCK_COUNT,
2535 GFP_KERNEL|__GFP_ZERO);
2540 INIT_DELAYED_WORK(&con->ras_counte_delay_work, amdgpu_ras_counte_dw);
2541 atomic_set(&con->ras_ce_count, 0);
2542 atomic_set(&con->ras_ue_count, 0);
2544 con->objs = (struct ras_manager *)(con + 1);
2546 amdgpu_ras_set_context(adev, con);
2548 amdgpu_ras_check_supported(adev);
2550 if (!adev->ras_enabled || adev->asic_type == CHIP_VEGA10) {
2551 /* set gfx block ras context feature for VEGA20 Gaming
2552 * send ras disable cmd to ras ta during ras late init.
2554 if (!adev->ras_enabled && adev->asic_type == CHIP_VEGA20) {
2555 con->features |= BIT(AMDGPU_RAS_BLOCK__GFX);
2564 con->update_channel_flag = false;
2566 INIT_LIST_HEAD(&con->head);
2567 /* Might need get this flag from vbios. */
2568 con->flags = RAS_DEFAULT_FLAGS;
2570 /* initialize nbio ras function ahead of any other
2571 * ras functions so hardware fatal error interrupt
2572 * can be enabled as early as possible */
2573 switch (adev->ip_versions[NBIO_HWIP][0]) {
2574 case IP_VERSION(7, 4, 0):
2575 case IP_VERSION(7, 4, 1):
2576 case IP_VERSION(7, 4, 4):
2577 if (!adev->gmc.xgmi.connected_to_cpu)
2578 adev->nbio.ras = &nbio_v7_4_ras;
2580 case IP_VERSION(4, 3, 0):
2581 if (adev->ras_hw_enabled & (1 << AMDGPU_RAS_BLOCK__DF))
2582 /* unlike other generation of nbio ras,
2583 * nbio v4_3 only support fatal error interrupt
2584 * to inform software that DF is freezed due to
2585 * system fatal error event. driver should not
2586 * enable nbio ras in such case. Instead,
2588 adev->nbio.ras = &nbio_v4_3_ras;
2591 /* nbio ras is not available */
2595 /* nbio ras block needs to be enabled ahead of other ras blocks
2596 * to handle fatal error */
2597 r = amdgpu_nbio_ras_sw_init(adev);
2601 if (adev->nbio.ras &&
2602 adev->nbio.ras->init_ras_controller_interrupt) {
2603 r = adev->nbio.ras->init_ras_controller_interrupt(adev);
2608 if (adev->nbio.ras &&
2609 adev->nbio.ras->init_ras_err_event_athub_interrupt) {
2610 r = adev->nbio.ras->init_ras_err_event_athub_interrupt(adev);
2615 amdgpu_ras_query_poison_mode(adev);
2617 if (amdgpu_ras_fs_init(adev)) {
2622 dev_info(adev->dev, "RAS INFO: ras initialized successfully, "
2623 "hardware ability[%x] ras_mask[%x]\n",
2624 adev->ras_hw_enabled, adev->ras_enabled);
2628 amdgpu_ras_set_context(adev, NULL);
2634 int amdgpu_persistent_edc_harvesting_supported(struct amdgpu_device *adev)
2636 if (adev->gmc.xgmi.connected_to_cpu ||
2637 adev->gmc.is_app_apu)
2642 static int amdgpu_persistent_edc_harvesting(struct amdgpu_device *adev,
2643 struct ras_common_if *ras_block)
2645 struct ras_query_if info = {
2649 if (!amdgpu_persistent_edc_harvesting_supported(adev))
2652 if (amdgpu_ras_query_error_status(adev, &info) != 0)
2653 DRM_WARN("RAS init harvest failure");
2655 if (amdgpu_ras_reset_error_status(adev, ras_block->block) != 0)
2656 DRM_WARN("RAS init harvest reset failure");
2661 bool amdgpu_ras_is_poison_mode_supported(struct amdgpu_device *adev)
2663 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2668 return con->poison_supported;
2671 /* helper function to handle common stuff in ip late init phase */
2672 int amdgpu_ras_block_late_init(struct amdgpu_device *adev,
2673 struct ras_common_if *ras_block)
2675 struct amdgpu_ras_block_object *ras_obj = NULL;
2676 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2677 struct ras_query_if *query_info;
2678 unsigned long ue_count, ce_count;
2681 /* disable RAS feature per IP block if it is not supported */
2682 if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
2683 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
2687 r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1);
2689 if (adev->in_suspend || amdgpu_in_reset(adev)) {
2690 /* in resume phase, if fail to enable ras,
2691 * clean up all ras fs nodes, and disable ras */
2697 /* check for errors on warm reset edc persisant supported ASIC */
2698 amdgpu_persistent_edc_harvesting(adev, ras_block);
2700 /* in resume phase, no need to create ras fs node */
2701 if (adev->in_suspend || amdgpu_in_reset(adev))
2704 ras_obj = container_of(ras_block, struct amdgpu_ras_block_object, ras_comm);
2705 if (ras_obj->ras_cb || (ras_obj->hw_ops &&
2706 (ras_obj->hw_ops->query_poison_status ||
2707 ras_obj->hw_ops->handle_poison_consumption))) {
2708 r = amdgpu_ras_interrupt_add_handler(adev, ras_block);
2713 r = amdgpu_ras_sysfs_create(adev, ras_block);
2717 /* Those are the cached values at init.
2719 query_info = kzalloc(sizeof(struct ras_query_if), GFP_KERNEL);
2722 memcpy(&query_info->head, ras_block, sizeof(struct ras_common_if));
2724 if (amdgpu_ras_query_error_count(adev, &ce_count, &ue_count, query_info) == 0) {
2725 atomic_set(&con->ras_ce_count, ce_count);
2726 atomic_set(&con->ras_ue_count, ue_count);
2733 if (ras_obj->ras_cb)
2734 amdgpu_ras_interrupt_remove_handler(adev, ras_block);
2736 amdgpu_ras_feature_enable(adev, ras_block, 0);
2740 static int amdgpu_ras_block_late_init_default(struct amdgpu_device *adev,
2741 struct ras_common_if *ras_block)
2743 return amdgpu_ras_block_late_init(adev, ras_block);
2746 /* helper function to remove ras fs node and interrupt handler */
2747 void amdgpu_ras_block_late_fini(struct amdgpu_device *adev,
2748 struct ras_common_if *ras_block)
2750 struct amdgpu_ras_block_object *ras_obj;
2754 amdgpu_ras_sysfs_remove(adev, ras_block);
2756 ras_obj = container_of(ras_block, struct amdgpu_ras_block_object, ras_comm);
2757 if (ras_obj->ras_cb)
2758 amdgpu_ras_interrupt_remove_handler(adev, ras_block);
2761 static void amdgpu_ras_block_late_fini_default(struct amdgpu_device *adev,
2762 struct ras_common_if *ras_block)
2764 return amdgpu_ras_block_late_fini(adev, ras_block);
2767 /* do some init work after IP late init as dependence.
2768 * and it runs in resume/gpu reset/booting up cases.
2770 void amdgpu_ras_resume(struct amdgpu_device *adev)
2772 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2773 struct ras_manager *obj, *tmp;
2775 if (!adev->ras_enabled || !con) {
2776 /* clean ras context for VEGA20 Gaming after send ras disable cmd */
2777 amdgpu_release_ras_context(adev);
2782 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
2783 /* Set up all other IPs which are not implemented. There is a
2784 * tricky thing that IP's actual ras error type should be
2785 * MULTI_UNCORRECTABLE, but as driver does not handle it, so
2786 * ERROR_NONE make sense anyway.
2788 amdgpu_ras_enable_all_features(adev, 1);
2790 /* We enable ras on all hw_supported block, but as boot
2791 * parameter might disable some of them and one or more IP has
2792 * not implemented yet. So we disable them on behalf.
2794 list_for_each_entry_safe(obj, tmp, &con->head, node) {
2795 if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
2796 amdgpu_ras_feature_enable(adev, &obj->head, 0);
2797 /* there should be no any reference. */
2798 WARN_ON(alive_obj(obj));
2804 void amdgpu_ras_suspend(struct amdgpu_device *adev)
2806 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2808 if (!adev->ras_enabled || !con)
2811 amdgpu_ras_disable_all_features(adev, 0);
2812 /* Make sure all ras objects are disabled. */
2814 amdgpu_ras_disable_all_features(adev, 1);
2817 int amdgpu_ras_late_init(struct amdgpu_device *adev)
2819 struct amdgpu_ras_block_list *node, *tmp;
2820 struct amdgpu_ras_block_object *obj;
2823 /* Guest side doesn't need init ras feature */
2824 if (amdgpu_sriov_vf(adev))
2827 list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
2828 if (!node->ras_obj) {
2829 dev_warn(adev->dev, "Warning: abnormal ras list node.\n");
2833 obj = node->ras_obj;
2834 if (obj->ras_late_init) {
2835 r = obj->ras_late_init(adev, &obj->ras_comm);
2837 dev_err(adev->dev, "%s failed to execute ras_late_init! ret:%d\n",
2838 obj->ras_comm.name, r);
2842 amdgpu_ras_block_late_init_default(adev, &obj->ras_comm);
2848 /* do some fini work before IP fini as dependence */
2849 int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
2851 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2853 if (!adev->ras_enabled || !con)
2857 /* Need disable ras on all IPs here before ip [hw/sw]fini */
2859 amdgpu_ras_disable_all_features(adev, 0);
2860 amdgpu_ras_recovery_fini(adev);
2864 int amdgpu_ras_fini(struct amdgpu_device *adev)
2866 struct amdgpu_ras_block_list *ras_node, *tmp;
2867 struct amdgpu_ras_block_object *obj = NULL;
2868 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2870 if (!adev->ras_enabled || !con)
2873 list_for_each_entry_safe(ras_node, tmp, &adev->ras_list, node) {
2874 if (ras_node->ras_obj) {
2875 obj = ras_node->ras_obj;
2876 if (amdgpu_ras_is_supported(adev, obj->ras_comm.block) &&
2878 obj->ras_fini(adev, &obj->ras_comm);
2880 amdgpu_ras_block_late_fini_default(adev, &obj->ras_comm);
2883 /* Clear ras blocks from ras_list and free ras block list node */
2884 list_del(&ras_node->node);
2888 amdgpu_ras_fs_fini(adev);
2889 amdgpu_ras_interrupt_remove_all(adev);
2891 WARN(con->features, "Feature mask is not cleared");
2894 amdgpu_ras_disable_all_features(adev, 1);
2896 cancel_delayed_work_sync(&con->ras_counte_delay_work);
2898 amdgpu_ras_set_context(adev, NULL);
2904 void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
2906 amdgpu_ras_check_supported(adev);
2907 if (!adev->ras_hw_enabled)
2910 if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
2911 dev_info(adev->dev, "uncorrectable hardware error"
2912 "(ERREVENT_ATHUB_INTERRUPT) detected!\n");
2914 amdgpu_ras_reset_gpu(adev);
2918 bool amdgpu_ras_need_emergency_restart(struct amdgpu_device *adev)
2920 if (adev->asic_type == CHIP_VEGA20 &&
2921 adev->pm.fw_version <= 0x283400) {
2922 return !(amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) &&
2923 amdgpu_ras_intr_triggered();
2929 void amdgpu_release_ras_context(struct amdgpu_device *adev)
2931 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2936 if (!adev->ras_enabled && con->features & BIT(AMDGPU_RAS_BLOCK__GFX)) {
2937 con->features &= ~BIT(AMDGPU_RAS_BLOCK__GFX);
2938 amdgpu_ras_set_context(adev, NULL);
2943 #ifdef CONFIG_X86_MCE_AMD
2944 static struct amdgpu_device *find_adev(uint32_t node_id)
2947 struct amdgpu_device *adev = NULL;
2949 for (i = 0; i < mce_adev_list.num_gpu; i++) {
2950 adev = mce_adev_list.devs[i];
2952 if (adev && adev->gmc.xgmi.connected_to_cpu &&
2953 adev->gmc.xgmi.physical_node_id == node_id)
2961 #define GET_MCA_IPID_GPUID(m) (((m) >> 44) & 0xF)
2962 #define GET_UMC_INST(m) (((m) >> 21) & 0x7)
2963 #define GET_CHAN_INDEX(m) ((((m) >> 12) & 0x3) | (((m) >> 18) & 0x4))
2964 #define GPU_ID_OFFSET 8
2966 static int amdgpu_bad_page_notifier(struct notifier_block *nb,
2967 unsigned long val, void *data)
2969 struct mce *m = (struct mce *)data;
2970 struct amdgpu_device *adev = NULL;
2971 uint32_t gpu_id = 0;
2972 uint32_t umc_inst = 0, ch_inst = 0;
2975 * If the error was generated in UMC_V2, which belongs to GPU UMCs,
2976 * and error occurred in DramECC (Extended error code = 0) then only
2977 * process the error, else bail out.
2979 if (!m || !((smca_get_bank_type(m->extcpu, m->bank) == SMCA_UMC_V2) &&
2980 (XEC(m->status, 0x3f) == 0x0)))
2984 * If it is correctable error, return.
2986 if (mce_is_correctable(m))
2990 * GPU Id is offset by GPU_ID_OFFSET in MCA_IPID_UMC register.
2992 gpu_id = GET_MCA_IPID_GPUID(m->ipid) - GPU_ID_OFFSET;
2994 adev = find_adev(gpu_id);
2996 DRM_WARN("%s: Unable to find adev for gpu_id: %d\n", __func__,
3002 * If it is uncorrectable error, then find out UMC instance and
3005 umc_inst = GET_UMC_INST(m->ipid);
3006 ch_inst = GET_CHAN_INDEX(m->ipid);
3008 dev_info(adev->dev, "Uncorrectable error detected in UMC inst: %d, chan_idx: %d",
3011 if (!amdgpu_umc_page_retirement_mca(adev, m->addr, ch_inst, umc_inst))
3017 static struct notifier_block amdgpu_bad_page_nb = {
3018 .notifier_call = amdgpu_bad_page_notifier,
3019 .priority = MCE_PRIO_UC,
3022 static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev)
3025 * Add the adev to the mce_adev_list.
3026 * During mode2 reset, amdgpu device is temporarily
3027 * removed from the mgpu_info list which can cause
3028 * page retirement to fail.
3029 * Use this list instead of mgpu_info to find the amdgpu
3030 * device on which the UMC error was reported.
3032 mce_adev_list.devs[mce_adev_list.num_gpu++] = adev;
3035 * Register the x86 notifier only once
3036 * with MCE subsystem.
3038 if (notifier_registered == false) {
3039 mce_register_decode_chain(&amdgpu_bad_page_nb);
3040 notifier_registered = true;
3045 struct amdgpu_ras *amdgpu_ras_get_context(struct amdgpu_device *adev)
3050 return adev->psp.ras_context.ras;
3053 int amdgpu_ras_set_context(struct amdgpu_device *adev, struct amdgpu_ras *ras_con)
3058 adev->psp.ras_context.ras = ras_con;
3062 /* check if ras is supported on block, say, sdma, gfx */
3063 int amdgpu_ras_is_supported(struct amdgpu_device *adev,
3067 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
3069 if (block >= AMDGPU_RAS_BLOCK_COUNT)
3072 ret = ras && (adev->ras_enabled & (1 << block));
3074 /* For the special asic with mem ecc enabled but sram ecc
3075 * not enabled, even if the ras block is not supported on
3076 * .ras_enabled, if the asic supports poison mode and the
3077 * ras block has ras configuration, it can be considered
3078 * that the ras block supports ras function.
3081 amdgpu_ras_is_poison_mode_supported(adev) &&
3082 amdgpu_ras_get_ras_block(adev, block, 0))
3088 int amdgpu_ras_reset_gpu(struct amdgpu_device *adev)
3090 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
3092 if (atomic_cmpxchg(&ras->in_recovery, 0, 1) == 0)
3093 amdgpu_reset_domain_schedule(ras->adev->reset_domain, &ras->recovery_work);
3098 /* Register each ip ras block into amdgpu ras */
3099 int amdgpu_ras_register_ras_block(struct amdgpu_device *adev,
3100 struct amdgpu_ras_block_object *ras_block_obj)
3102 struct amdgpu_ras_block_list *ras_node;
3103 if (!adev || !ras_block_obj)
3106 ras_node = kzalloc(sizeof(*ras_node), GFP_KERNEL);
3110 INIT_LIST_HEAD(&ras_node->node);
3111 ras_node->ras_obj = ras_block_obj;
3112 list_add_tail(&ras_node->node, &adev->ras_list);
3117 void amdgpu_ras_get_error_type_name(uint32_t err_type, char *err_type_name)
3123 case AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE:
3124 sprintf(err_type_name, "correctable");
3126 case AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE:
3127 sprintf(err_type_name, "uncorrectable");
3130 sprintf(err_type_name, "unknown");
3135 bool amdgpu_ras_inst_get_memory_id_field(struct amdgpu_device *adev,
3136 const struct amdgpu_ras_err_status_reg_entry *reg_entry,
3138 uint32_t *memory_id)
3140 uint32_t err_status_lo_data, err_status_lo_offset;
3145 err_status_lo_offset =
3146 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_entry->hwip, instance,
3147 reg_entry->seg_lo, reg_entry->reg_lo);
3148 err_status_lo_data = RREG32(err_status_lo_offset);
3150 if ((reg_entry->flags & AMDGPU_RAS_ERR_STATUS_VALID) &&
3151 !REG_GET_FIELD(err_status_lo_data, ERR_STATUS_LO, ERR_STATUS_VALID_FLAG))
3154 *memory_id = REG_GET_FIELD(err_status_lo_data, ERR_STATUS_LO, MEMORY_ID);
3159 bool amdgpu_ras_inst_get_err_cnt_field(struct amdgpu_device *adev,
3160 const struct amdgpu_ras_err_status_reg_entry *reg_entry,
3162 unsigned long *err_cnt)
3164 uint32_t err_status_hi_data, err_status_hi_offset;
3169 err_status_hi_offset =
3170 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_entry->hwip, instance,
3171 reg_entry->seg_hi, reg_entry->reg_hi);
3172 err_status_hi_data = RREG32(err_status_hi_offset);
3174 if ((reg_entry->flags & AMDGPU_RAS_ERR_INFO_VALID) &&
3175 !REG_GET_FIELD(err_status_hi_data, ERR_STATUS_HI, ERR_INFO_VALID_FLAG))
3176 /* keep the check here in case we need to refer to the result later */
3177 dev_dbg(adev->dev, "Invalid err_info field\n");
3179 /* read err count */
3180 *err_cnt = REG_GET_FIELD(err_status_hi_data, ERR_STATUS, ERR_CNT);
3185 void amdgpu_ras_inst_query_ras_error_count(struct amdgpu_device *adev,
3186 const struct amdgpu_ras_err_status_reg_entry *reg_list,
3187 uint32_t reg_list_size,
3188 const struct amdgpu_ras_memory_id_entry *mem_list,
3189 uint32_t mem_list_size,
3192 unsigned long *err_count)
3195 unsigned long err_cnt;
3196 char err_type_name[16];
3199 for (i = 0; i < reg_list_size; i++) {
3200 /* query memory_id from err_status_lo */
3201 if (!amdgpu_ras_inst_get_memory_id_field(adev, ®_list[i],
3202 instance, &memory_id))
3205 /* query err_cnt from err_status_hi */
3206 if (!amdgpu_ras_inst_get_err_cnt_field(adev, ®_list[i],
3207 instance, &err_cnt) ||
3211 *err_count += err_cnt;
3213 /* log the errors */
3214 amdgpu_ras_get_error_type_name(err_type, err_type_name);
3216 /* memory_list is not supported */
3218 "%ld %s hardware errors detected in %s, instance: %d, memory_id: %d\n",
3219 err_cnt, err_type_name,
3220 reg_list[i].block_name,
3221 instance, memory_id);
3223 for (j = 0; j < mem_list_size; j++) {
3224 if (memory_id == mem_list[j].memory_id) {
3226 "%ld %s hardware errors detected in %s, instance: %d, memory block: %s\n",
3227 err_cnt, err_type_name,
3228 reg_list[i].block_name,
3229 instance, mem_list[j].name);
3237 void amdgpu_ras_inst_reset_ras_error_count(struct amdgpu_device *adev,
3238 const struct amdgpu_ras_err_status_reg_entry *reg_list,
3239 uint32_t reg_list_size,
3242 uint32_t err_status_lo_offset, err_status_hi_offset;
3245 for (i = 0; i < reg_list_size; i++) {
3246 err_status_lo_offset =
3247 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_list[i].hwip, instance,
3248 reg_list[i].seg_lo, reg_list[i].reg_lo);
3249 err_status_hi_offset =
3250 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_list[i].hwip, instance,
3251 reg_list[i].seg_hi, reg_list[i].reg_hi);
3252 WREG32(err_status_lo_offset, 0);
3253 WREG32(err_status_hi_offset, 0);