Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 3 | #include "power_supply.hpp" |
| 4 | |
| 5 | #include "types.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 6 | #include "util.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 7 | |
Brandon Wyman | df13c3a | 2020-12-15 14:25:22 -0600 | [diff] [blame] | 8 | #include <fmt/format.h> |
| 9 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 11 | |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 12 | #include <chrono> // sleep_for() |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 13 | #include <cmath> |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 14 | #include <cstdint> // uint8_t... |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 15 | #include <fstream> |
Brandon Wyman | 056935c | 2022-06-24 23:05:09 +0000 | [diff] [blame] | 16 | #include <regex> |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 17 | #include <thread> // sleep_for() |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 18 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 19 | namespace phosphor::power::psu |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 20 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 21 | // Amount of time in milliseconds to delay between power supply going from |
| 22 | // missing to present before running the bind command(s). |
| 23 | constexpr auto bindDelay = 1000; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 24 | |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 25 | // The number of INPUT_HISTORY records to keep on D-Bus. |
| 26 | // Each record covers a 30-second span. That means two records are needed to |
| 27 | // cover a minute of time. If we want one (1) hour of data, that would be 120 |
| 28 | // records. |
| 29 | constexpr auto INPUT_HISTORY_MAX_RECORDS = 120; |
| 30 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 31 | using namespace phosphor::logging; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 32 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 33 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 34 | PowerSupply::PowerSupply(sdbusplus::bus_t& bus, const std::string& invpath, |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 35 | std::uint8_t i2cbus, std::uint16_t i2caddr, |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 36 | const std::string& driver, |
George Liu | 9464c42 | 2023-02-27 14:30:27 +0800 | [diff] [blame] | 37 | const std::string& gpioLineName, |
| 38 | std::function<bool()>&& callback) : |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 39 | bus(bus), |
George Liu | 9464c42 | 2023-02-27 14:30:27 +0800 | [diff] [blame] | 40 | inventoryPath(invpath), bindPath("/sys/bus/i2c/drivers/" + driver), |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 41 | isPowerOn(std::move(callback)), driverName(driver) |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 42 | { |
| 43 | if (inventoryPath.empty()) |
| 44 | { |
| 45 | throw std::invalid_argument{"Invalid empty inventoryPath"}; |
| 46 | } |
| 47 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 48 | if (gpioLineName.empty()) |
| 49 | { |
| 50 | throw std::invalid_argument{"Invalid empty gpioLineName"}; |
| 51 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 52 | |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 53 | shortName = findShortName(inventoryPath); |
| 54 | |
| 55 | log<level::DEBUG>( |
| 56 | fmt::format("{} gpioLineName: {}", shortName, gpioLineName).c_str()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 57 | presenceGPIO = createGPIO(gpioLineName); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 58 | |
| 59 | std::ostringstream ss; |
| 60 | ss << std::hex << std::setw(4) << std::setfill('0') << i2caddr; |
| 61 | std::string addrStr = ss.str(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 62 | std::string busStr = std::to_string(i2cbus); |
| 63 | bindDevice = busStr; |
| 64 | bindDevice.append("-"); |
| 65 | bindDevice.append(addrStr); |
| 66 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 67 | pmbusIntf = phosphor::pmbus::createPMBus(i2cbus, addrStr); |
| 68 | |
| 69 | // Get the current state of the Present property. |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 70 | try |
| 71 | { |
| 72 | updatePresenceGPIO(); |
| 73 | } |
| 74 | catch (...) |
| 75 | { |
| 76 | // If the above attempt to use the GPIO failed, it likely means that the |
| 77 | // GPIOs are in use by the kernel, meaning it is using gpio-keys. |
| 78 | // So, I should rely on phosphor-gpio-presence to update D-Bus, and |
| 79 | // work that way for power supply presence. |
| 80 | presenceGPIO = nullptr; |
| 81 | // Setup the functions to call when the D-Bus inventory path for the |
| 82 | // Present property changes. |
| 83 | presentMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 84 | bus, |
| 85 | sdbusplus::bus::match::rules::propertiesChanged(inventoryPath, |
| 86 | INVENTORY_IFACE), |
| 87 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 88 | |
| 89 | presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 90 | bus, |
| 91 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 92 | sdbusplus::bus::match::rules::argNpath(0, inventoryPath), |
| 93 | [this](auto& msg) { this->inventoryAdded(msg); }); |
| 94 | |
| 95 | updatePresence(); |
| 96 | updateInventory(); |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 97 | setupInputHistory(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 98 | } |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 99 | |
| 100 | setInputVoltageRating(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void PowerSupply::bindOrUnbindDriver(bool present) |
| 104 | { |
| 105 | auto action = (present) ? "bind" : "unbind"; |
| 106 | auto path = bindPath / action; |
| 107 | |
| 108 | if (present) |
| 109 | { |
Brandon Wyman | b1ee60f | 2022-03-22 22:37:12 +0000 | [diff] [blame] | 110 | std::this_thread::sleep_for(std::chrono::milliseconds(bindDelay)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 111 | log<level::INFO>( |
| 112 | fmt::format("Binding device driver. path: {} device: {}", |
| 113 | path.string(), bindDevice) |
| 114 | .c_str()); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | log<level::INFO>( |
| 119 | fmt::format("Unbinding device driver. path: {} device: {}", |
| 120 | path.string(), bindDevice) |
| 121 | .c_str()); |
| 122 | } |
| 123 | |
| 124 | std::ofstream file; |
| 125 | |
| 126 | file.exceptions(std::ofstream::failbit | std::ofstream::badbit | |
| 127 | std::ofstream::eofbit); |
| 128 | |
| 129 | try |
| 130 | { |
| 131 | file.open(path); |
| 132 | file << bindDevice; |
| 133 | file.close(); |
| 134 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 135 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 136 | { |
| 137 | auto err = errno; |
| 138 | |
| 139 | log<level::ERR>( |
| 140 | fmt::format("Failed binding or unbinding device. errno={}", err) |
| 141 | .c_str()); |
| 142 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 143 | } |
| 144 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 145 | void PowerSupply::updatePresence() |
| 146 | { |
| 147 | try |
| 148 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 149 | present = getPresence(bus, inventoryPath); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 150 | } |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 151 | catch (const sdbusplus::exception_t& e) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 152 | { |
| 153 | // Relying on property change or interface added to retry. |
| 154 | // Log an informational trace to the journal. |
Brandon Wyman | df13c3a | 2020-12-15 14:25:22 -0600 | [diff] [blame] | 155 | log<level::INFO>( |
| 156 | fmt::format("D-Bus property {} access failure exception", |
| 157 | inventoryPath) |
| 158 | .c_str()); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 162 | void PowerSupply::updatePresenceGPIO() |
| 163 | { |
| 164 | bool presentOld = present; |
| 165 | |
| 166 | try |
| 167 | { |
| 168 | if (presenceGPIO->read() > 0) |
| 169 | { |
| 170 | present = true; |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | present = false; |
| 175 | } |
| 176 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 177 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 178 | { |
| 179 | log<level::ERR>( |
| 180 | fmt::format("presenceGPIO read fail: {}", e.what()).c_str()); |
| 181 | throw; |
| 182 | } |
| 183 | |
| 184 | if (presentOld != present) |
| 185 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 186 | log<level::DEBUG>(fmt::format("{} presentOld: {} present: {}", |
| 187 | shortName, presentOld, present) |
| 188 | .c_str()); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 189 | |
| 190 | auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
Brandon Wyman | 90d529a | 2022-03-22 23:02:54 +0000 | [diff] [blame] | 191 | |
| 192 | bindOrUnbindDriver(present); |
| 193 | if (present) |
| 194 | { |
| 195 | // If the power supply was present, then missing, and present again, |
| 196 | // the hwmon path may have changed. We will need the correct/updated |
| 197 | // path before any reads or writes are attempted. |
| 198 | pmbusIntf->findHwmonDir(); |
| 199 | } |
| 200 | |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 201 | setPresence(bus, invpath, present, shortName); |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 202 | setupInputHistory(); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 203 | updateInventory(); |
| 204 | |
Brandon Wyman | 90d529a | 2022-03-22 23:02:54 +0000 | [diff] [blame] | 205 | // Need Functional to already be correct before calling this. |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 206 | checkAvailability(); |
| 207 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 208 | if (present) |
| 209 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 210 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
| 211 | clearFaults(); |
Brandon Wyman | 18a24d9 | 2022-04-19 22:48:34 +0000 | [diff] [blame] | 212 | // Indicate that the input history data and timestamps between all |
| 213 | // the power supplies that are present in the system need to be |
| 214 | // synchronized. |
| 215 | syncHistoryRequired = true; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 216 | } |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 220 | void PowerSupply::analyzeCMLFault() |
| 221 | { |
| 222 | if (statusWord & phosphor::pmbus::status_word::CML_FAULT) |
| 223 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 224 | if (cmlFault < DEGLITCH_LIMIT) |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 225 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 226 | if (statusWord != statusWordOld) |
| 227 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 228 | log<level::ERR>( |
| 229 | fmt::format("{} CML fault: STATUS_WORD = {:#06x}, " |
| 230 | "STATUS_CML = {:#02x}", |
| 231 | shortName, statusWord, statusCML) |
| 232 | .c_str()); |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 233 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 234 | cmlFault++; |
| 235 | } |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | cmlFault = 0; |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 243 | void PowerSupply::analyzeInputFault() |
| 244 | { |
| 245 | if (statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN) |
| 246 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 247 | if (inputFault < DEGLITCH_LIMIT) |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 248 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 249 | if (statusWord != statusWordOld) |
| 250 | { |
| 251 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 252 | fmt::format("{} INPUT fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 253 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 254 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 255 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 256 | .c_str()); |
| 257 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 258 | inputFault++; |
| 259 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 260 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 261 | |
| 262 | // If had INPUT/VIN_UV fault, and now off. |
| 263 | // Trace that odd behavior. |
| 264 | if (inputFault && |
| 265 | !(statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN)) |
| 266 | { |
| 267 | log<level::INFO>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 268 | fmt::format("{} INPUT fault cleared: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 6f939a3 | 2022-03-10 18:42:20 +0000 | [diff] [blame] | 269 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 270 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 271 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 272 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 273 | inputFault = 0; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 274 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 277 | void PowerSupply::analyzeVoutOVFault() |
| 278 | { |
| 279 | if (statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT) |
| 280 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 281 | if (voutOVFault < DEGLITCH_LIMIT) |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 282 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 283 | if (statusWord != statusWordOld) |
| 284 | { |
| 285 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 286 | fmt::format( |
| 287 | "{} VOUT_OV_FAULT fault: STATUS_WORD = {:#06x}, " |
| 288 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 289 | "STATUS_VOUT = {:#02x}", |
| 290 | shortName, statusWord, statusMFR, statusVout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 291 | .c_str()); |
| 292 | } |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 293 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 294 | voutOVFault++; |
| 295 | } |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | voutOVFault = 0; |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 303 | void PowerSupply::analyzeIoutOCFault() |
| 304 | { |
| 305 | if (statusWord & phosphor::pmbus::status_word::IOUT_OC_FAULT) |
| 306 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 307 | if (ioutOCFault < DEGLITCH_LIMIT) |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 308 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 309 | if (statusWord != statusWordOld) |
| 310 | { |
| 311 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 312 | fmt::format("{} IOUT fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 313 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 314 | "STATUS_IOUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 315 | shortName, statusWord, statusMFR, statusIout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 316 | .c_str()); |
| 317 | } |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 318 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 319 | ioutOCFault++; |
| 320 | } |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | ioutOCFault = 0; |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 328 | void PowerSupply::analyzeVoutUVFault() |
| 329 | { |
| 330 | if ((statusWord & phosphor::pmbus::status_word::VOUT_FAULT) && |
| 331 | !(statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT)) |
| 332 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 333 | if (voutUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 334 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 335 | if (statusWord != statusWordOld) |
| 336 | { |
| 337 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 338 | fmt::format( |
| 339 | "{} VOUT_UV_FAULT fault: STATUS_WORD = {:#06x}, " |
| 340 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 341 | "STATUS_VOUT = {:#04x}", |
| 342 | shortName, statusWord, statusMFR, statusVout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 343 | .c_str()); |
| 344 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 345 | voutUVFault++; |
| 346 | } |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | voutUVFault = 0; |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 354 | void PowerSupply::analyzeFanFault() |
| 355 | { |
| 356 | if (statusWord & phosphor::pmbus::status_word::FAN_FAULT) |
| 357 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 358 | if (fanFault < DEGLITCH_LIMIT) |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 359 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 360 | if (statusWord != statusWordOld) |
| 361 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 362 | log<level::ERR>(fmt::format("{} FANS fault/warning: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 363 | "STATUS_WORD = {:#06x}, " |
| 364 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 365 | "STATUS_FANS_1_2 = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 366 | shortName, statusWord, statusMFR, |
| 367 | statusFans12) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 368 | .c_str()); |
| 369 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 370 | fanFault++; |
| 371 | } |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | fanFault = 0; |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 379 | void PowerSupply::analyzeTemperatureFault() |
| 380 | { |
| 381 | if (statusWord & phosphor::pmbus::status_word::TEMPERATURE_FAULT_WARN) |
| 382 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 383 | if (tempFault < DEGLITCH_LIMIT) |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 384 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 385 | if (statusWord != statusWordOld) |
| 386 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 387 | log<level::ERR>(fmt::format("{} TEMPERATURE fault/warning: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 388 | "STATUS_WORD = {:#06x}, " |
| 389 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 390 | "STATUS_TEMPERATURE = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 391 | shortName, statusWord, statusMFR, |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 392 | statusTemperature) |
| 393 | .c_str()); |
| 394 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 395 | tempFault++; |
| 396 | } |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | tempFault = 0; |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 404 | void PowerSupply::analyzePgoodFault() |
| 405 | { |
| 406 | if ((statusWord & phosphor::pmbus::status_word::POWER_GOOD_NEGATED) || |
| 407 | (statusWord & phosphor::pmbus::status_word::UNIT_IS_OFF)) |
| 408 | { |
Brandon Wyman | 6d469fd | 2022-06-15 16:58:21 +0000 | [diff] [blame] | 409 | if (pgoodFault < PGOOD_DEGLITCH_LIMIT) |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 410 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 411 | if (statusWord != statusWordOld) |
| 412 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 413 | log<level::ERR>(fmt::format("{} PGOOD fault: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 414 | "STATUS_WORD = {:#06x}, " |
| 415 | "STATUS_MFR_SPECIFIC = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 416 | shortName, statusWord, statusMFR) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 417 | .c_str()); |
| 418 | } |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 419 | pgoodFault++; |
| 420 | } |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | pgoodFault = 0; |
| 425 | } |
| 426 | } |
| 427 | |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 428 | void PowerSupply::determineMFRFault() |
| 429 | { |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 430 | if (bindPath.string().find(IBMCFFPS_DD_NAME) != std::string::npos) |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 431 | { |
| 432 | // IBM MFR_SPECIFIC[4] is PS_Kill fault |
| 433 | if (statusMFR & 0x10) |
| 434 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 435 | if (psKillFault < DEGLITCH_LIMIT) |
| 436 | { |
| 437 | psKillFault++; |
| 438 | } |
| 439 | } |
| 440 | else |
| 441 | { |
| 442 | psKillFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 443 | } |
| 444 | // IBM MFR_SPECIFIC[6] is 12Vcs fault. |
| 445 | if (statusMFR & 0x40) |
| 446 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 447 | if (ps12VcsFault < DEGLITCH_LIMIT) |
| 448 | { |
| 449 | ps12VcsFault++; |
| 450 | } |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | ps12VcsFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 455 | } |
| 456 | // IBM MFR_SPECIFIC[7] is 12V Current-Share fault. |
| 457 | if (statusMFR & 0x80) |
| 458 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 459 | if (psCS12VFault < DEGLITCH_LIMIT) |
| 460 | { |
| 461 | psCS12VFault++; |
| 462 | } |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | psCS12VFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 471 | void PowerSupply::analyzeMFRFault() |
| 472 | { |
| 473 | if (statusWord & phosphor::pmbus::status_word::MFR_SPECIFIC_FAULT) |
| 474 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 475 | if (mfrFault < DEGLITCH_LIMIT) |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 476 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 477 | if (statusWord != statusWordOld) |
| 478 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 479 | log<level::ERR>(fmt::format("{} MFR fault: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 480 | "STATUS_WORD = {:#06x} " |
| 481 | "STATUS_MFR_SPECIFIC = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 482 | shortName, statusWord, statusMFR) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 483 | .c_str()); |
| 484 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 485 | mfrFault++; |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 488 | determineMFRFault(); |
| 489 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 490 | else |
| 491 | { |
| 492 | mfrFault = 0; |
| 493 | } |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 496 | void PowerSupply::analyzeVinUVFault() |
| 497 | { |
| 498 | if (statusWord & phosphor::pmbus::status_word::VIN_UV_FAULT) |
| 499 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 500 | if (vinUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 501 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 502 | if (statusWord != statusWordOld) |
| 503 | { |
| 504 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 505 | fmt::format("{} VIN_UV fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 506 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 507 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 508 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 509 | .c_str()); |
| 510 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 511 | vinUVFault++; |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 512 | } |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 513 | // Remember that this PSU has seen an AC fault |
| 514 | acFault = AC_FAULT_LIMIT; |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 515 | } |
Jim Wright | 7f9288c | 2022-12-08 11:57:04 -0600 | [diff] [blame] | 516 | else |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 517 | { |
Jim Wright | 7f9288c | 2022-12-08 11:57:04 -0600 | [diff] [blame] | 518 | if (vinUVFault != 0) |
| 519 | { |
| 520 | log<level::INFO>( |
| 521 | fmt::format("{} VIN_UV fault cleared: STATUS_WORD = {:#06x}, " |
| 522 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 523 | "STATUS_INPUT = {:#04x}", |
| 524 | shortName, statusWord, statusMFR, statusInput) |
| 525 | .c_str()); |
| 526 | vinUVFault = 0; |
| 527 | } |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 528 | // No AC fail, decrement counter |
Jim Wright | 7f9288c | 2022-12-08 11:57:04 -0600 | [diff] [blame] | 529 | if (acFault != 0) |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 530 | { |
| 531 | --acFault; |
| 532 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 533 | } |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 536 | void PowerSupply::analyze() |
| 537 | { |
| 538 | using namespace phosphor::pmbus; |
| 539 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 540 | if (presenceGPIO) |
| 541 | { |
| 542 | updatePresenceGPIO(); |
| 543 | } |
| 544 | |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 545 | if (present) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 546 | { |
| 547 | try |
| 548 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 549 | statusWordOld = statusWord; |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 550 | statusWord = pmbusIntf->read(STATUS_WORD, Type::Debug, |
| 551 | (readFail < LOG_LIMIT)); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 552 | // Read worked, reset the fail count. |
| 553 | readFail = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 554 | |
| 555 | if (statusWord) |
| 556 | { |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 557 | statusInput = pmbusIntf->read(STATUS_INPUT, Type::Debug); |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 558 | if (bindPath.string().find(IBMCFFPS_DD_NAME) != |
| 559 | std::string::npos) |
| 560 | { |
| 561 | statusMFR = pmbusIntf->read(STATUS_MFR, Type::Debug); |
| 562 | } |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 563 | statusCML = pmbusIntf->read(STATUS_CML, Type::Debug); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 564 | auto status0Vout = pmbusIntf->insertPageNum(STATUS_VOUT, 0); |
| 565 | statusVout = pmbusIntf->read(status0Vout, Type::Debug); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 566 | statusIout = pmbusIntf->read(STATUS_IOUT, Type::Debug); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 567 | statusFans12 = pmbusIntf->read(STATUS_FANS_1_2, Type::Debug); |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 568 | statusTemperature = pmbusIntf->read(STATUS_TEMPERATURE, |
| 569 | Type::Debug); |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 570 | |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 571 | analyzeCMLFault(); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 572 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 573 | analyzeInputFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 574 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 575 | analyzeVoutOVFault(); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 576 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 577 | analyzeIoutOCFault(); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 578 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 579 | analyzeVoutUVFault(); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 580 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 581 | analyzeFanFault(); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 582 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 583 | analyzeTemperatureFault(); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 584 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 585 | analyzePgoodFault(); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 586 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 587 | analyzeMFRFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 588 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 589 | analyzeVinUVFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 590 | } |
| 591 | else |
| 592 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 593 | if (statusWord != statusWordOld) |
| 594 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 595 | log<level::INFO>(fmt::format("{} STATUS_WORD = {:#06x}", |
| 596 | shortName, statusWord) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 597 | .c_str()); |
| 598 | } |
| 599 | |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 600 | // if INPUT/VIN_UV fault was on, it cleared, trace it. |
| 601 | if (inputFault) |
| 602 | { |
| 603 | log<level::INFO>( |
| 604 | fmt::format( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 605 | "{} INPUT fault cleared: STATUS_WORD = {:#06x}", |
| 606 | shortName, statusWord) |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 607 | .c_str()); |
| 608 | } |
| 609 | |
| 610 | if (vinUVFault) |
| 611 | { |
| 612 | log<level::INFO>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 613 | fmt::format("{} VIN_UV cleared: STATUS_WORD = {:#06x}", |
| 614 | shortName, statusWord) |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 615 | .c_str()); |
| 616 | } |
| 617 | |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 618 | if (pgoodFault > 0) |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 619 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 620 | log<level::INFO>( |
| 621 | fmt::format("{} pgoodFault cleared", shortName) |
| 622 | .c_str()); |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 623 | } |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 624 | |
| 625 | clearFaultFlags(); |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 626 | // No AC fail, decrement counter |
Jim Wright | 7f9288c | 2022-12-08 11:57:04 -0600 | [diff] [blame] | 627 | if (acFault != 0) |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 628 | { |
| 629 | --acFault; |
| 630 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 631 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 632 | |
| 633 | // Save off old inputVoltage value. |
| 634 | // Get latest inputVoltage. |
| 635 | // If voltage went from below minimum, and now is not, clear faults. |
| 636 | // Note: getInputVoltage() has its own try/catch. |
| 637 | int inputVoltageOld = inputVoltage; |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 638 | double actualInputVoltageOld = actualInputVoltage; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 639 | getInputVoltage(actualInputVoltage, inputVoltage); |
| 640 | if ((inputVoltageOld == in_input::VIN_VOLTAGE_0) && |
| 641 | (inputVoltage != in_input::VIN_VOLTAGE_0)) |
| 642 | { |
| 643 | log<level::INFO>( |
| 644 | fmt::format( |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 645 | "{} READ_VIN back in range: actualInputVoltageOld = {} " |
| 646 | "actualInputVoltage = {}", |
| 647 | shortName, actualInputVoltageOld, actualInputVoltage) |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 648 | .c_str()); |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 649 | clearVinUVFault(); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 650 | } |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 651 | else if (vinUVFault && (inputVoltage != in_input::VIN_VOLTAGE_0)) |
| 652 | { |
| 653 | log<level::INFO>( |
| 654 | fmt::format( |
| 655 | "{} CLEAR_FAULTS: vinUVFault {} actualInputVoltage {}", |
| 656 | shortName, vinUVFault, actualInputVoltage) |
| 657 | .c_str()); |
| 658 | // Do we have a VIN_UV fault latched that can now be cleared |
Jim Wright | 4ab8656 | 2022-11-18 14:05:46 -0600 | [diff] [blame] | 659 | // due to voltage back in range? Attempt to clear the |
| 660 | // fault(s), re-check faults on next call. |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 661 | clearVinUVFault(); |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 662 | } |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 663 | else if (std::abs(actualInputVoltageOld - actualInputVoltage) > |
| 664 | 10.0) |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 665 | { |
| 666 | log<level::INFO>( |
| 667 | fmt::format( |
| 668 | "{} actualInputVoltageOld = {} actualInputVoltage = {}", |
| 669 | shortName, actualInputVoltageOld, actualInputVoltage) |
| 670 | .c_str()); |
| 671 | } |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 672 | |
| 673 | checkAvailability(); |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 674 | |
| 675 | if (inputHistorySupported) |
| 676 | { |
| 677 | updateHistory(); |
| 678 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 679 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 680 | catch (const ReadFailure& e) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 681 | { |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 682 | if (readFail < SIZE_MAX) |
| 683 | { |
| 684 | readFail++; |
| 685 | } |
| 686 | if (readFail == LOG_LIMIT) |
| 687 | { |
| 688 | phosphor::logging::commit<ReadFailure>(); |
| 689 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 694 | void PowerSupply::onOffConfig(uint8_t data) |
| 695 | { |
| 696 | using namespace phosphor::pmbus; |
| 697 | |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 698 | if (present && driverName != ACBEL_FSG032_DD_NAME) |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 699 | { |
| 700 | log<level::INFO>("ON_OFF_CONFIG write", entry("DATA=0x%02X", data)); |
| 701 | try |
| 702 | { |
| 703 | std::vector<uint8_t> configData{data}; |
| 704 | pmbusIntf->writeBinary(ON_OFF_CONFIG, configData, |
| 705 | Type::HwmonDeviceDebug); |
| 706 | } |
| 707 | catch (...) |
| 708 | { |
| 709 | // The underlying code in writeBinary will log a message to the |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 710 | // journal if the write fails. If the ON_OFF_CONFIG is not setup |
| 711 | // as desired, later fault detection and analysis code should |
| 712 | // catch any of the fall out. We should not need to terminate |
| 713 | // the application if this write fails. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 718 | void PowerSupply::clearVinUVFault() |
| 719 | { |
| 720 | // Read in1_lcrit_alarm to clear bits 3 and 4 of STATUS_INPUT. |
| 721 | // The fault bits in STAUTS_INPUT roll-up to STATUS_WORD. Clearing those |
| 722 | // bits in STATUS_INPUT should result in the corresponding STATUS_WORD bits |
| 723 | // also clearing. |
| 724 | // |
| 725 | // Do not care about return value. Should be 1 if active, 0 if not. |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 726 | if (driverName != ACBEL_FSG032_DD_NAME) |
| 727 | { |
| 728 | static_cast<void>( |
| 729 | pmbusIntf->read("in1_lcrit_alarm", phosphor::pmbus::Type::Hwmon)); |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | static_cast<void>( |
| 734 | pmbusIntf->read("curr1_crit_alarm", phosphor::pmbus::Type::Hwmon)); |
| 735 | } |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 736 | vinUVFault = 0; |
| 737 | } |
| 738 | |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 739 | void PowerSupply::clearFaults() |
| 740 | { |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 741 | log<level::DEBUG>( |
| 742 | fmt::format("clearFaults() inventoryPath: {}", inventoryPath).c_str()); |
Brandon Wyman | 5474c91 | 2021-02-23 14:39:43 -0600 | [diff] [blame] | 743 | faultLogged = false; |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 744 | // The PMBus device driver does not allow for writing CLEAR_FAULTS |
| 745 | // directly. However, the pmbus hwmon device driver code will send a |
| 746 | // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so |
| 747 | // reading in1_input should result in clearing the fault bits in |
| 748 | // STATUS_BYTE/STATUS_WORD. |
| 749 | // I do not care what the return value is. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 750 | if (present) |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 751 | { |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 752 | clearFaultFlags(); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 753 | checkAvailability(); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 754 | readFail = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 755 | |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 756 | try |
| 757 | { |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 758 | clearVinUVFault(); |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 759 | static_cast<void>( |
| 760 | pmbusIntf->read("in1_input", phosphor::pmbus::Type::Hwmon)); |
| 761 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 762 | catch (const ReadFailure& e) |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 763 | { |
| 764 | // Since I do not care what the return value is, I really do not |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 765 | // care much if it gets a ReadFailure either. However, this |
| 766 | // should not prevent the application from continuing to run, so |
| 767 | // catching the read failure. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 768 | } |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 772 | void PowerSupply::inventoryChanged(sdbusplus::message_t& msg) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 773 | { |
| 774 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 775 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 776 | msg.read(msgSensor, msgData); |
| 777 | |
| 778 | // Check if it was the Present property that changed. |
| 779 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 780 | if (valPropMap != msgData.end()) |
| 781 | { |
| 782 | if (std::get<bool>(valPropMap->second)) |
| 783 | { |
| 784 | present = true; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 785 | // TODO: Immediately trying to read or write the "files" causes |
| 786 | // read or write failures. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 787 | using namespace std::chrono_literals; |
| 788 | std::this_thread::sleep_for(20ms); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 789 | pmbusIntf->findHwmonDir(); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 790 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 791 | clearFaults(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 792 | updateInventory(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 793 | } |
| 794 | else |
| 795 | { |
| 796 | present = false; |
| 797 | |
| 798 | // Clear out the now outdated inventory properties |
| 799 | updateInventory(); |
| 800 | } |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 801 | checkAvailability(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 805 | void PowerSupply::inventoryAdded(sdbusplus::message_t& msg) |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 806 | { |
| 807 | sdbusplus::message::object_path path; |
| 808 | msg.read(path); |
| 809 | // Make sure the signal is for the PSU inventory path |
| 810 | if (path == inventoryPath) |
| 811 | { |
| 812 | std::map<std::string, std::map<std::string, std::variant<bool>>> |
| 813 | interfaces; |
| 814 | // Get map of interfaces and their properties |
| 815 | msg.read(interfaces); |
| 816 | |
| 817 | auto properties = interfaces.find(INVENTORY_IFACE); |
| 818 | if (properties != interfaces.end()) |
| 819 | { |
| 820 | auto property = properties->second.find(PRESENT_PROP); |
| 821 | if (property != properties->second.end()) |
| 822 | { |
| 823 | present = std::get<bool>(property->second); |
| 824 | |
| 825 | log<level::INFO>(fmt::format("Power Supply {} Present {}", |
| 826 | inventoryPath, present) |
| 827 | .c_str()); |
| 828 | |
| 829 | updateInventory(); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 830 | checkAvailability(); |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 836 | auto PowerSupply::readVPDValue(const std::string& vpdName, |
| 837 | const phosphor::pmbus::Type& type, |
| 838 | const std::size_t& vpdSize) |
| 839 | { |
| 840 | std::string vpdValue; |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 841 | const std::regex illegalVPDRegex = std::regex("[^[:alnum:]]", |
| 842 | std::regex::basic); |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 843 | |
| 844 | try |
| 845 | { |
| 846 | vpdValue = pmbusIntf->readString(vpdName, type); |
| 847 | } |
| 848 | catch (const ReadFailure& e) |
| 849 | { |
| 850 | // Ignore the read failure, let pmbus code indicate failure, |
| 851 | // path... |
| 852 | // TODO - ibm918 |
| 853 | // https://github.com/openbmc/docs/blob/master/designs/vpd-collection.md |
| 854 | // The BMC must log errors if any of the VPD cannot be properly |
| 855 | // parsed or fails ECC checks. |
| 856 | } |
| 857 | |
| 858 | if (vpdValue.size() != vpdSize) |
| 859 | { |
| 860 | log<level::INFO>(fmt::format("{} {} resize needed. size: {}", shortName, |
| 861 | vpdName, vpdValue.size()) |
| 862 | .c_str()); |
| 863 | vpdValue.resize(vpdSize, ' '); |
| 864 | } |
| 865 | |
Brandon Wyman | 056935c | 2022-06-24 23:05:09 +0000 | [diff] [blame] | 866 | // Replace any illegal values with space(s). |
| 867 | std::regex_replace(vpdValue.begin(), vpdValue.begin(), vpdValue.end(), |
| 868 | illegalVPDRegex, " "); |
| 869 | |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 870 | return vpdValue; |
| 871 | } |
| 872 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 873 | void PowerSupply::updateInventory() |
| 874 | { |
| 875 | using namespace phosphor::pmbus; |
| 876 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 877 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 878 | std::string pn; |
| 879 | std::string fn; |
| 880 | std::string header; |
| 881 | std::string sn; |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 882 | // The IBM power supply splits the full serial number into two parts. |
| 883 | // Each part is 6 bytes long, which should match up with SN_KW_SIZE. |
| 884 | const auto HEADER_SIZE = 6; |
| 885 | const auto SERIAL_SIZE = 6; |
| 886 | // The IBM PSU firmware version size is a bit complicated. It was originally |
| 887 | // 1-byte, per command. It was later expanded to 2-bytes per command, then |
| 888 | // up to 8-bytes per command. The device driver only reads up to 2 bytes per |
| 889 | // command, but combines all three of the 2-byte reads, or all 4 of the |
| 890 | // 1-byte reads into one string. So, the maximum size expected is 6 bytes. |
Shawn McCarney | 983c989 | 2022-10-12 10:49:47 -0500 | [diff] [blame] | 891 | // However, it is formatted by the driver as a hex string with two ASCII |
| 892 | // characters per byte. So the maximum ASCII string size is 12. |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 893 | const auto IBMCFFPS_FW_VERSION_SIZE = 12; |
| 894 | const auto ACBEL_FSG032_FW_VERSION_SIZE = 6; |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 895 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 896 | using PropertyMap = |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 897 | std::map<std::string, |
| 898 | std::variant<std::string, std::vector<uint8_t>, bool>>; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 899 | PropertyMap assetProps; |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 900 | PropertyMap operProps; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 901 | PropertyMap versionProps; |
| 902 | PropertyMap ipzvpdDINFProps; |
| 903 | PropertyMap ipzvpdVINIProps; |
| 904 | using InterfaceMap = std::map<std::string, PropertyMap>; |
| 905 | InterfaceMap interfaces; |
| 906 | using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>; |
| 907 | ObjectMap object; |
| 908 | #endif |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 909 | log<level::DEBUG>( |
| 910 | fmt::format("updateInventory() inventoryPath: {}", inventoryPath) |
| 911 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 912 | |
| 913 | if (present) |
| 914 | { |
| 915 | // TODO: non-IBM inventory updates? |
| 916 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 917 | #if IBM_VPD |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 918 | if (driverName == ACBEL_FSG032_DD_NAME) |
faisal | aded7a0 | 2023-05-10 14:59:01 -0500 | [diff] [blame] | 919 | { |
| 920 | getPsuVpdFromDbus("CC", modelName); |
| 921 | getPsuVpdFromDbus("PN", pn); |
| 922 | getPsuVpdFromDbus("FN", fn); |
| 923 | getPsuVpdFromDbus("SN", sn); |
| 924 | assetProps.emplace(SN_PROP, sn); |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 925 | fwVersion = readVPDValue(FW_VERSION, Type::Debug, |
| 926 | ACBEL_FSG032_FW_VERSION_SIZE); |
| 927 | versionProps.emplace(VERSION_PROP, fwVersion); |
faisal | aded7a0 | 2023-05-10 14:59:01 -0500 | [diff] [blame] | 928 | } |
| 929 | else |
| 930 | { |
| 931 | modelName = readVPDValue(CCIN, Type::HwmonDeviceDebug, CC_KW_SIZE); |
| 932 | pn = readVPDValue(PART_NUMBER, Type::Debug, PN_KW_SIZE); |
| 933 | fn = readVPDValue(FRU_NUMBER, Type::Debug, FN_KW_SIZE); |
| 934 | |
| 935 | header = readVPDValue(SERIAL_HEADER, Type::Debug, HEADER_SIZE); |
| 936 | sn = readVPDValue(SERIAL_NUMBER, Type::Debug, SERIAL_SIZE); |
| 937 | assetProps.emplace(SN_PROP, header + sn); |
Faisal Awada | 9582d9c | 2023-07-11 09:31:22 -0500 | [diff] [blame^] | 938 | fwVersion = readVPDValue(FW_VERSION, Type::HwmonDeviceDebug, |
| 939 | IBMCFFPS_FW_VERSION_SIZE); |
| 940 | versionProps.emplace(VERSION_PROP, fwVersion); |
faisal | aded7a0 | 2023-05-10 14:59:01 -0500 | [diff] [blame] | 941 | } |
| 942 | |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 943 | assetProps.emplace(MODEL_PROP, modelName); |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 944 | assetProps.emplace(PN_PROP, pn); |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 945 | assetProps.emplace(SPARE_PN_PROP, fn); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 946 | |
Brandon Wyman | 8393f46 | 2022-06-28 16:06:46 +0000 | [diff] [blame] | 947 | ipzvpdVINIProps.emplace( |
| 948 | "CC", std::vector<uint8_t>(modelName.begin(), modelName.end())); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 949 | ipzvpdVINIProps.emplace("PN", |
| 950 | std::vector<uint8_t>(pn.begin(), pn.end())); |
| 951 | ipzvpdVINIProps.emplace("FN", |
| 952 | std::vector<uint8_t>(fn.begin(), fn.end())); |
Brandon Wyman | 33d492f | 2022-03-23 20:45:17 +0000 | [diff] [blame] | 953 | std::string header_sn = header + sn; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 954 | ipzvpdVINIProps.emplace( |
| 955 | "SN", std::vector<uint8_t>(header_sn.begin(), header_sn.end())); |
| 956 | std::string description = "IBM PS"; |
| 957 | ipzvpdVINIProps.emplace( |
| 958 | "DR", std::vector<uint8_t>(description.begin(), description.end())); |
| 959 | |
Ben Tyner | f8d8c46 | 2022-01-27 16:09:45 -0600 | [diff] [blame] | 960 | // Populate the VINI Resource Type (RT) keyword |
| 961 | ipzvpdVINIProps.emplace("RT", std::vector<uint8_t>{'V', 'I', 'N', 'I'}); |
| 962 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 963 | // Update the Resource Identifier (RI) keyword |
| 964 | // 2 byte FRC: 0x0003 |
| 965 | // 2 byte RID: 0x1000, 0x1001... |
| 966 | std::uint8_t num = std::stoul( |
| 967 | inventoryPath.substr(inventoryPath.size() - 1, 1), nullptr, 0); |
| 968 | std::vector<uint8_t> ri{0x00, 0x03, 0x10, num}; |
| 969 | ipzvpdDINFProps.emplace("RI", ri); |
| 970 | |
| 971 | // Fill in the FRU Label (FL) keyword. |
| 972 | std::string fl = "E"; |
| 973 | fl.push_back(inventoryPath.back()); |
| 974 | fl.resize(FL_KW_SIZE, ' '); |
| 975 | ipzvpdDINFProps.emplace("FL", |
| 976 | std::vector<uint8_t>(fl.begin(), fl.end())); |
| 977 | |
Ben Tyner | f8d8c46 | 2022-01-27 16:09:45 -0600 | [diff] [blame] | 978 | // Populate the DINF Resource Type (RT) keyword |
| 979 | ipzvpdDINFProps.emplace("RT", std::vector<uint8_t>{'D', 'I', 'N', 'F'}); |
| 980 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 981 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
| 982 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 983 | interfaces.emplace(DINF_IFACE, std::move(ipzvpdDINFProps)); |
| 984 | interfaces.emplace(VINI_IFACE, std::move(ipzvpdVINIProps)); |
| 985 | |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 986 | // Update the Functional |
| 987 | operProps.emplace(FUNCTIONAL_PROP, present); |
| 988 | interfaces.emplace(OPERATIONAL_STATE_IFACE, std::move(operProps)); |
| 989 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 990 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 991 | object.emplace(path, std::move(interfaces)); |
| 992 | |
| 993 | try |
| 994 | { |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 995 | auto service = util::getService(INVENTORY_OBJ_PATH, |
| 996 | INVENTORY_MGR_IFACE, bus); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 997 | |
| 998 | if (service.empty()) |
| 999 | { |
| 1000 | log<level::ERR>("Unable to get inventory manager service"); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1004 | auto method = bus.new_method_call(service.c_str(), |
| 1005 | INVENTORY_OBJ_PATH, |
| 1006 | INVENTORY_MGR_IFACE, "Notify"); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 1007 | |
| 1008 | method.append(std::move(object)); |
| 1009 | |
| 1010 | auto reply = bus.call(method); |
| 1011 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 1012 | catch (const std::exception& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 1013 | { |
Jay Meyer | 6a3fd2c | 2020-08-25 16:37:16 -0500 | [diff] [blame] | 1014 | log<level::ERR>( |
| 1015 | std::string(e.what() + std::string(" PATH=") + inventoryPath) |
| 1016 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 1017 | } |
| 1018 | #endif |
| 1019 | } |
| 1020 | } |
| 1021 | |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1022 | auto PowerSupply::getMaxPowerOut() const |
| 1023 | { |
| 1024 | using namespace phosphor::pmbus; |
| 1025 | |
| 1026 | auto maxPowerOut = 0; |
| 1027 | |
| 1028 | if (present) |
| 1029 | { |
| 1030 | try |
| 1031 | { |
| 1032 | // Read max_power_out, should be direct format |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1033 | auto maxPowerOutStr = pmbusIntf->readString(MFR_POUT_MAX, |
| 1034 | Type::HwmonDeviceDebug); |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1035 | log<level::INFO>(fmt::format("{} MFR_POUT_MAX read {}", shortName, |
| 1036 | maxPowerOutStr) |
| 1037 | .c_str()); |
| 1038 | maxPowerOut = std::stod(maxPowerOutStr); |
| 1039 | } |
| 1040 | catch (const std::exception& e) |
| 1041 | { |
| 1042 | log<level::ERR>(fmt::format("{} MFR_POUT_MAX read error: {}", |
| 1043 | shortName, e.what()) |
| 1044 | .c_str()); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | return maxPowerOut; |
| 1049 | } |
| 1050 | |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1051 | void PowerSupply::setupInputHistory() |
| 1052 | { |
Faisal Awada | b66ae50 | 2023-04-01 18:30:32 -0500 | [diff] [blame] | 1053 | if (bindPath.string().find(IBMCFFPS_DD_NAME) != std::string::npos) |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1054 | { |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1055 | auto maxPowerOut = getMaxPowerOut(); |
| 1056 | |
| 1057 | if (maxPowerOut != phosphor::pmbus::IBM_CFFPS_1400W) |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1058 | { |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1059 | // Do not enable input history for power supplies that are missing |
| 1060 | if (present) |
| 1061 | { |
| 1062 | inputHistorySupported = true; |
| 1063 | log<level::INFO>( |
| 1064 | fmt::format("{} INPUT_HISTORY enabled", shortName).c_str()); |
| 1065 | |
| 1066 | std::string name{fmt::format("{}_input_power", shortName)}; |
| 1067 | |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1068 | historyObjectPath = std::string{INPUT_HISTORY_SENSOR_ROOT} + |
| 1069 | '/' + name; |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1070 | |
| 1071 | // If the power supply was present, we created the |
| 1072 | // recordManager. If it then went missing, the recordManager is |
| 1073 | // still there. If it then is reinserted, we should be able to |
| 1074 | // use the recordManager that was allocated when it was |
| 1075 | // initially present. |
| 1076 | if (!recordManager) |
| 1077 | { |
| 1078 | recordManager = std::make_unique<history::RecordManager>( |
| 1079 | INPUT_HISTORY_MAX_RECORDS); |
| 1080 | } |
| 1081 | |
| 1082 | if (!average) |
| 1083 | { |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1084 | auto avgPath = historyObjectPath + '/' + |
| 1085 | history::Average::name; |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1086 | average = std::make_unique<history::Average>(bus, avgPath); |
| 1087 | log<level::DEBUG>( |
| 1088 | fmt::format("{} avgPath: {}", shortName, avgPath) |
| 1089 | .c_str()); |
| 1090 | } |
| 1091 | |
| 1092 | if (!maximum) |
| 1093 | { |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1094 | auto maxPath = historyObjectPath + '/' + |
| 1095 | history::Maximum::name; |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1096 | maximum = std::make_unique<history::Maximum>(bus, maxPath); |
| 1097 | log<level::DEBUG>( |
| 1098 | fmt::format("{} maxPath: {}", shortName, maxPath) |
| 1099 | .c_str()); |
| 1100 | } |
| 1101 | |
| 1102 | log<level::DEBUG>(fmt::format("{} historyObjectPath: {}", |
| 1103 | shortName, historyObjectPath) |
| 1104 | .c_str()); |
| 1105 | } |
| 1106 | } |
| 1107 | else |
| 1108 | { |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1109 | log<level::INFO>( |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1110 | fmt::format("{} INPUT_HISTORY DISABLED. max_power_out: {}", |
| 1111 | shortName, maxPowerOut) |
| 1112 | .c_str()); |
| 1113 | inputHistorySupported = false; |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | inputHistorySupported = false; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | void PowerSupply::updateHistory() |
| 1123 | { |
| 1124 | if (!recordManager) |
| 1125 | { |
| 1126 | // Not enabled |
| 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | if (!present) |
| 1131 | { |
| 1132 | // Cannot read when not present |
| 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | // Read just the most recent average/max record |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 1137 | auto data = pmbusIntf->readBinary(INPUT_HISTORY, |
| 1138 | pmbus::Type::HwmonDeviceDebug, |
| 1139 | history::RecordManager::RAW_RECORD_SIZE); |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1140 | |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 1141 | // Update D-Bus only if something changed (a new record ID, or cleared |
| 1142 | // out) |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1143 | auto changed = recordManager->add(data); |
| 1144 | if (changed) |
| 1145 | { |
Patrick Williams | 41a6b9f | 2023-05-31 19:54:59 -0500 | [diff] [blame] | 1146 | average->values(recordManager->getAverageRecords()); |
| 1147 | maximum->values(recordManager->getMaximumRecords()); |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 1151 | void PowerSupply::getInputVoltage(double& actualInputVoltage, |
| 1152 | int& inputVoltage) const |
| 1153 | { |
| 1154 | using namespace phosphor::pmbus; |
| 1155 | |
| 1156 | actualInputVoltage = in_input::VIN_VOLTAGE_0; |
| 1157 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 1158 | |
| 1159 | if (present) |
| 1160 | { |
| 1161 | try |
| 1162 | { |
| 1163 | // Read input voltage in millivolts |
| 1164 | auto inputVoltageStr = pmbusIntf->readString(READ_VIN, Type::Hwmon); |
| 1165 | |
| 1166 | // Convert to volts |
| 1167 | actualInputVoltage = std::stod(inputVoltageStr) / 1000; |
| 1168 | |
| 1169 | // Calculate the voltage based on voltage thresholds |
| 1170 | if (actualInputVoltage < in_input::VIN_VOLTAGE_MIN) |
| 1171 | { |
| 1172 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 1173 | } |
| 1174 | else if (actualInputVoltage < in_input::VIN_VOLTAGE_110_THRESHOLD) |
| 1175 | { |
| 1176 | inputVoltage = in_input::VIN_VOLTAGE_110; |
| 1177 | } |
| 1178 | else |
| 1179 | { |
| 1180 | inputVoltage = in_input::VIN_VOLTAGE_220; |
| 1181 | } |
| 1182 | } |
| 1183 | catch (const std::exception& e) |
| 1184 | { |
| 1185 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 1186 | fmt::format("{} READ_VIN read error: {}", shortName, e.what()) |
| 1187 | .c_str()); |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 1192 | void PowerSupply::checkAvailability() |
| 1193 | { |
| 1194 | bool origAvailability = available; |
George Liu | 9464c42 | 2023-02-27 14:30:27 +0800 | [diff] [blame] | 1195 | bool faulted = isPowerOn() && (hasPSKillFault() || hasIoutOCFault()); |
| 1196 | available = present && !hasInputFault() && !hasVINUVFault() && !faulted; |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 1197 | |
| 1198 | if (origAvailability != available) |
| 1199 | { |
| 1200 | auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 1201 | phosphor::power::psu::setAvailable(bus, invpath, available); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 1202 | |
| 1203 | // Check if the health rollup needs to change based on the |
| 1204 | // new availability value. |
| 1205 | phosphor::power::psu::handleChassisHealthRollup(bus, inventoryPath, |
| 1206 | !available); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 1210 | void PowerSupply::setInputVoltageRating() |
| 1211 | { |
| 1212 | if (!present) |
| 1213 | { |
Matt Spinler | 1aaf9f8 | 2023-03-22 09:52:22 -0500 | [diff] [blame] | 1214 | if (inputVoltageRatingIface) |
| 1215 | { |
| 1216 | inputVoltageRatingIface->value(0); |
| 1217 | inputVoltageRatingIface.reset(); |
| 1218 | } |
Matt Spinler | a068f42 | 2023-03-10 13:06:49 -0600 | [diff] [blame] | 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | double inputVoltageValue{}; |
| 1223 | int inputVoltageRating{}; |
| 1224 | getInputVoltage(inputVoltageValue, inputVoltageRating); |
| 1225 | |
| 1226 | if (!inputVoltageRatingIface) |
| 1227 | { |
| 1228 | auto path = fmt::format( |
| 1229 | "/xyz/openbmc_project/sensors/voltage/ps{}_input_voltage_rating", |
| 1230 | shortName.back()); |
| 1231 | |
| 1232 | inputVoltageRatingIface = std::make_unique<SensorObject>( |
| 1233 | bus, path.c_str(), SensorObject::action::defer_emit); |
| 1234 | |
| 1235 | // Leave other properties at their defaults |
| 1236 | inputVoltageRatingIface->unit(SensorInterface::Unit::Volts, true); |
| 1237 | inputVoltageRatingIface->value(static_cast<double>(inputVoltageRating), |
| 1238 | true); |
| 1239 | |
| 1240 | inputVoltageRatingIface->emit_object_added(); |
| 1241 | } |
| 1242 | else |
| 1243 | { |
| 1244 | inputVoltageRatingIface->value(static_cast<double>(inputVoltageRating)); |
| 1245 | } |
| 1246 | } |
| 1247 | |
faisal | aded7a0 | 2023-05-10 14:59:01 -0500 | [diff] [blame] | 1248 | void PowerSupply::getPsuVpdFromDbus(const std::string& keyword, |
| 1249 | std::string& vpdStr) |
| 1250 | { |
| 1251 | try |
| 1252 | { |
| 1253 | std::vector<uint8_t> value; |
| 1254 | vpdStr.clear(); |
| 1255 | util::getProperty(VINI_IFACE, keyword, inventoryPath, |
| 1256 | INVENTORY_MGR_IFACE, bus, value); |
| 1257 | for (char c : value) |
| 1258 | { |
| 1259 | vpdStr += c; |
| 1260 | } |
| 1261 | } |
| 1262 | catch (const sdbusplus::exception_t& e) |
| 1263 | { |
| 1264 | log<level::ERR>( |
| 1265 | fmt::format("Failed getProperty error: {}", e.what()).c_str()); |
| 1266 | } |
| 1267 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1268 | } // namespace phosphor::power::psu |