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 | { |
Brandon Wyman | 2877add | 2017-11-10 17:44:19 -0600 | [diff] [blame^] | 55 | // The hwmon path may have changed. |
| 56 | pmbusIntf.findHwmonDir(); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 57 | this->present = true; |
| 58 | }), |
| 59 | powerOnInterval(t), |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 60 | powerOnTimer(e, [this]() |
| 61 | { |
| 62 | this->powerOn = true; |
| 63 | }) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 64 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 65 | using namespace sdbusplus::bus; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 66 | presentMatch = std::make_unique<match_t>(bus, |
| 67 | match::rules::propertiesChanged( |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 68 | inventoryPath, |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 69 | INVENTORY_INTERFACE), |
| 70 | [this](auto& msg) |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 71 | { |
| 72 | this->inventoryChanged(msg); |
| 73 | }); |
| 74 | // Get initial presence state. |
Brandon Wyman | 253dc9b | 2017-08-12 13:45:52 -0500 | [diff] [blame] | 75 | updatePresence(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 76 | |
| 77 | // Subscribe to power state changes |
| 78 | powerOnMatch = std::make_unique<match_t>(bus, |
| 79 | match::rules::propertiesChanged( |
| 80 | POWER_OBJ_PATH, |
| 81 | POWER_INTERFACE), |
| 82 | [this](auto& msg) |
| 83 | { |
| 84 | this->powerStateChanged(msg); |
| 85 | }); |
| 86 | // Get initial power state. |
| 87 | updatePowerState(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 88 | } |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 89 | |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 90 | void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd, |
| 91 | witherspoon::pmbus::Type type) |
| 92 | { |
| 93 | if (pmbusIntf.exists(cmd, type)) |
| 94 | { |
| 95 | try |
| 96 | { |
| 97 | auto val = pmbusIntf.read(cmd, type); |
| 98 | nv.add(cmd, val); |
| 99 | } |
| 100 | catch (std::exception& e) |
| 101 | { |
| 102 | log<level::INFO>("Unable to capture metadata", entry("CMD=%s", |
| 103 | cmd)); |
| 104 | } |
| 105 | } |
| 106 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 107 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 108 | void PowerSupply::analyze() |
| 109 | { |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 110 | using namespace witherspoon::pmbus; |
| 111 | |
| 112 | try |
| 113 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 114 | if (present) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 115 | { |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 116 | std::uint16_t statusWord = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 117 | |
| 118 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 119 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 120 | readFail = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 121 | |
Brandon Wyman | bee8161 | 2017-11-01 18:24:43 -0500 | [diff] [blame] | 122 | //TODO: openbmc/openbmc#2484 Three consecutive reads should be |
| 123 | // performed. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 124 | // If 3 consecutive reads are seen, log the fault. |
| 125 | // Driver gives cached value, read once a second. |
| 126 | // increment for fault on, decrement for fault off, to deglitch. |
| 127 | // If count reaches 3, we have fault. If count reaches 0, fault is |
| 128 | // cleared. |
| 129 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 130 | checkInputFault(statusWord); |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 131 | |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 132 | if (powerOn && !faultFound) |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 133 | { |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 134 | checkFanFault(statusWord); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 135 | checkTemperatureFault(statusWord); |
Brandon Wyman | cfa032b | 2017-09-25 17:37:50 -0500 | [diff] [blame] | 136 | checkOutputOvervoltageFault(statusWord); |
| 137 | checkCurrentOutOverCurrentFault(statusWord); |
| 138 | checkPGOrUnitOffFault(statusWord); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | catch (ReadFailure& e) |
| 143 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 144 | if (readFail < FAULT_COUNT) |
| 145 | { |
| 146 | readFail++; |
| 147 | } |
| 148 | |
| 149 | if (!readFailLogged && readFail >= FAULT_COUNT) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 150 | { |
| 151 | commit<ReadFailure>(); |
| 152 | readFailLogged = true; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 159 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 160 | { |
| 161 | std::string msgSensor; |
| 162 | std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData; |
| 163 | msg.read(msgSensor, msgData); |
| 164 | |
| 165 | // Check if it was the Present property that changed. |
| 166 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 167 | if (valPropMap != msgData.end()) |
| 168 | { |
| 169 | present = sdbusplus::message::variant_ns::get<bool>(valPropMap->second); |
| 170 | |
| 171 | if (present) |
| 172 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 173 | clearFaults(); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 174 | presentTimer.start(presentInterval, Timer::TimerType::oneshot); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | presentTimer.stop(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | void PowerSupply::updatePresence() |
| 186 | { |
| 187 | // Use getProperty utility function to get presence status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 188 | std::string service = "xyz.openbmc_project.Inventory.Manager"; |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 189 | util::getProperty(INVENTORY_INTERFACE, PRESENT_PROP, inventoryPath, |
| 190 | service, bus, this->present); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 193 | void PowerSupply::powerStateChanged(sdbusplus::message::message& msg) |
| 194 | { |
| 195 | int32_t state = 0; |
| 196 | std::string msgSensor; |
| 197 | std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>> |
| 198 | msgData; |
| 199 | msg.read(msgSensor, msgData); |
| 200 | |
| 201 | // Check if it was the Present property that changed. |
| 202 | auto valPropMap = msgData.find("state"); |
| 203 | if (valPropMap != msgData.end()) |
| 204 | { |
| 205 | state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second); |
| 206 | |
| 207 | // Power is on when state=1. Set the fault logged variables to false |
| 208 | // and start the power on timer when the state changes to 1. |
| 209 | if (state) |
| 210 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 211 | clearFaults(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 212 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | powerOnTimer.stop(); |
| 217 | powerOn = false; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | } |
| 222 | |
| 223 | void PowerSupply::updatePowerState() |
| 224 | { |
| 225 | // When state = 1, system is powered on |
| 226 | int32_t state = 0; |
| 227 | |
| 228 | try |
| 229 | { |
| 230 | auto service = util::getService(POWER_OBJ_PATH, |
| 231 | POWER_INTERFACE, |
| 232 | bus); |
| 233 | |
| 234 | // Use getProperty utility function to get power state. |
| 235 | util::getProperty<int32_t>(POWER_INTERFACE, |
| 236 | "state", |
| 237 | POWER_OBJ_PATH, |
| 238 | service, |
| 239 | bus, |
| 240 | state); |
| 241 | |
| 242 | if (state) |
| 243 | { |
| 244 | powerOn = true; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | powerOn = false; |
| 249 | } |
| 250 | } |
| 251 | catch (std::exception& e) |
| 252 | { |
| 253 | log<level::INFO>("Failed to get power state. Assuming it is off."); |
| 254 | powerOn = false; |
| 255 | } |
| 256 | |
| 257 | } |
| 258 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 259 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 260 | { |
| 261 | using namespace witherspoon::pmbus; |
| 262 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 263 | if ((inputFault < FAULT_COUNT) && |
| 264 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 265 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 266 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 267 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 268 | } |
| 269 | else |
| 270 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 271 | if ((inputFault > 0) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 272 | !(statusWord & status_word::INPUT_FAULT_WARN) && |
| 273 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 274 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 275 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 276 | faultFound = false; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 277 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 278 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 279 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 280 | |
| 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 | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |