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