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