blob: 3d7673cd8593e5cc628b0e6b0e8a7074109a11eb [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 Wymana3c675c2017-11-14 14:54:54 -0600296 inputFault++;
Brandon Wyman603cc002017-08-28 18:17:58 -0500297 }
298 else
299 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600300 if ((inputFault > 0) &&
Brandon Wymand20686a2017-11-01 17:45:23 -0500301 !(statusWord & status_word::INPUT_FAULT_WARN) &&
302 !(statusWord & status_word::VIN_UV_FAULT))
Brandon Wyman603cc002017-08-28 18:17:58 -0500303 {
Brandon Wymana3c675c2017-11-14 14:54:54 -0600304 inputFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500305 faultFound = false;
Brandon Wyman69591bd2017-11-01 18:07:23 -0500306
Brandon Wyman603cc002017-08-28 18:17:58 -0500307 log<level::INFO>("INPUT_FAULT_WARN cleared",
Brandon Wymana3c675c2017-11-14 14:54:54 -0600308 entry("POWERSUPPLY=%s", inventoryPath.c_str()));
Brandon Wyman69591bd2017-11-01 18:07:23 -0500309
Brandon Wyman08b05712017-11-30 17:53:56 -0600310 resolveError(inventoryPath,
311 std::string(PowerSupplyInputFault::errName));
312
Brandon Wyman69591bd2017-11-01 18:07:23 -0500313 if (powerOn)
314 {
315 // The power supply will not be immediately powered on after
316 // the input power is restored.
317 powerOn = false;
318 // Start up the timer that will set the state to indicate we
319 // are ready for the powered on fault checks.
320 powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
321 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500322 }
323 }
Brandon Wymana3c675c2017-11-14 14:54:54 -0600324
325 if (!faultFound && (inputFault >= FAULT_COUNT))
326 {
327 util::NamesValues nv;
328 nv.add("STATUS_WORD", statusWord);
329 captureCmd(nv, STATUS_INPUT, Type::Debug);
330
331 using metadata = org::open_power::Witherspoon::Fault::
332 PowerSupplyInputFault;
333
334 report<PowerSupplyInputFault>(
335 metadata::RAW_STATUS(nv.get().c_str()),
336 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
337 faultFound = true;
338 }
339
Brandon Wyman603cc002017-08-28 18:17:58 -0500340}
341
342void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord)
343{
344 using namespace witherspoon::pmbus;
345
Brandon Wyman593d24f2017-10-13 18:15:23 -0500346 if (powerOnFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500347 {
Brandon Wyman593d24f2017-10-13 18:15:23 -0500348 // Check PG# and UNIT_IS_OFF
349 if ((statusWord & status_word::POWER_GOOD_NEGATED) ||
350 (statusWord & status_word::UNIT_IS_OFF))
351 {
352 log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad",
353 entry("STATUS_WORD=0x%04X", statusWord));
354 powerOnFault++;
355 }
356 else
357 {
358 if (powerOnFault > 0)
359 {
360 log<level::INFO>("PGOOD and UNIT_IS_OFF bits good");
361 powerOnFault = 0;
362 }
363 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500364
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600365 if (!faultFound && (powerOnFault >= FAULT_COUNT))
Brandon Wyman593d24f2017-10-13 18:15:23 -0500366 {
Brandon Wyman3343e822017-11-03 16:54:11 -0500367 faultFound = true;
368
Brandon Wyman593d24f2017-10-13 18:15:23 -0500369 util::NamesValues nv;
370 nv.add("STATUS_WORD", statusWord);
371 captureCmd(nv, STATUS_INPUT, Type::Debug);
372 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
373 captureCmd(nv, status0Vout, Type::Debug);
374 captureCmd(nv, STATUS_IOUT, Type::Debug);
375 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500376
Brandon Wyman593d24f2017-10-13 18:15:23 -0500377 using metadata = org::open_power::Witherspoon::Fault::
378 PowerSupplyShouldBeOn;
Brandon Wyman603cc002017-08-28 18:17:58 -0500379
Brandon Wyman593d24f2017-10-13 18:15:23 -0500380 // A power supply is OFF (or pgood low) but should be on.
381 report<PowerSupplyShouldBeOn>(
382 metadata::RAW_STATUS(nv.get().c_str()),
383 metadata::CALLOUT_INVENTORY_PATH(
384 inventoryPath.c_str()));
385 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500386 }
387
388}
389
390void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord)
391{
392 using namespace witherspoon::pmbus;
393
Brandon Wymandd61be42017-11-07 18:38:54 -0600394 if (outputOCFault < FAULT_COUNT)
Brandon Wyman603cc002017-08-28 18:17:58 -0500395 {
Brandon Wymandd61be42017-11-07 18:38:54 -0600396 // Check for an output overcurrent fault.
397 if ((statusWord & status_word::IOUT_OC_FAULT))
398 {
399 outputOCFault++;
400 }
401 else
402 {
403 if (outputOCFault > 0)
404 {
405 outputOCFault = 0;
406 }
407 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500408
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600409 if (!faultFound && (outputOCFault >= FAULT_COUNT))
Brandon Wymandd61be42017-11-07 18:38:54 -0600410 {
411 util::NamesValues nv;
412 nv.add("STATUS_WORD", statusWord);
413 captureCmd(nv, STATUS_INPUT, Type::Debug);
414 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
415 captureCmd(nv, status0Vout, Type::Debug);
416 captureCmd(nv, STATUS_IOUT, Type::Debug);
417 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wyman603cc002017-08-28 18:17:58 -0500418
Brandon Wymandd61be42017-11-07 18:38:54 -0600419 using metadata = org::open_power::Witherspoon::Fault::
420 PowerSupplyOutputOvercurrent;
Brandon Wyman603cc002017-08-28 18:17:58 -0500421
Brandon Wymandd61be42017-11-07 18:38:54 -0600422 report<PowerSupplyOutputOvercurrent>(
423 metadata::RAW_STATUS(nv.get().c_str()),
424 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
425
426 faultFound = true;
427 }
Brandon Wyman603cc002017-08-28 18:17:58 -0500428 }
429}
430
Brandon Wymanab05c072017-08-30 18:26:41 -0500431void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord)
432{
433 using namespace witherspoon::pmbus;
434
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600435 if (outputOVFault < FAULT_COUNT)
Brandon Wymanab05c072017-08-30 18:26:41 -0500436 {
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600437 // Check for an output overvoltage fault.
438 if (statusWord & status_word::VOUT_OV_FAULT)
439 {
440 outputOVFault++;
441 }
442 else
443 {
444 if (outputOVFault > 0)
445 {
446 outputOVFault = 0;
447 }
448 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500449
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600450 if (!faultFound && (outputOVFault >= FAULT_COUNT))
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600451 {
452 util::NamesValues nv;
453 nv.add("STATUS_WORD", statusWord);
454 captureCmd(nv, STATUS_INPUT, Type::Debug);
455 auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0);
456 captureCmd(nv, status0Vout, Type::Debug);
457 captureCmd(nv, STATUS_IOUT, Type::Debug);
458 captureCmd(nv, STATUS_MFR, Type::Debug);
Brandon Wymanab05c072017-08-30 18:26:41 -0500459
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600460 using metadata = org::open_power::Witherspoon::Fault::
461 PowerSupplyOutputOvervoltage;
Brandon Wymanab05c072017-08-30 18:26:41 -0500462
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600463 report<PowerSupplyOutputOvervoltage>(
464 metadata::RAW_STATUS(nv.get().c_str()),
465 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
466
467 faultFound = true;
468 }
Brandon Wymanab05c072017-08-30 18:26:41 -0500469 }
470}
471
Brandon Wyman12661f12017-08-31 15:28:21 -0500472void PowerSupply::checkFanFault(const uint16_t statusWord)
473{
474 using namespace witherspoon::pmbus;
475
Brandon Wymanba255532017-11-08 17:44:10 -0600476 if (fanFault < FAULT_COUNT)
Brandon Wyman12661f12017-08-31 15:28:21 -0500477 {
Brandon Wymanba255532017-11-08 17:44:10 -0600478 // Check for a fan fault or warning condition
479 if (statusWord & status_word::FAN_FAULT)
480 {
481 fanFault++;
482 }
483 else
484 {
485 if (fanFault > 0)
486 {
487 fanFault = 0;
488 }
489 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500490
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600491 if (!faultFound && (fanFault >= FAULT_COUNT))
Brandon Wymanba255532017-11-08 17:44:10 -0600492 {
493 util::NamesValues nv;
494 nv.add("STATUS_WORD", statusWord);
495 captureCmd(nv, STATUS_MFR, Type::Debug);
496 captureCmd(nv, STATUS_TEMPERATURE, Type::Debug);
497 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman12661f12017-08-31 15:28:21 -0500498
Brandon Wymanba255532017-11-08 17:44:10 -0600499 using metadata = org::open_power::Witherspoon::Fault::
500 PowerSupplyFanFault;
Brandon Wyman12661f12017-08-31 15:28:21 -0500501
Brandon Wymanba255532017-11-08 17:44:10 -0600502 report<PowerSupplyFanFault>(
503 metadata::RAW_STATUS(nv.get().c_str()),
504 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
505
506 faultFound = true;
507 }
Brandon Wyman12661f12017-08-31 15:28:21 -0500508 }
509}
510
Brandon Wyman875b3632017-09-13 18:46:03 -0500511void PowerSupply::checkTemperatureFault(const uint16_t statusWord)
512{
513 using namespace witherspoon::pmbus;
514
515 // Due to how the PMBus core device driver sends a clear faults command
516 // the bit in STATUS_WORD will likely be cleared when we attempt to examine
517 // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the
518 // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with
519 // logging the over-temperature condition.
520 std::uint8_t statusTemperature = 0;
521 statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug);
Brandon Wyman50044ea2017-11-08 17:58:56 -0600522 if (temperatureFault < FAULT_COUNT)
Brandon Wyman875b3632017-09-13 18:46:03 -0500523 {
Brandon Wyman50044ea2017-11-08 17:58:56 -0600524 if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
525 (statusTemperature & status_temperature::OT_FAULT))
526 {
527 temperatureFault++;
528 }
529 else
530 {
531 if (temperatureFault > 0)
532 {
533 temperatureFault = 0;
534 }
535 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500536
Brandon Wymane2fc7aa2017-11-13 17:37:10 -0600537 if (!faultFound && (temperatureFault >= FAULT_COUNT))
Brandon Wyman50044ea2017-11-08 17:58:56 -0600538 {
539 // The power supply has had an over-temperature condition.
540 // This may not result in a shutdown if experienced for a short
541 // duration.
542 // This should not occur under normal conditions.
543 // The power supply may be faulty, or the paired supply may be
544 // putting out less current.
545 // Capture command responses with potentially relevant information,
546 // and call out the power supply reporting the condition.
547 util::NamesValues nv;
548 nv.add("STATUS_WORD", statusWord);
549 captureCmd(nv, STATUS_MFR, Type::Debug);
550 captureCmd(nv, STATUS_IOUT, Type::Debug);
551 nv.add("STATUS_TEMPERATURE", statusTemperature);
552 captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
Brandon Wyman875b3632017-09-13 18:46:03 -0500553
Brandon Wyman50044ea2017-11-08 17:58:56 -0600554 using metadata = org::open_power::Witherspoon::Fault::
555 PowerSupplyTemperatureFault;
Brandon Wyman875b3632017-09-13 18:46:03 -0500556
Brandon Wyman50044ea2017-11-08 17:58:56 -0600557 report<PowerSupplyTemperatureFault>(
558 metadata::RAW_STATUS(nv.get().c_str()),
559 metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
560
561 faultFound = true;
562 }
Brandon Wyman875b3632017-09-13 18:46:03 -0500563 }
564}
565
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500566void PowerSupply::clearFaults()
567{
Brandon Wymane4af9802017-11-13 15:58:33 -0600568 readFail = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500569 readFailLogged = false;
Brandon Wymana3c675c2017-11-14 14:54:54 -0600570 inputFault = 0;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500571 powerOnFault = 0;
Brandon Wymandd61be42017-11-07 18:38:54 -0600572 outputOCFault = 0;
Brandon Wyman2ab319b2017-11-08 17:34:59 -0600573 outputOVFault = 0;
Brandon Wymanba255532017-11-08 17:44:10 -0600574 fanFault = 0;
Brandon Wyman50044ea2017-11-08 17:58:56 -0600575 temperatureFault = 0;
Brandon Wyman3343e822017-11-03 16:54:11 -0500576 faultFound = false;
Brandon Wyman6ccce0b2017-10-26 15:13:10 -0500577
Brandon Wyman1db9a9e2017-07-26 18:50:22 -0500578 return;
579}
580
Brandon Wyman43ce2082017-11-30 17:24:01 -0600581void PowerSupply::resolveError(const std::string& callout,
582 const std::string& message)
583{
Brandon Wyman01741f12017-12-01 17:22:08 -0600584 using EndpointList = std::vector<std::string>;
585
586 try
587 {
588 auto path = callout + "/fault";
589 // Get the service name from the mapper for the fault callout
590 auto service = util::getService(path,
591 ASSOCIATION_IFACE,
592 bus);
593
594 // Use getProperty utility function to get log entries (endpoints)
595 EndpointList logEntries;
Matt Spinler589e8722018-01-04 15:24:49 -0600596 util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service,
Brandon Wyman01741f12017-12-01 17:22:08 -0600597 bus, logEntries);
598
599 // It is possible that all such entries for this callout have since
600 // been deleted.
601 if (logEntries.empty())
602 {
603 return;
604 }
605
606 auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE,
607 bus);
608 if (logEntryService.empty())
609 {
610 return;
611 }
612
613 // go through each log entry that matches this callout path
614 std::string logMessage;
615 for (const auto& logEntry : logEntries)
616 {
617 // Check to see if this logEntry has a message that matches.
Matt Spinler589e8722018-01-04 15:24:49 -0600618 util::getProperty(LOGGING_IFACE, MESSAGE_PROP, logEntry,
Brandon Wyman01741f12017-12-01 17:22:08 -0600619 logEntryService, bus, logMessage);
620
621 if (message == logMessage)
622 {
623 // Log entry matches call out and message, set Resolved to true
624 bool resolved = true;
Matt Spinler589e8722018-01-04 15:24:49 -0600625 util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry,
Brandon Wyman01741f12017-12-01 17:22:08 -0600626 logEntryService, bus, resolved);
627 }
628
629 }
630
631 }
632 catch (std::exception& e)
633 {
634 log<level::INFO>("Failed to resolve error",
635 entry("CALLOUT=%s", callout.c_str()),
Matt Spinler0d09f292018-01-22 14:51:26 -0600636 entry("ERROR=%s", message.c_str()));
Brandon Wyman01741f12017-12-01 17:22:08 -0600637 }
638
Brandon Wyman43ce2082017-11-30 17:24:01 -0600639}
640
Matt Spinler234ce0d2018-01-04 15:06:57 -0600641void PowerSupply::updateInventory()
642{
Matt Spinler018a7bc2018-01-04 15:36:41 -0600643 using namespace witherspoon::pmbus;
644 using namespace sdbusplus::message;
645
646 // If any of these accesses fail, the fields will just be
647 // blank in the inventory. Leave logging ReadFailure errors
648 // to analyze() as it runs continuously and will most
649 // likely hit and threshold them first anyway. The
650 // readString() function will do the tracing of the failing
651 // path so this code doesn't need to.
652 std::string pn;
653 std::string sn;
654 std::string ccin;
655 std::string version;
656
657 if (present)
658 {
659 try
660 {
661 sn = pmbusIntf.readString(SERIAL_NUMBER, Type::HwmonDeviceDebug);
662 }
663 catch (ReadFailure& e) { }
664
665 try
666 {
667 pn = pmbusIntf.readString(PART_NUMBER, Type::HwmonDeviceDebug);
668 }
669 catch (ReadFailure& e) { }
670
671 try
672 {
673 ccin = pmbusIntf.readString(CCIN, Type::HwmonDeviceDebug);
674 }
675 catch (ReadFailure& e) { }
676
677 try
678 {
679 version = pmbusIntf.readString(FW_VERSION, Type::HwmonDeviceDebug);
680 }
681 catch (ReadFailure& e) { }
682 }
683
684 // Build the object map and send it to the inventory
685 using Properties = std::map<std::string, variant<std::string>>;
686 using Interfaces = std::map<std::string, Properties>;
687 using Object = std::map<object_path, Interfaces>;
688 Properties assetProps;
689 Properties versionProps;
690 Interfaces interfaces;
691 Object object;
692
693 assetProps.emplace(SN_PROP, sn);
694 assetProps.emplace(PN_PROP, pn);
695 assetProps.emplace(MODEL_PROP, ccin);
696 interfaces.emplace(ASSET_IFACE, std::move(assetProps));
697
698 versionProps.emplace(VERSION_PROP, version);
699 interfaces.emplace(VERSION_IFACE, std::move(versionProps));
700
701 //For Notify(), just send the relative path of the inventory
702 //object so remove the INVENTORY_OBJ_PATH prefix
703 auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH));
704
705 object.emplace(path, std::move(interfaces));
706
707 try
708 {
709 auto service = util::getService(
710 INVENTORY_OBJ_PATH,
711 INVENTORY_MGR_IFACE,
712 bus);
713
714 if (service.empty())
715 {
716 log<level::ERR>("Unable to get inventory manager service");
717 return;
718 }
719
720 auto method = bus.new_method_call(
721 service.c_str(),
722 INVENTORY_OBJ_PATH,
723 INVENTORY_MGR_IFACE,
724 "Notify");
725
726 method.append(std::move(object));
727
728 auto reply = bus.call(method);
729 if (reply.is_method_error())
730 {
731 log<level::ERR>(
732 "Unable to update power supply inventory properties",
733 entry("PATH=%s", path.c_str()));
734 }
735
736 // TODO: openbmc/openbmc#2756
737 // Calling Notify() with an enumerated property crashes inventory
738 // manager, so let it default to Unknown and now set it to the
739 // right value.
740 auto purpose = version::convertForMessage(
741 version::Version::VersionPurpose::Other);
742
743 util::setProperty(
744 VERSION_IFACE,
745 VERSION_PURPOSE_PROP,
746 inventoryPath,
747 service,
748 bus,
749 purpose);
750 }
751 catch (std::exception& e)
752 {
753 log<level::ERR>(
754 e.what(),
755 entry("PATH=%s", inventoryPath));
756 }
Matt Spinler234ce0d2018-01-04 15:06:57 -0600757}
758
Matt Spinlerd734e652018-01-18 14:31:15 -0600759void PowerSupply::syncHistory()
760{
761 using namespace witherspoon::gpio;
762
763 if (syncGPIODevPath.empty())
764 {
765 //Sync not implemented
766 return;
767 }
768
769 GPIO gpio{syncGPIODevPath,
770 static_cast<gpioNum_t>(syncGPIONumber),
771 Direction::output};
772
773 try
774 {
775 gpio.set(Value::low);
776
777 std::this_thread::sleep_for(std::chrono::milliseconds{5});
778
779 gpio.set(Value::high);
780
781 recordManager->clear();
782 }
783 catch (std::exception& e)
784 {
785 //Do nothing. There would already be a journal entry.
786 }
787}
788
Matt Spinler82384142018-01-18 14:15:03 -0600789void PowerSupply::enableHistory(const std::string& objectPath,
790 size_t numRecords,
791 const std::string& syncGPIOPath,
792 size_t syncGPIONum)
793{
794 historyObjectPath = objectPath;
795 syncGPIODevPath = syncGPIOPath;
796 syncGPIONumber = syncGPIONum;
797
798 recordManager = std::make_unique<history::RecordManager>(numRecords);
799
800 auto avgPath = historyObjectPath + '/' + history::Average::name;
801 auto maxPath = historyObjectPath + '/' + history::Maximum::name;
802
803 average = std::make_unique<history::Average>(bus, avgPath);
804
805 maximum = std::make_unique<history::Maximum>(bus, maxPath);
806}
807
Matt Spinlereb169fd2018-01-18 14:19:08 -0600808void PowerSupply::updateHistory()
809{
810 if (!recordManager)
811 {
812 //Not enabled
813 return;
814 }
815
816 //Read just the most recent average/max record
817 auto data = pmbusIntf.readBinary(
818 INPUT_HISTORY,
819 pmbus::Type::HwmonDeviceDebug,
820 history::RecordManager::RAW_RECORD_SIZE);
821
822 //Update D-Bus only if something changed (a new record ID, or cleared out)
823 auto changed = recordManager->add(data);
824 if (changed)
825 {
826 average->values(std::move(recordManager->getAverageRecords()));
827 maximum->values(std::move(recordManager->getMaximumRecords()));
828 }
829}
830
Brandon Wyman24e422f2017-07-25 19:40:14 -0500831}
832}
833}