blob: 93186cf1f0d7900faff4f2ea18cc42fa374a73be [file] [log] [blame]
Chau Lya743e382024-10-26 11:12:22 +00001#pragma once
2
3#include "libpldm/pldm.h"
4
5#include "common/instance_id.hpp"
6#include "common/types.hpp"
7#include "oem_event_manager.hpp"
8#include "platform-mc/manager.hpp"
9#include "requester/handler.hpp"
10#include "requester/request.hpp"
11
12namespace pldm
13{
14namespace oem_ampere
15{
16using namespace pldm::pdr;
17
18using EventToMsgMap_t = std::unordered_map<uint8_t, std::string>;
19
20enum sensor_ids
21{
Chau Lycebf4762024-10-03 09:02:54 +000022 DDR_STATUS = 51,
Chau Ly3de0d942024-10-03 08:57:11 +000023 PCIE_HOT_PLUG = 169,
Chau Lya743e382024-10-26 11:12:22 +000024 BOOT_OVERALL = 175,
25};
26
27namespace boot
28{
29namespace status
30{
31enum boot_status
32{
33 BOOT_STATUS_SUCCESS = 0x80,
34 BOOT_STATUS_FAILURE = 0x81,
35};
36} // namespace status
37namespace stage
38{
39enum boot_stage
40{
41 UEFI_STATUS_CLASS_CODE_MIN = 0x00,
42 UEFI_STATUS_CLASS_CODE_MAX = 0x7f,
43 SECPRO = 0x90,
44 MPRO = 0x91,
45 ATF_BL1 = 0x92,
46 ATF_BL2 = 0x93,
47 DDR_INITIALIZATION = 0x94,
48 DDR_TRAINING = 0x95,
49 S0_DDR_TRAINING_FAILURE = 0x96,
50 ATF_BL31 = 0x97,
51 ATF_BL32 = 0x98,
52 S1_DDR_TRAINING_FAILURE = 0x99,
53};
54} // namespace stage
55} // namespace boot
56
57enum class log_level : int
58{
59 OK,
Chau Ly3de0d942024-10-03 08:57:11 +000060 WARNING,
61 CRITICAL,
Chau Lya743e382024-10-26 11:12:22 +000062 BIOSFWPANIC,
63};
64
Chau Ly3de0d942024-10-03 08:57:11 +000065/*
66 * PresentReading value format
67 * FIELD | COMMENT
68 * Bit 31 | Reserved
69 * Bit 30:24 | Media slot number (0 - 63) This field can be used by UEFI
70 * | to indicate the media slot number (such as NVMe/SSD slot)
71 * | (7 bits)
72 * Bit 23 | Operation status: 1 = operation failed
73 * | 0 = operation successful
74 * Bit 22 | Action: 0 - Insertion 1 - Removal
75 * Bit 21:18 | Function (4 bits)
76 * Bit 17:13 | Device (5 bits)
77 * Bit 12:5 | Bus (8 bits)
78 * Bit 4:0 | Segment (5 bits)
79 */
80typedef union
81{
82 uint32_t value;
83 struct
84 {
85 uint32_t segment:5;
86 uint32_t bus:8;
87 uint32_t device:5;
88 uint32_t function:4;
89 uint32_t action:1;
90 uint32_t opStatus:1;
91 uint32_t mediaSlot:7;
92 uint32_t reserved:1;
93 } __attribute__((packed)) bits;
94} PCIeHotPlugEventRecord_t;
95
Chau Lycebf4762024-10-03 09:02:54 +000096typedef union
97{
98 uint32_t value;
99 struct
100 {
101 uint32_t type:2;
102 uint32_t mcuRankIdx:3;
103 uint32_t reserved_1:3; // byte0
104 uint32_t sliceNum:4;
105 uint32_t upperNibbStatErr:1;
106 uint32_t lowerNibbStatErr:1;
107 uint32_t reserved_2:2; // byte1
108 uint32_t syndrome:4;
109 uint32_t reserved_3:4; // byte2
110 uint32_t reserved_byte:8;
111 } __attribute__((packed)) bits;
112} DIMMTrainingFailure_t;
113
114namespace ddr
115{
116namespace status
117{
118enum ddr_status
119{
120 NO_SYSTEM_LEVEL_ERROR = 0x01,
121 ECC_INITIALIZATION_FAILURE = 0x04,
122 CONFIGURATION_FAILURE = 0x05,
123 TRAINING_FAILURE = 0x06,
124 OTHER_FAILURE = 0x07,
125 BOOT_FAILURE_NO_VALID_CONFIG = 0x08,
126 FAILSAFE_ACTIVATED_NEXT_BOOT_SUCCESS = 0x09,
127};
128}
129} // namespace ddr
130
131namespace dimm
132{
133namespace status
134{
135enum dimm_status
136{
137 INSTALLED_NO_ERROR = 0x01,
138 NOT_INSTALLED = 0x02,
139 OTHER_FAILURE = 0x07,
140 INSTALLED_BUT_DISABLED = 0x10,
141 TRAINING_FAILURE = 0x12,
142 PMIC_HIGH_TEMP = 0x13,
143 TSx_HIGH_TEMP = 0x14,
144 SPD_HUB_HIGH_TEMP = 0x15,
145 PMIC_TEMP_ALERT = 0x16,
146};
147} // namespace status
148
149namespace training_failure
150{
151enum dimm_training_failure_type
152{
153 PHY_TRAINING_FAILURE_TYPE = 0x01,
154 DIMM_TRAINING_FAILURE_TYPE = 0x02,
155};
156
157namespace phy_syndrome
158{
159enum phy_training_failure_syndrome
160{
161 NA = 0x00,
162 PHY_TRAINING_SETUP_FAILURE = 0x01,
163 CA_LEVELING = 0x02,
164 PHY_WRITE_LEVEL_FAILURE = 0x03,
165 PHY_READ_GATE_LEVELING_FAILURE = 0x04,
166 PHY_READ_LEVEL_FAILURE = 0x05,
167 WRITE_DQ_LEVELING = 0x06,
168 PHY_SW_TRAINING_FAILURE = 0x07,
169};
170} // namespace phy_syndrome
171
172namespace dimm_syndrome
173{
174enum dimm_training_failure_syndrome
175{
176 NA = 0x00,
177 DRAM_VREFDQ_TRAINING_FAILURE = 0x01,
178 LRDIMM_DB_TRAINING_FAILURE = 0x02,
179 LRDRIMM_DB_SW_TRAINING_FAILURE = 0x03,
180};
181} // namespace dimm_syndrome
182} // namespace training_failure
183} // namespace dimm
184
Chau Lya743e382024-10-26 11:12:22 +0000185/**
186 * @brief OemEventManager
187 *
188 *
189 */
190class OemEventManager
191{
192 public:
193 OemEventManager() = delete;
194 OemEventManager(const OemEventManager&) = delete;
195 OemEventManager(OemEventManager&&) = delete;
196 OemEventManager& operator=(const OemEventManager&) = delete;
197 OemEventManager& operator=(OemEventManager&&) = delete;
198 virtual ~OemEventManager() = default;
199
200 explicit OemEventManager(
201 sdeventplus::Event& event,
202 requester::Handler<requester::Request>* /* handler */,
203 pldm::InstanceIdDb& /* instanceIdDb */) : event(event) {};
204
205 /** @brief Decode sensor event messages and handle correspondingly.
206 *
207 * @param[in] request - the request message of sensor event
208 * @param[in] payloadLength - the payload length of sensor event
209 * @param[in] formatVersion - the format version of sensor event
210 * @param[in] tid - TID
211 * @param[in] eventDataOffset - the event data offset of sensor event
212 *
213 * @return int - returned error code
214 */
215 int handleSensorEvent(const pldm_msg* request, size_t payloadLength,
216 uint8_t /* formatVersion */, pldm_tid_t tid,
217 size_t eventDataOffset);
218
219 protected:
220 /** @brief Create prefix string for logging message.
221 *
222 * @param[in] tid - TID
223 * @param[in] sensorId - Sensor ID
224 *
225 * @return std::string - the prefeix string
226 */
227 std::string prefixMsgStrCreation(pldm_tid_t tid, uint16_t sensorId);
228
229 /** @brief Log the message into Redfish SEL.
230 *
231 * @param[in] description - the logging message
232 * @param[in] logLevel - the logging level
233 */
234 void sendJournalRedfish(const std::string& description,
235 log_level& logLevel);
236
237 /** @brief Convert the one-hot DIMM index byte into a string of DIMM
238 * indexes.
239 *
240 * @param[in] dimmIdxs - the one-hot DIMM index byte
241 *
242 * @return std::string - the string of DIMM indexes
243 */
244 std::string dimmIdxsToString(uint32_t dimmIdxs);
245
Chau Lycebf4762024-10-03 09:02:54 +0000246 /** @brief Convert the DIMM training failure into logging string.
247 *
248 * @param[in] failureInfo - the one-hot DIMM index byte
249 *
250 * @return std::string - the returned logging string
251 */
252 std::string dimmTrainingFailureToMsg(uint32_t failureInfo);
253
Chau Ly3de0d942024-10-03 08:57:11 +0000254 /** @brief Handle numeric sensor event message from PCIe hot-plug sensor.
255 *
256 * @param[in] tid - TID
257 * @param[in] sensorId - Sensor ID
258 * @param[in] presentReading - the present reading of the sensor
259 */
260 void handlePCIeHotPlugEvent(pldm_tid_t tid, uint16_t sensorId,
261 uint32_t presentReading);
262
Chau Lya743e382024-10-26 11:12:22 +0000263 /** @brief Handle numeric sensor event message from boot overall sensor.
264 *
265 * @param[in] tid - TID
266 * @param[in] sensorId - Sensor ID
267 * @param[in] presentReading - the present reading of the sensor
268 */
269 void handleBootOverallEvent(pldm_tid_t /*tid*/, uint16_t /*sensorId*/,
270 uint32_t presentReading);
271
Chau Lycebf4762024-10-03 09:02:54 +0000272 /** @brief Handle numeric sensor event message from DIMM status sensor.
273 *
274 * @param[in] tid - TID
275 * @param[in] sensorId - Sensor ID
276 * @param[in] presentReading - the present reading of the sensor
277 */
278 void handleDIMMStatusEvent(pldm_tid_t tid, uint16_t sensorId,
279 uint32_t presentReading);
280
281 /** @brief Handle numeric sensor event message from DDR status sensor.
282 *
283 * @param[in] tid - TID
284 * @param[in] sensorId - Sensor ID
285 * @param[in] presentReading - the present reading of the sensor
286 */
287 void handleDDRStatusEvent(pldm_tid_t tid, uint16_t sensorId,
288 uint32_t presentReading);
289
Chau Lya743e382024-10-26 11:12:22 +0000290 /** @brief Handle numeric sensor event messages.
291 *
292 * @param[in] tid - TID
293 * @param[in] sensorId - Sensor ID
294 * @param[in] sensorData - the sensor data
295 * @param[in] sensorDataLength - the length of sensor data
296 *
297 * @return int - returned error code
298 */
299 int processNumericSensorEvent(pldm_tid_t tid, uint16_t sensorId,
300 const uint8_t* sensorData,
301 size_t sensorDataLength);
302
303 /** @brief Handle state sensor event messages.
304 *
305 * @param[in] tid - TID
306 * @param[in] sensorId - Sensor ID
307 * @param[in] sensorData - the sensor data
308 * @param[in] sensorDataLength - the length of sensor data
309 *
310 * @return int - returned error code
311 */
312 int processStateSensorEvent(pldm_tid_t tid, uint16_t sensorId,
313 const uint8_t* sensorData,
314 size_t sensorDataLength);
315
316 /** @brief Handle op state sensor event messages.
317 *
318 * @param[in] tid - TID
319 * @param[in] sensorId - Sensor ID
320 * @param[in] sensorData - the sensor data
321 * @param[in] sensorDataLength - the length of sensor data
322 *
323 * @return int - returned error code
324 */
325 int processSensorOpStateEvent(pldm_tid_t tid, uint16_t sensorId,
326 const uint8_t* sensorData,
327 size_t sensorDataLength);
328
329 /** @brief reference of main event loop of pldmd, primarily used to schedule
330 * work
331 */
332 sdeventplus::Event& event;
333};
334} // namespace oem_ampere
335} // namespace pldm