blob: 48209540e34e45319ab8153b4cb80e17c1e2fbf7 [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
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600198/**
199 * @brief Process platform realted boot failure
200 *
201 * @param[in] errInfo - error details
202 */
203static void processPlatBootError(const ipl_error_info& errInfo);
204
Brad Bishop63508a72020-10-27 18:55:01 -0400205void processLogTraceCallback(void*, const char* fmt, va_list ap)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400206{
207 va_list vap;
208 va_copy(vap, ap);
209 std::vector<char> logData(1 + std::vsnprintf(nullptr, 0, fmt, ap));
210 std::vsnprintf(logData.data(), logData.size(), fmt, vap);
211 va_end(vap);
212 std::string logstr(logData.begin(), logData.end());
213
214 log<level::INFO>(logstr.c_str());
215
216 char timeBuf[80];
217 time_t t = time(0);
218 tm myTm{};
219 gmtime_r(&t, &myTm);
220 strftime(timeBuf, 80, "%Y-%m-%d %H:%M:%S", &myTm);
221
222 // key values need to be unique for PEL
223 // TODO #openbmc/dev/issues/1563
224 // If written to Json no need to worry about unique KEY
225 std::stringstream str;
226 str << std::setfill('0');
227 str << "LOG" << std::setw(3) << counter;
228 str << " " << timeBuf;
229 traceLog.emplace_back(std::make_pair(str.str(), std::move(logstr)));
230 counter++;
231}
232
233/**
234 * @brief GET PEL priority from pHAL priority
235 *
236 * The pHAL callout priority is in different format than PEL format
237 * so, this api is used to return current phal supported priority into
238 * PEL expected format.
239 *
240 * @param[in] phalPriority used to pass phal priority format string
241 *
242 * @return pel priority format string else empty if failure
243 *
244 * @note For "NONE" returning "L" (LOW)
245 */
246static std::string getPelPriority(const std::string& phalPriority)
247{
248 const std::map<std::string, std::string> priorityMap = {
249 {"HIGH", "H"}, {"MEDIUM", "M"}, {"LOW", "L"}, {"NONE", "L"}};
250
251 auto it = priorityMap.find(phalPriority);
252 if (it == priorityMap.end())
253 {
254 log<level::ERR>(fmt::format("Unsupported phal priority({}) is given "
255 "to get pel priority format",
256 phalPriority)
257 .c_str());
258 return "H";
259 }
260
261 return it->second;
262}
263
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500264void processIplErrorCallback(const ipl_error_info& errInfo)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400265{
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500266 log<level::INFO>(
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500267 fmt::format("processIplErrorCallback: Error type({})", errInfo.type)
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500268 .c_str());
269
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600270 switch (errInfo.type)
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500271 {
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600272 case IPL_ERR_OK:
273 // reset trace log and exit
274 reset();
275 break;
276 case IPL_ERR_SBE_BOOT:
277 case IPL_ERR_SBE_CHIPOP:
278 // handle SBE related failures.
279 processSbeBootError();
280 break;
281 case IPL_ERR_HWP:
282 // Handle hwp failure
283 processBootError(false);
284 break;
285 case IPL_ERR_PLAT:
286 processPlatBootError(errInfo);
287 break;
288 default:
289 createPEL("org.open_power.PHAL.Error.Boot");
290 // reset trace log and exit
291 reset();
292 break;
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500293 }
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500294}
295
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600296void processBootErrorHelper(FFDC* ffdc)
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500297{
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600298 log<level::INFO>("processBootErrorHelper ");
Brad Bishopf6783cd2020-10-27 19:25:09 -0400299 try
300 {
Ramesh Iyyar3af83eb2020-11-19 23:11:38 -0600301 log<level::INFO>(
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600302 fmt::format("PHAL FFDC: Return Message[{}]", ffdc->message)
303 .c_str());
Brad Bishopf6783cd2020-10-27 19:25:09 -0400304
305 // To store callouts details in json format as per pel expectation.
306 json jsonCalloutDataList;
307 jsonCalloutDataList = json::array();
308
309 // To store phal trace and other additional data about ffdc.
310 FFDCData pelAdditionalData;
311
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600312 if (ffdc->ffdc_type == FFDC_TYPE_HWP)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400313 {
314 // Adding hardware procedures return code details
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600315 pelAdditionalData.emplace_back("HWP_RC", ffdc->hwp_errorinfo.rc);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400316 pelAdditionalData.emplace_back("HWP_RC_DESC",
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600317 ffdc->hwp_errorinfo.rc_desc);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400318
319 // Adding hardware procedures required ffdc data for debug
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600320 for_each(ffdc->hwp_errorinfo.ffdcs_data.begin(),
321 ffdc->hwp_errorinfo.ffdcs_data.end(),
Brad Bishopf6783cd2020-10-27 19:25:09 -0400322 [&pelAdditionalData](
323 std::pair<std::string, std::string>& ele) -> void {
324 std::string keyWithPrefix("HWP_FFDC_");
325 keyWithPrefix.append(ele.first);
326
327 pelAdditionalData.emplace_back(keyWithPrefix,
328 ele.second);
329 });
330
331 // Adding hardware callout details
332 int calloutCount = 0;
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600333 for_each(ffdc->hwp_errorinfo.hwcallouts.begin(),
334 ffdc->hwp_errorinfo.hwcallouts.end(),
Brad Bishopf6783cd2020-10-27 19:25:09 -0400335 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList](
336 const HWCallout& hwCallout) -> void {
337 calloutCount++;
338 std::stringstream keyPrefix;
339 keyPrefix << "HWP_HW_CO_" << std::setfill('0')
340 << std::setw(2) << calloutCount << "_";
341
342 pelAdditionalData.emplace_back(
343 std::string(keyPrefix.str()).append("HW_ID"),
344 hwCallout.hwid);
345
346 pelAdditionalData.emplace_back(
347 std::string(keyPrefix.str()).append("PRIORITY"),
348 hwCallout.callout_priority);
349
350 phal::TargetInfo targetInfo;
351 phal::getTgtReqAttrsVal(hwCallout.target_entity_path,
352 targetInfo);
353
354 std::string locationCode =
355 std::string(targetInfo.locationCode);
356 pelAdditionalData.emplace_back(
357 std::string(keyPrefix.str()).append("LOC_CODE"),
358 locationCode);
359
360 std::string physPath =
361 std::string(targetInfo.physDevPath);
362 pelAdditionalData.emplace_back(
363 std::string(keyPrefix.str()).append("PHYS_PATH"),
364 physPath);
365
366 pelAdditionalData.emplace_back(
367 std::string(keyPrefix.str()).append("CLK_POS"),
368 std::to_string(hwCallout.clkPos));
369
370 json jsonCalloutData;
371 jsonCalloutData["LocationCode"] = locationCode;
372 std::string pelPriority =
373 getPelPriority(hwCallout.callout_priority);
374 jsonCalloutData["Priority"] = pelPriority;
375
376 if (targetInfo.mruId != 0)
377 {
378 jsonCalloutData["MRUs"] = json::array({
379 {{"ID", targetInfo.mruId},
380 {"Priority", pelPriority}},
381 });
382 }
383
384 jsonCalloutDataList.emplace_back(jsonCalloutData);
385 });
386
387 // Adding CDG (callout, deconfigure and guard) targets details
388 calloutCount = 0;
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600389 for_each(ffdc->hwp_errorinfo.cdg_targets.begin(),
390 ffdc->hwp_errorinfo.cdg_targets.end(),
Brad Bishopf6783cd2020-10-27 19:25:09 -0400391 [&pelAdditionalData, &calloutCount,
392 &jsonCalloutDataList](const CDG_Target& cdg_tgt) -> void {
393 calloutCount++;
394 std::stringstream keyPrefix;
395 keyPrefix << "HWP_CDG_TGT_" << std::setfill('0')
396 << std::setw(2) << calloutCount << "_";
397
398 phal::TargetInfo targetInfo;
399 targetInfo.deconfigure = cdg_tgt.deconfigure;
400
401 phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path,
402 targetInfo);
403
404 std::string locationCode =
405 std::string(targetInfo.locationCode);
406 pelAdditionalData.emplace_back(
407 std::string(keyPrefix.str()).append("LOC_CODE"),
408 locationCode);
409 std::string physPath =
410 std::string(targetInfo.physDevPath);
411 pelAdditionalData.emplace_back(
412 std::string(keyPrefix.str()).append("PHYS_PATH"),
413 physPath);
414
415 pelAdditionalData.emplace_back(
416 std::string(keyPrefix.str()).append("CO_REQ"),
417 (cdg_tgt.callout == true ? "true" : "false"));
418
419 pelAdditionalData.emplace_back(
420 std::string(keyPrefix.str()).append("CO_PRIORITY"),
421 cdg_tgt.callout_priority);
422
423 pelAdditionalData.emplace_back(
424 std::string(keyPrefix.str()).append("DECONF_REQ"),
425 (cdg_tgt.deconfigure == true ? "true" : "false"));
426
427 pelAdditionalData.emplace_back(
428 std::string(keyPrefix.str()).append("GUARD_REQ"),
429 (cdg_tgt.guard == true ? "true" : "false"));
430
431 pelAdditionalData.emplace_back(
432 std::string(keyPrefix.str()).append("GUARD_TYPE"),
433 cdg_tgt.guard_type);
434
435 json jsonCalloutData;
436 jsonCalloutData["LocationCode"] = locationCode;
437 std::string pelPriority =
438 getPelPriority(cdg_tgt.callout_priority);
439 jsonCalloutData["Priority"] = pelPriority;
440
441 if (targetInfo.mruId != 0)
442 {
443 jsonCalloutData["MRUs"] = json::array({
444 {{"ID", targetInfo.mruId},
445 {"Priority", pelPriority}},
446 });
447 }
448 jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure;
449 jsonCalloutData["Guarded"] = cdg_tgt.guard;
Jayanth Othayoth9883ed52021-11-12 02:55:49 -0600450 jsonCalloutData["GuardType"] = cdg_tgt.guard_type;
451 jsonCalloutData["EntityPath"] =
452 cdg_tgt.target_entity_path;
Brad Bishopf6783cd2020-10-27 19:25:09 -0400453
454 jsonCalloutDataList.emplace_back(jsonCalloutData);
455 });
Jayanth Othayoth0ac7c382021-11-15 05:43:24 -0600456 // Adding procedure callout
457 calloutCount = 0;
458 for_each(
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600459 ffdc->hwp_errorinfo.procedures_callout.begin(),
460 ffdc->hwp_errorinfo.procedures_callout.end(),
Jayanth Othayoth0ac7c382021-11-15 05:43:24 -0600461 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList](
462 const ProcedureCallout& procCallout) -> void {
463 calloutCount++;
464 std::stringstream keyPrefix;
465 keyPrefix << "HWP_PROC_CO_" << std::setfill('0')
466 << std::setw(2) << calloutCount << "_";
467
468 pelAdditionalData.emplace_back(
469 std::string(keyPrefix.str()).append("PRIORITY"),
470 procCallout.callout_priority);
471
472 pelAdditionalData.emplace_back(
473 std::string(keyPrefix.str()).append("MAINT_PROCEDURE"),
474 procCallout.proc_callout);
475
476 json jsonCalloutData;
477 jsonCalloutData["Procedure"] = procCallout.proc_callout;
478 std::string pelPriority =
479 getPelPriority(procCallout.callout_priority);
480 jsonCalloutData["Priority"] = pelPriority;
481 jsonCalloutDataList.emplace_back(jsonCalloutData);
482 });
Brad Bishopf6783cd2020-10-27 19:25:09 -0400483 }
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600484 else if ((ffdc->ffdc_type != FFDC_TYPE_NONE) &&
485 (ffdc->ffdc_type != FFDC_TYPE_UNSUPPORTED))
Brad Bishopf6783cd2020-10-27 19:25:09 -0400486 {
487 log<level::ERR>(
488 fmt::format("Unsupported phal FFDC type to create PEL. "
489 "MSG: {}",
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600490 ffdc->message)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400491 .c_str());
492 }
493
494 // Adding collected phal logs into PEL additional data
495 for_each(traceLog.begin(), traceLog.end(),
496 [&pelAdditionalData](
497 std::pair<std::string, std::string>& ele) -> void {
498 pelAdditionalData.emplace_back(ele.first, ele.second);
499 });
500
501 // TODO: #ibm-openbmc/dev/issues/2595 : Once enabled this support,
502 // callout details is not required to sort in H,M and L orders which
503 // are expected by pel because, pel will take care for sorting callouts
504 // based on priority so, now adding support to send callout in order
505 // i.e High -> Medium -> Low.
506 std::sort(
507 jsonCalloutDataList.begin(), jsonCalloutDataList.end(),
508 [](const json& aEle, const json& bEle) -> bool {
509 // Considering b element having higher priority than a element
510 // or Both element will be same priorty (to keep same order
511 // which are given by phal when two callouts are having same
512 // priority)
513 if (((aEle["Priority"] == "M") && (bEle["Priority"] == "H")) ||
514 ((aEle["Priority"] == "L") &&
515 ((bEle["Priority"] == "H") ||
516 (bEle["Priority"] == "M"))) ||
517 (aEle["Priority"] == bEle["Priority"]))
518 {
519 return false;
520 }
521
522 // Considering a element having higher priority than b element
523 return true;
524 });
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -0600525 openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot",
526 jsonCalloutDataList, pelAdditionalData);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400527 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500528 catch (const std::exception& ex)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400529 {
530 reset();
531 throw ex;
532 }
533 reset();
534}
535
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600536void processPlatBootError(const ipl_error_info& errInfo)
537{
538 log<level::INFO>("processPlatBootError ");
539
540 // Collecting ffdc details from phal
541 FFDC* ffdc = reinterpret_cast<FFDC*>(errInfo.private_data);
542 try
543 {
544 processBootErrorHelper(ffdc);
545 }
546 catch (const std::exception& ex)
547 {
548 log<level::ERR>(
549 fmt::format("processPlatBootError: exception({})", ex.what())
550 .c_str());
551 throw ex;
552 }
553}
554
555void processBootError(bool status)
556{
557 log<level::INFO>(
558 fmt::format("processBootError: status({})", status).c_str());
559
560 try
561 {
562 // return If no failure during hwp execution
563 if (status)
564 return;
565
566 // Collecting ffdc details from phal
567 FFDC ffdc;
568 libekb_get_ffdc(ffdc);
569
570 processBootErrorHelper(&ffdc);
571 }
572 catch (const std::exception& ex)
573 {
574 log<level::ERR>(
575 fmt::format("processBootError: exception({})", ex.what()).c_str());
576 throw ex;
577 }
578}
579
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500580void processSbeBootError()
581{
582 log<level::INFO>("processSbeBootError : Entered ");
583
584 using namespace openpower::phal::sbe;
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500585
586 // To store phal trace and other additional data about ffdc.
587 FFDCData pelAdditionalData;
588
589 // Adding collected phal logs into PEL additional data
590 for_each(
591 traceLog.begin(), traceLog.end(),
592 [&pelAdditionalData](std::pair<std::string, std::string>& ele) -> void {
593 pelAdditionalData.emplace_back(ele.first, ele.second);
594 });
595
596 // reset the trace log and counter
597 reset();
598
599 // get primary processor to collect FFDC/Dump information.
600 struct pdbg_target* procTarget;
601 pdbg_for_each_class_target("proc", procTarget)
602 {
603 if (openpower::phal::isPrimaryProc(procTarget))
604 break;
605 procTarget = nullptr;
606 }
607 // check valid primary processor is available
608 if (procTarget == nullptr)
609 {
610 log<level::ERR>("processSbeBootError: fail to get primary processor");
Jayanth Othayoth0a516de2021-11-14 09:59:06 -0600611 // Add BMC code callout and create PEL
612 json jsonCalloutDataList;
613 jsonCalloutDataList = json::array();
614 json jsonCalloutData;
615 jsonCalloutData["Procedure"] = "BMC0001";
616 jsonCalloutData["Priority"] = "H";
617 jsonCalloutDataList.emplace_back(jsonCalloutData);
618 openpower::pel::createErrorPEL(
619 "org.open_power.Processor.Error.SbeBootFailure",
620 jsonCalloutDataList);
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500621 return;
622 }
623 // SBE error object.
624 sbeError_t sbeError;
625 bool dumpIsRequired = false;
626
627 try
628 {
629 // Capture FFDC information on primary processor
630 sbeError = captureFFDC(procTarget);
631 }
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500632 catch (const phalError_t& phalError)
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500633 {
634 // Fail to collect FFDC information , trigger Dump
635 log<level::ERR>(
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500636 fmt::format("captureFFDC: Exception({})", phalError.what())
637 .c_str());
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500638 dumpIsRequired = true;
639 }
640
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500641 std::string event;
642
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500643 if ((sbeError.errType() == SBE_FFDC_NO_DATA) ||
644 (sbeError.errType() == SBE_CMD_TIMEOUT) || (dumpIsRequired))
645 {
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500646 event = "org.open_power.Processor.Error.SbeBootTimeout";
647 dumpIsRequired = true;
648 }
649 else
650 {
651 event = "org.open_power.Processor.Error.SbeBootFailure";
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500652 }
653 // SRC6 : [0:15] chip position
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500654 uint32_t index = pdbg_target_index(procTarget);
655 pelAdditionalData.emplace_back("SRC6", std::to_string(index << 16));
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500656 // Create SBE Error with FFDC data.
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500657 auto logId = createSbeErrorPEL(event, sbeError, pelAdditionalData);
658
659 if (dumpIsRequired)
660 {
661 using namespace openpower::phal::dump;
662 DumpParameters dumpParameters = {logId, index, SBE_DUMP_TIMEOUT,
663 DumpType::SBE};
664 try
665 {
666 requestDump(dumpParameters);
667 }
668 catch (const std::runtime_error& e)
669 {
670 // Allowing call back to handle the error gracefully.
671 log<level::ERR>("Dump collection failed");
672 // TODO revist error handling.
673 }
674 }
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500675}
676
Brad Bishopf6783cd2020-10-27 19:25:09 -0400677void reset()
678{
679 // reset the trace log and counter
680 traceLog.clear();
681 counter = 0;
682}
683
Brad Bishop63508a72020-10-27 18:55:01 -0400684void pDBGLogTraceCallbackHelper(int, const char* fmt, va_list ap)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400685{
686 processLogTraceCallback(NULL, fmt, ap);
687}
688} // namespace detail
689
690static inline uint8_t getLogLevelFromEnv(const char* env, const uint8_t dValue)
691{
692 auto logLevel = dValue;
693 try
694 {
695 if (const char* env_p = std::getenv(env))
696 {
697 logLevel = std::stoi(env_p);
698 }
699 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500700 catch (const std::exception& e)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400701 {
702 log<level::ERR>(("Conversion Failure"), entry("ENVIRONMENT=%s", env),
703 entry("EXCEPTION=%s", e.what()));
704 }
705 return logLevel;
706}
707
708void addBootErrorCallbacks()
709{
710 // Get individual phal repos log level from environment variable
711 // and update the log level.
712 pdbg_set_loglevel(getLogLevelFromEnv("PDBG_LOG", PDBG_INFO));
713 libekb_set_loglevel(getLogLevelFromEnv("LIBEKB_LOG", LIBEKB_LOG_IMP));
714 ipl_set_loglevel(getLogLevelFromEnv("IPL_LOG", IPL_INFO));
715
716 // add callback for debug traces
717 pdbg_set_logfunc(detail::pDBGLogTraceCallbackHelper);
718 libekb_set_logfunc(detail::processLogTraceCallback, NULL);
719 ipl_set_logfunc(detail::processLogTraceCallback, NULL);
720
721 // add callback for ipl failures
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500722 ipl_set_error_callback_func(detail::processIplErrorCallback);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400723}
724
725} // namespace pel
726} // namespace openpower