1fa5e4d32SSunny Srivastava #pragma once 2fa5e4d32SSunny Srivastava 3fa5e4d32SSunny Srivastava #include "constants.hpp" 4fa5e4d32SSunny Srivastava #include "gpio_monitor.hpp" 5fa5e4d32SSunny Srivastava #include "types.hpp" 6fa5e4d32SSunny Srivastava #include "worker.hpp" 7fa5e4d32SSunny Srivastava 8fa5e4d32SSunny Srivastava #include <sdbusplus/asio/object_server.hpp> 9fa5e4d32SSunny Srivastava 10fa5e4d32SSunny Srivastava namespace vpd 11fa5e4d32SSunny Srivastava { 12fa5e4d32SSunny Srivastava /** 13fa5e4d32SSunny Srivastava * @brief Class to manage VPD processing. 14fa5e4d32SSunny Srivastava * 15fa5e4d32SSunny Srivastava * The class is responsible to implement methods to manage VPD on the system. 16fa5e4d32SSunny Srivastava * It also implements methods to be exposed over D-Bus required to access/edit 17fa5e4d32SSunny Srivastava * VPD data. 18fa5e4d32SSunny Srivastava */ 19fa5e4d32SSunny Srivastava class Manager 20fa5e4d32SSunny Srivastava { 21fa5e4d32SSunny Srivastava public: 22fa5e4d32SSunny Srivastava /** 23fa5e4d32SSunny Srivastava * List of deleted methods. 24fa5e4d32SSunny Srivastava */ 25fa5e4d32SSunny Srivastava Manager(const Manager&) = delete; 26fa5e4d32SSunny Srivastava Manager& operator=(const Manager&) = delete; 27fa5e4d32SSunny Srivastava Manager(Manager&&) = delete; 28fa5e4d32SSunny Srivastava 29fa5e4d32SSunny Srivastava /** 30fa5e4d32SSunny Srivastava * @brief Constructor. 31fa5e4d32SSunny Srivastava * 32fa5e4d32SSunny Srivastava * @param[in] ioCon - IO context. 33fa5e4d32SSunny Srivastava * @param[in] iFace - interface to implement. 34fa5e4d32SSunny Srivastava * @param[in] connection - Dbus Connection. 35fa5e4d32SSunny Srivastava */ 36fa5e4d32SSunny Srivastava Manager(const std::shared_ptr<boost::asio::io_context>& ioCon, 37fa5e4d32SSunny Srivastava const std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace, 38fa5e4d32SSunny Srivastava const std::shared_ptr<sdbusplus::asio::connection>& asioConnection); 39fa5e4d32SSunny Srivastava 40fa5e4d32SSunny Srivastava /** 41fa5e4d32SSunny Srivastava * @brief Destructor. 42fa5e4d32SSunny Srivastava */ 43fa5e4d32SSunny Srivastava ~Manager() = default; 44fa5e4d32SSunny Srivastava 45fa5e4d32SSunny Srivastava /** 46fa5e4d32SSunny Srivastava * @brief Update keyword value. 47fa5e4d32SSunny Srivastava * 48fa5e4d32SSunny Srivastava * This API is used to update keyword value on the given input path and its 49fa5e4d32SSunny Srivastava * redundant path(s) if any taken from system config JSON. 50fa5e4d32SSunny Srivastava * 51fa5e4d32SSunny Srivastava * To update IPZ type VPD, input parameter for writing should be in the form 52fa5e4d32SSunny Srivastava * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}). 53fa5e4d32SSunny Srivastava * 54fa5e4d32SSunny Srivastava * To update Keyword type VPD, input parameter for writing should be in the 55fa5e4d32SSunny Srivastava * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}). 56fa5e4d32SSunny Srivastava * 57fa5e4d32SSunny Srivastava * @param[in] i_vpdPath - Path (inventory object path/FRU EEPROM path). 58fa5e4d32SSunny Srivastava * @param[in] i_paramsToWriteData - Input details. 59fa5e4d32SSunny Srivastava * 60fa5e4d32SSunny Srivastava * @return On success returns number of bytes written, on failure returns 61fa5e4d32SSunny Srivastava * -1. 62fa5e4d32SSunny Srivastava */ 63fa5e4d32SSunny Srivastava int updateKeyword(const types::Path i_vpdPath, 64fa5e4d32SSunny Srivastava const types::WriteVpdParams i_paramsToWriteData); 65fa5e4d32SSunny Srivastava 66fa5e4d32SSunny Srivastava /** 67fa5e4d32SSunny Srivastava * @brief Update keyword value on hardware. 68fa5e4d32SSunny Srivastava * 69fa5e4d32SSunny Srivastava * This API is used to update keyword value on hardware. Updates only on the 70fa5e4d32SSunny Srivastava * given input hardware path, does not look for corresponding redundant or 71fa5e4d32SSunny Srivastava * primary path against the given path. To update corresponding paths, make 72fa5e4d32SSunny Srivastava * separate call with respective path. 73fa5e4d32SSunny Srivastava * 74fa5e4d32SSunny Srivastava * To update IPZ type VPD, input parameter for writing should be in the form 75fa5e4d32SSunny Srivastava * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}). 76fa5e4d32SSunny Srivastava * 77fa5e4d32SSunny Srivastava * To update Keyword type VPD, input parameter for writing should be in the 78fa5e4d32SSunny Srivastava * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}). 79fa5e4d32SSunny Srivastava * 80fa5e4d32SSunny Srivastava * @param[in] i_fruPath - EEPROM path of the FRU. 81fa5e4d32SSunny Srivastava * @param[in] i_paramsToWriteData - Input details. 82fa5e4d32SSunny Srivastava * 83fa5e4d32SSunny Srivastava * @return On success returns number of bytes written, on failure returns 84fa5e4d32SSunny Srivastava * -1. 85fa5e4d32SSunny Srivastava */ 86fa5e4d32SSunny Srivastava int updateKeywordOnHardware( 87fa5e4d32SSunny Srivastava const types::Path i_fruPath, 88fa5e4d32SSunny Srivastava const types::WriteVpdParams i_paramsToWriteData) noexcept; 89fa5e4d32SSunny Srivastava 90fa5e4d32SSunny Srivastava /** 91fa5e4d32SSunny Srivastava * @brief Read keyword value. 92fa5e4d32SSunny Srivastava * 93fa5e4d32SSunny Srivastava * API can be used to read VPD keyword from the given input path. 94fa5e4d32SSunny Srivastava * 95fa5e4d32SSunny Srivastava * To read keyword of type IPZ, input parameter for reading should be in the 96fa5e4d32SSunny Srivastava * form of (Record, Keyword). Eg: ("VINI", "SN"). 97fa5e4d32SSunny Srivastava * 98fa5e4d32SSunny Srivastava * To read keyword from keyword type VPD, just keyword name has to be 99fa5e4d32SSunny Srivastava * supplied in the input parameter. Eg: ("SN"). 100fa5e4d32SSunny Srivastava * 101fa5e4d32SSunny Srivastava * @param[in] i_fruPath - EEPROM path. 102fa5e4d32SSunny Srivastava * @param[in] i_paramsToReadData - Input details. 103fa5e4d32SSunny Srivastava * 104fa5e4d32SSunny Srivastava * @throw 105fa5e4d32SSunny Srivastava * sdbusplus::xyz::openbmc_project::Common::Device::Error::ReadFailure. 106fa5e4d32SSunny Srivastava * 107fa5e4d32SSunny Srivastava * @return On success returns the read value in variant of array of bytes. 108fa5e4d32SSunny Srivastava * On failure throws exception. 109fa5e4d32SSunny Srivastava */ 11043fedabcSPatrick Williams types::DbusVariantType readKeyword( 11143fedabcSPatrick Williams const types::Path i_fruPath, 112fa5e4d32SSunny Srivastava const types::ReadVpdParams i_paramsToReadData); 113fa5e4d32SSunny Srivastava 114fa5e4d32SSunny Srivastava /** 115fa5e4d32SSunny Srivastava * @brief Collect single FRU VPD 116fa5e4d32SSunny Srivastava * API can be used to perform VPD collection for the given FRU, only if the 117fa5e4d32SSunny Srivastava * current state of the system matches with the state at which the FRU is 118fa5e4d32SSunny Srivastava * allowed for VPD recollection. 119fa5e4d32SSunny Srivastava * 120fa5e4d32SSunny Srivastava * @param[in] i_dbusObjPath - D-bus object path 121fa5e4d32SSunny Srivastava */ 122fa5e4d32SSunny Srivastava void collectSingleFruVpd( 123fa5e4d32SSunny Srivastava const sdbusplus::message::object_path& i_dbusObjPath); 124fa5e4d32SSunny Srivastava 125fa5e4d32SSunny Srivastava /** 126fa5e4d32SSunny Srivastava * @brief Delete single FRU VPD 127fa5e4d32SSunny Srivastava * API can be used to perform VPD deletion for the given FRU. 128fa5e4d32SSunny Srivastava * 129fa5e4d32SSunny Srivastava * @param[in] i_dbusObjPath - D-bus object path 130fa5e4d32SSunny Srivastava */ 131fa5e4d32SSunny Srivastava void deleteSingleFruVpd( 132fa5e4d32SSunny Srivastava const sdbusplus::message::object_path& i_dbusObjPath); 133fa5e4d32SSunny Srivastava 134fa5e4d32SSunny Srivastava /** 135fa5e4d32SSunny Srivastava * @brief Get expanded location code. 136fa5e4d32SSunny Srivastava * 137fa5e4d32SSunny Srivastava * API to get expanded location code from the unexpanded location code. 138fa5e4d32SSunny Srivastava * 139fa5e4d32SSunny Srivastava * @param[in] i_unexpandedLocationCode - Unexpanded location code. 140fa5e4d32SSunny Srivastava * @param[in] i_nodeNumber - Denotes the node in case of a multi-node 141fa5e4d32SSunny Srivastava * configuration, defaulted to zero incase of single node system. 142fa5e4d32SSunny Srivastava * 143fa5e4d32SSunny Srivastava * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 144fa5e4d32SSunny Srivastava * invalid argument. 145fa5e4d32SSunny Srivastava * 146fa5e4d32SSunny Srivastava * @return Location code of the FRU. 147fa5e4d32SSunny Srivastava */ 148fa5e4d32SSunny Srivastava std::string getExpandedLocationCode( 149fa5e4d32SSunny Srivastava const std::string& i_unexpandedLocationCode, 150fa5e4d32SSunny Srivastava [[maybe_unused]] const uint16_t i_nodeNumber = 0); 151fa5e4d32SSunny Srivastava 152fa5e4d32SSunny Srivastava /** 153fa5e4d32SSunny Srivastava * @brief Get D-Bus object path of FRUs from expanded location code. 154fa5e4d32SSunny Srivastava * 155fa5e4d32SSunny Srivastava * An API to get list of FRU D-Bus object paths for a given expanded 156fa5e4d32SSunny Srivastava * location code. 157fa5e4d32SSunny Srivastava * 158fa5e4d32SSunny Srivastava * @param[in] i_expandedLocationCode - Expanded location code. 159fa5e4d32SSunny Srivastava * 160fa5e4d32SSunny Srivastava * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 161fa5e4d32SSunny Srivastava * invalid argument. 162fa5e4d32SSunny Srivastava * 163fa5e4d32SSunny Srivastava * @return List of FRUs D-Bus object paths for the given location code. 164fa5e4d32SSunny Srivastava */ 165fa5e4d32SSunny Srivastava types::ListOfPaths getFrusByExpandedLocationCode( 166fa5e4d32SSunny Srivastava const std::string& i_expandedLocationCode); 167fa5e4d32SSunny Srivastava 168fa5e4d32SSunny Srivastava /** 169fa5e4d32SSunny Srivastava * @brief Get D-Bus object path of FRUs from unexpanded location code. 170fa5e4d32SSunny Srivastava * 171fa5e4d32SSunny Srivastava * An API to get list of FRU D-Bus object paths for a given unexpanded 172fa5e4d32SSunny Srivastava * location code. 173fa5e4d32SSunny Srivastava * 174fa5e4d32SSunny Srivastava * @param[in] i_unexpandedLocationCode - Unexpanded location code. 175fa5e4d32SSunny Srivastava * @param[in] i_nodeNumber - Denotes the node in case of a multi-node 176fa5e4d32SSunny Srivastava * configuration, defaulted to zero incase of single node system. 177fa5e4d32SSunny Srivastava * 178fa5e4d32SSunny Srivastava * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 179fa5e4d32SSunny Srivastava * invalid argument. 180fa5e4d32SSunny Srivastava * 181fa5e4d32SSunny Srivastava * @return List of FRUs D-Bus object paths for the given location code. 182fa5e4d32SSunny Srivastava */ 183fa5e4d32SSunny Srivastava types::ListOfPaths getFrusByUnexpandedLocationCode( 184fa5e4d32SSunny Srivastava const std::string& i_unexpandedLocationCode, 185fa5e4d32SSunny Srivastava [[maybe_unused]] const uint16_t i_nodeNumber = 0); 186fa5e4d32SSunny Srivastava 187fa5e4d32SSunny Srivastava /** 188fa5e4d32SSunny Srivastava * @brief Get Hardware path 189fa5e4d32SSunny Srivastava * API can be used to get EEPROM path for the given inventory path. 190fa5e4d32SSunny Srivastava * 191fa5e4d32SSunny Srivastava * @param[in] i_dbusObjPath - D-bus object path 192fa5e4d32SSunny Srivastava * 193fa5e4d32SSunny Srivastava * @return Corresponding EEPROM path. 194fa5e4d32SSunny Srivastava */ 195fa5e4d32SSunny Srivastava std::string getHwPath(const sdbusplus::message::object_path& i_dbusObjPath); 196fa5e4d32SSunny Srivastava 197fa5e4d32SSunny Srivastava /** 198fa5e4d32SSunny Srivastava * @brief Perform VPD recollection 199fa5e4d32SSunny Srivastava * This api will trigger parser to perform VPD recollection for FRUs that 200fa5e4d32SSunny Srivastava * can be replaced at standby. 201fa5e4d32SSunny Srivastava */ 202fa5e4d32SSunny Srivastava void performVpdRecollection(); 203fa5e4d32SSunny Srivastava 204fa5e4d32SSunny Srivastava /** 205fa5e4d32SSunny Srivastava * @brief Get unexpanded location code. 206fa5e4d32SSunny Srivastava * 207fa5e4d32SSunny Srivastava * An API to get unexpanded location code and node number from expanded 208fa5e4d32SSunny Srivastava * location code. 209fa5e4d32SSunny Srivastava * 210fa5e4d32SSunny Srivastava * @param[in] i_expandedLocationCode - Expanded location code. 211fa5e4d32SSunny Srivastava * 212fa5e4d32SSunny Srivastava * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 213fa5e4d32SSunny Srivastava * invalid argument. 214fa5e4d32SSunny Srivastava * 215fa5e4d32SSunny Srivastava * @return Location code in unexpanded format and its node number. 216fa5e4d32SSunny Srivastava */ 21743fedabcSPatrick Williams std::tuple<std::string, uint16_t> getUnexpandedLocationCode( 21843fedabcSPatrick Williams const std::string& i_expandedLocationCode); 219fa5e4d32SSunny Srivastava 220fa5e4d32SSunny Srivastava private: 221fa5e4d32SSunny Srivastava #ifdef IBM_SYSTEM 222fa5e4d32SSunny Srivastava /** 223fa5e4d32SSunny Srivastava * @brief API to set timer to detect system VPD over D-Bus. 224fa5e4d32SSunny Srivastava * 225fa5e4d32SSunny Srivastava * System VPD is required before bus name for VPD-Manager is claimed. Once 226fa5e4d32SSunny Srivastava * system VPD is published, VPD for other FRUs should be collected. This API 227fa5e4d32SSunny Srivastava * detects id system VPD is already published on D-Bus and based on that 228fa5e4d32SSunny Srivastava * triggers VPD collection for rest of the FRUs. 229fa5e4d32SSunny Srivastava * 230fa5e4d32SSunny Srivastava * Note: Throws exception in case of any failure. Needs to be handled by the 231fa5e4d32SSunny Srivastava * caller. 232fa5e4d32SSunny Srivastava */ 233fa5e4d32SSunny Srivastava void SetTimerToDetectSVPDOnDbus(); 234fa5e4d32SSunny Srivastava 235fa5e4d32SSunny Srivastava /** 236fa5e4d32SSunny Srivastava * @brief Set timer to detect and set VPD collection status for the system. 237fa5e4d32SSunny Srivastava * 238fa5e4d32SSunny Srivastava * Collection of FRU VPD is triggered in a separate thread. Resulting in 239fa5e4d32SSunny Srivastava * multiple threads at a given time. The API creates a timer which on 240fa5e4d32SSunny Srivastava * regular interval will check if all the threads were collected back and 241fa5e4d32SSunny Srivastava * sets the status of the VPD collection for the system accordingly. 242fa5e4d32SSunny Srivastava * 243fa5e4d32SSunny Srivastava * @throw std::runtime_error 244fa5e4d32SSunny Srivastava */ 245fa5e4d32SSunny Srivastava void SetTimerToDetectVpdCollectionStatus(); 246fa5e4d32SSunny Srivastava 247fa5e4d32SSunny Srivastava /** 248fa5e4d32SSunny Srivastava * @brief API to register callback for "AssetTag" property change. 249fa5e4d32SSunny Srivastava */ 250fa5e4d32SSunny Srivastava void registerAssetTagChangeCallback(); 251fa5e4d32SSunny Srivastava 252fa5e4d32SSunny Srivastava /** 253fa5e4d32SSunny Srivastava * @brief Callback API to be triggered on "AssetTag" property change. 254fa5e4d32SSunny Srivastava * 255fa5e4d32SSunny Srivastava * @param[in] i_msg - The callback message. 256fa5e4d32SSunny Srivastava */ 257fa5e4d32SSunny Srivastava void processAssetTagChangeCallback(sdbusplus::message_t& i_msg); 2581f4c8f81SSouvik Roy 2591f4c8f81SSouvik Roy /** 2601f4c8f81SSouvik Roy * @brief API to process VPD collection thread failed EEPROMs. 2611f4c8f81SSouvik Roy */ 2621f4c8f81SSouvik Roy void processFailedEeproms(); 2634c7798aaSSunny Srivastava 2644c7798aaSSunny Srivastava /** 265*022112bcSSunny Srivastava * @brief API to check and update PowerVS VPD. 266*022112bcSSunny Srivastava * 267*022112bcSSunny Srivastava * The API will read the existing data from the DBus and if found 268*022112bcSSunny Srivastava * different than what has been read from JSON, it will update the VPD with 269*022112bcSSunny Srivastava * JSON data on hardware and DBus both. 270*022112bcSSunny Srivastava * 271*022112bcSSunny Srivastava * @param[in] i_powerVsJsonObj - PowerVS JSON object. 272*022112bcSSunny Srivastava * @param[out] o_failedPathList - List of path failed to update. 273*022112bcSSunny Srivastava */ 274*022112bcSSunny Srivastava void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj, 275*022112bcSSunny Srivastava std::vector<std::string>& o_failedPathList); 276*022112bcSSunny Srivastava 277*022112bcSSunny Srivastava /** 2784c7798aaSSunny Srivastava * @brief API to handle configuration w.r.t. PowerVS systems. 2794c7798aaSSunny Srivastava * 2804c7798aaSSunny Srivastava * Some FRUs VPD is specific to powerVS system. The API detects the 2814c7798aaSSunny Srivastava * powerVS configuration and updates the VPD accordingly. 2824c7798aaSSunny Srivastava */ 2834c7798aaSSunny Srivastava void ConfigurePowerVsSystem(); 284fa5e4d32SSunny Srivastava #endif 285fa5e4d32SSunny Srivastava 286fa5e4d32SSunny Srivastava /** 287fa5e4d32SSunny Srivastava * @brief An api to check validity of unexpanded location code. 288fa5e4d32SSunny Srivastava * 289fa5e4d32SSunny Srivastava * @param[in] i_locationCode - Unexpanded location code. 290fa5e4d32SSunny Srivastava * 291fa5e4d32SSunny Srivastava * @return True/False based on validity check. 292fa5e4d32SSunny Srivastava */ 293fa5e4d32SSunny Srivastava bool isValidUnexpandedLocationCode(const std::string& i_locationCode); 294fa5e4d32SSunny Srivastava 295fa5e4d32SSunny Srivastava /** 296fa5e4d32SSunny Srivastava * @brief API to register callback for Host state change. 297fa5e4d32SSunny Srivastava */ 298fa5e4d32SSunny Srivastava void registerHostStateChangeCallback(); 299fa5e4d32SSunny Srivastava 300fa5e4d32SSunny Srivastava /** 301fa5e4d32SSunny Srivastava * @brief API to process host state change callback. 302fa5e4d32SSunny Srivastava * 303fa5e4d32SSunny Srivastava * @param[in] i_msg - Callback message. 304fa5e4d32SSunny Srivastava */ 305fa5e4d32SSunny Srivastava void hostStateChangeCallBack(sdbusplus::message_t& i_msg); 306fa5e4d32SSunny Srivastava 307fa5e4d32SSunny Srivastava // Shared pointer to asio context object. 308fa5e4d32SSunny Srivastava const std::shared_ptr<boost::asio::io_context>& m_ioContext; 309fa5e4d32SSunny Srivastava 310fa5e4d32SSunny Srivastava // Shared pointer to Dbus interface class. 311fa5e4d32SSunny Srivastava const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface; 312fa5e4d32SSunny Srivastava 313fa5e4d32SSunny Srivastava // Shared pointer to bus connection. 314fa5e4d32SSunny Srivastava const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection; 315fa5e4d32SSunny Srivastava 316fa5e4d32SSunny Srivastava // Shared pointer to worker class 317fa5e4d32SSunny Srivastava std::shared_ptr<Worker> m_worker; 318fa5e4d32SSunny Srivastava 319fa5e4d32SSunny Srivastava // Shared pointer to GpioMonitor class 320fa5e4d32SSunny Srivastava std::shared_ptr<GpioMonitor> m_gpioMonitor; 321fa5e4d32SSunny Srivastava 322fa5e4d32SSunny Srivastava // Variable to hold current collection status 323fa5e4d32SSunny Srivastava std::string m_vpdCollectionStatus = "NotStarted"; 324fa5e4d32SSunny Srivastava }; 325fa5e4d32SSunny Srivastava 326fa5e4d32SSunny Srivastava } // namespace vpd 327