Skip to content

Commit 0c9ff56

Browse files
Check for power vs configuration
Signed-off-by: Sunny Srivastava <[email protected]>
1 parent 8d35fae commit 0c9ff56

File tree

7 files changed

+161
-1
lines changed

7 files changed

+161
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"/sys/bus/spi/drivers/at25/spi12.0/eeprom" : {
3+
"VINI" : {
4+
"PN": [49, 50, 51, 52, 53, 54]
5+
}
6+
},
7+
"/sys/bus/spi/drivers/at25/spi22.0/eeprom" : {
8+
"VINI" : {
9+
"PN": [49, 50, 51, 52, 53, 54, 55]
10+
}
11+
},
12+
"/sys/bus/spi/drivers/at25/spi32.0/eeprom" : {
13+
"VINI" : {
14+
"PN": [49, 50, 51, 52, 53, 54, 55, 56]
15+
}
16+
},
17+
"/sys/bus/spi/drivers/at25/spi42.0/eeprom" : {
18+
"VINI" : {
19+
"PN": [49, 50, 51, 52, 53, 54, 55, 56, 57]
20+
}
21+
},
22+
"/sys/bus/i2c/drivers/at24/8-0051/eeprom" : {
23+
"VINI" : {
24+
"PN": [49, 50, 51, 52, 53]
25+
}
26+
}
27+
}

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ conf_data.set_quoted('JSON_ABSOLUTE_PATH_PREFIX', get_option('JSON_ABSOLUTE_PATH
4747
conf_data.set_quoted('SYSTEM_VPD_FILE_PATH', get_option('SYSTEM_VPD_FILE_PATH'))
4848
conf_data.set_quoted('VPD_SYMLIMK_PATH', get_option('VPD_SYMLIMK_PATH'))
4949
conf_data.set_quoted('PIM_PATH_PREFIX', get_option('PIM_PATH_PREFIX'))
50+
conf_data.set_quoted('5000_POWER_VS_JSON', get_option('5000_POWER_VS_JSON'))
5051
configure_file(output: 'config.h',
5152
configuration : conf_data)
5253

meson_options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ option('JSON_ABSOLUTE_PATH_PREFIX', type: 'string', value: '/usr/share/vpd/', d
1010
option('SYSTEM_VPD_FILE_PATH', type: 'string', value: '/sys/bus/i2c/drivers/at24/8-0050/eeprom', description: 'EEPROM path of system VPD.')
1111
option('VPD_SYMLIMK_PATH', type: 'string', value: '/var/lib/vpd', description: 'Symlink folder for VPD invnetory JSONs')
1212
option('PIM_PATH_PREFIX', type: 'string', value: '/xyz/openbmc_project/inventory', description: 'Prefix for PIM inventory paths.')
13-
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
13+
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
14+
option('5000_POWER_VS_JSON', type: 'string', value : '/usr/share/vpd/5000_power_vs.json', description: 'Json file that contains part number with respect to PowerVS system.')

vpd-manager/include/constants.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static constexpr auto SIZE_OF_8EQ_IN_PG = 24;
112112
// Zero based index position of first EQ in CP00's PG keyword
113113
static constexpr auto INDEX_OF_EQ0_IN_PG = 97;
114114

115+
static constexpr auto HEX_VALUE_5000 = 0x50;
116+
115117
constexpr auto systemInvPath = "/xyz/openbmc_project/inventory/system";
116118
constexpr auto pimPath = "/xyz/openbmc_project/inventory";
117119
constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager";
@@ -120,9 +122,11 @@ constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI";
120122
constexpr auto vsysInf = "com.ibm.ipzvpd.VSYS";
121123
constexpr auto utilInf = "com.ibm.ipzvpd.UTIL";
122124
constexpr auto vcenInf = "com.ibm.ipzvpd.VCEN";
125+
constexpr auto vsbpInf = "com.ibm.ipzvpd.VSBP";
123126
constexpr auto kwdCCIN = "CC";
124127
constexpr auto kwdRG = "RG";
125128
constexpr auto kwdAMM = "D0";
129+
constexpr auto kwdIM = "IM";
126130
constexpr auto kwdClearNVRAM_CreateLPAR = "D1";
127131
constexpr auto kwdKeepAndClear = "D1";
128132
constexpr auto kwdFC = "FC";

vpd-manager/include/manager.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ class Manager
271271
*/
272272
void registerHostStateChangeCallback();
273273

274+
/**
275+
* @brief API to check for PowerVS configuration.
276+
*/
277+
void checkPowerVsConfiguration();
278+
274279
/**
275280
* @brief API to process host state change callback.
276281
*

vpd-manager/include/utility/vpd_specific_utility.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <nlohmann/json.hpp>
1111
#include <utility/common_utility.hpp>
1212
#include <utility/dbus_utility.hpp>
13+
#include <utility/json_utility.hpp>
1314

1415
#include <filesystem>
1516
#include <fstream>
@@ -552,5 +553,42 @@ inline void resetDataUnderPIM(const std::string& i_objectPath,
552553
" with error: " + std::string(l_ex.what()));
553554
}
554555
}
556+
557+
/**
558+
* @brief API to read IM keyword value published over Dbus.
559+
*
560+
* @throw JsonException, std::runtime_error.
561+
*
562+
* @param[in] i_sysConfigJson - System config JSON object.
563+
* @return IM keywrod value read from DBus. Exception otherwise.
564+
*/
565+
inline types::BinaryVector readSystemIM(const nlohmann::json& i_sysConfigJson)
566+
{
567+
if (i_sysConfigJson.empty())
568+
{
569+
throw JsonException("Invalid system config JSON.");
570+
}
571+
572+
const auto& l_inventoryPath =
573+
jsonUtility::getInventoryObjPathFromJson(SYSTEM_VPD_FILE_PATH);
574+
575+
if (l_inventoryPath.empty())
576+
{
577+
throw JsonException(
578+
"Inventory path not found in Json for system VPD filepath.");
579+
}
580+
581+
const auto& l_retValue = dbusUtility::readDbusProperty(
582+
constants::pimServiceName, l_inventoryPath, constants::vsbpInf,
583+
constants::kwdIM);
584+
585+
if (auto l_imValue = std::get_if<types::BinaryVector>(&l_retValue))
586+
{
587+
return *l_imValue;
588+
}
589+
590+
throw std::runtime_error("Invalid type recieved for IM value.");
591+
}
592+
555593
} // namespace vpdSpecificUtility
556594
} // namespace vpd

vpd-manager/src/manager.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void Manager::SetTimerToDetectVpdCollectionStatus()
272272
{
273273
// cancel the timer
274274
l_timer.cancel();
275+
checkPowerVsConfiguration();
275276
m_interface->set_property("CollectionStatus",
276277
std::string("Completed"));
277278

@@ -910,4 +911,87 @@ void Manager::performVpdRecollection()
910911
std::string(l_ex.what()));
911912
}
912913
}
914+
915+
void Manager::checkPowerVsConfiguration()
916+
{
917+
try
918+
{
919+
if (m_worker.get() != nullptr)
920+
{
921+
const auto& l_imValue =
922+
vpdSpecificUtility::readSystemIM(m_worker->getSysCfgJsonObj());
923+
924+
// If the system is not a 5000 series system or image prefix is not
925+
// MX. Abort process.
926+
if ((l_imValue.at(0) != constants::HEX_VALUE_50)) /* &&
927+
(getImagePrefix() != "MX"))*/
928+
{
929+
return;
930+
}
931+
932+
std::error_code l_ec;
933+
if (!std::filesystem::exists(5000_POWER_VS_JSON, l_ec))
934+
{
935+
std::string l_errMsg{
936+
"Call to filesystem exists failed for PowerVS JSON."};
937+
938+
if (l_ec)
939+
{
940+
l_errMsg += " with error code: " + l_ec.message();
941+
}
942+
943+
throw std::runtime_error(l_errMsg);
944+
}
945+
946+
try
947+
{
948+
nlohmann::json l_parsedPwrVsJson =
949+
jsonUtility::getParsedJson(5000_POWER_VS_JSON);
950+
951+
for (const auto& [l_path, l_value] : l_parsedPwrVsJson.items())
952+
{
953+
std::cout << "Path = " << l_path << std::endl;
954+
if (!value.items().value().contains("PN"))
955+
{
956+
continue;
957+
}
958+
959+
types::BinaryVector l_kwdValue =
960+
value.items().value()["PN"].get<types::BinaryVector>();
961+
962+
std::cout << "kwd value size = " << l_kwdValue.size()
963+
<< std::endl;
964+
965+
/*updateKeyword(
966+
l_path,
967+
std::make_tuple(value.items().key(),
968+
value.items().value().items().key(),
969+
l_kwdValue));*/
970+
}
971+
}
972+
catch (const nlohmann::json::parse_error& l_ex)
973+
{
974+
throw(JsonException("Json parsing failed", POWER_VS_PN_JSON));
975+
}
976+
}
977+
978+
throw std::runtime_error("Failed to get worker instance.");
979+
}
980+
catch (const std::exception& l_ex)
981+
{
982+
types::ErrorType l_errTYype = types::ErrorType::InvalidSystem;
983+
984+
if (typeid(ex) == std::type_index(typeid(JsonException)))
985+
{
986+
l_errTYype = types::ErrorType::JsonFailure;
987+
}
988+
989+
EventLogger::createSyncPel(
990+
l_errTYype, types::SeverityType::Informational, __FILE__,
991+
__FUNCTION__, 0,
992+
"Failed to process powerVS configuration with error: " +
993+
std::string(l_ex.what()),
994+
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
995+
}
996+
}
913997
} // namespace vpd

0 commit comments

Comments
 (0)