xref: /openbmc/phosphor-logging/extensions/openpower-pels/sbe_ffdc_handler.hpp (revision da876617c418d8a94442389bb20d582843a134bf)
1e8bdeeaaSJayanth Othayoth #pragma once
2e8bdeeaaSJayanth Othayoth 
3e8bdeeaaSJayanth Othayoth #include "additional_data.hpp"
4e8bdeeaaSJayanth Othayoth #include "pel.hpp"
5e8bdeeaaSJayanth Othayoth 
6c74c2202SJayanth Othayoth #include <libekb.H>
7c74c2202SJayanth Othayoth 
88c7bb86aSMatt Spinler #include <filesystem>
98c7bb86aSMatt Spinler 
10e8bdeeaaSJayanth Othayoth namespace openpower
11e8bdeeaaSJayanth Othayoth {
12e8bdeeaaSJayanth Othayoth namespace pels
13e8bdeeaaSJayanth Othayoth {
14e8bdeeaaSJayanth Othayoth namespace sbe
15e8bdeeaaSJayanth Othayoth {
16e8bdeeaaSJayanth Othayoth 
17e8bdeeaaSJayanth Othayoth // SBE FFDC sub type.
18e8bdeeaaSJayanth Othayoth constexpr uint8_t sbeFFDCSubType = 0xCB;
19e8bdeeaaSJayanth Othayoth 
200866c3fcSJayanth Othayoth /**
210866c3fcSJayanth Othayoth  *   @brief FFDC Package structure and definitions based on SBE chip-op spec.
220866c3fcSJayanth Othayoth  *
230866c3fcSJayanth Othayoth  *   SBE FFDC Starts with a header word (Word 0) that has an unique magic
240866c3fcSJayanth Othayoth  *   identifier code of 0xFFDC followed by the length of the FFDC package
250866c3fcSJayanth Othayoth  *   including the header itself. Word 1 contains a sequence id ,
260866c3fcSJayanth Othayoth  *   command-class and command fields.
270866c3fcSJayanth Othayoth  *   The sequence id field is ignored on the BMC side.
280866c3fcSJayanth Othayoth  *   Word 2 contains a 32 bit Return Code which acts like the key to the
290866c3fcSJayanth Othayoth  *   contents of subsequent FFDC Data Words (0-N).
300866c3fcSJayanth Othayoth  *
310866c3fcSJayanth Othayoth  *   A FFDC package can typically contain debug data from either:
320866c3fcSJayanth Othayoth  *    1. A failed hardware procedure (e.g. local variable values
330866c3fcSJayanth Othayoth  *       at point of failure) or
340866c3fcSJayanth Othayoth  *    2. SBE firmware (e.g. traces, attributes and other information).
35*da876617Sdevenrao  *
36*da876617Sdevenrao  *   -------------------P10 proc-----------------------
370866c3fcSJayanth Othayoth  *   |        |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
380866c3fcSJayanth Othayoth  *   |----------------------------------------------------------|
390866c3fcSJayanth Othayoth  *   | Word 0 | Magic Bytes : 0xFFDC | Length in words (N+4)    |
400866c3fcSJayanth Othayoth  *   | Word 1 | [Sequence ID]        | Command-Class | Command  |
410866c3fcSJayanth Othayoth  *   | Word 2 |           Return Code 0..31                     |
420866c3fcSJayanth Othayoth  *   | Word 3 |           FFDC Data – Word 0                    |
430866c3fcSJayanth Othayoth  *   |  ...                                                     |
440866c3fcSJayanth Othayoth  *   | Word N+3 |  FFDC Data – Word N                           |
450866c3fcSJayanth Othayoth  *    -----------------------------------------------------------
46*da876617Sdevenrao  *
47*da876617Sdevenrao  *   --------------POZ - PowerOdysseyZEE-----------------------
48*da876617Sdevenrao  *   First FFDC packet structure
49*da876617Sdevenrao  *   --------------------------------------------------------------
50*da876617Sdevenrao  *   |          |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
51*da876617Sdevenrao  *   |------------------------------------------------------------|
52*da876617Sdevenrao  *   | Word 0   | Magic Bytes : 0xFBAD | Length in words (N+4)    |
53*da876617Sdevenrao  *   | Word 1   | [Sequence ID]        | Command-Class | Command  |
54*da876617Sdevenrao  *   | Word 2   | SLID                 | Severity      | Chip ID  |
55*da876617Sdevenrao  *   | Word 3   |           FAPI RC (HWP)                         |
56*da876617Sdevenrao  *   | Word 4   | HWP FFDC Dump Fields (Local FFDC | HW Register) |
57*da876617Sdevenrao  *   | Word 6   | Field ID 0(Local FFDC) | Field ID 0 Length      |
58*da876617Sdevenrao  *   | Word 7   |          Filed Data 0(Size1, data2)             |
59*da876617Sdevenrao  *   |  ...                                                       |
60*da876617Sdevenrao  *   | Word N   |          Filed Data N(Size1, data2)             |
61*da876617Sdevenrao  *   | Word N+1 | Field ID 1(HW Register) | Field ID 1 Length     |
62*da876617Sdevenrao  *   | Word N+2 |              Filed Data 0)                      |
63*da876617Sdevenrao  *   |  ...                                                       |
64*da876617Sdevenrao  *   | Word Y   |              Filed Data M)                      |
65*da876617Sdevenrao  *    -------------------------------------------------------------
66*da876617Sdevenrao  *   Second FFDC packet structure
67*da876617Sdevenrao  *   --------------------------------------------------------------
68*da876617Sdevenrao  *   |          |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
69*da876617Sdevenrao  *   |------------------------------------------------------------|
70*da876617Sdevenrao  *   | Word 0   | Magic Bytes : 0xFBAD | Length in words (N+4)    |
71*da876617Sdevenrao  *   | Word 1   | [Sequence ID]        | Command-Class | Command  |
72*da876617Sdevenrao  *   | Word 2   | SLID                 | Severity      | Chip ID  |
73*da876617Sdevenrao  *   | Word 3   |       FAPI RC (PLAT ERR SEE DATA)               |
74*da876617Sdevenrao  *   | Word 4   | Primary Status       | Secondary Status         |
75*da876617Sdevenrao  *   | Word 5   |             FW commit ID                        |
76*da876617Sdevenrao  *   | Word 5   | Reserve | DD Major   | DD Minor      | Thread ID|
77*da876617Sdevenrao  *   | Word 4   |         SBE FFDC Dump Fields (Bitmaped)         |
78*da876617Sdevenrao  *   | Word 6   | Field ID 0           | Field ID 0 Length        |
79*da876617Sdevenrao  *   | Word 7   |              Filed Data 0                       |
80*da876617Sdevenrao  *   |  ...                                                       |
81*da876617Sdevenrao  *   | Word N   |              Filed Data N                       |
82*da876617Sdevenrao  *   | Word N+1 | Field ID 1           | Field ID 1 Length        |
83*da876617Sdevenrao  *   | Word N+2 |       Filed Data 0)                             |
84*da876617Sdevenrao  *   |  ...                                                       |
85*da876617Sdevenrao  *   | Word Y   |       Filed Data M)                             |
86*da876617Sdevenrao  *   | Word Y+1 | 0xCODE               | 0xA8         | 0x1       |
87*da876617Sdevenrao  *   | Word Y+2 | Primary Status       | Secondary Status         |
88*da876617Sdevenrao  *   | Word Y+3 |          Distance to Header                     |
89*da876617Sdevenrao  *    -------------------------------------------------------------
90*da876617Sdevenrao  *
910866c3fcSJayanth Othayoth  **/
920866c3fcSJayanth Othayoth 
93742b00b9SJayanth Othayoth using LogSeverity = phosphor::logging::Entry::Level;
94742b00b9SJayanth Othayoth 
95e8bdeeaaSJayanth Othayoth /** @class SbeFFDC
96e8bdeeaaSJayanth Othayoth  *
97e8bdeeaaSJayanth Othayoth  * @brief This class provides higher level interface to process SBE ffdc
98e8bdeeaaSJayanth Othayoth  * for PEL based error logging infrastructure.
99e8bdeeaaSJayanth Othayoth  * Key Functionalities included here
100e8bdeeaaSJayanth Othayoth  *    - Process the SBE FFDC data with the help of FAPI infrastructure and
101e8bdeeaaSJayanth Othayoth  *      and create PEL required format Callout and user data for hardware
102e8bdeeaaSJayanth Othayoth  *      procedure failures specific reason code
103e8bdeeaaSJayanth Othayoth  *    - Add the user data section with SBE FFDC data to support SBE provided
104e8bdeeaaSJayanth Othayoth  *      parser tool usage.
105e8bdeeaaSJayanth Othayoth  *    - Any SBE FFDC processing will result additional log message in journal
106e8bdeeaaSJayanth Othayoth  *      and will continue to create Error log with available data. This is to
107e8bdeeaaSJayanth Othayoth  *      help user to analyse the failure.
108e8bdeeaaSJayanth Othayoth  */
109e8bdeeaaSJayanth Othayoth class SbeFFDC
110e8bdeeaaSJayanth Othayoth {
111e8bdeeaaSJayanth Othayoth   public:
112e8bdeeaaSJayanth Othayoth     SbeFFDC() = delete;
113e8bdeeaaSJayanth Othayoth     SbeFFDC(const SbeFFDC&) = delete;
114e8bdeeaaSJayanth Othayoth     SbeFFDC& operator=(const SbeFFDC&) = delete;
115e8bdeeaaSJayanth Othayoth     SbeFFDC(SbeFFDC&&) = delete;
116e8bdeeaaSJayanth Othayoth     SbeFFDC& operator=(SbeFFDC&&) = delete;
117e8bdeeaaSJayanth Othayoth 
118e8bdeeaaSJayanth Othayoth     /**
119e8bdeeaaSJayanth Othayoth      * @brief Constructor
120e8bdeeaaSJayanth Othayoth      *
121e8bdeeaaSJayanth Othayoth      * Create PEL required format data from SBE provided FFDC data.
122e8bdeeaaSJayanth Othayoth      *
123e8bdeeaaSJayanth Othayoth      * @param[in] data - The AdditionalData properties in this PEL event
124e8bdeeaaSJayanth Othayoth      * @param[in] files - FFDC files that go into UserData sections
125e8bdeeaaSJayanth Othayoth      */
126e8bdeeaaSJayanth Othayoth     SbeFFDC(const AdditionalData& data, const PelFFDC& files);
127e8bdeeaaSJayanth Othayoth 
128e8bdeeaaSJayanth Othayoth     /**
129e8bdeeaaSJayanth Othayoth      * @brief Destructor
130e8bdeeaaSJayanth Othayoth      *
131e8bdeeaaSJayanth Othayoth      * Deletes the temporary files
132e8bdeeaaSJayanth Othayoth      */
~SbeFFDC()133e8bdeeaaSJayanth Othayoth     ~SbeFFDC()
134e8bdeeaaSJayanth Othayoth     {
135e8bdeeaaSJayanth Othayoth         try
136e8bdeeaaSJayanth Othayoth         {
1378c7bb86aSMatt Spinler             for (const auto& [path, fd] : paths)
138e8bdeeaaSJayanth Othayoth             {
139e8bdeeaaSJayanth Othayoth                 if (!path.empty())
140e8bdeeaaSJayanth Othayoth                 {
141e8bdeeaaSJayanth Othayoth                     // Delete temporary file from file system
142e8bdeeaaSJayanth Othayoth                     std::error_code ec;
143e8bdeeaaSJayanth Othayoth                     std::filesystem::remove(path, ec);
1448c7bb86aSMatt Spinler                 }
1458c7bb86aSMatt Spinler 
1468c7bb86aSMatt Spinler                 if (fd != -1)
1478c7bb86aSMatt Spinler                 {
1488c7bb86aSMatt Spinler                     close(fd);
149e8bdeeaaSJayanth Othayoth                 }
150e8bdeeaaSJayanth Othayoth             }
1518c7bb86aSMatt Spinler             paths.clear();
152e8bdeeaaSJayanth Othayoth         }
153e8bdeeaaSJayanth Othayoth         catch (...)
154e8bdeeaaSJayanth Othayoth         {
155e8bdeeaaSJayanth Othayoth             // Destructors should not throw exceptions
156e8bdeeaaSJayanth Othayoth         }
157e8bdeeaaSJayanth Othayoth     }
158e8bdeeaaSJayanth Othayoth 
159e8bdeeaaSJayanth Othayoth     /**
160e8bdeeaaSJayanth Othayoth      * @brief Helper function to return FFDC files information, which
161e8bdeeaaSJayanth Othayoth      *        includes SBE FFDC specific callout information.
162e8bdeeaaSJayanth Othayoth      *
163e8bdeeaaSJayanth Othayoth      * return PelFFDC - pel formated FFDC files.
164e8bdeeaaSJayanth Othayoth      */
getSbeFFDC()165e8bdeeaaSJayanth Othayoth     const PelFFDC& getSbeFFDC()
166e8bdeeaaSJayanth Othayoth     {
167e8bdeeaaSJayanth Othayoth         return ffdcFiles;
168e8bdeeaaSJayanth Othayoth     }
169e8bdeeaaSJayanth Othayoth 
170742b00b9SJayanth Othayoth     /**
171742b00b9SJayanth Othayoth      * @brief Helper function to get severity type
172742b00b9SJayanth Othayoth      *
173742b00b9SJayanth Othayoth      * @return severity type as informational for spare clock
174742b00b9SJayanth Othayoth      *         failure type ffdc. Otherwise null string.
175742b00b9SJayanth Othayoth      */
176742b00b9SJayanth Othayoth     std::optional<LogSeverity> getSeverity();
177742b00b9SJayanth Othayoth 
178e8bdeeaaSJayanth Othayoth   private:
179e8bdeeaaSJayanth Othayoth     /**
1800866c3fcSJayanth Othayoth      * @brief Helper function to parse SBE FFDC file.
1810866c3fcSJayanth Othayoth      *        parsing is based on the FFDC structure definition
1820866c3fcSJayanth Othayoth      *        define initially in this file.
1830866c3fcSJayanth Othayoth      *
1840866c3fcSJayanth Othayoth      * @param fd  SBE ffdc file descriptor
1850866c3fcSJayanth Othayoth      *
1860866c3fcSJayanth Othayoth      * Any failure during the process stops the function
1870866c3fcSJayanth Othayoth      * execution to support the raw SBE FFDC data based
1880866c3fcSJayanth Othayoth      * PEL creation.
1890866c3fcSJayanth Othayoth      */
1900866c3fcSJayanth Othayoth     void parse(int fd);
1910866c3fcSJayanth Othayoth 
1920866c3fcSJayanth Othayoth     /**
193c74c2202SJayanth Othayoth      * @brief Helper function to process SBE FFDC packet.
194c74c2202SJayanth Othayoth      * This function call libekb function to process the
195c74c2202SJayanth Othayoth      * FFDC packet and convert in to known format for PEL
196c74c2202SJayanth Othayoth      * specific file creation. This function also creates
197c74c2202SJayanth Othayoth      * json callout file and text type file, which includes
198c74c2202SJayanth Othayoth      * the addition debug data included in SBE FFDC packet.
199c74c2202SJayanth Othayoth      *
200c74c2202SJayanth Othayoth      * @param ffdcPkt  SBE FFDC packet
201c74c2202SJayanth Othayoth      *
202c74c2202SJayanth Othayoth      * Any failure during the process stops the function
203c74c2202SJayanth Othayoth      * execution to support the raw SBE FFDC data based
204c74c2202SJayanth Othayoth      * PEL creation.
205c74c2202SJayanth Othayoth      */
206c74c2202SJayanth Othayoth     void process(const sbeFfdcPacketType& ffdcPkt);
2070866c3fcSJayanth Othayoth 
208c74c2202SJayanth Othayoth     /**
2098c7bb86aSMatt Spinler      * @brief  Temporary files path and FD information created as part of FFDC
210e8bdeeaaSJayanth Othayoth      *         processing.
211e8bdeeaaSJayanth Othayoth      */
2128c7bb86aSMatt Spinler     std::vector<std::pair<std::filesystem::path, int>> paths;
213e8bdeeaaSJayanth Othayoth 
214e8bdeeaaSJayanth Othayoth     /**
215e8bdeeaaSJayanth Othayoth      * @brief PEL FFDC files, which includes the user data sections and the
216e8bdeeaaSJayanth Othayoth      *        added callout details if any, found during SBE FFDC processing.
217e8bdeeaaSJayanth Othayoth      */
218e8bdeeaaSJayanth Othayoth     PelFFDC ffdcFiles;
219e8bdeeaaSJayanth Othayoth 
220e8bdeeaaSJayanth Othayoth     /**
221*da876617Sdevenrao      * @brief Chip position associated to SBE FFDC
222e8bdeeaaSJayanth Othayoth      */
223*da876617Sdevenrao     uint32_t chipPos;
224742b00b9SJayanth Othayoth 
225742b00b9SJayanth Othayoth     /**
226742b00b9SJayanth Othayoth      * @brief Used to get type of ffdc
227742b00b9SJayanth Othayoth      */
228742b00b9SJayanth Othayoth     FFDC_TYPE ffdcType;
229*da876617Sdevenrao 
230*da876617Sdevenrao     /**
231*da876617Sdevenrao      * @brief Chip type associated to SBE FFDC
232*da876617Sdevenrao      */
233*da876617Sdevenrao     uint32_t chipType;
234e8bdeeaaSJayanth Othayoth };
235e8bdeeaaSJayanth Othayoth 
236e8bdeeaaSJayanth Othayoth } // namespace sbe
237e8bdeeaaSJayanth Othayoth } // namespace pels
238e8bdeeaaSJayanth Othayoth } // namespace openpower
239