blob: 12c322590049181f4c16fc3566a9668b077df62c [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
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -05008namespace openpower
9{
10namespace pels
11{
12namespace sbe
13{
14
15// SBE FFDC sub type.
16constexpr uint8_t sbeFFDCSubType = 0xCB;
17
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -050018/**
19 * @brief FFDC Package structure and definitions based on SBE chip-op spec.
20 *
21 * SBE FFDC Starts with a header word (Word 0) that has an unique magic
22 * identifier code of 0xFFDC followed by the length of the FFDC package
23 * including the header itself. Word 1 contains a sequence id ,
24 * command-class and command fields.
25 * The sequence id field is ignored on the BMC side.
26 * Word 2 contains a 32 bit Return Code which acts like the key to the
27 * contents of subsequent FFDC Data Words (0-N).
28 *
29 * A FFDC package can typically contain debug data from either:
30 * 1. A failed hardware procedure (e.g. local variable values
31 * at point of failure) or
32 * 2. SBE firmware (e.g. traces, attributes and other information).
33 * ___________________________________________________________
34 * | | Byte 0 | Byte 1 | Byte 2 | Byte 3 |
35 * |----------------------------------------------------------|
36 * | Word 0 | Magic Bytes : 0xFFDC | Length in words (N+4) |
37 * | Word 1 | [Sequence ID] | Command-Class | Command |
38 * | Word 2 | Return Code 0..31 |
39 * | Word 3 | FFDC Data – Word 0 |
40 * | ... |
41 * | Word N+3 | FFDC Data – Word N |
42 * -----------------------------------------------------------
43 **/
44
45constexpr uint32_t sbeMaxFfdcPackets = 20;
46constexpr uint32_t ffdcPkgOneWord = 1;
47const uint16_t ffdcMagicCode = 0xFFDC;
48
49typedef struct
50{
51 uint32_t magic_bytes : 16;
52 uint32_t lengthinWords : 16;
53 uint32_t seqId : 16;
54 uint32_t cmdClass : 8;
55 uint32_t cmd : 8;
56 uint32_t fapiRc;
57} __attribute__((packed)) fapiFfdcBufType;
58
Jayanth Othayoth742b00b2022-06-30 05:16:57 -050059using LogSeverity = phosphor::logging::Entry::Level;
60
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050061/** @class SbeFFDC
62 *
63 * @brief This class provides higher level interface to process SBE ffdc
64 * for PEL based error logging infrastructure.
65 * Key Functionalities included here
66 * - Process the SBE FFDC data with the help of FAPI infrastructure and
67 * and create PEL required format Callout and user data for hardware
68 * procedure failures specific reason code
69 * - Add the user data section with SBE FFDC data to support SBE provided
70 * parser tool usage.
71 * - Any SBE FFDC processing will result additional log message in journal
72 * and will continue to create Error log with available data. This is to
73 * help user to analyse the failure.
74 */
75class SbeFFDC
76{
77 public:
78 SbeFFDC() = delete;
79 SbeFFDC(const SbeFFDC&) = delete;
80 SbeFFDC& operator=(const SbeFFDC&) = delete;
81 SbeFFDC(SbeFFDC&&) = delete;
82 SbeFFDC& operator=(SbeFFDC&&) = delete;
83
84 /**
85 * @brief Constructor
86 *
87 * Create PEL required format data from SBE provided FFDC data.
88 *
89 * @param[in] data - The AdditionalData properties in this PEL event
90 * @param[in] files - FFDC files that go into UserData sections
91 */
92 SbeFFDC(const AdditionalData& data, const PelFFDC& files);
93
94 /**
95 * @brief Destructor
96 *
97 * Deletes the temporary files
98 */
99 ~SbeFFDC()
100 {
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500101 try
102 {
103 for (auto path : paths)
104 {
105 if (!path.empty())
106 {
107 // Delete temporary file from file system
108 std::error_code ec;
109 std::filesystem::remove(path, ec);
110 // Clear path to indicate file has been deleted
111 path.clear();
112 }
113 }
114 }
115 catch (...)
116 {
117 // Destructors should not throw exceptions
118 }
119 }
120
121 /**
122 * @brief Helper function to return FFDC files information, which
123 * includes SBE FFDC specific callout information.
124 *
125 * return PelFFDC - pel formated FFDC files.
126 */
127 const PelFFDC& getSbeFFDC()
128 {
129 return ffdcFiles;
130 }
131
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500132 /**
133 * @brief Helper function to get severity type
134 *
135 * @return severity type as informational for spare clock
136 * failure type ffdc. Otherwise null string.
137 */
138 std::optional<LogSeverity> getSeverity();
139
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500140 private:
141 /**
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500142 * @brief Helper function to parse SBE FFDC file.
143 * parsing is based on the FFDC structure definition
144 * define initially in this file.
145 *
146 * @param fd SBE ffdc file descriptor
147 *
148 * Any failure during the process stops the function
149 * execution to support the raw SBE FFDC data based
150 * PEL creation.
151 */
152 void parse(int fd);
153
154 /**
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500155 * @brief Helper function to process SBE FFDC packet.
156 * This function call libekb function to process the
157 * FFDC packet and convert in to known format for PEL
158 * specific file creation. This function also creates
159 * json callout file and text type file, which includes
160 * the addition debug data included in SBE FFDC packet.
161 *
162 * @param ffdcPkt SBE FFDC packet
163 *
164 * Any failure during the process stops the function
165 * execution to support the raw SBE FFDC data based
166 * PEL creation.
167 */
168 void process(const sbeFfdcPacketType& ffdcPkt);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500169
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500170 /**
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500171 * @brief Temporary files path information created as part of FFDC
172 * processing.
173 */
174 std::vector<std::filesystem::path> paths;
175
176 /**
177 * @brief PEL FFDC files, which includes the user data sections and the
178 * added callout details if any, found during SBE FFDC processing.
179 */
180 PelFFDC ffdcFiles;
181
182 /**
183 * @brief Processor position associated to SBE FFDC
184 */
185 uint32_t procPos;
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500186
187 /**
188 * @brief Used to get type of ffdc
189 */
190 FFDC_TYPE ffdcType;
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500191};
192
193} // namespace sbe
194} // namespace pels
195} // namespace openpower