PHAL: createSbePEL API updates

Dump D-bus API requires PLID information to create SBE dump.
Updated createSbePEL API to return PLID information for same.
Replaced PEL CreateWithFFDCFiles api with CreatePELWithFFDCFiles
to get PEL id.

Tested: verified manually.

Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: I38984e63029ae236b05744c81726296d2da17149
diff --git a/extensions/phal/create_pel.cpp b/extensions/phal/create_pel.cpp
index b1557e7..b3fdd4e 100644
--- a/extensions/phal/create_pel.cpp
+++ b/extensions/phal/create_pel.cpp
@@ -30,6 +30,7 @@
 
 constexpr auto loggingObjectPath = "/xyz/openbmc_project/logging";
 constexpr auto loggingInterface = "xyz.openbmc_project.Logging.Create";
+constexpr auto opLoggingInterface = "org.open_power.Logging.PEL";
 
 void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData)
 {
@@ -86,9 +87,10 @@
     }
 }
 
-void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
-                       const FFDCData& ffdcData)
+uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
+                           const FFDCData& ffdcData)
 {
+    uint32_t plid = 0;
     std::map<std::string, std::string> additionalData;
     auto bus = sdbusplus::bus::new_default();
 
@@ -105,28 +107,43 @@
         uint8_t, uint8_t, sdbusplus::message::unix_fd>>
         pelFFDCInfo;
 
-    // Refer phosphor-logging/extensions/openpower-pels/README.md section
-    // "Self Boot Engine(SBE) First Failure Data Capture(FFDC) Support"
-    // for details of related to createPEL with SBE FFDC information
-    // usin g CreateWithFFDCFiles api.
-    pelFFDCInfo.push_back(
-        std::make_tuple(sdbusplus::xyz::openbmc_project::Logging::server::
-                            Create::FFDCFormat::Custom,
-                        static_cast<uint8_t>(0xCB), static_cast<uint8_t>(0x01),
-                        sbeError.getFd()));
+    // get SBE ffdc file descriptor
+    auto fd = sbeError.getFd();
+
+    // Negative fd value indicates error case or invalid file
+    // No need of special processing , just log error with additional ffdc.
+    if (fd > 0)
+    {
+        // Refer phosphor-logging/extensions/openpower-pels/README.md section
+        // "Self Boot Engine(SBE) First Failure Data Capture(FFDC) Support"
+        // for details of related to createPEL with SBE FFDC information
+        // usin g CreateWithFFDCFiles api.
+        pelFFDCInfo.push_back(
+            std::make_tuple(sdbusplus::xyz::openbmc_project::Logging::server::
+                                Create::FFDCFormat::Custom,
+                            static_cast<uint8_t>(0xCB),
+                            static_cast<uint8_t>(0x01), sbeError.getFd()));
+    }
     try
     {
         std::string service =
-            util::getService(bus, loggingObjectPath, loggingInterface);
+            util::getService(bus, loggingObjectPath, opLoggingInterface);
         auto method =
             bus.new_method_call(service.c_str(), loggingObjectPath,
-                                loggingInterface, "CreateWithFFDCFiles");
+                                opLoggingInterface, "CreatePELWithFFDCFiles");
         auto level =
             sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
                 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
                     Error);
         method.append(event, level, additionalData, pelFFDCInfo);
-        auto resp = bus.call(method);
+        auto response = bus.call(method);
+
+        // reply will be tuple containing bmc log id, platform log id
+        std::tuple<uint32_t, uint32_t> reply = {0, 0};
+
+        // parse dbus response into reply
+        response.read(reply);
+        plid = std::get<1>(reply); // platform log id is tuple "second"
     }
     catch (const sdbusplus::exception::exception& e)
     {
@@ -142,6 +159,8 @@
     {
         throw e;
     }
+
+    return plid;
 }
 
 void createPEL(const std::string& event, const FFDCData& ffdcData)
diff --git a/extensions/phal/create_pel.hpp b/extensions/phal/create_pel.hpp
index e6d49a5..5c780eb 100644
--- a/extensions/phal/create_pel.hpp
+++ b/extensions/phal/create_pel.hpp
@@ -25,14 +25,15 @@
 void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
 
 /**
- * @brief Create SBE boot error PEL
+ * @brief Create SBE boot error PEL and return id
  *
  * @param[in] event - the event type
  * @param[in] sbeError - SBE error object
  * @param[in] ffdcData - failure data to append to PEL
+ * @return Platform log id
  */
-void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
-                       const FFDCData& ffdcData);
+uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
+                           const FFDCData& ffdcData);
 
 /**
  * @brief Create a PEL for the specified event type and additional data