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