blob: d7eb67be216db3715b1eff1c00dc200aba7d8d85 [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
Dung Cao72c8aa02023-11-22 02:31:41 +0000256 /** @brief Handle the polled CPER (0x07, 0xFA) event class.
257 *
258 * @param[in] tid - terminus ID
259 * @param[out] eventId - Event ID
260 * @param[in] eventData - event data
261 * @param[in] eventDataSize - size of event data
262 *
263 * @return int - PLDM completion code
264 */
265 int processOemMsgPollEvent(pldm_tid_t tid, uint16_t eventId,
266 const uint8_t* eventData, size_t eventDataSize);
267
Chau Lya743e382024-10-26 11:12:22 +0000268 protected:
269 /** @brief Create prefix string for logging message.
270 *
271 * @param[in] tid - TID
272 * @param[in] sensorId - Sensor ID
273 *
274 * @return std::string - the prefeix string
275 */
276 std::string prefixMsgStrCreation(pldm_tid_t tid, uint16_t sensorId);
277
278 /** @brief Log the message into Redfish SEL.
279 *
280 * @param[in] description - the logging message
281 * @param[in] logLevel - the logging level
282 */
283 void sendJournalRedfish(const std::string& description,
284 log_level& logLevel);
285
286 /** @brief Convert the one-hot DIMM index byte into a string of DIMM
287 * indexes.
288 *
289 * @param[in] dimmIdxs - the one-hot DIMM index byte
290 *
291 * @return std::string - the string of DIMM indexes
292 */
293 std::string dimmIdxsToString(uint32_t dimmIdxs);
294
Thu Nguyen93d0ca32024-11-14 23:46:40 +0000295 /** @brief Convert sensor ID to DIMM index. Return maxDIMMInstantNum
296 * in failure.
297 *
298 * @param[in] sensorId - sensorID
299 *
300 * @return uint8_t - DIMM index
301 */
302 uint8_t sensorIdToDIMMIdx(const uint16_t& sensorId);
303
Chau Lycebf4762024-10-03 09:02:54 +0000304 /** @brief Convert the DIMM training failure into logging string.
305 *
306 * @param[in] failureInfo - the one-hot DIMM index byte
307 *
308 * @return std::string - the returned logging string
309 */
310 std::string dimmTrainingFailureToMsg(uint32_t failureInfo);
311
Chau Ly3de0d942024-10-03 08:57:11 +0000312 /** @brief Handle numeric sensor event message from PCIe hot-plug sensor.
313 *
314 * @param[in] tid - TID
315 * @param[in] sensorId - Sensor ID
316 * @param[in] presentReading - the present reading of the sensor
317 */
318 void handlePCIeHotPlugEvent(pldm_tid_t tid, uint16_t sensorId,
319 uint32_t presentReading);
320
Chau Lya743e382024-10-26 11:12:22 +0000321 /** @brief Handle numeric sensor event message from boot overall sensor.
322 *
323 * @param[in] tid - TID
324 * @param[in] sensorId - Sensor ID
325 * @param[in] presentReading - the present reading of the sensor
326 */
327 void handleBootOverallEvent(pldm_tid_t /*tid*/, uint16_t /*sensorId*/,
328 uint32_t presentReading);
329
Chau Lycebf4762024-10-03 09:02:54 +0000330 /** @brief Handle numeric sensor event message from DIMM status sensor.
331 *
332 * @param[in] tid - TID
333 * @param[in] sensorId - Sensor ID
334 * @param[in] presentReading - the present reading of the sensor
335 */
336 void handleDIMMStatusEvent(pldm_tid_t tid, uint16_t sensorId,
337 uint32_t presentReading);
338
339 /** @brief Handle numeric sensor event message from DDR status sensor.
340 *
341 * @param[in] tid - TID
342 * @param[in] sensorId - Sensor ID
343 * @param[in] presentReading - the present reading of the sensor
344 */
345 void handleDDRStatusEvent(pldm_tid_t tid, uint16_t sensorId,
346 uint32_t presentReading);
347
Chau Ly4cca3dc2024-10-03 09:07:09 +0000348 /** @brief Handle numeric sensor event message from VRD status sensor.
349 *
350 * @param[in] tid - TID
351 * @param[in] sensorId - Sensor ID
352 * @param[in] presentReading - the present reading of the sensor
353 */
354 void handleVRDStatusEvent(pldm_tid_t tid, uint16_t sensorId,
355 uint32_t presentReading);
356
Chau Lyb01357f2024-10-17 09:18:01 +0000357 /** @brief Handle numeric sensor event message from Watchdog status sensor.
358 *
359 * @param[in] tid - TID
360 * @param[in] sensorId - Sensor ID
361 * @param[in] presentReading - the present reading of the sensor
362 */
363 void handleNumericWatchdogEvent(pldm_tid_t tid, uint16_t sensorId,
364 uint32_t presentReading);
365
Chau Lya743e382024-10-26 11:12:22 +0000366 /** @brief Handle numeric sensor event messages.
367 *
368 * @param[in] tid - TID
369 * @param[in] sensorId - Sensor ID
370 * @param[in] sensorData - the sensor data
371 * @param[in] sensorDataLength - the length of sensor data
372 *
373 * @return int - returned error code
374 */
375 int processNumericSensorEvent(pldm_tid_t tid, uint16_t sensorId,
376 const uint8_t* sensorData,
377 size_t sensorDataLength);
378
379 /** @brief Handle state sensor event messages.
380 *
381 * @param[in] tid - TID
382 * @param[in] sensorId - Sensor ID
383 * @param[in] sensorData - the sensor data
384 * @param[in] sensorDataLength - the length of sensor data
385 *
386 * @return int - returned error code
387 */
388 int processStateSensorEvent(pldm_tid_t tid, uint16_t sensorId,
389 const uint8_t* sensorData,
390 size_t sensorDataLength);
391
392 /** @brief Handle op state sensor event messages.
393 *
394 * @param[in] tid - TID
395 * @param[in] sensorId - Sensor ID
396 * @param[in] sensorData - the sensor data
397 * @param[in] sensorDataLength - the length of sensor data
398 *
399 * @return int - returned error code
400 */
401 int processSensorOpStateEvent(pldm_tid_t tid, uint16_t sensorId,
402 const uint8_t* sensorData,
403 size_t sensorDataLength);
404
405 /** @brief reference of main event loop of pldmd, primarily used to schedule
406 * work
407 */
408 sdeventplus::Event& event;
409};
410} // namespace oem_ampere
411} // namespace pldm