Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 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 | */ |
Jayanth Othayoth | da9b583 | 2021-11-05 04:19:43 -0500 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 18 | #include "pel.hpp" |
| 19 | |
| 20 | #include "bcd_time.hpp" |
Matt Spinler | 386a61e | 2020-08-13 15:51:12 -0500 | [diff] [blame] | 21 | #include "extended_user_data.hpp" |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 22 | #include "extended_user_header.hpp" |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 23 | #include "failing_mtms.hpp" |
Andrew Geissler | f8e750d | 2022-01-14 14:56:13 -0600 | [diff] [blame] | 24 | #include "fru_identity.hpp" |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 25 | #include "json_utils.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 26 | #include "log_id.hpp" |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 27 | #include "pel_rules.hpp" |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 28 | #include "pel_values.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 29 | #include "section_factory.hpp" |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 30 | #include "src.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 31 | #include "stream.hpp" |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 32 | #include "user_data_formats.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 33 | |
Jayanth Othayoth | 92b2066 | 2021-11-05 00:09:15 -0500 | [diff] [blame] | 34 | #ifdef PEL_ENABLE_PHAL |
Jayanth Othayoth | da9b583 | 2021-11-05 04:19:43 -0500 | [diff] [blame] | 35 | #include "phal_service_actions.hpp" |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 36 | #include "sbe_ffdc_handler.hpp" |
Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame^] | 37 | |
| 38 | #include <libguard/guard_interface.hpp> |
| 39 | #include <libguard/include/guard_record.hpp> |
| 40 | |
| 41 | namespace libguard = openpower::guard; |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 42 | #endif |
| 43 | |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 44 | #include <sys/stat.h> |
| 45 | #include <unistd.h> |
| 46 | |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 47 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 48 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 49 | #include <format> |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 50 | #include <iostream> |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 51 | #include <ranges> |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 52 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 53 | namespace openpower |
| 54 | { |
| 55 | namespace pels |
| 56 | { |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 57 | namespace pv = openpower::pels::pel_values; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 58 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 59 | constexpr auto unknownValue = "Unknown"; |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 60 | constexpr auto AdDIMMInfoFetchError = "DIMMs Info Fetch Error"; |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 61 | |
Matt Spinler | 4bfc908 | 2020-03-24 15:05:54 -0500 | [diff] [blame] | 62 | PEL::PEL(const message::Entry& regEntry, uint32_t obmcLogID, uint64_t timestamp, |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 63 | phosphor::logging::Entry::Level severity, |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 64 | const AdditionalData& additionalData, const PelFFDC& ffdcFilesIn, |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 65 | const DataInterfaceBase& dataIface, const JournalBase& journal) |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 66 | { |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 67 | // No changes in input, for non SBE error related requests |
| 68 | PelFFDC ffdcFiles = ffdcFilesIn; |
| 69 | |
Jayanth Othayoth | 92b2066 | 2021-11-05 00:09:15 -0500 | [diff] [blame] | 70 | #ifdef PEL_ENABLE_PHAL |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 71 | // Add sbe ffdc processed data into ffdcfiles. |
| 72 | namespace sbe = openpower::pels::sbe; |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 73 | auto processReq = |
| 74 | std::any_of(ffdcFiles.begin(), ffdcFiles.end(), [](const auto& file) { |
| 75 | return file.format == UserDataFormat::custom && |
| 76 | file.subType == sbe::sbeFFDCSubType; |
| 77 | }); |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 78 | // sbeFFDC can't be destroyed until the end of the PEL constructor |
| 79 | // because it needs to keep around the FFDC Files to be used below. |
| 80 | std::unique_ptr<sbe::SbeFFDC> sbeFFDCPtr; |
| 81 | if (processReq) |
| 82 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 83 | sbeFFDCPtr = |
| 84 | std::make_unique<sbe::SbeFFDC>(additionalData, ffdcFilesIn); |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 85 | const auto& sbeFFDCFiles = sbeFFDCPtr->getSbeFFDC(); |
| 86 | ffdcFiles.insert(ffdcFiles.end(), sbeFFDCFiles.begin(), |
| 87 | sbeFFDCFiles.end()); |
Jayanth Othayoth | 742b00b | 2022-06-30 05:16:57 -0500 | [diff] [blame] | 88 | |
| 89 | // update pel priority for spare clock failures |
| 90 | if (auto customSeverity = sbeFFDCPtr->getSeverity()) |
| 91 | { |
| 92 | severity = customSeverity.value(); |
| 93 | } |
Jayanth Othayoth | e8bdeea | 2021-06-03 03:01:16 -0500 | [diff] [blame] | 94 | } |
| 95 | #endif |
| 96 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 97 | DebugData debugData; |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 98 | nlohmann::json callouts; |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 99 | |
Matt Spinler | 4bfc908 | 2020-03-24 15:05:54 -0500 | [diff] [blame] | 100 | _ph = std::make_unique<PrivateHeader>(regEntry.componentID, obmcLogID, |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 101 | timestamp); |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 102 | _uh = std::make_unique<UserHeader>(regEntry, severity, additionalData, |
| 103 | dataIface); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 104 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 105 | // Extract any callouts embedded in an FFDC file. |
| 106 | if (!ffdcFiles.empty()) |
| 107 | { |
| 108 | try |
| 109 | { |
| 110 | callouts = getCalloutJSON(ffdcFiles); |
| 111 | } |
| 112 | catch (const std::exception& e) |
| 113 | { |
| 114 | debugData.emplace("FFDC file JSON callouts error", |
| 115 | std::vector<std::string>{e.what()}); |
| 116 | } |
| 117 | } |
| 118 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 119 | auto src = |
| 120 | std::make_unique<SRC>(regEntry, additionalData, callouts, dataIface); |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 121 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 122 | nlohmann::json adSysInfoData(nlohmann::json::value_t::object); |
| 123 | addAdDetailsForDIMMsCallout(src, dataIface, adSysInfoData, debugData); |
| 124 | |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 125 | if (!src->getDebugData().empty()) |
| 126 | { |
| 127 | // Something didn't go as planned |
| 128 | debugData.emplace("SRC", src->getDebugData()); |
| 129 | } |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 130 | |
Matt Spinler | 4bfc908 | 2020-03-24 15:05:54 -0500 | [diff] [blame] | 131 | auto euh = std::make_unique<ExtendedUserHeader>(dataIface, regEntry, *src); |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 132 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 133 | _optionalSections.push_back(std::move(src)); |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 134 | _optionalSections.push_back(std::move(euh)); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 135 | |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 136 | auto mtms = std::make_unique<FailingMTMS>(dataIface); |
| 137 | _optionalSections.push_back(std::move(mtms)); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 138 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 139 | auto ud = util::makeSysInfoUserDataSection(additionalData, dataIface, true, |
| 140 | adSysInfoData); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 141 | addUserDataSection(std::move(ud)); |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 142 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 143 | // Check for pel severity of type - 0x51 = critical error, system |
| 144 | // termination and update terminate bit in SRC for pels |
| 145 | updateTerminateBitInSRCSection(); |
| 146 | |
Matt Spinler | 9b7e94f | 2020-03-24 15:44:41 -0500 | [diff] [blame] | 147 | // Create a UserData section from AdditionalData. |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 148 | if (!additionalData.empty()) |
| 149 | { |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 150 | ud = util::makeADUserDataSection(additionalData); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 151 | addUserDataSection(std::move(ud)); |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 154 | // Add any FFDC files into UserData sections |
| 155 | for (const auto& file : ffdcFiles) |
| 156 | { |
| 157 | ud = util::makeFFDCuserDataSection(regEntry.componentID, file); |
| 158 | if (!ud) |
| 159 | { |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 160 | // Add this error into the debug data UserData section |
| 161 | std::ostringstream msg; |
| 162 | msg << "Could not make PEL FFDC UserData section from file" |
| 163 | << std::hex << regEntry.componentID << " " << file.subType |
| 164 | << " " << file.version; |
| 165 | if (debugData.count("FFDC File")) |
| 166 | { |
| 167 | debugData.at("FFDC File").push_back(msg.str()); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | debugData.emplace("FFDC File", |
| 172 | std::vector<std::string>{msg.str()}); |
| 173 | } |
| 174 | |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 175 | continue; |
| 176 | } |
| 177 | |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 178 | addUserDataSection(std::move(ud)); |
| 179 | } |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 180 | |
Jayanth Othayoth | da9b583 | 2021-11-05 04:19:43 -0500 | [diff] [blame] | 181 | #ifdef PEL_ENABLE_PHAL |
| 182 | auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID); |
Deepa Karthikeyan | ff35be3 | 2024-10-15 09:10:49 -0500 | [diff] [blame^] | 183 | openpower::pels::phal::createServiceActions(callouts, dataIface, plid()); |
Jayanth Othayoth | da9b583 | 2021-11-05 04:19:43 -0500 | [diff] [blame] | 184 | #endif |
| 185 | |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 186 | // Store in the PEL any important debug data created while |
| 187 | // building the PEL sections. |
| 188 | if (!debugData.empty()) |
| 189 | { |
| 190 | nlohmann::json data; |
| 191 | data["PEL Internal Debug Data"] = debugData; |
| 192 | ud = util::makeJSONUserDataSection(data); |
| 193 | |
| 194 | addUserDataSection(std::move(ud)); |
| 195 | |
| 196 | // Also put in the journal for debug |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 197 | for (const auto& [name, msgs] : debugData) |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 198 | { |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 199 | for (const auto& message : msgs) |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 200 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 201 | lg2::info("{NAME}: {MSG}", "NAME", name, "MSG", message); |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 202 | } |
| 203 | } |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 206 | addJournalSections(regEntry, journal); |
| 207 | |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 208 | _ph->setSectionCount(2 + _optionalSections.size()); |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 209 | |
| 210 | checkRulesAndFix(); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 211 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 212 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 213 | PEL::PEL(std::vector<uint8_t>& data) : PEL(data, 0) {} |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 214 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 215 | PEL::PEL(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 216 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 217 | populateFromRawData(data, obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 220 | void PEL::populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 221 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 222 | Stream pelData{data}; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 223 | _ph = std::make_unique<PrivateHeader>(pelData); |
| 224 | if (obmcLogID != 0) |
| 225 | { |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 226 | _ph->setOBMCLogID(obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | _uh = std::make_unique<UserHeader>(pelData); |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 230 | |
| 231 | // Use the section factory to create the rest of the objects |
| 232 | for (size_t i = 2; i < _ph->sectionCount(); i++) |
| 233 | { |
| 234 | auto section = section_factory::create(pelData); |
| 235 | _optionalSections.push_back(std::move(section)); |
| 236 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | bool PEL::valid() const |
| 240 | { |
| 241 | bool valid = _ph->valid(); |
| 242 | |
| 243 | if (valid) |
| 244 | { |
| 245 | valid = _uh->valid(); |
| 246 | } |
| 247 | |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 248 | if (valid) |
| 249 | { |
| 250 | if (!std::all_of(_optionalSections.begin(), _optionalSections.end(), |
| 251 | [](const auto& section) { return section->valid(); })) |
| 252 | { |
| 253 | valid = false; |
| 254 | } |
| 255 | } |
| 256 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 257 | return valid; |
| 258 | } |
| 259 | |
| 260 | void PEL::setCommitTime() |
| 261 | { |
| 262 | auto now = std::chrono::system_clock::now(); |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 263 | _ph->setCommitTimestamp(getBCDTime(now)); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void PEL::assignID() |
| 267 | { |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 268 | _ph->setID(generatePELID()); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 269 | } |
| 270 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 271 | void PEL::flatten(std::vector<uint8_t>& pelBuffer) const |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 272 | { |
| 273 | Stream pelData{pelBuffer}; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 274 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 275 | if (!valid()) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 276 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 277 | lg2::warning("Unflattening an invalid PEL"); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 278 | } |
| 279 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 280 | _ph->flatten(pelData); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 281 | _uh->flatten(pelData); |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 282 | |
| 283 | for (auto& section : _optionalSections) |
| 284 | { |
| 285 | section->flatten(pelData); |
| 286 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 289 | std::vector<uint8_t> PEL::data() const |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 290 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 291 | std::vector<uint8_t> pelData; |
| 292 | flatten(pelData); |
| 293 | return pelData; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Matt Spinler | f1b46ff | 2020-01-22 14:10:04 -0600 | [diff] [blame] | 296 | size_t PEL::size() const |
| 297 | { |
| 298 | size_t size = 0; |
| 299 | |
| 300 | if (_ph) |
| 301 | { |
| 302 | size += _ph->header().size; |
| 303 | } |
| 304 | |
| 305 | if (_uh) |
| 306 | { |
| 307 | size += _uh->header().size; |
| 308 | } |
| 309 | |
| 310 | for (const auto& section : _optionalSections) |
| 311 | { |
| 312 | size += section->header().size; |
| 313 | } |
| 314 | |
| 315 | return size; |
| 316 | } |
| 317 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 318 | std::optional<SRC*> PEL::primarySRC() const |
| 319 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 320 | auto src = std::find_if( |
| 321 | _optionalSections.begin(), _optionalSections.end(), [](auto& section) { |
| 322 | return section->header().id == |
| 323 | static_cast<uint16_t>(SectionID::primarySRC); |
| 324 | }); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 325 | if (src != _optionalSections.end()) |
| 326 | { |
| 327 | return static_cast<SRC*>(src->get()); |
| 328 | } |
| 329 | |
| 330 | return std::nullopt; |
| 331 | } |
| 332 | |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 333 | void PEL::checkRulesAndFix() |
| 334 | { |
Matt Spinler | 1f93c59 | 2020-09-10 10:43:08 -0500 | [diff] [blame] | 335 | // Only fix if the action flags are at their default value which |
| 336 | // means they weren't specified in the registry. Otherwise |
| 337 | // assume the user knows what they are doing. |
| 338 | if (_uh->actionFlags() == actionFlagsDefault) |
| 339 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 340 | auto [actionFlags, eventType] = |
| 341 | pel_rules::check(0, _uh->eventType(), _uh->severity()); |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 342 | |
Matt Spinler | 1f93c59 | 2020-09-10 10:43:08 -0500 | [diff] [blame] | 343 | _uh->setActionFlags(actionFlags); |
| 344 | _uh->setEventType(eventType); |
| 345 | } |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 348 | void PEL::printSectionInJSON( |
| 349 | const Section& section, std::string& buf, |
| 350 | std::map<uint16_t, size_t>& pluralSections, message::Registry& registry, |
| 351 | const std::vector<std::string>& plugins, uint8_t creatorID) const |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 352 | { |
| 353 | char tmpB[5]; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 354 | uint8_t id[] = {static_cast<uint8_t>(section.header().id >> 8), |
| 355 | static_cast<uint8_t>(section.header().id)}; |
| 356 | sprintf(tmpB, "%c%c", id[0], id[1]); |
| 357 | std::string sectionID(tmpB); |
| 358 | std::string sectionName = pv::sectionTitles.count(sectionID) |
| 359 | ? pv::sectionTitles.at(sectionID) |
| 360 | : "Unknown Section"; |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 361 | |
| 362 | // Add a count if there are multiple of this type of section |
| 363 | auto count = pluralSections.find(section.header().id); |
| 364 | if (count != pluralSections.end()) |
| 365 | { |
| 366 | sectionName += " " + std::to_string(count->second); |
| 367 | count->second++; |
| 368 | } |
| 369 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 370 | if (section.valid()) |
| 371 | { |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 372 | std::optional<std::string> json; |
| 373 | if (sectionID == "PS" || sectionID == "SS") |
| 374 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 375 | json = section.getJSON(registry, plugins, creatorID); |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 376 | } |
Matt Spinler | 386a61e | 2020-08-13 15:51:12 -0500 | [diff] [blame] | 377 | else if ((sectionID == "UD") || (sectionID == "ED")) |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 378 | { |
Harisuddin Mohamed Isa | 3fdcd4e | 2020-08-26 11:56:42 +0800 | [diff] [blame] | 379 | json = section.getJSON(creatorID, plugins); |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 380 | } |
| 381 | else |
| 382 | { |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 383 | json = section.getJSON(creatorID); |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 384 | } |
Matt Spinler | 4220a15 | 2020-03-26 10:18:09 -0500 | [diff] [blame] | 385 | |
| 386 | buf += "\"" + sectionName + "\": {\n"; |
| 387 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 388 | if (json) |
| 389 | { |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 390 | buf += *json + "\n},\n"; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 391 | } |
| 392 | else |
| 393 | { |
Matt Spinler | 4220a15 | 2020-03-26 10:18:09 -0500 | [diff] [blame] | 394 | jsonInsert(buf, pv::sectionVer, |
| 395 | getNumberString("%d", section.header().version), 1); |
| 396 | jsonInsert(buf, pv::subSection, |
| 397 | getNumberString("%d", section.header().subType), 1); |
| 398 | jsonInsert(buf, pv::createdBy, |
| 399 | getNumberString("0x%X", section.header().componentID), |
| 400 | 1); |
| 401 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 402 | std::vector<uint8_t> data; |
| 403 | Stream s{data}; |
| 404 | section.flatten(s); |
Matt Spinler | 4220a15 | 2020-03-26 10:18:09 -0500 | [diff] [blame] | 405 | std::string dstr = |
| 406 | dumpHex(std::data(data) + SectionHeader::flattenedSize(), |
Arya K Padman | 8c8aaa0 | 2024-04-28 23:23:45 -0500 | [diff] [blame] | 407 | data.size() - SectionHeader::flattenedSize(), 2) |
| 408 | .get(); |
Matt Spinler | 4220a15 | 2020-03-26 10:18:09 -0500 | [diff] [blame] | 409 | std::string jsonIndent(indentLevel, 0x20); |
| 410 | buf += jsonIndent + "\"Data\": [\n"; |
| 411 | buf += dstr; |
| 412 | buf += jsonIndent + "]\n"; |
| 413 | buf += "},\n"; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 414 | } |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 415 | } |
| 416 | else |
| 417 | { |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 418 | buf += "\n\"Invalid Section\": [\n \"invalid\"\n],\n"; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 422 | std::map<uint16_t, size_t> PEL::getPluralSections() const |
| 423 | { |
| 424 | std::map<uint16_t, size_t> sectionCounts; |
| 425 | |
| 426 | for (const auto& section : optionalSections()) |
| 427 | { |
| 428 | if (sectionCounts.find(section->header().id) == sectionCounts.end()) |
| 429 | { |
| 430 | sectionCounts[section->header().id] = 1; |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | sectionCounts[section->header().id]++; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | std::map<uint16_t, size_t> sections; |
| 439 | for (const auto& [id, count] : sectionCounts) |
| 440 | { |
| 441 | if (count > 1) |
| 442 | { |
| 443 | // Start with 0 here and printSectionInJSON() |
| 444 | // will increment it as it goes. |
| 445 | sections.emplace(id, 0); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return sections; |
| 450 | } |
| 451 | |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 452 | void PEL::toJSON(message::Registry& registry, |
| 453 | const std::vector<std::string>& plugins) const |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 454 | { |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 455 | auto sections = getPluralSections(); |
| 456 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 457 | std::string buf = "{\n"; |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 458 | printSectionInJSON(*(_ph.get()), buf, sections, registry, plugins, |
| 459 | _ph->creatorID()); |
| 460 | printSectionInJSON(*(_uh.get()), buf, sections, registry, plugins, |
| 461 | _ph->creatorID()); |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 462 | for (auto& section : this->optionalSections()) |
| 463 | { |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 464 | printSectionInJSON(*(section.get()), buf, sections, registry, plugins, |
| 465 | _ph->creatorID()); |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 466 | } |
| 467 | buf += "}"; |
| 468 | std::size_t found = buf.rfind(","); |
| 469 | if (found != std::string::npos) |
| 470 | buf.replace(found, 1, ""); |
| 471 | std::cout << buf << std::endl; |
| 472 | } |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 473 | |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 474 | bool PEL::addUserDataSection(std::unique_ptr<UserData> userData) |
| 475 | { |
| 476 | if (size() + userData->header().size > _maxPELSize) |
| 477 | { |
| 478 | if (userData->shrink(_maxPELSize - size())) |
| 479 | { |
| 480 | _optionalSections.push_back(std::move(userData)); |
| 481 | } |
| 482 | else |
| 483 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 484 | lg2::warning("Could not shrink UserData section. Dropping. " |
| 485 | "Section size = {SSIZE}, Component ID = {COMP_ID}, " |
| 486 | "Subtype = {SUBTYPE}, Version = {VERSION}", |
| 487 | "SSIZE", userData->header().size, "COMP_ID", |
| 488 | userData->header().componentID, "SUBTYPE", |
| 489 | userData->header().subType, "VERSION", |
| 490 | userData->header().version); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 491 | return false; |
| 492 | } |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | _optionalSections.push_back(std::move(userData)); |
| 497 | } |
| 498 | return true; |
| 499 | } |
| 500 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 501 | nlohmann::json PEL::getCalloutJSON(const PelFFDC& ffdcFiles) |
| 502 | { |
| 503 | nlohmann::json callouts; |
| 504 | |
| 505 | for (const auto& file : ffdcFiles) |
| 506 | { |
| 507 | if ((file.format == UserDataFormat::json) && |
| 508 | (file.subType == jsonCalloutSubtype)) |
| 509 | { |
| 510 | auto data = util::readFD(file.fd); |
| 511 | if (data.empty()) |
| 512 | { |
| 513 | throw std::runtime_error{ |
| 514 | "Could not get data from JSON callout file descriptor"}; |
| 515 | } |
| 516 | |
| 517 | std::string jsonString{data.begin(), data.begin() + data.size()}; |
| 518 | |
| 519 | callouts = nlohmann::json::parse(jsonString); |
| 520 | break; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return callouts; |
| 525 | } |
| 526 | |
Andrew Geissler | f8e750d | 2022-01-14 14:56:13 -0600 | [diff] [blame] | 527 | bool PEL::isHwCalloutPresent() const |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 528 | { |
| 529 | auto pSRC = primarySRC(); |
| 530 | if (!pSRC) |
| 531 | { |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | bool calloutPresent = false; |
| 536 | if ((*pSRC)->callouts()) |
| 537 | { |
| 538 | for (auto& i : (*pSRC)->callouts()->callouts()) |
| 539 | { |
| 540 | if (((*i).fruIdentity())) |
| 541 | { |
| 542 | auto& fruId = (*i).fruIdentity(); |
Andrew Geissler | f8e750d | 2022-01-14 14:56:13 -0600 | [diff] [blame] | 543 | if ((*fruId).failingComponentType() == |
| 544 | src::FRUIdentity::hardwareFRU) |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 545 | { |
| 546 | calloutPresent = true; |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | return calloutPresent; |
| 554 | } |
| 555 | |
Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 556 | void PEL::updateSysInfoInExtendedUserDataSection( |
| 557 | const DataInterfaceBase& dataIface) |
| 558 | { |
| 559 | const AdditionalData additionalData; |
| 560 | |
| 561 | // Check for PEL from Hostboot |
| 562 | if (_ph->creatorID() == static_cast<uint8_t>(CreatorID::hostboot)) |
| 563 | { |
| 564 | // Get the ED section from PEL |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 565 | auto op = std::find_if( |
| 566 | _optionalSections.begin(), _optionalSections.end(), |
| 567 | [](auto& section) { |
| 568 | return section->header().id == |
| 569 | static_cast<uint16_t>(SectionID::extUserData); |
| 570 | }); |
Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 571 | |
| 572 | // Check for ED section found and its not the last section of PEL |
| 573 | if (op != _optionalSections.end()) |
| 574 | { |
| 575 | // Get the extended user data class mapped to found section |
| 576 | auto extUserData = static_cast<ExtendedUserData*>(op->get()); |
| 577 | |
| 578 | // Check for the creator ID is for OpenBMC |
| 579 | if (extUserData->creatorID() == |
| 580 | static_cast<uint8_t>(CreatorID::openBMC)) |
| 581 | { |
| 582 | // Update subtype and component id |
| 583 | auto subType = static_cast<uint8_t>(UserDataFormat::json); |
| 584 | auto componentId = |
| 585 | static_cast<uint16_t>(ComponentID::phosphorLogging); |
| 586 | |
| 587 | // Update system data to ED section |
George Liu | 9ac0d9b | 2022-07-15 10:57:38 +0800 | [diff] [blame] | 588 | auto ud = util::makeSysInfoUserDataSection(additionalData, |
| 589 | dataIface, false); |
Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 590 | extUserData->updateDataSection(subType, componentId, |
| 591 | ud->data()); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
Matt Spinler | 8e65f4e | 2023-05-02 13:40:08 -0500 | [diff] [blame] | 597 | bool PEL::getDeconfigFlag() const |
| 598 | { |
| 599 | auto creator = static_cast<CreatorID>(_ph->creatorID()); |
| 600 | |
| 601 | if ((creator == CreatorID::openBMC) || (creator == CreatorID::hostboot)) |
| 602 | { |
| 603 | auto src = primarySRC(); |
| 604 | return (*src)->getErrorStatusFlag(SRC::ErrorStatusFlags::deconfigured); |
| 605 | } |
| 606 | return false; |
| 607 | } |
| 608 | |
| 609 | bool PEL::getGuardFlag() const |
| 610 | { |
| 611 | auto creator = static_cast<CreatorID>(_ph->creatorID()); |
| 612 | |
| 613 | if ((creator == CreatorID::openBMC) || (creator == CreatorID::hostboot)) |
| 614 | { |
| 615 | auto src = primarySRC(); |
| 616 | return (*src)->getErrorStatusFlag(SRC::ErrorStatusFlags::guarded); |
| 617 | } |
| 618 | return false; |
| 619 | } |
| 620 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 621 | void PEL::updateTerminateBitInSRCSection() |
| 622 | { |
| 623 | // Check for pel severity of type - 0x51 = critical error, system |
| 624 | // termination |
| 625 | if (_uh->severity() == 0x51) |
| 626 | { |
| 627 | // Get the primary SRC section |
| 628 | auto pSRC = primarySRC(); |
| 629 | if (pSRC) |
| 630 | { |
| 631 | (*pSRC)->setTerminateBit(); |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 636 | void PEL::addJournalSections(const message::Entry& regEntry, |
| 637 | const JournalBase& journal) |
| 638 | { |
| 639 | if (!regEntry.journalCapture) |
| 640 | { |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | // Write all unwritten journal data to disk. |
| 645 | journal.sync(); |
| 646 | |
| 647 | const auto& jc = regEntry.journalCapture.value(); |
| 648 | std::vector<std::vector<std::string>> allMessages; |
| 649 | |
| 650 | if (std::holds_alternative<size_t>(jc)) |
| 651 | { |
| 652 | // Get the previous numLines journal entries |
| 653 | const auto& numLines = std::get<size_t>(jc); |
| 654 | try |
| 655 | { |
| 656 | auto messages = journal.getMessages("", numLines); |
| 657 | if (!messages.empty()) |
| 658 | { |
| 659 | allMessages.push_back(std::move(messages)); |
| 660 | } |
| 661 | } |
| 662 | catch (const std::exception& e) |
| 663 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 664 | lg2::error("Failed during journal collection: {ERROR}", "ERROR", e); |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | else if (std::holds_alternative<message::AppCaptureList>(jc)) |
| 668 | { |
| 669 | // Get journal entries based on the syslog id field. |
| 670 | const auto& sections = std::get<message::AppCaptureList>(jc); |
| 671 | for (const auto& [syslogID, numLines] : sections) |
| 672 | { |
| 673 | try |
| 674 | { |
| 675 | auto messages = journal.getMessages(syslogID, numLines); |
| 676 | if (!messages.empty()) |
| 677 | { |
| 678 | allMessages.push_back(std::move(messages)); |
| 679 | } |
| 680 | } |
| 681 | catch (const std::exception& e) |
| 682 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 683 | lg2::error("Failed during journal collection: {ERROR}", "ERROR", |
| 684 | e); |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // Create the UserData sections |
| 690 | for (const auto& messages : allMessages) |
| 691 | { |
| 692 | auto buffer = util::flattenLines(messages); |
| 693 | |
| 694 | // If the buffer is way too big, it can overflow the uint16_t |
| 695 | // PEL section size field that is checked below so do a cursory |
| 696 | // check here. |
| 697 | if (buffer.size() > _maxPELSize) |
| 698 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 699 | lg2::warning( |
| 700 | "Journal UserData section does not fit in PEL, dropping. " |
| 701 | "PEL size = {PEL_SIZE}, data size = {DATA_SIZE}", |
| 702 | "PEL_SIZE", size(), "DATA_SIZE", buffer.size()); |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 703 | continue; |
| 704 | } |
| 705 | |
| 706 | // Sections must be 4 byte aligned. |
| 707 | while (buffer.size() % 4 != 0) |
| 708 | { |
| 709 | buffer.push_back(0); |
| 710 | } |
| 711 | |
| 712 | auto ud = std::make_unique<UserData>( |
| 713 | static_cast<uint16_t>(ComponentID::phosphorLogging), |
| 714 | static_cast<uint8_t>(UserDataFormat::text), |
| 715 | static_cast<uint8_t>(UserDataFormatVersion::text), buffer); |
| 716 | |
| 717 | if (size() + ud->header().size <= _maxPELSize) |
| 718 | { |
| 719 | _optionalSections.push_back(std::move(ud)); |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | // Don't attempt to shrink here since we'd be dropping the |
| 724 | // most recent journal entries which would be confusing. |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 725 | lg2::warning( |
| 726 | "Journal UserData section does not fit in PEL, dropping. " |
| 727 | "PEL size = {PEL_SIZE}, data size = {DATA_SIZE}", |
| 728 | "PEL_SIZE", size(), "DATA_SIZE", buffer.size()); |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 729 | ud.reset(); |
| 730 | continue; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 735 | void PEL::addAdDetailsForDIMMsCallout( |
| 736 | const std::unique_ptr<SRC>& src, const DataInterfaceBase& dataIface, |
| 737 | nlohmann::json& adSysInfoData, DebugData& debugData) |
| 738 | { |
| 739 | if (!src->callouts()) |
| 740 | { |
| 741 | // No callouts |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | auto isDIMMCallout = [&dataIface, &debugData](const auto& callout) { |
| 746 | auto locCode{callout->locationCode()}; |
| 747 | if (locCode.empty()) |
| 748 | { |
| 749 | // Not a hardware callout. No action required |
| 750 | return false; |
| 751 | } |
| 752 | else |
| 753 | { |
Arya K Padman | ced8ed7 | 2024-09-02 05:18:07 -0500 | [diff] [blame] | 754 | return const_cast<DataInterfaceBase&>(dataIface).isDIMM(locCode); |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 755 | } |
| 756 | }; |
| 757 | auto addAdDIMMDetails = [&dataIface, &adSysInfoData, |
| 758 | &debugData](const auto& callout) { |
| 759 | auto dimmLocCode{callout->locationCode()}; |
| 760 | |
| 761 | auto diPropVal = dataIface.getDIProperty(dimmLocCode); |
| 762 | if (!diPropVal.has_value()) |
| 763 | { |
| 764 | std::string errMsg{ |
| 765 | std::format("Failed reading DI property from " |
| 766 | "VINI Interface for the LocationCode:[{}]", |
| 767 | dimmLocCode)}; |
| 768 | debugData[AdDIMMInfoFetchError].emplace_back(errMsg); |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | util::addDIMMInfo(dimmLocCode, diPropVal.value(), adSysInfoData); |
| 773 | } |
| 774 | }; |
| 775 | |
| 776 | auto DIMMsCallouts = src->callouts()->callouts() | |
| 777 | std::views::filter(isDIMMCallout); |
| 778 | |
| 779 | std::ranges::for_each(DIMMsCallouts, addAdDIMMDetails); |
| 780 | } |
| 781 | |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 782 | namespace util |
| 783 | { |
| 784 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 785 | std::unique_ptr<UserData> makeJSONUserDataSection(const nlohmann::json& json) |
| 786 | { |
Matt Spinler | 13db1d3 | 2024-10-08 11:22:54 -0500 | [diff] [blame] | 787 | std::string jsonString; |
| 788 | try |
| 789 | { |
| 790 | jsonString = json.dump(); |
| 791 | } |
| 792 | catch (const std::exception& e) |
| 793 | { |
| 794 | lg2::error("json.dump() failed with: {ERROR}", "ERROR", e); |
| 795 | jsonString = "Invalid JSON passed to makeJSONUserDataSection!"; |
| 796 | } |
| 797 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 798 | std::vector<uint8_t> jsonData(jsonString.begin(), jsonString.end()); |
| 799 | |
| 800 | // Pad to a 4 byte boundary |
| 801 | while ((jsonData.size() % 4) != 0) |
| 802 | { |
| 803 | jsonData.push_back(0); |
| 804 | } |
| 805 | |
| 806 | return std::make_unique<UserData>( |
| 807 | static_cast<uint16_t>(ComponentID::phosphorLogging), |
| 808 | static_cast<uint8_t>(UserDataFormat::json), |
| 809 | static_cast<uint8_t>(UserDataFormatVersion::json), jsonData); |
| 810 | } |
| 811 | |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 812 | std::unique_ptr<UserData> makeADUserDataSection(const AdditionalData& ad) |
| 813 | { |
| 814 | assert(!ad.empty()); |
| 815 | nlohmann::json json; |
| 816 | |
| 817 | // Remove the 'ESEL' entry, as it contains a full PEL in the value. |
| 818 | if (ad.getValue("ESEL")) |
| 819 | { |
| 820 | auto newAD = ad; |
| 821 | newAD.remove("ESEL"); |
| 822 | json = newAD.toJSON(); |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | json = ad.toJSON(); |
| 827 | } |
| 828 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 829 | return makeJSONUserDataSection(json); |
| 830 | } |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 831 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 832 | void addProcessNameToJSON(nlohmann::json& json, |
| 833 | const std::optional<std::string>& pid, |
| 834 | const DataInterfaceBase& dataIface) |
| 835 | { |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 836 | std::string name{unknownValue}; |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 837 | |
| 838 | try |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 839 | { |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 840 | if (pid) |
| 841 | { |
| 842 | auto n = dataIface.getProcessName(*pid); |
| 843 | if (n) |
| 844 | { |
| 845 | name = *n; |
| 846 | } |
| 847 | } |
| 848 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 849 | catch (const std::exception& e) |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 850 | {} |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 851 | |
Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 852 | if (pid) |
| 853 | { |
| 854 | json["Process Name"] = std::move(name); |
| 855 | } |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 856 | } |
| 857 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 858 | void addBMCFWVersionIDToJSON(nlohmann::json& json, |
| 859 | const DataInterfaceBase& dataIface) |
| 860 | { |
| 861 | auto id = dataIface.getBMCFWVersionID(); |
| 862 | if (id.empty()) |
| 863 | { |
| 864 | id = unknownValue; |
| 865 | } |
| 866 | |
Matt Spinler | c2b8a51 | 2021-05-21 12:44:42 -0600 | [diff] [blame] | 867 | json["FW Version ID"] = std::move(id); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 868 | } |
| 869 | |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 870 | std::string lastSegment(char separator, std::string data) |
| 871 | { |
| 872 | auto pos = data.find_last_of(separator); |
| 873 | if (pos != std::string::npos) |
| 874 | { |
| 875 | data = data.substr(pos + 1); |
| 876 | } |
| 877 | |
| 878 | return data; |
| 879 | } |
| 880 | |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 881 | void addIMKeyword(nlohmann::json& json, const DataInterfaceBase& dataIface) |
| 882 | { |
| 883 | auto keyword = dataIface.getSystemIMKeyword(); |
| 884 | |
| 885 | std::string value{}; |
| 886 | |
| 887 | std::for_each(keyword.begin(), keyword.end(), [&](const auto& byte) { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 888 | value += std::format("{:02X}", byte); |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 889 | }); |
| 890 | |
| 891 | json["System IM"] = value; |
| 892 | } |
| 893 | |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 894 | void addStatesToJSON(nlohmann::json& json, const DataInterfaceBase& dataIface) |
| 895 | { |
| 896 | json["BMCState"] = lastSegment('.', dataIface.getBMCState()); |
| 897 | json["ChassisState"] = lastSegment('.', dataIface.getChassisState()); |
| 898 | json["HostState"] = lastSegment('.', dataIface.getHostState()); |
Sumit Kumar | 2c36fdd | 2021-09-21 03:12:11 -0500 | [diff] [blame] | 899 | json["BootState"] = lastSegment('.', dataIface.getBootState()); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 900 | } |
| 901 | |
George Liu | 9ac0d9b | 2022-07-15 10:57:38 +0800 | [diff] [blame] | 902 | void addBMCUptime(nlohmann::json& json, const DataInterfaceBase& dataIface) |
| 903 | { |
| 904 | auto seconds = dataIface.getUptimeInSeconds(); |
| 905 | if (seconds) |
| 906 | { |
| 907 | json["BMCUptime"] = dataIface.getBMCUptime(*seconds); |
| 908 | } |
| 909 | else |
| 910 | { |
| 911 | json["BMCUptime"] = ""; |
| 912 | } |
| 913 | json["BMCLoad"] = dataIface.getBMCLoadAvg(); |
| 914 | } |
| 915 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 916 | std::unique_ptr<UserData> makeSysInfoUserDataSection( |
| 917 | const AdditionalData& ad, const DataInterfaceBase& dataIface, |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 918 | bool addUptime, const nlohmann::json& adSysInfoData) |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 919 | { |
| 920 | nlohmann::json json; |
| 921 | |
| 922 | addProcessNameToJSON(json, ad.getValue("_PID"), dataIface); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 923 | addBMCFWVersionIDToJSON(json, dataIface); |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 924 | addIMKeyword(json, dataIface); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 925 | addStatesToJSON(json, dataIface); |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 926 | |
George Liu | 9ac0d9b | 2022-07-15 10:57:38 +0800 | [diff] [blame] | 927 | if (addUptime) |
| 928 | { |
| 929 | addBMCUptime(json, dataIface); |
| 930 | } |
| 931 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 932 | if (!adSysInfoData.empty()) |
| 933 | { |
| 934 | json.update(adSysInfoData); |
| 935 | } |
| 936 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 937 | return makeJSONUserDataSection(json); |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 938 | } |
| 939 | |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 940 | std::vector<uint8_t> readFD(int fd) |
| 941 | { |
| 942 | std::vector<uint8_t> data; |
| 943 | |
| 944 | // Get the size |
| 945 | struct stat s; |
| 946 | int r = fstat(fd, &s); |
| 947 | if (r != 0) |
| 948 | { |
| 949 | auto e = errno; |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 950 | lg2::error("Could not get FFDC file size from FD, errno = {ERRNO}", |
| 951 | "ERRNO", e); |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 952 | return data; |
| 953 | } |
| 954 | |
| 955 | if (0 == s.st_size) |
| 956 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 957 | lg2::error("FFDC file is empty"); |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 958 | return data; |
| 959 | } |
| 960 | |
| 961 | data.resize(s.st_size); |
| 962 | |
| 963 | // Make sure its at the beginning, as maybe another |
| 964 | // extension already used it. |
| 965 | r = lseek(fd, 0, SEEK_SET); |
| 966 | if (r == -1) |
| 967 | { |
| 968 | auto e = errno; |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 969 | lg2::error("Could not seek to beginning of FFDC file, errno = {ERRNO}", |
| 970 | "ERRNO", e); |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 971 | return data; |
| 972 | } |
| 973 | |
| 974 | r = read(fd, data.data(), s.st_size); |
| 975 | if (r == -1) |
| 976 | { |
| 977 | auto e = errno; |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 978 | lg2::error("Could not read FFDC file, errno = {ERRNO}", "ERRNO", e); |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 979 | } |
| 980 | else if (r != s.st_size) |
| 981 | { |
Matt Spinler | fd2da66 | 2023-07-07 16:25:14 -0500 | [diff] [blame] | 982 | lg2::warning("Could not read full FFDC file. " |
| 983 | "File size = {FSIZE}, Size read = {SIZE_READ}", |
| 984 | "FSIZE", s.st_size, "SIZE_READ", r); |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | return data; |
| 988 | } |
| 989 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 990 | std::unique_ptr<UserData> |
| 991 | makeFFDCuserDataSection(uint16_t componentID, const PelFFDCfile& file) |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 992 | { |
Matt Spinler | 5b289b2 | 2020-03-26 14:27:19 -0500 | [diff] [blame] | 993 | auto data = readFD(file.fd); |
| 994 | |
| 995 | if (data.empty()) |
| 996 | { |
| 997 | return std::unique_ptr<UserData>(); |
| 998 | } |
| 999 | |
| 1000 | // The data needs 4 Byte alignment, and save amount padded for the |
| 1001 | // CBOR case. |
| 1002 | uint32_t pad = 0; |
| 1003 | while (data.size() % 4) |
| 1004 | { |
| 1005 | data.push_back(0); |
| 1006 | pad++; |
| 1007 | } |
| 1008 | |
| 1009 | // For JSON, CBOR, and Text use our component ID, subType, and version, |
| 1010 | // otherwise use the supplied ones. |
| 1011 | uint16_t compID = static_cast<uint16_t>(ComponentID::phosphorLogging); |
| 1012 | uint8_t subType{}; |
| 1013 | uint8_t version{}; |
| 1014 | |
| 1015 | switch (file.format) |
| 1016 | { |
| 1017 | case UserDataFormat::json: |
| 1018 | subType = static_cast<uint8_t>(UserDataFormat::json); |
| 1019 | version = static_cast<uint8_t>(UserDataFormatVersion::json); |
| 1020 | break; |
| 1021 | case UserDataFormat::cbor: |
| 1022 | subType = static_cast<uint8_t>(UserDataFormat::cbor); |
| 1023 | version = static_cast<uint8_t>(UserDataFormatVersion::cbor); |
| 1024 | |
| 1025 | // The CBOR parser will fail on the extra pad bytes since they |
| 1026 | // aren't CBOR. Add the amount we padded to the end and other |
| 1027 | // code will remove it all before parsing. |
| 1028 | { |
| 1029 | data.resize(data.size() + 4); |
| 1030 | Stream stream{data}; |
| 1031 | stream.offset(data.size() - 4); |
| 1032 | stream << pad; |
| 1033 | } |
| 1034 | |
| 1035 | break; |
| 1036 | case UserDataFormat::text: |
| 1037 | subType = static_cast<uint8_t>(UserDataFormat::text); |
| 1038 | version = static_cast<uint8_t>(UserDataFormatVersion::text); |
| 1039 | break; |
| 1040 | case UserDataFormat::custom: |
| 1041 | default: |
| 1042 | // Use the passed in values |
| 1043 | compID = componentID; |
| 1044 | subType = file.subType; |
| 1045 | version = file.version; |
| 1046 | break; |
| 1047 | } |
| 1048 | |
| 1049 | return std::make_unique<UserData>(compID, subType, version, data); |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 1052 | std::vector<uint8_t> flattenLines(const std::vector<std::string>& lines) |
| 1053 | { |
| 1054 | std::vector<uint8_t> out; |
| 1055 | |
| 1056 | for (const auto& line : lines) |
| 1057 | { |
| 1058 | out.insert(out.end(), line.begin(), line.end()); |
| 1059 | |
| 1060 | if (out.back() != '\n') |
| 1061 | { |
| 1062 | out.push_back('\n'); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | return out; |
| 1067 | } |
| 1068 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame] | 1069 | void addDIMMInfo(const std::string& locationCode, |
| 1070 | const std::vector<std::uint8_t>& diPropVal, |
| 1071 | nlohmann::json& adSysInfoData) |
| 1072 | { |
| 1073 | nlohmann::json dimmInfoObj; |
| 1074 | dimmInfoObj["Location Code"] = locationCode; |
| 1075 | std::ranges::transform( |
| 1076 | diPropVal, std::back_inserter(dimmInfoObj["DRAM Manufacturer ID"]), |
| 1077 | [](const auto& diPropEachByte) { |
| 1078 | return std::format("{:#04x}", diPropEachByte); |
| 1079 | }); |
| 1080 | adSysInfoData["DIMMs Additional Info"] += dimmInfoObj; |
| 1081 | } |
| 1082 | |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 1083 | } // namespace util |
| 1084 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 1085 | } // namespace pels |
| 1086 | } // namespace openpower |