| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2021 IBM Corporation |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 3 | |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 4 | extern "C" |
| 5 | { |
| Jayanth Othayoth | 66e186d | 2021-06-15 22:44:35 -0500 | [diff] [blame] | 6 | #include <libpdbg.h> |
| 7 | } |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 8 | |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 9 | #include "fapi_data_process.hpp" |
| 10 | #include "pel.hpp" |
| Jayanth Othayoth | 66e186d | 2021-06-15 22:44:35 -0500 | [diff] [blame] | 11 | #include "sbe_ffdc_handler.hpp" |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 12 | #include "temporary_file.hpp" |
| 13 | |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 14 | #include <ekb/hwpf/fapi2/include/return_code_defs.H> |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 15 | #include <ekb/hwpf/fapi2/include/target_types.H> |
| Jayanth Othayoth | eff307e | 2021-07-15 03:27:01 -0500 | [diff] [blame] | 16 | #include <libekb.H> |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 17 | |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/lg2.hpp> |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 19 | |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 20 | #include <new> |
| 21 | |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 22 | namespace openpower |
| 23 | { |
| 24 | namespace pels |
| 25 | { |
| 26 | namespace sbe |
| 27 | { |
| 28 | |
| devenrao | b569374 | 2024-02-16 18:33:32 +0530 | [diff] [blame] | 29 | constexpr uint32_t sbeMaxFfdcPackets = 20; |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 30 | constexpr uint16_t p10FfdcMagicCode = 0xFFDC; |
| 31 | constexpr uint16_t pozFfdcMagicCode = 0xFBAD; |
| 32 | constexpr uint16_t p10FfdcSkipWords = 2; |
| 33 | constexpr uint16_t pozFfdcSkipWords = 3; |
| devenrao | b569374 | 2024-02-16 18:33:32 +0530 | [diff] [blame] | 34 | |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 35 | struct p10FfdcHeader |
| devenrao | b569374 | 2024-02-16 18:33:32 +0530 | [diff] [blame] | 36 | { |
| 37 | uint32_t magic_bytes:16; |
| 38 | uint32_t lengthinWords:16; |
| 39 | uint32_t seqId:16; |
| 40 | uint32_t cmdClass:8; |
| 41 | uint32_t cmd:8; |
| 42 | uint32_t fapiRc; |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 43 | } __attribute__((packed)); |
| 44 | |
| 45 | struct pozFfdcHeader |
| 46 | { |
| 47 | uint32_t magicByte:16; |
| 48 | uint32_t lengthinWords:16; |
| 49 | uint32_t seqId:16; |
| 50 | uint32_t cmdClass:8; |
| 51 | uint32_t cmd:8; |
| 52 | uint32_t slid:16; |
| 53 | uint32_t severity:8; |
| 54 | uint32_t chipId:8; |
| 55 | uint32_t fapiRc; |
| 56 | } __attribute__((packed)); |
| 57 | |
| 58 | using namespace phosphor::logging; |
| devenrao | b569374 | 2024-02-16 18:33:32 +0530 | [diff] [blame] | 59 | |
| Jayanth Othayoth | 742b00b | 2022-06-30 05:16:57 -0500 | [diff] [blame] | 60 | SbeFFDC::SbeFFDC(const AdditionalData& aData, const PelFFDC& files) : |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 61 | ffdcType(FFDC_TYPE_NONE), chipType(fapi2::TARGET_TYPE_PROC_CHIP) |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 62 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 63 | lg2::info("SBE FFDC processing requested"); |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 64 | |
| 65 | // SRC6 field in the additional data contains Processor position |
| 66 | // associated to the SBE FFDC |
| 67 | //"[0:15] chip position" |
| 68 | auto src6 = aData.getValue("SRC6"); |
| 69 | if (src6 == std::nullopt) |
| 70 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 71 | lg2::error("Fail to extract SRC6 data: failing to get proc index"); |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | try |
| 75 | { |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 76 | chipPos = (std::stoi(src6.value()) & 0xFFFF0000) >> 16; |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 77 | } |
| Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 78 | catch (const std::exception& err) |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 79 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 80 | lg2::error("Conversion failure errormsg({ERR})", "ERR", err); |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 81 | return; |
| 82 | } |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 83 | auto type = aData.getValue("CHIP_TYPE"); |
| 84 | if (type != std::nullopt) |
| 85 | { |
| 86 | try |
| 87 | { |
| 88 | chipType = std::stoi(type.value()); |
| 89 | } |
| 90 | catch (const std::exception& err) |
| 91 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 92 | lg2::error("Conversion failure errormsg({ERR})", "ERR", err); |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | } |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 96 | |
| 97 | if (files.empty()) |
| 98 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 99 | lg2::info("SbeFFDC : No files found, skipping ffdc processing"); |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 100 | return; |
| 101 | } |
| 102 | |
| 103 | for (const auto& file : files) |
| 104 | { |
| 105 | if ((file.format == UserDataFormat::custom) && |
| 106 | (file.subType == sbeFFDCSubType)) |
| 107 | { |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 108 | // Process SBE file. |
| 109 | parse(file.fd); |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 114 | void SbeFFDC::parse(int fd) |
| 115 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 116 | lg2::info("SBE FFDC file fd:({FD}), parsing started", "FD", fd); |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 117 | |
| 118 | uint32_t ffdcBufOffset = 0; |
| 119 | uint32_t pktCount = 0; |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 120 | |
| 121 | // get SBE FFDC data. |
| 122 | auto ffdcData = util::readFD(fd); |
| 123 | if (ffdcData.empty()) |
| 124 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 125 | lg2::error("Empty SBE FFDC file fd:({FD}), skipping", "FD", fd); |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
| 129 | while ((ffdcBufOffset < ffdcData.size()) && (sbeMaxFfdcPackets != pktCount)) |
| 130 | { |
| devenrao | c1a0ff8 | 2024-02-16 18:36:20 +0530 | [diff] [blame] | 131 | sbeFfdcPacketType ffdcPkt; |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 132 | // Next un-extracted FFDC Packet |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 133 | uint16_t magicBytes = |
| 134 | *(reinterpret_cast<uint16_t*>(ffdcData.data() + ffdcBufOffset)); |
| 135 | magicBytes = ntohs(magicBytes); |
| 136 | uint32_t pktLenWords = 0; |
| 137 | uint16_t lenWords = 0; |
| 138 | if (magicBytes == p10FfdcMagicCode) |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 139 | { |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 140 | p10FfdcHeader* ffdc = reinterpret_cast<p10FfdcHeader*>( |
| 141 | ffdcData.data() + ffdcBufOffset); |
| 142 | lenWords = ntohs(ffdc->lengthinWords); |
| 143 | auto fapiRc = ntohl(ffdc->fapiRc); |
| 144 | |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 145 | lg2::info( |
| 146 | "P10 FFDC magic: {MAGIC_BYTES} length in words:{LEN_WORDS} " |
| 147 | "Fapirc:{FAPI_RC}", |
| 148 | "MAGIC_BYTES", magicBytes, "LEN_WORDS", lenWords, "FAPI_RC", |
| 149 | fapiRc); |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 150 | |
| 151 | ffdcPkt.fapiRc = fapiRc; |
| 152 | // Not interested in the first 2 words (these are not ffdc) |
| 153 | pktLenWords = lenWords - p10FfdcSkipWords; |
| 154 | ffdcPkt.ffdcLengthInWords = pktLenWords; |
| 155 | if (pktLenWords) |
| 156 | { |
| 157 | ffdcPkt.ffdcData = new uint32_t[pktLenWords]; |
| 158 | memcpy(ffdcPkt.ffdcData, |
| 159 | ((reinterpret_cast<uint32_t*>(ffdc)) + p10FfdcSkipWords), |
| 160 | (pktLenWords * sizeof(uint32_t))); |
| 161 | } |
| 162 | else |
| 163 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 164 | lg2::error("FFDC packet size is zero skipping"); |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 165 | return; |
| 166 | } |
| devenrao | 4fdb31a | 2024-02-16 18:51:17 +0530 | [diff] [blame] | 167 | pktCount++; |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 168 | } |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 169 | else if (magicBytes == pozFfdcMagicCode) |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 170 | { |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 171 | pozFfdcHeader* ffdc = reinterpret_cast<pozFfdcHeader*>( |
| 172 | ffdcData.data() + ffdcBufOffset); |
| 173 | lenWords = ntohs(ffdc->lengthinWords); |
| 174 | auto fapiRc = ntohl(ffdc->fapiRc); |
| 175 | |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 176 | lg2::info( |
| 177 | "P0Z FFDC magic: {MAGIC_BYTES} length in words:{LEN_WORDS} " |
| 178 | "Fapirc:{FAPI_RC}", |
| 179 | "MAGIC_BYTES", magicBytes, "LEN_WORDS", lenWords, "FAPI_RC", |
| 180 | fapiRc); |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 181 | |
| 182 | ffdcPkt.fapiRc = fapiRc; |
| 183 | // Not interested in the first 3 words (these are not ffdc) |
| 184 | pktLenWords = lenWords - pozFfdcSkipWords; |
| 185 | ffdcPkt.ffdcLengthInWords = pktLenWords; |
| 186 | if (pktLenWords) |
| 187 | { |
| 188 | ffdcPkt.ffdcData = new uint32_t[pktLenWords]; |
| 189 | memcpy(ffdcPkt.ffdcData, |
| 190 | ((reinterpret_cast<uint32_t*>(ffdc)) + pozFfdcSkipWords), |
| 191 | (pktLenWords * sizeof(uint32_t))); |
| 192 | } |
| 193 | else |
| 194 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 195 | lg2::error("FFDC packet size is zero skipping"); |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 196 | return; |
| 197 | } |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 198 | } |
| 199 | else |
| 200 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 201 | lg2::error("Invalid FFDC magic code in Header: Skipping "); |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 202 | return; |
| 203 | } |
| 204 | |
| 205 | // SBE FFDC processing is not required for SBE Plat errors RCs. |
| 206 | // Plat errors processing is driven by SBE provided user data |
| 207 | // plugins, which need to link with PEL tool infrastructure. |
| 208 | if (ffdcPkt.fapiRc != fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA) |
| 209 | { |
| 210 | process(ffdcPkt); |
| 211 | } |
| Jayanth Othayoth | fb9b811 | 2021-10-07 04:10:18 -0500 | [diff] [blame] | 212 | else |
| 213 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 214 | lg2::info("SBE FFDC: Internal FFDC packet"); |
| Jayanth Othayoth | fb9b811 | 2021-10-07 04:10:18 -0500 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // Update Buffer offset in Bytes |
| 218 | ffdcBufOffset += lenWords * sizeof(uint32_t); |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 219 | } |
| 220 | if (pktCount == sbeMaxFfdcPackets) |
| 221 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 222 | lg2::error("Received more than the limit of ({SBEMAXFFDCPACKETS}) FFDC " |
| 223 | "packets, processing only ({PKTCOUNT})", |
| 224 | "SBEMAXFFDCPACKETS", sbeMaxFfdcPackets, "PKTCOUNT", |
| 225 | pktCount); |
| Jayanth Othayoth | 0866c3f | 2021-06-07 07:06:20 -0500 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 229 | void SbeFFDC::process(const sbeFfdcPacketType& ffdcPkt) |
| 230 | { |
| 231 | using json = nlohmann::json; |
| 232 | |
| 233 | // formated FFDC data structure after FFDC packet processing |
| 234 | FFDC ffdc; |
| 235 | |
| 236 | try |
| 237 | { |
| 238 | // libekb provided wrapper function to convert SBE FFDC |
| 239 | // in to known ffdc structure. |
| devenrao | da87661 | 2024-02-16 18:48:27 +0530 | [diff] [blame] | 240 | libekb_get_sbe_ffdc(ffdc, ffdcPkt, chipPos, chipType); |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 241 | } |
| 242 | catch (...) |
| 243 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 244 | lg2::error("libekb_get_sbe_ffdc failed, skipping ffdc processing"); |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | |
| Jayanth Othayoth | 742b00b | 2022-06-30 05:16:57 -0500 | [diff] [blame] | 248 | // update FFDC type class membeir for hwp specific packet |
| 249 | // Assumption SBE FFDC contains only one hwp FFDC packet. |
| 250 | ffdcType = ffdc.ffdc_type; |
| 251 | |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 252 | // To store callouts details in json format as per pel expectation. |
| 253 | json pelJSONFmtCalloutDataList; |
| 254 | pelJSONFmtCalloutDataList = json::array(); |
| 255 | |
| 256 | // To store other user data from FFDC. |
| 257 | openpower::pels::phal::FFDCData ffdcUserData; |
| 258 | |
| 259 | // Get FFDC and required info to include in PEL |
| 260 | openpower::pels::phal::convertFAPItoPELformat( |
| 261 | ffdc, pelJSONFmtCalloutDataList, ffdcUserData); |
| 262 | |
| 263 | // Get callout information and sore in to file. |
| 264 | auto calloutData = pelJSONFmtCalloutDataList.dump(); |
| 265 | util::TemporaryFile ffdcFile(calloutData.c_str(), calloutData.size()); |
| 266 | |
| 267 | // Create json callout type pel FFDC file structre. |
| 268 | PelFFDCfile pf; |
| 269 | pf.format = openpower::pels::UserDataFormat::json; |
| 270 | pf.subType = openpower::pels::jsonCalloutSubtype; |
| 271 | pf.version = 0x01; |
| 272 | pf.fd = ffdcFile.getFd(); |
| 273 | ffdcFiles.push_back(pf); |
| 274 | |
| 275 | // save the file path to delete the file after usage. |
| Matt Spinler | 8c7bb86 | 2023-08-31 14:32:22 -0500 | [diff] [blame] | 276 | paths.emplace_back(ffdcFile.getPath(), pf.fd); |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 277 | |
| 278 | // Format ffdc user data and create new file. |
| 279 | std::string data; |
| 280 | for (auto& d : ffdcUserData) |
| 281 | { |
| 282 | data += d.first + " = " + d.second + "\n"; |
| 283 | } |
| 284 | util::TemporaryFile pelDataFile(data.c_str(), data.size()); |
| 285 | PelFFDCfile pdf; |
| 286 | pdf.format = openpower::pels::UserDataFormat::text; |
| 287 | pdf.version = 0x01; |
| 288 | pdf.fd = pelDataFile.getFd(); |
| Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 289 | pdf.subType = 0; |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 290 | ffdcFiles.push_back(pdf); |
| 291 | |
| Matt Spinler | 8c7bb86 | 2023-08-31 14:32:22 -0500 | [diff] [blame] | 292 | paths.emplace_back(pelDataFile.getPath(), pdf.fd); |
| Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame] | 293 | } |
| 294 | |
| Jayanth Othayoth | 742b00b | 2022-06-30 05:16:57 -0500 | [diff] [blame] | 295 | std::optional<LogSeverity> SbeFFDC::getSeverity() |
| 296 | { |
| 297 | if (ffdcType == FFDC_TYPE_SPARE_CLOCK_INFO) |
| 298 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 299 | lg2::info( |
| Jayanth Othayoth | 742b00b | 2022-06-30 05:16:57 -0500 | [diff] [blame] | 300 | "Found spare clock error, changing severity to informational"); |
| 301 | return LogSeverity::Informational; |
| 302 | } |
| 303 | return std::nullopt; |
| 304 | } |
| 305 | |
| Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 306 | } // namespace sbe |
| 307 | } // namespace pels |
| 308 | } // namespace openpower |