blob: bff206c2de69a4a2c2787d97d69dedd449524c60 [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 Othayothe8bdeea2021-06-03 03:01:16 -050059/** @class SbeFFDC
60 *
61 * @brief This class provides higher level interface to process SBE ffdc
62 * for PEL based error logging infrastructure.
63 * Key Functionalities included here
64 * - Process the SBE FFDC data with the help of FAPI infrastructure and
65 * and create PEL required format Callout and user data for hardware
66 * procedure failures specific reason code
67 * - Add the user data section with SBE FFDC data to support SBE provided
68 * parser tool usage.
69 * - Any SBE FFDC processing will result additional log message in journal
70 * and will continue to create Error log with available data. This is to
71 * help user to analyse the failure.
72 */
73class SbeFFDC
74{
75 public:
76 SbeFFDC() = delete;
77 SbeFFDC(const SbeFFDC&) = delete;
78 SbeFFDC& operator=(const SbeFFDC&) = delete;
79 SbeFFDC(SbeFFDC&&) = delete;
80 SbeFFDC& operator=(SbeFFDC&&) = delete;
81
82 /**
83 * @brief Constructor
84 *
85 * Create PEL required format data from SBE provided FFDC data.
86 *
87 * @param[in] data - The AdditionalData properties in this PEL event
88 * @param[in] files - FFDC files that go into UserData sections
89 */
90 SbeFFDC(const AdditionalData& data, const PelFFDC& files);
91
92 /**
93 * @brief Destructor
94 *
95 * Deletes the temporary files
96 */
97 ~SbeFFDC()
98 {
99
100 try
101 {
102 for (auto path : paths)
103 {
104 if (!path.empty())
105 {
106 // Delete temporary file from file system
107 std::error_code ec;
108 std::filesystem::remove(path, ec);
109 // Clear path to indicate file has been deleted
110 path.clear();
111 }
112 }
113 }
114 catch (...)
115 {
116 // Destructors should not throw exceptions
117 }
118 }
119
120 /**
121 * @brief Helper function to return FFDC files information, which
122 * includes SBE FFDC specific callout information.
123 *
124 * return PelFFDC - pel formated FFDC files.
125 */
126 const PelFFDC& getSbeFFDC()
127 {
128 return ffdcFiles;
129 }
130
131 private:
132 /**
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500133 * @brief Helper function to parse SBE FFDC file.
134 * parsing is based on the FFDC structure definition
135 * define initially in this file.
136 *
137 * @param fd SBE ffdc file descriptor
138 *
139 * Any failure during the process stops the function
140 * execution to support the raw SBE FFDC data based
141 * PEL creation.
142 */
143 void parse(int fd);
144
145 /**
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500146 * @brief Helper function to process SBE FFDC packet.
147 * This function call libekb function to process the
148 * FFDC packet and convert in to known format for PEL
149 * specific file creation. This function also creates
150 * json callout file and text type file, which includes
151 * the addition debug data included in SBE FFDC packet.
152 *
153 * @param ffdcPkt SBE FFDC packet
154 *
155 * Any failure during the process stops the function
156 * execution to support the raw SBE FFDC data based
157 * PEL creation.
158 */
159 void process(const sbeFfdcPacketType& ffdcPkt);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500160
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500161 /**
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500162 * @brief Temporary files path information created as part of FFDC
163 * processing.
164 */
165 std::vector<std::filesystem::path> paths;
166
167 /**
168 * @brief PEL FFDC files, which includes the user data sections and the
169 * added callout details if any, found during SBE FFDC processing.
170 */
171 PelFFDC ffdcFiles;
172
173 /**
174 * @brief Processor position associated to SBE FFDC
175 */
176 uint32_t procPos;
177};
178
179} // namespace sbe
180} // namespace pels
181} // namespace openpower