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