Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 1 | /** |
| 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 | */ |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 18 | #include "power_supply.hpp" |
| 19 | |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 20 | #include "elog-errors.hpp" |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 21 | #include "gpio.hpp" |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 22 | #include "names_values.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 23 | #include "pmbus.hpp" |
Lei YU | cfc040c | 2019-10-29 17:10:26 +0800 | [diff] [blame] | 24 | #include "types.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 25 | #include "utility.hpp" |
| 26 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 27 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 28 | #include <phosphor-logging/log.hpp> |
| 29 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 30 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
| 31 | |
Brandon Wyman | d1bc4ce | 2019-12-13 14:20:34 -0600 | [diff] [blame] | 32 | #include <functional> |
| 33 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 34 | namespace phosphor |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 35 | { |
| 36 | namespace power |
| 37 | { |
| 38 | namespace psu |
| 39 | { |
| 40 | |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 41 | using namespace phosphor::logging; |
| 42 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
| 43 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 44 | namespace version = sdbusplus::xyz::openbmc_project::Software::server; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 45 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 46 | PowerSupply::PowerSupply(const std::string& name, size_t inst, |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 47 | const std::string& objpath, const std::string& invpath, |
| 48 | sdbusplus::bus::bus& bus, const sdeventplus::Event& e, |
| 49 | std::chrono::seconds& t, std::chrono::seconds& p) : |
| 50 | Device(name, inst), |
| 51 | monitorPath(objpath), pmbusIntf(objpath), |
| 52 | inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), presentInterval(p), |
| 53 | presentTimer(e, std::bind([this]() { |
| 54 | // The hwmon path may have changed. |
| 55 | pmbusIntf.findHwmonDir(); |
| 56 | this->present = true; |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 57 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 58 | // Sync the INPUT_HISTORY data for all PSs |
| 59 | syncHistory(); |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 60 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 61 | // Update the inventory for the new device |
| 62 | updateInventory(); |
| 63 | })), |
| 64 | powerOnInterval(t), |
| 65 | powerOnTimer(e, std::bind([this]() { this->powerOn = true; })) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 66 | { |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 67 | getAccessType(); |
| 68 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 69 | using namespace sdbusplus::bus; |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 70 | using namespace phosphor::pmbus; |
Aatir Manzur | 817f8a7 | 2019-08-07 07:42:15 -0500 | [diff] [blame] | 71 | std::uint16_t statusWord = 0; |
| 72 | try |
| 73 | { |
| 74 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 75 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
| 76 | if (!((statusWord & status_word::INPUT_FAULT_WARN) || |
| 77 | (statusWord & status_word::VIN_UV_FAULT))) |
| 78 | { |
| 79 | resolveError(inventoryPath, |
| 80 | std::string(PowerSupplyInputFault::errName)); |
| 81 | } |
| 82 | } |
| 83 | catch (ReadFailure& e) |
| 84 | { |
| 85 | log<level::INFO>("Unable to read the 2 byte STATUS_WORD value to check " |
| 86 | "for power-supply input faults."); |
| 87 | } |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 88 | presentMatch = std::make_unique<match_t>( |
| 89 | bus, match::rules::propertiesChanged(inventoryPath, INVENTORY_IFACE), |
| 90 | [this](auto& msg) { this->inventoryChanged(msg); }); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 91 | // Get initial presence state. |
Brandon Wyman | 253dc9b | 2017-08-12 13:45:52 -0500 | [diff] [blame] | 92 | updatePresence(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 93 | |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 94 | // Write the SN, PN, etc to the inventory |
| 95 | updateInventory(); |
| 96 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 97 | // Subscribe to power state changes |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 98 | powerOnMatch = std::make_unique<match_t>( |
| 99 | bus, match::rules::propertiesChanged(POWER_OBJ_PATH, POWER_IFACE), |
| 100 | [this](auto& msg) { this->powerStateChanged(msg); }); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 101 | // Get initial power state. |
| 102 | updatePowerState(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 103 | } |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 104 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 105 | void PowerSupply::getAccessType() |
| 106 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 107 | using namespace phosphor::power::util; |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 108 | fruJson = loadJSONFromFile(PSU_JSON_PATH); |
| 109 | if (fruJson == nullptr) |
| 110 | { |
| 111 | log<level::ERR>("InternalFailure when parsing the JSON file"); |
| 112 | return; |
| 113 | } |
Lei YU | 4070546 | 2019-10-09 17:07:11 +0800 | [diff] [blame] | 114 | inventoryPMBusAccessType = getPMBusAccessType(fruJson); |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 115 | } |
| 116 | |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 117 | void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd, |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 118 | phosphor::pmbus::Type type) |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 119 | { |
| 120 | if (pmbusIntf.exists(cmd, type)) |
| 121 | { |
| 122 | try |
| 123 | { |
| 124 | auto val = pmbusIntf.read(cmd, type); |
| 125 | nv.add(cmd, val); |
| 126 | } |
| 127 | catch (std::exception& e) |
| 128 | { |
Joseph Reynolds | 5b48596 | 2018-05-17 16:05:06 -0500 | [diff] [blame] | 129 | log<level::INFO>("Unable to capture metadata", |
| 130 | entry("CMD=%s", cmd.c_str())); |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 134 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 135 | void PowerSupply::analyze() |
| 136 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 137 | using namespace phosphor::pmbus; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 138 | |
| 139 | try |
| 140 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 141 | if (present) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 142 | { |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 143 | std::uint16_t statusWord = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 144 | |
| 145 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 146 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 147 | readFail = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 148 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 149 | checkInputFault(statusWord); |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 150 | |
Brandon Wyman | 654eb6e | 2018-02-14 14:55:47 -0600 | [diff] [blame] | 151 | if (powerOn && (inputFault == 0) && !faultFound) |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 152 | { |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 153 | checkFanFault(statusWord); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 154 | checkTemperatureFault(statusWord); |
Brandon Wyman | cfa032b | 2017-09-25 17:37:50 -0500 | [diff] [blame] | 155 | checkOutputOvervoltageFault(statusWord); |
| 156 | checkCurrentOutOverCurrentFault(statusWord); |
| 157 | checkPGOrUnitOffFault(statusWord); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 158 | } |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 159 | |
| 160 | updateHistory(); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | catch (ReadFailure& e) |
| 164 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 165 | if (readFail < FAULT_COUNT) |
| 166 | { |
| 167 | readFail++; |
| 168 | } |
| 169 | |
| 170 | if (!readFailLogged && readFail >= FAULT_COUNT) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 171 | { |
| 172 | commit<ReadFailure>(); |
| 173 | readFailLogged = true; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 180 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 181 | { |
| 182 | std::string msgSensor; |
| 183 | std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData; |
| 184 | msg.read(msgSensor, msgData); |
| 185 | |
| 186 | // Check if it was the Present property that changed. |
| 187 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 188 | if (valPropMap != msgData.end()) |
| 189 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 190 | if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second)) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 191 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 192 | clearFaults(); |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 193 | presentTimer.restartOnce(presentInterval); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 194 | } |
| 195 | else |
| 196 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 197 | present = false; |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 198 | presentTimer.setEnabled(false); |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 199 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 200 | // Clear out the now outdated inventory properties |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 201 | updateInventory(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | void PowerSupply::updatePresence() |
| 209 | { |
| 210 | // Use getProperty utility function to get presence status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 211 | std::string service = "xyz.openbmc_project.Inventory.Manager"; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 212 | util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath, service, |
| 213 | bus, this->present); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 216 | void PowerSupply::powerStateChanged(sdbusplus::message::message& msg) |
| 217 | { |
| 218 | int32_t state = 0; |
| 219 | std::string msgSensor; |
William A. Kennington III | ac9d5c3 | 2018-11-12 14:58:39 -0800 | [diff] [blame] | 220 | std::map<std::string, sdbusplus::message::variant<int32_t>> msgData; |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 221 | msg.read(msgSensor, msgData); |
| 222 | |
| 223 | // Check if it was the Present property that changed. |
| 224 | auto valPropMap = msgData.find("state"); |
| 225 | if (valPropMap != msgData.end()) |
| 226 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 227 | state = |
| 228 | sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 229 | |
| 230 | // Power is on when state=1. Set the fault logged variables to false |
| 231 | // and start the power on timer when the state changes to 1. |
| 232 | if (state) |
| 233 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 234 | clearFaults(); |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 235 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 236 | } |
| 237 | else |
| 238 | { |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 239 | powerOnTimer.setEnabled(false); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 240 | powerOn = false; |
| 241 | } |
| 242 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void PowerSupply::updatePowerState() |
| 246 | { |
Lei YU | cfc040c | 2019-10-29 17:10:26 +0800 | [diff] [blame] | 247 | powerOn = util::isPoweredOn(bus); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 248 | } |
| 249 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 250 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 251 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 252 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 253 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 254 | if ((inputFault < FAULT_COUNT) && |
| 255 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 256 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 257 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 258 | if (inputFault == 0) |
| 259 | { |
| 260 | log<level::INFO>("INPUT or VIN_UV fault", |
| 261 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 262 | } |
| 263 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 264 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 265 | } |
| 266 | else |
| 267 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 268 | if ((inputFault > 0) && !(statusWord & status_word::INPUT_FAULT_WARN) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 269 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 270 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 271 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 272 | faultFound = false; |
Brandon Wyman | 7502f6c | 2018-02-12 20:20:39 -0600 | [diff] [blame] | 273 | // When an input fault occurs, the power supply cannot be on. |
| 274 | // However, the check for the case where the power supply should be |
| 275 | // on will stop when there is a fault found. |
| 276 | // Clear the powerOnFault when the inputFault is cleared to reset |
| 277 | // the powerOnFault de-glitching. |
| 278 | powerOnFault = 0; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 279 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 280 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 281 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 282 | |
Brandon Wyman | 08b0571 | 2017-11-30 17:53:56 -0600 | [diff] [blame] | 283 | resolveError(inventoryPath, |
| 284 | std::string(PowerSupplyInputFault::errName)); |
| 285 | |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 286 | if (powerOn) |
| 287 | { |
| 288 | // The power supply will not be immediately powered on after |
| 289 | // the input power is restored. |
| 290 | powerOn = false; |
| 291 | // Start up the timer that will set the state to indicate we |
| 292 | // are ready for the powered on fault checks. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 293 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 294 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 295 | } |
| 296 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 297 | |
| 298 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 299 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 300 | // If the power is on, report the fault in an error log entry. |
| 301 | if (powerOn) |
| 302 | { |
| 303 | util::NamesValues nv; |
| 304 | nv.add("STATUS_WORD", statusWord); |
| 305 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 306 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 307 | using metadata = |
| 308 | org::open_power::Witherspoon::Fault::PowerSupplyInputFault; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 309 | |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 310 | report<PowerSupplyInputFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 311 | metadata::RAW_STATUS(nv.get().c_str()), |
| 312 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 313 | |
| 314 | faultFound = true; |
| 315 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 316 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 320 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 321 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 322 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 323 | if (powerOnFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 324 | { |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 325 | // 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 Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 341 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 342 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 343 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 344 | faultFound = true; |
| 345 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 346 | 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 Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 353 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 354 | using metadata = |
| 355 | org::open_power::Witherspoon::Fault::PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 356 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 357 | // A power supply is OFF (or pgood low) but should be on. |
| 358 | report<PowerSupplyShouldBeOn>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 359 | metadata::RAW_STATUS(nv.get().c_str()), |
| 360 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 361 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 362 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 366 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 367 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 368 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 369 | if (outputOCFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 370 | { |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 371 | // Check for an output overcurrent fault. |
| 372 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 373 | { |
| 374 | outputOCFault++; |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | if (outputOCFault > 0) |
| 379 | { |
| 380 | outputOCFault = 0; |
| 381 | } |
| 382 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 383 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 384 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 385 | { |
| 386 | util::NamesValues nv; |
| 387 | nv.add("STATUS_WORD", statusWord); |
| 388 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 389 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 390 | captureCmd(nv, status0Vout, Type::Debug); |
| 391 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 392 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 393 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 394 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 395 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 396 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 397 | report<PowerSupplyOutputOvercurrent>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 398 | metadata::RAW_STATUS(nv.get().c_str()), |
| 399 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 400 | |
| 401 | faultFound = true; |
| 402 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 406 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 407 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 408 | using namespace phosphor::pmbus; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 409 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 410 | if (outputOVFault < FAULT_COUNT) |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 411 | { |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 412 | // Check for an output overvoltage fault. |
| 413 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 414 | { |
| 415 | outputOVFault++; |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | if (outputOVFault > 0) |
| 420 | { |
| 421 | outputOVFault = 0; |
| 422 | } |
| 423 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 424 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 425 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 426 | { |
| 427 | util::NamesValues nv; |
| 428 | nv.add("STATUS_WORD", statusWord); |
| 429 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 430 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 431 | captureCmd(nv, status0Vout, Type::Debug); |
| 432 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 433 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 434 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 435 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 436 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 437 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 438 | report<PowerSupplyOutputOvervoltage>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 439 | metadata::RAW_STATUS(nv.get().c_str()), |
| 440 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 441 | |
| 442 | faultFound = true; |
| 443 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 447 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 448 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 449 | using namespace phosphor::pmbus; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 450 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 451 | if (fanFault < FAULT_COUNT) |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 452 | { |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 453 | // Check for a fan fault or warning condition |
| 454 | if (statusWord & status_word::FAN_FAULT) |
| 455 | { |
| 456 | fanFault++; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | if (fanFault > 0) |
| 461 | { |
| 462 | fanFault = 0; |
| 463 | } |
| 464 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 465 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 466 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 467 | { |
| 468 | util::NamesValues nv; |
| 469 | nv.add("STATUS_WORD", statusWord); |
| 470 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 471 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 472 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 473 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 474 | using metadata = |
| 475 | org::open_power::Witherspoon::Fault::PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 476 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 477 | report<PowerSupplyFanFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 478 | metadata::RAW_STATUS(nv.get().c_str()), |
| 479 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 480 | |
| 481 | faultFound = true; |
| 482 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 486 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 487 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 488 | using namespace phosphor::pmbus; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 489 | |
| 490 | // Due to how the PMBus core device driver sends a clear faults command |
| 491 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 492 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 493 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 494 | // logging the over-temperature condition. |
| 495 | std::uint8_t statusTemperature = 0; |
| 496 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 497 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 498 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 499 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 500 | (statusTemperature & status_temperature::OT_FAULT)) |
| 501 | { |
| 502 | temperatureFault++; |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | if (temperatureFault > 0) |
| 507 | { |
| 508 | temperatureFault = 0; |
| 509 | } |
| 510 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 511 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 512 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 513 | { |
| 514 | // The power supply has had an over-temperature condition. |
| 515 | // This may not result in a shutdown if experienced for a short |
| 516 | // duration. |
| 517 | // This should not occur under normal conditions. |
| 518 | // The power supply may be faulty, or the paired supply may be |
| 519 | // putting out less current. |
| 520 | // Capture command responses with potentially relevant information, |
| 521 | // and call out the power supply reporting the condition. |
| 522 | util::NamesValues nv; |
| 523 | nv.add("STATUS_WORD", statusWord); |
| 524 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 525 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 526 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 527 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 528 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 529 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 530 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 531 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 532 | report<PowerSupplyTemperatureFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 533 | metadata::RAW_STATUS(nv.get().c_str()), |
| 534 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 535 | |
| 536 | faultFound = true; |
| 537 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 541 | void PowerSupply::clearFaults() |
| 542 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 543 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 544 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 545 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 546 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 547 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 548 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 549 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 550 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 551 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 552 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 556 | void PowerSupply::resolveError(const std::string& callout, |
| 557 | const std::string& message) |
| 558 | { |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 559 | using EndpointList = std::vector<std::string>; |
| 560 | |
| 561 | try |
| 562 | { |
| 563 | auto path = callout + "/fault"; |
| 564 | // Get the service name from the mapper for the fault callout |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 565 | auto service = util::getService(path, ASSOCIATION_IFACE, bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 566 | |
| 567 | // Use getProperty utility function to get log entries (endpoints) |
| 568 | EndpointList logEntries; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 569 | util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service, bus, |
| 570 | logEntries); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 571 | |
| 572 | // It is possible that all such entries for this callout have since |
| 573 | // been deleted. |
| 574 | if (logEntries.empty()) |
| 575 | { |
| 576 | return; |
| 577 | } |
| 578 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 579 | auto logEntryService = |
| 580 | util::getService(logEntries[0], LOGGING_IFACE, bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 581 | if (logEntryService.empty()) |
| 582 | { |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | // go through each log entry that matches this callout path |
| 587 | std::string logMessage; |
| 588 | for (const auto& logEntry : logEntries) |
| 589 | { |
| 590 | // Check to see if this logEntry has a message that matches. |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 591 | util::getProperty(LOGGING_IFACE, MESSAGE_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 592 | logEntryService, bus, logMessage); |
| 593 | |
| 594 | if (message == logMessage) |
| 595 | { |
| 596 | // Log entry matches call out and message, set Resolved to true |
| 597 | bool resolved = true; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 598 | util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 599 | logEntryService, bus, resolved); |
| 600 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 601 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 602 | } |
| 603 | catch (std::exception& e) |
| 604 | { |
| 605 | log<level::INFO>("Failed to resolve error", |
| 606 | entry("CALLOUT=%s", callout.c_str()), |
Matt Spinler | 0d09f29 | 2018-01-22 14:51:26 -0600 | [diff] [blame] | 607 | entry("ERROR=%s", message.c_str())); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 608 | } |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 609 | } |
| 610 | |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 611 | void PowerSupply::updateInventory() |
| 612 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 613 | using namespace phosphor::pmbus; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 614 | using namespace sdbusplus::message; |
| 615 | |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 616 | // Build the object map and send it to the inventory |
| 617 | using Properties = std::map<std::string, variant<std::string>>; |
| 618 | using Interfaces = std::map<std::string, Properties>; |
| 619 | using Object = std::map<object_path, Interfaces>; |
| 620 | Properties assetProps; |
| 621 | Properties versionProps; |
| 622 | Interfaces interfaces; |
| 623 | Object object; |
| 624 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 625 | // If any of these accesses fail, the fields will just be |
| 626 | // blank in the inventory. Leave logging ReadFailure errors |
| 627 | // to analyze() as it runs continuously and will most |
| 628 | // likely hit and threshold them first anyway. The |
| 629 | // readString() function will do the tracing of the failing |
| 630 | // path so this code doesn't need to. |
| 631 | for (const auto& fru : fruJson.at("fruConfigs")) |
| 632 | { |
| 633 | if (fru.at("interface") == ASSET_IFACE) |
| 634 | { |
| 635 | try |
| 636 | { |
| 637 | assetProps.emplace( |
| 638 | fru.at("propertyName"), |
| 639 | present ? pmbusIntf.readString(fru.at("fileName"), |
| 640 | inventoryPMBusAccessType) |
| 641 | : ""); |
| 642 | } |
| 643 | catch (ReadFailure& e) |
| 644 | { |
| 645 | } |
| 646 | } |
| 647 | else if (fru.at("interface") == VERSION_IFACE) |
| 648 | { |
| 649 | try |
| 650 | { |
| 651 | versionProps.emplace( |
| 652 | fru.at("propertyName"), |
| 653 | present ? pmbusIntf.readString(fru.at("fileName"), |
| 654 | inventoryPMBusAccessType) |
| 655 | : ""); |
| 656 | } |
| 657 | catch (const std::exception& e) |
| 658 | { |
| 659 | } |
| 660 | } |
| 661 | } |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 662 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 663 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 664 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 665 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 666 | // For Notify(), just send the relative path of the inventory |
| 667 | // object so remove the INVENTORY_OBJ_PATH prefix |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 668 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 669 | |
| 670 | object.emplace(path, std::move(interfaces)); |
| 671 | |
| 672 | try |
| 673 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 674 | auto service = |
| 675 | util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 676 | |
| 677 | if (service.empty()) |
| 678 | { |
| 679 | log<level::ERR>("Unable to get inventory manager service"); |
| 680 | return; |
| 681 | } |
| 682 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 683 | auto method = bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 684 | INVENTORY_MGR_IFACE, "Notify"); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 685 | |
| 686 | method.append(std::move(object)); |
| 687 | |
| 688 | auto reply = bus.call(method); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 689 | |
| 690 | // TODO: openbmc/openbmc#2756 |
| 691 | // Calling Notify() with an enumerated property crashes inventory |
| 692 | // manager, so let it default to Unknown and now set it to the |
| 693 | // right value. |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 694 | auto purpose = |
| 695 | version::convertForMessage(version::Version::VersionPurpose::Other); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 696 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 697 | util::setProperty(VERSION_IFACE, VERSION_PURPOSE_PROP, inventoryPath, |
| 698 | service, bus, purpose); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 699 | } |
| 700 | catch (std::exception& e) |
| 701 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 702 | log<level::ERR>(e.what(), entry("PATH=%s", inventoryPath.c_str())); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 703 | } |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 704 | } |
| 705 | |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 706 | void PowerSupply::syncHistory() |
| 707 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 708 | using namespace phosphor::gpio; |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 709 | |
| 710 | if (syncGPIODevPath.empty()) |
| 711 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 712 | // Sync not implemented |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 713 | return; |
| 714 | } |
| 715 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 716 | GPIO gpio{syncGPIODevPath, static_cast<gpioNum_t>(syncGPIONumber), |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 717 | Direction::output}; |
| 718 | |
| 719 | try |
| 720 | { |
| 721 | gpio.set(Value::low); |
| 722 | |
| 723 | std::this_thread::sleep_for(std::chrono::milliseconds{5}); |
| 724 | |
| 725 | gpio.set(Value::high); |
| 726 | |
| 727 | recordManager->clear(); |
| 728 | } |
| 729 | catch (std::exception& e) |
| 730 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 731 | // Do nothing. There would already be a journal entry. |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
Matt Spinler | 8238414 | 2018-01-18 14:15:03 -0600 | [diff] [blame] | 735 | void PowerSupply::enableHistory(const std::string& objectPath, |
| 736 | size_t numRecords, |
| 737 | const std::string& syncGPIOPath, |
| 738 | size_t syncGPIONum) |
| 739 | { |
| 740 | historyObjectPath = objectPath; |
| 741 | syncGPIODevPath = syncGPIOPath; |
| 742 | syncGPIONumber = syncGPIONum; |
| 743 | |
| 744 | recordManager = std::make_unique<history::RecordManager>(numRecords); |
| 745 | |
| 746 | auto avgPath = historyObjectPath + '/' + history::Average::name; |
| 747 | auto maxPath = historyObjectPath + '/' + history::Maximum::name; |
| 748 | |
| 749 | average = std::make_unique<history::Average>(bus, avgPath); |
| 750 | |
| 751 | maximum = std::make_unique<history::Maximum>(bus, maxPath); |
| 752 | } |
| 753 | |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 754 | void PowerSupply::updateHistory() |
| 755 | { |
| 756 | if (!recordManager) |
| 757 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 758 | // Not enabled |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 762 | // Read just the most recent average/max record |
| 763 | auto data = |
| 764 | pmbusIntf.readBinary(INPUT_HISTORY, pmbus::Type::HwmonDeviceDebug, |
| 765 | history::RecordManager::RAW_RECORD_SIZE); |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 766 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 767 | // Update D-Bus only if something changed (a new record ID, or cleared out) |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 768 | auto changed = recordManager->add(data); |
| 769 | if (changed) |
| 770 | { |
| 771 | average->values(std::move(recordManager->getAverageRecords())); |
| 772 | maximum->values(std::move(recordManager->getMaximumRecords())); |
| 773 | } |
| 774 | } |
| 775 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 776 | } // namespace psu |
| 777 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 778 | } // namespace phosphor |