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