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 "dc_link.h"
26 #include "link_dp_trace.h"
27
dp_trace_init(struct dc_link * link)28 void dp_trace_init(struct dc_link *link)
29 {
30 memset(&link->dp_trace, 0, sizeof(link->dp_trace));
31 link->dp_trace.is_initialized = true;
32 }
33
dp_trace_reset(struct dc_link * link)34 void dp_trace_reset(struct dc_link *link)
35 {
36 memset(&link->dp_trace, 0, sizeof(link->dp_trace));
37 }
38
dc_dp_trace_is_initialized(struct dc_link * link)39 bool dc_dp_trace_is_initialized(struct dc_link *link)
40 {
41 return link->dp_trace.is_initialized;
42 }
43
dp_trace_detect_lt_init(struct dc_link * link)44 void dp_trace_detect_lt_init(struct dc_link *link)
45 {
46 memset(&link->dp_trace.detect_lt_trace, 0, sizeof(link->dp_trace.detect_lt_trace));
47 }
48
dp_trace_commit_lt_init(struct dc_link * link)49 void dp_trace_commit_lt_init(struct dc_link *link)
50 {
51 memset(&link->dp_trace.commit_lt_trace, 0, sizeof(link->dp_trace.commit_lt_trace));
52 }
53
dp_trace_link_loss_increment(struct dc_link * link)54 void dp_trace_link_loss_increment(struct dc_link *link)
55 {
56 link->dp_trace.link_loss_count++;
57 }
58
dp_trace_lt_fail_count_update(struct dc_link * link,unsigned int fail_count,bool in_detection)59 void dp_trace_lt_fail_count_update(struct dc_link *link,
60 unsigned int fail_count,
61 bool in_detection)
62 {
63 if (in_detection)
64 link->dp_trace.detect_lt_trace.counts.fail = fail_count;
65 else
66 link->dp_trace.commit_lt_trace.counts.fail = fail_count;
67 }
68
dp_trace_lt_total_count_increment(struct dc_link * link,bool in_detection)69 void dp_trace_lt_total_count_increment(struct dc_link *link,
70 bool in_detection)
71 {
72 if (in_detection)
73 link->dp_trace.detect_lt_trace.counts.total++;
74 else
75 link->dp_trace.commit_lt_trace.counts.total++;
76 }
77
dc_dp_trace_set_is_logged_flag(struct dc_link * link,bool in_detection,bool is_logged)78 void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
79 bool in_detection,
80 bool is_logged)
81 {
82 if (in_detection)
83 link->dp_trace.detect_lt_trace.is_logged = is_logged;
84 else
85 link->dp_trace.commit_lt_trace.is_logged = is_logged;
86 }
87
dc_dp_trace_is_logged(struct dc_link * link,bool in_detection)88 bool dc_dp_trace_is_logged(struct dc_link *link,
89 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
dp_trace_lt_result_update(struct dc_link * link,enum link_training_result result,bool in_detection)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
dp_trace_set_lt_start_timestamp(struct dc_link * link,bool in_detection)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
dp_trace_set_lt_end_timestamp(struct dc_link * link,bool in_detection)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
dc_dp_trace_get_lt_end_timestamp(struct dc_link * link,bool in_detection)125 unsigned long long dc_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
dc_dp_trace_get_lt_counts(struct dc_link * link,bool in_detection)134 struct dp_trace_lt_counts *dc_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
dc_dp_trace_get_link_loss_count(struct dc_link * link)143 unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link)
144 {
145 return link->dp_trace.link_loss_count;
146 }
147
dp_trace_set_edp_power_timestamp(struct dc_link * link,bool power_up)148 void 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
dp_trace_get_edp_poweron_timestamp(struct dc_link * link)158 uint64_t dp_trace_get_edp_poweron_timestamp(struct dc_link *link)
159 {
160 return link->dp_trace.edp_trace_power_timestamps.poweron;
161 }
162
dp_trace_get_edp_poweroff_timestamp(struct dc_link * link)163 uint64_t dp_trace_get_edp_poweroff_timestamp(struct dc_link *link)
164 {
165 return link->dp_trace.edp_trace_power_timestamps.poweroff;
166 }