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 | */ |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 18 | #include "power_supply.hpp" |
| 19 | |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 20 | #include "elog-errors.hpp" |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 21 | #include "gpio.hpp" |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 22 | #include "names_values.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 23 | #include "pmbus.hpp" |
| 24 | #include "utility.hpp" |
| 25 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 26 | #include <functional> |
| 27 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 28 | #include <phosphor-logging/log.hpp> |
| 29 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 30 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
| 31 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 32 | namespace phosphor |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 33 | { |
| 34 | namespace power |
| 35 | { |
| 36 | namespace psu |
| 37 | { |
| 38 | |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 39 | using namespace phosphor::logging; |
| 40 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
| 41 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 42 | namespace version = sdbusplus::xyz::openbmc_project::Software::server; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 43 | |
Matt Spinler | 5b2964f | 2019-07-24 10:34:31 -0500 | [diff] [blame] | 44 | constexpr auto ASSOCIATION_IFACE = "xyz.openbmc_project.Association"; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 45 | constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry"; |
| 46 | constexpr auto INVENTORY_IFACE = "xyz.openbmc_project.Inventory.Item"; |
| 47 | constexpr auto POWER_IFACE = "org.openbmc.control.Power"; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 48 | constexpr auto INVENTORY_MGR_IFACE = "xyz.openbmc_project.Inventory.Manager"; |
| 49 | constexpr auto ASSET_IFACE = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
| 50 | constexpr auto VERSION_IFACE = "xyz.openbmc_project.Software.Version"; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 51 | |
| 52 | constexpr auto ENDPOINTS_PROP = "endpoints"; |
| 53 | constexpr auto MESSAGE_PROP = "Message"; |
| 54 | constexpr auto RESOLVED_PROP = "Resolved"; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 55 | constexpr auto PRESENT_PROP = "Present"; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 56 | constexpr auto VERSION_PURPOSE_PROP = "Purpose"; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 57 | |
| 58 | constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory"; |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 59 | constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0"; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 60 | |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 61 | constexpr auto INPUT_HISTORY = "input_history"; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 62 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 63 | PowerSupply::PowerSupply(const std::string& name, size_t inst, |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 64 | const std::string& objpath, const std::string& invpath, |
| 65 | sdbusplus::bus::bus& bus, const sdeventplus::Event& e, |
| 66 | std::chrono::seconds& t, std::chrono::seconds& p) : |
| 67 | Device(name, inst), |
| 68 | monitorPath(objpath), pmbusIntf(objpath), |
| 69 | inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), presentInterval(p), |
| 70 | presentTimer(e, std::bind([this]() { |
| 71 | // The hwmon path may have changed. |
| 72 | pmbusIntf.findHwmonDir(); |
| 73 | this->present = true; |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 74 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 75 | // Sync the INPUT_HISTORY data for all PSs |
| 76 | syncHistory(); |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 77 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 78 | // Update the inventory for the new device |
| 79 | updateInventory(); |
| 80 | })), |
| 81 | powerOnInterval(t), |
| 82 | powerOnTimer(e, std::bind([this]() { this->powerOn = true; })) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 83 | { |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 84 | getAccessType(); |
| 85 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 86 | using namespace sdbusplus::bus; |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 87 | using namespace phosphor::pmbus; |
Aatir Manzur | 817f8a7 | 2019-08-07 07:42:15 -0500 | [diff] [blame] | 88 | std::uint16_t statusWord = 0; |
| 89 | try |
| 90 | { |
| 91 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 92 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
| 93 | if (!((statusWord & status_word::INPUT_FAULT_WARN) || |
| 94 | (statusWord & status_word::VIN_UV_FAULT))) |
| 95 | { |
| 96 | resolveError(inventoryPath, |
| 97 | std::string(PowerSupplyInputFault::errName)); |
| 98 | } |
| 99 | } |
| 100 | catch (ReadFailure& e) |
| 101 | { |
| 102 | log<level::INFO>("Unable to read the 2 byte STATUS_WORD value to check " |
| 103 | "for power-supply input faults."); |
| 104 | } |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 105 | presentMatch = std::make_unique<match_t>( |
| 106 | bus, match::rules::propertiesChanged(inventoryPath, INVENTORY_IFACE), |
| 107 | [this](auto& msg) { this->inventoryChanged(msg); }); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 108 | // Get initial presence state. |
Brandon Wyman | 253dc9b | 2017-08-12 13:45:52 -0500 | [diff] [blame] | 109 | updatePresence(); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 110 | |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 111 | // Write the SN, PN, etc to the inventory |
| 112 | updateInventory(); |
| 113 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 114 | // Subscribe to power state changes |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 115 | powerOnMatch = std::make_unique<match_t>( |
| 116 | bus, match::rules::propertiesChanged(POWER_OBJ_PATH, POWER_IFACE), |
| 117 | [this](auto& msg) { this->powerStateChanged(msg); }); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 118 | // Get initial power state. |
| 119 | updatePowerState(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 120 | } |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 121 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 122 | void PowerSupply::getAccessType() |
| 123 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 124 | using namespace phosphor::power::util; |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 125 | fruJson = loadJSONFromFile(PSU_JSON_PATH); |
| 126 | if (fruJson == nullptr) |
| 127 | { |
| 128 | log<level::ERR>("InternalFailure when parsing the JSON file"); |
| 129 | return; |
| 130 | } |
Lei YU | 4070546 | 2019-10-09 17:07:11 +0800 | [diff] [blame] | 131 | inventoryPMBusAccessType = getPMBusAccessType(fruJson); |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 132 | } |
| 133 | |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 134 | void PowerSupply::captureCmd(util::NamesValues& nv, const std::string& cmd, |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 135 | phosphor::pmbus::Type type) |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 136 | { |
| 137 | if (pmbusIntf.exists(cmd, type)) |
| 138 | { |
| 139 | try |
| 140 | { |
| 141 | auto val = pmbusIntf.read(cmd, type); |
| 142 | nv.add(cmd, val); |
| 143 | } |
| 144 | catch (std::exception& e) |
| 145 | { |
Joseph Reynolds | 5b48596 | 2018-05-17 16:05:06 -0500 | [diff] [blame] | 146 | log<level::INFO>("Unable to capture metadata", |
| 147 | entry("CMD=%s", cmd.c_str())); |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 151 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 152 | void PowerSupply::analyze() |
| 153 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 154 | using namespace phosphor::pmbus; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 155 | |
| 156 | try |
| 157 | { |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 158 | if (present) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 159 | { |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 160 | std::uint16_t statusWord = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 161 | |
| 162 | // Read the 2 byte STATUS_WORD value to check for faults. |
| 163 | statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug); |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 164 | readFail = 0; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 165 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 166 | checkInputFault(statusWord); |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 167 | |
Brandon Wyman | 654eb6e | 2018-02-14 14:55:47 -0600 | [diff] [blame] | 168 | if (powerOn && (inputFault == 0) && !faultFound) |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 169 | { |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 170 | checkFanFault(statusWord); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 171 | checkTemperatureFault(statusWord); |
Brandon Wyman | cfa032b | 2017-09-25 17:37:50 -0500 | [diff] [blame] | 172 | checkOutputOvervoltageFault(statusWord); |
| 173 | checkCurrentOutOverCurrentFault(statusWord); |
| 174 | checkPGOrUnitOffFault(statusWord); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 175 | } |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 176 | |
| 177 | updateHistory(); |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | catch (ReadFailure& e) |
| 181 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 182 | if (readFail < FAULT_COUNT) |
| 183 | { |
| 184 | readFail++; |
| 185 | } |
| 186 | |
| 187 | if (!readFailLogged && readFail >= FAULT_COUNT) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 188 | { |
| 189 | commit<ReadFailure>(); |
| 190 | readFailLogged = true; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 194 | return; |
| 195 | } |
| 196 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 197 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 198 | { |
| 199 | std::string msgSensor; |
| 200 | std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData; |
| 201 | msg.read(msgSensor, msgData); |
| 202 | |
| 203 | // Check if it was the Present property that changed. |
| 204 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 205 | if (valPropMap != msgData.end()) |
| 206 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 207 | if (sdbusplus::message::variant_ns::get<bool>(valPropMap->second)) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 208 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 209 | clearFaults(); |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 210 | presentTimer.restartOnce(presentInterval); |
Brandon Wyman | 590fc28 | 2017-11-01 18:22:25 -0500 | [diff] [blame] | 211 | } |
| 212 | else |
| 213 | { |
Brandon Wyman | 2ef48cf | 2017-11-21 15:43:54 -0600 | [diff] [blame] | 214 | present = false; |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 215 | presentTimer.setEnabled(false); |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 216 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 217 | // Clear out the now outdated inventory properties |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 218 | updateInventory(); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | void PowerSupply::updatePresence() |
| 226 | { |
| 227 | // Use getProperty utility function to get presence status. |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 228 | std::string service = "xyz.openbmc_project.Inventory.Manager"; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 229 | util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath, service, |
| 230 | bus, this->present); |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 233 | void PowerSupply::powerStateChanged(sdbusplus::message::message& msg) |
| 234 | { |
| 235 | int32_t state = 0; |
| 236 | std::string msgSensor; |
William A. Kennington III | ac9d5c3 | 2018-11-12 14:58:39 -0800 | [diff] [blame] | 237 | std::map<std::string, sdbusplus::message::variant<int32_t>> msgData; |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 238 | msg.read(msgSensor, msgData); |
| 239 | |
| 240 | // Check if it was the Present property that changed. |
| 241 | auto valPropMap = msgData.find("state"); |
| 242 | if (valPropMap != msgData.end()) |
| 243 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 244 | state = |
| 245 | sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 246 | |
| 247 | // Power is on when state=1. Set the fault logged variables to false |
| 248 | // and start the power on timer when the state changes to 1. |
| 249 | if (state) |
| 250 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 251 | clearFaults(); |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 252 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 253 | } |
| 254 | else |
| 255 | { |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 256 | powerOnTimer.setEnabled(false); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 257 | powerOn = false; |
| 258 | } |
| 259 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void PowerSupply::updatePowerState() |
| 263 | { |
| 264 | // When state = 1, system is powered on |
| 265 | int32_t state = 0; |
| 266 | |
| 267 | try |
| 268 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 269 | auto service = util::getService(POWER_OBJ_PATH, POWER_IFACE, bus); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 270 | |
| 271 | // Use getProperty utility function to get power state. |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 272 | util::getProperty<int32_t>(POWER_IFACE, "state", POWER_OBJ_PATH, |
| 273 | service, bus, state); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 274 | |
| 275 | if (state) |
| 276 | { |
| 277 | powerOn = true; |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | powerOn = false; |
| 282 | } |
| 283 | } |
| 284 | catch (std::exception& e) |
| 285 | { |
| 286 | log<level::INFO>("Failed to get power state. Assuming it is off."); |
| 287 | powerOn = false; |
| 288 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 291 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 292 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 293 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 294 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 295 | if ((inputFault < FAULT_COUNT) && |
| 296 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 297 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 298 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 299 | if (inputFault == 0) |
| 300 | { |
| 301 | log<level::INFO>("INPUT or VIN_UV fault", |
| 302 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 303 | } |
| 304 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 305 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 306 | } |
| 307 | else |
| 308 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 309 | if ((inputFault > 0) && !(statusWord & status_word::INPUT_FAULT_WARN) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 310 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 311 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 312 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 313 | faultFound = false; |
Brandon Wyman | 7502f6c | 2018-02-12 20:20:39 -0600 | [diff] [blame] | 314 | // When an input fault occurs, the power supply cannot be on. |
| 315 | // However, the check for the case where the power supply should be |
| 316 | // on will stop when there is a fault found. |
| 317 | // Clear the powerOnFault when the inputFault is cleared to reset |
| 318 | // the powerOnFault de-glitching. |
| 319 | powerOnFault = 0; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 320 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 321 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 322 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 323 | |
Brandon Wyman | 08b0571 | 2017-11-30 17:53:56 -0600 | [diff] [blame] | 324 | resolveError(inventoryPath, |
| 325 | std::string(PowerSupplyInputFault::errName)); |
| 326 | |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 327 | if (powerOn) |
| 328 | { |
| 329 | // The power supply will not be immediately powered on after |
| 330 | // the input power is restored. |
| 331 | powerOn = false; |
| 332 | // Start up the timer that will set the state to indicate we |
| 333 | // are ready for the powered on fault checks. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 334 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 335 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 336 | } |
| 337 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 338 | |
| 339 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 340 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 341 | // If the power is on, report the fault in an error log entry. |
| 342 | if (powerOn) |
| 343 | { |
| 344 | util::NamesValues nv; |
| 345 | nv.add("STATUS_WORD", statusWord); |
| 346 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 347 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 348 | using metadata = |
| 349 | org::open_power::Witherspoon::Fault::PowerSupplyInputFault; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 350 | |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 351 | report<PowerSupplyInputFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 352 | metadata::RAW_STATUS(nv.get().c_str()), |
| 353 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 354 | |
| 355 | faultFound = true; |
| 356 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 357 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 361 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 362 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 363 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 364 | if (powerOnFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 365 | { |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 366 | // Check PG# and UNIT_IS_OFF |
| 367 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 368 | (statusWord & status_word::UNIT_IS_OFF)) |
| 369 | { |
| 370 | log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad", |
| 371 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 372 | powerOnFault++; |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | if (powerOnFault > 0) |
| 377 | { |
| 378 | log<level::INFO>("PGOOD and UNIT_IS_OFF bits good"); |
| 379 | powerOnFault = 0; |
| 380 | } |
| 381 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 382 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 383 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 384 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 385 | faultFound = true; |
| 386 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 387 | util::NamesValues nv; |
| 388 | nv.add("STATUS_WORD", statusWord); |
| 389 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 390 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 391 | captureCmd(nv, status0Vout, Type::Debug); |
| 392 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 393 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 394 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 395 | using metadata = |
| 396 | org::open_power::Witherspoon::Fault::PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 397 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 398 | // A power supply is OFF (or pgood low) but should be on. |
| 399 | report<PowerSupplyShouldBeOn>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 400 | metadata::RAW_STATUS(nv.get().c_str()), |
| 401 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 402 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 403 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 407 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 408 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 409 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 410 | if (outputOCFault < FAULT_COUNT) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 411 | { |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 412 | // Check for an output overcurrent fault. |
| 413 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 414 | { |
| 415 | outputOCFault++; |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | if (outputOCFault > 0) |
| 420 | { |
| 421 | outputOCFault = 0; |
| 422 | } |
| 423 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 424 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 425 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 426 | { |
| 427 | util::NamesValues nv; |
| 428 | nv.add("STATUS_WORD", statusWord); |
| 429 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 430 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 431 | captureCmd(nv, status0Vout, Type::Debug); |
| 432 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 433 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 434 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 435 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 436 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 437 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 438 | report<PowerSupplyOutputOvercurrent>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 439 | metadata::RAW_STATUS(nv.get().c_str()), |
| 440 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 441 | |
| 442 | faultFound = true; |
| 443 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 447 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 448 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 449 | using namespace phosphor::pmbus; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 450 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 451 | if (outputOVFault < FAULT_COUNT) |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 452 | { |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 453 | // Check for an output overvoltage fault. |
| 454 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 455 | { |
| 456 | outputOVFault++; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | if (outputOVFault > 0) |
| 461 | { |
| 462 | outputOVFault = 0; |
| 463 | } |
| 464 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 465 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 466 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 467 | { |
| 468 | util::NamesValues nv; |
| 469 | nv.add("STATUS_WORD", statusWord); |
| 470 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 471 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 472 | captureCmd(nv, status0Vout, Type::Debug); |
| 473 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 474 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 475 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 476 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 477 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 478 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 479 | report<PowerSupplyOutputOvervoltage>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 480 | metadata::RAW_STATUS(nv.get().c_str()), |
| 481 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 482 | |
| 483 | faultFound = true; |
| 484 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 488 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 489 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 490 | using namespace phosphor::pmbus; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 491 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 492 | if (fanFault < FAULT_COUNT) |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 493 | { |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 494 | // Check for a fan fault or warning condition |
| 495 | if (statusWord & status_word::FAN_FAULT) |
| 496 | { |
| 497 | fanFault++; |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | if (fanFault > 0) |
| 502 | { |
| 503 | fanFault = 0; |
| 504 | } |
| 505 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 506 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 507 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 508 | { |
| 509 | util::NamesValues nv; |
| 510 | nv.add("STATUS_WORD", statusWord); |
| 511 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 512 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 513 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 514 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 515 | using metadata = |
| 516 | org::open_power::Witherspoon::Fault::PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 517 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 518 | report<PowerSupplyFanFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 519 | metadata::RAW_STATUS(nv.get().c_str()), |
| 520 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 521 | |
| 522 | faultFound = true; |
| 523 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 527 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 528 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 529 | using namespace phosphor::pmbus; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 530 | |
| 531 | // Due to how the PMBus core device driver sends a clear faults command |
| 532 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 533 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 534 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 535 | // logging the over-temperature condition. |
| 536 | std::uint8_t statusTemperature = 0; |
| 537 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 538 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 539 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 540 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 541 | (statusTemperature & status_temperature::OT_FAULT)) |
| 542 | { |
| 543 | temperatureFault++; |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | if (temperatureFault > 0) |
| 548 | { |
| 549 | temperatureFault = 0; |
| 550 | } |
| 551 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 552 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 553 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 554 | { |
| 555 | // The power supply has had an over-temperature condition. |
| 556 | // This may not result in a shutdown if experienced for a short |
| 557 | // duration. |
| 558 | // This should not occur under normal conditions. |
| 559 | // The power supply may be faulty, or the paired supply may be |
| 560 | // putting out less current. |
| 561 | // Capture command responses with potentially relevant information, |
| 562 | // and call out the power supply reporting the condition. |
| 563 | util::NamesValues nv; |
| 564 | nv.add("STATUS_WORD", statusWord); |
| 565 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 566 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 567 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 568 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 569 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 570 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 571 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 572 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 573 | report<PowerSupplyTemperatureFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 574 | metadata::RAW_STATUS(nv.get().c_str()), |
| 575 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 576 | |
| 577 | faultFound = true; |
| 578 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 582 | void PowerSupply::clearFaults() |
| 583 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 584 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 585 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 586 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 587 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 588 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 589 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 590 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 591 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 592 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 593 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 597 | void PowerSupply::resolveError(const std::string& callout, |
| 598 | const std::string& message) |
| 599 | { |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 600 | using EndpointList = std::vector<std::string>; |
| 601 | |
| 602 | try |
| 603 | { |
| 604 | auto path = callout + "/fault"; |
| 605 | // Get the service name from the mapper for the fault callout |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 606 | auto service = util::getService(path, ASSOCIATION_IFACE, bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 607 | |
| 608 | // Use getProperty utility function to get log entries (endpoints) |
| 609 | EndpointList logEntries; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 610 | util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service, bus, |
| 611 | logEntries); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 612 | |
| 613 | // It is possible that all such entries for this callout have since |
| 614 | // been deleted. |
| 615 | if (logEntries.empty()) |
| 616 | { |
| 617 | return; |
| 618 | } |
| 619 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 620 | auto logEntryService = |
| 621 | util::getService(logEntries[0], LOGGING_IFACE, bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 622 | if (logEntryService.empty()) |
| 623 | { |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | // go through each log entry that matches this callout path |
| 628 | std::string logMessage; |
| 629 | for (const auto& logEntry : logEntries) |
| 630 | { |
| 631 | // Check to see if this logEntry has a message that matches. |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 632 | util::getProperty(LOGGING_IFACE, MESSAGE_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 633 | logEntryService, bus, logMessage); |
| 634 | |
| 635 | if (message == logMessage) |
| 636 | { |
| 637 | // Log entry matches call out and message, set Resolved to true |
| 638 | bool resolved = true; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 639 | util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 640 | logEntryService, bus, resolved); |
| 641 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 642 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 643 | } |
| 644 | catch (std::exception& e) |
| 645 | { |
| 646 | log<level::INFO>("Failed to resolve error", |
| 647 | entry("CALLOUT=%s", callout.c_str()), |
Matt Spinler | 0d09f29 | 2018-01-22 14:51:26 -0600 | [diff] [blame] | 648 | entry("ERROR=%s", message.c_str())); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 649 | } |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 650 | } |
| 651 | |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 652 | void PowerSupply::updateInventory() |
| 653 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 654 | using namespace phosphor::pmbus; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 655 | using namespace sdbusplus::message; |
| 656 | |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 657 | // Build the object map and send it to the inventory |
| 658 | using Properties = std::map<std::string, variant<std::string>>; |
| 659 | using Interfaces = std::map<std::string, Properties>; |
| 660 | using Object = std::map<object_path, Interfaces>; |
| 661 | Properties assetProps; |
| 662 | Properties versionProps; |
| 663 | Interfaces interfaces; |
| 664 | Object object; |
| 665 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 666 | // If any of these accesses fail, the fields will just be |
| 667 | // blank in the inventory. Leave logging ReadFailure errors |
| 668 | // to analyze() as it runs continuously and will most |
| 669 | // likely hit and threshold them first anyway. The |
| 670 | // readString() function will do the tracing of the failing |
| 671 | // path so this code doesn't need to. |
| 672 | for (const auto& fru : fruJson.at("fruConfigs")) |
| 673 | { |
| 674 | if (fru.at("interface") == ASSET_IFACE) |
| 675 | { |
| 676 | try |
| 677 | { |
| 678 | assetProps.emplace( |
| 679 | fru.at("propertyName"), |
| 680 | present ? pmbusIntf.readString(fru.at("fileName"), |
| 681 | inventoryPMBusAccessType) |
| 682 | : ""); |
| 683 | } |
| 684 | catch (ReadFailure& e) |
| 685 | { |
| 686 | } |
| 687 | } |
| 688 | else if (fru.at("interface") == VERSION_IFACE) |
| 689 | { |
| 690 | try |
| 691 | { |
| 692 | versionProps.emplace( |
| 693 | fru.at("propertyName"), |
| 694 | present ? pmbusIntf.readString(fru.at("fileName"), |
| 695 | inventoryPMBusAccessType) |
| 696 | : ""); |
| 697 | } |
| 698 | catch (const std::exception& e) |
| 699 | { |
| 700 | } |
| 701 | } |
| 702 | } |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 703 | |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 704 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 705 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 706 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 707 | // For Notify(), just send the relative path of the inventory |
| 708 | // object so remove the INVENTORY_OBJ_PATH prefix |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 709 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 710 | |
| 711 | object.emplace(path, std::move(interfaces)); |
| 712 | |
| 713 | try |
| 714 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 715 | auto service = |
| 716 | util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 717 | |
| 718 | if (service.empty()) |
| 719 | { |
| 720 | log<level::ERR>("Unable to get inventory manager service"); |
| 721 | return; |
| 722 | } |
| 723 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 724 | auto method = bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 725 | INVENTORY_MGR_IFACE, "Notify"); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 726 | |
| 727 | method.append(std::move(object)); |
| 728 | |
| 729 | auto reply = bus.call(method); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 730 | |
| 731 | // TODO: openbmc/openbmc#2756 |
| 732 | // Calling Notify() with an enumerated property crashes inventory |
| 733 | // manager, so let it default to Unknown and now set it to the |
| 734 | // right value. |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 735 | auto purpose = |
| 736 | version::convertForMessage(version::Version::VersionPurpose::Other); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 737 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 738 | util::setProperty(VERSION_IFACE, VERSION_PURPOSE_PROP, inventoryPath, |
| 739 | service, bus, purpose); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 740 | } |
| 741 | catch (std::exception& e) |
| 742 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 743 | log<level::ERR>(e.what(), entry("PATH=%s", inventoryPath.c_str())); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 744 | } |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 745 | } |
| 746 | |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 747 | void PowerSupply::syncHistory() |
| 748 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 749 | using namespace phosphor::gpio; |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 750 | |
| 751 | if (syncGPIODevPath.empty()) |
| 752 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 753 | // Sync not implemented |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 757 | GPIO gpio{syncGPIODevPath, static_cast<gpioNum_t>(syncGPIONumber), |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 758 | Direction::output}; |
| 759 | |
| 760 | try |
| 761 | { |
| 762 | gpio.set(Value::low); |
| 763 | |
| 764 | std::this_thread::sleep_for(std::chrono::milliseconds{5}); |
| 765 | |
| 766 | gpio.set(Value::high); |
| 767 | |
| 768 | recordManager->clear(); |
| 769 | } |
| 770 | catch (std::exception& e) |
| 771 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 772 | // Do nothing. There would already be a journal entry. |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
Matt Spinler | 8238414 | 2018-01-18 14:15:03 -0600 | [diff] [blame] | 776 | void PowerSupply::enableHistory(const std::string& objectPath, |
| 777 | size_t numRecords, |
| 778 | const std::string& syncGPIOPath, |
| 779 | size_t syncGPIONum) |
| 780 | { |
| 781 | historyObjectPath = objectPath; |
| 782 | syncGPIODevPath = syncGPIOPath; |
| 783 | syncGPIONumber = syncGPIONum; |
| 784 | |
| 785 | recordManager = std::make_unique<history::RecordManager>(numRecords); |
| 786 | |
| 787 | auto avgPath = historyObjectPath + '/' + history::Average::name; |
| 788 | auto maxPath = historyObjectPath + '/' + history::Maximum::name; |
| 789 | |
| 790 | average = std::make_unique<history::Average>(bus, avgPath); |
| 791 | |
| 792 | maximum = std::make_unique<history::Maximum>(bus, maxPath); |
| 793 | } |
| 794 | |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 795 | void PowerSupply::updateHistory() |
| 796 | { |
| 797 | if (!recordManager) |
| 798 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 799 | // Not enabled |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 803 | // Read just the most recent average/max record |
| 804 | auto data = |
| 805 | pmbusIntf.readBinary(INPUT_HISTORY, pmbus::Type::HwmonDeviceDebug, |
| 806 | history::RecordManager::RAW_RECORD_SIZE); |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 807 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 808 | // Update D-Bus only if something changed (a new record ID, or cleared out) |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 809 | auto changed = recordManager->add(data); |
| 810 | if (changed) |
| 811 | { |
| 812 | average->values(std::move(recordManager->getAverageRecords())); |
| 813 | maximum->values(std::move(recordManager->getMaximumRecords())); |
| 814 | } |
| 815 | } |
| 816 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 817 | } // namespace psu |
| 818 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 819 | } // namespace phosphor |