blob: cf78149bc871bfb8633caa72cfa7f4e3adebee13 [file] [log] [blame]
Zane Shelleyd84ed6e2020-06-08 13:41:48 -05001#include <assert.h>
Ben Tyner87eabc62020-05-14 17:56:54 -05002#include <libpdbg.h>
Zane Shelley9fb73932020-09-15 13:34:57 -05003#include <unistd.h>
Ben Tyner87eabc62020-05-14 17:56:54 -05004
Ben Tyner0205f3b2020-02-24 10:24:47 -06005#include <hei_main.hpp>
Zane Shelley9fb73932020-09-15 13:34:57 -05006#include <phosphor-logging/log.hpp>
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -06007#include <util/pdbg.hpp>
Zane Shelleyd84ed6e2020-06-08 13:41:48 -05008#include <util/trace.hpp>
Ben Tyner0205f3b2020-02-24 10:24:47 -06009
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050010#include <algorithm>
Ben Tyner87eabc62020-05-14 17:56:54 -050011#include <fstream>
12#include <iostream>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050013#include <map>
14#include <string>
15
Ben Tyner0205f3b2020-02-24 10:24:47 -060016namespace analyzer
17{
18
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060019//------------------------------------------------------------------------------
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050020
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060021// Forward references for externally defined functions.
Ben Tyner87eabc62020-05-14 17:56:54 -050022
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060023void initializeIsolator(const std::vector<libhei::Chip>& i_chips);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050024
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050025//------------------------------------------------------------------------------
26
Zane Shelley2f263182020-07-10 21:41:21 -050027const char* __attn(libhei::AttentionType_t i_attnType)
28{
29 const char* str = "";
30 switch (i_attnType)
31 {
32 case libhei::ATTN_TYPE_CHECKSTOP:
33 str = "CHECKSTOP";
34 break;
35 case libhei::ATTN_TYPE_UNIT_CS:
36 str = "UNIT_CS";
37 break;
38 case libhei::ATTN_TYPE_RECOVERABLE:
39 str = "RECOVERABLE";
40 break;
41 case libhei::ATTN_TYPE_SP_ATTN:
42 str = "SP_ATTN";
43 break;
44 case libhei::ATTN_TYPE_HOST_ATTN:
45 str = "HOST_ATTN";
46 break;
47 default:
48 trace::err("Unsupported attention type: %u", i_attnType);
49 assert(0);
50 }
51 return str;
52}
53
54uint32_t __trgt(const libhei::Signature& i_sig)
55{
Zane Shelleya0299852020-11-13 13:38:04 -060056 uint8_t type = util::pdbg::getTrgtType(i_sig.getChip());
57 uint32_t pos = util::pdbg::getChipPos(i_sig.getChip());
Zane Shelley2f263182020-07-10 21:41:21 -050058
59 // Technically, the FapiPos attribute is 32-bit, but not likely to ever go
60 // over 24-bit.
61
62 return type << 24 | (pos & 0xffffff);
63}
64
65uint32_t __sig(const libhei::Signature& i_sig)
66{
67 return i_sig.getId() << 16 | i_sig.getInstance() << 8 | i_sig.getBit();
68}
69
70//------------------------------------------------------------------------------
71
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060072// Returns the chip model/level of the given target.
73libhei::ChipType_t __getChipType(pdbg_target* i_trgt)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050074{
75 libhei::ChipType_t type;
76
77 // START WORKAROUND
78 // TODO: Will need to grab the model/level from the target attributes when
79 // they are available. For now, use ATTR_TYPE to determine which
80 // currently supported value to use supported.
Zane Shelleya0299852020-11-13 13:38:04 -060081 uint8_t attrType = util::pdbg::getTrgtType(i_trgt);
Zane Shelley2f263182020-07-10 21:41:21 -050082 switch (attrType)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050083 {
84 case 0x05: // PROC
85 type = 0x120DA049;
86 break;
87
88 case 0x4b: // OCMB_CHIP
89 type = 0x160D2000;
90 break;
91
92 default:
Zane Shelley2f263182020-07-10 21:41:21 -050093 trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType);
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050094 assert(0);
95 }
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050096 // END WORKAROUND
97
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050098 return type;
99}
100
101//------------------------------------------------------------------------------
102
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600103// Gathers list of active chips to analyze.
104void __getActiveChips(std::vector<libhei::Chip>& o_chips)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500105{
106 // Iterate each processor.
107 pdbg_target* procTrgt;
108 pdbg_for_each_class_target("proc", procTrgt)
109 {
110 // Active processors only.
111 if (PDBG_TARGET_ENABLED != pdbg_target_probe(procTrgt))
112 continue;
113
114 // Add the processor to the list.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600115 o_chips.emplace_back(procTrgt, __getChipType(procTrgt));
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500116
117 // Iterate the connected OCMBs, if they exist.
118 pdbg_target* ocmbTrgt;
Zane Shelley06e10f92020-08-10 20:35:08 -0500119 pdbg_for_each_target("ocmb", procTrgt, ocmbTrgt)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500120 {
121 // Active OCMBs only.
122 if (PDBG_TARGET_ENABLED != pdbg_target_probe(ocmbTrgt))
123 continue;
124
125 // Add the OCMB to the list.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600126 o_chips.emplace_back(ocmbTrgt, __getChipType(ocmbTrgt));
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500127 }
128 }
Zane Shelley2e994bc2020-06-08 14:38:14 -0500129}
130
131//------------------------------------------------------------------------------
132
Zane Shelley097a71a2020-06-08 15:55:29 -0500133// Takes a signature list that will be filtered and sorted. The first entry in
134// the returned list will be the root cause. If the returned list is empty,
135// analysis failed.
136void __filterRootCause(std::vector<libhei::Signature>& io_list)
137{
Zane Shelley2f263182020-07-10 21:41:21 -0500138 // For debug, trace out the original list of signatures before filtering.
139 for (const auto& sig : io_list)
140 {
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600141 trace::inf("Signature: %s 0x%0" PRIx32 " %s",
142 util::pdbg::getPath(sig.getChip()), __sig(sig),
143 __attn(sig.getAttnType()));
Zane Shelley2f263182020-07-10 21:41:21 -0500144 }
145
Zane Shelley097a71a2020-06-08 15:55:29 -0500146 // Special and host attentions are not supported by this user application.
147 auto newEndItr =
148 std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) {
149 return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() ||
150 libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType());
151 });
152
153 // Shrink the vector, if needed.
154 io_list.resize(std::distance(io_list.begin(), newEndItr));
155
156 // START WORKAROUND
157 // TODO: Filtering should be determined by the RAS Data Files provided by
158 // the host firmware via the PNOR (similar to the Chip Data Files).
159 // Until that support is available, use a rudimentary filter that
160 // first looks for any recoverable attention, then any unit checkstop,
161 // and then any system checkstop. This is built on the premise that
162 // recoverable errors could be the root cause of an system checkstop
163 // attentions. Fortunately, we just need to sort the list by the
164 // greater attention type value.
165 std::sort(io_list.begin(), io_list.end(),
166 [&](const auto& a, const auto& b) {
167 return a.getAttnType() > b.getAttnType();
168 });
169 // END WORKAROUND
170}
171
172//------------------------------------------------------------------------------
173
Zane Shelley9fb73932020-09-15 13:34:57 -0500174bool __logError(const std::vector<libhei::Signature>& i_sigList,
175 const libhei::IsolationData& i_isoData)
176{
177 bool attnFound = false;
178
179 // Get numerical values for the root cause.
180 uint32_t word6 = 0; // [ 0: 7]: chip target type
181 // [ 8:31]: chip FAPI position
182 // uint32_t word7 = 0; // TODO: chip target info
183 uint32_t word8 = 0; // [ 0:15]: node ID
184 // [16:23]: node instance
185 // [24:31]: bit position
186 // uint32_t word9 = 0; // [ 0: 7]: attention type
187
188 if (i_sigList.empty())
189 {
190 trace::inf("No active attentions found");
191 }
192 else
193 {
194 attnFound = true;
195
196 // The root cause attention is the first in the filtered list.
197 libhei::Signature root = i_sigList.front();
198
199 word6 = __trgt(root);
200 word8 = __sig(root);
201
202 trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s",
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600203 util::pdbg::getPath(root.getChip()), word8,
204 __attn(root.getAttnType()));
Zane Shelley9fb73932020-09-15 13:34:57 -0500205 }
206
207 // Get the log data.
208 std::map<std::string, std::string> logData;
209 logData["_PID"] = std::to_string(getpid());
210 logData["CHIP_ID"] = std::to_string(word6);
211 logData["SIGNATURE"] = std::to_string(word8);
212
213 // Get access to logging interface and method for creating log.
214 auto bus = sdbusplus::bus::new_default_system();
215
216 // Using direct create method (for additional data)
217 auto method = bus.new_method_call(
218 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
219 "xyz.openbmc_project.Logging.Create", "Create");
220
221 // Attach additional data
222 method.append("org.open_power.HwDiags.Error.Checkstop",
223 "xyz.openbmc_project.Logging.Entry.Level.Error", logData);
224
225 // Log the event.
226 // TODO: Should the reply be handled?
227 bus.call(method);
228
229 return attnFound;
230}
231
232//------------------------------------------------------------------------------
233
234bool analyzeHardware()
Ben Tyner87eabc62020-05-14 17:56:54 -0500235{
Zane Shelley097a71a2020-06-08 15:55:29 -0500236 bool attnFound = false;
Ben Tyner87eabc62020-05-14 17:56:54 -0500237
Zane Shelley2f263182020-07-10 21:41:21 -0500238 trace::inf(">>> enter analyzeHardware()");
239
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600240 // Get the active chips to be analyzed.
241 std::vector<libhei::Chip> chips;
242 __getActiveChips(chips);
Ben Tyner87eabc62020-05-14 17:56:54 -0500243
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600244 // Initialize the isolator for all chips.
245 trace::inf("Initializing the isolator...");
246 initializeIsolator(chips);
Zane Shelley2e994bc2020-06-08 14:38:14 -0500247
Zane Shelley097a71a2020-06-08 15:55:29 -0500248 // Isolate attentions.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600249 trace::inf("Isolating errors: # of chips=%u", chips.size());
Zane Shelley097a71a2020-06-08 15:55:29 -0500250 libhei::IsolationData isoData{};
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600251 libhei::isolate(chips, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500252
Zane Shelley2f263182020-07-10 21:41:21 -0500253 // Filter signatures to determine root cause. We'll need to make a copy of
254 // the list so that the original list is maintained for the log.
Zane Shelley097a71a2020-06-08 15:55:29 -0500255 std::vector<libhei::Signature> sigList{isoData.getSignatureList()};
256 __filterRootCause(sigList);
257
Zane Shelley9fb73932020-09-15 13:34:57 -0500258 // Create and commit a log.
259 attnFound = __logError(sigList, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500260
Zane Shelley097a71a2020-06-08 15:55:29 -0500261 // All done, clean up the isolator.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600262 trace::inf("Uninitializing isolator...");
Zane Shelley097a71a2020-06-08 15:55:29 -0500263 libhei::uninitialize();
Ben Tyner87eabc62020-05-14 17:56:54 -0500264
Zane Shelley2f263182020-07-10 21:41:21 -0500265 trace::inf("<<< exit analyzeHardware()");
266
Zane Shelley097a71a2020-06-08 15:55:29 -0500267 return attnFound;
Ben Tyner0205f3b2020-02-24 10:24:47 -0600268}
269
270} // namespace analyzer