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