blob: a88a85e4c4ee62f1565de13099c2f9ba07701916 [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
89 return files;
90}
91
92/**
Ben Tynerf5210bb2021-01-05 12:58:10 -060093 * Create a PEL from an existing PEL
94 *
95 * Create a new PEL based on the specified raw PEL and submit the new PEL
96 * to the backend logging code as a raw PEL. Note that additional data map
97 * here contains data to be committed to the PEL and it can also be used to
98 * create the PEL as it contains needed information.
99 *
Ben Tyner135793a2021-10-27 09:18:41 -0500100 * @param i_rawPel - buffer containing a raw PEL
Ben Tynerf5210bb2021-01-05 12:58:10 -0600101 * @param i_additional - additional data to be added to the new PEL
102 */
103void createPelCustom(std::vector<uint8_t>& i_rawPel,
104 std::map<std::string, std::string> i_additional)
105{
106 // create PEL object from buffer
107 auto tiPel = std::make_unique<pel::PelMinimal>(i_rawPel);
108
109 // The additional data contains the TI info as well as the value for the
110 // subystem that provided the TI info. Get the subystem from additional
111 // data and then populate the prmary SRC and SRC words for the custom PEL
112 // based on the sybsystem's TI info.
113 uint8_t subsystem = std::stoi(i_additional["Subsystem"]);
114 tiPel->setSubsystem(subsystem);
115
Ben Tyner135793a2021-10-27 09:18:41 -0500116 // If recoverable attentions are active we will call the analyzer and
117 // then link the custom pel to analyzer pel.
118 std::map<std::string, std::string>::iterator it;
119 it = i_additional.find("recoverables");
120 if (it != i_additional.end() && "true" == it->second)
121 {
122 DumpParameters dumpParameters;
Zane Shelleyebff0d32021-11-21 10:52:07 -0600123 auto plid = analyzer::analyzeHardware(
124 analyzer::AnalysisType::TERMINATE_IMMEDIATE, dumpParameters);
Zane Shelley611b3442021-11-19 16:02:01 -0600125 if (0 != plid)
Ben Tyner135793a2021-10-27 09:18:41 -0500126 {
Zane Shelley611b3442021-11-19 16:02:01 -0600127 // Link the PLID if an attention was found and a PEL was generated.
128 tiPel->setPlid(plid);
Ben Tyner135793a2021-10-27 09:18:41 -0500129 }
130 }
131
Ben Tynerf5210bb2021-01-05 12:58:10 -0600132 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem)
133 {
134 // populate hypervisor SRC words
135 tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{
136 (uint32_t)std::stoul(i_additional["0x10 SRC Word 12"], 0, 16),
137 (uint32_t)std::stoul(i_additional["0x14 SRC Word 13"], 0, 16),
138 (uint32_t)std::stoul(i_additional["0x18 SRC Word 14"], 0, 16),
139 (uint32_t)std::stoul(i_additional["0x1c SRC Word 15"], 0, 16),
140 (uint32_t)std::stoul(i_additional["0x20 SRC Word 16"], 0, 16),
141 (uint32_t)std::stoul(i_additional["0x24 SRC Word 17"], 0, 16),
142 (uint32_t)std::stoul(i_additional["0x28 SRC Word 18"], 0, 16),
143 (uint32_t)std::stoul(i_additional["0x2c SRC Word 19"], 0, 16)});
144
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600145 // Populate phyp primary SRC
146
147 // char array for raw pel src
Ben Tynerf5210bb2021-01-05 12:58:10 -0600148 std::array<char, pel::asciiStringSize> srcChars{'0'};
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600149
150 // src from TI info
Ben Tynerf5210bb2021-01-05 12:58:10 -0600151 std::string srcString = i_additional["SrcAscii"];
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600152
153 // copy from string to char array
Ben Tynerf5210bb2021-01-05 12:58:10 -0600154 srcString.copy(srcChars.data(),
155 std::min(srcString.size(), pel::asciiStringSize), 0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600156
157 tiPel->setAsciiString(srcChars); // pel object src is char array
Ben Tynerfeeea832021-04-06 10:08:11 -0500158
159 // set symptom-id
160 auto symptomId = (i_additional["SrcAscii"].substr(0, 8) + '_');
161
162 symptomId += (i_additional["0x10 SRC Word 12"]);
163 symptomId += (i_additional["0x14 SRC Word 13"] + '_');
164 symptomId += (i_additional["0x18 SRC Word 14"]);
165 symptomId += (i_additional["0x1c SRC Word 15"] + '_');
166 symptomId += (i_additional["0x20 SRC Word 16"]);
167 symptomId += (i_additional["0x24 SRC Word 17"] + '_');
168 symptomId += (i_additional["0x28 SRC Word 18"]);
169 symptomId += (i_additional["0x2c SRC Word 19"]);
170
171 // setSymptomId will take care of required null-terminate and padding
172 tiPel->setSymptomId(symptomId);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600173 }
174 else
175 {
176 // Populate hostboot SRC words - note HB word 0 from the shared info
177 // data (additional data "0x10 HB Word") is reflected in the PEL as
178 // "reason code" so we zero it here. Also note that the first word
179 // in this group of words starts at word 0 and word 1 does not exits.
180 tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{
181 (uint32_t)0x00000000,
182 (uint32_t)std::stoul(i_additional["0x14 HB Word 2"], 0, 16),
183 (uint32_t)std::stoul(i_additional["0x18 HB Word 3"], 0, 16),
184 (uint32_t)std::stoul(i_additional["0x1c HB Word 4"], 0, 16),
185 (uint32_t)std::stoul(i_additional["0x20 HB Word 5"], 0, 16),
186 (uint32_t)std::stoul(i_additional["0x24 HB Word 6"], 0, 16),
187 (uint32_t)std::stoul(i_additional["0x28 HB Word 7"], 0, 16),
188 (uint32_t)std::stoul(i_additional["0x2c HB Word 8"], 0, 16)});
189
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600190 // Populate hostboot primary SRC
191
192 // char array for raw pel src
Ben Tynerf5210bb2021-01-05 12:58:10 -0600193 std::array<char, pel::asciiStringSize> srcChars{'0'};
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600194
195 // src from TI info
196 std::string srcString = i_additional["SrcAscii"];
197
198 // copy from string to char array
Ben Tynerf5210bb2021-01-05 12:58:10 -0600199 srcString.copy(srcChars.data(),
200 std::min(srcString.size(), pel::asciiStringSize), 0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600201
202 tiPel->setAsciiString(srcChars); // pel object src is char array
Ben Tynerfeeea832021-04-06 10:08:11 -0500203
204 // set symptom-id
205 auto symptomId = (i_additional["SrcAscii"].substr(0, 8) + '_');
206
207 symptomId += (i_additional["0x10 HB Word 0"]); // note: word 1
208 symptomId += (i_additional["0x14 HB Word 2"] + '_'); // does not exist
209 symptomId += (i_additional["0x18 HB Word 3"]);
210 symptomId += (i_additional["0x1c HB Word 4"] + '_');
211 symptomId += (i_additional["0x20 HB Word 5"]);
212 symptomId += (i_additional["0x24 HB Word 6"] + '_');
213 symptomId += (i_additional["0x28 HB Word 7"]);
214 symptomId += (i_additional["0x2c HB Word 8"]);
215
216 // setSymptomId will take care of required null-terminate and padding
217 tiPel->setSymptomId(symptomId);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600218 }
219
220 // set severity, event type and action flags
221 tiPel->setSeverity(static_cast<uint8_t>(pel::Severity::termination));
222 tiPel->setType(static_cast<uint8_t>(pel::EventType::na));
Ben Tynerac5bd052022-03-03 14:09:13 -0600223
224 auto actionFlags = pel::ActionFlags::service | pel::ActionFlags::report |
225 pel::ActionFlags::call;
226
227 it = i_additional.find("hidden");
228 if (it != i_additional.end() && "true" == it->second)
229 {
230 trace::inf("making HB TI PEL hidden");
231 actionFlags = actionFlags | pel::ActionFlags::hidden;
232 }
233
234 tiPel->setAction(static_cast<uint16_t>(actionFlags));
Ben Tynerf5210bb2021-01-05 12:58:10 -0600235
236 // The raw PEL that we used as the basis for this custom PEL contains the
237 // attention handler trace data and does not needed to be in this PEL so
238 // we remove it here.
239 tiPel->setSectionCount(tiPel->getSectionCount() - 1);
240
241 // Update the raw PEL with the new custom PEL data
242 tiPel->raw(i_rawPel);
243
244 // create PEL from raw data
245 createPelRaw(i_rawPel);
246}
247
248/**
249 * Log an event handled by the attention handler
250 *
251 * Basic (non TI) events will generate a standard message-registry based PEL
252 *
253 * TI events will create two PEL's. One PEL will be informational and will
254 * contain trace information relevent to attention handler. The second PEL
255 * will be specific to the TI type (including the primary SRC) and will be
256 * based off of the TI information provided to the attention handler through
257 * shared TI info data area.
258 *
259 * @param i_event - The event type
260 * @param i_additional - Additional PEL data
261 * @param i_ffdc - FFDC PEL data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500262 * @return Event log Id (0 if no event log generated)
Ben Tynerf5210bb2021-01-05 12:58:10 -0600263 */
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500264uint32_t event(EventType i_event,
265 std::map<std::string, std::string>& i_additional,
266 const std::vector<util::FFDCFile>& i_ffdc)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500267{
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500268 uint32_t pelId = 0; // assume no event log generated
269
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500270 bool eventValid = false; // assume no event created
Ben Tynerf5210bb2021-01-05 12:58:10 -0600271 bool tiEvent = false; // assume not a terminate event
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500272
273 std::string eventName;
274
275 switch (i_event)
276 {
277 case EventType::Checkstop:
278 eventName = "org.open_power.HwDiags.Error.Checkstop";
279 eventValid = true;
280 break;
281 case EventType::Terminate:
282 eventName = "org.open_power.Attn.Error.Terminate";
283 eventValid = true;
Ben Tynerf5210bb2021-01-05 12:58:10 -0600284 tiEvent = true;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500285 break;
286 case EventType::Vital:
287 eventName = "org.open_power.Attn.Error.Vital";
288 eventValid = true;
289 break;
290 case EventType::HwDiagsFail:
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500291 case EventType::AttentionFail:
292 eventName = "org.open_power.Attn.Error.Fail";
293 eventValid = true;
294 break;
295 default:
296 eventValid = false;
297 break;
298 }
299
300 if (true == eventValid)
301 {
Ben Tynerf5210bb2021-01-05 12:58:10 -0600302 // Create PEL with additional data and FFDC data. The newly created
303 // PEL's platform log-id will be returned.
Ben Tyner13159682022-02-16 14:55:38 -0600304 pelId = util::dbus::createPel(eventName, levelPelError, i_additional,
305 createFFDCTuples(i_ffdc));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500306
Ben Tynerf5210bb2021-01-05 12:58:10 -0600307 // If this is a TI event we will create an additional PEL that is
308 // specific to the subsystem that generated the TI.
Ben Tyner135793a2021-10-27 09:18:41 -0500309 if ((0 != pelId) && (true == tiEvent))
Ben Tynerf5210bb2021-01-05 12:58:10 -0600310 {
311 // get file descriptor and size of information PEL
Ben Tyner188f1092021-02-01 09:33:06 -0600312 int pelFd = getPel(pelId);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500313
Ben Tynerf5210bb2021-01-05 12:58:10 -0600314 // if PEL found, read into buffer
315 if (-1 != pelFd)
316 {
317 auto pelSize = lseek(pelFd, 0, SEEK_END);
318 lseek(pelFd, 0, SEEK_SET);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500319
Ben Tynerf5210bb2021-01-05 12:58:10 -0600320 // read information PEL into buffer
321 std::vector<uint8_t> buffer(pelSize);
Ben Tynerd7006092021-02-05 14:55:52 -0600322 size_t numBytes = read(pelFd, buffer.data(), buffer.size());
323 if (buffer.size() != numBytes)
324 {
austinfcuibfa831a2022-01-26 15:37:07 -0600325 trace::err("Error reading event log: %u of %u bytes read",
326 numBytes, buffer.size());
Ben Tynerd7006092021-02-05 14:55:52 -0600327 }
328 else
329 {
330 // create PEL from buffer
331 createPelCustom(buffer, i_additional);
332 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500333
Ben Tynerd7006092021-02-05 14:55:52 -0600334 close(pelFd);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600335 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600336
Ben Tyner6bc43c92021-05-27 15:08:02 -0500337 uint8_t subsystem = std::stoi(i_additional["Subsystem"]);
Ben Tyner5c5db652021-02-22 18:22:35 -0600338
Ben Tyner6bc43c92021-05-27 15:08:02 -0500339 // If not hypervisor TI
340 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) != subsystem)
Ben Tyner5c5db652021-02-22 18:22:35 -0600341 {
Ben Tyner6bc43c92021-05-27 15:08:02 -0500342 // Request a dump and transition the host
343 if ("true" == i_additional["Dump"])
344 {
345 // will not return until dump is complete
Zane Shelley611b3442021-11-19 16:02:01 -0600346 requestDump(pelId, DumpParameters{0, DumpType::Hostboot});
Ben Tyner6bc43c92021-05-27 15:08:02 -0500347 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600348 }
349 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500350 }
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500351 return pelId;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500352}
353
Ben Tynerf5210bb2021-01-05 12:58:10 -0600354/**
355 * Commit special attention TI event to log
356 *
357 * Create a event log with provided additional information and standard
358 * FFDC data plus TI FFDC data
359 *
360 * @param i_additional - Additional log data
361 * @param i_ti_InfoData - TI FFDC data
362 */
363void eventTerminate(std::map<std::string, std::string> i_additionalData,
364 char* i_tiInfoData)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500365{
Ben Tynerb6401ed2021-01-11 09:08:07 -0600366
Ben Tyner29651ef2021-02-08 10:51:03 -0600367 uint32_t tiInfoSize = 0; // assume TI info was not available
Ben Tynerb6401ed2021-01-11 09:08:07 -0600368
Ben Tyner29651ef2021-02-08 10:51:03 -0600369 if (nullptr != i_tiInfoData)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600370 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600371 tiInfoSize = 56; // assume not hypervisor TI
Ben Tynerb6401ed2021-01-11 09:08:07 -0600372
Ben Tyner29651ef2021-02-08 10:51:03 -0600373 uint8_t subsystem = std::stoi(i_additionalData["Subsystem"]);
374
375 // If hypervisor
376 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600377 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600378 tiInfoSize = 1024; // assume hypervisor max
Ben Tynerb6401ed2021-01-11 09:08:07 -0600379
Ben Tyner29651ef2021-02-08 10:51:03 -0600380 // hypervisor may just want some of the data
381 if (0 == (*(i_tiInfoData + 0x09) & 0x01))
382 {
383 uint32_t* additionalLength = (uint32_t*)(i_tiInfoData + 0x50);
384 uint32_t tiAdditional = be32toh(*additionalLength);
385 tiInfoSize = std::min(tiInfoSize, (84 + tiAdditional));
386 }
Ben Tynerb6401ed2021-01-11 09:08:07 -0600387 }
388 }
389
austinfcuibfa831a2022-01-26 15:37:07 -0600390 trace::inf("TI info size = %u", tiInfoSize);
Ben Tynerb6401ed2021-01-11 09:08:07 -0600391
Ben Tynerf5210bb2021-01-05 12:58:10 -0600392 event(EventType::Terminate, i_additionalData,
Ben Tynerb6401ed2021-01-11 09:08:07 -0600393 createFFDCFiles(i_tiInfoData, tiInfoSize));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500394}
395
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500396/** @brief Commit SBE vital event to log, returns event log ID */
397uint32_t eventVital()
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500398{
Ben Tynerf5210bb2021-01-05 12:58:10 -0600399 // Additional data for log
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500400 std::map<std::string, std::string> additionalData;
401
Ben Tynerf5210bb2021-01-05 12:58:10 -0600402 // Create log event with additional data and FFDC data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500403 return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500404}
405
Ben Tynerf5210bb2021-01-05 12:58:10 -0600406/**
Ben Tynerf5210bb2021-01-05 12:58:10 -0600407 * Commit attention handler failure event to log
408 *
409 * Create an event log containing the specified error code.
410 *
411 * @param i_error - Error code
412 */
413void eventAttentionFail(int i_error)
414{
415 // Additional data for log
416 std::map<std::string, std::string> additionalData;
417 additionalData["ERROR_CODE"] = std::to_string(i_error);
418
419 // Create log event with additional data and FFDC data
420 event(EventType::AttentionFail, additionalData,
421 createFFDCFiles(nullptr, 0));
422}
423
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500424} // namespace attn