xref: /openbmc/openpower-occ-control/occ_ffdc.hpp (revision 2f9f9bba661dcae2f0dd05ea6ddae9eb11a909d9)
1*2f9f9bbaSEddie James #pragma once
2*2f9f9bbaSEddie James 
3*2f9f9bbaSEddie James #include "config.h"
4*2f9f9bbaSEddie James 
5*2f9f9bbaSEddie James #include "occ_errors.hpp"
6*2f9f9bbaSEddie James 
7*2f9f9bbaSEddie James namespace open_power
8*2f9f9bbaSEddie James {
9*2f9f9bbaSEddie James namespace occ
10*2f9f9bbaSEddie James {
11*2f9f9bbaSEddie James 
12*2f9f9bbaSEddie James /** @class FFDC
13*2f9f9bbaSEddie James  *  @brief Monitors for SBE FFDC availability
14*2f9f9bbaSEddie James  */
15*2f9f9bbaSEddie James class FFDC : public Error
16*2f9f9bbaSEddie James {
17*2f9f9bbaSEddie James   public:
18*2f9f9bbaSEddie James     FFDC() = delete;
19*2f9f9bbaSEddie James     FFDC(const FFDC&) = delete;
20*2f9f9bbaSEddie James     FFDC& operator=(const FFDC&) = delete;
21*2f9f9bbaSEddie James     FFDC(FFDC&&) = default;
22*2f9f9bbaSEddie James     FFDC& operator=(FFDC&&) = default;
23*2f9f9bbaSEddie James 
24*2f9f9bbaSEddie James     /** @brief Constructs the FFDC object
25*2f9f9bbaSEddie James      *
26*2f9f9bbaSEddie James      *  @param[in] event    - reference to sd_event unique_ptr
27*2f9f9bbaSEddie James      *  @param[in] file     - File used by driver to communicate FFDC data
28*2f9f9bbaSEddie James      *  @param[in] instance - OCC instance number
29*2f9f9bbaSEddie James      */
30*2f9f9bbaSEddie James     FFDC(EventPtr& event, const fs::path& file, unsigned int instance) :
31*2f9f9bbaSEddie James         Error(event, file, nullptr), instance(instance)
32*2f9f9bbaSEddie James     {
33*2f9f9bbaSEddie James         // Nothing to do here.
34*2f9f9bbaSEddie James     }
35*2f9f9bbaSEddie James 
36*2f9f9bbaSEddie James     ~FFDC()
37*2f9f9bbaSEddie James     {
38*2f9f9bbaSEddie James         for (auto&& it : temporaryFiles)
39*2f9f9bbaSEddie James         {
40*2f9f9bbaSEddie James             close(it.second);
41*2f9f9bbaSEddie James             fs::remove(it.first);
42*2f9f9bbaSEddie James         }
43*2f9f9bbaSEddie James     }
44*2f9f9bbaSEddie James 
45*2f9f9bbaSEddie James     /** @brief Helper function to create a PEL with the OpenPower DBus
46*2f9f9bbaSEddie James      *         interface
47*2f9f9bbaSEddie James      *
48*2f9f9bbaSEddie James      * @param[in] path - the DBus error path
49*2f9f9bbaSEddie James      * @param[in] src6 - the SBE error SRC6 word
50*2f9f9bbaSEddie James      * @param[in] msg - the error message
51*2f9f9bbaSEddie James      * @param[in] fd - the file descriptor for any FFDC
52*2f9f9bbaSEddie James      */
53*2f9f9bbaSEddie James     static uint32_t createPEL(const char* path, uint32_t src6, const char* msg,
54*2f9f9bbaSEddie James                               int fd = -1);
55*2f9f9bbaSEddie James 
56*2f9f9bbaSEddie James   private:
57*2f9f9bbaSEddie James     /** @brief OCC instance number. Ex, 0,1, etc */
58*2f9f9bbaSEddie James     unsigned int instance;
59*2f9f9bbaSEddie James 
60*2f9f9bbaSEddie James     /** @brief Stores the temporary files and file descriptors
61*2f9f9bbaSEddie James      *         in usage. They will be cleaned up when the class
62*2f9f9bbaSEddie James      *         is destroyed (when the application exits).
63*2f9f9bbaSEddie James      */
64*2f9f9bbaSEddie James     std::vector<std::pair<fs::path, int>> temporaryFiles;
65*2f9f9bbaSEddie James 
66*2f9f9bbaSEddie James     /** @brief When the error event is received, analyzes it
67*2f9f9bbaSEddie James      *         and makes a callback to error handler if the
68*2f9f9bbaSEddie James      *         content denotes an error condition
69*2f9f9bbaSEddie James      */
70*2f9f9bbaSEddie James     void analyzeEvent() override;
71*2f9f9bbaSEddie James };
72*2f9f9bbaSEddie James 
73*2f9f9bbaSEddie James } // namespace occ
74*2f9f9bbaSEddie James } // namespace open_power
75