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 | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 192 | void PowerSupply::analyzeCMLFault() |
| 193 | { |
| 194 | if (statusWord & phosphor::pmbus::status_word::CML_FAULT) |
| 195 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 196 | if (cmlFault < DEGLITCH_LIMIT) |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 197 | { |
| 198 | log<level::ERR>(fmt::format("CML fault: STATUS_WORD = {:#04x}, " |
| 199 | "STATUS_CML = {:#02x}", |
| 200 | statusWord, statusCML) |
| 201 | .c_str()); |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 202 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 203 | cmlFault++; |
| 204 | } |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | cmlFault = 0; |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 212 | void PowerSupply::analyzeInputFault() |
| 213 | { |
| 214 | if (statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN) |
| 215 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 216 | if (inputFault < DEGLITCH_LIMIT) |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 217 | { |
| 218 | log<level::ERR>(fmt::format("INPUT fault: STATUS_WORD = {:#04x}, " |
| 219 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 220 | "STATUS_INPUT = {:#02x}", |
| 221 | statusWord, statusMFR, statusInput) |
| 222 | .c_str()); |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 223 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 224 | inputFault++; |
| 225 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 226 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 227 | |
| 228 | // If had INPUT/VIN_UV fault, and now off. |
| 229 | // Trace that odd behavior. |
| 230 | if (inputFault && |
| 231 | !(statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN)) |
| 232 | { |
| 233 | log<level::INFO>( |
| 234 | fmt::format("INPUT fault cleared: STATUS_WORD = {:#04x}, " |
| 235 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 236 | "STATUS_INPUT = {:#02x}", |
| 237 | statusWord, statusMFR, statusInput) |
| 238 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 239 | inputFault = 0; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 240 | } |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 243 | void PowerSupply::analyzeVoutOVFault() |
| 244 | { |
| 245 | if (statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT) |
| 246 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 247 | if (voutOVFault < DEGLITCH_LIMIT) |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 248 | { |
| 249 | log<level::ERR>( |
| 250 | fmt::format("VOUT_OV_FAULT fault: STATUS_WORD = {:#04x}, " |
| 251 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 252 | "STATUS_VOUT = {:#02x}", |
| 253 | statusWord, statusMFR, statusVout) |
| 254 | .c_str()); |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 255 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 256 | voutOVFault++; |
| 257 | } |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | voutOVFault = 0; |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 265 | void PowerSupply::analyzeIoutOCFault() |
| 266 | { |
| 267 | if (statusWord & phosphor::pmbus::status_word::IOUT_OC_FAULT) |
| 268 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 269 | if (ioutOCFault < DEGLITCH_LIMIT) |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 270 | { |
| 271 | log<level::ERR>(fmt::format("IOUT fault: STATUS_WORD = {:#04x}, " |
| 272 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 273 | "STATUS_IOUT = {:#02x}", |
| 274 | statusWord, statusMFR, statusIout) |
| 275 | .c_str()); |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 276 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 277 | ioutOCFault++; |
| 278 | } |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | ioutOCFault = 0; |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 286 | void PowerSupply::analyzeVoutUVFault() |
| 287 | { |
| 288 | if ((statusWord & phosphor::pmbus::status_word::VOUT_FAULT) && |
| 289 | !(statusWord & phosphor::pmbus::status_word::VOUT_OV_FAULT)) |
| 290 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 291 | if (voutUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 292 | { |
| 293 | log<level::ERR>( |
| 294 | fmt::format("VOUT_UV_FAULT fault: STATUS_WORD = {:#04x}, " |
| 295 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 296 | "STATUS_VOUT = {:#02x}", |
| 297 | statusWord, statusMFR, statusVout) |
| 298 | .c_str()); |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 299 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 300 | voutUVFault++; |
| 301 | } |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | voutUVFault = 0; |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 309 | void PowerSupply::analyzeFanFault() |
| 310 | { |
| 311 | if (statusWord & phosphor::pmbus::status_word::FAN_FAULT) |
| 312 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 313 | if (fanFault < DEGLITCH_LIMIT) |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 314 | { |
| 315 | log<level::ERR>(fmt::format("FANS fault/warning: " |
| 316 | "STATUS_WORD = {:#04x}, " |
| 317 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 318 | "STATUS_FANS_1_2 = {:#02x}", |
| 319 | statusWord, statusMFR, statusFans12) |
| 320 | .c_str()); |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 321 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 322 | fanFault++; |
| 323 | } |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | fanFault = 0; |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 331 | void PowerSupply::analyzeTemperatureFault() |
| 332 | { |
| 333 | if (statusWord & phosphor::pmbus::status_word::TEMPERATURE_FAULT_WARN) |
| 334 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 335 | if (tempFault < DEGLITCH_LIMIT) |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 336 | { |
| 337 | log<level::ERR>(fmt::format("TEMPERATURE fault/warning: " |
| 338 | "STATUS_WORD = {:#04x}, " |
| 339 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 340 | "STATUS_TEMPERATURE = {:#02x}", |
| 341 | statusWord, statusMFR, |
| 342 | statusTemperature) |
| 343 | .c_str()); |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 344 | |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 345 | tempFault++; |
| 346 | } |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | tempFault = 0; |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 354 | void PowerSupply::analyzePgoodFault() |
| 355 | { |
| 356 | if ((statusWord & phosphor::pmbus::status_word::POWER_GOOD_NEGATED) || |
| 357 | (statusWord & phosphor::pmbus::status_word::UNIT_IS_OFF)) |
| 358 | { |
| 359 | if (pgoodFault < DEGLITCH_LIMIT) |
| 360 | { |
| 361 | log<level::ERR>(fmt::format("PGOOD fault: " |
| 362 | "STATUS_WORD = {:#04x}, " |
| 363 | "STATUS_MFR_SPECIFIC = {:#02x}", |
| 364 | statusWord, statusMFR) |
| 365 | .c_str()); |
| 366 | |
| 367 | pgoodFault++; |
| 368 | } |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | pgoodFault = 0; |
| 373 | } |
| 374 | } |
| 375 | |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 376 | void PowerSupply::determineMFRFault() |
| 377 | { |
| 378 | if (bindPath.string().find("ibm-cffps") != std::string::npos) |
| 379 | { |
| 380 | // IBM MFR_SPECIFIC[4] is PS_Kill fault |
| 381 | if (statusMFR & 0x10) |
| 382 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 383 | if (psKillFault < DEGLITCH_LIMIT) |
| 384 | { |
| 385 | psKillFault++; |
| 386 | } |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | psKillFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 391 | } |
| 392 | // IBM MFR_SPECIFIC[6] is 12Vcs fault. |
| 393 | if (statusMFR & 0x40) |
| 394 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 395 | if (ps12VcsFault < DEGLITCH_LIMIT) |
| 396 | { |
| 397 | ps12VcsFault++; |
| 398 | } |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | ps12VcsFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 403 | } |
| 404 | // IBM MFR_SPECIFIC[7] is 12V Current-Share fault. |
| 405 | if (statusMFR & 0x80) |
| 406 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 407 | if (psCS12VFault < DEGLITCH_LIMIT) |
| 408 | { |
| 409 | psCS12VFault++; |
| 410 | } |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | psCS12VFault = 0; |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 419 | void PowerSupply::analyzeMFRFault() |
| 420 | { |
| 421 | if (statusWord & phosphor::pmbus::status_word::MFR_SPECIFIC_FAULT) |
| 422 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 423 | if (mfrFault < DEGLITCH_LIMIT) |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 424 | { |
| 425 | log<level::ERR>(fmt::format("MFR fault: " |
| 426 | "STATUS_WORD = {:#04x} " |
| 427 | "STATUS_MFR_SPECIFIC = {:#02x}", |
| 428 | statusWord, statusMFR) |
| 429 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 430 | mfrFault++; |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 433 | determineMFRFault(); |
| 434 | } |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 435 | else |
| 436 | { |
| 437 | mfrFault = 0; |
| 438 | } |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 441 | void PowerSupply::analyzeVinUVFault() |
| 442 | { |
| 443 | if (statusWord & phosphor::pmbus::status_word::VIN_UV_FAULT) |
| 444 | { |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 445 | if (vinUVFault < DEGLITCH_LIMIT) |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 446 | { |
| 447 | log<level::ERR>(fmt::format("VIN_UV fault: STATUS_WORD = {:#04x}, " |
| 448 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 449 | "STATUS_INPUT = {:#02x}", |
| 450 | statusWord, statusMFR, statusInput) |
| 451 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 452 | vinUVFault++; |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 453 | } |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 454 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 455 | |
| 456 | if (vinUVFault && |
| 457 | !(statusWord & phosphor::pmbus::status_word::VIN_UV_FAULT)) |
| 458 | { |
| 459 | log<level::INFO>( |
| 460 | fmt::format("VIN_UV fault cleared: STATUS_WORD = {:#04x}, " |
| 461 | "STATUS_MFR_SPECIFIC = {:#02x}, " |
| 462 | "STATUS_INPUT = {:#02x}", |
| 463 | statusWord, statusMFR, statusInput) |
| 464 | .c_str()); |
Brandon Wyman | c2906f4 | 2021-12-21 20:14:56 +0000 | [diff] [blame] | 465 | vinUVFault = 0; |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 466 | } |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 469 | void PowerSupply::analyze() |
| 470 | { |
| 471 | using namespace phosphor::pmbus; |
| 472 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 473 | if (presenceGPIO) |
| 474 | { |
| 475 | updatePresenceGPIO(); |
| 476 | } |
| 477 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 478 | if ((present) && (readFail < LOG_LIMIT)) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 479 | { |
| 480 | try |
| 481 | { |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 482 | statusWord = pmbusIntf->read(STATUS_WORD, Type::Debug); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 483 | // Read worked, reset the fail count. |
| 484 | readFail = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 485 | |
| 486 | if (statusWord) |
| 487 | { |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 488 | statusInput = pmbusIntf->read(STATUS_INPUT, Type::Debug); |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 489 | statusMFR = pmbusIntf->read(STATUS_MFR, Type::Debug); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 490 | statusCML = pmbusIntf->read(STATUS_CML, Type::Debug); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 491 | auto status0Vout = pmbusIntf->insertPageNum(STATUS_VOUT, 0); |
| 492 | statusVout = pmbusIntf->read(status0Vout, Type::Debug); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 493 | statusIout = pmbusIntf->read(STATUS_IOUT, Type::Debug); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 494 | statusFans12 = pmbusIntf->read(STATUS_FANS_1_2, Type::Debug); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 495 | statusTemperature = |
| 496 | pmbusIntf->read(STATUS_TEMPERATURE, Type::Debug); |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 497 | |
Brandon Wyman | c220343 | 2021-12-21 23:09:48 +0000 | [diff] [blame] | 498 | analyzeCMLFault(); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 499 | |
Brandon Wyman | e3b0bb0 | 2021-12-21 23:16:48 +0000 | [diff] [blame] | 500 | analyzeInputFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 501 | |
Brandon Wyman | c2c8713 | 2021-12-21 23:22:18 +0000 | [diff] [blame] | 502 | analyzeVoutOVFault(); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 503 | |
Brandon Wyman | a00e730 | 2021-12-21 23:28:29 +0000 | [diff] [blame] | 504 | analyzeIoutOCFault(); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 505 | |
Brandon Wyman | 0837878 | 2021-12-21 23:48:15 +0000 | [diff] [blame] | 506 | analyzeVoutUVFault(); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 507 | |
Brandon Wyman | d5d9a22 | 2021-12-21 23:59:05 +0000 | [diff] [blame] | 508 | analyzeFanFault(); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 509 | |
Brandon Wyman | 52cb3f2 | 2021-12-21 23:02:47 +0000 | [diff] [blame] | 510 | analyzeTemperatureFault(); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 511 | |
Brandon Wyman | 993b554 | 2021-12-21 22:55:16 +0000 | [diff] [blame] | 512 | analyzePgoodFault(); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 513 | |
Brandon Wyman | 6c2ac39 | 2021-12-21 22:23:06 +0000 | [diff] [blame] | 514 | analyzeMFRFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 515 | |
Brandon Wyman | f087f47 | 2021-12-22 00:04:27 +0000 | [diff] [blame] | 516 | analyzeVinUVFault(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 517 | } |
| 518 | else |
| 519 | { |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 520 | // if INPUT/VIN_UV fault was on, it cleared, trace it. |
| 521 | if (inputFault) |
| 522 | { |
| 523 | log<level::INFO>( |
| 524 | fmt::format( |
| 525 | "INPUT fault cleared: STATUS_WORD = {:#04x}", |
| 526 | statusWord) |
| 527 | .c_str()); |
| 528 | } |
| 529 | |
| 530 | if (vinUVFault) |
| 531 | { |
| 532 | log<level::INFO>( |
| 533 | fmt::format("VIN_UV cleared: STATUS_WORD = {:#04x}", |
| 534 | statusWord) |
| 535 | .c_str()); |
| 536 | } |
| 537 | |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 538 | if (pgoodFault > 0) |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 539 | { |
| 540 | log<level::INFO>(fmt::format("pgoodFault cleared path: {}", |
| 541 | inventoryPath) |
| 542 | .c_str()); |
Brandon Wyman | 4aecc29 | 2021-11-10 22:40:41 +0000 | [diff] [blame] | 543 | } |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 544 | |
| 545 | clearFaultFlags(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 546 | } |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 547 | |
| 548 | // Save off old inputVoltage value. |
| 549 | // Get latest inputVoltage. |
| 550 | // If voltage went from below minimum, and now is not, clear faults. |
| 551 | // Note: getInputVoltage() has its own try/catch. |
| 552 | int inputVoltageOld = inputVoltage; |
| 553 | double actualInputVoltage; |
| 554 | getInputVoltage(actualInputVoltage, inputVoltage); |
| 555 | if ((inputVoltageOld == in_input::VIN_VOLTAGE_0) && |
| 556 | (inputVoltage != in_input::VIN_VOLTAGE_0)) |
| 557 | { |
| 558 | log<level::INFO>( |
| 559 | fmt::format( |
| 560 | "READ_VIN back in range: inputVoltageOld = {} inputVoltage = {}", |
| 561 | inputVoltageOld, inputVoltage) |
| 562 | .c_str()); |
| 563 | clearFaults(); |
| 564 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 565 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 566 | catch (const ReadFailure& e) |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 567 | { |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 568 | readFail++; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 569 | phosphor::logging::commit<ReadFailure>(); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 574 | void PowerSupply::onOffConfig(uint8_t data) |
| 575 | { |
| 576 | using namespace phosphor::pmbus; |
| 577 | |
| 578 | if (present) |
| 579 | { |
| 580 | log<level::INFO>("ON_OFF_CONFIG write", entry("DATA=0x%02X", data)); |
| 581 | try |
| 582 | { |
| 583 | std::vector<uint8_t> configData{data}; |
| 584 | pmbusIntf->writeBinary(ON_OFF_CONFIG, configData, |
| 585 | Type::HwmonDeviceDebug); |
| 586 | } |
| 587 | catch (...) |
| 588 | { |
| 589 | // The underlying code in writeBinary will log a message to the |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 590 | // journal if the write fails. If the ON_OFF_CONFIG is not setup |
| 591 | // as desired, later fault detection and analysis code should |
| 592 | // catch any of the fall out. We should not need to terminate |
| 593 | // the application if this write fails. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 598 | void PowerSupply::clearFaults() |
| 599 | { |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 600 | log<level::DEBUG>( |
| 601 | fmt::format("clearFaults() inventoryPath: {}", inventoryPath).c_str()); |
Brandon Wyman | 5474c91 | 2021-02-23 14:39:43 -0600 | [diff] [blame] | 602 | faultLogged = false; |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 603 | // The PMBus device driver does not allow for writing CLEAR_FAULTS |
| 604 | // directly. However, the pmbus hwmon device driver code will send a |
| 605 | // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so |
| 606 | // reading in1_input should result in clearing the fault bits in |
| 607 | // STATUS_BYTE/STATUS_WORD. |
| 608 | // I do not care what the return value is. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 609 | if (present) |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 610 | { |
Brandon Wyman | e3f7ad2 | 2021-12-21 20:27:45 +0000 | [diff] [blame] | 611 | clearFaultFlags(); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 612 | readFail = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 613 | |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 614 | try |
| 615 | { |
| 616 | static_cast<void>( |
| 617 | pmbusIntf->read("in1_input", phosphor::pmbus::Type::Hwmon)); |
| 618 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 619 | catch (const ReadFailure& e) |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 620 | { |
| 621 | // 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] | 622 | // care much if it gets a ReadFailure either. However, this |
| 623 | // should not prevent the application from continuing to run, so |
| 624 | // catching the read failure. |
Brandon Wyman | 1115153 | 2020-11-10 13:45:57 -0600 | [diff] [blame] | 625 | } |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 629 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 630 | { |
| 631 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 632 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 633 | msg.read(msgSensor, msgData); |
| 634 | |
| 635 | // Check if it was the Present property that changed. |
| 636 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 637 | if (valPropMap != msgData.end()) |
| 638 | { |
| 639 | if (std::get<bool>(valPropMap->second)) |
| 640 | { |
| 641 | present = true; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 642 | // TODO: Immediately trying to read or write the "files" causes |
| 643 | // read or write failures. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 644 | using namespace std::chrono_literals; |
| 645 | std::this_thread::sleep_for(20ms); |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 646 | pmbusIntf->findHwmonDir(); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 647 | onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 648 | clearFaults(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 649 | updateInventory(); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 650 | } |
| 651 | else |
| 652 | { |
| 653 | present = false; |
| 654 | |
| 655 | // Clear out the now outdated inventory properties |
| 656 | updateInventory(); |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 661 | void PowerSupply::inventoryAdded(sdbusplus::message::message& msg) |
| 662 | { |
| 663 | sdbusplus::message::object_path path; |
| 664 | msg.read(path); |
| 665 | // Make sure the signal is for the PSU inventory path |
| 666 | if (path == inventoryPath) |
| 667 | { |
| 668 | std::map<std::string, std::map<std::string, std::variant<bool>>> |
| 669 | interfaces; |
| 670 | // Get map of interfaces and their properties |
| 671 | msg.read(interfaces); |
| 672 | |
| 673 | auto properties = interfaces.find(INVENTORY_IFACE); |
| 674 | if (properties != interfaces.end()) |
| 675 | { |
| 676 | auto property = properties->second.find(PRESENT_PROP); |
| 677 | if (property != properties->second.end()) |
| 678 | { |
| 679 | present = std::get<bool>(property->second); |
| 680 | |
| 681 | log<level::INFO>(fmt::format("Power Supply {} Present {}", |
| 682 | inventoryPath, present) |
| 683 | .c_str()); |
| 684 | |
| 685 | updateInventory(); |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 691 | void PowerSupply::updateInventory() |
| 692 | { |
| 693 | using namespace phosphor::pmbus; |
| 694 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 695 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 696 | std::string ccin; |
| 697 | std::string pn; |
| 698 | std::string fn; |
| 699 | std::string header; |
| 700 | std::string sn; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 701 | using PropertyMap = |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 702 | std::map<std::string, |
| 703 | std::variant<std::string, std::vector<uint8_t>, bool>>; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 704 | PropertyMap assetProps; |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 705 | PropertyMap operProps; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 706 | PropertyMap versionProps; |
| 707 | PropertyMap ipzvpdDINFProps; |
| 708 | PropertyMap ipzvpdVINIProps; |
| 709 | using InterfaceMap = std::map<std::string, PropertyMap>; |
| 710 | InterfaceMap interfaces; |
| 711 | using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>; |
| 712 | ObjectMap object; |
| 713 | #endif |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 714 | log<level::DEBUG>( |
| 715 | fmt::format("updateInventory() inventoryPath: {}", inventoryPath) |
| 716 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 717 | |
| 718 | if (present) |
| 719 | { |
| 720 | // TODO: non-IBM inventory updates? |
| 721 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 722 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 723 | try |
| 724 | { |
| 725 | ccin = pmbusIntf->readString(CCIN, Type::HwmonDeviceDebug); |
| 726 | assetProps.emplace(MODEL_PROP, ccin); |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 727 | modelName = ccin; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 728 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 729 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 730 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 731 | // Ignore the read failure, let pmbus code indicate failure, |
| 732 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 733 | // TODO - ibm918 |
| 734 | // https://github.com/openbmc/docs/blob/master/designs/vpd-collection.md |
| 735 | // The BMC must log errors if any of the VPD cannot be properly |
| 736 | // parsed or fails ECC checks. |
| 737 | } |
| 738 | |
| 739 | try |
| 740 | { |
| 741 | pn = pmbusIntf->readString(PART_NUMBER, Type::HwmonDeviceDebug); |
| 742 | assetProps.emplace(PN_PROP, pn); |
| 743 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 744 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 745 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 746 | // Ignore the read failure, let pmbus code indicate failure, |
| 747 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | try |
| 751 | { |
| 752 | fn = pmbusIntf->readString(FRU_NUMBER, Type::HwmonDeviceDebug); |
Brandon Wyman | a169b0f | 2021-12-07 20:18:06 +0000 | [diff] [blame] | 753 | assetProps.emplace(SPARE_PN_PROP, fn); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 754 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 755 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 756 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 757 | // Ignore the read failure, let pmbus code indicate failure, |
| 758 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | try |
| 762 | { |
| 763 | header = |
| 764 | pmbusIntf->readString(SERIAL_HEADER, Type::HwmonDeviceDebug); |
| 765 | sn = pmbusIntf->readString(SERIAL_NUMBER, Type::HwmonDeviceDebug); |
| 766 | assetProps.emplace(SN_PROP, sn); |
| 767 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 768 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 769 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 770 | // Ignore the read failure, let pmbus code indicate failure, |
| 771 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | try |
| 775 | { |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 776 | fwVersion = |
| 777 | pmbusIntf->readString(FW_VERSION, Type::HwmonDeviceDebug); |
| 778 | versionProps.emplace(VERSION_PROP, fwVersion); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 779 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 780 | catch (const ReadFailure& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 781 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 782 | // Ignore the read failure, let pmbus code indicate failure, |
| 783 | // path... |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | ipzvpdVINIProps.emplace("CC", |
| 787 | std::vector<uint8_t>(ccin.begin(), ccin.end())); |
| 788 | ipzvpdVINIProps.emplace("PN", |
| 789 | std::vector<uint8_t>(pn.begin(), pn.end())); |
| 790 | ipzvpdVINIProps.emplace("FN", |
| 791 | std::vector<uint8_t>(fn.begin(), fn.end())); |
| 792 | std::string header_sn = header + sn + '\0'; |
| 793 | ipzvpdVINIProps.emplace( |
| 794 | "SN", std::vector<uint8_t>(header_sn.begin(), header_sn.end())); |
| 795 | std::string description = "IBM PS"; |
| 796 | ipzvpdVINIProps.emplace( |
| 797 | "DR", std::vector<uint8_t>(description.begin(), description.end())); |
| 798 | |
| 799 | // Update the Resource Identifier (RI) keyword |
| 800 | // 2 byte FRC: 0x0003 |
| 801 | // 2 byte RID: 0x1000, 0x1001... |
| 802 | std::uint8_t num = std::stoul( |
| 803 | inventoryPath.substr(inventoryPath.size() - 1, 1), nullptr, 0); |
| 804 | std::vector<uint8_t> ri{0x00, 0x03, 0x10, num}; |
| 805 | ipzvpdDINFProps.emplace("RI", ri); |
| 806 | |
| 807 | // Fill in the FRU Label (FL) keyword. |
| 808 | std::string fl = "E"; |
| 809 | fl.push_back(inventoryPath.back()); |
| 810 | fl.resize(FL_KW_SIZE, ' '); |
| 811 | ipzvpdDINFProps.emplace("FL", |
| 812 | std::vector<uint8_t>(fl.begin(), fl.end())); |
| 813 | |
| 814 | interfaces.emplace(ASSET_IFACE, std::move(assetProps)); |
| 815 | interfaces.emplace(VERSION_IFACE, std::move(versionProps)); |
| 816 | interfaces.emplace(DINF_IFACE, std::move(ipzvpdDINFProps)); |
| 817 | interfaces.emplace(VINI_IFACE, std::move(ipzvpdVINIProps)); |
| 818 | |
George Liu | 070c1bc | 2020-10-12 11:28:01 +0800 | [diff] [blame] | 819 | // Update the Functional |
| 820 | operProps.emplace(FUNCTIONAL_PROP, present); |
| 821 | interfaces.emplace(OPERATIONAL_STATE_IFACE, std::move(operProps)); |
| 822 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 823 | auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH)); |
| 824 | object.emplace(path, std::move(interfaces)); |
| 825 | |
| 826 | try |
| 827 | { |
| 828 | auto service = |
| 829 | util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus); |
| 830 | |
| 831 | if (service.empty()) |
| 832 | { |
| 833 | log<level::ERR>("Unable to get inventory manager service"); |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | auto method = |
| 838 | bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH, |
| 839 | INVENTORY_MGR_IFACE, "Notify"); |
| 840 | |
| 841 | method.append(std::move(object)); |
| 842 | |
| 843 | auto reply = bus.call(method); |
| 844 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 845 | catch (const std::exception& e) |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 846 | { |
Jay Meyer | 6a3fd2c | 2020-08-25 16:37:16 -0500 | [diff] [blame] | 847 | log<level::ERR>( |
| 848 | std::string(e.what() + std::string(" PATH=") + inventoryPath) |
| 849 | .c_str()); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 850 | } |
| 851 | #endif |
| 852 | } |
| 853 | } |
| 854 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 855 | void PowerSupply::getInputVoltage(double& actualInputVoltage, |
| 856 | int& inputVoltage) const |
| 857 | { |
| 858 | using namespace phosphor::pmbus; |
| 859 | |
| 860 | actualInputVoltage = in_input::VIN_VOLTAGE_0; |
| 861 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 862 | |
| 863 | if (present) |
| 864 | { |
| 865 | try |
| 866 | { |
| 867 | // Read input voltage in millivolts |
| 868 | auto inputVoltageStr = pmbusIntf->readString(READ_VIN, Type::Hwmon); |
| 869 | |
| 870 | // Convert to volts |
| 871 | actualInputVoltage = std::stod(inputVoltageStr) / 1000; |
| 872 | |
| 873 | // Calculate the voltage based on voltage thresholds |
| 874 | if (actualInputVoltage < in_input::VIN_VOLTAGE_MIN) |
| 875 | { |
| 876 | inputVoltage = in_input::VIN_VOLTAGE_0; |
| 877 | } |
| 878 | else if (actualInputVoltage < in_input::VIN_VOLTAGE_110_THRESHOLD) |
| 879 | { |
| 880 | inputVoltage = in_input::VIN_VOLTAGE_110; |
| 881 | } |
| 882 | else |
| 883 | { |
| 884 | inputVoltage = in_input::VIN_VOLTAGE_220; |
| 885 | } |
| 886 | } |
| 887 | catch (const std::exception& e) |
| 888 | { |
| 889 | log<level::ERR>( |
| 890 | fmt::format("READ_VIN read error: {}", e.what()).c_str()); |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 895 | } // namespace phosphor::power::psu |