Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Logging/Entry/server.hpp" |
| 4 | |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 5 | #include <phal_exception.H> |
| 6 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 7 | #include <nlohmann/json.hpp> |
Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 8 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | namespace openpower |
| 12 | { |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 13 | namespace pel |
| 14 | { |
| 15 | using FFDCData = std::vector<std::pair<std::string, std::string>>; |
| 16 | |
| 17 | using json = nlohmann::json; |
| 18 | |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 19 | using namespace openpower::phal; |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 20 | using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 21 | /** |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 22 | * @brief Create PEL with additional parameters and callout |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 23 | * |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 24 | * @param[in] event - the event type |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 25 | * @param[in] calloutData - callout data to append to PEL |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 26 | * @param[in] ffdcData - failure data to append to PEL |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 27 | */ |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 28 | void createErrorPEL(const std::string& event, const json& calloutData = {}, |
| 29 | const FFDCData& ffdcData = {}); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 30 | |
| 31 | /** |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 32 | * @brief Create SBE boot error PEL and return id |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 33 | * |
| 34 | * @param[in] event - the event type |
| 35 | * @param[in] sbeError - SBE error object |
| 36 | * @param[in] ffdcData - failure data to append to PEL |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 37 | * @param[in] severity - severity of the log |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 38 | * @return Platform log id |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 39 | */ |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 40 | uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError, |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 41 | const FFDCData& ffdcData, |
| 42 | const Severity severity = Severity::Error); |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 43 | |
| 44 | /** |
Jayanth Othayoth | a8d2f71 | 2021-09-20 07:02:51 -0500 | [diff] [blame] | 45 | * @brief Create a PEL for the specified event type and additional data |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 46 | * |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 47 | * @param[in] event - the event type |
Jayanth Othayoth | a8d2f71 | 2021-09-20 07:02:51 -0500 | [diff] [blame] | 48 | * @param[in] ffdcData - failure data to append to PEL |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 49 | */ |
Jayanth Othayoth | a8d2f71 | 2021-09-20 07:02:51 -0500 | [diff] [blame] | 50 | void createPEL(const std::string& event, const FFDCData& ffdcData = {}); |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 51 | |
| 52 | /** |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 53 | * @class FFDCFile |
| 54 | * @brief This class is used to create ffdc data file and to get fd |
| 55 | */ |
| 56 | class FFDCFile |
| 57 | { |
| 58 | public: |
| 59 | FFDCFile() = delete; |
| 60 | FFDCFile(const FFDCFile&) = delete; |
| 61 | FFDCFile& operator=(const FFDCFile&) = delete; |
| 62 | FFDCFile(FFDCFile&&) = delete; |
| 63 | FFDCFile& operator=(FFDCFile&&) = delete; |
| 64 | |
| 65 | /** |
| 66 | * Used to pass json object to create unique ffdc file by using |
| 67 | * passed json data. |
| 68 | */ |
| 69 | explicit FFDCFile(const json& pHALCalloutData); |
| 70 | |
| 71 | /** |
| 72 | * Used to remove created ffdc file. |
| 73 | */ |
| 74 | ~FFDCFile(); |
| 75 | |
| 76 | /** |
| 77 | * Used to get created ffdc file file descriptor id. |
| 78 | * |
| 79 | * @return file descriptor id |
| 80 | */ |
| 81 | int getFileFD() const; |
| 82 | |
| 83 | private: |
| 84 | /** |
| 85 | * Used to store callout ffdc data from passed json object. |
| 86 | */ |
| 87 | std::string calloutData; |
| 88 | |
| 89 | /** |
| 90 | * Used to store unique ffdc file name. |
| 91 | */ |
| 92 | std::string calloutFile; |
| 93 | |
| 94 | /** |
| 95 | * Used to store created ffdc file descriptor id. |
| 96 | */ |
| 97 | int fileFD; |
| 98 | |
| 99 | /** |
| 100 | * Used to create ffdc file to pass PEL api for creating |
| 101 | * pel records. |
| 102 | * |
| 103 | * @return NULL |
| 104 | */ |
| 105 | void prepareFFDCFile(); |
| 106 | |
| 107 | /** |
| 108 | * Create unique ffdc file. |
| 109 | * |
| 110 | * @return NULL |
| 111 | */ |
| 112 | void createCalloutFile(); |
| 113 | |
| 114 | /** |
| 115 | * Used write json object value into created file. |
| 116 | * |
| 117 | * @return NULL |
| 118 | */ |
| 119 | void writeCalloutData(); |
| 120 | |
| 121 | /** |
| 122 | * Used set ffdc file seek position begining to consume by PEL |
| 123 | * |
| 124 | * @return NULL |
| 125 | */ |
| 126 | void setCalloutFileSeekPos(); |
| 127 | |
| 128 | /** |
| 129 | * Used to remove created ffdc file. |
| 130 | * |
| 131 | * @return NULL |
| 132 | */ |
| 133 | void removeCalloutFile(); |
| 134 | |
| 135 | }; // FFDCFile end |
| 136 | |
| 137 | } // namespace pel |
| 138 | } // namespace openpower |