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