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