blob: 9060dd9d62584461bec51d1a0e026040004245a4 [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 Srivastavac74c8ef2025-04-16 12:45:27 +0530111 * @brief Set timer to detect and set VPD collection status for the system.
112 *
113 * Collection of FRU VPD is triggered in a separate thread. Resulting in
114 * multiple threads at a given time. The API creates a timer which on
115 * regular interval will check if all the threads were collected back and
116 * sets the status of the VPD collection for the system accordingly.
117 *
118 * @throw std::runtime_error
119 */
120 void SetTimerToDetectVpdCollectionStatus();
121
122 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530123 * @brief API to process VPD collection thread failed EEPROMs.
124 */
125 void processFailedEeproms();
126
127 /**
128 * @brief API to check and update PowerVS VPD.
129 *
130 * The API will read the existing data from the DBus and if found
131 * different than what has been read from JSON, it will update the VPD with
132 * JSON data on hardware and DBus both.
133 *
134 * @param[in] i_powerVsJsonObj - PowerVS JSON object.
135 * @param[out] o_failedPathList - List of path failed to update.
136 */
137 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
138 std::vector<std::string>& o_failedPathList);
139 /**
140 * @brief API to handle configuration w.r.t. PowerVS systems.
141 *
142 * Some FRUs VPD is specific to powerVS system. The API detects the
143 * powerVS configuration and updates the VPD accordingly.
144 */
145 void ConfigurePowerVsSystem();
146
Sunny Srivastava78a50422025-04-25 11:17:56 +0530147 /**
148 * @brief API to perform initial setup before manager claims Bus name.
149 *
150 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
151 * corret device tree, inventory JSON w.r.t system should be linked and
152 * system VPD should be on DBus.
153 */
154 void performInitialSetup();
155
156 /**
Sunny Srivastava78a50422025-04-25 11:17:56 +0530157 * @brief Function to enable and bring MUX out of idle state.
158 *
159 * This finds all the MUX defined in the system json and enables them by
160 * setting the holdidle parameter to 0.
161 *
162 * @throw std::runtime_error
163 */
164 void enableMuxChips();
165
Anupama B R95083d42025-10-27 04:54:58 -0500166 /**
167 * @brief Checks whether the system is an RBMC prototype.
168 *
169 * @param[out] o_errCode - To set error code in case of error.
170 *
171 * @return true for RBMC prototype system, false otherwise.
172 */
Anupama B R657aaa82025-10-30 04:12:24 -0500173 bool isRbmcPrototypeSystem(uint16_t& o_errCode) const noexcept;
Anupama B R95083d42025-10-27 04:54:58 -0500174
175 /**
Anupama B R657aaa82025-10-30 04:12:24 -0500176 * @brief Checks and updates BMC position.
Anupama B R95083d42025-10-27 04:54:58 -0500177 *
Anupama B R657aaa82025-10-30 04:12:24 -0500178 * This API updates BMC position for the RBMC prototype
179 * system based on whether the motherboard EEPROM is accessible.
Anupama B R95083d42025-10-27 04:54:58 -0500180 *
Anupama B R657aaa82025-10-30 04:12:24 -0500181 * @param[out] o_bmcPosition - BMC position.
Anupama B R95083d42025-10-27 04:54:58 -0500182 */
Anupama B R657aaa82025-10-30 04:12:24 -0500183 void checkAndUpdateBmcPosition(size_t& o_bmcPosition) const noexcept;
Anupama B R95083d42025-10-27 04:54:58 -0500184
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530185 // Parsed system config json object.
186 nlohmann::json m_sysCfgJsonObj{};
187
188 // Shared pointer to worker class
189 std::shared_ptr<Worker>& m_worker;
190
191 // Shared pointer to backup and restore object.
192 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
193
194 // Shared pointer to GpioMonitor object.
195 std::shared_ptr<GpioMonitor> m_gpioMonitor;
196
197 // Shared pointer to Dbus interface class.
198 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
199
Anupama B Rda9806b2025-08-29 02:41:10 -0500200 // Shared pointer to Dbus collection progress interface class.
201 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
202
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530203 // Shared pointer to asio context object.
204 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
205
206 // Shared pointer to bus connection.
207 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500208
209 // Shared pointer to Listener object.
210 std::shared_ptr<Listener> m_eventListener;
Souvik Roya5e18b82025-09-25 05:59:56 +0000211
212 // Shared pointer to Logger object.
213 std::shared_ptr<Logger> m_logger;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530214};
215} // namespace vpd