Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 3 | #include "average.hpp" |
| 4 | #include "maximum.hpp" |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 5 | #include "pmbus.hpp" |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 6 | #include "record_manager.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 7 | #include "types.hpp" |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 8 | #include "util.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 9 | #include "utility.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 10 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 11 | #include <gpiod.hpp> |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 12 | #include <sdbusplus/bus/match.hpp> |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 13 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 15 | #include <xyz/openbmc_project/State/Decorator/Availability/server.hpp> |
| 16 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 17 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 18 | #include <filesystem> |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 19 | #include <stdexcept> |
| 20 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 21 | namespace phosphor::power::psu |
| 22 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 23 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 24 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 25 | // PMBus device driver "file name" to read for CCIN value. |
| 26 | constexpr auto CCIN = "ccin"; |
Matt Spinler | b40f04c | 2023-03-20 11:07:44 -0500 | [diff] [blame] | 27 | constexpr auto PART_NUMBER = "mfr_revision"; |
| 28 | constexpr auto FRU_NUMBER = "mfr_model"; |
| 29 | constexpr auto SERIAL_HEADER = "mfr_location"; |
| 30 | constexpr auto SERIAL_NUMBER = "mfr_serial"; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 31 | constexpr auto FW_VERSION = "fw_version"; |
| 32 | |
| 33 | // The D-Bus property name to update with the CCIN value. |
| 34 | constexpr auto MODEL_PROP = "Model"; |
| 35 | constexpr auto PN_PROP = "PartNumber"; |
Brandon Wyman | a169b0f | 2021-12-07 20:18:06 +0000 | [diff] [blame] | 36 | constexpr auto SPARE_PN_PROP = "SparePartNumber"; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 37 | constexpr auto SN_PROP = "SerialNumber"; |
| 38 | constexpr auto VERSION_PROP = "Version"; |
| 39 | |
| 40 | // ipzVPD Keyword sizes |
| 41 | static constexpr auto FL_KW_SIZE = 20; |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 42 | static constexpr auto FN_KW_SIZE = 7; |
| 43 | static constexpr auto PN_KW_SIZE = 7; |
| 44 | // For IBM power supplies, the SN is 6-byte header + 6-byte serial. |
| 45 | static constexpr auto SN_KW_SIZE = 12; |
| 46 | static constexpr auto CC_KW_SIZE = 4; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 47 | #endif |
| 48 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 49 | constexpr auto LOG_LIMIT = 3; |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 50 | constexpr auto DEGLITCH_LIMIT = 3; |
Brandon Wyman | 6d469fd | 2022-06-15 16:58:21 +0000 | [diff] [blame] | 51 | constexpr auto PGOOD_DEGLITCH_LIMIT = 5; |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 52 | // Number of polls to remember that an AC fault occured. Should remain greater |
| 53 | // than PGOOD_DEGLITCH_LIMIT. |
| 54 | constexpr auto AC_FAULT_LIMIT = 6; |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 55 | |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 56 | constexpr auto IBMCFFPS_DD_NAME = "ibm-cffps"; |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame] | 57 | constexpr auto ACBEL_FSG032_DD_NAME = "acbel-fsg032"; |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 58 | |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 59 | using AvailabilityInterface = |
| 60 | sdbusplus::xyz::openbmc_project::State::Decorator::server::Availability; |
| 61 | using OperationalStatusInterface = sdbusplus::xyz::openbmc_project::State:: |
| 62 | Decorator::server::OperationalStatus; |
| 63 | using AssocDefInterface = |
| 64 | sdbusplus::xyz::openbmc_project::Association::server::Definitions; |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 65 | using SensorInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value; |
| 66 | using SensorObject = sdbusplus::server::object_t<SensorInterface>; |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 67 | using PowerSensorObject = |
| 68 | sdbusplus::server::object_t<SensorInterface, OperationalStatusInterface, |
| 69 | AvailabilityInterface, AssocDefInterface>; |
| 70 | |
| 71 | using AssociationTuple = std::tuple<std::string, std::string, std::string>; |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 72 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 73 | /** |
| 74 | * @class PowerSupply |
| 75 | * Represents a PMBus power supply device. |
| 76 | */ |
| 77 | class PowerSupply |
| 78 | { |
| 79 | public: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 80 | PowerSupply() = delete; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 81 | PowerSupply(const PowerSupply&) = delete; |
| 82 | PowerSupply(PowerSupply&&) = delete; |
| 83 | PowerSupply& operator=(const PowerSupply&) = delete; |
| 84 | PowerSupply& operator=(PowerSupply&&) = delete; |
| 85 | ~PowerSupply() = default; |
| 86 | |
| 87 | /** |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 88 | * @param[in] invpath - String for inventory path to use |
| 89 | * @param[in] i2cbus - The bus number this power supply is on |
| 90 | * @param[in] i2caddr - The 16-bit I2C address of the power supply |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 91 | * @param[in] driver - i2c driver name for power supply |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 92 | * @param[in] gpioLineName - The gpio-line-name to read for presence. See |
| 93 | * https://github.com/openbmc/docs/blob/master/designs/device-tree-gpio-naming.md |
George Liu | 9464c42 | 2023-02-27 14:30:27 +0800 | [diff] [blame] | 94 | * @param[in] callback - Get the power on status of the psu manager class |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 95 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 96 | PowerSupply(sdbusplus::bus_t& bus, const std::string& invpath, |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 97 | std::uint8_t i2cbus, const std::uint16_t i2caddr, |
George Liu | 9464c42 | 2023-02-27 14:30:27 +0800 | [diff] [blame] | 98 | const std::string& driver, const std::string& gpioLineName, |
| 99 | std::function<bool()>&& callback); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 100 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 101 | phosphor::pmbus::PMBusBase& getPMBus() |
| 102 | { |
| 103 | return *pmbusIntf; |
| 104 | } |
| 105 | |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 106 | GPIOInterfaceBase* getPresenceGPIO() |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 107 | { |
| 108 | return presenceGPIO.get(); |
| 109 | } |
| 110 | |
B. J. Wyman | d8b8cb1 | 2021-07-15 22:03:34 +0000 | [diff] [blame] | 111 | std::string getPresenceGPIOName() const |
| 112 | { |
| 113 | if (presenceGPIO != nullptr) |
| 114 | { |
| 115 | return presenceGPIO->getName(); |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | return std::string(); |
| 120 | } |
| 121 | } |
| 122 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 123 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 124 | * Power supply specific function to analyze for faults/errors. |
| 125 | * |
| 126 | * Various PMBus status bits will be checked for fault conditions. |
| 127 | * If a certain fault bits are on, the appropriate error will be |
| 128 | * committed. |
| 129 | */ |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 130 | void analyze(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 131 | |
| 132 | /** |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 133 | * Write PMBus ON_OFF_CONFIG |
| 134 | * |
| 135 | * This function will be called to cause the PMBus device driver to send the |
| 136 | * ON_OFF_CONFIG command. Takes one byte of data. |
| 137 | * |
| 138 | * @param[in] data - The ON_OFF_CONFIG data byte mask. |
| 139 | */ |
| 140 | void onOffConfig(uint8_t data); |
| 141 | |
| 142 | /** |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 143 | * Clears all the member variables that indicate if a fault bit was seen as |
| 144 | * on in the STATUS_WORD or STATUS_MFR_SPECIFIC response. |
| 145 | */ |
| 146 | void clearFaultFlags() |
| 147 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 148 | inputFault = 0; |
| 149 | mfrFault = 0; |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 150 | statusMFR = 0; |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 151 | vinUVFault = 0; |
| 152 | cmlFault = 0; |
| 153 | voutOVFault = 0; |
| 154 | ioutOCFault = 0; |
| 155 | voutUVFault = 0; |
| 156 | fanFault = 0; |
| 157 | tempFault = 0; |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 158 | pgoodFault = 0; |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 159 | psKillFault = 0; |
| 160 | ps12VcsFault = 0; |
| 161 | psCS12VFault = 0; |
Brandon Wyman | ba6d960 | 2022-05-02 18:10:47 +0000 | [diff] [blame] | 162 | faultLogged = false; |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 166 | * @brief Function to specifically clear VIN_UV/OFF fault(s). |
| 167 | * |
| 168 | * The PMBus HWMON device driver has various alarm "files" to read out of |
| 169 | * sysfs. Reading those files will indicate if various alarms are active or |
| 170 | * not, and then specifically clear those faults that go with that alarm. |
| 171 | * |
| 172 | * The VIN_UV fault, indicated in STATUS_INPUT, goes with in1_lcrit_alarm. |
| 173 | * When a VIN_UV fault occurs, the "Unit Off For Insufficient Input Voltage" |
| 174 | * may also be active. Reading in1_lcrit_alarm should clear both fault bits, |
| 175 | * resulting in the corresponding fault bits in STATUS_WORD also clearing. |
| 176 | * |
| 177 | * See: https://www.kernel.org/doc/html/latest/hwmon/pmbus.html |
| 178 | */ |
| 179 | void clearVinUVFault(); |
| 180 | |
| 181 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 182 | * Write PMBus CLEAR_FAULTS |
| 183 | * |
| 184 | * This function will be called in various situations in order to clear |
| 185 | * any fault status bits that may have been set, in order to start over |
| 186 | * with a clean state. Presence changes and power state changes will |
| 187 | * want to clear any faults logged. |
| 188 | */ |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 189 | void clearFaults(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * @brief Adds properties to the inventory. |
| 193 | * |
| 194 | * Reads the values from the device and writes them to the |
| 195 | * associated power supply D-Bus inventory object. |
| 196 | * |
| 197 | * This needs to be done on startup, and each time the presence |
| 198 | * state changes. |
| 199 | * |
| 200 | * Properties added: |
| 201 | * - Serial Number |
| 202 | * - Part Number |
| 203 | * - CCIN (Customer Card Identification Number) - added as the Model |
| 204 | * - Firmware version |
| 205 | */ |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 206 | void updateInventory(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 207 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 208 | /** |
| 209 | * @brief Accessor function to indicate present status |
| 210 | */ |
| 211 | bool isPresent() const |
| 212 | { |
| 213 | return present; |
| 214 | } |
| 215 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 216 | /** |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 217 | * @brief Returns the last read value from STATUS_WORD. |
| 218 | */ |
| 219 | uint64_t getStatusWord() const |
| 220 | { |
| 221 | return statusWord; |
| 222 | } |
| 223 | |
| 224 | /** |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 225 | * @brief Returns the last read value from STATUS_INPUT. |
| 226 | */ |
| 227 | uint64_t getStatusInput() const |
| 228 | { |
| 229 | return statusInput; |
| 230 | } |
| 231 | |
| 232 | /** |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 233 | * @brief Returns the last read value from STATUS_MFR. |
| 234 | */ |
| 235 | uint64_t getMFRFault() const |
| 236 | { |
| 237 | return statusMFR; |
| 238 | } |
| 239 | |
| 240 | /** |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 241 | * @brief Returns the last read value from STATUS_CML. |
| 242 | */ |
| 243 | uint64_t getStatusCML() const |
| 244 | { |
| 245 | return statusCML; |
| 246 | } |
| 247 | |
| 248 | /** |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 249 | * @brief Returns the last read value from STATUS_VOUT. |
| 250 | */ |
| 251 | uint64_t getStatusVout() const |
| 252 | { |
| 253 | return statusVout; |
| 254 | } |
| 255 | |
| 256 | /** |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 257 | * @brief Returns the last value read from STATUS_IOUT. |
| 258 | */ |
| 259 | uint64_t getStatusIout() const |
| 260 | { |
| 261 | return statusIout; |
| 262 | } |
| 263 | |
| 264 | /** |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 265 | * @brief Returns the last value read from STATUS_FANS_1_2. |
| 266 | */ |
| 267 | uint64_t getStatusFans12() const |
| 268 | { |
| 269 | return statusFans12; |
| 270 | } |
| 271 | |
| 272 | /** |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 273 | * @brief Returns the last value read from STATUS_TEMPERATURE. |
| 274 | */ |
| 275 | uint64_t getStatusTemperature() const |
| 276 | { |
| 277 | return statusTemperature; |
| 278 | } |
| 279 | |
| 280 | /** |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 281 | * @brief Returns true if a fault was found. |
| 282 | */ |
| 283 | bool isFaulted() const |
| 284 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 285 | return (hasCommFault() || (vinUVFault >= DEGLITCH_LIMIT) || |
| 286 | (inputFault >= DEGLITCH_LIMIT) || |
| 287 | (voutOVFault >= DEGLITCH_LIMIT) || |
| 288 | (ioutOCFault >= DEGLITCH_LIMIT) || |
| 289 | (voutUVFault >= DEGLITCH_LIMIT) || |
| 290 | (fanFault >= DEGLITCH_LIMIT) || (tempFault >= DEGLITCH_LIMIT) || |
Brandon Wyman | 6d469fd | 2022-06-15 16:58:21 +0000 | [diff] [blame] | 291 | (pgoodFault >= PGOOD_DEGLITCH_LIMIT) || |
| 292 | (mfrFault >= DEGLITCH_LIMIT)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 296 | * @brief Return whether a fault has been logged for this power supply |
| 297 | */ |
| 298 | bool isFaultLogged() const |
| 299 | { |
| 300 | return faultLogged; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * @brief Called when a fault for this power supply has been logged. |
| 305 | */ |
| 306 | void setFaultLogged() |
| 307 | { |
| 308 | faultLogged = true; |
| 309 | } |
| 310 | |
| 311 | /** |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 312 | * @brief Returns true if INPUT fault occurred. |
| 313 | */ |
| 314 | bool hasInputFault() const |
| 315 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 316 | return (inputFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * @brief Returns true if MFRSPECIFIC occurred. |
| 321 | */ |
| 322 | bool hasMFRFault() const |
| 323 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 324 | return (mfrFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * @brief Returns true if VIN_UV_FAULT occurred. |
| 329 | */ |
| 330 | bool hasVINUVFault() const |
| 331 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 332 | return (vinUVFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 333 | } |
| 334 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 335 | /** |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 336 | * @brief Returns true if VOUT_OV_FAULT occurred. |
| 337 | */ |
| 338 | bool hasVoutOVFault() const |
| 339 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 340 | return (voutOVFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 344 | * @brief Returns true if IOUT_OC fault occurred (bit 4 STATUS_BYTE). |
| 345 | */ |
| 346 | bool hasIoutOCFault() const |
| 347 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 348 | return (ioutOCFault >= DEGLITCH_LIMIT); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 352 | * @brief Returns true if VOUT_UV_FAULT occurred. |
| 353 | */ |
| 354 | bool hasVoutUVFault() const |
| 355 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 356 | return (voutUVFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /** |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 360 | *@brief Returns true if fan fault occurred. |
| 361 | */ |
| 362 | bool hasFanFault() const |
| 363 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 364 | return (fanFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 368 | * @brief Returns true if TEMPERATURE fault occurred. |
| 369 | */ |
| 370 | bool hasTempFault() const |
| 371 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 372 | return (tempFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 376 | * @brief Returns true if there is a PGood fault (PGOOD# inactive, or OFF |
| 377 | * bit on). |
| 378 | */ |
| 379 | bool hasPgoodFault() const |
| 380 | { |
Brandon Wyman | 6d469fd | 2022-06-15 16:58:21 +0000 | [diff] [blame] | 381 | return (pgoodFault >= PGOOD_DEGLITCH_LIMIT); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 385 | * @brief Return true if there is a PS_Kill fault. |
| 386 | */ |
| 387 | bool hasPSKillFault() const |
| 388 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 389 | return (psKillFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /** |
| 393 | * @brief Returns true if there is a 12Vcs (standy power) fault. |
| 394 | */ |
| 395 | bool hasPS12VcsFault() const |
| 396 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 397 | return (ps12VcsFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
| 401 | * @brief Returns true if there is a 12V current-share fault. |
| 402 | */ |
| 403 | bool hasPSCS12VFault() const |
| 404 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 405 | return (psCS12VFault >= DEGLITCH_LIMIT); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /** |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 409 | * @brief Returns true if an AC fault has occurred in the window of |
| 410 | * interest. |
| 411 | */ |
| 412 | bool hasACFault() const |
| 413 | { |
| 414 | return acFault != 0; |
| 415 | } |
| 416 | |
| 417 | /** |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 418 | * @brief Returns the device path |
| 419 | * |
| 420 | * This can be used for error call outs. |
| 421 | * Example: /sys/bus/i2c/devices/3-0068 |
| 422 | */ |
Brandon Wyman | 4176d6b | 2020-10-07 17:41:06 -0500 | [diff] [blame] | 423 | const std::string getDevicePath() const |
| 424 | { |
| 425 | return pmbusIntf->path(); |
| 426 | } |
| 427 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 428 | /** |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 429 | * @brief Returns this power supply's inventory path. |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 430 | * |
| 431 | * This can be used for error call outs. |
| 432 | * Example: |
| 433 | * /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1 |
| 434 | */ |
Brandon Wyman | 7e49527 | 2020-09-26 19:57:46 -0500 | [diff] [blame] | 435 | const std::string& getInventoryPath() const |
| 436 | { |
| 437 | return inventoryPath; |
| 438 | } |
| 439 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 440 | /** |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 441 | * @brief Returns the short name (last part of inventoryPath). |
| 442 | */ |
| 443 | const std::string& getShortName() const |
| 444 | { |
| 445 | return shortName; |
| 446 | } |
| 447 | |
| 448 | /** |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 449 | * @brief Returns the firmware revision version read from the power supply |
| 450 | */ |
| 451 | const std::string& getFWVersion() const |
| 452 | { |
| 453 | return fwVersion; |
| 454 | } |
| 455 | |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 456 | /** |
| 457 | * @brief Returns the model name of the power supply |
| 458 | */ |
| 459 | const std::string& getModelName() const |
| 460 | { |
| 461 | return modelName; |
| 462 | } |
| 463 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 464 | /** |
| 465 | * @brief Returns true if the number of failed reads exceeds limit |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 466 | * TODO: or CML bit on. |
| 467 | */ |
| 468 | bool hasCommFault() const |
| 469 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 470 | return ((readFail >= LOG_LIMIT) || (cmlFault >= DEGLITCH_LIMIT)); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 471 | } |
| 472 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 473 | /** |
| 474 | * @brief Reads the pmbus input voltage and returns that actual voltage |
| 475 | * reading and the calculated input voltage based on thresholds. |
| 476 | * @param[out] actualInputVoltage - The actual voltage reading, in Volts. |
| 477 | * @param[out] inputVoltage - A rounded up/down value of the actual input |
| 478 | * voltage based on thresholds, in Volts. |
| 479 | */ |
| 480 | void getInputVoltage(double& actualInputVoltage, int& inputVoltage) const; |
| 481 | |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 482 | /** |
| 483 | * @brief Check if the PS is considered to be available or not |
| 484 | * |
| 485 | * It is unavailable if any of: |
| 486 | * - not present |
| 487 | * - input fault active |
| 488 | * - Vin UV fault active |
| 489 | * - PS KILL fault active |
| 490 | * - Iout OC fault active |
| 491 | * |
| 492 | * Other faults will, through creating error logs with callouts, already |
| 493 | * be setting the Functional property to false. |
| 494 | * |
| 495 | * On changes, the Available property is updated in the inventory. |
| 496 | */ |
| 497 | void checkAvailability(); |
| 498 | |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 499 | /** |
| 500 | * @brief Setup for power supply input history. |
| 501 | * |
| 502 | * This will setup the variables and interfaces needed to get the power |
| 503 | * supply input history data over to D-Bus. The only known support for this |
| 504 | * at this time is the INPUT_HISTORY command implemented by the IBM Common |
| 505 | * Form Factor Power Suppplies (ibm-cffps). The INPUT_HISTORY command for |
| 506 | * ibm-cffps is implemented via a manufacturing specific PMBus command. |
| 507 | */ |
| 508 | void setupInputHistory(); |
| 509 | |
| 510 | /** |
| 511 | * @brief Returns true if this power supply has input history (supported). |
| 512 | */ |
| 513 | bool hasInputHistory() const |
| 514 | { |
| 515 | return inputHistorySupported; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * @brief Returns the number of input history records |
| 520 | * |
| 521 | * PowerSupply wrapper to getNumRecords() from RecordManager. |
| 522 | */ |
| 523 | size_t getNumInputHistoryRecords() const |
| 524 | { |
| 525 | if (recordManager) |
| 526 | { |
| 527 | return recordManager->getNumRecords(); |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | return 0; |
| 532 | } |
| 533 | } |
| 534 | |
Brandon Wyman | 18a24d9 | 2022-04-19 22:48:34 +0000 | [diff] [blame] | 535 | /** |
| 536 | * @brief Returns true when INPUT_HISTORY sync is required. |
| 537 | */ |
| 538 | bool isSyncHistoryRequired() const |
| 539 | { |
| 540 | return syncHistoryRequired; |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * @brief Clears the indicator that sync required for INPUT_HISTORY. |
| 545 | * |
| 546 | * Sets variable to false to indicate that the sync is no longer required. |
| 547 | * This can be used after the PSUManager has reacted to the need for the |
| 548 | * INPUT_HISTORY data to be synchronized. |
| 549 | */ |
| 550 | void clearSyncHistoryRequired() |
| 551 | { |
| 552 | syncHistoryRequired = false; |
| 553 | } |
| 554 | |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 555 | /** |
| 556 | * @brief Puts the input voltage rating on D-Bus. |
| 557 | * |
| 558 | * The rating is like 0, 110, 220. |
| 559 | */ |
| 560 | void setInputVoltageRating(); |
| 561 | |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 562 | /** |
| 563 | * @brief Returns the peak input power value if there is one, |
| 564 | * otherwise std::nullopt. |
| 565 | */ |
| 566 | std::optional<double> getPeakInputPower() const |
| 567 | { |
| 568 | std::optional<double> value; |
| 569 | if (peakInputPowerSensor) |
| 570 | { |
| 571 | value = peakInputPowerSensor->value(); |
| 572 | } |
| 573 | return value; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * @brief Converts a Linear Format power number to an integer |
| 578 | * |
| 579 | * The PMBus spec describes a 2 byte Linear Format |
| 580 | * number that is composed of an exponent and mantissa |
| 581 | * in two's complement notation. |
| 582 | * |
| 583 | * Value = Mantissa * 2**Exponent |
| 584 | * |
| 585 | * @return double - The converted value |
| 586 | */ |
| 587 | static double linearToInteger(uint16_t data); |
| 588 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 589 | private: |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 590 | /** |
Matt Spinler | d676026 | 2023-08-30 10:13:05 -0500 | [diff] [blame] | 591 | * @brief Examine STATUS_WORD for CML (communication, memory, logic fault). |
| 592 | */ |
| 593 | void analyzeCMLFault(); |
| 594 | |
| 595 | /** |
| 596 | * @brief Examine STATUS_WORD for INPUT bit on. |
| 597 | * |
| 598 | * "An input voltage, input current, or input power fault or warning has |
| 599 | * occurred." |
| 600 | */ |
| 601 | void analyzeInputFault(); |
| 602 | |
| 603 | /** |
| 604 | * @brief Examine STATUS_WORD for VOUT being set. |
| 605 | * |
| 606 | * If VOUT is on, "An output voltage fault or warning has occurred.", and |
| 607 | * VOUT_OV_FAULT is on, there is an output over-voltage fault. |
| 608 | */ |
| 609 | void analyzeVoutOVFault(); |
| 610 | |
| 611 | /** |
| 612 | * @brief Examine STATUS_WORD value read for IOUT_OC_FAULT. |
| 613 | * |
| 614 | * "An output overcurrent fault has occurred." If it is on, and fault not |
| 615 | * set, trace STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_IOUT values. |
| 616 | */ |
| 617 | void analyzeIoutOCFault(); |
| 618 | |
| 619 | /** |
| 620 | * @brief Examines STATUS_WORD value read to see if there is a UV fault. |
| 621 | * |
| 622 | * Checks if the VOUT bit is on, indicating "An output voltage fault or |
| 623 | * warning has occurred", if it is on, but VOUT_OV_FAULT is off, it is |
| 624 | * determined to be an indication of an output under-voltage fault. |
| 625 | */ |
| 626 | void analyzeVoutUVFault(); |
| 627 | |
| 628 | /** |
| 629 | * @brief Examine STATUS_WORD for the fan fault/warning bit. |
| 630 | * |
| 631 | * If fanFault is not on, trace that the bit now came on, include |
| 632 | * STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_FANS_1_2 values as well, to |
| 633 | * help with understanding what may have caused it to be set. |
| 634 | */ |
| 635 | void analyzeFanFault(); |
| 636 | |
| 637 | /** |
| 638 | * @brief Examine STATUS_WORD for temperature fault. |
| 639 | */ |
| 640 | void analyzeTemperatureFault(); |
| 641 | |
| 642 | /** |
| 643 | * @brief Examine STATUS_WORD for pgood or unit off faults. |
| 644 | */ |
| 645 | void analyzePgoodFault(); |
| 646 | |
| 647 | /** |
| 648 | * @brief Determine possible manufacturer-specific faults from bits in |
| 649 | * STATUS_MFR. |
| 650 | * |
| 651 | * The bits in the STATUS_MFR_SPECIFIC command response have "Manufacturer |
| 652 | * Defined" meanings. Determine which faults, if any, are present based on |
| 653 | * the power supply (device driver) type. |
| 654 | */ |
| 655 | void determineMFRFault(); |
| 656 | |
| 657 | /** |
| 658 | * @brief Examine STATUS_WORD value read for MFRSPECIFIC bit on. |
| 659 | * |
| 660 | * "A manufacturer specific fault or warning has occurred." |
| 661 | * |
| 662 | * If it is on, call the determineMFRFault() helper function to examine the |
| 663 | * value read from STATUS_MFR_SPECIFIC. |
| 664 | */ |
| 665 | void analyzeMFRFault(); |
| 666 | |
| 667 | /** |
| 668 | * @brief Analyzes the STATUS_WORD for a VIN_UV_FAULT indicator. |
| 669 | */ |
| 670 | void analyzeVinUVFault(); |
| 671 | |
| 672 | /** |
| 673 | * @brief Given a full inventory path, returns the last node of the path as |
| 674 | * the "short name" |
| 675 | */ |
| 676 | std::string findShortName(const std::string& invPath) |
| 677 | { |
| 678 | const auto lastSlashPos = invPath.find_last_of('/'); |
| 679 | |
| 680 | if ((lastSlashPos == std::string::npos) || |
| 681 | ((lastSlashPos + 1) == invPath.size())) |
| 682 | { |
| 683 | return invPath; |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | return invPath.substr(lastSlashPos + 1); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * @brief Binds or unbinds the power supply device driver |
| 693 | * |
| 694 | * Called when a presence change is detected to either bind the device |
| 695 | * driver for the power supply when it is installed, or unbind the device |
| 696 | * driver when the power supply is removed. |
| 697 | * |
| 698 | * Writes <device> to <path>/bind (or unbind) |
| 699 | * |
| 700 | * @param present - when true, will bind the device driver |
| 701 | * when false, will unbind the device driver |
| 702 | */ |
| 703 | void bindOrUnbindDriver(bool present); |
| 704 | |
| 705 | /** |
| 706 | * @brief Updates the presence status by querying D-Bus |
| 707 | * |
| 708 | * The D-Bus inventory properties for this power supply will be read to |
| 709 | * determine if the power supply is present or not and update this |
| 710 | * object's present member variable to reflect current status. |
| 711 | **/ |
| 712 | void updatePresence(); |
| 713 | |
| 714 | /** |
| 715 | * @brief Updates the power supply presence by reading the GPIO line. |
| 716 | */ |
| 717 | void updatePresenceGPIO(); |
| 718 | |
| 719 | /** |
| 720 | * @brief Callback for inventory property changes |
| 721 | * |
| 722 | * Process change of Present property for power supply. |
| 723 | * |
| 724 | * This is used if we are watching the D-Bus properties instead of reading |
| 725 | * the GPIO presence line ourselves. |
| 726 | * |
| 727 | * @param[in] msg - Data associated with Present change signal |
| 728 | **/ |
| 729 | void inventoryChanged(sdbusplus::message_t& msg); |
| 730 | |
| 731 | /** |
| 732 | * @brief Callback for inventory property added. |
| 733 | * |
| 734 | * Process add of the interface with the Present property for power supply. |
| 735 | * |
| 736 | * This is used if we are watching the D-Bus properties instead of reading |
| 737 | * the GPIO presence line ourselves. |
| 738 | * |
| 739 | * @param[in] msg - Data associated with Present add signal |
| 740 | **/ |
| 741 | void inventoryAdded(sdbusplus::message_t& msg); |
| 742 | |
| 743 | /** |
| 744 | * @brief Reads the pmbus MFR_POUT_MAX value. |
| 745 | * |
| 746 | * "The MFR_POUT_MAX command sets or retrieves the maximum rated output |
| 747 | * power, in watts, that the unit is rated to supply." |
| 748 | * |
| 749 | * @return max_power_out value converted from string. |
| 750 | */ |
| 751 | auto getMaxPowerOut() const; |
| 752 | |
| 753 | /** |
| 754 | * @brief Reads a VPD value from PMBus, correct size, and contents. |
| 755 | * |
| 756 | * If the VPD data read is not the passed in size, resize and fill with |
| 757 | * spaces. If the data contains a non-alphanumeric value, replace any of |
| 758 | * those values with spaces. |
| 759 | * |
| 760 | * @param[in] vpdName - The name of the sysfs "file" to read data from. |
| 761 | * @param[in] type - The HWMON file type to read from. |
| 762 | * @param[in] vpdSize - The expacted size of the data for this VPD/property |
| 763 | * |
| 764 | * @return A string containing the VPD data read, resized if necessary |
| 765 | */ |
| 766 | auto readVPDValue(const std::string& vpdName, |
| 767 | const phosphor::pmbus::Type& type, |
| 768 | const std::size_t& vpdSize); |
| 769 | |
| 770 | /** |
| 771 | * @brief Reads the most recent input history record from the power supply |
| 772 | * and updates the average and maximum properties in D-Bus if there is a new |
| 773 | * reading available. |
| 774 | * |
| 775 | * This will still run every time analyze() is called so code can post new |
| 776 | * data as soon as possible and the timestamp will more accurately reflect |
| 777 | * the correct time. |
| 778 | * |
| 779 | * D-Bus is only updated if there is a change and the oldest record will be |
| 780 | * pruned if the property already contains the max number of records. |
| 781 | */ |
| 782 | void updateHistory(); |
| 783 | |
| 784 | /** |
| 785 | * @brief Retrieve PSU VPD keyword from D-Bus |
| 786 | * |
| 787 | * It retrieves PSU VPD keyword from D-Bus and assign the associated |
| 788 | * string to vpdStr. |
| 789 | * @param[in] keyword - The VPD search keyword |
| 790 | * @param[out] vpdStr - The VPD string associated with the keyword. |
| 791 | */ |
| 792 | void getPsuVpdFromDbus(const std::string& keyword, std::string& vpdStr); |
| 793 | |
| 794 | /** |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 795 | * @brief Creates the appropriate sensor D-Bus objects. |
| 796 | */ |
| 797 | void setupSensors(); |
| 798 | |
| 799 | /** |
| 800 | * @brief Monitors sensor values and updates D-Bus. |
| 801 | * Called from analyze(). |
| 802 | */ |
| 803 | void monitorSensors(); |
| 804 | |
| 805 | /** |
| 806 | * @brief Creates the peak input power sensor D-Bus object |
| 807 | * if the PS supports it. |
| 808 | */ |
| 809 | void setupInputPowerPeakSensor(); |
| 810 | |
| 811 | /** |
| 812 | * @brief Monitors the peak input power sensor |
| 813 | */ |
| 814 | void monitorPeakInputPowerSensor(); |
| 815 | |
| 816 | /** |
| 817 | * @brief Sets any sensor objects to Available = false on D-Bus. |
| 818 | */ |
| 819 | void setSensorsNotAvailable(); |
| 820 | |
| 821 | /** |
| 822 | * @brief Returns the associations to create for a sensor on this |
| 823 | * power supply. |
| 824 | */ |
| 825 | std::vector<AssociationTuple> getSensorAssociations(); |
| 826 | |
| 827 | /** |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 828 | * @brief systemd bus member |
| 829 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 830 | sdbusplus::bus_t& bus; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 831 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 832 | /** |
Matt Spinler | d676026 | 2023-08-30 10:13:05 -0500 | [diff] [blame] | 833 | * @brief D-Bus path to use for this power supply's inventory status. |
| 834 | **/ |
| 835 | std::string inventoryPath; |
| 836 | |
| 837 | /** |
| 838 | * @brief The file system path used for binding the device driver. |
| 839 | */ |
| 840 | const std::filesystem::path bindPath; |
| 841 | |
| 842 | /** |
| 843 | * @brief Get the power on status of the psu manager class. |
| 844 | * |
| 845 | * This is a callback method used to get the power on status of the psu |
| 846 | * manager class. |
| 847 | */ |
| 848 | std::function<bool()> isPowerOn; |
| 849 | |
| 850 | /** |
| 851 | * @brief Set to true if INPUT_HISTORY command supported. |
| 852 | * |
| 853 | * Not all power supplies will support the INPUT_HISTORY command. The IBM |
| 854 | * Common Form Factor power supplies do support this command. |
| 855 | */ |
| 856 | bool inputHistorySupported{false}; |
| 857 | |
| 858 | /** |
| 859 | * @brief Set to true when INPUT_HISTORY sync is required. |
| 860 | * |
| 861 | * A power supply will need to synchronize its INPUT_HISTORY data with the |
| 862 | * other power supplies installed in the system when it goes from missing to |
| 863 | * present. |
| 864 | */ |
| 865 | bool syncHistoryRequired{false}; |
| 866 | |
| 867 | /** |
| 868 | * @brief Store the short name to avoid string processing. |
| 869 | * |
| 870 | * The short name will be something like powersupply1, the last part of the |
| 871 | * inventoryPath. |
| 872 | */ |
| 873 | std::string shortName; |
| 874 | |
| 875 | /** |
| 876 | * @brief The libgpiod object for monitoring PSU presence |
| 877 | */ |
| 878 | std::unique_ptr<GPIOInterfaceBase> presenceGPIO = nullptr; |
| 879 | |
| 880 | /** |
| 881 | * @brief True if the power supply is present. |
| 882 | */ |
| 883 | bool present = false; |
| 884 | |
| 885 | /** |
| 886 | * @brief Power supply model name. |
| 887 | */ |
| 888 | std::string modelName; |
| 889 | |
| 890 | /** |
| 891 | * @brief D-Bus match variable used to subscribe to Present property |
| 892 | * changes. |
| 893 | **/ |
| 894 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 895 | |
| 896 | /** |
| 897 | * @brief D-Bus match variable used to subscribe for Present property |
| 898 | * interface added. |
| 899 | */ |
| 900 | std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch; |
| 901 | |
| 902 | /** |
| 903 | * @brief Pointer to the PMBus interface |
| 904 | * |
| 905 | * Used to read or write to/from PMBus power supply devices. |
| 906 | */ |
| 907 | std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf = nullptr; |
| 908 | |
| 909 | /** |
| 910 | * @brief Stored copy of the firmware version/revision string |
| 911 | */ |
| 912 | std::string fwVersion; |
| 913 | |
| 914 | /** |
| 915 | * @brief The string to pass in for binding the device driver. |
| 916 | */ |
| 917 | std::string bindDevice; |
| 918 | |
| 919 | /** |
| 920 | * @brief The result of the most recent availability check |
| 921 | * |
| 922 | * Saved on the object so changes can be detected. |
| 923 | */ |
| 924 | bool available = false; |
| 925 | |
| 926 | /** |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 927 | * @brief Will be updated to the latest/lastvalue read from STATUS_WORD. |
| 928 | */ |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 929 | uint64_t statusWord = 0; |
| 930 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 931 | /** |
| 932 | * @brief Will be set to the last read value of STATUS_WORD. |
| 933 | */ |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 934 | uint64_t statusWordOld = 0; |
| 935 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 936 | /** |
| 937 | * @brief Will be updated to the latest/lastvalue read from STATUS_INPUT. |
| 938 | */ |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 939 | uint64_t statusInput = 0; |
| 940 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 941 | /** |
| 942 | * @brief Will be updated to the latest/lastvalue read from STATUS_MFR. |
| 943 | */ |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 944 | uint64_t statusMFR = 0; |
| 945 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 946 | /** |
| 947 | * @brief Will be updated to the latest/last value read from STATUS_CML. |
| 948 | */ |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 949 | uint64_t statusCML = 0; |
| 950 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 951 | /** |
| 952 | * @brief Will be updated to the latest/last value read from STATUS_VOUT. |
| 953 | */ |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 954 | uint64_t statusVout = 0; |
| 955 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 956 | /** |
| 957 | * @brief Will be updated to the latest/last value read from STATUS_IOUT. |
| 958 | */ |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 959 | uint64_t statusIout = 0; |
| 960 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 961 | /** |
| 962 | * @brief Will be updated to the latest/last value read from |
| 963 | * STATUS_FANS_1_2. |
| 964 | */ |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 965 | uint64_t statusFans12 = 0; |
| 966 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 967 | /** |
| 968 | * @brief Will be updated to the latest/last value read from |
| 969 | * STATUS_TEMPERATURE. |
| 970 | */ |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 971 | uint64_t statusTemperature = 0; |
| 972 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 973 | /** |
| 974 | * @brief Will be updated with latest converted value read from READ_VIN |
| 975 | */ |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 976 | int inputVoltage = phosphor::pmbus::in_input::VIN_VOLTAGE_0; |
| 977 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 978 | /** |
| 979 | * @brief Will be updated with the actual voltage last read from READ_VIN |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 980 | */ |
| 981 | double actualInputVoltage = 0; |
| 982 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 983 | /** |
| 984 | * @brief True if an error for a fault has already been logged. |
| 985 | */ |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 986 | bool faultLogged = false; |
| 987 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 988 | /** |
| 989 | * @brief Incremented if bit 1 of STATUS_WORD low byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 990 | * |
| 991 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 992 | */ |
| 993 | size_t cmlFault = 0; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 994 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 995 | /** |
| 996 | * @brief Incremented if bit 5 of STATUS_WORD high byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 997 | * |
| 998 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 999 | */ |
| 1000 | size_t inputFault = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1001 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1002 | /** |
| 1003 | * @brief Incremented if bit 4 of STATUS_WORD high byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1004 | * |
| 1005 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1006 | */ |
| 1007 | size_t mfrFault = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1008 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1009 | /** |
| 1010 | * @brief Incremented if bit 3 of STATUS_WORD low byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1011 | * |
| 1012 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1013 | */ |
| 1014 | size_t vinUVFault = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1015 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1016 | /** |
| 1017 | * @brief Incremented if bit 5 of STATUS_WORD low byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1018 | * |
| 1019 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1020 | */ |
| 1021 | size_t voutOVFault = 0; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1022 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1023 | /** |
| 1024 | * @brief Incremented if bit 4 of STATUS_WORD low byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1025 | * |
| 1026 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1027 | */ |
| 1028 | size_t ioutOCFault = 0; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1029 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1030 | /** |
| 1031 | * @brief Incremented if bit 7 of STATUS_WORD high byte is on and bit 5 |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1032 | * (VOUT_OV) of low byte is off. |
| 1033 | * |
| 1034 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1035 | */ |
| 1036 | size_t voutUVFault = 0; |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1037 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1038 | /** |
| 1039 | * @brief Incremented if FANS fault/warn bit on in STATUS_WORD. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1040 | * |
| 1041 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1042 | */ |
| 1043 | size_t fanFault = 0; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1044 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1045 | /** |
| 1046 | * @brief Incremented if bit 2 of STATUS_WORD low byte is on. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1047 | * |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1048 | * Considered faulted if reaches DEGLITCH_LIMIT. |
| 1049 | */ |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1050 | size_t tempFault = 0; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1051 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1052 | /** |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1053 | * @brief Incremented if bit 11 or 6 of STATUS_WORD is on. PGOOD# is |
| 1054 | * inactive, or the unit is off. |
| 1055 | * |
| 1056 | * Considered faulted if reaches DEGLITCH_LIMIT. |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1057 | */ |
Brandon Wyman | 925c026 | 2021-12-21 20:15:36 +0000 | [diff] [blame] | 1058 | size_t pgoodFault = 0; |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1059 | |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1060 | /** |
| 1061 | * @brief Power Supply Kill fault. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1062 | * |
| 1063 | * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use |
| 1064 | * bit 4 to indicate this fault. Considered faulted if it reaches |
| 1065 | * DEGLITCH_LIMIT. |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1066 | */ |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1067 | size_t psKillFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1068 | |
| 1069 | /** |
| 1070 | * @brief Power Supply 12Vcs fault (standby power). |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1071 | * |
| 1072 | * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use |
| 1073 | * bit 6 to indicate this fault. Considered faulted if it reaches |
| 1074 | * DEGLITCH_LIMIT. |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1075 | */ |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1076 | size_t ps12VcsFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1077 | |
| 1078 | /** |
| 1079 | * @brief Power Supply Current-Share fault in 12V domain. |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1080 | * |
| 1081 | * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use |
| 1082 | * bit 7 to indicate this fault. Considered faulted if it reaches |
| 1083 | * DEGLITCH_LIMIT. |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1084 | */ |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 1085 | size_t psCS12VFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1086 | |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1087 | /** |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 1088 | * @brief Set to AC_FAULT_LIMIT when AC fault is detected, decremented when |
| 1089 | * AC fault has cleared. Effectively forms a timer since last AC failure. |
| 1090 | * Zero indicates being outside the window of concern. |
| 1091 | */ |
| 1092 | size_t acFault = 0; |
| 1093 | |
| 1094 | /** |
Jim Wright | 1530024 | 2022-11-17 16:37:04 -0600 | [diff] [blame] | 1095 | * @brief Count of the number of read failures. |
| 1096 | */ |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 1097 | size_t readFail = 0; |
| 1098 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 1099 | /** |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1100 | * @brief Class that manages the input power history records. |
| 1101 | **/ |
| 1102 | std::unique_ptr<history::RecordManager> recordManager; |
| 1103 | |
| 1104 | /** |
| 1105 | * @brief The D-Bus object for the average input power history |
| 1106 | **/ |
| 1107 | std::unique_ptr<history::Average> average; |
| 1108 | |
| 1109 | /** |
| 1110 | * @brief The D-Bus object for the maximum input power history |
| 1111 | **/ |
| 1112 | std::unique_ptr<history::Maximum> maximum; |
| 1113 | |
| 1114 | /** |
| 1115 | * @brief The base D-Bus object path to use for the average and maximum |
| 1116 | * objects. |
| 1117 | **/ |
| 1118 | std::string historyObjectPath; |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 1119 | |
| 1120 | /** |
| 1121 | * @brief The D-Bus object for the input voltage rating |
| 1122 | * |
| 1123 | * It is updated at startup and power on. If a power supply is |
| 1124 | * added or removed after that, it does not need to be updated |
| 1125 | * again (though that could be done as a future improvement). |
| 1126 | */ |
| 1127 | std::unique_ptr<SensorObject> inputVoltageRatingIface; |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 1128 | |
| 1129 | /** |
Matt Spinler | 592bd27 | 2023-08-30 11:00:01 -0500 | [diff] [blame^] | 1130 | * @brief The D-Bus object for the peak input power sensor. |
| 1131 | */ |
| 1132 | std::unique_ptr<PowerSensorObject> peakInputPowerSensor; |
| 1133 | |
| 1134 | /** |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 1135 | * @brief The device driver name |
| 1136 | */ |
| 1137 | std::string driverName; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 1138 | }; |
| 1139 | |
| 1140 | } // namespace phosphor::power::psu |