blob: 9f59b512170aa6ef4930766a236efbc83e25da64 [file] [log] [blame]
Alexander Hansen40fb5492025-10-28 17:56:12 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2021 IBM Corporation
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -05003
Patrick Williams2544b412022-10-04 08:41:06 -05004extern "C"
5{
Jayanth Othayoth66e186d2021-06-15 22:44:35 -05006#include <libpdbg.h>
7}
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -05008
Jayanth Othayothc74c2202021-06-04 06:42:43 -05009#include "fapi_data_process.hpp"
10#include "pel.hpp"
Jayanth Othayoth66e186d2021-06-15 22:44:35 -050011#include "sbe_ffdc_handler.hpp"
Jayanth Othayothc74c2202021-06-04 06:42:43 -050012#include "temporary_file.hpp"
13
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -050014#include <ekb/hwpf/fapi2/include/return_code_defs.H>
devenraoda876612024-02-16 18:48:27 +053015#include <ekb/hwpf/fapi2/include/target_types.H>
Jayanth Othayotheff307e2021-07-15 03:27:01 -050016#include <libekb.H>
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050017
Arya K Padman5bc26532024-04-10 06:19:25 -050018#include <phosphor-logging/lg2.hpp>
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050019
Patrick Williams2544b412022-10-04 08:41:06 -050020#include <new>
21
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050022namespace openpower
23{
24namespace pels
25{
26namespace sbe
27{
28
devenraob5693742024-02-16 18:33:32 +053029constexpr uint32_t sbeMaxFfdcPackets = 20;
devenraoda876612024-02-16 18:48:27 +053030constexpr uint16_t p10FfdcMagicCode = 0xFFDC;
31constexpr uint16_t pozFfdcMagicCode = 0xFBAD;
32constexpr uint16_t p10FfdcSkipWords = 2;
33constexpr uint16_t pozFfdcSkipWords = 3;
devenraob5693742024-02-16 18:33:32 +053034
devenraoda876612024-02-16 18:48:27 +053035struct p10FfdcHeader
devenraob5693742024-02-16 18:33:32 +053036{
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;
devenraoda876612024-02-16 18:48:27 +053043} __attribute__((packed));
44
45struct 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
58using namespace phosphor::logging;
devenraob5693742024-02-16 18:33:32 +053059
Jayanth Othayoth742b00b2022-06-30 05:16:57 -050060SbeFFDC::SbeFFDC(const AdditionalData& aData, const PelFFDC& files) :
devenraoda876612024-02-16 18:48:27 +053061 ffdcType(FFDC_TYPE_NONE), chipType(fapi2::TARGET_TYPE_PROC_CHIP)
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050062{
Arya K Padman5bc26532024-04-10 06:19:25 -050063 lg2::info("SBE FFDC processing requested");
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050064
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 Padman5bc26532024-04-10 06:19:25 -050071 lg2::error("Fail to extract SRC6 data: failing to get proc index");
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050072 return;
73 }
74 try
75 {
devenraoda876612024-02-16 18:48:27 +053076 chipPos = (std::stoi(src6.value()) & 0xFFFF0000) >> 16;
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050077 }
Patrick Williams66491c62021-10-06 12:23:37 -050078 catch (const std::exception& err)
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050079 {
Arya K Padman5bc26532024-04-10 06:19:25 -050080 lg2::error("Conversion failure errormsg({ERR})", "ERR", err);
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050081 return;
82 }
devenraoda876612024-02-16 18:48:27 +053083 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 Padman5bc26532024-04-10 06:19:25 -050092 lg2::error("Conversion failure errormsg({ERR})", "ERR", err);
devenraoda876612024-02-16 18:48:27 +053093 return;
94 }
95 }
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -050096
97 if (files.empty())
98 {
Arya K Padman5bc26532024-04-10 06:19:25 -050099 lg2::info("SbeFFDC : No files found, skipping ffdc processing");
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500100 return;
101 }
102
103 for (const auto& file : files)
104 {
105 if ((file.format == UserDataFormat::custom) &&
106 (file.subType == sbeFFDCSubType))
107 {
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500108 // Process SBE file.
109 parse(file.fd);
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500110 }
111 }
112}
113
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500114void SbeFFDC::parse(int fd)
115{
Arya K Padman5bc26532024-04-10 06:19:25 -0500116 lg2::info("SBE FFDC file fd:({FD}), parsing started", "FD", fd);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500117
118 uint32_t ffdcBufOffset = 0;
119 uint32_t pktCount = 0;
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500120
121 // get SBE FFDC data.
122 auto ffdcData = util::readFD(fd);
123 if (ffdcData.empty())
124 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500125 lg2::error("Empty SBE FFDC file fd:({FD}), skipping", "FD", fd);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500126 return;
127 }
128
129 while ((ffdcBufOffset < ffdcData.size()) && (sbeMaxFfdcPackets != pktCount))
130 {
devenraoc1a0ff82024-02-16 18:36:20 +0530131 sbeFfdcPacketType ffdcPkt;
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500132 // Next un-extracted FFDC Packet
devenraoda876612024-02-16 18:48:27 +0530133 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 Othayoth0866c3f2021-06-07 07:06:20 -0500139 {
devenraoda876612024-02-16 18:48:27 +0530140 p10FfdcHeader* ffdc = reinterpret_cast<p10FfdcHeader*>(
141 ffdcData.data() + ffdcBufOffset);
142 lenWords = ntohs(ffdc->lengthinWords);
143 auto fapiRc = ntohl(ffdc->fapiRc);
144
Arya K Padman5bc26532024-04-10 06:19:25 -0500145 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);
devenraoda876612024-02-16 18:48:27 +0530150
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 Padman5bc26532024-04-10 06:19:25 -0500164 lg2::error("FFDC packet size is zero skipping");
devenraoda876612024-02-16 18:48:27 +0530165 return;
166 }
devenrao4fdb31a2024-02-16 18:51:17 +0530167 pktCount++;
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500168 }
devenraoda876612024-02-16 18:48:27 +0530169 else if (magicBytes == pozFfdcMagicCode)
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500170 {
devenraoda876612024-02-16 18:48:27 +0530171 pozFfdcHeader* ffdc = reinterpret_cast<pozFfdcHeader*>(
172 ffdcData.data() + ffdcBufOffset);
173 lenWords = ntohs(ffdc->lengthinWords);
174 auto fapiRc = ntohl(ffdc->fapiRc);
175
Arya K Padman5bc26532024-04-10 06:19:25 -0500176 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);
devenraoda876612024-02-16 18:48:27 +0530181
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 Padman5bc26532024-04-10 06:19:25 -0500195 lg2::error("FFDC packet size is zero skipping");
devenraoda876612024-02-16 18:48:27 +0530196 return;
197 }
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500198 }
199 else
200 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500201 lg2::error("Invalid FFDC magic code in Header: Skipping ");
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500202 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 Othayothfb9b8112021-10-07 04:10:18 -0500212 else
213 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500214 lg2::info("SBE FFDC: Internal FFDC packet");
Jayanth Othayothfb9b8112021-10-07 04:10:18 -0500215 }
216
217 // Update Buffer offset in Bytes
218 ffdcBufOffset += lenWords * sizeof(uint32_t);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500219 }
220 if (pktCount == sbeMaxFfdcPackets)
221 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500222 lg2::error("Received more than the limit of ({SBEMAXFFDCPACKETS}) FFDC "
223 "packets, processing only ({PKTCOUNT})",
224 "SBEMAXFFDCPACKETS", sbeMaxFfdcPackets, "PKTCOUNT",
225 pktCount);
Jayanth Othayoth0866c3f2021-06-07 07:06:20 -0500226 }
227}
228
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500229void 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.
devenraoda876612024-02-16 18:48:27 +0530240 libekb_get_sbe_ffdc(ffdc, ffdcPkt, chipPos, chipType);
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500241 }
242 catch (...)
243 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500244 lg2::error("libekb_get_sbe_ffdc failed, skipping ffdc processing");
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500245 return;
246 }
247
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500248 // 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 Othayothc74c2202021-06-04 06:42:43 -0500252 // 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 Spinler8c7bb862023-08-31 14:32:22 -0500276 paths.emplace_back(ffdcFile.getPath(), pf.fd);
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500277
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 Spinlerbe952d22022-07-01 11:30:11 -0500289 pdf.subType = 0;
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500290 ffdcFiles.push_back(pdf);
291
Matt Spinler8c7bb862023-08-31 14:32:22 -0500292 paths.emplace_back(pelDataFile.getPath(), pdf.fd);
Jayanth Othayothc74c2202021-06-04 06:42:43 -0500293}
294
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500295std::optional<LogSeverity> SbeFFDC::getSeverity()
296{
297 if (ffdcType == FFDC_TYPE_SPARE_CLOCK_INFO)
298 {
Arya K Padman5bc26532024-04-10 06:19:25 -0500299 lg2::info(
Jayanth Othayoth742b00b2022-06-30 05:16:57 -0500300 "Found spare clock error, changing severity to informational");
301 return LogSeverity::Informational;
302 }
303 return std::nullopt;
304}
305
Jayanth Othayothe8bdeea2021-06-03 03:01:16 -0500306} // namespace sbe
307} // namespace pels
308} // namespace openpower