| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 3 | |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 4 | #include "data_interface.hpp" |
| 5 | |
| Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 6 | #include "util.hpp" |
| 7 | |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 9 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
| Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 10 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 11 | |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 12 | #include <filesystem> |
| 13 | |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 14 | #ifdef PEL_ENABLE_PHAL |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 15 | #include <libekb.H> |
| 16 | #include <libpdbg.h> |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 17 | #include <libphal.H> |
| 18 | #endif |
| 19 | |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 20 | // Use a timeout of 10s for D-Bus calls so if there are |
| 21 | // timeouts the callers of the PEL creation method won't |
| 22 | // also timeout. |
| 23 | constexpr auto dbusTimeout = 10000000; |
| 24 | |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 25 | namespace openpower |
| 26 | { |
| 27 | namespace pels |
| 28 | { |
| 29 | |
| 30 | namespace service_name |
| 31 | { |
| 32 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 33 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 34 | constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager"; |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 35 | constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfigManager"; |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 36 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
| Matt Spinler | 52ee3a4 | 2023-07-27 14:54:48 -0500 | [diff] [blame] | 37 | constexpr auto pldm = "xyz.openbmc_project.PLDM"; |
| Matt Spinler | 412f50e | 2023-11-14 12:49:52 -0600 | [diff] [blame] | 38 | constexpr auto inventoryManager = "xyz.openbmc_project.Inventory.Manager"; |
| Matt Spinler | bbc11ef | 2024-01-11 16:26:51 -0600 | [diff] [blame] | 39 | constexpr auto entityManager = "xyz.openbmc_project.EntityManager"; |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 40 | constexpr auto systemd = "org.freedesktop.systemd1"; |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 41 | } // namespace service_name |
| 42 | |
| 43 | namespace object_path |
| 44 | { |
| 45 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 46 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 47 | constexpr auto motherBoardInv = |
| 48 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 49 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 50 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 51 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 52 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
| Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 53 | constexpr auto enableHostPELs = |
| 54 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 55 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
| Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 56 | constexpr auto logSetting = "/xyz/openbmc_project/logging/settings"; |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 57 | constexpr auto biosConfigMgr = "/xyz/openbmc_project/bios_config/manager"; |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 58 | constexpr auto bootRawProgress = "/xyz/openbmc_project/state/boot/raw0"; |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 59 | constexpr auto systemd = "/org/freedesktop/systemd1"; |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 60 | } // namespace object_path |
| 61 | |
| 62 | namespace interface |
| 63 | { |
| 64 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 65 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 66 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
| Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 67 | constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress"; |
| Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 68 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 69 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 70 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 71 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 72 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
| Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 73 | constexpr auto vsbpRecordVPD = "com.ibm.ipzvpd.VSBP"; |
| Matt Spinler | cc8b111 | 2021-12-15 09:30:35 -0600 | [diff] [blame] | 74 | constexpr auto locCode = "xyz.openbmc_project.Inventory.Decorator.LocationCode"; |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 75 | constexpr auto compatible = |
| Matt Spinler | bbc11ef | 2024-01-11 16:26:51 -0600 | [diff] [blame] | 76 | "xyz.openbmc_project.Inventory.Decorator.Compatible"; |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 77 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 78 | constexpr auto ledGroup = "xyz.openbmc_project.Led.Group"; |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 79 | constexpr auto operationalStatus = |
| 80 | "xyz.openbmc_project.State.Decorator.OperationalStatus"; |
| Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 81 | constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings"; |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 82 | constexpr auto associationDef = "xyz.openbmc_project.Association.Definitions"; |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 83 | constexpr auto hwIsolationEntry = "xyz.openbmc_project.HardwareIsolation.Entry"; |
| 84 | constexpr auto association = "xyz.openbmc_project.Association"; |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 85 | constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfig.Manager"; |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 86 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 87 | constexpr auto invItem = "xyz.openbmc_project.Inventory.Item"; |
| 88 | constexpr auto invFan = "xyz.openbmc_project.Inventory.Item.Fan"; |
| 89 | constexpr auto invPowerSupply = |
| 90 | "xyz.openbmc_project.Inventory.Item.PowerSupply"; |
| Matt Spinler | 412f50e | 2023-11-14 12:49:52 -0600 | [diff] [blame] | 91 | constexpr auto inventoryManager = "xyz.openbmc_project.Inventory.Manager"; |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 92 | constexpr auto systemdMgr = "org.freedesktop.systemd1.Manager"; |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 93 | } // namespace interface |
| 94 | |
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 95 | using namespace sdbusplus::server::xyz::openbmc_project::state::boot; |
| 96 | using namespace sdbusplus::server::xyz::openbmc_project::state; |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 97 | namespace match_rules = sdbusplus::bus::match::rules; |
| 98 | |
| 99 | const DBusInterfaceList hotplugInterfaces{interface::invFan, |
| 100 | interface::invPowerSupply}; |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 101 | static constexpr auto PDBG_DTB_PATH = |
| 102 | "/var/lib/phosphor-software-manager/hostfw/running/DEVTREE"; |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 103 | |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 104 | std::pair<std::string, std::string> |
| 105 | DataInterfaceBase::extractConnectorFromLocCode( |
| 106 | const std::string& locationCode) |
| 107 | { |
| 108 | auto base = locationCode; |
| 109 | std::string connector{}; |
| 110 | |
| 111 | auto pos = base.find("-T"); |
| 112 | if (pos != std::string::npos) |
| 113 | { |
| 114 | connector = base.substr(pos); |
| 115 | base = base.substr(0, pos); |
| 116 | } |
| 117 | |
| 118 | return {base, connector}; |
| 119 | } |
| 120 | |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 121 | DataInterface::DataInterface(sdbusplus::bus_t& bus) : |
| 122 | _bus(bus), _systemdSlot(nullptr) |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 123 | { |
| Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 124 | readBMCFWVersion(); |
| 125 | readServerFWVersion(); |
| Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 126 | readBMCFWVersionID(); |
| Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 127 | |
| Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 128 | // Watch the BootProgress property |
| Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 129 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 130 | bus, object_path::hostState, interface::bootProgress, "BootProgress", |
| 131 | *this, [this](const auto& value) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 132 | this->_bootState = std::get<std::string>(value); |
| 133 | auto status = Progress::convertProgressStagesFromString( |
| 134 | std::get<std::string>(value)); |
| Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 135 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 136 | if ((status == Progress::ProgressStages::SystemInitComplete) || |
| 137 | (status == Progress::ProgressStages::OSRunning)) |
| 138 | { |
| 139 | setHostUp(true); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | setHostUp(false); |
| 144 | } |
| 145 | })); |
| Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 146 | |
| 147 | // Watch the host PEL enable property |
| 148 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 149 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 150 | [this](const auto& value) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 151 | if (std::get<bool>(value) != this->_sendPELsToHost) |
| 152 | { |
| 153 | lg2::info("The send PELs to host setting changed to {VAL}", |
| 154 | "VAL", std::get<bool>(value)); |
| 155 | } |
| 156 | this->_sendPELsToHost = std::get<bool>(value); |
| 157 | })); |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 158 | |
| 159 | // Watch the BMCState property |
| 160 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 161 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 162 | *this, [this](const auto& value) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 163 | const auto& state = std::get<std::string>(value); |
| 164 | this->_bmcState = state; |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 165 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 166 | // Wait for BMC ready to start watching for |
| 167 | // plugs so things calm down first. |
| 168 | if (BMC::convertBMCStateFromString(state) == BMC::BMCState::Ready) |
| 169 | { |
| 170 | startFruPlugWatch(); |
| 171 | } |
| 172 | })); |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 173 | |
| 174 | // Watch the chassis current and requested power state properties |
| 175 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 176 | bus, object_path::chassisState, interface::chassisState, *this, |
| 177 | [this](const auto& properties) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 178 | auto state = properties.find("CurrentPowerState"); |
| 179 | if (state != properties.end()) |
| 180 | { |
| 181 | this->_chassisState = std::get<std::string>(state->second); |
| 182 | } |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 183 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 184 | auto trans = properties.find("RequestedPowerTransition"); |
| 185 | if (trans != properties.end()) |
| 186 | { |
| 187 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 188 | } |
| 189 | })); |
| Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 190 | |
| 191 | // Watch the CurrentHostState property |
| 192 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 193 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 194 | *this, [this](const auto& value) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 195 | this->_hostState = std::get<std::string>(value); |
| 196 | })); |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 197 | |
| 198 | // Watch the BaseBIOSTable property for the hmc managed attribute |
| 199 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 200 | bus, object_path::biosConfigMgr, interface::biosConfigMgr, |
| 201 | "BaseBIOSTable", service_name::biosConfigMgr, *this, |
| 202 | [this](const auto& value) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 203 | const auto& attributes = std::get<BiosAttributes>(value); |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 204 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 205 | auto it = attributes.find("pvm_hmc_managed"); |
| 206 | if (it != attributes.end()) |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 207 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 208 | const auto& currentValVariant = std::get<5>(it->second); |
| 209 | auto currentVal = std::get_if<std::string>(¤tValVariant); |
| 210 | if (currentVal) |
| 211 | { |
| 212 | this->_hmcManaged = |
| 213 | (*currentVal == "Enabled") ? true : false; |
| 214 | } |
| Matt Spinler | 744d851 | 2022-06-08 08:25:47 -0500 | [diff] [blame] | 215 | } |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 216 | })); |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 217 | |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 218 | if (isPHALDevTreeExist()) |
| 219 | { |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 220 | #ifdef PEL_ENABLE_PHAL |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 221 | initPHAL(); |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 222 | #endif |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 223 | } |
| 224 | else |
| 225 | { |
| 226 | // Watch the "openpower-update-bios-attr-table" service to init |
| 227 | // PHAL libraries |
| 228 | subscribeToSystemdSignals(); |
| 229 | } |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 232 | DBusPropertyMap DataInterface::getAllProperties( |
| 233 | const std::string& service, const std::string& objectPath, |
| 234 | const std::string& interface) const |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 235 | { |
| 236 | DBusPropertyMap properties; |
| 237 | |
| 238 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 239 | interface::dbusProperty, "GetAll"); |
| 240 | method.append(interface); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 241 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 242 | |
| 243 | reply.read(properties); |
| 244 | |
| 245 | return properties; |
| 246 | } |
| 247 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 248 | void DataInterface::getProperty( |
| 249 | const std::string& service, const std::string& objectPath, |
| 250 | const std::string& interface, const std::string& property, |
| 251 | DBusValue& value) const |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 252 | { |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 253 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 254 | interface::dbusProperty, "Get"); |
| 255 | method.append(interface, property); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 256 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 257 | |
| 258 | reply.read(value); |
| 259 | } |
| 260 | |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 261 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 262 | { |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 263 | auto method = _bus.new_method_call( |
| 264 | service_name::objectMapper, object_path::objectMapper, |
| 265 | interface::objectMapper, "GetSubTreePaths"); |
| 266 | |
| 267 | method.append(std::string{"/"}, 0, interfaces); |
| 268 | |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 269 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 270 | |
| Patrick Williams | b05e07c | 2025-11-05 00:03:06 -0500 | [diff] [blame^] | 271 | auto paths = reply.unpack<DBusPathList>(); |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 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 | |
| Patrick Williams | b05e07c | 2025-11-05 00:03:06 -0500 | [diff] [blame^] | 287 | auto response = reply.unpack<std::map<DBusService, DBusInterfaceList>>(); |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 288 | |
| 289 | if (!response.empty()) |
| 290 | { |
| 291 | return response.begin()->first; |
| 292 | } |
| 293 | |
| 294 | return std::string{}; |
| 295 | } |
| Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 296 | |
| Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 297 | void DataInterface::readBMCFWVersion() |
| 298 | { |
| Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 299 | _bmcFWVersion = |
| 300 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
| Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void DataInterface::readServerFWVersion() |
| 304 | { |
| Sumit Kumar | cad1620 | 2021-05-13 04:06:15 -0500 | [diff] [blame] | 305 | auto value = |
| 306 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
| 307 | if ((value != "") && (value.find_last_of(')') != std::string::npos)) |
| 308 | { |
| 309 | std::size_t pos = value.find_first_of('(') + 1; |
| 310 | _serverFWVersion = value.substr(pos, value.find_last_of(')') - pos); |
| 311 | } |
| Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 312 | } |
| 313 | |
| Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 314 | void DataInterface::readBMCFWVersionID() |
| 315 | { |
| Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 316 | _bmcFWVersionID = |
| 317 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
| Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 318 | } |
| 319 | |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 320 | std::string DataInterface::getMachineTypeModel() const |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 321 | { |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 322 | std::string model; |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 323 | try |
| 324 | { |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 325 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 326 | if (!service.empty()) |
| 327 | { |
| 328 | DBusValue value; |
| 329 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 330 | "Model", value); |
| 331 | |
| 332 | model = std::get<std::string>(value); |
| 333 | } |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 334 | } |
| 335 | catch (const std::exception& e) |
| 336 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 337 | lg2::warning("Failed reading Model property from " |
| 338 | "interface: {IFACE} exception: {ERROR}", |
| 339 | "IFACE", interface::invAsset, "ERROR", e); |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 340 | } |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 341 | |
| 342 | return model; |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 343 | } |
| 344 | |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 345 | std::string DataInterface::getMachineSerialNumber() const |
| 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 | std::string sn; |
| 348 | try |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 349 | { |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 350 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 351 | if (!service.empty()) |
| 352 | { |
| 353 | DBusValue value; |
| 354 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 355 | "SerialNumber", value); |
| 356 | |
| 357 | sn = std::get<std::string>(value); |
| 358 | } |
| 359 | } |
| 360 | catch (const std::exception& e) |
| 361 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 362 | lg2::warning("Failed reading SerialNumber property from " |
| 363 | "interface: {IFACE} exception: {ERROR}", |
| 364 | "IFACE", interface::invAsset, "ERROR", e); |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 365 | } |
| 366 | |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 367 | return sn; |
| 368 | } |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 369 | |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 370 | std::string DataInterface::getMotherboardCCIN() const |
| 371 | { |
| 372 | std::string ccin; |
| 373 | |
| 374 | try |
| 375 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 376 | auto service = |
| 377 | getService(object_path::motherBoardInv, interface::viniRecordVPD); |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 378 | if (!service.empty()) |
| 379 | { |
| 380 | DBusValue value; |
| 381 | getProperty(service, object_path::motherBoardInv, |
| 382 | interface::viniRecordVPD, "CC", value); |
| 383 | |
| 384 | auto cc = std::get<std::vector<uint8_t>>(value); |
| 385 | ccin = std::string{cc.begin(), cc.end()}; |
| 386 | } |
| 387 | } |
| 388 | catch (const std::exception& e) |
| 389 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 390 | lg2::warning("Failed reading Motherboard CCIN property from " |
| 391 | "interface: {IFACE} exception: {ERROR}", |
| 392 | "IFACE", interface::viniRecordVPD, "ERROR", e); |
| Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | return ccin; |
| Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 396 | } |
| 397 | |
| Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 398 | std::vector<uint8_t> DataInterface::getSystemIMKeyword() const |
| 399 | { |
| 400 | std::vector<uint8_t> systemIM; |
| 401 | |
| 402 | try |
| 403 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 404 | auto service = |
| 405 | getService(object_path::motherBoardInv, interface::vsbpRecordVPD); |
| Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 406 | if (!service.empty()) |
| 407 | { |
| 408 | DBusValue value; |
| 409 | getProperty(service, object_path::motherBoardInv, |
| 410 | interface::vsbpRecordVPD, "IM", value); |
| 411 | |
| 412 | systemIM = std::get<std::vector<uint8_t>>(value); |
| 413 | } |
| 414 | } |
| 415 | catch (const std::exception& e) |
| 416 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 417 | lg2::warning("Failed reading System IM property from " |
| 418 | "interface: {IFACE} exception: {ERROR}", |
| 419 | "IFACE", interface::vsbpRecordVPD, "ERROR", e); |
| Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | return systemIM; |
| 423 | } |
| 424 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 425 | void DataInterface::getHWCalloutFields( |
| 426 | const std::string& inventoryPath, std::string& fruPartNumber, |
| 427 | std::string& ccin, std::string& serialNumber) const |
| Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 428 | { |
| 429 | // For now, attempt to get all of the properties directly on the path |
| 430 | // passed in. In the future, may need to make use of an algorithm |
| 431 | // to figure out which inventory objects actually hold these |
| 432 | // interfaces in the case of non FRUs, or possibly another service |
| 433 | // will provide this info. Any missing interfaces will result |
| 434 | // in exceptions being thrown. |
| 435 | |
| Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 436 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
| Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 437 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 438 | auto properties = |
| 439 | getAllProperties(service, inventoryPath, interface::viniRecordVPD); |
| Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 440 | |
| 441 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 442 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 443 | |
| 444 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 445 | ccin = std::string{value.begin(), value.end()}; |
| 446 | |
| 447 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 448 | serialNumber = std::string{value.begin(), value.end()}; |
| 449 | } |
| 450 | |
| Patrick Williams | 2529115 | 2025-02-01 08:21:42 -0500 | [diff] [blame] | 451 | std::string DataInterface::getLocationCode( |
| 452 | const std::string& inventoryPath) const |
| Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 453 | { |
| 454 | auto service = getService(inventoryPath, interface::locCode); |
| 455 | |
| 456 | DBusValue locCode; |
| 457 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 458 | locCode); |
| 459 | |
| 460 | return std::get<std::string>(locCode); |
| 461 | } |
| 462 | |
| Patrick Williams | 2529115 | 2025-02-01 08:21:42 -0500 | [diff] [blame] | 463 | std::string DataInterface::addLocationCodePrefix( |
| 464 | const std::string& locationCode) |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 465 | { |
| 466 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 467 | |
| Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 468 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 469 | // if it already starts with a U then don't need to do anything. |
| 470 | if (locationCode.front() != 'U') |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 471 | { |
| 472 | return locationCodePrefix + locationCode; |
| 473 | } |
| 474 | |
| 475 | return locationCode; |
| 476 | } |
| 477 | |
| 478 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
| Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 479 | uint16_t /*node*/) const |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 480 | { |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 481 | // Location codes for connectors are the location code of the FRU they are |
| 482 | // on, plus a '-Tx' segment. Remove this last segment before expanding it |
| 483 | // and then add it back in afterwards. This way, the connector doesn't have |
| 484 | // to be in the model just so that it can be expanded. |
| 485 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 486 | |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 487 | auto method = |
| 488 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 489 | interface::vpdManager, "GetExpandedLocationCode"); |
| 490 | |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 491 | method.append(addLocationCodePrefix(baseLoc), static_cast<uint16_t>(0)); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 492 | |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 493 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 494 | |
| Patrick Williams | b05e07c | 2025-11-05 00:03:06 -0500 | [diff] [blame^] | 495 | auto expandedLocationCode = reply.unpack<std::string>(); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 496 | |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 497 | if (!connectorLoc.empty()) |
| 498 | { |
| 499 | expandedLocationCode += connectorLoc; |
| 500 | } |
| 501 | |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 502 | return expandedLocationCode; |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 505 | std::vector<std::string> DataInterface::getInventoryFromLocCode( |
| 506 | const std::string& locationCode, uint16_t node, bool expanded) const |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 507 | { |
| Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 508 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 509 | : "GetFRUsByUnexpandedLocationCode"; |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 510 | |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 511 | // Remove the connector segment, if present, so that this method call |
| 512 | // returns an inventory path that getHWCalloutFields() can be used with. |
| 513 | // (The serial number, etc, aren't stored on the connector in the |
| 514 | // inventory, and may not even be modeled.) |
| 515 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 516 | |
| Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 517 | auto method = |
| 518 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 519 | interface::vpdManager, methodName.c_str()); |
| 520 | |
| 521 | if (expanded) |
| 522 | { |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 523 | method.append(baseLoc); |
| Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 524 | } |
| 525 | else |
| 526 | { |
| Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 527 | method.append(addLocationCodePrefix(baseLoc), node); |
| Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 528 | } |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 529 | |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 530 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 531 | |
| Patrick Williams | b05e07c | 2025-11-05 00:03:06 -0500 | [diff] [blame^] | 532 | auto entries = reply.unpack<std::vector<sdbusplus::message::object_path>>(); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 533 | |
| Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 534 | std::vector<std::string> paths; |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 535 | |
| Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 536 | // Note: The D-Bus method will fail if nothing found. |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 537 | std::for_each(entries.begin(), entries.end(), |
| Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 538 | [&paths](const auto& path) { paths.push_back(path); }); |
| Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 539 | |
| Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 540 | return paths; |
| Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 541 | } |
| 542 | |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 543 | void DataInterface::assertLEDGroup(const std::string& ledGroup, |
| 544 | bool value) const |
| 545 | { |
| 546 | DBusValue variant = value; |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 547 | auto method = |
| 548 | _bus.new_method_call(service_name::ledGroupManager, ledGroup.c_str(), |
| 549 | interface::dbusProperty, "Set"); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 550 | method.append(interface::ledGroup, "Asserted", variant); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 551 | _bus.call(method, dbusTimeout); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 552 | } |
| 553 | |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 554 | void DataInterface::setFunctional(const std::string& objectPath, |
| 555 | bool value) const |
| 556 | { |
| Matt Spinler | 412f50e | 2023-11-14 12:49:52 -0600 | [diff] [blame] | 557 | DBusPropertyMap prop{{"Functional", value}}; |
| 558 | DBusInterfaceMap iface{{interface::operationalStatus, prop}}; |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 559 | |
| Matt Spinler | 412f50e | 2023-11-14 12:49:52 -0600 | [diff] [blame] | 560 | // PIM takes a relative path like /system/chassis so remove |
| 561 | // /xyz/openbmc_project/inventory if present. |
| 562 | std::string path{objectPath}; |
| 563 | if (path.starts_with(object_path::baseInv)) |
| 564 | { |
| 565 | path = objectPath.substr(strlen(object_path::baseInv)); |
| 566 | } |
| 567 | DBusObjectMap object{{path, iface}}; |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 568 | |
| Matt Spinler | 412f50e | 2023-11-14 12:49:52 -0600 | [diff] [blame] | 569 | auto method = _bus.new_method_call(service_name::inventoryManager, |
| 570 | object_path::baseInv, |
| 571 | interface::inventoryManager, "Notify"); |
| 572 | method.append(std::move(object)); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 573 | _bus.call(method, dbusTimeout); |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 574 | } |
| 575 | |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 576 | using AssociationTuple = std::tuple<std::string, std::string, std::string>; |
| 577 | using AssociationsProperty = std::vector<AssociationTuple>; |
| 578 | |
| 579 | void DataInterface::setCriticalAssociation(const std::string& objectPath) const |
| 580 | { |
| 581 | DBusValue getAssociationValue; |
| 582 | |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 583 | auto service = getService(objectPath, interface::associationDef); |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 584 | |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 585 | getProperty(service, objectPath, interface::associationDef, "Associations", |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 586 | getAssociationValue); |
| 587 | |
| 588 | auto association = std::get<AssociationsProperty>(getAssociationValue); |
| 589 | |
| 590 | AssociationTuple critAssociation{ |
| 591 | "health_rollup", "critical", |
| 592 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 593 | |
| 594 | if (std::find(association.begin(), association.end(), critAssociation) == |
| 595 | association.end()) |
| 596 | { |
| 597 | association.push_back(critAssociation); |
| 598 | DBusValue setAssociationValue = association; |
| 599 | |
| 600 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 601 | interface::dbusProperty, "Set"); |
| 602 | |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 603 | method.append(interface::associationDef, "Associations", |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 604 | setAssociationValue); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 605 | _bus.call(method, dbusTimeout); |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 609 | std::vector<std::string> DataInterface::getSystemNames() const |
| 610 | { |
| 611 | DBusSubTree subtree; |
| 612 | DBusValue names; |
| 613 | |
| 614 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 615 | object_path::objectMapper, |
| 616 | interface::objectMapper, "GetSubTree"); |
| 617 | method.append(std::string{"/"}, 0, |
| 618 | std::vector<std::string>{interface::compatible}); |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 619 | auto reply = _bus.call(method, dbusTimeout); |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 620 | |
| 621 | reply.read(subtree); |
| 622 | if (subtree.empty()) |
| 623 | { |
| 624 | throw std::runtime_error("Compatible interface not on D-Bus"); |
| 625 | } |
| 626 | |
| Matt Spinler | bbc11ef | 2024-01-11 16:26:51 -0600 | [diff] [blame] | 627 | for (const auto& [path, interfaceMap] : subtree) |
| 628 | { |
| 629 | auto iface = interfaceMap.find(service_name::entityManager); |
| 630 | if (iface == interfaceMap.end()) |
| 631 | { |
| 632 | continue; |
| 633 | } |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 634 | |
| Matt Spinler | bbc11ef | 2024-01-11 16:26:51 -0600 | [diff] [blame] | 635 | getProperty(iface->first, path, interface::compatible, "Names", names); |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 636 | |
| Matt Spinler | bbc11ef | 2024-01-11 16:26:51 -0600 | [diff] [blame] | 637 | return std::get<std::vector<std::string>>(names); |
| 638 | } |
| 639 | |
| 640 | throw std::runtime_error("EM Compatible interface not on D-Bus"); |
| Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 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 | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 649 | auto service = |
| 650 | getService(object_path::logSetting, 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 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 662 | lg2::warning("Failed reading QuiesceOnHwError property from " |
| 663 | "interface: {IFACE} exception: {ERROR}", |
| 664 | "IFACE", interface::logSetting, "ERROR", e); |
| Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | return ret; |
| 668 | } |
| 669 | |
| Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame] | 670 | #ifdef PEL_ENABLE_PHAL |
| Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 671 | void DataInterface::createGuardRecord(const std::vector<uint8_t>& binPath, |
| Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame] | 672 | GardType eGardType, uint32_t plid) const |
| Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 673 | { |
| 674 | try |
| 675 | { |
| Deepa Karthikeyan | c6396da | 2024-11-14 04:50:25 -0600 | [diff] [blame] | 676 | libguard::libguard_init(false); |
| Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame] | 677 | libguard::create(binPath, plid, eGardType); |
| Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 678 | } |
| Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame] | 679 | catch (libguard::exception::GuardException& e) |
| Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 680 | { |
| Deepa Karthikeyan | c6396da | 2024-11-14 04:50:25 -0600 | [diff] [blame] | 681 | lg2::error("Exception in libguard {ERROR}", "ERROR", e); |
| Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 682 | } |
| 683 | } |
| Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame] | 684 | #endif |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 685 | |
| 686 | void DataInterface::createProgressSRC( |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 687 | const std::vector<uint8_t>& priSRC, |
| 688 | const std::vector<uint8_t>& srcStruct) const |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 689 | { |
| 690 | DBusValue variant = std::make_tuple(priSRC, srcStruct); |
| 691 | |
| 692 | auto method = _bus.new_method_call(service_name::bootRawProgress, |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 693 | object_path::bootRawProgress, |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 694 | interface::dbusProperty, "Set"); |
| 695 | |
| 696 | method.append(interface::bootRawProgress, "Value", variant); |
| 697 | |
| Matt Spinler | 35a405b | 2022-03-02 11:42:42 -0600 | [diff] [blame] | 698 | _bus.call(method, dbusTimeout); |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 699 | } |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 700 | |
| 701 | std::vector<uint32_t> DataInterface::getLogIDWithHwIsolation() const |
| 702 | { |
| 703 | std::vector<std::string> association = {"xyz.openbmc_project.Association"}; |
| 704 | std::string hwErrorLog = "/isolated_hw_errorlog"; |
| 705 | std::string errorLog = "/error_log"; |
| 706 | DBusPathList paths; |
| 707 | std::vector<uint32_t> ids; |
| 708 | |
| 709 | // Get all latest mapper associations |
| 710 | paths = getPaths(association); |
| 711 | for (auto& path : paths) |
| 712 | { |
| 713 | // Look for object path with hardware isolation entry if any |
| 714 | size_t pos = path.find(hwErrorLog); |
| 715 | if (pos != std::string::npos) |
| 716 | { |
| 717 | // Get the object path |
| 718 | std::string ph = path; |
| 719 | ph.erase(pos, hwErrorLog.length()); |
| 720 | auto service = getService(ph, interface::hwIsolationEntry); |
| 721 | if (!service.empty()) |
| 722 | { |
| 723 | bool status; |
| 724 | DBusValue value; |
| 725 | |
| 726 | // Read the Resolved property from object path |
| 727 | getProperty(service, ph, interface::hwIsolationEntry, |
| 728 | "Resolved", value); |
| 729 | |
| 730 | status = std::get<bool>(value); |
| 731 | |
| 732 | // If the entry isn't resolved |
| 733 | if (!status) |
| 734 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 735 | auto assocService = |
| 736 | getService(path, interface::association); |
| Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 737 | if (!assocService.empty()) |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 738 | { |
| Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 739 | DBusValue endpoints; |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 740 | |
| 741 | // Read Endpoints property |
| Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 742 | getProperty(assocService, path, interface::association, |
| 743 | "endpoints", endpoints); |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 744 | |
| 745 | auto logPath = |
| Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 746 | std::get<std::vector<std::string>>(endpoints); |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 747 | if (!logPath.empty()) |
| 748 | { |
| 749 | // Get OpenBMC event log Id |
| 750 | uint32_t id = stoi(logPath[0].substr( |
| 751 | logPath[0].find_last_of('/') + 1)); |
| 752 | ids.push_back(id); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | // Look for object path with error_log entry if any |
| 760 | pos = path.find(errorLog); |
| 761 | if (pos != std::string::npos) |
| 762 | { |
| 763 | auto service = getService(path, interface::association); |
| 764 | if (!service.empty()) |
| 765 | { |
| 766 | DBusValue value; |
| 767 | |
| 768 | // Read Endpoints property |
| 769 | getProperty(service, path, interface::association, "endpoints", |
| 770 | value); |
| 771 | |
| 772 | auto logPath = std::get<std::vector<std::string>>(value); |
| 773 | if (!logPath.empty()) |
| 774 | { |
| 775 | // Get OpenBMC event log Id |
| 776 | uint32_t id = stoi( |
| 777 | logPath[0].substr(logPath[0].find_last_of('/') + 1)); |
| 778 | ids.push_back(id); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if (ids.size() > 1) |
| 785 | { |
| 786 | // remove duplicates to have only unique ids |
| 787 | std::sort(ids.begin(), ids.end()); |
| 788 | ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); |
| 789 | } |
| 790 | return ids; |
| 791 | } |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 792 | |
| 793 | std::vector<uint8_t> DataInterface::getRawProgressSRC(void) const |
| 794 | { |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 795 | using RawProgressProperty = |
| 796 | std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>; |
| Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 797 | |
| 798 | DBusValue value; |
| 799 | getProperty(service_name::bootRawProgress, object_path::bootRawProgress, |
| 800 | interface::bootRawProgress, "Value", value); |
| 801 | |
| 802 | const auto& rawProgress = std::get<RawProgressProperty>(value); |
| 803 | return std::get<1>(rawProgress); |
| 804 | } |
| 805 | |
| Patrick Williams | 2529115 | 2025-02-01 08:21:42 -0500 | [diff] [blame] | 806 | std::optional<std::vector<uint8_t>> DataInterface::getDIProperty( |
| 807 | const std::string& locationCode) const |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 808 | { |
| 809 | std::vector<uint8_t> viniDI; |
| 810 | |
| 811 | try |
| 812 | { |
| 813 | // Note : The hardcoded value 0 should be changed when comes to |
| 814 | // multinode system. |
| 815 | auto objectPath = getInventoryFromLocCode(locationCode, 0, true); |
| 816 | |
| 817 | DBusValue value; |
| 818 | getProperty(service_name::inventoryManager, objectPath[0], |
| 819 | interface::viniRecordVPD, "DI", value); |
| 820 | |
| 821 | viniDI = std::get<std::vector<uint8_t>>(value); |
| 822 | } |
| 823 | catch (const std::exception& e) |
| 824 | { |
| 825 | lg2::warning( |
| 826 | "Failed reading DI property for the location code : {LOC_CODE} from " |
| 827 | "interface: {IFACE} exception: {ERROR}", |
| 828 | "LOC_CODE", locationCode, "IFACE", interface::viniRecordVPD, |
| 829 | "ERROR", e); |
| 830 | return std::nullopt; |
| 831 | } |
| 832 | |
| 833 | return viniDI; |
| 834 | } |
| 835 | |
| Patrick Williams | 2529115 | 2025-02-01 08:21:42 -0500 | [diff] [blame] | 836 | std::optional<bool> DataInterfaceBase::isDIMMLocCode( |
| 837 | const std::string& locCode) const |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 838 | { |
| 839 | if (_locationCache.contains(locCode)) |
| 840 | { |
| 841 | return _locationCache.at(locCode); |
| 842 | } |
| 843 | else |
| 844 | { |
| 845 | return std::nullopt; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | void DataInterfaceBase::addDIMMLocCode(const std::string& locCode, |
| 850 | bool isFRUDIMM) |
| 851 | { |
| 852 | _locationCache.insert({locCode, isFRUDIMM}); |
| 853 | } |
| 854 | |
| Arya K Padman | ced8ed7 | 2024-09-02 05:18:07 -0500 | [diff] [blame] | 855 | bool DataInterfaceBase::isDIMM(const std::string& locCode) |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 856 | { |
| 857 | auto isDIMMType = isDIMMLocCode(locCode); |
| 858 | if (isDIMMType.has_value()) |
| 859 | { |
| 860 | return isDIMMType.value(); |
| 861 | } |
| 862 | #ifndef PEL_ENABLE_PHAL |
| Arya K Padman | ced8ed7 | 2024-09-02 05:18:07 -0500 | [diff] [blame] | 863 | return false; |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 864 | #else |
| 865 | else |
| 866 | { |
| 867 | // Invoke pHAL API inorder to fetch the FRU Type |
| 868 | auto fruType = openpower::phal::pdbg::getFRUType(locCode); |
| Arya K Padman | ced8ed7 | 2024-09-02 05:18:07 -0500 | [diff] [blame] | 869 | bool isDIMMFRU{false}; |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 870 | if (fruType.has_value()) |
| 871 | { |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 872 | if (fruType.value() == ENUM_ATTR_TYPE_DIMM) |
| 873 | { |
| 874 | isDIMMFRU = true; |
| 875 | } |
| 876 | addDIMMLocCode(locCode, isDIMMFRU); |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 877 | } |
| Arya K Padman | ced8ed7 | 2024-09-02 05:18:07 -0500 | [diff] [blame] | 878 | return isDIMMFRU; |
| Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 879 | } |
| 880 | #endif |
| 881 | } |
| 882 | |
| harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 883 | DBusPathList DataInterface::getAssociatedPaths( |
| 884 | const DBusPath& associatedPath, const DBusPath& subtree, int32_t depth, |
| 885 | const DBusInterfaceList& interfaces) const |
| 886 | { |
| 887 | DBusPathList paths; |
| 888 | try |
| 889 | { |
| 890 | auto method = _bus.new_method_call( |
| 891 | service_name::objectMapper, object_path::objectMapper, |
| 892 | interface::objectMapper, "GetAssociatedSubTreePaths"); |
| 893 | method.append(sdbusplus::message::object_path(associatedPath), |
| 894 | sdbusplus::message::object_path(subtree), depth, |
| 895 | interfaces); |
| 896 | |
| 897 | auto reply = _bus.call(method, dbusTimeout); |
| 898 | reply.read(paths); |
| 899 | } |
| 900 | catch (const std::exception& e) |
| 901 | { |
| 902 | std::string ifaces( |
| 903 | std::ranges::fold_left_first( |
| 904 | interfaces, |
| 905 | [](std::string ifaces, const std::string& iface) { |
| 906 | return ifaces + ", " + iface; |
| 907 | }) |
| 908 | .value_or("")); |
| 909 | |
| 910 | lg2::error("Failed getting associated paths: {ERROR}. " |
| 911 | "AssociatedPath: {ASSOIC_PATH} Subtree: {SUBTREE} " |
| 912 | "Interfaces: {IFACES}", |
| 913 | "ERROR", e, "ASSOIC_PATH", associatedPath, "SUBTREE", |
| 914 | subtree, "IFACES", ifaces); |
| 915 | } |
| 916 | return paths; |
| 917 | } |
| 918 | |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 919 | void DataInterface::startFruPlugWatch() |
| 920 | { |
| 921 | // Add a watch on inventory InterfacesAdded and then find all |
| 922 | // existing hotpluggable interfaces and add propertiesChanged |
| 923 | // watches on them. |
| 924 | |
| 925 | _invIaMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 926 | _bus, match_rules::interfacesAdded(object_path::baseInv), |
| 927 | std::bind(&DataInterface::inventoryIfaceAdded, this, |
| 928 | std::placeholders::_1)); |
| 929 | try |
| 930 | { |
| 931 | auto paths = getPaths(hotplugInterfaces); |
| 932 | |
| 933 | _invPresentMatches.clear(); |
| 934 | |
| 935 | std::for_each(paths.begin(), paths.end(), |
| 936 | [this](const auto& path) { addHotplugWatch(path); }); |
| 937 | } |
| 938 | catch (const sdbusplus::exception_t& e) |
| 939 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 940 | lg2::warning("Failed getting FRU paths to watch: {ERROR}", "ERROR", e); |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | void DataInterface::addHotplugWatch(const std::string& path) |
| 945 | { |
| 946 | if (!_invPresentMatches.contains(path)) |
| 947 | { |
| 948 | _invPresentMatches.emplace( |
| 949 | path, |
| 950 | std::make_unique<sdbusplus::bus::match_t>( |
| 951 | _bus, match_rules::propertiesChanged(path, interface::invItem), |
| 952 | std::bind(&DataInterface::presenceChanged, this, |
| 953 | std::placeholders::_1))); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | void DataInterface::inventoryIfaceAdded(sdbusplus::message_t& msg) |
| 958 | { |
| 959 | sdbusplus::message::object_path path; |
| 960 | DBusInterfaceMap interfaces; |
| 961 | |
| 962 | msg.read(path, interfaces); |
| 963 | |
| 964 | // Check if any of the new interfaces are for hot pluggable FRUs. |
| 965 | if (std::find_if(interfaces.begin(), interfaces.end(), |
| 966 | [](const auto& interfacePair) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 967 | return std::find(hotplugInterfaces.begin(), |
| 968 | hotplugInterfaces.end(), |
| 969 | interfacePair.first) != |
| 970 | hotplugInterfaces.end(); |
| 971 | }) == interfaces.end()) |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 972 | { |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | addHotplugWatch(path.str); |
| 977 | |
| 978 | // If an Inventory.Item interface was also added, check presence now. |
| 979 | |
| 980 | // Notes: |
| 981 | // * This assumes the Inv.Item and Inv.Fan/PS are added together which |
| 982 | // is currently the case. |
| 983 | // * If the code ever switches to something without a Present |
| 984 | // property, then the IA signal itself would probably indicate presence. |
| 985 | |
| 986 | auto itemIt = interfaces.find(interface::invItem); |
| 987 | if (itemIt != interfaces.end()) |
| 988 | { |
| 989 | notifyPresenceSubsribers(path.str, itemIt->second); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void DataInterface::presenceChanged(sdbusplus::message_t& msg) |
| 994 | { |
| 995 | DBusInterface interface; |
| 996 | DBusPropertyMap properties; |
| 997 | |
| 998 | msg.read(interface, properties); |
| 999 | if (interface != interface::invItem) |
| 1000 | { |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | std::string path = msg.get_path(); |
| 1005 | notifyPresenceSubsribers(path, properties); |
| 1006 | } |
| 1007 | |
| 1008 | void DataInterface::notifyPresenceSubsribers(const std::string& path, |
| 1009 | const DBusPropertyMap& properties) |
| 1010 | { |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1011 | auto prop = properties.find("Present"); |
| 1012 | if ((prop == properties.end()) || (!std::get<bool>(prop->second))) |
| 1013 | { |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | std::string locCode; |
| 1018 | |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1019 | try |
| 1020 | { |
| Matt Spinler | 52ee3a4 | 2023-07-27 14:54:48 -0500 | [diff] [blame] | 1021 | auto service = getService(path, interface::locCode); |
| 1022 | |
| 1023 | // If the hotplugged FRU is hosted by PLDM, then it is |
| 1024 | // in an IO expansion drawer and we don't care about it. |
| 1025 | if (service == service_name::pldm) |
| 1026 | { |
| 1027 | return; |
| 1028 | } |
| 1029 | |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1030 | locCode = getLocationCode(path); |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1031 | } |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1032 | catch (const sdbusplus::exception_t& e) |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1033 | { |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 1034 | lg2::debug("Could not get location code for {PATH}: {ERROR}", "PATH", |
| 1035 | path, "ERROR", e); |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1036 | return; |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1037 | } |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1038 | |
| Matt Spinler | a167a7d | 2023-06-30 15:14:25 -0500 | [diff] [blame] | 1039 | lg2::debug("Detected FRU {PATH} ({LOC}) present ", "PATH", path, "LOC", |
| 1040 | locCode); |
| Matt Spinler | 5ee3605 | 2023-05-30 14:20:56 -0500 | [diff] [blame] | 1041 | |
| 1042 | // Tell the subscribers. |
| 1043 | setFruPresent(locCode); |
| Matt Spinler | 5b42365 | 2023-05-04 13:08:44 -0500 | [diff] [blame] | 1044 | } |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1045 | |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1046 | bool DataInterface::isPHALDevTreeExist() const |
| 1047 | { |
| 1048 | try |
| 1049 | { |
| 1050 | if (std::filesystem::exists(PDBG_DTB_PATH)) |
| 1051 | { |
| 1052 | return true; |
| 1053 | } |
| 1054 | } |
| 1055 | catch (const std::exception& e) |
| 1056 | { |
| 1057 | lg2::error("Failed to check device tree {PHAL_DEVTREE_PATH} existence, " |
| 1058 | "{ERROR}", |
| 1059 | "PHAL_DEVTREE_PATH", PDBG_DTB_PATH, "ERROR", e); |
| 1060 | } |
| 1061 | return false; |
| 1062 | } |
| 1063 | |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 1064 | #ifdef PEL_ENABLE_PHAL |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1065 | void DataInterface::initPHAL() |
| 1066 | { |
| 1067 | if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1)) |
| 1068 | { |
| 1069 | // Log message and continue, |
| 1070 | // This is to help continue creating PEL in raw format. |
| 1071 | lg2::error("Failed to set PDBG_DTB: ({ERRNO})", "ERRNO", |
| 1072 | strerror(errno)); |
| 1073 | } |
| 1074 | |
| 1075 | if (!pdbg_targets_init(NULL)) |
| 1076 | { |
| 1077 | lg2::error("pdbg_targets_init failed"); |
| 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | if (libekb_init()) |
| 1082 | { |
| 1083 | lg2::error("libekb_init failed, skipping ffdc processing"); |
| 1084 | return; |
| 1085 | } |
| 1086 | } |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 1087 | #endif |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1088 | |
| 1089 | void DataInterface::subscribeToSystemdSignals() |
| 1090 | { |
| 1091 | try |
| 1092 | { |
| 1093 | auto method = |
| 1094 | _bus.new_method_call(service_name::systemd, object_path::systemd, |
| 1095 | interface::systemdMgr, "Subscribe"); |
| 1096 | _systemdSlot = method.call_async([this](sdbusplus::message_t&& msg) { |
| 1097 | // Initializing with nullptr to indicate that it is not subscribed |
| 1098 | // to any signal. |
| 1099 | this->_systemdSlot = sdbusplus::slot_t(nullptr); |
| 1100 | if (msg.is_method_error()) |
| 1101 | { |
| 1102 | auto* error = msg.get_error(); |
| 1103 | lg2::error("Failed to subscribe JobRemoved systemd signal, " |
| Arya K Padman | ea00107 | 2024-09-19 05:00:50 -0500 | [diff] [blame] | 1104 | "errorName: {ERR_NAME}, errorMsg: {ERR_MSG} ", |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 1105 | "ERR_NAME", error->name, "ERR_MSG", error->message); |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 1110 | this->_systemdMatch = |
| 1111 | std::make_unique<decltype(this->_systemdMatch)::element_type>( |
| 1112 | this->_bus, |
| 1113 | sdbusRule::type::signal() + |
| 1114 | sdbusRule::member("JobRemoved") + |
| 1115 | sdbusRule::path(object_path::systemd) + |
| 1116 | sdbusRule::interface(interface::systemdMgr), |
| 1117 | [this](sdbusplus::message_t& msg) { |
| 1118 | uint32_t jobID; |
| 1119 | sdbusplus::message::object_path jobObjPath; |
| 1120 | std::string jobUnitName, jobUnitResult; |
| 1121 | |
| 1122 | msg.read(jobID, jobObjPath, jobUnitName, jobUnitResult); |
| Manish Tiwari | 215121e | 2025-09-24 08:44:39 -0500 | [diff] [blame] | 1123 | if ((jobUnitName == "obmc-recover-pnor.service") && |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1124 | (jobUnitResult == "done")) |
| 1125 | { |
| Arya K Padman | ea00107 | 2024-09-19 05:00:50 -0500 | [diff] [blame] | 1126 | #ifdef PEL_ENABLE_PHAL |
| 1127 | this->initPHAL(); |
| 1128 | #endif |
| 1129 | // Invoke unsubscribe method to stop monitoring for |
| 1130 | // JobRemoved signals. |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1131 | this->unsubscribeFromSystemdSignals(); |
| 1132 | } |
| 1133 | }); |
| 1134 | }); |
| 1135 | } |
| 1136 | catch (const sdbusplus::exception_t& e) |
| 1137 | { |
| 1138 | lg2::error( |
| 1139 | "Exception occured while handling JobRemoved systemd signal, " |
| 1140 | "exception: {ERROR}", |
| 1141 | "ERROR", e); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | void DataInterface::unsubscribeFromSystemdSignals() |
| 1146 | { |
| 1147 | try |
| 1148 | { |
| 1149 | auto method = |
| 1150 | _bus.new_method_call(service_name::systemd, object_path::systemd, |
| 1151 | interface::systemdMgr, "Unsubscribe"); |
| 1152 | _systemdSlot = method.call_async([this](sdbusplus::message_t&& msg) { |
| 1153 | // Unsubscribing the _systemdSlot from the subscribed signal |
| 1154 | this->_systemdSlot = sdbusplus::slot_t(nullptr); |
| 1155 | if (msg.is_method_error()) |
| 1156 | { |
| 1157 | auto* error = msg.get_error(); |
| 1158 | lg2::error( |
| 1159 | "Failed to unsubscribe from JobRemoved systemd signal, " |
| Arya K Padman | ea00107 | 2024-09-19 05:00:50 -0500 | [diff] [blame] | 1160 | "errorName: {ERR_NAME}, errorMsg: {ERR_MSG} ", |
| Arya K Padman | 0b758fb | 2024-09-06 11:59:45 -0500 | [diff] [blame] | 1161 | "ERR_NAME", error->name, "ERR_MSG", error->message); |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1162 | return; |
| 1163 | } |
| Arya K Padman | ea00107 | 2024-09-19 05:00:50 -0500 | [diff] [blame] | 1164 | // Reset _systemdMatch to avoid reception of further JobRemoved |
| 1165 | // signals |
| 1166 | this->_systemdMatch.reset(); |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1167 | }); |
| 1168 | } |
| 1169 | catch (const sdbusplus::exception_t& e) |
| 1170 | { |
| 1171 | lg2::error( |
| 1172 | "Exception occured while unsubscribing from JobRemoved systemd signal, " |
| 1173 | "exception: {ERROR}", |
| 1174 | "ERROR", e); |
| 1175 | } |
| 1176 | } |
| Arya K Padman | afba316 | 2024-08-30 07:41:32 -0500 | [diff] [blame] | 1177 | |
| Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 1178 | } // namespace pels |
| 1179 | } // namespace openpower |