blob: 521a16bf788d48bd879c7c16d4895a56dccfda25 [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 Ly4cca3dc2024-10-03 09:07:09 +000023 PCP_VR_STATE = 75,
24 SOC_VR_STATE = 80,
25 DPHY_VR1_STATE = 85,
26 DPHY_VR2_STATE = 90,
27 D2D_VR_STATE = 95,
28 IOC_VR1_STATE = 100,
29 IOC_VR2_STATE = 105,
30 PCI_D_VR_STATE = 110,
31 PCI_A_VR_STATE = 115,
Chau Ly3de0d942024-10-03 08:57:11 +000032 PCIE_HOT_PLUG = 169,
Chau Lyef214b52024-10-16 09:40:38 +000033 SOC_HEALTH_AVAILABILITY = 170,
Chau Lya743e382024-10-26 11:12:22 +000034 BOOT_OVERALL = 175,
Chau Lyb01357f2024-10-17 09:18:01 +000035 WATCH_DOG = 179,
Chau Lya743e382024-10-26 11:12:22 +000036};
37
38namespace boot
39{
40namespace status
41{
42enum boot_status
43{
44 BOOT_STATUS_SUCCESS = 0x80,
45 BOOT_STATUS_FAILURE = 0x81,
46};
47} // namespace status
48namespace stage
49{
50enum boot_stage
51{
52 UEFI_STATUS_CLASS_CODE_MIN = 0x00,
53 UEFI_STATUS_CLASS_CODE_MAX = 0x7f,
54 SECPRO = 0x90,
55 MPRO = 0x91,
56 ATF_BL1 = 0x92,
57 ATF_BL2 = 0x93,
58 DDR_INITIALIZATION = 0x94,
59 DDR_TRAINING = 0x95,
60 S0_DDR_TRAINING_FAILURE = 0x96,
61 ATF_BL31 = 0x97,
62 ATF_BL32 = 0x98,
63 S1_DDR_TRAINING_FAILURE = 0x99,
64};
65} // namespace stage
66} // namespace boot
67
68enum class log_level : int
69{
70 OK,
Chau Ly3de0d942024-10-03 08:57:11 +000071 WARNING,
72 CRITICAL,
Chau Lya743e382024-10-26 11:12:22 +000073 BIOSFWPANIC,
74};
75
Chau Ly3de0d942024-10-03 08:57:11 +000076/*
77 * PresentReading value format
78 * FIELD | COMMENT
79 * Bit 31 | Reserved
80 * Bit 30:24 | Media slot number (0 - 63) This field can be used by UEFI
81 * | to indicate the media slot number (such as NVMe/SSD slot)
82 * | (7 bits)
83 * Bit 23 | Operation status: 1 = operation failed
84 * | 0 = operation successful
85 * Bit 22 | Action: 0 - Insertion 1 - Removal
86 * Bit 21:18 | Function (4 bits)
87 * Bit 17:13 | Device (5 bits)
88 * Bit 12:5 | Bus (8 bits)
89 * Bit 4:0 | Segment (5 bits)
90 */
91typedef union
92{
93 uint32_t value;
94 struct
95 {
96 uint32_t segment:5;
97 uint32_t bus:8;
98 uint32_t device:5;
99 uint32_t function:4;
100 uint32_t action:1;
101 uint32_t opStatus:1;
102 uint32_t mediaSlot:7;
103 uint32_t reserved:1;
104 } __attribute__((packed)) bits;
105} PCIeHotPlugEventRecord_t;
106
Chau Lycebf4762024-10-03 09:02:54 +0000107typedef union
108{
109 uint32_t value;
110 struct
111 {
112 uint32_t type:2;
113 uint32_t mcuRankIdx:3;
114 uint32_t reserved_1:3; // byte0
115 uint32_t sliceNum:4;
116 uint32_t upperNibbStatErr:1;
117 uint32_t lowerNibbStatErr:1;
118 uint32_t reserved_2:2; // byte1
119 uint32_t syndrome:4;
120 uint32_t reserved_3:4; // byte2
121 uint32_t reserved_byte:8;
122 } __attribute__((packed)) bits;
123} DIMMTrainingFailure_t;
124
125namespace ddr
126{
127namespace status
128{
129enum ddr_status
130{
131 NO_SYSTEM_LEVEL_ERROR = 0x01,
132 ECC_INITIALIZATION_FAILURE = 0x04,
133 CONFIGURATION_FAILURE = 0x05,
134 TRAINING_FAILURE = 0x06,
135 OTHER_FAILURE = 0x07,
136 BOOT_FAILURE_NO_VALID_CONFIG = 0x08,
137 FAILSAFE_ACTIVATED_NEXT_BOOT_SUCCESS = 0x09,
138};
139}
140} // namespace ddr
141
142namespace dimm
143{
144namespace status
145{
146enum dimm_status
147{
148 INSTALLED_NO_ERROR = 0x01,
149 NOT_INSTALLED = 0x02,
150 OTHER_FAILURE = 0x07,
151 INSTALLED_BUT_DISABLED = 0x10,
152 TRAINING_FAILURE = 0x12,
153 PMIC_HIGH_TEMP = 0x13,
154 TSx_HIGH_TEMP = 0x14,
155 SPD_HUB_HIGH_TEMP = 0x15,
156 PMIC_TEMP_ALERT = 0x16,
157};
158} // namespace status
159
160namespace training_failure
161{
162enum dimm_training_failure_type
163{
164 PHY_TRAINING_FAILURE_TYPE = 0x01,
165 DIMM_TRAINING_FAILURE_TYPE = 0x02,
166};
167
168namespace phy_syndrome
169{
170enum phy_training_failure_syndrome
171{
172 NA = 0x00,
173 PHY_TRAINING_SETUP_FAILURE = 0x01,
174 CA_LEVELING = 0x02,
175 PHY_WRITE_LEVEL_FAILURE = 0x03,
176 PHY_READ_GATE_LEVELING_FAILURE = 0x04,
177 PHY_READ_LEVEL_FAILURE = 0x05,
178 WRITE_DQ_LEVELING = 0x06,
179 PHY_SW_TRAINING_FAILURE = 0x07,
180};
181} // namespace phy_syndrome
182
183namespace dimm_syndrome
184{
185enum dimm_training_failure_syndrome
186{
187 NA = 0x00,
188 DRAM_VREFDQ_TRAINING_FAILURE = 0x01,
189 LRDIMM_DB_TRAINING_FAILURE = 0x02,
190 LRDRIMM_DB_SW_TRAINING_FAILURE = 0x03,
191};
192} // namespace dimm_syndrome
193} // namespace training_failure
194} // namespace dimm
195
Chau Ly4cca3dc2024-10-03 09:07:09 +0000196/*
197 * PresentReading value format
198 * FIELD | COMMENT
199 * Bit 31:30 | Reserved (2 bits)
200 * Bit 29 | A VR Critical condition observed (1 bit)
201 * Bit 28 | A VR Warning condition observed (1 bit)
202 * Bit 27:16 | Reserved (12 bits)
203 * Bit 15:8 | VR status byte high - The bit definition is the same as the
204 * | corresponding VR PMBUS STATUS_WORD (upper byte) (8 bits)
205 * Bit 7:0 | VR status byte low - The bit definition is the same as the
206 * | corresponding VR PMBUS STATUS_WORD (lower byte) (8 bits)
207 */
208typedef union
209{
210 uint32_t value;
211 struct
212 {
213 uint32_t vr_status_byte_low:8;
214 uint32_t vr_status_byte_high:8;
215 uint32_t reserved_1:12;
216 uint32_t warning:1;
217 uint32_t critical:1;
218 uint32_t reserved_2:2;
219 } __attribute__((packed)) bits;
220} VRDStatus_t;
221
Chau Lya743e382024-10-26 11:12:22 +0000222/**
223 * @brief OemEventManager
224 *
225 *
226 */
227class OemEventManager
228{
229 public:
230 OemEventManager() = delete;
231 OemEventManager(const OemEventManager&) = delete;
232 OemEventManager(OemEventManager&&) = delete;
233 OemEventManager& operator=(const OemEventManager&) = delete;
234 OemEventManager& operator=(OemEventManager&&) = delete;
235 virtual ~OemEventManager() = default;
236
237 explicit OemEventManager(
238 sdeventplus::Event& event,
239 requester::Handler<requester::Request>* /* handler */,
240 pldm::InstanceIdDb& /* instanceIdDb */) : event(event) {};
241
242 /** @brief Decode sensor event messages and handle correspondingly.
243 *
244 * @param[in] request - the request message of sensor event
245 * @param[in] payloadLength - the payload length of sensor event
246 * @param[in] formatVersion - the format version of sensor event
247 * @param[in] tid - TID
248 * @param[in] eventDataOffset - the event data offset of sensor event
249 *
250 * @return int - returned error code
251 */
252 int handleSensorEvent(const pldm_msg* request, size_t payloadLength,
253 uint8_t /* formatVersion */, pldm_tid_t tid,
254 size_t eventDataOffset);
255
256 protected:
257 /** @brief Create prefix string for logging message.
258 *
259 * @param[in] tid - TID
260 * @param[in] sensorId - Sensor ID
261 *
262 * @return std::string - the prefeix string
263 */
264 std::string prefixMsgStrCreation(pldm_tid_t tid, uint16_t sensorId);
265
266 /** @brief Log the message into Redfish SEL.
267 *
268 * @param[in] description - the logging message
269 * @param[in] logLevel - the logging level
270 */
271 void sendJournalRedfish(const std::string& description,
272 log_level& logLevel);
273
274 /** @brief Convert the one-hot DIMM index byte into a string of DIMM
275 * indexes.
276 *
277 * @param[in] dimmIdxs - the one-hot DIMM index byte
278 *
279 * @return std::string - the string of DIMM indexes
280 */
281 std::string dimmIdxsToString(uint32_t dimmIdxs);
282
Chau Lycebf4762024-10-03 09:02:54 +0000283 /** @brief Convert the DIMM training failure into logging string.
284 *
285 * @param[in] failureInfo - the one-hot DIMM index byte
286 *
287 * @return std::string - the returned logging string
288 */
289 std::string dimmTrainingFailureToMsg(uint32_t failureInfo);
290
Chau Ly3de0d942024-10-03 08:57:11 +0000291 /** @brief Handle numeric sensor event message from PCIe hot-plug sensor.
292 *
293 * @param[in] tid - TID
294 * @param[in] sensorId - Sensor ID
295 * @param[in] presentReading - the present reading of the sensor
296 */
297 void handlePCIeHotPlugEvent(pldm_tid_t tid, uint16_t sensorId,
298 uint32_t presentReading);
299
Chau Lya743e382024-10-26 11:12:22 +0000300 /** @brief Handle numeric sensor event message from boot overall sensor.
301 *
302 * @param[in] tid - TID
303 * @param[in] sensorId - Sensor ID
304 * @param[in] presentReading - the present reading of the sensor
305 */
306 void handleBootOverallEvent(pldm_tid_t /*tid*/, uint16_t /*sensorId*/,
307 uint32_t presentReading);
308
Chau Lycebf4762024-10-03 09:02:54 +0000309 /** @brief Handle numeric sensor event message from DIMM status sensor.
310 *
311 * @param[in] tid - TID
312 * @param[in] sensorId - Sensor ID
313 * @param[in] presentReading - the present reading of the sensor
314 */
315 void handleDIMMStatusEvent(pldm_tid_t tid, uint16_t sensorId,
316 uint32_t presentReading);
317
318 /** @brief Handle numeric sensor event message from DDR status sensor.
319 *
320 * @param[in] tid - TID
321 * @param[in] sensorId - Sensor ID
322 * @param[in] presentReading - the present reading of the sensor
323 */
324 void handleDDRStatusEvent(pldm_tid_t tid, uint16_t sensorId,
325 uint32_t presentReading);
326
Chau Ly4cca3dc2024-10-03 09:07:09 +0000327 /** @brief Handle numeric sensor event message from VRD status sensor.
328 *
329 * @param[in] tid - TID
330 * @param[in] sensorId - Sensor ID
331 * @param[in] presentReading - the present reading of the sensor
332 */
333 void handleVRDStatusEvent(pldm_tid_t tid, uint16_t sensorId,
334 uint32_t presentReading);
335
Chau Lyb01357f2024-10-17 09:18:01 +0000336 /** @brief Handle numeric sensor event message from Watchdog status sensor.
337 *
338 * @param[in] tid - TID
339 * @param[in] sensorId - Sensor ID
340 * @param[in] presentReading - the present reading of the sensor
341 */
342 void handleNumericWatchdogEvent(pldm_tid_t tid, uint16_t sensorId,
343 uint32_t presentReading);
344
Chau Lya743e382024-10-26 11:12:22 +0000345 /** @brief Handle numeric sensor event messages.
346 *
347 * @param[in] tid - TID
348 * @param[in] sensorId - Sensor ID
349 * @param[in] sensorData - the sensor data
350 * @param[in] sensorDataLength - the length of sensor data
351 *
352 * @return int - returned error code
353 */
354 int processNumericSensorEvent(pldm_tid_t tid, uint16_t sensorId,
355 const uint8_t* sensorData,
356 size_t sensorDataLength);
357
358 /** @brief Handle state sensor event messages.
359 *
360 * @param[in] tid - TID
361 * @param[in] sensorId - Sensor ID
362 * @param[in] sensorData - the sensor data
363 * @param[in] sensorDataLength - the length of sensor data
364 *
365 * @return int - returned error code
366 */
367 int processStateSensorEvent(pldm_tid_t tid, uint16_t sensorId,
368 const uint8_t* sensorData,
369 size_t sensorDataLength);
370
371 /** @brief Handle op state sensor event messages.
372 *
373 * @param[in] tid - TID
374 * @param[in] sensorId - Sensor ID
375 * @param[in] sensorData - the sensor data
376 * @param[in] sensorDataLength - the length of sensor data
377 *
378 * @return int - returned error code
379 */
380 int processSensorOpStateEvent(pldm_tid_t tid, uint16_t sensorId,
381 const uint8_t* sensorData,
382 size_t sensorDataLength);
383
384 /** @brief reference of main event loop of pldmd, primarily used to schedule
385 * work
386 */
387 sdeventplus::Event& event;
388};
389} // namespace oem_ampere
390} // namespace pldm