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