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