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> |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 20 | #include "elog-errors.hpp" |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 21 | #include "names_values.hpp" |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 22 | #include "power_supply.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 23 | #include "pmbus.hpp" |
| 24 | #include "utility.hpp" |
| 25 | |
| 26 | using namespace phosphor::logging; |
Brandon Wyman | e0eb45c | 2017-10-06 12:58:42 -0500 | [diff] [blame] | 27 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 28 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 29 | |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 30 | constexpr auto ASSOCIATION_IFACE = "org.openbmc.Association"; |
| 31 | constexpr auto ENDPOINTS_PROPERTY = "endpoints"; |
| 32 | constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry"; |
| 33 | constexpr auto MESSAGE_PROPERTY = "Message"; |
| 34 | constexpr auto RESOLVED_PROPERTY = "Resolved"; |
| 35 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 36 | namespace witherspoon |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 37 | { |
| 38 | namespace power |
| 39 | { |
| 40 | namespace psu |
| 41 | { |
| 42 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 43 | constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory"; |
| 44 | constexpr auto INVENTORY_INTERFACE = "xyz.openbmc_project.Inventory.Item"; |
| 45 | constexpr auto PRESENT_PROP = "Present"; |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 46 | constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0"; |
| 47 | constexpr auto POWER_INTERFACE = "org.openbmc.control.Power"; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 48 | |
| 49 | PowerSupply::PowerSupply(const std::string& name, size_t inst, |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 50 | const std::string& objpath, |
| 51 | const std::string& invpath, |
| 52 | sdbusplus::bus::bus& bus, |
| 53 | event::Event& e, |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 54 | std::chrono::seconds& t, |
| 55 | std::chrono::seconds& p) |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 56 | : Device(name, inst), monitorPath(objpath), pmbusIntf(objpath), |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 57 | inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), event(e), |
| 58 | presentInterval(p), |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 59 | presentTimer(e, [this]() |
| 60 | { |
Brandon Wyman | 2877add | 2017-11-10 17:44:19 -0600 | [diff] [blame] | 61 | // The hwmon path may have changed. |
| 62 | pmbusIntf.findHwmonDir(); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 63 | this->present = true; |
| 64 | }), |
| 65 | powerOnInterval(t), |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 66 | powerOnTimer(e, [this]() |
| 67 | { |
| 68 | this->powerOn = true; |
| 69 | }) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 70 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 71 | using namespace sdbusplus::bus; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 72 | presentMatch = std::make_unique<match_t>(bus, |
| 73 | match::rules::propertiesChanged( |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 74 | inventoryPath, |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 75 | INVENTORY_INTERFACE), |
| 76 | [this](auto& msg) |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 77 | { |
| 78 | this->inventoryChanged(msg); |
| 79 | }); |
| 80 | // Get initial presence state. |
Brandon Wyman | 253dc9b | 2017-08-12 13:45:52 -0500 | [diff] [blame] | 81 | updatePresence(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 82 | |
| 83 | // Subscribe to power state changes |
| 84 | powerOnMatch = std::make_unique<match_t>(bus, |
| 85 | match::rules::propertiesChanged( |
| 86 | POWER_OBJ_PATH, |
| 87 | POWER_INTERFACE), |
| 88 | [this](auto& msg) |
| 89 | { |
| 90 | this->powerStateChanged(msg); |
| 91 | }); |
| 92 | // Get initial power state. |
| 93 | updatePowerState(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 94 | } |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 95 | |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 96 | void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd, |
| 97 | witherspoon::pmbus::Type type) |
| 98 | { |
| 99 | if (pmbusIntf.exists(cmd, type)) |
| 100 | { |
| 101 | try |
| 102 | { |
| 103 | auto val = pmbusIntf.read(cmd, type); |
| 104 | nv.add(cmd, val); |
| 105 | } |
| 106 | catch (std::exception& e) |
| 107 | { |
| 108 | log<level::INFO>("Unable to capture metadata", entry("CMD=%s", |
| 109 | cmd)); |
| 110 | } |
| 111 | } |
| 112 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 113 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 114 | void PowerSupply::analyze() |
| 115 | { |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 116 | using namespace witherspoon::pmbus; |
| 117 | |
| 118 | try |
| 119 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 120 | if (present) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 121 | { |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 122 | std::uint16_t statusWord = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 123 | |
| 124 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 125 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 126 | readFail = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 127 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 128 | checkInputFault(statusWord); |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 129 | |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 130 | if (powerOn && !faultFound) |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 131 | { |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 132 | checkFanFault(statusWord); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 133 | checkTemperatureFault(statusWord); |
Brandon Wyman | cfa032b | 2017-09-25 17:37:50 -0500 | [diff] [blame] | 134 | checkOutputOvervoltageFault(statusWord); |
| 135 | checkCurrentOutOverCurrentFault(statusWord); |
| 136 | checkPGOrUnitOffFault(statusWord); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
| 140 | catch (ReadFailure& e) |
| 141 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 142 | if (readFail < FAULT_COUNT) |
| 143 | { |
| 144 | readFail++; |
| 145 | } |
| 146 | |
| 147 | if (!readFailLogged && readFail >= FAULT_COUNT) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 148 | { |
| 149 | commit<ReadFailure>(); |
| 150 | readFailLogged = true; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 154 | return; |
| 155 | } |
| 156 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 157 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 158 | { |
| 159 | std::string msgSensor; |
| 160 | std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData; |
| 161 | msg.read(msgSensor, msgData); |
| 162 | |
| 163 | // Check if it was the Present property that changed. |
| 164 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 165 | if (valPropMap != msgData.end()) |
| 166 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 167 | if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second)) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 168 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 169 | clearFaults(); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 170 | presentTimer.start(presentInterval, Timer::TimerType::oneshot); |
| 171 | } |
| 172 | else |
| 173 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 174 | present = false; |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 175 | presentTimer.stop(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | void PowerSupply::updatePresence() |
| 183 | { |
| 184 | // Use getProperty utility function to get presence status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 185 | std::string service = "xyz.openbmc_project.Inventory.Manager"; |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 186 | util::getProperty(INVENTORY_INTERFACE, PRESENT_PROP, inventoryPath, |
| 187 | service, bus, this->present); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 190 | void PowerSupply::powerStateChanged(sdbusplus::message::message& msg) |
| 191 | { |
| 192 | int32_t state = 0; |
| 193 | std::string msgSensor; |
| 194 | std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>> |
| 195 | msgData; |
| 196 | msg.read(msgSensor, msgData); |
| 197 | |
| 198 | // Check if it was the Present property that changed. |
| 199 | auto valPropMap = msgData.find("state"); |
| 200 | if (valPropMap != msgData.end()) |
| 201 | { |
| 202 | state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second); |
| 203 | |
| 204 | // Power is on when state=1. Set the fault logged variables to false |
| 205 | // and start the power on timer when the state changes to 1. |
| 206 | if (state) |
| 207 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 208 | clearFaults(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 209 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | powerOnTimer.stop(); |
| 214 | powerOn = false; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |
| 220 | void PowerSupply::updatePowerState() |
| 221 | { |
| 222 | // When state = 1, system is powered on |
| 223 | int32_t state = 0; |
| 224 | |
| 225 | try |
| 226 | { |
| 227 | auto service = util::getService(POWER_OBJ_PATH, |
| 228 | POWER_INTERFACE, |
| 229 | bus); |
| 230 | |
| 231 | // Use getProperty utility function to get power state. |
| 232 | util::getProperty<int32_t>(POWER_INTERFACE, |
| 233 | "state", |
| 234 | POWER_OBJ_PATH, |
| 235 | service, |
| 236 | bus, |
| 237 | state); |
| 238 | |
| 239 | if (state) |
| 240 | { |
| 241 | powerOn = true; |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | powerOn = false; |
| 246 | } |
| 247 | } |
| 248 | catch (std::exception& e) |
| 249 | { |
| 250 | log<level::INFO>("Failed to get power state. Assuming it is off."); |
| 251 | powerOn = false; |
| 252 | } |
| 253 | |
| 254 | } |
| 255 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 256 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 257 | { |
| 258 | using namespace witherspoon::pmbus; |
| 259 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 260 | if ((inputFault < FAULT_COUNT) && |
| 261 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 262 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 263 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 264 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 265 | } |
| 266 | else |
| 267 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 268 | if ((inputFault > 0) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 269 | !(statusWord & status_word::INPUT_FAULT_WARN) && |
| 270 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 271 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 272 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 273 | faultFound = false; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 274 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 275 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 276 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 277 | |
Brandon Wyman | 08b0571 | 2017-11-30 17:53:56 -0600 | [diff] [blame] | 278 | resolveError(inventoryPath, |
| 279 | std::string(PowerSupplyInputFault::errName)); |
| 280 | |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 281 | if (powerOn) |
| 282 | { |
| 283 | // The power supply will not be immediately powered on after |
| 284 | // the input power is restored. |
| 285 | powerOn = false; |
| 286 | // Start up the timer that will set the state to indicate we |
| 287 | // are ready for the powered on fault checks. |
| 288 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 289 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 290 | } |
| 291 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 292 | |
| 293 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 294 | { |
| 295 | util::NamesValues nv; |
| 296 | nv.add("STATUS_WORD", statusWord); |
| 297 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 298 | |
| 299 | using metadata = org::open_power::Witherspoon::Fault:: |
| 300 | PowerSupplyInputFault; |
| 301 | |
| 302 | report<PowerSupplyInputFault>( |
| 303 | metadata::RAW_STATUS(nv.get().c_str()), |
| 304 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 305 | faultFound = true; |
| 306 | } |
| 307 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 311 | { |
| 312 | using namespace witherspoon::pmbus; |
| 313 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 314 | if (powerOnFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 315 | { |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 316 | // Check PG# and UNIT_IS_OFF |
| 317 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 318 | (statusWord & status_word::UNIT_IS_OFF)) |
| 319 | { |
| 320 | log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad", |
| 321 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 322 | powerOnFault++; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | if (powerOnFault > 0) |
| 327 | { |
| 328 | log<level::INFO>("PGOOD and UNIT_IS_OFF bits good"); |
| 329 | powerOnFault = 0; |
| 330 | } |
| 331 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 332 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 333 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 334 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 335 | faultFound = true; |
| 336 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 337 | util::NamesValues nv; |
| 338 | nv.add("STATUS_WORD", statusWord); |
| 339 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 340 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 341 | captureCmd(nv, status0Vout, Type::Debug); |
| 342 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 343 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 344 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 345 | using metadata = org::open_power::Witherspoon::Fault:: |
| 346 | PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 347 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 348 | // A power supply is OFF (or pgood low) but should be on. |
| 349 | report<PowerSupplyShouldBeOn>( |
| 350 | metadata::RAW_STATUS(nv.get().c_str()), |
| 351 | metadata::CALLOUT_INVENTORY_PATH( |
| 352 | inventoryPath.c_str())); |
| 353 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | } |
| 357 | |
| 358 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 359 | { |
| 360 | using namespace witherspoon::pmbus; |
| 361 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 362 | if (outputOCFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 363 | { |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 364 | // Check for an output overcurrent fault. |
| 365 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 366 | { |
| 367 | outputOCFault++; |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | if (outputOCFault > 0) |
| 372 | { |
| 373 | outputOCFault = 0; |
| 374 | } |
| 375 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 376 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 377 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 378 | { |
| 379 | util::NamesValues nv; |
| 380 | nv.add("STATUS_WORD", statusWord); |
| 381 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 382 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 383 | captureCmd(nv, status0Vout, Type::Debug); |
| 384 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 385 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 386 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 387 | using metadata = org::open_power::Witherspoon::Fault:: |
| 388 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 389 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 390 | report<PowerSupplyOutputOvercurrent>( |
| 391 | metadata::RAW_STATUS(nv.get().c_str()), |
| 392 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 393 | |
| 394 | faultFound = true; |
| 395 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 399 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 400 | { |
| 401 | using namespace witherspoon::pmbus; |
| 402 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 403 | if (outputOVFault < FAULT_COUNT) |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 404 | { |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 405 | // Check for an output overvoltage fault. |
| 406 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 407 | { |
| 408 | outputOVFault++; |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | if (outputOVFault > 0) |
| 413 | { |
| 414 | outputOVFault = 0; |
| 415 | } |
| 416 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 417 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 418 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 419 | { |
| 420 | util::NamesValues nv; |
| 421 | nv.add("STATUS_WORD", statusWord); |
| 422 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 423 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 424 | captureCmd(nv, status0Vout, Type::Debug); |
| 425 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 426 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 427 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 428 | using metadata = org::open_power::Witherspoon::Fault:: |
| 429 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 430 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 431 | report<PowerSupplyOutputOvervoltage>( |
| 432 | metadata::RAW_STATUS(nv.get().c_str()), |
| 433 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 434 | |
| 435 | faultFound = true; |
| 436 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 440 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 441 | { |
| 442 | using namespace witherspoon::pmbus; |
| 443 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 444 | if (fanFault < FAULT_COUNT) |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 445 | { |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 446 | // Check for a fan fault or warning condition |
| 447 | if (statusWord & status_word::FAN_FAULT) |
| 448 | { |
| 449 | fanFault++; |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | if (fanFault > 0) |
| 454 | { |
| 455 | fanFault = 0; |
| 456 | } |
| 457 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 458 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 459 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 460 | { |
| 461 | util::NamesValues nv; |
| 462 | nv.add("STATUS_WORD", statusWord); |
| 463 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 464 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 465 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 466 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 467 | using metadata = org::open_power::Witherspoon::Fault:: |
| 468 | PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 469 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 470 | report<PowerSupplyFanFault>( |
| 471 | metadata::RAW_STATUS(nv.get().c_str()), |
| 472 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 473 | |
| 474 | faultFound = true; |
| 475 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 479 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 480 | { |
| 481 | using namespace witherspoon::pmbus; |
| 482 | |
| 483 | // Due to how the PMBus core device driver sends a clear faults command |
| 484 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 485 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 486 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 487 | // logging the over-temperature condition. |
| 488 | std::uint8_t statusTemperature = 0; |
| 489 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 490 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 491 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 492 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 493 | (statusTemperature & status_temperature::OT_FAULT)) |
| 494 | { |
| 495 | temperatureFault++; |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | if (temperatureFault > 0) |
| 500 | { |
| 501 | temperatureFault = 0; |
| 502 | } |
| 503 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 504 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 505 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 506 | { |
| 507 | // The power supply has had an over-temperature condition. |
| 508 | // This may not result in a shutdown if experienced for a short |
| 509 | // duration. |
| 510 | // This should not occur under normal conditions. |
| 511 | // The power supply may be faulty, or the paired supply may be |
| 512 | // putting out less current. |
| 513 | // Capture command responses with potentially relevant information, |
| 514 | // and call out the power supply reporting the condition. |
| 515 | util::NamesValues nv; |
| 516 | nv.add("STATUS_WORD", statusWord); |
| 517 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 518 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 519 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 520 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 521 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 522 | using metadata = org::open_power::Witherspoon::Fault:: |
| 523 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 524 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 525 | report<PowerSupplyTemperatureFault>( |
| 526 | metadata::RAW_STATUS(nv.get().c_str()), |
| 527 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 528 | |
| 529 | faultFound = true; |
| 530 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 534 | void PowerSupply::clearFaults() |
| 535 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 536 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 537 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 538 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 539 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 540 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 541 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 542 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 543 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 544 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 545 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 546 | return; |
| 547 | } |
| 548 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 549 | void PowerSupply::resolveError(const std::string& callout, |
| 550 | const std::string& message) |
| 551 | { |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 552 | using EndpointList = std::vector<std::string>; |
| 553 | |
| 554 | try |
| 555 | { |
| 556 | auto path = callout + "/fault"; |
| 557 | // Get the service name from the mapper for the fault callout |
| 558 | auto service = util::getService(path, |
| 559 | ASSOCIATION_IFACE, |
| 560 | bus); |
| 561 | |
| 562 | // Use getProperty utility function to get log entries (endpoints) |
| 563 | EndpointList logEntries; |
| 564 | util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROPERTY, path, service, |
| 565 | bus, logEntries); |
| 566 | |
| 567 | // It is possible that all such entries for this callout have since |
| 568 | // been deleted. |
| 569 | if (logEntries.empty()) |
| 570 | { |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE, |
| 575 | bus); |
| 576 | if (logEntryService.empty()) |
| 577 | { |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | // go through each log entry that matches this callout path |
| 582 | std::string logMessage; |
| 583 | for (const auto& logEntry : logEntries) |
| 584 | { |
| 585 | // Check to see if this logEntry has a message that matches. |
| 586 | util::getProperty(LOGGING_IFACE, MESSAGE_PROPERTY, logEntry, |
| 587 | logEntryService, bus, logMessage); |
| 588 | |
| 589 | if (message == logMessage) |
| 590 | { |
| 591 | // Log entry matches call out and message, set Resolved to true |
| 592 | bool resolved = true; |
| 593 | util::setProperty(LOGGING_IFACE, RESOLVED_PROPERTY, logEntry, |
| 594 | logEntryService, bus, resolved); |
| 595 | } |
| 596 | |
| 597 | } |
| 598 | |
| 599 | } |
| 600 | catch (std::exception& e) |
| 601 | { |
| 602 | log<level::INFO>("Failed to resolve error", |
| 603 | entry("CALLOUT=%s", callout.c_str()), |
| 604 | entry("MESSAGE=%s", message.c_str())); |
| 605 | } |
| 606 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 607 | } |
| 608 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | } |