blob: 0c42ca091ecde8cc84c19b41a706c4783ad6bc80 [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>
Matt Spinler018a7bc2018-01-04 15:36:41 -060020#include <xyz/openbmc_project/Software/Version/server.hpp>
Brandon Wyman442035f2017-08-08 15:58:45 -050021#include "elog-errors.hpp"
Matt Spinlerd734e652018-01-18 14:31:15 -060022#include "gpio.hpp"
Brandon Wyman10295542017-08-09 18:20:44 -050023#include "names_values.hpp"
Brandon Wyman24e422f2017-07-25 19:40:14 -050024#include "power_supply.hpp"
Brandon Wyman442035f2017-08-08 15:58:45 -050025#include "pmbus.hpp"
26#include "utility.hpp"
27
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050028namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -050029{
30namespace power
31{
32namespace psu
33{
34
Matt Spinler589e8722018-01-04 15:24:49 -060035using namespace phosphor::logging;
36using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error;
37using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
Matt Spinler018a7bc2018-01-04 15:36:41 -060038namespace version = sdbusplus::xyz::openbmc_project::Software::server;
Matt Spinler589e8722018-01-04 15:24:49 -060039
40constexpr auto ASSOCIATION_IFACE = "org.openbmc.Association";
41constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry";
42constexpr auto INVENTORY_IFACE = "xyz.openbmc_project.Inventory.Item";
43constexpr auto POWER_IFACE = "org.openbmc.control.Power";
Matt Spinler018a7bc2018-01-04 15:36:41 -060044constexpr auto INVENTORY_MGR_IFACE = "xyz.openbmc_project.Inventory.Manager";
45constexpr auto ASSET_IFACE = "xyz.openbmc_project.Inventory.Decorator.Asset";
46constexpr auto VERSION_IFACE = "xyz.openbmc_project.Software.Version";
Matt Spinler589e8722018-01-04 15:24:49 -060047
48constexpr auto ENDPOINTS_PROP = "endpoints";
49constexpr auto MESSAGE_PROP = "Message";
50constexpr auto RESOLVED_PROP = "Resolved";
Brandon Wyman10295542017-08-09 18:20:44 -050051constexpr auto PRESENT_PROP = "Present";
Matt Spinler018a7bc2018-01-04 15:36:41 -060052constexpr auto SN_PROP = "SerialNumber";
53constexpr auto PN_PROP = "PartNumber";
54constexpr auto MODEL_PROP = "Model";
55constexpr auto VERSION_PROP = "Version";
56constexpr auto VERSION_PURPOSE_PROP = "Purpose";
Matt Spinler589e8722018-01-04 15:24:49 -060057
58constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory";
Brandon Wyman431fbe42017-08-18 16:22:09 -050059constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0";
Brandon Wyman10295542017-08-09 18:20:44 -050060
Matt Spinler018a7bc2018-01-04 15:36:41 -060061constexpr auto SERIAL_NUMBER = "serial_number";
62constexpr auto PART_NUMBER = "part_number";
63constexpr auto FW_VERSION = "fw_version";
64constexpr auto CCIN = "ccin";
Matt Spinlereb169fd2018-01-18 14:19:08 -060065constexpr auto INPUT_HISTORY = "input_history";
Matt Spinler018a7bc2018-01-04 15:36:41 -060066
Brandon Wyman10295542017-08-09 18:20:44 -050067PowerSupply::PowerSupply(const std::string& name, size_t inst,
Brandon Wyman431fbe42017-08-18 16:22:09 -050068 const std::string& objpath,
69 const std::string& invpath,
70 sdbusplus::bus::bus& bus,
71 event::Event& e,
Brandon Wyman590fc282017-11-01 18:22:25 -050072 std::chrono::seconds& t,
73 std::chrono::seconds& p)
Brandon Wyman431fbe42017-08-18 16:22:09 -050074 : Device(name, inst), monitorPath(objpath), pmbusIntf(objpath),
Brandon Wyman50bb85d2017-11-01 18:36:00 -050075 inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), event(e),
76 presentInterval(p),
Brandon Wyman590fc282017-11-01 18:22:25 -050077 presentTimer(e, [this]()
78 {
Brandon Wyman2877add2017-11-10 17:44:19 -060079 // The hwmon path may have changed.
80 pmbusIntf.findHwmonDir();
Brandon Wyman590fc282017-11-01 18:22:25 -050081 this->present = true;
Matt Spinler234ce0d2018-01-04 15:06:57 -060082
Matt Spinlerd734e652018-01-18 14:31:15 -060083 // Sync the INPUT_HISTORY data for all PSs
84 syncHistory();
85
Matt Spinler234ce0d2018-01-04 15:06:57 -060086 // Update the inventory for the new device
87 updateInventory();
Brandon Wyman590fc282017-11-01 18:22:25 -050088 }),
89 powerOnInterval(t),
Brandon Wyman431fbe42017-08-18 16:22:09 -050090 powerOnTimer(e, [this]()
91 {
92 this->powerOn = true;
93 })
Brandon Wyman10295542017-08-09 18:20:44 -050094{
Brandon Wyman10295542017-08-09 18:20:44 -050095 using namespace sdbusplus::bus;
Brandon Wyman10295542017-08-09 18:20:44 -050096 presentMatch = std::make_unique<match_t>(bus,
97 match::rules::propertiesChanged(
Brandon Wyman50bb85d2017-11-01 18:36:00 -050098 inventoryPath,
Matt Spinler589e8722018-01-04 15:24:49 -060099 INVENTORY_IFACE),
Brandon Wyman10295542017-08-09 18:20:44 -0500100 [this](auto& msg)
Brandon Wyman431fbe42017-08-18 16:22:09 -0500101 {
102 this->inventoryChanged(msg);
103 });
104 // Get initial presence state.
Brandon Wyman253dc9b2017-08-12 13:45:52 -0500105 updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500106
Matt Spinler234ce0d2018-01-04 15:06:57 -0600107 // Write the SN, PN, etc to the inventory
108 updateInventory();
109
Brandon Wyman431fbe42017-08-18 16:22:09 -0500110 // Subscribe to power state changes
111 powerOnMatch = std::make_unique<match_t>(bus,
112 match::rules::propertiesChanged(
113 POWER_OBJ_PATH,
Matt Spinler589e8722018-01-04 15:24:49 -0600114 POWER_IFACE),
Brandon Wyman431fbe42017-08-18 16:22:09 -0500115 [this](auto& msg)
116 {
117 this->powerStateChanged(msg);
118 });
119 // Get initial power state.
120 updatePowerState();
Brandon Wyman10295542017-08-09 18:20:44 -0500121}
Brandon Wyman442035f2017-08-08 15:58:45 -0500122
Brandon Wymana1e96342017-09-25 16:47:44 -0500123void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd,
124 witherspoon::pmbus::Type type)
125{
126 if (pmbusIntf.exists(cmd, type))
127 {
128 try
129 {
130 auto val = pmbusIntf.read(cmd, type);
131 nv.add(cmd, val);
132 }
133 catch (std::exception& e)
134 {
135 log<level::INFO>("Unable to capture metadata", entry("CMD=%s",
136 cmd));
137 }
138 }
139}
Brandon Wyman431fbe42017-08-18 16:22:09 -0500140
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500141void PowerSupply::analyze()
142{
Brandon Wyman442035f2017-08-08 15:58:45 -0500143 using namespace witherspoon::pmbus;
144
145 try
146 {
Brandon Wyman10295542017-08-09 18:20:44 -0500147 if (present)
Brandon Wyman442035f2017-08-08 15:58:45 -0500148 {
Brandon Wyman764c7972017-08-22 17:05:36 -0500149 std::uint16_t statusWord = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500150
151 // Read the 2 byte STATUS_WORD value to check for faults.
152 statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug);
Brandon Wymane4af9802017-11-13 15:58:33 -0600153 readFail = 0;
Brandon Wyman764c7972017-08-22 17:05:36 -0500154
Brandon Wyman603cc002017-08-28 18:17:58 -0500155 checkInputFault(statusWord);
Brandon Wyman764c7972017-08-22 17:05:36 -0500156
Brandon Wyman3343e822017-11-03 16:54:11 -0500157 if (powerOn && !faultFound)
Brandon Wyman764c7972017-08-22 17:05:36 -0500158 {
Brandon Wyman12661f12017-08-31 15:28:21 -0500159 checkFanFault(statusWord);
Brandon Wyman875b3632017-09-13 18:46:03 -0500160 checkTemperatureFault(statusWord);
Brandon Wymancfa032b2017-09-25 17:37:50 -0500161 checkOutputOvervoltageFault(statusWord);
162 checkCurrentOutOverCurrentFault(statusWord);
163 checkPGOrUnitOffFault(statusWord);
Brandon Wyman442035f2017-08-08 15:58:45 -0500164 }
Matt Spinlereb169fd2018-01-18 14:19:08 -0600165
166 updateHistory();
Brandon Wyman442035f2017-08-08 15:58:45 -0500167 }
168 }
169 catch (ReadFailure& e)
170 {
Brandon Wymane4af9802017-11-13 15:58:33 -0600171 if (readFail < FAULT_COUNT)
172 {
173 readFail++;
174 }
175
176 if (!readFailLogged && readFail >= FAULT_COUNT)
Brandon Wyman442035f2017-08-08 15:58:45 -0500177 {
178 commit<ReadFailure>();
179 readFailLogged = true;
Brandon Wyman442035f2017-08-08 15:58:45 -0500180 }
181 }
182
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500183 return;
184}
185
Brandon Wyman10295542017-08-09 18:20:44 -0500186void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
187{
188 std::string msgSensor;
189 std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData;
190 msg.read(msgSensor, msgData);
191
192 // Check if it was the Present property that changed.
193 auto valPropMap = msgData.find(PRESENT_PROP);
194 if (valPropMap != msgData.end())
195 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600196 if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second))
Brandon Wyman10295542017-08-09 18:20:44 -0500197 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500198 clearFaults();
Brandon Wyman590fc282017-11-01 18:22:25 -0500199 presentTimer.start(presentInterval, Timer::TimerType::oneshot);
200 }
201 else
202 {
Brandon Wyman2ef48cf2017-11-21 15:43:54 -0600203 present = false;
Brandon Wyman590fc282017-11-01 18:22:25 -0500204 presentTimer.stop();
Matt Spinler234ce0d2018-01-04 15:06:57 -0600205
206 //Clear out the now outdated inventory properties
207 updateInventory();
Brandon Wyman10295542017-08-09 18:20:44 -0500208 }
209 }
210
211 return;
212}
213
214void PowerSupply::updatePresence()
215{
216 // Use getProperty utility function to get presence status.
Brandon Wyman10295542017-08-09 18:20:44 -0500217 std::string service = "xyz.openbmc_project.Inventory.Manager";
Matt Spinler589e8722018-01-04 15:24:49 -0600218 util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath,
Brandon Wyman50bb85d2017-11-01 18:36:00 -0500219 service, bus, this->present);
Brandon Wyman10295542017-08-09 18:20:44 -0500220}
221
Brandon Wyman431fbe42017-08-18 16:22:09 -0500222void PowerSupply::powerStateChanged(sdbusplus::message::message& msg)
223{
224 int32_t state = 0;
225 std::string msgSensor;
226 std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>>
227 msgData;
228 msg.read(msgSensor, msgData);
229
230 // Check if it was the Present property that changed.
231 auto valPropMap = msgData.find("state");
232 if (valPropMap != msgData.end())
233 {
234 state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second);
235
236 // Power is on when state=1. Set the fault logged variables to false
237 // and start the power on timer when the state changes to 1.
238 if (state)
239 {
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500240 clearFaults();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500241 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
242 }
243 else
244 {
245 powerOnTimer.stop();
246 powerOn = false;
247 }
248 }
249
250}
251
252void PowerSupply::updatePowerState()
253{
254 // When state = 1, system is powered on
255 int32_t state = 0;
256
257 try
258 {
259 auto service = util::getService(POWER_OBJ_PATH,
Matt Spinler589e8722018-01-04 15:24:49 -0600260 POWER_IFACE,
Brandon Wyman431fbe42017-08-18 16:22:09 -0500261 bus);
262
263 // Use getProperty utility function to get power state.
Matt Spinler589e8722018-01-04 15:24:49 -0600264 util::getProperty<int32_t>(POWER_IFACE,
Brandon Wyman431fbe42017-08-18 16:22:09 -0500265 "state",
266 POWER_OBJ_PATH,
267 service,
268 bus,
269 state);
270
271 if (state)
272 {
273 powerOn = true;
274 }
275 else
276 {
277 powerOn = false;
278 }
279 }
280 catch (std::exception& e)
281 {
282 log<level::INFO>("Failed to get power state. Assuming it is off.");
283 powerOn = false;
284 }
285
286}
287
Brandon Wyman603cc002017-08-28 18:17:58 -0500288void PowerSupply::checkInputFault(const uint16_t statusWord)
289{
290 using namespace witherspoon::pmbus;
291
Brandon Wymana3c675c2017-11-14 14:54:54 -0600292 if ((inputFault < FAULT_COUNT) &&
293 ((statusWord & status_word::INPUT_FAULT_WARN) ||
294 (statusWord & status_word::VIN_UV_FAULT)))
Brandon Wyman603cc002017-08-28 18:17:58 -0500295 {
Brandon Wymanad708242018-01-19 17:28:35 -0600296 if (inputFault == 0)
297 {
298 log<level::INFO>("INPUT or VIN_UV fault",
299 entry("STATUS_WORD=0x%04X", statusWord));
300 }
301
Brandon Wymana3c675c2017-11-14 14:54:54 -0600302 inputFault++;
Brandon Wyman603cc002017-08-28 18:17:58 -0500303 }
304 else
305 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600306 if ((inputFault > 0) &&
Brandon Wymand20686a2017-11-01 17:45:23 -0500307 !(statusWord & status_word::INPUT_FAULT_WARN) &&
308 !(statusWord & status_word::VIN_UV_FAULT))
Brandon Wyman603cc002017-08-28 18:17:58 -0500309 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600310 inputFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500311 faultFound = false;
Brandon Wyman69591bd2017-11-01 18:07:23 -0500312
Brandon Wyman603cc002017-08-28 18:17:58 -0500313 log<level::INFO>("INPUT_FAULT_WARN cleared",
Brandon Wymana3c675c2017-11-14 14:54:54 -0600314 entry("POWERSUPPLY=%s", inventoryPath.c_str()));
Brandon Wyman69591bd2017-11-01 18:07:23 -0500315
Brandon Wyman08b05712017-11-30 17:53:56 -0600316 resolveError(inventoryPath,
317 std::string(PowerSupplyInputFault::errName));
318
Brandon Wyman69591bd2017-11-01 18:07:23 -0500319 if (powerOn)
320 {
321 // The power supply will not be immediately powered on after
322 // the input power is restored.
323 powerOn = false;
324 // Start up the timer that will set the state to indicate we
325 // are ready for the powered on fault checks.
326 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
327 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500328 }
329 }
Brandon Wymana3c675c2017-11-14 14:54:54 -0600330
331 if (!faultFound && (inputFault >= FAULT_COUNT))
332 {
Brandon Wymanad708242018-01-19 17:28:35 -0600333 // If the power is on, report the fault in an error log entry.
334 if (powerOn)
335 {
336 util::NamesValues nv;
337 nv.add("STATUS_WORD", statusWord);
338 captureCmd(nv, STATUS_INPUT, Type::Debug);
Brandon Wymana3c675c2017-11-14 14:54:54 -0600339
Brandon Wymanad708242018-01-19 17:28:35 -0600340 using metadata = org::open_power::Witherspoon::Fault::
341 PowerSupplyInputFault;
Brandon Wymana3c675c2017-11-14 14:54:54 -0600342
Brandon Wymanad708242018-01-19 17:28:35 -0600343 report<PowerSupplyInputFault>(
344 metadata::RAW_STATUS(nv.get().c_str()),
345 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
346
347 faultFound = true;
348 }
Brandon Wymana3c675c2017-11-14 14:54:54 -0600349 }
350
Brandon Wyman603cc002017-08-28 18:17:58 -0500351}
352
353void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord)
354{
355 using namespace witherspoon::pmbus;
356
Brandon Wyman593d24f2017-10-13 18:15:23 -0500357 if (powerOnFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500358 {
Brandon Wyman593d24f2017-10-13 18:15:23 -0500359 // Check PG# and UNIT_IS_OFF
360 if ((statusWord & status_word::POWER_GOOD_NEGATED) ||
361 (statusWord & status_word::UNIT_IS_OFF))
362 {
363 log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad",
364 entry("STATUS_WORD=0x%04X", statusWord));
365 powerOnFault++;
366 }
367 else
368 {
369 if (powerOnFault > 0)
370 {
371 log<level::INFO>("PGOOD and UNIT_IS_OFF bits good");
372 powerOnFault = 0;
373 }
374 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500375
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600376 if (!faultFound && (powerOnFault >= FAULT_COUNT))
Brandon Wyman593d24f2017-10-13 18:15:23 -0500377 {
Brandon Wyman3343e822017-11-03 16:54:11 -0500378 faultFound = true;
379
Brandon Wyman593d24f2017-10-13 18:15:23 -0500380 util::NamesValues nv;
381 nv.add("STATUS_WORD", statusWord);
382 captureCmd(nv, STATUS_INPUT, Type::Debug);
383 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
384 captureCmd(nv, status0Vout, Type::Debug);
385 captureCmd(nv, STATUS_IOUT, Type::Debug);
386 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500387
Brandon Wyman593d24f2017-10-13 18:15:23 -0500388 using metadata = org::open_power::Witherspoon::Fault::
389 PowerSupplyShouldBeOn;
Brandon Wyman603cc002017-08-28 18:17:58 -0500390
Brandon Wyman593d24f2017-10-13 18:15:23 -0500391 // A power supply is OFF (or pgood low) but should be on.
392 report<PowerSupplyShouldBeOn>(
393 metadata::RAW_STATUS(nv.get().c_str()),
394 metadata::CALLOUT_INVENTORY_PATH(
395 inventoryPath.c_str()));
396 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500397 }
398
399}
400
401void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord)
402{
403 using namespace witherspoon::pmbus;
404
Brandon Wymandd61be42017-11-07 18:38:54 -0600405 if (outputOCFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500406 {
Brandon Wymandd61be42017-11-07 18:38:54 -0600407 // Check for an output overcurrent fault.
408 if ((statusWord & status_word::IOUT_OC_FAULT))
409 {
410 outputOCFault++;
411 }
412 else
413 {
414 if (outputOCFault > 0)
415 {
416 outputOCFault = 0;
417 }
418 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500419
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600420 if (!faultFound && (outputOCFault >= FAULT_COUNT))
Brandon Wymandd61be42017-11-07 18:38:54 -0600421 {
422 util::NamesValues nv;
423 nv.add("STATUS_WORD", statusWord);
424 captureCmd(nv, STATUS_INPUT, Type::Debug);
425 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
426 captureCmd(nv, status0Vout, Type::Debug);
427 captureCmd(nv, STATUS_IOUT, Type::Debug);
428 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500429
Brandon Wymandd61be42017-11-07 18:38:54 -0600430 using metadata = org::open_power::Witherspoon::Fault::
431 PowerSupplyOutputOvercurrent;
Brandon Wyman603cc002017-08-28 18:17:58 -0500432
Brandon Wymandd61be42017-11-07 18:38:54 -0600433 report<PowerSupplyOutputOvercurrent>(
434 metadata::RAW_STATUS(nv.get().c_str()),
435 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
436
437 faultFound = true;
438 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500439 }
440}
441
Brandon Wymanab05c072017-08-30 18:26:41 -0500442void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord)
443{
444 using namespace witherspoon::pmbus;
445
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600446 if (outputOVFault < FAULT_COUNT)
Brandon Wymanab05c072017-08-30 18:26:41 -0500447 {
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600448 // Check for an output overvoltage fault.
449 if (statusWord & status_word::VOUT_OV_FAULT)
450 {
451 outputOVFault++;
452 }
453 else
454 {
455 if (outputOVFault > 0)
456 {
457 outputOVFault = 0;
458 }
459 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500460
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600461 if (!faultFound && (outputOVFault >= FAULT_COUNT))
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600462 {
463 util::NamesValues nv;
464 nv.add("STATUS_WORD", statusWord);
465 captureCmd(nv, STATUS_INPUT, Type::Debug);
466 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
467 captureCmd(nv, status0Vout, Type::Debug);
468 captureCmd(nv, STATUS_IOUT, Type::Debug);
469 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wymanab05c072017-08-30 18:26:41 -0500470
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600471 using metadata = org::open_power::Witherspoon::Fault::
472 PowerSupplyOutputOvervoltage;
Brandon Wymanab05c072017-08-30 18:26:41 -0500473
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600474 report<PowerSupplyOutputOvervoltage>(
475 metadata::RAW_STATUS(nv.get().c_str()),
476 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
477
478 faultFound = true;
479 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500480 }
481}
482
Brandon Wyman12661f12017-08-31 15:28:21 -0500483void PowerSupply::checkFanFault(const uint16_t statusWord)
484{
485 using namespace witherspoon::pmbus;
486
Brandon Wymanba255532017-11-08 17:44:10 -0600487 if (fanFault < FAULT_COUNT)
Brandon Wyman12661f12017-08-31 15:28:21 -0500488 {
Brandon Wymanba255532017-11-08 17:44:10 -0600489 // Check for a fan fault or warning condition
490 if (statusWord & status_word::FAN_FAULT)
491 {
492 fanFault++;
493 }
494 else
495 {
496 if (fanFault > 0)
497 {
498 fanFault = 0;
499 }
500 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500501
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600502 if (!faultFound && (fanFault >= FAULT_COUNT))
Brandon Wymanba255532017-11-08 17:44:10 -0600503 {
504 util::NamesValues nv;
505 nv.add("STATUS_WORD", statusWord);
506 captureCmd(nv, STATUS_MFR, Type::Debug);
507 captureCmd(nv, STATUS_TEMPERATURE, Type::Debug);
508 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman12661f12017-08-31 15:28:21 -0500509
Brandon Wymanba255532017-11-08 17:44:10 -0600510 using metadata = org::open_power::Witherspoon::Fault::
511 PowerSupplyFanFault;
Brandon Wyman12661f12017-08-31 15:28:21 -0500512
Brandon Wymanba255532017-11-08 17:44:10 -0600513 report<PowerSupplyFanFault>(
514 metadata::RAW_STATUS(nv.get().c_str()),
515 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
516
517 faultFound = true;
518 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500519 }
520}
521
Brandon Wyman875b3632017-09-13 18:46:03 -0500522void PowerSupply::checkTemperatureFault(const uint16_t statusWord)
523{
524 using namespace witherspoon::pmbus;
525
526 // Due to how the PMBus core device driver sends a clear faults command
527 // the bit in STATUS_WORD will likely be cleared when we attempt to examine
528 // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the
529 // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with
530 // logging the over-temperature condition.
531 std::uint8_t statusTemperature = 0;
532 statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug);
Brandon Wyman50044ea2017-11-08 17:58:56 -0600533 if (temperatureFault < FAULT_COUNT)
Brandon Wyman875b3632017-09-13 18:46:03 -0500534 {
Brandon Wyman50044ea2017-11-08 17:58:56 -0600535 if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
536 (statusTemperature & status_temperature::OT_FAULT))
537 {
538 temperatureFault++;
539 }
540 else
541 {
542 if (temperatureFault > 0)
543 {
544 temperatureFault = 0;
545 }
546 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500547
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600548 if (!faultFound && (temperatureFault >= FAULT_COUNT))
Brandon Wyman50044ea2017-11-08 17:58:56 -0600549 {
550 // The power supply has had an over-temperature condition.
551 // This may not result in a shutdown if experienced for a short
552 // duration.
553 // This should not occur under normal conditions.
554 // The power supply may be faulty, or the paired supply may be
555 // putting out less current.
556 // Capture command responses with potentially relevant information,
557 // and call out the power supply reporting the condition.
558 util::NamesValues nv;
559 nv.add("STATUS_WORD", statusWord);
560 captureCmd(nv, STATUS_MFR, Type::Debug);
561 captureCmd(nv, STATUS_IOUT, Type::Debug);
562 nv.add("STATUS_TEMPERATURE", statusTemperature);
563 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman875b3632017-09-13 18:46:03 -0500564
Brandon Wyman50044ea2017-11-08 17:58:56 -0600565 using metadata = org::open_power::Witherspoon::Fault::
566 PowerSupplyTemperatureFault;
Brandon Wyman875b3632017-09-13 18:46:03 -0500567
Brandon Wyman50044ea2017-11-08 17:58:56 -0600568 report<PowerSupplyTemperatureFault>(
569 metadata::RAW_STATUS(nv.get().c_str()),
570 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
571
572 faultFound = true;
573 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500574 }
575}
576
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500577void PowerSupply::clearFaults()
578{
Brandon Wymane4af9802017-11-13 15:58:33 -0600579 readFail = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500580 readFailLogged = false;
Brandon Wymana3c675c2017-11-14 14:54:54 -0600581 inputFault = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500582 powerOnFault = 0;
Brandon Wymandd61be42017-11-07 18:38:54 -0600583 outputOCFault = 0;
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600584 outputOVFault = 0;
Brandon Wymanba255532017-11-08 17:44:10 -0600585 fanFault = 0;
Brandon Wyman50044ea2017-11-08 17:58:56 -0600586 temperatureFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500587 faultFound = false;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500588
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500589 return;
590}
591
Brandon Wyman43ce2082017-11-30 17:24:01 -0600592void PowerSupply::resolveError(const std::string& callout,
593 const std::string& message)
594{
Brandon Wyman01741f12017-12-01 17:22:08 -0600595 using EndpointList = std::vector<std::string>;
596
597 try
598 {
599 auto path = callout + "/fault";
600 // Get the service name from the mapper for the fault callout
601 auto service = util::getService(path,
602 ASSOCIATION_IFACE,
603 bus);
604
605 // Use getProperty utility function to get log entries (endpoints)
606 EndpointList logEntries;
Matt Spinler589e8722018-01-04 15:24:49 -0600607 util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service,
Brandon Wyman01741f12017-12-01 17:22:08 -0600608 bus, logEntries);
609
610 // It is possible that all such entries for this callout have since
611 // been deleted.
612 if (logEntries.empty())
613 {
614 return;
615 }
616
617 auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE,
618 bus);
619 if (logEntryService.empty())
620 {
621 return;
622 }
623
624 // go through each log entry that matches this callout path
625 std::string logMessage;
626 for (const auto& logEntry : logEntries)
627 {
628 // Check to see if this logEntry has a message that matches.
Matt Spinler589e8722018-01-04 15:24:49 -0600629 util::getProperty(LOGGING_IFACE, MESSAGE_PROP, logEntry,
Brandon Wyman01741f12017-12-01 17:22:08 -0600630 logEntryService, bus, logMessage);
631
632 if (message == logMessage)
633 {
634 // Log entry matches call out and message, set Resolved to true
635 bool resolved = true;
Matt Spinler589e8722018-01-04 15:24:49 -0600636 util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry,
Brandon Wyman01741f12017-12-01 17:22:08 -0600637 logEntryService, bus, resolved);
638 }
639
640 }
641
642 }
643 catch (std::exception& e)
644 {
645 log<level::INFO>("Failed to resolve error",
646 entry("CALLOUT=%s", callout.c_str()),
Matt Spinler0d09f292018-01-22 14:51:26 -0600647 entry("ERROR=%s", message.c_str()));
Brandon Wyman01741f12017-12-01 17:22:08 -0600648 }
649
Brandon Wyman43ce2082017-11-30 17:24:01 -0600650}
651
Matt Spinler234ce0d2018-01-04 15:06:57 -0600652void PowerSupply::updateInventory()
653{
Matt Spinler018a7bc2018-01-04 15:36:41 -0600654 using namespace witherspoon::pmbus;
655 using namespace sdbusplus::message;
656
657 // If any of these accesses fail, the fields will just be
658 // blank in the inventory. Leave logging ReadFailure errors
659 // to analyze() as it runs continuously and will most
660 // likely hit and threshold them first anyway. The
661 // readString() function will do the tracing of the failing
662 // path so this code doesn't need to.
663 std::string pn;
664 std::string sn;
665 std::string ccin;
666 std::string version;
667
668 if (present)
669 {
670 try
671 {
672 sn = pmbusIntf.readString(SERIAL_NUMBER, Type::HwmonDeviceDebug);
673 }
674 catch (ReadFailure& e) { }
675
676 try
677 {
678 pn = pmbusIntf.readString(PART_NUMBER, Type::HwmonDeviceDebug);
679 }
680 catch (ReadFailure& e) { }
681
682 try
683 {
684 ccin = pmbusIntf.readString(CCIN, Type::HwmonDeviceDebug);
685 }
686 catch (ReadFailure& e) { }
687
688 try
689 {
690 version = pmbusIntf.readString(FW_VERSION, Type::HwmonDeviceDebug);
691 }
692 catch (ReadFailure& e) { }
693 }
694
695 // Build the object map and send it to the inventory
696 using Properties = std::map<std::string, variant<std::string>>;
697 using Interfaces = std::map<std::string, Properties>;
698 using Object = std::map<object_path, Interfaces>;
699 Properties assetProps;
700 Properties versionProps;
701 Interfaces interfaces;
702 Object object;
703
704 assetProps.emplace(SN_PROP, sn);
705 assetProps.emplace(PN_PROP, pn);
706 assetProps.emplace(MODEL_PROP, ccin);
707 interfaces.emplace(ASSET_IFACE, std::move(assetProps));
708
709 versionProps.emplace(VERSION_PROP, version);
710 interfaces.emplace(VERSION_IFACE, std::move(versionProps));
711
712 //For Notify(), just send the relative path of the inventory
713 //object so remove the INVENTORY_OBJ_PATH prefix
714 auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH));
715
716 object.emplace(path, std::move(interfaces));
717
718 try
719 {
720 auto service = util::getService(
721 INVENTORY_OBJ_PATH,
722 INVENTORY_MGR_IFACE,
723 bus);
724
725 if (service.empty())
726 {
727 log<level::ERR>("Unable to get inventory manager service");
728 return;
729 }
730
731 auto method = bus.new_method_call(
732 service.c_str(),
733 INVENTORY_OBJ_PATH,
734 INVENTORY_MGR_IFACE,
735 "Notify");
736
737 method.append(std::move(object));
738
739 auto reply = bus.call(method);
740 if (reply.is_method_error())
741 {
742 log<level::ERR>(
743 "Unable to update power supply inventory properties",
744 entry("PATH=%s", path.c_str()));
745 }
746
747 // TODO: openbmc/openbmc#2756
748 // Calling Notify() with an enumerated property crashes inventory
749 // manager, so let it default to Unknown and now set it to the
750 // right value.
751 auto purpose = version::convertForMessage(
752 version::Version::VersionPurpose::Other);
753
754 util::setProperty(
755 VERSION_IFACE,
756 VERSION_PURPOSE_PROP,
757 inventoryPath,
758 service,
759 bus,
760 purpose);
761 }
762 catch (std::exception& e)
763 {
764 log<level::ERR>(
765 e.what(),
766 entry("PATH=%s", inventoryPath));
767 }
Matt Spinler234ce0d2018-01-04 15:06:57 -0600768}
769
Matt Spinlerd734e652018-01-18 14:31:15 -0600770void PowerSupply::syncHistory()
771{
772 using namespace witherspoon::gpio;
773
774 if (syncGPIODevPath.empty())
775 {
776 //Sync not implemented
777 return;
778 }
779
780 GPIO gpio{syncGPIODevPath,
781 static_cast<gpioNum_t>(syncGPIONumber),
782 Direction::output};
783
784 try
785 {
786 gpio.set(Value::low);
787
788 std::this_thread::sleep_for(std::chrono::milliseconds{5});
789
790 gpio.set(Value::high);
791
792 recordManager->clear();
793 }
794 catch (std::exception& e)
795 {
796 //Do nothing. There would already be a journal entry.
797 }
798}
799
Matt Spinler82384142018-01-18 14:15:03 -0600800void PowerSupply::enableHistory(const std::string& objectPath,
801 size_t numRecords,
802 const std::string& syncGPIOPath,
803 size_t syncGPIONum)
804{
805 historyObjectPath = objectPath;
806 syncGPIODevPath = syncGPIOPath;
807 syncGPIONumber = syncGPIONum;
808
809 recordManager = std::make_unique<history::RecordManager>(numRecords);
810
811 auto avgPath = historyObjectPath + '/' + history::Average::name;
812 auto maxPath = historyObjectPath + '/' + history::Maximum::name;
813
814 average = std::make_unique<history::Average>(bus, avgPath);
815
816 maximum = std::make_unique<history::Maximum>(bus, maxPath);
817}
818
Matt Spinlereb169fd2018-01-18 14:19:08 -0600819void PowerSupply::updateHistory()
820{
821 if (!recordManager)
822 {
823 //Not enabled
824 return;
825 }
826
827 //Read just the most recent average/max record
828 auto data = pmbusIntf.readBinary(
829 INPUT_HISTORY,
830 pmbus::Type::HwmonDeviceDebug,
831 history::RecordManager::RAW_RECORD_SIZE);
832
833 //Update D-Bus only if something changed (a new record ID, or cleared out)
834 auto changed = recordManager->add(data);
835 if (changed)
836 {
837 average->values(std::move(recordManager->getAverageRecords()));
838 maximum->values(std::move(recordManager->getMaximumRecords()));
839 }
840}
841
Brandon Wyman24e422f2017-07-25 19:40:14 -0500842}
843}
844}