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