blob: 3d3b3045e69bd715314a9a5e2e69dd7a59ab5fab [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.
59 */
60void processFFDCPackets(const openpower::phal::sbeError_t& sbeError,
61 const std::string& event,
62 openpower::dump::pel::FFDCData& pelAdditionalData);
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050063
64/**
65 * @class FFDCFile
66 * @brief This class is used to create ffdc data file and to get fd
67 */
68class FFDCFile
69{
70 public:
71 FFDCFile() = delete;
72 FFDCFile(const FFDCFile&) = delete;
73 FFDCFile& operator=(const FFDCFile&) = delete;
74 FFDCFile(FFDCFile&&) = delete;
75 FFDCFile& operator=(FFDCFile&&) = delete;
76
77 /**
78 * Used to pass json object to create unique ffdc file by using
79 * passed json data.
80 */
81 explicit FFDCFile(const json& pHALCalloutData);
82
83 /**
84 * Used to remove created ffdc file.
85 */
86 ~FFDCFile();
87
88 /**
89 * Used to get created ffdc file file descriptor id.
90 *
91 * @return file descriptor id
92 */
93 int getFileFD() const;
94
95 private:
96 /**
97 * Used to store callout ffdc data from passed json object.
98 */
99 std::string calloutData;
100
101 /**
102 * Used to store unique ffdc file name.
103 */
104 std::string calloutFile;
105
106 /**
107 * Used to store created ffdc file descriptor id.
108 */
109 int fileFD;
110
111 /**
112 * Used to create ffdc file to pass PEL api for creating
113 * pel records.
114 *
115 * @return NULL
116 */
117 void prepareFFDCFile();
118
119 /**
120 * Create unique ffdc file.
121 *
122 * @return NULL
123 */
124 void createCalloutFile();
125
126 /**
127 * Used write json object value into created file.
128 *
129 * @return NULL
130 */
131 void writeCalloutData();
132
133 /**
Manojkiran Edaeb462522024-06-17 11:05:27 +0530134 * Used set ffdc file seek position beginning to consume by PEL
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -0500135 *
136 * @return NULL
137 */
138 void setCalloutFileSeekPos();
139
140 /**
141 * Used to remove created ffdc file.
142 *
143 * @return NULL
144 */
145 void removeCalloutFile();
146
147}; // FFDCFile end
148
149} // namespace openpower::dump::pel