From 239714c7e71db22a615ab2134f8ce7599e8904fd Mon Sep 17 00:00:00 2001 From: Sunny Srivastava Date: Sun, 19 Jan 2025 23:20:02 +0530 Subject: [PATCH] Check for power vs configuration Signed-off-by: Sunny Srivastava --- configuration/ibm/5000_power_vs.json | 27 +++++++ meson.build | 1 + meson_options.txt | 3 +- vpd-manager/include/constants.hpp | 4 ++ vpd-manager/include/manager.hpp | 5 ++ .../include/utility/vpd_specific_utility.hpp | 54 ++++++++++++++ vpd-manager/src/manager.cpp | 70 ++++++++++++++++++- 7 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 configuration/ibm/5000_power_vs.json diff --git a/configuration/ibm/5000_power_vs.json b/configuration/ibm/5000_power_vs.json new file mode 100644 index 00000000..4c5b94d3 --- /dev/null +++ b/configuration/ibm/5000_power_vs.json @@ -0,0 +1,27 @@ +{ + "/sys/bus/spi/drivers/at25/spi12.0/eeprom": { + "VINI": { + "PN": [49, 50, 51, 52, 53, 54] + } + }, + "/sys/bus/spi/drivers/at25/spi22.0/eeprom": { + "VINI" : { + "PN": [49, 50, 51, 52, 53, 54, 55] + } + }, + "/sys/bus/spi/drivers/at25/spi32.0/eeprom": { + "VINI": { + "PN": [49, 50, 51, 52, 53, 54, 55, 56] + } + }, + "/sys/bus/spi/drivers/at25/spi42.0/eeprom": { + "VINI": { + "PN": [49, 50, 51, 52, 53, 54, 55, 56, 57] + } + }, + "/sys/bus/i2c/drivers/at24/8-0051/eeprom": { + "VINI": { + "PN": [49, 50, 51, 52, 53] + } + } +} \ No newline at end of file diff --git a/meson.build b/meson.build index fa9c9932..8b10a721 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,7 @@ conf_data.set_quoted('JSON_ABSOLUTE_PATH_PREFIX', get_option('JSON_ABSOLUTE_PATH conf_data.set_quoted('SYSTEM_VPD_FILE_PATH', get_option('SYSTEM_VPD_FILE_PATH')) conf_data.set_quoted('VPD_SYMLIMK_PATH', get_option('VPD_SYMLIMK_PATH')) conf_data.set_quoted('PIM_PATH_PREFIX', get_option('PIM_PATH_PREFIX')) +conf_data.set_quoted('POWER_VS_JSON_5000', get_option('POWER_VS_JSON_5000')) configure_file(output: 'config.h', configuration : conf_data) diff --git a/meson_options.txt b/meson_options.txt index 72bd1d6d..51c7012f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,4 +10,5 @@ option('JSON_ABSOLUTE_PATH_PREFIX', type: 'string', value: '/usr/share/vpd/', d option('SYSTEM_VPD_FILE_PATH', type: 'string', value: '/sys/bus/i2c/drivers/at24/8-0050/eeprom', description: 'EEPROM path of system VPD.') option('VPD_SYMLIMK_PATH', type: 'string', value: '/var/lib/vpd', description: 'Symlink folder for VPD invnetory JSONs') option('PIM_PATH_PREFIX', type: 'string', value: '/xyz/openbmc_project/inventory', description: 'Prefix for PIM inventory paths.') -option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.') \ No newline at end of file +option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.') +option('POWER_VS_JSON_5000', type: 'string', value : '/usr/share/vpd/5000_power_vs.json', description: 'Json file that contains part number with respect to PowerVS system.') \ No newline at end of file diff --git a/vpd-manager/include/constants.hpp b/vpd-manager/include/constants.hpp index 5faf8da8..a0b6f287 100644 --- a/vpd-manager/include/constants.hpp +++ b/vpd-manager/include/constants.hpp @@ -112,6 +112,8 @@ static constexpr auto SIZE_OF_8EQ_IN_PG = 24; // Zero based index position of first EQ in CP00's PG keyword static constexpr auto INDEX_OF_EQ0_IN_PG = 97; +static constexpr auto HEX_VALUE_50 = 0x50; + constexpr auto systemInvPath = "/xyz/openbmc_project/inventory/system"; constexpr auto pimPath = "/xyz/openbmc_project/inventory"; constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager"; @@ -120,9 +122,11 @@ constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI"; constexpr auto vsysInf = "com.ibm.ipzvpd.VSYS"; constexpr auto utilInf = "com.ibm.ipzvpd.UTIL"; constexpr auto vcenInf = "com.ibm.ipzvpd.VCEN"; +constexpr auto vsbpInf = "com.ibm.ipzvpd.VSBP"; constexpr auto kwdCCIN = "CC"; constexpr auto kwdRG = "RG"; constexpr auto kwdAMM = "D0"; +constexpr auto kwdIM = "IM"; constexpr auto kwdClearNVRAM_CreateLPAR = "D1"; constexpr auto kwdKeepAndClear = "D1"; constexpr auto kwdFC = "FC"; diff --git a/vpd-manager/include/manager.hpp b/vpd-manager/include/manager.hpp index cb64123b..0cd0d2f5 100644 --- a/vpd-manager/include/manager.hpp +++ b/vpd-manager/include/manager.hpp @@ -271,6 +271,11 @@ class Manager */ void registerHostStateChangeCallback(); + /** + * @brief API to update VPD related to power vs system. + */ + void updatePowerVsVpd(); + /** * @brief API to process host state change callback. * diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp index 601cbd31..9e96b1f7 100644 --- a/vpd-manager/include/utility/vpd_specific_utility.hpp +++ b/vpd-manager/include/utility/vpd_specific_utility.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -552,5 +553,58 @@ inline void resetDataUnderPIM(const std::string& i_objectPath, " with error: " + std::string(l_ex.what())); } } + +/** + * @brief API to detect of system configuration is that of PowerVS system. + * + * @param[in] i_sysConfigJson - System config JSON object. + * @return True if it is PowerVS configuration, false otherwise. + */ +inline bool isPowerVsConfiguration(const nlohmann::json& i_sysConfigJson) +{ + try + { + if (i_sysConfigJson.empty()) + { + throw std::runtime_error("Invalid system config JSON."); + } + + const auto& l_inventoryPath = jsonUtility::getInventoryObjPathFromJson( + i_sysConfigJson, SYSTEM_VPD_FILE_PATH); + + if (l_inventoryPath.empty()) + { + throw std::runtime_error( + "Inventory path not found in Json for system VPD filepath."); + } + + const auto& l_retValue = dbusUtility::readDbusProperty( + constants::pimServiceName, l_inventoryPath, constants::vsbpInf, + constants::kwdIM); + + if (auto l_imValue = std::get_if(&l_retValue)) + { + if (((*l_imValue).at(0) == constants::HEX_VALUE_50) /*&& + (getImagePrefix() == "MX")*/) + { + return true; + } + } + + throw std::runtime_error( + "Invalid type recieved while reading system IM."); + } + catch (const std::exception& l_ex) + { + EventLogger::createSyncPel( + types::ErrorType::InvalidSystem, types::SeverityType::Informational, + __FILE__, __FUNCTION__, 0, + "Failed to process powerVS configuration with error: " + + std::string(l_ex.what()), + std::nullopt, std::nullopt, std::nullopt, std::nullopt); + + return false; + } +} } // namespace vpdSpecificUtility } // namespace vpd diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp index 7f9efd48..23bbc4c7 100644 --- a/vpd-manager/src/manager.cpp +++ b/vpd-manager/src/manager.cpp @@ -18,6 +18,8 @@ #include #include +#include + namespace vpd { Manager::Manager( @@ -272,11 +274,18 @@ void Manager::SetTimerToDetectVpdCollectionStatus() { // cancel the timer l_timer.cancel(); - m_interface->set_property("CollectionStatus", - std::string("Completed")); const nlohmann::json& l_sysCfgJsonObj = m_worker->getSysCfgJsonObj(); + + if (vpdSpecificUtility::isPowerVsConfiguration(l_sysCfgJsonObj)) + { + updatePowerVsVpd(); + } + + m_interface->set_property("CollectionStatus", + std::string("Completed")); + if (jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj)) { BackupAndRestore l_backupAndRestoreObj(l_sysCfgJsonObj); @@ -910,4 +919,61 @@ void Manager::performVpdRecollection() std::string(l_ex.what())); } } + +void Manager::updatePowerVsVpd() +{ + try + { + nlohmann::json l_parsedPwrVsJson = + jsonUtility::getParsedJson(POWER_VS_JSON_5000); + + for (const auto& [l_path, l_recJson] : l_parsedPwrVsJson.items()) + { + std::cout << "Path = " << l_path << std::endl; + + for (const auto& [l_recordName, l_kwdJson] : l_recJson.items()) + { + std::cout << "record name = " << l_recordName << std::endl; + + for (const auto& [l_kwdName, l_kwdValue] : l_kwdJson.items()) + { + std::cout << "kwd name = " << l_kwdName << std::endl; + + std::cout << "kwd value size = " << l_kwdValue.size() + << std::endl; + if (l_kwdValue.is_array()) + { + std::cout << "Is array"; + types::BinaryVector l_binaryKwdValue = + l_kwdValue.get(); + + for (auto item : l_binaryKwdValue) + { + std::cout << (int)item << " "; + } + std::cout << std::endl; + } + + /* if (updateKeyword(l_path, + std::make_tuple(l_recordName, l_kwdName, + l_kwdValue)) == + constants::FAILURE) + { + // TODO should we stop all updates or log this failure + // and continue with rest of the updates. + }*/ + } + } + } + } + catch (const std::exception& l_ex) + { + /* types::ErrorType l_errTYype = types::ErrorType::InvalidSystem; + + if (typeid(l_ex) == std::type_index(typeid(JsonException))) + { + l_errTYype = types::ErrorType::JsonFailure; + }*/ + } +} } // namespace vpd