Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 3 | #include "power_supply.hpp" |
| 4 | |
| 5 | #include "types.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 6 | #include "util.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 7 | |
Brandon Wyman | df13c3a | 2020-12-15 14:25:22 -0600 | [diff] [blame] | 8 | #include <fmt/format.h> |
| 9 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 11 | |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 12 | #include <chrono> // sleep_for() |
| 13 | #include <cmath> |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 14 | #include <cstdint> // uint8_t... |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 15 | #include <fstream> |
| 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 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 27 | PowerSupply::PowerSupply(sdbusplus::bus::bus& 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, |
| 29 | const std::string& gpioLineName) : |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 30 | bus(bus), |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 31 | inventoryPath(invpath), bindPath("/sys/bus/i2c/drivers/ibm-cffps") |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 32 | { |
| 33 | if (inventoryPath.empty()) |
| 34 | { |
| 35 | throw std::invalid_argument{"Invalid empty inventoryPath"}; |
| 36 | } |
| 37 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 38 | if (gpioLineName.empty()) |
| 39 | { |
| 40 | throw std::invalid_argument{"Invalid empty gpioLineName"}; |
| 41 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 42 | |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 43 | shortName = findShortName(inventoryPath); |
| 44 | |
| 45 | log<level::DEBUG>( |
| 46 | fmt::format("{} gpioLineName: {}", shortName, gpioLineName).c_str()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 47 | presenceGPIO = createGPIO(gpioLineName); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 48 | |
| 49 | std::ostringstream ss; |
| 50 | ss << std::hex << std::setw(4) << std::setfill('0') << i2caddr; |
| 51 | std::string addrStr = ss.str(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 52 | std::string busStr = std::to_string(i2cbus); |
| 53 | bindDevice = busStr; |
| 54 | bindDevice.append("-"); |
| 55 | bindDevice.append(addrStr); |
| 56 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 57 | pmbusIntf = phosphor::pmbus::createPMBus(i2cbus, addrStr); |
| 58 | |
| 59 | // Get the current state of the Present property. |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 60 | try |
| 61 | { |
| 62 | updatePresenceGPIO(); |
| 63 | } |
| 64 | catch (...) |
| 65 | { |
| 66 | // If the above attempt to use the GPIO failed, it likely means that the |
| 67 | // GPIOs are in use by the kernel, meaning it is using gpio-keys. |
| 68 | // So, I should rely on phosphor-gpio-presence to update D-Bus, and |
| 69 | // work that way for power supply presence. |
| 70 | presenceGPIO = nullptr; |
| 71 | // Setup the functions to call when the D-Bus inventory path for the |
| 72 | // Present property changes. |
| 73 | presentMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 74 | bus, |
| 75 | sdbusplus::bus::match::rules::propertiesChanged(inventoryPath, |
| 76 | INVENTORY_IFACE), |
| 77 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 78 | |
| 79 | presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 80 | bus, |
| 81 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 82 | sdbusplus::bus::match::rules::argNpath(0, inventoryPath), |
| 83 | [this](auto& msg) { this->inventoryAdded(msg); }); |
| 84 | |
| 85 | updatePresence(); |
| 86 | updateInventory(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void PowerSupply::bindOrUnbindDriver(bool present) |
| 91 | { |
| 92 | auto action = (present) ? "bind" : "unbind"; |
| 93 | auto path = bindPath / action; |
| 94 | |
| 95 | if (present) |
| 96 | { |
Brandon Wyman | b1ee60f | 2022-03-22 22:37:12 +0000 | [diff] [blame^] | 97 | std::this_thread::sleep_for(std::chrono::milliseconds(bindDelay)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 98 | log<level::INFO>( |
| 99 | fmt::format("Binding device driver. path: {} device: {}", |
| 100 | path.string(), bindDevice) |
| 101 | .c_str()); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | log<level::INFO>( |
| 106 | fmt::format("Unbinding device driver. path: {} device: {}", |
| 107 | path.string(), bindDevice) |
| 108 | .c_str()); |
| 109 | } |
| 110 | |
| 111 | std::ofstream file; |
| 112 | |
| 113 | file.exceptions(std::ofstream::failbit | std::ofstream::badbit | |
| 114 | std::ofstream::eofbit); |
| 115 | |
| 116 | try |
| 117 | { |
| 118 | file.open(path); |
| 119 | file << bindDevice; |
| 120 | file.close(); |
| 121 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 122 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 123 | { |
| 124 | auto err = errno; |
| 125 | |
| 126 | log<level::ERR>( |
| 127 | fmt::format("Failed binding or unbinding device. errno={}", err) |
| 128 | .c_str()); |
| 129 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 130 | } |
| 131 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 132 | void PowerSupply::updatePresence() |
| 133 | { |
| 134 | try |
| 135 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 136 | present = getPresence(bus, inventoryPath); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 137 | } |
Patrick Williams | 69f10ad | 2021-09-02 09:46:49 -0500 | [diff] [blame] | 138 | catch (const sdbusplus::exception::exception& e) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 139 | { |
| 140 | // Relying on property change or interface added to retry. |
| 141 | // Log an informational trace to the journal. |
Brandon Wyman | df13c3a | 2020-12-15 14:25:22 -0600 | [diff] [blame] | 142 | log<level::INFO>( |
| 143 | fmt::format("D-Bus property {} access failure exception", |
| 144 | inventoryPath) |
| 145 | .c_str()); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 149 | void PowerSupply::updatePresenceGPIO() |
| 150 | { |
| 151 | bool presentOld = present; |
| 152 | |
| 153 | try |
| 154 | { |
| 155 | if (presenceGPIO->read() > 0) |
| 156 | { |
| 157 | present = true; |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | present = false; |
| 162 | } |
| 163 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 164 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 165 | { |
| 166 | log<level::ERR>( |
| 167 | fmt::format("presenceGPIO read fail: {}", e.what()).c_str()); |
| 168 | throw; |
| 169 | } |
| 170 | |
| 171 | if (presentOld != present) |
| 172 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 173 | log<level::DEBUG>(fmt::format("{} presentOld: {} present: {}", |
| 174 | shortName, presentOld, present) |
| 175 | .c_str()); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 176 | |
| 177 | auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 178 | setPresence(bus, invpath, present, shortName); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 179 | updateInventory(); |
| 180 | |
| 181 | // Need Functional to already be correct before calling this |
| 182 | checkAvailability(); |
| 183 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 184 | if (present) |
| 185 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 186 | bindOrUnbindDriver(present); |
| 187 | pmbusIntf->findHwmonDir(); |
| 188 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
| 189 | clearFaults(); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | bindOrUnbindDriver(present); |
| 194 | } |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 198 | void PowerSupply::analyzeCMLFault() |
| 199 | { |
| 200 | if (statusWord & phosphor::pmbus::status_word::CML_FAULT) |
| 201 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 202 | if (cmlFault < DEGLITCH_LIMIT) |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 203 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 204 | if (statusWord != statusWordOld) |
| 205 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 206 | log<level::ERR>( |
| 207 | fmt::format("{} CML fault: STATUS_WORD = {:#06x}, " |
| 208 | "STATUS_CML = {:#02x}", |
| 209 | shortName, statusWord, statusCML) |
| 210 | .c_str()); |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 211 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 212 | cmlFault++; |
| 213 | } |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | cmlFault = 0; |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 221 | void PowerSupply::analyzeInputFault() |
| 222 | { |
| 223 | if (statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN) |
| 224 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 225 | if (inputFault < DEGLITCH_LIMIT) |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 226 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 227 | if (statusWord != statusWordOld) |
| 228 | { |
| 229 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 230 | fmt::format("{} INPUT fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 231 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 232 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 233 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 234 | .c_str()); |
| 235 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 236 | inputFault++; |
| 237 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 238 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 239 | |
| 240 | // If had INPUT/VIN_UV fault, and now off. |
| 241 | // Trace that odd behavior. |
| 242 | if (inputFault && |
| 243 | !(statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN)) |
| 244 | { |
| 245 | log<level::INFO>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 246 | fmt::format("{} INPUT fault cleared: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 6f939a3 | 2022-03-10 18:42:20 +0000 | [diff] [blame] | 247 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 248 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 249 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 250 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 251 | inputFault = 0; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 252 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 255 | void PowerSupply::analyzeVoutOVFault() |
| 256 | { |
| 257 | if (statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT) |
| 258 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 259 | if (voutOVFault < DEGLITCH_LIMIT) |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 260 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 261 | if (statusWord != statusWordOld) |
| 262 | { |
| 263 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 264 | fmt::format( |
| 265 | "{} VOUT_OV_FAULT fault: STATUS_WORD = {:#06x}, " |
| 266 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 267 | "STATUS_VOUT = {:#02x}", |
| 268 | shortName, statusWord, statusMFR, statusVout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 269 | .c_str()); |
| 270 | } |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 271 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 272 | voutOVFault++; |
| 273 | } |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | voutOVFault = 0; |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 281 | void PowerSupply::analyzeIoutOCFault() |
| 282 | { |
| 283 | if (statusWord & phosphor::pmbus::status_word::IOUT_OC_FAULT) |
| 284 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 285 | if (ioutOCFault < DEGLITCH_LIMIT) |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 286 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 287 | if (statusWord != statusWordOld) |
| 288 | { |
| 289 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 290 | fmt::format("{} IOUT fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 291 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 292 | "STATUS_IOUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 293 | shortName, statusWord, statusMFR, statusIout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 294 | .c_str()); |
| 295 | } |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 296 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 297 | ioutOCFault++; |
| 298 | } |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | ioutOCFault = 0; |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 306 | void PowerSupply::analyzeVoutUVFault() |
| 307 | { |
| 308 | if ((statusWord & phosphor::pmbus::status_word::VOUT_FAULT) && |
| 309 | !(statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT)) |
| 310 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 311 | if (voutUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 312 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 313 | if (statusWord != statusWordOld) |
| 314 | { |
| 315 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 316 | fmt::format( |
| 317 | "{} VOUT_UV_FAULT fault: STATUS_WORD = {:#06x}, " |
| 318 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 319 | "STATUS_VOUT = {:#04x}", |
| 320 | shortName, statusWord, statusMFR, statusVout) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 321 | .c_str()); |
| 322 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 323 | voutUVFault++; |
| 324 | } |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | voutUVFault = 0; |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 332 | void PowerSupply::analyzeFanFault() |
| 333 | { |
| 334 | if (statusWord & phosphor::pmbus::status_word::FAN_FAULT) |
| 335 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 336 | if (fanFault < DEGLITCH_LIMIT) |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 337 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 338 | if (statusWord != statusWordOld) |
| 339 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 340 | log<level::ERR>(fmt::format("{} FANS fault/warning: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 341 | "STATUS_WORD = {:#06x}, " |
| 342 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 343 | "STATUS_FANS_1_2 = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 344 | shortName, statusWord, statusMFR, |
| 345 | statusFans12) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 346 | .c_str()); |
| 347 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 348 | fanFault++; |
| 349 | } |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | fanFault = 0; |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 357 | void PowerSupply::analyzeTemperatureFault() |
| 358 | { |
| 359 | if (statusWord & phosphor::pmbus::status_word::TEMPERATURE_FAULT_WARN) |
| 360 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 361 | if (tempFault < DEGLITCH_LIMIT) |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 362 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 363 | if (statusWord != statusWordOld) |
| 364 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 365 | log<level::ERR>(fmt::format("{} TEMPERATURE fault/warning: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 366 | "STATUS_WORD = {:#06x}, " |
| 367 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 368 | "STATUS_TEMPERATURE = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 369 | shortName, statusWord, statusMFR, |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 370 | statusTemperature) |
| 371 | .c_str()); |
| 372 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 373 | tempFault++; |
| 374 | } |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | tempFault = 0; |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 382 | void PowerSupply::analyzePgoodFault() |
| 383 | { |
| 384 | if ((statusWord & phosphor::pmbus::status_word::POWER_GOOD_NEGATED) || |
| 385 | (statusWord & phosphor::pmbus::status_word::UNIT_IS_OFF)) |
| 386 | { |
| 387 | if (pgoodFault < DEGLITCH_LIMIT) |
| 388 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 389 | if (statusWord != statusWordOld) |
| 390 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 391 | log<level::ERR>(fmt::format("{} PGOOD fault: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 392 | "STATUS_WORD = {:#06x}, " |
| 393 | "STATUS_MFR_SPECIFIC = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 394 | shortName, statusWord, statusMFR) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 395 | .c_str()); |
| 396 | } |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 397 | pgoodFault++; |
| 398 | } |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | pgoodFault = 0; |
| 403 | } |
| 404 | } |
| 405 | |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 406 | void PowerSupply::determineMFRFault() |
| 407 | { |
| 408 | if (bindPath.string().find("ibm-cffps") != std::string::npos) |
| 409 | { |
| 410 | // IBM MFR_SPECIFIC[4] is PS_Kill fault |
| 411 | if (statusMFR & 0x10) |
| 412 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 413 | if (psKillFault < DEGLITCH_LIMIT) |
| 414 | { |
| 415 | psKillFault++; |
| 416 | } |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | psKillFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 421 | } |
| 422 | // IBM MFR_SPECIFIC[6] is 12Vcs fault. |
| 423 | if (statusMFR & 0x40) |
| 424 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 425 | if (ps12VcsFault < DEGLITCH_LIMIT) |
| 426 | { |
| 427 | ps12VcsFault++; |
| 428 | } |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | ps12VcsFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 433 | } |
| 434 | // IBM MFR_SPECIFIC[7] is 12V Current-Share fault. |
| 435 | if (statusMFR & 0x80) |
| 436 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 437 | if (psCS12VFault < DEGLITCH_LIMIT) |
| 438 | { |
| 439 | psCS12VFault++; |
| 440 | } |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | psCS12VFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 449 | void PowerSupply::analyzeMFRFault() |
| 450 | { |
| 451 | if (statusWord & phosphor::pmbus::status_word::MFR_SPECIFIC_FAULT) |
| 452 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 453 | if (mfrFault < DEGLITCH_LIMIT) |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 454 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 455 | if (statusWord != statusWordOld) |
| 456 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 457 | log<level::ERR>(fmt::format("{} MFR fault: " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 458 | "STATUS_WORD = {:#06x} " |
| 459 | "STATUS_MFR_SPECIFIC = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 460 | shortName, statusWord, statusMFR) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 461 | .c_str()); |
| 462 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 463 | mfrFault++; |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 466 | determineMFRFault(); |
| 467 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 468 | else |
| 469 | { |
| 470 | mfrFault = 0; |
| 471 | } |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 474 | void PowerSupply::analyzeVinUVFault() |
| 475 | { |
| 476 | if (statusWord & phosphor::pmbus::status_word::VIN_UV_FAULT) |
| 477 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 478 | if (vinUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 479 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 480 | if (statusWord != statusWordOld) |
| 481 | { |
| 482 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 483 | fmt::format("{} VIN_UV fault: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 484 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 485 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 486 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 487 | .c_str()); |
| 488 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 489 | vinUVFault++; |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 490 | } |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 491 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 492 | |
| 493 | if (vinUVFault && |
| 494 | !(statusWord & phosphor::pmbus::status_word::VIN_UV_FAULT)) |
| 495 | { |
| 496 | log<level::INFO>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 497 | fmt::format("{} VIN_UV fault cleared: STATUS_WORD = {:#06x}, " |
Brandon Wyman | 6f939a3 | 2022-03-10 18:42:20 +0000 | [diff] [blame] | 498 | "STATUS_MFR_SPECIFIC = {:#04x}, " |
| 499 | "STATUS_INPUT = {:#04x}", |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 500 | shortName, statusWord, statusMFR, statusInput) |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 501 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 502 | vinUVFault = 0; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 503 | } |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 506 | void PowerSupply::analyze() |
| 507 | { |
| 508 | using namespace phosphor::pmbus; |
| 509 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 510 | if (presenceGPIO) |
| 511 | { |
| 512 | updatePresenceGPIO(); |
| 513 | } |
| 514 | |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 515 | if (present) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 516 | { |
| 517 | try |
| 518 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 519 | statusWordOld = statusWord; |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 520 | statusWord = pmbusIntf->read(STATUS_WORD, Type::Debug, |
| 521 | (readFail < LOG_LIMIT)); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 522 | // Read worked, reset the fail count. |
| 523 | readFail = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 524 | |
| 525 | if (statusWord) |
| 526 | { |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 527 | statusInput = pmbusIntf->read(STATUS_INPUT, Type::Debug); |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 528 | statusMFR = pmbusIntf->read(STATUS_MFR, Type::Debug); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 529 | statusCML = pmbusIntf->read(STATUS_CML, Type::Debug); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 530 | auto status0Vout = pmbusIntf->insertPageNum(STATUS_VOUT, 0); |
| 531 | statusVout = pmbusIntf->read(status0Vout, Type::Debug); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 532 | statusIout = pmbusIntf->read(STATUS_IOUT, Type::Debug); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 533 | statusFans12 = pmbusIntf->read(STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 534 | statusTemperature = |
| 535 | pmbusIntf->read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 536 | |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 537 | analyzeCMLFault(); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 538 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 539 | analyzeInputFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 540 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 541 | analyzeVoutOVFault(); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 542 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 543 | analyzeIoutOCFault(); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 544 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 545 | analyzeVoutUVFault(); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 546 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 547 | analyzeFanFault(); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 548 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 549 | analyzeTemperatureFault(); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 550 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 551 | analyzePgoodFault(); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 552 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 553 | analyzeMFRFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 554 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 555 | analyzeVinUVFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 556 | } |
| 557 | else |
| 558 | { |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 559 | if (statusWord != statusWordOld) |
| 560 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 561 | log<level::INFO>(fmt::format("{} STATUS_WORD = {:#06x}", |
| 562 | shortName, statusWord) |
Brandon Wyman | 9e292ee | 2022-03-10 22:56:23 +0000 | [diff] [blame] | 563 | .c_str()); |
| 564 | } |
| 565 | |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 566 | // if INPUT/VIN_UV fault was on, it cleared, trace it. |
| 567 | if (inputFault) |
| 568 | { |
| 569 | log<level::INFO>( |
| 570 | fmt::format( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 571 | "{} INPUT fault cleared: STATUS_WORD = {:#06x}", |
| 572 | shortName, statusWord) |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 573 | .c_str()); |
| 574 | } |
| 575 | |
| 576 | if (vinUVFault) |
| 577 | { |
| 578 | log<level::INFO>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 579 | fmt::format("{} VIN_UV cleared: STATUS_WORD = {:#06x}", |
| 580 | shortName, statusWord) |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 581 | .c_str()); |
| 582 | } |
| 583 | |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 584 | if (pgoodFault > 0) |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 585 | { |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 586 | log<level::INFO>( |
| 587 | fmt::format("{} pgoodFault cleared", shortName) |
| 588 | .c_str()); |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 589 | } |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 590 | |
| 591 | clearFaultFlags(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 592 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 593 | |
| 594 | // Save off old inputVoltage value. |
| 595 | // Get latest inputVoltage. |
| 596 | // If voltage went from below minimum, and now is not, clear faults. |
| 597 | // Note: getInputVoltage() has its own try/catch. |
| 598 | int inputVoltageOld = inputVoltage; |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 599 | double actualInputVoltageOld = actualInputVoltage; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 600 | getInputVoltage(actualInputVoltage, inputVoltage); |
| 601 | if ((inputVoltageOld == in_input::VIN_VOLTAGE_0) && |
| 602 | (inputVoltage != in_input::VIN_VOLTAGE_0)) |
| 603 | { |
| 604 | log<level::INFO>( |
| 605 | fmt::format( |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 606 | "{} READ_VIN back in range: actualInputVoltageOld = {} " |
| 607 | "actualInputVoltage = {}", |
| 608 | shortName, actualInputVoltageOld, actualInputVoltage) |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 609 | .c_str()); |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 610 | clearVinUVFault(); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 611 | } |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 612 | else if (vinUVFault && (inputVoltage != in_input::VIN_VOLTAGE_0)) |
| 613 | { |
| 614 | log<level::INFO>( |
| 615 | fmt::format( |
| 616 | "{} CLEAR_FAULTS: vinUVFault {} actualInputVoltage {}", |
| 617 | shortName, vinUVFault, actualInputVoltage) |
| 618 | .c_str()); |
| 619 | // Do we have a VIN_UV fault latched that can now be cleared |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 620 | // due to voltage back in range? Attempt to clear the fault(s), |
| 621 | // re-check faults on next call. |
| 622 | clearVinUVFault(); |
Brandon Wyman | 4fc191f | 2022-03-10 23:07:13 +0000 | [diff] [blame] | 623 | } |
| 624 | else if (std::abs(actualInputVoltageOld - actualInputVoltage) > 1.0) |
| 625 | { |
| 626 | log<level::INFO>( |
| 627 | fmt::format( |
| 628 | "{} actualInputVoltageOld = {} actualInputVoltage = {}", |
| 629 | shortName, actualInputVoltageOld, actualInputVoltage) |
| 630 | .c_str()); |
| 631 | } |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 632 | |
| 633 | checkAvailability(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 634 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 635 | catch (const ReadFailure& e) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 636 | { |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 637 | if (readFail < SIZE_MAX) |
| 638 | { |
| 639 | readFail++; |
| 640 | } |
| 641 | if (readFail == LOG_LIMIT) |
| 642 | { |
| 643 | phosphor::logging::commit<ReadFailure>(); |
| 644 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 649 | void PowerSupply::onOffConfig(uint8_t data) |
| 650 | { |
| 651 | using namespace phosphor::pmbus; |
| 652 | |
| 653 | if (present) |
| 654 | { |
| 655 | log<level::INFO>("ON_OFF_CONFIG write", entry("DATA=0x%02X", data)); |
| 656 | try |
| 657 | { |
| 658 | std::vector<uint8_t> configData{data}; |
| 659 | pmbusIntf->writeBinary(ON_OFF_CONFIG, configData, |
| 660 | Type::HwmonDeviceDebug); |
| 661 | } |
| 662 | catch (...) |
| 663 | { |
| 664 | // The underlying code in writeBinary will log a message to the |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 665 | // journal if the write fails. If the ON_OFF_CONFIG is not setup |
| 666 | // as desired, later fault detection and analysis code should |
| 667 | // catch any of the fall out. We should not need to terminate |
| 668 | // the application if this write fails. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 673 | void PowerSupply::clearVinUVFault() |
| 674 | { |
| 675 | // Read in1_lcrit_alarm to clear bits 3 and 4 of STATUS_INPUT. |
| 676 | // The fault bits in STAUTS_INPUT roll-up to STATUS_WORD. Clearing those |
| 677 | // bits in STATUS_INPUT should result in the corresponding STATUS_WORD bits |
| 678 | // also clearing. |
| 679 | // |
| 680 | // Do not care about return value. Should be 1 if active, 0 if not. |
| 681 | static_cast<void>( |
| 682 | pmbusIntf->read("in1_lcrit_alarm", phosphor::pmbus::Type::Hwmon)); |
| 683 | vinUVFault = 0; |
| 684 | } |
| 685 | |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 686 | void PowerSupply::clearFaults() |
| 687 | { |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 688 | log<level::DEBUG>( |
| 689 | fmt::format("clearFaults() inventoryPath: {}", inventoryPath).c_str()); |
Brandon Wyman | 5474c91 | 2021-02-23 14:39:43 -0600 | [diff] [blame] | 690 | faultLogged = false; |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 691 | // The PMBus device driver does not allow for writing CLEAR_FAULTS |
| 692 | // directly. However, the pmbus hwmon device driver code will send a |
| 693 | // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so |
| 694 | // reading in1_input should result in clearing the fault bits in |
| 695 | // STATUS_BYTE/STATUS_WORD. |
| 696 | // I do not care what the return value is. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 697 | if (present) |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 698 | { |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 699 | clearFaultFlags(); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 700 | checkAvailability(); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 701 | readFail = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 702 | |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 703 | try |
| 704 | { |
Brandon Wyman | 3225a45 | 2022-03-18 18:51:49 +0000 | [diff] [blame] | 705 | clearVinUVFault(); |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 706 | static_cast<void>( |
| 707 | pmbusIntf->read("in1_input", phosphor::pmbus::Type::Hwmon)); |
| 708 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 709 | catch (const ReadFailure& e) |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 710 | { |
| 711 | // 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] | 712 | // care much if it gets a ReadFailure either. However, this |
| 713 | // should not prevent the application from continuing to run, so |
| 714 | // catching the read failure. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 715 | } |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 719 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 720 | { |
| 721 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 722 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 723 | msg.read(msgSensor, msgData); |
| 724 | |
| 725 | // Check if it was the Present property that changed. |
| 726 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 727 | if (valPropMap != msgData.end()) |
| 728 | { |
| 729 | if (std::get<bool>(valPropMap->second)) |
| 730 | { |
| 731 | present = true; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 732 | // TODO: Immediately trying to read or write the "files" causes |
| 733 | // read or write failures. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 734 | using namespace std::chrono_literals; |
| 735 | std::this_thread::sleep_for(20ms); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 736 | pmbusIntf->findHwmonDir(); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 737 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 738 | clearFaults(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 739 | updateInventory(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 740 | } |
| 741 | else |
| 742 | { |
| 743 | present = false; |
| 744 | |
| 745 | // Clear out the now outdated inventory properties |
| 746 | updateInventory(); |
| 747 | } |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 748 | checkAvailability(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 752 | void PowerSupply::inventoryAdded(sdbusplus::message::message& msg) |
| 753 | { |
| 754 | sdbusplus::message::object_path path; |
| 755 | msg.read(path); |
| 756 | // Make sure the signal is for the PSU inventory path |
| 757 | if (path == inventoryPath) |
| 758 | { |
| 759 | std::map<std::string, std::map<std::string, std::variant<bool>>> |
| 760 | interfaces; |
| 761 | // Get map of interfaces and their properties |
| 762 | msg.read(interfaces); |
| 763 | |
| 764 | auto properties = interfaces.find(INVENTORY_IFACE); |
| 765 | if (properties != interfaces.end()) |
| 766 | { |
| 767 | auto property = properties->second.find(PRESENT_PROP); |
| 768 | if (property != properties->second.end()) |
| 769 | { |
| 770 | present = std::get<bool>(property->second); |
| 771 | |
| 772 | log<level::INFO>(fmt::format("Power Supply {} Present {}", |
| 773 | inventoryPath, present) |
| 774 | .c_str()); |
| 775 | |
| 776 | updateInventory(); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 777 | checkAvailability(); |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 783 | void PowerSupply::updateInventory() |
| 784 | { |
| 785 | using namespace phosphor::pmbus; |
| 786 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 787 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 788 | std::string ccin; |
| 789 | std::string pn; |
| 790 | std::string fn; |
| 791 | std::string header; |
| 792 | std::string sn; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 793 | using PropertyMap = |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 794 | std::map<std::string, |
| 795 | std::variant<std::string, std::vector<uint8_t>, bool>>; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 796 | PropertyMap assetProps; |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 797 | PropertyMap operProps; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 798 | PropertyMap versionProps; |
| 799 | PropertyMap ipzvpdDINFProps; |
| 800 | PropertyMap ipzvpdVINIProps; |
| 801 | using InterfaceMap = std::map<std::string, PropertyMap>; |
| 802 | InterfaceMap interfaces; |
| 803 | using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>; |
| 804 | ObjectMap object; |
| 805 | #endif |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 806 | log<level::DEBUG>( |
| 807 | fmt::format("updateInventory() inventoryPath: {}", inventoryPath) |
| 808 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 809 | |
| 810 | if (present) |
| 811 | { |
| 812 | // TODO: non-IBM inventory updates? |
| 813 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 814 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 815 | try |
| 816 | { |
| 817 | ccin = pmbusIntf->readString(CCIN, Type::HwmonDeviceDebug); |
| 818 | assetProps.emplace(MODEL_PROP, ccin); |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 819 | modelName = ccin; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 820 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 821 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 822 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 823 | // Ignore the read failure, let pmbus code indicate failure, |
| 824 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 825 | // TODO - ibm918 |
| 826 | // https://github.com/openbmc/docs/blob/master/designs/vpd-collection.md |
| 827 | // The BMC must log errors if any of the VPD cannot be properly |
| 828 | // parsed or fails ECC checks. |
| 829 | } |
| 830 | |
| 831 | try |
| 832 | { |
| 833 | pn = pmbusIntf->readString(PART_NUMBER, Type::HwmonDeviceDebug); |
| 834 | assetProps.emplace(PN_PROP, pn); |
| 835 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 836 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 837 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 838 | // Ignore the read failure, let pmbus code indicate failure, |
| 839 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | try |
| 843 | { |
| 844 | fn = pmbusIntf->readString(FRU_NUMBER, Type::HwmonDeviceDebug); |
Brandon Wyman | a169b0f | 2021-12-07 20:18:06 +0000 | [diff] [blame] | 845 | assetProps.emplace(SPARE_PN_PROP, fn); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 846 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 847 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 848 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 849 | // Ignore the read failure, let pmbus code indicate failure, |
| 850 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | try |
| 854 | { |
| 855 | header = |
| 856 | pmbusIntf->readString(SERIAL_HEADER, Type::HwmonDeviceDebug); |
| 857 | sn = pmbusIntf->readString(SERIAL_NUMBER, Type::HwmonDeviceDebug); |
Mike Capps | 1cb0f13 | 2022-03-14 11:40:30 -0400 | [diff] [blame] | 858 | assetProps.emplace(SN_PROP, header + sn); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 859 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 860 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 861 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 862 | // Ignore the read failure, let pmbus code indicate failure, |
| 863 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | try |
| 867 | { |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 868 | fwVersion = |
| 869 | pmbusIntf->readString(FW_VERSION, Type::HwmonDeviceDebug); |
| 870 | versionProps.emplace(VERSION_PROP, fwVersion); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 871 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 872 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 873 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 874 | // Ignore the read failure, let pmbus code indicate failure, |
| 875 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | ipzvpdVINIProps.emplace("CC", |
| 879 | std::vector<uint8_t>(ccin.begin(), ccin.end())); |
| 880 | ipzvpdVINIProps.emplace("PN", |
| 881 | std::vector<uint8_t>(pn.begin(), pn.end())); |
| 882 | ipzvpdVINIProps.emplace("FN", |
| 883 | std::vector<uint8_t>(fn.begin(), fn.end())); |
| 884 | std::string header_sn = header + sn + '\0'; |
| 885 | ipzvpdVINIProps.emplace( |
| 886 | "SN", std::vector<uint8_t>(header_sn.begin(), header_sn.end())); |
| 887 | std::string description = "IBM PS"; |
| 888 | ipzvpdVINIProps.emplace( |
| 889 | "DR", std::vector<uint8_t>(description.begin(), description.end())); |
| 890 | |
Ben Tyner | f8d8c46 | 2022-01-27 16:09:45 -0600 | [diff] [blame] | 891 | // Populate the VINI Resource Type (RT) keyword |
| 892 | ipzvpdVINIProps.emplace("RT", std::vector<uint8_t>{'V', 'I', 'N', 'I'}); |
| 893 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 894 | // Update the Resource Identifier (RI) keyword |
| 895 | // 2 byte FRC: 0x0003 |
| 896 | // 2 byte RID: 0x1000, 0x1001... |
| 897 | std::uint8_t num = std::stoul( |
| 898 | inventoryPath.substr(inventoryPath.size() - 1, 1), nullptr, 0); |
| 899 | std::vector<uint8_t> ri{0x00, 0x03, 0x10, num}; |
| 900 | ipzvpdDINFProps.emplace("RI", ri); |
| 901 | |
| 902 | // Fill in the FRU Label (FL) keyword. |
| 903 | std::string fl = "E"; |
| 904 | fl.push_back(inventoryPath.back()); |
| 905 | fl.resize(FL_KW_SIZE, ' '); |
| 906 | ipzvpdDINFProps.emplace("FL", |
| 907 | std::vector<uint8_t>(fl.begin(), fl.end())); |
| 908 | |
Ben Tyner | f8d8c46 | 2022-01-27 16:09:45 -0600 | [diff] [blame] | 909 | // Populate the DINF Resource Type (RT) keyword |
| 910 | ipzvpdDINFProps.emplace("RT", std::vector<uint8_t>{'D', 'I', 'N', 'F'}); |
| 911 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 912 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
| 913 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 914 | interfaces.emplace(DINF_IFACE, std::move(ipzvpdDINFProps)); |
| 915 | interfaces.emplace(VINI_IFACE, std::move(ipzvpdVINIProps)); |
| 916 | |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 917 | // Update the Functional |
| 918 | operProps.emplace(FUNCTIONAL_PROP, present); |
| 919 | interfaces.emplace(OPERATIONAL_STATE_IFACE, std::move(operProps)); |
| 920 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 921 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 922 | object.emplace(path, std::move(interfaces)); |
| 923 | |
| 924 | try |
| 925 | { |
| 926 | auto service = |
| 927 | util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus); |
| 928 | |
| 929 | if (service.empty()) |
| 930 | { |
| 931 | log<level::ERR>("Unable to get inventory manager service"); |
| 932 | return; |
| 933 | } |
| 934 | |
| 935 | auto method = |
| 936 | bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 937 | INVENTORY_MGR_IFACE, "Notify"); |
| 938 | |
| 939 | method.append(std::move(object)); |
| 940 | |
| 941 | auto reply = bus.call(method); |
| 942 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 943 | catch (const std::exception& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 944 | { |
Jay Meyer | 6a3fd2c | 2020-08-25 16:37:16 -0500 | [diff] [blame] | 945 | log<level::ERR>( |
| 946 | std::string(e.what() + std::string(" PATH=") + inventoryPath) |
| 947 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 948 | } |
| 949 | #endif |
| 950 | } |
| 951 | } |
| 952 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 953 | void PowerSupply::getInputVoltage(double& actualInputVoltage, |
| 954 | int& inputVoltage) const |
| 955 | { |
| 956 | using namespace phosphor::pmbus; |
| 957 | |
| 958 | actualInputVoltage = in_input::VIN_VOLTAGE_0; |
| 959 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 960 | |
| 961 | if (present) |
| 962 | { |
| 963 | try |
| 964 | { |
| 965 | // Read input voltage in millivolts |
| 966 | auto inputVoltageStr = pmbusIntf->readString(READ_VIN, Type::Hwmon); |
| 967 | |
| 968 | // Convert to volts |
| 969 | actualInputVoltage = std::stod(inputVoltageStr) / 1000; |
| 970 | |
| 971 | // Calculate the voltage based on voltage thresholds |
| 972 | if (actualInputVoltage < in_input::VIN_VOLTAGE_MIN) |
| 973 | { |
| 974 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 975 | } |
| 976 | else if (actualInputVoltage < in_input::VIN_VOLTAGE_110_THRESHOLD) |
| 977 | { |
| 978 | inputVoltage = in_input::VIN_VOLTAGE_110; |
| 979 | } |
| 980 | else |
| 981 | { |
| 982 | inputVoltage = in_input::VIN_VOLTAGE_220; |
| 983 | } |
| 984 | } |
| 985 | catch (const std::exception& e) |
| 986 | { |
| 987 | log<level::ERR>( |
Brandon Wyman | 321a615 | 2022-03-19 00:11:44 +0000 | [diff] [blame] | 988 | fmt::format("{} READ_VIN read error: {}", shortName, e.what()) |
| 989 | .c_str()); |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 994 | void PowerSupply::checkAvailability() |
| 995 | { |
| 996 | bool origAvailability = available; |
| 997 | available = present && !hasInputFault() && !hasVINUVFault() && |
| 998 | !hasPSKillFault() && !hasIoutOCFault(); |
| 999 | |
| 1000 | if (origAvailability != available) |
| 1001 | { |
| 1002 | auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 1003 | phosphor::power::psu::setAvailable(bus, invpath, available); |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 1004 | |
| 1005 | // Check if the health rollup needs to change based on the |
| 1006 | // new availability value. |
| 1007 | phosphor::power::psu::handleChassisHealthRollup(bus, inventoryPath, |
| 1008 | !available); |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1012 | } // namespace phosphor::power::psu |