blob: b81599baa6fbb450ae7bca5eeea1e0ed48b27263 [file] [log] [blame]
Brandon Wymana0f33ce2019-10-17 18:32:29 -05001#pragma once
2
Brandon Wymanc3324422022-03-24 20:30:57 +00003#include "average.hpp"
4#include "maximum.hpp"
Brandon Wyman8d195772020-01-27 15:03:51 -06005#include "pmbus.hpp"
Brandon Wymanc3324422022-03-24 20:30:57 +00006#include "record_manager.hpp"
Brandon Wymanaed1f752019-11-25 18:10:52 -06007#include "types.hpp"
B. J. Wyman681b2a32021-04-20 22:31:22 +00008#include "util.hpp"
Brandon Wyman3f1242f2020-01-28 13:11:25 -06009#include "utility.hpp"
Brandon Wymanaed1f752019-11-25 18:10:52 -060010
B. J. Wyman681b2a32021-04-20 22:31:22 +000011#include <gpiod.hpp>
Brandon Wymanaed1f752019-11-25 18:10:52 -060012#include <sdbusplus/bus/match.hpp>
13
B. J. Wyman681b2a32021-04-20 22:31:22 +000014#include <filesystem>
Brandon Wyman1d7a7df2020-03-26 10:14:05 -050015#include <stdexcept>
16
Brandon Wymana0f33ce2019-10-17 18:32:29 -050017namespace phosphor::power::psu
18{
Brandon Wyman3f1242f2020-01-28 13:11:25 -060019
Chanh Nguyenc12c53b2021-04-06 17:24:47 +070020#if IBM_VPD
Brandon Wyman1d7a7df2020-03-26 10:14:05 -050021// PMBus device driver "file name" to read for CCIN value.
22constexpr auto CCIN = "ccin";
23constexpr auto PART_NUMBER = "part_number";
24constexpr auto FRU_NUMBER = "fru";
25constexpr auto SERIAL_HEADER = "header";
26constexpr auto SERIAL_NUMBER = "serial_number";
27constexpr auto FW_VERSION = "fw_version";
28
29// The D-Bus property name to update with the CCIN value.
30constexpr auto MODEL_PROP = "Model";
31constexpr auto PN_PROP = "PartNumber";
Brandon Wymana169b0f2021-12-07 20:18:06 +000032constexpr auto SPARE_PN_PROP = "SparePartNumber";
Brandon Wyman1d7a7df2020-03-26 10:14:05 -050033constexpr auto SN_PROP = "SerialNumber";
34constexpr auto VERSION_PROP = "Version";
35
36// ipzVPD Keyword sizes
37static constexpr auto FL_KW_SIZE = 20;
38#endif
39
Brandon Wymanf65c4062020-08-19 13:15:53 -050040constexpr auto LOG_LIMIT = 3;
Brandon Wyman06ca4592021-12-06 22:52:23 +000041constexpr auto DEGLITCH_LIMIT = 3;
Brandon Wymanf65c4062020-08-19 13:15:53 -050042
Brandon Wymana0f33ce2019-10-17 18:32:29 -050043/**
44 * @class PowerSupply
45 * Represents a PMBus power supply device.
46 */
47class PowerSupply
48{
49 public:
Brandon Wymanaed1f752019-11-25 18:10:52 -060050 PowerSupply() = delete;
Brandon Wymana0f33ce2019-10-17 18:32:29 -050051 PowerSupply(const PowerSupply&) = delete;
52 PowerSupply(PowerSupply&&) = delete;
53 PowerSupply& operator=(const PowerSupply&) = delete;
54 PowerSupply& operator=(PowerSupply&&) = delete;
55 ~PowerSupply() = default;
56
57 /**
Brandon Wymanc63941c2020-01-27 16:49:33 -060058 * @param[in] invpath - String for inventory path to use
59 * @param[in] i2cbus - The bus number this power supply is on
60 * @param[in] i2caddr - The 16-bit I2C address of the power supply
Brandon Wymanc3324422022-03-24 20:30:57 +000061 * @param[in] driver - i2c driver name for power supply
B. J. Wyman681b2a32021-04-20 22:31:22 +000062 * @param[in] gpioLineName - The gpio-line-name to read for presence. See
63 * https://github.com/openbmc/docs/blob/master/designs/device-tree-gpio-naming.md
Brandon Wymanaed1f752019-11-25 18:10:52 -060064 */
Brandon Wymanc63941c2020-01-27 16:49:33 -060065 PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath,
B. J. Wyman681b2a32021-04-20 22:31:22 +000066 std::uint8_t i2cbus, const std::uint16_t i2caddr,
Brandon Wymanc3324422022-03-24 20:30:57 +000067 const std::string& driver, const std::string& gpioLineName);
Brandon Wymanaed1f752019-11-25 18:10:52 -060068
Brandon Wyman3f1242f2020-01-28 13:11:25 -060069 phosphor::pmbus::PMBusBase& getPMBus()
70 {
71 return *pmbusIntf;
72 }
73
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000074 GPIOInterfaceBase* getPresenceGPIO()
B. J. Wyman681b2a32021-04-20 22:31:22 +000075 {
76 return presenceGPIO.get();
77 }
78
B. J. Wymand8b8cb12021-07-15 22:03:34 +000079 std::string getPresenceGPIOName() const
80 {
81 if (presenceGPIO != nullptr)
82 {
83 return presenceGPIO->getName();
84 }
85 else
86 {
87 return std::string();
88 }
89 }
90
Brandon Wymanaed1f752019-11-25 18:10:52 -060091 /**
Brandon Wymana0f33ce2019-10-17 18:32:29 -050092 * Power supply specific function to analyze for faults/errors.
93 *
94 * Various PMBus status bits will be checked for fault conditions.
95 * If a certain fault bits are on, the appropriate error will be
96 * committed.
97 */
Brandon Wyman3f1242f2020-01-28 13:11:25 -060098 void analyze();
Brandon Wymana0f33ce2019-10-17 18:32:29 -050099
100 /**
Brandon Wyman59a35792020-06-04 12:37:40 -0500101 * Write PMBus ON_OFF_CONFIG
102 *
103 * This function will be called to cause the PMBus device driver to send the
104 * ON_OFF_CONFIG command. Takes one byte of data.
105 *
106 * @param[in] data - The ON_OFF_CONFIG data byte mask.
107 */
108 void onOffConfig(uint8_t data);
109
110 /**
Brandon Wymane3f7ad22021-12-21 20:27:45 +0000111 * Clears all the member variables that indicate if a fault bit was seen as
112 * on in the STATUS_WORD or STATUS_MFR_SPECIFIC response.
113 */
114 void clearFaultFlags()
115 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000116 inputFault = 0;
117 mfrFault = 0;
Brandon Wymane3f7ad22021-12-21 20:27:45 +0000118 statusMFR = 0;
Brandon Wymanc2906f42021-12-21 20:14:56 +0000119 vinUVFault = 0;
120 cmlFault = 0;
121 voutOVFault = 0;
122 ioutOCFault = 0;
123 voutUVFault = 0;
124 fanFault = 0;
125 tempFault = 0;
Brandon Wymane3f7ad22021-12-21 20:27:45 +0000126 pgoodFault = 0;
Brandon Wymanc2906f42021-12-21 20:14:56 +0000127 psKillFault = 0;
128 ps12VcsFault = 0;
129 psCS12VFault = 0;
Brandon Wymane3f7ad22021-12-21 20:27:45 +0000130 }
131
132 /**
Brandon Wyman3225a452022-03-18 18:51:49 +0000133 * @brief Function to specifically clear VIN_UV/OFF fault(s).
134 *
135 * The PMBus HWMON device driver has various alarm "files" to read out of
136 * sysfs. Reading those files will indicate if various alarms are active or
137 * not, and then specifically clear those faults that go with that alarm.
138 *
139 * The VIN_UV fault, indicated in STATUS_INPUT, goes with in1_lcrit_alarm.
140 * When a VIN_UV fault occurs, the "Unit Off For Insufficient Input Voltage"
141 * may also be active. Reading in1_lcrit_alarm should clear both fault bits,
142 * resulting in the corresponding fault bits in STATUS_WORD also clearing.
143 *
144 * See: https://www.kernel.org/doc/html/latest/hwmon/pmbus.html
145 */
146 void clearVinUVFault();
147
148 /**
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500149 * Write PMBus CLEAR_FAULTS
150 *
151 * This function will be called in various situations in order to clear
152 * any fault status bits that may have been set, in order to start over
153 * with a clean state. Presence changes and power state changes will
154 * want to clear any faults logged.
155 */
Brandon Wyman3c208462020-05-13 16:25:58 -0500156 void clearFaults();
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500157
158 /**
159 * @brief Adds properties to the inventory.
160 *
161 * Reads the values from the device and writes them to the
162 * associated power supply D-Bus inventory object.
163 *
164 * This needs to be done on startup, and each time the presence
165 * state changes.
166 *
167 * Properties added:
168 * - Serial Number
169 * - Part Number
170 * - CCIN (Customer Card Identification Number) - added as the Model
171 * - Firmware version
172 */
Brandon Wyman1d7a7df2020-03-26 10:14:05 -0500173 void updateInventory();
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500174
Brandon Wymanaed1f752019-11-25 18:10:52 -0600175 /**
176 * @brief Accessor function to indicate present status
177 */
178 bool isPresent() const
179 {
180 return present;
181 }
182
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600183 /**
Brandon Wymanfed0ba22020-09-26 20:02:51 -0500184 * @brief Returns the last read value from STATUS_WORD.
185 */
186 uint64_t getStatusWord() const
187 {
188 return statusWord;
189 }
190
191 /**
Brandon Wymanf07bc792021-10-12 19:00:35 +0000192 * @brief Returns the last read value from STATUS_INPUT.
193 */
194 uint64_t getStatusInput() const
195 {
196 return statusInput;
197 }
198
199 /**
Jay Meyer10d94052020-11-30 14:41:21 -0600200 * @brief Returns the last read value from STATUS_MFR.
201 */
202 uint64_t getMFRFault() const
203 {
204 return statusMFR;
205 }
206
207 /**
Brandon Wyman85c7bf42021-10-19 22:28:48 +0000208 * @brief Returns the last read value from STATUS_CML.
209 */
210 uint64_t getStatusCML() const
211 {
212 return statusCML;
213 }
214
215 /**
Brandon Wyman6710ba22021-10-27 17:39:31 +0000216 * @brief Returns the last read value from STATUS_VOUT.
217 */
218 uint64_t getStatusVout() const
219 {
220 return statusVout;
221 }
222
223 /**
Brandon Wymanb10b3be2021-11-09 22:12:15 +0000224 * @brief Returns the last value read from STATUS_IOUT.
225 */
226 uint64_t getStatusIout() const
227 {
228 return statusIout;
229 }
230
231 /**
Brandon Wyman7ee4d7e2021-11-19 20:48:23 +0000232 * @brief Returns the last value read from STATUS_FANS_1_2.
233 */
234 uint64_t getStatusFans12() const
235 {
236 return statusFans12;
237 }
238
239 /**
Brandon Wyman96893a42021-11-05 19:56:57 +0000240 * @brief Returns the last value read from STATUS_TEMPERATURE.
241 */
242 uint64_t getStatusTemperature() const
243 {
244 return statusTemperature;
245 }
246
247 /**
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600248 * @brief Returns true if a fault was found.
249 */
250 bool isFaulted() const
251 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000252 return (hasCommFault() || (vinUVFault >= DEGLITCH_LIMIT) ||
253 (inputFault >= DEGLITCH_LIMIT) ||
254 (voutOVFault >= DEGLITCH_LIMIT) ||
255 (ioutOCFault >= DEGLITCH_LIMIT) ||
256 (voutUVFault >= DEGLITCH_LIMIT) ||
257 (fanFault >= DEGLITCH_LIMIT) || (tempFault >= DEGLITCH_LIMIT) ||
258 (pgoodFault >= DEGLITCH_LIMIT) || (mfrFault >= DEGLITCH_LIMIT));
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600259 }
260
261 /**
Brandon Wymanb76ab242020-09-16 18:06:06 -0500262 * @brief Return whether a fault has been logged for this power supply
263 */
264 bool isFaultLogged() const
265 {
266 return faultLogged;
267 }
268
269 /**
270 * @brief Called when a fault for this power supply has been logged.
271 */
272 void setFaultLogged()
273 {
274 faultLogged = true;
275 }
276
277 /**
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600278 * @brief Returns true if INPUT fault occurred.
279 */
280 bool hasInputFault() const
281 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000282 return (inputFault >= DEGLITCH_LIMIT);
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600283 }
284
285 /**
286 * @brief Returns true if MFRSPECIFIC occurred.
287 */
288 bool hasMFRFault() const
289 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000290 return (mfrFault >= DEGLITCH_LIMIT);
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600291 }
292
293 /**
294 * @brief Returns true if VIN_UV_FAULT occurred.
295 */
296 bool hasVINUVFault() const
297 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000298 return (vinUVFault >= DEGLITCH_LIMIT);
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600299 }
300
Brandon Wymanc9efe412020-10-09 15:42:50 -0500301 /**
Brandon Wyman6710ba22021-10-27 17:39:31 +0000302 * @brief Returns true if VOUT_OV_FAULT occurred.
303 */
304 bool hasVoutOVFault() const
305 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000306 return (voutOVFault >= DEGLITCH_LIMIT);
Brandon Wyman6710ba22021-10-27 17:39:31 +0000307 }
308
309 /**
Brandon Wymanb10b3be2021-11-09 22:12:15 +0000310 * @brief Returns true if IOUT_OC fault occurred (bit 4 STATUS_BYTE).
311 */
312 bool hasIoutOCFault() const
313 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000314 return (ioutOCFault >= DEGLITCH_LIMIT);
Brandon Wymanb10b3be2021-11-09 22:12:15 +0000315 }
316
317 /**
Brandon Wyman2cf46942021-10-28 19:09:16 +0000318 * @brief Returns true if VOUT_UV_FAULT occurred.
319 */
320 bool hasVoutUVFault() const
321 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000322 return (voutUVFault >= DEGLITCH_LIMIT);
Brandon Wyman2cf46942021-10-28 19:09:16 +0000323 }
324
325 /**
Brandon Wyman7ee4d7e2021-11-19 20:48:23 +0000326 *@brief Returns true if fan fault occurred.
327 */
328 bool hasFanFault() const
329 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000330 return (fanFault >= DEGLITCH_LIMIT);
Brandon Wyman7ee4d7e2021-11-19 20:48:23 +0000331 }
332
333 /**
Brandon Wyman96893a42021-11-05 19:56:57 +0000334 * @brief Returns true if TEMPERATURE fault occurred.
335 */
336 bool hasTempFault() const
337 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000338 return (tempFault >= DEGLITCH_LIMIT);
Brandon Wyman96893a42021-11-05 19:56:57 +0000339 }
340
341 /**
Brandon Wyman2916ea52021-11-06 03:31:18 +0000342 * @brief Returns true if there is a PGood fault (PGOOD# inactive, or OFF
343 * bit on).
344 */
345 bool hasPgoodFault() const
346 {
Brandon Wyman06ca4592021-12-06 22:52:23 +0000347 return (pgoodFault >= DEGLITCH_LIMIT);
Brandon Wyman2916ea52021-11-06 03:31:18 +0000348 }
349
350 /**
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000351 * @brief Return true if there is a PS_Kill fault.
352 */
353 bool hasPSKillFault() const
354 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000355 return (psKillFault >= DEGLITCH_LIMIT);
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000356 }
357
358 /**
359 * @brief Returns true if there is a 12Vcs (standy power) fault.
360 */
361 bool hasPS12VcsFault() const
362 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000363 return (ps12VcsFault >= DEGLITCH_LIMIT);
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000364 }
365
366 /**
367 * @brief Returns true if there is a 12V current-share fault.
368 */
369 bool hasPSCS12VFault() const
370 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000371 return (psCS12VFault >= DEGLITCH_LIMIT);
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000372 }
373
374 /**
Brandon Wymanc9efe412020-10-09 15:42:50 -0500375 * @brief Returns the device path
376 *
377 * This can be used for error call outs.
378 * Example: /sys/bus/i2c/devices/3-0068
379 */
Brandon Wyman4176d6b2020-10-07 17:41:06 -0500380 const std::string getDevicePath() const
381 {
382 return pmbusIntf->path();
383 }
384
Brandon Wymanc9efe412020-10-09 15:42:50 -0500385 /**
Brandon Wyman321a6152022-03-19 00:11:44 +0000386 * @brief Returns this power supply's inventory path.
Brandon Wymanc9efe412020-10-09 15:42:50 -0500387 *
388 * This can be used for error call outs.
389 * Example:
390 * /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1
391 */
Brandon Wyman7e495272020-09-26 19:57:46 -0500392 const std::string& getInventoryPath() const
393 {
394 return inventoryPath;
395 }
396
Brandon Wymanc9efe412020-10-09 15:42:50 -0500397 /**
Brandon Wyman321a6152022-03-19 00:11:44 +0000398 * @brief Returns the short name (last part of inventoryPath).
399 */
400 const std::string& getShortName() const
401 {
402 return shortName;
403 }
404
405 /**
Brandon Wymanc9efe412020-10-09 15:42:50 -0500406 * @brief Returns the firmware revision version read from the power supply
407 */
408 const std::string& getFWVersion() const
409 {
410 return fwVersion;
411 }
412
Adriana Kobylak572a9052021-03-30 15:58:07 +0000413 /**
414 * @brief Returns the model name of the power supply
415 */
416 const std::string& getModelName() const
417 {
418 return modelName;
419 }
420
Brandon Wymanf65c4062020-08-19 13:15:53 -0500421 /** @brief Returns true if the number of failed reads exceeds limit
422 * TODO: or CML bit on.
423 */
424 bool hasCommFault() const
425 {
Brandon Wymanc2906f42021-12-21 20:14:56 +0000426 return ((readFail >= LOG_LIMIT) || (cmlFault >= DEGLITCH_LIMIT));
Brandon Wymanf65c4062020-08-19 13:15:53 -0500427 }
428
Adriana Kobylak4175ffb2021-08-02 14:51:05 +0000429 /**
430 * @brief Reads the pmbus input voltage and returns that actual voltage
431 * reading and the calculated input voltage based on thresholds.
432 * @param[out] actualInputVoltage - The actual voltage reading, in Volts.
433 * @param[out] inputVoltage - A rounded up/down value of the actual input
434 * voltage based on thresholds, in Volts.
435 */
436 void getInputVoltage(double& actualInputVoltage, int& inputVoltage) const;
437
Matt Spinler0975eaf2022-02-14 15:38:30 -0600438 /**
439 * @brief Check if the PS is considered to be available or not
440 *
441 * It is unavailable if any of:
442 * - not present
443 * - input fault active
444 * - Vin UV fault active
445 * - PS KILL fault active
446 * - Iout OC fault active
447 *
448 * Other faults will, through creating error logs with callouts, already
449 * be setting the Functional property to false.
450 *
451 * On changes, the Available property is updated in the inventory.
452 */
453 void checkAvailability();
454
Brandon Wymanc3324422022-03-24 20:30:57 +0000455 /**
456 * @brief Setup for power supply input history.
457 *
458 * This will setup the variables and interfaces needed to get the power
459 * supply input history data over to D-Bus. The only known support for this
460 * at this time is the INPUT_HISTORY command implemented by the IBM Common
461 * Form Factor Power Suppplies (ibm-cffps). The INPUT_HISTORY command for
462 * ibm-cffps is implemented via a manufacturing specific PMBus command.
463 */
464 void setupInputHistory();
465
466 /**
467 * @brief Returns true if this power supply has input history (supported).
468 */
469 bool hasInputHistory() const
470 {
471 return inputHistorySupported;
472 }
473
474 /**
475 * @brief Returns the number of input history records
476 *
477 * PowerSupply wrapper to getNumRecords() from RecordManager.
478 */
479 size_t getNumInputHistoryRecords() const
480 {
481 if (recordManager)
482 {
483 return recordManager->getNumRecords();
484 }
485 else
486 {
487 return 0;
488 }
489 }
490
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500491 private:
Brandon Wymanaed1f752019-11-25 18:10:52 -0600492 /** @brief systemd bus member */
493 sdbusplus::bus::bus& bus;
494
Brandon Wyman9564e942020-11-10 14:01:42 -0600495 /** @brief Will be updated to the latest/lastvalue read from STATUS_WORD.*/
Brandon Wymanfed0ba22020-09-26 20:02:51 -0500496 uint64_t statusWord = 0;
497
Brandon Wyman9e292ee2022-03-10 22:56:23 +0000498 /** @brief Will be set to the last read value of STATUS_WORD. */
499 uint64_t statusWordOld = 0;
500
Brandon Wymanf07bc792021-10-12 19:00:35 +0000501 /** @brief Will be updated to the latest/lastvalue read from STATUS_INPUT.*/
502 uint64_t statusInput = 0;
503
Jay Meyer10d94052020-11-30 14:41:21 -0600504 /** @brief Will be updated to the latest/lastvalue read from STATUS_MFR.*/
505 uint64_t statusMFR = 0;
506
Brandon Wyman85c7bf42021-10-19 22:28:48 +0000507 /** @brief Will be updated to the latest/last value read from STATUS_CML.*/
508 uint64_t statusCML = 0;
509
Brandon Wyman6710ba22021-10-27 17:39:31 +0000510 /** @brief Will be updated to the latest/last value read from STATUS_VOUT.*/
511 uint64_t statusVout = 0;
512
Brandon Wymanb10b3be2021-11-09 22:12:15 +0000513 /** @brief Will be updated to the latest/last value read from STATUS_IOUT.*/
514 uint64_t statusIout = 0;
515
Brandon Wyman96893a42021-11-05 19:56:57 +0000516 /** @brief Will be updated to the latest/last value read from
Brandon Wyman7ee4d7e2021-11-19 20:48:23 +0000517 * STATUS_FANS_1_2. */
518 uint64_t statusFans12 = 0;
519
520 /** @brief Will be updated to the latest/last value read from
Brandon Wyman96893a42021-11-05 19:56:57 +0000521 * STATUS_TEMPERATURE.*/
522 uint64_t statusTemperature = 0;
523
Brandon Wyman82affd92021-11-24 19:12:49 +0000524 /** @brief Will be updated with latest converted value read from READ_VIN */
525 int inputVoltage = phosphor::pmbus::in_input::VIN_VOLTAGE_0;
526
Brandon Wyman4fc191f2022-03-10 23:07:13 +0000527 /** @brief Will be updated with the actual voltage last read from READ_VIN
528 */
529 double actualInputVoltage = 0;
530
Brandon Wymanb76ab242020-09-16 18:06:06 -0500531 /** @brief True if an error for a fault has already been logged. */
532 bool faultLogged = false;
533
Brandon Wymanc2906f42021-12-21 20:14:56 +0000534 /** @brief Incremented if bit 1 of STATUS_WORD low byte is on.
535 *
536 * Considered faulted if reaches DEGLITCH_LIMIT.
537 */
538 size_t cmlFault = 0;
Brandon Wyman85c7bf42021-10-19 22:28:48 +0000539
Brandon Wymanc2906f42021-12-21 20:14:56 +0000540 /** @brief Incremented if bit 5 of STATUS_WORD high byte is on.
541 *
542 * Considered faulted if reaches DEGLITCH_LIMIT.
543 */
544 size_t inputFault = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600545
Brandon Wymanc2906f42021-12-21 20:14:56 +0000546 /** @brief Incremented if bit 4 of STATUS_WORD high byte is on.
547 *
548 * Considered faulted if reaches DEGLITCH_LIMIT.
549 */
550 size_t mfrFault = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600551
Brandon Wymanc2906f42021-12-21 20:14:56 +0000552 /** @brief Incremented if bit 3 of STATUS_WORD low byte is on.
553 *
554 * Considered faulted if reaches DEGLITCH_LIMIT.
555 */
556 size_t vinUVFault = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -0600557
Brandon Wymanc2906f42021-12-21 20:14:56 +0000558 /** @brief Incremented if bit 5 of STATUS_WORD low byte is on.
559 *
560 * Considered faulted if reaches DEGLITCH_LIMIT.
561 */
562 size_t voutOVFault = 0;
Brandon Wyman6710ba22021-10-27 17:39:31 +0000563
Brandon Wymanc2906f42021-12-21 20:14:56 +0000564 /** @brief Incremented if bit 4 of STATUS_WORD low byte is on.
565 *
566 * Considered faulted if reaches DEGLITCH_LIMIT.
567 */
568 size_t ioutOCFault = 0;
Brandon Wymanb10b3be2021-11-09 22:12:15 +0000569
Brandon Wymanc2906f42021-12-21 20:14:56 +0000570 /** @brief Incremented if bit 7 of STATUS_WORD high byte is on and bit 5
571 * (VOUT_OV) of low byte is off.
572 *
573 * Considered faulted if reaches DEGLITCH_LIMIT.
574 */
575 size_t voutUVFault = 0;
Brandon Wyman2cf46942021-10-28 19:09:16 +0000576
Brandon Wymanc2906f42021-12-21 20:14:56 +0000577 /** @brief Incremented if FANS fault/warn bit on in STATUS_WORD.
578 *
579 * Considered faulted if reaches DEGLITCH_LIMIT.
580 */
581 size_t fanFault = 0;
Brandon Wyman7ee4d7e2021-11-19 20:48:23 +0000582
Brandon Wymanc2906f42021-12-21 20:14:56 +0000583 /** @brief Incremented if bit 2 of STATUS_WORD low byte is on.
584 *
585 * Considered faulted if reaches DEGLITCH_LIMIT. */
586 size_t tempFault = 0;
Brandon Wyman96893a42021-11-05 19:56:57 +0000587
Brandon Wyman2cf46942021-10-28 19:09:16 +0000588 /**
Brandon Wyman06ca4592021-12-06 22:52:23 +0000589 * @brief Incremented if bit 11 or 6 of STATUS_WORD is on. PGOOD# is
590 * inactive, or the unit is off.
591 *
592 * Considered faulted if reaches DEGLITCH_LIMIT.
Brandon Wyman2916ea52021-11-06 03:31:18 +0000593 */
Brandon Wyman925c0262021-12-21 20:15:36 +0000594 size_t pgoodFault = 0;
Brandon Wyman2916ea52021-11-06 03:31:18 +0000595
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000596 /**
597 * @brief Power Supply Kill fault.
Brandon Wymanc2906f42021-12-21 20:14:56 +0000598 *
599 * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
600 * bit 4 to indicate this fault. Considered faulted if it reaches
601 * DEGLITCH_LIMIT.
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000602 */
Brandon Wymanc2906f42021-12-21 20:14:56 +0000603 size_t psKillFault = 0;
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000604
605 /**
606 * @brief Power Supply 12Vcs fault (standby power).
Brandon Wymanc2906f42021-12-21 20:14:56 +0000607 *
608 * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
609 * bit 6 to indicate this fault. Considered faulted if it reaches
610 * DEGLITCH_LIMIT.
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000611 */
Brandon Wymanc2906f42021-12-21 20:14:56 +0000612 size_t ps12VcsFault = 0;
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000613
614 /**
615 * @brief Power Supply Current-Share fault in 12V domain.
Brandon Wymanc2906f42021-12-21 20:14:56 +0000616 *
617 * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
618 * bit 7 to indicate this fault. Considered faulted if it reaches
619 * DEGLITCH_LIMIT.
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000620 */
Brandon Wymanc2906f42021-12-21 20:14:56 +0000621 size_t psCS12VFault = 0;
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000622
Brandon Wymanf65c4062020-08-19 13:15:53 -0500623 /** @brief Count of the number of read failures. */
624 size_t readFail = 0;
625
Brandon Wymanaed1f752019-11-25 18:10:52 -0600626 /**
Brandon Wymanc2203432021-12-21 23:09:48 +0000627 * @brief Examine STATUS_WORD for CML (communication, memory, logic fault).
628 */
629 void analyzeCMLFault();
630
631 /**
Brandon Wymane3b0bb02021-12-21 23:16:48 +0000632 * @brief Examine STATUS_WORD for INPUT bit on.
633 *
634 * "An input voltage, input current, or input power fault or warning has
635 * occurred."
636 */
637 void analyzeInputFault();
638
639 /**
Brandon Wymanc2c87132021-12-21 23:22:18 +0000640 * @brief Examine STATUS_WORD for VOUT being set.
641 *
642 * If VOUT is on, "An output voltage fault or warning has occurred.", and
643 * VOUT_OV_FAULT is on, there is an output over-voltage fault.
644 */
645 void analyzeVoutOVFault();
646
Brandon Wymana00e7302021-12-21 23:28:29 +0000647 /*
648 * @brief Examine STATUS_WORD value read for IOUT_OC_FAULT.
649 *
650 * "An output overcurrent fault has occurred." If it is on, and fault not
651 * set, trace STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_IOUT values.
652 */
653 void analyzeIoutOCFault();
654
Brandon Wymanc2c87132021-12-21 23:22:18 +0000655 /**
Brandon Wyman08378782021-12-21 23:48:15 +0000656 * @brief Examines STATUS_WORD value read to see if there is a UV fault.
657 *
658 * Checks if the VOUT bit is on, indicating "An output voltage fault or
659 * warning has occurred", if it is on, but VOUT_OV_FAULT is off, it is
660 * determined to be an indication of an output under-voltage fault.
661 */
662 void analyzeVoutUVFault();
663
664 /**
Brandon Wymand5d9a222021-12-21 23:59:05 +0000665 * @brief Examine STATUS_WORD for the fan fault/warning bit.
666 *
667 * If fanFault is not on, trace that the bit now came on, include
668 * STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_FANS_1_2 values as well, to
669 * help with understanding what may have caused it to be set.
670 */
671 void analyzeFanFault();
672
673 /**
Brandon Wyman52cb3f22021-12-21 23:02:47 +0000674 * @brief Examine STATUS_WORD for temperature fault.
675 */
676 void analyzeTemperatureFault();
677
678 /**
Brandon Wyman993b5542021-12-21 22:55:16 +0000679 * @brief Examine STATUS_WORD for pgood or unit off faults.
680 */
681 void analyzePgoodFault();
682
683 /**
Brandon Wyman39ea02b2021-11-23 23:22:23 +0000684 * @brief Determine possible manufacturer-specific faults from bits in
685 * STATUS_MFR.
686 *
687 * The bits in the STATUS_MFR_SPECIFIC command response have "Manufacturer
688 * Defined" meanings. Determine which faults, if any, are present based on
689 * the power supply (device driver) type.
690 */
691 void determineMFRFault();
692
693 /**
Brandon Wyman6c2ac392021-12-21 22:23:06 +0000694 * @brief Examine STATUS_WORD value read for MFRSPECIFIC bit on.
695 *
696 * "A manufacturer specific fault or warning has occurred."
697 *
698 * If it is on, call the determineMFRFault() helper function to examine the
699 * value read from STATUS_MFR_SPECIFIC.
700 */
701 void analyzeMFRFault();
702
703 /**
Brandon Wymanf087f472021-12-22 00:04:27 +0000704 * @brief Analyzes the STATUS_WORD for a VIN_UV_FAULT indicator.
705 */
706 void analyzeVinUVFault();
707
708 /**
Brandon Wymanaed1f752019-11-25 18:10:52 -0600709 * @brief D-Bus path to use for this power supply's inventory status.
710 **/
711 std::string inventoryPath;
712
B. J. Wyman681b2a32021-04-20 22:31:22 +0000713 /**
Brandon Wyman321a6152022-03-19 00:11:44 +0000714 * @brief Store the short name to avoid string processing.
715 *
716 * The short name will be something like powersupply1, the last part of the
717 * inventoryPath.
718 */
719 std::string shortName;
720
721 /**
722 * @brief Given a full inventory path, returns the last node of the path as
723 * the "short name"
724 */
725 std::string findShortName(const std::string& invPath)
726 {
727 auto const lastSlashPos = invPath.find_last_of('/');
728
729 if ((lastSlashPos == std::string::npos) ||
730 ((lastSlashPos + 1) == invPath.size()))
731 {
732 return invPath;
733 }
734 else
735 {
736 return invPath.substr(lastSlashPos + 1);
737 }
738 }
739
740 /**
B. J. Wyman681b2a32021-04-20 22:31:22 +0000741 * @brief The libgpiod object for monitoring PSU presence
742 */
Adriana Kobylak3ca062a2021-10-20 15:27:23 +0000743 std::unique_ptr<GPIOInterfaceBase> presenceGPIO = nullptr;
B. J. Wyman681b2a32021-04-20 22:31:22 +0000744
Brandon Wymanaed1f752019-11-25 18:10:52 -0600745 /** @brief True if the power supply is present. */
746 bool present = false;
747
Adriana Kobylak572a9052021-03-30 15:58:07 +0000748 /** @brief Power supply model name. */
749 std::string modelName;
750
Brandon Wymanaed1f752019-11-25 18:10:52 -0600751 /** @brief D-Bus match variable used to subscribe to Present property
752 * changes.
753 **/
754 std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
755
756 /** @brief D-Bus match variable used to subscribe for Present property
757 * interface added.
758 */
759 std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch;
760
761 /**
Brandon Wyman8d195772020-01-27 15:03:51 -0600762 * @brief Pointer to the PMBus interface
763 *
764 * Used to read or write to/from PMBus power supply devices.
765 */
Brandon Wyman9564e942020-11-10 14:01:42 -0600766 std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf = nullptr;
Brandon Wyman8d195772020-01-27 15:03:51 -0600767
Brandon Wymanc9efe412020-10-09 15:42:50 -0500768 /** @brief Stored copy of the firmware version/revision string */
769 std::string fwVersion;
770
Brandon Wyman8d195772020-01-27 15:03:51 -0600771 /**
B. J. Wyman681b2a32021-04-20 22:31:22 +0000772 * @brief The file system path used for binding the device driver.
773 */
774 const std::filesystem::path bindPath;
775
776 /* @brief The string to pass in for binding the device driver. */
777 std::string bindDevice;
778
779 /**
Matt Spinler0975eaf2022-02-14 15:38:30 -0600780 * @brief The result of the most recent availability check
781 *
782 * Saved on the object so changes can be detected.
783 */
784 bool available = false;
785
786 /**
B. J. Wyman681b2a32021-04-20 22:31:22 +0000787 * @brief Binds or unbinds the power supply device driver
788 *
789 * Called when a presence change is detected to either bind the device
790 * driver for the power supply when it is installed, or unbind the device
791 * driver when the power supply is removed.
792 *
793 * Writes <device> to <path>/bind (or unbind)
794 *
795 * @param present - when true, will bind the device driver
796 * when false, will unbind the device driver
797 */
798 void bindOrUnbindDriver(bool present);
799
800 /**
Brandon Wymanaed1f752019-11-25 18:10:52 -0600801 * @brief Updates the presence status by querying D-Bus
802 *
803 * The D-Bus inventory properties for this power supply will be read to
804 * determine if the power supply is present or not and update this
805 * object's present member variable to reflect current status.
806 **/
807 void updatePresence();
808
809 /**
B. J. Wyman681b2a32021-04-20 22:31:22 +0000810 * @brief Updates the power supply presence by reading the GPIO line.
811 */
812 void updatePresenceGPIO();
813
814 /**
Brandon Wymanaed1f752019-11-25 18:10:52 -0600815 * @brief Callback for inventory property changes
816 *
817 * Process change of Present property for power supply.
818 *
B. J. Wyman681b2a32021-04-20 22:31:22 +0000819 * This is used if we are watching the D-Bus properties instead of reading
820 * the GPIO presence line ourselves.
821 *
Brandon Wymanaed1f752019-11-25 18:10:52 -0600822 * @param[in] msg - Data associated with Present change signal
823 **/
824 void inventoryChanged(sdbusplus::message::message& msg);
Brandon Wyman9a507db2021-02-25 16:15:22 -0600825
826 /**
827 * @brief Callback for inventory property added.
828 *
829 * Process add of the interface with the Present property for power supply.
830 *
B. J. Wyman681b2a32021-04-20 22:31:22 +0000831 * This is used if we are watching the D-Bus properties instead of reading
832 * the GPIO presence line ourselves.
833 *
Brandon Wyman9a507db2021-02-25 16:15:22 -0600834 * @param[in] msg - Data associated with Present add signal
835 **/
836 void inventoryAdded(sdbusplus::message::message& msg);
Brandon Wymanc3324422022-03-24 20:30:57 +0000837
838 /**
839 * @brief Reads the most recent input history record from the power supply
840 * and updates the average and maximum properties in D-Bus if there is a new
841 * reading available.
842 *
843 * This will still run every time analyze() is called so code can post new
844 * data as soon as possible and the timestamp will more accurately reflect
845 * the correct time.
846 *
847 * D-Bus is only updated if there is a change and the oldest record will be
848 * pruned if the property already contains the max number of records.
849 */
850 void updateHistory();
851
852 /**
853 * @brief Set to true if INPUT_HISTORY command supported.
854 *
855 * Not all power supplies will support the INPUT_HISTORY command. The IBM
856 * Common Form Factor power supplies do support this command.
857 */
858 bool inputHistorySupported{false};
859
860 /**
861 * @brief Class that manages the input power history records.
862 **/
863 std::unique_ptr<history::RecordManager> recordManager;
864
865 /**
866 * @brief The D-Bus object for the average input power history
867 **/
868 std::unique_ptr<history::Average> average;
869
870 /**
871 * @brief The D-Bus object for the maximum input power history
872 **/
873 std::unique_ptr<history::Maximum> maximum;
874
875 /**
876 * @brief The base D-Bus object path to use for the average and maximum
877 * objects.
878 **/
879 std::string historyObjectPath;
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500880};
881
882} // namespace phosphor::power::psu