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> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 9 | #include <util/dbus.hpp> |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 10 | #include <util/ffdc_file.hpp> |
| 11 | #include <util/pdbg.hpp> |
| 12 | #include <util/trace.hpp> |
| 13 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 14 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 15 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 16 | #include <fstream> |
| 17 | #include <memory> |
| 18 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 19 | namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server; |
| 20 | |
| 21 | namespace analyzer |
| 22 | { |
| 23 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 24 | //------------------------------------------------------------------------------ |
| 25 | |
| 26 | enum FfdcSubType_t : uint8_t |
| 27 | { |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 28 | FFDC_SIGNATURES = 0x01, |
| 29 | FFDC_REGISTER_DUMP = 0x02, |
Zane Shelley | 2d11432 | 2021-08-25 17:06:12 -0500 | [diff] [blame] | 30 | FFDC_CALLOUT_FFDC = 0x03, |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 31 | |
| 32 | // For the callout section, the value of '0xCA' is required per the |
| 33 | // phosphor-logging openpower-pel extention spec. |
| 34 | FFDC_CALLOUTS = 0xCA, |
| 35 | }; |
| 36 | |
| 37 | enum FfdcVersion_t : uint8_t |
| 38 | { |
| 39 | FFDC_VERSION1 = 0x01, |
| 40 | }; |
| 41 | |
| 42 | //------------------------------------------------------------------------------ |
| 43 | |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 44 | void __getSrc(const libhei::Signature& i_signature, uint32_t& o_word6, |
| 45 | uint32_t& o_word7, uint32_t& o_word8) |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 46 | { |
| 47 | // [ 0:15] chip model |
| 48 | // [16:23] reserved space in chip ID |
| 49 | // [24:31] chip EC level |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 50 | o_word6 = i_signature.getChip().getType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 51 | |
| 52 | // [ 0:15] chip position |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 53 | // [16:23] node position |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 54 | // [24:31] signature attention type |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 55 | auto chipPos = util::pdbg::getChipPos(i_signature.getChip()); |
| 56 | uint8_t nodePos = 0; // TODO: multi-node support |
| 57 | auto attn = i_signature.getAttnType(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 58 | |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 59 | o_word7 = (chipPos & 0xffff) << 16 | (nodePos & 0xff) << 8 | (attn & 0xff); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 60 | |
| 61 | // [ 0:15] signature ID |
| 62 | // [16:23] signature instance |
| 63 | // [24:31] signature bit position |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 64 | o_word8 = i_signature.toUint32(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 65 | |
| 66 | // Word 9 is currently unused |
Zane Shelley | 021dab3 | 2020-12-08 20:28:40 -0600 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | //------------------------------------------------------------------------------ |
| 70 | |
| 71 | void __setSrc(const libhei::Signature& i_rootCause, |
| 72 | std::map<std::string, std::string>& io_logData) |
| 73 | { |
| 74 | uint32_t word6 = 0, word7 = 0, word8 = 0; |
| 75 | __getSrc(i_rootCause, word6, word7, word8); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 76 | |
| 77 | io_logData["SRC6"] = std::to_string(word6); |
| 78 | io_logData["SRC7"] = std::to_string(word7); |
| 79 | io_logData["SRC8"] = std::to_string(word8); |
| 80 | } |
| 81 | |
| 82 | //------------------------------------------------------------------------------ |
| 83 | |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 84 | void __addCalloutList(const ServiceData& i_servData, |
| 85 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 86 | { |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 87 | // Create a new entry for the user data section containing the callout list. |
| 88 | io_userDataFiles.emplace_back(util::FFDCFormat::JSON, FFDC_CALLOUTS, |
| 89 | FFDC_VERSION1); |
| 90 | |
| 91 | // Use a file stream to write the JSON to file. |
| 92 | std::ofstream o{io_userDataFiles.back().getPath()}; |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 93 | o << i_servData.getCalloutList(); |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | //------------------------------------------------------------------------------ |
| 97 | |
Zane Shelley | 2d11432 | 2021-08-25 17:06:12 -0500 | [diff] [blame] | 98 | void __addCalloutFFDC(const ServiceData& i_servData, |
| 99 | std::vector<util::FFDCFile>& io_userDataFiles) |
| 100 | { |
| 101 | // Create a new entry for the user data section containing the FFDC. |
| 102 | io_userDataFiles.emplace_back(util::FFDCFormat::Custom, FFDC_CALLOUT_FFDC, |
| 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 << i_servData.getCalloutFFDC(); |
| 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 |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 179 | // 1 byte node position |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 180 | // 4 byte number of registers |
| 181 | // Then the data for each register will follow. |
| 182 | |
| 183 | uint32_t chipType = chip.getType(); |
| 184 | uint16_t chipPos = util::pdbg::getChipPos(chip); |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 185 | uint8_t nodePos = 0; // TODO: multi-node support |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 186 | uint32_t numRegs = regList.size(); |
Zane Shelley | ff068a1 | 2021-06-17 17:45:40 -0500 | [diff] [blame] | 187 | stream << chipType << chipPos << nodePos << numRegs; |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 188 | |
| 189 | for (const auto& reg : regList) |
| 190 | { |
| 191 | // Each register will have the following information: |
| 192 | // 3 byte register ID |
| 193 | // 1 byte register instance |
| 194 | // 1 byte data size |
| 195 | // * byte data buffer (* depends on value of data size) |
| 196 | |
| 197 | libhei::RegisterId_t regId = reg.regId; // 3 byte |
| 198 | libhei::Instance_t regInst = reg.regInst; // 1 byte |
| 199 | |
| 200 | auto tmp = libhei::BitString::getMinBytes(reg.data->getBitLen()); |
| 201 | if (255 < tmp) |
| 202 | { |
| 203 | trace::inf("Register data execeeded 255 and was truncated: " |
| 204 | "regId=0x%06x regInst=%u", |
| 205 | regId, regInst); |
| 206 | tmp = 255; |
| 207 | } |
| 208 | uint8_t dataSize = tmp; |
| 209 | |
| 210 | stream << regId << regInst << dataSize; |
| 211 | |
| 212 | stream.write(reg.data->getBufAddr(), dataSize); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // If the stream failed for any reason, remove the FFDC file. |
| 217 | if (!stream.good()) |
| 218 | { |
| 219 | trace::err("Unable to write register dump FFDC file: %s", |
| 220 | path.string().c_str()); |
| 221 | io_userDataFiles.pop_back(); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | //------------------------------------------------------------------------------ |
| 226 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 227 | std::string __getMessageRegistry(bool i_isCheckstop) |
| 228 | { |
| 229 | // For now, there are only two choices: |
| 230 | return i_isCheckstop ? "org.open_power.HwDiags.Error.Checkstop" |
| 231 | : "org.open_power.HwDiags.Error.Predictive"; |
| 232 | } |
| 233 | |
| 234 | //------------------------------------------------------------------------------ |
| 235 | |
| 236 | std::string __getMessageSeverity(bool i_isCheckstop) |
| 237 | { |
| 238 | // We could specify the PEL severity in the message registry entry. However, |
| 239 | // that would require multiple copies of each entry for each possible |
| 240 | // severity. As a workaround, we will not explicitly state the PEL severity |
| 241 | // in the message registry. Instead, the message severity will be converted |
| 242 | // into a PEL severity via the openpower-pels extention of phosphor-logging. |
| 243 | |
| 244 | // Initially, we'll use a severity that will generate a predictive PEL. This |
| 245 | // is intended for Terminate Immediate (TI) errors and will require service. |
| 246 | LogSvr::Entry::Level severity = LogSvr::Entry::Level::Warning; |
| 247 | |
| 248 | // If the reason for analysis was due to a system checsktop, the severity |
| 249 | // will be upgraded to a unrecoverable PEL. |
| 250 | if (i_isCheckstop) |
| 251 | severity = LogSvr::Entry::Level::Error; |
| 252 | |
| 253 | // Convert the message severity to a string. |
| 254 | return LogSvr::Entry::convertLevelToString(severity); |
| 255 | } |
| 256 | |
| 257 | //------------------------------------------------------------------------------ |
| 258 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 259 | std::tuple<uint32_t, uint32_t> createPel(const libhei::IsolationData& i_isoData, |
| 260 | const ServiceData& i_servData) |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 261 | { |
| 262 | // The message registry will require additional log data to fill in keywords |
| 263 | // and additional log data. |
| 264 | std::map<std::string, std::string> logData; |
| 265 | |
| 266 | // Keep track of the temporary files associated with the user data FFDC. |
| 267 | // WARNING: Once the objects stored in this vector go out of scope, the |
| 268 | // temporary files will be deleted. So they must remain in scope |
| 269 | // until the PEL is submitted. |
| 270 | std::vector<util::FFDCFile> userDataFiles; |
| 271 | |
| 272 | // In several cases, it is important to know if the reason for analysis was |
| 273 | // due to a system checsktop. |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 274 | bool isCheckstop = i_isoData.queryCheckstop(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 275 | |
| 276 | // Set words 6-9 of the SRC. |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 277 | __setSrc(i_servData.getRootCause(), logData); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 278 | |
Zane Shelley | 4ed4be5 | 2021-02-15 17:53:40 -0600 | [diff] [blame] | 279 | // Add the list of callouts to the PEL. |
| 280 | __addCalloutList(i_servData, userDataFiles); |
| 281 | |
Zane Shelley | 2d11432 | 2021-08-25 17:06:12 -0500 | [diff] [blame] | 282 | // Add the callout FFDC to the PEL. |
| 283 | __addCalloutFFDC(i_servData, userDataFiles); |
| 284 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 285 | // Capture the complete signature list. |
| 286 | __captureSignatureList(i_isoData, userDataFiles); |
| 287 | |
Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 288 | // Capture the complete signature list. |
| 289 | __captureRegisterDump(i_isoData, userDataFiles); |
| 290 | |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 291 | // Now, that all of the user data files have been created, transform the |
| 292 | // data into the proper format for the PEL. |
| 293 | std::vector<util::FFDCTuple> userData; |
| 294 | util::transformFFDC(userDataFiles, userData); |
| 295 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 296 | // Response will be a tuple containing bmc-log-id, pel-log-id |
| 297 | std::tuple<uint32_t, uint32_t> response = {0, 0}; |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 298 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 299 | try |
| 300 | { |
| 301 | // We want to use the logging interface that returns the event log |
| 302 | // id's of the newly created logs (org.open_power.Logging.PEL) so |
| 303 | // find the service that implements this interface. |
| 304 | constexpr auto interface = "org.open_power.Logging.PEL"; |
| 305 | constexpr auto path = "/xyz/openbmc_project/logging"; |
| 306 | std::string service; |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 307 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 308 | if (0 == util::dbus::findService(interface, path, service)) |
| 309 | { |
| 310 | // Use function that returns log id's |
| 311 | constexpr auto function = "CreatePELWithFFDCFiles"; |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 312 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 313 | // Get access to logging interface and method for creating log. |
| 314 | auto bus = sdbusplus::bus::new_default_system(); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 315 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 316 | // Using direct create method (for additional data). |
| 317 | auto method = |
| 318 | bus.new_method_call(service.c_str(), path, interface, function); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 319 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 320 | // The "Create" method requires manually adding the process ID. |
| 321 | logData["_PID"] = std::to_string(getpid()); |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 322 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 323 | // Get the message registry entry for this failure. |
| 324 | auto message = __getMessageRegistry(isCheckstop); |
| 325 | |
| 326 | // Get the message severity for this failure. |
| 327 | auto severity = __getMessageSeverity(isCheckstop); |
| 328 | |
| 329 | // Add the message, with additional log and user data. |
| 330 | method.append(message, severity, logData, userData); |
| 331 | |
| 332 | // Log the event. |
| 333 | auto reply = bus.call(method); |
| 334 | |
| 335 | // Parse reply for response |
| 336 | reply.read(response); |
| 337 | } |
| 338 | } |
| 339 | catch (const sdbusplus::exception::SdBusError& e) |
| 340 | { |
| 341 | trace::err("Exception while creating event log entry"); |
| 342 | std::string exceptionString = std::string(e.what()); |
| 343 | trace::err(exceptionString.c_str()); |
| 344 | } |
| 345 | |
| 346 | // return tuple of {bmc-log-id, pel-log-id} or {0, 0} on error |
| 347 | return response; |
Zane Shelley | d3b9bac | 2020-11-17 21:59:12 -0600 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | } // namespace analyzer |