Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #pragma once |
George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 2 | #include "config.h" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 3 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 4 | #include "i2c_occ.hpp" |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 5 | #include "occ_command.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 6 | #include "occ_device.hpp" |
| 7 | #include "occ_events.hpp" |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 8 | #include "powercap.hpp" |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 9 | #include "powermode.hpp" |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 10 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 11 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 12 | #include <org/open_power/Control/Host/server.hpp> |
| 13 | #include <org/open_power/OCC/Status/server.hpp> |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 14 | #include <sdbusplus/bus.hpp> |
| 15 | #include <sdbusplus/server/object.hpp> |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 16 | #ifdef POWER10 |
| 17 | #include <sdeventplus/event.hpp> |
| 18 | #include <sdeventplus/utility/timer.hpp> |
| 19 | #endif |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 20 | #include <xyz/openbmc_project/Control/Power/Throttle/server.hpp> |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 21 | |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 22 | #include <functional> |
| 23 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 24 | namespace open_power |
| 25 | { |
| 26 | namespace occ |
| 27 | { |
| 28 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 29 | class Manager; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 30 | namespace Base = sdbusplus::org::open_power::OCC::server; |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 31 | using Interface = sdbusplus::server::object_t<Base::Status>; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 32 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 33 | namespace xyzBase = sdbusplus::xyz::openbmc_project::Control::Power::server; |
| 34 | using ThrottleInterface = sdbusplus::server::object_t<xyzBase::Throttle>; |
| 35 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 36 | // IPMID's host control application |
| 37 | namespace Control = sdbusplus::org::open_power::Control::server; |
| 38 | |
| 39 | // For waiting on signals |
| 40 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 41 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 42 | // OCC status instance. Ex. for "occ0", the instance is 0 |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 43 | using instanceID = unsigned int; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 44 | |
| 45 | // IPMI sensor ID for a given OCC instance |
| 46 | using sensorID = uint8_t; |
| 47 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 48 | // Human readable sensor name for DBus tree. E.g. "CPU0_OCC" |
| 49 | using sensorName = std::string; |
| 50 | |
| 51 | // OCC sensors definitions in the map |
| 52 | using sensorDefs = std::tuple<sensorID, sensorName>; |
| 53 | |
Eddie James | e7d976b | 2018-02-26 13:42:45 -0600 | [diff] [blame] | 54 | // OCC sysfs name prefix |
| 55 | const std::string sysfsName = "occ-hwmon"; |
| 56 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 57 | const uint8_t THROTTLED_NONE = 0x00; |
| 58 | const uint8_t THROTTLED_POWER = 0x01; |
| 59 | const uint8_t THROTTLED_THERMAL = 0x02; |
| 60 | const uint8_t THROTTLED_SAFE = 0x04; |
| 61 | const uint8_t THROTTLED_ALL = 0xFF; |
| 62 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 63 | /** @class Status |
| 64 | * @brief Implementation of OCC Active Status |
| 65 | */ |
| 66 | class Status : public Interface |
| 67 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 68 | public: |
| 69 | Status() = delete; |
| 70 | ~Status() = default; |
| 71 | Status(const Status&) = delete; |
| 72 | Status& operator=(const Status&) = delete; |
| 73 | Status(Status&&) = default; |
| 74 | Status& operator=(Status&&) = default; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 75 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 76 | /** @brief Constructs the Status object and |
| 77 | * the underlying device object |
| 78 | * |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 79 | * @param[in] event - sd_event unique pointer reference |
| 80 | * @param[in] path - DBus object path |
| 81 | * @param[in] manager - OCC manager instance |
| 82 | * @param[in] callBack - Callback handler to invoke during |
| 83 | * property change |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 84 | * @param[in] resetCallBack - callback handler to invoke for resetting the |
| 85 | * OCC if PLDM is the host communication |
| 86 | * protocol |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 87 | */ |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 88 | Status(EventPtr& event, const char* path, Manager& managerRef, |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 89 | #ifdef POWER10 |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 90 | std::unique_ptr<powermode::PowerMode>& powerModeRef, |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 91 | #endif |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 92 | std::function<void(instanceID, bool)> callBack = nullptr |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 93 | #ifdef PLDM |
| 94 | , |
| 95 | std::function<void(instanceID)> resetCallBack = nullptr |
| 96 | #endif |
| 97 | ) : |
| 98 | |
Patrick Williams | 1923a75 | 2022-04-05 21:35:45 -0500 | [diff] [blame] | 99 | Interface(utils::getBus(), getDbusPath(path).c_str(), |
| 100 | Interface::action::defer_emit), |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 101 | path(path), managerCallBack(callBack), instance(getInstance(path)), |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 102 | manager(managerRef), |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 103 | #ifdef POWER10 |
| 104 | pmode(powerModeRef), |
| 105 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | device(event, |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 107 | #ifdef I2C_OCC |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 108 | fs::path(DEV_PATH) / i2c_occ::getI2cDeviceName(path), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 109 | #else |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 110 | fs::path(DEV_PATH) / |
| 111 | fs::path(sysfsName + "." + std::to_string(instance + 1)), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 112 | #endif |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 113 | managerRef, *this, |
| 114 | #ifdef POWER10 |
| 115 | powerModeRef, |
| 116 | #endif |
| 117 | instance), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 118 | hostControlSignal( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 119 | utils::getBus(), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 120 | sdbusRule::type::signal() + sdbusRule::member("CommandComplete") + |
| 121 | sdbusRule::path("/org/open_power/control/host0") + |
| 122 | sdbusRule::interface("org.open_power.Control.Host") + |
| 123 | sdbusRule::argN(0, Control::convertForMessage( |
| 124 | Control::Host::Command::OCCReset)), |
| 125 | std::bind(std::mem_fn(&Status::hostControlEvent), this, |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 126 | std::placeholders::_1)), |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 127 | occCmd(instance, (fs::path(OCC_CONTROL_ROOT) / |
| 128 | (std::string(OCC_NAME) + std::to_string(instance))) |
| 129 | .c_str()) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 130 | #ifdef POWER10 |
| 131 | , |
| 132 | sdpEvent(sdeventplus::Event::get_default()), |
| 133 | safeStateDelayTimer( |
| 134 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>( |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 135 | sdpEvent, std::bind(&Status::safeStateDelayExpired, this))), |
| 136 | occReadStateFailTimer( |
| 137 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>( |
| 138 | sdpEvent, std::bind(&Status::occReadStateNow, this))) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 139 | #endif |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 140 | |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 141 | #ifdef PLDM |
| 142 | , |
| 143 | resetCallBack(resetCallBack) |
| 144 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 145 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 146 | // Announce that we are ready |
| 147 | this->emit_object_added(); |
| 148 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 149 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 150 | /** @brief Since we are overriding the setter-occActive but not the |
| 151 | * getter-occActive, we need to have this using in order to |
| 152 | * allow passthrough usage of the getter-occActive |
| 153 | */ |
| 154 | using Base::Status::occActive; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 155 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 156 | /** @brief SET OccActive to True or False |
| 157 | * |
| 158 | * @param[in] value - Intended value |
| 159 | * |
| 160 | * @return - Updated value of the property |
| 161 | */ |
| 162 | bool occActive(bool value) override; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 163 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 164 | /** @brief Starts OCC error detection */ |
| 165 | inline void addErrorWatch() |
| 166 | { |
| 167 | return device.addErrorWatch(); |
| 168 | } |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 169 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 170 | /** @brief Stops OCC error detection */ |
| 171 | inline void removeErrorWatch() |
| 172 | { |
| 173 | return device.removeErrorWatch(); |
| 174 | } |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 175 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 176 | /** @brief Starts to watch how many OCCs are present on the master */ |
| 177 | inline void addPresenceWatchMaster() |
| 178 | { |
| 179 | return device.addPresenceWatchMaster(); |
| 180 | } |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 181 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 182 | /** @brief Gets the occ instance number */ |
| 183 | unsigned int getOccInstanceID() |
| 184 | { |
| 185 | return instance; |
| 186 | } |
| 187 | |
| 188 | /** @brief Is this OCC the master OCC */ |
| 189 | bool isMasterOcc() |
| 190 | { |
| 191 | return device.master(); |
| 192 | } |
| 193 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 194 | /** @brief Read OCC state (will trigger kernel to poll the OCC) */ |
| 195 | void readOccState(); |
| 196 | |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 197 | /** @brief Called when device errors are detected |
| 198 | * |
| 199 | * @param[in] d - description of the error that occurred |
| 200 | */ |
| 201 | void deviceError(Error::Descriptor d = Error::Descriptor()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 202 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 203 | #ifdef POWER10 |
| 204 | /** @brief Handle additional tasks when the OCCs reach active state */ |
| 205 | void occsWentActive(); |
| 206 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 207 | /** @brief Send Ambient & Altitude data to OCC |
| 208 | * |
| 209 | * @param[in] ambient - temperature to send (0xFF will force read |
| 210 | * of current temperature and altitude) |
| 211 | * @param[in] altitude - altitude to send (0xFFFF = unavailable) |
| 212 | * |
| 213 | * @return SUCCESS on success |
| 214 | */ |
| 215 | CmdStatus sendAmbient(const uint8_t ambient = 0xFF, |
| 216 | const uint16_t altitude = 0xFFFF); |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 217 | |
| 218 | /** @brief Set flag indicating if PLDM sensor has been received |
| 219 | * |
| 220 | * @param[in] wasReceived - true if PLDM sensor was read |
| 221 | */ |
| 222 | void setPldmSensorReceived(const bool wasReceived) |
| 223 | { |
| 224 | pldmSensorStateReceived = wasReceived; |
| 225 | } |
| 226 | |
| 227 | /** @brief Read flag indicating if PLDM sensor has been read |
| 228 | * |
| 229 | * @return true if sensor has been read |
| 230 | */ |
| 231 | bool getPldmSensorReceived() |
| 232 | { |
| 233 | return pldmSensorStateReceived; |
| 234 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 235 | #endif // POWER10 |
| 236 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 237 | /** @brief Return the HWMON path for this OCC |
| 238 | * |
| 239 | * @return path or empty path if not found |
| 240 | */ |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 241 | fs::path getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 242 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 243 | /** @brief Update the processor path associated with this OCC |
| 244 | */ |
| 245 | void updateProcAssociation() |
| 246 | { |
| 247 | readProcAssociation(); |
| 248 | if (nullptr != throttleHandle) |
| 249 | { |
| 250 | throttleHandle.reset(); |
| 251 | } |
| 252 | if (!procPath.empty()) |
| 253 | { |
| 254 | throttleHandle = std::make_unique<ThrottleInterface>( |
| 255 | utils::getBus(), procPath.c_str()); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /** @brief Update the processor throttle status on dbus |
| 260 | */ |
| 261 | void updateThrottle(const bool isThrottled, const uint8_t reason); |
| 262 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 263 | private: |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 264 | /** @brief OCC dbus object path */ |
| 265 | std::string path; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 266 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 267 | /** @brief Processor path associated with this OCC */ |
| 268 | std::string procPath; |
| 269 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 270 | /** @brief Callback handler to be invoked during property change. |
| 271 | * This is a handler in Manager class |
| 272 | */ |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 273 | std::function<void(instanceID, bool)> managerCallBack; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 274 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 275 | /** @brief OCC instance number. Ex, 0,1, etc */ |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 276 | unsigned int instance; |
| 277 | |
| 278 | /** @brief The last state read from the OCC */ |
| 279 | unsigned int lastState = 0; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 280 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 281 | /** @brief Number of retry attempts to open file and update state. */ |
| 282 | const unsigned int occReadRetries = 1; |
| 283 | |
| 284 | /** @brief Current number of retries attempted towards occReadRetries. */ |
| 285 | size_t currentOccReadRetriesCount = 0; |
| 286 | |
| 287 | /** @brief The Trigger to indicate OCC State is valid or not. */ |
| 288 | bool stateValid = false; |
| 289 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 290 | /** @brief OCC instance to Sensor definitions mapping */ |
| 291 | static const std::map<instanceID, sensorDefs> sensorMap; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 292 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 293 | /** @brief OCC manager object */ |
| 294 | const Manager& manager; |
| 295 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 296 | #ifdef POWER10 |
| 297 | /** @brief OCC PowerMode object */ |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 298 | std::unique_ptr<powermode::PowerMode>& pmode; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 299 | #endif |
| 300 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 301 | /** @brief OCC device object to do bind and unbind */ |
| 302 | Device device; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 303 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 304 | /** @brief Subscribe to host control signal |
| 305 | * |
| 306 | * Once the OCC reset is requested, BMC sends that message to host. |
| 307 | * If the host does not ack the message, then there would be a timeout |
| 308 | * and we need to catch that to log an error |
| 309 | **/ |
| 310 | sdbusplus::bus::match_t hostControlSignal; |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 311 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 312 | /** @brief Command object to send commands to the OCC */ |
| 313 | OccCommand occCmd; |
| 314 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 315 | #ifdef POWER10 |
| 316 | /** @brief timer event */ |
| 317 | sdeventplus::Event sdpEvent; |
| 318 | #endif |
| 319 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 320 | /** @brief hwmon path for this OCC */ |
| 321 | fs::path hwmonPath; |
| 322 | |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 323 | /** @brief flag indicating if the OCC sensor has been received */ |
| 324 | bool pldmSensorStateReceived = false; |
| 325 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 326 | /** @brief Callback function on host control signals |
| 327 | * |
| 328 | * @param[in] msg - Data associated with subscribed signal |
| 329 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 330 | void hostControlEvent(sdbusplus::message_t& msg); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 331 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 332 | /** @brief Sends a message to host control command handler to reset OCC |
| 333 | */ |
| 334 | void resetOCC(); |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 335 | |
| 336 | /** @brief Determines the instance ID by specified object path. |
| 337 | * @param[in] path Estimated OCC Dbus object path |
| 338 | * @return Instance number |
| 339 | */ |
| 340 | static int getInstance(const std::string& path) |
| 341 | { |
| 342 | return (path.empty() ? 0 : path.back() - '0'); |
| 343 | } |
| 344 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 345 | #ifdef POWER10 |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 346 | /** |
| 347 | * @brief Timer that is started when OCC is detected to be in safe mode |
| 348 | */ |
| 349 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> |
| 350 | safeStateDelayTimer; |
| 351 | |
| 352 | /** @brief Callback for timer that is started when OCC was detected to be in |
| 353 | * safe mode. Called to verify and then disable and reset the OCCs. |
| 354 | */ |
| 355 | void safeStateDelayExpired(); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * @brief Timer that is started when OCC read Valid state failed. |
| 359 | */ |
| 360 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> |
| 361 | occReadStateFailTimer; |
| 362 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 363 | #endif // POWER10 |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 364 | /** @brief Callback for timer that is started when OCC state |
| 365 | * was not able to be read. Called to attempt another read when needed. |
| 366 | */ |
| 367 | void occReadStateNow(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 368 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 369 | /** @brief Override the sensor name with name from the definition. |
| 370 | * @param[in] estimatedPath - Estimated OCC Dbus object path |
| 371 | * @return Fixed OCC DBus object path |
| 372 | */ |
| 373 | static std::string getDbusPath(const std::string& estimatedPath) |
| 374 | { |
| 375 | if (!estimatedPath.empty()) |
| 376 | { |
| 377 | auto it = sensorMap.find(getInstance(estimatedPath)); |
| 378 | if (sensorMap.end() != it) |
| 379 | { |
| 380 | auto& name = std::get<1>(it->second); |
| 381 | if (!name.empty() && name != "None") |
| 382 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 383 | auto objectPath = fs::path(estimatedPath); |
| 384 | objectPath.replace_filename(name); |
| 385 | return objectPath.string(); |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return estimatedPath; |
| 391 | } |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 392 | #ifdef PLDM |
| 393 | std::function<void(instanceID)> resetCallBack = nullptr; |
| 394 | #endif |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 395 | |
| 396 | /** @brief Current throttle reason(s) for this processor */ |
| 397 | uint8_t throttleCause = THROTTLED_NONE; |
| 398 | |
| 399 | /** @brief Throttle interface for the processor associated with this OCC */ |
| 400 | std::unique_ptr<ThrottleInterface> throttleHandle; |
| 401 | |
| 402 | /** @brief Read the processor path associated with this OCC */ |
| 403 | void readProcAssociation(); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | } // namespace occ |
| 407 | } // namespace open_power |