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