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