blob: 0988e4dd9bcb1fd4d950da7a99547148edf55a5a [file] [log] [blame]
Zane Shelleyd3b9bac2020-11-17 21:59:12 -06001#include <unistd.h>
2
Zane Shelley4ed4be52021-02-15 17:53:40 -06003#include <analyzer/service_data.hpp>
Zane Shelley8f60a622021-02-01 14:41:30 -06004#include <analyzer/util.hpp>
Zane Shelleyd3b9bac2020-11-17 21:59:12 -06005#include <hei_main.hpp>
6#include <phosphor-logging/elog.hpp>
7#include <sdbusplus/bus.hpp>
Zane Shelleyb1106b52021-01-29 13:44:42 -06008#include <util/bin_stream.hpp>
Ben Tyner7029e522021-08-09 19:18:24 -05009#include <util/dbus.hpp>
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060010#include <util/ffdc_file.hpp>
11#include <util/pdbg.hpp>
12#include <util/trace.hpp>
13#include <xyz/openbmc_project/Logging/Create/server.hpp>
14#include <xyz/openbmc_project/Logging/Entry/server.hpp>
15
Zane Shelley021dab32020-12-08 20:28:40 -060016#include <fstream>
17#include <memory>
18
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060019namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server;
20
21namespace analyzer
22{
23
Zane Shelley021dab32020-12-08 20:28:40 -060024//------------------------------------------------------------------------------
25
26enum FfdcSubType_t : uint8_t
27{
Zane Shelleyc18ba8f2021-12-01 16:29:20 -060028 FFDC_SIGNATURES = 0x01,
29 FFDC_REGISTER_DUMP = 0x02,
30 FFDC_CALLOUT_FFDC = 0x03,
31 FFDC_HB_SCRATCH_REGS = 0x04,
Zane Shelley021dab32020-12-08 20:28:40 -060032
33 // For the callout section, the value of '0xCA' is required per the
34 // phosphor-logging openpower-pel extention spec.
35 FFDC_CALLOUTS = 0xCA,
36};
37
38enum FfdcVersion_t : uint8_t
39{
40 FFDC_VERSION1 = 0x01,
41};
42
43//------------------------------------------------------------------------------
44
Zane Shelley021dab32020-12-08 20:28:40 -060045void __getSrc(const libhei::Signature& i_signature, uint32_t& o_word6,
46 uint32_t& o_word7, uint32_t& o_word8)
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060047{
Zane Shelleya08d1c32022-03-01 17:51:09 -060048 o_word6 = o_word7 = o_word8 = 0; // default
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060049
Zane Shelleya08d1c32022-03-01 17:51:09 -060050 // Note that the chip could be null if there was no root cause attention
51 // found during analysis.
52 if (nullptr != i_signature.getChip().getChip())
53 {
54 // [ 0:15] chip model
55 // [16:23] reserved space in chip ID
56 // [24:31] chip EC level
57 o_word6 = i_signature.getChip().getType();
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060058
Zane Shelleya08d1c32022-03-01 17:51:09 -060059 // [ 0:15] chip position
60 // [16:23] node position
61 // [24:31] signature attention type
62 auto chipPos = util::pdbg::getChipPos(i_signature.getChip());
63 uint8_t nodePos = 0; // TODO: multi-node support
64 auto attn = i_signature.getAttnType();
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060065
Zane Shelleya08d1c32022-03-01 17:51:09 -060066 o_word7 =
67 (chipPos & 0xffff) << 16 | (nodePos & 0xff) << 8 | (attn & 0xff);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060068
Zane Shelleya08d1c32022-03-01 17:51:09 -060069 // [ 0:15] signature ID
70 // [16:23] signature instance
71 // [24:31] signature bit position
72 o_word8 = i_signature.toUint32();
73
74 // Word 9 is currently unused
75 }
Zane Shelley021dab32020-12-08 20:28:40 -060076}
77
78//------------------------------------------------------------------------------
79
80void __setSrc(const libhei::Signature& i_rootCause,
81 std::map<std::string, std::string>& io_logData)
82{
83 uint32_t word6 = 0, word7 = 0, word8 = 0;
84 __getSrc(i_rootCause, word6, word7, word8);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -060085
86 io_logData["SRC6"] = std::to_string(word6);
87 io_logData["SRC7"] = std::to_string(word7);
88 io_logData["SRC8"] = std::to_string(word8);
89}
90
91//------------------------------------------------------------------------------
92
Zane Shelley4ed4be52021-02-15 17:53:40 -060093void __addCalloutList(const ServiceData& i_servData,
94 std::vector<util::FFDCFile>& io_userDataFiles)
95{
Zane Shelley4ed4be52021-02-15 17:53:40 -060096 // Create a new entry for the user data section containing the callout list.
97 io_userDataFiles.emplace_back(util::FFDCFormat::JSON, FFDC_CALLOUTS,
98 FFDC_VERSION1);
99
100 // Use a file stream to write the JSON to file.
101 std::ofstream o{io_userDataFiles.back().getPath()};
Zane Shelleyc85716c2021-08-17 10:54:06 -0500102 o << i_servData.getCalloutList();
Zane Shelley4ed4be52021-02-15 17:53:40 -0600103}
104
105//------------------------------------------------------------------------------
106
Zane Shelley2d114322021-08-25 17:06:12 -0500107void __addCalloutFFDC(const ServiceData& i_servData,
108 std::vector<util::FFDCFile>& io_userDataFiles)
109{
110 // Create a new entry for the user data section containing the FFDC.
111 io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_CALLOUT_FFDC,
112 FFDC_VERSION1);
113
114 // Use a file stream to write the JSON to file.
115 std::ofstream o{io_userDataFiles.back().getPath()};
116 o << i_servData.getCalloutFFDC();
117}
118
119//------------------------------------------------------------------------------
120
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600121void __captureSignatureList(const libhei::IsolationData& i_isoData,
122 std::vector<util::FFDCFile>& io_userDataFiles)
123{
Zane Shelley021dab32020-12-08 20:28:40 -0600124 // Create a new entry for this user data section regardless if there are any
125 // signatures in the list.
126 io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_SIGNATURES,
127 FFDC_VERSION1);
128
Zane Shelleyb1106b52021-01-29 13:44:42 -0600129 // Create a streamer for easy writing to the FFDC file.
130 auto path = io_userDataFiles.back().getPath();
131 util::BinFileWriter stream{path};
132
133 // The first 4 bytes in the FFDC contains the number of signatures in the
134 // list. Then, the list of signatures will follow.
135
Zane Shelley021dab32020-12-08 20:28:40 -0600136 auto list = i_isoData.getSignatureList();
137
Zane Shelleyb1106b52021-01-29 13:44:42 -0600138 uint32_t numSigs = list.size();
139 stream << numSigs;
Zane Shelley021dab32020-12-08 20:28:40 -0600140
Zane Shelley021dab32020-12-08 20:28:40 -0600141 for (const auto& sig : list)
142 {
Zane Shelleyb1106b52021-01-29 13:44:42 -0600143 // Each signature will use the same format as the SRC (12 bytes each).
144 uint32_t word6 = 0, word7 = 0, word8 = 0;
Zane Shelley021dab32020-12-08 20:28:40 -0600145 __getSrc(sig, word6, word7, word8);
Zane Shelleyb1106b52021-01-29 13:44:42 -0600146 stream << word6 << word7 << word8;
Zane Shelley021dab32020-12-08 20:28:40 -0600147 }
148
Zane Shelleyb1106b52021-01-29 13:44:42 -0600149 // If the stream failed for any reason, remove the FFDC file.
150 if (!stream.good())
Zane Shelley021dab32020-12-08 20:28:40 -0600151 {
Zane Shelleyb1106b52021-01-29 13:44:42 -0600152 trace::err("Unable to write signature list FFDC file: %s",
153 path.string().c_str());
154 io_userDataFiles.pop_back();
Zane Shelley021dab32020-12-08 20:28:40 -0600155 }
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600156}
157
158//------------------------------------------------------------------------------
159
Zane Shelley8f60a622021-02-01 14:41:30 -0600160void __captureRegisterDump(const libhei::IsolationData& i_isoData,
161 std::vector<util::FFDCFile>& io_userDataFiles)
162{
163 // Create a new entry for this user data section regardless if there are any
164 // registers in the dump.
165 io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_REGISTER_DUMP,
166 FFDC_VERSION1);
167
168 // Create a streamer for easy writing to the FFDC file.
169 auto path = io_userDataFiles.back().getPath();
170 util::BinFileWriter stream{path};
171
172 // The first 4 bytes in the FFDC contains the number of chips with register
173 // data. Then the data for each chip will follow.
174
175 auto dump = i_isoData.getRegisterDump();
176
177 uint32_t numChips = dump.size();
178 stream << numChips;
179
180 for (const auto& entry : dump)
181 {
182 auto chip = entry.first;
183 auto regList = entry.second;
184
185 // Each chip will have the following information:
186 // 4 byte chip model/EC
187 // 2 byte chip position
Zane Shelleyff068a12021-06-17 17:45:40 -0500188 // 1 byte node position
Zane Shelley8f60a622021-02-01 14:41:30 -0600189 // 4 byte number of registers
190 // Then the data for each register will follow.
191
192 uint32_t chipType = chip.getType();
193 uint16_t chipPos = util::pdbg::getChipPos(chip);
Zane Shelleyff068a12021-06-17 17:45:40 -0500194 uint8_t nodePos = 0; // TODO: multi-node support
Zane Shelley8f60a622021-02-01 14:41:30 -0600195 uint32_t numRegs = regList.size();
Zane Shelleyff068a12021-06-17 17:45:40 -0500196 stream << chipType << chipPos << nodePos << numRegs;
Zane Shelley8f60a622021-02-01 14:41:30 -0600197
198 for (const auto& reg : regList)
199 {
200 // Each register will have the following information:
201 // 3 byte register ID
202 // 1 byte register instance
203 // 1 byte data size
204 // * byte data buffer (* depends on value of data size)
205
206 libhei::RegisterId_t regId = reg.regId; // 3 byte
207 libhei::Instance_t regInst = reg.regInst; // 1 byte
208
209 auto tmp = libhei::BitString::getMinBytes(reg.data->getBitLen());
210 if (255 < tmp)
211 {
212 trace::inf("Register data execeeded 255 and was truncated: "
213 "regId=0x%06x regInst=%u",
214 regId, regInst);
215 tmp = 255;
216 }
217 uint8_t dataSize = tmp;
218
219 stream << regId << regInst << dataSize;
220
221 stream.write(reg.data->getBufAddr(), dataSize);
222 }
223 }
224
225 // If the stream failed for any reason, remove the FFDC file.
226 if (!stream.good())
227 {
228 trace::err("Unable to write register dump FFDC file: %s",
229 path.string().c_str());
230 io_userDataFiles.pop_back();
231 }
232}
233
234//------------------------------------------------------------------------------
235
Zane Shelleyc18ba8f2021-12-01 16:29:20 -0600236void __captureHostbootScratchRegisters(
237 std::vector<util::FFDCFile>& io_userDataFiles)
238{
239 // Get the Hostboot scratch registers from the primary processor.
240
241 uint32_t cfamAddr = 0x283C;
242 uint32_t cfamValue = 0;
243
244 uint64_t scomAddr = 0x4602F489;
245 uint64_t scomValue = 0;
246
247 auto priProc = util::pdbg::getPrimaryProcessor();
248 if (nullptr == priProc)
249 {
250 trace::err("Unable to get primary processor");
251 }
252 else
253 {
254 if (0 != util::pdbg::getCfam(priProc, cfamAddr, cfamValue))
255 {
256 cfamValue = 0; // just in case
257 }
258
259 if (0 != util::pdbg::getScom(priProc, scomAddr, scomValue))
260 {
261 scomValue = 0; // just in case
262 }
263 }
264
265 // Create a new entry for this user data section.
266 io_userDataFiles.emplace_back(util::FFDCFormat::Custom,
267 FFDC_HB_SCRATCH_REGS, FFDC_VERSION1);
268
269 // Create a streamer for easy writing to the FFDC file.
270 auto path = io_userDataFiles.back().getPath();
271 util::BinFileWriter stream{path};
272
273 // Add the data (CFAM addr/val, then SCOM addr/val).
274 stream << cfamAddr << cfamValue << scomAddr << scomValue;
275
276 // If the stream failed for any reason, remove the FFDC file.
277 if (!stream.good())
278 {
279 trace::err("Unable to write register dump FFDC file: %s",
280 path.string().c_str());
281 io_userDataFiles.pop_back();
282 }
283}
284
285//------------------------------------------------------------------------------
286
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600287std::string __getMessageRegistry(AnalysisType i_type)
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600288{
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600289 if (AnalysisType::SYSTEM_CHECKSTOP == i_type)
290 {
291 return "org.open_power.HwDiags.Error.Checkstop";
292 }
293 else if (AnalysisType::TERMINATE_IMMEDIATE == i_type)
294 {
295 return "org.open_power.HwDiags.Error.Predictive";
296 }
297
298 return "org.open_power.HwDiags.Error.Informational"; // default
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600299}
300
301//------------------------------------------------------------------------------
302
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600303std::string __getMessageSeverity(AnalysisType i_type)
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600304{
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600305 // Default severity is informational (no service action required).
306 LogSvr::Entry::Level severity = LogSvr::Entry::Level::Informational;
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600307
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600308 if (AnalysisType::SYSTEM_CHECKSTOP == i_type)
309 {
310 // System checkstops are always unrecoverable errors (service action
311 // required).
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600312 severity = LogSvr::Entry::Level::Error;
Zane Shelleyf17bf3e2021-12-07 13:16:37 -0600313 }
314 else if (AnalysisType::TERMINATE_IMMEDIATE == i_type)
315 {
316 // TIs will be reported as a predicive error (service action required).
317 severity = LogSvr::Entry::Level::Warning;
318 }
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600319
320 // Convert the message severity to a string.
321 return LogSvr::Entry::convertLevelToString(severity);
322}
323
324//------------------------------------------------------------------------------
325
Ben Tynerc1e1c002022-02-16 15:09:31 -0600326uint32_t commitPel(const ServiceData& i_servData)
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600327{
Zane Shelley611b3442021-11-19 16:02:01 -0600328 uint32_t o_plid = 0; // default, zero indicates PEL was not created
329
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600330 // The message registry will require additional log data to fill in keywords
331 // and additional log data.
332 std::map<std::string, std::string> logData;
333
334 // Keep track of the temporary files associated with the user data FFDC.
335 // WARNING: Once the objects stored in this vector go out of scope, the
336 // temporary files will be deleted. So they must remain in scope
337 // until the PEL is submitted.
338 std::vector<util::FFDCFile> userDataFiles;
339
Zane Shelley55e7fec2022-01-28 15:29:44 -0600340 // Set the subsystem in the primary SRC.
341 i_servData.addSrcSubsystem(logData);
342
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600343 // Set words 6-9 of the SRC.
Zane Shelley8af9e462021-03-11 10:44:28 -0600344 __setSrc(i_servData.getRootCause(), logData);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600345
Zane Shelley4ed4be52021-02-15 17:53:40 -0600346 // Add the list of callouts to the PEL.
347 __addCalloutList(i_servData, userDataFiles);
348
Zane Shelleyc18ba8f2021-12-01 16:29:20 -0600349 // Add the Hostboot scratch register to the PEL.
350 __captureHostbootScratchRegisters(userDataFiles);
351
Zane Shelley2d114322021-08-25 17:06:12 -0500352 // Add the callout FFDC to the PEL.
353 __addCalloutFFDC(i_servData, userDataFiles);
354
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600355 // Capture the complete signature list.
Zane Shelley62adf5c2022-01-18 21:06:50 -0600356 __captureSignatureList(i_servData.getIsolationData(), userDataFiles);
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600357
Zane Shelley8f60a622021-02-01 14:41:30 -0600358 // Capture the complete signature list.
Zane Shelley62adf5c2022-01-18 21:06:50 -0600359 __captureRegisterDump(i_servData.getIsolationData(), userDataFiles);
Zane Shelley8f60a622021-02-01 14:41:30 -0600360
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600361 // Now, that all of the user data files have been created, transform the
362 // data into the proper format for the PEL.
363 std::vector<util::FFDCTuple> userData;
364 util::transformFFDC(userDataFiles, userData);
365
Ben Tynerc1e1c002022-02-16 15:09:31 -0600366 // Get the message registry entry for this failure.
367 auto message = __getMessageRegistry(i_servData.getAnalysisType());
368
369 // Get the message severity for this failure.
370 auto severity = __getMessageSeverity(i_servData.getAnalysisType());
371
372 // Create the PEL
373 o_plid = util::dbus::createPel(message, severity, logData, userData);
374
375 if (0 == o_plid)
Ben Tyner7029e522021-08-09 19:18:24 -0500376 {
Ben Tynerc1e1c002022-02-16 15:09:31 -0600377 trace::err("Error while creating event log entry");
Ben Tyner7029e522021-08-09 19:18:24 -0500378 }
379
Zane Shelley611b3442021-11-19 16:02:01 -0600380 // Return the platorm log ID of the error.
381 return o_plid;
Zane Shelleyd3b9bac2020-11-17 21:59:12 -0600382}
383
384} // namespace analyzer