blob: 259cf2745d53f0ac7be4ba988683267aa57f848d [file] [log] [blame]
Brad Bishop5e5d4452020-10-27 19:46:13 -04001extern "C"
2{
Brad Bishopf6783cd2020-10-27 19:25:09 -04003#include <libpdbg.h>
4}
5
6#include "create_pel.hpp"
Jayanth Othayoth006641e2021-10-07 06:56:24 -05007#include "dump_utils.hpp"
Jayanth Othayoth4079f092021-09-20 07:36:54 -05008#include "extensions/phal/common_utils.hpp"
Brad Bishopf6783cd2020-10-27 19:25:09 -04009#include "phal_error.hpp"
10
11#include <attributes_info.H>
12#include <fmt/format.h>
13#include <libekb.H>
Jayanth Othayoth4079f092021-09-20 07:36:54 -050014#include <libphal.H>
Brad Bishopf6783cd2020-10-27 19:25:09 -040015
Brad Bishop5e5d4452020-10-27 19:46:13 -040016#include <nlohmann/json.hpp>
17#include <phosphor-logging/elog.hpp>
18
Brad Bishopf6783cd2020-10-27 19:25:09 -040019#include <algorithm>
20#include <cstdlib>
21#include <cstring>
22#include <iomanip>
23#include <list>
24#include <map>
Brad Bishopf6783cd2020-10-27 19:25:09 -040025#include <sstream>
26#include <string>
27
28namespace openpower
29{
30namespace phal
31{
32using namespace phosphor::logging;
Jayanth Othayoth5d5eb312021-11-15 01:54:07 -060033using namespace openpower::phal::exception;
Brad Bishopf6783cd2020-10-27 19:25:09 -040034
35/**
36 * Used to pass buffer to pdbg callback api to get required target
37 * data (attributes) based on given data (attribute).
38 */
39struct TargetInfo
40{
41 ATTR_PHYS_BIN_PATH_Type physBinPath;
42 ATTR_LOCATION_CODE_Type locationCode;
43 ATTR_PHYS_DEV_PATH_Type physDevPath;
44 ATTR_MRU_ID_Type mruId;
45
46 bool deconfigure;
47
48 TargetInfo()
49 {
50 memset(&physBinPath, '\0', sizeof(physBinPath));
51 memset(&locationCode, '\0', sizeof(locationCode));
52 memset(&physDevPath, '\0', sizeof(physDevPath));
53 mruId = 0;
54 deconfigure = false;
55 }
56};
57
58/**
59 * Used to return in callback function which are used to get
60 * physical path value and it binary format value.
61 *
62 * The value for constexpr defined based on pdbg_target_traverse function usage.
63 */
64constexpr int continueTgtTraversal = 0;
65constexpr int requireAttrFound = 1;
66constexpr int requireAttrNotFound = 2;
67
68/**
69 * @brief Used to get target location code from phal device tree
70 *
71 * @param[in] target current device tree target
72 * @param[out] appPrivData used for accessing|storing from|to application
73 *
74 * @return 0 to continue traverse, non-zero to stop traverse
75 */
76int pdbgCallbackToGetTgtReqAttrsVal(struct pdbg_target* target,
77 void* appPrivData)
78{
Jayanth Othayoth5d5eb312021-11-15 01:54:07 -060079 using namespace openpower::phal::pdbg;
80
Brad Bishopf6783cd2020-10-27 19:25:09 -040081 TargetInfo* targetInfo = static_cast<TargetInfo*>(appPrivData);
82
83 ATTR_PHYS_BIN_PATH_Type physBinPath;
84 /**
85 * TODO: Issue: phal/pdata#16
86 * Should not use direct pdbg api to read attribute. Need to use DT_GET_PROP
87 * macro for bmc app's and this will call libdt-api api but, it will print
88 * "pdbg_target_get_attribute failed" trace if attribute is not found and
89 * this callback will call recursively by using pdbg_target_traverse() until
90 * find expected attribute based on return code from this callback. Because,
91 * need to do target iteration to get actual attribute (ATTR_PHYS_BIN_PATH)
92 * value when device tree target info doesn't know to read attribute from
93 * device tree. So, Due to this error trace user will get confusion while
94 * looking traces. Hence using pdbg api to avoid trace until libdt-api
95 * provides log level setup.
96 */
97 if (!pdbg_target_get_attribute(
98 target, "ATTR_PHYS_BIN_PATH",
99 std::stoi(dtAttr::fapi2::ATTR_PHYS_BIN_PATH_Spec),
100 dtAttr::fapi2::ATTR_PHYS_BIN_PATH_ElementCount, physBinPath))
101 {
102 return continueTgtTraversal;
103 }
104
105 if (std::memcmp(physBinPath, targetInfo->physBinPath,
106 sizeof(physBinPath)) != 0)
107 {
108 return continueTgtTraversal;
109 }
110
Jayanth Othayothde909252021-11-15 02:36:45 -0600111 // Found Target, now collect the required attributes associated to the
112 // target. Incase of any attribute read failure, initialize the data with
113 // default value.
Jayanth Othayoth5d5eb312021-11-15 01:54:07 -0600114 try
Brad Bishopf6783cd2020-10-27 19:25:09 -0400115 {
Jayanth Othayoth5d5eb312021-11-15 01:54:07 -0600116 // Get location code information
117 openpower::phal::pdbg::getLocationCode(target,
118 targetInfo->locationCode);
119 }
120 catch (const std::exception& e)
121 {
Jayanth Othayoth5d5eb312021-11-15 01:54:07 -0600122 log<level::ERR>(fmt::format("getLocationCode({}): Exception({})",
123 pdbg_target_path(target), e.what())
124 .c_str());
Brad Bishopf6783cd2020-10-27 19:25:09 -0400125 }
126
127 if (DT_GET_PROP(ATTR_PHYS_DEV_PATH, target, targetInfo->physDevPath))
128 {
Jayanth Othayothde909252021-11-15 02:36:45 -0600129 log<level::ERR>(
130 fmt::format("Could not read({}) PHYS_DEV_PATH attribute",
131 pdbg_target_path(target))
132 .c_str());
Brad Bishopf6783cd2020-10-27 19:25:09 -0400133 }
134
135 if (DT_GET_PROP(ATTR_MRU_ID, target, targetInfo->mruId))
136 {
Jayanth Othayothde909252021-11-15 02:36:45 -0600137 log<level::ERR>(fmt::format("Could not read({}) ATTR_MRU_ID attribute",
138 pdbg_target_path(target))
139 .c_str());
Brad Bishopf6783cd2020-10-27 19:25:09 -0400140 }
141
Brad Bishopf6783cd2020-10-27 19:25:09 -0400142 return requireAttrFound;
143}
144
145/**
146 * @brief Used to get target info (attributes data)
147 *
148 * To get target required attributes value using another attribute value
149 * ("PHYS_BIN_PATH" which is present in same target attributes list) by using
150 * "ipdbg_target_traverse" api because, here we have attribute value only and
151 * doesn't have respective device tree target info to get required attributes
152 * values from it attributes list.
153 *
154 * @param[in] physBinPath to pass PHYS_BIN_PATH value
155 * @param[out] targetInfo to pas buufer to fill with required attributes
156 *
157 * @return true on success otherwise false
158 */
159bool getTgtReqAttrsVal(const std::vector<uint8_t>& physBinPath,
160 TargetInfo& targetInfo)
161{
162 std::memcpy(&targetInfo.physBinPath, physBinPath.data(),
163 sizeof(targetInfo.physBinPath));
164
165 int ret = pdbg_target_traverse(NULL, pdbgCallbackToGetTgtReqAttrsVal,
166 &targetInfo);
167 if (ret == 0)
168 {
169 log<level::ERR>(fmt::format("Given ATTR_PHYS_BIN_PATH value({}) "
170 "not found in phal device tree",
171 targetInfo.physBinPath)
172 .c_str());
173 return false;
174 }
175 else if (ret == requireAttrNotFound)
176 {
177 return false;
178 }
179
180 return true;
181}
182} // namespace phal
183
184namespace pel
185{
186using namespace phosphor::logging;
187
188namespace detail
189{
190using json = nlohmann::json;
191
192// keys need to be unique so using counter value to generate unique key
193static int counter = 0;
194
195// list of debug traces
196static std::vector<std::pair<std::string, std::string>> traceLog;
197
Brad Bishop63508a72020-10-27 18:55:01 -0400198void processLogTraceCallback(void*, const char* fmt, va_list ap)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400199{
200 va_list vap;
201 va_copy(vap, ap);
202 std::vector<char> logData(1 + std::vsnprintf(nullptr, 0, fmt, ap));
203 std::vsnprintf(logData.data(), logData.size(), fmt, vap);
204 va_end(vap);
205 std::string logstr(logData.begin(), logData.end());
206
207 log<level::INFO>(logstr.c_str());
208
209 char timeBuf[80];
210 time_t t = time(0);
211 tm myTm{};
212 gmtime_r(&t, &myTm);
213 strftime(timeBuf, 80, "%Y-%m-%d %H:%M:%S", &myTm);
214
215 // key values need to be unique for PEL
216 // TODO #openbmc/dev/issues/1563
217 // If written to Json no need to worry about unique KEY
218 std::stringstream str;
219 str << std::setfill('0');
220 str << "LOG" << std::setw(3) << counter;
221 str << " " << timeBuf;
222 traceLog.emplace_back(std::make_pair(str.str(), std::move(logstr)));
223 counter++;
224}
225
226/**
227 * @brief GET PEL priority from pHAL priority
228 *
229 * The pHAL callout priority is in different format than PEL format
230 * so, this api is used to return current phal supported priority into
231 * PEL expected format.
232 *
233 * @param[in] phalPriority used to pass phal priority format string
234 *
235 * @return pel priority format string else empty if failure
236 *
237 * @note For "NONE" returning "L" (LOW)
238 */
239static std::string getPelPriority(const std::string& phalPriority)
240{
241 const std::map<std::string, std::string> priorityMap = {
242 {"HIGH", "H"}, {"MEDIUM", "M"}, {"LOW", "L"}, {"NONE", "L"}};
243
244 auto it = priorityMap.find(phalPriority);
245 if (it == priorityMap.end())
246 {
247 log<level::ERR>(fmt::format("Unsupported phal priority({}) is given "
248 "to get pel priority format",
249 phalPriority)
250 .c_str());
251 return "H";
252 }
253
254 return it->second;
255}
256
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500257void processIplErrorCallback(const ipl_error_info& errInfo)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400258{
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500259 log<level::INFO>(
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500260 fmt::format("processIplErrorCallback: Error type({})", errInfo.type)
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500261 .c_str());
262
Jayanth Othayothee56c552021-09-10 01:44:05 -0500263 if (errInfo.type == IPL_ERR_OK)
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500264 {
265 // reset trace log and exit
266 reset();
267 return;
268 }
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500269
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500270 if ((errInfo.type == IPL_ERR_SBE_BOOT) ||
271 (errInfo.type == IPL_ERR_SBE_CHIPOP))
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500272 {
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500273 // handle SBE related failures.
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500274 processSbeBootError();
275 return;
276 }
277
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500278 if (errInfo.type == IPL_ERR_HWP)
279 {
280 // Handle hwp failure
281 processBootError(false);
282 return;
283 }
284
285 // Log PEL for any other failures
286 if (errInfo.type != IPL_ERR_OK)
287 {
288 createPEL("org.open_power.PHAL.Error.Boot");
289 // reset trace log and exit
290 reset();
291 return;
292 }
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500293}
294
295void processBootError(bool status)
296{
297 log<level::INFO>("processBootError ", entry("STATUS=%d", status));
Brad Bishopf6783cd2020-10-27 19:25:09 -0400298 try
299 {
300 // return If no failure during hwp execution
301 if (status)
302 return;
303
304 // Collecting ffdc details from phal
305 FFDC ffdc;
306 libekb_get_ffdc(ffdc);
307
Ramesh Iyyar3af83eb2020-11-19 23:11:38 -0600308 log<level::INFO>(
309 fmt::format("PHAL FFDC: Return Message[{}]", ffdc.message).c_str());
Brad Bishopf6783cd2020-10-27 19:25:09 -0400310
311 // To store callouts details in json format as per pel expectation.
312 json jsonCalloutDataList;
313 jsonCalloutDataList = json::array();
314
315 // To store phal trace and other additional data about ffdc.
316 FFDCData pelAdditionalData;
317
318 if (ffdc.ffdc_type == FFDC_TYPE_HWP)
319 {
320 // Adding hardware procedures return code details
321 pelAdditionalData.emplace_back("HWP_RC", ffdc.hwp_errorinfo.rc);
322 pelAdditionalData.emplace_back("HWP_RC_DESC",
323 ffdc.hwp_errorinfo.rc_desc);
324
325 // Adding hardware procedures required ffdc data for debug
326 for_each(ffdc.hwp_errorinfo.ffdcs_data.begin(),
327 ffdc.hwp_errorinfo.ffdcs_data.end(),
328 [&pelAdditionalData](
329 std::pair<std::string, std::string>& ele) -> void {
330 std::string keyWithPrefix("HWP_FFDC_");
331 keyWithPrefix.append(ele.first);
332
333 pelAdditionalData.emplace_back(keyWithPrefix,
334 ele.second);
335 });
336
337 // Adding hardware callout details
338 int calloutCount = 0;
339 for_each(ffdc.hwp_errorinfo.hwcallouts.begin(),
340 ffdc.hwp_errorinfo.hwcallouts.end(),
341 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList](
342 const HWCallout& hwCallout) -> void {
343 calloutCount++;
344 std::stringstream keyPrefix;
345 keyPrefix << "HWP_HW_CO_" << std::setfill('0')
346 << std::setw(2) << calloutCount << "_";
347
348 pelAdditionalData.emplace_back(
349 std::string(keyPrefix.str()).append("HW_ID"),
350 hwCallout.hwid);
351
352 pelAdditionalData.emplace_back(
353 std::string(keyPrefix.str()).append("PRIORITY"),
354 hwCallout.callout_priority);
355
356 phal::TargetInfo targetInfo;
357 phal::getTgtReqAttrsVal(hwCallout.target_entity_path,
358 targetInfo);
359
360 std::string locationCode =
361 std::string(targetInfo.locationCode);
362 pelAdditionalData.emplace_back(
363 std::string(keyPrefix.str()).append("LOC_CODE"),
364 locationCode);
365
366 std::string physPath =
367 std::string(targetInfo.physDevPath);
368 pelAdditionalData.emplace_back(
369 std::string(keyPrefix.str()).append("PHYS_PATH"),
370 physPath);
371
372 pelAdditionalData.emplace_back(
373 std::string(keyPrefix.str()).append("CLK_POS"),
374 std::to_string(hwCallout.clkPos));
375
376 json jsonCalloutData;
377 jsonCalloutData["LocationCode"] = locationCode;
378 std::string pelPriority =
379 getPelPriority(hwCallout.callout_priority);
380 jsonCalloutData["Priority"] = pelPriority;
381
382 if (targetInfo.mruId != 0)
383 {
384 jsonCalloutData["MRUs"] = json::array({
385 {{"ID", targetInfo.mruId},
386 {"Priority", pelPriority}},
387 });
388 }
389
390 jsonCalloutDataList.emplace_back(jsonCalloutData);
391 });
392
393 // Adding CDG (callout, deconfigure and guard) targets details
394 calloutCount = 0;
395 for_each(ffdc.hwp_errorinfo.cdg_targets.begin(),
396 ffdc.hwp_errorinfo.cdg_targets.end(),
397 [&pelAdditionalData, &calloutCount,
398 &jsonCalloutDataList](const CDG_Target& cdg_tgt) -> void {
399 calloutCount++;
400 std::stringstream keyPrefix;
401 keyPrefix << "HWP_CDG_TGT_" << std::setfill('0')
402 << std::setw(2) << calloutCount << "_";
403
404 phal::TargetInfo targetInfo;
405 targetInfo.deconfigure = cdg_tgt.deconfigure;
406
407 phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path,
408 targetInfo);
409
410 std::string locationCode =
411 std::string(targetInfo.locationCode);
412 pelAdditionalData.emplace_back(
413 std::string(keyPrefix.str()).append("LOC_CODE"),
414 locationCode);
415 std::string physPath =
416 std::string(targetInfo.physDevPath);
417 pelAdditionalData.emplace_back(
418 std::string(keyPrefix.str()).append("PHYS_PATH"),
419 physPath);
420
421 pelAdditionalData.emplace_back(
422 std::string(keyPrefix.str()).append("CO_REQ"),
423 (cdg_tgt.callout == true ? "true" : "false"));
424
425 pelAdditionalData.emplace_back(
426 std::string(keyPrefix.str()).append("CO_PRIORITY"),
427 cdg_tgt.callout_priority);
428
429 pelAdditionalData.emplace_back(
430 std::string(keyPrefix.str()).append("DECONF_REQ"),
431 (cdg_tgt.deconfigure == true ? "true" : "false"));
432
433 pelAdditionalData.emplace_back(
434 std::string(keyPrefix.str()).append("GUARD_REQ"),
435 (cdg_tgt.guard == true ? "true" : "false"));
436
437 pelAdditionalData.emplace_back(
438 std::string(keyPrefix.str()).append("GUARD_TYPE"),
439 cdg_tgt.guard_type);
440
441 json jsonCalloutData;
442 jsonCalloutData["LocationCode"] = locationCode;
443 std::string pelPriority =
444 getPelPriority(cdg_tgt.callout_priority);
445 jsonCalloutData["Priority"] = pelPriority;
446
447 if (targetInfo.mruId != 0)
448 {
449 jsonCalloutData["MRUs"] = json::array({
450 {{"ID", targetInfo.mruId},
451 {"Priority", pelPriority}},
452 });
453 }
454 jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure;
455 jsonCalloutData["Guarded"] = cdg_tgt.guard;
Jayanth Othayoth9883ed52021-11-12 02:55:49 -0600456 jsonCalloutData["GuardType"] = cdg_tgt.guard_type;
457 jsonCalloutData["EntityPath"] =
458 cdg_tgt.target_entity_path;
Brad Bishopf6783cd2020-10-27 19:25:09 -0400459
460 jsonCalloutDataList.emplace_back(jsonCalloutData);
461 });
462 }
Ramesh Iyyar3af83eb2020-11-19 23:11:38 -0600463 else if ((ffdc.ffdc_type != FFDC_TYPE_NONE) &&
Brad Bishopf6783cd2020-10-27 19:25:09 -0400464 (ffdc.ffdc_type != FFDC_TYPE_UNSUPPORTED))
465 {
466 log<level::ERR>(
467 fmt::format("Unsupported phal FFDC type to create PEL. "
468 "MSG: {}",
469 ffdc.message)
470 .c_str());
471 }
472
473 // Adding collected phal logs into PEL additional data
474 for_each(traceLog.begin(), traceLog.end(),
475 [&pelAdditionalData](
476 std::pair<std::string, std::string>& ele) -> void {
477 pelAdditionalData.emplace_back(ele.first, ele.second);
478 });
479
480 // TODO: #ibm-openbmc/dev/issues/2595 : Once enabled this support,
481 // callout details is not required to sort in H,M and L orders which
482 // are expected by pel because, pel will take care for sorting callouts
483 // based on priority so, now adding support to send callout in order
484 // i.e High -> Medium -> Low.
485 std::sort(
486 jsonCalloutDataList.begin(), jsonCalloutDataList.end(),
487 [](const json& aEle, const json& bEle) -> bool {
488 // Considering b element having higher priority than a element
489 // or Both element will be same priorty (to keep same order
490 // which are given by phal when two callouts are having same
491 // priority)
492 if (((aEle["Priority"] == "M") && (bEle["Priority"] == "H")) ||
493 ((aEle["Priority"] == "L") &&
494 ((bEle["Priority"] == "H") ||
495 (bEle["Priority"] == "M"))) ||
496 (aEle["Priority"] == bEle["Priority"]))
497 {
498 return false;
499 }
500
501 // Considering a element having higher priority than b element
502 return true;
503 });
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -0600504 openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot",
505 jsonCalloutDataList, pelAdditionalData);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400506 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500507 catch (const std::exception& ex)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400508 {
509 reset();
510 throw ex;
511 }
512 reset();
513}
514
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500515void processSbeBootError()
516{
517 log<level::INFO>("processSbeBootError : Entered ");
518
519 using namespace openpower::phal::sbe;
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500520
521 // To store phal trace and other additional data about ffdc.
522 FFDCData pelAdditionalData;
523
524 // Adding collected phal logs into PEL additional data
525 for_each(
526 traceLog.begin(), traceLog.end(),
527 [&pelAdditionalData](std::pair<std::string, std::string>& ele) -> void {
528 pelAdditionalData.emplace_back(ele.first, ele.second);
529 });
530
531 // reset the trace log and counter
532 reset();
533
534 // get primary processor to collect FFDC/Dump information.
535 struct pdbg_target* procTarget;
536 pdbg_for_each_class_target("proc", procTarget)
537 {
538 if (openpower::phal::isPrimaryProc(procTarget))
539 break;
540 procTarget = nullptr;
541 }
542 // check valid primary processor is available
543 if (procTarget == nullptr)
544 {
545 log<level::ERR>("processSbeBootError: fail to get primary processor");
Jayanth Othayoth0a516de2021-11-14 09:59:06 -0600546 // Add BMC code callout and create PEL
547 json jsonCalloutDataList;
548 jsonCalloutDataList = json::array();
549 json jsonCalloutData;
550 jsonCalloutData["Procedure"] = "BMC0001";
551 jsonCalloutData["Priority"] = "H";
552 jsonCalloutDataList.emplace_back(jsonCalloutData);
553 openpower::pel::createErrorPEL(
554 "org.open_power.Processor.Error.SbeBootFailure",
555 jsonCalloutDataList);
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500556 return;
557 }
558 // SBE error object.
559 sbeError_t sbeError;
560 bool dumpIsRequired = false;
561
562 try
563 {
564 // Capture FFDC information on primary processor
565 sbeError = captureFFDC(procTarget);
566 }
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500567 catch (const phalError_t& phalError)
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500568 {
569 // Fail to collect FFDC information , trigger Dump
570 log<level::ERR>(
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500571 fmt::format("captureFFDC: Exception({})", phalError.what())
572 .c_str());
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500573 dumpIsRequired = true;
574 }
575
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500576 std::string event;
577
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500578 if ((sbeError.errType() == SBE_FFDC_NO_DATA) ||
579 (sbeError.errType() == SBE_CMD_TIMEOUT) || (dumpIsRequired))
580 {
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500581 event = "org.open_power.Processor.Error.SbeBootTimeout";
582 dumpIsRequired = true;
583 }
584 else
585 {
586 event = "org.open_power.Processor.Error.SbeBootFailure";
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500587 }
588 // SRC6 : [0:15] chip position
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500589 uint32_t index = pdbg_target_index(procTarget);
590 pelAdditionalData.emplace_back("SRC6", std::to_string(index << 16));
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500591 // Create SBE Error with FFDC data.
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500592 auto logId = createSbeErrorPEL(event, sbeError, pelAdditionalData);
593
594 if (dumpIsRequired)
595 {
596 using namespace openpower::phal::dump;
597 DumpParameters dumpParameters = {logId, index, SBE_DUMP_TIMEOUT,
598 DumpType::SBE};
599 try
600 {
601 requestDump(dumpParameters);
602 }
603 catch (const std::runtime_error& e)
604 {
605 // Allowing call back to handle the error gracefully.
606 log<level::ERR>("Dump collection failed");
607 // TODO revist error handling.
608 }
609 }
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500610}
611
Brad Bishopf6783cd2020-10-27 19:25:09 -0400612void reset()
613{
614 // reset the trace log and counter
615 traceLog.clear();
616 counter = 0;
617}
618
Brad Bishop63508a72020-10-27 18:55:01 -0400619void pDBGLogTraceCallbackHelper(int, const char* fmt, va_list ap)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400620{
621 processLogTraceCallback(NULL, fmt, ap);
622}
623} // namespace detail
624
625static inline uint8_t getLogLevelFromEnv(const char* env, const uint8_t dValue)
626{
627 auto logLevel = dValue;
628 try
629 {
630 if (const char* env_p = std::getenv(env))
631 {
632 logLevel = std::stoi(env_p);
633 }
634 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500635 catch (const std::exception& e)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400636 {
637 log<level::ERR>(("Conversion Failure"), entry("ENVIRONMENT=%s", env),
638 entry("EXCEPTION=%s", e.what()));
639 }
640 return logLevel;
641}
642
643void addBootErrorCallbacks()
644{
645 // Get individual phal repos log level from environment variable
646 // and update the log level.
647 pdbg_set_loglevel(getLogLevelFromEnv("PDBG_LOG", PDBG_INFO));
648 libekb_set_loglevel(getLogLevelFromEnv("LIBEKB_LOG", LIBEKB_LOG_IMP));
649 ipl_set_loglevel(getLogLevelFromEnv("IPL_LOG", IPL_INFO));
650
651 // add callback for debug traces
652 pdbg_set_logfunc(detail::pDBGLogTraceCallbackHelper);
653 libekb_set_logfunc(detail::processLogTraceCallback, NULL);
654 ipl_set_logfunc(detail::processLogTraceCallback, NULL);
655
656 // add callback for ipl failures
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500657 ipl_set_error_callback_func(detail::processIplErrorCallback);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400658}
659
660} // namespace pel
661} // namespace openpower