blob: effee2fee73eec09b77e0066c894b83b4d9756b2 [file] [log] [blame]
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -05001#pragma once
2
3#include "additional_data.hpp"
4#include "pel.hpp"
5
Jayanth Othayothc74c2202021-06-04 06:42:43 -05006#include <libekb.H>
7
Matt Spinler8c7bb862023-08-31 14:32:22 -05008#include <filesystem>
9
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050010namespace openpower
11{
12namespace pels
13{
14namespace sbe
15{
16
17// SBE FFDC sub type.
18constexpr uint8_t sbeFFDCSubType = 0xCB;
19
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -050020/**
21 * @brief FFDC Package structure and definitions based on SBE chip-op spec.
22 *
23 * SBE FFDC Starts with a header word (Word 0) that has an unique magic
24 * identifier code of 0xFFDC followed by the length of the FFDC package
25 * including the header itself. Word 1 contains a sequence id ,
26 * command-class and command fields.
27 * The sequence id field is ignored on the BMC side.
28 * Word 2 contains a 32 bit Return Code which acts like the key to the
29 * contents of subsequent FFDC Data Words (0-N).
30 *
31 * A FFDC package can typically contain debug data from either:
32 * 1. A failed hardware procedure (e.g. local variable values
33 * at point of failure) or
34 * 2. SBE firmware (e.g. traces, attributes and other information).
35 * ___________________________________________________________
36 * | | Byte 0 | Byte 1 | Byte 2 | Byte 3 |
37 * |----------------------------------------------------------|
38 * | Word 0 | Magic Bytes : 0xFFDC | Length in words (N+4) |
39 * | Word 1 | [Sequence ID] | Command-Class | Command |
40 * | Word 2 | Return Code 0..31 |
41 * | Word 3 | FFDC Data – Word 0 |
42 * | ... |
43 * | Word N+3 | FFDC Data – Word N |
44 * -----------------------------------------------------------
45 **/
46
Jayanth Othayoth742b00b2022-06-30 05:16:57 -050047using LogSeverity = phosphor::logging::Entry::Level;
48
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050049/** @class SbeFFDC
50 *
51 * @brief This class provides higher level interface to process SBE ffdc
52 * for PEL based error logging infrastructure.
53 * Key Functionalities included here
54 * - Process the SBE FFDC data with the help of FAPI infrastructure and
55 * and create PEL required format Callout and user data for hardware
56 * procedure failures specific reason code
57 * - Add the user data section with SBE FFDC data to support SBE provided
58 * parser tool usage.
59 * - Any SBE FFDC processing will result additional log message in journal
60 * and will continue to create Error log with available data. This is to
61 * help user to analyse the failure.
62 */
63class SbeFFDC
64{
65 public:
66 SbeFFDC() = delete;
67 SbeFFDC(const SbeFFDC&) = delete;
68 SbeFFDC& operator=(const SbeFFDC&) = delete;
69 SbeFFDC(SbeFFDC&&) = delete;
70 SbeFFDC& operator=(SbeFFDC&&) = delete;
71
72 /**
73 * @brief Constructor
74 *
75 * Create PEL required format data from SBE provided FFDC data.
76 *
77 * @param[in] data - The AdditionalData properties in this PEL event
78 * @param[in] files - FFDC files that go into UserData sections
79 */
80 SbeFFDC(const AdditionalData& data, const PelFFDC& files);
81
82 /**
83 * @brief Destructor
84 *
85 * Deletes the temporary files
86 */
87 ~SbeFFDC()
88 {
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050089 try
90 {
Matt Spinler8c7bb862023-08-31 14:32:22 -050091 for (const auto& [path, fd] : paths)
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050092 {
93 if (!path.empty())
94 {
95 // Delete temporary file from file system
96 std::error_code ec;
97 std::filesystem::remove(path, ec);
Matt Spinler8c7bb862023-08-31 14:32:22 -050098 }
99
100 if (fd != -1)
101 {
102 close(fd);
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500103 }
104 }
Matt Spinler8c7bb862023-08-31 14:32:22 -0500105 paths.clear();
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500106 }
107 catch (...)
108 {
109 // Destructors should not throw exceptions
110 }
111 }
112
113 /**
114 * @brief Helper function to return FFDC files information, which
115 * includes SBE FFDC specific callout information.
116 *
117 * return PelFFDC - pel formated FFDC files.
118 */
119 const PelFFDC& getSbeFFDC()
120 {
121 return ffdcFiles;
122 }
123
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500124 /**
125 * @brief Helper function to get severity type
126 *
127 * @return severity type as informational for spare clock
128 * failure type ffdc. Otherwise null string.
129 */
130 std::optional<LogSeverity> getSeverity();
131
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500132 private:
133 /**
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500134 * @brief Helper function to parse SBE FFDC file.
135 * parsing is based on the FFDC structure definition
136 * define initially in this file.
137 *
138 * @param fd SBE ffdc file descriptor
139 *
140 * Any failure during the process stops the function
141 * execution to support the raw SBE FFDC data based
142 * PEL creation.
143 */
144 void parse(int fd);
145
146 /**
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500147 * @brief Helper function to process SBE FFDC packet.
148 * This function call libekb function to process the
149 * FFDC packet and convert in to known format for PEL
150 * specific file creation. This function also creates
151 * json callout file and text type file, which includes
152 * the addition debug data included in SBE FFDC packet.
153 *
154 * @param ffdcPkt SBE FFDC packet
155 *
156 * Any failure during the process stops the function
157 * execution to support the raw SBE FFDC data based
158 * PEL creation.
159 */
160 void process(const sbeFfdcPacketType& ffdcPkt);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500161
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500162 /**
Matt Spinler8c7bb862023-08-31 14:32:22 -0500163 * @brief Temporary files path and FD information created as part of FFDC
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500164 * processing.
165 */
Matt Spinler8c7bb862023-08-31 14:32:22 -0500166 std::vector<std::pair<std::filesystem::path, int>> paths;
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500167
168 /**
169 * @brief PEL FFDC files, which includes the user data sections and the
170 * added callout details if any, found during SBE FFDC processing.
171 */
172 PelFFDC ffdcFiles;
173
174 /**
175 * @brief Processor position associated to SBE FFDC
176 */
177 uint32_t procPos;
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500178
179 /**
180 * @brief Used to get type of ffdc
181 */
182 FFDC_TYPE ffdcType;
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500183};
184
185} // namespace sbe
186} // namespace pels
187} // namespace openpower