xref: /openbmc/phosphor-logging/extensions/openpower-pels/fapi_data_process.cpp (revision 075c79237505ea3b810a461f5f514e4d520a0c44)
12544b419SPatrick Williams extern "C"
22544b419SPatrick Williams {
34d779b2cSJayanth Othayoth #include <libpdbg.h>
44d779b2cSJayanth Othayoth }
54d779b2cSJayanth Othayoth 
64d779b2cSJayanth Othayoth #include "fapi_data_process.hpp"
74d779b2cSJayanth Othayoth 
84d779b2cSJayanth Othayoth #include <attributes_info.H>
9417b88eaSJayanth Othayoth #include <libphal.H>
10417b88eaSJayanth Othayoth #include <phal_exception.H>
114d779b2cSJayanth Othayoth 
122544b419SPatrick Williams #include <phosphor-logging/elog.hpp>
135bc26533SArya K Padman #include <phosphor-logging/lg2.hpp>
142544b419SPatrick Williams 
154d779b2cSJayanth Othayoth #include <algorithm>
164d779b2cSJayanth Othayoth #include <cstdlib>
174d779b2cSJayanth Othayoth #include <cstring>
181aa90d49SJayanth Othayoth #include <format>
194d779b2cSJayanth Othayoth #include <iomanip>
204d779b2cSJayanth Othayoth #include <list>
214d779b2cSJayanth Othayoth #include <map>
224d779b2cSJayanth Othayoth #include <sstream>
234d779b2cSJayanth Othayoth #include <string>
244d779b2cSJayanth Othayoth 
254d779b2cSJayanth Othayoth namespace openpower
264d779b2cSJayanth Othayoth {
274d779b2cSJayanth Othayoth namespace pels
284d779b2cSJayanth Othayoth {
294d779b2cSJayanth Othayoth namespace phal
304d779b2cSJayanth Othayoth {
314d779b2cSJayanth Othayoth 
32417b88eaSJayanth Othayoth using namespace openpower::phal::exception;
334d779b2cSJayanth Othayoth 
344d779b2cSJayanth Othayoth /**
354d779b2cSJayanth Othayoth  * Used to pass buffer to pdbg callback api to get required target
364d779b2cSJayanth Othayoth  * data (attributes) based on given data (attribute).
374d779b2cSJayanth Othayoth  */
384d779b2cSJayanth Othayoth struct TargetInfo
394d779b2cSJayanth Othayoth {
404d779b2cSJayanth Othayoth     ATTR_PHYS_BIN_PATH_Type physBinPath;
414d779b2cSJayanth Othayoth     ATTR_LOCATION_CODE_Type locationCode;
424d779b2cSJayanth Othayoth     ATTR_PHYS_DEV_PATH_Type physDevPath;
434d779b2cSJayanth Othayoth     ATTR_MRU_ID_Type mruId;
444d779b2cSJayanth Othayoth 
454d779b2cSJayanth Othayoth     bool deconfigure;
464d779b2cSJayanth Othayoth 
TargetInfoopenpower::pels::phal::TargetInfo474d779b2cSJayanth Othayoth     TargetInfo()
484d779b2cSJayanth Othayoth     {
494d779b2cSJayanth Othayoth         memset(&physBinPath, '\0', sizeof(physBinPath));
504d779b2cSJayanth Othayoth         memset(&locationCode, '\0', sizeof(locationCode));
514d779b2cSJayanth Othayoth         memset(&physDevPath, '\0', sizeof(physDevPath));
524d779b2cSJayanth Othayoth         mruId = 0;
534d779b2cSJayanth Othayoth         deconfigure = false;
544d779b2cSJayanth Othayoth     }
554d779b2cSJayanth Othayoth };
564d779b2cSJayanth Othayoth 
574d779b2cSJayanth Othayoth /**
584d779b2cSJayanth Othayoth  * Used to return in callback function which are used to get
594d779b2cSJayanth Othayoth  * physical path value and it binary format value.
604d779b2cSJayanth Othayoth  *
614d779b2cSJayanth Othayoth  * The value for constexpr defined based on pdbg_target_traverse function usage.
624d779b2cSJayanth Othayoth  */
634d779b2cSJayanth Othayoth constexpr int continueTgtTraversal = 0;
644d779b2cSJayanth Othayoth constexpr int requireAttrFound = 1;
654d779b2cSJayanth Othayoth constexpr int requireAttrNotFound = 2;
664d779b2cSJayanth Othayoth 
674d779b2cSJayanth Othayoth /**
684d779b2cSJayanth Othayoth  * @brief Used to get target location code from phal device tree
694d779b2cSJayanth Othayoth  *
704d779b2cSJayanth Othayoth  * @param[in] target current device tree target
714d779b2cSJayanth Othayoth  * @param[out] appPrivData used for accessing|storing from|to application
724d779b2cSJayanth Othayoth  *
734d779b2cSJayanth Othayoth  * @return 0 to continue traverse, non-zero to stop traverse
744d779b2cSJayanth Othayoth  */
pdbgCallbackToGetTgtReqAttrsVal(struct pdbg_target * target,void * appPrivData)754d779b2cSJayanth Othayoth int pdbgCallbackToGetTgtReqAttrsVal(struct pdbg_target* target,
764d779b2cSJayanth Othayoth                                     void* appPrivData)
774d779b2cSJayanth Othayoth {
78417b88eaSJayanth Othayoth     using namespace openpower::phal::pdbg;
79417b88eaSJayanth Othayoth 
804d779b2cSJayanth Othayoth     TargetInfo* targetInfo = static_cast<TargetInfo*>(appPrivData);
814d779b2cSJayanth Othayoth 
824d779b2cSJayanth Othayoth     ATTR_PHYS_BIN_PATH_Type physBinPath;
834d779b2cSJayanth Othayoth     /**
844d779b2cSJayanth Othayoth      * TODO: Issue: phal/pdata#16
854d779b2cSJayanth Othayoth      * Should not use direct pdbg api to read attribute. Need to use DT_GET_PROP
864d779b2cSJayanth Othayoth      * macro for bmc app's and this will call libdt-api api but, it will print
874d779b2cSJayanth Othayoth      * "pdbg_target_get_attribute failed" trace if attribute is not found and
884d779b2cSJayanth Othayoth      * this callback will call recursively by using pdbg_target_traverse() until
894d779b2cSJayanth Othayoth      * find expected attribute based on return code from this callback. Because,
904d779b2cSJayanth Othayoth      * need to do target iteration to get actual attribute (ATTR_PHYS_BIN_PATH)
914d779b2cSJayanth Othayoth      * value when device tree target info doesn't know to read attribute from
924d779b2cSJayanth Othayoth      * device tree. So, Due to this error trace user will get confusion while
934d779b2cSJayanth Othayoth      * looking traces. Hence using pdbg api to avoid trace until libdt-api
944d779b2cSJayanth Othayoth      * provides log level setup.
954d779b2cSJayanth Othayoth      */
964d779b2cSJayanth Othayoth     if (!pdbg_target_get_attribute(
974d779b2cSJayanth Othayoth             target, "ATTR_PHYS_BIN_PATH",
984d779b2cSJayanth Othayoth             std::stoi(dtAttr::fapi2::ATTR_PHYS_BIN_PATH_Spec),
994d779b2cSJayanth Othayoth             dtAttr::fapi2::ATTR_PHYS_BIN_PATH_ElementCount, physBinPath))
1004d779b2cSJayanth Othayoth     {
1014d779b2cSJayanth Othayoth         return continueTgtTraversal;
1024d779b2cSJayanth Othayoth     }
1034d779b2cSJayanth Othayoth 
1044d779b2cSJayanth Othayoth     if (std::memcmp(physBinPath, targetInfo->physBinPath,
1054d779b2cSJayanth Othayoth                     sizeof(physBinPath)) != 0)
1064d779b2cSJayanth Othayoth     {
1074d779b2cSJayanth Othayoth         return continueTgtTraversal;
1084d779b2cSJayanth Othayoth     }
1094d779b2cSJayanth Othayoth 
110363ac769SJayanth Othayoth     // Found Target, now collect the required attributes associated to the
111363ac769SJayanth Othayoth     // target. Incase of any attribute read failure, initialize the data with
112363ac769SJayanth Othayoth     // default value.
113363ac769SJayanth Othayoth 
114417b88eaSJayanth Othayoth     try
1154d779b2cSJayanth Othayoth     {
116417b88eaSJayanth Othayoth         // Get location code information
117417b88eaSJayanth Othayoth         openpower::phal::pdbg::getLocationCode(target,
118417b88eaSJayanth Othayoth                                                targetInfo->locationCode);
119417b88eaSJayanth Othayoth     }
120417b88eaSJayanth Othayoth     catch (const std::exception& e)
121417b88eaSJayanth Othayoth     {
122417b88eaSJayanth Othayoth         // log message and continue with default data
1235bc26533SArya K Padman         lg2::error("getLocationCode({TARGET_PATH}): Exception({EXCEPTION})",
1245bc26533SArya K Padman                    "TARGET_PATH", pdbg_target_path(target), "EXCEPTION", e);
1254d779b2cSJayanth Othayoth     }
1264d779b2cSJayanth Othayoth 
1274d779b2cSJayanth Othayoth     if (DT_GET_PROP(ATTR_PHYS_DEV_PATH, target, targetInfo->physDevPath))
1284d779b2cSJayanth Othayoth     {
1295bc26533SArya K Padman         lg2::error("Could not read({TARGET_PATH}) PHYS_DEV_PATH attribute",
1305bc26533SArya K Padman                    "TARGET_PATH", pdbg_target_path(target));
1314d779b2cSJayanth Othayoth     }
1324d779b2cSJayanth Othayoth 
1334d779b2cSJayanth Othayoth     if (DT_GET_PROP(ATTR_MRU_ID, target, targetInfo->mruId))
1344d779b2cSJayanth Othayoth     {
1355bc26533SArya K Padman         lg2::error("Could not read({TARGET_PATH}) ATTR_MRU_ID attribute",
1365bc26533SArya K Padman                    "TARGET_PATH", pdbg_target_path(target));
1374d779b2cSJayanth Othayoth     }
1384d779b2cSJayanth Othayoth 
1394d779b2cSJayanth Othayoth     return requireAttrFound;
1404d779b2cSJayanth Othayoth }
1414d779b2cSJayanth Othayoth 
1424d779b2cSJayanth Othayoth /**
1434d779b2cSJayanth Othayoth  * @brief Used to get target info (attributes data)
1444d779b2cSJayanth Othayoth  *
1454d779b2cSJayanth Othayoth  * To get target required attributes value using another attribute value
1464d779b2cSJayanth Othayoth  * ("PHYS_BIN_PATH" which is present in same target attributes list) by using
1474d779b2cSJayanth Othayoth  * "ipdbg_target_traverse" api because, here we have attribute value only and
1484d779b2cSJayanth Othayoth  * doesn't have respective device tree target info to get required attributes
1494d779b2cSJayanth Othayoth  * values from it attributes list.
1504d779b2cSJayanth Othayoth  *
1514d779b2cSJayanth Othayoth  * @param[in] physBinPath to pass PHYS_BIN_PATH value
1524d779b2cSJayanth Othayoth  * @param[out] targetInfo to pas buufer to fill with required attributes
1534d779b2cSJayanth Othayoth  *
1544d779b2cSJayanth Othayoth  * @return true on success otherwise false
1554d779b2cSJayanth Othayoth  */
getTgtReqAttrsVal(const std::vector<uint8_t> & physBinPath,TargetInfo & targetInfo)1564d779b2cSJayanth Othayoth bool getTgtReqAttrsVal(const std::vector<uint8_t>& physBinPath,
1574d779b2cSJayanth Othayoth                        TargetInfo& targetInfo)
1584d779b2cSJayanth Othayoth {
1594d779b2cSJayanth Othayoth     std::memcpy(&targetInfo.physBinPath, physBinPath.data(),
1604d779b2cSJayanth Othayoth                 sizeof(targetInfo.physBinPath));
1614d779b2cSJayanth Othayoth 
1624d779b2cSJayanth Othayoth     int ret = pdbg_target_traverse(NULL, pdbgCallbackToGetTgtReqAttrsVal,
1634d779b2cSJayanth Othayoth                                    &targetInfo);
1644d779b2cSJayanth Othayoth     if (ret == 0)
1654d779b2cSJayanth Othayoth     {
1661aa90d49SJayanth Othayoth         std::string fmt;
1671aa90d49SJayanth Othayoth         for (auto value : targetInfo.physBinPath)
1681aa90d49SJayanth Othayoth         {
1691aa90d49SJayanth Othayoth             fmt += std::format("{:02X} ", value);
1701aa90d49SJayanth Othayoth         }
1711aa90d49SJayanth Othayoth 
1725bc26533SArya K Padman         lg2::error(
1735bc26533SArya K Padman             "Given ATTR_PHYS_BIN_PATH value {ATTR_PHYS_BIN_PATH} not found in phal device tree",
1745bc26533SArya K Padman             "ATTR_PHYS_BIN_PATH", fmt);
1754d779b2cSJayanth Othayoth         return false;
1764d779b2cSJayanth Othayoth     }
1774d779b2cSJayanth Othayoth     else if (ret == requireAttrNotFound)
1784d779b2cSJayanth Othayoth     {
1794d779b2cSJayanth Othayoth         return false;
1804d779b2cSJayanth Othayoth     }
1814d779b2cSJayanth Othayoth 
1824d779b2cSJayanth Othayoth     return true;
1834d779b2cSJayanth Othayoth }
1844d779b2cSJayanth Othayoth 
1854d779b2cSJayanth Othayoth /**
1864d779b2cSJayanth Othayoth  * @brief GET PEL priority from pHAL priority
1874d779b2cSJayanth Othayoth  *
1884d779b2cSJayanth Othayoth  * The pHAL callout priority is in different format than PEL format
1894d779b2cSJayanth Othayoth  * so, this api is used to return current phal supported priority into
1904d779b2cSJayanth Othayoth  * PEL expected format.
1914d779b2cSJayanth Othayoth  *
1924d779b2cSJayanth Othayoth  * @param[in] phalPriority used to pass phal priority format string
1934d779b2cSJayanth Othayoth  *
1944d779b2cSJayanth Othayoth  * @return pel priority format string else empty if failure
1954d779b2cSJayanth Othayoth  *
1964d779b2cSJayanth Othayoth  * @note For "NONE" returning "L" (LOW)
1974d779b2cSJayanth Othayoth  */
getPelPriority(const std::string & phalPriority)1984d779b2cSJayanth Othayoth static std::string getPelPriority(const std::string& phalPriority)
1994d779b2cSJayanth Othayoth {
2004d779b2cSJayanth Othayoth     const std::map<std::string, std::string> priorityMap = {
2014d779b2cSJayanth Othayoth         {"HIGH", "H"}, {"MEDIUM", "M"}, {"LOW", "L"}, {"NONE", "L"}};
2024d779b2cSJayanth Othayoth 
2034d779b2cSJayanth Othayoth     auto it = priorityMap.find(phalPriority);
2044d779b2cSJayanth Othayoth     if (it == priorityMap.end())
2054d779b2cSJayanth Othayoth     {
2065bc26533SArya K Padman         lg2::error(
2075bc26533SArya K Padman             "Unsupported phal priority({PHAL_PRIORITY}) is given to get pel priority format",
2085bc26533SArya K Padman             "PHAL_PRIORITY", phalPriority);
2094d779b2cSJayanth Othayoth         return "H";
2104d779b2cSJayanth Othayoth     }
2114d779b2cSJayanth Othayoth 
2124d779b2cSJayanth Othayoth     return it->second;
2134d779b2cSJayanth Othayoth }
2144d779b2cSJayanth Othayoth 
215f928c4a2Srajerpp1 /**
216f928c4a2Srajerpp1  * @brief addPlanarCallout
217f928c4a2Srajerpp1  *
218f928c4a2Srajerpp1  * This function will add a json for planar callout in the input json list.
219f928c4a2Srajerpp1  * The caller can pass this json list into createErrorPEL to apply the callout.
220f928c4a2Srajerpp1  *
221f928c4a2Srajerpp1  * @param[in,out] jsonCalloutDataList - json list where callout json will be
222f928c4a2Srajerpp1  *                  emplaced
223f928c4a2Srajerpp1  * @param[in] priority - string indicating priority.
224f928c4a2Srajerpp1  */
addPlanarCallout(json & jsonCalloutDataList,const std::string & priority)225f928c4a2Srajerpp1 static void addPlanarCallout(json& jsonCalloutDataList,
226f928c4a2Srajerpp1                              const std::string& priority)
227f928c4a2Srajerpp1 {
228f928c4a2Srajerpp1     json jsonCalloutData;
229f928c4a2Srajerpp1 
230f928c4a2Srajerpp1     // Inventory path for planar
231f928c4a2Srajerpp1     jsonCalloutData["InventoryPath"] =
232f928c4a2Srajerpp1         "/xyz/openbmc_project/inventory/system/chassis/motherboard";
233f928c4a2Srajerpp1     jsonCalloutData["Deconfigured"] = false;
234f928c4a2Srajerpp1     jsonCalloutData["Guarded"] = false;
235f928c4a2Srajerpp1     jsonCalloutData["Priority"] = priority;
236f928c4a2Srajerpp1 
237f928c4a2Srajerpp1     jsonCalloutDataList.emplace_back(jsonCalloutData);
238f928c4a2Srajerpp1 }
239f928c4a2Srajerpp1 
240e98777dcSJayanth Othayoth /**
241e98777dcSJayanth Othayoth  * @brief processClockInfoErrorHelper
242e98777dcSJayanth Othayoth  *
243e98777dcSJayanth Othayoth  * Creates informational PEL for spare clock failure
244e98777dcSJayanth Othayoth  *
245e98777dcSJayanth Othayoth  * @param[in]  ffdc FFDC data capturd by the HWP
246e98777dcSJayanth Othayoth  * @param[out] pelJSONFmtCalloutDataList used to store collected callout
247e98777dcSJayanth Othayoth  *            data into pel expected format
248e98777dcSJayanth Othayoth  * @param[out] ffdcUserData used to store additional ffdc user data to
249e98777dcSJayanth Othayoth  *              provided by the SBE FFDC packet.
250e98777dcSJayanth Othayoth  *
251e98777dcSJayanth Othayoth  * @return NULL
252e98777dcSJayanth Othayoth  *
253e98777dcSJayanth Othayoth  **/
processClockInfoErrorHelper(const FFDC & ffdc,json & pelJSONFmtCalloutDataList,FFDCData & ffdcUserData)254*075c7923SPatrick Williams void processClockInfoErrorHelper(
255*075c7923SPatrick Williams     const FFDC& ffdc, json& pelJSONFmtCalloutDataList, FFDCData& ffdcUserData)
256e98777dcSJayanth Othayoth {
2575bc26533SArya K Padman     lg2::info("processClockInfoErrorHelper: FFDC Message[{FFDC_MSG}]",
2585bc26533SArya K Padman               "FFDC_MSG", ffdc.message);
259e98777dcSJayanth Othayoth 
260e98777dcSJayanth Othayoth     // Adding hardware procedures return code details
261e98777dcSJayanth Othayoth     ffdcUserData.emplace_back("HWP_RC", ffdc.hwp_errorinfo.rc);
262e98777dcSJayanth Othayoth     ffdcUserData.emplace_back("HWP_RC_DESC", ffdc.hwp_errorinfo.rc_desc);
263e98777dcSJayanth Othayoth 
264e98777dcSJayanth Othayoth     // Adding hardware procedures required ffdc data for debug
265e98777dcSJayanth Othayoth     for_each(ffdc.hwp_errorinfo.ffdcs_data.cbegin(),
266e98777dcSJayanth Othayoth              ffdc.hwp_errorinfo.ffdcs_data.cend(),
267e98777dcSJayanth Othayoth              [&ffdcUserData](
268e98777dcSJayanth Othayoth                  const std::pair<std::string, std::string>& ele) -> void {
269e98777dcSJayanth Othayoth                  std::string keyWithPrefix("HWP_FFDC_");
270e98777dcSJayanth Othayoth                  keyWithPrefix.append(ele.first);
271e98777dcSJayanth Othayoth 
272e98777dcSJayanth Othayoth                  ffdcUserData.emplace_back(keyWithPrefix, ele.second);
273e98777dcSJayanth Othayoth              });
274e98777dcSJayanth Othayoth     // get clock position information
275e98777dcSJayanth Othayoth     auto clk_pos = 0xFF; // Invalid position.
276e98777dcSJayanth Othayoth     for (auto& hwCallout : ffdc.hwp_errorinfo.hwcallouts)
277e98777dcSJayanth Othayoth     {
278e98777dcSJayanth Othayoth         if ((hwCallout.hwid == "PROC_REF_CLOCK") ||
279e98777dcSJayanth Othayoth             (hwCallout.hwid == "PCI_REF_CLOCK"))
280e98777dcSJayanth Othayoth         {
281e98777dcSJayanth Othayoth             clk_pos = hwCallout.clkPos;
282e98777dcSJayanth Othayoth             break;
283e98777dcSJayanth Othayoth         }
284e98777dcSJayanth Othayoth     }
285e98777dcSJayanth Othayoth     // Adding CDG (Only deconfigure) targets details
286e98777dcSJayanth Othayoth     for_each(ffdc.hwp_errorinfo.cdg_targets.begin(),
287e98777dcSJayanth Othayoth              ffdc.hwp_errorinfo.cdg_targets.end(),
288e98777dcSJayanth Othayoth              [&ffdcUserData, &pelJSONFmtCalloutDataList,
289e98777dcSJayanth Othayoth               clk_pos](const CDG_Target& cdg_tgt) -> void {
290e98777dcSJayanth Othayoth                  json jsonCalloutData;
291e98777dcSJayanth Othayoth                  std::string pelPriority = "H";
292e98777dcSJayanth Othayoth                  jsonCalloutData["Priority"] = pelPriority; // Not used
293*075c7923SPatrick Williams                  jsonCalloutData["SymbolicFRU"] =
294*075c7923SPatrick Williams                      "REFCLK" + std::to_string(clk_pos);
295e98777dcSJayanth Othayoth                  jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure;
296e98777dcSJayanth Othayoth                  jsonCalloutData["EntityPath"] = cdg_tgt.target_entity_path;
297e98777dcSJayanth Othayoth                  pelJSONFmtCalloutDataList.emplace_back(jsonCalloutData);
298e98777dcSJayanth Othayoth              });
299e98777dcSJayanth Othayoth }
300e98777dcSJayanth Othayoth 
convertFAPItoPELformat(FFDC & ffdc,json & pelJSONFmtCalloutDataList,FFDCData & ffdcUserData)3014d779b2cSJayanth Othayoth void convertFAPItoPELformat(FFDC& ffdc, json& pelJSONFmtCalloutDataList,
3024d779b2cSJayanth Othayoth                             FFDCData& ffdcUserData)
3034d779b2cSJayanth Othayoth {
304e98777dcSJayanth Othayoth     if (ffdc.ffdc_type == FFDC_TYPE_SPARE_CLOCK_INFO)
305e98777dcSJayanth Othayoth     {
306e98777dcSJayanth Othayoth         processClockInfoErrorHelper(ffdc, pelJSONFmtCalloutDataList,
307e98777dcSJayanth Othayoth                                     ffdcUserData);
308e98777dcSJayanth Othayoth         return;
309e98777dcSJayanth Othayoth     }
310e98777dcSJayanth Othayoth 
3114d779b2cSJayanth Othayoth     if (ffdc.ffdc_type == FFDC_TYPE_HWP)
3124d779b2cSJayanth Othayoth     {
3134d779b2cSJayanth Othayoth         // Adding hardware procedures return code details
3144d779b2cSJayanth Othayoth         ffdcUserData.emplace_back("HWP_RC", ffdc.hwp_errorinfo.rc);
3154d779b2cSJayanth Othayoth         ffdcUserData.emplace_back("HWP_RC_DESC", ffdc.hwp_errorinfo.rc_desc);
3164d779b2cSJayanth Othayoth 
3174d779b2cSJayanth Othayoth         // Adding hardware procedures required ffdc data for debug
3184d779b2cSJayanth Othayoth         for_each(
3194d779b2cSJayanth Othayoth             ffdc.hwp_errorinfo.ffdcs_data.begin(),
3204d779b2cSJayanth Othayoth             ffdc.hwp_errorinfo.ffdcs_data.end(),
3214d779b2cSJayanth Othayoth             [&ffdcUserData](std::pair<std::string, std::string>& ele) -> void {
3224d779b2cSJayanth Othayoth                 std::string keyWithPrefix("HWP_FFDC_");
3234d779b2cSJayanth Othayoth                 keyWithPrefix.append(ele.first);
3244d779b2cSJayanth Othayoth 
3254d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(keyWithPrefix, ele.second);
3264d779b2cSJayanth Othayoth             });
3274d779b2cSJayanth Othayoth 
3284d779b2cSJayanth Othayoth         // Adding hardware callout details
3294d779b2cSJayanth Othayoth         int calloutCount = 0;
330*075c7923SPatrick Williams         for_each(
331*075c7923SPatrick Williams             ffdc.hwp_errorinfo.hwcallouts.begin(),
3324d779b2cSJayanth Othayoth             ffdc.hwp_errorinfo.hwcallouts.end(),
333*075c7923SPatrick Williams             [&ffdcUserData, &calloutCount,
334*075c7923SPatrick Williams              &pelJSONFmtCalloutDataList](const HWCallout& hwCallout) -> void {
3354d779b2cSJayanth Othayoth                 calloutCount++;
3364d779b2cSJayanth Othayoth                 std::stringstream keyPrefix;
3374d779b2cSJayanth Othayoth                 keyPrefix << "HWP_HW_CO_" << std::setfill('0') << std::setw(2)
3384d779b2cSJayanth Othayoth                           << calloutCount << "_";
3394d779b2cSJayanth Othayoth 
3404d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
341*075c7923SPatrick Williams                     std::string(keyPrefix.str()).append("HW_ID"),
342*075c7923SPatrick Williams                     hwCallout.hwid);
3434d779b2cSJayanth Othayoth 
3444d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
3454d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("PRIORITY"),
3464d779b2cSJayanth Othayoth                     hwCallout.callout_priority);
3474d779b2cSJayanth Othayoth 
3484d779b2cSJayanth Othayoth                 phal::TargetInfo targetInfo;
349*075c7923SPatrick Williams                 phal::getTgtReqAttrsVal(hwCallout.target_entity_path,
350*075c7923SPatrick Williams                                         targetInfo);
3514d779b2cSJayanth Othayoth 
3524d779b2cSJayanth Othayoth                 std::string locationCode = std::string(targetInfo.locationCode);
3534d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
354*075c7923SPatrick Williams                     std::string(keyPrefix.str()).append("LOC_CODE"),
355*075c7923SPatrick Williams                     locationCode);
3564d779b2cSJayanth Othayoth 
3574d779b2cSJayanth Othayoth                 std::string physPath = std::string(targetInfo.physDevPath);
3584d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
3594d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("PHYS_PATH"), physPath);
3604d779b2cSJayanth Othayoth 
3614d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
3624d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("CLK_POS"),
3634d779b2cSJayanth Othayoth                     std::to_string(hwCallout.clkPos));
364f928c4a2Srajerpp1 
365f928c4a2Srajerpp1                 ffdcUserData.emplace_back(
366f928c4a2Srajerpp1                     std::string(keyPrefix.str()).append("CALLOUT_PLANAR"),
367f928c4a2Srajerpp1                     (hwCallout.isPlanarCallout == true ? "true" : "false"));
368f928c4a2Srajerpp1 
369f928c4a2Srajerpp1                 std::string pelPriority =
370f928c4a2Srajerpp1                     getPelPriority(hwCallout.callout_priority);
371f928c4a2Srajerpp1 
372f928c4a2Srajerpp1                 if (hwCallout.isPlanarCallout)
373f928c4a2Srajerpp1                 {
374f928c4a2Srajerpp1                     addPlanarCallout(pelJSONFmtCalloutDataList, pelPriority);
375f928c4a2Srajerpp1                 }
3764d779b2cSJayanth Othayoth             });
3774d779b2cSJayanth Othayoth 
3784d779b2cSJayanth Othayoth         // Adding CDG (callout, deconfigure and guard) targets details
3794d779b2cSJayanth Othayoth         calloutCount = 0;
380*075c7923SPatrick Williams         for_each(
381*075c7923SPatrick Williams             ffdc.hwp_errorinfo.cdg_targets.begin(),
3824d779b2cSJayanth Othayoth             ffdc.hwp_errorinfo.cdg_targets.end(),
383*075c7923SPatrick Williams             [&ffdcUserData, &calloutCount,
384*075c7923SPatrick Williams              &pelJSONFmtCalloutDataList](const CDG_Target& cdg_tgt) -> void {
3854d779b2cSJayanth Othayoth                 calloutCount++;
3864d779b2cSJayanth Othayoth                 std::stringstream keyPrefix;
3874d779b2cSJayanth Othayoth                 keyPrefix << "HWP_CDG_TGT_" << std::setfill('0') << std::setw(2)
3884d779b2cSJayanth Othayoth                           << calloutCount << "_";
3894d779b2cSJayanth Othayoth 
3904d779b2cSJayanth Othayoth                 phal::TargetInfo targetInfo;
3914d779b2cSJayanth Othayoth                 targetInfo.deconfigure = cdg_tgt.deconfigure;
3924d779b2cSJayanth Othayoth 
3934d779b2cSJayanth Othayoth                 phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path, targetInfo);
3944d779b2cSJayanth Othayoth 
3954d779b2cSJayanth Othayoth                 std::string locationCode = std::string(targetInfo.locationCode);
3964d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
397*075c7923SPatrick Williams                     std::string(keyPrefix.str()).append("LOC_CODE"),
398*075c7923SPatrick Williams                     locationCode);
3994d779b2cSJayanth Othayoth                 std::string physPath = std::string(targetInfo.physDevPath);
4004d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4014d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("PHYS_PATH"), physPath);
4024d779b2cSJayanth Othayoth 
4034d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4044d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("CO_REQ"),
4054d779b2cSJayanth Othayoth                     (cdg_tgt.callout == true ? "true" : "false"));
4064d779b2cSJayanth Othayoth 
4074d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4084d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("CO_PRIORITY"),
4094d779b2cSJayanth Othayoth                     cdg_tgt.callout_priority);
4104d779b2cSJayanth Othayoth 
4114d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4124d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("DECONF_REQ"),
4134d779b2cSJayanth Othayoth                     (cdg_tgt.deconfigure == true ? "true" : "false"));
4144d779b2cSJayanth Othayoth 
4154d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4164d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("GUARD_REQ"),
4174d779b2cSJayanth Othayoth                     (cdg_tgt.guard == true ? "true" : "false"));
4184d779b2cSJayanth Othayoth 
4194d779b2cSJayanth Othayoth                 ffdcUserData.emplace_back(
4204d779b2cSJayanth Othayoth                     std::string(keyPrefix.str()).append("GUARD_TYPE"),
4214d779b2cSJayanth Othayoth                     cdg_tgt.guard_type);
4224d779b2cSJayanth Othayoth 
4234d779b2cSJayanth Othayoth                 json jsonCalloutData;
4244d779b2cSJayanth Othayoth                 jsonCalloutData["LocationCode"] = locationCode;
425*075c7923SPatrick Williams                 std::string pelPriority =
426*075c7923SPatrick Williams                     getPelPriority(cdg_tgt.callout_priority);
4274d779b2cSJayanth Othayoth                 jsonCalloutData["Priority"] = pelPriority;
4284d779b2cSJayanth Othayoth 
4294d779b2cSJayanth Othayoth                 if (targetInfo.mruId != 0)
4304d779b2cSJayanth Othayoth                 {
4314d779b2cSJayanth Othayoth                     jsonCalloutData["MRUs"] = json::array({
4324d779b2cSJayanth Othayoth                         {{"ID", targetInfo.mruId}, {"Priority", pelPriority}},
4334d779b2cSJayanth Othayoth                     });
4344d779b2cSJayanth Othayoth                 }
4354d779b2cSJayanth Othayoth                 jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure;
4364d779b2cSJayanth Othayoth                 jsonCalloutData["Guarded"] = cdg_tgt.guard;
43795205eb0SJayanth Othayoth                 jsonCalloutData["GuardType"] = cdg_tgt.guard_type;
43895205eb0SJayanth Othayoth                 jsonCalloutData["EntityPath"] = cdg_tgt.target_entity_path;
4394d779b2cSJayanth Othayoth 
4404d779b2cSJayanth Othayoth                 pelJSONFmtCalloutDataList.emplace_back(jsonCalloutData);
4414d779b2cSJayanth Othayoth             });
4429368b714SJayanth Othayoth 
4439368b714SJayanth Othayoth         // Adding procedure callout
4449368b714SJayanth Othayoth         calloutCount = 0;
4459368b714SJayanth Othayoth         for_each(ffdc.hwp_errorinfo.procedures_callout.begin(),
4469368b714SJayanth Othayoth                  ffdc.hwp_errorinfo.procedures_callout.end(),
4479368b714SJayanth Othayoth                  [&ffdcUserData, &calloutCount, &pelJSONFmtCalloutDataList](
4489368b714SJayanth Othayoth                      const ProcedureCallout& procCallout) -> void {
4499368b714SJayanth Othayoth                      calloutCount++;
4509368b714SJayanth Othayoth                      std::stringstream keyPrefix;
451*075c7923SPatrick Williams                      keyPrefix << "HWP_PROC_CO_" << std::setfill('0')
452*075c7923SPatrick Williams                                << std::setw(2) << calloutCount << "_";
4539368b714SJayanth Othayoth                      ffdcUserData.emplace_back(
4549368b714SJayanth Othayoth                          std::string(keyPrefix.str()).append("PRIORITY"),
4559368b714SJayanth Othayoth                          procCallout.callout_priority);
4569368b714SJayanth Othayoth                      ffdcUserData.emplace_back(
4579368b714SJayanth Othayoth                          std::string(keyPrefix.str()).append("MAINT_PROCEDURE"),
4589368b714SJayanth Othayoth                          procCallout.proc_callout);
4599368b714SJayanth Othayoth                      json jsonCalloutData;
4609368b714SJayanth Othayoth                      jsonCalloutData["Procedure"] = procCallout.proc_callout;
4619368b714SJayanth Othayoth                      std::string pelPriority =
4629368b714SJayanth Othayoth                          getPelPriority(procCallout.callout_priority);
4639368b714SJayanth Othayoth                      jsonCalloutData["Priority"] = pelPriority;
4649368b714SJayanth Othayoth                      pelJSONFmtCalloutDataList.emplace_back(jsonCalloutData);
4659368b714SJayanth Othayoth                  });
4664d779b2cSJayanth Othayoth     }
4674d779b2cSJayanth Othayoth     else if ((ffdc.ffdc_type != FFDC_TYPE_NONE) &&
4684d779b2cSJayanth Othayoth              (ffdc.ffdc_type != FFDC_TYPE_UNSUPPORTED))
4694d779b2cSJayanth Othayoth     {
4705bc26533SArya K Padman         lg2::error("Unsupported phal FFDC type to create PEL. MSG: {FFDC_MSG}",
4715bc26533SArya K Padman                    "FFDC_MSG", ffdc.message);
4724d779b2cSJayanth Othayoth     }
4734d779b2cSJayanth Othayoth }
4744d779b2cSJayanth Othayoth 
4754d779b2cSJayanth Othayoth } // namespace phal
4764d779b2cSJayanth Othayoth } // namespace pels
4774d779b2cSJayanth Othayoth } // namespace openpower
478