pldm: Add support for OCC reset

BMC initiated OCC reset is translated to a SetStateEffecterStates
request for state effecter corresponding to the OCC instance.

Tested:

Invoked resetOCC path explicitly and verified that the
SetStateEffecterStates request message for OCCReset is accurate.

Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Change-Id: I4e0d211b51151d24bf0112819fc9f201698bfac0
diff --git a/pldm.hpp b/pldm.hpp
index 76d7e44..48f80c7 100644
--- a/pldm.hpp
+++ b/pldm.hpp
@@ -2,6 +2,8 @@
 

 #include "occ_status.hpp"

 

+#include <libpldm/pldm.h>

+

 #include <sdbusplus/bus/match.hpp>

 

 namespace pldm

@@ -9,20 +11,26 @@
 

 namespace MatchRules = sdbusplus::bus::match::rules;

 

+using CompositeEffecterCount = uint8_t;

+using EffecterID = uint16_t;

 using EntityType = uint16_t;

 using EntityInstance = uint16_t;

 using EventState = uint8_t;

+using OccInstanceToEffecter = std::map<open_power::occ::instanceID, EffecterID>;

 using PdrList = std::vector<std::vector<uint8_t>>;

 using SensorID = uint16_t;

 using SensorOffset = uint8_t;

 using SensorToOCCInstance = std::map<SensorID, open_power::occ::instanceID>;

 using TerminusID = uint8_t;

 

+/** @brief Hardcoded TID */

+constexpr TerminusID tid = 0;

+

 /** @brief OCC instance starts with 0 for example "occ0" */

 constexpr open_power::occ::instanceID start = 0;

 

-/** @brief Hardcoded TID */

-constexpr TerminusID tid = 0;

+/** @brief Hardcoded mctpEid for HBRT */

+constexpr mctp_eid_t mctpEid = 10;

 

 /** @class Interface

  *

@@ -78,6 +86,41 @@
                             SensorToOCCInstance& sensorInstanceMap,

                             SensorOffset& sensorOffset);

 

+    /** @brief Fetch the OCC state effecter PDRs and populate the cache with

+     *         OCC instance to EffecterID information.

+     *

+     *  @param[in] pdrs - OCC state effecter PDRs

+     *  @param[out] instanceToEffecterMap - map of OCC instance to effecterID

+     *  @param[out] count - sensor offset of interested state set ID

+     *  @param[out] bootRestartPos - position of Boot/Restart Cause stateSetID

+     */

+    void fetchOCCEffecterInfo(const PdrList& pdrs,

+                              OccInstanceToEffecter& instanceToEffecterMap,

+                              CompositeEffecterCount& count,

+                              uint8_t& bootRestartPos);

+

+    /** @brief Prepare the request for SetStateEffecterStates command

+     *

+     *  @param[in] instanceId - PLDM instanceID

+     *  @param[in] instanceToEffecterMap - map of OCC instance to effecterID

+     *  @param[in] count - compositeEffecterCount for OCC reset effecter PDR

+     *  @param[in] bootRestartPos - position of Boot/Restart Cause stateSetID

+     *

+     *  @return PLDM request message to be sent to host for OCC reset, empty

+     *          response in the case of failure.

+     */

+    std::vector<uint8_t>

+        prepareSetEffecterReq(uint8_t instanceId, EffecterID effecterId,

+                              CompositeEffecterCount effecterCount,

+                              uint8_t bootRestartPos);

+

+    /** @brief Send the PLDM message to reset the OCC

+     *

+     *  @param[in] instanceId - OCC instance to reset

+     *

+     */

+    void resetOCC(open_power::occ::instanceID occInstanceId);

+

   private:

     /** @brief reference to the systemd bus*/

     sdbusplus::bus::bus& bus;

@@ -104,6 +147,18 @@
      */

     SensorOffset sensorOffset;

 

+    /** @brief OCC Instance mapping to PLDM Effecter ID

+     */

+    OccInstanceToEffecter occInstanceToEffecter;

+

+    /** @brief compositeEffecterCount for OCC reset state effecter PDR */

+    CompositeEffecterCount effecterCount = 0;

+

+    /** @brief Position of Boot/Restart Cause stateSetID in OCC state

+     *         effecter PDR

+     */

+    uint8_t bootRestartPosition = 0;

+

     /** @brief When the OCC state changes host sends PlatformEventMessage

      *         StateSensorEvent, this function processes the D-Bus signal

      *         with the sensor event information and invokes the callback

@@ -130,6 +185,16 @@
     {

         return (sensorToOCCInstance.empty() ? false : true);

     }

+

+    /** @brief Check if the PDR cache for PLDM OCC effecters is valid

+     *

+     *  @return true if cache is populated and false if the cache is not

+     *          populated.

+     */

+    auto isPDREffecterCacheValid()

+    {

+        return (occInstanceToEffecter.empty() ? false : true);

+    }

 };

 

 } // namespace pldm