phal: Added HW callout info into PEL

- If any hardware procedure (hwp) failed during execution of ipling then
  that particular hwp will request the required hardware's (which are defined
  error xml of respective hwp) need to be callout. So, this patch will create
  PEL records based on given FFDC (First Failure Data Collection) by phal
  during failure.

- Also, this patch will deconfigure (marking hardware as non-functional
  i.e update HWAS_STATE attribute with respective bitfield value in POWER CEC
  device tree) required hardwares which are given as part of phal ffdc data.

- Used "libfmt" to format trace with field value instead adding as entry
  in journal so, while debugging it will be easy instead looking each entry.

TestedBy:

"User Data 1": {
    "Section Version": "1",
    "Sub-section type": "1",
    "Created by": "0x2000",
    "HWP_CDG_TGT_01_CO_PRIORITY": "MEDIUM",
    "HWP_CDG_TGT_01_CO_REQ": "true",
    "HWP_CDG_TGT_01_DECONF_REQ": "false",
    "HWP_CDG_TGT_01_GUARD_REQ": "false",
    "HWP_CDG_TGT_01_GUARD_TYPE": "GARD_Fatal",
    "HWP_CDG_TGT_01_LOC_CODE": "Ufcs-P0-C15",
    "HWP_CDG_TGT_01_PHYS_PATH": "physical:sys-0/node-0/proc-0",
    "HWP_FFDC_ATTR_CP_REFCLOCK_SELECT_VALUE": "00",
    "HWP_FFDC_RCS_CLOCK_TEST_IN": "01",
    "HWP_FFDC_READ_SNS1LTH": "0c000000",
    "HWP_HW_CO_01_CLK_POS": "0",
    "HWP_HW_CO_01_HW_ID": "PROC_REF_CLOCK",
    "HWP_HW_CO_01_LOC_CODE": "Ufcs-P0-C15",
    "HWP_HW_CO_01_PHYS_PATH": "physical:sys-0/node-0/proc-0",
    "HWP_HW_CO_01_PRIORITY": "HIGH",
    "HWP_RC": "RC_CLOCK_TEST_OUT_RCS_ERR",
    "HWP_RC_DESC": "One or more processor reference clocks not toggling",
    "LOG000 2020-09-22 04:12:58": "Running p10_clock_test HWP on processor 0\n",
    "LOG001 2020-09-22 04:12:58": "inf: p10_clock_test:60
p10_clock_test: Entering ...\n",
    "LOG002 2020-09-22 04:12:58": "inf: p10_clock_test_latches:106
p10_clock_test_latches: Entering
...\n",
    "LOG003 2020-09-22 04:12:58": "err: CLOCK_TEST_OUT_RCS_ERR:4036
One or more processor reference clocks not toggling\n",
    "LOG004 2020-09-22 04:12:58": "err: _setHwpError:120 _setHwpError:
Creating HWP error 0x927e1c\n",
    "LOG005 2020-09-22 04:12:58": "inf: addErrorInfo:344
addErrorInfo: Adding cdg (1:0:0), pri: 1, gtyp: 227\n",
    "LOG006 2020-09-22 04:12:58": "err: p10_clock_test_latches:130 Clock A is bad\n",
    "LOG007 2020-09-22 04:12:58": "err: p10_clock_test:76
p10_clock_test_latches(i_target_chip, true) failed.\n",
    "LOG008 2020-09-22 04:12:58": "HWP clock_test failed on proc 0, rc=2124995320\n",
    "_PID": "1209"
},
"User Data 2": {
    "Section Version": "1",
    "Sub-section type": "1",
    "Created by": "0x2000",
    "Data": [
        {
            "LocationCode": "Ufcs-P0-C15",
            "MRUs": [
                {
                    "ID": 65536,
                    "Priority": "H"
                }
            ],
            "Priority": "H"
        },
        {
            "Deconfigured": false,
            "Guarded": false,
            "LocationCode": "Ufcs-P0-C15",
            "MRUs": [
                {
                    "ID": 65536,
                    "Priority": "M"
                }
            ],
            "Priority": "M"
        }
    ]
}

Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Change-Id: I4462c46747598166b085990e1d82cb2998b9e06b
diff --git a/phalerror/create_pel.hpp b/phalerror/create_pel.hpp
index b80b642..b123a5a 100644
--- a/phalerror/create_pel.hpp
+++ b/phalerror/create_pel.hpp
@@ -1,5 +1,6 @@
 #pragma once

 

+#include <nlohmann/json.hpp>

 #include <sdbusplus/bus.hpp>

 #include <string>

 #include <vector>

@@ -22,12 +23,101 @@
 namespace pel

 {

 using FFDCData = std::vector<std::pair<std::string, std::string>>;

+

+using json = nlohmann::json;

+

 /**

  * Create boot error PEL

  *

  * @param[in] ffdcData - failure data to append to PEL

+ * @param[in] calloutData - callout data to append to PEL

  */

-void createBootErrorPEL(const FFDCData& ffdcData);

+void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);

+

+/**

+ * @class FFDCFile

+ * @brief This class is used to create ffdc data file and to get fd

+ */

+class FFDCFile

+{

+  public:

+    FFDCFile() = delete;

+    FFDCFile(const FFDCFile&) = delete;

+    FFDCFile& operator=(const FFDCFile&) = delete;

+    FFDCFile(FFDCFile&&) = delete;

+    FFDCFile& operator=(FFDCFile&&) = delete;

+

+    /**

+     * Used to pass json object to create unique ffdc file by using

+     * passed json data.

+     */

+    explicit FFDCFile(const json& pHALCalloutData);

+

+    /**

+     * Used to remove created ffdc file.

+     */

+    ~FFDCFile();

+

+    /**

+     * Used to get created ffdc file file descriptor id.

+     *

+     * @return file descriptor id

+     */

+    int getFileFD() const;

+

+  private:

+    /**

+     * Used to store callout ffdc data from passed json object.

+     */

+    std::string calloutData;

+

+    /**

+     * Used to store unique ffdc file name.

+     */

+    std::string calloutFile;

+

+    /**

+     * Used to store created ffdc file descriptor id.

+     */

+    int fileFD;

+

+    /**

+     * Used to create ffdc file to pass PEL api for creating

+     * pel records.

+     *

+     * @return NULL

+     */

+    void prepareFFDCFile();

+

+    /**

+     * Create unique ffdc file.

+     *

+     * @return NULL

+     */

+    void createCalloutFile();

+

+    /**

+     * Used write json object value into created file.

+     *

+     * @return NULL

+     */

+    void writeCalloutData();

+

+    /**

+     * Used set ffdc file seek position begining to consume by PEL

+     *

+     * @return NULL

+     */

+    void setCalloutFileSeekPos();

+

+    /**

+     * Used to remove created ffdc file.

+     *

+     * @return NULL

+     */

+    void removeCalloutFile();

+

+}; // FFDCFile end

 

 } // namespace pel

 } // namespace openpower