blob: 2c384c4945cf01eb1d0f4c2dcdc6044a2a95d165 [file] [log] [blame]
Zane Shelleyd3b9bac2020-11-17 21:59:12 -06001#include <unistd.h>
2
3#include <hei_main.hpp>
4#include <phosphor-logging/elog.hpp>
5#include <sdbusplus/bus.hpp>
Zane Shelleyb1106b52021-01-29 13:44:42 -06006#include <util/bin_stream.hpp>
Zane Shelleyd3b9bac2020-11-17 21:59:12 -06007#include <util/ffdc_file.hpp>
8#include <util/pdbg.hpp>
9#include <util/trace.hpp>
10#include <xyz/openbmc_project/Logging/Create/server.hpp>
11#include <xyz/openbmc_project/Logging/Entry/server.hpp>
12
Zane Shelley021dab32020-12-08 20:28:40 -060013#include <fstream>
14#include <memory>
15
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060016namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server;
17
18namespace analyzer
19{
20
Zane Shelley021dab32020-12-08 20:28:40 -060021//------------------------------------------------------------------------------
22
23enum FfdcSubType_t : uint8_t
24{
25 FFDC_SIGNATURES = 0x01,
26 FFDC_CAPTURE_DATA = 0x02,
27
28 // For the callout section, the value of '0xCA' is required per the
29 // phosphor-logging openpower-pel extention spec.
30 FFDC_CALLOUTS = 0xCA,
31};
32
33enum FfdcVersion_t : uint8_t
34{
35 FFDC_VERSION1 = 0x01,
36};
37
38//------------------------------------------------------------------------------
39
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060040bool __isCheckstop(const libhei::IsolationData& i_isoData)
41{
42 // Look for any signature with a system checkstop attention.
43 auto list = i_isoData.getSignatureList();
44 auto itr = std::find_if(list.begin(), list.end(), [](const auto& s) {
45 return libhei::ATTN_TYPE_CHECKSTOP == s.getAttnType();
46 });
47
48 return list.end() != itr;
49}
50
51//------------------------------------------------------------------------------
52
Zane Shelley021dab32020-12-08 20:28:40 -060053void __getSrc(const libhei::Signature& i_signature, uint32_t& o_word6,
54 uint32_t& o_word7, uint32_t& o_word8)
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060055{
56 // [ 0:15] chip model
57 // [16:23] reserved space in chip ID
58 // [24:31] chip EC level
Zane Shelley021dab32020-12-08 20:28:40 -060059 o_word6 = i_signature.getChip().getType();
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060060
61 // [ 0:15] chip position
62 // [16:23] unused
63 // [24:31] signature attention type
Zane Shelley021dab32020-12-08 20:28:40 -060064 auto pos = util::pdbg::getChipPos(i_signature.getChip());
65 auto attn = i_signature.getAttnType();
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060066
Zane Shelley021dab32020-12-08 20:28:40 -060067 o_word7 = (pos & 0xffff) << 16 | (attn & 0xff);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060068
69 // [ 0:15] signature ID
70 // [16:23] signature instance
71 // [24:31] signature bit position
Zane Shelley021dab32020-12-08 20:28:40 -060072 o_word8 = i_signature.toUint32();
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060073
74 // Word 9 is currently unused
Zane Shelley021dab32020-12-08 20:28:40 -060075}
76
77//------------------------------------------------------------------------------
78
79void __setSrc(const libhei::Signature& i_rootCause,
80 std::map<std::string, std::string>& io_logData)
81{
82 uint32_t word6 = 0, word7 = 0, word8 = 0;
83 __getSrc(i_rootCause, word6, word7, word8);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060084
85 io_logData["SRC6"] = std::to_string(word6);
86 io_logData["SRC7"] = std::to_string(word7);
87 io_logData["SRC8"] = std::to_string(word8);
88}
89
90//------------------------------------------------------------------------------
91
92void __captureSignatureList(const libhei::IsolationData& i_isoData,
93 std::vector<util::FFDCFile>& io_userDataFiles)
94{
Zane Shelley021dab32020-12-08 20:28:40 -060095 // Create a new entry for this user data section regardless if there are any
96 // signatures in the list.
97 io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_SIGNATURES,
98 FFDC_VERSION1);
99
Zane Shelleyb1106b52021-01-29 13:44:42 -0600100 // Create a streamer for easy writing to the FFDC file.
101 auto path = io_userDataFiles.back().getPath();
102 util::BinFileWriter stream{path};
103
104 // The first 4 bytes in the FFDC contains the number of signatures in the
105 // list. Then, the list of signatures will follow.
106
Zane Shelley021dab32020-12-08 20:28:40 -0600107 auto list = i_isoData.getSignatureList();
108
Zane Shelleyb1106b52021-01-29 13:44:42 -0600109 uint32_t numSigs = list.size();
110 stream << numSigs;
Zane Shelley021dab32020-12-08 20:28:40 -0600111
Zane Shelley021dab32020-12-08 20:28:40 -0600112 for (const auto& sig : list)
113 {
Zane Shelleyb1106b52021-01-29 13:44:42 -0600114 // Each signature will use the same format as the SRC (12 bytes each).
115 uint32_t word6 = 0, word7 = 0, word8 = 0;
Zane Shelley021dab32020-12-08 20:28:40 -0600116 __getSrc(sig, word6, word7, word8);
Zane Shelleyb1106b52021-01-29 13:44:42 -0600117 stream << word6 << word7 << word8;
Zane Shelley021dab32020-12-08 20:28:40 -0600118 }
119
Zane Shelleyb1106b52021-01-29 13:44:42 -0600120 // If the stream failed for any reason, remove the FFDC file.
121 if (!stream.good())
Zane Shelley021dab32020-12-08 20:28:40 -0600122 {
Zane Shelleyb1106b52021-01-29 13:44:42 -0600123 trace::err("Unable to write signature list FFDC file: %s",
124 path.string().c_str());
125 io_userDataFiles.pop_back();
Zane Shelley021dab32020-12-08 20:28:40 -0600126 }
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600127}
128
129//------------------------------------------------------------------------------
130
131std::string __getMessageRegistry(bool i_isCheckstop)
132{
133 // For now, there are only two choices:
134 return i_isCheckstop ? "org.open_power.HwDiags.Error.Checkstop"
135 : "org.open_power.HwDiags.Error.Predictive";
136}
137
138//------------------------------------------------------------------------------
139
140std::string __getMessageSeverity(bool i_isCheckstop)
141{
142 // We could specify the PEL severity in the message registry entry. However,
143 // that would require multiple copies of each entry for each possible
144 // severity. As a workaround, we will not explicitly state the PEL severity
145 // in the message registry. Instead, the message severity will be converted
146 // into a PEL severity via the openpower-pels extention of phosphor-logging.
147
148 // Initially, we'll use a severity that will generate a predictive PEL. This
149 // is intended for Terminate Immediate (TI) errors and will require service.
150 LogSvr::Entry::Level severity = LogSvr::Entry::Level::Warning;
151
152 // If the reason for analysis was due to a system checsktop, the severity
153 // will be upgraded to a unrecoverable PEL.
154 if (i_isCheckstop)
155 severity = LogSvr::Entry::Level::Error;
156
157 // Convert the message severity to a string.
158 return LogSvr::Entry::convertLevelToString(severity);
159}
160
161//------------------------------------------------------------------------------
162
163void createPel(const libhei::Signature& i_rootCause,
164 const libhei::IsolationData& i_isoData)
165{
166 // The message registry will require additional log data to fill in keywords
167 // and additional log data.
168 std::map<std::string, std::string> logData;
169
170 // Keep track of the temporary files associated with the user data FFDC.
171 // WARNING: Once the objects stored in this vector go out of scope, the
172 // temporary files will be deleted. So they must remain in scope
173 // until the PEL is submitted.
174 std::vector<util::FFDCFile> userDataFiles;
175
176 // In several cases, it is important to know if the reason for analysis was
177 // due to a system checsktop.
178 bool isCheckstop = __isCheckstop(i_isoData);
179
180 // Set words 6-9 of the SRC.
181 __setSrc(i_rootCause, logData);
182
183 // Capture the complete signature list.
184 __captureSignatureList(i_isoData, userDataFiles);
185
186 // Now, that all of the user data files have been created, transform the
187 // data into the proper format for the PEL.
188 std::vector<util::FFDCTuple> userData;
189 util::transformFFDC(userDataFiles, userData);
190
191 // Get access to logging interface and method for creating log.
192 auto bus = sdbusplus::bus::new_default_system();
193
194 // Using direct create method (for additional data).
195 auto method = bus.new_method_call(
196 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
197 "xyz.openbmc_project.Logging.Create", "CreateWithFFDCFiles");
198
199 // The "Create" method requires manually adding the process ID.
200 logData["_PID"] = std::to_string(getpid());
201
202 // Get the message registry entry for this failure.
203 auto message = __getMessageRegistry(isCheckstop);
204
205 // Get the message severity for this failure.
206 auto severity = __getMessageSeverity(isCheckstop);
207
208 // Add the message, with additional log and user data.
209 method.append(message, severity, logData, userData);
210
211 // Log the event.
212 bus.call_noreply(method);
213}
214
215} // namespace analyzer