Add SBE timeout handling

Add an Error instance to detect SBE timeouts in the driver.
Refactor the PLDM code to handle another requeset type (the HRESET) and
another type of sensor event (success or failure of the HRESET).
Handle the timeout and the PLDM event state change in the Manager by
changing the SBE state and requesting an SBE dump if necessary.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Change-Id: I30d8f9de1914d9808ddb7b547cc57085a5e5779e
diff --git a/occ_manager.hpp b/occ_manager.hpp
index 5b97abc..e6e7a18 100644
--- a/occ_manager.hpp
+++ b/occ_manager.hpp
@@ -4,6 +4,8 @@
 #include "occ_status.hpp"
 #ifdef PLDM
 #include "pldm.hpp"
+
+#include <libphal.H>
 #endif
 #include "powercap.hpp"
 #include "utils.hpp"
@@ -74,6 +76,8 @@
         ,
         pldmHandle(std::make_unique<pldm::Interface>(
             std::bind(std::mem_fn(&Manager::updateOCCActive), this,
+                      std::placeholders::_1, std::placeholders::_2),
+            std::bind(std::mem_fn(&Manager::sbeHRESETResult), this,
                       std::placeholders::_1, std::placeholders::_2)))
 #endif
 #ifdef POWER10
@@ -98,6 +102,15 @@
         return activeCount;
     }
 
+#ifdef PLDM
+    /** @brief Called by a Device to report that the SBE timed out
+     *         and appropriate action should be taken
+     *
+     * @param[in] instance - the OCC instance id
+     */
+    void sbeTimeout(unsigned int instance);
+#endif
+
   private:
     /** @brief Creates the OCC D-Bus objects.
      */
@@ -195,6 +208,42 @@
      */
     bool updateOCCActive(instanceID instance, bool status);
 
+    /** @brief Callback handler invoked by PLDM sensor change when
+     *         the HRESET succeeds or fails.
+     *
+     *  @param[in] instance - the SBE instance id
+     *  @param[in] success - true if the HRESET succeeded, otherwise false
+     */
+    void sbeHRESETResult(instanceID instance, bool success);
+
+    /** @brief Helper function to check whether an SBE dump should be collected
+     *         now.
+     *
+     *  @param[in] instance - the SBE instance id
+     *
+     *  @return true if an SBE dump should be collected and false if not
+     */
+    bool sbeCanDump(unsigned int instance);
+
+    /** @brief Helper function to set the SBE state through PDBG/PHAL
+     *
+     * @param[in] instance - instance of the SBE
+     * @param[in] state - the state to which the SBE should be set
+     *
+     */
+    void setSBEState(unsigned int instance, enum sbe_state state);
+
+    /** @brief Helper function to get the SBE instance PDBG processor target
+     *
+     * @param[in] instance - the SBE instance id
+     *
+     * @return a pointer to the PDBG target
+     */
+    struct pdbg_target* getPdbgTarget(unsigned int instance);
+
+    /** @brief Whether pdbg_targets_init has been called */
+    bool pdbgInitialized = false;
+
     std::unique_ptr<pldm::Interface> pldmHandle = nullptr;
 #endif