blob: d7a018f401f65d0f981cef4a71960dbda3b48446 [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;
64 }),
65 powerOnInterval(t),
Brandon Wyman431fbe42017-08-18 16:22:09 -050066 powerOnTimer(e, [this]()
67 {
68 this->powerOn = true;
69 })
Brandon Wyman10295542017-08-09 18:20:44 -050070{
Brandon Wyman10295542017-08-09 18:20:44 -050071 using namespace sdbusplus::bus;
Brandon Wyman10295542017-08-09 18:20:44 -050072 presentMatch = std::make_unique<match_t>(bus,
73 match::rules::propertiesChanged(
Brandon Wyman50bb85d2017-11-01 18:36:00 -050074 inventoryPath,
Brandon Wyman10295542017-08-09 18:20:44 -050075 INVENTORY_INTERFACE),
76 [this](auto& msg)
Brandon Wyman431fbe42017-08-18 16:22:09 -050077 {
78 this->inventoryChanged(msg);
79 });
80 // Get initial presence state.
Brandon Wyman253dc9b2017-08-12 13:45:52 -050081 updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -050082
83 // Subscribe to power state changes
84 powerOnMatch = std::make_unique<match_t>(bus,
85 match::rules::propertiesChanged(
86 POWER_OBJ_PATH,
87 POWER_INTERFACE),
88 [this](auto& msg)
89 {
90 this->powerStateChanged(msg);
91 });
92 // Get initial power state.
93 updatePowerState();
Brandon Wyman10295542017-08-09 18:20:44 -050094}
Brandon Wyman442035f2017-08-08 15:58:45 -050095
Brandon Wymana1e96342017-09-25 16:47:44 -050096void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd,
97 witherspoon::pmbus::Type type)
98{
99 if (pmbusIntf.exists(cmd, type))
100 {
101 try
102 {
103 auto val = pmbusIntf.read(cmd, type);
104 nv.add(cmd, val);
105 }
106 catch (std::exception& e)
107 {
108 log<level::INFO>("Unable to capture metadata", entry("CMD=%s",
109 cmd));
110 }
111 }
112}
Brandon Wyman431fbe42017-08-18 16:22:09 -0500113
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500114void PowerSupply::analyze()
115{
Brandon Wyman442035f2017-08-08 15:58:45 -0500116 using namespace witherspoon::pmbus;
117
118 try
119 {
Brandon Wyman10295542017-08-09 18:20:44 -0500120 if (present)
Brandon Wyman442035f2017-08-08 15:58:45 -0500121 {
Brandon Wyman764c7972017-08-22 17:05:36 -0500122 std::uint16_t statusWord = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500123
124 // Read the 2 byte STATUS_WORD value to check for faults.
125 statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug);
Brandon Wymane4af9802017-11-13 15:58:33 -0600126 readFail = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500127
Brandon Wyman603cc002017-08-28 18:17:58 -0500128 checkInputFault(statusWord);
Brandon Wyman764c7972017-08-22 17:05:36 -0500129
Brandon Wyman3343e822017-11-03 16:54:11 -0500130 if (powerOn && !faultFound)
Brandon Wyman764c7972017-08-22 17:05:36 -0500131 {
Brandon Wyman12661f12017-08-31 15:28:21 -0500132 checkFanFault(statusWord);
Brandon Wyman875b3632017-09-13 18:46:03 -0500133 checkTemperatureFault(statusWord);
Brandon Wymancfa032b2017-09-25 17:37:50 -0500134 checkOutputOvervoltageFault(statusWord);
135 checkCurrentOutOverCurrentFault(statusWord);
136 checkPGOrUnitOffFault(statusWord);
Brandon Wyman442035f2017-08-08 15:58:45 -0500137 }
138 }
139 }
140 catch (ReadFailure& e)
141 {
Brandon Wymane4af9802017-11-13 15:58:33 -0600142 if (readFail < FAULT_COUNT)
143 {
144 readFail++;
145 }
146
147 if (!readFailLogged && readFail >= FAULT_COUNT)
Brandon Wyman442035f2017-08-08 15:58:45 -0500148 {
149 commit<ReadFailure>();
150 readFailLogged = true;
Brandon Wyman442035f2017-08-08 15:58:45 -0500151 }
152 }
153
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500154 return;
155}
156
Brandon Wyman10295542017-08-09 18:20:44 -0500157void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
158{
159 std::string msgSensor;
160 std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData;
161 msg.read(msgSensor, msgData);
162
163 // Check if it was the Present property that changed.
164 auto valPropMap = msgData.find(PRESENT_PROP);
165 if (valPropMap != msgData.end())
166 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600167 if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second))
Brandon Wyman10295542017-08-09 18:20:44 -0500168 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500169 clearFaults();
Brandon Wyman590fc282017-11-01 18:22:25 -0500170 presentTimer.start(presentInterval, Timer::TimerType::oneshot);
171 }
172 else
173 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600174 present = false;
Brandon Wyman590fc282017-11-01 18:22:25 -0500175 presentTimer.stop();
Brandon Wyman10295542017-08-09 18:20:44 -0500176 }
177 }
178
179 return;
180}
181
182void PowerSupply::updatePresence()
183{
184 // Use getProperty utility function to get presence status.
Brandon Wyman10295542017-08-09 18:20:44 -0500185 std::string service = "xyz.openbmc_project.Inventory.Manager";
Brandon Wyman50bb85d2017-11-01 18:36:00 -0500186 util::getProperty(INVENTORY_INTERFACE, PRESENT_PROP, inventoryPath,
187 service, bus, this->present);
Brandon Wyman10295542017-08-09 18:20:44 -0500188}
189
Brandon Wyman431fbe42017-08-18 16:22:09 -0500190void PowerSupply::powerStateChanged(sdbusplus::message::message& msg)
191{
192 int32_t state = 0;
193 std::string msgSensor;
194 std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>>
195 msgData;
196 msg.read(msgSensor, msgData);
197
198 // Check if it was the Present property that changed.
199 auto valPropMap = msgData.find("state");
200 if (valPropMap != msgData.end())
201 {
202 state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second);
203
204 // Power is on when state=1. Set the fault logged variables to false
205 // and start the power on timer when the state changes to 1.
206 if (state)
207 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500208 clearFaults();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500209 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
210 }
211 else
212 {
213 powerOnTimer.stop();
214 powerOn = false;
215 }
216 }
217
218}
219
220void PowerSupply::updatePowerState()
221{
222 // When state = 1, system is powered on
223 int32_t state = 0;
224
225 try
226 {
227 auto service = util::getService(POWER_OBJ_PATH,
228 POWER_INTERFACE,
229 bus);
230
231 // Use getProperty utility function to get power state.
232 util::getProperty<int32_t>(POWER_INTERFACE,
233 "state",
234 POWER_OBJ_PATH,
235 service,
236 bus,
237 state);
238
239 if (state)
240 {
241 powerOn = true;
242 }
243 else
244 {
245 powerOn = false;
246 }
247 }
248 catch (std::exception& e)
249 {
250 log<level::INFO>("Failed to get power state. Assuming it is off.");
251 powerOn = false;
252 }
253
254}
255
Brandon Wyman603cc002017-08-28 18:17:58 -0500256void PowerSupply::checkInputFault(const uint16_t statusWord)
257{
258 using namespace witherspoon::pmbus;
259
Brandon Wymana3c675c2017-11-14 14:54:54 -0600260 if ((inputFault < FAULT_COUNT) &&
261 ((statusWord & status_word::INPUT_FAULT_WARN) ||
262 (statusWord & status_word::VIN_UV_FAULT)))
Brandon Wyman603cc002017-08-28 18:17:58 -0500263 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600264 inputFault++;
Brandon Wyman603cc002017-08-28 18:17:58 -0500265 }
266 else
267 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600268 if ((inputFault > 0) &&
Brandon Wymand20686a2017-11-01 17:45:23 -0500269 !(statusWord & status_word::INPUT_FAULT_WARN) &&
270 !(statusWord & status_word::VIN_UV_FAULT))
Brandon Wyman603cc002017-08-28 18:17:58 -0500271 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600272 inputFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500273 faultFound = false;
Brandon Wyman69591bd2017-11-01 18:07:23 -0500274
Brandon Wyman603cc002017-08-28 18:17:58 -0500275 log<level::INFO>("INPUT_FAULT_WARN cleared",
Brandon Wymana3c675c2017-11-14 14:54:54 -0600276 entry("POWERSUPPLY=%s", inventoryPath.c_str()));
Brandon Wyman69591bd2017-11-01 18:07:23 -0500277
Brandon Wyman08b05712017-11-30 17:53:56 -0600278 resolveError(inventoryPath,
279 std::string(PowerSupplyInputFault::errName));
280
Brandon Wyman69591bd2017-11-01 18:07:23 -0500281 if (powerOn)
282 {
283 // The power supply will not be immediately powered on after
284 // the input power is restored.
285 powerOn = false;
286 // Start up the timer that will set the state to indicate we
287 // are ready for the powered on fault checks.
288 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
289 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500290 }
291 }
Brandon Wymana3c675c2017-11-14 14:54:54 -0600292
293 if (!faultFound && (inputFault >= FAULT_COUNT))
294 {
295 util::NamesValues nv;
296 nv.add("STATUS_WORD", statusWord);
297 captureCmd(nv, STATUS_INPUT, Type::Debug);
298
299 using metadata = org::open_power::Witherspoon::Fault::
300 PowerSupplyInputFault;
301
302 report<PowerSupplyInputFault>(
303 metadata::RAW_STATUS(nv.get().c_str()),
304 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
305 faultFound = true;
306 }
307
Brandon Wyman603cc002017-08-28 18:17:58 -0500308}
309
310void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord)
311{
312 using namespace witherspoon::pmbus;
313
Brandon Wyman593d24f2017-10-13 18:15:23 -0500314 if (powerOnFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500315 {
Brandon Wyman593d24f2017-10-13 18:15:23 -0500316 // Check PG# and UNIT_IS_OFF
317 if ((statusWord & status_word::POWER_GOOD_NEGATED) ||
318 (statusWord & status_word::UNIT_IS_OFF))
319 {
320 log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad",
321 entry("STATUS_WORD=0x%04X", statusWord));
322 powerOnFault++;
323 }
324 else
325 {
326 if (powerOnFault > 0)
327 {
328 log<level::INFO>("PGOOD and UNIT_IS_OFF bits good");
329 powerOnFault = 0;
330 }
331 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500332
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600333 if (!faultFound && (powerOnFault >= FAULT_COUNT))
Brandon Wyman593d24f2017-10-13 18:15:23 -0500334 {
Brandon Wyman3343e822017-11-03 16:54:11 -0500335 faultFound = true;
336
Brandon Wyman593d24f2017-10-13 18:15:23 -0500337 util::NamesValues nv;
338 nv.add("STATUS_WORD", statusWord);
339 captureCmd(nv, STATUS_INPUT, Type::Debug);
340 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
341 captureCmd(nv, status0Vout, Type::Debug);
342 captureCmd(nv, STATUS_IOUT, Type::Debug);
343 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500344
Brandon Wyman593d24f2017-10-13 18:15:23 -0500345 using metadata = org::open_power::Witherspoon::Fault::
346 PowerSupplyShouldBeOn;
Brandon Wyman603cc002017-08-28 18:17:58 -0500347
Brandon Wyman593d24f2017-10-13 18:15:23 -0500348 // A power supply is OFF (or pgood low) but should be on.
349 report<PowerSupplyShouldBeOn>(
350 metadata::RAW_STATUS(nv.get().c_str()),
351 metadata::CALLOUT_INVENTORY_PATH(
352 inventoryPath.c_str()));
353 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500354 }
355
356}
357
358void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord)
359{
360 using namespace witherspoon::pmbus;
361
Brandon Wymandd61be42017-11-07 18:38:54 -0600362 if (outputOCFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500363 {
Brandon Wymandd61be42017-11-07 18:38:54 -0600364 // Check for an output overcurrent fault.
365 if ((statusWord & status_word::IOUT_OC_FAULT))
366 {
367 outputOCFault++;
368 }
369 else
370 {
371 if (outputOCFault > 0)
372 {
373 outputOCFault = 0;
374 }
375 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500376
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600377 if (!faultFound && (outputOCFault >= FAULT_COUNT))
Brandon Wymandd61be42017-11-07 18:38:54 -0600378 {
379 util::NamesValues nv;
380 nv.add("STATUS_WORD", statusWord);
381 captureCmd(nv, STATUS_INPUT, Type::Debug);
382 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
383 captureCmd(nv, status0Vout, Type::Debug);
384 captureCmd(nv, STATUS_IOUT, Type::Debug);
385 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500386
Brandon Wymandd61be42017-11-07 18:38:54 -0600387 using metadata = org::open_power::Witherspoon::Fault::
388 PowerSupplyOutputOvercurrent;
Brandon Wyman603cc002017-08-28 18:17:58 -0500389
Brandon Wymandd61be42017-11-07 18:38:54 -0600390 report<PowerSupplyOutputOvercurrent>(
391 metadata::RAW_STATUS(nv.get().c_str()),
392 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
393
394 faultFound = true;
395 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500396 }
397}
398
Brandon Wymanab05c072017-08-30 18:26:41 -0500399void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord)
400{
401 using namespace witherspoon::pmbus;
402
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600403 if (outputOVFault < FAULT_COUNT)
Brandon Wymanab05c072017-08-30 18:26:41 -0500404 {
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600405 // Check for an output overvoltage fault.
406 if (statusWord & status_word::VOUT_OV_FAULT)
407 {
408 outputOVFault++;
409 }
410 else
411 {
412 if (outputOVFault > 0)
413 {
414 outputOVFault = 0;
415 }
416 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500417
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600418 if (!faultFound && (outputOVFault >= FAULT_COUNT))
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600419 {
420 util::NamesValues nv;
421 nv.add("STATUS_WORD", statusWord);
422 captureCmd(nv, STATUS_INPUT, Type::Debug);
423 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
424 captureCmd(nv, status0Vout, Type::Debug);
425 captureCmd(nv, STATUS_IOUT, Type::Debug);
426 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wymanab05c072017-08-30 18:26:41 -0500427
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600428 using metadata = org::open_power::Witherspoon::Fault::
429 PowerSupplyOutputOvervoltage;
Brandon Wymanab05c072017-08-30 18:26:41 -0500430
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600431 report<PowerSupplyOutputOvervoltage>(
432 metadata::RAW_STATUS(nv.get().c_str()),
433 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
434
435 faultFound = true;
436 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500437 }
438}
439
Brandon Wyman12661f12017-08-31 15:28:21 -0500440void PowerSupply::checkFanFault(const uint16_t statusWord)
441{
442 using namespace witherspoon::pmbus;
443
Brandon Wymanba255532017-11-08 17:44:10 -0600444 if (fanFault < FAULT_COUNT)
Brandon Wyman12661f12017-08-31 15:28:21 -0500445 {
Brandon Wymanba255532017-11-08 17:44:10 -0600446 // Check for a fan fault or warning condition
447 if (statusWord & status_word::FAN_FAULT)
448 {
449 fanFault++;
450 }
451 else
452 {
453 if (fanFault > 0)
454 {
455 fanFault = 0;
456 }
457 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500458
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600459 if (!faultFound && (fanFault >= FAULT_COUNT))
Brandon Wymanba255532017-11-08 17:44:10 -0600460 {
461 util::NamesValues nv;
462 nv.add("STATUS_WORD", statusWord);
463 captureCmd(nv, STATUS_MFR, Type::Debug);
464 captureCmd(nv, STATUS_TEMPERATURE, Type::Debug);
465 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman12661f12017-08-31 15:28:21 -0500466
Brandon Wymanba255532017-11-08 17:44:10 -0600467 using metadata = org::open_power::Witherspoon::Fault::
468 PowerSupplyFanFault;
Brandon Wyman12661f12017-08-31 15:28:21 -0500469
Brandon Wymanba255532017-11-08 17:44:10 -0600470 report<PowerSupplyFanFault>(
471 metadata::RAW_STATUS(nv.get().c_str()),
472 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
473
474 faultFound = true;
475 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500476 }
477}
478
Brandon Wyman875b3632017-09-13 18:46:03 -0500479void PowerSupply::checkTemperatureFault(const uint16_t statusWord)
480{
481 using namespace witherspoon::pmbus;
482
483 // Due to how the PMBus core device driver sends a clear faults command
484 // the bit in STATUS_WORD will likely be cleared when we attempt to examine
485 // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the
486 // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with
487 // logging the over-temperature condition.
488 std::uint8_t statusTemperature = 0;
489 statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug);
Brandon Wyman50044ea2017-11-08 17:58:56 -0600490 if (temperatureFault < FAULT_COUNT)
Brandon Wyman875b3632017-09-13 18:46:03 -0500491 {
Brandon Wyman50044ea2017-11-08 17:58:56 -0600492 if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
493 (statusTemperature & status_temperature::OT_FAULT))
494 {
495 temperatureFault++;
496 }
497 else
498 {
499 if (temperatureFault > 0)
500 {
501 temperatureFault = 0;
502 }
503 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500504
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600505 if (!faultFound && (temperatureFault >= FAULT_COUNT))
Brandon Wyman50044ea2017-11-08 17:58:56 -0600506 {
507 // The power supply has had an over-temperature condition.
508 // This may not result in a shutdown if experienced for a short
509 // duration.
510 // This should not occur under normal conditions.
511 // The power supply may be faulty, or the paired supply may be
512 // putting out less current.
513 // Capture command responses with potentially relevant information,
514 // and call out the power supply reporting the condition.
515 util::NamesValues nv;
516 nv.add("STATUS_WORD", statusWord);
517 captureCmd(nv, STATUS_MFR, Type::Debug);
518 captureCmd(nv, STATUS_IOUT, Type::Debug);
519 nv.add("STATUS_TEMPERATURE", statusTemperature);
520 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman875b3632017-09-13 18:46:03 -0500521
Brandon Wyman50044ea2017-11-08 17:58:56 -0600522 using metadata = org::open_power::Witherspoon::Fault::
523 PowerSupplyTemperatureFault;
Brandon Wyman875b3632017-09-13 18:46:03 -0500524
Brandon Wyman50044ea2017-11-08 17:58:56 -0600525 report<PowerSupplyTemperatureFault>(
526 metadata::RAW_STATUS(nv.get().c_str()),
527 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
528
529 faultFound = true;
530 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500531 }
532}
533
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500534void PowerSupply::clearFaults()
535{
Brandon Wymane4af9802017-11-13 15:58:33 -0600536 readFail = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500537 readFailLogged = false;
Brandon Wymana3c675c2017-11-14 14:54:54 -0600538 inputFault = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500539 powerOnFault = 0;
Brandon Wymandd61be42017-11-07 18:38:54 -0600540 outputOCFault = 0;
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600541 outputOVFault = 0;
Brandon Wymanba255532017-11-08 17:44:10 -0600542 fanFault = 0;
Brandon Wyman50044ea2017-11-08 17:58:56 -0600543 temperatureFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500544 faultFound = false;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500545
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500546 return;
547}
548
Brandon Wyman43ce2082017-11-30 17:24:01 -0600549void PowerSupply::resolveError(const std::string& callout,
550 const std::string& message)
551{
Brandon Wyman01741f12017-12-01 17:22:08 -0600552 using EndpointList = std::vector<std::string>;
553
554 try
555 {
556 auto path = callout + "/fault";
557 // Get the service name from the mapper for the fault callout
558 auto service = util::getService(path,
559 ASSOCIATION_IFACE,
560 bus);
561
562 // Use getProperty utility function to get log entries (endpoints)
563 EndpointList logEntries;
564 util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROPERTY, path, service,
565 bus, logEntries);
566
567 // It is possible that all such entries for this callout have since
568 // been deleted.
569 if (logEntries.empty())
570 {
571 return;
572 }
573
574 auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE,
575 bus);
576 if (logEntryService.empty())
577 {
578 return;
579 }
580
581 // go through each log entry that matches this callout path
582 std::string logMessage;
583 for (const auto& logEntry : logEntries)
584 {
585 // Check to see if this logEntry has a message that matches.
586 util::getProperty(LOGGING_IFACE, MESSAGE_PROPERTY, logEntry,
587 logEntryService, bus, logMessage);
588
589 if (message == logMessage)
590 {
591 // Log entry matches call out and message, set Resolved to true
592 bool resolved = true;
593 util::setProperty(LOGGING_IFACE, RESOLVED_PROPERTY, logEntry,
594 logEntryService, bus, resolved);
595 }
596
597 }
598
599 }
600 catch (std::exception& e)
601 {
602 log<level::INFO>("Failed to resolve error",
603 entry("CALLOUT=%s", callout.c_str()),
604 entry("MESSAGE=%s", message.c_str()));
605 }
606
Brandon Wyman43ce2082017-11-30 17:24:01 -0600607}
608
Brandon Wyman24e422f2017-07-25 19:40:14 -0500609}
610}
611}