1 /* 2 * Copyright 2022 Advanced Micro Devices, Inc. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Authors: AMD 23 * 24 */ 25 #include "link_dp_trace.h" 26 #include "link/protocols/link_dpcd.h" 27 #include "link.h" 28 29 void dp_trace_init(struct dc_link *link) 30 { 31 memset(&link->dp_trace, 0, sizeof(link->dp_trace)); 32 link->dp_trace.is_initialized = true; 33 } 34 35 void dp_trace_reset(struct dc_link *link) 36 { 37 memset(&link->dp_trace, 0, sizeof(link->dp_trace)); 38 } 39 40 bool dp_trace_is_initialized(struct dc_link *link) 41 { 42 return link->dp_trace.is_initialized; 43 } 44 45 void dp_trace_detect_lt_init(struct dc_link *link) 46 { 47 memset(&link->dp_trace.detect_lt_trace, 0, sizeof(link->dp_trace.detect_lt_trace)); 48 } 49 50 void dp_trace_commit_lt_init(struct dc_link *link) 51 { 52 memset(&link->dp_trace.commit_lt_trace, 0, sizeof(link->dp_trace.commit_lt_trace)); 53 } 54 55 void dp_trace_link_loss_increment(struct dc_link *link) 56 { 57 link->dp_trace.link_loss_count++; 58 } 59 60 void dp_trace_lt_fail_count_update(struct dc_link *link, 61 unsigned int fail_count, 62 bool in_detection) 63 { 64 if (in_detection) 65 link->dp_trace.detect_lt_trace.counts.fail = fail_count; 66 else 67 link->dp_trace.commit_lt_trace.counts.fail = fail_count; 68 } 69 70 void dp_trace_lt_total_count_increment(struct dc_link *link, 71 bool in_detection) 72 { 73 if (in_detection) 74 link->dp_trace.detect_lt_trace.counts.total++; 75 else 76 link->dp_trace.commit_lt_trace.counts.total++; 77 } 78 79 void dp_trace_set_is_logged_flag(struct dc_link *link, 80 bool in_detection, 81 bool is_logged) 82 { 83 if (in_detection) 84 link->dp_trace.detect_lt_trace.is_logged = is_logged; 85 else 86 link->dp_trace.commit_lt_trace.is_logged = is_logged; 87 } 88 89 bool dp_trace_is_logged(struct dc_link *link, bool in_detection) 90 { 91 if (in_detection) 92 return link->dp_trace.detect_lt_trace.is_logged; 93 else 94 return link->dp_trace.commit_lt_trace.is_logged; 95 } 96 97 void dp_trace_lt_result_update(struct dc_link *link, 98 enum link_training_result result, 99 bool in_detection) 100 { 101 if (in_detection) 102 link->dp_trace.detect_lt_trace.result = result; 103 else 104 link->dp_trace.commit_lt_trace.result = result; 105 } 106 107 void dp_trace_set_lt_start_timestamp(struct dc_link *link, 108 bool in_detection) 109 { 110 if (in_detection) 111 link->dp_trace.detect_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx); 112 else 113 link->dp_trace.commit_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx); 114 } 115 116 void dp_trace_set_lt_end_timestamp(struct dc_link *link, 117 bool in_detection) 118 { 119 if (in_detection) 120 link->dp_trace.detect_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx); 121 else 122 link->dp_trace.commit_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx); 123 } 124 125 unsigned long long dp_trace_get_lt_end_timestamp(struct dc_link *link, 126 bool in_detection) 127 { 128 if (in_detection) 129 return link->dp_trace.detect_lt_trace.timestamps.end; 130 else 131 return link->dp_trace.commit_lt_trace.timestamps.end; 132 } 133 134 const struct dp_trace_lt_counts *dp_trace_get_lt_counts(struct dc_link *link, 135 bool in_detection) 136 { 137 if (in_detection) 138 return &link->dp_trace.detect_lt_trace.counts; 139 else 140 return &link->dp_trace.commit_lt_trace.counts; 141 } 142 143 unsigned int dp_trace_get_link_loss_count(struct dc_link *link) 144 { 145 return link->dp_trace.link_loss_count; 146 } 147 148 void link_dp_trace_set_edp_power_timestamp(struct dc_link *link, 149 bool power_up) 150 { 151 if (!power_up) 152 /*save driver power off time stamp*/ 153 link->dp_trace.edp_trace_power_timestamps.poweroff = dm_get_timestamp(link->dc->ctx); 154 else 155 link->dp_trace.edp_trace_power_timestamps.poweron = dm_get_timestamp(link->dc->ctx); 156 } 157 158 uint64_t link_dp_trace_get_edp_poweron_timestamp(struct dc_link *link) 159 { 160 return link->dp_trace.edp_trace_power_timestamps.poweron; 161 } 162 163 uint64_t link_dp_trace_get_edp_poweroff_timestamp(struct dc_link *link) 164 { 165 return link->dp_trace.edp_trace_power_timestamps.poweroff; 166 } 167 168 void link_dp_source_sequence_trace(struct dc_link *link, uint8_t dp_test_mode) 169 { 170 if (link != NULL && link->dc->debug.enable_driver_sequence_debug) 171 core_link_write_dpcd(link, DP_SOURCE_SEQUENCE, 172 &dp_test_mode, sizeof(dp_test_mode)); 173 } 174