blob: cf3d1956cb90b1707a0266c5be719b794edf07c9 [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 -050027uint8_t __attrType(pdbg_target* i_trgt)
28{
29 uint8_t attr = 0;
30 pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, &attr);
31 return attr;
32}
33
34uint32_t __attrFapiPos(pdbg_target* i_trgt)
35{
36 uint32_t attr = 0;
37 pdbg_target_get_attribute(i_trgt, "ATTR_FAPI_POS", 4, 1, &attr);
38 return attr;
39}
40
41//------------------------------------------------------------------------------
42
Zane Shelley2f263182020-07-10 21:41:21 -050043const char* __attn(libhei::AttentionType_t i_attnType)
44{
45 const char* str = "";
46 switch (i_attnType)
47 {
48 case libhei::ATTN_TYPE_CHECKSTOP:
49 str = "CHECKSTOP";
50 break;
51 case libhei::ATTN_TYPE_UNIT_CS:
52 str = "UNIT_CS";
53 break;
54 case libhei::ATTN_TYPE_RECOVERABLE:
55 str = "RECOVERABLE";
56 break;
57 case libhei::ATTN_TYPE_SP_ATTN:
58 str = "SP_ATTN";
59 break;
60 case libhei::ATTN_TYPE_HOST_ATTN:
61 str = "HOST_ATTN";
62 break;
63 default:
64 trace::err("Unsupported attention type: %u", i_attnType);
65 assert(0);
66 }
67 return str;
68}
69
70uint32_t __trgt(const libhei::Signature& i_sig)
71{
72 auto trgt = (pdbg_target*)i_sig.getChip().getChip();
73
74 uint8_t type = __attrType(trgt);
75 uint32_t pos = __attrFapiPos(trgt);
76
77 // Technically, the FapiPos attribute is 32-bit, but not likely to ever go
78 // over 24-bit.
79
80 return type << 24 | (pos & 0xffffff);
81}
82
83uint32_t __sig(const libhei::Signature& i_sig)
84{
85 return i_sig.getId() << 16 | i_sig.getInstance() << 8 | i_sig.getBit();
86}
87
88//------------------------------------------------------------------------------
89
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060090// Returns the chip model/level of the given target.
91libhei::ChipType_t __getChipType(pdbg_target* i_trgt)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -050092{
93 libhei::ChipType_t type;
94
95 // START WORKAROUND
96 // TODO: Will need to grab the model/level from the target attributes when
97 // they are available. For now, use ATTR_TYPE to determine which
98 // currently supported value to use supported.
Zane Shelley2f263182020-07-10 21:41:21 -050099 uint8_t attrType = __attrType(i_trgt);
100 switch (attrType)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500101 {
102 case 0x05: // PROC
103 type = 0x120DA049;
104 break;
105
106 case 0x4b: // OCMB_CHIP
107 type = 0x160D2000;
108 break;
109
110 default:
Zane Shelley2f263182020-07-10 21:41:21 -0500111 trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType);
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500112 assert(0);
113 }
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500114 // END WORKAROUND
115
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500116 return type;
117}
118
119//------------------------------------------------------------------------------
120
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600121// Gathers list of active chips to analyze.
122void __getActiveChips(std::vector<libhei::Chip>& o_chips)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500123{
124 // Iterate each processor.
125 pdbg_target* procTrgt;
126 pdbg_for_each_class_target("proc", procTrgt)
127 {
128 // Active processors only.
129 if (PDBG_TARGET_ENABLED != pdbg_target_probe(procTrgt))
130 continue;
131
132 // Add the processor to the list.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600133 o_chips.emplace_back(procTrgt, __getChipType(procTrgt));
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500134
135 // Iterate the connected OCMBs, if they exist.
136 pdbg_target* ocmbTrgt;
Zane Shelley06e10f92020-08-10 20:35:08 -0500137 pdbg_for_each_target("ocmb", procTrgt, ocmbTrgt)
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500138 {
139 // Active OCMBs only.
140 if (PDBG_TARGET_ENABLED != pdbg_target_probe(ocmbTrgt))
141 continue;
142
143 // Add the OCMB to the list.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600144 o_chips.emplace_back(ocmbTrgt, __getChipType(ocmbTrgt));
Zane Shelleyd84ed6e2020-06-08 13:41:48 -0500145 }
146 }
Zane Shelley2e994bc2020-06-08 14:38:14 -0500147}
148
149//------------------------------------------------------------------------------
150
Zane Shelley097a71a2020-06-08 15:55:29 -0500151// Takes a signature list that will be filtered and sorted. The first entry in
152// the returned list will be the root cause. If the returned list is empty,
153// analysis failed.
154void __filterRootCause(std::vector<libhei::Signature>& io_list)
155{
Zane Shelley2f263182020-07-10 21:41:21 -0500156 // For debug, trace out the original list of signatures before filtering.
157 for (const auto& sig : io_list)
158 {
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600159 trace::inf("Signature: %s 0x%0" PRIx32 " %s",
160 util::pdbg::getPath(sig.getChip()), __sig(sig),
161 __attn(sig.getAttnType()));
Zane Shelley2f263182020-07-10 21:41:21 -0500162 }
163
Zane Shelley097a71a2020-06-08 15:55:29 -0500164 // Special and host attentions are not supported by this user application.
165 auto newEndItr =
166 std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) {
167 return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() ||
168 libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType());
169 });
170
171 // Shrink the vector, if needed.
172 io_list.resize(std::distance(io_list.begin(), newEndItr));
173
174 // START WORKAROUND
175 // TODO: Filtering should be determined by the RAS Data Files provided by
176 // the host firmware via the PNOR (similar to the Chip Data Files).
177 // Until that support is available, use a rudimentary filter that
178 // first looks for any recoverable attention, then any unit checkstop,
179 // and then any system checkstop. This is built on the premise that
180 // recoverable errors could be the root cause of an system checkstop
181 // attentions. Fortunately, we just need to sort the list by the
182 // greater attention type value.
183 std::sort(io_list.begin(), io_list.end(),
184 [&](const auto& a, const auto& b) {
185 return a.getAttnType() > b.getAttnType();
186 });
187 // END WORKAROUND
188}
189
190//------------------------------------------------------------------------------
191
Zane Shelley9fb73932020-09-15 13:34:57 -0500192bool __logError(const std::vector<libhei::Signature>& i_sigList,
193 const libhei::IsolationData& i_isoData)
194{
195 bool attnFound = false;
196
197 // Get numerical values for the root cause.
198 uint32_t word6 = 0; // [ 0: 7]: chip target type
199 // [ 8:31]: chip FAPI position
200 // uint32_t word7 = 0; // TODO: chip target info
201 uint32_t word8 = 0; // [ 0:15]: node ID
202 // [16:23]: node instance
203 // [24:31]: bit position
204 // uint32_t word9 = 0; // [ 0: 7]: attention type
205
206 if (i_sigList.empty())
207 {
208 trace::inf("No active attentions found");
209 }
210 else
211 {
212 attnFound = true;
213
214 // The root cause attention is the first in the filtered list.
215 libhei::Signature root = i_sigList.front();
216
217 word6 = __trgt(root);
218 word8 = __sig(root);
219
220 trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s",
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600221 util::pdbg::getPath(root.getChip()), word8,
222 __attn(root.getAttnType()));
Zane Shelley9fb73932020-09-15 13:34:57 -0500223 }
224
225 // Get the log data.
226 std::map<std::string, std::string> logData;
227 logData["_PID"] = std::to_string(getpid());
228 logData["CHIP_ID"] = std::to_string(word6);
229 logData["SIGNATURE"] = std::to_string(word8);
230
231 // Get access to logging interface and method for creating log.
232 auto bus = sdbusplus::bus::new_default_system();
233
234 // Using direct create method (for additional data)
235 auto method = bus.new_method_call(
236 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
237 "xyz.openbmc_project.Logging.Create", "Create");
238
239 // Attach additional data
240 method.append("org.open_power.HwDiags.Error.Checkstop",
241 "xyz.openbmc_project.Logging.Entry.Level.Error", logData);
242
243 // Log the event.
244 // TODO: Should the reply be handled?
245 bus.call(method);
246
247 return attnFound;
248}
249
250//------------------------------------------------------------------------------
251
252bool analyzeHardware()
Ben Tyner87eabc62020-05-14 17:56:54 -0500253{
Zane Shelley097a71a2020-06-08 15:55:29 -0500254 bool attnFound = false;
Ben Tyner87eabc62020-05-14 17:56:54 -0500255
Zane Shelley2f263182020-07-10 21:41:21 -0500256 trace::inf(">>> enter analyzeHardware()");
257
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600258 // Get the active chips to be analyzed.
259 std::vector<libhei::Chip> chips;
260 __getActiveChips(chips);
Ben Tyner87eabc62020-05-14 17:56:54 -0500261
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600262 // Initialize the isolator for all chips.
263 trace::inf("Initializing the isolator...");
264 initializeIsolator(chips);
Zane Shelley2e994bc2020-06-08 14:38:14 -0500265
Zane Shelley097a71a2020-06-08 15:55:29 -0500266 // Isolate attentions.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600267 trace::inf("Isolating errors: # of chips=%u", chips.size());
Zane Shelley097a71a2020-06-08 15:55:29 -0500268 libhei::IsolationData isoData{};
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600269 libhei::isolate(chips, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500270
Zane Shelley2f263182020-07-10 21:41:21 -0500271 // Filter signatures to determine root cause. We'll need to make a copy of
272 // the list so that the original list is maintained for the log.
Zane Shelley097a71a2020-06-08 15:55:29 -0500273 std::vector<libhei::Signature> sigList{isoData.getSignatureList()};
274 __filterRootCause(sigList);
275
Zane Shelley9fb73932020-09-15 13:34:57 -0500276 // Create and commit a log.
277 attnFound = __logError(sigList, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500278
Zane Shelley097a71a2020-06-08 15:55:29 -0500279 // All done, clean up the isolator.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600280 trace::inf("Uninitializing isolator...");
Zane Shelley097a71a2020-06-08 15:55:29 -0500281 libhei::uninitialize();
Ben Tyner87eabc62020-05-14 17:56:54 -0500282
Zane Shelley2f263182020-07-10 21:41:21 -0500283 trace::inf("<<< exit analyzeHardware()");
284
Zane Shelley097a71a2020-06-08 15:55:29 -0500285 return attnFound;
Ben Tyner0205f3b2020-02-24 10:24:47 -0600286}
287
288} // namespace analyzer