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