1815f9f55STom Joseph #pragma once 2db38e91aSRashmica Gupta 3bae4d07eSChris Cain #include "occ_events.hpp" 4815f9f55STom Joseph #include "occ_status.hpp" 5f3b7514eSGeorge Liu #include "utils.hpp" 6815f9f55STom Joseph 7db38e91aSRashmica Gupta #include <libpldm/instance-id.h> 800325238STom Joseph #include <libpldm/pldm.h> 952328cb4SRashmica Gupta #include <libpldm/transport.h> 106213f199SLakshmi Yadlapati #include <libpldm/transport/af-mctp.h> 1152328cb4SRashmica Gupta #include <libpldm/transport/mctp-demux.h> 1200325238STom Joseph 13815f9f55STom Joseph #include <sdbusplus/bus/match.hpp> 14bae4d07eSChris Cain #include <sdeventplus/event.hpp> 15bae4d07eSChris Cain #include <sdeventplus/utility/timer.hpp> 16815f9f55STom Joseph 17f0295f52SChris Cain enum pldm_msg_type 18f0295f52SChris Cain { 19f0295f52SChris Cain MSG_UNDEFINED = 0, 20f0295f52SChris Cain MSG_SENSOR_STATUS = 1, 21f0295f52SChris Cain MSG_OCC_RESET = 2, 22f0295f52SChris Cain MSG_HRESET = 3 23f0295f52SChris Cain }; 24f0295f52SChris Cain 25815f9f55STom Joseph namespace pldm 26815f9f55STom Joseph { 27815f9f55STom Joseph 28815f9f55STom Joseph namespace MatchRules = sdbusplus::bus::match::rules; 29bae4d07eSChris Cain using namespace open_power::occ; 30815f9f55STom Joseph 3100325238STom Joseph using CompositeEffecterCount = uint8_t; 3200325238STom Joseph using EffecterID = uint16_t; 33815f9f55STom Joseph using EntityType = uint16_t; 34815f9f55STom Joseph using EntityInstance = uint16_t; 35815f9f55STom Joseph using EventState = uint8_t; 36cbad219eSEddie James using InstanceToEffecter = std::map<open_power::occ::instanceID, EffecterID>; 37815f9f55STom Joseph using PdrList = std::vector<std::vector<uint8_t>>; 38815f9f55STom Joseph using SensorID = uint16_t; 39815f9f55STom Joseph using SensorOffset = uint8_t; 40cbad219eSEddie James using SensorToInstance = std::map<SensorID, open_power::occ::instanceID>; 41815f9f55STom Joseph using TerminusID = uint8_t; 42815f9f55STom Joseph 43815f9f55STom Joseph /** @brief OCC instance starts with 0 for example "occ0" */ 44815f9f55STom Joseph constexpr open_power::occ::instanceID start = 0; 45815f9f55STom Joseph 4600325238STom Joseph /** @brief Hardcoded mctpEid for HBRT */ 4700325238STom Joseph constexpr mctp_eid_t mctpEid = 10; 48815f9f55STom Joseph 4952328cb4SRashmica Gupta /** @brief Hardcoded TID */ 5052328cb4SRashmica Gupta constexpr TerminusID tid = mctpEid; 5152328cb4SRashmica Gupta 52815f9f55STom Joseph /** @class Interface 53815f9f55STom Joseph * 54815f9f55STom Joseph * @brief Abstracts the PLDM details related to the OCC 55815f9f55STom Joseph */ 56815f9f55STom Joseph class Interface 57815f9f55STom Joseph { 58815f9f55STom Joseph public: 59815f9f55STom Joseph Interface() = delete; 60db38e91aSRashmica Gupta //~Interface() = default; 61815f9f55STom Joseph Interface(const Interface&) = delete; 62815f9f55STom Joseph Interface& operator=(const Interface&) = delete; 63815f9f55STom Joseph Interface(Interface&&) = delete; 64815f9f55STom Joseph Interface& operator=(Interface&&) = delete; 65815f9f55STom Joseph 66815f9f55STom Joseph /** @brief Constructs the PLDM Interface object for OCC functions 67815f9f55STom Joseph * 68f0295f52SChris Cain * @param[in] occActiveCallBack - callBack handler to invoke when the OCC 69f0295f52SChris Cain * state changes. 70f0295f52SChris Cain * @param[in] sbeCallBack - callBack handler to invoke when the SBE 71f0295f52SChris Cain * state changes. 72f0295f52SChris Cain * @param[in] safeModeCallBack - callBack handler to invoke when the 73f0295f52SChris Cain * system is in safe mode. 74*c488bac1SChris Cain * @param[in] poweredOffCallBack - callBack handler to invoke when the 75*c488bac1SChris Cain * host is powered off. 76815f9f55STom Joseph */ Interface(std::function<bool (open_power::occ::instanceID,bool)> occActiveCallBack,std::function<void (open_power::occ::instanceID,bool)> sbeCallBack,std::function<void (bool)> safeModeCallBack,std::function<void ()> poweredOffCallBack,EventPtr & event)77815f9f55STom Joseph explicit Interface( 78f0295f52SChris Cain std::function<bool(open_power::occ::instanceID, bool)> 79f0295f52SChris Cain occActiveCallBack, 80bae4d07eSChris Cain std::function<void(open_power::occ::instanceID, bool)> sbeCallBack, 81*c488bac1SChris Cain std::function<void(bool)> safeModeCallBack, 82*c488bac1SChris Cain std::function<void()> poweredOffCallBack, EventPtr& event) : 83f0295f52SChris Cain occActiveCallBack(occActiveCallBack), sbeCallBack(sbeCallBack), 84*c488bac1SChris Cain safeModeCallBack(safeModeCallBack), 85*c488bac1SChris Cain poweredOffCallBack(poweredOffCallBack), event(event), 86815f9f55STom Joseph pldmEventSignal( 8748330578SChris Cain open_power::occ::utils::getBus(), 88815f9f55STom Joseph MatchRules::type::signal() + 89815f9f55STom Joseph MatchRules::member("StateSensorEvent") + 90815f9f55STom Joseph MatchRules::path("/xyz/openbmc_project/pldm") + 91815f9f55STom Joseph MatchRules::interface("xyz.openbmc_project.PLDM.Event"), 92815f9f55STom Joseph std::bind(std::mem_fn(&Interface::sensorEvent), this, 93815f9f55STom Joseph std::placeholders::_1)), 94157467d0SChris Cain hostStateSignal( 95157467d0SChris Cain open_power::occ::utils::getBus(), 96157467d0SChris Cain MatchRules::propertiesChanged("/xyz/openbmc_project/state/host0", 97157467d0SChris Cain "xyz.openbmc_project.State.Host"), 98157467d0SChris Cain std::bind(std::mem_fn(&Interface::hostStateEvent), this, 99157467d0SChris Cain std::placeholders::_1)), 100bae4d07eSChris Cain sdpEvent(sdeventplus::Event::get_default()), 101bae4d07eSChris Cain pldmRspTimer( 102bae4d07eSChris Cain sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>( 103bae4d07eSChris Cain sdpEvent, std::bind(&Interface::pldmRspExpired, this))) 104db38e91aSRashmica Gupta { 105db38e91aSRashmica Gupta int rc = pldm_instance_db_init_default(&pldmInstanceIdDb); 106db38e91aSRashmica Gupta if (rc) 107db38e91aSRashmica Gupta { 108db38e91aSRashmica Gupta throw std::system_category().default_error_condition(rc); 109db38e91aSRashmica Gupta } 110db38e91aSRashmica Gupta } 111db38e91aSRashmica Gupta ~Interface()112db38e91aSRashmica Gupta ~Interface() 113db38e91aSRashmica Gupta { 114db38e91aSRashmica Gupta int rc = pldm_instance_db_destroy(pldmInstanceIdDb); 115db38e91aSRashmica Gupta if (rc) 116db38e91aSRashmica Gupta { 117db38e91aSRashmica Gupta std::cout << "pldm_instance_db_destroy failed, rc =" << rc << "\n"; 118db38e91aSRashmica Gupta } 119db38e91aSRashmica Gupta } 120815f9f55STom Joseph 121cbad219eSEddie James /** @brief Fetch the state sensor PDRs and populate the cache with 122cbad219eSEddie James * sensorId to OCC/SBE instance mapping information and the sensor 123cbad219eSEddie James * offset for the relevent state set. 124815f9f55STom Joseph * 125cbad219eSEddie James * @param[in] stateSetId - the state set ID to look for 126cbad219eSEddie James * @param[out] sensorInstanceMap - map of sensorID to instance 127815f9f55STom Joseph * @param[out] sensorOffset - sensor offset of interested state set ID 128815f9f55STom Joseph */ 129cbad219eSEddie James void fetchSensorInfo(uint16_t stateSetId, 130cbad219eSEddie James SensorToInstance& sensorInstanceMap, 131815f9f55STom Joseph SensorOffset& sensorOffset); 132815f9f55STom Joseph 133cbad219eSEddie James /** @brief Fetch the OCC/SBE state effecter PDRs and populate the cache 134cbad219eSEddie James * with OCC/SBE instance to EffecterID information. 13500325238STom Joseph * 136cbad219eSEddie James * @param[in] stateSetId - the state set ID to look for 137cbad219eSEddie James * @param[out] instanceToEffecterMap - map of instance to effecterID 13800325238STom Joseph * @param[out] count - sensor offset of interested state set ID 139cbad219eSEddie James * @param[out] stateIdPos - position of the stateSetID 14000325238STom Joseph */ 141432dc486SEddie James void fetchEffecterInfo(uint16_t stateSetId, 142cbad219eSEddie James InstanceToEffecter& instanceToEffecterMap, 143cbad219eSEddie James CompositeEffecterCount& count, uint8_t& stateIdPos); 14400325238STom Joseph 14500325238STom Joseph /** @brief Prepare the request for SetStateEffecterStates command 14600325238STom Joseph * 147cbad219eSEddie James * @param[in] effecterId - the instance effecter ID 148cbad219eSEddie James * @param[in] effecterCount - compositeEffecterCount for the effecter PDR 149cbad219eSEddie James * @param[in] stateIdPos - position of the stateSetID 150cbad219eSEddie James * @param[in] stateSetValue - the value to set the state set to 15100325238STom Joseph * 152cbad219eSEddie James * @return PLDM request message to be sent to host for OCC reset or SBE 153cbad219eSEddie James * HRESET, empty response in the case of failure. 15400325238STom Joseph */ 155d7542c83SPatrick Williams std::vector<uint8_t> prepareSetEffecterReq( 156d7542c83SPatrick Williams EffecterID effecterId, CompositeEffecterCount effecterCount, 157cbad219eSEddie James uint8_t stateIdPos, uint8_t stateSetValue); 15800325238STom Joseph 15900325238STom Joseph /** @brief Send the PLDM message to reset the OCC 16000325238STom Joseph * 16100325238STom Joseph * @param[in] instanceId - OCC instance to reset 16200325238STom Joseph * 16300325238STom Joseph */ 16400325238STom Joseph void resetOCC(open_power::occ::instanceID occInstanceId); 16500325238STom Joseph 166cbad219eSEddie James /** @brief Send the PLDM message to perform the HRESET 167cbad219eSEddie James * 168cbad219eSEddie James * @param[in] instanceID - SBE instance to HRESET 169cbad219eSEddie James */ 170cbad219eSEddie James void sendHRESET(open_power::occ::instanceID sbeInstanceId); 171cbad219eSEddie James 172bae4d07eSChris Cain /** @brief Check if the OCC active sensor is available 173bae4d07eSChris Cain * On successful read, the Manager callback will be called to update 174bae4d07eSChris Cain * the status 175bae4d07eSChris Cain * 176bae4d07eSChris Cain * @param[in] instance - OCC instance to check 177bae4d07eSChris Cain */ 178bae4d07eSChris Cain void checkActiveSensor(uint8_t instance); 179bae4d07eSChris Cain 180755af102SChris Cain /** @brief Set the throttleTraces flag 181755af102SChris Cain * 182755af102SChris Cain * @param[in] throttle - Flag to indicate if traces should be throttled 183755af102SChris Cain */ 184755af102SChris Cain void setTraceThrottle(const bool throttle); 185755af102SChris Cain 186815f9f55STom Joseph private: 187db38e91aSRashmica Gupta /** @brief PLDM instance ID database object used to get instance IDs 188db38e91aSRashmica Gupta */ 189db38e91aSRashmica Gupta pldm_instance_db* pldmInstanceIdDb = nullptr; 190db38e91aSRashmica Gupta 191aeba51cdSRashmica Gupta /** @brief PLDM instance number used in PLDM requests 1928b508bfbSChris Cain */ 193aeba51cdSRashmica Gupta std::optional<uint8_t> pldmInstanceID; 1948b508bfbSChris Cain 195815f9f55STom Joseph /** @brief Callback handler to be invoked when the state of the OCC 196815f9f55STom Joseph * changes 197815f9f55STom Joseph */ 198f0295f52SChris Cain std::function<bool(open_power::occ::instanceID, bool)> occActiveCallBack = 199f0295f52SChris Cain nullptr; 200815f9f55STom Joseph 201cbad219eSEddie James /** @brief Callback handler to be invoked when the maintenance state of the 202cbad219eSEddie James * SBE changes 203cbad219eSEddie James */ 204cbad219eSEddie James std::function<void(open_power::occ::instanceID, bool)> sbeCallBack = 205cbad219eSEddie James nullptr; 206cbad219eSEddie James 20731a2f13aSSheldon Bailey /** @brief Callback handler to be invoked when the OCC is in SAFE Mode = 20831a2f13aSSheldon Bailey * true or when OCCs are in_service = false. 20931a2f13aSSheldon Bailey */ 21031a2f13aSSheldon Bailey std::function<void(bool)> safeModeCallBack = nullptr; 21131a2f13aSSheldon Bailey 212*c488bac1SChris Cain /** @brief Callback handler to be invoked when the host is powered off */ 213*c488bac1SChris Cain std::function<void()> poweredOffCallBack = nullptr; 214*c488bac1SChris Cain 215bae4d07eSChris Cain /** @brief reference to sd_event wrapped in unique_ptr */ 216bae4d07eSChris Cain EventPtr& event; 217bae4d07eSChris Cain 218bae4d07eSChris Cain /** @brief event source wrapped in unique_ptr */ 219bae4d07eSChris Cain EventSourcePtr eventSource; 220bae4d07eSChris Cain 221815f9f55STom Joseph /** @brief Used to subscribe to D-Bus PLDM StateSensorEvent signal and 222815f9f55STom Joseph * processes if the event corresponds to OCC state change. 223815f9f55STom Joseph */ 224815f9f55STom Joseph sdbusplus::bus::match_t pldmEventSignal; 225815f9f55STom Joseph 226157467d0SChris Cain /** @brief Used to subscribe for host state change signal */ 227157467d0SChris Cain sdbusplus::bus::match_t hostStateSignal; 228157467d0SChris Cain 229815f9f55STom Joseph /** @brief PLDM Sensor ID to OCC Instance mapping 230815f9f55STom Joseph */ 231cbad219eSEddie James SensorToInstance sensorToOCCInstance; 232815f9f55STom Joseph 233cbad219eSEddie James /** @brief PLDM Sensor ID to SBE Instance mapping 234cbad219eSEddie James */ 235cbad219eSEddie James SensorToInstance sensorToSBEInstance; 236cbad219eSEddie James 237cbad219eSEddie James /** @brief Sensor offset of OCC state set ID 238815f9f55STom Joseph * PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS in state sensor PDR. 239815f9f55STom Joseph */ 240f3a4a69fSGeorge Liu SensorOffset OCCSensorOffset = 0; 241cbad219eSEddie James 242cbad219eSEddie James /** @brief Sensor offset of the SBE state set ID 243cbad219eSEddie James * PLDM_OEM_IBM_SBE_HRESET_STATE in state sensor PDR. 244cbad219eSEddie James */ 245f3a4a69fSGeorge Liu SensorOffset SBESensorOffset = 0; 246815f9f55STom Joseph 24700325238STom Joseph /** @brief OCC Instance mapping to PLDM Effecter ID 24800325238STom Joseph */ 249cbad219eSEddie James InstanceToEffecter occInstanceToEffecter; 250cbad219eSEddie James 251cbad219eSEddie James /** @brief SBE instance mapping to PLDM Effecter ID 252cbad219eSEddie James */ 253cbad219eSEddie James InstanceToEffecter sbeInstanceToEffecter; 25400325238STom Joseph 25500325238STom Joseph /** @brief compositeEffecterCount for OCC reset state effecter PDR */ 256cbad219eSEddie James CompositeEffecterCount OCCEffecterCount = 0; 257cbad219eSEddie James 258cbad219eSEddie James /** @brief compositeEffecterCount for SBE HRESET state effecter PDR */ 259cbad219eSEddie James CompositeEffecterCount SBEEffecterCount = 0; 26000325238STom Joseph 26100325238STom Joseph /** @brief Position of Boot/Restart Cause stateSetID in OCC state 26200325238STom Joseph * effecter PDR 26300325238STom Joseph */ 26400325238STom Joseph uint8_t bootRestartPosition = 0; 26500325238STom Joseph 266cbad219eSEddie James /** @brief Position of the SBE maintenance stateSetID in the state 267cbad219eSEddie James * effecter PDR 268cbad219eSEddie James */ 269cbad219eSEddie James uint8_t sbeMaintenanceStatePosition = 0; 270cbad219eSEddie James 271bae4d07eSChris Cain /** @brief OCC instance number for the PLDM message */ 272bae4d07eSChris Cain uint8_t pldmResponseOcc = 0; 273bae4d07eSChris Cain 274bae4d07eSChris Cain /** @brief File descriptor for PLDM messages */ 275bae4d07eSChris Cain int pldmFd = -1; 276bae4d07eSChris Cain 27752328cb4SRashmica Gupta /** pldm transport instance */ 27852328cb4SRashmica Gupta struct pldm_transport* pldmTransport = NULL; 27952328cb4SRashmica Gupta 280f0295f52SChris Cain static enum pldm_msg_type msgType; 281f0295f52SChris Cain 2826213f199SLakshmi Yadlapati union TransportImpl 2836213f199SLakshmi Yadlapati { 28452328cb4SRashmica Gupta struct pldm_transport_mctp_demux* mctpDemux; 2856213f199SLakshmi Yadlapati struct pldm_transport_af_mctp* afMctp; 2866213f199SLakshmi Yadlapati }; 2876213f199SLakshmi Yadlapati 2886213f199SLakshmi Yadlapati TransportImpl impl; 28952328cb4SRashmica Gupta 290bae4d07eSChris Cain /** @brief The response for the PLDM request msg is received flag. 291bae4d07eSChris Cain */ 292bae4d07eSChris Cain bool pldmResponseReceived = false; 293bae4d07eSChris Cain 294bae4d07eSChris Cain /** @brief The response for the PLDM request has timed out. 295bae4d07eSChris Cain */ 296bae4d07eSChris Cain bool pldmResponseTimeout = false; 297bae4d07eSChris Cain 298f0295f52SChris Cain /** @brief The instance ID for the OCC/HRESET request */ 299f0295f52SChris Cain static open_power::occ::instanceID resetInstance; 300f0295f52SChris Cain 301bae4d07eSChris Cain /** @brief timer event */ 302bae4d07eSChris Cain sdeventplus::Event sdpEvent; 303bae4d07eSChris Cain 304bae4d07eSChris Cain /** @brief Timer that is started when PLDM command is sent 305bae4d07eSChris Cain */ 306bae4d07eSChris Cain sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> pldmRspTimer; 307bae4d07eSChris Cain 30812d0b828SChris Cain std::set<uint8_t> outstandingHResets; 30912d0b828SChris Cain 310755af102SChris Cain /** @brief Flag to indicate that traces should be throttled. 311755af102SChris Cain Used to limit traces when there are issues getting OCC status. 312755af102SChris Cain */ 313755af102SChris Cain static bool throttleTraces; 314755af102SChris Cain 315bae4d07eSChris Cain /** @brief Callback when PLDM response has not been received within the 316bae4d07eSChris Cain * timeout period. 317bae4d07eSChris Cain */ 318bae4d07eSChris Cain void pldmRspExpired(); 319bae4d07eSChris Cain 320bae4d07eSChris Cain /** @brief Close the MCTP file */ 321bae4d07eSChris Cain void pldmClose(); 322bae4d07eSChris Cain 323815f9f55STom Joseph /** @brief When the OCC state changes host sends PlatformEventMessage 324815f9f55STom Joseph * StateSensorEvent, this function processes the D-Bus signal 325815f9f55STom Joseph * with the sensor event information and invokes the callback 326815f9f55STom Joseph * to change the OCC state. 327815f9f55STom Joseph * 328815f9f55STom Joseph * @param[in] msg - data associated with the subscribed signal 329815f9f55STom Joseph */ 330af40808fSPatrick Williams void sensorEvent(sdbusplus::message_t& msg); 331815f9f55STom Joseph 332157467d0SChris Cain /** @brief When the host state changes and if the CurrentHostState is 333157467d0SChris Cain * xyz.openbmc_project.State.Host.HostState.Off then 334157467d0SChris Cain * the cache of OCC sensors and effecters mapping is cleared. 335157467d0SChris Cain * 336157467d0SChris Cain * @param[in] msg - data associated with the subscribed signal 337157467d0SChris Cain */ 338af40808fSPatrick Williams void hostStateEvent(sdbusplus::message_t& msg); 339157467d0SChris Cain 340bae4d07eSChris Cain /** @brief Called when it is determined that the Host is not running. 341bae4d07eSChris Cain * The cache of OCC sensors and effecters mapping is cleared. 342bae4d07eSChris Cain */ 343bae4d07eSChris Cain void clearData(); 344bae4d07eSChris Cain 345815f9f55STom Joseph /** @brief Check if the PDR cache for PLDM OCC sensors is valid 346815f9f55STom Joseph * 347815f9f55STom Joseph * @return true if cache is populated and false if the cache is not 348815f9f55STom Joseph * populated. 349815f9f55STom Joseph */ isOCCSensorCacheValid()350815f9f55STom Joseph auto isOCCSensorCacheValid() 351815f9f55STom Joseph { 352815f9f55STom Joseph return (sensorToOCCInstance.empty() ? false : true); 353815f9f55STom Joseph } 35400325238STom Joseph 35500325238STom Joseph /** @brief Check if the PDR cache for PLDM OCC effecters is valid 35600325238STom Joseph * 35700325238STom Joseph * @return true if cache is populated and false if the cache is not 35800325238STom Joseph * populated. 35900325238STom Joseph */ isPDREffecterCacheValid()36000325238STom Joseph auto isPDREffecterCacheValid() 36100325238STom Joseph { 36200325238STom Joseph return (occInstanceToEffecter.empty() ? false : true); 36300325238STom Joseph } 364cbad219eSEddie James 365db38e91aSRashmica Gupta /** @brief Get a PLDM requester instance id 366cbad219eSEddie James * 367cbad219eSEddie James * @return true if the id was found and false if not 368cbad219eSEddie James */ 369aeba51cdSRashmica Gupta bool getPldmInstanceId(); 370cbad219eSEddie James 371db38e91aSRashmica Gupta /** @brief Free PLDM requester instance id */ 372db38e91aSRashmica Gupta void freePldmInstanceId(); 373db38e91aSRashmica Gupta 374bae4d07eSChris Cain /** @brief Encode a GetStateSensor command into a PLDM request 375bae4d07eSChris Cain * @param[in] instance - OCC instance number 376bae4d07eSChris Cain * @param[in] sensorId - OCC Active sensor ID number 377bae4d07eSChris Cain * 378bae4d07eSChris Cain * @return request - The encoded PLDM messsage to be sent 379bae4d07eSChris Cain */ 3802d6ec909SPatrick Williams std::vector<uint8_t> encodeGetStateSensorRequest(uint8_t instance, 3812d6ec909SPatrick Williams uint16_t sensorId); 38252328cb4SRashmica Gupta 38352328cb4SRashmica Gupta /** @brief setup PLDM transport for sending and receiving PLDM messages. 38452328cb4SRashmica Gupta * 38552328cb4SRashmica Gupta * @return true on success, otherwise return false 38652328cb4SRashmica Gupta */ 38752328cb4SRashmica Gupta int pldmOpen(void); 38852328cb4SRashmica Gupta 38952328cb4SRashmica Gupta /** @brief Opens the MCTP socket for sending and receiving messages. 39052328cb4SRashmica Gupta * 3916213f199SLakshmi Yadlapati * @return 0 on success, otherwise returns a negative error code 39252328cb4SRashmica Gupta */ 39352328cb4SRashmica Gupta int openMctpDemuxTransport(); 39452328cb4SRashmica Gupta 3956213f199SLakshmi Yadlapati /** @brief Opens the MCTP AF_MCTP for sending and receiving messages. 3966213f199SLakshmi Yadlapati * 3976213f199SLakshmi Yadlapati * @return 0 on success, otherwise returns a negative error code 3986213f199SLakshmi Yadlapati */ 3996213f199SLakshmi Yadlapati int openAfMctpTransport(); 4006213f199SLakshmi Yadlapati 401cbad219eSEddie James /** @brief Send the PLDM request 402cbad219eSEddie James * 403d1b6826aSChris Cain * @param[in] request - the request data 404bae4d07eSChris Cain * @param[in] rspExpected - false: no need to wait for the response 405bae4d07eSChris Cain * true: will need to process response in callback 406cbad219eSEddie James */ 407bae4d07eSChris Cain void sendPldm(const std::vector<uint8_t>& request, const uint8_t instance, 408bae4d07eSChris Cain const bool rspExpected = false); 409bae4d07eSChris Cain 410bae4d07eSChris Cain /** @brief Register a callback function to handle the PLDM response */ 411bae4d07eSChris Cain void registerPldmRspCallback(); 412bae4d07eSChris Cain 413bae4d07eSChris Cain /** @brief callback for the PLDM response event 414bae4d07eSChris Cain * 415bae4d07eSChris Cain * @param[in] es - Populated event source 416bae4d07eSChris Cain * @param[in] fd - Associated File descriptor 417bae4d07eSChris Cain * @param[in] revents - Type of event 418bae4d07eSChris Cain * @param[in] userData - User data that was passed during registration 419bae4d07eSChris Cain * 420bae4d07eSChris Cain * @return - 0 or positive number on success and negative 421bae4d07eSChris Cain * errno otherwise 422bae4d07eSChris Cain */ 423bae4d07eSChris Cain static int pldmRspCallback(sd_event_source* es, int fd, uint32_t revents, 424bae4d07eSChris Cain void* userData); 425f0295f52SChris Cain 426f0295f52SChris Cain /** @brief callback for a OCC / HRESET response event 427f0295f52SChris Cain * 428f0295f52SChris Cain * @param[in] es - Populated event source 429f0295f52SChris Cain * @param[in] fd - Associated File descriptor 430f0295f52SChris Cain * @param[in] revents - Type of event 431f0295f52SChris Cain * @param[in] userData - User data that was passed during registration 432f0295f52SChris Cain * 433f0295f52SChris Cain * @return - 0 or positive number on success and negative 434f0295f52SChris Cain * errno otherwise 435f0295f52SChris Cain */ 436f0295f52SChris Cain static int pldmResetCallback(sd_event_source* /*es*/, 437f0295f52SChris Cain __attribute__((unused)) int fd, 438f0295f52SChris Cain uint32_t revents, void* userData); 439815f9f55STom Joseph }; 440815f9f55STom Joseph 441815f9f55STom Joseph } // namespace pldm 442f0295f52SChris Cain 443f0295f52SChris Cain template <> 444f0295f52SChris Cain struct std::formatter<enum pldm_msg_type> : formatter<int> 445f0295f52SChris Cain { formatstd::formatter446f0295f52SChris Cain auto format(enum pldm_msg_type m, format_context& ctx) const 447f0295f52SChris Cain { 448f0295f52SChris Cain return formatter<int>::format(std::to_underlying(m), ctx); 449f0295f52SChris Cain } 450f0295f52SChris Cain }; 451