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