1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright 2025 Advanced Micro Devices, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 */ 24 #ifndef __RAS_LOG_RING_H__ 25 #define __RAS_LOG_RING_H__ 26 #include "ras_aca.h" 27 28 #define MAX_RECORD_PER_BATCH 32 29 30 #define RAS_LOG_SEQNO_TO_BATCH_IDX(seqno) ((seqno) >> 8) 31 32 enum ras_log_event { 33 RAS_LOG_EVENT_NONE, 34 RAS_LOG_EVENT_UE, 35 RAS_LOG_EVENT_DE, 36 RAS_LOG_EVENT_CE, 37 RAS_LOG_EVENT_POISON_CREATION, 38 RAS_LOG_EVENT_POISON_CONSUMPTION, 39 RAS_LOG_EVENT_RMA, 40 RAS_LOG_EVENT_COUNT_MAX, 41 }; 42 43 struct ras_aca_reg { 44 uint64_t regs[ACA_REG_MAX_COUNT]; 45 }; 46 47 struct ras_log_info { 48 uint64_t seqno; 49 uint64_t timestamp; 50 enum ras_log_event event; 51 union { 52 struct ras_aca_reg aca_reg; 53 }; 54 }; 55 56 struct ras_log_batch_tag { 57 uint64_t batch_id; 58 uint64_t timestamp; 59 uint32_t sub_seqno; 60 }; 61 62 struct ras_log_ring { 63 void *ras_log_mempool; 64 struct radix_tree_root ras_log_root; 65 spinlock_t spin_lock; 66 uint64_t mono_upward_batch_id; 67 uint64_t last_del_batch_id; 68 int logged_ecc_count; 69 }; 70 71 struct ras_log_batch_overview { 72 uint64_t first_batch_id; 73 uint64_t last_batch_id; 74 uint32_t logged_batch_count; 75 }; 76 77 struct ras_core_context; 78 79 int ras_log_ring_sw_init(struct ras_core_context *ras_core); 80 int ras_log_ring_sw_fini(struct ras_core_context *ras_core); 81 82 struct ras_log_batch_tag *ras_log_ring_create_batch_tag(struct ras_core_context *ras_core); 83 void ras_log_ring_destroy_batch_tag(struct ras_core_context *ras_core, 84 struct ras_log_batch_tag *tag); 85 void ras_log_ring_add_log_event(struct ras_core_context *ras_core, 86 enum ras_log_event event, void *data, struct ras_log_batch_tag *tag); 87 88 int ras_log_ring_get_batch_records(struct ras_core_context *ras_core, uint64_t batch_idx, 89 struct ras_log_info **log_arr, uint32_t arr_num); 90 91 int ras_log_ring_get_batch_overview(struct ras_core_context *ras_core, 92 struct ras_log_batch_overview *overview); 93 #endif 94