Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 3 | #include "libpldm/base.h" |
| 4 | #include "libpldm/platform.h" |
| 5 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 6 | #include "common/types.hpp" |
| 7 | #include "common/utils.hpp" |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 8 | #include "libpldmresponder/event_parser.hpp" |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 9 | #include "libpldmresponder/pdr_utils.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 10 | #include "pldmd/dbus_impl_requester.hpp" |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 11 | |
| 12 | #include <sdeventplus/event.hpp> |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 13 | #include <sdeventplus/source/event.hpp> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 14 | |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 15 | #include <deque> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 16 | #include <map> |
| 17 | #include <memory> |
| 18 | #include <vector> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 19 | |
| 20 | using namespace pldm::dbus_api; |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 21 | using namespace pldm::responder::events; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 22 | |
| 23 | namespace pldm |
| 24 | { |
| 25 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 26 | using EntityType = uint16_t; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 27 | // vector which would hold the PDR record handle data returned by |
| 28 | // pldmPDRRepositoryChgEvent event data |
| 29 | using ChangeEntry = uint32_t; |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 30 | using PDRRecordHandles = std::deque<ChangeEntry>; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 31 | |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 32 | /** @struct SensorEntry |
| 33 | * |
| 34 | * SensorEntry is a unique key which maps a sensorEventType request in the |
| 35 | * PlatformEventMessage command to a host sensor PDR. This struct is a key |
| 36 | * in a std::map, so implemented operator==and operator<. |
| 37 | */ |
| 38 | struct SensorEntry |
| 39 | { |
| 40 | pdr::TerminusID terminusID; |
| 41 | pdr::SensorID sensorID; |
| 42 | |
| 43 | bool operator==(const SensorEntry& e) const |
| 44 | { |
| 45 | return ((terminusID == e.terminusID) && (sensorID == e.sensorID)); |
| 46 | } |
| 47 | |
| 48 | bool operator<(const SensorEntry& e) const |
| 49 | { |
| 50 | return ((terminusID < e.terminusID) || |
| 51 | ((terminusID == e.terminusID) && (sensorID < e.sensorID))); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | using HostStateSensorMap = std::map<SensorEntry, pdr::SensorInfo>; |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 56 | using PDRList = std::vector<std::vector<uint8_t>>; |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 57 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 58 | /** @class HostPDRHandler |
| 59 | * @brief This class can fetch and process PDRs from host firmware |
| 60 | * @details Provides an API to fetch PDRs from the host firmware. Upon |
| 61 | * receiving the PDRs, they are stored into the BMC's primary PDR repo. |
| 62 | * Adjustments are made to entity association PDRs received from the host, |
| 63 | * because they need to be assimilated into the BMC's entity association |
| 64 | * tree. A PLDM event containing the record handles of the updated entity |
| 65 | * association PDRs is sent to the host. |
| 66 | */ |
| 67 | class HostPDRHandler |
| 68 | { |
| 69 | public: |
| 70 | HostPDRHandler() = delete; |
| 71 | HostPDRHandler(const HostPDRHandler&) = delete; |
| 72 | HostPDRHandler(HostPDRHandler&&) = delete; |
| 73 | HostPDRHandler& operator=(const HostPDRHandler&) = delete; |
| 74 | HostPDRHandler& operator=(HostPDRHandler&&) = delete; |
| 75 | ~HostPDRHandler() = default; |
| 76 | |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 77 | using TLPDRMap = std::map<pdr::TerminusHandle, pdr::TerminusID>; |
| 78 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 79 | /** @brief Constructor |
| 80 | * @param[in] mctp_fd - fd of MCTP communications socket |
| 81 | * @param[in] mctp_eid - MCTP EID of host firmware |
| 82 | * @param[in] event - reference of main event loop of pldmd |
| 83 | * @param[in] repo - pointer to BMC's primary PDR repo |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 84 | * @param[in] eventsJsonDir - directory path which has the config JSONs |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 85 | * @param[in] tree - pointer to BMC's entity association tree |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 86 | * @param[in] requester - reference to Requester object |
| 87 | */ |
| 88 | explicit HostPDRHandler(int mctp_fd, uint8_t mctp_eid, |
| 89 | sdeventplus::Event& event, pldm_pdr* repo, |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 90 | const std::string& eventsJsonsDir, |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 91 | pldm_entity_association_tree* entityTree, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 92 | pldm_entity_association_tree* bmcEntityTree, |
Sridevi Ramesh | ae28bc7 | 2020-12-10 07:21:16 -0600 | [diff] [blame] | 93 | Requester& requester, bool verbose = false); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 94 | |
| 95 | /** @brief fetch PDRs from host firmware. See @class. |
| 96 | * @param[in] recordHandles - list of record handles pointing to host's |
| 97 | * PDRs that need to be fetched. |
| 98 | */ |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 99 | |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 100 | void fetchPDR(PDRRecordHandles&& recordHandles); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 101 | |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 102 | /** @brief Send a PLDM event to host firmware containing a list of record |
| 103 | * handles of PDRs that the host firmware has to fetch. |
| 104 | * @param[in] pdrTypes - list of PDR types that need to be looked up in the |
| 105 | * BMC repo |
| 106 | * @param[in] eventDataFormat - format for PDRRepositoryChgEvent in DSP0248 |
| 107 | */ |
| 108 | void sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes, |
| 109 | uint8_t eventDataFormat); |
| 110 | |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 111 | /** @brief Lookup host sensor info corresponding to requested SensorEntry |
| 112 | * |
| 113 | * @param[in] entry - TerminusID and SensorID |
| 114 | * |
| 115 | * @return SensorInfo corresponding to the input paramter SensorEntry |
| 116 | * throw std::out_of_range exception if not found |
| 117 | */ |
| 118 | const pdr::SensorInfo& lookupSensorInfo(const SensorEntry& entry) const |
| 119 | { |
| 120 | return sensorMap.at(entry); |
| 121 | } |
| 122 | |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 123 | /** @brief Handles state sensor event |
| 124 | * |
| 125 | * @param[in] entry - state sensor entry |
| 126 | * @param[in] state - event state |
| 127 | * |
| 128 | * @return PLDM completion code |
| 129 | */ |
| 130 | int handleStateSensorEvent(const StateSensorEntry& entry, |
| 131 | pdr::EventState state); |
| 132 | |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 133 | /** @brief Parse state sensor PDRs and populate the sensorMap lookup data |
| 134 | * structure |
| 135 | * |
| 136 | * @param[in] stateSensorPDRs - host state sensor PDRs |
| 137 | * @param[in] tlpdrInfo - terminus locator PDRs info |
| 138 | * |
| 139 | */ |
| 140 | void parseStateSensorPDRs(const PDRList& stateSensorPDRs, |
| 141 | const TLPDRMap& tlpdrInfo); |
| 142 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 143 | private: |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 144 | /** @brief fetchPDR schedules work on the event loop, this method does the |
| 145 | * actual work. This is so that the PDR exchg with the host is async. |
| 146 | * @param[in] source - sdeventplus event source |
| 147 | */ |
| 148 | void _fetchPDR(sdeventplus::source::EventBase& source); |
| 149 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 150 | /** @brief Merge host firmware's entity association PDRs into BMC's |
| 151 | * @details A merge operation involves adding a pldm_entity under the |
| 152 | * appropriate parent, and updating container ids. |
| 153 | * @param[in] pdr - entity association pdr |
| 154 | */ |
| 155 | void mergeEntityAssociations(const std::vector<uint8_t>& pdr); |
| 156 | |
| 157 | /** @brief Find parent of input entity type, from the entity association |
| 158 | * tree |
| 159 | * @param[in] type - PLDM entity type |
| 160 | * @param[out] parent - PLDM entity information of parent |
| 161 | * @return bool - true if parent found, false otherwise |
| 162 | */ |
| 163 | bool getParent(EntityType type, pldm_entity& parent); |
| 164 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 165 | /** @brief fd of MCTP communications socket */ |
| 166 | int mctp_fd; |
| 167 | /** @brief MCTP EID of host firmware */ |
| 168 | uint8_t mctp_eid; |
| 169 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 170 | * work. |
| 171 | */ |
| 172 | sdeventplus::Event& event; |
| 173 | /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */ |
| 174 | pldm_pdr* repo; |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 175 | |
| 176 | StateSensorHandler stateSensorHandler; |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 177 | /** @brief Pointer to BMC's and Host's entity association tree */ |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 178 | pldm_entity_association_tree* entityTree; |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 179 | |
| 180 | /** @brief Pointer to BMC's entity association tree */ |
| 181 | pldm_entity_association_tree* bmcEntityTree; |
| 182 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 183 | /** @brief reference to Requester object, primarily used to access API to |
| 184 | * obtain PLDM instance id. |
| 185 | */ |
| 186 | Requester& requester; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 187 | /** @brief sdeventplus event source */ |
| 188 | std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent; |
| 189 | /** @brief list of PDR record handles pointing to host's PDRs */ |
| 190 | PDRRecordHandles pdrRecordHandles; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 191 | /** @brief maps an entity type to parent pldm_entity from the BMC's entity |
| 192 | * association tree |
| 193 | */ |
| 194 | std::map<EntityType, pldm_entity> parents; |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 195 | /** @brief D-Bus property changed signal match */ |
| 196 | std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch; |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 197 | |
| 198 | /** @brief sensorMap is a lookup data structure that is build from the |
| 199 | * hostPDR that speeds up the lookup of <TerminusID, SensorID> in |
| 200 | * PlatformEventMessage command request. |
| 201 | */ |
| 202 | HostStateSensorMap sensorMap; |
Sridevi Ramesh | ae28bc7 | 2020-12-10 07:21:16 -0600 | [diff] [blame] | 203 | bool verbose; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | } // namespace pldm |