1fa5e4d32SSunny Srivastava #pragma once 2fa5e4d32SSunny Srivastava 3fa5e4d32SSunny Srivastava #include "constants.hpp" 4fa5e4d32SSunny Srivastava #include "types.hpp" 5fa5e4d32SSunny Srivastava 6fa5e4d32SSunny Srivastava #include <nlohmann/json.hpp> 7fa5e4d32SSunny Srivastava 8fa5e4d32SSunny Srivastava #include <mutex> 9fa5e4d32SSunny Srivastava #include <optional> 10fa5e4d32SSunny Srivastava #include <semaphore> 11fa5e4d32SSunny Srivastava #include <tuple> 12fa5e4d32SSunny Srivastava 13fa5e4d32SSunny Srivastava namespace vpd 14fa5e4d32SSunny Srivastava { 15fa5e4d32SSunny Srivastava /** 16fa5e4d32SSunny Srivastava * @brief A class to process and publish VPD data. 17fa5e4d32SSunny Srivastava * 18fa5e4d32SSunny Srivastava * The class works on VPD and is mainly responsible for following tasks: 19fa5e4d32SSunny Srivastava * 1) Select appropriate device tree and JSON. Reboot if required. 20fa5e4d32SSunny Srivastava * 2) Get desired parser using parser factory. 21fa5e4d32SSunny Srivastava * 3) Calling respective parser class to get parsed VPD. 22fa5e4d32SSunny Srivastava * 4) Arranging VPD data under required interfaces. 23fa5e4d32SSunny Srivastava * 5) Calling PIM to publish VPD. 24fa5e4d32SSunny Srivastava * 25fa5e4d32SSunny Srivastava * The class may also implement helper functions required for VPD handling. 26fa5e4d32SSunny Srivastava */ 27fa5e4d32SSunny Srivastava class Worker 28fa5e4d32SSunny Srivastava { 29fa5e4d32SSunny Srivastava public: 30fa5e4d32SSunny Srivastava /** 31fa5e4d32SSunny Srivastava * List of deleted functions. 32fa5e4d32SSunny Srivastava */ 33fa5e4d32SSunny Srivastava Worker(const Worker&); 34fa5e4d32SSunny Srivastava Worker& operator=(const Worker&); 35fa5e4d32SSunny Srivastava Worker(Worker&&) = delete; 36fa5e4d32SSunny Srivastava 37fa5e4d32SSunny Srivastava /** 38fa5e4d32SSunny Srivastava * @brief Constructor. 39fa5e4d32SSunny Srivastava * 40fa5e4d32SSunny Srivastava * In case the processing is not JSON based, no argument needs to be passed. 41fa5e4d32SSunny Srivastava * Constructor will also, based on symlink pick the correct JSON and 42fa5e4d32SSunny Srivastava * initialize the parsed JSON variable. 43fa5e4d32SSunny Srivastava * 44fa5e4d32SSunny Srivastava * @param[in] pathToConfigJSON - Path to the config JSON, if applicable. 45765cf7b8SSunny Srivastava * @param[in] i_maxThreadCount - Maximum thread while collecting FRUs VPD. 46fa5e4d32SSunny Srivastava * 47fa5e4d32SSunny Srivastava * Note: Throws std::exception in case of construction failure. Caller needs 48fa5e4d32SSunny Srivastava * to handle to detect successful object creation. 49fa5e4d32SSunny Srivastava */ 50765cf7b8SSunny Srivastava Worker(std::string pathToConfigJson = std::string(), 51765cf7b8SSunny Srivastava uint8_t i_maxThreadCount = constants::MAX_THREADS); 52fa5e4d32SSunny Srivastava 53fa5e4d32SSunny Srivastava /** 54fa5e4d32SSunny Srivastava * @brief Destructor 55fa5e4d32SSunny Srivastava */ 56fa5e4d32SSunny Srivastava ~Worker() = default; 57fa5e4d32SSunny Srivastava 58fa5e4d32SSunny Srivastava #ifdef IBM_SYSTEM 59fa5e4d32SSunny Srivastava /** 60fa5e4d32SSunny Srivastava * @brief API to perform initial setup before manager claims Bus name. 61fa5e4d32SSunny Srivastava * 62fa5e4d32SSunny Srivastava * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for 63fa5e4d32SSunny Srivastava * corret device tree, inventory JSON w.r.t system should be linked and 64fa5e4d32SSunny Srivastava * system VPD should be on DBus. 65fa5e4d32SSunny Srivastava */ 66fa5e4d32SSunny Srivastava void performInitialSetup(); 67fa5e4d32SSunny Srivastava #endif 68fa5e4d32SSunny Srivastava 69fa5e4d32SSunny Srivastava /** 70fa5e4d32SSunny Srivastava * @brief An API to check if system VPD is already published. 71fa5e4d32SSunny Srivastava * 72fa5e4d32SSunny Srivastava * @return Status, true if system is already collected else false. 73fa5e4d32SSunny Srivastava */ 74fa5e4d32SSunny Srivastava bool isSystemVPDOnDBus() const; 75fa5e4d32SSunny Srivastava 76fa5e4d32SSunny Srivastava /** 77fa5e4d32SSunny Srivastava * @brief API to process all FRUs presnt in config JSON file. 78fa5e4d32SSunny Srivastava * 79fa5e4d32SSunny Srivastava * This API based on config JSON passed/selected for the system, will 80fa5e4d32SSunny Srivastava * trigger parser for all the FRUs and publish it on DBus. 81fa5e4d32SSunny Srivastava * 82fa5e4d32SSunny Srivastava * Note: Config JSON file path should be passed to worker class constructor 83fa5e4d32SSunny Srivastava * to make use of this API. 84fa5e4d32SSunny Srivastava * 85fa5e4d32SSunny Srivastava */ 86fa5e4d32SSunny Srivastava void collectFrusFromJson(); 87fa5e4d32SSunny Srivastava 88fa5e4d32SSunny Srivastava /** 89fa5e4d32SSunny Srivastava * @brief API to parse VPD data 90fa5e4d32SSunny Srivastava * 91fa5e4d32SSunny Srivastava * @param[in] i_vpdFilePath - Path to the VPD file. 92fa5e4d32SSunny Srivastava */ 93fa5e4d32SSunny Srivastava types::VPDMapVariant parseVpdFile(const std::string& i_vpdFilePath); 94fa5e4d32SSunny Srivastava 95fa5e4d32SSunny Srivastava /** 96fa5e4d32SSunny Srivastava * @brief An API to populate DBus interfaces for a FRU. 97fa5e4d32SSunny Srivastava * 98fa5e4d32SSunny Srivastava * Note: Call this API to populate D-Bus. Also caller should handle empty 99fa5e4d32SSunny Srivastava * objectInterfaceMap. 100fa5e4d32SSunny Srivastava * 101fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 102fa5e4d32SSunny Srivastava * @param[out] objectInterfaceMap - Object and its interfaces map. 103fa5e4d32SSunny Srivastava * @param[in] vpdFilePath - EEPROM path of FRU. 104fa5e4d32SSunny Srivastava */ 105fa5e4d32SSunny Srivastava void populateDbus(const types::VPDMapVariant& parsedVpdMap, 106fa5e4d32SSunny Srivastava types::ObjectMap& objectInterfaceMap, 107fa5e4d32SSunny Srivastava const std::string& vpdFilePath); 108fa5e4d32SSunny Srivastava 109fa5e4d32SSunny Srivastava /** 110fa5e4d32SSunny Srivastava * @brief An API to delete FRU VPD over DBus. 111fa5e4d32SSunny Srivastava * 112fa5e4d32SSunny Srivastava * @param[in] i_dbusObjPath - Dbus object path of the FRU. 113fa5e4d32SSunny Srivastava * 114fa5e4d32SSunny Srivastava * @throw std::runtime_error if given input path is empty. 115fa5e4d32SSunny Srivastava */ 116fa5e4d32SSunny Srivastava void deleteFruVpd(const std::string& i_dbusObjPath); 117fa5e4d32SSunny Srivastava 118fa5e4d32SSunny Srivastava /** 119fa5e4d32SSunny Srivastava * @brief API to get status of VPD collection process. 120fa5e4d32SSunny Srivastava * 121fa5e4d32SSunny Srivastava * @return - True when done, false otherwise. 122fa5e4d32SSunny Srivastava */ isAllFruCollectionDone() const123fa5e4d32SSunny Srivastava inline bool isAllFruCollectionDone() const 124fa5e4d32SSunny Srivastava { 125fa5e4d32SSunny Srivastava return m_isAllFruCollected; 126fa5e4d32SSunny Srivastava } 127fa5e4d32SSunny Srivastava 128fa5e4d32SSunny Srivastava /** 129fa5e4d32SSunny Srivastava * @brief API to get system config JSON object 130fa5e4d32SSunny Srivastava * 131fa5e4d32SSunny Srivastava * @return System config JSON object. 132fa5e4d32SSunny Srivastava */ getSysCfgJsonObj() const133fa5e4d32SSunny Srivastava inline nlohmann::json getSysCfgJsonObj() const 134fa5e4d32SSunny Srivastava { 135fa5e4d32SSunny Srivastava return m_parsedJson; 136fa5e4d32SSunny Srivastava } 137fa5e4d32SSunny Srivastava 138fa5e4d32SSunny Srivastava /** 139fa5e4d32SSunny Srivastava * @brief API to get active thread count. 140fa5e4d32SSunny Srivastava * 141fa5e4d32SSunny Srivastava * Each FRU is collected in a separate thread. This API gives the active 142fa5e4d32SSunny Srivastava * thread collecting FRU's VPD at any given time. 143fa5e4d32SSunny Srivastava * 144fa5e4d32SSunny Srivastava * @return Count of active threads. 145fa5e4d32SSunny Srivastava */ getActiveThreadCount() const146fa5e4d32SSunny Srivastava size_t getActiveThreadCount() const 147fa5e4d32SSunny Srivastava { 148fa5e4d32SSunny Srivastava return m_activeCollectionThreadCount; 149fa5e4d32SSunny Srivastava } 150fa5e4d32SSunny Srivastava 1511f4c8f81SSouvik Roy /** 1521f4c8f81SSouvik Roy * @brief API to get list of EEPROMs for which thread creation failed. 1531f4c8f81SSouvik Roy * 1541f4c8f81SSouvik Roy * This API returns reference to list of EEPROM paths for which VPD 1551f4c8f81SSouvik Roy * collection thread creation has failed. Manager needs to process this list 1561f4c8f81SSouvik Roy * of EEPROMs and take appropriate action. 1571f4c8f81SSouvik Roy * 1581f4c8f81SSouvik Roy * @return reference to list of EEPROM paths for which VPD collection thread 1591f4c8f81SSouvik Roy * creation has failed 1601f4c8f81SSouvik Roy */ getFailedEepromPaths()1611f4c8f81SSouvik Roy inline std::forward_list<std::string>& getFailedEepromPaths() noexcept 1621f4c8f81SSouvik Roy { 1631f4c8f81SSouvik Roy return m_failedEepromPaths; 1641f4c8f81SSouvik Roy } 1651f4c8f81SSouvik Roy 166fa5e4d32SSunny Srivastava private: 167fa5e4d32SSunny Srivastava /** 168fa5e4d32SSunny Srivastava * @brief An API to parse and publish a FRU VPD over D-Bus. 169fa5e4d32SSunny Srivastava * 170fa5e4d32SSunny Srivastava * Note: This API will handle all the exceptions internally and will only 171fa5e4d32SSunny Srivastava * return status of parsing and publishing of VPD over D-Bus. 172fa5e4d32SSunny Srivastava * 173fa5e4d32SSunny Srivastava * @param[in] i_vpdFilePath - Path of file containing VPD. 174fa5e4d32SSunny Srivastava * @return Tuple of status and file path. Status, true if successfull else 175fa5e4d32SSunny Srivastava * false. 176fa5e4d32SSunny Srivastava */ 17743fedabcSPatrick Williams std::tuple<bool, std::string> parseAndPublishVPD( 17843fedabcSPatrick Williams const std::string& i_vpdFilePath); 179fa5e4d32SSunny Srivastava 180fa5e4d32SSunny Srivastava /** 181fa5e4d32SSunny Srivastava * @brief An API to set appropriate device tree and JSON. 182fa5e4d32SSunny Srivastava * 183fa5e4d32SSunny Srivastava * This API based on system chooses corresponding device tree and JSON. 184fa5e4d32SSunny Srivastava * If device tree change is required, it updates the "fitconfig" and reboots 185fa5e4d32SSunny Srivastava * the system. Else it is NOOP. 186fa5e4d32SSunny Srivastava * 187fa5e4d32SSunny Srivastava * @throw std::runtime_error 188fa5e4d32SSunny Srivastava */ 189fa5e4d32SSunny Srivastava void setDeviceTreeAndJson(); 190fa5e4d32SSunny Srivastava 191fa5e4d32SSunny Srivastava /** 192fa5e4d32SSunny Srivastava * @brief API to select system specific JSON. 193fa5e4d32SSunny Srivastava * 194fa5e4d32SSunny Srivastava * The API based on the IM value of VPD, will select appropriate JSON for 195fa5e4d32SSunny Srivastava * the system. In case no system is found corresponding to the extracted IM 196fa5e4d32SSunny Srivastava * value, error will be logged. 197fa5e4d32SSunny Srivastava * 198fa5e4d32SSunny Srivastava * @param[out] systemJson - System JSON name. 199fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD map. 200fa5e4d32SSunny Srivastava */ 201fa5e4d32SSunny Srivastava void getSystemJson(std::string& systemJson, 202fa5e4d32SSunny Srivastava const types::VPDMapVariant& parsedVpdMap); 203fa5e4d32SSunny Srivastava 204fa5e4d32SSunny Srivastava /** 205fa5e4d32SSunny Srivastava * @brief An API to read IM value from VPD. 206fa5e4d32SSunny Srivastava * 207fa5e4d32SSunny Srivastava * Note: Throws exception in case of error. Caller need to handle. 208fa5e4d32SSunny Srivastava * 209fa5e4d32SSunny Srivastava * @param[in] parsedVpd - Parsed VPD. 210fa5e4d32SSunny Srivastava */ 211fa5e4d32SSunny Srivastava std::string getIMValue(const types::IPZVpdMap& parsedVpd) const; 212fa5e4d32SSunny Srivastava 213fa5e4d32SSunny Srivastava /** 214fa5e4d32SSunny Srivastava * @brief An API to read HW version from VPD. 215fa5e4d32SSunny Srivastava * 216fa5e4d32SSunny Srivastava * Note: Throws exception in case of error. Caller need to handle. 217fa5e4d32SSunny Srivastava * 218fa5e4d32SSunny Srivastava * @param[in] parsedVpd - Parsed VPD. 219fa5e4d32SSunny Srivastava */ 220fa5e4d32SSunny Srivastava std::string getHWVersion(const types::IPZVpdMap& parsedVpd) const; 221fa5e4d32SSunny Srivastava 222fa5e4d32SSunny Srivastava /** 223fa5e4d32SSunny Srivastava * @brief An API to parse given VPD file path. 224fa5e4d32SSunny Srivastava * 225fa5e4d32SSunny Srivastava * @param[in] vpdFilePath - EEPROM file path. 226fa5e4d32SSunny Srivastava * @param[out] parsedVpd - Parsed VPD as a map. 227fa5e4d32SSunny Srivastava */ 228fa5e4d32SSunny Srivastava void fillVPDMap(const std::string& vpdFilePath, 229fa5e4d32SSunny Srivastava types::VPDMapVariant& parsedVpd); 230fa5e4d32SSunny Srivastava 231fa5e4d32SSunny Srivastava /** 232fa5e4d32SSunny Srivastava * @brief An API to parse and publish system VPD on D-Bus. 233fa5e4d32SSunny Srivastava * 234fa5e4d32SSunny Srivastava * Note: Throws exception in case of invalid VPD format. 235fa5e4d32SSunny Srivastava * 236fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 237fa5e4d32SSunny Srivastava */ 238fa5e4d32SSunny Srivastava void publishSystemVPD(const types::VPDMapVariant& parsedVpdMap); 239fa5e4d32SSunny Srivastava 240fa5e4d32SSunny Srivastava /** 241fa5e4d32SSunny Srivastava * @brief An API to process extrainterfaces w.r.t a FRU. 242fa5e4d32SSunny Srivastava * 243fa5e4d32SSunny Srivastava * @param[in] singleFru - JSON block for a single FRU. 244fa5e4d32SSunny Srivastava * @param[out] interfaces - Map to hold interface along with its properties. 245fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 246fa5e4d32SSunny Srivastava */ 247fa5e4d32SSunny Srivastava void processExtraInterfaces(const nlohmann::json& singleFru, 248fa5e4d32SSunny Srivastava types::InterfaceMap& interfaces, 249fa5e4d32SSunny Srivastava const types::VPDMapVariant& parsedVpdMap); 250fa5e4d32SSunny Srivastava 251fa5e4d32SSunny Srivastava /** 252fa5e4d32SSunny Srivastava * @brief An API to process embedded and synthesized FRUs. 253fa5e4d32SSunny Srivastava * 254fa5e4d32SSunny Srivastava * @param[in] singleFru - FRU to be processed. 255fa5e4d32SSunny Srivastava * @param[out] interfaces - Map to hold interface along with its properties. 256fa5e4d32SSunny Srivastava */ 257fa5e4d32SSunny Srivastava void processEmbeddedAndSynthesizedFrus(const nlohmann::json& singleFru, 258fa5e4d32SSunny Srivastava types::InterfaceMap& interfaces); 259fa5e4d32SSunny Srivastava 260fa5e4d32SSunny Srivastava /** 261fa5e4d32SSunny Srivastava * @brief An API to read process FRU based in CCIN. 262fa5e4d32SSunny Srivastava * 263fa5e4d32SSunny Srivastava * For some FRUs VPD can be processed only if the FRU has some specific 264fa5e4d32SSunny Srivastava * value for CCIN. In case the value is not from that set, VPD for those 265fa5e4d32SSunny Srivastava * FRUs can't be processed. 266fa5e4d32SSunny Srivastava * 267fa5e4d32SSunny Srivastava * @param[in] singleFru - Fru whose CCIN value needs to be matched. 268fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD map. 269fa5e4d32SSunny Srivastava */ 270fa5e4d32SSunny Srivastava bool processFruWithCCIN(const nlohmann::json& singleFru, 271fa5e4d32SSunny Srivastava const types::VPDMapVariant& parsedVpdMap); 272fa5e4d32SSunny Srivastava 273fa5e4d32SSunny Srivastava /** 274fa5e4d32SSunny Srivastava * @brief API to process json's inherit flag. 275fa5e4d32SSunny Srivastava * 276fa5e4d32SSunny Srivastava * Inherit flag denotes that some property in the child FRU needs to be 277fa5e4d32SSunny Srivastava * inherited from parent FRU. 278fa5e4d32SSunny Srivastava * 279fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 280fa5e4d32SSunny Srivastava * @param[out] interfaces - Map to hold interface along with its properties. 281fa5e4d32SSunny Srivastava */ 282fa5e4d32SSunny Srivastava void processInheritFlag(const types::VPDMapVariant& parsedVpdMap, 283fa5e4d32SSunny Srivastava types::InterfaceMap& interfaces); 284fa5e4d32SSunny Srivastava 285fa5e4d32SSunny Srivastava /** 286fa5e4d32SSunny Srivastava * @brief API to process json's "copyRecord" flag. 287fa5e4d32SSunny Srivastava * 288fa5e4d32SSunny Srivastava * copyRecord flag denotes if some record data needs to be copies in the 289fa5e4d32SSunny Srivastava * given FRU. 290fa5e4d32SSunny Srivastava * 291fa5e4d32SSunny Srivastava * @param[in] singleFru - FRU being processed. 292fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 293fa5e4d32SSunny Srivastava * @param[out] interfaces - Map to hold interface along with its properties. 294fa5e4d32SSunny Srivastava */ 295fa5e4d32SSunny Srivastava void processCopyRecordFlag(const nlohmann::json& singleFru, 296fa5e4d32SSunny Srivastava const types::VPDMapVariant& parsedVpdMap, 297fa5e4d32SSunny Srivastava types::InterfaceMap& interfaces); 298fa5e4d32SSunny Srivastava 299fa5e4d32SSunny Srivastava /** 300fa5e4d32SSunny Srivastava * @brief An API to populate IPZ VPD property map. 301fa5e4d32SSunny Srivastava * 302fa5e4d32SSunny Srivastava * @param[out] interfacePropMap - Map of interface and properties under it. 303fa5e4d32SSunny Srivastava * @param[in] keyordValueMap - Keyword value map of IPZ VPD. 304fa5e4d32SSunny Srivastava * @param[in] interfaceName - Name of the interface. 305fa5e4d32SSunny Srivastava */ 306fa5e4d32SSunny Srivastava void populateIPZVPDpropertyMap(types::InterfaceMap& interfacePropMap, 307fa5e4d32SSunny Srivastava const types::IPZKwdValueMap& keyordValueMap, 308fa5e4d32SSunny Srivastava const std::string& interfaceName); 309fa5e4d32SSunny Srivastava 310fa5e4d32SSunny Srivastava /** 311fa5e4d32SSunny Srivastava * @brief An API to populate Kwd VPD property map. 312fa5e4d32SSunny Srivastava * 313fa5e4d32SSunny Srivastava * @param[in] keyordValueMap - Keyword value map of Kwd VPD. 314fa5e4d32SSunny Srivastava * @param[out] interfaceMap - interface and property,value under it. 315fa5e4d32SSunny Srivastava */ 316fa5e4d32SSunny Srivastava void populateKwdVPDpropertyMap(const types::KeywordVpdMap& keyordVPDMap, 317fa5e4d32SSunny Srivastava types::InterfaceMap& interfaceMap); 318fa5e4d32SSunny Srivastava 319fa5e4d32SSunny Srivastava /** 320fa5e4d32SSunny Srivastava * @brief API to populate all required interface for a FRU. 321fa5e4d32SSunny Srivastava * 322fa5e4d32SSunny Srivastava * @param[in] interfaceJson - JSON containing interfaces to be populated. 323fa5e4d32SSunny Srivastava * @param[out] interfaceMap - Map to hold populated interfaces. 324fa5e4d32SSunny Srivastava * @param[in] parsedVpdMap - Parsed VPD as a map. 325fa5e4d32SSunny Srivastava */ 326fa5e4d32SSunny Srivastava void populateInterfaces(const nlohmann::json& interfaceJson, 327fa5e4d32SSunny Srivastava types::InterfaceMap& interfaceMap, 328fa5e4d32SSunny Srivastava const types::VPDMapVariant& parsedVpdMap); 329fa5e4d32SSunny Srivastava 330fa5e4d32SSunny Srivastava /** 331fa5e4d32SSunny Srivastava * @brief Check if the given CPU is an IO only chip. 332fa5e4d32SSunny Srivastava * 333fa5e4d32SSunny Srivastava * The CPU is termed as IO, whose all of the cores are bad and can never be 334fa5e4d32SSunny Srivastava * used. Those CPU chips can be used for IO purpose like connecting PCIe 335fa5e4d32SSunny Srivastava * devices etc., The CPU whose every cores are bad, can be identified from 336fa5e4d32SSunny Srivastava * the CP00 record's PG keyword, only if all of the 8 EQs' value equals 337fa5e4d32SSunny Srivastava * 0xE7F9FF. (1EQ has 4 cores grouped together by sharing its cache memory.) 338fa5e4d32SSunny Srivastava * 339fa5e4d32SSunny Srivastava * @param [in] pgKeyword - PG Keyword of CPU. 340fa5e4d32SSunny Srivastava * @return true if the given cpu is an IO, false otherwise. 341fa5e4d32SSunny Srivastava */ 342fa5e4d32SSunny Srivastava bool isCPUIOGoodOnly(const std::string& pgKeyword); 343fa5e4d32SSunny Srivastava 344fa5e4d32SSunny Srivastava /** 345fa5e4d32SSunny Srivastava * @brief API to prime inventory Objects. 346fa5e4d32SSunny Srivastava * 347fa5e4d32SSunny Srivastava * @param[in] i_vpdFilePath - EEPROM file path. 348fa5e4d32SSunny Srivastava * @return true if the prime inventory is success, false otherwise. 349fa5e4d32SSunny Srivastava */ 350fa5e4d32SSunny Srivastava bool primeInventory(const std::string& i_vpdFilePath); 351fa5e4d32SSunny Srivastava 352fa5e4d32SSunny Srivastava /** 353fa5e4d32SSunny Srivastava * @brief API to process preAction(base_action) defined in config JSON. 354fa5e4d32SSunny Srivastava * 355fa5e4d32SSunny Srivastava * @note sequence of tags under any given flag of preAction is EXTREMELY 356fa5e4d32SSunny Srivastava * important to ensure proper processing. The API will process all the 357fa5e4d32SSunny Srivastava * nested items under the base action sequentially. Also if any of the tag 358fa5e4d32SSunny Srivastava * processing fails, the code will not process remaining tags under the 359fa5e4d32SSunny Srivastava * flag. 360fa5e4d32SSunny Srivastava * ******** sample format ************** 361fa5e4d32SSunny Srivastava * fru EEPROM path: { 362fa5e4d32SSunny Srivastava * base_action: { 363fa5e4d32SSunny Srivastava * flag1: { 364fa5e4d32SSunny Srivastava * tag1: { 365fa5e4d32SSunny Srivastava * }, 366fa5e4d32SSunny Srivastava * tag2: { 367fa5e4d32SSunny Srivastava * } 368fa5e4d32SSunny Srivastava * } 369fa5e4d32SSunny Srivastava * flag2: { 370fa5e4d32SSunny Srivastava * tags: { 371fa5e4d32SSunny Srivastava * } 372fa5e4d32SSunny Srivastava * } 373fa5e4d32SSunny Srivastava * } 374fa5e4d32SSunny Srivastava * } 375fa5e4d32SSunny Srivastava * ************************************* 376fa5e4d32SSunny Srivastava * 377fa5e4d32SSunny Srivastava * @param[in] i_vpdFilePath - Path to the EEPROM file. 378fa5e4d32SSunny Srivastava * @param[in] i_flagToProcess - To identify which flag(s) needs to be 379fa5e4d32SSunny Srivastava * processed under PreAction tag of config JSON. 380fa5e4d32SSunny Srivastava * @return Execution status. 381fa5e4d32SSunny Srivastava */ 382fa5e4d32SSunny Srivastava bool processPreAction(const std::string& i_vpdFilePath, 383fa5e4d32SSunny Srivastava const std::string& i_flagToProcess); 384fa5e4d32SSunny Srivastava 385fa5e4d32SSunny Srivastava /** 386fa5e4d32SSunny Srivastava * @brief API to process postAction(base_action) defined in config JSON. 387fa5e4d32SSunny Srivastava * 388fa5e4d32SSunny Srivastava * @note Sequence of tags under any given flag of postAction is EXTREMELY 389fa5e4d32SSunny Srivastava * important to ensure proper processing. The API will process all the 390fa5e4d32SSunny Srivastava * nested items under the base action sequentially. Also if any of the tag 391fa5e4d32SSunny Srivastava * processing fails, the code will not process remaining tags under the 392fa5e4d32SSunny Srivastava * flag. 393fa5e4d32SSunny Srivastava * ******** sample format ************** 394fa5e4d32SSunny Srivastava * fru EEPROM path: { 395fa5e4d32SSunny Srivastava * base_action: { 396fa5e4d32SSunny Srivastava * flag1: { 397fa5e4d32SSunny Srivastava * tag1: { 398fa5e4d32SSunny Srivastava * }, 399fa5e4d32SSunny Srivastava * tag2: { 400fa5e4d32SSunny Srivastava * } 401fa5e4d32SSunny Srivastava * } 402fa5e4d32SSunny Srivastava * flag2: { 403fa5e4d32SSunny Srivastava * tags: { 404fa5e4d32SSunny Srivastava * } 405fa5e4d32SSunny Srivastava * } 406fa5e4d32SSunny Srivastava * } 407fa5e4d32SSunny Srivastava * } 408fa5e4d32SSunny Srivastava * ************************************* 409fa5e4d32SSunny Srivastava * Also, if post action is required to be processed only for FRUs with 410fa5e4d32SSunny Srivastava * certain CCIN then CCIN list can be provided under flag. 411fa5e4d32SSunny Srivastava * 412fa5e4d32SSunny Srivastava * @param[in] i_vpdFruPath - Path to the EEPROM file. 413fa5e4d32SSunny Srivastava * @param[in] i_flagToProcess - To identify which flag(s) needs to be 414fa5e4d32SSunny Srivastava * processed under postAction tag of config JSON. 415fa5e4d32SSunny Srivastava * @param[in] i_parsedVpd - Optional Parsed VPD map. If CCIN match is 416fa5e4d32SSunny Srivastava * required. 417fa5e4d32SSunny Srivastava * @return Execution status. 418fa5e4d32SSunny Srivastava */ 419fa5e4d32SSunny Srivastava bool processPostAction( 420fa5e4d32SSunny Srivastava const std::string& i_vpdFruPath, const std::string& i_flagToProcess, 421fa5e4d32SSunny Srivastava const std::optional<types::VPDMapVariant> i_parsedVpd = std::nullopt); 422fa5e4d32SSunny Srivastava 423fa5e4d32SSunny Srivastava /** 424fa5e4d32SSunny Srivastava * @brief Function to enable and bring MUX out of idle state. 425fa5e4d32SSunny Srivastava * 426fa5e4d32SSunny Srivastava * This finds all the MUX defined in the system json and enables them by 427fa5e4d32SSunny Srivastava * setting the holdidle parameter to 0. 428fa5e4d32SSunny Srivastava * 429fa5e4d32SSunny Srivastava * @throw std::runtime_error 430fa5e4d32SSunny Srivastava */ 431fa5e4d32SSunny Srivastava void enableMuxChips(); 432fa5e4d32SSunny Srivastava 433fa5e4d32SSunny Srivastava /** 434fa5e4d32SSunny Srivastava * @brief An API to perform backup or restore of VPD. 435fa5e4d32SSunny Srivastava * 436fa5e4d32SSunny Srivastava * @param[in,out] io_srcVpdMap - Source VPD map. 437fa5e4d32SSunny Srivastava */ 438fa5e4d32SSunny Srivastava void performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap); 439fa5e4d32SSunny Srivastava 440fa5e4d32SSunny Srivastava /** 441fa5e4d32SSunny Srivastava * @brief API to update "Functional" property. 442fa5e4d32SSunny Srivastava * 443fa5e4d32SSunny Srivastava * The API sets the default value for "Functional" property once if the 444fa5e4d32SSunny Srivastava * property is not yet populated over DBus. As the property value is not 445fa5e4d32SSunny Srivastava * controlled by the VPD-Collection process, if it is found already 446fa5e4d32SSunny Srivastava * populated, the functions skips re-populating the property so that already 447fa5e4d32SSunny Srivastava * existing value can be retained. 448fa5e4d32SSunny Srivastava * 449fa5e4d32SSunny Srivastava * @param[in] i_inventoryObjPath - Inventory path as read from config JSON. 450fa5e4d32SSunny Srivastava * @param[in] io_interfaces - Map to hold all the interfaces for the FRU. 451fa5e4d32SSunny Srivastava */ 452fa5e4d32SSunny Srivastava void processFunctionalProperty(const std::string& i_inventoryObjPath, 453fa5e4d32SSunny Srivastava types::InterfaceMap& io_interfaces); 454fa5e4d32SSunny Srivastava 455fa5e4d32SSunny Srivastava /** 456fa5e4d32SSunny Srivastava * @brief API to update "enabled" property. 457fa5e4d32SSunny Srivastava * 458fa5e4d32SSunny Srivastava * The API sets the default value for "enabled" property once if the 459fa5e4d32SSunny Srivastava * property is not yet populated over DBus. As the property value is not 460fa5e4d32SSunny Srivastava * controlled by the VPD-Collection process, if it is found already 461fa5e4d32SSunny Srivastava * populated, the functions skips re-populating the property so that already 462fa5e4d32SSunny Srivastava * existing value can be retained. 463fa5e4d32SSunny Srivastava * 464fa5e4d32SSunny Srivastava * @param[in] i_inventoryObjPath - Inventory path as read from config JSON. 465fa5e4d32SSunny Srivastava * @param[in] io_interfaces - Map to hold all the interfaces for the FRU. 466fa5e4d32SSunny Srivastava */ 467fa5e4d32SSunny Srivastava void processEnabledProperty(const std::string& i_inventoryObjPath, 468fa5e4d32SSunny Srivastava types::InterfaceMap& io_interfaces); 469fa5e4d32SSunny Srivastava 470fa5e4d32SSunny Srivastava /** 471fa5e4d32SSunny Srivastava * @brief API to form asset tag string for the system. 472fa5e4d32SSunny Srivastava * 473fa5e4d32SSunny Srivastava * @param[in] i_parsedVpdMap - Parsed VPD map. 474fa5e4d32SSunny Srivastava * 475fa5e4d32SSunny Srivastava * @throw std::runtime_error 476fa5e4d32SSunny Srivastava * 477fa5e4d32SSunny Srivastava * @return - Formed asset tag string. 478fa5e4d32SSunny Srivastava */ 47943fedabcSPatrick Williams std::string createAssetTagString( 48043fedabcSPatrick Williams const types::VPDMapVariant& i_parsedVpdMap); 481fa5e4d32SSunny Srivastava 482fa5e4d32SSunny Srivastava /** 483fa5e4d32SSunny Srivastava * @brief API to prime system blueprint. 484fa5e4d32SSunny Srivastava * 485fa5e4d32SSunny Srivastava * The API will traverse the system config JSON and will prime all the FRU 486fa5e4d32SSunny Srivastava * paths which qualifies for priming. 487fa5e4d32SSunny Srivastava */ 488fa5e4d32SSunny Srivastava void primeSystemBlueprint(); 489fa5e4d32SSunny Srivastava 490fa5e4d32SSunny Srivastava /** 491fa5e4d32SSunny Srivastava * @brief API to set symbolic link for system config JSON. 492fa5e4d32SSunny Srivastava * 493fa5e4d32SSunny Srivastava * Once correct device tree is set, symbolic link to the correct sytsem 494fa5e4d32SSunny Srivastava * config JSON is set to be used in subsequent BMC boot. 495fa5e4d32SSunny Srivastava * 496fa5e4d32SSunny Srivastava * @param[in] i_systemJson - system config JSON. 497fa5e4d32SSunny Srivastava */ 498fa5e4d32SSunny Srivastava void setJsonSymbolicLink(const std::string& i_systemJson); 499fa5e4d32SSunny Srivastava 500d159bb49SSunny Srivastava /** 501d159bb49SSunny Srivastava * @brief API to set present property. 502d159bb49SSunny Srivastava * 503*6a9553c8SSouvik Roy * This API updates the present property of the given FRU with the given 504*6a9553c8SSouvik Roy * value. Note: It is the responsibility of the caller to determine whether 505*6a9553c8SSouvik Roy * the present property for the FRU should be updated or not. 506*6a9553c8SSouvik Roy * 507d159bb49SSunny Srivastava * @param[in] i_vpdPath - EEPROM or inventory path. 508d159bb49SSunny Srivastava * @param[in] i_value - value to be set. 509d159bb49SSunny Srivastava */ 510d159bb49SSunny Srivastava void setPresentProperty(const std::string& i_fruPath, const bool& i_value); 511d159bb49SSunny Srivastava 51261611751SSunny Srivastava /** 51361611751SSunny Srivastava * @brief API to check if the path needs to be skipped for collection. 51461611751SSunny Srivastava * 51561611751SSunny Srivastava * Some FRUs, under some given scenarios should not be collected and 51661611751SSunny Srivastava * skipped. 51761611751SSunny Srivastava * 518765cf7b8SSunny Srivastava * @param[in] i_vpdFilePath - EEPROM path. 519765cf7b8SSunny Srivastava * 52061611751SSunny Srivastava * @return True - if path is empty or should be skipped, false otherwise. 52161611751SSunny Srivastava */ 52261611751SSunny Srivastava bool skipPathForCollection(const std::string& i_vpdFilePath); 52361611751SSunny Srivastava 524*6a9553c8SSouvik Roy /** 525*6a9553c8SSouvik Roy * @brief API to check if present property should be handled for given FRU. 526*6a9553c8SSouvik Roy * 527*6a9553c8SSouvik Roy * vpd-manager should update present property for a FRU if and only if it's 528*6a9553c8SSouvik Roy * not synthesized and vpd-manager handles present property for the FRU. 529*6a9553c8SSouvik Roy * This API assumes "handlePresence" tag is a subset of "synthesized" tag. 530*6a9553c8SSouvik Roy * 531*6a9553c8SSouvik Roy * @param[in] i_fru - JSON block for a single FRU. 532*6a9553c8SSouvik Roy * 533*6a9553c8SSouvik Roy * @return true if present property should be handled, false otherwise. 534*6a9553c8SSouvik Roy */ isPresentPropertyHandlingRequired(const nlohmann::json & i_fru) const535*6a9553c8SSouvik Roy inline bool isPresentPropertyHandlingRequired( 536*6a9553c8SSouvik Roy const nlohmann::json& i_fru) const noexcept 537*6a9553c8SSouvik Roy { 538*6a9553c8SSouvik Roy // TODO: revisit this to see if this logic can be optimized. 539*6a9553c8SSouvik Roy return !i_fru.value("synthesized", false) && 540*6a9553c8SSouvik Roy i_fru.value("handlePresence", true); 541*6a9553c8SSouvik Roy } 542*6a9553c8SSouvik Roy 543fa5e4d32SSunny Srivastava // Parsed JSON file. 544fa5e4d32SSunny Srivastava nlohmann::json m_parsedJson{}; 545fa5e4d32SSunny Srivastava 546fa5e4d32SSunny Srivastava // Hold if symlink is present or not. 547fa5e4d32SSunny Srivastava bool m_isSymlinkPresent = false; 548fa5e4d32SSunny Srivastava 549fa5e4d32SSunny Srivastava // Path to config JSON if applicable. 550fa5e4d32SSunny Srivastava std::string& m_configJsonPath; 551fa5e4d32SSunny Srivastava 552fa5e4d32SSunny Srivastava // Keeps track of active thread(s) doing VPD collection. 553fa5e4d32SSunny Srivastava size_t m_activeCollectionThreadCount = 0; 554fa5e4d32SSunny Srivastava 555fa5e4d32SSunny Srivastava // Holds status, if VPD collection has been done or not. 556fa5e4d32SSunny Srivastava // Note: This variable does not give information about successfull or failed 557fa5e4d32SSunny Srivastava // collection. It just states, if the VPD collection process is over or not. 558fa5e4d32SSunny Srivastava bool m_isAllFruCollected = false; 559fa5e4d32SSunny Srivastava 560fa5e4d32SSunny Srivastava // To distinguish the factory reset path. 561fa5e4d32SSunny Srivastava bool m_isFactoryResetDone = false; 562fa5e4d32SSunny Srivastava 563fa5e4d32SSunny Srivastava // Mutex to guard critical resource m_activeCollectionThreadCount. 564fa5e4d32SSunny Srivastava std::mutex m_mutex; 565fa5e4d32SSunny Srivastava 566fa5e4d32SSunny Srivastava // Counting semaphore to limit the number of threads. 567765cf7b8SSunny Srivastava std::counting_semaphore<constants::MAX_THREADS> m_semaphore; 5681f4c8f81SSouvik Roy 5691f4c8f81SSouvik Roy // List of EEPROM paths for which VPD collection thread creation has failed. 5701f4c8f81SSouvik Roy std::forward_list<std::string> m_failedEepromPaths; 571fa5e4d32SSunny Srivastava }; 572fa5e4d32SSunny Srivastava } // namespace vpd 573