blob: c13bc8bbf6da895b176d3269dfb8b2eea13d2963 [file] [log] [blame]
Zane Shelley979e2872021-09-20 22:46:06 -05001#include <analyzer/service_data.hpp>
2
3namespace analyzer
4{
5
Zane Shelley37acb282022-01-10 16:05:22 -06006//------------------------------------------------------------------------------
7
8void ServiceData::calloutTarget(pdbg_target* i_target,
Zane Shelley9980d482022-01-28 15:21:47 -06009 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -060010{
11 // Add the target to the callout list.
12 addTargetCallout(i_target, i_priority, i_guard);
13
14 // Add the callout FFDC.
15 nlohmann::json ffdc;
16 ffdc["Callout Type"] = "Hardware Callout";
17 ffdc["Target"] = util::pdbg::getPhysDevPath(i_target);
Zane Shelley9980d482022-01-28 15:21:47 -060018 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060019 ffdc["Guard"] = i_guard;
20 addCalloutFFDC(ffdc);
21}
22
23//------------------------------------------------------------------------------
24
25void ServiceData::calloutConnected(pdbg_target* i_rxTarget,
26 const callout::BusType& i_busType,
Zane Shelley9980d482022-01-28 15:21:47 -060027 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -060028{
29 // Get the endpoint target for the transfer side of the bus.
30 auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
31
32 // Callout the TX endpoint.
33 addTargetCallout(txTarget, i_priority, i_guard);
34
35 // Add the callout FFDC.
36 nlohmann::json ffdc;
37 ffdc["Callout Type"] = "Connected Callout";
38 ffdc["Bus Type"] = i_busType.getString();
39 ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
40 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
Zane Shelley9980d482022-01-28 15:21:47 -060041 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060042 ffdc["Guard"] = i_guard;
43 addCalloutFFDC(ffdc);
44}
45
46//------------------------------------------------------------------------------
47
48void ServiceData::calloutBus(pdbg_target* i_rxTarget,
49 const callout::BusType& i_busType,
Zane Shelley9980d482022-01-28 15:21:47 -060050 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -060051{
52 // Get the endpoint target for the transfer side of the bus.
53 auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
54
55 // Callout the RX endpoint.
56 addTargetCallout(i_rxTarget, i_priority, i_guard);
57
58 // Callout the TX endpoint.
59 addTargetCallout(txTarget, i_priority, i_guard);
60
61 // Callout everything else in between.
62 // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
63 addBackplaneCallout(i_priority);
64
65 // Add the callout FFDC.
66 nlohmann::json ffdc;
67 ffdc["Callout Type"] = "Bus Callout";
68 ffdc["Bus Type"] = i_busType.getString();
69 ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
70 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
Zane Shelley9980d482022-01-28 15:21:47 -060071 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060072 ffdc["Guard"] = i_guard;
73 addCalloutFFDC(ffdc);
74}
75
76//------------------------------------------------------------------------------
77
78void ServiceData::calloutClock(const callout::ClockType& i_clockType,
Zane Shelley9980d482022-01-28 15:21:47 -060079 callout::Priority i_priority, bool)
Zane Shelley37acb282022-01-10 16:05:22 -060080{
81 // Callout the clock target.
82 // TODO: For P10, the callout is simply the backplane. Also, there are no
83 // clock targets in the device tree. So at the moment there is no
84 // guard support for clock targets.
85 addBackplaneCallout(i_priority);
86
87 // Add the callout FFDC.
88 // TODO: Add the target and guard type if guard is ever supported.
89 nlohmann::json ffdc;
90 ffdc["Callout Type"] = "Clock Callout";
91 ffdc["Clock Type"] = i_clockType.getString();
Zane Shelley9980d482022-01-28 15:21:47 -060092 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060093 addCalloutFFDC(ffdc);
94}
95
96//------------------------------------------------------------------------------
97
98void ServiceData::calloutProcedure(const callout::Procedure& i_procedure,
Zane Shelley9980d482022-01-28 15:21:47 -060099 callout::Priority i_priority)
Zane Shelley37acb282022-01-10 16:05:22 -0600100{
101 // Add the actual callout to the service data.
102 nlohmann::json callout;
103 callout["Procedure"] = i_procedure.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600104 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600105 addCallout(callout);
106
107 // Add the callout FFDC.
108 nlohmann::json ffdc;
109 ffdc["Callout Type"] = "Procedure Callout";
110 ffdc["Procedure"] = i_procedure.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600111 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600112 addCalloutFFDC(ffdc);
113}
114
115//------------------------------------------------------------------------------
116
Zane Shelleya4134772022-01-10 17:22:44 -0600117void ServiceData::calloutPart(const callout::PartType& i_part,
Zane Shelley9980d482022-01-28 15:21:47 -0600118 callout::Priority i_priority)
Zane Shelleya4134772022-01-10 17:22:44 -0600119{
120 if (callout::PartType::PNOR == i_part)
121 {
122 // The PNOR is on the BMC card.
123 // TODO: Will need to be modified if we ever support systems with more
124 // than one BMC.
125 addTargetCallout(util::pdbg::getTrgt("/bmc0"), i_priority, false);
126 }
127 else
128 {
129 throw std::logic_error("Unsupported part type: " + i_part.getString());
130 }
131
132 // Add the callout FFDC.
133 nlohmann::json ffdc;
134 ffdc["Callout Type"] = "Part Callout";
135 ffdc["Part Type"] = i_part.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600136 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelleya4134772022-01-10 17:22:44 -0600137 addCalloutFFDC(ffdc);
138}
139
140//------------------------------------------------------------------------------
141
Zane Shelley979e2872021-09-20 22:46:06 -0500142void ServiceData::addCallout(const nlohmann::json& i_callout)
143{
144 // The new callout is either a hardware callout with a location code or a
145 // procedure callout.
146
147 std::string type{};
148 if (i_callout.contains("LocationCode"))
149 {
150 type = "LocationCode";
151 }
152 else if (i_callout.contains("Procedure"))
153 {
154 type = "Procedure";
155 }
156 else
157 {
158 throw std::logic_error("Unsupported callout: " + i_callout.dump());
159 }
160
161 // A map to determine the priority order. All of the medium priorities,
162 // including the medium group priorities, are all the same level.
163 static const std::map<std::string, unsigned int> m = {
164 {"H", 3}, {"M", 2}, {"A", 2}, {"B", 2}, {"C", 2}, {"L", 1},
165 };
166
167 bool addCallout = true;
168
169 for (auto& c : iv_calloutList)
170 {
171 if (c.contains(type) && (c.at(type) == i_callout.at(type)))
172 {
173 // The new callout already exists. Don't add a new callout.
174 addCallout = false;
175
176 if (m.at(c.at("Priority")) < m.at(i_callout.at("Priority")))
177 {
178 // The new callout has a higher priority, update it.
179 c["Priority"] = i_callout.at("Priority");
180 }
181 }
182 }
183
184 if (addCallout)
185 {
186 iv_calloutList.push_back(i_callout);
187 }
188}
189
Zane Shelley37acb282022-01-10 16:05:22 -0600190//------------------------------------------------------------------------------
191
192void ServiceData::addTargetCallout(pdbg_target* i_target,
Zane Shelley9980d482022-01-28 15:21:47 -0600193 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -0600194{
195 nlohmann::json callout;
196
197 callout["LocationCode"] = util::pdbg::getLocationCode(i_target);
Zane Shelley9980d482022-01-28 15:21:47 -0600198 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600199 callout["Deconfigured"] = false;
200 callout["Guarded"] = false; // default
201
202 // Check if guard info should be added.
203 if (i_guard)
204 {
205 auto guardType = queryGuardPolicy();
206
207 if (!(callout::GuardType::NONE == guardType))
208 {
209 callout["Guarded"] = true;
210 callout["EntityPath"] = util::pdbg::getPhysBinPath(i_target);
211 callout["GuardType"] = guardType.getString();
212 }
213 }
214
215 addCallout(callout);
216}
217
218//------------------------------------------------------------------------------
219
Zane Shelley9980d482022-01-28 15:21:47 -0600220void ServiceData::addBackplaneCallout(callout::Priority i_priority)
Zane Shelley37acb282022-01-10 16:05:22 -0600221{
222 // TODO: There isn't a device tree object for this. So will need to hardcode
223 // the location code for now. In the future, we will need a mechanism
224 // to make this data driven.
225
226 nlohmann::json callout;
227
228 callout["LocationCode"] = "P0";
Zane Shelley9980d482022-01-28 15:21:47 -0600229 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600230 callout["Deconfigured"] = false;
231 callout["Guarded"] = false;
232
233 addCallout(callout);
234}
235
236//------------------------------------------------------------------------------
237
Zane Shelley979e2872021-09-20 22:46:06 -0500238} // namespace analyzer