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