blob: ae4edd09011323321f3aec7c4fbaf46ac417a6ff [file] [log] [blame]
Zane Shelley0b8368c2021-03-18 17:33:41 -05001#include <analyzer/resolution.hpp>
Zane Shelley236bb732021-03-24 17:07:46 -05002#include <util/pdbg.hpp>
3#include <util/trace.hpp>
Zane Shelley0b8368c2021-03-18 17:33:41 -05004
5namespace analyzer
6{
7
Zane Shelley2d114322021-08-25 17:06:12 -05008//------------------------------------------------------------------------------
9
Zane Shelley96d54862021-09-17 11:16:12 -050010// Helper function to get the root cause chip target from the service data.
11pdbg_target* __getRootCauseChipTarget(const ServiceData& i_sd)
Zane Shelley0b8368c2021-03-18 17:33:41 -050012{
Zane Shelley96d54862021-09-17 11:16:12 -050013 auto target = util::pdbg::getTrgt(i_sd.getRootCause().getChip());
14 assert(nullptr != target); // This would be a really bad bug.
15 return target;
16}
Zane Shelley236bb732021-03-24 17:07:46 -050017
Zane Shelley96d54862021-09-17 11:16:12 -050018//------------------------------------------------------------------------------
19
20// Helper function to get a unit target from the given unit path, which is a
21// devtree path relative the the containing chip. An empty string indicates the
22// chip target should be returned.
23pdbg_target* __getUnitTarget(pdbg_target* i_chipTarget,
24 const std::string& i_unitPath)
25{
26 assert(nullptr != i_chipTarget);
27
28 auto target = i_chipTarget; // default, if i_unitPath is empty
29
30 if (!i_unitPath.empty())
Zane Shelley236bb732021-03-24 17:07:46 -050031 {
Zane Shelley96d54862021-09-17 11:16:12 -050032 auto path = std::string{util::pdbg::getPath(target)} + "/" + i_unitPath;
33
34 target = util::pdbg::getTrgt(path);
35 if (nullptr == target)
Zane Shelley236bb732021-03-24 17:07:46 -050036 {
Zane Shelley96d54862021-09-17 11:16:12 -050037 // Likely a bug the RAS data files.
38 throw std::logic_error("Unable to find target for " + path);
Zane Shelley236bb732021-03-24 17:07:46 -050039 }
40 }
41
Zane Shelley96d54862021-09-17 11:16:12 -050042 return target;
43}
44
45//------------------------------------------------------------------------------
46
Zane Shelley5d63cef2021-09-17 18:10:17 -050047// Helper function to get the connected target on the other side of the
48// given bus.
49pdbg_target* __getConnectedTarget(pdbg_target* i_rxTarget,
50 const callout::BusType& i_busType)
51{
52 assert(nullptr != i_rxTarget);
53
54 pdbg_target* txTarget = nullptr;
55
56 auto rxType = util::pdbg::getTrgtType(i_rxTarget);
57 std::string rxPath = util::pdbg::getPath(i_rxTarget);
58
59 if (callout::BusType::SMP_BUS == i_busType &&
60 util::pdbg::TYPE_IOLINK == rxType)
61 {
62 // TODO: Will need to reference some sort of data that can tell us how
63 // the processors are connected in the system. For now, return the
64 // RX target to avoid returning a nullptr.
65 trace::inf("No support to get peer target on SMP bus");
66 txTarget = i_rxTarget;
67 }
Zane Shelleybe619c02021-09-30 17:56:42 -050068 else if (callout::BusType::SMP_BUS == i_busType &&
69 util::pdbg::TYPE_IOHS == rxType)
70 {
71 // TODO: Will need to reference some sort of data that can tell us how
72 // the processors are connected in the system. For now, return the
73 // RX target to avoid returning a nullptr.
74 trace::inf("No support to get peer target on SMP bus");
75 txTarget = i_rxTarget;
76 }
Zane Shelley5d63cef2021-09-17 18:10:17 -050077 else if (callout::BusType::OMI_BUS == i_busType &&
78 util::pdbg::TYPE_OMI == rxType)
79 {
80 // This is a bit clunky. The pdbg APIs only give us the ability to
81 // iterate over the children instead of just returning a list. So we'll
82 // push all the children to a list and go from there.
83 std::vector<pdbg_target*> childList;
84
85 pdbg_target* childTarget = nullptr;
86 pdbg_for_each_target("ocmb", i_rxTarget, childTarget)
87 {
88 if (nullptr != childTarget)
89 {
90 childList.push_back(childTarget);
91 }
92 }
93
94 // We know there should only be one OCMB per OMI.
95 if (1 != childList.size())
96 {
97 throw std::logic_error("Invalid child list size for " + rxPath);
98 }
99
100 // Get the connected target.
101 txTarget = childList.front();
102 }
103 else if (callout::BusType::OMI_BUS == i_busType &&
104 util::pdbg::TYPE_OCMB == rxType)
105 {
106 txTarget = pdbg_target_parent("omi", i_rxTarget);
107 if (nullptr == txTarget)
108 {
109 throw std::logic_error("No parent OMI found for " + rxPath);
110 }
111 }
112 else
113 {
114 // This would be a code bug.
115 throw std::logic_error("Unsupported config: i_rxTarget=" + rxPath +
116 " i_busType=" + i_busType.getString());
117 }
118
119 assert(nullptr != txTarget); // just in case we missed something above
120
121 return txTarget;
122}
123
124//------------------------------------------------------------------------------
125
Zane Shelley9a738f72021-11-03 20:45:30 -0500126void __calloutTarget(ServiceData& io_sd, pdbg_target* i_target,
127 const callout::Priority& i_priority, bool i_guard)
128{
129 nlohmann::json callout;
130 callout["LocationCode"] = util::pdbg::getLocationCode(i_target);
131 callout["Priority"] = i_priority.getUserDataString();
132 callout["Deconfigured"] = false;
133 callout["Guarded"] = i_guard;
134 io_sd.addCallout(callout);
135}
136
137//------------------------------------------------------------------------------
138
Zane Shelley1eff9452021-11-03 13:59:54 -0500139void __calloutBackplane(ServiceData& io_sd, const callout::Priority& i_priority)
140{
141 // TODO: There isn't a device tree object for this. So will need to hardcode
142 // the location code for now. In the future, we will need a mechanism
143 // to make this data driven.
144
145 nlohmann::json callout;
146 callout["LocationCode"] = "P0";
147 callout["Priority"] = i_priority.getUserDataString();
148 callout["Deconfigured"] = false;
149 callout["Guarded"] = false;
150 io_sd.addCallout(callout);
151}
152
153//------------------------------------------------------------------------------
154
Zane Shelley96d54862021-09-17 11:16:12 -0500155void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
156{
157 // Get the target for the hardware callout.
158 auto target = __getUnitTarget(__getRootCauseChipTarget(io_sd), iv_unitPath);
159
Zane Shelleyc85716c2021-08-17 10:54:06 -0500160 // Add the actual callout to the service data.
Zane Shelley9a738f72021-11-03 20:45:30 -0500161 __calloutTarget(io_sd, target, iv_priority, iv_guard);
Zane Shelley236bb732021-03-24 17:07:46 -0500162
Zane Shelley2d114322021-08-25 17:06:12 -0500163 // Add the callout FFDC to the service data.
164 nlohmann::json ffdc;
165 ffdc["Callout Type"] = "Hardware Callout";
Zane Shelleya00426f2021-11-04 10:50:50 -0500166 ffdc["Target"] = util::pdbg::getPhysDevPath(target);
Zane Shelley2d114322021-08-25 17:06:12 -0500167 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500168 ffdc["Guard"] = iv_guard;
Zane Shelley2d114322021-08-25 17:06:12 -0500169 io_sd.addCalloutFFDC(ffdc);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500170}
171
Zane Shelleyc85716c2021-08-17 10:54:06 -0500172//------------------------------------------------------------------------------
173
Zane Shelley5d63cef2021-09-17 18:10:17 -0500174void ConnectedCalloutResolution::resolve(ServiceData& io_sd) const
175{
176 // Get the chip target from the root cause signature.
177 auto chipTarget = __getRootCauseChipTarget(io_sd);
178
179 // Get the endpoint target for the receiving side of the bus.
180 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
181
182 // Get the endpoint target for the transfer side of the bus.
183 auto txTarget = __getConnectedTarget(rxTarget, iv_busType);
184
185 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500186 __calloutTarget(io_sd, txTarget, iv_priority, iv_guard);
Zane Shelley5d63cef2021-09-17 18:10:17 -0500187
Zane Shelley5d63cef2021-09-17 18:10:17 -0500188 // Add the callout FFDC to the service data.
189 nlohmann::json ffdc;
190 ffdc["Callout Type"] = "Connected Callout";
191 ffdc["Bus Type"] = iv_busType.getString();
192 ffdc["Target"] = util::pdbg::getPhysDevPath(txTarget);
193 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500194 ffdc["Guard"] = iv_guard;
Zane Shelley5d63cef2021-09-17 18:10:17 -0500195 io_sd.addCalloutFFDC(ffdc);
196}
197
198//------------------------------------------------------------------------------
199
Zane Shelley4757a7b2021-09-20 22:23:38 -0500200void BusCalloutResolution::resolve(ServiceData& io_sd) const
201{
202 // Get the chip target from the root cause signature.
203 auto chipTarget = __getRootCauseChipTarget(io_sd);
204
205 // Get the endpoint target for the receiving side of the bus.
206 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
207
208 // Get the endpoint target for the transfer side of the bus.
209 auto txTarget = __getConnectedTarget(rxTarget, iv_busType);
210
211 // Callout the RX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500212 __calloutTarget(io_sd, rxTarget, iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500213
214 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500215 __calloutTarget(io_sd, txTarget, iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500216
217 // Callout everything else in between.
218 // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
Zane Shelley1eff9452021-11-03 13:59:54 -0500219 __calloutBackplane(io_sd, iv_priority);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500220
Zane Shelley4757a7b2021-09-20 22:23:38 -0500221 // Add the callout FFDC to the service data.
222 nlohmann::json ffdc;
223 ffdc["Callout Type"] = "Bus Callout";
224 ffdc["Bus Type"] = iv_busType.getString();
225 ffdc["RX Target"] = util::pdbg::getPhysDevPath(rxTarget);
226 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
227 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500228 ffdc["Guard"] = iv_guard;
Zane Shelley4757a7b2021-09-20 22:23:38 -0500229 io_sd.addCalloutFFDC(ffdc);
230}
231
232//------------------------------------------------------------------------------
233
Zane Shelley84721d92021-09-08 13:30:27 -0500234void ClockCalloutResolution::resolve(ServiceData& io_sd) const
235{
Zane Shelley1eff9452021-11-03 13:59:54 -0500236 // Callout the clock target.
237 // TODO: For P10, the callout is simply the backplane. Also, there are no
238 // clock targets in the device tree. So at the moment there is no
239 // guard support for clock targets.
240 __calloutBackplane(io_sd, iv_priority);
Zane Shelley84721d92021-09-08 13:30:27 -0500241
242 // Add the callout FFDC to the service data.
Zane Shelley1eff9452021-11-03 13:59:54 -0500243 // TODO: Add the target and guard type if guard is ever supported.
Zane Shelley84721d92021-09-08 13:30:27 -0500244 nlohmann::json ffdc;
245 ffdc["Callout Type"] = "Clock Callout";
246 ffdc["Clock Type"] = iv_clockType.getString();
Zane Shelley84721d92021-09-08 13:30:27 -0500247 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelley84721d92021-09-08 13:30:27 -0500248 io_sd.addCalloutFFDC(ffdc);
249}
250
251//------------------------------------------------------------------------------
252
Zane Shelleyc85716c2021-08-17 10:54:06 -0500253void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
254{
255 // Add the actual callout to the service data.
256 nlohmann::json callout;
257 callout["Procedure"] = iv_procedure.getString();
258 callout["Priority"] = iv_priority.getUserDataString();
259 io_sd.addCallout(callout);
Zane Shelley2d114322021-08-25 17:06:12 -0500260
261 // Add the callout FFDC to the service data.
262 nlohmann::json ffdc;
263 ffdc["Callout Type"] = "Procedure Callout";
264 ffdc["Procedure"] = iv_procedure.getString();
265 ffdc["Priority"] = iv_priority.getRegistryString();
266 io_sd.addCalloutFFDC(ffdc);
Zane Shelleyc85716c2021-08-17 10:54:06 -0500267}
268
269//------------------------------------------------------------------------------
270
Zane Shelley0b8368c2021-03-18 17:33:41 -0500271} // namespace analyzer