blob: 2a7d5f58e4e658c93d5b908849fca0f9690e8c60 [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);
Zane Shelley55e7fec2022-01-28 15:29:44 -060021 setSrcSubsystem(getTargetSubsystem(i_target), i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060022}
23
24//------------------------------------------------------------------------------
25
26void ServiceData::calloutConnected(pdbg_target* i_rxTarget,
27 const callout::BusType& i_busType,
Zane Shelley9980d482022-01-28 15:21:47 -060028 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -060029{
30 // Get the endpoint target for the transfer side of the bus.
31 auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
32
33 // Callout the TX endpoint.
34 addTargetCallout(txTarget, i_priority, i_guard);
35
36 // Add the callout FFDC.
37 nlohmann::json ffdc;
38 ffdc["Callout Type"] = "Connected Callout";
39 ffdc["Bus Type"] = i_busType.getString();
40 ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
41 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
Zane Shelley9980d482022-01-28 15:21:47 -060042 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060043 ffdc["Guard"] = i_guard;
44 addCalloutFFDC(ffdc);
Zane Shelley55e7fec2022-01-28 15:29:44 -060045 setSrcSubsystem(getTargetSubsystem(txTarget), i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060046}
47
48//------------------------------------------------------------------------------
49
50void ServiceData::calloutBus(pdbg_target* i_rxTarget,
51 const callout::BusType& i_busType,
Zane Shelley9980d482022-01-28 15:21:47 -060052 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -060053{
54 // Get the endpoint target for the transfer side of the bus.
55 auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
56
57 // Callout the RX endpoint.
58 addTargetCallout(i_rxTarget, i_priority, i_guard);
59
60 // Callout the TX endpoint.
61 addTargetCallout(txTarget, i_priority, i_guard);
62
63 // Callout everything else in between.
64 // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
65 addBackplaneCallout(i_priority);
66
67 // Add the callout FFDC.
68 nlohmann::json ffdc;
69 ffdc["Callout Type"] = "Bus Callout";
70 ffdc["Bus Type"] = i_busType.getString();
71 ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
72 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
Zane Shelley9980d482022-01-28 15:21:47 -060073 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060074 ffdc["Guard"] = i_guard;
75 addCalloutFFDC(ffdc);
Zane Shelley55e7fec2022-01-28 15:29:44 -060076 setSrcSubsystem(i_busType.getSrcSubsystem(), i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060077}
78
79//------------------------------------------------------------------------------
80
81void ServiceData::calloutClock(const callout::ClockType& i_clockType,
Zane Shelley9980d482022-01-28 15:21:47 -060082 callout::Priority i_priority, bool)
Zane Shelley37acb282022-01-10 16:05:22 -060083{
84 // Callout the clock target.
85 // TODO: For P10, the callout is simply the backplane. Also, there are no
86 // clock targets in the device tree. So at the moment there is no
87 // guard support for clock targets.
88 addBackplaneCallout(i_priority);
89
90 // Add the callout FFDC.
91 // TODO: Add the target and guard type if guard is ever supported.
92 nlohmann::json ffdc;
93 ffdc["Callout Type"] = "Clock Callout";
94 ffdc["Clock Type"] = i_clockType.getString();
Zane Shelley9980d482022-01-28 15:21:47 -060095 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060096 addCalloutFFDC(ffdc);
Zane Shelley55e7fec2022-01-28 15:29:44 -060097 setSrcSubsystem(i_clockType.getSrcSubsystem(), i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -060098}
99
100//------------------------------------------------------------------------------
101
102void ServiceData::calloutProcedure(const callout::Procedure& i_procedure,
Zane Shelley9980d482022-01-28 15:21:47 -0600103 callout::Priority i_priority)
Zane Shelley37acb282022-01-10 16:05:22 -0600104{
105 // Add the actual callout to the service data.
106 nlohmann::json callout;
107 callout["Procedure"] = i_procedure.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600108 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600109 addCallout(callout);
110
111 // Add the callout FFDC.
112 nlohmann::json ffdc;
113 ffdc["Callout Type"] = "Procedure Callout";
114 ffdc["Procedure"] = i_procedure.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600115 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600116 addCalloutFFDC(ffdc);
Zane Shelley55e7fec2022-01-28 15:29:44 -0600117 setSrcSubsystem(i_procedure.getSrcSubsystem(), i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600118}
119
120//------------------------------------------------------------------------------
121
Zane Shelleya4134772022-01-10 17:22:44 -0600122void ServiceData::calloutPart(const callout::PartType& i_part,
Zane Shelley9980d482022-01-28 15:21:47 -0600123 callout::Priority i_priority)
Zane Shelleya4134772022-01-10 17:22:44 -0600124{
125 if (callout::PartType::PNOR == i_part)
126 {
127 // The PNOR is on the BMC card.
128 // TODO: Will need to be modified if we ever support systems with more
129 // than one BMC.
130 addTargetCallout(util::pdbg::getTrgt("/bmc0"), i_priority, false);
131 }
132 else
133 {
134 throw std::logic_error("Unsupported part type: " + i_part.getString());
135 }
136
137 // Add the callout FFDC.
138 nlohmann::json ffdc;
139 ffdc["Callout Type"] = "Part Callout";
140 ffdc["Part Type"] = i_part.getString();
Zane Shelley9980d482022-01-28 15:21:47 -0600141 ffdc["Priority"] = callout::getStringFFDC(i_priority);
Zane Shelleya4134772022-01-10 17:22:44 -0600142 addCalloutFFDC(ffdc);
Zane Shelley55e7fec2022-01-28 15:29:44 -0600143 setSrcSubsystem(i_part.getSrcSubsystem(), i_priority);
Zane Shelleya4134772022-01-10 17:22:44 -0600144}
145
146//------------------------------------------------------------------------------
147
Zane Shelley979e2872021-09-20 22:46:06 -0500148void ServiceData::addCallout(const nlohmann::json& i_callout)
149{
150 // The new callout is either a hardware callout with a location code or a
151 // procedure callout.
152
153 std::string type{};
154 if (i_callout.contains("LocationCode"))
155 {
156 type = "LocationCode";
157 }
158 else if (i_callout.contains("Procedure"))
159 {
160 type = "Procedure";
161 }
162 else
163 {
164 throw std::logic_error("Unsupported callout: " + i_callout.dump());
165 }
166
167 // A map to determine the priority order. All of the medium priorities,
168 // including the medium group priorities, are all the same level.
169 static const std::map<std::string, unsigned int> m = {
170 {"H", 3}, {"M", 2}, {"A", 2}, {"B", 2}, {"C", 2}, {"L", 1},
171 };
172
173 bool addCallout = true;
174
175 for (auto& c : iv_calloutList)
176 {
177 if (c.contains(type) && (c.at(type) == i_callout.at(type)))
178 {
179 // The new callout already exists. Don't add a new callout.
180 addCallout = false;
181
182 if (m.at(c.at("Priority")) < m.at(i_callout.at("Priority")))
183 {
184 // The new callout has a higher priority, update it.
185 c["Priority"] = i_callout.at("Priority");
186 }
187 }
188 }
189
190 if (addCallout)
191 {
192 iv_calloutList.push_back(i_callout);
193 }
194}
195
Zane Shelley37acb282022-01-10 16:05:22 -0600196//------------------------------------------------------------------------------
197
198void ServiceData::addTargetCallout(pdbg_target* i_target,
Zane Shelley9980d482022-01-28 15:21:47 -0600199 callout::Priority i_priority, bool i_guard)
Zane Shelley37acb282022-01-10 16:05:22 -0600200{
201 nlohmann::json callout;
202
203 callout["LocationCode"] = util::pdbg::getLocationCode(i_target);
Zane Shelley9980d482022-01-28 15:21:47 -0600204 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600205 callout["Deconfigured"] = false;
206 callout["Guarded"] = false; // default
207
208 // Check if guard info should be added.
209 if (i_guard)
210 {
211 auto guardType = queryGuardPolicy();
212
213 if (!(callout::GuardType::NONE == guardType))
214 {
215 callout["Guarded"] = true;
216 callout["EntityPath"] = util::pdbg::getPhysBinPath(i_target);
217 callout["GuardType"] = guardType.getString();
218 }
219 }
220
221 addCallout(callout);
222}
223
224//------------------------------------------------------------------------------
225
Zane Shelley9980d482022-01-28 15:21:47 -0600226void ServiceData::addBackplaneCallout(callout::Priority i_priority)
Zane Shelley37acb282022-01-10 16:05:22 -0600227{
228 // TODO: There isn't a device tree object for this. So will need to hardcode
229 // the location code for now. In the future, we will need a mechanism
230 // to make this data driven.
231
232 nlohmann::json callout;
233
234 callout["LocationCode"] = "P0";
Zane Shelley9980d482022-01-28 15:21:47 -0600235 callout["Priority"] = callout::getString(i_priority);
Zane Shelley37acb282022-01-10 16:05:22 -0600236 callout["Deconfigured"] = false;
237 callout["Guarded"] = false;
238
239 addCallout(callout);
240}
241
242//------------------------------------------------------------------------------
243
Zane Shelley55e7fec2022-01-28 15:29:44 -0600244void ServiceData::setSrcSubsystem(callout::SrcSubsystem i_subsystem,
245 callout::Priority i_priority)
246{
247 // clang-format off
248 static const std::map<callout::Priority, unsigned int> m =
249 {
250 // Note that all medium priorities, including groups A, B, and C, are
251 // the same priority.
252 {callout::Priority::HIGH, 3},
253 {callout::Priority::MED, 2},
254 {callout::Priority::MED_A, 2},
255 {callout::Priority::MED_B, 2},
256 {callout::Priority::MED_C, 2},
257 {callout::Priority::LOW, 1},
258 };
259 // clang-format on
260
261 // The default subsystem is CEC_HARDWARE with LOW priority. Change the
262 // subsystem if the given subsystem has a higher priority or if the stored
263 // subsystem is still the default.
264 if (m.at(iv_srcSubsystem.second) < m.at(i_priority) ||
265 (callout::SrcSubsystem::CEC_HARDWARE == iv_srcSubsystem.first &&
266 callout::Priority::LOW == iv_srcSubsystem.second))
267 {
268 iv_srcSubsystem.first = i_subsystem;
269 iv_srcSubsystem.second = i_priority;
270 }
271}
272
273//------------------------------------------------------------------------------
274
275callout::SrcSubsystem ServiceData::getTargetSubsystem(pdbg_target* i_target)
276{
277 using TargetType_t = util::pdbg::TargetType_t;
278
279 // Default the subsystem to CEC_HARDWARE
280 callout::SrcSubsystem o_subSys = callout::SrcSubsystem::CEC_HARDWARE;
281
282 // clang-format off
283 static const std::map<uint8_t, callout::SrcSubsystem> subSysMap =
284 {
285 {TargetType_t::TYPE_DIMM, callout::SrcSubsystem::MEMORY_DIMM },
286 {TargetType_t::TYPE_PROC, callout::SrcSubsystem::PROCESSOR },
287 {TargetType_t::TYPE_CORE, callout::SrcSubsystem::PROCESSOR_UNIT},
288 {TargetType_t::TYPE_EQ, callout::SrcSubsystem::PROCESSOR },
289 {TargetType_t::TYPE_PEC, callout::SrcSubsystem::PHB },
290 {TargetType_t::TYPE_PHB, callout::SrcSubsystem::PHB },
291 {TargetType_t::TYPE_MC, callout::SrcSubsystem::MEMORY },
292 {TargetType_t::TYPE_IOLINK, callout::SrcSubsystem::CEC_HARDWARE },
293 {TargetType_t::TYPE_OMI, callout::SrcSubsystem::MEMORY },
294 {TargetType_t::TYPE_MCC, callout::SrcSubsystem::MEMORY },
295 {TargetType_t::TYPE_OMIC, callout::SrcSubsystem::MEMORY },
296 {TargetType_t::TYPE_OCMB, callout::SrcSubsystem::MEMORY },
297 {TargetType_t::TYPE_MEM_PORT, callout::SrcSubsystem::MEMORY },
298 {TargetType_t::TYPE_NMMU, callout::SrcSubsystem::PROCESSOR },
299 {TargetType_t::TYPE_PAU, callout::SrcSubsystem::PROCESSOR_BUS },
300 {TargetType_t::TYPE_IOHS, callout::SrcSubsystem::PROCESSOR_BUS },
301 {TargetType_t::TYPE_PAUC, callout::SrcSubsystem::PROCESSOR },
302 };
303 // clang-format on
304
305 auto targetType = util::pdbg::getTrgtType(i_target);
306
307 // If the type of the input target exists in the map, update the output
308 if (subSysMap.count(targetType) > 0)
309 {
310 o_subSys = subSysMap.at(targetType);
311 }
312
313 return o_subSys;
314}
315
316//------------------------------------------------------------------------------
317
Zane Shelley979e2872021-09-20 22:46:06 -0500318} // namespace analyzer