Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 1 | #include "pldm.hpp" |
| 2 | |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 3 | #include "libpldm/instance-id.h" |
| 4 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 5 | #include "file.hpp" |
| 6 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 7 | #include <libpldm/entity.h> |
Andrew Jeffery | 97476a1 | 2024-06-19 21:07:29 +0930 | [diff] [blame] | 8 | #include <libpldm/oem/ibm/state_set.h> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 9 | #include <libpldm/platform.h> |
| 10 | #include <libpldm/state_set.h> |
| 11 | |
| 12 | #include <phosphor-logging/log.hpp> |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdeventplus/clock.hpp> |
| 15 | #include <sdeventplus/exception.hpp> |
| 16 | #include <sdeventplus/source/io.hpp> |
| 17 | #include <sdeventplus/source/time.hpp> |
| 18 | |
| 19 | #include <algorithm> |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 20 | #include <format> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 21 | |
| 22 | namespace pldm |
| 23 | { |
| 24 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 25 | using namespace phosphor::logging; |
| 26 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 27 | using namespace sdeventplus; |
| 28 | using namespace sdeventplus::source; |
| 29 | constexpr auto clockId = sdeventplus::ClockId::RealTime; |
| 30 | using Clock = sdeventplus::Clock<clockId>; |
| 31 | using Timer = Time<clockId>; |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 32 | bool Interface::throttleTraces = false; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 33 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 34 | void Interface::fetchSensorInfo(uint16_t stateSetId, |
| 35 | SensorToInstance& sensorInstanceMap, |
| 36 | SensorOffset& sensorOffset) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 37 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 38 | PdrList pdrs{}; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 39 | static bool tracedError = false; |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 40 | |
| 41 | auto& bus = open_power::occ::utils::getBus(); |
| 42 | try |
| 43 | { |
| 44 | auto method = bus.new_method_call( |
| 45 | "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm", |
| 46 | "xyz.openbmc_project.PLDM.PDR", "FindStateSensorPDR"); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 47 | method.append(tid, static_cast<uint16_t>(PLDM_ENTITY_PROC), stateSetId); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 48 | |
| 49 | auto responseMsg = bus.call(method); |
| 50 | responseMsg.read(pdrs); |
| 51 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 52 | catch (const sdbusplus::exception_t& e) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 53 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 54 | if (!tracedError) |
| 55 | { |
| 56 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 57 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 58 | "fetchSensorInfo: Failed to find stateSetID:{} PDR: {}", |
| 59 | stateSetId, e.what()) |
| 60 | .c_str()); |
| 61 | tracedError = true; |
| 62 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | if (pdrs.empty()) |
| 66 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 67 | if (!tracedError) |
| 68 | { |
| 69 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 70 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 71 | "fetchSensorInfo: state sensor PDRs ({}) not present", |
| 72 | stateSetId) |
| 73 | .c_str()); |
| 74 | tracedError = true; |
| 75 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 79 | // Found PDR |
| 80 | if (tracedError) |
| 81 | { |
| 82 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 83 | std::format("fetchSensorInfo: found {} PDRs", pdrs.size()).c_str()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 84 | tracedError = false; |
| 85 | } |
| 86 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 87 | bool offsetFound = false; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 88 | auto stateSensorPDR = |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 89 | reinterpret_cast<const pldm_state_sensor_pdr*>(pdrs.front().data()); |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 90 | auto possibleStatesPtr = stateSensorPDR->possible_states; |
| 91 | for (auto offset = 0; offset < stateSensorPDR->composite_sensor_count; |
| 92 | offset++) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 93 | { |
| 94 | auto possibleStates = |
| 95 | reinterpret_cast<const state_sensor_possible_states*>( |
| 96 | possibleStatesPtr); |
| 97 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 98 | if (possibleStates->state_set_id == stateSetId) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 99 | { |
| 100 | sensorOffset = offset; |
| 101 | offsetFound = true; |
| 102 | break; |
| 103 | } |
| 104 | possibleStatesPtr += sizeof(possibleStates->state_set_id) + |
| 105 | sizeof(possibleStates->possible_states_size) + |
| 106 | possibleStates->possible_states_size; |
| 107 | } |
| 108 | |
| 109 | if (!offsetFound) |
| 110 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 111 | log<level::ERR>("pldm: state sensor PDR not found"); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | |
| 115 | // To order SensorID based on the EntityInstance. |
| 116 | // Note that when a proc is on a DCM, the PDRs for these sensors |
| 117 | // could have the same instance IDs but different container IDs. |
| 118 | std::map<uint32_t, SensorID> entityInstMap{}; |
| 119 | for (auto& pdr : pdrs) |
| 120 | { |
| 121 | auto pdrPtr = |
| 122 | reinterpret_cast<const pldm_state_sensor_pdr*>(pdr.data()); |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 123 | uint32_t key = pdrPtr->sensor_id; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 124 | entityInstMap.emplace(key, static_cast<SensorID>(pdrPtr->sensor_id)); |
| 125 | } |
| 126 | |
| 127 | open_power::occ::instanceID count = start; |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 128 | for (const auto& pair : entityInstMap) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 129 | { |
| 130 | sensorInstanceMap.emplace(pair.second, count); |
| 131 | count++; |
| 132 | } |
| 133 | } |
| 134 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 135 | void Interface::sensorEvent(sdbusplus::message_t& msg) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 136 | { |
| 137 | if (!isOCCSensorCacheValid()) |
| 138 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 139 | fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 140 | sensorToOCCInstance, OCCSensorOffset); |
| 141 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 142 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 143 | if (sensorToSBEInstance.empty()) |
| 144 | { |
| 145 | fetchSensorInfo(PLDM_OEM_IBM_SBE_HRESET_STATE, sensorToSBEInstance, |
| 146 | SBESensorOffset); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 149 | TerminusID sensorTid{}; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 150 | SensorID sensorId{}; |
| 151 | SensorOffset msgSensorOffset{}; |
| 152 | EventState eventState{}; |
| 153 | EventState previousEventState{}; |
| 154 | |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 155 | msg.read(sensorTid, sensorId, msgSensorOffset, eventState, |
| 156 | previousEventState); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 157 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 158 | if (msgSensorOffset == OCCSensorOffset) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 159 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 160 | auto sensorEntry = sensorToOCCInstance.find(sensorId); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 161 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 162 | if (sensorEntry != sensorToOCCInstance.end()) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 163 | { |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 164 | const uint8_t instance = sensorEntry->second; |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 165 | bool validEvent = true; |
Chris Cain | 7b00cde | 2023-03-14 15:47:12 -0500 | [diff] [blame] | 166 | bool isRunning = false; |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 167 | if (eventState == |
| 168 | static_cast<EventState>( |
| 169 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE)) |
| 170 | { |
| 171 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 172 | std::format("PLDM: OCC{} is RUNNING", instance).c_str()); |
Chris Cain | 7b00cde | 2023-03-14 15:47:12 -0500 | [diff] [blame] | 173 | isRunning = true; |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 174 | } |
| 175 | else if (eventState == |
| 176 | static_cast<EventState>( |
| 177 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED)) |
| 178 | { |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 179 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 180 | std::format("PLDM: OCC{} has now STOPPED", instance) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 181 | .c_str()); |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 182 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 183 | else if (eventState == |
| 184 | static_cast<EventState>( |
| 185 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT)) |
| 186 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 187 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 188 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 189 | "PLDM: OCC{} has now STOPPED and system is in SAFE MODE", |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 190 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 191 | .c_str()); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 192 | |
| 193 | // Setting safe mode true |
| 194 | safeModeCallBack(true); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 195 | } |
| 196 | else |
| 197 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 198 | log<level::WARNING>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 199 | std::format("PLDM: Unexpected PLDM state {} for OCC{}", |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 200 | eventState, instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 201 | .c_str()); |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 202 | validEvent = false; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 203 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 204 | if (validEvent) |
| 205 | { |
| 206 | if ((pldmFd > 0) && (instance == pldmResponseOcc)) |
| 207 | { |
| 208 | // Waiting for a response for this OCC, can stop waiting |
| 209 | pldmClose(); |
| 210 | } |
| 211 | callBack(instance, isRunning); |
| 212 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 213 | return; |
| 214 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 215 | } |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 216 | |
| 217 | if (msgSensorOffset == SBESensorOffset) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 218 | { |
| 219 | auto sensorEntry = sensorToSBEInstance.find(sensorId); |
| 220 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 221 | if (sensorEntry != sensorToSBEInstance.end()) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 222 | { |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 223 | const uint8_t instance = sensorEntry->second; |
| 224 | auto match = std::find(outstandingHResets.begin(), |
| 225 | outstandingHResets.end(), instance); |
| 226 | if (match != outstandingHResets.end()) |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 227 | { |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 228 | outstandingHResets.erase(match); |
| 229 | if (eventState == static_cast<EventState>(SBE_HRESET_NOT_READY)) |
| 230 | { |
| 231 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 232 | std::format("pldm: HRESET is NOT READY (OCC{})", |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 233 | instance) |
| 234 | .c_str()); |
| 235 | } |
| 236 | else if (eventState == |
| 237 | static_cast<EventState>(SBE_HRESET_READY)) |
| 238 | { |
| 239 | sbeCallBack(instance, true); |
| 240 | } |
| 241 | else if (eventState == |
| 242 | static_cast<EventState>(SBE_HRESET_FAILED)) |
| 243 | { |
| 244 | sbeCallBack(instance, false); |
| 245 | } |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 246 | } |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 247 | // else request was not from us |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 252 | void Interface::hostStateEvent(sdbusplus::message_t& msg) |
Chris Cain | 157467d | 2022-06-24 11:25:23 -0500 | [diff] [blame] | 253 | { |
| 254 | std::map<std::string, std::variant<std::string>> properties{}; |
| 255 | std::string interface; |
| 256 | msg.read(interface, properties); |
| 257 | const auto stateEntry = properties.find("CurrentHostState"); |
| 258 | if (stateEntry != properties.end()) |
| 259 | { |
| 260 | auto stateEntryValue = stateEntry->second; |
| 261 | auto propVal = std::get<std::string>(stateEntryValue); |
| 262 | if (propVal == "xyz.openbmc_project.State.Host.HostState.Off") |
| 263 | { |
| 264 | clearData(); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 269 | void Interface::clearData() |
| 270 | { |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 271 | if (!sensorToOCCInstance.empty()) |
| 272 | { |
| 273 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 274 | std::format("clearData: Clearing sensorToOCCInstance ({} entries)", |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 275 | sensorToOCCInstance.size()) |
| 276 | .c_str()); |
| 277 | for (auto entry : sensorToOCCInstance) |
| 278 | { |
| 279 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 280 | std::format("clearData: OCC{} / sensorID: 0x{:04X}", |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 281 | entry.second, entry.first) |
| 282 | .c_str()); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 283 | callBack(entry.second, false); |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 284 | } |
| 285 | sensorToOCCInstance.clear(); |
| 286 | } |
| 287 | if (!occInstanceToEffecter.empty()) |
| 288 | { |
| 289 | log<level::DEBUG>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 290 | std::format( |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 291 | "clearData: Clearing occInstanceToEffecter ({} entries)", |
| 292 | occInstanceToEffecter.size()) |
| 293 | .c_str()); |
| 294 | occInstanceToEffecter.clear(); |
| 295 | } |
| 296 | if (!sensorToSBEInstance.empty()) |
| 297 | { |
| 298 | log<level::DEBUG>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 299 | std::format("clearData: Clearing sensorToSBEInstance ({} entries)", |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 300 | sensorToSBEInstance.size()) |
| 301 | .c_str()); |
| 302 | sensorToSBEInstance.clear(); |
| 303 | } |
| 304 | if (!sbeInstanceToEffecter.empty()) |
| 305 | { |
| 306 | log<level::DEBUG>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 307 | std::format( |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 308 | "clearData: Clearing sbeInstanceToEffecter ({} entries)", |
| 309 | sbeInstanceToEffecter.size()) |
| 310 | .c_str()); |
| 311 | sbeInstanceToEffecter.clear(); |
| 312 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 313 | } |
| 314 | |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 315 | void Interface::fetchEffecterInfo(uint16_t stateSetId, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 316 | InstanceToEffecter& instanceToEffecterMap, |
| 317 | CompositeEffecterCount& effecterCount, |
| 318 | uint8_t& stateIdPos) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 319 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 320 | PdrList pdrs{}; |
| 321 | |
| 322 | auto& bus = open_power::occ::utils::getBus(); |
| 323 | try |
| 324 | { |
| 325 | auto method = bus.new_method_call( |
| 326 | "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm", |
| 327 | "xyz.openbmc_project.PLDM.PDR", "FindStateEffecterPDR"); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 328 | method.append(tid, static_cast<uint16_t>(PLDM_ENTITY_PROC), stateSetId); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 329 | |
| 330 | auto responseMsg = bus.call(method); |
| 331 | responseMsg.read(pdrs); |
| 332 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 333 | catch (const sdbusplus::exception_t& e) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 334 | { |
| 335 | log<level::ERR>("pldm: Failed to fetch the state effecter PDRs", |
| 336 | entry("ERROR=%s", e.what())); |
| 337 | } |
| 338 | |
| 339 | if (!pdrs.size()) |
| 340 | { |
| 341 | log<level::ERR>("pldm: state effecter PDRs not present"); |
| 342 | return; |
| 343 | } |
| 344 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 345 | bool offsetFound = false; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 346 | auto stateEffecterPDR = |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 347 | reinterpret_cast<const pldm_state_effecter_pdr*>(pdrs.front().data()); |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 348 | auto possibleStatesPtr = stateEffecterPDR->possible_states; |
| 349 | for (auto offset = 0; offset < stateEffecterPDR->composite_effecter_count; |
| 350 | offset++) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 351 | { |
| 352 | auto possibleStates = |
| 353 | reinterpret_cast<const state_effecter_possible_states*>( |
| 354 | possibleStatesPtr); |
| 355 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 356 | if (possibleStates->state_set_id == stateSetId) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 357 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 358 | stateIdPos = offset; |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 359 | effecterCount = stateEffecterPDR->composite_effecter_count; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 360 | offsetFound = true; |
| 361 | break; |
| 362 | } |
| 363 | possibleStatesPtr += sizeof(possibleStates->state_set_id) + |
| 364 | sizeof(possibleStates->possible_states_size) + |
| 365 | possibleStates->possible_states_size; |
| 366 | } |
| 367 | |
| 368 | if (!offsetFound) |
| 369 | { |
| 370 | return; |
| 371 | } |
| 372 | |
Chris Cain | 0f51652 | 2022-02-07 14:48:28 -0600 | [diff] [blame] | 373 | std::map<uint32_t, EffecterID> entityInstMap{}; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 374 | for (auto& pdr : pdrs) |
| 375 | { |
| 376 | auto pdrPtr = |
| 377 | reinterpret_cast<const pldm_state_effecter_pdr*>(pdr.data()); |
Chris Cain | 72d01aa | 2022-06-14 16:28:03 -0500 | [diff] [blame] | 378 | uint32_t key = pdrPtr->effecter_id; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 379 | entityInstMap.emplace(key, static_cast<SensorID>(pdrPtr->effecter_id)); |
| 380 | } |
| 381 | |
| 382 | open_power::occ::instanceID position = start; |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 383 | for (const auto& pair : entityInstMap) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 384 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 385 | instanceToEffecterMap.emplace(position, pair.second); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 386 | position++; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | std::vector<uint8_t> |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 391 | Interface::prepareSetEffecterReq(EffecterID effecterId, |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 392 | CompositeEffecterCount effecterCount, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 393 | uint8_t stateIdPos, uint8_t stateSetValue) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 394 | { |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 395 | if (!getPldmInstanceId()) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 396 | { |
| 397 | return std::vector<uint8_t>(); |
| 398 | } |
| 399 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 400 | std::vector<uint8_t> request( |
| 401 | sizeof(pldm_msg_hdr) + sizeof(effecterId) + sizeof(effecterCount) + |
| 402 | (effecterCount * sizeof(set_effecter_state_field))); |
| 403 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 404 | std::vector<set_effecter_state_field> stateField; |
| 405 | |
| 406 | for (uint8_t effecterPos = 0; effecterPos < effecterCount; effecterPos++) |
| 407 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 408 | if (effecterPos == stateIdPos) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 409 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 410 | stateField.emplace_back( |
| 411 | set_effecter_state_field{PLDM_REQUEST_SET, stateSetValue}); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 412 | } |
| 413 | else |
| 414 | { |
| 415 | stateField.emplace_back( |
| 416 | set_effecter_state_field{PLDM_NO_CHANGE, 0}); |
| 417 | } |
| 418 | } |
| 419 | auto rc = encode_set_state_effecter_states_req( |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 420 | pldmInstanceID.value(), effecterId, effecterCount, stateField.data(), |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 421 | requestMsg); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 422 | if (rc != PLDM_SUCCESS) |
| 423 | { |
| 424 | log<level::ERR>("encode set effecter states request returned error ", |
| 425 | entry("RC=%d", rc)); |
| 426 | request.clear(); |
| 427 | } |
| 428 | return request; |
| 429 | } |
| 430 | |
| 431 | void Interface::resetOCC(open_power::occ::instanceID occInstanceId) |
| 432 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 433 | if (open_power::occ::utils::isHostRunning()) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 434 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 435 | if (!isPDREffecterCacheValid()) |
| 436 | { |
| 437 | fetchEffecterInfo(PLDM_STATE_SET_BOOT_RESTART_CAUSE, |
| 438 | occInstanceToEffecter, OCCEffecterCount, |
| 439 | bootRestartPosition); |
| 440 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 441 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 442 | // Find the matching effecter for the OCC instance |
| 443 | auto effecterEntry = occInstanceToEffecter.find(occInstanceId); |
| 444 | if (effecterEntry == occInstanceToEffecter.end()) |
| 445 | { |
| 446 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 447 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 448 | "pldm: Failed to find a matching effecter for OCC instance {}", |
| 449 | occInstanceId) |
| 450 | .c_str()); |
| 451 | |
| 452 | return; |
| 453 | } |
| 454 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 455 | // Prepare the SetStateEffecterStates request to reset the OCC |
| 456 | auto request = prepareSetEffecterReq( |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 457 | effecterEntry->second, OCCEffecterCount, bootRestartPosition, |
| 458 | PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 459 | |
| 460 | if (request.empty()) |
| 461 | { |
| 462 | log<level::ERR>( |
| 463 | "pldm: SetStateEffecterStates OCC reset request empty"); |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | // Send request to reset the OCCs/PM Complex (ignore response) |
| 468 | sendPldm(request, occInstanceId, false); |
| 469 | } |
| 470 | else |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 471 | { |
| 472 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 473 | std::format("resetOCC: HOST is not running (OCC{})", occInstanceId) |
Chris Cain | 0f51652 | 2022-02-07 14:48:28 -0600 | [diff] [blame] | 474 | .c_str()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 475 | clearData(); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 476 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void Interface::sendHRESET(open_power::occ::instanceID sbeInstanceId) |
| 480 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 481 | if (open_power::occ::utils::isHostRunning()) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 482 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 483 | if (sbeInstanceToEffecter.empty()) |
| 484 | { |
| 485 | fetchEffecterInfo(PLDM_OEM_IBM_SBE_MAINTENANCE_STATE, |
| 486 | sbeInstanceToEffecter, SBEEffecterCount, |
| 487 | sbeMaintenanceStatePosition); |
| 488 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 489 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 490 | auto effecterEntry = sbeInstanceToEffecter.find(sbeInstanceId); |
| 491 | if (effecterEntry == sbeInstanceToEffecter.end()) |
| 492 | { |
| 493 | log<level::ERR>( |
| 494 | "pldm: Failed to find a matching effecter for SBE instance", |
| 495 | entry("SBE=%d", sbeInstanceId)); |
| 496 | return; |
| 497 | } |
| 498 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 499 | // Prepare the SetStateEffecterStates request to HRESET the SBE |
| 500 | auto request = prepareSetEffecterReq( |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 501 | effecterEntry->second, SBEEffecterCount, |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 502 | sbeMaintenanceStatePosition, SBE_RETRY_REQUIRED); |
| 503 | |
| 504 | if (request.empty()) |
| 505 | { |
| 506 | log<level::ERR>( |
| 507 | "pldm: SetStateEffecterStates HRESET request empty"); |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | // Send request to issue HRESET of SBE (ignore response) |
| 512 | sendPldm(request, sbeInstanceId, false); |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 513 | outstandingHResets.insert(sbeInstanceId); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 514 | } |
| 515 | else |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 516 | { |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 517 | log<level::ERR>(std::format("sendHRESET: HOST is not running (OCC{})", |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 518 | sbeInstanceId) |
| 519 | .c_str()); |
| 520 | clearData(); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 521 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 524 | bool Interface::getPldmInstanceId() |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 525 | { |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 526 | pldm_instance_id_t id; |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 527 | if (!pldmInstanceID) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 528 | { |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 529 | // Request new instance ID |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 530 | int rc = pldm_instance_id_alloc(pldmInstanceIdDb, tid, &id); |
| 531 | if (rc == -EAGAIN) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 532 | { |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 533 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 534 | rc = pldm_instance_id_alloc(pldmInstanceIdDb, tid, &id); |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 535 | } |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 536 | |
| 537 | if (rc) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 538 | { |
| 539 | log<level::ERR>( |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 540 | std::format( |
| 541 | "getPldmInstanceId: Failed to alloc ID for TID {}. RC{}", |
| 542 | tid, rc) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 543 | .c_str()); |
| 544 | return false; |
| 545 | } |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 546 | pldmInstanceID.emplace(id); |
| 547 | if (!throttleTraces) |
| 548 | { |
| 549 | log<level::INFO>( |
| 550 | std::format("got id {} and set PldmInstanceId to {}", id, |
| 551 | pldmInstanceID.value()) |
| 552 | .c_str()); |
| 553 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 554 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 555 | return true; |
| 556 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 557 | |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 558 | void Interface::freePldmInstanceId() |
| 559 | { |
| 560 | if (pldmInstanceID) |
| 561 | { |
| 562 | int rc = pldm_instance_id_free(pldmInstanceIdDb, tid, |
| 563 | pldmInstanceID.value()); |
| 564 | if (rc) |
| 565 | { |
| 566 | log<level::ERR>( |
| 567 | std::format( |
| 568 | "freePldmInstanceId: Failed to free ID {} for TID {}. RC{}", |
| 569 | pldmInstanceID.value(), tid, rc) |
| 570 | .c_str()); |
| 571 | return; |
| 572 | } |
| 573 | if (!throttleTraces) |
| 574 | { |
| 575 | log<level::INFO>( |
| 576 | std::format("Freed PLDM instance ID {}", pldmInstanceID.value()) |
| 577 | .c_str()); |
| 578 | } |
| 579 | pldmInstanceID = std::nullopt; |
| 580 | } |
| 581 | } |
| 582 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 583 | void Interface::sendPldm(const std::vector<uint8_t>& request, |
| 584 | const uint8_t instance, const bool rspExpected) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 585 | { |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 586 | if (!pldmInstanceID) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 587 | { |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 588 | log<level::ERR>("sendPldm: No PLDM Instance ID found!"); |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 589 | return; |
| 590 | } |
| 591 | |
Chris Cain | c9dc441 | 2023-03-06 15:56:34 -0600 | [diff] [blame] | 592 | // Connect to MCTP socket |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 593 | pldmFd = pldm_open(); |
| 594 | auto openErrno = errno; |
| 595 | if (pldmFd == PLDM_REQUESTER_OPEN_FAIL) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 596 | { |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 597 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 598 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 599 | "sendPldm: Failed to connect to MCTP socket, errno={}/{}", |
| 600 | openErrno, strerror(openErrno)) |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 601 | .c_str()); |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 602 | freePldmInstanceId(); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 603 | return; |
| 604 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 605 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 606 | // Send the PLDM request message to HBRT |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 607 | if (rspExpected) |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 608 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 609 | // Register callback when response is available |
| 610 | registerPldmRspCallback(); |
| 611 | |
| 612 | // Send PLDM request |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 613 | if (!throttleTraces) |
| 614 | { |
| 615 | log<level::INFO>( |
| 616 | std::format( |
| 617 | "sendPldm: calling pldm_send(OCC{}, instance:{}, {} bytes)", |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 618 | instance, pldmInstanceID.value(), request.size()) |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 619 | .c_str()); |
| 620 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 621 | pldmResponseReceived = false; |
| 622 | pldmResponseTimeout = false; |
| 623 | pldmResponseOcc = instance; |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 624 | auto pldmRc = pldm_send(mctpEid, pldmFd, request.data(), |
| 625 | request.size()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 626 | auto sendErrno = errno; |
| 627 | if (pldmRc != PLDM_REQUESTER_SUCCESS) |
| 628 | { |
| 629 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 630 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 631 | "sendPldm: pldm_send failed with rc={} and errno={}/{}", |
Chris Cain | 5161a02 | 2023-08-15 10:07:12 -0500 | [diff] [blame] | 632 | static_cast< |
| 633 | std::underlying_type_t<pldm_requester_error_codes>>( |
| 634 | pldmRc), |
| 635 | sendErrno, strerror(sendErrno)) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 636 | .c_str()); |
| 637 | pldmClose(); |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | // start timer waiting for the response |
| 642 | using namespace std::literals::chrono_literals; |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 643 | pldmRspTimer.restartOnce(8s); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 644 | |
| 645 | // Wait for response/timeout |
| 646 | } |
| 647 | else // not expecting the response |
| 648 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 649 | if (!throttleTraces) |
| 650 | { |
| 651 | log<level::INFO>( |
| 652 | std::format( |
| 653 | "sendPldm: calling pldm_send(mctpID:{}, fd:{}, {} bytes) for OCC{}", |
| 654 | mctpEid, pldmFd, request.size(), instance) |
| 655 | .c_str()); |
| 656 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 657 | auto rc = pldm_send(mctpEid, pldmFd, request.data(), request.size()); |
| 658 | auto sendErrno = errno; |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 659 | if (rc) |
| 660 | { |
| 661 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 662 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 663 | "sendPldm: pldm_send(mctpID:{}, fd:{}, {} bytes) failed with rc={} and errno={}/{}", |
Chris Cain | 5161a02 | 2023-08-15 10:07:12 -0500 | [diff] [blame] | 664 | mctpEid, pldmFd, request.size(), |
| 665 | static_cast< |
| 666 | std::underlying_type_t<pldm_requester_error_codes>>(rc), |
| 667 | sendErrno, strerror(sendErrno)) |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 668 | .c_str()); |
| 669 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 670 | pldmClose(); |
| 671 | } |
| 672 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 673 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 674 | // Attaches the FD to event loop and registers the callback handler |
| 675 | void Interface::registerPldmRspCallback() |
| 676 | { |
| 677 | decltype(eventSource.get()) sourcePtr = nullptr; |
| 678 | auto rc = sd_event_add_io(event.get(), &sourcePtr, pldmFd, EPOLLIN, |
| 679 | pldmRspCallback, this); |
| 680 | if (rc < 0) |
| 681 | { |
| 682 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 683 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 684 | "registerPldmRspCallback: sd_event_add_io: Error({})={} : fd={}", |
| 685 | rc, strerror(-rc), pldmFd) |
| 686 | .c_str()); |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 687 | } |
| 688 | else |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 689 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 690 | // puts sourcePtr in the event source. |
| 691 | eventSource.reset(sourcePtr); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | // Add a timer to the event loop, default 30s. |
| 696 | void Interface::pldmRspExpired() |
| 697 | { |
| 698 | if (!pldmResponseReceived) |
| 699 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 700 | if (!throttleTraces) |
| 701 | { |
| 702 | log<level::WARNING>( |
| 703 | std::format( |
| 704 | "pldmRspExpired: timerCallback - timeout waiting for pldm response for OCC{}", |
| 705 | pldmResponseOcc) |
| 706 | .c_str()); |
| 707 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 708 | pldmResponseTimeout = true; |
| 709 | if (pldmFd) |
| 710 | { |
| 711 | pldmClose(); |
| 712 | } |
| 713 | } |
| 714 | return; |
| 715 | }; |
| 716 | |
| 717 | void Interface::pldmClose() |
| 718 | { |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 719 | freePldmInstanceId(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 720 | if (pldmRspTimer.isEnabled()) |
| 721 | { |
| 722 | // stop PLDM response timer |
| 723 | pldmRspTimer.setEnabled(false); |
| 724 | } |
Pavithra Barithaya | 159a227 | 2023-09-27 06:10:55 -0500 | [diff] [blame] | 725 | pldm_close(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 726 | pldmFd = -1; |
| 727 | eventSource.reset(); |
| 728 | } |
| 729 | |
| 730 | int Interface::pldmRspCallback(sd_event_source* /*es*/, int fd, |
| 731 | uint32_t revents, void* userData) |
| 732 | { |
| 733 | if (!(revents & EPOLLIN)) |
| 734 | { |
| 735 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 736 | std::format("pldmRspCallback - revents={:08X}", revents).c_str()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 737 | return -1; |
| 738 | } |
| 739 | |
| 740 | auto pldmIface = static_cast<Interface*>(userData); |
| 741 | |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 742 | if (!pldmIface->pldmInstanceID) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 743 | { |
| 744 | log<level::ERR>( |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 745 | "pldmRspCallback: No outstanding PLDM Instance ID found"); |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 746 | return -1; |
| 747 | } |
| 748 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 749 | uint8_t* responseMsg = nullptr; |
| 750 | size_t responseMsgSize{}; |
| 751 | |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 752 | if (!throttleTraces) |
| 753 | { |
| 754 | log<level::INFO>( |
| 755 | std::format("pldmRspCallback: calling pldm_recv() instance:{}", |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 756 | pldmIface->pldmInstanceID.value()) |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 757 | .c_str()); |
| 758 | } |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 759 | auto rc = pldm_recv(mctpEid, fd, pldmIface->pldmInstanceID.value(), |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 760 | &responseMsg, &responseMsgSize); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 761 | int lastErrno = errno; |
| 762 | if (rc) |
| 763 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 764 | if (!throttleTraces) |
| 765 | { |
| 766 | log<level::ERR>( |
| 767 | std::format( |
| 768 | "pldmRspCallback: pldm_recv failed with rc={}, errno={}/{}", |
| 769 | static_cast< |
| 770 | std::underlying_type_t<pldm_requester_error_codes>>(rc), |
| 771 | lastErrno, strerror(lastErrno)) |
| 772 | .c_str()); |
| 773 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 774 | return -1; |
| 775 | } |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 776 | |
| 777 | // We got the response for the PLDM request msg that was sent |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 778 | if (!throttleTraces) |
| 779 | { |
| 780 | log<level::INFO>( |
| 781 | std::format("pldmRspCallback: pldm_recv() rsp was {} bytes", |
| 782 | responseMsgSize) |
| 783 | .c_str()); |
| 784 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 785 | |
| 786 | if (pldmIface->pldmRspTimer.isEnabled()) |
| 787 | { |
| 788 | // stop PLDM response timer |
| 789 | pldmIface->pldmRspTimer.setEnabled(false); |
| 790 | } |
| 791 | |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 792 | // instance ID should be freed |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 793 | pldmIface->pldmInstanceID = std::nullopt; |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 794 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 795 | // Set pointer to autodelete |
| 796 | std::unique_ptr<uint8_t, decltype(std::free)*> responseMsgPtr{responseMsg, |
| 797 | std::free}; |
| 798 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 799 | auto response = reinterpret_cast<pldm_msg*>(responseMsgPtr.get()); |
| 800 | if (response->payload[0] != PLDM_SUCCESS) |
| 801 | { |
| 802 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 803 | std::format("pldmRspCallback: payload[0] was not success: {}", |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 804 | response->payload[0]) |
| 805 | .c_str()); |
| 806 | pldmIface->pldmClose(); |
| 807 | return -1; |
| 808 | } |
| 809 | |
| 810 | // Decode the response |
| 811 | uint8_t compCode = 0, sensorCount = 1; |
| 812 | get_sensor_state_field field[6]; |
| 813 | responseMsgSize -= sizeof(pldm_msg_hdr); |
| 814 | auto msgRc = decode_get_state_sensor_readings_resp( |
| 815 | response, responseMsgSize, &compCode, &sensorCount, field); |
| 816 | if ((msgRc != PLDM_SUCCESS) || (compCode != PLDM_SUCCESS)) |
| 817 | { |
| 818 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 819 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 820 | "pldmRspCallback: decode_get_state_sensor_readings failed with rc={} and compCode={}", |
| 821 | msgRc, compCode) |
| 822 | .c_str()); |
| 823 | pldmIface->pldmClose(); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | pldmIface->pldmClose(); |
| 828 | |
| 829 | const uint8_t instance = pldmIface->pldmResponseOcc; |
| 830 | const uint8_t occSensorState = field[0].present_state; |
| 831 | pldmIface->pldmResponseReceived = true; |
| 832 | |
| 833 | if (occSensorState == PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE) |
| 834 | { |
| 835 | log<level::INFO>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 836 | std::format("pldmRspCallback: OCC{} is RUNNING", instance).c_str()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 837 | pldmIface->callBack(instance, true); |
| 838 | } |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 839 | else if (occSensorState == |
| 840 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT) |
| 841 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 842 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 843 | std::format( |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 844 | "pldmRspCallback: OCC{} has now STOPPED and system is in SAFE MODE", |
| 845 | instance) |
| 846 | .c_str()); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 847 | |
| 848 | // Setting safe mode true |
| 849 | pldmIface->safeModeCallBack(true); |
| 850 | |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 851 | pldmIface->callBack(instance, false); |
| 852 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 853 | else if (occSensorState == |
| 854 | PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 855 | { |
| 856 | log<level::INFO>( |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 857 | std::format("pldmRspCallback: OCC{} is not running", instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 858 | .c_str()); |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 859 | pldmIface->callBack(instance, false); |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | const size_t rspLength = responseMsgSize + sizeof(pldm_msg_hdr); |
| 864 | std::vector<std::uint8_t> pldmResponse(rspLength); |
| 865 | memcpy(&pldmResponse[0], reinterpret_cast<std::uint8_t*>(response), |
| 866 | rspLength); |
| 867 | if (!throttleTraces) |
Chris Cain | c9dc441 | 2023-03-06 15:56:34 -0600 | [diff] [blame] | 868 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 869 | log<level::WARNING>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 870 | std::format( |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 871 | "pldmRspCallback: Unexpected State: {} - PLDM response ({} bytes) for OCC{}:", |
| 872 | occSensorState, rspLength, instance) |
Chris Cain | c9dc441 | 2023-03-06 15:56:34 -0600 | [diff] [blame] | 873 | .c_str()); |
| 874 | dump_hex(pldmResponse); |
| 875 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | return 0; |
| 879 | }; |
| 880 | |
| 881 | std::vector<uint8_t> Interface::encodeGetStateSensorRequest(uint8_t instance, |
| 882 | uint16_t sensorId) |
| 883 | { |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 884 | if (!getPldmInstanceId()) |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 885 | { |
| 886 | log<level::ERR>( |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 887 | "encodeGetStateSensorRequest: failed to getPldmInstanceId"); |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 888 | return std::vector<uint8_t>(); |
| 889 | } |
| 890 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 891 | bitfield8_t sRearm = {0}; |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 892 | const size_t msgSize = sizeof(pldm_msg_hdr) + |
| 893 | PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 894 | std::vector<uint8_t> request(msgSize); |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 895 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 896 | auto msg = reinterpret_cast<pldm_msg*>(request.data()); |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 897 | auto msgRc = encode_get_state_sensor_readings_req(pldmInstanceID.value(), |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 898 | sensorId, sRearm, 0, msg); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 899 | if (msgRc != PLDM_SUCCESS) |
| 900 | { |
| 901 | log<level::ERR>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 902 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 903 | "encodeGetStateSensorRequest: Failed to encode sensorId:0x{:08X} for OCC{} (rc={})", |
| 904 | sensorId, instance, msgRc) |
| 905 | .c_str()); |
| 906 | } |
| 907 | return request; |
| 908 | } |
| 909 | |
| 910 | // Initiate query of the specified OCC Active Sensor |
| 911 | void Interface::checkActiveSensor(uint8_t instance) |
| 912 | { |
| 913 | static bool tracedOnce = false; |
| 914 | if (pldmFd > 0) |
| 915 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 916 | if (!throttleTraces && !tracedOnce) |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 917 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 918 | log<level::WARNING>( |
Patrick Williams | 4800249 | 2024-02-13 21:43:32 -0600 | [diff] [blame] | 919 | std::format( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 920 | "checkActiveSensor: already waiting on OCC{} (fd={})", |
| 921 | pldmResponseOcc, pldmFd) |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 922 | .c_str()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 923 | tracedOnce = true; |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 924 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 925 | return; |
| 926 | } |
| 927 | tracedOnce = false; |
| 928 | |
| 929 | if (!isOCCSensorCacheValid()) |
| 930 | { |
| 931 | fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 932 | sensorToOCCInstance, OCCSensorOffset); |
| 933 | } |
| 934 | |
| 935 | // look up sensor id (key) based on instance |
| 936 | auto entry = std::find_if( |
| 937 | sensorToOCCInstance.begin(), sensorToOCCInstance.end(), |
| 938 | [instance](const auto& entry) { return instance == entry.second; }); |
| 939 | if (entry != sensorToOCCInstance.end()) |
| 940 | { |
| 941 | // Query the OCC Active Sensor state for this instance |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 942 | if (!throttleTraces) |
| 943 | { |
| 944 | log<level::INFO>( |
| 945 | std::format("checkActiveSensor: OCC{} / sensorID: 0x{:04X}", |
| 946 | instance, entry->first) |
| 947 | .c_str()); |
| 948 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 949 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 950 | // Encode GetStateSensorReadings PLDM message |
| 951 | auto request = encodeGetStateSensorRequest(instance, entry->first); |
| 952 | if (request.empty()) |
| 953 | { |
| 954 | return; |
| 955 | } |
| 956 | |
| 957 | // Send request to PLDM and setup callback for response |
| 958 | sendPldm(request, instance, true); |
| 959 | } |
| 960 | else |
| 961 | { |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 962 | if (!throttleTraces) |
| 963 | { |
| 964 | log<level::ERR>( |
| 965 | std::format( |
| 966 | "checkActiveSensor: Unable to find PLDM sensor for OCC{}", |
| 967 | instance) |
| 968 | .c_str()); |
| 969 | log<level::INFO>( |
| 970 | "checkActiveSensor: fetching STATE_SET_OPERATIONAL_RUNNING_STATUS"); |
| 971 | } |
Chris Cain | 8cf7496 | 2022-06-29 08:45:16 -0500 | [diff] [blame] | 972 | fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 973 | sensorToOCCInstance, OCCSensorOffset); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 974 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 975 | } |
| 976 | |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 977 | void Interface::setTraceThrottle(const bool throttle) |
| 978 | { |
| 979 | if (throttle != throttleTraces) |
| 980 | { |
| 981 | if (throttle) |
| 982 | { |
| 983 | log<level::WARNING>("PLDM traces being throttled"); |
| 984 | } |
| 985 | else |
| 986 | { |
| 987 | log<level::INFO>("PLDM traces no longer being throttled"); |
| 988 | } |
| 989 | throttleTraces = throttle; |
| 990 | } |
| 991 | } |
| 992 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 993 | } // namespace pldm |