Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 1 | #include "pldm.hpp" |
| 2 | |
| 3 | #include "file.hpp" |
| 4 | |
| 5 | #include <fmt/core.h> |
| 6 | #include <libpldm/entity.h> |
| 7 | #include <libpldm/platform.h> |
| 8 | #include <libpldm/state_set.h> |
Eddie James | 36313c7 | 2021-11-18 08:27:03 -0600 | [diff] [blame] | 9 | #include <libpldm/state_set_oem_ibm.h> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 10 | |
| 11 | #include <phosphor-logging/log.hpp> |
| 12 | |
| 13 | namespace pldm |
| 14 | { |
| 15 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 16 | using namespace phosphor::logging; |
| 17 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 18 | void Interface::fetchSensorInfo(uint16_t stateSetId, |
| 19 | SensorToInstance& sensorInstanceMap, |
| 20 | SensorOffset& sensorOffset) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 21 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 22 | PdrList pdrs{}; |
| 23 | |
| 24 | auto& bus = open_power::occ::utils::getBus(); |
| 25 | try |
| 26 | { |
| 27 | auto method = bus.new_method_call( |
| 28 | "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm", |
| 29 | "xyz.openbmc_project.PLDM.PDR", "FindStateSensorPDR"); |
| 30 | method.append(tid, (uint16_t)PLDM_ENTITY_PROC, stateSetId); |
| 31 | |
| 32 | auto responseMsg = bus.call(method); |
| 33 | responseMsg.read(pdrs); |
| 34 | } |
| 35 | catch (const sdbusplus::exception::exception& e) |
| 36 | { |
| 37 | log<level::ERR>("pldm: Failed to fetch the state sensor PDRs", |
| 38 | entry("ERROR=%s", e.what())); |
| 39 | } |
| 40 | |
| 41 | if (pdrs.empty()) |
| 42 | { |
| 43 | log<level::ERR>("pldm: state sensor PDRs not present"); |
| 44 | return; |
| 45 | } |
| 46 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 47 | bool offsetFound = false; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 48 | auto stateSensorPDR = |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 49 | reinterpret_cast<const pldm_state_sensor_pdr*>(pdrs.front().data()); |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 50 | auto possibleStatesPtr = stateSensorPDR->possible_states; |
| 51 | for (auto offset = 0; offset < stateSensorPDR->composite_sensor_count; |
| 52 | offset++) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 53 | { |
| 54 | auto possibleStates = |
| 55 | reinterpret_cast<const state_sensor_possible_states*>( |
| 56 | possibleStatesPtr); |
| 57 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 58 | if (possibleStates->state_set_id == stateSetId) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 59 | { |
| 60 | sensorOffset = offset; |
| 61 | offsetFound = true; |
| 62 | break; |
| 63 | } |
| 64 | possibleStatesPtr += sizeof(possibleStates->state_set_id) + |
| 65 | sizeof(possibleStates->possible_states_size) + |
| 66 | possibleStates->possible_states_size; |
| 67 | } |
| 68 | |
| 69 | if (!offsetFound) |
| 70 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 71 | log<level::ERR>("pldm: state sensor PDR not found"); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | |
| 75 | // To order SensorID based on the EntityInstance. |
| 76 | // Note that when a proc is on a DCM, the PDRs for these sensors |
| 77 | // could have the same instance IDs but different container IDs. |
| 78 | std::map<uint32_t, SensorID> entityInstMap{}; |
| 79 | for (auto& pdr : pdrs) |
| 80 | { |
| 81 | auto pdrPtr = |
| 82 | reinterpret_cast<const pldm_state_sensor_pdr*>(pdr.data()); |
| 83 | uint32_t key = (static_cast<uint32_t>(pdrPtr->container_id) << 16) | |
| 84 | static_cast<uint32_t>(pdrPtr->entity_instance); |
| 85 | entityInstMap.emplace(key, static_cast<SensorID>(pdrPtr->sensor_id)); |
| 86 | } |
| 87 | |
| 88 | open_power::occ::instanceID count = start; |
| 89 | for (auto const& pair : entityInstMap) |
| 90 | { |
| 91 | sensorInstanceMap.emplace(pair.second, count); |
| 92 | count++; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void Interface::sensorEvent(sdbusplus::message::message& msg) |
| 97 | { |
| 98 | if (!isOCCSensorCacheValid()) |
| 99 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 100 | fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 101 | sensorToOCCInstance, OCCSensorOffset); |
| 102 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 103 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 104 | if (sensorToSBEInstance.empty()) |
| 105 | { |
| 106 | fetchSensorInfo(PLDM_OEM_IBM_SBE_HRESET_STATE, sensorToSBEInstance, |
| 107 | SBESensorOffset); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | TerminusID tid{}; |
| 111 | SensorID sensorId{}; |
| 112 | SensorOffset msgSensorOffset{}; |
| 113 | EventState eventState{}; |
| 114 | EventState previousEventState{}; |
| 115 | |
| 116 | msg.read(tid, sensorId, msgSensorOffset, eventState, previousEventState); |
| 117 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 118 | if (msgSensorOffset == OCCSensorOffset) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 119 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 120 | auto sensorEntry = sensorToOCCInstance.find(sensorId); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 121 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 122 | if (sensorEntry != sensorToOCCInstance.end()) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 123 | { |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 124 | if (eventState == |
| 125 | static_cast<EventState>( |
| 126 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE)) |
| 127 | { |
| 128 | log<level::INFO>( |
| 129 | fmt::format("PLDM: OCC{} is RUNNING", sensorEntry->second) |
| 130 | .c_str()); |
| 131 | callBack(sensorEntry->second, true); |
| 132 | } |
| 133 | else if (eventState == |
| 134 | static_cast<EventState>( |
| 135 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED)) |
| 136 | { |
| 137 | log<level::INFO>(fmt::format("PLDM: OCC{} has now STOPPED", |
| 138 | sensorEntry->second) |
| 139 | .c_str()); |
| 140 | callBack(sensorEntry->second, false); |
| 141 | } |
| 142 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 143 | return; |
| 144 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 145 | } |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 146 | |
| 147 | if (msgSensorOffset == SBESensorOffset) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 148 | { |
| 149 | auto sensorEntry = sensorToSBEInstance.find(sensorId); |
| 150 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 151 | if (sensorEntry != sensorToSBEInstance.end()) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 152 | { |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 153 | if (eventState == static_cast<EventState>(SBE_HRESET_NOT_READY)) |
| 154 | { |
| 155 | log<level::INFO>("pldm: HRESET is NOT READY", |
| 156 | entry("SBE=%d", sensorEntry->second)); |
| 157 | } |
| 158 | else if (eventState == static_cast<EventState>(SBE_HRESET_READY)) |
| 159 | { |
| 160 | sbeCallBack(sensorEntry->second, true); |
| 161 | } |
| 162 | else if (eventState == static_cast<EventState>(SBE_HRESET_FAILED)) |
| 163 | { |
| 164 | sbeCallBack(sensorEntry->second, false); |
| 165 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 166 | } |
| 167 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void Interface::hostStateEvent(sdbusplus::message::message& msg) |
| 171 | { |
| 172 | std::map<std::string, std::variant<std::string>> properties{}; |
| 173 | std::string interface; |
| 174 | msg.read(interface, properties); |
| 175 | const auto stateEntry = properties.find("CurrentHostState"); |
| 176 | if (stateEntry != properties.end()) |
| 177 | { |
| 178 | auto stateEntryValue = stateEntry->second; |
| 179 | auto propVal = std::get<std::string>(stateEntryValue); |
| 180 | if (propVal == "xyz.openbmc_project.State.Host.HostState.Off") |
| 181 | { |
| 182 | sensorToOCCInstance.clear(); |
| 183 | occInstanceToEffecter.clear(); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 184 | |
| 185 | sensorToSBEInstance.clear(); |
| 186 | sbeInstanceToEffecter.clear(); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 191 | void Interface::fetchEffecterInfo(uint16_t stateSetId, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 192 | InstanceToEffecter& instanceToEffecterMap, |
| 193 | CompositeEffecterCount& effecterCount, |
| 194 | uint8_t& stateIdPos) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 195 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 196 | PdrList pdrs{}; |
| 197 | |
| 198 | auto& bus = open_power::occ::utils::getBus(); |
| 199 | try |
| 200 | { |
| 201 | auto method = bus.new_method_call( |
| 202 | "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm", |
| 203 | "xyz.openbmc_project.PLDM.PDR", "FindStateEffecterPDR"); |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 204 | method.append(tid, (uint16_t)PLDM_ENTITY_PROC, stateSetId); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 205 | |
| 206 | auto responseMsg = bus.call(method); |
| 207 | responseMsg.read(pdrs); |
| 208 | } |
| 209 | catch (const sdbusplus::exception::exception& e) |
| 210 | { |
| 211 | log<level::ERR>("pldm: Failed to fetch the state effecter PDRs", |
| 212 | entry("ERROR=%s", e.what())); |
| 213 | } |
| 214 | |
| 215 | if (!pdrs.size()) |
| 216 | { |
| 217 | log<level::ERR>("pldm: state effecter PDRs not present"); |
| 218 | return; |
| 219 | } |
| 220 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 221 | bool offsetFound = false; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 222 | auto stateEffecterPDR = |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 223 | reinterpret_cast<const pldm_state_effecter_pdr*>(pdrs.front().data()); |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 224 | auto possibleStatesPtr = stateEffecterPDR->possible_states; |
| 225 | for (auto offset = 0; offset < stateEffecterPDR->composite_effecter_count; |
| 226 | offset++) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 227 | { |
| 228 | auto possibleStates = |
| 229 | reinterpret_cast<const state_effecter_possible_states*>( |
| 230 | possibleStatesPtr); |
| 231 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 232 | if (possibleStates->state_set_id == stateSetId) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 233 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 234 | stateIdPos = offset; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 235 | effecterCount = stateEffecterPDR->composite_effecter_count; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 236 | offsetFound = true; |
| 237 | break; |
| 238 | } |
| 239 | possibleStatesPtr += sizeof(possibleStates->state_set_id) + |
| 240 | sizeof(possibleStates->possible_states_size) + |
| 241 | possibleStates->possible_states_size; |
| 242 | } |
| 243 | |
| 244 | if (!offsetFound) |
| 245 | { |
| 246 | return; |
| 247 | } |
| 248 | |
Chris Cain | 0f51652 | 2022-02-07 14:48:28 -0600 | [diff] [blame] | 249 | std::map<uint32_t, EffecterID> entityInstMap{}; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 250 | for (auto& pdr : pdrs) |
| 251 | { |
| 252 | auto pdrPtr = |
| 253 | reinterpret_cast<const pldm_state_effecter_pdr*>(pdr.data()); |
| 254 | uint32_t key = (static_cast<uint32_t>(pdrPtr->container_id) << 16) | |
| 255 | static_cast<uint32_t>(pdrPtr->entity_instance); |
| 256 | entityInstMap.emplace(key, static_cast<SensorID>(pdrPtr->effecter_id)); |
| 257 | } |
| 258 | |
| 259 | open_power::occ::instanceID position = start; |
| 260 | for (auto const& pair : entityInstMap) |
| 261 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 262 | instanceToEffecterMap.emplace(position, pair.second); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 263 | position++; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | std::vector<uint8_t> |
| 268 | Interface::prepareSetEffecterReq(uint8_t instanceId, EffecterID effecterId, |
| 269 | CompositeEffecterCount effecterCount, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 270 | uint8_t stateIdPos, uint8_t stateSetValue) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 271 | { |
| 272 | std::vector<uint8_t> request( |
| 273 | sizeof(pldm_msg_hdr) + sizeof(effecterId) + sizeof(effecterCount) + |
| 274 | (effecterCount * sizeof(set_effecter_state_field))); |
| 275 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 276 | std::vector<set_effecter_state_field> stateField; |
| 277 | |
| 278 | for (uint8_t effecterPos = 0; effecterPos < effecterCount; effecterPos++) |
| 279 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 280 | if (effecterPos == stateIdPos) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 281 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 282 | stateField.emplace_back( |
| 283 | set_effecter_state_field{PLDM_REQUEST_SET, stateSetValue}); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 284 | } |
| 285 | else |
| 286 | { |
| 287 | stateField.emplace_back( |
| 288 | set_effecter_state_field{PLDM_NO_CHANGE, 0}); |
| 289 | } |
| 290 | } |
| 291 | auto rc = encode_set_state_effecter_states_req( |
| 292 | instanceId, effecterId, effecterCount, stateField.data(), requestMsg); |
| 293 | if (rc != PLDM_SUCCESS) |
| 294 | { |
| 295 | log<level::ERR>("encode set effecter states request returned error ", |
| 296 | entry("RC=%d", rc)); |
| 297 | request.clear(); |
| 298 | } |
| 299 | return request; |
| 300 | } |
| 301 | |
| 302 | void Interface::resetOCC(open_power::occ::instanceID occInstanceId) |
| 303 | { |
| 304 | if (!isPDREffecterCacheValid()) |
| 305 | { |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 306 | fetchEffecterInfo(PLDM_STATE_SET_BOOT_RESTART_CAUSE, |
| 307 | occInstanceToEffecter, OCCEffecterCount, |
| 308 | bootRestartPosition); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // Find the matching effecter for the OCC instance |
| 312 | auto effecterEntry = occInstanceToEffecter.find(occInstanceId); |
| 313 | if (effecterEntry == occInstanceToEffecter.end()) |
| 314 | { |
| 315 | log<level::ERR>( |
Chris Cain | 0f51652 | 2022-02-07 14:48:28 -0600 | [diff] [blame] | 316 | fmt::format( |
| 317 | "pldm: Failed to find a matching effecter for OCC instance {}", |
| 318 | occInstanceId) |
| 319 | .c_str()); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 320 | |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | uint8_t instanceId{}; |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 325 | if (!getMctpInstanceId(instanceId)) |
| 326 | { |
| 327 | return; |
| 328 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 329 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 330 | // Prepare the SetStateEffecterStates request to reset the OCC |
| 331 | auto request = prepareSetEffecterReq( |
| 332 | instanceId, effecterEntry->second, OCCEffecterCount, |
| 333 | bootRestartPosition, PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET); |
| 334 | |
| 335 | if (request.empty()) |
| 336 | { |
| 337 | log<level::ERR>("pldm: SetStateEffecterStates OCC reset request empty"); |
| 338 | return; |
| 339 | } |
| 340 | |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 341 | // Make asynchronous call to reset the OCCs/PM Complex |
| 342 | sendPldm(request, true); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void Interface::sendHRESET(open_power::occ::instanceID sbeInstanceId) |
| 346 | { |
| 347 | if (sbeInstanceToEffecter.empty()) |
| 348 | { |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 349 | fetchEffecterInfo(PLDM_OEM_IBM_SBE_MAINTENANCE_STATE, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 350 | sbeInstanceToEffecter, SBEEffecterCount, |
| 351 | sbeMaintenanceStatePosition); |
| 352 | } |
| 353 | |
| 354 | auto effecterEntry = sbeInstanceToEffecter.find(sbeInstanceId); |
| 355 | if (effecterEntry == sbeInstanceToEffecter.end()) |
| 356 | { |
| 357 | log<level::ERR>( |
| 358 | "pldm: Failed to find a matching effecter for SBE instance", |
| 359 | entry("SBE=%d", sbeInstanceId)); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | uint8_t instanceId{}; |
| 364 | if (!getMctpInstanceId(instanceId)) |
| 365 | { |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | // Prepare the SetStateEffecterStates request to HRESET the SBE |
| 370 | auto request = prepareSetEffecterReq( |
| 371 | instanceId, effecterEntry->second, SBEEffecterCount, |
| 372 | sbeMaintenanceStatePosition, SBE_RETRY_REQUIRED); |
| 373 | |
| 374 | if (request.empty()) |
| 375 | { |
| 376 | log<level::ERR>("pldm: SetStateEffecterStates HRESET request empty"); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | sendPldm(request); |
| 381 | } |
| 382 | |
| 383 | bool Interface::getMctpInstanceId(uint8_t& instanceId) |
| 384 | { |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 385 | auto& bus = open_power::occ::utils::getBus(); |
| 386 | try |
| 387 | { |
| 388 | auto method = bus.new_method_call( |
| 389 | "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm", |
| 390 | "xyz.openbmc_project.PLDM.Requester", "GetInstanceId"); |
| 391 | method.append(mctpEid); |
| 392 | auto reply = bus.call(method); |
| 393 | reply.read(instanceId); |
| 394 | } |
Patrick Williams | 2561362 | 2021-09-02 09:29:54 -0500 | [diff] [blame] | 395 | catch (const sdbusplus::exception::exception& e) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 396 | { |
| 397 | log<level::ERR>("pldm: GetInstanceId returned error", |
| 398 | entry("ERROR=%s", e.what())); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 399 | return false; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 400 | } |
| 401 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 402 | return true; |
| 403 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 404 | |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 405 | void Interface::sendPldm(const std::vector<uint8_t>& request, const bool async) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 406 | { |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 407 | // Connect to MCTP scoket |
| 408 | int fd = pldm_open(); |
| 409 | if (fd == -1) |
| 410 | { |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 411 | log<level::ERR>( |
| 412 | fmt::format("sendPldm: Failed to connect to MCTP socket, errno={}", |
| 413 | errno) |
| 414 | .c_str()); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 415 | return; |
| 416 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 417 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 418 | open_power::occ::FileDescriptor fileFd(fd); |
| 419 | |
| 420 | // Send the PLDM request message to HBRT |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 421 | if (async == false) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 422 | { |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 423 | uint8_t* response = nullptr; |
| 424 | size_t responseSize{}; |
| 425 | auto rc = pldm_send_recv(mctpEid, fileFd(), request.data(), |
| 426 | request.size(), &response, &responseSize); |
| 427 | std::unique_ptr<uint8_t, decltype(std::free)*> responsePtr{response, |
| 428 | std::free}; |
| 429 | if (rc) |
| 430 | { |
| 431 | log<level::ERR>( |
| 432 | fmt::format( |
| 433 | "sendPldm: pldm_send_recv({},{},req,{},...) failed with rc={} and errno={}", |
| 434 | mctpEid, fileFd(), request.size(), rc, errno) |
| 435 | .c_str()); |
| 436 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 437 | |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 438 | uint8_t completionCode{}; |
| 439 | auto responseMsg = reinterpret_cast<const pldm_msg*>(responsePtr.get()); |
| 440 | auto rcDecode = decode_set_state_effecter_states_resp( |
| 441 | responseMsg, responseSize - sizeof(pldm_msg_hdr), &completionCode); |
| 442 | if (rcDecode || completionCode) |
| 443 | { |
| 444 | log<level::ERR>( |
| 445 | fmt::format( |
| 446 | "sendPldm: decode_set_state_effecter_states_resp failed with rc={} and compCode={}", |
| 447 | rcDecode, completionCode) |
| 448 | .c_str()); |
| 449 | } |
| 450 | } |
| 451 | else |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 452 | { |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 453 | log<level::INFO>(fmt::format("sendPldm: calling pldm_send({}, {})", |
| 454 | mctpEid, fileFd()) |
| 455 | .c_str()); |
| 456 | auto rc = pldm_send(mctpEid, fileFd(), request.data(), request.size()); |
| 457 | if (rc) |
| 458 | { |
| 459 | log<level::ERR>( |
| 460 | fmt::format( |
| 461 | "sendPldm: pldm_send({},{},req,{}) failed with rc={} and errno={}", |
| 462 | mctpEid, fileFd(), request.size(), rc, errno) |
| 463 | .c_str()); |
| 464 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 465 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | } // namespace pldm |