Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 1 | #include "psu_manager.hpp" |
| 2 | |
| 3 | #include "utility.hpp" |
| 4 | |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 5 | #include <fmt/format.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <unistd.h> |
| 8 | |
Brandon Wyman | ecbecbc | 2021-08-31 22:53:21 +0000 | [diff] [blame] | 9 | #include <regex> |
| 10 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 11 | using namespace phosphor::logging; |
| 12 | |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 13 | namespace phosphor::power::manager |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 14 | { |
Adriana Kobylak | c9b0573 | 2022-03-19 15:15:10 +0000 | [diff] [blame] | 15 | constexpr auto managerBusName = "xyz.openbmc_project.Power.PSUMonitor"; |
| 16 | constexpr auto objectManagerObjPath = |
| 17 | "/xyz/openbmc_project/power/power_supplies"; |
| 18 | constexpr auto powerSystemsInputsObjPath = |
| 19 | "/xyz/openbmc_project/power/power_supplies/chassis0/psus"; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 20 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 21 | constexpr auto IBMCFFPSInterface = |
| 22 | "xyz.openbmc_project.Configuration.IBMCFFPSConnector"; |
| 23 | constexpr auto i2cBusProp = "I2CBus"; |
| 24 | constexpr auto i2cAddressProp = "I2CAddress"; |
| 25 | constexpr auto psuNameProp = "Name"; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 26 | constexpr auto presLineName = "NamedPresenceGpio"; |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 27 | |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 28 | constexpr auto supportedConfIntf = |
| 29 | "xyz.openbmc_project.Configuration.SupportedConfiguration"; |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 30 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 31 | PSUManager::PSUManager(sdbusplus::bus::bus& bus, const sdeventplus::Event& e) : |
Adriana Kobylak | c9b0573 | 2022-03-19 15:15:10 +0000 | [diff] [blame] | 32 | bus(bus), powerSystemInputs(bus, powerSystemsInputsObjPath), |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame^] | 33 | objectManager(bus, objectManagerObjPath), |
| 34 | historyManager(bus, "/org/open_power/sensors") |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 35 | { |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 36 | // Subscribe to InterfacesAdded before doing a property read, otherwise |
| 37 | // the interface could be created after the read attempt but before the |
| 38 | // match is created. |
| 39 | entityManagerIfacesAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 40 | bus, |
| 41 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 42 | sdbusplus::bus::match::rules::sender( |
| 43 | "xyz.openbmc_project.EntityManager"), |
| 44 | std::bind(&PSUManager::entityManagerIfaceAdded, this, |
| 45 | std::placeholders::_1)); |
| 46 | getPSUConfiguration(); |
| 47 | getSystemProperties(); |
| 48 | |
Adriana Kobylak | c9b0573 | 2022-03-19 15:15:10 +0000 | [diff] [blame] | 49 | // Request the bus name before the analyze() function, which is the one that |
| 50 | // determines the brownout condition and sets the status d-bus property. |
| 51 | bus.request_name(managerBusName); |
| 52 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 53 | using namespace sdeventplus; |
| 54 | auto interval = std::chrono::milliseconds(1000); |
| 55 | timer = std::make_unique<utility::Timer<ClockId::Monotonic>>( |
| 56 | e, std::bind(&PSUManager::analyze, this), interval); |
| 57 | |
Adriana Kobylak | a4d38fa | 2021-10-05 19:57:47 +0000 | [diff] [blame] | 58 | validationTimer = std::make_unique<utility::Timer<ClockId::Monotonic>>( |
| 59 | e, std::bind(&PSUManager::validateConfig, this)); |
| 60 | |
Adriana Kobylak | c0a0758 | 2021-10-13 15:52:25 +0000 | [diff] [blame] | 61 | try |
| 62 | { |
| 63 | powerConfigGPIO = createGPIO("power-config-full-load"); |
| 64 | } |
| 65 | catch (const std::exception& e) |
| 66 | { |
| 67 | // Ignore error, GPIO may not be implemented in this system. |
| 68 | powerConfigGPIO = nullptr; |
| 69 | } |
| 70 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 71 | // Subscribe to power state changes |
| 72 | powerService = util::getService(POWER_OBJ_PATH, POWER_IFACE, bus); |
| 73 | powerOnMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 74 | bus, |
| 75 | sdbusplus::bus::match::rules::propertiesChanged(POWER_OBJ_PATH, |
| 76 | POWER_IFACE), |
| 77 | [this](auto& msg) { this->powerStateChanged(msg); }); |
| 78 | |
| 79 | initialize(); |
| 80 | } |
| 81 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 82 | void PSUManager::getPSUConfiguration() |
| 83 | { |
| 84 | using namespace phosphor::power::util; |
| 85 | auto depth = 0; |
| 86 | auto objects = getSubTree(bus, "/", IBMCFFPSInterface, depth); |
| 87 | |
| 88 | psus.clear(); |
| 89 | |
| 90 | // I should get a map of objects back. |
| 91 | // Each object will have a path, a service, and an interface. |
| 92 | // The interface should match the one passed into this function. |
| 93 | for (const auto& [path, services] : objects) |
| 94 | { |
| 95 | auto service = services.begin()->first; |
| 96 | |
| 97 | if (path.empty() || service.empty()) |
| 98 | { |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | // For each object in the array of objects, I want to get properties |
| 103 | // from the service, path, and interface. |
| 104 | auto properties = |
| 105 | getAllProperties(bus, path, IBMCFFPSInterface, service); |
| 106 | |
| 107 | getPSUProperties(properties); |
| 108 | } |
| 109 | |
| 110 | if (psus.empty()) |
| 111 | { |
| 112 | // Interface or properties not found. Let the Interfaces Added callback |
| 113 | // process the information once the interfaces are added to D-Bus. |
| 114 | log<level::INFO>(fmt::format("No power supplies to monitor").c_str()); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void PSUManager::getPSUProperties(util::DbusPropertyMap& properties) |
| 119 | { |
| 120 | // From passed in properties, I want to get: I2CBus, I2CAddress, |
| 121 | // and Name. Create a power supply object, using Name to build the inventory |
| 122 | // path. |
| 123 | const auto basePSUInvPath = |
| 124 | "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply"; |
| 125 | uint64_t* i2cbus = nullptr; |
| 126 | uint64_t* i2caddr = nullptr; |
| 127 | std::string* psuname = nullptr; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 128 | std::string* preslineptr = nullptr; |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 129 | |
| 130 | for (const auto& property : properties) |
| 131 | { |
| 132 | try |
| 133 | { |
| 134 | if (property.first == i2cBusProp) |
| 135 | { |
| 136 | i2cbus = std::get_if<uint64_t>(&properties[i2cBusProp]); |
| 137 | } |
| 138 | else if (property.first == i2cAddressProp) |
| 139 | { |
| 140 | i2caddr = std::get_if<uint64_t>(&properties[i2cAddressProp]); |
| 141 | } |
| 142 | else if (property.first == psuNameProp) |
| 143 | { |
| 144 | psuname = std::get_if<std::string>(&properties[psuNameProp]); |
| 145 | } |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 146 | else if (property.first == presLineName) |
| 147 | { |
| 148 | preslineptr = |
| 149 | std::get_if<std::string>(&properties[presLineName]); |
| 150 | } |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 151 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 152 | catch (const std::exception& e) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 153 | {} |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | if ((i2cbus) && (i2caddr) && (psuname) && (!psuname->empty())) |
| 157 | { |
| 158 | std::string invpath = basePSUInvPath; |
| 159 | invpath.push_back(psuname->back()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 160 | std::string presline = ""; |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 161 | |
| 162 | log<level::DEBUG>(fmt::format("Inventory Path: {}", invpath).c_str()); |
| 163 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 164 | if (nullptr != preslineptr) |
| 165 | { |
| 166 | presline = *preslineptr; |
| 167 | } |
| 168 | |
Brandon Wyman | ecbecbc | 2021-08-31 22:53:21 +0000 | [diff] [blame] | 169 | auto invMatch = |
| 170 | std::find_if(psus.begin(), psus.end(), [&invpath](auto& psu) { |
| 171 | return psu->getInventoryPath() == invpath; |
| 172 | }); |
| 173 | if (invMatch != psus.end()) |
| 174 | { |
| 175 | // This power supply has the same inventory path as the one with |
| 176 | // information just added to D-Bus. |
| 177 | // Changes to GPIO line name unlikely, so skip checking. |
| 178 | // Changes to the I2C bus and address unlikely, as that would |
| 179 | // require corresponding device tree updates. |
| 180 | // Return out to avoid duplicate object creation. |
| 181 | return; |
| 182 | } |
| 183 | |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame^] | 184 | constexpr auto driver = "ibm-cffps"; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 185 | log<level::DEBUG>( |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame^] | 186 | fmt::format( |
| 187 | "make PowerSupply bus: {} addr: {} driver: {} presline: {}", |
| 188 | *i2cbus, *i2caddr, driver, presline) |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 189 | .c_str()); |
| 190 | auto psu = std::make_unique<PowerSupply>(bus, invpath, *i2cbus, |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame^] | 191 | *i2caddr, driver, presline); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 192 | psus.emplace_back(std::move(psu)); |
Adriana Kobylak | 9ba3823 | 2021-11-16 20:27:45 +0000 | [diff] [blame] | 193 | |
| 194 | // Subscribe to power supply presence changes |
| 195 | auto presenceMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 196 | bus, |
| 197 | sdbusplus::bus::match::rules::propertiesChanged(invpath, |
| 198 | INVENTORY_IFACE), |
| 199 | [this](auto& msg) { this->presenceChanged(msg); }); |
| 200 | presenceMatches.emplace_back(std::move(presenceMatch)); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | if (psus.empty()) |
| 204 | { |
| 205 | log<level::INFO>(fmt::format("No power supplies to monitor").c_str()); |
| 206 | } |
| 207 | } |
| 208 | |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 209 | void PSUManager::populateSysProperties(const util::DbusPropertyMap& properties) |
| 210 | { |
| 211 | try |
| 212 | { |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 213 | auto propIt = properties.find("SupportedType"); |
| 214 | if (propIt == properties.end()) |
| 215 | { |
| 216 | return; |
| 217 | } |
| 218 | const std::string* type = std::get_if<std::string>(&(propIt->second)); |
| 219 | if ((type == nullptr) || (*type != "PowerSupply")) |
| 220 | { |
| 221 | return; |
| 222 | } |
| 223 | |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 224 | propIt = properties.find("SupportedModel"); |
| 225 | if (propIt == properties.end()) |
| 226 | { |
| 227 | return; |
| 228 | } |
Adriana Kobylak | d3a70d9 | 2021-06-04 16:24:45 +0000 | [diff] [blame] | 229 | const std::string* model = std::get_if<std::string>(&(propIt->second)); |
| 230 | if (model == nullptr) |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 231 | { |
| 232 | return; |
| 233 | } |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 234 | |
Adriana Kobylak | d3a70d9 | 2021-06-04 16:24:45 +0000 | [diff] [blame] | 235 | sys_properties sys; |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 236 | propIt = properties.find("RedundantCount"); |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 237 | if (propIt != properties.end()) |
| 238 | { |
| 239 | const uint64_t* count = std::get_if<uint64_t>(&(propIt->second)); |
| 240 | if (count != nullptr) |
| 241 | { |
Adriana Kobylak | d3a70d9 | 2021-06-04 16:24:45 +0000 | [diff] [blame] | 242 | sys.powerSupplyCount = *count; |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 245 | propIt = properties.find("InputVoltage"); |
| 246 | if (propIt != properties.end()) |
| 247 | { |
Adriana Kobylak | d3a70d9 | 2021-06-04 16:24:45 +0000 | [diff] [blame] | 248 | const std::vector<uint64_t>* voltage = |
| 249 | std::get_if<std::vector<uint64_t>>(&(propIt->second)); |
Adriana Kobylak | 9ea66a6 | 2021-03-24 17:54:14 +0000 | [diff] [blame] | 250 | if (voltage != nullptr) |
| 251 | { |
| 252 | sys.inputVoltage = *voltage; |
| 253 | } |
| 254 | } |
| 255 | |
Adriana Kobylak | 886574c | 2021-11-01 18:22:28 +0000 | [diff] [blame] | 256 | // The PowerConfigFullLoad is an optional property, default it to false |
| 257 | // since that's the default value of the power-config-full-load GPIO. |
| 258 | sys.powerConfigFullLoad = false; |
| 259 | propIt = properties.find("PowerConfigFullLoad"); |
| 260 | if (propIt != properties.end()) |
| 261 | { |
| 262 | const bool* fullLoad = std::get_if<bool>(&(propIt->second)); |
| 263 | if (fullLoad != nullptr) |
| 264 | { |
| 265 | sys.powerConfigFullLoad = *fullLoad; |
| 266 | } |
| 267 | } |
| 268 | |
Adriana Kobylak | d3a70d9 | 2021-06-04 16:24:45 +0000 | [diff] [blame] | 269 | supportedConfigs.emplace(*model, sys); |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 270 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 271 | catch (const std::exception& e) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 272 | {} |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 275 | void PSUManager::getSystemProperties() |
| 276 | { |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 277 | |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 278 | try |
| 279 | { |
| 280 | util::DbusSubtree subtree = |
| 281 | util::getSubTree(bus, INVENTORY_OBJ_PATH, supportedConfIntf, 0); |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 282 | if (subtree.empty()) |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 283 | { |
| 284 | throw std::runtime_error("Supported Configuration Not Found"); |
| 285 | } |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 286 | |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 287 | for (const auto& [objPath, services] : subtree) |
| 288 | { |
| 289 | std::string service = services.begin()->first; |
| 290 | if (objPath.empty() || service.empty()) |
| 291 | { |
| 292 | continue; |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 293 | } |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 294 | auto properties = util::getAllProperties( |
| 295 | bus, objPath, supportedConfIntf, service); |
| 296 | populateSysProperties(properties); |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 297 | } |
| 298 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 299 | catch (const std::exception& e) |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 300 | { |
| 301 | // Interface or property not found. Let the Interfaces Added callback |
| 302 | // process the information once the interfaces are added to D-Bus. |
| 303 | } |
| 304 | } |
| 305 | |
Brandon Wyman | 3e42913 | 2021-03-18 18:03:14 -0500 | [diff] [blame] | 306 | void PSUManager::entityManagerIfaceAdded(sdbusplus::message::message& msg) |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 307 | { |
| 308 | try |
| 309 | { |
| 310 | sdbusplus::message::object_path objPath; |
Adriana Kobylak | e1074d8 | 2021-03-16 20:46:44 +0000 | [diff] [blame] | 311 | std::map<std::string, std::map<std::string, util::DbusVariant>> |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 312 | interfaces; |
| 313 | msg.read(objPath, interfaces); |
| 314 | |
| 315 | auto itIntf = interfaces.find(supportedConfIntf); |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 316 | if (itIntf != interfaces.cend()) |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 317 | { |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 318 | populateSysProperties(itIntf->second); |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Brandon Wyman | 510acaa | 2020-11-05 18:32:04 -0600 | [diff] [blame] | 321 | itIntf = interfaces.find(IBMCFFPSInterface); |
| 322 | if (itIntf != interfaces.cend()) |
| 323 | { |
| 324 | log<level::INFO>( |
| 325 | fmt::format("InterfacesAdded for: {}", IBMCFFPSInterface) |
| 326 | .c_str()); |
| 327 | getPSUProperties(itIntf->second); |
| 328 | } |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 329 | |
| 330 | // Call to validate the psu configuration if the power is on and both |
| 331 | // the IBMCFFPSConnector and SupportedConfiguration interfaces have been |
| 332 | // processed |
| 333 | if (powerOn && !psus.empty() && !supportedConfigs.empty()) |
| 334 | { |
Adriana Kobylak | a4d38fa | 2021-10-05 19:57:47 +0000 | [diff] [blame] | 335 | validationTimer->restartOnce(validationTimeout); |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 336 | } |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 337 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 338 | catch (const std::exception& e) |
Adriana Kobylak | 9bab9e1 | 2021-02-24 15:32:03 -0600 | [diff] [blame] | 339 | { |
| 340 | // Ignore, the property may be of a different type than expected. |
| 341 | } |
| 342 | } |
| 343 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 344 | void PSUManager::powerStateChanged(sdbusplus::message::message& msg) |
| 345 | { |
| 346 | int32_t state = 0; |
| 347 | std::string msgSensor; |
Patrick Williams | abe4941 | 2020-05-13 17:59:47 -0500 | [diff] [blame] | 348 | std::map<std::string, std::variant<int32_t>> msgData; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 349 | msg.read(msgSensor, msgData); |
| 350 | |
| 351 | // Check if it was the Present property that changed. |
| 352 | auto valPropMap = msgData.find("state"); |
| 353 | if (valPropMap != msgData.end()) |
| 354 | { |
| 355 | state = std::get<int32_t>(valPropMap->second); |
| 356 | |
| 357 | // Power is on when state=1. Clear faults. |
| 358 | if (state) |
| 359 | { |
| 360 | powerOn = true; |
Adriana Kobylak | a4d38fa | 2021-10-05 19:57:47 +0000 | [diff] [blame] | 361 | validationTimer->restartOnce(validationTimeout); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 362 | clearFaults(); |
Adriana Kobylak | c0a0758 | 2021-10-13 15:52:25 +0000 | [diff] [blame] | 363 | setPowerConfigGPIO(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
| 367 | powerOn = false; |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 368 | runValidateConfig = true; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Adriana Kobylak | 9ba3823 | 2021-11-16 20:27:45 +0000 | [diff] [blame] | 373 | void PSUManager::presenceChanged(sdbusplus::message::message& msg) |
| 374 | { |
| 375 | std::string msgSensor; |
| 376 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
| 377 | msg.read(msgSensor, msgData); |
| 378 | |
| 379 | // Check if it was the Present property that changed. |
| 380 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 381 | if (valPropMap != msgData.end()) |
| 382 | { |
| 383 | if (std::get<bool>(valPropMap->second)) |
| 384 | { |
| 385 | // A PSU became present, force the PSU validation to run. |
| 386 | runValidateConfig = true; |
| 387 | validationTimer->restartOnce(validationTimeout); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
Brandon Wyman | 10fc6e8 | 2022-02-08 20:51:22 +0000 | [diff] [blame] | 392 | void PSUManager::setPowerSupplyError(const std::string& psuErrorString) |
| 393 | { |
| 394 | using namespace sdbusplus::xyz::openbmc_project; |
| 395 | constexpr auto service = "org.openbmc.control.Power"; |
| 396 | constexpr auto objPath = "/org/openbmc/control/power0"; |
| 397 | constexpr auto interface = "org.openbmc.control.Power"; |
| 398 | constexpr auto method = "setPowerSupplyError"; |
| 399 | |
| 400 | try |
| 401 | { |
| 402 | // Call D-Bus method to inform pseq of PSU error |
| 403 | auto methodMsg = |
| 404 | bus.new_method_call(service, objPath, interface, method); |
| 405 | methodMsg.append(psuErrorString); |
| 406 | auto callReply = bus.call(methodMsg); |
| 407 | } |
| 408 | catch (const std::exception& e) |
| 409 | { |
| 410 | log<level::INFO>( |
| 411 | fmt::format("Failed calling setPowerSupplyError due to error {}", |
| 412 | e.what()) |
| 413 | .c_str()); |
| 414 | } |
| 415 | } |
| 416 | |
Brandon Wyman | 8b66288 | 2021-10-08 17:31:51 +0000 | [diff] [blame] | 417 | void PSUManager::createError(const std::string& faultName, |
| 418 | std::map<std::string, std::string>& additionalData) |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 419 | { |
| 420 | using namespace sdbusplus::xyz::openbmc_project; |
| 421 | constexpr auto loggingObjectPath = "/xyz/openbmc_project/logging"; |
| 422 | constexpr auto loggingCreateInterface = |
| 423 | "xyz.openbmc_project.Logging.Create"; |
| 424 | |
| 425 | try |
| 426 | { |
Brandon Wyman | 8b66288 | 2021-10-08 17:31:51 +0000 | [diff] [blame] | 427 | additionalData["_PID"] = std::to_string(getpid()); |
| 428 | |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 429 | auto service = |
| 430 | util::getService(loggingObjectPath, loggingCreateInterface, bus); |
| 431 | |
| 432 | if (service.empty()) |
| 433 | { |
| 434 | log<level::ERR>("Unable to get logging manager service"); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | auto method = bus.new_method_call(service.c_str(), loggingObjectPath, |
| 439 | loggingCreateInterface, "Create"); |
| 440 | |
| 441 | auto level = Logging::server::Entry::Level::Error; |
| 442 | method.append(faultName, level, additionalData); |
| 443 | |
| 444 | auto reply = bus.call(method); |
Brandon Wyman | 10fc6e8 | 2022-02-08 20:51:22 +0000 | [diff] [blame] | 445 | setPowerSupplyError(faultName); |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 446 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 447 | catch (const std::exception& e) |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 448 | { |
| 449 | log<level::ERR>( |
| 450 | fmt::format( |
| 451 | "Failed creating event log for fault {} due to error {}", |
| 452 | faultName, e.what()) |
| 453 | .c_str()); |
| 454 | } |
| 455 | } |
| 456 | |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 457 | void PSUManager::analyze() |
| 458 | { |
| 459 | for (auto& psu : psus) |
| 460 | { |
| 461 | psu->analyze(); |
| 462 | } |
| 463 | |
Adriana Kobylak | e5b1e08 | 2022-03-02 15:37:32 +0000 | [diff] [blame] | 464 | std::map<std::string, std::string> additionalData; |
| 465 | |
| 466 | auto notPresentCount = decltype(psus.size())( |
| 467 | std::count_if(psus.begin(), psus.end(), |
| 468 | [](const auto& psu) { return !psu->isPresent(); })); |
| 469 | |
| 470 | auto hasVINUVFaultCount = decltype(psus.size())( |
| 471 | std::count_if(psus.begin(), psus.end(), |
| 472 | [](const auto& psu) { return psu->hasVINUVFault(); })); |
| 473 | |
| 474 | // The PSU D-Bus objects may not be available yet, so ignore if all |
| 475 | // PSUs are not present or the number of PSUs is still 0. |
| 476 | if ((psus.size() == (notPresentCount + hasVINUVFaultCount)) && |
| 477 | (psus.size() != notPresentCount) && (psus.size() != 0)) |
| 478 | { |
| 479 | // Brownout: All PSUs report an AC failure: At least one PSU reports |
| 480 | // AC loss VIN fault and the rest either report AC loss VIN fault as |
| 481 | // well or are not present. |
| 482 | additionalData["NOT_PRESENT_COUNT"] = std::to_string(notPresentCount); |
| 483 | additionalData["VIN_FAULT_COUNT"] = std::to_string(hasVINUVFaultCount); |
| 484 | setBrownout(additionalData); |
| 485 | } |
| 486 | else |
| 487 | { |
| 488 | // Brownout condition is not present or has been cleared |
| 489 | clearBrownout(); |
| 490 | } |
| 491 | |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 492 | if (powerOn) |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 493 | { |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 494 | for (auto& psu : psus) |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 495 | { |
Brandon Wyman | ec0b8dc | 2021-10-08 21:49:43 +0000 | [diff] [blame] | 496 | additionalData.clear(); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 497 | |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 498 | if (!psu->isFaultLogged() && !psu->isPresent()) |
| 499 | { |
Brandon Wyman | da369c7 | 2021-10-08 18:43:30 +0000 | [diff] [blame] | 500 | std::map<std::string, std::string> requiredPSUsData; |
| 501 | auto requiredPSUsPresent = hasRequiredPSUs(requiredPSUsData); |
Adriana Kobylak | f2ba146 | 2021-06-24 15:16:17 +0000 | [diff] [blame] | 502 | if (!requiredPSUsPresent) |
| 503 | { |
Brandon Wyman | da369c7 | 2021-10-08 18:43:30 +0000 | [diff] [blame] | 504 | additionalData.merge(requiredPSUsData); |
Adriana Kobylak | f2ba146 | 2021-06-24 15:16:17 +0000 | [diff] [blame] | 505 | // Create error for power supply missing. |
| 506 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 507 | psu->getInventoryPath(); |
| 508 | additionalData["CALLOUT_PRIORITY"] = "H"; |
| 509 | createError( |
| 510 | "xyz.openbmc_project.Power.PowerSupply.Error.Missing", |
| 511 | additionalData); |
| 512 | } |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 513 | psu->setFaultLogged(); |
| 514 | } |
| 515 | else if (!psu->isFaultLogged() && psu->isFaulted()) |
| 516 | { |
Brandon Wyman | 786b6f4 | 2021-10-12 20:21:41 +0000 | [diff] [blame] | 517 | // Add STATUS_WORD and STATUS_MFR last response, in padded |
| 518 | // hexadecimal format. |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 519 | additionalData["STATUS_WORD"] = |
Brandon Wyman | 786b6f4 | 2021-10-12 20:21:41 +0000 | [diff] [blame] | 520 | fmt::format("{:#04x}", psu->getStatusWord()); |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 521 | additionalData["STATUS_MFR"] = |
Brandon Wyman | 786b6f4 | 2021-10-12 20:21:41 +0000 | [diff] [blame] | 522 | fmt::format("{:#02x}", psu->getMFRFault()); |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 523 | // If there are faults being reported, they possibly could be |
| 524 | // related to a bug in the firmware version running on the power |
| 525 | // supply. Capture that data into the error as well. |
| 526 | additionalData["FW_VERSION"] = psu->getFWVersion(); |
| 527 | |
Brandon Wyman | b85b9dd | 2021-10-19 21:25:17 +0000 | [diff] [blame] | 528 | if (psu->hasCommFault()) |
| 529 | { |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 530 | additionalData["STATUS_CML"] = |
| 531 | fmt::format("{:#02x}", psu->getStatusCML()); |
Brandon Wyman | b85b9dd | 2021-10-19 21:25:17 +0000 | [diff] [blame] | 532 | /* Attempts to communicate with the power supply have |
| 533 | * reached there limit. Create an error. */ |
| 534 | additionalData["CALLOUT_DEVICE_PATH"] = |
| 535 | psu->getDevicePath(); |
| 536 | |
| 537 | createError( |
| 538 | "xyz.openbmc_project.Power.PowerSupply.Error.CommFault", |
| 539 | additionalData); |
| 540 | |
| 541 | psu->setFaultLogged(); |
| 542 | } |
| 543 | else if ((psu->hasInputFault() || psu->hasVINUVFault())) |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 544 | { |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 545 | // Include STATUS_INPUT for input faults. |
| 546 | additionalData["STATUS_INPUT"] = |
| 547 | fmt::format("{:#02x}", psu->getStatusInput()); |
| 548 | |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 549 | /* The power supply location might be needed if the input |
| 550 | * fault is due to a problem with the power supply itself. |
| 551 | * Include the inventory path with a call out priority of |
| 552 | * low. |
| 553 | */ |
| 554 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 555 | psu->getInventoryPath(); |
| 556 | additionalData["CALLOUT_PRIORITY"] = "L"; |
| 557 | createError("xyz.openbmc_project.Power.PowerSupply.Error." |
| 558 | "InputFault", |
| 559 | additionalData); |
| 560 | psu->setFaultLogged(); |
| 561 | } |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 562 | else if (psu->hasPSKillFault()) |
| 563 | { |
| 564 | createError( |
| 565 | "xyz.openbmc_project.Power.PowerSupply.Error.PSKillFault", |
| 566 | additionalData); |
| 567 | psu->setFaultLogged(); |
| 568 | } |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 569 | else if (psu->hasVoutOVFault()) |
| 570 | { |
| 571 | // Include STATUS_VOUT for Vout faults. |
| 572 | additionalData["STATUS_VOUT"] = |
| 573 | fmt::format("{:#02x}", psu->getStatusVout()); |
| 574 | |
| 575 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 576 | psu->getInventoryPath(); |
| 577 | |
| 578 | createError( |
| 579 | "xyz.openbmc_project.Power.PowerSupply.Error.Fault", |
| 580 | additionalData); |
| 581 | |
| 582 | psu->setFaultLogged(); |
| 583 | } |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 584 | else if (psu->hasIoutOCFault()) |
| 585 | { |
| 586 | // Include STATUS_IOUT for Iout faults. |
| 587 | additionalData["STATUS_IOUT"] = |
| 588 | fmt::format("{:#02x}", psu->getStatusIout()); |
| 589 | |
| 590 | createError( |
| 591 | "xyz.openbmc_project.Power.PowerSupply.Error.IoutOCFault", |
| 592 | additionalData); |
| 593 | |
| 594 | psu->setFaultLogged(); |
| 595 | } |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 596 | else if (psu->hasVoutUVFault() || psu->hasPS12VcsFault() || |
| 597 | psu->hasPSCS12VFault()) |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 598 | { |
| 599 | // Include STATUS_VOUT for Vout faults. |
| 600 | additionalData["STATUS_VOUT"] = |
| 601 | fmt::format("{:#02x}", psu->getStatusVout()); |
| 602 | |
| 603 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 604 | psu->getInventoryPath(); |
| 605 | |
| 606 | createError( |
| 607 | "xyz.openbmc_project.Power.PowerSupply.Error.Fault", |
| 608 | additionalData); |
| 609 | |
| 610 | psu->setFaultLogged(); |
| 611 | } |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 612 | // A fan fault should have priority over a temperature fault, |
| 613 | // since a failed fan may lead to a temperature problem. |
| 614 | else if (psu->hasFanFault()) |
| 615 | { |
| 616 | // Include STATUS_TEMPERATURE and STATUS_FANS_1_2 |
| 617 | additionalData["STATUS_TEMPERATURE"] = |
| 618 | fmt::format("{:#02x}", psu->getStatusTemperature()); |
| 619 | additionalData["STATUS_FANS_1_2"] = |
| 620 | fmt::format("{:#02x}", psu->getStatusFans12()); |
| 621 | |
| 622 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 623 | psu->getInventoryPath(); |
| 624 | |
| 625 | createError( |
| 626 | "xyz.openbmc_project.Power.PowerSupply.Error.FanFault", |
| 627 | additionalData); |
| 628 | |
| 629 | psu->setFaultLogged(); |
| 630 | } |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 631 | else if (psu->hasTempFault()) |
| 632 | { |
| 633 | // Include STATUS_TEMPERATURE for temperature faults. |
| 634 | additionalData["STATUS_TEMPERATURE"] = |
| 635 | fmt::format("{:#02x}", psu->getStatusTemperature()); |
| 636 | |
| 637 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 638 | psu->getInventoryPath(); |
| 639 | |
| 640 | createError( |
| 641 | "xyz.openbmc_project.Power.PowerSupply.Error.Fault", |
| 642 | additionalData); |
| 643 | |
| 644 | psu->setFaultLogged(); |
| 645 | } |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 646 | else if (psu->hasMFRFault()) |
| 647 | { |
| 648 | /* This can represent a variety of faults that result in |
| 649 | * calling out the power supply for replacement: Output |
| 650 | * OverCurrent, Output Under Voltage, and potentially other |
| 651 | * faults. |
| 652 | * |
| 653 | * Also plan on putting specific fault in AdditionalData, |
| 654 | * along with register names and register values |
| 655 | * (STATUS_WORD, STATUS_MFR, etc.).*/ |
| 656 | |
| 657 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 658 | psu->getInventoryPath(); |
| 659 | |
| 660 | createError( |
| 661 | "xyz.openbmc_project.Power.PowerSupply.Error.Fault", |
Brandon Wyman | 52e54e8 | 2020-10-08 14:44:58 -0500 | [diff] [blame] | 662 | additionalData); |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 663 | |
Brandon Wyman | 3180f4d | 2020-12-08 17:53:46 -0600 | [diff] [blame] | 664 | psu->setFaultLogged(); |
| 665 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 666 | else if (psu->hasPgoodFault()) |
| 667 | { |
| 668 | /* POWER_GOOD# is not low, or OFF is on */ |
| 669 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 670 | psu->getInventoryPath(); |
| 671 | |
| 672 | createError( |
| 673 | "xyz.openbmc_project.Power.PowerSupply.Error.Fault", |
| 674 | additionalData); |
| 675 | |
| 676 | psu->setFaultLogged(); |
| 677 | } |
Brandon Wyman | 4176d6b | 2020-10-07 17:41:06 -0500 | [diff] [blame] | 678 | } |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 683 | void PSUManager::validateConfig() |
| 684 | { |
Adriana Kobylak | b23e443 | 2022-04-01 14:22:47 +0000 | [diff] [blame] | 685 | if (!runValidateConfig || supportedConfigs.empty() || psus.empty()) |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 686 | { |
| 687 | return; |
| 688 | } |
| 689 | |
Adriana Kobylak | 4d9aaf9 | 2021-06-30 15:27:42 +0000 | [diff] [blame] | 690 | std::map<std::string, std::string> additionalData; |
| 691 | auto supported = hasRequiredPSUs(additionalData); |
| 692 | if (supported) |
| 693 | { |
| 694 | runValidateConfig = false; |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | // Validation failed, create an error log. |
| 699 | // Return without setting the runValidateConfig flag to false because |
| 700 | // it may be that an additional supported configuration interface is |
| 701 | // added and we need to validate it to see if it matches this system. |
| 702 | createError("xyz.openbmc_project.Power.PowerSupply.Error.NotSupported", |
| 703 | additionalData); |
| 704 | } |
| 705 | |
| 706 | bool PSUManager::hasRequiredPSUs( |
| 707 | std::map<std::string, std::string>& additionalData) |
| 708 | { |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 709 | std::string model{}; |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 710 | if (!validateModelName(model, additionalData)) |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 711 | { |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 712 | return false; |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 713 | } |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 714 | |
Adriana Kobylak | 4d9aaf9 | 2021-06-30 15:27:42 +0000 | [diff] [blame] | 715 | auto presentCount = |
| 716 | std::count_if(psus.begin(), psus.end(), |
| 717 | [](const auto& psu) { return psu->isPresent(); }); |
| 718 | |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 719 | // Validate the supported configurations. A system may support more than one |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 720 | // power supply model configuration. Since all configurations need to be |
| 721 | // checked, the additional data would contain only the information of the |
| 722 | // last configuration that did not match. |
| 723 | std::map<std::string, std::string> tmpAdditionalData; |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 724 | for (const auto& config : supportedConfigs) |
| 725 | { |
Adriana Kobylak | 4d9aaf9 | 2021-06-30 15:27:42 +0000 | [diff] [blame] | 726 | if (config.first != model) |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 727 | { |
| 728 | continue; |
| 729 | } |
| 730 | if (presentCount != config.second.powerSupplyCount) |
| 731 | { |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 732 | tmpAdditionalData.clear(); |
| 733 | tmpAdditionalData["EXPECTED_COUNT"] = |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 734 | std::to_string(config.second.powerSupplyCount); |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 735 | tmpAdditionalData["ACTUAL_COUNT"] = std::to_string(presentCount); |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 736 | continue; |
| 737 | } |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 738 | |
| 739 | bool voltageValidated = true; |
| 740 | for (const auto& psu : psus) |
| 741 | { |
| 742 | if (!psu->isPresent()) |
| 743 | { |
| 744 | // Only present PSUs report a valid input voltage |
| 745 | continue; |
| 746 | } |
| 747 | |
| 748 | double actualInputVoltage; |
| 749 | int inputVoltage; |
| 750 | psu->getInputVoltage(actualInputVoltage, inputVoltage); |
| 751 | |
| 752 | if (std::find(config.second.inputVoltage.begin(), |
| 753 | config.second.inputVoltage.end(), |
| 754 | inputVoltage) == config.second.inputVoltage.end()) |
| 755 | { |
| 756 | tmpAdditionalData.clear(); |
| 757 | tmpAdditionalData["ACTUAL_VOLTAGE"] = |
| 758 | std::to_string(actualInputVoltage); |
| 759 | for (const auto& voltage : config.second.inputVoltage) |
| 760 | { |
| 761 | tmpAdditionalData["EXPECTED_VOLTAGE"] += |
| 762 | std::to_string(voltage) + " "; |
| 763 | } |
| 764 | tmpAdditionalData["CALLOUT_INVENTORY_PATH"] = |
| 765 | psu->getInventoryPath(); |
| 766 | |
| 767 | voltageValidated = false; |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | if (!voltageValidated) |
| 772 | { |
| 773 | continue; |
| 774 | } |
| 775 | |
Adriana Kobylak | 4d9aaf9 | 2021-06-30 15:27:42 +0000 | [diff] [blame] | 776 | return true; |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 777 | } |
Adriana Kobylak | 70e7f93 | 2021-06-10 18:53:56 +0000 | [diff] [blame] | 778 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 779 | additionalData.insert(tmpAdditionalData.begin(), tmpAdditionalData.end()); |
Adriana Kobylak | 4d9aaf9 | 2021-06-30 15:27:42 +0000 | [diff] [blame] | 780 | return false; |
Adriana Kobylak | 8f16fb5 | 2021-03-31 15:50:15 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 783 | bool PSUManager::validateModelName( |
| 784 | std::string& model, std::map<std::string, std::string>& additionalData) |
| 785 | { |
| 786 | // Check that all PSUs have the same model name. Initialize the model |
| 787 | // variable with the first PSU name found, then use it as a base to compare |
Adriana Kobylak | b70eae9 | 2022-01-20 22:09:56 +0000 | [diff] [blame] | 788 | // against the rest of the PSUs and get its inventory path to use as callout |
| 789 | // if needed. |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 790 | model.clear(); |
Adriana Kobylak | b70eae9 | 2022-01-20 22:09:56 +0000 | [diff] [blame] | 791 | std::string modelInventoryPath{}; |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 792 | for (const auto& psu : psus) |
| 793 | { |
| 794 | auto psuModel = psu->getModelName(); |
| 795 | if (psuModel.empty()) |
| 796 | { |
| 797 | continue; |
| 798 | } |
| 799 | if (model.empty()) |
| 800 | { |
| 801 | model = psuModel; |
Adriana Kobylak | b70eae9 | 2022-01-20 22:09:56 +0000 | [diff] [blame] | 802 | modelInventoryPath = psu->getInventoryPath(); |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 803 | continue; |
| 804 | } |
| 805 | if (psuModel != model) |
| 806 | { |
Adriana Kobylak | b70eae9 | 2022-01-20 22:09:56 +0000 | [diff] [blame] | 807 | if (supportedConfigs.find(model) != supportedConfigs.end()) |
| 808 | { |
| 809 | // The base model is supported, callout the mismatched PSU. The |
| 810 | // mismatched PSU may or may not be supported. |
| 811 | additionalData["EXPECTED_MODEL"] = model; |
| 812 | additionalData["ACTUAL_MODEL"] = psuModel; |
| 813 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 814 | psu->getInventoryPath(); |
| 815 | } |
| 816 | else if (supportedConfigs.find(psuModel) != supportedConfigs.end()) |
| 817 | { |
| 818 | // The base model is not supported, but the mismatched PSU is, |
| 819 | // callout the base PSU. |
| 820 | additionalData["EXPECTED_MODEL"] = psuModel; |
| 821 | additionalData["ACTUAL_MODEL"] = model; |
| 822 | additionalData["CALLOUT_INVENTORY_PATH"] = modelInventoryPath; |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | // The base model and the mismatched PSU are not supported or |
| 827 | // could not be found in the supported configuration, callout |
| 828 | // the mismatched PSU. |
| 829 | additionalData["EXPECTED_MODEL"] = model; |
| 830 | additionalData["ACTUAL_MODEL"] = psuModel; |
| 831 | additionalData["CALLOUT_INVENTORY_PATH"] = |
| 832 | psu->getInventoryPath(); |
| 833 | } |
Adriana Kobylak | 523704d | 2021-09-21 15:55:41 +0000 | [diff] [blame] | 834 | model.clear(); |
| 835 | return false; |
| 836 | } |
| 837 | } |
| 838 | return true; |
| 839 | } |
| 840 | |
Adriana Kobylak | c0a0758 | 2021-10-13 15:52:25 +0000 | [diff] [blame] | 841 | void PSUManager::setPowerConfigGPIO() |
| 842 | { |
| 843 | if (!powerConfigGPIO) |
| 844 | { |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | std::string model{}; |
| 849 | std::map<std::string, std::string> additionalData; |
| 850 | if (!validateModelName(model, additionalData)) |
| 851 | { |
| 852 | return; |
| 853 | } |
| 854 | |
| 855 | auto config = supportedConfigs.find(model); |
| 856 | if (config != supportedConfigs.end()) |
| 857 | { |
| 858 | // The power-config-full-load is an open drain GPIO. Set it to low (0) |
| 859 | // if the supported configuration indicates that this system model |
| 860 | // expects the maximum number of power supplies (full load set to true). |
| 861 | // Else, set it to high (1), this is the default. |
| 862 | auto powerConfigValue = |
| 863 | (config->second.powerConfigFullLoad == true ? 0 : 1); |
| 864 | auto flags = gpiod::line_request::FLAG_OPEN_DRAIN; |
| 865 | powerConfigGPIO->write(powerConfigValue, flags); |
| 866 | } |
| 867 | } |
| 868 | |
Adriana Kobylak | e5b1e08 | 2022-03-02 15:37:32 +0000 | [diff] [blame] | 869 | void PSUManager::setBrownout(std::map<std::string, std::string>& additionalData) |
| 870 | { |
| 871 | powerSystemInputs.status(sdbusplus::xyz::openbmc_project::State::Decorator:: |
| 872 | server::PowerSystemInputs::Status::Fault); |
| 873 | if (!brownoutLogged) |
| 874 | { |
| 875 | if (powerOn) |
| 876 | { |
| 877 | createError( |
| 878 | "xyz.openbmc_project.State.Shutdown.Power.Error.Blackout", |
| 879 | additionalData); |
| 880 | brownoutLogged = true; |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | void PSUManager::clearBrownout() |
| 886 | { |
| 887 | powerSystemInputs.status(sdbusplus::xyz::openbmc_project::State::Decorator:: |
| 888 | server::PowerSystemInputs::Status::Good); |
| 889 | brownoutLogged = false; |
| 890 | } |
| 891 | |
Brandon Wyman | 63ea78b | 2020-09-24 16:49:09 -0500 | [diff] [blame] | 892 | } // namespace phosphor::power::manager |