/* * Copyright 2018 Advanced Micro Devices, Inc. * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. * *
*/ #include <linux/debugfs.h> #include <linux/list.h> #include <linux/module.h> #include <linux/uaccess.h> #include <linux/reboot.h> #include <linux/syscalls.h> #include <linux/pm_runtime.h> #include <linux/list_sort.h>
dev_warn(adev->dev, "WARNING: THIS IS ONLY FOR TEST PURPOSES AND WILL CORRUPT RAS EEPROM\n");
dev_warn(adev->dev, "Clear EEPROM:\n");
dev_warn(adev->dev, " echo 1 > /sys/kernel/debug/dri/0/ras/ras_eeprom_reset\n");
if (amdgpu_ras_query_error_status(obj->adev, &info)) return -EINVAL;
/* Hardware counter will be reset automatically after the query on Vega20 and Arcturus */ if (amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) { if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
}
s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n", "ue", info.ue_count, "ce", info.ce_count); if (*pos >= s) return 0;
s -= *pos;
s = min_t(u64, s, size);
if (copy_to_user(buf, &val[*pos], s)) return -EINVAL;
staticint amdgpu_ras_find_block_id_by_name(constchar *name, int *block_id)
{ int i;
for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
*block_id = i; if (strcmp(name, ras_block_string[i]) == 0) return 0;
} return -EINVAL;
}
staticint amdgpu_ras_debugfs_ctrl_parse_data(struct file *f, constchar __user *buf, size_t size,
loff_t *pos, struct ras_debug_if *data)
{
ssize_t s = min_t(u64, 64, size); char str[65]; char block_name[33]; char err[9] = "ue"; int op = -1; int block_id;
uint32_t sub_block;
u64 address, value; /* default value is 0 if the mask is not set by user */
u32 instance_mask = 0;
/* no need to set instance mask if there is only one instance */ if (num_xcc <= 1 && inst_mask) {
data->inject.instance_mask = 0;
dev_dbg(adev->dev, "RAS inject mask(0x%x) isn't supported and force it to 0.\n",
inst_mask);
return;
}
switch (data->head.block) { case AMDGPU_RAS_BLOCK__GFX:
mask = GENMASK(num_xcc - 1, 0); break; case AMDGPU_RAS_BLOCK__SDMA:
mask = GENMASK(adev->sdma.num_instances - 1, 0); break; case AMDGPU_RAS_BLOCK__VCN: case AMDGPU_RAS_BLOCK__JPEG:
mask = GENMASK(adev->vcn.num_vcn_inst - 1, 0); break; default:
mask = inst_mask; break;
}
/* remove invalid bits in instance mask */
data->inject.instance_mask &= mask; if (inst_mask != data->inject.instance_mask)
dev_dbg(adev->dev, "Adjust RAS inject mask 0x%x to 0x%x\n",
inst_mask, data->inject.instance_mask);
}
/** * DOC: AMDGPU RAS debugfs control interface * * The control interface accepts struct ras_debug_if which has two members. * * First member: ras_debug_if::head or ras_debug_if::inject. * * head is used to indicate which IP block will be under control. * * head has four members, they are block, type, sub_block_index, name. * block: which IP will be under control. * type: what kind of error will be enabled/disabled/injected. * sub_block_index: some IPs have subcomponets. say, GFX, sDMA. * name: the name of IP. * * inject has three more members than head, they are address, value and mask. * As their names indicate, inject operation will write the * value to the address. * * The second member: struct ras_debug_if::op. * It has three kinds of operations. * * - 0: disable RAS on the block. Take ::head as its data. * - 1: enable RAS on the block. Take ::head as its data. * - 2: inject errors on the block. Take ::inject as its data. * * How to use the interface? * * In a program * * Copy the struct ras_debug_if in your code and initialize it. * Write the struct to the control interface. * * From shell * * .. code-block:: bash * * echo "disable <block>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl * echo "enable <block> <error>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl * echo "inject <block> <error> <sub-block> <address> <value> <mask>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl * * Where N, is the card which you want to affect. * * "disable" requires only the block. * "enable" requires the block and error type. * "inject" requires the block, error type, address, and value. * * The block is one of: umc, sdma, gfx, etc. * see ras_block_string[] for details * * The error type is one of: ue, ce and poison where, * ue is multi-uncorrectable * ce is single-correctable * poison is poison * * The sub-block is a the sub-block index, pass 0 if there is no sub-block. * The address and value are hexadecimal numbers, leading 0x is optional. * The mask means instance mask, is optional, default value is 0x1. * * For instance, * * .. code-block:: bash * * echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl * echo inject umc ce 0 0 0 3 > /sys/kernel/debug/dri/0/ras/ras_ctrl * echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl * * How to check the result of the operation? * * To check disable/enable, see "ras" features at, * /sys/class/drm/card[0/1/2...]/device/ras/features * * To check inject, see the corresponding error count at, * /sys/class/drm/card[0/1/2...]/device/ras/[gfx|sdma|umc|...]_err_count * * .. note:: * Operations are only allowed on blocks which are supported. * Check the "ras" mask at /sys/module/amdgpu/parameters/ras_mask * to see which blocks support RAS on a particular asic. *
*/ static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f, constchar __user *buf,
size_t size, loff_t *pos)
{ struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private; struct ras_debug_if data; int ret = 0;
ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data); if (ret) return ret;
if (data.op == 3) {
ret = amdgpu_reserve_page_direct(adev, data.inject.address); if (!ret) return size; else return ret;
}
if (!amdgpu_ras_is_supported(adev, data.head.block)) return -EINVAL;
switch (data.op) { case 0:
ret = amdgpu_ras_feature_enable(adev, &data.head, 0); break; case 1:
ret = amdgpu_ras_feature_enable(adev, &data.head, 1); break; case 2: /* umc ce/ue error injection for a bad page is not allowed */ if (data.head.block == AMDGPU_RAS_BLOCK__UMC)
ret = amdgpu_ras_check_bad_page(adev, data.inject.address); if (ret == -EINVAL) {
dev_warn(adev->dev, "RAS WARN: input address 0x%llx is invalid.",
data.inject.address); break;
} elseif (ret == 1) {
dev_warn(adev->dev, "RAS WARN: inject: 0x%llx has already been marked as bad!\n",
data.inject.address); break;
}
amdgpu_ras_instance_mask_check(adev, &data);
/* data.inject.address is offset instead of absolute gpu address */
ret = amdgpu_ras_error_inject(adev, &data.inject); break; default:
ret = -EINVAL; break;
}
if (ret) return ret;
return size;
}
/** * DOC: AMDGPU RAS debugfs EEPROM table reset interface * * Some boards contain an EEPROM which is used to persistently store a list of * bad pages which experiences ECC errors in vram. This interface provides * a way to reset the EEPROM, e.g., after testing error injection. * * Usage: * * .. code-block:: bash * * echo 1 > ../ras/ras_eeprom_reset * * will reset EEPROM table to 0 entries. *
*/ static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f, constchar __user *buf,
size_t size, loff_t *pos)
{ struct amdgpu_device *adev =
(struct amdgpu_device *)file_inode(f)->i_private; int ret;
ret = amdgpu_ras_eeprom_reset_table(
&(amdgpu_ras_get_context(adev)->eeprom_control));
if (!ret) { /* Something was written to EEPROM.
*/
amdgpu_ras_get_context(adev)->flags = RAS_DEFAULT_FLAGS; return size;
} else { return ret;
}
}
/** * DOC: AMDGPU RAS sysfs Error Count Interface * * It allows the user to read the error count for each IP block on the gpu through * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count * * It outputs the multiple lines which report the uncorrected (ue) and corrected * (ce) error counts. * * The format of one line is below, * * [ce|ue]: count * * Example: * * .. code-block:: bash * * ue: 0 * ce: 1 *
*/ static ssize_t amdgpu_ras_sysfs_read(struct device *dev, struct device_attribute *attr, char *buf)
{ struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr); struct ras_query_if info = {
.head = obj->head,
};
if (!amdgpu_ras_get_error_query_ready(obj->adev)) return sysfs_emit(buf, "Query currently inaccessible\n");
if (amdgpu_ras_query_error_status(obj->adev, &info)) return -EINVAL;
if (amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) { if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
}
/* return an obj equal to head, or the first when head is NULL */ struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev, struct ras_common_if *head)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_manager *obj; int i;
if (!adev->ras_enabled || !con) return NULL;
if (head) { if (head->block >= AMDGPU_RAS_BLOCK_COUNT) return NULL;
if (head->block == AMDGPU_RAS_BLOCK__MCA) { if (head->sub_block_index >= AMDGPU_RAS_MCA_BLOCK__LAST) return NULL;
/* * if obj is not created, then create one. * set feature enable flag.
*/ staticint __amdgpu_ras_feature_enable(struct amdgpu_device *adev, struct ras_common_if *head, int enable)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
/* If hardware does not support ras, then do not create obj. * But if hardware support ras, we can create the obj. * Ras framework checks con->hw_supported to see if it need do * corresponding initialization. * IP checks con->support to see if it need disable ras.
*/ if (!amdgpu_ras_is_feature_allowed(adev, head)) return 0;
if (enable) { if (!obj) {
obj = amdgpu_ras_create_obj(adev, head); if (!obj) return -EINVAL;
} else { /* In case we create obj somewhere else */
get_obj(obj);
}
con->features |= BIT(head->block);
} else { if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
con->features &= ~BIT(head->block);
put_obj(obj);
}
}
return 0;
}
/* wrapper of psp_ras_enable_features */ int amdgpu_ras_feature_enable(struct amdgpu_device *adev, struct ras_common_if *head, bool enable)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); union ta_ras_cmd_input *info; int ret;
if (!con) return -EINVAL;
/* For non-gfx ip, do not enable ras feature if it is not allowed */ /* For gfx ip, regardless of feature support status, */ /* Force issue enable or disable ras feature commands */ if (head->block != AMDGPU_RAS_BLOCK__GFX &&
!amdgpu_ras_is_feature_allowed(adev, head)) return 0;
/* Only enable gfx ras feature from host side */ if (head->block == AMDGPU_RAS_BLOCK__GFX &&
!amdgpu_sriov_vf(adev) &&
!amdgpu_ras_intr_triggered()) {
info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL); if (!info) return -ENOMEM;
/* setup the obj */
__amdgpu_ras_feature_enable(adev, head, enable);
return 0;
}
/* Only used in device probe stage and called only once. */ int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev, struct ras_common_if *head, bool enable)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); int ret;
if (!con) return -EINVAL;
if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) { if (enable) { /* There is no harm to issue a ras TA cmd regardless of * the currecnt ras state. * If current state == target state, it will do nothing * But sometimes it requests driver to reset and repost * with error code -EAGAIN.
*/
ret = amdgpu_ras_feature_enable(adev, head, 1); /* With old ras TA, we might fail to enable ras. * Log it and just setup the object. * TODO need remove this WA in the future.
*/ if (ret == -EINVAL) {
ret = __amdgpu_ras_feature_enable(adev, head, 1); if (!ret)
dev_info(adev->dev, "RAS INFO: %s setup object\n",
get_ras_block_str(head));
}
} else { /* setup the object then issue a ras TA disable cmd.*/
ret = __amdgpu_ras_feature_enable(adev, head, 1); if (ret) return ret;
/* gfx block ras disable cmd must send to ras-ta */ if (head->block == AMDGPU_RAS_BLOCK__GFX)
con->features |= BIT(head->block);
ret = amdgpu_ras_feature_enable(adev, head, 0);
/* clean gfx block ras features flag */ if (adev->ras_enabled && head->block == AMDGPU_RAS_BLOCK__GFX)
con->features &= ~BIT(head->block);
}
} else
ret = amdgpu_ras_feature_enable(adev, head, enable);
for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) { struct ras_common_if head = {
.block = i,
.type = default_ras_type,
.sub_block_index = 0,
};
if (i == AMDGPU_RAS_BLOCK__MCA) continue;
if (bypass) { /* * bypass psp. vbios enable ras for us. * so just create the obj
*/ if (__amdgpu_ras_feature_enable(adev, &head, 1)) break;
} else { if (amdgpu_ras_feature_enable(adev, &head, 1)) break;
}
}
for (i = 0; i < AMDGPU_RAS_MCA_BLOCK_COUNT; i++) { struct ras_common_if head = {
.block = AMDGPU_RAS_BLOCK__MCA,
.type = default_ras_type,
.sub_block_index = i,
};
if (bypass) { /* * bypass psp. vbios enable ras for us. * so just create the obj
*/ if (__amdgpu_ras_feature_enable(adev, &head, 1)) break;
} else { if (amdgpu_ras_feature_enable(adev, &head, 1)) break;
}
}
list_for_each_entry_safe(node, tmp, &adev->ras_list, node) { if (!node->ras_obj) {
dev_warn(adev->dev, "Warning: abnormal ras list node.\n"); continue;
}
obj = node->ras_obj; if (obj->ras_block_match) { if (obj->ras_block_match(obj, block, sub_block_index) == 0) return obj;
} else { if (amdgpu_ras_block_match_default(obj, block) == 0) return obj;
}
}
return NULL;
}
staticvoid amdgpu_ras_get_ecc_info(struct amdgpu_device *adev, struct ras_err_data *err_data)
{ struct amdgpu_ras *ras = amdgpu_ras_get_context(adev); int ret = 0;
/* * choosing right query method according to * whether smu support query error information
*/
ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc)); if (ret == -EOPNOTSUPP) { if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
adev->umc.ras->ras_block.hw_ops->query_ras_error_count)
adev->umc.ras->ras_block.hw_ops->query_ras_error_count(adev, err_data);
/* umc query_ras_error_address is also responsible for clearing * error status
*/ if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
adev->umc.ras->ras_block.hw_ops->query_ras_error_address)
adev->umc.ras->ras_block.hw_ops->query_ras_error_address(adev, err_data);
} elseif (!ret) { if (adev->umc.ras &&
adev->umc.ras->ecc_info_query_ras_error_count)
adev->umc.ras->ecc_info_query_ras_error_count(adev, err_data);
if (adev->umc.ras &&
adev->umc.ras->ecc_info_query_ras_error_address)
adev->umc.ras->ecc_info_query_ras_error_address(adev, err_data);
}
}
if (block_obj->hw_ops->ras_error_inject) { if (info->head.block == AMDGPU_RAS_BLOCK__GFX)
ret = block_obj->hw_ops->ras_error_inject(adev, info, info->instance_mask); else/* Special ras_error_inject is defined (e.g: xgmi) */
ret = block_obj->hw_ops->ras_error_inject(adev, &block_info,
info->instance_mask);
} else { /* default path */
ret = psp_ras_trigger_error(&adev->psp, &block_info, info->instance_mask);
}
if (ret)
dev_err(adev->dev, "ras inject %s failed %d\n",
get_ras_block_str(&info->head), ret);
return ret;
}
/** * amdgpu_ras_query_error_count_helper -- Get error counter for specific IP * @adev: pointer to AMD GPU device * @ce_count: pointer to an integer to be set to the count of correctible errors. * @ue_count: pointer to an integer to be set to the count of uncorrectible errors. * @query_info: pointer to ras_query_if * * Return 0 for query success or do nothing, otherwise return an error * on failures
*/ staticint amdgpu_ras_query_error_count_helper(struct amdgpu_device *adev, unsignedlong *ce_count, unsignedlong *ue_count, struct ras_query_if *query_info)
{ int ret;
if (!query_info) /* do nothing if query_info is not specified */ return 0;
ret = amdgpu_ras_query_error_status(adev, query_info); if (ret) return ret;
/* some hardware/IP supports read to clear
* no need to explictly reset the err status after the query call */ if (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) { if (amdgpu_ras_reset_error_status(adev, query_info->head.block))
dev_warn(adev->dev, "Failed to reset error counter and error status\n");
}
return 0;
}
/** * amdgpu_ras_query_error_count -- Get error counts of all IPs or specific IP * @adev: pointer to AMD GPU device * @ce_count: pointer to an integer to be set to the count of correctible errors. * @ue_count: pointer to an integer to be set to the count of uncorrectible * errors. * @query_info: pointer to ras_query_if if the query request is only for * specific ip block; if info is NULL, then the qurey request is for * all the ip blocks that support query ras error counters/status * * If set, @ce_count or @ue_count, count and return the corresponding * error counts in those integer pointers. Return 0 if the device * supports RAS. Return -EOPNOTSUPP if the device doesn't support RAS.
*/ int amdgpu_ras_query_error_count(struct amdgpu_device *adev, unsignedlong *ce_count, unsignedlong *ue_count, struct ras_query_if *query_info)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_manager *obj; unsignedlong ce, ue; int ret;
if (!adev->ras_enabled || !con) return -EOPNOTSUPP;
/* Don't count since no reporting.
*/ if (!ce_count && !ue_count) return 0;
ce = 0;
ue = 0; if (!query_info) { /* query all the ip blocks that support ras query interface */
list_for_each_entry(obj, &con->head, node) { struct ras_query_if info = {
.head = obj->head,
};
ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, &info);
}
} else { /* query specific ip block */
ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, query_info);
}
staticchar *amdgpu_ras_badpage_flags_str(unsignedint flags)
{ switch (flags) { case AMDGPU_RAS_RETIRE_PAGE_RESERVED: return"R"; case AMDGPU_RAS_RETIRE_PAGE_PENDING: return"P"; case AMDGPU_RAS_RETIRE_PAGE_FAULT: default: return"F";
}
}
/** * DOC: AMDGPU RAS sysfs gpu_vram_bad_pages Interface * * It allows user to read the bad pages of vram on the gpu through * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages * * It outputs multiple lines, and each line stands for one gpu page. * * The format of one line is below, * gpu pfn : gpu page size : flags * * gpu pfn and gpu page size are printed in hex format. * flags can be one of below character, * * R: reserved, this gpu page is reserved and not able to use. * * P: pending for reserve, this gpu page is marked as bad, will be reserved * in next window of page_reserve. * * F: unable to reserve. this gpu page can't be reserved due to some reasons. * * Examples: * * .. code-block:: bash * * 0x00000001 : 0x00001000 : R * 0x00000002 : 0x00001000 : P *
*/
if (amdgpu_bad_page_threshold != 0)
amdgpu_ras_sysfs_remove_bad_page_node(adev);
amdgpu_ras_sysfs_remove_dev_attr_node(adev);
return 0;
} /* sysfs end */
/** * DOC: AMDGPU RAS Reboot Behavior for Unrecoverable Errors * * Normally when there is an uncorrectable error, the driver will reset * the GPU to recover. However, in the event of an unrecoverable error, * the driver provides an interface to reboot the system automatically * in that event. * * The following file in debugfs provides that interface: * /sys/kernel/debug/dri/[0/1/2...]/ras/auto_reboot * * Usage: * * .. code-block:: bash * * echo true > .../ras/auto_reboot *
*/ /* debugfs begin */ staticstruct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_ras_eeprom_control *eeprom = &con->eeprom_control; struct drm_minor *minor = adev_to_drm(adev)->primary; struct dentry *dir;
/* * After one uncorrectable error happens, usually GPU recovery will * be scheduled. But due to the known problem in GPU recovery failing * to bring GPU back, below interface provides one direct way to * user to reboot system automatically in such case within * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine * will never be called.
*/
debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, dir, &con->reboot);
/* * User could set this not to clean up hardware's error count register * of RAS IPs during ras recovery.
*/
debugfs_create_bool("disable_ras_err_cnt_harvest", 0644, dir,
&con->disable_ras_err_cnt_harvest); return dir;
}
if (IS_ENABLED(CONFIG_DEBUG_FS)) {
list_for_each_entry_safe(con_obj, tmp, &con->head, node) {
ip_obj = amdgpu_ras_find_obj(adev, &con_obj->head); if (ip_obj)
put_obj(ip_obj);
}
}
amdgpu_ras_sysfs_remove_all(adev); return 0;
} /* ras fs end */
/* ih begin */
/* For the hardware that cannot enable bif ring for both ras_controller_irq * and ras_err_evnet_athub_irq ih cookies, the driver has to poll status * register to check whether the interrupt is triggered or not, and properly * ack the interrupt if it is there
*/ void amdgpu_ras_interrupt_fatal_error_handler(struct amdgpu_device *adev)
{ /* Fatal error events are handled on host side */ if (amdgpu_sriov_vf(adev)) return; /* * If the current interrupt is caused by a non-fatal RAS error, skip * check for fatal error. For fatal errors, FED status of all devices * in XGMI hive gets set when the first device gets fatal error * interrupt. The error gets propagated to other devices as well, so * make sure to ack the interrupt regardless of FED status.
*/ if (!amdgpu_ras_get_fed_status(adev) &&
amdgpu_ras_is_err_state(adev, AMDGPU_RAS_BLOCK__ANY)) return;
if (adev->nbio.ras &&
adev->nbio.ras->handle_ras_controller_intr_no_bifring)
adev->nbio.ras->handle_ras_controller_intr_no_bifring(adev);
if (adev->nbio.ras &&
adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring)
adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring(adev);
}
ret = amdgpu_ras_mark_ras_event(adev, type); if (ret) return;
amdgpu_ras_set_err_poison(adev, block_obj->ras_comm.block); /* both query_poison_status and handle_poison_consumption are optional, * but at least one of them should be implemented if we need poison * consumption handler
*/ if (block_obj->hw_ops && block_obj->hw_ops->query_poison_status) {
poison_stat = block_obj->hw_ops->query_poison_status(adev); if (!poison_stat) { /* Not poison consumption interrupt, no need to handle it */
dev_info(adev->dev, "No RAS poison status in %s poison IH.\n",
block_obj->ras_comm.name);
ret = amdgpu_ras_error_data_init(&err_data); if (ret) return;
/* Let IP handle its data, maybe we need get the output * from the callback to update the error type/count, etc
*/
amdgpu_ras_set_fed(obj->adev, true);
ret = data->cb(obj->adev, &err_data, entry); /* ue will trigger an interrupt, and in that case * we need do a reset to recovery the whole system. * But leave IP do that recovery, here we just dispatch * the error.
*/ if (ret == AMDGPU_RAS_SUCCESS) { /* these counts could be left as 0 if * some blocks do not count error number
*/
obj->err_data.ue_count += err_data.ue_count;
obj->err_data.ce_count += err_data.ce_count;
obj->err_data.de_count += err_data.de_count;
}
if (!obj) { /* in case we registe the IH before enable ras feature */
obj = amdgpu_ras_create_obj(adev, head); if (!obj) return -EINVAL;
} else
get_obj(obj);
data->aligned_element_size = ALIGN(data->element_size, 8); /* the ring can store 64 iv entries. */
data->ring_size = 64 * data->aligned_element_size;
data->ring = kmalloc(data->ring_size, GFP_KERNEL); if (!data->ring) {
put_obj(obj); return -ENOMEM;
}
/* * PCIE_BIF IP has one different isr by ras controller * interrupt, the specific ras counter query will be * done in that isr. So skip such block from common * sync flood interrupt isr calling.
*/ if (info.head.block == AMDGPU_RAS_BLOCK__PCIE_BIF) continue;
/* * this is a workaround for aldebaran, skip send msg to * smu to get ecc_info table due to smu handle get ecc * info table failed temporarily. * should be removed until smu fix handle ecc_info table.
*/ if ((info.head.block == AMDGPU_RAS_BLOCK__UMC) &&
(amdgpu_ip_version(adev, MP1_HWIP, 0) ==
IP_VERSION(13, 0, 2))) continue;
if (amdgpu_ip_version(adev, MP0_HWIP, 0) !=
IP_VERSION(11, 0, 2) &&
amdgpu_ip_version(adev, MP0_HWIP, 0) !=
IP_VERSION(11, 0, 4) &&
amdgpu_ip_version(adev, MP0_HWIP, 0) !=
IP_VERSION(13, 0, 0)) { if (amdgpu_ras_reset_error_status(adev, info.head.block))
dev_warn(adev->dev, "Failed to reset error counter and error status");
}
}
}
/* Parse RdRspStatus and WrRspStatus */ staticvoid amdgpu_ras_error_status_query(struct amdgpu_device *adev, struct ras_query_if *info)
{ struct amdgpu_ras_block_object *block_obj; /* * Only two block need to query read/write * RspStatus at current state
*/ if ((info->head.block != AMDGPU_RAS_BLOCK__GFX) &&
(info->head.block != AMDGPU_RAS_BLOCK__MMHUB)) return;
/* If any device which is part of the hive received RAS fatal * error interrupt, set fatal error status on all. This * condition will need a recovery, and flag will be cleared * as part of recovery.
*/
list_for_each_entry(remote_adev, &hive->device_list,
gmc.xgmi.head) if (amdgpu_ras_get_fed_status(remote_adev)) {
amdgpu_ras_set_fed_all(adev, hive, true); break;
}
} if (!ras->disable_ras_err_cnt_harvest) {
/* Build list of devices to query RAS related errors */ if (hive && adev->gmc.xgmi.num_physical_nodes > 1) {
device_list_handle = &hive->device_list;
} else {
INIT_LIST_HEAD(&device_list);
list_add_tail(&adev->gmc.xgmi.head, &device_list);
device_list_handle = &device_list;
}
if (adev->smuio.funcs && adev->smuio.funcs->get_socket_id)
socket = adev->smuio.funcs->get_socket_id(adev);
/* although die id is gotten from PA in nps1 mode, the id is * fitable for any nps mode
*/ if (adev->umc.ras && adev->umc.ras->get_die_id_from_pa)
die_id = adev->umc.ras->get_die_id_from_pa(adev, bps->address,
bps->retired_page << AMDGPU_GPU_PAGE_SHIFT); else return -EINVAL;
/*old asics just have pa in eeprom*/ if (IP_VERSION_MAJ(amdgpu_ip_version(adev, UMC_HWIP, 0)) < 12) {
memcpy(err_data->err_addr, bps, sizeof(struct eeprom_table_record) * adev->umc.retire_unit); goto out;
}
for (i = 0; i < adev->umc.retire_unit; i++)
bps[i].retired_page &= ~(UMC_NPS_MASK << UMC_NPS_SHIFT);
if (save_nps) { if (save_nps == nps) { if (amdgpu_umc_pages_in_a_row(adev, err_data,
bps[0].retired_page << AMDGPU_GPU_PAGE_SHIFT)) return -EINVAL; for (i = 0; i < adev->umc.retire_unit; i++) {
err_data->err_addr[i].address = bps[0].address;
err_data->err_addr[i].mem_channel = bps[0].mem_channel;
err_data->err_addr[i].bank = bps[0].bank;
err_data->err_addr[i].err_type = bps[0].err_type;
err_data->err_addr[i].mcumc_id = bps[0].mcumc_id;
}
} else { if (amdgpu_ras_mca2pa_by_idx(adev, &bps[0], err_data)) return -EINVAL;
}
} else { if (bps[0].address == 0) { /* for specific old eeprom data, mca address is not stored, * calc it from pa
*/ if (amdgpu_umc_pa2mca(adev, bps[0].retired_page << AMDGPU_GPU_PAGE_SHIFT,
&(bps[0].address), AMDGPU_NPS1_PARTITION_MODE)) return -EINVAL;
}
if (amdgpu_ras_mca2pa(adev, &bps[0], err_data)) { if (nps == AMDGPU_NPS1_PARTITION_MODE)
memcpy(err_data->err_addr, bps, sizeof(struct eeprom_table_record) * adev->umc.retire_unit); else return -EOPNOTSUPP;
}
}
if (save_nps == nps) { if (amdgpu_umc_pages_in_a_row(adev, err_data,
bps->retired_page << AMDGPU_GPU_PAGE_SHIFT)) return -EINVAL; for (i = 0; i < adev->umc.retire_unit; i++) {
err_data->err_addr[i].address = bps->address;
err_data->err_addr[i].mem_channel = bps->mem_channel;
err_data->err_addr[i].bank = bps->bank;
err_data->err_addr[i].err_type = bps->err_type;
err_data->err_addr[i].mcumc_id = bps->mcumc_id;
}
} else { if (bps->address) { if (amdgpu_ras_mca2pa_by_idx(adev, bps, err_data)) return -EINVAL;
} else { /* for specific old eeprom data, mca address is not stored, * calc it from pa
*/ if (amdgpu_umc_pa2mca(adev, bps->retired_page << AMDGPU_GPU_PAGE_SHIFT,
&(bps->address), AMDGPU_NPS1_PARTITION_MODE)) return -EINVAL;
if (amdgpu_ras_mca2pa(adev, bps, err_data)) return -EOPNOTSUPP;
}
}
if (from_rom) {
err_data.err_addr =
kcalloc(adev->umc.retire_unit, sizeof(struct eeprom_table_record), GFP_KERNEL); if (!err_data.err_addr) {
dev_warn(adev->dev, "Failed to alloc UMC error address record in mca2pa conversion!\n"); return -ENOMEM;
}
if (adev->gmc.gmc_funcs->query_mem_partition_mode)
nps = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
}
mutex_lock(&con->recovery_lock);
if (from_rom) { /* there is no pa recs in V3, so skip pa recs processing */ if (control->tbl_hdr.version < RAS_TABLE_VER_V3) { for (i = 0; i < pages; i++) { if (control->ras_num_recs - i >= adev->umc.retire_unit) { if ((bps[i].address == bps[i + 1].address) &&
(bps[i].mem_channel == bps[i + 1].mem_channel)) { /* deal with retire_unit records a time */
ret = __amdgpu_ras_convert_rec_array_from_rom(adev,
&bps[i], &err_data, nps); if (ret)
control->ras_num_bad_pages -= adev->umc.retire_unit;
i += (adev->umc.retire_unit - 1);
} else { break;
}
} else { break;
}
}
} for (; i < pages; i++) {
ret = __amdgpu_ras_convert_rec_from_rom(adev,
&bps[i], &err_data, nps); if (ret)
control->ras_num_bad_pages -= adev->umc.retire_unit;
}
} else {
ret = __amdgpu_ras_restore_bad_pages(adev, bps, pages);
}
if (from_rom)
kfree(err_data.err_addr);
mutex_unlock(&con->recovery_lock);
return ret;
}
/* * write error record array to eeprom, the function should be * protected by recovery_lock * new_cnt: new added UE count, excluding reserved bad pages, can be NULL
*/ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev, unsignedlong *new_cnt)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_err_handler_data *data; struct amdgpu_ras_eeprom_control *control; int save_count, unit_num, bad_page_num, i;
if (!con || !con->eh_data) { if (new_cnt)
*new_cnt = 0;
return 0;
}
if (!con->eeprom_control.is_eeprom_valid) {
dev_warn(adev->dev, "Failed to save EEPROM table data because of EEPROM data corruption!"); if (new_cnt)
*new_cnt = 0;
return 0;
}
mutex_lock(&con->recovery_lock);
control = &con->eeprom_control;
data = con->eh_data;
bad_page_num = control->ras_num_bad_pages;
save_count = data->count - bad_page_num;
mutex_unlock(&con->recovery_lock);
unit_num = save_count / adev->umc.retire_unit; if (new_cnt)
*new_cnt = unit_num;
/* only new entries are saved */ if (save_count > 0) { /*old asics only save pa to eeprom like before*/ if (IP_VERSION_MAJ(amdgpu_ip_version(adev, UMC_HWIP, 0)) < 12) { if (amdgpu_ras_eeprom_append(control,
&data->bps[bad_page_num], save_count)) {
dev_err(adev->dev, "Failed to save EEPROM table data!"); return -EIO;
}
} else { for (i = 0; i < unit_num; i++) { if (amdgpu_ras_eeprom_append(control,
&data->bps[bad_page_num +
i * adev->umc.retire_unit], 1)) {
dev_err(adev->dev, "Failed to save EEPROM table data!"); return -EIO;
}
}
}
dev_info(adev->dev, "Saved %d pages to EEPROM table.\n", save_count);
}
return 0;
}
/* * read error record array in eeprom and reserve enough space for * storing new bad pages
*/ staticint amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
{ struct amdgpu_ras_eeprom_control *control =
&adev->psp.ras_context.ras->eeprom_control; struct eeprom_table_record *bps; int ret, i = 0;
/* no bad page record, skip eeprom access */ if (control->ras_num_recs == 0 || amdgpu_bad_page_threshold == 0) return 0;
bps = kcalloc(control->ras_num_recs, sizeof(*bps), GFP_KERNEL); if (!bps) return -ENOMEM;
ret = amdgpu_ras_eeprom_read(control, bps, control->ras_num_recs); if (ret) {
dev_err(adev->dev, "Failed to load EEPROM table records!");
} else { if (adev->umc.ras && adev->umc.ras->convert_ras_err_addr) { /*In V3, there is no pa recs, and some cases(when address==0) may be parsed as pa recs, so add verion check to avoid it.
*/ if (control->tbl_hdr.version < RAS_TABLE_VER_V3) { for (i = 0; i < control->ras_num_recs; i++) { if ((control->ras_num_recs - i) >= adev->umc.retire_unit) { if ((bps[i].address == bps[i + 1].address) &&
(bps[i].mem_channel == bps[i + 1].mem_channel)) {
control->ras_num_pa_recs += adev->umc.retire_unit;
i += (adev->umc.retire_unit - 1);
} else {
control->ras_num_mca_recs +=
(control->ras_num_recs - i); break;
}
} else {
control->ras_num_mca_recs += (control->ras_num_recs - i); break;
}
}
} else {
control->ras_num_mca_recs = control->ras_num_recs;
}
}
ret = amdgpu_ras_eeprom_check(control); if (ret) goto out;
/* HW not usable */ if (amdgpu_ras_is_rma(adev)) {
ret = -EHWPOISON; goto out;
}
ret = amdgpu_ras_add_bad_pages(adev, bps, control->ras_num_recs, true);
}
addr >>= AMDGPU_GPU_PAGE_SHIFT; for (i = 0; i < data->count; i++) if (addr == data->bps[i].retired_page) return 1;
return 0;
}
/* * check if an address belongs to bad page * * Note: this check is only for umc block
*/ staticint amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
uint64_t addr)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); int ret = 0;
if (!con || !con->eh_data) return ret;
mutex_lock(&con->recovery_lock);
ret = amdgpu_ras_check_bad_page_unlock(con, addr);
mutex_unlock(&con->recovery_lock); return ret;
}
/* * amdgpu_bad_page_threshold is used to config * the threshold for the number of bad pages. * -1: Threshold is set to default value * Driver will issue a warning message when threshold is reached * and continue runtime services. * 0: Disable bad page retirement * Driver will not retire bad pages * which is intended for debugging purpose. * -2: Threshold is determined by a formula * that assumes 1 bad page per 100M of local memory. * Driver will continue runtime services when threhold is reached. * 0 < threshold < max number of bad page records in EEPROM, * A user-defined threshold is set * Driver will halt runtime services when this custom threshold is reached.
*/ if (amdgpu_bad_page_threshold == -2) {
u64 val = adev->gmc.mc_vram_size;
/* If gpu reset is ongoing, delay retiring the bad pages */ if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev)) {
amdgpu_ras_schedule_retirement_dwork(con,
AMDGPU_RAS_RETIRE_PAGE_INTERVAL * 3); return;
}
for (i = 0; i < msg_count; i++) {
ret = amdgpu_ras_get_poison_req(adev, &msg); if (!ret) continue;
if (msg.pasid_fn)
msg.pasid_fn(adev, msg.pasid, msg.data);
reset_flags |= msg.reset;
}
/* * Try to ensure poison creation handler is completed first * to set rma if bad page exceed threshold.
*/
flush_delayed_work(&con->page_retirement_dwork);
/* for RMA, amdgpu_ras_poison_creation_handler will trigger gpu reset */ if (reset_flags && !amdgpu_ras_is_rma(adev)) { if (reset_flags & AMDGPU_RAS_GPU_RESET_MODE1_RESET)
reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET; elseif (reset_flags & AMDGPU_RAS_GPU_RESET_MODE2_RESET)
reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET; else
reset = reset_flags;
do {
poison_creation_count = atomic_read(&con->poison_creation_count);
ret = amdgpu_ras_poison_creation_handler(adev, poison_creation_count); if (ret == -EIO) break;
if (poison_creation_count) {
atomic_sub(poison_creation_count, &con->poison_creation_count);
atomic_sub(poison_creation_count, &con->page_retirement_req_cnt);
}
} while (atomic_read(&con->poison_creation_count) &&
!atomic_read(&con->poison_consumption_count));
if (ret != -EIO) {
msg_count = kfifo_len(&con->poison_fifo); if (msg_count) {
ret = amdgpu_ras_poison_consumption_handler(adev,
msg_count, &gpu_reset); if ((ret != -EIO) &&
(gpu_reset != AMDGPU_RAS_GPU_RESET_MODE1_RESET))
atomic_sub(msg_count, &con->page_retirement_req_cnt);
}
}
if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) { /* gpu mode-1 reset is ongoing or just completed ras mode-1 reset */ /* Clear poison creation request */
atomic_set(&con->poison_creation_count, 0);
atomic_set(&con->poison_consumption_count, 0);
/* Clear all poison requests */
atomic_set(&con->page_retirement_req_cnt, 0);
if (ret == -EIO) { /* Wait for mode-1 reset to complete */
down_read(&adev->reset_domain->sem);
up_read(&adev->reset_domain->sem);
}
/* Wake up work to save bad pages to eeprom */
schedule_delayed_work(&con->page_retirement_dwork, 0);
} elseif (gpu_reset) { /* gpu just completed mode-2 reset or other reset */ /* Clear poison consumption messages cached in fifo */
msg_count = kfifo_len(&con->poison_fifo); if (msg_count) {
amdgpu_ras_clear_poison_fifo(adev);
atomic_sub(msg_count, &con->page_retirement_req_cnt);
}
atomic_set(&con->poison_consumption_count, 0);
/* Wake up work to save bad pages to eeprom */
schedule_delayed_work(&con->page_retirement_dwork, 0);
}
}
return 0;
}
int amdgpu_ras_init_badpage_info(struct amdgpu_device *adev)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_ras_eeprom_control *control; int ret;
if (!con || amdgpu_sriov_vf(adev)) return 0;
control = &con->eeprom_control;
ret = amdgpu_ras_eeprom_init(control);
control->is_eeprom_valid = !ret;
if (!adev->umc.ras || !adev->umc.ras->convert_ras_err_addr)
control->ras_num_pa_recs = control->ras_num_recs;
if (adev->umc.ras &&
adev->umc.ras->get_retire_flip_bits)
adev->umc.ras->get_retire_flip_bits(adev);
if (control->ras_num_recs && control->is_eeprom_valid) {
ret = amdgpu_ras_load_bad_pages(adev); if (ret) {
control->is_eeprom_valid = false; return 0;
}
/* The format action is only applied to new ASICs */ if (IP_VERSION_MAJ(amdgpu_ip_version(adev, UMC_HWIP, 0)) >= 12 &&
control->tbl_hdr.version < RAS_TABLE_VER_V3) if (!amdgpu_ras_eeprom_reset_table(control)) if (amdgpu_ras_save_bad_pages(adev, NULL))
dev_warn(adev->dev, "Failed to format RAS EEPROM data in V3 version!\n");
}
/* Allow access to RAS EEPROM via debugfs, when the ASIC * supports RAS and debugfs is enabled, but when * adev->ras_enabled is unset, i.e. when "ras_enable" * module parameter is set to 0.
*/
con->adev = adev;
if (!adev->ras_enabled) return 0;
data = &con->eh_data;
*data = kzalloc(sizeof(**data), GFP_KERNEL); if (!*data) {
ret = -ENOMEM; goto out;
}
/* * Except error threshold exceeding case, other failure cases in this * function would not fail amdgpu driver init.
*/ if (!amdgpu_ras_is_rma(adev))
ret = 0; else
ret = -EINVAL;
/* recovery_init failed to init it, fini is useless */ if (!data) return 0;
/* Save all cached bad pages to eeprom */ do {
flush_delayed_work(&con->page_retirement_dwork);
ret = amdgpu_ras_schedule_retirement_dwork(con, 0);
} while (ret && max_flush_timeout--);
if (con->page_retirement_thread)
kthread_stop(con->page_retirement_thread);
/* * this is workaround for vega20 workstation sku, * force enable gfx ras, ignore vbios gfx ras flag * due to GC EDC can not write
*/ staticvoid amdgpu_ras_get_quirks(struct amdgpu_device *adev)
{ struct atom_context *ctx = adev->mode_info.atom_context;
/* Query ras capablity via atomfirmware interface */ staticvoid amdgpu_ras_query_ras_capablity_from_vbios(struct amdgpu_device *adev)
{ /* mem_ecc cap */ if (amdgpu_atomfirmware_mem_ecc_supported(adev)) {
dev_info(adev->dev, "MEM ECC is active.\n");
adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__UMC |
1 << AMDGPU_RAS_BLOCK__DF);
} else {
dev_info(adev->dev, "MEM ECC is not presented.\n");
}
/* sram_ecc cap */ if (amdgpu_atomfirmware_sram_ecc_supported(adev)) {
dev_info(adev->dev, "SRAM ECC is active.\n"); if (!amdgpu_sriov_vf(adev))
adev->ras_hw_enabled |= ~(1 << AMDGPU_RAS_BLOCK__UMC |
1 << AMDGPU_RAS_BLOCK__DF); else
adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__PCIE_BIF |
1 << AMDGPU_RAS_BLOCK__SDMA |
1 << AMDGPU_RAS_BLOCK__GFX);
/* * VCN/JPEG RAS can be supported on both bare metal and * SRIOV environment
*/ if (amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(2, 6, 0) ||
amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(4, 0, 0) ||
amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(4, 0, 3) ||
amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(5, 0, 1))
adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__VCN |
1 << AMDGPU_RAS_BLOCK__JPEG); else
adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__VCN |
1 << AMDGPU_RAS_BLOCK__JPEG);
/* * XGMI RAS is not supported if xgmi num physical nodes * is zero
*/ if (!adev->gmc.xgmi.num_physical_nodes)
adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__XGMI_WAFL);
} else {
dev_info(adev->dev, "SRAM ECC is not presented.\n");
}
}
/* poison setting is useless on SRIOV guest */ if (amdgpu_sriov_vf(adev) || !con) return;
/* Init poison supported flag, the default value is false */ if (adev->gmc.xgmi.connected_to_cpu ||
adev->gmc.is_app_apu) { /* enabled by default when GPU is connected to CPU */
con->poison_supported = true;
} elseif (adev->df.funcs &&
adev->df.funcs->query_ras_poison_mode &&
adev->umc.ras &&
adev->umc.ras->query_ras_poison_mode) {
df_poison =
adev->df.funcs->query_ras_poison_mode(adev);
umc_poison =
adev->umc.ras->query_ras_poison_mode(adev);
/* Only poison is set in both DF and UMC, we can support it */ if (df_poison && umc_poison)
con->poison_supported = true; elseif (df_poison != umc_poison)
dev_warn(adev->dev, "Poison setting is inconsistent in DF/UMC(%d:%d)!\n",
df_poison, umc_poison);
}
}
/* * check hardware's ras ability which will be saved in hw_supported. * if hardware does not support ras, we can skip some ras initializtion and * forbid some ras operations from IP. * if software itself, say boot parameter, limit the ras ability. We still * need allow IP do some limited operations, like disable. In such case, * we have to initialize ras as normal. but need check if operation is * allowed or not in each function.
*/ staticvoid amdgpu_ras_check_supported(struct amdgpu_device *adev)
{
adev->ras_hw_enabled = adev->ras_enabled = 0;
if (!amdgpu_ras_asic_supported(adev)) return;
if (amdgpu_sriov_vf(adev)) { if (amdgpu_virt_get_ras_capability(adev)) goto init_ras_enabled_flag;
}
/* query ras capability from psp */ if (amdgpu_psp_get_ras_capability(&adev->psp)) goto init_ras_enabled_flag;
/* query ras capablity from bios */ if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {
amdgpu_ras_query_ras_capablity_from_vbios(adev);
} else { /* driver only manages a few IP blocks RAS feature
* when GPU is connected cpu through XGMI */
adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__GFX |
1 << AMDGPU_RAS_BLOCK__SDMA |
1 << AMDGPU_RAS_BLOCK__MMHUB);
}
/* apply asic specific settings (vega20 only for now) */
amdgpu_ras_get_quirks(adev);
/* query poison mode from umc/df ip callback */
amdgpu_ras_query_poison_mode(adev);
init_ras_enabled_flag: /* hw_supported needs to be aligned with RAS block mask. */
adev->ras_hw_enabled &= AMDGPU_RAS_BLOCK_MASK;
/* aca is disabled by default except for psp v13_0_6/v13_0_12/v13_0_14 */ if (!amdgpu_sriov_vf(adev)) {
adev->aca.is_enabled =
(amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 6) ||
amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 12) ||
amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 14));
}
/* bad page feature is not applicable to specific app platform */ if (adev->gmc.is_app_apu &&
amdgpu_ip_version(adev, UMC_HWIP, 0) == IP_VERSION(12, 0, 0))
amdgpu_bad_page_threshold = 0;
}
/* init event manager with node 0 on xgmi system */ if (!amdgpu_reset_in_recovery(adev)) { if (!hive || adev->gmc.xgmi.node_id == 0)
ras_event_mgr_init(ras->event_mgr);
}
if (!adev->ras_enabled || adev->asic_type == CHIP_VEGA10) { /* set gfx block ras context feature for VEGA20 Gaming * send ras disable cmd to ras ta during ras late init.
*/ if (!adev->ras_enabled && adev->asic_type == CHIP_VEGA20) {
con->features |= BIT(AMDGPU_RAS_BLOCK__GFX);
return 0;
}
r = 0; goto release_con;
}
con->update_channel_flag = false;
con->features = 0;
con->schema = 0;
INIT_LIST_HEAD(&con->head); /* Might need get this flag from vbios. */
con->flags = RAS_DEFAULT_FLAGS;
/* initialize nbio ras function ahead of any other * ras functions so hardware fatal error interrupt
* can be enabled as early as possible */ switch (amdgpu_ip_version(adev, NBIO_HWIP, 0)) { case IP_VERSION(7, 4, 0): case IP_VERSION(7, 4, 1): case IP_VERSION(7, 4, 4): if (!adev->gmc.xgmi.connected_to_cpu)
adev->nbio.ras = &nbio_v7_4_ras; break; case IP_VERSION(4, 3, 0): if (adev->ras_hw_enabled & (1 << AMDGPU_RAS_BLOCK__DF)) /* unlike other generation of nbio ras, * nbio v4_3 only support fatal error interrupt * to inform software that DF is freezed due to * system fatal error event. driver should not * enable nbio ras in such case. Instead,
* check DF RAS */
adev->nbio.ras = &nbio_v4_3_ras; break; case IP_VERSION(6, 3, 1): if (adev->ras_hw_enabled & (1 << AMDGPU_RAS_BLOCK__DF)) /* unlike other generation of nbio ras, * nbif v6_3_1 only support fatal error interrupt * to inform software that DF is freezed due to * system fatal error event. driver should not * enable nbio ras in such case. Instead, * check DF RAS
*/
adev->nbio.ras = &nbif_v6_3_1_ras; break; case IP_VERSION(7, 9, 0): case IP_VERSION(7, 9, 1): if (!adev->gmc.is_app_apu)
adev->nbio.ras = &nbio_v7_9_ras; break; default: /* nbio ras is not available */ break;
}
/* nbio ras block needs to be enabled ahead of other ras blocks
* to handle fatal error */
r = amdgpu_nbio_ras_sw_init(adev); if (r) return r;
if (adev->nbio.ras &&
adev->nbio.ras->init_ras_controller_interrupt) {
r = adev->nbio.ras->init_ras_controller_interrupt(adev); if (r) goto release_con;
}
if (adev->nbio.ras &&
adev->nbio.ras->init_ras_err_event_athub_interrupt) {
r = adev->nbio.ras->init_ras_err_event_athub_interrupt(adev); if (r) goto release_con;
}
/* Packed socket_id to ras feature mask bits[31:29] */ if (adev->smuio.funcs &&
adev->smuio.funcs->get_socket_id)
con->features |= ((adev->smuio.funcs->get_socket_id(adev)) <<
AMDGPU_RAS_FEATURES_SOCKETID_SHIFT);
/* Get RAS schema for particular SOC */
con->schema = amdgpu_get_ras_schema(adev);
amdgpu_ras_init_reserved_vram_size(adev);
if (amdgpu_ras_fs_init(adev)) {
r = -EINVAL; goto release_con;
}
if (amdgpu_ras_aca_is_supported(adev)) { if (amdgpu_aca_is_enabled(adev))
r = amdgpu_aca_init(adev); else
r = amdgpu_mca_init(adev); if (r) goto release_con;
}
/* helper function to handle common stuff in ip late init phase */ int amdgpu_ras_block_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block)
{ struct amdgpu_ras_block_object *ras_obj = NULL; struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_query_if *query_info; unsignedlong ue_count, ce_count; int r;
/* disable RAS feature per IP block if it is not supported */ if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0); return 0;
}
r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1); if (r) { if (adev->in_suspend || amdgpu_reset_in_recovery(adev)) { /* in resume phase, if fail to enable ras,
* clean up all ras fs nodes, and disable ras */ goto cleanup;
} else return r;
}
/* check for errors on warm reset edc persisant supported ASIC */
amdgpu_persistent_edc_harvesting(adev, ras_block);
/* in resume phase, no need to create ras fs node */ if (adev->in_suspend || amdgpu_reset_in_recovery(adev)) return 0;
ras_obj = container_of(ras_block, struct amdgpu_ras_block_object, ras_comm); if (ras_obj->ras_cb || (ras_obj->hw_ops &&
(ras_obj->hw_ops->query_poison_status ||
ras_obj->hw_ops->handle_poison_consumption))) {
r = amdgpu_ras_interrupt_add_handler(adev, ras_block); if (r) goto cleanup;
}
if (ras_obj->hw_ops &&
(ras_obj->hw_ops->query_ras_error_count ||
ras_obj->hw_ops->query_ras_error_status)) {
r = amdgpu_ras_sysfs_create(adev, ras_block); if (r) goto interrupt;
/* Those are the cached values at init.
*/
query_info = kzalloc(sizeof(*query_info), GFP_KERNEL); if (!query_info) return -ENOMEM;
memcpy(&query_info->head, ras_block, sizeof(struct ras_common_if));
/* do some init work after IP late init as dependence. * and it runs in resume/gpu reset/booting up cases.
*/ void amdgpu_ras_resume(struct amdgpu_device *adev)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct ras_manager *obj, *tmp;
if (!adev->ras_enabled || !con) { /* clean ras context for VEGA20 Gaming after send ras disable cmd */
amdgpu_release_ras_context(adev);
return;
}
if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) { /* Set up all other IPs which are not implemented. There is a * tricky thing that IP's actual ras error type should be * MULTI_UNCORRECTABLE, but as driver does not handle it, so * ERROR_NONE make sense anyway.
*/
amdgpu_ras_enable_all_features(adev, 1);
/* We enable ras on all hw_supported block, but as boot * parameter might disable some of them and one or more IP has * not implemented yet. So we disable them on behalf.
*/
list_for_each_entry_safe(obj, tmp, &con->head, node) { if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
amdgpu_ras_feature_enable(adev, &obj->head, 0); /* there should be no any reference. */
WARN_ON(alive_obj(obj));
}
}
}
}
amdgpu_ras_disable_all_features(adev, 0); /* Make sure all ras objects are disabled. */ if (AMDGPU_RAS_GET_FEATURES(con->features))
amdgpu_ras_disable_all_features(adev, 1);
}
int amdgpu_ras_late_init(struct amdgpu_device *adev)
{ struct amdgpu_ras_block_list *node, *tmp; struct amdgpu_ras_block_object *obj; int r;
amdgpu_ras_event_mgr_init(adev);
if (amdgpu_ras_aca_is_supported(adev)) { if (amdgpu_reset_in_recovery(adev)) { if (amdgpu_aca_is_enabled(adev))
r = amdgpu_aca_reset(adev); else
r = amdgpu_mca_reset(adev); if (r) return r;
}
if (!amdgpu_sriov_vf(adev)) { if (amdgpu_aca_is_enabled(adev))
amdgpu_ras_set_aca_debug_mode(adev, false); else
amdgpu_ras_set_mca_debug_mode(adev, false);
}
}
/* Guest side doesn't need init ras feature */ if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_ras_telemetry_en(adev)) return 0;
list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
obj = node->ras_obj; if (!obj) {
dev_warn(adev->dev, "Warning: abnormal ras list node.\n"); continue;
}
if (!amdgpu_ras_is_supported(adev, obj->ras_comm.block)) continue;
if (obj->ras_late_init) {
r = obj->ras_late_init(adev, &obj->ras_comm); if (r) {
dev_err(adev->dev, "%s failed to execute ras_late_init! ret:%d\n",
obj->ras_comm.name, r); return r;
}
} else
amdgpu_ras_block_late_init_default(adev, &obj->ras_comm);
}
return 0;
}
/* do some fini work before IP fini as dependence */ int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
if (!adev->ras_enabled || !con) return 0;
/* Need disable ras on all IPs here before ip [hw/sw]fini */ if (AMDGPU_RAS_GET_FEATURES(con->features))
amdgpu_ras_disable_all_features(adev, 0);
amdgpu_ras_recovery_fini(adev); return 0;
}
if (type >= RAS_EVENT_TYPE_COUNT) return RAS_EVENT_INVALID_ID;
switch (type) { case RAS_EVENT_TYPE_FATAL: case RAS_EVENT_TYPE_POISON_CREATION: case RAS_EVENT_TYPE_POISON_CONSUMPTION:
event_mgr = __get_ras_event_mgr(adev); if (!event_mgr) return RAS_EVENT_INVALID_ID;
id = event_mgr->event_state[type].last_seqno; break; case RAS_EVENT_TYPE_INVALID: default:
id = RAS_EVENT_INVALID_ID; break;
}
/* * If the error was generated in UMC_V2, which belongs to GPU UMCs, * and error occurred in DramECC (Extended error code = 0) then only * process the error, else bail out.
*/ if (!m || !((smca_get_bank_type(m->extcpu, m->bank) == SMCA_UMC_V2) &&
(XEC(m->status, 0x3f) == 0x0))) return NOTIFY_DONE;
/* * If it is correctable error, return.
*/ if (mce_is_correctable(m)) return NOTIFY_OK;
/* * GPU Id is offset by GPU_ID_OFFSET in MCA_IPID_UMC register.
*/
gpu_id = GET_MCA_IPID_GPUID(m->ipid) - GPU_ID_OFFSET;
adev = find_adev(gpu_id); if (!adev) {
DRM_WARN("%s: Unable to find adev for gpu_id: %d\n", __func__,
gpu_id); return NOTIFY_DONE;
}
/* * If it is uncorrectable error, then find out UMC instance and * channel index.
*/
umc_inst = GET_UMC_INST(m->ipid);
ch_inst = GET_CHAN_INDEX(m->ipid);
staticvoid amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev)
{ /* * Add the adev to the mce_adev_list. * During mode2 reset, amdgpu device is temporarily * removed from the mgpu_info list which can cause * page retirement to fail. * Use this list instead of mgpu_info to find the amdgpu * device on which the UMC error was reported.
*/
mce_adev_list.devs[mce_adev_list.num_gpu++] = adev;
/* * Register the x86 notifier only once * with MCE subsystem.
*/ if (notifier_registered == false) {
mce_register_decode_chain(&amdgpu_bad_page_nb);
notifier_registered = true;
}
} #endif
struct amdgpu_ras *amdgpu_ras_get_context(struct amdgpu_device *adev)
{ if (!adev) return NULL;
return adev->psp.ras_context.ras;
}
int amdgpu_ras_set_context(struct amdgpu_device *adev, struct amdgpu_ras *ras_con)
{ if (!adev) return -EINVAL;
adev->psp.ras_context.ras = ras_con; return 0;
}
/* check if ras is supported on block, say, sdma, gfx */ int amdgpu_ras_is_supported(struct amdgpu_device *adev, unsignedint block)
{ int ret = 0; struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
if (block >= AMDGPU_RAS_BLOCK_COUNT) return 0;
ret = ras && (adev->ras_enabled & (1 << block));
/* For the special asic with mem ecc enabled but sram ecc * not enabled, even if the ras block is not supported on * .ras_enabled, if the asic supports poison mode and the * ras block has ras configuration, it can be considered * that the ras block supports ras function.
*/ if (!ret &&
(block == AMDGPU_RAS_BLOCK__GFX ||
block == AMDGPU_RAS_BLOCK__SDMA ||
block == AMDGPU_RAS_BLOCK__VCN ||
block == AMDGPU_RAS_BLOCK__JPEG) &&
(amdgpu_ras_mask & (1 << block)) &&
amdgpu_ras_is_poison_mode_supported(adev) &&
amdgpu_ras_get_ras_block(adev, block, 0))
ret = 1;
return ret;
}
int amdgpu_ras_reset_gpu(struct amdgpu_device *adev)
{ struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
/* mode1 is the only selection for RMA status */ if (amdgpu_ras_is_rma(adev)) {
ras->gpu_reset_flags = 0;
ras->gpu_reset_flags |= AMDGPU_RAS_GPU_RESET_MODE1_RESET;
}
if (atomic_cmpxchg(&ras->in_recovery, 0, 1) == 0) { struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev); int hive_ras_recovery = 0;
if (hive) {
hive_ras_recovery = atomic_read(&hive->ras_recovery);
amdgpu_put_xgmi_hive(hive);
} /* In the case of multiple GPUs, after a GPU has started * resetting all GPUs on hive, other GPUs do not need to * trigger GPU reset again.
*/ if (!hive_ras_recovery)
amdgpu_reset_domain_schedule(ras->adev->reset_domain, &ras->recovery_work); else
atomic_set(&ras->in_recovery, 0);
} else {
flush_work(&ras->recovery_work);
amdgpu_reset_domain_schedule(ras->adev->reset_domain, &ras->recovery_work);
}
return 0;
}
int amdgpu_ras_set_mca_debug_mode(struct amdgpu_device *adev, bool enable)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); int ret = 0;
if (con) {
ret = amdgpu_mca_smu_set_debug_mode(adev, enable); if (!ret)
con->is_aca_debug_mode = enable;
}
return ret;
}
int amdgpu_ras_set_aca_debug_mode(struct amdgpu_device *adev, bool enable)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); int ret = 0;
if (con) { if (amdgpu_aca_is_enabled(adev))
ret = amdgpu_aca_smu_set_debug_mode(adev, enable); else
ret = amdgpu_mca_smu_set_debug_mode(adev, enable); if (!ret)
con->is_aca_debug_mode = enable;
}
if ((reg_entry->flags & AMDGPU_RAS_ERR_INFO_VALID) &&
!REG_GET_FIELD(err_status_hi_data, ERR_STATUS_HI, ERR_INFO_VALID_FLAG)) /* keep the check here in case we need to refer to the result later */
dev_dbg(adev->dev, "Invalid err_info field\n");
for (i = 0; i < reg_list_size; i++) { /* query memory_id from err_status_lo */ if (!amdgpu_ras_inst_get_memory_id_field(adev, ®_list[i],
instance, &memory_id)) continue;
/* query err_cnt from err_status_hi */ if (!amdgpu_ras_inst_get_err_cnt_field(adev, ®_list[i],
instance, &err_cnt) ||
!err_cnt) continue;
*err_count += err_cnt;
/* log the errors */
amdgpu_ras_get_error_type_name(err_type, err_type_name); if (!mem_list) { /* memory_list is not supported */
dev_info(adev->dev, "%ld %s hardware errors detected in %s, instance: %d, memory_id: %d\n",
err_cnt, err_type_name,
reg_list[i].block_name,
instance, memory_id);
} else { for (j = 0; j < mem_list_size; j++) { if (memory_id == mem_list[j].memory_id) {
dev_info(adev->dev, "%ld %s hardware errors detected in %s, instance: %d, memory block: %s\n",
err_cnt, err_type_name,
reg_list[i].block_name,
instance, mem_list[j].name); break;
}
}
}
}
}
/* The pattern for smn addressing in other SOC could be different from * the one for aqua_vanjaram. We should revisit the code if the pattern * is changed. In such case, replace the aqua_vanjaram implementation
* with more common helper */
reg_addr = (mmMP0_SMN_C2PMSG_92 << 2) +
aqua_vanjaram_encode_ext_smn_addressing(instance);
fw_status = amdgpu_device_indirect_rreg_ext(adev, reg_addr);
for (i = 0; i < num_instances; i++) { if (amdgpu_ras_boot_error_detected(adev, i))
amdgpu_ras_boot_time_error_reporting(adev, i);
}
}
int amdgpu_ras_reserve_page(struct amdgpu_device *adev, uint64_t pfn)
{ struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
uint64_t start = pfn << AMDGPU_GPU_PAGE_SHIFT; int ret = 0;
mutex_lock(&con->page_rsv_lock);
ret = amdgpu_vram_mgr_query_page_status(mgr, start); if (ret == -ENOENT)
ret = amdgpu_vram_mgr_reserve_range(mgr, start, AMDGPU_GPU_PAGE_SIZE);
mutex_unlock(&con->page_rsv_lock);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.