blob: fbc5b1de91887175c3b4dc055b81e8b3f379f4dd [file] [log] [blame]
Brandon Wyman24e422f2017-07-25 19:40:14 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brandon Wyman442035f2017-08-08 15:58:45 -050016#include <phosphor-logging/log.hpp>
17#include <phosphor-logging/elog.hpp>
Brandon Wymane0eb45c2017-10-06 12:58:42 -050018#include <org/open_power/Witherspoon/Fault/error.hpp>
Matt Spinlerceacf942017-10-05 13:55:02 -050019#include <xyz/openbmc_project/Common/Device/error.hpp>
Brandon Wyman442035f2017-08-08 15:58:45 -050020#include "elog-errors.hpp"
Brandon Wyman10295542017-08-09 18:20:44 -050021#include "names_values.hpp"
Brandon Wyman24e422f2017-07-25 19:40:14 -050022#include "power_supply.hpp"
Brandon Wyman442035f2017-08-08 15:58:45 -050023#include "pmbus.hpp"
24#include "utility.hpp"
25
26using namespace phosphor::logging;
Brandon Wymane0eb45c2017-10-06 12:58:42 -050027using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error;
Matt Spinlerceacf942017-10-05 13:55:02 -050028using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
Brandon Wyman24e422f2017-07-25 19:40:14 -050029
Brandon Wyman01741f12017-12-01 17:22:08 -060030constexpr auto ASSOCIATION_IFACE = "org.openbmc.Association";
31constexpr auto ENDPOINTS_PROPERTY = "endpoints";
32constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry";
33constexpr auto MESSAGE_PROPERTY = "Message";
34constexpr auto RESOLVED_PROPERTY = "Resolved";
35
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050036namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -050037{
38namespace power
39{
40namespace psu
41{
42
Brandon Wyman10295542017-08-09 18:20:44 -050043constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory";
44constexpr auto INVENTORY_INTERFACE = "xyz.openbmc_project.Inventory.Item";
45constexpr auto PRESENT_PROP = "Present";
Brandon Wyman431fbe42017-08-18 16:22:09 -050046constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0";
47constexpr auto POWER_INTERFACE = "org.openbmc.control.Power";
Brandon Wyman10295542017-08-09 18:20:44 -050048
49PowerSupply::PowerSupply(const std::string& name, size_t inst,
Brandon Wyman431fbe42017-08-18 16:22:09 -050050 const std::string& objpath,
51 const std::string& invpath,
52 sdbusplus::bus::bus& bus,
53 event::Event& e,
Brandon Wyman590fc282017-11-01 18:22:25 -050054 std::chrono::seconds& t,
55 std::chrono::seconds& p)
Brandon Wyman431fbe42017-08-18 16:22:09 -050056 : Device(name, inst), monitorPath(objpath), pmbusIntf(objpath),
Brandon Wyman50bb85d2017-11-01 18:36:00 -050057 inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), event(e),
58 presentInterval(p),
Brandon Wyman590fc282017-11-01 18:22:25 -050059 presentTimer(e, [this]()
60 {
Brandon Wyman2877add2017-11-10 17:44:19 -060061 // The hwmon path may have changed.
62 pmbusIntf.findHwmonDir();
Brandon Wyman590fc282017-11-01 18:22:25 -050063 this->present = true;
Matt Spinler234ce0d2018-01-04 15:06:57 -060064
65 // Update the inventory for the new device
66 updateInventory();
Brandon Wyman590fc282017-11-01 18:22:25 -050067 }),
68 powerOnInterval(t),
Brandon Wyman431fbe42017-08-18 16:22:09 -050069 powerOnTimer(e, [this]()
70 {
71 this->powerOn = true;
72 })
Brandon Wyman10295542017-08-09 18:20:44 -050073{
Brandon Wyman10295542017-08-09 18:20:44 -050074 using namespace sdbusplus::bus;
Brandon Wyman10295542017-08-09 18:20:44 -050075 presentMatch = std::make_unique<match_t>(bus,
76 match::rules::propertiesChanged(
Brandon Wyman50bb85d2017-11-01 18:36:00 -050077 inventoryPath,
Brandon Wyman10295542017-08-09 18:20:44 -050078 INVENTORY_INTERFACE),
79 [this](auto& msg)
Brandon Wyman431fbe42017-08-18 16:22:09 -050080 {
81 this->inventoryChanged(msg);
82 });
83 // Get initial presence state.
Brandon Wyman253dc9b2017-08-12 13:45:52 -050084 updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -050085
Matt Spinler234ce0d2018-01-04 15:06:57 -060086 // Write the SN, PN, etc to the inventory
87 updateInventory();
88
Brandon Wyman431fbe42017-08-18 16:22:09 -050089 // Subscribe to power state changes
90 powerOnMatch = std::make_unique<match_t>(bus,
91 match::rules::propertiesChanged(
92 POWER_OBJ_PATH,
93 POWER_INTERFACE),
94 [this](auto& msg)
95 {
96 this->powerStateChanged(msg);
97 });
98 // Get initial power state.
99 updatePowerState();
Brandon Wyman10295542017-08-09 18:20:44 -0500100}
Brandon Wyman442035f2017-08-08 15:58:45 -0500101
Brandon Wymana1e96342017-09-25 16:47:44 -0500102void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd,
103 witherspoon::pmbus::Type type)
104{
105 if (pmbusIntf.exists(cmd, type))
106 {
107 try
108 {
109 auto val = pmbusIntf.read(cmd, type);
110 nv.add(cmd, val);
111 }
112 catch (std::exception& e)
113 {
114 log<level::INFO>("Unable to capture metadata", entry("CMD=%s",
115 cmd));
116 }
117 }
118}
Brandon Wyman431fbe42017-08-18 16:22:09 -0500119
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500120void PowerSupply::analyze()
121{
Brandon Wyman442035f2017-08-08 15:58:45 -0500122 using namespace witherspoon::pmbus;
123
124 try
125 {
Brandon Wyman10295542017-08-09 18:20:44 -0500126 if (present)
Brandon Wyman442035f2017-08-08 15:58:45 -0500127 {
Brandon Wyman764c7972017-08-22 17:05:36 -0500128 std::uint16_t statusWord = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500129
130 // Read the 2 byte STATUS_WORD value to check for faults.
131 statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug);
Brandon Wymane4af9802017-11-13 15:58:33 -0600132 readFail = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500133
Brandon Wyman603cc002017-08-28 18:17:58 -0500134 checkInputFault(statusWord);
Brandon Wyman764c7972017-08-22 17:05:36 -0500135
Brandon Wyman3343e822017-11-03 16:54:11 -0500136 if (powerOn && !faultFound)
Brandon Wyman764c7972017-08-22 17:05:36 -0500137 {
Brandon Wyman12661f12017-08-31 15:28:21 -0500138 checkFanFault(statusWord);
Brandon Wyman875b3632017-09-13 18:46:03 -0500139 checkTemperatureFault(statusWord);
Brandon Wymancfa032b2017-09-25 17:37:50 -0500140 checkOutputOvervoltageFault(statusWord);
141 checkCurrentOutOverCurrentFault(statusWord);
142 checkPGOrUnitOffFault(statusWord);
Brandon Wyman442035f2017-08-08 15:58:45 -0500143 }
144 }
145 }
146 catch (ReadFailure& e)
147 {
Brandon Wymane4af9802017-11-13 15:58:33 -0600148 if (readFail < FAULT_COUNT)
149 {
150 readFail++;
151 }
152
153 if (!readFailLogged && readFail >= FAULT_COUNT)
Brandon Wyman442035f2017-08-08 15:58:45 -0500154 {
155 commit<ReadFailure>();
156 readFailLogged = true;
Brandon Wyman442035f2017-08-08 15:58:45 -0500157 }
158 }
159
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500160 return;
161}
162
Brandon Wyman10295542017-08-09 18:20:44 -0500163void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
164{
165 std::string msgSensor;
166 std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData;
167 msg.read(msgSensor, msgData);
168
169 // Check if it was the Present property that changed.
170 auto valPropMap = msgData.find(PRESENT_PROP);
171 if (valPropMap != msgData.end())
172 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600173 if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second))
Brandon Wyman10295542017-08-09 18:20:44 -0500174 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500175 clearFaults();
Brandon Wyman590fc282017-11-01 18:22:25 -0500176 presentTimer.start(presentInterval, Timer::TimerType::oneshot);
177 }
178 else
179 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600180 present = false;
Brandon Wyman590fc282017-11-01 18:22:25 -0500181 presentTimer.stop();
Matt Spinler234ce0d2018-01-04 15:06:57 -0600182
183 //Clear out the now outdated inventory properties
184 updateInventory();
Brandon Wyman10295542017-08-09 18:20:44 -0500185 }
186 }
187
188 return;
189}
190
191void PowerSupply::updatePresence()
192{
193 // Use getProperty utility function to get presence status.
Brandon Wyman10295542017-08-09 18:20:44 -0500194 std::string service = "xyz.openbmc_project.Inventory.Manager";
Brandon Wyman50bb85d2017-11-01 18:36:00 -0500195 util::getProperty(INVENTORY_INTERFACE, PRESENT_PROP, inventoryPath,
196 service, bus, this->present);
Brandon Wyman10295542017-08-09 18:20:44 -0500197}
198
Brandon Wyman431fbe42017-08-18 16:22:09 -0500199void PowerSupply::powerStateChanged(sdbusplus::message::message& msg)
200{
201 int32_t state = 0;
202 std::string msgSensor;
203 std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>>
204 msgData;
205 msg.read(msgSensor, msgData);
206
207 // Check if it was the Present property that changed.
208 auto valPropMap = msgData.find("state");
209 if (valPropMap != msgData.end())
210 {
211 state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second);
212
213 // Power is on when state=1. Set the fault logged variables to false
214 // and start the power on timer when the state changes to 1.
215 if (state)
216 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500217 clearFaults();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500218 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
219 }
220 else
221 {
222 powerOnTimer.stop();
223 powerOn = false;
224 }
225 }
226
227}
228
229void PowerSupply::updatePowerState()
230{
231 // When state = 1, system is powered on
232 int32_t state = 0;
233
234 try
235 {
236 auto service = util::getService(POWER_OBJ_PATH,
237 POWER_INTERFACE,
238 bus);
239
240 // Use getProperty utility function to get power state.
241 util::getProperty<int32_t>(POWER_INTERFACE,
242 "state",
243 POWER_OBJ_PATH,
244 service,
245 bus,
246 state);
247
248 if (state)
249 {
250 powerOn = true;
251 }
252 else
253 {
254 powerOn = false;
255 }
256 }
257 catch (std::exception& e)
258 {
259 log<level::INFO>("Failed to get power state. Assuming it is off.");
260 powerOn = false;
261 }
262
263}
264
Brandon Wyman603cc002017-08-28 18:17:58 -0500265void PowerSupply::checkInputFault(const uint16_t statusWord)
266{
267 using namespace witherspoon::pmbus;
268
Brandon Wymana3c675c2017-11-14 14:54:54 -0600269 if ((inputFault < FAULT_COUNT) &&
270 ((statusWord & status_word::INPUT_FAULT_WARN) ||
271 (statusWord & status_word::VIN_UV_FAULT)))
Brandon Wyman603cc002017-08-28 18:17:58 -0500272 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600273 inputFault++;
Brandon Wyman603cc002017-08-28 18:17:58 -0500274 }
275 else
276 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600277 if ((inputFault > 0) &&
Brandon Wymand20686a2017-11-01 17:45:23 -0500278 !(statusWord & status_word::INPUT_FAULT_WARN) &&
279 !(statusWord & status_word::VIN_UV_FAULT))
Brandon Wyman603cc002017-08-28 18:17:58 -0500280 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600281 inputFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500282 faultFound = false;
Brandon Wyman69591bd2017-11-01 18:07:23 -0500283
Brandon Wyman603cc002017-08-28 18:17:58 -0500284 log<level::INFO>("INPUT_FAULT_WARN cleared",
Brandon Wymana3c675c2017-11-14 14:54:54 -0600285 entry("POWERSUPPLY=%s", inventoryPath.c_str()));
Brandon Wyman69591bd2017-11-01 18:07:23 -0500286
Brandon Wyman08b05712017-11-30 17:53:56 -0600287 resolveError(inventoryPath,
288 std::string(PowerSupplyInputFault::errName));
289
Brandon Wyman69591bd2017-11-01 18:07:23 -0500290 if (powerOn)
291 {
292 // The power supply will not be immediately powered on after
293 // the input power is restored.
294 powerOn = false;
295 // Start up the timer that will set the state to indicate we
296 // are ready for the powered on fault checks.
297 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
298 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500299 }
300 }
Brandon Wymana3c675c2017-11-14 14:54:54 -0600301
302 if (!faultFound && (inputFault >= FAULT_COUNT))
303 {
304 util::NamesValues nv;
305 nv.add("STATUS_WORD", statusWord);
306 captureCmd(nv, STATUS_INPUT, Type::Debug);
307
308 using metadata = org::open_power::Witherspoon::Fault::
309 PowerSupplyInputFault;
310
311 report<PowerSupplyInputFault>(
312 metadata::RAW_STATUS(nv.get().c_str()),
313 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
314 faultFound = true;
315 }
316
Brandon Wyman603cc002017-08-28 18:17:58 -0500317}
318
319void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord)
320{
321 using namespace witherspoon::pmbus;
322
Brandon Wyman593d24f2017-10-13 18:15:23 -0500323 if (powerOnFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500324 {
Brandon Wyman593d24f2017-10-13 18:15:23 -0500325 // Check PG# and UNIT_IS_OFF
326 if ((statusWord & status_word::POWER_GOOD_NEGATED) ||
327 (statusWord & status_word::UNIT_IS_OFF))
328 {
329 log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad",
330 entry("STATUS_WORD=0x%04X", statusWord));
331 powerOnFault++;
332 }
333 else
334 {
335 if (powerOnFault > 0)
336 {
337 log<level::INFO>("PGOOD and UNIT_IS_OFF bits good");
338 powerOnFault = 0;
339 }
340 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500341
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600342 if (!faultFound && (powerOnFault >= FAULT_COUNT))
Brandon Wyman593d24f2017-10-13 18:15:23 -0500343 {
Brandon Wyman3343e822017-11-03 16:54:11 -0500344 faultFound = true;
345
Brandon Wyman593d24f2017-10-13 18:15:23 -0500346 util::NamesValues nv;
347 nv.add("STATUS_WORD", statusWord);
348 captureCmd(nv, STATUS_INPUT, Type::Debug);
349 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
350 captureCmd(nv, status0Vout, Type::Debug);
351 captureCmd(nv, STATUS_IOUT, Type::Debug);
352 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500353
Brandon Wyman593d24f2017-10-13 18:15:23 -0500354 using metadata = org::open_power::Witherspoon::Fault::
355 PowerSupplyShouldBeOn;
Brandon Wyman603cc002017-08-28 18:17:58 -0500356
Brandon Wyman593d24f2017-10-13 18:15:23 -0500357 // A power supply is OFF (or pgood low) but should be on.
358 report<PowerSupplyShouldBeOn>(
359 metadata::RAW_STATUS(nv.get().c_str()),
360 metadata::CALLOUT_INVENTORY_PATH(
361 inventoryPath.c_str()));
362 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500363 }
364
365}
366
367void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord)
368{
369 using namespace witherspoon::pmbus;
370
Brandon Wymandd61be42017-11-07 18:38:54 -0600371 if (outputOCFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500372 {
Brandon Wymandd61be42017-11-07 18:38:54 -0600373 // Check for an output overcurrent fault.
374 if ((statusWord & status_word::IOUT_OC_FAULT))
375 {
376 outputOCFault++;
377 }
378 else
379 {
380 if (outputOCFault > 0)
381 {
382 outputOCFault = 0;
383 }
384 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500385
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600386 if (!faultFound && (outputOCFault >= FAULT_COUNT))
Brandon Wymandd61be42017-11-07 18:38:54 -0600387 {
388 util::NamesValues nv;
389 nv.add("STATUS_WORD", statusWord);
390 captureCmd(nv, STATUS_INPUT, Type::Debug);
391 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
392 captureCmd(nv, status0Vout, Type::Debug);
393 captureCmd(nv, STATUS_IOUT, Type::Debug);
394 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500395
Brandon Wymandd61be42017-11-07 18:38:54 -0600396 using metadata = org::open_power::Witherspoon::Fault::
397 PowerSupplyOutputOvercurrent;
Brandon Wyman603cc002017-08-28 18:17:58 -0500398
Brandon Wymandd61be42017-11-07 18:38:54 -0600399 report<PowerSupplyOutputOvercurrent>(
400 metadata::RAW_STATUS(nv.get().c_str()),
401 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
402
403 faultFound = true;
404 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500405 }
406}
407
Brandon Wymanab05c072017-08-30 18:26:41 -0500408void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord)
409{
410 using namespace witherspoon::pmbus;
411
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600412 if (outputOVFault < FAULT_COUNT)
Brandon Wymanab05c072017-08-30 18:26:41 -0500413 {
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600414 // Check for an output overvoltage fault.
415 if (statusWord & status_word::VOUT_OV_FAULT)
416 {
417 outputOVFault++;
418 }
419 else
420 {
421 if (outputOVFault > 0)
422 {
423 outputOVFault = 0;
424 }
425 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500426
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600427 if (!faultFound && (outputOVFault >= FAULT_COUNT))
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600428 {
429 util::NamesValues nv;
430 nv.add("STATUS_WORD", statusWord);
431 captureCmd(nv, STATUS_INPUT, Type::Debug);
432 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
433 captureCmd(nv, status0Vout, Type::Debug);
434 captureCmd(nv, STATUS_IOUT, Type::Debug);
435 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wymanab05c072017-08-30 18:26:41 -0500436
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600437 using metadata = org::open_power::Witherspoon::Fault::
438 PowerSupplyOutputOvervoltage;
Brandon Wymanab05c072017-08-30 18:26:41 -0500439
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600440 report<PowerSupplyOutputOvervoltage>(
441 metadata::RAW_STATUS(nv.get().c_str()),
442 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
443
444 faultFound = true;
445 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500446 }
447}
448
Brandon Wyman12661f12017-08-31 15:28:21 -0500449void PowerSupply::checkFanFault(const uint16_t statusWord)
450{
451 using namespace witherspoon::pmbus;
452
Brandon Wymanba255532017-11-08 17:44:10 -0600453 if (fanFault < FAULT_COUNT)
Brandon Wyman12661f12017-08-31 15:28:21 -0500454 {
Brandon Wymanba255532017-11-08 17:44:10 -0600455 // Check for a fan fault or warning condition
456 if (statusWord & status_word::FAN_FAULT)
457 {
458 fanFault++;
459 }
460 else
461 {
462 if (fanFault > 0)
463 {
464 fanFault = 0;
465 }
466 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500467
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600468 if (!faultFound && (fanFault >= FAULT_COUNT))
Brandon Wymanba255532017-11-08 17:44:10 -0600469 {
470 util::NamesValues nv;
471 nv.add("STATUS_WORD", statusWord);
472 captureCmd(nv, STATUS_MFR, Type::Debug);
473 captureCmd(nv, STATUS_TEMPERATURE, Type::Debug);
474 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman12661f12017-08-31 15:28:21 -0500475
Brandon Wymanba255532017-11-08 17:44:10 -0600476 using metadata = org::open_power::Witherspoon::Fault::
477 PowerSupplyFanFault;
Brandon Wyman12661f12017-08-31 15:28:21 -0500478
Brandon Wymanba255532017-11-08 17:44:10 -0600479 report<PowerSupplyFanFault>(
480 metadata::RAW_STATUS(nv.get().c_str()),
481 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
482
483 faultFound = true;
484 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500485 }
486}
487
Brandon Wyman875b3632017-09-13 18:46:03 -0500488void PowerSupply::checkTemperatureFault(const uint16_t statusWord)
489{
490 using namespace witherspoon::pmbus;
491
492 // Due to how the PMBus core device driver sends a clear faults command
493 // the bit in STATUS_WORD will likely be cleared when we attempt to examine
494 // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the
495 // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with
496 // logging the over-temperature condition.
497 std::uint8_t statusTemperature = 0;
498 statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug);
Brandon Wyman50044ea2017-11-08 17:58:56 -0600499 if (temperatureFault < FAULT_COUNT)
Brandon Wyman875b3632017-09-13 18:46:03 -0500500 {
Brandon Wyman50044ea2017-11-08 17:58:56 -0600501 if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
502 (statusTemperature & status_temperature::OT_FAULT))
503 {
504 temperatureFault++;
505 }
506 else
507 {
508 if (temperatureFault > 0)
509 {
510 temperatureFault = 0;
511 }
512 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500513
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600514 if (!faultFound && (temperatureFault >= FAULT_COUNT))
Brandon Wyman50044ea2017-11-08 17:58:56 -0600515 {
516 // The power supply has had an over-temperature condition.
517 // This may not result in a shutdown if experienced for a short
518 // duration.
519 // This should not occur under normal conditions.
520 // The power supply may be faulty, or the paired supply may be
521 // putting out less current.
522 // Capture command responses with potentially relevant information,
523 // and call out the power supply reporting the condition.
524 util::NamesValues nv;
525 nv.add("STATUS_WORD", statusWord);
526 captureCmd(nv, STATUS_MFR, Type::Debug);
527 captureCmd(nv, STATUS_IOUT, Type::Debug);
528 nv.add("STATUS_TEMPERATURE", statusTemperature);
529 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman875b3632017-09-13 18:46:03 -0500530
Brandon Wyman50044ea2017-11-08 17:58:56 -0600531 using metadata = org::open_power::Witherspoon::Fault::
532 PowerSupplyTemperatureFault;
Brandon Wyman875b3632017-09-13 18:46:03 -0500533
Brandon Wyman50044ea2017-11-08 17:58:56 -0600534 report<PowerSupplyTemperatureFault>(
535 metadata::RAW_STATUS(nv.get().c_str()),
536 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
537
538 faultFound = true;
539 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500540 }
541}
542
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500543void PowerSupply::clearFaults()
544{
Brandon Wymane4af9802017-11-13 15:58:33 -0600545 readFail = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500546 readFailLogged = false;
Brandon Wymana3c675c2017-11-14 14:54:54 -0600547 inputFault = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500548 powerOnFault = 0;
Brandon Wymandd61be42017-11-07 18:38:54 -0600549 outputOCFault = 0;
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600550 outputOVFault = 0;
Brandon Wymanba255532017-11-08 17:44:10 -0600551 fanFault = 0;
Brandon Wyman50044ea2017-11-08 17:58:56 -0600552 temperatureFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500553 faultFound = false;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500554
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500555 return;
556}
557
Brandon Wyman43ce2082017-11-30 17:24:01 -0600558void PowerSupply::resolveError(const std::string& callout,
559 const std::string& message)
560{
Brandon Wyman01741f12017-12-01 17:22:08 -0600561 using EndpointList = std::vector<std::string>;
562
563 try
564 {
565 auto path = callout + "/fault";
566 // Get the service name from the mapper for the fault callout
567 auto service = util::getService(path,
568 ASSOCIATION_IFACE,
569 bus);
570
571 // Use getProperty utility function to get log entries (endpoints)
572 EndpointList logEntries;
573 util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROPERTY, path, service,
574 bus, logEntries);
575
576 // It is possible that all such entries for this callout have since
577 // been deleted.
578 if (logEntries.empty())
579 {
580 return;
581 }
582
583 auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE,
584 bus);
585 if (logEntryService.empty())
586 {
587 return;
588 }
589
590 // go through each log entry that matches this callout path
591 std::string logMessage;
592 for (const auto& logEntry : logEntries)
593 {
594 // Check to see if this logEntry has a message that matches.
595 util::getProperty(LOGGING_IFACE, MESSAGE_PROPERTY, logEntry,
596 logEntryService, bus, logMessage);
597
598 if (message == logMessage)
599 {
600 // Log entry matches call out and message, set Resolved to true
601 bool resolved = true;
602 util::setProperty(LOGGING_IFACE, RESOLVED_PROPERTY, logEntry,
603 logEntryService, bus, resolved);
604 }
605
606 }
607
608 }
609 catch (std::exception& e)
610 {
611 log<level::INFO>("Failed to resolve error",
612 entry("CALLOUT=%s", callout.c_str()),
613 entry("MESSAGE=%s", message.c_str()));
614 }
615
Brandon Wyman43ce2082017-11-30 17:24:01 -0600616}
617
Matt Spinler234ce0d2018-01-04 15:06:57 -0600618void PowerSupply::updateInventory()
619{
620}
621
Brandon Wyman24e422f2017-07-25 19:40:14 -0500622}
623}
624}