Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 18 | #include "data_interface.hpp" |
| 19 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 20 | #include "util.hpp" |
| 21 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 22 | #include <fmt/format.h> |
| 23 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/log.hpp> |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 25 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 26 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 27 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 28 | #include <fstream> |
| 29 | #include <iterator> |
| 30 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 31 | // Use a timeout of 10s for D-Bus calls so if there are |
| 32 | // timeouts the callers of the PEL creation method won't |
| 33 | // also timeout. |
| 34 | constexpr auto dbusTimeout = 10000000; |
| 35 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 36 | namespace openpower |
| 37 | { |
| 38 | namespace pels |
| 39 | { |
| 40 | |
| 41 | namespace service_name |
| 42 | { |
| 43 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 44 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 45 | constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 46 | constexpr auto logSetting = "xyz.openbmc_project.Settings"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 47 | constexpr auto hwIsolation = "org.open_power.HardwareIsolation"; |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 48 | constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfigManager"; |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 49 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 50 | } // namespace service_name |
| 51 | |
| 52 | namespace object_path |
| 53 | { |
| 54 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 55 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 56 | constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis"; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 57 | constexpr auto motherBoardInv = |
| 58 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 59 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 60 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 61 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 62 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 63 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 64 | constexpr auto enableHostPELs = |
| 65 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 66 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 67 | constexpr auto logSetting = "/xyz/openbmc_project/logging/settings"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 68 | constexpr auto hwIsolation = "/xyz/openbmc_project/hardware_isolation"; |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 69 | constexpr auto biosConfigMgr = "/xyz/openbmc_project/bios_config/manager"; |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 70 | constexpr auto bootRawProgress = "/xyz/openbmc_project/state/boot/raw0"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 71 | } // namespace object_path |
| 72 | |
| 73 | namespace interface |
| 74 | { |
| 75 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 76 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 77 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 78 | constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 79 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 80 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 81 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 82 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 83 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 84 | constexpr auto invMotherboard = |
| 85 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; |
| 86 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 87 | constexpr auto vsbpRecordVPD = "com.ibm.ipzvpd.VSBP"; |
Matt Spinler | cc8b111 | 2021-12-15 09:30:35 -0600 | [diff] [blame] | 88 | constexpr auto locCode = "xyz.openbmc_project.Inventory.Decorator.LocationCode"; |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 89 | constexpr auto compatible = |
| 90 | "xyz.openbmc_project.Configuration.IBMCompatibleSystem"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 91 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 92 | constexpr auto ledGroup = "xyz.openbmc_project.Led.Group"; |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 93 | constexpr auto operationalStatus = |
| 94 | "xyz.openbmc_project.State.Decorator.OperationalStatus"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 95 | constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings"; |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 96 | constexpr auto associationDef = "xyz.openbmc_project.Association.Definitions"; |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 97 | constexpr auto dumpEntry = "xyz.openbmc_project.Dump.Entry"; |
| 98 | constexpr auto dumpProgress = "xyz.openbmc_project.Common.Progress"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 99 | constexpr auto hwIsolationCreate = "org.open_power.HardwareIsolation.Create"; |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 100 | constexpr auto hwIsolationEntry = "xyz.openbmc_project.HardwareIsolation.Entry"; |
| 101 | constexpr auto association = "xyz.openbmc_project.Association"; |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 102 | constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfig.Manager"; |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 103 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 104 | constexpr auto invItem = "xyz.openbmc_project.Inventory.Item"; |
| 105 | constexpr auto invFan = "xyz.openbmc_project.Inventory.Item.Fan"; |
| 106 | constexpr auto invPowerSupply = |
| 107 | "xyz.openbmc_project.Inventory.Item.PowerSupply"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 108 | } // namespace interface |
| 109 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 110 | using namespace sdbusplus::xyz::openbmc_project::State::Boot::server; |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 111 | using namespace sdbusplus::xyz::openbmc_project::State::server; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 112 | using namespace phosphor::logging; |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 113 | namespace match_rules = sdbusplus::bus::match::rules; |
| 114 | |
| 115 | const DBusInterfaceList hotplugInterfaces{interface::invFan, |
| 116 | interface::invPowerSupply}; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 117 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 118 | std::pair<std::string, std::string> |
| 119 | DataInterfaceBase::extractConnectorFromLocCode( |
| 120 | const std::string& locationCode) |
| 121 | { |
| 122 | auto base = locationCode; |
| 123 | std::string connector{}; |
| 124 | |
| 125 | auto pos = base.find("-T"); |
| 126 | if (pos != std::string::npos) |
| 127 | { |
| 128 | connector = base.substr(pos); |
| 129 | base = base.substr(0, pos); |
| 130 | } |
| 131 | |
| 132 | return {base, connector}; |
| 133 | } |
| 134 | |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 135 | DataInterface::DataInterface(sdbusplus::bus_t& bus) : _bus(bus) |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 136 | { |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 137 | readBMCFWVersion(); |
| 138 | readServerFWVersion(); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 139 | readBMCFWVersionID(); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 140 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 141 | // Watch the BootProgress property |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 142 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 143 | bus, object_path::hostState, interface::bootProgress, "BootProgress", |
| 144 | *this, [this](const auto& value) { |
Sumit Kumar | 2c36fdd | 2021-09-21 03:12:11 -0500 | [diff] [blame] | 145 | this->_bootState = std::get<std::string>(value); |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 146 | auto status = Progress::convertProgressStagesFromString( |
| 147 | std::get<std::string>(value)); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 148 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 149 | if ((status == Progress::ProgressStages::SystemInitComplete) || |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 150 | (status == Progress::ProgressStages::OSRunning)) |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 151 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 152 | setHostUp(true); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 153 | } |
| 154 | else |
| 155 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 156 | setHostUp(false); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 157 | } |
| 158 | })); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 159 | |
| 160 | // Watch the host PEL enable property |
| 161 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 162 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 163 | [this](const auto& value) { |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 164 | if (std::get<bool>(value) != this->_sendPELsToHost) |
| 165 | { |
| 166 | log<level::INFO>( |
| 167 | fmt::format("The send PELs to host setting changed to {}", |
| 168 | std::get<bool>(value)) |
| 169 | .c_str()); |
| 170 | } |
| 171 | this->_sendPELsToHost = std::get<bool>(value); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 172 | })); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 173 | |
| 174 | // Watch the BMCState property |
| 175 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 176 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 177 | *this, [this](const auto& value) { |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 178 | const auto& state = std::get<std::string>(value); |
| 179 | this->_bmcState = state; |
| 180 | |
| 181 | // Wait for BMC ready to start watching for |
| 182 | // plugs so things calm down first. |
| 183 | if (BMC::convertBMCStateFromString(state) == BMC::BMCState::Ready) |
| 184 | { |
| 185 | startFruPlugWatch(); |
| 186 | } |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 187 | })); |
| 188 | |
| 189 | // Watch the chassis current and requested power state properties |
| 190 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 191 | bus, object_path::chassisState, interface::chassisState, *this, |
| 192 | [this](const auto& properties) { |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 193 | auto state = properties.find("CurrentPowerState"); |
| 194 | if (state != properties.end()) |
| 195 | { |
| 196 | this->_chassisState = std::get<std::string>(state->second); |
| 197 | } |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 198 | |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 199 | auto trans = properties.find("RequestedPowerTransition"); |
| 200 | if (trans != properties.end()) |
| 201 | { |
| 202 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 203 | } |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 204 | })); |
| 205 | |
| 206 | // Watch the CurrentHostState property |
| 207 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 208 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 209 | *this, [this](const auto& value) { |
| 210 | this->_hostState = std::get<std::string>(value); |
| 211 | })); |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 212 | |
| 213 | // Watch the BaseBIOSTable property for the hmc managed attribute |
| 214 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 215 | bus, object_path::biosConfigMgr, interface::biosConfigMgr, |
| 216 | "BaseBIOSTable", service_name::biosConfigMgr, *this, |
| 217 | [this](const auto& value) { |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 218 | const auto& attributes = std::get<BiosAttributes>(value); |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 219 | |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 220 | auto it = attributes.find("pvm_hmc_managed"); |
| 221 | if (it != attributes.end()) |
| 222 | { |
| 223 | const auto& currentValVariant = std::get<5>(it->second); |
| 224 | auto currentVal = std::get_if<std::string>(¤tValVariant); |
| 225 | if (currentVal) |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 226 | { |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 227 | this->_hmcManaged = (*currentVal == "Enabled") ? true : false; |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 228 | } |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 229 | } |
Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 230 | })); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 233 | DBusPropertyMap |
| 234 | DataInterface::getAllProperties(const std::string& service, |
| 235 | const std::string& objectPath, |
| 236 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 237 | { |
| 238 | DBusPropertyMap properties; |
| 239 | |
| 240 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 241 | interface::dbusProperty, "GetAll"); |
| 242 | method.append(interface); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 243 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 244 | |
| 245 | reply.read(properties); |
| 246 | |
| 247 | return properties; |
| 248 | } |
| 249 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 250 | void DataInterface::getProperty(const std::string& service, |
| 251 | const std::string& objectPath, |
| 252 | const std::string& interface, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 253 | const std::string& property, |
| 254 | DBusValue& value) const |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 255 | { |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 256 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 257 | interface::dbusProperty, "Get"); |
| 258 | method.append(interface, property); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 259 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 260 | |
| 261 | reply.read(value); |
| 262 | } |
| 263 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 264 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 265 | { |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 266 | auto method = _bus.new_method_call( |
| 267 | service_name::objectMapper, object_path::objectMapper, |
| 268 | interface::objectMapper, "GetSubTreePaths"); |
| 269 | |
| 270 | method.append(std::string{"/"}, 0, interfaces); |
| 271 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 272 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 273 | |
| 274 | DBusPathList paths; |
| 275 | reply.read(paths); |
| 276 | |
| 277 | return paths; |
| 278 | } |
| 279 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 280 | DBusService DataInterface::getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 281 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 282 | { |
| 283 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 284 | object_path::objectMapper, |
| 285 | interface::objectMapper, "GetObject"); |
| 286 | |
| 287 | method.append(objectPath, std::vector<std::string>({interface})); |
| 288 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 289 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 290 | |
| 291 | std::map<DBusService, DBusInterfaceList> response; |
| 292 | reply.read(response); |
| 293 | |
| 294 | if (!response.empty()) |
| 295 | { |
| 296 | return response.begin()->first; |
| 297 | } |
| 298 | |
| 299 | return std::string{}; |
| 300 | } |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 301 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 302 | void DataInterface::readBMCFWVersion() |
| 303 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 304 | _bmcFWVersion = |
| 305 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void DataInterface::readServerFWVersion() |
| 309 | { |
Sumit Kumar | cad1620 | 2021-05-13 04:06:15 -0500 | [diff] [blame] | 310 | auto value = |
| 311 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
| 312 | if ((value != "") && (value.find_last_of(')') != std::string::npos)) |
| 313 | { |
| 314 | std::size_t pos = value.find_first_of('(') + 1; |
| 315 | _serverFWVersion = value.substr(pos, value.find_last_of(')') - pos); |
| 316 | } |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 317 | } |
| 318 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 319 | void DataInterface::readBMCFWVersionID() |
| 320 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 321 | _bmcFWVersionID = |
| 322 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 323 | } |
| 324 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 325 | std::string DataInterface::getMachineTypeModel() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 326 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 327 | std::string model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 328 | try |
| 329 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 330 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 331 | if (!service.empty()) |
| 332 | { |
| 333 | DBusValue value; |
| 334 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 335 | "Model", value); |
| 336 | |
| 337 | model = std::get<std::string>(value); |
| 338 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 339 | } |
| 340 | catch (const std::exception& e) |
| 341 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 342 | log<level::WARNING>(fmt::format("Failed reading Model property from " |
| 343 | "Interface: {} exception: {}", |
| 344 | interface::invAsset, e.what()) |
| 345 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 346 | } |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 347 | |
| 348 | return model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 349 | } |
| 350 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 351 | std::string DataInterface::getMachineSerialNumber() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 352 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 353 | std::string sn; |
| 354 | try |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 355 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 356 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 357 | if (!service.empty()) |
| 358 | { |
| 359 | DBusValue value; |
| 360 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 361 | "SerialNumber", value); |
| 362 | |
| 363 | sn = std::get<std::string>(value); |
| 364 | } |
| 365 | } |
| 366 | catch (const std::exception& e) |
| 367 | { |
| 368 | log<level::WARNING>( |
| 369 | fmt::format("Failed reading SerialNumber property from " |
| 370 | "Interface: {} exception: {}", |
| 371 | interface::invAsset, e.what()) |
| 372 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 373 | } |
| 374 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 375 | return sn; |
| 376 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 377 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 378 | std::string DataInterface::getMotherboardCCIN() const |
| 379 | { |
| 380 | std::string ccin; |
| 381 | |
| 382 | try |
| 383 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 384 | auto service = getService(object_path::motherBoardInv, |
| 385 | interface::viniRecordVPD); |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 386 | if (!service.empty()) |
| 387 | { |
| 388 | DBusValue value; |
| 389 | getProperty(service, object_path::motherBoardInv, |
| 390 | interface::viniRecordVPD, "CC", value); |
| 391 | |
| 392 | auto cc = std::get<std::vector<uint8_t>>(value); |
| 393 | ccin = std::string{cc.begin(), cc.end()}; |
| 394 | } |
| 395 | } |
| 396 | catch (const std::exception& e) |
| 397 | { |
| 398 | log<level::WARNING>( |
| 399 | fmt::format("Failed reading Motherboard CCIN property from " |
| 400 | "Interface: {} exception: {}", |
| 401 | interface::viniRecordVPD, e.what()) |
| 402 | .c_str()); |
| 403 | } |
| 404 | |
| 405 | return ccin; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 406 | } |
| 407 | |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 408 | std::vector<uint8_t> DataInterface::getSystemIMKeyword() const |
| 409 | { |
| 410 | std::vector<uint8_t> systemIM; |
| 411 | |
| 412 | try |
| 413 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 414 | auto service = getService(object_path::motherBoardInv, |
| 415 | interface::vsbpRecordVPD); |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 416 | if (!service.empty()) |
| 417 | { |
| 418 | DBusValue value; |
| 419 | getProperty(service, object_path::motherBoardInv, |
| 420 | interface::vsbpRecordVPD, "IM", value); |
| 421 | |
| 422 | systemIM = std::get<std::vector<uint8_t>>(value); |
| 423 | } |
| 424 | } |
| 425 | catch (const std::exception& e) |
| 426 | { |
| 427 | log<level::WARNING>( |
| 428 | fmt::format("Failed reading System IM property from " |
| 429 | "Interface: {} exception: {}", |
| 430 | interface::vsbpRecordVPD, e.what()) |
| 431 | .c_str()); |
| 432 | } |
| 433 | |
| 434 | return systemIM; |
| 435 | } |
| 436 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 437 | void DataInterface::getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 438 | std::string& fruPartNumber, |
| 439 | std::string& ccin, |
| 440 | std::string& serialNumber) const |
| 441 | { |
| 442 | // For now, attempt to get all of the properties directly on the path |
| 443 | // passed in. In the future, may need to make use of an algorithm |
| 444 | // to figure out which inventory objects actually hold these |
| 445 | // interfaces in the case of non FRUs, or possibly another service |
| 446 | // will provide this info. Any missing interfaces will result |
| 447 | // in exceptions being thrown. |
| 448 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 449 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 450 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 451 | auto properties = getAllProperties(service, inventoryPath, |
| 452 | interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 453 | |
| 454 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 455 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 456 | |
| 457 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 458 | ccin = std::string{value.begin(), value.end()}; |
| 459 | |
| 460 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 461 | serialNumber = std::string{value.begin(), value.end()}; |
| 462 | } |
| 463 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 464 | std::string |
| 465 | DataInterface::getLocationCode(const std::string& inventoryPath) const |
| 466 | { |
| 467 | auto service = getService(inventoryPath, interface::locCode); |
| 468 | |
| 469 | DBusValue locCode; |
| 470 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 471 | locCode); |
| 472 | |
| 473 | return std::get<std::string>(locCode); |
| 474 | } |
| 475 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 476 | std::string |
| 477 | DataInterface::addLocationCodePrefix(const std::string& locationCode) |
| 478 | { |
| 479 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 480 | |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 481 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 482 | // if it already starts with a U then don't need to do anything. |
| 483 | if (locationCode.front() != 'U') |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 484 | { |
| 485 | return locationCodePrefix + locationCode; |
| 486 | } |
| 487 | |
| 488 | return locationCode; |
| 489 | } |
| 490 | |
| 491 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 492 | uint16_t /*node*/) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 493 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 494 | // Location codes for connectors are the location code of the FRU they are |
| 495 | // on, plus a '-Tx' segment. Remove this last segment before expanding it |
| 496 | // and then add it back in afterwards. This way, the connector doesn't have |
| 497 | // to be in the model just so that it can be expanded. |
| 498 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 499 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 500 | auto method = |
| 501 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 502 | interface::vpdManager, "GetExpandedLocationCode"); |
| 503 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 504 | method.append(addLocationCodePrefix(baseLoc), static_cast<uint16_t>(0)); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 505 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 506 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 507 | |
| 508 | std::string expandedLocationCode; |
| 509 | reply.read(expandedLocationCode); |
| 510 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 511 | if (!connectorLoc.empty()) |
| 512 | { |
| 513 | expandedLocationCode += connectorLoc; |
| 514 | } |
| 515 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 516 | return expandedLocationCode; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 517 | } |
| 518 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 519 | std::vector<std::string> |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 520 | DataInterface::getInventoryFromLocCode(const std::string& locationCode, |
| 521 | uint16_t node, bool expanded) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 522 | { |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 523 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 524 | : "GetFRUsByUnexpandedLocationCode"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 525 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 526 | // Remove the connector segment, if present, so that this method call |
| 527 | // returns an inventory path that getHWCalloutFields() can be used with. |
| 528 | // (The serial number, etc, aren't stored on the connector in the |
| 529 | // inventory, and may not even be modeled.) |
| 530 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 531 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 532 | auto method = |
| 533 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 534 | interface::vpdManager, methodName.c_str()); |
| 535 | |
| 536 | if (expanded) |
| 537 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 538 | method.append(baseLoc); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 539 | } |
| 540 | else |
| 541 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 542 | method.append(addLocationCodePrefix(baseLoc), node); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 543 | } |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 544 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 545 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 546 | |
| 547 | std::vector<sdbusplus::message::object_path> entries; |
| 548 | reply.read(entries); |
| 549 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 550 | std::vector<std::string> paths; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 551 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 552 | // Note: The D-Bus method will fail if nothing found. |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 553 | std::for_each(entries.begin(), entries.end(), |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 554 | [&paths](const auto& path) { paths.push_back(path); }); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 555 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 556 | return paths; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 557 | } |
| 558 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 559 | void DataInterface::assertLEDGroup(const std::string& ledGroup, |
| 560 | bool value) const |
| 561 | { |
| 562 | DBusValue variant = value; |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 563 | auto method = _bus.new_method_call(service_name::ledGroupManager, |
| 564 | ledGroup.c_str(), |
| 565 | interface::dbusProperty, "Set"); |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 566 | method.append(interface::ledGroup, "Asserted", variant); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 567 | _bus.call(method, dbusTimeout); |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 568 | } |
| 569 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 570 | void DataInterface::setFunctional(const std::string& objectPath, |
| 571 | bool value) const |
| 572 | { |
| 573 | DBusValue variant = value; |
| 574 | auto service = getService(objectPath, interface::operationalStatus); |
| 575 | |
| 576 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 577 | interface::dbusProperty, "Set"); |
| 578 | |
| 579 | method.append(interface::operationalStatus, "Functional", variant); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 580 | _bus.call(method, dbusTimeout); |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 581 | } |
| 582 | |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 583 | using AssociationTuple = std::tuple<std::string, std::string, std::string>; |
| 584 | using AssociationsProperty = std::vector<AssociationTuple>; |
| 585 | |
| 586 | void DataInterface::setCriticalAssociation(const std::string& objectPath) const |
| 587 | { |
| 588 | DBusValue getAssociationValue; |
| 589 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 590 | auto service = getService(objectPath, interface::associationDef); |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 591 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 592 | getProperty(service, objectPath, interface::associationDef, "Associations", |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 593 | getAssociationValue); |
| 594 | |
| 595 | auto association = std::get<AssociationsProperty>(getAssociationValue); |
| 596 | |
| 597 | AssociationTuple critAssociation{ |
| 598 | "health_rollup", "critical", |
| 599 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 600 | |
| 601 | if (std::find(association.begin(), association.end(), critAssociation) == |
| 602 | association.end()) |
| 603 | { |
| 604 | association.push_back(critAssociation); |
| 605 | DBusValue setAssociationValue = association; |
| 606 | |
| 607 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 608 | interface::dbusProperty, "Set"); |
| 609 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 610 | method.append(interface::associationDef, "Associations", |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 611 | setAssociationValue); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 612 | _bus.call(method, dbusTimeout); |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 616 | std::vector<std::string> DataInterface::getSystemNames() const |
| 617 | { |
| 618 | DBusSubTree subtree; |
| 619 | DBusValue names; |
| 620 | |
| 621 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 622 | object_path::objectMapper, |
| 623 | interface::objectMapper, "GetSubTree"); |
| 624 | method.append(std::string{"/"}, 0, |
| 625 | std::vector<std::string>{interface::compatible}); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 626 | auto reply = _bus.call(method, dbusTimeout); |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 627 | |
| 628 | reply.read(subtree); |
| 629 | if (subtree.empty()) |
| 630 | { |
| 631 | throw std::runtime_error("Compatible interface not on D-Bus"); |
| 632 | } |
| 633 | |
| 634 | const auto& object = *(subtree.begin()); |
| 635 | const auto& path = object.first; |
| 636 | const auto& service = object.second.begin()->first; |
| 637 | |
| 638 | getProperty(service, path, interface::compatible, "Names", names); |
| 639 | |
| 640 | return std::get<std::vector<std::string>>(names); |
| 641 | } |
| 642 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 643 | bool DataInterface::getQuiesceOnError() const |
| 644 | { |
| 645 | bool ret = false; |
| 646 | |
| 647 | try |
| 648 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 649 | auto service = getService(object_path::logSetting, |
| 650 | interface::logSetting); |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 651 | if (!service.empty()) |
| 652 | { |
| 653 | DBusValue value; |
| 654 | getProperty(service, object_path::logSetting, interface::logSetting, |
| 655 | "QuiesceOnHwError", value); |
| 656 | |
| 657 | ret = std::get<bool>(value); |
| 658 | } |
| 659 | } |
| 660 | catch (const std::exception& e) |
| 661 | { |
| 662 | log<level::WARNING>( |
| 663 | fmt::format("Failed reading QuiesceOnHwError property from " |
| 664 | "Interface: {} exception: {}", |
| 665 | interface::logSetting, e.what()) |
| 666 | .c_str()); |
| 667 | } |
| 668 | |
| 669 | return ret; |
| 670 | } |
| 671 | |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 672 | std::vector<bool> |
| 673 | DataInterface::checkDumpStatus(const std::vector<std::string>& type) const |
| 674 | { |
| 675 | DBusSubTree subtree; |
| 676 | std::vector<bool> result(type.size(), false); |
| 677 | |
| 678 | // Query GetSubTree for the availability of dump interface |
| 679 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 680 | object_path::objectMapper, |
| 681 | interface::objectMapper, "GetSubTree"); |
| 682 | method.append(std::string{"/"}, 0, |
| 683 | std::vector<std::string>{interface::dumpEntry}); |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 684 | auto reply = _bus.call(method, dbusTimeout); |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 685 | |
| 686 | reply.read(subtree); |
| 687 | |
| 688 | if (subtree.empty()) |
| 689 | { |
| 690 | return result; |
| 691 | } |
| 692 | |
| 693 | std::vector<bool>::iterator itDumpStatus = result.begin(); |
| 694 | uint8_t count = 0; |
| 695 | for (const auto& [path, serviceInfo] : subtree) |
| 696 | { |
| 697 | const auto& service = serviceInfo.begin()->first; |
| 698 | // Check for dump type on the object path |
| 699 | for (const auto& it : type) |
| 700 | { |
| 701 | if (path.find(it) != std::string::npos) |
| 702 | { |
| 703 | DBusValue value, progress; |
| 704 | |
| 705 | // If dump type status is already available go for next path |
| 706 | if (*itDumpStatus) |
| 707 | { |
| 708 | break; |
| 709 | } |
| 710 | |
| 711 | // Check for valid dump to be available if following |
| 712 | // conditions are met for the dump entry path - |
| 713 | // Offloaded == false and Status == Completed |
| 714 | getProperty(service, path, interface::dumpEntry, "Offloaded", |
| 715 | value); |
| 716 | getProperty(service, path, interface::dumpProgress, "Status", |
| 717 | progress); |
| 718 | auto offload = std::get<bool>(value); |
| 719 | auto status = std::get<std::string>(progress); |
| 720 | if (!offload && (status.find("Completed") != std::string::npos)) |
| 721 | { |
| 722 | *itDumpStatus = true; |
| 723 | count++; |
| 724 | if (count >= type.size()) |
| 725 | { |
| 726 | return result; |
| 727 | } |
| 728 | break; |
| 729 | } |
| 730 | } |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 731 | ++itDumpStatus; |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 732 | } |
| 733 | itDumpStatus = result.begin(); |
| 734 | } |
| 735 | |
| 736 | return result; |
| 737 | } |
| 738 | |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 739 | void DataInterface::createGuardRecord(const std::vector<uint8_t>& binPath, |
| 740 | const std::string& type, |
| 741 | const std::string& logPath) const |
| 742 | { |
| 743 | try |
| 744 | { |
| 745 | auto method = _bus.new_method_call( |
| 746 | service_name::hwIsolation, object_path::hwIsolation, |
| 747 | interface::hwIsolationCreate, "CreateWithEntityPath"); |
| 748 | method.append(binPath, type, sdbusplus::message::object_path(logPath)); |
| 749 | // Note: hw isolation "CreateWithEntityPath" got dependency on logging |
| 750 | // api's. Making d-bus call no reply type to avoid cyclic dependency. |
| 751 | // Added minimal timeout to catch initial failures. |
| 752 | // Need to revisit this design later to avoid cyclic dependency. |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 753 | constexpr auto hwIsolationTimeout = 100000; // in micro seconds |
| 754 | _bus.call_noreply(method, hwIsolationTimeout); |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 755 | } |
| 756 | |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 757 | catch (const sdbusplus::exception_t& e) |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 758 | { |
| 759 | std::string errName = e.name(); |
| 760 | // SD_BUS_ERROR_TIMEOUT error is expected, due to PEL api dependency |
| 761 | // mentioned above. Ignoring the error. |
| 762 | if (errName != SD_BUS_ERROR_TIMEOUT) |
| 763 | { |
| 764 | log<level::ERR>( |
| 765 | fmt::format("GUARD D-Bus call exception" |
| 766 | "OBJPATH={}, INTERFACE={}, EXCEPTION={}", |
| 767 | object_path::hwIsolation, |
| 768 | interface::hwIsolationCreate, e.what()) |
| 769 | .c_str()); |
| 770 | } |
| 771 | } |
| 772 | } |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 773 | |
| 774 | void DataInterface::createProgressSRC( |
| 775 | const uint64_t& priSRC, const std::vector<uint8_t>& srcStruct) const |
| 776 | { |
| 777 | DBusValue variant = std::make_tuple(priSRC, srcStruct); |
| 778 | |
| 779 | auto method = _bus.new_method_call(service_name::bootRawProgress, |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 780 | object_path::bootRawProgress, |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 781 | interface::dbusProperty, "Set"); |
| 782 | |
| 783 | method.append(interface::bootRawProgress, "Value", variant); |
| 784 | |
Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 785 | _bus.call(method, dbusTimeout); |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 786 | } |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 787 | |
| 788 | std::vector<uint32_t> DataInterface::getLogIDWithHwIsolation() const |
| 789 | { |
| 790 | std::vector<std::string> association = {"xyz.openbmc_project.Association"}; |
| 791 | std::string hwErrorLog = "/isolated_hw_errorlog"; |
| 792 | std::string errorLog = "/error_log"; |
| 793 | DBusPathList paths; |
| 794 | std::vector<uint32_t> ids; |
| 795 | |
| 796 | // Get all latest mapper associations |
| 797 | paths = getPaths(association); |
| 798 | for (auto& path : paths) |
| 799 | { |
| 800 | // Look for object path with hardware isolation entry if any |
| 801 | size_t pos = path.find(hwErrorLog); |
| 802 | if (pos != std::string::npos) |
| 803 | { |
| 804 | // Get the object path |
| 805 | std::string ph = path; |
| 806 | ph.erase(pos, hwErrorLog.length()); |
| 807 | auto service = getService(ph, interface::hwIsolationEntry); |
| 808 | if (!service.empty()) |
| 809 | { |
| 810 | bool status; |
| 811 | DBusValue value; |
| 812 | |
| 813 | // Read the Resolved property from object path |
| 814 | getProperty(service, ph, interface::hwIsolationEntry, |
| 815 | "Resolved", value); |
| 816 | |
| 817 | status = std::get<bool>(value); |
| 818 | |
| 819 | // If the entry isn't resolved |
| 820 | if (!status) |
| 821 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 822 | auto assocService = getService(path, |
| 823 | interface::association); |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 824 | if (!assocService.empty()) |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 825 | { |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 826 | DBusValue endpoints; |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 827 | |
| 828 | // Read Endpoints property |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 829 | getProperty(assocService, path, interface::association, |
| 830 | "endpoints", endpoints); |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 831 | |
| 832 | auto logPath = |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 833 | std::get<std::vector<std::string>>(endpoints); |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 834 | if (!logPath.empty()) |
| 835 | { |
| 836 | // Get OpenBMC event log Id |
| 837 | uint32_t id = stoi(logPath[0].substr( |
| 838 | logPath[0].find_last_of('/') + 1)); |
| 839 | ids.push_back(id); |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | // Look for object path with error_log entry if any |
| 847 | pos = path.find(errorLog); |
| 848 | if (pos != std::string::npos) |
| 849 | { |
| 850 | auto service = getService(path, interface::association); |
| 851 | if (!service.empty()) |
| 852 | { |
| 853 | DBusValue value; |
| 854 | |
| 855 | // Read Endpoints property |
| 856 | getProperty(service, path, interface::association, "endpoints", |
| 857 | value); |
| 858 | |
| 859 | auto logPath = std::get<std::vector<std::string>>(value); |
| 860 | if (!logPath.empty()) |
| 861 | { |
| 862 | // Get OpenBMC event log Id |
| 863 | uint32_t id = stoi( |
| 864 | logPath[0].substr(logPath[0].find_last_of('/') + 1)); |
| 865 | ids.push_back(id); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | if (ids.size() > 1) |
| 872 | { |
| 873 | // remove duplicates to have only unique ids |
| 874 | std::sort(ids.begin(), ids.end()); |
| 875 | ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); |
| 876 | } |
| 877 | return ids; |
| 878 | } |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 879 | |
| 880 | std::vector<uint8_t> DataInterface::getRawProgressSRC(void) const |
| 881 | { |
| 882 | using RawProgressProperty = std::tuple<uint64_t, std::vector<uint8_t>>; |
| 883 | |
| 884 | DBusValue value; |
| 885 | getProperty(service_name::bootRawProgress, object_path::bootRawProgress, |
| 886 | interface::bootRawProgress, "Value", value); |
| 887 | |
| 888 | const auto& rawProgress = std::get<RawProgressProperty>(value); |
| 889 | return std::get<1>(rawProgress); |
| 890 | } |
| 891 | |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 892 | void DataInterface::startFruPlugWatch() |
| 893 | { |
| 894 | // Add a watch on inventory InterfacesAdded and then find all |
| 895 | // existing hotpluggable interfaces and add propertiesChanged |
| 896 | // watches on them. |
| 897 | |
| 898 | _invIaMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 899 | _bus, match_rules::interfacesAdded(object_path::baseInv), |
| 900 | std::bind(&DataInterface::inventoryIfaceAdded, this, |
| 901 | std::placeholders::_1)); |
| 902 | try |
| 903 | { |
| 904 | auto paths = getPaths(hotplugInterfaces); |
| 905 | |
| 906 | _invPresentMatches.clear(); |
| 907 | |
| 908 | std::for_each(paths.begin(), paths.end(), |
| 909 | [this](const auto& path) { addHotplugWatch(path); }); |
| 910 | } |
| 911 | catch (const sdbusplus::exception_t& e) |
| 912 | { |
| 913 | log<level::WARNING>( |
| 914 | fmt::format("Failed getting FRU paths to watch: {}", e.what()) |
| 915 | .c_str()); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | void DataInterface::addHotplugWatch(const std::string& path) |
| 920 | { |
| 921 | if (!_invPresentMatches.contains(path)) |
| 922 | { |
| 923 | _invPresentMatches.emplace( |
| 924 | path, |
| 925 | std::make_unique<sdbusplus::bus::match_t>( |
| 926 | _bus, match_rules::propertiesChanged(path, interface::invItem), |
| 927 | std::bind(&DataInterface::presenceChanged, this, |
| 928 | std::placeholders::_1))); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | void DataInterface::inventoryIfaceAdded(sdbusplus::message_t& msg) |
| 933 | { |
| 934 | sdbusplus::message::object_path path; |
| 935 | DBusInterfaceMap interfaces; |
| 936 | |
| 937 | msg.read(path, interfaces); |
| 938 | |
| 939 | // Check if any of the new interfaces are for hot pluggable FRUs. |
| 940 | if (std::find_if(interfaces.begin(), interfaces.end(), |
| 941 | [](const auto& interfacePair) { |
| 942 | return std::find(hotplugInterfaces.begin(), hotplugInterfaces.end(), |
| 943 | interfacePair.first) != hotplugInterfaces.end(); |
| 944 | }) == interfaces.end()) |
| 945 | { |
| 946 | return; |
| 947 | } |
| 948 | |
| 949 | addHotplugWatch(path.str); |
| 950 | |
| 951 | // If an Inventory.Item interface was also added, check presence now. |
| 952 | |
| 953 | // Notes: |
| 954 | // * This assumes the Inv.Item and Inv.Fan/PS are added together which |
| 955 | // is currently the case. |
| 956 | // * If the code ever switches to something without a Present |
| 957 | // property, then the IA signal itself would probably indicate presence. |
| 958 | |
| 959 | auto itemIt = interfaces.find(interface::invItem); |
| 960 | if (itemIt != interfaces.end()) |
| 961 | { |
| 962 | notifyPresenceSubsribers(path.str, itemIt->second); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | void DataInterface::presenceChanged(sdbusplus::message_t& msg) |
| 967 | { |
| 968 | DBusInterface interface; |
| 969 | DBusPropertyMap properties; |
| 970 | |
| 971 | msg.read(interface, properties); |
| 972 | if (interface != interface::invItem) |
| 973 | { |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | std::string path = msg.get_path(); |
| 978 | notifyPresenceSubsribers(path, properties); |
| 979 | } |
| 980 | |
| 981 | void DataInterface::notifyPresenceSubsribers(const std::string& path, |
| 982 | const DBusPropertyMap& properties) |
| 983 | { |
Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 984 | auto prop = properties.find("Present"); |
| 985 | if ((prop == properties.end()) || (!std::get<bool>(prop->second))) |
| 986 | { |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | std::string locCode; |
| 991 | |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 992 | try |
| 993 | { |
Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 994 | locCode = getLocationCode(path); |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 995 | } |
Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 996 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 997 | { |
Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 998 | log<level::DEBUG>(fmt::format("Could not get location code for {}: {}", |
| 999 | path, e.what()) |
| 1000 | .c_str()); |
| 1001 | return; |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1002 | } |
Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1003 | |
| 1004 | log<level::DEBUG>( |
| 1005 | fmt::format("Detected FRU {} ({}) present ", path, locCode).c_str()); |
| 1006 | |
| 1007 | // Tell the subscribers. |
| 1008 | setFruPresent(locCode); |
Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1009 | } |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 1010 | } // namespace pels |
| 1011 | } // namespace openpower |