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