blob: 474ad8d725b5c961057f17fd5d5b6941f6499e68 [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 Wyman24e422f2017-07-25 19:40:14 -050017/**
18 * @class PowerSupply
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050019 * Represents a PMBus power supply device.
Brandon Wyman24e422f2017-07-25 19:40:14 -050020 */
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050021class PowerSupply : public Device
Brandon Wyman24e422f2017-07-25 19:40:14 -050022{
23 public:
24 PowerSupply() = delete;
25 PowerSupply(const PowerSupply&) = delete;
Brandon Wyman24e422f2017-07-25 19:40:14 -050026 PowerSupply(PowerSupply&&) = default;
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050027 PowerSupply& operator=(const PowerSupply&) = default;
Brandon Wyman24e422f2017-07-25 19:40:14 -050028 PowerSupply& operator=(PowerSupply&&) = default;
29 ~PowerSupply() = default;
30
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050031 /**
32 * Constructor
33 *
34 * @param[in] name - the device name
35 * @param[in] inst - the device instance
36 * @param[in] objpath - the path to monitor
37 * @param[in] invpath - the inventory path to use
Brandon Wyman442035f2017-08-08 15:58:45 -050038 * @param[in] bus - D-Bus bus object
Brandon Wyman431fbe42017-08-18 16:22:09 -050039 * @param[in] e - event object
40 * @param[in] t - time to allow power supply to assert PG#
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050041 */
42 PowerSupply(const std::string& name, size_t inst,
Brandon Wyman442035f2017-08-08 15:58:45 -050043 const std::string& objpath,
44 const std::string& invpath,
Brandon Wyman431fbe42017-08-18 16:22:09 -050045 sdbusplus::bus::bus& bus,
46 event::Event& e,
47 std::chrono::seconds& t);
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050048
49 /**
50 * Power supply specific function to analyze for faults/errors.
51 *
52 * Various PMBus status bits will be checked for fault conditions.
53 * If a certain fault bits are on, the appropriate error will be
54 * committed.
55 */
56 void analyze() override;
57
58 /**
59 * Write PMBus CLEAR_FAULTS
60 *
61 * This function will be called in various situations in order to clear
62 * any fault status bits that may have been set, in order to start over
63 * with a clean state. Presence changes and power state changes will
64 * want to clear any faults logged.
65 */
66 void clearFaults() override;
67
68 private:
69 /**
70 * The path to use for reading various PMBus bits/words.
71 */
72 std::string monitorPath;
73
74 /**
Brandon Wyman442035f2017-08-08 15:58:45 -050075 * @brief Pointer to the PMBus interface
76 *
77 * Used to read out of or write to the /sysfs tree(s) containing files
78 * that a device driver monitors the PMBus interface to the power
79 * supplies.
80 */
81 witherspoon::pmbus::PMBus pmbusIntf;
82
83 /**
Brandon Wyman431fbe42017-08-18 16:22:09 -050084 * @brief D-Bus path to use for this power supply's inventory status.
Brandon Wyman10295542017-08-09 18:20:44 -050085 */
Brandon Wyman431fbe42017-08-18 16:22:09 -050086 std::string inventoryPath;
87
88 /** @brief Connection for sdbusplus bus */
89 sdbusplus::bus::bus& bus;
90
91 /** @brief True if the power supply is present. */
Brandon Wyman10295542017-08-09 18:20:44 -050092 bool present = false;
93
Brandon Wyman875b3632017-09-13 18:46:03 -050094 /** @brief Used to subscribe to D-Bus property changes for Present */
Brandon Wyman10295542017-08-09 18:20:44 -050095 std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
96
Brandon Wyman431fbe42017-08-18 16:22:09 -050097 /** @brief True if the power is on. */
98 bool powerOn = false;
99
Brandon Wyman764c7972017-08-22 17:05:36 -0500100 /** @brief True if power on fault has been detected/reported. */
101 bool powerOnFault = false;
102
Brandon Wyman431fbe42017-08-18 16:22:09 -0500103 /** @brief The sd_event structure used by the power on timer. */
104 event::Event& event;
105
106 /**
107 * @brief Interval to setting powerOn to true.
108 *
109 * The amount of time to wait from power state on to setting the
110 * internal powerOn state to true. The amount of time the power supply
111 * is allowed to delay setting DGood/PG#.
112 */
113 std::chrono::seconds powerOnInterval;
114
115 /**
116 * @brief Timer used to delay setting the internal powerOn state.
117 *
118 * The timer used to do the callback after the power state has been on
119 * long enough.
120 */
121 Timer powerOnTimer;
122
Brandon Wyman875b3632017-09-13 18:46:03 -0500123 /** @brief Used to subscribe to D-Bus power on state changes */
Brandon Wyman431fbe42017-08-18 16:22:09 -0500124 std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
125
Brandon Wyman764c7972017-08-22 17:05:36 -0500126 /** @brief Has a PMBus read failure already been logged? */
Brandon Wyman442035f2017-08-08 15:58:45 -0500127 bool readFailLogged = false;
128
129 /**
130 * @brief Set to true when a VIN UV fault has been detected
131 *
132 * This is the VIN_UV_FAULT bit in the low byte from the STATUS_WORD
133 * command response.
134 */
135 bool vinUVFault = false;
136
137 /**
138 * @brief Set to true when an input fault or warning is detected
139 *
140 * This is the "INPUT FAULT OR WARNING" bit in the high byte from the
141 * STATUS_WORD command response.
142 */
143 bool inputFault = false;
Brandon Wyman10295542017-08-09 18:20:44 -0500144
Brandon Wyman764c7972017-08-22 17:05:36 -0500145 /**
Brandon Wymanb165c252017-08-25 18:59:54 -0500146 * @brief Set to true when an output over current fault is detected
147 *
148 * This is the "IOUT_OC_FAULT" bit in the low byte from the STATUS_WORD
149 * command response.
150 */
151 bool outputOCFault = false;
152
153 /**
Brandon Wymanab05c072017-08-30 18:26:41 -0500154 * @brief Set to true when the output overvoltage fault is detected
155 */
156 bool outputOVFault = false;
157
158 /**
Brandon Wyman12661f12017-08-31 15:28:21 -0500159 * @brief Set to true when a fan fault or warning condition is detected
160 */
161 bool fanFault = false;
162
163 /**
Brandon Wyman875b3632017-09-13 18:46:03 -0500164 * @brief Set to true during a temperature fault or warn condition.
165 */
166 bool temperatureFault = false;
167
168 /**
Brandon Wyman764c7972017-08-22 17:05:36 -0500169 * @brief Callback for inventory property changes
Brandon Wyman10295542017-08-09 18:20:44 -0500170 *
171 * Process change of Present property for power supply.
172 *
173 * @param[in] msg - Data associated with Present change signal
174 *
175 */
176 void inventoryChanged(sdbusplus::message::message& msg);
177
178 /**
179 * Updates the presence status by querying D-Bus
180 *
181 * The D-Bus inventory properties for this power supply will be read to
182 * determine if the power supply is present or not and update this
183 * objects present member variable to reflect current status.
184 */
185 void updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500186
187 /**
188 * @brief Updates the poweredOn status by querying D-Bus
189 *
Brandon Wyman875b3632017-09-13 18:46:03 -0500190 * The D-Bus property for the system power state will be read to
Brandon Wyman431fbe42017-08-18 16:22:09 -0500191 * determine if the system is powered on or not.
192 */
193 void updatePowerState();
194
Brandon Wyman764c7972017-08-22 17:05:36 -0500195 /**
196 * @brief Callback for power state property changes
197 *
Brandon Wyman431fbe42017-08-18 16:22:09 -0500198 * Process changes to the powered on stat property for the system.
199 *
200 * @param[in] msg - Data associated with the power state signal
201 */
202 void powerStateChanged(sdbusplus::message::message& msg);
203
Brandon Wyman603cc002017-08-28 18:17:58 -0500204 /**
Brandon Wymana1e96342017-09-25 16:47:44 -0500205 * @brief Wrapper for PMBus::read() and adding metadata
206 *
207 * @param[out] nv - NamesValues instance to store cmd string and value
208 * @param[in] cmd - String for the command to read data from.
209 * @param[in] type - The type of file to read the command from.
210 */
211 void captureCmd(util::NamesValues& nv, const std::string& cmd,
212 witherspoon::pmbus::Type type);
213
214 /**
Brandon Wyman603cc002017-08-28 18:17:58 -0500215 * @brief Checks for input voltage faults and logs error if needed.
216 *
217 * Check for voltage input under voltage fault (VIN_UV_FAULT) and/or
218 * input fault or warning (INPUT_FAULT), and logs appropriate error(s).
219 *
220 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
221 */
222 void checkInputFault(const uint16_t statusWord);
223
224 /**
225 * @brief Checks for power good negated or unit is off in wrong state
226 *
227 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
228 */
229 void checkPGOrUnitOffFault(const uint16_t statusWord);
230
231 /**
232 * @brief Checks for output current over current fault.
233 *
234 * IOUT_OC_FAULT is checked, if on, appropriate error is logged.
235 *
236 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
237 */
238 void checkCurrentOutOverCurrentFault(const uint16_t statusWord);
239
Brandon Wymanab05c072017-08-30 18:26:41 -0500240 /**
241 * @brief Checks for output overvoltage fault.
242 *
243 * VOUT_OV_FAULT is checked, if on, appropriate error is logged.
244 *
245 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
246 */
247 void checkOutputOvervoltageFault(const uint16_t statusWord);
248
Brandon Wyman12661f12017-08-31 15:28:21 -0500249 /**
250 * @brief Checks for a fan fault or warning condition.
251 *
252 * The high byte of STATUS_WORD is checked to see if the "FAN FAULT OR
253 * WARNING" bit is turned on. If it is on, log an error.
254 *
255 * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
256 */
257 void checkFanFault(const uint16_t statusWord);
258
Brandon Wyman875b3632017-09-13 18:46:03 -0500259 /**
260 * @brief Checks for a temperature fault or warning condition.
261 *
262 * The low byte of STATUS_WORD is checked to see if the "TEMPERATURE
263 * FAULT OR WARNING" bit is turned on. If it is on, log an error,
264 * call out the power supply indicating the fault/warning condition.
265 *
266 * @parma[in] statusWord - 2 byte STATUS_WORD value read from sysfs
267 */
268 void checkTemperatureFault(const uint16_t statusWord);
269
Brandon Wyman24e422f2017-07-25 19:40:14 -0500270};
271
272}
273}
274}