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, |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 46 | sdbusplus::bus_t& bus, const sdeventplus::Event& e, |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 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 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 81 | catch (const ReadFailure& e) |
Aatir Manzur | 817f8a7 | 2019-08-07 07:42:15 -0500 | [diff] [blame] | 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 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 125 | catch (const std::exception& e) |
Brandon Wyman | a1e9634 | 2017-09-25 16:47:44 -0500 | [diff] [blame] | 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 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 161 | catch (const ReadFailure& e) |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 178 | void PowerSupply::inventoryChanged(sdbusplus::message_t& msg) |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 179 | { |
| 180 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 181 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 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 | { |
Patrick Williams | 365d61c | 2020-05-13 12:23:08 -0500 | [diff] [blame] | 188 | if (std::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 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 214 | void PowerSupply::powerStateChanged(sdbusplus::message_t& msg) |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 215 | { |
| 216 | int32_t state = 0; |
| 217 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 218 | std::map<std::string, std::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 | { |
Patrick Williams | 365d61c | 2020-05-13 12:23:08 -0500 | [diff] [blame] | 225 | state = std::get<int32_t>(valPropMap->second); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 226 | |
| 227 | // Power is on when state=1. Set the fault logged variables to false |
| 228 | // and start the power on timer when the state changes to 1. |
| 229 | if (state) |
| 230 | { |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 231 | clearFaults(); |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 232 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 233 | } |
| 234 | else |
| 235 | { |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 236 | powerOnTimer.setEnabled(false); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 237 | powerOn = false; |
| 238 | } |
| 239 | } |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void PowerSupply::updatePowerState() |
| 243 | { |
Lei YU | cfc040c | 2019-10-29 17:10:26 +0800 | [diff] [blame] | 244 | powerOn = util::isPoweredOn(bus); |
Brandon Wyman | 431fbe4 | 2017-08-18 16:22:09 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 247 | void PowerSupply::checkInputFault(const uint16_t statusWord) |
| 248 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 249 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 250 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 251 | if ((inputFault < FAULT_COUNT) && |
| 252 | ((statusWord & status_word::INPUT_FAULT_WARN) || |
| 253 | (statusWord & status_word::VIN_UV_FAULT))) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 254 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 255 | if (inputFault == 0) |
| 256 | { |
| 257 | log<level::INFO>("INPUT or VIN_UV fault", |
| 258 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 259 | } |
| 260 | |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 261 | inputFault++; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 262 | } |
| 263 | else |
| 264 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 265 | if ((inputFault > 0) && !(statusWord & status_word::INPUT_FAULT_WARN) && |
Brandon Wyman | d20686a | 2017-11-01 17:45:23 -0500 | [diff] [blame] | 266 | !(statusWord & status_word::VIN_UV_FAULT)) |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 267 | { |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 268 | inputFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 269 | faultFound = false; |
Brandon Wyman | 7502f6c | 2018-02-12 20:20:39 -0600 | [diff] [blame] | 270 | // When an input fault occurs, the power supply cannot be on. |
| 271 | // However, the check for the case where the power supply should be |
| 272 | // on will stop when there is a fault found. |
| 273 | // Clear the powerOnFault when the inputFault is cleared to reset |
| 274 | // the powerOnFault de-glitching. |
| 275 | powerOnFault = 0; |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 276 | |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 277 | log<level::INFO>("INPUT_FAULT_WARN cleared", |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 278 | entry("POWERSUPPLY=%s", inventoryPath.c_str())); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 279 | |
Brandon Wyman | 08b0571 | 2017-11-30 17:53:56 -0600 | [diff] [blame] | 280 | resolveError(inventoryPath, |
| 281 | std::string(PowerSupplyInputFault::errName)); |
| 282 | |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 283 | if (powerOn) |
| 284 | { |
| 285 | // The power supply will not be immediately powered on after |
| 286 | // the input power is restored. |
| 287 | powerOn = false; |
| 288 | // Start up the timer that will set the state to indicate we |
| 289 | // are ready for the powered on fault checks. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 290 | powerOnTimer.restartOnce(powerOnInterval); |
Brandon Wyman | 69591bd | 2017-11-01 18:07:23 -0500 | [diff] [blame] | 291 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 292 | } |
| 293 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 294 | |
| 295 | if (!faultFound && (inputFault >= FAULT_COUNT)) |
| 296 | { |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 297 | // If the power is on, report the fault in an error log entry. |
| 298 | if (powerOn) |
| 299 | { |
| 300 | util::NamesValues nv; |
| 301 | nv.add("STATUS_WORD", statusWord); |
| 302 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 303 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 304 | using metadata = |
| 305 | org::open_power::Witherspoon::Fault::PowerSupplyInputFault; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 306 | |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 307 | report<PowerSupplyInputFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 308 | metadata::RAW_STATUS(nv.get().c_str()), |
| 309 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ad70824 | 2018-01-19 17:28:35 -0600 | [diff] [blame] | 310 | |
| 311 | faultFound = true; |
| 312 | } |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 313 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord) |
| 317 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 318 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 319 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 320 | if (powerOnFault < FAULT_COUNT) |
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 | // Check PG# and UNIT_IS_OFF |
| 323 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 324 | (statusWord & status_word::UNIT_IS_OFF)) |
| 325 | { |
| 326 | log<level::INFO>("PGOOD or UNIT_IS_OFF bit bad", |
| 327 | entry("STATUS_WORD=0x%04X", statusWord)); |
| 328 | powerOnFault++; |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | if (powerOnFault > 0) |
| 333 | { |
| 334 | log<level::INFO>("PGOOD and UNIT_IS_OFF bits good"); |
| 335 | powerOnFault = 0; |
| 336 | } |
| 337 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 338 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 339 | if (!faultFound && (powerOnFault >= FAULT_COUNT)) |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 340 | { |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 341 | faultFound = true; |
| 342 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 343 | util::NamesValues nv; |
| 344 | nv.add("STATUS_WORD", statusWord); |
| 345 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 346 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 347 | captureCmd(nv, status0Vout, Type::Debug); |
| 348 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 349 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 350 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 351 | using metadata = |
| 352 | org::open_power::Witherspoon::Fault::PowerSupplyShouldBeOn; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 353 | |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 354 | // A power supply is OFF (or pgood low) but should be on. |
| 355 | report<PowerSupplyShouldBeOn>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 356 | metadata::RAW_STATUS(nv.get().c_str()), |
| 357 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 593d24f | 2017-10-13 18:15:23 -0500 | [diff] [blame] | 358 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 359 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord) |
| 363 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 364 | using namespace phosphor::pmbus; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 365 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 366 | if (outputOCFault < FAULT_COUNT) |
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 | // Check for an output overcurrent fault. |
| 369 | if ((statusWord & status_word::IOUT_OC_FAULT)) |
| 370 | { |
| 371 | outputOCFault++; |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | if (outputOCFault > 0) |
| 376 | { |
| 377 | outputOCFault = 0; |
| 378 | } |
| 379 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 380 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 381 | if (!faultFound && (outputOCFault >= FAULT_COUNT)) |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 382 | { |
| 383 | util::NamesValues nv; |
| 384 | nv.add("STATUS_WORD", statusWord); |
| 385 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 386 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 387 | captureCmd(nv, status0Vout, Type::Debug); |
| 388 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 389 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 390 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 391 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 392 | PowerSupplyOutputOvercurrent; |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 393 | |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 394 | report<PowerSupplyOutputOvercurrent>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 395 | metadata::RAW_STATUS(nv.get().c_str()), |
| 396 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 397 | |
| 398 | faultFound = true; |
| 399 | } |
Brandon Wyman | 603cc00 | 2017-08-28 18:17:58 -0500 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 403 | void PowerSupply::checkOutputOvervoltageFault(const uint16_t statusWord) |
| 404 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 405 | using namespace phosphor::pmbus; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 406 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 407 | if (outputOVFault < FAULT_COUNT) |
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 | // Check for an output overvoltage fault. |
| 410 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 411 | { |
| 412 | outputOVFault++; |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | if (outputOVFault > 0) |
| 417 | { |
| 418 | outputOVFault = 0; |
| 419 | } |
| 420 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 421 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 422 | if (!faultFound && (outputOVFault >= FAULT_COUNT)) |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 423 | { |
| 424 | util::NamesValues nv; |
| 425 | nv.add("STATUS_WORD", statusWord); |
| 426 | captureCmd(nv, STATUS_INPUT, Type::Debug); |
| 427 | auto status0Vout = pmbusIntf.insertPageNum(STATUS_VOUT, 0); |
| 428 | captureCmd(nv, status0Vout, Type::Debug); |
| 429 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 430 | captureCmd(nv, STATUS_MFR, Type::Debug); |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 431 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 432 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 433 | PowerSupplyOutputOvervoltage; |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 434 | |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 435 | report<PowerSupplyOutputOvervoltage>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 436 | metadata::RAW_STATUS(nv.get().c_str()), |
| 437 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 438 | |
| 439 | faultFound = true; |
| 440 | } |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 444 | void PowerSupply::checkFanFault(const uint16_t statusWord) |
| 445 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 446 | using namespace phosphor::pmbus; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 447 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 448 | if (fanFault < FAULT_COUNT) |
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 | // Check for a fan fault or warning condition |
| 451 | if (statusWord & status_word::FAN_FAULT) |
| 452 | { |
| 453 | fanFault++; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | if (fanFault > 0) |
| 458 | { |
| 459 | fanFault = 0; |
| 460 | } |
| 461 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 462 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 463 | if (!faultFound && (fanFault >= FAULT_COUNT)) |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 464 | { |
| 465 | util::NamesValues nv; |
| 466 | nv.add("STATUS_WORD", statusWord); |
| 467 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 468 | captureCmd(nv, STATUS_TEMPERATURE, Type::Debug); |
| 469 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 470 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 471 | using metadata = |
| 472 | org::open_power::Witherspoon::Fault::PowerSupplyFanFault; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 473 | |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 474 | report<PowerSupplyFanFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 475 | metadata::RAW_STATUS(nv.get().c_str()), |
| 476 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 477 | |
| 478 | faultFound = true; |
| 479 | } |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 483 | void PowerSupply::checkTemperatureFault(const uint16_t statusWord) |
| 484 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 485 | using namespace phosphor::pmbus; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 486 | |
| 487 | // Due to how the PMBus core device driver sends a clear faults command |
| 488 | // the bit in STATUS_WORD will likely be cleared when we attempt to examine |
| 489 | // it for a Thermal Fault or Warning. So, check the STATUS_WORD and the |
| 490 | // STATUS_TEMPERATURE bits. If either indicates a fault, proceed with |
| 491 | // logging the over-temperature condition. |
| 492 | std::uint8_t statusTemperature = 0; |
| 493 | statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 494 | if (temperatureFault < FAULT_COUNT) |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 495 | { |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 496 | if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) || |
| 497 | (statusTemperature & status_temperature::OT_FAULT)) |
| 498 | { |
| 499 | temperatureFault++; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | if (temperatureFault > 0) |
| 504 | { |
| 505 | temperatureFault = 0; |
| 506 | } |
| 507 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 508 | |
Brandon Wyman | e2fc7aa | 2017-11-13 17:37:10 -0600 | [diff] [blame] | 509 | if (!faultFound && (temperatureFault >= FAULT_COUNT)) |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 510 | { |
| 511 | // The power supply has had an over-temperature condition. |
| 512 | // This may not result in a shutdown if experienced for a short |
| 513 | // duration. |
| 514 | // This should not occur under normal conditions. |
| 515 | // The power supply may be faulty, or the paired supply may be |
| 516 | // putting out less current. |
| 517 | // Capture command responses with potentially relevant information, |
| 518 | // and call out the power supply reporting the condition. |
| 519 | util::NamesValues nv; |
| 520 | nv.add("STATUS_WORD", statusWord); |
| 521 | captureCmd(nv, STATUS_MFR, Type::Debug); |
| 522 | captureCmd(nv, STATUS_IOUT, Type::Debug); |
| 523 | nv.add("STATUS_TEMPERATURE", statusTemperature); |
| 524 | captureCmd(nv, STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 525 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 526 | using metadata = org::open_power::Witherspoon::Fault:: |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 527 | PowerSupplyTemperatureFault; |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 528 | |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 529 | report<PowerSupplyTemperatureFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 530 | metadata::RAW_STATUS(nv.get().c_str()), |
| 531 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 532 | |
| 533 | faultFound = true; |
| 534 | } |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 538 | void PowerSupply::clearFaults() |
| 539 | { |
Brandon Wyman | e4af980 | 2017-11-13 15:58:33 -0600 | [diff] [blame] | 540 | readFail = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 541 | readFailLogged = false; |
Brandon Wyman | a3c675c | 2017-11-14 14:54:54 -0600 | [diff] [blame] | 542 | inputFault = 0; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 543 | powerOnFault = 0; |
Brandon Wyman | dd61be4 | 2017-11-07 18:38:54 -0600 | [diff] [blame] | 544 | outputOCFault = 0; |
Brandon Wyman | 2ab319b | 2017-11-08 17:34:59 -0600 | [diff] [blame] | 545 | outputOVFault = 0; |
Brandon Wyman | ba25553 | 2017-11-08 17:44:10 -0600 | [diff] [blame] | 546 | fanFault = 0; |
Brandon Wyman | 50044ea | 2017-11-08 17:58:56 -0600 | [diff] [blame] | 547 | temperatureFault = 0; |
Brandon Wyman | 3343e82 | 2017-11-03 16:54:11 -0500 | [diff] [blame] | 548 | faultFound = false; |
Brandon Wyman | 6ccce0b | 2017-10-26 15:13:10 -0500 | [diff] [blame] | 549 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 550 | return; |
| 551 | } |
| 552 | |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 553 | void PowerSupply::resolveError(const std::string& callout, |
| 554 | const std::string& message) |
| 555 | { |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 556 | using EndpointList = std::vector<std::string>; |
| 557 | |
| 558 | try |
| 559 | { |
| 560 | auto path = callout + "/fault"; |
| 561 | // Get the service name from the mapper for the fault callout |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 562 | auto service = util::getService(path, ASSOCIATION_IFACE, bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 563 | |
| 564 | // Use getProperty utility function to get log entries (endpoints) |
| 565 | EndpointList logEntries; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 566 | util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service, bus, |
| 567 | logEntries); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 568 | |
| 569 | // It is possible that all such entries for this callout have since |
| 570 | // been deleted. |
| 571 | if (logEntries.empty()) |
| 572 | { |
| 573 | return; |
| 574 | } |
| 575 | |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 576 | auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE, |
| 577 | bus); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 578 | if (logEntryService.empty()) |
| 579 | { |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | // go through each log entry that matches this callout path |
| 584 | std::string logMessage; |
| 585 | for (const auto& logEntry : logEntries) |
| 586 | { |
| 587 | // Check to see if this logEntry has a message that matches. |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 588 | util::getProperty(LOGGING_IFACE, MESSAGE_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 589 | logEntryService, bus, logMessage); |
| 590 | |
| 591 | if (message == logMessage) |
| 592 | { |
| 593 | // Log entry matches call out and message, set Resolved to true |
| 594 | bool resolved = true; |
Matt Spinler | 589e872 | 2018-01-04 15:24:49 -0600 | [diff] [blame] | 595 | util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry, |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 596 | logEntryService, bus, resolved); |
| 597 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 598 | } |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 599 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 600 | catch (const std::exception& e) |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 601 | { |
| 602 | log<level::INFO>("Failed to resolve error", |
| 603 | entry("CALLOUT=%s", callout.c_str()), |
Matt Spinler | 0d09f29 | 2018-01-22 14:51:26 -0600 | [diff] [blame] | 604 | entry("ERROR=%s", message.c_str())); |
Brandon Wyman | 01741f1 | 2017-12-01 17:22:08 -0600 | [diff] [blame] | 605 | } |
Brandon Wyman | 43ce208 | 2017-11-30 17:24:01 -0600 | [diff] [blame] | 606 | } |
| 607 | |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 608 | void PowerSupply::updateInventory() |
| 609 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 610 | using namespace phosphor::pmbus; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 611 | using namespace sdbusplus::message; |
| 612 | |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 613 | // Build the object map and send it to the inventory |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 614 | using Properties = std::map<std::string, std::variant<std::string, bool>>; |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 615 | using Interfaces = std::map<std::string, Properties>; |
| 616 | using Object = std::map<object_path, Interfaces>; |
| 617 | Properties assetProps; |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 618 | Properties operProps; |
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 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 640 | catch (const ReadFailure& e) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 641 | {} |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 642 | } |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 643 | } |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 644 | |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 645 | operProps.emplace(FUNCTIONAL_PROP, present); |
George Liu | 690e780 | 2019-08-23 11:04:01 +0800 | [diff] [blame] | 646 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 647 | interfaces.emplace(OPERATIONAL_STATE_IFACE, std::move(operProps)); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 648 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 649 | // For Notify(), just send the relative path of the inventory |
| 650 | // object so remove the INVENTORY_OBJ_PATH prefix |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 651 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 652 | |
| 653 | object.emplace(path, std::move(interfaces)); |
| 654 | |
| 655 | try |
| 656 | { |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 657 | auto service = util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, |
| 658 | bus); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 659 | |
| 660 | if (service.empty()) |
| 661 | { |
| 662 | log<level::ERR>("Unable to get inventory manager service"); |
| 663 | return; |
| 664 | } |
| 665 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 666 | auto method = bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 667 | INVENTORY_MGR_IFACE, "Notify"); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 668 | |
| 669 | method.append(std::move(object)); |
| 670 | |
| 671 | auto reply = bus.call(method); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 672 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 673 | catch (const std::exception& e) |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 674 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 675 | log<level::ERR>(e.what(), entry("PATH=%s", inventoryPath.c_str())); |
Matt Spinler | 018a7bc | 2018-01-04 15:36:41 -0600 | [diff] [blame] | 676 | } |
Matt Spinler | 234ce0d | 2018-01-04 15:06:57 -0600 | [diff] [blame] | 677 | } |
| 678 | |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 679 | void PowerSupply::syncHistory() |
| 680 | { |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 681 | using namespace phosphor::gpio; |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 682 | |
| 683 | if (syncGPIODevPath.empty()) |
| 684 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 685 | // Sync not implemented |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 686 | return; |
| 687 | } |
| 688 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 689 | GPIO gpio{syncGPIODevPath, static_cast<gpioNum_t>(syncGPIONumber), |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 690 | Direction::output}; |
| 691 | |
| 692 | try |
| 693 | { |
| 694 | gpio.set(Value::low); |
| 695 | |
| 696 | std::this_thread::sleep_for(std::chrono::milliseconds{5}); |
| 697 | |
| 698 | gpio.set(Value::high); |
| 699 | |
| 700 | recordManager->clear(); |
| 701 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 702 | catch (const std::exception& e) |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 703 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 704 | // Do nothing. There would already be a journal entry. |
Matt Spinler | d734e65 | 2018-01-18 14:31:15 -0600 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Matt Spinler | 8238414 | 2018-01-18 14:15:03 -0600 | [diff] [blame] | 708 | void PowerSupply::enableHistory(const std::string& objectPath, |
| 709 | size_t numRecords, |
| 710 | const std::string& syncGPIOPath, |
| 711 | size_t syncGPIONum) |
| 712 | { |
| 713 | historyObjectPath = objectPath; |
| 714 | syncGPIODevPath = syncGPIOPath; |
| 715 | syncGPIONumber = syncGPIONum; |
| 716 | |
| 717 | recordManager = std::make_unique<history::RecordManager>(numRecords); |
| 718 | |
| 719 | auto avgPath = historyObjectPath + '/' + history::Average::name; |
| 720 | auto maxPath = historyObjectPath + '/' + history::Maximum::name; |
| 721 | |
| 722 | average = std::make_unique<history::Average>(bus, avgPath); |
| 723 | |
| 724 | maximum = std::make_unique<history::Maximum>(bus, maxPath); |
| 725 | } |
| 726 | |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 727 | void PowerSupply::updateHistory() |
| 728 | { |
| 729 | if (!recordManager) |
| 730 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 731 | // Not enabled |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 735 | // Read just the most recent average/max record |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 736 | auto data = pmbusIntf.readBinary(INPUT_HISTORY, |
| 737 | pmbus::Type::HwmonDeviceDebug, |
| 738 | history::RecordManager::RAW_RECORD_SIZE); |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 739 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 740 | // 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] | 741 | auto changed = recordManager->add(data); |
| 742 | if (changed) |
| 743 | { |
Patrick Williams | 41a6b9f | 2023-05-31 19:54:59 -0500 | [diff] [blame] | 744 | average->values(recordManager->getAverageRecords()); |
| 745 | maximum->values(recordManager->getMaximumRecords()); |
Matt Spinler | eb169fd | 2018-01-18 14:19:08 -0600 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 749 | } // namespace psu |
| 750 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 751 | } // namespace phosphor |