blob: 7f621df9aaa0400ca09888af1adc81262e124e79 [file] [log] [blame]
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05001#include <unistd.h>
2
Ben Tyner135793a2021-10-27 09:18:41 -05003#include <analyzer/analyzer_main.hpp>
Ben Tyner5c5db652021-02-22 18:22:35 -06004#include <attn/attn_common.hpp>
Ben Tyner188f1092021-02-01 09:33:06 -06005#include <attn/attn_dbus.hpp>
Ben Tyner7029e522021-08-09 19:18:24 -05006#include <attn/attn_dump.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05007#include <attn/attn_logging.hpp>
Ben Tynerf5210bb2021-01-05 12:58:10 -06008#include <attn/pel/pel_minimal.hpp>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05009#include <phosphor-logging/log.hpp>
Ben Tyner13159682022-02-16 14:55:38 -060010#include <util/dbus.hpp>
Ben Tynerfaf33362022-02-16 14:04:51 -060011#include <util/ffdc.hpp>
austinfcuibfa831a2022-01-26 15:37:07 -060012#include <util/trace.hpp>
Ben Tynerf5210bb2021-01-05 12:58:10 -060013
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050014namespace attn
15{
16
Ben Tynerf5210bb2021-01-05 12:58:10 -060017/** @brief Tuple containing information about ffdc files */
18using FFDCTuple =
19 std::tuple<util::FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>;
20
Ben Tynerf5210bb2021-01-05 12:58:10 -060021/**
22 * Create FFDCTuple objects corresponding to the specified FFDC files.
23 *
24 * The D-Bus method to create an error log requires a vector of tuples to
25 * pass in the FFDC file information.
26 *
27 * @param files - FFDC files
28 * @return vector of FFDCTuple objects
29 */
30std::vector<FFDCTuple>
31 createFFDCTuples(const std::vector<util::FFDCFile>& files)
32{
33 std::vector<FFDCTuple> ffdcTuples{};
Zane Shelleya79f6c82021-01-12 16:38:49 -060034 util::transformFFDC(files, ffdcTuples);
Ben Tynerf5210bb2021-01-05 12:58:10 -060035
36 return ffdcTuples;
37}
38
39/**
40 * @brief Create an FFDCFile object containing raw data
41 *
42 * Throws an exception if an error occurs.
43 *
44 * @param i_buffer - raw data to add to ffdc faw data file
45 * @param i_size - size of the raw data
46 * @return FFDCFile object
47 */
48util::FFDCFile createFFDCRawFile(void* i_buffer, size_t i_size)
49{
50 util::FFDCFile file{util::FFDCFormat::Custom};
51
52 // Write buffer to file and then reset file description file offset
Ben Tynerd7006092021-02-05 14:55:52 -060053 int fd = file.getFileDescriptor();
54 size_t numBytes = write(fd, static_cast<char*>(i_buffer), i_size);
55 if (i_size != numBytes)
56 {
austinfcuibfa831a2022-01-26 15:37:07 -060057 trace::err("%s only %u of %u bytes written", file.getPath().c_str(),
58 numBytes, i_size);
Ben Tynerd7006092021-02-05 14:55:52 -060059 }
60
Ben Tynerf5210bb2021-01-05 12:58:10 -060061 lseek(fd, 0, SEEK_SET);
62
63 return file;
64}
65
66/**
Ben Tynerf5210bb2021-01-05 12:58:10 -060067 * Create FFDCFile objects containing debug data to store in the error log.
68 *
69 * If an error occurs, the error is written to the journal but an exception
70 * is not thrown.
71 *
72 * @param i_buffer - raw data (if creating raw dump ffdc entry in log)
73 * @return vector of FFDCFile objects
74 */
75std::vector<util::FFDCFile> createFFDCFiles(char* i_buffer = nullptr,
76 size_t i_size = 0)
77{
78 std::vector<util::FFDCFile> files{};
79
80 // Create raw dump file
81 if ((nullptr != i_buffer) && (0 != i_size))
82 {
83 files.emplace_back(createFFDCRawFile(i_buffer, i_size));
84 }
85
86 // Create trace dump file
Ben Tynerfaf33362022-02-16 14:04:51 -060087 util::createFFDCTraceFiles(files);
Ben Tynerf5210bb2021-01-05 12:58:10 -060088
Ben Tyner21cc6272022-10-05 18:26:36 -050089 // Add PRD scratch registers
90 addPrdScratchRegs(files);
91
Ben Tynerf5210bb2021-01-05 12:58:10 -060092 return files;
93}
94
95/**
Ben Tynerf5210bb2021-01-05 12:58:10 -060096 * Create a PEL from an existing PEL
97 *
98 * Create a new PEL based on the specified raw PEL and submit the new PEL
99 * to the backend logging code as a raw PEL. Note that additional data map
100 * here contains data to be committed to the PEL and it can also be used to
101 * create the PEL as it contains needed information.
102 *
Ben Tyner135793a2021-10-27 09:18:41 -0500103 * @param i_rawPel - buffer containing a raw PEL
Ben Tynerf5210bb2021-01-05 12:58:10 -0600104 * @param i_additional - additional data to be added to the new PEL
105 */
106void createPelCustom(std::vector<uint8_t>& i_rawPel,
107 std::map<std::string, std::string> i_additional)
108{
109 // create PEL object from buffer
110 auto tiPel = std::make_unique<pel::PelMinimal>(i_rawPel);
111
112 // The additional data contains the TI info as well as the value for the
113 // subystem that provided the TI info. Get the subystem from additional
austinfcuic49d20b2022-02-22 16:36:47 -0600114 // data and then populate the primary SRC and SRC words for the custom PEL
115 // based on the subsystem's TI info.
116 std::map<std::string, std::string>::iterator it;
117 uint8_t subsystem;
118
119 it = i_additional.find("Subsystem");
120 if (it != i_additional.end())
121 {
122 subsystem = std::stoi(it->second);
123 tiPel->setSubsystem(subsystem);
124 }
125 else
126 {
127 // The entry with key "Subsystem" does not exist in the additional map.
128 // Log the error, create failure event, and return.
Zane Shelley67b82292022-03-25 09:48:40 -0500129 trace::err("Error the key Subsystem does not exist in the map.");
austinfcuic49d20b2022-02-22 16:36:47 -0600130 eventAttentionFail((int)AttnSection::attnLogging | ATTN_INVALID_KEY);
131 return;
132 }
Ben Tynerf5210bb2021-01-05 12:58:10 -0600133
Ben Tyner135793a2021-10-27 09:18:41 -0500134 // If recoverable attentions are active we will call the analyzer and
135 // then link the custom pel to analyzer pel.
Ben Tyner135793a2021-10-27 09:18:41 -0500136 it = i_additional.find("recoverables");
137 if (it != i_additional.end() && "true" == it->second)
138 {
139 DumpParameters dumpParameters;
Zane Shelleyebff0d32021-11-21 10:52:07 -0600140 auto plid = analyzer::analyzeHardware(
141 analyzer::AnalysisType::TERMINATE_IMMEDIATE, dumpParameters);
Zane Shelley611b3442021-11-19 16:02:01 -0600142 if (0 != plid)
Ben Tyner135793a2021-10-27 09:18:41 -0500143 {
Zane Shelley611b3442021-11-19 16:02:01 -0600144 // Link the PLID if an attention was found and a PEL was generated.
145 tiPel->setPlid(plid);
Ben Tyner135793a2021-10-27 09:18:41 -0500146 }
147 }
148
Ben Tynerf5210bb2021-01-05 12:58:10 -0600149 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem)
150 {
151 // populate hypervisor SRC words
152 tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{
153 (uint32_t)std::stoul(i_additional["0x10 SRC Word 12"], 0, 16),
154 (uint32_t)std::stoul(i_additional["0x14 SRC Word 13"], 0, 16),
155 (uint32_t)std::stoul(i_additional["0x18 SRC Word 14"], 0, 16),
156 (uint32_t)std::stoul(i_additional["0x1c SRC Word 15"], 0, 16),
157 (uint32_t)std::stoul(i_additional["0x20 SRC Word 16"], 0, 16),
158 (uint32_t)std::stoul(i_additional["0x24 SRC Word 17"], 0, 16),
159 (uint32_t)std::stoul(i_additional["0x28 SRC Word 18"], 0, 16),
160 (uint32_t)std::stoul(i_additional["0x2c SRC Word 19"], 0, 16)});
161
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600162 // Populate phyp primary SRC
163
164 // char array for raw pel src
Ben Tynerf5210bb2021-01-05 12:58:10 -0600165 std::array<char, pel::asciiStringSize> srcChars{'0'};
austinfcuic49d20b2022-02-22 16:36:47 -0600166 std::string srcString;
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600167
168 // src from TI info
austinfcuic49d20b2022-02-22 16:36:47 -0600169 it = i_additional.find("SrcAscii");
170 if (it != i_additional.end())
171 {
172 srcString = it->second;
173 }
174 else
175 {
176 // The entry with key "Subsystem" does not exist in the additional
177 // map. Log the error, create failure event, and return.
Zane Shelley67b82292022-03-25 09:48:40 -0500178 trace::err("Error the key SrcAscii does not exist in the map.");
austinfcuic49d20b2022-02-22 16:36:47 -0600179 eventAttentionFail((int)AttnSection::attnLogging |
180 ATTN_INVALID_KEY);
181 return;
182 }
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600183
184 // copy from string to char array
Ben Tynerf5210bb2021-01-05 12:58:10 -0600185 srcString.copy(srcChars.data(),
186 std::min(srcString.size(), pel::asciiStringSize), 0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600187
188 tiPel->setAsciiString(srcChars); // pel object src is char array
Ben Tynerfeeea832021-04-06 10:08:11 -0500189
190 // set symptom-id
austinfcuic49d20b2022-02-22 16:36:47 -0600191 auto symptomId = (srcString.substr(0, 8) + '_');
Ben Tynerfeeea832021-04-06 10:08:11 -0500192
193 symptomId += (i_additional["0x10 SRC Word 12"]);
194 symptomId += (i_additional["0x14 SRC Word 13"] + '_');
195 symptomId += (i_additional["0x18 SRC Word 14"]);
196 symptomId += (i_additional["0x1c SRC Word 15"] + '_');
197 symptomId += (i_additional["0x20 SRC Word 16"]);
198 symptomId += (i_additional["0x24 SRC Word 17"] + '_');
199 symptomId += (i_additional["0x28 SRC Word 18"]);
200 symptomId += (i_additional["0x2c SRC Word 19"]);
201
202 // setSymptomId will take care of required null-terminate and padding
203 tiPel->setSymptomId(symptomId);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600204 }
205 else
206 {
207 // Populate hostboot SRC words - note HB word 0 from the shared info
208 // data (additional data "0x10 HB Word") is reflected in the PEL as
209 // "reason code" so we zero it here. Also note that the first word
210 // in this group of words starts at word 0 and word 1 does not exits.
211 tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{
212 (uint32_t)0x00000000,
213 (uint32_t)std::stoul(i_additional["0x14 HB Word 2"], 0, 16),
214 (uint32_t)std::stoul(i_additional["0x18 HB Word 3"], 0, 16),
215 (uint32_t)std::stoul(i_additional["0x1c HB Word 4"], 0, 16),
216 (uint32_t)std::stoul(i_additional["0x20 HB Word 5"], 0, 16),
217 (uint32_t)std::stoul(i_additional["0x24 HB Word 6"], 0, 16),
218 (uint32_t)std::stoul(i_additional["0x28 HB Word 7"], 0, 16),
219 (uint32_t)std::stoul(i_additional["0x2c HB Word 8"], 0, 16)});
220
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600221 // Populate hostboot primary SRC
222
223 // char array for raw pel src
Ben Tynerf5210bb2021-01-05 12:58:10 -0600224 std::array<char, pel::asciiStringSize> srcChars{'0'};
austinfcuic49d20b2022-02-22 16:36:47 -0600225 std::string srcString;
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600226
227 // src from TI info
austinfcuic49d20b2022-02-22 16:36:47 -0600228 it = i_additional.find("SrcAscii");
229 if (it != i_additional.end())
230 {
231 srcString = it->second;
232 }
233 else
234 {
235 // The entry with key "Subsystem" does not exist in the additional
236 // map. Log the error, create failure event, and return.
Zane Shelley67b82292022-03-25 09:48:40 -0500237 trace::err("Error the key SrcAscii does not exist in the map.");
austinfcuic49d20b2022-02-22 16:36:47 -0600238 eventAttentionFail((int)AttnSection::attnLogging |
239 ATTN_INVALID_KEY);
240 return;
241 }
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600242
243 // copy from string to char array
Ben Tynerf5210bb2021-01-05 12:58:10 -0600244 srcString.copy(srcChars.data(),
245 std::min(srcString.size(), pel::asciiStringSize), 0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600246
247 tiPel->setAsciiString(srcChars); // pel object src is char array
Ben Tynerfeeea832021-04-06 10:08:11 -0500248
249 // set symptom-id
austinfcuic49d20b2022-02-22 16:36:47 -0600250 auto symptomId = (srcString.substr(0, 8) + '_');
Ben Tynerfeeea832021-04-06 10:08:11 -0500251
252 symptomId += (i_additional["0x10 HB Word 0"]); // note: word 1
253 symptomId += (i_additional["0x14 HB Word 2"] + '_'); // does not exist
254 symptomId += (i_additional["0x18 HB Word 3"]);
255 symptomId += (i_additional["0x1c HB Word 4"] + '_');
256 symptomId += (i_additional["0x20 HB Word 5"]);
257 symptomId += (i_additional["0x24 HB Word 6"] + '_');
258 symptomId += (i_additional["0x28 HB Word 7"]);
259 symptomId += (i_additional["0x2c HB Word 8"]);
260
261 // setSymptomId will take care of required null-terminate and padding
262 tiPel->setSymptomId(symptomId);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600263 }
264
265 // set severity, event type and action flags
266 tiPel->setSeverity(static_cast<uint8_t>(pel::Severity::termination));
267 tiPel->setType(static_cast<uint8_t>(pel::EventType::na));
Ben Tynerac5bd052022-03-03 14:09:13 -0600268
269 auto actionFlags = pel::ActionFlags::service | pel::ActionFlags::report |
270 pel::ActionFlags::call;
271
272 it = i_additional.find("hidden");
273 if (it != i_additional.end() && "true" == it->second)
274 {
275 trace::inf("making HB TI PEL hidden");
276 actionFlags = actionFlags | pel::ActionFlags::hidden;
277 }
278
279 tiPel->setAction(static_cast<uint16_t>(actionFlags));
Ben Tynerf5210bb2021-01-05 12:58:10 -0600280
Ben Tyner21cc6272022-10-05 18:26:36 -0500281 // The raw PEL that we used as the basis for this custom PEL contains some
282 // user data sections that do not need to be in this PEL. However we do
283 // want to include the raw TI information.
284 int ffdcCount = 0;
285 it = i_additional.find("FFDC count");
286 if (it != i_additional.end())
287 {
288 // remove all sections except 1 (raw Ti info)
289 ffdcCount = std::stoi(it->second) - 1;
290 }
291 tiPel->setSectionCount(tiPel->getSectionCount() - ffdcCount);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600292
293 // Update the raw PEL with the new custom PEL data
294 tiPel->raw(i_rawPel);
295
296 // create PEL from raw data
297 createPelRaw(i_rawPel);
298}
299
300/**
301 * Log an event handled by the attention handler
302 *
303 * Basic (non TI) events will generate a standard message-registry based PEL
304 *
305 * TI events will create two PEL's. One PEL will be informational and will
306 * contain trace information relevent to attention handler. The second PEL
307 * will be specific to the TI type (including the primary SRC) and will be
308 * based off of the TI information provided to the attention handler through
309 * shared TI info data area.
310 *
311 * @param i_event - The event type
312 * @param i_additional - Additional PEL data
313 * @param i_ffdc - FFDC PEL data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500314 * @return Event log Id (0 if no event log generated)
Ben Tynerf5210bb2021-01-05 12:58:10 -0600315 */
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500316uint32_t event(EventType i_event,
317 std::map<std::string, std::string>& i_additional,
318 const std::vector<util::FFDCFile>& i_ffdc)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500319{
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500320 uint32_t pelId = 0; // assume no event log generated
321
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500322 bool eventValid = false; // assume no event created
Ben Tynerf5210bb2021-01-05 12:58:10 -0600323 bool tiEvent = false; // assume not a terminate event
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500324
Ben Tyner21cc6272022-10-05 18:26:36 -0500325 // count user data sections so we can fixup custom PEL
326 i_additional["FFDC count"] = std::to_string(i_ffdc.size());
327
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500328 std::string eventName;
329
330 switch (i_event)
331 {
332 case EventType::Checkstop:
333 eventName = "org.open_power.HwDiags.Error.Checkstop";
334 eventValid = true;
335 break;
336 case EventType::Terminate:
337 eventName = "org.open_power.Attn.Error.Terminate";
338 eventValid = true;
Ben Tynerf5210bb2021-01-05 12:58:10 -0600339 tiEvent = true;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500340 break;
341 case EventType::Vital:
342 eventName = "org.open_power.Attn.Error.Vital";
343 eventValid = true;
344 break;
345 case EventType::HwDiagsFail:
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500346 case EventType::AttentionFail:
347 eventName = "org.open_power.Attn.Error.Fail";
348 eventValid = true;
349 break;
350 default:
351 eventValid = false;
352 break;
353 }
354
355 if (true == eventValid)
356 {
Ben Tynerf5210bb2021-01-05 12:58:10 -0600357 // Create PEL with additional data and FFDC data. The newly created
358 // PEL's platform log-id will be returned.
Ben Tyner13159682022-02-16 14:55:38 -0600359 pelId = util::dbus::createPel(eventName, levelPelError, i_additional,
360 createFFDCTuples(i_ffdc));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500361
Ben Tynerf5210bb2021-01-05 12:58:10 -0600362 // If this is a TI event we will create an additional PEL that is
363 // specific to the subsystem that generated the TI.
Ben Tyner135793a2021-10-27 09:18:41 -0500364 if ((0 != pelId) && (true == tiEvent))
Ben Tynerf5210bb2021-01-05 12:58:10 -0600365 {
366 // get file descriptor and size of information PEL
Ben Tyner188f1092021-02-01 09:33:06 -0600367 int pelFd = getPel(pelId);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500368
Ben Tynerf5210bb2021-01-05 12:58:10 -0600369 // if PEL found, read into buffer
370 if (-1 != pelFd)
371 {
372 auto pelSize = lseek(pelFd, 0, SEEK_END);
373 lseek(pelFd, 0, SEEK_SET);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500374
Ben Tynerf5210bb2021-01-05 12:58:10 -0600375 // read information PEL into buffer
376 std::vector<uint8_t> buffer(pelSize);
Ben Tynerd7006092021-02-05 14:55:52 -0600377 size_t numBytes = read(pelFd, buffer.data(), buffer.size());
378 if (buffer.size() != numBytes)
379 {
austinfcuibfa831a2022-01-26 15:37:07 -0600380 trace::err("Error reading event log: %u of %u bytes read",
381 numBytes, buffer.size());
Ben Tynerd7006092021-02-05 14:55:52 -0600382 }
383 else
384 {
385 // create PEL from buffer
386 createPelCustom(buffer, i_additional);
387 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500388
Ben Tynerd7006092021-02-05 14:55:52 -0600389 close(pelFd);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600390 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600391
austinfcuic49d20b2022-02-22 16:36:47 -0600392 std::map<std::string, std::string>::iterator it;
393 uint8_t subsystem;
394
395 it = i_additional.find("Subsystem");
396 if (it != i_additional.end())
397 {
398 subsystem = std::stoi(it->second);
399 }
400 else
401 {
402 // The entry with key "Subsystem" does not exist in the
403 // additional map. Log the error, create failure event, and
404 // return.
Zane Shelley67b82292022-03-25 09:48:40 -0500405 trace::err(
406 "Error the key Subsystem does not exist in the map.");
austinfcuic49d20b2022-02-22 16:36:47 -0600407 eventAttentionFail((int)AttnSection::attnLogging |
408 ATTN_INVALID_KEY);
409 return 0;
410 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600411
Ben Tyner6bc43c92021-05-27 15:08:02 -0500412 // If not hypervisor TI
413 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) != subsystem)
Ben Tyner5c5db652021-02-22 18:22:35 -0600414 {
Ben Tyner6bc43c92021-05-27 15:08:02 -0500415 // Request a dump and transition the host
416 if ("true" == i_additional["Dump"])
417 {
418 // will not return until dump is complete
Zane Shelley611b3442021-11-19 16:02:01 -0600419 requestDump(pelId, DumpParameters{0, DumpType::Hostboot});
Ben Tyner6bc43c92021-05-27 15:08:02 -0500420 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600421 }
422 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500423 }
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500424 return pelId;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500425}
426
Ben Tynerf5210bb2021-01-05 12:58:10 -0600427/**
428 * Commit special attention TI event to log
429 *
430 * Create a event log with provided additional information and standard
431 * FFDC data plus TI FFDC data
432 *
433 * @param i_additional - Additional log data
434 * @param i_ti_InfoData - TI FFDC data
435 */
436void eventTerminate(std::map<std::string, std::string> i_additionalData,
437 char* i_tiInfoData)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500438{
Ben Tyner29651ef2021-02-08 10:51:03 -0600439 uint32_t tiInfoSize = 0; // assume TI info was not available
Ben Tynerb6401ed2021-01-11 09:08:07 -0600440
Ben Tyner29651ef2021-02-08 10:51:03 -0600441 if (nullptr != i_tiInfoData)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600442 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600443 tiInfoSize = 56; // assume not hypervisor TI
Ben Tynerb6401ed2021-01-11 09:08:07 -0600444
austinfcuic49d20b2022-02-22 16:36:47 -0600445 std::map<std::string, std::string>::iterator it;
446 uint8_t subsystem;
447
448 it = i_additionalData.find("Subsystem");
449 if (it != i_additionalData.end())
450 {
451 subsystem = std::stoi(it->second);
452 }
453 else
454 {
455 // The entry with key "Subsystem" does not exist in the additional
456 // map. Log the error, create failure event, and return.
Zane Shelley67b82292022-03-25 09:48:40 -0500457 trace::err("Error the key Subsystem does not exist in the map.");
austinfcuic49d20b2022-02-22 16:36:47 -0600458 eventAttentionFail((int)AttnSection::attnLogging |
459 ATTN_INVALID_KEY);
460 return;
461 }
Ben Tyner29651ef2021-02-08 10:51:03 -0600462
463 // If hypervisor
464 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600465 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600466 tiInfoSize = 1024; // assume hypervisor max
Ben Tynerb6401ed2021-01-11 09:08:07 -0600467
Ben Tyner29651ef2021-02-08 10:51:03 -0600468 // hypervisor may just want some of the data
469 if (0 == (*(i_tiInfoData + 0x09) & 0x01))
470 {
471 uint32_t* additionalLength = (uint32_t*)(i_tiInfoData + 0x50);
472 uint32_t tiAdditional = be32toh(*additionalLength);
473 tiInfoSize = std::min(tiInfoSize, (84 + tiAdditional));
474 }
Ben Tynerb6401ed2021-01-11 09:08:07 -0600475 }
476 }
477
austinfcuibfa831a2022-01-26 15:37:07 -0600478 trace::inf("TI info size = %u", tiInfoSize);
Ben Tynerb6401ed2021-01-11 09:08:07 -0600479
Ben Tynerf5210bb2021-01-05 12:58:10 -0600480 event(EventType::Terminate, i_additionalData,
Ben Tynerb6401ed2021-01-11 09:08:07 -0600481 createFFDCFiles(i_tiInfoData, tiInfoSize));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500482}
483
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500484/** @brief Commit SBE vital event to log, returns event log ID */
485uint32_t eventVital()
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500486{
Ben Tynerf5210bb2021-01-05 12:58:10 -0600487 // Additional data for log
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500488 std::map<std::string, std::string> additionalData;
489
Ben Tynerf5210bb2021-01-05 12:58:10 -0600490 // Create log event with additional data and FFDC data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500491 return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500492}
493
Ben Tynerf5210bb2021-01-05 12:58:10 -0600494/**
Ben Tynerf5210bb2021-01-05 12:58:10 -0600495 * Commit attention handler failure event to log
496 *
497 * Create an event log containing the specified error code.
498 *
499 * @param i_error - Error code
500 */
501void eventAttentionFail(int i_error)
502{
503 // Additional data for log
504 std::map<std::string, std::string> additionalData;
505 additionalData["ERROR_CODE"] = std::to_string(i_error);
506
507 // Create log event with additional data and FFDC data
508 event(EventType::AttentionFail, additionalData,
509 createFFDCFiles(nullptr, 0));
510}
511
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500512} // namespace attn