Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "sbe_ffdc_handler.hpp" |
| 18 | |
Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame^] | 19 | #include "fapi_data_process.hpp" |
| 20 | #include "pel.hpp" |
| 21 | #include "temporary_file.hpp" |
| 22 | |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 23 | #include <fmt/format.h> |
| 24 | |
| 25 | #include <phosphor-logging/log.hpp> |
| 26 | |
| 27 | namespace openpower |
| 28 | { |
| 29 | namespace pels |
| 30 | { |
| 31 | namespace sbe |
| 32 | { |
| 33 | |
| 34 | using namespace phosphor::logging; |
| 35 | |
| 36 | SbeFFDC::SbeFFDC(const AdditionalData& aData, const PelFFDC& files) |
| 37 | { |
| 38 | log<level::INFO>("SBE FFDC processing requested"); |
| 39 | |
| 40 | // SRC6 field in the additional data contains Processor position |
| 41 | // associated to the SBE FFDC |
| 42 | //"[0:15] chip position" |
| 43 | auto src6 = aData.getValue("SRC6"); |
| 44 | if (src6 == std::nullopt) |
| 45 | { |
| 46 | log<level::ERR>("Fail to extract SRC6 data: failing to get proc index"); |
| 47 | return; |
| 48 | } |
| 49 | try |
| 50 | { |
| 51 | procPos = std::stoi((src6.value()).substr(0, 4)); |
| 52 | } |
| 53 | catch (std::exception& err) |
| 54 | { |
| 55 | log<level::ERR>( |
| 56 | fmt::format("Conversion failure errormsg({})", err.what()).c_str()); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | if (files.empty()) |
| 61 | { |
| 62 | log<level::INFO>("SbeFFDC : No files found, skipping ffdc processing"); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | for (const auto& file : files) |
| 67 | { |
| 68 | if ((file.format == UserDataFormat::custom) && |
| 69 | (file.subType == sbeFFDCSubType)) |
| 70 | { |
| 71 | // TODO Process SBE file. |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
Jayanth Othayoth | c74c220 | 2021-06-04 06:42:43 -0500 | [diff] [blame^] | 76 | void SbeFFDC::process(const sbeFfdcPacketType& ffdcPkt) |
| 77 | { |
| 78 | using json = nlohmann::json; |
| 79 | |
| 80 | // formated FFDC data structure after FFDC packet processing |
| 81 | FFDC ffdc; |
| 82 | |
| 83 | try |
| 84 | { |
| 85 | // libekb provided wrapper function to convert SBE FFDC |
| 86 | // in to known ffdc structure. |
| 87 | libekb_get_sbe_ffdc(ffdc, ffdcPkt, procPos); |
| 88 | } |
| 89 | catch (...) |
| 90 | { |
| 91 | log<level::ERR>("libekb_get_sbe_ffdc failed, skipping ffdc processing"); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | // To store callouts details in json format as per pel expectation. |
| 96 | json pelJSONFmtCalloutDataList; |
| 97 | pelJSONFmtCalloutDataList = json::array(); |
| 98 | |
| 99 | // To store other user data from FFDC. |
| 100 | openpower::pels::phal::FFDCData ffdcUserData; |
| 101 | |
| 102 | // Get FFDC and required info to include in PEL |
| 103 | openpower::pels::phal::convertFAPItoPELformat( |
| 104 | ffdc, pelJSONFmtCalloutDataList, ffdcUserData); |
| 105 | |
| 106 | // Get callout information and sore in to file. |
| 107 | auto calloutData = pelJSONFmtCalloutDataList.dump(); |
| 108 | util::TemporaryFile ffdcFile(calloutData.c_str(), calloutData.size()); |
| 109 | |
| 110 | // Create json callout type pel FFDC file structre. |
| 111 | PelFFDCfile pf; |
| 112 | pf.format = openpower::pels::UserDataFormat::json; |
| 113 | pf.subType = openpower::pels::jsonCalloutSubtype; |
| 114 | pf.version = 0x01; |
| 115 | pf.fd = ffdcFile.getFd(); |
| 116 | ffdcFiles.push_back(pf); |
| 117 | |
| 118 | // save the file path to delete the file after usage. |
| 119 | paths.push_back(ffdcFile.getPath()); |
| 120 | |
| 121 | // Format ffdc user data and create new file. |
| 122 | std::string data; |
| 123 | for (auto& d : ffdcUserData) |
| 124 | { |
| 125 | data += d.first + " = " + d.second + "\n"; |
| 126 | } |
| 127 | util::TemporaryFile pelDataFile(data.c_str(), data.size()); |
| 128 | PelFFDCfile pdf; |
| 129 | pdf.format = openpower::pels::UserDataFormat::text; |
| 130 | pdf.version = 0x01; |
| 131 | pdf.fd = pelDataFile.getFd(); |
| 132 | ffdcFiles.push_back(pdf); |
| 133 | |
| 134 | paths.push_back(pelDataFile.getPath()); |
| 135 | } |
| 136 | |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 137 | } // namespace sbe |
| 138 | } // namespace pels |
| 139 | } // namespace openpower |