blob: 3da02b4f09cf68fca09130f0e02712e2d2ca372a [file] [log] [blame]
Brandon Wyman24e422f2017-07-25 19:40:14 -05001#pragma once
Brandon Wyman10295542017-08-09 18:20:44 -05002#include <sdbusplus/bus/match.hpp>
Brandon Wyman1db9a9e2017-07-26 18:50:22 -05003#include "device.hpp"
Brandon Wyman442035f2017-08-08 15:58:45 -05004#include "pmbus.hpp"
Brandon Wyman431fbe42017-08-18 16:22:09 -05005#include "timer.hpp"
Brandon Wymana1e96342017-09-25 16:47:44 -05006#include "names_values.hpp"
Brandon Wyman24e422f2017-07-25 19:40:14 -05007
Brandon Wyman1db9a9e2017-07-26 18:50:22 -05008namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -05009{
10namespace power
11{
12namespace psu
13{
14
Brandon Wyman10295542017-08-09 18:20:44 -050015namespace sdbusRule = sdbusplus::bus::match::rules;
16
Brandon Wyman593d24f2017-10-13 18:15:23 -050017constexpr auto FAULT_COUNT = 3;
18
Brandon Wyman24e422f2017-07-25 19:40:14 -050019/**
20 * @class PowerSupply
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050021 * Represents a PMBus power supply device.
Brandon Wyman24e422f2017-07-25 19:40:14 -050022 */
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050023class PowerSupply : public Device
Brandon Wyman24e422f2017-07-25 19:40:14 -050024{
25 public:
26 PowerSupply() = delete;
27 PowerSupply(const PowerSupply&) = delete;
Brandon Wyman24e422f2017-07-25 19:40:14 -050028 PowerSupply(PowerSupply&&) = default;
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050029 PowerSupply& operator=(const PowerSupply&) = default;
Brandon Wyman24e422f2017-07-25 19:40:14 -050030 PowerSupply& operator=(PowerSupply&&) = default;
31 ~PowerSupply() = default;
32
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050033 /**
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 Wyman442035f2017-08-08 15:58:45 -050040 * @param[in] bus - D-Bus bus object
Brandon Wyman431fbe42017-08-18 16:22:09 -050041 * @param[in] e - event object
42 * @param[in] t - time to allow power supply to assert PG#
Brandon Wyman590fc282017-11-01 18:22:25 -050043 * @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 Wyman1db9a9e2017-07-26 18:50:22 -050046 */
47 PowerSupply(const std::string& name, size_t inst,
Brandon Wyman442035f2017-08-08 15:58:45 -050048 const std::string& objpath,
49 const std::string& invpath,
Brandon Wyman431fbe42017-08-18 16:22:09 -050050 sdbusplus::bus::bus& bus,
51 event::Event& e,
Brandon Wyman590fc282017-11-01 18:22:25 -050052 std::chrono::seconds& t,
53 std::chrono::seconds& p);
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050054
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
74 private:
75 /**
76 * The path to use for reading various PMBus bits/words.
77 */
78 std::string monitorPath;
79
80 /**
Brandon Wyman442035f2017-08-08 15:58:45 -050081 * @brief Pointer to the PMBus interface
82 *
83 * Used to read out of or write to the /sysfs tree(s) containing files
84 * that a device driver monitors the PMBus interface to the power
85 * supplies.
86 */
87 witherspoon::pmbus::PMBus pmbusIntf;
88
89 /**
Brandon Wyman431fbe42017-08-18 16:22:09 -050090 * @brief D-Bus path to use for this power supply's inventory status.
Brandon Wyman10295542017-08-09 18:20:44 -050091 */
Brandon Wyman431fbe42017-08-18 16:22:09 -050092 std::string inventoryPath;
93
94 /** @brief Connection for sdbusplus bus */
95 sdbusplus::bus::bus& bus;
96
97 /** @brief True if the power supply is present. */
Brandon Wyman10295542017-08-09 18:20:44 -050098 bool present = false;
99
Brandon Wyman875b3632017-09-13 18:46:03 -0500100 /** @brief Used to subscribe to D-Bus property changes for Present */
Brandon Wyman10295542017-08-09 18:20:44 -0500101 std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
102
Brandon Wyman590fc282017-11-01 18:22:25 -0500103 /** @brief The sd_event structure used by the power on and present
104 * timers. */
105 event::Event& event;
106
107 /**
108 * @brief Interval for setting present to true.
109 *
110 * The amount of time to wait from not present to present change before
111 * updating the internal present indicator. Allows person servicing
112 * the power supply some time to plug in the cable.
113 */
114 std::chrono::seconds presentInterval;
115
116 /**
117 * @brief Timer used to delay setting the internal present state.
118 *
119 * The timer used to do the callback after the present property has
120 * changed.
121 */
122 Timer presentTimer;
123
Brandon Wyman431fbe42017-08-18 16:22:09 -0500124 /** @brief True if the power is on. */
125 bool powerOn = false;
126
Brandon Wyman593d24f2017-10-13 18:15:23 -0500127 /**
128 * @brief Equal to FAULT_COUNT if power on fault has been
129 * detected.
130 */
131 size_t powerOnFault = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500132
Brandon Wyman431fbe42017-08-18 16:22:09 -0500133 /**
134 * @brief Interval to setting powerOn to true.
135 *
136 * The amount of time to wait from power state on to setting the
137 * internal powerOn state to true. The amount of time the power supply
138 * is allowed to delay setting DGood/PG#.
139 */
140 std::chrono::seconds powerOnInterval;
141
142 /**
143 * @brief Timer used to delay setting the internal powerOn state.
144 *
145 * The timer used to do the callback after the power state has been on
146 * long enough.
147 */
148 Timer powerOnTimer;
149
Brandon Wyman875b3632017-09-13 18:46:03 -0500150 /** @brief Used to subscribe to D-Bus power on state changes */
Brandon Wyman431fbe42017-08-18 16:22:09 -0500151 std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
152
Brandon Wyman764c7972017-08-22 17:05:36 -0500153 /** @brief Has a PMBus read failure already been logged? */
Brandon Wyman442035f2017-08-08 15:58:45 -0500154 bool readFailLogged = false;
155
156 /**
Brandon Wyman442035f2017-08-08 15:58:45 -0500157 * @brief Set to true when an input fault or warning is detected
158 *
159 * This is the "INPUT FAULT OR WARNING" bit in the high byte from the
160 * STATUS_WORD command response.
161 */
162 bool inputFault = false;
Brandon Wyman10295542017-08-09 18:20:44 -0500163
Brandon Wyman764c7972017-08-22 17:05:36 -0500164 /**
Brandon Wymanb165c252017-08-25 18:59:54 -0500165 * @brief Set to true when an output over current fault is detected
166 *
167 * This is the "IOUT_OC_FAULT" bit in the low byte from the STATUS_WORD
168 * command response.
169 */
170 bool outputOCFault = false;
171
172 /**
Brandon Wymanab05c072017-08-30 18:26:41 -0500173 * @brief Set to true when the output overvoltage fault is detected
174 */
175 bool outputOVFault = false;
176
177 /**
Brandon Wyman12661f12017-08-31 15:28:21 -0500178 * @brief Set to true when a fan fault or warning condition is detected
179 */
180 bool fanFault = false;
181
182 /**
Brandon Wyman875b3632017-09-13 18:46:03 -0500183 * @brief Set to true during a temperature fault or warn condition.
184 */
185 bool temperatureFault = false;
186
187 /**
Brandon Wyman764c7972017-08-22 17:05:36 -0500188 * @brief Callback for inventory property changes
Brandon Wyman10295542017-08-09 18:20:44 -0500189 *
190 * Process change of Present property for power supply.
191 *
192 * @param[in] msg - Data associated with Present change signal
193 *
194 */
195 void inventoryChanged(sdbusplus::message::message& msg);
196
197 /**
198 * Updates the presence status by querying D-Bus
199 *
200 * The D-Bus inventory properties for this power supply will be read to
201 * determine if the power supply is present or not and update this
202 * objects present member variable to reflect current status.
203 */
204 void updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500205
206 /**
207 * @brief Updates the poweredOn status by querying D-Bus
208 *
Brandon Wyman875b3632017-09-13 18:46:03 -0500209 * The D-Bus property for the system power state will be read to
Brandon Wyman431fbe42017-08-18 16:22:09 -0500210 * determine if the system is powered on or not.
211 */
212 void updatePowerState();
213
Brandon Wyman764c7972017-08-22 17:05:36 -0500214 /**
215 * @brief Callback for power state property changes
216 *
Brandon Wyman431fbe42017-08-18 16:22:09 -0500217 * Process changes to the powered on stat property for the system.
218 *
219 * @param[in] msg - Data associated with the power state signal
220 */
221 void powerStateChanged(sdbusplus::message::message& msg);
222
Brandon Wyman603cc002017-08-28 18:17:58 -0500223 /**
Brandon Wymana1e96342017-09-25 16:47:44 -0500224 * @brief Wrapper for PMBus::read() and adding metadata
225 *
226 * @param[out] nv - NamesValues instance to store cmd string and value
227 * @param[in] cmd - String for the command to read data from.
228 * @param[in] type - The type of file to read the command from.
229 */
230 void captureCmd(util::NamesValues& nv, const std::string& cmd,
231 witherspoon::pmbus::Type type);
232
233 /**
Brandon Wyman603cc002017-08-28 18:17:58 -0500234 * @brief Checks for input voltage faults and logs error if needed.
235 *
236 * Check for voltage input under voltage fault (VIN_UV_FAULT) and/or
237 * input fault or warning (INPUT_FAULT), and logs appropriate error(s).
238 *
239 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
240 */
241 void checkInputFault(const uint16_t statusWord);
242
243 /**
244 * @brief Checks for power good negated or unit is off in wrong state
245 *
246 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
247 */
248 void checkPGOrUnitOffFault(const uint16_t statusWord);
249
250 /**
251 * @brief Checks for output current over current fault.
252 *
253 * IOUT_OC_FAULT is checked, if on, appropriate error is logged.
254 *
255 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
256 */
257 void checkCurrentOutOverCurrentFault(const uint16_t statusWord);
258
Brandon Wymanab05c072017-08-30 18:26:41 -0500259 /**
260 * @brief Checks for output overvoltage fault.
261 *
262 * VOUT_OV_FAULT is checked, if on, appropriate error is logged.
263 *
264 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
265 */
266 void checkOutputOvervoltageFault(const uint16_t statusWord);
267
Brandon Wyman12661f12017-08-31 15:28:21 -0500268 /**
269 * @brief Checks for a fan fault or warning condition.
270 *
271 * The high byte of STATUS_WORD is checked to see if the "FAN FAULT OR
272 * WARNING" bit is turned on. If it is on, log an error.
273 *
274 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
275 */
276 void checkFanFault(const uint16_t statusWord);
277
Brandon Wyman875b3632017-09-13 18:46:03 -0500278 /**
279 * @brief Checks for a temperature fault or warning condition.
280 *
281 * The low byte of STATUS_WORD is checked to see if the "TEMPERATURE
282 * FAULT OR WARNING" bit is turned on. If it is on, log an error,
283 * call out the power supply indicating the fault/warning condition.
284 *
285 * @parma[in] statusWord - 2 byte STATUS_WORD value read from sysfs
286 */
287 void checkTemperatureFault(const uint16_t statusWord);
288
Brandon Wyman24e422f2017-07-25 19:40:14 -0500289};
290
291}
292}
293}