Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <hei_main.hpp> |
| 4 | #include <phosphor-logging/elog.hpp> |
| 5 | #include <sdbusplus/bus.hpp> |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 6 | #include <util/bin_stream.hpp> |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 7 | #include <util/ffdc_file.hpp> |
| 8 | #include <util/pdbg.hpp> |
| 9 | #include <util/trace.hpp> |
| 10 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 11 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 12 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 13 | #include <fstream> |
| 14 | #include <memory> |
| 15 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 16 | namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server; |
| 17 | |
| 18 | namespace analyzer |
| 19 | { |
| 20 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 21 | //------------------------------------------------------------------------------ |
| 22 | |
| 23 | enum FfdcSubType_t : uint8_t |
| 24 | { |
| 25 | FFDC_SIGNATURES = 0x01, |
| 26 | FFDC_CAPTURE_DATA = 0x02, |
| 27 | |
| 28 | // For the callout section, the value of '0xCA' is required per the |
| 29 | // phosphor-logging openpower-pel extention spec. |
| 30 | FFDC_CALLOUTS = 0xCA, |
| 31 | }; |
| 32 | |
| 33 | enum FfdcVersion_t : uint8_t |
| 34 | { |
| 35 | FFDC_VERSION1 = 0x01, |
| 36 | }; |
| 37 | |
| 38 | //------------------------------------------------------------------------------ |
| 39 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 40 | bool __isCheckstop(const libhei::IsolationData& i_isoData) |
| 41 | { |
| 42 | // Look for any signature with a system checkstop attention. |
| 43 | auto list = i_isoData.getSignatureList(); |
| 44 | auto itr = std::find_if(list.begin(), list.end(), [](const auto& s) { |
| 45 | return libhei::ATTN_TYPE_CHECKSTOP == s.getAttnType(); |
| 46 | }); |
| 47 | |
| 48 | return list.end() != itr; |
| 49 | } |
| 50 | |
| 51 | //------------------------------------------------------------------------------ |
| 52 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 53 | void __getSrc(const libhei::Signature& i_signature, uint32_t& o_word6, |
| 54 | uint32_t& o_word7, uint32_t& o_word8) |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 55 | { |
| 56 | // [ 0:15] chip model |
| 57 | // [16:23] reserved space in chip ID |
| 58 | // [24:31] chip EC level |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 59 | o_word6 = i_signature.getChip().getType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 60 | |
| 61 | // [ 0:15] chip position |
| 62 | // [16:23] unused |
| 63 | // [24:31] signature attention type |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 64 | auto pos = util::pdbg::getChipPos(i_signature.getChip()); |
| 65 | auto attn = i_signature.getAttnType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 66 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 67 | o_word7 = (pos & 0xffff) << 16 | (attn & 0xff); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 68 | |
| 69 | // [ 0:15] signature ID |
| 70 | // [16:23] signature instance |
| 71 | // [24:31] signature bit position |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 72 | o_word8 = i_signature.toUint32(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 73 | |
| 74 | // Word 9 is currently unused |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | |
| 79 | void __setSrc(const libhei::Signature& i_rootCause, |
| 80 | std::map<std::string, std::string>& io_logData) |
| 81 | { |
| 82 | uint32_t word6 = 0, word7 = 0, word8 = 0; |
| 83 | __getSrc(i_rootCause, word6, word7, word8); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 84 | |
| 85 | io_logData["SRC6"] = std::to_string(word6); |
| 86 | io_logData["SRC7"] = std::to_string(word7); |
| 87 | io_logData["SRC8"] = std::to_string(word8); |
| 88 | } |
| 89 | |
| 90 | //------------------------------------------------------------------------------ |
| 91 | |
| 92 | void __captureSignatureList(const libhei::IsolationData& i_isoData, |
| 93 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 94 | { |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 95 | // Create a new entry for this user data section regardless if there are any |
| 96 | // signatures in the list. |
| 97 | io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_SIGNATURES, |
| 98 | FFDC_VERSION1); |
| 99 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 100 | // Create a streamer for easy writing to the FFDC file. |
| 101 | auto path = io_userDataFiles.back().getPath(); |
| 102 | util::BinFileWriter stream{path}; |
| 103 | |
| 104 | // The first 4 bytes in the FFDC contains the number of signatures in the |
| 105 | // list. Then, the list of signatures will follow. |
| 106 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 107 | auto list = i_isoData.getSignatureList(); |
| 108 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 109 | uint32_t numSigs = list.size(); |
| 110 | stream << numSigs; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 111 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 112 | for (const auto& sig : list) |
| 113 | { |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 114 | // Each signature will use the same format as the SRC (12 bytes each). |
| 115 | uint32_t word6 = 0, word7 = 0, word8 = 0; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 116 | __getSrc(sig, word6, word7, word8); |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 117 | stream << word6 << word7 << word8; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 118 | } |
| 119 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 120 | // If the stream failed for any reason, remove the FFDC file. |
| 121 | if (!stream.good()) |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 122 | { |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame^] | 123 | trace::err("Unable to write signature list FFDC file: %s", |
| 124 | path.string().c_str()); |
| 125 | io_userDataFiles.pop_back(); |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 126 | } |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | //------------------------------------------------------------------------------ |
| 130 | |
| 131 | std::string __getMessageRegistry(bool i_isCheckstop) |
| 132 | { |
| 133 | // For now, there are only two choices: |
| 134 | return i_isCheckstop ? "org.open_power.HwDiags.Error.Checkstop" |
| 135 | : "org.open_power.HwDiags.Error.Predictive"; |
| 136 | } |
| 137 | |
| 138 | //------------------------------------------------------------------------------ |
| 139 | |
| 140 | std::string __getMessageSeverity(bool i_isCheckstop) |
| 141 | { |
| 142 | // We could specify the PEL severity in the message registry entry. However, |
| 143 | // that would require multiple copies of each entry for each possible |
| 144 | // severity. As a workaround, we will not explicitly state the PEL severity |
| 145 | // in the message registry. Instead, the message severity will be converted |
| 146 | // into a PEL severity via the openpower-pels extention of phosphor-logging. |
| 147 | |
| 148 | // Initially, we'll use a severity that will generate a predictive PEL. This |
| 149 | // is intended for Terminate Immediate (TI) errors and will require service. |
| 150 | LogSvr::Entry::Level severity = LogSvr::Entry::Level::Warning; |
| 151 | |
| 152 | // If the reason for analysis was due to a system checsktop, the severity |
| 153 | // will be upgraded to a unrecoverable PEL. |
| 154 | if (i_isCheckstop) |
| 155 | severity = LogSvr::Entry::Level::Error; |
| 156 | |
| 157 | // Convert the message severity to a string. |
| 158 | return LogSvr::Entry::convertLevelToString(severity); |
| 159 | } |
| 160 | |
| 161 | //------------------------------------------------------------------------------ |
| 162 | |
| 163 | void createPel(const libhei::Signature& i_rootCause, |
| 164 | const libhei::IsolationData& i_isoData) |
| 165 | { |
| 166 | // The message registry will require additional log data to fill in keywords |
| 167 | // and additional log data. |
| 168 | std::map<std::string, std::string> logData; |
| 169 | |
| 170 | // Keep track of the temporary files associated with the user data FFDC. |
| 171 | // WARNING: Once the objects stored in this vector go out of scope, the |
| 172 | // temporary files will be deleted. So they must remain in scope |
| 173 | // until the PEL is submitted. |
| 174 | std::vector<util::FFDCFile> userDataFiles; |
| 175 | |
| 176 | // In several cases, it is important to know if the reason for analysis was |
| 177 | // due to a system checsktop. |
| 178 | bool isCheckstop = __isCheckstop(i_isoData); |
| 179 | |
| 180 | // Set words 6-9 of the SRC. |
| 181 | __setSrc(i_rootCause, logData); |
| 182 | |
| 183 | // Capture the complete signature list. |
| 184 | __captureSignatureList(i_isoData, userDataFiles); |
| 185 | |
| 186 | // Now, that all of the user data files have been created, transform the |
| 187 | // data into the proper format for the PEL. |
| 188 | std::vector<util::FFDCTuple> userData; |
| 189 | util::transformFFDC(userDataFiles, userData); |
| 190 | |
| 191 | // Get access to logging interface and method for creating log. |
| 192 | auto bus = sdbusplus::bus::new_default_system(); |
| 193 | |
| 194 | // Using direct create method (for additional data). |
| 195 | auto method = bus.new_method_call( |
| 196 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 197 | "xyz.openbmc_project.Logging.Create", "CreateWithFFDCFiles"); |
| 198 | |
| 199 | // The "Create" method requires manually adding the process ID. |
| 200 | logData["_PID"] = std::to_string(getpid()); |
| 201 | |
| 202 | // Get the message registry entry for this failure. |
| 203 | auto message = __getMessageRegistry(isCheckstop); |
| 204 | |
| 205 | // Get the message severity for this failure. |
| 206 | auto severity = __getMessageSeverity(isCheckstop); |
| 207 | |
| 208 | // Add the message, with additional log and user data. |
| 209 | method.append(message, severity, logData, userData); |
| 210 | |
| 211 | // Log the event. |
| 212 | bus.call_noreply(method); |
| 213 | } |
| 214 | |
| 215 | } // namespace analyzer |