blob: 82ee4189b53a48ff3842ecd3c4e6a488b06e766f [file] [log] [blame]
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -05001#pragma once
2
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -05003#include "xyz/openbmc_project/Logging/Entry/server.hpp"
4
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -05005#include <phal_exception.H>
6
7#include <nlohmann/json.hpp>
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -05008#include <xyz/openbmc_project/Logging/Create/server.hpp>
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -05009
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050010#include <optional>
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050011#include <string>
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050012#include <tuple>
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050013#include <vector>
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050014
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050015namespace openpower::dump::pel
16{
17
18using FFDCData = std::vector<std::pair<std::string, std::string>>;
19
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -050020using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
21
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050022using json = nlohmann::json;
23
24using namespace openpower::phal;
25
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050026using PELFFDCInfo = std::vector<std::tuple<
27 sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat,
28 uint8_t, uint8_t, sdbusplus::message::unix_fd>>;
29
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050030/**
31 * @brief Create SBE boot error PEL and return id
32 *
33 * @param[in] event - the event type
34 * @param[in] sbeError - SBE error object
35 * @param[in] ffdcData - failure data to append to PEL
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -050036 * @param[in] severity - severity of the log
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050037 * @return Platform log id
38 */
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050039uint32_t createSbeErrorPEL(
40 const std::string& event, const sbeError_t& sbeError,
41 const FFDCData& ffdcData, const Severity severity = Severity::Error,
42 const std::optional<PELFFDCInfo>& pelFFDCInfoOpt = std::nullopt);
43
44/**
45 * @brief Convert a FAPI2 severity code to PEL severity.
46 *
47 * @param[in] severity - Severity code from FAPI2 error logs.
48 * @return Severity - The corresponding Severity enumeration value.
49 */
50openpower::dump::pel::Severity convertSeverityToEnum(uint8_t severity);
51
52/**
53 * @brief Process FFDC packets and create PELs for each packet.
54 *
55 * @param[in] sbeError - An SBE error object containing FFDC packet information.
56 * @param[in] event - The event identifier associated with the PELs.
57 * @param[out] pelAdditionalData - A reference to additional PEL data to be
58 * included in the PEL.
SwethaParasaed53dc72025-01-24 01:07:01 -060059 * @return logIdList - List of Errors created
Dhruvaraj Subhashchandranf2298892024-04-21 04:42:55 -050060 */
SwethaParasaed53dc72025-01-24 01:07:01 -060061std::vector<uint32_t> processFFDCPackets(
62 const openpower::phal::sbeError_t& sbeError, const std::string& event,
63 openpower::dump::pel::FFDCData& pelAdditionalData);
64
65/**
66 * @brief Get PEL Id and Reason Code for a given logEntry
67 *
68 * @param[in] logId - dbus entry id.
69 *
70 * @return Platform Event Log Id, Reason Code
71 */
72std::tuple<uint32_t, std::string> getLogInfo(uint32_t logId);
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050073
74/**
75 * @class FFDCFile
76 * @brief This class is used to create ffdc data file and to get fd
77 */
78class FFDCFile
79{
80 public:
81 FFDCFile() = delete;
82 FFDCFile(const FFDCFile&) = delete;
83 FFDCFile& operator=(const FFDCFile&) = delete;
84 FFDCFile(FFDCFile&&) = delete;
85 FFDCFile& operator=(FFDCFile&&) = delete;
86
87 /**
88 * Used to pass json object to create unique ffdc file by using
89 * passed json data.
90 */
91 explicit FFDCFile(const json& pHALCalloutData);
92
93 /**
94 * Used to remove created ffdc file.
95 */
96 ~FFDCFile();
97
98 /**
99 * Used to get created ffdc file file descriptor id.
100 *
101 * @return file descriptor id
102 */
103 int getFileFD() const;
104
105 private:
106 /**
107 * Used to store callout ffdc data from passed json object.
108 */
109 std::string calloutData;
110
111 /**
112 * Used to store unique ffdc file name.
113 */
114 std::string calloutFile;
115
116 /**
117 * Used to store created ffdc file descriptor id.
118 */
119 int fileFD;
120
121 /**
122 * Used to create ffdc file to pass PEL api for creating
123 * pel records.
124 *
125 * @return NULL
126 */
127 void prepareFFDCFile();
128
129 /**
130 * Create unique ffdc file.
131 *
132 * @return NULL
133 */
134 void createCalloutFile();
135
136 /**
137 * Used write json object value into created file.
138 *
139 * @return NULL
140 */
141 void writeCalloutData();
142
143 /**
Manojkiran Edaeb462522024-06-17 11:05:27 +0530144 * Used set ffdc file seek position beginning to consume by PEL
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -0500145 *
146 * @return NULL
147 */
148 void setCalloutFileSeekPos();
149
150 /**
151 * Used to remove created ffdc file.
152 *
153 * @return NULL
154 */
155 void removeCalloutFile();
156
157}; // FFDCFile end
158
159} // namespace openpower::dump::pel