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); |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 118 | readFail = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 119 | |
Brandon Wyman | bee8161 | 2017-11-01 18:24:43 -0500 | [diff] [blame] | 120 | //TODO: openbmc/openbmc#2484 Three consecutive reads should be |
| 121 | // performed. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 122 | // If 3 consecutive reads are seen, log the fault. |
| 123 | // Driver gives cached value, read once a second. |
| 124 | // increment for fault on, decrement for fault off, to deglitch. |
| 125 | // If count reaches 3, we have fault. If count reaches 0, fault is |
| 126 | // cleared. |
| 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 | { |
| 167 | present = sdbusplus::message::variant_ns::get<bool>(valPropMap->second); |
| 168 | |
| 169 | if (present) |
| 170 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 171 | clearFaults(); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 172 | presentTimer.start(presentInterval, Timer::TimerType::oneshot); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | presentTimer.stop(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | void PowerSupply::updatePresence() |
| 184 | { |
| 185 | // Use getProperty utility function to get presence status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 186 | std::string service = "xyz.openbmc_project.Inventory.Manager"; |
Brandon Wyman | 50bb85d | 2017-11-01 18:36:00 -0500 | [diff] [blame] | 187 | util::getProperty(INVENTORY_INTERFACE, PRESENT_PROP, inventoryPath, |
| 188 | service, bus, this->present); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 191 | void PowerSupply::powerStateChanged(sdbusplus::message::message& msg) |
| 192 | { |
| 193 | int32_t state = 0; |
| 194 | std::string msgSensor; |
| 195 | std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>> |
| 196 | msgData; |
| 197 | msg.read(msgSensor, msgData); |
| 198 | |
| 199 | // Check if it was the Present property that changed. |
| 200 | auto valPropMap = msgData.find("state"); |
| 201 | if (valPropMap != msgData.end()) |
| 202 | { |
| 203 | state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second); |
| 204 | |
| 205 | // Power is on when state=1. Set the fault logged variables to false |
| 206 | // and start the power on timer when the state changes to 1. |
| 207 | if (state) |
| 208 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 209 | clearFaults(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 210 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | powerOnTimer.stop(); |
| 215 | powerOn = false; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | } |
| 220 | |
| 221 | void PowerSupply::updatePowerState() |
| 222 | { |
| 223 | // When state = 1, system is powered on |
| 224 | int32_t state = 0; |
| 225 | |
| 226 | try |
| 227 | { |
| 228 | auto service = util::getService(POWER_OBJ_PATH, |
| 229 | POWER_INTERFACE, |
| 230 | bus); |
| 231 | |
| 232 | // Use getProperty utility function to get power state. |
| 233 | util::getProperty<int32_t>(POWER_INTERFACE, |
| 234 | "state", |
| 235 | POWER_OBJ_PATH, |
| 236 | service, |
| 237 | bus, |
| 238 | state); |
| 239 | |
| 240 | if (state) |
| 241 | { |
| 242 | powerOn = true; |
| 243 | } |
| 244 | else |
| 245 | { |
| 246 | powerOn = false; |
| 247 | } |
| 248 | } |
| 249 | catch (std::exception& e) |
| 250 | { |
| 251 | log<level::INFO>("Failed to get power state. Assuming it is off."); |
| 252 | powerOn = false; |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 257 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 258 | { |
| 259 | using namespace witherspoon::pmbus; |
| 260 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 261 | if ((inputFault < FAULT_COUNT) && |
| 262 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 263 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 264 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 265 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 266 | } |
| 267 | else |
| 268 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 269 | if ((inputFault > 0) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 270 | !(statusWord & status_word::INPUT_FAULT_WARN) && |
| 271 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 272 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 273 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 274 | faultFound = false; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 275 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 276 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 277 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 278 | |
| 279 | if (powerOn) |
| 280 | { |
| 281 | // The power supply will not be immediately powered on after |
| 282 | // the input power is restored. |
| 283 | powerOn = false; |
| 284 | // Start up the timer that will set the state to indicate we |
| 285 | // are ready for the powered on fault checks. |
| 286 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 287 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 288 | } |
| 289 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 290 | |
| 291 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 292 | { |
| 293 | util::NamesValues nv; |
| 294 | nv.add("STATUS_WORD", statusWord); |
| 295 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 296 | |
| 297 | using metadata = org::open_power::Witherspoon::Fault:: |
| 298 | PowerSupplyInputFault; |
| 299 | |
| 300 | report<PowerSupplyInputFault>( |
| 301 | metadata::RAW_STATUS(nv.get().c_str()), |
| 302 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 303 | faultFound = true; |
| 304 | } |
| 305 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 309 | { |
| 310 | using namespace witherspoon::pmbus; |
| 311 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 312 | if (powerOnFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 313 | { |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 314 | // Check PG# and UNIT_IS_OFF |
| 315 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 316 | (statusWord & status_word::UNIT_IS_OFF)) |
| 317 | { |
| 318 | log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad", |
| 319 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 320 | powerOnFault++; |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | if (powerOnFault > 0) |
| 325 | { |
| 326 | log<level::INFO>("PGOOD and UNIT_IS_OFF bits good"); |
| 327 | powerOnFault = 0; |
| 328 | } |
| 329 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 330 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame^] | 331 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 332 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 333 | faultFound = true; |
| 334 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 335 | util::NamesValues nv; |
| 336 | nv.add("STATUS_WORD", statusWord); |
| 337 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 338 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 339 | captureCmd(nv, status0Vout, Type::Debug); |
| 340 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 341 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 342 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 343 | using metadata = org::open_power::Witherspoon::Fault:: |
| 344 | PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 345 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 346 | // A power supply is OFF (or pgood low) but should be on. |
| 347 | report<PowerSupplyShouldBeOn>( |
| 348 | metadata::RAW_STATUS(nv.get().c_str()), |
| 349 | metadata::CALLOUT_INVENTORY_PATH( |
| 350 | inventoryPath.c_str())); |
| 351 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | } |
| 355 | |
| 356 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 357 | { |
| 358 | using namespace witherspoon::pmbus; |
| 359 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 360 | if (outputOCFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 361 | { |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 362 | // Check for an output overcurrent fault. |
| 363 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 364 | { |
| 365 | outputOCFault++; |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | if (outputOCFault > 0) |
| 370 | { |
| 371 | outputOCFault = 0; |
| 372 | } |
| 373 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 374 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame^] | 375 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 376 | { |
| 377 | util::NamesValues nv; |
| 378 | nv.add("STATUS_WORD", statusWord); |
| 379 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 380 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 381 | captureCmd(nv, status0Vout, Type::Debug); |
| 382 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 383 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 384 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 385 | using metadata = org::open_power::Witherspoon::Fault:: |
| 386 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 387 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 388 | report<PowerSupplyOutputOvercurrent>( |
| 389 | metadata::RAW_STATUS(nv.get().c_str()), |
| 390 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 391 | |
| 392 | faultFound = true; |
| 393 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 397 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 398 | { |
| 399 | using namespace witherspoon::pmbus; |
| 400 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 401 | if (outputOVFault < FAULT_COUNT) |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 402 | { |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 403 | // Check for an output overvoltage fault. |
| 404 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 405 | { |
| 406 | outputOVFault++; |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | if (outputOVFault > 0) |
| 411 | { |
| 412 | outputOVFault = 0; |
| 413 | } |
| 414 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 415 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame^] | 416 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 417 | { |
| 418 | util::NamesValues nv; |
| 419 | nv.add("STATUS_WORD", statusWord); |
| 420 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 421 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 422 | captureCmd(nv, status0Vout, Type::Debug); |
| 423 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 424 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 425 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 426 | using metadata = org::open_power::Witherspoon::Fault:: |
| 427 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 428 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 429 | report<PowerSupplyOutputOvervoltage>( |
| 430 | metadata::RAW_STATUS(nv.get().c_str()), |
| 431 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 432 | |
| 433 | faultFound = true; |
| 434 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 438 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 439 | { |
| 440 | using namespace witherspoon::pmbus; |
| 441 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 442 | if (fanFault < FAULT_COUNT) |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 443 | { |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 444 | // Check for a fan fault or warning condition |
| 445 | if (statusWord & status_word::FAN_FAULT) |
| 446 | { |
| 447 | fanFault++; |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | if (fanFault > 0) |
| 452 | { |
| 453 | fanFault = 0; |
| 454 | } |
| 455 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 456 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame^] | 457 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 458 | { |
| 459 | util::NamesValues nv; |
| 460 | nv.add("STATUS_WORD", statusWord); |
| 461 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 462 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 463 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 464 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 465 | using metadata = org::open_power::Witherspoon::Fault:: |
| 466 | PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 467 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 468 | report<PowerSupplyFanFault>( |
| 469 | metadata::RAW_STATUS(nv.get().c_str()), |
| 470 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 471 | |
| 472 | faultFound = true; |
| 473 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 477 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 478 | { |
| 479 | using namespace witherspoon::pmbus; |
| 480 | |
| 481 | // Due to how the PMBus core device driver sends a clear faults command |
| 482 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 483 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 484 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 485 | // logging the over-temperature condition. |
| 486 | std::uint8_t statusTemperature = 0; |
| 487 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 488 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 489 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 490 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 491 | (statusTemperature & status_temperature::OT_FAULT)) |
| 492 | { |
| 493 | temperatureFault++; |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | if (temperatureFault > 0) |
| 498 | { |
| 499 | temperatureFault = 0; |
| 500 | } |
| 501 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 502 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame^] | 503 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 504 | { |
| 505 | // The power supply has had an over-temperature condition. |
| 506 | // This may not result in a shutdown if experienced for a short |
| 507 | // duration. |
| 508 | // This should not occur under normal conditions. |
| 509 | // The power supply may be faulty, or the paired supply may be |
| 510 | // putting out less current. |
| 511 | // Capture command responses with potentially relevant information, |
| 512 | // and call out the power supply reporting the condition. |
| 513 | util::NamesValues nv; |
| 514 | nv.add("STATUS_WORD", statusWord); |
| 515 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 516 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 517 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 518 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 519 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 520 | using metadata = org::open_power::Witherspoon::Fault:: |
| 521 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 522 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 523 | report<PowerSupplyTemperatureFault>( |
| 524 | metadata::RAW_STATUS(nv.get().c_str()), |
| 525 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 526 | |
| 527 | faultFound = true; |
| 528 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 532 | void PowerSupply::clearFaults() |
| 533 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 534 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 535 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 536 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 537 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 538 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 539 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 540 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 541 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 542 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 543 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 544 | return; |
| 545 | } |
| 546 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | } |