blob: e2bf3dad74caf6fb4d475dd6a5c9f5731fa21fbe [file] [log] [blame]
Sunny Srivastava867ee752025-04-15 12:24:23 +05301#pragma once
2
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05303#include "backup_restore.hpp"
4#include "gpio_monitor.hpp"
Anupama B Rc7565ed2025-06-19 02:08:39 -05005#include "listener.hpp"
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05306#include "worker.hpp"
7
8#include <sdbusplus/asio/object_server.hpp>
9
10#include <memory>
11
Sunny Srivastava867ee752025-04-15 12:24:23 +053012namespace vpd
13{
14/**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053015 * @brief Class to handle OEM specific use case.
Sunny Srivastava867ee752025-04-15 12:24:23 +053016 *
17 * Few pre-requisites needs to be taken case specifically, which will be
18 * encapsulated by this class.
19 */
20class IbmHandler
21{
22 public:
23 /**
24 * List of deleted methods.
25 */
26 IbmHandler(const IbmHandler&) = delete;
27 IbmHandler& operator=(const IbmHandler&) = delete;
28 IbmHandler(IbmHandler&&) = delete;
29
30 /**
31 * @brief Constructor.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053032 *
33 * @param[in] o_worker - Reference to worker class object.
34 * @param[in] o_backupAndRestoreObj - Ref to back up and restore class
35 * object.
36 * @param[in] i_iFace - interface to implement.
Anupama B Rda9806b2025-08-29 02:41:10 -050037 * @param[in] i_progressiFace - Interface to track collection progress.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053038 * @param[in] i_ioCon - IO context.
39 * @param[in] i_asioConnection - Dbus Connection.
Sunny Srivastava867ee752025-04-15 12:24:23 +053040 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053041 IbmHandler(
42 std::shared_ptr<Worker>& o_worker,
43 std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj,
44 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace,
Anupama B Rda9806b2025-08-29 02:41:10 -050045 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace,
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053046 const std::shared_ptr<boost::asio::io_context>& i_ioCon,
47 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
48
Anupama B R7127ab42025-06-26 01:39:08 -050049 /**
50 * @brief API to collect all FRUs VPD.
51 *
52 * This api will call worker API to perform VPD collection for all FRUs
53 * present in the system config JSON and publish it on DBus. Also updates
54 * the Dbus VPD collection status property hosted under vpd-manager.
55 *
56 * Note:
57 * System VPD collection will always be skipped.
58 * If host is in power on state, FRUs marked as 'powerOffOnly' in the
59 * system config JSON will be skipped.
60 *
61 * @throw JsonException, runtime_error
62 */
63 void collectAllFruVpd();
64
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053065 private:
66 /**
67 * @brief API to set timer to detect system VPD over D-Bus.
68 *
69 * System VPD is required before bus name for VPD-Manager is claimed. Once
70 * system VPD is published, VPD for other FRUs should be collected. This API
71 * detects id system VPD is already published on D-Bus and based on that
72 * triggers VPD collection for rest of the FRUs.
73 *
74 * Note: Throws exception in case of any failure. Needs to be handled by the
75 * caller.
76 */
77 void SetTimerToDetectSVPDOnDbus();
78
79 /**
80 * @brief Set timer to detect and set VPD collection status for the system.
81 *
82 * Collection of FRU VPD is triggered in a separate thread. Resulting in
83 * multiple threads at a given time. The API creates a timer which on
84 * regular interval will check if all the threads were collected back and
85 * sets the status of the VPD collection for the system accordingly.
86 *
87 * @throw std::runtime_error
88 */
89 void SetTimerToDetectVpdCollectionStatus();
90
91 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053092 * @brief API to process VPD collection thread failed EEPROMs.
93 */
94 void processFailedEeproms();
95
96 /**
97 * @brief API to check and update PowerVS VPD.
98 *
99 * The API will read the existing data from the DBus and if found
100 * different than what has been read from JSON, it will update the VPD with
101 * JSON data on hardware and DBus both.
102 *
103 * @param[in] i_powerVsJsonObj - PowerVS JSON object.
104 * @param[out] o_failedPathList - List of path failed to update.
105 */
106 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
107 std::vector<std::string>& o_failedPathList);
108 /**
109 * @brief API to handle configuration w.r.t. PowerVS systems.
110 *
111 * Some FRUs VPD is specific to powerVS system. The API detects the
112 * powerVS configuration and updates the VPD accordingly.
113 */
114 void ConfigurePowerVsSystem();
115
Sunny Srivastava78a50422025-04-25 11:17:56 +0530116 /**
117 * @brief API to perform initial setup before manager claims Bus name.
118 *
119 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
120 * corret device tree, inventory JSON w.r.t system should be linked and
121 * system VPD should be on DBus.
122 */
123 void performInitialSetup();
124
125 /**
126 * @brief API to prime system blueprint.
127 *
128 * The API will traverse the system config JSON and will prime all the FRU
129 * paths which qualifies for priming.
130 */
131 void primeSystemBlueprint();
132
133 /**
134 * @brief Function to enable and bring MUX out of idle state.
135 *
136 * This finds all the MUX defined in the system json and enables them by
137 * setting the holdidle parameter to 0.
138 *
139 * @throw std::runtime_error
140 */
141 void enableMuxChips();
142
Anupama B Rec7f8862025-05-23 01:21:01 -0500143 /**
144 * @brief API to check if priming is required.
145 *
146 * The API will traverse the system config JSON and counts the FRU
147 * paths which qualifies for priming and compares with count of object paths
148 * found under PIM which hosts the "com.ibm.VPD.Collection" interface. If
149 * the dbus count is equal to or greater than the count from JSON config
150 * consider as priming is not required.
151 *
152 * @return true if priming is required, false otherwise.
153 */
154 bool isPrimingRequired() const noexcept;
155
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530156 // Parsed system config json object.
157 nlohmann::json m_sysCfgJsonObj{};
158
159 // Shared pointer to worker class
160 std::shared_ptr<Worker>& m_worker;
161
162 // Shared pointer to backup and restore object.
163 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
164
165 // Shared pointer to GpioMonitor object.
166 std::shared_ptr<GpioMonitor> m_gpioMonitor;
167
168 // Shared pointer to Dbus interface class.
169 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
170
Anupama B Rda9806b2025-08-29 02:41:10 -0500171 // Shared pointer to Dbus collection progress interface class.
172 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
173
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530174 // Shared pointer to asio context object.
175 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
176
177 // Shared pointer to bus connection.
178 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500179
180 // Shared pointer to Listener object.
181 std::shared_ptr<Listener> m_eventListener;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530182};
183} // namespace vpd