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