Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 1 | #pragma once |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 2 | #include <sdbusplus/bus/match.hpp> |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 3 | #include "device.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 4 | #include "pmbus.hpp" |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 5 | #include "timer.hpp" |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 6 | #include "names_values.hpp" |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 7 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 8 | namespace witherspoon |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 9 | { |
| 10 | namespace power |
| 11 | { |
| 12 | namespace psu |
| 13 | { |
| 14 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 15 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 16 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 17 | constexpr auto FAULT_COUNT = 3; |
| 18 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 19 | /** |
| 20 | * @class PowerSupply |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 21 | * Represents a PMBus power supply device. |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 22 | */ |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 23 | class PowerSupply : public Device |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 24 | { |
| 25 | public: |
| 26 | PowerSupply() = delete; |
| 27 | PowerSupply(const PowerSupply&) = delete; |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 28 | PowerSupply(PowerSupply&&) = default; |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 29 | PowerSupply& operator=(const PowerSupply&) = default; |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 30 | PowerSupply& operator=(PowerSupply&&) = default; |
| 31 | ~PowerSupply() = default; |
| 32 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 33 | /** |
| 34 | * Constructor |
| 35 | * |
| 36 | * @param[in] name - the device name |
| 37 | * @param[in] inst - the device instance |
| 38 | * @param[in] objpath - the path to monitor |
| 39 | * @param[in] invpath - the inventory path to use |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 40 | * @param[in] bus - D-Bus bus object |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 41 | * @param[in] e - event object |
| 42 | * @param[in] t - time to allow power supply to assert PG# |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 43 | * @param[in] p - time to allow power supply presence state to |
| 44 | * settle/deglitch and allow for application of power |
| 45 | * prior to fault checking |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 46 | */ |
| 47 | PowerSupply(const std::string& name, size_t inst, |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 48 | const std::string& objpath, |
| 49 | const std::string& invpath, |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 50 | sdbusplus::bus::bus& bus, |
| 51 | event::Event& e, |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 52 | std::chrono::seconds& t, |
| 53 | std::chrono::seconds& p); |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Power supply specific function to analyze for faults/errors. |
| 57 | * |
| 58 | * Various PMBus status bits will be checked for fault conditions. |
| 59 | * If a certain fault bits are on, the appropriate error will be |
| 60 | * committed. |
| 61 | */ |
| 62 | void analyze() override; |
| 63 | |
| 64 | /** |
| 65 | * Write PMBus CLEAR_FAULTS |
| 66 | * |
| 67 | * This function will be called in various situations in order to clear |
| 68 | * any fault status bits that may have been set, in order to start over |
| 69 | * with a clean state. Presence changes and power state changes will |
| 70 | * want to clear any faults logged. |
| 71 | */ |
| 72 | void clearFaults() override; |
| 73 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 74 | /** |
| 75 | * Mark error for specified callout and message as resolved. |
| 76 | * |
| 77 | * @param[in] callout - The callout to be resolved (inventory path) |
| 78 | * @parma[in] message - The message for the fault to be resolved |
| 79 | */ |
| 80 | void resolveError(const std::string& callout, |
| 81 | const std::string& message); |
| 82 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 83 | private: |
| 84 | /** |
| 85 | * The path to use for reading various PMBus bits/words. |
| 86 | */ |
| 87 | std::string monitorPath; |
| 88 | |
| 89 | /** |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 90 | * @brief Pointer to the PMBus interface |
| 91 | * |
| 92 | * Used to read out of or write to the /sysfs tree(s) containing files |
| 93 | * that a device driver monitors the PMBus interface to the power |
| 94 | * supplies. |
| 95 | */ |
| 96 | witherspoon::pmbus::PMBus pmbusIntf; |
| 97 | |
| 98 | /** |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 99 | * @brief D-Bus path to use for this power supply's inventory status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 100 | */ |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 101 | std::string inventoryPath; |
| 102 | |
| 103 | /** @brief Connection for sdbusplus bus */ |
| 104 | sdbusplus::bus::bus& bus; |
| 105 | |
| 106 | /** @brief True if the power supply is present. */ |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 107 | bool present = false; |
| 108 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 109 | /** @brief Used to subscribe to D-Bus property changes for Present */ |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 110 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 111 | |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 112 | /** @brief The sd_event structure used by the power on and present |
| 113 | * timers. */ |
| 114 | event::Event& event; |
| 115 | |
| 116 | /** |
| 117 | * @brief Interval for setting present to true. |
| 118 | * |
| 119 | * The amount of time to wait from not present to present change before |
| 120 | * updating the internal present indicator. Allows person servicing |
| 121 | * the power supply some time to plug in the cable. |
| 122 | */ |
| 123 | std::chrono::seconds presentInterval; |
| 124 | |
| 125 | /** |
| 126 | * @brief Timer used to delay setting the internal present state. |
| 127 | * |
| 128 | * The timer used to do the callback after the present property has |
| 129 | * changed. |
| 130 | */ |
| 131 | Timer presentTimer; |
| 132 | |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 133 | /** @brief True if a fault has already been found and not cleared */ |
| 134 | bool faultFound = false; |
| 135 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 136 | /** @brief True if the power is on. */ |
| 137 | bool powerOn = false; |
| 138 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 139 | /** |
| 140 | * @brief Equal to FAULT_COUNT if power on fault has been |
| 141 | * detected. |
| 142 | */ |
| 143 | size_t powerOnFault = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 144 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 145 | /** |
| 146 | * @brief Interval to setting powerOn to true. |
| 147 | * |
| 148 | * The amount of time to wait from power state on to setting the |
| 149 | * internal powerOn state to true. The amount of time the power supply |
| 150 | * is allowed to delay setting DGood/PG#. |
| 151 | */ |
| 152 | std::chrono::seconds powerOnInterval; |
| 153 | |
| 154 | /** |
| 155 | * @brief Timer used to delay setting the internal powerOn state. |
| 156 | * |
| 157 | * The timer used to do the callback after the power state has been on |
| 158 | * long enough. |
| 159 | */ |
| 160 | Timer powerOnTimer; |
| 161 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 162 | /** @brief Used to subscribe to D-Bus power on state changes */ |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 163 | std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch; |
| 164 | |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 165 | /** @brief Indicates that a read failure has occurred. |
| 166 | * |
| 167 | * @details This will be incremented each time a read failure is |
| 168 | * encountered. If it is incremented to FAULT_COUNT, an error |
| 169 | * will be logged. |
| 170 | */ |
| 171 | size_t readFail = 0; |
| 172 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 173 | /** @brief Has a PMBus read failure already been logged? */ |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 174 | bool readFailLogged = false; |
| 175 | |
| 176 | /** |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 177 | * @brief Indicates an input fault or warning if equal to FAULT_COUNT. |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 178 | * |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 179 | * @details This is the "INPUT FAULT OR WARNING" bit in the high byte, |
| 180 | * or the VIN_UV_FAULT bit in the low byte in the STATUS_WORD |
| 181 | * command response. If either of those bits are on, this will |
| 182 | * be incremented. |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 183 | */ |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 184 | size_t inputFault = 0; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 185 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 186 | /** |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 187 | * @brief Indicates output over current fault if equal to FAULT_COUNT |
Brandon Wyman | b165c25 | 2017-08-25 18:59:54 -0500 | [diff] [blame] | 188 | * |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 189 | * @details This is incremented when the "IOUT_OC_FAULT" bit in the low |
| 190 | * byte from the STATUS_WORD command response is on. |
Brandon Wyman | b165c25 | 2017-08-25 18:59:54 -0500 | [diff] [blame] | 191 | */ |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 192 | size_t outputOCFault = 0; |
Brandon Wyman | b165c25 | 2017-08-25 18:59:54 -0500 | [diff] [blame] | 193 | |
| 194 | /** |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 195 | * @brief Indicates output overvoltage fault if equal to FAULT_COUNT. |
| 196 | * |
| 197 | * @details This is incremented when the "VOUT_OV_FAULT" bit in the |
| 198 | * STATUS_WORD command response is on. |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 199 | */ |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 200 | size_t outputOVFault = 0; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 201 | |
| 202 | /** |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 203 | * @brief Indicates a fan fault or warning condition was detected if |
| 204 | * equal to FAULT_COUNT. |
| 205 | * |
| 206 | * @details This is incremented when the 'FAN_FAULT' bit in the |
| 207 | * STATUS_WORD command response is on. |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 208 | */ |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 209 | size_t fanFault = 0; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 210 | |
| 211 | /** |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 212 | * @brief Indicates a temperature fault or warn condition was detected |
| 213 | * if equal to FAULT_COUNT. |
| 214 | * |
| 215 | * @details This is incremented when the 'TEMPERATURE_FAULT_WARN' bit |
| 216 | * in the STATUS_WORD command response is on, or if the |
| 217 | * 'OT_FAULT' bit in the STATUS_TEMPERATURE command response |
| 218 | * is on. |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 219 | */ |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 220 | size_t temperatureFault = 0; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 221 | |
| 222 | /** |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 223 | * @brief Callback for inventory property changes |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 224 | * |
| 225 | * Process change of Present property for power supply. |
| 226 | * |
| 227 | * @param[in] msg - Data associated with Present change signal |
| 228 | * |
| 229 | */ |
| 230 | void inventoryChanged(sdbusplus::message::message& msg); |
| 231 | |
| 232 | /** |
| 233 | * Updates the presence status by querying D-Bus |
| 234 | * |
| 235 | * The D-Bus inventory properties for this power supply will be read to |
| 236 | * determine if the power supply is present or not and update this |
| 237 | * objects present member variable to reflect current status. |
| 238 | */ |
| 239 | void updatePresence(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * @brief Updates the poweredOn status by querying D-Bus |
| 243 | * |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 244 | * The D-Bus property for the system power state will be read to |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 245 | * determine if the system is powered on or not. |
| 246 | */ |
| 247 | void updatePowerState(); |
| 248 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 249 | /** |
| 250 | * @brief Callback for power state property changes |
| 251 | * |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 252 | * Process changes to the powered on stat property for the system. |
| 253 | * |
| 254 | * @param[in] msg - Data associated with the power state signal |
| 255 | */ |
| 256 | void powerStateChanged(sdbusplus::message::message& msg); |
| 257 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 258 | /** |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 259 | * @brief Wrapper for PMBus::read() and adding metadata |
| 260 | * |
| 261 | * @param[out] nv - NamesValues instance to store cmd string and value |
| 262 | * @param[in] cmd - String for the command to read data from. |
| 263 | * @param[in] type - The type of file to read the command from. |
| 264 | */ |
| 265 | void captureCmd(util::NamesValues& nv, const std::string& cmd, |
| 266 | witherspoon::pmbus::Type type); |
| 267 | |
| 268 | /** |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 269 | * @brief Checks for input voltage faults and logs error if needed. |
| 270 | * |
| 271 | * Check for voltage input under voltage fault (VIN_UV_FAULT) and/or |
| 272 | * input fault or warning (INPUT_FAULT), and logs appropriate error(s). |
| 273 | * |
| 274 | * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 275 | */ |
| 276 | void checkInputFault(const uint16_t statusWord); |
| 277 | |
| 278 | /** |
| 279 | * @brief Checks for power good negated or unit is off in wrong state |
| 280 | * |
| 281 | * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 282 | */ |
| 283 | void checkPGOrUnitOffFault(const uint16_t statusWord); |
| 284 | |
| 285 | /** |
| 286 | * @brief Checks for output current over current fault. |
| 287 | * |
| 288 | * IOUT_OC_FAULT is checked, if on, appropriate error is logged. |
| 289 | * |
| 290 | * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 291 | */ |
| 292 | void checkCurrentOutOverCurrentFault(const uint16_t statusWord); |
| 293 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 294 | /** |
| 295 | * @brief Checks for output overvoltage fault. |
| 296 | * |
| 297 | * VOUT_OV_FAULT is checked, if on, appropriate error is logged. |
| 298 | * |
| 299 | * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 300 | */ |
| 301 | void checkOutputOvervoltageFault(const uint16_t statusWord); |
| 302 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 303 | /** |
| 304 | * @brief Checks for a fan fault or warning condition. |
| 305 | * |
| 306 | * The high byte of STATUS_WORD is checked to see if the "FAN FAULT OR |
| 307 | * WARNING" bit is turned on. If it is on, log an error. |
| 308 | * |
| 309 | * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 310 | */ |
| 311 | void checkFanFault(const uint16_t statusWord); |
| 312 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 313 | /** |
| 314 | * @brief Checks for a temperature fault or warning condition. |
| 315 | * |
| 316 | * The low byte of STATUS_WORD is checked to see if the "TEMPERATURE |
| 317 | * FAULT OR WARNING" bit is turned on. If it is on, log an error, |
| 318 | * call out the power supply indicating the fault/warning condition. |
| 319 | * |
| 320 | * @parma[in] statusWord - 2 byte STATUS_WORD value read from sysfs |
| 321 | */ |
| 322 | void checkTemperatureFault(const uint16_t statusWord); |
| 323 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | } |
| 327 | } |
| 328 | } |