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