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