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 | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 12 | #include <chrono> // sleep_for() |
| 13 | #include <cstdint> // uint8_t... |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 14 | #include <fstream> |
| 15 | #include <thread> // sleep_for() |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 16 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 17 | namespace phosphor::power::psu |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 18 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 19 | // Amount of time in milliseconds to delay between power supply going from |
| 20 | // missing to present before running the bind command(s). |
| 21 | constexpr auto bindDelay = 1000; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 22 | |
| 23 | using namespace phosphor::logging; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 24 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 25 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 26 | PowerSupply::PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath, |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 27 | std::uint8_t i2cbus, std::uint16_t i2caddr, |
| 28 | const std::string& gpioLineName) : |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 29 | bus(bus), |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 30 | inventoryPath(invpath), bindPath("/sys/bus/i2c/drivers/ibm-cffps") |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 31 | { |
| 32 | if (inventoryPath.empty()) |
| 33 | { |
| 34 | throw std::invalid_argument{"Invalid empty inventoryPath"}; |
| 35 | } |
| 36 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 37 | if (gpioLineName.empty()) |
| 38 | { |
| 39 | throw std::invalid_argument{"Invalid empty gpioLineName"}; |
| 40 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 41 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 42 | log<level::DEBUG>(fmt::format("gpioLineName: {}", gpioLineName).c_str()); |
| 43 | presenceGPIO = createGPIO(gpioLineName); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 44 | |
| 45 | std::ostringstream ss; |
| 46 | ss << std::hex << std::setw(4) << std::setfill('0') << i2caddr; |
| 47 | std::string addrStr = ss.str(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 48 | std::string busStr = std::to_string(i2cbus); |
| 49 | bindDevice = busStr; |
| 50 | bindDevice.append("-"); |
| 51 | bindDevice.append(addrStr); |
| 52 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 53 | pmbusIntf = phosphor::pmbus::createPMBus(i2cbus, addrStr); |
| 54 | |
| 55 | // Get the current state of the Present property. |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 56 | try |
| 57 | { |
| 58 | updatePresenceGPIO(); |
| 59 | } |
| 60 | catch (...) |
| 61 | { |
| 62 | // If the above attempt to use the GPIO failed, it likely means that the |
| 63 | // GPIOs are in use by the kernel, meaning it is using gpio-keys. |
| 64 | // So, I should rely on phosphor-gpio-presence to update D-Bus, and |
| 65 | // work that way for power supply presence. |
| 66 | presenceGPIO = nullptr; |
| 67 | // Setup the functions to call when the D-Bus inventory path for the |
| 68 | // Present property changes. |
| 69 | presentMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 70 | bus, |
| 71 | sdbusplus::bus::match::rules::propertiesChanged(inventoryPath, |
| 72 | INVENTORY_IFACE), |
| 73 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 74 | |
| 75 | presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 76 | bus, |
| 77 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 78 | sdbusplus::bus::match::rules::argNpath(0, inventoryPath), |
| 79 | [this](auto& msg) { this->inventoryAdded(msg); }); |
| 80 | |
| 81 | updatePresence(); |
| 82 | updateInventory(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void PowerSupply::bindOrUnbindDriver(bool present) |
| 87 | { |
| 88 | auto action = (present) ? "bind" : "unbind"; |
| 89 | auto path = bindPath / action; |
| 90 | |
| 91 | if (present) |
| 92 | { |
| 93 | log<level::INFO>( |
| 94 | fmt::format("Binding device driver. path: {} device: {}", |
| 95 | path.string(), bindDevice) |
| 96 | .c_str()); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | log<level::INFO>( |
| 101 | fmt::format("Unbinding device driver. path: {} device: {}", |
| 102 | path.string(), bindDevice) |
| 103 | .c_str()); |
| 104 | } |
| 105 | |
| 106 | std::ofstream file; |
| 107 | |
| 108 | file.exceptions(std::ofstream::failbit | std::ofstream::badbit | |
| 109 | std::ofstream::eofbit); |
| 110 | |
| 111 | try |
| 112 | { |
| 113 | file.open(path); |
| 114 | file << bindDevice; |
| 115 | file.close(); |
| 116 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 117 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 118 | { |
| 119 | auto err = errno; |
| 120 | |
| 121 | log<level::ERR>( |
| 122 | fmt::format("Failed binding or unbinding device. errno={}", err) |
| 123 | .c_str()); |
| 124 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 127 | void PowerSupply::updatePresence() |
| 128 | { |
| 129 | try |
| 130 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 131 | present = getPresence(bus, inventoryPath); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 132 | } |
Patrick Williams | 69f10ad | 2021-09-02 09:46:49 -0500 | [diff] [blame] | 133 | catch (const sdbusplus::exception::exception& e) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 134 | { |
| 135 | // Relying on property change or interface added to retry. |
| 136 | // Log an informational trace to the journal. |
Brandon Wyman | df13c3a | 2020-12-15 14:25:22 -0600 | [diff] [blame] | 137 | log<level::INFO>( |
| 138 | fmt::format("D-Bus property {} access failure exception", |
| 139 | inventoryPath) |
| 140 | .c_str()); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 144 | void PowerSupply::updatePresenceGPIO() |
| 145 | { |
| 146 | bool presentOld = present; |
| 147 | |
| 148 | try |
| 149 | { |
| 150 | if (presenceGPIO->read() > 0) |
| 151 | { |
| 152 | present = true; |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | present = false; |
| 157 | } |
| 158 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 159 | catch (const std::exception& e) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 160 | { |
| 161 | log<level::ERR>( |
| 162 | fmt::format("presenceGPIO read fail: {}", e.what()).c_str()); |
| 163 | throw; |
| 164 | } |
| 165 | |
| 166 | if (presentOld != present) |
| 167 | { |
| 168 | log<level::DEBUG>( |
| 169 | fmt::format("presentOld: {} present: {}", presentOld, present) |
| 170 | .c_str()); |
| 171 | if (present) |
| 172 | { |
| 173 | std::this_thread::sleep_for(std::chrono::milliseconds(bindDelay)); |
| 174 | bindOrUnbindDriver(present); |
| 175 | pmbusIntf->findHwmonDir(); |
| 176 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
| 177 | clearFaults(); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | bindOrUnbindDriver(present); |
| 182 | } |
| 183 | |
| 184 | auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 185 | auto const lastSlashPos = invpath.find_last_of('/'); |
| 186 | std::string prettyName = invpath.substr(lastSlashPos + 1); |
| 187 | setPresence(bus, invpath, present, prettyName); |
| 188 | updateInventory(); |
| 189 | } |
| 190 | } |
| 191 | |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 192 | void PowerSupply::determineMFRFault() |
| 193 | { |
| 194 | if (bindPath.string().find("ibm-cffps") != std::string::npos) |
| 195 | { |
| 196 | // IBM MFR_SPECIFIC[4] is PS_Kill fault |
| 197 | if (statusMFR & 0x10) |
| 198 | { |
| 199 | psKillFault = true; |
| 200 | } |
| 201 | // IBM MFR_SPECIFIC[6] is 12Vcs fault. |
| 202 | if (statusMFR & 0x40) |
| 203 | { |
| 204 | ps12VcsFault = true; |
| 205 | } |
| 206 | // IBM MFR_SPECIFIC[7] is 12V Current-Share fault. |
| 207 | if (statusMFR & 0x80) |
| 208 | { |
| 209 | psCS12VFault = true; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 214 | void PowerSupply::analyze() |
| 215 | { |
| 216 | using namespace phosphor::pmbus; |
| 217 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 218 | if (presenceGPIO) |
| 219 | { |
| 220 | updatePresenceGPIO(); |
| 221 | } |
| 222 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 223 | if ((present) && (readFail < LOG_LIMIT)) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 224 | { |
| 225 | try |
| 226 | { |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 227 | statusWord = pmbusIntf->read(STATUS_WORD, Type::Debug); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 228 | // Read worked, reset the fail count. |
| 229 | readFail = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 230 | |
| 231 | if (statusWord) |
| 232 | { |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 233 | statusInput = pmbusIntf->read(STATUS_INPUT, Type::Debug); |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 234 | statusMFR = pmbusIntf->read(STATUS_MFR, Type::Debug); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 235 | statusCML = pmbusIntf->read(STATUS_CML, Type::Debug); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 236 | auto status0Vout = pmbusIntf->insertPageNum(STATUS_VOUT, 0); |
| 237 | statusVout = pmbusIntf->read(status0Vout, Type::Debug); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 238 | statusIout = pmbusIntf->read(STATUS_IOUT, Type::Debug); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 239 | statusFans12 = pmbusIntf->read(STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 240 | statusTemperature = |
| 241 | pmbusIntf->read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 242 | if (statusWord & status_word::CML_FAULT) |
| 243 | { |
| 244 | if (!cmlFault) |
| 245 | { |
Brandon Wyman | 43d3263 | 2021-10-26 23:44:11 +0000 | [diff] [blame] | 246 | log<level::ERR>( |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 247 | fmt::format("CML fault: STATUS_WORD = {:#04x}, " |
| 248 | "STATUS_CML = {:#02x}", |
| 249 | statusWord, statusCML) |
| 250 | .c_str()); |
| 251 | } |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 252 | |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 253 | cmlFault = true; |
| 254 | } |
| 255 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 256 | if (statusWord & status_word::INPUT_FAULT_WARN) |
| 257 | { |
| 258 | if (!inputFault) |
| 259 | { |
Brandon Wyman | 43d3263 | 2021-10-26 23:44:11 +0000 | [diff] [blame] | 260 | log<level::ERR>( |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 261 | fmt::format("INPUT fault: STATUS_WORD = {:#04x}, " |
| 262 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 263 | "STATUS_INPUT = {:#02x}", |
| 264 | statusWord, statusMFR, statusInput) |
Brandon Wyman | c899660 | 2021-10-12 19:28:56 +0000 | [diff] [blame] | 265 | .c_str()); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 266 | } |
| 267 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 268 | inputFault = true; |
| 269 | } |
| 270 | |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 271 | if (statusWord & status_word::VOUT_OV_FAULT) |
| 272 | { |
| 273 | if (!voutOVFault) |
| 274 | { |
Brandon Wyman | 43d3263 | 2021-10-26 23:44:11 +0000 | [diff] [blame] | 275 | log<level::ERR>( |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 276 | fmt::format( |
| 277 | "VOUT_OV_FAULT fault: STATUS_WORD = {:#04x}, " |
| 278 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 279 | "STATUS_VOUT = {:#02x}", |
| 280 | statusWord, statusMFR, statusVout) |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 281 | .c_str()); |
| 282 | } |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 283 | |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 284 | voutOVFault = true; |
| 285 | } |
| 286 | |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 287 | if (statusWord & status_word::IOUT_OC_FAULT) |
| 288 | { |
| 289 | if (!ioutOCFault) |
| 290 | { |
| 291 | log<level::ERR>( |
| 292 | fmt::format("IOUT fault: STATUS_WORD = {:#04x}, " |
| 293 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 294 | "STATUS_IOUT = {:#02x}", |
| 295 | statusWord, statusMFR, statusIout) |
| 296 | .c_str()); |
| 297 | } |
| 298 | |
| 299 | ioutOCFault = true; |
| 300 | } |
| 301 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 302 | if ((statusWord & status_word::VOUT_FAULT) && |
| 303 | !(statusWord & status_word::VOUT_OV_FAULT)) |
| 304 | { |
| 305 | if (!voutUVFault) |
| 306 | { |
| 307 | log<level::ERR>( |
| 308 | fmt::format( |
| 309 | "VOUT_UV_FAULT fault: STATUS_WORD = {:#04x}, " |
| 310 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 311 | "STATUS_VOUT = {:#02x}", |
| 312 | statusWord, statusMFR, statusVout) |
| 313 | .c_str()); |
| 314 | } |
| 315 | |
| 316 | voutUVFault = true; |
| 317 | } |
| 318 | |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 319 | if (statusWord & status_word::FAN_FAULT) |
| 320 | { |
| 321 | if (!fanFault) |
| 322 | { |
| 323 | log<level::ERR>( |
| 324 | fmt::format("FANS fault/warning: " |
| 325 | "STATUS_WORD = {:#04x}, " |
| 326 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 327 | "STATUS_FANS_1_2 = {:#02x}", |
| 328 | statusWord, statusMFR, statusFans12) |
| 329 | .c_str()); |
| 330 | } |
| 331 | |
| 332 | fanFault = true; |
| 333 | } |
| 334 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 335 | if (statusWord & status_word::TEMPERATURE_FAULT_WARN) |
| 336 | { |
| 337 | if (!tempFault) |
| 338 | { |
| 339 | log<level::ERR>( |
| 340 | fmt::format("TEMPERATURE fault/warning: " |
| 341 | "STATUS_WORD = {:#04x}, " |
| 342 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 343 | "STATUS_TEMPERATURE = {:#02x}", |
| 344 | statusWord, statusMFR, |
| 345 | statusTemperature) |
| 346 | .c_str()); |
| 347 | } |
| 348 | |
| 349 | tempFault = true; |
| 350 | } |
| 351 | |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 352 | if ((statusWord & status_word::POWER_GOOD_NEGATED) || |
| 353 | (statusWord & status_word::UNIT_IS_OFF)) |
| 354 | { |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 355 | if (pgoodFault < DEGLITCH_LIMIT) |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 356 | { |
| 357 | log<level::ERR>( |
| 358 | fmt::format("PGOOD fault: " |
| 359 | "STATUS_WORD = {:#04x}, " |
| 360 | "STATUS_MFR_SPECIFIC = {:#02x}", |
| 361 | statusWord, statusMFR) |
| 362 | .c_str()); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 363 | |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 364 | pgoodFault++; |
| 365 | } |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | pgoodFault = 0; |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 372 | if (statusWord & status_word::MFR_SPECIFIC_FAULT) |
| 373 | { |
| 374 | if (!mfrFault) |
| 375 | { |
Brandon Wyman | c899660 | 2021-10-12 19:28:56 +0000 | [diff] [blame] | 376 | log<level::ERR>( |
| 377 | fmt::format("MFR fault: " |
| 378 | "STATUS_WORD = {:#04x} " |
| 379 | "STATUS_MFR_SPECIFIC = {:#02x}", |
| 380 | statusWord, statusMFR) |
| 381 | .c_str()); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 382 | } |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 383 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 384 | mfrFault = true; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 385 | determineMFRFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (statusWord & status_word::VIN_UV_FAULT) |
| 389 | { |
| 390 | if (!vinUVFault) |
| 391 | { |
Brandon Wyman | 43d3263 | 2021-10-26 23:44:11 +0000 | [diff] [blame] | 392 | log<level::ERR>( |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 393 | fmt::format("VIN_UV fault: STATUS_WORD = {:#04x}, " |
| 394 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 395 | "STATUS_INPUT = {:#02x}", |
| 396 | statusWord, statusMFR, statusInput) |
Brandon Wyman | c899660 | 2021-10-12 19:28:56 +0000 | [diff] [blame] | 397 | .c_str()); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 398 | } |
| 399 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 400 | vinUVFault = true; |
| 401 | } |
| 402 | } |
| 403 | else |
| 404 | { |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 405 | cmlFault = false; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 406 | inputFault = false; |
| 407 | mfrFault = false; |
| 408 | vinUVFault = false; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 409 | voutOVFault = false; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 410 | ioutOCFault = false; |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 411 | voutUVFault = false; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 412 | fanFault = false; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 413 | tempFault = false; |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 414 | if (pgoodFault > 0) |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 415 | { |
| 416 | log<level::INFO>(fmt::format("pgoodFault cleared path: {}", |
| 417 | inventoryPath) |
| 418 | .c_str()); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 419 | pgoodFault = 0; |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 420 | } |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 421 | psKillFault = false; |
| 422 | ps12VcsFault = false; |
| 423 | psCS12VFault = false; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 424 | } |
| 425 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 426 | catch (const ReadFailure& e) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 427 | { |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 428 | readFail++; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 429 | phosphor::logging::commit<ReadFailure>(); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 434 | void PowerSupply::onOffConfig(uint8_t data) |
| 435 | { |
| 436 | using namespace phosphor::pmbus; |
| 437 | |
| 438 | if (present) |
| 439 | { |
| 440 | log<level::INFO>("ON_OFF_CONFIG write", entry("DATA=0x%02X", data)); |
| 441 | try |
| 442 | { |
| 443 | std::vector<uint8_t> configData{data}; |
| 444 | pmbusIntf->writeBinary(ON_OFF_CONFIG, configData, |
| 445 | Type::HwmonDeviceDebug); |
| 446 | } |
| 447 | catch (...) |
| 448 | { |
| 449 | // The underlying code in writeBinary will log a message to the |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 450 | // journal if the write fails. If the ON_OFF_CONFIG is not setup |
| 451 | // as desired, later fault detection and analysis code should |
| 452 | // catch any of the fall out. We should not need to terminate |
| 453 | // the application if this write fails. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 458 | void PowerSupply::clearFaults() |
| 459 | { |
Brandon Wyman | 5474c91 | 2021-02-23 14:39:43 -0600 | [diff] [blame] | 460 | faultLogged = false; |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 461 | // The PMBus device driver does not allow for writing CLEAR_FAULTS |
| 462 | // directly. However, the pmbus hwmon device driver code will send a |
| 463 | // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so |
| 464 | // reading in1_input should result in clearing the fault bits in |
| 465 | // STATUS_BYTE/STATUS_WORD. |
| 466 | // I do not care what the return value is. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 467 | if (present) |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 468 | { |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 469 | inputFault = false; |
| 470 | mfrFault = false; |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 471 | statusMFR = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 472 | vinUVFault = false; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 473 | cmlFault = false; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 474 | voutOVFault = false; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 475 | ioutOCFault = false; |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 476 | voutUVFault = false; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 477 | fanFault = false; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 478 | tempFault = false; |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 479 | pgoodFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 480 | psKillFault = false; |
| 481 | ps12VcsFault = false; |
| 482 | psCS12VFault = false; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 483 | readFail = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 484 | |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 485 | try |
| 486 | { |
| 487 | static_cast<void>( |
| 488 | pmbusIntf->read("in1_input", phosphor::pmbus::Type::Hwmon)); |
| 489 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 490 | catch (const ReadFailure& e) |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 491 | { |
| 492 | // 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] | 493 | // care much if it gets a ReadFailure either. However, this |
| 494 | // should not prevent the application from continuing to run, so |
| 495 | // catching the read failure. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 496 | } |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 500 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 501 | { |
| 502 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 503 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 504 | msg.read(msgSensor, msgData); |
| 505 | |
| 506 | // Check if it was the Present property that changed. |
| 507 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 508 | if (valPropMap != msgData.end()) |
| 509 | { |
| 510 | if (std::get<bool>(valPropMap->second)) |
| 511 | { |
| 512 | present = true; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 513 | // TODO: Immediately trying to read or write the "files" causes |
| 514 | // read or write failures. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 515 | using namespace std::chrono_literals; |
| 516 | std::this_thread::sleep_for(20ms); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 517 | pmbusIntf->findHwmonDir(); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 518 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 519 | clearFaults(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 520 | updateInventory(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 521 | } |
| 522 | else |
| 523 | { |
| 524 | present = false; |
| 525 | |
| 526 | // Clear out the now outdated inventory properties |
| 527 | updateInventory(); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 532 | void PowerSupply::inventoryAdded(sdbusplus::message::message& msg) |
| 533 | { |
| 534 | sdbusplus::message::object_path path; |
| 535 | msg.read(path); |
| 536 | // Make sure the signal is for the PSU inventory path |
| 537 | if (path == inventoryPath) |
| 538 | { |
| 539 | std::map<std::string, std::map<std::string, std::variant<bool>>> |
| 540 | interfaces; |
| 541 | // Get map of interfaces and their properties |
| 542 | msg.read(interfaces); |
| 543 | |
| 544 | auto properties = interfaces.find(INVENTORY_IFACE); |
| 545 | if (properties != interfaces.end()) |
| 546 | { |
| 547 | auto property = properties->second.find(PRESENT_PROP); |
| 548 | if (property != properties->second.end()) |
| 549 | { |
| 550 | present = std::get<bool>(property->second); |
| 551 | |
| 552 | log<level::INFO>(fmt::format("Power Supply {} Present {}", |
| 553 | inventoryPath, present) |
| 554 | .c_str()); |
| 555 | |
| 556 | updateInventory(); |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 562 | void PowerSupply::updateInventory() |
| 563 | { |
| 564 | using namespace phosphor::pmbus; |
| 565 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 566 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 567 | std::string ccin; |
| 568 | std::string pn; |
| 569 | std::string fn; |
| 570 | std::string header; |
| 571 | std::string sn; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 572 | using PropertyMap = |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 573 | std::map<std::string, |
| 574 | std::variant<std::string, std::vector<uint8_t>, bool>>; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 575 | PropertyMap assetProps; |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 576 | PropertyMap operProps; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 577 | PropertyMap versionProps; |
| 578 | PropertyMap ipzvpdDINFProps; |
| 579 | PropertyMap ipzvpdVINIProps; |
| 580 | using InterfaceMap = std::map<std::string, PropertyMap>; |
| 581 | InterfaceMap interfaces; |
| 582 | using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>; |
| 583 | ObjectMap object; |
| 584 | #endif |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 585 | log<level::DEBUG>( |
| 586 | fmt::format("updateInventory() inventoryPath: {}", inventoryPath) |
| 587 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 588 | |
| 589 | if (present) |
| 590 | { |
| 591 | // TODO: non-IBM inventory updates? |
| 592 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 593 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 594 | try |
| 595 | { |
| 596 | ccin = pmbusIntf->readString(CCIN, Type::HwmonDeviceDebug); |
| 597 | assetProps.emplace(MODEL_PROP, ccin); |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 598 | modelName = ccin; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 599 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 600 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 601 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 602 | // Ignore the read failure, let pmbus code indicate failure, |
| 603 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 604 | // TODO - ibm918 |
| 605 | // https://github.com/openbmc/docs/blob/master/designs/vpd-collection.md |
| 606 | // The BMC must log errors if any of the VPD cannot be properly |
| 607 | // parsed or fails ECC checks. |
| 608 | } |
| 609 | |
| 610 | try |
| 611 | { |
| 612 | pn = pmbusIntf->readString(PART_NUMBER, Type::HwmonDeviceDebug); |
| 613 | assetProps.emplace(PN_PROP, pn); |
| 614 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 615 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 616 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 617 | // Ignore the read failure, let pmbus code indicate failure, |
| 618 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | try |
| 622 | { |
| 623 | fn = pmbusIntf->readString(FRU_NUMBER, Type::HwmonDeviceDebug); |
Brandon Wyman | a169b0f | 2021-12-07 20:18:06 +0000 | [diff] [blame] | 624 | assetProps.emplace(SPARE_PN_PROP, fn); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 625 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 626 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 627 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 628 | // Ignore the read failure, let pmbus code indicate failure, |
| 629 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | try |
| 633 | { |
| 634 | header = |
| 635 | pmbusIntf->readString(SERIAL_HEADER, Type::HwmonDeviceDebug); |
| 636 | sn = pmbusIntf->readString(SERIAL_NUMBER, Type::HwmonDeviceDebug); |
| 637 | assetProps.emplace(SN_PROP, sn); |
| 638 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 639 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 640 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 641 | // Ignore the read failure, let pmbus code indicate failure, |
| 642 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | try |
| 646 | { |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 647 | fwVersion = |
| 648 | pmbusIntf->readString(FW_VERSION, Type::HwmonDeviceDebug); |
| 649 | versionProps.emplace(VERSION_PROP, fwVersion); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 650 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 651 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 652 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 653 | // Ignore the read failure, let pmbus code indicate failure, |
| 654 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | ipzvpdVINIProps.emplace("CC", |
| 658 | std::vector<uint8_t>(ccin.begin(), ccin.end())); |
| 659 | ipzvpdVINIProps.emplace("PN", |
| 660 | std::vector<uint8_t>(pn.begin(), pn.end())); |
| 661 | ipzvpdVINIProps.emplace("FN", |
| 662 | std::vector<uint8_t>(fn.begin(), fn.end())); |
| 663 | std::string header_sn = header + sn + '\0'; |
| 664 | ipzvpdVINIProps.emplace( |
| 665 | "SN", std::vector<uint8_t>(header_sn.begin(), header_sn.end())); |
| 666 | std::string description = "IBM PS"; |
| 667 | ipzvpdVINIProps.emplace( |
| 668 | "DR", std::vector<uint8_t>(description.begin(), description.end())); |
| 669 | |
| 670 | // Update the Resource Identifier (RI) keyword |
| 671 | // 2 byte FRC: 0x0003 |
| 672 | // 2 byte RID: 0x1000, 0x1001... |
| 673 | std::uint8_t num = std::stoul( |
| 674 | inventoryPath.substr(inventoryPath.size() - 1, 1), nullptr, 0); |
| 675 | std::vector<uint8_t> ri{0x00, 0x03, 0x10, num}; |
| 676 | ipzvpdDINFProps.emplace("RI", ri); |
| 677 | |
| 678 | // Fill in the FRU Label (FL) keyword. |
| 679 | std::string fl = "E"; |
| 680 | fl.push_back(inventoryPath.back()); |
| 681 | fl.resize(FL_KW_SIZE, ' '); |
| 682 | ipzvpdDINFProps.emplace("FL", |
| 683 | std::vector<uint8_t>(fl.begin(), fl.end())); |
| 684 | |
| 685 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
| 686 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 687 | interfaces.emplace(DINF_IFACE, std::move(ipzvpdDINFProps)); |
| 688 | interfaces.emplace(VINI_IFACE, std::move(ipzvpdVINIProps)); |
| 689 | |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 690 | // Update the Functional |
| 691 | operProps.emplace(FUNCTIONAL_PROP, present); |
| 692 | interfaces.emplace(OPERATIONAL_STATE_IFACE, std::move(operProps)); |
| 693 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 694 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 695 | object.emplace(path, std::move(interfaces)); |
| 696 | |
| 697 | try |
| 698 | { |
| 699 | auto service = |
| 700 | util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus); |
| 701 | |
| 702 | if (service.empty()) |
| 703 | { |
| 704 | log<level::ERR>("Unable to get inventory manager service"); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | auto method = |
| 709 | bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 710 | INVENTORY_MGR_IFACE, "Notify"); |
| 711 | |
| 712 | method.append(std::move(object)); |
| 713 | |
| 714 | auto reply = bus.call(method); |
| 715 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 716 | catch (const std::exception& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 717 | { |
Jay Meyer | 6a3fd2c | 2020-08-25 16:37:16 -0500 | [diff] [blame] | 718 | log<level::ERR>( |
| 719 | std::string(e.what() + std::string(" PATH=") + inventoryPath) |
| 720 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 721 | } |
| 722 | #endif |
| 723 | } |
| 724 | } |
| 725 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 726 | void PowerSupply::getInputVoltage(double& actualInputVoltage, |
| 727 | int& inputVoltage) const |
| 728 | { |
| 729 | using namespace phosphor::pmbus; |
| 730 | |
| 731 | actualInputVoltage = in_input::VIN_VOLTAGE_0; |
| 732 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 733 | |
| 734 | if (present) |
| 735 | { |
| 736 | try |
| 737 | { |
| 738 | // Read input voltage in millivolts |
| 739 | auto inputVoltageStr = pmbusIntf->readString(READ_VIN, Type::Hwmon); |
| 740 | |
| 741 | // Convert to volts |
| 742 | actualInputVoltage = std::stod(inputVoltageStr) / 1000; |
| 743 | |
| 744 | // Calculate the voltage based on voltage thresholds |
| 745 | if (actualInputVoltage < in_input::VIN_VOLTAGE_MIN) |
| 746 | { |
| 747 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 748 | } |
| 749 | else if (actualInputVoltage < in_input::VIN_VOLTAGE_110_THRESHOLD) |
| 750 | { |
| 751 | inputVoltage = in_input::VIN_VOLTAGE_110; |
| 752 | } |
| 753 | else |
| 754 | { |
| 755 | inputVoltage = in_input::VIN_VOLTAGE_220; |
| 756 | } |
| 757 | } |
| 758 | catch (const std::exception& e) |
| 759 | { |
| 760 | log<level::ERR>( |
| 761 | fmt::format("READ_VIN read error: {}", e.what()).c_str()); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 766 | } // namespace phosphor::power::psu |