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