Collect SBE dump during chip-op timeouts

Add support for collecting SBE dump during dump chip-op
failure.
 - Request SBE dump in the case of a chip-op timeout
 - Wait for the dump to complete the timeout

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I2f6693a3136803f3555d7e5dc00528bb9d004cdf
diff --git a/dump/sbe_dump_collector.cpp b/dump/sbe_dump_collector.cpp
index 58a34e7..9e7801c 100644
--- a/dump/sbe_dump_collector.cpp
+++ b/dump/sbe_dump_collector.cpp
@@ -138,18 +138,39 @@
     try
     {
         std::string event = sbeTypeAttributes.at(sbeType).chipOpFailure;
+        auto dumpIsRequired = false;
+
+        if (sbeError.errType() == openpower::phal::exception::SBE_CMD_TIMEOUT)
+        {
+            event = sbeTypeAttributes.at(sbeType).chipOpTimeout;
+            dumpIsRequired = true;
+        }
 
         openpower::dump::pel::FFDCData pelAdditionalData = {
             {"SRC6", std::format("{:X}{:X}", chipPos, (cmdClass | cmdType))}};
 
         openpower::dump::pel::createSbeErrorPEL(event, sbeError,
                                                 pelAdditionalData);
+        auto logId = openpower::dump::pel::createSbeErrorPEL(event, sbeError,
+                                                             pelAdditionalData);
+
+        // Request SBE Dump if required
+        if (dumpIsRequired)
+        {
+            util::requestSBEDump(chipPos, logId, sbeType);
+        }
     }
     catch (const std::out_of_range& e)
     {
         lg2::error("Unknown SBE Type({SBETYPE}) ErrorMsg({ERROR})", "SBETYPE",
                    sbeType, "ERROR", e);
     }
+    catch (const std::exception& e)
+    {
+        lg2::error("SBE Dump request failed, chip position({CHIPPOS}), "
+                   "Error: {ERROR}",
+                   "CHIPPOS", chipPos, "ERROR", e);
+    }
 }
 
 void SbeDumpCollector::collectDumpFromSBE(struct pdbg_target* chip,
@@ -192,11 +213,14 @@
         }
 
         lg2::error("Error in collecting dump dump type({TYPE}), "
-                   "clockstate({CLOCKSTATE}), proc position({PROC}), "
+                   "clockstate({CLOCKSTATE}), chip type({CHIPTYPE}) "
+                   "position({POSITION}), "
                    "collectFastArray({COLLECTFASTARRAY}) error({ERROR})",
-                   "TYPE", type, "CLOCKSTATE", clockState, "PROC", chipPos,
-                   "COLLECTFASTARRAY", collectFastArray, "ERROR", sbeError);
-
+                   "TYPE", type, "CLOCKSTATE", clockState, "CHIPTYPE", chipName,
+                   "POSITION", chipPos, "COLLECTFASTARRAY", collectFastArray,
+                   "ERROR", sbeError);
+        logErrorAndCreatePEL(sbeError, chipPos, sbeType, SBEFIFO_CMD_CLASS_DUMP,
+                             SBEFIFO_CMD_GET_DUMP);
         return;
     }
     writeDumpFile(path, id, clockState, 0, chipName, chipPos, dataPtr, len);