change analyzerHardware() to return PEL PLID is created

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: Icee2909e5060c79cb95ead8fc08a5e359df42829
diff --git a/analyzer/analyzer_main.cpp b/analyzer/analyzer_main.cpp
index 71d47e9..c17a0ee 100644
--- a/analyzer/analyzer_main.cpp
+++ b/analyzer/analyzer_main.cpp
@@ -34,10 +34,10 @@
  * @brief Will create and submit a PEL using the given data.
  * @param i_isoData   The data gathered during isolation (for FFDC).
  * @param i_servData  Data regarding service actions gathered during analysis.
- * @return Tuple of BMC log id, platform log id
+ * @return The platform log ID. Will return zero if no PEL is generated.
  */
-std::tuple<uint32_t, uint32_t> createPel(const libhei::IsolationData& i_isoData,
-                                         const ServiceData& i_servData);
+uint32_t createPel(const libhei::IsolationData& i_isoData,
+                   const ServiceData& i_servData);
 
 //------------------------------------------------------------------------------
 
@@ -70,14 +70,14 @@
 
 //------------------------------------------------------------------------------
 
-bool analyzeHardware(attn::DumpParameters& o_dumpParameters)
+uint32_t analyzeHardware(attn::DumpParameters& o_dumpParameters)
 {
-    bool attnFound = false;
+    uint32_t o_plid = 0; // default, zero indicates PEL was not created
 
     if (!util::pdbg::queryHardwareAnalysisSupported())
     {
         trace::err("Hardware error analysis is not supported on this system");
-        return attnFound;
+        return o_plid;
     }
 
     trace::inf(">>> enter analyzeHardware()");
@@ -102,7 +102,7 @@
 
     // Filter for root cause attention.
     libhei::Signature rootCause{};
-    attnFound = filterRootCause(isoData, rootCause);
+    bool attnFound = filterRootCause(isoData, rootCause);
 
     if (!attnFound)
     {
@@ -124,18 +124,24 @@
         rasData.getResolution(rootCause)->resolve(servData);
 
         // Create and commit a PEL.
-        uint32_t logId = std::get<1>(createPel(isoData, servData));
+        o_plid = createPel(isoData, servData);
 
-        trace::inf("PEL created: PLID=0x%0" PRIx32, logId);
+        if (0 == o_plid)
+        {
+            trace::err("Failed to create PEL");
+        }
+        else
+        {
+            trace::inf("PEL created: PLID=0x%0" PRIx32, o_plid);
 
-        // Gather/return information needed for dump. A hardware dump will
-        // always be used for system checkstop attenions. Software dumps will be
-        // reserved for MP-IPLs during TI analysis.
-        // TODO: Need ID from root cause. At the moment, HUID does not exist in
-        //       devtree. Will need a better ID definition.
-        o_dumpParameters.logId    = logId;
-        o_dumpParameters.unitId   = 0;
-        o_dumpParameters.dumpType = attn::DumpType::Hardware;
+            // Gather/return information needed for dump. A hardware dump will
+            // always be used for system checkstop attenions. Software dumps
+            // will be reserved for MP-IPLs during TI analysis.
+            // TODO: Need ID from root cause. At the moment, HUID does not exist
+            //       in devtree. Will need a better ID definition.
+            o_dumpParameters.unitId   = 0;
+            o_dumpParameters.dumpType = attn::DumpType::Hardware;
+        }
     }
 
     // All done, clean up the isolator.
@@ -144,7 +150,7 @@
 
     trace::inf("<<< exit analyzeHardware()");
 
-    return attnFound;
+    return o_plid;
 }
 
 //------------------------------------------------------------------------------
diff --git a/analyzer/analyzer_main.hpp b/analyzer/analyzer_main.hpp
index 5619ba3..51399b0 100644
--- a/analyzer/analyzer_main.hpp
+++ b/analyzer/analyzer_main.hpp
@@ -11,18 +11,10 @@
  *         attentions.
  *
  * @param[out] o_dumpParameters Dump request parameters
- * @return True if an active attenion was successfully analyzed, false
- *         otherwise.
- *         For system checkstop handling:
- *            If analysis fails, there likely is a defect in the design because
- *            an active attention is required to trigger the interrupt.
- *         For TI handling:
- *            It is possible that a recoverable attention could cause a TI,
- *            however, it is not required. Therefore, it is expected that
- *            analysis could fail to find an attention and it should not be
- *            treated as a defect.
+ * @return The platform log ID (PLID) of the PEL generated during analysis. Will
+ *         return zero if no PEL is generated.
  */
-bool analyzeHardware(attn::DumpParameters& o_dumpParameters);
+uint32_t analyzeHardware(attn::DumpParameters& o_dumpParameters);
 
 /**
  * @brief Get error analyzer build information
diff --git a/analyzer/create_pel.cpp b/analyzer/create_pel.cpp
index adc2264..bef001e 100644
--- a/analyzer/create_pel.cpp
+++ b/analyzer/create_pel.cpp
@@ -308,9 +308,11 @@
 
 //------------------------------------------------------------------------------
 
-std::tuple<uint32_t, uint32_t> createPel(const libhei::IsolationData& i_isoData,
-                                         const ServiceData& i_servData)
+uint32_t createPel(const libhei::IsolationData& i_isoData,
+                   const ServiceData& i_servData)
 {
+    uint32_t o_plid = 0; // default, zero indicates PEL was not created
+
     // The message registry will require additional log data to fill in keywords
     // and additional log data.
     std::map<std::string, std::string> logData;
@@ -348,9 +350,6 @@
     std::vector<util::FFDCTuple> userData;
     util::transformFFDC(userDataFiles, userData);
 
-    // Response will be a tuple containing bmc-log-id, pel-log-id
-    std::tuple<uint32_t, uint32_t> response = {0, 0};
-
     try
     {
         // We want to use the logging interface that returns the event log
@@ -387,8 +386,13 @@
             // Log the event.
             auto reply = bus.call(method);
 
+            // Response will be a tuple containing bmc-log-id, pel-log-id
+            std::tuple<uint32_t, uint32_t> response = {0, 0};
+
             // Parse reply for response
             reply.read(response);
+
+            o_plid = std::get<1>(response);
         }
     }
     catch (const sdbusplus::exception::SdBusError& e)
@@ -398,8 +402,8 @@
         trace::err(exceptionString.c_str());
     }
 
-    // return tuple of {bmc-log-id, pel-log-id} or {0, 0} on error
-    return response;
+    // Return the platorm log ID of the error.
+    return o_plid;
 }
 
 } // namespace analyzer
diff --git a/attn/attn_dump.cpp b/attn/attn_dump.cpp
index 3f325bd..52bfca0 100644
--- a/attn/attn_dump.cpp
+++ b/attn/attn_dump.cpp
@@ -78,7 +78,7 @@
 }
 
 /** Request a dump from the dump manager */
-void requestDump(const DumpParameters& i_dumpParameters)
+void requestDump(uint32_t i_logId, const DumpParameters& i_dumpParameters)
 {
     constexpr auto path      = "/org/openpower/dump";
     constexpr auto interface = "xyz.openbmc_project.Dump.Create";
@@ -94,7 +94,7 @@
             std::map<std::string, std::variant<std::string, uint64_t>>
                 createParams;
             createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] =
-                uint64_t(i_dumpParameters.logId);
+                uint64_t(i_logId);
             if (DumpType::Hostboot == i_dumpParameters.dumpType)
             {
                 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
diff --git a/attn/attn_dump.hpp b/attn/attn_dump.hpp
index d7cdfac..289aea5 100644
--- a/attn/attn_dump.hpp
+++ b/attn/attn_dump.hpp
@@ -16,7 +16,6 @@
 class DumpParameters
 {
   public:
-    uint32_t logId;
     uint32_t unitId;
     DumpType dumpType;
 };
@@ -27,8 +26,9 @@
  * Request a dump from the dump manager and register a monitor for observing
  * the dump progress.
  *
+ * @param i_logId        The platform log ID associated with the dump request.
  * @param dumpParameters Parameters for the dump request
  */
-void requestDump(const DumpParameters& dumpParameters);
+void requestDump(uint32_t i_logId, const DumpParameters& dumpParameters);
 
 } // namespace attn
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index 4022d06..65bf7f9 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -249,13 +249,15 @@
         // Look for any attentions found in hardware. This will generate and
         // commit a PEL if any errors are found.
         DumpParameters dumpParameters;
-        if (true != analyzer::analyzeHardware(dumpParameters))
+        auto logid = analyzer::analyzeHardware(dumpParameters);
+        if (0 == logid)
         {
+            // A PEL should exist for a checkstop attention.
             rc = RC_ANALYZER_ERROR;
         }
         else
         {
-            requestDump(dumpParameters);
+            requestDump(logid, dumpParameters);
             util::dbus::transitionHost(util::dbus::HostState::Quiesce);
         }
     }
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index 3fb0572..279d212 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -219,9 +219,11 @@
     if (it != i_additional.end() && "true" == it->second)
     {
         DumpParameters dumpParameters;
-        if (analyzer::analyzeHardware(dumpParameters))
+        auto plid = analyzer::analyzeHardware(dumpParameters);
+        if (0 != plid)
         {
-            tiPel->setPlid(dumpParameters.logId);
+            // Link the PLID if an attention was found and a PEL was generated.
+            tiPel->setPlid(plid);
         }
     }
 
@@ -436,7 +438,7 @@
                 if ("true" == i_additional["Dump"])
                 {
                     // will not return until dump is complete
-                    requestDump(DumpParameters{pelId, 0, DumpType::Hostboot});
+                    requestDump(pelId, DumpParameters{0, DumpType::Hostboot});
                 }
             }
         }
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
index 6d28458..3a82bb4 100644
--- a/attn/ti_handler.cpp
+++ b/attn/ti_handler.cpp
@@ -137,7 +137,7 @@
         {
             // retrieve log ID from TI info data
             uint32_t logId = be32toh(i_tiDataArea->asciiData1);
-            requestDump(DumpParameters{logId, 0, DumpType::Hostboot});
+            requestDump(logId, DumpParameters{0, DumpType::Hostboot});
         }
     }
 
diff --git a/attn/vital_handler.cpp b/attn/vital_handler.cpp
index c07dfc7..4d4b0ce 100644
--- a/attn/vital_handler.cpp
+++ b/attn/vital_handler.cpp
@@ -36,7 +36,7 @@
         if ((0 != pelId) && (util::dbus::HostRunningState::NotStarted ==
                              util::dbus::hostRunningState()))
         {
-            requestDump(DumpParameters{pelId, 0, DumpType::SBE});
+            requestDump(pelId, DumpParameters{0, DumpType::SBE});
         }
 
         // transition host
diff --git a/main.cpp b/main.cpp
index 5bce1a5..c63cb80 100644
--- a/main.cpp
+++ b/main.cpp
@@ -11,7 +11,7 @@
  * This is the main interface to the hardware diagnostics application. This
  * application will either be loaded as a daemon for monitoring the attention
  * gpio or it will be loaded as an application to analyze hardware and
- * diagnose hadrware error conditions.
+ * diagnose hardware error conditions.
  *
  *     Usage:
  *        --analyze:              Analyze the hardware
@@ -60,7 +60,8 @@
         // Either analyze (application mode) or daemon mode
         if (true == getCliOption(argv, argv + argc, "--analyze"))
         {
-            rc = analyzer::analyzeHardware(); // analyze hardware
+            attn::DumpParameters dumpParameters;
+            analyzer::analyzeHardware(dumpParameters); // analyze hardware
         }
         // daemon mode
         else
diff --git a/main_nl.cpp b/main_nl.cpp
index 16baa36..227c6a6 100644
--- a/main_nl.cpp
+++ b/main_nl.cpp
@@ -49,7 +49,7 @@
         if (true == getCliOption(argv, argv + argc, "--analyze"))
         {
             attn::DumpParameters dumpParameters;
-            rc = analyzer::analyzeHardware(dumpParameters); // analyze hardware
+            analyzer::analyzeHardware(dumpParameters); // analyze hardware
         }
         // daemon mode
         else