19e585a52SHawking Zhang /* 29e585a52SHawking Zhang * Copyright (C) 2019 Advanced Micro Devices, Inc. 39e585a52SHawking Zhang * 49e585a52SHawking Zhang * Permission is hereby granted, free of charge, to any person obtaining a 59e585a52SHawking Zhang * copy of this software and associated documentation files (the "Software"), 69e585a52SHawking Zhang * to deal in the Software without restriction, including without limitation 79e585a52SHawking Zhang * the rights to use, copy, modify, merge, publish, distribute, sublicense, 89e585a52SHawking Zhang * and/or sell copies of the Software, and to permit persons to whom the 99e585a52SHawking Zhang * Software is furnished to do so, subject to the following conditions: 109e585a52SHawking Zhang * 119e585a52SHawking Zhang * The above copyright notice and this permission notice shall be included 129e585a52SHawking Zhang * in all copies or substantial portions of the Software. 139e585a52SHawking Zhang * 149e585a52SHawking Zhang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 159e585a52SHawking Zhang * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 169e585a52SHawking Zhang * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 179e585a52SHawking Zhang * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 189e585a52SHawking Zhang * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 199e585a52SHawking Zhang * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 209e585a52SHawking Zhang */ 219e585a52SHawking Zhang #ifndef __AMDGPU_UMC_H__ 229e585a52SHawking Zhang #define __AMDGPU_UMC_H__ 23efe17d5aSyipechai #include "amdgpu_ras.h" 24afb617f3SYiPeng Chai #include "amdgpu_mca.h" 25c5a4ef3eSJohn Clements /* 266ec598ccSStanley.Yang * (addr / 256) * 4096, the higher 26 bits in ErrorAddr 276ec598ccSStanley.Yang * is the index of 4KB block 286ec598ccSStanley.Yang */ 296ec598ccSStanley.Yang #define ADDR_OF_4KB_BLOCK(addr) (((addr) & ~0xffULL) << 4) 306ec598ccSStanley.Yang /* 31c5a4ef3eSJohn Clements * (addr / 256) * 8192, the higher 26 bits in ErrorAddr 32c5a4ef3eSJohn Clements * is the index of 8KB block 33c5a4ef3eSJohn Clements */ 34c5a4ef3eSJohn Clements #define ADDR_OF_8KB_BLOCK(addr) (((addr) & ~0xffULL) << 5) 3540a08fe8STao Zhou /* 3640a08fe8STao Zhou * (addr / 256) * 32768, the higher 26 bits in ErrorAddr 3740a08fe8STao Zhou * is the index of 8KB block 3840a08fe8STao Zhou */ 3940a08fe8STao Zhou #define ADDR_OF_32KB_BLOCK(addr) (((addr) & ~0xffULL) << 7) 40c5a4ef3eSJohn Clements /* channel index is the index of 256B block */ 41c5a4ef3eSJohn Clements #define ADDR_OF_256B_BLOCK(channel_index) ((channel_index) << 8) 42c5a4ef3eSJohn Clements /* offset in 256B block */ 43c5a4ef3eSJohn Clements #define OFFSET_IN_256B_BLOCK(addr) ((addr) & 0xffULL) 44c5a4ef3eSJohn Clements 45c5a4ef3eSJohn Clements #define LOOP_UMC_INST(umc_inst) for ((umc_inst) = 0; (umc_inst) < adev->umc.umc_inst_num; (umc_inst)++) 46c5a4ef3eSJohn Clements #define LOOP_UMC_CH_INST(ch_inst) for ((ch_inst) = 0; (ch_inst) < adev->umc.channel_inst_num; (ch_inst)++) 47c5a4ef3eSJohn Clements #define LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) LOOP_UMC_INST((umc_inst)) LOOP_UMC_CH_INST((ch_inst)) 48c5a4ef3eSJohn Clements 49e4b1edf4SYiPeng Chai #define LOOP_UMC_NODE_INST(node_inst) \ 502b595659SCandice Li for_each_set_bit((node_inst), &(adev->umc.active_mask), adev->umc.node_inst_num) 51e4b1edf4SYiPeng Chai 52e4b1edf4SYiPeng Chai #define LOOP_UMC_EACH_NODE_INST_AND_CH(node_inst, umc_inst, ch_inst) \ 53e4b1edf4SYiPeng Chai LOOP_UMC_NODE_INST((node_inst)) LOOP_UMC_INST_AND_CH((umc_inst), (ch_inst)) 54e4b1edf4SYiPeng Chai 55f27defcaSYiPeng Chai /* Page retirement tag */ 56f27defcaSYiPeng Chai #define UMC_ECC_NEW_DETECTED_TAG 0x1 57e86bd8b2SYiPeng Chai 58e86bd8b2SYiPeng Chai typedef int (*umc_func)(struct amdgpu_device *adev, uint32_t node_inst, 59e86bd8b2SYiPeng Chai uint32_t umc_inst, uint32_t ch_inst, void *data); 60e86bd8b2SYiPeng Chai 61efe17d5aSyipechai struct amdgpu_umc_ras { 62efe17d5aSyipechai struct amdgpu_ras_block_object ras_block; 63d99659a0STao Zhou void (*err_cnt_init)(struct amdgpu_device *adev); 64aaca8c38STao Zhou bool (*query_ras_poison_mode)(struct amdgpu_device *adev); 658882f90aSStanley.Yang void (*ecc_info_query_ras_error_count)(struct amdgpu_device *adev, 668882f90aSStanley.Yang void *ras_error_status); 678882f90aSStanley.Yang void (*ecc_info_query_ras_error_address)(struct amdgpu_device *adev, 688882f90aSStanley.Yang void *ras_error_status); 69afb617f3SYiPeng Chai bool (*check_ecc_err_status)(struct amdgpu_device *adev, 70afb617f3SYiPeng Chai enum amdgpu_mca_error_type type, void *ras_error_status); 7195b4063dSYiPeng Chai int (*update_ecc_status)(struct amdgpu_device *adev, 7295b4063dSYiPeng Chai uint64_t status, uint64_t ipid, uint64_t addr); 7349070c4eSHawking Zhang }; 7449070c4eSHawking Zhang 7549070c4eSHawking Zhang struct amdgpu_umc_funcs { 76e7da754bSMonk Liu void (*init_registers)(struct amdgpu_device *adev); 779e585a52SHawking Zhang }; 789e585a52SHawking Zhang 79045c0216STao Zhou struct amdgpu_umc { 80045c0216STao Zhou /* max error count in one ras query call */ 81045c0216STao Zhou uint32_t max_ras_err_cnt_per_query; 8233b97cf8STao Zhou /* number of umc channel instance with memory map register access */ 8333b97cf8STao Zhou uint32_t channel_inst_num; 8433b97cf8STao Zhou /* number of umc instance with memory map register access */ 8533b97cf8STao Zhou uint32_t umc_inst_num; 86e4b1edf4SYiPeng Chai 872b595659SCandice Li /* Total number of umc node instance including harvest one */ 88e4b1edf4SYiPeng Chai uint32_t node_inst_num; 89e4b1edf4SYiPeng Chai 9033b97cf8STao Zhou /* UMC regiser per channel offset */ 9133b97cf8STao Zhou uint32_t channel_offs; 92e69c7857STao Zhou /* how many pages are retired in one UE */ 93e69c7857STao Zhou uint32_t retire_unit; 9433b97cf8STao Zhou /* channel index table of interleaved memory */ 9533b97cf8STao Zhou const uint32_t *channel_idx_tbl; 9603740baaSTao Zhou struct ras_common_if *ras_if; 9733b97cf8STao Zhou 98045c0216STao Zhou const struct amdgpu_umc_funcs *funcs; 99efe17d5aSyipechai struct amdgpu_umc_ras *ras; 1002b595659SCandice Li 1012b595659SCandice Li /* active mask for umc node instance */ 1022b595659SCandice Li unsigned long active_mask; 103045c0216STao Zhou }; 104045c0216STao Zhou 105a6dcf9a7SHawking Zhang int amdgpu_umc_ras_sw_init(struct amdgpu_device *adev); 1064e9b1fa5Syipechai int amdgpu_umc_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block); 107ed1e1e42SYiPeng Chai int amdgpu_umc_poison_handler(struct amdgpu_device *adev, 1082fc46e0bSTao Zhou enum amdgpu_ras_block block, uint32_t reset); 109*bfa579b3SYiPeng Chai int amdgpu_umc_pasid_poison_handler(struct amdgpu_device *adev, 110*bfa579b3SYiPeng Chai enum amdgpu_ras_block block, uint16_t pasid, 111*bfa579b3SYiPeng Chai pasid_notify pasid_fn, void *data, uint32_t reset); 11234cc4fd9STao Zhou int amdgpu_umc_process_ecc_irq(struct amdgpu_device *adev, 11334cc4fd9STao Zhou struct amdgpu_irq_src *source, 11434cc4fd9STao Zhou struct amdgpu_iv_entry *entry); 115e74313beSYiPeng Chai int amdgpu_umc_fill_error_record(struct ras_err_data *err_data, 116400013b2STao Zhou uint64_t err_addr, 117400013b2STao Zhou uint64_t retired_page, 118400013b2STao Zhou uint32_t channel_index, 119400013b2STao Zhou uint32_t umc_inst); 120a3ace75cSyipechai 121a3ace75cSyipechai int amdgpu_umc_process_ras_data_cb(struct amdgpu_device *adev, 122a3ace75cSyipechai void *ras_error_status, 123a3ace75cSyipechai struct amdgpu_iv_entry *entry); 124cbe4d43eSTao Zhou int amdgpu_umc_page_retirement_mca(struct amdgpu_device *adev, 125cbe4d43eSTao Zhou uint64_t err_addr, uint32_t ch_inst, uint32_t umc_inst); 126e86bd8b2SYiPeng Chai 127e86bd8b2SYiPeng Chai int amdgpu_umc_loop_channels(struct amdgpu_device *adev, 128e86bd8b2SYiPeng Chai umc_func func, void *data); 1296c23f3d1SYiPeng Chai 13095b4063dSYiPeng Chai int amdgpu_umc_update_ecc_status(struct amdgpu_device *adev, 13195b4063dSYiPeng Chai uint64_t status, uint64_t ipid, uint64_t addr); 132f27defcaSYiPeng Chai int amdgpu_umc_logs_ecc_err(struct amdgpu_device *adev, 133f27defcaSYiPeng Chai struct radix_tree_root *ecc_tree, struct ras_ecc_err *ecc_err); 1342cf8e50eSYiPeng Chai 1352cf8e50eSYiPeng Chai void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev, 1362cf8e50eSYiPeng Chai void *ras_error_status); 1379e585a52SHawking Zhang #endif 138