blob: 52e39bc95fc80c0f9e05f3093e298d475e2b7013 [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));
223 tiPel->setAction(static_cast<uint16_t>(pel::ActionFlags::service |
224 pel::ActionFlags::report |
225 pel::ActionFlags::call));
226
227 // The raw PEL that we used as the basis for this custom PEL contains the
228 // attention handler trace data and does not needed to be in this PEL so
229 // we remove it here.
230 tiPel->setSectionCount(tiPel->getSectionCount() - 1);
231
232 // Update the raw PEL with the new custom PEL data
233 tiPel->raw(i_rawPel);
234
235 // create PEL from raw data
236 createPelRaw(i_rawPel);
237}
238
239/**
240 * Log an event handled by the attention handler
241 *
242 * Basic (non TI) events will generate a standard message-registry based PEL
243 *
244 * TI events will create two PEL's. One PEL will be informational and will
245 * contain trace information relevent to attention handler. The second PEL
246 * will be specific to the TI type (including the primary SRC) and will be
247 * based off of the TI information provided to the attention handler through
248 * shared TI info data area.
249 *
250 * @param i_event - The event type
251 * @param i_additional - Additional PEL data
252 * @param i_ffdc - FFDC PEL data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500253 * @return Event log Id (0 if no event log generated)
Ben Tynerf5210bb2021-01-05 12:58:10 -0600254 */
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500255uint32_t event(EventType i_event,
256 std::map<std::string, std::string>& i_additional,
257 const std::vector<util::FFDCFile>& i_ffdc)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500258{
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500259 uint32_t pelId = 0; // assume no event log generated
260
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500261 bool eventValid = false; // assume no event created
Ben Tynerf5210bb2021-01-05 12:58:10 -0600262 bool tiEvent = false; // assume not a terminate event
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500263
264 std::string eventName;
265
266 switch (i_event)
267 {
268 case EventType::Checkstop:
269 eventName = "org.open_power.HwDiags.Error.Checkstop";
270 eventValid = true;
271 break;
272 case EventType::Terminate:
273 eventName = "org.open_power.Attn.Error.Terminate";
274 eventValid = true;
Ben Tynerf5210bb2021-01-05 12:58:10 -0600275 tiEvent = true;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500276 break;
277 case EventType::Vital:
278 eventName = "org.open_power.Attn.Error.Vital";
279 eventValid = true;
280 break;
281 case EventType::HwDiagsFail:
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500282 case EventType::AttentionFail:
283 eventName = "org.open_power.Attn.Error.Fail";
284 eventValid = true;
285 break;
286 default:
287 eventValid = false;
288 break;
289 }
290
291 if (true == eventValid)
292 {
Ben Tynerf5210bb2021-01-05 12:58:10 -0600293 // Create PEL with additional data and FFDC data. The newly created
294 // PEL's platform log-id will be returned.
Ben Tyner13159682022-02-16 14:55:38 -0600295 pelId = util::dbus::createPel(eventName, levelPelError, i_additional,
296 createFFDCTuples(i_ffdc));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500297
Ben Tynerf5210bb2021-01-05 12:58:10 -0600298 // If this is a TI event we will create an additional PEL that is
299 // specific to the subsystem that generated the TI.
Ben Tyner135793a2021-10-27 09:18:41 -0500300 if ((0 != pelId) && (true == tiEvent))
Ben Tynerf5210bb2021-01-05 12:58:10 -0600301 {
302 // get file descriptor and size of information PEL
Ben Tyner188f1092021-02-01 09:33:06 -0600303 int pelFd = getPel(pelId);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500304
Ben Tynerf5210bb2021-01-05 12:58:10 -0600305 // if PEL found, read into buffer
306 if (-1 != pelFd)
307 {
308 auto pelSize = lseek(pelFd, 0, SEEK_END);
309 lseek(pelFd, 0, SEEK_SET);
Ben Tyner1b1915e2020-10-23 15:13:38 -0500310
Ben Tynerf5210bb2021-01-05 12:58:10 -0600311 // read information PEL into buffer
312 std::vector<uint8_t> buffer(pelSize);
Ben Tynerd7006092021-02-05 14:55:52 -0600313 size_t numBytes = read(pelFd, buffer.data(), buffer.size());
314 if (buffer.size() != numBytes)
315 {
austinfcuibfa831a2022-01-26 15:37:07 -0600316 trace::err("Error reading event log: %u of %u bytes read",
317 numBytes, buffer.size());
Ben Tynerd7006092021-02-05 14:55:52 -0600318 }
319 else
320 {
321 // create PEL from buffer
322 createPelCustom(buffer, i_additional);
323 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500324
Ben Tynerd7006092021-02-05 14:55:52 -0600325 close(pelFd);
Ben Tynerf5210bb2021-01-05 12:58:10 -0600326 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600327
Ben Tyner6bc43c92021-05-27 15:08:02 -0500328 uint8_t subsystem = std::stoi(i_additional["Subsystem"]);
Ben Tyner5c5db652021-02-22 18:22:35 -0600329
Ben Tyner6bc43c92021-05-27 15:08:02 -0500330 // If not hypervisor TI
331 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) != subsystem)
Ben Tyner5c5db652021-02-22 18:22:35 -0600332 {
Ben Tyner6bc43c92021-05-27 15:08:02 -0500333 // Request a dump and transition the host
334 if ("true" == i_additional["Dump"])
335 {
336 // will not return until dump is complete
Zane Shelley611b3442021-11-19 16:02:01 -0600337 requestDump(pelId, DumpParameters{0, DumpType::Hostboot});
Ben Tyner6bc43c92021-05-27 15:08:02 -0500338 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600339 }
340 }
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500341 }
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500342 return pelId;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500343}
344
Ben Tynerf5210bb2021-01-05 12:58:10 -0600345/**
346 * Commit special attention TI event to log
347 *
348 * Create a event log with provided additional information and standard
349 * FFDC data plus TI FFDC data
350 *
351 * @param i_additional - Additional log data
352 * @param i_ti_InfoData - TI FFDC data
353 */
354void eventTerminate(std::map<std::string, std::string> i_additionalData,
355 char* i_tiInfoData)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500356{
Ben Tynerb6401ed2021-01-11 09:08:07 -0600357
Ben Tyner29651ef2021-02-08 10:51:03 -0600358 uint32_t tiInfoSize = 0; // assume TI info was not available
Ben Tynerb6401ed2021-01-11 09:08:07 -0600359
Ben Tyner29651ef2021-02-08 10:51:03 -0600360 if (nullptr != i_tiInfoData)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600361 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600362 tiInfoSize = 56; // assume not hypervisor TI
Ben Tynerb6401ed2021-01-11 09:08:07 -0600363
Ben Tyner29651ef2021-02-08 10:51:03 -0600364 uint8_t subsystem = std::stoi(i_additionalData["Subsystem"]);
365
366 // If hypervisor
367 if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem)
Ben Tynerb6401ed2021-01-11 09:08:07 -0600368 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600369 tiInfoSize = 1024; // assume hypervisor max
Ben Tynerb6401ed2021-01-11 09:08:07 -0600370
Ben Tyner29651ef2021-02-08 10:51:03 -0600371 // hypervisor may just want some of the data
372 if (0 == (*(i_tiInfoData + 0x09) & 0x01))
373 {
374 uint32_t* additionalLength = (uint32_t*)(i_tiInfoData + 0x50);
375 uint32_t tiAdditional = be32toh(*additionalLength);
376 tiInfoSize = std::min(tiInfoSize, (84 + tiAdditional));
377 }
Ben Tynerb6401ed2021-01-11 09:08:07 -0600378 }
379 }
380
austinfcuibfa831a2022-01-26 15:37:07 -0600381 trace::inf("TI info size = %u", tiInfoSize);
Ben Tynerb6401ed2021-01-11 09:08:07 -0600382
Ben Tynerf5210bb2021-01-05 12:58:10 -0600383 event(EventType::Terminate, i_additionalData,
Ben Tynerb6401ed2021-01-11 09:08:07 -0600384 createFFDCFiles(i_tiInfoData, tiInfoSize));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500385}
386
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500387/** @brief Commit SBE vital event to log, returns event log ID */
388uint32_t eventVital()
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500389{
Ben Tynerf5210bb2021-01-05 12:58:10 -0600390 // Additional data for log
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500391 std::map<std::string, std::string> additionalData;
392
Ben Tynerf5210bb2021-01-05 12:58:10 -0600393 // Create log event with additional data and FFDC data
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500394 return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0));
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500395}
396
Ben Tynerf5210bb2021-01-05 12:58:10 -0600397/**
Ben Tynerf5210bb2021-01-05 12:58:10 -0600398 * Commit attention handler failure event to log
399 *
400 * Create an event log containing the specified error code.
401 *
402 * @param i_error - Error code
403 */
404void eventAttentionFail(int i_error)
405{
406 // Additional data for log
407 std::map<std::string, std::string> additionalData;
408 additionalData["ERROR_CODE"] = std::to_string(i_error);
409
410 // Create log event with additional data and FFDC data
411 event(EventType::AttentionFail, additionalData,
412 createFFDCFiles(nullptr, 0));
413}
414
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500415} // namespace attn