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