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 | |
Brandon Wyman | 08b0571 | 2017-11-30 17:53:56 -0600 | [diff] [blame^] | 272 | resolveError(inventoryPath, |
| 273 | std::string(PowerSupplyInputFault::errName)); |
| 274 | |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 275 | if (powerOn) |
| 276 | { |
| 277 | // The power supply will not be immediately powered on after |
| 278 | // the input power is restored. |
| 279 | powerOn = false; |
| 280 | // Start up the timer that will set the state to indicate we |
| 281 | // are ready for the powered on fault checks. |
| 282 | powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot); |
| 283 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 284 | } |
| 285 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 286 | |
| 287 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 288 | { |
| 289 | util::NamesValues nv; |
| 290 | nv.add("STATUS_WORD", statusWord); |
| 291 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 292 | |
| 293 | using metadata = org::open_power::Witherspoon::Fault:: |
| 294 | PowerSupplyInputFault; |
| 295 | |
| 296 | report<PowerSupplyInputFault>( |
| 297 | metadata::RAW_STATUS(nv.get().c_str()), |
| 298 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 299 | faultFound = true; |
| 300 | } |
| 301 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 305 | { |
| 306 | using namespace witherspoon::pmbus; |
| 307 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 308 | if (powerOnFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 309 | { |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 310 | // Check PG# and UNIT_IS_OFF |
| 311 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 312 | (statusWord & status_word::UNIT_IS_OFF)) |
| 313 | { |
| 314 | log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad", |
| 315 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 316 | powerOnFault++; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | if (powerOnFault > 0) |
| 321 | { |
| 322 | log<level::INFO>("PGOOD and UNIT_IS_OFF bits good"); |
| 323 | powerOnFault = 0; |
| 324 | } |
| 325 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 326 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 327 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 328 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 329 | faultFound = true; |
| 330 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 331 | util::NamesValues nv; |
| 332 | nv.add("STATUS_WORD", statusWord); |
| 333 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 334 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 335 | captureCmd(nv, status0Vout, Type::Debug); |
| 336 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 337 | captureCmd(nv, STATUS_MFR, Type::Debug); |
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 | using metadata = org::open_power::Witherspoon::Fault:: |
| 340 | PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 341 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 342 | // A power supply is OFF (or pgood low) but should be on. |
| 343 | report<PowerSupplyShouldBeOn>( |
| 344 | metadata::RAW_STATUS(nv.get().c_str()), |
| 345 | metadata::CALLOUT_INVENTORY_PATH( |
| 346 | inventoryPath.c_str())); |
| 347 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | } |
| 351 | |
| 352 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 353 | { |
| 354 | using namespace witherspoon::pmbus; |
| 355 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 356 | if (outputOCFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 357 | { |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 358 | // Check for an output overcurrent fault. |
| 359 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 360 | { |
| 361 | outputOCFault++; |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | if (outputOCFault > 0) |
| 366 | { |
| 367 | outputOCFault = 0; |
| 368 | } |
| 369 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 370 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 371 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 372 | { |
| 373 | util::NamesValues nv; |
| 374 | nv.add("STATUS_WORD", statusWord); |
| 375 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 376 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 377 | captureCmd(nv, status0Vout, Type::Debug); |
| 378 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 379 | captureCmd(nv, STATUS_MFR, Type::Debug); |
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 | using metadata = org::open_power::Witherspoon::Fault:: |
| 382 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 383 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 384 | report<PowerSupplyOutputOvercurrent>( |
| 385 | metadata::RAW_STATUS(nv.get().c_str()), |
| 386 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 387 | |
| 388 | faultFound = true; |
| 389 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 393 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 394 | { |
| 395 | using namespace witherspoon::pmbus; |
| 396 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 397 | if (outputOVFault < FAULT_COUNT) |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 398 | { |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 399 | // Check for an output overvoltage fault. |
| 400 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 401 | { |
| 402 | outputOVFault++; |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | if (outputOVFault > 0) |
| 407 | { |
| 408 | outputOVFault = 0; |
| 409 | } |
| 410 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 411 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 412 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 413 | { |
| 414 | util::NamesValues nv; |
| 415 | nv.add("STATUS_WORD", statusWord); |
| 416 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 417 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 418 | captureCmd(nv, status0Vout, Type::Debug); |
| 419 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 420 | captureCmd(nv, STATUS_MFR, Type::Debug); |
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 | using metadata = org::open_power::Witherspoon::Fault:: |
| 423 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 424 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 425 | report<PowerSupplyOutputOvervoltage>( |
| 426 | metadata::RAW_STATUS(nv.get().c_str()), |
| 427 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 428 | |
| 429 | faultFound = true; |
| 430 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 434 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 435 | { |
| 436 | using namespace witherspoon::pmbus; |
| 437 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 438 | if (fanFault < FAULT_COUNT) |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 439 | { |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 440 | // Check for a fan fault or warning condition |
| 441 | if (statusWord & status_word::FAN_FAULT) |
| 442 | { |
| 443 | fanFault++; |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | if (fanFault > 0) |
| 448 | { |
| 449 | fanFault = 0; |
| 450 | } |
| 451 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 452 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 453 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 454 | { |
| 455 | util::NamesValues nv; |
| 456 | nv.add("STATUS_WORD", statusWord); |
| 457 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 458 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 459 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
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 | using metadata = org::open_power::Witherspoon::Fault:: |
| 462 | PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 463 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 464 | report<PowerSupplyFanFault>( |
| 465 | metadata::RAW_STATUS(nv.get().c_str()), |
| 466 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 467 | |
| 468 | faultFound = true; |
| 469 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 473 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 474 | { |
| 475 | using namespace witherspoon::pmbus; |
| 476 | |
| 477 | // Due to how the PMBus core device driver sends a clear faults command |
| 478 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 479 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 480 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 481 | // logging the over-temperature condition. |
| 482 | std::uint8_t statusTemperature = 0; |
| 483 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 484 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 485 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 486 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 487 | (statusTemperature & status_temperature::OT_FAULT)) |
| 488 | { |
| 489 | temperatureFault++; |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | if (temperatureFault > 0) |
| 494 | { |
| 495 | temperatureFault = 0; |
| 496 | } |
| 497 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 498 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 499 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 500 | { |
| 501 | // The power supply has had an over-temperature condition. |
| 502 | // This may not result in a shutdown if experienced for a short |
| 503 | // duration. |
| 504 | // This should not occur under normal conditions. |
| 505 | // The power supply may be faulty, or the paired supply may be |
| 506 | // putting out less current. |
| 507 | // Capture command responses with potentially relevant information, |
| 508 | // and call out the power supply reporting the condition. |
| 509 | util::NamesValues nv; |
| 510 | nv.add("STATUS_WORD", statusWord); |
| 511 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 512 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 513 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 514 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
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 | using metadata = org::open_power::Witherspoon::Fault:: |
| 517 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 518 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 519 | report<PowerSupplyTemperatureFault>( |
| 520 | metadata::RAW_STATUS(nv.get().c_str()), |
| 521 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
| 522 | |
| 523 | faultFound = true; |
| 524 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 528 | void PowerSupply::clearFaults() |
| 529 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 530 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 531 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 532 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 533 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 534 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 535 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 536 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 537 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 538 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 539 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 543 | void PowerSupply::resolveError(const std::string& callout, |
| 544 | const std::string& message) |
| 545 | { |
| 546 | // to be filled in. |
| 547 | return; |
| 548 | } |
| 549 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | } |