Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 3 | #include <analyzer/service_data.hpp> |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 4 | #include <analyzer/util.hpp> |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 5 | #include <hei_main.hpp> |
| 6 | #include <phosphor-logging/elog.hpp> |
| 7 | #include <sdbusplus/bus.hpp> |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 8 | #include <util/bin_stream.hpp> |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 9 | #include <util/ffdc_file.hpp> |
| 10 | #include <util/pdbg.hpp> |
| 11 | #include <util/trace.hpp> |
| 12 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 13 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 14 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 15 | #include <fstream> |
| 16 | #include <memory> |
| 17 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 18 | namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server; |
| 19 | |
| 20 | namespace analyzer |
| 21 | { |
| 22 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 23 | //------------------------------------------------------------------------------ |
| 24 | |
| 25 | enum FfdcSubType_t : uint8_t |
| 26 | { |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 27 | FFDC_SIGNATURES = 0x01, |
| 28 | FFDC_REGISTER_DUMP = 0x02, |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 29 | |
| 30 | // For the callout section, the value of '0xCA' is required per the |
| 31 | // phosphor-logging openpower-pel extention spec. |
| 32 | FFDC_CALLOUTS = 0xCA, |
| 33 | }; |
| 34 | |
| 35 | enum FfdcVersion_t : uint8_t |
| 36 | { |
| 37 | FFDC_VERSION1 = 0x01, |
| 38 | }; |
| 39 | |
| 40 | //------------------------------------------------------------------------------ |
| 41 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 42 | bool __isCheckstop(const libhei::IsolationData& i_isoData) |
| 43 | { |
| 44 | // Look for any signature with a system checkstop attention. |
| 45 | auto list = i_isoData.getSignatureList(); |
| 46 | auto itr = std::find_if(list.begin(), list.end(), [](const auto& s) { |
| 47 | return libhei::ATTN_TYPE_CHECKSTOP == s.getAttnType(); |
| 48 | }); |
| 49 | |
| 50 | return list.end() != itr; |
| 51 | } |
| 52 | |
| 53 | //------------------------------------------------------------------------------ |
| 54 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 55 | void __getSrc(const libhei::Signature& i_signature, uint32_t& o_word6, |
| 56 | uint32_t& o_word7, uint32_t& o_word8) |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 57 | { |
| 58 | // [ 0:15] chip model |
| 59 | // [16:23] reserved space in chip ID |
| 60 | // [24:31] chip EC level |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 61 | o_word6 = i_signature.getChip().getType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 62 | |
| 63 | // [ 0:15] chip position |
| 64 | // [16:23] unused |
| 65 | // [24:31] signature attention type |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 66 | auto pos = util::pdbg::getChipPos(i_signature.getChip()); |
| 67 | auto attn = i_signature.getAttnType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 68 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 69 | o_word7 = (pos & 0xffff) << 16 | (attn & 0xff); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 70 | |
| 71 | // [ 0:15] signature ID |
| 72 | // [16:23] signature instance |
| 73 | // [24:31] signature bit position |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 74 | o_word8 = i_signature.toUint32(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 75 | |
| 76 | // Word 9 is currently unused |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | //------------------------------------------------------------------------------ |
| 80 | |
| 81 | void __setSrc(const libhei::Signature& i_rootCause, |
| 82 | std::map<std::string, std::string>& io_logData) |
| 83 | { |
| 84 | uint32_t word6 = 0, word7 = 0, word8 = 0; |
| 85 | __getSrc(i_rootCause, word6, word7, word8); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 86 | |
| 87 | io_logData["SRC6"] = std::to_string(word6); |
| 88 | io_logData["SRC7"] = std::to_string(word7); |
| 89 | io_logData["SRC8"] = std::to_string(word8); |
| 90 | } |
| 91 | |
| 92 | //------------------------------------------------------------------------------ |
| 93 | |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 94 | void __addCalloutList(const ServiceData& i_servData, |
| 95 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 96 | { |
| 97 | // Get the JSON output for the callout list. |
| 98 | nlohmann::json json; |
| 99 | i_servData.getCalloutList(json); |
| 100 | |
| 101 | // Create a new entry for the user data section containing the callout list. |
| 102 | io_userDataFiles.emplace_back(util::FFDCFormat::JSON, FFDC_CALLOUTS, |
| 103 | FFDC_VERSION1); |
| 104 | |
| 105 | // Use a file stream to write the JSON to file. |
| 106 | std::ofstream o{io_userDataFiles.back().getPath()}; |
| 107 | o << json; |
| 108 | } |
| 109 | |
| 110 | //------------------------------------------------------------------------------ |
| 111 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 112 | void __captureSignatureList(const libhei::IsolationData& i_isoData, |
| 113 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 114 | { |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 115 | // Create a new entry for this user data section regardless if there are any |
| 116 | // signatures in the list. |
| 117 | io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_SIGNATURES, |
| 118 | FFDC_VERSION1); |
| 119 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 120 | // Create a streamer for easy writing to the FFDC file. |
| 121 | auto path = io_userDataFiles.back().getPath(); |
| 122 | util::BinFileWriter stream{path}; |
| 123 | |
| 124 | // The first 4 bytes in the FFDC contains the number of signatures in the |
| 125 | // list. Then, the list of signatures will follow. |
| 126 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 127 | auto list = i_isoData.getSignatureList(); |
| 128 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 129 | uint32_t numSigs = list.size(); |
| 130 | stream << numSigs; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 131 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 132 | for (const auto& sig : list) |
| 133 | { |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 134 | // Each signature will use the same format as the SRC (12 bytes each). |
| 135 | uint32_t word6 = 0, word7 = 0, word8 = 0; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 136 | __getSrc(sig, word6, word7, word8); |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 137 | stream << word6 << word7 << word8; |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 140 | // If the stream failed for any reason, remove the FFDC file. |
| 141 | if (!stream.good()) |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 142 | { |
Zane Shelley | b1106b5 | 2021-01-29 13:44:42 -0600 | [diff] [blame] | 143 | trace::err("Unable to write signature list FFDC file: %s", |
| 144 | path.string().c_str()); |
| 145 | io_userDataFiles.pop_back(); |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 146 | } |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | //------------------------------------------------------------------------------ |
| 150 | |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 151 | void __captureRegisterDump(const libhei::IsolationData& i_isoData, |
| 152 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 153 | { |
| 154 | // Create a new entry for this user data section regardless if there are any |
| 155 | // registers in the dump. |
| 156 | io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_REGISTER_DUMP, |
| 157 | FFDC_VERSION1); |
| 158 | |
| 159 | // Create a streamer for easy writing to the FFDC file. |
| 160 | auto path = io_userDataFiles.back().getPath(); |
| 161 | util::BinFileWriter stream{path}; |
| 162 | |
| 163 | // The first 4 bytes in the FFDC contains the number of chips with register |
| 164 | // data. Then the data for each chip will follow. |
| 165 | |
| 166 | auto dump = i_isoData.getRegisterDump(); |
| 167 | |
| 168 | uint32_t numChips = dump.size(); |
| 169 | stream << numChips; |
| 170 | |
| 171 | for (const auto& entry : dump) |
| 172 | { |
| 173 | auto chip = entry.first; |
| 174 | auto regList = entry.second; |
| 175 | |
| 176 | // Each chip will have the following information: |
| 177 | // 4 byte chip model/EC |
| 178 | // 2 byte chip position |
| 179 | // 4 byte number of registers |
| 180 | // Then the data for each register will follow. |
| 181 | |
| 182 | uint32_t chipType = chip.getType(); |
| 183 | uint16_t chipPos = util::pdbg::getChipPos(chip); |
| 184 | uint32_t numRegs = regList.size(); |
| 185 | stream << chipType << chipPos << numRegs; |
| 186 | |
| 187 | for (const auto& reg : regList) |
| 188 | { |
| 189 | // Each register will have the following information: |
| 190 | // 3 byte register ID |
| 191 | // 1 byte register instance |
| 192 | // 1 byte data size |
| 193 | // * byte data buffer (* depends on value of data size) |
| 194 | |
| 195 | libhei::RegisterId_t regId = reg.regId; // 3 byte |
| 196 | libhei::Instance_t regInst = reg.regInst; // 1 byte |
| 197 | |
| 198 | auto tmp = libhei::BitString::getMinBytes(reg.data->getBitLen()); |
| 199 | if (255 < tmp) |
| 200 | { |
| 201 | trace::inf("Register data execeeded 255 and was truncated: " |
| 202 | "regId=0x%06x regInst=%u", |
| 203 | regId, regInst); |
| 204 | tmp = 255; |
| 205 | } |
| 206 | uint8_t dataSize = tmp; |
| 207 | |
| 208 | stream << regId << regInst << dataSize; |
| 209 | |
| 210 | stream.write(reg.data->getBufAddr(), dataSize); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // If the stream failed for any reason, remove the FFDC file. |
| 215 | if (!stream.good()) |
| 216 | { |
| 217 | trace::err("Unable to write register dump FFDC file: %s", |
| 218 | path.string().c_str()); |
| 219 | io_userDataFiles.pop_back(); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | //------------------------------------------------------------------------------ |
| 224 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 225 | std::string __getMessageRegistry(bool i_isCheckstop) |
| 226 | { |
| 227 | // For now, there are only two choices: |
| 228 | return i_isCheckstop ? "org.open_power.HwDiags.Error.Checkstop" |
| 229 | : "org.open_power.HwDiags.Error.Predictive"; |
| 230 | } |
| 231 | |
| 232 | //------------------------------------------------------------------------------ |
| 233 | |
| 234 | std::string __getMessageSeverity(bool i_isCheckstop) |
| 235 | { |
| 236 | // We could specify the PEL severity in the message registry entry. However, |
| 237 | // that would require multiple copies of each entry for each possible |
| 238 | // severity. As a workaround, we will not explicitly state the PEL severity |
| 239 | // in the message registry. Instead, the message severity will be converted |
| 240 | // into a PEL severity via the openpower-pels extention of phosphor-logging. |
| 241 | |
| 242 | // Initially, we'll use a severity that will generate a predictive PEL. This |
| 243 | // is intended for Terminate Immediate (TI) errors and will require service. |
| 244 | LogSvr::Entry::Level severity = LogSvr::Entry::Level::Warning; |
| 245 | |
| 246 | // If the reason for analysis was due to a system checsktop, the severity |
| 247 | // will be upgraded to a unrecoverable PEL. |
| 248 | if (i_isCheckstop) |
| 249 | severity = LogSvr::Entry::Level::Error; |
| 250 | |
| 251 | // Convert the message severity to a string. |
| 252 | return LogSvr::Entry::convertLevelToString(severity); |
| 253 | } |
| 254 | |
| 255 | //------------------------------------------------------------------------------ |
| 256 | |
| 257 | void createPel(const libhei::Signature& i_rootCause, |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 258 | const libhei::IsolationData& i_isoData, |
| 259 | const ServiceData& i_servData) |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 260 | { |
| 261 | // The message registry will require additional log data to fill in keywords |
| 262 | // and additional log data. |
| 263 | std::map<std::string, std::string> logData; |
| 264 | |
| 265 | // Keep track of the temporary files associated with the user data FFDC. |
| 266 | // WARNING: Once the objects stored in this vector go out of scope, the |
| 267 | // temporary files will be deleted. So they must remain in scope |
| 268 | // until the PEL is submitted. |
| 269 | std::vector<util::FFDCFile> userDataFiles; |
| 270 | |
| 271 | // In several cases, it is important to know if the reason for analysis was |
| 272 | // due to a system checsktop. |
| 273 | bool isCheckstop = __isCheckstop(i_isoData); |
| 274 | |
| 275 | // Set words 6-9 of the SRC. |
| 276 | __setSrc(i_rootCause, logData); |
| 277 | |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 278 | // Add the list of callouts to the PEL. |
| 279 | __addCalloutList(i_servData, userDataFiles); |
| 280 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 281 | // Capture the complete signature list. |
| 282 | __captureSignatureList(i_isoData, userDataFiles); |
| 283 | |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 284 | // Capture the complete signature list. |
| 285 | __captureRegisterDump(i_isoData, userDataFiles); |
| 286 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 287 | // Now, that all of the user data files have been created, transform the |
| 288 | // data into the proper format for the PEL. |
| 289 | std::vector<util::FFDCTuple> userData; |
| 290 | util::transformFFDC(userDataFiles, userData); |
| 291 | |
| 292 | // Get access to logging interface and method for creating log. |
| 293 | auto bus = sdbusplus::bus::new_default_system(); |
| 294 | |
| 295 | // Using direct create method (for additional data). |
| 296 | auto method = bus.new_method_call( |
| 297 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 298 | "xyz.openbmc_project.Logging.Create", "CreateWithFFDCFiles"); |
| 299 | |
| 300 | // The "Create" method requires manually adding the process ID. |
| 301 | logData["_PID"] = std::to_string(getpid()); |
| 302 | |
| 303 | // Get the message registry entry for this failure. |
| 304 | auto message = __getMessageRegistry(isCheckstop); |
| 305 | |
| 306 | // Get the message severity for this failure. |
| 307 | auto severity = __getMessageSeverity(isCheckstop); |
| 308 | |
| 309 | // Add the message, with additional log and user data. |
| 310 | method.append(message, severity, logData, userData); |
| 311 | |
| 312 | // Log the event. |
| 313 | bus.call_noreply(method); |
| 314 | } |
| 315 | |
| 316 | } // namespace analyzer |