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