Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Dhruvaraj Subhashchandran | f9f65b8 | 2022-10-13 06:46:43 -0500 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Logging/Entry/server.hpp" |
| 4 | |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 5 | #include <phal_exception.H> |
| 6 | |
| 7 | #include <nlohmann/json.hpp> |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 9 | |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 10 | #include <optional> |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 11 | #include <string> |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 12 | #include <tuple> |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 13 | #include <vector> |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 14 | |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 15 | namespace openpower::dump::pel |
| 16 | { |
| 17 | |
| 18 | using FFDCData = std::vector<std::pair<std::string, std::string>>; |
| 19 | |
Dhruvaraj Subhashchandran | f9f65b8 | 2022-10-13 06:46:43 -0500 | [diff] [blame] | 20 | using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level; |
| 21 | |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 22 | using json = nlohmann::json; |
| 23 | |
| 24 | using namespace openpower::phal; |
| 25 | |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 26 | using PELFFDCInfo = std::vector<std::tuple< |
| 27 | sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat, |
| 28 | uint8_t, uint8_t, sdbusplus::message::unix_fd>>; |
| 29 | |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 30 | /** |
| 31 | * @brief Create SBE boot error PEL and return id |
| 32 | * |
| 33 | * @param[in] event - the event type |
| 34 | * @param[in] sbeError - SBE error object |
| 35 | * @param[in] ffdcData - failure data to append to PEL |
Dhruvaraj Subhashchandran | f9f65b8 | 2022-10-13 06:46:43 -0500 | [diff] [blame] | 36 | * @param[in] severity - severity of the log |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 37 | * @return Platform log id |
| 38 | */ |
Dhruvaraj Subhashchandran | f229889 | 2024-04-21 04:42:55 -0500 | [diff] [blame] | 39 | uint32_t createSbeErrorPEL( |
| 40 | const std::string& event, const sbeError_t& sbeError, |
| 41 | const FFDCData& ffdcData, const Severity severity = Severity::Error, |
| 42 | const std::optional<PELFFDCInfo>& pelFFDCInfoOpt = std::nullopt); |
| 43 | |
| 44 | /** |
| 45 | * @brief Convert a FAPI2 severity code to PEL severity. |
| 46 | * |
| 47 | * @param[in] severity - Severity code from FAPI2 error logs. |
| 48 | * @return Severity - The corresponding Severity enumeration value. |
| 49 | */ |
| 50 | openpower::dump::pel::Severity convertSeverityToEnum(uint8_t severity); |
| 51 | |
| 52 | /** |
| 53 | * @brief Process FFDC packets and create PELs for each packet. |
| 54 | * |
| 55 | * @param[in] sbeError - An SBE error object containing FFDC packet information. |
| 56 | * @param[in] event - The event identifier associated with the PELs. |
| 57 | * @param[out] pelAdditionalData - A reference to additional PEL data to be |
| 58 | * included in the PEL. |
| 59 | */ |
| 60 | void processFFDCPackets(const openpower::phal::sbeError_t& sbeError, |
| 61 | const std::string& event, |
| 62 | openpower::dump::pel::FFDCData& pelAdditionalData); |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * @class FFDCFile |
| 66 | * @brief This class is used to create ffdc data file and to get fd |
| 67 | */ |
| 68 | class FFDCFile |
| 69 | { |
| 70 | public: |
| 71 | FFDCFile() = delete; |
| 72 | FFDCFile(const FFDCFile&) = delete; |
| 73 | FFDCFile& operator=(const FFDCFile&) = delete; |
| 74 | FFDCFile(FFDCFile&&) = delete; |
| 75 | FFDCFile& operator=(FFDCFile&&) = delete; |
| 76 | |
| 77 | /** |
| 78 | * Used to pass json object to create unique ffdc file by using |
| 79 | * passed json data. |
| 80 | */ |
| 81 | explicit FFDCFile(const json& pHALCalloutData); |
| 82 | |
| 83 | /** |
| 84 | * Used to remove created ffdc file. |
| 85 | */ |
| 86 | ~FFDCFile(); |
| 87 | |
| 88 | /** |
| 89 | * Used to get created ffdc file file descriptor id. |
| 90 | * |
| 91 | * @return file descriptor id |
| 92 | */ |
| 93 | int getFileFD() const; |
| 94 | |
| 95 | private: |
| 96 | /** |
| 97 | * Used to store callout ffdc data from passed json object. |
| 98 | */ |
| 99 | std::string calloutData; |
| 100 | |
| 101 | /** |
| 102 | * Used to store unique ffdc file name. |
| 103 | */ |
| 104 | std::string calloutFile; |
| 105 | |
| 106 | /** |
| 107 | * Used to store created ffdc file descriptor id. |
| 108 | */ |
| 109 | int fileFD; |
| 110 | |
| 111 | /** |
| 112 | * Used to create ffdc file to pass PEL api for creating |
| 113 | * pel records. |
| 114 | * |
| 115 | * @return NULL |
| 116 | */ |
| 117 | void prepareFFDCFile(); |
| 118 | |
| 119 | /** |
| 120 | * Create unique ffdc file. |
| 121 | * |
| 122 | * @return NULL |
| 123 | */ |
| 124 | void createCalloutFile(); |
| 125 | |
| 126 | /** |
| 127 | * Used write json object value into created file. |
| 128 | * |
| 129 | * @return NULL |
| 130 | */ |
| 131 | void writeCalloutData(); |
| 132 | |
| 133 | /** |
Manojkiran Eda | eb46252 | 2024-06-17 11:05:27 +0530 | [diff] [blame^] | 134 | * Used set ffdc file seek position beginning to consume by PEL |
Dhruvaraj Subhashchandran | 6feeebd | 2021-10-19 05:03:59 -0500 | [diff] [blame] | 135 | * |
| 136 | * @return NULL |
| 137 | */ |
| 138 | void setCalloutFileSeekPos(); |
| 139 | |
| 140 | /** |
| 141 | * Used to remove created ffdc file. |
| 142 | * |
| 143 | * @return NULL |
| 144 | */ |
| 145 | void removeCalloutFile(); |
| 146 | |
| 147 | }; // FFDCFile end |
| 148 | |
| 149 | } // namespace openpower::dump::pel |