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