blob: 30efd74f84d9f55b8e2f9069ded3a02d3cb6c263 [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 Shelley171a2e02020-11-13 13:56:13 -060023void initializeIsolator(std::vector<libhei::Chip>& o_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 Shelley097a71a2020-06-08 15:55:29 -050072// Takes a signature list that will be filtered and sorted. The first entry in
73// the returned list will be the root cause. If the returned list is empty,
74// analysis failed.
75void __filterRootCause(std::vector<libhei::Signature>& io_list)
76{
Zane Shelley2f263182020-07-10 21:41:21 -050077 // For debug, trace out the original list of signatures before filtering.
78 for (const auto& sig : io_list)
79 {
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060080 trace::inf("Signature: %s 0x%0" PRIx32 " %s",
81 util::pdbg::getPath(sig.getChip()), __sig(sig),
82 __attn(sig.getAttnType()));
Zane Shelley2f263182020-07-10 21:41:21 -050083 }
84
Zane Shelley097a71a2020-06-08 15:55:29 -050085 // Special and host attentions are not supported by this user application.
86 auto newEndItr =
87 std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) {
88 return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() ||
89 libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType());
90 });
91
92 // Shrink the vector, if needed.
93 io_list.resize(std::distance(io_list.begin(), newEndItr));
94
95 // START WORKAROUND
96 // TODO: Filtering should be determined by the RAS Data Files provided by
97 // the host firmware via the PNOR (similar to the Chip Data Files).
98 // Until that support is available, use a rudimentary filter that
99 // first looks for any recoverable attention, then any unit checkstop,
100 // and then any system checkstop. This is built on the premise that
101 // recoverable errors could be the root cause of an system checkstop
102 // attentions. Fortunately, we just need to sort the list by the
103 // greater attention type value.
104 std::sort(io_list.begin(), io_list.end(),
105 [&](const auto& a, const auto& b) {
106 return a.getAttnType() > b.getAttnType();
107 });
108 // END WORKAROUND
109}
110
111//------------------------------------------------------------------------------
112
Zane Shelley9fb73932020-09-15 13:34:57 -0500113bool __logError(const std::vector<libhei::Signature>& i_sigList,
114 const libhei::IsolationData& i_isoData)
115{
116 bool attnFound = false;
117
118 // Get numerical values for the root cause.
119 uint32_t word6 = 0; // [ 0: 7]: chip target type
120 // [ 8:31]: chip FAPI position
121 // uint32_t word7 = 0; // TODO: chip target info
122 uint32_t word8 = 0; // [ 0:15]: node ID
123 // [16:23]: node instance
124 // [24:31]: bit position
125 // uint32_t word9 = 0; // [ 0: 7]: attention type
126
127 if (i_sigList.empty())
128 {
129 trace::inf("No active attentions found");
130 }
131 else
132 {
133 attnFound = true;
134
135 // The root cause attention is the first in the filtered list.
136 libhei::Signature root = i_sigList.front();
137
138 word6 = __trgt(root);
139 word8 = __sig(root);
140
141 trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s",
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600142 util::pdbg::getPath(root.getChip()), word8,
143 __attn(root.getAttnType()));
Zane Shelley9fb73932020-09-15 13:34:57 -0500144 }
145
146 // Get the log data.
147 std::map<std::string, std::string> logData;
148 logData["_PID"] = std::to_string(getpid());
149 logData["CHIP_ID"] = std::to_string(word6);
150 logData["SIGNATURE"] = std::to_string(word8);
151
152 // Get access to logging interface and method for creating log.
153 auto bus = sdbusplus::bus::new_default_system();
154
155 // Using direct create method (for additional data)
156 auto method = bus.new_method_call(
157 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
158 "xyz.openbmc_project.Logging.Create", "Create");
159
160 // Attach additional data
161 method.append("org.open_power.HwDiags.Error.Checkstop",
162 "xyz.openbmc_project.Logging.Entry.Level.Error", logData);
163
164 // Log the event.
165 // TODO: Should the reply be handled?
166 bus.call(method);
167
168 return attnFound;
169}
170
171//------------------------------------------------------------------------------
172
173bool analyzeHardware()
Ben Tyner87eabc62020-05-14 17:56:54 -0500174{
Zane Shelley097a71a2020-06-08 15:55:29 -0500175 bool attnFound = false;
Ben Tyner87eabc62020-05-14 17:56:54 -0500176
Zane Shelley2f263182020-07-10 21:41:21 -0500177 trace::inf(">>> enter analyzeHardware()");
178
Zane Shelley171a2e02020-11-13 13:56:13 -0600179 // Initialize the isolator and get all of the chips to be analyzed.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600180 trace::inf("Initializing the isolator...");
Zane Shelley171a2e02020-11-13 13:56:13 -0600181 std::vector<libhei::Chip> chips;
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600182 initializeIsolator(chips);
Zane Shelley2e994bc2020-06-08 14:38:14 -0500183
Zane Shelley097a71a2020-06-08 15:55:29 -0500184 // Isolate attentions.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600185 trace::inf("Isolating errors: # of chips=%u", chips.size());
Zane Shelley097a71a2020-06-08 15:55:29 -0500186 libhei::IsolationData isoData{};
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600187 libhei::isolate(chips, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500188
Zane Shelley2f263182020-07-10 21:41:21 -0500189 // Filter signatures to determine root cause. We'll need to make a copy of
190 // the list so that the original list is maintained for the log.
Zane Shelley097a71a2020-06-08 15:55:29 -0500191 std::vector<libhei::Signature> sigList{isoData.getSignatureList()};
192 __filterRootCause(sigList);
193
Zane Shelley9fb73932020-09-15 13:34:57 -0500194 // Create and commit a log.
195 attnFound = __logError(sigList, isoData);
Ben Tyner87eabc62020-05-14 17:56:54 -0500196
Zane Shelley097a71a2020-06-08 15:55:29 -0500197 // All done, clean up the isolator.
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600198 trace::inf("Uninitializing isolator...");
Zane Shelley097a71a2020-06-08 15:55:29 -0500199 libhei::uninitialize();
Ben Tyner87eabc62020-05-14 17:56:54 -0500200
Zane Shelley2f263182020-07-10 21:41:21 -0500201 trace::inf("<<< exit analyzeHardware()");
202
Zane Shelley097a71a2020-06-08 15:55:29 -0500203 return attnFound;
Ben Tyner0205f3b2020-02-24 10:24:47 -0600204}
205
206} // namespace analyzer