Line data Source code
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 :
28 0 : void dp_trace_init(struct dc_link *link)
29 : {
30 0 : memset(&link->dp_trace, 0, sizeof(link->dp_trace));
31 0 : link->dp_trace.is_initialized = true;
32 0 : }
33 :
34 0 : void dp_trace_reset(struct dc_link *link)
35 : {
36 0 : memset(&link->dp_trace, 0, sizeof(link->dp_trace));
37 0 : }
38 :
39 0 : bool dc_dp_trace_is_initialized(struct dc_link *link)
40 : {
41 0 : return link->dp_trace.is_initialized;
42 : }
43 :
44 0 : void dp_trace_detect_lt_init(struct dc_link *link)
45 : {
46 0 : memset(&link->dp_trace.detect_lt_trace, 0, sizeof(link->dp_trace.detect_lt_trace));
47 0 : }
48 :
49 0 : void dp_trace_commit_lt_init(struct dc_link *link)
50 : {
51 0 : memset(&link->dp_trace.commit_lt_trace, 0, sizeof(link->dp_trace.commit_lt_trace));
52 0 : }
53 :
54 0 : void dp_trace_link_loss_increment(struct dc_link *link)
55 : {
56 0 : link->dp_trace.link_loss_count++;
57 0 : }
58 :
59 0 : void dp_trace_lt_fail_count_update(struct dc_link *link,
60 : unsigned int fail_count,
61 : bool in_detection)
62 : {
63 0 : if (in_detection)
64 0 : link->dp_trace.detect_lt_trace.counts.fail = fail_count;
65 : else
66 0 : link->dp_trace.commit_lt_trace.counts.fail = fail_count;
67 0 : }
68 :
69 0 : void dp_trace_lt_total_count_increment(struct dc_link *link,
70 : bool in_detection)
71 : {
72 0 : if (in_detection)
73 0 : link->dp_trace.detect_lt_trace.counts.total++;
74 : else
75 0 : link->dp_trace.commit_lt_trace.counts.total++;
76 0 : }
77 :
78 0 : void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
79 : bool in_detection,
80 : bool is_logged)
81 : {
82 0 : if (in_detection)
83 0 : link->dp_trace.detect_lt_trace.is_logged = is_logged;
84 : else
85 0 : link->dp_trace.commit_lt_trace.is_logged = is_logged;
86 0 : }
87 :
88 0 : bool dc_dp_trace_is_logged(struct dc_link *link,
89 : bool in_detection)
90 : {
91 0 : if (in_detection)
92 0 : return link->dp_trace.detect_lt_trace.is_logged;
93 : else
94 0 : return link->dp_trace.commit_lt_trace.is_logged;
95 : }
96 :
97 0 : void dp_trace_lt_result_update(struct dc_link *link,
98 : enum link_training_result result,
99 : bool in_detection)
100 : {
101 0 : if (in_detection)
102 0 : link->dp_trace.detect_lt_trace.result = result;
103 : else
104 0 : link->dp_trace.commit_lt_trace.result = result;
105 0 : }
106 :
107 0 : void dp_trace_set_lt_start_timestamp(struct dc_link *link,
108 : bool in_detection)
109 : {
110 0 : if (in_detection)
111 0 : link->dp_trace.detect_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
112 : else
113 0 : link->dp_trace.commit_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
114 0 : }
115 :
116 0 : void dp_trace_set_lt_end_timestamp(struct dc_link *link,
117 : bool in_detection)
118 : {
119 0 : if (in_detection)
120 0 : link->dp_trace.detect_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
121 : else
122 0 : link->dp_trace.commit_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
123 0 : }
124 :
125 0 : unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
126 : bool in_detection)
127 : {
128 0 : if (in_detection)
129 0 : return link->dp_trace.detect_lt_trace.timestamps.end;
130 : else
131 0 : return link->dp_trace.commit_lt_trace.timestamps.end;
132 : }
133 :
134 0 : struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
135 : bool in_detection)
136 : {
137 0 : if (in_detection)
138 0 : return &link->dp_trace.detect_lt_trace.counts;
139 : else
140 0 : return &link->dp_trace.commit_lt_trace.counts;
141 : }
142 :
143 0 : unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link)
144 : {
145 0 : return link->dp_trace.link_loss_count;
146 : }
147 :
148 0 : void dp_trace_set_edp_power_timestamp(struct dc_link *link,
149 : bool power_up)
150 : {
151 0 : if (!power_up)
152 : /*save driver power off time stamp*/
153 0 : link->dp_trace.edp_trace_power_timestamps.poweroff = dm_get_timestamp(link->dc->ctx);
154 : else
155 0 : link->dp_trace.edp_trace_power_timestamps.poweron = dm_get_timestamp(link->dc->ctx);
156 0 : }
157 :
158 0 : uint64_t dp_trace_get_edp_poweron_timestamp(struct dc_link *link)
159 : {
160 0 : return link->dp_trace.edp_trace_power_timestamps.poweron;
161 : }
162 :
163 0 : uint64_t dp_trace_get_edp_poweroff_timestamp(struct dc_link *link)
164 : {
165 0 : return link->dp_trace.edp_trace_power_timestamps.poweroff;
166 : }
|