xref: /openbmc/openpower-debug-collector/dump/create_pel.hpp (revision ac291d44b3822d6c9359f0397d7d4084b0954bd9)
1 #pragma once
2 
3 #include "xyz/openbmc_project/Logging/Entry/server.hpp"
4 
5 #include <phal_exception.H>
6 
7 #include <nlohmann/json.hpp>
8 #include <xyz/openbmc_project/Logging/Create/server.hpp>
9 
10 #include <optional>
11 #include <string>
12 #include <tuple>
13 #include <vector>
14 
15 namespace openpower::dump::pel
16 {
17 
18 using FFDCData = std::vector<std::pair<std::string, std::string>>;
19 
20 using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
21 
22 using json = nlohmann::json;
23 
24 using namespace openpower::phal;
25 
26 using PELFFDCInfo = std::vector<std::tuple<
27     sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat,
28     uint8_t, uint8_t, sdbusplus::message::unix_fd>>;
29 
30 /**
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
36  * @param[in] severity - severity of the log
37  * @return Platform log id
38  */
39 uint32_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  */
50 openpower::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.
59  * @return logIdList - List of Errors created
60  */
61 std::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  */
72 std::tuple<uint32_t, std::string> getLogInfo(uint32_t logId);
73 
74 /**
75  * @class FFDCFile
76  * @brief This class is used to create ffdc data file and to get fd
77  */
78 class 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     /**
144      * Used set ffdc file seek position beginning to consume by PEL
145      *
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
160