Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 1 | #include "host_pdr_handler.hpp" |
| 2 | |
Andrew Jeffery | 4668f5c | 2024-01-15 14:59:17 +1030 | [diff] [blame] | 3 | #include <libpldm/fru.h> |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 4 | #ifdef OEM_IBM |
Andrew Jeffery | 21f128d | 2024-01-15 15:34:26 +1030 | [diff] [blame] | 5 | #include <libpldm/oem/ibm/fru.h> |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 6 | #endif |
Kamalkumar Patel | 14107a1 | 2024-06-19 08:50:01 -0500 | [diff] [blame] | 7 | #include "dbus/custom_dbus.hpp" |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 8 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 9 | #include <nlohmann/json.hpp> |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 10 | #include <phosphor-logging/lg2.hpp> |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 11 | #include <sdeventplus/clock.hpp> |
| 12 | #include <sdeventplus/exception.hpp> |
| 13 | #include <sdeventplus/source/io.hpp> |
| 14 | #include <sdeventplus/source/time.hpp> |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 15 | |
Pavithra Barithaya | b3b84b4 | 2024-08-23 11:43:57 +0530 | [diff] [blame] | 16 | #include <cassert> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 17 | #include <fstream> |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 18 | #include <type_traits> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 19 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 20 | PHOSPHOR_LOG2_USING; |
| 21 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 22 | namespace pldm |
| 23 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 24 | using namespace pldm::responder::events; |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 25 | using namespace pldm::utils; |
| 26 | using namespace sdbusplus::bus::match::rules; |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 27 | using namespace pldm::responder::pdr_utils; |
Kamalkumar Patel | 516122e | 2024-05-07 04:39:32 -0500 | [diff] [blame] | 28 | using namespace pldm::hostbmc::utils; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 29 | using Json = nlohmann::json; |
| 30 | namespace fs = std::filesystem; |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 31 | using namespace pldm::dbus; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 32 | const Json emptyJson{}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 33 | |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 34 | template <typename T> |
| 35 | uint16_t extractTerminusHandle(std::vector<uint8_t>& pdr) |
| 36 | { |
| 37 | T* var = nullptr; |
| 38 | if (std::is_same<T, pldm_pdr_fru_record_set>::value) |
| 39 | { |
| 40 | var = (T*)(pdr.data() + sizeof(pldm_pdr_hdr)); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | var = (T*)(pdr.data()); |
| 45 | } |
| 46 | if (var != nullptr) |
| 47 | { |
| 48 | return var->terminus_handle; |
| 49 | } |
| 50 | return TERMINUS_HANDLE; |
| 51 | } |
| 52 | |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 53 | template <typename T> |
| 54 | void updateContainerId(pldm_entity_association_tree* entityTree, |
| 55 | std::vector<uint8_t>& pdr) |
| 56 | { |
| 57 | T* t = nullptr; |
| 58 | if (entityTree == nullptr) |
| 59 | { |
| 60 | return; |
| 61 | } |
| 62 | if (std::is_same<T, pldm_pdr_fru_record_set>::value) |
| 63 | { |
| 64 | t = (T*)(pdr.data() + sizeof(pldm_pdr_hdr)); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | t = (T*)(pdr.data()); |
| 69 | } |
| 70 | if (t == nullptr) |
| 71 | { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | pldm_entity entity{t->entity_type, t->entity_instance, t->container_id}; |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 76 | auto node = pldm_entity_association_tree_find_with_locality( |
| 77 | entityTree, &entity, true); |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 78 | if (node) |
| 79 | { |
| 80 | pldm_entity e = pldm_entity_extract(node); |
| 81 | t->container_id = e.entity_container_id; |
| 82 | } |
| 83 | } |
| 84 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 85 | HostPDRHandler::HostPDRHandler( |
Andrew Jeffery | 3dd444d | 2024-07-25 22:00:27 +0930 | [diff] [blame] | 86 | int /* mctp_fd */, uint8_t mctp_eid, sdeventplus::Event& event, |
| 87 | pldm_pdr* repo, const std::string& eventsJsonsDir, |
| 88 | pldm_entity_association_tree* entityTree, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 89 | pldm_entity_association_tree* bmcEntityTree, |
| 90 | pldm::InstanceIdDb& instanceIdDb, |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 91 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 92 | mctp_eid(mctp_eid), event(event), repo(repo), |
| 93 | stateSensorHandler(eventsJsonsDir), entityTree(entityTree), |
| 94 | instanceIdDb(instanceIdDb), handler(handler), |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 95 | entityMaps(parseEntityMap(ENTITY_MAP_JSON)), oemUtilsHandler(nullptr) |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 96 | { |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 97 | mergedHostParents = false; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 98 | hostOffMatch = std::make_unique<sdbusplus::bus::match_t>( |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 99 | pldm::utils::DBusHandler::getBus(), |
| 100 | propertiesChanged("/xyz/openbmc_project/state/host0", |
| 101 | "xyz.openbmc_project.State.Host"), |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 102 | [this, repo, entityTree, bmcEntityTree](sdbusplus::message_t& msg) { |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 103 | DbusChangedProps props{}; |
| 104 | std::string intf; |
| 105 | msg.read(intf, props); |
| 106 | const auto itr = props.find("CurrentHostState"); |
| 107 | if (itr != props.end()) |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 108 | { |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 109 | PropertyValue value = itr->second; |
| 110 | auto propVal = std::get<std::string>(value); |
| 111 | if (propVal == "xyz.openbmc_project.State.Host.HostState.Off") |
| 112 | { |
| 113 | // Delete all the remote terminus information |
| 114 | std::erase_if(tlPDRInfo, [](const auto& item) { |
| 115 | const auto& [key, value] = item; |
| 116 | return key != TERMINUS_HANDLE; |
| 117 | }); |
| 118 | pldm_pdr_remove_remote_pdrs(repo); |
| 119 | pldm_entity_association_tree_destroy_root(entityTree); |
| 120 | pldm_entity_association_tree_copy_root(bmcEntityTree, |
| 121 | entityTree); |
| 122 | this->sensorMap.clear(); |
| 123 | this->responseReceived = false; |
| 124 | this->mergedHostParents = false; |
| 125 | } |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 126 | } |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 127 | }); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 128 | } |
| 129 | |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 130 | void HostPDRHandler::fetchPDR(PDRRecordHandles&& recordHandles) |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 131 | { |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 132 | pdrRecordHandles.clear(); |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 133 | modifiedPDRRecordHandles.clear(); |
| 134 | |
| 135 | if (isHostPdrModified) |
| 136 | { |
| 137 | modifiedPDRRecordHandles = std::move(recordHandles); |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | pdrRecordHandles = std::move(recordHandles); |
| 142 | } |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 143 | |
| 144 | // Defer the actual fetch of PDRs from the host (by queuing the call on the |
| 145 | // main event loop). That way, we can respond to the platform event msg from |
| 146 | // the host firmware. |
| 147 | pdrFetchEvent = std::make_unique<sdeventplus::source::Defer>( |
| 148 | event, std::bind(std::mem_fn(&HostPDRHandler::_fetchPDR), this, |
| 149 | std::placeholders::_1)); |
| 150 | } |
| 151 | |
| 152 | void HostPDRHandler::_fetchPDR(sdeventplus::source::EventBase& /*source*/) |
| 153 | { |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 154 | getHostPDR(); |
| 155 | } |
| 156 | |
| 157 | void HostPDRHandler::getHostPDR(uint32_t nextRecordHandle) |
| 158 | { |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 159 | pdrFetchEvent.reset(); |
| 160 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 161 | std::vector<uint8_t> requestMsg( |
| 162 | sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 163 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 164 | uint32_t recordHandle{}; |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 165 | if (!nextRecordHandle && (!modifiedPDRRecordHandles.empty()) && |
| 166 | isHostPdrModified) |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 167 | { |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 168 | recordHandle = modifiedPDRRecordHandles.front(); |
| 169 | modifiedPDRRecordHandles.pop_front(); |
| 170 | } |
| 171 | else if (!nextRecordHandle && (!pdrRecordHandles.empty())) |
| 172 | { |
| 173 | recordHandle = pdrRecordHandles.front(); |
| 174 | pdrRecordHandles.pop_front(); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 175 | } |
| 176 | else |
| 177 | { |
| 178 | recordHandle = nextRecordHandle; |
| 179 | } |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 180 | auto instanceId = instanceIdDb.next(mctp_eid); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 181 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 182 | auto rc = |
| 183 | encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART, |
| 184 | UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 185 | if (rc != PLDM_SUCCESS) |
| 186 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 187 | instanceIdDb.free(mctp_eid, instanceId); |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 188 | error("Failed to encode get pdr request, response code '{RC}'", "RC", |
| 189 | rc); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 190 | return; |
| 191 | } |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 192 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 193 | rc = handler->registerRequest( |
| 194 | mctp_eid, instanceId, PLDM_PLATFORM, PLDM_GET_PDR, |
| 195 | std::move(requestMsg), |
Andrew Jeffery | c14fb4b | 2024-07-25 22:13:09 +0930 | [diff] [blame] | 196 | std::bind_front(&HostPDRHandler::processHostPDRs, this)); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 197 | if (rc) |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 198 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 199 | error( |
| 200 | "Failed to send the getPDR request to remote terminus, response code '{RC}'", |
| 201 | "RC", rc); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 202 | } |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 205 | int HostPDRHandler::handleStateSensorEvent(const StateSensorEntry& entry, |
| 206 | pdr::EventState state) |
| 207 | { |
| 208 | auto rc = stateSensorHandler.eventAction(entry, state); |
| 209 | if (rc != PLDM_SUCCESS) |
| 210 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 211 | error("Failed to fetch and update D-bus property, response code '{RC}'", |
| 212 | "RC", rc); |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 213 | return rc; |
| 214 | } |
| 215 | return PLDM_SUCCESS; |
| 216 | } |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 217 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 218 | void HostPDRHandler::mergeEntityAssociations( |
| 219 | const std::vector<uint8_t>& pdr, [[maybe_unused]] const uint32_t& size, |
| 220 | [[maybe_unused]] const uint32_t& record_handle) |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 221 | { |
| 222 | size_t numEntities{}; |
| 223 | pldm_entity* entities = nullptr; |
| 224 | bool merged = false; |
| 225 | auto entityPdr = reinterpret_cast<pldm_pdr_entity_association*>( |
| 226 | const_cast<uint8_t*>(pdr.data()) + sizeof(pldm_pdr_hdr)); |
| 227 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 228 | if (oemPlatformHandler && |
| 229 | oemPlatformHandler->checkRecordHandleInRange(record_handle)) |
| 230 | { |
| 231 | // Adding the remote range PDRs to the repo before merging it |
| 232 | uint32_t handle = record_handle; |
Andrew Jeffery | 5a945bd | 2024-08-01 13:15:36 +0000 | [diff] [blame] | 233 | pldm_pdr_add(repo, pdr.data(), size, true, 0xFFFF, &handle); |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 236 | pldm_entity_association_pdr_extract(pdr.data(), pdr.size(), &numEntities, |
| 237 | &entities); |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 238 | if (numEntities > 0) |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 239 | { |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 240 | pldm_entity_node* pNode = nullptr; |
| 241 | if (!mergedHostParents) |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 242 | { |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 243 | pNode = pldm_entity_association_tree_find_with_locality( |
| 244 | entityTree, &entities[0], false); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 245 | } |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 246 | else |
| 247 | { |
| 248 | pNode = pldm_entity_association_tree_find_with_locality( |
| 249 | entityTree, &entities[0], true); |
| 250 | } |
| 251 | if (!pNode) |
| 252 | { |
| 253 | return; |
| 254 | } |
| 255 | |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 256 | Entities entityAssoc; |
| 257 | entityAssoc.push_back(pNode); |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 258 | for (size_t i = 1; i < numEntities; ++i) |
| 259 | { |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 260 | bool isUpdateContainerId = true; |
| 261 | if (oemPlatformHandler) |
| 262 | { |
| 263 | isUpdateContainerId = |
Sagar Srinivas | 5db6e87 | 2023-12-01 10:03:30 -0600 | [diff] [blame] | 264 | checkIfLogicalBitSet(entities[i].entity_container_id); |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 265 | } |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 266 | auto node = pldm_entity_association_tree_add_entity( |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 267 | entityTree, &entities[i], entities[i].entity_instance_num, |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 268 | pNode, entityPdr->association_type, true, isUpdateContainerId, |
| 269 | 0xFFFF); |
| 270 | if (!node) |
| 271 | { |
| 272 | continue; |
| 273 | } |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 274 | merged = true; |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 275 | entityAssoc.push_back(node); |
George Liu | acf2c8c | 2021-05-10 14:08:52 +0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | mergedHostParents = true; |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 279 | if (merged) |
| 280 | { |
| 281 | entityAssociations.push_back(entityAssoc); |
| 282 | } |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 283 | } |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 284 | |
| 285 | if (merged) |
| 286 | { |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 287 | // Update our PDR repo with the merged entity association PDRs |
Sampa Misra | 719ed39 | 2021-06-04 05:15:13 -0500 | [diff] [blame] | 288 | pldm_entity_node* node = nullptr; |
| 289 | pldm_find_entity_ref_in_tree(entityTree, entities[0], &node); |
| 290 | if (node == nullptr) |
| 291 | { |
Manojkiran Eda | 2576aec | 2024-06-17 12:05:17 +0530 | [diff] [blame] | 292 | error("Failed to find reference of the entity in the tree"); |
Sampa Misra | 719ed39 | 2021-06-04 05:15:13 -0500 | [diff] [blame] | 293 | } |
| 294 | else |
| 295 | { |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 296 | int rc = 0; |
| 297 | if (oemPlatformHandler) |
| 298 | { |
| 299 | auto record = oemPlatformHandler->fetchLastBMCRecord(repo); |
| 300 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 301 | uint32_t record_handle = |
| 302 | pldm_pdr_get_record_handle(repo, record); |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 303 | |
| 304 | rc = |
| 305 | pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 306 | node, repo, &entities, numEntities, true, |
| 307 | TERMINUS_HANDLE, (record_handle + 1)); |
| 308 | } |
| 309 | else |
| 310 | { |
Andrew Jeffery | 7761bd2 | 2024-08-01 13:15:36 +0000 | [diff] [blame] | 311 | rc = pldm_entity_association_pdr_add_from_node( |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 312 | node, repo, &entities, numEntities, true, TERMINUS_HANDLE); |
| 313 | } |
| 314 | |
Andrew Jeffery | 1fd3c51 | 2023-07-03 13:02:03 +0930 | [diff] [blame] | 315 | if (rc) |
| 316 | { |
| 317 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 318 | "Failed to add entity association PDR from node, response code '{RC}'", |
| 319 | "RC", rc); |
Andrew Jeffery | 1fd3c51 | 2023-07-03 13:02:03 +0930 | [diff] [blame] | 320 | } |
Sampa Misra | 719ed39 | 2021-06-04 05:15:13 -0500 | [diff] [blame] | 321 | } |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 322 | } |
Sampa Misra | 719ed39 | 2021-06-04 05:15:13 -0500 | [diff] [blame] | 323 | free(entities); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 324 | } |
| 325 | |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 326 | void HostPDRHandler::sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes, |
| 327 | uint8_t eventDataFormat) |
| 328 | { |
| 329 | assert(eventDataFormat == FORMAT_IS_PDR_HANDLES); |
| 330 | |
| 331 | // Extract from the PDR repo record handles of PDRs we want the host |
| 332 | // to pull up. |
| 333 | std::vector<uint8_t> eventDataOps{PLDM_RECORDS_ADDED}; |
| 334 | std::vector<uint8_t> numsOfChangeEntries(1); |
| 335 | std::vector<std::vector<ChangeEntry>> changeEntries( |
| 336 | numsOfChangeEntries.size()); |
| 337 | for (auto pdrType : pdrTypes) |
| 338 | { |
| 339 | const pldm_pdr_record* record{}; |
| 340 | do |
| 341 | { |
| 342 | record = pldm_pdr_find_record_by_type(repo, pdrType, record, |
| 343 | nullptr, nullptr); |
| 344 | if (record && pldm_pdr_record_is_remote(record)) |
| 345 | { |
| 346 | changeEntries[0].push_back( |
| 347 | pldm_pdr_get_record_handle(repo, record)); |
| 348 | } |
| 349 | } while (record); |
| 350 | } |
| 351 | if (changeEntries.empty()) |
| 352 | { |
| 353 | return; |
| 354 | } |
| 355 | numsOfChangeEntries[0] = changeEntries[0].size(); |
| 356 | |
| 357 | // Encode PLDM platform event msg to indicate a PDR repo change. |
| 358 | size_t maxSize = PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH + |
| 359 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH + |
| 360 | changeEntries[0].size() * sizeof(uint32_t); |
| 361 | std::vector<uint8_t> eventDataVec{}; |
| 362 | eventDataVec.resize(maxSize); |
| 363 | auto eventData = |
| 364 | reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>( |
| 365 | eventDataVec.data()); |
| 366 | size_t actualSize{}; |
| 367 | auto firstEntry = changeEntries[0].data(); |
| 368 | auto rc = encode_pldm_pdr_repository_chg_event_data( |
| 369 | eventDataFormat, 1, eventDataOps.data(), numsOfChangeEntries.data(), |
| 370 | &firstEntry, eventData, &actualSize, maxSize); |
| 371 | if (rc != PLDM_SUCCESS) |
| 372 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 373 | error( |
| 374 | "Failed to encode pldm pdr repository change event data, response code '{RC}'", |
| 375 | "RC", rc); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 376 | return; |
| 377 | } |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 378 | auto instanceId = instanceIdDb.next(mctp_eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 379 | std::vector<uint8_t> requestMsg( |
| 380 | sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 381 | actualSize); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 382 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 383 | rc = encode_platform_event_message_req( |
ArchanaKakani | 6c39c7a | 2022-12-05 04:36:35 -0600 | [diff] [blame] | 384 | instanceId, 1, TERMINUS_ID, PLDM_PDR_REPOSITORY_CHG_EVENT, |
| 385 | eventDataVec.data(), actualSize, request, |
Christian Geddes | 3bdb3c2 | 2020-05-01 14:55:39 -0500 | [diff] [blame] | 386 | actualSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 387 | if (rc != PLDM_SUCCESS) |
| 388 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 389 | instanceIdDb.free(mctp_eid, instanceId); |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 390 | error( |
| 391 | "Failed to encode platform event message request, response code '{RC}'", |
| 392 | "RC", rc); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 396 | auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/, |
| 397 | const pldm_msg* response, |
| 398 | size_t respMsgLen) { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 399 | if (response == nullptr || !respMsgLen) |
| 400 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 401 | error( |
| 402 | "Failed to receive response for the PDR repository changed event"); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 403 | return; |
| 404 | } |
| 405 | |
| 406 | uint8_t completionCode{}; |
| 407 | uint8_t status{}; |
| 408 | auto responsePtr = reinterpret_cast<const struct pldm_msg*>(response); |
Pavithra Barithaya | 54b5a56 | 2021-09-27 06:07:10 -0500 | [diff] [blame] | 409 | auto rc = decode_platform_event_message_resp(responsePtr, respMsgLen, |
| 410 | &completionCode, &status); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 411 | if (rc || completionCode) |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 412 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 413 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 414 | "Failed to decode platform event message response, response code '{RC}' and completion code '{CC}'", |
| 415 | "RC", rc, "CC", completionCode); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 416 | } |
| 417 | }; |
| 418 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 419 | rc = handler->registerRequest( |
Sampa Misra | 626c565 | 2021-08-11 10:28:48 -0500 | [diff] [blame] | 420 | mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 421 | std::move(requestMsg), std::move(platformEventMessageResponseHandler)); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 422 | if (rc) |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 423 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 424 | error( |
| 425 | "Failed to send the PDR repository changed event request, response code '{RC}'", |
| 426 | "RC", rc); |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 430 | void HostPDRHandler::parseStateSensorPDRs(const PDRList& stateSensorPDRs) |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 431 | { |
| 432 | for (const auto& pdr : stateSensorPDRs) |
| 433 | { |
| 434 | SensorEntry sensorEntry{}; |
| 435 | const auto& [terminusHandle, sensorID, sensorInfo] = |
| 436 | responder::pdr_utils::parseStateSensorPDR(pdr); |
| 437 | sensorEntry.sensorID = sensorID; |
| 438 | try |
| 439 | { |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 440 | sensorEntry.terminusID = std::get<0>(tlPDRInfo.at(terminusHandle)); |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 441 | } |
| 442 | // If there is no mapping for terminusHandle assign the reserved TID |
| 443 | // value of 0xFF to indicate that. |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 444 | catch (const std::out_of_range&) |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 445 | { |
| 446 | sensorEntry.terminusID = PLDM_TID_RESERVED; |
| 447 | } |
| 448 | sensorMap.emplace(sensorEntry, std::move(sensorInfo)); |
| 449 | } |
| 450 | } |
| 451 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 452 | void HostPDRHandler::processHostPDRs( |
| 453 | mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 454 | { |
| 455 | static bool merged = false; |
| 456 | static PDRList stateSensorPDRs{}; |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 457 | static PDRList fruRecordSetPDRs{}; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 458 | uint32_t nextRecordHandle{}; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 459 | uint8_t tlEid = 0; |
| 460 | bool tlValid = true; |
| 461 | uint32_t rh = 0; |
| 462 | uint16_t terminusHandle = 0; |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 463 | uint16_t pdrTerminusHandle = 0; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 464 | uint8_t tid = 0; |
| 465 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 466 | uint8_t completionCode{}; |
| 467 | uint32_t nextDataTransferHandle{}; |
| 468 | uint8_t transferFlag{}; |
| 469 | uint16_t respCount{}; |
| 470 | uint8_t transferCRC{}; |
| 471 | if (response == nullptr || !respMsgLen) |
| 472 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 473 | error("Failed to receive response for the GetPDR command"); |
Riya Dixit | 478e71d | 2024-06-21 14:10:14 -0500 | [diff] [blame] | 474 | pldm::utils::reportError( |
| 475 | "xyz.openbmc_project.PLDM.Error.GetPDR.PDRExchangeFailure"); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
| 479 | auto rc = decode_get_pdr_resp( |
| 480 | response, respMsgLen /*- sizeof(pldm_msg_hdr)*/, &completionCode, |
| 481 | &nextRecordHandle, &nextDataTransferHandle, &transferFlag, &respCount, |
| 482 | nullptr, 0, &transferCRC); |
| 483 | std::vector<uint8_t> responsePDRMsg; |
| 484 | responsePDRMsg.resize(respMsgLen + sizeof(pldm_msg_hdr)); |
| 485 | memcpy(responsePDRMsg.data(), response, respMsgLen + sizeof(pldm_msg_hdr)); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 486 | if (rc != PLDM_SUCCESS) |
| 487 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 488 | error( |
| 489 | "Failed to decode getPDR response for next record handle '{NEXT_RECORD_HANDLE}', response code '{RC}'", |
| 490 | "NEXT_RECORD_HANDLE", nextRecordHandle, "RC", rc); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 491 | return; |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | std::vector<uint8_t> pdr(respCount, 0); |
| 496 | rc = decode_get_pdr_resp(response, respMsgLen, &completionCode, |
| 497 | &nextRecordHandle, &nextDataTransferHandle, |
| 498 | &transferFlag, &respCount, pdr.data(), |
| 499 | respCount, &transferCRC); |
| 500 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 501 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 502 | error( |
| 503 | "Failed to decode getPDR response for next record handle '{NEXT_RECORD_HANDLE}', next data transfer handle '{DATA_TRANSFER_HANDLE}' and transfer flag '{FLAG}', response code '{RC}' and completion code '{CC}'", |
| 504 | "NEXT_RECORD_HANDLE", nextRecordHandle, "DATA_TRANSFER_HANDLE", |
| 505 | nextDataTransferHandle, "FLAG", transferFlag, "RC", rc, "CC", |
| 506 | completionCode); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | else |
| 510 | { |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 511 | // when nextRecordHandle is 0, we need the recordHandle of the last |
| 512 | // PDR and not 0-1. |
| 513 | if (!nextRecordHandle) |
| 514 | { |
| 515 | rh = nextRecordHandle; |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | rh = nextRecordHandle - 1; |
| 520 | } |
| 521 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 522 | auto pdrHdr = reinterpret_cast<pldm_pdr_hdr*>(pdr.data()); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 523 | if (!rh) |
| 524 | { |
| 525 | rh = pdrHdr->record_handle; |
| 526 | } |
| 527 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 528 | if (pdrHdr->type == PLDM_PDR_ENTITY_ASSOCIATION) |
| 529 | { |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 530 | this->mergeEntityAssociations(pdr, respCount, rh); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 531 | merged = true; |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | if (pdrHdr->type == PLDM_TERMINUS_LOCATOR_PDR) |
| 536 | { |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 537 | pdrTerminusHandle = |
| 538 | extractTerminusHandle<pldm_terminus_locator_pdr>(pdr); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 539 | auto tlpdr = |
| 540 | reinterpret_cast<const pldm_terminus_locator_pdr*>( |
| 541 | pdr.data()); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 542 | |
| 543 | terminusHandle = tlpdr->terminus_handle; |
| 544 | tid = tlpdr->tid; |
| 545 | auto terminus_locator_type = tlpdr->terminus_locator_type; |
| 546 | if (terminus_locator_type == |
| 547 | PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID) |
| 548 | { |
| 549 | auto locatorValue = reinterpret_cast< |
| 550 | const pldm_terminus_locator_type_mctp_eid*>( |
| 551 | tlpdr->terminus_locator_value); |
| 552 | tlEid = static_cast<uint8_t>(locatorValue->eid); |
| 553 | } |
| 554 | if (tlpdr->validity == 0) |
| 555 | { |
| 556 | tlValid = false; |
| 557 | } |
Pavithra Barithaya | 52aad39 | 2022-08-02 04:18:52 -0500 | [diff] [blame] | 558 | for (const auto& terminusMap : tlPDRInfo) |
| 559 | { |
| 560 | if ((terminusHandle == (terminusMap.first)) && |
| 561 | (get<1>(terminusMap.second) == tlEid) && |
| 562 | (get<2>(terminusMap.second) == tlpdr->validity)) |
| 563 | { |
| 564 | // TL PDR already present with same validity don't |
| 565 | // add the PDR to the repo just return |
| 566 | return; |
| 567 | } |
| 568 | } |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 569 | tlPDRInfo.insert_or_assign( |
| 570 | tlpdr->terminus_handle, |
| 571 | std::make_tuple(tlpdr->tid, tlEid, tlpdr->validity)); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 572 | } |
| 573 | else if (pdrHdr->type == PLDM_STATE_SENSOR_PDR) |
| 574 | { |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 575 | pdrTerminusHandle = |
| 576 | extractTerminusHandle<pldm_state_sensor_pdr>(pdr); |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 577 | updateContainerId<pldm_state_sensor_pdr>(entityTree, pdr); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 578 | stateSensorPDRs.emplace_back(pdr); |
| 579 | } |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 580 | else if (pdrHdr->type == PLDM_PDR_FRU_RECORD_SET) |
| 581 | { |
| 582 | pdrTerminusHandle = |
| 583 | extractTerminusHandle<pldm_pdr_fru_record_set>(pdr); |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 584 | updateContainerId<pldm_pdr_fru_record_set>(entityTree, pdr); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 585 | fruRecordSetPDRs.emplace_back(pdr); |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 586 | } |
| 587 | else if (pdrHdr->type == PLDM_STATE_EFFECTER_PDR) |
| 588 | { |
| 589 | pdrTerminusHandle = |
| 590 | extractTerminusHandle<pldm_state_effecter_pdr>(pdr); |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 591 | updateContainerId<pldm_state_effecter_pdr>(entityTree, pdr); |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 592 | } |
| 593 | else if (pdrHdr->type == PLDM_NUMERIC_EFFECTER_PDR) |
| 594 | { |
| 595 | pdrTerminusHandle = |
| 596 | extractTerminusHandle<pldm_numeric_effecter_value_pdr>( |
| 597 | pdr); |
George Liu | 96af8cb | 2021-07-31 15:23:45 +0800 | [diff] [blame] | 598 | updateContainerId<pldm_numeric_effecter_value_pdr>( |
| 599 | entityTree, pdr); |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 600 | } |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 601 | // if the TLPDR is invalid update the repo accordingly |
| 602 | if (!tlValid) |
| 603 | { |
| 604 | pldm_pdr_update_TL_pdr(repo, terminusHandle, tid, tlEid, |
| 605 | tlValid); |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 606 | |
| 607 | if (!isHostUp()) |
| 608 | { |
| 609 | // The terminus PDR becomes invalid when the terminus |
| 610 | // itself is down. We don't need to do PDR exchange in |
| 611 | // that case, so setting the next record handle to 0. |
| 612 | nextRecordHandle = 0; |
| 613 | } |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 614 | } |
| 615 | else |
| 616 | { |
Andrew Jeffery | 5a945bd | 2024-08-01 13:15:36 +0000 | [diff] [blame] | 617 | rc = pldm_pdr_add(repo, pdr.data(), respCount, true, |
| 618 | pdrTerminusHandle, &rh); |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 619 | if (rc) |
| 620 | { |
| 621 | // pldm_pdr_add() assert()ed on failure to add a PDR. |
| 622 | throw std::runtime_error("Failed to add PDR"); |
| 623 | } |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 624 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | } |
| 628 | if (!nextRecordHandle) |
| 629 | { |
Kamalkumar Patel | 516122e | 2024-05-07 04:39:32 -0500 | [diff] [blame] | 630 | updateEntityAssociation(entityAssociations, entityTree, objPathMap, |
Kamalkumar Patel | 15ce5a1 | 2024-05-07 11:45:11 -0500 | [diff] [blame] | 631 | entityMaps, oemPlatformHandler); |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 632 | if (oemUtilsHandler) |
| 633 | { |
| 634 | oemUtilsHandler->setCoreCount(entityAssociations, entityMaps); |
| 635 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 636 | /*received last record*/ |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 637 | this->parseStateSensorPDRs(stateSensorPDRs); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 638 | this->createDbusObjects(fruRecordSetPDRs); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 639 | if (isHostUp()) |
| 640 | { |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 641 | this->setHostSensorState(stateSensorPDRs); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 642 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 643 | stateSensorPDRs.clear(); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 644 | fruRecordSetPDRs.clear(); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 645 | entityAssociations.clear(); |
| 646 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 647 | if (merged) |
| 648 | { |
| 649 | merged = false; |
| 650 | deferredPDRRepoChgEvent = |
| 651 | std::make_unique<sdeventplus::source::Defer>( |
| 652 | event, |
| 653 | std::bind( |
| 654 | std::mem_fn((&HostPDRHandler::_processPDRRepoChgEvent)), |
| 655 | this, std::placeholders::_1)); |
| 656 | } |
| 657 | } |
| 658 | else |
| 659 | { |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 660 | if (modifiedPDRRecordHandles.empty() && isHostPdrModified) |
| 661 | { |
| 662 | isHostPdrModified = false; |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | deferredFetchPDREvent = |
| 667 | std::make_unique<sdeventplus::source::Defer>( |
| 668 | event, |
| 669 | std::bind( |
| 670 | std::mem_fn((&HostPDRHandler::_processFetchPDREvent)), |
| 671 | this, nextRecordHandle, std::placeholders::_1)); |
| 672 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | void HostPDRHandler::_processPDRRepoChgEvent( |
| 677 | sdeventplus::source::EventBase& /*source */) |
| 678 | { |
| 679 | deferredPDRRepoChgEvent.reset(); |
| 680 | this->sendPDRRepositoryChgEvent( |
Andrew Jeffery | c14fb4b | 2024-07-25 22:13:09 +0930 | [diff] [blame] | 681 | std::vector<uint8_t>(1, PLDM_PDR_ENTITY_ASSOCIATION), |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 682 | FORMAT_IS_PDR_HANDLES); |
| 683 | } |
| 684 | |
| 685 | void HostPDRHandler::_processFetchPDREvent( |
| 686 | uint32_t nextRecordHandle, sdeventplus::source::EventBase& /*source */) |
| 687 | { |
| 688 | deferredFetchPDREvent.reset(); |
| 689 | if (!this->pdrRecordHandles.empty()) |
| 690 | { |
| 691 | nextRecordHandle = this->pdrRecordHandles.front(); |
| 692 | this->pdrRecordHandles.pop_front(); |
| 693 | } |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 694 | if (isHostPdrModified && (!this->modifiedPDRRecordHandles.empty())) |
| 695 | { |
| 696 | nextRecordHandle = this->modifiedPDRRecordHandles.front(); |
| 697 | this->modifiedPDRRecordHandles.pop_front(); |
| 698 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 699 | this->getHostPDR(nextRecordHandle); |
| 700 | } |
| 701 | |
Sampa Misra | f9ba8c1 | 2021-08-06 00:33:47 -0500 | [diff] [blame] | 702 | void HostPDRHandler::setHostFirmwareCondition() |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 703 | { |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 704 | responseReceived = false; |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 705 | auto instanceId = instanceIdDb.next(mctp_eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 706 | std::vector<uint8_t> requestMsg( |
| 707 | sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES); |
Sampa Misra | f9ba8c1 | 2021-08-06 00:33:47 -0500 | [diff] [blame] | 708 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 709 | auto rc = encode_get_version_req(instanceId, 0, PLDM_GET_FIRSTPART, |
| 710 | PLDM_BASE, request); |
| 711 | if (rc != PLDM_SUCCESS) |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 712 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 713 | error("Failed to encode GetPLDMVersion, response code {RC}", "RC", |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 714 | lg2::hex, rc); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 715 | instanceIdDb.free(mctp_eid, instanceId); |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 716 | return; |
| 717 | } |
| 718 | |
Sampa Misra | f9ba8c1 | 2021-08-06 00:33:47 -0500 | [diff] [blame] | 719 | auto getPLDMVersionHandler = [this](mctp_eid_t /*eid*/, |
| 720 | const pldm_msg* response, |
| 721 | size_t respMsgLen) { |
| 722 | if (response == nullptr || !respMsgLen) |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 723 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 724 | error( |
| 725 | "Failed to receive response for getPLDMVersion command, Host seems to be off"); |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 726 | return; |
| 727 | } |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 728 | info("Getting the response code '{RC}'", "RC", lg2::hex, |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 729 | response->payload[0]); |
Sampa Misra | f9ba8c1 | 2021-08-06 00:33:47 -0500 | [diff] [blame] | 730 | this->responseReceived = true; |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 731 | }; |
Sampa Misra | f9ba8c1 | 2021-08-06 00:33:47 -0500 | [diff] [blame] | 732 | rc = handler->registerRequest(mctp_eid, instanceId, PLDM_BASE, |
| 733 | PLDM_GET_PLDM_VERSION, std::move(requestMsg), |
| 734 | std::move(getPLDMVersionHandler)); |
| 735 | if (rc) |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 736 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 737 | error( |
| 738 | "Failed to discover remote terminus state. Assuming remote terminus as off"); |
sampmisr | 6decfc1 | 2021-03-02 11:07:36 +0530 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
| 742 | bool HostPDRHandler::isHostUp() |
| 743 | { |
| 744 | return responseReceived; |
| 745 | } |
| 746 | |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 747 | void HostPDRHandler::setHostSensorState(const PDRList& stateSensorPDRs) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 748 | { |
| 749 | for (const auto& stateSensorPDR : stateSensorPDRs) |
| 750 | { |
| 751 | auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>( |
| 752 | stateSensorPDR.data()); |
| 753 | |
| 754 | if (!pdr) |
| 755 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 756 | error("Failed to get state sensor PDR"); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 757 | pldm::utils::reportError( |
Manojkiran Eda | 92fb0b5 | 2024-04-17 10:48:17 +0530 | [diff] [blame] | 758 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
| 762 | uint16_t sensorId = pdr->sensor_id; |
| 763 | |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 764 | for (const auto& [terminusHandle, terminusInfo] : tlPDRInfo) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 765 | { |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 766 | if (terminusHandle == pdr->terminus_handle) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 767 | { |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 768 | if (std::get<2>(terminusInfo) == PLDM_TL_PDR_VALID) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 769 | { |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 770 | mctp_eid = std::get<1>(terminusInfo); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | bitfield8_t sensorRearm; |
| 774 | sensorRearm.byte = 0; |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 775 | uint8_t tid = std::get<0>(terminusInfo); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 776 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 777 | auto instanceId = instanceIdDb.next(mctp_eid); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 778 | std::vector<uint8_t> requestMsg( |
| 779 | sizeof(pldm_msg_hdr) + |
| 780 | PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES); |
| 781 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 782 | auto rc = encode_get_state_sensor_readings_req( |
| 783 | instanceId, sensorId, sensorRearm, 0, request); |
| 784 | |
| 785 | if (rc != PLDM_SUCCESS) |
| 786 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 787 | instanceIdDb.free(mctp_eid, instanceId); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 788 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 789 | "Failed to encode get state sensor readings request for sensorID '{SENSOR_ID}' and instanceID '{INSTANCE}', response code '{RC}'", |
| 790 | "SENSOR_ID", sensorId, "INSTANCE", instanceId, "RC", |
| 791 | rc); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 792 | pldm::utils::reportError( |
Manojkiran Eda | 92fb0b5 | 2024-04-17 10:48:17 +0530 | [diff] [blame] | 793 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 794 | return; |
| 795 | } |
| 796 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 797 | auto getStateSensorReadingRespHandler = [=, this]( |
| 798 | mctp_eid_t /*eid*/, |
| 799 | const pldm_msg* |
| 800 | response, |
| 801 | size_t respMsgLen) { |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 802 | if (response == nullptr || !respMsgLen) |
| 803 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 804 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 805 | "Failed to receive response for get state sensor reading command for sensorID '{SENSOR_ID}' and instanceID '{INSTANCE}'", |
| 806 | "SENSOR_ID", sensorId, "INSTANCE", instanceId); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 807 | return; |
| 808 | } |
| 809 | std::array<get_sensor_state_field, 8> stateField{}; |
| 810 | uint8_t completionCode = 0; |
| 811 | uint8_t comp_sensor_count = 0; |
| 812 | |
| 813 | auto rc = decode_get_state_sensor_readings_resp( |
| 814 | response, respMsgLen, &completionCode, |
| 815 | &comp_sensor_count, stateField.data()); |
| 816 | |
| 817 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 818 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 819 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 820 | "Failed to decode get state sensor readings response for sensorID '{SENSOR_ID}' and instanceID '{INSTANCE}', response code'{RC}' and completion code '{CC}'", |
| 821 | "SENSOR_ID", sensorId, "INSTANCE", instanceId, "RC", |
| 822 | rc, "CC", completionCode); |
Manojkiran Eda | 92fb0b5 | 2024-04-17 10:48:17 +0530 | [diff] [blame] | 823 | pldm::utils::reportError( |
| 824 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | uint8_t eventState; |
| 828 | uint8_t previousEventState; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 829 | |
RIYA DIXIT | bb5fda4 | 2022-09-27 06:48:08 -0500 | [diff] [blame] | 830 | for (uint8_t sensorOffset = 0; |
| 831 | sensorOffset < comp_sensor_count; sensorOffset++) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 832 | { |
RIYA DIXIT | bb5fda4 | 2022-09-27 06:48:08 -0500 | [diff] [blame] | 833 | eventState = stateField[sensorOffset].present_state; |
| 834 | previousEventState = |
| 835 | stateField[sensorOffset].previous_state; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 836 | |
| 837 | emitStateSensorEventSignal(tid, sensorId, sensorOffset, |
| 838 | eventState, |
| 839 | previousEventState); |
| 840 | |
| 841 | SensorEntry sensorEntry{tid, sensorId}; |
| 842 | |
| 843 | pldm::pdr::EntityInfo entityInfo{}; |
| 844 | pldm::pdr::CompositeSensorStates |
| 845 | compositeSensorStates{}; |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 846 | std::vector<pldm::pdr::StateSetId> stateSetIds{}; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 847 | |
| 848 | try |
| 849 | { |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 850 | std::tie(entityInfo, compositeSensorStates, |
| 851 | stateSetIds) = |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 852 | lookupSensorInfo(sensorEntry); |
| 853 | } |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 854 | catch (const std::out_of_range&) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 855 | { |
| 856 | try |
| 857 | { |
| 858 | sensorEntry.terminusID = PLDM_TID_RESERVED; |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 859 | std::tie(entityInfo, compositeSensorStates, |
| 860 | stateSetIds) = |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 861 | lookupSensorInfo(sensorEntry); |
| 862 | } |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 863 | catch (const std::out_of_range&) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 864 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 865 | error("No mapping for the events"); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
Manojkiran Eda | 07a07e2 | 2024-04-24 19:15:10 +0530 | [diff] [blame] | 869 | if ((compositeSensorStates.size() > 1) && |
| 870 | (sensorOffset > (compositeSensorStates.size() - 1))) |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 871 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 872 | error( |
| 873 | "Error Invalid data, Invalid sensor offset '{SENSOR_OFFSET}'", |
| 874 | "SENSOR_OFFSET", sensorOffset); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 875 | return; |
| 876 | } |
| 877 | |
| 878 | const auto& possibleStates = |
| 879 | compositeSensorStates[sensorOffset]; |
| 880 | if (possibleStates.find(eventState) == |
| 881 | possibleStates.end()) |
| 882 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 883 | error( |
| 884 | "Error invalid_data, Invalid event state '{STATE}'", |
| 885 | "STATE", eventState); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 886 | return; |
| 887 | } |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 888 | const auto& [containerId, entityType, entityInstance] = |
| 889 | entityInfo; |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 890 | auto stateSetId = stateSetIds[sensorOffset]; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 891 | pldm::responder::events::StateSensorEntry |
Manojkiran Eda | fa08470 | 2024-05-27 10:20:30 +0530 | [diff] [blame] | 892 | stateSensorEntry{containerId, entityType, |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 893 | entityInstance, sensorOffset, |
Manojkiran Eda | fa08470 | 2024-05-27 10:20:30 +0530 | [diff] [blame] | 894 | stateSetId, false}; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 895 | handleStateSensorEvent(stateSensorEntry, eventState); |
| 896 | } |
| 897 | }; |
| 898 | |
| 899 | rc = handler->registerRequest( |
| 900 | mctp_eid, instanceId, PLDM_PLATFORM, |
| 901 | PLDM_GET_STATE_SENSOR_READINGS, std::move(requestMsg), |
| 902 | std::move(getStateSensorReadingRespHandler)); |
| 903 | |
| 904 | if (rc != PLDM_SUCCESS) |
| 905 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 906 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 907 | "Failed to send request to get state sensor reading on remote terminus for sensorID '{SENSOR_ID}' and instanceID '{INSTANCE}', response code '{RC}'", |
| 908 | "SENSOR_ID", sensorId, "INSTANCE", instanceId, "RC", |
| 909 | rc); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | } |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 915 | |
| 916 | void HostPDRHandler::getFRURecordTableMetadataByRemote( |
| 917 | const PDRList& fruRecordSetPDRs) |
| 918 | { |
| 919 | auto instanceId = instanceIdDb.next(mctp_eid); |
| 920 | std::vector<uint8_t> requestMsg( |
| 921 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES); |
| 922 | |
| 923 | // GetFruRecordTableMetadata |
| 924 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 925 | auto rc = encode_get_fru_record_table_metadata_req( |
| 926 | instanceId, request, requestMsg.size() - sizeof(pldm_msg_hdr)); |
| 927 | if (rc != PLDM_SUCCESS) |
| 928 | { |
| 929 | instanceIdDb.free(mctp_eid, instanceId); |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 930 | error( |
| 931 | "Failed to encode get fru record table metadata request, response code '{RC}'", |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 932 | "RC", lg2::hex, rc); |
| 933 | return; |
| 934 | } |
| 935 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 936 | auto getFruRecordTableMetadataResponseHandler = [this, fruRecordSetPDRs]( |
| 937 | mctp_eid_t /*eid*/, |
| 938 | const pldm_msg* |
| 939 | response, |
| 940 | size_t respMsgLen) { |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 941 | if (response == nullptr || !respMsgLen) |
| 942 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 943 | error( |
| 944 | "Failed to receive response for the get fru record table metadata"); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 945 | return; |
| 946 | } |
| 947 | |
| 948 | uint8_t cc = 0; |
| 949 | uint8_t fru_data_major_version, fru_data_minor_version; |
| 950 | uint32_t fru_table_maximum_size, fru_table_length; |
| 951 | uint16_t total_record_set_identifiers; |
| 952 | uint16_t total; |
| 953 | uint32_t checksum; |
| 954 | |
| 955 | auto rc = decode_get_fru_record_table_metadata_resp( |
| 956 | response, respMsgLen, &cc, &fru_data_major_version, |
| 957 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 958 | &total_record_set_identifiers, &total, &checksum); |
| 959 | |
| 960 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 961 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 962 | error( |
| 963 | "Failed to decode get fru record table metadata response, response code '{RC}' and completion code '{CC}'", |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 964 | "RC", lg2::hex, rc, "CC", cc); |
| 965 | return; |
| 966 | } |
| 967 | |
| 968 | // pass total to getFRURecordTableByRemote |
| 969 | this->getFRURecordTableByRemote(fruRecordSetPDRs, total); |
| 970 | }; |
| 971 | |
| 972 | rc = handler->registerRequest( |
| 973 | mctp_eid, instanceId, PLDM_FRU, PLDM_GET_FRU_RECORD_TABLE_METADATA, |
| 974 | std::move(requestMsg), |
| 975 | std::move(getFruRecordTableMetadataResponseHandler)); |
| 976 | if (rc != PLDM_SUCCESS) |
| 977 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 978 | error( |
| 979 | "Failed to send the the set state effecter states request, response code '{RC}'", |
| 980 | "RC", rc); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | return; |
| 984 | } |
| 985 | |
| 986 | void HostPDRHandler::getFRURecordTableByRemote(const PDRList& fruRecordSetPDRs, |
| 987 | uint16_t totalTableRecords) |
| 988 | { |
| 989 | fruRecordData.clear(); |
| 990 | |
| 991 | if (!totalTableRecords) |
| 992 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 993 | error("Failed to get fru record table"); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
| 997 | auto instanceId = instanceIdDb.next(mctp_eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 998 | std::vector<uint8_t> requestMsg( |
| 999 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1000 | |
| 1001 | // send the getFruRecordTable command |
| 1002 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1003 | auto rc = encode_get_fru_record_table_req( |
| 1004 | instanceId, 0, PLDM_GET_FIRSTPART, request, |
| 1005 | requestMsg.size() - sizeof(pldm_msg_hdr)); |
| 1006 | if (rc != PLDM_SUCCESS) |
| 1007 | { |
| 1008 | instanceIdDb.free(mctp_eid, instanceId); |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 1009 | error( |
| 1010 | "Failed to encode get fru record table request, response code '{RC}'", |
| 1011 | "RC", lg2::hex, rc); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1012 | return; |
| 1013 | } |
| 1014 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 1015 | auto getFruRecordTableResponseHandler = [totalTableRecords, this, |
| 1016 | fruRecordSetPDRs]( |
| 1017 | mctp_eid_t /*eid*/, |
| 1018 | const pldm_msg* response, |
| 1019 | size_t respMsgLen) { |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1020 | if (response == nullptr || !respMsgLen) |
| 1021 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 1022 | error("Failed to receive response for the get fru record table"); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | uint8_t cc = 0; |
| 1027 | uint32_t next_data_transfer_handle = 0; |
| 1028 | uint8_t transfer_flag = 0; |
| 1029 | size_t fru_record_table_length = 0; |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 1030 | std::vector<uint8_t> fru_record_table_data( |
| 1031 | respMsgLen - sizeof(pldm_msg_hdr)); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1032 | auto responsePtr = reinterpret_cast<const struct pldm_msg*>(response); |
| 1033 | auto rc = decode_get_fru_record_table_resp( |
Manojkiran Eda | 33a9cd0 | 2024-01-22 11:06:59 +0530 | [diff] [blame] | 1034 | responsePtr, respMsgLen, &cc, &next_data_transfer_handle, |
| 1035 | &transfer_flag, fru_record_table_data.data(), |
| 1036 | &fru_record_table_length); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1037 | |
| 1038 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 1039 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 1040 | error( |
| 1041 | "Failed to decode get fru record table resp, response code '{RC}' and completion code '{CC}'", |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1042 | "RC", lg2::hex, rc, "CC", cc); |
| 1043 | return; |
| 1044 | } |
| 1045 | |
| 1046 | fruRecordData = responder::pdr_utils::parseFruRecordTable( |
| 1047 | fru_record_table_data.data(), fru_record_table_length); |
| 1048 | |
| 1049 | if (totalTableRecords != fruRecordData.size()) |
| 1050 | { |
| 1051 | fruRecordData.clear(); |
| 1052 | |
Manojkiran Eda | 2576aec | 2024-06-17 12:05:17 +0530 | [diff] [blame] | 1053 | error("Failed to parse fru record data format."); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | this->setFRUDataOnDBus(fruRecordSetPDRs, fruRecordData); |
| 1058 | }; |
| 1059 | |
| 1060 | rc = handler->registerRequest( |
| 1061 | mctp_eid, instanceId, PLDM_FRU, PLDM_GET_FRU_RECORD_TABLE, |
| 1062 | std::move(requestMsg), std::move(getFruRecordTableResponseHandler)); |
| 1063 | if (rc != PLDM_SUCCESS) |
| 1064 | { |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 1065 | error("Failed to send the the set state effecter states request"); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | std::optional<uint16_t> HostPDRHandler::getRSI(const PDRList& fruRecordSetPDRs, |
| 1070 | const pldm_entity& entity) |
| 1071 | { |
| 1072 | for (const auto& pdr : fruRecordSetPDRs) |
| 1073 | { |
| 1074 | auto fruPdr = reinterpret_cast<const pldm_pdr_fru_record_set*>( |
| 1075 | const_cast<uint8_t*>(pdr.data()) + sizeof(pldm_pdr_hdr)); |
| 1076 | |
| 1077 | if (fruPdr->entity_type == entity.entity_type && |
Sagar Srinivas | ebf8bb5 | 2023-10-06 01:15:55 -0500 | [diff] [blame] | 1078 | fruPdr->entity_instance == entity.entity_instance_num && |
| 1079 | fruPdr->container_id == entity.entity_container_id) |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1080 | { |
| 1081 | return fruPdr->fru_rsi; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | return std::nullopt; |
| 1086 | } |
| 1087 | |
| 1088 | void HostPDRHandler::setFRUDataOnDBus( |
Patrick Williams | d310f82 | 2023-10-07 19:01:19 -0500 | [diff] [blame] | 1089 | [[maybe_unused]] const PDRList& fruRecordSetPDRs, |
| 1090 | [[maybe_unused]] const std::vector< |
| 1091 | responder::pdr_utils::FruRecordDataFormat>& fruRecordData) |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1092 | { |
Patrick Williams | d310f82 | 2023-10-07 19:01:19 -0500 | [diff] [blame] | 1093 | #ifdef OEM_IBM |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1094 | for (const auto& entity : objPathMap) |
| 1095 | { |
| 1096 | pldm_entity node = pldm_entity_extract(entity.second); |
| 1097 | auto fruRSI = getRSI(fruRecordSetPDRs, node); |
| 1098 | |
| 1099 | for (const auto& data : fruRecordData) |
| 1100 | { |
| 1101 | if (!fruRSI || *fruRSI != data.fruRSI) |
| 1102 | { |
| 1103 | continue; |
| 1104 | } |
| 1105 | |
| 1106 | if (data.fruRecType == PLDM_FRU_RECORD_TYPE_OEM) |
| 1107 | { |
| 1108 | for (const auto& tlv : data.fruTLV) |
| 1109 | { |
| 1110 | if (tlv.fruFieldType == |
| 1111 | PLDM_OEM_FRU_FIELD_TYPE_LOCATION_CODE) |
| 1112 | { |
| 1113 | CustomDBus::getCustomDBus().setLocationCode( |
| 1114 | entity.first, |
| 1115 | std::string(reinterpret_cast<const char*>( |
| 1116 | tlv.fruFieldValue.data()), |
| 1117 | tlv.fruFieldLen)); |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | } |
Patrick Williams | d310f82 | 2023-10-07 19:01:19 -0500 | [diff] [blame] | 1123 | #endif |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1124 | } |
| 1125 | void HostPDRHandler::createDbusObjects(const PDRList& fruRecordSetPDRs) |
| 1126 | { |
| 1127 | // TODO: Creating and Refreshing dbus hosted by remote PLDM entity Fru PDRs |
Kamalkumar Patel | 56da574 | 2024-05-23 04:53:07 -0500 | [diff] [blame] | 1128 | for (const auto& entity : objPathMap) |
| 1129 | { |
| 1130 | pldm_entity node = pldm_entity_extract(entity.second); |
| 1131 | switch (node.entity_type) |
| 1132 | { |
| 1133 | case PLDM_ENTITY_PROC | 0x8000: |
| 1134 | CustomDBus::getCustomDBus().implementCpuCoreInterface( |
| 1135 | entity.first); |
| 1136 | break; |
Archana Kakani | bf1fd27 | 2024-06-05 13:25:53 -0500 | [diff] [blame] | 1137 | case PLDM_ENTITY_SLOT: |
| 1138 | CustomDBus::getCustomDBus().implementPCIeSlotInterface( |
| 1139 | entity.first); |
| 1140 | break; |
Archana Kakani | 733b39d | 2024-06-05 21:05:20 -0500 | [diff] [blame] | 1141 | case PLDM_ENTITY_CARD: |
| 1142 | CustomDBus::getCustomDBus().implementPCIeDeviceInterface( |
| 1143 | entity.first); |
| 1144 | break; |
Kamalkumar Patel | 2ed986c | 2024-05-08 02:20:47 -0500 | [diff] [blame] | 1145 | case PLDM_ENTITY_SYS_BOARD: |
| 1146 | CustomDBus::getCustomDBus().implementMotherboardInterface( |
| 1147 | entity.first); |
| 1148 | break; |
Archana Kakani | 733b39d | 2024-06-05 21:05:20 -0500 | [diff] [blame] | 1149 | default: |
| 1150 | break; |
Kamalkumar Patel | 56da574 | 2024-05-23 04:53:07 -0500 | [diff] [blame] | 1151 | } |
| 1152 | } |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1153 | getFRURecordTableMetadataByRemote(fruRecordSetPDRs); |
| 1154 | } |
| 1155 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 1156 | } // namespace pldm |