blob: 27f9067ca6ef03e4e1d33fb2c4f35b8dee6bc857 [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));
Brad Bishopf6783cd2020-10-27 19:25:09 -0400369 });
370
371 // Adding CDG (callout, deconfigure and guard) targets details
372 calloutCount = 0;
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600373 for_each(ffdc->hwp_errorinfo.cdg_targets.begin(),
374 ffdc->hwp_errorinfo.cdg_targets.end(),
Brad Bishopf6783cd2020-10-27 19:25:09 -0400375 [&pelAdditionalData, &calloutCount,
376 &jsonCalloutDataList](const CDG_Target& cdg_tgt) -> void {
377 calloutCount++;
378 std::stringstream keyPrefix;
379 keyPrefix << "HWP_CDG_TGT_" << std::setfill('0')
380 << std::setw(2) << calloutCount << "_";
381
382 phal::TargetInfo targetInfo;
383 targetInfo.deconfigure = cdg_tgt.deconfigure;
384
385 phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path,
386 targetInfo);
387
388 std::string locationCode =
389 std::string(targetInfo.locationCode);
390 pelAdditionalData.emplace_back(
391 std::string(keyPrefix.str()).append("LOC_CODE"),
392 locationCode);
393 std::string physPath =
394 std::string(targetInfo.physDevPath);
395 pelAdditionalData.emplace_back(
396 std::string(keyPrefix.str()).append("PHYS_PATH"),
397 physPath);
398
399 pelAdditionalData.emplace_back(
400 std::string(keyPrefix.str()).append("CO_REQ"),
401 (cdg_tgt.callout == true ? "true" : "false"));
402
403 pelAdditionalData.emplace_back(
404 std::string(keyPrefix.str()).append("CO_PRIORITY"),
405 cdg_tgt.callout_priority);
406
407 pelAdditionalData.emplace_back(
408 std::string(keyPrefix.str()).append("DECONF_REQ"),
409 (cdg_tgt.deconfigure == true ? "true" : "false"));
410
411 pelAdditionalData.emplace_back(
412 std::string(keyPrefix.str()).append("GUARD_REQ"),
413 (cdg_tgt.guard == true ? "true" : "false"));
414
415 pelAdditionalData.emplace_back(
416 std::string(keyPrefix.str()).append("GUARD_TYPE"),
417 cdg_tgt.guard_type);
418
419 json jsonCalloutData;
420 jsonCalloutData["LocationCode"] = locationCode;
421 std::string pelPriority =
422 getPelPriority(cdg_tgt.callout_priority);
423 jsonCalloutData["Priority"] = pelPriority;
424
425 if (targetInfo.mruId != 0)
426 {
427 jsonCalloutData["MRUs"] = json::array({
428 {{"ID", targetInfo.mruId},
429 {"Priority", pelPriority}},
430 });
431 }
432 jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure;
433 jsonCalloutData["Guarded"] = cdg_tgt.guard;
Jayanth Othayoth9883ed52021-11-12 02:55:49 -0600434 jsonCalloutData["GuardType"] = cdg_tgt.guard_type;
435 jsonCalloutData["EntityPath"] =
436 cdg_tgt.target_entity_path;
Brad Bishopf6783cd2020-10-27 19:25:09 -0400437
438 jsonCalloutDataList.emplace_back(jsonCalloutData);
439 });
Jayanth Othayoth0ac7c382021-11-15 05:43:24 -0600440 // Adding procedure callout
441 calloutCount = 0;
442 for_each(
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600443 ffdc->hwp_errorinfo.procedures_callout.begin(),
444 ffdc->hwp_errorinfo.procedures_callout.end(),
Jayanth Othayoth0ac7c382021-11-15 05:43:24 -0600445 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList](
446 const ProcedureCallout& procCallout) -> void {
447 calloutCount++;
448 std::stringstream keyPrefix;
449 keyPrefix << "HWP_PROC_CO_" << std::setfill('0')
450 << std::setw(2) << calloutCount << "_";
451
452 pelAdditionalData.emplace_back(
453 std::string(keyPrefix.str()).append("PRIORITY"),
454 procCallout.callout_priority);
455
456 pelAdditionalData.emplace_back(
457 std::string(keyPrefix.str()).append("MAINT_PROCEDURE"),
458 procCallout.proc_callout);
459
460 json jsonCalloutData;
461 jsonCalloutData["Procedure"] = procCallout.proc_callout;
462 std::string pelPriority =
463 getPelPriority(procCallout.callout_priority);
464 jsonCalloutData["Priority"] = pelPriority;
465 jsonCalloutDataList.emplace_back(jsonCalloutData);
466 });
Brad Bishopf6783cd2020-10-27 19:25:09 -0400467 }
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600468 else if ((ffdc->ffdc_type != FFDC_TYPE_NONE) &&
469 (ffdc->ffdc_type != FFDC_TYPE_UNSUPPORTED))
Brad Bishopf6783cd2020-10-27 19:25:09 -0400470 {
471 log<level::ERR>(
472 fmt::format("Unsupported phal FFDC type to create PEL. "
473 "MSG: {}",
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600474 ffdc->message)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400475 .c_str());
476 }
477
478 // Adding collected phal logs into PEL additional data
479 for_each(traceLog.begin(), traceLog.end(),
480 [&pelAdditionalData](
481 std::pair<std::string, std::string>& ele) -> void {
482 pelAdditionalData.emplace_back(ele.first, ele.second);
483 });
484
485 // TODO: #ibm-openbmc/dev/issues/2595 : Once enabled this support,
486 // callout details is not required to sort in H,M and L orders which
487 // are expected by pel because, pel will take care for sorting callouts
488 // based on priority so, now adding support to send callout in order
489 // i.e High -> Medium -> Low.
490 std::sort(
491 jsonCalloutDataList.begin(), jsonCalloutDataList.end(),
492 [](const json& aEle, const json& bEle) -> bool {
493 // Considering b element having higher priority than a element
494 // or Both element will be same priorty (to keep same order
495 // which are given by phal when two callouts are having same
496 // priority)
497 if (((aEle["Priority"] == "M") && (bEle["Priority"] == "H")) ||
498 ((aEle["Priority"] == "L") &&
499 ((bEle["Priority"] == "H") ||
500 (bEle["Priority"] == "M"))) ||
501 (aEle["Priority"] == bEle["Priority"]))
502 {
503 return false;
504 }
505
506 // Considering a element having higher priority than b element
507 return true;
508 });
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -0600509 openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot",
510 jsonCalloutDataList, pelAdditionalData);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400511 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500512 catch (const std::exception& ex)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400513 {
514 reset();
515 throw ex;
516 }
517 reset();
518}
519
Marri Devender Rao381c3e32021-12-01 06:27:55 -0600520void processPlatBootError(const ipl_error_info& errInfo)
521{
522 log<level::INFO>("processPlatBootError ");
523
524 // Collecting ffdc details from phal
525 FFDC* ffdc = reinterpret_cast<FFDC*>(errInfo.private_data);
526 try
527 {
528 processBootErrorHelper(ffdc);
529 }
530 catch (const std::exception& ex)
531 {
532 log<level::ERR>(
533 fmt::format("processPlatBootError: exception({})", ex.what())
534 .c_str());
535 throw ex;
536 }
537}
538
539void processBootError(bool status)
540{
541 log<level::INFO>(
542 fmt::format("processBootError: status({})", status).c_str());
543
544 try
545 {
546 // return If no failure during hwp execution
547 if (status)
548 return;
549
550 // Collecting ffdc details from phal
551 FFDC ffdc;
552 libekb_get_ffdc(ffdc);
553
554 processBootErrorHelper(&ffdc);
555 }
556 catch (const std::exception& ex)
557 {
558 log<level::ERR>(
559 fmt::format("processBootError: exception({})", ex.what()).c_str());
560 throw ex;
561 }
562}
563
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500564void processSbeBootError()
565{
566 log<level::INFO>("processSbeBootError : Entered ");
567
568 using namespace openpower::phal::sbe;
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500569
570 // To store phal trace and other additional data about ffdc.
571 FFDCData pelAdditionalData;
572
573 // Adding collected phal logs into PEL additional data
574 for_each(
575 traceLog.begin(), traceLog.end(),
576 [&pelAdditionalData](std::pair<std::string, std::string>& ele) -> void {
577 pelAdditionalData.emplace_back(ele.first, ele.second);
578 });
579
580 // reset the trace log and counter
581 reset();
582
583 // get primary processor to collect FFDC/Dump information.
584 struct pdbg_target* procTarget;
585 pdbg_for_each_class_target("proc", procTarget)
586 {
587 if (openpower::phal::isPrimaryProc(procTarget))
588 break;
589 procTarget = nullptr;
590 }
591 // check valid primary processor is available
592 if (procTarget == nullptr)
593 {
594 log<level::ERR>("processSbeBootError: fail to get primary processor");
Jayanth Othayoth0a516de2021-11-14 09:59:06 -0600595 // Add BMC code callout and create PEL
596 json jsonCalloutDataList;
597 jsonCalloutDataList = json::array();
598 json jsonCalloutData;
599 jsonCalloutData["Procedure"] = "BMC0001";
600 jsonCalloutData["Priority"] = "H";
601 jsonCalloutDataList.emplace_back(jsonCalloutData);
602 openpower::pel::createErrorPEL(
603 "org.open_power.Processor.Error.SbeBootFailure",
604 jsonCalloutDataList);
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500605 return;
606 }
607 // SBE error object.
608 sbeError_t sbeError;
609 bool dumpIsRequired = false;
610
611 try
612 {
613 // Capture FFDC information on primary processor
614 sbeError = captureFFDC(procTarget);
615 }
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500616 catch (const phalError_t& phalError)
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500617 {
618 // Fail to collect FFDC information , trigger Dump
619 log<level::ERR>(
Jayanth Othayothfaaef2a2021-10-08 06:49:36 -0500620 fmt::format("captureFFDC: Exception({})", phalError.what())
621 .c_str());
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500622 dumpIsRequired = true;
623 }
624
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500625 std::string event;
626
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500627 if ((sbeError.errType() == SBE_FFDC_NO_DATA) ||
628 (sbeError.errType() == SBE_CMD_TIMEOUT) || (dumpIsRequired))
629 {
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500630 event = "org.open_power.Processor.Error.SbeBootTimeout";
631 dumpIsRequired = true;
632 }
633 else
634 {
635 event = "org.open_power.Processor.Error.SbeBootFailure";
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500636 }
637 // SRC6 : [0:15] chip position
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500638 uint32_t index = pdbg_target_index(procTarget);
639 pelAdditionalData.emplace_back("SRC6", std::to_string(index << 16));
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500640 // Create SBE Error with FFDC data.
Jayanth Othayoth006641e2021-10-07 06:56:24 -0500641 auto logId = createSbeErrorPEL(event, sbeError, pelAdditionalData);
642
643 if (dumpIsRequired)
644 {
645 using namespace openpower::phal::dump;
646 DumpParameters dumpParameters = {logId, index, SBE_DUMP_TIMEOUT,
647 DumpType::SBE};
648 try
649 {
650 requestDump(dumpParameters);
651 }
652 catch (const std::runtime_error& e)
653 {
654 // Allowing call back to handle the error gracefully.
655 log<level::ERR>("Dump collection failed");
656 // TODO revist error handling.
657 }
658 }
Jayanth Othayoth4079f092021-09-20 07:36:54 -0500659}
660
Brad Bishopf6783cd2020-10-27 19:25:09 -0400661void reset()
662{
663 // reset the trace log and counter
664 traceLog.clear();
665 counter = 0;
666}
667
Brad Bishop63508a72020-10-27 18:55:01 -0400668void pDBGLogTraceCallbackHelper(int, const char* fmt, va_list ap)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400669{
670 processLogTraceCallback(NULL, fmt, ap);
671}
672} // namespace detail
673
674static inline uint8_t getLogLevelFromEnv(const char* env, const uint8_t dValue)
675{
676 auto logLevel = dValue;
677 try
678 {
679 if (const char* env_p = std::getenv(env))
680 {
681 logLevel = std::stoi(env_p);
682 }
683 }
Patrick Williams1a9a5a62021-10-06 13:05:06 -0500684 catch (const std::exception& e)
Brad Bishopf6783cd2020-10-27 19:25:09 -0400685 {
686 log<level::ERR>(("Conversion Failure"), entry("ENVIRONMENT=%s", env),
687 entry("EXCEPTION=%s", e.what()));
688 }
689 return logLevel;
690}
691
692void addBootErrorCallbacks()
693{
694 // Get individual phal repos log level from environment variable
695 // and update the log level.
696 pdbg_set_loglevel(getLogLevelFromEnv("PDBG_LOG", PDBG_INFO));
697 libekb_set_loglevel(getLogLevelFromEnv("LIBEKB_LOG", LIBEKB_LOG_IMP));
698 ipl_set_loglevel(getLogLevelFromEnv("IPL_LOG", IPL_INFO));
699
700 // add callback for debug traces
701 pdbg_set_logfunc(detail::pDBGLogTraceCallbackHelper);
702 libekb_set_logfunc(detail::processLogTraceCallback, NULL);
703 ipl_set_logfunc(detail::processLogTraceCallback, NULL);
704
705 // add callback for ipl failures
Jayanth Othayoth2b211702021-09-06 05:14:23 -0500706 ipl_set_error_callback_func(detail::processIplErrorCallback);
Brad Bishopf6783cd2020-10-27 19:25:09 -0400707}
708
709} // namespace pel
710} // namespace openpower