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