blob: d10323bd6591a9f2dbaf16dae9fb0a134127495e [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"
Souvik Roya5e18b82025-09-25 05:59:56 +00006#include "logger.hpp"
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05307#include "worker.hpp"
8
9#include <sdbusplus/asio/object_server.hpp>
10
11#include <memory>
12
Sunny Srivastava867ee752025-04-15 12:24:23 +053013namespace vpd
14{
15/**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053016 * @brief Class to handle OEM specific use case.
Sunny Srivastava867ee752025-04-15 12:24:23 +053017 *
18 * Few pre-requisites needs to be taken case specifically, which will be
19 * encapsulated by this class.
20 */
21class IbmHandler
22{
23 public:
24 /**
25 * List of deleted methods.
26 */
27 IbmHandler(const IbmHandler&) = delete;
28 IbmHandler& operator=(const IbmHandler&) = delete;
29 IbmHandler(IbmHandler&&) = delete;
30
31 /**
32 * @brief Constructor.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053033 *
34 * @param[in] o_worker - Reference to worker class object.
35 * @param[in] o_backupAndRestoreObj - Ref to back up and restore class
36 * object.
37 * @param[in] i_iFace - interface to implement.
Anupama B Rda9806b2025-08-29 02:41:10 -050038 * @param[in] i_progressiFace - Interface to track collection progress.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053039 * @param[in] i_ioCon - IO context.
40 * @param[in] i_asioConnection - Dbus Connection.
Sunny Srivastava867ee752025-04-15 12:24:23 +053041 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053042 IbmHandler(
43 std::shared_ptr<Worker>& o_worker,
44 std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj,
45 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace,
Anupama B Rda9806b2025-08-29 02:41:10 -050046 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace,
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053047 const std::shared_ptr<boost::asio::io_context>& i_ioCon,
48 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
49
Anupama B R7127ab42025-06-26 01:39:08 -050050 /**
51 * @brief API to collect all FRUs VPD.
52 *
53 * This api will call worker API to perform VPD collection for all FRUs
54 * present in the system config JSON and publish it on DBus. Also updates
55 * the Dbus VPD collection status property hosted under vpd-manager.
56 *
57 * Note:
58 * System VPD collection will always be skipped.
59 * If host is in power on state, FRUs marked as 'powerOffOnly' in the
60 * system config JSON will be skipped.
61 *
62 * @throw JsonException, runtime_error
63 */
64 void collectAllFruVpd();
65
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053066 private:
67 /**
Sunny Srivastavac607fe52025-11-18 20:52:23 +053068 * @brief An API to set appropriate device tree and JSON.
69 *
70 * This API based on system chooses corresponding device tree and JSON.
71 * If device tree change is required, it updates the "fitconfig" and reboots
72 * the system. Else it is NOOP.
73 *
74 * @throw std::exception
75 */
76 void setDeviceTreeAndJson();
77
78 /**
79 * @brief API to detect if system vpd is backed up in cache.
80 *
81 * System vpd can be cached either in cache or some other location. The
82 * information is extracted from system config json.
83 *
84 * @return True if the location is cache, fale otherwise.
85 */
86 bool isBackupOnCache();
87
88 /**
89 * @brief API to select system specific JSON.
90 *
91 * The API based on the IM value of VPD, will select appropriate JSON for
92 * the system. In case no system is found corresponding to the extracted IM
93 * value, error will be logged.
94 *
95 * @throw DataException, std::exception
96 *
97 * @param[out] o_systemJson - System JSON name.
98 * @param[in] i_parsedVpdMap - Parsed VPD map.
99 */
100 void getSystemJson(std::string& o_systemJson,
101 const types::VPDMapVariant& i_parsedVpdMap);
102
103 /**
104 * @brief An API to perform backup or restore of VPD.
105 *
106 * @param[in,out] io_srcVpdMap - Source VPD map.
107 */
108 void performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap);
109
110 /**
Sunny Srivastava57a4ee52025-11-19 12:13:50 +0530111 * @brief An API to parse and publish system VPD on D-Bus.
112 *
113 * @throw DataException, std::runtime_error
114 *
115 * @param[in] parsedVpdMap - Parsed VPD as a map.
116 */
117 void publishSystemVPD(const types::VPDMapVariant& i_parsedVpdMap);
118
119 /**
120 * @brief API to form asset tag string for the system.
121 *
122 * @param[in] i_parsedVpdMap - Parsed VPD map.
123 *
124 * @throw std::runtime_error
125 *
126 * @return - Formed asset tag string.
127 */
128 std::string createAssetTagString(
129 const types::VPDMapVariant& i_parsedVpdMap);
130
131 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530132 * @brief Set timer to detect and set VPD collection status for the system.
133 *
134 * Collection of FRU VPD is triggered in a separate thread. Resulting in
135 * multiple threads at a given time. The API creates a timer which on
136 * regular interval will check if all the threads were collected back and
137 * sets the status of the VPD collection for the system accordingly.
138 *
139 * @throw std::runtime_error
140 */
141 void SetTimerToDetectVpdCollectionStatus();
142
143 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530144 * @brief API to process VPD collection thread failed EEPROMs.
145 */
146 void processFailedEeproms();
147
148 /**
149 * @brief API to check and update PowerVS VPD.
150 *
151 * The API will read the existing data from the DBus and if found
152 * different than what has been read from JSON, it will update the VPD with
153 * JSON data on hardware and DBus both.
154 *
155 * @param[in] i_powerVsJsonObj - PowerVS JSON object.
156 * @param[out] o_failedPathList - List of path failed to update.
157 */
158 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
159 std::vector<std::string>& o_failedPathList);
160 /**
161 * @brief API to handle configuration w.r.t. PowerVS systems.
162 *
163 * Some FRUs VPD is specific to powerVS system. The API detects the
164 * powerVS configuration and updates the VPD accordingly.
165 */
166 void ConfigurePowerVsSystem();
167
Sunny Srivastava78a50422025-04-25 11:17:56 +0530168 /**
169 * @brief API to perform initial setup before manager claims Bus name.
170 *
171 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
172 * corret device tree, inventory JSON w.r.t system should be linked and
173 * system VPD should be on DBus.
174 */
175 void performInitialSetup();
176
177 /**
Sunny Srivastava78a50422025-04-25 11:17:56 +0530178 * @brief Function to enable and bring MUX out of idle state.
179 *
180 * This finds all the MUX defined in the system json and enables them by
181 * setting the holdidle parameter to 0.
182 *
183 * @throw std::runtime_error
184 */
185 void enableMuxChips();
186
Anupama B R95083d42025-10-27 04:54:58 -0500187 /**
188 * @brief Checks whether the system is an RBMC prototype.
189 *
190 * @param[out] o_errCode - To set error code in case of error.
191 *
192 * @return true for RBMC prototype system, false otherwise.
193 */
Anupama B R657aaa82025-10-30 04:12:24 -0500194 bool isRbmcPrototypeSystem(uint16_t& o_errCode) const noexcept;
Anupama B R95083d42025-10-27 04:54:58 -0500195
196 /**
Anupama B R657aaa82025-10-30 04:12:24 -0500197 * @brief Checks and updates BMC position.
Anupama B R95083d42025-10-27 04:54:58 -0500198 *
Anupama B R657aaa82025-10-30 04:12:24 -0500199 * This API updates BMC position for the RBMC prototype
200 * system based on whether the motherboard EEPROM is accessible.
Anupama B R95083d42025-10-27 04:54:58 -0500201 *
Anupama B R657aaa82025-10-30 04:12:24 -0500202 * @param[out] o_bmcPosition - BMC position.
Anupama B R95083d42025-10-27 04:54:58 -0500203 */
Anupama B R657aaa82025-10-30 04:12:24 -0500204 void checkAndUpdateBmcPosition(size_t& o_bmcPosition) const noexcept;
Anupama B R95083d42025-10-27 04:54:58 -0500205
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530206 // Parsed system config json object.
207 nlohmann::json m_sysCfgJsonObj{};
208
209 // Shared pointer to worker class
210 std::shared_ptr<Worker>& m_worker;
211
212 // Shared pointer to backup and restore object.
213 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
214
215 // Shared pointer to GpioMonitor object.
216 std::shared_ptr<GpioMonitor> m_gpioMonitor;
217
218 // Shared pointer to Dbus interface class.
219 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
220
Anupama B Rda9806b2025-08-29 02:41:10 -0500221 // Shared pointer to Dbus collection progress interface class.
222 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
223
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530224 // Shared pointer to asio context object.
225 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
226
227 // Shared pointer to bus connection.
228 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500229
230 // Shared pointer to Listener object.
231 std::shared_ptr<Listener> m_eventListener;
Souvik Roya5e18b82025-09-25 05:59:56 +0000232
233 // Shared pointer to Logger object.
234 std::shared_ptr<Logger> m_logger;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530235};
236} // namespace vpd