blob: 4a91fd094f05c8d8b6d988daf48410a86f6f8df8 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
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 Spinlercad9c2b2019-12-02 15:42:01 -060016#include "config.h"
17
Matt Spinlerc8705e22019-09-11 12:36:07 -050018#include "data_interface.hpp"
19
Matt Spinlerf61f2922020-06-23 11:32:49 -050020#include "util.hpp"
21
Vijay Lobo81b4dca2021-04-29 00:04:00 -050022#include <fmt/format.h>
23
Vijay Lobo81b4dca2021-04-29 00:04:00 -050024#include <phosphor-logging/log.hpp>
Matt Spinlerf10068d2020-12-02 10:44:08 -060025#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
Matt Spinlera7d9d962019-11-06 15:01:25 -060026
Patrick Williams2544b412022-10-04 08:41:06 -050027#include <fstream>
28#include <iterator>
29
Matt Spinler35a405b2022-03-02 11:42:42 -060030// Use a timeout of 10s for D-Bus calls so if there are
31// timeouts the callers of the PEL creation method won't
32// also timeout.
33constexpr auto dbusTimeout = 10000000;
34
Matt Spinlerc8705e22019-09-11 12:36:07 -050035namespace openpower
36{
37namespace pels
38{
39
40namespace service_name
41{
42constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper";
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -050043constexpr auto vpdManager = "com.ibm.VPD.Manager";
Matt Spinler34a904c2020-08-05 14:53:28 -050044constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager";
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -050045constexpr auto logSetting = "xyz.openbmc_project.Settings";
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -050046constexpr auto hwIsolation = "org.open_power.HardwareIsolation";
Matt Spinler744d8512022-06-08 08:25:47 -050047constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfigManager";
Vijay Lobo875b6c72021-10-20 17:38:56 -050048constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw";
Matt Spinlerc8705e22019-09-11 12:36:07 -050049} // namespace service_name
50
51namespace object_path
52{
53constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper";
54constexpr auto systemInv = "/xyz/openbmc_project/inventory/system";
Matt Spinler6ea4d5f2020-05-20 13:31:07 -050055constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis";
Vijay Lobo81b4dca2021-04-29 00:04:00 -050056constexpr auto motherBoardInv =
57 "/xyz/openbmc_project/inventory/system/chassis/motherboard";
Matt Spinlerb3d488f2020-02-21 15:30:46 -060058constexpr auto baseInv = "/xyz/openbmc_project/inventory";
Matt Spinler4aa23a12020-02-03 15:05:09 -060059constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0";
60constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0";
Matt Spinlera7d9d962019-11-06 15:01:25 -060061constexpr auto hostState = "/xyz/openbmc_project/state/host0";
Matt Spinlerb3f51862019-12-09 13:55:10 -060062constexpr auto pldm = "/xyz/openbmc_project/pldm";
Matt Spinler9cf3cfd2020-02-03 14:41:55 -060063constexpr auto enableHostPELs =
64 "/xyz/openbmc_project/logging/send_event_logs_to_host";
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -050065constexpr auto vpdManager = "/com/ibm/VPD/Manager";
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -050066constexpr auto logSetting = "/xyz/openbmc_project/logging/settings";
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -050067constexpr auto hwIsolation = "/xyz/openbmc_project/hardware_isolation";
Matt Spinler744d8512022-06-08 08:25:47 -050068constexpr auto biosConfigMgr = "/xyz/openbmc_project/bios_config/manager";
Vijay Lobo875b6c72021-10-20 17:38:56 -050069constexpr auto bootRawProgress = "/xyz/openbmc_project/state/boot/raw0";
Matt Spinlerc8705e22019-09-11 12:36:07 -050070} // namespace object_path
71
72namespace interface
73{
74constexpr auto dbusProperty = "org.freedesktop.DBus.Properties";
75constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper";
76constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset";
Matt Spinlerf10068d2020-12-02 10:44:08 -060077constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress";
Matt Spinlerb3f51862019-12-09 13:55:10 -060078constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester";
Matt Spinler9cf3cfd2020-02-03 14:41:55 -060079constexpr auto enable = "xyz.openbmc_project.Object.Enable";
Matt Spinler4aa23a12020-02-03 15:05:09 -060080constexpr auto bmcState = "xyz.openbmc_project.State.BMC";
81constexpr auto chassisState = "xyz.openbmc_project.State.Chassis";
82constexpr auto hostState = "xyz.openbmc_project.State.Host";
Matt Spinlerb3d488f2020-02-21 15:30:46 -060083constexpr auto invMotherboard =
84 "xyz.openbmc_project.Inventory.Item.Board.Motherboard";
85constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI";
Ben Tynere32b7e72021-05-18 12:38:40 -050086constexpr auto vsbpRecordVPD = "com.ibm.ipzvpd.VSBP";
Matt Spinlercc8b1112021-12-15 09:30:35 -060087constexpr auto locCode = "xyz.openbmc_project.Inventory.Decorator.LocationCode";
Matt Spinler1ab66962020-10-29 13:21:44 -050088constexpr auto compatible =
89 "xyz.openbmc_project.Configuration.IBMCompatibleSystem";
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -050090constexpr auto vpdManager = "com.ibm.VPD.Manager";
Matt Spinler34a904c2020-08-05 14:53:28 -050091constexpr auto ledGroup = "xyz.openbmc_project.Led.Group";
Matt Spinler993168d2021-04-07 16:05:03 -050092constexpr auto operationalStatus =
93 "xyz.openbmc_project.State.Decorator.OperationalStatus";
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -050094constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings";
Sumit Kumar027bf282022-01-24 11:25:19 -060095constexpr auto associationDef = "xyz.openbmc_project.Association.Definitions";
Sumit Kumar9d43a722021-08-24 09:46:19 -050096constexpr auto dumpEntry = "xyz.openbmc_project.Dump.Entry";
97constexpr auto dumpProgress = "xyz.openbmc_project.Common.Progress";
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -050098constexpr auto hwIsolationCreate = "org.open_power.HardwareIsolation.Create";
Sumit Kumar027bf282022-01-24 11:25:19 -060099constexpr auto hwIsolationEntry = "xyz.openbmc_project.HardwareIsolation.Entry";
100constexpr auto association = "xyz.openbmc_project.Association";
Matt Spinler744d8512022-06-08 08:25:47 -0500101constexpr auto biosConfigMgr = "xyz.openbmc_project.BIOSConfig.Manager";
Vijay Lobo875b6c72021-10-20 17:38:56 -0500102constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw";
Matt Spinlerc8705e22019-09-11 12:36:07 -0500103} // namespace interface
104
Matt Spinlerf10068d2020-12-02 10:44:08 -0600105using namespace sdbusplus::xyz::openbmc_project::State::Boot::server;
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500106using namespace phosphor::logging;
Matt Spinlera7d9d962019-11-06 15:01:25 -0600107
Matt Spinler0d92b522021-06-16 13:28:17 -0600108std::pair<std::string, std::string>
109 DataInterfaceBase::extractConnectorFromLocCode(
110 const std::string& locationCode)
111{
112 auto base = locationCode;
113 std::string connector{};
114
115 auto pos = base.find("-T");
116 if (pos != std::string::npos)
117 {
118 connector = base.substr(pos);
119 base = base.substr(0, pos);
120 }
121
122 return {base, connector};
123}
124
Patrick Williams45e83522022-07-22 19:26:52 -0500125DataInterface::DataInterface(sdbusplus::bus_t& bus) : _bus(bus)
Matt Spinlerc8705e22019-09-11 12:36:07 -0500126{
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600127 readBMCFWVersion();
128 readServerFWVersion();
Matt Spinler677381b2020-01-23 10:04:29 -0600129 readBMCFWVersionID();
Matt Spinler2a28c932020-02-03 14:23:40 -0600130
Matt Spinlerf10068d2020-12-02 10:44:08 -0600131 // Watch the BootProgress property
Matt Spinler2a28c932020-02-03 14:23:40 -0600132 _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
Matt Spinlerf10068d2020-12-02 10:44:08 -0600133 bus, object_path::hostState, interface::bootProgress, "BootProgress",
134 *this, [this](const auto& value) {
Sumit Kumar2c36fdd2021-09-21 03:12:11 -0500135 this->_bootState = std::get<std::string>(value);
Matt Spinlerf10068d2020-12-02 10:44:08 -0600136 auto status = Progress::convertProgressStagesFromString(
137 std::get<std::string>(value));
Matt Spinler2a28c932020-02-03 14:23:40 -0600138
Matt Spinlerf10068d2020-12-02 10:44:08 -0600139 if ((status == Progress::ProgressStages::SystemInitComplete) ||
Matt Spinlerf10068d2020-12-02 10:44:08 -0600140 (status == Progress::ProgressStages::OSRunning))
Matt Spinler2a28c932020-02-03 14:23:40 -0600141 {
Matt Spinler4aa23a12020-02-03 15:05:09 -0600142 setHostUp(true);
Matt Spinler2a28c932020-02-03 14:23:40 -0600143 }
144 else
145 {
Matt Spinler4aa23a12020-02-03 15:05:09 -0600146 setHostUp(false);
Matt Spinler2a28c932020-02-03 14:23:40 -0600147 }
148 }));
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600149
150 // Watch the host PEL enable property
151 _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
152 bus, object_path::enableHostPELs, interface::enable, "Enabled", *this,
153 [this](const auto& value) {
Matt Spinlerc6ee7c52022-01-14 13:21:53 -0600154 if (std::get<bool>(value) != this->_sendPELsToHost)
155 {
156 log<level::INFO>(
157 fmt::format("The send PELs to host setting changed to {}",
158 std::get<bool>(value))
159 .c_str());
160 }
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600161 this->_sendPELsToHost = std::get<bool>(value);
162 }));
Matt Spinler4aa23a12020-02-03 15:05:09 -0600163
164 // Watch the BMCState property
165 _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
166 bus, object_path::bmcState, interface::bmcState, "CurrentBMCState",
167 *this, [this](const auto& value) {
168 this->_bmcState = std::get<std::string>(value);
169 }));
170
171 // Watch the chassis current and requested power state properties
172 _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>(
173 bus, object_path::chassisState, interface::chassisState, *this,
174 [this](const auto& properties) {
175 auto state = properties.find("CurrentPowerState");
176 if (state != properties.end())
177 {
178 this->_chassisState = std::get<std::string>(state->second);
179 }
180
181 auto trans = properties.find("RequestedPowerTransition");
182 if (trans != properties.end())
183 {
184 this->_chassisTransition = std::get<std::string>(trans->second);
185 }
186 }));
187
188 // Watch the CurrentHostState property
189 _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
190 bus, object_path::hostState, interface::hostState, "CurrentHostState",
191 *this, [this](const auto& value) {
192 this->_hostState = std::get<std::string>(value);
193 }));
Matt Spinler744d8512022-06-08 08:25:47 -0500194
195 // Watch the BaseBIOSTable property for the hmc managed attribute
196 _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
197 bus, object_path::biosConfigMgr, interface::biosConfigMgr,
198 "BaseBIOSTable", service_name::biosConfigMgr, *this,
199 [this](const auto& value) {
200 const auto& attributes = std::get<BiosAttributes>(value);
201
202 auto it = attributes.find("pvm_hmc_managed");
203 if (it != attributes.end())
204 {
205 const auto& currentValVariant = std::get<5>(it->second);
206 auto currentVal = std::get_if<std::string>(&currentValVariant);
207 if (currentVal)
208 {
Patrick Williams2544b412022-10-04 08:41:06 -0500209 this->_hmcManaged = (*currentVal == "Enabled") ? true
210 : false;
Matt Spinler744d8512022-06-08 08:25:47 -0500211 }
212 }
213 }));
Matt Spinlerc8705e22019-09-11 12:36:07 -0500214}
215
Matt Spinler2a28c932020-02-03 14:23:40 -0600216DBusPropertyMap
217 DataInterface::getAllProperties(const std::string& service,
218 const std::string& objectPath,
219 const std::string& interface) const
Matt Spinlerc8705e22019-09-11 12:36:07 -0500220{
221 DBusPropertyMap properties;
222
223 auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(),
224 interface::dbusProperty, "GetAll");
225 method.append(interface);
Matt Spinler35a405b2022-03-02 11:42:42 -0600226 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlerc8705e22019-09-11 12:36:07 -0500227
228 reply.read(properties);
229
230 return properties;
231}
232
Matt Spinlera7d9d962019-11-06 15:01:25 -0600233void DataInterface::getProperty(const std::string& service,
234 const std::string& objectPath,
235 const std::string& interface,
Matt Spinler2a28c932020-02-03 14:23:40 -0600236 const std::string& property,
237 DBusValue& value) const
Matt Spinlera7d9d962019-11-06 15:01:25 -0600238{
Matt Spinlera7d9d962019-11-06 15:01:25 -0600239 auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(),
240 interface::dbusProperty, "Get");
241 method.append(interface, property);
Matt Spinler35a405b2022-03-02 11:42:42 -0600242 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlera7d9d962019-11-06 15:01:25 -0600243
244 reply.read(value);
245}
246
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600247DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const
248{
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600249 auto method = _bus.new_method_call(
250 service_name::objectMapper, object_path::objectMapper,
251 interface::objectMapper, "GetSubTreePaths");
252
253 method.append(std::string{"/"}, 0, interfaces);
254
Matt Spinler35a405b2022-03-02 11:42:42 -0600255 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600256
257 DBusPathList paths;
258 reply.read(paths);
259
260 return paths;
261}
262
Matt Spinlerc8705e22019-09-11 12:36:07 -0500263DBusService DataInterface::getService(const std::string& objectPath,
Matt Spinlerb3f51862019-12-09 13:55:10 -0600264 const std::string& interface) const
Matt Spinlerc8705e22019-09-11 12:36:07 -0500265{
266 auto method = _bus.new_method_call(service_name::objectMapper,
267 object_path::objectMapper,
268 interface::objectMapper, "GetObject");
269
270 method.append(objectPath, std::vector<std::string>({interface}));
271
Matt Spinler35a405b2022-03-02 11:42:42 -0600272 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlerc8705e22019-09-11 12:36:07 -0500273
274 std::map<DBusService, DBusInterfaceList> response;
275 reply.read(response);
276
277 if (!response.empty())
278 {
279 return response.begin()->first;
280 }
281
282 return std::string{};
283}
Matt Spinlera7d9d962019-11-06 15:01:25 -0600284
Matt Spinler677381b2020-01-23 10:04:29 -0600285void DataInterface::readBMCFWVersion()
286{
Matt Spinlerf61f2922020-06-23 11:32:49 -0500287 _bmcFWVersion =
288 phosphor::logging::util::getOSReleaseValue("VERSION").value_or("");
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600289}
290
291void DataInterface::readServerFWVersion()
292{
Sumit Kumarcad16202021-05-13 04:06:15 -0500293 auto value =
294 phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or("");
295 if ((value != "") && (value.find_last_of(')') != std::string::npos))
296 {
297 std::size_t pos = value.find_first_of('(') + 1;
298 _serverFWVersion = value.substr(pos, value.find_last_of(')') - pos);
299 }
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600300}
301
Matt Spinler677381b2020-01-23 10:04:29 -0600302void DataInterface::readBMCFWVersionID()
303{
Matt Spinlerf61f2922020-06-23 11:32:49 -0500304 _bmcFWVersionID =
305 phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or("");
Matt Spinler677381b2020-01-23 10:04:29 -0600306}
307
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500308std::string DataInterface::getMachineTypeModel() const
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600309{
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500310 std::string model;
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600311 try
312 {
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500313 auto service = getService(object_path::systemInv, interface::invAsset);
314 if (!service.empty())
315 {
316 DBusValue value;
317 getProperty(service, object_path::systemInv, interface::invAsset,
318 "Model", value);
319
320 model = std::get<std::string>(value);
321 }
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600322 }
323 catch (const std::exception& e)
324 {
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500325 log<level::WARNING>(fmt::format("Failed reading Model property from "
326 "Interface: {} exception: {}",
327 interface::invAsset, e.what())
328 .c_str());
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600329 }
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500330
331 return model;
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600332}
333
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500334std::string DataInterface::getMachineSerialNumber() const
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600335{
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500336 std::string sn;
337 try
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600338 {
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500339 auto service = getService(object_path::systemInv, interface::invAsset);
340 if (!service.empty())
341 {
342 DBusValue value;
343 getProperty(service, object_path::systemInv, interface::invAsset,
344 "SerialNumber", value);
345
346 sn = std::get<std::string>(value);
347 }
348 }
349 catch (const std::exception& e)
350 {
351 log<level::WARNING>(
352 fmt::format("Failed reading SerialNumber property from "
353 "Interface: {} exception: {}",
354 interface::invAsset, e.what())
355 .c_str());
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600356 }
357
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500358 return sn;
359}
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600360
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500361std::string DataInterface::getMotherboardCCIN() const
362{
363 std::string ccin;
364
365 try
366 {
Patrick Williams2544b412022-10-04 08:41:06 -0500367 auto service = getService(object_path::motherBoardInv,
368 interface::viniRecordVPD);
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500369 if (!service.empty())
370 {
371 DBusValue value;
372 getProperty(service, object_path::motherBoardInv,
373 interface::viniRecordVPD, "CC", value);
374
375 auto cc = std::get<std::vector<uint8_t>>(value);
376 ccin = std::string{cc.begin(), cc.end()};
377 }
378 }
379 catch (const std::exception& e)
380 {
381 log<level::WARNING>(
382 fmt::format("Failed reading Motherboard CCIN property from "
383 "Interface: {} exception: {}",
384 interface::viniRecordVPD, e.what())
385 .c_str());
386 }
387
388 return ccin;
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600389}
390
Ben Tynere32b7e72021-05-18 12:38:40 -0500391std::vector<uint8_t> DataInterface::getSystemIMKeyword() const
392{
393 std::vector<uint8_t> systemIM;
394
395 try
396 {
Patrick Williams2544b412022-10-04 08:41:06 -0500397 auto service = getService(object_path::motherBoardInv,
398 interface::vsbpRecordVPD);
Ben Tynere32b7e72021-05-18 12:38:40 -0500399 if (!service.empty())
400 {
401 DBusValue value;
402 getProperty(service, object_path::motherBoardInv,
403 interface::vsbpRecordVPD, "IM", value);
404
405 systemIM = std::get<std::vector<uint8_t>>(value);
406 }
407 }
408 catch (const std::exception& e)
409 {
410 log<level::WARNING>(
411 fmt::format("Failed reading System IM property from "
412 "Interface: {} exception: {}",
413 interface::vsbpRecordVPD, e.what())
414 .c_str());
415 }
416
417 return systemIM;
418}
419
Matt Spinler60c4e792020-03-13 13:45:36 -0500420void DataInterface::getHWCalloutFields(const std::string& inventoryPath,
Matt Spinler60c4e792020-03-13 13:45:36 -0500421 std::string& fruPartNumber,
422 std::string& ccin,
423 std::string& serialNumber) const
424{
425 // For now, attempt to get all of the properties directly on the path
426 // passed in. In the future, may need to make use of an algorithm
427 // to figure out which inventory objects actually hold these
428 // interfaces in the case of non FRUs, or possibly another service
429 // will provide this info. Any missing interfaces will result
430 // in exceptions being thrown.
431
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500432 auto service = getService(inventoryPath, interface::viniRecordVPD);
Matt Spinler60c4e792020-03-13 13:45:36 -0500433
Patrick Williams2544b412022-10-04 08:41:06 -0500434 auto properties = getAllProperties(service, inventoryPath,
435 interface::viniRecordVPD);
Matt Spinler60c4e792020-03-13 13:45:36 -0500436
437 auto value = std::get<std::vector<uint8_t>>(properties["FN"]);
438 fruPartNumber = std::string{value.begin(), value.end()};
439
440 value = std::get<std::vector<uint8_t>>(properties["CC"]);
441 ccin = std::string{value.begin(), value.end()};
442
443 value = std::get<std::vector<uint8_t>>(properties["SN"]);
444 serialNumber = std::string{value.begin(), value.end()};
445}
446
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500447std::string
448 DataInterface::getLocationCode(const std::string& inventoryPath) const
449{
450 auto service = getService(inventoryPath, interface::locCode);
451
452 DBusValue locCode;
453 getProperty(service, inventoryPath, interface::locCode, "LocationCode",
454 locCode);
455
456 return std::get<std::string>(locCode);
457}
458
Matt Spinler5fb24c12020-06-04 11:21:33 -0500459std::string
460 DataInterface::addLocationCodePrefix(const std::string& locationCode)
461{
462 static const std::string locationCodePrefix{"Ufcs-"};
463
Matt Spinler0e4d72e2020-08-05 12:36:53 -0500464 // Technically there are 2 location code prefixes, Ufcs and Umts, so
465 // if it already starts with a U then don't need to do anything.
466 if (locationCode.front() != 'U')
Matt Spinler5fb24c12020-06-04 11:21:33 -0500467 {
468 return locationCodePrefix + locationCode;
469 }
470
471 return locationCode;
472}
473
474std::string DataInterface::expandLocationCode(const std::string& locationCode,
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500475 uint16_t /*node*/) const
Matt Spinler5fb24c12020-06-04 11:21:33 -0500476{
Matt Spinler0d92b522021-06-16 13:28:17 -0600477 // Location codes for connectors are the location code of the FRU they are
478 // on, plus a '-Tx' segment. Remove this last segment before expanding it
479 // and then add it back in afterwards. This way, the connector doesn't have
480 // to be in the model just so that it can be expanded.
481 auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode);
482
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500483 auto method =
484 _bus.new_method_call(service_name::vpdManager, object_path::vpdManager,
485 interface::vpdManager, "GetExpandedLocationCode");
486
Matt Spinler0d92b522021-06-16 13:28:17 -0600487 method.append(addLocationCodePrefix(baseLoc), static_cast<uint16_t>(0));
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500488
Matt Spinler35a405b2022-03-02 11:42:42 -0600489 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500490
491 std::string expandedLocationCode;
492 reply.read(expandedLocationCode);
493
Matt Spinler0d92b522021-06-16 13:28:17 -0600494 if (!connectorLoc.empty())
495 {
496 expandedLocationCode += connectorLoc;
497 }
498
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500499 return expandedLocationCode;
Matt Spinler5fb24c12020-06-04 11:21:33 -0500500}
501
Matt Spinlerbad056b2023-01-25 14:16:57 -0600502std::vector<std::string>
Matt Spinler2f9225a2020-08-05 12:58:49 -0500503 DataInterface::getInventoryFromLocCode(const std::string& locationCode,
504 uint16_t node, bool expanded) const
Matt Spinler5fb24c12020-06-04 11:21:33 -0500505{
Matt Spinler2f9225a2020-08-05 12:58:49 -0500506 std::string methodName = expanded ? "GetFRUsByExpandedLocationCode"
507 : "GetFRUsByUnexpandedLocationCode";
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500508
Matt Spinler0d92b522021-06-16 13:28:17 -0600509 // Remove the connector segment, if present, so that this method call
510 // returns an inventory path that getHWCalloutFields() can be used with.
511 // (The serial number, etc, aren't stored on the connector in the
512 // inventory, and may not even be modeled.)
513 auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode);
514
Matt Spinler2f9225a2020-08-05 12:58:49 -0500515 auto method =
516 _bus.new_method_call(service_name::vpdManager, object_path::vpdManager,
517 interface::vpdManager, methodName.c_str());
518
519 if (expanded)
520 {
Matt Spinler0d92b522021-06-16 13:28:17 -0600521 method.append(baseLoc);
Matt Spinler2f9225a2020-08-05 12:58:49 -0500522 }
523 else
524 {
Matt Spinler0d92b522021-06-16 13:28:17 -0600525 method.append(addLocationCodePrefix(baseLoc), node);
Matt Spinler2f9225a2020-08-05 12:58:49 -0500526 }
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500527
Matt Spinler35a405b2022-03-02 11:42:42 -0600528 auto reply = _bus.call(method, dbusTimeout);
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500529
530 std::vector<sdbusplus::message::object_path> entries;
531 reply.read(entries);
532
Matt Spinlerbad056b2023-01-25 14:16:57 -0600533 std::vector<std::string> paths;
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500534
Matt Spinlerbad056b2023-01-25 14:16:57 -0600535 // Note: The D-Bus method will fail if nothing found.
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500536 std::for_each(entries.begin(), entries.end(),
Matt Spinlerbad056b2023-01-25 14:16:57 -0600537 [&paths](const auto& path) { paths.push_back(path); });
Matt Spinlerfcf9a3f2020-07-28 13:21:07 -0500538
Matt Spinlerbad056b2023-01-25 14:16:57 -0600539 return paths;
Matt Spinler5fb24c12020-06-04 11:21:33 -0500540}
541
Matt Spinler34a904c2020-08-05 14:53:28 -0500542void DataInterface::assertLEDGroup(const std::string& ledGroup,
543 bool value) const
544{
545 DBusValue variant = value;
Patrick Williams2544b412022-10-04 08:41:06 -0500546 auto method = _bus.new_method_call(service_name::ledGroupManager,
547 ledGroup.c_str(),
548 interface::dbusProperty, "Set");
Matt Spinler34a904c2020-08-05 14:53:28 -0500549 method.append(interface::ledGroup, "Asserted", variant);
Matt Spinler35a405b2022-03-02 11:42:42 -0600550 _bus.call(method, dbusTimeout);
Matt Spinler34a904c2020-08-05 14:53:28 -0500551}
552
Matt Spinler993168d2021-04-07 16:05:03 -0500553void DataInterface::setFunctional(const std::string& objectPath,
554 bool value) const
555{
556 DBusValue variant = value;
557 auto service = getService(objectPath, interface::operationalStatus);
558
559 auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(),
560 interface::dbusProperty, "Set");
561
562 method.append(interface::operationalStatus, "Functional", variant);
Matt Spinler35a405b2022-03-02 11:42:42 -0600563 _bus.call(method, dbusTimeout);
Matt Spinler993168d2021-04-07 16:05:03 -0500564}
565
Sumit Kumar76198a22021-07-15 05:59:57 -0500566using AssociationTuple = std::tuple<std::string, std::string, std::string>;
567using AssociationsProperty = std::vector<AssociationTuple>;
568
569void DataInterface::setCriticalAssociation(const std::string& objectPath) const
570{
571 DBusValue getAssociationValue;
572
Sumit Kumar027bf282022-01-24 11:25:19 -0600573 auto service = getService(objectPath, interface::associationDef);
Sumit Kumar76198a22021-07-15 05:59:57 -0500574
Sumit Kumar027bf282022-01-24 11:25:19 -0600575 getProperty(service, objectPath, interface::associationDef, "Associations",
Sumit Kumar76198a22021-07-15 05:59:57 -0500576 getAssociationValue);
577
578 auto association = std::get<AssociationsProperty>(getAssociationValue);
579
580 AssociationTuple critAssociation{
581 "health_rollup", "critical",
582 "/xyz/openbmc_project/inventory/system/chassis"};
583
584 if (std::find(association.begin(), association.end(), critAssociation) ==
585 association.end())
586 {
587 association.push_back(critAssociation);
588 DBusValue setAssociationValue = association;
589
590 auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(),
591 interface::dbusProperty, "Set");
592
Sumit Kumar027bf282022-01-24 11:25:19 -0600593 method.append(interface::associationDef, "Associations",
Sumit Kumar76198a22021-07-15 05:59:57 -0500594 setAssociationValue);
Matt Spinler35a405b2022-03-02 11:42:42 -0600595 _bus.call(method, dbusTimeout);
Sumit Kumar76198a22021-07-15 05:59:57 -0500596 }
597}
598
Matt Spinler1ab66962020-10-29 13:21:44 -0500599std::vector<std::string> DataInterface::getSystemNames() const
600{
601 DBusSubTree subtree;
602 DBusValue names;
603
604 auto method = _bus.new_method_call(service_name::objectMapper,
605 object_path::objectMapper,
606 interface::objectMapper, "GetSubTree");
607 method.append(std::string{"/"}, 0,
608 std::vector<std::string>{interface::compatible});
Matt Spinler35a405b2022-03-02 11:42:42 -0600609 auto reply = _bus.call(method, dbusTimeout);
Matt Spinler1ab66962020-10-29 13:21:44 -0500610
611 reply.read(subtree);
612 if (subtree.empty())
613 {
614 throw std::runtime_error("Compatible interface not on D-Bus");
615 }
616
617 const auto& object = *(subtree.begin());
618 const auto& path = object.first;
619 const auto& service = object.second.begin()->first;
620
621 getProperty(service, path, interface::compatible, "Names", names);
622
623 return std::get<std::vector<std::string>>(names);
624}
625
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500626bool DataInterface::getQuiesceOnError() const
627{
628 bool ret = false;
629
630 try
631 {
Patrick Williams2544b412022-10-04 08:41:06 -0500632 auto service = getService(object_path::logSetting,
633 interface::logSetting);
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500634 if (!service.empty())
635 {
636 DBusValue value;
637 getProperty(service, object_path::logSetting, interface::logSetting,
638 "QuiesceOnHwError", value);
639
640 ret = std::get<bool>(value);
641 }
642 }
643 catch (const std::exception& e)
644 {
645 log<level::WARNING>(
646 fmt::format("Failed reading QuiesceOnHwError property from "
647 "Interface: {} exception: {}",
648 interface::logSetting, e.what())
649 .c_str());
650 }
651
652 return ret;
653}
654
Sumit Kumar9d43a722021-08-24 09:46:19 -0500655std::vector<bool>
656 DataInterface::checkDumpStatus(const std::vector<std::string>& type) const
657{
658 DBusSubTree subtree;
659 std::vector<bool> result(type.size(), false);
660
661 // Query GetSubTree for the availability of dump interface
662 auto method = _bus.new_method_call(service_name::objectMapper,
663 object_path::objectMapper,
664 interface::objectMapper, "GetSubTree");
665 method.append(std::string{"/"}, 0,
666 std::vector<std::string>{interface::dumpEntry});
Matt Spinler35a405b2022-03-02 11:42:42 -0600667 auto reply = _bus.call(method, dbusTimeout);
Sumit Kumar9d43a722021-08-24 09:46:19 -0500668
669 reply.read(subtree);
670
671 if (subtree.empty())
672 {
673 return result;
674 }
675
676 std::vector<bool>::iterator itDumpStatus = result.begin();
677 uint8_t count = 0;
678 for (const auto& [path, serviceInfo] : subtree)
679 {
680 const auto& service = serviceInfo.begin()->first;
681 // Check for dump type on the object path
682 for (const auto& it : type)
683 {
684 if (path.find(it) != std::string::npos)
685 {
686 DBusValue value, progress;
687
688 // If dump type status is already available go for next path
689 if (*itDumpStatus)
690 {
691 break;
692 }
693
694 // Check for valid dump to be available if following
695 // conditions are met for the dump entry path -
696 // Offloaded == false and Status == Completed
697 getProperty(service, path, interface::dumpEntry, "Offloaded",
698 value);
699 getProperty(service, path, interface::dumpProgress, "Status",
700 progress);
701 auto offload = std::get<bool>(value);
702 auto status = std::get<std::string>(progress);
703 if (!offload && (status.find("Completed") != std::string::npos))
704 {
705 *itDumpStatus = true;
706 count++;
707 if (count >= type.size())
708 {
709 return result;
710 }
711 break;
712 }
713 }
Matt Spinler45796e82022-07-01 11:25:27 -0500714 ++itDumpStatus;
Sumit Kumar9d43a722021-08-24 09:46:19 -0500715 }
716 itDumpStatus = result.begin();
717 }
718
719 return result;
720}
721
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -0500722void DataInterface::createGuardRecord(const std::vector<uint8_t>& binPath,
723 const std::string& type,
724 const std::string& logPath) const
725{
726 try
727 {
728 auto method = _bus.new_method_call(
729 service_name::hwIsolation, object_path::hwIsolation,
730 interface::hwIsolationCreate, "CreateWithEntityPath");
731 method.append(binPath, type, sdbusplus::message::object_path(logPath));
732 // Note: hw isolation "CreateWithEntityPath" got dependency on logging
733 // api's. Making d-bus call no reply type to avoid cyclic dependency.
734 // Added minimal timeout to catch initial failures.
735 // Need to revisit this design later to avoid cyclic dependency.
Matt Spinler35a405b2022-03-02 11:42:42 -0600736 constexpr auto hwIsolationTimeout = 100000; // in micro seconds
737 _bus.call_noreply(method, hwIsolationTimeout);
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -0500738 }
739
Patrick Williams45e83522022-07-22 19:26:52 -0500740 catch (const sdbusplus::exception_t& e)
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -0500741 {
742 std::string errName = e.name();
743 // SD_BUS_ERROR_TIMEOUT error is expected, due to PEL api dependency
744 // mentioned above. Ignoring the error.
745 if (errName != SD_BUS_ERROR_TIMEOUT)
746 {
747 log<level::ERR>(
748 fmt::format("GUARD D-Bus call exception"
749 "OBJPATH={}, INTERFACE={}, EXCEPTION={}",
750 object_path::hwIsolation,
751 interface::hwIsolationCreate, e.what())
752 .c_str());
753 }
754 }
755}
Sumit Kumar3e274432021-09-14 06:37:56 -0500756
757void DataInterface::createProgressSRC(
758 const uint64_t& priSRC, const std::vector<uint8_t>& srcStruct) const
759{
760 DBusValue variant = std::make_tuple(priSRC, srcStruct);
761
762 auto method = _bus.new_method_call(service_name::bootRawProgress,
Vijay Lobo875b6c72021-10-20 17:38:56 -0500763 object_path::bootRawProgress,
Sumit Kumar3e274432021-09-14 06:37:56 -0500764 interface::dbusProperty, "Set");
765
766 method.append(interface::bootRawProgress, "Value", variant);
767
Matt Spinler35a405b2022-03-02 11:42:42 -0600768 _bus.call(method, dbusTimeout);
Sumit Kumar3e274432021-09-14 06:37:56 -0500769}
Sumit Kumar027bf282022-01-24 11:25:19 -0600770
771std::vector<uint32_t> DataInterface::getLogIDWithHwIsolation() const
772{
773 std::vector<std::string> association = {"xyz.openbmc_project.Association"};
774 std::string hwErrorLog = "/isolated_hw_errorlog";
775 std::string errorLog = "/error_log";
776 DBusPathList paths;
777 std::vector<uint32_t> ids;
778
779 // Get all latest mapper associations
780 paths = getPaths(association);
781 for (auto& path : paths)
782 {
783 // Look for object path with hardware isolation entry if any
784 size_t pos = path.find(hwErrorLog);
785 if (pos != std::string::npos)
786 {
787 // Get the object path
788 std::string ph = path;
789 ph.erase(pos, hwErrorLog.length());
790 auto service = getService(ph, interface::hwIsolationEntry);
791 if (!service.empty())
792 {
793 bool status;
794 DBusValue value;
795
796 // Read the Resolved property from object path
797 getProperty(service, ph, interface::hwIsolationEntry,
798 "Resolved", value);
799
800 status = std::get<bool>(value);
801
802 // If the entry isn't resolved
803 if (!status)
804 {
Patrick Williams2544b412022-10-04 08:41:06 -0500805 auto assocService = getService(path,
806 interface::association);
Matt Spinler45796e82022-07-01 11:25:27 -0500807 if (!assocService.empty())
Sumit Kumar027bf282022-01-24 11:25:19 -0600808 {
Matt Spinler45796e82022-07-01 11:25:27 -0500809 DBusValue endpoints;
Sumit Kumar027bf282022-01-24 11:25:19 -0600810
811 // Read Endpoints property
Matt Spinler45796e82022-07-01 11:25:27 -0500812 getProperty(assocService, path, interface::association,
813 "endpoints", endpoints);
Sumit Kumar027bf282022-01-24 11:25:19 -0600814
815 auto logPath =
Matt Spinler45796e82022-07-01 11:25:27 -0500816 std::get<std::vector<std::string>>(endpoints);
Sumit Kumar027bf282022-01-24 11:25:19 -0600817 if (!logPath.empty())
818 {
819 // Get OpenBMC event log Id
820 uint32_t id = stoi(logPath[0].substr(
821 logPath[0].find_last_of('/') + 1));
822 ids.push_back(id);
823 }
824 }
825 }
826 }
827 }
828
829 // Look for object path with error_log entry if any
830 pos = path.find(errorLog);
831 if (pos != std::string::npos)
832 {
833 auto service = getService(path, interface::association);
834 if (!service.empty())
835 {
836 DBusValue value;
837
838 // Read Endpoints property
839 getProperty(service, path, interface::association, "endpoints",
840 value);
841
842 auto logPath = std::get<std::vector<std::string>>(value);
843 if (!logPath.empty())
844 {
845 // Get OpenBMC event log Id
846 uint32_t id = stoi(
847 logPath[0].substr(logPath[0].find_last_of('/') + 1));
848 ids.push_back(id);
849 }
850 }
851 }
852 }
853
854 if (ids.size() > 1)
855 {
856 // remove duplicates to have only unique ids
857 std::sort(ids.begin(), ids.end());
858 ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
859 }
860 return ids;
861}
Vijay Lobo875b6c72021-10-20 17:38:56 -0500862
863std::vector<uint8_t> DataInterface::getRawProgressSRC(void) const
864{
865 using RawProgressProperty = std::tuple<uint64_t, std::vector<uint8_t>>;
866
867 DBusValue value;
868 getProperty(service_name::bootRawProgress, object_path::bootRawProgress,
869 interface::bootRawProgress, "Value", value);
870
871 const auto& rawProgress = std::get<RawProgressProperty>(value);
872 return std::get<1>(rawProgress);
873}
874
Matt Spinlerc8705e22019-09-11 12:36:07 -0500875} // namespace pels
876} // namespace openpower