[SWDEV-522623] Add afid functionality to API and CLI (#330)

Change-Id: I015bde926491d54e09da8f39b05650515711e09f

[SWDEV-522623] Add afid functionality to API and CLI


Change-Id: I015bde926491d54e09da8f39b05650515711e09f

Signed-off-by: Oosman Saeed <oossaeed@amd.com>
Co-authored-by: Oosman Saeed <oossaeed@amd.com>
Esse commit está contido em:
Saeed, Oosman
2025-05-15 21:49:56 -05:00
commit de GitHub
commit 1bb1f8acc2
21 arquivos alterados com 2228 adições e 209 exclusões
+64
Ver Arquivo
@@ -0,0 +1,64 @@
/**
* @file aca_decode.h
* @brief Internal decoder interface and data structures
*/
#ifndef ACA_DECODE_H
#define ACA_DECODE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "aca_fields.h"
/**
* @brief Internal decoder structure with parsed register fields
*/
typedef struct
{
uint64_t aca_status; /**< Raw status register value */
uint64_t aca_ipid; /**< Raw IPID register value */
uint64_t aca_synd; /**< Raw syndrome register value */
uint32_t flags; /**< Decoder flags */
uint16_t hw_revision; /**< Hardware hw_revision */
aca_status_fields_t status; /**< Parsed status fields */
aca_ipid_fields_t ipid; /**< Parsed IPID fields */
aca_synd_fields_t synd; /**< Parsed syndrome fields */
} aca_decoder_t;
/**
* @brief Structure containing raw ACA error data from hardware
*/
typedef struct
{
uint64_t aca_status; /**< Raw status register value */
uint64_t aca_ipid; /**< Raw IPID register value */
uint64_t aca_synd; /**< Raw syndrome register value */
uint32_t flags; /**< Flags from descriptor */
uint16_t hw_revision; /**< Hardware hw_revision number */
} aca_raw_data_t;
/**
* @brief Structure containing decoded error information
*/
typedef struct
{
const char *bank_ref; /**< Reference to bank name string */
const char *error_type_ref; /**< Reference to error type string */
const char *severity_ref; /**< Reference to error severity string */
const char *category_ref; /**< Reference to error category string */
int afid; /**< AFID value (AMD Field ID) */
} aca_error_info_t;
/**
* @brief Main decode function that processes raw ACA error data
* @param[in] raw_data Pointer to structure containing raw ACA error data
* @return Decoded error information structure
*/
aca_error_info_t aca_decode(const aca_raw_data_t *raw_data);
#ifdef __cplusplus
}
#endif
#endif /* ACA_DECODE_H */
+110
Ver Arquivo
@@ -0,0 +1,110 @@
/**
* @file aca_fields.h
* @brief ACA register field definitions and manipulation functions
*
* Contains structures and functions for decoding and handling
* ACA register fields. It provides field
* definitions for status, IPID, and syndrome registers, along with
* functions to initialize and access these fields.
*/
#ifndef ACA_FIELDS_H
#define ACA_FIELDS_H
#include <stdint.h>
/**
* @brief Base structure for ACA fields containing raw register value
*/
typedef struct
{
uint64_t raw_value; /**< Raw 64-bit register value */
} aca_fields_t;
/**
* @brief Structure containing decoded ACA status register fields
*/
typedef struct
{
aca_fields_t base;
uint16_t error_code;
uint8_t error_code_ext;
uint8_t reserv22;
uint8_t addr_lsb;
uint8_t reserv30;
uint8_t err_core_id;
uint8_t reserv38;
uint8_t scrub;
uint8_t reserv41;
uint8_t poison;
uint8_t deferred;
uint8_t uecc;
uint8_t cecc;
uint8_t reserv47;
uint8_t synd_v;
uint8_t reserv54;
uint8_t tcc;
uint8_t err_core_id_val;
uint8_t pcc;
uint8_t addr_v;
uint8_t misc_v;
uint8_t en;
uint8_t uc;
uint8_t overflow;
uint8_t val;
} aca_status_fields_t;
/**
* @brief Structure containing decoded ACA IPID register fields
*/
typedef struct
{
aca_fields_t base;
uint32_t instance_id_lo;
uint16_t hardware_id;
uint16_t aca_type;
uint8_t instance_id_hi;
} aca_ipid_fields_t;
/**
* @brief Structure containing decoded ACA syndrome register fields
*/
typedef struct
{
aca_fields_t base;
uint32_t error_information;
uint8_t length;
uint8_t error_priority;
uint8_t reserved27;
uint16_t syndrome;
uint32_t reserved39;
} aca_synd_fields_t;
/**
* @brief Reads the raw value from an ACA field structure
* @param[in] fields Pointer to the ACA fields structure
* @return The raw 64-bit value stored in the structure
*/
uint64_t aca_fields_read(const aca_fields_t *fields);
/**
* @brief Initializes ACA status fields from a raw status register value
* @param[out] fields Pointer to the status fields structure to initialize
* @param[in] status_reg Raw 64-bit status register value
*/
void aca_status_init(aca_status_fields_t *fields, uint64_t status_reg);
/**
* @brief Initializes ACA IPID fields from a raw IPID register value
* @param[out] fields Pointer to the IPID fields structure to initialize
* @param[in] ipid_reg Raw 64-bit IPID register value
*/
void aca_ipid_init(aca_ipid_fields_t *fields, uint64_t ipid_reg);
/**
* @brief Initializes ACA syndrome fields from a raw syndrome register value
* @param[out] fields Pointer to the syndrome fields structure to initialize
* @param[in] synd_reg Raw 64-bit syndrome register value
*/
void aca_synd_init(aca_synd_fields_t *fields, uint64_t synd_reg);
#endif
+84
Ver Arquivo
@@ -0,0 +1,84 @@
/**
* @file aca_tables.h
* @brief ACA lookup table definitions and helper functions
* @details Contains data structures and functions definitions for mapping ACA Registers
* into their corresponding names and types.
*/
#ifndef ACA_TABLES_H
#define ACA_TABLES_H
#include <stdint.h>
#include <stddef.h>
/**
* @brief Structure mapping hardware ID and ACA type to bank names
*/
typedef struct
{
uint16_t hw_id; /**< Hardware ID value */
uint16_t aca_type; /**< ACA type identifier */
const char *name; /**< Bank name string */
} aca_bank_entry_t;
/**
* @brief Structure mapping bank-specific error codes to error types
*/
typedef struct
{
const char *bank; /**< Bank name string */
uint32_t error_code; /**< Error code value */
const char *type; /**< Error type string */
} aca_error_type_t;
/**
* @brief Structure for generic error code to error type mapping
*/
typedef struct
{
uint32_t error_code; /**< Error code value */
const char *type; /**< Error type string */
} aca_error_entry_t;
// External table declarations
extern const aca_bank_entry_t bank_table[];
extern const aca_error_type_t error_table[];
extern const aca_error_entry_t xcd_error_table[];
extern const aca_error_entry_t aid_error_table[];
// Table size constants
extern const size_t NUM_BANKS;
extern const size_t NUM_ERRORS;
extern const size_t NUM_XCD_ERRORS;
extern const size_t NUM_AID_ERRORS;
/**
* @brief Find bank name based on hardware ID and ACA type
* @param[in] hw_id Hardware ID value
* @param[in] aca_type ACA type value
* @param[out] bank_name Pointer to store result string
* @return 0 on success, 1 if not found, -1 on parameter error
*/
int find_bank_name(uint16_t hw_id, uint16_t aca_type, const char **bank_name);
/**
* @brief Find error type for a specific bank and error code
* @param[in] bank Bank name string
* @param[in] error_code Error code value
* @param[out] error_type Pointer to store result string
* @return 0 on success, 1 if not found, -1 on parameter error
*/
int find_error_type_by_bank(const char *bank, uint32_t error_code, const char **error_type);
/**
* @brief Generic lookup for error codes in an error table
* @param[in] table Pointer to error table
* @param[in] table_size Number of table entries
* @param[in] error_code Error code to look up
* @param[out] error_type Pointer to store result string
* @return 0 on success, 1 if not found, -1 on parameter error
*/
int find_error_in_table(const aca_error_entry_t *table, size_t table_size,
uint32_t error_code, const char **error_type);
#endif
+27
Ver Arquivo
@@ -0,0 +1,27 @@
#ifndef ERROR_MAP_H
#define ERROR_MAP_H
#include <stdint.h>
/**
* @brief Structure representing an error mapping entry
*/
typedef struct
{
uint32_t id;
const char *error_category;
const char *error_type;
const char *method;
const char *error_severity;
} error_map_entry_t;
/**
* @brief Get error ID based on category, type and severity
* @param[in] error_category Error category string
* @param[in] error_type Error type string
* @param[in] error_severity Error severity string
* @return Error ID if found, -1 if not found
*/
int get_error_id(const char *error_category, const char *error_type, const char *error_severity);
#endif /* ERROR_MAP_H */
+32 -1
Ver Arquivo
@@ -150,7 +150,7 @@ typedef enum {
#define AMDSMI_MAX_NUM_JPEG 32
/**
* @brief new for gpu metrics v1.8, document presents NUM_JPEG_ENG_V1
* @brief Introduced in gpu metrics v1.8, document presents NUM_JPEG_ENG_V1
* but will change to AMDSMI_MAX_NUM_JPEG_ENG_V1 for continuity
*/
#define AMDSMI_MAX_NUM_JPEG_ENG_V1 40
@@ -182,6 +182,11 @@ typedef enum {
*/
#define AMDSMI_MAX_NUM_XCP 8
/**
* @brief Max Number of AFIDs that will be inside one cper entry
*/
#define MAX_NUMBER_OF_AFIDS_PER_RECORD 12
/* string format */
#define AMDSMI_TIME_FORMAT "%02d:%02d:%02d.%03d"
#define AMDSMI_DATE_FORMAT "%04d-%02d-%02d:%02d:%02d:%02d.%03d"
@@ -4795,6 +4800,32 @@ amdsmi_get_gpu_cper_entries(amdsmi_processor_handle processor_handle, uint32_t s
/** @} End tagECCInfo */
/**
* @brief Get the AFIDs from CPER buffer
*
* @platform{gpu_bm_linux} @platform{host} @platform{guest_1vf}
* @platform{guest_mvf} @platform{guest_windows}
*
* @details A utility function which retrieves the AFIDs from the CPER record.
*
* @param[in] cper_buffer a pointer to the buffer with one CPER record. The caller must make sure the whole CPER record is loaded into the buffer.
*
* @param[in] buf_size is the size of the cper_buffer.
*
* @param[out] afids a pointer to an array of uint64_t to which the AF IDs will be written
*
* @param[in,out] num_afids As input, the value passed through this parameter is the number of
* uint64_t that may be safely written to the memory pointed to by @p afids. This is the limit
* on how many AF IDs will be written to @p afids. On return, @p num_afids will contain the
* number of AF IDs written to @p afids, or the number of AF IDs that could have been written
* if enough memory had been provided. It is suggest to pass MAX_NUMBER_OF_AFIDS_PER_RECORD for all
* AF Ids.
*
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success, non-zero on fail
*/
amdsmi_status_t amdsmi_get_afids_from_cper(
char* cper_buffer, uint32_t buf_size, uint64_t* afids, uint32_t* num_afids);
/*****************************************************************************/
/** @defgroup tagErrorQuery Error Queries
* These functions provide error information about AMDSMI calls as well as
+223
Ver Arquivo
@@ -0,0 +1,223 @@
/*
* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "amd_smi/amdsmi.h"
#pragma pack(1)
#define CPER_MAX_OAM_COUNT (8)
typedef enum cper_error_severity {
CPER_SEV_FATAL_UNCORRECTED = 0,
CPER_SEV_FATAL = 1,
CPER_SEV_FATAL_CORRECTED = 2,
CPER_SEV_UNUSED = 10,
};
typedef enum cper_aca_reg {
CPER_ACA_REG_CTL_LO = 0,
CPER_ACA_REG_CTL_HI = 1,
CPER_ACA_REG_STATUS_LO = 2,
CPER_ACA_REG_STATUS_HI = 3,
CPER_ACA_REG_ADDR_LO = 4,
CPER_ACA_REG_ADDR_HI = 5,
CPER_ACA_REG_MISC0_LO = 6,
CPER_ACA_REG_MISC0_HI = 7,
CPER_ACA_REG_CONFIG_LO = 8,
CPER_ACA_REG_CONFIG_HI = 9,
CPER_ACA_REG_IPID_LO = 10,
CPER_ACA_REG_IPID_HI = 11,
CPER_ACA_REG_SYND_LO = 12,
CPER_ACA_REG_SYND_HI = 13,
CPER_ACA_REG_COUNT = 32,
};
struct cper_sec_desc {
uint32_t sec_offset; /* Offset from the start of CPER entry */
uint32_t sec_length;
uint8_t revision_minor; /* CPER_SEC_MINOR_REV_1 */
uint8_t revision_major; /* CPER_SEC_MAJOR_REV_22 */
union {
struct {
uint8_t fru_id : 1;
uint8_t fru_text : 1;
uint8_t reserved : 6;
} valid_bits;
uint8_t valid_mask;
};
uint8_t reserved;
union {
struct {
uint32_t primary : 1;
uint32_t reserved1 : 2;
uint32_t exceed_err_threshold : 1;
uint32_t latent_err : 1; /* "Deferred" error Creation*/
uint32_t reserved2 : 27;
} flags_bits;
uint32_t flags_mask;
};
amdsmi_cper_guid_t sec_type; /* AMD non-Standard, AMD Crashdump */
char fru_id[16]; /* FRU Serial ID */
amdsmi_cper_sev_t severity;
char fru_text[20]; /* "OAM%d" */
};
struct cper_sec_nonstd_err_info {
amdsmi_cper_guid_t error_type;
union {
struct {
uint64_t ms_chk : 1;
uint64_t target_addr_id : 1;
uint64_t req_id : 1;
uint64_t resp_id : 1;
uint64_t instr_ptr : 1;
uint64_t reserved : 59;
} valid_bits;
uint64_t valid_mask;
};
union {
struct {
uint64_t err_type_valid : 1;
uint64_t pcc_valid : 1;
uint64_t uncorr_valid : 1;
uint64_t precise_ip_valid : 1;
uint64_t restartable_ip_valid : 1;
uint64_t overflow_valid : 1;
uint64_t reserved1 : 10;
uint64_t err_type : 2;
uint64_t pcc : 1;
uint64_t uncorr : 1;
uint64_t precised_ip : 1;
uint64_t restartable_ip : 1;
uint64_t overflow : 1;
uint64_t reserved2 : 41;
} ms_chk_bits;
uint64_t ms_chk_mask;
};
uint64_t target_addr_id;
uint64_t req_id;
uint64_t resp_id;
uint64_t instr_ptr;
};
struct cper_sec_nonstd_err_ctx {
uint16_t reg_ctx_type;
uint16_t reg_arr_size;
uint32_t msr_addr;
uint64_t mm_reg_addr;
uint32_t reg_dump[CPER_ACA_REG_COUNT]; /* This buffer can grow */
};
struct cper_sec_nonstd_err_hdr {
union {
struct {
uint64_t apic_id : 1;
uint64_t fw_id : 1;
uint64_t err_info_cnt : 6; /* should match context_cnt */
uint64_t err_context_cnt : 6; /* should match info_cnt */
} valid_bits;
uint64_t valid_mask;
};
uint64_t apic_id;
char fw_id[48];
};
struct cper_sec_nonstd_err_body {
struct cper_sec_nonstd_err_info err_info;
struct cper_sec_nonstd_err_ctx err_ctx;
};
struct cper_sec_nonstd_err {
struct cper_sec_nonstd_err_hdr hdr;
struct cper_sec_nonstd_err_body body[]; /* Variable Size, today only 1 entry */
};
struct cper_sec_crashdump_data {
uint16_t reg_ctx_type;
uint16_t reg_arr_size;
uint32_t reserved1;
uint64_t reserved2;
union {
struct {
uint32_t status_lo;
uint32_t status_hi;
uint32_t addr_lo;
uint32_t addr_hi;
uint32_t ipid_lo;
uint32_t ipid_hi;
uint32_t synd_lo;
uint32_t synd_hi;
} fatal_err;
struct {
uint64_t msg[CPER_MAX_OAM_COUNT];
} boot_err;
} dump;
};
struct cper_sec_crashdump {
uint64_t reserved1;
uint64_t reserved2;
char fw_id[48];
uint64_t reserved3[8];
struct cper_sec_crashdump_data data;
};
struct cper_sec {
union {
struct {
uint8_t fru_id : 1;
uint8_t fru_text : 1;
uint8_t reserved : 6;
} valid_bits;
uint8_t valid_mask;
};
union {
struct cper_sec_crashdump crashdump;
struct cper_sec_nonstd_err runtime_err;
};
};
/* General CPER record structure */
struct cper_1_0 {
struct cper_hdr *hdr;
struct cper_sec_desc *sec_desc; /* Variable Size */
struct cper_sec *sec; /* Variable Size */
};
#pragma pack()
amdsmi_status_t amdsmi_get_gpu_cper_entries_by_path(const char *amdgpu_ring_cper_file, uint32_t severity_mask,
char *cper_data, uint64_t *buf_size, amdsmi_cper_hdr_t **cper_hdrs,
uint64_t *entry_count, uint64_t *cursor);
std::vector<int> cper_decode(const amdsmi_cper_hdr_t *cper);
-1
Ver Arquivo
@@ -56,7 +56,6 @@ std::string smi_split_string(std::string str, char delim);
std::string smi_amdgpu_get_status_string(amdsmi_status_t ret, bool fullStatus);
amdsmi_status_t smi_clear_char_and_reinitialize(char buffer[], uint32_t len,
std::string newString);
amdsmi_status_t amdsmi_get_gpu_cper_entries_by_path(const char *amdgpu_ring_cper_file, uint32_t severity_mask, char *cper_data, uint64_t *buf_size, amdsmi_cper_hdr_t **cper_hdrs, uint64_t *entry_count, uint64_t *cursor);
/**
* @brief Wait for user input, a debugging function to pause the program
*